@jayyuen66/dsh-dir-prep-organize 0.1.3 → 0.1.5

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.md CHANGED
@@ -1,108 +1,218 @@
1
- # @jayyuen66/dsh-dir-prep-organize
1
+ <p align="center">
2
+ <img src="https://cdn.jsdelivr.net/gh/JayYuen666/dsh-dir-prep-organize@main/icon.svg" width="96" height="96" alt="dsh-dir-prep-organize logo" />
3
+ </p>
4
+
5
+ <h1 align="center">dsh-dir-prep-organize</h1>
6
+
7
+ <p align="center"><em>Two buttons beside the dsh chat input: rewrite the draft with the current directory in view, and drop a role template into it.</em></p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@jayyuen66/dsh-dir-prep-organize"><img src="https://img.shields.io/npm/v/@jayyuen66/dsh-dir-prep-organize?style=flat-square&logo=npm&logoColor=white" alt="npm version" /></a>
11
+ <a href="https://www.npmjs.com/package/@jayyuen66/dsh-dir-prep-organize"><img src="https://img.shields.io/npm/dm/@jayyuen66/dsh-dir-prep-organize?style=flat-square" alt="npm downloads" /></a>
12
+ <a href="https://github.com/JayYuen666/dsh-dir-prep-organize/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/JayYuen666/dsh-dir-prep-organize/ci.yml?branch=main&style=flat-square&label=ci" alt="ci" /></a>
13
+ <img src="https://img.shields.io/badge/license-MIT-4c1?style=flat-square" alt="MIT" />
14
+ <img src="https://img.shields.io/badge/node-%3E%3D22.12-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.1--rc.2-658EFF?style=flat-square" alt="dsh" />
16
+ <a href="https://github.com/deepseek-ai/deepseek-harness"><img src="https://img.shields.io/badge/powered_by_dsh-4D6BFE?style=flat-square&logo=deepseek&logoColor=white" alt="powered by dsh" /></a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img src="https://skillicons.dev/icons?i=typescript,react,nodejs" alt="tech stack" />
21
+ </p>
22
+
23
+ <p align="center">
24
+ <a href="https://github.com/JayYuen666"><img src="https://img.shields.io/badge/GitHub-JayYuen666-181717?style=flat-square&logo=github&logoColor=white" alt="GitHub" /></a>
25
+ <a href="mailto:cqwkkj@gmail.com"><img src="https://img.shields.io/badge/Email-cqwkkj@gmail.com-EA4335?style=flat-square&logo=gmail&logoColor=white" alt="Email" /></a>
26
+ <a href="https://twitter.com/JayYuen666"><img src="https://img.shields.io/badge/Twitter-X%2FJayYuen666-000000?style=flat-square&logo=x&logoColor=white" alt="Twitter/X" /></a>
27
+ <a href="./README.zh-CN.md"><img src="https://img.shields.io/badge/lang-简体中文-658EFF?style=flat-square" alt="简体中文" /></a>
28
+ </p>
29
+
30
+ **A [dsh](https://github.com/deepseek-ai/deepseek-harness) plugin: a split "Polish" button that hands your draft, the top level of the session directory and the recent real turns to the current default model for a rewrite, plus a "Template" dropdown of role templates. Zero model tools, zero HTTP routes of its own.**
31
+
32
+ ## <img src="https://api.iconify.design/lucide/file-text.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Contents
33
+
34
+ - [What it does](#what-it-does)
35
+ - [Install](#install)
36
+ - [Verify it is live](#verify-it-is-live)
37
+ - [What it does not provide](#what-it-does-not-provide)
38
+ - [Enabling it in dsh](#enabling-it-in-dsh)
39
+ - [The polish call](#the-polish-call)
40
+ - [Templates](#templates)
41
+ - [Settings](#settings)
42
+ - [Public interface](#public-interface)
43
+ - [Data and privacy](#data-and-privacy)
44
+ - [Known boundaries](#known-boundaries)
45
+ - [FAQ](#faq)
46
+ - [Development](#development)
47
+ - [License](#license)
48
+
49
+ ## <img src="https://api.iconify.design/lucide/shield.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> What it does
50
+
51
+ - Adds **two controls** to the right of the web chat input: a split "Polish" button (main key + caret) and a "Template" dropdown.
52
+ - The main key polishes directly; the caret key offers "polish in a role's style".
53
+ - The dropdown groups entries by their `group` field; an entry with an empty group lands in "General".
54
+ - **Polish** sends the draft, the top level of the session cwd (file names, sizes, and the full text of key text files), and the session's **real** user/assistant turns to the current default model, then replaces the draft with the rewrite.
55
+ - On failure the draft is **never** touched: the button shows an error state for 4 seconds with the reason in its tooltip.
56
+ - **Templates** insert text into the draft: a whole fill when the draft is empty, an append after one blank line otherwise.
57
+ - The built-in set is **85 curated role templates**, generated by `scripts/gen-defaults.mjs` from this package's `agents/` role library - a vendored collection of several hundred role `.md` files across more than twenty department directories. The curated 85 is the number that matters to a user; the library size is not pinned here because it changes whenever the upstream project is refreshed.
58
+ - That table **stays host-side**: the client bundle no longer inlines it. The generated file is ~640 KB and used to push `client.js` to ~711 KB.
59
+ - The browser calls the Remote `defaults` method **once, lazily** (first menu open or first settings-card visit) and reuses it in-process. Nothing is fetched at all when the user already has their own templates.
60
+ - While it has not arrived the menu shows a loading row - not the "no templates" hint. A failure surfaces the host's own reason plus a Retry button.
61
+ - The **"Template library"** card covers per-entry add/edit/delete, a two-step restore of the defaults, one-click import of the whole built-in library, import of a local `.md` or directory **by path**, and registration of extra allowed import directories. That card is **one list feeding two places**: the input-box "Template" dropdown and the "Polish" ▾ role menu.
62
+ - Templates and allowed directories are read and written through the host settings with **zero LLM calls**, and **no model tool is registered**.
63
+
64
+ ## <img src="https://api.iconify.design/lucide/package.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Install
2
65
 
3
- [English](./README.md) · [简体中文](./README.zh-CN.md)
66
+ ```sh
67
+ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
68
+ ```
69
+
70
+ Remove with `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`. The package is on the public npm registry, so installation needs no credentials and no scoped-registry line.
71
+
72
+ - **Requires Node.js `>= 22.12`.** This is an ESM-only package. Use the **named** exports (`import { apply } from "@jayyuen66/dsh-dir-prep-organize"`); there is **no default export**, so `import pkg from …` fails with `does not provide an export named 'default'`. That Node floor is what makes `require()` of an ESM entry work at all, which is why `engines.node` is declared.
73
+ - **Requires host `dsh` at the `0.2.1-rc.2` line.** The requirement the host actually reads is `engines.dsh` (`^0.2.1-rc.2`), and it **decides alone**: `evaluatePluginCompatibility` returns on the `engines.dsh` branch before it ever looks at `peerDependencies`. Measured against the real host code: `0.2.0-rc.2` is **refused**, `0.2.1-rc.2` and `0.2.2` pass, `0.3.0` is refused. A refused host needs the explicit risk grant `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`.
74
+ - **The `@deepseek-ai/dsh-*` pins stay at `0.2.1-rc.2`** - the version this package is built and tested against. The `engines.dsh` range is a claim about which *hosts* it runs on; the pin is a fact about which host version it was *compiled* against. Mixing the two is why the publish gate checks them separately.
75
+ - **No `@deepseek-ai/*` under `dependencies`, by contract** (`test/publish-manifest.test.ts` enforces it). Consumer profiles install with `nodeLinker: hoisted` and `autoInstallPeers: false`, so a host package under `dependencies` is materialized as a **real directory** next to the copy the running host already loaded. `@deepseek-ai/dsh-tools` keys its tool-runtime scheduler with a plain `Symbol` (not `Symbol.for`), so symbol identity is per module instance: the host reads the scheduler off the profile copy, gets `undefined`, and **every native tool call throws** - while this package's build, typecheck and coverage gates stay green right up to that moment.
76
+ - **The two host packages `host.js` imports as values are required peers**: `@deepseek-ai/schemastery` (the host's fork - only it resolves the `.volatile()` fields) and `@deepseek-ai/dsh-brand`. `build-host.mjs` externalizes `dependencies` **and** `peerDependencies`, so the bare specifiers stay in the artifact; a devDependencies-only entry would let the bundler inline the official function body. `test/build-host.test.ts` pins both "specifier present" and "function body absent".
77
+ - **Every host package the emitted declarations name is declared under `peerDependencies`**, and each one reached only there is *optional* (`@deepseek-ai/cordis`, `cosmokit`, and the `dsh-agent-default-model` / client-ui / `fs` / `llm` / `session` family). Declaring them is not ceremony: under pnpm's strict layout a bare specifier in `types/host.d.ts` that no manifest table names is unresolvable on the consumer's side, while this repository's own typecheck stays green. The test reads that roster off `types/**/*.d.ts` rather than off this paragraph, so the two cannot drift apart.
78
+ - **What ships**: `host.js`, `client.js`, `templates.data.mjs`, `types/`, `cordis.patch.yml`, `agents/` and `THIRD_PARTY_NOTICES.md`. `package.json`, `README*` and `LICENSE` are attached unconditionally by the registry client.
79
+ - **The built-in table ships as its own artifact and is loaded on first use**, not at plugin load. It used to be bundled into `host.js`, so every user paid for the templates in memory even without opening the dropdown.
80
+ - **`agents/` is not authored here**: it comes from [`agency-agents-zh`](https://github.com/jnMetaCode/agency-agents-zh) (MIT). The copyright and licence notice ship in `THIRD_PARTY_NOTICES.md`, because MIT requires it in every distributed copy. Do not hand-edit files under `agents/`.
81
+
82
+ ### <img src="https://api.iconify.design/lucide/arrow-down-to-line.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Shared version floor
83
+
84
+ If your profile pins `@jayyuen66/dsh-plugin-shared` with a pnpm `overrides` entry, that pin must be at least the version this package declares. A lower pin installs a copy without the names imported at runtime, and the host then reports `N entries did not activate` together with `does not provide an export named ...` at boot - the package installs fine and never loads, and no per-repository CI run can see it.
85
+
86
+ ## <img src="https://api.iconify.design/lucide/circle-check.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Verify it is live
4
87
 
5
- ## What it does
88
+ 1. **Two controls appear** to the right of the chat input. If they do not, the bundle layer is not mounted - check `dsh --profile web --dump-config` for the `dir-prep-organize` layer.
89
+ - `--dump-config` is the only accepted "it is in the layer stack" signal, and it is **not read-only** - it rewrites that profile's root assembly file. Read layer lines from stdout **and** check stderr separately: an unmatched patch target appears only on stderr, so the exit code alone proves nothing.
90
+ - A layer line may read `# == <layer>` or `# == <layer>, patched by <path>`; accept both forms.
91
+ 2. **The dropdown fills**: open "Template" and the built-in list arrives through the Remote `defaults` method. A loading row means the call is in flight; a failure shows the host's reason plus Retry.
92
+ 3. **Polish works**: press the main key. The draft is replaced on success; on failure it is untouched and the button turns into an error state whose tooltip carries the reason.
93
+ 4. **The settings card renders**: "Template library" appears on the settings page, edits stage locally and take effect after **Save**.
6
94
 
7
- - Adds two controls to the right of the dsh web chat input: a split "Organize" button and a "Template" dropdown.
8
- - The main Organize key organizes directly, the caret key offers "organize from a role's point of view"; the Template dropdown groups entries by `group`, and an empty group falls into "General".
9
- - "Organize" hands the draft plus the top level of the session cwd (file names, sizes, full text of key text files) plus the session's recent real turns to the current default model for a rewrite.
10
- - On success the draft is replaced; on failure it stays untouched and the button shows an error state for 4 seconds (reason in its title).
11
- - Picking a template inserts it into the draft: a whole fill when the draft is empty, an append after one blank line otherwise.
12
- - The default list is 85 curated role templates generated by scripts/gen-defaults.mjs from this package's agents/ role library (21 department directories, 293 role .md files).
13
- - That table **stays host-side only**: the client bundle no longer inlines it - the generated file is 640KB and used to push `client.js` to 711KB.
14
- - The browser calls the Remote `defaults` method once, lazily - on the first menu open or settings-card visit - and reuses it in-process afterwards.
15
- - While it has not arrived the menus show a loading row rather than the existing "no templates" hint, and a failure surfaces the host's own reason plus a Retry button. Nothing is fetched at all when the user already has their own templates.
16
- - The "Prompt templates" card on the settings page covers per-entry add/edit/delete, two-step restore of defaults, one-click import of the whole built-in library, import of a local .md or directory by path, and registration of import allowed directories.
17
- - Templates and allowed directories are read and written through the host settings with zero LLM calls, and no model tool is registered.
95
+ ## <img src="https://api.iconify.design/lucide/circle-slash.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> What it does not provide
18
96
 
19
- ## Install
97
+ Worth knowing before you look for them:
20
98
 
21
- The packages are published to the public npm registry (`registry.npmjs.org`), so installation needs no credentials:
99
+ - **It registers no model tools.** The host half only injects `settings`; it never touches the tool registry. There is no `organize_text` tool to call.
100
+ - **It opens no HTTP route of its own.** The data plane is the official Typert Remote namespace `dirPrepOrganize`, registered through an injected child fiber, reached through the host `/api` gateway. Authentication, Host/DNS-rebinding/Origin checks, the signed browser-session cookie and body limits are all the gateway's - this package keeps no CSRF token and no route table.
101
+ - **It adds no CLI subcommand.**
102
+ - **It reads no environment variable** and makes no outbound request of its own.
103
+ - What it *does* consume: the host `settings` service (hard-injected), `llm.stream`, `agentDefaultModel`, and the session/filesystem services. Without `settings` the card is disabled with a warning and the dropdown falls back to the built-in curated set.
104
+
105
+ ## <img src="https://api.iconify.design/lucide/plug.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Enabling it in dsh
106
+
107
+ - Installing contributes the bundle patch layer (`dsh.bundle.patch` → `./cordis.patch.yml`), which inserts `- id: dir-prep-organize` with `name` set to the package name.
108
+ - The **client half** registers two slots plus the settings card:
109
+ - `conversation.input.right` - the polish button (id `dir-prep-organize`, order 99) and the templates dropdown (id `dir-prep-organize-templates`, order 100).
110
+ - `plugins.bundle.config` - the settings card, keyed by the **bundle package name** `@jayyuen66/dsh-dir-prep-organize`. The host dispatches `entryKey: pkg.name` (source of truth: `dsh.profile.bundles` in the profile's `package.json`), so a bare entry id never matches and the card would render nowhere.
111
+ - The settings namespace and `configForms.get()` stay the **bare entry id** `dir-prep-organize` - deliberately not the same identifier as that slot key.
112
+ - The client half is `dsh.client.platform = web` with `immediately`.
113
+ - The card follows the official locale plugin's preference for its own labels and copy; the host half reads the preference per request, so switching language needs no restart.
114
+
115
+ ## <img src="https://api.iconify.design/lucide/sparkles.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> The polish call
116
+
117
+ | Aspect | Fact |
118
+ |---|---|
119
+ | Transport | Host `llm.stream`: one **request-only** user text message (no `id`, no `source`) plus a `system` rule block |
120
+ | Model | `agentDefaultModel.currentSelection()` - provider / model / reasoningEffort. Its absence reports "No model selection is available" |
121
+ | Role style | An optional `roleText` injected into the user message's `<data>` fence (never into the system block - see the trust-order note above `buildOrganizeSystem`). It borrows terminology and tone only; it never executes the role's tasks |
122
+ | Finish reason | Anything other than `stop` - including a missing finish chunk - **fails** and never writes back to the draft |
123
+ | Timeout | `organizeTimeoutMs`, default 120000 ms, read per request via `.get()`. The client fetch timeout is that value + 5000 ms |
124
+ | Input caps | `maxSnippetBytes` (262144 = 256 KiB) per key file, `readConcurrency` (8) for reads. Directory, conversation and role text are **never truncated** |
125
+ | No truncation, on purpose | A model context-overflow error is the feedback, and the user slims the input. A payload above the endpoint body cap gets a 413 instead |
126
+
127
+ ## <img src="https://api.iconify.design/lucide/layout-template.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Templates
128
+
129
+ | Aspect | Fact |
130
+ |---|---|
131
+ | Entry shape | `{ id, name, description, text, group, emoji }`, all strings. `description` / `group` / `emoji` default to empty strings |
132
+ | Validation on save | Entries with an empty `name` or `text` are dropped; `emoji` is cut to 12 characters; a missing or colliding `id` is deterministically replaced by `tpl-<index>` |
133
+ | Built-in set | 85 curated templates generated from the `agents/` role library. The dropdown falls back to them when `templates` is unset |
134
+ | "Unset" is an empty array | Under implicit registration schemastery casts a missing array field to `[]`, so **an empty list always means "fall back to built-in"**. Only a non-empty array whose items are all invalid renders as an empty list |
135
+ | Restore defaults | Unsets `templates` back to the curated set and leaves `importAllowRoots` untouched. Two-step confirm; the second click must come within 4 seconds |
136
+ | Import | By path: a local `.md` file or a directory. `path` exactly empty imports the whole built-in library |
137
+
138
+ ## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Settings
139
+
140
+ Namespace `dir-prep-organize` equals the settings entry id. Fields projected into the settings form are the `.volatile()` ones.
141
+
142
+ | Field | Type | Default | Card control | Notes |
143
+ |---|---|---|---|---|
144
+ | `templates` | `{id,name,description,text,group,emoji}[]` | unset | **yes** | The user's own templates. Unset falls back to the 85 built-in entries |
145
+ | `importAllowRoots` | `string[]` | `[]` | **yes** | Extra allowed roots for the import endpoint. Non-strings and whitespace-only items are dropped; duplicates removed. With nothing registered, only the session cwd and the built-in role library are allowed |
146
+ | `organizeTimeoutMs` | natural, volatile | `120000` | **no** | The LLM abort deadline in ms. Clamped to `[1, 2147483647]`: past 2^31-1 Node's `setTimeout` prints a `TimeoutOverflowWarning` and silently uses **1 ms**, which turns "raise the timeout" into "fail instantly". The card has no control, so changing it means `settings.yaml` or the row's `config:` |
147
+ | `maxSnippetBytes` | natural, non-volatile | `262144` | **no** | Per-file cap for key-file snippets; a larger file, or one whose size is unknown, is skipped whole and counted in `skipped.tooLarge`. Import candidates use the same cap. Non-volatile means no form projection, hence no card row - deployment value only |
148
+ | `readConcurrency` | natural, non-volatile | `8` | **no** | Bounded read concurrency for snippets and directory imports. Clamped to `[1, 64]`: `0` or a negative value made the bounded map recurse forever until the host was killed by the OOM killer, and a huge value defeats the fd ceiling this field exists to hold |
149
+
150
+ Settings are persisted in `settings.yaml` under the dsh data directory.
151
+
152
+ ## <img src="https://api.iconify.design/lucide/network.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Public interface
153
+
154
+ Official Typert Remote namespace **`dirPrepOrganize`**, registered through an injected child fiber. The descriptors are hand-written, parameters go through strict shape validation, results go through `src-json`.
155
+
156
+ | Method | Input | Success payload |
157
+ |---|---|---|
158
+ | `defaults` | - | `ok` / `templates[…]` (the curated set) |
159
+ | `context` | `{ sessionId }` | `ok` / `cwd` / `truncated` / `skipped` / `entries[{name,isDir,sizeBytes,snippet}]` |
160
+ | `model` | `{ sessionId }` | `ok` / `provider` / `model` / `reasoningEffort` |
161
+ | `organize` | `{ sessionId, prompt, entriesSummary, roleText? }` | `ok` / `content` |
162
+ | `importTemplates` | `{ path, sessionId }` (`path` exactly empty = whole built-in library) | `ok` / `count` / `truncated` / `skipped` / `entries` |
163
+
164
+ - Business failures stay `ok:false` with `error`. The import path-policy branches are the exception: an out-of-bounds path or a malformed `path` field also carries `status` 403 or 400.
165
+ - Result parsing on the client keeps defensive defaults: a non-object payload or a missing `ok:true` becomes a **visible error**, never an empty list.
166
+
167
+ ## <img src="https://api.iconify.design/lucide/lock.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Data and privacy
168
+
169
+ | Aspect | Fact |
170
+ |---|---|
171
+ | Network | No outbound requests of its own: the data plane is the host gateway's RPC channel. No environment variable is read |
172
+ | On disk | The only data written is `templates` and `importAllowRoots`, in the host settings file |
173
+ | What one polish call sends | The full draft, the session cwd path, top-level directory entries **with the full text of key text files**, the real user/assistant turns (framework-injected messages and tool results are filtered out), and the optional role body |
174
+ | Which files get a snippet | Only 20 code/document extensions (ts/tsx/js/jsx/mjs/cjs/py/rs/go/java/rb/json/toml/md/sql/graphql/proto/css/scss/less). `yaml` / `env` are **not** whitelisted |
175
+ | Sensitive file names | Any file whose name matches `credentials` / `secret(s)` / `id_rsa` / `pem` / `p12` / `pfx` / `keystore` / `env` / `key(s)` / `token(s)` / `auth` / `passwd` / `password` / `account(s)` **at a separator boundary** never gets a snippet. The boundary is deliberate: a naive substring match would drop `monkey.js` and `AUTHORS.md`, while a miss would send credential text to a third-party model |
176
+ | Caps and concurrency | A single file over `maxSnippetBytes`, or with unknown size, is skipped whole - never half-summarized. Reads run with `readConcurrency` |
177
+ | Counters | Too-large / unreadable / deeper-level / non-role cases are counted in `skipped`, shown in the UI, and reflected honestly by `truncated` |
178
+ | Import endpoint | **Read-only**: no model call, no disk writes. Absolute paths are refused by default; only paths inside the session cwd, the package's `agents/` and `importAllowRoots` pass. `.` / `..` / hidden segments (such as `.ssh`) are always rejected, and an out-of-bounds path answers 403 echoing the resolved path |
179
+
180
+ ## <img src="https://api.iconify.design/lucide/triangle-alert.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Known boundaries
181
+
182
+ Registered honestly, one entry per class.
183
+
184
+ - **Nothing is truncated for you.** Directory listings, conversation text and role bodies go in whole. A context overflow is the model's error to report and yours to slim - this plugin will not silently drop half your draft.
185
+ - **The import card has no session context.** Its POST sends `sessionId` as an empty string, so an import must live inside the built-in `agents/` or a registered root, and must contain no `.` / `..` / hidden segments. The rejection names the allowed zones and echoes the resolved path.
186
+ - **Directory import reaches two levels.** The top level plus one sub-directory level; a third level is only **counted** as `deeper`, never imported.
187
+ - **A file whose name cannot be parsed from the first 20 frontmatter lines counts as `unnamed`** and is skipped rather than guessed.
188
+ - **Machine translation does not exist here.** The `agents/` role library and template bodies are user data; they are never translated, whichever interface language is active.
189
+ - **The polish path is best-effort about the model's answer.** A non-`stop` finish reason fails the whole call; a model that returns prose instead of a rewrite replaces your draft with that prose.
190
+
191
+ ## <img src="https://api.iconify.design/lucide/circle-help.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> FAQ
192
+
193
+ | Symptom | What happens |
194
+ |---|---|
195
+ | Nothing changed after pressing "Polish" | Failures never touch the draft; the button shows an error state for a few seconds with the reason in its tooltip. Usual causes: no session cwd (`sessionId` missing or session unknown), no model selection, a finish reason other than `stop`, or the `organizeTimeoutMs` deadline |
196
+ | The model reports a context overflow | Working as designed: input is deliberately not truncated, so the model error is the feedback. A payload above the endpoint body cap gets 413 instead |
197
+ | Importing local roles was refused | Absolute paths are refused by default and the card has no session context. The path must live inside the built-in `agents/` or a registered directory and contain no `.` / `..` / hidden segments |
198
+ | Fewer entries imported than expected | Read the four `skipped` counters: `deeper` (third level, counted only), `tooLarge` (over `maxSnippetBytes`), `unnamed` (no name in the first 20 frontmatter lines), `unreadable` (read failure) |
199
+ | Template edits not applied / wrong language | Edits stage locally and take effect for newly opened dropdowns after **Save**. Labels and copy follow the official locale preference; role and template **bodies** are user data and are never machine translated |
200
+
201
+ ## <img src="https://api.iconify.design/lucide/wrench.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Development
22
202
 
23
203
  ```sh
24
- dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
204
+ pnpm install
205
+ pnpm run check # typecheck → lint → client build → host build → types → tests → format
206
+ pnpm run gen:defaults # regenerate the curated set from agents/ (dev-time only)
25
207
  ```
26
208
 
27
- - Host range `>= 0.2.0-rc.2`, written to both `peerDependencies` and `engines.dsh`. Only `peerDependencies` is actually enforced: since `0.1.7-rc.1` the host evaluates it when loading plugins and disables an entry that fails (`compatibility-preflight.ts` → `deny()`), whereas `engines.dsh` has no reader at this host version.
28
- - The `@deepseek-ai/dsh-*` dependencies stay pinned at `0.2.1-rc.2`, the version this package is built and tested against. The range is a claim about which *hosts* it runs on; the pin is a fact about which host version *it* was compiled against — mixing the two is why the publish gate now checks them separately.
29
- - The client half is `dsh.client.platform = web` with `immediately`.
30
- - The publishing form is one repository per package, `repository.url` is git+https://github.com/JayYuen666/dsh-dir-prep-organize.git ; issues go to that repository's issue tracker (`bugs`).
31
- - Requires Node.js `>= 22.12`. This is an ESM-only package: use `import { apply } from "@jayyuen66/dsh-dir-prep-organize"` or `require("@jayyuen66/dsh-dir-prep-organize")`. There is **no default export** — `import pkg from …` fails with `does not provide an export named 'default'`; take the named exports instead. That Node floor is what makes `require()` of this ESM entry work at all, which is why `engines.node` is declared.
32
- - TypeScript declarations ship as `types/host.d.ts`, wired into both `types` and the `.` export condition. The `Config` schema value carries an explicit annotation so the emitted file never has to name a package a consumer cannot resolve.
33
- - The published artifact ships only `host.js`, `client.js`, `templates.data.mjs`, `types/`, `cordis.patch.yml`, `agents/` and `THIRD_PARTY_NOTICES.md` (package.json `files`). `LICENSE`, `README.md` and `package.json` are attached unconditionally by the registry client.
34
- - The built-in template table lives in its own artifact and is loaded **on first use**, not at plugin load. It used to be bundled into `host.js`, so every user paid for 85 templates in memory even without opening the dropdown - `host.js` is now roughly a tenth of its former size, and the browser already fetched this data lazily anyway.
35
- - `agents/` is not authored here: it comes from the upstream project [`agency-agents-zh`](https://github.com/jnMetaCode/agency-agents-zh) (MIT). Its copyright and licence notice ship in `THIRD_PARTY_NOTICES.md`, because MIT requires it in every distributed copy.
36
- - No `@deepseek-ai/*` goes in `dependencies`, and that is not a style preference. Consumers of this package are dsh plugins installed into a profile (`nodeLinker: hoisted`, `autoInstallPeers: false`), so any host package listed under `dependencies` is written into that profile as a **real directory**, coexisting with the copy the host process already loaded. `@deepseek-ai/dsh-tools` keys its `TOOL_RUNTIME_SCHEDULER` with a plain `Symbol` (not `Symbol.for`), so symbol identity is per module instance: the host's `dsh-agent-loop` reads a `ToolRuntime` mounted from the duplicate using its own copy's symbol, gets `undefined`, and **every native tool call throws** `Cannot read properties of undefined (reading 'prepare')` — the whole profile loses its tools. This package's build, typecheck and tests all stay green right up to that point, so `test/publish-manifest.test.ts` pins the invariant in the manifest instead.
37
- - The two host packages the shipped `host.js` imports as **values** are required (non-optional) `peerDependencies`: `@deepseek-ai/schemastery` (the host's fork — only it resolves 0.1.7 `.volatile()` fields into live references) and `@deepseek-ai/dsh-brand` (`0.2.1-rc.2`). The host provides them at runtime and a profile installs no peers, so no duplicate appears. `build-host.mjs` externalizes `dependencies` *and* `peerDependencies`, so the bare specifiers in `host.js` stay exactly as they were — that is the ruling behind `brandString`: the peer keeps the specifier external and the official function body out of the artifact, while a `devDependencies`-only entry lets rolldown inline it (`test/build-host.test.ts` pins both "specifier present" and "function body absent").
38
- - Every host package the emitted **declarations** name is declared under `peerDependencies`, and each one reached only there is *optional*: `@deepseek-ai/cordis` (`4.0.5`), `@deepseek-ai/cosmokit` (`1.8.6`, reached only through schemastery's `Dict`) and `@deepseek-ai/dsh-agent-default-model`, `-client-locale`, `-client-ui-conversation`, `-client-ui-renderer`, `-client-ui-settings`, `-client-ui-slots`, `-fs`, `-llm`, `-session` (all `0.2.1-rc.2`). Declaring them is not ceremony: under pnpm's strict layout a bare specifier in `types/host.d.ts` that no manifest table names is unresolvable, so the declaration entry simply would not typecheck on the consumer's side while this repository's own typecheck stays green — here both tables carry it. `test/publish-manifest.test.ts` reads that roster off `types/**/*.d.ts` rather than off this paragraph, so the two cannot drift apart. `@deepseek-ai/dsh` is the one peer nothing imports: it names the host, which is what `engines.dsh` says in words.
39
- - Every peer is repeated in `devDependencies` at the same exact pin; that is what lets this repository's own typecheck, build and tests resolve them. The remaining `@deepseek-ai/*` entries here are type-only in source and leave no specifier in the declarations either, so they stay in `devDependencies` alone.
40
- - What is left in `dependencies` is this package's own runtime code: `@jayyuen66/dsh-plugin-shared`.
41
-
42
- ## Enabling it in dsh
43
-
44
- - Installing the package contributes the bundle patch layer (`dsh.bundle.patch` points at `./cordis.patch.yml`), which inserts `- id: dir-prep-organize` with `name` set to the package name.
45
- - Removal goes through `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`.
46
- - The host half hard-injects settings: without it the card is disabled with a warning and the "Template" dropdown falls back to the built-in curated set. The client read surface is the official Typert Remote service `dirPrepOrganize`, registered through an injected child fiber; no `webServer` dependency is involved.
47
- - The client half registers slot `conversation.input.right` (organize id `dir-prep-organize` order 99, templates id `dir-prep-organize-templates` order 100) and the settings card slot `plugins.bundle.config`.
48
- - The card slot key = the bundle package name `@jayyuen66/dsh-dir-prep-organize`: the host dispatches `entryKey: pkg.name` (source of truth: `dsh.profile.bundles` in `~/.dsh/profiles/web/package.json`), so a bare entry id never matches and the card renders nowhere.
49
- - The settings namespace and `configForms.get()` stay the bare entry id `dir-prep-organize` - not the same identifier as that slot key.
50
-
51
- ## Tools exposed to the model
52
-
53
- | Aspect | Fact |
54
- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
- | Tool registration | None. The host half only `inject`s settings and never touches the host tool registry |
56
- | Organize call | Host `llm.stream`: one user text message (**request-only input** - no `id`, no `source`; see the three-evidence note at the top of `host.ts`) plus a `system` rule block; the model comes from `agentDefaultModel.currentSelection()` (provider/model/reasoningEffort) and its absence reports "No model selection is available" |
57
- | Role point of view | Optional `roleText` injected into the "Reference role" part of the system block; it only borrows terminology and tone, it never executes the role's tasks |
58
- | Limits | All three live in config and every request takes them through `limits`: `organizeTimeoutMs` defaults to 120000 ms (a volatile reference read via `.get()`), `maxSnippetBytes` to 262144 (256 KiB) and `readConcurrency` to 8 (plain values, no `.get()`); the client request timeout is `organizeTimeoutMs` + 5000 ms (125000 when the host value is absent; the other four reads use a 125000 ms constant); directory/conversation/role text are never truncated; a finish reason other than `stop` (including a missing finish chunk) fails and never writes back |
59
-
60
- ## Settings
61
-
62
- | Field | Type | Default | Notes |
63
- | ------------------- | ------------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
64
- | `templates` | `{id,name,description,text,group,emoji}[]` | unset | All-string fields; description/group/emoji default to empty strings; entries with an empty name or body are dropped on save, emoji is cut to 12 characters, a missing or colliding id is deterministically replaced by `tpl-<index>`. The dropdown falls back to the 85 built-in curated entries when unset. ⚠ under implicit registration "unset" reaches the client as an **empty array** (schemastery casts a missing array field to `[]`; omitting the default does not yield `undefined`), so an empty list always means "fall back to built-in" - only a non-empty array whose items are all invalid renders as an empty list |
65
- | `importAllowRoots` | `string[]` | `[]` | Extra allowed roots for the import endpoint, registered directory by directory; non-strings and whitespace-only items are dropped and duplicates removed; with nothing registered only the session cwd and the built-in role library are allowed |
66
- | `organizeTimeoutMs` | natural, `.volatile()` | `120000` | The LLM abort deadline in ms; the host reads it per request via `config.organizeTimeoutMs.get()`. Being volatile it is projected into this entry's form snapshot, and of the three it is the only one the client half reads (`rawOrganizeTimeoutMsOf`), used to set the organize fetch timeout to "this value + 5000 ms". ⚠ Clamped to `[1, 2147483647]`: past 2^31-1 Node's `setTimeout` prints a `TimeoutOverflowWarning` and silently uses **1 ms**, which turns "raise the timeout" into "fail instantly". ⚠ The card has **no control** for it: `src/client-entry.ts` writes only `templates` and `importAllowRoots`, so changing it means settings.yaml or the row's `config:` |
67
- | `maxSnippetBytes` | natural (non-volatile) | `262144` | Per-file cap for the key-file snippet; a larger file, or one whose size is unknown, is skipped whole and counted in `skipped.tooLarge`. Import candidates use the same cap. Non-volatile means it is not projected into the form snapshot, so there is no card row either - deployment value only (settings.yaml / row `config:`) |
68
- | `readConcurrency` | natural (non-volatile) | `8` | Bounded read concurrency for the key-file snippets and for directory imports (sub-directory listings, third-level counting, candidate reads). Same as above: no projection, no card control. ⚠ Clamped to `[1, 64]` before use: `0` or a negative value made the bounded map recurse into itself forever until the host process was killed by the OOM killer, and a huge value simply defeats the fd ceiling this field exists to hold |
69
- | Restore defaults | — | — | Unsets `templates` back to the curated set and leaves `importAllowRoots` untouched; two-step confirm, the second click must come within 4 seconds |
70
- | Storage | — | — | Settings namespace `dir-prep-organize` (0.1.7 implicit registration: the namespace is this entry's id, and the fields projected into the settings form are the `.volatile()` ones on `Config` in host.ts - `templates`, `importAllowRoots`, `organizeTimeoutMs`, of which the card writes the first two; `maxSnippetBytes` and `readConcurrency` stay plain values; the curated set stays on the host half and is served on demand, not as a host `base`), persisted in the settings.yaml under `<dsh data dir>` (`$DSH_HOME`) |
71
-
72
- ## Public interface
73
-
74
- Official Typert Remote namespace `dirPrepOrganize`, registered through an injected child fiber. Authentication and transport are enforced by the host `/api` gateway (Host/DNS-rebinding/Origin checks, signed browser-session cookie, body limits); the package opens no HTTP routes and keeps no CSRF token of its own.
75
-
76
- | Method | Input | Success payload |
77
- | ----------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------ |
78
- | `defaults` | — | `ok/templates[{id,name,description,text,group,emoji}]` (the curated set) |
79
- | `context` | `{ sessionId }` | `ok/cwd/truncated/skipped/entries[{name,isDir,sizeBytes,snippet}]` |
80
- | `model` | `{ sessionId }` | `ok/provider/model/reasoningEffort` |
81
- | `organize` | `{ sessionId, prompt, entriesSummary, roleText? }` | `ok/content` |
82
- | `importTemplates` | `{ path, sessionId }` (`path` exactly empty = whole built-in library) | `ok/count/truncated/skipped/entries` |
83
-
84
- - Business failures stay `ok:false` with `error`. The import path-policy branches are the exception: an out-of-bounds path or a malformed `path` field also carries `status` 403 or 400 for callers that surface it.
85
- - Result parsing on the client keeps its defensive defaults: a non-object payload or a missing `ok:true` becomes a visible error, never an empty list.
86
-
87
- ## Data and privacy
88
-
89
- | Aspect | Fact |
90
- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
- | Network calls | No outbound requests: the read surface is reached through the host gateway's RPC channel, and no environment variable is read |
92
- | Data on disk | The only data written to disk is `templates` and `importAllowRoots` in settings |
93
- | What one organize call sends | The full draft, the session cwd path, top-level directory entries with the full text of key text files, real user/assistant turns (framework-injected messages and tool results are filtered out), and the optional role body |
94
- | Snippet extensions | Only 20 code/document extensions (ts/tsx/js/jsx/mjs/cjs/py/rs/go/java/rb/json/toml/md/sql/graphql/proto/css/scss/less); yaml/env types are not whitelisted |
95
- | Sensitive file names | Any file whose name contains credential/secret/id_rsa/.pem/.p12/.pfx/keystore/.env/.key never gets a snippet |
96
- | Per-file cap and concurrency | A single file over `maxSnippetBytes` (default 256 KiB), or with unknown size, is skipped whole (no half summaries), reads run with `readConcurrency` (default 8); both are config fields and neither has a card control |
97
- | Counters and echo | Too-large/unreadable/deeper-level/non-role cases are counted in `skipped`, shown in the UI, and reflected honestly by `truncated` |
98
- | Import endpoint | Read-only: no model call, no disk writes. Absolute paths are refused by default; only paths inside the session cwd, the package's `agents/` and `importAllowRoots` pass, `.`/`..`/hidden segments (such as `.ssh`) are always rejected, and an out-of-bounds path answers 403 echoing the resolved path |
99
-
100
- ## FAQ
101
-
102
- | Symptom | What happens |
103
- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
104
- | Nothing changed after pressing "Organize"? | Failures never touch the draft; the button shows an error state for 4 seconds with the reason in its title. Usual causes: no session cwd (sessionId missing or session unknown), no model selection, a finish reason other than `stop`, the `organizeTimeoutMs` deadline (120 seconds by default) |
105
- | The model reports a context overflow? | Directory/conversation/role text are deliberately not truncated, so the model error is the feedback and you slim the input yourself; a payload above the configured body cap (8 MiB by default) gets 413 from the endpoint instead |
106
- | Importing local roles was refused? | Absolute paths are refused by default and the settings card has no session context (its POST sends `sessionId` as an empty string), so the path must live inside the built-in `agents/` or a registered directory and contain no `.`/`..`/hidden segments; the rejection names the allowed zones and echoes the resolved path |
107
- | Fewer entries imported than expected? | Read the four `skipped` counters: directory imports cover the top level plus one sub-directory level (a third level is only counted as `deeper`), files over `maxSnippetBytes` (256 KiB by default) count as `tooLarge`, files whose name cannot be parsed from the first 20 frontmatter lines count as `unnamed`, and read failures as `unreadable` |
108
- | Template edits not applied / wrong language? | Edits are staged locally and take effect for newly opened dropdowns after "Save"; the card, the two dock buttons next to the input (their labels and copy now live in the `ui-messages.ts` dictionary) and the host replies all follow the official locale plugin's preference (the host side reads it per request, no restart), while the agents/ role library and template bodies are user data and are never machine translated |
209
+ - **`test/gen-defaults.test.ts` is a drift lock.** It compares the generated file field by field against the role library, checks both mirror tables' key order, and requires **byte-level** identity with what the generator produces. Editing the parsing or extraction logic means editing `scripts/gen-defaults-lib.mjs` **and** re-running `pnpm run gen:defaults`; anything else shows up as a red test rather than a silently stale dropdown.
210
+ - The generator exits non-zero when a curated slug is missing or fails to parse, so a role can never disappear silently.
211
+ - The rest of the suite splits the classes of defect a stub cannot see: the host half, the client half, the Remote contract (`test/dir-prep-remote.test.ts`), the two build artifacts (`test/build-host.test.ts`, `test/build-client.test.ts`), and an integration layer.
212
+ - Coverage thresholds are 100% across four metrics, so a new branch needs a case that reaches it.
213
+
214
+ ## <img src="https://api.iconify.design/lucide/scale.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> License
215
+
216
+ MIT. Source at [github.com/JayYuen666/dsh-dir-prep-organize](https://github.com/JayYuen666/dsh-dir-prep-organize). Issues go to that repository's tracker.
217
+
218
+ `agents/` is vendored from [`agency-agents-zh`](https://github.com/jnMetaCode/agency-agents-zh) (MIT); see [`THIRD_PARTY_NOTICES.md`](./THIRD_PARTY_NOTICES.md).