nx-kv 0.63.0 → 0.64.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 (183) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +6 -5
  3. package/package.json +2 -2
  4. package/src/core/attachmentdb/docs.ts +3 -6
  5. package/src/core/attachmentdb/query.ts +2 -2
  6. package/src/core/attachmentdb/relations.ts +36 -21
  7. package/src/core/db/import-json/refs.ts +17 -19
  8. package/src/core/db/import-json/repos.ts +4 -8
  9. package/src/core/db/migrations/index.ts +2 -0
  10. package/src/core/db/migrations/v13.sql +24 -0
  11. package/src/core/db/seed-templates.ts +15 -4
  12. package/src/core/db/version.ts +3 -1
  13. package/src/modules/docs/actions/_manifest.generated.ts +0 -3
  14. package/src/modules/docs/actions/doc-attach.ts +0 -1
  15. package/src/modules/docs/actions/docs-bindings.ts +2 -5
  16. package/src/modules/docs/actions/docs-link.ts +1 -2
  17. package/src/modules/docs/attach.ts +1 -36
  18. package/src/modules/docs/bound-docs.ts +2 -2
  19. package/src/modules/docs/brief.ts +0 -2
  20. package/src/modules/docs/docref.ts +7 -17
  21. package/src/modules/docs/knowledge-md.ts +1 -1
  22. package/src/modules/docs/knowledge.ts +48 -45
  23. package/src/modules/docs/ref-sync.ts +1 -5
  24. package/src/modules/docs/refs.ts +7 -10
  25. package/src/modules/docs/service.ts +1 -3
  26. package/src/modules/localtask/actions/localtask-config.ts +19 -58
  27. package/src/modules/localtask/actions/localtask-prune.ts +7 -2
  28. package/src/modules/localtask/repo/open.ts +0 -4
  29. package/src/modules/localtask/repo/settings.ts +20 -196
  30. package/src/modules/localtask/task-lifecycle.ts +7 -9
  31. package/src/modules/localtask/task-templates.ts +4 -4
  32. package/src/modules/localtask/task-view.ts +4 -0
  33. package/src/modules/localtask/topics.ts +30 -28
  34. package/src/modules/promptplug/actions/_manifest.generated.ts +0 -3
  35. package/src/modules/promptplug/actions/prompt-registry.ts +19 -30
  36. package/src/modules/promptplug/base.ts +69 -25
  37. package/src/modules/promptplug/compose.ts +40 -23
  38. package/src/modules/promptplug/factory.ts +91 -59
  39. package/src/modules/promptplug/index.ts +25 -11
  40. package/src/modules/promptplug/plugins/ack.ts +28 -0
  41. package/src/modules/promptplug/plugins/attachment.ts +237 -19
  42. package/src/modules/promptplug/plugins/context.ts +124 -30
  43. package/src/modules/promptplug/plugins/doneguard.ts +33 -0
  44. package/src/modules/promptplug/plugins/ext.ts +34 -11
  45. package/src/modules/promptplug/plugins/getloop.ts +29 -8
  46. package/src/modules/promptplug/plugins/goal-shape.ts +34 -0
  47. package/src/modules/promptplug/plugins/goalhint.ts +33 -0
  48. package/src/modules/promptplug/plugins/timecheck.ts +33 -0
  49. package/src/modules/promptplug/registry.ts +99 -0
  50. package/src/modules/promptplug/schema-bridge.ts +77 -13
  51. package/src/modules/repos/actions/board-rekey.ts +1 -1
  52. package/src/modules/repos/actions/repo-doc-add.ts +2 -3
  53. package/src/modules/repos/boards/core.ts +1 -13
  54. package/src/modules/repos/boards/docs.ts +2 -12
  55. package/src/modules/repos/boards/members.ts +2 -14
  56. package/src/modules/repos/boards/transfer.ts +2 -11
  57. package/src/modules/repos/keys.ts +4 -11
  58. package/src/modules/repos/repo/refs.ts +3 -5
  59. package/src/modules/repos/repo/repos.ts +12 -13
  60. package/src/modules/repos/repo/rows.ts +2 -8
  61. package/src/modules/repos/service/context.ts +0 -2
  62. package/src/modules/repos/service/crud.ts +1 -4
  63. package/src/modules/repos/service/store.ts +6 -7
  64. package/src/modules/repos/transfer/export.ts +3 -8
  65. package/src/modules/repos/transfer/import.ts +0 -13
  66. package/src/modules/repos/transfer/layout.ts +2 -2
  67. package/src/modules/tasktool/attach-template.ts +3 -3
  68. package/src/modules/tasktool/groupctx.ts +4 -5
  69. package/src/modules/tasktool/plugins/waitgoal-config.ts +5 -6
  70. package/src/modules/tasktool/preview.ts +20 -23
  71. package/src/modules/tasktool/wait.ts +24 -46
  72. package/src/modules/templates/actions/_manifest.generated.ts +3 -0
  73. package/src/modules/templates/actions/templates-reorder.ts +28 -0
  74. package/src/modules/templates/repo/templates.ts +32 -2
  75. package/src/modules/templates/service.ts +45 -0
  76. package/src/shared/prompt-blocks.ts +7 -173
  77. package/src/shared/prompt-plugin.ts +79 -59
  78. package/src/web/frontend/App.tsx +27 -1
  79. package/src/web/frontend/api/cli-tree.json +20 -35
  80. package/src/web/frontend/api/client.generated.ts +22 -32
  81. package/src/web/frontend/components/Introduction/rail.tsx +2 -2
  82. package/src/web/frontend/components/Introduction/use-intro.ts +2 -5
  83. package/src/web/frontend/components/bindings/bind-tags.tsx +1 -3
  84. package/src/web/frontend/components/list-search.tsx +37 -0
  85. package/src/web/frontend/components/md/attach-area.tsx +10 -15
  86. package/src/web/frontend/components/md/live-block.tsx +5 -14
  87. package/src/web/frontend/components/md/md-panes.tsx +3 -19
  88. package/src/web/frontend/modules/list-filter.ts +37 -0
  89. package/src/web/frontend/modules/md/fill-session.ts +36 -0
  90. package/src/web/frontend/modules/md/manage-session.ts +24 -0
  91. package/src/web/frontend/modules/md/new-task-from-template.ts +22 -0
  92. package/src/web/frontend/modules/md/styles/editor.css +5 -12
  93. package/src/web/frontend/modules/md/styles/shell.css +4 -0
  94. package/src/web/frontend/modules/md/task-intent.ts +29 -0
  95. package/src/web/frontend/modules/md/use-templates.ts +8 -0
  96. package/src/web/frontend/modules/prompts/template-preview.ts +12 -20
  97. package/src/web/frontend/modules/refs/api.ts +0 -1
  98. package/src/web/frontend/page/dir/index.tsx +20 -5
  99. package/src/web/frontend/page/dir/task-actions.ts +14 -0
  100. package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
  101. package/src/web/frontend/page/dir/task.tsx +19 -0
  102. package/src/web/frontend/page/doc/api.ts +2 -3
  103. package/src/web/frontend/page/doc/bindings.tsx +46 -16
  104. package/src/web/frontend/page/doc/index.tsx +3 -4
  105. package/src/web/frontend/page/group/index.tsx +65 -117
  106. package/src/web/frontend/page/refs/index.tsx +27 -3
  107. package/src/web/frontend/page/refs/style.css +3 -0
  108. package/src/web/frontend/page/repos/bind-modals.tsx +18 -2
  109. package/src/web/frontend/page/repos/board-admin.tsx +1 -1
  110. package/src/web/frontend/page/repos/index.tsx +4 -8
  111. package/src/web/frontend/page/repos/ref-block.tsx +5 -12
  112. package/src/web/frontend/page/repos/ref-panel.tsx +3 -4
  113. package/src/web/frontend/page/repos/repo-form-modal.tsx +1 -8
  114. package/src/web/frontend/page/repos/repo-table.tsx +4 -29
  115. package/src/web/frontend/page/repos/use-repos-derive.ts +4 -5
  116. package/src/web/frontend/page/settings/api.ts +7 -15
  117. package/src/web/frontend/page/settings/prompt-templates-section.tsx +261 -289
  118. package/src/web/frontend/page/settings/prompt-vars.ts +56 -0
  119. package/src/web/frontend/page/settings/style.css +46 -64
  120. package/src/web/frontend/page/templates/fill.tsx +124 -0
  121. package/src/web/frontend/page/templates/index.tsx +11 -0
  122. package/src/web/frontend/page/templates/manage.tsx +218 -0
  123. package/src/web/frontend/page/templates/style.css +46 -0
  124. package/src/web/frontend/page/templates/template-list.tsx +58 -54
  125. package/src/web/frontend/refs/api.ts +0 -2
  126. package/src/web/frontend/routes/route-eq.ts +22 -0
  127. package/src/web/frontend/routes/templates.ts +20 -0
  128. package/src/web/frontend/style.css +1 -0
  129. package/src/web/frontend/styles/list-search.css +44 -0
  130. package/src/web/frontend/types.ts +5 -1
  131. package/src/web/public/assets/{bar-CYWfxHfm.js → bar-j14ON7uZ.js} +1 -1
  132. package/src/web/public/assets/{composer-launch-Bor4ngrQ.js → composer-launch-DRi9mZE1.js} +1 -1
  133. package/src/web/public/assets/{composer-panel-C7mNI7EW.js → composer-panel-swmDqlPw.js} +1 -1
  134. package/src/web/public/assets/dir-DhsB1ZhL.js +3 -0
  135. package/src/web/public/assets/doc-D4po3sDc.js +6 -0
  136. package/src/web/public/assets/fill-session-fHxQHFaD.js +1 -0
  137. package/src/web/public/assets/group-BxmSNzIB.js +1 -0
  138. package/src/web/public/assets/index-CMjG5NVU.js +2 -0
  139. package/src/web/public/assets/index-uMjSWNVr.css +1 -0
  140. package/src/web/public/assets/list-filter-D-x94TvA.js +1 -0
  141. package/src/web/public/assets/manage-session-CS8UvmUd.js +1 -0
  142. package/src/web/public/assets/md-history-CZUF_FhN.js +39 -0
  143. package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +1 -0
  144. package/src/web/public/assets/refs-TuuoaRs7.js +2 -0
  145. package/src/web/public/assets/refs-zSA2k_45.css +1 -0
  146. package/src/web/public/assets/render-template-body-bXdedFig.js +1 -0
  147. package/src/web/public/assets/repo-form-modal-BD4N37MI.js +1 -0
  148. package/src/web/public/assets/repos-BPeuX4N9.js +12 -0
  149. package/src/web/public/assets/settings-CZJaKLZW.js +1 -0
  150. package/src/web/public/assets/settings-Cc6puKd5.css +1 -0
  151. package/src/web/public/assets/task-DgbbF5gy.js +11 -0
  152. package/src/web/public/assets/task-intent-CX5DZccN.js +1 -0
  153. package/src/web/public/assets/{task-utils-DpnPjZKJ.js → task-utils-bJH1-Cjy.js} +1 -1
  154. package/src/web/public/assets/templates-CBXlwyof.js +11 -0
  155. package/src/web/public/assets/templates-plA8R7jJ.css +1 -0
  156. package/src/web/public/assets/use-rail-drag-ufwy2XZB.js +1 -0
  157. package/src/web/public/index.html +8 -6
  158. package/src/modules/docs/actions/doc-attach-note.ts +0 -32
  159. package/src/modules/promptplug/Template/blockTemplates.json +0 -90
  160. package/src/modules/promptplug/actions/prompt-order.ts +0 -38
  161. package/src/modules/promptplug/ensure.ts +0 -57
  162. package/src/modules/promptplug/keys.ts +0 -9
  163. package/src/modules/promptplug/plugins/readonly-blocks.ts +0 -75
  164. package/src/modules/promptplug/template-bundle.ts +0 -59
  165. package/src/web/frontend/modules/md/template-locks.ts +0 -105
  166. package/src/web/frontend/page/settings/prompt-editor.tsx +0 -279
  167. package/src/web/frontend/page/settings/prompt-rail.tsx +0 -170
  168. package/src/web/public/assets/dir-CcffxXL2.js +0 -3
  169. package/src/web/public/assets/doc-BxWVzWkw.js +0 -6
  170. package/src/web/public/assets/group-C5Yu3oJr.js +0 -1
  171. package/src/web/public/assets/index-BvyZ1MA2.js +0 -2
  172. package/src/web/public/assets/index-Cp-TtHyA.css +0 -1
  173. package/src/web/public/assets/md-history-DejKuR12.js +0 -39
  174. package/src/web/public/assets/refs-DJdKV8_H.css +0 -1
  175. package/src/web/public/assets/refs-VbDnDTV0.js +0 -2
  176. package/src/web/public/assets/repo-form-modal-Dkdvu_uN.js +0 -1
  177. package/src/web/public/assets/repos-CY0eZheu.js +0 -16
  178. package/src/web/public/assets/settings-AwzLRYUu.css +0 -1
  179. package/src/web/public/assets/settings-D3T-vgCl.js +0 -1
  180. package/src/web/public/assets/task-CkCD82h_.js +0 -11
  181. package/src/web/public/assets/templates-BcuCbT4U.js +0 -10
  182. package/src/web/public/assets/templates-gNdtaMI2.css +0 -1
  183. package/src/web/public/assets/use-rail-drag-DMvr8-GE.js +0 -1
