nx-kv 0.41.0 → 0.41.1

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 (204) hide show
  1. package/CHANGELOG.md +29 -6
  2. package/README.md +1 -0
  3. package/package.json +2 -2
  4. package/src/core/attachmentdb/docs.js +104 -0
  5. package/src/core/attachmentdb/ids.js +96 -0
  6. package/src/core/attachmentdb/query.js +189 -0
  7. package/src/core/attachmentdb/relations.js +153 -0
  8. package/src/core/attachmentdb/resources.js +225 -0
  9. package/src/core/attachmentdb.js +42 -715
  10. package/src/core/db/import-json/data.js +140 -0
  11. package/src/core/db/import-json/extras.js +69 -0
  12. package/src/core/db/import-json/links.js +147 -0
  13. package/src/core/db/import-json/refs.js +183 -0
  14. package/src/core/db/import-json/repos.js +180 -0
  15. package/src/core/db/import-json/scan.js +35 -0
  16. package/src/core/db/import-json/tasks.js +317 -0
  17. package/src/core/db/import-json.js +31 -1061
  18. package/src/modules/docs/attach.js +181 -0
  19. package/src/modules/docs/index.js +20 -448
  20. package/src/modules/docs/knowledge.js +7 -2
  21. package/src/modules/docs/render.js +84 -0
  22. package/src/modules/docs/service.js +200 -0
  23. package/src/modules/localtask/action-attach.js +88 -0
  24. package/src/modules/localtask/action-flags.js +6 -0
  25. package/src/modules/localtask/action-lifecycle.js +190 -0
  26. package/src/modules/localtask/action-maintenance.js +130 -0
  27. package/src/modules/localtask/action-move.js +58 -0
  28. package/src/modules/localtask/action-query.js +46 -0
  29. package/src/modules/localtask/action-remove.js +116 -0
  30. package/src/modules/localtask/action-render.js +200 -0
  31. package/src/modules/localtask/action-submit.js +186 -0
  32. package/src/modules/localtask/action-topics.js +46 -0
  33. package/src/modules/localtask/action-waiting.js +95 -0
  34. package/src/modules/localtask/index.js +29 -1104
  35. package/src/modules/repos/boards/core.js +255 -0
  36. package/src/modules/repos/boards/docs.js +53 -0
  37. package/src/modules/repos/boards/members.js +228 -0
  38. package/src/modules/repos/boards/transfer.js +159 -0
  39. package/src/modules/repos/boards.js +25 -661
  40. package/src/modules/repos/cli/board-actions.js +177 -0
  41. package/src/modules/repos/cli/ref-actions.js +157 -0
  42. package/src/modules/repos/cli/remote-actions.js +141 -0
  43. package/src/modules/repos/cli/render.js +168 -0
  44. package/src/modules/repos/cli/repo-actions.js +199 -0
  45. package/src/modules/repos/cli/transfer-actions.js +105 -0
  46. package/src/modules/repos/index.js +18 -920
  47. package/src/modules/repos/service/bind-topics.js +97 -0
  48. package/src/modules/repos/service/context.js +189 -0
  49. package/src/modules/repos/service/crud.js +345 -0
  50. package/src/modules/repos/service/identity.js +188 -0
  51. package/src/modules/repos/service/store.js +274 -0
  52. package/src/modules/repos/service.js +41 -1061
  53. package/src/modules/repos/transfer/diff.js +126 -0
  54. package/src/modules/repos/transfer/export.js +223 -0
  55. package/src/modules/repos/transfer/import.js +377 -0
  56. package/src/modules/repos/transfer/layout.js +135 -0
  57. package/src/modules/repos/transfer/render.js +72 -0
  58. package/src/modules/repos/transfer.js +11 -922
  59. package/src/modules/tasktool/attach-resource.js +293 -0
  60. package/src/modules/tasktool/attach-template.js +266 -0
  61. package/src/modules/tasktool/attach.js +70 -558
  62. package/src/modules/tasktool/delivery-template.js +2 -1
  63. package/src/modules/tasktool/doc-inline.js +84 -0
  64. package/src/modules/tasktool/groupctx.js +3 -1
  65. package/src/modules/tasktool/plugins/timegoal-core-store.js +151 -0
  66. package/src/modules/tasktool/plugins/timegoal-cwd-store.js +441 -0
  67. package/src/modules/tasktool/plugins/timegoal-store.js +16 -842
  68. package/src/modules/tasktool/plugins/timegoal-task-store.js +289 -0
  69. package/src/modules/tasktool/wait.js +3 -1
  70. package/src/modules/todo/attachments.js +149 -0
  71. package/src/modules/todo/locate.js +82 -0
  72. package/src/modules/todo/service.js +42 -382
  73. package/src/modules/todo/store.js +158 -0
  74. package/src/shared/prompt-blocks.js +13 -4
  75. package/src/web/frontend/components/md/find-bar.jsx +38 -0
  76. package/src/web/frontend/components/md/live-block.jsx +129 -0
  77. package/src/web/frontend/components/md/md-panes-helpers.js +92 -0
  78. package/src/web/frontend/components/md/md-panes-keys.js +193 -0
  79. package/src/web/frontend/components/md/md-panes-root.jsx +158 -0
  80. package/src/web/frontend/components/md/md-panes.jsx +124 -1342
  81. package/src/web/frontend/components/md/slash-menu.jsx +83 -0
  82. package/src/web/frontend/components/md/status-bar.jsx +46 -0
  83. package/src/web/frontend/components/md/use-live-preview.js +279 -0
  84. package/src/web/frontend/components/md/use-slash-menu.js +80 -0
  85. package/src/web/frontend/components/md/use-source-editor.js +297 -0
  86. package/src/web/frontend/modules/md/md-blocks.js +248 -0
  87. package/src/web/frontend/modules/md/md-parse.js +23 -507
  88. package/src/web/frontend/modules/md/md-render.js +258 -0
  89. package/src/web/frontend/modules/md/style.css +7 -1605
  90. package/src/web/frontend/modules/md/styles/chrome.css +252 -0
  91. package/src/web/frontend/modules/md/styles/docs.css +185 -0
  92. package/src/web/frontend/modules/md/styles/editor.css +308 -0
  93. package/src/web/frontend/modules/md/styles/panels.css +372 -0
  94. package/src/web/frontend/modules/md/styles/shell.css +363 -0
  95. package/src/web/frontend/modules/md/styles/templates.css +125 -0
  96. package/src/web/frontend/page/dag/edges.js +55 -0
  97. package/src/web/frontend/page/dag/head-bar.jsx +46 -0
  98. package/src/web/frontend/page/dag/index.jsx +57 -420
  99. package/src/web/frontend/page/dag/layout.js +83 -0
  100. package/src/web/frontend/page/dag/model.js +47 -0
  101. package/src/web/frontend/page/dag/node-card.jsx +123 -0
  102. package/src/web/frontend/page/dag/use-interactions.js +135 -0
  103. package/src/web/frontend/page/dir/task-ack.js +38 -0
  104. package/src/web/frontend/page/dir/task-actions.js +379 -0
  105. package/src/web/frontend/page/dir/task-beside-header.jsx +18 -0
  106. package/src/web/frontend/page/dir/task-board-section.jsx +38 -0
  107. package/src/web/frontend/page/dir/task-chain.js +172 -0
  108. package/src/web/frontend/page/dir/task-derived-ctx.js +46 -0
  109. package/src/web/frontend/page/dir/task-dock-panel.jsx +227 -0
  110. package/src/web/frontend/page/dir/task-dock.js +79 -0
  111. package/src/web/frontend/page/dir/task-feedback.js +207 -0
  112. package/src/web/frontend/page/dir/task-goal-section.jsx +50 -0
  113. package/src/web/frontend/page/dir/task-goal.js +36 -0
  114. package/src/web/frontend/page/dir/task-history-view.jsx +44 -0
  115. package/src/web/frontend/page/dir/task-not-found.jsx +23 -0
  116. package/src/web/frontend/page/dir/task-preview-modal.jsx +82 -0
  117. package/src/web/frontend/page/dir/task-sel-menu.js +54 -0
  118. package/src/web/frontend/page/dir/task-status-bar.jsx +61 -0
  119. package/src/web/frontend/page/dir/task-utils.js +7 -0
  120. package/src/web/frontend/page/dir/task.jsx +117 -1532
  121. package/src/web/frontend/page/repos/bind-modals.jsx +118 -0
  122. package/src/web/frontend/page/repos/board-admin.jsx +226 -0
  123. package/src/web/frontend/page/repos/board-refs.jsx +97 -0
  124. package/src/web/frontend/page/repos/doc-search-modal.jsx +241 -0
  125. package/src/web/frontend/page/repos/filters-bar.jsx +44 -0
  126. package/src/web/frontend/page/repos/index.jsx +248 -1834
  127. package/src/web/frontend/page/repos/pending-section.jsx +163 -0
  128. package/src/web/frontend/page/repos/ref-panel.jsx +406 -0
  129. package/src/web/frontend/page/repos/remote-modal.jsx +112 -0
  130. package/src/web/frontend/page/repos/repo-form-modal.jsx +219 -0
  131. package/src/web/frontend/page/repos/repo-table.jsx +216 -0
  132. package/src/web/frontend/page/settings/prompt-template-params.js +214 -0
  133. package/src/web/frontend/page/settings/prompt-templates-section.jsx +1 -213
  134. package/src/web/frontend/style-v2.css +6 -1232
  135. package/src/web/frontend/style.css +10 -2434
  136. package/src/web/frontend/styles/base.css +139 -0
  137. package/src/web/frontend/styles/board.css +322 -0
  138. package/src/web/frontend/styles/buttons-cards.css +244 -0
  139. package/src/web/frontend/styles/modals.css +458 -0
  140. package/src/web/frontend/styles/panels.css +366 -0
  141. package/src/web/frontend/styles/repos-admin.css +207 -0
  142. package/src/web/frontend/styles/repos.css +330 -0
  143. package/src/web/frontend/styles/settings.css +244 -0
  144. package/src/web/frontend/styles/submit-bar.css +124 -0
  145. package/src/web/frontend/styles-v2/dag.css +285 -0
  146. package/src/web/frontend/styles-v2/dir.css +210 -0
  147. package/src/web/frontend/styles-v2/shell.css +251 -0
  148. package/src/web/frontend/styles-v2/sidebar.css +199 -0
  149. package/src/web/frontend/styles-v2/views.css +287 -0
  150. package/src/web/frontend/workspace/layout.js +399 -0
  151. package/src/web/frontend/workspace/open.js +246 -0
  152. package/src/web/frontend/workspace/panels.js +417 -0
  153. package/src/web/frontend/workspace.js +8 -1044
  154. package/src/web/public/assets/Introduction-Dnh0L_ss.js +1 -0
  155. package/src/web/public/assets/app-context-D7HAx67n.js +1 -0
  156. package/src/web/public/assets/bar-CgCAhY5x.js +1 -0
  157. package/src/web/public/assets/{board-view-t8CKtq17.js → board-view-CZKZsyk-.js} +1 -1
  158. package/src/web/public/assets/{button-M9TUn-AR.js → button-Cmo-6aoW.js} +1 -1
  159. package/src/web/public/assets/cloud-DMeqfWK9.js +3 -0
  160. package/src/web/public/assets/composer-launch-Bf4rXhLs.js +1 -0
  161. package/src/web/public/assets/composer-panel-C0qsxE7e.js +1 -0
  162. package/src/web/public/assets/dag-BBtSqd-X.js +1 -0
  163. package/src/web/public/assets/dir-UUWImKeX.js +5 -0
  164. package/src/web/public/assets/frontmatter-QvrjUNzF.js +2 -0
  165. package/src/web/public/assets/group-DFMGHQ-H.js +1 -0
  166. package/src/web/public/assets/index-CgEWvYQk.js +2 -0
  167. package/src/web/public/assets/md-history-CKumOs4q.js +39 -0
  168. package/src/web/public/assets/md-parse-awNLHAzO.js +13 -0
  169. package/src/web/public/assets/{member-picker--32VkTmv.js → member-picker-BAgkj36N.js} +1 -1
  170. package/src/web/public/assets/model-DzdWfp14.js +2 -0
  171. package/src/web/public/assets/{overview-B788GcJE.js → overview-BrcPfsJO.js} +1 -1
  172. package/src/web/public/assets/progress-DHDlz9O9.js +3 -0
  173. package/src/web/public/assets/refs-CqvRGv8w.js +1 -0
  174. package/src/web/public/assets/repos-DGrGWDnX.js +14 -0
  175. package/src/web/public/assets/route-crumb-yyPGKKKq.js +1 -0
  176. package/src/web/public/assets/settings-9zNucAPD.js +6 -0
  177. package/src/web/public/assets/{status-tag-BPbfa4zt.js → status-tag-bDdrFgpZ.js} +1 -1
  178. package/src/web/public/assets/task-CG4fzV6s.js +11 -0
  179. package/src/web/public/assets/{task-status-BP6y8MVu.js → task-status-BnymQMTw.js} +1 -1
  180. package/src/web/public/assets/templates-DdHWIxUE.js +1 -0
  181. package/src/web/public/assets/tool-bar-D8q3kOOl.js +1 -0
  182. package/src/web/public/assets/upload-BIMbGcCB.js +1 -0
  183. package/src/web/public/assets/workspace-C_5X2gIr.js +28 -0
  184. package/src/web/public/index.html +8 -4
  185. package/src/web/public/assets/Introduction-DKqRmABL.js +0 -1
  186. package/src/web/public/assets/bar-B8QJ4EnF.js +0 -1
  187. package/src/web/public/assets/cloud-C2O_1vT5.js +0 -3
  188. package/src/web/public/assets/composer-launch-BgMj0T3Y.js +0 -1
  189. package/src/web/public/assets/composer-panel-C5XUApWJ.js +0 -1
  190. package/src/web/public/assets/dag-CWAWk_gt.js +0 -1
  191. package/src/web/public/assets/dir-Cu5B5z6J.js +0 -5
  192. package/src/web/public/assets/group-YA-FgKS3.js +0 -1
  193. package/src/web/public/assets/index-DxX-ZzRP.js +0 -30
  194. package/src/web/public/assets/md-history-4sXoj4RH.js +0 -28
  195. package/src/web/public/assets/md-parse-C2bDc3IZ.js +0 -25
  196. package/src/web/public/assets/progress-CfzFVSDu.js +0 -3
  197. package/src/web/public/assets/refs-qtxw66hp.js +0 -1
  198. package/src/web/public/assets/repos-CpVuGaP2.js +0 -14
  199. package/src/web/public/assets/route-crumb-B8oEN8BB.js +0 -1
  200. package/src/web/public/assets/settings-BmWNBqcv.js +0 -6
  201. package/src/web/public/assets/task-DsFCNaOJ.js +0 -11
  202. package/src/web/public/assets/templates-4Xaj2m9L.js +0 -1
  203. package/src/web/public/assets/tool-bar-CfBWzhpV.js +0 -1
  204. package/src/web/public/assets/upload-L1g-pfvZ.js +0 -1
