nx-kv 0.48.1 → 0.49.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 (289) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/package.json +1 -1
  3. package/src/core/attachmentdb/bodies.ts +161 -0
  4. package/src/core/attachmentdb/docs.ts +95 -33
  5. package/src/core/attachmentdb/ids.ts +27 -1
  6. package/src/core/attachmentdb/mdfile.ts +249 -0
  7. package/src/core/attachmentdb/query.ts +14 -1
  8. package/src/core/attachmentdb/resources.ts +23 -0
  9. package/src/core/attachmentdb.ts +22 -0
  10. package/src/core/db/bootstrap.ts +5 -5
  11. package/src/core/db/import-json/refs.ts +27 -13
  12. package/src/core/db/migrations/index.ts +7 -0
  13. package/src/core/db/migrations/v2-data.ts +4 -4
  14. package/src/core/db/migrations/v5.sql +100 -0
  15. package/src/core/db/migrations/v6-data.ts +261 -0
  16. package/src/core/db/migrations/v6.sql +67 -0
  17. package/src/core/db/version.ts +9 -1
  18. package/src/core/paths.ts +10 -0
  19. package/src/modules/auth/actions/auth-login.ts +11 -4
  20. package/src/modules/auth/actions/auth-logout.ts +9 -4
  21. package/src/modules/auth/actions/auth-me.ts +9 -4
  22. package/src/modules/auth/actions/auth-status.ts +9 -4
  23. package/src/modules/bundled/actions/bundled-get.ts +12 -4
  24. package/src/modules/bundled/actions/bundled-groups.ts +9 -4
  25. package/src/modules/bundled/actions/bundled-install.ts +13 -4
  26. package/src/modules/bundled/actions/bundled-list.ts +9 -4
  27. package/src/modules/db/actions/db-backup.ts +10 -4
  28. package/src/modules/db/actions/db-migrate.ts +10 -4
  29. package/src/modules/db/actions/db-status.ts +9 -4
  30. package/src/modules/db/actions/db-verify.ts +9 -4
  31. package/src/modules/docs/actions/_manifest.generated.ts +9 -0
  32. package/src/modules/docs/actions/doc-add.ts +12 -4
  33. package/src/modules/docs/actions/doc-attach-note.ts +11 -4
  34. package/src/modules/docs/actions/doc-attach.ts +20 -5
  35. package/src/modules/docs/actions/doc-attachments.ts +9 -4
  36. package/src/modules/docs/actions/doc-detach.ts +11 -4
  37. package/src/modules/docs/actions/doc-get.ts +9 -4
  38. package/src/modules/docs/actions/doc-link-file.ts +28 -0
  39. package/src/modules/docs/actions/doc-list.ts +9 -4
  40. package/src/modules/docs/actions/doc-mdfile.ts +28 -0
  41. package/src/modules/docs/actions/doc-mdfiles.ts +29 -0
  42. package/src/modules/docs/actions/doc-remove.ts +9 -4
  43. package/src/modules/docs/actions/doc-update.ts +12 -4
  44. package/src/modules/docs/actions/docs-bind.ts +13 -4
  45. package/src/modules/docs/actions/docs-index.ts +9 -4
  46. package/src/modules/docs/actions/docs-link.ts +14 -4
  47. package/src/modules/docs/actions/docs-notebind.ts +13 -4
  48. package/src/modules/docs/actions/docs-seed.ts +9 -4
  49. package/src/modules/docs/attach.ts +14 -1
  50. package/src/modules/docs/docref.ts +13 -1
  51. package/src/modules/docs/knowledge.ts +17 -19
  52. package/src/modules/docs/mdfile.ts +24 -0
  53. package/src/modules/docs/paths.ts +6 -9
  54. package/src/modules/docs/render.ts +24 -4
  55. package/src/modules/docs/seed.ts +1 -1
  56. package/src/modules/docs/service.ts +48 -18
  57. package/src/modules/docs/store.ts +120 -74
  58. package/src/modules/file/actions/file-content.ts +10 -4
  59. package/src/modules/file/actions/file-get.ts +10 -4
  60. package/src/modules/file/actions/file-list.ts +11 -4
  61. package/src/modules/file/actions/file-orphans.ts +9 -4
  62. package/src/modules/file/actions/file-prune.ts +10 -4
  63. package/src/modules/file/actions/file-remove.ts +10 -4
  64. package/src/modules/file/actions/file-sync.ts +13 -4
  65. package/src/modules/file/actions/file-upload.ts +15 -4
  66. package/src/modules/localtask/action-render.ts +2 -2
  67. package/src/modules/localtask/actions/localtask-add.ts +24 -4
  68. package/src/modules/localtask/actions/localtask-attach-note.ts +13 -4
  69. package/src/modules/localtask/actions/localtask-attach.ts +26 -6
  70. package/src/modules/localtask/actions/localtask-attachments.ts +11 -4
  71. package/src/modules/localtask/actions/localtask-cancel.ts +10 -4
  72. package/src/modules/localtask/actions/localtask-cancelMany.ts +11 -4
  73. package/src/modules/localtask/actions/localtask-chain.ts +11 -4
  74. package/src/modules/localtask/actions/localtask-claim.ts +12 -4
  75. package/src/modules/localtask/actions/localtask-clone.ts +11 -4
  76. package/src/modules/localtask/actions/localtask-closeMany.ts +13 -4
  77. package/src/modules/localtask/actions/localtask-config.ts +19 -4
  78. package/src/modules/localtask/actions/localtask-detach.ts +13 -4
  79. package/src/modules/localtask/actions/localtask-done.ts +12 -4
  80. package/src/modules/localtask/actions/localtask-events.ts +12 -4
  81. package/src/modules/localtask/actions/localtask-fork.ts +11 -4
  82. package/src/modules/localtask/actions/localtask-get.ts +11 -4
  83. package/src/modules/localtask/actions/localtask-importRemote.ts +13 -4
  84. package/src/modules/localtask/actions/localtask-list.ts +9 -4
  85. package/src/modules/localtask/actions/localtask-presence.ts +9 -4
  86. package/src/modules/localtask/actions/localtask-preview.ts +13 -4
  87. package/src/modules/localtask/actions/localtask-prune.ts +10 -4
  88. package/src/modules/localtask/actions/localtask-remove.ts +12 -4
  89. package/src/modules/localtask/actions/localtask-removeMany.ts +12 -4
  90. package/src/modules/localtask/actions/localtask-reopen.ts +17 -4
  91. package/src/modules/localtask/actions/localtask-reorder.ts +15 -4
  92. package/src/modules/localtask/actions/localtask-task-restore.ts +11 -4
  93. package/src/modules/localtask/actions/localtask-timegoalLog.ts +11 -4
  94. package/src/modules/localtask/actions/localtask-topic-add.ts +10 -4
  95. package/src/modules/localtask/actions/localtask-topic-remove.ts +11 -4
  96. package/src/modules/localtask/actions/localtask-topic-removeMany.ts +12 -4
  97. package/src/modules/localtask/actions/localtask-update.ts +22 -4
  98. package/src/modules/localtask/actions/localtask-wait.ts +13 -4
  99. package/src/modules/localtask/actions/task-move.ts +21 -4
  100. package/src/modules/repos/actions/board-add.ts +10 -4
  101. package/src/modules/repos/actions/board-assign.ts +12 -4
  102. package/src/modules/repos/actions/board-export.ts +9 -4
  103. package/src/modules/repos/actions/board-get.ts +9 -4
  104. package/src/modules/repos/actions/board-import.ts +9 -4
  105. package/src/modules/repos/actions/board-list.ts +9 -4
  106. package/src/modules/repos/actions/board-note.ts +11 -4
  107. package/src/modules/repos/actions/board-prefix.ts +10 -4
  108. package/src/modules/repos/actions/board-prune.ts +11 -4
  109. package/src/modules/repos/actions/board-rekey.ts +11 -4
  110. package/src/modules/repos/actions/board-remove.ts +9 -4
  111. package/src/modules/repos/actions/board-update.ts +11 -4
  112. package/src/modules/repos/actions/repo-add.ts +17 -4
  113. package/src/modules/repos/actions/repo-bind-topics.ts +10 -4
  114. package/src/modules/repos/actions/repo-bind.ts +12 -4
  115. package/src/modules/repos/actions/repo-clone.ts +14 -4
  116. package/src/modules/repos/actions/repo-detect.ts +9 -4
  117. package/src/modules/repos/actions/repo-doc-add.ts +15 -4
  118. package/src/modules/repos/actions/repo-doc-list.ts +9 -4
  119. package/src/modules/repos/actions/repo-doc-remove.ts +10 -4
  120. package/src/modules/repos/actions/repo-export.ts +12 -4
  121. package/src/modules/repos/actions/repo-get.ts +9 -4
  122. package/src/modules/repos/actions/repo-import-diff.ts +10 -4
  123. package/src/modules/repos/actions/repo-import.ts +14 -4
  124. package/src/modules/repos/actions/repo-key-migrate.ts +9 -4
  125. package/src/modules/repos/actions/repo-key-refresh.ts +11 -4
  126. package/src/modules/repos/actions/repo-key-set.ts +11 -4
  127. package/src/modules/repos/actions/repo-knowledge.ts +10 -4
  128. package/src/modules/repos/actions/repo-list.ts +9 -4
  129. package/src/modules/repos/actions/repo-open.ts +9 -4
  130. package/src/modules/repos/actions/repo-ref-add.ts +13 -4
  131. package/src/modules/repos/actions/repo-ref-backfill.ts +10 -4
  132. package/src/modules/repos/actions/repo-ref-check.ts +9 -4
  133. package/src/modules/repos/actions/repo-ref-clone.ts +16 -4
  134. package/src/modules/repos/actions/repo-ref-note.ts +12 -4
  135. package/src/modules/repos/actions/repo-ref-of.ts +9 -4
  136. package/src/modules/repos/actions/repo-ref-sync.ts +10 -4
  137. package/src/modules/repos/actions/repo-remote-check.ts +10 -4
  138. package/src/modules/repos/actions/repo-remote-list.ts +9 -4
  139. package/src/modules/repos/actions/repo-remote-pick.ts +10 -4
  140. package/src/modules/repos/actions/repo-remote.ts +11 -4
  141. package/src/modules/repos/actions/repo-remove.ts +9 -4
  142. package/src/modules/repos/actions/repo-scan.ts +11 -4
  143. package/src/modules/repos/actions/repo-update.ts +21 -4
  144. package/src/modules/repos/service/bind-topics.ts +8 -18
  145. package/src/modules/repos/service.ts +1 -1
  146. package/src/modules/repos/transfer/export.ts +4 -1
  147. package/src/modules/setting/actions/setting-get.ts +9 -4
  148. package/src/modules/setting/actions/setting-set.ts +12 -4
  149. package/src/modules/system/actions/bootstrap.ts +7 -4
  150. package/src/modules/system/actions/health.ts +6 -3
  151. package/src/modules/system/actions/routes.ts +11 -3
  152. package/src/modules/system/routes.ts +1 -1
  153. package/src/modules/tasktool/actions/timegoal-check.ts +11 -4
  154. package/src/modules/tasktool/actions/timegoal-clear.ts +9 -4
  155. package/src/modules/tasktool/actions/timegoal-list.ts +9 -4
  156. package/src/modules/tasktool/actions/timegoal-log.ts +9 -4
  157. package/src/modules/tasktool/actions/timegoal-prune.ts +9 -4
  158. package/src/modules/tasktool/actions/timegoal-set.ts +11 -4
  159. package/src/modules/tasktool/actions/timegoal-show.ts +10 -4
  160. package/src/modules/tasktool/actions/timegoal-update.ts +11 -4
  161. package/src/modules/tasktool/attach-resource.ts +37 -5
  162. package/src/modules/tasktool/attach-template.ts +45 -4
  163. package/src/modules/tasktool/attach.ts +47 -3
  164. package/src/modules/tasktool/doc-inline.ts +54 -29
  165. package/src/modules/templates/actions/templates-add.ts +17 -4
  166. package/src/modules/templates/actions/templates-default.ts +13 -4
  167. package/src/modules/templates/actions/templates-list.ts +11 -4
  168. package/src/modules/templates/actions/templates-remove.ts +9 -4
  169. package/src/modules/templates/actions/templates-update.ts +15 -4
  170. package/src/modules/todo/actions/group-add.ts +10 -4
  171. package/src/modules/todo/actions/group-current.ts +9 -4
  172. package/src/modules/todo/actions/group-get.ts +9 -4
  173. package/src/modules/todo/actions/group-list.ts +9 -4
  174. package/src/modules/todo/actions/group-members.ts +9 -4
  175. package/src/modules/todo/actions/group-remove.ts +9 -4
  176. package/src/modules/todo/actions/group-update.ts +11 -4
  177. package/src/modules/todo/actions/group-use.ts +9 -4
  178. package/src/modules/todo/actions/prompt-get.ts +10 -4
  179. package/src/modules/todo/actions/prompt-remove.ts +10 -4
  180. package/src/modules/todo/actions/prompt-set.ts +11 -4
  181. package/src/modules/todo/actions/todo-add.ts +11 -4
  182. package/src/modules/todo/actions/todo-archive.ts +10 -4
  183. package/src/modules/todo/actions/todo-attach.ts +17 -4
  184. package/src/modules/todo/actions/todo-attachments.ts +12 -4
  185. package/src/modules/todo/actions/todo-done.ts +13 -4
  186. package/src/modules/todo/actions/todo-freeze.ts +12 -4
  187. package/src/modules/todo/actions/todo-get.ts +12 -4
  188. package/src/modules/todo/actions/todo-list.ts +11 -4
  189. package/src/modules/todo/actions/todo-remove.ts +12 -4
  190. package/src/modules/todo/actions/todo-unfreeze.ts +12 -4
  191. package/src/modules/todo/actions/todo-update.ts +15 -4
  192. package/src/modules/todo/actions/topic-add.ts +10 -4
  193. package/src/modules/todo/actions/topic-list.ts +9 -4
  194. package/src/modules/todo/actions/topic-remove.ts +10 -4
  195. package/src/runtime/action-decorator.ts +2 -2
  196. package/src/runtime/codegen.ts +26 -41
  197. package/src/runtime/registry.ts +2 -2
  198. package/src/shared/prompt-blocks.ts +6 -1
  199. package/src/web/frontend/api/cli-tree.json +47 -2
  200. package/src/web/frontend/api/client.generated.ts +424 -536
  201. package/src/web/frontend/components/md/attach-area.tsx +58 -3
  202. package/src/web/frontend/components/md/attach-common.ts +2 -2
  203. package/src/web/frontend/modules/md/attach-mention.ts +6 -1
  204. package/src/web/frontend/modules/md/styles/chrome.css +25 -0
  205. package/src/web/frontend/page/cloud/api.ts +99 -0
  206. package/src/web/frontend/page/cloud/index.tsx +13 -32
  207. package/src/web/frontend/page/dag/api.ts +20 -0
  208. package/src/web/frontend/page/dag/index.tsx +2 -5
  209. package/src/web/frontend/page/dir/api.ts +140 -0
  210. package/src/web/frontend/page/dir/index.tsx +37 -57
  211. package/src/web/frontend/page/dir/task-actions.ts +39 -59
  212. package/src/web/frontend/page/dir/task-chain.ts +2 -2
  213. package/src/web/frontend/page/dir/task-dock-panel.tsx +87 -2
  214. package/src/web/frontend/page/dir/task-feedback.ts +19 -23
  215. package/src/web/frontend/page/dir/task-goal.ts +3 -3
  216. package/src/web/frontend/page/dir/task-status-bar.tsx +14 -1
  217. package/src/web/frontend/page/dir/task.tsx +5 -3
  218. package/src/web/frontend/page/doc/api.ts +82 -0
  219. package/src/web/frontend/page/doc/index.tsx +45 -47
  220. package/src/web/frontend/page/group/api.ts +24 -0
  221. package/src/web/frontend/page/group/index.tsx +7 -16
  222. package/src/web/frontend/page/overview/api.ts +16 -0
  223. package/src/web/frontend/page/overview/index.tsx +2 -2
  224. package/src/web/frontend/page/progress/api.ts +20 -0
  225. package/src/web/frontend/page/progress/index.tsx +3 -6
  226. package/src/web/frontend/page/refs/api.ts +14 -0
  227. package/src/web/frontend/page/refs/index.tsx +2 -4
  228. package/src/web/frontend/page/repos/api.ts +197 -0
  229. package/src/web/frontend/page/repos/bind-modals.tsx +4 -7
  230. package/src/web/frontend/page/repos/board-admin.tsx +6 -6
  231. package/src/web/frontend/page/repos/doc-search-modal.tsx +11 -4
  232. package/src/web/frontend/page/repos/index.tsx +10 -14
  233. package/src/web/frontend/page/repos/pending-section.tsx +7 -13
  234. package/src/web/frontend/page/repos/ref-panel.tsx +9 -14
  235. package/src/web/frontend/page/repos/remote-modal.tsx +4 -28
  236. package/src/web/frontend/page/repos/repo-form-modal.tsx +4 -4
  237. package/src/web/frontend/page/settings/api.ts +29 -0
  238. package/src/web/frontend/page/settings/index.tsx +3 -3
  239. package/src/web/frontend/page/settings/prompt-templates-section.tsx +4 -4
  240. package/src/web/frontend/page/settings/sidebar-section.tsx +2 -2
  241. package/src/web/public/assets/Introduction-BDS09bo3.js +6 -0
  242. package/src/web/public/assets/{bar-B9WWmCpt.js → bar-DBtVMtRi.js} +1 -1
  243. package/src/web/public/assets/cloud-0AcS7Mtd.js +3 -0
  244. package/src/web/public/assets/{composer-panel-ByezS8Xv.js → composer-panel-D624x9uT.js} +1 -1
  245. package/src/web/public/assets/dag-Ca-wjIxQ.js +1 -0
  246. package/src/web/public/assets/{deleted-panel-BcbtctNF.js → deleted-panel-BeyVhrAI.js} +1 -1
  247. package/src/web/public/assets/dir-CYGqeYZU.js +5 -0
  248. package/src/web/public/assets/group-B5cZqWIt.js +2 -0
  249. package/src/web/public/assets/{index-D8MvtVAm.js → index-BLEuH6mL.js} +2 -2
  250. package/src/web/public/assets/{index-DP3qBv1o.css → index-ChWwzUrF.css} +1 -1
  251. package/src/web/public/assets/{md-history-BqZvzWiD.js → md-history-Bpyib4z4.js} +3 -3
  252. package/src/web/public/assets/overview-DrsWuDVi.js +1 -0
  253. package/src/web/public/assets/progress-CdhFz0Lz.js +3 -0
  254. package/src/web/public/assets/{prompt-blocks-BovFd039.js → prompt-blocks-CO8msDuJ.js} +1 -1
  255. package/src/web/public/assets/refs-DMVuOOK9.js +1 -0
  256. package/src/web/public/assets/repos-C5OwK72H.js +15 -0
  257. package/src/web/public/assets/{route-crumb-CWVu80du.js → route-crumb-6q3rIB-_.js} +1 -1
  258. package/src/web/public/assets/settings-BH_l1Yek.js +1 -0
  259. package/src/web/public/assets/{status-tag-DRl9E2Os.js → status-tag-BD6cdnyb.js} +1 -1
  260. package/src/web/public/assets/task-B7AjuMiC.js +11 -0
  261. package/src/web/public/assets/task-utils-BNFx9yag.js +12 -0
  262. package/src/web/public/assets/{templates-Df__0k-F.js → templates-G7kHB-xI.js} +1 -1
  263. package/src/web/public/assets/tool-bar-DIXBM0wv.js +1 -0
  264. package/src/web/public/index.html +2 -2
  265. package/src/modules/auth/schemas.ts +0 -27
  266. package/src/modules/bundled/schemas.ts +0 -32
  267. package/src/modules/db/schemas.ts +0 -27
  268. package/src/modules/docs/schemas.ts +0 -107
  269. package/src/modules/file/schemas.ts +0 -61
  270. package/src/modules/localtask/schemas.ts +0 -310
  271. package/src/modules/repos/schemas.ts +0 -310
  272. package/src/modules/setting/schemas.ts +0 -18
  273. package/src/modules/system/schemas.ts +0 -30
  274. package/src/modules/tasktool/schemas.ts +0 -52
  275. package/src/modules/templates/schemas.ts +0 -50
  276. package/src/modules/todo/schemas.ts +0 -177
  277. package/src/web/public/assets/Introduction-aQCeCLrV.js +0 -6
  278. package/src/web/public/assets/cloud-C4b8SU7C.js +0 -3
  279. package/src/web/public/assets/dag-jvrjx4i7.js +0 -1
  280. package/src/web/public/assets/dir-B82XBb1J.js +0 -5
  281. package/src/web/public/assets/group-BPUOO_QM.js +0 -2
  282. package/src/web/public/assets/overview-DMihuyzh.js +0 -1
  283. package/src/web/public/assets/progress-D-rMgz3w.js +0 -3
  284. package/src/web/public/assets/refs-D21jmrn6.js +0 -1
  285. package/src/web/public/assets/repos-B94tMDGs.js +0 -15
  286. package/src/web/public/assets/settings-DgTt4JG5.js +0 -1
  287. package/src/web/public/assets/task-B2x5GoV3.js +0 -11
  288. package/src/web/public/assets/task-utils-By8gLpHY.js +0 -12
  289. package/src/web/public/assets/tool-bar-Cv7f6p4v.js +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,61 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.49.0] - 2026-11-12 ref 正文入库(v6)与 DOCS_DIR 收口