@@ -1,52 +1,30 @@
1
- // 本机设置仓储:settings 表的 lt.* 键(超时 / 追加模式 / 每区块模板列表)。
1
+ // 本机设置仓储:settings 表的 lt.* 键(超时 / 追加模式)。
2
2
  //
3
3
  // 为什么走 k/v 而不是宽表:这些键会持续增加,加键零迁移(schema G2 的取舍)。
4
- // value 一律 JSON 文本('240' / '["a","b"]' / '"…"'),读写都在这里序列化。
4
+ // value 一律 JSON 文本('240' / '"xml"'),读写都在这里序列化。
5
5
  // 凭据(token/baseUrl/email/userId/groupId)**绝不进这张表** —— 它们留在 config.json。
6
6
  //
7
- // 提示词模型(v6,唯一基准方案 docs/research/prompt-plugin-single-route.md §4):
8
- // - `lt.blockTemplates` 是唯一权威来源:`{ [blockId]: { active, list } }`,
9
- // 每个区块各自一份模板列表、各自指定生效项;内置条目 `builtin` 常驻不可改。
10
- // 首启落库由 promptplug/ensure.ts 完成(open.ts 挂 ensure)——本文件**不做任何
11
- // 合成与旧键折算**(§4.1 纯校验;旧 lt.* 键、rule 键、数组简写形态已全部下线)。
12
- // - 全局只有 `lt.appendMode`(xml / plain)对所有区块整体生效。
13
- // - 没有落库行 = 事故,抛错(ensure 恒先于本文件的任何读取执行)。
7
+ // 提示词模板模型(#152 重构):
8
+ // - **模板正文的唯一真相是插件类**(modules/promptplug/plugins/*.ts 的 `templates`)。
9
+ // 没有 JSON 注册表、没有 DB seed、没有「每区块 active + list」这套落库模型,
10
+ // 也没有从库里派生出来的镜像——要用正文就读插件类(activeTemplateOf)。
11
+ // - 因此本文件只剩两个真正可写的键:`lt.timeoutSec` 与 `lt.appendMode`。
14
12
  import { db, txw } from './open.js';
