opencode-skills-doctor 0.3.2 → 0.3.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 +55 -15
  2. package/README.zh-CN.md +56 -16
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -8,9 +8,24 @@ Local scanner, linter, fixer, updater and **OpenCode plugin** for skills — zer
8
8
 
9
9
  ## Why
10
10
 
11
- On every model step, OpenCode advertises every skill that has a `description` — the model sees `ID + name + description` for each of them. As skills pile up, this turns into **context bloat, colliding descriptions, shadowed IDs, edits to the wrong file, and skills that silently stop working**.
11
+ On every model step, OpenCode advertises every skill that has a `description` — the model sees `ID + name + description` for each of them. Skills are not free: they are a permanent context tax on every request.
12
12
 
13
- `skills-doctor` surfaces all of that locally, and can also update skills from an HTTP catalog and verify the result.
13
+ **What this costs.** 29 skills with long descriptions ≈ **3,000+ tokens every step**. Over a 100-step session that is ~300k tokens of pure overhead — spent before the model reads a single line of your code.
14
+
15
+ **What can go wrong.** As skills pile up:
16
+ - duplicate IDs silently shadow each other — you may be editing a file that never loads;
17
+ - descriptions drift until the model picks the wrong skill;
18
+ - half the catalog is dead weight nobody noticed.
19
+
20
+ **What `skills-doctor` does.** It measures the cost, shows which definition actually wins, and fixes it:
21
+
22
+ - `check` — report duplicates/shadowing, long descriptions, oversized bodies and the per-step token budget, with fix hints;
23
+ - `scan` — list every skill with its source, precedence and cost;
24
+ - `fix` — archive shadowed duplicates (reversible) or hide low-frequency skills (`autoinvoke: false`, still loadable with `@id`);
25
+ - `update` — sync skills from HTTP catalogs by version, with a lockfile and drift detection;
26
+ - plugin — expose the audit as a `skills_doctor` tool / `/skills-doctor` command inside OpenCode.
27
+
28
+ Works as a CLI and a plugin on **OpenCode 1.x and 2.x**.
14
29
 
15
30
  ## Quick start
16
31
 
@@ -114,22 +129,31 @@ It registers:
114
129
 
115
130
  ### OpenCode 1.x
116
131
 
117
- 1.x uses a different plugin API. Point the `plugin` array at the `/v1` entry:
132
+ 1.x uses a different plugin API: it resolves the `./server` export for npm plugins and needs `@opencode-ai/plugin` at runtime. The reliable setup is a one-line local plugin file.
133
+
134
+ 1. Install the package where OpenCode resolves plugins:
135
+
136
+ ```powershell
137
+ npm i --prefix ~/.config/opencode opencode-skills-doctor
138
+ ```
139
+
140
+ 2. Create `~/.config/opencode/plugins/skills-doctor.js`:
141
+
142
+ ```js
143
+ export { SkillsDoctorPlugin } from "opencode-skills-doctor/v1"
144
+ ```
145
+
146
+ 3. Reference it from `opencode.json` (1.x uses `plugin`, not `plugins`):
118
147
 
119
148
  ```jsonc
120
- // opencode.json (1.x)
121
149
  {
122
- "plugin": ["opencode-skills-doctor/v1"]
150
+ "plugin": ["C:\\Users\\<you>\\.config\\opencode\\plugins\\skills-doctor.js"]
123
151
  }
124
152
  ```
125
153
 
126
- It registers the same `skills_doctor` tool (1.x has no `/skills-doctor` command hook). The package must be installed where OpenCode resolves plugins, e.g.:
127
-
128
- ```powershell
129
- npm i --prefix ~/.config/opencode opencode-skills-doctor
130
- ```
154
+ It registers the same `skills_doctor` tool (1.x has no `/skills-doctor` command hook).
131
155
 
132
- > The package root entry (`import "opencode-skills-doctor"`) is the V2 plugin and requires OpenCode 2.x. The CLI works on both lines.
156
+ > The package root entry is the V2 plugin and requires OpenCode 2.x. The CLI works on both lines.
133
157
 
134
158
  ## Rules
135
159
 
@@ -174,12 +198,28 @@ npm i --prefix ~/.config/opencode opencode-skills-doctor
174
198
 
175
199
  `check --json`, `scan --json` and `update --json` all print structured JSON, ready for CI or a web report. Fields include `summary`, `findings[]` and `skills[]` (with `managed: { version, url, root }`).
176
200
 
