nx-kv 0.48.2 → 0.50.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 +85 -0
- package/README.md +103 -216
- package/assets/groups.json +1 -1
- package/assets/kv-get/SKILL.md +1 -1
- package/assets/kv-get/references/localget.md +2 -2
- package/assets/kv-get/references/timegoal-workflow.md +3 -3
- package/assets/kv-get/references/timegoal.md +1 -1
- package/assets/kv-get/references/wait-workflow.md +2 -3
- package/assets/kv-get/references/waitloop.md +3 -3
- package/assets/kv-repo/SKILL.md +1 -1
- package/assets/kv-submit/SKILL.md +3 -3
- package/assets/nx-kv/SKILL.md +111 -76
- package/assets/nx-kv/references/agent-workflow.md +58 -47
- package/assets/nx-kv/references/localtask-commands.md +179 -0
- package/package.json +3 -4
- package/src/core/attachmentdb/bodies.ts +193 -0
- package/src/core/attachmentdb/docs.ts +158 -33
- package/src/core/attachmentdb/ids.ts +27 -1
- package/src/core/attachmentdb/mdfile.ts +249 -0
- package/src/core/attachmentdb/query.ts +14 -1
- package/src/core/attachmentdb/resources.ts +28 -2
- package/src/core/attachmentdb.ts +27 -0
- package/src/core/config.ts +13 -133
- package/src/core/db/bootstrap.ts +5 -5
- package/src/core/db/import-json/refs.ts +27 -13
- package/src/core/db/migrations/index.ts +9 -0
- package/src/core/db/migrations/v2-data.ts +4 -4
- package/src/core/db/migrations/v5.sql +100 -0
- package/src/core/db/migrations/v6-data.ts +261 -0
- package/src/core/db/migrations/v6.sql +67 -0
- package/src/core/db/migrations/v7.sql +8 -0
- package/src/core/db/seed-templates.ts +3 -1
- package/src/core/db/version.ts +12 -1
- package/src/core/filekind.ts +95 -0
- package/src/core/instruction-template.ts +6 -4
- package/src/core/localatt.ts +3 -6
- package/src/core/paths.ts +11 -1
- package/src/index.ts +0 -2
- package/src/modules/docs/actions/_manifest.generated.ts +18 -0
- package/src/modules/docs/actions/doc-attach.ts +2 -1
- package/src/modules/docs/actions/doc-link-file.ts +28 -0
- package/src/modules/docs/actions/doc-mdfile.ts +28 -0
- package/src/modules/docs/actions/doc-mdfiles.ts +29 -0
- package/src/modules/docs/actions/doc-ref.ts +36 -0
- package/src/modules/docs/actions/doc-unbind.ts +34 -0
- package/src/modules/docs/actions/doc-update.ts +3 -2
- package/src/modules/docs/actions/docs-bind.ts +1 -1
- package/src/modules/docs/actions/docs-bindings.ts +108 -0
- package/src/modules/docs/actions/docs-notebind.ts +1 -1
- package/src/modules/docs/attach.ts +16 -3
- package/src/modules/docs/bound-docs.ts +74 -0
- package/src/modules/docs/docref.ts +18 -3
- package/src/modules/docs/knowledge-md.ts +51 -0
- package/src/modules/docs/knowledge.ts +112 -112
- package/src/modules/docs/links.ts +7 -1
- package/src/modules/docs/mdfile.ts +24 -0
- package/src/modules/docs/paths.ts +6 -9
- package/src/modules/docs/ref-sync.ts +166 -0
- package/src/modules/docs/refs.ts +16 -5
- package/src/modules/docs/render.ts +33 -15
- package/src/modules/docs/seed.ts +1 -1
- package/src/modules/docs/service.ts +300 -30
- package/src/modules/docs/store.ts +147 -74
- package/src/modules/file/actions/_manifest.generated.ts +0 -9
- package/src/modules/file/actions/file-content.ts +3 -4
- package/src/modules/file/actions/file-get.ts +2 -3
- package/src/modules/file/actions/file-upload.ts +1 -4
- package/src/modules/file/service.ts +52 -253
- package/src/modules/localtask/action-render.ts +5 -5
- package/src/modules/localtask/actions/_manifest.generated.ts +0 -6
- package/src/modules/localtask/actions/localtask-attach.ts +4 -2
- package/src/modules/localtask/actions/localtask-cancelMany.ts +1 -1
- package/src/modules/localtask/actions/localtask-closeMany.ts +4 -3
- package/src/modules/localtask/actions/localtask-get.ts +1 -1
- package/src/modules/localtask/repo/tasks.ts +12 -6
- package/src/modules/localtask/service.ts +0 -2
- package/src/modules/localtask/task-ops.ts +4 -4
- package/src/modules/localtask/task-remove.ts +33 -16
- package/src/modules/localtask/task-templates.ts +2 -3
- package/src/modules/localtask/task-view.ts +2 -2
- package/src/modules/repos/actions/_manifest.generated.ts +0 -3
- package/src/modules/repos/actions/repo-update.ts +2 -4
- package/src/modules/repos/cli/render.ts +0 -15
- package/src/modules/repos/service/bind-topics.ts +8 -18
- package/src/modules/repos/service.ts +1 -1
- package/src/modules/repos/transfer/export.ts +4 -1
- package/src/modules/setting/actions/setting-set.ts +0 -2
- package/src/modules/setting/service.ts +6 -25
- package/src/modules/system/actions/bootstrap.ts +2 -31
- package/src/modules/system/actions/health.ts +4 -31
- package/src/modules/system/routes.ts +1 -1
- package/src/modules/tasktool/attach-resource.ts +68 -42
- package/src/modules/tasktool/attach-template.ts +73 -54
- package/src/modules/tasktool/attach.ts +98 -71
- package/src/modules/tasktool/delivery-template.ts +14 -4
- package/src/modules/tasktool/doc-inline.ts +63 -29
- package/src/modules/tasktool/get.ts +1 -1
- package/src/modules/tasktool/groupctx.ts +19 -11
- package/src/modules/tasktool/plugins/waitgoal-config.ts +24 -55
- package/src/modules/tasktool/plugins/waitgoal.ts +0 -2
- package/src/modules/tasktool/preview.ts +2 -3
- package/src/modules/tasktool/wait.ts +6 -9
- package/src/runtime/cli.ts +3 -15
- package/src/runtime/container.ts +1 -5
- package/src/runtime/help.ts +1 -4
- package/src/runtime/registry.ts +0 -6
- package/src/shared/prompt-blocks.ts +37 -33
- package/src/shared/task-status.ts +3 -3
- package/src/web/frontend/App.tsx +3 -3
- package/src/web/frontend/api/cli-tree.json +115 -608
- package/src/web/frontend/api/client.generated.ts +88 -401
- package/src/web/frontend/components/Introduction/index.tsx +26 -14
- package/src/web/frontend/components/Introduction/rail.tsx +28 -3
- package/src/web/frontend/components/Introduction/style.css +3 -33
- package/src/web/frontend/components/Introduction/use-intro.ts +0 -80
- package/src/web/frontend/components/{cloud → attach}/upload.ts +7 -20
- package/src/web/frontend/components/bindings/bind-tags.tsx +183 -0
- package/src/web/frontend/components/doc/doc-head.tsx +29 -26
- package/src/web/frontend/components/icons.tsx +0 -1
- package/src/web/frontend/components/layout/crumbs.ts +0 -2
- package/src/web/frontend/components/md/ack-rail.tsx +10 -142
- package/src/web/frontend/components/md/attach-area.tsx +64 -9
- package/src/web/frontend/components/md/attach-common.ts +8 -3
- package/src/web/frontend/components/md/attach-modal.tsx +22 -17
- package/src/web/frontend/components/md/attach-picker.tsx +2 -2
- package/src/web/frontend/components/md/attachments.ts +2 -3
- package/src/web/frontend/components/popup/dismiss.ts +1 -1
- package/src/web/frontend/components/repos/get-loop-modal.tsx +20 -207
- package/src/web/frontend/components/sidebar/index.tsx +32 -6
- package/src/web/frontend/components/sidebar/model.ts +71 -0
- package/src/web/frontend/components/sidebar/task-children.tsx +41 -20
- package/src/web/frontend/components/status-tag/model.ts +1 -1
- package/src/web/frontend/components/task-panel/index.tsx +4 -1
- package/src/web/frontend/components/task-panel/task-row.tsx +2 -2
- package/src/web/frontend/components/tool-acts/modules.ts +0 -3
- package/src/web/frontend/components/use-rail-drag.ts +177 -0
- package/src/web/frontend/modules/board/ack-rail-pos.ts +17 -7
- package/src/web/frontend/modules/board/board-view.ts +2 -2
- package/src/web/frontend/modules/board/task-search.ts +81 -0
- package/src/web/frontend/modules/md/attach-mention.ts +6 -1
- package/src/web/frontend/modules/md/doc-bus.ts +22 -0
- package/src/web/frontend/modules/md/md-render.ts +9 -2
- package/src/web/frontend/modules/md/styles/chrome.css +25 -0
- package/src/web/frontend/modules/md/styles/docs.css +32 -21
- package/src/web/frontend/modules/md/styles/shell.css +1 -10
- package/src/web/frontend/page/dir/api.ts +7 -0
- package/src/web/frontend/page/dir/index.tsx +24 -58
- package/src/web/frontend/page/dir/landing.tsx +85 -72
- package/src/web/frontend/page/dir/task-actions.ts +17 -5
- package/src/web/frontend/page/dir/task-dock-panel.tsx +87 -2
- package/src/web/frontend/page/dir/task-dock.ts +21 -10
- package/src/web/frontend/page/dir/task-goal.ts +2 -2
- package/src/web/frontend/page/dir/task-status-bar.tsx +14 -1
- package/src/web/frontend/page/dir/task.tsx +5 -3
- package/src/web/frontend/page/doc/api.ts +71 -5
- package/src/web/frontend/page/doc/bindings.tsx +240 -0
- package/src/web/frontend/page/doc/doc-dock.tsx +159 -0
- package/src/web/frontend/page/doc/index.tsx +131 -212
- package/src/web/frontend/page/doc/use-wiki-nav.ts +101 -0
- package/src/web/frontend/page/group/index.tsx +61 -87
- package/src/web/frontend/page/overview/index.tsx +1 -2
- package/src/web/frontend/page/refs/api.ts +60 -8
- package/src/web/frontend/page/refs/index.tsx +177 -90
- package/src/web/frontend/page/refs/style.css +45 -2
- package/src/web/frontend/page/repos/doc-search-modal.tsx +7 -0
- package/src/web/frontend/page/repos/index.tsx +21 -60
- package/src/web/frontend/page/repos/repo-table.tsx +85 -77
- package/src/web/frontend/page/settings/index.tsx +3 -27
- package/src/web/frontend/page/settings/prompt-template-params.ts +18 -28
- package/src/web/frontend/panels.tsx +52 -6
- package/src/web/frontend/registry.ts +1 -2
- package/src/web/frontend/routes/index.ts +1 -2
- package/src/web/frontend/routes/static.ts +2 -3
- package/src/web/frontend/store.tsx +1 -8
- package/src/web/frontend/style.css +1 -0
- package/src/web/frontend/styles/base.css +0 -17
- package/src/web/frontend/styles/bindings.css +75 -0
- package/src/web/frontend/styles/buttons-cards.css +0 -72
- package/src/web/frontend/styles/repos-admin.css +7 -5
- package/src/web/frontend/styles-v2/dir.css +1 -9
- package/src/web/frontend/styles-v2/shell.css +0 -2
- package/src/web/frontend/styles-v2/sidebar.css +12 -0
- package/src/web/frontend/styles-v2/views.css +22 -102
- package/src/web/frontend/workspace/areas.ts +0 -2
- package/src/web/public/assets/Introduction-CohW6Xit.js +6 -0
- package/src/web/public/assets/Introduction-Iuxssa-b.css +1 -0
- package/src/web/public/assets/app-context-BgpTewyA.js +1 -0
- package/src/web/public/assets/{bar-B52NTf_v.js → bar-C2mfoqmj.js} +1 -1
- package/src/web/public/assets/{board-view-DABoVkaA.js → board-view-aAIEbSQi.js} +1 -1
- package/src/web/public/assets/button-xyR2UROd.js +1 -0
- package/src/web/public/assets/composer-launch-eTktHT_f.js +1 -0
- package/src/web/public/assets/{composer-panel-DpiU2h50.js → composer-panel-C0OOIXxz.js} +1 -1
- package/src/web/public/assets/dag-Gm4RcvEg.js +1 -0
- package/src/web/public/assets/dir-PjuMRbWo.js +3 -0
- package/src/web/public/assets/group-D94y_Lq6.js +1 -0
- package/src/web/public/assets/index-CBJKsJU3.css +1 -0
- package/src/web/public/assets/index-Crxdmsux.js +2 -0
- package/src/web/public/assets/md-history-CU_1I6ht.js +39 -0
- package/src/web/public/assets/{md-parse-b6GY5eBl.js → md-parse-CLyUaUto.js} +1 -1
- package/src/web/public/assets/{member-picker-B5I7KuOR.js → member-picker-XT12VRe6.js} +1 -1
- package/src/web/public/assets/model-CWJ8_2dN.js +2 -0
- package/src/web/public/assets/{overview-B3kHI66i.js → overview-BQm8BLCG.js} +1 -1
- package/src/web/public/assets/{progress-CdhFz0Lz.js → progress-CNam3Wuj.js} +2 -2
- package/src/web/public/assets/refs-C5idWnUj.css +1 -0
- package/src/web/public/assets/refs-ClETk1cj.js +2 -0
- package/src/web/public/assets/repos-BioGejZo.js +14 -0
- package/src/web/public/assets/route-crumb-Fc68LcQ4.js +1 -0
- package/src/web/public/assets/settings-BIzumXLD.js +8 -0
- package/src/web/public/assets/status-tag-CBFf_-ae.js +1 -0
- package/src/web/public/assets/task-CGmO3I2y.js +11 -0
- package/src/web/public/assets/task-row-DRBa11tf.js +1 -0
- package/src/web/public/assets/{task-status-DSrx0i66.js → task-status-BHF-y9Aq.js} +2 -1
- package/src/web/public/assets/{task-utils-_JAWRAz6.js → task-utils-DjODjVdc.js} +2 -2
- package/src/web/public/assets/{templates-CbRyW3PJ.js → templates-j8EzXHXf.js} +1 -1
- package/src/web/public/assets/ui-Y0aL-bGk.js +1 -0
- package/src/web/public/assets/use-rail-drag-DNfz4Gcx.js +1 -0
- package/src/web/public/assets/{workspace-4tw7trV7.js → workspace-D_G-B3TX.js} +4 -4
- package/src/web/public/index.html +9 -9
- package/assets/nx-kv/references/todo-commands.md +0 -269
- package/src/core/attachstore.ts +0 -360
- package/src/core/fileapi.ts +0 -267
- package/src/core/kvapi.ts +0 -237
- package/src/modules/auth/actions/_manifest.generated.ts +0 -26
- package/src/modules/auth/actions/auth-login.ts +0 -31
- package/src/modules/auth/actions/auth-logout.ts +0 -33
- package/src/modules/auth/actions/auth-me.ts +0 -33
- package/src/modules/auth/actions/auth-status.ts +0 -41
- package/src/modules/auth/index.ts +0 -24
- package/src/modules/auth/support.ts +0 -28
- package/src/modules/file/actions/file-list.ts +0 -31
- package/src/modules/file/actions/file-remove.ts +0 -31
- package/src/modules/file/actions/file-sync.ts +0 -33
- package/src/modules/localtask/actions/localtask-importRemote.ts +0 -51
- package/src/modules/localtask/actions/task-move.ts +0 -67
- package/src/modules/localtask/move-prims.ts +0 -170
- package/src/modules/localtask/move.ts +0 -174
- package/src/modules/localtask/remote-import.ts +0 -159
- package/src/modules/repos/actions/repo-ref-backfill.ts +0 -33
- package/src/modules/repos/ref-backfill.ts +0 -219
- package/src/modules/todo/actions/_manifest.generated.ts +0 -89
- package/src/modules/todo/actions/group-add.ts +0 -34
- package/src/modules/todo/actions/group-current.ts +0 -36
- package/src/modules/todo/actions/group-get.ts +0 -43
- package/src/modules/todo/actions/group-list.ts +0 -41
- package/src/modules/todo/actions/group-members.ts +0 -41
- package/src/modules/todo/actions/group-remove.ts +0 -44
- package/src/modules/todo/actions/group-update.ts +0 -37
- package/src/modules/todo/actions/group-use.ts +0 -43
- package/src/modules/todo/actions/prompt-get.ts +0 -31
- package/src/modules/todo/actions/prompt-remove.ts +0 -31
- package/src/modules/todo/actions/prompt-set.ts +0 -32
- package/src/modules/todo/actions/todo-add.ts +0 -34
- package/src/modules/todo/actions/todo-archive.ts +0 -33
- package/src/modules/todo/actions/todo-attach.ts +0 -37
- package/src/modules/todo/actions/todo-attachments.ts +0 -33
- package/src/modules/todo/actions/todo-done.ts +0 -33
- package/src/modules/todo/actions/todo-freeze.ts +0 -32
- package/src/modules/todo/actions/todo-get.ts +0 -33
- package/src/modules/todo/actions/todo-list.ts +0 -32
- package/src/modules/todo/actions/todo-remove.ts +0 -32
- package/src/modules/todo/actions/todo-unfreeze.ts +0 -34
- package/src/modules/todo/actions/todo-update.ts +0 -42
- package/src/modules/todo/actions/topic-add.ts +0 -31
- package/src/modules/todo/actions/topic-list.ts +0 -35
- package/src/modules/todo/actions/topic-remove.ts +0 -36
- package/src/modules/todo/attachments.ts +0 -194
- package/src/modules/todo/group.ts +0 -207
- package/src/modules/todo/index.ts +0 -26
- package/src/modules/todo/locate.ts +0 -103
- package/src/modules/todo/service.ts +0 -476
- package/src/modules/todo/store.ts +0 -176
- package/src/modules/todo/support.ts +0 -93
- package/src/web/frontend/components/Introduction/docs-modal.tsx +0 -338
- package/src/web/frontend/components/cloud/editor.tsx +0 -254
- package/src/web/frontend/components/cloud/group-popup.tsx +0 -198
- package/src/web/frontend/components/cloud/markdown.tsx +0 -60
- package/src/web/frontend/components/migrate/dialog.tsx +0 -120
- package/src/web/frontend/components/migrate/undo.tsx +0 -73
- package/src/web/frontend/components/migrate/use-move.ts +0 -137
- package/src/web/frontend/page/cloud/api.ts +0 -99
- package/src/web/frontend/page/cloud/index.tsx +0 -516
- package/src/web/frontend/page/dir/deleted-panel.tsx +0 -77
- package/src/web/public/assets/Introduction-BcPrmROW.css +0 -1
- package/src/web/public/assets/Introduction-Du_dycft.js +0 -6
- package/src/web/public/assets/app-context-BASCGAA-.js +0 -1
- package/src/web/public/assets/cloud-Droja_aT.js +0 -3
- package/src/web/public/assets/composer-launch-mK9Nr6mZ.js +0 -1
- package/src/web/public/assets/dag-Ca-wjIxQ.js +0 -1
- package/src/web/public/assets/deleted-panel-K9GgfR8t.js +0 -1
- package/src/web/public/assets/dir-DacRpcBt.js +0 -5
- package/src/web/public/assets/frontmatter-CLLxCmTv.js +0 -2
- package/src/web/public/assets/group-TPuU-QVc.js +0 -2
- package/src/web/public/assets/index-BkLkooKe.js +0 -2
- package/src/web/public/assets/index-DP3qBv1o.css +0 -1
- package/src/web/public/assets/md-history-0GBWw4qr.js +0 -39
- package/src/web/public/assets/model-Bn2fG6CC.js +0 -2
- package/src/web/public/assets/prompt-blocks-BovFd039.js +0 -8
- package/src/web/public/assets/refs-BDxfuH6R.js +0 -1
- package/src/web/public/assets/refs-CY4i7PoC.css +0 -1
- package/src/web/public/assets/repos-C8jRM7wS.js +0 -15
- package/src/web/public/assets/repos-ZPiaK93i.css +0 -1
- package/src/web/public/assets/route-crumb-QvahotvN.js +0 -1
- package/src/web/public/assets/settings-BBcdGLTc.js +0 -1
- package/src/web/public/assets/status-tag-BheHByek.js +0 -1
- package/src/web/public/assets/task-CUkQaLBZ.js +0 -11
- package/src/web/public/assets/tool-bar-BAmT-BI-.js +0 -1
- package/src/web/public/assets/upload-BcMhRsMn.js +0 -1
- /package/src/web/public/assets/{prompt-blocks-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
- /package/src/web/public/assets/{tool-bar-1h2zairf.css → use-rail-drag-1h2zairf.css} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// 文档绑定 → refs / ref_bindings 的**整表重建**(#183)。
|
|
2
|
+
//
|
|
3
|
+
// 背景:文档的「归谁」有两层——
|
|
4
|
+
// · ext 里的 DocRef(`repo.doc` / `repo.docLinks` / `board.doc` / `board.docLinks`
|
|
5
|
+
// / `board.repoDocs`):宿主身上挂了哪些篇,docs 域读写的就是它;
|
|
6
|
+
// · 库里的 refs / ref_bindings:**索引层**,供孤儿清单、附件归属、检索用。
|
|
7
|
+
//
|
|
8
|
+
// 两层此前只在上层(ext)同步,索引层只有 bind-topics 与导入器写过一次,
|
|
9
|
+
// 于是「面板上明明挂着文档,库里一行绑定都没有、state 全是 orphan」——同一份
|
|
10
|
+
// 文档在仓库、组、组内三处各挂一遍时更是理不清。
|
|
11
|
+
//
|
|
12
|
+
// 本文件是索引层的**唯一写入方**:按 ext + 约定路径算出完整绑定集合,
|
|
13
|
+
// 一个事务内整表重写(幂等)。孤儿状态在收尾时按「有无绑定」重算。
|
|
14
|
+
import { getDb } from '../../core/db/index.js';
|
|
15
|
+
import { tx } from '../../core/db/tx.js';
|
|
16
|
+
import {
|
|
17
|
+
clearRefBindings,
|
|
18
|
+
ensureDocRef,
|
|
19
|
+
markRefBound,
|
|
20
|
+
markUnboundRefsOrphan,
|
|
21
|
+
putRefBinding,
|
|
22
|
+
} from '../../core/attachmentdb.js';
|
|
23
|
+
import * as paths from './paths.js';
|
|
24
|
+
import * as store from './store.js';
|
|
25
|
+
import { reposBridge } from './repos-bridge.js';
|
|
26
|
+
|
|
27
|
+
/** 一条待写入的绑定(locator 由 DocRef 归一:自有给 rel,外部给绝对路径)。 */
|
|
28
|
+
interface DesiredBinding {
|
|
29
|
+
repoKey: string;
|
|
30
|
+
groupKey: string | null;
|
|
31
|
+
type: 'repo' | 'group' | 'group_repo';
|
|
32
|
+
locator: string;
|
|
33
|
+
position: number;
|
|
34
|
+
note: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** syncRefIndex 的入参:调用方已有扫描结果时直接传,避免重复走盘。 */
|
|
38
|
+
export interface SyncRefIndexInput {
|
|
39
|
+
/** docs 树里的 rel 列表(listOwnDocs 的 rel) */
|
|
40
|
+
files?: string[];
|
|
41
|
+
/** repos store(loadStore 的结果) */
|
|
42
|
+
store?: any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SyncRefIndexResult {
|
|
46
|
+
bindings: number;
|
|
47
|
+
/** 收尾时被打回 orphan 的 ref 数 */
|
|
48
|
+
orphaned: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const locatorOf = (ref: any): string => {
|
|
52
|
+
if (!ref || typeof ref !== 'object') return '';
|
|
53
|
+
const rel = String(ref.rel || '').trim();
|
|
54
|
+
if (rel) return rel.replace(/\\/g, '/');
|
|
55
|
+
const abs = String(ref.path || '').trim();
|
|
56
|
+
return abs ? abs.replace(/\\/g, '/') : '';
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** 约定路径二选一:目录主篇优先,旧单文件回落;都不在盘上 → 空(不绑不存在的文件)。 */
|
|
60
|
+
function pickExisting(candidates: string[], fileSet: Set<string>): string {
|
|
61
|
+
for (const rel of candidates) if (fileSet.has(rel)) return rel;
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 从 store 算出完整绑定集合(纯函数;顺序 = 主篇 → docLinks → 组内描述)。 */
|
|
66
|
+
export function desiredBindings(s: any, files: string[]): DesiredBinding[] {
|
|
67
|
+
const fileSet = new Set((files || []).map((f) => String(f).replace(/\\/g, '/')));
|
|
68
|
+
const out: DesiredBinding[] = [];
|
|
69
|
+
const push = (
|
|
70
|
+
repoKey: string,
|
|
71
|
+
groupKey: string | null,
|
|
72
|
+
type: DesiredBinding['type'],
|
|
73
|
+
ref: any,
|
|
74
|
+
position: number,
|
|
75
|
+
note = ''
|
|
76
|
+
): void => {
|
|
77
|
+
const locator = locatorOf(ref);
|
|
78
|
+
if (!locator) return;
|
|
79
|
+
out.push({ repoKey, groupKey, type, locator, position: Number(position) || 0, note: String(note || '') });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// ── 仓库:主篇 + 介绍文档集 ──
|
|
83
|
+
for (const r of s.repos || []) {
|
|
84
|
+
const key = String(r.key || '');
|
|
85
|
+
if (!key || r.type === 'group') continue;
|
|
86
|
+
if (r.doc) push(key, null, 'repo', r.doc, 0);
|
|
87
|
+
else {
|
|
88
|
+
const main = pickExisting([paths.docMainRel(paths.repoDocDirRel(key)), paths.repoDocRel(key)], fileSet);
|
|
89
|
+
if (main) push(key, null, 'repo', { rel: main }, 0);
|
|
90
|
+
}
|
|
91
|
+
(Array.isArray(r.docLinks) ? r.docLinks : []).forEach((l: any, i: number) => {
|
|
92
|
+
push(key, null, 'repo', l, i + 1, l && l.note);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ── 组:组介绍 + 组级文档 + 组内成员描述(type=group_repo)──
|
|
97
|
+
for (const b of s.boards || []) {
|
|
98
|
+
const gk = String(b.key || ('board/' + paths.boardSeg(b.name)) || '');
|
|
99
|
+
if (!gk) continue;
|
|
100
|
+
if (b.doc) push(gk, null, 'group', b.doc, 0);
|
|
101
|
+
else {
|
|
102
|
+
const main = pickExisting([paths.docMainRel(paths.boardDocDirRel(b.name)), paths.boardDocRel(b.name)], fileSet);
|
|
103
|
+
if (main) push(gk, null, 'group', { rel: main }, 0);
|
|
104
|
+
}
|
|
105
|
+
(Array.isArray(b.docLinks) ? b.docLinks : []).forEach((l: any, i: number) => {
|
|
106
|
+
push(gk, null, 'group', l, i + 1, l && l.note);
|
|
107
|
+
});
|
|
108
|
+
for (const [repoKey, ref] of Object.entries(b.repoDocs || {})) {
|
|
109
|
+
push(String(repoKey), gk, 'group_repo', ref, 0, (ref as any) && (ref as any).note);
|
|
110
|
+
}
|
|
111
|
+
// 组内成员描述:ext 没显式登记 repoDocs 时按**约定路径**回落——
|
|
112
|
+
// 与 boards/core.ts 的 noteDocRel、迁移导入器 import-json/refs.ts 同一口径。
|
|
113
|
+
// 漏了这一步,整表重建会把「盘上有、只是按约定放置」的组内说明清成孤儿
|
|
114
|
+
// (v6 后首次 buildIndex 就踩到:19 条 group_repo 全丢,正文还在 ref_bodies 里)。
|
|
115
|
+
for (const rawKey of Array.isArray(b.repoKeys) ? b.repoKeys : []) {
|
|
116
|
+
const rk = String(rawKey || '');
|
|
117
|
+
if (!rk || (b.repoDocs && b.repoDocs[rk])) continue;
|
|
118
|
+
const rel = pickExisting(
|
|
119
|
+
[paths.docMainRel(paths.groupNoteDirRel(b.name, rk)), paths.groupNoteRel(b.name, rk)],
|
|
120
|
+
fileSet
|
|
121
|
+
);
|
|
122
|
+
if (rel) push(rk, gk, 'group_repo', { rel }, 0);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 整表重建绑定索引(幂等)。调用点:
|
|
130
|
+
* · 绑定写动作之后(docs/refs 的 setDocRef / setNoteDocRef / setDocLink / addRepoDoc / removeRepoDoc)
|
|
131
|
+
* · 文档落盘/删除之后(docs/service 的 add / update / remove)
|
|
132
|
+
* · 双链索引刷新时(links.buildIndex —— 顺手把「上传就有但没登记」的本地 md 补进库)
|
|
133
|
+
*/
|
|
134
|
+
export async function syncRefIndex({ files, store: s }: SyncRefIndexInput = {}): Promise<SyncRefIndexResult> {
|
|
135
|
+
let storeData = s;
|
|
136
|
+
if (!storeData) {
|
|
137
|
+
const { loadStore } = await reposBridge();
|
|
138
|
+
storeData = await loadStore();
|
|
139
|
+
}
|
|
140
|
+
const rels = files || (await store.listOwnDocs()).map((f) => f.rel);
|
|
141
|
+
const wanted = desiredBindings(storeData, rels);
|
|
142
|
+
|
|
143
|
+
const db = getDb();
|
|
144
|
+
return tx(
|
|
145
|
+
(conn: any) => {
|
|
146
|
+
clearRefBindings(conn);
|
|
147
|
+
let n = 0;
|
|
148
|
+
for (const b of wanted) {
|
|
149
|
+
const refId = ensureDocRef(conn, { locator: b.locator });
|
|
150
|
+
if (!refId) continue;
|
|
151
|
+
putRefBinding(conn, {
|
|
152
|
+
repoKey: b.repoKey,
|
|
153
|
+
groupKey: b.groupKey,
|
|
154
|
+
refId,
|
|
155
|
+
type: b.type,
|
|
156
|
+
position: b.position,
|
|
157
|
+
note: b.note,
|
|
158
|
+
});
|
|
159
|
+
markRefBound(conn, refId);
|
|
160
|
+
n += 1;
|
|
161
|
+
}
|
|
162
|
+
return { bindings: n, orphaned: markUnboundRefsOrphan(conn) };
|
|
163
|
+
},
|
|
164
|
+
{ db, mode: 'IMMEDIATE' }
|
|
165
|
+
);
|
|
166
|
+
}
|
package/src/modules/docs/refs.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { badInput, notFound, conflict } from '../../core/errors.js';
|
|
|
13
13
|
import { withLinkMeta } from './docref.js';
|
|
14
14
|
import type { DocRef } from './docref.js';
|
|
15
15
|
import { readIntroSet } from './knowledge.js';
|
|
16
|
+
import { syncRefIndex } from './ref-sync.js';
|
|
16
17
|
|
|
17
18
|
// 看板定位(id / key / 名称):boardKeyOf 由 bridge 注入(key 口径必须与 repos 完全一致)
|
|
18
19
|
function findBoardIn(s: any, idOrKey: unknown, { normalizeKey: nk, boardKeyOf }: { normalizeKey: (k: unknown) => string; boardKeyOf: (v: any) => any }): any {
|
|
@@ -58,7 +59,7 @@ export async function setDocRef({ repo, board, rel, path, reset }: SetDocRefInpu
|
|
|
58
59
|
const { mutateStore, deriveKey, boardKeyOf } = await reposBridge();
|
|
59
60
|
const repoKeyIn = makeRepoKeyIn({ normalizeKey, deriveKey });
|
|
60
61
|
const nk = { normalizeKey, boardKeyOf };
|
|
61
|
-
|
|
62
|
+
const res = await mutateStore((s: any) => {
|
|
62
63
|
if (repo) {
|
|
63
64
|
const rkey = repoKeyIn(s, repo);
|
|
64
65
|
if (!rkey) throw notFound('repo 不存在: ' + repo);
|
|
@@ -73,6 +74,8 @@ export async function setDocRef({ repo, board, rel, path, reset }: SetDocRefInpu
|
|
|
73
74
|
else delete b.doc;
|
|
74
75
|
return { kind: 'board', key: boardKeyOf(b.name), name: b.name, ref: b.doc || null };
|
|
75
76
|
});
|
|
77
|
+
await syncRefIndex();
|
|
78
|
+
return res;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
/** setNoteDocRef 的入参。 */
|
|
@@ -96,7 +99,7 @@ export async function setNoteDocRef({ board, repo, rel, path, reset }: SetNoteDo
|
|
|
96
99
|
const { mutateStore, deriveKey, boardKeyOf, boardRepoKeys } = await reposBridge();
|
|
97
100
|
const repoKeyIn = makeRepoKeyIn({ normalizeKey, deriveKey });
|
|
98
101
|
const nk = { normalizeKey, boardKeyOf };
|
|
99
|
-
|
|
102
|
+
const res = await mutateStore((s: any) => {
|
|
100
103
|
const b = findBoardIn(s, board, nk);
|
|
101
104
|
if (!b) throw notFound('看板不存在: ' + board);
|
|
102
105
|
const rkey = repoKeyIn(s, locator) || normalizeKey(locator);
|
|
@@ -108,6 +111,8 @@ export async function setNoteDocRef({ board, repo, rel, path, reset }: SetNoteDo
|
|
|
108
111
|
else delete b.repoDocs[rkey];
|
|
109
112
|
return { board: b.id, boardName: b.name, boardKey: boardKeyOf(b.name), repoKey: rkey, ref: b.repoDocs[rkey] || null };
|
|
110
113
|
});
|
|
114
|
+
await syncRefIndex();
|
|
115
|
+
return res;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
// ─── 组级附加文档(有序列表,自有 rel 与外部 path 混排)────────────────
|
|
@@ -135,7 +140,7 @@ export interface SetDocLinkInput {
|
|
|
135
140
|
export async function setDocLink({ board, doc, note, tag, remove, before }: SetDocLinkInput = {}): Promise<any> {
|
|
136
141
|
if (!board) throw badInput('缺少看板(id / key / 名称)');
|
|
137
142
|
const { mutateStore, boardKeyOf } = await reposBridge();
|
|
138
|
-
|
|
143
|
+
const res = await mutateStore((s: any) => {
|
|
139
144
|
const b = findBoardIn(s, board, { normalizeKey, boardKeyOf });
|
|
140
145
|
if (!b) throw notFound('看板不存在: ' + board);
|
|
141
146
|
if (!Array.isArray(b.docLinks)) b.docLinks = [];
|
|
@@ -167,6 +172,8 @@ export async function setDocLink({ board, doc, note, tag, remove, before }: SetD
|
|
|
167
172
|
else b.docLinks.push(entry);
|
|
168
173
|
return { boardName: b.name, links: b.docLinks.slice(), count: b.docLinks.length };
|
|
169
174
|
});
|
|
175
|
+
await syncRefIndex();
|
|
176
|
+
return res;
|
|
170
177
|
}
|
|
171
178
|
|
|
172
179
|
function describeLink(l: any): string {
|
|
@@ -239,7 +246,7 @@ export async function addRepoDoc(locator: string, raw: unknown): Promise<any> {
|
|
|
239
246
|
const docRef = paths.assertDocRef(raw);
|
|
240
247
|
const rawMeta = (raw && typeof raw === 'object' ? raw : {}) as { note?: unknown; tag?: unknown };
|
|
241
248
|
const entry = withLinkMeta(docRef, { note: rawMeta.note, tag: rawMeta.tag });
|
|
242
|
-
|
|
249
|
+
const res = await mutateStore((s: any) => {
|
|
243
250
|
const r = s.repos.find((x: any) => deriveKey(x) === deriveKey(repo));
|
|
244
251
|
if (!r) throw notFound('repo 不存在: ' + locator);
|
|
245
252
|
if (!Array.isArray(r.docLinks)) r.docLinks = [];
|
|
@@ -249,6 +256,8 @@ export async function addRepoDoc(locator: string, raw: unknown): Promise<any> {
|
|
|
249
256
|
r.updatedAt = new Date().toISOString();
|
|
250
257
|
return { key: deriveKey(r), name: r.name, added: entry, count: r.docLinks.length };
|
|
251
258
|
});
|
|
259
|
+
await syncRefIndex();
|
|
260
|
+
return res;
|
|
252
261
|
}
|
|
253
262
|
|
|
254
263
|
/** 从项目的介绍文档集里摘掉一篇(--index 从 1 起;1 = 主篇) */
|
|
@@ -257,7 +266,7 @@ export async function removeRepoDoc(locator: string, index: unknown): Promise<an
|
|
|
257
266
|
const repo = await getRepo(locator);
|
|
258
267
|
const n = Number(index);
|
|
259
268
|
if (!Number.isInteger(n) || n < 1) throw badInput('缺少参数 --index <序号>(1 = 主篇,其后依次)');
|
|
260
|
-
|
|
269
|
+
const res = await mutateStore((s: any) => {
|
|
261
270
|
const r = s.repos.find((x: any) => deriveKey(x) === deriveKey(repo));
|
|
262
271
|
if (!r) throw notFound('repo 不存在: ' + locator);
|
|
263
272
|
if (n === 1) {
|
|
@@ -272,4 +281,6 @@ export async function removeRepoDoc(locator: string, index: unknown): Promise<an
|
|
|
272
281
|
r.updatedAt = new Date().toISOString();
|
|
273
282
|
return { key: deriveKey(r), name: r.name, removed: gone };
|
|
274
283
|
});
|
|
284
|
+
await syncRefIndex();
|
|
285
|
+
return res;
|
|
275
286
|
}
|
|
@@ -2,36 +2,53 @@
|
|
|
2
2
|
// 全是纯函数 —— 输入 action 的结构化结果,输出给人看的文本。
|
|
3
3
|
// 入参是 action 产出的结构化结果(外部 JSON 形状),按 any 处理。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return `${addr}${head}${extra}`;
|
|
11
|
-
}
|
|
5
|
+
const KIND_NOTE: Record<string, string> = {
|
|
6
|
+
legacy: '历史空壳',
|
|
7
|
+
external: '外部文件镜像',
|
|
8
|
+
empty: '正文缺失',
|
|
9
|
+
};
|
|
12
10
|
|
|
13
11
|
export const renderList = (d: any): string => {
|
|
14
|
-
const
|
|
15
|
-
|
|
12
|
+
const withBody = (d.docs || []).filter((x: any) => x.hasBody).length;
|
|
13
|
+
const lines = [`自有文档 ${d.count} 个(${withBody} 个有正文;正文只存库内)`];
|
|
14
|
+
for (const x of d.docs) {
|
|
15
|
+
// ref 是 DB 实体:列表以 desc(缺省标题)为主标签,地址用 refId,不展示路径
|
|
16
|
+
const label = x.desc || x.title || x.name || '未命名文档';
|
|
17
|
+
const tag = x.hasBody ? '' : ` (无正文 · ${KIND_NOTE[x.relKind] || '正文缺失'})`;
|
|
18
|
+
lines.push(` ${label} [${x.refId || x.docId}]${tag}`);
|
|
19
|
+
}
|
|
16
20
|
if (d.external?.length) {
|
|
17
21
|
lines.push(`外部文档 ${d.external.length} 个(只读引用):`);
|
|
18
22
|
for (const x of d.external) lines.push(` ${x.path}`);
|
|
19
23
|
}
|
|
20
24
|
if (!d.count && !d.external?.length) {
|
|
21
|
-
lines.push('
|
|
25
|
+
lines.push('(还没有文档——直接新建即可,正文写入库内)');
|
|
22
26
|
}
|
|
23
27
|
return lines.join('\n');
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
export const renderGet = (d: any): string => {
|
|
27
|
-
if (d.missing)
|
|
31
|
+
if (d.missing) {
|
|
32
|
+
// 有 relKind = 「条目存在但没有正文」(历史空壳 / 外部镜像 / 正文缺失);
|
|
33
|
+
// 没有 relKind = 外部路径本身不存在。
|
|
34
|
+
const who = d.desc || d.title || d.refId || d.docId || d.rel || d.path;
|
|
35
|
+
if (d.relKind) {
|
|
36
|
+
const kind = KIND_NOTE[d.relKind] ? ` · ${KIND_NOTE[d.relKind]}` : '';
|
|
37
|
+
return `(无正文${kind}: ${who}${d.reason ? ` — ${d.reason}` : ''})`;
|
|
38
|
+
}
|
|
39
|
+
return `(文档不存在: ${who})`;
|
|
40
|
+
}
|
|
28
41
|
if (d.dir) return `(外部目录绑定: ${d.path},${d.files.length} 个文档)\n ${d.files.slice(0, 20).join('\n ')}`;
|
|
29
|
-
const
|
|
42
|
+
const title = d.desc || d.title || '未命名文档';
|
|
43
|
+
const head = [`【${title}】`, ` ${d.refId || d.docId}${d.external ? ' (外部 · 可写回来源)' : ''}`, ''];
|
|
30
44
|
return head.join('\n') + d.body;
|
|
31
45
|
};
|
|
32
46
|
|
|
33
|
-
export const renderWritten = (d: any): string =>
|
|
34
|
-
|
|
47
|
+
export const renderWritten = (d: any): string => {
|
|
48
|
+
const who = d.desc || d.refId || d.rel || d.path || d.docId;
|
|
49
|
+
const descLine = d.desc !== undefined ? `\n描述: ${d.desc || '(空)'}` : '';
|
|
50
|
+
return `已写入 ${who}(${d.bytes} 字节)${d.summary ? `\n摘要已回写: ${d.summary}` : ''}${descLine}`;
|
|
51
|
+
};
|
|
35
52
|
|
|
36
53
|
export const renderSeed = (d: any): string => {
|
|
37
54
|
if (d.written !== undefined) return `已播种 ${d.written} 份文档:\n ${(d.items || []).join('\n ') || '(无)'}`;
|
|
@@ -61,7 +78,8 @@ export const renderAttachments = (d: any): string => {
|
|
|
61
78
|
const areaOf = (role: unknown): string => (role === 'attach' ? '附件区' : '正文内嵌');
|
|
62
79
|
const lines = [`「${d.locator}」的资源(${d.attachments.length})`];
|
|
63
80
|
for (const a of d.attachments) {
|
|
64
|
-
const where = a.localPath || a.url || (a.kind === '
|
|
81
|
+
const where = a.localPath || a.url || (a.kind === 'mdfile' ? a.absPath
|
|
82
|
+
: a.kind === 'task' ? `task ${a.targetKey}#${a.targetSeq}` : a.targetKey);
|
|
65
83
|
lines.push(` ${a.id} [${a.kind}/${a.role} · ${areaOf(a.role)}] ${a.name || '-'} ${where || ''}`);
|
|
66
84
|
}
|
|
67
85
|
return lines.join('\n');
|
package/src/modules/docs/seed.ts
CHANGED
|
@@ -110,7 +110,7 @@ async function candidateOf(rel: string, field: unknown, owner: RelOwner): Promis
|
|
|
110
110
|
return { rel, title, body: '# ' + title + '\n\n' + clean(field) + '\n' };
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
/**
|
|
113
|
+
/** 种子计划(零副作用):列出所有「字符串有值、文档还没有正文行」的约定路径 */
|
|
114
114
|
export async function seedPlan(): Promise<{ items: SeedItem[]; count: number }> {
|
|
115
115
|
const { loadStore, deriveKey, boardRepoKeys } = await reposBridge();
|
|
116
116
|
const s = await loadStore();
|