nx-kv 0.66.2 → 0.67.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 (153) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/assets/nx-kv/references/A02-/346/217/220/344/272/244/344/273/273/345/212/241.md +6 -7
  3. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +1 -1
  4. package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +2 -2
  5. package/package.json +1 -1
  6. package/src/core/attachmentdb/ids.ts +14 -1
  7. package/src/core/attachmentdb/query.ts +0 -38
  8. package/src/core/attachmentdb/repo.ts +98 -0
  9. package/src/core/attachmentdb.ts +5 -1
  10. package/src/core/db/import-json/tasks.ts +10 -9
  11. package/src/core/db/import-json.ts +16 -6
  12. package/src/core/db/index.ts +1 -1
  13. package/src/core/db/migrations/index.ts +2 -0
  14. package/src/core/db/migrations/v15.sql +88 -0
  15. package/src/core/db/verify.ts +7 -3
  16. package/src/core/db/version.ts +4 -1
  17. package/src/core/topic-key.ts +5 -8
  18. package/src/core/workflow/readiness.ts +1 -1
  19. package/src/core/workflow/types.ts +1 -1
  20. package/src/modules/claim/assemble.ts +0 -5
  21. package/src/modules/claim/host.ts +2 -4
  22. package/src/modules/claim/preview.ts +0 -1
  23. package/src/modules/claim/wait.ts +9 -49
  24. package/src/modules/docs/actions/docs-detach.ts +1 -2
  25. package/src/modules/docs/attach.ts +3 -17
  26. package/src/modules/docs/render.ts +4 -13
  27. package/src/modules/localtask/actions/localtask-add.ts +1 -3
  28. package/src/modules/localtask/actions/localtask-attach.ts +4 -2
  29. package/src/modules/localtask/actions/localtask-boardtasks.ts +0 -1
  30. package/src/modules/localtask/actions/localtask-clone.ts +1 -1
  31. package/src/modules/localtask/actions/localtask-config.ts +2 -11
  32. package/src/modules/localtask/actions/localtask-detach.ts +1 -3
  33. package/src/modules/localtask/infra/events.ts +5 -5
  34. package/src/modules/localtask/infra/repo/rows.ts +0 -1
  35. package/src/modules/localtask/infra/repo/settings.ts +1 -9
  36. package/src/modules/localtask/infra/repo/topics.ts +0 -4
  37. package/src/modules/localtask/lifecycle/add.ts +2 -9
  38. package/src/modules/localtask/lifecycle/deletion.ts +7 -15
  39. package/src/modules/localtask/lifecycle/task-lifecycle.ts +2 -2
  40. package/src/modules/localtask/lifecycle/task-ops.ts +14 -56
  41. package/src/modules/localtask/lifecycle/task-templates.ts +0 -13
  42. package/src/modules/localtask/lifecycle/task-view.ts +2 -3
  43. package/src/modules/localtask/lifecycle/topics.ts +3 -8
  44. package/src/modules/localtask/ops/attach-resource.ts +46 -4
  45. package/src/modules/localtask/ops/attach-template.ts +73 -3
  46. package/src/modules/localtask/ops/attach.ts +45 -18
  47. package/src/modules/localtask/paths.ts +7 -17
  48. package/src/modules/localtask/service.ts +3 -7
  49. package/src/modules/localtask/ui/action-flags.ts +2 -2
  50. package/src/modules/localtask/ui/action-render.ts +7 -19
  51. package/src/modules/localtask/waiting.ts +1 -8
  52. package/src/modules/promptplug/compose.ts +1 -3
  53. package/src/modules/promptplug/plugins/attachment.ts +56 -6
  54. package/src/modules/promptplug/plugins/context.ts +11 -2
  55. package/src/modules/promptplug/template-store.ts +25 -3
  56. package/src/modules/templates/scope.ts +1 -1
  57. package/src/shared/prompt-blocks.ts +2 -23
  58. package/src/web/frontend/App.tsx +4 -9
  59. package/src/web/frontend/api/cli-tree.json +6 -6
  60. package/src/web/frontend/api/client.generated.ts +11 -11
  61. package/src/web/frontend/api/tasks.ts +117 -0
  62. package/src/web/frontend/components/Introduction/index.tsx +50 -3
  63. package/src/web/frontend/components/Introduction/style.css +6 -0
  64. package/src/web/frontend/components/Introduction/use-intro.ts +25 -0
  65. package/src/web/frontend/components/md/attachments/attach-area.tsx +9 -11
  66. package/src/web/frontend/components/md/attachments/attach-common.ts +12 -5
  67. package/src/web/frontend/components/md/attachments/attach-modal.tsx +54 -9
  68. package/src/web/frontend/components/md/attachments/attach-repo-pick.tsx +48 -0
  69. package/src/web/frontend/components/sidebar/index.tsx +52 -48
  70. package/src/web/frontend/components/sidebar/model.ts +16 -32
  71. package/src/web/frontend/components/sidebar/queue-nav.ts +3 -4
  72. package/src/web/frontend/components/sidebar/row-menu.tsx +1 -1
  73. package/src/web/frontend/components/sidebar/task-children.tsx +53 -32
  74. package/src/web/frontend/{page/dir → components/task-panel}/dag-editor.tsx +1 -1
  75. package/src/web/frontend/components/task-panel/task-ops.ts +299 -0
  76. package/src/web/frontend/components/task-panel/task-page.tsx +495 -0
  77. package/src/web/frontend/components/tool-acts/modules.ts +3 -0
  78. package/src/web/frontend/modules/board/board-view.ts +2 -56
  79. package/src/web/frontend/modules/md/doc-store.ts +2 -3
  80. package/src/web/frontend/page/dag/head-bar.tsx +0 -1
  81. package/src/web/frontend/page/dag/index.tsx +1 -4
  82. package/src/web/frontend/page/dag/model.ts +0 -1
  83. package/src/web/frontend/page/dir/api.ts +4 -108
  84. package/src/web/frontend/page/dir/index.tsx +161 -348
  85. package/src/web/frontend/page/dir/task-actions.ts +20 -32
  86. package/src/web/frontend/page/dir/task-board-section.tsx +3 -0
  87. package/src/web/frontend/page/dir/task-chain.ts +6 -10
  88. package/src/web/frontend/page/dir/task-dock-panel.tsx +3 -6
  89. package/src/web/frontend/page/dir/task-feedback.ts +9 -17
  90. package/src/web/frontend/page/dir/task-not-found.tsx +2 -3
  91. package/src/web/frontend/page/dir/task-utils.ts +0 -1
  92. package/src/web/frontend/page/dir/task.tsx +14 -18
  93. package/src/web/frontend/page/doc/doc-dock.tsx +1 -1
  94. package/src/web/frontend/page/group/api.ts +3 -21
  95. package/src/web/frontend/page/group/group-project-memo.ts +41 -0
  96. package/src/web/frontend/page/group/index.tsx +289 -429
  97. package/src/web/frontend/page/progress/index.tsx +7 -12
  98. package/src/web/frontend/page/settings/api.ts +1 -2
  99. package/src/web/frontend/page/settings/prompt-templates-section.tsx +12 -44
  100. package/src/web/frontend/panels.tsx +1 -1
  101. package/src/web/frontend/registry.ts +1 -2
  102. package/src/web/frontend/route-map.ts +0 -1
  103. package/src/web/frontend/routes/dir.ts +1 -4
  104. package/src/web/frontend/routes/keys.ts +5 -3
  105. package/src/web/frontend/svghub/catalog-nav.ts +8 -11
  106. package/src/web/public/assets/app-context-CngKv8Tc.js +1 -0
  107. package/src/web/public/assets/{bar-Dy_QDX2h.js → bar-C0Q_Qe4z.js} +1 -1
  108. package/src/web/public/assets/board-view-C8OQhkyi.js +1 -0
  109. package/src/web/public/assets/{button-3JlUeln_.js → button-Cs6w2CDi.js} +1 -1
  110. package/src/web/public/assets/{composer-launch-B7DH53Yf.js → composer-launch-BF3_hyn5.js} +1 -1
  111. package/src/web/public/assets/{composer-panel-Cj1J16r-.js → composer-panel-D6vBrzCs.js} +1 -1
  112. package/src/web/public/assets/{dag-DXRPHVl8.js → dag-CZF6sV2_.js} +1 -1
  113. package/src/web/public/assets/dir-6RhnWw1E.js +1 -0
  114. package/src/web/public/assets/doc-CVIVBV6n.js +6 -0
  115. package/src/web/public/assets/doc-DgYKv2wo.css +1 -0
  116. package/src/web/public/assets/group-AF62Z-_G.js +1 -0
  117. package/src/web/public/assets/group-project-memo-G-O6sPRw.js +1 -0
  118. package/src/web/public/assets/index-Bposj22Z.js +3 -0
  119. package/src/web/public/assets/{list-filter-CWxiOSg_.js → list-search-DFvFY408.js} +1 -1
  120. package/src/web/public/assets/md-history-COQu16vy.js +47 -0
  121. package/src/web/public/assets/{member-picker-BZgE3HGb.js → member-picker-CHX0nS0O.js} +1 -1
  122. package/src/web/public/assets/popup-dBtYqEM1.js +1 -0
  123. package/src/web/public/assets/progress-CDh6DY7g.js +3 -0
  124. package/src/web/public/assets/refs-t79ynSY8.js +2 -0
  125. package/src/web/public/assets/reopen-text-B2d9SZi0.js +13 -0
  126. package/src/web/public/assets/{repo-form-modal-CNLYR12c.js → repo-form-modal-dZqpHyUj.js} +1 -1
  127. package/src/web/public/assets/{repos-BGx-yAXd.js → repos-DdhOQJqF.js} +9 -9
  128. package/src/web/public/assets/{route-crumb-DX9C4jmQ.js → route-crumb-BKq2jry0.js} +1 -1
  129. package/src/web/public/assets/settings-Bk3clN2f.js +1 -0
  130. package/src/web/public/assets/task-C8nax2rT.js +13 -0
  131. package/src/web/public/assets/task-ops-D6E_TgEC.js +2 -0
  132. package/src/web/public/assets/task-utils-Dh33OFKe.js +1 -0
  133. package/src/web/public/assets/{templates-Co1Qb1aA.js → templates-Dusbff7Z.js} +3 -3
  134. package/src/web/public/assets/{tool-bar-D5wLBLRl.js → tool-bar-DPXnjdQF.js} +2 -2
  135. package/src/web/public/assets/use-rail-drag-B6J0iqFK.js +1 -0
  136. package/src/web/public/index.html +13 -13
  137. package/src/web/frontend/page/dir/landing.tsx +0 -553
  138. package/src/web/public/assets/app-context-BqCBcDsx.js +0 -1
  139. package/src/web/public/assets/board-view-Cm8189wG.js +0 -1
  140. package/src/web/public/assets/dir-_M1ciSxM.js +0 -3
  141. package/src/web/public/assets/doc-Iuxssa-b.css +0 -1
  142. package/src/web/public/assets/doc-_iteSM2X.js +0 -6
  143. package/src/web/public/assets/get-loop-modal-DlAfqJMz.js +0 -2
  144. package/src/web/public/assets/group-CH8qe-eg.js +0 -1
  145. package/src/web/public/assets/index-Cui4IuGj.js +0 -3
  146. package/src/web/public/assets/md-history-Bj790fdn.js +0 -46
  147. package/src/web/public/assets/popup-DZ2Khv2c.js +0 -1
  148. package/src/web/public/assets/progress-MPse2JLQ.js +0 -3
  149. package/src/web/public/assets/refs-DiIPoqnJ.js +0 -2
  150. package/src/web/public/assets/settings-Pt4YgGdY.js +0 -1
  151. package/src/web/public/assets/task-DOIIpQ4X.js +0 -13
  152. package/src/web/public/assets/task-utils-CJfMODCP.js +0 -13
  153. package/src/web/public/assets/use-rail-drag-CNOHXWng.js +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,75 @@
