nx-kv 0.24.1 → 0.24.2

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 (28) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/package.json +1 -1
  3. package/src/modules/docs/knowledge.js +175 -64
  4. package/src/modules/docs/refs.js +26 -3
  5. package/src/modules/repos/boards.js +25 -1
  6. package/src/modules/repos/index.js +5 -2
  7. package/src/modules/tasktool/groupctx.js +38 -4
  8. package/src/web/frontend/components/Introduction/index.jsx +5 -1
  9. package/src/web/frontend/components/Introduction/use-intro.js +31 -9
  10. package/src/web/public/assets/Introduction-Dr99GN_o.js +1 -0
  11. package/src/web/public/assets/{cloud-E33bm4CD.js → cloud-BJbs3IuB.js} +1 -1
  12. package/src/web/public/assets/{dag-ClRadqiu.js → dag-DBydHtGQ.js} +1 -1
  13. package/src/web/public/assets/{dir-Dj-3QRkO.js → dir-DgWqKcbC.js} +1 -1
  14. package/src/web/public/assets/{group-Ckwoc5tW.js → group-ji7zeaXJ.js} +1 -1
  15. package/src/web/public/assets/{index-DMp4lRKl.js → index-CHHRdALV.js} +2 -2
  16. package/src/web/public/assets/{md-history-CwtrJcZo.js → md-history-H16pOkv6.js} +1 -1
  17. package/src/web/public/assets/{member-picker-BV1a-LiO.js → member-picker-BmVwgSWB.js} +1 -1
  18. package/src/web/public/assets/{overview-CQW1MViJ.js → overview-BNovkb_k.js} +1 -1
  19. package/src/web/public/assets/{progress-CDiNmHVI.js → progress-Ck-s4Ypp.js} +1 -1
  20. package/src/web/public/assets/{repos-BYFj2sjE.js → repos-A2URD6SC.js} +1 -1
  21. package/src/web/public/assets/{route-crumb-DSgy8FTp.js → route-crumb-x1Za8gFU.js} +1 -1
  22. package/src/web/public/assets/{settings-BoAQ5YXH.js → settings-DNZkV_Be.js} +1 -1
  23. package/src/web/public/assets/{task-Br1K-bzV.js → task-BqQw-96B.js} +1 -1
  24. package/src/web/public/assets/{template-slots-CMB5ZTZE.js → template-slots-DTd6DvJ3.js} +1 -1
  25. package/src/web/public/assets/{templates-DMVIPsdx.js → templates-CHvZ38Vw.js} +1 -1
  26. package/src/web/public/assets/{upload-CzfyPGrk.js → upload-BM8dlfZG.js} +1 -1
  27. package/src/web/public/index.html +1 -1
  28. package/src/web/public/assets/Introduction-DGcd3YBk.js +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.24.2] - 2026-11-05 描述改成 md 列表
6
+
7
+ ### Changed
8
+
9
+ - **仓库 / 项目组的「描述」不再是孤零零一篇 md,而是一个 md 列表**(任务 #58):
10
+ 介绍文档集 = **主篇**(介绍目录的 `index.md` → 没有目录则旧单文件 `repo/<key>.md`
11
+ → 再没有则绑定的外部文件)+ **其余各篇**(介绍目录里的其他 md,含 `reference/` 补充说明)。
12
+ - 交付层(agent 领任务时拿到的组上下文):项目介绍 / 组介绍都按「主篇正文 + 其余各篇
13
+ 的可读路径」呈现,并标出「N 篇」;项目自己登记的补充文档也给出可读路径。
14
+ - `repo knowledge --md`:介绍按列表输出(主篇正文 + 其余各篇路径)。
15
+ - `repo doc list`:主篇 + 目录补充篇 + 登记的补充篇,一起列出。
16
+ - 面板简介区:主篇指向介绍目录的 `index.md`(存在时),目录补充篇并入同一行列表。
17
+ - 兼容:旧数据(旧单文件 + 登记的 `docLinks`)照旧可读;目录里没有 `index.md` 时,
18
+ 目录内的 md 仍算描述的一部分(不再因为少一篇主篇就把其余藏起来)。
19
+
5
20
  ## [0.24.1] - 2026-11-05 面板跨域不再拦写请求
6
21
 
7
22
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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 同一语义)——
@@ -27,10 +27,21 @@ import {
27
27
  findBoard,
28
28
  } from './service.js';
29
29
  import { badInput, notFound, conflict } from '../../core/errors.js';
30
- import { boardDocRel, groupNoteRel } from '../docs/paths.js';
30
+ import { boardDocDirRel, boardDocRel, groupNoteRel } from '../docs/paths.js';
31
+ import { readIntroSet } from '../docs/knowledge.js';
31
32
 
