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

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,14 @@
4
4
  [语义化版本](https://semver.org/lang/zh-CN/)。最新版本在最上。这里的偏离是刻意的:版本标题
5
5
  不写发布日期,各版发布时间以 npm registry 为准(`npm view <包名> time` 取得到)。
6
6
 
7
+ ## 0.1.17
8
+
9
+ shared 经 catalog 抬到 `^0.3.1`:运行期入口收敛为 `./tool` / `./client`,本仓导入与 Remote 读取器(`parseOrThrow` / `remoteMounterOf`)迁到新入口;本地的 `clampInt`、`hasMethods`、工作目录形状守卫与 `markRemote` 副本删除,改由 shared 提供,host 构建经 `toolImportTransform` 拆分 `/tool`;client 仍按 `dsh.client.external` 外置 `/client`。宿主基线同步切到 `dsh 0.2.3-alpha.3`(devDependencies 全族精确钉 alpha.3);客户端对 `ui-slots` / `ui-primitives` 的导入改走 `<包名>/client`(包根保留兼容,`ui-messages.ts` 的 `declare module` 同批改名);`dsh.client.immediately` 改为 `false`,不再进启动预取层(bundle 随 Loader 条目到达);`react` / `react-dom` 开发依赖抬到 `^19.3.1`,并以 optional peer 声明。devDependencies 补 `@deepseek-ai/dsh-fs-patch`、`@deepseek-ai/dsh-output-retention` 与 `@rolldown/plugin-transform-imports`(peer 同步)。设置卡的脏值判等改用 shared 的 `formValueEquals`(`null` / `undefined` / 缺键按同值处理);「一键导入内置角色库」的范围收窄为顶层 + 一层子目录(两份 README 同步)。角色库、默认配置与整理行为不变。
10
+
11
+ 发布面不再随包发 `types/` 声明:`exports["."]` 回到纯运行期映射,`files`、`check` 与 `prepack` 去掉声明链,`build-types.mjs`、`tsconfig.types.json` 与声明相关用例一并退役;README 的声明承诺与 peer 清单读法同步删除。插件是终端产物,宿主按包名载入 `host.js` / `client.js`,没有 TypeScript 消费方。
12
+
13
+ - 客户端的样式注入迁到 `meta.stylesheets`:构建期注册、宿主渲染前安装,客户端不再向 `document.head` 追加 `<style>`;导入内置库的忙碌态补 `ProgressBar`。两张 capability-map 配图重绘并对齐仓库的 SVG 无障碍契约。
14
+
7
15
  ## 0.1.16
8
16
 
9
17
  宿主基线切到 `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` 依赖。角色库、默认配置与路由不变。
package/README.md CHANGED
@@ -12,7 +12,7 @@
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
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" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.3--alpha.3-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
 
@@ -61,7 +61,7 @@
61
61
  - That table **stays host-side**: the client bundle no longer inlines it. The generated file is ~640 KB and used to push `client.js` to ~711 KB.
62
62
  - The browser calls the Remote `defaults` method **once, lazily** (first menu open or first settings-card visit) and reuses it in-process. Nothing is fetched at all when the user already has their own templates.
63
63
  - While it has not arrived the menu shows a loading row - not the "no templates" hint. A failure surfaces the host's own reason plus a Retry button.
64
- - The settings card's **"Role library"** section covers per-entry add/edit/delete, a two-step restore of the defaults, one-click import of the whole built-in library, import of a local `.md` or directory **by path**, and registration of extra allowed import directories. That section is **one list feeding two places**: the input-box "Template" dropdown and the "Polish" ▾ role menu.
64
+ - The settings card's **"Role library"** section covers per-entry add/edit/delete, a two-step restore of the defaults, one-click import of the built-in role library's top level plus one sub-directory level, import of a local `.md` or directory **by path**, and registration of extra allowed import directories. That section is **one list feeding two places**: the input-box "Template" dropdown and the "Polish" ▾ role menu.
65
65
  - Templates and allowed directories are read and written through the host settings with **zero LLM calls**, and **no model tool is registered**.
66
66
 
67
67
  ## <img src="https://api.iconify.design/lucide/package.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Install
@@ -74,13 +74,12 @@ 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.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
- - **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
- - **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
- - **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.
83
- - **What ships**: `host.js`, `client.js`, `templates.data.mjs`, `types/`, `cordis.patch.yml`, `agents/`, `locale/`, `docs/` and `THIRD_PARTY_NOTICES.md`. `package.json`, `README*` and `LICENSE` are attached unconditionally by the registry client.
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'`. `engines.node` follows the host floor; the installer rejects a Node the host cannot run on.
78
+ - **Requires host `dsh` on the `0.2.3-alpha.3` host line or later.** The requirement the host actually reads is `engines.dsh` (`^0.2.3-alpha.3`), 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.3`, later releases below `0.3.0` and prereleases on the `0.2.3` tuple pass; `0.2.2` and earlier and `0.3.0` or later are refused; prereleases of later `0.2.x` tuples such as `0.2.4-rc.1` pass as well. 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.3`** - 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.3`); 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
+ - **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` once keyed its tool-runtime scheduler with a plain `Symbol` on the `0.2.2` host line (removed in `0.2.3`) (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
+ - **The three host packages `host.js` imports as values are required peers**: `@deepseek-ai/schemastery` (the host's fork - only it resolves the `.volatile()` fields), `@deepseek-ai/dsh-brand` and `@deepseek-ai/dsh-typert-protocol` (the Remote service base). `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
+ - **What ships**: `host.js`, `client.js`, `templates.data.mjs`, `cordis.patch.yml`, `agents/`, `locale/`, `docs/` and `THIRD_PARTY_NOTICES.md`. `package.json`, `README*` and `LICENSE` are attached unconditionally by the registry client.
84
83
  - **The built-in table ships as its own artifact and is loaded on first use**, not at plugin load. It used to be bundled into `host.js`, so every user paid for the templates in memory even without opening the dropdown.
85
84
  - **`agents/` is not authored here**: it comes from [`agency-agents-zh`](https://github.com/jnMetaCode/agency-agents-zh) (MIT). The copyright and licence notice ship in `THIRD_PARTY_NOTICES.md`, because MIT requires it in every distributed copy. Do not hand-edit files under `agents/`.
86
85
 
@@ -88,6 +87,8 @@ Remove with `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`.
88
87
 
89
88
  If your profile pins `@jayyuen66/dsh-plugin-shared` with a pnpm `overrides` entry, that pin must be at least the version this package declares. A lower pin installs a copy without the names imported at runtime, and the host then reports `N entries did not activate` together with `does not provide an export named ...` at boot - the package installs fine and never loads, and no per-repository CI run can see it.
90
89
 
90
+ Bundle order matters too: this package's patch inserts the `dsh-plugin-shared` row and declares shared in `dependencies`, so that row loads the copy this bundle imports. When several bundles insert a row for the same package, the bundle listed first in `dsh.profile.bundles` decides which copy it loads; a profile `cordis.patch.yml` row with the same package name loads the profile's copy. Keep whichever copy that row ends up with at least as new as this package declares. From this release on, the client stylesheets (`meta.stylesheets`) and `ProgressBar` require shared `0.3.2` or later; the `^0.3.1` range only keeps older plugins compatible, so treat `0.3.2` as the effective floor for releases and single-repository CI.
91
+
91
92
  ## <img src="https://api.iconify.design/lucide/circle-check.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Verify it is live
92
93
 
93
94
  1. **Two controls appear** to the right of the chat input. If they do not, the bundle layer is not mounted - check `dsh --profile web --dump-config` for the `dir-prep-organize` layer.
@@ -104,6 +105,8 @@ Worth knowing before you look for them:
104
105
  - **It registers no model tools.** The host half only injects `settings`; it never touches the tool registry. There is no `organize_text` tool to call.
105
106
  - **It opens no HTTP route of its own.** The data plane is the official Typert Remote namespace `dirPrepOrganize`, registered through an injected child fiber, reached through the host `/api` gateway. Authentication, Host/DNS-rebinding/Origin checks, the signed browser-session cookie and body limits are all the gateway's - this package keeps no CSRF token and no route table.
106
107
  - **It adds no CLI subcommand.**
108
+ - **It does not require the plugin manager to be installed.** The settings card waits for the `plugins.bundle.config` slot; without that slot it never appears, and the input-box controls keep working.
109
+ - **Its stylesheet is managed by the host renderer.** The build registers it through `ModuleLoader` metadata, so the client entry does not append a `<style>` element to `document.head`.
107
110
  - **It reads no environment variable** and makes no outbound request of its own.
108
111
  - What it *does* consume: the host `settings` service (hard-injected, so the entry does not activate without it), `llm.stream`, `agentDefaultModel`, and the session/agent/filesystem services. When the settings form itself is not ready, the card renders disabled with a status hint while the dropdown falls back to the built-in curated set.
109
112
 
@@ -114,7 +117,8 @@ Worth knowing before you look for them:
114
117
  - `conversation.input.right` - the polish button (id `dir-prep-organize`, order 99) and the templates dropdown (id `dir-prep-organize-templates`, order 100).
115
118
  - `plugins.bundle.config` - the settings card, keyed by the **bundle package name** `@jayyuen66/dsh-dir-prep-organize`. The host dispatches `entryKey: pkg.name` (source of truth: `dsh.profile.bundles` in the profile's `package.json`), so a bare entry id never matches and the card would render nowhere.
116
119
  - The settings namespace and `configForms.get()` stay the **bare entry id** `dir-prep-organize` - deliberately not the same identifier as that slot key.
117
- - The client half is `dsh.client.platform = web` with `immediately`; `dsh.client.external` names `@jayyuen66/dsh-plugin-shared/client` so the host sorts the startup graph with that supply row in place.
120
+ - The client half is `dsh.client.platform = web`; it is not an `immediately` row, so its bundle is not part of the boot prefetch tier and arrives with the Loader entry. `dsh.client.external` names `@jayyuen66/dsh-plugin-shared/client` so the host sorts the startup graph with that supply row in place.
121
+ - The card's `Menu` / `RiskConfirmation` come from `@deepseek-ai/dsh-client-ui-primitives/client`; the Web composition loads `ui-slots`, `ui-primitives`, and `ui-dockkit` as `immediately` rows, and `PLATFORM_MODULES` answers those names for every dynamic bundle. A composition that drops those rows cannot render the card.
118
122
  - The card follows the official locale plugin's preference for its own labels and copy; the host half reads the preference per request, so switching language needs no restart.
119
123
  - The plugin page reads its title, description and detail document from `locale/<lang>.json` (`meta.title`, `meta.description`, `meta.detail`). `docs/DETAIL.md` and `docs/DETAIL.zh.md` ship in the tarball; without `meta.detail` the host falls back to the README.
120
124
 
@@ -140,22 +144,20 @@ Worth knowing before you look for them:
140
144
  | Built-in set | 85 curated templates generated from the `agents/` role library. The dropdown falls back to them when `templates` is unset |
141
145
  | Insertion | Uses the input box's version-checked insert face (`captureInsertion()` + `insertText()`). Text goes in at the caret, quoted blocks and attachments stay intact, and a stale insertion inserts nothing |
142
146
  | "Unset" is an empty array | Under implicit registration schemastery casts a missing array field to `[]`, so **an empty list always means "fall back to built-in"**. Only a non-empty array whose items are all invalid renders as an empty list |
143
- | Restore defaults | Unsets `templates` back to the curated set and leaves `importAllowRoots` untouched. Two-step confirm; the second click must come within 4 seconds |
144
- | Import | By path: a local `.md` file or a directory. `path` exactly empty imports the whole built-in library. A role file whose code fence never closes is rejected instead of silently importing half its body |
147
+ | Restore defaults | Unsets `templates` back to the curated set and leaves `importAllowRoots` untouched. Two-step confirm |
148
+ | Import | By path: a local `.md` file or a directory. `path` exactly empty imports the built-in library's top level plus one sub-directory level. A role file whose code fence never closes is rejected instead of silently importing half its body |
145
149
 
146
150
  ## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Settings
147
151
 
148
- Namespace `dir-prep-organize` equals the settings entry id. Fields projected into the settings form are the `.volatile()` ones.
152
+ Settings live on the **dir-prep-organize** card in the plugin detail page. The card is the configuration reference for its editable lists: placeholders, tooltips, section notes and the shared save bar explain the controls where help exists. This README does not duplicate that field-level guidance.
153
+
154
+ The namespace and settings entry id are both `dir-prep-organize`; values persist in `settings.yaml` under the dsh data directory. Edits stage locally and take effect after **Save**. Saved template and allowed-root lists are read again on later actions, so they do not require a host restart.
155
+
156
+ `importAllowRoots` is an explicit trust list, not a placeholder. It accepts absolute directories only; relative paths and `~` are dropped, trailing separators are normalized, and duplicates are removed. An empty list adds nothing. Because the card has no session context, its imports can use only the bundled `agents/` library and registered roots; an endpoint call with a session also allows that session's active working directory. `.` / `..` and hidden path segments remain refused.
149
157
 
150
- | Field | Type | Default | Card control | Notes |
151
- |---|---|---|---|---|
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's active working directory and the built-in role library are allowed |
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
- | `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
- | `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 |
158
+ `organizeTimeoutMs` stays off-card. It defaults to `120000` ms, is read per request as the host's abort deadline, and gives the client fetch timeout a further 5000 ms. Values are truncated and clamped to `[1, 2147483647]`; non-finite values fall back to the default. Set it in `settings.yaml` or the plugin row's `config:` block. `maxSnippetBytes` (`262144`) and `readConcurrency` (`8`) are also off-card deployment values; they take effect on restart, and read concurrency is clamped to `[1, 64]`.
157
159
 
158
- Settings are persisted in `settings.yaml` under the dsh data directory.
160
+ **Conservative refusals and ways out.** A stale-write message means the input changed while the request was in flight; retry from the current draft, because there is no force-overwrite path. An import refusal means the target is outside the explicit trust boundary; register its absolute directory and save. Missing key-file text may be deliberate: sensitive names are never selected, while symlink escapes, unreadable files and size or budget skips are reflected in `skipped` / `truncated`. Do not treat the directory listing as complete content. If a role style is a poor fit, choose direct polish or another role.
159
161
 
160
162
  ## <img src="https://api.iconify.design/lucide/network.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Public interface
161
163
 
@@ -167,7 +169,7 @@ Official Typert Remote namespace **`dirPrepOrganize`**, registered through an in
167
169
  | `context` | `{ sessionId }` | `ok` / `cwd` / `truncated` / `skipped` / `entries[{name,isDir,sizeBytes,snippet}]` |
168
170
  | `model` | `{ sessionId }` | `ok` / `provider` / `model` / `reasoningEffort` |
169
171
  | `organize` | `{ sessionId, prompt, entriesSummary, roleText? }` | `ok` / `content` |
170
- | `importTemplates` | `{ path, sessionId }` (`path` exactly empty = whole built-in library) | `ok` / `count` / `truncated` / `skipped` / `entries` |
172
+ | `importTemplates` | `{ path, sessionId }` (`path` exactly empty = built-in library, top level plus one sub-directory level) | `ok` / `count` / `truncated` / `skipped` / `entries` |
171
173
 
172
174
  - Business failures stay `ok:false` with `error`. The import path-policy branches are the exception: an out-of-bounds path or a malformed `path` field also carries `status` 403 or 400.
173
175
  - `model` is the preflight read of the default selection; `organize` prefers the live agent's selection as described under "The polish call".
package/README.zh-CN.md CHANGED
@@ -12,7 +12,7 @@
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
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" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.3--alpha.3-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
 
@@ -61,7 +61,7 @@
61
61
  - 这张表**只在宿主侧**:客户端产物不再内联它。生成文件约 640 KB,曾把 `client.js` 推到约 711 KB。
62
62
  - 浏览器**懒加载、只调一次** Remote 的 `defaults` 方法(首次打开菜单或首次进设置卡),之后在进程内复用。用户已经有自己的模板时**一个字节都不拉**。
63
63
  - 数据还没到时菜单显示一行 loading,而不是「没有模板」那句提示;失败时把宿主自己的原因和「重试」按钮一起显示出来。
64
- - 设置卡的**「角色库」**小节覆盖:逐条增/改/删、两步恢复默认、一键导入整套内置库、按路径导入本地 `.md` 或目录、登记额外的允许导入目录。这个小节是**一份列表同时喂两处**——输入框「模板」下拉,与「润色」▾ 的角色菜单。
64
+ - 设置卡的**「角色库」**小节覆盖:逐条增/改/删、两步恢复默认、一键导入内置库(顶层 + 一层子目录)、按路径导入本地 `.md` 或目录、登记额外的允许导入目录。这个小节是**一份列表同时喂两处**——输入框「模板」下拉,与「润色」▾ 的角色菜单。
65
65
  - 模板与允许目录都经宿主设置读写,**零 LLM 调用**,且**不注册任何模型工具**。
66
66
 
67
67
  ## <img src="https://api.iconify.design/lucide/package.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 安装
@@ -74,13 +74,12 @@ 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.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
- - **`dependencies` 里不放任何 `@deepseek-ai/*`,这是约定**(`test/publish-manifest.test.ts` 钉着)。消费方 profile 用 `nodeLinker: hoisted` 且 `autoInstallPeers: false` 安装,于是写在 `dependencies` 里的宿主包会被落成**真实目录**,与运行中的宿主已加载的那份并存。`@deepseek-ai/dsh-tools` 的工具运行期调度键是普通 `Symbol`(不是 `Symbol.for`),符号身份按模块实例算:宿主从 profile 副本上读那个键拿到 `undefined`,于是**每一次原生工具调用都抛**——而本包的构建、类型检查、覆盖率检查在此之前全部照绿。
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
- - **声明里点到的每一枚宿主包都落在 `peerDependencies`**,凡是只能从那里到达的都是 *optional*(`@deepseek-ai/cordis`、`cosmokit`,以及 `dsh-agent-default-model` / client-ui / `fs` / `llm` / `session` 那一族)。声明它们不是仪式:pnpm 严格布局下,`types/host.d.ts` 里一枚没有被任何 manifest 表点名的裸说明符在消费方侧解析不到,而本仓自己的类型检查照样绿。那条清单由测试从 `types/**/*.d.ts` 现量读,不从这段文字读,所以两边不会漂移。
83
- - **随包发的东西**:`host.js`、`client.js`、`templates.data.mjs`、`types/`、`cordis.patch.yml`、`agents/`、`locale/`、`docs/` 与 `THIRD_PARTY_NOTICES.md`。`package.json`、`README*` 与 `LICENSE` 由发布器无条件附带。
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'`。`engines.node` 跟随宿主下限;宿主跑不起来的 Node,安装器也会拒掉。
78
+ - **要求宿主 `dsh` 在 `0.2.3-alpha.3` 这条宿主线上或更晚。** 宿主真正读的是 `engines.dsh`(`^0.2.3-alpha.3`),而且它**单独决定**:`evaluatePluginCompatibility` 在 `engines.dsh` 那一支就返回了,根本走不到读 `peerDependencies` 的那段。按宿主装载门的判定谓词(`app-boot` 的 `satisfies`,带 `includePrerelease: true`):`0.2.3-alpha.3`、其后低于 `0.3.0` 的正式版与 `0.2.3` 元组内的预发布通过;`0.2.2` 及更早与 `0.3.0` 及以后都被拒;更高 `0.2.x` 元组的预发布(如 `0.2.4-rc.1`)同样满足。被拒的宿主需要走显式担责的授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时把窗口内的每个已发布宿主版本逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
79
+ - **`@deepseek-ai/dsh-*` 的开发依赖钉在 `0.2.3-alpha.3`**——本包编译与测试所对着的那条宿主线。`engines.dsh` 与 optional peer 范围承载单独判读的支持窗口(`^0.2.3-alpha.3`);钉版是关于「它是对着哪个宿主版本**编译**的」的事实,不是那个窗口的复述。把两者混为一谈,正是发布门禁分开检查它们的原因。
80
+ - **`dependencies` 里不放任何 `@deepseek-ai/*`,这是约定**(`test/publish-manifest.test.ts` 钉着)。消费方 profile 用 `nodeLinker: hoisted` 且 `autoInstallPeers: false` 安装,于是写在 `dependencies` 里的宿主包会被落成**真实目录**,与运行中的宿主已加载的那份并存。`@deepseek-ai/dsh-tools` 的工具运行期调度键曾在宿主 `0.2.2` 线是普通 `Symbol`(不是 `Symbol.for`),符号身份按模块实例算(该调度键在 `0.2.3` 源码里已移除):宿主从 profile 副本上读那个键拿到 `undefined`,于是**每一次原生工具调用都抛**——而本包的构建、类型检查、覆盖率检查在此之前全部照绿。
81
+ - **`host.js` 按值导入的那三枚宿主包是必需 peer**:`@deepseek-ai/schemastery`(宿主 fork——只有它能把 `.volatile()` 字段解析成活引用)、`@deepseek-ai/dsh-brand` 与 `@deepseek-ai/dsh-typert-protocol`(Remote 的 Service 基类)。`build-host.mjs` 外部化 `dependencies` **与** `peerDependencies`,所以裸说明符留在产物里;只写 `devDependencies` 会让打包器把官方函数体内联进去。`test/build-host.test.ts` 同时钉「说明符在」与「函数体不在」。
82
+ - **随包发的东西**:`host.js`、`client.js`、`templates.data.mjs`、`cordis.patch.yml`、`agents/`、`locale/`、`docs/` 与 `THIRD_PARTY_NOTICES.md`。`package.json`、`README*` 与 `LICENSE` 由发布器无条件附带。
84
83
  - **内置表单独一个产物、首次使用时才加载**,不是插件装载时加载。它以前被打进 `host.js`,于是每个用户即使从不开那个下拉,也要在内存里付一份模板的代价。
85
84
  - **`agents/` 不是本仓写的**:来自 [`agency-agents-zh`](https://github.com/jnMetaCode/agency-agents-zh)(MIT)。版权与许可声明随包发在 `THIRD_PARTY_NOTICES.md` 里,因为 MIT 要求它出现在每一份分发副本中。**不要手改 `agents/` 下的任何文件。**
86
85
 
@@ -88,6 +87,8 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
88
87
 
89
88
  如果你的 profile 用 pnpm `overrides` 把 `@jayyuen66/dsh-plugin-shared` 钉在某个版本,那个值必须不低于本包声明的那一版。钉得更低会装到一份缺少运行期所导入名字的产物,宿主起来时报 `N entries did not activate` 与 `does not provide an export named ...`——包装得上、永远不生效,而各仓单仓 CI 看不见这一类。
90
89
 
90
+ bundle 顺序也会决定这件事:本包的 patch 插入 `dsh-plugin-shared` 行,并在 `dependencies` 声明 shared,所以这行加载本 bundle 自己 import 的那份。多个 bundle 插入同一个包名的行时,`dsh.profile.bundles` 里排在最前的那个决定它加载哪份;profile 自己的 `cordis.patch.yml` 里写同一包名的行则加载 profile 的那份。请让这行最终拿到的那份不低于本包声明的版本。本版起的客户端样式表(`meta.stylesheets`)与 `ProgressBar` 需要 shared `0.3.2` 或更晚;`^0.3.1` 的范围只为兼容旧插件,发布与单仓 CI 请以 `0.3.2` 作为实际下限。
91
+
91
92
  ## <img src="https://api.iconify.design/lucide/circle-check.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 确认它真的在工作
92
93
 
93
94
  1. **输入框右边出现两个控件。** 没出现就是装配层没挂上——用 `dsh --profile web --dump-config` 看有没有 `dir-prep-organize` 这一层。
@@ -104,6 +105,8 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
104
105
  - **它不注册任何模型工具。** 宿主半只 inject `settings`,从不碰工具注册表。没有 `organize_text` 这类工具可调。
105
106
  - **它没有自建的 HTTP 路由。** 数据那一栏是官方 Typert Remote 命名空间 `dirPrepOrganize`,经注入的子 fiber 注册,走宿主 `/api` 网关。认证、Host/DNS 重绑定/Origin判据、签名浏览器会话 cookie、body 上限全归网关——本包不持有 CSRF token,也没有路由表。
106
107
  - **它不加 CLI 子命令。**
108
+ - **它不要求装插件管理器。** 设置卡等的是 `plugins.bundle.config` 槽;没有那个槽时卡片不会出现,输入框旁的控件照常工作。
109
+ - **样式表由宿主 renderer 管理。** 构建时通过 `ModuleLoader` 元数据注册,客户端入口不再向 `document.head` 追加 `<style>` 元素。
107
110
  - **它不读任何环境变量**,也没有自己的出站请求。
108
111
  - 它**确实**消费的东西:宿主 `settings` 服务(硬注入,缺它条目根本不激活)、`llm.stream`、`agentDefaultModel`,以及会话、Agent 与文件系统服务。设置表单本身没就绪时,卡片禁用并显示状态提示,下拉回落到内置精选集。
109
112
 
@@ -114,7 +117,8 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
114
117
  - `conversation.input.right`——润色按钮(id `dir-prep-organize`,order 99)与模板下拉(id `dir-prep-organize-templates`,order 100)。
115
118
  - `plugins.bundle.config`——设置卡,按 **bundle 包名** `@jayyuen66/dsh-dir-prep-organize` 作 key。宿主派发 `entryKey: pkg.name`(唯一来源是 profile `package.json` 里的 `dsh.profile.bundles`),所以写成裸条目 id 永远匹配不上,卡片哪都不渲染。
116
119
  - 设置命名空间与 `configForms.get()` 仍是**裸条目 id** `dir-prep-organize`——与那个槽位 key 刻意不是同一个标识。
117
- - 客户端半是 `dsh.client.platform = web` 且带 `immediately`;`dsh.client.external` 声明 `@jayyuen66/dsh-plugin-shared/client`,供宿主把这条供应行排进启动图。
120
+ - 客户端半是 `dsh.client.platform = web`;它不是 `immediately` 行,因此不进启动预取层,bundle 随 Loader 条目到达。`dsh.client.external` 声明 `@jayyuen66/dsh-plugin-shared/client`,供宿主把这条供应行排进启动图。
121
+ - 卡片的 `Menu` / `RiskConfirmation` 来自 `@deepseek-ai/dsh-client-ui-primitives/client`;Web 组合把 `ui-slots`、`ui-primitives`、`ui-dockkit` 作为 `immediately` 行装载,`PLATFORM_MODULES` 为每个动态 bundle 提供这几个名字。组合里漏掉这几行时,卡片渲染不出来。
118
122
  - 卡片的文案遵循官方 locale 插件的偏好;宿主半每次请求现读该偏好,所以切语言不必重启。
119
123
  - 插件页的标题、说明与详情文档来自 `locale/<语言>.json`(`meta.title`、`meta.description`、`meta.detail`)。`docs/DETAIL.md` 与 `docs/DETAIL.zh.md` 随包发布;没有声明 `meta.detail` 时宿主才回落到 README。
120
124
 
@@ -140,22 +144,20 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
140
144
  | 内置集 | 从 `agents/` 角色库生成的 85 条精选模板。`templates` 未设置时下拉回落到它们 |
141
145
  | 插入 | 走输入框的版本校验插入接口(`captureInsertion()` + `insertText()`)。文本写到光标处,引用块与附件保持原样;凭据过期时什么都不插入 |
142
146
  | 「未设置」= 空数组 | 隐式注册下 schemastery 会把缺失的数组字段 cast 成 `[]`,所以**空列表永远意味着「回落到内置」**。只有非空数组且条目全部非法,才渲染成空列表 |
143
- | 恢复默认 | 把 `templates` 退回精选集,`importAllowRoots` 不动。两步确认,第二次点击须在 4 秒内 |
144
- | 导入 | 按路径:本地 `.md` 文件或目录。`path` 恰为空串 = 导入整套内置库。角色文件的代码围栏没有结束标记时直接拒绝,不会静默只导入半篇正文 |
147
+ | 恢复默认 | 把 `templates` 退回精选集,`importAllowRoots` 不动。两步确认 |
148
+ | 导入 | 按路径:本地 `.md` 文件或目录。`path` 恰为空串 = 导入内置库(顶层 + 一层子目录)。角色文件的代码围栏没有结束标记时直接拒绝,不会静默只导入半篇正文 |
145
149
 
146
150
  ## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 设置项
147
151
 
148
- 命名空间 `dir-prep-organize` 即设置条目 id。投影进设置表单的字段就是那几个 `.volatile()` 的。
152
+ 设置位于插件详情页的 **dir-prep-organize** 卡片。卡片是两份可编辑列表的配置说明:placeholder、tooltip、小节提示与统一保存条在有帮助的地方解释控件。本文不再复述字段级帮助。
153
+
154
+ 命名空间与设置条目 id 都是 `dir-prep-organize`,值持久化在 dsh 数据目录的 `settings.yaml`。改动先本地暂存,点**保存**后生效。已保存的模板与允许目录会在后续动作中重新读取,不需要重启宿主。
155
+
156
+ `importAllowRoots` 是显式信任列表,不是占位项。它只接受绝对目录;相对路径与 `~` 会被丢弃,末尾分隔符先归一再去重。列表为空表示不额外放行。设置卡没有会话上下文,因此卡上导入只能使用随包 `agents/` 与已登记目录;带会话调用的端点还允许该会话的活动工作目录。含 `.` / `..` 或隐藏段的路径仍被拒绝。
149
157
 
150
- | 字段 | 类型 | 默认值 | 卡上有控件 | 说明 |
151
- |---|---|---|---|---|
152
- | `templates` | `{id,name,description,text,group,emoji}[]` | 未设置 | **有** | 用户自己的模板。未设置时回落到 85 条内置 |
153
- | `importAllowRoots` | `string[]` | `[]` | **有** | 导入端点的额外允许根,逐个目录登记;非字符串与纯空白项丢弃,**相对路径与 `~` 同样丢弃**(host 按它自己的进程 cwd 解析它们,等于登记一条界面上看不出指向哪里的根),末尾分隔符归一后再去重——`/a` 与 `/a/` 是同一棵树,不该在卡上摆两行。一个都没登记时只允许会话活动工作目录与内置角色库 |
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
- | `maxSnippetBytes` | natural,非 volatile | `262144` | **无** | 关键文件摘要的单文件上限;超过、或大小未知的文件整份跳过并计入 `skipped.tooLarge`。导入候选用同一个上限。非 volatile 意味着不进表单快照,所以也没有卡上的行——纯部署值 |
156
- | `readConcurrency` | natural,非 volatile | `8` | **无** | 摘要与目录导入的有界读并发。夹在 `[1, 64]`:`0` 或负数会让那套有界 map 自我递归直到宿主被 OOM killer 杀掉,而过大的值直接废掉这个字段存在的意义(fd 上限) |
158
+ `organizeTimeoutMs` 留在卡外。默认 `120000` ms,每次请求现读,作为宿主的 abort 时限;客户端 fetch 超时再留 5000 ms。取值先取整再夹到 `[1, 2147483647]`,非有限数回落默认值。修改位置是 `settings.yaml` 或插件注册行的 `config:` 块。`maxSnippetBytes`(`262144`)与 `readConcurrency`(`8`)同样留在卡外,随重启生效;读并发夹在 `[1, 64]`。
157
159
 
158
- 设置持久化在 dsh 数据目录下的 `settings.yaml`。
160
+ **保守拒绝与出路。** 过期写入提示表示请求途中输入已变;请从当前草稿重试,没有强制覆盖路径。导入被拒表示目标不在显式信任边界内;登记它的绝对目录并保存。关键文件正文缺失可能是刻意行为:敏感文件名永不入选,符号链接越界、读取失败以及大小或总量预算跳过会反映在 `skipped` / `truncated`。不要把目录列表当成完整内容。角色风格不合适时,改用直接润色或另一个角色。
159
161
 
160
162
  ## <img src="https://api.iconify.design/lucide/network.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 对外接口
161
163
 
@@ -167,7 +169,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
167
169
  | `context` | `{ sessionId }` | `ok` / `cwd` / `truncated` / `skipped` / `entries[{name,isDir,sizeBytes,snippet}]` |
168
170
  | `model` | `{ sessionId }` | `ok` / `provider` / `model` / `reasoningEffort` |
169
171
  | `organize` | `{ sessionId, prompt, entriesSummary, roleText? }` | `ok` / `content` |
170
- | `importTemplates` | `{ path, sessionId }`(`path` 恰为空串 = 整套内置库) | `ok` / `count` / `truncated` / `skipped` / `entries` |
172
+ | `importTemplates` | `{ path, sessionId }`(`path` 恰为空串 = 内置库,顶层 + 一层子目录) | `ok` / `count` / `truncated` / `skipped` / `entries` |
171
173
 
172
174
  - 业务失败一律 `ok:false` 带 `error`。导入路径策略那几支是例外:越界路径或形状不对的 `path` 还会额外带 `status` 403 或 400。
173
175
  - `model` 只是对默认选择的预检;`organize` 优先用会话活 Agent 的选择,见「润色调用」。
@@ -47,8 +47,10 @@ SOFTWARE.
47
47
  ## 运行期依赖
48
48
 
49
49
  运行期依赖的许可由各自包随包分发,本包不再重复其文本:`@deepseek-ai/cosmokit`、
50
- `@deepseek-ai/dsh-brand`、`@deepseek-ai/schemastery`、`@jayyuen66/dsh-plugin-shared`、`zod`。
50
+ `@deepseek-ai/dsh-brand`、`@deepseek-ai/dsh-typert-protocol`、`@deepseek-ai/schemastery`、
51
+ `@deepseek-ai/dsh-output-retention`(shared 的文本模块在运行期按值导入它)、
52
+ `@jayyuen66/dsh-plugin-shared`、`zod`。
51
53
  `zod` 由设置卡的 `src/remote.ts` 以值引入(strict codec 的形状校验),client 产物按宿主
52
54
  `PLATFORM_MODULES` 保持 `require("zod")` 外部化。
53
- 其中 `@deepseek-ai/cosmokit` 仅出现在本包发布的类型声明里——schemastery 的 `Schema` 类型
54
- 把 `Dict` 取自 cosmokit,声明文件点名它就必须让它可解析,故列为运行期依赖而非开发依赖。
55
+ 其中 `@deepseek-ai/cosmokit` 只作为类型解析出现——schemastery 的 `Schema` 类型把 `Dict`
56
+ 取自 cosmokit;本包不按值导入它,但 typecheck 解析这条类型时需要它,故留在 peer/dev 的类型供应里。
package/client.js CHANGED
@@ -1,44 +1,14 @@
1
- // GENERATED by buildClient() in build-client.mjs — edit src/client-entry.ts, then run `node build-client.mjs`.
1
+ // GENERATED by buildClient() in build-client.mjs — edit src/*.ts, then run `node build-client.mjs`.
2
2
  window.__ModuleLoader__.load({
3
3
  id: "@jayyuen66/dsh-dir-prep-organize",
4
+ meta: () => ({ stylesheets: { "src/client-styles.ts": { text: () => ".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}\n.dpi-btn:hover:not(:disabled){border-color:var(--dsw-alias-border-l3,currentColor);background:var(--dsw-alias-interactive-bg-hover,transparent)}\n.dpi-btn:disabled{opacity:.55;cursor:not-allowed}\n.dpi-btn:disabled[data-state=\"loading\"]{cursor:progress}\n.dpi-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,currentColor);outline-offset:1px}\n.dpi-btn svg{width:14px;height:14px;flex:none}\n.dpi-btn-err{border-color:var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-secondary,currentColor)}\n.dpi-btn-err:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor)}\n.dpi-spin{animation:dpi-rotate .8s linear infinite}\n@keyframes dpi-rotate{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn{transition:none}}\n.dpi-wrap{position:relative;display:inline-flex;isolation:isolate}\n.dpi-caretWrap{display:inline-flex}\n.dpi-polish-menu{width:280px}\n.dpi-split{display:inline-flex;align-items:stretch}\n.dpi-split .dpi-main{border-top-right-radius:0;border-bottom-right-radius:0;padding-right:10px}\n.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}\n.dpi-split .dpi-caret svg{width:16px;height:16px;display:block;flex:none}\n.dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}\n.dpic-name{flex:1;min-width:0}\n.dpic-rowhead .dpic-name{width:auto}\n.dpic-rowhead .dpic-emoji{width:44px;flex:none;text-align:center}\n.dpic-rowhead .dpic-group{width:84px;flex:none}\n.dpic-desc{width:100%;margin-top:6px}\n.dpic-text{width:100%;margin-top:6px}\n.dpic-importpath{flex:1;min-width:0}\n.dpic-rowhead .dpic-importpath{width:auto}\n.dpic-del{flex:none}\n.dpic-toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:8px 0}\n.dpic-rowhead{display:flex;gap:8px;align-items:center}\n.dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);flex:none;min-width:26px}\n.dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}" } } }),
4
5
  factory: (require) => {
5
6
  'use strict';
6
7
  const module = { exports: {} };
7
8
  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,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
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@deepseek-ai/dsh-client-ui-primitives/client"),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){if(typeof e!=`object`||!e)return!1;try{return!Array.isArray(e)}catch{return!1}}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,b=12e4;function x(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function S(e){let t=e.organizeTimeoutMs;return x(t)?(0,n.clampInt)(t,1,y,1):void 0}function C(e){let t=x(e)?e:b;return(0,n.clampInt)(Math.min(t,0x7fffec77)+5e3,1,y,b)}const w={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}`,builtinBadPayload:`内置模板响应不是合法载荷`,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 built-in role library (top level plus one sub-directory level); 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 {count} entries from the built-in role library (top level plus one sub-directory level){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 the built-in role library (top level plus one sub-directory level); or a .md / directory path (must be inside an allowed root)`,importAriaPath:`Role import path`,importBtnTitle:`Empty imports the built-in role library in one click (top level plus one sub-directory level); 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 built-in role library (agents/, top level plus one sub-directory level); 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}`,builtinBadPayload:`The built-in template response is not a valid payload`,builtinRetry:`Retry`}};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 ee(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 D=`dirPrepOrganize`,O=`remote.${D}`,k=`@jayyuen66/dsh-dir-prep-organize`,A=`session request requires a string sessionId`,te=r.z.object({sessionId:r.z.string({error:A})},{error:A}),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(0,n.parseOrThrow)(te,e,r.z.prettifyError)}})},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=(0,n.parseOrThrow)(ne,e,r.z.prettifyError);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(0,n.parseOrThrow)(re,e,r.z.prettifyError)}})}}],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=(0,n.remoteMounterOf)(e,!1);return t===void 0?void 0:ce(e,t)}const N=`dir-prep-organize`,P=125e3,F=`dpic-rowhead`,I=`dpic-importpath`,L=`conversation.input.right`,ue=`conversation.input.placeholder`;function de(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 R(e,t){let n=e[t];return typeof n==`string`?n:void 0}function z(e,t){return e===void 0?{}:{[t]:e}}function fe(e){return[[`skipDeeper`,e.deeper],[`skipTooLarge`,e.tooLarge],[`skipUnreadable`,e.unreadable],[`skipUnnamed`,e.unnamed],[`skipEscaped`,e.escaped]]}function pe(e){let t=(0,n.isRecord)(e)?e:{},{ok:r,truncated:i,entries:a}=t,o=Array.isArray(a)?a.map(e=>de(e)):void 0;return{ok:r===!0,...z(R(t,`error`),`error`),...z(R(t,`cwd`),`cwd`),...i===!0?{truncated:!0}:{},...o===void 0?{}:{entries:o}}}function me(e){let t=(0,n.isRecord)(e)?e:{};return{ok:t.ok===!0,...z(R(t,`error`),`error`),...z(R(t,`provider`),`provider`),...z(R(t,`model`),`model`),...z(R(t,`reasoningEffort`),`reasoningEffort`)}}function he(e){let t=(0,n.isRecord)(e)?e:{};return{ok:t.ok===!0,...z(R(t,`error`),`error`),...z(R(t,`content`),`content`)}}function B(e){return typeof e==`number`&&e>0?e:0}function ge(e){return{tooLarge:B(e.tooLarge),unreadable:B(e.unreadable),deeper:B(e.deeper),unnamed:B(e.unnamed),escaped:B(e.escaped)}}function _e(e,t){if(t===void 0)return``;let n=[];for(let[r,i]of fe(t))i>0&&n.push(e(r,{count:i}));return n.length===0?``:e(`skipSummary`,{list:n.join(e(`skipSeparator`))})}function ve(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:ge(o)}:{},...c===void 0?{}:{entries:c}}}function ye(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
10
  `,` `)}`),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(`远程读面不可用:宿主网关没有挂上 ${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
- .dpi-btn:disabled{opacity:.55;cursor:not-allowed}
13
- .dpi-btn:disabled[data-state="loading"]{cursor:progress}
14
- .dpi-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,currentColor);outline-offset:1px}
15
- .dpi-btn svg{width:14px;height:14px;flex:none}
16
- .dpi-btn-err{border-color:var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-secondary,currentColor)}
17
- .dpi-btn-err:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor)}
18
- .dpi-spin{animation:dpi-rotate .8s linear infinite}
19
- @keyframes dpi-rotate{to{transform:rotate(360deg)}}
20
- @media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn{transition:none}}
21
- .dpi-wrap{position:relative;display:inline-flex;isolation:isolate}
22
- .dpi-caretWrap{display:inline-flex}
23
- .dpi-polish-menu{width:280px}
24
- .dpi-split{display:inline-flex;align-items:stretch}
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}
28
- .dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}
29
- .dpic-name{flex:1;min-width:0}
30
- .dpic-rowhead .dpic-name{width:auto}
31
- .dpic-rowhead .dpic-emoji{width:44px;flex:none;text-align:center}
32
- .dpic-rowhead .dpic-group{width:84px;flex:none}
33
- .dpic-desc{width:100%;margin-top:6px}
34
- .dpic-text{width:100%;margin-top:6px}
35
- .dpic-importpath{flex:1;min-width:0}
36
- .dpic-rowhead .dpic-importpath{width:auto}
37
- .dpic-del{flex:none}
38
- .dpic-toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:8px 0}
39
- .dpic-rowhead{display:flex;gap:8px;align-items:center}
40
- .dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);flex:none;min-width:26px}
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;
11
+ `)}const V={phase:`idle`,list:[],error:``};let H=V,U=null,W=0;const G=new Set;function K(e){if(e===H)return H;H=e;for(let e of G)e();return e}let q;function J(){if(q===void 0)throw Error(`远程读面不可用:宿主网关没有挂上 ${D}`);return q}var Y=class extends Error{messageKey;params;constructor(e,t={}){super(e),this.name=`LocalizedOrganizeError`,this.messageKey=e,this.params=t}};async function X(e,t){return(0,n.raceTimeout)(e,t,()=>new Y(`organizeErrTimeout`))}async function Z(e=()=>w.zh.builtinBadPayload){if(H.phase===`ready`)return H;if(U!==null)return await U;let t=W;return U=(async()=>{K({phase:`loading`,list:H.list,error:``});let r;try{let t=await X(J().defaults(),P),i=(0,n.isRecord)(t)?t:void 0,a=i?.error;r=i?.ok===!0?{phase:`ready`,list:f(i.templates),error:``}:{phase:`error`,list:[],error:typeof a==`string`&&a.trim()!==``?a:e(`builtinBadPayload`)}}catch(e){r={phase:`error`,list:[],error:(0,n.errorText)(e)}}finally{W===t&&(U=null)}return W===t?K(r):r})(),await U}function be(e){return G.add(e),()=>{G.delete(e)}}function xe(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 Se(e,t,n,r){if(!e.ok)throw new Y(`organizeErrContextFailed`,{message:e.error??r});if(!t.ok||t.provider===void 0||t.model===void 0)throw new Y(`organizeErrModelFailed`,{message:t.error??r});if(n.trim().length===0)throw new Y(`organizeErrEmpty`)}async function Ce(e){let{ctxRes:t,prompt:n,sessionId:r,roleText:i,timeoutMs:a}=e,o=ye(t),s=he(await X(J().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 Y(`organizeErrUnknown`):Error(s.error);return s.content}async function we(e){let t=J(),[n,r]=await Promise.all([X(t.context(e.sessionId),P),X(t.model(e.sessionId),P)]),i=pe(n);return Se(i,me(r),e.prompt,e.unknownReason),Ce({ctxRes:i,prompt:e.prompt,sessionId:e.sessionId,roleText:e.roleText,timeoutMs:e.timeoutMs})}function Te(e){let{value:t,status:n,writable:r,revision:i}=e;return{value:t??{},ready:n===`ready`,writable:r,revision:i??0}}function Ee(e){return e.templates}function De(e){return e.importAllowRoots}function Oe(e){let t=null,n=H,r={templates:V.list,fromSettings:!1,builtinPhase:`idle`,builtinError:``,allowRoots:[],ready:!1,writable:!1,organizeTimeoutMs:void 0};return{getSnapshot(){let i=e.getSnapshot();if(i===t&&H===n)return r;t=i,n=H;let a=Te(i),o=Ee(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(De(a.value)),ready:a.ready,writable:a.writable,organizeTimeoutMs:S(a.value)},r},subscribe(t){let n=e.subscribe(t),r=be(t);return()=>{n(),r()}},readBack(){let t=Te(e.getSnapshot());return{ready:t.ready,revision:t.revision,templates:f(Ee(t.value)),allowRoots:v(De(t.value))}}}}function ke(e,t,r,i,a){let o,s=a?.treatEmptyAsReverted===!0&&t.templates.length===0&&r.length>0;return t.ready?!s&&!(0,n.formValueEquals)(t.templates,r)&&(o=e(`persistRejected`,{action:i,revision:t.revision})):o=e(`persistUnconfirmed`,{action:i}),o}function Ae(e,t,r,i){let a;return t.ready?(0,n.formValueEquals)(t.allowRoots,r)||(a=e(`persistRejected`,{action:i,revision:t.revision})):a=e(`persistUnconfirmed`,{action:i}),a}function je(e){return`${e.emoji===``?``:`${e.emoji} `}${e.name}`}function Me(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 Q(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 Ne(){return Object.fromEntries([[`cx`,7],[`cy`,7],[`r`,5.5],[`fill`,`none`],[`stroke`,`currentColor`],[`strokeWidth`,1.5],[`strokeDasharray`,`26 10`],[`strokeLinecap`,`round`]])}function Pe(){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 Fe(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0,className:`dpi-spin`},(0,t.createElement)(`circle`,Ne()))}function Ie(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,Q(`M3 3l8 8M11 3l-8 8`)))}function Le(){return(0,t.createElement)(`svg`,{width:14,height:14,viewBox:`0 0 14 14`,"aria-hidden":!0},(0,t.createElement)(`path`,Q(`M2.5 3.5h9M2.5 7h9M2.5 10.5h5.5`)))}function Re(){return(0,t.createElement)(`svg`,{width:16,height:16,viewBox:`0 0 16 16`,"aria-hidden":!0},(0,t.createElement)(`path`,Q(`M3 6l5 5 5-5`,!0)))}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 we({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 Y?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,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)(Re))}function Ue(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 We(e,n,r){return e===void 0?n?{icon:(0,t.createElement)(Fe),label:r(`organizeLoading`),state:`loading`}:{icon:(0,t.createElement)(Pe),label:r(`organizeIdle`),state:`idle`}:{icon:(0,t.createElement)(Ie),label:r(`organizeFailedShort`),state:`error`}}function Ge(){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=ee({sessionId:n.sessionId??``,actions:n.inputActions,draftRev:h,phase:g},{unavailable:n.t(Be),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 ze({t:n.t,loading:r,inFlight:d,seq:u,prompt:m,sessionId:n.sessionId??``,timeoutMs:C(_.organizeTimeoutMs),roleText:e,setLoading:a,setMenuOpen:l,setFailed:s,flashTimer:f,writeDraft:e=>{v.commit(e,t)}})}finally{v.finish(t)}}function b(){_.fromSettings||Z(n.t),l(e=>!e)}let x=We(o,r,n.t),S=T(n.inputActions),w=S&&g===`plain`,E=n.t(`organizeIdleTitle`);o===void 0?S?g!==`plain`&&(E=n.t(`organizeBusyTitle`)):E=n.t(Be):E=n.t(`organizeFailedTitle`,{message:o});let D={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:xe(_,n.t),loading:r,menuOpen:c,canWrite:w,templates:_.templates,onRun:y,onToggleMenu:b},O=Ue(D),k=He(D,p),A=(0,t.createElement)(e.Menu,{open:c,anchor:k,items:O,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,()=>{Z(n.t)})}});return(0,t.createElement)(`span`,{className:`dpi-wrap dpi-split`},Ve(D),A)}}function Ke(e,n){let{templates:r}=e,i=Me(r,n),a=[];if(r.length===0){let t=xe(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},je(n))})}return a}function qe(){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=Ke(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||Z(n.t),i(e=>!e)}},(0,t.createElement)(Le),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,()=>{Z(n.t)})&&i(!1)}})}}function Je(){let e;try{e=`tpl-${crypto.randomUUID()}`}catch{e=`tpl-${Date.now().toString(36)}-${Math.floor(Math.random()*1e9).toString(36)}`}return e}function Ye(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:F},s,c,l,u,d),f,p)}function Xe(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 Ye({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 Ze(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=ve(await X(J().importTemplates({path:t,sessionId:``}),P));if(!n.ok||n.entries===void 0)throw Error(n.error??r(`importFailedUnknown`));let i=n.entries.length,o=B(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=`${_e(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:`${I} 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`)),y=o?(0,t.createElement)(n.ProgressBar,{label:r(`importing`)}):null;return(0,t.createElement)(`div`,{className:`dpic-importrow`},(0,t.createElement)(`div`,{className:F},m,h),y,g,_,v)}function Qe(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:`${I} 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:F,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:`${I} 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:F},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 $e(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 et(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 tt(e,t){return{title:e(`rolesSection`),hint:e(`rolesHint`),count:e(`rolesCount`,{count:String(t)})}}function nt(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 rt(e,t){let n;return n=e.ready?e.writable?``:t(`statusReadOnly`):t(`statusNotReady`),n}function it(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:Je(),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 $(e,t,n,r,i){let a=ke(e,t,n,e(r),i);if(a!==void 0)throw Error(a)}function at(e,t,n){let r=Ae(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: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),$(t,m(),e,`save`)),a&&(await d(`importAllowRoots`,n),at(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 Z(t);if(e.phase!==`ready`)throw Error(e.error);await p(`templates`),$(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 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.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,tt(r,a.length),(0,t.createElement)(et,{foot:s,editable:c,busy:u,onAdd:h,onReset:f}),a.length===0?C:a.map((e,n)=>(0,t.createElement)(Xe,{key:e.id,t:r,index:n,template:e,disabled:!c||u,onCommit:p,onDelete:m})),(0,t.createElement)(Ze,{t:r,editable:c&&!u,onImported:g}),(0,t.createElement)(Qe,{t:r,roots:o,disabled:!c||u,onChangeRoot:_,onDeleteRoot:v,onAddRoot:y}),S),w)}function ct(e){let{t:r}=e,[i,a]=(0,t.useState)(!1),[o,s]=(0,t.useState)(``),[c,l]=(0,t.useState)(!1),u=nt(r),d=e.useCard(e=>e),{templates:f}=d,p=d.ready&&d.writable,m=rt(d,r);(0,t.useEffect)(()=>{d.fromSettings||Z(r)},[d.fromSettings,r]);let[h,g]=(0,t.useState)(f),[_,y]=(0,t.useState)(f);(0,t.useEffect)(()=>{_!==f&&(y(f),g(e=>(0,n.formValueEquals)(e,_)?f:e))},[f,_]);let[b,x]=(0,t.useState)(d.allowRoots),[S,C]=(0,t.useState)(d.allowRoots);(0,t.useEffect)(()=>{S!==d.allowRoots&&(C(d.allowRoots),x(e=>(0,n.formValueEquals)(e,S)?d.allowRoots:e))},[S,d.allowRoots]);let w=!(0,n.formValueEquals)(h,f),T=!(0,n.formValueEquals)(v(b),d.allowRoots),E=w||T,ee=it(r,h,b,g,x),D=ot({t:r,editable:p,dirty:w,rootsDirty:T,anythingDirty:E,templates:f,allowRoots:d.allowRoots,draft:h,rootsDraft:b,set:e.set,unset:e.unset,readBack:e.readBack,setDraft:g,setDraftFor:y,setRootsDraft:x,setBusy:l,setSaveError:s}),O=st({t:r,statusHint:m,draft:h,rootsDraft:b,foot:u,editable:p,anythingDirty:E,busy:c,saveError:o,onRequestReset:()=>{a(!0)},draftActions:ee,persistActions:D});return(0,t.createElement)(t.Fragment,null,O,i?(0,t.createElement)($e,{t:r,busy:c,onCancel:()=>{a(!1)},onConfirm:()=>{a(!1),D.onReset()}}):null)}const lt=[`slots`,`configForms`,`locale`];function ut(e,t,n){let r=()=>({hooks:{card:t}});e.slots.inject(L,()=>{let t=e.slots.register({name:L,id:N,order:99,label:()=>n(`dockOrganizeEntry`),locale:N,inject:r},Ge()),i=e.slots.register({name:L,id:`${N}-templates`,order:100,label:()=>n(`dockTemplatesEntry`),locale:N,inject:r},qe());return()=>{t(),i()}})}function dt(e,t){e.slots.inject(ue,()=>e.slots.register({name:ue,select:()=>!0,inject:()=>({t})},e=>e.t(`inputPlaceholder`)))}function ft(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);q=t,e.effect(()=>()=>{q===t&&(q=void 0)},`dir-prep-organize: remote reader`);let n=e.configForms.get(N),r=Oe(n);e.effect(()=>e.locale.register(N,w),`dir-prep-organize-card: locale dictionaries`);let i=e.locale.bind(N);ut(e,r,i),dt(e,i),ft(e,r,i,n)},exports.builtinTemplatesSnapshot=function(){return H},exports.formatContextSummary=ye,exports.formatImportSkips=_e,exports.inject=lt,exports.loadBuiltinTemplates=Z,exports.parseContextResponse=pe,exports.parseOrganizeResponse=he,exports.persistError=ke,exports.resetBuiltinTemplates=function(){W+=1,U=null,K(V)},exports.rootsPersistError=Ae,exports.setDirPrepReader=function(e){q=e},exports.subscribeBuiltinTemplates=be;
42
12
  return module.exports;
43
13
  },
44
14
  });