nx-kv 0.62.1 → 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 (225) hide show
  1. package/CHANGELOG.md +62 -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/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +2 -1
  4. package/package.json +2 -2
  5. package/src/core/attachmentdb/docs.ts +3 -6
  6. package/src/core/attachmentdb/query.ts +2 -2
  7. package/src/core/attachmentdb/relations.ts +36 -21
  8. package/src/core/db/import-json/refs.ts +17 -19
  9. package/src/core/db/import-json/repos.ts +4 -8
  10. package/src/core/db/migrations/index.ts +2 -0
  11. package/src/core/db/migrations/v13.sql +24 -0
  12. package/src/core/db/seed-templates.ts +86 -3
  13. package/src/core/db/version.ts +3 -1
  14. package/src/modules/docs/actions/_manifest.generated.ts +3 -3
  15. package/src/modules/docs/actions/doc-attach.ts +0 -1
  16. package/src/modules/docs/actions/docs-bindings.ts +2 -5
  17. package/src/modules/docs/actions/docs-link.ts +1 -2
  18. package/src/modules/docs/actions/docs-main.ts +39 -0
  19. package/src/modules/docs/attach.ts +1 -36
  20. package/src/modules/docs/bound-docs.ts +2 -2
  21. package/src/modules/docs/brief.ts +0 -2
  22. package/src/modules/docs/docref.ts +7 -17
  23. package/src/modules/docs/knowledge-md.ts +1 -1
  24. package/src/modules/docs/knowledge.ts +48 -45
  25. package/src/modules/docs/ref-sync.ts +1 -5
  26. package/src/modules/docs/refs.ts +82 -10
  27. package/src/modules/docs/service.ts +1 -3
  28. package/src/modules/localtask/actions/localtask-config.ts +19 -58
  29. package/src/modules/localtask/actions/localtask-prune.ts +7 -2
  30. package/src/modules/localtask/repo/open.ts +0 -4
  31. package/src/modules/localtask/repo/settings.ts +20 -196
  32. package/src/modules/localtask/task-lifecycle.ts +7 -9
  33. package/src/modules/localtask/task-templates.ts +4 -4
  34. package/src/modules/localtask/task-view.ts +4 -0
  35. package/src/modules/localtask/topics.ts +30 -28
  36. package/src/modules/promptplug/actions/_manifest.generated.ts +0 -3
  37. package/src/modules/promptplug/actions/prompt-registry.ts +19 -30
  38. package/src/modules/promptplug/base.ts +69 -25
  39. package/src/modules/promptplug/compose.ts +40 -23
  40. package/src/modules/promptplug/factory.ts +91 -59
  41. package/src/modules/promptplug/index.ts +25 -11
  42. package/src/modules/promptplug/plugins/ack.ts +28 -0
  43. package/src/modules/promptplug/plugins/attachment.ts +237 -19
  44. package/src/modules/promptplug/plugins/context.ts +124 -30
  45. package/src/modules/promptplug/plugins/doneguard.ts +33 -0
  46. package/src/modules/promptplug/plugins/ext.ts +34 -11
  47. package/src/modules/promptplug/plugins/getloop.ts +29 -8
  48. package/src/modules/promptplug/plugins/goal-shape.ts +34 -0
  49. package/src/modules/promptplug/plugins/goalhint.ts +33 -0
  50. package/src/modules/promptplug/plugins/timecheck.ts +33 -0
  51. package/src/modules/promptplug/registry.ts +99 -0
  52. package/src/modules/promptplug/schema-bridge.ts +77 -13
  53. package/src/modules/repos/actions/board-rekey.ts +1 -1
  54. package/src/modules/repos/actions/repo-doc-add.ts +2 -3
  55. package/src/modules/repos/boards/core.ts +1 -13
  56. package/src/modules/repos/boards/docs.ts +2 -12
  57. package/src/modules/repos/boards/members.ts +2 -14
  58. package/src/modules/repos/boards/transfer.ts +2 -11
  59. package/src/modules/repos/keys.ts +4 -11
  60. package/src/modules/repos/repo/refs.ts +3 -5
  61. package/src/modules/repos/repo/repos.ts +12 -13
  62. package/src/modules/repos/repo/rows.ts +2 -8
  63. package/src/modules/repos/service/context.ts +0 -2
  64. package/src/modules/repos/service/crud.ts +1 -4
  65. package/src/modules/repos/service/store.ts +6 -7
  66. package/src/modules/repos/transfer/export.ts +3 -8
  67. package/src/modules/repos/transfer/import.ts +0 -13
  68. package/src/modules/repos/transfer/layout.ts +2 -2
  69. package/src/modules/tasktool/attach-template.ts +3 -3
  70. package/src/modules/tasktool/groupctx.ts +4 -5
  71. package/src/modules/tasktool/plugins/waitgoal-config.ts +5 -6
  72. package/src/modules/tasktool/preview.ts +20 -23
  73. package/src/modules/tasktool/wait.ts +24 -46
  74. package/src/modules/templates/actions/_manifest.generated.ts +3 -0
  75. package/src/modules/templates/actions/templates-reorder.ts +28 -0
  76. package/src/modules/templates/repo/templates.ts +32 -2
  77. package/src/modules/templates/service.ts +45 -0
  78. package/src/shared/prompt-blocks.ts +7 -173
  79. package/src/shared/prompt-plugin.ts +79 -59
  80. package/src/web/frontend/App.tsx +27 -1
  81. package/src/web/frontend/api/cli-tree.json +35 -35
  82. package/src/web/frontend/api/client.generated.ts +32 -32
  83. package/src/web/frontend/components/Introduction/rail.tsx +2 -2
  84. package/src/web/frontend/components/Introduction/use-intro.ts +2 -5
  85. package/src/web/frontend/components/bindings/bind-tags.tsx +1 -3
  86. package/src/web/frontend/components/icons.tsx +12 -0
  87. package/src/web/frontend/components/list-search.tsx +37 -0
  88. package/src/web/frontend/components/md/attach-area.tsx +10 -15
  89. package/src/web/frontend/components/md/live-block.tsx +8 -2
  90. package/src/web/frontend/components/md/md-panes-root.tsx +4 -0
  91. package/src/web/frontend/components/md/md-panes.tsx +11 -1
  92. package/src/web/frontend/components/popup/style.css +4 -0
  93. package/src/web/frontend/components/sidebar/index.tsx +1 -0
  94. package/src/web/frontend/modules/list-filter.ts +37 -0
  95. package/src/web/frontend/modules/md/fill-session.ts +36 -0
  96. package/src/web/frontend/modules/md/manage-session.ts +24 -0
  97. package/src/web/frontend/modules/md/new-task-from-template.ts +22 -0
  98. package/src/web/frontend/modules/md/styles/editor.css +17 -0
  99. package/src/web/frontend/modules/md/styles/panels.css +14 -2
  100. package/src/web/frontend/modules/md/styles/shell.css +4 -0
  101. package/src/web/frontend/modules/md/task-intent.ts +29 -0
  102. package/src/web/frontend/modules/md/use-templates.ts +24 -5
  103. package/src/web/frontend/modules/prompts/template-preview.ts +62 -0
  104. package/src/web/frontend/modules/refs/api.ts +0 -1
  105. package/src/web/frontend/page/dir/index.tsx +36 -9
  106. package/src/web/frontend/page/dir/task-actions.ts +16 -1
  107. package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
  108. package/src/web/frontend/page/dir/task.tsx +21 -2
  109. package/src/web/frontend/page/doc/api.ts +2 -3
  110. package/src/web/frontend/page/doc/bindings.tsx +46 -16
  111. package/src/web/frontend/page/doc/index.tsx +3 -4
  112. package/src/web/frontend/page/group/index.tsx +72 -127
  113. package/src/web/frontend/page/refs/index.tsx +76 -13
  114. package/src/web/frontend/page/refs/style.css +7 -0
  115. package/src/web/frontend/page/repos/bind-modals.tsx +18 -2
  116. package/src/web/frontend/page/repos/block-tabs.tsx +30 -24
  117. package/src/web/frontend/page/repos/board-admin.tsx +1 -1
  118. package/src/web/frontend/page/repos/branch-picker.tsx +29 -20
  119. package/src/web/frontend/page/repos/doc-block.tsx +9 -2
  120. package/src/web/frontend/page/repos/index.tsx +67 -39
  121. package/src/web/frontend/page/repos/ref-block.tsx +11 -18
  122. package/src/web/frontend/page/repos/ref-panel.tsx +3 -4
  123. package/src/web/frontend/page/repos/repo-form-modal.tsx +1 -8
  124. package/src/web/frontend/page/repos/repo-table.tsx +12 -37
  125. package/src/web/frontend/page/repos/search-results.tsx +114 -0
  126. package/src/web/frontend/page/repos/use-repos-derive.ts +4 -5
  127. package/src/web/frontend/page/settings/api.ts +7 -15
  128. package/src/web/frontend/page/settings/index.tsx +0 -14
  129. package/src/web/frontend/page/settings/prompt-templates-section.tsx +261 -289
  130. package/src/web/frontend/page/settings/prompt-vars.ts +56 -0
  131. package/src/web/frontend/page/settings/style.css +46 -64
  132. package/src/web/frontend/page/templates/fill.tsx +124 -0
  133. package/src/web/frontend/page/templates/index.tsx +81 -30
  134. package/src/web/frontend/page/templates/manage.tsx +218 -0
  135. package/src/web/frontend/page/templates/style.css +108 -0
  136. package/src/web/frontend/page/templates/template-list.tsx +202 -0
  137. package/src/web/frontend/panels.tsx +2 -2
  138. package/src/web/frontend/refs/api.ts +10 -2
  139. package/src/web/frontend/refs/ops.ts +15 -0
  140. package/src/web/frontend/routes/route-eq.ts +22 -0
  141. package/src/web/frontend/routes/templates.ts +20 -0
  142. package/src/web/frontend/style.css +1 -0
  143. package/src/web/frontend/styles/list-search.css +44 -0
  144. package/src/web/frontend/styles/repos-branch.css +72 -0
  145. package/src/web/frontend/types.ts +6 -0
  146. package/src/web/public/assets/app-context-DDQnrPSP.js +1 -0
  147. package/src/web/public/assets/bar-j14ON7uZ.js +1 -0
  148. package/src/web/public/assets/{board-view-CxihNjDm.js → board-view-BVennxTs.js} +1 -1
  149. package/src/web/public/assets/button-BEWXOABr.js +1 -0
  150. package/src/web/public/assets/composer-launch-DRi9mZE1.js +1 -0
  151. package/src/web/public/assets/composer-panel-swmDqlPw.js +1 -0
  152. package/src/web/public/assets/dag-BzdFYMml.js +1 -0
  153. package/src/web/public/assets/dir-DhsB1ZhL.js +3 -0
  154. package/src/web/public/assets/doc-D4po3sDc.js +6 -0
  155. package/src/web/public/assets/fill-session-fHxQHFaD.js +1 -0
  156. package/src/web/public/assets/frontmatter-CN6IlxWU.js +2 -0
  157. package/src/web/public/assets/group-BxmSNzIB.js +1 -0
  158. package/src/web/public/assets/index-CMjG5NVU.js +2 -0
  159. package/src/web/public/assets/index-uMjSWNVr.css +1 -0
  160. package/src/web/public/assets/list-filter-D-x94TvA.js +1 -0
  161. package/src/web/public/assets/manage-session-CS8UvmUd.js +1 -0
  162. package/src/web/public/assets/md-history-CZUF_FhN.js +39 -0
  163. package/src/web/public/assets/{md-parse-no7xfuA1.js → md-parse-C9Vd6ejP.js} +1 -1
  164. package/src/web/public/assets/member-picker-Cvbv24IK.js +1 -0
  165. package/src/web/public/assets/{model-YH7aER_y.js → model-Cc2EoUQp.js} +1 -1
  166. package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +1 -0
  167. package/src/web/public/assets/overview-CctJfO3D.js +1 -0
  168. package/src/web/public/assets/{frontmatter-BZrdOH46.css → popup-BAvk7J7u.css} +1 -1
  169. package/src/web/public/assets/{frontmatter-CK4ti7be.js → popup-D8KWI6-Q.js} +1 -2
  170. package/src/web/public/assets/progress-CawQRCQf.js +3 -0
  171. package/src/web/public/assets/refs-TuuoaRs7.js +2 -0
  172. package/src/web/public/assets/refs-zSA2k_45.css +1 -0
  173. package/src/web/public/assets/render-template-body-bXdedFig.js +1 -0
  174. package/src/web/public/assets/repo-form-modal-BD4N37MI.js +1 -0
  175. package/src/web/public/assets/repos-BPeuX4N9.js +12 -0
  176. package/src/web/public/assets/route-crumb-BcDPd7Ht.js +1 -0
  177. package/src/web/public/assets/settings-CZJaKLZW.js +1 -0
  178. package/src/web/public/assets/settings-Cc6puKd5.css +1 -0
  179. package/src/web/public/assets/status-tag-BD_0iWMB.js +1 -0
  180. package/src/web/public/assets/task-DgbbF5gy.js +11 -0
  181. package/src/web/public/assets/task-intent-CX5DZccN.js +1 -0
  182. package/src/web/public/assets/task-row-CQgzQmzu.js +1 -0
  183. package/src/web/public/assets/{task-utils-BIUeGQ-v.js → task-utils-bJH1-Cjy.js} +1 -1
  184. package/src/web/public/assets/templates-CBXlwyof.js +11 -0
  185. package/src/web/public/assets/templates-plA8R7jJ.css +1 -0
  186. package/src/web/public/assets/use-rail-drag-ufwy2XZB.js +1 -0
  187. package/src/web/public/assets/{workspace-BFjAH4-Z.js → workspace-D3jbcTwf.js} +2 -2
  188. package/src/web/public/index.html +19 -15
  189. package/src/modules/docs/actions/doc-attach-note.ts +0 -32
  190. package/src/modules/promptplug/Template/blockTemplates.json +0 -90
  191. package/src/modules/promptplug/actions/prompt-order.ts +0 -38
  192. package/src/modules/promptplug/ensure.ts +0 -57
  193. package/src/modules/promptplug/keys.ts +0 -9
  194. package/src/modules/promptplug/plugins/readonly-blocks.ts +0 -75
  195. package/src/modules/promptplug/template-bundle.ts +0 -59
  196. package/src/web/frontend/page/settings/prompt-editor.tsx +0 -279
  197. package/src/web/frontend/page/settings/prompt-rail.tsx +0 -170
  198. package/src/web/frontend/page/settings/task-templates-section.tsx +0 -124
  199. package/src/web/public/assets/app-context-DJ_8MHEG.js +0 -1
  200. package/src/web/public/assets/bar-D_n00iZf.js +0 -1
  201. package/src/web/public/assets/composer-launch-DKpTk_et.js +0 -1
  202. package/src/web/public/assets/composer-panel-BuTQ4otm.js +0 -1
  203. package/src/web/public/assets/dag-B-5Zh9um.js +0 -1
  204. package/src/web/public/assets/dir-XjJQx6mX.js +0 -3
  205. package/src/web/public/assets/doc-nLsdRBww.js +0 -6
  206. package/src/web/public/assets/group-DzkX_qJJ.js +0 -1
  207. package/src/web/public/assets/index-Cuio6jjI.css +0 -1
  208. package/src/web/public/assets/index-kP1chg-J.js +0 -2
  209. package/src/web/public/assets/md-history-Hu_Zzy11.js +0 -39
  210. package/src/web/public/assets/member-picker-BmpHTUrK.js +0 -1
  211. package/src/web/public/assets/overview-BkzCE6-x.js +0 -1
  212. package/src/web/public/assets/progress-uUW8vQTZ.js +0 -3
  213. package/src/web/public/assets/refs-Bs0RZMWI.js +0 -2
  214. package/src/web/public/assets/refs-CIdrPlDN.css +0 -1
  215. package/src/web/public/assets/repo-form-modal-Bwr95n7V.js +0 -1
  216. package/src/web/public/assets/repos-DceWSdjD.js +0 -16
  217. package/src/web/public/assets/route-crumb-D73iZP1h.js +0 -1
  218. package/src/web/public/assets/settings-AwzLRYUu.css +0 -1
  219. package/src/web/public/assets/settings-D9LFuVWi.js +0 -1
  220. package/src/web/public/assets/status-tag-DfTirXD_.js +0 -1
  221. package/src/web/public/assets/task-1TZaYQJI.js +0 -11
  222. package/src/web/public/assets/task-row-DFH4lNSh.js +0 -1
  223. package/src/web/public/assets/templates-B8sOtXTt.js +0 -1
  224. package/src/web/public/assets/use-rail-drag-CWKmhXVF.js +0 -1
  225. /package/src/web/public/assets/{repo-form-modal-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,68 @@
2
2
 
3
3
  本文件对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.64.0] - 2026-11-18 模板插槽修复 / 幽灵目录可视化 / 变量目录带含义