15
13
  import { nowMs } from '../../../core/db/time.js';
16
- import { badInput } from '../../../core/errors.js';
17
- import { validateTemplate } from '../../../core/instruction-template.js';
18
14
  import {
19
15
  DEFAULT_TIMEOUT_SEC,
20
16
  MAX_TIMEOUT_SEC,
21
17
  clampTimeoutSec,
22
18
  } from '../store-io.js';
23
- import {
24
- clampAckPromptList,
25
- clampDeliveryTemplate,
26
- clampAttachTemplate,
27
- clampAppendMode,
28
- } from '../task-templates.js';
29
- import {
30
- BUILTIN_TEMPLATE_ID,
31
- MAX_BLOCK_TEMPLATE_LEN,
32
- PROMPT_BLOCK_IDS,
33
- normalizeBlockTemplateLists,
34
- resolveBlockTemplates,
35
- } from '../../../shared/prompt-blocks.js';
36
- import type { BlockLists, BlockTemplateList } from '../../../shared/prompt-blocks.js';
19
+ import { clampAppendMode } from '../task-templates.js';
37
20
  import type { DbApi } from '../../../core/db/driver.js';
38
- import { undeclaredTemplateVars } from '../../../shared/prompt-plugin.js';
39
- import { globalTemplateVarScope, blockLabelOf } from '../../promptplug/index.js';
21
+ import { activeTemplateOf } from '../../promptplug/index.js';
40
22
 