177
- ## Known limitations
201
+ ## Caveats and known limitations
202
+
203
+ **Install / plugin**
204
+
205
+ - OpenCode **2.x**: add `"plugins": ["opencode-skills-doctor"]` to `opencode.jsonc` — done.
206
+ - OpenCode **1.x**: needs `npm i --prefix ~/.config/opencode opencode-skills-doctor` plus a one-line local plugin file (`export { SkillsDoctorPlugin } from "opencode-skills-doctor/v1"`), because 1.x resolves plugins differently and `@opencode-ai/plugin` is an optional peer.
207
+ - 1.x has **no `/skills-doctor` command** — only the `skills_doctor` tool.
208
+
209
+ **Safety / behavior**
210
+
211
+ - `fix` defaults to **project-only**; pass `--all` to touch global sources. Archived files go to `.skills-doctor-archive/<timestamp>/` (reversible; originals are moved, not deleted).
212
+ - `fix` only touches **shadowed** definitions. It never edits the effective skill and never rewrites descriptions or bodies.
213
+ - `fix --hide` only adds `metadata.opencode/autoinvoke: false`; the skill stays loadable with `@id`.
214
+ - Shadowing follows OpenCode's precedence: later registration wins; on a tie, the `SKILL.md` directory form wins. If the runtime disagrees, trust the runtime.
215
+ - This is **not** a security sandbox: it audits configuration and files, it does not constrain what the agent can do.
216
+
217
+ **Measurement**
178
218
 
179
- - `check` is offline; use `update --check-only` to ask a catalog for new versions.
219
+ - The default `budget` (1200 tokens) is a recommendation, not a hard limit. Tune it with `.skills-doctor.json` or `--budget`.
180
220
  - Token counts are heuristic (CJK ≈ 1.7 chars/token, the rest ≈ 4 chars/token) — good for comparisons, not for billing.
181
- - Config precedence is assumed: global config < project config < `skills` array order. If OpenCode differs, trust the runtime.
182
- - No automatic file rewriting yet (v0.2 plans `--fix`: archive shadowed definitions, normalize IDs, trim descriptions).
221
+ - `check` is offline; ask a catalog for new versions with `update --check-only`.
222
+ - Config precedence is assumed: global config < project config < `skills` array order.
183
223
 
184
224
  ## Roadmap
185
225
 
package/README.zh-CN.md CHANGED
@@ -8,9 +8,24 @@ OpenCode skill 的**本地检测器 + 更新器 + 修复器**,并附带 **Open
8
8
 
9
9
  ## 为什么需要它
10
10
 
11
- opencode 每个模型步骤都会把所有「有 description 的 skill」展示给模型(`ID + name + description`)。skill 一多、一杂,就会出现**上下文膨胀、描述撞车、同 ID 互相遮蔽、改错文件、静默失效**。
11
+ opencode 每个模型步骤都会把所有「有 description 的 skill」展示给模型(`ID + name + description`)。skill 不是免费的——它是**每一次请求都要交的上下文税**。
12
12
 
13
- `skills-doctor` 在本地把这些都查出来,并且能从 HTTP catalog 更新 skill、校验更新结果。
13
+ **成本有多大**:29 个 skill、描述偏长,就是**每步 3000+ tokens**。一次 100 步的会话,光 skill 目录就烧掉约 30 万 tokens,模型还没开始读你一行代码。
14
+
15
+ **会出什么问题**:skill 越攒越多,就会出现
16
+ - 同 ID 互相遮蔽——你改的可能是一份永远不会加载的文件;
17
+ - 描述越来越像,模型选错 skill;
18
+ - 一堆没人注意的死重。
19
+
20
+ **`skills-doctor` 做什么**:把成本量出来、把「谁真正生效」指出来,并直接修:
21
+
22
+ - `check` —— 报告重复/遮蔽、超长描述、超大正文、每步 token 预算,并给修复建议;
23
+ - `scan` —— 列出每个 skill 的来源、优先级和成本;
24
+ - `fix` —— 归档被遮蔽的重复定义(可逆),或隐藏低频 skill(`autoinvoke: false`,仍可 `@id` 加载);
25
+ - `update` —— 按版本从 HTTP catalog 同步 skill,带 lockfile 和 drift 检测;
26
+ - 插件 —— 在 OpenCode 会话里暴露 `skills_doctor` 工具 / `/skills-doctor` 命令。
27
+
28
+ CLI 和插件都同时支持 **OpenCode 1.x 和 2.x**。
14
29
 
15
30
  ## 快速开始
16
31
 
@@ -114,22 +129,31 @@ skills-doctor update --into .\team-skills
114
129
 
115
130
  ### OpenCode 1.x
116
131
 
117
- 1.x 用的是另一套插件 API,把 `plugin` 数组指向 `/v1` 入口:
132
+ 1.x 用的是另一套插件 API:npm 插件会解析 `./server` 导出,运行时需要 `@opencode-ai/plugin`。最稳的接法是加一个一行的本地插件文件。
133
+
134
+ 1. 先把包装到 OpenCode 解析插件的位置:
135
+
136
+ ```powershell
137
+ npm i --prefix ~/.config/opencode opencode-skills-doctor
138
+ ```
139
+
140
+ 2. 新建 `~/.config/opencode/plugins/skills-doctor.js`:
141
+
142
+ ```js
143
+ export { SkillsDoctorPlugin } from "opencode-skills-doctor/v1"
144
+ ```
145
+
146
+ 3. 在 `opencode.json` 里引用(1.x 用 `plugin`,不是 `plugins`):
118
147
 
