nx-kv 0.68.3 → 0.69.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 +40 -0
- package/package.json +1 -1
- package/src/core/attachmentdb/query.ts +10 -1
- package/src/core/attachmentdb/resources.ts +4 -16
- package/src/core/db/bootstrap.ts +4 -3
- package/src/core/db/import-json/links.ts +2 -2
- package/src/core/db/import-json/repos.ts +3 -24
- package/src/core/db/import-json/tasks.ts +92 -7
- package/src/core/db/import-json.ts +1 -2
- package/src/core/db/migrations/index.ts +6 -0
- package/src/core/db/migrations/v16-data.ts +167 -0
- package/src/core/db/migrations/v16.sql +15 -0
- package/src/core/db/migrations/v17-data.ts +110 -0
- package/src/core/db/migrations/v17.sql +112 -0
- package/src/core/db/repo-match.ts +52 -0
- package/src/core/db/seed-templates.ts +46 -11
- package/src/core/db/verify.ts +2 -2
- package/src/core/db/version.ts +5 -1
- package/src/modules/claim/groupctx.ts +1 -1
- package/src/modules/claim/host.ts +5 -5
- package/src/modules/goals/plugins/timegoal-task-store.ts +1 -1
- package/src/modules/localtask/actions/_manifest.generated.ts +3 -0
- package/src/modules/localtask/actions/localtask-boardtasks.ts +39 -39
- package/src/modules/localtask/actions/localtask-reopen.ts +5 -0
- package/src/modules/localtask/actions/localtask-sync-queues.ts +35 -0
- package/src/modules/localtask/actions/localtask-tasks.ts +3 -2
- package/src/modules/localtask/actions/localtask-update.ts +6 -0
- package/src/modules/localtask/infra/repo/goals.ts +2 -2
- package/src/modules/localtask/infra/repo/links.ts +1 -1
- package/src/modules/localtask/infra/repo/rows.ts +16 -0
- package/src/modules/localtask/infra/repo/tasks.ts +45 -41
- package/src/modules/localtask/infra/repo/topics.ts +61 -4
- package/src/modules/localtask/lifecycle/add.ts +15 -23
- package/src/modules/localtask/lifecycle/task-lifecycle.ts +7 -7
- package/src/modules/localtask/lifecycle/task-ops.ts +22 -11
- package/src/modules/localtask/lifecycle/task-view.ts +17 -11
- package/src/modules/localtask/lifecycle/topics.ts +79 -3
- package/src/modules/localtask/lifecycle/update.ts +28 -29
- package/src/modules/localtask/ops/attach-resource.ts +3 -4
- package/src/modules/localtask/ops/attach.ts +2 -2
- package/src/modules/localtask/ops/board-target.ts +8 -28
- package/src/modules/repos/actions/board-add.ts +5 -1
- package/src/modules/repos/actions/board-assign.ts +5 -1
- package/src/modules/repos/actions/board-remove.ts +5 -1
- package/src/modules/repos/actions/repo-add.ts +5 -1
- package/src/modules/repos/actions/repo-update.ts +5 -1
- package/src/modules/repos/boards/transfer.ts +3 -2
- package/src/modules/repos/orchestrate.ts +17 -0
- package/src/modules/repos/transfer/export.ts +24 -18
- package/src/modules/templates/actions/template-update.ts +1 -1
- package/src/modules/templates/service.ts +3 -0
- package/src/web/frontend/api/cli-tree.json +16 -1
- package/src/web/frontend/api/client.generated.ts +11 -3
- package/src/web/frontend/components/Introduction/style.css +1 -1
- package/src/web/frontend/components/layout/vsc-crumbs-model.ts +16 -8
- package/src/web/frontend/components/layout/vsc-crumbs.css +9 -16
- package/src/web/frontend/components/layout/vsc-crumbs.tsx +63 -57
- package/src/web/frontend/components/md/panes/live-block.tsx +3 -11
- package/src/web/frontend/components/md/panes/md-panes-keys.ts +1 -2
- package/src/web/frontend/components/md/panes/md-panes.tsx +2 -4
- package/src/web/frontend/components/popup/index.tsx +17 -3
- package/src/web/frontend/components/popup/style.css +9 -0
- package/src/web/frontend/components/sidebar/model.ts +2 -2
- package/src/web/frontend/components/tool-acts/modules.ts +1 -0
- package/src/web/frontend/modules/md/doc-store.ts +6 -0
- package/src/web/frontend/modules/md/md-blocks.ts +4 -43
- package/src/web/frontend/modules/md/md-parse.ts +2 -5
- package/src/web/frontend/modules/md/md-render.ts +2 -2
- package/src/web/frontend/modules/md/styles/docs.css +1 -1
- package/src/web/frontend/modules/prompts/template-preview.ts +5 -6
- package/src/web/frontend/page/dag/index.tsx +6 -5
- package/src/web/frontend/page/dir/task-actions.ts +16 -13
- package/src/web/frontend/page/dir/task-beside.ts +10 -20
- package/src/web/frontend/page/dir/task-board-section.tsx +3 -5
- package/src/web/frontend/page/dir/task-derived-ctx.ts +10 -5
- package/src/web/frontend/page/dir/task-utils.ts +9 -1
- package/src/web/frontend/page/dir/task.tsx +4 -4
- package/src/web/frontend/page/group/index.tsx +8 -8
- package/src/web/frontend/page/progress/index.tsx +7 -11
- package/src/web/frontend/page/repos/api.ts +5 -0
- package/src/web/frontend/page/repos/index.tsx +12 -1
- package/src/web/frontend/page/templates/index.tsx +9 -0
- package/src/web/frontend/page/templates/template-list.tsx +2 -1
- package/src/web/frontend/styles/base.css +1 -1
- package/src/web/frontend/styles/bindings.css +1 -1
- package/src/web/public/assets/app-context-DPFYOrgE.js +1 -0
- package/src/web/public/assets/{bar-DEY9q8mI.js → bar-I4qGaKTO.js} +1 -1
- package/src/web/public/assets/board-view-jt8QixVg.js +1 -0
- package/src/web/public/assets/{button-BRGGaUcY.js → button-VP4pjVsx.js} +1 -1
- package/src/web/public/assets/{composer-launch-DEHhs8k_.js → composer-launch-BL344XZg.js} +1 -1
- package/src/web/public/assets/composer-panel-D0ojgf7z.js +1 -0
- package/src/web/public/assets/dag-BY0lf-Nl.js +1 -0
- package/src/web/public/assets/{dir-C8HhVpFz.js → dir-BNHyviHQ.js} +1 -1
- package/src/web/public/assets/{doc-DgYKv2wo.css → doc-Ka-2V5jn.css} +1 -1
- package/src/web/public/assets/doc-wmc4swmo.js +6 -0
- package/src/web/public/assets/group-BSQ9_Gjs.js +1 -0
- package/src/web/public/assets/index-D2P-v30u.js +3 -0
- package/src/web/public/assets/{index-CUnLXQWJ.css → index-DHLeXl42.css} +1 -1
- package/src/web/public/assets/md-history-D0bYVPZY.js +47 -0
- package/src/web/public/assets/md-parse-BjzYV8n7.js +6 -0
- package/src/web/public/assets/{member-picker-BJ-Ucm-9.js → member-picker-BtWykPer.js} +1 -1
- package/src/web/public/assets/{popup-BdVXUaJk.js → popup-DLfU1TXG.js} +1 -1
- package/src/web/public/assets/{popup-CHK8uSG4.css → popup-DzBICcYS.css} +1 -1
- package/src/web/public/assets/progress-CQAvP9-n.js +3 -0
- package/src/web/public/assets/{refs-Cb9pmVsb.js → refs-Cf4ZbAra.js} +1 -1
- package/src/web/public/assets/{reopen-text-C3dnqygC.js → reopen-text-D0eQ2XAC.js} +1 -1
- package/src/web/public/assets/repo-form-modal-BahZhXq3.js +1 -0
- package/src/web/public/assets/repos-C2cZtRFo.js +12 -0
- package/src/web/public/assets/{route-crumb-DvXzznKm.js → route-crumb-DS76cmRK.js} +1 -1
- package/src/web/public/assets/{settings-BiqKrd8o.js → settings-C_VmzG7F.js} +1 -1
- package/src/web/public/assets/task-C4Sqe4vT.js +14 -0
- package/src/web/public/assets/{task-j7fMfJUp.css → task-Dcd2eA8B.css} +1 -1
- package/src/web/public/assets/task-ops-SFagO-OC.js +2 -0
- package/src/web/public/assets/task-utils-Y-j-zi8J.js +1 -0
- package/src/web/public/assets/template-preview-EM3OQ1Rc.js +1 -0
- package/src/web/public/assets/templates-B8jnGSAl.js +10 -0
- package/src/web/public/assets/{tool-bar-CAMqYt5j.js → tool-bar-NHeX0Kmo.js} +2 -2
- package/src/web/public/assets/use-rail-drag-CtZxisjE.js +1 -0
- package/src/web/public/index.html +15 -15
- package/src/shared/frontmatter.ts +0 -107
- package/src/web/public/assets/app-context-KCsdqNTq.js +0 -1
- package/src/web/public/assets/board-view-C8OQhkyi.js +0 -1
- package/src/web/public/assets/composer-panel-Cke_nbex.js +0 -1
- package/src/web/public/assets/dag-BvkJhdpX.js +0 -1
- package/src/web/public/assets/doc-R8KHVCxp.js +0 -6
- package/src/web/public/assets/group-d9wqo1pL.js +0 -1
- package/src/web/public/assets/index-DqTSNBzX.js +0 -3
- package/src/web/public/assets/md-history-BR2jLhFQ.js +0 -47
- package/src/web/public/assets/progress-CLSIX544.js +0 -3
- package/src/web/public/assets/repo-form-modal-awEPCcJK.js +0 -1
- package/src/web/public/assets/repos-CIgKjolu.js +0 -12
- package/src/web/public/assets/task-C664y4Vd.js +0 -14
- package/src/web/public/assets/task-ops-D8L16-TP.js +0 -2
- package/src/web/public/assets/task-status-Cjsm0xF7.js +0 -7
- package/src/web/public/assets/task-utils-Dh33OFKe.js +0 -1
- package/src/web/public/assets/template-preview-CjQ-ucPt.js +0 -1
- package/src/web/public/assets/templates-BZ1EM7W4.js +0 -10
- package/src/web/public/assets/use-rail-drag-C3GpkThI.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
本文件对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.69.0] - 2026-11-25 任务归属落库(schema v16/v17)+ frontmatter 彻底删除 + 队列自动持有
|
|
6
|
+
|
|
7
|
+
本轮主线:**任务归属从正文 frontmatter 搬进库内关联**(用户验收 #197 的彻底化),
|
|
8
|
+
配套 schema v16/v17 自动迁移(老库升级无感,数据不丢)。
|
|
9
|
+
|
|
10
|
+
### Changed(Breaking:库结构升级,自动迁移)
|
|
11
|
+
|
|
12
|
+
- **任务归属落库**(#197,v16+v17):`tasks` 重建为两条 topic 外键——`repo_topic_id`
|
|
13
|
+
(必填,编号序列与 `get --cwd` 领取按它,行为不变)+ `group_topic_id`(可空,组归属
|
|
14
|
+
唯一来源);新增 `ix_tasks_group` 索引。**正文只存 markdown,frontmatter 体系整体删除**
|
|
15
|
+
(shared/frontmatter.ts、前端 FM 块识别、写函数全部移除;迁移时剥掉历史正文头)。
|
|
16
|
+
- **哨兵仓库 `__unbound__` 删除**:队列必须绑真实仓库(cwd 匹配,匹配不到自动登记
|
|
17
|
+
`local/<目录名>`,绝不因找不到归属丢任务);组本身也是一条 topic(`group:<组key>`)。
|
|
18
|
+
- **组页/提示词查询 SQL 化**:组任务列表 `WHERE group_topic_id` 走索引,不再全量拉任务
|
|
19
|
+
逐条解析正文;提示词模板的组上下文(组介绍/组文档)改读库内关联。
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **仓库/组登记即持有队列 topic**(#199):登记/改路径/建组/成员变更/删组后自动补齐;
|
|
24
|
+
仓库管理页新增「刷新队列」按钮兜历史缺口;新 CLI `localtask sync-queues`(幂等)。
|
|
25
|
+
- **ref 生成模板升级**(#195):新增第 2 步「判断任务来源」——按 `show --json` 的
|
|
26
|
+
`boardMark`/`repoKey` 判组/仓库任务再绑定文档宿主;内置模板改为出厂正文随版本覆盖升级。
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- 组任务的 `get` 指令缺「项目组上下文/组介绍」整段(claim 还在解析正文);
|
|
31
|
+
- 组 topic(cwd 空)混进目录队列列表/侧栏的幽灵行;
|
|
32
|
+
- dag/progress 页判组任务、改归属从正文解析(#197 漏网点)改读关联。
|
|
33
|
+
|
|
34
|
+
### Chores
|
|
35
|
+
|
|
36
|
+
- 项目瘦身:重复实现收拢单点(frontmatter 读/剥、taskTopicColumn、路径归一);
|
|
37
|
+
测试碎片合并 164 → 153 个文件,用例 1182 个全保留。
|
|
38
|
+
|
|
39
|
+
### Verification
|
|
40
|
+
|
|
41
|
+
- 全量门禁通过:lint / typecheck / build / 全量单测 1169/1169。
|
|
42
|
+
- 生产库真迁移 v15→v16→v17 成功(326 任务 / 3 组 topic,数据无丢失);
|
|
43
|
+
浏览器端到端验收组页分流、无 frontmatter 残留(截图 temp/nxkv-197-*.png 等)。
|
|
44
|
+
|
|
5
45
|
## [0.68.3] - 2026-11-24 设置浮窗弹性缩放开场 + 材质升级
|
|
6
46
|
|
|
7
47
|
#253 的验收反馈(#260):「提升设置页面的视觉层级与材质表现,增强界面质感;弹窗过渡
|
package/package.json
CHANGED
|
@@ -88,12 +88,21 @@ export function listTaskAttachments(conn: any, taskId?: string | number): Linked
|
|
|
88
88
|
.map((r: any) => ({ ...rowView(r), role: r.role, position: Number(r.position) || 0, note: r.note }));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* tasks 表指向队列的列名(#197 起是 repo_topic_id,之前是 topic_id)。
|
|
93
|
+
* 迁移期(v2 等历史步骤)调到这里时表还是旧结构——按实际列探测,两个时代都能跑。
|
|
94
|
+
*/
|
|
95
|
+
export function taskTopicColumn(conn: any): string {
|
|
96
|
+
const cols = conn.all('PRAGMA table_info(tasks)').map((c: any) => String(c.name));
|
|
97
|
+
return cols.includes('repo_topic_id') ? 'repo_topic_id' : 'topic_id';
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
/** CLI 只有 topicKey + seq 时的查询入口。 */
|
|
92
101
|
export function listTaskAttachmentsBySeq(conn: any, { topicKey, seq }: {
|
|
93
102
|
topicKey?: string; seq?: number | string;
|
|
94
103
|
}): LinkedAttachmentView[] {
|
|
95
104
|
const row = conn.get(
|
|
96
|
-
`SELECT t.id FROM tasks t JOIN topics k ON k.id = t
|
|
105
|
+
`SELECT t.id FROM tasks t JOIN topics k ON k.id = t.${taskTopicColumn(conn)}
|
|
97
106
|
WHERE k.key = :key AND t.seq = :seq`,
|
|
98
107
|
{ key: String(topicKey || ''), seq: Number(seq) }
|
|
99
108
|
);
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from './ids.js';
|
|
11
11
|
import type { AttachmentRef } from './ids.js';
|
|
12
12
|
import { ensureFolderAttachment } from './folder.js';
|
|
13
|
+
import { taskTopicColumn } from './query.js';
|
|
13
14
|
|
|
14
15
|
export interface UpsertFileAttachmentInput {
|
|
15
16
|
id?: string;
|
|
@@ -161,22 +162,9 @@ export function ensureUrlAttachment(conn: any, { url, name = '', atMs = Date.now
|
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
/**
|
|
165
|
-
* 去掉正文头部的 frontmatter(与 shared/frontmatter.js 的 stripFrontmatter 同口径)。
|
|
166
|
-
* core 是最底层,不能反向 import shared,所以这里保留一份最小实现。
|
|
167
|
-
*/
|
|
168
|
-
const FM_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
169
|
-
const FM_KV_RE = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/;
|
|
170
|
-
function stripFrontmatter(src: unknown): string {
|
|
171
|
-
return String(src ?? '').replace(FM_RE, (block: string, inner: string) => {
|
|
172
|
-
const kv = String(inner || '').split(/\r?\n/).some((l) => FM_KV_RE.test(l));
|
|
173
|
-
return kv ? '' : block;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** 任务标题 = 正文(去 frontmatter)首个非空行,去 # 前缀,截 80 字。 */
|
|
165
|
+
/** 任务标题 = 正文首个非空行,去 # 前缀,截 80 字。#197 正文无 frontmatter 头。 */
|
|
178
166
|
function taskTitleOf(body: unknown): string {
|
|
179
|
-
const text = String(
|
|
167
|
+
const text = String(body || '').trim();
|
|
180
168
|
const first = text.split(/\r?\n/).map((s) => s.trim()).find(Boolean) || '';
|
|
181
169
|
return first.replace(/^#+\s*/, '').trim().slice(0, 80);
|
|
182
170
|
}
|
|
@@ -201,7 +189,7 @@ export function ensureTaskAttachment(conn: any, { taskId, atMs = Date.now(), nam
|
|
|
201
189
|
} = {}): string | null {
|
|
202
190
|
const row = conn.get(
|
|
203
191
|
`SELECT t.id AS taskId, t.seq, t.body, k.key AS topicKey
|
|
204
|
-
FROM tasks t JOIN topics k ON k.id = t
|
|
192
|
+
FROM tasks t JOIN topics k ON k.id = t.${taskTopicColumn(conn)}
|
|
205
193
|
WHERE t.id = :id`,
|
|
206
194
|
{ id: Number(taskId) }
|
|
207
195
|
);
|
package/src/core/db/bootstrap.ts
CHANGED
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
storeKindOf,
|
|
49
49
|
userVersion,
|
|
50
50
|
} from './migrator.js';
|
|
51
|
-
import { importLegacy, scanLegacy,
|
|
51
|
+
import { importLegacy, scanLegacy, LEGACY_FILES } from './import-json.js';
|
|
52
52
|
import { seedBuiltinTemplates } from './seed-templates.js';
|
|
53
53
|
import {
|
|
54
54
|
NotNxKvStoreError,
|
|
@@ -220,13 +220,14 @@ export function bootstrap(
|
|
|
220
220
|
// 双检:并发进程可能刚把表建好(锁是在 BEGIN IMMEDIATE 上等的)
|
|
221
221
|
if (countTables(conn) > 0) return { raced: true };
|
|
222
222
|
migrate(conn, { from: 0, context: migrationContext });
|
|
223
|
-
|
|
223
|
+
// #197:不再建哨兵仓库——队列必须绑真实仓库(导入时按 cwd 匹配或自动登记)
|
|
224
224
|
setMeta(conn, 'store_kind', STORE_KIND, atMs);
|
|
225
225
|
setMeta(conn, 'schema_version', String(CURRENT_SCHEMA_VERSION), atMs);
|
|
226
226
|
setMeta(conn, 'created_by', 'nx-kv/' + appVersion(), atMs);
|
|
227
227
|
let report: any = null;
|
|
228
228
|
if (importLegacyData && legacy.any) {
|
|
229
229
|
report = importLegacy(conn, { appDir, atMs });
|
|
230
|
+
// #197:导入已直接产出 v17 结构(组 topic 关联 + 剥正文头),无需再跑归一
|
|
230
231
|
}
|
|
231
232
|
// 导入之后立刻把正文引用/文档资源落关系表(002 的 apply 在导入之前跑,
|
|
232
233
|
// 这里补一次,保证「导入的历史任务」也不是只有正文里的 fileId 字符串)。
|
|
@@ -290,7 +291,6 @@ export function bootstrap(
|
|
|
290
291
|
const report = tx(
|
|
291
292
|
(conn) => {
|
|
292
293
|
if (!!getMeta(conn, 'migrated_from_json_at')) return null; // 双检
|
|
293
|
-
ensureSentinelRepo(conn, atMs); // `db status` 只建表不导入的库,也要有哨兵
|
|
294
294
|
// 同一个事务里再确认一次:空库导入时不覆盖已有数据
|
|
295
295
|
const taskCount = Number((conn.get('SELECT count(*) AS c FROM tasks') || {}).c || 0);
|
|
296
296
|
if (taskCount > 0) {
|
|
@@ -298,6 +298,7 @@ export function bootstrap(
|
|
|
298
298
|
return null;
|
|
299
299
|
}
|
|
300
300
|
const out = importLegacy(conn, { appDir, atMs });
|
|
301
|
+
// #197:导入已直接产出 v17 结构(组 topic 关联 + 剥正文头)
|
|
301
302
|
// 导入的数据在本事务里落资源关系;失败则整段回滚,不会留下半套关系。
|
|
302
303
|
syncTaskAttachmentIndex(conn, { atMs });
|
|
303
304
|
syncDocAttachmentIndex(conn, { docsDir: migrationContext.docsDir, atMs });
|
|
@@ -20,7 +20,7 @@ export function importLinksAndDeps(
|
|
|
20
20
|
if (!parsed) return null;
|
|
21
21
|
const topic = byLegacyKey.get(parsed.legacyKey);
|
|
22
22
|
if (!topic) return null;
|
|
23
|
-
const row = db.get('SELECT id FROM tasks WHERE
|
|
23
|
+
const row = db.get('SELECT id FROM tasks WHERE repo_topic_id = :t AND seq = :s', { t: topic.id, s: parsed.seq });
|
|
24
24
|
return row ? row.id : null;
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -93,7 +93,7 @@ export function importStandaloneGoals(
|
|
|
93
93
|
report.warnings.push({ what: 'goal', why: '作用域里的队列对不上,已丢弃', scope });
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
|
-
const taskRow = db.get('SELECT id, claimed_at, created_at FROM tasks WHERE
|
|
96
|
+
const taskRow = db.get('SELECT id, claimed_at, created_at FROM tasks WHERE repo_topic_id = :t AND seq = :s', {
|
|
97
97
|
t: topic.id,
|
|
98
98
|
s: parsed.seq,
|
|
99
99
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// legacy 的 type(ref / dev)不是新 schema 的二分(repo/group),存 ext 取证。
|
|
5
5
|
import { groupKeyOf } from '../../keys.js';
|
|
6
6
|
import { anyTimeMs } from '../time.js';
|
|
7
|
-
import {
|
|
7
|
+
import { jsonText, stringOrNull } from './data.js';
|
|
8
8
|
import type { ImportReport } from './data.js';
|
|
9
9
|
import type { DbApi } from '../driver.js';
|
|
10
10
|
|
|
@@ -16,33 +16,12 @@ export interface ImportReposResult {
|
|
|
16
16
|
boardNames: string[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/** 哨兵仓库必须**永远在场**:topics.repo_key 是 NOT NULL 外键,没有它连一条队列都建不出来。
|
|
20
|
-
* 幂等(已存在跳过)。bootstrap 在建表后无条件调用 —— 与「有没有 legacy JSON」无关。 */
|
|
21
|
-
export function ensureSentinelRepo(db: DbApi, atMs: number, report: ImportReport = emptyReport()): void {
|
|
22
|
-
const exists = db.get('SELECT key FROM repos WHERE key = :k', { k: SENTINEL_REPO_KEY });
|
|
23
|
-
if (exists) return;
|
|
24
|
-
db.run(
|
|
25
|
-
`INSERT INTO repos (key, type, name, description, path, remote, sort_order, ext, state, version,
|
|
26
|
-
deleted_at, created_at, updated_at)
|
|
27
|
-
VALUES (:key, 'repo', :name, :desc, '', '', -1, :ext, '', 0, NULL, :at, :at)`,
|
|
28
|
-
{
|
|
29
|
-
key: SENTINEL_REPO_KEY,
|
|
30
|
-
name: SENTINEL_REPO_NAME,
|
|
31
|
-
desc: '迁移时承载"对不上真实仓库"的队列与全局池;不是用户登记的仓库(面板默认隐藏)',
|
|
32
|
-
ext: jsonText({ ext_sentinel: 1 }),
|
|
33
|
-
at: atMs,
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
report.imported.repos += 1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
19
|
export function importRepos(db: DbApi, reposData: any, atMs: number, report: ImportReport): ImportReposResult {
|
|
40
20
|
const repos = Array.isArray(reposData && reposData.repos) ? reposData.repos : [];
|
|
41
21
|
const boards = Array.isArray(reposData && reposData.boards) ? reposData.boards : [];
|
|
42
22
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const seen = new Set([SENTINEL_REPO_KEY]);
|
|
23
|
+
// #197:不再创建哨兵仓库——队列必须绑真实仓库(cwd 匹配或自动登记)
|
|
24
|
+
const seen = new Set<string>();
|
|
46
25
|
const legacyIdToKey = new Map<string, string>(); // 旧 r_xxx → 新 key
|
|
47
26
|
const boardLegacyIdToKey = new Map<string, string>(); // 旧 b_xxx → 组 key
|
|
48
27
|
|
|
@@ -8,8 +8,34 @@ import {
|
|
|
8
8
|
numberOrNull,
|
|
9
9
|
stringOrNull,
|
|
10
10
|
MAX_BODY,
|
|
11
|
-
SENTINEL_REPO_KEY,
|
|
12
11
|
} from './data.js';
|
|
12
|
+
import { matchRepoKey, autoRepoKey } from '../repo-match.js';
|
|
13
|
+
// ── 一次性迁移用的最小 frontmatter 读/剥(#197 起任务正文不再有 --- 头)──
|
|
14
|
+
// 这段逻辑**冻结在本文件**:迁移/导入是处理历史数据的唯一入口,跑完即退役;
|
|
15
|
+
// 运行时(服务层/前端)已无任何 frontmatter 读/剥(shared/frontmatter.ts 已删除)。
|
|
16
|
+
// 与历史版本 shared/frontmatter.ts 同口径;不要再抽公共模块——那会让「已删除的
|
|
17
|
+
// frontmatter」在代码里长期存在。
|
|
18
|
+
const FM_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
19
|
+
const FM_KV_RE = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/;
|
|
20
|
+
function parseFrontmatter(src: unknown): Record<string, string> {
|
|
21
|
+
const m = String(src ?? '').match(FM_RE);
|
|
22
|
+
if (!m) return {};
|
|
23
|
+
const out: Record<string, string> = {};
|
|
24
|
+
for (const line of (m[1] ?? '').split(/\r?\n/)) {
|
|
25
|
+
const kv = line.match(FM_KV_RE);
|
|
26
|
+
if (kv) out[kv[1] ?? ''] = (kv[2] ?? '').trim();
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
function stripFrontmatter(src: unknown): string {
|
|
31
|
+
return String(src ?? '').replace(FM_RE, (block: string, inner: string) => {
|
|
32
|
+
const kv = String(inner || '').split(/\r?\n/).some((l) => FM_KV_RE.test(l));
|
|
33
|
+
return kv ? '' : block;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fmOf = parseFrontmatter;
|
|
38
|
+
const stripFm = stripFrontmatter;
|
|
13
39
|
import type { ImportReport } from './data.js';
|
|
14
40
|
import type { DbApi } from '../driver.js';
|
|
15
41
|
|
|
@@ -62,6 +88,12 @@ export function importTopicsAndTasks(
|
|
|
62
88
|
? localtasksData.topics
|
|
63
89
|
: {};
|
|
64
90
|
|
|
91
|
+
/** #197:队列必须绑真实仓库——导入时按 cwd 匹配已登记的;匹配不到且目录还在就自动登记。 */
|
|
92
|
+
const realRepos: Array<{ key: string; path: string }> = db
|
|
93
|
+
.all("SELECT key, path FROM repos WHERE type = 'repo' AND path <> ''")
|
|
94
|
+
.map((r: any) => ({ key: String(r.key), path: String(r.path) }));
|
|
95
|
+
const takenRepos = new Set<string>(db.all('SELECT key FROM repos').map((r: any) => String(r.key)));
|
|
96
|
+
|
|
65
97
|
/** legacy topic key → { id, legacyKey } */
|
|
66
98
|
const byLegacyKey = new Map<string, LegacyTopicRef>();
|
|
67
99
|
/** 新 key → topic 行(碰撞时合并到同一行) */
|
|
@@ -103,13 +135,26 @@ export function importTopicsAndTasks(
|
|
|
103
135
|
if (topic.manual) ext.ext_manual = 1;
|
|
104
136
|
|
|
105
137
|
const createdAt = anyTimeMs(topic.createdAt, atMs);
|
|
138
|
+
// 归属仓库:cwd 匹配已登记仓库;匹配不到且目录还在 → 自动登记(local/<目录名>)
|
|
139
|
+
let repoKey = matchRepoKey(cwd, realRepos);
|
|
140
|
+
if (!repoKey) {
|
|
141
|
+
repoKey = autoRepoKey(cwd, takenRepos);
|
|
142
|
+
takenRepos.add(repoKey);
|
|
143
|
+
db.run(
|
|
144
|
+
`INSERT INTO repos (key, type, name, description, path, remote, sort_order, ext, state, version,
|
|
145
|
+
deleted_at, created_at, updated_at)
|
|
146
|
+
VALUES (:key, 'repo', :name, '', :path, '', 0, '{}', '', 0, NULL, :at, :at)`,
|
|
147
|
+
{ key: repoKey, name: repoKey.slice('local/'.length), path: cwd, at: createdAt },
|
|
148
|
+
);
|
|
149
|
+
realRepos.push({ key: repoKey, path: cwd });
|
|
150
|
+
}
|
|
106
151
|
const res = db.run(
|
|
107
152
|
`INSERT INTO topics (key, repo_key, cwd, group_key, name, next_seq, ext, state, version,
|
|
108
153
|
deleted_at, created_at, updated_at)
|
|
109
154
|
VALUES (:key, :repo, :cwd, NULL, :name, 1, :ext, :state, :version, NULL, :created, :updated)`,
|
|
110
155
|
{
|
|
111
156
|
key,
|
|
112
|
-
repo:
|
|
157
|
+
repo: repoKey,
|
|
113
158
|
cwd,
|
|
114
159
|
name: String(topic.name || ''),
|
|
115
160
|
ext: jsonText(ext),
|
|
@@ -173,6 +218,34 @@ export function importTopicsAndTasks(
|
|
|
173
218
|
return { byLegacyKey, byNewKey };
|
|
174
219
|
}
|
|
175
220
|
|
|
221
|
+
/** legacy board id(b_xxx)→ 组的 repos.key(走 ext_legacy_id)。 */
|
|
222
|
+
function boardKeyOfLegacyId(db: DbApi, boardId: string): string {
|
|
223
|
+
for (const g of db.all("SELECT key, ext FROM repos WHERE type = 'group'")) {
|
|
224
|
+
try {
|
|
225
|
+
if (String(JSON.parse(String(g.ext || '{}')).ext_legacy_id || '') === boardId) return String(g.key);
|
|
226
|
+
} catch {
|
|
227
|
+
/* 坏 ext 跳过 */
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** 找/建组 topic(key = group:<组key>,cwd 空,repo_key 指向组行)。 */
|
|
234
|
+
function ensureGroupTopicRow(db: DbApi, groupKey: string, atMs: number): number | null {
|
|
235
|
+
const key = `group:${groupKey}`;
|
|
236
|
+
const hit = db.get('SELECT id FROM topics WHERE key = :k', { k: key });
|
|
237
|
+
if (hit) return Number(hit.id);
|
|
238
|
+
const g = db.get('SELECT name FROM repos WHERE key = :k', { k: groupKey });
|
|
239
|
+
db.run(
|
|
240
|
+
`INSERT INTO topics (key, repo_key, cwd, group_key, name, next_seq, ext, state, version,
|
|
241
|
+
deleted_at, created_at, updated_at)
|
|
242
|
+
VALUES (:key, :repo, '', :group, :name, 1, '{}', '', 0, NULL, :at, :at)`,
|
|
243
|
+
{ key, repo: groupKey, group: groupKey, name: String((g && g.name) || groupKey), at: atMs },
|
|
244
|
+
);
|
|
245
|
+
const created = db.get('SELECT id FROM topics WHERE key = :k', { k: key });
|
|
246
|
+
return created ? Number(created.id) : null;
|
|
247
|
+
}
|
|
248
|
+
|
|
176
249
|
function insertTask(db: DbApi, { row, legacyKey, task, atMs, report }: InsertTaskParams): void {
|
|
177
250
|
const mapped = mapLegacyStatus(task);
|
|
178
251
|
report.distribution[mapped.status] = (report.distribution[mapped.status] || 0) + 1;
|
|
@@ -266,17 +339,29 @@ function insertTask(db: DbApi, { row, legacyKey, task, atMs, report }: InsertTas
|
|
|
266
339
|
report.warnings.push({ what: 'task.roundSummary', why: `状态 ${mapped.status} 但有非空 roundSummary,已存 ext`, key: legacyKey, id: seq });
|
|
267
340
|
}
|
|
268
341
|
|
|
342
|
+
// #197:正文里的 board/project 在本步转成库内关联(组 topic + 剥正文头),
|
|
343
|
+
// 导入直接产出 v17 结构,不再依赖导入后再跑一次归一。
|
|
344
|
+
const fmFm = fmOf(body);
|
|
345
|
+
let groupTopicId: number | null = null;
|
|
346
|
+
const boardId = String(fmFm.board || '').trim();
|
|
347
|
+
if (boardId) {
|
|
348
|
+
const gk = boardKeyOfLegacyId(db, boardId);
|
|
349
|
+
if (gk) groupTopicId = ensureGroupTopicRow(db, gk, atMs);
|
|
350
|
+
}
|
|
351
|
+
if (Object.keys(fmFm).length) body = stripFm(body);
|
|
352
|
+
|
|
269
353
|
const round = (Number(task.reopenCount) || 0) + 1;
|
|
270
354
|
if (task.reopenCount) report.discarded.push({ what: 'task.reopenCount', key: legacyKey, id: seq, count: 1, note: '→ round = reopenCount+1' });
|
|
271
355
|
|
|
272
356
|
db.run(
|
|
273
|
-
`INSERT INTO tasks (
|
|
274
|
-
from_src, blocks_following, claimed_at, done_at,
|
|
275
|
-
created_at, updated_at)
|
|
276
|
-
VALUES (:topic, :seq, '', :status, 0, :body, :ext, :feedback, :feedbackAt,
|
|
357
|
+
`INSERT INTO tasks (repo_topic_id, group_topic_id, seq, type, status, version, body, ext,
|
|
358
|
+
feedback, feedback_at, from_src, blocks_following, claimed_at, done_at,
|
|
359
|
+
round, deleted_at, created_at, updated_at)
|
|
360
|
+
VALUES (:topic, :gtid, :seq, '', :status, 0, :body, :ext, :feedback, :feedbackAt,
|
|
277
361
|
:from, :blocks, :claimedAt, :doneAt, :round, :deletedAt, :createdAt, :updatedAt)`,
|
|
278
362
|
{
|
|
279
363
|
topic: row.id,
|
|
364
|
+
gtid: groupTopicId,
|
|
280
365
|
seq,
|
|
281
366
|
status: mapped.status,
|
|
282
367
|
body,
|
|
@@ -309,7 +394,7 @@ function insertGoal(
|
|
|
309
394
|
db: DbApi,
|
|
310
395
|
{ topicId, seq, legacyKey, timegoal, claimedAt, createdAt, report }: InsertGoalParams
|
|
311
396
|
): void {
|
|
312
|
-
const taskRow = db.get('SELECT id FROM tasks WHERE
|
|
397
|
+
const taskRow = db.get('SELECT id FROM tasks WHERE repo_topic_id = :t AND seq = :s', { t: topicId, s: seq });
|
|
313
398
|
if (!taskRow) return;
|
|
314
399
|
let durationSec = legacyDurationSec(timegoal);
|
|
315
400
|
const startedAt = anyTimeMs(timegoal.startedAt, NaN);
|
|
@@ -73,7 +73,6 @@ export {
|
|
|
73
73
|
refIdOf,
|
|
74
74
|
} from './import-json/data.js';
|
|
75
75
|
export { scanLegacy } from './import-json/scan.js';
|
|
76
|
-
export { ensureSentinelRepo } from './import-json/repos.js';
|
|
77
76
|
export { listDocFiles } from './import-json/refs.js';
|
|
78
77
|
|
|
79
78
|
/** importLegacy 的选项。 */
|
|
@@ -119,7 +118,7 @@ function validateImport(
|
|
|
119
118
|
for (const t of topics) {
|
|
120
119
|
const expect = topicKeyOf(t.cwd, t.group_key || '');
|
|
121
120
|
if (expect !== t.key) problems.push(`队列 ${t.id} 的 key 不是 (cwd,group) 的派生值`);
|
|
122
|
-
const row = conn.get('SELECT max(seq) AS m, count(*) AS c FROM tasks WHERE
|
|
121
|
+
const row = conn.get('SELECT max(seq) AS m, count(*) AS c FROM tasks WHERE repo_topic_id = :id', { id: t.id });
|
|
123
122
|
const maxSeq = Number((row && row.m) || 0);
|
|
124
123
|
const cnt = Number((row && row.c) || 0);
|
|
125
124
|
if (cnt > 0 && Number(t.next_seq) <= maxSeq) {
|
|
@@ -19,6 +19,8 @@ import { migrateGroupRefs } from './v4-data.js';
|
|
|
19
19
|
import { migrateRefsBodies } from './v6-data.js';
|
|
20
20
|
import { migrateRefsRel } from './v8-data.js';
|
|
21
21
|
import { migrateOrphanRefs } from './v11-data.js';
|
|
22
|
+
import { migrateAssignmentsToColumns } from './v16-data.js';
|
|
23
|
+
import { migrateTopicLinks } from './v17-data.js';
|
|
22
24
|
import { CURRENT_SCHEMA_VERSION } from '../version.js';
|
|
23
25
|
import type { DbApi } from '../driver.js';
|
|
24
26
|
|
|
@@ -66,6 +68,8 @@ export const DIRECT_EDGES: MigrationStep[] = [
|
|
|
66
68
|
{ from: 12, to: 13, file: 'v13.sql', title: '去掉关系表上的业务 note(4 张表 drop note 列)' },
|
|
67
69
|
{ from: 13, to: 14, file: 'v14.sql', title: 'task_links.type 扩 fork(任务链四类节点:评论/反馈/重开/分支)' },
|
|
68
70
|
{ from: 14, to: 15, file: 'v15.sql', title: "附件新增 repo 类型(参考仓库指针,不复制字节;重建 attachments 扩 CHECK)" },
|
|
71
|
+
{ from: 15, to: 16, file: 'v16.sql', title: '任务归属落库第一步(tasks.repo_key + topics.group_key,删 frontmatter #197)', apply: migrateAssignmentsToColumns },
|
|
72
|
+
{ from: 16, to: 17, file: 'v17.sql', title: '任务归属规范成两条 topic 关联(repo_topic_id + group_topic_id #197)', apply: migrateTopicLinks },
|
|
69
73
|
];
|
|
70
74
|
|
|
71
75
|
// 人读版本说明(docs/decisions 是决策的唯一权威位置,里面对应一份 date 化的 .md)
|
|
@@ -85,6 +89,8 @@ export const VERSION_NOTES = {
|
|
|
85
89
|
13: 'docs/decisions/versions/2026-11-17-v13.md',
|
|
86
90
|
14: 'docs/decisions/versions/2026-11-22-v14.md',
|
|
87
91
|
15: 'docs/decisions/versions/2026-11-23-v15.md',
|
|
92
|
+
16: 'docs/decisions/versions/2026-11-24-v16.md',
|
|
93
|
+
17: 'docs/decisions/versions/2026-11-24-v17.md',
|
|
88
94
|
};
|
|
89
95
|
|
|
90
96
|
const keyOf = (from: number, to: number): string => `${from}->${to}`;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// schema v15 → v16 的数据迁移(与 v16.sql 同一事务执行):#197 第一步
|
|
2
|
+
//
|
|
3
|
+
// 把正文 frontmatter 的归属搬进库内列:
|
|
4
|
+
// 1. 哨兵队列重绑:repo_key='__unbound__' 的 topic 按 cwd 匹配已登记仓库;
|
|
5
|
+
// 匹配不到就自动登记 local/<目录名>——绝不因为「找不到归属」丢任务。
|
|
6
|
+
// 2. frontmatter → 列:project → tasks.repo_key;board → 拆 (cwd, group_key) 组队列;
|
|
7
|
+
// 然后剥掉正文 --- 头。
|
|
8
|
+
// 3. 补齐 repo_key、删除哨兵仓库行。
|
|
9
|
+
//
|
|
10
|
+
// 本步骤已在 2026-11-24 应用到本机库(user_version=16),**逻辑不可再改**;
|
|
11
|
+
// 更彻底的归属规范(repo_topic_id / group_topic_id 两条关联)在 v17 做。
|
|
12
|
+
import { matchRepoKey, autoRepoKey } from '../repo-match.js';
|
|
13
|
+
// frontmatter 读/剥收拢到 core/task-frontmatter(#200);core 不能依赖 shared,同名别名承接
|
|
14
|
+
// ── 一次性迁移用的最小 frontmatter 读/剥(#197 起任务正文不再有 --- 头)──
|
|
15
|
+
// 这段逻辑**冻结在本文件**:迁移/导入是处理历史数据的唯一入口,跑完即退役;
|
|
16
|
+
// 运行时(服务层/前端)已无任何 frontmatter 读/剥(shared/frontmatter.ts 已删除)。
|
|
17
|
+
// 与历史版本 shared/frontmatter.ts 同口径;不要再抽公共模块——那会让「已删除的
|
|
18
|
+
// frontmatter」在代码里长期存在。
|
|
19
|
+
const FM_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
20
|
+
const FM_KV_RE = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/;
|
|
21
|
+
function parseFrontmatter(src: unknown): Record<string, string> {
|
|
22
|
+
const m = String(src ?? '').match(FM_RE);
|
|
23
|
+
if (!m) return {};
|
|
24
|
+
const out: Record<string, string> = {};
|
|
25
|
+
for (const line of (m[1] ?? '').split(/\r?\n/)) {
|
|
26
|
+
const kv = line.match(FM_KV_RE);
|
|
27
|
+
if (kv) out[kv[1] ?? ''] = (kv[2] ?? '').trim();
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function stripFrontmatter(src: unknown): string {
|
|
32
|
+
return String(src ?? '').replace(FM_RE, (block: string, inner: string) => {
|
|
33
|
+
const kv = String(inner || '').split(/\r?\n/).some((l) => FM_KV_RE.test(l));
|
|
34
|
+
return kv ? '' : block;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
import { topicKeyOf } from '../../topic-key.js';
|
|
39
|
+
|
|
40
|
+
export interface V16Context {
|
|
41
|
+
atMs?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface V16Result {
|
|
45
|
+
rebound: number;
|
|
46
|
+
autoRepo: number;
|
|
47
|
+
droppedTopic: number;
|
|
48
|
+
stripped: number;
|
|
49
|
+
moved: number;
|
|
50
|
+
sentinelRemoved: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function normalizeAssignments(
|
|
54
|
+
conn: any,
|
|
55
|
+
{ atMs = Date.now() }: V16Context = {},
|
|
56
|
+
): V16Result {
|
|
57
|
+
const result: V16Result = { rebound: 0, autoRepo: 0, droppedTopic: 0, stripped: 0, moved: 0, sentinelRemoved: 0 };
|
|
58
|
+
|
|
59
|
+
// ── 1. 哨兵队列重绑 ──
|
|
60
|
+
const realRepos: Array<{ key: string; path: string }> = conn
|
|
61
|
+
.all("SELECT key, path FROM repos WHERE type = 'repo' AND path <> '' AND key <> '__unbound__'")
|
|
62
|
+
.map((r: any) => ({ key: String(r.key), path: String(r.path) }));
|
|
63
|
+
const takenKeys = new Set<string>(conn.all('SELECT key FROM repos').map((r: any) => String(r.key)));
|
|
64
|
+
const sentinels = conn.all("SELECT id, key, cwd, name FROM topics WHERE repo_key = '__unbound__'");
|
|
65
|
+
for (const t of sentinels) {
|
|
66
|
+
const tid = Number(t.id);
|
|
67
|
+
const cwd = String(t.cwd || '');
|
|
68
|
+
const matched = matchRepoKey(cwd, realRepos);
|
|
69
|
+
if (matched) {
|
|
70
|
+
conn.run('UPDATE topics SET repo_key = :rk, updated_at = :at WHERE id = :id', { rk: matched, at: atMs, id: tid });
|
|
71
|
+
result.rebound += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (!cwd) {
|
|
75
|
+
conn.run('DELETE FROM topics WHERE id = :id', { id: tid });
|
|
76
|
+
result.droppedTopic += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const key = autoRepoKey(cwd, takenKeys);
|
|
80
|
+
takenKeys.add(key);
|
|
81
|
+
conn.run(
|
|
82
|
+
`INSERT INTO repos (key, type, name, description, path, remote, sort_order, ext, state, version,
|
|
83
|
+
deleted_at, created_at, updated_at)
|
|
84
|
+
VALUES (:key, 'repo', :name, '', :path, '', 0, '{}', '', 0, NULL, :at, :at)`,
|
|
85
|
+
{ key, name: key.slice('local/'.length), path: cwd, at: atMs },
|
|
86
|
+
);
|
|
87
|
+
realRepos.push({ key, path: cwd });
|
|
88
|
+
conn.run('UPDATE topics SET repo_key = :rk, updated_at = :at WHERE id = :id', { rk: key, at: atMs, id: tid });
|
|
89
|
+
result.autoRepo += 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── 2. board id(b_xxx)→ 组 repos.key ──
|
|
93
|
+
const groupByBoard = new Map<string, string>();
|
|
94
|
+
for (const g of conn.all("SELECT key, ext FROM repos WHERE type = 'group'")) {
|
|
95
|
+
let legacy = '';
|
|
96
|
+
try {
|
|
97
|
+
legacy = String(JSON.parse(String(g.ext || '{}')).ext_legacy_id || '');
|
|
98
|
+
} catch {
|
|
99
|
+
legacy = '';
|
|
100
|
+
}
|
|
101
|
+
if (legacy) groupByBoard.set(legacy, String(g.key));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ── 3. 逐 task:frontmatter → repo_key / 组队列,剥正文头 ──
|
|
105
|
+
const tasks = conn.all('SELECT id, topic_id, body FROM tasks');
|
|
106
|
+
for (const task of tasks) {
|
|
107
|
+
const body = String(task.body || '');
|
|
108
|
+
const fm = parseFrontmatter(body);
|
|
109
|
+
if (!Object.keys(fm).length) continue;
|
|
110
|
+
|
|
111
|
+
const clean = stripFrontmatter(body);
|
|
112
|
+
conn.run('UPDATE tasks SET body = :b WHERE id = :id', { b: clean, id: Number(task.id) });
|
|
113
|
+
result.stripped += 1;
|
|
114
|
+
|
|
115
|
+
const topic = conn.get('SELECT id, key, cwd, name, repo_key FROM topics WHERE id = :id', { id: Number(task.topic_id) });
|
|
116
|
+
if (!topic) continue;
|
|
117
|
+
|
|
118
|
+
const projectKey = String(fm.project || '').trim();
|
|
119
|
+
const repoKey = projectKey && conn.get('SELECT 1 AS ok FROM repos WHERE key = :k', { k: projectKey })
|
|
120
|
+
? projectKey
|
|
121
|
+
: String(topic.repo_key || '');
|
|
122
|
+
|
|
123
|
+
const boardId = String(fm.board || '').trim();
|
|
124
|
+
const groupKey = boardId ? groupByBoard.get(boardId) || '' : '';
|
|
125
|
+
|
|
126
|
+
if (groupKey) {
|
|
127
|
+
// 组任务拆到 (cwd, group_key) 独立队列
|
|
128
|
+
const cwd = String(topic.cwd || '');
|
|
129
|
+
const newKey = topicKeyOf(cwd, groupKey);
|
|
130
|
+
let host = conn.get('SELECT id FROM topics WHERE key = :k', { k: newKey });
|
|
131
|
+
if (!host) {
|
|
132
|
+
conn.run(
|
|
133
|
+
`INSERT INTO topics (key, repo_key, cwd, group_key, name, next_seq, ext, state, version,
|
|
134
|
+
deleted_at, created_at, updated_at)
|
|
135
|
+
VALUES (:key, :repo, :cwd, :group, :name, 1, '{}', '', 0, NULL, :at, :at)`,
|
|
136
|
+
{ key: newKey, repo: repoKey, cwd, group: groupKey, name: String(topic.name || ''), at: atMs },
|
|
137
|
+
);
|
|
138
|
+
host = conn.get('SELECT id FROM topics WHERE key = :k', { k: newKey });
|
|
139
|
+
}
|
|
140
|
+
conn.run('UPDATE tasks SET topic_id = :tid, repo_key = :rk WHERE id = :id', {
|
|
141
|
+
tid: Number(host.id), rk: repoKey, id: Number(task.id),
|
|
142
|
+
});
|
|
143
|
+
result.moved += 1;
|
|
144
|
+
} else {
|
|
145
|
+
conn.run('UPDATE tasks SET repo_key = :rk WHERE id = :id', { rk: repoKey, id: Number(task.id) });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ── 4. 非组任务补齐 repo_key ──
|
|
150
|
+
conn.run(
|
|
151
|
+
`UPDATE tasks SET repo_key = (SELECT repo_key FROM topics t WHERE t.id = tasks.topic_id)
|
|
152
|
+
WHERE repo_key = '' AND EXISTS (SELECT 1 FROM topics t WHERE t.id = tasks.topic_id)`,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** v15 → v16:先归一归属,再删哨兵仓库行。 */
|
|
159
|
+
export function migrateAssignmentsToColumns(
|
|
160
|
+
conn: any,
|
|
161
|
+
ctx: V16Context = {},
|
|
162
|
+
): V16Result {
|
|
163
|
+
const result = normalizeAssignments(conn, ctx);
|
|
164
|
+
const del = conn.run("DELETE FROM repos WHERE key = '__unbound__'");
|
|
165
|
+
result.sentinelRemoved = Number(del.changes) || 0;
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- schema v16:任务归属落库,删除正文 frontmatter(#197 第一步)
|
|
2
|
+
--
|
|
3
|
+
-- 把「属于哪个组 / 哪个仓库」从正文 frontmatter 搬进库内列:
|
|
4
|
+
-- · tasks.repo_key 归属仓库(替代 frontmatter.project)
|
|
5
|
+
-- · topics.group_key 组上下文——组任务拆到 (cwd, group_key) 独立队列
|
|
6
|
+
-- 正文只留 markdown。
|
|
7
|
+
--
|
|
8
|
+
-- 数据迁移在 v16-data.ts(同一事务)。
|
|
9
|
+
-- 注:v17 会把这里的 repo_key / group_key 进一步规范成两条 topic 关联
|
|
10
|
+
-- (repo_topic_id + group_topic_id),见 docs/decisions/versions/2026-11-24-v17.md。
|
|
11
|
+
--
|
|
12
|
+
-- 本步骤已在 2026-11-24 应用到本机库(user_version=16),**内容不可再改**。
|
|
13
|
+
--
|
|
14
|
+
-- @decision docs/decisions/versions/2026-11-24-v16.md
|
|
15
|
+
ALTER TABLE tasks ADD COLUMN repo_key TEXT NOT NULL DEFAULT '';
|