41
23
  const KEYS = {
42
24
  timeoutSec: 'lt.timeoutSec',
43
25
  appendMode: 'lt.appendMode',
44
- blockTemplates: 'lt.blockTemplates',
45
26
  };
46
27
 
47
- /** 命令行便捷写入使用的固定条目 id(不影响用户自己新建的模板)。 */
48
- const CLI_ENTRY_ID = 'cli';
49
-
50
28
  function readSetting(conn: DbApi, key: string): any {
51
29
  const row = conn.get('SELECT value FROM settings WHERE key = :k', { k: key });
52
30
  if (!row) return undefined;
@@ -65,194 +43,44 @@ function writeSetting(conn: DbApi, key: string, value: unknown): void {
65
43
  );
66
44
  }
67
45
 
68
- /** 多条设置按空行拼成一条模板(CLI 便捷入口用)。 */
69
- function joinEntries(list?: string[]): string {
70
- return (list || []).join('\n\n');
71
- }
72
-
73
- /** 一条模板 → 旧版「多条」视图(按空行拆分;供旧 CLI/面板字段兼容)。 */
46
+ /** 一条模板 → 「多条」视图(按空行拆分;旧 CLI 字段兼容用)。 */
74
47
  function splitEntries(template: unknown): string[] {
75
48
  const s = String(template ?? '').trim();
76
49
  return s ? s.split(/\n{2,}/).map((x) => x.trim()).filter(Boolean) : [];
77
50
  }
78
51
 
79
- function clampTemplate(v: unknown): string {
80
- const s = String(v ?? '').trim();
81
- return s.length > MAX_BLOCK_TEMPLATE_LEN ? s.slice(0, MAX_BLOCK_TEMPLATE_LEN) : s;
82
- }
83
-
84
- /**
85
- * 读「每区块模板列表 + 全局追加模式」(**纯读 + 纯校验**)。
86
- * `lt.blockTemplates` 恒存在(open.ts 的 ensurePromptTemplates 首启落库);
87
- * 没有行 / 校验不过都是事故,抛错——不合成、不补齐(方案 §4.1)。
88
- */
89
- function readBlockState(conn: DbApi): { lists: BlockLists; appendMode: string } {
90
- const stored = readSetting(conn, KEYS.blockTemplates);
91
- return {
92
- lists: normalizeBlockTemplateLists(stored),
93
- appendMode: clampAppendMode(readSetting(conn, KEYS.appendMode)),
94
- };
95
- }
96
-
97
- /** 当前生效模板 → 旧版派生字段(仅用于 CLI/旧面板视图兼容,不是读写模型)。 */
98
- function derivedOf(lists: BlockLists): { ackPrompt: string[]; deliveryTemplate: string; attachTemplate: string } {
99
- const active = resolveBlockTemplates(lists);
100
- return {
101
- // 旧视图的「多条」字段按当前生效模板拆分(内置模板也如实反映)
102
- ackPrompt: splitEntries(active.ack!.template),
103
- deliveryTemplate: active.context!.builtin ? '' : active.context!.template,
104
- attachTemplate: active.attachment!.builtin ? '' : active.attachment!.template,
105
- };
106
- }
107
-
108
- /** 读全部 lt.* 设置(校验不过即抛——落库行被人为写坏是事故)。 */
52
+ /** 读全部 lt.* 设置。 */
109
53
  export function getLtSettings(): Record<string, any> {
110
54
  const conn = db();
111
- const { lists, appendMode } = readBlockState(conn);
112
55
  return {
113
56
  timeoutSec: clampTimeoutSec(readSetting(conn, KEYS.timeoutSec)),
114
- appendMode,
115
- blockTemplates: lists,
116
- ...derivedOf(lists),
117
- };
118
- }
119
-
120
- /**
121
- * 保存前的模板校验(方案 §4.2,三道):
122
- * 1. 语法错误**拒绝保存**并指出模板 / 区块 / 出错位置(渲染期不再回落);
123
- * 2. 当前生效(active)模板为空 → 拒绝——空模板在运行期是配置错误(S1 起
124
- * compose 的 assertPluginList 直接抛),不许「保存成功、领取时整次失败」;
125
- * 3. 变量白名单:全局段集 + 点路径全路径命中 fields 并集(落地裁决见方案 §4.2 补记;
126
- * `params` 动态键放行,`{{#each}}` 块内放行但 each 目标必须已声明)。
127
- */
128
- function assertBlockTemplatesValid(lists: BlockLists): void {
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 的空条目合法(不渲染,仅存档)
135
- const r = validateTemplate(item.template);
136
- if (!r.ok) {
137
- throw badInput(
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('、')}。可用变量见设置页「插入变量」目录`
152
- );
153
- }
154
- }
155
- }
156
- }
157
-
158
- /**
159
- * 命令行便捷入口:把一条模板写入某区块的固定条目(`cli`)并设为生效;
160
- * 空模板 = 恢复内置(保留用户其它条目,只把 active 指回 builtin)。
161
- * 内置条目恒在(normalize 校验保证),直接从现值取——不再按代码重建。
162
- */
163
- function setCustomActive(lists: BlockLists, blockId: string, template: unknown, { name = '命令行' }: { name?: string } = {}): void {
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)}」区块缺内置条目(落库行被写坏)`);
168
- const t = clampTemplate(template);
169
- if (!t) {
170
- lists[blockId] = { active: BUILTIN_TEMPLATE_ID, list: b.list };
171
- return;
172
- }
173
- const rest = b.list.filter((x) => x.id !== BUILTIN_TEMPLATE_ID && x.id !== CLI_ENTRY_ID);
174
- lists[blockId] = {
175
- active: CLI_ENTRY_ID,
176
- list: [builtin, { id: CLI_ENTRY_ID, name, template: t, builtin: false }, ...rest],
57
+ appendMode: clampAppendMode(readSetting(conn, KEYS.appendMode)),
58
+ // 旧视图字段:ack 段落正文来自 ack 插件类的内置模板,仍按「多条」形态给出,
59
+ // 让老 CLI 的 localtask config 输出不必断代(#152:只是回显,不可写)。
60
+ ackPrompt: splitEntries(activeTemplateOf('ack')),
177
61
  };
178
62
  }
