@jayyuen66/dsh-dir-prep-organize 0.1.0 → 0.1.2-rc

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/LICENSE CHANGED
@@ -19,3 +19,10 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
23
+ ---
24
+
25
+ 本文件覆盖本仓自身编写的代码(Copyright (c) 2026 JayYuen)。发布物中的内置角色库
26
+ `agents/` 来自第三方项目 `agency-agents-zh`(MIT,版权归 Michael Sitarzewski 与
27
+ jnMetaCode 所有)。MIT 的条款要求把该版权声明与许可声明随软件副本一并分发,其原文照录
28
+ 于 [`THIRD_PARTY_NOTICES.md`](./THIRD_PARTY_NOTICES.md),该文件随本包一同发布。
package/README.md CHANGED
@@ -1,114 +1,8 @@
1
1
  # @jayyuen66/dsh-dir-prep-organize
2
2
 
3
- [中文](#中文) · [English](#english)
3
+ [English](./README.md) · [简体中文](./README.zh-CN.md)
4
4
 
5
- ## 中文
6
-
7
- ### 它做什么
8
-
9
- - 在 dsh web 对话输入框右侧加两个控件:「整理」分段按钮与「模板」下拉。
10
- - 「整理」主键直接整理,▾ 选「以某角色视角整理」;「模板」下拉按 group 分组,空组归「通用」。
11
- - 「整理」把草稿 + 会话 cwd 的顶层目录(文件名/大小/关键文本文件全文)+ 会话最近真人对话交给当前默认模型重写。
12
- - 成功直接替换草稿;失败草稿原值不动、按钮转失败态 4 秒(title 带原因)。
13
- - 「模板」点选即插入草稿:空草稿整段填入,非空草稿末尾空一行追加。
14
- - 默认列表是 85 条内置精选角色模板(scripts/gen-defaults.mjs 生成自包内 agents/ 角色库:22 个部门目录、306 个角色 .md)。
15
- - 那张表**只留在 host 半**:client 半不再打包它(生成表 640KB,曾让 `client.js` 涨到 711KB),改为首次打开「整理」/「模板」菜单或进设置卡时 `GET /_dsh/dir-prep/default-templates` 按需拉一发并进程内复用;未就绪时菜单里是「正在载入…」占位行,失败则显形为原因 + 重试按钮(不静默显示空列表)。用户已设置过自己的模板时一发都不发。
16
- - 设置页一张「提示词模板」卡承载逐条增删改、两步确认恢复默认、一键导入内置全部角色、按路径导入本地 .md 或目录、登记导入允许目录。
17
- - 模板与允许目录的读写走宿主 settings,零 LLM,也不注册任何模型工具。
18
-
19
- ### 安装
20
-
21
- 包发布在公共 npm(`registry.npmjs.org`),安装不需要凭据:
22
-
23
- ```sh
24
- dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
25
- ```
26
-
27
- - 宿主版本 `>= 0.2.0-rc.2`:写在 `peerDependencies`(0.1.7-rc 起宿主装插件时校验它,alpha.1 无此门)与 `engines.dsh`(同值、无人读);client 半 `dsh.client.platform = web`、`immediately`。
28
- - 发布形态为按包单仓,`repository.url` 为 git+https://github.com/JayYuen666/dsh-dir-prep-organize.git
29
- - 发布产物只有 `host.js`、`client.js`、`cordis.patch.yml`、`agents/`(package.json 的 `files`)。
30
- - 运行期依赖三枚,全在 `dependencies`:`@jayyuen66/dsh-plugin-shared`、`@deepseek-ai/schemastery`(宿主 fork,0.1.7 的 `.volatile()` 活引用只有它解析得出来)与 `@deepseek-ai/dsh-brand`(`0.2.0-rc.2`)。
31
- - 第三枚不是笔误:`host.ts` 的 `brandString` 是**值导入**,必须落 `dependencies`——`build-host.mjs` 的外部化名单只读 `dependencies`∪`peerDependencies`,放 `devDependencies` 就会被 rolldown 把官方函数体内联进 `host.js`(`test/build-host.test.ts` 同时钉「说明符在」与「函数体不在」)。
32
-
33
- ### 在 dsh 里启用
34
-
35
- - 装包即由包内 bundle patch(`dsh.bundle.patch` 指向 `./cordis.patch.yml`)注入 `- id: dir-prep-organize`(`name` 为包名)。
36
- - 卸载用 `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`。
37
- - host 半硬依赖 webServer 与 settings:缺 settings 时设置卡停用并 warn,「模板」下拉回落内置精选集,五个端点不受影响。
38
- - client 半注册槽 `conversation.input.right`(整理 id `dir-prep-organize` order 99、模板 id `dir-prep-organize-templates` order 100),另注册设置卡槽 `plugins.bundle.config`。
39
- - 卡槽 key = bundle 包名 `@jayyuen66/dsh-dir-prep-organize`:该槽按 bundle 包名 keyed(宿主派发 `entryKey: pkg.name`,真源是 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles`);写成裸条目 id 就不命中,卡片整张不渲染。
40
- - settings 命名空间与 `configForms.get()` 仍是裸条目 id `dir-prep-organize`,与上面的 slot key 不是一回事。
41
-
42
- ### 提供给模型的工具
43
-
44
- | 面 | 事实 |
45
- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
46
- | 模型工具注册 | 无。host 半只 `inject` webServer 与 settings,不碰宿主工具注册面 |
47
- | 整理调用 | 宿主 `llm.stream`:单条 user 文本消息(**request-only 输入**,不带 `id`/`source`,见 `host.ts` 上方那条注释的三条证据)+ `system` 规则段;模型取 `agentDefaultModel.currentSelection()` 的 provider/model/reasoningEffort,取不到即报「当前无可用模型选择」 |
48
- | 角色视角 | 可选 `roleText` 注入 system 的「参考角色」段,只借术语与措辞重写草稿,不代为执行角色的任务 |
49
- | 时限与上限 | 三枚都进 config,路由每次请求经 `limits` 取一次:`organizeTimeoutMs` 默认 120000 ms(volatile 引用,`.get()` 现读)、`maxSnippetBytes` 默认 262144(256 KiB)、`readConcurrency` 默认 8(后两位是普通值形态,不经 `.get()`);client 请求超时 = `organizeTimeoutMs` + 5000 ms(宿主值缺席按 120000 算,即 125000;另外三个端点的 fetch 用常量 `FETCH_TIMEOUT_MS` 125000 ms);POST body 上限是配置字段 `importBodyMaxBytes`,默认 8 MiB;目录/对话/角色正文一律不截断;流终态非 `stop`(含缺 finish 块)判失败且不写回 |
50
-
51
- ### 设置项
52
-
53
- | 字段 | 类型 | 默认 | 说明 |
54
- | ------------------- | ------------------------------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
- | `templates` | `{id,name,description,text,group,emoji}[]` | 未设置 | 全 string 字段,description/group/emoji 缺省空串;保存时 name 或 text 为空的条目被剔除,emoji 截到 12 字符,id 缺失或撞名确定性补 `tpl-<index>`;未设置时下拉回落内置 85 条精选(生成集留在 host 半、经 default-templates 端点按需下发,不再是 host 的 base)。⚠ 隐式注册下「未设置」到客户端就是**空表**(schemastery 对 array 字段把缺失值 cast 成 `[]`,不给默认并不产生 undefined),所以空表一律按未设置回落内置;只有「非空数组但逐项非法」才渲染空列表 |
56
- | `importAllowRoots` | `string[]` | `[]` | 导入端点的额外允许根,逐条登记目录;非字符串与纯空白项丢弃、去重;未登记 = 只放行会话 cwd 与内置角色库 |
57
- | `organizeTimeoutMs` | natural,`.volatile()` | `120000` | LLM 整理中止时限(毫秒),host 侧 `config.organizeTimeoutMs.get()` 每次请求现读。标了 volatile ⇒ 随宿主投影进本条目的表单快照,三枚里 client 半只读它一枚(`rawOrganizeTimeoutMsOf`),用来把 organize 的 fetch 超时定为「该值 + 5000 ms」。⚠ 卡片**没有**它的控件:`src/client-entry.ts` 只写 `templates` 与 `importAllowRoots`,改它得动 settings.yaml 或注册行的 `config:` |
58
- | `maxSnippetBytes` | natural(非 volatile) | `262144` | 单个关键文件摘要的字节上限,超出整份跳过(不喂半份摘要)并计 `skipped.tooLarge`;导入候选读取用同一枚。非 volatile ⇒ 不进表单快照,卡片自然也没有它的行;只能按部署值给(settings.yaml / 行 `config:`) |
59
- | `readConcurrency` | natural(非 volatile) | `8` | 关键文件摘要读取与目录导入(子目录 listDir、第三层清点、候选读取)的有界并发度;同上,无投影、无卡上控件 |
60
- | `importBodyMaxBytes` | natural(非 volatile) | `8388608` | organize / import 两条 POST 的 body 字节上限(内存防爆纵深防御,非功能截断:两条路由提交的是整理草稿与模板产物,不是大文件本体);超限即 413,guardBody 流式计量并在越界处早退,所以最坏常驻内存就是这一枚水位。同上,无投影、无卡上控件 |
61
- | 恢复默认 | — | — | unset `templates` 回落精选集、不动 `importAllowRoots`;两步确认,第二次点击须在 4 秒内 |
62
- | 存储位置 | — | — | settings 命名空间 `dir-prep-organize`(0.1.7 隐式注册:命名空间 = 本条目 id,投影进设置表单的是 host.ts `Config` 上标了 `.volatile()` 的 `templates`/`importAllowRoots`/`organizeTimeoutMs`,其中卡片只写前两枚;`maxSnippetBytes` 与 `readConcurrency` 是普通值形态),落在 `<dsh 数据目录>`(`$DSH_HOME`)的 settings.yaml |
63
-
64
- ### 对外接口
65
-
66
- | 路由 | 方法 | 入参 | 成功回执 |
67
- | ------------------------- | ---- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
68
- | `/_dsh/dir-prep/context` | GET | query `sessionId` | `ok/csrf/cwd/truncated/skipped/entries[{name,isDir,sizeBytes,snippet}]` |
69
- | `/_dsh/dir-prep/model` | GET | query `sessionId` | `ok/csrf/provider/model/reasoningEffort` |
70
- | `/_dsh/dir-prep/organize` | POST | body `prompt`/`sessionId`/`entriesSummary`/可选 `roleText`,头 `x-dir-prep-csrf` | `ok/content` |
71
- | `/_dsh/dir-prep/import` | POST | body `path`(精确空串 = 内置全量)/`sessionId`,不经 CSRF | `ok/count/truncated/skipped/entries` |
72
- | `/_dsh/dir-prep/default-templates` | GET | 无参数,不经 CSRF | `ok/templates[{id,name,description,text,group,emoji}]`(内置精选表原文下发) |
73
-
74
- | 情形 | 响应 |
75
- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
76
- | 路由与令牌 | 四条都是 webServer 精确路由(注册时 `kind: "exact"`);每条 handler 体的**第一条语句**是 `guardTrust(req, res, { servingNonLoopback })`(shared/lib/trust),非 trusted 即写一次 403 并 return,不再读 body;`csrf` 为 per-apply 随机令牌,两个 GET 下发、organize 回填 |
77
- | 信任判据的次序 | Host 权威 → `sec-fetch-site` 白名单(只放 same-origin/none/缺失)→ `origin` 与 Host 逐字比对;本包 handler 里自家那枚 `isCrossOrigin` 分支在闸门落地后不可达、已删(共享层 `guardBody` 的同形检查也被闸门挡在前面),拒跨域的是闸门,错误文本由它给 |
78
- | Host 权威不是本机可信地址 | 403 + `{ok:false,error:"untrusted host authority"}`;`servingNonLoopback` 取自 `webServer.host === "0.0.0.0"`,取不到即按只绑回环的保守档 |
79
- | `sec-fetch-site` 不在白名单、或 origin 对不上 | 403 + `{ok:false,error:"cross-origin request rejected"}`(`origin` 为 `null` 的沙箱页,以及缺 Host 却又带了 `origin` 的本地面,同落这一句) |
80
- | 方法不符 | 405 带 `Allow`,体是 JSON:`{ok:false,error:"GET only"}`(organize/import 为 `"POST only"`) |
81
- | CSRF 缺失或错 | 403 + `{ok:false,error:"invalid csrf token"}`(`guardBody` 那一条,仍在闸门之后) |
82
- | body 超 64 MiB | 413 + `{ok:false,error:"request body too large"}` |
83
- | 坏流或非法 JSON | 400 + `{ok:false,error}`(坏流 `"request body unreadable"`,非法 JSON 走字典文案) |
84
- | 业务失败 | 仍回 200 + `{ok:false,error}`;导入路径越界/非法段例外,回 403 与 400(见数据与隐私) |
85
-
86
- ### 数据与隐私
87
-
88
- | 面 | 事实 |
89
- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
- | 网络调用 | 只指向本进程的同源 `/_dsh/*`;不请求任何外部主机,也不读任何环境变量 |
91
- | 落盘 | 唯一落盘数据是 settings 里的 `templates` 与 `importAllowRoots` |
92
- | 一次整理发给模型的全部内容 | 草稿全文、会话 cwd 路径、顶层目录条目与关键文本文件全文、真人 user/assistant 文本(框架注入消息与 tool 结果被过滤)、可选角色正文 |
93
- | 摘要扩展名 | 只取 20 种代码/文档扩展名(ts/tsx/js/jsx/mjs/cjs/py/rs/go/java/rb/json/toml/md/sql/graphql/proto/css/scss/less);yaml/env 类不在白名单 |
94
- | 敏感文件名 | 文件名含 credential/secret/id_rsa/.pem/.p12/.pfx/keystore/.env/.key 者永不取正文 |
95
- | 单文件上限与并发 | 单文件超 `maxSnippetBytes`(默认 256 KiB)或大小未知即整份跳过(不喂半份摘要),读取按 `readConcurrency`(默认 8)有界并发;两位都是配置字段,也都不是卡上的控件 |
96
- | 计数与回显 | 超限/读失败/更深层未扫/非角色都计入 `skipped` 并回显,`truncated` 如实上报 |
97
- | 导入端点 | 只读:不调模型、不写盘。绝对路径默认拒绝,仅放行会话 cwd、包内 `agents/`、`importAllowRoots` 三类根之内,`.`/`..`/隐藏段(如 `.ssh`)一律拒,越界回 403 并回显解析后的路径 |
98
-
99
- ### 常见问题
100
-
101
- | 现象 | 处理 |
102
- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103
- | 点了「整理」草稿没变? | 失败不改草稿;按钮 4 秒失败态,title 写原因。常见为无会话 cwd(sessionId 缺失或会话不存在)、无模型选择、模型终态非 stop、`organizeTimeoutMs` 到点(默认 120 秒) |
104
- | 模型报上下文超限? | 目录/对话/角色正文都不截断,超限由模型报错、用户自行精简;载荷本身超 64 MiB 时端点回 413 |
105
- | 导入本地角色被拒? | 绝对路径默认拒绝,且设置卡没有会话上下文(POST 的 `sessionId` 为空串),路径须落在内置 `agents/` 或已登记目录内、且不含 `.`/`..`/隐藏段;越界回执会点名允许区并回显解析后的路径 |
106
- | 导入条数比预期少? | 看回执 `skipped` 四项:目录只扫顶层与一层子目录(第三层只计 `deeper`)、超 `maxSnippetBytes`(默认 256 KiB)计 `tooLarge`、frontmatter 前 20 行解析不出 name 计 `unnamed`、读失败计 `unreadable` |
107
- | 改模板不生效 / 语言不对? | 编辑先本地暂存,点「保存」后对新开的下拉生效;设置卡、输入框旁那两个 dock 按钮(文案与注册 label 都进了 `ui-messages.ts` 字典)、以及 host 回执都跟随官方 locale 插件的语言偏好(host 侧每请求现读,无需重启),而 agents/ 角色库与模板正文属用户数据、不做机翻 |
108
-
109
- ## English
110
-
111
- ### What it does
5
+ ## What it does
112
6
 
113
7
  - Adds two controls to the right of the dsh web chat input: a split "Organize" button and a "Template" dropdown.
114
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".
@@ -122,7 +16,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
122
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.
123
17
  - Templates and allowed directories are read and written through the host settings with zero LLM calls, and no model tool is registered.
124
18
 
125
- ### Install
19
+ ## Install
126
20
 
127
21
  The packages are published to the public npm registry (`registry.npmjs.org`), so installation needs no credentials:
128
22
 
@@ -130,13 +24,22 @@ The packages are published to the public npm registry (`registry.npmjs.org`), so
130
24
  dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
131
25
  ```
132
26
 
133
- - Host version `engines.dsh >= 0.2.0-rc.2`; the client half is `dsh.client.platform = web` with `immediately`.
134
- - The publishing form is one repository per package, `repository.url` is git+https://github.com/JayYuen666/dsh-dir-prep-organize.git
135
- - The published artifact ships only `host.js`, `client.js`, `cordis.patch.yml` and `agents/` (package.json `files`).
136
- - Runtime dependencies are three, all under `dependencies`: `@jayyuen66/dsh-plugin-shared`, `@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.0-rc.2`).
137
- - The third one is no typo: `brandString` in `host.ts` is a **value import**, and per ruling A it must sit in `dependencies` — the externalization list in `build-host.mjs` only reads `dependencies` ∪ `peerDependencies`, so a `devDependencies` entry lets rolldown inline the official function body into `host.js` (`test/build-host.test.ts` pins both "specifier present" and "function body absent").
138
-
139
- ### Enabling it in dsh
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-alpha.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-alpha.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-alpha.1`), `@deepseek-ai/cosmokit` (`1.8.6-alpha.1`, 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-alpha.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
140
43
 
141
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.
142
45
  - Removal goes through `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`.
@@ -145,7 +48,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
145
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.
146
49
  - The settings namespace and `configForms.get()` stay the bare entry id `dir-prep-organize` - not the same identifier as that slot key.
147
50
 
148
- ### Tools exposed to the model
51
+ ## Tools exposed to the model
149
52
 
150
53
  | Aspect | Fact |
151
54
  | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -154,20 +57,20 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
154
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 |
155
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 three endpoints fetch with the constant `FETCH_TIMEOUT_MS` of 125000 ms); the POST body cap is the config field `importBodyMaxBytes` at 8 MiB by default; directory/conversation/role text are never truncated; a finish reason other than `stop` (including a missing finish chunk) fails and never writes back |
156
59
 
157
- ### Settings
60
+ ## Settings
158
61
 
159
62
  | Field | Type | Default | Notes |
160
63
  | ------------------- | ------------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
161
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 |
162
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 |
163
- | `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". ⚠ 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:` |
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:` |
164
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:`) |
165
- | `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 |
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 |
166
69
  | `importBodyMaxBytes` | natural (non-volatile) | `8388608` | Byte cap on the bodies of the two POST routes, organize and import (depth-of-defense against a memory blow-up, not a functional truncation: those routes carry the organized draft and the template products, not the file payloads themselves); over the cap is 413, and `guardBody` meters the stream and returns early at the crossing, so the worst resident memory is exactly this watermark. Same as above: no projection, no card control |
167
70
  | Restore defaults | — | — | Unsets `templates` back to the curated set and leaves `importAllowRoots` untouched; two-step confirm, the second click must come within 4 seconds |
168
71
  | 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`) |
169
72
 
170
- ### Public interface
73
+ ## Public interface
171
74
 
172
75
  | Route | Method | Input | Success payload |
173
76
  | ------------------------- | ------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
@@ -181,15 +84,15 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
181
84
  | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
182
85
  | Routing and token | All four are exact-match webServer routes (`kind: "exact"`); the **first statement** of every handler body is `guardTrust(req, res, { servingNonLoopback })` from shared/lib/trust, which writes a single 403 and returns without reading the body; `csrf` is a per-apply random token, issued by the two GETs and verified on organize |
183
86
  | Order of the trust checks | Host authority → the `sec-fetch-site` allowlist (only same-origin/none/absent) → a verbatim `origin` vs Host comparison; the `isCrossOrigin` branch inside this package's handlers became unreachable once the gate landed and is deleted (the identical check inside the shared `guardBody` now sits behind the gate too), so the gate is what rejects cross-site traffic and supplies the sentence |
184
- | Host authority is not a trusted local address | 403 with `{ok:false,error:"untrusted host authority"}`; `servingNonLoopback` comes from `webServer.host === "0.0.0.0"`, and a service without that field keeps the conservative loopback-only setting |
87
+ | Host authority is not a trusted local address | 403 with `{ok:false,error:"untrusted host authority"}`; `servingNonLoopback` comes from `isNonLoopbackBindHost(webServer.host)` (shared/lib/trust) - the host takes any local interface address as `Config.host` and rejects the wildcard address at load, so comparing against `"0.0.0.0"` would be permanently false; a service that reports no bind address keeps the conservative loopback-only setting |
185
88
  | `sec-fetch-site` outside the allowlist, or origin mismatch | 403 with `{ok:false,error:"cross-origin request rejected"}` (opaque `origin: null` sandbox pages, and a local request that carries `origin` but no Host, land here too) |
186
89
  | Wrong method | 405 with `Allow` and a JSON body: `{ok:false,error:"GET only"}` (organize/import answer `"POST only"`) |
187
90
  | Missing or wrong CSRF | 403 with `{ok:false,error:"invalid csrf token"}` (the `guardBody` check, still behind the gate) |
188
- | Body over 64 MiB | 413 with `{ok:false,error:"request body too large"}` |
91
+ | Body over the configured cap (8 MiB by default) | 413 with `{ok:false,error:"request body too large"}` |
189
92
  | Broken stream or invalid JSON | 400 with `{ok:false,error}` (`"request body unreadable"` for a broken stream; invalid JSON uses the dictionary text) |
190
93
  | Business failure | Still 200 with `{ok:false,error}`; the import endpoint's out-of-bounds and malformed-path branches are the exception - 403 and 400 (see Data and privacy) |
191
94
 
192
- ### Data and privacy
95
+ ## Data and privacy
193
96
 
194
97
  | Aspect | Fact |
195
98
  | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -202,12 +105,12 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
202
105
  | Counters and echo | Too-large/unreadable/deeper-level/non-role cases are counted in `skipped`, shown in the UI, and reflected honestly by `truncated` |
203
106
  | 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 |
204
107
 
205
- ### FAQ
108
+ ## FAQ
206
109
 
207
110
  | Symptom | What happens |
208
111
  | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
209
112
  | 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) |
210
- | 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 64 MiB gets 413 from the endpoint instead |
113
+ | 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 |
211
114
  | 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 |
212
115
  | 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` |
213
116
  | 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 |
@@ -0,0 +1,114 @@
1
+ # @jayyuen66/dsh-dir-prep-organize
2
+
3
+ [English](./README.md) · [简体中文](./README.zh-CN.md)
4
+
5
+ ## 它做什么
6
+
7
+ - 在 dsh web 对话输入框右侧加两个控件:「整理」分段按钮与「模板」下拉。
8
+ - 「整理」主键直接整理,▾ 选「以某角色视角整理」;「模板」下拉按 group 分组,空组归「通用」。
9
+ - 「整理」把草稿 + 会话 cwd 的顶层目录(文件名/大小/关键文本文件全文)+ 会话最近真人对话交给当前默认模型重写。
10
+ - 成功直接替换草稿;失败草稿原值不动、按钮转失败态 4 秒(title 带原因)。
11
+ - 「模板」点选即插入草稿:空草稿整段填入,非空草稿末尾空一行追加。
12
+ - 默认列表是 85 条内置精选角色模板(scripts/gen-defaults.mjs 生成自包内 agents/ 角色库:22 个部门目录、306 个角色 .md)。
13
+ - 那张表**只留在 host 半**:client 半不再打包它(生成表 640KB,曾让 `client.js` 涨到 711KB),改为首次打开「整理」/「模板」菜单或进设置卡时 `GET /_dsh/dir-prep/default-templates` 按需拉一发并进程内复用;未就绪时菜单里是「正在载入…」占位行,失败则显形为原因 + 重试按钮(不静默显示空列表)。用户已设置过自己的模板时一发都不发。
14
+ - 设置页一张「提示词模板」卡承载逐条增删改、两步确认恢复默认、一键导入内置全部角色、按路径导入本地 .md 或目录、登记导入允许目录。
15
+ - 模板与允许目录的读写走宿主 settings,零 LLM,也不注册任何模型工具。
16
+
17
+ ## 安装
18
+
19
+ 包发布在公共 npm(`registry.npmjs.org`),安装不需要凭据:
20
+
21
+ ```sh
22
+ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
23
+ ```
24
+
25
+ - 宿主区间 `>= 0.2.0-rc.2`,同时写进 `peerDependencies` 与 `engines.dsh`。真正生效的只有 `peerDependencies`:自 `0.1.7-rc.1` 起宿主载入插件时会校验它并把不兼容的条目**停用**(`compatibility-preflight.ts` 的 `deny()`);`engines.dsh` 在该宿主版本上没有任何读者。
26
+ - `@deepseek-ai/dsh-*` 依赖仍精确钉在 `0.2.1-alpha.2`——那是本包构建并测过的宿主版本。区间是对**它能跑在哪些宿主上**的声明,钉版是对**它在哪个宿主版本上编译过**的事实;把两者混成一条断言,正是发布门禁现在把它们拆开分别验的原因。
27
+ - client 半 `dsh.client.platform = web`、`immediately`。
28
+ - 发布形态为按包单仓,`repository.url` 为 git+https://github.com/JayYuen666/dsh-dir-prep-organize.git ;问题反馈走同一仓库的 issue(`bugs`)。
29
+ - 要求 Node.js `>= 22.12`。本包是纯 ESM:用 `import { apply } from "@jayyuen66/dsh-dir-prep-organize"` 或 `require("@jayyuen66/dsh-dir-prep-organize")`。**没有默认导出**——`import pkg from …` 会报 `does not provide an export named 'default'`,请取具名导出。正是这个 Node 下限让 `require()` 能吃下这个 ESM 入口,所以 `engines.node` 要写明。
30
+ - TypeScript 声明以 `types/host.d.ts` 随包发出,同时接进 `types` 与 `.` 的 exports 条件。`Config` 那个 schema 值带了显式注解,所以产物里不会出现消费方解析不到的类型名。
31
+ - 发布产物只有 `host.js`、`client.js`、`templates.data.mjs`、`types/`、`cordis.patch.yml`、`agents/` 与 `THIRD_PARTY_NOTICES.md`(package.json 的 `files`);`LICENSE`、`README.md`、`package.json` 由 registry 客户端无条件附带。
32
+ - 内置精选模板表单独成一个产物,**首次用到时才载入**,不再随插件载入就进内存。它原先被打进 `host.js`,于是即便用户从不开「模板」下拉,也要替 85 条模板付内存——现在 `host.js` 只有原先的约十分之一,而浏览器那一侧本来就是按需拉的。
33
+ - `agents/` 并非本仓原创:它来自上游项目 [`agency-agents-zh`](https://github.com/jnMetaCode/agency-agents-zh)(MIT)。MIT 要求声明随每一份分发副本一起给出,故其版权与许可声明收录在 `THIRD_PARTY_NOTICES.md`。
34
+ - `dependencies` 里不放任何 `@deepseek-ai/*`,这不是风格偏好。本包的消费方是 dsh 插件,被装进 profile(`nodeLinker: hoisted`、`autoInstallPeers: false`),宿主包只要出现在 `dependencies`,pnpm 就会在那棵 profile 依赖树里把它落成**真实目录**,与宿主进程已经加载的那份并存。而 `@deepseek-ai/dsh-tools` 的 `TOOL_RUNTIME_SCHEDULER` 是普通 `Symbol`(不是 `Symbol.for`),符号身份按模块实例计算——宿主 `dsh-agent-loop` 拿自己那份的 Symbol 去读由副本挂载出来的 `ToolRuntime`,得到 `undefined`,于是**每一次原生工具调用都抛** `Cannot read properties of undefined (reading 'prepare')`,整个 profile 的工具一起失效。本包的构建、类型检查与测试在这之前全部照绿,所以判据由 `test/publish-manifest.test.ts` 落在 manifest 面。
35
+ - 产物 `host.js` 里以**值**导入的两枚宿主包是非 optional 的 `peerDependencies`:`@deepseek-ai/schemastery`(宿主 fork,0.1.7 的 `.volatile()` 活引用只有它解析得出来)与 `@deepseek-ai/dsh-brand`(`0.2.1-alpha.2`)。运行期由宿主在场提供,而 profile 不装 peer,所以不产生副本。`build-host.mjs` 的外部化名单读 `dependencies` ∪ `peerDependencies`,两张表都读,所以 `host.js` 里的裸说明符一字未变——这正是 `brandString` 那处裁定的落点:落 peer 保住「说明符在」,只写 `devDependencies` 就会被 rolldown 把官方函数体内联进来(`test/build-host.test.ts` 同时钉「说明符在」与「函数体不在」)。
36
+ - 凡被**声明产物**点名的宿主包都写进 `peerDependencies`,其中只在那里现身的都判为 optional:`@deepseek-ai/cordis`(`4.0.5-alpha.1`)、`@deepseek-ai/cosmokit`(`1.8.6-alpha.1`,只经 schemastery 的 `Dict` 现身)以及 `@deepseek-ai/dsh-agent-default-model`、`-client-locale`、`-client-ui-conversation`、`-client-ui-renderer`、`-client-ui-settings`、`-client-ui-slots`、`-fs`、`-llm`、`-session`(全为 `0.2.1-alpha.2`)。声明它们不是礼节:pnpm 严格布局下,`types/host.d.ts` 里一枚没有任何 manifest 表认领的裸说明符就是解析不到——消费方那侧的声明入口根本过不了类型检查,而本仓自己的 typecheck 照绿,因为我们两张表都有它。`test/publish-manifest.test.ts` 因此按 `types/**/*.d.ts` 现扫这份名单,而不是照这段话抄,两边就此漂不开。`@deepseek-ai/dsh` 是唯一谁也没 import 的 peer:它指宿主本身,也就是 `engines.dsh` 用文字说的那件事。
37
+ - 每枚 peer 都在 `devDependencies` 里以同一枚精确版本再写一份,本仓自己的 typecheck、build 与测试靠它解析。其余 `@deepseek-ai/*` 在源码里是 type-only,在声明产物里也不留说明符,所以只留在 `devDependencies`。
38
+ - `dependencies` 剩下的确实是本包自己的运行期代码:`@jayyuen66/dsh-plugin-shared`。
39
+
40
+ ## 在 dsh 里启用
41
+
42
+ - 装包即由包内 bundle patch(`dsh.bundle.patch` 指向 `./cordis.patch.yml`)注入 `- id: dir-prep-organize`(`name` 为包名)。
43
+ - 卸载用 `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`。
44
+ - host 半硬依赖 webServer 与 settings:缺 settings 时设置卡停用并 warn,「模板」下拉回落内置精选集,五个端点不受影响。
45
+ - client 半注册槽 `conversation.input.right`(整理 id `dir-prep-organize` order 99、模板 id `dir-prep-organize-templates` order 100),另注册设置卡槽 `plugins.bundle.config`。
46
+ - 卡槽 key = bundle 包名 `@jayyuen66/dsh-dir-prep-organize`:该槽按 bundle 包名 keyed(宿主派发 `entryKey: pkg.name`,真源是 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles`);写成裸条目 id 就不命中,卡片整张不渲染。
47
+ - settings 命名空间与 `configForms.get()` 仍是裸条目 id `dir-prep-organize`,与上面的 slot key 不是一回事。
48
+
49
+ ## 提供给模型的工具
50
+
51
+ | 面 | 事实 |
52
+ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
+ | 模型工具注册 | 无。host 半只 `inject` webServer 与 settings,不碰宿主工具注册面 |
54
+ | 整理调用 | 宿主 `llm.stream`:单条 user 文本消息(**request-only 输入**,不带 `id`/`source`,见 `host.ts` 上方那条注释的三条证据)+ `system` 规则段;模型取 `agentDefaultModel.currentSelection()` 的 provider/model/reasoningEffort,取不到即报「当前无可用模型选择」 |
55
+ | 角色视角 | 可选 `roleText` 注入 system 的「参考角色」段,只借术语与措辞重写草稿,不代为执行角色的任务 |
56
+ | 时限与上限 | 三枚都进 config,路由每次请求经 `limits` 取一次:`organizeTimeoutMs` 默认 120000 ms(volatile 引用,`.get()` 现读)、`maxSnippetBytes` 默认 262144(256 KiB)、`readConcurrency` 默认 8(后两位是普通值形态,不经 `.get()`);client 请求超时 = `organizeTimeoutMs` + 5000 ms(宿主值缺席按 120000 算,即 125000;另外三个端点的 fetch 用常量 `FETCH_TIMEOUT_MS` 125000 ms);POST body 上限是配置字段 `importBodyMaxBytes`,默认 8 MiB;目录/对话/角色正文一律不截断;流终态非 `stop`(含缺 finish 块)判失败且不写回 |
57
+
58
+ ## 设置项
59
+
60
+ | 字段 | 类型 | 默认 | 说明 |
61
+ | ------------------- | ------------------------------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62
+ | `templates` | `{id,name,description,text,group,emoji}[]` | 未设置 | 全 string 字段,description/group/emoji 缺省空串;保存时 name 或 text 为空的条目被剔除,emoji 截到 12 字符,id 缺失或撞名确定性补 `tpl-<index>`;未设置时下拉回落内置 85 条精选(生成集留在 host 半、经 default-templates 端点按需下发,不再是 host 的 base)。⚠ 隐式注册下「未设置」到客户端就是**空表**(schemastery 对 array 字段把缺失值 cast 成 `[]`,不给默认并不产生 undefined),所以空表一律按未设置回落内置;只有「非空数组但逐项非法」才渲染空列表 |
63
+ | `importAllowRoots` | `string[]` | `[]` | 导入端点的额外允许根,逐条登记目录;非字符串与纯空白项丢弃、去重;未登记 = 只放行会话 cwd 与内置角色库 |
64
+ | `organizeTimeoutMs` | natural,`.volatile()` | `120000` | LLM 整理中止时限(毫秒),host 侧 `config.organizeTimeoutMs.get()` 每次请求现读。标了 volatile ⇒ 随宿主投影进本条目的表单快照,三枚里 client 半只读它一枚(`rawOrganizeTimeoutMsOf`),用来把 organize 的 fetch 超时定为「该值 + 5000 ms」。⚠ 使用前夹进 `[1, 2147483647]`:超过 2^31-1 时 Node 的 `setTimeout` 会打一条 `TimeoutOverflowWarning` 然后**静默改用 1 ms**,「把超时调大」于是变成「立刻失败」。⚠ 卡片**没有**它的控件:`src/client-entry.ts` 只写 `templates` 与 `importAllowRoots`,改它得动 settings.yaml 或注册行的 `config:` |
65
+ | `maxSnippetBytes` | natural(非 volatile) | `262144` | 单个关键文件摘要的字节上限,超出整份跳过(不喂半份摘要)并计 `skipped.tooLarge`;导入候选读取用同一枚。非 volatile ⇒ 不进表单快照,卡片自然也没有它的行;只能按部署值给(settings.yaml / 行 `config:`) |
66
+ | `readConcurrency` | natural(非 volatile) | `8` | 关键文件摘要读取与目录导入(子目录 listDir、第三层清点、候选读取)的有界并发度;同上,无投影、无卡上控件。⚠ 使用前夹进 `[1, 64]`:`0` 或负数会让有界 map 无限自递归直到宿主进程被 OOM killer 杀掉,而配成极大值则直接废掉这个字段存在的理由(那道 fd 上界) |
67
+ | `importBodyMaxBytes` | natural(非 volatile) | `8388608` | organize / import 两条 POST 的 body 字节上限(内存防爆纵深防御,非功能截断:两条路由提交的是整理草稿与模板产物,不是大文件本体);超限即 413,guardBody 流式计量并在越界处早退,所以最坏常驻内存就是这一枚水位。同上,无投影、无卡上控件 |
68
+ | 恢复默认 | — | — | unset `templates` 回落精选集、不动 `importAllowRoots`;两步确认,第二次点击须在 4 秒内 |
69
+ | 存储位置 | — | — | settings 命名空间 `dir-prep-organize`(0.1.7 隐式注册:命名空间 = 本条目 id,投影进设置表单的是 host.ts `Config` 上标了 `.volatile()` 的 `templates`/`importAllowRoots`/`organizeTimeoutMs`,其中卡片只写前两枚;`maxSnippetBytes` 与 `readConcurrency` 是普通值形态),落在 `<dsh 数据目录>`(`$DSH_HOME`)的 settings.yaml |
70
+
71
+ ## 对外接口
72
+
73
+ | 路由 | 方法 | 入参 | 成功回执 |
74
+ | ------------------------- | ---- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
75
+ | `/_dsh/dir-prep/context` | GET | query `sessionId` | `ok/csrf/cwd/truncated/skipped/entries[{name,isDir,sizeBytes,snippet}]` |
76
+ | `/_dsh/dir-prep/model` | GET | query `sessionId` | `ok/csrf/provider/model/reasoningEffort` |
77
+ | `/_dsh/dir-prep/organize` | POST | body `prompt`/`sessionId`/`entriesSummary`/可选 `roleText`,头 `x-dir-prep-csrf` | `ok/content` |
78
+ | `/_dsh/dir-prep/import` | POST | body `path`(精确空串 = 内置全量)/`sessionId`,不经 CSRF | `ok/count/truncated/skipped/entries` |
79
+ | `/_dsh/dir-prep/default-templates` | GET | 无参数,不经 CSRF | `ok/templates[{id,name,description,text,group,emoji}]`(内置精选表原文下发) |
80
+
81
+ | 情形 | 响应 |
82
+ | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83
+ | 路由与令牌 | 四条都是 webServer 精确路由(注册时 `kind: "exact"`);每条 handler 体的**第一条语句**是 `guardTrust(req, res, { servingNonLoopback })`(shared/lib/trust),非 trusted 即写一次 403 并 return,不再读 body;`csrf` 为 per-apply 随机令牌,两个 GET 下发、organize 回填 |
84
+ | 信任判据的次序 | Host 权威 → `sec-fetch-site` 白名单(只放 same-origin/none/缺失)→ `origin` 与 Host 逐字比对;本包 handler 里自家那枚 `isCrossOrigin` 分支在闸门落地后不可达、已删(共享层 `guardBody` 的同形检查也被闸门挡在前面),拒跨域的是闸门,错误文本由它给 |
85
+ | Host 权威不是本机可信地址 | 403 + `{ok:false,error:"untrusted host authority"}`;`servingNonLoopback` 取自 `isNonLoopbackBindHost(webServer.host)`(shared/lib/trust)——宿主的 `Config.host` 收任意本机接口地址、通配地址在载入即拒,所以跟 `"0.0.0.0"` 比字面量恒为 false;服务不报绑定地址时按只绑回环的保守档 |
86
+ | `sec-fetch-site` 不在白名单、或 origin 对不上 | 403 + `{ok:false,error:"cross-origin request rejected"}`(`origin` 为 `null` 的沙箱页,以及缺 Host 却又带了 `origin` 的本地面,同落这一句) |
87
+ | 方法不符 | 405 带 `Allow`,体是 JSON:`{ok:false,error:"GET only"}`(organize/import 为 `"POST only"`) |
88
+ | CSRF 缺失或错 | 403 + `{ok:false,error:"invalid csrf token"}`(`guardBody` 那一条,仍在闸门之后) |
89
+ | body 超配置上限(默认 8 MiB) | 413 + `{ok:false,error:"request body too large"}` |
90
+ | 坏流或非法 JSON | 400 + `{ok:false,error}`(坏流 `"request body unreadable"`,非法 JSON 走字典文案) |
91
+ | 业务失败 | 仍回 200 + `{ok:false,error}`;导入路径越界/非法段例外,回 403 与 400(见数据与隐私) |
92
+
93
+ ## 数据与隐私
94
+
95
+ | 面 | 事实 |
96
+ | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97
+ | 网络调用 | 只指向本进程的同源 `/_dsh/*`;不请求任何外部主机,也不读任何环境变量 |
98
+ | 落盘 | 唯一落盘数据是 settings 里的 `templates` 与 `importAllowRoots` |
99
+ | 一次整理发给模型的全部内容 | 草稿全文、会话 cwd 路径、顶层目录条目与关键文本文件全文、真人 user/assistant 文本(框架注入消息与 tool 结果被过滤)、可选角色正文 |
100
+ | 摘要扩展名 | 只取 20 种代码/文档扩展名(ts/tsx/js/jsx/mjs/cjs/py/rs/go/java/rb/json/toml/md/sql/graphql/proto/css/scss/less);yaml/env 类不在白名单 |
101
+ | 敏感文件名 | 文件名含 credential/secret/id_rsa/.pem/.p12/.pfx/keystore/.env/.key 者永不取正文 |
102
+ | 单文件上限与并发 | 单文件超 `maxSnippetBytes`(默认 256 KiB)或大小未知即整份跳过(不喂半份摘要),读取按 `readConcurrency`(默认 8)有界并发;两位都是配置字段,也都不是卡上的控件 |
103
+ | 计数与回显 | 超限/读失败/更深层未扫/非角色都计入 `skipped` 并回显,`truncated` 如实上报 |
104
+ | 导入端点 | 只读:不调模型、不写盘。绝对路径默认拒绝,仅放行会话 cwd、包内 `agents/`、`importAllowRoots` 三类根之内,`.`/`..`/隐藏段(如 `.ssh`)一律拒,越界回 403 并回显解析后的路径 |
105
+
106
+ ## 常见问题
107
+
108
+ | 现象 | 处理 |
109
+ | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
110
+ | 点了「整理」草稿没变? | 失败不改草稿;按钮 4 秒失败态,title 写原因。常见为无会话 cwd(sessionId 缺失或会话不存在)、无模型选择、模型终态非 stop、`organizeTimeoutMs` 到点(默认 120 秒) |
111
+ | 模型报上下文超限? | 目录/对话/角色正文都不截断,超限由模型报错、用户自行精简;载荷本身超配置上限(默认 8 MiB)时端点回 413 |
112
+ | 导入本地角色被拒? | 绝对路径默认拒绝,且设置卡没有会话上下文(POST 的 `sessionId` 为空串),路径须落在内置 `agents/` 或已登记目录内、且不含 `.`/`..`/隐藏段;越界回执会点名允许区并回显解析后的路径 |
113
+ | 导入条数比预期少? | 看回执 `skipped` 四项:目录只扫顶层与一层子目录(第三层只计 `deeper`)、超 `maxSnippetBytes`(默认 256 KiB)计 `tooLarge`、frontmatter 前 20 行解析不出 name 计 `unnamed`、读失败计 `unreadable` |
114
+ | 改模板不生效 / 语言不对? | 编辑先本地暂存,点「保存」后对新开的下拉生效;设置卡、输入框旁那两个 dock 按钮(文案与注册 label 都进了 `ui-messages.ts` 字典)、以及 host 回执都跟随官方 locale 插件的语言偏好(host 侧每请求现读,无需重启),而 agents/ 角色库与模板正文属用户数据、不做机翻 |
@@ -0,0 +1,52 @@
1
+ # Third-party notices
2
+
3
+ 本包自身代码以 MIT 发布,见 [`LICENSE`](./LICENSE)。但发布物里并非全部内容都是本仓原创:
4
+ 内置角色库 `agents/` 来自下面的第三方项目,且占发布体积的绝大部分。MIT 要求「上述版权声明与
5
+ 本许可声明须包含在软件的所有副本或实质性部分中」,因此那一段必须随包发出——本文件就是它的
6
+ 载体。
7
+
8
+ ## 内置角色库 `agents/`
9
+
10
+ - 上游项目:`agency-agents-zh`
11
+ - 上游仓库:https://github.com/jnMetaCode/agency-agents-zh
12
+ - 上游 npm 包:https://www.npmjs.com/package/agency-agents-zh
13
+ - 上游许可:MIT
14
+ - 本仓的改动:整体移入本插件的 `agents/` 目录;未改动角色正文。上游的 `integrations/`
15
+ 目录(面向 Claude Code / Cursor / Gemini CLI 等外部工具的转换件与安装脚本)对 dsh 插件
16
+ 无作用,也未被本仓使用,故未随本包分发。
17
+
18
+ 上游许可原文照录如下。
19
+
20
+ ```
21
+ MIT License
22
+
23
+ Copyright (c) 2025 Michael Sitarzewski (original English version)
24
+ Copyright (c) 2026 jnMetaCode (Chinese translation and localization)
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining a copy
27
+ of this software and associated documentation files (the "Software"), to deal
28
+ in the Software without restriction, including without limitation the rights
29
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30
+ copies of the Software, and to permit persons to whom the Software is
31
+ furnished to do so, subject to the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be included in all
34
+ copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42
+ SOFTWARE.
43
+ ```
44
+
45
+ > 版权年份是许可条款要求随附的内容,不是无用的时间标记,故按上游原文保留。
46
+
47
+ ## 运行期依赖
48
+
49
+ 运行期依赖的许可由各自包随包分发,本包不再重复其文本:`@deepseek-ai/cosmokit`、
50
+ `@deepseek-ai/dsh-brand`、`@deepseek-ai/schemastery`、`@jayyuen66/dsh-plugin-shared`。
51
+ 其中 `@deepseek-ai/cosmokit` 仅出现在本包发布的类型声明里——schemastery 的 `Schema` 类型
52
+ 把 `Dict` 取自 cosmokit,声明文件点名它就必须让它可解析,故列为运行期依赖而非开发依赖。