@jayyuen66/dsh-dir-prep-organize 0.1.7 → 0.1.8

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
@@ -3,6 +3,25 @@
3
3
  格式遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循
4
4
  [语义化版本](https://semver.org/lang/zh-CN/)。最新版本在最上。
5
5
 
6
+ ## 0.1.8
7
+
8
+ 一轮跨面审查修复:模板导入判据与解析收口,客户端超时与写回时序修正,CI 与发布链同步加固。
9
+
10
+ ### Changed
11
+
12
+ - **发布链加固**(`.github/workflows/publish.yml`):拆 build/publish 两 job,`id-token: write` 只留 publish job;预检补本包版本占用检查与全部 `catalog:` 依赖可见性遍历;tarball 打包一次经 artifact 传递,发布前校验身份一致且无 `catalog:`/`workspace:` 残留,发布后轮询 registry 至可见(上限 5 分钟)。CI 侧 actionlint 改按文件豁免,codeql/scorecard/dependabot 同步收口。
13
+ - **依赖与元数据**:author 改对象形(name+url);`@deepseek-ai/schemastery` peer 放宽为 `^3.18.6-alpha.1`;devDependencies 删孤儿 `@deepseek-ai/dsh-host-webserver`、新增 fast-check 4.10.2;catalog 的 shared 抬到 0.2.2。
14
+
15
+ ### Fixed
16
+
17
+ - **模板导入**(`host.ts`):导入失败的 promise 先清出缓存再重抛,读面 Retry 不再永远重放同一 rejection;单文件正文围栏未闭合按 `truncated` 记账不再让整次导入失败;多根命中按绝对路径长度降序逐个复判,cwd 内合法登记不再被判隐藏段越权;子目录加 `fs.contains` 复判,链接进根外的目录按 escaped 记账;`.md` 后缀大小写不敏感;导入允许根拒收相对路径并按 resolve 去重。
18
+ - **模板解析**(`src/templates.ts`):emoji 按 Unicode 码点截断不再劈开代理对;frontmatter 上限 20→200 行、缩进子键不再当顶层键;空 id 合并处理;`sanitizeAllowRoots` 只收绝对路径(POSIX/盘符/UNC)。
19
+ - **客户端超时与写回**(`src/client-timeouts.ts`、`src/input-writeback.ts`、`src/client-entry.ts`):fetch 超时先压 base 再加余量,配置顶格时客户端时限不再等于宿主时限;导入回执 count 坏值回落真实条数并追加 truncated 提示;保存往返期间用户的新输入不再被清洗结果覆盖;写回 commit 现判 sessionId/phase,组件卸载作废在途票据;润色超时抛本地化错误,英文界面不再见硬编码中文。
20
+
21
+ ### Added
22
+
23
+ - **测试三层**:`test/e2e/product-load.e2e.test.ts`(rolldown 产物原生 import 装载加真宿主服务链全链)、`test/platform/paths.platform.test.ts`(跨平台路径形状)、`test/property/import-policy.property.test.ts`(fast-check 属性面)。
24
+
6
25
  ## 0.1.7
7
26
 
8
27
  这一版让润色跟随会话当前的模型选择,把模板写入改成宿主校验的光标插入,并把插件页展示面收进包内。
@@ -19,8 +38,8 @@
19
38
  `CARD_UI_CSS` 与 `dsu-*` 控件类。
20
39
  - **Remote 参数校验改用 zod strict codec**:新增 `zod` 运行期依赖,client 产物按宿主 `PLATFORM_MODULES`
21
40
  外部化;`THIRD_PARTY_NOTICES` 同步补声明。
22
- - **宿主开发依赖抬到 `0.2.2-alpha.2`**:catalog、overrides 与 devDependencies 同值;`engines.dsh` 与
23
- peer 的支持窗口保持 `^0.2.1-rc.3`。
41
+ - **宿主开发依赖抬到 `0.2.2-alpha.2`**:overrides 与 devDependencies 同值(catalog 段不含宿主包);`engines.dsh` 与
42
+ peer 的支持窗口为 `^0.2.1-rc.3`,宿主按 `includePrerelease` 判该窗口。
24
43
  - **插件页展示元数据进包**:新增 `locale/en.json`、`locale/zh.json` 与 `docs/DETAIL.md`、`docs/DETAIL.zh.md`;
25
44
  `exports` 增加 `./locale/*.json`,`files` 收进 locale 与 docs。
26
45
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 JayYuen666
3
+ Copyright (c) 2026 JayYuen (JayYuen666)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,10 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
-
23
- ---
24
-
25
- 本文件覆盖本仓自身编写的代码(Copyright (c) 2026 JayYuen)。发布物中的内置角色库
26
- `agents/` 来自第三方项目 `agency-agents-zh`(MIT,版权归 Michael Sitarzewski 与
27
- jnMetaCode 所有)。MIT 的条款要求把该版权声明与许可声明随软件副本一并分发,其原文照录
28
- 于 [`THIRD_PARTY_NOTICES.md`](./THIRD_PARTY_NOTICES.md),该文件随本包一同发布。
package/README.md CHANGED
@@ -70,7 +70,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
70
70
  Remove with `dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`. The package is on the public npm registry, so installation needs no credentials and no scoped-registry line.
71
71
 
72
72
  - **Requires Node.js `>= 22.12`.** This is an ESM-only package. Use the **named** exports (`import { apply } from "@jayyuen66/dsh-dir-prep-organize"`); there is **no default export**, so `import pkg from …` fails with `does not provide an export named 'default'`. That Node floor is what makes `require()` of an ESM entry work at all, which is why `engines.node` is declared.
73
- - **Requires host `dsh` at the `0.2.1-rc.3` line.** The requirement the host actually reads is `engines.dsh` (`^0.2.1-rc.3`), and it **decides alone**: `evaluatePluginCompatibility` returns on the `engines.dsh` branch before it ever looks at `peerDependencies`. Measured against the real host code: `0.2.0-rc.2` is **refused**, `0.2.1-rc.3` and `0.2.2` pass, `0.3.0` is refused. A refused host needs the explicit risk grant `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`. The support window rolls: this package is verified against the three most recently released host versions at publish time and re-verified once the window moves, so the version number in this bullet is not a standing promise.
73
+ - **Requires host `dsh` in the `0.2.1-rc.3` → `0.2.2-alpha.2` window.** The requirement the host actually reads is `engines.dsh` (`^0.2.1-rc.3`), and it **decides alone**: `evaluatePluginCompatibility` returns on the `engines.dsh` branch before it ever looks at `peerDependencies`. Measured against the real host code: `0.2.0-rc.2` is **refused**, `0.2.1-rc.3` and `0.2.2` pass, `0.3.0` is refused. A refused host needs the explicit risk grant `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`. The support window rolls: this package is verified against the three most recently released host versions at publish time and re-verified once the window moves, so the version number in this bullet is not a standing promise.
74
74
  - **The `@deepseek-ai/dsh-*` development pins are at `0.2.2-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.1-rc.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.
75
75
  - **No `@deepseek-ai/*` under `dependencies`, by contract** (`test/publish-manifest.test.ts` enforces it). Consumer profiles install with `nodeLinker: hoisted` and `autoInstallPeers: false`, so a host package under `dependencies` is materialized as a **real directory** next to the copy the running host already loaded. `@deepseek-ai/dsh-tools` keys its tool-runtime scheduler with a plain `Symbol` (not `Symbol.for`), so symbol identity is per module instance: the host reads the scheduler off the profile copy, gets `undefined`, and **every native tool call throws** - while this package's build, typecheck and coverage gates stay green right up to that moment.
76
76
  - **The two host packages `host.js` imports as values are required peers**: `@deepseek-ai/schemastery` (the host's fork - only it resolves the `.volatile()` fields) and `@deepseek-ai/dsh-brand`. `build-host.mjs` externalizes `dependencies` **and** `peerDependencies`, so the bare specifiers stay in the artifact; a devDependencies-only entry would let the bundler inline the official function body. `test/build-host.test.ts` pins both "specifier present" and "function body absent".
package/README.zh-CN.md CHANGED
@@ -70,7 +70,7 @@ dsh plugin --profile web add @jayyuen66/dsh-dir-prep-organize
70
70
  卸载:`dsh plugin --profile web remove @jayyuen66/dsh-dir-prep-organize`。包在公共 npm 上,安装不需要凭据,也不需要配作用域源。
71
71
 
72
72
  - **要求 Node.js `>= 22.12`。** 本包是纯 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`。
73
- - **要求宿主 `dsh` 在 `0.2.1-rc.3` 这条线上。** 宿主真正读的是 `engines.dsh`(`^0.2.1-rc.3`),而且它**单独决定**:`evaluatePluginCompatibility` 在 `engines.dsh` 那一支就返回了,根本走不到读 `peerDependencies` 的那段。对宿主真实代码实测:`0.2.0-rc.2` **被拒**,`0.2.1-rc.3` 与 `0.2.2` 通过,`0.3.0` 被拒。被拒的宿主需要走显式担责的授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时最近的三个已发布宿主版本上逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
73
+ - **要求宿主 `dsh` 在 `0.2.1-rc.3` → `0.2.2-alpha.2` 窗口内。** 宿主真正读的是 `engines.dsh`(`^0.2.1-rc.3`),而且它**单独决定**:`evaluatePluginCompatibility` 在 `engines.dsh` 那一支就返回了,根本走不到读 `peerDependencies` 的那段。对宿主真实代码实测:`0.2.0-rc.2` **被拒**,`0.2.1-rc.3` 与 `0.2.2` 通过,`0.3.0` 被拒。被拒的宿主需要走显式担责的授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时最近的三个已发布宿主版本上逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
74
74
  - **`@deepseek-ai/dsh-*` 的开发依赖钉在 `0.2.2-alpha.2`**——本包编译与测试所对着的那条宿主线。`engines.dsh` 与 optional peer 范围承载单独判读的支持窗口(`^0.2.1-rc.3`);钉版是关于「它是对着哪个宿主版本**编译**的」的事实,不是那个窗口的复述。把两者混为一谈,正是发布门禁分开检查它们的原因。
75
75
  - **`dependencies` 里不放任何 `@deepseek-ai/*`,这是契约**(`test/publish-manifest.test.ts` 钉着)。消费方 profile 用 `nodeLinker: hoisted` 且 `autoInstallPeers: false` 安装,于是写在 `dependencies` 里的宿主包会被落成**真实目录**,与运行中的宿主已加载的那份并存。`@deepseek-ai/dsh-tools` 的工具运行期调度键是普通 `Symbol`(不是 `Symbol.for`),符号身份按模块实例算:宿主从 profile 副本上读那个键拿到 `undefined`,于是**每一次原生工具调用都抛**——而本包的构建、类型检查、覆盖率门禁在此之前全部照绿。
76
76
  - **`host.js` 按值导入的那两枚宿主包是必需 peer**:`@deepseek-ai/schemastery`(宿主 fork——只有它能把 `.volatile()` 字段解析成活引用)与 `@deepseek-ai/dsh-brand`。`build-host.mjs` 外部化 `dependencies` **与** `peerDependencies`,所以裸说明符留在产物里;只写 `devDependencies` 会让打包器把官方函数体内联进去。`test/build-host.test.ts` 同时钉「说明符在」与「函数体不在」。
@@ -1,9 +1,9 @@
1
1
  # Third-party notices
2
2
 
3
- 本包自身代码以 MIT 发布,见 [`LICENSE`](./LICENSE)。但发布物里并非全部内容都是本仓原创:
4
- 内置角色库 `agents/` 来自下面的第三方项目,且占发布体积的绝大部分。MIT 要求「上述版权声明与
5
- 本许可声明须包含在软件的所有副本或实质性部分中」,因此那一段必须随包发出——本文件就是它的
6
- 载体。
3
+ 本包自身代码以 MIT 发布(版权人 JayYuen (JayYuen666)),见 [`LICENSE`](./LICENSE)。
4
+ 但发布物里并非全部内容都是本仓原创:内置角色库 `agents/` 来自下面的第三方项目,且占发布
5
+ 体积的绝大部分。MIT 要求「上述版权声明与本许可声明须包含在软件的所有副本或实质性部分中」,
6
+ 因此那一段必须随包发出——本文件就是它的载体。
7
7
 
8
8
  ## 内置角色库 `agents/`
9
9
 
package/client.js CHANGED
@@ -18,18 +18,35 @@ function e$1(e) {
18
18
  * 为必填(空串表示未设置),保证下拉与设置卡无缺字段分支。 */
19
19
  /** 视觉标记进入下拉前缀的最大字符数。 */
20
20
  const EMOJI_MAX_LENGTH = 12;
21
+ /** 按 Unicode 码点截断:`String#slice` 数的是 UTF-16 码元,会把一个 emoji(代理对)或
22
+ * 组合字符劈成半个,落进模板后显示成空白方块。两个截断点(frontmatter 与设置卡草稿)
23
+ * 共用这一份实现,scripts/gen-defaults-lib.mjs 有同源镜像。 */
24
+ function truncateCodePoints(value, max) {
25
+ const points = Array.from(value);
26
+ return points.length > max ? points.slice(0, max).join("") : value;
27
+ }
28
+ /** id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加 `-<index>` 直到唯一)。
29
+ * 只负责取名,不登记 `seen`——登记由调用方在装配条目时按装配顺序做。 */
30
+ function uniqueEntryId(candidate, index, seen) {
31
+ if (candidate !== "" && !seen.has(candidate)) return candidate;
32
+ let id = `tpl-${index}`;
33
+ while (seen.has(id)) id = `${id}-${index}`;
34
+ return id;
35
+ }
21
36
  /**
22
37
  * 导入条目并入现有草稿:与既有 id 碰撞时确定性改写(追加 `-i` 直到唯一)。
23
- * 返回新数组(不改输入),保证 pre-save 阶段 React key 唯一(保存前的 id 去重,
24
- * sanitizeTemplateList 的确定性补 id 只兜底缺失/空,不负责碰撞改写)。
38
+ * 返回新数组(不改输入),保证 pre-save 阶段 React key 唯一。sanitizeTemplateList 对**存量
39
+ * 快照**同样按序号补 id(缺失/空/撞名三档都管),这边要额外做的是避开草稿里已有的 id
40
+ * ——两个入口各管一段,不靠对方兜底。
25
41
  */
26
42
  function mergeImportedTemplates(existing, incoming) {
27
43
  const ids = new Set(existing.map(({ id }) => id));
28
44
  const out = [...existing];
29
45
  for (const { id: baseId, ...rest } of incoming) {
30
- let id = baseId;
31
- if (ids.has(id)) {
32
- id = `${baseId}-i`;
46
+ let id = baseId.trim();
47
+ if (id === "") id = uniqueEntryId("", out.length, ids);
48
+ else if (ids.has(id)) {
49
+ id = `${id}-i`;
33
50
  while (ids.has(id)) id = `${id}i`;
34
51
  }
35
52
  ids.add(id);
@@ -40,26 +57,10 @@ function mergeImportedTemplates(existing, incoming) {
40
57
  }
41
58
  return out;
42
59
  }
43
- /** 任意来源(settings 快照 / 设置卡草稿)→ 合法模板列表(纯函数,测试锁死)。
44
- *
45
- * - 非数组输入 → [](调用方自行决定是否回落 DEFAULT_TEMPLATES);
46
- * - 剔除非对象条目与 name/text trim 后为空的条目;
47
- * - name/text/description/group 一律 trim;emoji trim 后截断至 12 字符;
48
- * - id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加
49
- * `-<index>` 直到唯一)——同输入同输出,可测试;
50
- * - 绝不修改输入(深比较测试锁死)。 */
51
60
  /** 字段 → trim 后的 string;非字符串一律 ""。 */
52
61
  function trimField(value) {
53
62
  return typeof value === "string" ? value.trim() : "";
54
63
  }
55
- /** id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加 `-<index>` 直到唯一)。
56
- * 只负责取名,不登记 `seen`——登记由调用方在装配条目时按装配顺序做。 */
57
- function uniqueEntryId(candidate, index, seen) {
58
- if (candidate !== "" && !seen.has(candidate)) return candidate;
59
- let id = `tpl-${index}`;
60
- while (seen.has(id)) id = `${id}-${index}`;
61
- return id;
62
- }
63
64
  /** 单条归一化:剔除坏条目/空 name|text;id 缺失或撞名 → 确定性补 tpl-<index>,
64
65
  * 返回 undefined 表示该条应被剔除。 */
65
66
  function normalizeEntry(item, index, seen) {
@@ -77,12 +78,19 @@ function normalizeEntry(item, index, seen) {
77
78
  description: trimField(description),
78
79
  text: nextText,
79
80
  group: trimField(group),
80
- emoji: trimField(emoji).slice(0, EMOJI_MAX_LENGTH)
81
+ emoji: truncateCodePoints(trimField(emoji), EMOJI_MAX_LENGTH)
81
82
  };
82
83
  }
83
84
  }
84
85
  return result;
85
86
  }
87
+ /** 任意来源(settings 快照 / 设置卡草稿)→ 合法模板列表(纯函数,测试锁死)。
88
+ *
89
+ * - 非数组输入 → [](调用方自行决定是否回落 DEFAULT_TEMPLATES);
90
+ * - 剔除非对象条目与 name/text trim 后为空的条目;
91
+ * - name/text/description/group 一律 trim;emoji trim 后按码点截断至 12 个字符;
92
+ * - id 缺失与已收集 id 撞名都由 uniqueEntryId 按序号补成唯一(同输入同输出,可测试);
93
+ * - 绝不修改输入(深比较测试锁死)。 */
86
94
  function sanitizeTemplateList(raw) {
87
95
  if (!Array.isArray(raw)) return [];
88
96
  const seen = /* @__PURE__ */ new Set();
@@ -99,12 +107,22 @@ function sanitizeTemplateList(raw) {
99
107
  * - 非数组 → [](未设置 = 一条都不登记,不是"全放行");
100
108
  * - 非字符串 / trim 后为空 → 丢弃(空串在 host 侧 path.resolve 会落到进程 cwd,
101
109
  * 绝不能让它变成一个隐式允许根);
110
+ * - **非绝对路径 → 丢弃**:契约是「额外允许的绝对目录」,相对项会被 host 按它自己的
111
+ * 进程 cwd 解析,等于登记了一条用户没写过、界面上也看不出指向哪里的允许根;
102
112
  * - 去重(同一目录登记两次没有额外语义,界面上也不该出现两行)。 */
113
+ /** 绝对路径形状(与 host 侧 path.isAbsolute 同口径的宽松版:POSIX 根、win32 盘符、UNC)。
114
+ * client 半跑在浏览器里,没有 node:path 可用,故按形状判。 */
115
+ const BACKSLASH = String.fromCodePoint(92);
116
+ const WIN_DRIVE_LETTER = /^[A-Za-z]:$/u;
117
+ function isAbsolutePath(value) {
118
+ const winDrive = WIN_DRIVE_LETTER.test(value.slice(0, 2)) && (value[2] === "/" || value[2] === BACKSLASH);
119
+ return value.startsWith("/") || winDrive || value.startsWith(BACKSLASH + BACKSLASH);
120
+ }
103
121
  function sanitizeAllowRoots(raw) {
104
122
  const out = [];
105
123
  if (Array.isArray(raw)) for (const item of raw) {
106
124
  const root = typeof item === "string" ? item.trim() : "";
107
- if (root !== "" && !out.includes(root)) out.push(root);
125
+ if (root !== "" && isAbsolutePath(root) && !out.includes(root)) out.push(root);
108
126
  }
109
127
  return out;
110
128
  }
@@ -119,6 +137,10 @@ const MAX_TIMER_MS = 2147483647;
119
137
  const ORGANIZE_TIMEOUT_FALLBACK_MS = 12e4;
120
138
  /** 客户端比 host 多等的余量:host 先超时,客户端留一点时间把它的回执读回来。 */
121
139
  const ORGANIZE_TIMEOUT_SLACK_MS = 5e3;
140
+ /** 配置投影值是否可当作毫秒数用(有限且 > 0;两处取表共用同一判据)。 */
141
+ function isUsableTimeoutMs(value) {
142
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
143
+ }
122
144
  /**
123
145
  * `organizeTimeoutMs` 的前端取表。
124
146
  *
@@ -130,7 +152,7 @@ const ORGANIZE_TIMEOUT_SLACK_MS = 5e3;
130
152
  */
131
153
  function rawOrganizeTimeoutMsOf(value) {
132
154
  const raw = value["organizeTimeoutMs"];
133
- return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? Math.min(Math.max(Math.trunc(raw), 1), MAX_TIMER_MS) : void 0;
155
+ return isUsableTimeoutMs(raw) ? Math.min(Math.max(Math.trunc(raw), 1), MAX_TIMER_MS) : void 0;
134
156
  }
135
157
  /**
136
158
  * 润色请求的客户端超时:host 的润色时限 + 余量,整条结果同样夹进 `[1, MAX_TIMER_MS]`。
@@ -142,7 +164,8 @@ function rawOrganizeTimeoutMsOf(value) {
142
164
  * @returns 可安全交给 setTimeout 的毫秒数
143
165
  */
144
166
  function organizeFetchTimeoutMs(raw) {
145
- return Math.trunc(Math.min(Math.max((typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : ORGANIZE_TIMEOUT_FALLBACK_MS) + ORGANIZE_TIMEOUT_SLACK_MS, 1), MAX_TIMER_MS));
167
+ const base = isUsableTimeoutMs(raw) ? raw : ORGANIZE_TIMEOUT_FALLBACK_MS;
168
+ return Math.trunc(Math.min(Math.max(Math.min(base, 2147478647) + ORGANIZE_TIMEOUT_SLACK_MS, 1), MAX_TIMER_MS));
146
169
  }
147
170
  // src/client-styles.ts
148
171
  const CARD_STYLES = [
@@ -223,6 +246,7 @@ const UI_MESSAGES = {
223
246
  importEmpty: "目录下没有符合条件的角色 .md(需含 name 的 frontmatter)",
224
247
  importAllDone: "已从内置角色库导入全部 {count} 条{skips},编辑后点「保存」生效",
225
248
  importFromDone: "已从 {path} 导入 {count} 条{skips},编辑后点「保存」生效",
249
+ importTruncated: "(回执标记本次导入有内容被上限截断)",
226
250
  importPlaceholder: "留空 = 导入内置全部角色;或填 .md / 目录路径(须在允许根内)",
227
251
  importAriaPath: "角色导入路径",
228
252
  importBtnTitle: "留空 = 一键导入内置全部角色;填路径 = 导入该 .md 或目录下的角色(路径须在允许根内)",
@@ -257,6 +281,7 @@ const UI_MESSAGES = {
257
281
  organizeErrContextFailed: "目录上下文读取失败:{message}",
258
282
  organizeErrModelFailed: "读取模型失败:{message}",
259
283
  organizeErrEmpty: "输入框为空,无内容可润色",
284
+ organizeErrTimeout: "润色请求超时:宿主没有在时限内回报结果",
260
285
  organizeErrUnknownReason: "未知错误",
261
286
  organizeErrUnknown: "润色失败(未知错误)",
262
287
  organizeCaretAria: "选择润色的角色风格",
@@ -314,6 +339,7 @@ const UI_MESSAGES = {
314
339
  importEmpty: "No qualifying role .md in that directory (frontmatter must contain name)",
315
340
  importAllDone: "Imported all {count} entries from the built-in role library{skips}; press \"Save\" after editing",
316
341
  importFromDone: "Imported {count} entries from {path}{skips}; press \"Save\" after editing",
342
+ importTruncated: " (the reply flagged some content as truncated by a limit)",
317
343
  importPlaceholder: "Empty = import every built-in role; or a .md / directory path (must be inside an allowed root)",
318
344
  importAriaPath: "Role import path",
319
345
  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)",
@@ -348,6 +374,7 @@ const UI_MESSAGES = {
348
374
  organizeErrContextFailed: "Failed to read the directory context: {message}",
349
375
  organizeErrModelFailed: "Failed to read the model: {message}",
350
376
  organizeErrEmpty: "The input box is empty; nothing to polish",
377
+ organizeErrTimeout: "Polish request timed out: the host did not reply in time",
351
378
  organizeErrUnknownReason: "unknown error",
352
379
  organizeErrUnknown: "Polish failed (unknown error)",
353
380
  organizeCaretAria: "Choose a role style to polish with",
@@ -530,6 +557,13 @@ function useWriteBack(input, messages) {
530
557
  if (ticket === void 0) return;
531
558
  if (ticket.sessionId !== input.sessionId || ticket.actions !== input.actions || input.phase !== "plain") ticket.invalidated = true;
532
559
  }, [input]);
560
+ (0, react.useEffect)(() => () => {
561
+ const ticket = active.current;
562
+ if (ticket !== void 0) {
563
+ ticket.invalidated = true;
564
+ active.current = void 0;
565
+ }
566
+ }, []);
533
567
  return {
534
568
  begin: () => {
535
569
  const ticket = {
@@ -545,9 +579,11 @@ function useWriteBack(input, messages) {
545
579
  if (active.current === ticket) active.current = void 0;
546
580
  },
547
581
  commit: (content, ticket) => {
548
- const { actions } = latest.current;
582
+ const live = latest.current;
583
+ const { actions } = live;
549
584
  if (!hasDraftFace(actions)) throw new Error(messages.unavailable);
550
- let liveRev = latest.current.draftRev;
585
+ if (ticket.sessionId !== live.sessionId || live.phase !== "plain") throw new Error(messages.stale);
586
+ let liveRev = live.draftRev;
551
587
  if (hasInsertFace(actions)) liveRev = actions.captureInsertion().draftRev;
552
588
  if (ticket.invalidated || liveRev !== ticket.draftRev) throw new Error(messages.stale);
553
589
  actions.setDraft(content);
@@ -887,11 +923,26 @@ function requireReader() {
887
923
  if (dirPrepReader === void 0) throw new Error(`远程读面不可用:宿主网关没有挂上 ${DIR_PREP_NAMESPACE}`);
888
924
  return dirPrepReader;
889
925
  }
926
+ /**
927
+ * 润色链路里由客户端自己产生的错误:messageKey 指向 ui-messages 的键,捕获侧用当前
928
+ * 语言的 t 渲染成 tooltip——把文案直接写进 Error.message 会让英文界面看到硬编码中文。
929
+ * 宿主回执携带的原文(ctxRes.error / modelRes.error)不翻译,作为 {message} 原样带出。
930
+ */
931
+ var LocalizedOrganizeError = class extends Error {
932
+ messageKey;
933
+ params;
934
+ constructor(messageKey, params = {}) {
935
+ super(messageKey);
936
+ this.name = "LocalizedOrganizeError";
937
+ this.messageKey = messageKey;
938
+ this.params = params;
939
+ }
940
+ };
890
941
  /** 客户端超时只影响等待:宿主侧的润色超时仍由它自己的 AbortController 收口。 */
891
942
  async function within(pending, timeoutMs) {
892
943
  const gate = Promise.withResolvers();
893
944
  const timer = setTimeout(() => {
894
- gate.reject(/* @__PURE__ */ new Error("请求超时"));
945
+ gate.reject(new LocalizedOrganizeError("organizeErrTimeout"));
895
946
  }, timeoutMs);
896
947
  try {
897
948
  return await Promise.race([pending, gate.promise]);
@@ -966,21 +1017,6 @@ function builtinStatusRow(snap, t) {
966
1017
  if (!snap.fromSettings && snap.builtinPhase !== "ready") row = snap.builtinPhase === "error" ? (0, react.createElement)("div", attrs, t("builtinFailed", { message: snap.builtinError }), retryButton) : (0, react.createElement)("div", attrs, t("builtinLoading"));
967
1018
  return row;
968
1019
  }
969
- /**
970
- * 润色链路里由客户端自己产生的错误:messageKey 指向 ui-messages 的键,捕获侧用当前
971
- * 语言的 t 渲染成 tooltip——把文案直接写进 Error.message 会让英文界面看到硬编码中文。
972
- * 宿主回执携带的原文(ctxRes.error / modelRes.error)不翻译,作为 {message} 原样带出。
973
- */
974
- var LocalizedOrganizeError = class extends Error {
975
- messageKey;
976
- params;
977
- constructor(messageKey, params = {}) {
978
- super(messageKey);
979
- this.name = "LocalizedOrganizeError";
980
- this.messageKey = messageKey;
981
- this.params = params;
982
- }
983
- };
984
1020
  function assertOrganizeReady(ctxRes, modelRes, prompt, unknownReason) {
985
1021
  if (!ctxRes.ok) throw new LocalizedOrganizeError("organizeErrContextFailed", { message: ctxRes.error ?? unknownReason });
986
1022
  if (!modelRes.ok || modelRes.provider === void 0 || modelRes.model === void 0) throw new LocalizedOrganizeError("organizeErrModelFailed", { message: modelRes.error ?? unknownReason });
@@ -1635,14 +1671,16 @@ function ImportPanel(props) {
1635
1671
  }), REMOTE_TIMEOUT_MS));
1636
1672
  if (!resp.ok || resp.entries === void 0) throw new Error(resp.error ?? t("importFailedUnknown"));
1637
1673
  const usable = resp.entries.length;
1638
- const count = Math.min(resp.count ?? usable, usable);
1674
+ const declared = countField(resp.count);
1675
+ const count = declared === 0 ? usable : Math.min(declared, usable);
1639
1676
  if (count === 0) {
1640
1677
  setImportError(t("importEmpty"));
1641
1678
  return;
1642
1679
  }
1643
1680
  props.onImported(resp.entries);
1644
1681
  setImportPath("");
1645
- const skipNote = formatImportSkips(t, resp.skipped);
1682
+ const truncatedNote = resp.truncated === true ? t("importTruncated") : "";
1683
+ const skipNote = `${formatImportSkips(t, resp.skipped)}${truncatedNote}`;
1646
1684
  setImportMsg(target.length === 0 ? t("importAllDone", {
1647
1685
  count,
1648
1686
  skips: skipNote
@@ -1863,8 +1901,8 @@ function createPersistActions(args) {
1863
1901
  verifyRootsPersisted(t, readBack(), nextRoots);
1864
1902
  }
1865
1903
  setBusy(false);
1866
- setDraft(next);
1867
- setRootsDraft(nextRoots);
1904
+ setDraft((prev) => prev === draft ? next : prev);
1905
+ setRootsDraft((prev) => prev === rootsDraft ? nextRoots : prev);
1868
1906
  } catch (error) {
1869
1907
  setBusy(false);
1870
1908
  reportError(error);
package/host.js CHANGED
@@ -166,8 +166,9 @@ function stripPairQuotes(value) {
166
166
  }
167
167
  /** frontmatter 键名形状:字母开头,随后字母/数字/下划线/连字符。 */
168
168
  const FRONTMATTER_KEY = /^[A-Za-z][\w-]*$/u;
169
- /** 头部只解析前 20 行键值对(防御恶意超长头部拖慢)。 */
170
- const FRONTMATTER_MAX_LINES = 20;
169
+ /** 头部只解析前 200 行键值对(防御恶意超长头部拖慢)。20 行会让带 tags/多行说明的
170
+ * 合法角色文件在后半段丢 name/description,整份被判成非角色文件。 */
171
+ const FRONTMATTER_MAX_LINES = 200;
171
172
  /** 视觉标记进入下拉前缀的最大字符数。 */
172
173
  const EMOJI_MAX_LENGTH = 12;
173
174
  /** 一行 frontmatter → `键 + 原样值`;无冒号 / 键名不合法 / 值为空 → 不算键值对。
@@ -186,13 +187,22 @@ function readFrontmatterPair(line) {
186
187
  }
187
188
  return result;
188
189
  }
189
- /** 键 → 目标位:防重复(已有值不覆盖,取首个同名键);emoji 截断至 EMOJI_MAX_LENGTH。 */
190
+ /** 按 Unicode 码点截断:`String#slice` 数的是 UTF-16 码元,会把一个 emoji(代理对)或
191
+ * 组合字符劈成半个,落进模板后显示成空白方块。两个截断点(frontmatter 与设置卡草稿)
192
+ * 共用这一份实现,scripts/gen-defaults-lib.mjs 有同源镜像。 */
193
+ function truncateCodePoints(value, max) {
194
+ const points = Array.from(value);
195
+ return points.length > max ? points.slice(0, max).join("") : value;
196
+ }
197
+ /** 键 → 目标位:防重复(已有值不覆盖,取首个同名键);emoji 截断至 EMOJI_MAX_LENGTH(按码点)。 */
190
198
  function takeFrontmatterField(fields, key, value) {
191
199
  if (key === "name" && fields.name === "" && value.length > 0) fields.name = value;
192
200
  else if (key === "description" && fields.description === "" && value.length > 0) fields.description = value;
193
- else if (key === "emoji" && fields.emoji === "") fields.emoji = value.slice(0, EMOJI_MAX_LENGTH);
201
+ else if (key === "emoji" && fields.emoji === "") fields.emoji = truncateCodePoints(value, EMOJI_MAX_LENGTH);
194
202
  }
195
- /** 从 frontmatter 头部解析 name/description/emoji(只解析前 20 行键值对,
203
+ /** 缩进行:属于嵌套映射(`metadata:` 下的 `name:` 之类),不是 frontmatter 顶层键。 */
204
+ const INDENTED_LINE = /^\s/u;
205
+ /** 从 frontmatter 头部解析 name/description/emoji(只解析前 FRONTMATTER_MAX_LINES 行键值对,
196
206
  * 防御恶意超长头部拖慢;防重复,取首个同名键)。 */
197
207
  function parseFrontmatterFields(head) {
198
208
  const fields = {
@@ -202,8 +212,10 @@ function parseFrontmatterFields(head) {
202
212
  };
203
213
  for (const [lineNum, rawLine] of head.split("\n").entries()) {
204
214
  if (lineNum >= FRONTMATTER_MAX_LINES) break;
205
- const pair = readFrontmatterPair(rawLine.trim());
206
- if (pair !== void 0) takeFrontmatterField(fields, pair.key, stripPairQuotes(pair.value));
215
+ if (!INDENTED_LINE.test(rawLine)) {
216
+ const pair = readFrontmatterPair(rawLine.trim());
217
+ if (pair !== void 0) takeFrontmatterField(fields, pair.key, stripPairQuotes(pair.value));
218
+ }
207
219
  }
208
220
  return fields;
209
221
  }
@@ -237,17 +249,7 @@ function parseAgentFrontmatter(text) {
237
249
  }
238
250
  return result;
239
251
  }
240
- /**
241
- * 角色正文提炼(导入 / 「按角色风格润色」共用):取叙述主干、去代码围栏。
242
- *
243
- * 规则(确定性,测试锁死):
244
- * - ``` 围栏行整体剔除(围栏内容多为长代码样例,对角色语境价值低);
245
- * - 行内反引号一并剔除——沿用"正文不含反引号、插入不破坏 markdown 围栏"不变式;
246
- * - 不设字符上限(用户拍板):全量保留叙述内容,避免截断影响
247
- * 「以角色风格润色」的上下文完整性;模型 context 超限由模型报错提示用户自行处理;
248
- * - 结果 trim;空正文(全围栏/全空白)→ 空串。
249
- */
250
- function condenseRoleBody(body) {
252
+ function tryCondenseRoleBody(body) {
251
253
  const lines = body.split(LINE_BREAK);
252
254
  const out = [];
253
255
  let inFence = false;
@@ -256,8 +258,10 @@ function condenseRoleBody(body) {
256
258
  fenceStart = inFence ? 0 : index + 1;
257
259
  inFence = !inFence;
258
260
  } else if (inFence) {} else out.push(raw.replaceAll("`", ""));
259
- if (inFence) throw new Error(`正文第 ${String(fenceStart)} 行的代码围栏没有结束标记(\`\`\`)`);
260
- return out.join("\n").trim();
261
+ return {
262
+ text: out.join("\n").trim(),
263
+ unclosedFenceLine: inFence ? fenceStart : void 0
264
+ };
261
265
  }
262
266
  // host.ts
263
267
  /** 本包送进 `llm.stream({ messages })` 的润色请求帧是 **request-only 输入**:它从不落
@@ -334,11 +338,19 @@ async function importDefaultTemplates() {
334
338
  * 静态导入会让整张精选表随宿主载入插件一起进内存,而它们只有一个消费者——default-templates
335
339
  * 读面,而客户端本来就是首次打开下拉时才拉这一发。两边都按需,才是同一件事的同一口径。
336
340
  *
341
+ * @param load - 载入器,缺省即真实 import 产物;单测靠它把「首读失败」那一档做成可复跑
342
+ * 的判据(产物 URL 一旦被成功加载就进 ESM 缓存,改磁盘内容对后续 import 无效,所以失败路径
343
+ * 只能从这一个缝注入)。
337
344
  * @returns 内置精选模板表
338
345
  */
339
- async function loadDefaultTemplates() {
340
- defaultTemplatesPromise ??= importDefaultTemplates();
341
- return defaultTemplatesPromise;
346
+ async function loadDefaultTemplates(load = importDefaultTemplates) {
347
+ defaultTemplatesPromise ??= load();
348
+ try {
349
+ return await defaultTemplatesPromise;
350
+ } catch (error) {
351
+ defaultTemplatesPromise = void 0;
352
+ throw error;
353
+ }
342
354
  }
343
355
  /** 关键文本扩展名(这些文件取首段摘要)。仅代码/文档/结构配置面;
344
356
  * yaml/env 等敏感配置不取摘要(凭据泄露风险,实测 .credentials.yaml 被带出)。 */
@@ -432,7 +444,7 @@ function isAgentsService(value) {
432
444
  return hasFnMember(value, "get");
433
445
  }
434
446
  function isFsService(value) {
435
- return hasFnMember(value, "resolve") && hasFnMember(value, "stat");
447
+ return hasFnMember(value, "resolve") && hasFnMember(value, "stat") && hasFnMember(value, "listDir") && hasFnMember(value, "readText") && hasFnMember(value, "contains");
436
448
  }
437
449
  function isLlmService(value) {
438
450
  return hasFnMember(value, "stream");
@@ -755,14 +767,16 @@ function importPathError(requested, cwd, allowRoots, messages) {
755
767
  if (!path.isAbsolute(trimmed) && cwd === void 0) return messages.relativeNeedsCwd;
756
768
  const absolute = path.resolve(cwd ?? "", trimmed);
757
769
  const roots = importRootsOf(cwd, allowRoots, messages);
758
- const matched = roots.find((root) => isWithinRoot(root.absolute, absolute));
759
- if (matched === void 0) return outsideRootsError(absolute, roots, messages);
760
- return pathTokensError(path.relative(matched.absolute, absolute), true, messages);
770
+ const matched = roots.filter((root) => isWithinRoot(root.absolute, absolute));
771
+ if (matched.length === 0) return outsideRootsError(absolute, roots, messages);
772
+ const errors = matched.toSorted((left, right) => right.absolute.length - left.absolute.length).map((root) => pathTokensError(path.relative(root.absolute, absolute), true, messages));
773
+ return errors.some((error) => error === void 0) ? void 0 : errors[0];
761
774
  }
762
775
  /** 角色文件 → 模板条目(正文提炼 + 目录分组标签 + 确定性 id 去重)。
763
776
  * 正文提炼不设字符上限。 */
764
777
  function agentEntryFromFile(slug, dirName, info, collided) {
765
- const text = condenseRoleBody(info.body);
778
+ const { text: condensedText, unclosedFenceLine } = tryCondenseRoleBody(info.body);
779
+ const text = unclosedFenceLine === void 0 ? condensedText : "";
766
780
  let result;
767
781
  if (text.length > 0) {
768
782
  let suffix = collided.size;
@@ -787,9 +801,19 @@ function agentEntryFromFile(slug, dirName, info, collided) {
787
801
  function isVisibleDirectory(child) {
788
802
  return child.type === "directory" && !child.name.startsWith(".");
789
803
  }
804
+ /** 扩展名是否 .md:不区分大小写。macOS 默认文件系统不区分大小写,`Agent.MD` 在用户看来
805
+ * 就是一份角色文件;按字节判后缀会把它静默丢在扫描面之外(且不计任何 skipped)。 */
806
+ function isMdName(name) {
807
+ return name.toLowerCase().endsWith(".md");
808
+ }
809
+ const MD_SUFFIX = /\.md$/iu;
810
+ /** 去掉 .md 后缀(大小写不敏感);没有该后缀时原样返回(replace 不命中即原样,无需分支)。 */
811
+ function stripMdSuffix(name) {
812
+ return name.replace(MD_SUFFIX, "");
813
+ }
790
814
  /** 目录项是「可见 .md 文件」?(候选收集与第三层清点同一判据,两处必须数到同一批)。 */
791
815
  function isVisibleMdFile(child) {
792
- return child.type === "file" && child.name.endsWith(".md") && !child.name.startsWith(".");
816
+ return child.type === "file" && isMdName(child.name) && !child.name.startsWith(".");
793
817
  }
794
818
  /** 一层目录内容 → 顶层 .md 候选(跳过隐藏项,按名排序保确定性)。
795
819
  * `skipped` 就地累加 escaped 计数:被 contains 拦下的链接文件如果不数出来,
@@ -874,9 +898,17 @@ async function importFromFile(args, absolute) {
874
898
  error: messages.missingRoleName
875
899
  };
876
900
  }
877
- const entry = agentEntryFromFile(path.basename(absolute, ".md"), path.basename(path.dirname(absolute)), info, /* @__PURE__ */ new Set());
901
+ const entry = agentEntryFromFile(stripMdSuffix(path.basename(absolute)), path.basename(path.dirname(absolute)), info, /* @__PURE__ */ new Set());
902
+ if (entry === void 0) {
903
+ skipped.unnamed += 1;
904
+ return {
905
+ entries: [],
906
+ truncated: true,
907
+ skipped
908
+ };
909
+ }
878
910
  return {
879
- entries: entry === void 0 ? [] : [entry],
911
+ entries: [entry],
880
912
  truncated: false,
881
913
  skipped
882
914
  };
@@ -924,7 +956,7 @@ function pushReadResult(read, entries, collided, skipped) {
924
956
  skipped.unnamed += 1;
925
957
  return;
926
958
  }
927
- const entry = agentEntryFromFile(path.basename(read.file.name, ".md"), read.file.dirName, read.info, collided);
959
+ const entry = agentEntryFromFile(stripMdSuffix(read.file.name), read.file.dirName, read.info, collided);
928
960
  if (entry === void 0) {
929
961
  skipped.unnamed += 1;
930
962
  return;
@@ -938,11 +970,16 @@ function pushReadResult(read, entries, collided, skipped) {
938
970
  async function importFromDirectory(fs, absolute, target, limits, skipped) {
939
971
  const rootChildren = await fs.listDir(target);
940
972
  const rootFiles = mdCandidates(fs, target, rootChildren, path.basename(absolute), skipped);
941
- const subScans = await mapBounded(rootChildren.filter((child) => isVisibleDirectory(child)).map((child) => child.target).toSorted((left, right) => left.displayPath.localeCompare(right.displayPath)), limits.readConcurrency, async (sub) => {
973
+ const subScans = await mapBounded(rootChildren.filter((child) => {
974
+ if (!isVisibleDirectory(child)) return false;
975
+ const inside = fs.contains(target, child.target);
976
+ if (!inside) skipped.escaped += 1;
977
+ return inside;
978
+ }).map((child) => child.target).toSorted((left, right) => left.displayPath.localeCompare(right.displayPath)), limits.readConcurrency, async (sub) => {
942
979
  const children = await listDirOrUnreadable(fs, sub, skipped);
943
980
  return {
944
981
  files: mdCandidates(fs, target, children, path.basename(sub.displayPath), skipped),
945
- deeper: children.filter((child) => isVisibleDirectory(child)).map((child) => child.target)
982
+ deeper: children.filter((child) => isVisibleDirectory(child) && fs.contains(target, child.target)).map((child) => child.target)
946
983
  };
947
984
  });
948
985
  const subFiles = [];
@@ -990,7 +1027,7 @@ async function collectAgentTemplates(fs, requested, cwd, messages, opts) {
990
1027
  error: outsideRootsError(target.displayPath, roots, messages)
991
1028
  };
992
1029
  }
993
- if (absolute.endsWith(".md")) return await importFromFile({
1030
+ if (isMdName(absolute)) return await importFromFile({
994
1031
  fs,
995
1032
  target,
996
1033
  limits,
@@ -1217,11 +1254,21 @@ const configShape = {
1217
1254
  const configSchema = Schema.object(configShape);
1218
1255
  /** volatile 引用读出的值 → importAllowRoots 字符串列表(纯函数,测试锁死)。
1219
1256
  * 引用背后可能是存量脏配置:非数组一律空表(fail-closed),非字符串/纯空白项逐个
1220
- * 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。 */
1257
+ * 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
1258
+ * 相对路径同样丢弃:契约写的是「额外允许的**绝对**目录」(见 schema describe 与 DETAIL
1259
+ * 文档),放进来会被 toImportRoot 的 path.resolve 按**宿主进程 cwd** 解析,变成一条用户
1260
+ * 没写过、也不知道存在着的允许根。 */
1221
1261
  function importAllowRootsOf(raw) {
1222
1262
  const roots = [];
1263
+ const seen = /* @__PURE__ */ new Set();
1223
1264
  if (Array.isArray(raw)) {
1224
- for (const item of raw) if (typeof item === "string" && item.trim().length > 0) roots.push(item.trim());
1265
+ for (const item of raw) if (typeof item === "string" && item.trim().length > 0 && path.isAbsolute(item.trim())) {
1266
+ const normalized = path.resolve(item.trim());
1267
+ if (!seen.has(normalized)) {
1268
+ seen.add(normalized);
1269
+ roots.push(normalized);
1270
+ }
1271
+ }
1225
1272
  }
1226
1273
  return roots;
1227
1274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayyuen66/dsh-dir-prep-organize",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "dsh 插件:对话输入框「润色」按钮(主键直接润色/▾ 以角色风格润色,结合当前目录 + session 模型润色草稿)+「模板」下拉(内置精选角色集生成自插件 agents/ 角色库,可按部门分组;设置卡可增删改/一键导入内置全部/导入本地角色 .md)",
5
5
  "keywords": [
6
6
  "cordis",
@@ -15,7 +15,10 @@
15
15
  "url": "https://github.com/JayYuen666/dsh-dir-prep-organize/issues"
16
16
  },
17
17
  "license": "MIT",
18
- "author": "JayYuen",
18
+ "author": {
19
+ "name": "JayYuen",
20
+ "url": "https://github.com/JayYuen666"
21
+ },
19
22
  "repository": {
20
23
  "type": "git",
21
24
  "url": "git+https://github.com/JayYuen666/dsh-dir-prep-organize.git"
@@ -58,7 +61,7 @@
58
61
  "registry": "https://registry.npmjs.org"
59
62
  },
60
63
  "dependencies": {
61
- "@jayyuen66/dsh-plugin-shared": "0.2.1",
64
+ "@jayyuen66/dsh-plugin-shared": "0.2.2",
62
65
  "zod": "4.6.7"
63
66
  },
64
67
  "devDependencies": {
@@ -78,7 +81,6 @@
78
81
  "@deepseek-ai/dsh-config-editor": "0.2.2-alpha.2",
79
82
  "@deepseek-ai/dsh-fs": "0.2.2-alpha.2",
80
83
  "@deepseek-ai/dsh-home-paths": "0.2.2-alpha.2",
81
- "@deepseek-ai/dsh-host-webserver": "0.2.2-alpha.2",
82
84
  "@deepseek-ai/dsh-launch-environment": "0.2.2-alpha.2",
83
85
  "@deepseek-ai/dsh-llm": "0.2.2-alpha.2",
84
86
  "@deepseek-ai/dsh-sandbox": "0.2.2-alpha.2",
@@ -95,6 +97,7 @@
95
97
  "eslint-plugin-regexp": "3.3.2",
96
98
  "eslint-plugin-sonarjs": "4.2.2",
97
99
  "eslint-plugin-zod": "5.2.2",
100
+ "fast-check": "4.10.2",
98
101
  "happy-dom": "21.0.4",
99
102
  "oxfmt": "0.75.0",
100
103
  "oxlint": "1.90.0",
@@ -121,7 +124,7 @@
121
124
  "@deepseek-ai/dsh-llm": "^0.2.1-rc.3",
122
125
  "@deepseek-ai/dsh-session": "^0.2.1-rc.3",
123
126
  "@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
124
- "@deepseek-ai/schemastery": "3.18.6-alpha.1"
127
+ "@deepseek-ai/schemastery": "^3.18.6-alpha.1"
125
128
  },
126
129
  "peerDependenciesMeta": {
127
130
  "@deepseek-ai/cordis": {
package/types/host.d.ts CHANGED
@@ -24,9 +24,12 @@ export declare function defaultTemplatesFrom(raw: unknown): readonly TemplateEnt
24
24
  * 静态导入会让整张精选表随宿主载入插件一起进内存,而它们只有一个消费者——default-templates
25
25
  * 读面,而客户端本来就是首次打开下拉时才拉这一发。两边都按需,才是同一件事的同一口径。
26
26
  *
27
+ * @param load - 载入器,缺省即真实 import 产物;单测靠它把「首读失败」那一档做成可复跑
28
+ * 的判据(产物 URL 一旦被成功加载就进 ESM 缓存,改磁盘内容对后续 import 无效,所以失败路径
29
+ * 只能从这一个缝注入)。
27
30
  * @returns 内置精选模板表
28
31
  */
29
- export declare function loadDefaultTemplates(): Promise<readonly TemplateEntry[]>;
32
+ export declare function loadDefaultTemplates(load?: () => Promise<readonly TemplateEntry[]>): Promise<readonly TemplateEntry[]>;
30
33
  /**
31
34
  * 把一个部署来的数夹进 `[min, max]`,非有限值回落到 `fallback`。
32
35
  *
@@ -381,7 +384,10 @@ export interface Config {
381
384
  export { configSchema as Config };
382
385
  /** volatile 引用读出的值 → importAllowRoots 字符串列表(纯函数,测试锁死)。
383
386
  * 引用背后可能是存量脏配置:非数组一律空表(fail-closed),非字符串/纯空白项逐个
384
- * 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。 */
387
+ * 丢弃——绝不能把非字符串塞进路径校验,也不能让空串变成"允许 process.cwd()"。
388
+ * 相对路径同样丢弃:契约写的是「额外允许的**绝对**目录」(见 schema describe 与 DETAIL
389
+ * 文档),放进来会被 toImportRoot 的 path.resolve 按**宿主进程 cwd** 解析,变成一条用户
390
+ * 没写过、也不知道存在着的允许根。 */
385
391
  export declare function importAllowRootsOf(raw: unknown): string[];
386
392
  /** 注入的服务面:settings 为硬依赖(cordis 等它就绪才 apply)。
387
393
  * 命名空间是隐式的(= 本条目在 cordis.patch.yml 里的裸 id,可编辑字段取自
@@ -46,13 +46,25 @@ export declare function parseAgentFrontmatter(text: string): AgentFileInfo | und
46
46
  * - 行内反引号一并剔除——沿用"正文不含反引号、插入不破坏 markdown 围栏"不变式;
47
47
  * - 不设字符上限(用户拍板):全量保留叙述内容,避免截断影响
48
48
  * 「以角色风格润色」的上下文完整性;模型 context 超限由模型报错提示用户自行处理;
49
- * - 结果 trim;空正文(全围栏/全空白)→ 空串。
49
+ * - 结果 trim;空正文(全围栏/全空白)→ 空串;
50
+ * - 围栏未闭合时**不抛**:把行号作为结果交出,由调用方决定是拒绝整份文件还是跳过它。
51
+ * 异常只由 `condenseRoleBody` 这一层抛(生成器要据此拒绝产出),导入读面拿到的是结果。
50
52
  */
53
+ export interface CondenseResult {
54
+ /** 清洗后的正文(围栏未闭合时是围栏起始行之前的那些行)。 */
55
+ text: string;
56
+ /** 未闭合围栏在正文里的行号(1 起);闭合完整时为 undefined。 */
57
+ unclosedFenceLine: number | undefined;
58
+ }
59
+ export declare function tryCondenseRoleBody(body: string): CondenseResult;
60
+ /** `tryCondenseRoleBody` 的严格形态:围栏未闭合时抛错,供生成器拒收畸形角色文件。
61
+ * 导入读面不用这一支——一份漏写结束围栏的文件不该让同目录其余角色全部失败。 */
51
62
  export declare function condenseRoleBody(body: string): string;
52
63
  /**
53
64
  * 导入条目并入现有草稿:与既有 id 碰撞时确定性改写(追加 `-i` 直到唯一)。
54
- * 返回新数组(不改输入),保证 pre-save 阶段 React key 唯一(保存前的 id 去重,
55
- * sanitizeTemplateList 的确定性补 id 只兜底缺失/空,不负责碰撞改写)。
65
+ * 返回新数组(不改输入),保证 pre-save 阶段 React key 唯一。sanitizeTemplateList 对**存量
66
+ * 快照**同样按序号补 id(缺失/空/撞名三档都管),这边要额外做的是避开草稿里已有的 id
67
+ * ——两个入口各管一段,不靠对方兜底。
56
68
  */
57
69
  export declare function mergeImportedTemplates(existing: readonly TemplateEntry[], incoming: readonly TemplateEntry[]): TemplateEntry[];
58
70
  /** 内置默认模板(独立开发者精选角色集,生成自插件内置 agents/ 目录)。
@@ -61,12 +73,12 @@ export declare function mergeImportedTemplates(existing: readonly TemplateEntry[
61
73
  * 全量角色可经设置页「导入角色」导入(路径留空 = 导入内置 agents/ 全部;显式路径
62
74
  * 受 host 的「cwd 内 + 内置角色目录 allowlist」策略约束)。 */
63
75
  export { DEFAULT_TEMPLATES } from "./default-templates.generated.js";
76
+ /** 任意来源(settings 快照 / 设置卡草稿)→ 合法模板列表(纯函数,测试锁死)。
77
+ *
78
+ * - 非数组输入 → [](调用方自行决定是否回落 DEFAULT_TEMPLATES);
79
+ * - 剔除非对象条目与 name/text trim 后为空的条目;
80
+ * - name/text/description/group 一律 trim;emoji trim 后按码点截断至 12 个字符;
81
+ * - id 缺失与已收集 id 撞名都由 uniqueEntryId 按序号补成唯一(同输入同输出,可测试);
82
+ * - 绝不修改输入(深比较测试锁死)。 */
64
83
  export declare function sanitizeTemplateList(raw: unknown): TemplateEntry[];
65
- /** 任意来源(settings 快照 / 设置卡草稿)→ 合法的「导入允许目录」列表(纯函数)。
66
- * host 的导入策略是「会话 cwd + 内置角色库 + importAllowRoots」,绝对路径默认拒绝,
67
- * 这里登记的每一项都是**放一个读盘口子**,故:
68
- * - 非数组 → [](未设置 = 一条都不登记,不是"全放行");
69
- * - 非字符串 / trim 后为空 → 丢弃(空串在 host 侧 path.resolve 会落到进程 cwd,
70
- * 绝不能让它变成一个隐式允许根);
71
- * - 去重(同一目录登记两次没有额外语义,界面上也不该出现两行)。 */
72
84
  export declare function sanitizeAllowRoots(raw: unknown): string[];
@@ -71,6 +71,8 @@ export interface UiMessages {
71
71
  readonly importAllDone: string;
72
72
  /** 导入成功(显式路径)。 */
73
73
  readonly importFromDone: string;
74
+ /** 回执带 truncated 标记时的追加说明(有内容因上限被跳过的总括)。 */
75
+ readonly importTruncated: string;
74
76
  /** 导入路径输入框的 placeholder。 */
75
77
  readonly importPlaceholder: string;
76
78
  /** 导入路径输入框的 aria-label。 */
@@ -139,6 +141,9 @@ export interface UiMessages {
139
141
  readonly organizeErrModelFailed: string;
140
142
  /** 润色前置检查失败:输入框为空。 */
141
143
  readonly organizeErrEmpty: string;
144
+ /** 润色请求超时(宿主端未在时限内回报)。 */
145
+ readonly organizeErrTimeout: string;
146
+ /** 没有会话 id 时「润色」不可用的 title 说明。 */
142
147
  /** 润色链路兜底:宿主回执没带 error 字段时给 {message} 的占位原因。 */
143
148
  readonly organizeErrUnknownReason: string;
144
149
  /** 润色回执整体不是对象时的兜底错误。 */