Package Exports
- opencode-core-rules-injector
- opencode-core-rules-injector/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (opencode-core-rules-injector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
opencode-core-rules-injector
OpenCode 插件:通过 experimental.chat.system.transform 在每次 LLM 请求准备阶段把 core-rules.md 追加到 system prompt。
目标
AGENTS.md 和 instructions 适合会话启动时加载规则,但它们不是每轮 LLM 调用前的动态注入机制。本插件的目标是在主 Agent 连续执行工具调用、调度子 Agent、长时间自动推进任务时,仍然让模型持续看到 core-rules.md。
注入路径
插件只注册 experimental.chat.system.transform。它不会修改用户消息,不使用 instructions 作为成功路径。
- 每次 LLM 调用前触发。
- 将
core-rules.md追加到 system prompt 数组。 - 这是长任务自动运行期间的核心保障。
运行态目录
~/.config/opencode/plugins/opencode-core-rules-injector/
├── config.toml
├── core-rules.md
└── logs/
└── injector-YYYY-MM-DD.logconfig.toml 默认内容:
[git]
user_name = "liumenglife"
user_email = "liumenglife@163.com"
default_branch = "main"
[logging]
daily_rotation = true日志字段
日志按天滚动,写入:
~/.config/opencode/plugins/opencode-core-rules-injector/logs/injector-YYYY-MM-DD.log示例:
ts=2026-06-13T10:00:00.000Z level=info event=system_prompt_injection hook=experimental.chat.system.transform result=injected session_id=ab12cd34 provider_id=anthropic model_id=claude-sonnet-4-20250514 model_name=Claude Sonnet 4 rules_path=/home/lm/.config/opencode/plugins/opencode-core-rules-injector/core-rules.md rules_chars=2451 rules_mtime=1780000000000 rules_hash=abc123 system_before_count=1 system_after_count=2 duration_ms=15安装
bun install -g opencode-core-rules-injector --trust或:
npm install -g opencode-core-rules-injector安装或升级后必须完全重启 OpenCode。OpenCode 不会热重载插件、配置或运行态规则。
安装脚本会把插件注册为当前精确版本,例如 opencode-core-rules-injector@1.3.2-2,以规避 OpenCode 对 @latest 缓存旧包导致继续加载旧规则的问题。
迁移
安装或升级时会自动迁移:
~/.config/opencode/core-rules.md→~/.config/opencode/plugins/opencode-core-rules-injector/core-rules.md~/.config/opencode-agent/config.toml→~/.config/opencode/plugins/opencode-core-rules-injector/config.toml
如果运行态 core-rules.md 已存在且不同于包内标准规则,安装脚本会先备份旧文件,再用包内标准 core-rules.md 整体覆盖;已有备份不会被覆盖。内容已经一致时不会创建新备份。
验证
npm test
npm pack --dry-run运行 OpenCode 后检查日志:
rg "event=system_prompt_injection" ~/.config/opencode/plugins/opencode-core-rules-injector/logs