6
+
7
+ ### Added
8
+
9
+ - **`ref_bodies`:文档正文的唯一真相**。`refs` 增加 `rel/origin/body_bytes`,
10
+ `docs add/set` 只写库不落盘;`docs list/get`、`repo knowledge`、交付注入、
11
+ 面板文档页全部改为读库,删掉磁盘扫描分支。
12
+ - **读路径区分 `normal / legacy / external / empty`**:`legacy/<id>`、`external/<sha1>`
13
+ 与无正文行在列表、文档页、交付清单里显式标「无正文」,`docs get` 返回 `missing`
14
+ 并给出原因,不再渲染成空文件。
15
+ - **`docs-dir-policy` 单测**:扫描 `src/**`,`NX_KV_DOCS_DIR` / `docsRoot` /
16
+ `mdfileDirFromEnv` 只允许出现在 paths、attachment 层与迁移脚本里。
17
+
18
+ ### Changed
19
+
20
+ - **`NX_KV_DOCS_DIR` 语义收敛为 mdfile 的默认附件目录**(环境变量名不变,既有配置
21
+ 继续生效):`docsRoot()` → `mdfileDir()` / `mdfileDirFromEnv()`,唯一读入口为
22
+ `readMdfile`,任何模块不得直接扫盘。
23
+ - **外部 md 交付不再自动内联**:未登记为附件时显式提示「该文档未登记为附件,
24
+ 无法内联」,并给出可直接执行的 `nx-kv localtask attach --mdfile <abs>` 命令。
25
+ - **删除 O9 守卫**「文档树内禁止登记 mdfile」及其 `RegisterMdfileInput.docsRoot`
26
+ 参数——默认目录本就是 mdfile 的存放地,二者语义矛盾。
27
+
28
+ ### Notes
29
+
30
+ - **数据库自动升级 v4 → v6**:新建 `ref_bodies`(PK `ref_id`,FK CASCADE),
31
+ `ref_attach` 重建(role 增加 `source`),外部文件仍在时登记 mdfile +
32
+ `ref_attach(role='source')`,不在则只留空壳;逐篇 sha256 硬门禁,任一不符整步回滚。
33
+ 升级前自动备份为 `backups/nxkv-v4-<时间戳>.db`。
34
+ - 存量 133 行 `refs.id` 全部保留(公式仍为 `ref_<sha1(rel)>`,输入从 locator 换成 rel)。
35
+ - 31 份盘上 `.md` 入库后磁盘副本只留档,不再读取、不再自动登记 mdfile。
36
+ - 验证:unit 921 / smoke 200 / lint 0 error;真实库副本 5 项端到端(迁移计数
37
+ 133/31/67/87 + `foreign_key_check` 空、CLI 全链、面板走查、故意违规被拦、壳行 missing 回归)。
38
+
39
+
40
+ ## [0.48.2] - 2026-11-12 zod 契约内联进 action 文件(#178 第 4 轮)
41
+
42
+ ### Changed
43
+
44
+ - **不再有独立的 `schemas.ts`**:每条 action 的 zod 契约(运行期契约)直接声明在
45
+ 自己的 action 文件里,模块私有、就在类上方,命名为 `input`。12 个 `schemas.ts`
46
+ (1201 行)随之删除,154 个 action 文件各带一份契约。
47
+ 契约内容**逐字保留**——`.describe()` 是 CLI 用法串与 help 文案的来源,动了就改口径。
48
+ - **前端入参类型改为从 action 类反推**(`z.input<InstanceType<typeof XAction>['_input']>`):
49
+ 类型经基类泛型模板流到前端,契约常量降级为「文件内的实现细节」,
50
+ 生成物不再 import 后端契约文件。
51
+ - **删掉 `<camelCase(actionId)>Input` 命名约定**:旧方案靠约定拼 import 名,
52
+ 约定破了会生成指向不存在符号的代码;现在约定不再存在,也就没有破的可能。
53
+
54
+ ### Notes
55
+
56
+ - 纯结构调整,对外行为不变(契约内容与位置语义不变:字段、用法串、help 文案均不变)。
57
+ - 验证:node 侧 strict 0 错误 / 生成物及传递依赖 web 编译 0 错误 / eslint 0 error /
58
+ unit 906 / smoke 194。
59
+
5
60
  ## [0.48.1] - 2026-11-11 action 入参泛型化(#177 第 3 轮)
