nx-kv 0.59.0 → 0.61.0

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +3 -2
  3. package/assets/nx-kv/references/A04-/344/273/223/345/272/223/344/270/216/351/241/271/347/233/256/347/273/204.md +2 -1
  4. package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +3 -3
  5. package/bin/kv.mjs +10 -0
  6. package/package.json +1 -1
  7. package/src/core/attachmentdb/docs.ts +3 -5
  8. package/src/core/db/import-json/refs.ts +2 -2
  9. package/src/core/db/migrations/index.ts +2 -0
  10. package/src/core/db/migrations/v12.sql +14 -0
  11. package/src/core/db/migrations/v8-data.ts +20 -4
  12. package/src/core/db/version.ts +3 -1
  13. package/src/modules/docs/actions/docs-bindings.ts +2 -3
  14. package/src/modules/docs/actions/docs-link.ts +1 -2
  15. package/src/modules/docs/brief.ts +0 -2
  16. package/src/modules/docs/docref.ts +8 -7
  17. package/src/modules/docs/knowledge.ts +1 -4
  18. package/src/modules/docs/ref-sync.ts +1 -5
  19. package/src/modules/docs/refs.ts +66 -8
  20. package/src/modules/docs/render.ts +1 -1
  21. package/src/modules/docs/service.ts +1 -3
  22. package/src/modules/localtask/actions/localtask-config.ts +3 -3
  23. package/src/modules/localtask/repo/open.ts +4 -0
  24. package/src/modules/localtask/repo/settings.ts +72 -202
  25. package/src/modules/localtask/task-templates.ts +10 -12
  26. package/src/modules/promptplug/Template/blockTemplates.json +90 -0
  27. package/src/modules/promptplug/actions/_manifest.generated.ts +20 -0
  28. package/src/modules/promptplug/actions/prompt-order.ts +38 -0
  29. package/src/modules/promptplug/actions/prompt-registry.ts +51 -0
  30. package/src/modules/promptplug/base.ts +70 -0
  31. package/src/modules/promptplug/compose.ts +86 -0
  32. package/src/modules/promptplug/ensure.ts +57 -0
  33. package/src/modules/promptplug/factory.ts +105 -0
  34. package/src/modules/promptplug/index.ts +39 -0
  35. package/src/modules/promptplug/keys.ts +9 -0
  36. package/src/modules/promptplug/plugins/attachment.ts +36 -0
  37. package/src/modules/promptplug/plugins/context.ts +167 -0
  38. package/src/modules/promptplug/plugins/ext.ts +32 -0
  39. package/src/modules/promptplug/plugins/getloop.ts +29 -0
  40. package/src/modules/promptplug/plugins/readonly-blocks.ts +75 -0
  41. package/src/modules/promptplug/schema-bridge.ts +88 -0
  42. package/src/modules/promptplug/template-bundle.ts +59 -0
  43. package/src/modules/repos/actions/repo-doc-add.ts +1 -2
  44. package/src/modules/repos/actions/repo-doc-list.ts +1 -1
  45. package/src/modules/repos/actions/repo-knowledge.ts +1 -1
  46. package/src/modules/repos/actions/repo-ref-note.ts +4 -4
  47. package/src/modules/repos/boards/core.ts +0 -3
  48. package/src/modules/repos/{link-note.ts → ref-note-doc.ts} +53 -29
  49. package/src/modules/repos/ref.ts +8 -36
  50. package/src/modules/repos/transfer/export.ts +3 -3
  51. package/src/modules/repos/transfer/layout.ts +3 -3
  52. package/src/modules/tasktool/attach-template.ts +31 -1
  53. package/src/modules/tasktool/plugins/waitgoal-config.ts +11 -3
  54. package/src/modules/tasktool/preview.ts +7 -8
  55. package/src/modules/tasktool/wait.ts +78 -54
  56. package/src/runtime/registry.ts +2 -0
  57. package/src/shared/prompt-blocks.ts +93 -338
  58. package/src/shared/prompt-plugin.ts +182 -0
  59. package/src/web/frontend/api/cli-tree.json +41 -2
  60. package/src/web/frontend/api/client.generated.ts +24 -4
  61. package/src/web/frontend/components/Introduction/use-intro.ts +2 -4
  62. package/src/web/frontend/components/md/block-rail.tsx +141 -0
  63. package/src/web/frontend/components/md/live-block.tsx +14 -2
  64. package/src/web/frontend/components/md/md-panes.tsx +36 -1
  65. package/src/web/frontend/components/md/use-block-drag.ts +68 -0
  66. package/src/web/frontend/components/md/use-live-preview.ts +46 -1
  67. package/src/web/frontend/modules/md/md-edit-ops.ts +32 -0
  68. package/src/web/frontend/modules/md/md-render.ts +61 -1
  69. package/src/web/frontend/modules/md/styles/docs.css +11 -0
  70. package/src/web/frontend/modules/md/styles/editor.css +35 -0
  71. package/src/web/frontend/modules/md/use-templates.ts +1 -1
  72. package/src/web/frontend/modules/prompts/render-template-body.ts +14 -0
  73. package/src/web/frontend/modules/refs/api.ts +0 -1
  74. package/src/web/frontend/page/dir/index.tsx +1 -1
  75. package/src/web/frontend/page/group/index.tsx +1 -1
  76. package/src/web/frontend/page/repos/index.tsx +1 -1
  77. package/src/web/frontend/page/settings/api.ts +29 -0
  78. package/src/web/frontend/page/settings/prompt-order-card.tsx +113 -0
  79. package/src/web/frontend/page/settings/prompt-templates-section.tsx +127 -68
  80. package/src/web/frontend/page/settings/style.css +31 -0
  81. package/src/web/frontend/page/templates/index.tsx +1 -1
  82. package/src/web/frontend/refs/api.ts +0 -1
  83. package/src/web/public/assets/bar-CGEZ954x.js +1 -0
  84. package/src/web/public/assets/{composer-launch-h-8g0f8A.js → composer-launch-Dhrj1gNT.js} +1 -1
  85. package/src/web/public/assets/{composer-panel-MB_2m-jI.js → composer-panel-AXUbIJgb.js} +1 -1
  86. package/src/web/public/assets/{dir-BQZAPk92.js → dir-TgJu4iE_.js} +1 -1
  87. package/src/web/public/assets/doc-utk54z7G.js +6 -0
  88. package/src/web/public/assets/{group-CXDiKp4X.js → group-CqtNx-o9.js} +1 -1
  89. package/src/web/public/assets/{index-BPxgsnXM.css → index-BJstNMuV.css} +1 -1
  90. package/src/web/public/assets/{index-Dmlh01et.js → index-BdJwacQ0.js} +2 -2
  91. package/src/web/public/assets/md-history-BRw2I-G_.js +39 -0
  92. package/src/web/public/assets/{refs-DvvwZmdl.js → refs-CIpytW-v.js} +1 -1
  93. package/src/web/public/assets/{repo-form-modal-pyqiC7pB.js → repo-form-modal-CF9-xxFD.js} +1 -1
  94. package/src/web/public/assets/{repos-CeyrjSQ_.js → repos-C8boX9eg.js} +2 -2
  95. package/src/web/public/assets/{settings-ZgyeQVU1.css → settings-BB1PvwRD.css} +1 -1
  96. package/src/web/public/assets/settings-Dzpmh-Ol.js +1 -0
  97. package/src/web/public/assets/{task-DJF54sKp.js → task-h2ezBIz9.js} +5 -5
  98. package/src/web/public/assets/{task-utils-WfeuGNak.js → task-utils-dgdA6Pxs.js} +1 -1
  99. package/src/web/public/assets/{templates-BaX3bQsl.js → templates-D7eg9iE4.js} +1 -1
  100. package/src/web/public/assets/use-rail-drag-H0M8oQ0Z.js +1 -0
  101. package/src/web/public/index.html +7 -7
  102. package/src/modules/docs/link-note.ts +0 -171
  103. package/src/modules/tasktool/delivery-template.ts +0 -236
  104. package/src/modules/tasktool/system-blocks.ts +0 -112
  105. package/src/web/frontend/modules/prompts/placeholders.ts +0 -106
  106. package/src/web/frontend/page/settings/prompt-template-params.ts +0 -296
  107. package/src/web/public/assets/bar-CmzzOYQi.js +0 -1
  108. package/src/web/public/assets/doc-CKkCGsZ4.js +0 -6
  109. package/src/web/public/assets/md-history-BF85zuFo.js +0 -39
  110. package/src/web/public/assets/settings-KNodW2wX.js +0 -8
  111. package/src/web/public/assets/use-rail-drag-B1RQzqcB.js +0 -1
  112. /package/src/web/public/assets/{use-rail-drag-1h2zairf.css → md-history-1h2zairf.css} +0 -0
