nx-kv 0.32.0 → 0.34.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 +67 -0
- package/package.json +1 -1
- package/src/core/db/migrations/index.js +2 -0
- package/src/core/db/migrations/v3.sql +20 -0
- package/src/core/db/version.js +4 -1
- package/src/modules/localtask/index.js +59 -0
- package/src/modules/localtask/repo/tasks.js +23 -0
- package/src/modules/localtask/task-ops.js +9 -0
- package/src/modules/localtask/task-remove.js +69 -0
- package/src/modules/localtask/task-view.js +4 -0
- package/src/modules/tasktool/plugins/timegoal-store.js +60 -0
- package/src/modules/templates/index.js +65 -9
- package/src/modules/templates/repo/templates.js +24 -2
- package/src/modules/templates/scope.js +107 -0
- package/src/modules/templates/service.js +83 -4
- package/src/runtime/spec.js +6 -1
- package/src/web/frontend/App.jsx +34 -2
- package/src/web/frontend/components/button/index.jsx +34 -7
- package/src/web/frontend/components/button/style.css +1 -1
- package/src/web/frontend/components/doc/doc-head.jsx +164 -48
- package/src/web/frontend/components/icons.jsx +17 -0
- package/src/web/frontend/components/layout/crumbs.js +4 -1
- package/src/web/frontend/components/md/attach-area.jsx +20 -11
- package/src/web/frontend/components/md/attach-modal.jsx +3 -2
- package/src/web/frontend/components/md/attach-picker.jsx +37 -7
- package/src/web/frontend/components/md/md-panes.jsx +102 -23
- package/src/web/frontend/components/md/sel-menu.jsx +11 -0
- package/src/web/frontend/components/md/tool-bar.jsx +153 -91
- package/src/web/frontend/components/sidebar/task-children.jsx +6 -11
- package/src/web/frontend/components/status-tag/index.jsx +30 -0
- package/src/web/frontend/components/status-tag/model.js +53 -0
- package/src/web/frontend/components/tool-acts/bar.jsx +156 -0
- package/src/web/frontend/components/tool-acts/dnd.js +59 -0
- package/src/web/frontend/components/tool-acts/layout-panel.jsx +289 -0
- package/src/web/frontend/components/tool-acts/modules.js +162 -0
- package/src/web/frontend/components/tool-acts/style.css +108 -0
- package/src/web/frontend/components/tool-acts/use-layout.js +27 -0
- package/src/web/frontend/modules/md/attach-mention.js +11 -0
- package/src/web/frontend/modules/md/md-edit-ops.js +10 -7
- package/src/web/frontend/modules/md/md-parse.js +8 -21
- package/src/web/frontend/modules/md/progress-search.js +96 -0
- package/src/web/frontend/modules/md/style.css +124 -14
- package/src/web/frontend/modules/md/use-templates.js +65 -2
- package/src/web/frontend/page/dir/index.jsx +73 -38
- package/src/web/frontend/page/dir/landing.jsx +73 -78
- package/src/web/frontend/page/dir/task.jsx +426 -111
- package/src/web/frontend/page/group/index.jsx +194 -88
- package/src/web/frontend/page/overview/index.jsx +168 -269
- package/src/web/frontend/page/progress/index.jsx +59 -9
- package/src/web/frontend/page/repos/index.jsx +95 -103
- package/src/web/frontend/page/settings/index.jsx +4 -3
- package/src/web/frontend/page/settings/style.css +59 -31
- package/src/web/frontend/page/settings/task-templates-section.jsx +94 -99
- package/src/web/frontend/page/templates/index.jsx +221 -203
- package/src/web/frontend/page/templates/scope-chips.jsx +211 -0
- package/src/web/frontend/panels.jsx +28 -4
- package/src/web/frontend/route-map.js +42 -2
- package/src/web/frontend/style-v2.css +33 -71
- package/src/web/frontend/style.css +127 -319
- package/src/web/frontend/workspace/areas.js +1 -1
- package/src/web/public/assets/Introduction-DU27b_b_.js +1 -0
- package/src/web/public/assets/bar-CNuQf706.js +1 -0
- package/src/web/public/assets/board-view-t8CKtq17.js +1 -0
- package/src/web/public/assets/button-BPYMY-zh.js +1 -0
- package/src/web/public/assets/button-DA4lNJeC.css +1 -0
- package/src/web/public/assets/cloud-DgNCxJsL.js +3 -0
- package/src/web/public/assets/{composer-launch-q1uPzWGo.js → composer-launch-BKeKTPp4.js} +1 -1
- package/src/web/public/assets/composer-panel-DP322mVs.js +1 -0
- package/src/web/public/assets/dag-C4702bOt.js +1 -0
- package/src/web/public/assets/dir-Cipgyv3a.js +5 -0
- package/src/web/public/assets/group-m61-WL4C.js +1 -0
- package/src/web/public/assets/index-BEkITE6q.css +1 -0
- package/src/web/public/assets/index-CeIJd4ee.js +30 -0
- package/src/web/public/assets/md-history-Uo6U7hYS.js +1 -0
- package/src/web/public/assets/md-panes-PS7K93Lg.js +28 -0
- package/src/web/public/assets/md-parse-DN9INgZn.js +25 -0
- package/src/web/public/assets/member-picker--32VkTmv.js +1 -0
- package/src/web/public/assets/overview-BmoTQJuu.js +1 -0
- package/src/web/public/assets/progress-CWy9bYKr.js +3 -0
- package/src/web/public/assets/refs-DAy1kYGf.js +1 -0
- package/src/web/public/assets/repos-D_NT51Dq.js +9 -0
- package/src/web/public/assets/route-crumb-lOriqwxP.js +1 -0
- package/src/web/public/assets/settings-CBrQ3Iz5.css +1 -0
- package/src/web/public/assets/settings-Vp3ZMC1M.js +7 -0
- package/src/web/public/assets/status-tag-DGlwjAg2.js +1 -0
- package/src/web/public/assets/task-CRpctHxx.js +9 -0
- package/src/web/public/assets/task-status-BP6y8MVu.js +1 -0
- package/src/web/public/assets/templates-D900RS5b.js +1 -0
- package/src/web/public/assets/tool-bar-1h2zairf.css +1 -0
- package/src/web/public/assets/tool-bar-C-rnP0vv.js +1 -0
- package/src/web/public/assets/upload-L1g-pfvZ.js +1 -0
- package/src/web/public/index.html +6 -5
- package/src/web/public/assets/Introduction-MAkTZvUX.js +0 -1
- package/src/web/public/assets/attach-Bw0necIf.js +0 -1
- package/src/web/public/assets/cloud-CG_hgVn9.js +0 -3
- package/src/web/public/assets/composer-panel-S2d6A3fG.js +0 -1
- package/src/web/public/assets/dag-CwY66RrZ.js +0 -1
- package/src/web/public/assets/dir-B_ySdQT1.js +0 -5
- package/src/web/public/assets/group-6sWouRDt.js +0 -1
- package/src/web/public/assets/index-DKncYqtS.js +0 -54
- package/src/web/public/assets/index-DO7b1M3E.css +0 -1
- package/src/web/public/assets/md-edit-ops-ZwnwtEax.js +0 -22
- package/src/web/public/assets/md-history-BxbOQtPI.js +0 -1
- package/src/web/public/assets/md-panes-Cso2NHbG.js +0 -7
- package/src/web/public/assets/member-picker-BpB9ZpWx.js +0 -1
- package/src/web/public/assets/overview-Bo8ivqRU.js +0 -1
- package/src/web/public/assets/progress-DPkGjn0P.js +0 -3
- package/src/web/public/assets/refs-CskU6rI7.js +0 -1
- package/src/web/public/assets/repos-B_tskNGw.js +0 -9
- package/src/web/public/assets/route-crumb-BZ6ffDRj.js +0 -1
- package/src/web/public/assets/settings-BMTd_p9Y.js +0 -7
- package/src/web/public/assets/settings-qCi-niJC.css +0 -1
- package/src/web/public/assets/task-Cs-9RNQn.js +0 -7
- package/src/web/public/assets/task-status-Bgo2Nfiw.js +0 -1
- package/src/web/public/assets/template-editor-CRxfV218.js +0 -1
- package/src/web/public/assets/templates-Apc3JKXa.js +0 -2
- package/src/web/public/assets/upload-C83Bwy06.js +0 -1
- /package/src/web/public/assets/{attach-BZrdOH46.css → task-status-BZrdOH46.css} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.34.0] - 2026-11-09 模板可见域 + 全屏编辑 / 工具区编排 / 进程搜索口径
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **模板可见域(#128)**:模板带 scope(全局 `*` / 目录 `topic:` / 项目 `repo:` / 组 `group:`)
|
|
10
|
+
与创建来源 origin_topic;设置页 scope chips(全局开关 + 定向加删 + 创建于标记);
|
|
11
|
+
组页 hover 出模板下拉面板——列该 topic 可用的模板、面板右下角新增模板;
|
|
12
|
+
`GET /api/templates?topic=` 按可见域过滤(use ≠ edit:全局/项目/组条目只给用不给改)。
|
|
13
|
+
存储迁移 v2→v3(`templates` 加 `scope`(默认 `["*"]`)与 `origin_topic`,零破坏)。
|
|
14
|
+
运行时 flag 新增 `raw` 类型(值本身是数组/对象的透传,修「清空可见域被静默吞掉」)。
|
|
15
|
+
- **模板全屏编辑与工具区编排**:模板改为 settings 卡片 + `#/templates` 路由编辑;
|
|
16
|
+
group/dir/task/doc 工具栏按 nx-ft 支持顺序/显隐编排(隐藏收入「更多」)。
|
|
17
|
+
- **进程面板搜索口径(#129)**:纯数字查询命中编号等值(#12)、编号前缀(12 → #120–#129)
|
|
18
|
+
与标题逐位通配(12 ≡ 1*2,位序在即可);带 `*` 按段顺序匹配;普通文本标题子串不变。
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **进程卡右侧显示任务编号 #id(#127)**:原按重开轮次渲染「N楼」的口径纠正为编号本身。
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- CI lint:group/settings 页两处 eslint 错误(未用解构 / 未定义 openPanel);
|
|
27
|
+
check-tdz 补齐「跳过多行解构参数」——解构模式的属性键(`catalog: catalogProp`)不是引用。
|
|
28
|
+
- 小修:repos 页 chip 选中态黑块改绿(#126);总览收组任务(#125);
|
|
29
|
+
md 实时预览跨块选区统一删除/复制(#124)。
|
|
30
|
+
|
|
31
|
+
## [0.33.1] - 2026-11-09 skill 文档按 0.33.0 实况校准(仅文档)
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **客户端 skill(assets/)**:kv-get 重写为「领取 → 读正文 → 取附件 → 完成」流程,
|
|
36
|
+
补齐 wait 四种出口、任务级 timegoal、`close-many --ids`、reopen 派生新任务;kv-submit
|
|
37
|
+
修正 `--global` 位置与 `--project/--board`,`delivered/queued` 为布尔;kv-repo / nx-kv
|
|
38
|
+
校正 `board list` 字段、`repo ref` 命令与 `--matchTopic`。删除与 waitloop / timegoal
|
|
39
|
+
重复且过期的 wait-workflow、timegoal-workflow。
|
|
40
|
+
- **开发 skill(.claude/skills/dev-nxkv)**:SOP 压缩为一条规则一句;领域模型改为 v2
|
|
41
|
+
表结构(`attachments` / `task_attach` / `ref_attach`,`refs` 仅收 `.md`);迁移规则改为
|
|
42
|
+
`vN.sql` + `index.js` 边映射;提示词补共享 ctx 与区块模板列表;settings 页与底部
|
|
43
|
+
状态栏只点结构变化。
|
|
44
|
+
- 命令与返回字段全部按 `help --json` / 临时库实跑校准:`instruction` 非任务正文、
|
|
45
|
+
附件 `area` 取 `inline|area`、`close-many` 的 `--ids` 必填、`todo list` 返回对象等。
|
|
46
|
+
- 无业务代码、schema 或存储变更;并入 origin/main 尚未发版的改动(#111–#114:
|
|
47
|
+
md 草稿与 @ 面板、撤掉 frontmatter 属性卡、总览扁平清单、仓库页按钮规范)。
|
|
48
|
+
|
|
49
|
+
## [0.33.0] - 2026-11-08 底部信息面板 / check 日志 / 用户侧收口 / 状态配色
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- **任务页底部信息面板(VSCode 风,#81)**:附件 / check / 反馈收进底部面板,
|
|
54
|
+
正文下方不再堆内容块,编辑区恢复完整高度。上沿 6px 拖拽线可调高(双击最大化/还原),
|
|
55
|
+
面板头左上切 tab、右上两个控制钮(最大化↔还原 / 关闭);关闭后底部常驻状态栏保留
|
|
56
|
+
「附件 / check N / 反馈」入口与任务状态,点条目重开对应 tab;展开状态、当前 tab、
|
|
57
|
+
高度按视图持久化到 localStorage。窄屏按容器宽度先省略状态标签、再省略条目文字。
|
|
58
|
+
- **时间目标每轮 check 日志**:新增 `localtask timegoal-log`
|
|
59
|
+
(`GET /api/localtasks/timegoal-log`),返回时长、开始/截止、轮次数与每轮
|
|
60
|
+
时间、已用/剩余、是否到点、当轮总结与进度;面板 check tab 逐轮展示,0 轮给明确空态。
|
|
61
|
+
- **用户侧直接完成/取消待领取任务(close-many)**:新增 `localtask close-many`
|
|
62
|
+
(`POST /api/localtasks/items/close`),不要求先领取;只动 pending,done 写完成总结、
|
|
63
|
+
cancelled 只改状态,已领取/已交付跳过。任务页「更多」与目录页多选均可操作。
|
|
64
|
+
|
|
65
|
+
### Changed
|
|
66
|
+
|
|
67
|
+
- **任务状态徽标配色**:侧栏任务子行与目录列表按状态配色——等=蓝、跑=青绿、完=灰、档=淡灰。
|
|
68
|
+
- **验收条去掉「通行」**:done 本身即终态;反馈仍是新开一条任务(原任务留档)。
|
|
69
|
+
- **并入 main 既有的 md 编辑器改动(#99–#109,原未发版)**:@ 附件选择面板、
|
|
70
|
+
引用区并排原文、评论/反馈改为新开 md 编辑页、设置页重排等。
|
|
71
|
+
|
|
5
72
|
## [0.32.0] - 2026-11-08 附件模型 v2(存储版本 1→2,破坏性)
|
|
6
73
|
|
|
7
74
|
### Breaking
|
package/package.json
CHANGED
|
@@ -17,12 +17,14 @@ import { CURRENT_SCHEMA_VERSION } from '../version.js';
|
|
|
17
17
|
export const DIRECT_EDGES = [
|
|
18
18
|
{ from: 0, to: 1, file: 'v1.sql', title: '初始 schema(topics/tasks/refs/…)' },
|
|
19
19
|
{ from: 1, to: 2, file: 'v2.sql', title: '附件/资源统一模型', apply: migrateAttachments },
|
|
20
|
+
{ from: 2, to: 3, file: 'v3.sql', title: '模板可见域(scope/origin_topic)' },
|
|
20
21
|
];
|
|
21
22
|
|
|
22
23
|
// 人读版本说明(docs/decisions 是决策的唯一权威位置,里面对应一份 date 化的 .md)
|
|
23
24
|
export const VERSION_NOTES = {
|
|
24
25
|
1: 'docs/decisions/versions/2026-11-08-v1.md',
|
|
25
26
|
2: 'docs/decisions/versions/2026-11-08-v2.md',
|
|
27
|
+
3: 'docs/decisions/versions/2026-11-09-v3.md',
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
const keyOf = (from, to) => `${from}->${to}`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- schema v3:任务模板的可见域(scope)与创建来源(origin_topic)
|
|
2
|
+
--
|
|
3
|
+
-- 设计口径(2026-11-09,任务 #128,评估见 plan/2026-11-09-template-architecture-eval.md §2):
|
|
4
|
+
-- · 模板从「全机共享」升级为「带可见域」:scope 是 JSON 数组,条目三种前缀——
|
|
5
|
+
-- "*" 全局可见(缺省,行为与 v2 完全一致)
|
|
6
|
+
-- "topic:<key>" 指定队列主题可见(topics.key)
|
|
7
|
+
-- "repo:<key>" 指定项目可见(repos.key)
|
|
8
|
+
-- "group:<key>" 指定项目组可见(组也是 repos.key)
|
|
9
|
+
-- 可见判定 = scope 含 "*",或命中主题行的 key / repo_key / group_key 任一。
|
|
10
|
+
-- · origin_topic 记录「在哪个主题里创建的」:从主题页新建模板时默认只在该主题
|
|
11
|
+
-- 可见(scope 默认 [topic:<key>]),origin 是创建事实、不随 scope 改写;
|
|
12
|
+
-- 它同时是「编辑权」的锚(canEdit = origin 命中或 scope 显式点名本主题)。
|
|
13
|
+
--
|
|
14
|
+
-- 两列都带 NOT NULL DEFAULT:存量模板(含内置 seed 的四类目)原地升级为全局
|
|
15
|
+
-- 可见,零破坏——不跑数据回填脚本。
|
|
16
|
+
|
|
17
|
+
-- @decision docs/decisions/versions/2026-11-09-v3.md
|
|
18
|
+
ALTER TABLE templates ADD COLUMN scope TEXT NOT NULL DEFAULT '["*"]'
|
|
19
|
+
CHECK (json_valid(scope) AND json_type(scope) = 'array');
|
|
20
|
+
ALTER TABLE templates ADD COLUMN origin_topic TEXT NOT NULL DEFAULT '';
|
package/src/core/db/version.js
CHANGED
|
@@ -8,8 +8,11 @@
|
|
|
8
8
|
*
|
|
9
9
|
* v2(2026-11-08):新增 attachments / task_attach / ref_attach,删除 task_refs /
|
|
10
10
|
* ref_relations;旧 manifest.json 与正文 fileId 引用在迁移阶段落库。
|
|
11
|
+
*
|
|
12
|
+
* v3(2026-11-09):templates 加 scope(可见域 JSON 数组,默认 '["*"]')与
|
|
13
|
+
* origin_topic(创建来源主题,默认 '')——存量行原地升为全局可见,零破坏。
|
|
11
14
|
*/
|
|
12
|
-
export const CURRENT_SCHEMA_VERSION =
|
|
15
|
+
export const CURRENT_SCHEMA_VERSION = 3;
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* 运行时最低 Node 版本。
|
|
@@ -429,6 +429,31 @@ export default {
|
|
|
429
429
|
return `已标记完成: #${d.id} @ ${d.name}(${d.completedAt})${goal}`;
|
|
430
430
|
},
|
|
431
431
|
},
|
|
432
|
+
{
|
|
433
|
+
id: 'localtask.timegoalLog',
|
|
434
|
+
cli: ['localtask', 'timegoal-log'],
|
|
435
|
+
http: ['GET', '/api/localtasks/timegoal-log'],
|
|
436
|
+
summary: '查看任务级时间目标的每轮 check 记录(时间、已用/剩余、是否到点、当轮总结与进度)',
|
|
437
|
+
flags: { id: { type: 'number', required: true, hint: '任务编号' }, cwd: CWD, key: KEY },
|
|
438
|
+
run: async (ctx) => {
|
|
439
|
+
const topicKey = ctx.key || service.normalizeCwd(ctx.cwd).key;
|
|
440
|
+
const { getTaskGoalLog } = await import('../tasktool/timegoal.js');
|
|
441
|
+
return getTaskGoalLog({ topicKey, taskId: ctx.id });
|
|
442
|
+
},
|
|
443
|
+
render: (d) => {
|
|
444
|
+
if (!d.hasGoal) return `#${d.seq || ''} 没有任务级时间目标记录。`;
|
|
445
|
+
const lines = [`#${d.seq} 时间目标 check 记录 ${d.count} 轮(${d.duration} · ${d.startedAt} → ${d.deadline})`];
|
|
446
|
+
if (!d.count) lines.push(' (还没有 check 记录)');
|
|
447
|
+
d.entries.forEach((e, i) => {
|
|
448
|
+
lines.push(
|
|
449
|
+
` R${i + 1} ${e.checkedAt} 已用 ${e.elapsedSec}s · 剩余 ${e.remainingSec}s${e.reached ? ' · 已到点' : ''}`,
|
|
450
|
+
);
|
|
451
|
+
if (e.summary) lines.push(` ${e.summary}`);
|
|
452
|
+
if (e.progress) lines.push(` 进度: ${e.progress}`);
|
|
453
|
+
});
|
|
454
|
+
return lines.join('\n');
|
|
455
|
+
},
|
|
456
|
+
},
|
|
432
457
|
{
|
|
433
458
|
id: 'localtask.importRemote',
|
|
434
459
|
cli: ['localtask', 'import-remote'],
|
|
@@ -752,6 +777,40 @@ export default {
|
|
|
752
777
|
return head + skip + miss;
|
|
753
778
|
},
|
|
754
779
|
},
|
|
780
|
+
{
|
|
781
|
+
id: 'localtask.closeMany',
|
|
782
|
+
cli: ['localtask', 'close-many'],
|
|
783
|
+
http: ['POST', '/api/localtasks/items/close'],
|
|
784
|
+
summary:
|
|
785
|
+
'批量收口待领取任务(按 --ids,定位到 --cwd 主题或 --key):不要求先领取;--status done 写完成总结,cancelled 只改状态;已领取/已交付跳过',
|
|
786
|
+
flags: {
|
|
787
|
+
ids: { type: 'array', required: true, hint: '任务编号,逗号分隔或给多次' },
|
|
788
|
+
cwd: CWD,
|
|
789
|
+
key: KEY,
|
|
790
|
+
status: { type: 'string', hint: 'done(标为完成,默认)或 cancelled(取消)' },
|
|
791
|
+
summary: { type: 'string', hint: '完成总结(status=done 时可选)' },
|
|
792
|
+
},
|
|
793
|
+
run: (ctx) =>
|
|
794
|
+
service.closeTasks({
|
|
795
|
+
ids: ctx.ids,
|
|
796
|
+
cwd: ctx.cwd,
|
|
797
|
+
key: ctx.key,
|
|
798
|
+
status: ctx.status,
|
|
799
|
+
summary: ctx.summary,
|
|
800
|
+
}),
|
|
801
|
+
render: (d) => {
|
|
802
|
+
const done = d.closed.map((x) => `#${x.id}`).join(' ');
|
|
803
|
+
const verb = d.closeStatus === 'cancelled' ? '取消' : '标为完成';
|
|
804
|
+
const head = d.count
|
|
805
|
+
? `已在主题「${d.name}」${verb} ${d.count} 条待领取任务(${done})`
|
|
806
|
+
: `主题「${d.name}」没有可${verb}的待领取任务`;
|
|
807
|
+
const skip = d.skipped.length
|
|
808
|
+
? `;跳过 ${d.skipped.map((x) => `#${x.id}(${x.status})`).join(' ')}`
|
|
809
|
+
: '';
|
|
810
|
+
const miss = d.missing.length ? `;未找到 #${d.missing.join(' #')}` : '';
|
|
811
|
+
return head + skip + miss;
|
|
812
|
+
},
|
|
813
|
+
},
|
|
755
814
|
{
|
|
756
815
|
id: 'localtask.task.restore',
|
|
757
816
|
cli: ['localtask', 'task', 'restore'],
|
|
@@ -243,6 +243,29 @@ export function completeTask(topicId, seq, { feedback = '', atMs = nowMs() } = {
|
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
/**
|
|
247
|
+
* 用户侧关闭「待领取」任务(面板「标为完成 / 取消任务」):不要求先领取。
|
|
248
|
+
* 只动 pending ∧ 未删除;done 写完成总结与时刻,cancelled 只改状态(与批量取消同口径)。
|
|
249
|
+
*/
|
|
250
|
+
export function closePendingTask(topicId, seq, { status = 'done', feedback = '', atMs = nowMs() } = {}) {
|
|
251
|
+
const isDone = String(status) === 'done';
|
|
252
|
+
return txw((conn) => {
|
|
253
|
+
const r = isDone
|
|
254
|
+
? conn.run(
|
|
255
|
+
`UPDATE tasks SET status = 'done', done_at = :at, feedback_at = :at, feedback = :fb,
|
|
256
|
+
version = version + 1, updated_at = :at
|
|
257
|
+
WHERE topic_id = :t AND seq = :s AND status = 'pending' AND deleted_at IS NULL`,
|
|
258
|
+
{ t: topicId, s: seq, at: atMs, fb: String(feedback ?? '') }
|
|
259
|
+
)
|
|
260
|
+
: conn.run(
|
|
261
|
+
`UPDATE tasks SET status = 'cancelled', version = version + 1, updated_at = :at
|
|
262
|
+
WHERE topic_id = :t AND seq = :s AND status = 'pending' AND deleted_at IS NULL`,
|
|
263
|
+
{ t: topicId, s: seq, at: atMs }
|
|
264
|
+
);
|
|
265
|
+
return Number(r.changes) === 1;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
246
269
|
/**
|
|
247
270
|
* 字段级更新(reopen / update / 软删 / 恢复都用它)。
|
|
248
271
|
* `patch` 是 JSON 形态的字段子集;写不进任何列的低频字段进 ext。
|
|
@@ -79,16 +79,25 @@ export async function addTask({
|
|
|
79
79
|
// forkKind 缺省按 comment(评论/随手派生)——reopen 有自己的写入口(task-lifecycle)。
|
|
80
80
|
let forkOf = null; // 解析结果 { key, seq } —— 插入后写链
|
|
81
81
|
let forkKind = '';
|
|
82
|
+
// 楼数(#122):schema 语义(v1.sql tasks.round)「派生任务 = 来源任务的 round + 1」。
|
|
83
|
+
// 以前 add --fork-of 不带 round、落盘默认 1——链上第二轮会显示「1楼」,与 reopen
|
|
84
|
+
// 写入口(task-lifecycle:新 round = 父 round + 1)不一致。发布时按父任务算好。
|
|
85
|
+
let forkRound;
|
|
82
86
|
if (rawForkOf !== undefined && rawForkOf !== null && String(rawForkOf).trim() !== '') {
|
|
83
87
|
const ref = resolveForkRef(rawForkOf, key);
|
|
84
88
|
forkOf = { ref };
|
|
85
89
|
forkKind = rawForkKind === 'reopen' ? 'reopen' : 'comment';
|
|
90
|
+
const at = ref.lastIndexOf(':');
|
|
91
|
+
const parent = topicsRepo.getTopic(ref.slice(0, at));
|
|
92
|
+
const prow = parent && (parent.tasks || []).find((x) => Number(x.id) === Number(ref.slice(at + 1)));
|
|
93
|
+
if (prow) forkRound = (Number(prow.reopenCount) || 0) + 1 + 1; // 父 round(=reopenCount+1) + 1
|
|
86
94
|
}
|
|
87
95
|
const taskDraft = {
|
|
88
96
|
// 不写 id:真实编号由 insertTask 在事务内分配,避免事务外读号撞车
|
|
89
97
|
text: body,
|
|
90
98
|
status: 'pending',
|
|
91
99
|
timegoal,
|
|
100
|
+
round: forkRound,
|
|
92
101
|
blockBy: normalizeBlockBy(rawBlockBy, provisionalId),
|
|
93
102
|
blocksFollowing: !!blocksFollowing,
|
|
94
103
|
forkOf,
|
|
@@ -166,6 +166,75 @@ export async function cancelTasks({ cwd: rawCwd, key: rawKey, ids } = {}) {
|
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/**
|
|
170
|
+
* 批量收口「待领取」任务(面板「标为完成 / 取消」用):**不要求先领取**。
|
|
171
|
+
*
|
|
172
|
+
* 场景:有的任务在队列里等着被领,但其实用户已经自己干完了(或决定不做)。
|
|
173
|
+
* 以前只有 agent 领取后走 completeTask 才能收口;这里补上用户侧的直接操作。
|
|
174
|
+
* - status=done:写完成总结与完成时刻(总结缺省为「用户确认已完成(任务未领取,直接关闭)」)
|
|
175
|
+
* - status=cancelled:只改状态(与 cancelTasks 同口径,原文留档)
|
|
176
|
+
* 已领取(可能有 agent 正在处理)、已交付、已取消、已删除都跳过。
|
|
177
|
+
*/
|
|
178
|
+
export async function closeTasks({ cwd: rawCwd, key: rawKey, ids, status = 'done', summary = '' } = {}) {
|
|
179
|
+
const wantStatus = String(status ?? 'done');
|
|
180
|
+
if (wantStatus !== 'done' && wantStatus !== 'cancelled') {
|
|
181
|
+
throw badInput('--status 只接受 done / cancelled');
|
|
182
|
+
}
|
|
183
|
+
const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
|
|
184
|
+
const { cwd } = normalizeCwd(rawCwd);
|
|
185
|
+
const wants = (Array.isArray(ids) ? ids : [ids])
|
|
186
|
+
.map((x) => Number(String(x ?? '').trim()))
|
|
187
|
+
.filter((n) => Number.isFinite(n) && n > 0);
|
|
188
|
+
if (!wants.length) throw badInput('缺少参数 --ids <任务编号,逗号分隔或给多次>');
|
|
189
|
+
|
|
190
|
+
openStore();
|
|
191
|
+
const t = topicsRepo.getTopic(key);
|
|
192
|
+
const topicId = t ? t.id : null;
|
|
193
|
+
const closed = [];
|
|
194
|
+
const missing = [];
|
|
195
|
+
const skipped = [];
|
|
196
|
+
const feedback =
|
|
197
|
+
wantStatus === 'done'
|
|
198
|
+
? String(summary ?? '').trim() || '用户确认已完成(任务未领取,直接关闭)'
|
|
199
|
+
: '';
|
|
200
|
+
tx(() => {
|
|
201
|
+
for (const want of wants) {
|
|
202
|
+
const cur = topicId ? tasksRepo.getTaskRow(topicId, want) : null;
|
|
203
|
+
if (!cur) {
|
|
204
|
+
missing.push(want);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (cur.task.status !== 'pending' || cur.task.migratedTo || cur.task.deletedAt) {
|
|
208
|
+
skipped.push({
|
|
209
|
+
id: want,
|
|
210
|
+
status: cur.task.status,
|
|
211
|
+
reason: cur.task.migratedTo ? 'migrated' : cur.task.deletedAt ? 'deleted' : 'not_pending',
|
|
212
|
+
});
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const ok = tasksRepo.closePendingTask(topicId, want, { status: wantStatus, feedback });
|
|
216
|
+
if (!ok) {
|
|
217
|
+
skipped.push({ id: want, status: cur.task.status, reason: 'not_pending' });
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
closed.push(normalizeTask(tasksRepo.getTaskRow(topicId, want).task));
|
|
221
|
+
}
|
|
222
|
+
if (closed.length) topicsRepo.updateTopic(key, { bumpRevision: true });
|
|
223
|
+
return true;
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
status: 'ok',
|
|
227
|
+
key,
|
|
228
|
+
cwd: t ? t.cwd || cwd : cwd,
|
|
229
|
+
name: t ? t.name : key,
|
|
230
|
+
closeStatus: wantStatus,
|
|
231
|
+
closed,
|
|
232
|
+
missing,
|
|
233
|
+
skipped,
|
|
234
|
+
count: closed.length,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
169
238
|
/**
|
|
170
239
|
* 恢复一条被软删除的任务(撤销删除)。
|
|
171
240
|
* 与 removeTask 互为逆操作:任务仍在队列里,只是带着 deletedAt 标记。
|
|
@@ -228,6 +228,10 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
|
|
|
228
228
|
archivedAt: String(t.archivedAt ?? ''),
|
|
229
229
|
archivedReason: String(t.archivedReason ?? ''),
|
|
230
230
|
reopenCount: Number(t.reopenCount) || 0,
|
|
231
|
+
// 链上第几轮(#122 进程面板「楼数」):根任务 = 1,派生 = 来源 + 1(schema 语义
|
|
232
|
+
// 见 v1.sql tasks.round)。库里存的是 round 列,JSON 形态只带 reopenCount = round-1
|
|
233
|
+
// (repo/rows.js),这里换算回来 —— 前端显示「第 N 楼」/按楼搜索不必再回溯链。
|
|
234
|
+
round: Math.max(1, (Number(t.reopenCount) || 0) + 1),
|
|
231
235
|
// DAG / 闸门(#34):blockBy=依赖 id;blocksFollowing=挡住数组其后所有 pending
|
|
232
236
|
blockBy,
|
|
233
237
|
blocksFollowing,
|
|
@@ -683,6 +683,66 @@ export async function getTimegoalLog({ cwd: rawCwd } = {}) {
|
|
|
683
683
|
};
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
+
function durationLabel(sec) {
|
|
687
|
+
const s = Math.max(0, Number(sec) || 0);
|
|
688
|
+
if (s >= 3600 && s % 3600 === 0) return `${s / 3600}h`;
|
|
689
|
+
if (s >= 60 && s % 60 === 0) return `${s / 60}m`;
|
|
690
|
+
return `${s}s`;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* 任务维度的 check 流水:面板「查看每轮 check」与 CLI `localtask timegoal-log` 共用。
|
|
695
|
+
* 与队列级 getTimegoalLog 不同——任务级记录落在 goal_checks 行,逐轮读。
|
|
696
|
+
*/
|
|
697
|
+
export async function getTaskGoalLog({ topicKey, taskId: seq } = {}) {
|
|
698
|
+
const key = taskGoalKey(topicKey, seq);
|
|
699
|
+
if (!topicKey || seq === undefined || seq === null) {
|
|
700
|
+
return { hasGoal: false, key, seq: Number(seq) || 0, count: 0, entries: [] };
|
|
701
|
+
}
|
|
702
|
+
const row = goalsRepo.getGoalRowByTaskKey(topicKey, seq, ltDb());
|
|
703
|
+
if (!row) return { hasGoal: false, key, seq: Number(seq) || 0, count: 0, entries: [] };
|
|
704
|
+
const checks = goalsRepo.listChecks(Number(row.id), ltDb());
|
|
705
|
+
const view = goalRowToView(row);
|
|
706
|
+
return {
|
|
707
|
+
hasGoal: true,
|
|
708
|
+
key,
|
|
709
|
+
seq: Number(seq) || 0,
|
|
710
|
+
name: String(row.topic_name || ''),
|
|
711
|
+
cwd: String(row.topic_cwd || ''),
|
|
712
|
+
durationSec: Number(view.durationSec) || 0,
|
|
713
|
+
duration: durationLabel(view.durationSec),
|
|
714
|
+
startedAt: view.startedAt,
|
|
715
|
+
deadline: view.deadline,
|
|
716
|
+
archived: view.archived,
|
|
717
|
+
count: checks.length,
|
|
718
|
+
totalChecks: checks.length,
|
|
719
|
+
entries: checks.map((c) => {
|
|
720
|
+
let summary = '';
|
|
721
|
+
let progress = '';
|
|
722
|
+
try {
|
|
723
|
+
const v = JSON.parse(String(c.summary || '{}'));
|
|
724
|
+
if (v && typeof v === 'object') {
|
|
725
|
+
summary = String(v.summary || '');
|
|
726
|
+
progress = String(v.progress || '');
|
|
727
|
+
} else {
|
|
728
|
+
summary = String(c.summary || '');
|
|
729
|
+
}
|
|
730
|
+
} catch {
|
|
731
|
+
summary = String(c.summary || '');
|
|
732
|
+
}
|
|
733
|
+
return {
|
|
734
|
+
checkedAt: stampOf(c.at),
|
|
735
|
+
elapsedSec: Number(c.elapsed_sec) || 0,
|
|
736
|
+
remainingSec: Number(c.remaining_sec) || 0,
|
|
737
|
+
overtimeSec: Number(c.overtime_sec) || 0,
|
|
738
|
+
reached: !!c.reached,
|
|
739
|
+
summary,
|
|
740
|
+
progress,
|
|
741
|
+
};
|
|
742
|
+
}),
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
|
|
686
746
|
function normalizeLogField(raw, flag, maxLength) {
|
|
687
747
|
const value = String(raw ?? '').trim();
|
|
688
748
|
if (!value) throw badInput(`--${flag} 不能为空(每次 check 都会写入 timegoal 日志)`);
|
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
// 直接改默认),不凑 CRUD 五件的数,免得为了凑数造出没人用的命令。
|
|
8
8
|
import * as service from './service.js';
|
|
9
9
|
import { badInput } from '../../core/errors.js';
|
|
10
|
+
import { topicKeyOf } from '../../core/topic-key.js';
|
|
11
|
+
import { resolve as resolvePath } from 'node:path';
|
|
10
12
|
|
|
11
13
|
const renderList = (d) => {
|
|
12
14
|
const lines = [`模板 ${d.templates.length} 个(默认: ${d.defaultId})`];
|
|
13
15
|
for (const t of d.templates) {
|
|
14
16
|
const head = String(t.body || '').split('\n').find((l) => l.trim()) || '(空)';
|
|
15
|
-
|
|
17
|
+
const scopeMark = d.scoped
|
|
18
|
+
? ` · ${t.perm && t.perm.edit ? '本主题可编辑' : '仅可用'}`
|
|
19
|
+
: '';
|
|
20
|
+
lines.push(` ${t.id === d.defaultId ? '★' : ' '} ${t.id}${t.builtin ? ' [内置]' : ''} ${t.name} · ${head.trim().slice(0, 40)}${scopeMark}`);
|
|
16
21
|
}
|
|
17
22
|
return lines.join('\n');
|
|
18
23
|
};
|
|
@@ -32,6 +37,24 @@ function parseValues(raw) {
|
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
// 可见域:CLI 传 JSON 数组字符串(或逗号分隔短写),HTTP 传数组——归一(含非法
|
|
41
|
+
// 条目校验)在 service 层。cmd.exe 里塞 JSON 引号太痛苦,裸条目按逗号拆。
|
|
42
|
+
function parseScope(raw) {
|
|
43
|
+
if (raw === undefined || raw === null) return undefined;
|
|
44
|
+
if (typeof raw !== 'string') return raw;
|
|
45
|
+
const s = raw.trim();
|
|
46
|
+
if (!s) return undefined;
|
|
47
|
+
if (s.startsWith('[')) return s; // JSON 数组
|
|
48
|
+
return s.split(',').map((x) => x.trim()).filter(Boolean);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --cwd → 创建主题锚(与 localtask 同一派生:完整 cwd 小写折叠、无组上下文)。
|
|
52
|
+
function topicFromCwd(raw) {
|
|
53
|
+
const s = String(raw || '').trim();
|
|
54
|
+
if (!s) return undefined;
|
|
55
|
+
return topicKeyOf(resolvePath(s), '');
|
|
56
|
+
}
|
|
57
|
+
|
|
35
58
|
export default {
|
|
36
59
|
id: 'templates',
|
|
37
60
|
title: '任务模板(MD 工作台新建页的起始正文)',
|
|
@@ -44,14 +67,22 @@ export default {
|
|
|
44
67
|
cli: ['template', 'list'],
|
|
45
68
|
http: ['GET', '/api/templates'],
|
|
46
69
|
summary: '列出任务模板(含默认模板 id;新建页的起始正文按默认模板取)',
|
|
47
|
-
|
|
70
|
+
flags: {
|
|
71
|
+
topic: { type: 'string', hint: '按队列 topics.key 过滤(可与 --group/--repo 组合;响应带 scoped:true)' },
|
|
72
|
+
group: { type: 'string', hint: '按项目组 repos.key 过滤(#132:组本身是可见主体,与 topic/repo 平级)' },
|
|
73
|
+
repo: { type: 'string', hint: '按项目 repos.key 过滤' },
|
|
74
|
+
},
|
|
75
|
+
run: (ctx) =>
|
|
76
|
+
ctx.topic || ctx.group || ctx.repo
|
|
77
|
+
? service.listTemplatesForTopic({ topic: ctx.topic, group: ctx.group, repo: ctx.repo })
|
|
78
|
+
: service.listTemplates(),
|
|
48
79
|
render: renderList,
|
|
49
80
|
},
|
|
50
81
|
{
|
|
51
82
|
id: 'templates.add',
|
|
52
83
|
cli: ['template', 'add'],
|
|
53
84
|
http: ['POST', '/api/templates'],
|
|
54
|
-
summary: '新增任务模板(--body 给 Markdown 正文;多行正文用 --body-file <文件> 或 --body - 读管道;--setDefault
|
|
85
|
+
summary: '新增任务模板(--body 给 Markdown 正文;多行正文用 --body-file <文件> 或 --body - 读管道;--setDefault 同时设为默认;--scope 设可见域、--topic 记创建主题并默认仅该主题可见)',
|
|
55
86
|
args: ['name'],
|
|
56
87
|
flags: {
|
|
57
88
|
body: { type: 'string', hint: '模板正文(Markdown;首行写 `# 标题` 则提交时作为任务标题)' },
|
|
@@ -59,6 +90,9 @@ export default {
|
|
|
59
90
|
'body-file': { type: 'string', hint: '同 --bodyFile(连字符写法)' },
|
|
60
91
|
setDefault: { type: 'boolean', hint: '新增后立即设为默认模板' },
|
|
61
92
|
'set-default': { type: 'boolean', hint: '同 --setDefault(连字符写法)' },
|
|
93
|
+
scope: { type: 'raw', hint: '可见域(#128/#131):* 全局 / topic:<key> 队列 / repo:<key> 项目 / group:<key> 组——JSON 数组或逗号短写;缺省空(未配置,不默认全局);带 --topic 时默认仅该主题' },
|
|
94
|
+
topic: { type: 'string', hint: '创建主题锚(topics.key):默认仅该主题可见,origin_topic 记它' },
|
|
95
|
+
cwd: { type: 'string', hint: '同 --topic,但给工作目录(按目录派生主题 key)' },
|
|
62
96
|
},
|
|
63
97
|
// 读文件/读管道只给 CLI:HTTP 是面板的通道,不该变成「任意读本机文件」的入口
|
|
64
98
|
run: (ctx, opts) =>
|
|
@@ -67,20 +101,28 @@ export default {
|
|
|
67
101
|
body: ctx.body,
|
|
68
102
|
bodyFile: opts && opts.transport === 'http' ? undefined : (ctx.bodyFile ?? ctx['body-file']),
|
|
69
103
|
setDefault: ctx.setDefault ?? ctx['set-default'],
|
|
104
|
+
scope: parseScope(ctx.scope),
|
|
105
|
+
topic: ctx.topic || topicFromCwd(ctx.cwd),
|
|
70
106
|
}),
|
|
71
|
-
render: (d) =>
|
|
107
|
+
render: (d) =>
|
|
108
|
+
`已新增模板「${d.template.name}」(${d.template.id})${d.defaultId === d.template.id ? ',并设为默认' : ''}${
|
|
109
|
+
Array.isArray(d.template.scope) && !d.template.scope.includes('*')
|
|
110
|
+
? `,可见域 ${JSON.stringify(d.template.scope)}`
|
|
111
|
+
: ''
|
|
112
|
+
}`,
|
|
72
113
|
},
|
|
73
114
|
{
|
|
74
115
|
id: 'templates.update',
|
|
75
116
|
cli: ['template', 'update'],
|
|
76
117
|
http: ['PATCH', '/api/templates/:id'],
|
|
77
|
-
summary: '编辑任务模板(--name 改名 / --body
|
|
118
|
+
summary: '编辑任务模板(--name 改名 / --body 改正文 / --scope 改可见域,只改传入项;多行正文用 --body-file;内置模板的正文也可改)',
|
|
78
119
|
args: ['id'],
|
|
79
120
|
flags: {
|
|
80
121
|
name: { type: 'string', hint: '新名字(不传保持不变)' },
|
|
81
122
|
body: { type: 'string', hint: '新正文(Markdown;不传保持不变)' },
|
|
82
123
|
bodyFile: { type: 'string', hint: '从文件读新正文(--body 优先);`-` = 读标准输入' },
|
|
83
124
|
'body-file': { type: 'string', hint: '同 --bodyFile(连字符写法)' },
|
|
125
|
+
scope: { type: 'raw', hint: '可见域(#128):* / topic:<key> / repo:<key> / group:<key>,JSON 数组或逗号短写(不传保持不变)' },
|
|
84
126
|
values: {
|
|
85
127
|
type: 'string',
|
|
86
128
|
hint: '槽位值 JSON(形如 {"背景":"要做的事"})——老模板正文里的 {{槽位名}} 处填这段文字(新模板直接写正文即可)',
|
|
@@ -92,6 +134,7 @@ export default {
|
|
|
92
134
|
name: ctx.name,
|
|
93
135
|
body: ctx.body,
|
|
94
136
|
bodyFile: opts && opts.transport === 'http' ? undefined : (ctx.bodyFile ?? ctx['body-file']),
|
|
137
|
+
scope: parseScope(ctx.scope),
|
|
95
138
|
values: parseValues(ctx.values),
|
|
96
139
|
}),
|
|
97
140
|
render: (d) => `已更新模板「${d.template.name}」(${d.template.id})`,
|
|
@@ -111,18 +154,31 @@ export default {
|
|
|
111
154
|
http: ['PATCH', '/api/templates/default'],
|
|
112
155
|
// 这条路由同时管两件事——**字面量路由优先于 :id**(runtime/api.js 的路由排序:
|
|
113
156
|
// 字面量段在前),所以 id 恰是 'default' 的模板,正文更新会被这条路由截走:
|
|
114
|
-
// 带 name/body/values → 改**默认模板本身**(id 就是 default)
|
|
115
|
-
// 只带 id
|
|
157
|
+
// 带 name/body/values/scope → 改**默认模板本身**(id 就是 default)
|
|
158
|
+
// 只带 id → 把默认模板换成它
|
|
116
159
|
// 不分派的话,「默认模板」永远存不进去(面板里改默认模板 400,2026-11-07 任务 #87 实锤)。
|
|
117
|
-
summary: '设置默认模板(新建页的起始正文换成它);带 --body/--name 则改默认模板本身',
|
|
160
|
+
summary: '设置默认模板(新建页的起始正文换成它);带 --body/--name/--scope 则改默认模板本身',
|
|
118
161
|
args: ['id'],
|
|
162
|
+
// flag 声明补齐(之前一个都没声明):CLI 的 --body/--name/--scope 会撞
|
|
163
|
+
// 「未知参数」;声明之后 CLI 能传,HTTP 的 body 字段也照常落在 ctx 上。
|
|
164
|
+
// values/scope 用 raw:值本身是对象/数组,不能被 String() 压掉。
|
|
165
|
+
flags: {
|
|
166
|
+
name: { type: 'string', hint: '新名字(配合 --body/--scope 时改默认模板本身)' },
|
|
167
|
+
body: { type: 'string', hint: '新正文(配合时改默认模板本身)' },
|
|
168
|
+
values: { type: 'raw', hint: '槽位值 JSON(CLI 传 JSON 串;HTTP 可直接给对象)' },
|
|
169
|
+
scope: { type: 'raw', hint: '可见域(#128):* / topic:<key> / repo:<key> / group:<key>,JSON 数组或逗号短写' },
|
|
170
|
+
},
|
|
119
171
|
run: (ctx) => {
|
|
120
|
-
if (
|
|
172
|
+
if (
|
|
173
|
+
ctx.body !== undefined || ctx.name !== undefined ||
|
|
174
|
+
ctx.values !== undefined || ctx.scope !== undefined
|
|
175
|
+
) {
|
|
121
176
|
return service.updateTemplate({
|
|
122
177
|
id: ctx.id || 'default',
|
|
123
178
|
name: ctx.name,
|
|
124
179
|
body: ctx.body,
|
|
125
180
|
values: parseValues(ctx.values),
|
|
181
|
+
scope: parseScope(ctx.scope),
|
|
126
182
|
});
|
|
127
183
|
}
|
|
128
184
|
return service.setDefaultTemplate({ id: ctx.id });
|
|
@@ -47,9 +47,9 @@ export function insertIfAbsent(conn, row) {
|
|
|
47
47
|
conn.run(
|
|
48
48
|
`INSERT INTO templates (id, category, name, slot, body, vars_schema, vars, is_default,
|
|
49
49
|
enabled, sort_order, builtin, state, version, deleted_at,
|
|
50
|
-
created_at, updated_at)
|
|
50
|
+
created_at, updated_at, scope, origin_topic)
|
|
51
51
|
VALUES (:id, :category, :name, :slot, :body, :schema, :vars, :isDefault,
|
|
52
|
-
:enabled, :sort, :builtin, '', 0, NULL, :created, :updated)
|
|
52
|
+
:enabled, :sort, :builtin, '', 0, NULL, :created, :updated, :scope, :originTopic)
|
|
53
53
|
ON CONFLICT(id) DO NOTHING`,
|
|
54
54
|
{
|
|
55
55
|
id: row.id,
|
|
@@ -65,6 +65,9 @@ export function insertIfAbsent(conn, row) {
|
|
|
65
65
|
builtin: row.builtin ? 1 : 0,
|
|
66
66
|
created: row.createdAtMs,
|
|
67
67
|
updated: row.updatedAtMs,
|
|
68
|
+
// 可见域(v3):数组归一在 service 层做完,这里只管落库形状
|
|
69
|
+
scope: rowJson(row.scope, '["*"]'),
|
|
70
|
+
originTopic: String(row.originTopic || ''),
|
|
68
71
|
}
|
|
69
72
|
);
|
|
70
73
|
}
|
|
@@ -89,6 +92,11 @@ export function updateRow(conn, id, patch, atMs) {
|
|
|
89
92
|
sets.push('enabled = :enabled');
|
|
90
93
|
params.enabled = patch.enabled ? 1 : 0;
|
|
91
94
|
}
|
|
95
|
+
if (patch.scope !== undefined) {
|
|
96
|
+
sets.push('scope = :scope');
|
|
97
|
+
params.scope = rowJson(patch.scope, '["*"]');
|
|
98
|
+
}
|
|
99
|
+
// origin_topic 不进 updateRow:它是创建事实(v3 裁决),不随编辑改写
|
|
92
100
|
if (!sets.length) return !!getRow(id, conn);
|
|
93
101
|
sets.push('updated_at = :at');
|
|
94
102
|
const r = conn.run(`UPDATE templates SET ${sets.join(', ')} WHERE id = :id AND deleted_at IS NULL`, params);
|
|
@@ -129,5 +137,19 @@ export function nextSortOrder(conn, category) {
|
|
|
129
137
|
return Number((row && row.m) || -1) + 1;
|
|
130
138
|
}
|
|
131
139
|
|
|
140
|
+
/**
|
|
141
|
+
* 主题的三把钥匙(key / repo_key / group_key)——scope 判定只认这三列。
|
|
142
|
+
* 查无此主题返回 null(service 层降级为「只按裸 key 命中 + 全局」)。
|
|
143
|
+
* topics 是共享存储,这里只读三列,不复制 localtask 的仓储逻辑。
|
|
144
|
+
*/
|
|
145
|
+
export function getTopicKeys(key, conn = db()) {
|
|
146
|
+
return (
|
|
147
|
+
conn.get(
|
|
148
|
+
'SELECT key, repo_key, group_key FROM topics WHERE key = :key AND deleted_at IS NULL',
|
|
149
|
+
{ key: String(key || '') }
|
|
150
|
+
) || null
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
132
154
|
/** 事务入口的窄转发。 */
|
|
133
155
|
export { txw };
|