dsh-seal-scripts 0.6.1 → 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.
Files changed (4) hide show
  1. package/README.en.md +226 -231
  2. package/README.md +108 -106
  3. package/lib/client.js +215 -32
  4. package/package.json +1 -1
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,385 +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)
23
- - [Session management](#sec-sessions)
18
+ - [Sealing](#sec-tools)
24
19
  - [Reviews](#sec-reviews)
25
- - [Configuration and settings page](#sec-config)
20
+ - [Session management](#sec-sessions)
21
+ - [Configuration](#sec-config)
26
22
  - [Data and backup](#sec-data)
27
- - [Compatibility and degradation](#sec-compat)
23
+ - [Compatibility](#sec-compat)
28
24
  - [Known limitations](#sec-limits)
29
25
  - [Development](#sec-dev)
30
26
 
31
- <a name="sec-features"></a>
32
-
33
- ## Features
27
+ <a name="sec-class"></a>
34
28
 
35
- #### Sealed scripts
29
+ ## CLI solidification
36
30
 
37
- - **One chain → one tool script**: full script text, entry, args, steps, provenance, per-file sha256.
38
- - **In the system prompt**: the toolSequence block lists every sealed tool, one line each.
39
- - **Runs as written**: args as an argv array, never through a shell; interpreter chosen by the run field.
40
- - **Verifiable**: sha256 compared before running; a hand-edited script is refused unless explicitly allowed.
41
- - **Portable**: store-only zip; import previews first, index rebuilt from the files on disk.
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:
42
32
 
43
- #### Context reviews
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.
44
59
 
45
- - **Captured on compaction**: no model call; tool calls and arguments kept verbatim.
46
- - **Four-level decay**: original → summary → diary → keywords; a read bumps and pins the level.
47
- - **Cross-workspace search**: workspace → children → siblings → parents; outer rings need permission.
48
- - **Diary nudges**: asked once when the diary or keywords are empty.
60
+ <a name="sec-install"></a>
49
61
 
50
- #### Engineering
62
+ ## Install
51
63
 
52
- - Zero runtime dependencies, Node built-ins only; UI and injected text follow DSH's 8 languages, model-facing errors and receipts are English.
53
- - A missing host capability disables that block only.
54
- - Plain-text data: copy `session-memory/` for a backup.
64
+ Add the package through the plugin manager (package name, local path, tarball or Git). `--profile` is required, e.g. `web`:
55
65
 
56
- <a name="sec-install"></a>
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
+ ```
57
71
 
58
- ## Install
72
+ `dsh plugin` forwards its arguments to pnpm inside the profile directory, so the npm route works too:
59
73
 
60
- 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
+ ```
61
78
 
62
- ~~~bash
63
- dsh plugin --profile web add dsh-seal-scripts
64
- dsh plugin --profile web add /path/to/dsh-seal-scripts
65
- ~~~
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.
66
80
 
67
- The second line is a local directory, registered as a link dependency. Restart the profile to load it.
81
+ Reload the profile after installing.
68
82
 
69
- 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`.
70
84
 
71
- After the restart, Settings shows **Tool (script) manager**.
85
+ A **Tool (script) manager** section appearing in settings means it loaded.
72
86
 
73
87
  <a name="sec-quickstart"></a>
74
88
 
75
89
  ## Quick start
76
90
 
77
- 1. **Master switch**: Settings → Tool (script) manager → Options → turn on **Auto review** (off by default; nothing is created while off).
78
- 2. **Run a chain end to end**.
79
- 3. **Seal it**: ask the model to turn the steps above into a tool.
80
- 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`.
81
95
 
82
- ~~~text
83
- You: turn that packaging flow into a tool
84
- Model: (session_tool_create_write) installed dsh-plugin-pack at .../toolSequence/dsh-plugin-pack
85
- 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
86
100
 
87
101
  (new session)
88
- You: run dsh-plugin-pack, the source dir is /sdcard/Download/my-src
89
- Model: (session_tool_call) exit 0, N files, sha256 matches the manifest
90
- ~~~
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
+ ```
91
105
 
92
106
  <a name="sec-tools"></a>
93
107
 
94
- ## Sealed scripts
108
+ ## Sealing
95
109
 
96
- #### Why this is not a note
110
+ #### Triggers
97
111
 
98
- 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.
99
-
100
- #### How to trigger it
101
-
102
- | What you say | What happens | When to use |
112
+ | You say | It does | Good for |
103
113
  |---|---|---|
104
- | turn the steps above into a tool | seals the steps that just ran | same session, commands still in context |
105
- | 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 |
106
116
 
107
- 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`).
108
118
 
109
- #### What gets created
119
+ #### Layout
110
120
 
111
- ~~~
121
+ ```text
112
122
  $DSH_HOME/session-memory/toolSequence/
113
- _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
114
124
  <id>/
115
- toolScript.json manifest: full script text, docs, hashes, provenance
116
- <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)
117
127
  README.md generated from the manifest
118
128
  <notes>.md read-only notes (never executed)
119
- _runs/ full stdout/stderr log of every run
120
- <id>.bak-<timestamp>/ previous directory kept on reinstall or import
121
- ~~~
129
+ _runs/ full stdout/stderr per run
130
+ <id>.bak-<ts>/ kept on replace / import
131
+ ```
122
132
 
123
- #### How the model learns about it
133
+ #### System-prompt injection
124
134
 
125
- 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.
126
136
 
127
137
  | Mode | Behaviour | Cost |
128
138
  |---|---|---|
129
- | 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 |
130
- | 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 |
131
141
 
132
- Changing the mode refreshes every remembered session immediately.
142
+ Switching modes refreshes every remembered session immediately.
133
143
 
134
- #### The three tools
144
+ #### Tools
135
145
 
136
146
  | Tool | Purpose | Key arguments |
137
147
  |---|---|---|
138
- | `session_tool_create_write` | seal a chain | `toolScript{ id, title, purpose, entry, scripts[], docs[], params, steps, timeoutMs }`; `replace` overwrites |
139
- | `session_tool_create_read` | read review originals, read-only | `file` or `date`+`nth`; `mode` = outline / raw / block; `cursor`, `chars`, `line`, `span` |
140
- | `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` |
141
151
 
142
- - No arguments: lists every tool script.
143
- - `dryRun: true`: echoes the arguments and cwd only.
144
- - `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.
145
155
 
146
- #### Validation when sealing
156
+ #### Seal-time validation
147
157
 
148
158
  | Item | Rule |
149
159
  |---|---|
150
- | `id` | starts with a lowercase letter, only `a-z0-9-`, no length limit |
151
- | 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 |
152
162
  | `run` vs extension | bash→`.sh`; node→`.js/.mjs/.cjs`; ps1→`.ps1`; cmd→`.bat/.cmd` |
153
- | size | no cap |
154
- | `title` / `purpose` | non-empty; any length |
155
- | `entry` / `steps` | must name files in `scripts`; entry defaults to the first |
156
- | `timeoutMs` | any positive ms, clamped to the host maxTimeoutMs, defaults to the host timeoutMs |
157
- | docs | must be `.md`, not `README.md`, no duplicates |
158
- | script body | non-empty; must not contain `<!--ovr:` |
159
- | 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 |
160
170
 
161
- `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).
162
172
 
163
- #### Execution semantics
173
+ #### Execution
164
174
 
165
175
  | Item | Value |
166
176
  |---|---|
167
- | interpreter | bash; node uses `process.execPath`; ps1 uses Windows PowerShell (`pwsh` elsewhere); cmd uses `%ComSpec% /d /c` (falls back to `sh` off Windows) |
168
- | 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 |
169
179
  | cwd | `workspace`, `toolScript`, or an absolute path inside either |
170
- | environment | inherits `process.env`, plus `TOOL_NAME`, `TOOL_SCRIPT`, `TOOL_ROOT`, `DSH_HOME` |
171
- | 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 |
172
- | output | DSH maxOutputBytes; every run written to `_runs/` and the reply carries the file path |
173
- | result | `{ exitCode, signal, timedOut, background, pid, logFile, stdout, stderr, truncated, spill }` |
174
- | argument count | more than `params` declares fails before running; fewer is fine |
175
- | drift | sha256 compared first; mismatch refuses, `allowDrift: true` allows it and marks `drift` |
176
- | 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 |
177
187
 
178
188
  #### Import / export
179
189
 
180
- - **Export**: Sealed tools tab → Export. Packs `toolSequence.zip` (store) into the session workspace and returns the path — no browser download.
181
- - **Import**: pick a zip → `dryRun` preview → confirm to write; an existing directory is kept as `.bak-<timestamp>`.
182
- - `_index.json` in the package is not trusted; the index is rebuilt from disk. `_runs`, backups, escaping paths and invalid ids are skipped.
183
- - 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.
184
194
 
185
- #### Clear cache
195
+ #### Clearing caches
186
196
 
187
197
  Two clicks (the first only changes the button label):
188
198
 
189
- - **Deleted**: `<id>.bak-<timestamp>` rollback directories, every log in `_runs/`.
190
- - **Kept**: `_index.json` and every `<id>/` directory.
191
- - Only "valid id + `.bak-` + digits" directories count; a staged import package is skipped.
192
- - 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.
193
203
 
194
- <a name="sec-sessions"></a>
204
+ <a name="sec-reviews"></a>
195
205
 
196
- ## Session management
206
+ ## Reviews
197
207
 
198
- The Sessions tab lists this machine's sessions grouped by workspace and manages each one: import a package, delete it, or delete it after producing a review.
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.
199
209
 
200
- #### The list
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).
201
215
 
202
- - **Grouped by workspace**: one block per workspace that has sessions, headed by the workspace path; empty workspaces take no space.
203
- - **One row each**: the session title (the id in grey while a title does not exist yet), with an **Archived** badge when the session is archived.
204
- - **Unreadable logs are named**: when a log cannot be decoded the list says so at the top instead of showing it as an empty session.
216
+ #### Four levels
205
217
 
206
- #### Import
218
+ | When | Level | Model sees |
219
+ |---|---|---|
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 |
207
224
 
208
- - **One button**: the leftmost **Import** in the footer takes a `dsh-session-<id>.zip`; no hand-built directories. When the host cannot write zstd the button is disabled and says why.
209
- - **Preview first**: the dry run says whether the id will be renamed and whether it hangs under that session as a branch; nothing is written until you confirm.
210
- - **Openable immediately**: the log is packed the way DSH stores it (a one-line header frame plus a body frame) and then `attachSession` registers it; images and files land under the attachment store by sha256; the host is told the list gained a session, so the main window shows it at once, with no restart.
211
- - **Collisions are not forced**: an id that already exists anywhere on this machine gets a new id and the original stays untouched; a same-workspace collision also hangs under that session as a branch (`parentSession`), another workspace gets a plain rename. A session that carries inherited history (`isSeeded:true`) records its real inherited count and still opens and branches.
212
- - **Backed up first**: the workspace roster and projection cache are copied into `会话导入备份-<time>/` inside the target workspace before writing.
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.
213
226
 
214
- #### Delete
227
+ #### Search scope
215
228
 
216
- - **Two taps**: the first tap only turns the button into Confirm; the second deletes.
217
- - **Live sessions are closed first**: cancel → wait idle → flush → release the write handle, then remove the directory; if it cannot be closed, the delete is refused and the log is kept.
218
- - **Removed from the list**: the directory is deleted and the session is detached from its workspace, so it leaves the list at once.
219
- - **Leftovers are reported**: when the engine still holds a reference, the receipt says so ("it may be remembered until restart") instead of pretending it is clean.
229
+ Order: this workspace → children → siblings → parent → parent's siblings → their 1–2 levels of children. Outer rings require `allowOuter`.
220
230
 
221
- #### Delete + review
231
+ Match order: keywords, then summary, then original text; within a workspace by level, hit count, compaction time.
222
232
 
223
- - **Review first, then delete**: compact, wait for the review to be split out, validate, and only then delete.
224
- - **No delete on failure**: any failing step keeps the session; the worst case is "compaction succeeded, split failed, session still there", and that compaction is irreversible.
225
- - **Log**: each failing step writes a line to `session-memory/_compact-delete.log`, otherwise only one English error remains.
226
- - **Result**: the review it produces shows up on the Reviews tab and decays by calendar day.
233
+ #### Reminders
227
234
 
228
- <a name="sec-reviews"></a>
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.
229
236
 
230
- ## Reviews and context memory
237
+ #### Injection and preview
231
238
 
232
- The shadowed transcript is kept as a file and can be read back when it matters.
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".
233
242
 
234
- #### When a review is created
243
+ #### Review tools
235
244
 
236
- - Only on **compaction**: written as one review file (summary + original + empty diary).
237
- - Tool calls and arguments are kept verbatim, never truncated.
238
- - Spawned subagent sessions produce nothing; with Auto review off, not even detection happens.
239
- - Delete + review triggers one on purpose: compact → confirm the review landed → delete. Any failed step aborts.
240
- - 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.
241
- - Once compaction ends, the plugin reads the newest `compaction/summary` and splits the review.
242
- - Every failed step is logged to `session-memory/_compact-delete.log` (trimmed to its last 64 KB past 256 KB).
245
+ Installed only when "Automatic review" is on.
243
246
 
244
- #### Four levels
245
-
246
- | Day | Level | What the model sees |
247
+ | Tool | Purpose | Key arguments |
247
248
  |---|---|---|
248
- | the day of compaction | 3 | the original dialogue (tool calls and errors filtered) |
249
- | day 2 | 2 | the compaction summary |
250
- | days 3–28 | 1 | the diary |
251
- | day 29 and later | 0 | keywords plus the file name |
252
-
253
- 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.
254
-
255
- #### Cross-workspace search
256
-
257
- 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`.
258
-
259
- Hits go keywords first, then summary, then original; within a workspace they sort by level, matched terms, then compaction time.
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[]` |
260
251
 
261
- #### Diary nudges
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.
262
255
 
263
- At level 1 or 0, an empty diary or empty keywords trigger one nudge:
256
+ <a name="sec-sessions"></a>
264
257
 
265
- - **In context** (default): appended to the review text, disappears once written.
266
- - **In the system prompt**: a trailing prompt section.
258
+ ## Session management
267
259
 
268
- #### Injection and preview
260
+ The Sessions tab lists local sessions grouped by workspace, reading persisted logs. Each workspace starts collapsed; click its path to expand.
269
261
 
270
- - Reviews enter the context every turn, oldest first.
271
- - The preview box runs the same assembly function as the real injection (selecting one review shows only that one).
272
- - A failed assembly gives the model a diagnostic (how many, total size, largest file) instead of silently showing no reviews.
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.
273
267
 
274
- #### The two review tools
268
+ #### Import
275
269
 
276
- Installed only while Auto review is on.
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.
277
275
 
278
- | Tool | Purpose | Key arguments |
279
- |---|---|---|
280
- | `session_mem_read` | find a review from a clue, one hit per call | `need` (required), `skip`, `allowOuter` |
281
- | `session_mem_write` | read one original; write keywords and diary, in batch | `file` or `date`+`nth`; `keywords`, `diary`; `writes[]` |
276
+ #### Delete
282
277
 
283
- - Locator only = the Original section: dialogue only, tool calls stripped.
284
- - Writing many uses `writes[]`; all-or-nothing.
285
- - Neither tool changes depth.
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".
286
282
 
287
- #### How it relates to sealing
283
+ #### Delete and review
288
284
 
289
- 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.
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.
290
288
 
291
289
  <a name="sec-config"></a>
292
290
 
293
- ## Configuration and settings page
291
+ ## Configuration
294
292
 
295
- 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.
296
-
297
- #### The four tabs
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.
298
294
 
299
295
  | Tab | Contents |
300
296
  |---|---|
301
- | Sealed tools (`toolList` in the English UI) | tool path, the injected prompt text, list toggle and refresh mode, import / export / clear cache |
302
- | Sessions | sessions grouped by workspace; Delete, Delete + review (both confirmed) |
303
- | Reviews | calendar filter, review list with depth badges, injection preview, delete one |
304
- | Options | four groups: Sealed tools, Recall injection, Review content, Review depth |
305
-
306
- #### 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 |
307
301
 
308
302
  | Field | Values | Default | Meaning |
309
303
  |---|---|---|---|
310
- | `autoReviewEnabled` | bool | `false` | master switch: no reviews, no injection, no review tools when off |
311
- | `injectEnabled` | bool | `true` | recall injection and diary nudges (not the tool list) |
312
- | `toolListEnabled` | bool | `true` | inject the toolSequence block and install/remove the three `session_tool_*` tools |
313
- | `toolListRefresh` | `newSession` / `realtime` | `newSession` | when the list is recomputed |
314
- | `fullLoad` | bool | `false` | keep tool calls and errors at level 3 (full re-injection) |
315
- | `reminderChannel` | `context` / `system` | `context` | where the diary nudge goes |
316
- | `stopLowering` | bool | `false` | reviews keep their recorded level, no daily decay |
317
- | `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) |
318
312
 
319
- 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.
320
314
 
321
- #### UI language
315
+ #### Language
322
316
 
323
- 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.
324
318
 
325
319
  <a name="sec-data"></a>
326
320
 
327
321
  ## Data and backup
328
322
 
329
- ~~~
323
+ ```text
330
324
  $DSH_HOME/session-memory/
331
325
  _options.json options
332
326
  _locale.json language
333
327
  _health.json last success/failure per workspace
334
- _compact-delete.log per-step diagnostics (trimmed past 256 KB)
328
+ _compact-delete.log compaction and delete-and-review diagnostics (>256 KB truncated)
335
329
  <workspace key>/
336
- <stamp>-<id>.md review text (plain text, readable and searchable)
337
- <same name>.json load cache (rebuilt from file time if lost)
338
- _assembly.json.migrated-* leftover of the old index (never auto-deleted)
339
- toolSequence/ tool scripts (machine level, shared)
340
- ~~~
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
+ ```
341
335
 
342
- - The workspace key uses the host `sessions/` encoding: `/` becomes `-`, non-ASCII becomes `~XXXX`.
343
- - Backup: copy the whole `session-memory/`. Migration: put it at the same place on the new machine and install the same plugin.
344
- - 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.
345
339
 
346
340
  <a name="sec-compat"></a>
347
341
 
348
- ## Compatibility and degradation
342
+ ## Compatibility
349
343
 
350
- 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):
351
345
 
352
346
  | Missing | Effect |
353
347
  |---|---|
354
- | `systemPrompt.context` | recall injection off |
355
- | `systemPrompt.section` | diary nudge section and toolSequence block do not appear |
356
- | `tools.register` | none of the five tools is installed |
357
- | `webServer.register` | settings endpoints not installed |
358
- | `agents.create` / `resume` | deleting a live session falls back to tier 2 (plugin-built teardown) |
359
- | `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 |
360
354
 
361
- 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)").
362
356
 
363
- 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.
364
358
 
365
359
  <a name="sec-limits"></a>
366
360
 
367
361
  ## Known limitations
368
362
 
369
- - 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").
370
364
  - `steps` never chain automatically; use `calls`.
371
- - Reviews are created on compaction only; the Reviews tab has no full-text search.
372
- - Subagent sessions produce no reviews and no diary nudges.
373
- - Import and export cover tool scripts only; copy `session-memory/` for reviews.
374
- - Delete + review needs `command-compact` mounted on that session's preset.
375
- - 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.
376
371
 
377
372
  <a name="sec-dev"></a>
378
373
 
379
374
  ## Development
380
375
 
381
- ~~~
376
+ ```text
382
377
  index.js plugin entry (exports name / apply / inject)
383
378
  cordis.patch.yml inserts the plugin into the host loader
384
- lib/core/ host-side logic: storage, decay, tool definitions, script runner
385
- lib/host/ host service adapters: 12 HTTP endpoints, capability probe, session delete
386
- lib/client.js settings page (React, registered at settings.section)
387
- ~~~
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
+ ```
388
383
 
389
384
  - Zero runtime dependencies, ESM, Node `>=18`.
390
- - Tests `node --test test/*.test.mjs` (not shipped in the package).
391
- - 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`.
392
387
 
393
388
  ## License
394
389