nx-kv 0.24.1 → 0.24.3

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 (40) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/assets/kv-get/SKILL.md +9 -4
  3. package/package.json +1 -1
  4. package/src/core/workflow/readiness.js +10 -2
  5. package/src/core/workflow/types.js +3 -1
  6. package/src/modules/docs/knowledge.js +175 -64
  7. package/src/modules/docs/refs.js +26 -3
  8. package/src/modules/localtask/index.js +5 -3
  9. package/src/modules/localtask/task-lifecycle.js +63 -31
  10. package/src/modules/localtask/task-view.js +15 -4
  11. package/src/modules/repos/boards.js +25 -1
  12. package/src/modules/repos/index.js +5 -2
  13. package/src/modules/tasktool/groupctx.js +38 -4
  14. package/src/web/frontend/components/Introduction/index.jsx +5 -1
  15. package/src/web/frontend/components/Introduction/use-intro.js +31 -9
  16. package/src/web/frontend/modules/board/board-view.js +7 -2
  17. package/src/web/frontend/page/dir/index.jsx +8 -14
  18. package/src/web/frontend/page/dir/landing.jsx +8 -5
  19. package/src/web/frontend/page/dir/task.jsx +13 -17
  20. package/src/web/public/assets/Introduction-DK2deIP2.js +1 -0
  21. package/src/web/public/assets/{cloud-E33bm4CD.js → cloud-BoIeutoa.js} +1 -1
  22. package/src/web/public/assets/{dag-ClRadqiu.js → dag-DC3tN4dI.js} +1 -1
  23. package/src/web/public/assets/dir-BbDWEJOC.js +3 -0
  24. package/src/web/public/assets/{group-Ckwoc5tW.js → group-C30SuifL.js} +1 -1
  25. package/src/web/public/assets/{index-DMp4lRKl.js → index-DFMD9MV2.js} +3 -3
  26. package/src/web/public/assets/{md-history-CwtrJcZo.js → md-history-DBs3hhRL.js} +1 -1
  27. package/src/web/public/assets/{member-picker-BV1a-LiO.js → member-picker-xneI-u00.js} +1 -1
  28. package/src/web/public/assets/{overview-CQW1MViJ.js → overview-Ai76EDG0.js} +1 -1
  29. package/src/web/public/assets/{progress-CDiNmHVI.js → progress-DRKqpuh_.js} +1 -1
  30. package/src/web/public/assets/{repos-BYFj2sjE.js → repos-CMmB-5Nj.js} +1 -1
  31. package/src/web/public/assets/{route-crumb-DSgy8FTp.js → route-crumb-D3TTGwPj.js} +1 -1
  32. package/src/web/public/assets/{settings-BoAQ5YXH.js → settings-D81FsMru.js} +1 -1
  33. package/src/web/public/assets/task-w3pgQWfV.js +5 -0
  34. package/src/web/public/assets/{template-slots-CMB5ZTZE.js → template-slots-DLN_zed3.js} +1 -1
  35. package/src/web/public/assets/{templates-DMVIPsdx.js → templates-DnYaTa0s.js} +1 -1
  36. package/src/web/public/assets/{upload-CzfyPGrk.js → upload-DAjZdYV0.js} +1 -1
  37. package/src/web/public/index.html +1 -1
  38. package/src/web/public/assets/Introduction-DGcd3YBk.js +0 -1
  39. package/src/web/public/assets/dir-Dj-3QRkO.js +0 -3
  40. package/src/web/public/assets/task-Br1K-bzV.js +0 -5
