JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3554
  • Score
    100M100P100Q107275F
  • License MIT

OpenCode plugin: injects core rules into every LLM call

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.mdinstructions 适合会话启动时加载规则,但它们不是每轮 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.log

config.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 不会热重载插件、配置或运行态规则。

迁移

安装或升级时会自动迁移:

  • ~/.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

如果新路径文件已存在,安装脚本不会覆盖。

验证

npm test
npm pack --dry-run

运行 OpenCode 后检查日志:

rg "event=system_prompt_injection" ~/.config/opencode/plugins/opencode-core-rules-injector/logs