@jayyuen66/dsh-dir-prep-organize 0.1.15 → 0.1.16

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/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@
4
4
  [语义化版本](https://semver.org/lang/zh-CN/)。最新版本在最上。这里的偏离是刻意的:版本标题
5
5
  不写发布日期,各版发布时间以 npm registry 为准(`npm view <包名> time` 取得到)。
6
6
 
7
+ ## 0.1.16
8
+
9
+ 宿主基线切到 `dsh 0.2.3-alpha.2`(Node `^24.22.3 || >=26.13.1`),shared 经 catalog 抬到 `^0.2.13`。设置卡随 shared v3 视觉层更新;客户端注册空输入框 placeholder;宿主侧改用会话的活动工作目录(live cwd 优先、非法活值回落),并移除 `@deepseek-ai/dsh-working-directory` 依赖。角色库、默认配置与路由不变。
10
+
7
11
  ## 0.1.15
8
12
 
9
13
  宿主基线抬到 `0.2.2-rc.5`:devDependencies 全族精确钉 rc.5,`engines.dsh` 与 dsh 家族 peer 同一条窗口;dependabot 配置注释与集成台架的契约证据行(deepseek-harness @ dsh-v0.2.2-rc.5)同步。Typert 远端方法的程序化标记收编 shared `./lib/remote-marker`(与 session-rescue / ocr-review 的副本逐字同构);`test/build-host.test.ts` 的 shared 子路径外置清单补 `lib/instance-lock` 与 `lib/remote-marker`。`src/remote.ts` 的 `RemoteHost` / `isMounter` 与 `src/client-entry.ts` 的 `within` 竞速骨架收编 shared(`./lib/typert-client` / `./lib/with-timeout`)。shared 经 catalog 抬到 `^0.2.12`——收编的三个子路径随 shared 0.2.12 发布,`pnpm-lock.yaml` 经 `pnpm install --lockfile-only` 重解到 registry 现量。
package/README.md CHANGED
@@ -11,8 +11,8 @@
11
11
  <a href="https://www.npmjs.com/package/@jayyuen66/dsh-dir-prep-organize"><img src="https://img.shields.io/npm/d18m/@jayyuen66/dsh-dir-prep-organize?style=flat-square" alt="npm downloads (18 months)" /></a>
12
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
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%3D24.9-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
- <img src="https://img.shields.io/badge/dsh-%5E0.2.2--rc.5-658EFF?style=flat-square" alt="dsh" />
14
+ <img src="https://img.shields.io/badge/node-%5E24.22.3%7C%7C%3E%3D26.13.1-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.3--alpha.2-658EFF?style=flat-square" alt="dsh" />
16
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
17
  </p>
18
18
 
@@ -54,7 +54,7 @@
54
54
  - Adds **two controls** to the right of the web chat input: a split "Polish" button (main key + caret) and a "Template" dropdown.
55
55
  - The main key polishes directly; the caret key offers "polish in a role's style".
56
56
  - The dropdown groups entries by their `group` field; an entry with an empty group lands in "General".
57
- - **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 model selected for that conversation (falling back to the host default), then replaces the draft with the rewrite. The result is written back only while the session, draft revision and input phase are unchanged.
57
+ - **Polish** sends the draft, the top level of the session's active working directory (the live `workingDirectory` value first, `header.cwd` only when it is absent — every path below derives from that one rule; file names, sizes, and the full text of key text files), and the session's **real** user/assistant turns to the model selected for that conversation (falling back to the host default), then replaces the draft with the rewrite. The result is written back only while the session, draft revision and input phase are unchanged.
58
58
  - On failure the draft is **never** touched: the button shows an error state for 4 seconds with the reason in its tooltip.
59
59
  - **Templates** insert text at the caret through the input box's insert face: quoted blocks and attachments stay intact, and a stale insertion is refused instead of replacing the draft. Both controls are disabled while the input box is submitting.
60
60
  - 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.
@@ -74,9 +74,9 @@ Remove with `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`.
74
74
 
75
75
  - The bundle patch inserts `- id: dsh-plugin-shared` (`@jayyuen66/dsh-plugin-shared`). **Keep that component enabled**: disabling it removes the settings card's shared component supply, and the next page load fails with `missed the module table`.
76
76
 
77
- - **Requires Node.js `>= 24.9`.** 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.
78
- - **Requires host `dsh` on the `0.2.2-rc.5` host line or later.** The requirement the host actually reads is `engines.dsh` (`^0.2.2-rc.5`), and it **decides alone**: `evaluatePluginCompatibility` returns on the `engines.dsh` branch before it ever looks at `peerDependencies`. Derived per host version from the loading gate's own predicate (`app-boot`'s `satisfies`, with `includePrerelease: true`): `0.2.0-rc.2`, `0.2.1-rc.5`, `0.2.2-alpha.3`, `0.2.2-rc.1` and `0.2.2-rc.2` through `0.2.2-rc.4` are **refused**, `0.2.2-rc.5`, `0.2.2` and `0.2.3` 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`. The support window rolls: this package is verified against every released host version inside the window at publish time and re-verified once the window moves, so the version number in this bullet is not a standing promise.
79
- - **The `@deepseek-ai/dsh-*` development pins are at `0.2.2-rc.5`** - the host line this package is built and tested against. `engines.dsh` and the optional peer ranges carry the separately checked support window (`^0.2.2-rc.5`); the pin is a fact about which host version it was *compiled* against, not a restatement of that window. Mixing the two is why the publish gate checks them separately.
77
+ - **Requires Node.js `^24.22.3 || >=26.13.1`.** 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.
78
+ - **Requires host `dsh` on the `0.2.3-alpha.2` host line or later.** The requirement the host actually reads is `engines.dsh` (`^0.2.3-alpha.2`), and it **decides alone**: `evaluatePluginCompatibility` returns on the `engines.dsh` branch before it ever looks at `peerDependencies`. Derived per host version from the loading gate's own predicate (`app-boot`'s `satisfies`, with `includePrerelease: true`): `0.2.3-alpha.2`, later releases below `0.3.0` and prereleases on the `0.2.3` tuple pass; `0.2.2` and earlier, prereleases of later tuples such as `0.2.4-rc.1`, and `0.3.0` or later are refused. A refused host needs the explicit risk grant `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`. The support window rolls: this package is verified against every released host version inside the window at publish time and re-verified once the window moves, so the version number in this bullet is not a standing promise.
79
+ - **The `@deepseek-ai/dsh-*` development pins are at `0.2.3-alpha.2`** - the host line this package is built and tested against. `engines.dsh` and the optional peer ranges carry the separately checked support window (`^0.2.3-alpha.2`); the pin is a fact about which host version it was *compiled* against, not a restatement of that window. Mixing the two is why the publish gate checks them separately.
80
80
  - **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.
81
81
  - **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".
82
82
  - **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.
@@ -150,7 +150,7 @@ Namespace `dir-prep-organize` equals the settings entry id. Fields projected int
150
150
  | Field | Type | Default | Card control | Notes |
151
151
  |---|---|---|---|---|
152
152
  | `templates` | `{id,name,description,text,group,emoji}[]` | unset | **yes** | The user's own templates. Unset falls back to the 85 built-in entries |
153
- | `importAllowRoots` | `string[]` | `[]` | **yes** | Extra allowed roots for the import endpoint. Non-strings and whitespace-only items are dropped, **relative paths and `~` are dropped too** (the host resolves those against its own process cwd, which would register a root whose target nobody can read off the card), and items are deduplicated after trailing separators are normalized — `/a` and `/a/` are one tree, not two rows. With nothing registered, only the session cwd and the built-in role library are allowed |
153
+ | `importAllowRoots` | `string[]` | `[]` | **yes** | Extra allowed roots for the import endpoint. Non-strings and whitespace-only items are dropped, **relative paths and `~` are dropped too** (the host resolves those against its own process cwd, which would register a root whose target nobody can read off the card), and items are deduplicated after trailing separators are normalized — `/a` and `/a/` are one tree, not two rows. With nothing registered, only the session's active working directory and the built-in role library are allowed |
154
154
  | `organizeTimeoutMs` | natural, volatile | `120000` | **no** | The LLM abort deadline in ms. Values are truncated and clamped to `[1, 2147483647]`; non-finite values fall back to `120000`. `0` passes the schema and clamps to 1 ms, so it really does mean an immediate timeout. 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:` |
155
155
  | `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 |
156
156
  | `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 |
@@ -179,12 +179,12 @@ Official Typert Remote namespace **`dirPrepOrganize`**, registered through an in
179
179
  |---|---|
180
180
  | Network | No outbound requests of its own: the data plane is the host gateway's RPC channel. No environment variable is read |
181
181
  | On disk | The only data written is `templates` and `importAllowRoots`, in the host settings file |
182
- | 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 |
182
+ | What one polish call sends | The full draft, the session's active working directory 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 |
183
183
  | 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 |
184
184
  | 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 |
185
185
  | Caps and concurrency | A single file over `maxSnippetBytes`, or with unknown size, is skipped whole - never half-summarized. Collected snippets share a 2 MiB budget; once it is exhausted the rest are skipped whole and counted in `skipped.tooLarge`. Reads run with `readConcurrency` |
186
186
  | Counters | Too-large / unreadable / deeper-level / non-role cases are counted in `skipped`, shown in the UI, and reflected honestly by `truncated` |
187
- | 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 |
187
+ | Import endpoint | **Read-only**: no model call, no disk writes. Absolute paths are refused by default; only paths inside the session's active working directory, 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 |
188
188
 
189
189
  ## <img src="https://api.iconify.design/lucide/triangle-alert.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Known boundaries
190
190
 
@@ -201,7 +201,7 @@ Registered honestly, one entry per class.
201
201
 
202
202
  | Symptom | What happens |
203
203
  |---|---|