179
63
 
180
- /** setLtSettings 的 patch 形状(全部可选)。 */
64
+ /** setLtSettings 的 patch 形状(#152:模板不再可写,只留两个键)。 */
181
65
  export interface LtSettingsPatch {
182
66
  timeoutSec?: unknown;
183
67
  appendMode?: unknown;
184
- blockTemplates?: unknown;
185
- ackPrompt?: unknown;
186
- deliveryTemplate?: unknown;
187
- attachTemplate?: unknown;
188
68
  }
189
69
 
190
- /** 写部分设置(只改传入项;校验沿用 store-io / task-templates 的 clamp)。 */
70
+ /** 写部分设置(只改传入项;校验沿用 store-io 的 clamp)。 */
191
71
  export function setLtSettings(patch: LtSettingsPatch = {}): Record<string, any> {
192
72
  return txw((conn) => {
193
73
  if (patch.timeoutSec !== undefined) {
194
74
  writeSetting(conn, KEYS.timeoutSec, clampTimeoutSec(patch.timeoutSec));
195
75
  }
196
-
197
- const touches =
198
- patch.blockTemplates !== undefined ||
199
- patch.appendMode !== undefined ||
200
- patch.ackPrompt !== undefined ||
201
- patch.deliveryTemplate !== undefined ||
202
- patch.attachTemplate !== undefined;
203
- if (!touches) return getLtSettings();
204
-
205
- const current = readBlockState(conn);
206
- let lists = current.lists;
207
-
208
- // 新模型:按区块合并(只传某个区块时不动其它区块的列表),整体过纯校验。
209
- // 历史 rule 键已下线:patch 里带 rule 直接忽略(§11 不做旧配置兼容)。
210
- if (patch.blockTemplates !== undefined) {
211
- const raw = patch.blockTemplates as Record<string, any> | undefined;
212
- const merged = { ...lists };
213
- if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
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] };
229
- }
230
- }
231
- lists = normalizeBlockTemplateLists(merged);
232
- }
233
-
234
- // CLI 便捷入口:写入对应区块的 `cli` 条目并启用(空 = 恢复内置)。
235
- if (patch.ackPrompt !== undefined) {
236
- setCustomActive(lists, 'ack', joinEntries(clampAckPromptList(patch.ackPrompt)));
76
+ if (patch.appendMode !== undefined) {
77
+ writeSetting(conn, KEYS.appendMode, clampAppendMode(patch.appendMode));
237
78
  }
238
- if (patch.deliveryTemplate !== undefined) {
239
- setCustomActive(lists, 'context', clampDeliveryTemplate(patch.deliveryTemplate));
240
- }
241
- if (patch.attachTemplate !== undefined) {
242
- setCustomActive(lists, 'attachment', clampAttachTemplate(patch.attachTemplate));
243
- }
244
-
245
- assertBlockTemplatesValid(lists);
246
-
247
- const appendMode =
248
- patch.appendMode !== undefined ? clampAppendMode(patch.appendMode) : current.appendMode;
249
- writeSetting(conn, KEYS.blockTemplates, lists);
250
- writeSetting(conn, KEYS.appendMode, appendMode);
251
79
  return getLtSettings();
252
80
  });
253
81
  }
254
82
 