@@ -16,6 +16,7 @@ import { openStore, getDb, closeDb, isStoreOpen, tx } from '../../../core/db/ind
16
16
  import { checkNodeVersion } from '../../../core/db/version.js';
17
17
  import type { DbApi } from '../../../core/db/driver.js';
18
18
  import type { TxOptions } from '../../../core/db/tx.js';
19
+ import { ensurePromptTemplates } from '../../promptplug/ensure.js';
19
20
 
20
21
  /** 当前连接是按哪个库路径打开的(env 变了要关旧开新;null = 尚未打开)。 */
21
22
  let openedFor: string | null | undefined = null;
@@ -39,6 +40,9 @@ export function openLocaltaskStore(): DbApi {
39
40
  if (isStoreOpen()) closeDb();
40
41
  openStore({ path: target.path, appDir: target.appDir, importLegacyData: true });
41
42
  openedFor = target.path;
43
+ // 出厂提示词模板:首启落库 / 版本落后时只刷 builtin(幂等;已最新 → 零写)。
44
+ // 放这里而非 runtime 启动行:db() 是全仓唯一的库打开入口,任何命令先经它。
45
+ ensurePromptTemplates(getDb());
42
46
  return getDb();
43
47
  }
44
48
 
@@ -4,16 +4,13 @@
4
4
  // value 一律 JSON 文本('240' / '["a","b"]' / '"…"'),读写都在这里序列化。
5
5
  // 凭据(token/baseUrl/email/userId/groupId)**绝不进这张表** —— 它们留在 config.json。
6
6
  //
7
- // 提示词模型(v5,见 shared/prompt-blocks.js):
7
+ // 提示词模型(v6,唯一基准方案 docs/research/prompt-plugin-single-route.md §4):
8
8
  // - `lt.blockTemplates` 是唯一权威来源:`{ [blockId]: { active, list } }`,
9
- // 每个区块各自一份模板列表、各自指定生效项;内置条目 `builtin` 常驻不可删。
9
+ // 每个区块各自一份模板列表、各自指定生效项;内置条目 `builtin` 常驻不可改。
10
+ // 首启落库由 promptplug/ensure.ts 完成(open.ts 挂 ensure)——本文件**不做任何
11
+ // 合成与旧键折算**(§4.1 纯校验;旧 lt.* 键、rule 键、数组简写形态已全部下线)。
10
12
  // - 全局只有 `lt.appendMode`(xml / plain)对所有区块整体生效。
11
- // - 旧键 `lt.promptTemplates / lt.activePromptTemplate / lt.xmlBlocks /
12
- // lt.deliveryTemplate / lt.attachTemplate / lt.taskSuffix / lt.ackPrompt`
13
- // 只作**一次性迁移来源**:读取时若还没有 `lt.blockTemplates`,把它们折算进
14
- // 各区块的列表;之后不再读写这些旧键。
15
- // - 旧语法模板(`{{#repo}}…{{/repo}}` 等)迁移时会被校验拒绝(不进入新列表),
16
- // 旧模板不保证可用——这是「不再维护新旧两套语法」的明确取舍。
13
+ // - 没有落库行 = 事故,抛错(ensure 恒先于本文件的任何读取执行)。
17
14
  import { db, txw } from './open.js';
18
15
  import { nowMs } from '../../../core/db/time.js';
19
16
  import { badInput } from '../../../core/errors.js';
@@ -30,40 +27,25 @@ import {
30
27
  clampAppendMode,
31
28
  } from '../task-templates.js';
32
29
  import {
33
- BLOCK_DEFS,
34
30
  BUILTIN_TEMPLATE_ID,
35
- BUILTIN_TEMPLATE_NAME,
36
- DEFAULT_ACK_PROMPT,
37
31
  MAX_BLOCK_TEMPLATE_LEN,
38
- defaultBlockTemplateLists,
32
+ PROMPT_BLOCK_IDS,
39
33
  normalizeBlockTemplateLists,
40
34
  resolveBlockTemplates,
41
35
  } from '../../../shared/prompt-blocks.js';
42
- import type { BlockTemplateList } from '../../../shared/prompt-blocks.js';
36
+ import type { BlockLists, BlockTemplateList } from '../../../shared/prompt-blocks.js';
43
37
  import type { DbApi } from '../../../core/db/driver.js';
