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.
- package/CHANGELOG.md +30 -0
- package/assets/kv-get/SKILL.md +9 -4
- package/package.json +1 -1
- package/src/core/workflow/readiness.js +10 -2
- package/src/core/workflow/types.js +3 -1
- package/src/modules/docs/knowledge.js +175 -64
- package/src/modules/docs/refs.js +26 -3
- package/src/modules/localtask/index.js +5 -3
- package/src/modules/localtask/task-lifecycle.js +63 -31
- package/src/modules/localtask/task-view.js +15 -4
- 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/web/frontend/components/Introduction/index.jsx +5 -1
- package/src/web/frontend/components/Introduction/use-intro.js +31 -9
- package/src/web/frontend/modules/board/board-view.js +7 -2
- package/src/web/frontend/page/dir/index.jsx +8 -14
- package/src/web/frontend/page/dir/landing.jsx +8 -5
- package/src/web/frontend/page/dir/task.jsx +13 -17
- package/src/web/public/assets/Introduction-DK2deIP2.js +1 -0
- package/src/web/public/assets/{cloud-E33bm4CD.js → cloud-BoIeutoa.js} +1 -1
- package/src/web/public/assets/{dag-ClRadqiu.js → dag-DC3tN4dI.js} +1 -1
- package/src/web/public/assets/dir-BbDWEJOC.js +3 -0
- package/src/web/public/assets/{group-Ckwoc5tW.js → group-C30SuifL.js} +1 -1
- package/src/web/public/assets/{index-DMp4lRKl.js → index-DFMD9MV2.js} +3 -3
- package/src/web/public/assets/{md-history-CwtrJcZo.js → md-history-DBs3hhRL.js} +1 -1
- package/src/web/public/assets/{member-picker-BV1a-LiO.js → member-picker-xneI-u00.js} +1 -1
- package/src/web/public/assets/{overview-CQW1MViJ.js → overview-Ai76EDG0.js} +1 -1
- package/src/web/public/assets/{progress-CDiNmHVI.js → progress-DRKqpuh_.js} +1 -1
- package/src/web/public/assets/{repos-BYFj2sjE.js → repos-CMmB-5Nj.js} +1 -1
- package/src/web/public/assets/{route-crumb-DSgy8FTp.js → route-crumb-D3TTGwPj.js} +1 -1
- package/src/web/public/assets/{settings-BoAQ5YXH.js → settings-D81FsMru.js} +1 -1
- package/src/web/public/assets/task-w3pgQWfV.js +5 -0
- package/src/web/public/assets/{template-slots-CMB5ZTZE.js → template-slots-DLN_zed3.js} +1 -1
- package/src/web/public/assets/{templates-DMVIPsdx.js → templates-DnYaTa0s.js} +1 -1
- package/src/web/public/assets/{upload-CzfyPGrk.js → upload-DAjZdYV0.js} +1 -1
- package/src/web/public/index.html +1 -1
- package/src/web/public/assets/Introduction-DGcd3YBk.js +0 -1
- package/src/web/public/assets/dir-Dj-3QRkO.js +0 -3
- package/src/web/public/assets/task-Br1K-bzV.js +0 -5
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
// (#54 自 service.js 拆出)队列出口的任务生命周期:consumeFirstPending(D-first 领取,
|
|
2
2
|
// 跳过被依赖/闸门挡住的 pending)、completeTask(完成门禁:timegoal 未到点返回 blocked
|
|
3
|
-
// 业务值而不是抛错)、reopenTask(用户修改反馈 →
|
|
3
|
+
// 业务值而不是抛错)、reopenTask(用户修改反馈 → **新建一条任务**,旧任务归档)。
|
|
4
4
|
import { badInput, notFound } from '../../core/errors.js';
|
|
5
5
|
import { formatDuration } from '../../core/instruction-template.js';
|
|
6
6
|
import { preserveFrontmatter } from '../../shared/frontmatter.js';
|
|
7
7
|
import { findFirstReadyPending } from './dag.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { basename } from 'node:path';
|
|
9
|
+
import { isGlobalKey, resolveTaskKey, topicKeyFor } from './paths.js';
|
|
10
|
+
import { loadStore, saveStore, stampNow, normalizeSummary, normalizeText, bumpWorkflowRevision, topicOf, nextTaskId } from './store-io.js';
|
|
11
|
+
import { normalizeTask, foreignResolver, isPending } from './task-view.js';
|
|
12
|
+
import { normalizeBlockBy } from './dag.js';
|
|
11
13
|
import { markConsumed } from './waiters.js';
|
|
12
|
-
// 把一条任务重新开放(用户的**修改反馈**
|
|
14
|
+
// 把一条任务重新开放(用户的**修改反馈** / 重做 / 加评论)。
|
|
13
15
|
//
|
|
14
|
-
//
|
|
15
|
-
// -
|
|
16
|
-
//
|
|
17
|
-
// -
|
|
18
|
-
//
|
|
19
|
-
//
|
|
16
|
+
// 语义(任务 #59):**新建一条任务**(新的 md),旧任务**归档**——状态只往前。
|
|
17
|
+
// - 旧任务:状态前进到终态 archived,正文、完成总结、领取记录**一个字都不动**(留档);
|
|
18
|
+
// 它不会再回到「重新开始」,也就没有「完成等待验收 → 重新开始」这条回退边。
|
|
19
|
+
// - 新任务:正文 = 调用方拼好的(面板口径:原正文 + 上一轮完成总结 + 本轮反馈),
|
|
20
|
+
// forkOf 指回上一条('队列key:旧编号'),supersededBy 记在旧任务上。
|
|
21
|
+
// - 落点:默认同主题;带改过归属(moveTo)就落那边——归属决定落点。
|
|
22
|
+
//
|
|
23
|
+
// 为什么不再「就地改同一条、把状态翻回 pending」:
|
|
24
|
+
// 1. 那是**回退边**——完成等待验收的任务被拉回重新开始,历史被抹掉;
|
|
25
|
+
// 2. 就地改写会覆盖旧正文——上轮做过什么、用户评了什么,都被新正文吃掉;
|
|
26
|
+
// 3. 现在链条可追:旧任务留档、新任务指回它,状态机 pending → consumed → archived。
|
|
20
27
|
export async function reopenTask({ cwd: rawCwd, key: rawKey, id, text, moveTo } = {}) {
|
|
21
28
|
const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
|
|
22
29
|
const want = Number(id);
|
|
@@ -24,32 +31,54 @@ export async function reopenTask({ cwd: rawCwd, key: rawKey, id, text, moveTo }
|
|
|
24
31
|
const store = await loadStore();
|
|
25
32
|
const t = store.topics[key];
|
|
26
33
|
if (!t) throw notFound('主题不存在: ' + key);
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// 改文案不该把 frontmatter 一起改没——归组信息(board/project/介绍引用)保住,
|
|
32
|
-
// 新正文自带的 frontmatter 优先。丢了它任务就从组 / 项目面板里掉出去。
|
|
33
|
-
task.text = preserveFrontmatter(task.text, normalizeText(text));
|
|
34
|
+
const old = t.tasks.find((x) => Number(x.id) === want);
|
|
35
|
+
if (!old || old.deletedAt) throw notFound('任务不存在或已删除: #' + want);
|
|
36
|
+
if (old.status === 'archived') {
|
|
37
|
+
throw badInput(`#${want} 已归档(被新任务取代)——不能再重开;要继续做请新建任务`);
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
task.lastReopenedAt = stampNow();
|
|
40
|
-
// 归属变了(reopen 的正文可能带着改过的 project)→ 先翻回待领取再搬家,
|
|
41
|
-
// 搬家守卫按 pending 口径放行;同一主题 → 不搬。
|
|
39
|
+
const before = { status: old.status, consumedAt: old.consumedAt || '', completedAt: old.completedAt || '' };
|
|
40
|
+
const body = String(text ?? '').trim();
|
|
41
|
+
|
|
42
|
+
// 落点:默认同主题;带改过归属(moveTo)就落那边——归属决定落点。
|
|
42
43
|
let host = t;
|
|
43
44
|
let moved = false;
|
|
44
45
|
let movedFrom = null;
|
|
45
|
-
if (moveTo) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
host =
|
|
46
|
+
if (moveTo && moveTo.cwd) {
|
|
47
|
+
const toKey = topicKeyFor(basename(String(moveTo.cwd)));
|
|
48
|
+
if (toKey !== t.key) {
|
|
49
|
+
host = topicOf(store, toKey, moveTo.cwd, moveTo.name || '');
|
|
49
50
|
moved = true;
|
|
50
51
|
movedFrom = { key, name: t.name, id: want };
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
// 新任务:正文用调用方拼好的(面板口径 = 原正文 + 上一轮完成总结 + 本轮反馈);
|
|
56
|
+
// 没给正文就沿用旧正文(只归档、不改内容)。
|
|
57
|
+
const newId = nextTaskId(host.tasks);
|
|
58
|
+
const forked = normalizeTask({
|
|
59
|
+
id: newId,
|
|
60
|
+
text: body ? preserveFrontmatter(old.text, normalizeText(body)) : old.text,
|
|
61
|
+
status: 'pending',
|
|
62
|
+
createdAt: stampNow(),
|
|
63
|
+
forkOf: `${key}:${want}`,
|
|
64
|
+
// 同一件活,约束也接着走:
|
|
65
|
+
// timegoal 时间目标继承——新任务从**再次领取**开始重新计时(与旧口径一致)
|
|
66
|
+
// blocksFollowing 闸门继承——旧任务归档后不再挡人,闸门得由新任务接着当
|
|
67
|
+
// blockBy 上游依赖继承(去掉指向自己的那条)
|
|
68
|
+
timegoal: old.timegoal || null,
|
|
69
|
+
blocksFollowing: !!old.blocksFollowing,
|
|
70
|
+
blockBy: normalizeBlockBy(old.blockBy, newId),
|
|
71
|
+
});
|
|
72
|
+
host.tasks.push(forked);
|
|
73
|
+
|
|
74
|
+
// 旧任务:**前进**到终态(归档)。正文与完成总结一个字都不动——留档。
|
|
75
|
+
old.status = 'archived';
|
|
76
|
+
old.archivedAt = stampNow();
|
|
77
|
+
old.archivedReason = 'superseded';
|
|
78
|
+
old.supersededBy = { key: host.key, id: newId };
|
|
79
|
+
old.reopenCount = (Number(old.reopenCount) || 0) + 1;
|
|
80
|
+
old.lastReopenedAt = stampNow();
|
|
81
|
+
|
|
53
82
|
host.updatedAt = stampNow();
|
|
54
83
|
bumpWorkflowRevision(host);
|
|
55
84
|
if (host !== t) bumpWorkflowRevision(t);
|
|
@@ -57,13 +86,16 @@ export async function reopenTask({ cwd: rawCwd, key: rawKey, id, text, moveTo }
|
|
|
57
86
|
return {
|
|
58
87
|
status: 'ok',
|
|
59
88
|
reopened: true,
|
|
60
|
-
|
|
89
|
+
forked: true,
|
|
90
|
+
id: newId, // 新任务编号(面板据此切到新的 md)
|
|
61
91
|
key: host.key,
|
|
62
92
|
name: host.name,
|
|
63
93
|
before,
|
|
94
|
+
from: { key, id: want }, // 上一条(已归档)
|
|
64
95
|
moved,
|
|
65
96
|
movedFrom,
|
|
66
|
-
task: normalizeTask(
|
|
97
|
+
task: normalizeTask(forked, host.tasks),
|
|
98
|
+
archived: normalizeTask(old, t.tasks),
|
|
67
99
|
};
|
|
68
100
|
}
|
|
69
101
|
// 取走该主题第一条 pending;没有则返回 null。roundSummary 显式指定本轮完成总结,
|
|
@@ -11,7 +11,8 @@ import { stampNow, parseStampMs, topicOf, nextTaskId } from './store-io.js';
|
|
|
11
11
|
// 也省得存一份会漂移的冗余副本。
|
|
12
12
|
// 只有真的被领走的才有值;还没被领的返回 null(那是"还在等",由使用方按当前时间算)。
|
|
13
13
|
function pickupSecOf(t) {
|
|
14
|
-
|
|
14
|
+
// 归档的任务也是被领走过(consumedAt 保留)——领取耗时照旧算。
|
|
15
|
+
if (!t || (t.status !== 'consumed' && t.status !== 'archived')) return null;
|
|
15
16
|
const created = parseStampMs(t.createdAt);
|
|
16
17
|
const consumed = parseStampMs(t.consumedAt);
|
|
17
18
|
if (!Number.isFinite(created) || !Number.isFinite(consumed)) return null;
|
|
@@ -94,7 +95,9 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
|
|
|
94
95
|
const base = {
|
|
95
96
|
id: Number(t.id) || 0,
|
|
96
97
|
text: String(t.text ?? ''),
|
|
97
|
-
|
|
98
|
+
// 状态词汇:pending → consumed(已领取)→ archived(终态:被新任务取代)。
|
|
99
|
+
// **单向**:没有回退边——完成等待验收之后只能往前(归档),不能回 pending(#59)。
|
|
100
|
+
status: t.status === 'consumed' ? 'consumed' : t.status === 'archived' ? 'archived' : 'pending',
|
|
98
101
|
roundSummary: String(t.roundSummary ?? ''),
|
|
99
102
|
createdAt: String(t.createdAt ?? ''),
|
|
100
103
|
consumedAt: String(t.consumedAt ?? ''),
|
|
@@ -119,7 +122,14 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
|
|
|
119
122
|
timegoal: sanitizeTaskGoal(t.timegoal),
|
|
120
123
|
// 完成标记(localtask done 写入):带时间目标的任务未到点会被拒绝,写不进来。
|
|
121
124
|
completedAt: String(t.completedAt ?? ''),
|
|
122
|
-
//
|
|
125
|
+
// 重开轨迹:现在重开 = **新建一条任务**,旧任务归档(#59)。
|
|
126
|
+
// forkOf 这条是从哪一条派生的('队列key:旧编号')
|
|
127
|
+
// supersededBy 被哪一条取代(归档那条的落点:{ key, id })
|
|
128
|
+
// archivedAt / archivedReason 归档时刻与原因
|
|
129
|
+
forkOf: String(t.forkOf ?? ''),
|
|
130
|
+
supersededBy: t.supersededBy && typeof t.supersededBy === 'object' ? t.supersededBy : null,
|
|
131
|
+
archivedAt: String(t.archivedAt ?? ''),
|
|
132
|
+
archivedReason: String(t.archivedReason ?? ''),
|
|
123
133
|
reopenCount: Number(t.reopenCount) || 0,
|
|
124
134
|
lastReopenedAt: String(t.lastReopenedAt ?? ''),
|
|
125
135
|
// DAG / 闸门(#34):blockBy=依赖 id;blocksFollowing=挡住数组其后所有 pending
|
|
@@ -141,7 +151,8 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
|
|
|
141
151
|
// pending 的统一判据:未领取、未删除、未迁出。
|
|
142
152
|
// 迁出(tombstone)不算活——它不会被派发,也不该阻塞主题删除或挡住 prune。
|
|
143
153
|
export function isPending(t) {
|
|
144
|
-
|
|
154
|
+
// 归档(archived)是终态:不再算待领取——否则归档的任务会被重新派发(#59)。
|
|
155
|
+
return t.status !== 'consumed' && t.status !== 'archived' && !t.deletedAt && !t.migratedTo;
|
|
145
156
|
}
|
|
146
157
|
|
|
147
158
|
// 主题的截止时刻(epoch ms)。优先用 waitingUntilMs(毫秒精度,新数据都有),
|
|
@@ -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) {
|
|
@@ -20,7 +20,11 @@ export default function Introduction({ kind, owner, model }) {
|
|
|
20
20
|
|
|
21
21
|
if (!owner || !docRef) return null;
|
|
22
22
|
|
|
23
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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,
|
|
@@ -69,8 +69,10 @@ export function withGlobalRow(rows) {
|
|
|
69
69
|
export function splitQueueTasks(tasks = []) {
|
|
70
70
|
const list = Array.isArray(tasks) ? tasks : [];
|
|
71
71
|
return {
|
|
72
|
-
pending: list.filter((t) => t.status !== 'consumed' && !t.deletedAt && !t.migratedTo),
|
|
72
|
+
pending: list.filter((t) => t.status !== 'consumed' && t.status !== 'archived' && !t.deletedAt && !t.migratedTo),
|
|
73
73
|
consumed: list.filter((t) => t.status === 'consumed' && !t.deletedAt).slice().reverse(),
|
|
74
|
+
// 归档(#59):被新任务取代的旧任务——终态留档,不再算进行中
|
|
75
|
+
archived: list.filter((t) => t.status === 'archived' && !t.deletedAt).slice().reverse(),
|
|
74
76
|
deleted: list.filter((t) => !!t.deletedAt).slice().reverse(),
|
|
75
77
|
// 迁出记录(tombstone):原条目留在队列里但已不算待领取,看板渲染成
|
|
76
78
|
// 虚线灰卡「已迁移 → …」,可跳转/移除/撤销。保持队列原序(正序)。
|
|
@@ -97,15 +99,18 @@ export function sortTasksForDisplay(tasks = []) {
|
|
|
97
99
|
const list = Array.isArray(tasks) ? tasks : [];
|
|
98
100
|
const pending = [];
|
|
99
101
|
const consumed = [];
|
|
102
|
+
const archived = [];
|
|
100
103
|
const migrated = [];
|
|
101
104
|
const deleted = [];
|
|
102
105
|
for (const t of list) {
|
|
103
106
|
if (t.deletedAt) deleted.push(t);
|
|
104
107
|
else if (t.status === 'consumed') consumed.push(t);
|
|
108
|
+
else if (t.status === 'archived') archived.push(t);
|
|
105
109
|
else if (t.migratedTo) migrated.push(t);
|
|
106
110
|
else pending.push(t);
|
|
107
111
|
}
|
|
108
|
-
|
|
112
|
+
// 归档沉在历史区(与迁出记录同层),删除记录垫底
|
|
113
|
+
return [...pending, ...consumed.reverse(), ...migrated, ...archived.reverse(), ...deleted.reverse()];
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
export function mergeDirectoryRows(topics = [], goals = []) { const rows = [];
|
|
@@ -14,7 +14,7 @@ import { useApp } from '../../app-context.jsx';
|
|
|
14
14
|
import Landing from './landing.jsx';
|
|
15
15
|
import DagEditor from './dag-editor.jsx';
|
|
16
16
|
import { findOpenPanel, openPanel } from '../../workspace.js';
|
|
17
|
-
import { docIdOf, nextDraftId,
|
|
17
|
+
import { docIdOf, nextDraftId, saveDoc, scopeOf } from '../../modules/md/doc-store.js';
|
|
18
18
|
|
|
19
19
|
// 目录任务表每页条数(队列一长就翻页,不再一次渲染全部)
|
|
20
20
|
const PAGE_SIZE = 20;
|
|
@@ -196,20 +196,14 @@ export default function DirPanel({ dirKey }) {
|
|
|
196
196
|
...(text ? { text } : {}),
|
|
197
197
|
},
|
|
198
198
|
});
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (text) {
|
|
204
|
-
const docKey = docIdOf(scopeOf(dirKey), t.id);
|
|
205
|
-
const open = peekDoc(docKey);
|
|
206
|
-
if (open && String(open.body || '').trim() === String(t.text || '').trim()) {
|
|
207
|
-
saveDoc(docKey, { body: text });
|
|
208
|
-
}
|
|
209
|
-
}
|
|
199
|
+
// 重开 = **新建一条任务**(新 md),旧任务归档留档(#59:状态单向)。
|
|
200
|
+
// 旧文档**不动**(那是历史);新正文写进新任务自己的文档。
|
|
201
|
+
const landedKey = res?.key || dirKey;
|
|
202
|
+
const newId = String(res?.task?.id ?? t.id);
|
|
203
|
+
if (text) saveDoc(docIdOf(scopeOf(landedKey), newId), { body: text });
|
|
210
204
|
toast(
|
|
211
|
-
`已重开「${title.replace(/^#\s*/, '')}
|
|
212
|
-
(res?.moved && res.name ?
|
|
205
|
+
`已重开「${title.replace(/^#\s*/, '')}」→ 新任务 #${newId}(旧任务归档留档)` +
|
|
206
|
+
(res?.moved && res.name ? `;归属迁到「${res.name}」` : ''),
|
|
213
207
|
);
|
|
214
208
|
refreshLocal();
|
|
215
209
|
});
|
|
@@ -211,7 +211,7 @@ export default function Landing({
|
|
|
211
211
|
闸门{downs.length ? `×${downs.length}` : ''}
|
|
212
212
|
</span>
|
|
213
213
|
) : null}
|
|
214
|
-
{t.status !== 'consumed' && t.ready === false ? (
|
|
214
|
+
{t.status !== 'consumed' && t.status !== 'archived' && t.ready === false ? (
|
|
215
215
|
<span
|
|
216
216
|
className="mdw-tg"
|
|
217
217
|
title={t.blockBy?.length ? `等待依赖完成:#${t.blockBy.join(', #')}` : '被前方闸门挡住'}
|
|
@@ -222,8 +222,11 @@ export default function Landing({
|
|
|
222
222
|
</div>
|
|
223
223
|
</td>
|
|
224
224
|
<td>
|
|
225
|
-
<span
|
|
226
|
-
{t.status === 'consumed' ? '
|
|
225
|
+
<span
|
|
226
|
+
className={'st' + (t.status === 'consumed' || t.status === 'archived' ? ' done' : t.from ? ' run' : '')}
|
|
227
|
+
title={t.status === 'archived' ? '已归档:被新任务取代,原文留档' : ''}
|
|
228
|
+
>
|
|
229
|
+
{t.status === 'archived' ? '档' : t.status === 'consumed' ? '完' : t.from ? '跑' : '等'}
|
|
227
230
|
</span>
|
|
228
231
|
</td>
|
|
229
232
|
<td className="mono faint">{shortTime(t.createdAt)}</td>
|
|
@@ -243,10 +246,10 @@ export default function Landing({
|
|
|
243
246
|
/>
|
|
244
247
|
</span>
|
|
245
248
|
)}
|
|
246
|
-
{onReopenTask && (t.status === 'consumed' || t.completedAt) && (
|
|
249
|
+
{onReopenTask && t.status !== 'archived' && (t.status === 'consumed' || t.completedAt) && (
|
|
247
250
|
<span
|
|
248
251
|
className="op" role="button" tabIndex={-1}
|
|
249
|
-
title={t.completedAt ? '
|
|
252
|
+
title={t.completedAt ? '重做(验收反馈):新建一条任务继续做,旧任务归档留档' : '反馈修改:新建一条任务继续做,旧任务归档留档'}
|
|
250
253
|
aria-label={`重开 ${titleFromMd(t.text)}`}
|
|
251
254
|
onClick={(e) => {
|
|
252
255
|
e.stopPropagation();
|
|
@@ -168,27 +168,23 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
|
|
|
168
168
|
text,
|
|
169
169
|
},
|
|
170
170
|
});
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
171
|
+
// 重开 = **新建一条任务**(新 md),旧任务归档留档(#59:状态单向)。
|
|
172
|
+
// 所以:旧文档**不动**(那是历史),新正文写进**新任务自己的文档**,
|
|
173
|
+
// 页签切到新任务——用户接着看的就是「这一轮要干的活」。
|
|
174
174
|
// text 是拿 doc.body 拼的,未保存的编辑原样带在里面,不会被抹掉。
|
|
175
175
|
// 归属改了会搬家(同保存路径,任务 #43)——文档与页签跟到新队列新号。
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: newId } }));
|
|
183
|
-
}
|
|
184
|
-
setDirty(false);
|
|
185
|
-
toast(`已重开并改归属:「${title}」迁到「${res.name}」#${newId}`);
|
|
186
|
-
refreshLocal();
|
|
187
|
-
return;
|
|
176
|
+
const landedKey = res?.key || dirKey;
|
|
177
|
+
const newId = String(res?.task?.id ?? task);
|
|
178
|
+
const newDocId = docIdOf(scopeOf(landedKey), newId);
|
|
179
|
+
saveDoc(newDocId, { title: titleFromMd(text), body: text });
|
|
180
|
+
if (model && tabId) {
|
|
181
|
+
model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: newId } }));
|
|
188
182
|
}
|
|
189
|
-
saveDoc(id, { title: titleFromMd(text), body: text });
|
|
190
183
|
setDirty(false);
|
|
191
|
-
toast(
|
|
184
|
+
toast(
|
|
185
|
+
`已重开「${title}」→ 新任务 #${newId}(旧任务归档留档)` +
|
|
186
|
+
(res?.moved && res.name ? `;归属迁到「${res.name}」` : ''),
|
|
187
|
+
);
|
|
192
188
|
refreshLocal();
|
|
193
189
|
});
|
|
194
190
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as e,f as t,h as n,m as r,o as i,u as a}from"./attach-v8BxRJ7p.js";import{C as o,D as s,W as c,b as l,j as u,p as d,q as f,y as p}from"./index-DFMD9MV2.js";import{a as m,i as h,n as g,o as _,r as v,t as y}from"./md-history-DBs3hhRL.js";var b=r({default:()=>w,useWikiNav:()=>C}),x=n(t(),1),S=e();function C(e){let t=c()||{},n=a(),r=e||t.model,i=(0,x.useRef)(null),o=(0,x.useCallback)(async()=>{if(!i.current)try{i.current=(await f(`/api/docs/index`)).index||[]}catch{i.current=[]}return i.current},[]),l=(0,x.useCallback)(async(e,t,n={})=>{let i=(t||await o()).find(t=>t.docId===e);u(r,{component:`doc`,name:i?i.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[r,o]),d=(0,x.useCallback)(async e=>{let t=await o(),r=s(e,t);if(r&&r.docId)return l(r.docId,t);if(r&&r.candidates)return n(`「${e}」同名文档多份:${r.candidates.join(`、`)}`);n(`未找到「${e}」——可用 nx-kv docs add <rel> 创建`)},[o,l,n]);return{nav:d,onClick:(0,x.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),d(t.getAttribute(`data-wl`)))},[d]),ensureIndex:o,openByDocId:l}}function w({docId:e,repoKey:t,boardKey:n,boardName:r,model:s}){let c=a(),{dialog:u,node:b}=i(),w=(0,x.useRef)(new Map),E=(0,x.useRef)(null),D=(0,x.useRef)(null),{onClick:O,openByDocId:k}=C(s),A=t?`repo`:n?`board`:``,j=t||n||``,M=(0,x.useMemo)(()=>t?{repoKey:t}:n?{boardKey:n,boardName:r||``}:{},[t,n,r]),[N,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(``),[te,L]=(0,x.useState)(!1),[R,z]=(0,x.useState)(`split`),[B,V]=(0,x.useState)([]),[H,U]=(0,x.useState)(null),W=(0,x.useCallback)(async()=>{I(``);try{let t=await f(`/api/docs/item?ref=`+encodeURIComponent(e||``));P(t),L(!1)}catch(e){I(String(e.message||e)),P(null)}},[e]);(0,x.useEffect)(()=>{P(null),W()},[W]);let G=(0,x.useCallback)(()=>{if(!j){V([]);return}if(A===`repo`){f(`/api/repos/docs?id=`+encodeURIComponent(j)).then(t=>{let n=[],r=(e,t)=>{if(!e)return;let r=e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``;r&&n.push({docId:r,label:e.rel||e.path||(t?`主篇`:`补充`),note:e.note||``,main:t})};r(t.main||{rel:`repo/${j}.md`},!0);for(let e of t.links||[])r(e,!1);e&&!n.some(t=>t.docId===e)&&n.push({docId:e,label:`当前`,note:``,main:!0}),V(n)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}f(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===j||e.key===j),r=[];e&&r.push({docId:e,label:`当前`,note:``,main:!0});for(let e of n&&n.docLinks||[]){let t=e.rel?`rel:${e.rel}`:e.path?`path:${e.path}`:``;t&&!r.some(e=>e.docId===t)&&r.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,main:!1})}V(r)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[j,A,e]);(0,x.useEffect)(()=>{G()},[G]);let[K,q]=(0,x.useState)(null);(0,x.useEffect)(()=>{f(`/api/docs/index`).then(e=>{let t=new Set;for(let n of e.index||[])t.add(n.name),n.rel&&t.add(String(n.rel).toLowerCase()),n.path&&t.add(String(n.path).replace(/\\/g,`/`).toLowerCase());q(t)}).catch(()=>{})},[]);let J=!!(N&&N.writable),Y=(0,x.useMemo)(()=>N?p(N.body,[],J?K:null):``,[N,K,J]),X=(0,x.useMemo)(()=>N?d(N.body):[],[N]);(0,x.useEffect)(()=>{let e=D.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;U(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>U(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[N,R,Y]);let Z=e=>e().catch(e=>c(String(e.message||e))),ne=(0,x.useCallback)(e=>k(e,null,M),[k,M]),re=()=>{j&&Z(async()=>{let t=await u({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(t===null)return;let n=l(String(t).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?T(e):A===`repo`?`repo/${j}`:`board/${r||j}`}/reference/${n}.md`;await f(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(t).trim()||n}\n\n(待补)\n`}});try{A===`repo`?await f(`/api/repos/docs`,{method:`POST`,body:{id:j,rel:i}}):await f(`/api/docs/link`,{method:`POST`,body:{board:j,doc:i}})}catch{}c(`已补充:${i}`),G(),k(`rel:`+i,null,M)})},Q=()=>Z(async()=>{if(!N||!J)return;let t=await f(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:N.body}});P(e=>({...e,body:N.body,summary:t.summary})),L(!1),y(w.current,e),c(t.summary?`已保存,摘要已回写`:`已保存`)}),ie=(t,n=`op`)=>{N&&(g(w.current,e,{body:N.body},n),L(!0),P(e=>({...e,body:t,title:o(t,e.title)})))},ae=(t,n=`typing`)=>{if(!N)return;g(w.current,e,{body:N.body},n),L(!0);let r=/^#\s+/m.test(N.body)?N.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${N.body}`;P(e=>({...e,body:r,title:t}))},oe=()=>{if(!N)return;let t=h(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:o(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},se=()=>{if(!N)return;let t=v(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:o(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},ce=()=>Z(async()=>{let t=String(e||``).startsWith(`rel:`)?e.slice(4):String(e||``).startsWith(`path:`)?``:String(e||``);if(!t)return;let n=t.replace(/\.md$/i,``).split(`/`).pop()||`未命名文档`;await f(`/api/docs/item`,{method:`POST`,body:{rel:t,body:`# ${n}\n\n(待补)\n`}}),c(`已创建:${t}`),await W()});if(N&&N.dir)return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.path}),(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,S.jsxs)(`div`,{className:`docp-files`,children:[N.files.map(e=>(0,S.jsx)(`button`,{className:`docp-file`,onClick:()=>k(`path:`+e,null),children:e},e)),!N.files.length&&(0,S.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(F)return(0,S.jsx)(`div`,{className:`mdw docp`,children:(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档打开失败`})}),(0,S.jsx)(`div`,{className:`hint`,children:F})]})});if(!N)return(0,S.jsx)(`div`,{className:`mdw`,children:(0,S.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(N.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsx)(`div`,{className:`docp-head`,children:(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.rel||N.path||e})}),(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,S.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,S.jsx)(`div`,{children:(0,S.jsx)(`button`,{className:`btn sm`,onClick:ce,children:`创建骨架`})})]})]})}let $=J?R:`preview`;return(0,S.jsxs)(`div`,{className:`mdw docp`,"data-mode":$,onClick:O,ref:D,children:[(0,S.jsxs)(`div`,{className:`mdw-main`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,title:N.rel||N.path,children:N.rel||N.path}),te&&(0,S.jsx)(`span`,{className:`docp-dirty`,children:`未保存`}),!J&&(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部绑定 · 只读`}),(0,S.jsx)(`span`,{className:`grow`}),J&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_,{mode:$,onChange:z}),(0,S.jsx)(`button`,{className:`btn sm docp-save`,onClick:Q,children:`保存`})]})]}),N.summary&&J&&(0,S.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,N.summary]}),(0,S.jsx)(m,{mode:$,title:N.title,body:N.body,previewHtml:Y,onTitle:J?ae:null,onBody:J?ie:null,attachments:[],docKey:e,editorApiRef:E,onSave:J?Q:null,onUndo:J?oe:null,onRedo:J?se:null}),(0,S.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,S.jsx)(ee,{headings:X,scrollRoot:H,links:B,activeDocId:e,onOpenDoc:j?ne:null,onAddRef:j?re:null}),b]})}function T(e){let t=String(e||``).startsWith(`rel:`)?String(e).slice(4):``;return t?/\/index\.md$/i.test(t)?t.replace(/\/index\.md$/i,``):/\.md$/i.test(t)?t.replace(/\.md$/i,``):t.replace(/\/+$/,``):``}function E(e,t){return e?e.doc&&e.doc.path?`path:`+e.doc.path:e.doc&&e.doc.rel?`rel:`+e.doc.rel:e.docPath?`path:`+e.docPath:e.docRel?`rel:`+e.docRel:t===`repo`&&e.key?`rel:repo/`+e.key+`.md`:``:``}function D(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function O({kind:e,owner:t,model:n}){let{openByDocId:r}=C(n),i=e===`board`?`组介绍`:`项目介绍`,a=e===`board`?t&&(t.id||t.key):t&&t.key,o=t&&t.name,s=(0,x.useMemo)(()=>E(t,e),[t,e]),[c,u]=(0,x.useState)([]),[d,p]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),g=(0,x.useCallback)(()=>h(e=>e+1),[]);(0,x.useEffect)(()=>{let n=!0;if(!a){u([]);return}if(e===`repo`)f(`/api/repos/docs?id=`+encodeURIComponent(a)).then(e=>{if(!n)return;let t=[],r=D(e.main);p(r||s),r&&t.push({docId:r,label:e.main.rel||e.main.path||`主篇`,note:e.main.note||``,tag:e.main.tag||``,main:!0,ref:e.main.ref||``});for(let n of e.extras||[]){let e=D(n);e&&t.push({docId:e,label:n.name||n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}for(let n of e.links||[]){let e=D(n);e&&t.push({docId:e,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}u(t)}).catch(()=>{n&&(u([]),p(s))});else{let e=()=>{let e=[];s&&e.push({docId:s,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let n of t?.docLinks||[]){let t=D(n);t&&e.push({docId:t,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}return e};f(`/api/boards/`+encodeURIComponent(String(a))).then(t=>{if(!n)return;let r=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!r){u(e()),p(s);return}let i=[],a=D(t&&t.introMain)||s;p(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=D(e);t&&i.push({docId:t,label:e.name||e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}for(let e of r){let t=D(e);t&&i.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}u(i)}).catch(()=>{n&&(u(e()),p(s))})}return()=>{n=!1}},[e,a,t,s,m]);let _=(0,x.useMemo)(()=>e===`repo`&&a?{repoKey:a}:e===`board`&&a?{boardKey:a,boardName:o||``}:{},[e,a,o]);return{kind:e,label:i,ownerKey:a,docRef:s,mainDocId:d,links:c,openMain:(0,x.useCallback)(()=>{let e=d||s;e&&r(e,null,_)},[d,s,r,_]),openDoc:(0,x.useCallback)(e=>r(e,null,_),[r,_]),addRef:(0,x.useCallback)(async(t,n)=>{if(!a||!s.startsWith(`rel:`))return n&&n(`当前简介无法补充(需要自有树路径)`),null;let i=await t({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(i===null)return null;let c=typeof i==`string`?i:i&&i.value||``,u=typeof i==`object`&&i&&i.tag||``,d=l(String(c).trim()||`note`).replace(/\.md$/i,``),p=`${T(s)||(e===`repo`?`repo/${a}`:`board/${o||a}`)}/reference/${d}.md`;await f(`/api/docs/item`,{method:`POST`,body:{rel:p,body:`# ${String(c).trim()||d}\n\n(待补)\n`}});try{e===`repo`?await f(`/api/repos/docs`,{method:`POST`,body:{id:a,rel:p,tag:u||void 0}}):await f(`/api/docs/link`,{method:`POST`,body:{board:a,doc:p,tag:u||void 0}})}catch{}return n&&n(`已补充:${p}${u?` [${u}]`:``}`),g(),r(`rel:`+p,null,_),p},[a,s,e,o,r,_,g]),setLinkTag:(0,x.useCallback)(async(t,n,r)=>{if(!a)throw Error(`缺少归属`);let i=String(t||``).startsWith(`path:`)?{path:String(t).slice(5)}:{rel:String(t||``).startsWith(`rel:`)?String(t).slice(4):String(t||``)},o=r&&r.note||``;e===`repo`?await f(`/api/repos/docs`,{method:`POST`,body:{id:a,...i,note:o||void 0,tag:n||void 0}}):await f(`/api/docs/link`,{method:`POST`,body:{board:a,doc:i.path||i.rel,note:o||void 0,tag:n||void 0}}),g()},[a,e,g]),reload:g,canEdit:!!s}}function k(e){return e<=1?18:e===2?12:8}function ee({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(``),u=(0,x.useMemo)(()=>e||[],[e]),d=(0,x.useMemo)(()=>n||[],[n]);(0,x.useEffect)(()=>{let e=t;if(!e||!u.length)return;let n=()=>u.map(t=>{let n=e.querySelector(`#${CSS.escape(t.id)}`);if(!n)return null;let r=n.getBoundingClientRect(),i=e.getBoundingClientRect();return{id:t.id,y:r.top-i.top}}).filter(Boolean),r=()=>{let e=n();if(!e.length)return;let t=e[0].id;for(let n of e)n.y<=28&&(t=n.id);l(t)};return r(),e.addEventListener(`scroll`,r,{passive:!0}),()=>e.removeEventListener(`scroll`,r)},[t,u]);let f=(0,x.useCallback)(e=>{let n=t;if(!n)return;let r=n.querySelector(`#${CSS.escape(e)}`);if(!r){n.scrollTo({top:0,behavior:`smooth`}),l(e);return}r.scrollIntoView({behavior:`smooth`,block:`start`}),l(e)},[t]);return!u.length&&!d.length&&!a?null:(0,S.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{})]}),(0,S.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${k(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,S.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-row`+(c===e.id?` on`:``),"data-lv":e.level,onClick:()=>f(e.id),children:e.text},e.id))]}),(d.length>0||a)&&(0,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`doc-rail-row`+(e.docId===r?` on`:``),title:e.note||e.label,disabled:!i,onClick:()=>i&&i(e.docId),children:[e.main?`● `:`○ `,e.label]},e.docId)),a&&(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function A({kind:e,owner:t,model:n}){let r=a(),{dialog:o,node:s}=i(),{label:c,docRef:l,links:u,openMain:d,openDoc:f,addRef:p,setLinkTag:m,canEdit:h}=O({kind:e,owner:t,model:n});if(!t||!l)return null;let g=u.find(e=>e.main),_=g?g.docId:l,v=_.startsWith(`rel:`)?_.slice(4):_,y=u.filter(e=>!e.main),b=()=>p(o,r).catch(e=>r(String(e.message||e))),x=e=>{(async()=>{let t=await o({title:`标签 · ${e.label}`,input:!0,placeholder:`标签(如 qa;留空 = 清掉)`,value:e.tag||``,okText:`保存标签`});if(t===null)return;let n=typeof t==`string`?t:t&&t.tag||``;await m(e.docId,n,e),r(n?`标签已设为 [${n}]`:`标签已清除`)})().catch(e=>r(String(e.message||e)))};return(0,S.jsxs)(`div`,{className:`nx-intro`,children:[(0,S.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${c}(新页签阅读 / 编辑)`,onClick:d,children:c}),(0,S.jsx)(`span`,{className:`nx-intro-path mono`,children:v}),(0,S.jsx)(`span`,{className:`nx-intro-spacer`}),h&&l.startsWith(`rel:`)&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-btn`,title:`补充一篇介绍文档(reference)`,onClick:b,children:`+ ref`})]}),y.length>0&&(0,S.jsxs)(`div`,{className:`nx-intro-links`,children:[(0,S.jsx)(`span`,{className:`nx-intro-links-lab`,children:`补充`}),y.map(e=>(0,S.jsxs)(`span`,{className:`nx-intro-link-item`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`nx-intro-link`+(e.docId.startsWith(`path:`)?` ext`:``),title:e.note?`${e.label} — ${e.note}`:e.label,onClick:()=>f(e.docId),children:[(0,S.jsx)(`span`,{className:`nx-intro-link-label`,children:e.label}),e.tag?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,title:`标签:${e.tag}`,children:e.tag}):null,e.note?(0,S.jsx)(`span`,{className:`nx-intro-link-note`,children:e.note}):null,e.docId.startsWith(`path:`)?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,children:`外部`}):null]}),h&&!e.ref&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-tag-btn`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,"aria-label":`标签:${e.label}`,onClick:()=>x(e),children:`#`})]},e.docId))]}),s]})}export{b as n,C as r,A as t};
|