skill-evolution 0.1.0 → 0.1.1

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/CHANGELOG.md CHANGED
@@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
 
15
15
  ## [Unreleased]
16
16
 
17
+ ## [0.1.1] - 2026-11-29
18
+
19
+ ### Fixed
20
+ - Default the standalone HTTP listener to loopback (`127.0.0.1:18890`), add `httpEnabled` / `httpHost` / `httpPort` / `httpToken`, refuse non-loopback binds without a token, and use `httpToken` with constant-time SHA-256 digest comparison to guard all API and mobile HTML routes on that port; `DSH_EVOLUTION_PORT` still overrides the port. The host-mounted `/dsh-evolution` prefix is guarded by the host Connection fence (`requestRejection`), not `httpToken`, so the desktop workbench keeps working when a token is set.
21
+ - Remove the bundled global `tool-skill.catalogDescriptionMaxLength` override; document it as an optional user-side setting that affects every skill.
22
+ - Disable automatic evolution by default in the schema and bundle, including curator background work while disabled. Document review model costs, session excerpt limits, and draft storage; keep the workbench available while disabled.
23
+
24
+ ### Changed
25
+ - Declare Node `>=20.11` and DSH `>=0.2.2-rc.1 <0.3.0` compatibility.
26
+
17
27
  ## [0.3.1] - 2026-11-10
18
28
 
19
29
  ### Added
package/README.en.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![CI](https://github.com/veritaswiki/skill-evolution/actions/workflows/ci.yml/badge.svg)](https://github.com/veritaswiki/skill-evolution/actions/workflows/ci.yml)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
5
5
  [![Node](https://img.shields.io/badge/Node-%3E%3D20.11-informational.svg)](#development)
6
- [![Tests](https://img.shields.io/badge/tests-70%20passed-34d399.svg)](#development)
6
+ [![Tests](https://img.shields.io/badge/tests-80%20passed-34d399.svg)](#development)
7
7
  [![Hermes parity](https://img.shields.io/badge/Hermes%20parity-41%2F41-8b7cf6.svg)](#capability-parity-and-audits)
8
8
 
9
9
  > In DSH the `skill` tool can load skills but cannot write them back. This plugin adds that write-back path: after a turn ends it reviews the session, distills the lesson into a skill draft, runs four code-level gates, and waits for your directive — with a ledger and single-entry rollback.
@@ -101,21 +101,18 @@ Prefix `/dsh-evolution`; `GET /dsh-evolution/mobile` returns the standalone mobi
101
101
  dsh plugin add github:veritaswiki/skill-evolution
102
102
  ```
103
103
 
104
- Then add the package name to that profile's `dsh.profile.bundles` and restart DSH. The plugin's own `cordis.patch.yml` carries the defaults (it tightens the DSH skill catalog description cap from 500 to 80 chars, and inserts its own config).
104
+ Then add the package name to that profile's `dsh.profile.bundles` and restart DSH. The plugin's own `cordis.patch.yml` inserts only its own config, with automatic evolution disabled. It does not change the global skill catalog description limit.
105
105
 
106
106
  **Option B: config file**
107
107
 
108
108
  Skip the bundle and write into `~/.dsh/cordis.patch.yml`:
109
109
 
110
110
  ```yaml
111
- - id: tool-skill
112
- config:
113
- catalogDescriptionMaxLength: 80
114
111
  - insert:
115
112
  - id: skill-evolution
116
113
  name: 'skill-evolution'
117
114
  config:
118
- enabled: true
115
+ enabled: false
119
116
  mode: draft
120
117
  ```
121
118
 
@@ -128,6 +125,22 @@ dsh plugin add ./skill-evolution
128
125
 
129
126
  After installing, `/evolution status` should show the skills root, mode, skill count, draft count and ledger entry count.
130
127
 
128
+ ### Before you enable it
129
+
130
+ Automatic evolution is off by default (`enabled: false`). Each reviewed turn adds one extra model call; a host review fork can make further calls while using its read-only tools. The review model receives a session excerpt bounded by `maxMessages: 24` recent messages (plus an older-message digest) and `maxChars: 24000` total characters. Review your provider's privacy and billing terms before enabling it. The default `mode: draft` writes generated skill content only to `~/.dsh/skills/.staging/` (or `<skillsRoot>/.staging/`); ledger and telemetry sidecars also live under the skills root. Promotion requires an explicit action.
131
+
132
+ Enable it in the Web UI settings or set `enabled: true` in your plugin config after reviewing these costs and privacy implications. Background collection, reviews and curator work stay inactive while disabled; the Web UI and explicit manual actions remain available.
133
+
134
+ ### Optional global catalog limit
135
+
136
+ If you want shorter catalog descriptions, you can add this **opt-in, global** snippet to your own `~/.dsh/cordis.patch.yml`. It changes the displayed catalog description limit for **every skill in that profile**, not just skills created by this plugin. The bundle no longer applies it automatically. The plugin's own 80-character draft validation is separate.
137
+
138
+ ```yaml
139
+ - id: tool-skill
140
+ config:
141
+ catalogDescriptionMaxLength: 80
142
+ ```
143
+
131
144
  ---
132
145
 
133
146
  ## Configuration
@@ -136,7 +149,11 @@ Defaults in `cordis.patch.yml` match the Schemastery definition in `index.js`:
136
149
 
137
150
  | Key | Type | Default | Meaning |
138
151
  |---|---|---|---|
139
- | `enabled` | boolean | `true` | Enable post-turn review |
152
+ | `enabled` | boolean | `false` | Enable automatic collection, post-turn review and curator work |
153
+ | `httpEnabled` | boolean | `true` | Start the standalone HTTP listener; the mounted host route remains available |
154
+ | `httpHost` | string | `"127.0.0.1"` | Standalone bind address; non-loopback requires `httpToken` |
155
+ | `httpPort` | number | `18890` | Standalone port; overridden by `DSH_EVOLUTION_PORT` |
156
+ | `httpToken` | string | `""` | When set, required on every HTTP API and mobile HTML request, including mounted host routes |
140
157
  | `skillsRoot` | string | `""` (→ `~/.dsh/skills`) | Skills root; drafts, ledger and telemetry live here |
141
158
  | `mode` | `"draft" \| "apply"` | `"draft"` | `draft` writes only to `.staging/`; `apply` writes into the library after the gates |
142
159
  | `minTurnsBetween` | number | `1` | Minimum reviewable turns between two reviews |
@@ -160,9 +177,28 @@ Environment variables (all optional):
160
177
  | `DSH_EVOLUTION_BASE_URL` | OpenAI-compatible auxiliary endpoint (e.g. `https://host/v1`). Unset means reviews go through the host subagent fork |
161
178
  | `DSH_EVOLUTION_API_KEY` | Bearer token for that endpoint |
162
179
  | `DSH_EVOLUTION_MODEL` | Model name used on that endpoint |
163
- | `DSH_EVOLUTION_PORT` | Fixed port for the standalone mobile service, default `18890` |
180
+ | `DSH_EVOLUTION_PORT` | Override `httpPort` for the standalone mobile service |
164
181
  | `DSH_HOME` | DSH home directory, default `~/.dsh` |
165
182
 
183
+ ### HTTP access from a phone
184
+
185
+ The standalone service defaults to `127.0.0.1:18890`, reachable only on the same machine. `httpEnabled: false` disables this listener. Changes to `httpEnabled`, `httpHost` or `httpPort` require a plugin restart; token changes apply to the next request. The mounted `/dsh-evolution` route also runs the host Connection authentication and Host/Origin checks when available; older hosts without that service or method continue with the plugin's token check.
186
+
187
+ For LAN or Tailscale access, generate a strong token (for example, `openssl rand -hex 32`), set it as `httpToken`, and bind to your computer's LAN/Tailscale IP (or explicitly `0.0.0.0`). A non-loopback listener refuses to start without a token and logs a warning. Example user-side plugin config:
188
+
189
+ ```yaml
190
+ - id: skill-evolution
191
+ config:
192
+ httpEnabled: true
193
+ httpHost: '0.0.0.0'
194
+ httpPort: 18890
195
+ httpToken: '<replace-with-your-generated-token>'
196
+ ```
197
+
198
+ Restart the plugin, then open `http://<computer-LAN-or-Tailscale-IP>:18890/dsh-evolution/mobile?token=<URL-encoded-token>` on your phone. The page forwards this token as a Bearer header on its API calls. Every request, including `/`, `/dsh-evolution` and `/dsh-evolution/mobile`, requires either `Authorization: Bearer <token>` or `?token=<token>` when a token is configured. The desktop Web UI can likewise use `?token=<URL-encoded-token>` on its URL. Tokens are compared using `crypto.timingSafeEqual` on equal-length SHA-256 digests; missing or incorrect tokens receive 401. The token is never included in status/config responses.
199
+
200
+ Treat the token URL as a password: it may remain in browser history. Plain HTTP does not encrypt the token or session-derived data; use Tailscale's encrypted network or an HTTPS reverse proxy for remote access. On the host-mounted route, the plugin token supplements the host's own login rather than replacing it.
201
+
166
202
  ### Commands and tools
167
203
 
168
204
  `/evolution` subcommands: `brief [name]` / `drafts`, `refine <name> <directive>`, `approve <name> <directive>` (`promote` is an alias and also requires a directive), `reject <name> <directive>` (`discard` is an alias), `ledger`, `skills`, `adopt <name>`, `disown <name>`, `rollback <id>`, `review`, `consolidate [--apply]`, `status` (default).
@@ -177,7 +213,7 @@ The `evolution_review_center` tool targets chat and mobile clients: `action` is
177
213
  - **Gates cannot judge value**: the four gates are static checks (name, frontmatter, forbidden content, size). Whether a lesson is worth recording is still the model's call, so drafts need a human read.
178
214
  - **The UI is Chinese only**: `locale/en.json` covers just the plugin name and description; the workbench has no English UI.
179
215
  - **Interactive cards need host support**: `evolution_review_center` asks through the host `userQuestions` service. Without it, the tool falls back to Chinese briefing text and the user replies with a directive.
180
- - **The local HTTP API has no authentication**: the fixed-port service binds `0.0.0.0:18890` for local or trusted-network use; if the port is taken it silently skips.
216
+ - **Remote HTTP needs explicit setup**: loopback is the default; LAN/Tailscale exposure requires a token. Listener errors are logged. See the phone-access section for encrypted transport and host authentication requirements.
181
217
  - **`mode: apply` writes the real skill library**: only for skills with `metadata.createdBy: agent`; the default is still `draft`.
182
218
  - **Archiving does not free disk**: skills move to `.archive/` and you delete them yourself.
183
219
  - **Body cap is 24000 chars**: beyond that, depth has to go into `references/`.
@@ -187,13 +223,13 @@ The `evolution_review_center` tool targets chat and mobile clients: `action` is
187
223
  ## Development
188
224
 
189
225
  ```bash
190
- npm test # 70 unit tests (node --test test/*.test.js)
226
+ npm test # 80 tests, including HTTP security (node --test test/*.test.mjs)
191
227
  npm run audit:parity # 41-item capability audit (37 Hermes capabilities + 4 DSH-only)
192
228
  npm run audit:prompts # byte-level prompt fidelity (LESSON_LAYER_BLOCK / _DO_NOT_CAPTURE_BLOCK)
193
229
  npm run sanitize # sanitization gate, must report 0 hits
194
230
  ```
195
231
 
196
- Requires Node ≥ 20.11 (`tools/*.mjs` use `import.meta.dirname`). CI runs the syntax check, the 70 tests, both audits and the sanitization gate.
232
+ Requires Node ≥ 20.11 (`tools/*.mjs` use `import.meta.dirname`) and DSH `>=0.2.2-rc.1 <0.3.0`. CI runs the syntax check, unit tests, both audits and the sanitization gate.
197
233
 
198
234
  ### Capability parity and audits
199
235
 
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![CI](https://github.com/veritaswiki/skill-evolution/actions/workflows/ci.yml/badge.svg)](https://github.com/veritaswiki/skill-evolution/actions/workflows/ci.yml)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
5
5
  [![Node](https://img.shields.io/badge/Node-%3E%3D20.11-informational.svg)](#开发)
6
- [![Tests](https://img.shields.io/badge/tests-70%20passed-34d399.svg)](#开发)
6
+ [![Tests](https://img.shields.io/badge/tests-80%20passed-34d399.svg)](#开发)
7
7
  [![Hermes parity](https://img.shields.io/badge/Hermes%20parity-41%2F41-8b7cf6.svg)](#能力对齐与审计)
8
8
 
9
9
  > DSH 的 `skill` 工具只能加载技能,不能写回技能。这个插件补上写回的那一段:回合结束后自动复盘会话、把经验蒸馏成技能草稿、过四道代码级闸门后等你批示,全程记账、可单条回滚。
@@ -101,21 +101,18 @@
101
101
  dsh plugin add github:veritaswiki/skill-evolution
102
102
  ```
103
103
 
104
- 然后把包名加入该 profile 的 `dsh.profile.bundles`,重启 DSH。插件自己的 `cordis.patch.yml` 会带上默认配置(把 DSH 技能目录描述上限从 500 收到 80 字符,并对本插件 `insert` 一份配置)。
104
+ 然后把包名加入该 profile 的 `dsh.profile.bundles`,重启 DSH。插件自己的 `cordis.patch.yml` 只插入本插件配置,默认关闭自动进化,不再修改全局技能目录描述上限。
105
105
 
106
106
  **方式 B:配置文件**
107
107
 
108
108
  不装 bundle,直接在 `~/.dsh/cordis.patch.yml` 写:
109
109
 
110
110
  ```yaml
111
- - id: tool-skill
112
- config:
113
- catalogDescriptionMaxLength: 80
114
111
  - insert:
115
112
  - id: skill-evolution
116
113
  name: 'skill-evolution'
117
114
  config:
118
- enabled: true
115
+ enabled: false
119
116
  mode: draft
120
117
  ```
121
118
 
@@ -128,6 +125,22 @@ dsh plugin add ./skill-evolution
128
125
 
129
126
  装好之后,`/evolution status` 应能看到技能根目录、模式、技能数、待审草稿数与账本条数。
130
127
 
128
+ ### Before you enable it(启用前须知)
129
+
130
+ 自动进化默认关闭(`enabled: false`)。每个实际复盘的回合会增加一次模型调用;宿主复盘 fork 使用只读工具时还可能继续调用模型。复盘模型会收到会话摘录,默认预算为 `maxMessages: 24` 条最近消息(另加更早消息的摘要),摘录总长度受 `maxChars: 24000` 字符限制。启用前请确认模型服务商的隐私与计费规则。默认 `mode: draft` 只把生成的技能内容写到 `~/.dsh/skills/.staging/`(或 `<skillsRoot>/.staging/`);账本与遥测旁路文件也保存在技能根目录。提升到正式库需要显式操作。
131
+
132
+ 确认费用与隐私影响后,在 Web UI 设置中启用,或在插件配置中设 `enabled: true`。关闭时不执行后台采集、复盘与 curator 维护;Web UI 和显式手动操作仍可使用。
133
+
134
+ ### 可选的全局目录描述上限
135
+
136
+ 如果需要缩短目录描述,可自行把下面的**显式选择、全局生效**片段加入 `~/.dsh/cordis.patch.yml`。它会修改**该 profile 内所有技能**的目录描述展示上限,而不只影响本插件生成的技能。bundle 不再自动应用它;插件自身对草稿描述的 80 字符校验是另一项独立规则。
137
+
138
+ ```yaml
139
+ - id: tool-skill
140
+ config:
141
+ catalogDescriptionMaxLength: 80
142
+ ```
143
+
131
144
  ---
132
145
 
133
146
  ## 配置
@@ -136,7 +149,11 @@ dsh plugin add ./skill-evolution
136
149
 
137
150
  | 键 | 类型 | 默认值 | 说明 |
138
151
  |---|---|---|---|
139
- | `enabled` | boolean | `true` | 是否启用回合后自动复盘 |
152
+ | `enabled` | boolean | `false` | 是否启用自动采集、回合后复盘与 curator 维护 |
153
+ | `httpEnabled` | boolean | `true` | 是否启动独立 HTTP 服务;不影响宿主挂载路由 |
154
+ | `httpHost` | string | `"127.0.0.1"` | 独立服务监听地址;非回环地址必须配置 `httpToken` |
155
+ | `httpPort` | number | `18890` | 独立服务端口;可由 `DSH_EVOLUTION_PORT` 覆盖 |
156
+ | `httpToken` | string | `""` | 非空时每个 HTTP API 与手机 HTML 请求均须认证,包括宿主挂载路由 |
140
157
  | `skillsRoot` | string | `""`(→ `~/.dsh/skills`) | 技能根目录;草稿、账本、遥测都放这里 |
141
158
  | `mode` | `"draft" \| "apply"` | `"draft"` | `draft` 只写 `.staging/`;`apply` 过闸后直接落盘 |
142
159
  | `minTurnsBetween` | number | `1` | 两次复盘之间至少间隔多少个可复盘回合 |
@@ -160,9 +177,28 @@ dsh plugin add ./skill-evolution
160
177
  | `DSH_EVOLUTION_BASE_URL` | OpenAI-compatible 辅助端点(如 `https://host/v1`)。不设则复盘走宿主 subagent fork |
161
178
  | `DSH_EVOLUTION_API_KEY` | 辅助端点的 Bearer token |
162
179
  | `DSH_EVOLUTION_MODEL` | 辅助端点使用的模型名 |
163
- | `DSH_EVOLUTION_PORT` | 独立手机端服务的固定端口,默认 `18890` |
180
+ | `DSH_EVOLUTION_PORT` | 覆盖独立手机端服务的 `httpPort` |
164
181
  | `DSH_HOME` | DSH 主目录,默认 `~/.dsh` |
165
182
 
183
+ ### 手机 HTTP 访问
184
+
185
+ 独立服务默认监听 `127.0.0.1:18890`,仅本机可达。`httpEnabled: false` 可关闭此监听器。修改 `httpEnabled`、`httpHost` 或 `httpPort` 后需重启插件;令牌修改在下次请求生效。挂载到宿主的 `/dsh-evolution` 路由会先执行宿主 Connection 的认证与 Host/Origin 检查;旧宿主没有该服务或方法时继续执行插件自己的令牌检查。
186
+
187
+ 如需从 LAN 或 Tailscale 访问,先生成强令牌(例如 `openssl rand -hex 32`),写入 `httpToken`,并把监听地址改成电脑的 LAN/Tailscale IP(也可显式设 `0.0.0.0`)。非回环监听地址未配置令牌时拒绝启动,并记录警告。用户侧插件配置示例:
188
+
189
+ ```yaml
190
+ - id: skill-evolution
191
+ config:
192
+ httpEnabled: true
193
+ httpHost: '0.0.0.0'
194
+ httpPort: 18890
195
+ httpToken: '<替换为自行生成的令牌>'
196
+ ```
197
+
198
+ 重启插件后,在手机打开 `http://<电脑的LAN或Tailscale-IP>:18890/dsh-evolution/mobile?token=<URL编码后的令牌>`。页面会把令牌作为 Bearer 请求头传给后续 API。设置令牌后,每个请求(包括 `/`、`/dsh-evolution` 和 `/dsh-evolution/mobile`)都必须带 `Authorization: Bearer <token>` 或 `?token=<token>`。桌面 Web UI 也可在地址后加 `?token=<URL编码后的令牌>`。令牌先各自计算 SHA-256,再用 `crypto.timingSafeEqual` 比较等长摘要;缺失或错误均返回 401。状态与配置响应不会包含令牌。
199
+
200
+ 请把令牌 URL 当作密码保管,它可能留在浏览器历史中。普通 HTTP 不加密令牌与会话衍生数据;远程访问应使用 Tailscale 加密网络或 HTTPS 反向代理。宿主挂载路由仍需宿主自身登录,插件令牌是额外的一层认证。
201
+
166
202
  ### 命令与工具
167
203
 
168
204
  `/evolution` 子命令:`brief [name]` / `drafts`、`refine <name> <批示>`、`approve <name> <批示>`(`promote` 同义,同样必须带批示)、`reject <name> <批示>`(`discard` 同义)、`ledger`、`skills`、`adopt <name>`、`disown <name>`、`rollback <id>`、`review`、`consolidate [--apply]`、`status`(默认)。
@@ -177,7 +213,7 @@ dsh plugin add ./skill-evolution
177
213
  - **闸门挡不住「没价值」**:四道闸门只做静态检查(命名、frontmatter、禁词、体积),「这条经验值不值得记」仍由模型判断,草稿需要人看。
178
214
  - **界面只有中文**:`locale/en.json` 只覆盖插件名与描述,工作台没有英文 UI。
179
215
  - **交互卡片依赖宿主**:`evolution_review_center` 的卡片走宿主 `userQuestions` 服务;宿主没有这个服务时退化为返回中文简报文本,需要用户直接回复批示。
180
- - **本地 HTTP 无鉴权**:固定端口服务绑 `0.0.0.0:18890`,供本机或可信网络使用;端口被占用时静默跳过。
216
+ - **远程 HTTP 需显式配置**:默认只监听回环地址,LAN/Tailscale 暴露必须设置令牌;监听错误会记录日志。加密传输与宿主认证要求见手机访问说明。
181
217
  - **`mode: apply` 会直接改正式技能库**:只对 `metadata.createdBy: agent` 的技能生效,默认仍是 `draft`。
182
218
  - **归档不释放磁盘**:移进 `.archive/`,要回收得自己删。
183
219
  - **正文上限 24000 字符**:超了必须拆到 `references/`。
@@ -187,13 +223,13 @@ dsh plugin add ./skill-evolution
187
223
  ## 开发
188
224
 
189
225
  ```bash
190
- npm test # 70 个单元测试(node --test test/*.test.js)
226
+ npm test # 80 个测试,含 HTTP 安全回归(node --test test/*.test.mjs)
191
227
  npm run audit:parity # 41 项能力对齐审计(37 项 Hermes 能力 + 4 项 DSH 独有)
192
228
  npm run audit:prompts # 两段提示词逐字节保真度(LESSON_LAYER_BLOCK / _DO_NOT_CAPTURE_BLOCK)
193
229
  npm run sanitize # 脱敏门禁,0 命中才通过
194
230
  ```
195
231
 
196
- 需要 Node ≥ 20.11(`tools/*.mjs` 用 `import.meta.dirname`)。CI 会跑语法检查、70 个测试、两道审计和脱敏门禁。
232
+ 需要 Node ≥ 20.11(`tools/*.mjs` 用 `import.meta.dirname`),DSH 版本范围为 `>=0.2.2-rc.1 <0.3.0`。CI 会跑语法检查、单元测试、两道审计和脱敏门禁。
197
233
 
198
234
  ### 能力对齐与审计
199
235
 
package/client.js CHANGED
@@ -17,9 +17,10 @@ window.__ModuleLoader__.load({
17
17
  const API_BASE = '/dsh-evolution/api';
18
18
 
19
19
  async function api(endpoint, options = {}) {
20
+ const token = new URLSearchParams(window.location.search).get('token');
20
21
  const res = await fetch(`${API_BASE}${endpoint}`, {
21
- headers: { 'Content-Type': 'application/json' },
22
22
  ...options,
23
+ headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}), ...options.headers },
23
24
  });
24
25
  const data = await res.json().catch(() => ({}));
25
26
  if (!res.ok || data.ok === false) {
package/cordis.patch.yml CHANGED
@@ -3,19 +3,20 @@
3
3
  # 让 DSH 拥有 Hermes 的 closed learning loop:
4
4
  # 回合结束 → 采集快照 → fork 只读复盘 → 蒸馏成技能 → 闸门校验 → 落盘草稿 → 记账
5
5
  #
6
- # 默认启用:装上即开始工作,但只产草稿(见下方 mode),不会自动改写技能库。
6
+ # 默认关闭:确认额外模型费用与会话摘录的隐私影响后,再将 enabled 改为 true。
7
7
  #
8
8
  # ⚠️ 默认 mode: draft —— 只写 ~/.dsh/skills/.staging/ 等人工审阅,
9
9
  # 绝不自动改写正式技能库。确认草稿质量后可用 /evolution approve <name> <批示> 提升。
10
- # 对齐 Hermes SKILL_PROMPT_DESC_LIMIT:将 DSH 全局技能目录描述上限从 500 收紧至 80 字符,防止目录膨胀
11
- - id: tool-skill
12
- config:
13
- catalogDescriptionMaxLength: 80
14
10
  - insert:
15
11
  - id: skill-evolution
16
12
  name: 'skill-evolution'
17
13
  config:
18
- enabled: true
14
+ enabled: false
15
+ # 独立手机 HTTP 服务;非回环监听地址必须配置非空 httpToken
16
+ httpEnabled: true
17
+ httpHost: '127.0.0.1'
18
+ httpPort: 18890
19
+ httpToken: ''
19
20
  mode: draft
20
21
  # 技能根目录留空 = ~/.dsh/skills
21
22
  skillsRoot: ''
package/index.js CHANGED
@@ -30,7 +30,12 @@ export const name = "skill-evolution";
30
30
  export const inject = ["agents", "subagents", "commands", "tools"];
31
31
 
32
32
  export const Config = z.object({
33
- enabled: z.boolean().default(true).description("是否启用 DSH 自进化复盘"),
33
+ enabled: z.boolean().default(false).description("是否启用 DSH 自进化复盘(默认关闭,确认费用与隐私后启用)"),
34
+
35
+ httpEnabled: z.boolean().default(true).description("是否启动独立 HTTP 手机审批服务"),
36
+ httpHost: z.string().default("127.0.0.1").description("独立 HTTP 监听地址;非回环地址必须设置 httpToken"),
37
+ httpPort: z.number().default(18890).description("独立 HTTP 端口;DSH_EVOLUTION_PORT 可覆盖"),
38
+ httpToken: z.string().default("").description("HTTP 访问令牌;设置后所有 API 和手机页面均需认证"),
34
39
 
35
40
  skillsRoot: z
36
41
  .string()
@@ -82,6 +87,10 @@ function loadPersistedSettings(config) {
82
87
  if (!saved || typeof saved !== "object") return;
83
88
  for (const key of [
84
89
  "enabled",
90
+ "httpEnabled",
91
+ "httpHost",
92
+ "httpPort",
93
+ "httpToken",
85
94
  "mode",
86
95
  "minTurnsBetween",
87
96
  "minMinutesBetween",
@@ -269,6 +278,7 @@ export function apply(ctx, rawConfig = {}) {
269
278
  let curatorTimer;
270
279
  if (config.curatorEnabled) {
271
280
  const runCurator = async () => {
281
+ if (!config.enabled || !config.curatorEnabled) return;
272
282
  try {
273
283
  // 3a. 确定性状态转换(不需要模型)
274
284
  const counts = await applyAutomaticTransitions(skillsRoot, {
@@ -699,6 +709,10 @@ export function apply(ctx, rawConfig = {}) {
699
709
  if (!patch || typeof patch !== "object") return;
700
710
  for (const key of [
701
711
  "enabled",
712
+ "httpEnabled",
713
+ "httpHost",
714
+ "httpPort",
715
+ "httpToken",
702
716
  "mode",
703
717
  "minTurnsBetween",
704
718
  "minMinutesBetween",
package/lib/http-api.js CHANGED
@@ -24,6 +24,8 @@
24
24
  import fs from "node:fs/promises";
25
25
  import http from "node:http";
26
26
  import path from "node:path";
27
+ import { createHash, timingSafeEqual } from "node:crypto";
28
+ import { isIP } from "node:net";
27
29
 
28
30
  import { readEntries, rollbackEntry, appendEntry, captureSnapshot } from "./ledger.js";
29
31
  import { listSkills, listDrafts, promoteDraft, STAGING_DIRNAME } from "./applier.js";
@@ -43,6 +45,24 @@ function sendJson(res, status, payload) {
43
45
  res.end(body);
44
46
  }
45
47
 
48
+ function isLoopbackHost(host) {
49
+ if (host.toLowerCase() === "localhost") return true;
50
+ if (isIP(host) === 4) return host.startsWith("127.");
51
+ return isIP(host) === 6 && new URL(`http://[${host}]/`).hostname === "[::1]";
52
+ }
53
+
54
+ function tokenMatches(candidate, token) {
55
+ if (typeof candidate !== "string") return false;
56
+ // Hash both values so timingSafeEqual always receives equal-length digests.
57
+ const digest = (value) => createHash("sha256").update(value).digest();
58
+ return timingSafeEqual(digest(candidate), digest(token));
59
+ }
60
+
61
+ function connectionOf(ctx) {
62
+ // Cordis permits optional service lookup through get(); older hosts may lack it.
63
+ return typeof ctx.get === "function" ? ctx.get("connection", false) : ctx.connection;
64
+ }
65
+
46
66
  async function readJsonBody(req, limitBytes = 512 * 1024) {
47
67
  const chunks = [];
48
68
  let total = 0;
@@ -455,6 +475,7 @@ const MOBILE_HTML = `<!doctype html>
455
475
  <div id="app">正在加载 DSH 自进化手机审批台…</div>
456
476
  <script>
457
477
  const API = '/dsh-evolution/api';
478
+ const token = new URL(window.location.href).searchParams.get('token');
458
479
  let state = { data: null, tab: 'drafts', busy: null, toast: null, comments: {}, previewOpen: {} };
459
480
  const QUICKS = [
460
481
  '同意采纳:请将技能正文全部转化为清晰易读的中文规范后正式入库',
@@ -464,7 +485,10 @@ const MOBILE_HTML = `<!doctype html>
464
485
  ];
465
486
 
466
487
  async function callApi(path, opts) {
467
- const r = await fetch(API + path, { headers: { 'content-type': 'application/json' }, ...opts });
488
+ const r = await fetch(API + path, {
489
+ ...opts,
490
+ headers: { 'content-type': 'application/json', ...(token ? { Authorization: 'Bearer ' + token } : {}), ...opts?.headers }
491
+ });
468
492
  const d = await r.json().catch(() => ({}));
469
493
  if (!r.ok) throw new Error(d.error || ('HTTP ' + r.status));
470
494
  return d;
@@ -619,36 +643,50 @@ const MOBILE_HTML = `<!doctype html>
619
643
  </html>`;
620
644
 
621
645
  export function registerEvolutionHttp(ctx, deps) {
622
- const handleRequest = async (req, res) => {
623
- // 仅用于解析相对路径,不发起任何网络请求;用保留 TLD 占位,避免把 loopback 字面量写进发行版。
624
- const url = new URL(req.url ?? "/", "http://placeholder.invalid");
625
- if (
626
- req.method === "GET" &&
627
- (url.pathname === "/" ||
628
- url.pathname === "/dsh-evolution" ||
629
- url.pathname === "/dsh-evolution/" ||
630
- url.pathname === "/dsh-evolution/mobile" ||
631
- url.pathname === "/dsh-evolution/mobile/")
632
- ) {
633
- const buf = Buffer.from(MOBILE_HTML, "utf8");
634
- res.writeHead(200, {
635
- "content-type": "text/html; charset=utf-8",
636
- "cache-control": "no-store",
637
- "content-length": buf.length,
638
- });
639
- res.end(buf);
640
- return;
641
- }
642
- const prefix = "/dsh-evolution/api/";
643
- if (!url.pathname.startsWith(prefix)) {
644
- res.writeHead(404);
645
- res.end();
646
- return;
647
- }
648
- const action = url.pathname.slice(prefix.length).replace(/\/$/, "");
649
- const { config, skillsRoot } = deps;
650
-
646
+ const handleRequest = async (req, res, connection, standalone = false) => {
651
647
  try {
648
+ // The host's trust/authentication fence runs before URL, body or private data reads.
649
+ if (typeof connection?.requestRejection === "function") {
650
+ const rejection = connection.requestRejection(req);
651
+ if (rejection === 401 || rejection === 403) {
652
+ sendJson(res, rejection, { ok: false, error: rejection === 401 ? "Unauthorized" : "Forbidden" });
653
+ return;
654
+ }
655
+ }
656
+ // 仅用于解析相对路径,不发起任何网络请求。
657
+ const url = new URL(req.url ?? "/", "http://placeholder.invalid");
658
+ const { config, skillsRoot } = deps;
659
+ if (standalone && config.httpToken) {
660
+ const bearer = /^Bearer (.+)$/i.exec(req.headers?.authorization ?? "")?.[1];
661
+ if (!tokenMatches(bearer, config.httpToken) && !tokenMatches(url.searchParams.get("token"), config.httpToken)) {
662
+ sendJson(res, 401, { ok: false, error: "Unauthorized" });
663
+ return;
664
+ }
665
+ }
666
+ if (
667
+ req.method === "GET" &&
668
+ (url.pathname === "/" ||
669
+ url.pathname === "/dsh-evolution" ||
670
+ url.pathname === "/dsh-evolution/" ||
671
+ url.pathname === "/dsh-evolution/mobile" ||
672
+ url.pathname === "/dsh-evolution/mobile/")
673
+ ) {
674
+ const buf = Buffer.from(MOBILE_HTML, "utf8");
675
+ res.writeHead(200, {
676
+ "content-type": "text/html; charset=utf-8",
677
+ "cache-control": "no-store",
678
+ "content-length": buf.length,
679
+ });
680
+ res.end(buf);
681
+ return;
682
+ }
683
+ const prefix = "/dsh-evolution/api/";
684
+ if (!url.pathname.startsWith(prefix)) {
685
+ res.writeHead(404);
686
+ res.end();
687
+ return;
688
+ }
689
+ const action = url.pathname.slice(prefix.length).replace(/\/$/, "");
652
690
  // ---- GET ----
653
691
  if (req.method === "GET" && action === "status") {
654
692
  sendJson(res, 200, await buildSnapshot(skillsRoot, config));
@@ -888,25 +926,42 @@ export function registerEvolutionHttp(ctx, deps) {
888
926
 
889
927
  // 1. 挂载到 DSH 主 WebServer
890
928
  ctx.inject(["webServer"], (webCtx) => {
891
- webCtx.effect(() =>
892
- webCtx.webServer.register({
929
+ const mount = (routeCtx) => routeCtx.effect(() =>
930
+ routeCtx.webServer.register({
893
931
  kind: "prefix",
894
932
  path: "/dsh-evolution",
895
- handler: handleRequest,
933
+ handler: (req, res) => handleRequest(req, res, connectionOf(routeCtx), false),
896
934
  }),
897
935
  );
936
+ // A required connection injection would prevent mounting on older hosts.
937
+ // Still look it up per request so a service arriving later cannot bypass it.
938
+ if (connectionOf(webCtx)) webCtx.inject(["webServer", "connection"], mount);
939
+ else mount(webCtx);
898
940
  });
899
941
 
900
- // 2. 同时在固定端口 18890 提供独立服务(供 DSH Go 的 Loopback 端口预览或 Tailscale 手机直连,不随 Desktop 随机端口变化)
942
+ // 2. 独立服务默认仅回环可达;LAN / Tailscale 暴露必须显式配置令牌。
901
943
  ctx.effect(() => {
902
- const fixedPort = Number(process.env.DSH_EVOLUTION_PORT || 18890);
944
+ const { config } = deps;
945
+ if (config.httpEnabled === false) return;
946
+ const host = config.httpHost ?? "127.0.0.1";
947
+ const needsToken = !isLoopbackHost(host);
948
+ if (needsToken && !config.httpToken) {
949
+ ctx.logger?.warn?.("[dsh-evolution] standalone HTTP listener not started: non-loopback httpHost requires a non-empty httpToken");
950
+ return;
951
+ }
952
+ const fixedPort = Number(process.env.DSH_EVOLUTION_PORT || (config.httpPort ?? 18890));
903
953
  const srv = http.createServer((req, res) => {
904
- void handleRequest(req, res);
954
+ // Config can be changed live: removing the token must never open a LAN listener.
955
+ if (needsToken && !config.httpToken) {
956
+ sendJson(res, 401, { ok: false, error: "Non-loopback HTTP requires httpToken" });
957
+ return;
958
+ }
959
+ void handleRequest(req, res, undefined, true);
905
960
  });
906
- srv.on("error", () => {
907
- /* 若端口已被其他 profile 占用则静默忽略 */
961
+ srv.on("error", (error) => {
962
+ ctx.logger?.warn?.(`[dsh-evolution] standalone HTTP listener failed: ${error.code ?? "unknown error"}`);
908
963
  });
909
- srv.listen(fixedPort, "0.0.0.0");
964
+ srv.listen(fixedPort, host);
910
965
  srv.unref?.();
911
966
  return () => {
912
967
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skill-evolution",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "Closed-loop skill self-evolution plugin for DSH: post-turn review, Chinese briefing & mandatory directive fusion, 4-gate safety validation, SHA-256 content-addressed ledger with single-entry rollback, LLM umbrella consolidation, and a Web/Mobile/Remote review workbench.",
6
6
  "license": "MIT",
@@ -54,13 +54,14 @@
54
54
  "assets/screenshots/*.png"
55
55
  ],
56
56
  "scripts": {
57
- "test": "node --test test/*.test.js",
57
+ "test": "node --test test/*.test.mjs",
58
58
  "audit:parity": "node tools/verify-parity.mjs",
59
59
  "audit:prompts": "node tools/verify-prompt-fidelity.mjs",
60
60
  "sanitize": "node scripts/sanitize-check.mjs"
61
61
  },
62
62
  "engines": {
63
- "node": ">=20.11"
63
+ "node": ">=20.11",
64
+ "dsh": ">=0.2.2-rc.1 <0.3.0"
64
65
  },
65
66
  "publishConfig": {
66
67
  "access": "public",