nx-kv 0.64.0 → 0.65.2

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 (151) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/assets/nx-kv/SKILL.md +5 -2
  3. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +6 -0
  4. 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 +79 -6
  5. package/assets/nx-kv/templates/ref-main-doc.md +46 -0
  6. package/package.json +1 -1
  7. package/src/core/db/seed-templates.ts +2 -86
  8. package/src/modules/localtask/task-lifecycle.ts +1 -1
  9. package/src/modules/promptplug/actions/_manifest.generated.ts +9 -0
  10. package/src/modules/promptplug/actions/prompt-registry.ts +4 -1
  11. package/src/modules/promptplug/actions/prompt-template-activate.ts +31 -0
  12. package/src/modules/promptplug/actions/prompt-template-delete.ts +30 -0
  13. package/src/modules/promptplug/actions/prompt-template-save.ts +52 -0
  14. package/src/modules/promptplug/delivery.ts +151 -0
  15. package/src/modules/promptplug/factory.ts +16 -8
  16. package/src/modules/promptplug/index.ts +3 -1
  17. package/src/modules/promptplug/plugins/doneguard.ts +3 -0
  18. package/src/modules/promptplug/plugins/getloop.ts +8 -7
  19. package/src/modules/{tasktool/plugins/goal-template.ts → promptplug/plugins/goal-prompt.ts} +57 -4
  20. package/src/modules/promptplug/plugins/goal-shape.ts +17 -0
  21. package/src/modules/promptplug/plugins/goalhint.ts +22 -9
  22. package/src/modules/promptplug/plugins/timecheck.ts +25 -14
  23. package/src/modules/promptplug/registry.ts +3 -3
  24. package/src/modules/promptplug/template-store.ts +145 -0
  25. package/src/modules/tasktool/delivery.ts +231 -0
  26. package/src/modules/tasktool/get.ts +2 -2
  27. package/src/modules/tasktool/plugins/taskgoal-store.ts +28 -22
  28. package/src/modules/tasktool/plugins/timegoal-task-store.ts +70 -5
  29. package/src/modules/tasktool/plugins/waitgoal-config.ts +1 -25
  30. package/src/modules/tasktool/plugins/waitgoal.ts +0 -4
  31. package/src/modules/tasktool/preview.ts +3 -4
  32. package/src/modules/tasktool/wait.ts +16 -284
  33. package/src/modules/templates/actions/templates-default.ts +2 -5
  34. package/src/modules/templates/actions/templates-update.ts +1 -3
  35. package/src/modules/templates/service.ts +11 -13
  36. package/src/modules/templates/support.ts +0 -15
  37. package/src/web/frontend/App.tsx +0 -12
  38. package/src/web/frontend/api/cli-tree.json +58 -0
  39. package/src/web/frontend/api/client.generated.ts +32 -2
  40. package/src/web/frontend/components/doc/doc-head.tsx +13 -4
  41. package/src/web/frontend/components/icons.tsx +9 -199
  42. package/src/web/frontend/components/md/live-block.tsx +1 -5
  43. package/src/web/frontend/components/md/md-panes-root.tsx +0 -4
  44. package/src/web/frontend/components/md/md-panes.tsx +1 -11
  45. package/src/web/frontend/components/md/tool-bar.tsx +9 -0
  46. package/src/web/frontend/components/sidebar/index.tsx +13 -2
  47. package/src/web/frontend/components/sidebar/model.ts +3 -0
  48. package/src/web/frontend/components/tool-acts/bar.tsx +40 -29
  49. package/src/web/frontend/components/tool-acts/layout-panel.tsx +7 -3
  50. package/src/web/frontend/components/tool-acts/modules.ts +53 -51
  51. package/src/web/frontend/components/tool-acts/style.css +7 -3
  52. package/src/web/frontend/modules/md/styles/docs.css +0 -7
  53. package/src/web/frontend/modules/md/styles/editor.css +0 -17
  54. package/src/web/frontend/modules/md/styles/shell.css +3 -0
  55. package/src/web/frontend/modules/md/use-templates.ts +3 -13
  56. package/src/web/frontend/page/dir/index.tsx +3 -15
  57. package/src/web/frontend/page/dir/task-actions.ts +1 -16
  58. package/src/web/frontend/page/dir/task.tsx +2 -16
  59. package/src/web/frontend/page/group/index.tsx +6 -19
  60. package/src/web/frontend/page/repos/branch-persist.ts +32 -0
  61. package/src/web/frontend/page/repos/icons.tsx +47 -229
  62. package/src/web/frontend/page/repos/index.tsx +12 -8
  63. package/src/web/frontend/page/repos/repo-table.tsx +24 -3
  64. package/src/web/frontend/page/settings/api.ts +20 -0
  65. package/src/web/frontend/page/settings/index.tsx +1 -1
  66. package/src/web/frontend/page/settings/prompt-template-editor.tsx +180 -0
  67. package/src/web/frontend/page/settings/prompt-templates-section.tsx +39 -34
  68. package/src/web/frontend/page/settings/style.css +30 -0
  69. package/src/web/frontend/page/templates/index.tsx +5 -54
  70. package/src/web/frontend/page/templates/manage.tsx +1 -5
  71. package/src/web/frontend/page/templates/style.css +1 -43
  72. package/src/web/frontend/page/templates/template-list.tsx +7 -15
  73. package/src/web/frontend/routes/route-eq.ts +2 -3
  74. package/src/web/frontend/routes/static.ts +2 -2
  75. package/src/web/frontend/routes/templates.ts +0 -10
  76. package/src/web/frontend/styles/repos.css +22 -0
  77. package/src/web/frontend/styles-v2/shell.css +7 -0
  78. package/src/web/frontend/svghub/catalog-act.ts +168 -0
  79. package/src/web/frontend/svghub/catalog-doc.ts +102 -0
  80. package/src/web/frontend/svghub/catalog-nav.ts +192 -0
  81. package/src/web/frontend/svghub/catalog-repo.ts +102 -0
  82. package/src/web/frontend/svghub/catalog-state.ts +70 -0
  83. package/src/web/frontend/svghub/icon.tsx +95 -0
  84. package/src/web/frontend/svghub/index.ts +66 -0
  85. package/src/web/frontend/svghub/serialize.ts +39 -0
  86. package/src/web/frontend/svghub/types.ts +67 -0
  87. package/src/web/frontend/types.ts +2 -1
  88. package/src/web/public/assets/app-context-BqCBcDsx.js +1 -0
  89. package/src/web/public/assets/bar-Dc5Tq1eE.js +1 -0
  90. package/src/web/public/assets/{button-BEWXOABr.js → button-3JlUeln_.js} +1 -1
  91. package/src/web/public/assets/{composer-launch-DRi9mZE1.js → composer-launch-fp2IzGzQ.js} +1 -1
  92. package/src/web/public/assets/{composer-panel-swmDqlPw.js → composer-panel-Dh681iO6.js} +1 -1
  93. package/src/web/public/assets/dag-DnaU0I_z.js +1 -0
  94. package/src/web/public/assets/dir-d16q1GLe.js +3 -0
  95. package/src/web/public/assets/doc-DRSKD0Re.js +6 -0
  96. package/src/web/public/assets/group-Dc3ZgW24.js +1 -0
  97. package/src/web/public/assets/index-BIVxGd6t.css +1 -0
  98. package/src/web/public/assets/index-Bg0m8gbJ.js +2 -0
  99. package/src/web/public/assets/{list-filter-D-x94TvA.js → list-filter-CWxiOSg_.js} +1 -1
  100. package/src/web/public/assets/md-history-CLIs9Dr0.css +1 -0
  101. package/src/web/public/assets/md-history-DNtgaIdH.js +39 -0
  102. package/src/web/public/assets/{member-picker-Cvbv24IK.js → member-picker-BZgE3HGb.js} +1 -1
  103. package/src/web/public/assets/model-CtG2jIDv.js +2 -0
  104. package/src/web/public/assets/{overview-CctJfO3D.js → overview-C68QpcT9.js} +1 -1
  105. package/src/web/public/assets/popup-DZ2Khv2c.js +1 -0
  106. package/src/web/public/assets/progress-CEmAFxo9.js +3 -0
  107. package/src/web/public/assets/refs-TzxZYy7T.js +2 -0
  108. package/src/web/public/assets/repo-form-modal-Dg3hJWUV.js +1 -0
  109. package/src/web/public/assets/repos-uNqSR5YB.js +12 -0
  110. package/src/web/public/assets/{route-crumb-BcDPd7Ht.js → route-crumb-C4DgkJ8G.js} +1 -1
  111. package/src/web/public/assets/{settings-Cc6puKd5.css → settings-BWHjNegB.css} +1 -1
  112. package/src/web/public/assets/settings-BzIllshQ.js +1 -0
  113. package/src/web/public/assets/{status-tag-BD_0iWMB.js → status-tag-8cLH8hl9.js} +1 -1
  114. package/src/web/public/assets/task-DuFOXLPC.js +11 -0
  115. package/src/web/public/assets/{task-row-CQgzQmzu.js → task-row-CRjuAfKW.js} +1 -1
  116. package/src/web/public/assets/{task-utils-bJH1-Cjy.js → task-utils-DAPxKm4c.js} +1 -1
  117. package/src/web/public/assets/templates-CwYDIBYn.css +1 -0
  118. package/src/web/public/assets/templates-DNiGvmdq.js +10 -0
  119. package/src/web/public/assets/{use-rail-drag-ufwy2XZB.js → use-rail-drag-DxIYcszo.js} +1 -1
  120. package/src/web/public/assets/{workspace-D3jbcTwf.js → workspace-DojQ3RP4.js} +2 -2
  121. package/src/web/public/index.html +15 -16
  122. package/src/web/frontend/modules/md/fill-session.ts +0 -36
  123. package/src/web/frontend/modules/md/new-task-from-template.ts +0 -22
  124. package/src/web/frontend/modules/md/task-intent.ts +0 -29
  125. package/src/web/frontend/modules/prompts/render-template-body.ts +0 -14
  126. package/src/web/frontend/modules/prompts/template-preview.ts +0 -62
  127. package/src/web/frontend/page/templates/fill.tsx +0 -124
  128. package/src/web/public/assets/app-context-DDQnrPSP.js +0 -1
  129. package/src/web/public/assets/bar-j14ON7uZ.js +0 -1
  130. package/src/web/public/assets/dag-BzdFYMml.js +0 -1
  131. package/src/web/public/assets/dir-DhsB1ZhL.js +0 -3
  132. package/src/web/public/assets/doc-D4po3sDc.js +0 -6
  133. package/src/web/public/assets/fill-session-fHxQHFaD.js +0 -1
  134. package/src/web/public/assets/group-BxmSNzIB.js +0 -1
  135. package/src/web/public/assets/index-CMjG5NVU.js +0 -2
  136. package/src/web/public/assets/index-uMjSWNVr.css +0 -1
  137. package/src/web/public/assets/md-history-1h2zairf.css +0 -1
  138. package/src/web/public/assets/md-history-CZUF_FhN.js +0 -39
  139. package/src/web/public/assets/model-Cc2EoUQp.js +0 -2
  140. package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +0 -1
  141. package/src/web/public/assets/popup-D8KWI6-Q.js +0 -1
  142. package/src/web/public/assets/progress-CawQRCQf.js +0 -3
  143. package/src/web/public/assets/refs-TuuoaRs7.js +0 -2
  144. package/src/web/public/assets/render-template-body-bXdedFig.js +0 -1
  145. package/src/web/public/assets/repo-form-modal-BD4N37MI.js +0 -1
  146. package/src/web/public/assets/repos-BPeuX4N9.js +0 -12
  147. package/src/web/public/assets/settings-CZJaKLZW.js +0 -1
  148. package/src/web/public/assets/task-DgbbF5gy.js +0 -11
  149. package/src/web/public/assets/task-intent-CX5DZccN.js +0 -1
  150. package/src/web/public/assets/templates-CBXlwyof.js +0 -11
  151. package/src/web/public/assets/templates-plA8R7jJ.css +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,76 @@