119
148
  ```jsonc
120
- // opencode.json(1.x)
121
149
  {
122
- "plugin": ["opencode-skills-doctor/v1"]
150
+ "plugin": ["C:\\Users\\<you>\\.config\\opencode\\plugins\\skills-doctor.js"]
123
151
  }
124
152
  ```
125
153
 
126
- 它会注册同样的 `skills_doctor` 工具(1.x 没有 `/skills-doctor` 命令钩子)。需要把包装在 OpenCode 能解析插件的位置,例如:
127
-
128
- ```powershell
129
- npm i --prefix ~/.config/opencode opencode-skills-doctor
130
- ```
154
+ 它会注册同样的 `skills_doctor` 工具(1.x 没有 `/skills-doctor` 命令钩子)。
131
155
 
132
- > 包根入口(`import "opencode-skills-doctor"`)是 V2 插件,需要 OpenCode 2.x;CLI 两条线都能用。
156
+ > 包根入口是 V2 插件,需要 OpenCode 2.x;CLI 两条线都能用。
133
157
 
134
158
  ## 检测规则
135
159
 
@@ -174,12 +198,28 @@ npm i --prefix ~/.config/opencode opencode-skills-doctor
174
198
 
175
199
  `check --json` / `scan --json` / `update --json` 都会输出结构化 JSON,方便接 CI 或做网页报告。字段包括 `summary`、`findings[]`、`skills[]`(含 `managed: { version, url, root }`)。
176
200
 
177
- ## 已知限制
201
+ ## 注意事项与已知限制
202
+
203
+ **安装 / 插件**
204
+
205
+ - OpenCode **2.x**:在 `opencode.jsonc` 加 `"plugins": ["opencode-skills-doctor"]` 即可。
206
+ - OpenCode **1.x**:需要 `npm i --prefix ~/.config/opencode opencode-skills-doctor`,再加一个一行本地插件文件(`export { SkillsDoctorPlugin } from "opencode-skills-doctor/v1"`)——因为 1.x 解析插件的机制不同,且 `@opencode-ai/plugin` 是可选 peer 依赖。
207
+ - 1.x **没有 `/skills-doctor` 命令**,只有 `skills_doctor` 工具。
208
+
209
+ **安全性 / 行为**
210
+
211
+ - `fix` 默认**只处理项目内**;要动全局来源加 `--all`。归档文件进入 `.skills-doctor-archive/<时间戳>/`(可逆,是移动不是删除)。
212
+ - `fix` 只处理**被遮蔽**的定义,永远不改生效版本,也不会重写描述或正文。
213
+ - `fix --hide` 只加 `metadata.opencode/autoinvoke: false`,skill 仍可用 `@id` 加载。
214
+ - 遮蔽判定遵循 OpenCode 优先级:注册越后越优先;同序时 `SKILL.md` 目录形式优先。如与实际运行不一致,以实际运行为准。
215
+ - 它**不是安全沙箱**:只审计配置和文件,不限制 agent 能做什么。
216
+
217
+ **度量**
178
218
 
179
- - 不联网时 `check` 只做本地检查;catalog 是否有新版本要用 `update --check-only`。
180
- - token 估算是启发式(CJK 约 1.7 字/token,其余约 4 字符/token),用于横向比较,不是精确计费。
181
- - 配置优先级假设:全局配置 < 项目配置 < `skills` 数组顺序;如与 opencode 实现有出入,以实际加载结果为准。
182
- - 还不会自动改文件(v0.2 计划加 `--fix`:归档被遮蔽的定义、规范化 ID、裁剪描述)。
219
+ - 默认 `budget`(1200 tokens)是建议值,不是硬限制;用 `.skills-doctor.json` 或 `--budget` 调整。
220
+ - token 是启发式估算(CJK 约 1.7 字/token,其余约 4 字符/token),用于横向比较,不是精确计费。
221
+ - `check` 不联网;要看 catalog 新版本用 `update --check-only`。
222
+ - 配置优先级假设:全局配置 < 项目配置 < `skills` 数组顺序。
183
223
 
184
224
  ## Roadmap
185
225
 
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "opencode-skills-doctor",
3
- "version": "0.3.2",
4
- "description": "Local scanner, linter, fixer and updater for OpenCode skills, with OpenCode 2.x and 1.x plugin entries",
3
+ "version": "0.3.4",
4
+ "description": "Audit, fix and update OpenCode skills: measure per-step context cost, catch shadowed duplicates, archive safely and sync from catalogs. Works on OpenCode 1.x and 2.x.",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./src/plugin.mjs",
8
8
  "./plugin": "./src/plugin.mjs",
9
+ "./server": "./src/plugin-v1.mjs",
9
10
  "./v1": "./src/plugin-v1.mjs",
10
11
  "./audit": "./src/audit.mjs"
11
12
  },