204
- | 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`, the `organizeTimeoutMs` deadline, or the draft/selection changing while the request was in flight (the result is discarded) |
204
+ | 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 active working directory (`sessionId` missing, session unknown, and neither a live value nor `header.cwd` to fall back to), no model selection, a finish reason other than `stop`, the `organizeTimeoutMs` deadline, or the draft/selection changing while the request was in flight (the result is discarded) |
205
205
  | 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 |
206
206
  | 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 |
207
207
  | Fewer entries imported than expected | Read the four `skipped` counters: `deeper` (third level, counted only), `tooLarge` (over `maxSnippetBytes`), `unnamed` (no name in the first 200 frontmatter lines), `unreadable` (read failure) |
package/README.zh-CN.md CHANGED
@@ -11,8 +11,8 @@
11
11
  <a href="https://www.npmjs.com/package/@jayyuen66/dsh-dir-prep-organize"><img src="https://img.shields.io/npm/d18m/@jayyuen66/dsh-dir-prep-organize?style=flat-square" alt="npm downloads (18 months)" /></a>
12
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
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%3D24.9-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
- <img src="https://img.shields.io/badge/dsh-%5E0.2.2--rc.5-658EFF?style=flat-square" alt="dsh" />
14
+ <img src="https://img.shields.io/badge/node-%5E24.22.3%7C%7C%3E%3D26.13.1-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.3--alpha.2-658EFF?style=flat-square" alt="dsh" />
16
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
17
  </p>
18
18
 
@@ -54,7 +54,7 @@
54
54
  - 在 web 输入框右侧加**两个控件**:一个可拆分的「润色」按钮(主键 + ▾),一个「模板」下拉。
55
55
  - 主键直接润色;▾ 键提供「以某个角色的风格润色」。
56
56
  - 下拉按条目的 `group` 字段分组,`group` 为空的条目落在「通用」里。
57
- - **润色**会把草稿、会话 cwd 的顶层(文件名、大小、关键文本文件的全文)以及会话里**真实的** user/assistant 轮次交给当前会话选定的模型(取不到时回落宿主默认模型),然后用重写结果替换草稿。只有会话、草稿版本与输入阶段都没变时才写回。
57
+ - **润色**会把草稿、会话活动工作目录的顶层(活值 `workingDirectory` 优先,缺席才回落 `header.cwd`——下文每条路径都按这一条推导;文件名、大小、关键文本文件的全文)以及会话里**真实的** user/assistant 轮次交给当前会话选定的模型(取不到时回落宿主默认模型),然后用重写结果替换草稿。只有会话、草稿版本与输入阶段都没变时才写回。
58
58
  - 失败时草稿**绝不**被改动:按钮进入错误态若干秒,原因写在其 tooltip 里。
59
59
  - **模板**经输入框的插入接口写到光标处:引用块与附件保持原样;插入凭据过期时宿主拒绝插入,而不是重建整份草稿。输入框处于提交期时两个控件禁用。
60
60
  - 内置集是 **85 条精选角色模板**,由 `scripts/gen-defaults.mjs` 从本包的 `agents/` 角色库生成——那是从上游项目移入的几百份角色 `.md`,分布在二十多个部门目录下。对用户有意义的是那 85 条;角色库的份数不在这里钉死,因为上游一刷新它就变。
@@ -74,9 +74,9 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
74
74
 
75
75
  - 组合包补丁会插入 `- id: dsh-plugin-shared`(`@jayyuen66/dsh-plugin-shared`)。**这个组件必须保持开启**:停用后设置卡会失去 shared 组件供应,下一次页面加载会报 `missed the module table`。
76
76
 
77
- - **要求 Node.js `>= 24.9`。** 本包是纯 ESM。用**具名**导出(`import { apply } from "@jayyuen66/dsh-dir-prep-organize"`);**没有 default 导出**,所以 `import pkg from …` 会报 `does not provide an export named 'default'`。正是这个 Node 下限让 ESM 入口的 `require()` 形式可用,所以声明了 `engines.node`。
78
- - **要求宿主 `dsh` 在 `0.2.2-rc.5` 这条宿主线上或更晚。** 宿主真正读的是 `engines.dsh`(`^0.2.2-rc.5`),而且它**单独决定**:`evaluatePluginCompatibility` 在 `engines.dsh` 那一支就返回了,根本走不到读 `peerDependencies` 的那段。按宿主装载门的判定谓词(`app-boot` 的 `satisfies`,带 `includePrerelease: true`)逐版本推得:`0.2.0-rc.2`、`0.2.1-rc.5`、`0.2.2-alpha.3`、`0.2.2-rc.1` 与 `0.2.2-rc.2` 到 `0.2.2-rc.4` **被拒**,`0.2.2-rc.5`、`0.2.2` 与 `0.2.3` 通过,`0.3.0` 被拒。被拒的宿主需要走显式担责的授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时把窗口内的每个已发布宿主版本逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
79
- - **`@deepseek-ai/dsh-*` 的开发依赖钉在 `0.2.2-rc.5`**——本包编译与测试所对着的那条宿主线。`engines.dsh` 与 optional peer 范围承载单独判读的支持窗口(`^0.2.2-rc.5`);钉版是关于「它是对着哪个宿主版本**编译**的」的事实,不是那个窗口的复述。把两者混为一谈,正是发布门禁分开检查它们的原因。
77
+ - **要求 Node.js `^24.22.3 || >=26.13.1`。** 本包是纯 ESM。用**具名**导出(`import { apply } from "@jayyuen66/dsh-dir-prep-organize"`);**没有 default 导出**,所以 `import pkg from …` 会报 `does not provide an export named 'default'`。正是这个 Node 下限让 ESM 入口的 `require()` 形式可用,所以声明了 `engines.node`。
78
+ - **要求宿主 `dsh` 在 `0.2.3-alpha.2` 这条宿主线上或更晚。** 宿主真正读的是 `engines.dsh`(`^0.2.3-alpha.2`),而且它**单独决定**:`evaluatePluginCompatibility` 在 `engines.dsh` 那一支就返回了,根本走不到读 `peerDependencies` 的那段。按宿主装载门的判定谓词(`app-boot` 的 `satisfies`,带 `includePrerelease: true`):`0.2.3-alpha.2`、其后低于 `0.3.0` 的正式版与 `0.2.3` 元组内的预发布通过;`0.2.2` 及更早、更高元组的预发布(如 `0.2.4-rc.1`)与 `0.3.0` 及以后都被拒。被拒的宿主需要走显式担责的授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时把窗口内的每个已发布宿主版本逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
79
+ - **`@deepseek-ai/dsh-*` 的开发依赖钉在 `0.2.3-alpha.2`**——本包编译与测试所对着的那条宿主线。`engines.dsh` 与 optional peer 范围承载单独判读的支持窗口(`^0.2.3-alpha.2`);钉版是关于「它是对着哪个宿主版本**编译**的」的事实,不是那个窗口的复述。把两者混为一谈,正是发布门禁分开检查它们的原因。
80
80
  - **`dependencies` 里不放任何 `@deepseek-ai/*`,这是约定**(`test/publish-manifest.test.ts` 钉着)。消费方 profile 用 `nodeLinker: hoisted` 且 `autoInstallPeers: false` 安装,于是写在 `dependencies` 里的宿主包会被落成**真实目录**,与运行中的宿主已加载的那份并存。`@deepseek-ai/dsh-tools` 的工具运行期调度键是普通 `Symbol`(不是 `Symbol.for`),符号身份按模块实例算:宿主从 profile 副本上读那个键拿到 `undefined`,于是**每一次原生工具调用都抛**——而本包的构建、类型检查、覆盖率检查在此之前全部照绿。
81
81
  - **`host.js` 按值导入的那两枚宿主包是必需 peer**:`@deepseek-ai/schemastery`(宿主 fork——只有它能把 `.volatile()` 字段解析成活引用)与 `@deepseek-ai/dsh-brand`。`build-host.mjs` 外部化 `dependencies` **与** `peerDependencies`,所以裸说明符留在产物里;只写 `devDependencies` 会让打包器把官方函数体内联进去。`test/build-host.test.ts` 同时钉「说明符在」与「函数体不在」。
82
82
  - **声明里点到的每一枚宿主包都落在 `peerDependencies`**,凡是只能从那里到达的都是 *optional*(`@deepseek-ai/cordis`、`cosmokit`,以及 `dsh-agent-default-model` / client-ui / `fs` / `llm` / `session` 那一族)。声明它们不是仪式:pnpm 严格布局下,`types/host.d.ts` 里一枚没有被任何 manifest 表点名的裸说明符在消费方侧解析不到,而本仓自己的类型检查照样绿。那条清单由测试从 `types/**/*.d.ts` 现量读,不从这段文字读,所以两边不会漂移。
@@ -150,7 +150,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
150
150
  | 字段 | 类型 | 默认值 | 卡上有控件 | 说明 |
151
151
  |---|---|---|---|---|
152
152
  | `templates` | `{id,name,description,text,group,emoji}[]` | 未设置 | **有** | 用户自己的模板。未设置时回落到 85 条内置 |
153
- | `importAllowRoots` | `string[]` | `[]` | **有** | 导入端点的额外允许根,逐个目录登记;非字符串与纯空白项丢弃,**相对路径与 `~` 同样丢弃**(host 按它自己的进程 cwd 解析它们,等于登记一条界面上看不出指向哪里的根),末尾分隔符归一后再去重——`/a` 与 `/a/` 是同一棵树,不该在卡上摆两行。一个都没登记时只允许会话 cwd 与内置角色库 |
153
+ | `importAllowRoots` | `string[]` | `[]` | **有** | 导入端点的额外允许根,逐个目录登记;非字符串与纯空白项丢弃,**相对路径与 `~` 同样丢弃**(host 按它自己的进程 cwd 解析它们,等于登记一条界面上看不出指向哪里的根),末尾分隔符归一后再去重——`/a` 与 `/a/` 是同一棵树,不该在卡上摆两行。一个都没登记时只允许会话活动工作目录与内置角色库 |
154
154
  | `organizeTimeoutMs` | natural,volatile | `120000` | **无** | LLM 中止时限(毫秒)。取值先取整再夹到 `[1, 2147483647]`;非有限数回落到 `120000`。`0` 能过 schema,夹完是 1 ms,所以它确实表示"立刻超时"。超过 2^31-1 时 Node 的 `setTimeout` 会打 `TimeoutOverflowWarning` 并静默用 **1 ms**,于是"调大超时"变成"立刻失败"。卡上没有控件,改它只能经 `settings.yaml` 或该行的 `config:` |
155
155
  | `maxSnippetBytes` | natural,非 volatile | `262144` | **无** | 关键文件摘要的单文件上限;超过、或大小未知的文件整份跳过并计入 `skipped.tooLarge`。导入候选用同一个上限。非 volatile 意味着不进表单快照,所以也没有卡上的行——纯部署值 |
156
156
  | `readConcurrency` | natural,非 volatile | `8` | **无** | 摘要与目录导入的有界读并发。夹在 `[1, 64]`:`0` 或负数会让那套有界 map 自我递归直到宿主被 OOM killer 杀掉,而过大的值直接废掉这个字段存在的意义(fd 上限) |
@@ -179,12 +179,12 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
179
179
  |---|---|
180
180
  | 网络 | 没有自己的出站请求:数据那一栏走宿主网关的 RPC 通道。不读任何环境变量 |
181
181
  | 写到磁盘 | 唯一写盘的是宿主设置文件里的 `templates` 与 `importAllowRoots` |
182
- | 一次润色发出去什么 | 完整草稿、会话 cwd 路径、顶层目录条目**连同关键文本文件的全文**、真实的 user/assistant 轮次(框架注入的消息与工具结果被滤掉),以及可选的角色正文 |
182
+ | 一次润色发出去什么 | 完整草稿、会话活动工作目录路径、顶层目录条目**连同关键文本文件的全文**、真实的 user/assistant 轮次(框架注入的消息与工具结果被滤掉),以及可选的角色正文 |
183
183
  | 哪些文件会取摘要 | 只有 20 种代码/文档扩展名(ts/tsx/js/jsx/mjs/cjs/py/rs/go/java/rb/json/toml/md/sql/graphql/proto/css/scss/less)。`yaml` / `env` **不在**白名单里 |
184
184
  | 敏感文件名 | 名字在**分隔符边界**上命中 `credentials` / `secret(s)` / `id_rsa` / `pem` / `p12` / `pfx` / `keystore` / `env` / `key(s)` / `token(s)` / `auth` / `passwd` / `password` / `account(s)` 的文件,永不取摘要。边界是刻意的:朴素子串匹配会误杀 `monkey.js` 与 `AUTHORS.md`,而漏匹配会把凭据全文发给第三方模型 |
185
185
  | 上限与并发 | 单个文件超过 `maxSnippetBytes`、或大小未知,整份跳过——绝不半份摘要。收集到的摘要共享 2 MiB 总量预算;用完之后其余整份跳过并计入 `skipped.tooLarge`。读按 `readConcurrency` 跑 |
186
186
  | 计数器 | 过大 / 读不出 / 更深层 / 非角色这几类计入 `skipped`,在 UI 里显示,并由 `truncated` 如实反映 |
187
- | 导入端点 | **只读**:不调模型、不写盘。绝对路径默认拒绝;只有会话 cwd、本包的 `agents/` 与 `importAllowRoots` 之内通过。`.` / `..` / 隐藏段(如 `.ssh`)一律拒绝,越界路径回 403 并回显解析后的路径 |
187
+ | 导入端点 | **只读**:不调模型、不写盘。绝对路径默认拒绝;只有会话活动工作目录、本包的 `agents/` 与 `importAllowRoots` 之内通过。`.` / `..` / 隐藏段(如 `.ssh`)一律拒绝,越界路径回 403 并回显解析后的路径 |
188
188
 
189
189
  ## <img src="https://api.iconify.design/lucide/triangle-alert.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 已知边界
190
190
 
@@ -201,7 +201,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
201
201
 
202
202
  | 症状 | 怎么回事 |
203
203
  |---|---|
204
- | 按了「润色」什么都没变 | 失败从不碰草稿;按钮进入错误态若干秒,原因在 tooltip 里。常见成因:没有会话 cwd(`sessionId` 缺失或会话未知)、没有模型选择、finish reason 不是 `stop`、撞上 `organizeTimeoutMs` 时限,或请求途中草稿/模型选择变了(结果被丢弃) |
204
+ | 按了「润色」什么都没变 | 失败从不碰草稿;按钮进入错误态若干秒,原因在 tooltip 里。常见成因:没有可用的活动工作目录(`sessionId` 缺失、会话未知,且活值与 `header.cwd` 都取不到)、没有模型选择、finish reason 不是 `stop`、撞上 `organizeTimeoutMs` 时限,或请求途中草稿/模型选择变了(结果被丢弃) |
205
205
  | 模型报上下文溢出 | 这是设计如此:输入刻意不截断,模型报错就是反馈。载荷超过端点 body 上限则得到 413 |
206
206
  | 导入本地角色被拒 | 绝对路径默认拒绝,而卡片没有会话上下文。路径必须在内置 `agents/` 或某个已登记目录之内,且不含 `.` / `..` / 隐藏段 |
207
207
  | 导入的条目比预期少 | 看四个 `skipped` 计数器:`deeper`(第三层,只计数)、`tooLarge`(超过 `maxSnippetBytes`)、`unnamed`(前 200 行 frontmatter 里没有名字)、`unreadable`(读失败) |
package/client.js CHANGED
@@ -5,10 +5,10 @@ window.__ModuleLoader__.load({
5
5
  'use strict';
6
6
  const module = { exports: {} };
7
7
  let exports = module.exports;
8
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@deepseek-ai/dsh-client-ui-primitives"),t=require("react"),n=require("@jayyuen66/dsh-plugin-shared/client"),r=require("zod");function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}new TextEncoder,new TextDecoder;function a(e,t){if(t<1||Number.isNaN(t))return``;let n=0,r=0;for(let i of e){if(r>=t)break;n+=i.length,r+=1}return e.slice(0,n)}function o(e,t,n){if(e!==``&&!n.has(e))return e;let r=`tpl-${t}`;for(;n.has(r);)r=`${r}-${t}`;return r}function s(e,t){let n=new Set(e.map(({id:e})=>e)),r=[...e];for(let{id:e,...i}of t){let t=e.trim();if(t===``)t=o(``,r.length,n);else if(n.has(t))for(t=`${t}-i`;n.has(t);)t=`${t}i`;n.add(t),r.push({...i,id:t})}return r}function c(e){return typeof e==`string`?e.trim():``}function l(e,t,n){let r;if(i(e)){let{id:i,name:s,description:l,text:u,group:d,emoji:f}=e,p=c(s),m=c(u);if(p!==``&&m!==``){let e=o(c(i),t,n);n.add(e),r={id:e,name:p,description:c(l),text:m,group:c(d),emoji:a(c(f),12)}}}return r}function u(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let[r,i]of e.entries()){let e=l(i,r,t);e!==void 0&&n.push(e)}return n}const d=String.fromCodePoint(92),f=/^[A-Za-z]:$/u,p=/[/\\]+$/u;function m(e){let t=f.test(e.slice(0,2))&&(e[2]===`/`||e[2]===d);return e.startsWith(`/`)||t||e.startsWith(d+d)}function h(e){let t=e.replace(p,``);return t.length===0||f.test(t)?e:t}function g(e){let t=[];if(Array.isArray(e))for(let n of e){let e=typeof n==`string`?n.trim():``,r=h(e);e.length>0&&m(r)&&!t.includes(r)&&t.push(r)}return t}const _=0x7fffffff;function v(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function y(e){let t=e.organizeTimeoutMs;return v(t)?Math.min(Math.max(Math.trunc(t),1),_):void 0}function b(e){let t=v(e)?e:12e4;return Math.trunc(Math.min(Math.max(Math.min(t,0x7fffec77)+5e3,1),_))}const x={zh:{rolesSection:`角色库`,rolesCount:`{count} 条`,rolesHint:`输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。`,statusReadOnly:`设置源不可写:编辑已禁用;下拉仍按当前列表生效。`,statusNotReady:`设置源未就绪:显示当前生效列表,就绪后可编辑。`,addTemplate:`+ 新增模板`,saveTitleDirty:`写入模板列表与导入允许目录(模板生效于新拉开的菜单)`,saveTitleClean:`无未保存修改`,saving:`保存中…`,save:`保存`,revert:`撤销`,resetTitle:`恢复默认?`,resetDefault:`恢复默认`,resetConfirmDescription:`将丢弃模板列表的全部自定义并写回内置默认:立即写盘、不可撤销(撤销按钮只回滚未保存的草稿)。已登记的导入允许目录不受影响。`,resetConfirmAcknowledge:`我知道这会立即写盘且不可撤销`,resetConfirmCancel:`取消`,resetConfirmClose:`关闭`,resetConfirmAction:`确认恢复默认`,footHint:`说明:编辑/新增/删除先在本地暂存,点「保存」一次写入(模板与导入允许目录同理);清空名称或正文的条目保存时会被剔除(删除请用行内「删除」);恢复默认只回滚模板列表。`,saveFailed:`保存失败:`,newTemplateName:`新模板 {index}`,persistUnconfirmed:`{action}结果不可确认:设置源未就绪(宿主未回读成功)`,persistRejected:`{action}未生效:宿主拒绝了本次写入(当前 revision {revision})`,rowAriaEmoji:`模板 {index} 视觉标记`,rowEmojiTitle:`可选视觉标记(emoji 或短文本),下拉菜单显示在名称前`,rowPlaceholderName:`菜单显示名`,rowAriaName:`模板 {index} 名称`,rowPlaceholderGroup:`分组`,rowAriaGroup:`模板 {index} 分组`,rowGroupTitle:`下拉按此分组展示;留空归入「通用」`,rowDeleteTitle:`删除此模板`,rowDelete:`删除`,rowPlaceholderDescription:`一句话介绍(下拉悬停时显示;如:威胁建模与 OWASP 代码审计)`,rowAriaDescription:`模板 {index} 一句话介绍`,rowPlaceholderText:`模板正文(点选后插入输入框,随你的消息一起发给模型)`,rowAriaText:`模板 {index} 正文`,importFailedUnknown:`导入失败(未知错误)`,importEmpty:`目录下没有符合条件的角色 .md(需含 name 的 frontmatter)`,importAllDone:`已从内置角色库导入全部 {count} 条{skips},编辑后点「保存」生效`,importFromDone:`已从 {path} 导入 {count} 条{skips},编辑后点「保存」生效`,importTruncated:`(回执标记本次导入有内容被上限截断)`,importPlaceholder:`留空 = 导入内置全部角色;或填 .md / 目录路径(须在允许根内)`,importAriaPath:`角色导入路径`,importBtnTitle:`留空 = 一键导入内置全部角色;填路径 = 导入该 .md 或目录下的角色(路径须在允许根内)`,importing:`导入中…`,importRoles:`导入角色`,importErrorPrefix:`导入失败:`,importHint:`导入说明:留空导入内置角色库全部(agents/);填路径时只放行「会话 cwd」「内置角色库 agents/」与下方「导入允许目录」之内的路径——绝对路径默认拒绝,越界会直接报「导入路径越界」并回显解析后的路径。本卡没有会话上下文,故只能填内置库或已登记目录里的路径。目录扫描顶层 + 一层子目录 .md(跳过隐藏项),文件须含 name 的 frontmatter,正文将提炼为模板正文。`,skipDeeper:`{count} 个更深层 .md 未扫描(导入只扫两层)`,skipTooLarge:`{count} 个文件超字节上限被跳过`,skipUnreadable:`{count} 个文件读取失败`,skipUnnamed:`{count} 个非角色文件(frontmatter 无 name)`,skipEscaped:`{count} 个文件的真实目标在允许根之外(符号链接),已按安全策略排除`,skipSummary:`({list})`,skipSeparator:`,`,rootsHeading:`导入允许目录(importAllowRoots)`,rootsAriaRow:`导入允许目录 {index}`,rootsRowTitle:`该目录(含其子目录)内的角色 .md 可经「导入角色」读取`,rootsRemoveTitle:`移除此允许目录`,rootsRemove:`移除`,rootsAddPlaceholder:`新增一个允许导入的目录绝对路径`,rootsAddAria:`新增导入允许目录`,rootsAddTitle:`加入待保存的允许目录列表`,rootsAdd:`登记目录`,rootsHint:`绝对路径默认拒绝:只有「当前会话 cwd」「插件内置角色库 agents/」与本列表登记的目录之内可导入。设置页没有会话上下文,卡上填的路径必须落在内置库或本列表内。改完点底部「保存」生效。`,dockOrganizeEntry:`润色`,dockTemplatesEntry:`模板`,organizeIdle:`润色`,organizeLoading:`润色中`,organizeFailedShort:`失败`,organizeIdleTitle:`结合当前目录润色输入框内容(主键直接润色;▾ 可选角色风格)`,organizeFailedTitle:`润色失败:{message}`,organizeErrContextFailed:`目录上下文读取失败:{message}`,organizeErrModelFailed:`读取模型失败:{message}`,organizeErrEmpty:`输入框为空,无内容可润色`,organizeErrTimeout:`润色请求超时:宿主没有在时限内回报结果`,organizeErrUnknownReason:`未知错误`,organizeErrUnknown:`润色失败(未知错误)`,organizeCaretAria:`选择润色的角色风格`,organizeCaretTitle:`按某个角色的风格润色(角色来自下方模板库)`,organizeMainAria:`润色输入框内容`,organizeDirectItem:`直接润色(默认,不带角色)`,organizeNoTemplates:`无模板可选作角色风格`,organizeRoleItem:`以「{name}」的风格润色`,organizeWriteBackUnavailable:`输入框动作不可用,无法写回`,organizeWriteBackStale:`输入框内容已变化,润色结果未写回`,organizeBusyTitle:`输入框正在提交,暂不能润色`,templatesIdleTitle:`选择一条模板插入光标处(按分组展示)`,templatesBrokenTitle:`输入框动作不可用,无法插入`,templatesBusyTitle:`输入框正在提交,暂不能插入模板`,templatesGroupCommon:`通用`,templatesAria:`插入模板`,templatesEmptyHint:`无模板:在设置页「角色库」中添加或恢复默认`,builtinLoading:`正在载入内置角色模板…`,builtinFailed:`内置模板加载失败:{message}`,builtinRetry:`重试`},en:{rolesSection:`Role library`,rolesCount:`{count} items`,rolesHint:`The input-box "Template" dropdown and the "Polish" ▾ role menu share this one list; an empty list falls back to the built-in curated role set (generated from this plugin's agents/ role library). Leave the path empty and press "Import roles" to import the whole built-in library; an explicit path is allowed within "session cwd + built-in role library + the import allowed directories below". Press "Save" after editing — it survives restarts.`,statusReadOnly:`Settings source is read-only: editing is disabled; the dropdown still uses the current list.`,statusNotReady:`Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.`,addTemplate:`+ Add template`,saveTitleDirty:`Write the template list and the import allowed directories (templates take effect in newly opened menus)`,saveTitleClean:`No unsaved changes`,saving:`Saving…`,save:`Save`,revert:`Revert`,resetTitle:`Restore defaults?`,resetDefault:`Restore defaults`,resetConfirmDescription:`Discards every customization of the template list and writes the built-in defaults back: immediate, irreversible (Revert only rolls back unsaved drafts). Registered import directories are untouched.`,resetConfirmAcknowledge:`I understand this writes immediately and cannot be undone`,resetConfirmCancel:`Cancel`,resetConfirmClose:`Close`,resetConfirmAction:`Restore defaults`,footHint:`Note: edits, additions and deletions are staged locally first and written in one go when you press "Save" (same for templates and import directories); entries whose name or body is empty are dropped on save (use the inline "Delete" instead); "Restore defaults" only rolls back the template list.`,saveFailed:`Save failed: `,newTemplateName:`New template {index}`,persistUnconfirmed:`{action} cannot be confirmed: the settings source is not ready (host read-back failed)`,persistRejected:`{action} did not take effect: the host rejected this write (current revision {revision})`,rowAriaEmoji:`Visual mark of template {index}`,rowEmojiTitle:`Optional visual mark (emoji or short text), shown before the name in the dropdown`,rowPlaceholderName:`Menu display name`,rowAriaName:`Name of template {index}`,rowPlaceholderGroup:`Group`,rowAriaGroup:`Group of template {index}`,rowGroupTitle:`The dropdown groups entries by this value; leave empty to fall into "General"`,rowDeleteTitle:`Delete this template`,rowDelete:`Delete`,rowPlaceholderDescription:`One-line intro (shown on dropdown hover; e.g. threat modelling and OWASP code auditing)`,rowAriaDescription:`One-line intro of template {index}`,rowPlaceholderText:`Template body (inserted into the input box and sent to the model with your message)`,rowAriaText:`Body of template {index}`,importFailedUnknown:`Import failed (unknown error)`,importEmpty:`No qualifying role .md in that directory (frontmatter must contain name)`,importAllDone:`Imported all {count} entries from the built-in role library{skips}; press "Save" after editing`,importFromDone:`Imported {count} entries from {path}{skips}; press "Save" after editing`,importTruncated:` (the reply flagged some content as truncated by a limit)`,importPlaceholder:`Empty = import every built-in role; or a .md / directory path (must be inside an allowed root)`,importAriaPath:`Role import path`,importBtnTitle:`Empty imports the whole built-in role library in one click; a path imports that .md or the roles in that directory (must be inside an allowed root)`,importing:`Importing…`,importRoles:`Import roles`,importErrorPrefix:`Import failed: `,importHint:`Import notes: an empty path imports the whole built-in role library (agents/); an explicit path is only allowed inside "session cwd", "built-in role library agents/" and the "import allowed directories" below — absolute paths are refused by default, and anything out of bounds reports "import path out of bounds" with the resolved path echoed back. This card has no session context, so explicit paths must live in the built-in library or a registered directory. Directory scans cover the top level plus one level of sub-directory .md files (hidden entries skipped), each file needs a frontmatter name, and its body is condensed into the template text.`,skipDeeper:`{count} deeper .md files were not scanned (imports cover two levels)`,skipTooLarge:`{count} files were skipped for exceeding the byte limit`,skipUnreadable:`{count} files could not be read`,skipUnnamed:`{count} non-role files (no name in frontmatter)`,skipEscaped:`{count} files whose real target lies outside the allowed roots (symlinks) were excluded by policy`,skipSummary:` ({list})`,skipSeparator:`, `,rootsHeading:`Import allowed directories (importAllowRoots)`,rootsAriaRow:`Import allowed directory {index}`,rootsRowTitle:`Role .md files inside this directory (and its subdirectories) can be read by "Import roles"`,rootsRemoveTitle:`Remove this allowed directory`,rootsRemove:`Remove`,rootsAddPlaceholder:`Absolute path of a directory newly allowed for imports`,rootsAddAria:`Add an import allowed directory`,rootsAddTitle:`Add it to the pending allowed-directory list`,rootsAdd:`Register directory`,rootsHint:`Absolute paths are refused by default: imports only succeed inside "the current session cwd", "the plugin's built-in role library agents/" and the directories registered below. The settings page has no session context, so a path typed here must fall inside the built-in library or this list. Press "Save" at the bottom to apply.`,dockOrganizeEntry:`Polish`,dockTemplatesEntry:`Templates`,organizeIdle:`Polish`,organizeLoading:`Polishing`,organizeFailedShort:`Failed`,organizeIdleTitle:`Polish the input-box content against the current directory (main key polishes directly; ▾ picks a role style)`,organizeFailedTitle:`Polish failed: {message}`,organizeErrContextFailed:`Failed to read the directory context: {message}`,organizeErrModelFailed:`Failed to read the model: {message}`,organizeErrEmpty:`The input box is empty; nothing to polish`,organizeErrTimeout:`Polish request timed out: the host did not reply in time`,organizeErrUnknownReason:`unknown error`,organizeErrUnknown:`Polish failed (unknown error)`,organizeCaretAria:`Choose a role style to polish with`,organizeCaretTitle:`Polish in a role's style (roles come from the template library below)`,organizeMainAria:`Polish the input-box content`,organizeDirectItem:`Polish directly (default, no role)`,organizeNoTemplates:`No templates available as a role style`,organizeRoleItem:`Polish in the style of "{name}"`,organizeWriteBackUnavailable:`Input-box actions unavailable; cannot write back`,organizeWriteBackStale:`The input box changed; the polished text was not applied`,organizeBusyTitle:`The input box is submitting; cannot polish right now`,templatesIdleTitle:`Pick a template to insert at the caret (shown grouped)`,templatesBrokenTitle:`Input-box actions unavailable; cannot insert`,templatesBusyTitle:`The input box is submitting; cannot insert a template`,templatesGroupCommon:`General`,templatesAria:`Insert a template`,templatesEmptyHint:`No templates: add or restore defaults under "Role library" in the settings page`,builtinLoading:`Loading built-in role templates…`,builtinFailed:`Failed to load built-in templates: {message}`,builtinRetry:`Retry`}};async function S(e,t,n){let{promise:r,reject:i}=Promise.withResolvers(),a=setTimeout(()=>{i(n())},t);try{return await Promise.race([e,r])}finally{clearTimeout(a)}}function C(e){return e!==void 0&&typeof e.setDraft==`function`}function w(e){return e!==void 0&&typeof e.captureInsertion==`function`&&typeof e.insertText==`function`}function T(e,n){let r=(0,t.useRef)(e),i=(0,t.useRef)(void 0);return(0,t.useEffect)(()=>{r.current=e;let t=i.current;t!==void 0&&(t.sessionId!==e.sessionId||t.actions!==e.actions||e.phase!==`plain`)&&(t.invalidated=!0)},[e]),(0,t.useEffect)(()=>()=>{let e=i.current;e!==void 0&&(e.invalidated=!0,i.current=void 0)},[]),{begin:()=>{let e={sessionId:r.current.sessionId,draftRev:r.current.draftRev,actions:r.current.actions,invalidated:!1};return i.current=e,e},finish:e=>{i.current===e&&(i.current=void 0)},commit:(e,t)=>{let i=r.current,{actions:a}=i;if(!C(a))throw Error(n.unavailable);if(t.sessionId!==i.sessionId||i.phase!==`plain`)throw Error(n.stale);let o=i.draftRev;if(w(a)&&(o=a.captureInsertion().draftRev),t.invalidated||o!==t.draftRev)throw Error(n.stale);a.setDraft(e)}}}const E=e=>i(e)&&typeof e.$mount==`function`,D=`dirPrepOrganize`,O=`remote.${D}`,k=`@jayyuen66/dsh-dir-prep-organize`;function A(e,t){let n=e.safeParse(t);if(!n.success)throw TypeError(r.z.prettifyError(n.error));return n.data}const ee=`session request requires a string sessionId`,te=r.z.object({sessionId:r.z.string({error:ee})},{error:ee}),j=`organize request requires string sessionId, prompt and entriesSummary`,ne=r.z.object({sessionId:r.z.string({error:j}),prompt:r.z.string({error:j}),entriesSummary:r.z.string({error:j}),roleText:r.z.string({error:`organize request roleText must be a string when present`}).optional()},{error:j}),M=`import request requires string path and sessionId`,re=r.z.object({path:r.z.string({error:M}),sessionId:r.z.string({error:M})},{error:M}),ie={mode:`strict`,typeSymbol:`${k}#session-request`,create:()=>({parse(e){return A(te,e)}})},ae=[{id:`${k}#${D}/defaults`,service:D,namespace:D,method:`defaults`,invocation:{kind:`direct`},parameters:[],result:{mode:`src-json`}},{id:`${k}#${D}/context`,service:D,namespace:D,method:`context`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:ie}],result:{mode:`src-json`}},{id:`${k}#${D}/model`,service:D,namespace:D,method:`model`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:ie}],result:{mode:`src-json`}},{id:`${k}#${D}/organize`,service:D,namespace:D,method:`organize`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${k}#organize-request`,create:()=>({parse(e){let t=A(ne,e);return t.roleText===void 0?{sessionId:t.sessionId,prompt:t.prompt,entriesSummary:t.entriesSummary}:{...t,roleText:t.roleText}}})}}],result:{mode:`src-json`}},{id:`${k}#${D}/importTemplates`,service:D,namespace:D,method:`importTemplates`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${k}#import-request`,create:()=>({parse(e){return A(re,e)}})}}],result:{mode:`src-json`}}],oe=e=>(0,n.isRecord)(e)&&typeof e.defaults==`function`&&typeof e.context==`function`&&typeof e.model==`function`&&typeof e.organize==`function`&&typeof e.importTemplates==`function`,se=e=>{if(!(0,n.isRecord)(e)||typeof e.ok!=`boolean`)throw TypeError(`Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok`);if(!e.ok){let{error:t}=e;throw!(0,n.isRecord)(t)||typeof t.code!=`string`||typeof t.message!=`string`?TypeError(`Typert Remote 应答的 error 分支缺 code/message`):Error(`${t.code}: ${t.message}`)}if(!(`value`in e))throw TypeError(`Typert Remote 应答的 ok 分支缺 value 字段`);return e.value};function ce(e,t){let n,r=async()=>{n??=t.$mount({package:k,descriptors:ae});try{await n}catch(e){throw n=void 0,e}let r=e.get?.(O,!1);if(!oe(r))throw Error(`${O} 未提供:宿主网关没有挂上这枚命名空间`);return r},i=async e=>{let t=await r();return se(await e(t))};return{defaults:async()=>i(e=>e.defaults()),context:async e=>i(t=>t.context({sessionId:e})),model:async e=>i(t=>t.model({sessionId:e})),organize:async e=>i(t=>t.organize(e)),importTemplates:async e=>i(t=>t.importTemplates(e))}}function le(e){let t;try{t=e.get?.(`remote`,!1)}catch{t=void 0}return E(t)?ce(e,t):void 0}const N=`dir-prep-organize`,P=125e3,F=`dpi-item-empty`,I=`dpic-rowhead`,L=`dpic-importpath`,R=`conversation.input.right`;function ue(e){let{name:t,isDir:r,sizeBytes:i,snippet:a}=(0,n.isRecord)(e)?e:{};return{name:typeof t==`string`?t:``,isDir:r===!0,sizeBytes:typeof i==`number`?i:0,...typeof a==`string`?{snippet:a}:{}}}function z(e,t){let n=e[t];return typeof n==`string`?n:void 0}function B(e,t){return e===void 0?{}:{[t]:e}}function de(e){return[[`skipDeeper`,e.deeper],[`skipTooLarge`,e.tooLarge],[`skipUnreadable`,e.unreadable],[`skipUnnamed`,e.unnamed],[`skipEscaped`,e.escaped]]}function fe(e){let t=(0,n.isRecord)(e)?e:{},{ok:r,truncated:i,entries:a}=t,o=Array.isArray(a)?a.map(e=>ue(e)):void 0;return{ok:r===!0,...B(z(t,`error`),`error`),...B(z(t,`cwd`),`cwd`),...i===!0?{truncated:!0}:{},...o===void 0?{}:{entries:o}}}function pe(e){let t=(0,n.isRecord)(e)?e:{};return{ok:t.ok===!0,...B(z(t,`error`),`error`),...B(z(t,`provider`),`provider`),...B(z(t,`model`),`model`),...B(z(t,`reasoningEffort`),`reasoningEffort`)}}function me(e){let t=(0,n.isRecord)(e)?e:{};return{ok:t.ok===!0,...B(z(t,`error`),`error`),...B(z(t,`content`),`content`)}}function V(e){return typeof e==`number`&&e>0?e:0}function he(e){return{tooLarge:V(e.tooLarge),unreadable:V(e.unreadable),deeper:V(e.deeper),unnamed:V(e.unnamed),escaped:V(e.escaped)}}function ge(e,t){if(t===void 0)return``;let n=[];for(let[r,i]of de(t))i>0&&n.push(e(r,{count:i}));return n.length===0?``:e(`skipSummary`,{list:n.join(e(`skipSeparator`))})}function _e(e){let{ok:t,error:r,count:i,truncated:a,skipped:o,entries:s}=(0,n.isRecord)(e)?e:{},c=Array.isArray(s)?u(s):void 0;return{ok:t===!0,...typeof r==`string`?{error:r}:{},...typeof i==`number`?{count:i}:{},...a===!0?{truncated:!0}:{},...(0,n.isRecord)(o)?{skipped:he(o)}:{},...c===void 0?{}:{entries:c}}}function ve(e){let t=e.entries??[],n=[`当前目录: ${e.cwd??`(未提供)`}`],r=t.filter(e=>!e.isDir),i=t.filter(e=>e.isDir);n.push(`文件 ${r.length} 个, 目录 ${i.length} 个`),e.truncated===!0&&n.push(`(以上条目按上限截断,目录树并未完整列出,勿据此判断文件不存在)`);for(let e of i)n.push(`📁 ${e.name}/`);for(let e of r){let t=e.sizeBytes>1024?`${(e.sizeBytes/1024).toFixed(1)}KB`:`${e.sizeBytes}B`,r=`📄 ${e.name} (${t})`;e.snippet!==void 0&&e.snippet.length>0&&(r+=` ↳ ${e.snippet.replaceAll(`
8
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@deepseek-ai/dsh-client-ui-primitives"),t=require("react"),n=require("@jayyuen66/dsh-plugin-shared/client"),r=require("zod");function i(e,t,n,r){if(e===`direct`){n();return}if(e===`builtin-retry`){r();return}if(!e.startsWith(`tpl:`))return;let i=t.find(t=>`tpl:${t.id}`===e);i!==void 0&&n(i.text)}function a(e,t,n,r){if(e===`builtin-retry`)return r(),!1;if(!e.startsWith(`tpl:`))return!0;let i=t.find(t=>`tpl:${t.id}`===e);return i!==void 0&&n(i.text),!0}function o(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}new TextEncoder,new TextDecoder;function s(e,t){if(t<1||Number.isNaN(t))return``;let n=0,r=0;for(let i of e){if(r>=t)break;n+=i.length,r+=1}return e.slice(0,n)}function c(e,t,n){if(e!==``&&!n.has(e))return e;let r=`tpl-${t}`;for(;n.has(r);)r=`${r}-${t}`;return r}function l(e,t){let n=new Set(e.map(({id:e})=>e)),r=[...e];for(let{id:e,...i}of t){let t=e.trim();if(t===``)t=c(``,r.length,n);else if(n.has(t))for(t=`${t}-i`;n.has(t);)t=`${t}i`;n.add(t),r.push({...i,id:t})}return r}function u(e){return typeof e==`string`?e.trim():``}function d(e,t,n){let r;if(o(e)){let{id:i,name:a,description:o,text:l,group:d,emoji:f}=e,p=u(a),m=u(l);if(p!==``&&m!==``){let e=c(u(i),t,n);n.add(e),r={id:e,name:p,description:u(o),text:m,group:u(d),emoji:s(u(f),12)}}}return r}function f(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let[r,i]of e.entries()){let e=d(i,r,t);e!==void 0&&n.push(e)}return n}const p=String.fromCodePoint(92),m=/^[A-Za-z]:$/u,h=/[/\\]+$/u;function g(e){let t=m.test(e.slice(0,2))&&(e[2]===`/`||e[2]===p);return e.startsWith(`/`)||t||e.startsWith(p+p)}function _(e){let t=e.replace(h,``);return t.length===0||m.test(t)?e:t}function v(e){let t=[];if(Array.isArray(e))for(let n of e){let e=typeof n==`string`?n.trim():``,r=_(e);e.length>0&&g(r)&&!t.includes(r)&&t.push(r)}return t}const y=0x7fffffff;function b(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function x(e){let t=e.organizeTimeoutMs;return b(t)?Math.min(Math.max(Math.trunc(t),1),y):void 0}function S(e){let t=b(e)?e:12e4;return Math.trunc(Math.min(Math.max(Math.min(t,0x7fffec77)+5e3,1),y))}const C={zh:{rolesSection:`角色库`,rolesEmptyTitle:`角色库还是空的`,rolesEmptyNote:`点「导入角色」拉取内置角色库,或用「+ 新增模板」手工写一条;空表时下拉会回落到内置精选角色集。`,rolesCount:`{count} 条`,rolesHint:`输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。`,statusReadOnly:`设置源不可写:编辑已禁用;下拉仍按当前列表生效。`,statusNotReady:`设置源未就绪:显示当前生效列表,就绪后可编辑。`,addTemplate:`+ 新增模板`,saveTitleDirty:`写入模板列表与导入允许目录(模板生效于新拉开的菜单)`,saveTitleClean:`无未保存修改`,saving:`保存中…`,save:`保存`,revert:`撤销`,resetTitle:`恢复默认?`,resetDefault:`恢复默认`,resetConfirmDescription:`将丢弃模板列表的全部自定义并写回内置默认:立即写盘、不可撤销(撤销按钮只回滚未保存的草稿)。已登记的导入允许目录不受影响。`,resetConfirmAcknowledge:`我知道这会立即写盘且不可撤销`,resetConfirmCancel:`取消`,resetConfirmClose:`关闭`,resetConfirmAction:`确认恢复默认`,footHint:`说明:编辑/新增/删除先在本地暂存,点「保存」一次写入(模板与导入允许目录同理);清空名称或正文的条目保存时会被剔除(删除请用行内「删除」);恢复默认只回滚模板列表。`,saveFailed:`保存失败:`,newTemplateName:`新模板 {index}`,persistUnconfirmed:`{action}结果不可确认:设置源未就绪(宿主未回读成功)`,persistRejected:`{action}未生效:宿主拒绝了本次写入(当前 revision {revision})`,rowAriaEmoji:`模板 {index} 视觉标记`,rowEmojiTitle:`可选视觉标记(emoji 或短文本),下拉菜单显示在名称前`,rowPlaceholderName:`菜单显示名`,rowAriaName:`模板 {index} 名称`,rowPlaceholderGroup:`分组`,rowAriaGroup:`模板 {index} 分组`,rowGroupTitle:`下拉按此分组展示;留空归入「通用」`,rowDeleteTitle:`删除此模板`,rowDelete:`删除`,rowPlaceholderDescription:`一句话介绍(下拉悬停时显示;如:威胁建模与 OWASP 代码审计)`,rowAriaDescription:`模板 {index} 一句话介绍`,rowPlaceholderText:`模板正文(点选后插入输入框,随你的消息一起发给模型)`,rowAriaText:`模板 {index} 正文`,importFailedUnknown:`导入失败(未知错误)`,importEmpty:`目录下没有符合条件的角色 .md(需含 name 的 frontmatter)`,importAllDone:`已从内置角色库导入全部 {count} 条{skips},编辑后点「保存」生效`,importFromDone:`已从 {path} 导入 {count} 条{skips},编辑后点「保存」生效`,importTruncated:`(回执标记本次导入有内容被上限截断)`,importPlaceholder:`留空 = 导入内置全部角色;或填 .md / 目录路径(须在允许根内)`,importAriaPath:`角色导入路径`,importBtnTitle:`留空 = 一键导入内置全部角色;填路径 = 导入该 .md 或目录下的角色(路径须在允许根内)`,importing:`导入中…`,importRoles:`导入角色`,importErrorPrefix:`导入失败:`,importHint:`导入说明:留空导入内置角色库全部(agents/);填路径时只放行「会话 cwd」「内置角色库 agents/」与下方「导入允许目录」之内的路径——绝对路径默认拒绝,越界会直接报「导入路径越界」并回显解析后的路径。本卡没有会话上下文,故只能填内置库或已登记目录里的路径。目录扫描顶层 + 一层子目录 .md(跳过隐藏项),文件须含 name 的 frontmatter,正文将提炼为模板正文。`,skipDeeper:`{count} 个更深层 .md 未扫描(导入只扫两层)`,skipTooLarge:`{count} 个文件超字节上限被跳过`,skipUnreadable:`{count} 个文件读取失败`,skipUnnamed:`{count} 个非角色文件(frontmatter 无 name)`,skipEscaped:`{count} 个文件的真实目标在允许根之外(符号链接),已按安全策略排除`,skipSummary:`({list})`,skipSeparator:`,`,rootsHeading:`导入允许目录(importAllowRoots)`,rootsAriaRow:`导入允许目录 {index}`,rootsRowTitle:`该目录(含其子目录)内的角色 .md 可经「导入角色」读取`,rootsRemoveTitle:`移除此允许目录`,rootsRemove:`移除`,rootsAddPlaceholder:`新增一个允许导入的目录绝对路径`,rootsAddAria:`新增导入允许目录`,rootsAddTitle:`加入待保存的允许目录列表`,rootsAdd:`登记目录`,rootsHint:`绝对路径默认拒绝:只有「当前会话 cwd」「插件内置角色库 agents/」与本列表登记的目录之内可导入。设置页没有会话上下文,卡上填的路径必须落在内置库或本列表内。改完点底部「保存」生效。`,dockOrganizeEntry:`润色`,dockTemplatesEntry:`模板`,inputPlaceholder:`输入消息,或描述要整理的目录;✦ 一键润色可整理输入框草稿。`,organizeIdle:`一键润色`,organizeLoading:`润色中`,organizeFailedShort:`失败`,organizeIdleTitle:`结合当前目录润色输入框内容(主键直接润色;▾ 可选角色风格)`,organizeFailedTitle:`润色失败:{message}`,organizeErrContextFailed:`目录上下文读取失败:{message}`,organizeErrModelFailed:`读取模型失败:{message}`,organizeErrEmpty:`输入框为空,无内容可润色`,organizeErrTimeout:`润色请求超时:宿主没有在时限内回报结果`,organizeErrUnknownReason:`未知错误`,organizeErrUnknown:`润色失败(未知错误)`,organizeCaretAria:`选择润色的角色风格`,organizeCaretTitle:`按某个角色的风格润色(角色来自下方模板库)`,organizeMainAria:`润色输入框内容`,organizeRoleGroup:`角色`,organizeDirectItem:`直接润色(默认,不带角色)`,organizeNoTemplates:`无模板可选作角色风格`,organizeRoleItem:`以「{name}」的风格润色`,organizeWriteBackUnavailable:`输入框动作不可用,无法写回`,organizeWriteBackStale:`输入框内容已变化,润色结果未写回`,organizeBusyTitle:`输入框正在提交,暂不能润色`,templatesIdleTitle:`选择一条模板插入光标处(按分组展示)`,templatesBrokenTitle:`输入框动作不可用,无法插入`,templatesBusyTitle:`输入框正在提交,暂不能插入模板`,templatesGroupCommon:`通用`,templatesAria:`插入模板`,templatesEmptyHint:`无模板:在设置页「角色库」中添加或恢复默认`,builtinLoading:`正在载入内置角色模板…`,builtinFailed:`内置模板加载失败:{message}`,builtinRetry:`重试`},en:{rolesSection:`Role library`,rolesEmptyTitle:`The role library is empty`,rolesEmptyNote:`Press "Import roles" to pull in the built-in library, or use "+ Add template" to write one by hand; while the list is empty the dropdown falls back to the built-in curated role set.`,rolesCount:`{count} items`,rolesHint:`The input-box "Template" dropdown and the "Polish" ▾ role menu share this one list; an empty list falls back to the built-in curated role set (generated from this plugin's agents/ role library). Leave the path empty and press "Import roles" to import the whole built-in library; an explicit path is allowed within "session cwd + built-in role library + the import allowed directories below". Press "Save" after editing — it survives restarts.`,statusReadOnly:`Settings source is read-only: editing is disabled; the dropdown still uses the current list.`,statusNotReady:`Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.`,addTemplate:`+ Add template`,saveTitleDirty:`Write the template list and the import allowed directories (templates take effect in newly opened menus)`,saveTitleClean:`No unsaved changes`,saving:`Saving…`,save:`Save`,revert:`Revert`,resetTitle:`Restore defaults?`,resetDefault:`Restore defaults`,resetConfirmDescription:`Discards every customization of the template list and writes the built-in defaults back: immediate, irreversible (Revert only rolls back unsaved drafts). Registered import directories are untouched.`,resetConfirmAcknowledge:`I understand this writes immediately and cannot be undone`,resetConfirmCancel:`Cancel`,resetConfirmClose:`Close`,resetConfirmAction:`Restore defaults`,footHint:`Note: edits, additions and deletions are staged locally first and written in one go when you press "Save" (same for templates and import directories); entries whose name or body is empty are dropped on save (use the inline "Delete" instead); "Restore defaults" only rolls back the template list.`,saveFailed:`Save failed: `,newTemplateName:`New template {index}`,persistUnconfirmed:`{action} cannot be confirmed: the settings source is not ready (host read-back failed)`,persistRejected:`{action} did not take effect: the host rejected this write (current revision {revision})`,rowAriaEmoji:`Visual mark of template {index}`,rowEmojiTitle:`Optional visual mark (emoji or short text), shown before the name in the dropdown`,rowPlaceholderName:`Menu display name`,rowAriaName:`Name of template {index}`,rowPlaceholderGroup:`Group`,rowAriaGroup:`Group of template {index}`,rowGroupTitle:`The dropdown groups entries by this value; leave empty to fall into "General"`,rowDeleteTitle:`Delete this template`,rowDelete:`Delete`,rowPlaceholderDescription:`One-line intro (shown on dropdown hover; e.g. threat modelling and OWASP code auditing)`,rowAriaDescription:`One-line intro of template {index}`,rowPlaceholderText:`Template body (inserted into the input box and sent to the model with your message)`,rowAriaText:`Body of template {index}`,importFailedUnknown:`Import failed (unknown error)`,importEmpty:`No qualifying role .md in that directory (frontmatter must contain name)`,importAllDone:`Imported all {count} entries from the built-in role library{skips}; press "Save" after editing`,importFromDone:`Imported {count} entries from {path}{skips}; press "Save" after editing`,importTruncated:` (the reply flagged some content as truncated by a limit)`,importPlaceholder:`Empty = import every built-in role; or a .md / directory path (must be inside an allowed root)`,importAriaPath:`Role import path`,importBtnTitle:`Empty imports the whole built-in role library in one click; a path imports that .md or the roles in that directory (must be inside an allowed root)`,importing:`Importing…`,importRoles:`Import roles`,importErrorPrefix:`Import failed: `,importHint:`Import notes: an empty path imports the whole built-in role library (agents/); an explicit path is only allowed inside "session cwd", "built-in role library agents/" and the "import allowed directories" below — absolute paths are refused by default, and anything out of bounds reports "import path out of bounds" with the resolved path echoed back. This card has no session context, so explicit paths must live in the built-in library or a registered directory. Directory scans cover the top level plus one level of sub-directory .md files (hidden entries skipped), each file needs a frontmatter name, and its body is condensed into the template text.`,skipDeeper:`{count} deeper .md files were not scanned (imports cover two levels)`,skipTooLarge:`{count} files were skipped for exceeding the byte limit`,skipUnreadable:`{count} files could not be read`,skipUnnamed:`{count} non-role files (no name in frontmatter)`,skipEscaped:`{count} files whose real target lies outside the allowed roots (symlinks) were excluded by policy`,skipSummary:` ({list})`,skipSeparator:`, `,rootsHeading:`Import allowed directories (importAllowRoots)`,rootsAriaRow:`Import allowed directory {index}`,rootsRowTitle:`Role .md files inside this directory (and its subdirectories) can be read by "Import roles"`,rootsRemoveTitle:`Remove this allowed directory`,rootsRemove:`Remove`,rootsAddPlaceholder:`Absolute path of a directory newly allowed for imports`,rootsAddAria:`Add an import allowed directory`,rootsAddTitle:`Add it to the pending allowed-directory list`,rootsAdd:`Register directory`,rootsHint:`Absolute paths are refused by default: imports only succeed inside "the current session cwd", "the plugin's built-in role library agents/" and the directories registered below. The settings page has no session context, so a path typed here must fall inside the built-in library or this list. Press "Save" at the bottom to apply.`,dockOrganizeEntry:`Polish`,dockTemplatesEntry:`Templates`,inputPlaceholder:`Type a message or describe a directory; ✦ Polish can tidy the draft.`,organizeIdle:`Polish`,organizeLoading:`Polishing`,organizeFailedShort:`Failed`,organizeIdleTitle:`Polish the input-box content against the current directory (main key polishes directly; ▾ picks a role style)`,organizeFailedTitle:`Polish failed: {message}`,organizeErrContextFailed:`Failed to read the directory context: {message}`,organizeErrModelFailed:`Failed to read the model: {message}`,organizeErrEmpty:`The input box is empty; nothing to polish`,organizeErrTimeout:`Polish request timed out: the host did not reply in time`,organizeErrUnknownReason:`unknown error`,organizeErrUnknown:`Polish failed (unknown error)`,organizeCaretAria:`Choose a role style to polish with`,organizeCaretTitle:`Polish in a role's style (roles come from the template library below)`,organizeMainAria:`Polish the input-box content`,organizeRoleGroup:`Roles`,organizeDirectItem:`Polish directly (default, no role)`,organizeNoTemplates:`No templates available as a role style`,organizeRoleItem:`Polish in the style of "{name}"`,organizeWriteBackUnavailable:`Input-box actions unavailable; cannot write back`,organizeWriteBackStale:`The input box changed; the polished text was not applied`,organizeBusyTitle:`The input box is submitting; cannot polish right now`,templatesIdleTitle:`Pick a template to insert at the caret (shown grouped)`,templatesBrokenTitle:`Input-box actions unavailable; cannot insert`,templatesBusyTitle:`The input box is submitting; cannot insert a template`,templatesGroupCommon:`General`,templatesAria:`Insert a template`,templatesEmptyHint:`No templates: add or restore defaults under "Role library" in the settings page`,builtinLoading:`Loading built-in role templates…`,builtinFailed:`Failed to load built-in templates: {message}`,builtinRetry:`Retry`}};async function w(e,t,n){let{promise:r,reject:i}=Promise.withResolvers(),a=setTimeout(()=>{i(n())},t);try{return await Promise.race([e,r])}finally{clearTimeout(a)}}function T(e){return e!==void 0&&typeof e.setDraft==`function`}function E(e){return e!==void 0&&typeof e.captureInsertion==`function`&&typeof e.insertText==`function`}function D(e,n){let r=(0,t.useRef)(e),i=(0,t.useRef)(void 0);return(0,t.useEffect)(()=>{r.current=e;let t=i.current;t!==void 0&&(t.sessionId!==e.sessionId||t.actions!==e.actions||e.phase!==`plain`)&&(t.invalidated=!0)},[e]),(0,t.useEffect)(()=>()=>{let e=i.current;e!==void 0&&(e.invalidated=!0,i.current=void 0)},[]),{begin:()=>{let e={sessionId:r.current.sessionId,draftRev:r.current.draftRev,actions:r.current.actions,invalidated:!1};return i.current=e,e},finish:e=>{i.current===e&&(i.current=void 0)},commit:(e,t)=>{let i=r.current,{actions:a}=i;if(!T(a))throw Error(n.unavailable);if(t.sessionId!==i.sessionId||i.phase!==`plain`)throw Error(n.stale);let o=i.draftRev;if(E(a)&&(o=a.captureInsertion().draftRev),t.invalidated||o!==t.draftRev)throw Error(n.stale);a.setDraft(e)}}}const O=e=>o(e)&&typeof e.$mount==`function`,k=`dirPrepOrganize`,A=`remote.${k}`,j=`@jayyuen66/dsh-dir-prep-organize`;function ee(e,t){let n=e.safeParse(t);if(!n.success)throw TypeError(r.z.prettifyError(n.error));return n.data}const te=`session request requires a string sessionId`,ne=r.z.object({sessionId:r.z.string({error:te})},{error:te}),M=`organize request requires string sessionId, prompt and entriesSummary`,re=r.z.object({sessionId:r.z.string({error:M}),prompt:r.z.string({error:M}),entriesSummary:r.z.string({error:M}),roleText:r.z.string({error:`organize request roleText must be a string when present`}).optional()},{error:M}),N=`import request requires string path and sessionId`,ie=r.z.object({path:r.z.string({error:N}),sessionId:r.z.string({error:N})},{error:N}),ae={mode:`strict`,typeSymbol:`${j}#session-request`,create:()=>({parse(e){return ee(ne,e)}})},oe=[{id:`${j}#${k}/defaults`,service:k,namespace:k,method:`defaults`,invocation:{kind:`direct`},parameters:[],result:{mode:`src-json`}},{id:`${j}#${k}/context`,service:k,namespace:k,method:`context`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:ae}],result:{mode:`src-json`}},{id:`${j}#${k}/model`,service:k,namespace:k,method:`model`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:ae}],result:{mode:`src-json`}},{id:`${j}#${k}/organize`,service:k,namespace:k,method:`organize`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${j}#organize-request`,create:()=>({parse(e){let t=ee(re,e);return t.roleText===void 0?{sessionId:t.sessionId,prompt:t.prompt,entriesSummary:t.entriesSummary}:{...t,roleText:t.roleText}}})}}],result:{mode:`src-json`}},{id:`${j}#${k}/importTemplates`,service:k,namespace:k,method:`importTemplates`,invocation:{kind:`direct`},parameters:[{name:`request`,wire:`request`,source:`json`,codec:{mode:`strict`,typeSymbol:`${j}#import-request`,create:()=>({parse(e){return ee(ie,e)}})}}],result:{mode:`src-json`}}],se=e=>(0,n.isRecord)(e)&&typeof e.defaults==`function`&&typeof e.context==`function`&&typeof e.model==`function`&&typeof e.organize==`function`&&typeof e.importTemplates==`function`,ce=e=>{if(!(0,n.isRecord)(e)||typeof e.ok!=`boolean`)throw TypeError(`Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok`);if(!e.ok){let{error:t}=e;throw!(0,n.isRecord)(t)||typeof t.code!=`string`||typeof t.message!=`string`?TypeError(`Typert Remote 应答的 error 分支缺 code/message`):Error(`${t.code}: ${t.message}`)}if(!(`value`in e))throw TypeError(`Typert Remote 应答的 ok 分支缺 value 字段`);return e.value};function le(e,t){let n,r=async()=>{n??=t.$mount({package:j,descriptors:oe});try{await n}catch(e){throw n=void 0,e}let r=e.get?.(A,!1);if(!se(r))throw Error(`${A} 未提供:宿主网关没有挂上这枚命名空间`);return r},i=async e=>{let t=await r();return ce(await e(t))};return{defaults:async()=>i(e=>e.defaults()),context:async e=>i(t=>t.context({sessionId:e})),model:async e=>i(t=>t.model({sessionId:e})),organize:async e=>i(t=>t.organize(e)),importTemplates:async e=>i(t=>t.importTemplates(e))}}function ue(e){let t;try{t=e.get?.(`remote`,!1)}catch{t=void 0}return O(t)?le(e,t):void 0}const P=`dir-prep-organize`,F=125e3,I=`dpic-rowhead`,L=`dpic-importpath`,R=`conversation.input.right`,de=`conversation.input.placeholder`;function fe(e){let{name:t,isDir:r,sizeBytes:i,snippet:a}=(0,n.isRecord)(e)?e:{};return{name:typeof t==`string`?t:``,isDir:r===!0,sizeBytes:typeof i==`number`?i:0,...typeof a==`string`?{snippet:a}:{}}}function z(e,t){let n=e[t];return typeof n==`string`?n:void 0}function B(e,t){return e===void 0?{}:{[t]:e}}function pe(e){return[[`skipDeeper`,e.deeper],[`skipTooLarge`,e.tooLarge],[`skipUnreadable`,e.unreadable],[`skipUnnamed`,e.unnamed],[`skipEscaped`,e.escaped]]}function me(e){let t=(0,n.isRecord)(e)?e:{},{ok:r,truncated:i,entries:a}=t,o=Array.isArray(a)?a.map(e=>fe(e)):void 0;return{ok:r===!0,...B(z(t,`error`),`error`),...B(z(t,`cwd`),`cwd`),...i===!0?{truncated:!0}:{},...o===void 0?{}:{entries:o}}}function he(e){let t=(0,n.isRecord)(e)?e:{};return{ok:t.ok===!0,...B(z(t,`error`),`error`),...B(z(t,`provider`),`provider`),...B(z(t,`model`),`model`),...B(z(t,`reasoningEffort`),`reasoningEffort`)}}function ge(e){let t=(0,n.isRecord)(e)?e:{};return{ok:t.ok===!0,...B(z(t,`error`),`error`),...B(z(t,`content`),`content`)}}function V(e){return typeof e==`number`&&e>0?e:0}function _e(e){return{tooLarge:V(e.tooLarge),unreadable:V(e.unreadable),deeper:V(e.deeper),unnamed:V(e.unnamed),escaped:V(e.escaped)}}function ve(e,t){if(t===void 0)return``;let n=[];for(let[r,i]of pe(t))i>0&&n.push(e(r,{count:i}));return n.length===0?``:e(`skipSummary`,{list:n.join(e(`skipSeparator`))})}function ye(e){let{ok:t,error:r,count:i,truncated:a,skipped:o,entries:s}=(0,n.isRecord)(e)?e:{},c=Array.isArray(s)?f(s):void 0;return{ok:t===!0,...typeof r==`string`?{error:r}:{},...typeof i==`number`?{count:i}:{},...a===!0?{truncated:!0}:{},...(0,n.isRecord)(o)?{skipped:_e(o)}:{},...c===void 0?{}:{entries:c}}}function be(e){let t=e.entries??[],n=[`当前目录: ${e.cwd??`(未提供)`}`],r=t.filter(e=>!e.isDir),i=t.filter(e=>e.isDir);n.push(`文件 ${r.length} 个, 目录 ${i.length} 个`),e.truncated===!0&&n.push(`(以上条目按上限截断,目录树并未完整列出,勿据此判断文件不存在)`);for(let e of i)n.push(`📁 ${e.name}/`);for(let e of r){let t=e.sizeBytes>1024?`${(e.sizeBytes/1024).toFixed(1)}KB`:`${e.sizeBytes}B`,r=`📄 ${e.name} (${t})`;e.snippet!==void 0&&e.snippet.length>0&&(r+=` ↳ ${e.snippet.replaceAll(`
9
9
  `,` `)}`),n.push(r)}return n.join(`
10
- `)}const H={phase:`idle`,list:[],error:``};let U=H,W=null,G=0;const K=new Set;function q(e){if(e===U)return U;U=e;for(let e of K)e();return e}let J;function Y(){if(J===void 0)throw Error(`远程读面不可用:宿主网关没有挂上 ${D}`);return J}var X=class extends Error{messageKey;params;constructor(e,t={}){super(e),this.name=`LocalizedOrganizeError`,this.messageKey=e,this.params=t}};async function Z(e,t){return S(e,t,()=>new X(`organizeErrTimeout`))}async function Q(){if(U.phase===`ready`)return U;if(W!==null)return await W;let e=G;return W=(async()=>{q({phase:`loading`,list:U.list,error:``});let t;try{let e=await Z(Y().defaults(),P),r=(0,n.isRecord)(e)?e:void 0,i=r?.error;t=r?.ok===!0?{phase:`ready`,list:u(r.templates),error:``}:{phase:`error`,list:[],error:typeof i==`string`&&i.trim()!==``?i:`内置模板响应不是合法载荷`}}catch(e){t={phase:`error`,list:[],error:(0,n.errorText)(e)}}finally{G===e&&(W=null)}return G===e?q(t):t})(),await W}function ye(e){return K.add(e),()=>{K.delete(e)}}function be(e,n){let r={className:F,"data-field":`dpi-builtin-state`},i=(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,"data-field":`dpi-builtin-retry`,onClick:()=>{Q()}},n(`builtinRetry`)),a;return!e.fromSettings&&e.builtinPhase!==`ready`&&(a=e.builtinPhase===`error`?(0,t.createElement)(`div`,r,n(`builtinFailed`,{message:e.builtinError}),i):(0,t.createElement)(`div`,r,n(`builtinLoading`))),a}function xe(e,t,n,r){if(!e.ok)throw new X(`organizeErrContextFailed`,{message:e.error??r});if(!t.ok||t.provider===void 0||t.model===void 0)throw new X(`organizeErrModelFailed`,{message:t.error??r});if(n.trim().length===0)throw new X(`organizeErrEmpty`)}async function Se(e){let{ctxRes:t,prompt:n,sessionId:r,roleText:i,timeoutMs:a}=e,o=ve(t),s=me(await Z(Y().organize({sessionId:r,prompt:n,entriesSummary:o,...i===void 0?{}:{roleText:i}}),a));if(!s.ok||s.content===void 0)throw s.error===void 0?new X(`organizeErrUnknown`):Error(s.error);return s.content}async function Ce(e){let t=Y(),[n,r]=await Promise.all([Z(t.context(e.sessionId),P),Z(t.model(e.sessionId),P)]),i=fe(n);return xe(i,pe(r),e.prompt,e.unknownReason),Se({ctxRes:i,prompt:e.prompt,sessionId:e.sessionId,roleText:e.roleText,timeoutMs:e.timeoutMs})}function we(e){let{value:t,status:n,writable:r,revision:i}=e;return{value:t??{},ready:n===`ready`,writable:r,revision:i??0}}function Te(e){return e.templates}function Ee(e){return e.importAllowRoots}function De(e){let t=null,n=U,r={templates:H.list,fromSettings:!1,builtinPhase:`idle`,builtinError:``,allowRoots:[],ready:!1,writable:!1,organizeTimeoutMs:void 0};return{getSnapshot(){let i=e.getSnapshot();if(i===t&&U===n)return r;t=i,n=U;let a=we(i),o=Te(a.value),s=Array.isArray(o)&&o.length>0;return r={templates:s?u(o):n.list,fromSettings:s,builtinPhase:n.phase,builtinError:n.error,allowRoots:g(Ee(a.value)),ready:a.ready,writable:a.writable,organizeTimeoutMs:y(a.value)},r},subscribe(t){let n=e.subscribe(t),r=ye(t);return()=>{n(),r()}},readBack(){let t=we(e.getSnapshot());return{ready:t.ready,revision:t.revision,templates:u(Te(t.value)),allowRoots:g(Ee(t.value))}}}}function Oe(e,t,n,r,i){let a,o=i?.treatEmptyAsReverted===!0&&t.templates.length===0&&n.length>0;return t.ready?!o&&JSON.stringify(t.templates)!==JSON.stringify(n)&&(a=e(`persistRejected`,{action:r,revision:t.revision})):a=e(`persistUnconfirmed`,{action:r}),a}function ke(e,t,n,r){let i;return t.ready?JSON.stringify(t.allowRoots)!==JSON.stringify(n)&&(i=e(`persistRejected`,{action:r,revision:t.revision})):i=e(`persistUnconfirmed`,{action:r}),i}function Ae(e){return`${e.emoji===``?``:`${e.emoji} `}${e.name}`}function je(e,t){let n=new Map;for(let r of e){let e=r.group.trim()===``?t(`templatesGroupCommon`):r.group,i=n.get(e)??[];i.push(r),n.set(e,i)}return Array.from(n.entries(),([e,t])=>({group:e,items:t}))}function $(e,t=!1){let n=[[`d`,e],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeLinecap`,`round`]];return t&&n.push([`strokeLinejoin`,`round`]),Object.fromEntries(n)}function Me(){return Object.fromEntries([[`cx`,7],[`cy`,7],[`r`,5.5],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeDasharray`,`26 10`],[`strokeLinecap`,`round`]])}function Ne(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M2 4l5 4 5-4`,!0)),(0,t.createElement)(`path`,$(`M2 8.5l5 4 5-4`,!0)))}function Pe(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0,className:`dpi-spin`},(0,t.createElement)(`circle`,Me()))}function Fe(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M3 3l8 8M11 3l-8 8`)))}function Ie(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M2.5 3.5h9M2.5 7h9M2.5 10.5h5.5`)))}function Le(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M2.5 5.5L7 9.5l4.5-4`,!0)))}function Re(e,n,r){(0,t.useEffect)(()=>{function t(e){n.current!==null&&e.target instanceof Node&&!n.current.contains(e.target)&&r()}function i(e){e.key===`Escape`&&r()}return e&&(document.addEventListener(`mousedown`,t),document.addEventListener(`keydown`,i)),()=>{document.removeEventListener(`mousedown`,t),document.removeEventListener(`keydown`,i)}},[r,e,n])}async function ze(e){let{t,loading:r,inFlight:i,seq:a,prompt:o,sessionId:s,timeoutMs:c,roleText:l,setLoading:u,setMenuOpen:d,setFailed:f,flashTimer:p,writeDraft:m}=e;if(r||i.current)return;i.current=!0,a.current+=1;let h=a.current;u(!0),f(void 0),d(!1);try{let e=await Ce({prompt:o,sessionId:s,...l===void 0?{}:{roleText:l},timeoutMs:c,unknownReason:t(`organizeErrUnknownReason`)});if(a.current!==h)return;m(e)}catch(e){if(a.current!==h)return;f(e instanceof X?t(e.messageKey,e.params):(0,n.errorText)(e)),p.current!==null&&clearTimeout(p.current),p.current=setTimeout(()=>{f(void 0)},4e3)}finally{i.current=!1,a.current===h&&u(!1)}}const Be=`organizeWriteBackUnavailable`;function Ve(e){let{t:n,icon:r,label:i,state:a,errClass:o,errTitle:s,loading:c,canWrite:l,onRun:u}=e;return(0,t.createElement)(`button`,{type:`button`,className:`dpi-btn dpi-main${o}`,"aria-label":n(`organizeMainAria`),title:s,"data-field":`dpi-organize-btn`,"data-state":a,disabled:c||!l,onClick:()=>{u()}},r,i)}function He(e){let{t:n,errClass:r,menuOpen:i,loading:a,onToggleMenu:o}=e;return(0,t.createElement)(`button`,{type:`button`,className:`dpi-btn dpi-caret${r}`,"aria-label":n(`organizeCaretAria`),"aria-haspopup":`menu`,"aria-expanded":i,title:n(`organizeCaretTitle`),"data-field":`dpi-organize-caret`,"data-state":i?`open`:`idle`,disabled:a,onClick:o},(0,t.createElement)(Le))}function Ue(e){let{t:n,templates:r,onRun:i,directItemLabel:a,noTemplatesLabel:o,builtinRow:s,loading:c,canWrite:l,errTitle:u}=e,d=c||!l,f=l?void 0:u;return(0,t.createElement)(`div`,{className:`dpi-menu`,role:`menu`,"data-field":`dpi-organize-menu`},(0,t.createElement)(`button`,{type:`button`,className:`dpi-item`,role:`menuitem`,"data-field":`dpi-organize-role-direct`,disabled:d,...f===void 0?{}:{title:f},onClick:()=>{i()}},a),r.length===0?s??(0,t.createElement)(`div`,{className:F},o):r.map(e=>(0,t.createElement)(`button`,{key:e.id,type:`button`,className:`dpi-item`,role:`menuitem`,"data-field":`dpi-organize-role-item`,disabled:d,title:f??(e.description===``?e.text:e.description),onClick:()=>{i(e.text)}},`${e.emoji===``?``:`${e.emoji} `}${n(`organizeRoleItem`,{name:e.name})}`)))}function We(e,n,r){return e===void 0?n?{icon:(0,t.createElement)(Pe),label:r(`organizeLoading`),state:`loading`}:{icon:(0,t.createElement)(Ne),label:r(`organizeIdle`),state:`idle`}:{icon:(0,t.createElement)(Fe),label:r(`organizeFailedShort`),state:`error`}}function Ge(){return function(e){let[n,r]=(0,t.useState)(!1),[i,a]=(0,t.useState)(void 0),[o,s]=(0,t.useState)(!1),c=(0,t.useRef)(0),l=(0,t.useRef)(!1),u=(0,t.useRef)(null),d=(0,t.useRef)(null),f=e.useInput===void 0?``:e.useInput(e=>e.draft)??``,p=e.useInput===void 0?0:e.useInput(e=>e.draftRev),m=e.useInput===void 0?`plain`:e.useInput(e=>e.phase),h=e.useCard(e=>e),{templates:g}=h,_=T({sessionId:e.sessionId??``,actions:e.inputActions,draftRev:p,phase:m},{unavailable:e.t(Be),stale:e.t(`organizeWriteBackStale`)});Re(o,d,()=>{s(!1)}),(0,t.useEffect)(()=>()=>{c.current+=1,u.current!==null&&clearTimeout(u.current)},[]);async function v(t){let i=_.begin();try{await ze({t:e.t,loading:n,inFlight:l,seq:c,prompt:f,sessionId:e.sessionId??``,timeoutMs:b(h.organizeTimeoutMs),roleText:t,setLoading:r,setMenuOpen:s,setFailed:a,flashTimer:u,writeDraft:e=>{_.commit(e,i)}})}finally{_.finish(i)}}function y(){h.fromSettings||Q(),s(e=>!e)}let x=We(i,n,e.t),S=C(e.inputActions),w=S&&m===`plain`,E=e.t(`organizeIdleTitle`);i===void 0?S?m!==`plain`&&(E=e.t(`organizeBusyTitle`)):E=e.t(Be):E=e.t(`organizeFailedTitle`,{message:i});let D={t:e.t,errTitle:E,icon:x.icon,label:x.label,state:x.state,errClass:i===void 0?``:` dpi-btn-err`,directItemLabel:e.t(`organizeDirectItem`),noTemplatesLabel:e.t(`organizeNoTemplates`),builtinRow:be(h,e.t),loading:n,menuOpen:o,canWrite:w,templates:g,onRun:v,onToggleMenu:y};return(0,t.createElement)(`span`,{className:`dpi-wrap dpi-split`,ref:d},Ve(D),He(D),o?Ue(D):null)}}function Ke(){return function(e){let[n,r]=(0,t.useState)(!1),i=(0,t.useRef)(null),a=e.useInput===void 0?`plain`:e.useInput(e=>e.phase),o=e.useCard(e=>e),{templates:s}=o;Re(n,i,()=>{r(!1)});function c(t){r(!1);let n=e.inputActions;w(n)&&n.insertText(t,n.captureInsertion())}let l=w(e.inputActions),u=l&&a===`plain`,d=e.t(`templatesBrokenTitle`);u?d=e.t(`templatesIdleTitle`):l&&(d=e.t(`templatesBusyTitle`));let f=je(s,e.t),p=e.t(`templatesEmptyHint`),m=be(o,e.t);return(0,t.createElement)(`span`,{className:`dpi-wrap`,ref:i},(0,t.createElement)(`button`,{type:`button`,className:`dpi-btn`,"aria-label":e.t(`templatesAria`),"aria-haspopup":`menu`,"aria-expanded":n,title:d,"data-field":`dpi-template-btn`,"data-state":n?`open`:`idle`,disabled:!u,onClick:()=>{o.fromSettings||Q(),r(e=>!e)}},(0,t.createElement)(Ie),e.t(`dockTemplatesEntry`)),n?(0,t.createElement)(`div`,{className:`dpi-menu`,role:`menu`,"data-field":`dpi-template-menu`},s.length===0?m??(0,t.createElement)(`div`,{className:F},p):f.map(e=>(0,t.createElement)(`div`,{key:e.group,className:`dpi-group`},(0,t.createElement)(`div`,{className:`dpi-grouph`,role:`presentation`},e.group),e.items.map(e=>(0,t.createElement)(`button`,{key:e.id,type:`button`,className:`dpi-item`,role:`menuitem`,"data-field":`dpi-template-item`,title:e.description===``?e.text:e.description,onClick:()=>{c(e.text)}},Ae(e)))))):null)}}function qe(){let e;try{e=`tpl-${crypto.randomUUID()}`}catch{e=`tpl-${Date.now().toString(36)}-${Math.floor(Math.random()*1e9).toString(36)}`}return e}function Je(e){let{t:n,rowNum:r,disabled:i,values:a,setters:o}=e,s=(0,t.createElement)(`span`,{className:`dpic-idx`},`#${r}`),c=(0,t.createElement)(`input`,{type:`text`,className:`dpic-emoji dsu-input`,value:a.emoji,placeholder:`😀`,disabled:i,"aria-label":n(`rowAriaEmoji`,{index:r}),title:n(`rowEmojiTitle`),onChange:e=>{o.emoji(e.target.value)},onBlur:e.onBlur}),l=(0,t.createElement)(`input`,{type:`text`,className:`dpic-name dsu-input`,value:a.name,placeholder:n(`rowPlaceholderName`),disabled:i,"aria-label":n(`rowAriaName`,{index:r}),onChange:e=>{o.name(e.target.value)},onBlur:e.onBlur}),u=(0,t.createElement)(`input`,{type:`text`,className:`dpic-group dsu-input`,value:a.group,placeholder:n(`rowPlaceholderGroup`),disabled:i,"aria-label":n(`rowAriaGroup`,{index:r}),title:n(`rowGroupTitle`),onChange:e=>{o.group(e.target.value)},onBlur:e.onBlur}),d=(0,t.createElement)(`button`,{type:`button`,className:`dpic-del dsu-btn dsu-btnDanger`,disabled:i,title:n(`rowDeleteTitle`),onClick:()=>{e.onDelete(e.templateId)}},n(`rowDelete`)),f=(0,t.createElement)(`input`,{type:`text`,className:`dpic-desc dsu-input`,value:a.description,placeholder:n(`rowPlaceholderDescription`),disabled:i,"aria-label":n(`rowAriaDescription`,{index:r}),onChange:e=>{o.description(e.target.value)},onBlur:e.onBlur}),p=(0,t.createElement)(`textarea`,{className:`dpic-text dsu-input dsu-textarea dsu-mono`,value:a.text,rows:6,placeholder:n(`rowPlaceholderText`),disabled:i,"aria-label":n(`rowAriaText`,{index:r}),onChange:e=>{o.text(e.target.value)},onBlur:e.onBlur});return(0,t.createElement)(`div`,{className:`dpic-row`},(0,t.createElement)(`div`,{className:I},s,c,l,u,d),f,p)}function Ye(e){let{t:n}=e,[r,i]=(0,t.useState)(e.template.name),[a,o]=(0,t.useState)(e.template.emoji),[s,c]=(0,t.useState)(e.template.group),[l,u]=(0,t.useState)(e.template.description),[d,f]=(0,t.useState)(e.template.text),p=String(e.index+1);(0,t.useEffect)(()=>{i(e.template.name),o(e.template.emoji),c(e.template.group),u(e.template.description),f(e.template.text)},[e.template.id,e.template.name,e.template.emoji,e.template.group,e.template.description,e.template.text]);function m(){let t=r.trim(),n=d.trim();if(t===``||n===``)return;let i=a.trim(),o=s.trim(),c=l.trim();(t!==e.template.name||i!==e.template.emoji||o!==e.template.group||c!==e.template.description||n!==e.template.text)&&e.onCommit(e.template.id,{name:t,emoji:i,group:o,description:c,text:n})}return Je({t:n,rowNum:p,disabled:e.disabled,templateId:e.template.id,values:{name:r,emoji:a,group:s,description:l,text:d},setters:{name:i,emoji:o,group:c,text:f,description:u},onBlur:m,onDelete:e.onDelete})}function Xe(e){let{t:r}=e,[i,a]=(0,t.useState)(``),[o,s]=(0,t.useState)(!1),[c,l]=(0,t.useState)(``),[u,d]=(0,t.useState)(``);async function f(){if(o)return;let t=i.trim();s(!0),d(``),l(``);try{let n=_e(await Z(Y().importTemplates({path:t,sessionId:``}),P));if(!n.ok||n.entries===void 0)throw Error(n.error??r(`importFailedUnknown`));let i=n.entries.length,o=V(n.count),s=o===0?i:Math.min(o,i);if(s===0){d(r(`importEmpty`));return}e.onImported(n.entries),a(``);let c=n.truncated===!0?r(`importTruncated`):``,u=`${ge(r,n.skipped)}${c}`;l(t.length===0?r(`importAllDone`,{count:s,skips:u}):r(`importFromDone`,{path:t,count:s,skips:u}))}catch(e){d((0,n.errorText)(e))}finally{s(!1)}}let p=e.editable&&!o,m=(0,t.createElement)(`input`,{type:`text`,className:`${L} dsu-input`,value:i,placeholder:r(`importPlaceholder`),disabled:!p,"aria-label":r(`importAriaPath`),onChange:e=>{a(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&f()}}),h=(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!p,title:r(`importBtnTitle`),onClick:f},r(o?`importing`:`importRoles`)),g=c===``?null:(0,t.createElement)(`div`,{className:`dsu-hint`},c),_=u===``?null:(0,t.createElement)(`div`,{className:`dsu-hint dsu-error`},`${r(`importErrorPrefix`)}${u}`),v=(0,t.createElement)(`div`,{className:`dsu-hint`},r(`importHint`));return(0,t.createElement)(`div`,{className:`dpic-importrow`},(0,t.createElement)(`div`,{className:I},m,h),g,_,v)}function Ze(e){let{t:n}=e,[r,i]=(0,t.useState)(``),a=!e.disabled&&r.trim().length>0,o=n(`rootsRowTitle`),s=n(`rootsRemoveTitle`),c=n(`rootsRemove`),l=e.roots.map((r,i)=>{let a=n(`rootsAriaRow`,{index:i+1}),l=(0,t.createElement)(`input`,{type:`text`,className:`${L} dsu-input`,value:r,placeholder:`/Users/me/roles`,disabled:e.disabled,"aria-label":a,title:o,onChange:t=>{e.onChangeRoot(i,t.target.value)}}),u=(0,t.createElement)(`button`,{type:`button`,className:`dpic-del dsu-btn dsu-btnDanger`,disabled:e.disabled,title:s,onClick:()=>{e.onDeleteRoot(i)}},c);return(0,t.createElement)(`div`,{className:I,key:`allow-root-${String(i)}`},l,u)}),u=n(`rootsAddPlaceholder`),d=n(`rootsAddAria`),f=n(`rootsAddTitle`),p=n(`rootsAdd`),m=(0,t.createElement)(`input`,{type:`text`,className:`${L} dsu-input`,value:r,placeholder:u,disabled:e.disabled,"aria-label":d,onChange:e=>{i(e.target.value)},onKeyDown:t=>{t.key===`Enter`&&a&&(e.onAddRoot(r.trim()),i(``))}}),h=(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!a,title:f,onClick:()=>{e.onAddRoot(r.trim()),i(``)}},p),g=(0,t.createElement)(`div`,{className:I},m,h);return(0,t.createElement)(`div`,{className:`dpic-importrow`,"data-field":`allow-roots`},(0,t.createElement)(`div`,{className:`dsu-hint`},n(`rootsHeading`)),l,g,(0,t.createElement)(`div`,{className:`dsu-hint`},n(`rootsHint`)))}function Qe(n){let{t:r,busy:i,onCancel:a,onConfirm:o}=n,[s,c]=(0,t.useState)(!1);return(0,t.createElement)(e.RiskConfirmation,{open:!0,title:r(`resetTitle`),description:r(`resetConfirmDescription`),acknowledgeLabel:r(`resetConfirmAcknowledge`),cancelLabel:r(`resetConfirmCancel`),closeLabel:r(`resetConfirmClose`),confirmLabel:r(`resetConfirmAction`),acknowledged:s,disabled:i,onAcknowledgedChange:c,onCancel:a,onConfirm:o})}function $e(e){let{foot:n,editable:r,busy:i}=e;return(0,t.createElement)(`div`,{className:`dpic-toolbar`},(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!r,onClick:e.onAdd},n.add),(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn dsu-btnDanger`,disabled:!r||i,title:n.resetTitle,onClick:e.onReset},n.reset))}function et(e,t){return{title:e(`rolesSection`),hint:e(`rolesHint`),count:e(`rolesCount`,{count:String(t)})}}function tt(e){return{add:e(`addTemplate`),save:e(`save`),saving:e(`saving`),revert:e(`revert`),reset:e(`resetDefault`),saveTitleDirty:e(`saveTitleDirty`),saveTitleClean:e(`saveTitleClean`),resetTitle:e(`resetTitle`)}}function nt(e,t){let n;return n=e.ready?e.writable?``:t(`statusReadOnly`):t(`statusNotReady`),n}function rt(e,t,n,r,i){function a(e,n){r(t.map(t=>t.id===e?{...t,...n}:t))}function o(e){r(t.filter(t=>t.id!==e))}function c(){r([...t,{id:qe(),name:e(`newTemplateName`,{index:t.length+1}),description:``,text:``,group:``,emoji:``}])}function l(e){r(t=>s(t,e))}function u(e,t){i(n.map((n,r)=>r===e?t:n))}function d(e){i(n.filter((t,n)=>n!==e))}function f(e){i([...n,e])}return{onCommit:a,onDelete:o,onAdd:c,onImported:l,onRootChange:u,onRootDelete:d,onRootAdd:f}}function it(e,t,n,r,i){let a=Oe(e,t,n,e(r),i);if(a!==void 0)throw Error(a)}function at(e,t,n){let r=ke(e,t,n,e(`save`));if(r!==void 0)throw Error(r)}function ot(e){let{t,editable:r,dirty:i,rootsDirty:a,anythingDirty:o,templates:s,allowRoots:c,draft:l,rootsDraft:d,set:f,unset:p,readBack:m,setDraft:h,setDraftFor:_,setRootsDraft:v,setBusy:y,setSaveError:b}=e;function x(e){console.error(`[dir-prep-organize] templates settings write failed:`,e),b((0,n.errorText)(e))}async function S(){if(!r||!o)return;y(!0),b(``);let e=u(l),n=g(d);try{i&&(await f(`templates`,e),it(t,m(),e,`save`)),a&&(await f(`importAllowRoots`,n),at(t,m(),n)),y(!1),h(t=>t===l?e:t),v(e=>e===d?n:e)}catch(e){y(!1),x(e)}}function C(){h(s),v(c),b(``)}function w(){y(!0),(async()=>{try{let e=await Q();if(e.phase!==`ready`)throw Error(e.error);await p(`templates`),it(t,m(),e.list,`resetDefault`,{treatEmptyAsReverted:!0}),b(``),h(e.list),_(e.list),v(c)}catch(e){x(e)}finally{y(!1)}})()}return{onSave:S,onDiscard:C,onReset:w}}function st(e){let{t:r,statusHint:i,draft:a,rootsDraft:o,foot:s,editable:c,anythingDirty:l,busy:u,saveError:d,onRequestReset:f}=e,{onCommit:p,onDelete:m,onAdd:h,onImported:g,onRootChange:_,onRootDelete:v,onRootAdd:y}=e.draftActions,{onSave:b,onDiscard:x}=e.persistActions,S=(0,t.createElement)(`p`,{className:`dsu-hint`},r(`footHint`)),C=(0,t.createElement)(n.SaveBar,{dirty:l,busy:u,writable:c,error:d===``?null:`${r(`saveFailed`)}${d}`,saveLabel:r(`save`),savingLabel:r(`saving`),revertLabel:r(`revert`),dirtyLabel:r(`saveTitleDirty`),cleanLabel:r(`saveTitleClean`),readOnlyLabel:r(`statusReadOnly`),onSave:()=>{b()},onDiscard:x});return(0,t.createElement)(n.CardForm,null,i===``?null:(0,t.createElement)(`p`,{className:`dsu-hint`},i),(0,t.createElement)(n.Section,et(r,a.length),(0,t.createElement)($e,{foot:s,editable:c,busy:u,onAdd:h,onReset:f}),a.map((e,n)=>(0,t.createElement)(Ye,{key:e.id,t:r,index:n,template:e,disabled:!c||u,onCommit:p,onDelete:m})),(0,t.createElement)(Xe,{t:r,editable:c&&!u,onImported:g}),(0,t.createElement)(Ze,{t:r,roots:o,disabled:!c||u,onChangeRoot:_,onDeleteRoot:v,onAddRoot:y}),S),C)}function ct(e){let{t:n}=e,[r,i]=(0,t.useState)(!1),[a,o]=(0,t.useState)(``),[s,c]=(0,t.useState)(!1),l=tt(n),u=e.useCard(e=>e),{templates:d}=u,f=u.ready&&u.writable,p=nt(u,n);(0,t.useEffect)(()=>{u.fromSettings||Q()},[u.fromSettings]);let[m,h]=(0,t.useState)(d),[_,v]=(0,t.useState)(d);(0,t.useEffect)(()=>{_!==d&&(v(d),h(e=>JSON.stringify(e)===JSON.stringify(_)?d:e))},[d,_]);let[y,b]=(0,t.useState)(u.allowRoots),[x,S]=(0,t.useState)(u.allowRoots);(0,t.useEffect)(()=>{x!==u.allowRoots&&(S(u.allowRoots),b(e=>JSON.stringify(e)===JSON.stringify(x)?u.allowRoots:e))},[x,u.allowRoots]);let C=JSON.stringify(m)!==JSON.stringify(d),w=JSON.stringify(g(y))!==JSON.stringify(u.allowRoots),T=C||w,E=rt(n,m,y,h,b),D=ot({t:n,editable:f,dirty:C,rootsDirty:w,anythingDirty:T,templates:d,allowRoots:u.allowRoots,draft:m,rootsDraft:y,set:e.set,unset:e.unset,readBack:e.readBack,setDraft:h,setDraftFor:v,setRootsDraft:b,setBusy:c,setSaveError:o}),O=st({t:n,statusHint:p,draft:m,rootsDraft:y,foot:l,editable:f,anythingDirty:T,busy:s,saveError:a,onRequestReset:()=>{i(!0)},draftActions:E,persistActions:D});return(0,t.createElement)(t.Fragment,null,O,r?(0,t.createElement)(Qe,{t:n,busy:s,onCancel:()=>{i(!1)},onConfirm:()=>{i(!1),D.onReset()}}):null)}const lt=[`slots`,`configForms`,`locale`];function ut(e,t,n){let r=()=>({hooks:{card:t}});e.slots.inject(R,()=>{let t=e.slots.register({name:R,id:N,order:99,label:()=>n(`dockOrganizeEntry`),locale:N,inject:r},Ge()),i=e.slots.register({name:R,id:`${N}-templates`,order:100,label:()=>n(`dockTemplatesEntry`),locale:N,inject:r},Ke());return()=>{t(),i()}})}function dt(e,t,n,r){e.slots.inject(`plugins.bundle.config`,()=>e.slots.register({name:`plugins.bundle.config`,key:`@jayyuen66/dsh-dir-prep-organize`,inject:()=>({t:n,hooks:{card:t},set:(e,t)=>r.set(e,t),unset:e=>r.unset(e),readBack:()=>t.readBack()})},ct))}exports.apply=function(e){let t=le(e);J=t,e.effect(()=>()=>{J===t&&(J=void 0)},`dir-prep-organize: remote reader`),e.effect(()=>{let e=(0,n.ensureCardUiCss)(),t=document.createElement(`style`);return t.id=`dir-prep-organize-css`,t.textContent=`.dpi-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-1,transparent);color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1;border-radius:8px;padding:6px 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .16s,border-color .16s,color .16s}
11
- .dpi-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,currentColor);background:var(--dsw-alias-bg-layer-2,transparent)}
10
+ `)}const H={phase:`idle`,list:[],error:``};let U=H,W=null,G=0;const K=new Set;function q(e){if(e===U)return U;U=e;for(let e of K)e();return e}let J;function Y(){if(J===void 0)throw Error(`远程读面不可用:宿主网关没有挂上 ${k}`);return J}var X=class extends Error{messageKey;params;constructor(e,t={}){super(e),this.name=`LocalizedOrganizeError`,this.messageKey=e,this.params=t}};async function Z(e,t){return w(e,t,()=>new X(`organizeErrTimeout`))}async function Q(){if(U.phase===`ready`)return U;if(W!==null)return await W;let e=G;return W=(async()=>{q({phase:`loading`,list:U.list,error:``});let t;try{let e=await Z(Y().defaults(),F),r=(0,n.isRecord)(e)?e:void 0,i=r?.error;t=r?.ok===!0?{phase:`ready`,list:f(r.templates),error:``}:{phase:`error`,list:[],error:typeof i==`string`&&i.trim()!==``?i:`内置模板响应不是合法载荷`}}catch(e){t={phase:`error`,list:[],error:(0,n.errorText)(e)}}finally{G===e&&(W=null)}return G===e?q(t):t})(),await W}function xe(e){return K.add(e),()=>{K.delete(e)}}function Se(e,n){return e.fromSettings||e.builtinPhase===`ready`?[]:e.builtinPhase===`error`?[{id:`builtin-state`,label:(0,t.createElement)(`span`,{"data-field":`dpi-builtin-state`},n(`builtinFailed`,{message:e.builtinError})),disabled:!0},{id:`builtin-retry`,label:n(`builtinRetry`)}]:[{id:`builtin-state`,label:(0,t.createElement)(`span`,{"data-field":`dpi-builtin-state`},n(`builtinLoading`)),disabled:!0}]}function Ce(e,t,n,r){if(!e.ok)throw new X(`organizeErrContextFailed`,{message:e.error??r});if(!t.ok||t.provider===void 0||t.model===void 0)throw new X(`organizeErrModelFailed`,{message:t.error??r});if(n.trim().length===0)throw new X(`organizeErrEmpty`)}async function we(e){let{ctxRes:t,prompt:n,sessionId:r,roleText:i,timeoutMs:a}=e,o=be(t),s=ge(await Z(Y().organize({sessionId:r,prompt:n,entriesSummary:o,...i===void 0?{}:{roleText:i}}),a));if(!s.ok||s.content===void 0)throw s.error===void 0?new X(`organizeErrUnknown`):Error(s.error);return s.content}async function Te(e){let t=Y(),[n,r]=await Promise.all([Z(t.context(e.sessionId),F),Z(t.model(e.sessionId),F)]),i=me(n);return Ce(i,he(r),e.prompt,e.unknownReason),we({ctxRes:i,prompt:e.prompt,sessionId:e.sessionId,roleText:e.roleText,timeoutMs:e.timeoutMs})}function Ee(e){let{value:t,status:n,writable:r,revision:i}=e;return{value:t??{},ready:n===`ready`,writable:r,revision:i??0}}function De(e){return e.templates}function Oe(e){return e.importAllowRoots}function ke(e){let t=null,n=U,r={templates:H.list,fromSettings:!1,builtinPhase:`idle`,builtinError:``,allowRoots:[],ready:!1,writable:!1,organizeTimeoutMs:void 0};return{getSnapshot(){let i=e.getSnapshot();if(i===t&&U===n)return r;t=i,n=U;let a=Ee(i),o=De(a.value),s=Array.isArray(o)&&o.length>0;return r={templates:s?f(o):n.list,fromSettings:s,builtinPhase:n.phase,builtinError:n.error,allowRoots:v(Oe(a.value)),ready:a.ready,writable:a.writable,organizeTimeoutMs:x(a.value)},r},subscribe(t){let n=e.subscribe(t),r=xe(t);return()=>{n(),r()}},readBack(){let t=Ee(e.getSnapshot());return{ready:t.ready,revision:t.revision,templates:f(De(t.value)),allowRoots:v(Oe(t.value))}}}}function Ae(e,t,n,r,i){let a,o=i?.treatEmptyAsReverted===!0&&t.templates.length===0&&n.length>0;return t.ready?!o&&JSON.stringify(t.templates)!==JSON.stringify(n)&&(a=e(`persistRejected`,{action:r,revision:t.revision})):a=e(`persistUnconfirmed`,{action:r}),a}function je(e,t,n,r){let i;return t.ready?JSON.stringify(t.allowRoots)!==JSON.stringify(n)&&(i=e(`persistRejected`,{action:r,revision:t.revision})):i=e(`persistUnconfirmed`,{action:r}),i}function Me(e){return`${e.emoji===``?``:`${e.emoji} `}${e.name}`}function Ne(e,t){let n=new Map;for(let r of e){let e=r.group.trim()===``?t(`templatesGroupCommon`):r.group,i=n.get(e)??[];i.push(r),n.set(e,i)}return Array.from(n.entries(),([e,t])=>({group:e,items:t}))}function $(e,t=!1){let n=[[`d`,e],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeLinecap`,`round`]];return t&&n.push([`strokeLinejoin`,`round`]),Object.fromEntries(n)}function Pe(){return Object.fromEntries([[`cx`,7],[`cy`,7],[`r`,5.5],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeDasharray`,`26 10`],[`strokeLinecap`,`round`]])}function Fe(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,{d:`M7 1.6l1.45 3.95L12.4 7 8.45 8.45 7 12.4 5.55 8.45 1.6 7l3.95-1.45Z`,fill:`currentColor`,stroke:`none`}))}function Ie(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0,className:`dpi-spin`},(0,t.createElement)(`circle`,Pe()))}function Le(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M3 3l8 8M11 3l-8 8`)))}function Re(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M2.5 3.5h9M2.5 7h9M2.5 10.5h5.5`)))}function ze(){return(0,t.createElement)(`svg`,{width:16,height:16,viewBox:`0 0 16 16`,"aria-hidden":!0},(0,t.createElement)(`path`,$(`M3 6l5 5 5-5`,!0)))}async function Be(e){let{t,loading:r,inFlight:i,seq:a,prompt:o,sessionId:s,timeoutMs:c,roleText:l,setLoading:u,setMenuOpen:d,setFailed:f,flashTimer:p,writeDraft:m}=e;if(r||i.current)return;i.current=!0,a.current+=1;let h=a.current;u(!0),f(void 0),d(!1);try{let e=await Te({prompt:o,sessionId:s,...l===void 0?{}:{roleText:l},timeoutMs:c,unknownReason:t(`organizeErrUnknownReason`)});if(a.current!==h)return;m(e)}catch(e){if(a.current!==h)return;f(e instanceof X?t(e.messageKey,e.params):(0,n.errorText)(e)),p.current!==null&&clearTimeout(p.current),p.current=setTimeout(()=>{f(void 0)},4e3)}finally{i.current=!1,a.current===h&&u(!1)}}const Ve=`organizeWriteBackUnavailable`;function He(e){let{t:n,icon:r,label:i,state:a,errClass:o,errTitle:s,loading:c,canWrite:l,onRun:u}=e;return(0,t.createElement)(`button`,{type:`button`,className:`dpi-btn dpi-main${o}`,"aria-label":n(`organizeMainAria`),title:s,"data-field":`dpi-organize-btn`,"data-state":a,disabled:c||!l,onClick:()=>{u()}},r,i)}function Ue(e,n){let{t:r,errClass:i,menuOpen:a,loading:o,onToggleMenu:s}=e;return(0,t.createElement)(`button`,{ref:n,type:`button`,className:`dpi-btn dpi-caret${i}`,"aria-label":r(`organizeCaretAria`),"aria-haspopup":`menu`,"aria-expanded":a,title:r(`organizeCaretTitle`),"data-field":`dpi-organize-caret`,"data-state":a?`open`:`idle`,disabled:o,onClick:s},(0,t.createElement)(ze))}function We(e){let{t:n,templates:r,roleGroupLabel:i,directItemLabel:a,noTemplatesLabel:o,builtinEntries:s,loading:c,canWrite:l,errTitle:u}=e,d=c||!l,f=l?void 0:u,p=[{type:`label`,id:`roles`,text:i},{id:`direct`,label:(0,t.createElement)(`span`,f===void 0?null:{title:f},a),disabled:d}];if(r.length===0)return p.push(...s,{id:`empty`,label:o,disabled:!0}),p;for(let e of r){let r=`${e.emoji===``?``:`${e.emoji} `}${n(`organizeRoleItem`,{name:e.name})}`;p.push({id:`tpl:${e.id}`,label:(0,t.createElement)(`span`,{title:f??(e.description===``?e.text:e.description)},r),disabled:d})}return p}function Ge(e,n,r){return e===void 0?n?{icon:(0,t.createElement)(Ie),label:r(`organizeLoading`),state:`loading`}:{icon:(0,t.createElement)(Fe),label:r(`organizeIdle`),state:`idle`}:{icon:(0,t.createElement)(Le),label:r(`organizeFailedShort`),state:`error`}}function Ke(){return function(n){let[r,a]=(0,t.useState)(!1),[o,s]=(0,t.useState)(void 0),[c,l]=(0,t.useState)(!1),u=(0,t.useRef)(0),d=(0,t.useRef)(!1),f=(0,t.useRef)(null),p=(0,t.useRef)(null),m=n.useInput===void 0?``:n.useInput(e=>e.draft)??``,h=n.useInput===void 0?0:n.useInput(e=>e.draftRev),g=n.useInput===void 0?`plain`:n.useInput(e=>e.phase),_=n.useCard(e=>e),v=D({sessionId:n.sessionId??``,actions:n.inputActions,draftRev:h,phase:g},{unavailable:n.t(Ve),stale:n.t(`organizeWriteBackStale`)});(0,t.useEffect)(()=>()=>{u.current+=1,f.current!==null&&clearTimeout(f.current)},[]);async function y(e){let t=v.begin();try{await Be({t:n.t,loading:r,inFlight:d,seq:u,prompt:m,sessionId:n.sessionId??``,timeoutMs:S(_.organizeTimeoutMs),roleText:e,setLoading:a,setMenuOpen:l,setFailed:s,flashTimer:f,writeDraft:e=>{v.commit(e,t)}})}finally{v.finish(t)}}function b(){_.fromSettings||Q(),l(e=>!e)}let x=Ge(o,r,n.t),C=T(n.inputActions),w=C&&g===`plain`,E=n.t(`organizeIdleTitle`);o===void 0?C?g!==`plain`&&(E=n.t(`organizeBusyTitle`)):E=n.t(Ve):E=n.t(`organizeFailedTitle`,{message:o});let O={t:n.t,errTitle:E,icon:x.icon,label:x.label,state:x.state,errClass:o===void 0?``:` dpi-btn-err`,roleGroupLabel:n.t(`organizeRoleGroup`),directItemLabel:n.t(`organizeDirectItem`),noTemplatesLabel:n.t(`organizeNoTemplates`),builtinEntries:Se(_,n.t),loading:r,menuOpen:c,canWrite:w,templates:_.templates,onRun:y,onToggleMenu:b},k=We(O),A=Ue(O,p),j=(0,t.createElement)(e.Menu,{open:c,anchor:A,items:k,side:`top`,portal:!0,anchorRef:p,className:`dpi-caretWrap`,listClassName:`dpi-polish-menu dpi-organize-menu`,returnFocus:()=>p.current,onClose:()=>{l(!1)},onSelect:e=>{l(!1),i(e,_.templates,y,()=>{Q()})}});return(0,t.createElement)(`span`,{className:`dpi-wrap dpi-split`},He(O),j)}}function qe(e,n){let{templates:r}=e,i=Ne(r,n),a=[];if(r.length===0){let t=Se(e,n);return a.push(...t),t.length===0&&a.push({id:`templates-empty`,label:n(`templatesEmptyHint`),disabled:!0}),a}for(let e of i){a.push({type:`label`,id:`group:${e.group}`,text:e.group});for(let n of e.items)a.push({id:`tpl:${n.id}`,label:(0,t.createElement)(`span`,{title:n.description===``?n.text:n.description},Me(n))})}return a}function Je(){return function(n){let[r,i]=(0,t.useState)(!1),o=(0,t.useRef)(null),s=n.useInput===void 0?`plain`:n.useInput(e=>e.phase),c=n.useCard(e=>e),{templates:l}=c;function u(e){i(!1);let t=n.inputActions;E(t)&&t.insertText(e,t.captureInsertion())}let d=E(n.inputActions),f=d&&s===`plain`,p=n.t(`templatesBrokenTitle`);f?p=n.t(`templatesIdleTitle`):d&&(p=n.t(`templatesBusyTitle`));let m=qe(c,n.t),h=(0,t.createElement)(`button`,{ref:o,type:`button`,className:`dpi-btn`,"aria-label":n.t(`templatesAria`),"aria-haspopup":`menu`,"aria-expanded":r,title:p,"data-field":`dpi-template-btn`,"data-state":r?`open`:`idle`,disabled:!f,onClick:()=>{c.fromSettings||Q(),i(e=>!e)}},(0,t.createElement)(Re),n.t(`dockTemplatesEntry`));return(0,t.createElement)(e.Menu,{open:r,anchor:h,items:m,side:`top`,portal:!0,anchorRef:o,listClassName:`dpi-polish-menu dpi-template-menu`,returnFocus:()=>o.current,onClose:()=>{i(!1)},onSelect:e=>{a(e,l,u,()=>{Q()})&&i(!1)}})}}function Ye(){let e;try{e=`tpl-${crypto.randomUUID()}`}catch{e=`tpl-${Date.now().toString(36)}-${Math.floor(Math.random()*1e9).toString(36)}`}return e}function Xe(e){let{t:n,rowNum:r,disabled:i,values:a,setters:o}=e,s=(0,t.createElement)(`span`,{className:`dpic-idx`},`#${r}`),c=(0,t.createElement)(`input`,{type:`text`,className:`dpic-emoji dsu-input`,value:a.emoji,placeholder:`😀`,disabled:i,"aria-label":n(`rowAriaEmoji`,{index:r}),title:n(`rowEmojiTitle`),onChange:e=>{o.emoji(e.target.value)},onBlur:e.onBlur}),l=(0,t.createElement)(`input`,{type:`text`,className:`dpic-name dsu-input`,value:a.name,placeholder:n(`rowPlaceholderName`),disabled:i,"aria-label":n(`rowAriaName`,{index:r}),onChange:e=>{o.name(e.target.value)},onBlur:e.onBlur}),u=(0,t.createElement)(`input`,{type:`text`,className:`dpic-group dsu-input`,value:a.group,placeholder:n(`rowPlaceholderGroup`),disabled:i,"aria-label":n(`rowAriaGroup`,{index:r}),title:n(`rowGroupTitle`),onChange:e=>{o.group(e.target.value)},onBlur:e.onBlur}),d=(0,t.createElement)(`button`,{type:`button`,className:`dpic-del dsu-btn dsu-btnDanger`,disabled:i,title:n(`rowDeleteTitle`),onClick:()=>{e.onDelete(e.templateId)}},n(`rowDelete`)),f=(0,t.createElement)(`input`,{type:`text`,className:`dpic-desc dsu-input`,value:a.description,placeholder:n(`rowPlaceholderDescription`),disabled:i,"aria-label":n(`rowAriaDescription`,{index:r}),onChange:e=>{o.description(e.target.value)},onBlur:e.onBlur}),p=(0,t.createElement)(`textarea`,{className:`dpic-text dsu-input dsu-textarea dsu-mono`,value:a.text,rows:6,placeholder:n(`rowPlaceholderText`),disabled:i,"aria-label":n(`rowAriaText`,{index:r}),onChange:e=>{o.text(e.target.value)},onBlur:e.onBlur});return(0,t.createElement)(`div`,{className:`dpic-row`},(0,t.createElement)(`div`,{className:I},s,c,l,u,d),f,p)}function Ze(e){let{t:n}=e,[r,i]=(0,t.useState)(e.template.name),[a,o]=(0,t.useState)(e.template.emoji),[s,c]=(0,t.useState)(e.template.group),[l,u]=(0,t.useState)(e.template.description),[d,f]=(0,t.useState)(e.template.text),p=String(e.index+1);(0,t.useEffect)(()=>{i(e.template.name),o(e.template.emoji),c(e.template.group),u(e.template.description),f(e.template.text)},[e.template.id,e.template.name,e.template.emoji,e.template.group,e.template.description,e.template.text]);function m(){let t=r.trim(),n=d.trim();if(t===``||n===``)return;let i=a.trim(),o=s.trim(),c=l.trim();(t!==e.template.name||i!==e.template.emoji||o!==e.template.group||c!==e.template.description||n!==e.template.text)&&e.onCommit(e.template.id,{name:t,emoji:i,group:o,description:c,text:n})}return Xe({t:n,rowNum:p,disabled:e.disabled,templateId:e.template.id,values:{name:r,emoji:a,group:s,description:l,text:d},setters:{name:i,emoji:o,group:c,text:f,description:u},onBlur:m,onDelete:e.onDelete})}function Qe(e){let{t:r}=e,[i,a]=(0,t.useState)(``),[o,s]=(0,t.useState)(!1),[c,l]=(0,t.useState)(``),[u,d]=(0,t.useState)(``);async function f(){if(o)return;let t=i.trim();s(!0),d(``),l(``);try{let n=ye(await Z(Y().importTemplates({path:t,sessionId:``}),F));if(!n.ok||n.entries===void 0)throw Error(n.error??r(`importFailedUnknown`));let i=n.entries.length,o=V(n.count),s=o===0?i:Math.min(o,i);if(s===0){d(r(`importEmpty`));return}e.onImported(n.entries),a(``);let c=n.truncated===!0?r(`importTruncated`):``,u=`${ve(r,n.skipped)}${c}`;l(t.length===0?r(`importAllDone`,{count:s,skips:u}):r(`importFromDone`,{path:t,count:s,skips:u}))}catch(e){d((0,n.errorText)(e))}finally{s(!1)}}let p=e.editable&&!o,m=(0,t.createElement)(`input`,{type:`text`,className:`${L} dsu-input`,value:i,placeholder:r(`importPlaceholder`),disabled:!p,"aria-label":r(`importAriaPath`),onChange:e=>{a(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&f()}}),h=(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!p,title:r(`importBtnTitle`),onClick:f},r(o?`importing`:`importRoles`)),g=c===``?null:(0,t.createElement)(`div`,{className:`dsu-hint`},c),_=u===``?null:(0,t.createElement)(`div`,{className:`dsu-hint dsu-error`},`${r(`importErrorPrefix`)}${u}`),v=(0,t.createElement)(`div`,{className:`dsu-hint`},r(`importHint`));return(0,t.createElement)(`div`,{className:`dpic-importrow`},(0,t.createElement)(`div`,{className:I},m,h),g,_,v)}function $e(e){let{t:n}=e,[r,i]=(0,t.useState)(``),a=!e.disabled&&r.trim().length>0,o=n(`rootsRowTitle`),s=n(`rootsRemoveTitle`),c=n(`rootsRemove`),l=e.roots.map((r,i)=>{let a=n(`rootsAriaRow`,{index:i+1}),l=(0,t.createElement)(`input`,{type:`text`,className:`${L} dsu-input`,value:r,placeholder:`/Users/me/roles`,disabled:e.disabled,"aria-label":a,title:o,onChange:t=>{e.onChangeRoot(i,t.target.value)}}),u=(0,t.createElement)(`button`,{type:`button`,className:`dpic-del dsu-btn dsu-btnDanger`,disabled:e.disabled,title:s,onClick:()=>{e.onDeleteRoot(i)}},c);return(0,t.createElement)(`div`,{className:I,key:`allow-root-${String(i)}`},l,u)}),u=n(`rootsAddPlaceholder`),d=n(`rootsAddAria`),f=n(`rootsAddTitle`),p=n(`rootsAdd`),m=(0,t.createElement)(`input`,{type:`text`,className:`${L} dsu-input`,value:r,placeholder:u,disabled:e.disabled,"aria-label":d,onChange:e=>{i(e.target.value)},onKeyDown:t=>{t.key===`Enter`&&a&&(e.onAddRoot(r.trim()),i(``))}}),h=(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!a,title:f,onClick:()=>{e.onAddRoot(r.trim()),i(``)}},p),g=(0,t.createElement)(`div`,{className:I},m,h);return(0,t.createElement)(`div`,{className:`dpic-importrow`,"data-field":`allow-roots`},(0,t.createElement)(`div`,{className:`dsu-hint`},n(`rootsHeading`)),l,g,(0,t.createElement)(`div`,{className:`dsu-hint`},n(`rootsHint`)))}function et(n){let{t:r,busy:i,onCancel:a,onConfirm:o}=n,[s,c]=(0,t.useState)(!1);return(0,t.createElement)(e.RiskConfirmation,{open:!0,title:r(`resetTitle`),description:r(`resetConfirmDescription`),acknowledgeLabel:r(`resetConfirmAcknowledge`),cancelLabel:r(`resetConfirmCancel`),closeLabel:r(`resetConfirmClose`),confirmLabel:r(`resetConfirmAction`),acknowledged:s,disabled:i,onAcknowledgedChange:c,onCancel:a,onConfirm:o})}function tt(e){let{foot:n,editable:r,busy:i}=e;return(0,t.createElement)(`div`,{className:`dpic-toolbar`},(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn`,disabled:!r,onClick:e.onAdd},n.add),(0,t.createElement)(`button`,{type:`button`,className:`dsu-btn dsu-btnDanger`,disabled:!r||i,title:n.resetTitle,onClick:e.onReset},n.reset))}function nt(e,t){return{title:e(`rolesSection`),hint:e(`rolesHint`),count:e(`rolesCount`,{count:String(t)})}}function rt(e){return{add:e(`addTemplate`),save:e(`save`),saving:e(`saving`),revert:e(`revert`),reset:e(`resetDefault`),saveTitleDirty:e(`saveTitleDirty`),saveTitleClean:e(`saveTitleClean`),resetTitle:e(`resetTitle`)}}function it(e,t){let n;return n=e.ready?e.writable?``:t(`statusReadOnly`):t(`statusNotReady`),n}function at(e,t,n,r,i){function a(e,n){r(t.map(t=>t.id===e?{...t,...n}:t))}function o(e){r(t.filter(t=>t.id!==e))}function s(){r([...t,{id:Ye(),name:e(`newTemplateName`,{index:t.length+1}),description:``,text:``,group:``,emoji:``}])}function c(e){r(t=>l(t,e))}function u(e,t){i(n.map((n,r)=>r===e?t:n))}function d(e){i(n.filter((t,n)=>n!==e))}function f(e){i([...n,e])}return{onCommit:a,onDelete:o,onAdd:s,onImported:c,onRootChange:u,onRootDelete:d,onRootAdd:f}}function ot(e,t,n,r,i){let a=Ae(e,t,n,e(r),i);if(a!==void 0)throw Error(a)}function st(e,t,n){let r=je(e,t,n,e(`save`));if(r!==void 0)throw Error(r)}function ct(e){let{t,editable:r,dirty:i,rootsDirty:a,anythingDirty:o,templates:s,allowRoots:c,draft:l,rootsDraft:u,set:d,unset:p,readBack:m,setDraft:h,setDraftFor:g,setRootsDraft:_,setBusy:y,setSaveError:b}=e;function x(e){console.error(`[dir-prep-organize] templates settings write failed:`,e),b((0,n.errorText)(e))}async function S(){if(!r||!o)return;y(!0),b(``);let e=f(l),n=v(u);try{i&&(await d(`templates`,e),ot(t,m(),e,`save`)),a&&(await d(`importAllowRoots`,n),st(t,m(),n)),y(!1),h(t=>t===l?e:t),_(e=>e===u?n:e)}catch(e){y(!1),x(e)}}function C(){h(s),_(c),b(``)}function w(){y(!0),(async()=>{try{let e=await Q();if(e.phase!==`ready`)throw Error(e.error);await p(`templates`),ot(t,m(),e.list,`resetDefault`,{treatEmptyAsReverted:!0}),b(``),h(e.list),g(e.list),_(c)}catch(e){x(e)}finally{y(!1)}})()}return{onSave:S,onDiscard:C,onReset:w}}function lt(e){let{t:r,statusHint:i,draft:a,rootsDraft:o,foot:s,editable:c,anythingDirty:l,busy:u,saveError:d,onRequestReset:f}=e,{onCommit:p,onDelete:m,onAdd:h,onImported:g,onRootChange:_,onRootDelete:v,onRootAdd:y}=e.draftActions,{onSave:b,onDiscard:x}=e.persistActions,S=(0,t.createElement)(`p`,{className:`dsu-hint`},r(`footHint`)),C=(0,t.createElement)(n.EmptyState,{title:r(`rolesEmptyTitle`),plain:!0},r(`rolesEmptyNote`)),w=(0,t.createElement)(n.SaveBar,{dirty:l,busy:u,writable:c,error:d===``?null:`${r(`saveFailed`)}${d}`,saveLabel:r(`save`),savingLabel:r(`saving`),revertLabel:r(`revert`),dirtyLabel:r(`saveTitleDirty`),cleanLabel:r(`saveTitleClean`),readOnlyLabel:r(`statusReadOnly`),onSave:()=>{b()},onDiscard:x});return(0,t.createElement)(n.CardForm,null,i===``?null:(0,t.createElement)(`p`,{className:`dsu-hint`},i),(0,t.createElement)(n.Section,nt(r,a.length),(0,t.createElement)(tt,{foot:s,editable:c,busy:u,onAdd:h,onReset:f}),a.length===0?C:a.map((e,n)=>(0,t.createElement)(Ze,{key:e.id,t:r,index:n,template:e,disabled:!c||u,onCommit:p,onDelete:m})),(0,t.createElement)(Qe,{t:r,editable:c&&!u,onImported:g}),(0,t.createElement)($e,{t:r,roots:o,disabled:!c||u,onChangeRoot:_,onDeleteRoot:v,onAddRoot:y}),S),w)}function ut(e){let{t:n}=e,[r,i]=(0,t.useState)(!1),[a,o]=(0,t.useState)(``),[s,c]=(0,t.useState)(!1),l=rt(n),u=e.useCard(e=>e),{templates:d}=u,f=u.ready&&u.writable,p=it(u,n);(0,t.useEffect)(()=>{u.fromSettings||Q()},[u.fromSettings]);let[m,h]=(0,t.useState)(d),[g,_]=(0,t.useState)(d);(0,t.useEffect)(()=>{g!==d&&(_(d),h(e=>JSON.stringify(e)===JSON.stringify(g)?d:e))},[d,g]);let[y,b]=(0,t.useState)(u.allowRoots),[x,S]=(0,t.useState)(u.allowRoots);(0,t.useEffect)(()=>{x!==u.allowRoots&&(S(u.allowRoots),b(e=>JSON.stringify(e)===JSON.stringify(x)?u.allowRoots:e))},[x,u.allowRoots]);let C=JSON.stringify(m)!==JSON.stringify(d),w=JSON.stringify(v(y))!==JSON.stringify(u.allowRoots),T=C||w,E=at(n,m,y,h,b),D=ct({t:n,editable:f,dirty:C,rootsDirty:w,anythingDirty:T,templates:d,allowRoots:u.allowRoots,draft:m,rootsDraft:y,set:e.set,unset:e.unset,readBack:e.readBack,setDraft:h,setDraftFor:_,setRootsDraft:b,setBusy:c,setSaveError:o}),O=lt({t:n,statusHint:p,draft:m,rootsDraft:y,foot:l,editable:f,anythingDirty:T,busy:s,saveError:a,onRequestReset:()=>{i(!0)},draftActions:E,persistActions:D});return(0,t.createElement)(t.Fragment,null,O,r?(0,t.createElement)(et,{t:n,busy:s,onCancel:()=>{i(!1)},onConfirm:()=>{i(!1),D.onReset()}}):null)}const dt=[`slots`,`configForms`,`locale`];function ft(e,t,n){let r=()=>({hooks:{card:t}});e.slots.inject(R,()=>{let t=e.slots.register({name:R,id:P,order:99,label:()=>n(`dockOrganizeEntry`),locale:P,inject:r},Ke()),i=e.slots.register({name:R,id:`${P}-templates`,order:100,label:()=>n(`dockTemplatesEntry`),locale:P,inject:r},Je());return()=>{t(),i()}})}function pt(e,t){e.slots.inject(de,()=>e.slots.register({name:de,select:()=>!0,inject:()=>({t})},e=>e.t(`inputPlaceholder`)))}function mt(e,t,n,r){e.slots.inject(`plugins.bundle.config`,()=>e.slots.register({name:`plugins.bundle.config`,key:`@jayyuen66/dsh-dir-prep-organize`,inject:()=>({t:n,hooks:{card:t},set:(e,t)=>r.set(e,t),unset:e=>r.unset(e),readBack:()=>t.readBack()})},ut))}exports.apply=function(e){let t=ue(e);J=t,e.effect(()=>()=>{J===t&&(J=void 0)},`dir-prep-organize: remote reader`),e.effect(()=>{let e=(0,n.ensureCardUiCss)(),t=document.createElement(`style`);return t.id=`dir-prep-organize-css`,t.textContent=`.dpi-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-1,transparent);color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:13px;line-height:1;height:32px;border-radius:6px;padding:0 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .16s,border-color .16s,color .16s}
11
+ .dpi-btn:hover:not(:disabled){border-color:var(--dsw-alias-border-l3,currentColor);background:var(--dsw-alias-interactive-bg-hover,transparent)}
12
12
  .dpi-btn:disabled{opacity:.55;cursor:not-allowed}
13
13
  .dpi-btn:disabled[data-state="loading"]{cursor:progress}
14
14
  .dpi-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,currentColor);outline-offset:1px}
