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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.60.0] - 2026-11-16 去掉「分类标签」这个无效概念(tag 整个退役)
|
|
6
|
+
|
|
7
|
+
### Removed
|
|
8
|
+
|
|
9
|
+
- **「分类标签」(`--tag qa` 那一套)从整个应用里删掉**——用户判断:「tag 又是什么参数呀
|
|
10
|
+
是不是压根 web 里面没有这个」「在整个应用里把 tag 这个概念去掉 移除无效概念」。
|
|
11
|
+
它在整个应用里**没有落点**:面板没有编辑入口、检索几乎不用,却让宿主 ext、
|
|
12
|
+
`ref_bindings` 索引、API 形状、CLI 输出到处背着一个字段。
|
|
13
|
+
- **存储版本 12**:`ALTER TABLE ref_bindings DROP COLUMN tag`(纯 DDL);
|
|
14
|
+
宿主 ext 的 `docLinks[].tag` 不再被读写(盘上旧数据保留但忽略);
|
|
15
|
+
- **接口**:`docs link` / `repo doc add` 的 `--tag` 入参删除;附件注解只剩 `note`
|
|
16
|
+
(一句话说明——那是有用的,不在删除范围);
|
|
17
|
+
- **视图与输出**:文档绑定视图、知识索引、仓库文档列表、组文档集、`docs link` /
|
|
18
|
+
`repo doc list` / `repo knowledge` 的 CLI 输出里的 `[tag]` chip 全部去掉;
|
|
19
|
+
- **前端**:API 形状去掉 `tag` 字段,仓库页检索不再按 tag 匹配;
|
|
20
|
+
- **导出/导入**:附件注解只带 `note`;旧 JSON 里的 `tag` 按 note 读入(不引入新概念)。
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **关系描述文档的定位改回「desc 就在 ref 上」**(用户追问:「link_notes? desc 不是直接在
|
|
25
|
+
ref 上吗 描述关系干什么」——原来的 `link-note:<关系 key>` 定位器其实就是把分类标签
|
|
26
|
+
当成了索引,属于绕远路):
|
|
27
|
+
- 同一组 / 同一仓库与参考仓库的关系 → 该参考仓库文档列表里 **desc 等于
|
|
28
|
+
「在组「X」里参考什么」/「在仓库「Y」里参考什么」**的那一篇;
|
|
29
|
+
- 重复写只是改内容,不新增;留空 = 删掉那篇;
|
|
30
|
+
- 定位实现落在 `src/modules/repos/ref-note-doc.ts`(desc 由系统生成,用户可在面板改);
|
|
31
|
+
- 因此**不需要**任何「关系 → 文档」的索引表——关系本身在 `group_refs` / `ext_linked` 上,
|
|
32
|
+
描述在文档里,两者靠「宿主 + desc」对上。
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- 历史迁移 `v8-data.ts`(v7 → v8 的数据搬运)在**当前** schema 上跑(legacy JSON 导入会这样)
|
|
37
|
+
时不再撞上已删除的 `tag` 列:按列是否存在裁剪,真升级路径行为一字不变。
|
|
38
|
+
- `localtask` / `docs` 等模块的迁移映射表与孤儿 GC 用例随新版本号更新。
|
|
39
|
+
|
|
40
|
+
## [0.59.0] - 2026-11-16 孤儿 ref 到期清理(3 天 TTL)+ 软删留痕
|
|
41
|
+
|
|
42
|
+
> 这一版的 schema v11 与孤儿清理由**并行会话**完成(同一工作树),本会话代为校准门禁并发布。
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
|
|
46
|
+
- **孤儿 ref 自动回收**(用户要求:「孤儿满 3 天后自动删除,删除前可看清单、删除后可审计」):
|
|
47
|
+
- **孤儿定义**:`deleted_at IS NULL` 且 `ref_bindings` 里没有任何一行的 ref(不看 `state`);
|
|
48
|
+
- `refs.orphan_since`:失绑起算时间(毫秒,0 = 未计时)——由「有归属」变「无归属」时写入,
|
|
49
|
+
**重建索引不刷新已在计时的孤儿**(否则每次 `syncRefIndex` 都把倒计时重置,永远到期不了);
|
|
50
|
+
- `ref_gc_log`:清理的**不可变留痕**(ref_id / desc / origin / body_bytes / unbound_at /
|
|
51
|
+
deleted_at / ttl_days / reason / source / snapshot);
|
|
52
|
+
- 到期清理为**软删**(`refs.deleted_at`,`ref_bodies` 保留),可回滚;
|
|
53
|
+
**只清空正文的孤儿**,有正文的到期孤儿只列清单、不自动删;
|
|
54
|
+
- 新增设置项 `app.orphanTtlDays`(默认 3 天)、CLI / HTTP `docs orphans`(看清单)、
|
|
55
|
+
`docs orphans purge`(执行清理)、serve 每小时例行维护、设置面板「文档清理」分区。
|
|
56
|
+
- **存储版本 11**:`src/core/db/migrations/v11.sql`(纯 DDL)+ `v11-data.ts`(存量孤儿起算时间回填);
|
|
57
|
+
存量孤儿在升级时统一从迁移时刻起算,保证升级后仍有完整 TTL 缓冲;回填不改 `updated_at`
|
|
58
|
+
(避免打乱文档列表的最近更新排序)。
|
|
59
|
+
- 决策见 `docs/decisions/2026-11-15-orphan-ref-gc.md`,版本说明见
|
|
60
|
+
`docs/decisions/versions/2026-11-15-v11.md`。
|
|
61
|
+
|
|
5
62
|
## [0.58.0] - 2026-11-16 新建任务模板只留一条内置「ref 生成」;旧内置下线(#137)
|
|
6
63
|
|
|
7
64
|
### Changed
|
package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md
CHANGED
|
@@ -77,7 +77,7 @@ nx-kv localtask done --id <id> --cwd "<项目目录>" --summary "<回答了什
|
|
|
77
77
|
|
|
78
78
|
- 第 ① 步就已经把 ref 挂进仓库了:仓库**有主篇** → 它是附加篇;**没有主篇** → 它就是主篇。
|
|
79
79
|
**别再重复挂一次**(同一篇挂两次,列表里会出现两条)。
|
|
80
|
-
-
|
|
80
|
+
- 附件与文档**不要挂两遍**(同一篇挂两次,列表里会出现两条)。
|
|
81
81
|
- 面板「新建任务」的内置模板就是这套流程的说明书(任务模板「ref 生成」)。
|
|
82
82
|
|
|
83
83
|
## 四、参考仓库也能构建文档列表(与开发仓库完全同构)
|
|
@@ -128,7 +128,8 @@ nx-kv docs bindings --group <组key> --json
|
|
|
128
128
|
3. **组视图里参考仓库排在最后**(组 → 组内仓库 → 成员仓库自己 → 组内参考仓库自己),
|
|
129
129
|
徽标 `hostKind` = `dev` / `ref` / `group`——按它分清每篇挂在谁身上。
|
|
130
130
|
4. **「组级描述」现在是文档**(#134):`repo ref note` 写的说明**完全归档**到该参考仓库
|
|
131
|
-
|
|
131
|
+
自己的文档列表(**desc 就在 ref 上**:desc =「在组「X」里参考什么」,重复写 = 改同一篇),
|
|
132
|
+
面板上不再有弹窗与「写描述」按钮;
|
|
132
133
|
关系边上只留一份供导出/导入带走的副本,真身是文档。
|
|
133
134
|
|
|
134
135
|
## 五、摘 / 删:三个动作别搞混
|
|
@@ -92,7 +92,8 @@ nx-kv repo ref note --id <参考仓库key> --board <组id> --note "<参考它的
|
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
**④ 的落点是「一篇文档」**(#134):这条说明**完全归档**到这个参考仓库自己的文档列表
|
|
95
|
-
(右侧栏「<参考仓库名> ·
|
|
95
|
+
(右侧栏「<参考仓库名> · 文档列表」里可见可编辑),**desc 就在 ref 上**——
|
|
96
|
+
desc 由系统生成(「在组「X」里参考什么」),同一关系重复写 = 改同一篇——
|
|
96
97
|
同一组 / 同一仓库重复写 = 改同一篇,不新增;`--note ""` = 清除(删掉那篇)。
|
|
97
98
|
面板上**没有**「写描述」按钮,也没有专属弹窗:写描述就在文档列表里写。
|
|
98
99
|
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
| `docs ref unbind` | `--ref` `--type` `--repo` `--group` | 摘归属(文档与正文保留) |
|
|
69
69
|
| `docs remove` | `--ref` | 删整篇 |
|
|
70
70
|
| `docs bindings` | `--ref` \| `--host <repoKey>` \| `--group <groupKey>` | 归属查询:`--host` 只给仓库自己的(含参考仓库);`--group` 给组域(组 → 组内 → 成员仓库自己 → **组内参考仓库自己**)。每行带 `hostKind`(`dev` / `ref` / `group`) |
|
|
71
|
-
| `docs bind` / `docs link` / `docs note-bind` | `--repo`/`--board` `--ref` `--path` `--note` `--
|
|
71
|
+
| `docs bind` / `docs link` / `docs note-bind` | `--repo`/`--board` `--ref` `--path` `--note` `--remove` `--before` `--reset` | 宿主文档集的增删改(`bind` 主篇,`link` 目录补充,`note-bind` 组内描述) |
|
|
72
72
|
| `docs attach` / `detach` / `attachments` / `attach-note` | `--ref` + 附件参数 | 文档附件(用法同 `localtask attach`) |
|
|
73
73
|
| `docs mdfile` / `mdfiles` / `link-file` | `--attachment` / `--missing` / `--path` | md 文件指针相关 |
|
|
74
74
|
| `docs gc` | `--apply` | 清没有正文的 ref(默认只报数) |
|
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
| `repo clone` | `--remote` `--key` `--name` `--depth` | clone 并登记(普通仓库) |
|
|
87
87
|
| `repo ref add` / `repo ref clone` | `--path` / `--url` `--name` `--desc` `--board` `--bind` `--no-bind` `--depth` | 登记 / 克隆参考仓库(`--board` 顺手挂组,`--bind` 绑开发仓库) |
|
|
88
88
|
| `repo ref sync` / `check` / `of` | `--id` `--all` / — / `--id` | 更新 / 完整性检查 / 这个仓库的参考 |
|
|
89
|
-
| `repo ref note` | `--id` \| `--repo` \| `--board` `--note "…"` | 写参考绑定说明(`repo bind` 本身不收 note)。#134:说明落成该**参考仓库的一篇文档**(右侧栏「<名字> ·
|
|
89
|
+
| `repo ref note` | `--id` \| `--repo` \| `--board` `--note "…"` | 写参考绑定说明(`repo bind` 本身不收 note)。#134:说明落成该**参考仓库的一篇文档**(右侧栏「<名字> · 文档列表」可见可编辑),desc 由系统生成、**desc 就是定位键**(同一关系重复写 = 改同一篇),`--note ""` = 清除 |
|
|
90
90
|
| `repo bind` | `--id <ref>` `--repo` \| `--board` `--remove` | 绑参考到仓库/组(`--remove` 解绑) |
|
|
91
91
|
| `repo bind-topics` | `--repo` `--apply` | 按主题回填绑定(维护用) |
|
|
92
|
-
| `repo doc add` / `list` / `remove` | `--id` `--ref` \| `--path` `--note`
|
|
92
|
+
| `repo doc add` / `list` / `remove` | `--id` `--ref` \| `--path` `--note` / `--index` | 仓库文档集(主篇 + 附加) |
|
|
93
93
|
| `repo knowledge` | `--id` `--md` | 仓库上下文知识(给 agent 读) |
|
|
94
94
|
| `repo key set` / `migrate` / `refresh` | `--id` `--key` `--apply` `--all` `--follow` | key 维护 |
|
|
95
95
|
| `repo remote` / `remote list` / `remote pick` / `remote check` | `--id` `--url` `--refresh` | remote 相关 |
|
package/package.json
CHANGED
|
@@ -55,17 +55,36 @@ export function ensureDocRef(conn: any, { ref, locator, atMs = Date.now() }: Ens
|
|
|
55
55
|
if (byLoc) return String(byLoc.id);
|
|
56
56
|
}
|
|
57
57
|
const external = input ? isExternal(input) : false;
|
|
58
|
+
const hasOrigin = !!conn.get("SELECT name FROM pragma_table_info('refs') WHERE name = 'origin'");
|
|
59
|
+
const hasOrphanSince = !!conn.get("SELECT name FROM pragma_table_info('refs') WHERE name = 'orphan_since'");
|
|
58
60
|
let id = refId || (external ? refIdFor(input) : 'ref_' + sha1(randomUUID()).slice(0, 16));
|
|
59
|
-
|
|
61
|
+
const occupied = conn.get('SELECT deleted_at FROM refs WHERE id = :id', { id });
|
|
62
|
+
if (occupied) {
|
|
60
63
|
// id 被占用:直接 ref 换一个;locator 场景理论上不会撞(已按 locator 查过)
|
|
61
|
-
if (refId)
|
|
64
|
+
if (refId) {
|
|
65
|
+
// v11 软删过的 ref 被显式重新登记 = 恢复,重新从当前时刻开始失绑计时
|
|
66
|
+
if (hasOrphanSince && occupied.deleted_at != null) {
|
|
67
|
+
conn.run(
|
|
68
|
+
`UPDATE refs SET deleted_at = NULL, state = 'orphan', orphan_since = :at, updated_at = :at
|
|
69
|
+
WHERE id = :id`,
|
|
70
|
+
{ id, at: atMs }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return id;
|
|
74
|
+
}
|
|
62
75
|
id = 'ref_' + sha1(randomUUID()).slice(0, 16);
|
|
63
76
|
}
|
|
64
|
-
const hasOrigin = !!conn.get("SELECT name FROM pragma_table_info('refs') WHERE name = 'origin'");
|
|
65
77
|
if (hasOrigin) {
|
|
78
|
+
// v11 起新建即无归属的 ref 立刻开始失绑计时;迁移链里 v2/v6 阶段还没有这一列,
|
|
79
|
+
// 所以列清单按 pragma 现取(与 origin 的兼容原因相同)。
|
|
80
|
+
const cols = ['id', 'type', 'locator', 'origin', 'state', 'version', 'deleted_at', 'created_at', 'updated_at'];
|
|
81
|
+
const vals = [':id', "'md'", ':locator', ':origin', "'orphan'", '0', 'NULL', ':at', ':at'];
|
|
82
|
+
if (hasOrphanSince) {
|
|
83
|
+
cols.push('orphan_since');
|
|
84
|
+
vals.push(':at');
|
|
85
|
+
}
|
|
66
86
|
conn.run(
|
|
67
|
-
`INSERT INTO refs (
|
|
68
|
-
VALUES (:id, 'md', :locator, :origin, 'orphan', 0, NULL, :at, :at)
|
|
87
|
+
`INSERT INTO refs (${cols.join(', ')}) VALUES (${vals.join(', ')})
|
|
69
88
|
ON CONFLICT(id) DO NOTHING`,
|
|
70
89
|
{ id, locator: input, origin: external ? 'external' : 'own', at: atMs }
|
|
71
90
|
);
|
|
@@ -101,7 +120,6 @@ export interface RefBindingRow {
|
|
|
101
120
|
type?: string;
|
|
102
121
|
position?: number;
|
|
103
122
|
note?: string;
|
|
104
|
-
tag?: string;
|
|
105
123
|
atMs?: number;
|
|
106
124
|
}
|
|
107
125
|
|
|
@@ -113,12 +131,12 @@ export function putRefBinding(conn: any, {
|
|
|
113
131
|
type = 'repo',
|
|
114
132
|
position = 0,
|
|
115
133
|
note = '',
|
|
116
|
-
tag = '',
|
|
117
134
|
atMs = Date.now(),
|
|
118
135
|
}: RefBindingRow = {}): void {
|
|
136
|
+
// tag 列已在 schema v12 删除(分类标签概念整个去掉)
|
|
119
137
|
conn.run(
|
|
120
|
-
`INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note,
|
|
121
|
-
VALUES (:repo, :group, :ref, :type, :pos, :note, :
|
|
138
|
+
`INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, created_at)
|
|
139
|
+
VALUES (:repo, :group, :ref, :type, :pos, :note, :at)`,
|
|
122
140
|
{
|
|
123
141
|
repo: String(repoKey || ''),
|
|
124
142
|
group: groupKey == null ? null : String(groupKey),
|
|
@@ -126,7 +144,6 @@ export function putRefBinding(conn: any, {
|
|
|
126
144
|
type: String(type || 'repo'),
|
|
127
145
|
pos: Number(position) || 0,
|
|
128
146
|
note: String(note || ''),
|
|
129
|
-
tag: String(tag || ''),
|
|
130
147
|
at: atMs,
|
|
131
148
|
}
|
|
132
149
|
);
|
|
@@ -141,14 +158,20 @@ export function clearRefBindings(conn: any): void {
|
|
|
141
158
|
export function markRefBound(conn: any, refId?: string): void {
|
|
142
159
|
const id = String(refId || '');
|
|
143
160
|
if (!id) return;
|
|
144
|
-
conn.run(
|
|
161
|
+
conn.run(
|
|
162
|
+
"UPDATE refs SET state = '', orphan_since = 0, updated_at = :at WHERE id = :id",
|
|
163
|
+
{ id, at: Date.now() }
|
|
164
|
+
);
|
|
145
165
|
}
|
|
146
166
|
|
|
147
167
|
/** 没有任何绑定的 ref → 回到 orphan(重建收尾,防止摘绑定后状态残留)。 */
|
|
148
168
|
export function markUnboundRefsOrphan(conn: any): number {
|
|
149
169
|
const r = conn.run(
|
|
150
|
-
`UPDATE refs SET state = 'orphan',
|
|
151
|
-
|
|
170
|
+
`UPDATE refs SET state = 'orphan',
|
|
171
|
+
orphan_since = CASE WHEN orphan_since > 0 THEN orphan_since ELSE :at END,
|
|
172
|
+
updated_at = :at
|
|
173
|
+
WHERE deleted_at IS NULL
|
|
174
|
+
AND (state <> 'orphan' OR orphan_since = 0)
|
|
152
175
|
AND id NOT IN (SELECT ref_id FROM ref_bindings)`,
|
|
153
176
|
{ at: Date.now() }
|
|
154
177
|
);
|
package/src/core/config.ts
CHANGED
|
@@ -17,8 +17,14 @@ import { nowMs } from './db/time.js';
|
|
|
17
17
|
export const PREF_KEYS = Object.freeze([
|
|
18
18
|
'gitRepoRoot',
|
|
19
19
|
'gitDevRoot',
|
|
20
|
+
'orphanTtlDays',
|
|
20
21
|
] as const);
|
|
21
22
|
|
|
23
|
+
/** 孤儿 ref 的默认保留天数(可配置;0 或非法值回落为它)。 */
|
|
24
|
+
export const DEFAULT_ORPHAN_TTL_DAYS = 3;
|
|
25
|
+
const ORPHAN_TTL_MIN_DAYS = 1;
|
|
26
|
+
const ORPHAN_TTL_MAX_DAYS = 3650;
|
|
27
|
+
|
|
22
28
|
/** settings 表里偏好字段的键名。 */
|
|
23
29
|
export const APP_SETTING_KEYS = Object.freeze(PREF_KEYS.map((k) => 'app.' + k));
|
|
24
30
|
|
|
@@ -26,6 +32,8 @@ export const APP_SETTING_KEYS = Object.freeze(PREF_KEYS.map((k) => 'app.' + k));
|
|
|
26
32
|
export interface AppConfig {
|
|
27
33
|
gitRepoRoot: string;
|
|
28
34
|
gitDevRoot: string;
|
|
35
|
+
/** 孤儿 ref 到期天数(默认 3;范围 1–3650)。 */
|
|
36
|
+
orphanTtlDays: number;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
const EMPTY = (): AppConfig => ({
|
|
@@ -34,8 +42,19 @@ const EMPTY = (): AppConfig => ({
|
|
|
34
42
|
gitRepoRoot: '',
|
|
35
43
|
// 导入布局时开发仓库(type=dev)的默认克隆根;空 = 导入时 dev 只登记不克隆。
|
|
36
44
|
gitDevRoot: '',
|
|
45
|
+
// 无任何归属的 ref 保留天数;到期由 serve 例行维护 / docs orphans purge 清理。
|
|
46
|
+
orphanTtlDays: DEFAULT_ORPHAN_TTL_DAYS,
|
|
37
47
|
});
|
|
38
48
|
|
|
49
|
+
/** TTL 天数归一:非数字 / 越界一律回落默认值。 */
|
|
50
|
+
function normalizeTtlDays(v: unknown): number {
|
|
51
|
+
const n = Math.trunc(Number(v));
|
|
52
|
+
if (!Number.isFinite(n) || n < ORPHAN_TTL_MIN_DAYS || n > ORPHAN_TTL_MAX_DAYS) {
|
|
53
|
+
return DEFAULT_ORPHAN_TTL_DAYS;
|
|
54
|
+
}
|
|
55
|
+
return n;
|
|
56
|
+
}
|
|
57
|
+
|
|
39
58
|
let cache: AppConfig | null = null;
|
|
40
59
|
|
|
41
60
|
/** 全量归一(保证形状与类型稳定)。 */
|
|
@@ -46,6 +65,7 @@ function normalize(data: unknown): AppConfig {
|
|
|
46
65
|
return {
|
|
47
66
|
gitRepoRoot: String(d.gitRepoRoot || ''),
|
|
48
67
|
gitDevRoot: String(d.gitDevRoot || ''),
|
|
68
|
+
orphanTtlDays: normalizeTtlDays(d.orphanTtlDays),
|
|
49
69
|
};
|
|
50
70
|
}
|
|
51
71
|
|
|
@@ -126,9 +126,9 @@ export function importRefs(
|
|
|
126
126
|
// 旧 JSON 里的键名就叫 rel(v6 之前的字段名);读出来一律当 **locator** 用。
|
|
127
127
|
const legacyPath = String(ref.rel || '').trim();
|
|
128
128
|
const path = String(ref.path || '').trim();
|
|
129
|
-
if (legacyPath) out.push({ locator: legacyPath, type: 'md', note: String(
|
|
129
|
+
if (legacyPath) out.push({ locator: legacyPath, type: 'md', note: String(note || ''), extPath: '' });
|
|
130
130
|
// v2 起 refs 只装文档:外部 .md 绝对路径也是文档,type 统一为 md。
|
|
131
|
-
else if (path) out.push({ locator: path, type: 'md', note: String(
|
|
131
|
+
else if (path) out.push({ locator: path, type: 'md', note: String(note || ''), extPath: path });
|
|
132
132
|
};
|
|
133
133
|
pushRef(host && host.doc);
|
|
134
134
|
for (const l of Array.isArray(host && host.docLinks) ? host.docLinks : []) pushRef(l);
|
|
@@ -18,6 +18,7 @@ import { migrateAttachments } from './v2-data.js';
|
|
|
18
18
|
import { migrateGroupRefs } from './v4-data.js';
|
|
19
19
|
import { migrateRefsBodies } from './v6-data.js';
|
|
20
20
|
import { migrateRefsRel } from './v8-data.js';
|
|
21
|
+
import { migrateOrphanRefs } from './v11-data.js';
|
|
21
22
|
import { CURRENT_SCHEMA_VERSION } from '../version.js';
|
|
22
23
|
import type { DbApi } from '../driver.js';
|
|
23
24
|
|
|
@@ -60,6 +61,8 @@ export const DIRECT_EDGES: MigrationStep[] = [
|
|
|
60
61
|
{ from: 7, to: 8, file: 'v8.sql', title: '去 rel:ref 只按 id / locator 寻址(bindings 补 tag)', apply: migrateRefsRel },
|
|
61
62
|
{ from: 8, to: 9, file: 'v9.sql', title: '任务新增 plan 状态(不进队列的临时草稿;重建 tasks 扩 CHECK)' },
|
|
62
63
|
{ from: 9, to: 10, file: 'v10.sql', title: '附件新增 folder 类型(本地文件夹路径指针;重建 attachments 扩 CHECK)' },
|
|
64
|
+
{ from: 10, to: 11, file: 'v11.sql', title: '孤儿 ref 失绑计时(orphan_since)与到期清理留痕(ref_gc_log)', apply: migrateOrphanRefs },
|
|
65
|
+
{ from: 11, to: 12, file: 'v12.sql', title: '去掉分类标签概念(删 ref_bindings.tag)' },
|
|
63
66
|
];
|
|
64
67
|
|
|
65
68
|
// 人读版本说明(docs/decisions 是决策的唯一权威位置,里面对应一份 date 化的 .md)
|
|
@@ -74,6 +77,8 @@ export const VERSION_NOTES = {
|
|
|
74
77
|
8: 'docs/decisions/versions/2026-11-13-v8.md',
|
|
75
78
|
9: 'docs/decisions/versions/2026-11-14-v9.md',
|
|
76
79
|
10: 'docs/decisions/versions/2026-11-14-v10.md',
|
|
80
|
+
11: 'docs/decisions/versions/2026-11-15-v11.md',
|
|
81
|
+
12: 'docs/decisions/versions/2026-11-16-v12.md',
|
|
77
82
|
};
|
|
78
83
|
|
|
79
84
|
const keyOf = (from: number, to: number): string => `${from}->${to}`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// schema v10 → v11 的数据迁移(在 v11.sql 的同一个事务里执行)。
|
|
2
|
+
//
|
|
3
|
+
// 口径:
|
|
4
|
+
// · 孤儿定义 = 没有任何 ref_bindings 行的未删除 ref;
|
|
5
|
+
// · 存量孤儿的失绑起算时间统一按**升级时刻**(context.atMs)落库,
|
|
6
|
+
// 因此升级后仍有完整的 TTL 缓冲,不会被立刻清掉;
|
|
7
|
+
// · 有绑定的 ref 清掉 orphan_since(0 = 未计时);
|
|
8
|
+
// · 不碰 updated_at:迁移不该改变文档列表的最近更新排序。
|
|
9
|
+
export interface V11Context {
|
|
10
|
+
atMs?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OrphanSinceBackfillResult {
|
|
14
|
+
orphaned: number;
|
|
15
|
+
bound: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function migrateOrphanRefs(
|
|
19
|
+
conn: any,
|
|
20
|
+
{ atMs = Date.now() }: V11Context = {}
|
|
21
|
+
): OrphanSinceBackfillResult {
|
|
22
|
+
const orphaned = conn.run(
|
|
23
|
+
`UPDATE refs SET state = 'orphan', orphan_since = :at
|
|
24
|
+
WHERE deleted_at IS NULL
|
|
25
|
+
AND orphan_since = 0
|
|
26
|
+
AND id NOT IN (SELECT ref_id FROM ref_bindings)`,
|
|
27
|
+
{ at: atMs }
|
|
28
|
+
);
|
|
29
|
+
const bound = conn.run(
|
|
30
|
+
`UPDATE refs SET state = '', orphan_since = 0
|
|
31
|
+
WHERE deleted_at IS NULL
|
|
32
|
+
AND (state <> '' OR orphan_since <> 0)
|
|
33
|
+
AND id IN (SELECT ref_id FROM ref_bindings)`
|
|
34
|
+
);
|
|
35
|
+
return { orphaned: Number(orphaned.changes) || 0, bound: Number(bound.changes) || 0 };
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- schema v11:孤儿文档的失绑计时与到期清理留痕
|
|
2
|
+
--
|
|
3
|
+
-- 口径(2026-11-15 用户拍板):ref 没有任何 ref_bindings 归属即为孤儿;
|
|
4
|
+
-- 失绑起算时间落 refs.orphan_since(0 = 未计时 / 仍有归属)。
|
|
5
|
+
-- 到期清理**只软删** refs 行(deleted_at),不碰 ref_bodies;
|
|
6
|
+
-- 每次清理在 ref_gc_log 留一条不可变记录(删除前清单、删除后审计都读它)。
|
|
7
|
+
--
|
|
8
|
+
-- @decision docs/decisions/2026-11-15-orphan-ref-gc.md
|
|
9
|
+
ALTER TABLE refs ADD COLUMN orphan_since INTEGER NOT NULL DEFAULT 0;
|
|
10
|
+
|
|
11
|
+
-- @decision docs/decisions/2026-11-15-orphan-ref-gc.md
|
|
12
|
+
CREATE TABLE ref_gc_log (
|
|
13
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
14
|
+
ref_id TEXT NOT NULL,
|
|
15
|
+
ref_desc TEXT NOT NULL DEFAULT '',
|
|
16
|
+
origin TEXT NOT NULL DEFAULT '',
|
|
17
|
+
body_bytes INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
unbound_at INTEGER NOT NULL,
|
|
19
|
+
deleted_at INTEGER NOT NULL,
|
|
20
|
+
ttl_days INTEGER NOT NULL,
|
|
21
|
+
reason TEXT NOT NULL DEFAULT '',
|
|
22
|
+
source TEXT NOT NULL DEFAULT '',
|
|
23
|
+
snapshot TEXT NOT NULL DEFAULT '{}',
|
|
24
|
+
created_at INTEGER NOT NULL
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
CREATE INDEX ix_ref_gc_log_ref ON ref_gc_log (ref_id);
|
|
28
|
+
CREATE INDEX ix_ref_gc_log_deleted ON ref_gc_log (deleted_at);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- schema v12:去掉「分类标签」这个概念
|
|
2
|
+
--
|
|
3
|
+
-- 口径(2026-11-16 用户拍板):文档绑定的「分类标签」(`--tag qa` 那一套)
|
|
4
|
+
-- **在整个应用里没有落点**——面板里没有编辑入口、检索里也几乎不用,
|
|
5
|
+
-- 却让宿主 ext、ref_bindings 索引、API 形状、CLI 输出到处都背着一个字段。
|
|
6
|
+
-- 无效概念就该从根上删掉,而不是留着假装有用。
|
|
7
|
+
--
|
|
8
|
+
-- 本次动作:`ref_bindings.tag` 列直接删(DROP COLUMN)。
|
|
9
|
+
-- 这一列只是分类标签的索引投影,没有别的用途:
|
|
10
|
+
-- 关系描述文档的定位不走它——**desc 就在 ref 上**
|
|
11
|
+
-- (同一条关系的描述 = 该参考仓库文档列表里 desc 等于「在组「X」里参考什么」的那一篇)。
|
|
12
|
+
--
|
|
13
|
+
-- @decision docs/decisions/2026-11-16-drop-tag-concept.md
|
|
14
|
+
ALTER TABLE ref_bindings DROP COLUMN tag;
|
|
@@ -243,6 +243,16 @@ function normalizeDocs(doc: RefDocRef | null, links: RefDocRef[]): { doc: RefDoc
|
|
|
243
243
|
|
|
244
244
|
// ─── 主流程 ────────────────────────────────────────────────────────────
|
|
245
245
|
|
|
246
|
+
/** 表里有没有这一列(历史迁移要兼容「列后来被删了」的当前 schema)。 */
|
|
247
|
+
function hasColumn(conn: any, table: string, column: string): boolean {
|
|
248
|
+
try {
|
|
249
|
+
const rows = conn.all(`PRAGMA table_info(${table})`);
|
|
250
|
+
return rows.some((r: any) => String(r.name || '') === column);
|
|
251
|
+
} catch {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
246
256
|
export function migrateRefsRel(conn: any, { atMs = Date.now() }: V8Context = {}): RefsRelRemovalResult {
|
|
247
257
|
const warnings: string[] = [];
|
|
248
258
|
const rows: any[] = conn.all(
|
|
@@ -351,8 +361,14 @@ export function migrateRefsRel(conn: any, { atMs = Date.now() }: V8Context = {})
|
|
|
351
361
|
}
|
|
352
362
|
|
|
353
363
|
// 已有直接 ref 归属(v7 只写 ref_bindings)反向补进宿主 ext
|
|
364
|
+
//
|
|
365
|
+
// #137:tag 列(分类标签)已在 schema v12 删除。这段是**历史迁移**——真升级
|
|
366
|
+
// (v7 → v8)时该列还在(v8.sql 才加的),行为一字不变;但 legacy JSON 导入
|
|
367
|
+
// 会把这段跑在**当前** schema 上(没有 tag 列)→ 按列是否存在裁剪,两种情形都对。
|
|
368
|
+
const hasTagCol = hasColumn(conn, 'ref_bindings', 'tag');
|
|
354
369
|
const existingBindings: any[] = conn.all(
|
|
355
|
-
|
|
370
|
+
`SELECT repo_key, group_key, ref_id, type, position, note${hasTagCol ? ', tag' : ''}
|
|
371
|
+
FROM ref_bindings ORDER BY type, position, rowid`
|
|
356
372
|
);
|
|
357
373
|
for (const b of existingBindings) {
|
|
358
374
|
const refId = String(b.ref_id || '');
|
|
@@ -413,8 +429,8 @@ export function migrateRefsRel(conn: any, { atMs = Date.now() }: V8Context = {})
|
|
|
413
429
|
return;
|
|
414
430
|
}
|
|
415
431
|
const r = conn.run(
|
|
416
|
-
`INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, tag, created_at)
|
|
417
|
-
VALUES (:repo, :group, :ref, :type, :pos, :note, :tag, :at)`,
|
|
432
|
+
`INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note${hasTagCol ? ', tag' : ''}, created_at)
|
|
433
|
+
VALUES (:repo, :group, :ref, :type, :pos, :note${hasTagCol ? ', :tag' : ''}, :at)`,
|
|
418
434
|
{
|
|
419
435
|
repo: repoKey,
|
|
420
436
|
group: groupKey,
|
|
@@ -422,7 +438,7 @@ export function migrateRefsRel(conn: any, { atMs = Date.now() }: V8Context = {})
|
|
|
422
438
|
type,
|
|
423
439
|
pos,
|
|
424
440
|
note: clean(d.note),
|
|
425
|
-
tag: clean(d.tag),
|
|
441
|
+
...(hasTagCol ? { tag: clean(d.tag) } : {}),
|
|
426
442
|
at: atMs,
|
|
427
443
|
}
|
|
428
444
|
);
|
package/src/core/db/version.ts
CHANGED
|
@@ -34,7 +34,11 @@
|
|
|
34
34
|
// SQLite 不能 ALTER CHECK,按 v5 的 12-step 模式重建 tasks 并快照/回填所有关系表。
|
|
35
35
|
// v10(2026-11-14):attachments.kind 新增 `folder`(本地文件夹路径指针,
|
|
36
36
|
// 不复制目录内容);同样按 v5 的 12-step 模式重建以扩 CHECK。
|
|
37
|
-
|
|
37
|
+
// v11(2026-11-15):refs 增加 orphan_since(无任何 ref_bindings 的失绑起算时间);
|
|
38
|
+
// 新增 ref_gc_log(孤儿到期清理的不可变留痕)。存量孤儿按升级时刻起算。
|
|
39
|
+
// v12(2026-11-16):去掉「分类标签」概念——删 ref_bindings.tag 列。
|
|
40
|
+
// 关系描述文档的定位不走 tag:desc 就在 ref 上。
|
|
41
|
+
export const CURRENT_SCHEMA_VERSION = 12;
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* 运行时最低 Node 版本。
|
|
@@ -25,6 +25,8 @@ import { DocsGcAction } from './docs-gc.js';
|
|
|
25
25
|
import { DocsIndexAction } from './docs-index.js';
|
|
26
26
|
import { DocsLinkAction } from './docs-link.js';
|
|
27
27
|
import { DocsNotebindAction } from './docs-notebind.js';
|
|
28
|
+
import { DocsOrphansPurgeAction } from './docs-orphans-purge.js';
|
|
29
|
+
import { DocsOrphansAction } from './docs-orphans.js';
|
|
28
30
|
|
|
29
31
|
/** 本模块的全部 action 类(容器按这个顺序建实例)。 */
|
|
30
32
|
export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
|
|
@@ -47,6 +49,8 @@ export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
|
|
|
47
49
|
DocsIndexAction,
|
|
48
50
|
DocsLinkAction,
|
|
49
51
|
DocsNotebindAction,
|
|
52
|
+
DocsOrphansPurgeAction,
|
|
53
|
+
DocsOrphansAction,
|
|
50
54
|
];
|
|
51
55
|
|
|
52
56
|
// 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
|
|
@@ -69,3 +73,5 @@ export { DocsGcAction };
|
|
|
69
73
|
export { DocsIndexAction };
|
|
70
74
|
export { DocsLinkAction };
|
|
71
75
|
export { DocsNotebindAction };
|
|
76
|
+
export { DocsOrphansPurgeAction };
|
|
77
|
+
export { DocsOrphansAction };
|
|
@@ -87,7 +87,7 @@ export class DocsBindingsAction extends ActionBase<typeof input> {
|
|
|
87
87
|
http: ['GET', '/api/docs/bindings'],
|
|
88
88
|
summary: '查文档归属(--ref <refId> 看这篇被谁引用;--host <repo> 只看仓库自己的文档;--group <组> 看组域文档集:组 → 组内仓库 → 成员仓库自己 → 组内参考仓库自己;hostKind 标宿主是开发仓库/参考仓库/组;position=0 为主篇)',
|
|
89
89
|
input,
|
|
90
|
-
// 备注(只有附加篇有:主篇 push 时不带 note)跟着 main
|
|
90
|
+
// 备注(只有附加篇有:主篇 push 时不带 note)跟着 main 一起打,和前端注解上的
|
|
91
91
|
// 「附加 · 备注」保持同一口径——否则 CLI 里看不出自己刚填的备注有没有落库。
|
|
92
92
|
render: (d: any) => (d.bindings || [])
|
|
93
93
|
.map((b: any) => {
|
|
@@ -153,7 +153,7 @@ export class DocsBindingsAction extends ActionBase<typeof input> {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
const rows = db.all(
|
|
156
|
-
`SELECT b.repo_key AS repoKey, b.group_key AS groupKey, b.type, b.position, b.note,
|
|
156
|
+
`SELECT b.repo_key AS repoKey, b.group_key AS groupKey, b.type, b.position, b.note,
|
|
157
157
|
r.id AS refId, r."desc", r.origin, r.locator,
|
|
158
158
|
CASE WHEN rb.ref_id IS NULL THEN 0 ELSE 1 END AS has_body,
|
|
159
159
|
rb.body
|
|
@@ -185,7 +185,6 @@ export class DocsBindingsAction extends ActionBase<typeof input> {
|
|
|
185
185
|
position,
|
|
186
186
|
main: position === 0,
|
|
187
187
|
note: String(r.note || ''),
|
|
188
|
-
tag: String(r.tag || ''),
|
|
189
188
|
// 宿主 kind(#132):dev 开发仓库 / ref 参考仓库 / group 组。
|
|
190
189
|
// 参考仓库与开发仓库在底层只有这一个差异,列表上标出来才不会看不懂。
|
|
191
190
|
hostKind: kindOf.get(String(r.repoKey)) || 'dev',
|
|
@@ -15,7 +15,6 @@ const input = z.object({
|
|
|
15
15
|
ref: z.string().optional().describe("文档 refId(ref_<16hex>)"),
|
|
16
16
|
path: z.string().optional().describe("外部文件/目录绝对路径(登记成 origin=external 的 ref)"),
|
|
17
17
|
note: z.string().optional().describe("条目说明"),
|
|
18
|
-
tag: z.string().optional().describe("分类标签(如 qa;简介行渲染成小 chip;空串 = 清掉)"),
|
|
19
18
|
remove: z.number().optional().describe("移除第 N 条(1 起)"),
|
|
20
19
|
before: z.number().optional().describe("插到第 N 条之前(缺省追加到末尾)"),
|
|
21
20
|
});
|
|
@@ -25,7 +24,7 @@ export class DocsLinkAction extends ActionBase<typeof input> {
|
|
|
25
24
|
id: 'docs.link',
|
|
26
25
|
cli: ['docs', 'link'],
|
|
27
26
|
http: ['POST', '/api/docs/link'],
|
|
28
|
-
summary: '维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note
|
|
27
|
+
summary: '维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 更新)',
|
|
29
28
|
args: ['board'],
|
|
30
29
|
input,
|
|
31
30
|
render: renderLink,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// docs.orphans.purge —— 到期孤儿的预演 / 软删。
|
|
2
|
+
//
|
|
3
|
+
// 默认 dry-run:只列「会被删的篇目」。`--apply` 才软删空正文且到期的孤儿;
|
|
4
|
+
// 有正文的到期孤儿永远只进清单(skippedWithBody),不自动删。
|
|
5
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
8
|
+
import { sweepOrphans, renderOrphans } from '../orphan.js';
|
|
9
|
+
|
|
10
|
+
/** docs.orphans.purge 的入参契约(CLI 与 HTTP 共用)。 */
|
|
11
|
+
const input = z.object({
|
|
12
|
+
apply: z.boolean().optional().describe('真的软删(缺省 = 只预演,不动数据)'),
|
|
13
|
+
ttlDays: z.number().int().min(1).max(3650).optional().describe('按指定保留天数额外算一遍(不落库;缺省读设置)'),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export class DocsOrphansPurgeAction extends ActionBase<typeof input> {
|
|
17
|
+
@action({
|
|
18
|
+
id: 'docs.orphans.purge',
|
|
19
|
+
cli: ['docs', 'orphans', 'purge'],
|
|
20
|
+
http: ['POST', '/api/docs/orphans/purge'],
|
|
21
|
+
summary: '孤儿到期清理(默认只预演;--apply 软删空正文到期孤儿,有正文的只列清单)',
|
|
22
|
+
input,
|
|
23
|
+
render: renderOrphans,
|
|
24
|
+
})
|
|
25
|
+
override async run(ctx: ActionInput<this['_input']>) {
|
|
26
|
+
return sweepOrphans({ apply: ctx.apply === true, ttlDays: ctx.ttlDays, source: 'cli' });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// docs.orphans —— 只读列出「没有任何归属(ref_bindings)」的孤儿文档。
|
|
2
|
+
//
|
|
3
|
+
// 给「谁要到期、还差多久」一个可核对的窗口:失绑时间、剩余天数、是否到期、
|
|
4
|
+
// 是否有正文(有正文的到期孤儿不会自动清,必须能单独看见)。
|
|
5
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
8
|
+
import { listOrphans, renderOrphans } from '../orphan.js';
|
|
9
|
+
|
|
10
|
+
/** docs.orphans 的入参契约(CLI 与 HTTP 共用)。 */
|
|
11
|
+
const input = z.object({
|
|
12
|
+
ttlDays: z.number().int().min(1).max(3650).optional().describe('按指定保留天数额外算一遍(不落库;缺省读设置)'),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export class DocsOrphansAction extends ActionBase<typeof input> {
|
|
16
|
+
@action({
|
|
17
|
+
id: 'docs.orphans',
|
|
18
|
+
cli: ['docs', 'orphans'],
|
|
19
|
+
http: ['GET', '/api/docs/orphans'],
|
|
20
|
+
summary: '列出无归属的孤儿文档(失绑时间 / 剩余天数 / 是否有正文;只读)',
|
|
21
|
+
input,
|
|
22
|
+
render: renderOrphans,
|
|
23
|
+
})
|
|
24
|
+
override async run(ctx: ActionInput<this['_input']>) {
|
|
25
|
+
return listOrphans({ ttlDays: ctx.ttlDays });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -46,7 +46,6 @@ export interface DocBriefView {
|
|
|
46
46
|
/** 正文摘要(首个非标题行);没有正文时为空 */
|
|
47
47
|
summary: string;
|
|
48
48
|
note: string;
|
|
49
|
-
tag: string;
|
|
50
49
|
/** 有正文(外部镜像也算存在:正文在库外) */
|
|
51
50
|
exists: boolean;
|
|
52
51
|
missing?: boolean;
|
|
@@ -105,7 +104,6 @@ export async function docSetOf(owner: any, _kind: 'repo' | 'board' = 'repo'): Pr
|
|
|
105
104
|
desc: row.desc,
|
|
106
105
|
summary: body ? summaryFromMd(body) : '',
|
|
107
106
|
note: String((raw && raw.note) || ''),
|
|
108
|
-
tag: String((raw && raw.tag) || ''),
|
|
109
107
|
exists: row.hasBody || row.origin === 'external',
|
|
110
108
|
...(row.hasBody || row.origin === 'external' ? {} : { missing: true }),
|
|
111
109
|
};
|