2
2
 
3
3
  本文件对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.65.2] - 2026-11-19 getloop 残留预渲染链清理(#230 审计)
6
+
7
+ ### Changed
8
+
9
+ - **getloop 段模板清理**(#230,审计裁决「没删干净的残留」):#182 下线仓库级 template
10
+ 口子时,`getLoopInstruction → getLoopTpl → loopText Supply → data.getloop.text` 这条
11
+ 预渲染管道没拆——预渲染上下文缺 `getloop` 键,产出的 `text` 是残缺副本(分钟子句被
12
+ 丢),插件内置模板也从不消费它;同一段文案存在三份(两个别名常量 + BUILTIN)。
13
+ 已整条删除:getloop 插件改收 `enabled` 开关 Supply,`dataSchema` 去掉 `text` 字段
14
+ (变量目录与 `prompt.registry` 同步收窄),文案唯一真相 = 插件内置模板。
15
+ **交付渲染输出逐字节不变**(golden 仅 ctx 基线重生成,`.txt` 正文基线零变化)。
16
+ - 契约与 Dart 包按流程重新生成(`pnpm gen:dart`,变量目录变化同步)。
17
+
18
+ ### Removed
19
+
20
+ - `tasktool/plugins/waitgoal-config.ts` 的 `DEFAULT_GETLOOP_INSTRUCTION` /
21
+ `DEFAULT_GET_LOOP_TEMPLATE` 常量与 `getLoopInstruction()`(随预渲染链一并删除;
22
+ 外部取文案请读 getloop 插件类内置模板)。
23
+
24
+ ## [0.65.1] - 2026-11-19 交付组装收编 promptplug(#227 重构)
25
+
26
+ ### Changed
27
+
28
+ - **交付组装收编 promptplug**(#227):`buildTaskDelivery` 的组装下半段(seed 构造 /
29
+ 平面扩展键保护 / getloop 预渲染 / get+check+done 三链合并 / coversBody 判定)从
30
+ `tasktool/wait.ts` 收编为 `promptplug/delivery.ts` 的 `assembleDelivery()`;宿主取数
31
+ (附件标注 / timegoal 起表 / 组上下文 / 队列余量)留在新文件 `tasktool/delivery.ts`,
32
+ `wait.ts` 只剩阻塞编排(跨进程轮询 / goal 到点收尾 / 面板随行)。边界从此可查:
33
+ **promptplug 管模板正文 + 变量 + 组装 + 渲染,tasktool 管取数 + 阻塞**。
34
+ 交付输出**逐字节不变**(prompt-golden 等 1106 项单测 + smoke 96/96 全绿钉住)。
35
+ - **任务级 timegoal 提示词模板归位**(#227):`goal-template.ts` 从 `tasktool/plugins/`
36
+ 迁为 `promptplug/plugins/goal-prompt.ts`——模板正文归提示词模板体系;领取路径
37
+ (taskgoal-store)与 check 路径(timegoal-task-store)改从 promptplug 取用,
38
+ 依赖方向单一(tasktool → promptplug),不再依赖「模板夹在两个互相 import 的
39
+ store 之间」来防环。
40
+
41
+ ## [0.65.0] - 2026-11-19 提示词三段化 / 段模板管理 / check 历史警告
42
+
43
+ ### Added
44
+
45
+ - **提示词段模板管理**(#161):设置页「提示词模板」每段可**复制出多条模板、启用哪条自己挑、
46
+ 就地编辑、删除、一键回出厂**(出厂 builtin 仍在代码里,永远可回);
47
+ 保存前按该段变量白名单校验,引用了不存在变量的模板会被拒收。
48
+ 新增 `prompt.template.save / activate / delete`(HTTP + CLI)。
49
+ - **check 历史进变量域**(#161):时间目标的段模板新增 `goal.checks`(检查流水列表,
50
+ `{{#each goal.checks}}` 遍历:时刻 / 当时进度 / 那轮现状)与 `goal.sinceLastCheckSec`
51
+ (距上次检查秒数)。
52
+ - **10 分钟重复检查严重警告**(#161):check 段与 done 段在「两次检查间隔 <10 分钟」时
53
+ 输出严重警告——防 AI 死胡同原地打转甚至 sleep 空转,要求派 sub agent 换全新切入角度
54
+ 拿新产出;首次检查不触发。
55
+ - **仓库管理页「所在组」列**(#162):main / default 视图的仓库表显示每个仓库属于哪些组
56
+ (组 chip 点击直接跳到该组分支);分组视图不显示。
57
+ - **仓库页记住分支选择**(#158):切到某个组分支后重开面板仍停在该分支(localStorage,
58
+ 所选组被删时自动回落)。
59
+
60
+ ### Changed
61
+
62
+ - **timegoal 提示词三段化**(#161):get 一段(启动介绍)/ check 一段(进度 + 每轮检查提醒,
63
+ 原 timecheck 壳 + goalhint 进度行合并)/ done 一段(完成门禁)——出厂指令正文完整写在
64
+ 段模板里(所见即所得);`nx-kv timegoal check` 的「本轮提示词」从硬编码改为**走 check 链
65
+ 实时渲染**,与 get 交付同源,设置页改段模板两处同时生效。
66
+ - `goals.prompt` 只存用户自定义(`timegoal set/update --prompt`);出厂原文视为未自定义,
67
+ 段模板编辑对旧任务同样生效。
68
+
69
+ ### Fixed
70
+
71
+ - **带槽位模板创建时「直接提交」不生效**(#156):提交意图的 key 两端不一致(存裸草稿 id、
72
+ 取 docId),自动提交从未触发——「直接提交」退化成「进入编辑页」。修复后点「直接提交」
73
+ 自动落库为待领取任务并跳到任务页。
74
+
5
75
  ## [0.64.0] - 2026-11-18 模板插槽修复 / 幽灵目录可视化 / 变量目录带含义
6
76
 
7
77
  ### Added
@@ -12,13 +12,16 @@ description: nx-kv 本机任务队列与仓库上下文的**唯一 skill**(原
12
12
  | **A(SOP)** | 5 个**专项**场景的标准动作,照着做就行 | **先看 A**——绝大多数请求都在这 |
13
13
  | **B(知识)** | 概念 / 寻址 / CLI 参数 / 数据结构 | **只有 A 覆盖不到**时才翻 |
14
14
 
15
- ## 一句话定调(三条硬规矩)
15
+ ## 一句话定调(四条硬规矩)
16
16
 
17
17
  1. **领活的标准动作是 `localtask get`**——它把任务正文、项目组上下文、附件本地路径、
18
18
  收尾要求都封装好了。**不要**先 `localtask list` / `show` 翻一遍再决定要不要领。
19
19
  2. **`timeout` 是业务结果不是错误**(exit 0):说明暂时没活,收尾即可,别重试。
20
20
  3. **读交付内容不要用 `--json`**:交付的 `instruction` 是引擎封装好的 context 原文,
21
21
  JSON 会把它转义成一行。默认输出就是逐字原文。
22
+ 4. **参考仓库入库 = 克隆 + 绑定 + 读 + 一篇主篇**。克隆只完成一半:必须实读并产出
23
+ 「概念 + 关键代码」分析,写进该仓库**唯一**的初始化主篇(`count=1 / extras=0`);
24
+ 组内「参考什么」写进主篇末尾一节,**不要用 `repo ref note` 另起一篇**。
22
25
 
23
26
  ## A 序列:5 个专项场景
24
27
 
@@ -27,7 +30,7 @@ description: nx-kv 本机任务队列与仓库上下文的**唯一 skill**(原
27
30
  | **① 领取任务**(领 → 读 → 干 → 回填 → 按反馈派生下一轮) | `nx-kv localtask get`(默认输出即逐字 context) | [[A01-领取任务]] |
28
31
  | **② 提交任务**(把上下文 + 工程知识 + 关键路径写成自包含任务) | 提炼 → 写文件 → `localtask add --file … --cwd …` | [[A02-提交任务]] |
29
32
  | **③ 文档(ref)管理**(四类宿主:开发仓库 / **参考仓库** / 组 / 组内仓库;可绑定列表;写一篇能照做的安装文档) | `docs ref add` / `docs bind` / `docs link` | [[A03-文档与归属]] |
30
- | **④ 仓库与项目组管理**(远程仓库 git 到指定位置、绑定关系) | `setting set --gitRepoRoot` → `repo clone` / `repo ref clone` → `board assign` / `repo bind` | [[A04-仓库与项目组]] |
33
+ | **④ 仓库与项目组管理**(远程仓库 git 到指定位置、绑定关系、**克隆后的读+分析收尾**) | `setting set --gitRepoRoot` → `repo clone` / `repo ref clone` → `board assign` / `repo bind` → **概念/关键代码分析写进唯一主篇** | [[A04-仓库与项目组]] |
31
34
  | **⑤ 任务链成块 + 反馈识别 + 回写 topic 的 ref** | `localtask chain` 认链尖 → 合成现状 → `docs set` / `docs bind` | [[A05-任务链与反馈汇总]] |
32
35
 
33
36
  > A 序列内部还有常用分支:领指定编号(`show` → `reorder` → `get`)、阻塞等人回填
@@ -100,6 +100,10 @@ nx-kv localtask done --id <id> --cwd "<项目目录>" --summary "<回答了什
100
100
 
101
101
  ### 4.2 CLI 侧(建 → 挂 → 查)
102
102
 
103
+ > **参考仓库入库只建一篇**:第一篇发出去就是主篇,后面所有内容(含「在本组里参考什么」)
104
+ > 都写进这一篇的正文。下面的 ③「补充篇」是给开发仓库/长系列文档用的,
105
+ > **参考仓库不要用**——那会让一个仓库在文档列表里出现两篇、组视图条目翻倍。
106
+
103
107
  ```bash
104
108
  # ① 建一篇(正文为空;拿到 refId 后再写)
105
109
  nx-kv docs ref add --owner repo --repo <参考仓库key> --desc "<这篇是什么>" --json
@@ -132,6 +136,8 @@ nx-kv docs bindings --group <组key> --json
132
136
  自己的文档列表(**desc 就在 ref 上**:desc =「在组「X」里参考什么」,重复写 = 改同一篇),
133
137
  面板上不再有弹窗与「写描述」按钮;
134
138
  关系边上只留一份供导出/导入带走的副本,真身是文档。
139
+ **但入库口径是「一仓一篇」**:参考仓库只保留初始化主篇,组内「参考什么」写进主篇末尾一节,
140
+ 不要为了写这句话另起第二篇(已有第二篇就合并进主篇后 `docs remove`,见 [[A04-仓库与项目组]] §八 8.3)。
135
141
 
136
142
  ## 五、摘 / 删:三个动作别搞混
137
143
 
@@ -15,13 +15,17 @@
15
15
  **参考仓库与开发仓库在底层只有一个 kind 的差异**(#132)——文档宿主、绑定、ext 结构都一样:
16
16
  参考仓库一样能提交文档、一样能在右侧栏当文档列表的主题(见 [[A03-文档与归属]] §四)。
17
17
 
18
- ## 二、五步把远程仓库落到指定位置
18
+ ## 二、六步把远程仓库落到指定位置(参考仓库必须走完第 5、6 步)
19
19
 
20
20
  1. **定存储根**:`setting set --gitRepoRoot`(参考仓库落点)/ `--gitDevRoot`(开发仓库落点)——不设会直接报错。
21
21
  2. **克隆或登记**:`repo clone --remote …`(开发仓库)/ `repo ref clone --url …`(参考仓库)/ `repo ref add --path …`(已有 checkout)。
22
22
  3. **对齐身份**:key 默认跟随 remote 归一化;要固化就 `--key`(或 `repo key set --follow` 恢复跟随)。
23
23
  4. **挂进关系**:`board assign`(仓库↔组)/ `repo bind`(参考仓库↔组或仓库)。
24
- 5. **写清角色**:`board note`(组内角色)/ `repo ref note`(参考它的什么——写成该参考仓库的一篇文档)。
24
+ 5. **读进去**:实读 README 与关键源文件,产出**概念 + 关键代码分析**(见 §八 8.2)。
25
+ 6. **只留一篇**:把分析写进该参考仓库的**唯一初始化主篇**,组内参考说明也写在主篇里,**不再用 `repo ref note` 另起一篇**(见 §八 8.3)。
26
+
27
+ > **参考仓库的收尾是「一篇主篇 + 一次分析」,不是「一篇介绍 + 一篇说明」。**
28
+ > 克隆只完成了「拿来看」的前半段;不读、不写、或者写成两篇,都算没做完。
25
29
 
26
30
  ## 三、把远程仓库 git 到指定位置(细账)
27
31
 
@@ -132,11 +136,14 @@ nx-kv repo import --diff --file <布局.json> --json # 导入前的差异
132
136
  nx-kv repo import --file <布局.json> --strategy ours --json # ours | overwrite | duplicate
133
137
  ```
134
138
 
135
- ## 八、克隆之后:**强制读**(调研的纪律)
139
+ ## 八、克隆并绑定之后:一次收尾(必读 + 必写 + 只留一篇)
140
+
141
+ 参考仓库是**拿来看实现**的——克隆下来不读等于没克隆;读完不落成一篇能用的主篇,等于没入库。
142
+ 所以**克隆/登记 + 绑定成功后,任务还没结束**,必须做完下面三件事。
136
143
 
137
- 参考仓库是**拿来看实现**的——克隆下来不读等于没克隆。
144
+ ### 8.1 强制读
138
145
 
139
- - 至少读 **README + 与任务直接相关的源文件/契约**;结论里写清**具体位置**(文件路径 + 函数名)。
146
+ - 至少读 **README + 与任务直接相关的源文件/契约**;结论里写清**具体位置**(文件路径 + 函数名/类名/命令名)。
140
147
  - **不许**只凭 `grep` 命中一行或搜索摘要下结论——摘要会丢上下文。
141
148
  - 引用时写清「参考的是哪个仓库的哪个文件」。
142
149
  - 2 个以上候选仓库时,先各读入口与契约再取舍,不要凭 star 数拍脑袋。
@@ -146,6 +153,68 @@ nx-kv repo import --file <布局.json> --strategy ours --json # ours | overwri
146
153
  多路调研时:3–5 路并行深搜 → 最多 clone 2 个最有价值的项目 → SSH 优先、失败双向回退 → `--depth 1` 浅克隆。
147
154
  搜索关键词优先用域内术语(接口名、协议名、错误码原文)。
148
155
 
156
+ ### 8.2 产出「概念 + 关键代码」分析(写进正文,不是写进结论里)
157
+
158
+ 分析必须落在下面五块,且每块都要带**可核对的位置**。缺任何一块就是调研没做完:
159
+
160
+ | 块 | 写什么 | 证据要求 |
161
+ | --- | --- | --- |
162
+ | **一句话定位** | 它到底是框架 / 协议 / 配置集合 / 工具 / 评测器,别被仓库名和宣传语带偏 | 引用 README 原句或目录结构 |
163
+ | **3–5 条关键概念** | 这个仓库独有的抽象,不是「支持多模型」这类通稿话 | 每条指到具体实现文件或文档章节 |
164
+ | **入口与契约** | 命令、入口函数、协议字段、schema、事件类型、配置项 | 文件路径 + 函数/类/命令名 + 真实字段名 |
165
+ | **错误与边界** | 拒绝路径、错误码、超时/过期语义、fail-closed 的地方、已知缺陷与 open issue | 错误码原文 / issue 号 |
166
+ | **可迁移手法 + 限制** | 哪些做法能搬到本项目;哪些是它自己没验证过的 | 明说「未验证」而不是替它背书 |
167
+
168
+ 数字必须来自实读:文件大小、事件条数、规则条数、限制字节数——**不要用别的文章里的数字**。
169
+
170
+ 正文骨架直接抄 `templates/ref-main-doc.md`(定位 / 关键概念 / 入口与契约 / 错误与边界 / 可迁移手法 / 限制 / 在本组里参考什么)。
171
+
172
+ ### 8.3 只保留**一篇**初始化主篇 ref
173
+
174
+ 口径:**一个参考仓库 = 一篇文档(`main=true`、position 0)**。这篇既是仓库介绍,也是入库分析,也是「在本组里参考什么」。
175
+
176
+ ```bash
177
+ KEY=github.com/owner/repo
178
+
179
+ # ① 先查现状:有没有主篇、有没有多余篇
180
+ nx-kv repo doc list --id $KEY --json # main / extras / count
181
+
182
+ # ② 没有主篇 → 建一篇(没有主篇时,建的第一篇自动成为主篇)
183
+ nx-kv docs ref add --owner repo --repo $KEY --desc "<一句话说清这篇是什么>" --json
184
+
185
+ # ③ 有主篇 → 直接用它的 refId 写正文(正文第一行必须是 `# 标题`)
186
+ nx-kv docs set --ref ref:<refId> --body-file <本地 md> --desc "<同一句话>" --json
187
+
188
+ # ④ 组内「参考什么」写进主篇末尾的一节,不要另起文档
189
+ # (在正文里加 `## 在本组里参考什么` 段落即可)
190
+
191
+ # ⑤ 若已经有多余篇(旧的 note 篇 / 附加篇)→ 先把正文并进主篇,再删掉它
192
+ nx-kv docs get --ref ref:<多余篇refId> --json
193
+ nx-kv docs remove --ref ref:<多余篇refId> --json # 会顺手清掉宿主里的悬空引用
194
+
195
+ # ⑥ 复核:必须 count=1、extras=0
196
+ nx-kv repo doc list --id $KEY --json
197
+ nx-kv docs bindings --host $KEY --json
198
+ ```
199
+
200
+ **为什么不能多一篇**(这是踩过的坑):
201
+
202
+ - `repo ref note` **不是**「改仓库描述」,它会把那句话**落成该参考仓库文档列表里的另一篇文档**:
203
+ 标题为空、`desc` 由系统生成(「在组「X」里参考什么」)、正文只有一段。
204
+ 于是每个仓库都固定多出一篇**看起来像占位说明**的短文,文档列表从 1 篇变 2 篇、组视图条目翻倍。
205
+ - 那篇 `desc` 是定位键,重复写只会改同一篇、**不会自动并进主篇**;想收敛必须自己合并再 `docs remove`。
206
+ - 克隆**未必**自动建主篇(实测有仓库克隆后 `repo doc list` 直接是 `count: 0`),所以第 ② 步的检查不能省。
207
+
208
+ ### 8.4 收尾自检(三条都过才算入库完成)
209
+
210
+ ```bash
211
+ nx-kv repo get --id $KEY --json # 落盘路径、remote、groups 正确
212
+ nx-kv repo doc list --id $KEY --json # count=1、main 有正文
213
+ nx-kv docs bindings --group <组key> --json # 组里能看到这篇,且同一仓库只出现一次
214
+ ```
215
+
216
+ 正文长度不作为硬指标,但**只有一两句话的「介绍」不算完成**:定位、关键概念、入口契约、边界、可迁移点五块齐全,才算把仓库读进去了。
217
+
149
218
  ## 九、项目级「持续 get」
150
219
 
151
220
  ```bash
@@ -165,7 +234,11 @@ nx-kv repo update --id <仓库key> --get-loop off --json
165
234
  | 目录已存在还去 clone | 会报错让你改用 `repo ref add --path` 登记(不覆盖) |
166
235
  | 改 key 当改名 | key 是身份不是名字:改名用 `repo update --id --name`;改 key 会连锁影响关系表 |
167
236
  | 组内成员顺序乱了 | `board assign --before` 插位;顺序影响组视图里的呈现 |
168
- | 参考仓库绑了但没人知道参考什么 | `repo ref note --id --board --note "…"`(落成该参考仓库的一篇文档,在文档列表里看/改) |
237
+ | 参考仓库绑了但没人知道参考什么 | **写进主篇末尾的「在本组里参考什么」一节**(不要用 `repo ref note` 另起一篇,见 §八 8.3) |
238
+ | 用 `repo ref note` 写「参考什么」 | 它会落成**另一篇**文档(标题空、desc=「在组「X」里参考什么」),把一仓一篇变成一仓两篇;要写就写进主篇 |
239
+ | 克隆完就当入库完成 | 克隆只是「拿来看」;必须再做 §八 的读 + 概念/关键代码分析 + 写进唯一主篇 |
240
+ | 以为克隆会自动建主篇 | 实测部分仓库克隆后 `count: 0`;先 `repo doc list` 查,没有就 `docs ref add` 建(自动成主篇) |
241
+ | 参考仓库文档列表有两三篇 | 合并进主篇后 `docs remove` 多余篇,复核 `count=1 / extras=0` |
169
242
  | `board prune` / `bind-topics` 直接落盘 | 它们默认**预览**,确认清单后再 `--apply` |
170
243
  | 每次都手动 `git pull` 参考仓库 | `repo ref sync --all`(ff-only,脏工作区不动) |
171
244
  | 用 `repo update --desc` 改项目介绍 | 描述已改为文档,介绍走 [[A03-文档与归属]] 的绑定 |
@@ -0,0 +1,46 @@
1
+ # <仓库名>:<一句话定位——它到底是什么类型的项目,别用宣传语>
2
+
3
+ > 用途:参考仓库入库时的**唯一一篇主篇**模板。一个参考仓库 = 一篇文档,`count=1 / extras=0`。
4
+ > 正文第一行必须是 `# 标题`(`docs set` 的硬要求);本文件里的提示行写完后删掉。
5
+
6
+ ## 一句话定位
7
+
8
+ 它属于哪一类:框架 / 协议 / 配置集合 / CLI 工具 / 评测器 / 平台。至少给两条证据(README 原句、目录结构、入口文件)。
9
+
10
+ - 证据:`<文件路径>` ——「<原文摘句>」
11
+
12
+ ## 关键概念(3–5 条,每条都要指到实现)
13
+
14
+ 1. **<概念名>**:<它解决什么问题> —— 实现见 `<路径>` 的 `<函数/类/常量>`
15
+ 2. **<概念名>**:……
16
+
17
+ > 只写这个仓库**独有**的抽象。凡是「支持多模型 / 高性能 / 易扩展」这类通稿话,删掉。
18
+
19
+ ## 入口与契约
20
+
21
+ | 维度 | 事实 | 位置 |
22
+ | --- | --- | --- |
23
+ | 命令 / 入口 | `<命令或函数>` | `<路径>` |
24
+ | 协议 / 事件 / 字段 | `<真实字段名、事件数、必填项>` | `<路径>` |
25
+ | 配置项 | `<配置键与默认值>` | `<路径>` |
26
+ | 产物 | `<生成什么文件/目录,落在哪>` | `<路径>` |
27
+
28
+ ## 错误与边界
29
+
30
+ - 拒绝路径 / 错误码:`<错误码原文>` → <什么情况触发>
31
+ - 超时 / 过期 / 重试语义:<…>
32
+ - fail-closed 的地方:<…>
33
+ - 已知缺陷与未验证项:<issue 号 / 「作者自己写了还没证明什么」>
34
+
35
+ ## 可迁移的手法
36
+
37
+ 1. <能搬到本项目的做法> —— 为什么成立、迁移时要改什么
38
+ 2. ……
39
+
40
+ ## 限制(别替它背书)
41
+
42
+ - <它没验证的、假设的、实验性的部分>
43
+
44
+ ## 在本组里参考什么
45
+
46
+ <一到两句:这个参考在「<组名>」组里被参考的具体那一块。写在这里,不要另起一篇文档。>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.64.0",
3
+ "version": "0.65.2",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,44 +17,7 @@
17
17
  import type { DbApi } from './driver.js';
18
18
 
19
19
  /**
20
- * 插槽的**统一写法**(#218):`{{content}}`。
21
- *
22
- * 为什么不许自定义名字:#217 的锁定判定靠「模板里有槽位就把它当可编辑出口」,
23
- * 名字各写各的(`{{问题}}` / `{{任务}}` / `{{需求}}`)时,一眼看不出哪段是插槽,
24
- * 也没法在文案里给用户一个固定说法。所以对用户只认一个名字 —— 一个模板可以有
25
- * 多个 `{{content}}`,它们共享同一个值(模板正文里重复出现同一段内容时用得上)。
26
- *
27
- * 渲染层仍按 `{{名字}}` 通用解析(老模板不至于一升级就失效),但出厂文本、
28
- * 新建骨架、面板文案一律只出现 `content`。
29
- */
30
- export const SLOT_NAME = 'content';
31
-
32
- /** 内置模板的槽位默认值:提示文字,不是空串(空块看不出该写什么)。 */
33
- const CONTENT_HINT = '(把你要问这个仓库的问题写在这里)';
34
-
35
- /** 模板正文里有没有插槽(含 `{{content}}` 或任何 `{{名字}}`)。 */
36
- function hasSlot(body: string): boolean {
37
- return /\{\{\s*[^}{\s][^{}]*?\s*\}\}/.test(String(body || ''));
38
- }
39
-
40
- /**
41
- * 出厂正文「被当成普通正文保存过一次」的样子:插槽已经渲染成默认值。
42
- *
43
- * #217 的模板编辑器曾经把正文渲染后再给用户编辑(保存即把 `{{content}}`
44
- * 写成提示文字),库里因此留下一批「没有插槽的内置模板」。#218 修了编辑器,
45
- * 同时用这个形态做**自愈判据**:body 与它逐字相同 = 用户没改过内容,可以安全
46
- * 恢复成带插槽的出厂文本;差一个字都不动(T06:内置不被代码覆盖用户编辑)。
47
- */
48
- function renderedFactoryBody(t: { body: string; vars?: Readonly<Record<string, unknown>> }): string {
49
- const vals = t.vars || {};
50
- return String(t.body || '').replace(/\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g, (_all, name) => {
51
- const v = vals[String(name).trim()];
52
- return v === undefined || v === null ? '' : String(v);
53
- });
54
- }
55
-
56
- /**
57
- * 内置「ref 生成」任务模板的正文(#137;#218 起插槽统一 `{{content}}`)。
20
+ * 内置「ref 生成」任务模板的正文(#137)。
58
21
  *
59
22
  * 它是**新任务正文骨架**:用户在这个仓库里提一个问题 → agent 按正文里的
60
23
  * 「零知识起步 SOP」走一遍 → 这轮问答被归档成一篇 ref,挂进该仓库的文档列表。
@@ -64,7 +27,6 @@ function renderedFactoryBody(t: { body: string; vars?: Readonly<Record<string, u
64
27
  */
65
28
  export const NEWTASK_REF_BODY = `## 本轮问题
66
29
 
67
- {{content}}
68
30
 
69
31
  ---
70
32
 
@@ -142,10 +104,7 @@ export const BUILTIN_TEMPLATES = Object.freeze([
142
104
  slot: 'suffix',
143
105
  body: NEWTASK_REF_BODY,
144
106
  varsSchema: [],
145
- // 槽位默认值 = 用户看到的「填这里」提示:渲染后任务里不是空块,点进去改成自己的问题即可。
146
- // 默认值是**提示文字**而不是空串,是因为 #217 之后这块在编辑器里是「可编辑插槽」——
147
- // 空块看不出该写什么。
148
- vars: { [SLOT_NAME]: CONTENT_HINT },
107
+ vars: {},
149
108
  isDefault: 1,
150
109
  },
151
110
  {
@@ -244,48 +203,5 @@ export function seedBuiltinTemplates(conn: DbApi, atMs: number): number {
244
203
  }
245
204
  );
246
205
  }
247
- // ③ 出厂正文自愈(#218):插槽被旧编辑器吃掉的 builtin 行恢复成带 {{content}} 的出厂文本
248
- healRenderedBuiltinBodies(conn, atMs);
249
206
  return BUILTIN_TEMPLATES.length;
250
207
  }
251
-
252
- /**
253
- * 出厂正文自愈(#218;seedBuiltinTemplates 的第 ③ 步,独立导出以便单测)。
254
- *
255
- * 两条判据,都只碰 `builtin = 1` 的行(用户自建模板 builtin=0,一律不动):
256
- *
257
- * ① **逐字相等**:body === 「出厂文本按默认值渲染后的样子」。
258
- * 旧编辑器「先渲染再编辑、保存回库」的产物,插槽变了提示文字。
259
- * ② **渲染残留**:库里这行一个插槽都没有,**但还留着出厂的提示文字**
260
- * (`{{content}}` 被替换成的「(把你要问这个仓库的问题写在这里)」)。
261
- * 跨了几个版本之后 ① 对不上(出厂文本本身改过),但症状一样:正文里再也
262
- * 检不出槽位,「新建任务」永远进不了参数填写页(#153 验收反馈)。
263
- * 只认「提示文字还在」这一种残留——用户手写的正文里没有这句提示,
264
- * 照旧按 T06 不动。
265
- *
266
- * 返回被恢复的模板 id(正常库上是空数组,幂等)。
267
- */
268
- export function healRenderedBuiltinBodies(conn: DbApi, atMs: number): string[] {
269
- const healed: string[] = [];
270
- for (const t of BUILTIN_TEMPLATES) {
271
- if (!hasSlot(t.body)) continue;
272
- const eaten = renderedFactoryBody(t);
273
- if (eaten === t.body) continue;
274
- const row = conn.get('SELECT body, builtin FROM templates WHERE id = :id', { id: t.id }) as
275
- | { body?: string; builtin?: number }
276
- | undefined;
277
- if (!row || !Number(row.builtin)) continue;
278
- const cur = String(row.body || '');
279
- const rendered = cur === eaten;
280
- // 跨版本的渲染残留:没有插槽,但出厂提示文字还在(= 旧编辑器把插槽渲染成了提示)
281
- const staleRender = !hasSlot(cur) && cur.includes(CONTENT_HINT);
282
- if (!rendered && !staleRender) continue;
283
- conn.run(
284
- `UPDATE templates SET body = :body, vars = :vars, updated_at = :at
285
- WHERE id = :id AND builtin = 1`,
286
- { id: t.id, body: t.body, vars: JSON.stringify(t.vars || {}), at: atMs },
287
- );
288
- healed.push(t.id);
289
- }
290
- return healed;
291
- }
@@ -4,7 +4,7 @@
4
4
  import { badInput, notFound } from '../../core/errors.js';
5
5
  import { formatDuration, renderInstruction } from '../../core/instruction-template.js';
6
6
  import { activeTemplateOf } from '../promptplug/index.js';
7
- import { taskGoalTemplateCtx } from '../tasktool/plugins/goal-template.js';
7
+ import { taskGoalTemplateCtx } from '../promptplug/plugins/goal-prompt.js';
8
8
  import { preserveFrontmatter } from '../../shared/frontmatter.js';
9
9
  import {
10
10
  FEEDBACK_HEADING,
@@ -7,11 +7,20 @@
7
7
  import type { ActionBase } from '../../../runtime/action-base.js';
8
8
  import type { Container } from '../../../runtime/container.js';
9
9
  import { PromptRegistryAction } from './prompt-registry.js';
10
+ import { PromptTemplateActivateAction } from './prompt-template-activate.js';
11
+ import { PromptTemplateDeleteAction } from './prompt-template-delete.js';
12
+ import { PromptTemplateSaveAction } from './prompt-template-save.js';
10
13
 
11
14
  /** 本模块的全部 action 类(容器按这个顺序建实例)。 */
12
15
  export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
13
16
  PromptRegistryAction,
17
+ PromptTemplateActivateAction,
18
+ PromptTemplateDeleteAction,
19
+ PromptTemplateSaveAction,
14
20
  ];
15
21
 
16
22
  // 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
17
23
  export { PromptRegistryAction };
24
+ export { PromptTemplateActivateAction };
25
+ export { PromptTemplateDeleteAction };
26
+ export { PromptTemplateSaveAction };
@@ -12,6 +12,7 @@ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
12
12
  import { uiDescriptor } from '../../../shared/prompt-plugin.js';
13
13
  import { buildAllPlugins } from '../factory.js';
14
14
  import { allPluginIds, assertRegistry, groupIndex } from '../registry.js';
15
+ import { allSegmentTemplates } from '../template-store.js';
15
16
 
16
17
  /** prompt.registry 的入参契约(无参)。 */
17
18
  const input = z.object({});
@@ -35,6 +36,8 @@ export class PromptRegistryAction extends ActionBase<typeof input> {
35
36
  const plugins = uiDescriptor(buildAllPlugins()).sort(
36
37
  (a, b) => order.indexOf(a.id) - order.indexOf(b.id),
37
38
  );
38
- return { groups: groupIndex(), plugins };
39
+ // #161:用户层模板数据随注册表一起外露(每段的条目 + 启用 id)——
40
+ // 出厂 builtin 在 descriptors 的 templates 里,用户条目在 segmentTemplates 里。
41
+ return { groups: groupIndex(), plugins, segmentTemplates: allSegmentTemplates() };
39
42
  }
40
43
  }
@@ -0,0 +1,31 @@
1
+ // prompt.template.activate —— 切换段启用的模板(#161)。
2
+ //
3
+ // 'builtin'(出厂第一条)或用户条目 id;装配时 factory 把启用正文传给插件构造。
4
+ import { action } from '../../../runtime/action-decorator.js';
5
+ import { z } from 'zod';
6
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
+ import { badInput } from '../../../core/errors.js';
8
+ import { pluginMeta } from '../registry.js';
9
+ import { activateTemplate } from '../template-store.js';
10
+
11
+ const input = z.object({
12
+ segment: z.string().min(1).describe('段(插件 id)'),
13
+ /** 'builtin' = 回出厂;否则须是已存在的用户条目 id */
14
+ id: z.string().min(1).describe('模板 id(builtin 或用户条目)'),
15
+ });
16
+
17
+ export class PromptTemplateActivateAction extends ActionBase<typeof input> {
18
+ @action({
19
+ id: 'prompt.template.activate',
20
+ cli: ['prompt', 'template', 'activate'],
21
+ http: ['POST', '/api/prompt/template/activate'],
22
+ summary: '切换提示词段启用的模板(builtin 或用户条目)',
23
+ input,
24
+ render: (d: any) => `[${d.segment}] 已启用模板:${d.activeId}`,
25
+ })
26
+ override async run(ctx: ActionInput<this['_input']>) {
27
+ if (!pluginMeta(ctx.segment)) throw badInput(`未知提示词段:${ctx.segment}`);
28
+ const seg = activateTemplate(ctx.segment, String(ctx.id));
29
+ return { segment: ctx.segment, ...seg };
30
+ }
31
+ }
@@ -0,0 +1,30 @@
1
+ // prompt.template.delete —— 删除一条用户段模板(#161)。
2
+ //
3
+ // 删的是启用条目时自动回落 builtin;builtin 不在内(不在 store),删不到。
4
+ import { action } from '../../../runtime/action-decorator.js';
5
+ import { z } from 'zod';
6
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
+ import { badInput } from '../../../core/errors.js';
8
+ import { pluginMeta } from '../registry.js';
9
+ import { deleteTemplate } from '../template-store.js';
10
+
11
+ const input = z.object({
12
+ segment: z.string().min(1).describe('段(插件 id)'),
13
+ id: z.string().min(1).describe('用户条目 id'),
14
+ });
15
+
16
+ export class PromptTemplateDeleteAction extends ActionBase<typeof input> {
17
+ @action({
18
+ id: 'prompt.template.delete',
19
+ cli: ['prompt', 'template', 'delete'],
20
+ http: ['POST', '/api/prompt/template/delete'],
21
+ summary: '删除提示词段的用户模板(启用中的删除后回落 builtin)',
22
+ input,
23
+ render: (d: any) => `[${d.segment}] 模板已删除(当前启用:${d.activeId})`,
24
+ })
25
+ override async run(ctx: ActionInput<this['_input']>) {
26
+ if (!pluginMeta(ctx.segment)) throw badInput(`未知提示词段:${ctx.segment}`);
27
+ const seg = deleteTemplate(ctx.segment, String(ctx.id));
28
+ return { segment: ctx.segment, ...seg };
29
+ }
30
+ }
@@ -0,0 +1,52 @@
1
+ // prompt.template.save —— 保存段模板(新建 / 编辑用户条目)(#161)。
2
+ //
3
+ // 每段可有多个模板:出厂 builtin(代码内,不可改)+ 用户条目(本 action 落盘)。
4
+ // 保存前先按该段变量白名单校验正文——坏模板不许落盘,否则运行期每轮渲染 throw。
5
+ // 新建即启用;编辑启用中的条目即时生效。
6
+ import { action } from '../../../runtime/action-decorator.js';
7
+ import { z } from 'zod';
8
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
9
+ import { badInput } from '../../../core/errors.js';
10
+ import { pluginMeta } from '../registry.js';
11
+ import { varScopeOf } from '../factory.js';
12
+ import { undeclaredTemplateVars } from '../../../shared/prompt-plugin.js';
13
+ import { upsertTemplate } from '../template-store.js';
14
+
15
+ const input = z.object({
16
+ /** 段(插件 id,如 timecheck / doneguard) */
17
+ segment: z.string().min(1).describe('段(插件 id)'),
18
+ /** 条目 id;缺省 = 新建(复制场景前端先拉原文再不带 id 提交) */
19
+ id: z.string().optional().describe('用户条目 id;缺省新建'),
20
+ name: z.string().optional().describe('模板名(缺省「未命名模板」)'),
21
+ text: z.string().min(1).describe('模板正文(Handlebars 子集)'),
22
+ });
23
+
24
+ export class PromptTemplateSaveAction extends ActionBase<typeof input> {
25
+ @action({
26
+ id: 'prompt.template.save',
27
+ cli: ['prompt', 'template', 'save'],
28
+ http: ['POST', '/api/prompt/template/save'],
29
+ summary: '保存提示词段模板(新建/编辑用户条目;保存前按该段变量白名单校验)',
30
+ input,
31
+ render: (d: any) => `[${d.segment}] 模板已保存:${d.activeId}`,
32
+ })
33
+ override async run(ctx: ActionInput<this['_input']>) {
34
+ const p = pluginMeta(ctx.segment);
35
+ if (!p) throw badInput(`未知提示词段:${ctx.segment}`);
36
+ // 白名单校验:本段可见变量域(seed ∪ 本段 dataSchema)——坏模板不许落盘
37
+ const scope = varScopeOf(ctx.segment);
38
+ const stray = undeclaredTemplateVars(String(ctx.text), scope.allowedSegments, scope.fieldKeys);
39
+ if (stray.length) {
40
+ throw badInput(
41
+ `模板引用了本段没有的变量 ${stray.join(', ')}(每段只能引用 seed(${scope.allowedSegments.join(' / ')})与自己的 dataSchema 字段)`,
42
+ );
43
+ }
44
+ const seg = upsertTemplate({
45
+ segment: ctx.segment,
46
+ id: ctx.id,
47
+ name: ctx.name,
48
+ text: String(ctx.text),
49
+ });
50
+ return { segment: ctx.segment, ...seg };
51
+ }
52
+ }