@@ -19,16 +19,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
19
19
  @keyframes dpi-rotate{to{transform:rotate(360deg)}}
20
20
  @media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn{transition:none}}
21
21
  .dpi-wrap{position:relative;display:inline-flex;isolation:isolate}
22
- .dpi-menu{position:absolute;bottom:calc(100% + 6px);right:0;z-index:50;min-width:224px;max-height:340px;overflow-y:auto;background:var(--dsw-menu-surface-fill,transparent);backdrop-filter:var(--dsw-menu-backdrop-filter,none);border:0;border-radius:10px;padding:4px;display:flex;flex-direction:column;gap:2px;box-shadow:var(--dsw-elevation-panel,none)}
23
- .dpi-item{appearance:none;border:none;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1.4;text-align:left;border-radius:6px;padding:8px 10px;cursor:pointer;white-space:nowrap}
24
- .dpi-item:hover,.dpi-item:focus-visible{background:var(--dsw-alias-bg-layer-2,transparent)}
25
- .dpi-item-empty{color:var(--dsw-alias-label-tertiary,inherit);cursor:default;font-size:12px;padding:8px 10px;white-space:nowrap}
22
+ .dpi-caretWrap{display:inline-flex}
23
+ .dpi-polish-menu{width:280px}
26
24
  .dpi-split{display:inline-flex;align-items:stretch}