6
+
7
+ ### Added
8
+
9
+ - **`localtask prune --missing-dir`**(#155):显式清理「工作目录已不存在且没有待领任务」的主题
10
+ (删掉的临时目录 / 测试残留;外接盘未挂载也会命中,所以默认关闭、必须显式开,`--dry-run` 可预演)。
11
+ - **设置页变量目录显示含义**:提示词模板的「可使用变量」从光秃秃的键名升级为
12
+ 「`repo.name` 项目名(登记名;未填时回落 key)」——含义由插件 schema 的 `.describe()`
13
+ 单一来源驱动,90+ 个变量(含数组元素内字段)自动带说明,前端零手写表;
14
+ 过长截断、悬停看完整。
15
+
16
+ ### Changed
17
+
18
+ - **任务页头部标注幽灵目录**(#155):主题的工作目录被删 / 盘未挂载时,路径旁显示
19
+ 「· 目录已不存在」(任务本身还在,只是不再有对应目录)。
20
+ - **群组页「新建」入口与目录页对齐**:按钮文案「+ 新建页」、主按钮样式、
21
+ 下拉兜底项与空态提示统一(以 repo 为准)。
22
+
23
+ ### Fixed
24
+
25
+ - **带槽位模板创建时不进参数填写页**(#153,两层根因):
26
+ ① 库里的内置模板正文是旧编辑器「渲染后保存」的产物——`{{content}}` 早被替换成
27
+ 提示文字,检出 0 个槽位就直接进草稿;出厂正文自愈新增判据:内置行整行没有插槽、
28
+ 但还留着出厂提示文字 → 以出厂正文 + 默认值恢复(用户手写的正文照旧不动)。
29
+ ② 面板路由比较只看 view/key/task,`#/templates` → `#/templates/fill/<id>` 三者相同
30
+ 被判「没变」→ 新路由被丢弃;改为全字段比较(mode/id/topic/scope/repoKey/boardKey)。
31
+ - **段的产出不再能覆盖任务本体**:交付编排里 seed(任务 id / 时间目标)优先于段的
32
+ `buildData`,防止身份字段被某一段改写。
33
+
34
+ ## [0.63.0] - 2026-11-17 文档主篇 / 全局检索 / 模板插槽三块收口(#144–#147、#217、#218)
35
+
36
+ ### Added
37
+
38
+ - **文档列表「⋯ → 设为主篇」**(#144):面板行尾菜单可以直接把某一篇设成宿主的**主篇**,
39
+ 主篇行多一枚绿色「主篇」标签(以前只有标题颜色不同,看不出谁是主篇)。
40
+ 新增 `docs.main`(CLI `nx-kv docs main --repo|--board --ref`,HTTP `POST /api/docs/main`):
41
+ 语义是**换位**——目标从附加篇摘出、**原主篇退回附加篇**,两边都不丢归属;
42
+ 目标没绑在这个宿主上直接报错,重复设同一篇幂等。
43
+ (老的 `docs bind` 只换指针、不动附加篇:目标本来在附加篇会出现「同一篇两份」,
44
+ 原主篇则失去归属、3 天后被孤儿清理——面板因此不走那条。)
45
+ - **任务模板成为独立列表页**(#217):侧边栏新增「任务模板」入口,`#/templates` 是真正的
46
+ 列表页(设置页的「任务模板」tab 下线);每张模板卡可「预览」渲染结果
47
+ (没值的槽位显示成〔槽位名〕)。
48
+ - **模板骨架只读 + 插槽可编辑**(#217/#218):模板正文里含插槽的段落,在用它建出的任务里
49
+ **只读**、插槽块可编辑(`template-locks.ts` 纯派生下标集合,零数据迁移);
50
+ 模板身份写进任务正文 frontmatter `template:<id>`;插槽统一一个名字 **`{{content}}`**
51
+ (可写多次共用同值),出厂模板正文自愈成 `{{content}}` 版(旧编辑器渲染后写回的产物,
52
+ 下次开库恢复;差一个字都不动)。
53
+ - **分组选择器底部「+ 新建分组」**(#145):弹窗问名字即建组并切过去,不用再绕「分组管理」。
54
+
55
+ ### Changed
56
+
57
+ - **仓库页文案统一「分组」**(#145):界面上一律「分组」,「分支」只是当初的比喻;
58
+ 同时删掉选择器底部与分组信息条里的解释文字(一行只留必要信息)。
59
+ - **搜索框上移到分组信息条 + 检索改成全局**(#146):搜索框与分组名同行(不再跟着区块按钮走),
60
+ 有词时区块按钮让位给「搜索结果」页——`仓库 N · 参考仓库 M · 文档 K` + 三段各一张表
61
+ (同样的行与动作,不是只读视图),一键清除回到原视图。
62
+ - **文档列表行尾只留一个 ⋯**(#147):原来那个红色 ×(移出)也收进菜单,与
63
+ 「设为主篇 / 复制 refId」并列,hint 写明「只解除归属,文档本身不删」。
64
+ - **md 窄列排版补齐紧凑档**:编辑列被挤到 ~640px 以下时标题、块距、代码块按档收紧
65
+ (宽栏排版零变化)。
66
+
5
67
  ## [0.62.1] - 2026-11-16 仓库页第二轮:计数去重、按钮收拢进 ⋯、行内补图标(#143)
6
68
 
7
69
  ### Changed
@@ -49,14 +49,15 @@ nx-kv docs bind --repo <仓库key> --ref ref:<refId> --json # 仓库的主
49
49
  nx-kv docs bind --board <组key> --ref ref:<refId> --json # 组的主篇
50
50
 
51
51
  # ③ 挂成补充篇 / 附加篇
52
- nx-kv repo doc add --id <仓库key> --ref ref:<refId> --note "<这篇在仓库里的说明>" --json
53
- nx-kv docs link --board <组key> --ref ref:<refId> --note "<这篇在组里的说明>" --json
52
+ nx-kv repo doc add --id <仓库key> --ref ref:<refId> --json
53
+ nx-kv docs link --board <组key> --ref ref:<refId> --json
54
54
 
55
55
  # ④ 挂成「组内仓库的那一篇」
56
56
  nx-kv docs note-bind --board <组key> --repo <仓库key> --ref ref:<refId> --json
57
57
  ```
58
58
 
59
- 同一篇 ref 重复添加 = 更新注解(不会多出一份)。
59
+ 同一篇 ref 重复添加 = 把它移到新位置(不会多出一份);条目上的说明
60
+ (desc)在文档本体里,v13 起关系表不再存 note。
60
61
 
61
62
  ### 3.1 把「一轮问答」归档成一篇(#137 内置任务模板「ref 生成」)
62
63
 
@@ -106,8 +107,8 @@ nx-kv docs ref add --owner repo --repo <参考仓库key> --desc "<这篇是什
106
107
  # ② 挂成主篇(这个参考仓库的「项目介绍」)
107
108
  nx-kv docs bind --repo <参考仓库key> --ref ref:<refId> --json
108
109
 
109
- # ③ 挂成补充篇(带一句说明)
110
- nx-kv repo doc add --id <参考仓库key> --ref ref:<refId> --note "<这篇在参考里的什么>" --json
110
+ # ③ 挂成补充篇
111
+ nx-kv repo doc add --id <参考仓库key> --ref ref:<refId> --json
111
112
 
112
113
  # ④ 查这一份文档列表(只有这个参考仓库自己的文档;每行 hostKind=ref)
113
114
  nx-kv docs bindings --host <参考仓库key> --json
@@ -68,7 +68,8 @@
68
68
  | `docs ref unbind` | `--ref` `--type` `--repo` `--group` | 摘归属(文档与正文保留) |
69
69
  | `docs remove` | `--ref` | 删整篇 |
70
70
  | `docs bindings` | `--ref` \| `--host <repoKey>` \| `--group <groupKey>` | 归属查询:`--host` 只给仓库自己的(含参考仓库);`--group` 给组域(组 → 组内 → 成员仓库自己 → **组内参考仓库自己**)。每行带 `hostKind`(`dev` / `ref` / `group`) |
71
- | `docs bind` / `docs link` / `docs note-bind` | `--repo`/`--board` `--ref` `--path` `--note` `--remove` `--before` `--reset` | 宿主文档集的增删改(`bind` 主篇,`link` 目录补充,`note-bind` 组内描述) |
71
+ | `docs bind` / `docs link` / `docs note-bind` | `--repo`/`--board` `--ref` `--path` `--note` `--remove` `--before` `--reset` | 宿主文档集的增删改(`bind` 主篇指针,`link` 目录补充,`note-bind` 组内描述) |
72
+ | `docs main` | `--repo`/`--board`(二选一)`--ref` \| `--path` | **把某一篇设为主篇**(换位):目标从附加篇摘出、原主篇退回附加篇,两边都不丢归属。面板「文档列表 → 行尾 ⋯ → 设为主篇」走这条;`docs bind` 只换指针、会把原主篇甩成孤儿 |
72
73
  | `docs attach` / `detach` / `attachments` / `attach-note` | `--ref` + 附件参数 | 文档附件(用法同 `localtask attach`) |
73
74
  | `docs mdfile` / `mdfiles` / `link-file` | `--attachment` / `--missing` / `--path` | md 文件指针相关 |
74
75
  | `docs gc` | `--apply` | 清没有正文的 ref(默认只报数) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.62.1",
3
+ "version": "0.64.0",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "start": "pnpm run build && node --import tsx src/runtime/cli.ts serve",
24
24
  "link:local": "node scripts/link-local.mjs",
25
25
  "unlink:local": "node scripts/link-local.mjs --unlink",
26
- "lint": "eslint . && node scripts/check-tdz.mjs --all && node scripts/check-schema-decisions.mjs && node scripts/check-lines.mjs && node scripts/check-skill-sop.mjs",
26
+ "lint": "eslint . && node scripts/check-tdz.mjs --all && node scripts/check-schema-decisions.mjs && node scripts/check-lines.mjs && node scripts/check-skill-sop.mjs && node scripts/check-test-isolation.mjs",
27
27
  "check:schema": "node scripts/check-schema-decisions.mjs",
28
28
  "check:skill": "node scripts/check-skill-sop.mjs",
29
29
  "test": "pnpm run lint && pnpm run typecheck && pnpm run build && pnpm run test:smoke && pnpm run test:unit",
@@ -119,7 +119,6 @@ export interface RefBindingRow {
119
119
  refId?: string;
120
120
  type?: string;
121
121
  position?: number;
122
- note?: string;
123
122
  atMs?: number;
124
123
  }
125
124
 
@@ -130,20 +129,18 @@ export function putRefBinding(conn: any, {
130
129
  refId,
131
130
  type = 'repo',
132
131
  position = 0,
133
- note = '',
134
132
  atMs = Date.now(),
135
133
  }: RefBindingRow = {}): void {
136
- // tag 列已在 schema v12 删除(分类标签概念整个去掉)
134
+ // tag 列在 v12 删(分类标签),note 列在 v13 删(关系表不挂业务注解)
137
135
  conn.run(
138
- `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, created_at)
139
- VALUES (:repo, :group, :ref, :type, :pos, :note, :at)`,
136
+ `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, created_at)
137
+ VALUES (:repo, :group, :ref, :type, :pos, :at)`,
140
138
  {
141
139
  repo: String(repoKey || ''),
142
140
  group: groupKey == null ? null : String(groupKey),
143
141
  ref: String(refId || ''),
144
142
  type: String(type || 'repo'),
145
143
  pos: Number(position) || 0,
146
- note: String(note || ''),
147
144
  at: atMs,
148
145
  }
149
146
  );
@@ -106,13 +106,13 @@ export function listRefAttachments(conn: any, refId?: string | number): LinkedAt
106
106
  `SELECT a.id, a.kind, a.name, a.local_path, a.url, a.mime, a.size, a.hash, a.storage,
107
107
  a.group_id, a.target_kind, a.target_key, a.target_seq, a.meta,
108
108
  a.abs_path, a.anchor_dir, a.missing_at, a.last_seen_at,
109
- a.deleted_at, a.created_at, a.updated_at, ra.role, ra.position, ra.note
109
+ a.deleted_at, a.created_at, a.updated_at, ra.role, ra.position
110
110
  FROM ref_attach ra JOIN attachments a ON a.id = ra.attachment_id
111
111
  WHERE ra.ref_id = :id AND a.deleted_at IS NULL
112
112
  ORDER BY ra.position, a.id`,
113
113
  { id: String(refId || '') }
114
114
  )
115
- .map((r: any) => ({ ...rowView(r), role: r.role, position: Number(r.position) || 0, note: r.note }));
115
+ .map((r: any) => ({ ...rowView(r), role: r.role, position: Number(r.position) || 0, note: '' }));
116
116
  }
117
117
 
118
118
  /**
@@ -42,15 +42,18 @@ export interface LinkAttachmentInput {
42
42
  /**
43
43
  * 写一条宿主 ↔ 资源的关系(upsert,带 role 优先级)。
44
44
  *
45
- * note 是**边上的说明**(desc):只在与现存 role 同级且调用方**显式给了** note
45
+ * note 是**任务附件边上的说明**(desc):只在与现存 role 同级且调用方**显式给了** note
46
46
  * (!== undefined)时才更新——正文同步等不关心 note 的调用方不传,就不会把
47
- * 用户写的说明冲掉(#162:attach --ref --note 走 embed 路径时说明不再丢)。
47
+ * 用户写的说明冲掉(#162)。#148 起 ref_attach 的 note 列已删(关系表不挂业务字段),
48
+ * 所以只有 host==='task' 才写 note;ref 侧传入的 note 一律忽略。
48
49
  * @returns {string} 实际落库的 role
49
50
  */
50
51
  export function linkAttachment(conn: any, {
51
52
  host, hostId, attachmentId, role = 'attach', position, note, atMs = Date.now(),
52
53
  }: LinkAttachmentInput = {}): AttachmentRole {
53
54
  const h = hostOf(host);
55
+ const withNote = host === 'task'; // v13:只有 task_attach 还有 note 列
56
+ const effNote = withNote ? note : undefined;
54
57
  const hostVal = host === 'task' ? Number(hostId) : String(hostId || '');
55
58
  const att = String(attachmentId || '');
56
59
  if (!att) throw new Error('linkAttachment 需要 attachmentId');
@@ -68,7 +71,7 @@ export function linkAttachment(conn: any, {
68
71
  if (curRank > newRank) return cur.role; // 显式边不被正文降级
69
72
  if (curRank === newRank) {
70
73
  const pos = position === undefined ? cur.position : position;
71
- if (note === undefined) {
74
+ if (effNote === undefined) {
72
75
  conn.run(
73
76
  `UPDATE ${h.table} SET position = :pos WHERE ${h.col} = :host AND attachment_id = :att`,
74
77
  { pos: Number(pos) || 0, host: hostVal, att }
@@ -77,16 +80,24 @@ export function linkAttachment(conn: any, {
77
80
  conn.run(
78
81
  `UPDATE ${h.table} SET position = :pos, note = :note
79
82
  WHERE ${h.col} = :host AND attachment_id = :att`,
80
- { pos: Number(pos) || 0, note: String(note || ''), host: hostVal, att }
83
+ { pos: Number(pos) || 0, note: String(effNote || ''), host: hostVal, att }
81
84
  );
82
85
  }
83
86
  return cur.role;
84
87
  }
85
- conn.run(
86
- `UPDATE ${h.table} SET role = :role, position = :pos, note = :note
87
- WHERE ${h.col} = :host AND attachment_id = :att`,
88
- { role, pos: Number(position) || 0, note: String(note || ''), host: hostVal, att }
89
- );
88
+ if (effNote === undefined) {
89
+ conn.run(
90
+ `UPDATE ${h.table} SET role = :role, position = :pos
91
+ WHERE ${h.col} = :host AND attachment_id = :att`,
92
+ { role, pos: Number(position) || 0, host: hostVal, att }
93
+ );
94
+ } else {
95
+ conn.run(
96
+ `UPDATE ${h.table} SET role = :role, position = :pos, note = :note
97
+ WHERE ${h.col} = :host AND attachment_id = :att`,
98
+ { role, pos: Number(position) || 0, note: String(effNote || ''), host: hostVal, att }
99
+ );
100
+ }
90
101
  return role;
91
102
  }
92
103
  let pos = position;
@@ -99,11 +110,19 @@ export function linkAttachment(conn: any, {
99
110
  );
100
111
  pos = Number((row && row.next) || 0);
101
112
  }
102
- conn.run(
103
- `INSERT INTO ${h.table} (${h.col}, attachment_id, role, position, note, created_at)
104
- VALUES (:host, :att, :role, :pos, :note, :at)`,
105
- { host: hostVal, att, role, pos: Number(pos) || 0, note: String(note || ''), at: atMs }
106
- );
113
+ if (effNote === undefined) {
114
+ conn.run(
115
+ `INSERT INTO ${h.table} (${h.col}, attachment_id, role, position, created_at)
116
+ VALUES (:host, :att, :role, :pos, :at)`,
117
+ { host: hostVal, att, role, pos: Number(pos) || 0, at: atMs }
118
+ );
119
+ } else {
120
+ conn.run(
121
+ `INSERT INTO ${h.table} (${h.col}, attachment_id, role, position, note, created_at)
122
+ VALUES (:host, :att, :role, :pos, :note, :at)`,
123
+ { host: hostVal, att, role, pos: Number(pos) || 0, note: String(effNote || ''), at: atMs }
124
+ );
125
+ }
107
126
  return role;
108
127
  }
109
128
 
@@ -123,6 +142,7 @@ export function updateAttachmentNote(conn: any, {
123
142
  host, hostId, attachmentId, note = '',
124
143
  }: UpdateAttachmentNoteInput = {}): number {
125
144
  const h = hostOf(host);
145
+ if (host !== 'task') return 0; // v13:ref_attach 无 note 列,任务侧才有说明
126
146
  const hostVal = host === 'task' ? Number(hostId) : String(hostId || '');
127
147
  const att = String(attachmentId || '');
128
148
  if (!att) return 0;
@@ -205,16 +225,11 @@ export function syncRefAttachments(conn: any, {
205
225
  const att = ensureAttachment(conn, r, { atMs });
206
226
  if (att && !rows.some((x) => x.id === att)) rows.push({ id: att, role: r.role });
207
227
  }
208
- // 同任务侧:整组重写保留边上的说明(note)。
209
- const notes = new Map(
210
- (conn.all("SELECT attachment_id, note FROM ref_attach WHERE ref_id = :id AND role IN ('inline', 'reference')", { id }) as Array<{ attachment_id: string; note: string }>)
211
- .map((r): [string, string] => [r.attachment_id, r.note])
212
- );
228
+ // v13:ref_attach 的 note 列已删,整组重写不再有「保留边上说明」这一步
213
229
  conn.run("DELETE FROM ref_attach WHERE ref_id = :id AND role IN ('inline', 'reference')", { id });
214
230
  rows.forEach((x, pos) => {
215
231
  linkAttachment(conn, {
216
- host: 'ref', hostId: id, attachmentId: x.id, role: x.role, position: pos,
217
- note: notes.has(x.id) ? notes.get(x.id) : undefined, atMs,
232
+ host: 'ref', hostId: id, attachmentId: x.id, role: x.role, position: pos, atMs,
218
233
  });
219
234
  });
220
235
  return rows.length;
@@ -14,7 +14,6 @@ import type { Dirent } from 'node:fs';
14
14
  interface DocRefEntry {
15
15
  locator: string;
16
16
  type: string;
17
- note: string;
18
17
  extPath: string;
19
18
  }
20
19
 
@@ -98,8 +97,7 @@ export function importRefs(
98
97
  groupKey: string | null,
99
98
  locator: string,
100
99
  type: string,
101
- position: number,
102
- note: string
100
+ position: number
103
101
  ): boolean => {
104
102
  if (!fileSet.has(locator)) return false;
105
103
  const id = idOfLocator(locator);
@@ -107,9 +105,9 @@ export function importRefs(
107
105
  // ON CONFLICT 的冲突目标带表达式(COALESCE)在 SQLite 里要写成一模一样的表达式,
108
106
  // 这里用 INSERT OR IGNORE:绑定边重复插是幂等的正常情况,不该报错。
109
107
  const r = db.run(
110
- `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, created_at)
111
- VALUES (:repo, :group, :ref, :type, :pos, :note, :at)`,
112
- { repo: repoKey, group: groupKey, ref: id, type, pos: position, note, at: atMs }
108
+ `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, created_at)
109
+ VALUES (:repo, :group, :ref, :type, :pos, :at)`,
110
+ { repo: repoKey, group: groupKey, ref: id, type, pos: position, at: atMs }
113
111
  );
114
112
  if (Number(r.changes) > 0) report.imported.refBindings += 1;
115
113
  return true;
@@ -121,19 +119,19 @@ export function importRefs(
121
119
  // DocRef(本机 repos.json 没有这些字段,代码保留给别的机器)
122
120
  const docRefsOf = (host: any): DocRefEntry[] => {
123
121
  const out: DocRefEntry[] = [];
124
- const pushRef = (ref: any, note: string = ''): void => {
122
+ const pushRef = (ref: any): void => {
125
123
  if (!ref || typeof ref !== 'object') return;
126
124
  // 旧 JSON 里的键名就叫 rel(v6 之前的字段名);读出来一律当 **locator** 用。
127
125
  const legacyPath = String(ref.rel || '').trim();
128
126
  const path = String(ref.path || '').trim();
129
- if (legacyPath) out.push({ locator: legacyPath, type: 'md', note: String(note || ''), extPath: '' });
127
+ if (legacyPath) out.push({ locator: legacyPath, type: 'md', extPath: '' });
130
128
  // v2 起 refs 只装文档:外部 .md 绝对路径也是文档,type 统一为 md。
131
- else if (path) out.push({ locator: path, type: 'md', note: String(note || ''), extPath: path });
129
+ else if (path) out.push({ locator: path, type: 'md', extPath: path });
132
130
  };
133
131
  pushRef(host && host.doc);
134
132
  for (const l of Array.isArray(host && host.docLinks) ? host.docLinks : []) pushRef(l);
135
133
  if (host && host.repoDocs && typeof host.repoDocs === 'object') {
136
- for (const [k, v] of Object.entries(host.repoDocs)) pushRef(v, k);
134
+ for (const [, v] of Object.entries(host.repoDocs)) pushRef(v);
137
135
  }
138
136
  return out;
139
137
  };
@@ -149,8 +147,8 @@ export function importRefs(
149
147
  }
150
148
  // 约定路径:目录主篇优先,其次旧单文件(与 docs 模块的读回落顺序一致)
151
149
  position = 0;
152
- const boundMain = bind(key, null, `repo/${key}/index.md`, 'repo', position, '');
153
- if (!boundMain) bind(key, null, `repo/${key}.md`, 'repo', position, '');
150
+ const boundMain = bind(key, null, `repo/${key}/index.md`, 'repo', position);
151
+ if (!boundMain) bind(key, null, `repo/${key}.md`, 'repo', position);
154
152
  position += 1;
155
153
  for (const d of docRefsOf(r)) {
156
154
  if (d.extPath) {
@@ -172,9 +170,9 @@ export function importRefs(
172
170
  continue;
173
171
  }
174
172
  const br = db.run(
175
- `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, created_at)
176
- VALUES (:repo, NULL, :ref, 'repo', :pos, :note, :at)`,
177
- { repo: key, ref: idOfLocator(d.locator), pos: position, note: d.note, at: atMs }
173
+ `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, created_at)
174
+ VALUES (:repo, NULL, :ref, 'repo', :pos, :at)`,
175
+ { repo: key, ref: idOfLocator(d.locator), pos: position, at: atMs }
178
176
  );
179
177
  if (Number(br.changes) > 0) report.imported.refBindings += 1;
180
178
  position += 1;
@@ -193,8 +191,8 @@ export function importRefs(
193
191
  continue;
194
192
  }
195
193
  const seg = base.slice('group/'.length);
196
- const boundGroup = bind(gk, null, `board/${seg}/index.md`, 'group', 0, '');
197
- if (!boundGroup) bind(gk, null, `board/${seg}.md`, 'group', 0, '');
194
+ const boundGroup = bind(gk, null, `board/${seg}/index.md`, 'group', 0);
195
+ if (!boundGroup) bind(gk, null, `board/${seg}.md`, 'group', 0);
198
196
  for (const repoKeyRaw of Array.isArray(b.repoKeys) ? b.repoKeys : []) {
199
197
  const repoKey = repoKeyById.get(String(repoKeyRaw || '').trim()) || String(repoKeyRaw || '').trim();
200
198
  if (!repoKey) continue;
@@ -202,8 +200,8 @@ export function importRefs(
202
200
  report.warnings.push({ what: 'docRef', why: '组成员不存在,已跳过成员文档绑定', group: gk, repo: repoKey });
203
201
  continue;
204
202
  }
205
- const boundMember = bind(repoKey, gk, `group/${seg}/${repoKey}/index.md`, 'group_repo', 0, '');
206
- if (!boundMember) bind(repoKey, gk, `group/${seg}/${repoKey}.md`, 'group_repo', 0, '');
203
+ const boundMember = bind(repoKey, gk, `group/${seg}/${repoKey}/index.md`, 'group_repo', 0);
204
+ if (!boundMember) bind(repoKey, gk, `group/${seg}/${repoKey}.md`, 'group_repo', 0);
207
205
  }
208
206
  }
209
207
 
@@ -146,10 +146,8 @@ export function importRepos(db: DbApi, reposData: any, atMs: number, report: Imp
146
146
  boards.forEach((b: any, bi: number) => {
147
147
  const groupKey = groupKeys[bi];
148
148
  if (!groupKey) return;
149
- const notesIn = b.repoNotes && typeof b.repoNotes === 'object' ? b.repoNotes : {};
150
149
  let keys: any[] = Array.isArray(b.repoKeys) ? b.repoKeys : [];
151
- let notes: any = notesIn;
152
- // 老结构(迁移前的存量数据):成员存随机 id(repoIds / repoNotes 按 id 键)。
150
+ // 老结构(迁移前的存量数据):成员存随机 id(repoIds 按 id)。
153
151
  // repos 已全部入库(legacyIdToKey 齐),一次性换算成 key;换算不到的丢弃 + 报告
154
152
  //(与 JSON 时代 keys.js migrateRelations 同一口径,只是搬进了导入事务)。
155
153
  const oldIds = Array.isArray(b.repoIds) ? b.repoIds : null;
@@ -160,8 +158,6 @@ export function importRepos(db: DbApi, reposData: any, atMs: number, report: Imp
160
158
  if (k) keys.push(k);
161
159
  else report.warnings.push({ what: 'member', why: 'repoIds 里的 id 换算不到 key(登记缺失),已丢弃', group: groupKey, id: String(id) });
162
160
  }
163
- notes = {};
164
- for (const [k, v] of Object.entries(notesIn)) notes[legacyIdToKey.get(String(k)) || k] = v;
165
161
  report.warnings.push({ what: 'member', why: 'repoIds(旧结构)已换算为 repoKeys', group: groupKey, count: keys.length });
166
162
  }
167
163
  keys.forEach((repoKeyRaw: any, position: number) => {
@@ -177,10 +173,10 @@ export function importRepos(db: DbApi, reposData: any, atMs: number, report: Imp
177
173
  return;
178
174
  }
179
175
  db.run(
180
- `INSERT INTO repo_group_members (group_key, repo_key, position, note, created_at)
181
- VALUES (:g, :r, :pos, :note, :at)
176
+ `INSERT INTO repo_group_members (group_key, repo_key, position, created_at)
177
+ VALUES (:g, :r, :pos, :at)
182
178
  ON CONFLICT(group_key, repo_key) DO NOTHING`,
183
- { g: groupKey, r: repoKey, pos: position, note: String(notes[repoKey] || ''), at: atMs }
179
+ { g: groupKey, r: repoKey, pos: position, at: atMs }
184
180
  );
185
181
  report.imported.members += 1;
186
182
  });
@@ -63,6 +63,7 @@ export const DIRECT_EDGES: MigrationStep[] = [
63
63
  { from: 9, to: 10, file: 'v10.sql', title: '附件新增 folder 类型(本地文件夹路径指针;重建 attachments 扩 CHECK)' },
64
64
  { from: 10, to: 11, file: 'v11.sql', title: '孤儿 ref 失绑计时(orphan_since)与到期清理留痕(ref_gc_log)', apply: migrateOrphanRefs },
65
65
  { from: 11, to: 12, file: 'v12.sql', title: '去掉分类标签概念(删 ref_bindings.tag)' },
66
+ { from: 12, to: 13, file: 'v13.sql', title: '去掉关系表上的业务 note(4 张表 drop note 列)' },
66
67
  ];
67
68
 
68
69
  // 人读版本说明(docs/decisions 是决策的唯一权威位置,里面对应一份 date 化的 .md)
@@ -79,6 +80,7 @@ export const VERSION_NOTES = {
79
80
  10: 'docs/decisions/versions/2026-11-14-v10.md',
80
81
  11: 'docs/decisions/versions/2026-11-15-v11.md',
81
82
  12: 'docs/decisions/versions/2026-11-16-v12.md',
83
+ 13: 'docs/decisions/versions/2026-11-17-v13.md',
82
84
  };
83
85
 
84
86
  const keyOf = (from: number, to: number): string => `${from}->${to}`;
@@ -0,0 +1,24 @@
1
+ -- schema v13:彻底删除「关系表上的业务 note」概念
2
+ --
3
+ -- 口径(2026-11-17 用户拍板,任务 #148):note 是前期错误的设计——
4
+ -- 1. 关系表(ref_bindings / ref_attach / group_refs / repo_group_members)
5
+ -- 本身就表达「多对多」,不该再挂一个业务字段当说明;
6
+ -- 2. 文档描述已经落到 ref 自己的 desc(v7)+ 正文标题(#168)上,
7
+ -- 参考仓库的描述也走「绑定 ref 的文档列表」(v12 的 link_notes 机制),
8
+ -- note 在界面上要么被 desc 覆盖、要么根本没显示;
9
+ -- 3. web 已经完全基于文档列表:note 既没有显示位、也不该当搜索依据。
10
+ -- 无效概念就该从根上删掉,而不是留着假装有用。
11
+ --
12
+ -- 本次动作:4 张关系表的 note 列直接删(DROP COLUMN)。
13
+ -- · ref_bindings.note —— 某份文档在某个列表里的一句话(被 desc 取代)
14
+ -- · ref_attach.note —— 附件绑定说明
15
+ -- · group_refs.note —— 参考仓库在组/仓库里参考什么(走 link_notes 描述文档)
16
+ -- · repo_group_members.note —— 仓库在组里的说明(主体是成员关系,无显示位)
17
+ -- 历史 DDL 快照(v1/v4/v5/v6/v9/v10)保持不可变,靠本迁移 drop。
18
+ --
19
+ -- 不删(主体不是关系):task_links.note(派生一句话)、repos.notes(仓库自身备注,
20
+ -- 但 web 的表单/展示位本轮一并移除,列暂留以兼容旧数据)、task_attach.note(任务附件说明)。
21
+ ALTER TABLE ref_bindings DROP COLUMN note;
22
+ ALTER TABLE ref_attach DROP COLUMN note;
23
+ ALTER TABLE group_refs DROP COLUMN note;
24
+ ALTER TABLE repo_group_members DROP COLUMN note;
@@ -17,7 +17,44 @@
17
17
  import type { DbApi } from './driver.js';
18
18
 
19
19
  /**
20
- * 内置「ref 生成」任务模板的正文(#137)。
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}}`)。
21
58
  *
22
59
  * 它是**新任务正文骨架**:用户在这个仓库里提一个问题 → agent 按正文里的
23
60
  * 「零知识起步 SOP」走一遍 → 这轮问答被归档成一篇 ref,挂进该仓库的文档列表。
@@ -27,7 +64,7 @@ import type { DbApi } from './driver.js';
27
64
  */
28
65
  export const NEWTASK_REF_BODY = `## 本轮问题
29
66
 
30
- (把你要问这个仓库的问题写在这里)
67
+ {{content}}
31
68
 
32
69
  ---
33
70
 
@@ -105,7 +142,10 @@ export const BUILTIN_TEMPLATES = Object.freeze([
105
142
  slot: 'suffix',
106
143
  body: NEWTASK_REF_BODY,
107
144
  varsSchema: [],
108
- vars: {},
145
+ // 槽位默认值 = 用户看到的「填这里」提示:渲染后任务里不是空块,点进去改成自己的问题即可。
146
+ // 默认值是**提示文字**而不是空串,是因为 #217 之后这块在编辑器里是「可编辑插槽」——
147
+ // 空块看不出该写什么。
148
+ vars: { [SLOT_NAME]: CONTENT_HINT },
109
149
  isDefault: 1,
110
150
  },
111
151
  {
@@ -204,5 +244,48 @@ export function seedBuiltinTemplates(conn: DbApi, atMs: number): number {
204
244
  }
205
245
  );
206
246
  }
247
+ // ③ 出厂正文自愈(#218):插槽被旧编辑器吃掉的 builtin 行恢复成带 {{content}} 的出厂文本
248
+ healRenderedBuiltinBodies(conn, atMs);
207
249
  return BUILTIN_TEMPLATES.length;
208
250
  }
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
+ }
@@ -38,7 +38,9 @@
38
38
  // 新增 ref_gc_log(孤儿到期清理的不可变留痕)。存量孤儿按升级时刻起算。
39
39
  // v12(2026-11-16):去掉「分类标签」概念——删 ref_bindings.tag 列。
40
40
  // 关系描述文档的定位不走 tag:desc 就在 ref 上。
41
- export const CURRENT_SCHEMA_VERSION = 12;
41
+ // v13(2026-11-17):彻底删除「关系表上的业务 note」概念——4 张关系表 drop note 列。
42
+ // 关系表本身就表达多对多;文档描述走 ref.desc + 正文标题,参考仓库描述走绑定 ref 的文档。
43
+ export const CURRENT_SCHEMA_VERSION = 13;
42
44
 
43
45
  /**
44
46
  * 运行时最低 Node 版本。
@@ -6,7 +6,6 @@
6
6
 
7
7
  import type { ActionBase } from '../../../runtime/action-base.js';
8
8
  import type { Container } from '../../../runtime/container.js';
9
- import { DocAttachNoteAction } from './doc-attach-note.js';
10
9
  import { DocAttachAction } from './doc-attach.js';
11
10
  import { DocAttachmentsAction } from './doc-attachments.js';
12
11
  import { DocDetachAction } from './doc-detach.js';
@@ -24,13 +23,13 @@ import { DocsBindingsAction } from './docs-bindings.js';
24
23
  import { DocsGcAction } from './docs-gc.js';
25
24
  import { DocsIndexAction } from './docs-index.js';
26
25
  import { DocsLinkAction } from './docs-link.js';
26
+ import { DocsMainAction } from './docs-main.js';
27
27
  import { DocsNotebindAction } from './docs-notebind.js';
28
28
  import { DocsOrphansPurgeAction } from './docs-orphans-purge.js';
29
29
  import { DocsOrphansAction } from './docs-orphans.js';
30
30
 
31
31
  /** 本模块的全部 action 类(容器按这个顺序建实例)。 */
32
32
  export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
33
- DocAttachNoteAction,
34
33
  DocAttachAction,
35
34
  DocAttachmentsAction,
36
35
  DocDetachAction,
@@ -48,13 +47,13 @@ export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
48
47
  DocsGcAction,
49
48
  DocsIndexAction,
50
49
  DocsLinkAction,
50
+ DocsMainAction,
51
51
  DocsNotebindAction,
52
52
  DocsOrphansPurgeAction,
53
53
  DocsOrphansAction,
54
54
  ];
55
55
 
56
56
  // 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
57
- export { DocAttachNoteAction };
58
57
  export { DocAttachAction };
59
58
  export { DocAttachmentsAction };
60
59
  export { DocDetachAction };
@@ -72,6 +71,7 @@ export { DocsBindingsAction };
72
71
  export { DocsGcAction };
73
72
  export { DocsIndexAction };
74
73
  export { DocsLinkAction };
74
+ export { DocsMainAction };
75
75
  export { DocsNotebindAction };
76
76
  export { DocsOrphansPurgeAction };
77
77
  export { DocsOrphansAction };