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 插件:在每次 LLM 调用前注入核心规则,确保模型始终遵守你的工作流和偏好。

作用

OpenCode 在长时间自动执行(如 5 小时、100 个任务)时,模型容易忘记用户制定的规则。已有的方式(AGENTS.md、opencode.json instructions)只在会话启动时读取一次,无法防止长任务中的注意力漂移。

这个插件在每次 LLM 调用前~/.config/opencode/core-rules.md 的内容注入到 system prompt 中,让模型每轮都能看到规则,确保始终如一地遵守。

实现方法

  1. 利用 OpenCode 的 experimental.chat.system.transform 钩子,在每个 LLM 调用前修改 system prompt
  2. 读取 ~/.config/opencode/core-rules.md 的内容并追加到 system prompt 尾部
  3. 带 mtime 缓存,文件无变化时不重复读盘
  4. 首次安装时自动创建 ~/.config/opencode/core-rules.md(含默认工作流)
  5. 通过 postinstall 脚本自动注册到 opencode.jsonc/opencode.json"plugin" 数组

三层规则保障:

生效时机 覆盖范围
AGENTS.md(核心指令+工作流) 会话启动时 主 Agent + 所有子 Agent
core-rules.md(插件注入) 每次 LLM 调用前 主 Agent
AGENTS.md 上下文(ctx7 等) 会话启动时 主 Agent + 所有子 Agent

安装

# 使用 bun(推荐,更快),--trust 确保 postinstall 脚本执行
bun install -g opencode-core-rules-injector --trust

# 或使用 npm
npm install -g opencode-core-rules-injector

安装后重启 OpenCode 即可生效。postinstall 会自动完成以下操作:

  • "opencode-core-rules-injector" 添加到 ~/.config/opencode/opencode.jsoncopencode.json"plugin" 数组
  • 创建 ~/.config/opencode/core-rules.md(含默认的语言、工具偏好和工作流规则)

自定义规则

编辑 ~/.config/opencode/core-rules.md,修改立即生效,无需重启:

## 语言
始终使用简体中文输出,包括工具调用描述、思考过程等全部内容。

## 工具偏好
- **文件内容搜索**: `rg` 而非 `grep`
- **文件名搜索**: `fd` 而非 `find`
- **内容替换**: `sd` 而非 `sed`
- **JSON 处理**: `jq`
- **HTTP 请求**: `httpie` 而非 `curl`
- **文件查看**: `bat` 而非 `cat`
- **包管理**: Python 用 `uv` 而非 `pip3`
- Rust 三板斧:`rg` + `fd` + `sd`

## 工作流
...

更新

bun install -g opencode-core-rules-injector@latest --trust
# 或
npm install -g opencode-core-rules-injector@latest

发布历史

版本 说明
1.0.0 基础插件:每轮注入 core-rules.md
1.0.1 新增 postinstall 自动注册
1.1.0 添加完整工作流规则
1.1.3 拆分 Specs/Plans 目录,明确人工确认边界