dsh-agent-control-center 0.0.0-stage → 0.2.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/LICENSE +32 -0
  3. package/README.md +252 -2
  4. package/README.zh.md +193 -0
  5. package/client.js +11058 -0
  6. package/cordis.patch.yml +30 -0
  7. package/docs/00-PACKAGE-VERIFICATION.md +88 -0
  8. package/docs/01-CONTRACT.md +381 -0
  9. package/docs/02-REFERENCE-PROVENANCE.md +53 -0
  10. package/docs/04-MODULE-AUTHORING.md +159 -0
  11. package/docs/05-ACCEPTANCE-EVIDENCE.md +247 -0
  12. package/docs/06-UX-OPTIMIZATION.md +57 -0
  13. package/docs/07-GUIDE.md +327 -0
  14. package/docs/08-COMPATIBILITY.md +202 -0
  15. package/docs/09-ARCHITECTURE.md +333 -0
  16. package/docs/DETAIL.en.md +49 -0
  17. package/docs/DETAIL.zh.md +42 -0
  18. package/docs/ROADMAP.md +448 -0
  19. package/icon.svg +6 -0
  20. package/index.js +201 -0
  21. package/lib/core/atomic.js +191 -0
  22. package/lib/core/cache.js +277 -0
  23. package/lib/core/caps.js +100 -0
  24. package/lib/core/compat.js +877 -0
  25. package/lib/core/diff.js +258 -0
  26. package/lib/core/errors.js +79 -0
  27. package/lib/core/http.js +274 -0
  28. package/lib/core/index.js +162 -0
  29. package/lib/core/markdown-checks.js +672 -0
  30. package/lib/core/paths.js +130 -0
  31. package/lib/core/registry.js +225 -0
  32. package/lib/core/store.js +362 -0
  33. package/lib/core/usage-ledger.js +659 -0
  34. package/lib/core/util.js +181 -0
  35. package/lib/modules/a-agents.js +1710 -0
  36. package/lib/modules/b-tools.js +1214 -0
  37. package/lib/modules/c-sessions.js +1428 -0
  38. package/lib/modules/d-usage.js +998 -0
  39. package/lib/modules/e-meta.js +1417 -0
  40. package/lib/modules/f-diagnostics.js +1461 -0
  41. package/lib/modules/g-templates.js +904 -0
  42. package/lib/modules/h-overview.js +220 -0
  43. package/lib/modules/i-recovery.js +861 -0
  44. package/locale/en.json +7 -0
  45. package/locale/zh.json +7 -0
  46. package/package.json +89 -4
  47. package/scripts/build-client.mjs +186 -0
  48. package/scripts/release.mjs +81 -0
  49. package/scripts/verify.mjs +165 -0
  50. package/src/client/app.js +764 -0
  51. package/src/client/i18n/agents.js +354 -0
  52. package/src/client/i18n/common.js +99 -0
  53. package/src/client/i18n/diagnostics.js +334 -0
  54. package/src/client/i18n/meta.js +328 -0
  55. package/src/client/i18n/overview.js +90 -0
  56. package/src/client/i18n/recovery.js +253 -0
  57. package/src/client/i18n/sessions.js +372 -0
  58. package/src/client/i18n/templates.js +288 -0
  59. package/src/client/i18n/tools.js +326 -0
  60. package/src/client/i18n/usage.js +194 -0
  61. package/src/client/kernel.js +727 -0
  62. package/src/client/pages/agents.js +1077 -0
  63. package/src/client/pages/diagnostics.js +631 -0
  64. package/src/client/pages/meta.js +912 -0
  65. package/src/client/pages/overview.js +333 -0
  66. package/src/client/pages/recovery.js +493 -0
  67. package/src/client/pages/sessions.js +1035 -0
  68. package/src/client/pages/templates.js +1035 -0
  69. package/src/client/pages/tools.js +721 -0
  70. package/src/client/pages/usage.js +619 -0
  71. package/templates/agents-md-minimal.json +39 -0
  72. package/templates/agents-md-skeleton.json +64 -0
  73. package/templates/convention-code-style.json +54 -0
  74. package/templates/diagnostics-checklist.json +39 -0
  75. package/templates/persona-reviewer.json +46 -0
  76. package/templates/tooling-shell-guard.json +46 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,131 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 — 2026-11-29
