nx-kv 0.62.1 → 0.64.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 +62 -0
- package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +6 -5
- package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +2 -1
- package/package.json +2 -2
- package/src/core/attachmentdb/docs.ts +3 -6
- package/src/core/attachmentdb/query.ts +2 -2
- package/src/core/attachmentdb/relations.ts +36 -21
- package/src/core/db/import-json/refs.ts +17 -19
- package/src/core/db/import-json/repos.ts +4 -8
- package/src/core/db/migrations/index.ts +2 -0
- package/src/core/db/migrations/v13.sql +24 -0
- package/src/core/db/seed-templates.ts +86 -3
- package/src/core/db/version.ts +3 -1
- package/src/modules/docs/actions/_manifest.generated.ts +3 -3
- package/src/modules/docs/actions/doc-attach.ts +0 -1
- package/src/modules/docs/actions/docs-bindings.ts +2 -5
- package/src/modules/docs/actions/docs-link.ts +1 -2
- package/src/modules/docs/actions/docs-main.ts +39 -0
- package/src/modules/docs/attach.ts +1 -36
- package/src/modules/docs/bound-docs.ts +2 -2
- package/src/modules/docs/brief.ts +0 -2
- package/src/modules/docs/docref.ts +7 -17
- package/src/modules/docs/knowledge-md.ts +1 -1
- package/src/modules/docs/knowledge.ts +48 -45
- package/src/modules/docs/ref-sync.ts +1 -5
- package/src/modules/docs/refs.ts +82 -10
- package/src/modules/docs/service.ts +1 -3
- package/src/modules/localtask/actions/localtask-config.ts +19 -58
- package/src/modules/localtask/actions/localtask-prune.ts +7 -2
- package/src/modules/localtask/repo/open.ts +0 -4
- package/src/modules/localtask/repo/settings.ts +20 -196
- package/src/modules/localtask/task-lifecycle.ts +7 -9
- package/src/modules/localtask/task-templates.ts +4 -4
- package/src/modules/localtask/task-view.ts +4 -0
- package/src/modules/localtask/topics.ts +30 -28
- package/src/modules/promptplug/actions/_manifest.generated.ts +0 -3
- package/src/modules/promptplug/actions/prompt-registry.ts +19 -30
- package/src/modules/promptplug/base.ts +69 -25
- package/src/modules/promptplug/compose.ts +40 -23
- package/src/modules/promptplug/factory.ts +91 -59
- package/src/modules/promptplug/index.ts +25 -11
- package/src/modules/promptplug/plugins/ack.ts +28 -0
- package/src/modules/promptplug/plugins/attachment.ts +237 -19
- package/src/modules/promptplug/plugins/context.ts +124 -30
- package/src/modules/promptplug/plugins/doneguard.ts +33 -0
- package/src/modules/promptplug/plugins/ext.ts +34 -11
- package/src/modules/promptplug/plugins/getloop.ts +29 -8
- package/src/modules/promptplug/plugins/goal-shape.ts +34 -0
- package/src/modules/promptplug/plugins/goalhint.ts +33 -0
- package/src/modules/promptplug/plugins/timecheck.ts +33 -0
- package/src/modules/promptplug/registry.ts +99 -0
- package/src/modules/promptplug/schema-bridge.ts +77 -13
- package/src/modules/repos/actions/board-rekey.ts +1 -1
- package/src/modules/repos/actions/repo-doc-add.ts +2 -3
- package/src/modules/repos/boards/core.ts +1 -13
- package/src/modules/repos/boards/docs.ts +2 -12
- package/src/modules/repos/boards/members.ts +2 -14
- package/src/modules/repos/boards/transfer.ts +2 -11
- package/src/modules/repos/keys.ts +4 -11
- package/src/modules/repos/repo/refs.ts +3 -5
- package/src/modules/repos/repo/repos.ts +12 -13
- package/src/modules/repos/repo/rows.ts +2 -8
- package/src/modules/repos/service/context.ts +0 -2
- package/src/modules/repos/service/crud.ts +1 -4
- package/src/modules/repos/service/store.ts +6 -7
- package/src/modules/repos/transfer/export.ts +3 -8
- package/src/modules/repos/transfer/import.ts +0 -13
- package/src/modules/repos/transfer/layout.ts +2 -2
- package/src/modules/tasktool/attach-template.ts +3 -3
- package/src/modules/tasktool/groupctx.ts +4 -5
- package/src/modules/tasktool/plugins/waitgoal-config.ts +5 -6
- package/src/modules/tasktool/preview.ts +20 -23
- package/src/modules/tasktool/wait.ts +24 -46
- package/src/modules/templates/actions/_manifest.generated.ts +3 -0
- package/src/modules/templates/actions/templates-reorder.ts +28 -0
- package/src/modules/templates/repo/templates.ts +32 -2
- package/src/modules/templates/service.ts +45 -0
- package/src/shared/prompt-blocks.ts +7 -173
- package/src/shared/prompt-plugin.ts +79 -59
- package/src/web/frontend/App.tsx +27 -1
- package/src/web/frontend/api/cli-tree.json +35 -35
- package/src/web/frontend/api/client.generated.ts +32 -32
- package/src/web/frontend/components/Introduction/rail.tsx +2 -2
- package/src/web/frontend/components/Introduction/use-intro.ts +2 -5
- package/src/web/frontend/components/bindings/bind-tags.tsx +1 -3
- package/src/web/frontend/components/icons.tsx +12 -0
- package/src/web/frontend/components/list-search.tsx +37 -0
- package/src/web/frontend/components/md/attach-area.tsx +10 -15
- package/src/web/frontend/components/md/live-block.tsx +8 -2
- package/src/web/frontend/components/md/md-panes-root.tsx +4 -0
- package/src/web/frontend/components/md/md-panes.tsx +11 -1
- package/src/web/frontend/components/popup/style.css +4 -0
- package/src/web/frontend/components/sidebar/index.tsx +1 -0
- package/src/web/frontend/modules/list-filter.ts +37 -0
- package/src/web/frontend/modules/md/fill-session.ts +36 -0
- package/src/web/frontend/modules/md/manage-session.ts +24 -0
- package/src/web/frontend/modules/md/new-task-from-template.ts +22 -0
- package/src/web/frontend/modules/md/styles/editor.css +17 -0
- package/src/web/frontend/modules/md/styles/panels.css +14 -2
- package/src/web/frontend/modules/md/styles/shell.css +4 -0
- package/src/web/frontend/modules/md/task-intent.ts +29 -0
- package/src/web/frontend/modules/md/use-templates.ts +24 -5
- package/src/web/frontend/modules/prompts/template-preview.ts +62 -0
- package/src/web/frontend/modules/refs/api.ts +0 -1
- package/src/web/frontend/page/dir/index.tsx +36 -9
- package/src/web/frontend/page/dir/task-actions.ts +16 -1
- package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
- package/src/web/frontend/page/dir/task.tsx +21 -2
- package/src/web/frontend/page/doc/api.ts +2 -3
- package/src/web/frontend/page/doc/bindings.tsx +46 -16
- package/src/web/frontend/page/doc/index.tsx +3 -4
- package/src/web/frontend/page/group/index.tsx +72 -127
- package/src/web/frontend/page/refs/index.tsx +76 -13
- package/src/web/frontend/page/refs/style.css +7 -0
- package/src/web/frontend/page/repos/bind-modals.tsx +18 -2
- package/src/web/frontend/page/repos/block-tabs.tsx +30 -24
- package/src/web/frontend/page/repos/board-admin.tsx +1 -1
- package/src/web/frontend/page/repos/branch-picker.tsx +29 -20
- package/src/web/frontend/page/repos/doc-block.tsx +9 -2
- package/src/web/frontend/page/repos/index.tsx +67 -39
- package/src/web/frontend/page/repos/ref-block.tsx +11 -18
- package/src/web/frontend/page/repos/ref-panel.tsx +3 -4
- package/src/web/frontend/page/repos/repo-form-modal.tsx +1 -8
- package/src/web/frontend/page/repos/repo-table.tsx +12 -37
- package/src/web/frontend/page/repos/search-results.tsx +114 -0
- package/src/web/frontend/page/repos/use-repos-derive.ts +4 -5
- package/src/web/frontend/page/settings/api.ts +7 -15
- package/src/web/frontend/page/settings/index.tsx +0 -14
- package/src/web/frontend/page/settings/prompt-templates-section.tsx +261 -289
- package/src/web/frontend/page/settings/prompt-vars.ts +56 -0
- package/src/web/frontend/page/settings/style.css +46 -64
- package/src/web/frontend/page/templates/fill.tsx +124 -0
- package/src/web/frontend/page/templates/index.tsx +81 -30
- package/src/web/frontend/page/templates/manage.tsx +218 -0
- package/src/web/frontend/page/templates/style.css +108 -0
- package/src/web/frontend/page/templates/template-list.tsx +202 -0
- package/src/web/frontend/panels.tsx +2 -2
- package/src/web/frontend/refs/api.ts +10 -2
- package/src/web/frontend/refs/ops.ts +15 -0
- package/src/web/frontend/routes/route-eq.ts +22 -0
- package/src/web/frontend/routes/templates.ts +20 -0
- package/src/web/frontend/style.css +1 -0
- package/src/web/frontend/styles/list-search.css +44 -0
- package/src/web/frontend/styles/repos-branch.css +72 -0
- package/src/web/frontend/types.ts +6 -0
- package/src/web/public/assets/app-context-DDQnrPSP.js +1 -0
- package/src/web/public/assets/bar-j14ON7uZ.js +1 -0
- package/src/web/public/assets/{board-view-CxihNjDm.js → board-view-BVennxTs.js} +1 -1
- package/src/web/public/assets/button-BEWXOABr.js +1 -0
- package/src/web/public/assets/composer-launch-DRi9mZE1.js +1 -0
- package/src/web/public/assets/composer-panel-swmDqlPw.js +1 -0
- package/src/web/public/assets/dag-BzdFYMml.js +1 -0
- package/src/web/public/assets/dir-DhsB1ZhL.js +3 -0
- package/src/web/public/assets/doc-D4po3sDc.js +6 -0
- package/src/web/public/assets/fill-session-fHxQHFaD.js +1 -0
- package/src/web/public/assets/frontmatter-CN6IlxWU.js +2 -0
- package/src/web/public/assets/group-BxmSNzIB.js +1 -0
- package/src/web/public/assets/index-CMjG5NVU.js +2 -0
- package/src/web/public/assets/index-uMjSWNVr.css +1 -0
- package/src/web/public/assets/list-filter-D-x94TvA.js +1 -0
- package/src/web/public/assets/manage-session-CS8UvmUd.js +1 -0
- package/src/web/public/assets/md-history-CZUF_FhN.js +39 -0
- package/src/web/public/assets/{md-parse-no7xfuA1.js → md-parse-C9Vd6ejP.js} +1 -1
- package/src/web/public/assets/member-picker-Cvbv24IK.js +1 -0
- package/src/web/public/assets/{model-YH7aER_y.js → model-Cc2EoUQp.js} +1 -1
- package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +1 -0
- package/src/web/public/assets/overview-CctJfO3D.js +1 -0
- package/src/web/public/assets/{frontmatter-BZrdOH46.css → popup-BAvk7J7u.css} +1 -1
- package/src/web/public/assets/{frontmatter-CK4ti7be.js → popup-D8KWI6-Q.js} +1 -2
- package/src/web/public/assets/progress-CawQRCQf.js +3 -0
- package/src/web/public/assets/refs-TuuoaRs7.js +2 -0
- package/src/web/public/assets/refs-zSA2k_45.css +1 -0
- package/src/web/public/assets/render-template-body-bXdedFig.js +1 -0
- package/src/web/public/assets/repo-form-modal-BD4N37MI.js +1 -0
- package/src/web/public/assets/repos-BPeuX4N9.js +12 -0
- package/src/web/public/assets/route-crumb-BcDPd7Ht.js +1 -0
- package/src/web/public/assets/settings-CZJaKLZW.js +1 -0
- package/src/web/public/assets/settings-Cc6puKd5.css +1 -0
- package/src/web/public/assets/status-tag-BD_0iWMB.js +1 -0
- package/src/web/public/assets/task-DgbbF5gy.js +11 -0
- package/src/web/public/assets/task-intent-CX5DZccN.js +1 -0
- package/src/web/public/assets/task-row-CQgzQmzu.js +1 -0
- package/src/web/public/assets/{task-utils-BIUeGQ-v.js → task-utils-bJH1-Cjy.js} +1 -1
- package/src/web/public/assets/templates-CBXlwyof.js +11 -0
- package/src/web/public/assets/templates-plA8R7jJ.css +1 -0
- package/src/web/public/assets/use-rail-drag-ufwy2XZB.js +1 -0
- package/src/web/public/assets/{workspace-BFjAH4-Z.js → workspace-D3jbcTwf.js} +2 -2
- package/src/web/public/index.html +19 -15
- package/src/modules/docs/actions/doc-attach-note.ts +0 -32
- package/src/modules/promptplug/Template/blockTemplates.json +0 -90
- package/src/modules/promptplug/actions/prompt-order.ts +0 -38
- package/src/modules/promptplug/ensure.ts +0 -57
- package/src/modules/promptplug/keys.ts +0 -9
- package/src/modules/promptplug/plugins/readonly-blocks.ts +0 -75
- package/src/modules/promptplug/template-bundle.ts +0 -59
- package/src/web/frontend/page/settings/prompt-editor.tsx +0 -279
- package/src/web/frontend/page/settings/prompt-rail.tsx +0 -170
- package/src/web/frontend/page/settings/task-templates-section.tsx +0 -124
- package/src/web/public/assets/app-context-DJ_8MHEG.js +0 -1
- package/src/web/public/assets/bar-D_n00iZf.js +0 -1
- package/src/web/public/assets/composer-launch-DKpTk_et.js +0 -1
- package/src/web/public/assets/composer-panel-BuTQ4otm.js +0 -1
- package/src/web/public/assets/dag-B-5Zh9um.js +0 -1
- package/src/web/public/assets/dir-XjJQx6mX.js +0 -3
- package/src/web/public/assets/doc-nLsdRBww.js +0 -6
- package/src/web/public/assets/group-DzkX_qJJ.js +0 -1
- package/src/web/public/assets/index-Cuio6jjI.css +0 -1
- package/src/web/public/assets/index-kP1chg-J.js +0 -2
- package/src/web/public/assets/md-history-Hu_Zzy11.js +0 -39
- package/src/web/public/assets/member-picker-BmpHTUrK.js +0 -1
- package/src/web/public/assets/overview-BkzCE6-x.js +0 -1
- package/src/web/public/assets/progress-uUW8vQTZ.js +0 -3
- package/src/web/public/assets/refs-Bs0RZMWI.js +0 -2
- package/src/web/public/assets/refs-CIdrPlDN.css +0 -1
- package/src/web/public/assets/repo-form-modal-Bwr95n7V.js +0 -1
- package/src/web/public/assets/repos-DceWSdjD.js +0 -16
- package/src/web/public/assets/route-crumb-D73iZP1h.js +0 -1
- package/src/web/public/assets/settings-AwzLRYUu.css +0 -1
- package/src/web/public/assets/settings-D9LFuVWi.js +0 -1
- package/src/web/public/assets/status-tag-DfTirXD_.js +0 -1
- package/src/web/public/assets/task-1TZaYQJI.js +0 -11
- package/src/web/public/assets/task-row-DFH4lNSh.js +0 -1
- package/src/web/public/assets/templates-B8sOtXTt.js +0 -1
- package/src/web/public/assets/use-rail-drag-CWKmhXVF.js +0 -1
- /package/src/web/public/assets/{repo-form-modal-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
|
@@ -20,7 +20,6 @@ const input = z.object({
|
|
|
20
20
|
mdfile: z.string().optional().describe("本地 .md 文件路径(kind=mdfile:只登记指针,不复制正文)"),
|
|
21
21
|
folder: z.string().optional().describe("本地文件夹路径(kind=folder:只登记目录路径,不复制内容)"),
|
|
22
22
|
name: z.string().optional().describe("显示名(默认取文件名/原名)"),
|
|
23
|
-
note: z.string().optional().describe("附件区备注"),
|
|
24
23
|
noEmbed: z.boolean().optional().describe("只写 ref_attach(role=attach),不改正文"),
|
|
25
24
|
'no-embed': z.boolean().optional().describe("同 --noEmbed"),
|
|
26
25
|
});
|
|
@@ -87,11 +87,9 @@ 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 一起打,和前端注解上的
|
|
91
|
-
// 「附加 · 备注」保持同一口径——否则 CLI 里看不出自己刚填的备注有没有落库。
|
|
92
90
|
render: (d: any) => (d.bindings || [])
|
|
93
91
|
.map((b: any) => {
|
|
94
|
-
const role = b.main ? '主篇' :
|
|
92
|
+
const role = b.main ? '主篇' : '附加';
|
|
95
93
|
const label = b.desc || b.title || b.refId;
|
|
96
94
|
return ` ${b.type} ${b.repoKey}${b.groupKey ? ' @' + b.groupKey : ''} ${role} ${label} [${b.refId}]`;
|
|
97
95
|
})
|
|
@@ -153,7 +151,7 @@ export class DocsBindingsAction extends ActionBase<typeof input> {
|
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
const rows = db.all(
|
|
156
|
-
`SELECT b.repo_key AS repoKey, b.group_key AS groupKey, b.type, b.position,
|
|
154
|
+
`SELECT b.repo_key AS repoKey, b.group_key AS groupKey, b.type, b.position,
|
|
157
155
|
r.id AS refId, r."desc", r.origin, r.locator,
|
|
158
156
|
CASE WHEN rb.ref_id IS NULL THEN 0 ELSE 1 END AS has_body,
|
|
159
157
|
rb.body
|
|
@@ -184,7 +182,6 @@ export class DocsBindingsAction extends ActionBase<typeof input> {
|
|
|
184
182
|
type,
|
|
185
183
|
position,
|
|
186
184
|
main: position === 0,
|
|
187
|
-
note: String(r.note || ''),
|
|
188
185
|
// 宿主 kind(#132):dev 开发仓库 / ref 参考仓库 / group 组。
|
|
189
186
|
// 参考仓库与开发仓库在底层只有这一个差异,列表上标出来才不会看不懂。
|
|
190
187
|
hostKind: kindOf.get(String(r.repoKey)) || 'dev',
|
|
@@ -14,7 +14,6 @@ const input = z.object({
|
|
|
14
14
|
board: z.string(),
|
|
15
15
|
ref: z.string().optional().describe("文档 refId(ref_<16hex>)"),
|
|
16
16
|
path: z.string().optional().describe("外部文件/目录绝对路径(登记成 origin=external 的 ref)"),
|
|
17
|
-
note: z.string().optional().describe("条目说明"),
|
|
18
17
|
remove: z.number().optional().describe("移除第 N 条(1 起)"),
|
|
19
18
|
before: z.number().optional().describe("插到第 N 条之前(缺省追加到末尾)"),
|
|
20
19
|
});
|
|
@@ -24,7 +23,7 @@ export class DocsLinkAction extends ActionBase<typeof input> {
|
|
|
24
23
|
id: 'docs.link',
|
|
25
24
|
cli: ['docs', 'link'],
|
|
26
25
|
http: ['POST', '/api/docs/link'],
|
|
27
|
-
summary: '维护组的附加文档列表(--ref <refId> | --path
|
|
26
|
+
summary: '维护组的附加文档列表(--ref <refId> | --path <外部路径>;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 移位)',
|
|
28
27
|
args: ['board'],
|
|
29
28
|
input,
|
|
30
29
|
render: renderLink,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// docs.main —— 把某一篇设为宿主的**主篇**(#144)。
|
|
2
|
+
//
|
|
3
|
+
// 与 docs.bind 的分工:
|
|
4
|
+
// · `docs bind` 是「指定主篇指针」的老命令,只换指针、不动附加篇(CLI 专用);
|
|
5
|
+
// · `docs main` 是**换位**:目标从附加篇摘出、原主篇退回附加篇,两边都不丢归属。
|
|
6
|
+
// 面板的「⋯ → 设为主篇」走这条(面板只认真实语义,不制造孤儿文档)。
|
|
7
|
+
//
|
|
8
|
+
// 宿主:`--repo <仓库>` 或 `--board <组>`(二选一);目标是 `--ref <refId>` 或 `--path`。
|
|
9
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
12
|
+
import * as refsNs from '../refs.js';
|
|
13
|
+
const refs: any = refsNs;
|
|
14
|
+
|
|
15
|
+
/** docs.main 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
16
|
+
const input = z.object({
|
|
17
|
+
repo: z.string().optional().describe('仓库(id / key / 名称)——与 --board 二选一'),
|
|
18
|
+
board: z.string().optional().describe('项目组(id / key / 名称)——与 --repo 二选一'),
|
|
19
|
+
ref: z.string().optional().describe('文档 refId(ref_<16hex>)'),
|
|
20
|
+
path: z.string().optional().describe('外部文件绝对路径(会登记成 origin=external 的 ref)'),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export class DocsMainAction extends ActionBase<typeof input> {
|
|
24
|
+
@action({
|
|
25
|
+
id: 'docs.main',
|
|
26
|
+
cli: ['docs', 'main'],
|
|
27
|
+
http: ['POST', '/api/docs/main'],
|
|
28
|
+
summary: '把某一篇设为主篇:原主篇退回附加篇(不丢归属),目标从附加篇摘出(不会出现两份)',
|
|
29
|
+
input,
|
|
30
|
+
render: (d: any) => (
|
|
31
|
+
d && d.alreadyMain
|
|
32
|
+
? `已经是主篇: ${d.name}`
|
|
33
|
+
: `已设为主篇: ${d.name}(原主篇${d.previous ? ` ${d.previous} ` : ' '}退回附加篇;列表共 ${d.count} 篇)`
|
|
34
|
+
),
|
|
35
|
+
})
|
|
36
|
+
override async run(ctx: ActionInput<this['_input']>) {
|
|
37
|
+
return refs.setDocMain(ctx);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
registerMdfile,
|
|
16
16
|
registerFolder,
|
|
17
17
|
unlinkAttachment,
|
|
18
|
-
updateAttachmentNote,
|
|
19
18
|
upsertFileAttachment,
|
|
20
19
|
} from '../../core/attachmentdb.js';
|
|
21
20
|
import type { LinkedAttachmentView } from '../../core/attachmentdb/query.js';
|
|
@@ -88,7 +87,6 @@ export interface AttachToDocCtx {
|
|
|
88
87
|
/** 本地文件夹(登记为 kind=folder,只存路径) */
|
|
89
88
|
folder?: unknown;
|
|
90
89
|
noEmbed?: unknown;
|
|
91
|
-
note?: unknown;
|
|
92
90
|
[key: string]: unknown;
|
|
93
91
|
}
|
|
94
92
|
|
|
@@ -209,7 +207,7 @@ export async function attachToDoc(ctx: AttachToDocCtx): Promise<AttachToDocResul
|
|
|
209
207
|
if (noEmbed) {
|
|
210
208
|
tx(
|
|
211
209
|
(conn) => {
|
|
212
|
-
linkAttachment(conn, { host: 'ref', hostId: hostRefId, attachmentId, role: 'attach'
|
|
210
|
+
linkAttachment(conn, { host: 'ref', hostId: hostRefId, attachmentId, role: 'attach' });
|
|
213
211
|
},
|
|
214
212
|
{ db, mode: 'IMMEDIATE' }
|
|
215
213
|
);
|
|
@@ -230,39 +228,6 @@ export async function attachToDoc(ctx: AttachToDocCtx): Promise<AttachToDocResul
|
|
|
230
228
|
};
|
|
231
229
|
}
|
|
232
230
|
|
|
233
|
-
/** docs attach --note 的入参。 */
|
|
234
|
-
export interface NoteOnDocInput {
|
|
235
|
-
ref?: unknown;
|
|
236
|
-
attachment?: unknown;
|
|
237
|
-
note?: unknown;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/** docs attach --note 的出参。 */
|
|
241
|
-
export interface NoteOnDocResult {
|
|
242
|
-
refId: string;
|
|
243
|
-
attachment: string;
|
|
244
|
-
note: string;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 改一条文档侧绑定上的说明(desc,#168):与任务侧同一口径——只动 note。
|
|
249
|
-
*/
|
|
250
|
-
export async function noteOnDoc({ ref, attachment, note = '' }: NoteOnDocInput = {}): Promise<NoteOnDocResult> {
|
|
251
|
-
const { refId } = await docRefOf(ref);
|
|
252
|
-
const attId = String(attachment || '').trim();
|
|
253
|
-
if (!attId) throw badInput('需要 --attachment <资源 id>(见 docs attachments 输出)');
|
|
254
|
-
const db = getDb();
|
|
255
|
-
let changed = 0;
|
|
256
|
-
tx(
|
|
257
|
-
(conn) => {
|
|
258
|
-
changed = updateAttachmentNote(conn, { host: 'ref', hostId: refId, attachmentId: attId, note: note as string | undefined });
|
|
259
|
-
},
|
|
260
|
-
{ db, mode: 'IMMEDIATE' }
|
|
261
|
-
);
|
|
262
|
-
if (!changed) throw badInput(`这篇文档上没有附件 ${attId}`);
|
|
263
|
-
return { refId, attachment: attId, note: String(note || '') };
|
|
264
|
-
}
|
|
265
|
-
|
|
266
231
|
/** docs detach 的入参。 */
|
|
267
232
|
export interface DetachFromDocInput {
|
|
268
233
|
ref?: unknown;
|
|
@@ -35,7 +35,7 @@ export function boundDocs({ repoKey = '', groupKey = '' }: { repoKey?: string; g
|
|
|
35
35
|
const group = String(groupKey || '').trim();
|
|
36
36
|
if (!repo && !group) return [];
|
|
37
37
|
const rows: any[] = getDb().all(
|
|
38
|
-
`SELECT b.type, b.repo_key, b.group_key, b.position,
|
|
38
|
+
`SELECT b.type, b.repo_key, b.group_key, b.position,
|
|
39
39
|
r.id AS ref_id, r."desc", r.origin,
|
|
40
40
|
CASE WHEN rb.ref_id IS NULL THEN 0 ELSE 1 END AS has_body,
|
|
41
41
|
rb.body
|
|
@@ -67,7 +67,7 @@ export function boundDocs({ repoKey = '', groupKey = '' }: { repoKey?: string; g
|
|
|
67
67
|
repoKey: String(x.repo_key || ''),
|
|
68
68
|
groupKey: x.group_key == null ? null : String(x.group_key),
|
|
69
69
|
position,
|
|
70
|
-
note:
|
|
70
|
+
note: '', // v13 起 ref_bindings 无 note 列;字段保留仅为兼容旧调用方
|
|
71
71
|
body,
|
|
72
72
|
};
|
|
73
73
|
});
|
|
@@ -45,7 +45,6 @@ export interface DocBriefView {
|
|
|
45
45
|
desc: string;
|
|
46
46
|
/** 正文摘要(首个非标题行);没有正文时为空 */
|
|
47
47
|
summary: string;
|
|
48
|
-
note: string;
|
|
49
48
|
/** 有正文(外部镜像也算存在:正文在库外) */
|
|
50
49
|
exists: boolean;
|
|
51
50
|
missing?: boolean;
|
|
@@ -103,7 +102,6 @@ export async function docSetOf(owner: any, _kind: 'repo' | 'board' = 'repo'): Pr
|
|
|
103
102
|
title,
|
|
104
103
|
desc: row.desc,
|
|
105
104
|
summary: body ? summaryFromMd(body) : '',
|
|
106
|
-
note: String((raw && raw.note) || ''),
|
|
107
105
|
exists: row.hasBody || row.origin === 'external',
|
|
108
106
|
...(row.hasBody || row.origin === 'external' ? {} : { missing: true }),
|
|
109
107
|
};
|
|
@@ -10,17 +10,16 @@
|
|
|
10
10
|
import { badInput } from '../../core/errors.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* DocRef:{ ref }
|
|
13
|
+
* DocRef:{ ref } 指向文档库条目。
|
|
14
14
|
*
|
|
15
|
-
* #137
|
|
15
|
+
* #137 的 `tag` 已在 v12 删掉;#148 的 `note`(列表条目注解)在 v13 删掉——
|
|
16
|
+
* 描述走 ref 自己的 desc + 正文标题,关系表不再挂业务字段。
|
|
16
17
|
*/
|
|
17
18
|
export interface DocRef {
|
|
18
19
|
ref?: string;
|
|
19
|
-
/** 链接级注解(note,docLinks 条目用) */
|
|
20
|
-
note?: string;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
/** DocRef
|
|
22
|
+
/** 兼容旧调用方的类型别名(现在与 DocRef 同形)。 */
|
|
24
23
|
export type DocRefWithMeta = DocRef;
|
|
25
24
|
|
|
26
25
|
const REF_ID_RE = /^ref_[0-9a-f]{16}$/i;
|
|
@@ -52,18 +51,9 @@ export function sanitizeDocRef(raw: unknown): DocRef | null {
|
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* 注解要过三道关(写入口合并 / 读归一化回贴 / 导出保留),三处口径必须一致——
|
|
59
|
-
* 实现只此一份,docs/refs 与 repos/service、transfer 都从这里拿。
|
|
60
|
-
* 空串/缺省 = 不落字段(对已有条目即「清掉」)。
|
|
61
|
-
*/
|
|
62
|
-
export function withLinkMeta(ref: DocRef, raw: { note?: unknown } = {}): DocRefWithMeta {
|
|
63
|
-
const note = typeof raw.note === 'string' ? raw.note.trim() : '';
|
|
64
|
-
const entry: DocRefWithMeta = { ...ref };
|
|
65
|
-
if (note) entry.note = note;
|
|
66
|
-
return entry;
|
|
54
|
+
/** 归一化一条文档条目(v13 去 note 后就是浅拷贝,保留名字让调用方语义统一)。 */
|
|
55
|
+
export function withLinkMeta(ref: DocRef): DocRefWithMeta {
|
|
56
|
+
return { ...ref };
|
|
67
57
|
}
|
|
68
58
|
|
|
69
59
|
// ─── docId(前后端统一寻址)────────────────────────────────────────────
|
|
@@ -40,7 +40,7 @@ export function renderRepoKnowledgeMd(k: RepoKnowledgeResult): string {
|
|
|
40
40
|
heading('## 参考仓库');
|
|
41
41
|
for (const r of k.refRepos) {
|
|
42
42
|
const src = r.direct && !r.groups.length ? '[直接绑定]' : r.direct ? '[组 + 直接绑定]' : '';
|
|
43
|
-
lines.push(`- ${r.name}${r.remote ? `(${r.remote})` : ''}${src}
|
|
43
|
+
lines.push(`- ${r.name}${r.remote ? `(${r.remote})` : ''}${src}`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return lines.join('\n');
|
|
@@ -9,6 +9,7 @@ import { reposBridge } from './repos-bridge.js';
|
|
|
9
9
|
import { getDb } from '../../core/db/index.js';
|
|
10
10
|
import { refDocById } from '../../core/attachmentdb.js';
|
|
11
11
|
import { renderRepoKnowledgeMd } from './knowledge-md.js';
|
|
12
|
+
import { docTitleFromMd } from '../../shared/doc-title.js';
|
|
12
13
|
import type { DocRef } from './docref.js';
|
|
13
14
|
|
|
14
15
|
const MAX_DOC_BYTES = 256 * 1024;
|
|
@@ -53,7 +54,6 @@ export interface RefRepoItem {
|
|
|
53
54
|
name: string;
|
|
54
55
|
path: string;
|
|
55
56
|
remote: string;
|
|
56
|
-
note: string;
|
|
57
57
|
groups: string[];
|
|
58
58
|
direct: boolean;
|
|
59
59
|
}
|
|
@@ -145,7 +145,7 @@ async function readRefDocs(raw: DocRef | null | undefined, opts: ReadOpts): Prom
|
|
|
145
145
|
}
|
|
146
146
|
return docs;
|
|
147
147
|
}
|
|
148
|
-
return [{ ...one, refId
|
|
148
|
+
return [{ ...one, refId }];
|
|
149
149
|
}
|
|
150
150
|
if (!row.hasBody) {
|
|
151
151
|
return [{
|
|
@@ -153,13 +153,11 @@ async function readRefDocs(raw: DocRef | null | undefined, opts: ReadOpts): Prom
|
|
|
153
153
|
refId,
|
|
154
154
|
docId: 'ref:' + refId,
|
|
155
155
|
title: row.desc,
|
|
156
|
-
note: String((raw && raw.note) || ''),
|
|
157
156
|
}];
|
|
158
157
|
}
|
|
159
158
|
return [{
|
|
160
159
|
...docOut('ref:' + refId, row.body ?? '', opts),
|
|
161
160
|
refId,
|
|
162
|
-
note: String((raw && raw.note) || ''),
|
|
163
161
|
}];
|
|
164
162
|
}
|
|
165
163
|
|
|
@@ -230,10 +228,9 @@ export async function repoKnowledge(locator?: string, { md = false }: { md?: boo
|
|
|
230
228
|
const hit = seenRefRepos.get(l.id);
|
|
231
229
|
if (hit) {
|
|
232
230
|
if (!hit.groups.includes(b.name)) hit.groups.push(b.name);
|
|
233
|
-
if (l.note && !hit.note) hit.note = l.note;
|
|
234
231
|
continue;
|
|
235
232
|
}
|
|
236
|
-
const item: RefRepoItem = { name: r.name, path: r.path || '', remote: r.remote || '',
|
|
233
|
+
const item: RefRepoItem = { name: r.name, path: r.path || '', remote: r.remote || '', groups: [b.name], direct: false };
|
|
237
234
|
seenRefRepos.set(l.id, item);
|
|
238
235
|
refRepos.push(item);
|
|
239
236
|
}
|
|
@@ -246,10 +243,9 @@ export async function repoKnowledge(locator?: string, { md = false }: { md?: boo
|
|
|
246
243
|
const hit = seenRefRepos.get(id);
|
|
247
244
|
if (hit) {
|
|
248
245
|
hit.direct = true;
|
|
249
|
-
if (l.note && !hit.note) hit.note = l.note;
|
|
250
246
|
continue;
|
|
251
247
|
}
|
|
252
|
-
const item: RefRepoItem = { name: r.name, path: r.path || '', remote: r.remote || '',
|
|
248
|
+
const item: RefRepoItem = { name: r.name, path: r.path || '', remote: r.remote || '', groups: [], direct: true };
|
|
253
249
|
seenRefRepos.set(id, item);
|
|
254
250
|
refRepos.push(item);
|
|
255
251
|
}
|
|
@@ -295,31 +291,36 @@ export async function groupContextFor(cwd: unknown, { board = '' }: { board?: st
|
|
|
295
291
|
refId: (repoMain && repoMain.refId) || '',
|
|
296
292
|
desc: '',
|
|
297
293
|
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
294
|
+
// #148:补充篇的 title/desc 必须从 refs 查真实值——原来写死 title:''、desc:note,
|
|
295
|
+
// 模板里 {{title}} 永远空、{{desc}} 拿到的是 note。DB 查不到时留空由模板回落。
|
|
296
|
+
const repoDocLinks: BoundDoc[] = (Array.isArray(repo.docLinks) ? repo.docLinks : []).map((l: any) => {
|
|
297
|
+
const refId = String(l.ref || '');
|
|
298
|
+
const d = refDocById(getDb(), refId);
|
|
299
|
+
return {
|
|
300
|
+
refId,
|
|
301
|
+
desc: String((d && d.desc) || ''),
|
|
302
|
+
title: d && d.hasBody ? docTitleFromMd(String(d.body ?? '')) : '',
|
|
303
|
+
hasBody: !!(d && (d.hasBody || d.origin === 'external')),
|
|
304
|
+
origin: '',
|
|
305
|
+
type: 'repo' as const,
|
|
306
|
+
repoKey: rk,
|
|
307
|
+
groupKey: null,
|
|
308
|
+
position: 0,
|
|
309
|
+
body: '',
|
|
310
|
+
};
|
|
311
|
+
});
|
|
311
312
|
|
|
312
313
|
// 参考仓库(repos 里 type=ref,不是文档库 refs):本仓库直接绑定与组级绑定
|
|
313
|
-
//
|
|
314
|
-
const refRepoItemOf = (id: unknown
|
|
314
|
+
// 是两类并列来源,交付时给「名称 + 本机路径」;说明走绑定 ref 的文档列表(v13)。
|
|
315
|
+
const refRepoItemOf = (id: unknown): { key: string; name: string; path: string } | null => {
|
|
315
316
|
const rr = s.repos.find((x: any) => x.type === 'ref' && deriveKey(x) === String(id));
|
|
316
317
|
if (!rr) return null;
|
|
317
|
-
return { key: String(id), name: rr.name, path: rr.path || ''
|
|
318
|
+
return { key: String(id), name: rr.name, path: rr.path || '' };
|
|
318
319
|
};
|
|
319
320
|
const repoRefRepos = (Array.isArray(repo.linked) ? repo.linked : [])
|
|
320
321
|
.filter((l: any) => l && l.kind === 'ref')
|
|
321
|
-
.map((l: any) => refRepoItemOf(l.id
|
|
322
|
-
.filter(Boolean) as Array<{ key: string; name: string; path: string
|
|
322
|
+
.map((l: any) => refRepoItemOf(l.id))
|
|
323
|
+
.filter(Boolean) as Array<{ key: string; name: string; path: string }>;
|
|
323
324
|
|
|
324
325
|
// #64 作用域:只有组任务(正文 frontmatter 带 board)才挂组上下文。
|
|
325
326
|
const wantBoard = String(board || '').trim();
|
|
@@ -338,19 +339,22 @@ export async function groupContextFor(cwd: unknown, { board = '' }: { board?: st
|
|
|
338
339
|
refId: (gMain && gMain.refId) || '',
|
|
339
340
|
desc: '',
|
|
340
341
|
};
|
|
341
|
-
const docLinks: BoundDoc[] = (Array.isArray(b.docLinks) ? b.docLinks : []).map((l: any) =>
|
|
342
|
-
refId
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
342
|
+
const docLinks: BoundDoc[] = (Array.isArray(b.docLinks) ? b.docLinks : []).map((l: any) => {
|
|
343
|
+
const refId = String(l.ref || '');
|
|
344
|
+
const d = refDocById(getDb(), refId);
|
|
345
|
+
return {
|
|
346
|
+
refId,
|
|
347
|
+
desc: String((d && d.desc) || ''),
|
|
348
|
+
title: d && d.hasBody ? docTitleFromMd(String(d.body ?? '')) : '',
|
|
349
|
+
hasBody: !!(d && (d.hasBody || d.origin === 'external')),
|
|
350
|
+
origin: '',
|
|
351
|
+
type: 'group' as const,
|
|
352
|
+
repoKey: gkey,
|
|
353
|
+
groupKey: null,
|
|
354
|
+
position: 0,
|
|
355
|
+
body: '',
|
|
356
|
+
};
|
|
357
|
+
});
|
|
354
358
|
// 本项目在组里的位置
|
|
355
359
|
const noteDocs = await readRefDocs((b.repoDocs || {})[rk], { warnings, label: `组内描述·${b.name}` });
|
|
356
360
|
const noteOwn = noteDocs[0] || null;
|
|
@@ -364,7 +368,7 @@ export async function groupContextFor(cwd: unknown, { board = '' }: { board?: st
|
|
|
364
368
|
const peer = peerDocs[0];
|
|
365
369
|
peers.push({
|
|
366
370
|
name: mname,
|
|
367
|
-
note: (peer && peer.body) ||
|
|
371
|
+
note: (peer && peer.body) || '',
|
|
368
372
|
path: (mr && mr.path) || '',
|
|
369
373
|
});
|
|
370
374
|
}
|
|
@@ -374,10 +378,10 @@ export async function groupContextFor(cwd: unknown, { board = '' }: { board?: st
|
|
|
374
378
|
desc: b.desc || '',
|
|
375
379
|
intro,
|
|
376
380
|
introSet: { main: null, extras: [], count: 0 },
|
|
377
|
-
note: (
|
|
381
|
+
note: (noteOwn && noteOwn.body) || '',
|
|
378
382
|
peers,
|
|
379
383
|
docLinks,
|
|
380
|
-
refRepos: (Array.isArray(b.refs) ? b.refs : []).map((l: any) => refRepoItemOf(l.id
|
|
384
|
+
refRepos: (Array.isArray(b.refs) ? b.refs : []).map((l: any) => refRepoItemOf(l.id)).filter(Boolean) as Array<{ key: string; name: string; path: string }>,
|
|
381
385
|
});
|
|
382
386
|
}
|
|
383
387
|
return {
|
|
@@ -405,7 +409,7 @@ export interface GroupContextGroup {
|
|
|
405
409
|
note: string;
|
|
406
410
|
peers: Array<{ name: string; path: string; note: string }>;
|
|
407
411
|
docLinks: BoundDoc[];
|
|
408
|
-
refRepos: Array<{ key: string; name: string; path: string
|
|
412
|
+
refRepos: Array<{ key: string; name: string; path: string }>;
|
|
409
413
|
}
|
|
410
414
|
|
|
411
415
|
/** groupContextFor 的出参。 */
|
|
@@ -416,7 +420,7 @@ export interface GroupContextResult {
|
|
|
416
420
|
intro: ContextIntro;
|
|
417
421
|
introSet: IntroSet;
|
|
418
422
|
docLinks: BoundDoc[];
|
|
419
|
-
refRepos: Array<{ key: string; name: string; path: string
|
|
423
|
+
refRepos: Array<{ key: string; name: string; path: string }>;
|
|
420
424
|
};
|
|
421
425
|
groups: GroupContextGroup[];
|
|
422
426
|
}
|
|
@@ -432,6 +436,5 @@ interface BoundDoc {
|
|
|
432
436
|
repoKey: string;
|
|
433
437
|
groupKey: string | null;
|
|
434
438
|
position: number;
|
|
435
|
-
note: string;
|
|
436
439
|
body: string;
|
|
437
440
|
}
|
|
@@ -21,7 +21,6 @@ interface DesiredBinding {
|
|
|
21
21
|
type: 'repo' | 'group' | 'group_repo';
|
|
22
22
|
refId: string;
|
|
23
23
|
position: number;
|
|
24
|
-
note: string;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export interface SyncRefIndexInput {
|
|
@@ -43,8 +42,7 @@ export function desiredBindings(s: any): DesiredBinding[] {
|
|
|
43
42
|
groupKey: string | null,
|
|
44
43
|
type: DesiredBinding['type'],
|
|
45
44
|
raw: any,
|
|
46
|
-
position: number
|
|
47
|
-
note = ''
|
|
45
|
+
position: number
|
|
48
46
|
): void => {
|
|
49
47
|
const refId = String((raw && raw.ref) || '').trim();
|
|
50
48
|
if (!refId) return;
|
|
@@ -54,7 +52,6 @@ export function desiredBindings(s: any): DesiredBinding[] {
|
|
|
54
52
|
type,
|
|
55
53
|
refId,
|
|
56
54
|
position: Number(position) || 0,
|
|
57
|
-
note: String((raw && raw.note) ?? note ?? ''),
|
|
58
55
|
});
|
|
59
56
|
};
|
|
60
57
|
|
|
@@ -111,7 +108,6 @@ export async function syncRefIndex({ store: s }: SyncRefIndexInput = {}): Promis
|
|
|
111
108
|
refId: b.refId,
|
|
112
109
|
type: b.type,
|
|
113
110
|
position: b.position,
|
|
114
|
-
note: b.note,
|
|
115
111
|
});
|
|
116
112
|
markRefBound(conn, b.refId);
|
|
117
113
|
n += 1;
|
package/src/modules/docs/refs.ts
CHANGED
|
@@ -94,6 +94,81 @@ export async function setDocRef({ repo, board, ref, path, reset }: SetDocRefInpu
|
|
|
94
94
|
return res;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** setDocMain 的入参:宿主(repo / board 二选一)+ 目标文档(ref / path)。 */
|
|
98
|
+
export interface SetDocMainInput {
|
|
99
|
+
repo?: unknown;
|
|
100
|
+
board?: unknown;
|
|
101
|
+
ref?: unknown;
|
|
102
|
+
path?: unknown;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 把某一篇设成宿主的**主篇**(#144)。
|
|
107
|
+
*
|
|
108
|
+
* 与 `docs bind` 的差别(用户视角正是这一点):这是**换位**,不是覆盖——
|
|
109
|
+
* · 目标那篇如果已经在附加篇(docLinks)里,先把它摘出来,避免同一篇出现两次;
|
|
110
|
+
* · 原主篇还在、且不是目标 → 挪到 docLinks 头部,**保住它的归属**
|
|
111
|
+
* (`docs bind` 会直接把原主篇甩成孤儿,3 天后被清理);
|
|
112
|
+
* · 目标没绑在这个宿主上 → 显式报错,先加进列表(不做「顺手加一篇」的隐式行为)。
|
|
113
|
+
*
|
|
114
|
+
* 宿主 = 仓库(repo.doc/docLinks)或组(board.doc/docLinks);组内仓库描述
|
|
115
|
+
* (board.repoDocs)不在这个语义里。
|
|
116
|
+
*/
|
|
117
|
+
export async function setDocMain({ repo, board, ref, path }: SetDocMainInput = {}): Promise<any> {
|
|
118
|
+
if (!!repo === !!board) throw badInput('请给 --repo <仓库> 或 --board <看板>(二选一)');
|
|
119
|
+
const docRef = await docRefOf({ ref, path });
|
|
120
|
+
const { mutateStore, deriveKey, boardKeyOf } = await reposBridge();
|
|
121
|
+
const nk = { normalizeKey, boardKeyOf };
|
|
122
|
+
const repoKeyIn = makeRepoKeyIn({ normalizeKey, deriveKey });
|
|
123
|
+
const res = await mutateStore((s: any) => {
|
|
124
|
+
const host = repo
|
|
125
|
+
? (() => {
|
|
126
|
+
const rkey = repoKeyIn(s, repo);
|
|
127
|
+
if (!rkey) throw notFound('repo 不存在: ' + String(repo));
|
|
128
|
+
const r = s.repos.find((x: any) => deriveKey(x) === rkey);
|
|
129
|
+
if (!r) throw notFound('repo 不存在: ' + String(repo));
|
|
130
|
+
return r;
|
|
131
|
+
})()
|
|
132
|
+
: (() => {
|
|
133
|
+
const b = findBoardIn(s, board, nk);
|
|
134
|
+
if (!b) throw notFound('看板不存在: ' + String(board));
|
|
135
|
+
return b;
|
|
136
|
+
})();
|
|
137
|
+
const links: any[] = Array.isArray(host.docLinks) ? host.docLinks : [];
|
|
138
|
+
const inLinks = links.findIndex((x: any) => x && x.ref === docRef.ref);
|
|
139
|
+
const isMain = !!(host.doc && host.doc.ref === docRef.ref);
|
|
140
|
+
if (isMain && inLinks < 0) {
|
|
141
|
+
return { changed: false, alreadyMain: true, name: host.name, key: deriveKey(host), ref: docRef.ref };
|
|
142
|
+
}
|
|
143
|
+
// 目标必须已经在这个宿主的文档列表里(主篇或附加篇)。不在这里就显式报错——
|
|
144
|
+
// 「顺手把它加成主篇」是隐式行为,会让列表凭空多一篇。
|
|
145
|
+
if (!isMain && inLinks < 0) {
|
|
146
|
+
throw conflict('这篇不在这个宿主的文档列表里:先加进去(repo doc add / docs link)再设主篇');
|
|
147
|
+
}
|
|
148
|
+
// ① 目标从附加篇里摘出来(同一篇不能既是主篇又在附加篇里)
|
|
149
|
+
if (inLinks >= 0) links.splice(inLinks, 1);
|
|
150
|
+
// ② 原主篇退回附加篇头部(保住归属;只有它还在、且不是目标时才动)
|
|
151
|
+
const prev = host.doc;
|
|
152
|
+
if (prev && prev.ref && prev.ref !== docRef.ref) links.unshift(prev);
|
|
153
|
+
// ③ 目标上位
|
|
154
|
+
host.doc = docRef;
|
|
155
|
+
if (links.length) host.docLinks = links;
|
|
156
|
+
else delete host.docLinks;
|
|
157
|
+
host.updatedAt = new Date().toISOString();
|
|
158
|
+
return {
|
|
159
|
+
changed: true,
|
|
160
|
+
alreadyMain: false,
|
|
161
|
+
name: host.name,
|
|
162
|
+
key: deriveKey(host),
|
|
163
|
+
ref: docRef.ref,
|
|
164
|
+
previous: prev && prev.ref ? prev.ref : '',
|
|
165
|
+
count: links.length + 1,
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
await syncRefIndex();
|
|
169
|
+
return res;
|
|
170
|
+
}
|
|
171
|
+
|
|
97
172
|
/** setNoteDocRef 的入参。 */
|
|
98
173
|
export interface SetNoteDocRefInput {
|
|
99
174
|
board?: string;
|
|
@@ -138,7 +213,6 @@ export interface SetDocLinkInput {
|
|
|
138
213
|
board?: string;
|
|
139
214
|
ref?: string;
|
|
140
215
|
path?: string;
|
|
141
|
-
note?: string;
|
|
142
216
|
remove?: number;
|
|
143
217
|
before?: number;
|
|
144
218
|
}
|
|
@@ -146,13 +220,12 @@ export interface SetDocLinkInput {
|
|
|
146
220
|
/**
|
|
147
221
|
* 维护组的 docLinks。
|
|
148
222
|
* --ref <refId> 或 --path <绝对路径>(外部只读)
|
|
149
|
-
* note 条目注解
|
|
150
223
|
* remove --remove <序号>(1 起)
|
|
151
224
|
* before --before <序号>(插到该条之前;缺省追加)
|
|
152
225
|
*
|
|
153
|
-
* 同 ref 重复添加 =
|
|
226
|
+
* 同 ref 重复添加 = 把该条移到新位置。
|
|
154
227
|
*/
|
|
155
|
-
export async function setDocLink({ board, ref, path,
|
|
228
|
+
export async function setDocLink({ board, ref, path, remove, before }: SetDocLinkInput = {}): Promise<any> {
|
|
156
229
|
if (!board) throw badInput('缺少看板(id / key / 名称)');
|
|
157
230
|
const { mutateStore, boardKeyOf } = await reposBridge();
|
|
158
231
|
const docRef = remove === undefined ? await docRefOf({ ref, path }) : null;
|
|
@@ -174,8 +247,8 @@ export async function setDocLink({ board, ref, path, note, remove, before }: Set
|
|
|
174
247
|
return { boardName: b.name, removed: describeLink(gone), count: b.docLinks.length };
|
|
175
248
|
}
|
|
176
249
|
|
|
177
|
-
// 条目 = DocRef
|
|
178
|
-
const entry = withLinkMeta(docRef
|
|
250
|
+
// 条目 = DocRef(去 note 后只剩 ref 本体)
|
|
251
|
+
const entry = withLinkMeta(docRef!);
|
|
179
252
|
const at = b.docLinks.findIndex((x: any) => (x && x.ref) === entry.ref);
|
|
180
253
|
if (at >= 0) b.docLinks.splice(at, 1);
|
|
181
254
|
const want = before !== undefined ? idxOf(before) : -1;
|
|
@@ -216,20 +289,19 @@ export async function listRepoDocs(locator: string): Promise<any> {
|
|
|
216
289
|
};
|
|
217
290
|
}
|
|
218
291
|
|
|
219
|
-
/** addRepoDoc 的入参(refId
|
|
292
|
+
/** addRepoDoc 的入参(refId 或外部路径)。 */
|
|
220
293
|
export interface AddRepoDocInput {
|
|
221
294
|
ref?: string;
|
|
222
295
|
path?: string;
|
|
223
|
-
note?: string;
|
|
224
296
|
}
|
|
225
297
|
|
|
226
|
-
/** 往项目的介绍文档集里加一篇(同 ref 重复添加 =
|
|
298
|
+
/** 往项目的介绍文档集里加一篇(同 ref 重复添加 = 移到末尾)。 */
|
|
227
299
|
export async function addRepoDoc(locator: string, raw: unknown): Promise<any> {
|
|
228
300
|
const { getRepo, deriveKey, mutateStore } = await reposBridge();
|
|
229
301
|
const repo = await getRepo(locator);
|
|
230
302
|
const input = (raw && typeof raw === 'object' ? raw : {}) as AddRepoDocInput;
|
|
231
303
|
const docRef = await docRefOf({ ref: input.ref, path: input.path });
|
|
232
|
-
const entry = withLinkMeta(docRef
|
|
304
|
+
const entry = withLinkMeta(docRef);
|
|
233
305
|
const res = await mutateStore((s: any) => {
|
|
234
306
|
const r = s.repos.find((x: any) => deriveKey(x) === deriveKey(repo));
|
|
235
307
|
if (!r) throw notFound('repo 不存在: ' + locator);
|
|
@@ -81,7 +81,6 @@ export interface RefBindingView {
|
|
|
81
81
|
repoKey: string;
|
|
82
82
|
groupKey: string | null;
|
|
83
83
|
position: number;
|
|
84
|
-
note: string;
|
|
85
84
|
main: boolean;
|
|
86
85
|
}
|
|
87
86
|
|
|
@@ -197,7 +196,7 @@ function bindingsOfRef(refId: string): RefBindingView[] {
|
|
|
197
196
|
if (!clean(refId)) return [];
|
|
198
197
|
return getDb()
|
|
199
198
|
.all(
|
|
200
|
-
`SELECT type, repo_key AS repoKey, group_key AS groupKey, position
|
|
199
|
+
`SELECT type, repo_key AS repoKey, group_key AS groupKey, position
|
|
201
200
|
FROM ref_bindings WHERE ref_id = :id ORDER BY type, position`,
|
|
202
201
|
{ id: refId }
|
|
203
202
|
)
|
|
@@ -206,7 +205,6 @@ function bindingsOfRef(refId: string): RefBindingView[] {
|
|
|
206
205
|
repoKey: String(r.repoKey),
|
|
207
206
|
groupKey: r.groupKey == null ? null : String(r.groupKey),
|
|
208
207
|
position: Number(r.position) || 0,
|
|
209
|
-
note: String(r.note || ''),
|
|
210
208
|
main: (Number(r.position) || 0) === 0,
|
|
211
209
|
}));
|
|
212
210
|
}
|