opencode-core-rules-injector 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +66 -10
  2. package/core-rules.md +1 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,23 +1,79 @@
1
1
  # opencode-core-rules-injector
2
2
 
3
- **原理:** 在每次 LLM 调用前,把 `~/.config/opencode/core-rules.md` 的内容注入到 system prompt 里。
4
- 你改那个文件,它就生效,无需重启,无需改 AGENTS.md。
3
+ OpenCode 插件:在每次 LLM 调用前注入核心规则,确保模型始终遵守你的工作流和偏好。
4
+
5
+ ## 作用
6
+
7
+ OpenCode 在长时间自动执行(如 5 小时、100 个任务)时,模型容易忘记用户制定的规则。已有的方式(AGENTS.md、opencode.json instructions)只在会话启动时读取一次,无法防止长任务中的注意力漂移。
8
+
9
+ 这个插件在**每次 LLM 调用前**把 `~/.config/opencode/core-rules.md` 的内容注入到 system prompt 中,让模型每轮都能看到规则,确保始终如一地遵守。
10
+
11
+ ## 实现方法
12
+
13
+ 1. 利用 OpenCode 的 `experimental.chat.system.transform` 钩子,在每个 LLM 调用前修改 system prompt
14
+ 2. 读取 `~/.config/opencode/core-rules.md` 的内容并追加到 system prompt 尾部
15
+ 3. 带 mtime 缓存,文件无变化时不重复读盘
16
+ 4. 首次安装时自动创建 `~/.config/opencode/core-rules.md`(含默认工作流)
17
+ 5. 通过 `postinstall` 脚本自动注册到 `opencode.jsonc/opencode.json` 的 `"plugin"` 数组
18
+
19
+ 三层规则保障:
20
+
21
+ | 层 | 生效时机 | 覆盖范围 |
22
+ |---|---|---|
23
+ | **AGENTS.md**(核心指令+工作流) | 会话启动时 | 主 Agent + 所有子 Agent |
24
+ | **core-rules.md**(插件注入) | 每次 LLM 调用前 | 主 Agent |
25
+ | **AGENTS.md 上下文**(ctx7 等) | 会话启动时 | 主 Agent + 所有子 Agent |
5
26
 
6
27
  ## 安装
7
28
 
8
29
  ```bash
30
+ # 使用 bun(推荐,更快)
31
+ bun install -g opencode-core-rules-injector
32
+
33
+ # 或使用 npm
9
34
  npm install -g opencode-core-rules-injector
10
35
  ```
11
36
 
12
- 然后在 opencode.json 里启用:
37
+ 安装后重启 OpenCode 即可生效。`postinstall` 会自动完成以下操作:
38
+
39
+ - 将 `"opencode-core-rules-injector"` 添加到 `~/.config/opencode/opencode.jsonc` 或 `opencode.json` 的 `"plugin"` 数组
40
+ - 创建 `~/.config/opencode/core-rules.md`(含默认的语言、工具偏好和工作流规则)
13
41
 
14
- ```json
15
- {
16
- "plugin": ["opencode-core-rules-injector"]
17
- }
42
+ ## 自定义规则
43
+
44
+ 编辑 `~/.config/opencode/core-rules.md`,修改立即生效,无需重启:
45
+
46
+ ```markdown
47
+ ## 语言
48
+ 始终使用简体中文输出,包括工具调用描述、思考过程等全部内容。
49
+
50
+ ## 工具偏好
51
+ - **文件内容搜索**: `rg` 而非 `grep`
52
+ - **文件名搜索**: `fd` 而非 `find`
53
+ - **内容替换**: `sd` 而非 `sed`
54
+ - **JSON 处理**: `jq`
55
+ - **HTTP 请求**: `httpie` 而非 `curl`
56
+ - **文件查看**: `bat` 而非 `cat`
57
+ - **包管理**: Python 用 `uv` 而非 `pip3`
58
+ - Rust 三板斧:`rg` + `fd` + `sd`
59
+
60
+ ## 工作流
61
+ ...
62
+ ```
63
+
64
+ ## 更新
65
+
66
+ ```bash
67
+ bun install -g opencode-core-rules-injector@latest
68
+ # 或
69
+ npm install -g opencode-core-rules-injector@latest
18
70
  ```
19
71
 
20
- ## 使用
72
+ ## 发布历史
21
73
 
22
- 编辑 `~/.config/opencode/core-rules.md`,填入你最看重的规则(语言、工具偏好等)。
23
- 每次 LLM 调用会自动注入,修改后立刻生效。
74
+ | 版本 | 说明 |
75
+ |---|---|
76
+ | 1.0.0 | 基础插件:每轮注入 core-rules.md |
77
+ | 1.0.1 | 新增 postinstall 自动注册 |
78
+ | 1.1.0 | 添加完整工作流规则 |
79
+ | 1.1.3 | 拆分 Specs/Plans 目录,明确人工确认边界 |
package/core-rules.md CHANGED
@@ -23,7 +23,7 @@
23
23
  - Plan 中每个 Task 必须写清执行顺序:哪些可并行,哪些必须串行,串行任务依赖哪个前置 Task
24
24
  - Plan 中必须显式标注 Task 间依赖关系和可并行执行标记
25
25
  - 能并行的任务在 Plan 中设计成并行分支
26
- - Specs Plans 保存到 `docs/superpowers/plans/` 下
26
+ - Specs 保存到 `docs/superpowers/specs/`,Plans 保存到 `docs/superpowers/plans/` 下
27
27
 
28
28
  ### 2. 执行阶段(用户确认 Plans 后全自动,无需用户干预)
29
29
  - 使用 Superpowers 的 using-git-worktrees 技能,在 `.worktree/` 下创建隔离功能分支
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-core-rules-injector",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "OpenCode plugin: injects core rules into every LLM call",
5
5
  "type": "module",
6
6
  "main": "index.js",