nx-kv 0.24.0 → 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.
- package/CHANGELOG.md +34 -0
- package/README.md +21 -0
- package/package.json +1 -1
- package/src/modules/docs/knowledge.js +175 -64
- package/src/modules/docs/refs.js +26 -3
- package/src/modules/repos/boards.js +25 -1
- package/src/modules/repos/index.js +5 -2
- package/src/modules/tasktool/groupctx.js +38 -4
- package/src/runtime/api.js +6 -23
- package/src/runtime/cli.js +8 -3
- package/src/runtime/cors.js +125 -0
- package/src/runtime/server.js +14 -1
- package/src/web/frontend/components/Introduction/index.jsx +5 -1
- package/src/web/frontend/components/Introduction/use-intro.js +31 -9
- package/src/web/public/assets/Introduction-Dr99GN_o.js +1 -0
- package/src/web/public/assets/{cloud-E33bm4CD.js → cloud-BJbs3IuB.js} +1 -1
- package/src/web/public/assets/{dag-ClRadqiu.js → dag-DBydHtGQ.js} +1 -1
- package/src/web/public/assets/{dir-Dj-3QRkO.js → dir-DgWqKcbC.js} +1 -1
- package/src/web/public/assets/{group-Ckwoc5tW.js → group-ji7zeaXJ.js} +1 -1
- package/src/web/public/assets/{index-DMp4lRKl.js → index-CHHRdALV.js} +2 -2
- package/src/web/public/assets/{md-history-CwtrJcZo.js → md-history-H16pOkv6.js} +1 -1
- package/src/web/public/assets/{member-picker-BV1a-LiO.js → member-picker-BmVwgSWB.js} +1 -1
- package/src/web/public/assets/{overview-CQW1MViJ.js → overview-BNovkb_k.js} +1 -1
- package/src/web/public/assets/{progress-CDiNmHVI.js → progress-Ck-s4Ypp.js} +1 -1
- package/src/web/public/assets/{repos-BYFj2sjE.js → repos-A2URD6SC.js} +1 -1
- package/src/web/public/assets/{route-crumb-DSgy8FTp.js → route-crumb-x1Za8gFU.js} +1 -1
- package/src/web/public/assets/{settings-BoAQ5YXH.js → settings-DNZkV_Be.js} +1 -1
- package/src/web/public/assets/{task-Br1K-bzV.js → task-BqQw-96B.js} +1 -1
- package/src/web/public/assets/{template-slots-CMB5ZTZE.js → template-slots-DTd6DvJ3.js} +1 -1
- package/src/web/public/assets/{templates-DMVIPsdx.js → templates-CHvZ38Vw.js} +1 -1
- package/src/web/public/assets/{upload-CzfyPGrk.js → upload-BM8dlfZG.js} +1 -1
- package/src/web/public/index.html +1 -1
- package/src/web/public/assets/Introduction-DGcd3YBk.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
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
|
+
|
|
20
|
+
## [0.24.1] - 2026-11-05 面板跨域不再拦写请求
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **面板写请求不再因 Origin 跨站被拒(任务 #57)**:原先按 `Origin` 的主机名是不是
|
|
25
|
+
`127.0.0.1` 判「跨站」并回 403。但浏览器对 POST/PUT/DELETE **一律带 `Origin`**——
|
|
26
|
+
走内网穿透(frp / cloudflared / ngrok)从手机或外网访问面板时,`Origin` 是隧道域名,
|
|
27
|
+
**自己面板的同源写请求**也被判成跨站 → 从外网提交任务直接失败。现在:
|
|
28
|
+
- 不再按 `Origin` 拒绝写请求;跨域交给标准 CORS 处理(`OPTIONS` 预检 +
|
|
29
|
+
`access-control-allow-origin`),浏览器跨源提交能真正走通。
|
|
30
|
+
- 同源请求(含隧道同源)**根本不预检**,直接放行——内网穿透 / 移动端访问恢复。
|
|
31
|
+
- 非浏览器客户端(curl / 原生 App)本来不带 `Origin`,不受影响。
|
|
32
|
+
- **新增 `nx-kv serve --allow-origin <origin>`**:需要收紧时只放行指定来源
|
|
33
|
+
(逗号分隔,支持 `https://*.example.com` 通配);缺省仍放行全部。
|
|
34
|
+
|
|
35
|
+
> 边界提示:面板只绑 `127.0.0.1`,是本机工具。**经内网穿透暴露到公网后,真正的边界是
|
|
36
|
+
> 隧道自身的访问控制**(访问密码 / basic auth / IP 白名单)——任何非浏览器客户端都能
|
|
37
|
+
> 直接调 API,从头到尾不经过 `Origin` 校验。
|
|
38
|
+
|
|
5
39
|
## [0.24.0] - 2026-11-05 进程面板支持项目组
|
|
6
40
|
|
|
7
41
|
### Added
|
package/README.md
CHANGED
|
@@ -35,6 +35,27 @@ pnpm test
|
|
|
35
35
|
|
|
36
36
|
`--no-open` 只关这一次;`NX_SERVE_NO_OPEN=1`(`true` / `yes` / `on` 同义)则是**所有 nx-xx 项目共用**的全局开关,设为真值后 `serve` 完全不开浏览器。
|
|
37
37
|
|
|
38
|
+
### 跨域(内网穿透 / 移动端访问)
|
|
39
|
+
|
|
40
|
+
面板的写请求**不再按 `Origin` 判定「跨站」并拒绝**。原先那道校验比对 `Origin` 的
|
|
41
|
+
主机名是不是 `127.0.0.1`,但浏览器对 POST/PUT/DELETE **一律带 `Origin`**——经内网穿透
|
|
42
|
+
(frp / cloudflared / ngrok)从手机访问时 `Origin` 是隧道域名,**自己面板的同源写请求**
|
|
43
|
+
也被判成跨站而 403,任务提交不了。
|
|
44
|
+
|
|
45
|
+
现在的口径:
|
|
46
|
+
|
|
47
|
+
- 同源请求(含隧道同源)**不预检**,直接放行;
|
|
48
|
+
- 跨源请求走标准 CORS:先 `OPTIONS` 预检,服务端回 `access-control-allow-origin` 才放行;
|
|
49
|
+
- 非浏览器客户端(curl / 原生 App)不带 `Origin`,本来就不受限。
|
|
50
|
+
|
|
51
|
+
要收紧来源时用 `--allow-origin`(逗号分隔,支持 `https://*.example.com` 通配;缺省放行全部):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
nx-kv serve --allow-origin https://panel.example.com
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> 面板只绑 `127.0.0.1`,是本机工具。**经内网穿透暴露到公网后,真正的边界是隧道自身的
|
|
58
|
+
> 访问控制**(访问密码 / basic auth / IP 白名单)——非浏览器客户端从不经过 `Origin` 校验。
|
|
38
59
|
## 登录
|
|
39
60
|
|
|
40
61
|
```bash
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
192
|
+
lines.push(...introMdLines(k.introSet, k.intro));
|
|
175
193
|
for (const b of k.boards) {
|
|
176
194
|
heading(`## 组:${b.name}`);
|
|
177
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
297
|
+
* dirRel 介绍目录(自有树内):repo/<key> · board/<组 slug>
|
|
282
298
|
* legacyRel 旧单文件路径(读时回落,保证既有数据继续可用)
|
|
283
299
|
* ref DocRef 覆盖(绑定的文件或目录);给了就以它为准
|
|
284
300
|
*
|
|
285
|
-
* 返回 { main
|
|
286
|
-
* main = 主篇(目录 index.md
|
|
287
|
-
* extras =
|
|
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
|
-
|
|
290
|
-
|
|
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
|
|
296
|
-
return {
|
|
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
|
|
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
|
|
304
|
-
return {
|
|
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
|
|
309
|
-
const others = files.filter((f) => f !==
|
|
310
|
-
const mainDoc =
|
|
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
|
|
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
|
-
|
|
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
|
|
377
|
+
const extras = extrasOf(mainRel);
|
|
328
378
|
return {
|
|
329
|
-
main: {
|
|
330
|
-
extras
|
|
331
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/src/modules/docs/refs.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
278
|
-
|
|
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 || ''}
|
|
60
|
-
lines.push(
|
|
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(
|
|
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) {
|
package/src/runtime/api.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 所以「面板上有按钮、CLI 里没命令」在结构上不可能发生。
|
|
5
5
|
import { ACTIONS } from './registry.js';
|
|
6
6
|
import { compileRoute, applySpec } from './spec.js';
|
|
7
|
-
import { toErrorPayload, httpStatusOf
|
|
7
|
+
import { toErrorPayload, httpStatusOf } from '../core/errors.js';
|
|
8
8
|
|
|
9
9
|
// 逐段比较两条模式,决定谁该先匹配:**字面量段优先于参数段**,段数多的优先。
|
|
10
10
|
//
|
|
@@ -56,20 +56,6 @@ async function readBody(req) {
|
|
|
56
56
|
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// 跨站防护。服务虽然只绑 127.0.0.1,但用户浏览器里的任意页面都能向它发起请求——
|
|
60
|
-
// 少了这道校验,一个恶意网页就能 POST /api/repos/scan 或 DELETE /api/repos/:id。
|
|
61
|
-
// 浏览器发跨域请求必带 Origin,非浏览器客户端(curl / agent / 测试)不带,故放行。
|
|
62
|
-
function originAllowed(req) {
|
|
63
|
-
const origin = req.headers.origin;
|
|
64
|
-
if (!origin) return true;
|
|
65
|
-
try {
|
|
66
|
-
const h = new URL(origin).hostname;
|
|
67
|
-
return h === '127.0.0.1' || h === 'localhost' || h === '::1';
|
|
68
|
-
} catch {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
59
|
export async function handleApi(req, res, url) {
|
|
74
60
|
const method = (req.method || 'GET').toUpperCase();
|
|
75
61
|
|
|
@@ -78,14 +64,11 @@ export async function handleApi(req, res, url) {
|
|
|
78
64
|
const m = route.regex.exec(url.pathname);
|
|
79
65
|
if (!m) continue;
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
67
|
+
// 这里不再按 Origin 拒绝写请求(任务 #57)。
|
|
68
|
+
// 原先那道校验比对 Origin 主机名是不是 127.0.0.1——但浏览器对 POST 一律带
|
|
69
|
+
// Origin(哪怕同源),于是走内网穿透从手机访问时 Origin 是隧道域名,
|
|
70
|
+
// 自己面板的同源写请求被判成跨站 → 403,任务提交不了。
|
|
71
|
+
// 跨域改由标准 CORS 头处理(预检 + allow-origin),见 runtime/cors.js。
|
|
89
72
|
|
|
90
73
|
try {
|
|
91
74
|
const raw = {};
|