27
- .dpi-split .dpi-main{border-top-right-radius:0;border-bottom-right-radius:0;padding-right:8px}
28
- .dpi-split .dpi-caret{border-left:none;border-top-left-radius:0;border-bottom-left-radius:0;padding-left:4px;padding-right:6px}
29
- .dpi-split .dpi-caret svg{width:10px;height:10px}
30
- .dpi-group{padding:2px 0}
31
- .dpi-grouph{font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary,inherit);padding:6px 10px 2px;letter-spacing:.02em}
25
+ .dpi-split .dpi-main{border-top-right-radius:0;border-bottom-right-radius:0;padding-right:10px}
26
+ .dpi-split .dpi-caret{width:32px;min-width:32px;padding:0;justify-content:center;border-left:0;border-top-left-radius:0;border-bottom-left-radius:0}
27
+ .dpi-split .dpi-caret svg{width:16px;height:16px;display:block;flex:none}
32
28
  .dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}
33
29
  .dpic-name{flex:1;min-width:0}
34
30
  .dpic-rowhead .dpic-name{width:auto}
@@ -42,7 +38,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
42
38
  .dpic-toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:8px 0}
43
39
  .dpic-rowhead{display:flex;gap:8px;align-items:center}
44
40
  .dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);flex:none;min-width:26px}
