nx-kv 0.59.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +3 -2
  3. 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
  4. package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +3 -3
  5. package/package.json +1 -1
  6. package/src/core/attachmentdb/docs.ts +3 -5
  7. package/src/core/db/import-json/refs.ts +2 -2
  8. package/src/core/db/migrations/index.ts +2 -0
  9. package/src/core/db/migrations/v12.sql +14 -0
  10. package/src/core/db/migrations/v8-data.ts +20 -4
  11. package/src/core/db/version.ts +3 -1
  12. package/src/modules/docs/actions/docs-bindings.ts +2 -3
  13. package/src/modules/docs/actions/docs-link.ts +1 -2
  14. package/src/modules/docs/brief.ts +0 -2
  15. package/src/modules/docs/docref.ts +8 -7
  16. package/src/modules/docs/knowledge.ts +1 -4
  17. package/src/modules/docs/ref-sync.ts +1 -5
  18. package/src/modules/docs/refs.ts +66 -8
  19. package/src/modules/docs/render.ts +1 -1
  20. package/src/modules/docs/service.ts +1 -3
  21. package/src/modules/repos/actions/repo-doc-add.ts +1 -2
  22. package/src/modules/repos/actions/repo-doc-list.ts +1 -1
  23. package/src/modules/repos/actions/repo-knowledge.ts +1 -1
  24. package/src/modules/repos/actions/repo-ref-note.ts +4 -4
  25. package/src/modules/repos/boards/core.ts +0 -3
  26. package/src/modules/repos/{link-note.ts → ref-note-doc.ts} +53 -29
  27. package/src/modules/repos/ref.ts +8 -36
  28. package/src/modules/repos/transfer/export.ts +3 -3
  29. package/src/modules/repos/transfer/layout.ts +3 -3
  30. package/src/modules/tasktool/delivery-template.ts +3 -4
  31. package/src/web/frontend/api/cli-tree.json +2 -2
  32. package/src/web/frontend/api/client.generated.ts +4 -4
  33. package/src/web/frontend/components/Introduction/use-intro.ts +2 -4
  34. package/src/web/frontend/modules/refs/api.ts +0 -1
  35. package/src/web/frontend/page/repos/index.tsx +1 -1
  36. package/src/web/frontend/refs/api.ts +0 -1
  37. package/src/web/public/assets/{composer-panel-MB_2m-jI.js → composer-panel-BhT_eFic.js} +1 -1
  38. package/src/web/public/assets/{dir-BQZAPk92.js → dir-1w7D_lg7.js} +1 -1
  39. package/src/web/public/assets/{doc-CKkCGsZ4.js → doc-Dn4-viog.js} +1 -1
  40. package/src/web/public/assets/{group-CXDiKp4X.js → group-BsvhgO5r.js} +1 -1
  41. package/src/web/public/assets/{index-Dmlh01et.js → index-CBVkXanT.js} +2 -2
  42. package/src/web/public/assets/{refs-DvvwZmdl.js → refs-BHzLZnJn.js} +1 -1
  43. package/src/web/public/assets/{repo-form-modal-pyqiC7pB.js → repo-form-modal-BafSPVlv.js} +1 -1
  44. package/src/web/public/assets/{repos-CeyrjSQ_.js → repos-CmlsSN0h.js} +2 -2
  45. package/src/web/public/assets/{settings-KNodW2wX.js → settings-C_Dkc9gQ.js} +1 -1
  46. package/src/web/public/assets/{task-DJF54sKp.js → task-Ci94al50.js} +1 -1
  47. package/src/web/public/assets/{templates-BaX3bQsl.js → templates-Dc5Pln-Q.js} +1 -1
  48. package/src/web/public/index.html +3 -3
  49. package/src/modules/docs/link-note.ts +0 -171
package/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
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
+
5
40
  ## [0.59.0] - 2026-11-16 孤儿 ref 到期清理(3 天 TTL)+ 软删留痕
6
41
 
7
42
  > 这一版的 schema v11 与孤儿清理由**并行会话**完成(同一工作树),本会话代为校准门禁并发布。
@@ -77,7 +77,7 @@ nx-kv localtask done --id <id> --cwd "<项目目录>" --summary "<回答了什
77
77
 
78
78
  - 第 ① 步就已经把 ref 挂进仓库了:仓库**有主篇** → 它是附加篇;**没有主篇** → 它就是主篇。