4
+
5
+ Verified against DSH `0.2.2-rc.5`. Everything below was exercised on an isolated
6
+ `accverify` profile; the numbers in the acceptance report come from that run.
7
+
8
+ ### Added
9
+
10
+ - **Read-through cache** for the three expensive read-only views: `tools.list`
11
+ (~5.5 s -> ~0.07 s on a hit), `diagnostics.run` (seconds -> ~14 ms), and
12
+ `recovery.scan` (seconds -> ~8 ms). Same-key concurrency shares one scan,
13
+ errors are never cached, `refresh: true` bypasses, `cacheTtlMs` tunes the TTL
14
+ (null = module defaults, number = all, object = one module, 0 = off), and each
15
+ module warms up after activation without blocking it.
16
+ - **Compatibility layer** (`lib/core/compat.js`): version detection from
17
+ `profileContext`/argv/`DSH_INSTALL_DIR`, semver comparison, a capability ->
18
+ module requirement matrix, and a verdict exposed as `compat` in `/health`
19
+ (`full|degraded|unsupported`, `tested`, `readOnly`, per-module reasons). Host
20
+ write methods are refused with 403 while the verdict is read-only, so an
21
+ untested host version cannot corrupt host files; plugin-owned storage keeps
22
+ working.
23
+ - **Refusals are audited**: a denied request now appends `http.rejected` to the
24
+ plugin audit log instead of leaving no trail.
25
+ - **Documentation and community files**: rewritten `README.md`/`README.zh.md`,
26
+ `docs/07-GUIDE.md` (task-oriented user guide), `docs/08-COMPATIBILITY.md`,
27
+ `docs/09-ARCHITECTURE.md`, `CONTRIBUTING.md`, `SECURITY.md`, issue forms, PR
28
+ template, CODEOWNERS, `.editorconfig`, `.nvmrc`, `.gitattributes`.
29
+ - **Release tooling**: `scripts/release.mjs` (gates -> version -> tag -> push ->
30
+ publish) and a CI workflow that runs the build, the full suite, the contract
31
+ gate and a packed-artifact smoke on Node 22 and 24.
32
+ - **Product roadmap** (`docs/ROADMAP.md`) with IA review, three release
33
+ proposals, and the capabilities the host cannot support.
34
+
35
+ ### Changed
36
+
37
+ - **UI/UX overhaul (two rounds, browser-verified)**: per-page titles and
38
+ descriptions, icon navigation with text status pills, contrast-safe semantic
39
+ colours (44 measurements, minimum 4.93:1 light / 5.09:1 dark), unified
40
+ loading/error/empty states, sticky table heads, row hover, truncation with
41
+ `title`, focus rings, reduced-motion support, responsive breakpoints driven by
42
+ the panel width, English UI without Chinese leakage (host text is mapped per
43
+ id, raw text stays in a labelled `Raw` region), line-level diff confirmation
44
+ before writing AGENTS.md or applying a template, plural-aware confirmations,
45
+ actionable empty states, scan progress with a cancel button, and unique
46
+ accessible names for repeated controls.
47
+ - `sessions.archive`/`unarchive` confirm through the host dialog; archive stays
48
+ the only session action because the host still exposes no delete API.
49
+ - Recovery scan ranges are capped at the backend limit (120 -> 100) and every
50
+ explicit refresh now bypasses the cache.
51
+
52
+ ### Fixed
53
+
54
+ - **Security**: `templates.preview` was an arbitrary-file read primitive inside
55
+ the read roots (could return `~/.dsh/.credentials.yaml` and `~/.npmrc`); it is
56
+ now restricted to real instruction files. Instruction files reached through a
57
+ symlink are refused instead of reading/writing their target, and the path
58
+ fence denies `$DSH_HOME` credentials, provider keys, profiles, storage and
59
+ skills. The fallback HTTP fence now rejects non-loopback `Host` headers (DNS
60
+ rebinding). Internal error hints are sanitized before they reach the page.
61
+ - Registry `refresh()` re-probes modules, so a module that reported BLOCKED
62
+ before its host service mounted recovers instead of staying blocked for the
63
+ process lifetime.
64
+ - `util.redact` covers hyphenated key prefixes (`sk-...`), so provider keys
65
+ cannot reach the audit log in plaintext.
66
+ - The audit list, health aggregate and `updateState` edge cases found by the new
67
+ contract suite.
68
+
69
+ ### Tests
70
+
71
+ - 153 -> **309** behaviour tests (contract, capability matrix, HTTP limits,
72
+ storage atomicity, compatibility, cache, security). All green.
73
+
74
+ ## 0.1.0 — 2026-11-28
75
+
76
+ First release, verified against DSH `0.2.2-rc.5` (web profile).
77
+
78
+ ### Added
79
+
80
+ - One settings entry ("Agent Control Center") with nine internal pages and a
81
+ responsive narrow-screen layout.
82
+ - **Overview**: environment facts, capability presence, module states, real
83
+ counts, internal navigation shortcuts.
84
+ - **AGENTS.md**: instruction-chain discovery (user global / project chain /
85
+ `CLAUDE.md` / `*.local.md`, dedup and budget per host rules), byte-exact read
86
+ (hash, bytes, EOL, BOM, trailing newline), version-guarded save with mandatory
87
+ pre-write backup and read-back verification, backup list/restore, unified
88
+ diff, 11 deterministic checks (empty file, BOM, mixed EOL, unclosed fence,
89
+ heading jumps, duplicate headings, empty sections, duplicated rules,
90
+ suspected conflicting rules, over budget, missing local references), audit
91
+ trail.
92
+ - **Tools**: read-only inventory with three states (registered / visible to an
93
+ agent / called in history), error clusters and recent failures from session
94
+ events; never executes a tool to probe it.
95
+ - **Sessions**: list, title/id search with documented full-text fallback, group
96
+ by workspace or flat, batched archive/unarchive with per-item results and
97
+ retry of failures, expandable detail (turns, steps, messages, tool calls,
98
+ tool distribution, attachments, produced files, web fetches, lineage) with
99
+ response caps, pagination. Session deletion is intentionally absent because
100
+ the host exposes no public API; the page says so.
101
+ - **Usage**: idempotent ledger keyed by `sessionId + seq` with per-session
102
+ cursors, cold-start replay, live event increment, manual recompute, local-day
103
+ pruning, six headline cells, 30-day provider/model CSS bar chart, date picker,
104
+ explicit calibration notes, explicit "statistics start" notice when history
105
+ cannot be replayed.
106
+ - **Agent info**: live agents, presets, default model, redacted export,
107
+ field-level diff, import preview; import applies only to plugin-owned state.
108
+ - **Diagnostics**: 22 probes across ten groups with status/evidence/impact/action,
109
+ Markdown and JSON export, safe repairs limited to the plugin's own storage,
110
+ post-repair re-check.
111
+ - **Templates**: six bundled templates in five categories, source and rendered
112
+ preview, variable fill with unresolved-variable reporting, line-level diff,
113
+ apply through the AGENTS.md save pipeline, user template CRUD with import /
114
+ export and executable-content rejection.
115
+ - **Restart & Resume**: read-only detection of interrupted sessions from event
116
+ semantics (synthetic `TOOL_NOT_STARTED` / `TOOL_OUTCOME_UNKNOWN` results,
117
+ unclosed tail turns) with evidence; no automatic resume, no message injection,
118
+ no log appends.
119
+ - Loopback- and same-origin-fenced HTTP transport with a JSON envelope, method
120
+ whitelist, 1 MiB body cap, explicit status codes, serialized storage writes,
121
+ atomic documents with corruption quarantine and version migration, and an
122
+ append-only audit that never stores contents or credentials.
123
+
124
+ ### Known limits
125
+
126
+ - Session deletion is unavailable (host API absent) and the page hides it.
127
+ - Full-text session search works only when the deployment enables the index;
128
+ otherwise title/id substring matching is used and labelled.
129
+ - Usage cost estimation and provider balance/plan are not implemented (no
130
+ trustworthy price list or currency).
131
+ - No AI analysis entry point is shipped; the plugin never calls a model.
package/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DSH Agent Control Center contributors
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.
22
+
23
+ ---
24
+
25
+ Third-party acknowledgements
26
+
27
+ The behaviour specification for the "sessions" page was modelled on
28
+ `dsh-archived-sessions` (MIT, Copyright (c) 2026 Zephyr-vibe), and the behaviour
29
+ specification for the "usage" page was modelled on `@linxin666/dsh-usage`
30
+ (Apache-2.0, linxin666 / zhu1090093659/dsh-web). This plugin is an independent
31
+ implementation: no source code from either project is copied, neither project
32
+ is required at runtime, and neither project's storage is read or written.
package/README.md CHANGED
@@ -1,3 +1,253 @@
1
- # Temporary Holding Version
1
+ # dsh-agent-control-center
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
+ [English](README.md) | [中文](README.zh.md)
4
+
5
+ **One settings page for a DeepSeek Harness profile.** Nine pages in one
6
+ `Settings → Agent Control Center` section: edit and back up `AGENTS.md`, inspect
7
+ tools, browse and archive sessions, read real token usage, export agent
8
+ metadata, run diagnostics, apply templates, and detect interrupted sessions.
9
+
10
+ The plugin uses only official host services, never fabricates data, never makes
11
+ network requests or spawns subprocesses, and keeps all of its own state in one
12
+ directory under `$DSH_HOME`. It is deliberately read-only where the host gives no
13
+ safe write path.
14
+
15
+ Targets DSH `>=0.2.1-rc.1 <0.3.0`; developed and verified against **DSH 0.2.2-rc.5**.
16
+
17
+ ![Agent Control Center overview page](docs/assets/overview.png)
18
+
19
+ *The Overview page on a real DSH 0.2.2-rc.5 deployment: environment, 21/21 host
20
+ capabilities present, module states, and counts that link to their pages.
21
+ Screenshots live in `docs/assets/` and are excluded from the npm tarball.*
22
+
23
+ ## Pages and status
24
+
25
+ Runtime state comes from `GET /__agent-control-center/health`; the table records
26
+ what the 0.2.0 acceptance run actually proved (details and evidence levels in
27
+ [docs/05-ACCEPTANCE-EVIDENCE.md](docs/05-ACCEPTANCE-EVIDENCE.md)).
28
+
29
+ | Page | What it gives you | State | Why / data source |
30
+ |---|---|---|---|
31
+ | **Overview** | environment, host capabilities, module states, key counts, links into every page | FULL | Every number comes from a host service or a sibling module summary; an unavailable source is labelled with a reason, never shown as `0`. Verified on a real deployment. |
32
+ | **AGENTS.md** | instruction-chain discovery, byte-exact read (hash/bytes/EOL/BOM), version-guarded edit, pre-write backups, restore, unified diff, 11 checks (10 deterministic plus one heuristic conflict suggestion), budget | FULL | Real file read/save/backup/restore and a real 409 were verified; writes go through the host `fs` service with its version guard. Degrades to PARTIAL only when neither `sessionQuery` nor `sessions` exists (working directory falls back). |
33
+ | **Tools** | read-only inventory with three independent states (registered / visible to an agent / called in history), error clusters, recent failures | FULL | 42-tool inventory and history aggregation verified; the module never executes a tool to probe it. PARTIAL when `sessionQuery` is missing (history statistics unavailable). |
34
+ | **Sessions** | list, title/id search (with documented full-text fallback), workspace grouping, batched archive/unarchive, expandable detail with real activity statistics and lineage | PARTIAL | Listing, search, archive state and detail statistics were verified; the archive **write** round-trip was only exercised against fake services (no real sessions were touched). This deployment disables the session full-text index (`openAt: never`), so searches fall back to title/id substrings and the page says so. **No delete**: the host exposes no public session-delete API. |
35
+ | **Usage** | real token accounting (input / cache read / cache write / output / calls), local-day trend 30 days, provider/model split, date picker, retention, collection switch | FULL | Totals, idempotent replay, date-key validation and pruning were verified. Only a live "+1 call" before/after one real model call was not verified (it would consume a paid call). |
36
+ | **Agent info** | live agents, presets, default model, redacted export, field-level diff, import preview | FULL | Agents/presets/default model, redacted export and diff verified. Host configuration import is **BLOCKED by design**: the host has no safe public write path, so import writes only this plugin's own state and says so. |
37
+ | **Diagnostics** | 22 probes across ten groups with evidence/impact/action, Markdown and JSON export, safe repairs limited to the plugin's own storage, post-repair re-check | FULL | Baseline run: 19 ok / 2 warn / 1 unknown. Egress probing stays `unknown` permanently: the plugin never sends a network request to find out. |
38
+ | **Templates** | six bundled templates in five categories, source and rendered preview, variable fill, line-level diff, apply through the AGENTS.md save pipeline, user-template CRUD | FULL | Apply was verified end-to-end through the AGENTS.md pipeline (backup + read-back hash). Templates are data only; executable content is rejected. |
39
+ | **Restart & Resume** | read-only detection of interrupted sessions from recorded event semantics, with evidence and confidence; never resumes anything | PARTIAL | Detection-only by design. Event-semantics detection was verified on a real corpus with no false positives; the `kill -9` crash scene itself was not reproduced (it needs an isolated profile and explicit authorization). |
40
+
41
+ Legend: **FULL** = verified end-to-end on a real deployment. **PARTIAL** = works
42
+ but a documented part is limited by the host or could not be fully verified.
43
+ **BLOCKED** = deliberately hidden or degraded because the host exposes no safe
44
+ capability; the page states the reason.
45
+
46
+ ## Install
47
+
48
+ Use the host's official plugin entry (never hand-edit the profile). `web` and
49
+ `desktop` profiles are supported; the desktop app loads the same Web client.
50
+
51
+ ```bash
52
+ # 1) from npm
53
+ dsh plugin --profile web add dsh-agent-control-center
54
+
55
+ # 2) from a packed tarball
56
+ npm pack
57
+ dsh plugin --profile web add ./dsh-agent-control-center-0.2.0.tgz
58
+
59
+ # 3) from a local checkout
60
+ dsh plugin --profile web add /absolute/path/to/dsh-agent-control-center
61
+ ```
62
+
63
+ Then restart the Web GUI (the Host half mounts its HTTP route at boot) and open
64
+ **Settings → Agent Control Center**. Verify the channel without the browser:
65
+
66
+ ```bash
67
+ curl -s http://127.0.0.1:<gui-port>/__agent-control-center/health
68
+ # → {"ok":true,"value":{"version":"0.2.0", …, "modules":[ … 9 entries … ]}}
69
+ ```
70
+
71
+ Uninstall with `dsh plugin --profile web remove dsh-agent-control-center`.
72
+ To disable without uninstalling, set the row's `enabled` to `false` (no channel,
73
+ no storage writes). The data directory is left in place on uninstall; delete it
74
+ manually to remove all plugin data.
75
+
76
+ The git checkout can be ahead of the published npm version; see
77
+ [CHANGELOG.md](CHANGELOG.md).
78
+
79
+ ## Permissions and security boundaries
80
+
81
+ This plugin runs **in-process inside the DSH host** and therefore shares its
82
+ privileges. It is not a sandbox. What it does enforce:
83
+
84
+ - **Transport.** Exactly one HTTP prefix is mounted through the host Web server:
85
+ `GET /__agent-control-center/health` and `POST /__agent-control-center/api`.
86
+ Only `application/json` bodies are accepted (1 MiB cap, 10 s read timeout), and
87
+ the method name must resolve in the plugin's registry — unknown methods are 404.
88
+ - **Request fence.** Every request first goes through the host's
89
+ `connection.requestRejection(request)` guard when that service exists. When it
90
+ does not, the plugin checks its own fallback: the peer address must be loopback,
91
+ `sec-fetch-site` must not be `cross-site`, and a present `Origin` must match the
92
+ request `Host`. Requests that pass the fence are treated as authenticated local
93
+ requests, which is why destructive methods (save, restore, archive, template
94
+ apply, import apply, diagnostics fix) also require this level.
95
+ - **No plugin CSRF token.** The client relies on same-origin credentials
96
+ (`credentials: 'same-origin'`) and the host's own session handling. Do not put
97
+ the GUI behind an unauthenticated reverse proxy: the plugin's fence is not a
98
+ substitute for the host's auth.
99
+ - **Filesystem fence.** Paths are normalised through `realpath` (missing tails
100
+ resolve against the nearest existing ancestor) and must stay strictly inside an
101
+ allowed root. Writes additionally require the exact file to be on the
102
+ allow-list produced by instruction-chain discovery. Symlink escapes are
103
+ rejected.
104
+ - **Writes go through the host.** Saving or restoring an instruction file uses
105
+ the host `fs` service with `replaceIfVersion` (optimistic lock), an explicit
106
+ caller `sandboxPolicy`, and a strict order: **back up first → write → read back
107
+ and compare → roll back from the backup on mismatch**. A failed backup refuses
108
+ the write.
109
+ - **Storage.** Plugin data lives in `$DSH_HOME/dsh-agent-control-center/`
110
+ (overridable by an absolute `storageDir`), directories `0700`, files `0600`.
111
+ JSON documents are written atomically (temp file + fsync + rename). Corrupt
112
+ documents are quarantined, never silently overwritten; documents with a newer
113
+ unknown `version` switch the plugin to read-only for that document.
114
+ - **Audit and redaction.** `audit.jsonl` records `{ts, op, target, result,
115
+ detail}` only — never file bodies, session bodies, or credential values.
116
+ Diagnostics call `settings.describe({ redactSecrets: true })`, read credential
117
+ *metadata* only, and never read credential values. Exports and report files
118
+ carry no secrets, no session titles and no session bodies; preset YAML is
119
+ masked line by line.
120
+ - **No outbound activity.** The plugin issues no HTTP requests, opens no
121
+ subprocesses, loads no third-party runtime code (`dependencies` is empty; the
122
+ client only `require('react')`), and never calls a model. The `aiAnalysisEnabled`
123
+ field is reserved and the entry point is not shipped.
124
+
125
+ ## Deliberate limits
126
+
127
+ - **No session deletion.** DSH 0.2.2-rc.5 exposes no public session-delete API
128
+ (no session-query write method, no persistence delete, no remote action), so the
129
+ page hides deletion and says why. Archiving is the supported action.
130
+ - **Full-text search may be disabled.** This deployment configures the
131
+ session-query index with `openAt: never`; the page probes by calling the search
132
+ provider and falls back to case-insensitive title/id substring matching, labelled
133
+ in the UI. It does not pretend coverage it does not have.
134
+ - **Detection only, no automatic resume.** The Restart & Resume page reads session
135
+ events and reports candidates with evidence. It never resumes, injects messages,
136
+ appends events, bypasses the write lock, or wakes sessions. Continue in the
137
+ host's own session UI.
138
+ - **No cost estimation, no provider balance/plan.** No trustworthy price list or
139
+ currency is available, so no money is displayed.
140
+ - **No AI analysis.** The plugin never calls a model; `aiAnalysisEnabled` is
141
+ reserved and not implemented.
142
+ - **No host `settings`/`credentials` writes.** Agent-info import writes only this
143
+ plugin's state; host configuration has no safe public write path for that
144
+ document format, so it is reported as `not_supported`, not faked.
145
+ - **AGENTS.md edits only touch discovered chain files.** New files are not
146
+ created; writes are version-guarded and backed up first. Files above the host's
147
+ single-file limit are read-only here.
148
+ - **Multi-tab editing is optimistic.** Another tab or process changing the file
149
+ first makes the later save return 409 without overwriting anything.
150
+ - **Single-process status.** "Not live" means "not in this host process's memory";
151
+ it does not prove the session is not running elsewhere.
152
+ - **Performance.** First loads are not instant: on the acceptance deployment the
153
+ Tools page took ~5.6 s and the recovery scan ~17 s over 340 sessions (both have
154
+ loading/progress states and bounded scans). Usage history can only replay what
155
+ the host can read; the page states the statistics start point.
156
+
157
+ ## Configuration
158
+
159
+ Row `agent-control-center` in `cordis.patch.yml`. Unknown fields, wrong types or
160
+ out-of-range values **fail loudly at load** instead of silently defaulting.
161
+
162
+ | Field | Default | Meaning |
163
+ |---|---|---|
164
+ | `enabled` | `true` | Turn the whole plugin off: no HTTP channel, no storage writes. |
165
+ | `storageDir` | `""` | Absolute storage root; empty means `$DSH_HOME/dsh-agent-control-center`. Must be absolute. |
166
+ | `exposeDelete` | `false` | Reserved. Deletion stays hidden while the host has no API; this flag only allows the UI to offer it. |
167
+ | `maxBackups` | `20` | Pre-write backups kept per instruction file (1–200). |
168
+ | `usageRetentionDays` | `180` | Local-day retention of the usage ledger (7–730). |
169
+ | `usageReplaySessions` | `200` | Sessions replayed on cold start (1–2000). |
170
+ | `usageReplayDays` | `30` | Days replayed on cold start (1–365). |
171
+ | `aiAnalysisEnabled` | `false` | Reserved. The AI entry point is not shipped; the plugin makes no model calls. |
172
+
173
+ ## Storage
174
+
175
+ ```text
176
+ $DSH_HOME/dsh-agent-control-center/ # 0700; storageDir overrides
177
+ ├── state.json # settings, ignored checks, import snapshots (version 1)
178
+ ├── usage-ledger.json # idempotent token ledger: per-session cursor + per-local-day totals
179
+ ├── audit.jsonl # append-only audit (rotates at 4 MiB); no contents, no credentials
180
+ ├── backups/<key>/ # <timestamp>.md + <timestamp>.md.meta.json per save, capped by maxBackups
181
+ ├── templates/ # user templates (JSON)
182
+ ├── cache/ # reserved for derived data; safe to delete
183
+ └── tmp/ # atomic-write temp area and diagnostics probes; safe to clean
184
+ ```
185
+
186
+ Uninstalling the plugin leaves this directory untouched. The plugin writes
187
+ outside it only when you explicitly save/restore an instruction file or
188
+ archive/unarchive sessions — always through host services, with the caller's
189
+ sandbox policy, version guard and a pre-write backup.
190
+
191
+ ## Development
192
+
193
+ Node `>=22.19` (`.nvmrc` pins `22.19`; CI also runs 24). There are **no runtime
194
+ dependencies**, so no install step is needed:
195
+
196
+ ```bash
197
+ node scripts/build-client.mjs # concatenate src/client → client.js + syntax/factory/i18n/size self-checks
198
+ node --test tests/*.test.mjs # behaviour suite
199
+ node scripts/verify.mjs # contract gate: required files, module completeness, forbidden client patterns, package metadata
200
+ ```
201
+
202
+ `npm run verify` runs the build first. CI (`.github/workflows/ci.yml`) runs build
203
+ → `node --test` → verify → a packed-tarball smoke check on Node 22 and 24.
204
+ Tests never touch the real `$DSH_HOME` and never use the network.
205
+
206
+ Release (maintainers, after updating `CHANGELOG.md`):
207
+
208
+ ```bash
209
+ node scripts/release.mjs patch|minor|major [--dry-run] [--notes "text"]
210
+ ```
211
+
212
+ It runs build → full tests → verify, bumps the version, packs, commits, tags,
213
+ pushes and publishes to npm, stopping at the first failure so a half-released
214
+ version cannot land.
215
+
216
+ - Contribution rules: [CONTRIBUTING.md](CONTRIBUTING.md)
217
+ - Security policy and reporting: [SECURITY.md](SECURITY.md)
218
+ - Architecture, request flow, storage layout and extension points:
219
+ [docs/09-ARCHITECTURE.md](docs/09-ARCHITECTURE.md)
220
+ - Task-oriented user guide (Chinese): [docs/07-GUIDE.md](docs/07-GUIDE.md)
221
+ - Internal contract and host-capability facts: [docs/01-CONTRACT.md](docs/01-CONTRACT.md)
222
+
223
+ ## Version and compatibility
224
+
225
+ | Item | Value |
226
+ |---|---|
227
+ | Plugin version | `0.2.0` |
228
+ | DSH range | `>=0.2.1-rc.1 <0.3.0` (`engines.dsh` and `dsh.compatibility.dsh`) |
229
+ | Verified against | DSH `0.2.2-rc.5` (web profile), Node `v24.22.2`, Linux x86_64 |
230
+ | Node | `>=22.19` (CI: 22 and 24) |
231
+ | Host peer | `@deepseek-ai/cordis ^4.0.1` (provided by the host) |
232
+ | Profiles | `web`, `desktop` (same Web client) |
233
+ | Storage document versions | `state.json` 1, `usage-ledger.json` 1, backup metadata 1, template `schemaVersion` 1 |
234
+
235
+ Version windows, the capability dependency matrix and the upgrade checklist are
236
+ in [docs/08-COMPATIBILITY.md](docs/08-COMPATIBILITY.md) (Chinese).
237
+
238
+ DSH public APIs are pre-stable. The plugin is defensive about that — a missing
239
+ service degrades one module instead of failing activation, and `/health` plus the
240
+ Diagnostics page report what is actually present — but a host upgrade outside the
241
+ declared range can still change the wiring. Storage documents with a newer
242
+ unknown version put the plugin into read-only mode for that document instead of
243
+ overwriting it.
244
+
245
+ ## Attribution and license
246
+
247
+ Behaviour specifications were modelled on `dsh-archived-sessions` (MIT,
248
+ Zephyr-vibe) and `@linxin666/dsh-usage` (Apache-2.0, linxin666). This is an
249
+ independent implementation: no copied source, no runtime dependency, no access to
250
+ their storage. See [LICENSE](LICENSE) and
251
+ [docs/02-REFERENCE-PROVENANCE.md](docs/02-REFERENCE-PROVENANCE.md).
252
+
253
+ MIT © 240xu
package/README.zh.md ADDED
@@ -0,0 +1,193 @@
1
+ # dsh-agent-control-center
2
+
3
+ [English](README.md) | [中文](README.zh.md)
4
+
5
+ **一个 DeepSeek Harness(DSH)profile 的统一控制台。** 在 `设置 → Agent 控制台` 一个一级入口里提供九个页面:
6
+ 编辑并备份 `AGENTS.md`、查看工具、浏览与归档会话、读取真实 token 用量、导出 Agent 元信息、跑系统诊断、应用模板、检测中断会话。
7
+
8
+ 插件只使用 DSH 官方服务,不伪造数据,不发起网络请求、不起子进程,自有数据全部放在 `$DSH_HOME` 下的一个目录里;
9
+ 宿主没有安全写入路径的地方一律保持只读并说明原因。
10
+
11
+ 目标宿主 DSH `>=0.2.1-rc.1 <0.3.0`;开发与验证版本为 **DSH 0.2.2-rc.5**。
12
+
13
+ ![Agent 控制台总览页](docs/assets/overview.png)
14
+
15
+ *真实 DSH 0.2.2-rc.5 部署上的总览页:环境、21/21 宿主能力、模块状态,以及与各页面互链的真实计数。
16
+ 截图位于 `docs/assets/`,不包含在 npm tarball 中。*
17
+
18
+ ## 页面与状态
19
+
20
+ 运行期状态来自 `GET /__agent-control-center/health`;下表记录 0.2.0 验收实际证明了什么
21
+ (逐条证据与等级见 [docs/05-ACCEPTANCE-EVIDENCE.md](docs/05-ACCEPTANCE-EVIDENCE.md))。
22
+
23
+ | 页面 | 提供什么 | 状态 | 依据 / 数据来源 |
24
+ |---|---|---|---|
25
+ | **总览** | 环境、宿主能力、模块状态、关键计数、进入每个页面的入口 | FULL | 每个数字都来自宿主服务或兄弟模块摘要;拿不到时显示「不可用 + 原因」,绝不显示 0。已在真实部署验证。 |
26
+ | **AGENTS.md** | 指令链发现、字节级读取(hash/字节/换行/BOM)、版本守卫编辑、写前备份、恢复、统一 diff、11 条校验(10 条确定性 + 1 条疑似冲突分析建议)、预算 | FULL | 真实文件的读取/保存/备份/恢复与真实 409 已验证;写入经宿主 `fs` 服务并带版本守卫。仅当 `sessionQuery` 与 `sessions` 都不存在时降级为 PARTIAL(工作目录回退到默认目录)。 |
27
+ | **工具管理** | 三层互不替代的只读状态(已注册 / 对 Agent 可见 / 历史调用过)、错误聚类、最近失败 | FULL | 42 个工具清单与历史统计已验证;模块**从不执行工具探活**。缺 `sessionQuery` 时为 PARTIAL(历史统计不可用)。 |
28
+ | **会话管理** | 列表、标题/ID 搜索(含明确的全文降级)、按工作区分组、批量归档/取消归档、可展开详情(真实活动统计与谱系) | PARTIAL | 列表、搜索、归档状态与详情统计已验证;归档**写操作**往返只在假服务上验证过(未触碰真实会话)。本部署禁用了会话全文索引(`openAt: never`),搜索降级为标题/ID 子串并在页内标注。**无删除**:宿主没有公开的会话删除 API。 |
29
+ | **使用统计** | 真实 token 口径(输入 / 缓存读 / 缓存写 / 输出 / 调用次数)、近 30 天本地日趋势、provider/model 分布、日期选择、保留期、采集开关 | FULL | 总量、幂等回放、日期键校验与剪枝已验证。唯一未验证项是「真实模型调用前后 +1」的活体比对(会消耗一次付费调用)。 |
30
+ | **Agent 信息** | 活跃 Agent、预设、默认模型、脱敏导出、字段级 diff、导入预览 | FULL | Agent/预设/默认模型、脱敏导出与 diff 已验证。宿主配置导入按设计为 **BLOCKED**:宿主没有安全公开的写路径,导入只写本插件自有 state 并如实说明。 |
31
+ | **诊断** | 10 组共 22 项检查(证据/影响/建议)、Markdown 与 JSON 导出、仅限自有存储的安全修复、修复后复检 | FULL | 基线运行:19 通过 / 2 注意 / 1 未知。出网能力检查永久为 `unknown`:插件不会为了探测而发起网络请求。 |
32
+ | **模板** | 5 个分类共 6 个内置模板、源码与渲染双视图、变量填充、行级 diff、经 AGENTS.md 保存管线应用、用户模板 CRUD | FULL | 应用已端到端验证(先备份 + 回读 hash 一致)。模板只是数据,可执行内容会被拒绝。 |
33
+ | **中断恢复检测** | 从已记录的事件语义只读检测中断会话,给出证据与置信度;**绝不自动续跑** | PARTIAL | 按设计为检测档。事件语义检测在真实语料上验证且无误报;`kill -9` 崩溃现场本身未复现(需要隔离 profile 与明确授权)。 |
34
+
35
+ 图例:**FULL** = 已在真实部署端到端验证。**PARTIAL** = 可用,但有已记录的部分受宿主限制或未能完全验证。
36
+ **BLOCKED** = 宿主没有安全能力,因此刻意隐藏或降级;页面会写出原因。
37
+
38
+ ## 安装
39
+
40
+ 只用宿主官方插件入口(不要手改 profile)。支持 `web` 与 `desktop` profile;桌面端加载的是同一个 Web 客户端。
41
+
42
+ ```bash
43
+ # 1) 从 npm 安装
44
+ dsh plugin --profile web add dsh-agent-control-center
45
+
46
+ # 2) 从打包产物安装
47
+ npm pack
48
+ dsh plugin --profile web add ./dsh-agent-control-center-0.2.0.tgz
49
+
50
+ # 3) 从本地 checkout 安装
51
+ dsh plugin --profile web add /绝对路径/dsh-agent-control-center
52
+ ```
53
+
54
+ 重启 Web GUI(Host 半区在启动时挂载 HTTP 路由),打开 **Settings → Agent Control Center(设置 → Agent 控制台)**。
55
+ 不打开浏览器也可以验证通道:
56
+
57
+ ```bash
58
+ curl -s http://127.0.0.1:<GUI端口>/__agent-control-center/health
59
+ # → {"ok":true,"value":{"version":"0.2.0", …, "modules":[ … 9 项 … ]}}
60
+ ```
61
+
62
+ 卸载:`dsh plugin --profile web remove dsh-agent-control-center`。
63
+ 只想禁用而不卸载:把配置行的 `enabled` 设为 `false`(不建通道、不写存储)。卸载后数据目录保留,需要时手动删除。
64
+
65
+ Git checkout 可能比 npm 已发布版本更新,变更见 [CHANGELOG.md](CHANGELOG.md)。
66
+
67
+ ## 权限与安全边界
68
+
69
+ 本插件**运行在 DSH 宿主进程内**,因此共享宿主权限——它不是一个沙箱。它实际强制的边界是:
70
+
71
+ - **传输**:只通过宿主 Web 服务挂载一个 HTTP 前缀——`GET /__agent-control-center/health` 与
72
+ `POST /__agent-control-center/api`。只接受 `application/json`(上限 1 MiB、读取超时 10 s),
73
+ 方法名必须在插件注册表里,未知方法返回 404。
74
+ - **请求围栏**:每个请求先经过宿主的 `connection.requestRejection(request)`(存在时);不存在时插件用自己的回退判定:
75
+ peer 地址必须是回环、`sec-fetch-site` 不能是 `cross-site`、带 `Origin` 时必须与请求 `Host` 同源。
76
+ 通过围栏的请求被视为「已认证的本地请求」——这也是破坏性方法(保存、恢复、归档、模板应用、导入应用、诊断修复)
77
+ 额外要求的级别。
78
+ - **没有插件级 CSRF token**:客户端依赖同源凭据(`credentials: 'same-origin'`)与宿主自身的会话处理。
79
+ 不要把 GUI 暴露在无认证的反向代理后面:插件的围栏不能替代宿主认证。
80
+ - **路径围栏**:路径先经 `realpath` 规范化(不存在的尾部按最近的已存在祖先解析),必须严格位于允许根内;
81
+ 写操作还要求目标文件在「指令链发现产生的白名单」里。符号链接逃逸会被拒绝。
82
+ - **写入经宿主**:保存/恢复指令文件使用宿主 `fs` 服务的 `replaceIfVersion`(乐观锁)、显式传入调用方 `sandboxPolicy`,
83
+ 并严格按「**先备份 → 写入 → 回读比对 → 不一致则用备份回滚**」;备份失败直接拒绝写入。
84
+ - **存储**:插件数据在 `$DSH_HOME/dsh-agent-control-center/`(可用绝对路径 `storageDir` 覆盖),目录 `0700`、文件 `0600`;
85
+ JSON 文档原子写(临时文件 + fsync + rename);损坏文档隔离保留、绝不静默覆盖;`version` 高于插件支持的文档切只读。
86
+ - **审计与脱敏**:`audit.jsonl` 只记 `{ts, op, target, result, detail}`——不含文件正文、会话正文或凭据值。
87
+ 诊断调用 `settings.describe({ redactSecrets: true })`,凭据只读**元数据**、绝不读凭据值;导出与报告不含密钥、
88
+ 不含会话标题与正文;预设 YAML 逐行遮蔽。
89
+ - **不出网、不起子进程**:插件不发起 HTTP 请求、不创建子进程、不加载第三方运行时代码(`dependencies` 为空,
90
+ 客户端只 `require('react')`),也从不调用模型。`aiAnalysisEnabled` 是保留位,入口不随包提供。
91
+
92
+ ## 有意的限制
93
+
94
+ - **不提供删除会话**:DSH 0.2.2-rc.5 没有公开的会话删除 API(无 session-query 写方法、无 persistence 删除、无远端 action),
95
+ 因此页面隐藏删除并说明原因;归档是受支持的动作。
96
+ - **全文搜索可能被禁用**:本部署把会话索引配成 `openAt: never`;页面通过试调用探测搜索提供方,降级为不区分大小写的
97
+ 标题/ID 子串匹配并在界面标注,不会假装拥有它没有的覆盖范围。
98
+ - **只检测、不自动续跑**:中断恢复页读取会话事件并按证据列出候选;不续跑、不注入消息、不追加事件、不绕过写占用、
99
+ 不唤醒会话。要继续请在宿主原生会话界面操作。
100
+ - **不估算费用、不查 provider 余额/套餐**:没有可信价目表与币种,因此不显示金额。
101
+ - **不提供 AI 分析**:插件不调用模型;`aiAnalysisEnabled` 是保留位,未实现。
102
+ - **不写宿主 `settings`/`credentials`**:Agent 信息导入只写本插件 state;宿主配置对该文档格式没有安全公开写路径,
103
+ 因此返回 `not_supported`,不伪造成功。
104
+ - **AGENTS.md 只改已发现的链上文件**:不新建文件;写入带版本守卫且先备份;超过宿主单文件上限的文件在本页只读。
105
+ - **多标签页编辑是乐观并发**:其它标签页/进程先改文件时,后保存返回 409 且不覆盖任何内容。
106
+ - **单进程状态**:「未在本进程」只表示不在当前宿主进程内存中,不能证明该会话没有在别处运行。
107
+ - **性能**:首屏不是瞬时——验收部署上工具页约 5.6 s、恢复扫描在 340 个会话上约 17 s(两者都有加载/进度态与有界扫描)。
108
+ 用量历史只能回放宿主可读的部分,页面会标注统计起点。
109
+
110
+ ## 配置
111
+
112
+ `cordis.patch.yml` 中 row `agent-control-center`。未知字段、类型错误或越界值会**在加载期直接报错**,不会静默兜底。
113
+
114
+ | 字段 | 默认 | 含义 |
115
+ |---|---|---|
116
+ | `enabled` | `true` | 关闭整个插件:不建 HTTP 通道、不写存储。 |
117
+ | `storageDir` | `""` | 绝对存储根;空表示 `$DSH_HOME/dsh-agent-control-center`。必须是绝对路径。 |
118
+ | `exposeDelete` | `false` | 保留位。宿主没有删除 API 期间删除始终隐藏;该开关只允许 UI「提供」入口。 |
119
+ | `maxBackups` | `20` | 每个指令文件保留的写前备份数(1–200)。 |
120
+ | `usageRetentionDays` | `180` | 用量台账的本地日保留期(7–730)。 |
121
+ | `usageReplaySessions` | `200` | 冷启动回放的会话数上限(1–2000)。 |
122
+ | `usageReplayDays` | `30` | 冷启动回放的天数上限(1–365)。 |
123
+ | `aiAnalysisEnabled` | `false` | 保留位。AI 入口不随包提供;插件不发起模型调用。 |
124
+
125
+ ## 存储
126
+
127
+ ```text
128
+ $DSH_HOME/dsh-agent-control-center/ # 0700;storageDir 可覆盖
129
+ ├── state.json # 设置、忽略项、导入快照(version 1)
130
+ ├── usage-ledger.json # 幂等台账:每会话游标 + 每本地日合计
131
+ ├── audit.jsonl # 追加式审计(4 MiB 轮转);不含正文、不含凭据
132
+ ├── backups/<key>/ # 每次保存的 <时间戳>.md + <时间戳>.md.meta.json,受 maxBackups 限制
133
+ ├── templates/ # 用户模板(JSON)
134
+ ├── cache/ # 派生数据预留目录;可安全删除
135
+ └── tmp/ # 原子写临时区与诊断探针;可安全清理
136
+ ```
137
+
138
+ 卸载插件**不会**删除该目录。插件只在用户显式保存/恢复指令文件或归档/取消归档会话时写到该目录之外——
139
+ 且始终经宿主服务、带调用方沙箱策略、版本守卫与写前备份。
140
+
141
+ ## 开发
142
+
143
+ Node `>=22.19`(`.nvmrc` 固定 `22.19`;CI 另外跑 24)。**没有运行时依赖**,因此不需要安装步骤:
144
+
145
+ ```bash
146
+ node scripts/build-client.mjs # 拼接 src/client → client.js,并做语法/factory/i18n/体积自检
147
+ node --test tests/*.test.mjs # 行为测试
148
+ node scripts/verify.mjs # 契约门禁:必需文件、模块完整性、客户端禁用模式、包元数据
149
+ ```
150
+
151
+ `npm run verify` 会先构建再校验。CI(`.github/workflows/ci.yml`)在 Node 22 与 24 上跑
152
+ build → `node --test` → verify → 打包产物冒烟检查。测试不触碰真实 `$DSH_HOME`,也不联网。
153
+
154
+ 发布(维护者操作,先更新 `CHANGELOG.md`):
155
+
156
+ ```bash
157
+ node scripts/release.mjs patch|minor|major [--dry-run] [--notes "text"]
158
+ ```
159
+
160
+ 依次执行 build → 全量测试 → verify → 版本号 → pack → commit/tag/push → 发布到 npm;任一门禁失败即停止,
161
+ 不会留下半发布状态。
162
+
163
+ - 贡献规范:[CONTRIBUTING.md](CONTRIBUTING.md)
164
+ - 安全策略与报告渠道:[SECURITY.md](SECURITY.md)
165
+ - 架构、请求流、存储布局与扩展点:[docs/09-ARCHITECTURE.md](docs/09-ARCHITECTURE.md)
166
+ - 按任务组织的用户指南(中文):[docs/07-GUIDE.md](docs/07-GUIDE.md)
167
+ - 内部实现契约与宿主能力事实:[docs/01-CONTRACT.md](docs/01-CONTRACT.md)
168
+
169
+ ## 版本与兼容
170
+
171
+ | 项 | 值 |
172
+ |---|---|
173
+ | 插件版本 | `0.2.0` |
174
+ | 宿主区间 | `>=0.2.1-rc.1 <0.3.0`(`engines.dsh` 与 `dsh.compatibility.dsh`) |
175
+ | 验证环境 | DSH `0.2.2-rc.5`(web profile)、Node `v24.22.2`、Linux x86_64 |
176
+ | Node | `>=22.19`(CI:22 与 24) |
177
+ | 宿主 peer | `@deepseek-ai/cordis ^4.0.1`(由宿主提供) |
178
+ | Profile | `web`、`desktop`(同一 Web 客户端) |
179
+ | 存储文档版本 | `state.json` 1、`usage-ledger.json` 1、备份元数据 1、模板 `schemaVersion` 1 |
180
+
181
+ 版本窗口、能力依赖矩阵与升级检查清单见 [docs/08-COMPATIBILITY.md](docs/08-COMPATIBILITY.md)。
182
+
183
+ DSH 公共 API 处于 pre-stable:插件对此是防御式的——某个服务缺失只让对应模块降级,不会让插件激活失败,
184
+ `/health` 与诊断页会如实报告当前到底有什么;但升级到声明区间之外仍可能改变接线。存储文档出现插件不认识的更高
185
+ `version` 时,插件对该文档切只读而不是覆盖。
186
+
187
+ ## 致谢与许可
188
+
189
+ 行为规格参考了 `dsh-archived-sessions`(MIT,Zephyr-vibe)与 `@linxin666/dsh-usage`(Apache-2.0,linxin666)。
190
+ 实现为独立重写:未复制源代码、运行时不依赖、不读写其存储。见 [LICENSE](LICENSE) 与
191
+ [docs/02-REFERENCE-PROVENANCE.md](docs/02-REFERENCE-PROVENANCE.md)。
192
+
193
+ MIT © 240xu