nx-kv 0.42.3 → 0.43.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 (76) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +1 -1
  3. package/assets/kv-get/SKILL.md +4 -4
  4. package/assets/kv-get/references/localget.md +2 -2
  5. package/package.json +1 -1
  6. package/src/core/attachmentdb/docs.js +12 -0
  7. package/src/core/attachmentdb/relations.js +17 -0
  8. package/src/core/attachmentdb.js +1 -0
  9. package/src/modules/docs/attach.js +46 -1
  10. package/src/modules/docs/brief.js +35 -4
  11. package/src/modules/docs/index.js +15 -1
  12. package/src/modules/docs/service.js +10 -6
  13. package/src/modules/localtask/action-attach.js +25 -0
  14. package/src/modules/localtask/action-flags.js +0 -1
  15. package/src/modules/localtask/action-lifecycle.js +6 -4
  16. package/src/modules/localtask/action-waiting.js +3 -3
  17. package/src/modules/localtask/repo/rows.js +3 -0
  18. package/src/modules/localtask/repo/tasks.js +18 -2
  19. package/src/modules/localtask/task-lifecycle.js +3 -3
  20. package/src/modules/localtask/task-view.js +14 -6
  21. package/src/modules/tasktool/attach-resource.js +3 -0
  22. package/src/modules/tasktool/attach.js +62 -0
  23. package/src/modules/tasktool/get.js +1 -2
  24. package/src/modules/tasktool/plugins/waitgoal-config.js +1 -1
  25. package/src/modules/tasktool/wait.js +2 -2
  26. package/src/shared/doc-title.js +71 -0
  27. package/src/web/frontend/components/md/attach-area.jsx +56 -6
  28. package/src/web/frontend/components/md/attach-common.js +16 -3
  29. package/src/web/frontend/components/md/attach-modal.jsx +42 -2
  30. package/src/web/frontend/components/md/md-panes-helpers.js +4 -1
  31. package/src/web/frontend/components/repos/get-loop-modal.jsx +1 -1
  32. package/src/web/frontend/components/task-panel/layout.jsx +64 -0
  33. package/src/web/frontend/components/task-panel/page-shell.jsx +38 -0
  34. package/src/web/frontend/components/tool-acts/modules.js +2 -0
  35. package/src/web/frontend/modules/md/md-render.js +34 -11
  36. package/src/web/frontend/modules/md/progress-chain.js +29 -0
  37. package/src/web/frontend/modules/md/progress-search.js +14 -0
  38. package/src/web/frontend/modules/md/styles/chrome.css +9 -0
  39. package/src/web/frontend/modules/md/styles/panels.css +2 -0
  40. package/src/web/frontend/modules/md/styles/shell.css +2 -10
  41. package/src/web/frontend/page/dir/index.jsx +8 -5
  42. package/src/web/frontend/page/dir/landing.jsx +92 -99
  43. package/src/web/frontend/page/dir/task.jsx +19 -3
  44. package/src/web/frontend/page/doc/index.jsx +24 -12
  45. package/src/web/frontend/page/group/index.jsx +145 -68
  46. package/src/web/frontend/page/progress/index.jsx +67 -19
  47. package/src/web/frontend/styles-v2/views.css +5 -1
  48. package/src/web/public/assets/Introduction-DAXj7E6q.js +6 -0
  49. package/src/web/public/assets/{bar-C0LZwZoX.js → bar-KTPTE33i.js} +1 -1
  50. package/src/web/public/assets/{cloud-ol3se4zn.js → cloud-CLco1knr.js} +1 -1
  51. package/src/web/public/assets/{composer-panel-O04Eac_2.js → composer-panel-D3N_wO9r.js} +1 -1
  52. package/src/web/public/assets/deleted-panel-B6sZddUs.js +1 -0
  53. package/src/web/public/assets/dir-DEbQhSfL.js +5 -0
  54. package/src/web/public/assets/group-CxqVtyyh.js +2 -0
  55. package/src/web/public/assets/index-DGvBoOdp.css +1 -0
  56. package/src/web/public/assets/{index-BAS6Qpjs.js → index-DNB8tgNi.js} +2 -2
  57. package/src/web/public/assets/md-history-C9vOgGLz.js +39 -0
  58. package/src/web/public/assets/{overview-CIeUo4At.js → overview-9nXafXeK.js} +1 -1
  59. package/src/web/public/assets/progress-Bx0reVYl.js +3 -0
  60. package/src/web/public/assets/{refs-BpET-Lxl.js → refs-B5YIZ9SG.js} +1 -1
  61. package/src/web/public/assets/{repos-K67Ie07A.js → repos-Dbr-i-gg.js} +2 -2
  62. package/src/web/public/assets/{route-crumb-B7T_Hupr.js → route-crumb-BfRi1GKw.js} +1 -1
  63. package/src/web/public/assets/{settings-Bek4c_r_.js → settings-B4FvZtu0.js} +1 -1
  64. package/src/web/public/assets/{status-tag-B7CrVhQP.js → status-tag-p3fo3Hbr.js} +1 -1
  65. package/src/web/public/assets/{task-DHca1uMu.js → task-CUb7dohw.js} +3 -3
  66. package/src/web/public/assets/{templates-6moKn9GB.js → templates-BGhPIp0x.js} +1 -1
  67. package/src/web/public/assets/tool-bar-DpwpQ47h.js +1 -0
  68. package/src/web/public/index.html +2 -2
  69. package/src/web/public/assets/Introduction--ILYt-bQ.js +0 -1
  70. package/src/web/public/assets/dir-B_HW1kpE.js +0 -5
  71. package/src/web/public/assets/group-BCOXDlvk.js +0 -1
  72. package/src/web/public/assets/index-CZzMw1zg.css +0 -1
  73. package/src/web/public/assets/md-history-DCgN2zcc.js +0 -39
  74. package/src/web/public/assets/progress-DHDlz9O9.js +0 -3
  75. package/src/web/public/assets/task-row-W12GJMCO.js +0 -1
  76. package/src/web/public/assets/tool-bar-CDUi6q4z.js +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,71 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.43.0] - 2026-11-10 任务面板统一 + 进程链折叠 + 文档绑定收口
