nx-kv 0.58.0 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +3 -2
- package/assets/nx-kv/references/A04-/344/273/223/345/272/223/344/270/216/351/241/271/347/233/256/347/273/204.md +2 -1
- package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +3 -3
- package/package.json +1 -1
- package/src/core/attachmentdb/docs.ts +36 -13
- package/src/core/config.ts +20 -0
- package/src/core/db/import-json/refs.ts +2 -2
- package/src/core/db/migrations/index.ts +5 -0
- package/src/core/db/migrations/v11-data.ts +36 -0
- package/src/core/db/migrations/v11.sql +28 -0
- package/src/core/db/migrations/v12.sql +14 -0
- package/src/core/db/migrations/v8-data.ts +20 -4
- package/src/core/db/version.ts +5 -1
- package/src/modules/docs/actions/_manifest.generated.ts +6 -0
- package/src/modules/docs/actions/docs-bindings.ts +2 -3
- package/src/modules/docs/actions/docs-link.ts +1 -2
- package/src/modules/docs/actions/docs-orphans-purge.ts +28 -0
- package/src/modules/docs/actions/docs-orphans.ts +27 -0
- package/src/modules/docs/brief.ts +0 -2
- package/src/modules/docs/docref.ts +8 -7
- package/src/modules/docs/knowledge.ts +1 -4
- package/src/modules/docs/orphan.ts +389 -0
- package/src/modules/docs/ref-sync.ts +1 -5
- package/src/modules/docs/refs.ts +66 -8
- package/src/modules/docs/render.ts +1 -1
- package/src/modules/docs/service.ts +1 -3
- package/src/modules/repos/actions/repo-doc-add.ts +1 -2
- package/src/modules/repos/actions/repo-doc-list.ts +1 -1
- package/src/modules/repos/actions/repo-knowledge.ts +1 -1
- package/src/modules/repos/actions/repo-ref-note.ts +4 -4
- package/src/modules/repos/boards/core.ts +0 -3
- package/src/modules/repos/{link-note.ts → ref-note-doc.ts} +53 -29
- package/src/modules/repos/ref.ts +8 -36
- package/src/modules/repos/transfer/export.ts +3 -3
- package/src/modules/repos/transfer/layout.ts +3 -3
- package/src/modules/setting/actions/setting-set.ts +1 -0
- package/src/modules/setting/service.ts +13 -1
- package/src/modules/tasktool/delivery-template.ts +3 -4
- package/src/runtime/cli.ts +9 -0
- package/src/web/frontend/api/cli-tree.json +34 -2
- package/src/web/frontend/api/client.generated.ts +30 -7
- package/src/web/frontend/components/Introduction/use-intro.ts +2 -4
- package/src/web/frontend/modules/refs/api.ts +0 -1
- package/src/web/frontend/page/repos/index.tsx +1 -1
- package/src/web/frontend/page/settings/api.ts +10 -0
- package/src/web/frontend/page/settings/index.tsx +163 -1
- package/src/web/frontend/page/settings/style.css +26 -0
- package/src/web/frontend/refs/api.ts +0 -1
- package/src/web/public/assets/{composer-panel-D73-SjHP.js → composer-panel-BhT_eFic.js} +1 -1
- package/src/web/public/assets/{dir-DOlFdrrg.js → dir-1w7D_lg7.js} +1 -1
- package/src/web/public/assets/{doc-CKkCGsZ4.js → doc-Dn4-viog.js} +1 -1
- package/src/web/public/assets/{group-C3N5tBVQ.js → group-BsvhgO5r.js} +1 -1
- package/src/web/public/assets/{index-Ca-l9oTn.js → index-CBVkXanT.js} +2 -2
- package/src/web/public/assets/{refs-DvvwZmdl.js → refs-BHzLZnJn.js} +1 -1
- package/src/web/public/assets/{repo-form-modal-pyqiC7pB.js → repo-form-modal-BafSPVlv.js} +1 -1
- package/src/web/public/assets/{repos-CeyrjSQ_.js → repos-CmlsSN0h.js} +2 -2
- package/src/web/public/assets/settings-C_Dkc9gQ.js +8 -0
- package/src/web/public/assets/settings-ZgyeQVU1.css +1 -0
- package/src/web/public/assets/{task-Czd6vy99.js → task-Ci94al50.js} +1 -1
- package/src/web/public/assets/{templates-bCiyBvPJ.js → templates-Dc5Pln-Q.js} +1 -1
- package/src/web/public/index.html +3 -3
- package/src/modules/docs/link-note.ts +0 -171
- package/src/web/public/assets/settings-Bopc08A2.css +0 -1
- package/src/web/public/assets/settings-Bt1Uzf7g.js +0 -8
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { action } from '../../../runtime/action-decorator.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
7
|
-
import * as
|
|
8
|
-
const link: any =
|
|
7
|
+
import * as refNoteDoc from '../ref-note-doc.js';
|
|
8
|
+
const link: any = refNoteDoc;
|
|
9
9
|
|
|
10
10
|
/** repo.ref.note 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
11
11
|
const input = z.object({
|
|
@@ -21,8 +21,8 @@ export class RepoRefNoteAction extends ActionBase<typeof input> {
|
|
|
21
21
|
cli: ['repo', 'ref', 'note'],
|
|
22
22
|
http: ['POST', '/api/repos/ref/note'],
|
|
23
23
|
summary:
|
|
24
|
-
'
|
|
25
|
-
'
|
|
24
|
+
'写/清绑定描述:这个参考在该组/该仓库里参考什么(描述落成该参考仓库文档列表里的一篇文档,' +
|
|
25
|
+
'desc 由系统生成;--note 留空 = 清除那篇)',
|
|
26
26
|
args: ['id'],
|
|
27
27
|
input,
|
|
28
28
|
render: (d: any) =>
|
|
@@ -25,7 +25,6 @@ export interface IntroMainOut {
|
|
|
25
25
|
title: string;
|
|
26
26
|
desc: string;
|
|
27
27
|
note: string;
|
|
28
|
-
tag: string;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
// 组内描述:同一个仓库在不同看板里的角色可以各不相同(「fr 组里它是 API 契约方」,
|
|
@@ -189,7 +188,6 @@ export async function getBoard(idOrKey: unknown): Promise<GetBoardResult> {
|
|
|
189
188
|
title: set.main.title,
|
|
190
189
|
desc: set.main.desc,
|
|
191
190
|
note: set.main.note,
|
|
192
|
-
tag: set.main.tag,
|
|
193
191
|
} : null,
|
|
194
192
|
introExtras: set.links.map((d) => ({
|
|
195
193
|
refId: d.refId,
|
|
@@ -197,7 +195,6 @@ export async function getBoard(idOrKey: unknown): Promise<GetBoardResult> {
|
|
|
197
195
|
title: d.title,
|
|
198
196
|
desc: d.desc,
|
|
199
197
|
note: d.note,
|
|
200
|
-
tag: d.tag,
|
|
201
198
|
name: d.title,
|
|
202
199
|
})),
|
|
203
200
|
introCount: set.count,
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
// 绑定描述(组 ↔ 参考仓库 / 开发仓库 ↔
|
|
1
|
+
// 绑定描述(组 ↔ 参考仓库 / 开发仓库 ↔ 参考仓库)= **参考仓库文档列表里的一篇文档**。
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// #137:原来这套机制靠 `ref_bindings.tag = link-note:<关系 key>` 定位「这条关系的那一篇」,
|
|
4
|
+
// 那其实是把**分类标签**(一个没有入口、没人用的无效概念)当成了定位器。
|
|
5
|
+
// 现在定位回归它本来的样子:**desc 就在 ref 上**——
|
|
6
|
+
// 同一条关系 = 该参考仓库文档列表里 desc 等于「在组「X」里参考什么」的那一篇;
|
|
7
|
+
// 找不到就是还没写过;写一次即创建,再写即改同一篇。
|
|
8
|
+
//
|
|
9
|
+
// 关键口径:
|
|
10
|
+
// · 描述的**短标签(desc)由系统生成**(关系 + 「参考什么」),用户可在面板里改;
|
|
11
|
+
// 改了就等于换了一条关系(新的短标签 → 新的一篇)——可接受的代价:
|
|
12
|
+
// 关系描述本来就是「一句给人看的话」,不是机器主键;
|
|
13
|
+
// · 描述的**全文(body)**是用户写的内容(多行、含关键路径/搜索词),
|
|
14
|
+
// 长文本走 `--body-file`;
|
|
15
|
+
// · 关系本身不再有专门的存储:绑定关系在 `group_refs` / `ext_linked` 上,
|
|
16
|
+
// 描述在文档里,两者靠「宿主 + desc」对上。
|
|
6
17
|
//
|
|
7
18
|
// 单独成文件的原因:ref.ts 已在行数门禁的上限上,绑定描述这套逻辑独立成块
|
|
8
19
|
// (校验关系存在 → 写文档),拆出去两边都清爽。
|
|
9
20
|
import * as service from './service.js';
|
|
10
21
|
import { loadRef, boardKeyInside, repoKeyInside } from './ref.js';
|
|
11
22
|
import { badInput, notFound, conflict } from '../../core/errors.js';
|
|
23
|
+
import { getDb } from '../../core/db/index.js';
|
|
12
24
|
|
|
13
25
|
/** setLinkNote 的返回:写组级带 group、写仓库级带 repo。 */
|
|
14
26
|
export interface SetLinkNoteResult {
|
|
@@ -17,7 +29,7 @@ export interface SetLinkNoteResult {
|
|
|
17
29
|
group?: string;
|
|
18
30
|
repo?: string;
|
|
19
31
|
note: string;
|
|
20
|
-
/**
|
|
32
|
+
/** 描述落成的文档(refId / docId) */
|
|
21
33
|
refId?: string;
|
|
22
34
|
docId?: string;
|
|
23
35
|
}
|
|
@@ -31,13 +43,36 @@ export interface SetLinkNoteInput {
|
|
|
31
43
|
note?: unknown;
|
|
32
44
|
}
|
|
33
45
|
|
|
46
|
+
/** 关系描述的短标签(desc):系统生成,形如「在组「csharp」里参考什么」。 */
|
|
47
|
+
export function relationDescOf(scope: { kind: 'board' | 'repo'; name: string }): string {
|
|
48
|
+
return scope.kind === 'board'
|
|
49
|
+
? `在组「${scope.name}」里参考什么`
|
|
50
|
+
: `在仓库「${scope.name}」里参考什么`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 这条关系对应的描述文档(按 desc 找;没有 → 空串)。 */
|
|
54
|
+
export function findRelationDoc(refKey: string, scope: { kind: 'board' | 'repo'; name: string }): string {
|
|
55
|
+
const desc = relationDescOf(scope);
|
|
56
|
+
const row = getDb().get(
|
|
57
|
+
`SELECT b.ref_id AS refId
|
|
58
|
+
FROM ref_bindings b
|
|
59
|
+
JOIN refs r ON r.id = b.ref_id AND r.deleted_at IS NULL
|
|
60
|
+
WHERE b.type = 'repo' AND b.repo_key = :refKey AND r."desc" = :desc
|
|
61
|
+
ORDER BY b.position, b.rowid
|
|
62
|
+
LIMIT 1`,
|
|
63
|
+
{ refKey: String(refKey || ''), desc },
|
|
64
|
+
);
|
|
65
|
+
return row ? String(row.refId || '') : '';
|
|
66
|
+
}
|
|
67
|
+
|
|
34
68
|
/**
|
|
35
69
|
* 绑定描述:这条绑定「参考什么」。note 留空 = 清除。
|
|
36
70
|
* --board b 写组级绑定(组 ↔ 参考仓库)的描述
|
|
37
71
|
* --repo x 写仓库级绑定(开发仓库 ↔ 参考仓库)的描述
|
|
38
72
|
* 两者只能选一个(一条绑定一条描述);目标关系不存在时显式报错。
|
|
39
73
|
*
|
|
40
|
-
*
|
|
74
|
+
* 关系必须真实存在——描述得挂在一条存在的关系上;描述本身落成**文档**
|
|
75
|
+
* (该参考仓库文档列表里的一篇,desc 由系统生成)。
|
|
41
76
|
*/
|
|
42
77
|
export async function setLinkNote({ id, key, repo, board, note }: SetLinkNoteInput = {}): Promise<SetLinkNoteResult> {
|
|
43
78
|
const ref = await loadRef(id || key);
|
|
@@ -77,35 +112,24 @@ export async function setLinkNote({ id, key, repo, board, note }: SetLinkNoteInp
|
|
|
77
112
|
}
|
|
78
113
|
|
|
79
114
|
// docs 域用**动态 import**(模块之间不静态互依,见 docs/repos-bridge 的同款约定)
|
|
80
|
-
const {
|
|
81
|
-
const
|
|
115
|
+
const { setDocLinkDoc } = await import('../docs/refs.js');
|
|
116
|
+
const desc = relationDescOf(scope);
|
|
117
|
+
const out = text
|
|
118
|
+
? await setDocLinkDoc({ repoKey: refKey, desc, body: text })
|
|
119
|
+
: { refId: findRelationDoc(refKey, scope), desc, created: false };
|
|
82
120
|
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (scope.kind === 'board') {
|
|
89
|
-
const db = d.boards.find((x: any) => service.storedBoardKey(x) === scope.key);
|
|
90
|
-
const link = db && (db.refs || []).find((l: any) => l.id === refKey);
|
|
91
|
-
if (!link) return;
|
|
92
|
-
if (text) link.note = text;
|
|
93
|
-
else delete link.note;
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const dev = d.repos.find((x: any) => service.deriveKey(x) === scope.key);
|
|
97
|
-
const link = dev && (dev.linked || []).find((l: any) => l && l.kind === 'ref' && String(l.id) === refKey);
|
|
98
|
-
if (!link) return;
|
|
99
|
-
if (text) link.note = text;
|
|
100
|
-
else delete link.note;
|
|
101
|
-
});
|
|
121
|
+
// 留空 = 清除:删掉那篇描述文档(正文与归属一起清)
|
|
122
|
+
if (!text && out.refId) {
|
|
123
|
+
const { removeDoc } = await import('../docs/service.js');
|
|
124
|
+
await removeDoc({ ref: out.refId }).catch(() => null);
|
|
125
|
+
}
|
|
102
126
|
|
|
103
127
|
return {
|
|
104
128
|
key: refKey,
|
|
105
129
|
name: r.name,
|
|
106
130
|
...relation,
|
|
107
131
|
note: text,
|
|
108
|
-
refId: out.refId,
|
|
109
|
-
docId: out.refId ? `ref:${out.refId}` : '',
|
|
132
|
+
refId: text ? out.refId : '',
|
|
133
|
+
docId: text && out.refId ? `ref:${out.refId}` : '',
|
|
110
134
|
};
|
|
111
135
|
}
|
package/src/modules/repos/ref.ts
CHANGED
|
@@ -457,27 +457,16 @@ export async function refReposOfRepo(idOrPathOrName: unknown): Promise<RefsOfRep
|
|
|
457
457
|
const repoKey = service.deriveKey(repo);
|
|
458
458
|
const groups = groupsOfRepo(s, repoKey);
|
|
459
459
|
// #134:描述已经不在关系边上了(在文档里)——只读展示从文档取,缺省回落旧 note。
|
|
460
|
-
const boardsOut =
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
name: b.name,
|
|
467
|
-
desc: b.desc || '',
|
|
468
|
-
refRepos: linksOfBoard(s, b).map(({ ref, note }) => ({
|
|
469
|
-
...projectRef(ref),
|
|
470
|
-
note: bodies.get(service.deriveKey(ref)) || note,
|
|
471
|
-
})),
|
|
472
|
-
};
|
|
460
|
+
const boardsOut = groups.map((b) => ({
|
|
461
|
+
id: b.id,
|
|
462
|
+
key: service.storedBoardKey(b),
|
|
463
|
+
name: b.name,
|
|
464
|
+
desc: b.desc || '',
|
|
465
|
+
refRepos: linksOfBoard(s, b).map(({ ref, note }) => ({ ...projectRef(ref), note })),
|
|
473
466
|
}));
|
|
474
467
|
|
|
475
468
|
// 仓库级直接绑定:与组无关,永远原样回显(组级结果不覆盖它)
|
|
476
|
-
const
|
|
477
|
-
const direct = directLinksOfRepo(s, repo).map(({ ref, note }) => ({
|
|
478
|
-
...projectRef(ref),
|
|
479
|
-
note: repoBodies.get(service.deriveKey(ref)) || note,
|
|
480
|
-
}));
|
|
469
|
+
const direct = directLinksOfRepo(s, repo).map(({ ref, note }) => ({ ...projectRef(ref), note }));
|
|
481
470
|
|
|
482
471
|
return {
|
|
483
472
|
repo: { id: repo.id, key: repoKey, name: repo.name, path: repo.path, desc: repo.desc || '' },
|
|
@@ -486,18 +475,6 @@ export async function refReposOfRepo(idOrPathOrName: unknown): Promise<RefsOfRep
|
|
|
486
475
|
};
|
|
487
476
|
}
|
|
488
477
|
|
|
489
|
-
/**
|
|
490
|
-
* #134:这条关系下各参考仓库的**描述正文**(refKey → 正文)。
|
|
491
|
-
*
|
|
492
|
-
* 描述已经不在关系边上了(归档成文档),但只读展示(面板 chip、交付上下文)
|
|
493
|
-
* 仍要给出「这个参考在本组里参考什么」——出处是文档。docs 域用**动态 import**
|
|
494
|
-
* (模块之间不静态互依,见 docs/repos-bridge 的同款约定)。
|
|
495
|
-
*/
|
|
496
|
-
async function linkNoteBodiesOf(scope: { kind: 'board' | 'repo'; key: string; name: string }): Promise<Map<string, string>> {
|
|
497
|
-
const { linkNoteBodiesOf: f } = await import('../docs/link-note.js');
|
|
498
|
-
return f(scope);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
478
|
/** syncRef 的结果(status: missing/upToDate/updated/conflict;syncAllRefs 里还有 error)。 */
|
|
502
479
|
export interface SyncRefResult {
|
|
503
480
|
id: string;
|
|
@@ -637,13 +614,8 @@ export async function refReposOfBoard(boardIdOrKey: unknown): Promise<RefsOfBoar
|
|
|
637
614
|
if (!b) b = s.boards.find((x) => String(x.name).toLowerCase() === raw.toLowerCase());
|
|
638
615
|
if (!b) throw notFound('看板不存在: ' + raw);
|
|
639
616
|
const bkey = service.storedBoardKey(b);
|
|
640
|
-
// #134:描述正文从文档取(关系边上已经没有它了)
|
|
641
|
-
const bodies = await linkNoteBodiesOf({ kind: 'board', key: bkey, name: b.name });
|
|
642
617
|
return {
|
|
643
618
|
board: { id: b.id, key: bkey, name: b.name },
|
|
644
|
-
refRepos: linksOfBoard(s, b).map(({ ref, note }) => ({
|
|
645
|
-
...projectRef(ref),
|
|
646
|
-
note: bodies.get(service.deriveKey(ref)) || note,
|
|
647
|
-
})),
|
|
619
|
+
refRepos: linksOfBoard(s, b).map(({ ref, note }) => ({ ...projectRef(ref), note })),
|
|
648
620
|
};
|
|
649
621
|
}
|
|
@@ -28,7 +28,7 @@ export interface ExportRepoEntry {
|
|
|
28
28
|
type: string;
|
|
29
29
|
/** 文档绑定(主篇 refId) */
|
|
30
30
|
doc?: any;
|
|
31
|
-
/** 项目补充文档(refId + note
|
|
31
|
+
/** 项目补充文档(refId + note) */
|
|
32
32
|
docLinks?: any[];
|
|
33
33
|
remote?: string;
|
|
34
34
|
remotes?: string[];
|
|
@@ -49,7 +49,7 @@ export interface ExportBoardEntry {
|
|
|
49
49
|
repos: ExportBoardRepoEntry[];
|
|
50
50
|
/** 文档绑定(v4):组介绍覆盖 */
|
|
51
51
|
doc?: any;
|
|
52
|
-
/** 组级附加文档列表(note
|
|
52
|
+
/** 组级附加文档列表(note 注解跟条目一起走) */
|
|
53
53
|
docLinks?: any[];
|
|
54
54
|
/** 组内描述覆盖(v4) */
|
|
55
55
|
repoDocs?: Record<string, any>;
|
|
@@ -166,7 +166,7 @@ export async function repoExport({ repoKeys, boardKeys, includeUnassigned = true
|
|
|
166
166
|
// 文档绑定(v4):组介绍覆盖 / 组级附加列表 / 组内描述覆盖
|
|
167
167
|
const bdoc = sanitizeDocRef(b.doc);
|
|
168
168
|
if (bdoc) entry.doc = bdoc;
|
|
169
|
-
// docLinks 条目 = DocRef + 注解(note
|
|
169
|
+
// docLinks 条目 = DocRef + 注解(note),注解跟条目一起走(withLinkMeta 统一口径)
|
|
170
170
|
const links = (Array.isArray(b.docLinks) ? b.docLinks : [])
|
|
171
171
|
.map((l: any) => {
|
|
172
172
|
const d = sanitizeDocRef(l);
|
|
@@ -87,12 +87,12 @@ export function parseLayout(json: unknown): Layout {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// v2 → v3:没有 key 的条目用 remote/name 现算,让老导出文件也能导入。
|
|
90
|
-
// v3 → v4:文档绑定字段做形状归一(非法形状丢弃;note
|
|
90
|
+
// v3 → v4:文档绑定字段做形状归一(非法形状丢弃;note 注解原样保留)。
|
|
91
91
|
const refOf = (raw: unknown): any => {
|
|
92
92
|
const d = sanitizeDocRef(raw);
|
|
93
93
|
if (!d) return null;
|
|
94
|
-
// sanitizeDocRef 通过即说明 raw 是 DocRef 形状对象(note
|
|
95
|
-
return withLinkMeta(d, raw as { note?: unknown
|
|
94
|
+
// sanitizeDocRef 通过即说明 raw 是 DocRef 形状对象(note 注解原样带出)
|
|
95
|
+
return withLinkMeta(d, raw as { note?: unknown });
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
function normalizeLayout(data: any): Layout {
|
|
@@ -11,6 +11,7 @@ const service: any = serviceNs;
|
|
|
11
11
|
const input = z.object({
|
|
12
12
|
gitRepoRoot: z.string().optional().describe("参考仓库存储根目录(非 C 盘;空 = clone 参考仓库被拒绝)"),
|
|
13
13
|
gitDevRoot: z.string().optional().describe("导入布局时开发仓库的默认克隆根(空 = 只登记不克隆)"),
|
|
14
|
+
orphanTtlDays: z.number().int().min(1).max(3650).optional().describe("无归属 ref 的保留天数(默认 3;到期由例行维护软删空壳)"),
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
export class SettingSetAction extends ActionBase<typeof input> {
|
|
@@ -16,6 +16,8 @@ export interface SettingsView {
|
|
|
16
16
|
resolvedDir: string;
|
|
17
17
|
gitRepoRoot: string;
|
|
18
18
|
gitDevRoot: string;
|
|
19
|
+
/** 无归属 ref 的保留天数(到期清理;默认 3) */
|
|
20
|
+
orphanTtlDays: number;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export async function getSettings(): Promise<SettingsView> {
|
|
@@ -27,19 +29,28 @@ export async function getSettings(): Promise<SettingsView> {
|
|
|
27
29
|
// 参考仓库(type=ref)的存储根;空 = clone 会被拒绝,直到用户显式设置
|
|
28
30
|
gitRepoRoot: cfg.gitRepoRoot,
|
|
29
31
|
gitDevRoot: cfg.gitDevRoot,
|
|
32
|
+
orphanTtlDays: cfg.orphanTtlDays,
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export async function setSettings(patch: {
|
|
34
37
|
gitRepoRoot?: unknown;
|
|
35
38
|
gitDevRoot?: unknown;
|
|
39
|
+
orphanTtlDays?: unknown;
|
|
36
40
|
} = {}): Promise<SettingsView> {
|
|
37
41
|
const body: Record<string, unknown> = {};
|
|
38
42
|
if (patch.gitRepoRoot !== undefined) body.gitRepoRoot = String(patch.gitRepoRoot || '').trim();
|
|
39
43
|
if (patch.gitDevRoot !== undefined) body.gitDevRoot = String(patch.gitDevRoot || '').trim();
|
|
44
|
+
if (patch.orphanTtlDays !== undefined) {
|
|
45
|
+
const n = Math.trunc(Number(patch.orphanTtlDays));
|
|
46
|
+
if (!Number.isFinite(n) || n < 1 || n > 3650) {
|
|
47
|
+
throw badInput('孤儿文档保留天数必须是 1–3650 的整数');
|
|
48
|
+
}
|
|
49
|
+
body.orphanTtlDays = n;
|
|
50
|
+
}
|
|
40
51
|
if (!Object.keys(body).length) {
|
|
41
52
|
throw badInput(
|
|
42
|
-
'没有要改的设置:--gitRepoRoot <参考仓库根目录> / --gitDevRoot <开发仓库克隆根>'
|
|
53
|
+
'没有要改的设置:--gitRepoRoot <参考仓库根目录> / --gitDevRoot <开发仓库克隆根> / --orphanTtlDays <天数>'
|
|
43
54
|
);
|
|
44
55
|
}
|
|
45
56
|
await saveConfig({ ...(await loadConfig()), ...body });
|
|
@@ -52,5 +63,6 @@ export function renderSettings(d: SettingsView): string {
|
|
|
52
63
|
`(附件根目录 ${d.attachmentsRoot})`,
|
|
53
64
|
`参考仓库存储根: ${d.gitRepoRoot || '(未设置 —— clone 参考仓库前先 nx-kv setting set --gitRepoRoot <非C盘目录>)'}`,
|
|
54
65
|
`开发仓库克隆根: ${d.gitDevRoot || '(未设置 —— 导入布局时开发仓库只登记不克隆)'}`,
|
|
66
|
+
`孤儿文档保留: ${d.orphanTtlDays} 天(无归属 ref 到期后软删;有正文的不自动删)`,
|
|
55
67
|
].filter(Boolean).join('\n');
|
|
56
68
|
}
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
// {{task.text}} 原始提示词(任务正文,逐字)
|
|
15
15
|
// {{task.id}} 任务编号
|
|
16
16
|
// {{repo.name}} {{repo.intro}} {{repo.introPath}} 项目介绍(正文 + 可读路径)
|
|
17
|
-
// {{#each repo.docs}}…{{/each}} 项目补充文档(数组:path /
|
|
17
|
+
// {{#each repo.docs}}…{{/each}} 项目补充文档(数组:path / note)
|
|
18
18
|
// {{group.name}} {{group.desc}} {{group.intro}} {{group.introPath}} {{group.note}}
|
|
19
19
|
// {{#each group.peers}}…{{/each}} 组内成员(数组:name / note)
|
|
20
|
-
// {{#each group.docs}}…{{/each}} 组绑定参考文件(数组:path /
|
|
20
|
+
// {{#each group.docs}}…{{/each}} 组绑定参考文件(数组:path / note)
|
|
21
21
|
// {{#each repo.refRepos}}…{{/each}} 本仓库直接绑定的参考仓库(name / path / note)
|
|
22
22
|
// {{#each group.refRepos}}…{{/each}} 本组绑定的参考仓库(name / path / note)
|
|
23
23
|
// {{#each refRepos.list}}…{{/each}} 两者去重并集({{refRepos.count}} 总数)
|
|
@@ -45,14 +45,13 @@ export const DEFAULT_DELIVERY_TEMPLATE = DEFAULT_CONTEXT_TEMPLATE;
|
|
|
45
45
|
* 「项目文档 / 组文档」→ 结构化数组(模板用 {{#each}} 组织行)。
|
|
46
46
|
* v7:ref 是 DB 实体,没有路径——只给 desc / title / refId / hasBody。
|
|
47
47
|
*/
|
|
48
|
-
function docItems(links: any): { refId: string; desc: string; title: string; hasBody: boolean; note: string
|
|
48
|
+
function docItems(links: any): { refId: string; desc: string; title: string; hasBody: boolean; note: string }[] {
|
|
49
49
|
return (links || []).map((d: any) => ({
|
|
50
50
|
refId: d.refId || '',
|
|
51
51
|
desc: d.desc || '',
|
|
52
52
|
title: d.title || '',
|
|
53
53
|
hasBody: d.hasBody !== false,
|
|
54
54
|
note: d.note || '',
|
|
55
|
-
tag: d.tag || '',
|
|
56
55
|
}));
|
|
57
56
|
}
|
|
58
57
|
|
package/src/runtime/cli.ts
CHANGED
|
@@ -431,6 +431,15 @@ async function cmdServe(ctx: ServeCtx): Promise<void> {
|
|
|
431
431
|
};
|
|
432
432
|
process.on('exit', unregister);
|
|
433
433
|
|
|
434
|
+
// 孤儿文档例行维护:启动后延迟跑一次,此后每小时一次。
|
|
435
|
+
// 只软删空正文且到期的孤儿;有正文的只列清单(不静默删)。失败不影响面板。
|
|
436
|
+
try {
|
|
437
|
+
const { startOrphanGcTimer } = await import('../modules/docs/orphan.js');
|
|
438
|
+
startOrphanGcTimer();
|
|
439
|
+
} catch {
|
|
440
|
+
/* 计时器启动失败不影响 serve 本体 */
|
|
441
|
+
}
|
|
442
|
+
|
|
434
443
|
console.log('nx-kv · nx-kv v' + VERSION);
|
|
435
444
|
console.log(`面板: ${addr}`);
|
|
436
445
|
console.log('CLI: nx-kv help(每个按钮都有对应命令,agent 可加 --json)');
|
|
@@ -658,7 +658,7 @@
|
|
|
658
658
|
"action": {
|
|
659
659
|
"id": "repo.ref.note",
|
|
660
660
|
"module": "repos",
|
|
661
|
-
"summary": "
|
|
661
|
+
"summary": "写/清绑定描述:这个参考在该组/该仓库里参考什么(描述落成该参考仓库文档列表里的一篇文档,desc 由系统生成;--note 留空 = 清除那篇)",
|
|
662
662
|
"usage": "repo ref note",
|
|
663
663
|
"http": "POST /api/repos/ref/note"
|
|
664
664
|
},
|
|
@@ -1092,7 +1092,7 @@
|
|
|
1092
1092
|
"action": {
|
|
1093
1093
|
"id": "docs.link",
|
|
1094
1094
|
"module": "docs",
|
|
1095
|
-
"summary": "维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note
|
|
1095
|
+
"summary": "维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 更新)",
|
|
1096
1096
|
"usage": "docs link",
|
|
1097
1097
|
"http": "POST /api/docs/link"
|
|
1098
1098
|
},
|
|
@@ -1112,6 +1112,38 @@
|
|
|
1112
1112
|
"http": null
|
|
1113
1113
|
},
|
|
1114
1114
|
"children": []
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
"name": "orphans",
|
|
1118
|
+
"path": [
|
|
1119
|
+
"docs",
|
|
1120
|
+
"orphans"
|
|
1121
|
+
],
|
|
1122
|
+
"action": {
|
|
1123
|
+
"id": "docs.orphans",
|
|
1124
|
+
"module": "docs",
|
|
1125
|
+
"summary": "列出无归属的孤儿文档(失绑时间 / 剩余天数 / 是否有正文;只读)",
|
|
1126
|
+
"usage": "docs orphans",
|
|
1127
|
+
"http": "GET /api/docs/orphans"
|
|
1128
|
+
},
|
|
1129
|
+
"children": [
|
|
1130
|
+
{
|
|
1131
|
+
"name": "purge",
|
|
1132
|
+
"path": [
|
|
1133
|
+
"docs",
|
|
1134
|
+
"orphans",
|
|
1135
|
+
"purge"
|
|
1136
|
+
],
|
|
1137
|
+
"action": {
|
|
1138
|
+
"id": "docs.orphans.purge",
|
|
1139
|
+
"module": "docs",
|
|
1140
|
+
"summary": "孤儿到期清理(默认只预演;--apply 软删空正文到期孤儿,有正文的只列清单)",
|
|
1141
|
+
"usage": "docs orphans purge",
|
|
1142
|
+
"http": "POST /api/docs/orphans/purge"
|
|
1143
|
+
},
|
|
1144
|
+
"children": []
|
|
1145
|
+
}
|
|
1146
|
+
]
|
|
1115
1147
|
}
|
|
1116
1148
|
]
|
|
1117
1149
|
},
|
|
@@ -30,6 +30,8 @@ import type {
|
|
|
30
30
|
DocsGcAction,
|
|
31
31
|
DocsIndexAction,
|
|
32
32
|
DocsLinkAction,
|
|
33
|
+
DocsOrphansAction,
|
|
34
|
+
DocsOrphansPurgeAction,
|
|
33
35
|
} from '../../../modules/docs/actions/_manifest.generated.js';
|
|
34
36
|
import type {
|
|
35
37
|
FileContentAction,
|
|
@@ -227,7 +229,7 @@ export interface ApiClient {
|
|
|
227
229
|
check(): Promise<Awaited<ReturnType<InstanceType<typeof RepoRefCheckAction>['run']>>>;
|
|
228
230
|
/** 克隆远程仓库为参考仓库(落到 gitRepoRoot,登记 + 可选绑定当前目录的开发仓库) */
|
|
229
231
|
refClone(input: z.input<InstanceType<typeof RepoRefCloneAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof RepoRefCloneAction>['run']>>>;
|
|
230
|
-
/**
|
|
232
|
+
/** 写/清绑定描述:这个参考在该组/该仓库里参考什么(描述落成该参考仓库文档列表里的一篇文档,desc 由系统生成;--note 留空 = 清除那篇) */
|
|
231
233
|
refNote(input: z.input<InstanceType<typeof RepoRefNoteAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof RepoRefNoteAction>['run']>>>;
|
|
232
234
|
/** 查参考仓库:--id 某仓库(缺省当前目录)看它直接绑的 + 所属组绑的,两类并列;--board 某组 看这个组绑定的(带绑定描述) */
|
|
233
235
|
of(input?: z.input<InstanceType<typeof RepoRefOfAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof RepoRefOfAction>['run']>>>;
|
|
@@ -279,8 +281,12 @@ export interface ApiClient {
|
|
|
279
281
|
gc(input?: z.input<InstanceType<typeof DocsGcAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsGcAction>['run']>>>;
|
|
280
282
|
/** 双链索引(docId + 文件名;前端点击 [[..]] 前拉一次;解析规则见 core/wikilink.js) */
|
|
281
283
|
index(): Promise<Awaited<ReturnType<InstanceType<typeof DocsIndexAction>['run']>>>;
|
|
282
|
-
/** 维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note
|
|
284
|
+
/** 维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 更新) */
|
|
283
285
|
link(input: z.input<InstanceType<typeof DocsLinkAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsLinkAction>['run']>>>;
|
|
286
|
+
/** 孤儿到期清理(默认只预演;--apply 软删空正文到期孤儿,有正文的只列清单) */
|
|
287
|
+
purge(input?: z.input<InstanceType<typeof DocsOrphansPurgeAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsOrphansPurgeAction>['run']>>>;
|
|
288
|
+
/** 列出无归属的孤儿文档(失绑时间 / 剩余天数 / 是否有正文;只读) */
|
|
289
|
+
orphans(input?: z.input<InstanceType<typeof DocsOrphansAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsOrphansAction>['run']>>>;
|
|
284
290
|
/** 向某主题(工作目录)的队列回填一条任务(正文可多行;--file <文件|-> 从文件/标准输入读,长文本不必靠引号硬拼;有 wait 在等则即时投递,否则排队);--global 推到全局共享池;--duration 给任务带时间目标(领取即计时,完成前必须 check);--board/--project 让任务带工作组语义(正文 frontmatter:board + project + 双方介绍引用),并落进该项目的队列;正文自带 frontmatter 时同样认归属——补介绍引用,落点跟到项目队列(显式给过 --cwd 时不挪窝) */
|
|
285
291
|
localtaskAdd(input?: z.input<InstanceType<typeof LocaltaskAddAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskAddAction>['run']>>>;
|
|
286
292
|
/** 改一条附件绑定的说明(desc):--attachment <资源 id> --note <说明>(只动说明,角色/位置不变) */
|
|
@@ -378,7 +384,7 @@ export interface ApiClient {
|
|
|
378
384
|
/** 查单个附件的元数据与本机路径 */
|
|
379
385
|
fileGet(input: z.input<InstanceType<typeof FileGetAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof FileGetAction>['run']>>>;
|
|
380
386
|
/** 列出无主资源(没有任何任务/文档关系边;删任务、删文档、删正文行之后用) */
|
|
381
|
-
|
|
387
|
+
fileOrphans(): Promise<Awaited<ReturnType<InstanceType<typeof FileOrphansAction>['run']>>>;
|
|
382
388
|
/** 回收无主资源(DB 行 + 附件根目录内的本机/镜像字节;仍被引用的不删) */
|
|
383
389
|
filePrune(input?: z.input<InstanceType<typeof FilePruneAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof FilePruneAction>['run']>>>;
|
|
384
390
|
/** 上传附件到本机附件仓(不碰网;本地任务/文档贴图用) */
|
|
@@ -419,7 +425,7 @@ export function createApiClient(transport: Transport): ApiClient {
|
|
|
419
425
|
async set(input?: z.input<InstanceType<typeof SettingSetAction>['_input']>) {
|
|
420
426
|
const inp = input ?? ({} as z.input<InstanceType<typeof SettingSetAction>['_input']>);
|
|
421
427
|
const path = `/api/setting`;
|
|
422
|
-
const body = { "gitRepoRoot": inp["gitRepoRoot"], "gitDevRoot": inp["gitDevRoot"] };
|
|
428
|
+
const body = { "gitRepoRoot": inp["gitRepoRoot"], "gitDevRoot": inp["gitDevRoot"], "orphanTtlDays": inp["orphanTtlDays"] };
|
|
423
429
|
return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof SettingSetAction>['run']>>;
|
|
424
430
|
},
|
|
425
431
|
// action: board.add
|
|
@@ -539,7 +545,7 @@ export function createApiClient(transport: Transport): ApiClient {
|
|
|
539
545
|
async docAdd(input: z.input<InstanceType<typeof RepoDocAddAction>['_input']>) {
|
|
540
546
|
const inp = input ?? ({} as z.input<InstanceType<typeof RepoDocAddAction>['_input']>);
|
|
541
547
|
const path = `/api/repos/docs`;
|
|
542
|
-
const body = { "id": inp["id"], "ref": inp["ref"], "path": inp["path"], "note": inp["note"]
|
|
548
|
+
const body = { "id": inp["id"], "ref": inp["ref"], "path": inp["path"], "note": inp["note"] };
|
|
543
549
|
return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof RepoDocAddAction>['run']>>;
|
|
544
550
|
},
|
|
545
551
|
// action: repo.doc.list
|
|
@@ -874,9 +880,26 @@ export function createApiClient(transport: Transport): ApiClient {
|
|
|
874
880
|
async link(input: z.input<InstanceType<typeof DocsLinkAction>['_input']>) {
|
|
875
881
|
const inp = input ?? ({} as z.input<InstanceType<typeof DocsLinkAction>['_input']>);
|
|
876
882
|
const path = `/api/docs/link`;
|
|
877
|
-
const body = { "board": inp["board"], "ref": inp["ref"], "path": inp["path"], "note": inp["note"], "
|
|
883
|
+
const body = { "board": inp["board"], "ref": inp["ref"], "path": inp["path"], "note": inp["note"], "remove": inp["remove"], "before": inp["before"] };
|
|
878
884
|
return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof DocsLinkAction>['run']>>;
|
|
879
885
|
},
|
|
886
|
+
// action: docs.orphans.purge
|
|
887
|
+
async purge(input?: z.input<InstanceType<typeof DocsOrphansPurgeAction>['_input']>) {
|
|
888
|
+
const inp = input ?? ({} as z.input<InstanceType<typeof DocsOrphansPurgeAction>['_input']>);
|
|
889
|
+
const path = `/api/docs/orphans/purge`;
|
|
890
|
+
const body = { "apply": inp["apply"], "ttlDays": inp["ttlDays"] };
|
|
891
|
+
return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof DocsOrphansPurgeAction>['run']>>;
|
|
892
|
+
},
|
|
893
|
+
// action: docs.orphans
|
|
894
|
+
async orphans(input?: z.input<InstanceType<typeof DocsOrphansAction>['_input']>) {
|
|
895
|
+
const inp = input ?? ({} as z.input<InstanceType<typeof DocsOrphansAction>['_input']>);
|
|
896
|
+
let path = `/api/docs/orphans`;
|
|
897
|
+
const q = new URLSearchParams();
|
|
898
|
+
if (inp["ttlDays"] !== undefined) q.set("ttlDays", String(inp["ttlDays"]));
|
|
899
|
+
const query = q.toString();
|
|
900
|
+
if (query) path += path.includes('?') ? '&' + query : '?' + query;
|
|
901
|
+
return (await transport.request("GET", path)) as Awaited<ReturnType<InstanceType<typeof DocsOrphansAction>['run']>>;
|
|
902
|
+
},
|
|
880
903
|
// action: localtask.add
|
|
881
904
|
async localtaskAdd(input?: z.input<InstanceType<typeof LocaltaskAddAction>['_input']>) {
|
|
882
905
|
const inp = input ?? ({} as z.input<InstanceType<typeof LocaltaskAddAction>['_input']>);
|
|
@@ -1258,7 +1281,7 @@ export function createApiClient(transport: Transport): ApiClient {
|
|
|
1258
1281
|
return (await transport.request("GET", path)) as Awaited<ReturnType<InstanceType<typeof FileGetAction>['run']>>;
|
|
1259
1282
|
},
|
|
1260
1283
|
// action: file.orphans
|
|
1261
|
-
async
|
|
1284
|
+
async fileOrphans() {
|
|
1262
1285
|
const path = `/api/file/orphans`;
|
|
1263
1286
|
return (await transport.request("GET", path)) as Awaited<ReturnType<InstanceType<typeof FileOrphansAction>['run']>>;
|
|
1264
1287
|
},
|
|
@@ -15,7 +15,6 @@ export interface IntroLink {
|
|
|
15
15
|
docId: string;
|
|
16
16
|
label: string;
|
|
17
17
|
note?: string;
|
|
18
|
-
tag?: string;
|
|
19
18
|
main?: boolean;
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -29,7 +28,6 @@ export interface IntroDocEntry {
|
|
|
29
28
|
title?: string;
|
|
30
29
|
desc?: string;
|
|
31
30
|
note?: string;
|
|
32
|
-
tag?: string;
|
|
33
31
|
[k: string]: any;
|
|
34
32
|
}
|
|
35
33
|
|
|
@@ -129,11 +127,11 @@ export function useIntro({ kind, owner, model }: UseIntroArgs): IntroApi {
|
|
|
129
127
|
const mid = linkDocId(main);
|
|
130
128
|
setMainDocId(mid || docRef);
|
|
131
129
|
if (mid && main) {
|
|
132
|
-
out.push({ docId: mid, label: labelOf(main, '主篇'), note: main.note || '',
|
|
130
|
+
out.push({ docId: mid, label: labelOf(main, '主篇'), note: main.note || '', main: true });
|
|
133
131
|
}
|
|
134
132
|
for (const l of extras) {
|
|
135
133
|
const id = linkDocId(l);
|
|
136
|
-
if (id) out.push({ docId: id, label: labelOf(l, '补充'), note: l.note || '',
|
|
134
|
+
if (id) out.push({ docId: id, label: labelOf(l, '补充'), note: l.note || '', main: false });
|
|
137
135
|
}
|
|
138
136
|
setLinks(out);
|
|
139
137
|
};
|
|
@@ -140,7 +140,7 @@ export default function ReposView() {
|
|
|
140
140
|
const main = r.descDocs && r.descDocs.main;
|
|
141
141
|
if (main && [main.title, main.summary, main.desc].some((s) => s && String(s).toLowerCase().includes(kw))) return true;
|
|
142
142
|
return ((r.descDocs && r.descDocs.links) || []).some((l) =>
|
|
143
|
-
[l.title, l.desc, l.
|
|
143
|
+
[l.title, l.desc, l.note].some((s) => s && String(s).toLowerCase().includes(kw)));
|
|
144
144
|
};
|
|
145
145
|
return list.filter((r) =>
|
|
146
146
|
[r.name, r.key, r.path, r.desc].some((s) => s && String(s).toLowerCase().includes(kw))
|
|
@@ -13,6 +13,16 @@ export function saveSettings(patch: Record<string, unknown>): Promise<any> {
|
|
|
13
13
|
return api('/api/setting', { method: 'POST', body: patch });
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/** 读孤儿文档清单(GET /api/docs/orphans;CLI docs orphans 等价)。 */
|
|
17
|
+
export function getOrphans(): Promise<any> {
|
|
18
|
+
return api('/api/docs/orphans');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 预演 / 执行孤儿到期清理(POST /api/docs/orphans/purge;缺省只预演)。 */
|
|
22
|
+
export function purgeOrphans(patch: { apply?: boolean; ttlDays?: number } = {}): Promise<any> {
|
|
23
|
+
return api('/api/docs/orphans/purge', { method: 'POST', body: patch });
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
/** 读 localtask 全量(GET /api/localtasks;settings 段带提示词模板与追加模式)。 */
|
|
17
27
|
export function getLocaltaskSettings(): Promise<any> {
|
|
18
28
|
return api('/api/localtasks');
|