44
-
45
- /** 归一化后的「每区块模板列表」集合(normalize/defaultBlockTemplateLists 恒产出全部 BLOCK_DEFS 区块)。 */
46
- type BlockLists = Record<string, BlockTemplateList>;
38
+ import { undeclaredTemplateVars } from '../../../shared/prompt-plugin.js';
39
+ import { globalTemplateVarScope, blockLabelOf } from '../../promptplug/index.js';
47
40
 
48
41
  const KEYS = {
49
42
  timeoutSec: 'lt.timeoutSec',
50
43
  appendMode: 'lt.appendMode',
51
44
  blockTemplates: 'lt.blockTemplates',
52
- // 以下旧键只用于读取迁移,不再写回
53
- taskSuffix: 'lt.taskSuffix',
54
- ackPrompt: 'lt.ackPrompt',
55
- deliveryTemplate: 'lt.deliveryTemplate',
56
- attachTemplate: 'lt.attachTemplate',
57
- xmlBlocks: 'lt.xmlBlocks',
58
- promptTemplates: 'lt.promptTemplates',
59
- activePromptTemplate: 'lt.activePromptTemplate',
60
45
  };
61
46
 
62
- /** 旧迁移 / 命令行便捷写入使用的固定条目 id(不影响用户自己新建的模板)。 */
63
- const LEGACY_ENTRY_ID = 'legacy';
47
+ /** 命令行便捷写入使用的固定条目 id(不影响用户自己新建的模板)。 */
64
48
  const CLI_ENTRY_ID = 'cli';
65
- /** 旧 rule 并入 ack 后的固定条目 id。 */
66
- const RULE_LEGACY_ENTRY_ID = 'legacy-rule';
67
49
 
68
50
  function readSetting(conn: DbApi, key: string): any {
69
51
  const row = conn.get('SELECT value FROM settings WHERE key = :k', { k: key });
@@ -83,7 +65,7 @@ function writeSetting(conn: DbApi, key: string, value: unknown): void {
83
65
  );
84
66
  }
85
67
 
86
- /** 多条旧设置按空行拼成一条模板(迁移用)。 */
68
+ /** 多条设置按空行拼成一条模板(CLI 便捷入口用)。 */
87
69
  function joinEntries(list?: string[]): string {
88
70
  return (list || []).join('\n\n');
89
71
  }
@@ -99,156 +81,17 @@ function clampTemplate(v: unknown): string {
99
81
  return s.length > MAX_BLOCK_TEMPLATE_LEN ? s.slice(0, MAX_BLOCK_TEMPLATE_LEN) : s;
100
82
  }
101
83
 
