dsh-seal-scripts 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [简体中文](./README.md) | **English**
4
4
 
5
- > Seal the scripts that worked. Keep what compaction threw away.
5
+ > Seal a proven CLI chain into a tool script with a contract, replayable as written, with the session's actual call history as raw material.
6
6
 
7
7
  [![version](https://img.shields.io/npm/v/dsh-seal-scripts?color=4a7cff)](https://www.npmjs.com/package/dsh-seal-scripts)
8
8
  [![license](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
@@ -10,350 +10,380 @@
10
10
  [![dsh](https://img.shields.io/badge/dsh-%3E%3D0.2.2--rc.1%20%3C1.0.0-6f42c1)](https://github.com/deepseek-ai/dsh)
11
11
  [![deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen)](./package.json)
12
12
 
13
- **Sealed scripts**: a chain that just worked is sealed into a tool script — a directory, a manifest entry, one line in the system prompt; next time it runs with a single sentence.
14
-
15
- **Reviews**: when DSH compacts the context, the shadowed transcript is written to a review file, decays by calendar day and is injected back; the model can read the original from a clue. Reviews are also the raw material for sealing across sessions.
16
-
17
13
  ## Contents
18
14
 
19
- - [Features](#sec-features)
15
+ - [CLI solidification](#sec-class)
20
16
  - [Install](#sec-install)
21
17
  - [Quick start](#sec-quickstart)
22
- - [Sealed scripts](#sec-tools)
18
+ - [Sealing](#sec-tools)
23
19
  - [Reviews](#sec-reviews)
24
- - [Configuration and settings page](#sec-config)
20
+ - [Session management](#sec-sessions)
21
+ - [Configuration](#sec-config)
25
22
  - [Data and backup](#sec-data)
26
- - [Compatibility and degradation](#sec-compat)
23
+ - [Compatibility](#sec-compat)
27
24
  - [Known limitations](#sec-limits)
28
25
  - [Development](#sec-dev)
29
26
 
30
- <a name="sec-features"></a>
27
+ <a name="sec-class"></a>
31
28
 
32
- ## Features
29
+ ## CLI solidification
33
30
 
34
- #### Sealed scripts
31
+ The binary sits on the machine, but **how to call it is composed by the model every time**; composed correctly, it is still correct only once. Solidifying means storing that run together with its contract, as a tool you can call again:
35
32
 
36
- - **One chain → one tool script**: full script text, entry, args, steps, provenance, per-file sha256.
37
- - **In the system prompt**: the toolSequence block lists every sealed tool, one line each.
38
- - **Runs as written**: args as an argv array, never through a shell; interpreter chosen by the run field.
39
- - **Verifiable**: sha256 compared before running; a hand-edited script is refused unless explicitly allowed.
40
- - **Portable**: store-only zip; import previews first, index rebuilt from the files on disk.
33
+ | Sealed | Where it lives | Effect on replay |
34
+ |---|---|---|
35
+ | Command text | `scripts[].content` + per-file sha256 | Byte-for-byte replay; hand edits rejected before running |
36
+ | Argument contract | `params` (argv order) + arity check | Extra arguments fail before running; fewer are allowed |
37
+ | Interpreter | `run` (bash / node / ps1 / cmd) | No environment guessing |
38
+ | Working directory | `cwd`: `workspace` / `toolScript` / inside either | No forgotten `cd`; paths outside are rejected |
39
+ | Runtime bounds | `timeoutMs`, output cap, timeout to background | Long jobs do not stall the chat; logs in `_runs/` |
40
+ | Provenance | `provenance`, hashes in `toolScript.json` | Knows which conversation it came from and whether it changed |
41
+
42
+ Four steps:
43
+
44
+ ```text
45
+ 1 run it the model uses the CLI normally (ffmpeg / gh / git / its own script)
46
+ 2 seal it session_tool_create_write -> toolSequence/<id>/ dir + manifest + sha256
47
+ 3 announce the tool-group list at the end of the system prompt:
48
+ id (title): purpose | entry | params
49
+ 4 replay session_tool_call{toolScript:"<id>", args:[...]} -> same argv, exit code reported
50
+ ```
51
+
52
+ How it differs from typing the command:
53
+
54
+ - Script text is checked by sha256; hand edits are rejected (`allowDrift` overrides).
55
+ - argv array, never a shell; more args than `params` declares fails before running.
56
+ - Interpreter and cwd are fixed; only files inside the tool directory run, unknown script names rejected.
57
+ - A non-zero exit code fails the tool call; no fake success.
58
+ - The tool list stays in the system prompt; the whole set travels as a zip with an import preview.
41
59
 
42
- #### Context reviews
60
+ <a name="sec-install"></a>
43
61
 
44
- - **Captured on compaction**: no model call; tool calls and arguments kept verbatim.
45
- - **Four-level decay**: original → summary → diary → keywords; a read bumps and pins the level.
46
- - **Cross-workspace search**: workspace → children → siblings → parents; outer rings need permission.
47
- - **Diary nudges**: asked once when the diary or keywords are empty.
62
+ ## Install
48
63
 
49
- #### Engineering
64
+ Add the package through the plugin manager (package name, local path, tarball or Git). `--profile` is required, e.g. `web`:
50
65
 
51
- - Zero runtime dependencies, Node built-ins only; UI and injected text follow DSH's 8 languages, model-facing errors and receipts are English.
52
- - A missing host capability disables that block only.
53
- - Plain-text data: copy `session-memory/` for a backup.
66
+ ```bash
67
+ dsh plugin --profile web add dsh-seal-scripts # latest from the registry
68
+ dsh plugin --profile web add dsh-seal-scripts@0.6.2 # pin a version
69
+ dsh plugin --profile web add /path/to/dsh-seal-scripts # local dir, linked dependency
70
+ ```
54
71
 
55
- <a name="sec-install"></a>
72
+ `dsh plugin` forwards its arguments to pnpm inside the profile directory, so the npm route works too:
56
73
 
57
- ## Install
58
-
59
- Add the package in the plugin manager (package name, local path, tarball, or Git URL). `--profile` is required, e.g. `web`:
74
+ ```bash
75
+ npm i dsh-seal-scripts # install into the current Node environment
76
+ npx dsh plugin --profile web add dsh-seal-scripts
77
+ ```
60
78
 
61
- ~~~bash
62
- dsh plugin --profile web add dsh-seal-scripts
63
- dsh plugin --profile web add /path/to/dsh-seal-scripts
64
- ~~~
79
+ `npm i` alone only fills `node_modules`; it does not register the plugin into a profile — the command above (or the plugin manager) does that by package name.
65
80
 
66
- The second line is a local directory, registered as a link dependency. Restart the profile to load it.
81
+ Reload the profile after installing.
67
82
 
68
- Requirements: host `@deepseek-ai/dsh` `>=0.2.2-rc.1`, `<1.0.0` (peer, not forced); Node `>=18`.
83
+ Requires host `@deepseek-ai/dsh` `>=0.2.2-rc.1`, `<1.0.0` (peer, optional) and Node `>=18`.
69
84
 
70
- After the restart, Settings shows **Tool (script) manager**.
85
+ A **Tool (script) manager** section appearing in settings means it loaded.
71
86
 
72
87
  <a name="sec-quickstart"></a>
73
88
 
74
89
  ## Quick start
75
90
 
76
- 1. **Master switch**: Settings → Tool (script) manager → Options → turn on **Auto review** (off by default; nothing is created while off).
77
- 2. **Run a chain end to end**.
78
- 3. **Seal it**: ask the model to turn the steps above into a tool.
79
- 4. **Reuse it**: "run <id>"; add "show me the commands first, do not run" to preview.
91
+ 1. Settings → Tool (script) manager → Options → enable "Automatic review" (off by default).
92
+ 2. Run a command chain until it works.
93
+ 3. Say "turn the above into a tool"; the model calls `session_tool_create_write`.
94
+ 4. Say "run <id>"; add "show the command first, don't run it" for a `dryRun`.
80
95
 
81
- ~~~text
82
- You: turn that packaging flow into a tool
83
- Model: (session_tool_create_write) installed dsh-plugin-pack at .../toolSequence/dsh-plugin-pack
84
- entry pack.sh, params source_dir out_dir
96
+ ```text
97
+ You: turn that packaging flow into a tool
98
+ Model: (session_tool_create_write) installed dsh-plugin-pack at …/toolSequence/dsh-plugin-pack
99
+ entry pack.sh, params source_dir out_dir
85
100
 
86
101
  (new session)
87
- You: run dsh-plugin-pack, the source dir is /sdcard/Download/my-src
88
- Model: (session_tool_call) exit 0, N files, sha256 matches the manifest
89
- ~~~
102
+ You: run dsh-plugin-pack on /sdcard/Download/my-src
103
+ Model: (session_tool_call) exit 0, N files, sha256 matches the manifest
104
+ ```
90
105
 
91
106
  <a name="sec-tools"></a>
92
107
 
93
- ## Sealed scripts
94
-
95
- #### Why this is not a note
108
+ ## Sealing
96
109
 
97
- A note cannot run, and rebuilding commands on the spot differs every time. What gets stored is the script itself: the lines that worked, byte for byte, argument order included.
110
+ #### Triggers
98
111
 
99
- #### How to trigger it
100
-
101
- | What you say | What happens | When to use |
112
+ | You say | It does | Good for |
102
113
  |---|---|---|
103
- | turn the steps above into a tool | seals the steps that just ran | same session, commands still in context |
104
- | turn the workflow from an earlier session into a tool | reads review originals first with `session_tool_create_read`, then seals | new session, new machine, old history |
114
+ | Turn the above into a tool | Seals the steps that just ran | Same session, commands still in context |
115
+ | Turn that older session into a tool | Reads the review text via `session_tool_create_read`, then seals | New session, new machine |
105
116
 
106
- The version that ran is stored, not a draft; editing after installing means re-sending the context.
117
+ The sealed copy is the one that ran, not a draft. Editing afterwards means resending the context (or `replace`).
107
118
 
108
- #### What gets created
119
+ #### Layout
109
120
 
110
- ~~~
121
+ ```text
111
122
  $DSH_HOME/session-memory/toolSequence/
112
- _index.json registry: id, title, purpose, entry, args, steps, per-file sha256
123
+ _index.json catalog: id, title, purpose, entry, params, steps, per-file sha256
113
124
  <id>/
114
- toolScript.json manifest: full script text, docs, hashes, provenance
115
- <script> the file that actually runs (.sh / .js .mjs .cjs / .ps1 / .bat .cmd)
125
+ toolScript.json manifest: script text, docs, hashes, provenance
126
+ <script> the executed file (.sh / .js .mjs .cjs / .ps1 / .bat .cmd)
116
127
  README.md generated from the manifest
117
128
  <notes>.md read-only notes (never executed)
118
- _runs/ full stdout/stderr log of every run
119
- <id>.bak-<timestamp>/ previous directory kept on reinstall or import
120
- ~~~
129
+ _runs/ full stdout/stderr per run
130
+ <id>.bak-<ts>/ kept on replace / import
131
+ ```
121
132
 
122
- #### How the model learns about it
133
+ #### System-prompt injection
123
134
 
124
- The system prompt gains a toolSequence block, one line each: `· id (title): purpose|entry <entry>|args <p1> <p2>`. No entry or character cap; purpose shown in full.
135
+ A "tool group" section is appended to the system prompt, one line per tool: `id (title): purpose | entry | params`. No count or length cap; the whole purpose text is used.
125
136
 
126
137
  | Mode | Behaviour | Cost |
127
138
  |---|---|---|
128
- | Before a new session (default) | computed at the first assembly, fixed until the session ends | installing or removing a tool mid-session leaves the prompt unchanged |
129
- | Live per session | computed every turn | one cache miss on the next message |
139
+ | Before a new session (default) | Computed once on first assembly, fixed for the session | Installing/removing mid-session leaves the prompt unchanged |
140
+ | Realtime | Recomputed every turn | One cache miss after each change |
130
141
 
131
- Changing the mode refreshes every remembered session immediately.
142
+ Switching modes refreshes every remembered session immediately.
132
143
 
133
- #### The three tools
144
+ #### Tools
134
145
 
135
146
  | Tool | Purpose | Key arguments |
136
147
  |---|---|---|
137
- | `session_tool_create_write` | seal a chain | `toolScript{ id, title, purpose, entry, scripts[], docs[], params, steps, timeoutMs }`; `replace` overwrites |
138
- | `session_tool_create_read` | read review originals, read-only | `file` or `date`+`nth`; `mode` = outline / raw / block; `cursor`, `chars`, `line`, `span` |
139
- | `session_tool_call` | run as written | `toolScript`, `step`, `args`, `stdin`, `cwd`, `dryRun`, `calls`, `stopOnError`, `allowDrift`, `timeoutMs`, `maxOutputBytes` |
148
+ | `session_tool_create_write` | Seal a chain | `toolScript{ id, title, purpose, entry, scripts[], docs[], params, steps, timeoutMs }`; `replace` |
149
+ | `session_tool_create_read` | Read review source text | `file` or `date`+`nth`; `mode` = outline / raw / block; `cursor`, `chars`, `line`, `span` |
150
+ | `session_tool_call` | Replay as written | `toolScript`, `step`, `args`, `stdin`, `cwd`, `dryRun`, `calls`, `stopOnError`, `allowDrift`, `timeoutMs`, `maxOutputBytes` |
140
151
 
141
- - No arguments: lists every tool script.
142
- - `dryRun: true`: echoes the arguments and cwd only.
143
- - `calls: []`: runs in order, no count limit, reporting exit code, duration and logs per entry.
152
+ - No arguments: list all tool scripts.
153
+ - `dryRun: true`: echo argv and cwd only.
154
+ - `calls: []`: run in order, unlimited entries, per-entry exit code, duration and log.
144
155
 
145
- #### Validation when sealing
156
+ #### Seal-time validation
146
157
 
147
158
  | Item | Rule |
148
159
  |---|---|
149
- | `id` | starts with a lowercase letter, only `a-z0-9-`, no length limit |
150
- | file name | starts alphanumeric, letters, digits and . _ - only, no paths, no leading dot |
160
+ | `id` | Starts with a lowercase letter, `a-z0-9-` only, no length limit |
161
+ | File names | Start alphanumeric; letters, digits, `. _ -` only; no paths, no leading dot |
151
162
  | `run` vs extension | bash→`.sh`; node→`.js/.mjs/.cjs`; ps1→`.ps1`; cmd→`.bat/.cmd` |
152
- | size | no cap |
153
- | `title` / `purpose` | non-empty; any length |
154
- | `entry` / `steps` | must name files in `scripts`; entry defaults to the first |
155
- | `timeoutMs` | any positive ms, clamped to the host maxTimeoutMs, defaults to the host timeoutMs |
156
- | docs | must be `.md`, not `README.md`, no duplicates |
157
- | script body | non-empty; must not contain `<!--ovr:` |
158
- | same id exists | refused without `replace`; the error quotes the first 12 hex chars of the manifest sha256 |
163
+ | Size | No limit |
164
+ | `title` / `purpose` | Non-empty; purpose unlimited |
165
+ | `entry` / `steps` | Must name files in `scripts`; entry defaults to the first |
166
+ | `timeoutMs` | Positive ms; clamped to the host maxTimeoutMs at run time |
167
+ | Notes | Must be `.md`, not `README.md`, no duplicates |
168
+ | Body | Non-empty; must not contain `<!--ovr:` |
169
+ | Existing name | Rejected without `replace`, returning the first 12 chars of the manifest sha256 |
159
170
 
160
- `steps` only declares order and never chains; `params` only declares argv order and names are not validated.
171
+ `steps` declares order only (no auto chaining); `params` declares argv order only (names unvalidated).
161
172
 
162
- #### Execution semantics
173
+ #### Execution
163
174
 
164
175
  | Item | Value |
165
176
  |---|---|
166
- | interpreter | bash; node uses `process.execPath`; ps1 uses Windows PowerShell (`pwsh` elsewhere); cmd uses `%ComSpec% /d /c` (falls back to `sh` off Windows) |
167
- | argv | interpreter args + absolute script path + args, as an array, never through a shell |
177
+ | Interpreter | bash; node via `process.execPath`; ps1 via Windows PowerShell (else `pwsh`); cmd via `%ComSpec% /d /c` (else `sh`) |
178
+ | argv | Interpreter flags + absolute script path + args, array form, never a shell |
168
179
  | cwd | `workspace`, `toolScript`, or an absolute path inside either |
169
- | environment | inherits `process.env`, plus `TOOL_NAME`, `TOOL_SCRIPT`, `TOOL_ROOT`, `DSH_HOME` |
170
- | timeout | follows the DSH terminal settings (120 s default, capped by maxTimeoutMs); on expiry it moves to the background and the reply carries pid and the log path; explicit stop: SIGTERM → 2 s → SIGKILL; process group on POSIX, `taskkill /T /F` on Windows |
171
- | output | DSH maxOutputBytes; every run written to `_runs/` and the reply carries the file path |
172
- | result | `{ exitCode, signal, timedOut, background, pid, logFile, stdout, stderr, truncated, spill }` |
173
- | argument count | more than `params` declares fails before running; fewer is fine |
174
- | drift | sha256 compared first; mismatch refuses, `allowDrift: true` allows it and marks `drift` |
175
- | containment | only files inside the script directory run; unknown script names refused |
180
+ | Env | Inherits `process.env` plus `TOOL_NAME`, `TOOL_SCRIPT`, `TOOL_ROOT`, `DSH_HOME` |
181
+ | Timeout | Follows the DSH terminal settings (120 s default, maxTimeoutMs cap); on expiry the run moves to the background with pid and log path; stop = SIGTERM then SIGKILL after 2 s; process group on POSIX, `taskkill /T /F` on Windows |
182
+ | Output | DSH maxOutputBytes by default; every run is written to `_runs/` and the result carries the path |
183
+ | Return | `{ exitCode, signal, timedOut, background, pid, logFile, stdout, stderr, truncated, spill }` |
184
+ | Arity | More args than `params` fails before running; fewer is allowed |
185
+ | Drift | sha256 compared before running; mismatch rejected unless `allowDrift: true` (marked `drift`) |
186
+ | Scope | Only files inside the tool directory; unknown script names rejected |
176
187
 
177
188
  #### Import / export
178
189
 
179
- - **Export**: Sealed tools tab → Export. Packs `toolSequence.zip` (store) into the session workspace and returns the path — no browser download.
180
- - **Import**: pick a zip → `dryRun` preview → confirm to write; an existing directory is kept as `.bak-<timestamp>`.
181
- - `_index.json` in the package is not trusted; the index is rebuilt from disk. `_runs`, backups, escaping paths and invalid ids are skipped.
182
- - No size cap; the zip-bomb guard compares extracted bytes + 16 MB against free disk space. zip64 and encrypted archives are not supported.
190
+ - **Export**: Tools tab → Export, packed as `toolSequence.zip` (store) into the current workspace, returning the path (no browser download).
191
+ - **Import**: pick a zip → `dryRun` preview → confirm; same-name directories kept as `.bak-<ts>`.
192
+ - The archive's `_index.json` is ignored; the index is rebuilt from landed files. `_runs`, backups, out-of-scope paths and invalid ids are skipped.
193
+ - No size limit; zip bombs are judged by "unpacked bytes + 16 MB vs free disk". No zip64, no encryption.
183
194
 
184
- #### Clear cache
195
+ #### Clearing caches
185
196
 
186
197
  Two clicks (the first only changes the button label):
187
198
 
188
- - **Deleted**: `<id>.bak-<timestamp>` rollback directories, every log in `_runs/`.
189
- - **Kept**: `_index.json` and every `<id>/` directory.
190
- - Only "valid id + `.bak-` + digits" directories count; a staged import package is skipped.
191
- - One entry that cannot be removed does not abort the run; the receipt reports counts and bytes.
199
+ - **Deletes**: `<id>.bak-<ts>` rollback directories and all `_runs/` logs.
200
+ - **Keeps**: `_index.json` and every `<id>/` directory.
201
+ - Only "valid id + `.bak-` + digits" directories; in-progress import temp dirs are skipped.
202
+ - One failure does not abort the sweep; the result reports counts and bytes.
192
203
 
193
204
  <a name="sec-reviews"></a>
194
205
 
195
- ## Reviews and context memory
196
-
197
- The shadowed transcript is kept as a file and can be read back when it matters.
206
+ ## Reviews
198
207
 
199
- #### When a review is created
208
+ Reviews are the raw material for sealing: when a session is compacted, **tool calls and their arguments are persisted verbatim**, so the model can later recover the exact chain and seal it with `session_tool_create_write`. Without reviews, sealing can only happen inside a single session.
200
209
 
201
- - Only on **compaction**: written as one review file (summary + original + empty diary).
202
- - Tool calls and arguments are kept verbatim, never truncated.
203
- - Spawned subagent sessions produce nothing; with Auto review off, not even detection happens.
204
- - Delete + review triggers one on purpose: compact → confirm the review landed → delete. Any failed step aborts.
205
- - Compaction runs through the host command registry: the service is mounted per agent preset and isolated, so the plugin root never calls it — `/compact` is executed by the command handler.
206
- - Once compaction ends, the plugin reads the newest `compaction/summary` and splits the review.
207
- - Every failed step is logged to `session-memory/_compact-delete.log` (trimmed to its last 64 KB past 256 KB).
210
+ - Produced only on **compaction**: summary + original text + empty diary; tool calls and arguments kept verbatim.
211
+ - Not produced for subagent sessions; nothing is even checked while "Automatic review" is off.
212
+ - "Delete and review" triggers the chain explicitly; the session is deleted only after the review lands.
213
+ - Compaction runs through the host command table (`/compact` by the command handler); the latest `compaction/summary` is split into a review.
214
+ - Every failed step is logged to `session-memory/_compact-delete.log` (last 64 KB kept past 256 KB).
208
215
 
209
216
  #### Four levels
210
217
 
211
- | Day | Level | What the model sees |
218
+ | When | Level | Model sees |
212
219
  |---|---|---|
213
- | the day of compaction | 3 | the original dialogue (tool calls and errors filtered) |
214
- | day 2 | 2 | the compaction summary |
215
- | days 3–28 | 1 | the diary |
216
- | day 29 and later | 0 | keywords plus the file name |
220
+ | Compaction day | 3 | Original dialogue (tool calls and errors filtered) |
221
+ | Day 2 | 2 | Compaction summary |
222
+ | Day 3–28 | 1 | Diary |
223
+ | From day 29 | 0 | Keywords + file name |
217
224
 
218
- Local calendar days. Only reading this workspace's own review bumps and pins the level (0→1, 1→2) and stops decay; child, sibling and parent reviews are read-only.
225
+ Calendar days, local time. Only this workspace's own review, when read out, gains a level and locks (0→1, 1→2); child, sibling and parent workspaces are read-only and do not count.
219
226
 
220
- #### Cross-workspace search
227
+ #### Search scope
221
228
 
222
- The unit is a workspace review folder. Order: this workspace → children → siblings → the parent → the parent's siblings → their level-1 and level-2 children. Outer rings need `allowOuter`.
229
+ Order: this workspace → children → siblings → parent → parent's siblings → their 1–2 levels of children. Outer rings require `allowOuter`.
223
230
 
224
- Hits go keywords first, then summary, then original; within a workspace they sort by level, matched terms, then compaction time.
231
+ Match order: keywords, then summary, then original text; within a workspace by level, hit count, compaction time.
225
232
 
226
- #### Diary nudges
233
+ #### Reminders
227
234
 
228
- At level 1 or 0, an empty diary or empty keywords trigger one nudge:
229
-
230
- - **In context** (default): appended to the review text, disappears once written.
231
- - **In the system prompt**: a trailing prompt section.
235
+ At level 1 or 0, an empty diary or keyword set triggers one reminder: inline in the review body by default (it disappears once written), or as a system-prompt section.
232
236
 
233
237
  #### Injection and preview
234
238
 
235
- - Reviews enter the context every turn, oldest first.
236
- - The preview box runs the same assembly function as the real injection (selecting one review shows only that one).
237
- - A failed assembly gives the model a diagnostic (how many, total size, largest file) instead of silently showing no reviews.
239
+ - Reviews are injected each turn, oldest first.
240
+ - The settings preview uses the same assembly function as real injection.
241
+ - Assembly failure yields a diagnostic (how many, how large, which is largest), never "no reviews".
238
242
 
239
- #### The two review tools
243
+ #### Review tools
240
244
 
241
- Installed only while Auto review is on.
245
+ Installed only when "Automatic review" is on.
242
246
 
243
247
  | Tool | Purpose | Key arguments |
244
248
  |---|---|---|
245
- | `session_mem_read` | find a review from a clue, one hit per call | `need` (required), `skip`, `allowOuter` |
246
- | `session_mem_write` | read one original; write keywords and diary, in batch | `file` or `date`+`nth`; `keywords`, `diary`; `writes[]` |
249
+ | `session_mem_read` | Find a review by clue, one per call | `need` (required), `skip`, `allowOuter` |
250
+ | `session_mem_write` | Read one review's original text; write keywords and diary, batched | `file` or `date`+`nth`; `keywords`, `diary`; `writes[]` |
247
251
 
248
- - Locator only = the Original section: dialogue only, tool calls stripped.
249
- - Writing many uses `writes[]`; all-or-nothing.
250
- - Neither tool changes depth.
252
+ - Locator without content = read the "original" section: dialogue only, tool calls stripped.
253
+ - Batch via `writes[]`: all entries must validate before anything is written.
254
+ - Neither tool changes a review's level.
251
255
 
252
- #### How it relates to sealing
256
+ <a name="sec-sessions"></a>
253
257
 
254
- Reviews are the raw-material store: the model uses `session_tool_create_read` to recover commands and arguments, then `session_tool_create_write` to seal them.
258
+ ## Session management
255
259
 
256
- <a name="sec-config"></a>
260
+ The Sessions tab lists local sessions grouped by workspace, reading persisted logs. Each workspace starts collapsed; click its path to expand.
261
+
262
+ - Each group is a collapsible workspace header (collapsed by default) with the session count on the right; the selected workspace keeps a blue dot while collapsed; empty workspaces are omitted.
263
+ - Import / Delete / Delete and review sit in the page header, so you do not have to scroll to the bottom of the list.
264
+ - The whole settings section shares one page scrollbar; only the preview boxes (tool list, review) keep their own inner scrollbar.
265
+ - One row per session: title (id placeholder in grey when not yet known), "Archived" badge when applicable.
266
+ - Unreadable logs are reported at the top instead of being shown as empty sessions.
267
+
268
+ #### Import
269
+
270
+ - "Import" at the far left of the page header; pick `dsh-session-<id>.zip`. Disabled with a reason when the host cannot write zstd.
271
+ - Dry run first (new id? branch?), write only after confirmation.
272
+ - Log becomes "header frame + body frame", then `attachSession`; images and files land in the attachment store by sha256; the host list is notified, no restart needed.
273
+ - A colliding id gets a new id, the original untouched; collisions inside the same workspace attach as a branch (`parentSession`).
274
+ - `workspace.json` and the directory registry are backed up into `会话导入备份-<time>/` before writing.
275
+
276
+ #### Delete
257
277
 
258
- ## Configuration and settings page
278
+ - Two-click confirmation.
279
+ - Live sessions are cancelled → idled → flushed → disposed before the directory is removed; refusal keeps the logs.
280
+ - The workspace entry is removed too, so the row disappears.
281
+ - If the engine still holds a reference the result says "may still remember it until restart".
259
282
 
260
- There is one config file, `$DSH_HOME/session-memory/_options.json`; changes apply immediately and are shared by all workspaces. Settings → **Tool (script) manager** → **Options** edits the same file.
283
+ #### Delete and review
261
284
 
262
- #### The four tabs
285
+ - Compress into a review, wait for extraction, verify, then delete; any failure keeps the session.
286
+ - Every failed step is logged to `session-memory/_compact-delete.log`.
287
+ - The review appears on the Reviews tab and decays by calendar day.
288
+
289
+ <a name="sec-config"></a>
290
+
291
+ ## Configuration
292
+
293
+ There is one config file, `$DSH_HOME/session-memory/_options.json`, shared by all workspaces and applied immediately. Settings → **Tool (script) manager** → **Options** edits the same file.
263
294
 
264
295
  | Tab | Contents |
265
296
  |---|---|
266
- | Sealed tools (`toolList` in the English UI) | tool path, the injected prompt text, list toggle and refresh mode, import / export / clear cache |
267
- | Sessions | sessions grouped by workspace; Delete, Delete + review (both confirmed) |
268
- | Reviews | calendar filter, review list with depth badges, injection preview, delete one |
269
- | Options | four groups: Sealed tools, Recall injection, Review content, Review depth |
270
-
271
- #### Every option field
297
+ | Tools | Tool path, injected prompt text, list switch and refresh mode, import / export / clear cache |
298
+ | Sessions | Sessions grouped by workspace; import, delete, delete-and-review (both confirmed) |
299
+ | Reviews | Calendar filter, review list with level badges, injection preview, delete one |
300
+ | Options | Four groups: sealing, review injection, review content, review depth |
272
301
 
273
302
  | Field | Values | Default | Meaning |
274
303
  |---|---|---|---|
275
- | `autoReviewEnabled` | bool | `false` | master switch: no reviews, no injection, no review tools when off |
276
- | `injectEnabled` | bool | `true` | recall injection and diary nudges (not the tool list) |
277
- | `toolListEnabled` | bool | `true` | inject the toolSequence block and install/remove the three `session_tool_*` tools |
278
- | `toolListRefresh` | `newSession` / `realtime` | `newSession` | when the list is recomputed |
279
- | `fullLoad` | bool | `false` | keep tool calls and errors at level 3 (full re-injection) |
280
- | `reminderChannel` | `context` / `system` | `context` | where the diary nudge goes |
281
- | `stopLowering` | bool | `false` | reviews keep their recorded level, no daily decay |
282
- | `loadLevel` | `follow` / 0–3 | `follow` | force a level at load time (recorded depth unchanged) |
304
+ | `autoReviewEnabled` | bool | `false` | Master switch: no reviews, no injection, no review tools when off |
305
+ | `injectEnabled` | bool | `true` | Review injection and diary reminders (not the tool list) |
306
+ | `toolListEnabled` | bool | `true` | Inject the tool list and install the three `session_tool_*` tools |
307
+ | `toolListRefresh` | `newSession` / `realtime` | `newSession` | When the list is recomputed |
308
+ | `fullLoad` | bool | `false` | Keep tool calls and errors at level 3 (reloads everything) |
309
+ | `reminderChannel` | `context` / `system` | `context` | Where diary reminders appear |
310
+ | `stopLowering` | bool | `false` | Reviews keep their recorded level and stop decaying |
311
+ | `loadLevel` | `follow` / 0–3 | `follow` | Force a level at load time (does not change the recorded level) |
283
312
 
284
- Two couplings: with Auto review off, `injectEnabled` reads as off (the stored value is untouched); with Stop lowering on, Load level falls back to follow.
313
+ Two interactions: with automatic review off, review injection counts as off (the stored value is kept); with "stop lowering" on, the load level falls back to follow.
285
314
 
286
- #### UI language
315
+ #### Language
287
316
 
288
- Follows DSH: settings strings, injected review text, diary reminders and the toolSequence block all switch. A review file is written with the header and section titles of the language active **at capture time**; switching later only changes the display (all 8 spellings are accepted). Errors and receipts the tools return to the model are English.
317
+ UI text, injected review bodies, diary reminders and the tool list follow the DSH language setting. Review files record their headers in the language current **when written**; switching language only changes display (all 8 variants are recognised). Tool errors and receipts returned to the model are English.
289
318
 
290
319
  <a name="sec-data"></a>
291
320
 
292
321
  ## Data and backup
293
322
 
294
- ~~~
323
+ ```text
295
324
  $DSH_HOME/session-memory/
296
325
  _options.json options
297
326
  _locale.json language
298
327
  _health.json last success/failure per workspace
299
- _compact-delete.log per-step diagnostics (trimmed past 256 KB)
328
+ _compact-delete.log compaction and delete-and-review diagnostics (>256 KB truncated)
300
329
  <workspace key>/
301
- <stamp>-<id>.md review text (plain text, readable and searchable)
302
- <same name>.json load cache (rebuilt from file time if lost)
303
- _assembly.json.migrated-* leftover of the old index (never auto-deleted)
304
- toolSequence/ tool scripts (machine level, shared)
305
- ~~~
330
+ <ts>-<id>.md review body (plain text, readable and editable)
331
+ <same>.json load cache (rebuilt from file times if lost)
332
+ _assembly.json.migrated-* legacy index leftovers (never deleted automatically)
333
+ toolSequence/ tool scripts (machine-wide, shared by all workspaces)
334
+ ```
306
335
 
307
- - The workspace key uses the host `sessions/` encoding: `/` becomes `-`, non-ASCII becomes `~XXXX`.
308
- - Backup: copy the whole `session-memory/`. Migration: put it at the same place on the new machine and install the same plugin.
309
- - Uninstalling deletes no data.
336
+ - Workspace keys use the host's `sessions/` encoding: `/` becomes `-`, non-ASCII as `~XXXX`.
337
+ - Backup = copy the whole `session-memory/`; migrate = same path on the new machine plus the same plugin.
338
+ - Uninstalling does not delete data.
310
339
 
311
340
  <a name="sec-compat"></a>
312
341
 
313
- ## Compatibility and degradation
342
+ ## Compatibility
314
343
 
315
- Missing host capabilities disable the matching block only (the settings page lists what is missing):
344
+ Missing host capabilities disable the matching part only (the settings page lists what is missing):
316
345
 
317
346
  | Missing | Effect |
318
347
  |---|---|
319
- | `systemPrompt.context` | recall injection off |
320
- | `systemPrompt.section` | diary nudge section and toolSequence block do not appear |
321
- | `tools.register` | none of the five tools is installed |
322
- | `webServer.register` | settings endpoints not installed |
323
- | `agents.create` / `resume` | deleting a live session falls back to tier 2 (plugin-built teardown) |
324
- | `commands.execute`, or `command-compact` not mounted | Delete + review is unavailable; plain delete still works |
348
+ | `systemPrompt.context` | Review injection off |
349
+ | `systemPrompt.section` | No diary-reminder or tool-list section |
350
+ | `tools.register` | None of the five tools is installed |
351
+ | `webServer.register` | No settings API |
352
+ | `agents.create` / `resume` | Deleting a live session drops to fallback teardown |
353
+ | `commands.execute` or no `command-compact` in the preset | Delete-and-review unavailable; plain delete works |
325
354
 
326
- Two tiers for deleting a live session: (1) the `dispose` returned by `agents.create` / `resume`, captured by the lifecycle hook; (2) no handle — the plugin builds its own `cancel({kind:'disposed'})` → `whenIdle()` → `scope.dispose()`. Tier 2 only stops the agent; unregistering belongs to the host closure with no public API, so the delete succeeds with a `warnings` entry (the settings page says the engine may still remember it until restart).
355
+ Deleting a live session has two paths: ① the `dispose` returned by `agents.create` / `resume`, captured by the lifecycle; ② without a handle, a synthetic `cancel({kind:'disposed'})` → `whenIdle()` → `scope.dispose()`. Path ② can stop the agent but cannot unregister it from the host closure, so the delete succeeds with `warnings` ("deleted (may be remembered until engine restart)").
327
356
 
328
- Session logs are multi-frame zstd, split by frame header; without native `zlib.zstdDecompressSync` the built-in decoder takes over.
357
+ Session logs are multi-frame zstd, decoded frame by frame; the built-in decoder is used when `zlib.zstdDecompressSync` is unavailable. Importing sessions needs host zstd compression: without `zstdCompress` the Import button is disabled with a reason.
329
358
 
330
359
  <a name="sec-limits"></a>
331
360
 
332
361
  ## Known limitations
333
362
 
334
- - Tool scripts have **no delete or edit in the UI**: reinstall to overwrite (a `.bak-` is kept) or remove the directory (the registry keeps the entry and later runs report a missing directory).
363
+ - Tool scripts have **no UI for delete or edit**: replace them (keeping `.bak-`) or remove the directory by hand (the index keeps the entry and runs fail with "directory not found").
335
364
  - `steps` never chain automatically; use `calls`.
336
- - Reviews are created on compaction only; the Reviews tab has no full-text search.
337
- - Subagent sessions produce no reviews and no diary nudges.
338
- - Import and export cover tool scripts only; copy `session-memory/` for reviews.
339
- - Delete + review needs `command-compact` mounted on that session's preset.
340
- - With the plugin-built teardown, the engine may still remember the session until it restarts.
365
+ - Reviews are produced only on compaction; the Reviews tab has a calendar filter but no full-text search.
366
+ - Subagent sessions produce no reviews and get no diary reminders.
367
+ - Import/export covers tool scripts only; reviews travel by copying `session-memory/`. Session zips are a separate import on the Sessions tab.
368
+ - Delete-and-review requires the preset to provide `command-compact`.
369
+ - Fallback teardown may leave the session remembered until the engine restarts.
370
+ - A freshly imported cold session shows `Untitled` in the sidebar until the host's title projection loads.
341
371
 
342
372
  <a name="sec-dev"></a>
343
373
 
344
374
  ## Development
345
375
 
346
- ~~~
376
+ ```text
347
377
  index.js plugin entry (exports name / apply / inject)
348
378
  cordis.patch.yml inserts the plugin into the host loader
349
- lib/core/ host-side logic: storage, decay, tool definitions, script runner
350
- lib/host/ host service adapters: 12 HTTP endpoints, capability probe, session delete
351
- lib/client.js settings page (React, registered at settings.section)
352
- ~~~
379
+ lib/core/ host-side logic: persistence, decay, tool definitions, script runner
380
+ lib/host/ host service adapters: HTTP endpoints, capability probing, session import/delete
381
+ lib/client.js settings UI (React, registered into settings.section)
382
+ ```
353
383
 
354
384
  - Zero runtime dependencies, ESM, Node `>=18`.
355
- - Tests `node --test test/*.test.mjs` (not shipped in the package).
356
- - Packaging `npm pack`; whitelist is the `files` field of `package.json`.
385
+ - Tests: `node --test test/*.test.mjs` (not shipped).
386
+ - Package: `npm pack`, whitelist in `package.json` `files`.
357
387
 
358
388
  ## License
359
389