79
79
  **别再重复挂一次**(同一篇挂两次,列表里会出现两条)。
80
- - 附件与文档**不要挂两遍**;`--tag` 在面板里没有入口,别用它当分类手段。
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
- 自己的文档列表(定位靠 `link-note:<关系 key>`),面板上不再有弹窗与「写描述」按钮;
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
- (右侧栏「<参考仓库名> · 文档列表」里可见可编辑),定位靠 `link-note:<关系 key>`——
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` `--tag` `--remove` `--before` `--reset` | 宿主文档集的增删改(`bind` 主篇,`link` 目录补充,`note-bind` 组内描述) |
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:说明落成该**参考仓库的一篇文档**(右侧栏「<名字> · 文档列表」可见可编辑),同一关系重复写 = 改同一篇,`--note ""` = 清除 |
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` `--tag` / `--index` | 仓库文档集(主篇 + 附加) |
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -120,7 +120,6 @@ export interface RefBindingRow {
120
120
  type?: string;
121
121
  position?: number;
122
122
  note?: string;
123
- tag?: string;
124
123
  atMs?: number;
125
124
  }
126
125
 
@@ -132,12 +131,12 @@ export function putRefBinding(conn: any, {
132
131
  type = 'repo',
133
132
  position = 0,
134
133
  note = '',
135
- tag = '',
136
134
  atMs = Date.now(),
137
135
  }: RefBindingRow = {}): void {
136
+ // tag 列已在 schema v12 删除(分类标签概念整个去掉)
138
137
  conn.run(
139
- `INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, tag, created_at)
140
- VALUES (:repo, :group, :ref, :type, :pos, :note, :tag, :at)`,
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)`,
141
140
  {
142
141
  repo: String(repoKey || ''),
143
142
  group: groupKey == null ? null : String(groupKey),
@@ -145,7 +144,6 @@ export function putRefBinding(conn: any, {
145
144
  type: String(type || 'repo'),
146
145
  pos: Number(position) || 0,
147
146
  note: String(note || ''),
148
- tag: String(tag || ''),
149
147
  at: atMs,
150
148
  }
151
149
  );
@@ -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(ref.tag || note || ''), extPath: '' });
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(ref.tag || note || ''), extPath: path });
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);
@@ -62,6 +62,7 @@ export const DIRECT_EDGES: MigrationStep[] = [
62
62
  { from: 8, to: 9, file: 'v9.sql', title: '任务新增 plan 状态(不进队列的临时草稿;重建 tasks 扩 CHECK)' },
63
63
  { from: 9, to: 10, file: 'v10.sql', title: '附件新增 folder 类型(本地文件夹路径指针;重建 attachments 扩 CHECK)' },
64
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)' },
65
66
  ];
66
67
 
67
68
  // 人读版本说明(docs/decisions 是决策的唯一权威位置,里面对应一份 date 化的 .md)
@@ -77,6 +78,7 @@ export const VERSION_NOTES = {
77
78
  9: 'docs/decisions/versions/2026-11-14-v9.md',
78
79
  10: 'docs/decisions/versions/2026-11-14-v10.md',
79
80
  11: 'docs/decisions/versions/2026-11-15-v11.md',
81
+ 12: 'docs/decisions/versions/2026-11-16-v12.md',
80
82
  };
81
83
 
82
84
  const keyOf = (from: number, to: number): string => `${from}->${to}`;
@@ -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
- 'SELECT repo_key, group_key, ref_id, type, position, note, tag FROM ref_bindings ORDER BY type, position, rowid'
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
  );
@@ -36,7 +36,9 @@
36
36
  // 不复制目录内容);同样按 v5 的 12-step 模式重建以扩 CHECK。
37
37
  // v11(2026-11-15):refs 增加 orphan_since(无任何 ref_bindings 的失绑起算时间);
38
38
  // 新增 ref_gc_log(孤儿到期清理的不可变留痕)。存量孤儿按升级时刻起算。
39
- export const CURRENT_SCHEMA_VERSION = 11;
39
+ // v12(2026-11-16):去掉「分类标签」概念——删 ref_bindings.tag 列。
40
+ // 关系描述文档的定位不走 tag:desc 就在 ref 上。
41
+ export const CURRENT_SCHEMA_VERSION = 12;
40
42
 
41
43
  /**
42
44
  * 运行时最低 Node 版本。
@@ -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 一起打,和前端 tag 上的
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, b.tag,
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/--tag;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 更新)',
27
+ summary: '维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 更新)',
29
28
  args: ['board'],
30
29
  input,
31
30
  render: renderLink,
@@ -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
  };
@@ -9,12 +9,15 @@
9
9
  // 实际位置在 refs.locator;宿主只认 refId。
10
10
  import { badInput } from '../../core/errors.js';
11
11
 
12
- /** DocRef:{ ref } 指向文档库条目;note/tag 是列表条目的注解(docLinks 用)。 */
12
+ /**
13
+ * DocRef:{ ref } 指向文档库条目;note 是列表条目的注解(docLinks 用)。
14
+ *
15
+ * #137 之前还有 `tag`(分类标签)——面板没有入口、无处可用,已在 v12 整个删掉。
16
+ */
13
17
  export interface DocRef {
14
18
  ref?: string;
15
- /** 链接级注解(note/tag,docLinks 条目用) */
19
+ /** 链接级注解(note,docLinks 条目用) */
16
20
  note?: string;
17
- tag?: string;
18
21
  }
19
22
 
20
23
  /** DocRef + 链接级注解(withLinkMeta 的产出形状)。 */
@@ -50,18 +53,16 @@ export function sanitizeDocRef(raw: unknown): DocRef | null {
50
53
  }
51
54
 
52
55
  /**
53
- * DocRef + 链接级注解(note/tag)合成列表条目。
56
+ * DocRef + 链接级注解(note)合成列表条目。
54
57
  *
55
58
  * 注解要过三道关(写入口合并 / 读归一化回贴 / 导出保留),三处口径必须一致——
56
59
  * 实现只此一份,docs/refs 与 repos/service、transfer 都从这里拿。
57
60
  * 空串/缺省 = 不落字段(对已有条目即「清掉」)。
58
61
  */
59
- export function withLinkMeta(ref: DocRef, raw: { note?: unknown; tag?: unknown } = {}): DocRefWithMeta {
62
+ export function withLinkMeta(ref: DocRef, raw: { note?: unknown } = {}): DocRefWithMeta {
60
63
  const note = typeof raw.note === 'string' ? raw.note.trim() : '';
61
- const tag = typeof raw.tag === 'string' ? raw.tag.trim() : '';
62
64
  const entry: DocRefWithMeta = { ...ref };
63
65
  if (note) entry.note = note;
64
- if (tag) entry.tag = tag;
65
66
  return entry;
66
67
  }
67
68
 
@@ -23,7 +23,6 @@ export interface KnowledgeDoc {
23
23
  name?: string;
24
24
  path?: string;
25
25
  note?: string;
26
- tag?: string;
27
26
  missing?: boolean;
28
27
  dir?: boolean;
29
28
  files?: string[];
@@ -146,7 +145,7 @@ async function readRefDocs(raw: DocRef | null | undefined, opts: ReadOpts): Prom
146
145
  }
147
146
  return docs;
148
147
  }
149
- return [{ ...one, refId, note: String((raw && raw.note) || ''), tag: String((raw && raw.tag) || '') }];
148
+ return [{ ...one, refId, note: String((raw && raw.note) || '') }];
150
149
  }
151
150
  if (!row.hasBody) {
152
151
  return [{
@@ -155,14 +154,12 @@ async function readRefDocs(raw: DocRef | null | undefined, opts: ReadOpts): Prom
155
154
  docId: 'ref:' + refId,
156
155
  title: row.desc,
157
156
  note: String((raw && raw.note) || ''),
158
- tag: String((raw && raw.tag) || ''),
159
157
  }];
160
158
  }
161
159
  return [{
162
160
  ...docOut('ref:' + refId, row.body ?? '', opts),
163
161
  refId,
164
162
  note: String((raw && raw.note) || ''),
165
- tag: String((raw && raw.tag) || ''),
166
163
  }];
167
164
  }
168
165
 
@@ -22,7 +22,6 @@ interface DesiredBinding {
22
22
  refId: string;
23
23
  position: number;
24
24
  note: string;
25
- tag: string;
26
25
  }
27
26
 
28
27
  export interface SyncRefIndexInput {
@@ -45,8 +44,7 @@ export function desiredBindings(s: any): DesiredBinding[] {
45
44
  type: DesiredBinding['type'],
46
45
  raw: any,
47
46
  position: number,
48
- note = '',
49
- tag = ''
47
+ note = ''
50
48
  ): void => {
51
49
  const refId = String((raw && raw.ref) || '').trim();
52
50
  if (!refId) return;
@@ -57,7 +55,6 @@ export function desiredBindings(s: any): DesiredBinding[] {
57
55
  refId,
58
56
  position: Number(position) || 0,
59
57
  note: String((raw && raw.note) ?? note ?? ''),
60
- tag: String((raw && raw.tag) ?? tag ?? ''),
61
58
  });
62
59
  };
63
60
 
@@ -115,7 +112,6 @@ export async function syncRefIndex({ store: s }: SyncRefIndexInput = {}): Promis
115
112
  type: b.type,
116
113
  position: b.position,
117
114
  note: b.note,
118
- tag: b.tag,
119
115
  });
120
116
  markRefBound(conn, b.refId);
121
117
  n += 1;
@@ -139,7 +139,6 @@ export interface SetDocLinkInput {
139
139
  ref?: string;
140
140
  path?: string;
141
141
  note?: string;
142
- tag?: string;
143
142
  remove?: number;
144
143
  before?: number;
145
144
  }
@@ -147,13 +146,13 @@ export interface SetDocLinkInput {
147
146
  /**
148
147
  * 维护组的 docLinks。
149
148
  * --ref <refId> 或 --path <绝对路径>(外部只读)
150
- * note / tag 条目注解
149
+ * note 条目注解
151
150
  * remove --remove <序号>(1 起)
152
151
  * before --before <序号>(插到该条之前;缺省追加)
153
152
  *
154
- * 同 ref 重复添加 = 更新该条(note/tag 以本次为准)。
153
+ * 同 ref 重复添加 = 更新该条(note 以本次为准)。
155
154
  */
156
- export async function setDocLink({ board, ref, path, note, tag, remove, before }: SetDocLinkInput = {}): Promise<any> {
155
+ export async function setDocLink({ board, ref, path, note, remove, before }: SetDocLinkInput = {}): Promise<any> {
157
156
  if (!board) throw badInput('缺少看板(id / key / 名称)');
158
157
  const { mutateStore, boardKeyOf } = await reposBridge();
159
158
  const docRef = remove === undefined ? await docRefOf({ ref, path }) : null;
@@ -175,8 +174,8 @@ export async function setDocLink({ board, ref, path, note, tag, remove, before }
175
174
  return { boardName: b.name, removed: describeLink(gone), count: b.docLinks.length };
176
175
  }
177
176
 
178
- // 条目 = DocRef + 注解(note/tag);合成逻辑收在 docref.withLinkMeta
179
- const entry = withLinkMeta(docRef!, { note, tag });
177
+ // 条目 = DocRef + 注解(note);合成逻辑收在 docref.withLinkMeta
178
+ const entry = withLinkMeta(docRef!, { note });
180
179
  const at = b.docLinks.findIndex((x: any) => (x && x.ref) === entry.ref);
181
180
  if (at >= 0) b.docLinks.splice(at, 1);
182
181
  const want = before !== undefined ? idxOf(before) : -1;
@@ -222,7 +221,6 @@ export interface AddRepoDocInput {
222
221
  ref?: string;
223
222
  path?: string;
224
223
  note?: string;
225
- tag?: string;
226
224
  }
227
225
 
228
226
  /** 往项目的介绍文档集里加一篇(同 ref 重复添加 = 更新注解)。 */
@@ -231,7 +229,7 @@ export async function addRepoDoc(locator: string, raw: unknown): Promise<any> {
231
229
  const repo = await getRepo(locator);
232
230
  const input = (raw && typeof raw === 'object' ? raw : {}) as AddRepoDocInput;
233
231
  const docRef = await docRefOf({ ref: input.ref, path: input.path });
234
- const entry = withLinkMeta(docRef, { note: input.note, tag: input.tag });
232
+ const entry = withLinkMeta(docRef, { note: input.note });
235
233
  const res = await mutateStore((s: any) => {
236
234
  const r = s.repos.find((x: any) => deriveKey(x) === deriveKey(repo));
237
235
  if (!r) throw notFound('repo 不存在: ' + locator);
@@ -246,6 +244,66 @@ export async function addRepoDoc(locator: string, raw: unknown): Promise<any> {
246
244
  return res;
247
245
  }
248
246
 
247
+ /**
248
+ * 「建一篇文档并挂到某个仓库上」——关系描述的落点(#137)。
249
+ *
250
+ * 定位口径:**desc 就在 ref 上**——同一个 desc 的那篇就是它;
251
+ * 找到了就改(正文 + desc),没找到就新建一篇并挂到该仓库的文档列表。
252
+ */
253
+ export async function setDocLinkDoc({ repoKey, desc, body }: {
254
+ repoKey: string;
255
+ desc: string;
256
+ body?: string;
257
+ }): Promise<{ refId: string; desc: string; created: boolean }> {
258
+ const { getRepo, deriveKey, mutateStore } = await reposBridge();
259
+ const repo = await getRepo(repoKey);
260
+ const key = deriveKey(repo);
261
+ const label = String(desc || '').trim();
262
+ const text = String(body ?? '');
263
+
264
+ // ① 找同 desc 的那篇(该仓库的文档集里)
265
+ const s = await (await reposBridge()).loadStore();
266
+ const r = s.repos.find((x: any) => deriveKey(x) === key);
267
+ const ids: string[] = [];
268
+ if (r && r.doc && r.doc.ref) ids.push(String(r.doc.ref));
269
+ for (const l of (r && Array.isArray(r.docLinks) ? r.docLinks : [])) {
270
+ if (l && l.ref) ids.push(String(l.ref));
271
+ }
272
+ let hit = '';
273
+ for (const id of ids) {
274
+ const row = getDb().get(`SELECT "desc" AS desc FROM refs WHERE id = :id AND deleted_at IS NULL`, { id });
275
+ if (row && String(row.desc || '') === label) { hit = id; break; }
276
+ }
277
+
278
+ if (hit) {
279
+ // ② 改:正文 + desc(同一篇,不新增)
280
+ const { writeOwnDoc, setOwnDocDesc } = await import('./store.js');
281
+ await writeOwnDoc(hit, text);
282
+ await setOwnDocDesc(hit, label);
283
+ return { refId: hit, desc: label, created: false };
284
+ }
285
+
286
+ // ③ 建:新建一篇自有文档(空正文也落行)+ 挂到仓库文档集
287
+ const { createRef } = await import('./service.js');
288
+ const made = await createRef({ desc: label, owner: 'repo', repo: key });
289
+ const { writeOwnDoc } = await import('./store.js');
290
+ await writeOwnDoc(made.refId, text);
291
+ // createRef 会把它挂成**主篇**(仓库没有主篇时);关系描述是「又一篇」,
292
+ // 应当是附加篇 —— 把主篇位还回去(本来就是空的),改挂 docLinks。
293
+ await mutateStore((draft: any) => {
294
+ const dr = draft.repos.find((x: any) => deriveKey(x) === key);
295
+ if (!dr) return;
296
+ if (dr.doc && dr.doc.ref === made.refId) {
297
+ delete dr.doc;
298
+ if (!Array.isArray(dr.docLinks)) dr.docLinks = [];
299
+ dr.docLinks.push({ ref: made.refId });
300
+ }
301
+ dr.updatedAt = new Date().toISOString();
302
+ });
303
+ await syncRefIndex();
304
+ return { refId: made.refId, desc: label, created: true };
305
+ }
306
+
249
307
  /** 从项目的介绍文档集里摘掉一篇(--index 从 1 起;1 = 主篇) */
250
308
  export async function removeRepoDoc(locator: string, index: unknown): Promise<any> {
251
309
  const { getRepo, deriveKey, mutateStore } = await reposBridge();
@@ -60,7 +60,7 @@ export const renderLink = (d: any): string => {
60
60
  if (d.removed !== undefined) return `已移除组绑定: ${d.removed}(剩 ${d.count} 条)`;
61
61
  const lines = [`「${d.boardName}」的组绑定(${d.count} 条):`];
62
62
  for (const l of d.links) {
63
- lines.push(` ref:${l.ref}${l.tag ? ` [${l.tag}]` : ''}${l.note ? ` · ${l.note}` : ''}`);
63
+ lines.push(` ref:${l.ref}${l.note ? ` · ${l.note}` : ''}`);
64
64
  }
65
65
  return lines.join('\n');
66
66
  };
@@ -82,7 +82,6 @@ export interface RefBindingView {
82
82
  groupKey: string | null;
83
83
  position: number;
84
84
  note: string;
85
- tag: string;
86
85
  main: boolean;
87
86
  }
88
87
 
@@ -198,7 +197,7 @@ function bindingsOfRef(refId: string): RefBindingView[] {
198
197
  if (!clean(refId)) return [];
199
198
  return getDb()
200
199
  .all(
201
- `SELECT type, repo_key AS repoKey, group_key AS groupKey, position, note, tag
200
+ `SELECT type, repo_key AS repoKey, group_key AS groupKey, position, note
202
201
  FROM ref_bindings WHERE ref_id = :id ORDER BY type, position`,
203
202
  { id: refId }
204
203
  )