6
61
 
7
62
  ### Changed
@@ -25,6 +80,17 @@
25
80
  - 已知约束:TS 对类成员声明没有上下文类型注入通路(override 与装饰器都试过),
26
81
  因此注解必须存在——但它是全项目统一样板,不再重述 schema 结构。
27
82
 
83
+ ## [Unreleased]
84
+
85
+ ### Changed
86
+
87
+ - **前端页面 API 收口到各页 api.ts**(模板约定,#176):10 个页面(overview / dag / refs /
88
+ progress / group / settings / cloud / doc / dir / repos)共约 97 处 `api()` 调用搬到
89
+ 各页私有的 `api.ts` 具名函数——请求路径、方法、body 形状、返回值处理、错误分支与 toast
90
+ 文案逐字保留;页面组件只消费具名函数,不再直接调 `api()`。
91
+ - **eslint 收口规则**:页面组件(`page/**`,不含各页 `api.ts`)禁止出现 `api()` 裸调用
92
+ (`no-restricted-syntax`),防止形态回潮。
93
+
28
94
  ## [0.48.0] - 2026-11-11 全仓 TypeScript 毕业(#175)
29
95
 
30
96
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.48.1",
3
+ "version": "0.49.0",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,161 @@
1
+ // ref 正文(ref_bodies)的读写与条目分类。
2
+ //
3
+ // v6 起 `refs` 是文档身份 + 元数据,正文唯一真相在 `ref_bodies`(1:1,CASCADE)。
4
+ // 本模块只做三件事:
5
+ // 1. 正文 CRUD(upsert / get);
6
+ // 2. rel ↔ id 的解析(rel 是逻辑名,id 是外键目标);
7
+ // 3. 条目分类:normal / legacy / external / empty —— 让调用方能区分
8
+ // 「正常文档」与「历史空壳 / 外部文件镜像 / 无正文」。
9
+ //
10
+ // 分类口径(docs/decisions/2026-11-12-refs-body-in-db.md §11.1):
11
+ // legacy/<id> 迁移时无 locator 的历史行,只有身份、没有正文;
12
+ // external/<hash> 外部绝对路径 / URL 的镜像行,正文在库外,不进 ref_bodies;
13
+ // empty 其它没有正文的活动行(如盘上文件已删的历史条目);
14
+ // normal 有正文、且不是上面两类命名空间。
15
+ import { createHash } from 'node:crypto';
16
+
17
+ /** 一条 ref 条目的读路径类别。 */
18
+ export type RelKind = 'normal' | 'legacy' | 'external' | 'empty';
19
+
20
+ /** 一条正文记录。 */
21
+ export interface RefBodyRow {
22
+ ref_id: string;
23
+ body: string;
24
+ body_bytes: number;
25
+ body_hash: string;
26
+ updated_at: number;
27
+ }
28
+
29
+ /** 列表用的一条 ref 条目(带正文是否存在)。 */
30
+ export interface RefDocRow {
31
+ id: string;
32
+ rel: string;
33
+ origin: string;
34
+ bodyBytes: number;
35
+ hasBody: boolean;
36
+ relKind: RelKind;
37
+ }
38
+
39
+ const sha256 = (s: string): string => createHash('sha256').update(s, 'utf8').digest('hex');
40
+
41
+ /** rel + 是否有正文 → 读路径类别。 */
42
+ export function relKindOf(rel: unknown, hasBody: boolean): RelKind {
43
+ const r = String(rel || '');
44
+ if (r.startsWith('legacy/')) return 'legacy';
45
+ if (r.startsWith('external/')) return 'external';
46
+ return hasBody ? 'normal' : 'empty';
47
+ }
48
+
49
+ /** 无正文条目的原因(给人读;docs get / 交付清单共用)。 */
50
+ export function noBodyReason(kind: RelKind): string {
51
+ if (kind === 'legacy') return '历史索引条目:只有身份与旧地址,没有正文';
52
+ if (kind === 'external') return '外部文件镜像:正文在库外,未入库';
53
+ if (kind === 'empty') return '条目存在但正文缺失(文件已删除或从未入库)';
54
+ return '';
55
+ }
56
+
57
+ /** rel 是否属于「不允许当正常文档展示」的命名空间。 */
58
+ export function isShellRel(rel: unknown): boolean {
59
+ const r = String(rel || '');
60
+ return r.startsWith('legacy/') || r.startsWith('external/');
61
+ }
62
+
63
+ /** 按 refs.id 取正文。 */
64
+ export function getRefBody(conn: any, refId: unknown): RefBodyRow | null {
65
+ const row = conn.get(
66
+ 'SELECT ref_id, body, body_bytes, body_hash, updated_at FROM ref_bodies WHERE ref_id = :id',
67
+ { id: String(refId || '') }
68
+ );
69
+ return row ? (row as RefBodyRow) : null;
70
+ }
71
+
72
+ /** 写正文(UPSERT),返回字节数与 sha256。body_bytes 一律按 UTF-8 计。 */
73
+ export function upsertRefBody(
74
+ conn: any,
75
+ { refId, body, atMs = Date.now() }: { refId: string; body: unknown; atMs?: number }
76
+ ): { bytes: number; hash: string } {
77
+ const text = String(body ?? '');
78
+ const bytes = Buffer.byteLength(text, 'utf8');
79
+ const hash = sha256(text);
80
+ conn.run(
81
+ `INSERT INTO ref_bodies (ref_id, body, body_bytes, body_hash, updated_at)
82
+ VALUES (:id, :body, :n, :hash, :at)
83
+ ON CONFLICT(ref_id) DO UPDATE SET
84
+ body = excluded.body,
85
+ body_bytes = excluded.body_bytes,
86
+ body_hash = excluded.body_hash,
87
+ updated_at = excluded.updated_at`,
88
+ { id: refId, body: text, n: bytes, hash, at: atMs }
89
+ );
90
+ return { bytes, hash };
91
+ }
92
+
93
+ /** 按 rel 找活动行的 id(rel 是逻辑名,唯一)。 */
94
+ export function refIdByRel(conn: any, rel: unknown): string | null {
95
+ const r = String(rel || '').trim();
96
+ if (!r) return null;
97
+ const row = conn.get(
98
+ 'SELECT id FROM refs WHERE rel = :rel AND deleted_at IS NULL',
99
+ { rel: r }
100
+ );
101
+ return row ? String(row.id) : null;
102
+ }
103
+
104
+ /**
105
+ * 列出 ref 条目。
106
+ * @param includeEmpty=false 只给「有正文且非 legacy/external」的正常文档
107
+ * (默认口径,供导出/双链/知识聚合使用);
108
+ * true 连历史空壳、外部镜像、无正文行一起给(`docs list` 用,需显式标注)。
109
+ */
110
+ export function listRefDocs(conn: any, { includeEmpty = false }: { includeEmpty?: boolean } = {}): RefDocRow[] {
111
+ const rows: any[] = conn.all(
112
+ `SELECT r.id, r.rel, r.origin, r.body_bytes,
113
+ CASE WHEN b.ref_id IS NULL THEN 0 ELSE 1 END AS has_body
114
+ FROM refs r
115
+ LEFT JOIN ref_bodies b ON b.ref_id = r.id
116
+ WHERE r.deleted_at IS NULL AND r.rel <> ''
117
+ ORDER BY r.rel`
118
+ );
119
+ const out: RefDocRow[] = [];
120
+ for (const row of rows) {
121
+ const rel = String(row.rel || '');
122
+ const hasBody = Number(row.has_body) === 1;
123
+ const relKind = relKindOf(rel, hasBody);
124
+ if (!includeEmpty && (!hasBody || relKind !== 'normal')) continue;
125
+ out.push({
126
+ id: String(row.id),
127
+ rel,
128
+ origin: String(row.origin || ''),
129
+ bodyBytes: Number(row.body_bytes) || 0,
130
+ hasBody,
131
+ relKind,
132
+ });
133
+ }
134
+ return out;
135
+ }
136
+
137
+ /** 按 rel 取条目状态(含正文);不存在返回 null。 */
138
+ export function refDocByRel(conn: any, rel: unknown): (RefDocRow & { body: string | null }) | null {
139
+ const r = String(rel || '').trim();
140
+ if (!r) return null;
141
+ const row = conn.get(
142
+ `SELECT r.id, r.rel, r.origin, r.body_bytes,
143
+ CASE WHEN b.ref_id IS NULL THEN 0 ELSE 1 END AS has_body,
144
+ b.body
145
+ FROM refs r
146
+ LEFT JOIN ref_bodies b ON b.ref_id = r.id
147
+ WHERE r.rel = :rel AND r.deleted_at IS NULL`,
148
+ { rel: r }
149
+ );
150
+ if (!row) return null;
151
+ const hasBody = Number(row.has_body) === 1;
152
+ return {
153
+ id: String(row.id),
154
+ rel: String(row.rel),
155
+ origin: String(row.origin || ''),
156
+ bodyBytes: Number(row.body_bytes) || 0,
157
+ hasBody,
158
+ relKind: relKindOf(row.rel, hasBody),
159
+ body: hasBody ? String(row.body ?? '') : null,
160
+ };
161
+ }
@@ -1,35 +1,42 @@
1
1
  // 文档索引:refs 行的解析/建/删,与任务、文档两块正文的整库重扫(迁移与索引用;幂等)。