6
+
7
+ ### Removed
8
+
9
+ - **取消两个没有界面入口的命令行参数(#171)**:
10
+ - `localtask done --progress`(完成度/下一步)——面板上没有对应输入界面;
11
+ - `localtask get` / `localtask wait --summary`(当前现状)——同上,且队列现状
12
+ 早已不在面板上展示(上轮删掉了「路径 + 现状」行)。
13
+ 两个参数**保留 flag 但不再生效**(传了也不写库、不进 ctx)——直接删掉会让
14
+ 已安装的 skill 与在跑的旧调用报「未知参数」而中断。
15
+ `done --summary`(完成总结)与 `timegoal check --summary/--progress`(日志内容,
16
+ 面板上有展示)**保留**。同步更新:action 声明、service/tasktool 实现、内置
17
+ skill(kv-get)、README / docs 示例、持续 get 默认模板文案与前端弹窗文案。
18
+
19
+ ### Changed
20
+
21
+ - **任务面板页布局整块抽成共享组件(#170)**:新增
22
+ `components/task-panel/layout.jsx`(TaskPanelLayout)——整页骨架同源:头部
23
+ (图标 + 名字 + 计数 chips + 右对齐动作区)→ 简介 → 批量条 → 任务列表 → 翻页,
24
+ 块序与间距由组件定。**路由与数据语义各自保留**(组页 = 多条成员 topic 的视图,
25
+ 目录页 = 一条 topic 的视图),两页只往槽位里放各自的内容与动作。
26
+ - **目录落地页不再套 MD 工作台外壳(#170)**:`.mdw` 是编辑器外壳(自带 canvas
27
+ 米色底 + 一整套 `.mdw` 作用域的按钮/字号口径)。落地页只是队列列表页,套上它
28
+ 导致**同款按钮在目录页与项目组页呈现两套观感**、页面底色也不同——落地页与
29
+ 项目组页现在同底色同观感(编辑器分支仍用 `.mdw`)。
30
+ - **`.btn.ghost` 全站统一观感(#170)**:v1 的 `.btn.ghost{background:var(--soft)}`
31
+ 与 `.mdw .btn.ghost`(透明/浅边/中灰字)两套并存,同一个按钮类在不同页面
32
+ 呈现灰底或透明两种观感——现在定一份全局口径(透明底 + 浅边 + 中灰字),
33
+ 与 md 编辑器内一致。
34
+ - **进程面板折叠反馈链旧轮次(#172)**:反馈任务链动辄几十轮,此前进程面板把
35
+ 链上每一轮都**累计**摊开,读重复内容太费劲。现在面板只留**链尖**(最新一轮),
36
+ 被下一轮取代的旧轮次不再占屏——旧轮次去任务页「更多 → 任务链」里看;面板底部
37
+ 说明如实标注折叠了多少条。判据是 reopen 边数(新视图字段 `childRoundCount`):
38
+ 评论派生 / 反馈新需求(comment 边)是**旁支新活**,父任务照旧显示、不折叠。
39
+ 编号精确查询(如 `87` / `#87`)仍能把折叠的旧轮次**点名召回**(卡片带「旧轮次」
40
+ 标记);标题模糊与编号前缀命中不召回——一召回就又把几十条旧轮次堆回屏上。
41
+ - **任务链节点标注链边类型(#172 顺带)**:`localtask chain` 与面板「任务链」
42
+ 弹窗的节点现在从 task_links **边**上取类型——反馈轮次显示「反馈」、评论派生
43
+ 显示「评论」;此前任务行上的旧 `forkKind` 字段多半为空,链上每一格都显示成
44
+ 「起点」,看不出哪轮是反馈、哪条是评论旁支。
45
+
46
+ ### Fixed
47
+
48
+ - **文档标题口径统一(#168)**:标题 = 正文**首行**的 `# 标题`——此前有三套口径在打架
49
+ (「任意位置的首个 # 行」会被正文中间的标题带偏、「首个非空行」会让**正文第一行顶替
50
+ 标题」),文档页 / docs 列表 / 附件清单 / 项目简介现在同一口径(新增
51
+ `shared/doc-title.js`,前后端共用)。改标题一律改写首行(首行不是 # 就补到文首),
52
+ frontmatter 原样保留。
53
+ - **ref 引用在 md 编辑器里显示文档标题(#168)**:用户在文档里填了标题后,附件区与
54
+ 正文里的 `nxkv://ref/…` 引用此前只显示文件名——服务端读盘补出标题(附件清单带
55
+ `docTitle`),渲染层按 refId 查表替换链接文字。
56
+ - **面板挂文档到任务此前必然失败(两处坏点,#162)**:任务侧 action 收 `ref` 而面板
57
+ 一直发 `doc`(未知键透传,服务端收不到文档);面板给的 `rel:`/`path:` 前缀 locator
58
+ 与 refs 索引的裸相对路径对不上——现在请求体按宿主分字段,后端解析额外按剥前缀后的
59
+ locator 再查一次。
60
+
61
+ ### Added
62
+
63
+ - **面板文档绑定的「说明」与「进原文」(#162 的 UI 收口)**:添加附件弹窗里文档条目可填
64
+ 一行说明(desc,随边落库、交付清单透出)并勾「进原文」(交付带全文,与 CLI
65
+ `--note`/`--inline` 同口径)。
66
+ - **已挂载绑定的「✎ 说明 / ⇄ 更换」(#168)**:附件区的文档条目可直接改说明
67
+ (新增 `localtask attach-note` / `docs attach-note`,只动说明不改角色),也可把绑定
68
+ 换成另一篇文档(换指向时沿用原说明)。
69
+
5
70
  ## [0.42.3] - 2026-11-10 组任务面板分页 + 两页彻底同构
6
71
 
7
72
  ### Changed
package/README.md CHANGED
@@ -168,7 +168,7 @@ remove-many`)。阻塞等待弹窗只是 `wait` 当前的一个子功能。三
168
168
 
169
169
  ```bash
170
170
  # 等待侧:每完成一步、提交结果后【必须】调 wait 领新任务(循环只有 timeout 才终止)
171
- nx-kv localtask wait --summary "<当前现状总结>" --json
171
+ nx-kv localtask wait --json
172
172
  # 队列非空 → 立即取走(queued:true);空 → 开窗阻塞,默认 180 秒未回填 → {status:"timeout"}(exit 0)
173
173
 
174
174
  # 提交侧:把提炼好的任务投进目标目录的队列,委托在那边工作的 agent
@@ -17,8 +17,8 @@ description: 领取与完成排给本工作目录的本地任务(别人通过
17
17
 
18
18
  | 动作 | 命令 | 语义 |
19
19
  | --- | --- | --- |
20
- | **领活** | `nx-kv localtask get --summary "<现状>" --json` | 队列有任务**立即领走**;没有就**立即返回 timeout**(不阻塞、不开窗)——「暂时没活」是正常业务结果 |
21
- | **等人** | `nx-kv localtask wait --summary "<现状>" --timeout 30 --json` | 阻塞等人回填;**本轮最后一步**,唯一合法出口是 timeout |
20
+ | **领活** | `nx-kv localtask get --json` | 队列有任务**立即领走**;没有就**立即返回 timeout**(不阻塞、不开窗)——「暂时没活」是正常业务结果 |
21
+ | **等人** | `nx-kv localtask wait --timeout 30 --json` | 阻塞等人回填;**本轮最后一步**,唯一合法出口是 timeout |
22
22
  | **挂着领** | 同上,但项目开启了「持续 get」 | `get` 升级为 waitgoal:无任务时**阻塞等待**项目配置的分钟数,期间用户回填就直接领到;领到的交付文本自带「继续 get 直到超时」的项目模板 |
23
23
 
24
24
  「持续 get」是**项目级**开关(`repo update --get-loop on` 开启),默认关闭——默认就是「直接 get」。
@@ -26,7 +26,7 @@ description: 领取与完成排给本工作目录的本地任务(别人通过
26
26
  ## 领取到的东西必须读全
27
27
 
28
28
  ```bash
29
- nx-kv localtask get --summary "<本轮现状>" --json
29
+ nx-kv localtask get --json
30
30
  # → { status:"ok", task:{id,text,...}, instruction:"…" }
31
31
  ```
32
32
 
@@ -69,7 +69,7 @@ nx-kv localtask done --id <n> --summary "<完成总结>" --json
69
69
 
70
70
  ```bash
71
71
  # 标记完成(完成总结必填——它就是下一轮 agent 能看到的「上轮做了什么」)
72
- nx-kv localtask done --id <n> --summary "<完成总结>" [--progress "<完成度/下一步>"]
72
+ nx-kv localtask done --id <n> --summary "<完成总结>"
73
73
 
74
74
  # 用户看了结果提修改意见 → **就地重开原任务**(同号回写,旧态压进 history)
75
75
  nx-kv localtask reopen --id <n> [--text "<改后的正文(Markdown)>"] [--kind reopen|comment] --json
@@ -17,11 +17,11 @@ nx-kv localtask list --json
17
17
  # → {topics:[{key,cwd,name,summary,waiting,pending,total,tasks:[...]}], waiting, settings}
18
18
 
19
19
  # 2. 有待领取 → 取走最早的一条(默认「直接 get」:队列非空立即返回,不开窗不阻塞)
20
- nx-kv localtask get --summary "<本轮现状,如:空闲,领取新任务>" --json
20
+ nx-kv localtask get --json
21
21
  # → {status:"ok", queued:true, task:{id,text,...}}
22
22
 
23
23
  # 2b. 想挂着等活(阻塞等人回填)→ 用 wait(kv-waittask 的循环契约)
24
- nx-kv localtask wait --summary "<本轮现状>" --timeout 30 --json
24
+ nx-kv localtask wait --timeout 30 --json
25
25
 
26
26
  # 3. 执行 task.text(内容永远读 task.text,id 只是编号),产出落在本目录
27
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.42.3",
3
+ "version": "0.43.0",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -7,6 +7,10 @@ import { syncRefAttachments, syncTaskAttachments } from './relations.js';
7
7
  /**
8
8
  * 把一个「文档标识」解析成 refs.id:先按 id,再按 locator(原样 / 反斜杠归一),
9
9
  * 都没有返回 null。CLI `--ref` 与面板选择器共用这一条,避免各自猜地址语法。
10
+ *
11
+ * **docId 前缀也认**(#165 二轮:面板选择器给的是 `rel:` / `path:` 形式,
12
+ * 而 refs.locator 存的是裸相对路径 / 绝对路径——不剥前缀就永远匹配不上,
13
+ * 面板「给任务挂文档」直接失败)。故额外按「剥前缀后的 locator」再查一次。
10
14
  */
11
15
  export function resolveRefId(conn, input) {
12
16
  const raw = String(input || '').trim();
@@ -18,6 +22,14 @@ export function resolveRefId(conn, input) {
18
22
  'SELECT id FROM refs WHERE locator = :loc AND deleted_at IS NULL', { loc }
19
23
  );
20
24
  if (byLoc) return byLoc.id;
25
+ // docId 形态(rel:xxx / path:xxx)→ 剥前缀按 locator 再查
26
+ const stripped = /^rel:|^path:/i.test(loc) ? loc.replace(/^rel:|^path:/i, '') : '';
27
+ if (stripped) {
28
+ const byStripped = conn.get(
29
+ 'SELECT id FROM refs WHERE locator = :loc AND deleted_at IS NULL', { loc: stripped }
30
+ );
31
+ if (byStripped) return byStripped.id;
32
+ }
21
33
  const derived = refIdFor(loc);
22
34
  const byDerived = conn.get('SELECT id FROM refs WHERE id = :id AND deleted_at IS NULL', { id: derived });
23
35
  return byDerived ? byDerived.id : null;
@@ -89,6 +89,23 @@ export function linkAttachment(conn, {
89
89
  return role;
90
90
  }
91
91
 
92
+ /**
93
+ * 改一条关系上的说明(desc,#168):面板里给已挂载的文档绑定补/改说明。
94
+ * 只动 note,不动 role/position——角色是「这条边是什么」,说明是「它讲什么」。
95
+ * @returns {number} 受影响行数(0 = 没有这条边)
96
+ */
97
+ export function updateAttachmentNote(conn, { host, hostId, attachmentId, note = '' } = {}) {
98
+ const h = hostOf(host);
99
+ const hostVal = host === 'task' ? Number(hostId) : String(hostId || '');
100
+ const att = String(attachmentId || '');
101
+ if (!att) return 0;
102
+ const r = conn.run(
103
+ `UPDATE ${h.table} SET note = :note WHERE ${h.col} = :host AND attachment_id = :att`,
104
+ { note: String(note || ''), host: hostVal, att }
105
+ );
106
+ return Number(r.changes) || 0;
107
+ }
108
+
92
109
  /** 解除一条关系(只删边,不删资源字节)。返回是否真的删掉。 */
93
110
  export function unlinkAttachment(conn, { host, hostId, attachmentId } = {}) {
94
111
  const h = hostOf(host);
@@ -33,6 +33,7 @@ export {
33
33
  syncRefAttachments,
34
34
  syncTaskAttachments,
35
35
  unlinkAttachment,
36
+ updateAttachmentNote,
36
37
  } from './attachmentdb/relations.js';
37
38
  export {
38
39
  ensureDocRef,
@@ -14,6 +14,7 @@ import {
14
14
  refIdFor,
15
15
  resolveRefId,
16
16
  unlinkAttachment,
17
+ updateAttachmentNote,
17
18
  upsertFileAttachment,
18
19
  } from '../../core/attachmentdb.js';
19
20
  import { localUpload } from '../../core/localatt.js';
@@ -39,7 +40,31 @@ export async function listDocAttachments({ ref } = {}) {
39
40
  const d = await getDoc({ ref });
40
41
  const locator = String(d.rel || d.path || '').replace(/\\/g, '/');
41
42
  if (!locator) throw badInput('无法定位文档: ' + String(ref || ''));
42
- return { refId: refIdFor(locator), locator, attachments: listRefAttachments(getDb(), refIdFor(locator)) };
43
+ const refId = refIdFor(locator);
44
+ const attachments = listRefAttachments(getDb(), refId);
45
+ // #168:ref 条目补**文档标题**(正文首行的 # 标题)——面板与编辑器都显示它
46
+ try {
47
+ const { refTitlesOf } = await import('./brief.js');
48
+ const titles = await refTitlesOf(
49
+ attachments
50
+ .filter((a) => a.kind === 'ref')
51
+ .map((a) => ({
52
+ id: String((a.meta && a.meta.refId) || a.targetKey || ''),
53
+ locator: String((a.meta && a.meta.locator) || a.targetKey || ''),
54
+ })),
55
+ );
56
+ for (const a of attachments) {
57
+ if (a.kind !== 'ref') continue;
58
+ const t = titles.get(String((a.meta && a.meta.refId) || a.targetKey || ''));
59
+ if (!t) continue;
60
+ a.docTitle = t;
61
+ a.title = t;
62
+ a.name = t;
63
+ }
64
+ } catch {
65
+ /* 读不到标题 → 不补(前端回落文件名) */
66
+ }
67
+ return { refId, locator, attachments };
43
68
  }
44
69
 
45
70
  /**
@@ -151,6 +176,26 @@ export async function attachToDoc(ctx) {
151
176
  };
152
177
  }
153
178
 
179
+ /**
180
+ * 改一条文档侧绑定上的说明(desc,#168):与任务侧同一口径——只动 note。
181
+ */
182
+ export async function noteOnDoc({ ref, attachment, note = '' } = {}) {
183
+ const { locator } = await docLocatorOf(ref);
184
+ const attId = String(attachment || '').trim();
185
+ if (!attId) throw badInput('需要 --attachment <资源 id>(见 docs attachments 输出)');
186
+ const db = getDb();
187
+ let changed = 0;
188
+ tx(
189
+ (conn) => {
190
+ const refId = ensureDocRef(conn, { locator });
191
+ changed = updateAttachmentNote(conn, { host: 'ref', hostId: refId, attachmentId: attId, note });
192
+ },
193
+ { db, mode: 'IMMEDIATE' }
194
+ );
195
+ if (!changed) throw badInput(`这篇文档上没有附件 ${attId}`);
196
+ return { refId: refIdFor(locator), locator, attachment: attId, note: String(note || '') };
197
+ }
198
+
154
199
  /** 解除文档与资源的关系;--purge 在无人引用时连资源行与本机字节一起删。 */
155
200
  export async function detachFromDoc({ ref, attachment, purge } = {}) {
156
201
  const { locator } = await docLocatorOf(ref);
@@ -10,8 +10,7 @@
10
10
  import * as paths from './paths.js';
11
11
  import * as store from './store.js';
12
12
  import { summaryFromMd } from './seed.js';
13
-
14
- const TITLE_RE = /^#\s+(.+)$/m;
13
+ import { docTitleFromMd } from '../../shared/doc-title.js';
15
14
 
16
15
  const baseNameOf = (p) => String(p || '').replace(/\\/g, '/').split('/').pop().replace(/\.md$/i, '');
17
16
 
@@ -42,9 +41,9 @@ async function mainMeta(ref, fallbackRel, ownerName) {
42
41
  if (rel) {
43
42
  try {
44
43
  const body = await store.readOwnDoc(rel);
45
- const t = TITLE_RE.exec(body);
44
+ // #168:标题 = 正文**首行**的 `# 标题`(与文档页/附件清单同一口径)
46
45
  return {
47
- title: (t && t[1].trim()) || ownerName || baseNameOf(rel),
46
+ title: docTitleFromMd(body) || ownerName || baseNameOf(rel),
48
47
  summary: summaryFromMd(body),
49
48
  };
50
49
  } catch { /* 还没落盘 */ }
@@ -54,6 +53,38 @@ async function mainMeta(ref, fallbackRel, ownerName) {
54
53
  return { title: ownerName || '', summary: '' };
55
54
  }
56
55
 
56
+ /**
57
+ * 批量取 ref 的**文档标题**(#168):标题 = 正文首行的 `# 标题`。
58
+ *
59
+ * 用途:面板里的 ref 条目(任务/文档附件区、md 编辑器的引用名)此前只能显示
60
+ * 文件名——用户「填写了标题」后编辑器里看到的仍是文件名。附件清单在服务端补
61
+ * 上真实标题,前端直接用。
62
+ *
63
+ * 只读自有树(外部路径读盘在闭包外不给——与 docs get 读侧同纪律);读不到就
64
+ * 不给(前端回落附件名/文件名)。
65
+ *
66
+ * @param {Array<{id?:string, locator?:string}>} refs
67
+ * @returns {Promise<Map<string,string>>} refId → 标题
68
+ */
69
+ export async function refTitlesOf(refs) {
70
+ const out = new Map();
71
+ for (const r of refs || []) {
72
+ const id = String((r && (r.id || r.refId)) || '');
73
+ const loc = String((r && r.locator) || '');
74
+ if (!id || !loc || out.has(id)) continue;
75
+ // 只认自有树相对路径(外部绝对路径需要闭包校验,附件清单场景不落外部 ref)
76
+ if (/^[a-zA-Z]:[\\/]/.test(loc) || loc.startsWith('/')) continue;
77
+ try {
78
+ const body = await store.readOwnDoc(loc);
79
+ const title = docTitleFromMd(body);
80
+ if (title) out.set(id, title);
81
+ } catch {
82
+ /* 读不到(缺失/被删)→ 不给标题,前端回落 */
83
+ }
84
+ }
85
+ return out;
86
+ }
87
+
57
88
  /**
58
89
  * 文档集短视图。
59
90
  * @param {object} owner repo 或 board 记录
@@ -13,7 +13,7 @@ import * as seed from './seed.js';
13
13
  import * as refs from './refs.js';
14
14
  import * as links from './links.js';
15
15
  import { addDoc, getDoc, listDocs, removeDoc, updateDoc } from './service.js';
16
- import { attachToDoc, detachFromDoc, listDocAttachments } from './attach.js';
16
+ import { attachToDoc, detachFromDoc, listDocAttachments, noteOnDoc } from './attach.js';
17
17
  import {
18
18
  renderAttach,
19
19
  renderAttachments,
@@ -132,6 +132,20 @@ export default {
132
132
  run: attachToDoc,
133
133
  render: renderAttach,
134
134
  },
135
+ {
136
+ // #168:改一条绑定的说明(desc)——面板里 ref 条目「✎ 说明」的落点
137
+ id: 'doc.attach-note',
138
+ cli: ['docs', 'attach-note'],
139
+ http: ['PATCH', '/api/docs/attach-note'],
140
+ summary: '改一条附件绑定的说明(desc):--attachment <资源 id> --note <说明>(只动说明,角色/位置不变)',
141
+ args: ['ref'],
142
+ flags: {
143
+ attachment: { type: 'string', required: true, hint: '资源 id(见 docs attachments)' },
144
+ note: { type: 'string', hint: '说明文字(留空 = 清掉)' },
145
+ },
146
+ run: (ctx) => noteOnDoc({ ref: ctx.ref, attachment: ctx.attachment, note: ctx.note }),
147
+ render: (d) => `已更新 ${d.attachment} 的说明:${d.note || '(清空)'}`,
148
+ },
135
149
  {
136
150
  id: 'doc.detach',
137
151
  cli: ['docs', 'detach'],
@@ -18,6 +18,7 @@ import { badInput, blocked } from '../../core/errors.js';
18
18
  import { getDb } from '../../core/db/index.js';
19
19
  import { tx } from '../../core/db/tx.js';
20
20
  import { ensureDocRef, syncRefAttachments } from '../../core/attachmentdb.js';
21
+ import { docTitleFromMd } from '../../shared/doc-title.js';
21
22
  import fsp from 'node:fs/promises';
22
23
  import path from 'node:path';
23
24
 
@@ -37,12 +38,13 @@ async function safeRead(abs) {
37
38
  export async function listDocs({ external } = {}) {
38
39
  const docs = [];
39
40
  for (const f of await store.listOwnDocs()) {
40
- const title = /^#\s+(.+)$/m.exec(f.size <= 512 * 1024 ? await safeRead(f.abs) : '');
41
+ // #168:标题口径 = 正文**首行**的 `# 标题`(与文档页/附件清单同一口径)
42
+ const title = docTitleFromMd(f.size <= 512 * 1024 ? await safeRead(f.abs) : '');
41
43
  docs.push({
42
44
  docId: paths.ownDocId(f.rel),
43
45
  rel: f.rel,
44
46
  name: f.rel.replace(/\.md$/i, '').split('/').pop(),
45
- title: title ? title[1].trim() : '',
47
+ title,
46
48
  size: f.size,
47
49
  });
48
50
  }
@@ -174,11 +176,13 @@ export async function removeDoc({ ref } = {}) {
174
176
 
175
177
  function outOwn(rel, body) {
176
178
  const { summaryFromMd } = seed;
177
- const m = /^#\s+(.+)$/m.exec(body);
179
+ // #168:标题 = 正文**首行**的 `# 标题`(不是「任意位置的首个 # 行」——
180
+ // 那样正文中间插一行 ## 就会改标题;也不是「首个非空行」——那会让正文
181
+ // 第一行顶替标题)。与前端 shared/doc-title.js 同一口径。
178
182
  return {
179
183
  docId: paths.ownDocId(rel),
180
184
  rel,
181
- title: m ? m[1].trim() : '',
185
+ title: docTitleFromMd(body),
182
186
  summary: summaryFromMd(body),
183
187
  body,
184
188
  writable: true,
@@ -186,11 +190,11 @@ function outOwn(rel, body) {
186
190
  }
187
191
 
188
192
  function outExternal(abs, body) {
189
- const m = /^#\s+(.+)$/m.exec(body);
190
193
  return {
191
194
  docId: paths.extDocId(abs),
192
195
  path: abs,
193
- title: m ? m[1].trim() : '',
196
+ // #168:与自有树同一口径——标题 = 正文首行的 `# 标题`
197
+ title: docTitleFromMd(body),
194
198
  summary: seed.summaryFromMd(body),
195
199
  body,
196
200
  // 登记在册的外部文档 = 用户的文档集,允许就地写回来源文件(写侧另过闭包校验)
@@ -73,6 +73,31 @@ export const attachActions = [
73
73
  },
74
74
  render: renderDetach,
75
75
  },
76
+ {
77
+ // #168:给已挂载的绑定改说明(desc)——面板里 ref 条目上「✎ 说明」的落点。
78
+ id: 'localtask.attach-note',
79
+ cli: ['localtask', 'attach-note'],
80
+ http: ['PATCH', '/api/localtasks/attach-note'],
81
+ summary: '改一条附件绑定的说明(desc):--attachment <资源 id> --note <说明>(只动说明,角色/位置不变)',
82
+ flags: {
83
+ id: { type: 'number', required: true, hint: '任务编号' },
84
+ cwd: CWD,
85
+ key: KEY,
86
+ attachment: { type: 'string', required: true, hint: '资源 id(见 localtask attachments)' },
87
+ note: { type: 'string', hint: '说明文字(留空 = 清掉)' },
88
+ },
89
+ run: async (ctx) => {
90
+ const { noteTaskAttachment } = await import('../tasktool/attach.js');
91
+ return noteTaskAttachment({
92
+ id: ctx.id,
93
+ cwd: ctx.cwd,
94
+ key: ctx.key,
95
+ attachment: ctx.attachment,
96
+ note: ctx.note,
97
+ });
98
+ },
99
+ render: (d) => `已更新 ${d.attachment} 的说明:${d.note || '(清空)'}`,
100
+ },
76
101
  {
77
102
  id: 'localtask.attachments',
78
103
  cli: ['localtask', 'attachments'],
@@ -1,6 +1,5 @@
1
1
  // action 共享的 flag 定义(自 index.js 拆出):cwd/key 主题定位与 wait 的现状参数。
2
2
 
3
3
  export const CWD = { type: 'string', hint: '工作目录(作为主题;默认当前目录)' };
4
- export const SUMMARY = { type: 'string', required: true, hint: '当前现状(agent 当前状态,展示给用户)' };
5
4
  // 任务级寻址的 key flag:全局主题没有 cwd,只能按 key 定位(__GLOBAL__)
6
5
  export const KEY = { type: 'string', hint: '主题 key(与 --cwd 二选一;全局任务池固定 __GLOBAL__)' };
@@ -45,7 +45,8 @@ export const lifecycleActions = [
45
45
  '领取任务:有任务立即领(含任务级 timegoal 的 check 指令);没任务默认立即返回 timeout,项目开启「持续 get」后自动唤起阻塞窗口等人回填',
46
46
  flags: {
47
47
  cwd: CWD,
48
- summary: { type: 'string', hint: '当前现状(agent 状态,展示给用户)' },
48
+ // #171:现状参数已取消——**保留 flag 只为不打断旧调用**(传了也不生效)
49
+ summary: { type: 'string', hint: '已废弃:当前现状不再收(面板上没有对应输入界面)' },
49
50
  timeout: { type: 'number', hint: '阻塞上限(秒);仅项目开启「持续 get」时有意义' },
50
51
  'no-open': { type: 'boolean', hint: '不自动打开浏览器(测试用)' },
51
52
  param: { type: 'array', hint: '外部参数(平面扩展):k=v,可重复或逗号分隔;进交付模板 ctx,模板里 {{k}} / {{params.k}} 取' },
@@ -53,7 +54,7 @@ export const lifecycleActions = [
53
54
  run: async (ctx) => {
54
55
  const { getTask } = await import('../tasktool/get.js');
55
56
  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
+ return getTask({ cwd: ctx.cwd, timeoutSec: ctx.timeout, open: !ctx['no-open'], params: parseParams(ctx.param) });
57
58
  },
58
59
  render: renderWait, // 返回形状与 wait 同构(ok/timeout),复用同一份人读渲染
59
60
  },
@@ -148,10 +149,11 @@ export const lifecycleActions = [
148
149
  cwd: CWD,
149
150
  key: KEY,
150
151
  summary: { type: 'string', required: true, hint: '完成总结(记为本轮终态 + timegoal 日志)' },
151
- progress: { type: 'string', hint: '完成度/下一步(≤2000 字,一并写入日志)' },
152
+ // #171:进度参数已取消——保留 flag 只为不打断旧调用(传了也不生效)
153
+ progress: { type: 'string', hint: '已废弃:完成度/下一步不再收(面板上没有对应输入界面)' },
152
154
  },
153
155
  run: (ctx) =>
154
- service.completeTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key, summary: ctx.summary, progress: ctx.progress }),
156
+ service.completeTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key, summary: ctx.summary }),
155
157
  render: (d) => {
156
158
  if (d.status === 'blocked') {
157
159
  const why = d.reason === 'not_claimed' ? d.hint : `时间未到(剩 ${d.remainingHuman || Math.round((d.remainingSec || 0) / 60) + ' 分钟'},截止 ${d.deadline})——${d.hint}`;
@@ -1,7 +1,7 @@
1
1
  // 阻塞等待族 action(自 index.js 拆出):wait(纯 CLI,agent 本轮最后一步)/
2
2
  // cancel 关闭等待 / presence 面板活标签探测 / events 等待事件流。
3
3
  import * as service from './service.js';
4
- import { CWD, SUMMARY } from './action-flags.js';
4
+ import { CWD } from './action-flags.js';
5
5
  import { renderWait, renderCancel } from './action-render.js';
6
6
 
7
7
  export const waitingActions = [
@@ -13,7 +13,8 @@ export const waitingActions = [
13
13
  '针对某主题(按 cwd 目录名识别)阻塞等待用户回填(默认 3 分钟,最大 10 分钟);本地空时自动领取全局共享池的任务',
14
14
  flags: {
15
15
  cwd: CWD,
16
- summary: SUMMARY,
16
+ // #171:现状参数已取消——保留 flag 只为不打断旧调用(传了也不生效)
17
+ summary: { type: 'string', hint: '已废弃:当前现状不再收(面板上没有对应输入界面)' },
17
18
  timeout: { type: 'number', hint: '阻塞上限(秒);缺省用页面配置(推荐 180,最大 600)' },
18
19
  'no-open': { type: 'boolean', hint: '不自动打开浏览器(测试用)' },
19
20
  param: { type: 'array', hint: '外部参数(平面扩展):k=v,可重复或逗号分隔;进交付模板 ctx,模板里 {{k}} / {{params.k}} 取' },
@@ -24,7 +25,6 @@ export const waitingActions = [
24
25
  const { parseParams } = await import('../tasktool/params.js');
25
26
  return waitForTask({
26
27
  cwd: ctx.cwd,
27
- summary: ctx.summary,
28
28
  timeoutSec: ctx.timeout,
29
29
  open: !ctx['no-open'],
30
30
  params: parseParams(ctx.param),
@@ -100,6 +100,9 @@ export function rowToTask(row) {
100
100
  reopenCount: Math.max(0, Number(row.round ?? 1) - 1),
101
101
  // 派生子任务数(#144):>0 = 链上已有后续轮次,反馈入口只在链尖显示
102
102
  childCount: Number(row.childCount ?? 0),
103
+ // 派生的「下一轮」数(#172):reopen 边数——>0 = 本条已被下一轮取代(不是链尖)。
104
+ // comment / feedback 边(旁支新活)不计入。
105
+ childRoundCount: Number(row.childRoundCount ?? 0),
103
106
  // 迁出 tombstone(本机 → 云端):原条目留在队列里只作记录,不算待领取
104
107
  migratedTo: ext[EXT.MIGRATED_TO] || null,
105
108
  moveFrom: ext[EXT.MOVE_FROM] || null,
@@ -98,8 +98,24 @@ function rowToTaskWithDeps(conn, row) {
98
98
  .map((r) => Number(r.depSeq))
99
99
  .filter((n) => Number.isFinite(n) && n > 0);
100
100
  // 派生子任务数(#144):>0 = 已有后续轮次/评论派生,面板据此收起反馈入口
101
- const child = conn.get('SELECT count(*) AS n FROM task_links WHERE dst_id = :id', { id: row.id });
102
- return { row, task: rowToTask({ ...row, depsLocal: deps, childCount: Number(child && child.n) || 0 }) };
101
+ // 派生「下一轮」数(#172):只有 reopen 边 = **同一件活儿继续下一轮** → 本条
102
+ // 不是链尖(面板只留链尖,旧轮次去任务链里看)。comment / feedback 边是
103
+ // **旁支新活**(评论派生 / 反馈里提的新需求),父任务照旧是活的,不算被取代。
104
+ const child = conn.get(
105
+ `SELECT count(*) AS n,
106
+ sum(CASE WHEN type = 'reopen' THEN 1 ELSE 0 END) AS rounds
107
+ FROM task_links WHERE dst_id = :id`,
108
+ { id: row.id }
109
+ );
110
+ return {
111
+ row,
112
+ task: rowToTask({
113
+ ...row,
114
+ depsLocal: deps,
115
+ childCount: Number(child && child.n) || 0,
116
+ childRoundCount: Number(child && child.rounds) || 0,
117
+ }),
118
+ };
103
119
  }
104
120
 
105
121
  /**
@@ -270,12 +270,11 @@ export async function consumeFirstPending(key, roundSummary, by) {
270
270
  // 时间未到 → 拒绝标记完成。返回 blocked 业务结果而不是抛错——agent 要据此行动
271
271
  // (派出 sub agent 重新提出新的需求,或等到点);抛错会把这条指令埋进错误堆里。
272
272
  // 到点 → 放行并自动记录最终 check(「结束必须 check」的记录器语义,落 timegoal 日志)。
273
- export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawSummary, progress: rawProgress } = {}) {
273
+ export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawSummary } = {}) {
274
274
  const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
275
275
  const want = Number(id);
276
276
  if (!Number.isFinite(want) || want <= 0) throw badInput('缺少参数 --id <任务编号>');
277
277
  const summary = normalizeSummary(rawSummary); // 完成总结必填(记为该任务的终态)
278
- const progress = String(rawProgress ?? '').trim().slice(0, 2000);
279
278
  openStore();
280
279
  const t = topicsRepo.getTopic(key);
281
280
  if (!t) throw notFound('主题不存在: ' + key);
@@ -326,7 +325,8 @@ export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawS
326
325
  };
327
326
  }
328
327
  if (st.hasGoal) {
329
- const rec = await recordTaskCheck({ topicKey: key, taskId: want, summary, progress: progress || '完成' });
328
+ // #171:done 不再收 --progress(面板上没有对应输入界面)——日志只留完成总结
329
+ const rec = await recordTaskCheck({ topicKey: key, taskId: want, summary, progress: '完成' });
330
330
  goal = { recorded: rec.recorded, reached: true, checkedAt: rec.checkedAt };
331
331
  } else {
332
332
  // goal 已被保留期清理(任务拖了 7 天以上才标完成)→ 放行 + 说明:
@@ -230,6 +230,9 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
230
230
  reopenCount: Number(t.reopenCount) || 0,
231
231
  // 派生子任务数(#144):>0 = 已有后续轮次/评论派生——反馈入口只在链尖显示
232
232
  childCount: Number(t.childCount) || 0,
233
+ // 派生的「下一轮」数(#172):reopen 边数——>0 = 本条已被下一轮取代(不是链尖)。
234
+ // 进程面板据此只留链尖,旧轮次去任务链里看;comment / feedback 边(旁支新活)不计入。
235
+ childRoundCount: Number(t.childRoundCount) || 0,
233
236
  // 链上第几轮(#122 进程面板「楼数」):根任务 = 1,派生 = 来源 + 1(schema 语义
234
237
  // 见 v1.sql tasks.round)。库里存的是 round 列,JSON 形态只带 reopenCount = round-1
235
238
  // (repo/rows.js),这里换算回来 —— 前端显示「第 N 楼」/按楼搜索不必再回溯链。
@@ -399,16 +402,21 @@ export async function taskChain({ id, cwd, key } = {}) {
399
402
 
400
403
  // 节点 = 链上每一代任务(每轮一条,seq 做面板 key),从根排到叶;自己是"当前尖"
401
404
  // wrapper = getTaskRowById 的返回({ row, task });row.topicId 是主题内部 id
402
- const nodeOf = (wrapper) => {
405
+ // 链边的类型(reopen=反馈轮次 / comment=评论旁支)从**边**上取:task_links 是链的
406
+ // 唯一来源,任务自身那个旧 forkKind 字段多半是空的——空着的话面板的链上每一格
407
+ // 都显示成「起点」,看不出哪一轮是反馈、哪一条是评论旁支(#172)。
408
+ const nodeOf = (wrapper, linkType) => {
403
409
  const owner = topicsRepo.getTopicById(wrapper.row.topicId);
410
+ const lite = chainLite(owner || { key: k, name: t.name }, wrapper.task);
404
411
  return {
405
- ...chainLite(owner || { key: k, name: t.name }, wrapper.task),
412
+ ...lite,
413
+ forkKind: linkType || lite.forkKind || '',
406
414
  at: String(wrapper.task.createdAt || ''),
407
415
  current: Number(wrapper.task.id) === Number(selfRow.task.id),
408
416
  };
409
417
  };
410
- const upNodes = ancestorLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id)));
411
- const downNodes = descendantLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id)));
418
+ const upNodes = ancestorLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id), l.type));
419
+ const downNodes = descendantLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id), l.type));
412
420
  const selfNode = nodeOf(selfRow);
413
421
  // 根 → … → 自己 → … → 叶(自己是"当前尖";查询哪条,哪条就是尖)
414
422
  const nodes = [...upNodes, selfNode, ...downNodes].map(
@@ -416,8 +424,8 @@ export async function taskChain({ id, cwd, key } = {}) {
416
424
  );
417
425
 
418
426
  // 祖先/子任务清单(旧字段形状保留:面板兼容)
419
- const ancestors = upNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.type || '', forkOf: '', createdAt: n.createdAt, excerpt: n.excerpt }));
420
- const children = downNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.type || '', forkOf: '', createdAt: n.createdAt, excerpt: n.excerpt }));
427
+ const ancestors = upNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.forkKind || '', forkOf: '', createdAt: n.createdAt, excerpt: n.excerpt }));
428
+ const children = downNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.forkKind || '', forkOf: '', createdAt: n.createdAt, excerpt: n.excerpt }));
421
429
 
422
430
  return {
423
431
  status: 'ok',
@@ -268,6 +268,9 @@ export function resourceOf(row, lookups = {}) {
268
268
  }
269
269
 
270
270
  // ref:文档库里的 md(locator 是 docs 树相对路径,或外部 md 的绝对路径)
271
+ // 标题口径(#168):**文档标题**(正文首行的 # 标题)优先 —— 服务端在标注层
272
+ // (tasktool/attach.js 的 annotateRefTitles)读盘补上并覆盖 title/name;
273
+ // 这里先给文件名占位,读不到标题时前端回落它。
271
274
  const info = lookups.refs && lookups.refs.get(String(meta.refId || row.targetKey || ''));
272
275
  const refId = String(meta.refId || row.targetKey || (info && info.refId) || '');
273
276
  const relPath = String((info && info.locator) || meta.locator || '');