@@ -208,7 +207,6 @@ function bindingsOfRef(refId: string): RefBindingView[] {
208
207
  groupKey: r.groupKey == null ? null : String(r.groupKey),
209
208
  position: Number(r.position) || 0,
210
209
  note: String(r.note || ''),
211
- tag: String(r.tag || ''),
212
210
  main: (Number(r.position) || 0) === 0,
213
211
  }));
214
212
  }
@@ -13,7 +13,6 @@ const input = z.object({
13
13
  ref: z.string().optional().describe("文档 refId(ref_<16hex>)"),
14
14
  path: z.string().optional().describe("外部绝对路径(登记成 origin=external 的 ref)"),
15
15
  note: z.string().optional().describe("这篇的说明"),
16
- tag: z.string().optional().describe("分类标签(如 qa;简介行渲染成小 chip;空串 = 清掉)"),
17
16
  });
18
17
 
19
18
  export class RepoDocAddAction extends ActionBase<typeof input> {
@@ -28,7 +27,7 @@ export class RepoDocAddAction extends ActionBase<typeof input> {
28
27
  })
29
28
  override async run(ctx: ActionInput<this['_input']>) {
30
29
 
31
- return addRepoDoc(ctx.id, { ref: ctx.ref, path: ctx.path, note: ctx.note, tag: ctx.tag });
30
+ return addRepoDoc(ctx.id, { ref: ctx.ref, path: ctx.path, note: ctx.note });
32
31
 
33
32
  }