2
2
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
3
3
  import type { Dirent } from 'node:fs';
4
+ import { createHash } from 'node:crypto';
4
5
  import { isAbsolute, join, relative, resolve } from 'node:path';
5
6
  import { refIdFor } from './ids.js';
7
+ import { refIdByRel } from './bodies.js';
6
8
  import { syncRefAttachments, syncTaskAttachments } from './relations.js';
7
9
 
8
10
  /**
9
- * 把一个「文档标识」解析成 refs.id:先按 id,再按 locator(原样 / 反斜杠归一),
10
- * 都没有返回 null。CLI `--ref` 与面板选择器共用这一条,避免各自猜地址语法。
11
+ * 把一个「文档标识」解析成 refs.id:先按 id,再按 rel(v6 起的逻辑名),
12
+ * 再按 locator(历史入口 / 外部绝对路径),都没有返回 null。
13
+ * CLI `--ref` 与面板选择器共用这一条,避免各自猜地址语法。
11
14
  *
12
- * **docId 前缀也认**(#165 二轮:面板选择器给的是 `rel:` / `path:` 形式,
13
- * 而 refs.locator 存的是裸相对路径 / 绝对路径——不剥前缀就永远匹配不上,
14
- * 面板「给任务挂文档」直接失败)。故额外按「剥前缀后的 locator」再查一次。
15
+ * **docId 前缀也认**(#165 二轮:面板选择器给的是 `rel:` / `path:` 形式)。
15
16
  */