102
- /** 迁移只接受「新语法」模板:旧语法/语法错误的旧模板不进入新列表(旧模板不保证可用)。 */
103
- function migratableTemplate(v: unknown): string {
104
- const t = clampTemplate(v);
105
- if (!t) return '';
106
- return validateTemplate(t).ok ? t : '';
107
- }
108
-
109
- /**
110
- * 把旧模板写进某区块的列表(只有内容有效且不同于内置模板时才建条目)。
111
- * @param {object} lists 归一化后的 lists(就地修改)
112
- */
113
- function applyMigration(lists: BlockLists, blockId: string, template: unknown, name: string = '迁移模板'): void {
114
- const def = BLOCK_DEFS.find((d) => d.id === blockId);
115
- const t = migratableTemplate(template);
116
- if (!def || !t || t === def.defaultTemplate) return;
117
- const builtin = lists[blockId]!.list.find((x) => x.id === BUILTIN_TEMPLATE_ID)!;
118
- lists[blockId] = {
119
- active: LEGACY_ENTRY_ID,
120
- list: [builtin, { id: LEGACY_ENTRY_ID, name, template: t, builtin: false }],
121
- };
122
- }
123
-
124
- /**
125
- * 把旧 rule 区块的模板内容并入 ack:done 指令与收尾要求只保留 ack 一个出口。
126
- * 合并后的条目设为生效;原 ack 生效模板作为基底一起保留——内容不静默丢。
127
- */
128
- function mergeRuleIntoAck(lists: BlockLists, template: unknown, name: string = '迁移:原 rule(已并入 ack)'): void {
129
- const def = BLOCK_DEFS.find((d) => d.id === 'ack')!;
130
- const t = migratableTemplate(template);
131
- if (!def || !t) return;
132
- const ack = lists.ack!; // BlockLists 恒含全部 BLOCK_DEFS 区块(normalize 保证)
133
- const builtin = ack.list.find((x) => x.id === BUILTIN_TEMPLATE_ID) || {
134
- id: BUILTIN_TEMPLATE_ID,
135
- name: BUILTIN_TEMPLATE_NAME,
136
- template: def.defaultTemplate,
137
- builtin: true,
138
- };
139
- const current = ack.list.find((x) => x.id === ack.active) || builtin;
140
- const base = String(current.template || '').trim() || def.defaultTemplate;
141
- if (base.includes(t)) return; // 同一条内容已在 ack 里,不重复拼接
142
- const rest = ack.list.filter((x) => x.id !== BUILTIN_TEMPLATE_ID && x.id !== current.id);
143
- lists.ack = {
144
- active: RULE_LEGACY_ENTRY_ID,
145
- list: [
146
- builtin,
147
- { id: RULE_LEGACY_ENTRY_ID, name, template: `${base}\n\n${t}`, builtin: false },
148
- ...rest,
149
- ],
150
- };
151
- }
152
-
153
- /** 已落盘的 blockTemplates 里若还带 rule:读时并入 ack(之后保存自然不再写 rule 键)。 */
154
- function absorbStoredRule(stored: unknown): BlockLists {
155
- const lists = normalizeBlockTemplateLists(stored);
156
- const rule = stored && typeof stored === 'object' && !Array.isArray(stored)
157
- ? (stored as Record<string, any>).rule
158
- : null;
159
- if (!rule || typeof rule !== 'object') return lists;
160
- const texts = (Array.isArray(rule.list) ? rule.list : [])
161
- .filter((x: any) => x && !x.builtin && x.id !== BUILTIN_TEMPLATE_ID)
162
- .map((x: any) => migratableTemplate(x.template))
163
- .filter(Boolean);
164
- if (!texts.length && typeof rule.template === 'string') {
165
- const t = migratableTemplate(rule.template);
166
- if (t) texts.push(t);
167
- }
168
- const uniq = [...new Set(texts)];
169
- if (uniq.length) mergeRuleIntoAck(lists, uniq.join('\n\n'));
170
- return normalizeBlockTemplateLists(lists);
171
- }
172
-
173
- /**
174
- * 旧库迁移:没有 `lt.blockTemplates` 时,把旧键折算成每区块列表。
175
- * 优先级:旧「整体模板」的当前启用项 > 旧 `lt.xmlBlocks` > 旧的单项键。
176
- * 旧 rule 模板(整体模板 / xmlBlocks / lt.taskSuffix)统一并入 ack,不再单独成块。
177
- */
178
- function migrateLegacy(conn: DbApi): { lists: BlockLists; appendMode: string } {
179
- const lists = defaultBlockTemplateLists();
180
- let legacyRule = '';
181
-
182
- // 1) 旧「整体模板集合 + activePromptTemplate」:只迁移当前启用模板(其它整组模板丢弃)
183
- const templates = readSetting(conn, KEYS.promptTemplates);
184
- let appendMode = clampAppendMode(readSetting(conn, KEYS.appendMode));
185
- if (Array.isArray(templates) && templates.length) {
186
- const wanted = String(readSetting(conn, KEYS.activePromptTemplate) || '').trim();
187
- const active = templates.find((t: any) => t && t.id === wanted) || templates[0];
188
- if (active && typeof active === 'object') {
189
- const blocks = active.blocks && typeof active.blocks === 'object' ? active.blocks : {};
190
- for (const def of BLOCK_DEFS) {
191
- const b = blocks[def.id];
192
- if (b && typeof b === 'object' && typeof b.template === 'string') {
193
- applyMigration(lists, def.id, b.template);
194
- }
195
- }
196
- const b = blocks.rule;
197
- if (b && typeof b === 'object' && typeof b.template === 'string') legacyRule = b.template;
198
- if (active.appendMode === 'plain' || active.appendMode === 'xml') appendMode = active.appendMode;
199
- }
200
- }
201
-
202
- // 2) 旧 xmlBlocks(v3 的 { [id]: { enabled, template } }):逐块迁移有效模板
203
- const xmlBlocks = readSetting(conn, KEYS.xmlBlocks);
204
- if (xmlBlocks && typeof xmlBlocks === 'object' && !Array.isArray(xmlBlocks)) {
205
- for (const def of BLOCK_DEFS) {
206
- const b = xmlBlocks[def.id];
207
- // 已由整体模板迁移过的不再覆盖(优先级更高)
208
- if (lists[def.id]!.active !== BUILTIN_TEMPLATE_ID) continue;
209
- if (b && typeof b === 'object' && typeof b.template === 'string') {
210
- applyMigration(lists, def.id, b.template);
211
- }
212
- }
213
- const b = xmlBlocks.rule;
214
- if (!legacyRule && b && typeof b === 'object' && typeof b.template === 'string') {
215
- legacyRule = b.template;
216
- }
217
- }
218
-
219
- // 3) 旧的单项键(对应区块仍只有内置时生效)
220
- if (lists.context!.active === BUILTIN_TEMPLATE_ID) {
221
- applyMigration(lists, 'context', clampDeliveryTemplate(readSetting(conn, KEYS.deliveryTemplate)));
222
- }
223
- if (lists.attachment!.active === BUILTIN_TEMPLATE_ID) {
224
- applyMigration(lists, 'attachment', clampAttachTemplate(readSetting(conn, KEYS.attachTemplate)));
225
- }
226
- if (lists.ack!.active === BUILTIN_TEMPLATE_ID) {
227
- applyMigration(lists, 'ack', joinEntries(clampAckPromptList(readSetting(conn, KEYS.ackPrompt))));
228
- }
229
- if (!legacyRule) {
230
- const raw = readSetting(conn, KEYS.taskSuffix);
231
- const list: unknown[] = Array.isArray(raw) ? raw : raw == null ? [] : [raw];
232
- legacyRule = joinEntries(list.map((x) => String(x ?? '').trim()).filter(Boolean) as string[]);
233
- }
234
- mergeRuleIntoAck(lists, legacyRule);
235
-
236
- return { lists: normalizeBlockTemplateLists(lists), appendMode };
237
- }
238
-
239
84
  /**
240
- * 读「每区块模板列表 + 全局追加模式」。
241
- * 有 `lt.blockTemplates` 就以它为准;否则从旧键一次性折算(不落盘,写入口见 setLtSettings)。
85
+ * 读「每区块模板列表 + 全局追加模式」(**纯读 + 纯校验**)。
86
+ * `lt.blockTemplates` 恒存在(open.ts 的 ensurePromptTemplates 首启落库);
87
+ * 没有行 / 校验不过都是事故,抛错——不合成、不补齐(方案 §4.1)。
242
88
  */
243
89
  function readBlockState(conn: DbApi): { lists: BlockLists; appendMode: string } {
244
90
  const stored = readSetting(conn, KEYS.blockTemplates);
245
- if (stored !== undefined) {
246
- return {
247
- lists: absorbStoredRule(stored),
248
- appendMode: clampAppendMode(readSetting(conn, KEYS.appendMode)),
249
- };
250
- }
251
- return migrateLegacy(conn);
91
+ return {
92
+ lists: normalizeBlockTemplateLists(stored),
93
+ appendMode: clampAppendMode(readSetting(conn, KEYS.appendMode)),
94
+ };
252
95
  }
253
96
 
254
97
  /** 当前生效模板 → 旧版派生字段(仅用于 CLI/旧面板视图兼容,不是读写模型)。 */
@@ -262,7 +105,7 @@ function derivedOf(lists: BlockLists): { ackPrompt: string[]; deliveryTemplate:
262
105
  };
263
106
  }
264
107
 