34
33
  }
@@ -21,7 +21,7 @@ export class RepoDocListAction extends ActionBase<typeof input> {
21
21
  args: ['id'],
22
22
  input,
23
23
  render: (d: any) => {
24
- const one: any = (x: any, i: any) => ` ${i}. ${x.title || x.desc || x.ref}${x.tag ? ` [${x.tag}]` : ''}${x.note ? ` # ${x.note}` : ''}${x.missing ? ' (缺正文)' : ''}`;
24
+ const one: any = (x: any, i: any) => ` ${i}. ${x.title || x.desc || x.ref}${x.note ? ` # ${x.note}` : ''}${x.missing ? ' (缺正文)' : ''}`;
25
25
  const lines: any = [`【${d.repo.name}】介绍文档 ${d.count} 篇`];
26
26
  // 描述是**列表**:主篇 + 登记的补充(#58)
27
27
  let n: any = 0;
@@ -30,7 +30,7 @@ export class RepoKnowledgeAction extends ActionBase<typeof input> {
30
30
  lines.push(` ◇ 组「${b.name}」`);
31
31
  if (b.intro && !b.intro.missing) lines.push(` 组介绍: ${b.intro.docId}`);
32
32
  if (b.note && !b.note.missing) lines.push(` 组内描述: ${b.note.docId}`);
33
- for (const l of b.docLinks) lines.push(` 绑定: ${l.docId}${l.tag ? ` [${l.tag}]` : ''}${l.note ? ` · ${l.note}` : ''}${l.missing ? '(缺失)' : ''}`);
33
+ for (const l of b.docLinks) lines.push(` 绑定: ${l.docId}${l.note ? ` · ${l.note}` : ''}${l.missing ? '(缺失)' : ''}`);
34
34
  for (const x of b.externalDirs) lines.push(` 外部目录: ${x.path}(${x.files.length} 个文档,按需读盘)`);
35
35
  }
36
36
  if (d.refRepos.length) {
@@ -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 linkNote from '../link-note.js';
8
- const link: any = linkNote;
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
- '写/清绑定描述:这个参考在该组/该仓库里参考什么(#134:描述归档成该参考仓库的一篇文档,' +
25
- '在「<参考仓库名> · 文档列表」里可见可编辑;--note 留空 = 清除)',
24
+ '写/清绑定描述:这个参考在该组/该仓库里参考什么(描述落成该参考仓库文档列表里的一篇文档,' +
25
+ 'desc 由系统生成;--note 留空 = 清除那篇)',
26
26
  args: ['id'],
27
27
  input,
28
28
  render: (d: any) =>