skill-evolution 0.0.0-stage → 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 ADDED
@@ -0,0 +1,69 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-11-11
4
+
5
+ First public release.
6
+
7
+ > Version note: earlier iterations used internal sequence numbers (the sections below). The public series restarts here at 0.1.0; internal numbers are not carried over.
8
+
9
+
10
+ All notable changes to `skill-evolution` will be documented in this file.
11
+
12
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
13
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
14
+
15
+ ## [Unreleased]
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
+
27
+ ## [0.3.1] - 2026-11-10
28
+
29
+ ### Added
30
+ - **Native Web UI (`client.js` rewrite)**: the workbench now follows the host settings page design language instead of a self-made layout — 720px container, 20/14/12 type scale, `.5px` row separators, and colors taken only from host `--dsw-alias-*` tokens so light and dark themes are followed automatically.
31
+ - **Native switch control**: `NativeSwitch` renders a 36×20 button with `role="switch"` and `aria-checked`, replacing the previous custom toggle.
32
+ - **Split renderers**: `settings.section` now renders engine parameters and status only, while the full five-view workbench (overview / drafts / skills / ledger / settings) mounts in `main` and `sidebar.panellist`.
33
+ - **`settings.section.icon` registration**: the settings section now has its own icon entry.
34
+ - **`client.inject` expands to six UI packages**: `@deepseek-ai/dsh-client-ui-sidebar` and `@deepseek-ai/dsh-client-ui-layout` are now injected so `sidebar.panellist` and `main` resolve.
35
+ - **Auxiliary LLM review channel**: `runAuxiliaryReview` calls an OpenAI-compatible endpoint directly (`DSH_EVOLUTION_BASE_URL` / `DSH_EVOLUTION_API_KEY` / `DSH_EVOLUTION_MODEL`), so a review can run outside the session lock during short-lived or headless exits.
36
+ - **`scripts/sanitize-check.mjs`**: sanitization gate with 11 needles (home paths, private package scope, loopback address and hostname, private key marker, internal IP segment, internal gateway and cloud vendor names, API key and GitHub token prefixes) plus checks for `.bak-*` files and `node_modules/`. Vendored Hermes sources are excluded from content scanning and the skip count is printed.
37
+ - **CI sanitization step**, and `npm run sanitize` for local use.
38
+
39
+ ### Changed
40
+ - **`reviewModel` now inherits by default**: `provider` and `model` default to empty strings, meaning the review uses the current session model; set them (or the env vars) to use a cheaper auxiliary model.
41
+ - **Review channel selection**: when no auxiliary endpoint is configured, reviews go through the host subagent fork instead of assuming a local endpoint exists.
42
+ - **Throttle defaults**: `minTurnsBetween` 3 → 1, `minMinutesBetween` 5 → 2 (both in `index.js` and `cordis.patch.yml`).
43
+ - **`consolidate` / `consolidateDryRun` documented in the bundle patch**: umbrella consolidation stays off by default and previews only.
44
+ - **`package.json`**: version 0.3.1, `private` removed, `publishConfig` (`access: public`, `provenance: true`), `@deepseek-ai/schemastery` declared as a peer dependency (`>=3.0.0-0`), `engines` set to Node `>=20.11`, and `assets/icon-180.png` / `README.en.md` / `CHANGELOG.md` added to `files`.
45
+ - **README.md / README.en.md restructured to one shared outline** (what it does / how it works / install / config / limitations / development / license) and all numbers checked against the code and test output: 70 tests, 41/41 capability audit, 2 prompt blocks byte-identical.
46
+
47
+ ### Fixed
48
+ - The HTTP request parser no longer embeds a loopback literal: relative URLs are parsed against a reserved placeholder origin. `pathname` and `searchParams` behavior is unchanged.
49
+ - Removed the private package scope from the client module id, test header and bundles patch, so the published package carries no private scope.
50
+
51
+ ## [0.3.0] - 2026-11-08
52
+
53
+ ### Added
54
+ - **Chinese Briefing & Mandatory User Directive Fusion**:
55
+ - Added `.briefing.json` generation and `ReviewBrief` UI card displaying plain-language summaries (`whatItIs`, `keyRules`, `ifApprove`, `ifReject`).
56
+ - Added mandatory user directive (`comment`) input with quick-directive chips and AI-powered draft refinement (`POST /dsh-evolution/api/refine-draft` and `evolveWithComment` in `POST /dsh-evolution/api/promote`).
57
+ - **Full Desktop, Mobile PWA & Remote App Support**:
58
+ - Mounted the workbench into `main`, `sidebar.panellist` (order 15) and `settings.section` (order 30).
59
+ - Added standalone Mobile PWA workbench (`GET /dsh-evolution/mobile` and fixed port `18890`) with bottom tab bar and iOS `16px` zoom prevention.
60
+ - Added `evolution_review_center` tool (with native `ask_user_question` interactive cards for Remote/Mobile apps) and `/evolution brief|refine|approve|reject` slash commands.
61
+ - **LLM Umbrella Consolidation Workbench**:
62
+ - Ported `CURATOR_REVIEW_PROMPT` and implemented `lib/consolidation.js` for prefix-cluster umbrella merging (`create`, `patch`, `write_file`, `archive` with mandatory `absorbedInto`).
63
+ - **Short-Lived Process Flush Barrier**:
64
+ - Subscribed to `session/flush` with `inflightPromises` barrier so one-shot/headless runs never truncate in-flight reviews before exit.
65
+
66
+ ### Fixed
67
+ - Fixed DSH `session/event` nested `ev.data` envelope parsing and filtered system-injected `<system-reminder>` / runtime-context blocks.
68
+ - Fixed `SettingsPanel` child component focus loss by hoisting field components to module scope.
69
+ - Refined `NEGATIVE_CLAIM_PATTERNS` in `lib/gatekeeper.js` to avoid false positives on cautionary prose.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 veritaswiki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,244 @@
1
+ # 🧬 Skill Evolution (`skill-evolution`)
2
+
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
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
5
+ [![Node](https://img.shields.io/badge/Node-%3E%3D20.11-informational.svg)](#development)
6
+ [![Tests](https://img.shields.io/badge/tests-80%20passed-34d399.svg)](#development)
7
+ [![Hermes parity](https://img.shields.io/badge/Hermes%20parity-41%2F41-8b7cf6.svg)](#capability-parity-and-audits)
8
+
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.
10
+
11
+ [中文文档 (README.md)](./README.md) · [Changelog (CHANGELOG.md)](./CHANGELOG.md)
12
+
13
+ ---
14
+
15
+ ## Screenshots
16
+
17
+ ![The workbench overview: pending drafts, promoted skills, ledger snapshots and last heartbeat, with the review entry points](assets/screenshots/workbench.png)
18
+
19
+ ---
20
+
21
+ ## What it does
22
+
23
+ 1. **Post-turn review** — listens on `turn/end` and `session/flush`, detects `user-correction`, `new-technique` and `skill-was-wrong` signals, throttles by `minTurnsBetween` turns / `minMinutesBetween` minutes (`.throttle.json`, cross-process), and bounds the snapshot by `maxMessages` and `maxChars`.
24
+ 2. **The review is read-only** — it runs either in a host subagent fork (`subagents.startActivation`, tool allowlist `skill` / `glob` / `grep` / `read`) or against an OpenAI-compatible auxiliary endpoint. Neither path writes files: writes happen in the plugin, after the gates. A newer turn aborts the previous review, and every run has a timeout.
25
+ 3. **Drafts by default** — with `mode: draft` output goes to `<skillsRoot>/.staging/` and the real skill library stays untouched. Promotion moves the draft into the skills directory, where DSH's skill filesystem hot-reloads it.
26
+ 4. **Four code-level gates plus provenance protection** — see the gate table below. Only skills with `metadata.createdBy: agent` are ever auto-modified; user-authored skills are left alone.
27
+ 5. **Ledger and single-entry rollback** — every create / patch / directive refinement / promotion / consolidation / archive appends to `.evolution_ledger.jsonl`, and file contents are stored deduplicated by SHA-256 under `.evolution_backups/blobs/`. Rollback takes a safety snapshot first and refuses (fail-closed) when that snapshot fails.
28
+ 6. **Lifecycle and umbrella consolidation** — sidecar `.usage.json` telemetry drives `active → stale(14d) → archived(30d)` (zero-use immunity, `pinned` exemption, protected built-ins, archive never deletes). An LLM umbrella pass can merge narrow skills into class-level ones; it previews by default and does not touch disk.
29
+
30
+ ---
31
+
32
+ ## How it works
33
+
34
+ ### Pipeline modules
35
+
36
+ | Stage | File | What it does |
37
+ |---|---|---|
38
+ | Collect | `lib/collector.js` | Strips system-injected blocks, detects review signals, throttles, digests older turns, trims to `maxChars` |
39
+ | Review | `lib/reflector.js` + `lib/prompts.js` | Read-only fork or auxiliary endpoint; prompts are verbatim from Hermes (see `vendor/hermes/`) |
40
+ | Synthesize | `lib/synthesizer.js` | Structured JSON → `SKILL.md` content (pure functions) |
41
+ | Gate | `lib/gatekeeper.js` | Four static checks, see the table below |
42
+ | Apply | `lib/applier.js` | draft/apply destination, provenance protection, draft promotion |
43
+ | Record | `lib/ledger.js` | JSONL ledger, SHA-256 blobs, single-entry rollback, rotation and blob GC |
44
+ | Lifecycle | `lib/usage.js` | `.usage.json` telemetry, three states, pinned/protected skills, adopt/disown |
45
+ | Consolidate | `lib/consolidation.js` | Prefix clustering plus LLM plan validation (atomic: one non-compliant entry rejects the batch) |
46
+ | Surface | `client.js` + `lib/http-api.js` | Web workbench and `/dsh-evolution/api/*` |
47
+
48
+ ### The four gates (`lib/gatekeeper.js`)
49
+
50
+ | # | Check | Rejects |
51
+ |---|---|---|
52
+ | 1 | Name | Non-kebab-case, over 64 chars, session artifacts such as `fix-X` / `debug-Y` / PR numbers / dates, bare library names |
53
+ | 2 | Frontmatter | Missing `description`; `description` over 80 chars; `frontmatter.name` not matching the target |
54
+ | 3 | Forbidden content | Negative tool claims (`X tool does not work`), environment failures (`command not found`), one-off narratives |
55
+ | 4 | Size and paths | Body over 24000 chars; `add_reference` paths that are not `references/<topic>.md` or that carry date stamps |
56
+
57
+ ### Client mount points (`client.js`)
58
+
59
+ | Slot | order | Content |
60
+ |---|---|---|
61
+ | `main` | — | Full workbench: overview / drafts / skills / ledger / settings views |
62
+ | `sidebar.panellist` | 15 | Sidebar entry |
63
+ | `settings.section` | 30 | Engine settings and status only, not the review workbench |
64
+ | `settings.section.icon` | — | Settings section icon |
65
+
66
+ Styling uses only host `--dsw-alias-*` tokens so it follows light and dark themes (720px container, 20/14/12 type scale, `.5px` row separators, 36×20 native switch).
67
+
68
+ ### HTTP API (`lib/http-api.js`)
69
+
70
+ Prefix `/dsh-evolution`; `GET /dsh-evolution/mobile` returns the standalone mobile page.
71
+
72
+ | Method | Path | Purpose |
73
+ |---|---|---|
74
+ | GET | `/dsh-evolution/api/status` | Full state (skill counts, drafts with bodies and briefings, ledger, last review, throttle, config) |
75
+ | GET | `/dsh-evolution/api/skills` | Skill list (lifecycle state, use count, whether created by the agent) |
76
+ | GET | `/dsh-evolution/api/drafts` | Pending drafts (full `SKILL.md` plus `briefing`) |
77
+ | GET | `/dsh-evolution/api/skill/:name` | One skill in detail |
78
+ | GET | `/dsh-evolution/api/ledger` | Ledger entries (`?limit=`) |
79
+ | GET | `/dsh-evolution/api/ledger/:id` | One ledger entry with before/after SHA lists |
80
+ | GET | `/dsh-evolution/api/candidates` | Skills eligible for consolidation |
81
+ | POST | `/dsh-evolution/api/refine-draft` | Rewrite a draft from your directive and refresh the briefing |
82
+ | POST | `/dsh-evolution/api/promote` | Promote a draft (optionally fusing the directive first) |
83
+ | POST | `/dsh-evolution/api/promote-batch` | Atomic batch promotion |
84
+ | POST | `/dsh-evolution/api/discard` | Reject a draft |
85
+ | POST | `/dsh-evolution/api/tidy` | One-click triage of a draft backlog |
86
+ | POST | `/dsh-evolution/api/rollback` | Roll back by ledger `id` |
87
+ | POST | `/dsh-evolution/api/pin` | Pin / unpin |
88
+ | POST | `/dsh-evolution/api/adopt` · `/disown` | Take over / release a skill |
89
+ | POST | `/dsh-evolution/api/consolidate` | Umbrella consolidation (`dryRun: true` previews) |
90
+ | POST | `/dsh-evolution/api/config` | Save config |
91
+ | POST | `/dsh-evolution/api/review` | Trigger one review manually |
92
+
93
+ ---
94
+
95
+ ## Install
96
+
97
+ **Option A: plugin manager**
98
+
99
+ ```bash
100
+ # installs into the given profile (a pnpm add inside that profile)
101
+ dsh plugin add github:veritaswiki/skill-evolution
102
+ ```
103
+
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
+
106
+ **Option B: config file**
107
+
108
+ Skip the bundle and write into `~/.dsh/cordis.patch.yml`:
109
+
110
+ ```yaml
111
+ - insert:
112
+ - id: skill-evolution
113
+ name: 'skill-evolution'
114
+ config:
115
+ enabled: false
116
+ mode: draft
117
+ ```
118
+
119
+ **Option C: from source**
120
+
121
+ ```bash
122
+ git clone https://github.com/veritaswiki/skill-evolution.git
123
+ dsh plugin add ./skill-evolution
124
+ ```
125
+
126
+ After installing, `/evolution status` should show the skills root, mode, skill count, draft count and ledger entry count.
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
+
144
+ ---
145
+
146
+ ## Configuration
147
+
148
+ Defaults in `cordis.patch.yml` match the Schemastery definition in `index.js`:
149
+
150
+ | Key | Type | Default | Meaning |
151
+ |---|---|---|---|
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 |
157
+ | `skillsRoot` | string | `""` (→ `~/.dsh/skills`) | Skills root; drafts, ledger and telemetry live here |
158
+ | `mode` | `"draft" \| "apply"` | `"draft"` | `draft` writes only to `.staging/`; `apply` writes into the library after the gates |
159
+ | `minTurnsBetween` | number | `1` | Minimum reviewable turns between two reviews |
160
+ | `minMinutesBetween` | number | `2` | Minimum minutes between two reviews |
161
+ | `maxMessages` | number | `24` | Recent messages kept in the snapshot |
162
+ | `maxChars` | number | `24000` | Snapshot character budget per review |
163
+ | `reviewTimeoutSeconds` | number | `180` | Per-review timeout |
164
+ | `reviewModel.provider` | string | `""` | Review-only provider; empty inherits the session model |
165
+ | `reviewModel.model` | string | `""` | Review-only model; empty inherits the session model |
166
+ | `reviewModel.reasoningEffort` | string | `""` | Passed through to the host |
167
+ | `curatorEnabled` | boolean | `true` | Enable lifecycle maintenance |
168
+ | `consolidate` | boolean | `false` | Run umbrella consolidation in the curator timer |
169
+ | `consolidateDryRun` | boolean | `true` | Consolidation previews only |
170
+ | `staleAfterDays` | number | `14` | Days of non-use before `stale` |
171
+ | `archiveAfterDays` | number | `30` | Days of non-use before moving to `.archive/` (no delete) |
172
+
173
+ Environment variables (all optional):
174
+
175
+ | Variable | Purpose |
176
+ |---|---|
177
+ | `DSH_EVOLUTION_BASE_URL` | OpenAI-compatible auxiliary endpoint (e.g. `https://host/v1`). Unset means reviews go through the host subagent fork |
178
+ | `DSH_EVOLUTION_API_KEY` | Bearer token for that endpoint |
179
+ | `DSH_EVOLUTION_MODEL` | Model name used on that endpoint |
180
+ | `DSH_EVOLUTION_PORT` | Override `httpPort` for the standalone mobile service |
181
+ | `DSH_HOME` | DSH home directory, default `~/.dsh` |
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
+
202
+ ### Commands and tools
203
+
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).
205
+
206
+ The `evolution_review_center` tool targets chat and mobile clients: `action` is one of `brief`, `interactive_review` (default), `refine`, `approve`, `reject`.
207
+
208
+ ---
209
+
210
+ ## Known limitations
211
+
212
+ - **The auxiliary channel is yours to configure**: the package ships no gateway address and no credentials. Without `DSH_EVOLUTION_BASE_URL`, reviews go through the host subagent fork and you do not get the low-latency auxiliary path.
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.
214
+ - **The UI is Chinese only**: `locale/en.json` covers just the plugin name and description; the workbench has no English UI.
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.
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.
217
+ - **`mode: apply` writes the real skill library**: only for skills with `metadata.createdBy: agent`; the default is still `draft`.
218
+ - **Archiving does not free disk**: skills move to `.archive/` and you delete them yourself.
219
+ - **Body cap is 24000 chars**: beyond that, depth has to go into `references/`.
220
+
221
+ ---
222
+
223
+ ## Development
224
+
225
+ ```bash
226
+ npm test # 80 tests, including HTTP security (node --test test/*.test.mjs)
227
+ npm run audit:parity # 41-item capability audit (37 Hermes capabilities + 4 DSH-only)
228
+ npm run audit:prompts # byte-level prompt fidelity (LESSON_LAYER_BLOCK / _DO_NOT_CAPTURE_BLOCK)
229
+ npm run sanitize # sanitization gate, must report 0 hits
230
+ ```
231
+
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.
233
+
234
+ ### Capability parity and audits
235
+
236
+ `npm run audit:parity` checks each ported Hermes capability and lists the 4 DSH-only ones. `npm run audit:prompts` compares the two prompt blocks in `lib/prompts.js` byte for byte against `vendor/hermes/background_review.py` (currently 2098 / 1690 chars, identical).
237
+
238
+ `vendor/hermes/` is a verbatim copy of Nous Research `hermes-agent` (MIT), see [`vendor/hermes/PROVENANCE.md`](./vendor/hermes/PROVENANCE.md).
239
+
240
+ ---
241
+
242
+ ## License
243
+
244
+ [MIT](./LICENSE). Reference sources under `vendor/hermes/` come from Nous Research `hermes-agent`, also MIT.
package/README.md CHANGED
@@ -1,3 +1,244 @@
1
- # Temporary Holding Version
1
+ # 🧬 Skill Evolution (`skill-evolution`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
5
+ [![Node](https://img.shields.io/badge/Node-%3E%3D20.11-informational.svg)](#开发)
6
+ [![Tests](https://img.shields.io/badge/tests-80%20passed-34d399.svg)](#开发)
7
+ [![Hermes parity](https://img.shields.io/badge/Hermes%20parity-41%2F41-8b7cf6.svg)](#能力对齐与审计)
8
+
9
+ > DSH 的 `skill` 工具只能加载技能,不能写回技能。这个插件补上写回的那一段:回合结束后自动复盘会话、把经验蒸馏成技能草稿、过四道代码级闸门后等你批示,全程记账、可单条回滚。
10
+
11
+ [English Documentation (README.en.md)](./README.en.md) · [变更日志 (CHANGELOG.md)](./CHANGELOG.md)
12
+
13
+ ---
14
+
15
+ ## 界面
16
+
17
+ ![自进化工作台:概览统计(待审草稿 / 正式技能 / 账本快照 / 最近心跳)与审阅入口](assets/screenshots/workbench.png)
18
+
19
+ ---
20
+
21
+ ## 它做什么
22
+
23
+ 1. **回合后自动复盘** — 监听 `turn/end` 与 `session/flush`,识别 `user-correction`、`new-technique`、`skill-was-wrong` 三类信号;按 `minTurnsBetween` 回合 / `minMinutesBetween` 分钟双重节流(`.throttle.json` 跨进程持久化),快照有界(`maxMessages` 条、`maxChars` 字符)。
24
+ 2. **复盘是只读的** — 复盘跑在宿主 subagent fork(`subagents.startActivation`,工具白名单 `skill` / `glob` / `grep` / `read`)或一个 OpenAI-compatible 辅助端点;两条通道都不写文件,写入由插件在闸门之后自己做,且新回合到来会打断上一次复盘、单次有超时。
25
+ 3. **默认只产草稿** — `mode: draft` 时产物只写 `<skillsRoot>/.staging/`,正式技能库零改动;采纳后由 `promote` 落进正式技能目录,靠 DSH 技能文件系统的热更新自动生效。
26
+ 4. **四道代码级闸门 + 归属保护** — 见下方闸门表;只有 `metadata.createdBy: agent` 的技能会被自动改写,用户手写技能一律不碰。
27
+ 5. **账本与单条回滚** — 每次创建 / 补丁 / 批示修订 / 采纳 / 合并 / 归档都追加一条 `.evolution_ledger.jsonl`,文件内容按 SHA-256 去重存进 `.evolution_backups/blobs/`;回滚前先做安全捕获,捕获失败就拒绝回滚(fail-closed)。
28
+ 6. **生命周期与建伞合并** — `.usage.json` 旁路遥测驱动 `active → stale(14d) → archived(30d)`(零使用不归档、`pinned` 豁免、内置技能受保护、只移动不删除);另有 LLM 建伞合并把多个窄技能并成类级别伞技能,默认只预览不执行。
29
+
30
+ ---
31
+
32
+ ## 它怎么做
33
+
34
+ ### 流水线模块
35
+
36
+ | 环节 | 文件 | 做什么 |
37
+ |---|---|---|
38
+ | 采集 | `lib/collector.js` | 剥离系统注入块,识别复盘信号,节流,压缩历史为摘要,裁剪到 `maxChars` |
39
+ | 复盘 | `lib/reflector.js` + `lib/prompts.js` | fork 只读复盘或调辅助端点;提示词逐字取自 Hermes(见 `vendor/hermes/`) |
40
+ | 蒸馏 | `lib/synthesizer.js` | 结构化 JSON → `SKILL.md` 内容(纯函数) |
41
+ | 闸门 | `lib/gatekeeper.js` | 四道静态检查,见下表 |
42
+ | 落盘 | `lib/applier.js` | draft/apply 两种落盘位置,归属保护,提升草稿 |
43
+ | 记账 | `lib/ledger.js` | JSONL 账本、SHA-256 blob、单条回滚、轮转与 blob GC |
44
+ | 生命周期 | `lib/usage.js` | `.usage.json` 遥测、三态转换、pinned/保护技能、adopt/disown |
45
+ | 建伞合并 | `lib/consolidation.js` | 前缀聚类 + LLM 计划校验(原子性:一条不合规整批拒绝) |
46
+ | 展示 | `client.js` + `lib/http-api.js` | Web 工作台与 `/dsh-evolution/api/*` |
47
+
48
+ ### 四道闸门(`lib/gatekeeper.js`)
49
+
50
+ | # | 检查 | 拒绝什么 |
51
+ |---|---|---|
52
+ | 1 | 命名 | 非 kebab-case、超 64 字符、`fix-X` / `debug-Y` / PR 号 / 日期戳这类一次性会话产物、裸库名 |
53
+ | 2 | Frontmatter | 缺 `description`;`description` 超 80 字符;`frontmatter.name` 与目标名不一致 |
54
+ | 3 | 禁词扫描 | 负面断言(`X tool does not work`)、环境失败(`command not found`)、一次性叙事 |
55
+ | 4 | 体积与路径 | 正文超 24000 字符;`add_reference` 的路径不是 `references/<topic>.md` 或带日期戳 |
56
+
57
+ ### 前端挂载点(`client.js`)
58
+
59
+ | 插槽 | order | 内容 |
60
+ |---|---|---|
61
+ | `main` | — | 完整工作台:概览 / 待审草稿 / 技能库 / 账本 / 参数五个视图 |
62
+ | `sidebar.panellist` | 15 | 侧栏入口 |
63
+ | `settings.section` | 30 | 只放引擎参数与状态,不放审阅工作台 |
64
+ | `settings.section.icon` | — | 设置段图标 |
65
+
66
+ 界面样式只取宿主 `--dsw-alias-*` token 跟随明暗主题(720px 容器、20/14/12 号字阶梯、`.5px` 行分割线、36×20 原生开关)。
67
+
68
+ ### HTTP API(`lib/http-api.js`)
69
+
70
+ 前缀 `/dsh-evolution`,`GET /dsh-evolution/mobile` 返回独立手机端页面。
71
+
72
+ | 方法 | 路径 | 作用 |
73
+ |---|---|---|
74
+ | GET | `/dsh-evolution/api/status` | 完整状态(技能数、草稿含正文与中文简报、账本、最近复盘、节流、配置) |
75
+ | GET | `/dsh-evolution/api/skills` | 技能列表(生命周期状态、使用次数、是否 agent 创建) |
76
+ | GET | `/dsh-evolution/api/drafts` | 待审草稿(含完整 `SKILL.md` 与 `briefing`) |
77
+ | GET | `/dsh-evolution/api/skill/:name` | 单个技能详情 |
78
+ | GET | `/dsh-evolution/api/ledger` | 账本记录(`?limit=`) |
79
+ | GET | `/dsh-evolution/api/ledger/:id` | 单条账本(含前后文件 SHA 清单) |
80
+ | GET | `/dsh-evolution/api/candidates` | 可参与建伞合并的候选技能 |
81
+ | POST | `/dsh-evolution/api/refine-draft` | 按批示让 AI 重写草稿并更新简报 |
82
+ | POST | `/dsh-evolution/api/promote` | 采纳草稿(可先融合批示) |
83
+ | POST | `/dsh-evolution/api/promote-batch` | 原子批量采纳 |
84
+ | POST | `/dsh-evolution/api/discard` | 驳回草稿 |
85
+ | POST | `/dsh-evolution/api/tidy` | 待审积压一键分诊 |
86
+ | POST | `/dsh-evolution/api/rollback` | 按账本 `id` 回滚 |
87
+ | POST | `/dsh-evolution/api/pin` | 固定 / 取消固定 |
88
+ | POST | `/dsh-evolution/api/adopt` · `/disown` | 纳入 / 取消纳管 |
89
+ | POST | `/dsh-evolution/api/consolidate` | 建伞合并(`dryRun: true` 预览) |
90
+ | POST | `/dsh-evolution/api/config` | 保存配置 |
91
+ | POST | `/dsh-evolution/api/review` | 手动触发一次复盘 |
92
+
93
+ ---
94
+
95
+ ## 安装
96
+
97
+ **方式 A:插件管理器**
98
+
99
+ ```bash
100
+ # 装进指定 profile(等价于在该 profile 目录执行 pnpm add)
101
+ dsh plugin add github:veritaswiki/skill-evolution
102
+ ```
103
+
104
+ 然后把包名加入该 profile 的 `dsh.profile.bundles`,重启 DSH。插件自己的 `cordis.patch.yml` 只插入本插件配置,默认关闭自动进化,不再修改全局技能目录描述上限。
105
+
106
+ **方式 B:配置文件**
107
+
108
+ 不装 bundle,直接在 `~/.dsh/cordis.patch.yml` 写:
109
+
110
+ ```yaml
111
+ - insert:
112
+ - id: skill-evolution
113
+ name: 'skill-evolution'
114
+ config:
115
+ enabled: false
116
+ mode: draft
117
+ ```
118
+
119
+ **方式 C:源码**
120
+
121
+ ```bash
122
+ git clone https://github.com/veritaswiki/skill-evolution.git
123
+ dsh plugin add ./skill-evolution
124
+ ```
125
+
126
+ 装好之后,`/evolution status` 应能看到技能根目录、模式、技能数、待审草稿数与账本条数。
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
+
144
+ ---
145
+
146
+ ## 配置
147
+
148
+ `cordis.patch.yml` 里的默认值与 `index.js` 的 Schemastery 定义一致:
149
+
150
+ | 键 | 类型 | 默认值 | 说明 |
151
+ |---|---|---|---|
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 请求均须认证,包括宿主挂载路由 |
157
+ | `skillsRoot` | string | `""`(→ `~/.dsh/skills`) | 技能根目录;草稿、账本、遥测都放这里 |
158
+ | `mode` | `"draft" \| "apply"` | `"draft"` | `draft` 只写 `.staging/`;`apply` 过闸后直接落盘 |
159
+ | `minTurnsBetween` | number | `1` | 两次复盘之间至少间隔多少个可复盘回合 |
160
+ | `minMinutesBetween` | number | `2` | 两次复盘之间至少间隔多少分钟 |
161
+ | `maxMessages` | number | `24` | 快照保留的最近消息条数 |
162
+ | `maxChars` | number | `24000` | 单次复盘快照字符上限 |
163
+ | `reviewTimeoutSeconds` | number | `180` | 单次复盘超时 |
164
+ | `reviewModel.provider` | string | `""` | 复盘专用模型 provider;留空继承当前会话模型 |
165
+ | `reviewModel.model` | string | `""` | 复盘专用模型名;留空继承当前会话模型 |
166
+ | `reviewModel.reasoningEffort` | string | `""` | 透传给宿主的 reasoning effort |
167
+ | `curatorEnabled` | boolean | `true` | 是否启用生命周期维护 |
168
+ | `consolidate` | boolean | `false` | 定时 curator 是否自动跑建伞合并 |
169
+ | `consolidateDryRun` | boolean | `true` | 建伞合并只出计划、不改盘 |
170
+ | `staleAfterDays` | number | `14` | 多少天未使用标记 `stale` |
171
+ | `archiveAfterDays` | number | `30` | 多少天未使用移入 `.archive/`(不删除) |
172
+
173
+ 环境变量(全部可选):
174
+
175
+ | 变量 | 作用 |
176
+ |---|---|
177
+ | `DSH_EVOLUTION_BASE_URL` | OpenAI-compatible 辅助端点(如 `https://host/v1`)。不设则复盘走宿主 subagent fork |
178
+ | `DSH_EVOLUTION_API_KEY` | 辅助端点的 Bearer token |
179
+ | `DSH_EVOLUTION_MODEL` | 辅助端点使用的模型名 |
180
+ | `DSH_EVOLUTION_PORT` | 覆盖独立手机端服务的 `httpPort` |
181
+ | `DSH_HOME` | DSH 主目录,默认 `~/.dsh` |
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
+
202
+ ### 命令与工具
203
+
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`(默认)。
205
+
206
+ `evolution_review_center` 工具面向聊天端 / 手机端:`action` 取 `brief`、`interactive_review`(默认)、`refine`、`approve`、`reject`。
207
+
208
+ ---
209
+
210
+ ## 已知限制
211
+
212
+ - **辅助通道需要你自己配**:不带任何网关地址或凭据。不设 `DSH_EVOLUTION_BASE_URL` 时复盘走宿主 subagent fork,走不了低延迟辅助模型那条路。
213
+ - **闸门挡不住「没价值」**:四道闸门只做静态检查(命名、frontmatter、禁词、体积),「这条经验值不值得记」仍由模型判断,草稿需要人看。
214
+ - **界面只有中文**:`locale/en.json` 只覆盖插件名与描述,工作台没有英文 UI。
215
+ - **交互卡片依赖宿主**:`evolution_review_center` 的卡片走宿主 `userQuestions` 服务;宿主没有这个服务时退化为返回中文简报文本,需要用户直接回复批示。
216
+ - **远程 HTTP 需显式配置**:默认只监听回环地址,LAN/Tailscale 暴露必须设置令牌;监听错误会记录日志。加密传输与宿主认证要求见手机访问说明。
217
+ - **`mode: apply` 会直接改正式技能库**:只对 `metadata.createdBy: agent` 的技能生效,默认仍是 `draft`。
218
+ - **归档不释放磁盘**:移进 `.archive/`,要回收得自己删。
219
+ - **正文上限 24000 字符**:超了必须拆到 `references/`。
220
+
221
+ ---
222
+
223
+ ## 开发
224
+
225
+ ```bash
226
+ npm test # 80 个测试,含 HTTP 安全回归(node --test test/*.test.mjs)
227
+ npm run audit:parity # 41 项能力对齐审计(37 项 Hermes 能力 + 4 项 DSH 独有)
228
+ npm run audit:prompts # 两段提示词逐字节保真度(LESSON_LAYER_BLOCK / _DO_NOT_CAPTURE_BLOCK)
229
+ npm run sanitize # 脱敏门禁,0 命中才通过
230
+ ```
231
+
232
+ 需要 Node ≥ 20.11(`tools/*.mjs` 用 `import.meta.dirname`),DSH 版本范围为 `>=0.2.2-rc.1 <0.3.0`。CI 会跑语法检查、单元测试、两道审计和脱敏门禁。
233
+
234
+ ### 能力对齐与审计
235
+
236
+ `npm run audit:parity` 逐项核对 Hermes 能力是否落地,并列出 4 项 DSH 独有能力;`npm run audit:prompts` 把 `lib/prompts.js` 里的两段提示词与 `vendor/hermes/background_review.py` 的原文逐字节比对(当前 2098 / 1690 字符全等)。
237
+
238
+ `vendor/hermes/` 是 Nous Research `hermes-agent` 的逐字副本(MIT),见 [`vendor/hermes/PROVENANCE.md`](./vendor/hermes/PROVENANCE.md)。
239
+
240
+ ---
241
+
242
+ ## License
243
+
244
+ [MIT](./LICENSE)。`vendor/hermes/` 下的参考源码来自 Nous Research `hermes-agent`,同样遵循 MIT。
Binary file
Binary file