@@ -314,7 +314,8 @@ export async function groupContextFor(cwd, { board = '' } = {}) {
314
314
  // 本项目在组里的位置
315
315
  const noteRef = (b.repoDocs || {})[rk];
316
316
  const noteOwn = await readRef(noteRef, paths.groupNoteRel(b.name, rk), { warnings, label: `组内描述·${b.name}` });
317
- // 兄弟成员(组内各仓库的组内描述)
317
+ // 兄弟成员(组内各仓库的组内描述);path = 本机磁盘路径(#163:agent 看到名字
318
+ // 就能定位兄弟仓库,不用再查清单)
318
319
  const peers = [];
319
320
  for (const mkey of members) {
320
321
  const mr = s.repos.find((x) => deriveKey(x) === mkey);
@@ -325,7 +326,11 @@ export async function groupContextFor(cwd, { board = '' } = {}) {
325
326
  paths.groupNoteRel(b.name, mkey),
326
327
  { warnings, label: `组内描述·${b.name}/${mkey}` }
327
328
  );
328
- peers.push({ name: mname, note: peerNote.body || (b.repoNotes || {})[mkey] || '' });
329
+ peers.push({
330
+ name: mname,
331
+ note: peerNote.body || (b.repoNotes || {})[mkey] || '',
332
+ path: (mr && mr.path) || '',
333
+ });
329
334
  }
330
335
  // 组绑定参考文件(给可读路径——agent 直接读盘);tag 随条目走(有才带)
331
336
  const docLinks = linkEntries(b.docLinks, closure);
@@ -0,0 +1,84 @@
1
+ // 文档模块的 CLI 人读渲染:list/get/写回/seed/绑定/附件。
2
+ // 全是纯函数 —— 输入 action 的结构化结果,输出给人看的文本。
3
+
4
+ // list/get 的人读渲染共用的标题行:rel 或 path,缺省标题来自正文首个 #
5
+ function docHead(d) {
6
+ const addr = d.rel ? d.rel : d.path || d.docId;
7
+ const head = d.title ? `「${d.title}」` : '';
8
+ const extra = d.summary && d.summary !== d.title ? ` · ${d.summary}` : '';
9
+ return `${addr}${head}${extra}`;
10
+ }
11
+
12
+ export const renderList = (d) => {
13
+ const lines = [`自有文档 ${d.count} 个(~/.nx-kv/docs/,env NX_KV_DOCS_DIR 可覆盖)`];
14
+ for (const x of d.docs) lines.push(` ${x.rel} ${x.title || x.name}`);
15
+ if (d.external?.length) {
16
+ lines.push(`外部文档 ${d.external.length} 个(只读引用):`);
17
+ for (const x of d.external) lines.push(` ${x.path}`);
18
+ }
19
+ if (!d.count && !d.external?.length) {
20
+ lines.push('(还没有文档——描述字符串会在首次读取时播种为 md,或直接 docs seed --apply)');
21
+ }
22
+ return lines.join('\n');
23
+ };
24
+
25
+ export const renderGet = (d) => {
26
+ if (d.missing) return `(文档不存在: ${d.rel || d.path})`;
27
+ if (d.dir) return `(外部目录绑定: ${d.path},${d.files.length} 个文档)\n ${d.files.slice(0, 20).join('\n ')}`;
28
+ const head = [`【${d.title || docHead(d)}】`, ` ${d.rel || d.path}${d.external ? ' (外部 · 可写回来源)' : ''}`, ''];
29
+ return head.join('\n') + d.body;
30
+ };
31
+
32
+ export const renderWritten = (d) =>
33
+ `已写入 ${d.rel}(${d.bytes} 字节)${d.summary ? `\n摘要已回写: ${d.summary}` : ''}`;
34
+
35
+ export const renderSeed = (d) => {
36
+ if (d.written !== undefined) return `已播种 ${d.written} 份文档:\n ${(d.items || []).join('\n ') || '(无)'}`;
37
+ if (!d.count) return '没有需要播种的文档(字符串字段都为空,或约定路径已有 md)';
38
+ return `待播种 ${d.count} 份(--apply 执行):\n ${d.items.map((x) => `${x.rel} ←「${x.title}」`).join('\n ')}`;
39
+ };
40
+
41
+ export const renderRef = (d) =>
42
+ `${d.ref ? '已绑定' : '已拆绑定(回到约定路径)'}: ${d.kind} ${d.name} → ${d.ref ? (d.ref.rel ? 'rel:' + d.ref.rel : 'path:' + d.ref.path) : '约定路径'}`;
43
+
44
+ export const renderNoteRef = (d) =>
45
+ `${d.ref ? '已绑定' : '已拆绑定'}: 「${d.boardName}」× ${d.repoKey} → ${d.ref ? (d.ref.rel ? 'rel:' + d.ref.rel : 'path:' + d.ref.path) : '约定路径'}`;
46
+
47
+ export const renderLink = (d) => {
48
+ if (d.removed !== undefined) return `已移除组绑定: ${d.removed}(剩 ${d.count} 条)`;
49
+ const lines = [`「${d.boardName}」的组绑定(${d.count} 条):`];
50
+ for (const l of d.links) {
51
+ lines.push(` ${l.rel ? 'rel:' + l.rel : 'path:' + l.path}${l.tag ? ` [${l.tag}]` : ''}${l.note ? ` · ${l.note}` : ''}`);
52
+ }
53
+ return lines.join('\n');
54
+ };
55
+
56
+ export const renderAttachments = (d) => {
57
+ if (!d.attachments.length) {
58
+ return `「${d.locator}」没有登记资源(docs attach --no-embed 可只挂到附件区)`;
59
+ }
60
+ const areaOf = (role) => (role === 'attach' ? '附件区' : '正文内嵌');
61
+ const lines = [`「${d.locator}」的资源(${d.attachments.length})`];
62
+ for (const a of d.attachments) {
63
+ const where = a.localPath || a.url || (a.kind === 'task' ? `task ${a.targetKey}#${a.targetSeq}` : a.targetKey);
64
+ lines.push(` ${a.id} [${a.kind}/${a.role} · ${areaOf(a.role)}] ${a.name || '-'} ${where || ''}`);
65
+ }
66
+ return lines.join('\n');
67
+ };
68
+
69
+ export const renderAttach = (d) =>
70
+ `已附加 ${d.attachmentId}(${d.kind})到「${d.ref}」· ${d.area === 'area' ? '附件区(未写正文)' : '正文内嵌'}${d.markdown ? `\n嵌入: ${d.markdown}` : ''}`;
71
+
72
+ export const renderDetach = (d) => {
73
+ const head = d.unlinked
74
+ ? `已解除「${d.ref}」与附件 ${d.attachment} 的关系`
75
+ : `「${d.ref}」本来就没有引用附件 ${d.attachment}`;
76
+ const tail = d.purged
77
+ ? ';资源已删除(含本机字节)'
78
+ : d.purgeReason === 'in-use'
79
+ ? ';资源仍被其他任务/文档引用,未删字节'
80
+ : d.purgeReason === 'file-locked'
81
+ ? ';文件被占用,未删字节'
82
+ : '';
83
+ return head + tail;
84
+ };
@@ -0,0 +1,200 @@
1
+ // 文档模块的业务逻辑:CRUD + 外部写回。
2
+ //
3
+ // 「描述的权威是磁盘上的 .md 文件」——本模块只做这件事:CRUD、绑定、种子、知识聚合。
4
+ // 面板编辑(DocPanel)与组详情渲染都从这里取数;`repo knowledge` 在 repos 模块
5
+ // (它属于 repo.* 命令族),聚合逻辑在 knowledge.js。
6
+ //
7
+ // ─── 读写口径(2026-11 任务 #88「简介文档优化」)───────────────────────
8
+ // rel: 自有树(~/.nx-kv/docs/)——可读可写可删
9
+ // path: 外部(Obsidian vault / 任意登记目录)——**登记在册即可写**:
10
+ // 读侧要求路径在绑定闭包内;写侧再校验一次(闭包 + .md + 非目录),
11
+ // 等于「文档集里的每一篇都能就地改」,同时不把 PATCH 变成任意文件写入口。
12
+ // 删除仍不给外部:删除是可恢复性最差的操作,让它回来源做。
13
+ import * as paths from './paths.js';
14
+ import * as store from './store.js';
15
+ import * as seed from './seed.js';
16
+ import { reposBridge } from './repos-bridge.js';
17
+ import { badInput, blocked } from '../../core/errors.js';
18
+ import { getDb } from '../../core/db/index.js';
19
+ import { tx } from '../../core/db/tx.js';
20
+ import { ensureDocRef, syncRefAttachments } from '../../core/attachmentdb.js';
21
+ import fsp from 'node:fs/promises';
22
+ import path from 'node:path';
23
+
24
+ const clean = (v) => String(v || '').trim();
25
+
26
+ async function safeRead(abs) {
27
+ try {
28
+ return await fsp.readFile(abs, 'utf8');
29
+ } catch {
30
+ return '';
31
+ }
32
+ }
33
+
34
+ // ─── 查 ────────────────────────────────────────────────────────────────
35
+
36
+ // 树索引(零副作用,不播种——agent/前端拿它当双链解析的数据源)
37
+ export async function listDocs({ external } = {}) {
38
+ const docs = [];
39
+ for (const f of await store.listOwnDocs()) {
40
+ const title = /^#\s+(.+)$/m.exec(f.size <= 512 * 1024 ? await safeRead(f.abs) : '');
41
+ docs.push({
42
+ docId: paths.ownDocId(f.rel),
43
+ rel: f.rel,
44
+ name: f.rel.replace(/\.md$/i, '').split('/').pop(),
45
+ title: title ? title[1].trim() : '',
46
+ size: f.size,
47
+ });
48
+ }
49
+ const out = { docs, count: docs.length };
50
+ if (external) {
51
+ const { loadStore } = await reposBridge();
52
+ const s = await loadStore();
53
+ const closure = await store.externalClosure(s);
54
+ const files = await store.listExternalDocs(closure);
55
+ out.external = files.map((abs) => ({ docId: paths.extDocId(abs), path: abs, name: abs.replace(/\\/g, '/').split('/').pop().replace(/\.md$/i, '') }));
56
+ out.bound = closure.map((c) => ({ path: c.path, owner: c.owner, exists: c.exists, isDir: c.isDir }));
57
+ }
58
+ return out;
59
+ }
60
+
61
+ // 读全文:自有(惰性播种)/ 外部(闭包内才放行);目录绑定返回文件清单
62
+ export async function getDoc({ ref } = {}) {
63
+ if (!clean(ref)) throw badInput('请给文档标识:自有 rel:<路径>(或裸相对路径),外部 path:<绝对路径>');
64
+ const parsed = paths.parseDocId(ref);
65
+ if (parsed.kind === 'own') {
66
+ let body = null;
67
+ try {
68
+ body = await store.readOwnDoc(parsed.rel);
69
+ } catch {
70
+ const seeded = await seed.ensureSeedForRel(parsed.rel);
71
+ if (seeded === null) {
72
+ return { docId: paths.ownDocId(parsed.rel), rel: parsed.rel, missing: true, writable: true, title: '', summary: '', body: '' };
73
+ }
74
+ body = seeded;
75
+ }
76
+ return outOwn(parsed.rel, body);
77
+ }
78
+ // 外部:先过绑定闭包,闭包外一律拒绝——doc.get 不能变成任意文件读入口
79
+ const { loadStore } = await reposBridge();
80
+ const s = await loadStore();
81
+ const closure = await store.externalClosure(s);
82
+ const abs = store.resolveExternal(parsed.path, closure);
83
+ if (!abs) throw blocked(`外部路径不在绑定闭包内(先 docs bind 登记): ${parsed.path}`);
84
+ let st = null;
85
+ try {
86
+ st = await fsp.stat(abs);
87
+ } catch {
88
+ /* 缺失:按 missing 返回 */
89
+ }
90
+ if (!st) {
91
+ return { docId: paths.extDocId(abs), path: abs, missing: true, writable: true, title: '', summary: '', body: '' };
92
+ }
93
+ if (st.isDirectory()) {
94
+ const files = await store.listExternalDocs([{ path: abs, exists: true, isDir: true }], { maxDepth: 3, maxFiles: 200 });
95
+ return { docId: paths.extDocId(abs), path: abs, dir: true, writable: false, files };
96
+ }
97
+ return outExternal(abs, await safeRead(abs));
98
+ }
99
+
100
+ // ─── 增 / 改 / 删 ──────────────────────────────────────────────────────
101
+
102
+ // body-file 只给 CLI(templates 先例):HTTP 是面板的通道,不该变成任意读本机文件的入口
103
+ async function bodyOf({ body, bodyFile }, opts) {
104
+ const fileArg = opts && opts.transport === 'http' ? undefined : bodyFile;
105
+ if (typeof body === 'string') return body;
106
+ if (fileArg !== undefined) {
107
+ const { readFileSync } = await import('node:fs');
108
+ return readFileSync(fileArg === '-' ? 0 : fileArg, 'utf8');
109
+ }
110
+ return null;
111
+ }
112
+
113
+ export async function addDoc(ctx, opts) {
114
+ const rel = await store.writeOwnDoc(ctx.rel, (await bodyOf(ctx, opts)) ?? '');
115
+ const body = await store.readOwnDoc(rel);
116
+ const summary = await seed.writeBackSummary(rel, body);
117
+ return { docId: paths.ownDocId(rel), rel, bytes: Buffer.byteLength(body, 'utf8'), summary };
118
+ }
119
+
120
+ // 外部文档写回(面板/CLI 均可):路径必须仍在**绑定闭包**内——闭包是唯一的授权来源,
121
+ // 否则 PATCH 就成了任意文件写入口(与 getDoc 的读侧守卫同口径)。
122
+ // 目录绑定只允许改写目录内的 .md;单文件绑定只允许那一个文件。
123
+ async function writeExternalDoc(abs, body) {
124
+ const { loadStore } = await reposBridge();
125
+ const s = await loadStore();
126
+ const closure = await store.externalClosure(s);
127
+ const hit = store.resolveExternal(abs, closure);
128
+ if (!hit) throw blocked(`外部路径不在绑定闭包内(先 docs bind 登记): ${abs}`);
129
+ if (!/\.md$/i.test(abs)) throw badInput('只能写回 .md 文档: ' + abs);
130
+ let st = null;
131
+ try {
132
+ st = await fsp.stat(abs);
133
+ } catch {
134
+ st = null;
135
+ }
136
+ if (st && st.isDirectory()) throw blocked('这是目录绑定,不能整体写回: ' + abs);
137
+ await fsp.mkdir(path.dirname(abs), { recursive: true });
138
+ await fsp.writeFile(abs, body, 'utf8');
139
+ const saved = await safeRead(abs);
140
+ // 外部文档同样是「文档库的一行」:正文里的 fileId / nxkv 链接也落 ref_attach。
141
+ // 与自有树同一事务口径(ensureDocRef 幂等;refs 只装 .md)。
142
+ const db = getDb();
143
+ tx(
144
+ (conn) => {
145
+ const refId = ensureDocRef(conn, { locator: abs });
146
+ syncRefAttachments(conn, { refId, text: saved });
147
+ },
148
+ { db, mode: 'IMMEDIATE' }
149
+ );
150
+ return { docId: paths.extDocId(abs), path: abs, bytes: Buffer.byteLength(saved, 'utf8'), external: true };
151
+ }
152
+
153
+ export async function updateDoc(ctx, opts) {
154
+ const parsed = paths.parseDocId(ctx.ref);
155
+ const body = await bodyOf(ctx, opts);
156
+ if (body === null) throw badInput('请给 --body <正文>(多行用 --body-file <文件> 或 - 读管道)');
157
+ // 外部绑定:登记在册 = 我的文档集,允许就地写回来源文件(闭包内校验)
158
+ if (parsed.kind !== 'own') return writeExternalDoc(parsed.path, body);
159
+ // 不存在即创建(面板保存语义:脏页签保存不该因为别人先建了而失败,也不该在这里静默分叉出第二份)
160
+ const rel = await store.writeOwnDoc(parsed.rel, body);
161
+ const saved = await store.readOwnDoc(rel);
162
+ const summary = await seed.writeBackSummary(rel, saved);
163
+ return { docId: paths.ownDocId(rel), rel, bytes: Buffer.byteLength(saved, 'utf8'), summary };
164
+ }
165
+
166
+ export async function removeDoc({ ref } = {}) {
167
+ const parsed = paths.parseDocId(ref);
168
+ if (parsed.kind !== 'own') throw blocked('外部绑定是只读引用,不能在这里删除');
169
+ const rel = await store.removeOwnDoc(parsed.rel);
170
+ return { docId: paths.ownDocId(rel), rel };
171
+ }
172
+
173
+ // ─── 出参整形 ──────────────────────────────────────────────────────────
174
+
175
+ function outOwn(rel, body) {
176
+ const { summaryFromMd } = seed;
177
+ const m = /^#\s+(.+)$/m.exec(body);
178
+ return {
179
+ docId: paths.ownDocId(rel),
180
+ rel,
181
+ title: m ? m[1].trim() : '',
182
+ summary: summaryFromMd(body),
183
+ body,
184
+ writable: true,
185
+ };
186
+ }
187
+
188
+ function outExternal(abs, body) {
189
+ const m = /^#\s+(.+)$/m.exec(body);
190
+ return {
191
+ docId: paths.extDocId(abs),
192
+ path: abs,
193
+ title: m ? m[1].trim() : '',
194
+ summary: seed.summaryFromMd(body),
195
+ body,
196
+ // 登记在册的外部文档 = 用户的文档集,允许就地写回来源文件(写侧另过闭包校验)
197
+ writable: true,
198
+ external: true,
199
+ };
200
+ }
@@ -0,0 +1,88 @@
1
+ // 附件类 action(自 index.js 拆出):挂附件 attach / 解除 detach / 列附件 attachments。
2
+ import { CWD, KEY } from './action-flags.js';
3
+ import { renderDetach, renderTaskAttachments } from './action-render.js';
4
+
5
+ export const attachActions = [
6
+ {
7
+ // 附件追加(与云端 todo attach 同构):--path 落**本机附件仓**(零云端)→ 嵌入正文末尾;
8
+ // --fileId 引用已有附件(本机仓 / 云端 id)。面板编辑器贴同一条语法(components/md/attachments.js)。
9
+ id: 'localtask.attach',
10
+ cli: ['localtask', 'attach'],
11
+ http: ['POST', '/api/localtasks/attach'],
12
+ summary:
13
+ '给任务挂附件:--path 存本机附件仓 / --fileId 引用已有附件 / --url / --task(同主题任务)/ --ref(文档);默认嵌进正文,--no-embed 只挂到附件区(不写正文),--ref 加 --inline 文档进原文(交付带全文)',
14
+ flags: {
15
+ id: { type: 'number', required: true, hint: '任务编号' },
16
+ cwd: CWD,
17
+ key: KEY,
18
+ path: { type: 'string', hint: '本机文件路径(落 ~/.nx-kv/attachments/local/ 再登记)' },
19
+ fileId: { type: 'string', hint: '已有附件的 id(32 位 hex,可带扩展名;本机仓或云端)' },
20
+ url: { type: 'string', hint: '外部链接(http/https;kind=url)' },
21
+ task: { type: 'string', hint: '同主题下的任务编号(kind=task,落 nxkv://task/<id>)' },
22
+ ref: { type: 'string', hint: '文档路径或 ref id(kind=ref,落 nxkv://ref/<refId>)' },
23
+ inline: { type: 'boolean', hint: '文档进原文:交付时附全文(截断 2 万字)而不是只给路径;仅 --ref 有效' },
24
+ name: { type: 'string', hint: '显示名 / 本地文件名(默认取原名)' },
25
+ kind: { type: 'string', hint: 'image | file(仅 --path/--fileId 用;不给按扩展名判)' },
26
+ note: { type: 'string', hint: '绑定说明(desc):附件区条目备注 / 文档绑定的一行简介,交付清单透出' },
27
+ noEmbed: { type: 'boolean', hint: '只写 attachments + task_attach(role=attach),不改正文' },
28
+ 'no-embed': { type: 'boolean', hint: '同 --noEmbed(连字符写法)' },
29
+ },
30
+ run: async (ctx) => {
31
+ const { attachToTask } = await import('../tasktool/attach.js');
32
+ return attachToTask({
33
+ id: ctx.id,
34
+ cwd: ctx.cwd,
35
+ key: ctx.key,
36
+ path: ctx.path,
37
+ fileId: ctx.fileId,
38
+ url: ctx.url,
39
+ task: ctx.task,
40
+ ref: ctx.ref,
41
+ inline: ctx.inline,
42
+ name: ctx.name,
43
+ kind: ctx.kind,
44
+ note: ctx.note,
45
+ noEmbed: !!(ctx.noEmbed ?? ctx['no-embed']),
46
+ });
47
+ },
48
+ render: (d) =>
49
+ `已附加 ${d.fileId}(${d.kind === 'image' ? '图片' : d.kind === 'url' ? '链接' : d.kind === 'task' ? '任务' : d.kind === 'ref' ? '文档' : '文件'})到主题「${d.name}」#${d.task.id} · ${d.role === 'doc' ? '文档资料(交付进原文)' : d.area === 'area' ? '附件区(未写正文)' : '正文内嵌'}${d.markdown ? `\n嵌入: ${d.markdown}` : ''}`,
50
+ },
51
+ {
52
+ id: 'localtask.detach',
53
+ cli: ['localtask', 'detach'],
54
+ http: ['DELETE', '/api/localtasks/attach'],
55
+ summary:
56
+ '解除任务与附件的关系(默认只解除关系,资源进孤儿池);--purge 在无人引用时连资源行与本机字节一起删',
57
+ flags: {
58
+ id: { type: 'number', required: true, hint: '任务编号' },
59
+ cwd: CWD,
60
+ key: KEY,
61
+ attachment: { type: 'string', required: true, hint: '资源 id(见 localtask attachments)' },
62
+ purge: { type: 'boolean', hint: '连资源行与本机字节一起删(仍被其他任务/文档引用时拒绝删)' },
63
+ },
64
+ run: async (ctx) => {
65
+ const { detachTaskAttachment } = await import('../tasktool/attach.js');
66
+ return detachTaskAttachment({
67
+ id: ctx.id,
68
+ cwd: ctx.cwd,
69
+ key: ctx.key,
70
+ attachment: ctx.attachment,
71
+ purge: ctx.purge,
72
+ });
73
+ },
74
+ render: renderDetach,
75
+ },
76
+ {
77
+ id: 'localtask.attachments',
78
+ cli: ['localtask', 'attachments'],
79
+ http: ['GET', '/api/localtasks/attachments'],
80
+ summary: '列出某条任务引用的附件(正文里的 ![名](fileId) 嵌入),以及本地是否已有(给 agent 直接读本地文件)',
81
+ flags: { id: { type: 'number', required: true, hint: '任务编号' }, cwd: CWD, key: KEY },
82
+ run: async (ctx) => {
83
+ const { listTaskAttachments } = await import('../tasktool/attach.js');
84
+ return listTaskAttachments({ id: ctx.id, cwd: ctx.cwd, key: ctx.key });
85
+ },
86
+ render: renderTaskAttachments,
87
+ },
88
+ ];
@@ -0,0 +1,6 @@
1
+ // action 共享的 flag 定义(自 index.js 拆出):cwd/key 主题定位与 wait 的现状参数。
2
+
3
+ export const CWD = { type: 'string', hint: '工作目录(作为主题;默认当前目录)' };
4
+ export const SUMMARY = { type: 'string', required: true, hint: '当前现状(agent 当前状态,展示给用户)' };
5
+ // 任务级寻址的 key flag:全局主题没有 cwd,只能按 key 定位(__GLOBAL__)
6
+ export const KEY = { type: 'string', hint: '主题 key(与 --cwd 二选一;全局任务池固定 __GLOBAL__)' };
@@ -0,0 +1,190 @@
1
+ // 任务生命周期 action(自 index.js 拆出):克隆/派生 → 领取/预览 → 重开/完成/时间目标日志。
2
+ import * as service from './service.js';
3
+ import { badInput } from '../../core/errors.js';
4
+ import { CWD, KEY } from './action-flags.js';
5
+ import { renderWait, renderPreview } from './action-render.js';
6
+
7
+ export const lifecycleActions = [
8
+ {
9
+ // 克隆(#70):以现任务为模板快速复制内容成一条新任务。**不建派生链**——
10
+ // forkOf 留空(那条语义属于 reopen 反馈 / 评论派生),时间目标与依赖也不继承;
11
+ // 源任务不动,克隆后两条并存。
12
+ id: 'localtask.clone',
13
+ cli: ['localtask', 'clone'],
14
+ http: ['POST', '/api/localtasks/clone'],
15
+ summary:
16
+ '克隆任务:复制正文内容为一条新任务(同主题;全局任务仍进全局池)。不带派生链、不继承时间目标与依赖——开新活用',
17
+ flags: { id: { type: 'number', required: true, hint: '任务编号' }, cwd: CWD, key: KEY },
18
+ run: (ctx) => service.cloneTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key }),
19
+ render: (d) =>
20
+ `已克隆 #${d.from.id} → #${d.task.id} @ ${d.name}(内容复制,无派生链;${d.delivered ? '已实时投递' : '待领取'})`,
21
+ },
22
+ {
23
+ // Fork(#67):克隆的原文复制 + 派生链。clone 有时被当成新活后,原任务的
24
+ // 评论/反馈链就看不到了;fork 把新任务挂到源任务下(task_links type=comment),
25
+ // 链在任务链弹窗里继续可见。正文逐字复制,源任务不动。
26
+ id: 'localtask.fork',
27
+ cli: ['localtask', 'fork'],
28
+ http: ['POST', '/api/localtasks/fork'],
29
+ summary:
30
+ 'Fork 任务:复制正文内容为新任务,并把它挂到源任务的任务链下(保留评论/反馈链);不继承时间目标与依赖',
31
+ flags: { id: { type: 'number', required: true, hint: '任务编号' }, cwd: CWD, key: KEY },
32
+ run: (ctx) => service.forkTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key }),
33
+ render: (d) =>
34
+ `已 Fork #${d.from.id} → #${d.task.id} @ ${d.name}(内容复制 + 保留任务链;${d.delivered ? '已实时投递' : '待领取'})`,
35
+ },
36
+ {
37
+ // 领取(todo.md 的「get」):默认直接领——队列有任务立即返回,没有立即空手而回
38
+ // (不阻塞);项目开启「持续 get」(repo getLoop)后升级为 waitgoal:
39
+ // 无任务自动唤起阻塞窗口(打开页面 + 项目配置的分钟数),领到的交付文本
40
+ // 自带「继续 get 直到超时」的项目模板。
41
+ id: 'localtask.claim',
42
+ cli: ['localtask', 'get'],
43
+ http: null, // 与 wait 同族:阻塞语义只走 CLI(agent 本轮的领取动作)
44
+ summary:
45
+ '领取任务:有任务立即领(含任务级 timegoal 的 check 指令);没任务默认立即返回 timeout,项目开启「持续 get」后自动唤起阻塞窗口等人回填',
46
+ flags: {
47
+ cwd: CWD,
48
+ summary: { type: 'string', hint: '当前现状(agent 状态,展示给用户)' },
49
+ timeout: { type: 'number', hint: '阻塞上限(秒);仅项目开启「持续 get」时有意义' },
50
+ 'no-open': { type: 'boolean', hint: '不自动打开浏览器(测试用)' },
51
+ param: { type: 'array', hint: '外部参数(平面扩展):k=v,可重复或逗号分隔;进交付模板 ctx,模板里 {{k}} / {{params.k}} 取' },
52
+ },
53
+ run: async (ctx) => {
54
+ const { getTask } = await import('../tasktool/get.js');
55
+ const { parseParams } = await import('../tasktool/params.js');
56
+ return getTask({ cwd: ctx.cwd, summary: ctx.summary, timeoutSec: ctx.timeout, open: !ctx['no-open'], params: parseParams(ctx.param) });
57
+ },
58
+ render: renderWait, // 返回形状与 wait 同构(ok/timeout),复用同一份人读渲染
59
+ },
60
+ {
61
+ // 预览(任务 #65):编辑页「更多 → 预览 get 提示词」的接口层。
62
+ // **只读**:不领取、不写盘、不启动时间目标计时、不为附件发网。
63
+ // 它与真实领取走同一条 buildTaskDelivery(见 tasktool/preview.js 的三条纪律),
64
+ // 所以预览出来的字符串就是 agent 会拿到的那一份。
65
+ id: 'localtask.preview',
66
+ cli: ['localtask', 'preview'],
67
+ http: ['POST', '/api/localtasks/preview'],
68
+ summary:
69
+ '预览一条任务在 get/wait 时的交付提示词(只读:不领取、不写盘、不启动计时、不为附件发网);草稿用 --text 直接预览',
70
+ flags: {
71
+ id: { type: 'number', hint: '任务编号(草稿预览可省,改给 --text)' },
72
+ cwd: CWD,
73
+ key: KEY,
74
+ text: { type: 'string', hint: '直接预览这段正文(草稿未落库时用;给了就不读库存)' },
75
+ param: { type: 'array', hint: '外部参数(平面扩展):k=v,与 get 的 --param 同语义' },
76
+ },
77
+ run: async (ctx) => {
78
+ const { previewTaskDelivery } = await import('../tasktool/preview.js');
79
+ const { parseParams } = await import('../tasktool/params.js');
80
+ const draftText = ctx.text === undefined || ctx.text === null ? '' : String(ctx.text);
81
+ if (!draftText.trim() && (ctx.id === undefined || ctx.id === null)) {
82
+ throw badInput('需要 --id <任务编号>(预览库存任务)或 --text <正文>(预览草稿)');
83
+ }
84
+ const task = draftText.trim()
85
+ ? { id: 0, text: draftText, status: 'draft' }
86
+ : await service.getTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key });
87
+ // 任务级 timegoal 按主题 key 寻址:没显式给 key 就从 cwd 归一化出来
88
+ const topicKey = ctx.key || service.normalizeCwd(ctx.cwd).key;
89
+ return previewTaskDelivery({
90
+ task,
91
+ cwd: ctx.cwd,
92
+ key: topicKey,
93
+ summary: '',
94
+ params: parseParams(ctx.param),
95
+ });
96
+ },
97
+ render: renderPreview,
98
+ },
99
+ {
100
+ // 修改反馈 / 重做 / 划选评论 → **就地重开原任务**(#74),历史进 history 链。
101
+ id: 'localtask.reopen',
102
+ cli: ['localtask', 'reopen'],
103
+ http: ['POST', '/api/localtasks/reopen'],
104
+ summary:
105
+ '重开任务(验收反馈 / 重做 / 评论):回写原任务正文,旧态压进 history;已完成则回到 pending 待再领',
106
+ flags: {
107
+ id: { type: 'number', required: true, hint: '任务编号' },
108
+ cwd: CWD,
109
+ key: KEY,
110
+ text: { type: 'string', hint: '修改后的任务正文(Markdown);不给则只重开不改内容' },
111
+ kind: { type: 'string', hint: 'reopen(验收反馈,默认)或 comment(划选评论)' },
112
+ quote: { type: 'string', hint: '划选原文(comment 时)' },
113
+ feedback: { type: 'string', hint: '用户反馈原文;不给 text 时追加到当前正文末尾(#79,base = 服务端最新正文)' },
114
+ feedbackHeading: { type: 'string', hint: '追加反馈段的段名(缺省 comment=## 反馈修改 / reopen=## 验收反馈)' },
115
+ feedbackBold: { type: 'boolean', hint: '追加的反馈是否逐行加粗(缺省 comment=false / reopen=true)' },
116
+ },
117
+ run: async (ctx) => {
118
+ // 重开也可能带着改过的归属(--text 的 frontmatter.project 变了)→ 同样搬家
119
+ const { reopenTask } = await import('../tasktool/update.js');
120
+ return reopenTask({
121
+ id: ctx.id,
122
+ cwd: ctx.cwd,
123
+ key: ctx.key,
124
+ text: ctx.text,
125
+ kind: ctx.kind,
126
+ quote: ctx.quote,
127
+ feedback: ctx.feedback,
128
+ feedbackHeading: ctx.feedbackHeading,
129
+ feedbackBold: ctx.feedbackBold,
130
+ attachments: ctx.attachments,
131
+ });
132
+ },
133
+ render: (d) =>
134
+ `已重开 #${d.id} @ ${d.name}` +
135
+ (d.before?.completedAt ? '(已完成→待领取)' : '') +
136
+ (d.historyId != null ? `;链节点 #${d.historyId}` : '') +
137
+ (d.moved && d.movedFrom ? `;已改归属项目,原 ${d.movedFrom.name} #${d.movedFrom.id}` : ''),
138
+ },
139
+ {
140
+ // 完成门禁:带时间目标的任务未到点拒绝标记完成(提示派 sub agent 重提需求)。
141
+ id: 'localtask.done',
142
+ cli: ['localtask', 'done'],
143
+ http: ['POST', '/api/localtasks/done'],
144
+ summary:
145
+ '标记任务完成:--summary 完成总结必填;带时间目标的任务未到点会被拒绝(blocked),到点自动记录最终 check',
146
+ flags: {
147
+ id: { type: 'number', required: true, hint: '任务编号' },
148
+ cwd: CWD,
149
+ key: KEY,
150
+ summary: { type: 'string', required: true, hint: '完成总结(记为本轮终态 + timegoal 日志)' },
151
+ progress: { type: 'string', hint: '完成度/下一步(≤2000 字,一并写入日志)' },
152
+ },
153
+ run: (ctx) =>
154
+ service.completeTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key, summary: ctx.summary, progress: ctx.progress }),
155
+ render: (d) => {
156
+ if (d.status === 'blocked') {
157
+ const why = d.reason === 'not_claimed' ? d.hint : `时间未到(剩 ${d.remainingHuman || Math.round((d.remainingSec || 0) / 60) + ' 分钟'},截止 ${d.deadline})——${d.hint}`;
158
+ return `[blocked] 任务 #${d.id} 暂不能标完成:${why}`;
159
+ }
160
+ if (d.already) return `任务 #${d.id} 之前已完成(${d.completedAt}),无需重复标记。`;
161
+ const goal = d.goal && d.goal.recorded ? '(最终 check 已记录)' : '';
162
+ return `已标记完成: #${d.id} @ ${d.name}(${d.completedAt})${goal}`;
163
+ },
164
+ },
165
+ {
166
+ id: 'localtask.timegoalLog',
167
+ cli: ['localtask', 'timegoal-log'],
168
+ http: ['GET', '/api/localtasks/timegoal-log'],
169
+ summary: '查看任务级时间目标的每轮 check 记录(时间、已用/剩余、是否到点、当轮总结与进度)',
170
+ flags: { id: { type: 'number', required: true, hint: '任务编号' }, cwd: CWD, key: KEY },
171
+ run: async (ctx) => {
172
+ const topicKey = ctx.key || service.normalizeCwd(ctx.cwd).key;
173
+ const { getTaskGoalLog } = await import('../tasktool/timegoal.js');
174
+ return getTaskGoalLog({ topicKey, taskId: ctx.id });
175
+ },
176
+ render: (d) => {
177
+ if (!d.hasGoal) return `#${d.seq || ''} 没有任务级时间目标记录。`;
178
+ const lines = [`#${d.seq} 时间目标 check 记录 ${d.count} 轮(${d.duration} · ${d.startedAt} → ${d.deadline})`];
179
+ if (!d.count) lines.push(' (还没有 check 记录)');
180
+ d.entries.forEach((e, i) => {
181
+ lines.push(
182
+ ` R${i + 1} ${e.checkedAt} 已用 ${e.elapsedSec}s · 剩余 ${e.remainingSec}s${e.reached ? ' · 已到点' : ''}`,
183
+ );
184
+ if (e.summary) lines.push(` ${e.summary}`);
185
+ if (e.progress) lines.push(` 进度: ${e.progress}`);
186
+ });
187
+ return lines.join('\n');
188
+ },
189
+ },
190
+ ];