2
2
 
3
3
  本文件对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.67.0] - 2026-11-24 删除「全局任务池」(breaking)
6
+
7
+ 用户口径:「全局任务模块和功能安全删了吧,get 的时候也不需要考虑全局任务,项目也不
8
+ 需要出现全局任务的任何概念了」。
9
+
10
+ ### Breaking
11
+
12
+ - **全局任务池整条链路删除**:队列一律绑定目录,不再有跨目录共享池。
13
+ - `localtask add` / `get` 不带 `--cwd` → 落**当前工作目录**(原来进全局池);
14
+ - `localtask add --global` 参数删除(传了报未知参数);
15
+ - `wait` / `get` 领取顺序只剩「本目录队列 → 阻塞」,删除跨目录全局兜底与全局 FIFO 唤醒;
16
+ - `#/global` 深链与未知路径统一落「仓库管理」;侧栏不再有「全局任务」行;
17
+ - `topicKeyOf('')` 直接报错(不再返回 `__GLOBAL__`);
18
+ - 迁移旧数据:空 cwd 的队列行**整行跳过**(导入自检与 `db verify` 对账同步扣除)。
19
+ - 后端删除:`GLOBAL_KEY` / `GLOBAL_NAME` / `GLOBAL_CWD` / `isGlobalKey` /
20
+ `GLOBAL_TOPIC_KEY` / `TOPIC_EXT.GLOBAL` / `resolveCwd` 兜底之外的全局分支(lifecycle、
21
+ waiting、events、claim/wait、claim/host、boardtasks、action-render、action-flags);
22
+ - 前端删除:侧栏全局行与 globe 菜单、`#/global` 路由与 `registry` 视图、
23
+ `board-view` 的 `GLOBAL_KEY` / `GLOBAL_NAME` / `withGlobalRow` / `globalPlaceholderTopic`、
24
+ dir/progress/dag/group 的 `isGlobal` 分支、`routes/keys.ts` 的 `GLOBAL_KEY`;
25
+ - 文档:`A02-提交任务` 删 `--global` 投递路径、`A03` docs detach 口径、`B02-CLI速查` 同步。
26
+
27
+ ### Removed
28
+
29
+ - 库内 `__GLOBAL__` 队列及其 16 条任务(按用户决定一并删除,删除前已备份原文)。
30
+
31
+ ### Verification
32
+
33
+ - lint 0 errors、typecheck(node + web)、build、smoke 97/97、全量单测 160 文件逐个全过;
34
+ - CDP 实测侧栏无「全局任务」行、`#/global` 落仓库管理。
35
+
36
+ ## [0.66.3] - 2026-11-23 附件挂参考仓库 + 内部资源强制访问 + 移除只解除关联(#183–#189 / #251)
37
+
38
+ ### Added
39
+
40
+ - **附件支持参考仓库(kind=`repo`)**:`localtask attach --repo <key|路径|名称>`、
41
+ 面板「添加附件」新增「关联参考仓库」区块。附件是**登记指针**(不 clone / 不复制),
42
+ 行内 meta 带 `repoKey / name / desc / repoType / localPath / branch / docs[]`,
43
+ 按 repo key 去重(同一仓库重挂不建新行);未登记仓库明确报错,不退化成 folder。
44
+ - **内部资源强制访问**(task / ref / repo):附件段先声明「其中 N 个是系统内部资源——
45
+ 必须被实际访问:任务读正文、文档读全文、仓库读源码;未访问不得直接开始实现或交付」,
46
+ 再逐条给出可执行的 `access`(含 localPath 与命令);参考仓库额外强制
47
+ 「实现必须参考该仓库源码,禁止凭记忆臆测 API / 文件结构」。
48
+ - 模板变量新增 `{{mandatory}}` / `{{access}}` / `{{attach.mandatoryCount}}` /
49
+ `{{attach.hasMandatory}}` 与 `{{repo.localPath}}` / `{{repo.cmd}}` 等,设置页可检索。
50
+ - 组页记住归属项目(#187):按组记录上次选择(localStorage),下次进去直接用。
51
+
52
+ ### Changed
53
+
54
+ - **schema v15**:`attachments.kind` 新增 `repo`(`target_kind` 同步),12-step 重建 + 关系表快照回填。
55
+ - dst:`dir` / `group` 任务页合并为同一份模板组件(#251),组页补批量与行尾菜单;
56
+ 组 / 项目介绍行在无文档时不再整块消失。
57
+ - 附件弹窗「关联任务(本主题)」搜索收口到 `modules/board/task-search`,
58
+ 与 topic 页同一引擎(分词 AND / 剥 frontmatter / 通配 / 编号前缀)。
59
+ - 删除「系统提示词追加方式」选择:系统提示词**固定 XML 区块**,`plain` 直拼模式与
60
+ `--append-mode`、`APPEND_MODES` 全部下线。
61
+ - 侧栏「…还有 N 条」改为**点一次加载 10 条**(默认 8 条),不再一次铺开全部。
62
+ - 内置模板更新可传导:启用的用户副本若与当前内置实质相同(只是复制没改过)→ 跟随内置;
63
+ 组主篇正文内嵌(`{{group.intro}}`),repo / group 主篇独立加载。
64
+
65
+ ### Fixed
66
+
67
+ - 旧提示词模板引用已删除的 `group.note` 导致模板功能整体不可用(读时惰性迁移为
68
+ `group.introDesc` + 装配兜底)。
69
+ - **附件移除只解除关联**(#189):删掉 `purge` 能力(ops / action / 契约 / 前端弹窗 /
70
+ render 文案 / 死代码 `deleteAttachment`)。此前「连资源一起删」实际只对 file 删仓内字节,
71
+ 其余 kind 只删指针行,与文案承诺不一致;清理统一交给库级 GC(`file prune`:
72
+ 只删无引用行,file 只删附件根目录内字节,repo 指针按 key 幂等重建,实体表不碰)。
73
+
5
74
  ## [0.66.2] - 2026-11-23 修复旧提示词模板数据不兼容导致模板功能整体不可用
6
75
 
7
76
  ### Fixed
@@ -27,19 +27,18 @@
27
27
 
28
28
  4. **投递**(见下)——记下返回的 `task.id`,向用户报告「投到哪个目录、第几号」。
29
29
 
30
- ## 投递:三条路,按「谁该领」选
30
+ ## 投递:两条路,按「谁该领」选
31
31
 
32
32
  ```bash
33
- # ① 投到目标目录的队列(--cwd = 接收方 agent 的工作目录,不是你的)
33
+ # ① 投到目标目录的队列(--cwd = 接收方 agent 的工作目录,不是你的;缺省 = 当前目录)
34
34
  nx-kv localtask add "<任务文本>" --cwd "<目标目录>" --json
35
35
 
36
- # ② 不限定接收方 → 全局共享池(忽略 --cwd,谁闲谁领)
37
- nx-kv localtask add "<任务文本>" --global --json
38
-
39
- # ③ 挂到项目/组(任务才会出现在对应的组面板与项目上下文里)
36
+ # ② 挂到项目/组(任务才会出现在对应的组面板与项目上下文里)
40
37
  nx-kv localtask add "<任务文本>" --project <仓库key> --board <组id> --json
41
38
  ```
42
39
 
40
+ > #190 起「全局共享池」已删除:队列一律绑定目录,`get/wait` 只在本目录队列里等。
41
+
43
42
  返回 `{ status:"ok", task:{id,…}, queued|delivered }`:`queued:true` = 已入队(目标目录正在
44
43
  wait/get 的 agent 约 0.5 秒内取走,没人等就排队);`delivered` = 已经被领走。
45
44
 
@@ -189,7 +188,7 @@ done / 被取代。已领取/已完成的任务不会再被派发,不走 reope
189
188
  | 只写「做什么」不写「怎么验证」 | ②里带上关键路径与验证入口(跑哪条命令 / 看哪张表) |
190
189
  | 长文本用引号硬拼 | `--file <文件>` 或 `--file -`(标准输入);换行逐字保留 |
191
190
  | 大需求塞成一条 | 拆成多条可独立完成的单元;顺序重要时 `reorder` 校正 |
192
- | 有依赖的步骤走 `--global` | 全局池不保顺序,必须 `--cwd` 投到同一目录队列 |
191
+ | 有依赖的步骤投到不同目录 | 依赖是队列内语义,必须 `--cwd` 投到同一目录队列 |
193
192
  | 提交完自己去 `get` | 那是接收方的事;要跟进等它 `reopen` 回来 |
194
193
  | 已领取的任务想改时间目标 | `update` 改不了(已起表);走 `reopen` 派生下一轮 |
195
194
  | 想法直接 add 进队列 | add 完立刻 `plan --to plan`,别让人领到半成品 |
@@ -177,7 +177,7 @@ nx-kv docs attach --ref ref:<refId> --path <本机文件> --json # 图片/文
177
177
  nx-kv docs attach --ref ref:<refId> --folder <本机目录> --json # 文件夹(只登记路径指针)
178
178
  nx-kv docs attach --ref ref:<refId> --mdfile <本机 md> --json # 本地 md 指针
179
179
  nx-kv docs attachments --ref ref:<refId> --json # 这篇挂了哪些资源
180
- nx-kv docs detach --ref ref:<refId> --attachment <id> --json # 摘掉一个(--purge 连资源一起删)
180
+ nx-kv docs detach --ref ref:<refId> --attachment <id> --json # 摘掉一个(只解除关联,资源留在孤儿池)
181
181
  ```
182
182
 
183
183
  ## 偏差与陷阱
@@ -12,7 +12,7 @@
12
12
  | 命令 | 关键参数 | 说明 |
13
13
  | --- | --- | --- |
14
14
  | `localtask get` | `--cwd` `--timeout N` `--no-open` `--param k=v` | **领活**。有活立即领;`--timeout` 显式给定时阻塞到上限(等不到返回 `timeout`) |
15
- | `localtask add` | `--cwd` `--global` `--summary` `--project` `--board` `--duration 2h` `--goal-prompt` `--block-by 12,13` `--gate` `--fork-of` `--fork-kind` `--file <文件|->` | 提交任务。`--project` 决定归属项目并推导落点目录;`--board` 给组(任务才出现在组面板);`--global` 进共享池(忽略 `--cwd`);**`--file` 从文件/标准输入读正文**(多行长文本不必靠引号硬拼,`-` = stdin) |
15
+ | `localtask add` | `--cwd` `--summary` `--project` `--board` `--duration 2h` `--goal-prompt` `--block-by 12,13` `--gate` `--fork-of` `--fork-kind` `--file <文件|->` | 提交任务。`--project` 决定归属项目并推导落点目录;`--board` 给组(任务才出现在组面板);`--cwd` 缺省 = 当前目录(#190 起无全局池);**`--file` 从文件/标准输入读正文**(多行长文本不必靠引号硬拼,`-` = stdin) |
16
16
  | `localtask show` | `--id N` | 看单条(只读,**不领取**) |
17
17
  | `localtask list` | — | 全部主题概览(目录、现状、等待中、待领取数) |
18
18
  | `localtask done` | `--id N` `--summary "…"` | 标完成;summary 记为本轮终态 + timegoal 日志 |
@@ -139,7 +139,7 @@ nx-kv health # 服务与版本(纯本机)
139
139
  1. `get` 是领取、`show` 是查看——两个不同子命令,别拿 `show` 当领取。
140
140
  2. `wait` 不要再用:`get --timeout N` 等价,且只有一条路可维护。
141
141
  3. `update --text` 在任务被领取后无效(先 `reopen`)。
142
- 4. `add --cwd` 是**接收方**目录;`--global` 会忽略它。
142
+ 4. `add --cwd` 是**接收方**目录,缺省 = 当前目录(#190 起没有全局共享池)。
143
143
  5. 追加附件会改写正文,连续操作一律用 `--id` 定位。
144
144
  6. `docs` 的 ref 没有路径;读文件只有附件。
145
145
  7. `repo bind` 不收 `--note`,写说明要用 `repo ref note`(落成该参考仓库的一篇文档)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.66.2",
3
+ "version": "0.67.0",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -26,6 +26,7 @@ const NXKV_TASK_RE = /^nxkv:\/\/task\/(\d+)$/i;
26
26
  const NXKV_REF_RE = /^nxkv:\/\/ref\/([A-Za-z0-9_-]+)$/i;
27
27
  const NXKV_MDFILE_RE = /^nxkv:\/\/mdfile\/([A-Za-z0-9_-]+)$/i;
28
28
  const NXKV_FOLDER_RE = /^nxkv:\/\/folder\/([A-Za-z0-9_-]+)$/i;
29
+ const NXKV_REPO_RE = /^nxkv:\/\/repo\/([A-Za-z0-9_-]+)$/i;
29
30
 
30
31
  const sha1 = (s: unknown): string => createHash('sha1').update(String(s), 'utf8').digest('hex');
31
32
 
@@ -34,7 +35,7 @@ export type AttachmentRole = 'inline' | 'reference' | 'doc' | 'attach';
34
35
 
35
36
  /** 正文里解析出的一条引用;position / role 在入清单时补齐。 */
36
37
  export interface AttachmentRef {
37
- kind: 'file' | 'url' | 'task' | 'ref' | 'mdfile' | 'folder';
38
+ kind: 'file' | 'url' | 'task' | 'ref' | 'mdfile' | 'folder' | 'repo';
38
39
  id?: string;
39
40
  name: string;
40
41
  isImage?: boolean;
@@ -42,6 +43,7 @@ export interface AttachmentRef {
42
43
  targetRefId?: string;
43
44
  targetMdfileId?: string;
44
45
  targetFolderId?: string;
46
+ targetRepoId?: string;
45
47
  url?: string;
46
48
  position?: number;
47
49
  role?: AttachmentRole;
@@ -64,6 +66,14 @@ export function taskAttachmentId(topicKey?: unknown, seq?: unknown): string {
64
66
  return 'att_task_' + sha1(`${String(topicKey || '')}:${Number(seq) || 0}`).slice(0, 16);
65
67
  }
66
68
 
69
+ /**
70
+ * 参考仓库附件的稳定 id:按**仓库 key** 去重(同一仓库重挂不建新行)。
71
+ * 与 folder 的区别是语义:repo 必带 key / type / docs,不能退化成普通目录。
72
+ */
73
+ export function repoAttachmentId(key?: unknown): string {
74
+ return 'att_repo_' + sha1(String(key || '').trim()).slice(0, 16);
75
+ }
76
+
67
77
  export function refAttachmentId(refId?: unknown): string {
68
78
  return 'att_ref_' + sha1(String(refId || '')).slice(0, 16);
69
79
  }
@@ -120,10 +130,12 @@ export function parseAttachmentRefs(text?: unknown): AttachmentRef[] {
120
130
  const doc = target.match(NXKV_REF_RE);
121
131
  const md = target.match(NXKV_MDFILE_RE);
122
132
  const dir = target.match(NXKV_FOLDER_RE);
133
+ const repoRef = target.match(NXKV_REPO_RE);
123
134
  if (task) ref = { kind: 'task', targetTaskId: Number(task[1]), name: name || `任务 ${task[1]}` };
124
135
  else if (doc) ref = { kind: 'ref', targetRefId: doc[1], name: name || (doc[1] ?? '') };
125
136
  else if (md) ref = { kind: 'mdfile', targetMdfileId: md[1], name: name || (md[1] ?? '') };
126
137
  else if (dir) ref = { kind: 'folder', targetFolderId: dir[1], name: name || (dir[1] ?? '') };
138
+ else if (repoRef) ref = { kind: 'repo', targetRepoId: repoRef[1], name: name || (repoRef[1] ?? '') };
127
139
  else if (/^https?:\/\//i.test(target)) ref = { kind: 'url', url: target, name: name || target };
128
140
  }
129
141
  if (!ref) continue;
@@ -132,6 +144,7 @@ export function parseAttachmentRefs(text?: unknown): AttachmentRef[] {
132
144
  || (ref.kind === 'ref' ? `ref:${ref.targetRefId}` : '')
133
145
  || (ref.kind === 'mdfile' ? `mdfile:${ref.targetMdfileId}` : '')
134
146
  || (ref.kind === 'folder' ? `folder:${ref.targetFolderId}` : '')
147
+ || (ref.kind === 'repo' ? `repo:${ref.targetRepoId}` : '')
135
148
  || (ref.kind === 'url' ? `url:${(ref.url ?? '').toLowerCase()}` : '');
136
149
  if (seen.has(key)) continue;
137
150
  seen.add(key);
@@ -138,44 +138,6 @@ function within(root: string | null | undefined, p: string | null | undefined):
138
138
  return b === a || b.startsWith(a.replace(/\/+$/, '') + '/');
139
139
  }
140
140
 
141
- export interface DeleteAttachmentResult {
142
- removed: boolean;
143
- reason?: string;
144
- bytesRemoved?: boolean;
145
- attachment?: AttachmentView | null;
146
- }
147
-
148
- /**
149
- * 删除资源行(可选连字节一起删)。仍被任何任务/文档引用时拒绝——关系表是权威,
150
- * 「解除关系」和「删资源」是两步,不能因为一次 detach --purge 误删别人在用的文件。
151
- * @returns {{removed:boolean, reason?:string, attachment?:object}}
152
- */
153
- export function deleteAttachment(conn: any, id: string | number, {
154
- attachmentsRoot, purgeBytes = true,
155
- }: { attachmentsRoot?: string; purgeBytes?: boolean } = {}): DeleteAttachmentResult {
156
- const row = getAttachment(conn, id);
157
- if (!row) return { removed: false, reason: 'not-found' };
158
- const still = conn.get(
159
- `SELECT 1 AS x FROM task_attach WHERE attachment_id = :id
160
- UNION ALL SELECT 1 FROM ref_attach WHERE attachment_id = :id LIMIT 1`,
161
- { id: row.id }
162
- );
163
- if (still) return { removed: false, reason: 'in-use', attachment: row };
164
- let bytesRemoved = false;
165
- if (purgeBytes && row.kind === 'file' && row.localPath && within(attachmentsRoot, row.localPath)) {
166
- try {
167
- if (existsSync(row.localPath)) {
168
- unlinkSync(row.localPath);
169
- bytesRemoved = true;
170
- }
171
- } catch {
172
- return { removed: false, reason: 'file-locked', attachment: row };
173
- }
174
- }
175
- conn.run('DELETE FROM attachments WHERE id = :id', { id: row.id });
176
- return { removed: true, bytesRemoved, attachment: row };
177
- }
178
-
179
141
  export function pruneOrphans(conn: any, { attachmentsRoot, dryRun = false }: {
180
142
  attachmentsRoot?: string; dryRun?: boolean;
181
143
  } = {}): { removed: AttachmentView[]; skipped: AttachmentView[] } {
@@ -0,0 +1,98 @@
1
+ // 参考仓库附件的登记(#184):附件是**指针**,字节留在原 checkout 里(不 clone / 不复制)。
2
+ //
3
+ // 与 folder 的区别是语义:repo 必须已在本机登记(repo get 能取到 key / type / 文档),
4
+ // 因此这里只认 key,并要求调用方先把仓库元数据查好一起写进 meta —— 交付时模板直接
5
+ // 从 meta 读,不必每次回查仓库表(但 localPath 的 exists 仍按盘上现况判定)。
6
+ import { existsSync } from 'node:fs';
7
+ import { badInput, conflict } from '../errors.js';
8
+ import { repoAttachmentId } from './ids.js';
9
+
10
+ export interface RegisterRepoAttachInput {
11
+ /** 仓库 key(github.com/org/name 或本机登记用的 key) */
12
+ key?: unknown;
13
+ name?: unknown;
14
+ desc?: unknown;
15
+ /** ref / dev */
16
+ repoType?: unknown;
17
+ /** checkout 的本地绝对路径 */
18
+ localPath?: unknown;
19
+ branch?: unknown;
20
+ /** 仓库已绑定的文档 refId 列表 */
21
+ docs?: unknown;
22
+ atMs?: number;
23
+ }
24
+
25
+ /**
26
+ * 登记(或复用)一条仓库附件。按 key 幂等:同一仓库重挂复用同一行,只刷新元数据。
27
+ */
28
+ export function registerRepoAttachment(conn: any, {
29
+ key, name = '', desc = '', repoType = '', localPath = '', branch = '', docs = [], atMs = Date.now(),
30
+ }: RegisterRepoAttachInput = {}): { id: string; name: string; localPath: string } {
31
+ const repoKey = String(key || '').trim();
32
+ if (!repoKey) throw badInput('repo 附件需要仓库 key(先用 nx-kv repo add 登记)');
33
+ const absPath = String(localPath || '');
34
+ const displayName = String(name || '').trim() || repoKey;
35
+ const id = repoAttachmentId(repoKey);
36
+ const cur = conn.get('SELECT id, kind FROM attachments WHERE id = :id', { id });
37
+ if (cur && cur.kind !== 'repo') {
38
+ throw conflict(`附件 id 冲突:${id} 已被 kind=${cur.kind} 占用,无法登记为 repo`);
39
+ }
40
+ const meta = JSON.stringify({
41
+ repoKey,
42
+ name: displayName,
43
+ desc: String(desc || ''),
44
+ repoType: String(repoType || ''),
45
+ localPath: absPath,
46
+ branch: String(branch || ''),
47
+ docs: Array.isArray(docs) ? docs.map((x) => String(x || '')).filter(Boolean) : [],
48
+ });
49
+ const upsert = (targetId: string): void => conn.run(
50
+ `INSERT INTO attachments
51
+ (id, kind, name, local_path, url, mime, size, hash, storage, group_id,
52
+ target_kind, target_key, target_seq, dedupe_key, meta,
53
+ abs_path, anchor_dir, missing_at, last_seen_at, deleted_at, created_at, updated_at)
54
+ VALUES (:id, 'repo', :name, :absPath, '', '', 0, '', 'external', 0,
55
+ 'repo', :key, NULL, :dedupe, :meta,
56
+ :absPath, :absPath, NULL, :at, NULL, :at, :at)
57
+ ON CONFLICT(id) DO UPDATE SET
58
+ name = excluded.name,
59
+ local_path = excluded.local_path,
60
+ abs_path = excluded.abs_path,
61
+ anchor_dir = excluded.anchor_dir,
62
+ target_key = excluded.target_key,
63
+ dedupe_key = excluded.dedupe_key,
64
+ meta = excluded.meta,
65
+ missing_at = NULL,
66
+ last_seen_at = excluded.last_seen_at,
67
+ deleted_at = NULL,
68
+ updated_at = excluded.updated_at`,
69
+ { id: targetId, name: displayName, key: repoKey, dedupe: `repo:${repoKey}`, meta, absPath, at: atMs },
70
+ );
71
+ upsert(id);
72
+ return { id, name: displayName, localPath: absPath };
73
+ }
74
+
75
+ /** 正文里出现 nxkv://repo/<id> 时:行必须已存在,否则不认这条引用。 */
76
+ export function ensureRepoAttachment(conn: any, { id, name = '', atMs = Date.now() }: {
77
+ id?: string | null; name?: string; atMs?: number;
78
+ } = {}): string | null {
79
+ const attId = String(id || '').trim();
80
+ if (!attId) return null;
81
+ const row = conn.get(
82
+ "SELECT id, name FROM attachments WHERE id = :id AND kind = 'repo' AND deleted_at IS NULL",
83
+ { id: attId },
84
+ );
85
+ if (!row) return null;
86
+ if (name && !row.name) {
87
+ conn.run('UPDATE attachments SET name = :name, updated_at = :at WHERE id = :id', {
88
+ id: attId, name: String(name), at: atMs,
89
+ });
90
+ }
91
+ return attId;
92
+ }
93
+
94
+ /** 盘上是否还有这个 checkout(交付时现判,不用登记时的快照)。 */
95
+ export function repoLocalExists(localPath: unknown): boolean {
96
+ const p = String(localPath || '');
97
+ return !!p && existsSync(p);
98
+ }
@@ -45,6 +45,11 @@ export {
45
45
  normalizeFolderPath,
46
46
  registerFolder,
47
47
  } from './attachmentdb/folder.js';
48
+ export {
49
+ ensureRepoAttachment,
50
+ registerRepoAttachment,
51
+ repoLocalExists,
52
+ } from './attachmentdb/repo.js';
48
53
  export {
49
54
  linkAttachment,
50
55
  syncRefAttachments,
@@ -75,7 +80,6 @@ export {
75
80
  } from './attachmentdb/docs.js';
76
81
  export {
77
82
  archiveAttachmentManifests,
78
- deleteAttachment,
79
83
  getAttachment,
80
84
  listOrphans,
81
85
  listRefAttachments,
@@ -1,5 +1,5 @@
1
1
  // topics / tasks 阶段:legacy localtasks.json → topics + topic_presence + tasks(含内嵌 timegoal → goals)。
2
- import { topicKeyOf, GLOBAL_TOPIC_KEY } from '../../topic-key.js';
2
+ import { topicKeyOf } from '../../topic-key.js';
3
3
  import { anyTimeMs } from '../time.js';
4
4
  import {
5
5
  jsonText,
@@ -80,14 +80,16 @@ export function importTopicsAndTasks(
80
80
  note: 'schema 一条队列一个 cwd',
81
81
  });
82
82
  }
83
- const hasTasks = Array.isArray(topic.tasks) && topic.tasks.length > 0;
84
- if (!cwd && legacyKey !== GLOBAL_TOPIC_KEY && hasTasks) {
85
- // 异常行(v1/v2 迁移来的、没 cwd 的旧等待点):挂哨兵 + cwd='' + 报告
86
- report.warnings.push({
87
- what: 'topic',
88
- why: 'cwd 为空且不是全局池(旧 slot/session 迁移残留),cwd 落空串',
89
- legacyKey,
83
+ // #190:空 cwd 的队列行(历史上的全局池)**整行跳过**(不迁移)——
84
+ // 队列必须绑定真实目录;跳过并在报告里留痕,条目数与丢弃明细都能核对。
85
+ if (!cwd) {
86
+ report.discarded.push({
87
+ what: 'topic(空 cwd / 全局池)',
88
+ key: legacyKey,
89
+ count: Array.isArray(topic.tasks) ? topic.tasks.length : 0,
90
+ note: '#190 起队列必须绑定目录,空 cwd 行不迁移',
90
91
  });
92
+ continue;
91
93
  }
92
94
  const key = topicKeyOf(cwd, '');
93
95
  let row = byNewKey.get(key);
@@ -99,7 +101,6 @@ export function importTopicsAndTasks(
99
101
  const ext: Record<string, any> = { ext_legacy_key: legacyKey };
100
102
  if (topic.summary) ext.ext_last_summary = String(topic.summary);
101
103
  if (topic.manual) ext.ext_manual = 1;
102
- if (legacyKey === GLOBAL_TOPIC_KEY) ext.ext_global = 1;
103
104
 
104
105
  const createdAt = anyTimeMs(topic.createdAt, atMs);
105
106
  const res = db.run(
@@ -31,7 +31,7 @@
31
31
  // ── 迁移口径(与 docs/research/SQLITE-REFACTOR.md §6 对齐,差异见行内注释)──
32
32
  //
33
33
  // · 哨兵仓库 `__unbound__`:legacy 队列全都对不上真实仓库(key 是目录名 sha1),
34
- // 全局池 `__GLOBAL__` 也挂它下面;`cwd = ''`。不伪造 repo key、不放松 NOT NULL。
34
+ // 空 cwd 的历史行(#190 前的全局池)不迁移。不伪造 repo key、不放松 NOT NULL。
35
35
  // · `boards` → `repos(type='group')`,key = `group/<slug(初始 name)>`(冻结,
36
36
  // name 之后可改),旧 `b_xxx` 存 `ext.ext_legacy_id`。
37
37
  // · `consumedAt → claimed_at`(75/75 有值,它就是领取时刻)。
@@ -103,11 +103,16 @@ export interface ImportLegacyOptions {
103
103
  * 正文哈希不在这一步:body 就是本条代码从 text 直接写进去的,比了也是自证。
104
104
  * 它留给 `db verify`(那时是与磁盘上的 JSON 对账,才是真校验)。
105
105
  */
106
- function validateImport(conn: DbApi, { expectedTasks }: { expectedTasks: number }): void {
106
+ function validateImport(
107
+ conn: DbApi,
108
+ { expectedTasks, skippedTasks = 0 }: { expectedTasks: number; skippedTasks?: number },
109
+ ): void {
107
110
  const problems: string[] = [];
108
111
  const taskCount = Number((conn.get('SELECT count(*) AS c FROM tasks') || {}).c || 0);
109
- if (taskCount !== expectedTasks) {
110
- problems.push(`任务行数 ${taskCount} ≠ legacy ${expectedTasks}`);
112
+ // #190:空 cwd / 全局池的队列整行跳过,它们名下的任务不计入期望值
113
+ const want = expectedTasks - skippedTasks;
114
+ if (taskCount !== want) {
115
+ problems.push(`任务行数 ${taskCount} ≠ legacy ${want}(legacy ${expectedTasks} - 跳过全局池 ${skippedTasks})`);
111
116
  }
112
117
 
113
118
  const topics = conn.all('SELECT id, key, cwd, group_key, next_seq FROM topics');
@@ -179,8 +184,13 @@ export function importLegacy(db: DbApi, { appDir, docsDir, atMs = nowMs() }: Imp
179
184
 
180
185
  // 期望的任务总数:**从 legacy 里数**,不是从写进去的行数里数 —— 后者永远相等。
181
186
  let expectedTasks = 0;
187
+ let skippedTasks = 0;
182
188
  for (const t of Object.values(((localtasksData && localtasksData.topics) || {}) as Record<string, any>)) {
183
- expectedTasks += Array.isArray(t && t.tasks) ? t.tasks.length : 0;
189
+ const n = Array.isArray(t && t.tasks) ? t.tasks.length : 0;
190
+ expectedTasks += n;
191
+ // #190:全局池 / 空 cwd 的队列不迁移,其任务数从期望值里扣掉
192
+ const cwd = String((t && (t.cwd || (Array.isArray(t.cwds) && t.cwds[0]))) || '').trim();
193
+ if (!cwd) skippedTasks += n;
184
194
  }
185
195
 
186
196
  // 顺序即外键依赖:repos(含哨兵)→ members → topics → tasks → links/deps → goals
@@ -199,7 +209,7 @@ export function importLegacy(db: DbApi, { appDir, docsDir, atMs = nowMs() }: Imp
199
209
  report
200
210
  );
201
211
 
202
- validateImport(db, { expectedTasks });
212
+ validateImport(db, { expectedTasks, skippedTasks });
203
213
 
204
214
  setMeta(db, 'migrated_from_json_at', String(atMs), atMs);
205
215
  return report;
@@ -143,5 +143,5 @@ export { openRaw, bindValue } from './driver.js';
143
143
  export { CURRENT_SCHEMA_VERSION, REQUIRED_NODE_VERSION, checkNodeVersion } from './version.js';
144
144
  export { StoreMigrationError, StoreTooNewError, NotNxKvStoreError } from './errors.js';
145
145
  export { verifyStore, tableCounts, statusDistribution, findLegacyLocalTasks } from './verify.js';
146
- export { topicKeyOf, GLOBAL_TOPIC_KEY } from '../topic-key.js';
146
+ export { topicKeyOf } from '../topic-key.js';
147
147
  export { nowMs, parseStampMs, parseIsoMs, msToStamp, stampFileTag } from './time.js';
@@ -65,6 +65,7 @@ export const DIRECT_EDGES: MigrationStep[] = [
65
65
  { from: 11, to: 12, file: 'v12.sql', title: '去掉分类标签概念(删 ref_bindings.tag)' },
66
66
  { from: 12, to: 13, file: 'v13.sql', title: '去掉关系表上的业务 note(4 张表 drop note 列)' },
67
67
  { from: 13, to: 14, file: 'v14.sql', title: 'task_links.type 扩 fork(任务链四类节点:评论/反馈/重开/分支)' },
68
+ { from: 14, to: 15, file: 'v15.sql', title: "附件新增 repo 类型(参考仓库指针,不复制字节;重建 attachments 扩 CHECK)" },
68
69
  ];
69
70
 
70
71
  // 人读版本说明(docs/decisions 是决策的唯一权威位置,里面对应一份 date 化的 .md)
@@ -83,6 +84,7 @@ export const VERSION_NOTES = {
83
84
  12: 'docs/decisions/versions/2026-11-16-v12.md',
84
85
  13: 'docs/decisions/versions/2026-11-17-v13.md',
85
86
  14: 'docs/decisions/versions/2026-11-22-v14.md',
87
+ 15: 'docs/decisions/versions/2026-11-23-v15.md',
86
88
  };
87
89
 
88
90
  const keyOf = (from: number, to: number): string => `${from}->${to}`;
@@ -0,0 +1,88 @@
1
+ -- schema v15:附件新增 kind='repo'(参考仓库指针,#184)
2
+ --
3
+ -- 口径:参考仓库附件是**登记指针**——字节留在原 checkout(不 clone、不复制、不打包),
4
+ -- 行里带 repo key / type / 文档 refId 列表(meta),交付时模板据此强制「实现必须参考
5
+ -- 该仓库源码」,并给出 localPath 与 `repo get` / `repo doc list` 命令。
6
+ -- 与 folder 的区别是语义:folder 是任意目录;repo 必须已登记(带 key / type / docs)。
7
+ --
8
+ -- SQLite 不能 ALTER 既有 CHECK → 按 v10 的 12-step 模式重建 attachments。
9
+ -- DROP TABLE 会级联删 task_attach / ref_attach 的行,所以先 TEMP 快照、
10
+ -- DROP 前清空、重建后按显式列名回填。
11
+ --
12
+ -- @decision docs/decisions/versions/2026-11-23-v15.md
13
+ PRAGMA defer_foreign_keys = ON;
14
+
15
+ -- v13 已删关系表的业务 note 列,这里只快照现存列
16
+ CREATE TEMP TABLE _v15_task_attach AS
17
+ SELECT task_id, attachment_id, role, position, created_at FROM task_attach;
18
+ CREATE TEMP TABLE _v15_ref_attach AS
19
+ SELECT ref_id, attachment_id, role, position, created_at FROM ref_attach;
20
+
21
+ -- @decision docs/decisions/versions/2026-11-23-v15.md
22
+ CREATE TABLE attachments_new (
23
+ id TEXT PRIMARY KEY,
24
+ kind TEXT NOT NULL CHECK (kind IN ('file', 'url', 'task', 'ref', 'mdfile', 'folder', 'repo')),
25
+ name TEXT NOT NULL DEFAULT '',
26
+ local_path TEXT NOT NULL DEFAULT '',
27
+ url TEXT NOT NULL DEFAULT '',
28
+ mime TEXT NOT NULL DEFAULT '',
29
+ size INTEGER NOT NULL DEFAULT 0 CHECK (size >= 0),
30
+ hash TEXT NOT NULL DEFAULT '',
31
+ storage TEXT NOT NULL DEFAULT '' CHECK (storage IN ('', 'local', 'cloud', 'external')),
32
+ group_id INTEGER NOT NULL DEFAULT 0,
33
+ target_kind TEXT NOT NULL DEFAULT '' CHECK (target_kind IN ('', 'task', 'ref', 'repo')),
34
+ target_key TEXT NOT NULL DEFAULT '',
35
+ target_seq INTEGER,
36
+ dedupe_key TEXT NOT NULL DEFAULT '',
37
+ meta TEXT NOT NULL DEFAULT '{}'
38
+ CHECK (json_valid(meta) AND json_type(meta) = 'object'),
39
+ abs_path TEXT NOT NULL DEFAULT '',
40
+ anchor_dir TEXT NOT NULL DEFAULT '',
41
+ missing_at INTEGER,
42
+ last_seen_at INTEGER,
43
+ deleted_at INTEGER,
44
+ created_at INTEGER NOT NULL,
45
+ updated_at INTEGER NOT NULL
46
+ );
47
+
48
+ INSERT INTO attachments_new (
49
+ id, kind, name, local_path, url, mime, size, hash, storage, group_id,
50
+ target_kind, target_key, target_seq, dedupe_key, meta,
51
+ abs_path, anchor_dir, missing_at, last_seen_at, deleted_at, created_at, updated_at
52
+ )
53
+ SELECT
54
+ id, kind, name, local_path, url, mime, size, hash, storage, group_id,
55
+ target_kind, target_key, target_seq, dedupe_key, meta,
56
+ abs_path, anchor_dir, missing_at, last_seen_at, deleted_at, created_at, updated_at
57
+ FROM attachments;
58
+
59
+ -- @decision docs/decisions/versions/2026-11-23-v15.md
60
+ DROP TABLE attachments;
61
+
62
+ ALTER TABLE attachments_new RENAME TO attachments;
63
+
64
+ CREATE UNIQUE INDEX IF NOT EXISTS ux_attachments_dedupe
65
+ ON attachments (dedupe_key) WHERE dedupe_key <> '' AND deleted_at IS NULL;
66
+ CREATE INDEX IF NOT EXISTS ix_attachments_kind ON attachments (kind, deleted_at);
67
+ CREATE INDEX IF NOT EXISTS ix_attachments_target ON attachments (target_kind, target_key, target_seq);
68
+ CREATE INDEX IF NOT EXISTS ix_attachments_group ON attachments (storage, group_id, deleted_at);
69
+ CREATE UNIQUE INDEX IF NOT EXISTS ux_attachments_mdfile_path
70
+ ON attachments (abs_path COLLATE NOCASE)
71
+ WHERE kind = 'mdfile' AND deleted_at IS NULL;
72
+ -- 同一文件夹路径(大小写不敏感)只登记一行
73
+ CREATE UNIQUE INDEX IF NOT EXISTS ux_attachments_folder_path
74
+ ON attachments (abs_path COLLATE NOCASE)
75
+ WHERE kind = 'folder' AND deleted_at IS NULL;
76
+
77
+ -- DROP TABLE 是否级联取决于连接上的 foreign_keys:先清空再回填,两种情形都不重不漏
78
+ DELETE FROM task_attach;
79
+ DELETE FROM ref_attach;
80
+ INSERT OR REPLACE INTO task_attach (task_id, attachment_id, role, position, created_at)
81
+ SELECT task_id, attachment_id, role, position, created_at FROM _v15_task_attach;
82
+ INSERT OR REPLACE INTO ref_attach (ref_id, attachment_id, role, position, created_at)
83
+ SELECT ref_id, attachment_id, role, position, created_at FROM _v15_ref_attach;
84
+
85
+ -- @decision docs/decisions/versions/2026-11-23-v15.md
86
+ DROP TABLE _v15_task_attach;
87
+ -- @decision docs/decisions/versions/2026-11-23-v15.md
88
+ DROP TABLE _v15_ref_attach;
@@ -261,12 +261,16 @@ export function verifyStore(db: DbApi, { appDir }: { appDir?: string } = {}): Ve
261
261
  const problems: Array<Record<string, any>> = [];
262
262
  let compared = 0;
263
263
  let legacyTasks = 0;
264
+ let skippedGlobal = 0;
264
265
  for (const [legacyKey, lt] of Object.entries(legacyTopics)) {
265
266
  const topic = topicByLegacyKey.get(legacyKey);
266
267
  const tasks = Array.isArray(lt && lt.tasks) ? lt.tasks : [];
267
268
  legacyTasks += tasks.length;
268
269
  if (!topic) {
269
- problems.push({ legacyKey, why: '队列未迁移' });
270
+ // #190:全局池 / 空 cwd 的队列**按设计不迁移**——不算问题,只从对账基数里扣掉
271
+ const cwd = String((lt && (lt.cwd || (Array.isArray(lt.cwds) && lt.cwds[0]))) || '').trim();
272
+ if (!cwd) skippedGlobal += tasks.length;
273
+ else problems.push({ legacyKey, why: '队列未迁移' });
270
274
  continue;
271
275
  }
272
276
  for (const task of tasks) {
@@ -298,8 +302,8 @@ export function verifyStore(db: DbApi, { appDir }: { appDir?: string } = {}): Ve
298
302
  // 不会跟 —— 要求相等会让任何真实使用过的库永远红一条(T07 裁决)。
299
303
  add(
300
304
  'legacy 任务数 ≤ 迁移后任务数(库是活数据,允许新增)',
301
- legacyTasks <= statusTotal,
302
- `${legacyTasks} vs ${statusTotal}`
305
+ legacyTasks - skippedGlobal <= statusTotal,
306
+ `${legacyTasks}${skippedGlobal ? ` - 跳过全局池 ${skippedGlobal}` : ''} vs ${statusTotal}`
303
307
  );
304
308
  } else {
305
309
  add('每条 task 的 body 哈希 = 原 text', true, hashDetail);
@@ -40,7 +40,10 @@
40
40
  // 关系描述文档的定位不走 tag:desc 就在 ref 上。
41
41
  // v13(2026-11-17):彻底删除「关系表上的业务 note」概念——4 张关系表 drop note 列。
42
42
  // 关系表本身就表达多对多;文档描述走 ref.desc + 正文标题,参考仓库描述走绑定 ref 的文档。
43
- export const CURRENT_SCHEMA_VERSION = 14;
43
+ // v14(2026-11-22):task_links.type 扩 `fork`(任务链四类节点可区分)。
44
+ // v15(2026-11-23):attachments.kind 新增 `repo`(参考仓库指针:#184 附件挂仓库,
45
+ // 字节留在原 checkout,交付时强制参考源码);同样 12-step 重建扩 CHECK。
46
+ export const CURRENT_SCHEMA_VERSION = 15;
44
47
 
45
48
  /**
46
49
  * 运行时最低 Node 版本。