nx-kv 0.68.3 → 0.69.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 +62 -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 +8 -0
- package/src/core/db/migrations/v16-data.ts +166 -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/migrations/v18.sql +24 -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 +7 -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-add.ts +4 -4
- package/src/modules/localtask/actions/localtask-boardtasks.ts +40 -40
- 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 +82 -4
- 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 +17 -2
- package/src/web/frontend/api/client.generated.ts +12 -4
- 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/attachments/attach-modal.tsx +1 -1
- package/src/web/frontend/components/md/hooks/use-live-preview.ts +1 -1
- package/src/web/frontend/components/md/model/divider/index.ts +0 -3
- package/src/web/frontend/components/md/panes/live-block.tsx +3 -11
- package/src/web/frontend/components/md/panes/md-panes-helpers.ts +1 -3
- 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/md/styles/editor.css +0 -26
- 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-C20VCKMu.js} +1 -1
- package/src/web/public/assets/composer-panel-C3ET4SBT.js +1 -0
- package/src/web/public/assets/dag-xQRISqLX.js +1 -0
- package/src/web/public/assets/{dir-C8HhVpFz.js → dir-B-UPu7OY.js} +1 -1
- package/src/web/public/assets/{doc-DgYKv2wo.css → doc-Ka-2V5jn.css} +1 -1
- package/src/web/public/assets/doc-zDLeR8PE.js +6 -0
- package/src/web/public/assets/group-Hh-NL_sa.js +1 -0
- package/src/web/public/assets/{index-CUnLXQWJ.css → index-DXJxcKIU.css} +1 -1
- package/src/web/public/assets/index-Di6ErKBG.js +3 -0
- package/src/web/public/assets/md-history-B7TamGno.js +45 -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-C6rZJhnb.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-DpwLdBYp.js +1 -0
- package/src/web/public/assets/repos-BjVw1SQ2.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-C1NfJqNk.js} +1 -1
- package/src/web/public/assets/{task-j7fMfJUp.css → task-Dcd2eA8B.css} +1 -1
- package/src/web/public/assets/task-Ddr-iU14.js +14 -0
- package/src/web/public/assets/task-ops-s9kkuLcK.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-BnEJVU91.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-4iK6t5ab.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
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 为什么需要这条(而不是让端侧自己拼):
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
5
|
+
// #197 起组归属是**库内关联**:tasks.group_topic_id → 组队列 topic。
|
|
6
|
+
// 本命令直接 SQL 查 `WHERE gtp.group_key = ?` 一次取完(走 ix_tasks_group 索引),
|
|
7
|
+
// 不再全量拉任务 + 逐条解析正文 frontmatter。
|
|
8
|
+
//
|
|
9
|
+
// 端侧(fr 手机界面)不持有全量主题快照:
|
|
9
10
|
//
|
|
10
11
|
// · 逐个成员队列去问 → 28 个队列 28 次请求,每次服务端还要把整份 store 读一遍;
|
|
11
12
|
// · 去拉 /api/localtasks → 每个任务都带正文,一次几 MB(端侧只画 30 字标题)。
|
|
@@ -19,10 +20,9 @@
|
|
|
19
20
|
import { action } from '../../../runtime/action-decorator.js';
|
|
20
21
|
import { z } from 'zod';
|
|
21
22
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
22
|
-
import * as serviceNs from '../service.js';
|
|
23
23
|
import * as boardsNs from '../../repos/boards.js';
|
|
24
|
+
import { db } from '../infra/repo/index.js';
|
|
24
25
|
|
|
25
|
-
const service: any = serviceNs;
|
|
26
26
|
const boardsSvc: any = boardsNs;
|
|
27
27
|
|
|
28
28
|
/** localtask.boardtasks 的入参契约:不给 board = 全部组。 */
|
|
@@ -49,7 +49,7 @@ const taskRow = z.object({
|
|
|
49
49
|
const output = z.object({
|
|
50
50
|
boards: z.array(
|
|
51
51
|
z.object({
|
|
52
|
-
id: z.string().describe('看板 id
|
|
52
|
+
id: z.string().describe('看板 id(组队列 topic 的 group_key,组页建任务时落库关联的就是它)'),
|
|
53
53
|
key: z.string().describe('看板键(board/xxx)'),
|
|
54
54
|
name: z.string().describe('看板名称'),
|
|
55
55
|
pending: z.int().describe('本组待领取数(= side bar 徽标口径)'),
|
|
@@ -59,6 +59,12 @@ const output = z.object({
|
|
|
59
59
|
),
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
/** epoch ms → 时间戳串(与任务视图同格式:YYYY-MM-DD HH:MM:SS)。 */
|
|
63
|
+
function stampOf(ms: unknown): string {
|
|
64
|
+
const n = Number(ms);
|
|
65
|
+
return Number.isFinite(n) && n > 0 ? new Date(n).toISOString().replace('T', ' ').slice(0, 19) : '';
|
|
66
|
+
}
|
|
67
|
+
|
|
62
68
|
/** 取正文里的标题:跳过 frontmatter,首个 `#` 标题优先,否则首行;按 80 字截断。 */
|
|
63
69
|
function titleOf(text: unknown): string {
|
|
64
70
|
const raw = String(text ?? '');
|
|
@@ -104,40 +110,34 @@ export class LocaltaskBoardTasksAction extends ActionBase<typeof input> {
|
|
|
104
110
|
throw badInput(`项目组不存在: ${want}`);
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
const
|
|
108
|
-
const topics: any[] = (list.topics ?? []) as any[];
|
|
109
|
-
|
|
113
|
+
const conn = db();
|
|
110
114
|
const boards = picked.map((b) => {
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
roundSummary: x.roundSummary ?? '',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
115
|
+
// #197:组任务 = group_topic_id 指向「本组队列」的任务(一条 SQL,走索引)
|
|
116
|
+
const rows: any[] = conn
|
|
117
|
+
.all(
|
|
118
|
+
`SELECT t.seq, t.status, t.round, t.body, t.created_at AS createdAtMs,
|
|
119
|
+
t.claimed_at AS claimedAtMs, t.done_at AS doneAtMs, t.feedback,
|
|
120
|
+
rtp.key AS topicKey, rtp.name AS topicName
|
|
121
|
+
FROM tasks t
|
|
122
|
+
JOIN topics gtp ON gtp.id = t.group_topic_id
|
|
123
|
+
JOIN topics rtp ON rtp.id = t.repo_topic_id
|
|
124
|
+
WHERE gtp.group_key = :gk AND t.deleted_at IS NULL AND rtp.deleted_at IS NULL`,
|
|
125
|
+
{ gk: String(b.key) },
|
|
126
|
+
)
|
|
127
|
+
.map((r: any) => ({
|
|
128
|
+
id: Number(r.seq),
|
|
129
|
+
status: String(r.status),
|
|
130
|
+
title: titleOf(r.body),
|
|
131
|
+
round: Number(r.round) || 1,
|
|
132
|
+
ready: String(r.status) === 'pending',
|
|
133
|
+
project: String(r.topicName || r.topicKey),
|
|
134
|
+
topicKey: String(r.topicKey),
|
|
135
|
+
createdAt: stampOf(r.createdAtMs),
|
|
136
|
+
consumedAt: stampOf(r.claimedAtMs),
|
|
137
|
+
completedAt: stampOf(r.doneAtMs),
|
|
138
|
+
claimedByName: '',
|
|
139
|
+
roundSummary: String(r.feedback || ''),
|
|
140
|
+
}));
|
|
141
141
|
// 待领在前、其余按编号倒序:组页最想看的是「还有什么没干」
|
|
142
142
|
rows.sort((a, b) => Number(b.status === 'pending') - Number(a.status === 'pending') || a.id - b.id);
|
|
143
143
|
return {
|
|
@@ -17,6 +17,9 @@ const input = z.object({
|
|
|
17
17
|
feedback: z.string().optional().describe("用户反馈原文;派生出的新任务正文会追加 [!WARNING] 验收反馈 callout(base = 服务端最新正文,防连续评论丢内容)"),
|
|
18
18
|
feedbackHeading: z.string().optional().describe("反馈段形态:comment=旧段名 ## 反馈修改(不进轮次);reopen=轮次 callout([!NOTE] 完成总结 + [!WARNING] 验收反馈,标题含轮次号)"),
|
|
19
19
|
feedbackBold: z.boolean().optional().describe("追加的反馈是否逐行加粗(缺省 comment=false / reopen=true)"),
|
|
20
|
+
// #197:归属改由显式参数给出(不再改正文 frontmatter)
|
|
21
|
+
project: z.string().optional().describe("改归属项目(仓库 key / 名称 / 路径)——派生出的新任务落该仓库队列"),
|
|
22
|
+
board: z.string().optional().describe("改归属组(组 id / key / 名称)"),
|
|
20
23
|
});
|
|
21
24
|
|
|
22
25
|
export class LocaltaskReopenAction extends ActionBase<typeof input> {
|
|
@@ -41,6 +44,8 @@ export class LocaltaskReopenAction extends ActionBase<typeof input> {
|
|
|
41
44
|
key: ctx.key,
|
|
42
45
|
text: ctx.text,
|
|
43
46
|
kind: ctx.kind,
|
|
47
|
+
project: ctx.project,
|
|
48
|
+
board: ctx.board,
|
|
44
49
|
quote: ctx.quote,
|
|
45
50
|
feedback: ctx.feedback,
|
|
46
51
|
feedbackHeading: ctx.feedbackHeading,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// localtask.sync-queues —— 补齐仓库 / 组缺的队列 topic(#199)。
|
|
2
|
+
//
|
|
3
|
+
// 口径:**一个仓库 = 一条目录队列 topic**、**一个组 = 一条组 topic**。登记时就建好;
|
|
4
|
+
// 这里给「仓库管理」页一个显式入口(刷新按钮)与编排后的自动刷新用,补齐历史数据缺的。
|
|
5
|
+
//
|
|
6
|
+
// 幂等:只补不删、重复调用无副作用。返回值是本次**新补的条数**,便于面板 toast 与 CLI 核对。
|
|
7
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
10
|
+
import * as serviceNs from '../service.js';
|
|
11
|
+
const service: any = serviceNs;
|
|
12
|
+
|
|
13
|
+
/** localtask.sync-queues 的入参契约。 */
|
|
14
|
+
const input = z.object({});
|
|
15
|
+
|
|
16
|
+
/** 出参视图:本次新补的队列条数(跨语言契约用)。 */
|
|
17
|
+
const output = z.object({
|
|
18
|
+
repos: z.int().describe('本次新补建的仓库队列数'),
|
|
19
|
+
groups: z.int().describe('本次新补建的组队列数'),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export class LocaltaskSyncQueuesAction extends ActionBase<typeof input> {
|
|
23
|
+
@action({
|
|
24
|
+
id: 'localtask.sync-queues',
|
|
25
|
+
cli: ['localtask', 'sync-queues'],
|
|
26
|
+
http: ['POST', '/api/localtask/queues/sync'],
|
|
27
|
+
summary: '补齐仓库 / 组缺的队列 topic(幂等,只补不删)——仓库管理页的「刷新队列」与编排后自动刷新走它',
|
|
28
|
+
input,
|
|
29
|
+
output,
|
|
30
|
+
render: (d: any) => `队列已同步:新补仓库队列 ${d.repos} 条、组队列 ${d.groups} 条`,
|
|
31
|
+
})
|
|
32
|
+
override async run(_ctx: ActionInput<this['_input']>) {
|
|
33
|
+
return service.syncQueues();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -38,7 +38,7 @@ const row = z.object({
|
|
|
38
38
|
status: z.string().describe('pending / claimed / done / cancelled'),
|
|
39
39
|
title: z.string().describe('正文首个标题行(没有标题就取首行,已截断)'),
|
|
40
40
|
round: z.int().describe('第几轮'),
|
|
41
|
-
board: z.string().describe('
|
|
41
|
+
board: z.string().describe('组任务标注:所属组队列的 key(#197 起来自 DB 关联);纯项目任务为空串'),
|
|
42
42
|
ready: z.boolean().describe('当前是否可领取'),
|
|
43
43
|
reopenCount: z.int(),
|
|
44
44
|
createdAt: z.string(),
|
|
@@ -124,7 +124,8 @@ export class LocaltaskTasksAction extends ActionBase<typeof input> {
|
|
|
124
124
|
round: t.round ?? 1,
|
|
125
125
|
// 组任务标注:normalizeTask 已经把 frontmatter.board 解析成 boardMark,
|
|
126
126
|
// 这里只做「缺省为空串」的形状收口 —— 别在这层再解析一遍正文。
|
|
127
|
-
|
|
127
|
+
// #197:组归属来自 DB 关联(boardKey/boardMark 同源)
|
|
128
|
+
board: t.boardMark || t.boardKey || '',
|
|
128
129
|
ready: !!t.ready,
|
|
129
130
|
reopenCount: t.reopenCount ?? 0,
|
|
130
131
|
createdAt: t.createdAt ?? '',
|
|
@@ -22,6 +22,9 @@ const input = z.object({
|
|
|
22
22
|
'clear-block-by': z.boolean().optional().describe("清掉 blockBy 依赖"),
|
|
23
23
|
clearBlockBy: z.boolean().optional().describe("同 --clear-block-by"),
|
|
24
24
|
gate: z.boolean().optional().describe("设/清闸门(true=挡住后续;false=取消闸门)"),
|
|
25
|
+
// #197:归属改由显式参数给出(不再改正文 frontmatter 里的 project/board)
|
|
26
|
+
project: z.string().optional().describe("改归属项目(仓库 key / 名称 / 路径)——任务迁到该仓库队列"),
|
|
27
|
+
board: z.string().optional().describe("改归属组(组 id / key / 名称)——同时更新 group topic 关联"),
|
|
25
28
|
});
|
|
26
29
|
|
|
27
30
|
export class LocaltaskUpdateAction extends ActionBase<typeof input> {
|
|
@@ -74,6 +77,9 @@ export class LocaltaskUpdateAction extends ActionBase<typeof input> {
|
|
|
74
77
|
blockBy,
|
|
75
78
|
clearBlockBy,
|
|
76
79
|
blocksFollowing: ctx.gate,
|
|
80
|
+
// #197:改归属走显式参数(null 表示不改)
|
|
81
|
+
project: ctx.project,
|
|
82
|
+
board: ctx.board,
|
|
77
83
|
});
|
|
78
84
|
// 出参契约(updateView)只回编号:把 task.id 提到顶层(纯附加,原有键不变)
|
|
79
85
|
if (r && r.task && r.task.id != null) r.id = r.task.id;
|
|
@@ -73,7 +73,7 @@ export function getGoalRowByTaskKey(topicKey: string, seq: number, conn: DbApi =
|
|
|
73
73
|
`SELECT g.*, t.seq AS task_seq, tp.key AS topic_key, tp.cwd AS topic_cwd, tp.name AS topic_name
|
|
74
74
|
FROM goals g
|
|
75
75
|
JOIN tasks t ON t.id = g.task_id
|
|
76
|
-
JOIN topics tp ON tp.id = t.
|
|
76
|
+
JOIN topics tp ON tp.id = t.repo_topic_id
|
|
77
77
|
WHERE tp.key = :k AND t.seq = :s AND t.deleted_at IS NULL AND g.deleted_at IS NULL
|
|
78
78
|
AND tp.deleted_at IS NULL`,
|
|
79
79
|
{ k: String(topicKey || ''), s: Number(seq) }
|
|
@@ -176,7 +176,7 @@ export function listGoalRows(conn: DbApi = db()): GoalRow[] {
|
|
|
176
176
|
`SELECT g.*, t.seq AS task_seq, tp.key AS topic_key, tp.cwd AS topic_cwd, tp.name AS topic_name
|
|
177
177
|
FROM goals g
|
|
178
178
|
JOIN tasks t ON t.id = g.task_id
|
|
179
|
-
JOIN topics tp ON tp.id = t.
|
|
179
|
+
JOIN topics tp ON tp.id = t.repo_topic_id
|
|
180
180
|
WHERE g.deleted_at IS NULL AND t.deleted_at IS NULL AND tp.deleted_at IS NULL
|
|
181
181
|
ORDER BY g.deadline`
|
|
182
182
|
);
|
|
@@ -42,7 +42,7 @@ export type LinkNode = ChildLinkNode | ChainLinkNode;
|
|
|
42
42
|
|
|
43
43
|
function taskRowById(conn: DbApi, id: number): Record<string, any> | null {
|
|
44
44
|
return conn.get(
|
|
45
|
-
`SELECT id,
|
|
45
|
+
`SELECT id, repo_topic_id AS topicId, seq, type, status, version, body, ext, feedback,
|
|
46
46
|
feedback_at AS feedbackAt, from_src AS fromSrc, blocks_following AS blocksFollowing,
|
|
47
47
|
claimed_at AS claimedAtMs, done_at AS doneAtMs, round, deleted_at AS deletedAtMs,
|
|
48
48
|
created_at AS createdAtMs, updated_at AS updatedAtMs
|
|
@@ -85,6 +85,12 @@ export function rowToTask(row: any): TaskObject {
|
|
|
85
85
|
roundSummary: String(row.feedback ?? ''),
|
|
86
86
|
deletedAt: stampOf(row.deletedAtMs),
|
|
87
87
|
from: String(row.fromSrc ?? ''),
|
|
88
|
+
// #197:两条 topic 关联(库内关系)——repo 队列必填、组队列可空
|
|
89
|
+
repoTopicId: Number(row.repoTopicId ?? 0),
|
|
90
|
+
groupTopicId: row.groupTopicId != null ? Number(row.groupTopicId) : null,
|
|
91
|
+
// 便利字段:归属仓库 key 与组 key(JOIN 出来,前端/CLI 直接读,不再解析正文)
|
|
92
|
+
repoKey: String(row.repoKey ?? ''),
|
|
93
|
+
boardKey: String(row.groupKey ?? ''),
|
|
88
94
|
blocksFollowing: !!row.blocksFollowing,
|
|
89
95
|
blockBy: [...localDeps, ...foreignDeps],
|
|
90
96
|
timegoal: ext[EXT.TIMEGOAL] || null,
|
|
@@ -115,6 +121,14 @@ export interface TaskObject {
|
|
|
115
121
|
id: number;
|
|
116
122
|
text: string;
|
|
117
123
|
status: string;
|
|
124
|
+
/** #197:仓库队列 topic(必填;编号与领取按它) */
|
|
125
|
+
repoTopicId?: number;
|
|
126
|
+
/** #197:组队列 topic(可空;组归属的唯一来源) */
|
|
127
|
+
groupTopicId?: number | null;
|
|
128
|
+
/** #197:归属仓库 key(JOIN repo topic 带出) */
|
|
129
|
+
repoKey?: string;
|
|
130
|
+
/** #197:组 key(JOIN group topic 带出;空 = 纯仓库任务) */
|
|
131
|
+
boardKey?: string;
|
|
118
132
|
createdAt: string;
|
|
119
133
|
consumedAt: string;
|
|
120
134
|
completedAt: string;
|
|
@@ -188,6 +202,8 @@ export function splitTaskFields(t: any): SplitTaskFields {
|
|
|
188
202
|
doneAtMs: t.completedAt !== undefined ? msOf(t.completedAt) : undefined,
|
|
189
203
|
deletedAtMs: t.deletedAt !== undefined ? msOf(t.deletedAt) : undefined,
|
|
190
204
|
fromSrc: t.from !== undefined ? String(t.from ?? '') : undefined,
|
|
205
|
+
// #197:组队列 topic(可空)——组归属的唯一来源
|
|
206
|
+
groupTopicId: t.groupTopicId !== undefined ? (t.groupTopicId == null ? null : Number(t.groupTopicId)) : undefined,
|
|
191
207
|
blocksFollowing: t.blocksFollowing !== undefined ? (t.blocksFollowing ? 1 : 0) : undefined,
|
|
192
208
|
// round 显式优先(派生 reopen:新.round = 父.round + 1,不走 reopenCount 换算)
|
|
193
209
|
round: t.round !== undefined ? Number(t.round) : t.reopenCount !== undefined ? Number(t.reopenCount) + 1 : undefined,
|
|
@@ -26,11 +26,18 @@ export interface TaskRowWithDeps {
|
|
|
26
26
|
export type TaskPatch = Record<string, any>;
|
|
27
27
|
|
|
28
28
|
// 行查询的统一列清单(camelCase 别名 = rowToTask 的入参形状)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
// #197:JOIN 出队列的 group_key——任务「归属哪个组」直接来自库内关系,
|
|
30
|
+
// 不再解析正文 frontmatter。task.repo_key 是它归属的仓库(cwd-repo)。
|
|
31
|
+
const TASK_SELECT = `SELECT t.id, t.repo_topic_id AS topicId, t.repo_topic_id AS repoTopicId,
|
|
32
|
+
t.group_topic_id AS groupTopicId,
|
|
33
|
+
t.seq, t.type, t.status, t.version, t.body, t.ext,
|
|
34
|
+
t.feedback, t.feedback_at AS feedbackAt, t.from_src AS fromSrc,
|
|
35
|
+
t.blocks_following AS blocksFollowing, t.claimed_at AS claimedAtMs, t.done_at AS doneAtMs,
|
|
36
|
+
t.round, t.deleted_at AS deletedAtMs, t.created_at AS createdAtMs, t.updated_at AS updatedAtMs,
|
|
37
|
+
rtp.repo_key AS repoKey, gtp.group_key AS groupKey
|
|
38
|
+
FROM tasks t
|
|
39
|
+
LEFT JOIN topics rtp ON rtp.id = t.repo_topic_id
|
|
40
|
+
LEFT JOIN topics gtp ON gtp.id = t.group_topic_id`;
|
|
34
41
|
|
|
35
42
|
/** 主题的下一个编号(next_seq 列维护,等价于旧 nextTaskId 的 max+1)。 */
|
|
36
43
|
export function nextSeq(topicId: number, conn: DbApi | null = null): number {
|
|
@@ -53,7 +60,7 @@ function takeSeq(topicId: number, conn: DbApi): number {
|
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
function extOf(conn: DbApi, topicId: number, seq: number): Record<string, any> {
|
|
56
|
-
const row = conn.get('SELECT ext FROM tasks WHERE
|
|
63
|
+
const row = conn.get('SELECT ext FROM tasks WHERE repo_topic_id = :t AND seq = :s', { t: topicId, s: seq });
|
|
57
64
|
return parseExt(row && row.ext);
|
|
58
65
|
}
|
|
59
66
|
|
|
@@ -63,7 +70,7 @@ function mergeExt(conn: DbApi, topicId: number, seq: number, patch: Record<strin
|
|
|
63
70
|
if (v === undefined) delete ext[k];
|
|
64
71
|
else ext[k] = v;
|
|
65
72
|
}
|
|
66
|
-
conn.run('UPDATE tasks SET ext = :ext, version = version + 1 WHERE
|
|
73
|
+
conn.run('UPDATE tasks SET ext = :ext, version = version + 1 WHERE repo_topic_id = :t AND seq = :s', {
|
|
67
74
|
ext: jsonText(ext),
|
|
68
75
|
t: topicId,
|
|
69
76
|
s: seq,
|
|
@@ -74,14 +81,14 @@ function mergeExt(conn: DbApi, topicId: number, seq: number, patch: Record<strin
|
|
|
74
81
|
* 本地依赖整组重写(task_deps 是逐对边;「这条任务挡在这些后面」就是块级语义)。
|
|
75
82
|
*
|
|
76
83
|
* 边存的是**全局 tasks.id**(外键列),而 JSON 形态的 blockBy 是**主题内 seq**。
|
|
77
|
-
* 多队列下两者不相等:写入时按 (
|
|
84
|
+
* 多队列下两者不相等:写入时按 (repo_topic_id, seq) 解析,读时反向解析,视图层仍只见 seq。
|
|
78
85
|
*/
|
|
79
86
|
function writeLocalDeps(conn: DbApi, topicId: number, taskId: number, depsLocal?: unknown[]): void {
|
|
80
87
|
conn.run('DELETE FROM task_deps WHERE task_id = :id', { id: taskId });
|
|
81
88
|
for (const dep of depsLocal || []) {
|
|
82
89
|
const depSeq = Number(dep);
|
|
83
90
|
if (!Number.isFinite(depSeq) || depSeq <= 0) continue;
|
|
84
|
-
const dr = conn.get('SELECT id FROM tasks WHERE
|
|
91
|
+
const dr = conn.get('SELECT id FROM tasks WHERE repo_topic_id = :t AND seq = :s', {
|
|
85
92
|
t: topicId,
|
|
86
93
|
s: depSeq,
|
|
87
94
|
});
|
|
@@ -102,7 +109,7 @@ function rowToTaskWithDeps(conn: DbApi, row: Record<string, any>): TaskRowWithDe
|
|
|
102
109
|
.all(
|
|
103
110
|
`SELECT d.seq AS depSeq
|
|
104
111
|
FROM task_deps td JOIN tasks d ON d.id = td.dep_id
|
|
105
|
-
WHERE td.task_id = :id AND d.
|
|
112
|
+
WHERE td.task_id = :id AND d.repo_topic_id = :t
|
|
106
113
|
ORDER BY d.seq`,
|
|
107
114
|
{ id: row.id, t: row.topicId }
|
|
108
115
|
)
|
|
@@ -138,12 +145,12 @@ export function insertTask(topicId: number, task: TaskPatch = {}): { id: number;
|
|
|
138
145
|
return txw((conn) => {
|
|
139
146
|
const at = nowMs();
|
|
140
147
|
// 编号必须在同一个事务里取:事务外的 next_seq 会被别的进程同时读到,
|
|
141
|
-
// 两边拿同一个号 → INSERT 撞 UNIQUE(
|
|
148
|
+
// 两边拿同一个号 → INSERT 撞 UNIQUE(repo_topic_id, seq)。
|
|
142
149
|
const explicit = Number(task.id);
|
|
143
150
|
let seq: number;
|
|
144
151
|
if (Number.isFinite(explicit) && explicit > 0) {
|
|
145
152
|
// 显式给了编号(引擎造节点 / 搬队列)也要把 next_seq 顶过去 —— 否则下一批
|
|
146
|
-
// addTask 会从旧值重新编号,撞主键 (
|
|
153
|
+
// addTask 会从旧值重新编号,撞主键 (repo_topic_id, seq)。
|
|
147
154
|
seq = Math.trunc(explicit);
|
|
148
155
|
conn.run('UPDATE topics SET next_seq = MAX(next_seq, :n) WHERE id = :id', {
|
|
149
156
|
n: seq + 1,
|
|
@@ -155,12 +162,12 @@ export function insertTask(topicId: number, task: TaskPatch = {}): { id: number;
|
|
|
155
162
|
const fields = splitTaskFields({ status: 'pending', createdAt: undefined, ...task });
|
|
156
163
|
const c = fields.columns;
|
|
157
164
|
conn.run(
|
|
158
|
-
`INSERT INTO tasks (
|
|
159
|
-
from_src, blocks_following, claimed_at, done_at,
|
|
160
|
-
created_at, updated_at)
|
|
161
|
-
VALUES (:t, :s, '', :status, 0, :body, :ext,
|
|
162
|
-
:
|
|
163
|
-
:createdAtMs, :at)`,
|
|
165
|
+
`INSERT INTO tasks (repo_topic_id, group_topic_id, seq, type, status, version, body, ext,
|
|
166
|
+
feedback, feedback_at, from_src, blocks_following, claimed_at, done_at,
|
|
167
|
+
round, deleted_at, created_at, updated_at)
|
|
168
|
+
VALUES (:t, :gt, :s, '', :status, 0, :body, :ext,
|
|
169
|
+
:feedback, NULL, :fromSrc, :blocksFollowing, :claimedAtMs, :doneAtMs,
|
|
170
|
+
:round, :deletedAtMs, :createdAtMs, :at)`,
|
|
164
171
|
{
|
|
165
172
|
t: topicId,
|
|
166
173
|
s: seq,
|
|
@@ -176,10 +183,12 @@ export function insertTask(topicId: number, task: TaskPatch = {}): { id: number;
|
|
|
176
183
|
deletedAtMs: c.deletedAtMs ?? null,
|
|
177
184
|
// createdAt 缺省 = 现在(旧行为:发布时刻)
|
|
178
185
|
createdAtMs: c.createdAtMs ?? at,
|
|
186
|
+
// #197:组队列(可空)——组归属的唯一来源
|
|
187
|
+
gt: c.groupTopicId ?? null,
|
|
179
188
|
at,
|
|
180
189
|
}
|
|
181
190
|
);
|
|
182
|
-
const row = conn.get('SELECT id FROM tasks WHERE
|
|
191
|
+
const row = conn.get('SELECT id FROM tasks WHERE repo_topic_id = :t AND seq = :s', { t: topicId, s: seq });
|
|
183
192
|
writeLocalDeps(conn, topicId, Number(row.id), fields.depsLocal);
|
|
184
193
|
// 正文里已经写了 fileId / nxkv 链接:入库即建资源关系,不等到领取才解析。
|
|
185
194
|
syncTaskAttachments(conn, { taskId: Number(row.id), text: c.body ?? '', atMs: at });
|
|
@@ -190,7 +199,7 @@ export function insertTask(topicId: number, task: TaskPatch = {}): { id: number;
|
|
|
190
199
|
/** 查一条任务(JSON 形态,含 deps / ext);不存在返回 null。 */
|
|
191
200
|
export function getTaskRow(topicId: number, seq: number, conn: DbApi | null = null): TaskRowWithDeps | null {
|
|
192
201
|
const c = conn || db();
|
|
193
|
-
const row = c.get(`${TASK_SELECT} WHERE
|
|
202
|
+
const row = c.get(`${TASK_SELECT} WHERE t.repo_topic_id = :t AND t.seq = :s`, { t: topicId, s: seq });
|
|
194
203
|
if (!row) return null;
|
|
195
204
|
return rowToTaskWithDeps(c, row);
|
|
196
205
|
}
|
|
@@ -198,7 +207,7 @@ export function getTaskRow(topicId: number, seq: number, conn: DbApi | null = nu
|
|
|
198
207
|
/** 按内部主键取任务行(链节点用:链存的是全局 tasks.id)。 */
|
|
199
208
|
export function getTaskRowById(id: number, conn: DbApi | null = null): TaskRowWithDeps | null {
|
|
200
209
|
const c = conn || db();
|
|
201
|
-
const row = c.get(`${TASK_SELECT} WHERE id = :id`, { id });
|
|
210
|
+
const row = c.get(`${TASK_SELECT} WHERE t.id = :id`, { id });
|
|
202
211
|
if (!row) return null;
|
|
203
212
|
return rowToTaskWithDeps(c, row);
|
|
204
213
|
}
|
|
@@ -209,22 +218,17 @@ export function getTaskRowById(id: number, conn: DbApi | null = null): TaskRowWi
|
|
|
209
218
|
*/
|
|
210
219
|
export function listTaskRowsByTopic(topicId: number, conn: DbApi | null = null): TaskRowWithDeps[] {
|
|
211
220
|
const c = conn || db();
|
|
212
|
-
const rows = c.all(`${TASK_SELECT} WHERE
|
|
221
|
+
const rows = c.all(`${TASK_SELECT} WHERE t.repo_topic_id = :t ORDER BY t.seq`, { t: topicId });
|
|
213
222
|
return rows.map((row) => rowToTaskWithDeps(c, row));
|
|
214
223
|
}
|
|
215
224
|
|
|
216
225
|
/** 全库任务(跨主题总览用),带 topicKey。软删主题下的任务不出现(祖先过滤)。 */
|
|
217
226
|
export function listAllTaskRows(conn: DbApi | null = null): Array<{ task: TaskObject; topicKey: string; topicId: number }> {
|
|
218
227
|
const c = conn || db();
|
|
228
|
+
// 复用 TASK_SELECT(含 group topic 的 JOIN,组归属/仓库归属都在里面)
|
|
219
229
|
const rows = c.all(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
t.claimed_at AS claimedAtMs, t.done_at AS doneAtMs, t.round, t.deleted_at AS deletedAtMs,
|
|
223
|
-
t.created_at AS createdAtMs, t.updated_at AS updatedAtMs, k.key AS topic_key
|
|
224
|
-
FROM tasks t JOIN topics k ON k.id = t.topic_id
|
|
225
|
-
WHERE k.deleted_at IS NULL
|
|
226
|
-
ORDER BY t.topic_id, t.seq`
|
|
227
|
-
);
|
|
230
|
+
`${TASK_SELECT} WHERE rtp.deleted_at IS NULL ORDER BY t.repo_topic_id, t.seq`
|
|
231
|
+
).map((r: any) => ({ ...r, topic_key: r.topicId }));
|
|
228
232
|
return rows.map((row) => {
|
|
229
233
|
const { task } = rowToTaskWithDeps(c, row);
|
|
230
234
|
return { task, topicKey: String(row.topic_key), topicId: Number(row.topicId) };
|
|
@@ -255,7 +259,7 @@ export function claimTask(
|
|
|
255
259
|
const r = conn.run(
|
|
256
260
|
`UPDATE tasks SET status = 'claimed', claimed_at = :at, feedback = :fb, version = version + 1,
|
|
257
261
|
updated_at = :at
|
|
258
|
-
WHERE
|
|
262
|
+
WHERE repo_topic_id = :t AND seq = :s AND status = 'pending' AND deleted_at IS NULL`,
|
|
259
263
|
{ t: topicId, s: seq, at: atMs, fb: String(summary ?? '') }
|
|
260
264
|
);
|
|
261
265
|
if (Number(r.changes) !== 1) return null;
|
|
@@ -274,7 +278,7 @@ export function completeTask(topicId: number, seq: number, { feedback = '', atMs
|
|
|
274
278
|
const r = conn.run(
|
|
275
279
|
`UPDATE tasks SET status = 'done', done_at = :at, feedback_at = :at, feedback = :fb,
|
|
276
280
|
version = version + 1, updated_at = :at
|
|
277
|
-
WHERE
|
|
281
|
+
WHERE repo_topic_id = :t AND seq = :s AND status = 'claimed' AND deleted_at IS NULL`,
|
|
278
282
|
{ t: topicId, s: seq, at: atMs, fb: String(feedback ?? '') }
|
|
279
283
|
);
|
|
280
284
|
return Number(r.changes) === 1;
|
|
@@ -298,12 +302,12 @@ export function closeOpenTask(topicId: number, seq: number, { status = 'done', f
|
|
|
298
302
|
? conn.run(
|
|
299
303
|
`UPDATE tasks SET status = 'done', done_at = :at, feedback_at = :at, feedback = :fb,
|
|
300
304
|
version = version + 1, updated_at = :at
|
|
301
|
-
WHERE
|
|
305
|
+
WHERE repo_topic_id = :t AND seq = :s AND status IN ('pending', 'claimed') AND deleted_at IS NULL`,
|
|
302
306
|
{ t: topicId, s: seq, at: atMs, fb: String(feedback ?? '') }
|
|
303
307
|
)
|
|
304
308
|
: conn.run(
|
|
305
309
|
`UPDATE tasks SET status = 'cancelled', version = version + 1, updated_at = :at
|
|
306
|
-
WHERE
|
|
310
|
+
WHERE repo_topic_id = :t AND seq = :s AND status IN ('pending', 'claimed') AND deleted_at IS NULL`,
|
|
307
311
|
{ t: topicId, s: seq, at: atMs }
|
|
308
312
|
);
|
|
309
313
|
return Number(r.changes) === 1;
|
|
@@ -333,7 +337,7 @@ export function tombstoneAsCancelled(
|
|
|
333
337
|
`UPDATE tasks SET status = 'cancelled',
|
|
334
338
|
deleted_at = COALESCE(:del, deleted_at),
|
|
335
339
|
version = version + 1, updated_at = :at
|
|
336
|
-
WHERE
|
|
340
|
+
WHERE repo_topic_id = :t AND seq = :s AND status NOT IN ('done', 'cancelled')`,
|
|
337
341
|
{ t: topicId, s: seq, del: extra.deletedAtMs ?? null, at }
|
|
338
342
|
);
|
|
339
343
|
if (Number(r.changes) !== 1) return null;
|
|
@@ -356,7 +360,7 @@ export function switchPlanStatus(topicId: number, seq: number, to: 'plan' | 'pen
|
|
|
356
360
|
return txw((conn) => {
|
|
357
361
|
const r = conn.run(
|
|
358
362
|
`UPDATE tasks SET status = :to, version = version + 1, updated_at = :at
|
|
359
|
-
WHERE
|
|
363
|
+
WHERE repo_topic_id = :t AND seq = :s AND status = :from AND deleted_at IS NULL`,
|
|
360
364
|
{ t: topicId, s: seq, to, from, at: nowMs() }
|
|
361
365
|
);
|
|
362
366
|
if (Number(r.changes) !== 1) return null;
|
|
@@ -374,7 +378,7 @@ export function alignClaimedFromSnapshot(topicId: number, seq: number): boolean
|
|
|
374
378
|
return txw((conn) => {
|
|
375
379
|
const r = conn.run(
|
|
376
380
|
`UPDATE tasks SET status = 'claimed', claimed_at = :at, version = version + 1, updated_at = :at
|
|
377
|
-
WHERE
|
|
381
|
+
WHERE repo_topic_id = :t AND seq = :s AND status NOT IN ('claimed', 'done')`,
|
|
378
382
|
{ t: topicId, s: seq, at: nowMs() }
|
|
379
383
|
);
|
|
380
384
|
return Number(r.changes) === 1;
|
|
@@ -426,7 +430,7 @@ export function updateTask(topicId: number, seq: number, patch: TaskPatch = {}):
|
|
|
426
430
|
// 它就不再是死列,还能给外部同步/审计一个廉价的变更判据。
|
|
427
431
|
sets.push('version = version + 1');
|
|
428
432
|
sets.push('updated_at = :at');
|
|
429
|
-
conn.run(`UPDATE tasks SET ${sets.join(', ')} WHERE
|
|
433
|
+
conn.run(`UPDATE tasks SET ${sets.join(', ')} WHERE repo_topic_id = :t AND seq = :s`, params);
|
|
430
434
|
writeLocalDeps(conn, topicId, Number(cur.row.id), fields.depsLocal);
|
|
431
435
|
// 只有正文真的变了才重写资源关系:status/feedback 更新不动 task_attach。
|
|
432
436
|
if (patch.text !== undefined || patch.body !== undefined) {
|
|
@@ -450,11 +454,11 @@ export function updateTaskByKey(key: string, seq: number, patch: TaskPatch = {})
|
|
|
450
454
|
/** 彻底删除一行(purge)。软删除走 updateTask({ deletedAt })。 */
|
|
451
455
|
export function purgeTask(topicId: number, seq: number): boolean {
|
|
452
456
|
return txw((conn) => {
|
|
453
|
-
const row = conn.get('SELECT id FROM tasks WHERE
|
|
457
|
+
const row = conn.get('SELECT id FROM tasks WHERE repo_topic_id = :t AND seq = :s', { t: topicId, s: seq });
|
|
454
458
|
if (!row) return false;
|
|
455
459
|
conn.run('DELETE FROM task_deps WHERE task_id = :id', { id: row.id });
|
|
456
460
|
conn.run('DELETE FROM task_deps WHERE dep_id = :id', { id: row.id });
|
|
457
|
-
const r = conn.run('DELETE FROM tasks WHERE
|
|
461
|
+
const r = conn.run('DELETE FROM tasks WHERE repo_topic_id = :t AND seq = :s', { t: topicId, s: seq });
|
|
458
462
|
return Number(r.changes) === 1;
|
|
459
463
|
});
|
|
460
464
|
}
|
|
@@ -470,7 +474,7 @@ export function hasBlockingGate(topicId: number, seq: number, conn: DbApi | null
|
|
|
470
474
|
const c = conn || db();
|
|
471
475
|
return !!c.get(
|
|
472
476
|
`SELECT 1 FROM tasks g
|
|
473
|
-
WHERE g.
|
|
477
|
+
WHERE g.repo_topic_id = :t AND g.seq < :s
|
|
474
478
|
AND g.status = 'pending' AND g.deleted_at IS NULL AND g.blocks_following = 1
|
|
475
479
|
LIMIT 1`,
|
|
476
480
|
{ t: topicId, s: seq }
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// 主题仓储(topics + topic_presence 的窄方法)。
|
|
2
2
|
|
|
3
3
|
import { db, txw } from './open.js';
|
|
4
|
+
import { normRepoPath, autoRepoKey } from '../../../../core/db/repo-match.js';
|
|
4
5
|
import { nowMs, msToStamp } from '../../../../core/db/time.js';
|
|
5
6
|
import { TOPIC_EXT, parseExt, jsonText } from './rows.js';
|
|
6
7
|
import { listTaskRowsByTopic, listAllTaskRows } from './tasks.js';
|
|
7
8
|
import type { DbApi } from '../../../../core/db/driver.js';
|
|
8
9
|
import type { TaskObject } from './rows.js';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
// #197:不再有哨兵仓库——队列必须绑真实仓库。cwd 匹配不到且目录存在时自动登记
|
|
12
|
+
// (local/<目录名>);目录也不存在则用 local/<key> 兜底,保证 repo_key 永不为空。
|
|
11
13
|
|
|
12
14
|
// 统一列清单:assembleTopic 读的是 camelCase 别名(createdAtMs/updatedAtMs),
|
|
13
15
|
// SELECT * 只有蛇形列名 —— 时间戳恒为空、面板排序失效都是从这里来的。
|
|
@@ -48,26 +50,54 @@ export function getTopicRow(key: string): TopicRow | null {
|
|
|
48
50
|
|
|
49
51
|
/** 全部主题行(稳定序;不含软删)。 */
|
|
50
52
|
export function listTopicRows(): TopicRow[] {
|
|
51
|
-
|
|
53
|
+
// #198:**只列目录队列**(repo topic)。组也是一条 topic(key=group:<组key>)但
|
|
54
|
+
// 它没有物理目录(cwd 空),不属于「按目录领取」的世界——组页走 boardtasks 的
|
|
55
|
+
// SQL 关联,不该把它当普通队列列进侧栏/CLI 列表。
|
|
56
|
+
return db().all(`${TOPIC_SELECT} WHERE deleted_at IS NULL AND cwd <> '' ORDER BY id`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** #197:队列归属仓库的解析(显式优先 → cwd 匹配 → 自动登记 → local/<key> 兜底)。 */
|
|
60
|
+
function resolveRepoKey(conn: DbApi, cwd: string, explicit: string, key: string, at: number): string {
|
|
61
|
+
if (explicit) return explicit;
|
|
62
|
+
const repos = conn
|
|
63
|
+
.all("SELECT key, path FROM repos WHERE type = 'repo' AND path <> '' AND key <> '__unbound__'")
|
|
64
|
+
.map((r: any) => ({ key: String(r.key), path: String(r.path) }));
|
|
65
|
+
const nc = normRepoPath(cwd);
|
|
66
|
+
const matched = repos.find((r) => r.path && normRepoPath(r.path) === nc);
|
|
67
|
+
if (matched) return matched.key;
|
|
68
|
+
const taken = new Set<string>(conn.all('SELECT key FROM repos').map((r: any) => String(r.key)));
|
|
69
|
+
const rk = autoRepoKey(cwd || key, taken);
|
|
70
|
+
conn.run(
|
|
71
|
+
`INSERT INTO repos (key, type, name, description, path, remote, sort_order, ext, state, version,
|
|
72
|
+
deleted_at, created_at, updated_at)
|
|
73
|
+
VALUES (:key, 'repo', :name, '', :path, '', 0, '{}', '', 0, NULL, :at, :at)`,
|
|
74
|
+
{ key: rk, name: rk.slice('local/'.length), path: String(cwd || ''), at },
|
|
75
|
+
);
|
|
76
|
+
return rk;
|
|
52
77
|
}
|
|
53
78
|
|
|
54
79
|
/**
|
|
55
80
|
* 取(必要时新建)主题,返回内部行。
|
|
56
81
|
* cwd 语义与 JSON 时代一致:**第一个路径为准**(稳定),后到的调用不覆盖已有 cwd。
|
|
57
82
|
*/
|
|
58
|
-
export function ensureTopic(
|
|
83
|
+
export function ensureTopic(
|
|
84
|
+
key: string,
|
|
85
|
+
{ cwd = '', name = '', repoKey = '' }: { cwd?: string; name?: string; repoKey?: string } = {},
|
|
86
|
+
): { id: number; cwd: string; name: string; ext: Record<string, any> } {
|
|
59
87
|
return txw((conn) => {
|
|
60
88
|
const at = nowMs();
|
|
61
89
|
let row: any = conn.get('SELECT id, cwd, name, ext, deleted_at FROM topics WHERE key = :key', { key });
|
|
62
90
|
if (!row) {
|
|
63
91
|
const ext: Record<string, any> = {};
|
|
92
|
+
// #197:归属仓库落库(显式 > cwd 匹配 > 自动登记 > local/<key> 兜底)
|
|
93
|
+
const resolvedRepo = resolveRepoKey(conn, cwd, repoKey, key, at);
|
|
64
94
|
conn.run(
|
|
65
95
|
`INSERT INTO topics (key, repo_key, cwd, group_key, name, next_seq, ext, state, version,
|
|
66
96
|
deleted_at, created_at, updated_at)
|
|
67
97
|
VALUES (:key, :repo, :cwd, NULL, :name, 1, :ext, '', 0, NULL, :at, :at)`,
|
|
68
98
|
{
|
|
69
99
|
key,
|
|
70
|
-
repo:
|
|
100
|
+
repo: resolvedRepo,
|
|
71
101
|
cwd: String(cwd || ''),
|
|
72
102
|
name: String(name || (cwd ? String(cwd).split(/[\\/]/).pop() : key) || key),
|
|
73
103
|
ext: jsonText(ext),
|
|
@@ -92,6 +122,33 @@ export function ensureTopic(key: string, { cwd = '', name = '' }: { cwd?: string
|
|
|
92
122
|
});
|
|
93
123
|
}
|
|
94
124
|
|
|
125
|
+
/**
|
|
126
|
+
* 找/建**组队列** topic(#197):组本身也是一个 topic。
|
|
127
|
+
* key = 'group:<组 key>',repo_key 指向组的 repos 行,cwd 空(组没有物理目录)。
|
|
128
|
+
* 组的文档/提示词上下文直接挂这条 topic,组页查询用 tasks.group_topic_id 一次取完。
|
|
129
|
+
*/
|
|
130
|
+
export function ensureGroupTopic(groupKey: string, groupName = ''): { id: number; key: string } {
|
|
131
|
+
const gk = String(groupKey || '').trim();
|
|
132
|
+
if (!gk) throw new Error('ensureGroupTopic: 需要组 key');
|
|
133
|
+
const key = `group:${gk}`;
|
|
134
|
+
return txw((conn) => {
|
|
135
|
+
const at = nowMs();
|
|
136
|
+
const hit = conn.get('SELECT id FROM topics WHERE key = :k', { k: key });
|
|
137
|
+
if (hit) {
|
|
138
|
+
conn.run('UPDATE topics SET deleted_at = NULL WHERE id = :id AND deleted_at IS NOT NULL', { id: Number(hit.id) });
|
|
139
|
+
return { id: Number(hit.id), key };
|
|
140
|
+
}
|
|
141
|
+
conn.run(
|
|
142
|
+
`INSERT INTO topics (key, repo_key, cwd, group_key, name, next_seq, ext, state, version,
|
|
143
|
+
deleted_at, created_at, updated_at)
|
|
144
|
+
VALUES (:key, :repo, '', :group, :name, 1, '{}', '', 0, NULL, :at, :at)`,
|
|
145
|
+
{ key, repo: gk, group: gk, name: String(groupName || gk), at },
|
|
146
|
+
);
|
|
147
|
+
const row = conn.get('SELECT id FROM topics WHERE key = :k', { k: key });
|
|
148
|
+
return { id: Number(row.id), key };
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
95
152
|
/** 组装 JSON 形态的主题对象(含 tasks / presence)。不存在返回 null。 */
|
|
96
153
|
export function getTopic(key: string): TopicObject | null {
|
|
97
154
|
const conn = db();
|