16
17
  export function resolveRefId(conn: any, input?: string): string | null {
17
18
  const raw = String(input || '').trim();
18
19
  if (!raw) return null;
19
20
  const byId = conn.get('SELECT id FROM refs WHERE id = :id AND deleted_at IS NULL', { id: raw });
20
21
  if (byId) return byId.id;
22
+
21
23
  const loc = raw.replace(/\\/g, '/');
22
- const byLoc = conn.get(
23
- 'SELECT id FROM refs WHERE locator = :loc AND deleted_at IS NULL', { loc }
24
- );
25
- if (byLoc) return byLoc.id;
26
- // docId 形态(rel:xxx / path:xxx)→ 剥前缀按 locator 再查
27
24
  const stripped = /^rel:|^path:/i.test(loc) ? loc.replace(/^rel:|^path:/i, '') : '';
28
- if (stripped) {
29
- const byStripped = conn.get(
30
- 'SELECT id FROM refs WHERE locator = :loc AND deleted_at IS NULL', { loc: stripped }
25
+ const candidates = [loc, stripped].filter(Boolean);
26
+
27
+ // v6 之前(迁移链早期步骤)refs 还没有 rel 列,只能走历史 locator 入口
28
+ if (hasRelColumn(conn)) {
29
+ for (const cand of candidates) {
30
+ const id = refIdByRel(conn, cand);
31
+ if (id) return id;
32
+ }
33
+ }
34
+ // 历史入口:locator(v4 及以前的行;外部绝对路径仍靠它命中)
35
+ for (const cand of candidates) {
36
+ const byLoc = conn.get(
37
+ 'SELECT id FROM refs WHERE locator = :loc AND deleted_at IS NULL', { loc: cand }
31
38
  );
32
- if (byStripped) return byStripped.id;
39
+ if (byLoc) return byLoc.id;
33
40
  }
34
41
  const derived = refIdFor(loc);
35
42
  const byDerived = conn.get('SELECT id FROM refs WHERE id = :id AND deleted_at IS NULL', { id: derived });
@@ -37,29 +44,79 @@ export function resolveRefId(conn: any, input?: string): string | null {
37
44
  }
38
45
 
39
46
  export interface EnsureDocRefInput {
47
+ /** v6 起的逻辑名(首选) */
48
+ rel?: string;
49
+ /** 历史入口 / 外部绝对路径(兼容既有调用方) */
40
50
  locator?: string;
41
51
  atMs?: number;
42
52
  }
43
53
 
44
- /** 确保 refs 行存在(文档保存 / 索引重建共用;已有行不重置 state)。 */
45
- export function ensureDocRef(conn: any, { locator, atMs = Date.now() }: EnsureDocRefInput = {}): string | null {
46
- const loc = String(locator || '').trim().replace(/\\/g, '/');
47
- if (!loc) return null;
48
- const id = refIdFor(loc);
54
+ const sha1 = (s: unknown): string => createHash('sha1').update(String(s), 'utf8').digest('hex');
55
+
56
+ /**
57
+ * refs 是否已有 v6 的 rel 列。
58
+ * 迁移链会从旧结构逐级升级:v2-data 也会调 ensureDocRef,那时 rel 还不存在,
59
+ * 不能无条件查询它(否则 1→2 直接失败)。列存在性用 pragma_table_info 判断。
60
+ */
61
+ function hasRelColumn(conn: any): boolean {
62
+ return !!conn.get("SELECT name FROM pragma_table_info('refs') WHERE name = 'rel'");
63
+ }
64
+
65
+ /** 外部绝对路径 / URL 的逻辑 rel(v6 迁移同一口径)。 */
66
+ function externalRelOf(input: string): string {
67
+ let seed = isAbsolute(input) ? resolve(input).replace(/\\/g, '/') : input;
68
+ if (/^[A-Z]:/.test(seed)) seed = seed.charAt(0).toLowerCase() + seed.slice(1);
69
+ return 'external/' + sha1(seed).slice(0, 16);
70
+ }
71
+
72
+ /**
73
+ * 确保 refs 行存在(文档保存 / 索引重建共用;已有行不重置 state)。
74
+ * 先按 rel / locator 命中既有行——v6 迁移保留的 id 绝不被新公式改写。
75
+ */
76
+ export function ensureDocRef(conn: any, { rel, locator, atMs = Date.now() }: EnsureDocRefInput = {}): string | null {
77
+ const input = String(rel ?? locator ?? '').trim().replace(/\\/g, '/');
78
+ if (!input) return null;
79
+ const hasRel = hasRelColumn(conn);
80
+ if (hasRel) {
81
+ const byRel = refIdByRel(conn, input);
82
+ if (byRel) return byRel;
83
+ }
84
+ // 绝对路径 / URL:先按 locator 命中(外部镜像行的 id 与 rel 都不是新公式)
85
+ const byLoc = conn.get(
86
+ 'SELECT id FROM refs WHERE locator = :loc AND deleted_at IS NULL', { loc: input }
87
+ );
88
+ if (byLoc) return String(byLoc.id);
89
+
90
+ // v6 之前:保持历史形态(不动 locator 之外的语义)
91
+ if (!hasRel) {
92
+ const oldId = refIdFor(input);
93
+ conn.run(
94
+ `INSERT INTO refs (id, type, locator, state, version, deleted_at, created_at, updated_at)
95
+ VALUES (:id, 'md', :locator, 'orphan', 0, NULL, :at, :at)
96
+ ON CONFLICT(id) DO UPDATE SET type = 'md', locator = excluded.locator, updated_at = excluded.updated_at`,
97
+ { id: oldId, locator: input, at: atMs }
98
+ );
99
+ return oldId;
100
+ }
101
+
102
+ const external = /^https?:\/\//i.test(input)
103
+ || isAbsolute(input) || /^[A-Za-z]:[\\/]/.test(input) || input.startsWith('//');
104
+ const targetRel = external ? externalRelOf(input) : input;
105
+ const id = refIdFor(external ? input : targetRel);
49
106
  conn.run(
50
- `INSERT INTO refs (id, type, locator, state, version, deleted_at, created_at, updated_at)
51
- VALUES (:id, 'md', :locator, 'orphan', 0, NULL, :at, :at)
52
- ON CONFLICT(id) DO UPDATE SET type = 'md', locator = excluded.locator, updated_at = excluded.updated_at`,
53
- { id, locator: loc, at: atMs }
107
+ `INSERT INTO refs (id, type, rel, locator, origin, state, version, deleted_at, created_at, updated_at)
108
+ VALUES (:id, 'md', :rel, :locator, :origin, 'orphan', 0, NULL, :at, :at)
109
+ ON CONFLICT(id) DO NOTHING`,
110
+ { id, rel: targetRel, locator: input, origin: external ? 'external' : 'own', at: atMs }
54
111
  );
55
112
  return id;
56
113
  }
57
114
 
58
- /** 文档删除:refs 行消失,ref_attach / ref_bindings 随之 CASCADE。 */
59
- export function forgetDocRef(conn: any, locator?: string): number {
60
- const loc = String(locator || '').trim().replace(/\\/g, '/');
61
- if (!loc) return 0;
62
- const r = conn.run('DELETE FROM refs WHERE id = :id', { id: refIdFor(loc) });
115
+ /** 文档删除:refs 行消失,ref_bodies / ref_attach / ref_bindings 随之 CASCADE。 */
116
+ export function forgetDocRef(conn: any, input?: string): number {
117
+ const id = resolveRefId(conn, input);
118
+ if (!id) return 0;
119
+ const r = conn.run('DELETE FROM refs WHERE id = :id', { id });
63
120
  return Number(r.changes) || 0;
64
121
  }
65
122
 
@@ -71,11 +128,16 @@ export function syncTaskAttachmentIndex(conn: any, { atMs = Date.now() }: { atMs
71
128
  return n;
72
129
  }
73
130
 
74
- /** 全量重扫 docs 自有树 + 外部 .md(迁移与索引重建用;幂等)。 */
75
- export function syncDocAttachmentIndex(conn: any, { docsRoot, atMs = Date.now() }: {
76
- docsRoot?: string; atMs?: number;
131
+ /**
132
+ * 全量重扫 docs 自有树 + 外部 .md(**仅迁移 / 索引重建用**;幂等)。
133
+ *
134
+ * 这是 attachment 层的例外读盘:v2 迁移时正文还没进库,必须从旧文档目录取一次。
135
+ * 业务读路径不得调用它——自有文档正文的唯一真相是 `ref_bodies`。
136
+ */
137
+ export function syncDocAttachmentIndex(conn: any, { docsDir, atMs = Date.now() }: {
138
+ docsDir?: string; atMs?: number;
77
139
  } = {}): number {
78
- const root = String(docsRoot || '');
140
+ const root = String(docsDir || '');
79
141
  const files: string[] = [];
80
142
  const walk = (dir: string): void => {
81
143
  let entries: Dirent[] = [];
@@ -105,7 +167,7 @@ export function syncDocAttachmentIndex(conn: any, { docsRoot, atMs = Date.now()
105
167
  const refId = ensureDocRef(conn, { locator, atMs });
106
168
  n += syncRefAttachments(conn, { refId, text, atMs });
107
169
  }
108
- // 外部 .md(refs.locator 是绝对路径):不在 docs 树里,但同样是文档库的一行。
170
+ // 外部 .md(refs.locator 是绝对路径):不在 docs 目录里,但同样是文档库的一行。
109
171
  // 迁移必须把它们的正文引用也落库,否则「存量文档的图片」只有正文 fileId 字符串。
110
172
  for (const row of conn.all("SELECT id, locator FROM refs WHERE type = 'md'")) {
111
173
  const loc = String(row.locator || '');
@@ -1,6 +1,7 @@
1
1
  // 标识与正文解析:fileId / ref / url / task 四类资源的稳定 id 公式,
2
2
  // 以及 markdown 正文 → 资源引用清单的纯函数。本文件不碰数据库与文件系统。
3
3
  import { createHash } from 'node:crypto';
4
+ import { resolve } from 'node:path';
4
5
 
5
6
  // 不 import fileapi:它经 config → db/index → bootstrap → migrator 会绕回本模块。
6
7
  // 这里只需要「按扩展名补一个够用的 MIME」,真实 MIME 由上传/同步路径写入。
@@ -23,6 +24,7 @@ const FILE_ID_RE = /^[0-9a-fA-F]{16,}(\.[A-Za-z0-9]{1,8})?$/;
23
24
  const MD_LINK_RE = /!?\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/g;
24
25
  const NXKV_TASK_RE = /^nxkv:\/\/task\/(\d+)$/i;
25
26
  const NXKV_REF_RE = /^nxkv:\/\/ref\/([A-Za-z0-9_-]+)$/i;
27
+ const NXKV_MDFILE_RE = /^nxkv:\/\/mdfile\/([A-Za-z0-9_-]+)$/i;
26
28
 
27
29
  const sha1 = (s: unknown): string => createHash('sha1').update(String(s), 'utf8').digest('hex');
28
30
 
@@ -31,12 +33,13 @@ export type AttachmentRole = 'inline' | 'reference' | 'doc' | 'attach';
31
33
 
32
34
  /** 正文里解析出的一条引用;position / role 在入清单时补齐。 */
33
35
  export interface AttachmentRef {
34
- kind: 'file' | 'url' | 'task' | 'ref';
36
+ kind: 'file' | 'url' | 'task' | 'ref' | 'mdfile';
35
37
  id?: string;
36
38
  name: string;
37
39
  isImage?: boolean;
38
40
  targetTaskId?: number;
39
41
  targetRefId?: string;
42
+ targetMdfileId?: string;
40
43
  url?: string;
41
44
  position?: number;
42
45
  role?: AttachmentRole;
@@ -63,6 +66,26 @@ export function refAttachmentId(refId?: unknown): string {
63
66
  return 'att_ref_' + sha1(String(refId || '')).slice(0, 16);
64
67
  }
65
68
 
69
+ /**
70
+ * 规范化 mdfile 的绝对路径:解析相对路径、压掉 `.`/`..`、统一分隔符语义
71
+ * (存储时保留本机原生分隔符;身份种子按 POSIX + 小写,Windows 大小写不敏感)。
72
+ */
73
+ export function normalizeMdfilePath(input: unknown): string {
74
+ const raw = String(input ?? '').trim();
75
+ return raw ? resolve(raw) : '';
76
+ }
77
+
78
+ /**
79
+ * 本地 md 文件的稳定 id:`att_mdfile_<sha1(规范化绝对路径).slice(0,16)>`。
80
+ * 与 file/url/task/ref 共用 `att_<kind>_<hash>` 命名族;同一路径幂等。
81
+ */
82
+ export function mdfileAttachmentId(path?: unknown): string {
83
+ let seed = normalizeMdfilePath(path).replace(/\\/g, '/');
84
+ // Windows 盘符统一小写(c:/...);其余部分保留原大小写(不做 realpath)
85
+ if (/^[A-Z]:/.test(seed)) seed = seed.charAt(0).toLowerCase() + seed.slice(1);
86
+ return 'att_mdfile_' + sha1(seed).slice(0, 16);
87
+ }
88
+
66
89
  export function metaOf(row?: any): Record<string, unknown> {
67
90
  try {
68
91
  const v = JSON.parse(String((row && row.meta) || '{}'));
@@ -93,14 +116,17 @@ export function parseAttachmentRefs(text?: unknown): AttachmentRef[] {
93
116
  } else {
94
117
  const task = target.match(NXKV_TASK_RE);
95
118
  const doc = target.match(NXKV_REF_RE);
119
+ const md = target.match(NXKV_MDFILE_RE);
96
120
  if (task) ref = { kind: 'task', targetTaskId: Number(task[1]), name: name || `任务 ${task[1]}` };
97
121
  else if (doc) ref = { kind: 'ref', targetRefId: doc[1], name: name || (doc[1] ?? '') };
122
+ else if (md) ref = { kind: 'mdfile', targetMdfileId: md[1], name: name || (md[1] ?? '') };
98
123
  else if (/^https?:\/\//i.test(target)) ref = { kind: 'url', url: target, name: name || target };
99
124
  }
100
125
  if (!ref) continue;
101
126
  // 同一资源出现多次只保留第一条(关系表一资源一 role 一行,position 取首次出现)
102
127
  const key = ref.id || (ref.kind === 'task' ? `task:${ref.targetTaskId}` : '')
103
128
  || (ref.kind === 'ref' ? `ref:${ref.targetRefId}` : '')
129
+ || (ref.kind === 'mdfile' ? `mdfile:${ref.targetMdfileId}` : '')
104
130
  || (ref.kind === 'url' ? `url:${(ref.url ?? '').toLowerCase()}` : '');
105
131
  if (seen.has(key)) continue;
106
132
  seen.add(key);