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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -1,12 +1,13 @@
1
1
  // GENERATED by buildClient() in build-client.mjs — edit src/client-entry.ts, then run `node build-client.mjs`.
2
2
  window.__ModuleLoader__.load({
3
- id: '@jayyuen66/dsh-dir-prep-organize',
3
+ id: "@jayyuen66/dsh-dir-prep-organize",
4
4
  factory: (require) => {
5
- var module = { exports: {} };
6
- var exports = module.exports;
5
+ 'use strict';
6
+ const module = { exports: {} };
7
+ let exports = module.exports;
7
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
9
  let react = require("react");
9
- //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_421050e71de450f7d7bae78e31868f4a/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
10
+ //#region node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
10
11
  function e(e) {
11
12
  return typeof e == `object` && !!e && !Array.isArray(e);
12
13
  }
@@ -47,12 +48,12 @@ function mergeImportedTemplates(existing, incoming) {
47
48
  * - id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加
48
49
  * `-<index>` 直到唯一)——同输入同输出,可测试;
49
50
  * - 绝不修改输入(深比较测试锁死)。 */
50
- /** 字段 → trim 后的 string;非字符串一律 ""(与旧版逐字段三元的判据同语义)。 */
51
+ /** 字段 → trim 后的 string;非字符串一律 ""。 */
51
52
  function trimField(value) {
52
53
  return typeof value === "string" ? value.trim() : "";
53
54
  }
54
55
  /** id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加 `-<index>` 直到唯一)。
55
- * 只负责取名,不登记 `seen`——登记由调用方在装配条目时做(同旧版顺序)。 */
56
+ * 只负责取名,不登记 `seen`——登记由调用方在装配条目时按装配顺序做。 */
56
57
  function uniqueEntryId(candidate, index, seen) {
57
58
  if (candidate !== "" && !seen.has(candidate)) return candidate;
58
59
  let id = `tpl-${index}`;
@@ -121,26 +122,26 @@ const ORGANIZE_TIMEOUT_SLACK_MS = 5e3;
121
122
  * `organizeTimeoutMs` 的前端取表。
122
123
  *
123
124
  * 上界与 host 同为 `[1, MAX_TIMER_MS]`:host 自己夹了上界正是为了躲开上面那个静默夹断,
124
- * 而这一侧是**唯一**发起整理读面调用的地方,它要是没夹,host 夹得再对也没用。
125
+ * 而这一侧是**唯一**发起润色读面调用的地方,它要是没夹,host 夹得再对也没用。
125
126
  *
126
127
  * @param value - 配置表单投影值
127
128
  * @returns `[1, MAX_TIMER_MS]` 区间内的整数;不合法时 undefined(回落默认)
128
129
  */
129
130
  function rawOrganizeTimeoutMsOf(value) {
130
131
  const raw = value["organizeTimeoutMs"];
131
- return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? Math.min(Math.trunc(raw), MAX_TIMER_MS) : void 0;
132
+ return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? Math.min(Math.max(Math.trunc(raw), 1), MAX_TIMER_MS) : void 0;
132
133
  }
133
134
  /**
134
- * 整理请求的客户端超时:host 的整理时限 + 余量,整条结果同样夹进 `[1, MAX_TIMER_MS]`。
135
+ * 润色请求的客户端超时:host 的润色时限 + 余量,整条结果同样夹进 `[1, MAX_TIMER_MS]`。
135
136
  *
136
137
  * **加法之后还要再夹一次**,因为 `MAX_TIMER_MS + ORGANIZE_TIMEOUT_SLACK_MS` 自己就越界了
137
- * (实测 V8 把 2147488647 的延时夹成 1ms,点击整理立刻回「请求超时」)。
138
+ * (实测 V8 把 2147488647 的延时夹成 1ms,点击润色立刻回「请求超时」)。
138
139
  *
139
- * @param raw - 配置表单投影里的整理时限(未夹)
140
+ * @param raw - 配置表单投影里的润色时限(未夹)
140
141
  * @returns 可安全交给 setTimeout 的毫秒数
141
142
  */
142
143
  function organizeFetchTimeoutMs(raw) {
143
- return Math.min((raw ?? 12e4) + ORGANIZE_TIMEOUT_SLACK_MS, MAX_TIMER_MS);
144
+ return Math.min(Math.max((raw ?? 12e4) + ORGANIZE_TIMEOUT_SLACK_MS, 1), MAX_TIMER_MS);
144
145
  }
145
146
  //#endregion
146
147
  //#region src/client-styles.ts
@@ -171,7 +172,7 @@ const CARD_STYLES = [
171
172
  ".dpic-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}",
172
173
  ".dpic-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}",
173
174
  ".dpic-title{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}",
174
- ".dpic-desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
175
+ ".dpic-cardsub{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
175
176
  ".dpic-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}",
176
177
  ".dpic-chevron-open{transform:rotate(180deg)}",
177
178
  ".dpic-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:8px 0 12px;list-style:none}",
@@ -182,6 +183,7 @@ const CARD_STYLES = [
182
183
  ".dpic-del{appearance:none;border:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:12px;border-radius:6px;padding:4px 8px;cursor:pointer;flex:none}",
183
184
  ".dpic-del:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}",
184
185
  ".dpic-del:disabled{opacity:.55;cursor:not-allowed}",
186
+ ".dpic-header:focus-visible,.dpic-del:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
185
187
  ".dpic-text{width:100%;box-sizing:border-box;font:inherit;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:8px;margin-top:6px;min-height:96px;resize:vertical}",
186
188
  ".dpic-name:focus,.dpic-text:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}",
187
189
  ".dpic-emoji{width:44px;flex:none;box-sizing:border-box;font:inherit;font-size:13px;text-align:center;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:6px 4px}",
@@ -197,6 +199,7 @@ const CARD_STYLES = [
197
199
  ".dpic-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
198
200
  ".dpic-btn:disabled{opacity:.55;cursor:not-allowed}",
199
201
  ".dpic-btn-primary{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-foreground)}",
202
+ ".dpic-btn-primary:hover:not(:disabled){background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary)}",
200
203
  ".dpic-btn-primary:disabled{opacity:.55;cursor:not-allowed}",
201
204
  ".dpic-btn-danger{color:var(--dsw-alias-state-error-primary)}",
202
205
  ".dpic-btn-danger:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary)}",
@@ -207,8 +210,8 @@ const CARD_STYLES = [
207
210
  //#region src/ui-messages.ts
208
211
  const UI_MESSAGES = {
209
212
  zh: {
210
- cardTitle: "提示词模板(输入框「模板」下拉)",
211
- cardDescription: "「模板」下拉的数据源:内置精选角色集(生成自插件 agents/ 角色库,可增删改);留空点「导入角色」可一键导入内置全部角色,导入路径按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。",
213
+ cardTitle: "模板库(输入框「模板」下拉与「润色」▾ 共用)",
214
+ cardDescription: "输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。",
212
215
  statusReadOnly: "设置源不可写:编辑已禁用;下拉仍按当前列表生效。",
213
216
  statusNotReady: "设置源未就绪:显示当前生效列表,就绪后可编辑。",
214
217
  addTemplate: "+ 新增模板",
@@ -223,7 +226,7 @@ const UI_MESSAGES = {
223
226
  footHint: "说明:编辑/新增/删除先在本地暂存,点「保存」一次写入(模板与导入允许目录同理);清空名称或正文的条目保存时会被剔除(删除请用行内「删除」);恢复默认只回滚模板列表。",
224
227
  saveFailed: "保存失败:",
225
228
  newTemplateName: "新模板 {index}",
226
- newTemplateText: "(填写模板正文:发给 AI 的引导词;[product] 类占位符用户发送前填写)",
229
+ newTemplateText: "(填写模板正文:点选后插入输入框、随消息发给模型的文字)",
227
230
  persistUnconfirmed: "{action}结果不可确认:设置源未就绪(宿主未回读成功)",
228
231
  persistRejected: "{action}未生效:宿主拒绝了本次写入(当前 revision {revision})",
229
232
  rowAriaEmoji: "模板 {index} 视觉标记",
@@ -237,7 +240,7 @@ const UI_MESSAGES = {
237
240
  rowDelete: "删除",
238
241
  rowPlaceholderDescription: "一句话介绍(下拉悬停时显示;如:威胁建模与 OWASP 代码审计)",
239
242
  rowAriaDescription: "模板 {index} 一句话介绍",
240
- rowPlaceholderText: "模板正文(发送给 AI 的引导词;[product] 类占位符由用户发送前填写)",
243
+ rowPlaceholderText: "模板正文(点选后插入输入框,随你的消息一起发给模型)",
241
244
  rowAriaText: "模板 {index} 正文",
242
245
  importFailedUnknown: "导入失败(未知错误)",
243
246
  importEmpty: "目录下没有符合条件的角色 .md(需含 name 的 frontmatter)",
@@ -267,32 +270,32 @@ const UI_MESSAGES = {
267
270
  rootsAddTitle: "加入待保存的允许目录列表",
268
271
  rootsAdd: "登记目录",
269
272
  rootsHint: "绝对路径默认拒绝:只有「当前会话 cwd」「插件内置角色库 agents/」与本列表登记的目录之内可导入。设置页没有会话上下文,卡上填的路径必须落在内置库或本列表内。改完点底部「保存」生效。",
270
- dockOrganizeEntry: "整理",
273
+ dockOrganizeEntry: "润色",
271
274
  dockTemplatesEntry: "模板",
272
- organizeIdle: "整理",
273
- organizeLoading: "整理中",
275
+ organizeIdle: "润色",
276
+ organizeLoading: "润色中",
274
277
  organizeFailedShort: "失败",
275
- organizeIdleTitle: "根据当前目录结构整理输入框内容(主键直接整理;▾ 可选角色视角)",
276
- organizeFailedTitle: "整理失败:{message}",
277
- organizeCaretAria: "选择整理角色视角",
278
- organizeCaretTitle: "以某角色视角整理(角色来自下方模板库)",
279
- organizeMainAria: "整理输入框内容",
280
- organizeDirectItem: "直接整理(默认,不带角色)",
281
- organizeNoTemplates: "无模板可选为整理视角",
282
- organizeRoleItem: "以「{name}」视角整理",
278
+ organizeIdleTitle: "结合当前目录润色输入框内容(主键直接润色;▾ 可选角色风格)",
279
+ organizeFailedTitle: "润色失败:{message}",
280
+ organizeCaretAria: "选择润色的角色风格",
281
+ organizeCaretTitle: "按某个角色的风格润色(角色来自下方模板库)",
282
+ organizeMainAria: "润色输入框内容",
283
+ organizeDirectItem: "直接润色(默认,不带角色)",
284
+ organizeNoTemplates: "无模板可选作角色风格",
285
+ organizeRoleItem: "以「{name}」的风格润色",
283
286
  organizeWriteBackUnavailable: "输入框动作不可用,无法写回",
284
- templatesIdleTitle: "选择一条提示引导词插入输入框(空则填入,非空追加;按分组展示;[product] 类占位符发送前自己补)",
287
+ templatesIdleTitle: "选择一条模板插入输入框(空则填入,非空则空一行追加;按分组展示)",
285
288
  templatesBrokenTitle: "输入框动作不可用,无法插入",
286
289
  templatesGroupCommon: "通用",
287
- templatesAria: "插入提示引导词模板",
288
- templatesEmptyHint: "无模板:在设置页「提示词模板」中添加或恢复默认",
290
+ templatesAria: "插入模板",
291
+ templatesEmptyHint: "无模板:在设置页「模板库」中添加或恢复默认",
289
292
  builtinLoading: "正在载入内置角色模板…",
290
293
  builtinFailed: "内置模板加载失败:{message}",
291
294
  builtinRetry: "重试"
292
295
  },
293
296
  en: {
294
- cardTitle: "Prompt templates (input-box \"Template\" dropdown)",
295
- cardDescription: "Data source of the \"Template\" dropdown: a curated built-in role set (generated from this plugin's agents/ role library; add, edit and delete are supported). Leave the path empty and press \"Import roles\" to import the whole built-in library; import paths are allowed within \"session cwd + built-in role library + the import allowed directories below\". Press \"Save\" after editing — it survives restarts.",
297
+ cardTitle: "Template library (shared by the \"Template\" dropdown and the \"Polish\" ▾ menu)",
298
+ cardDescription: "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.",
296
299
  statusReadOnly: "Settings source is read-only: editing is disabled; the dropdown still uses the current list.",
297
300
  statusNotReady: "Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.",
298
301
  addTemplate: "+ Add template",
@@ -307,7 +310,7 @@ const UI_MESSAGES = {
307
310
  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.",
308
311
  saveFailed: "Save failed: ",
309
312
  newTemplateName: "New template {index}",
310
- newTemplateText: "(Template body: the prompt sent to the AI; fill [product]-style placeholders yourself before sending)",
313
+ newTemplateText: "(Template body: the text inserted into the input box and sent to the model with your message)",
311
314
  persistUnconfirmed: "{action} cannot be confirmed: the settings source is not ready (host read-back failed)",
312
315
  persistRejected: "{action} did not take effect: the host rejected this write (current revision {revision})",
313
316
  rowAriaEmoji: "Visual mark of template {index}",
@@ -321,7 +324,7 @@ const UI_MESSAGES = {
321
324
  rowDelete: "Delete",
322
325
  rowPlaceholderDescription: "One-line intro (shown on dropdown hover; e.g. threat modelling and OWASP code auditing)",
323
326
  rowAriaDescription: "One-line intro of template {index}",
324
- rowPlaceholderText: "Template body (the prompt sent to the AI; [product]-style placeholders are filled in before sending)",
327
+ rowPlaceholderText: "Template body (inserted into the input box and sent to the model with your message)",
325
328
  rowAriaText: "Body of template {index}",
326
329
  importFailedUnknown: "Import failed (unknown error)",
327
330
  importEmpty: "No qualifying role .md in that directory (frontmatter must contain name)",
@@ -351,32 +354,32 @@ const UI_MESSAGES = {
351
354
  rootsAddTitle: "Add it to the pending allowed-directory list",
352
355
  rootsAdd: "Register directory",
353
356
  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.",
354
- dockOrganizeEntry: "Organize",
357
+ dockOrganizeEntry: "Polish",
355
358
  dockTemplatesEntry: "Templates",
356
- organizeIdle: "Organize",
357
- organizeLoading: "Organizing",
359
+ organizeIdle: "Polish",
360
+ organizeLoading: "Polishing",
358
361
  organizeFailedShort: "Failed",
359
- organizeIdleTitle: "Organize the input-box content from the current directory structure (main key organizes directly; ▾ picks a role perspective)",
360
- organizeFailedTitle: "Organize failed: {message}",
361
- organizeCaretAria: "Choose a role perspective for organizing",
362
- organizeCaretTitle: "Organize from a role's perspective (roles come from the template library below)",
363
- organizeMainAria: "Organize the input-box content",
364
- organizeDirectItem: "Organize directly (default, no role)",
365
- organizeNoTemplates: "No templates available as an organize perspective",
366
- organizeRoleItem: "Organize as \"{name}\"",
362
+ organizeIdleTitle: "Polish the input-box content against the current directory (main key polishes directly; ▾ picks a role style)",
363
+ organizeFailedTitle: "Polish failed: {message}",
364
+ organizeCaretAria: "Choose a role style to polish with",
365
+ organizeCaretTitle: "Polish in a role's style (roles come from the template library below)",
366
+ organizeMainAria: "Polish the input-box content",
367
+ organizeDirectItem: "Polish directly (default, no role)",
368
+ organizeNoTemplates: "No templates available as a role style",
369
+ organizeRoleItem: "Polish in the style of \"{name}\"",
367
370
  organizeWriteBackUnavailable: "Input-box actions unavailable; cannot write back",
368
- templatesIdleTitle: "Pick a prompt template to insert into the input box (empty fills it, non-empty appends; grouped display; fill [product]-style placeholders yourself before sending)",
371
+ templatesIdleTitle: "Pick a template to insert into the input box (an empty draft is filled, a non-empty one gets a blank line plus the template; shown grouped)",
369
372
  templatesBrokenTitle: "Input-box actions unavailable; cannot insert",
370
373
  templatesGroupCommon: "General",
371
- templatesAria: "Insert a prompt template",
372
- templatesEmptyHint: "No templates: add or restore defaults under \"Prompt templates\" in the settings page",
374
+ templatesAria: "Insert a template",
375
+ templatesEmptyHint: "No templates: add or restore defaults under \"Template library\" in the settings page",
373
376
  builtinLoading: "Loading built-in role templates…",
374
377
  builtinFailed: "Failed to load built-in templates: {message}",
375
378
  builtinRetry: "Retry"
376
379
  }
377
380
  };
378
381
  //#endregion
379
- //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_421050e71de450f7d7bae78e31868f4a/node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
382
+ //#region node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
380
383
  function t(e) {
381
384
  let t = Object.getOwnPropertyDescriptor(e, `message`);
382
385
  return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
@@ -405,6 +408,11 @@ function r(e) {
405
408
  }
406
409
  //#endregion
407
410
  //#region src/remote.ts
411
+ /** Typert Remote 命名空间(client 半这一侧的唯一一枚)。
412
+ *
413
+ * 宿主半的注册键在 host.ts 的 `DIR_PREP_REMOTE_NAMESPACE`——两半各自打包、client 包
414
+ * 不能 import host.ts,所以这一枚字面量必然有两份。两边取值必须一致:写岔了的表现是
415
+ * 网关挂上的是 A、报错文案说的是 B,而没有任何运行期信号。 */
408
416
  const DIR_PREP_NAMESPACE = "dirPrepOrganize";
409
417
  const DIR_PREP_SERVICE_KEY = `remote.${DIR_PREP_NAMESPACE}`;
410
418
  const PACKAGE_NAME = "@jayyuen66/dsh-dir-prep-organize";
@@ -509,9 +517,14 @@ const DIR_PREP_DESCRIPTORS = [
509
517
  ];
510
518
  const isMounter = (value) => e(value) && typeof value["$mount"] === "function";
511
519
  const isNamespace = (value) => e(value) && typeof value["defaults"] === "function" && typeof value["context"] === "function" && typeof value["model"] === "function" && typeof value["organize"] === "function" && typeof value["importTemplates"] === "function";
512
- const unwrap = (result) => {
513
- if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
514
- return result.value;
520
+ const unwrap = (raw) => {
521
+ if (!e(raw) || typeof raw["ok"] !== "boolean") throw new TypeError("Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok");
522
+ if (!raw["ok"]) {
523
+ const { error } = raw;
524
+ if (!e(error) || typeof error["code"] !== "string" || typeof error["message"] !== "string") throw new TypeError("Typert Remote 应答的 error 分支缺 code/message");
525
+ throw new Error(`${error["code"]}: ${error["message"]}`);
526
+ }
527
+ return raw["value"];
515
528
  };
516
529
  function buildReader(ctx, remote) {
517
530
  let mounted;
@@ -520,7 +533,12 @@ function buildReader(ctx, remote) {
520
533
  package: PACKAGE_NAME,
521
534
  descriptors: DIR_PREP_DESCRIPTORS
522
535
  });
523
- await mounted;
536
+ try {
537
+ await mounted;
538
+ } catch (error) {
539
+ mounted = void 0;
540
+ throw error;
541
+ }
524
542
  const namespace = ctx.get?.(DIR_PREP_SERVICE_KEY, false);
525
543
  if (!isNamespace(namespace)) throw new Error(`${DIR_PREP_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
526
544
  return namespace;
@@ -547,7 +565,7 @@ function createDirPrepReader(ctx) {
547
565
  const NS = "dir-prep-organize";
548
566
  const BUNDLE_PKG = "@jayyuen66/dsh-dir-prep-organize";
549
567
  const ERROR_FLASH_MS = 4e3;
550
- /** 非整理读面的等待上限(与迁移前 HTTP 读面的常量同值)。 */
568
+ /** 非润色读面的等待上限。润色那一发有自己的超时(来自设置卡的 organizeTimeoutMs)。 */
551
569
  const REMOTE_TIMEOUT_MS = 125e3;
552
570
  const RESET_CONFIRM_MS = 4e3;
553
571
  const EMOJI_PLACEHOLDER = "😀";
@@ -672,6 +690,11 @@ const builtinInitial = {
672
690
  };
673
691
  let builtinState = builtinInitial;
674
692
  let builtinInflight = null;
693
+ /**
694
+ * 在飞 Promise 的世代。reset 之后新一代重新起跑,上一代晚到的结果不许再写进 store,
695
+ * 否则用户点了「恢复默认」却拿回恢复前那次请求的快照。
696
+ */
697
+ let builtinGeneration = 0;
675
698
  const builtinListeners = /* @__PURE__ */ new Set();
676
699
  function setBuiltinState(next) {
677
700
  if (next === builtinState) return builtinState;
@@ -688,10 +711,10 @@ function setDirPrepReader(reader) {
688
711
  dirPrepReader = reader;
689
712
  }
690
713
  function requireReader() {
691
- if (dirPrepReader === void 0) throw new Error("远程读面不可用:宿主网关没有挂上 dirPrepOrganize");
714
+ if (dirPrepReader === void 0) throw new Error(`远程读面不可用:宿主网关没有挂上 ${DIR_PREP_NAMESPACE}`);
692
715
  return dirPrepReader;
693
716
  }
694
- /** 客户端超时只影响等待:宿主侧的整理超时仍由它自己的 AbortController 收口。 */
717
+ /** 客户端超时只影响等待:宿主侧的润色超时仍由它自己的 AbortController 收口。 */
695
718
  async function within(pending, timeoutMs) {
696
719
  const gate = Promise.withResolvers();
697
720
  const timer = setTimeout(() => {
@@ -706,6 +729,7 @@ async function within(pending, timeoutMs) {
706
729
  async function loadBuiltinTemplates() {
707
730
  if (builtinState.phase === "ready") return builtinState;
708
731
  if (builtinInflight !== null) return await builtinInflight;
732
+ const generation = builtinGeneration;
709
733
  builtinInflight = (async () => {
710
734
  setBuiltinState({
711
735
  phase: "loading",
@@ -735,9 +759,9 @@ async function loadBuiltinTemplates() {
735
759
  error: r(error)
736
760
  };
737
761
  } finally {
738
- builtinInflight = null;
762
+ if (builtinGeneration === generation) builtinInflight = null;
739
763
  }
740
- return setBuiltinState(settled);
764
+ return builtinGeneration === generation ? setBuiltinState(settled) : settled;
741
765
  })();
742
766
  return await builtinInflight;
743
767
  }
@@ -748,6 +772,7 @@ function subscribeBuiltinTemplates(listener) {
748
772
  };
749
773
  }
750
774
  function resetBuiltinTemplates() {
775
+ builtinGeneration += 1;
751
776
  builtinInflight = null;
752
777
  setBuiltinState(builtinInitial);
753
778
  }
@@ -758,7 +783,7 @@ function builtinStatusRow(snap, t) {
758
783
  };
759
784
  const retryButton = (0, react.createElement)("button", {
760
785
  type: "button",
761
- className: "dpi-builtin-retry",
786
+ className: "dpic-btn",
762
787
  "data-field": "dpi-builtin-retry",
763
788
  onClick: () => {
764
789
  loadBuiltinTemplates();
@@ -771,7 +796,7 @@ function builtinStatusRow(snap, t) {
771
796
  function assertOrganizeReady(ctxRes, modelRes, prompt) {
772
797
  if (!ctxRes.ok) throw new Error(`目录上下文失败: ${ctxRes.error ?? "未知错误"}`);
773
798
  if (!modelRes.ok || modelRes.provider === void 0 || modelRes.model === void 0) throw new Error(`读取模型失败: ${modelRes.error ?? "未知错误"}`);
774
- if (prompt.trim().length === 0) throw new Error("输入框为空,无内容可整理");
799
+ if (prompt.trim().length === 0) throw new Error("输入框为空,无内容可润色");
775
800
  }
776
801
  async function requestOrganize(args) {
777
802
  const { ctxRes, prompt, sessionId, roleText, timeoutMs } = args;
@@ -782,7 +807,7 @@ async function requestOrganize(args) {
782
807
  entriesSummary,
783
808
  ...roleText === void 0 ? {} : { roleText }
784
809
  }), timeoutMs));
785
- if (!orgRes.ok || orgRes.content === void 0) throw new Error(orgRes.error ?? "整理失败(未知错误)");
810
+ if (!orgRes.ok || orgRes.content === void 0) throw new Error(orgRes.error ?? "润色失败(未知错误)");
786
811
  return orgRes.content;
787
812
  }
788
813
  async function runOrganizeFlow(args) {
@@ -1026,7 +1051,7 @@ async function runOrganizeClick(args) {
1026
1051
  if (seq.current === mySeq) setLoading(false);
1027
1052
  }
1028
1053
  }
1029
- /** 整理结果无处可写时的主按钮 title(与模板项那一档同一句话,同一套判据)。 */
1054
+ /** 润色结果无处可写时的主按钮 title(与模板项那一档同一句话,同一套判据)。 */
1030
1055
  const NO_WRITE_BACK_TITLE_KEY = "organizeWriteBackUnavailable";
1031
1056
  function createOrganizeMainButton(ui) {
1032
1057
  const { t, icon, label, state, errClass, errTitle, loading, canWrite, onRun } = ui;
@@ -1059,7 +1084,9 @@ function createOrganizeCaret(ui) {
1059
1084
  }, (0, react.createElement)(CaretIcon));
1060
1085
  }
1061
1086
  function createOrganizeRoleMenu(ui) {
1062
- const { t, templates, onRun, directItemLabel, noTemplatesLabel, builtinRow } = ui;
1087
+ const { t, templates, onRun, directItemLabel, noTemplatesLabel, builtinRow, loading, canWrite, errTitle } = ui;
1088
+ const blocked = loading || !canWrite;
1089
+ const blockedTitle = canWrite ? void 0 : errTitle;
1063
1090
  return (0, react.createElement)("div", {
1064
1091
  className: "dpi-menu",
1065
1092
  role: "menu",
@@ -1069,6 +1096,8 @@ function createOrganizeRoleMenu(ui) {
1069
1096
  className: "dpi-item",
1070
1097
  role: "menuitem",
1071
1098
  "data-field": "dpi-organize-role-direct",
1099
+ disabled: blocked,
1100
+ ...blockedTitle === void 0 ? {} : { title: blockedTitle },
1072
1101
  onClick: () => {
1073
1102
  onRun();
1074
1103
  }
@@ -1078,7 +1107,8 @@ function createOrganizeRoleMenu(ui) {
1078
1107
  className: "dpi-item",
1079
1108
  role: "menuitem",
1080
1109
  "data-field": "dpi-organize-role-item",
1081
- title: tpl.description === "" ? tpl.text : tpl.description,
1110
+ disabled: blocked,
1111
+ title: blockedTitle ?? (tpl.description === "" ? tpl.text : tpl.description),
1082
1112
  onClick: () => {
1083
1113
  onRun(tpl.text);
1084
1114
  }
@@ -1565,7 +1595,7 @@ function cardStatusHint(snap, t) {
1565
1595
  function createCardHeader(view) {
1566
1596
  const { t, open, setOpen } = view;
1567
1597
  const headTitle = (0, react.createElement)("div", { className: "dpic-title" }, t("cardTitle"));
1568
- const headDesc = (0, react.createElement)("div", { className: "dpic-desc" }, t("cardDescription"));
1598
+ const headDesc = (0, react.createElement)("div", { className: "dpic-cardsub" }, t("cardDescription"));
1569
1599
  const headBlock = (0, react.createElement)("div", { className: "dpic-head" }, headTitle, headDesc);
1570
1600
  const chevronPath = (0, react.createElement)("path", svgPathProps("M3 5l4 4 4-4", true));
1571
1601
  const chevron = (0, react.createElement)("svg", {
@@ -1674,6 +1704,7 @@ function createPersistActions(args) {
1674
1704
  return;
1675
1705
  }
1676
1706
  setConfirmReset(false);
1707
+ setBusy(true);
1677
1708
  (async () => {
1678
1709
  try {
1679
1710
  const builtin = await loadBuiltinTemplates();
@@ -1686,6 +1717,8 @@ function createPersistActions(args) {
1686
1717
  setRootsDraft(allowRoots);
1687
1718
  } catch (error) {
1688
1719
  reportError(error);
1720
+ } finally {
1721
+ setBusy(false);
1689
1722
  }
1690
1723
  })();
1691
1724
  }
@@ -1821,7 +1854,7 @@ const inject = [
1821
1854
  "configForms",
1822
1855
  "locale"
1823
1856
  ];
1824
- /** 注入输入框右侧的「整理」「模板」两个按钮(两枚共用同一份 store 与 t)。
1857
+ /** 注入输入框右侧的「润色」「模板」两个按钮(两枚共用同一份 store 与 t)。
1825
1858
  *
1826
1859
  * 一次 inject 挂两枚:它们的 inject 面完全相同(都只要 store 这一份 card hook),
1827
1860
  * 分成两次 inject 会让宿主多跑一轮 occupant 装配,而拆开的唯一好处只是少几行。 */
@@ -1850,7 +1883,8 @@ function injectDock(ctx, store, t) {
1850
1883
  };
1851
1884
  });
1852
1885
  }
1853
- /** 注入设置页的「提示词模板」卡(插件自带卡片,宿主不再生成自动表单页)。
1886
+ /** 注入设置页的「模板库」卡(插件自带卡片,宿主不再生成自动表单页)。
1887
+ * 这张卡管的就是「模板」下拉与「润色」▾ 共用的那一份列表。
1854
1888
  *
1855
1889
  * scope 作为参数传进来而不是就地取:卡片 inject 闭包里的 set/unset 必须落到
1856
1890
  * apply 期取的那**同一份**配置表单上(中途再 get 一次未必是同一个 provider 对象),
package/cordis.patch.yml CHANGED
@@ -1,24 +1,24 @@
1
- # dir-prep-organize(整理 + 模板;内容源为内置角色库)。
2
- # 功能一「整理」:输入框右上角分段按钮。主键点击 → 按当前目录结构 + 当前 session
3
- # 模型整理优化草稿(成功直接替换,失败保持原值);▾ → 「以 XX 视角整理」(角色菜单,
4
- # 角色上下文 = 模板正文提炼,随 organize 调用注入 system,走同一 LLM 流)。
1
+ # dir-prep-organize(润色 + 模板;内容源为内置角色库)。
2
+ # 功能一「润色」:输入框右上角分段按钮。主键点击 → 按当前目录结构 + 当前 session
3
+ # 模型润色草稿(成功直接替换,失败保持原值);▾ → 「以 XX 的风格润色」(角色菜单,
4
+ # 角色上下文 = 模板正文提炼,随 organize 调用注入 user 的 <data> 围栏,走同一 LLM 流)。
5
5
  # 功能二「模板」:输入框旁「模板」下拉,默认展示精选角色集(由 scripts/gen-defaults.mjs
6
6
  # 从插件 agents/ 目录生成,src/default-templates.generated.ts 单源),按 group 分组
7
7
  # 渲染(emoji + 名称 + description 悬停);点选插入草稿(空整段填入 / 非空末尾追加)。
8
- # 列表存 settings(0.1.7 隐式注册:命名空间 = 本条目 id,可编辑字段 = host.ts 导出的
9
- # Config 上标了 .volatile() 的 templates/importAllowRoots;生成集不再是 register 的 base,
10
- # 而是 client 半的回落),设置页卡逐条增删改(name/emoji/
8
+ # 列表存 settings(隐式注册:命名空间 = 本条目 id,可编辑字段 = host.ts 导出的
9
+ # Config 上标了 .volatile() 的那几项;内置精选集是 client 半在配置缺席时的回落),
10
+ # 设置页卡逐条增删改(name/emoji/
11
11
  # group/description/text)+ 两步确认恢复默认 + 角色导入(importTemplates:留空 = 一键
12
12
  # 导入内置 agents/ 全部;填路径 = 导入本地 .md 或目录)。client 直读本条目的配置表单
13
- # (ctx.configForms.get(条目 id);0.1.7 已移除 settingsScope)。
13
+ # (ctx.configForms.get(条目 id),没有 settingsScope 这一层)。
14
14
  #
15
15
  # 架构:Host 半(host.ts)注册官方 Typert Remote 的服务键 `dirPrepOrganize`,
16
- # defaults / context / model / organize / importTemplates 五个方法就是全部读面;
16
+ # 它导出的方法表就是全部读面;
17
17
  # 认证、Host/DNS 重绑定/Origin 判据与请求体上限由宿主 /api 网关承担,本包不注册
18
18
  # HTTP 路由、也没有自建 CSRF 令牌。Client 半(src/client-entry.ts → client.js)注册
19
- # conversation.input.right list 槽(整理 id=dir-prep-organize order 99 / 模板
20
- # id=…-templates order 100)与 plugins.bundle.config 设置卡(keyed;0.1.6 起
21
- # settings.plugin.item 已随旧设置页删除);整理经 Remote 读取器调用上述方法,写回走
19
+ # conversation.input.right list 槽(润色 id=dir-prep-organize order 99 / 模板
20
+ # id=dir-prep-organize-templates order 100)与 plugins.bundle.config 设置卡(keyed,
21
+ # 旧设置页的 settings.plugin.item 面已不存在);润色经 Remote 读取器调用上述方法,写回走
22
22
  # inputActions.setDraft;模板读写配置表单 ctx.configForms.get(条目 id)(数组 set=字段级整体替换,
23
23
  # 已按 dsh-settings applyPathOp/cloneJsonShaped 源码取证)。
24
24
  - insert: