nx-kv 0.25.0 → 0.26.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 (36) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/assets/kv-get/SKILL.md +7 -11
  3. package/package.json +1 -1
  4. package/src/modules/localtask/index.js +36 -15
  5. package/src/modules/localtask/task-lifecycle.js +128 -55
  6. package/src/modules/localtask/task-view.js +89 -12
  7. package/src/web/frontend/components/md/sel-menu.jsx +112 -19
  8. package/src/web/frontend/components/md/task-chain.jsx +75 -0
  9. package/src/web/frontend/components/md/tool-bar.jsx +6 -0
  10. package/src/web/frontend/modules/board/ack-nodes.js +2 -2
  11. package/src/web/frontend/modules/md/style.css +44 -0
  12. package/src/web/frontend/page/dir/index.jsx +32 -15
  13. package/src/web/frontend/page/dir/landing.jsx +2 -2
  14. package/src/web/frontend/page/dir/task.jsx +300 -89
  15. package/src/web/frontend/panels.jsx +13 -3
  16. package/src/web/public/assets/{Introduction-VfytFhtV.js → Introduction-ka0UxW_S.js} +1 -1
  17. package/src/web/public/assets/{cloud-DolkshAI.js → cloud-y1mZIdlN.js} +1 -1
  18. package/src/web/public/assets/{dag-C-E5GoLz.js → dag-CiMSs7uT.js} +1 -1
  19. package/src/web/public/assets/dir-DKzzrY8P.js +3 -0
  20. package/src/web/public/assets/{group-BQTuoGyZ.js → group-DOLdLkaj.js} +1 -1
  21. package/src/web/public/assets/{index-BryAyn_9.js → index-CbZfbzqr.js} +2 -2
  22. package/src/web/public/assets/{index-B48b_WIl.css → index-DUvCgdUV.css} +1 -1
  23. package/src/web/public/assets/{md-history-vwtmQsFJ.js → md-history-Ddk04A_2.js} +1 -1
  24. package/src/web/public/assets/{member-picker-DwJAdKTe.js → member-picker-Dsy1GH0E.js} +1 -1
  25. package/src/web/public/assets/{overview-Crnguaek.js → overview-ty9m-bCh.js} +1 -1
  26. package/src/web/public/assets/{progress-ijTyMRPT.js → progress-BQJhISlF.js} +1 -1
  27. package/src/web/public/assets/{repos-C_dN0b6h.js → repos-Di5InllN.js} +1 -1
  28. package/src/web/public/assets/{route-crumb-DZw2J3Nx.js → route-crumb-g3leiQhY.js} +1 -1
  29. package/src/web/public/assets/{settings-C7zGy-xI.js → settings-CE-rlcXr.js} +1 -1
  30. package/src/web/public/assets/task-D97dEZdc.js +6 -0
  31. package/src/web/public/assets/{template-slots-DhPGCIqW.js → template-slots-D40ponA2.js} +1 -1
  32. package/src/web/public/assets/{templates-xXPow5BD.js → templates-Ca1jXhnO.js} +1 -1
  33. package/src/web/public/assets/{upload-uBhGCTZ2.js → upload-BeiJetbd.js} +1 -1
  34. package/src/web/public/index.html +2 -2
  35. package/src/web/public/assets/dir-kBhfKX8r.js +0 -3
  36. package/src/web/public/assets/task-CqoiXFKL.js +0 -5
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.26.0] - 2026-11-05 ack 与评论统一回写原任务 + 任务链可视化
6
+
7
+ ### Changed
8
+
9
+ - **修正 ack 与评论机制(任务 #74)——推翻 v0.24.9 的「重开即新建」方向**:验收反馈与
10
+ 划选评论**就地回写原任务**(同一编号、同一 md),不再新建队列行 + 归档旧任务。
11
+ 「新建任务」会把同一件活拆成多条待领,验收 / 评论闭环断在新号上;现在闭环回到同号。
12
+ - `reopenTask`:旧态压进 `history[]` 链(起点 → 反馈 / 评论 → 当前),正文 = 原正文 +
13
+ 上一轮完成总结 + 本轮反馈;清领取 / 完成标记回 pending,等再领(同号继续)。
14
+ - `archived` 状态仍保留给旧口径(#59 fork 取代)的残留行,但不再由 reopen 写入。
15
+ - **评论与反馈都支持附件 / 图片**(划选评论入口同样可带图,走附件链路)。
16
+ - 评论入口新增 `quote`(划选原文)与 `kind`(reopen / comment)参数,
17
+ `localtask reopen --kind comment --quote "…" --feedback "…"`。
18
+ ### Added
19
+
20
+ - **任务链可视化(弹窗)**:编辑页可打开本任务的链——`history` 节点(起点 / 反馈 / 评论 /
21
+ 当前)按时间排列,点任一节点**旁路只读查看那一轮的正文**(页签带 historyId 只读形态);
22
+ 旧 `forkOf` 派生链(祖先 + 子任务)继续兼容显示。`localtask chain --id <n>` 人读输出同步
23
+ 改为以 history 节点为主。
24
+
25
+ > 与 v0.24.9 的关系:那版把「重开」改成了「新建任务 + 归档」,实践下来验收 / 评论闭环断在
26
+ > 新号上(#74 要求统一回写原任务、历史用链可视化),本版改回就地重开,历史不丢(history 链)。
5
27
  ## [0.25.0] - 2026-11-05 新建任务不再丢上下文 + 交付预览 + 存储层收口
6
28
 
7
29
  ### Added
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: kv-get
3
- description: 领取与完成排给本工作目录的本地任务(别人通过 kv-submit 委托的、用户排队的,都落在「目录名即主题」的队列里)——用 localtask get 取活(默认直接领;项目开启「持续 get」后自动阻塞等人回填)、localtask wait 挂着等人接力、localtask done 标记完成(带时间目标的任务未到点会被拒绝,提示派 sub agent 重提需求)、localtask reopen 把用户的修改反馈变成**一条新任务**(旧任务归档留档,状态单向)。触发词:领取本地任务、看看有没有排给我的任务、本地队列、领取委托任务、拿任务、本目录的任务、排队任务、localtask get、localtask wait、标记完成、任务完成、修改反馈、重新执行、kv-get。凡「主动获取排给本目录的任务」以及「把任务标记完成/按反馈重开」的场景都走本 skill。反例:把需求提交/委托给别的目录用 kv-submit;查本机仓库分组与参考仓库用 kv-repo;操作远程 KV 清单(todo)用 nx-kv。
3
+ description: 领取与完成排给本工作目录的本地任务(别人通过 kv-submit 委托的、用户排队的,都落在「目录名即主题」的队列里)——用 localtask get 取活(默认直接领;项目开启「持续 get」后自动阻塞等人回填)、localtask wait 挂着等人接力、localtask done 标记完成(带时间目标的任务未到点会被拒绝,提示派 sub agent 重提需求)、localtask reopen **就地重开原任务**(历史进 history 链,已完成则回到待领取)。触发词:领取本地任务、看看有没有排给我的任务、本地队列、领取委托任务、拿任务、本目录的任务、排队任务、localtask get、localtask wait、标记完成、任务完成、修改反馈、重新执行、kv-get。凡「主动获取排给本目录的任务」以及「把任务标记完成/按反馈重开」的场景都走本 skill。反例:把需求提交/委托给别的目录用 kv-submit;查本机仓库分组与参考仓库用 kv-repo;操作远程 KV 清单(todo)用 nx-kv。
4
4
  ---
5
5
 
6
6
  # kv-get — 领取、执行、完成(领取侧)
@@ -69,20 +69,16 @@ nx-kv localtask done --id <n> --summary "<完成总结>" --json
69
69
  # 标记完成(完成总结必填——它就是下一轮 agent 能看到的「上轮做了什么」)
70
70
  nx-kv localtask done --id <n> --summary "<完成总结>" [--progress "<完成度/下一步>"]
71
71
 
72
- # 用户看了结果提修改意见 → **新建一条任务**(新的 md),旧任务归档留档
73
- nx-kv localtask reopen --id <n> [--text "<改后的正文(Markdown)>"] --json
72
+ # 用户看了结果提修改意见 → **就地重开原任务**(同号回写,旧态压进 history)
73
+ nx-kv localtask reopen --id <n> [--text "<改后的正文(Markdown)>"] [--kind reopen|comment] --json
74
74
 
75
- # 查派生链(评论生成 / 反馈重开的关联):祖先 + 全部子任务,跨主题
75
+ # 查任务链:同任务 history 节点(origin/reopen/comment/current)+ 旧 forkOf 派生(若有)
76
76
  nx-kv localtask chain --id <n> --json
77
77
  ```
78
78
 
79
- `reopen` **不改旧任务**:它在同一条队列里**新建一条待领取任务**(正文 = `--text` 给的
80
- 内容),旧任务状态前进到终态「已归档」——原文、上一轮完成总结、完成标记全部留档。
81
- 新任务继承同一件活的约束(时间目标从再次领取重新计时、闸门、上游依赖),
82
- 并用 `forkOf` 指回上一条。
83
-
84
- 任务状态是**单向**的:`待领取 → 已领取 → 已归档`,**没有回退边**——
85
- 完成等待验收之后不会回到「重新开始」。
79
+ `reopen` **回写同一条任务**:正文 = `--text`;上一轮完成总结等压进 `history[]`。
80
+ 若任务已完成(有 `completedAt`),清领取/完成标记并回到 `pending` 等待再领;
81
+ 未完成则只改正文 + 记链。面板的验收重做与划选评论共用这一入口(可带附件)。
86
82
 
87
83
  ## 硬规则
88
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -79,18 +79,28 @@ function renderAdd(d) {
79
79
  return body + ignored;
80
80
  }
81
81
 
82
- // `localtask chain` 的人读输出(#69):本条 → 祖先链(逐级 fork 自)→ 子任务
83
- const KIND_TAG = { reopen: '反馈', comment: '评论' };
82
+ // `localtask chain` 的人读输出(#74):同任务 history 节点为主;旧 forkOf 祖先/子任务为辅
83
+ const KIND_TAG = { origin: '起点', reopen: '反馈', comment: '评论', current: '当前' };
84
84
  function renderChain(d) {
85
85
  const self = d.task;
86
86
  const lines = [
87
87
  `#${self.id} [${STATUS_TAG[self.status] || self.status}] ${d.name}`,
88
88
  ` ${self.text.split('\n').map((l) => l.trim()).find(Boolean) || ''}`,
89
89
  ];
90
+ const nodes = Array.isArray(d.nodes) ? d.nodes : [];
91
+ if (nodes.length) {
92
+ lines.push(` 任务链(${nodes.length} 节点):`);
93
+ for (const n of nodes) {
94
+ const tag = KIND_TAG[n.kind] || n.kind || '?';
95
+ const mark = n.current ? '●' : '○';
96
+ const att = n.attachmentCount ? ` 📎${n.attachmentCount}` : '';
97
+ lines.push(` ${mark} [${tag}] ${n.excerpt || '—'}${att}`);
98
+ }
99
+ }
90
100
  if (self.forkOf) {
91
101
  lines.push(` 派生自: ${self.forkOf}${self.forkKind ? `(${KIND_TAG[self.forkKind] || self.forkKind})` : ''}`);
92
102
  }
93
- if (d.ancestors.length) {
103
+ if (d.ancestors && d.ancestors.length) {
94
104
  lines.push(` 祖先链(${d.ancestors.length} 级):`);
95
105
  for (const a of d.ancestors) {
96
106
  lines.push(
@@ -100,7 +110,7 @@ function renderChain(d) {
100
110
  );
101
111
  }
102
112
  }
103
- if (d.children.length) {
113
+ if (d.children && d.children.length) {
104
114
  lines.push(` 子任务(${d.children.length} 条):`);
105
115
  for (const c of d.children) {
106
116
  lines.push(
@@ -109,8 +119,8 @@ function renderChain(d) {
109
119
  );
110
120
  }
111
121
  }
112
- if (!self.forkOf && !d.ancestors.length && !d.children.length) {
113
- lines.push(' (这条任务没有派生关联)');
122
+ if (!nodes.length && !self.forkOf && !(d.ancestors && d.ancestors.length) && !(d.children && d.children.length)) {
123
+ lines.push(' (这条任务还没有链节点)');
114
124
  }
115
125
  return lines.join('\n');
116
126
  }
@@ -225,13 +235,12 @@ export default {
225
235
  render: renderTask,
226
236
  },
227
237
  {
228
- // 任务链(#69):「评论生成新任务」「验收反馈重开」都派生新任务,链路存在
229
- // forkOf + forkKind。这里把一条任务的祖先链与全部子任务一次查清(跨主题)。
238
+ // 任务链(#74):同任务 history 节点(就地重开/评论)为主;旧 forkOf 祖先/子任务仍返回。
230
239
  id: 'localtask.chain',
231
240
  cli: ['localtask', 'chain'],
232
241
  http: ['GET', '/api/localtasks/chain'],
233
242
  summary:
234
- '查一条任务的派生链:祖先(forkOf 逐级上溯)+ 全部子任务(谁 fork 自它,跨主题);forkKind 区分 reopen(验收反馈)/ comment(划选评论)',
243
+ '查一条任务的链:history 节点(origin/reopen/comment/current)+ 旧 forkOf 祖先/子任务;面板点节点可旁路查看正文',
235
244
  flags: { id: { type: 'number', required: true, hint: '任务编号' }, cwd: CWD, key: KEY },
236
245
  run: (ctx) => service.taskChain({ id: ctx.id, cwd: ctx.cwd, key: ctx.key }),
237
246
  render: renderChain,
@@ -314,27 +323,39 @@ export default {
314
323
  render: renderPreview,
315
324
  },
316
325
  {
317
- // 修改反馈 / 重做 / 加评论 → **新建一条任务**(新的 md),旧任务**归档**。
318
- // 状态单向:完成等待验收之后没有回退边——不会回到「重新开始」(任务 #59)。
326
+ // 修改反馈 / 重做 / 划选评论 → **就地重开原任务**(#74),历史进 history 链。
319
327
  id: 'localtask.reopen',
320
328
  cli: ['localtask', 'reopen'],
321
329
  http: ['POST', '/api/localtasks/reopen'],
322
330
  summary:
323
- '重开任务(用户的修改反馈 / 重做 / 加评论):新建一条待领取任务(正文 = --text 给的内容),旧任务归档留档(状态单向,不回退)',
331
+ '重开任务(验收反馈 / 重做 / 评论):回写原任务正文,旧态压进 history;已完成则回到 pending 待再领',
324
332
  flags: {
325
333
  id: { type: 'number', required: true, hint: '任务编号' },
326
334
  cwd: CWD,
327
335
  key: KEY,
328
336
  text: { type: 'string', hint: '修改后的任务正文(Markdown);不给则只重开不改内容' },
337
+ kind: { type: 'string', hint: 'reopen(验收反馈,默认)或 comment(划选评论)' },
338
+ quote: { type: 'string', hint: '划选原文(comment 时)' },
339
+ feedback: { type: 'string', hint: '用户反馈原文(写入 history 节点)' },
329
340
  },
330
341
  run: async (ctx) => {
331
342
  // 重开也可能带着改过的归属(--text 的 frontmatter.project 变了)→ 同样搬家
332
343
  const { reopenTask } = await import('../tasktool/update.js');
333
- return reopenTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key, text: ctx.text });
344
+ return reopenTask({
345
+ id: ctx.id,
346
+ cwd: ctx.cwd,
347
+ key: ctx.key,
348
+ text: ctx.text,
349
+ kind: ctx.kind,
350
+ quote: ctx.quote,
351
+ feedback: ctx.feedback,
352
+ attachments: ctx.attachments,
353
+ });
334
354
  },
335
355
  render: (d) =>
336
- `已新建任务 #${d.id} @ ${d.name}(待领取)` +
337
- (d.from ? `;旧任务 #${d.from.id} 已归档留档` : '') +
356
+ `已重开 #${d.id} @ ${d.name}` +
357
+ (d.before?.completedAt ? '(已完成→待领取)' : '') +
358
+ (d.historyId != null ? `;链节点 #${d.historyId}` : '') +
338
359
  (d.moved && d.movedFrom ? `;已改归属项目,原 ${d.movedFrom.name} #${d.movedFrom.id}` : ''),
339
360
  },
340
361
  {
@@ -1,104 +1,178 @@
1
1
  // (#54 自 service.js 拆出)队列出口的任务生命周期:consumeFirstPending(D-first 领取,
2
2
  // 跳过被依赖/闸门挡住的 pending)、completeTask(完成门禁:timegoal 未到点返回 blocked
3
- // 业务值而不是抛错)、reopenTask(用户修改反馈 → **新建一条任务**,旧任务归档)。
3
+ // 业务值而不是抛错)、reopenTask(用户修改反馈 → **就地重开原任务**,历史进 history 链)。
4
4
  import { badInput, notFound } from '../../core/errors.js';
5
5
  import { formatDuration } from '../../core/instruction-template.js';
6
6
  import { preserveFrontmatter } from '../../shared/frontmatter.js';
7
7
  import { findFirstReadyPending } from './dag.js';
8
8
  import { basename } from 'node:path';
9
9
  import { isGlobalKey, resolveTaskKey, topicKeyFor } from './paths.js';
10
- import { loadStore, saveStore, stampNow, normalizeSummary, normalizeText, bumpWorkflowRevision, topicOf, nextTaskId } from './store-io.js';
10
+ import { loadStore, saveStore, stampNow, normalizeSummary, normalizeText, bumpWorkflowRevision } from './store-io.js';
11
11
  import { normalizeTask, foreignResolver, isPending } from './task-view.js';
12
12
  import { normalizeBlockBy } from './dag.js';
13
13
  import { markConsumed } from './waiters.js';
14
- // 把一条任务重新开放(用户的**修改反馈** / 重做 / 加评论)。
14
+
15
+ /** 下一条 history 节点编号(任务内自增) */
16
+ function nextHistoryId(history) {
17
+ let max = 0;
18
+ for (const h of history || []) {
19
+ const n = Number(h && h.id) || 0;
20
+ if (n > max) max = n;
21
+ }
22
+ return max + 1;
23
+ }
24
+
25
+ /** 把当前任务态压成一条 history 节点(就地重开前留档) */
26
+ function snapshotNode(task, { kind, quote, feedback, attachments } = {}) {
27
+ const excerpt =
28
+ String(task.text ?? '')
29
+ .split('\n')
30
+ .map((l) => l.trim())
31
+ .find(Boolean) || '';
32
+ return {
33
+ id: nextHistoryId(task.history),
34
+ kind: kind === 'comment' ? 'comment' : kind === 'origin' ? 'origin' : 'reopen',
35
+ at: stampNow(),
36
+ text: String(task.text ?? ''),
37
+ summary: String(task.roundSummary ?? ''),
38
+ status: String(task.status || 'pending'),
39
+ completedAt: String(task.completedAt ?? ''),
40
+ quote: String(quote ?? ''),
41
+ feedback: String(feedback ?? ''),
42
+ attachments: Array.isArray(attachments)
43
+ ? attachments
44
+ .filter((a) => a && typeof a === 'object')
45
+ .map((a) => ({
46
+ id: String(a.id || ''),
47
+ name: String(a.name || ''),
48
+ type: a.type === 'image' ? 'image' : 'file',
49
+ size: String(a.size || ''),
50
+ url: a.url ? String(a.url) : '',
51
+ }))
52
+ : [],
53
+ excerpt: excerpt.replace(/^#+\s*/, '').slice(0, 100),
54
+ };
55
+ }
56
+
57
+ // 把一条任务重新开放(用户的**修改反馈** / 重做 / 划选评论)。
15
58
  //
16
- // 语义(任务 #59):**新建一条任务**(新的 md),旧任务**归档**——状态只往前。
17
- // - 旧任务:状态前进到终态 archived,正文、完成总结、领取记录**一个字都不动**(留档);
18
- // 它不会再回到「重新开始」,也就没有「完成等待验收 → 重新开始」这条回退边。
19
- // - 新任务:正文 = 调用方拼好的(面板口径:原正文 + 上一轮完成总结 + 本轮反馈),
20
- // forkOf 指回上一条('队列key:旧编号'),supersededBy 记在旧任务上。
21
- // - 落点:默认同主题;带改过归属(moveTo)就落那边——归属决定落点。
59
+ // 语义(任务 #74):**就地重开原任务**——同一编号、同一 md,不新建队列行。
60
+ // - 旧态压进 `history[]`(可追链、可点开旁路查看)
61
+ // - 正文 = 调用方拼好的(面板口径:原正文 + 上一轮完成总结 + 本轮反馈)
62
+ // - 清领取/完成标记,状态回到 pending,等再领(同号继续)
63
+ // - 落点:默认同主题;带改过归属(moveTo)就搬整条任务
22
64
  //
23
- // 为什么不再「就地改同一条、把状态翻回 pending」:
24
- // 1. 那是**回退边**——完成等待验收的任务被拉回重新开始,历史被抹掉;
25
- // 2. 就地改写会覆盖旧正文——上轮做过什么、用户评了什么,都被新正文吃掉;
26
- // 3. 现在链条可追:旧任务留档、新任务指回它,状态机 pending → consumed → archived。
27
- export async function reopenTask({ cwd: rawCwd, key: rawKey, id, text, moveTo } = {}) {
65
+ // 对比 #59「新建 md + 归档」:那会把同一件活拆成多条待领,验收/评论闭环断在新号上;
66
+ // #74 要求 ack 与评论统一回写原任务,历史用链可视化而不是多条归档任务。
67
+ export async function reopenTask({
68
+ cwd: rawCwd,
69
+ key: rawKey,
70
+ id,
71
+ text,
72
+ moveTo,
73
+ kind: rawKind,
74
+ quote,
75
+ feedback,
76
+ attachments,
77
+ } = {}) {
28
78
  const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
29
79
  const want = Number(id);
30
80
  if (!Number.isFinite(want) || want <= 0) throw badInput('缺少参数 --id <任务编号>');
31
81
  const store = await loadStore();
32
82
  const t = store.topics[key];
33
83
  if (!t) throw notFound('主题不存在: ' + key);
34
- const old = t.tasks.find((x) => Number(x.id) === want);
35
- if (!old || old.deletedAt) throw notFound('任务不存在或已删除: #' + want);
36
- if (old.status === 'archived') {
84
+ const task = t.tasks.find((x) => Number(x.id) === want);
85
+ if (!task || task.deletedAt) throw notFound('任务不存在或已删除: #' + want);
86
+ // 旧口径(#59)归档的 superseded 任务仍拒绝——那是被新号取代的残留,不是本条活。
87
+ if (task.status === 'archived') {
37
88
  throw badInput(`#${want} 已归档(被新任务取代)——不能再重开;要继续做请新建任务`);
38
89
  }
39
- const before = { status: old.status, consumedAt: old.consumedAt || '', completedAt: old.completedAt || '' };
90
+
91
+ const kind = rawKind === 'comment' ? 'comment' : 'reopen';
92
+ const before = {
93
+ status: task.status,
94
+ consumedAt: task.consumedAt || '',
95
+ completedAt: task.completedAt || '',
96
+ roundSummary: task.roundSummary || '',
97
+ };
98
+
99
+ if (!Array.isArray(task.history)) task.history = [];
100
+ // 首次重开:先落一条 origin,把「改之前」的正文留住(后续节点只记事件态)。
101
+ if (task.history.length === 0) {
102
+ task.history.push(snapshotNode(task, { kind: 'origin' }));
103
+ }
104
+
40
105
  const body = String(text ?? '').trim();
106
+ if (body) {
107
+ task.text = preserveFrontmatter(task.text, normalizeText(body));
108
+ }
109
+
110
+ // 本轮事件节点:记反馈/选区/附件;text 取**更新后**的正文(旁路点开即这一轮交付形态)
111
+ const node = snapshotNode(task, {
112
+ kind,
113
+ quote,
114
+ feedback: feedback || '',
115
+ attachments,
116
+ });
117
+ // origin 已占「改前」;事件节点用更新后正文,避免与 origin 完全重复时仍要能看反馈字段
118
+ task.history.push(node);
119
+
120
+ // 重开 = 重新进入待领取:清领取/完成标记,让 get/wait 能再领到同一条。
121
+ // (划选评论也走此入口——反馈已写进正文,下一轮 agent 从同号再领。)
122
+ task.status = 'pending';
123
+ task.consumedAt = '';
124
+ task.completedAt = '';
125
+ task.roundSummary = '';
126
+ task.claimedFrom = '';
127
+ task.claimedBy = '';
128
+ task.claimedByName = '';
41
129
 
42
- // 落点:默认同主题;带改过归属(moveTo)就落那边——归属决定落点。
130
+ task.reopenCount = (Number(task.reopenCount) || 0) + 1;
131
+ task.lastReopenedAt = stampNow();
132
+ // 链上的「当前尖」语义:forkKind 记最近一次事件种类(兼容旧 chain 查询展示)
133
+ task.forkKind = kind;
134
+
135
+ // 落点:默认同主题;带改过归属(moveTo)就搬整条。
43
136
  let host = t;
44
137
  let moved = false;
45
138
  let movedFrom = null;
46
139
  if (moveTo && moveTo.cwd) {
47
140
  const toKey = topicKeyFor(basename(String(moveTo.cwd)));
48
141
  if (toKey !== t.key) {
49
- host = topicOf(store, toKey, moveTo.cwd, moveTo.name || '');
50
- moved = true;
51
- movedFrom = { key, name: t.name, id: want };
142
+ const { relocateInStore } = await import('./task-view.js');
143
+ const relocated = relocateInStore(store, t, task, moveTo);
144
+ if (relocated) {
145
+ host = relocated.topic;
146
+ moved = true;
147
+ movedFrom = { key, name: t.name, id: want };
148
+ }
52
149
  }
53
150
  }
54
151
 
55
- // 新任务:正文用调用方拼好的(面板口径 = 原正文 + 上一轮完成总结 + 本轮反馈);
56
- // 没给正文就沿用旧正文(只归档、不改内容)。
57
- const newId = nextTaskId(host.tasks);
58
- const forked = normalizeTask({
59
- id: newId,
60
- text: body ? preserveFrontmatter(old.text, normalizeText(body)) : old.text,
61
- status: 'pending',
62
- createdAt: stampNow(),
63
- forkOf: `${key}:${want}`,
64
- forkKind: 'reopen', // 验收反馈 / 重做派生(#69 任务链;评论派生是 addTask 的 'comment')
65
- // 同一件活,约束也接着走:
66
- // timegoal 时间目标继承——新任务从**再次领取**开始重新计时(与旧口径一致)
67
- // blocksFollowing 闸门继承——旧任务归档后不再挡人,闸门得由新任务接着当
68
- // blockBy 上游依赖继承(去掉指向自己的那条)
69
- timegoal: old.timegoal || null,
70
- blocksFollowing: !!old.blocksFollowing,
71
- blockBy: normalizeBlockBy(old.blockBy, newId),
72
- });
73
- host.tasks.push(forked);
74
-
75
- // 旧任务:**前进**到终态(归档)。正文与完成总结一个字都不动——留档。
76
- old.status = 'archived';
77
- old.archivedAt = stampNow();
78
- old.archivedReason = 'superseded';
79
- old.supersededBy = { key: host.key, id: newId };
80
- old.reopenCount = (Number(old.reopenCount) || 0) + 1;
81
- old.lastReopenedAt = stampNow();
152
+ // blockBy 仍指向自己时清掉(编号没变,一般不会;搬家后仍校验一次)
153
+ task.blockBy = normalizeBlockBy(task.blockBy, Number(task.id));
82
154
 
83
155
  host.updatedAt = stampNow();
84
156
  bumpWorkflowRevision(host);
85
157
  if (host !== t) bumpWorkflowRevision(t);
86
158
  await saveStore(store);
159
+
87
160
  return {
88
161
  status: 'ok',
89
162
  reopened: true,
90
- forked: true,
91
- id: newId, // 新任务编号(面板据此切到新的 md)
163
+ forked: false, // #74:不再新建
164
+ id: Number(task.id),
92
165
  key: host.key,
93
166
  name: host.name,
94
167
  before,
95
- from: { key, id: want }, // 上一条(已归档)
168
+ kind,
169
+ historyId: node.id,
96
170
  moved,
97
171
  movedFrom,
98
- task: normalizeTask(forked, host.tasks),
99
- archived: normalizeTask(old, t.tasks),
172
+ task: normalizeTask(task, host.tasks),
100
173
  };
101
174
  }
175
+
102
176
  // 取走该主题第一条 pending;没有则返回 null。roundSummary 显式指定本轮完成总结,
103
177
  // 缺省回落到主题当前 summary(等待中即本轮现状)。
104
178
  // by = 领取方身份 {key,name,cwd}(wait 传入),用于记领取审计。
@@ -227,4 +301,3 @@ export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawS
227
301
  //
228
302
  // (goal 探针与目标上下文已随 wait 编排迁往 tasktool/wait.js——任务工具语义归
229
303
  // tasktool,队列本体不再依赖 timegoal 模块。)
230
-
@@ -96,8 +96,8 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
96
96
  const base = {
97
97
  id: Number(t.id) || 0,
98
98
  text: String(t.text ?? ''),
99
- // 状态词汇:pending → consumed(已领取)→ archived(终态:被新任务取代)。
100
- // **单向**:没有回退边——完成等待验收之后只能往前(归档),不能回 pending(#59)。
99
+ // 状态词汇:pending → consumed(已领取);完成验收后可就地回 pending(#74)。
100
+ // archived 仍保留给旧口径(#59 fork 取代)的残留行,不再由 reopen 写入。
101
101
  status: t.status === 'consumed' ? 'consumed' : t.status === 'archived' ? 'archived' : 'pending',
102
102
  roundSummary: String(t.roundSummary ?? ''),
103
103
  createdAt: String(t.createdAt ?? ''),
@@ -123,11 +123,12 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
123
123
  timegoal: sanitizeTaskGoal(t.timegoal),
124
124
  // 完成标记(localtask done 写入):带时间目标的任务未到点会被拒绝,写不进来。
125
125
  completedAt: String(t.completedAt ?? ''),
126
- // 重开轨迹:现在重开 = **新建一条任务**,旧任务归档(#59)。
127
- // forkOf 这条是从哪一条派生的('队列key:旧编号')
128
- // forkKind 派生种类(#69 任务链):reopen=验收反馈/重做;comment=面板划选评论生成
129
- // supersededBy 被哪一条取代(归档那条的落点:{ key, id })
130
- // archivedAt / archivedReason 归档时刻与原因
126
+ // 重开轨迹(#74):就地重开,历史进 history[];forkOf 仅兼容旧 #59/#69 派生数据。
127
+ // history 同任务内的链节点(origin / reopen / comment),点开可旁路查看
128
+ // forkOf 旧派生链('队列key:旧编号')——新 reopen 不再写
129
+ // forkKind 最近一次事件种类(reopen / comment),或旧派生种类
130
+ // supersededBy / archived* 旧归档残留字段
131
+ history: normalizeHistory(t.history),
131
132
  forkOf: String(t.forkOf ?? ''),
132
133
  forkKind: t.forkKind === 'reopen' || t.forkKind === 'comment' ? t.forkKind : '',
133
134
  supersededBy: t.supersededBy && typeof t.supersededBy === 'object' ? t.supersededBy : null,
@@ -227,11 +228,50 @@ export function topicView(t, repoCtx = null, readyOpts = {}) {
227
228
  }
228
229
 
229
230
  // ─── 任务链(#69) ────────────────────────────────────────────────────
230
- // 「面板划选评论生成新任务」与「验收反馈重开」都会**派生新任务**;链路结构统一存在
231
- // forkOf('队列key:编号')+ forkKind(reopen / comment)。三个原语:
231
+ /** 规范化任务内 history 链(#74)。非法项丢弃,顺序保留。 */
232
+ export function normalizeHistory(raw) {
233
+ if (!Array.isArray(raw)) return [];
234
+ const out = [];
235
+ for (const h of raw) {
236
+ if (!h || typeof h !== 'object') continue;
237
+ const kind = h.kind === 'comment' || h.kind === 'origin' ? h.kind : 'reopen';
238
+ const attachments = Array.isArray(h.attachments)
239
+ ? h.attachments
240
+ .filter((a) => a && typeof a === 'object')
241
+ .map((a) => ({
242
+ id: String(a.id || ''),
243
+ name: String(a.name || ''),
244
+ type: a.type === 'image' ? 'image' : 'file',
245
+ size: String(a.size || ''),
246
+ url: a.url ? String(a.url) : '',
247
+ }))
248
+ : [];
249
+ out.push({
250
+ id: Number(h.id) || out.length + 1,
251
+ kind,
252
+ at: String(h.at ?? ''),
253
+ text: String(h.text ?? ''),
254
+ summary: String(h.summary ?? ''),
255
+ status: String(h.status ?? ''),
256
+ completedAt: String(h.completedAt ?? ''),
257
+ quote: String(h.quote ?? ''),
258
+ feedback: String(h.feedback ?? ''),
259
+ attachments,
260
+ excerpt: String(h.excerpt ?? '')
261
+ .replace(/^#+\s*/, '')
262
+ .slice(0, 100),
263
+ });
264
+ }
265
+ return out;
266
+ }
267
+
268
+ // 任务链两套来源(#74 / 兼容 #69):
269
+ // history[] —— 同任务内就地重开/评论节点(主路径)
270
+ // forkOf 派生 —— 旧「新建任务」链(祖先 + 子任务)
271
+ // 三个原语:
232
272
  // resolveForkRef —— 发布侧:裸数字(同主题)/'key:id'(跨主题)规范化 + 验证父任务存在
233
273
  // forkRow —— 按引用取行(内部;软删/迁出不算存在)
234
- // taskChain —— 查询侧:一条任务的祖先链 + 全部子任务(跨主题扫 forkOf)
274
+ // taskChain —— 查询侧:history 节点 + 祖先链 + 子任务
235
275
 
236
276
  function forkRow(store, ref) {
237
277
  const m = /^(.+):(\d+)$/.exec(String(ref || ''));
@@ -280,7 +320,7 @@ function chainLite(topic, t) {
280
320
  };
281
321
  }
282
322
 
283
- /** 任务链查询:祖先链(forkOf 逐级上溯)+ 全部子任务(谁 fork 自它,跨主题)。 */
323
+ /** 任务链查询:同任务 history 节点 + 旧 forkOf 祖先/子任务。 */
284
324
  export async function taskChain({ id, cwd, key } = {}) {
285
325
  const k = resolveTaskKey({ key, cwd });
286
326
  const want = Number(id);
@@ -290,6 +330,41 @@ export async function taskChain({ id, cwd, key } = {}) {
290
330
  if (!t) throw notFound('主题不存在: ' + k);
291
331
  const self = (t.tasks || []).find((x) => Number(x.id) === want && !x.deletedAt && !x.migratedTo);
292
332
  if (!self) throw notFound('任务不存在或已删除: #' + want);
333
+
334
+ const history = normalizeHistory(self.history);
335
+ // nodes:history 按时间序 + 当前尖(live)。面板链图只吃这一列。
336
+ const nodes = history.map((h) => ({
337
+ historyId: h.id,
338
+ kind: h.kind,
339
+ at: h.at,
340
+ excerpt: h.excerpt || h.feedback?.slice(0, 100) || '',
341
+ feedback: h.feedback,
342
+ quote: h.quote,
343
+ summary: h.summary,
344
+ status: h.status,
345
+ completedAt: h.completedAt,
346
+ attachmentCount: (h.attachments || []).length,
347
+ current: false,
348
+ }));
349
+ const tipExcerpt =
350
+ String(self.text ?? '')
351
+ .split('\n')
352
+ .map((l) => l.trim())
353
+ .find(Boolean) || '';
354
+ nodes.push({
355
+ historyId: null,
356
+ kind: 'current',
357
+ at: String(self.lastReopenedAt || self.createdAt || ''),
358
+ excerpt: tipExcerpt.replace(/^#+\s*/, '').slice(0, 100),
359
+ feedback: '',
360
+ quote: '',
361
+ summary: String(self.roundSummary || ''),
362
+ status: self.status,
363
+ completedAt: String(self.completedAt || ''),
364
+ attachmentCount: 0,
365
+ current: true,
366
+ });
367
+
293
368
  // 祖先链:visited 防环;上限 32(这是条链不是树,合理深度远小于它——超限即数据异常)
294
369
  const ancestors = [];
295
370
  const seen = new Set([`${k}:${want}`]);
@@ -306,7 +381,7 @@ export async function taskChain({ id, cwd, key } = {}) {
306
381
  ancestors.push(chainLite(row.topic, row.task));
307
382
  cur = String(row.task.forkOf || '');
308
383
  }
309
- // 子任务:派生落点可能换主题(reopen 带 moveTo / 评论跨队列),所以全 store 扫
384
+ // 子任务:派生落点可能换主题(旧 reopen 带 moveTo / 评论跨队列),所以全 store 扫
310
385
  const ref = `${k}:${want}`;
311
386
  const children = [];
312
387
  for (const topic of Object.values(store.topics)) {
@@ -322,6 +397,8 @@ export async function taskChain({ id, cwd, key } = {}) {
322
397
  name: t.name,
323
398
  id: want,
324
399
  task: normalizeTask(self, t.tasks),
400
+ nodes,
401
+ history,
325
402
  ancestors,
326
403
  children,
327
404
  };