32
33
  const cleanText = (v) => String(v || '').trim();
33
34
 
35
+ /** 介绍文档集条目 → DocRef 形状(自有树给 rel,外部给 path) */
36
+ function introRefOut(d) {
37
+ if (!d) return null;
38
+ if (d.rel) return { rel: d.rel };
39
+ if (d.docId && String(d.docId).startsWith('rel:')) return { rel: String(d.docId).slice(4) };
40
+ if (d.path) return { path: d.path };
41
+ if (d.abs) return { path: d.abs };
42
+ return null;
43
+ }
44
+
34
45
  // 组内描述:同一个仓库在不同看板里的角色可以各不相同(「fr 组里它是 API 契约方」,
35
46
  // 「nx 组里它只是同族工具」),所以描述挂在**看板的成员关系**上(repoNotes,按 key),
36
47
  // 而不是仓库登记上。登记里的 desc 回答「这个仓库是干什么的」,
@@ -108,6 +119,15 @@ export async function getBoard(idOrKey) {
108
119
  if (!b) b = s.boards.find((x) => boardKeyOf(x.name) === normalizeKey(raw));
109
120
  if (!b) b = s.boards.find((x) => String(x.name).toLowerCase() === raw.toLowerCase());
110
121
  if (!b) throw notFound('看板不存在: ' + raw);
122
+ // 组介绍是**文档集**(主篇 + 其余各篇),不是孤立的一篇——#58
123
+ const set = await readIntroSet({
124
+ dirRel: boardDocDirRel(b.name),
125
+ legacyRel: boardDocRel(b.name),
126
+ ref: b.doc || null,
127
+ links: b.docLinks,
128
+ warnings: [],
129
+ label: `组介绍·${b.name}`,
130
+ });
111
131
  return {
112
132
  id: b.id,
113
133
  name: b.name,
@@ -115,6 +135,10 @@ export async function getBoard(idOrKey) {
115
135
  key: boardKeyOf(b.name),
116
136
  docRel: b.doc?.rel || boardDocRel(b.name),
117
137
  docPath: b.doc?.path || '',
138
+ // 介绍文档集:主篇(目录 index.md 优先)+ 其余各篇
139
+ introMain: set.main ? introRefOut(set.main) : null,
140
+ introExtras: (set.extras || []).map((d) => ({ ...introRefOut(d), name: d.name || '' })),
141
+ introCount: set.count,
118
142
  docLinks: Array.isArray(b.docLinks) ? b.docLinks : [],
119
143
  repos: membersOf(s, b),
120
144
  };
@@ -274,8 +274,11 @@ export default {
274
274
  render: (d) => {
275
275
  const one = (x, i) => ` ${i}. ${x.rel ? '自有 ' + x.rel : x.ref ? 'ref ' + x.ref + '/' + x.rel : '外部 ' + x.path}${x.tag ? ` [${x.tag}]` : ''}${x.note ? ` # ${x.note}` : ''}`;
276
276
  const lines = [`【${d.repo.name}】介绍文档 ${d.count} 篇`];
277
- if (d.main) lines.push(one(d.main, 1));
278
- d.links.forEach((x, i) => lines.push(one(x, i + 2)));
277
+ // 描述是**列表**:主篇 + 介绍目录里的其余 + 登记的补充(#58)
278
+ let n = 0;
279
+ if (d.main) lines.push(one(d.main, ++n));
280
+ for (const x of d.extras || []) lines.push(one(x, ++n));
281
+ for (const x of d.links || []) lines.push(one(x, ++n));
279
282
  return lines.join('\n');
280
283
  },
281
284
  },
@@ -45,6 +45,33 @@ export async function readGroupContext(cwd) {
45
45
  }
46
46
  }
47
47
 
48
+ /**
49
+ * 介绍段:主篇(正文)+ 其余各篇(可读路径)。
50
+ * 描述是**文档集**(主篇 + 其余 md),不是孤立的一篇——#58。
51
+ * @param {string} header 段标题(如「组介绍」/「〔项目介绍 · x〕」)
52
+ * @param {{body: string, path: string}} intro 主篇
53
+ * @param {{count?: number, extras?: Array}|null} set 文档集
54
+ * @returns {string[]} 渲染行
55
+ */
56
+ function introLines(header, intro, set) {
57
+ const out = [];
58
+ const extras = (set && set.extras) || [];
59
+ const count = (set && set.count) || (extras.length ? extras.length + 1 : 1);
60
+ const path = intro.path || 'docs';
61
+ if (count > 1) {
62
+ out.push(`${header}(${count} 篇)`);
63
+ out.push(`主篇(${path}):`);
64
+ } else {
65
+ out.push(`${header}(${path}):`);
66
+ }
67
+ out.push(clipIntro(intro.body, intro.path));
68
+ if (extras.length) {
69
+ out.push('其余介绍文档(可直接读取):');
70
+ for (const d of extras) out.push(` - ${d.abs || d.docId || d.rel || ''}`);
71
+ }
72
+ return out;
73
+ }
74
+
48
75
  /**
49
76
  * 把组上下文渲染成交付文本里的一段。
50
77
  * 结构:项目介绍 → 组概念 → 本项目位置 → 兄弟成员 → 参考文件地址。
@@ -55,9 +82,17 @@ export function renderGroupContext(ctx) {
55
82
  if (!ctx) return '';
56
83
  const lines = [];
57
84
  const repo = ctx.repo || {};
85
+ // 项目介绍:**主篇 + 其余各篇**(描述是 md 列表,不是一篇——#58)
58
86
  if (repo.intro && repo.intro.body) {
59
- lines.push(`〔项目介绍 · ${repo.name || repo.key || ''}〕${repo.intro.path ? `(${repo.intro.path})` : ''}:`);
60
- lines.push(clipIntro(repo.intro.body, repo.intro.path));
87
+ lines.push(...introLines(`〔项目介绍 · ${repo.name || repo.key || ''}〕`, repo.intro, repo.introSet));
88
+ lines.push('');
89
+ }
90
+ // 项目自己登记的补充文档(外部 / ref 仓库里的文件)——给可读路径,agent 直接读盘
91
+ if (repo.docLinks && repo.docLinks.length) {
92
+ lines.push('项目补充文档(可直接读取):');
93
+ for (const d of repo.docLinks) {
94
+ lines.push(` - ${d.abs || d.rel}${d.tag ? ` [${d.tag}]` : ''}${d.note ? ` # ${d.note}` : ''}`);
95
+ }
61
96
  lines.push('');
62
97
  }
63
98
  if (!ctx.groups || !ctx.groups.length) return lines.join('\n').trim();
@@ -65,8 +100,7 @@ export function renderGroupContext(ctx) {
65
100
  lines.push(`〔项目组上下文 · ${g.name}〕`);
66
101
  if (g.desc) lines.push(`组定位:${g.desc}`);
67
102
  if (g.intro && g.intro.body) {
68
- lines.push(`组介绍(${g.intro.path || 'docs'}):`);
69
- lines.push(clipIntro(g.intro.body, g.intro.path));
103
+ lines.push(...introLines('组介绍', g.intro, g.introSet));
70
104
  }
71
105
  if (g.note) lines.push(`本项目在组里的位置:${g.note}`);
72
106
  if (g.peers && g.peers.length) {
@@ -20,7 +20,11 @@ export default function Introduction({ kind, owner, model }) {
20
20
 
21
21
  if (!owner || !docRef) return null;
22
22
 
23
- const pathLabel = docRef.startsWith('rel:') ? docRef.slice(4) : docRef;
23
+ // 主篇以「介绍文档集」为准(目录 index.md 优先 → 旧单文件回落)——
24
+ // 路径标签显示的必须是真正的主篇那篇。
25
+ const mainEntry = links.find((l) => l.main);
26
+ const mainRef = mainEntry ? mainEntry.docId : docRef;
27
+ const pathLabel = mainRef.startsWith('rel:') ? mainRef.slice(4) : mainRef;
24
28
  const extras = links.filter((l) => !l.main);
25
29
  const onAdd = () => addRef(dialog, toast).catch((e) => toast(String(e.message || e)));
26
30
 
@@ -48,6 +48,9 @@ export function useIntro({ kind, owner, model }) {
48
48
  const docRef = useMemo(() => introRefOf(owner, kind), [owner, kind]);
49
49
 
50
50
  const [links, setLinks] = useState([]); // [{ docId, label, note, main }]
51
+ // 主篇 docId:以后端返回的「介绍文档集」为准(目录 index.md 优先,
52
+ // 旧单文件回落);拿不到才用 prop 推的 docRef。
53
+ const [mainDocId, setMainDocId] = useState("");
51
54
  const [tick, setTick] = useState(0);
52
55
 
53
56
  const reload = useCallback(() => setTick((n) => n + 1), []);
@@ -64,10 +67,18 @@ export function useIntro({ kind, owner, model }) {
64
67
  .then((d) => {
65
68
  if (!alive) return;
66
69
  const out = [];
67
- if (d.main) {
68
- const id = linkDocId(d.main);
69
- if (id) out.push({ docId: id, label: d.main.rel || d.main.path || '主篇', note: d.main.note || '', tag: d.main.tag || '', main: true, ref: d.main.ref || '' });
70
+ // 主篇:文档集的主篇(目录 index.md 优先 → 旧单文件回落)
71
+ const mid = linkDocId(d.main);
72
+ setMainDocId(mid || docRef);
73
+ if (mid) {
74
+ out.push({ docId: mid, label: d.main.rel || d.main.path || '主篇', note: d.main.note || '', tag: d.main.tag || '', main: true, ref: d.main.ref || '' });
70
75
  }
76
+ // 其余:介绍目录里的补充说明(同一目录下的其他 md)
77
+ for (const l of d.extras || []) {
78
+ const id = linkDocId(l);
79
+ if (id) out.push({ docId: id, label: l.name || l.rel || l.path || '补充', note: l.note || '', tag: l.tag || '', main: false, ref: l.ref || '' });
80
+ }
81
+ // 登记在册的补充文档(外部 / ref 仓库里的文件)
71
82
  for (const l of d.links || []) {
72
83
  const id = linkDocId(l);
73
84
  // ref 随条目留着:ref 形态的链接(参考仓库内文件)不能按 rel 回写,标签编辑要对它关掉
@@ -75,7 +86,7 @@ export function useIntro({ kind, owner, model }) {
75
86
  }
76
87
  setLinks(out);
77
88
  })
78
- .catch(() => { if (alive) setLinks([]); });
89
+ .catch(() => { if (alive) { setLinks([]); setMainDocId(docRef); } });
79
90
  } else {
80
91
  // board 分支拉实时数据(GET /api/boards/:id)而不是读 owner prop——
81
92
  // owner 是父层的 repoData 快照,addRef / 改 tag 后不会自动刷新:
@@ -95,10 +106,19 @@ export function useIntro({ kind, owner, model }) {
95
106
  const links = Array.isArray(bd && bd.docLinks) ? bd.docLinks : null;
96
107
  if (!links) {
97
108
  setLinks(fromOwner());
109
+ setMainDocId(docRef);
98
110
  return;
99
111
  }
100
112
  const out = [];
101
- if (docRef) out.push({ docId: docRef, label: '主篇', note: '', tag: '', main: true, ref: '' });
113
+ // 主篇:文档集的主篇(目录 index.md 优先 → 旧单文件回落)
114
+ const mid = linkDocId(bd && bd.introMain) || docRef;
115
+ setMainDocId(mid);
116
+ if (mid) out.push({ docId: mid, label: '主篇', note: '', tag: '', main: true, ref: '' });
117
+ // 其余:介绍目录里的补充说明
118
+ for (const l of (bd && bd.introExtras) || []) {
119
+ const id = linkDocId(l);
120
+ if (id) out.push({ docId: id, label: l.name || l.rel || l.path || '补充', note: l.note || '', tag: l.tag || '', main: false, ref: l.ref || '' });
121
+ }
102
122
  // ref 随条目留着:ref 形态的链接(参考仓库内文件)不能按 rel 回写,标签编辑要对它关掉
103
123
  for (const l of links) {
104
124
  const id = linkDocId(l);
@@ -106,7 +126,7 @@ export function useIntro({ kind, owner, model }) {
106
126
  }
107
127
  setLinks(out);
108
128
  })
109
- .catch(() => { if (alive) setLinks(fromOwner()); });
129
+ .catch(() => { if (alive) { setLinks(fromOwner()); setMainDocId(docRef); } });
110
130
  }
111
131
  return () => { alive = false; };
112
132
  }, [kind, ownerKey, owner, docRef, tick]);
@@ -119,9 +139,10 @@ export function useIntro({ kind, owner, model }) {
119
139
 
120
140
  /** 打开主篇(缺文档时 DocPanel 给「创建骨架」) */
121
141
  const openMain = useCallback(() => {
122
- if (!docRef) return;
123
- openByDocId(docRef, null, openExtra);
124
- }, [docRef, openByDocId, openExtra]);
142
+ const target = mainDocId || docRef;
143
+ if (!target) return;
144
+ openByDocId(target, null, openExtra);
145
+ }, [mainDocId, docRef, openByDocId, openExtra]);
125
146
 
126
147
  const openDoc = useCallback(
127
148
  (id) => openByDocId(id, null, openExtra),
@@ -192,6 +213,7 @@ export function useIntro({ kind, owner, model }) {
192
213
  label,
193
214
  ownerKey,
194
215
  docRef,
216
+ mainDocId,
195
217
  links,
196
218
  openMain,
197
219
  openDoc,