@xesrevinu/opencode-context-shieldContext-reduction plugin for OpenCode with deterministic output compaction and backtest tooling.
0
14
近 7 天 2
18.9
生态多维模型
5 个月前
2026-03-17
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@xesrevinu/opencode-context-shield@0.1.1"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@xesrevinu/opencode-context-shield@0.1.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @xesrevinu/opencode-context-shieldopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Deterministic context-reduction plugin for OpenCode sessions with built-in backtest tooling.
Highlights
- compacts large tool output while preserving the signals, head, and tail that matter
- skips read and edit sensitive tools by default so file work stays intact
- clamps noisy
readcalls and injects routing hints for subagent tasks - exposes
cshield_toggleandcshield_statshelper tools for live control and measurement - includes replay-style Python backtests for evaluating real session history before rollout
Install
Use the published package from opencode.jsonc:
{
"plugin": ["@xesrevinu/opencode-context-shield@latest"],
}
Restart OpenCode after updating the plugin list.
If you want to iterate from a checkout instead of npm:
mkdir -p .opencode/plugin
cp plugin/context-shield.ts .opencode/plugin/context-shield.ts
Usage
The plugin stores runtime config at <project>/.opencode/state/context-shield.json.
Default config:
{
"enabled": true,
"readLimit": 800,
"compactThresholdBytes": 8192,
"compactTargetBytes": 4096
}
Quick smoke test:
opencode run --format json "Call cshield_stats exactly once, then respond with OK."
Backtest a single session:
python3 scripts/backtest-session.py \
--session ses_371939900ffeZgZksolV6nC1A1 \
--thresholds 12,10,8,6,4,3,2 \
--target-kb 4
Batch backtest recent sessions:
python3 scripts/backtest-batch.py \
--min-tool-bytes 30000 \
--limit 80 \
--thresholds 12,10,8,6,4,3,2 \
--target-kb 4 \
--target-sweep 6,4,3,2 \
--read-limits 800,600,400,200
Development
The repository uses Bun for dependency management and local commands.
bun install
bun run check
bun run backtest:session -- --help
bun run backtest:batch -- --help
Release
This package uses Changesets plus the shared GitHub Actions release workflow.
bun run changeset
bun run version-packages
bun run release
License
MIT