nx-kv 0.41.0 → 0.41.1
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 +29 -6
- package/README.md +1 -0
- package/package.json +2 -2
- package/src/core/attachmentdb/docs.js +104 -0
- package/src/core/attachmentdb/ids.js +96 -0
- package/src/core/attachmentdb/query.js +189 -0
- package/src/core/attachmentdb/relations.js +153 -0
- package/src/core/attachmentdb/resources.js +225 -0
- package/src/core/attachmentdb.js +42 -715
- package/src/core/db/import-json/data.js +140 -0
- package/src/core/db/import-json/extras.js +69 -0
- package/src/core/db/import-json/links.js +147 -0
- package/src/core/db/import-json/refs.js +183 -0
- package/src/core/db/import-json/repos.js +180 -0
- package/src/core/db/import-json/scan.js +35 -0
- package/src/core/db/import-json/tasks.js +317 -0
- package/src/core/db/import-json.js +31 -1061
- package/src/modules/docs/attach.js +181 -0
- package/src/modules/docs/index.js +20 -448
- package/src/modules/docs/knowledge.js +7 -2
- package/src/modules/docs/render.js +84 -0
- package/src/modules/docs/service.js +200 -0
- package/src/modules/localtask/action-attach.js +88 -0
- package/src/modules/localtask/action-flags.js +6 -0
- package/src/modules/localtask/action-lifecycle.js +190 -0
- package/src/modules/localtask/action-maintenance.js +130 -0
- package/src/modules/localtask/action-move.js +58 -0
- package/src/modules/localtask/action-query.js +46 -0
- package/src/modules/localtask/action-remove.js +116 -0
- package/src/modules/localtask/action-render.js +200 -0
- package/src/modules/localtask/action-submit.js +186 -0
- package/src/modules/localtask/action-topics.js +46 -0
- package/src/modules/localtask/action-waiting.js +95 -0
- package/src/modules/localtask/index.js +29 -1104
- package/src/modules/repos/boards/core.js +255 -0
- package/src/modules/repos/boards/docs.js +53 -0
- package/src/modules/repos/boards/members.js +228 -0
- package/src/modules/repos/boards/transfer.js +159 -0
- package/src/modules/repos/boards.js +25 -661
- package/src/modules/repos/cli/board-actions.js +177 -0
- package/src/modules/repos/cli/ref-actions.js +157 -0
- package/src/modules/repos/cli/remote-actions.js +141 -0
- package/src/modules/repos/cli/render.js +168 -0
- package/src/modules/repos/cli/repo-actions.js +199 -0
- package/src/modules/repos/cli/transfer-actions.js +105 -0
- package/src/modules/repos/index.js +18 -920
- package/src/modules/repos/service/bind-topics.js +97 -0
- package/src/modules/repos/service/context.js +189 -0
- package/src/modules/repos/service/crud.js +345 -0
- package/src/modules/repos/service/identity.js +188 -0
- package/src/modules/repos/service/store.js +274 -0
- package/src/modules/repos/service.js +41 -1061
- package/src/modules/repos/transfer/diff.js +126 -0
- package/src/modules/repos/transfer/export.js +223 -0
- package/src/modules/repos/transfer/import.js +377 -0
- package/src/modules/repos/transfer/layout.js +135 -0
- package/src/modules/repos/transfer/render.js +72 -0
- package/src/modules/repos/transfer.js +11 -922
- package/src/modules/tasktool/attach-resource.js +293 -0
- package/src/modules/tasktool/attach-template.js +266 -0
- package/src/modules/tasktool/attach.js +70 -558
- package/src/modules/tasktool/delivery-template.js +2 -1
- package/src/modules/tasktool/doc-inline.js +84 -0
- package/src/modules/tasktool/groupctx.js +3 -1
- package/src/modules/tasktool/plugins/timegoal-core-store.js +151 -0
- package/src/modules/tasktool/plugins/timegoal-cwd-store.js +441 -0
- package/src/modules/tasktool/plugins/timegoal-store.js +16 -842
- package/src/modules/tasktool/plugins/timegoal-task-store.js +289 -0
- package/src/modules/tasktool/wait.js +3 -1
- package/src/modules/todo/attachments.js +149 -0
- package/src/modules/todo/locate.js +82 -0
- package/src/modules/todo/service.js +42 -382
- package/src/modules/todo/store.js +158 -0
- package/src/shared/prompt-blocks.js +13 -4
- package/src/web/frontend/components/md/find-bar.jsx +38 -0
- package/src/web/frontend/components/md/live-block.jsx +129 -0
- package/src/web/frontend/components/md/md-panes-helpers.js +92 -0
- package/src/web/frontend/components/md/md-panes-keys.js +193 -0
- package/src/web/frontend/components/md/md-panes-root.jsx +158 -0
- package/src/web/frontend/components/md/md-panes.jsx +124 -1342
- package/src/web/frontend/components/md/slash-menu.jsx +83 -0
- package/src/web/frontend/components/md/status-bar.jsx +46 -0
- package/src/web/frontend/components/md/use-live-preview.js +279 -0
- package/src/web/frontend/components/md/use-slash-menu.js +80 -0
- package/src/web/frontend/components/md/use-source-editor.js +297 -0
- package/src/web/frontend/modules/md/md-blocks.js +248 -0
- package/src/web/frontend/modules/md/md-parse.js +23 -507
- package/src/web/frontend/modules/md/md-render.js +258 -0
- package/src/web/frontend/modules/md/style.css +7 -1605
- package/src/web/frontend/modules/md/styles/chrome.css +252 -0
- package/src/web/frontend/modules/md/styles/docs.css +185 -0
- package/src/web/frontend/modules/md/styles/editor.css +308 -0
- package/src/web/frontend/modules/md/styles/panels.css +372 -0
- package/src/web/frontend/modules/md/styles/shell.css +363 -0
- package/src/web/frontend/modules/md/styles/templates.css +125 -0
- package/src/web/frontend/page/dag/edges.js +55 -0
- package/src/web/frontend/page/dag/head-bar.jsx +46 -0
- package/src/web/frontend/page/dag/index.jsx +57 -420
- package/src/web/frontend/page/dag/layout.js +83 -0
- package/src/web/frontend/page/dag/model.js +47 -0
- package/src/web/frontend/page/dag/node-card.jsx +123 -0
- package/src/web/frontend/page/dag/use-interactions.js +135 -0
- package/src/web/frontend/page/dir/task-ack.js +38 -0
- package/src/web/frontend/page/dir/task-actions.js +379 -0
- package/src/web/frontend/page/dir/task-beside-header.jsx +18 -0
- package/src/web/frontend/page/dir/task-board-section.jsx +38 -0
- package/src/web/frontend/page/dir/task-chain.js +172 -0
- package/src/web/frontend/page/dir/task-derived-ctx.js +46 -0
- package/src/web/frontend/page/dir/task-dock-panel.jsx +227 -0
- package/src/web/frontend/page/dir/task-dock.js +79 -0
- package/src/web/frontend/page/dir/task-feedback.js +207 -0
- package/src/web/frontend/page/dir/task-goal-section.jsx +50 -0
- package/src/web/frontend/page/dir/task-goal.js +36 -0
- package/src/web/frontend/page/dir/task-history-view.jsx +44 -0
- package/src/web/frontend/page/dir/task-not-found.jsx +23 -0
- package/src/web/frontend/page/dir/task-preview-modal.jsx +82 -0
- package/src/web/frontend/page/dir/task-sel-menu.js +54 -0
- package/src/web/frontend/page/dir/task-status-bar.jsx +61 -0
- package/src/web/frontend/page/dir/task-utils.js +7 -0
- package/src/web/frontend/page/dir/task.jsx +117 -1532
- package/src/web/frontend/page/repos/bind-modals.jsx +118 -0
- package/src/web/frontend/page/repos/board-admin.jsx +226 -0
- package/src/web/frontend/page/repos/board-refs.jsx +97 -0
- package/src/web/frontend/page/repos/doc-search-modal.jsx +241 -0
- package/src/web/frontend/page/repos/filters-bar.jsx +44 -0
- package/src/web/frontend/page/repos/index.jsx +248 -1834
- package/src/web/frontend/page/repos/pending-section.jsx +163 -0
- package/src/web/frontend/page/repos/ref-panel.jsx +406 -0
- package/src/web/frontend/page/repos/remote-modal.jsx +112 -0
- package/src/web/frontend/page/repos/repo-form-modal.jsx +219 -0
- package/src/web/frontend/page/repos/repo-table.jsx +216 -0
- package/src/web/frontend/page/settings/prompt-template-params.js +214 -0
- package/src/web/frontend/page/settings/prompt-templates-section.jsx +1 -213
- package/src/web/frontend/style-v2.css +6 -1232
- package/src/web/frontend/style.css +10 -2434
- package/src/web/frontend/styles/base.css +139 -0
- package/src/web/frontend/styles/board.css +322 -0
- package/src/web/frontend/styles/buttons-cards.css +244 -0
- package/src/web/frontend/styles/modals.css +458 -0
- package/src/web/frontend/styles/panels.css +366 -0
- package/src/web/frontend/styles/repos-admin.css +207 -0
- package/src/web/frontend/styles/repos.css +330 -0
- package/src/web/frontend/styles/settings.css +244 -0
- package/src/web/frontend/styles/submit-bar.css +124 -0
- package/src/web/frontend/styles-v2/dag.css +285 -0
- package/src/web/frontend/styles-v2/dir.css +210 -0
- package/src/web/frontend/styles-v2/shell.css +251 -0
- package/src/web/frontend/styles-v2/sidebar.css +199 -0
- package/src/web/frontend/styles-v2/views.css +287 -0
- package/src/web/frontend/workspace/layout.js +399 -0
- package/src/web/frontend/workspace/open.js +246 -0
- package/src/web/frontend/workspace/panels.js +417 -0
- package/src/web/frontend/workspace.js +8 -1044
- package/src/web/public/assets/Introduction-Dnh0L_ss.js +1 -0
- package/src/web/public/assets/app-context-D7HAx67n.js +1 -0
- package/src/web/public/assets/bar-CgCAhY5x.js +1 -0
- package/src/web/public/assets/{board-view-t8CKtq17.js → board-view-CZKZsyk-.js} +1 -1
- package/src/web/public/assets/{button-M9TUn-AR.js → button-Cmo-6aoW.js} +1 -1
- package/src/web/public/assets/cloud-DMeqfWK9.js +3 -0
- package/src/web/public/assets/composer-launch-Bf4rXhLs.js +1 -0
- package/src/web/public/assets/composer-panel-C0qsxE7e.js +1 -0
- package/src/web/public/assets/dag-BBtSqd-X.js +1 -0
- package/src/web/public/assets/dir-UUWImKeX.js +5 -0
- package/src/web/public/assets/frontmatter-QvrjUNzF.js +2 -0
- package/src/web/public/assets/group-DFMGHQ-H.js +1 -0
- package/src/web/public/assets/index-CgEWvYQk.js +2 -0
- package/src/web/public/assets/md-history-CKumOs4q.js +39 -0
- package/src/web/public/assets/md-parse-awNLHAzO.js +13 -0
- package/src/web/public/assets/{member-picker--32VkTmv.js → member-picker-BAgkj36N.js} +1 -1
- package/src/web/public/assets/model-DzdWfp14.js +2 -0
- package/src/web/public/assets/{overview-B788GcJE.js → overview-BrcPfsJO.js} +1 -1
- package/src/web/public/assets/progress-DHDlz9O9.js +3 -0
- package/src/web/public/assets/refs-CqvRGv8w.js +1 -0
- package/src/web/public/assets/repos-DGrGWDnX.js +14 -0
- package/src/web/public/assets/route-crumb-yyPGKKKq.js +1 -0
- package/src/web/public/assets/settings-9zNucAPD.js +6 -0
- package/src/web/public/assets/{status-tag-BPbfa4zt.js → status-tag-bDdrFgpZ.js} +1 -1
- package/src/web/public/assets/task-CG4fzV6s.js +11 -0
- package/src/web/public/assets/{task-status-BP6y8MVu.js → task-status-BnymQMTw.js} +1 -1
- package/src/web/public/assets/templates-DdHWIxUE.js +1 -0
- package/src/web/public/assets/tool-bar-D8q3kOOl.js +1 -0
- package/src/web/public/assets/upload-BIMbGcCB.js +1 -0
- package/src/web/public/assets/workspace-C_5X2gIr.js +28 -0
- package/src/web/public/index.html +8 -4
- package/src/web/public/assets/Introduction-DKqRmABL.js +0 -1
- package/src/web/public/assets/bar-B8QJ4EnF.js +0 -1
- package/src/web/public/assets/cloud-C2O_1vT5.js +0 -3
- package/src/web/public/assets/composer-launch-BgMj0T3Y.js +0 -1
- package/src/web/public/assets/composer-panel-C5XUApWJ.js +0 -1
- package/src/web/public/assets/dag-CWAWk_gt.js +0 -1
- package/src/web/public/assets/dir-Cu5B5z6J.js +0 -5
- package/src/web/public/assets/group-YA-FgKS3.js +0 -1
- package/src/web/public/assets/index-DxX-ZzRP.js +0 -30
- package/src/web/public/assets/md-history-4sXoj4RH.js +0 -28
- package/src/web/public/assets/md-parse-C2bDc3IZ.js +0 -25
- package/src/web/public/assets/progress-CfzFVSDu.js +0 -3
- package/src/web/public/assets/refs-qtxw66hp.js +0 -1
- package/src/web/public/assets/repos-CpVuGaP2.js +0 -14
- package/src/web/public/assets/route-crumb-B8oEN8BB.js +0 -1
- package/src/web/public/assets/settings-BmWNBqcv.js +0 -6
- package/src/web/public/assets/task-DsFCNaOJ.js +0 -11
- package/src/web/public/assets/templates-4Xaj2m9L.js +0 -1
- package/src/web/public/assets/tool-bar-CfBWzhpV.js +0 -1
- package/src/web/public/assets/upload-L1g-pfvZ.js +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// 常量与纯函数:状态判据、时长解析、ref id、任务引用解析、空报告工厂。
|
|
2
|
+
// 本文件不碰数据库,供导入管线的各阶段共用。
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
/** legacy 写入层的正文上限(迁移时超长按截断 + 标记,不整体失败)。 */
|
|
6
|
+
export const MAX_BODY = 20_000;
|
|
7
|
+
|
|
8
|
+
/** 迁移时承载「对不上真实仓库的队列」的哨兵仓库 key。 */
|
|
9
|
+
export const SENTINEL_REPO_KEY = '__unbound__';
|
|
10
|
+
export const SENTINEL_REPO_NAME = '未绑定仓库';
|
|
11
|
+
|
|
12
|
+
/** legacy 文件名(只认这几个;`repos.backup.*.json` 不参与)。 */
|
|
13
|
+
export const LEGACY_FILES = {
|
|
14
|
+
localtasks: 'localtasks.json',
|
|
15
|
+
sessiontasks: 'sessiontasks.json',
|
|
16
|
+
repos: 'repos.json',
|
|
17
|
+
timegoals: 'timegoals.json',
|
|
18
|
+
templates: 'templates.json',
|
|
19
|
+
config: 'config.json',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** config.json 里属于「偏好」的 4 个字段(其余是凭据,**绝不进库**)。 */
|
|
23
|
+
export const CONFIG_PREF_KEYS = ['autoSyncAttachments', 'attachmentsDir', 'gitRepoRoot', 'gitDevRoot'];
|
|
24
|
+
|
|
25
|
+
/** localtasks store 里属于「本机设置」的 5 个字段。 */
|
|
26
|
+
export const LOCALTASK_SETTING_KEYS = [
|
|
27
|
+
'timeoutSec',
|
|
28
|
+
'taskSuffix',
|
|
29
|
+
'ackPrompt',
|
|
30
|
+
'deliveryTemplate',
|
|
31
|
+
'attachTemplate',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** 稳定的 ref id:locator 的纯函数(同一份文档换台机器也是同一个 id;路径统一 POSIX)。 */
|
|
35
|
+
export function refIdOf(locator) {
|
|
36
|
+
return 'ref_' + crypto.createHash('sha1').update(String(locator).replace(/\\/g, '/'), 'utf8').digest('hex').slice(0, 16);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 空报告。所有分支都填它,调用方(CLI / 测试)只读这一个对象。 */
|
|
40
|
+
export function emptyReport() {
|
|
41
|
+
return {
|
|
42
|
+
sources: [],
|
|
43
|
+
imported: {
|
|
44
|
+
repos: 0,
|
|
45
|
+
members: 0,
|
|
46
|
+
topics: 0,
|
|
47
|
+
tasks: 0,
|
|
48
|
+
presence: 0,
|
|
49
|
+
links: 0,
|
|
50
|
+
deps: 0,
|
|
51
|
+
goals: 0,
|
|
52
|
+
goalChecks: 0,
|
|
53
|
+
refs: 0,
|
|
54
|
+
refBindings: 0,
|
|
55
|
+
templates: 0,
|
|
56
|
+
settings: 0,
|
|
57
|
+
},
|
|
58
|
+
distribution: { pending: 0, claimed: 0, done: 0, cancelled: 0 },
|
|
59
|
+
warnings: [],
|
|
60
|
+
discarded: [],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const jsonText = (v) => JSON.stringify(v === undefined ? null : v);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* legacy 任务的 5 步嵌套判据。
|
|
68
|
+
*
|
|
69
|
+
* @param {object} task legacy 任务行
|
|
70
|
+
* @returns {{status: string, unknown: boolean, archived: boolean, hasSummary: boolean}}
|
|
71
|
+
*/
|
|
72
|
+
export function mapLegacyStatus(task) {
|
|
73
|
+
const raw = String((task && task.status) ?? '').trim();
|
|
74
|
+
const summaryRaw = task ? task.roundSummary : undefined;
|
|
75
|
+
const hasSummary = summaryRaw !== undefined && summaryRaw !== null && String(summaryRaw).trim() !== '';
|
|
76
|
+
|
|
77
|
+
// 第 0 步:**新词直通**。T02 之后 JSON 里可能已是 pending/claimed/done/cancelled
|
|
78
|
+
// (跑过 rewrite-json-status.mjs 的机器),它们不是 legacy 词,原样认领 ——
|
|
79
|
+
// 「两条都要认」:旧词按判据映射,新词原样保留。
|
|
80
|
+
if (raw === 'claimed' || raw === 'done' || raw === 'cancelled') {
|
|
81
|
+
return { status: raw, unknown: false, archived: raw === 'cancelled', hasSummary };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 第 2 步:pending 优先于一切 —— 即使带了 roundSummary(历史残留 / 就地重开的空串)
|
|
85
|
+
if (raw === 'pending') return { status: 'pending', unknown: false, archived: false, hasSummary };
|
|
86
|
+
// 第 3 步
|
|
87
|
+
if (raw === 'consumed') {
|
|
88
|
+
return { status: hasSummary ? 'done' : 'claimed', unknown: false, archived: false, hasSummary };
|
|
89
|
+
}
|
|
90
|
+
// 第 4 步
|
|
91
|
+
if (raw === 'archived') {
|
|
92
|
+
return { status: hasSummary ? 'done' : 'cancelled', unknown: false, archived: true, hasSummary };
|
|
93
|
+
}
|
|
94
|
+
// 第 5 步:未知状态不猜语义 —— 当 pending(可领)并报告,因为"丢失"比"重领"更糟
|
|
95
|
+
return { status: 'pending', unknown: true, archived: false, hasSummary };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 旧 timegoal 的时长写法:既可能是 `{durationSec: 1800}`(新夹具),
|
|
100
|
+
* 也可能是 `{duration: "2h"}`(真机上更早的存档)。只认 durationSec 会让后者
|
|
101
|
+
* 静默变成 0 → 目标被跳过,迁移报告却说「已迁入 goals」。
|
|
102
|
+
*/
|
|
103
|
+
const DURATION_UNITS = {
|
|
104
|
+
s: 1, sec: 1, secs: 1, second: 1, seconds: 1, 秒: 1,
|
|
105
|
+
m: 60, min: 60, mins: 60, minute: 60, minutes: 60, 分: 60, 分钟: 60,
|
|
106
|
+
h: 3600, hr: 3600, hrs: 3600, hour: 3600, hours: 3600, 小时: 3600, 时: 3600,
|
|
107
|
+
d: 86400, day: 86400, days: 86400, 天: 86400, 日: 86400,
|
|
108
|
+
w: 604800, week: 604800, weeks: 604800, 周: 604800,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export function legacyDurationSec(tg) {
|
|
112
|
+
const direct = Math.trunc(Number(tg && tg.durationSec) || 0);
|
|
113
|
+
if (direct > 0) return direct;
|
|
114
|
+
const raw = tg && tg.duration;
|
|
115
|
+
if (Number.isFinite(Number(raw)) && Number(raw) > 0) return Math.trunc(Number(raw));
|
|
116
|
+
const m = /^(\d+(?:\.\d+)?)\s*([a-zA-Z一-龥]+)$/.exec(String(raw || '').trim());
|
|
117
|
+
if (!m) return 0;
|
|
118
|
+
const unit = DURATION_UNITS[m[2].toLowerCase()];
|
|
119
|
+
return unit ? Math.trunc(Number(m[1]) * unit) : 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** `"topicKey:id"` → { legacyKey, seq };解析不出来返回 null。 */
|
|
123
|
+
export function parseTaskRef(raw) {
|
|
124
|
+
const s = String(raw ?? '').trim();
|
|
125
|
+
if (!s) return null;
|
|
126
|
+
const at = s.lastIndexOf(':');
|
|
127
|
+
if (at <= 0) return null;
|
|
128
|
+
const seq = Math.trunc(Number(s.slice(at + 1)) || 0);
|
|
129
|
+
if (!seq) return null;
|
|
130
|
+
return { legacyKey: s.slice(0, at), seq };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function stringOrNull(v) {
|
|
134
|
+
const s = String(v ?? '').trim();
|
|
135
|
+
return s ? s : null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function numberOrNull(n) {
|
|
139
|
+
return Number.isFinite(n) ? n : null;
|
|
140
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// templates / settings 阶段:templates.json → templates;本机设置与偏好白名单 → settings。
|
|
2
|
+
import { CONFIG_PREF_KEYS, jsonText, LOCALTASK_SETTING_KEYS } from './data.js';
|
|
3
|
+
|
|
4
|
+
export function importTemplates(db, templatesData, atMs, report) {
|
|
5
|
+
const list = Array.isArray(templatesData && templatesData.templates) ? templatesData.templates : [];
|
|
6
|
+
const defaultId = String((templatesData && templatesData.defaultId) || '');
|
|
7
|
+
list.forEach((t, index) => {
|
|
8
|
+
const id = String((t && t.id) || '').trim();
|
|
9
|
+
if (!id) return;
|
|
10
|
+
// legacy 只有"新建任务的骨架正文"这一种用途 → category='newtask'
|
|
11
|
+
// is_default 一律先落 0:类目的「唯一位」可能已被内置 seed 占住
|
|
12
|
+
//(ux_templates_default 每类目最多一个),下面循环外统一两步落默认。
|
|
13
|
+
db.run(
|
|
14
|
+
`INSERT INTO templates (id, category, name, slot, body, vars_schema, vars, is_default,
|
|
15
|
+
enabled, sort_order, builtin, state, version, deleted_at,
|
|
16
|
+
created_at, updated_at)
|
|
17
|
+
VALUES (:id, 'newtask', :name, 'suffix', :body, '[]', :vars, 0,
|
|
18
|
+
1, :sort, :builtin, '', 0, NULL, :at, :at)
|
|
19
|
+
ON CONFLICT(id) DO NOTHING`,
|
|
20
|
+
{
|
|
21
|
+
id,
|
|
22
|
+
name: String(t.name || id),
|
|
23
|
+
body: String(t.body || ''),
|
|
24
|
+
vars: jsonText(t.values && typeof t.values === 'object' ? t.values : {}),
|
|
25
|
+
sort: index,
|
|
26
|
+
builtin: t.builtin ? 1 : 0,
|
|
27
|
+
at: atMs,
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
report.imported.templates += 1;
|
|
31
|
+
});
|
|
32
|
+
// defaultId → is_default 列。两步落:先摘掉类目里已有的默认,再点亮 defaultId
|
|
33
|
+
// 指的那行(defaultId 对不上任何行时保持原默认 —— 与旧 normalize 同兜底)。
|
|
34
|
+
if (defaultId) {
|
|
35
|
+
db.run("UPDATE templates SET is_default = 0 WHERE category = 'newtask' AND is_default = 1");
|
|
36
|
+
db.run(
|
|
37
|
+
"UPDATE templates SET is_default = 1, updated_at = :at WHERE id = :id AND category = 'newtask'",
|
|
38
|
+
{ id: defaultId, at: atMs }
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function setSetting(db, key, value, atMs) {
|
|
44
|
+
db.run(
|
|
45
|
+
`INSERT INTO settings (key, value, updated_at) VALUES (:k, :v, :at)
|
|
46
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at`,
|
|
47
|
+
{ k: key, v: jsonText(value), at: atMs }
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function importSettings(db, localtasksData, configData, atMs, report) {
|
|
52
|
+
const lt = (localtasksData && localtasksData.settings) || null;
|
|
53
|
+
if (lt && typeof lt === 'object') {
|
|
54
|
+
for (const k of LOCALTASK_SETTING_KEYS) {
|
|
55
|
+
if (!Object.prototype.hasOwnProperty.call(lt, k)) continue;
|
|
56
|
+
setSetting(db, 'lt.' + k, lt[k], atMs);
|
|
57
|
+
report.imported.settings += 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (configData && typeof configData === 'object') {
|
|
61
|
+
// 白名单写入:**只**这四个偏好。token / baseUrl / email / userId / groupId
|
|
62
|
+
// 是凭据与会话身份,绝不允许进库(库会被备份、dump、拷走排障)。
|
|
63
|
+
for (const k of CONFIG_PREF_KEYS) {
|
|
64
|
+
if (!Object.prototype.hasOwnProperty.call(configData, k)) continue;
|
|
65
|
+
setSetting(db, 'app.' + k, configData[k], atMs);
|
|
66
|
+
report.imported.settings += 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// 边与独立目标阶段:forkOf/blockBy → task_links / task_deps;timegoals.json → goals。
|
|
2
|
+
// `blockBy` / `forkOf` 的 `"topicKey:id"` 两段都要重映射;解析失败的边记报告丢弃
|
|
3
|
+
// (一条脏边不能让整个迁移回滚)。
|
|
4
|
+
import { anyTimeMs } from '../time.js';
|
|
5
|
+
import { legacyDurationSec, parseTaskRef } from './data.js';
|
|
6
|
+
|
|
7
|
+
export function importLinksAndDeps(db, localtasksData, byLegacyKey, atMs, report) {
|
|
8
|
+
const topics = (localtasksData && localtasksData.topics) || {};
|
|
9
|
+
const resolve = (ref) => {
|
|
10
|
+
const parsed = parseTaskRef(ref);
|
|
11
|
+
if (!parsed) return null;
|
|
12
|
+
const topic = byLegacyKey.get(parsed.legacyKey);
|
|
13
|
+
if (!topic) return null;
|
|
14
|
+
const row = db.get('SELECT id FROM tasks WHERE topic_id = :t AND seq = :s', { t: topic.id, s: parsed.seq });
|
|
15
|
+
return row ? row.id : null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
for (const [legacyKey, t] of Object.entries(topics)) {
|
|
19
|
+
const tasks = Array.isArray(t && t.tasks) ? t.tasks : [];
|
|
20
|
+
for (const task of tasks) {
|
|
21
|
+
const srcId = resolve(`${legacyKey}:${task.id}`);
|
|
22
|
+
if (!srcId) continue;
|
|
23
|
+
|
|
24
|
+
// 派生链:forkOf → task_links(方向恒为 新 → 旧,一个任务只有一个来源)
|
|
25
|
+
if (task.forkOf) {
|
|
26
|
+
const dstId = resolve(task.forkOf);
|
|
27
|
+
if (!dstId) {
|
|
28
|
+
report.warnings.push({ what: 'link', why: 'forkOf 解析失败,已丢弃', key: legacyKey, id: task.id, ref: task.forkOf });
|
|
29
|
+
} else if (dstId !== srcId) {
|
|
30
|
+
const type = ['comment', 'reopen', 'feedback'].includes(task.forkKind) ? task.forkKind : 'reopen';
|
|
31
|
+
try {
|
|
32
|
+
db.run(
|
|
33
|
+
`INSERT INTO task_links (src_id, dst_id, type, note, created_at)
|
|
34
|
+
VALUES (:src, :dst, :type, '', :at)`,
|
|
35
|
+
{ src: srcId, dst: dstId, type, at: anyTimeMs(task.createdAt, atMs) }
|
|
36
|
+
);
|
|
37
|
+
report.imported.links += 1;
|
|
38
|
+
} catch (err) {
|
|
39
|
+
report.warnings.push({ what: 'link', why: String(err && err.message), key: legacyKey, id: task.id });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 编排依赖:blockBy[] → task_deps(一条脏边不能整体回滚)
|
|
45
|
+
for (const ref of Array.isArray(task.blockBy) ? task.blockBy : []) {
|
|
46
|
+
const depId = resolve(ref);
|
|
47
|
+
if (!depId) {
|
|
48
|
+
report.warnings.push({ what: 'dep', why: 'blockBy 解析失败,已丢弃', key: legacyKey, id: task.id, ref });
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (depId === srcId) {
|
|
52
|
+
report.warnings.push({ what: 'dep', why: 'blockBy 指向自己,已丢弃', key: legacyKey, id: task.id });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
db.run(
|
|
56
|
+
`INSERT INTO task_deps (task_id, dep_id, created_at) VALUES (:t, :d, :at)
|
|
57
|
+
ON CONFLICT(task_id, dep_id) DO NOTHING`,
|
|
58
|
+
{ t: srcId, d: depId, at: atMs }
|
|
59
|
+
);
|
|
60
|
+
report.imported.deps += 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// timegoals.json:只保留任务级目标;队列级目标丢弃 + 报告(队列是容器,没有"交付"这件事)。
|
|
67
|
+
export function importStandaloneGoals(db, timegoalsData, byLegacyKey, report) {
|
|
68
|
+
const goals = timegoalsData && timegoalsData.goals && typeof timegoalsData.goals === 'object'
|
|
69
|
+
? timegoalsData.goals
|
|
70
|
+
: {};
|
|
71
|
+
for (const [scope, g] of Object.entries(goals)) {
|
|
72
|
+
if (!scope.startsWith('task:')) {
|
|
73
|
+
report.discarded.push({ what: 'timegoal(queue-scope)', scope, count: 1, note: '只保留任务级目标' });
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const parsed = parseTaskRef(scope.slice('task:'.length));
|
|
77
|
+
const topic = parsed ? byLegacyKey.get(parsed.legacyKey) : null;
|
|
78
|
+
if (!topic) {
|
|
79
|
+
report.warnings.push({ what: 'goal', why: '作用域里的队列对不上,已丢弃', scope });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const taskRow = db.get('SELECT id, claimed_at, created_at FROM tasks WHERE topic_id = :t AND seq = :s', {
|
|
83
|
+
t: topic.id,
|
|
84
|
+
s: parsed.seq,
|
|
85
|
+
});
|
|
86
|
+
if (!taskRow) {
|
|
87
|
+
report.warnings.push({ what: 'goal', why: '作用域里的任务对不上,已丢弃', scope });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
let durationSec = legacyDurationSec(g);
|
|
91
|
+
const start = anyTimeMs(g.startedAt, NaN);
|
|
92
|
+
const startMs = Number.isFinite(start) ? start : taskRow.claimed_at || taskRow.created_at;
|
|
93
|
+
const deadlineRaw = anyTimeMs(g.deadline, NaN);
|
|
94
|
+
if (durationSec <= 0 && Number.isFinite(deadlineRaw) && deadlineRaw > startMs) {
|
|
95
|
+
durationSec = Math.trunc((deadlineRaw - startMs) / 1000);
|
|
96
|
+
}
|
|
97
|
+
const deadline = Number.isFinite(deadlineRaw) ? deadlineRaw : startMs + durationSec * 1000;
|
|
98
|
+
if (durationSec <= 0 || deadline <= startMs) {
|
|
99
|
+
report.warnings.push({ what: 'goal', why: '时长或截止时刻非法,已跳过', scope });
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// 与内嵌 timegoal 撞同一条任务时保留先到的一条,不能整库回滚
|
|
103
|
+
const res = db.run(
|
|
104
|
+
`INSERT INTO goals (task_id, duration_sec, started_at, deadline, prompt, state, version,
|
|
105
|
+
deleted_at, created_at, updated_at)
|
|
106
|
+
VALUES (:task, :dur, :start, :deadline, :prompt, :state, 0, :deleted, :at, :updated)
|
|
107
|
+
ON CONFLICT(task_id) WHERE deleted_at IS NULL DO NOTHING`,
|
|
108
|
+
{
|
|
109
|
+
task: taskRow.id,
|
|
110
|
+
dur: durationSec,
|
|
111
|
+
start: startMs,
|
|
112
|
+
deadline,
|
|
113
|
+
prompt: String(g.prompt || ''),
|
|
114
|
+
state: String(g.state || ''),
|
|
115
|
+
deleted: g.archivedAt ? anyTimeMs(g.archivedAt, null) : null,
|
|
116
|
+
at: startMs,
|
|
117
|
+
updated: anyTimeMs(g.updatedAt, startMs),
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
let goalId = Number(res.lastInsertRowid) || 0;
|
|
121
|
+
if (Number(res.changes) > 0) {
|
|
122
|
+
report.imported.goals += 1;
|
|
123
|
+
} else {
|
|
124
|
+
const existing = db.get('SELECT id FROM goals WHERE task_id = :t AND deleted_at IS NULL', { t: taskRow.id });
|
|
125
|
+
if (!existing) continue;
|
|
126
|
+
goalId = Number(existing.id);
|
|
127
|
+
}
|
|
128
|
+
for (const log of Array.isArray(g.log) ? g.log : []) {
|
|
129
|
+
const at = anyTimeMs(log.at, NaN);
|
|
130
|
+
if (!Number.isFinite(at)) continue;
|
|
131
|
+
db.run(
|
|
132
|
+
`INSERT INTO goal_checks (goal_id, at, elapsed_sec, remaining_sec, overtime_sec, reached, summary)
|
|
133
|
+
VALUES (:g, :at, :elapsed, :remaining, :overtime, :reached, :summary)`,
|
|
134
|
+
{
|
|
135
|
+
g: goalId,
|
|
136
|
+
at,
|
|
137
|
+
elapsed: Math.trunc(Number(log.elapsedSec) || 0),
|
|
138
|
+
remaining: Math.trunc(Number(log.remainingSec) || 0),
|
|
139
|
+
overtime: Math.trunc(Number(log.overtimeSec) || 0),
|
|
140
|
+
reached: log.reached ? 1 : 0,
|
|
141
|
+
summary: String(log.summary || ''),
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
report.imported.goalChecks += 1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// refs / ref_bindings 阶段:refs 磁盘上从来没有过 JSON 数据源,初值从两处重建 ——
|
|
2
|
+
// 1. `repos.json` 的 DocRef(doc / docLinks / repoDocs)
|
|
3
|
+
// 2. `docs/` 树扫描(未被任何 DocRef 指到的 → state='orphan')
|
|
4
|
+
// `ref_relations` 本轮留空。
|
|
5
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { join, sep } from 'node:path';
|
|
7
|
+
import { groupKeyOf } from '../../keys.js';
|
|
8
|
+
import { refIdOf } from './data.js';
|
|
9
|
+
|
|
10
|
+
/** docs 树的相对路径 → POSIX(库里的地址永远是正斜杠)。 */
|
|
11
|
+
function toPosix(rel) {
|
|
12
|
+
return rel.split(sep).join('/');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 递归收集 docs 树里的 .md(返回 POSIX 相对路径)。 */
|
|
16
|
+
export function listDocFiles(docsRoot) {
|
|
17
|
+
const out = [];
|
|
18
|
+
if (!docsRoot || !existsSync(docsRoot)) return out;
|
|
19
|
+
const walk = (dir, prefix) => {
|
|
20
|
+
let entries = [];
|
|
21
|
+
try {
|
|
22
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
23
|
+
} catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const e of entries) {
|
|
27
|
+
const p = join(dir, e.name);
|
|
28
|
+
if (e.isDirectory()) walk(p, prefix ? `${prefix}/${e.name}` : e.name);
|
|
29
|
+
else if (/\.md$/i.test(e.name)) out.push(prefix ? `${prefix}/${e.name}` : e.name);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
walk(docsRoot, '');
|
|
33
|
+
return out.map(toPosix).sort();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 索引层初值重建。另外按**约定路径**把"仓库介绍 / 组介绍 / 组内成员说明"绑到宿主上
|
|
38
|
+
* (`repo/<key>.md`、`board/<slug>.md`、`group/<slug>/<key>.md`,以及它们的
|
|
39
|
+
* 目录主篇 `<dir>/index.md`)。约定路径是 docs 模块读文档时的回落顺序,
|
|
40
|
+
* 迁移时按同一顺序探一次,绑定关系才不会丢。
|
|
41
|
+
*/
|
|
42
|
+
export function importRefs(db, reposData, docsRoot, atMs, report) {
|
|
43
|
+
const files = listDocFiles(docsRoot);
|
|
44
|
+
const fileSet = new Set(files);
|
|
45
|
+
for (const locator of files) {
|
|
46
|
+
const r = db.run(
|
|
47
|
+
`INSERT INTO refs (id, type, locator, state, version, deleted_at, created_at, updated_at)
|
|
48
|
+
VALUES (:id, 'md', :locator, 'orphan', 0, NULL, :at, :at)
|
|
49
|
+
ON CONFLICT(id) DO NOTHING`,
|
|
50
|
+
{ id: refIdOf(locator), locator, at: atMs }
|
|
51
|
+
);
|
|
52
|
+
if (Number(r.changes) > 0) report.imported.refs += 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// legacy id → 真实 key:repos 合并/重名加后缀后,旧 id 对应的 key 可能已经不是
|
|
56
|
+
// 原始字符串。绑定前必须按真实行校验(否则 FK 一拒,整个迁移回滚)。
|
|
57
|
+
const repoKeyById = new Map();
|
|
58
|
+
const groupKeyById = new Map();
|
|
59
|
+
for (const row of db.all("SELECT key, type, ext FROM repos WHERE deleted_at IS NULL")) {
|
|
60
|
+
let ext = {};
|
|
61
|
+
try {
|
|
62
|
+
ext = JSON.parse(String(row.ext || '{}')) || {};
|
|
63
|
+
} catch {
|
|
64
|
+
ext = {};
|
|
65
|
+
}
|
|
66
|
+
const lid = ext && ext.ext_legacy_id;
|
|
67
|
+
if (lid === undefined || lid === null || lid === '') continue;
|
|
68
|
+
if (row.type === 'group') groupKeyById.set(String(lid), String(row.key));
|
|
69
|
+
else repoKeyById.set(String(lid), String(row.key));
|
|
70
|
+
}
|
|
71
|
+
const isRepo = (k) =>
|
|
72
|
+
!!db.get("SELECT 1 AS x FROM repos WHERE key = :k AND type <> 'group' AND deleted_at IS NULL", { k });
|
|
73
|
+
const isGroup = (k) =>
|
|
74
|
+
!!db.get("SELECT 1 AS x FROM repos WHERE key = :k AND type = 'group' AND deleted_at IS NULL", { k });
|
|
75
|
+
|
|
76
|
+
const bind = (repoKey, groupKey, locator, type, position, note) => {
|
|
77
|
+
if (!fileSet.has(locator)) return false;
|
|
78
|
+
const id = refIdOf(locator);
|
|
79
|
+
db.run(`UPDATE refs SET state = '' WHERE id = :id`, { id });
|
|
80
|
+
// ON CONFLICT 的冲突目标带表达式(COALESCE)在 SQLite 里要写成一模一样的表达式,
|
|
81
|
+
// 这里用 INSERT OR IGNORE:绑定边重复插是幂等的正常情况,不该报错。
|
|
82
|
+
const r = db.run(
|
|
83
|
+
`INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, created_at)
|
|
84
|
+
VALUES (:repo, :group, :ref, :type, :pos, :note, :at)`,
|
|
85
|
+
{ repo: repoKey, group: groupKey, ref: id, type, pos: position, note, at: atMs }
|
|
86
|
+
);
|
|
87
|
+
if (Number(r.changes) > 0) report.imported.refBindings += 1;
|
|
88
|
+
return true;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const repos = Array.isArray(reposData && reposData.repos) ? reposData.repos : [];
|
|
92
|
+
const boards = Array.isArray(reposData && reposData.boards) ? reposData.boards : [];
|
|
93
|
+
|
|
94
|
+
// DocRef(本机 repos.json 没有这些字段,代码保留给别的机器)
|
|
95
|
+
const docRefsOf = (host) => {
|
|
96
|
+
const out = [];
|
|
97
|
+
const pushRef = (ref, note = '') => {
|
|
98
|
+
if (!ref || typeof ref !== 'object') return;
|
|
99
|
+
const rel = String(ref.rel || '').trim();
|
|
100
|
+
const path = String(ref.path || '').trim();
|
|
101
|
+
if (rel) out.push({ locator: rel, type: 'md', note: String(ref.tag || note || ''), extPath: '' });
|
|
102
|
+
// v2 起 refs 只装文档:外部 .md 绝对路径也是文档,type 统一为 md。
|
|
103
|
+
else if (path) out.push({ locator: path, type: 'md', note: String(ref.tag || note || ''), extPath: path });
|
|
104
|
+
};
|
|
105
|
+
pushRef(host && host.doc);
|
|
106
|
+
for (const l of Array.isArray(host && host.docLinks) ? host.docLinks : []) pushRef(l);
|
|
107
|
+
if (host && host.repoDocs && typeof host.repoDocs === 'object') {
|
|
108
|
+
for (const [k, v] of Object.entries(host.repoDocs)) pushRef(v, k);
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
let position = 0;
|
|
114
|
+
for (const r of repos) {
|
|
115
|
+
const legacyKey = String((r && r.key) || '').trim();
|
|
116
|
+
if (!legacyKey) continue;
|
|
117
|
+
const key = repoKeyById.get(String(r.id)) || legacyKey;
|
|
118
|
+
if (!isRepo(key)) {
|
|
119
|
+
report.warnings.push({ what: 'docRef', why: '宿主仓库不存在(合并/改名后失配),已跳过该仓库的文档绑定', repo: legacyKey });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// 约定路径:目录主篇优先,其次旧单文件(与 docs 模块的读回落顺序一致)
|
|
123
|
+
position = 0;
|
|
124
|
+
const boundMain = bind(key, null, `repo/${key}/index.md`, 'repo', position, '');
|
|
125
|
+
if (!boundMain) bind(key, null, `repo/${key}.md`, 'repo', position, '');
|
|
126
|
+
position += 1;
|
|
127
|
+
for (const d of docRefsOf(r)) {
|
|
128
|
+
if (d.extPath) {
|
|
129
|
+
// 外部路径(Obsidian 等):只在库里留地址,字节在库外
|
|
130
|
+
db.run(
|
|
131
|
+
`INSERT INTO refs (id, type, locator, state, version, deleted_at, created_at, updated_at)
|
|
132
|
+
VALUES (:id, :type, :locator, '', 0, NULL, :at, :at)
|
|
133
|
+
ON CONFLICT(id) DO NOTHING`,
|
|
134
|
+
{ id: refIdOf(d.locator), type: d.type, locator: d.locator, at: atMs }
|
|
135
|
+
);
|
|
136
|
+
report.imported.refs += 1;
|
|
137
|
+
} else if (!fileSet.has(d.locator)) {
|
|
138
|
+
// 相对 DocRef 指向的文件不在 docs 树里:没有 refs 行,绑定会撞 FK → 跳过并记账
|
|
139
|
+
report.warnings.push({ what: 'docRef', why: '引用文件不在 docs 树里,已跳过绑定', repo: key, locator: d.locator });
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const br = db.run(
|
|
143
|
+
`INSERT OR IGNORE INTO ref_bindings (repo_key, group_key, ref_id, type, position, note, created_at)
|
|
144
|
+
VALUES (:repo, NULL, :ref, 'repo', :pos, :note, :at)`,
|
|
145
|
+
{ repo: key, ref: refIdOf(d.locator), pos: position, note: d.note, at: atMs }
|
|
146
|
+
);
|
|
147
|
+
if (Number(br.changes) > 0) report.imported.refBindings += 1;
|
|
148
|
+
position += 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 组(boards)自身的介绍 + 组内成员说明
|
|
153
|
+
for (const b of boards) {
|
|
154
|
+
const name = String((b && b.name) || '').trim();
|
|
155
|
+
if (!name) continue;
|
|
156
|
+
const base = groupKeyOf(name);
|
|
157
|
+
const byName = db.get("SELECT key FROM repos WHERE type = 'group' AND name = :n AND deleted_at IS NULL", { n: name });
|
|
158
|
+
const gk = groupKeyById.get(String(b.id)) || (isGroup(base) ? base : byName && byName.key) || base;
|
|
159
|
+
if (!isGroup(gk)) {
|
|
160
|
+
report.warnings.push({ what: 'docRef', why: '组宿主不存在,已跳过该组的文档绑定', group: name });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const seg = base.slice('group/'.length);
|
|
164
|
+
const boundGroup = bind(gk, null, `board/${seg}/index.md`, 'group', 0, '');
|
|
165
|
+
if (!boundGroup) bind(gk, null, `board/${seg}.md`, 'group', 0, '');
|
|
166
|
+
for (const repoKeyRaw of Array.isArray(b.repoKeys) ? b.repoKeys : []) {
|
|
167
|
+
const repoKey = repoKeyById.get(String(repoKeyRaw || '').trim()) || String(repoKeyRaw || '').trim();
|
|
168
|
+
if (!repoKey) continue;
|
|
169
|
+
if (!isRepo(repoKey)) {
|
|
170
|
+
report.warnings.push({ what: 'docRef', why: '组成员不存在,已跳过成员文档绑定', group: gk, repo: repoKey });
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const boundMember = bind(repoKey, gk, `group/${seg}/${repoKey}/index.md`, 'group_repo', 0, '');
|
|
174
|
+
if (!boundMember) bind(repoKey, gk, `group/${seg}/${repoKey}.md`, 'group_repo', 0, '');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 没被任何绑定引用的 ref 保持 state='orphan'(面板要能列出"孤儿文档")
|
|
179
|
+
const orphans = db.get("SELECT count(*) AS c FROM refs WHERE state = 'orphan'");
|
|
180
|
+
if (orphans && orphans.c) {
|
|
181
|
+
report.warnings.push({ what: 'refs', why: '孤儿文档(未被任何宿主绑定)', count: Number(orphans.c) });
|
|
182
|
+
}
|
|
183
|
+
}
|