45
- .dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}`,document.head.append(t),()=>{t.remove(),e()}},`dir-prep-organize: styles`);let r=e.configForms.get(N),i=De(r);e.effect(()=>e.locale.register(N,x),`dir-prep-organize-card: locale dictionaries`);let a=e.locale.bind(N);ut(e,i,a),dt(e,i,a,r)},exports.builtinTemplatesSnapshot=function(){return U},exports.formatContextSummary=ve,exports.formatImportSkips=ge,exports.inject=lt,exports.loadBuiltinTemplates=Q,exports.parseContextResponse=fe,exports.parseOrganizeResponse=me,exports.persistError=Oe,exports.resetBuiltinTemplates=function(){G+=1,W=null,q(H)},exports.rootsPersistError=ke,exports.setDirPrepReader=function(e){J=e},exports.subscribeBuiltinTemplates=ye;
41
+ .dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}`,document.head.append(t),()=>{t.remove(),e()}},`dir-prep-organize: styles`);let r=e.configForms.get(P),i=ke(r);e.effect(()=>e.locale.register(P,C),`dir-prep-organize-card: locale dictionaries`);let a=e.locale.bind(P);ft(e,i,a),pt(e,a),mt(e,i,a,r)},exports.builtinTemplatesSnapshot=function(){return U},exports.formatContextSummary=be,exports.formatImportSkips=ve,exports.inject=dt,exports.loadBuiltinTemplates=Q,exports.parseContextResponse=me,exports.parseOrganizeResponse=ge,exports.persistError=Ae,exports.resetBuiltinTemplates=function(){G+=1,W=null,q(H)},exports.rootsPersistError=je,exports.setDirPrepReader=function(e){J=e},exports.subscribeBuiltinTemplates=xe;
46
42
  return module.exports;