255
- /** 面板/CLI 的设置视图(派生兼容字段在这里补齐;权威字段是 blockTemplates)。 */
83
+ /** 面板/CLI 的设置视图(派生兼容字段在这里补齐)。 */
256
84
  export function settingsView(): Record<string, any> {
257
85
  const s = getLtSettings();
258
86
  return {
@@ -260,13 +88,9 @@ export function settingsView(): Record<string, any> {
260
88
  recommendedSec: DEFAULT_TIMEOUT_SEC,
261
89
  maxSec: MAX_TIMEOUT_SEC,
262
90
  ackPromptList: s.ackPrompt,
263
- deliveryTemplate: s.deliveryTemplate,
264
- attachTemplate: s.attachTemplate,
265
91
  appendMode: s.appendMode,
266
- blockTemplates: s.blockTemplates,
267
92
  };
268
93
  }
269
94
 
270
95
  export { DEFAULT_TIMEOUT_SEC, MAX_TIMEOUT_SEC } from '../store-io.js';
271
96
  export { DEFAULT_ACK_PROMPT } from '../task-templates.js';
272
- export type { BlockTemplateList };
@@ -3,8 +3,7 @@
3
3
  // 业务值而不是抛错)、reopenTask(用户修改反馈 → **就地重开原任务**,历史进 history 链)。
4
4
  import { badInput, notFound } from '../../core/errors.js';
5
5
  import { formatDuration, renderInstruction } from '../../core/instruction-template.js';
6
- import { resolveBlockTemplates } from '../../shared/prompt-blocks.js';
7
- import { getLtSettings } from './repo/settings.js';
6
+ import { activeTemplateOf } from '../promptplug/index.js';
8
7
  import { taskGoalTemplateCtx } from '../tasktool/plugins/goal-template.js';
9
8
  import { preserveFrontmatter } from '../../shared/frontmatter.js';
10
9
  import {
@@ -33,14 +32,13 @@ interface SupersederRef {
33
32
  }
34
33
 
35
34
  /**
36
- * 「未到点就想 done」的拦截提示(#90):模板来自设置 lt.blockTemplates.doneguard,
37
- * 与其余系统段同一套 Handlebars 引擎与 ctx;渲染失败退回 '',调用方仍用内置 hint,
38
- * 门禁本身的业务结果不受模板影响。
35
+ * 「未到点就想 done」的拦截提示(#90):模板是 doneguard 插件类的内置正文
36
+ * (#152 起不再从 settings 解析;与其余系统段同一套 Handlebars 引擎与 ctx)。
37
+ * 渲染失败退回 '',调用方仍用内置 hint,门禁本身的业务结果不受模板影响。
39
38
  */
40
39
  function renderDoneGuard({ taskId, taskText, goalKey, st }: { taskId: number; taskText: string; goalKey: string; st: any }): string {
41
40
  try {
42
- const s = getLtSettings();
43
- const tpl = resolveBlockTemplates(s && s.blockTemplates).doneguard!.template;
41
+ const tpl = activeTemplateOf('doneguard');
44
42
  const goal = st.goal || {};
45
43
  const ctx = taskGoalTemplateCtx({
46
44
  taskId,
@@ -355,8 +353,8 @@ export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawS
355
353
  const { taskGoalState, recordTaskCheck } = await import('../tasktool/taskgoal.js');
356
354
  const st = await taskGoalState({ topicKey: key, taskId: want });
357
355
  if (st.hasGoal && !st.reached) {
358
- // 「未到点就想 done」的拦截提示可配(#90):模板与其它区块同源,落
359
- // lt.blockTemplates.doneguard;渲染失败退回内置 hint,不挡业务结果。
356
+ // 「未到点就想 done」的拦截提示(#90):模板与其它区块同源,是 doneguard
357
+ // 插件类的内置正文(#152);渲染失败退回内置 hint,不挡业务结果。
360
358
  const guard = renderDoneGuard({
361
359
  taskId: want,
362
360
  taskText: task.text,
@@ -5,9 +5,9 @@
5
5
 
6
6
  /**
7
7
  * 默认 ack:完成任务就调用 localtask done 回填结果(任务 51 的职责合并决定)。
8
- * v6 起唯一归属在本文件——shared/prompt-blocks 不再持有任何模板正文,模板真相在
9
- * 出厂快照 blockTemplates.json;这里的文本 ≡ 快照 ack 段内置文本,一致性由
10
- * tests/unit/prompt-ensure.test.mjs 对账;改任何一处都要同步另一处并跑单测。
8
+ * #152 起模板正文的唯一真相是插件类——ack 段的正文在
9
+ * modules/promptplug/plugins/ack.ts 的 BUILTIN;这里保留一份同文常量
10
+ * 只为兼容旧引用(设置视图的「多条」形态回显)。改文案请改插件类。
11
11
  */
12
12
  export const DEFAULT_ACK_PROMPT =
13
13
  '完成之后必须调用 nx-kv localtask done --id {{task.id}} --summary "<完成总结>" 汇报结果。';
@@ -71,7 +71,7 @@ export function joinAckPrompt(v: unknown): string {
71
71
  // ─── 系统上下文追加模式 + XML 区块配置(settings 两键)───────────────
72
72
  //
73
73
  // appendMode:'xml'(默认,每段包独立标签)| 'plain'(改造前按空行直拼)。
74
- // 每个区块的模板列表与生效项在 shared/prompt-blocks.js 的 blockTemplates 模型里。
74
+ // 每个区块的模板正文在插件类里(modules/promptplug/plugins/*.ts),不再有落库模型。
75
75
  export const APPEND_MODE_IDS = Object.freeze(APPEND_MODES.map((m) => m.id));
76
76
 
77
77
  /** 归一化追加模式:缺省/非法 → xml(默认足够清晰)。 */
@@ -1,6 +1,7 @@
1
1
  // (#54 自 service.js 拆出)任务行/主题的只读视图与队列内关系原语:
2
2
  // normalizeTask(含 ready 徽标)、topicView、跨队列依赖解析器(foreignResolver)、
3
3
  // 队列内关系清单(queueRelationsOf)与搬家(relocateTask)。
4
+ import { existsSync } from 'node:fs';
4
5
  import { badInput, notFound } from '../../core/errors.js';
5
6
  import { sanitizeTaskGoal } from '../tasktool/taskgoal.js';
6
7
  import { normalizeBlockBy, isReadyToClaim } from './dag.js';
@@ -319,6 +320,9 @@ export function topicView(t: any, repoCtx: any = null, readyOpts: ReadyOpts = {}
319
320
  return {
320
321
  key: t.key,
321
322
  cwd: t.cwd || '',
323
+ // 目录还在不在:临时目录被删 / 外接盘未挂载 / 测试残留都会让 cwd 失效。
324
+ // UI 与 prune --missing-dir 都靠它判断「这条主题是幽灵还是真的」。
325
+ cwdExists: t.isGlobal ? true : !!t.cwd && existsSync(String(t.cwd)),
322
326
  name: t.name || '',
323
327
  summary: t.summary || '',
324
328
  // 提交方(add --summary)留下的补充说明:与 agent 的「当前现状」分开存,
@@ -3,6 +3,7 @@
3
3
  //
4
4
  // T03:存储切到 repo/(SQLite)。本文件不再直接读写任何存储形状 ——
5
5
  // 读走 repo.topics 的 JSON 形态投影,写走窄方法(一个动作一个事务)。
6
+ import { existsSync } from 'node:fs';
6
7
  import { badInput } from '../../core/errors.js';
7
8
  import { normalizeCwd } from './paths.js';
8
9
  import { normalizeSummary } from './store-io.js';
@@ -86,13 +87,19 @@ export async function getSettings(): Promise<Record<string, any>> {
86
87
  // 清理旧脏数据:只动「非等待中」的主题——
87
88
  // 1) 旧模型迁移来的无 cwd 主题(“旧数据,无目录”);
88
89
  // 2) 空主题(没有任何任务);
89
- // 3) allFinished 时,连同「已全部领取、无待领」的主题一起清。
90
+ // 3) allFinished 时,连同「已全部领取、无待领」的主题一起清;
91
+ // 4) missingDir 时,清「cwd 已不存在且没有待领任务」的主题
92
+ // (删掉的临时目录 / 测试残留;外接盘没挂载也会命中,所以必须显式开)。
90
93
  // 等待中的主题与全局主题一律保留;dryRun 只报告不改动。
91
94
  //
92
95
  // **僵尸等待标志不算"等待中"**:wait 被强杀后残留的 waiting:true 会让主题
93
96
  // 永远躲过清理(gs-ac 就这么卡住的)。用 isLiveWaiting 判定——截止已过 = 没人
94
97
  // 在等 = 可以清。
95
- export async function pruneTopics({ allFinished = false, dryRun = false }: { allFinished?: boolean; dryRun?: boolean } = {}): Promise<Record<string, any>> {
98
+ export async function pruneTopics({
99
+ allFinished = false,
100
+ dryRun = false,
101
+ missingDir = false,
102
+ }: { allFinished?: boolean; dryRun?: boolean; missingDir?: boolean } = {}): Promise<Record<string, any>> {
96
103
  openStore();
97
104
  const removed: Array<{ key: string; name: string; cwd: string; reason: string }> = [];
98
105
  for (const t of topicsRepo.listTopics()) {
@@ -104,8 +111,15 @@ export async function pruneTopics({ allFinished = false, dryRun = false }: { all
104
111
  const isLegacy = !t.cwd;
105
112
  const isEmpty = tasks.length === 0;
106
113
  const isFinished = allFinished && tasks.length > 0 && !hasPending;
107
- if (isLegacy || isEmpty || isFinished) {
108
- const reason = isLegacy ? '旧模型无目录' : isEmpty ? '空主题' : '已完成无待领';
114
+ const cwdGone = missingDir && !!t.cwd && !hasPending && !existsSync(String(t.cwd));
115
+ if (isLegacy || isEmpty || isFinished || cwdGone) {
116
+ const reason = isLegacy
117
+ ? '旧模型无目录'
118
+ : isEmpty
119
+ ? '空主题'
120
+ : cwdGone
121
+ ? '目录已不存在'
122
+ : '已完成无待领';
109
123
  removed.push({ key: t.key, name: t.name || t.key, cwd: t.cwd || '', reason });
110
124
  }
111
125
  }
@@ -115,33 +129,25 @@ export async function pruneTopics({ allFinished = false, dryRun = false }: { all
115
129
  return { status: 'ok', dryRun: !!dryRun, count: removed.length, removed };
116
130
  }
117
131
 
118
- /** updateSettings 的入参(全部可选)。 */
132
+ /**
133
+ * updateSettings 的入参(全部可选)。
134
+ *
135
+ * #152 起只剩两个真正可写的键:提示词模板正文的唯一真相搬到了插件类
136
+ * (modules/promptplug/plugins/*.ts 的 `templates`),DB 不再存模板,
137
+ * 因此 ackPrompt / deliveryTemplate / attachTemplate / blockTemplates 四个
138
+ * 写入通道一并删除(旧值也不再读取)。
139
+ */
119
140
  export interface UpdateSettingsInput {
120
141
  timeoutSec?: unknown;
121
- ackPrompt?: unknown;
122
- deliveryTemplate?: unknown;
123
- attachTemplate?: unknown;
124
142
  appendMode?: unknown;
125
- blockTemplates?: unknown;
126
143
  }
127
144
 
128
- // 配置等待超时 / ack 汇报要求(页面可调)。超时推荐 180=3 分钟、最大 600=10 分钟;
129
- // ackPrompt 写入 ack 区块的「命令行」模板并启用(done 指令与收尾要求只有这一个出口),
130
- // 传 '' / [] 恢复内置、不传保持不变。
131
- //
132
- // blockTemplates:每区块独立模板列表 `{ [blockId]: { active, list } }`
133
- // (结构见 shared/prompt-blocks.js 的 normalizeBlockTemplateLists)。
134
- export async function updateSettings({ timeoutSec, ackPrompt, deliveryTemplate, attachTemplate, appendMode, blockTemplates }: UpdateSettingsInput = {}): Promise<Record<string, any>> {
145
+ // 配置等待超时(页面可调)。超时推荐 180=3 分钟、最大 600=10 分钟。
146
+ export async function updateSettings({ timeoutSec, appendMode }: UpdateSettingsInput = {}): Promise<Record<string, any>> {
135
147
  const hasTimeout = timeoutSec !== undefined && timeoutSec !== null;
136
- const hasAck = ackPrompt !== undefined;
137
- const hasDelivery = deliveryTemplate !== undefined;
138
- const hasAttach = attachTemplate !== undefined;
139
148
  const hasAppend = appendMode !== undefined;
140
- const hasBlocks = blockTemplates !== undefined;
141
- if (!hasTimeout && !hasAck && !hasDelivery && !hasAttach && !hasAppend && !hasBlocks) {
142
- throw badInput(
143
- '请至少指定一项:--timeout <秒>,或 --ack "<ack 提示词>",或 --append-mode,或 --block-templates "JSON 对象"'
144
- );
149
+ if (!hasTimeout && !hasAppend) {
150
+ throw badInput('请至少指定一项:--timeout <秒>,或 --append-mode <xml|plain>');
145
151
  }
146
152
  if (hasTimeout) {
147
153
  const n = Number(timeoutSec);
@@ -152,11 +158,7 @@ export async function updateSettings({ timeoutSec, ackPrompt, deliveryTemplate,
152
158
  openStore();
153
159
  settingsRepo.setLtSettings({
154
160
  timeoutSec: hasTimeout ? timeoutSec : undefined,
155
- ackPrompt: hasAck ? ackPrompt : undefined,
156
- deliveryTemplate: hasDelivery ? deliveryTemplate : undefined,
157
- attachTemplate: hasAttach ? attachTemplate : undefined,
158
161
  appendMode: hasAppend ? appendMode : undefined,
159
- blockTemplates: hasBlocks ? blockTemplates : undefined,
160
162
  });
161
163
  return settingsRepo.settingsView();
162
164
  }
@@ -6,15 +6,12 @@
6
6
 
7
7
  import type { ActionBase } from '../../../runtime/action-base.js';
8
8
  import type { Container } from '../../../runtime/container.js';
9
- import { PromptOrderAction } from './prompt-order.js';
10
9
  import { PromptRegistryAction } from './prompt-registry.js';
11
10
 
12
11
  /** 本模块的全部 action 类(容器按这个顺序建实例)。 */
13
12
  export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
14
- PromptOrderAction,
15
13
  PromptRegistryAction,
16
14
  ];
17
15
 
18
16
  // 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
19
- export { PromptOrderAction };
20
17
  export { PromptRegistryAction };
@@ -1,22 +1,17 @@
1
- // prompt.registry —— 注册表外露(方案 §5.3 / §7):三端同源的唯一出口。
1
+ // prompt.registry —— 注册表外露:三端同源的唯一出口(#152 起**只读派生**)。
2
2
  //
3
- // CLI(nx-kv prompt registry)、HTTP(GET /api/prompt/registry)与设置页
4
- // 消费同一份 uiDescriptor():字段目录、生效模板、顺序位全部从插件声明 +
5
- // DB 生效项派生,前端不再有手工副本(placeholders.ts / prompt-template-params.ts)。
3
+ // 真相是插件类本身(registry.ts 的 PLUGIN_CLASSES):id / 时机链 / 顺序 / 内置模板 /
4
+ // 变量目录全部从类声明派生。没有 JSON 注册表、没有 DB seed、也没有「顺序数组」——
5
+ // 顺序 = 链内 order。
6
6
  //
7
- // deps 全空:uiDescriptor 只读文本态(get())与 schema 派生面(fields/writes),
8
- // 结构态 data() 永不被调用——不需要宿主取数。
7
+ // deps 全空:uiDescriptor 只读文本态(get())与声明面(fields/varScope/templates),
8
+ // 结构态 buildData() 永不被调用——不需要宿主取数。
9
9
  import { action } from '../../../runtime/action-decorator.js';
10
10
  import { z } from 'zod';
11
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
12
  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';
13
+ import { buildAllPlugins } from '../factory.js';
14
+ import { allPluginIds, assertRegistry, groupIndex } from '../registry.js';
20
15
 
21
16
  /** prompt.registry 的入参契约(无参)。 */
22
17
  const input = z.object({});
@@ -26,26 +21,20 @@ export class PromptRegistryAction extends ActionBase<typeof input> {
26
21
  id: 'prompt.registry',
27
22
  cli: ['prompt', 'registry'],
28
23
  http: ['GET', '/api/prompt/registry'],
29
- summary: '提示词插件注册表:8 段的生效模板 / 变量目录 / 顺序位(三端同源,uiDescriptor 派生)',
24
+ summary: '提示词插件注册表:按时机链(get / check / done)列出插件的内置模板 / 变量目录 / 链内顺序',
30
25
  input,
31
26
  render: (d: any) =>
32
- d.plugins.map((p: any) => `${p.order} ${p.id}(${p.label},标签 ${p.tag})`).join(';'),
27
+ d.plugins.map((p: any) => `[${p.group}] ${p.order} ${p.id}(${p.label})`).join(';'),
33
28
  })
34
29
  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 };
30
+ assertRegistry();
31
+ // uiDescriptor 会按 group 名字母序排(check / done / get);对外的 plugins 数组
32
+ // 统一改用「时机声明序 + 链内 order」——与 groups 索引、CLI 渲染顺序逐项同序,
33
+ // 前端左轨直接按它铺开就不会出现「导航顺序 ≠ 实际输出顺序」。
34
+ const order = allPluginIds();
35
+ const plugins = uiDescriptor(buildAllPlugins()).sort(
36
+ (a, b) => order.indexOf(a.id) - order.indexOf(b.id),
37
+ );
38
+ return { groups: groupIndex(), plugins };
50
39
  }
51
40
  }