package/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.24.3] - 2026-11-05 任务状态单向 + 重开即新建
6
+
7
+ ### Changed
8
+
9
+ - **重做 / 加评论不再「把同一条任务打回重新开始」,而是新建一条任务**(任务 #59):
10
+ 用户提修改意见时,旧任务**归档留档**(原文、上一轮完成总结、完成标记一个字不动),
11
+ 队列里**新建一条待领取任务**(正文 = 原正文 + 上一轮完成总结 + 本轮反馈),
12
+ `forkOf` 指回上一条、`supersededBy` 记在旧任务上。
13
+ - **状态单向**:`待领取 → 已领取 → 已归档`,**没有回退边**——完成等待验收之后
14
+ 不会再回到「重新开始」。
15
+ - 归档是终态:不再算待领取(不会被再派发)、不能再重开;作为上游依赖时视为
16
+ 「已了结」,不再挡住后来者。
17
+ - 新任务继承同一件活的约束:时间目标(新一轮从再次领取重新计时)、闸门、上游依赖。
18
+ - 面板:重做 / 评论后开**新任务的新文档**,旧文档留档;任务列表新增「已归档」
19
+ 状态(徽标「档」),归档任务不再算进行中。
20
+ ## [0.24.2] - 2026-11-05 描述改成 md 列表
21
+
22
+ ### Changed
23
+
24
+ - **仓库 / 项目组的「描述」不再是孤零零一篇 md,而是一个 md 列表**(任务 #58):
25
+ 介绍文档集 = **主篇**(介绍目录的 `index.md` → 没有目录则旧单文件 `repo/<key>.md`
26
+ → 再没有则绑定的外部文件)+ **其余各篇**(介绍目录里的其他 md,含 `reference/` 补充说明)。
27
+ - 交付层(agent 领任务时拿到的组上下文):项目介绍 / 组介绍都按「主篇正文 + 其余各篇
28
+ 的可读路径」呈现,并标出「N 篇」;项目自己登记的补充文档也给出可读路径。
29
+ - `repo knowledge --md`:介绍按列表输出(主篇正文 + 其余各篇路径)。
30
+ - `repo doc list`:主篇 + 目录补充篇 + 登记的补充篇,一起列出。
31
+ - 面板简介区:主篇指向介绍目录的 `index.md`(存在时),目录补充篇并入同一行列表。
32
+ - 兼容:旧数据(旧单文件 + 登记的 `docLinks`)照旧可读;目录里没有 `index.md` 时,
33
+ 目录内的 md 仍算描述的一部分(不再因为少一篇主篇就把其余藏起来)。
34
+
5
35
  ## [0.24.1] - 2026-11-05 面板跨域不再拦写请求
6
36
 
7
37
  ### Fixed
@@ -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 把用户的修改反馈变成**一条新任务**(旧任务归档留档,状态单向)。触发词:领取本地任务、看看有没有排给我的任务、本地队列、领取委托任务、拿任务、本目录的任务、排队任务、localtask get、localtask wait、标记完成、任务完成、修改反馈、重新执行、kv-get。凡「主动获取排给本目录的任务」以及「把任务标记完成/按反馈重开」的场景都走本 skill。反例:把需求提交/委托给别的目录用 kv-submit;查本机仓库分组与参考仓库用 kv-repo;操作远程 KV 清单(todo)用 nx-kv。
4
4
  ---
5
5
 
6
6
  # kv-get — 领取、执行、完成(领取侧)
@@ -70,12 +70,17 @@ nx-kv localtask done --id <n> --summary "<完成总结>" --json
70
70
  # 标记完成(完成总结必填——它就是下一轮 agent 能看到的「上轮做了什么」)
71
71
  nx-kv localtask done --id <n> --summary "<完成总结>" [--progress "<完成度/下一步>"]
72
72
 
73
- # 用户看了结果提修改意见 → 任务回到待领取,agent 可再次领取(执行循环继续)
73
+ # 用户看了结果提修改意见 → **新建一条任务**(新的 md),旧任务归档留档
74
74
  nx-kv localtask reopen --id <n> [--text "<改后的正文(Markdown)>"] --json
75
75
  ```
76
76
 
77
- `reopen` 会作废领取时间(新一轮从**再次领取**开始重新计时)、清掉完成标记,
78
- 但**保留上一轮的完成总结**——下一轮接手时 agent 能看到自己上轮做到哪。
77
+ `reopen` **不改旧任务**:它在同一条队列里**新建一条待领取任务**(正文 = `--text` 给的
78
+ 内容),旧任务状态前进到终态「已归档」——原文、上一轮完成总结、完成标记全部留档。
79
+ 新任务继承同一件活的约束(时间目标从再次领取重新计时、闸门、上游依赖),
80
+ 并用 `forkOf` 指回上一条。
81
+
82
+ 任务状态是**单向**的:`待领取 → 已领取 → 已归档`,**没有回退边**——
83
+ 完成等待验收之后不会回到「重新开始」。
79
84
 
80
85
  ## 硬规则
81
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.24.1",
3
+ "version": "0.24.3",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -99,12 +99,20 @@ function isAlive(t) {
99
99
  return t && !t.deletedAt && !t.migratedTo;
100
100
  }
101
101
 
102
+ /**
103
+ * 已完成口径。**归档(archived)也算完成**——归档是终态:它不会再动,
104
+ * 依赖它的人不该永远被挡着(#59)。
105
+ */
102
106
  function isCompleted(t) {
103
- return isAlive(t) && !!t.completedAt;
107
+ return isAlive(t) && (!!t.completedAt || t.status === 'archived');
104
108
  }
105
109
 
110
+ /**
111
+ * 待领取口径:活着(没删没迁出)且不是「已领走」。
112
+ * **归档(archived)也不算待领取**——归档是终态:状态单向,没有回退边(#59)。
113
+ */
106
114
  function isPendingLike(t) {
107
- return isAlive(t) && t.status !== 'consumed';
115
+ return isAlive(t) && t.status !== 'consumed' && t.status !== 'archived';
108
116
  }
109
117
 
110
118
  /**
@@ -131,9 +131,11 @@ export function isGateNode(node) {
131
131
  export function taskToNode(task) {
132
132
  const completed = !!task?.completedAt;
133
133
  const consumed = task?.status === 'consumed';
134
+ // 归档(archived)是终态:它不会再动,依赖它的人不该永远被挡着(#59)。
135
+ const archived = task?.status === 'archived';
134
136
  /** @type {NodeState} */
135
137
  let state = 'pending';
136
- if (completed) state = 'success';
138
+ if (completed || archived) state = 'success';
137
139
  else if (consumed) state = 'running';
138
140
  else if (task?.ready === true) state = 'ready';
139
141
 
@@ -110,7 +110,16 @@ export async function repoKnowledge(locator, { md = false } = {}) {
110
110
  const warnings = [];
111
111
  const closure = await store.externalClosure(s);
112
112
 
113
- const intro = await readRef(repo.doc, paths.repoDocRel(rk), { warnings, label: '项目介绍' });
113
+ // 介绍是**文档集**(主篇 + 其余各篇)——#58
114
+ const introSet = await readIntroSet({
115
+ dirRel: paths.repoDocDirRel(rk),
116
+ legacyRel: paths.repoDocRel(rk),
117
+ ref: repo.doc,
118
+ links: repo.docLinks,
119
+ warnings,
120
+ label: '项目介绍',
121
+ });
122
+ const intro = introSet.main ? { ...introSet.main } : { missing: true, docId: paths.repoDocRel(rk) };
114
123
 
115
124
  // 所属组:显式成员(与 listBoards 同一口径)
116
125
  const boards = [];
@@ -118,7 +127,15 @@ export async function repoKnowledge(locator, { md = false } = {}) {
118
127
  const members = boardRepoKeys(b, s);
119
128
  if (!members.includes(rk)) continue;
120
129
  const bkey = boardKeyOf(b.name);
121
- const bIntro = await readRef(b.doc, paths.boardDocRel(b.name), { warnings, label: `组介绍·${b.name}` });
130
+ const bIntroSet = await readIntroSet({
131
+ dirRel: paths.boardDocDirRel(b.name),
132
+ legacyRel: paths.boardDocRel(b.name),
133
+ ref: b.doc,
134
+ links: b.docLinks,
135
+ warnings,
136
+ label: `组介绍·${b.name}`,
137
+ });
138
+ const bIntro = bIntroSet.main ? { ...bIntroSet.main } : { missing: true, docId: paths.boardDocRel(b.name) };
122
139
  const noteRef = (b.repoDocs || {})[rk];
123
140
  const note = await readRef(noteRef, paths.groupNoteRel(b.name, rk), { warnings, label: `组内描述·${b.name}/${rk}` });
124
141
  // 组级附加文档:自有/单文件进全文;目录绑定只列清单
@@ -144,7 +161,7 @@ export async function repoKnowledge(locator, { md = false } = {}) {
144
161
  docLinks.push({ note: l.note || '', ...meta, ...(await readExternalDoc(abs, { warnings, label: `组绑定·${l.path}` })) });
145
162
  }
146
163
  }
147
- boards.push({ name: b.name, key: bkey, intro: bIntro, note, docLinks, externalDirs });
164
+ boards.push({ name: b.name, key: bkey, intro: bIntro, introSet: bIntroSet, note, docLinks, externalDirs });
148
165
  }
149
166
 
150
167
  // 参考仓库(dev 侧反向引用 {kind:'ref'})
@@ -158,6 +175,7 @@ export async function repoKnowledge(locator, { md = false } = {}) {
158
175
  const out = {
159
176
  repo: { key: rk, name: repo.name, path: repo.path, desc: repo.desc || '', remote: repo.remote || '', type: repo.type || 'dev' },
160
177
  intro: intro.missing ? null : intro,
178
+ introSet,
161
179
  boards,
162
180
  refs,
163
181
  warnings,
@@ -171,10 +189,10 @@ function renderMd(k) {
171
189
  const lines = [];
172
190
  const heading = (t) => (lines.length ? lines.push('', t) : lines.push(t));
173
191
  heading(`# ${k.repo.name}`);
174
- if (k.intro && !k.intro.missing) lines.push(k.intro.body.trim());
192
+ lines.push(...introMdLines(k.introSet, k.intro));
175
193
  for (const b of k.boards) {
176
194
  heading(`## 组:${b.name}`);
177
- if (b.intro && !b.intro.missing) lines.push(b.intro.body.trim());
195
+ lines.push(...introMdLines(b.introSet, b.intro));
178
196
  if (b.note && !b.note.missing) lines.push(b.note.body.trim());
179
197
  for (const d of b.docLinks) {
180
198
  if (!d.missing && d.body) lines.push(d.body.trim());
@@ -191,19 +209,6 @@ function renderMd(k) {
191
209
  return lines.join('\n');
192
210
  }
193
211
 
194
- /**
195
- * **介绍文档**:绑定优先(外部绝对路径 / 自有 rel),缺省走约定路径。
196
- * 返回 { body, path }——path 给 agent 直接读盘(自有树给绝对路径)。
197
- */
198
- async function readIntroDoc(ref, fallbackRel, { warnings, label }) {
199
- if (ref && ref.path) {
200
- const ext = await readExternalDoc(ref.path, { warnings, label });
201
- return { body: ext.body || '', path: ref.path };
202
- }
203
- const rel = (ref && ref.rel) || fallbackRel;
204
- const own = await readOwn(rel, { warnings, label });
205
- return { body: own.body || '', path: join(paths.docsRoot(), rel) };
206
- }
207
212
 
208
213
  /**
209
214
  * **项目组上下文**(交付层用):某个工作目录所属仓库所在的项目组材料。
@@ -227,14 +232,33 @@ export async function groupContextFor(cwd) {
227
232
  const closure = await store.externalClosure(s);
228
233
  const groups = [];
229
234
 
230
- // 项目介绍(项目级任务也要带——它回答「这个项目是干什么的」)
231
- const repoIntro = await readIntroDoc(repo.doc, paths.repoDocRel(rk), { warnings, label: '项目介绍' });
235
+ // 项目介绍(项目级任务也要带——它回答「这个项目是干什么的」)。
236
+ // 介绍是**文档集**(主篇 + 其余各篇),不是孤立的一篇——#58。
237
+ const repoIntroSet = await readIntroSet({
238
+ dirRel: paths.repoDocDirRel(rk),
239
+ legacyRel: paths.repoDocRel(rk),
240
+ ref: repo.doc,
241
+ links: repo.docLinks,
242
+ warnings,
243
+ label: '项目介绍',
244
+ });
245
+ const repoIntro = mainAsIntro(repoIntroSet);
246
+ // 项目自己登记的补充文档(外部 / ref 仓库里的文件)——交付时给可读路径
247
+ const repoDocLinks = linkEntries(repo.docLinks, closure);
232
248
 
233
249
  for (const b of s.boards) {
234
250
  const members = boardRepoKeys(b, s);
235
251
  if (!members.includes(rk)) continue;
236
- // 组介绍(绑定优先,缺省约定路径)
237
- const intro = await readIntroDoc(b.doc, paths.boardDocRel(b.name), { warnings, label: `组介绍·${b.name}` });
252
+ // 组介绍(绑定优先 → 介绍目录主篇 → 旧单文件;是文档集,不是一篇)
253
+ const introSet = await readIntroSet({
254
+ dirRel: paths.boardDocDirRel(b.name),
255
+ legacyRel: paths.boardDocRel(b.name),
256
+ ref: b.doc,
257
+ links: b.docLinks,
258
+ warnings,
259
+ label: `组介绍·${b.name}`,
260
+ });
261
+ const intro = mainAsIntro(introSet);
238
262
  // 本项目在组里的位置
239
263
  const noteRef = (b.repoDocs || {})[rk];
240
264
  const noteOwn = await readRef(noteRef, paths.groupNoteRel(b.name, rk), { warnings, label: `组内描述·${b.name}` });
@@ -252,68 +276,77 @@ export async function groupContextFor(cwd) {
252
276
  peers.push({ name: mname, note: peerNote.body || (b.repoNotes || {})[mkey] || '' });
253
277
  }
254
278
  // 组绑定参考文件(给可读路径——agent 直接读盘);tag 随条目走(有才带)
255
- const docLinks = [];
256
- for (const l of Array.isArray(b.docLinks) ? b.docLinks : []) {
257
- if (l.rel) {
258
- docLinks.push({ rel: l.rel, abs: join(paths.docsRoot(), l.rel), note: l.note || '', ...(l.tag ? { tag: l.tag } : {}) });
259
- continue;
260
- }
261
- const abs = l.path && store.resolveExternal(l.path, closure);
262
- if (!abs) continue;
263
- docLinks.push({ path: abs, abs, note: l.note || '', ...(l.tag ? { tag: l.tag } : {}) });
264
- }
279
+ const docLinks = linkEntries(b.docLinks, closure);
265
280
  groups.push({
266
281
  name: b.name,
267
282
  key: boardKeyOf(b.name),
268
283
  desc: b.desc || '',
269
284
  intro,
285
+ introSet,
270
286
  note: noteOwn.body || (b.repoNotes || {})[rk] || '',
271
287
  peers,
272
288
  docLinks,
273
289
  });
274
290
  }
275
- return { repo: { name: repo.name, key: rk, intro: repoIntro }, groups };
291
+ return { repo: { name: repo.name, key: rk, intro: repoIntro, introSet: repoIntroSet, docLinks: repoDocLinks }, groups };
276
292
  }
277
293
 
278
294
  /**
279
- * **介绍文档集**(多篇):目录优先,旧的单文件路径回落。
295
+ * **介绍文档集**(多篇 md 的列表):主篇 + 其余各篇。
280
296
  *
281
- * dirRel 介绍目录(自有树内):repo/<key> · board/<组> · group/<组>/<key>
297
+ * dirRel 介绍目录(自有树内):repo/<key> · board/<组 slug>
282
298
  * legacyRel 旧单文件路径(读时回落,保证既有数据继续可用)
283
299
  * ref DocRef 覆盖(绑定的文件或目录);给了就以它为准
284
300
  *
285
- * 返回 { main: {body,title,path}|null, extras: [{rel,name,path,isReference}], count }
286
- * main = 主篇(目录 index.md;没有目录则旧单文件)
287
- * extras = 其余文档(补充说明;reference/ 子目录下的标记 isReference)
301
+ * 返回 { main, extras, count }:
302
+ * main = 主篇(目录 index.md → 没有目录则旧单文件 → 再没有则绑定的那一篇)
303
+ * extras = 其余文档(目录内的其余 md;reference/ 子目录下的标 isReference)
304
+ *
305
+ * 每篇都带两套坐标:
306
+ * docId 面板导航用('rel:…' 自有树 / 'path:…' 外部绝对路径)
307
+ * abs **磁盘绝对路径**——agent 拿到就能直接读盘(交付层用这个)
308
+ *
309
+ * 为什么描述是「列表」而不是一篇:介绍往往不止主篇——还有架构、问答、规范等补充
310
+ * 说明。只给一篇,等于让 agent 拿着半张地图干活(#58)。
288
311
  */
289
- // WIP:目录介绍文档集读取(暂无调用方,保留待接线;lint 豁免用 _ 前缀)
290
- async function _readIntroSet({ dirRel, legacyRel, ref, warnings, label }) {
291
- // 1) 绑定了文档/目录 → 以绑定为准
312
+ export async function readIntroSet({ dirRel, legacyRel, ref, links = [], warnings, label }) {
313
+ // 1) 绑定了文档 / 目录 → 以绑定为准
292
314
  if (ref) {
293
315
  if (ref.rel) {
294
316
  const one = await readOwn(ref.rel, { warnings, label });
295
- if (one.missing) return { main: null, extras: [], count: 0 };
296
- return { main: { body: one.body, title: one.title, path: paths.ownDocId(ref.rel) }, extras: [], count: 1 };
317
+ if (one.missing) return emptyIntroSet();
318
+ return {
319
+ main: { docId: paths.ownDocId(ref.rel), title: one.title, body: one.body, abs: join(paths.docsRoot(), ref.rel) },
320
+ extras: [],
321
+ count: 1,
322
+ };
297
323
  }
298
324
  if (ref.path) {
299
325
  const st = await import('node:fs/promises').then((m) => m.stat(ref.path).catch(() => null));
300
- if (!st) return { main: null, extras: [], count: 0 };
326
+ if (!st) return emptyIntroSet();
301
327
  if (!st.isDirectory()) {
302
328
  const one = await readExternalDoc(ref.path, { warnings, label });
303
- if (one.missing) return { main: null, extras: [], count: 0 };
304
- return { main: { body: one.body, title: one.title, path: ref.path }, extras: [], count: 1 };
329
+ if (one.missing) return emptyIntroSet();
330
+ return {
331
+ main: { docId: paths.extDocId(ref.path), title: one.title, body: one.body, abs: ref.path },
332
+ extras: [],
333
+ count: 1,
334
+ };
305
335
  }
306
336
  // 绑的是目录 → 目录内全部 .md(主篇 = index.md,其余为补充说明)
307
337
  const files = await listDirMd(ref.path);
308
- const main = files.find((f) => f.toLowerCase().endsWith('/index.md')) || files[0] || '';
309
- const others = files.filter((f) => f !== main);
310
- const mainDoc = main ? await readExternalDoc(main, { warnings, label }) : null;
338
+ const mainFile = files.find((f) => f.toLowerCase().endsWith('/index.md')) || files[0] || '';
339
+ const others = files.filter((f) => f !== mainFile);
340
+ const mainDoc = mainFile ? await readExternalDoc(mainFile, { warnings, label }) : null;
311
341
  return {
312
- main: mainDoc && !mainDoc.missing ? { body: mainDoc.body, title: mainDoc.title, path: main } : null,
342
+ main: mainDoc && !mainDoc.missing
343
+ ? { docId: paths.extDocId(mainFile), title: mainDoc.title, body: mainDoc.body, abs: mainFile }
344
+ : null,
313
345
  extras: others.map((f) => ({
346
+ docId: paths.extDocId(f),
347
+ name: baseNameOf(f),
314
348
  rel: '',
315
- name: f.slice(f.lastIndexOf(sep) + 1),
316
- path: f,
349
+ abs: f,
317
350
  isReference: isReferencePath(f),
318
351
  })),
319
352
  count: files.length,
@@ -321,28 +354,106 @@ async function _readIntroSet({ dirRel, legacyRel, ref, warnings, label }) {
321
354
  }
322
355
  }
323
356
  // 2) 无绑定:目录主篇优先 → 回落旧单文件
357
+ // 目录里没有 index.md 时,目录内的 md 仍然算「描述的一部分」——
358
+ // 描述是列表,不该因为少一篇主篇就把其余也藏起来。
324
359
  const mainRel = dirRel ? paths.docMainRel(dirRel) : '';
360
+ const inDir = dirRel ? await store.listOwnDocsIn(dirRel) : [];
361
+ // 已在 store 里登记过的(docLinks)不重复列:它们由「补充文档」那层负责
362
+ const registered = new Set(
363
+ (Array.isArray(links) ? links : []).map((l) => String(l.rel || '')).filter(Boolean),
364
+ );
365
+ const extrasOf = (skipRel) =>
366
+ inDir
367
+ .filter((d) => d.rel !== skipRel && !registered.has(d.rel))
368
+ .map((d) => ({
369
+ docId: paths.ownDocId(d.rel),
370
+ name: d.name,
371
+ rel: d.rel,
372
+ abs: d.abs || join(paths.docsRoot(), d.rel),
373
+ isReference: String(d.name || '').toLowerCase().startsWith(paths.DOC_REFERENCE_DIR + '/'),
374
+ }));
325
375
  if (mainRel && (await store.ownDocExists(mainRel))) {
326
376
  const one = await readOwn(mainRel, { warnings, label });
327
- const inDir = await store.listOwnDocsIn(dirRel);
377
+ const extras = extrasOf(mainRel);
328
378
  return {
329
- main: { body: one.body, title: one.title, path: paths.ownDocId(mainRel) },
330
- extras: inDir
331
- .filter((d) => d.rel !== mainRel)
332
- .map((d) => ({
333
- rel: d.rel,
334
- name: d.name,
335
- path: paths.ownDocId(d.rel),
336
- isReference: d.name.toLowerCase().startsWith(paths.DOC_REFERENCE_DIR + '/'),
337
- })),
338
- count: inDir.length,
379
+ main: { docId: paths.ownDocId(mainRel), title: one.title, body: one.body, abs: join(paths.docsRoot(), mainRel) },
380
+ extras,
381
+ count: 1 + extras.length,
339
382
  };
340
383
  }
341
384
  if (legacyRel) {
342
385
  const one = await readOwn(legacyRel, { warnings, label });
343
386
  if (!one.missing) {
344
- return { main: { body: one.body, title: one.title, path: paths.ownDocId(legacyRel) }, extras: [], count: 1 };
387
+ const extras = extrasOf(legacyRel);
388
+ return {
389
+ main: { docId: paths.ownDocId(legacyRel), title: one.title, body: one.body, abs: join(paths.docsRoot(), legacyRel) },
390
+ extras,
391
+ count: 1 + extras.length,
392
+ };
345
393
  }
346
394
  }
395
+ // 目录里既没有 index.md、旧单文件也没有:目录内的 md 就是全部
396
+ if (inDir.length) {
397
+ const extras = extrasOf(inDir[0].rel);
398
+ const first = await readOwn(inDir[0].rel, { warnings, label });
399
+ return {
400
+ main: first.missing
401
+ ? null
402
+ : { docId: paths.ownDocId(inDir[0].rel), title: first.title, body: first.body, abs: inDir[0].abs || join(paths.docsRoot(), inDir[0].rel) },
403
+ extras,
404
+ count: 1 + extras.length,
405
+ };
406
+ }
407
+ return emptyIntroSet();
408
+ }
409
+
410
+ /** 文档集的主篇 → 旧的单篇形状({ body, path }),兼容既有消费方 */
411
+ function mainAsIntro(set) {
412
+ const m = set && set.main;
413
+ return m ? { body: m.body || '', path: m.abs || '', title: m.title || '' } : { body: '', path: '' };
414
+ }
415
+
416
+ /** 登记在 store 里的补充文档(rel 自有树 / path 外部)→ 可读绝对路径条目 */
417
+ function linkEntries(links, closure) {
418
+ const out = [];
419
+ for (const l of Array.isArray(links) ? links : []) {
420
+ if (l.rel) {
421
+ out.push({ rel: l.rel, abs: join(paths.docsRoot(), l.rel), note: l.note || '', ...(l.tag ? { tag: l.tag } : {}) });
422
+ continue;
423
+ }
424
+ const abs = l.path && store.resolveExternal(l.path, closure);
425
+ if (!abs) continue;
426
+ out.push({ path: abs, abs, note: l.note || '', ...(l.tag ? { tag: l.tag } : {}) });
427
+ }
428
+ return out;
429
+ }
430
+
431
+ /** 文档集 → markdown 行(主篇正文 + 其余各篇的可读路径) */
432
+ function introMdLines(set, fallback) {
433
+ const out = [];
434
+ const main = (set && set.main) || (fallback && !fallback.missing ? fallback : null);
435
+ if (main && main.body) out.push(String(main.body).trim());
436
+ const extras = (set && set.extras) || [];
437
+ if (extras.length) {
438
+ out.push('', '其余介绍文档(可直接读取):');
439
+ for (const d of extras) out.push(`- ${d.abs || d.docId || d.rel || ''}`);
440
+ }
441
+ return out;
442
+ }
443
+
444
+ /** 空文档集(没有主篇、也没有其余) */
445
+ function emptyIntroSet() {
347
446
  return { main: null, extras: [], count: 0 };
348
447
  }
448
+
449
+ /** 文件名(路径最后一段) */
450
+ function baseNameOf(p) {
451
+ const s = String(p || '');
452
+ return s.split(sep).pop() || s.split('/').pop() || '';
453
+ }
454
+
455
+ /** 是否在 reference/ 补充说明子目录下 */
456
+ function isReferencePath(p) {
457
+ const segs = String(p || '').split(sep).join('/').split('/');
458
+ return segs.includes(paths.DOC_REFERENCE_DIR);
459
+ }
@@ -11,6 +11,7 @@ import { normalizeKey } from '../../core/keys.js';
11
11
  import { reposBridge } from './repos-bridge.js';
12
12
  import { badInput, notFound, conflict } from '../../core/errors.js';
13
13
  import { withLinkMeta } from './docref.js';
14
+ import { readIntroSet } from './knowledge.js';
14
15
 
15
16
  // 看板定位(id / key / 名称):boardKeyOf 由 bridge 注入(key 口径必须与 repos 完全一致)
16
17
  function findBoardIn(s, idOrKey, { normalizeKey: nk, boardKeyOf }) {
@@ -157,16 +158,38 @@ export async function listRepoDocs(locator) {
157
158
  const repo = await getRepo(locator);
158
159
  const s = await loadStore();
159
160
  const r = s.repos.find((x) => deriveKey(x) === deriveKey(repo));
160
- const main = r && r.doc ? r.doc : null;
161
+ const key = deriveKey(repo);
161
162
  const links = r && Array.isArray(r.docLinks) ? r.docLinks : [];
163
+ // 介绍文档集:**主篇 + 其余各篇**(目录主篇优先 → 旧单文件回落)——#58
164
+ const set = await readIntroSet({
165
+ dirRel: paths.repoDocDirRel(key),
166
+ legacyRel: paths.repoDocRel(key),
167
+ ref: r && r.doc ? r.doc : null,
168
+ links,
169
+ warnings: [],
170
+ label: '项目介绍',
171
+ });
172
+ const main = set.main ? docRefOut(set.main) : null;
173
+ const extras = (set.extras || []).map((d) => ({ ...docRefOut(d), name: d.name || '', isReference: !!d.isReference }));
162
174
  return {
163
- repo: { key: deriveKey(repo), name: repo.name },
175
+ repo: { key, name: repo.name },
164
176
  main,
177
+ extras,
165
178
  links,
166
- count: (main ? 1 : 0) + links.length,
179
+ count: (main ? 1 : 0) + extras.length + links.length,
167
180
  };
168
181
  }
169
182
 
183
+ /** 文档集条目 → DocRef 形状(自有树给 rel,外部给 path) */
184
+ function docRefOut(d) {
185
+ if (!d) return null;
186
+ if (d.rel) return { rel: d.rel };
187
+ if (d.docId && String(d.docId).startsWith('rel:')) return { rel: String(d.docId).slice(4) };
188
+ if (d.path) return { path: d.path };
189
+ if (d.abs) return { path: d.abs };
190
+ return null;
191
+ }
192
+
170
193
  /** 往项目的介绍文档集里加一篇(rel / path / ref+rel 三选一;note/tag 可选注解)。
171
194
  *
172
195
  * 同 rel/path 重复添加 = 更新该条(与组级 setDocLink 同一语义)——
@@ -191,12 +191,13 @@ export default {
191
191
  render: renderWait, // 返回形状与 wait 同构(ok/timeout),复用同一份人读渲染
192
192
  },
193
193
  {
194
- // 修改反馈 → 重新进入执行循环:任务回到 pending,agent 可再次领取。
194
+ // 修改反馈 / 重做 / 加评论 → **新建一条任务**(新的 md),旧任务**归档**。
195
+ // 状态单向:完成等待验收之后没有回退边——不会回到「重新开始」(任务 #59)。
195
196
  id: 'localtask.reopen',
196
197
  cli: ['localtask', 'reopen'],
197
198
  http: ['POST', '/api/localtasks/reopen'],
198
199
  summary:
199
- '重开任务(用户的修改反馈):任务回到待领取,领取时间作废(新一轮重新计时);--text 可带上修改后的正文(Markdown)',
200
+ '重开任务(用户的修改反馈 / 重做 / 加评论):新建一条待领取任务(正文 = --text 给的内容),旧任务归档留档(状态单向,不回退)',
200
201
  flags: {
201
202
  id: { type: 'number', required: true, hint: '任务编号' },
202
203
  cwd: CWD,
@@ -209,7 +210,8 @@ export default {
209
210
  return reopenTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key, text: ctx.text });
210
211
  },
211
212
  render: (d) =>
212
- `已重开任务 #${d.id} @ ${d.name}(回到待领取,第 ${d.task.reopenCount} 次重开)` +
213
+ `已新建任务 #${d.id} @ ${d.name}(待领取)` +
214
+ (d.from ? `;旧任务 #${d.from.id} 已归档留档` : '') +
213
215
  (d.moved && d.movedFrom ? `;已改归属项目,原 ${d.movedFrom.name} #${d.movedFrom.id}` : ''),
214
216
  },
215
217
  {