47
43
  },
48
44
  });
package/host.js CHANGED
@@ -534,11 +534,23 @@ function classifyRead(read, usedBytes, maxTotalBytes) {
534
534
  countTooLarge: false
535
535
  };
536
536
  }
537
- /** cwd 提取:sessions.get(id).header.cwd,非字符串视为缺。 */
538
- function cwdOfSession(sessions, sessionId) {
537
+ function isWorkingDirectory(value) {
538
+ if (!isRecord(value)) return false;
539
+ return typeof value["get"] === "function";
540
+ }
541
+ /** 服务表里的 `workingDirectory` 只按形状收:缺席或形状不符都交回 undefined,由 header.cwd 回落。 */
542
+ function workingDirectoryOf(service) {
543
+ return isWorkingDirectory(service) ? service : void 0;
544
+ }
545
+ /** cwd 提取:优先活目录 `workingDirectory.get(session)`,服务缺席或给不出非空串时回落
546
+ * `sessions.get(id).header.cwd`(创建期快照)。会话 `cd` 之后只有前者跟着变,目录上下文、
547
+ * 越界判定与润色提示词都须按它解析。非字符串一律视为缺。 */
548
+ function cwdOfSession(sessions, workingDirectory, sessionId) {
539
549
  let cwd;
540
550
  if (sessionId !== null && sessionId.length > 0) {
541
- const value = (sessions?.get(sessionIdOf(sessionId)))?.header?.cwd;
551
+ const session = sessions?.get(sessionIdOf(sessionId));
552
+ const live = workingDirectory?.get?.(session);
553
+ const value = typeof live === "string" && live.length > 0 ? live : session?.header?.cwd;
542
554
  if (typeof value === "string" && value.length > 0) cwd = value;
543
555
  }
544
556
  return cwd;
@@ -1366,7 +1378,7 @@ async function contextPayload(scope, sessionId) {
1366
1378
  const messages = scope.messagesOf();
1367
1379
  try {
1368
1380
  const fs = scope.deps.fs?.();
1369
- const cwd = cwdOfSession(scope.deps.sessions?.(), sessionId);
1381
+ const cwd = cwdOfSession(scope.deps.sessions?.(), scope.deps.workingDirectory?.(), sessionId);
1370
1382
  if (fs === void 0) return {
1371
1383
  ok: false,
1372
1384
  error: messages.fsUnavailable
@@ -1445,7 +1457,7 @@ async function organizePayload(scope, parsed) {
1445
1457
  const { prompt, entriesSummary, roleText: roleTextRaw, sessionId: sessionIdText } = organizeRequestOf(isRecord(parsed) ? parsed : {});
1446
1458
  const sessions = scope.deps.sessions?.();
1447
1459
  const recentTurns = resolveRecentTurns(sessions, sessionIdText);
1448
- const cwd = cwdOfSession(sessions, sessionIdText);
1460
+ const cwd = cwdOfSession(sessions, scope.deps.workingDirectory?.(), sessionIdText);
1449
1461
  if (cwd === void 0) return {
1450
1462
  ok: false,
1451
1463
  error: messages.cwdUnknown
@@ -1498,7 +1510,7 @@ async function importPayload(scope, parsed) {
1498
1510
  }
1499
1511
  };
1500
1512
  const allowRoots = scope.deps.importAllowRoots?.() ?? [];
1501
- const cwd = cwdOfSession(scope.deps.sessions?.(), request.sessionId);
1513
+ const cwd = cwdOfSession(scope.deps.sessions?.(), scope.deps.workingDirectory?.(), request.sessionId);
1502
1514
  if (!request.isBuiltin) {
1503
1515
  const policyError = importPathError(request.requested, cwd, allowRoots, messages);
1504
1516
  if (policyError !== void 0) return {
@@ -1651,12 +1663,13 @@ function apply(ctx, config) {
1651
1663
  maxSnippetBytes: config.maxSnippetBytes,
1652
1664
  readConcurrency: config.readConcurrency
1653
1665
  });
1654
- const scope = {
1666
+ installDirPrepRemote(ctx, {
1655
1667
  deps: {
1656
1668
  sessions: () => {
1657
1669
  const service = getService("sessions");
1658
1670
  return isSessionsService(service) ? service : void 0;
1659
1671
  },
1672
+ workingDirectory: () => workingDirectoryOf(getService("workingDirectory")),
1660
1673
  fs: () => {
1661
1674
  const service = getService("fs");
1662
1675
  return isFsService(service) ? service : void 0;
@@ -1678,9 +1691,6 @@ function apply(ctx, config) {
1678
1691
  },
1679
1692
  messagesOf: localeMessages,
1680
1693
  limitsOf: () => sanitizeLimits(limitsOfConfig())
1681
- };
1682
- ctx.inject([], (child) => {
1683
- installDirPrepRemote(child, scope);
1684
1694
  });
1685
1695
  }
1686
- export { configSchema as Config, DIR_PREP_REMOTE_NAMESPACE, DirPrepRemoteService, apply, buildOrganizeSystem, buildOrganizeUser, clampInt, collectAgentTemplates, collectDirContext, createRemotePayloads, defaultTemplatesFrom, drainStreamToText, extractRecentTurns, importAllowRootsOf, importPathError, inject, installDirPrepRemote, liveModelOf, loadDefaultTemplates, runOrganize, sanitizeLimits };
1696
+ export { configSchema as Config, DIR_PREP_REMOTE_NAMESPACE, DirPrepRemoteService, apply, buildOrganizeSystem, buildOrganizeUser, clampInt, collectAgentTemplates, collectDirContext, createRemotePayloads, defaultTemplatesFrom, drainStreamToText, extractRecentTurns, importAllowRootsOf, importPathError, inject, installDirPrepRemote, isWorkingDirectory, liveModelOf, loadDefaultTemplates, runOrganize, sanitizeLimits, workingDirectoryOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayyuen66/dsh-dir-prep-organize",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "dsh 插件:对话输入框「润色」按钮(主键直接润色/▾ 以角色风格润色,结合当前目录 + session 模型润色草稿)+「模板」下拉(内置精选角色集生成自插件 agents/ 角色库,可按部门分组;设置卡可增删改/一键导入内置全部/导入本地角色 .md)",
5
5
  "keywords": [
6
6
  "cordis",
@@ -61,37 +61,37 @@
61
61
  "registry": "https://registry.npmjs.org"
62
62
  },
63
63
  "dependencies": {
64
- "@jayyuen66/dsh-plugin-shared": "^0.2.12",
64
+ "@jayyuen66/dsh-plugin-shared": "^0.2.13",
65
65
  "zod": "4.6.7"
66
66
  },
67
67
  "devDependencies": {
68
- "@deepseek-ai/cordis": "4.1.0",
69
- "@deepseek-ai/cordis-plugin-group": "1.1.0",
70
- "@deepseek-ai/cordis-plugin-include": "1.1.0",
71
- "@deepseek-ai/cosmokit": "1.9.0",
72
- "@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.5",
73
- "@deepseek-ai/dsh-app-boot": "0.2.2-rc.5",
74
- "@deepseek-ai/dsh-brand": "0.2.2-rc.5",
75
- "@deepseek-ai/dsh-client-locale": "0.2.2-rc.5",
76
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.5",
77
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-rc.5",
78
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
79
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.5",
80
- "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.5",
81
- "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.5",
82
- "@deepseek-ai/dsh-config-editor": "0.2.2-rc.5",
83
- "@deepseek-ai/dsh-error": "0.2.2-rc.5",
84
- "@deepseek-ai/dsh-fs": "0.2.2-rc.5",
85
- "@deepseek-ai/dsh-home-paths": "0.2.2-rc.5",
86
- "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.5",
87
- "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
88
- "@deepseek-ai/dsh-output-retention": "0.2.2-rc.5",
89
- "@deepseek-ai/dsh-sandbox": "0.2.2-rc.5",
90
- "@deepseek-ai/dsh-scope": "0.2.2-rc.5",
91
- "@deepseek-ai/dsh-session": "0.2.2-rc.5",
92
- "@deepseek-ai/dsh-settings": "0.2.2-rc.5",
93
- "@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.5",
94
- "@deepseek-ai/schemastery": "3.19.0",
68
+ "@deepseek-ai/cordis": "4.2.0-alpha.1",
69
+ "@deepseek-ai/cordis-plugin-group": "1.2.0-alpha.1",
70
+ "@deepseek-ai/cordis-plugin-include": "1.2.0-alpha.1",
71
+ "@deepseek-ai/cosmokit": "1.10.0-alpha.1",
72
+ "@deepseek-ai/dsh-agent-default-model": "0.2.3-alpha.2",
73
+ "@deepseek-ai/dsh-app-boot": "0.2.3-alpha.2",
74
+ "@deepseek-ai/dsh-brand": "0.2.3-alpha.2",
75
+ "@deepseek-ai/dsh-client-locale": "0.2.3-alpha.2",
76
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.3-alpha.2",
77
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.3-alpha.2",
78
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.3-alpha.2",
79
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.3-alpha.2",
80
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.3-alpha.2",
81
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.3-alpha.2",
82
+ "@deepseek-ai/dsh-config-editor": "0.2.3-alpha.2",
83
+ "@deepseek-ai/dsh-error": "0.2.3-alpha.2",
84
+ "@deepseek-ai/dsh-fs": "0.2.3-alpha.2",
85
+ "@deepseek-ai/dsh-home-paths": "0.2.3-alpha.2",
86
+ "@deepseek-ai/dsh-launch-environment": "0.2.3-alpha.2",
87
+ "@deepseek-ai/dsh-llm": "0.2.3-alpha.2",
88
+ "@deepseek-ai/dsh-output-retention": "0.2.3-alpha.2",
89
+ "@deepseek-ai/dsh-sandbox": "0.2.3-alpha.2",
90
+ "@deepseek-ai/dsh-scope": "0.2.3-alpha.2",
91
+ "@deepseek-ai/dsh-session": "0.2.3-alpha.2",
92
+ "@deepseek-ai/dsh-settings": "0.2.3-alpha.2",
93
+ "@deepseek-ai/dsh-typert-protocol": "0.2.3-alpha.2",
94
+ "@deepseek-ai/schemastery": "3.20.0-alpha.1",
95
95
  "@e18e/eslint-plugin": "0.8.1",
96
96
  "@types/node": "26.6.6",
97
97
  "@types/react": "19.3.0",
@@ -113,21 +113,21 @@
113
113
  "vitest": "5.1.1"
114
114
  },
115
115
  "peerDependencies": {
116
- "@deepseek-ai/cordis": "^4.0.5 || ^4.0.6-alpha.2",
117
- "@deepseek-ai/cosmokit": "^1.8.6 || ^1.8.7-alpha.2",
118
- "@deepseek-ai/dsh": "^0.2.2-rc.5",
119
- "@deepseek-ai/dsh-agent-default-model": "^0.2.2-rc.5",
120
- "@deepseek-ai/dsh-brand": "^0.2.2-rc.5",
121
- "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.5",
122
- "@deepseek-ai/dsh-client-ui-conversation": "^0.2.2-rc.5",
123
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.5",
124
- "@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.5",
125
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.5",
126
- "@deepseek-ai/dsh-fs": "^0.2.2-rc.5",
127
- "@deepseek-ai/dsh-llm": "^0.2.2-rc.5",
128
- "@deepseek-ai/dsh-session": "^0.2.2-rc.5",
129
- "@deepseek-ai/dsh-typert-protocol": "^0.2.2-rc.5",
130
- "@deepseek-ai/schemastery": "^3.19.0"
116
+ "@deepseek-ai/cordis": "^4.2.0-alpha.1",
117
+ "@deepseek-ai/cosmokit": "^1.10.0-alpha.1",
118
+ "@deepseek-ai/dsh": "^0.2.3-alpha.2",
119
+ "@deepseek-ai/dsh-agent-default-model": "^0.2.3-alpha.2",
120
+ "@deepseek-ai/dsh-brand": "^0.2.3-alpha.2",
121
+ "@deepseek-ai/dsh-client-locale": "^0.2.3-alpha.2",
122
+ "@deepseek-ai/dsh-client-ui-conversation": "^0.2.3-alpha.2",
123
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.3-alpha.2",
124
+ "@deepseek-ai/dsh-client-ui-settings": "^0.2.3-alpha.2",
125
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.3-alpha.2",
126
+ "@deepseek-ai/dsh-fs": "^0.2.3-alpha.2",
127
+ "@deepseek-ai/dsh-llm": "^0.2.3-alpha.2",
128
+ "@deepseek-ai/dsh-session": "^0.2.3-alpha.2",
129
+ "@deepseek-ai/dsh-typert-protocol": "^0.2.3-alpha.2",
130
+ "@deepseek-ai/schemastery": "^3.20.0-alpha.1"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@deepseek-ai/cordis": {
@@ -172,8 +172,8 @@
172
172
  },
173
173
  "icon": "icon.svg",
174
174
  "engines": {
175
- "dsh": "^0.2.2-rc.5",
176
- "node": ">=24.9.0"
175
+ "dsh": "^0.2.3-alpha.2",
176
+ "node": "^24.22.3 || >=26.13.1"
177
177
  },
178
178
  "dsh": {
179
179
  "manifestVersion": 1,
package/types/host.d.ts CHANGED
@@ -179,6 +179,13 @@ export type LlmStreamOptions = Pick<GenerateOptions, "provider" | "model" | "rea
179
179
  * `AsyncIterable<StreamChunk>`——官方那一位的真实返回域由成员自己交出,重述一次就多一处
180
180
  * 会漂移的判决(`stream` 在 installed index.d.ts 上有数枚同名成员,本包用的是 runtime 那枚)。 */
181
181
  export type LlmService = Pick<LlmRuntime, "stream">;
182
+ /** 官方工作目录服务的最小读取形状(`WorkingDirectoryService.get(session)` 同步、无 fs I/O)。 */
183
+ interface WorkingDirectoryFace {
184
+ get?: (session: unknown) => unknown;
185
+ }
186
+ export declare function isWorkingDirectory(value: unknown): value is WorkingDirectoryFace;
187
+ /** 服务表里的 `workingDirectory` 只按形状收:缺席或形状不符都交回 undefined,由 header.cwd 回落。 */
188
+ export declare function workingDirectoryOf(service: unknown): WorkingDirectoryFace | undefined;
182
189
  export interface DirEntry {
183
190
  name: string;
184
191
  isDir: boolean;
@@ -400,6 +407,8 @@ export declare const inject: string[];
400
407
  * 注册之后才就绪),测试可直接注入静态假服务。 */
401
408
  export interface RouteDeps {
402
409
  sessions?: () => SessionsService | undefined;
410
+ /** 会话活目录服务(宿主 `ctx.workingDirectory`);缺席时 cwd 回落 `header.cwd`。 */
411
+ workingDirectory?: () => WorkingDirectoryFace | undefined;
403
412
  fs?: () => FsService | undefined;
404
413
  llm?: () => LlmService | undefined;
405
414
  agentDefaultModel?: () => AgentDefaultModel | undefined;
@@ -0,0 +1,7 @@
1
+ import type { TemplatesSnapshot } from "./client-entry.js";
2
+ /** 内置模板失败态的重试项 id。 */
3
+ export declare const BUILTIN_RETRY_ID = "builtin-retry";
4
+ /** 组织菜单动作:direct 立即整理、重试重新拉表、模板项带稿子整理。 */
5
+ export declare function runOrganizeMenuSelection(id: string, templates: TemplatesSnapshot["templates"], organize: (roleText?: string) => Promise<void>, retry: () => void): void;
6
+ /** 模板菜单动作;返回是否关闭菜单(重试保持打开等 store 换代列出)。 */
7
+ export declare function runTemplateMenuSelection(id: string, templates: TemplatesSnapshot["templates"], pick: (text: string) => void, retry: () => void): boolean;
@@ -4,6 +4,9 @@ import type { MessagesCatalog } from "@jayyuen66/dsh-plugin-shared/lib/locale";
4
4
  export interface UiMessages {
5
5
  /** 角色库小节标题与说明(这份列表同时喂「模板」下拉与「润色」▾)。 */
6
6
  readonly rolesSection: string;
7
+ /** 角色库为 0 条时的块级空态。 */
8
+ readonly rolesEmptyTitle: string;
9
+ readonly rolesEmptyNote: string;
7
10
  readonly rolesCount: string;
8
11
  readonly rolesHint: string;
9
12
  /** 设置源可写位为 false 时的状态条。 */
@@ -130,6 +133,8 @@ export interface UiMessages {
130
133
  readonly dockOrganizeEntry: string;
131
134
  /** dock 注册项 label:「模板」按钮。 */
132
135
  readonly dockTemplatesEntry: string;
136
+ /** 空输入框的占位提示(`conversation.input.placeholder`)。 */
137
+ readonly inputPlaceholder: string;
133
138
  /** 「润色」主键(空闲态)。 */
134
139
  readonly organizeIdle: string;
135
140
  /** 「润色」主键(请求中)。 */
@@ -159,6 +164,8 @@ export interface UiMessages {
159
164
  readonly organizeCaretTitle: string;
160
165
  /** 「润色」主键的 aria-label。 */
161
166
  readonly organizeMainAria: string;
167
+ /** 角色菜单分组标题(画板 F:菜单项上方的「角色」小标签)。 */
168
+ readonly organizeRoleGroup: string;
162
169
  /** 角色菜单首项:直接润色。 */
163
170
  readonly organizeDirectItem: string;
164
171
  /** 角色菜单空态(没有任何模板)。 */