265
- /** 读全部 lt.* 设置(缺省回落内置默认)。 */
108
+ /** 读全部 lt.* 设置(校验不过即抛——落库行被人为写坏是事故)。 */
266
109
  export function getLtSettings(): Record<string, any> {
267
110
  const conn = db();
268
111
  const { lists, appendMode } = readBlockState(conn);
@@ -275,19 +118,37 @@ export function getLtSettings(): Record<string, any> {
275
118
  }
276
119
 
277
120
  /**
278
- * 保存前的模板语法校验:
279
- * 语法错误 / 旧语法**拒绝保存**并指出模板 / 区块 / 出错位置。理由:渲染期回落到
280
- * 内置模板是兜底(老数据 / 手改库),不该成为正常入口的静默出口。旧语法同样拒绝,
281
- * 避免「保存成功、领取时被悄悄换回内置」的半兼容状态。
121
+ * 保存前的模板校验(方案 §4.2,三道):
122
+ * 1. 语法错误**拒绝保存**并指出模板 / 区块 / 出错位置(渲染期不再回落);
123
+ * 2. 当前生效(active)模板为空 → 拒绝——空模板在运行期是配置错误(S1 起
124
+ * compose 的 assertPluginList 直接抛),不许「保存成功、领取时整次失败」;
125
+ * 3. 变量白名单:全局段集 + 点路径全路径命中 fields 并集(落地裁决见方案 §4.2 补记;
126
+ * `params` 动态键放行,`{{#each}}` 块内放行但 each 目标必须已声明)。
282
127
  */
283
128
  function assertBlockTemplatesValid(lists: BlockLists): void {
284
- for (const def of BLOCK_DEFS) {
285
- for (const item of lists[def.id]!.list) {
286
- if (!item.template) continue; // 空模板合法(rule / 用户主动清空)
129
+ const scope = globalTemplateVarScope();
130
+ for (const blockId of PROMPT_BLOCK_IDS) {
131
+ const b = lists[blockId]!;
132
+ const label = blockLabelOf(blockId);
133
+ for (const item of b.list) {
134
+ if (!item.template) continue; // 非 active 的空条目合法(不渲染,仅存档)
287
135
  const r = validateTemplate(item.template);
288
136
  if (!r.ok) {
289
137
  throw badInput(
290
- `提示词模板「${item.name}」的「${def.label}」区块语法错误:${r.error}`
138
+ `提示词模板「${item.name}」的「${label}」区块语法错误:${r.error}`
139
+ );
140
+ }
141
+ }
142
+ // 生效模板的空 / 变量白名单
143
+ const active = b.list.find((x) => x.id === b.active);
144
+ if (active && !active.template.trim()) {
145
+ throw badInput(`「${label}」区块当前生效的模板「${active.name}」是空的:换回内置或改成有内容的模板后再保存`);
146
+ }
147
+ if (active && active.template) {
148
+ const undeclared = undeclaredTemplateVars(active.template, scope.allowedSegments, scope.fieldKeys);
149
+ if (undeclared.length) {
150
+ throw badInput(
151
+ `「${label}」区块的生效模板「${active.name}」引用了未声明的变量:${undeclared.join('、')}。可用变量见设置页「插入变量」目录`
291
152
  );
292
153
  }
293
154
  }
@@ -297,15 +158,13 @@ function assertBlockTemplatesValid(lists: BlockLists): void {
297
158
  /**
298
159
  * 命令行便捷入口:把一条模板写入某区块的固定条目(`cli`)并设为生效;
299
160
  * 空模板 = 恢复内置(保留用户其它条目,只把 active 指回 builtin)。
161
+ * 内置条目恒在(normalize 校验保证),直接从现值取——不再按代码重建。
300
162
  */
301
163
  function setCustomActive(lists: BlockLists, blockId: string, template: unknown, { name = '命令行' }: { name?: string } = {}): void {
302
- const b = lists[blockId]!; // BLOCK_DEFS 区块恒存在(normalize/defaultBlockTemplateLists 保证)
303
- const builtin = b.list.find((x) => x.id === BUILTIN_TEMPLATE_ID) || {
304
- id: BUILTIN_TEMPLATE_ID,
305
- name: BUILTIN_TEMPLATE_NAME,
306
- template: BLOCK_DEFS.find((d) => d.id === blockId)!.defaultTemplate,
307
- builtin: true,
308
- };
164
+ const b = lists[blockId]; // normalize 保证全部区块存在
165
+ if (!b) throw badInput(`未知提示词区块:${blockId}`);
166
+ const builtin = b.list.find((x) => x.id === BUILTIN_TEMPLATE_ID);
167
+ if (!builtin) throw badInput(`「${blockLabelOf(blockId)}」区块缺内置条目(落库行被写坏)`);
309
168
  const t = clampTemplate(template);
310
169
  if (!t) {
311
170
  lists[blockId] = { active: BUILTIN_TEMPLATE_ID, list: b.list };
@@ -346,23 +205,33 @@ export function setLtSettings(patch: LtSettingsPatch = {}): Record<string, any>
346
205
  const current = readBlockState(conn);
347
206
  let lists = current.lists;
348
207
 
349
- // 新模型:按区块合并(只传某个区块时不动其它区块的列表)。
208
+ // 新模型:按区块合并(只传某个区块时不动其它区块的列表),整体过纯校验。
209
+ // 历史 rule 键已下线:patch 里带 rule 直接忽略(§11 不做旧配置兼容)。
350
210
  if (patch.blockTemplates !== undefined) {
351
211
  const raw = patch.blockTemplates as Record<string, any> | undefined;
352
212
  const merged = { ...lists };
353
213
  if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
354
- for (const def of BLOCK_DEFS) {
355
- if (raw[def.id] !== undefined) merged[def.id] = raw[def.id];
214
+ for (const blockId of PROMPT_BLOCK_IDS) {
215
+ if (raw[blockId] !== undefined) merged[blockId] = raw[blockId];
216
+ }
217
+ // 内置不可改(§4.2 第 1 道):被 patch 的区块里,builtin 条目一律替换回
218
+ // 库内现值(含 name / template / 位置)——落库后 builtin 是真数据,
219
+ // 客户端传什么都不生效;patch 缺 builtin 条目时补回。
220
+ for (const blockId of PROMPT_BLOCK_IDS) {
221
+ const next = merged[blockId];
222
+ const cur = lists[blockId];
223
+ if (raw[blockId] === undefined || !next || !cur) continue;
224
+ const curBuiltin = cur.list.find((x) => x.id === BUILTIN_TEMPLATE_ID)!;
225
+ const rest = (Array.isArray(next.list) ? next.list : []).filter(
226
+ (x: any) => x && x.id !== BUILTIN_TEMPLATE_ID && x.builtin !== true,
227
+ );
228
+ merged[blockId] = { ...next, list: [curBuiltin, ...rest] };
356
229
  }
357
230
  }
358
- // 旧客户端仍带 rule:并入 ack(内容不静默丢),写盘后不再保留 rule 键。
359
- lists =
360
- raw && typeof raw === 'object' && !Array.isArray(raw) && raw.rule !== undefined
361
- ? absorbStoredRule({ ...merged, rule: raw.rule })
362
- : normalizeBlockTemplateLists(merged);
231
+ lists = normalizeBlockTemplateLists(merged);
363
232
  }
364
233
 
365
- // 旧 CLI 便捷入口:写入对应区块的 `cli` 条目并启用(空 = 恢复内置)。
234
+ // CLI 便捷入口:写入对应区块的 `cli` 条目并启用(空 = 恢复内置)。
366
235
  if (patch.ackPrompt !== undefined) {
367
236
  setCustomActive(lists, 'ack', joinEntries(clampAckPromptList(patch.ackPrompt)));
368
237
  }
@@ -373,7 +242,6 @@ export function setLtSettings(patch: LtSettingsPatch = {}): Record<string, any>
373
242
  setCustomActive(lists, 'attachment', clampAttachTemplate(patch.attachTemplate));
374
243
  }
375
244
 
376
- lists = normalizeBlockTemplateLists(lists);
377
245
  assertBlockTemplatesValid(lists);
378
246
 
379
247
  const appendMode =
@@ -399,4 +267,6 @@ export function settingsView(): Record<string, any> {
399
267
  };
400
268
  }
401
269
 
402
- export { DEFAULT_TIMEOUT_SEC, MAX_TIMEOUT_SEC, DEFAULT_ACK_PROMPT };
270
+ export { DEFAULT_TIMEOUT_SEC, MAX_TIMEOUT_SEC } from '../store-io.js';
271
+ export { DEFAULT_ACK_PROMPT } from '../task-templates.js';
272
+ export type { BlockTemplateList };
@@ -2,23 +2,21 @@
2
2
  // settings.ackPrompt 的存储形态、条数/长度上限与缺省值,以及交付模板的钳制都在这里。
3
3
  // 完成后的汇报要求与收尾要求统一落在 ack 区块(DEFAULT_ACK_PROMPT,设置页可见可改);
4
4
  // 旧 rule 区块已删除,其内容迁移时并入 ack。
5
+
6
+ /**
7
+ * 默认 ack:完成任务就调用 localtask done 回填结果(任务 51 的职责合并决定)。
8
+ * v6 起唯一归属在本文件——shared/prompt-blocks 不再持有任何模板正文,模板真相在
9
+ * 出厂快照 blockTemplates.json;这里的文本 ≡ 快照 ack 段内置文本,一致性由
10
+ * tests/unit/prompt-ensure.test.mjs 对账;改任何一处都要同步另一处并跑单测。
11
+ */
12
+ export const DEFAULT_ACK_PROMPT =
13
+ '完成之后必须调用 nx-kv localtask done --id {{task.id}} --summary "<完成总结>" 汇报结果。';
14
+
5
15
  import {
6
16
  DEFAULT_APPEND_MODE,
7
- DEFAULT_ACK_PROMPT,
8
17
  APPEND_MODES,
9
18
  } from '../../shared/prompt-blocks.js';
10
19
 
11
- export { DEFAULT_ACK_PROMPT };
12
-
13
- // ─── ack 完成总结提示词(settings.ackPrompt)─────────────────────────
14
- //
15
- // agent 完成任务时写的**完成总结(ack)**该按什么格式——收进 ack 区块的模板列表,
16
- // 多条按空行拼成一段,随领取交付的 instruction 一起给到 agent。
17
- // **缺省就是默认汇报要求**(可见、可改;显式 '' / [] 恢复内置而不是关掉)。
18
- // done 指令只存在于 ack 区块(旧 rule 已删除,其内容迁移时并入这里)。
19
- /** 默认 ack:完成任务就调用 localtask done 回填结果(任务 51 的职责合并决定)。
20
- * 文案与区块默认模板同源(shared/prompt-blocks.js),上面已重导出。 */
21
-
22
20
  /** 交付上下文模板(任务 #62)的长度上限——防把整本书塞进设置。 */
23
21
  export const MAX_DELIVERY_TEMPLATE_LEN = 8000;
24
22
 
@@ -0,0 +1,90 @@
1
+ {
2
+ "context": {
3
+ "active": "builtin",
4
+ "list": [
5
+ {
6
+ "id": "builtin",
7
+ "name": "系统内置",
8
+ "template": "{{#if repo}}\n{{#if repo.intro}}\n〔项目介绍 · {{repo.name}}〕\n{{repo.intro}}\n{{/if}}\n{{#if repo.docs}}\n〔项目文档〕按需取用:nx-kv docs get --ref <refId>\n{{#each repo.docs}}\n - {{#if desc}}{{desc}}{{else}}{{#if title}}{{title}}{{else}}未命名文档{{/if}}{{/if}}{{#if note}} # {{note}}{{/if}}\n 取用:nx-kv docs get --ref {{refId}}\n{{/each}}\n{{/if}}\n{{#if repo.intro}}{{else}}{{#if repo.docs}}{{else}}\n〔项目上下文 · {{repo.name}}〕已登记为本机仓库({{repo.key}}),但没有项目介绍文档:nx-kv repo doc add {{repo.key}} --ref <refId>\n{{/if}}{{/if}}\n{{/if}}\n{{#if repo}}{{else}}{{#if cwd}}\n〔项目上下文〕工作目录 {{cwd}} 未登记为本机仓库,本次交付没有项目介绍 / 组上下文。登记(不需要 .git,给 key 即可):nx-kv repo add \"{{cwd}}\" --key <key>\n{{/if}}{{/if}}\n{{#if group}}\n〔项目组上下文 · {{group.name}}〕\n{{#if group.desc}}\n组定位:{{group.desc}}\n{{/if}}\n{{#if group.note}}\n本项目在组里的位置:{{group.note}}\n{{/if}}\n{{#if group.introRefId}}\n组介绍:{{#if group.introDesc}}{{group.introDesc}}{{else}}(无描述){{/if}}\n 取用:nx-kv docs get --ref {{group.introRefId}}\n{{/if}}\n{{#if group.peers}}\n组内成员:\n{{#each group.peers}}\n - {{name}}:{{#if note}}{{note}}{{else}}(无组内描述){{/if}}{{#if path}}({{path}}){{/if}}\n{{/each}}\n{{/if}}\n{{#if group.docs}}\n组文档(按需取用):\n{{#each group.docs}}\n - {{#if desc}}{{desc}}{{else}}{{#if title}}{{title}}{{else}}未命名文档{{/if}}{{/if}}{{#if note}} # {{note}}{{/if}}\n 取用:nx-kv docs get --ref {{refId}}\n{{/each}}\n{{/if}}\n{{/if}}\n{{#if refRepos.count}}\n参考仓库(可直接读取,共 {{refRepos.count}} 个):\n{{#each refRepos.list}}\n - {{name}}{{#if path}}({{path}}){{/if}}{{#if note}} # {{note}}{{/if}}\n{{/each}}\n{{/if}}",
9
+ "builtin": true
10
+ }
11
+ ]
12
+ },
13
+ "attachment": {
14
+ "active": "builtin",
15
+ "list": [
16
+ {
17
+ "id": "builtin",
18
+ "name": "系统内置",
19
+ "template": "{{#if attach}}\n〔附件〕本任务包含 {{attach.count}} 个附件(正文内嵌 {{attach.inlineCount}} · 附件区 {{attach.areaCount}})。请先识别附件内容(图片先看图、文档先读内容、文件夹先列目录)再开始处理,不要跳过附件。\n\n附件清单:\n{{#each attach.list}}\n - [{{originLabel}}] {{kindLabel}} {{name}}{{#if sizeText}}({{sizeText}}){{/if}}:{{#if file}}{{#if file.exists}}{{file.localPath}}{{else}}未同步到本地(fileId {{file.fileId}}){{/if}}{{/if}}{{#if url}}{{url.href}}{{/if}}{{#if task}}{{#if task.resolved}}#{{task.seq}} {{task.title}} · 地址 {{task.address}}({{task.statusLabel}}){{else}}地址 {{task.address}}({{task.statusLabel}}){{/if}}{{/if}}{{#if ref}}{{ref.title}}{{/if}}{{#if mdfile}}{{mdfile.absPath}}{{#if mdfile.missing}}(源文件已不在){{/if}}{{/if}}{{#if folder}}{{folder.absPath}}{{#if folder.missing}}(目录已不在){{/if}}{{/if}}{{#if note}} # {{note}}{{/if}}\n{{/each}}\n\n取用方式:\n{{#each attach.list}}\n - {{kindLabel}} 《{{name}}》:{{usage}}\n{{/each}}\n{{#each attach.list}}{{#if mdfile}}{{#if mdfile.content}}〔外部 md · {{name}}〕({{mdfile.absPath}}{{#if mdfile.truncated}},已截断{{/if}}{{#if mdfile.stale}},内容有变化{{/if}}):\n\n{{mdfile.content}}\n\n{{/if}}{{/if}}{{/each}}\n{{#each attach.list}}{{#if ref}}{{#if ref.content}}〔文档原文 · {{ref.title}}〕:\n\n{{ref.content}}\n\n{{/if}}{{/if}}{{/each}}\n{{/if}}",
20
+ "builtin": true
21
+ }
22
+ ]
23
+ },
24
+ "timecheck": {
25
+ "active": "builtin",
26
+ "list": [
27
+ {
28
+ "id": "builtin",
29
+ "name": "系统内置",
30
+ "template": "{{#if goal.check}}\n{{goal.check}}\n{{/if}}\n{{#if goal.statusLine}}\n{{goal.statusLine}}\n{{/if}}",
31
+ "builtin": true
32
+ }
33
+ ]
34
+ },
35
+ "goalhint": {
36
+ "active": "builtin",
37
+ "list": [
38
+ {
39
+ "id": "builtin",
40
+ "name": "系统内置",
41
+ "template": "{{#if goal.check}}\n〔特殊功能提示 · 时间目标〕任务 #{{task.id}} 正在计时:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),{{#if goal.reached}}已到点(超时 {{formatDuration goal.overtimeSec}}){{else}}剩余 {{goal.remainingHuman}}{{/if}}。\n{{#if goal.reached}}——时间已到:可以收口,把改动收敛成可交付状态,补验证与说明后按 ack 段 done。\n{{else}}{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}——已过 2/3:进入收尾整理(收敛改动 / 补验证 / 写清遗留),别开新战线。\n{{else}}{{#if (gte (percent goal.elapsedSec goal.durationSec) 50)}}——已过半:先确认主线走到哪,剩余时间只做收尾必需项。\n{{else}}——时间尚足:先做主线,再补细节。{{/if}}{{/if}}{{/if}}\n{{/if}}",
42
+ "builtin": true
43
+ }
44
+ ]
45
+ },
46
+ "doneguard": {
47
+ "active": "builtin",
48
+ "list": [
49
+ {
50
+ "id": "builtin",
51
+ "name": "系统内置",
52
+ "template": "{{#if goal.blocked}}\n〔完成门禁 · 时间未到〕任务 #{{task.id}} 还不能 done:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),剩余 {{goal.remainingHuman}}。\n- 现在可做:{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}收尾整理(收敛改动 / 补验证 / 写清遗留),或派 sub agent 提出新的需求继续推进{{else}}继续推进主线,并派 sub agent 重新提出新的需求{{/if}}。\n- 每轮推进先跑:nx-kv timegoal check --task {{goal.goalKey}} --summary \"<本轮现状>\"\n- 到点后再:nx-kv localtask done --id {{task.id}} --summary \"<完成总结>\"\n{{/if}}",
53
+ "builtin": true
54
+ }
55
+ ]
56
+ },
57
+ "ext": {
58
+ "active": "builtin",
59
+ "list": [
60
+ {
61
+ "id": "builtin",
62
+ "name": "系统内置",
63
+ "template": "{{#if ext.count}}\n本队列({{ext.topic}})还有 {{ext.count}} 条待领取任务:\n{{#each ext.list}}\n - #{{id}} {{title}}\n{{/each}}\n先完成当前任务,再领取下一条;不要因为后面还有活就提前收尾或分心。\n{{/if}}",
64
+ "builtin": true
65
+ }
66
+ ]
67
+ },
68
+ "ack": {
69
+ "active": "builtin",
70
+ "list": [
71
+ {
72
+ "id": "builtin",
73
+ "name": "系统内置",
74
+ "template": "完成之后必须调用 nx-kv localtask done --id {{task.id}} --summary \"<完成总结>\" 汇报结果。",
75
+ "builtin": true
76
+ }
77
+ ]
78
+ },
79
+ "getloop": {
80
+ "active": "builtin",
81
+ "list": [
82
+ {
83
+ "id": "builtin",
84
+ "name": "系统内置",
85
+ "template": "{{#if getloop}}\n{{#if task}}不要直接结束本轮:完成上面的任务({{task.id}})之后,继续调用 nx-kv localtask get 领取下一条任务。队列里有活会立即返回;{{#if (gt getloop.waitMinutes 0)}}没活时每次最多阻塞 {{getloop.waitMinutes}} 分钟,直到 get 返回 timeout 为止。{{/if}}{{/if}}\n{{/if}}",
86
+ "builtin": true
87
+ }
88
+ ]
89
+ }
90
+ }
@@ -0,0 +1,20 @@
1
+ // AUTO-GENERATED —— 由 scripts/gen-actions.mjs 生成,勿手改。
2
+ //
3
+ // 收录本目录下所有继承 ActionBase 的类。**加一条 action = 新建一个文件 +
4
+ // 跑 `pnpm gen`**;模块的 index.ts 不需要改。
5
+ // 新鲜度由 tests/unit/action-registry.test.mjs 对账。
6
+
7
+ import type { ActionBase } from '../../../runtime/action-base.js';
8
+ import type { Container } from '../../../runtime/container.js';
9
+ import { PromptOrderAction } from './prompt-order.js';
10
+ import { PromptRegistryAction } from './prompt-registry.js';
11
+
12
+ /** 本模块的全部 action 类(容器按这个顺序建实例)。 */
13
+ export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
14
+ PromptOrderAction,
15
+ PromptRegistryAction,
16
+ ];
17
+
18
+ // 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
19
+ export { PromptOrderAction };
20
+ export { PromptRegistryAction };
@@ -0,0 +1,38 @@
1
+ // prompt.order —— 顺序数组写入(方案 §5.1 / §5.3)。
2
+ //
3
+ // 唯一真相是数组:恰好包含全部插件 id 各一次、无未知 id;不合法即拒绝保存
4
+ // (UI 拖动重排后 PUT 这里,CLI 渲染顺序随之变化)。
5
+ import { action } from '../../../runtime/action-decorator.js';
6
+ import { z } from 'zod';
7
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
8
+ import { getDb } from '../../../core/db/index.js';
9
+ import { writeSettingRaw } from '../../../core/db/settings.js';
10
+ import { assertOrder } from '../../../shared/prompt-plugin.js';
11
+ import { buildDeliveryPlugins } from '../factory.js';
12
+ import { PROMPT_ORDER_KEY } from '../keys.js';
13
+
14
+ /** prompt.order 的入参契约。 */
15
+ const input = z.object({
16
+ order: z.array(z.string()).describe('顺序数组:恰好包含全部插件 id 各一次'),
17
+ });
18
+
19
+ export class PromptOrderAction extends ActionBase<typeof input> {
20
+ @action({
21
+ id: 'prompt.order',
22
+ cli: ['prompt', 'order'],
23
+ http: ['PUT', '/api/prompt/order'],
24
+ summary: '写提示词插件顺序数组(唯一真相;必须恰好包含全部 8 个插件 id 各一次)',
25
+ input,
26
+ render: (d: any) => `顺序已保存:${d.order.join(' → ')}`,
27
+ })
28
+ override async run(ctx: ActionInput<this['_input']>) {
29
+ const plugins = buildDeliveryPlugins({}, {
30
+ groupCtx: null, attach: null, queueInfo: null, loopText: '', waitMinutes: 0,
31
+ });
32
+ // 只校验 id 集合不变量(模板为空串不影响 assertOrder / id 检查)
33
+ assertOrder(plugins, ctx.order);
34
+ const conn = getDb();
35
+ writeSettingRaw(conn, PROMPT_ORDER_KEY, ctx.order);
36
+ return { order: ctx.order };
37
+ }
38
+ }
@@ -0,0 +1,51 @@
1
+ // prompt.registry —— 注册表外露(方案 §5.3 / §7):三端同源的唯一出口。
2
+ //
3
+ // CLI(nx-kv prompt registry)、HTTP(GET /api/prompt/registry)与设置页
4
+ // 消费同一份 uiDescriptor():字段目录、生效模板、顺序位全部从插件声明 +
5
+ // DB 生效项派生,前端不再有手工副本(placeholders.ts / prompt-template-params.ts)。
6
+ //
7
+ // deps 全空:uiDescriptor 只读文本态(get())与 schema 派生面(fields/writes),
8
+ // 结构态 data() 永不被调用——不需要宿主取数。
9
+ import { action } from '../../../runtime/action-decorator.js';
10
+ import { z } from 'zod';
11
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
12
+ import { getDb } from '../../../core/db/index.js';
13
+ import { readSettingRaw } from '../../../core/db/settings.js';
14
+ import { resolveBlockTemplates } from '../../../shared/prompt-blocks.js';
15
+ import { uiDescriptor } from '../../../shared/prompt-plugin.js';
16
+ import { buildDeliveryPlugins, PLUGIN_IDS } from '../factory.js';
17
+ import { templateBundle } from '../template-bundle.js';
18
+ import { ensurePromptTemplates } from '../ensure.js';
19
+ import { LT_BLOCK_TEMPLATES, PROMPT_ORDER_KEY } from '../keys.js';
20
+
21
+ /** prompt.registry 的入参契约(无参)。 */
22
+ const input = z.object({});
23
+
24
+ export class PromptRegistryAction extends ActionBase<typeof input> {
25
+ @action({
26
+ id: 'prompt.registry',
27
+ cli: ['prompt', 'registry'],
28
+ http: ['GET', '/api/prompt/registry'],
29
+ summary: '提示词插件注册表:8 段的生效模板 / 变量目录 / 顺序位(三端同源,uiDescriptor 派生)',
30
+ input,
31
+ render: (d: any) =>
32
+ d.plugins.map((p: any) => `${p.order} ${p.id}(${p.label},标签 ${p.tag})`).join(';'),
33
+ })
34
+ override async run(_ctx: ActionInput<this['_input']>) {
35
+ const conn = getDb();
36
+ // 自举兜底(幂等,版本相同零写):注册表出口不依赖 localtask 的 open 链——
37
+ // 纯 core store 上也必须能出注册表(方案的「全仓唯一落库调用点」仍是 open.ts)。
38
+ let raw = readSettingRaw(conn, LT_BLOCK_TEMPLATES);
39
+ if (raw === undefined) {
40
+ ensurePromptTemplates(conn);
41
+ raw = readSettingRaw(conn, LT_BLOCK_TEMPLATES);
42
+ }
43
+ const resolved = resolveBlockTemplates(raw ?? templateBundle());
44
+ const plugins = buildDeliveryPlugins(resolved as any, {
45
+ groupCtx: null, attach: null, queueInfo: null, loopText: '', waitMinutes: 0,
46
+ });
47
+ const orderIds = readSettingRaw(conn, PROMPT_ORDER_KEY);
48
+ const pluginsDesc = uiDescriptor(plugins, Array.isArray(orderIds) ? orderIds : PLUGIN_IDS);
49
+ return { plugins: pluginsDesc };
50
+ }
51
+ }