opencode-core-rules-injector 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # opencode-core-rules-injector
2
+
3
+ **原理:** 在每次 LLM 调用前,把 `~/.config/opencode/core-rules.md` 的内容注入到 system prompt 里。
4
+ 你改那个文件,它就生效,无需重启,无需改 AGENTS.md。
5
+
6
+ ## 安装
7
+
8
+ ```bash
9
+ npm install -g opencode-core-rules-injector
10
+ ```
11
+
12
+ 然后在 opencode.json 里启用:
13
+
14
+ ```json
15
+ {
16
+ "plugin": ["opencode-core-rules-injector"]
17
+ }
18
+ ```
19
+
20
+ ## 使用
21
+
22
+ 编辑 `~/.config/opencode/core-rules.md`,填入你最看重的规则(语言、工具偏好等)。
23
+ 每次 LLM 调用会自动注入,修改后立刻生效。
package/core-rules.md ADDED
@@ -0,0 +1,13 @@
1
+ ## 语言
2
+
3
+ 始终使用简体中文输出,包括工具调用描述、思考过程等全部内容。
4
+
5
+ ## 工具偏好
6
+
7
+ - **文件内容搜索**: `rg` (ripgrep) 而非 `grep`
8
+ - **文件名搜索**: `fd` 而非 `find`
9
+ - **内容替换**: `sd` 而非 `sed`
10
+ - **JSON 处理**: `jq`
11
+ - **HTTP 请求**: `httpie` (`http`/`https`) 而非 `curl`
12
+ - **文件查看**: `bat` 而非 `cat`
13
+ - **包管理**: Python 用 `uv` 而非 `pip3`
package/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import { readFileSync, statSync, existsSync, mkdirSync, writeFileSync } from 'fs';
2
+ import { join, dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ const CONFIG_DIR = join(process.env.HOME || process.env.USERPROFILE, '.config', 'opencode');
7
+ const RULES_FILE = join(CONFIG_DIR, 'core-rules.md');
8
+ const DEFAULT_RULES = join(__dirname, 'core-rules.md');
9
+
10
+ function ensureDefaultRules() {
11
+ if (existsSync(RULES_FILE)) return;
12
+ if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
13
+ if (existsSync(DEFAULT_RULES)) {
14
+ writeFileSync(RULES_FILE, readFileSync(DEFAULT_RULES, 'utf-8'));
15
+ }
16
+ }
17
+
18
+ let rulesCache = null;
19
+ let rulesMtime = 0;
20
+
21
+ function loadRules() {
22
+ try {
23
+ if (!existsSync(RULES_FILE)) return '';
24
+ const { mtimeMs } = statSync(RULES_FILE);
25
+ if (rulesCache && mtimeMs === rulesMtime) return rulesCache;
26
+ rulesMtime = mtimeMs;
27
+ rulesCache = readFileSync(RULES_FILE, 'utf-8').trim();
28
+ return rulesCache;
29
+ } catch {
30
+ return '';
31
+ }
32
+ }
33
+
34
+ ensureDefaultRules();
35
+
36
+ export const CoreRulesInjector = async () => {
37
+ return {
38
+ 'experimental.chat.system.transform': async (_input, output) => {
39
+ const rules = loadRules();
40
+ if (rules) output.system.push(rules);
41
+ },
42
+ };
43
+ };
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "opencode-core-rules-injector",
3
+ "version": "1.0.0",
4
+ "description": "OpenCode plugin: injects core rules into every LLM call",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "files": ["index.js", "core-rules.md"],
8
+ "keywords": ["opencode", "plugin", "rules"],
9
+ "license": "MIT"
10
+ }