nx-kv 0.69.0 → 0.70.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 +69 -0
- package/README.md +20 -2
- package/package.json +21 -8
- package/packages/plugin-dir-annotate/dist/client/client.js +3 -0
- package/packages/plugin-dir-annotate/dist/client/style.css +2 -0
- package/packages/plugin-dir-annotate/dist/server/index.js +109 -0
- package/packages/plugin-dir-annotate/package.json +31 -0
- package/packages/plugin-dir-annotate/src/client/AnnotatePage.tsx +313 -0
- package/packages/plugin-dir-annotate/src/client/SettingsPage.tsx +116 -0
- package/packages/plugin-dir-annotate/src/client/index.tsx +23 -0
- package/packages/plugin-dir-annotate/src/client/style.css +91 -0
- package/packages/plugin-dir-annotate/src/server/index.ts +43 -0
- package/packages/plugin-dir-annotate/src/server/settings.ts +75 -0
- package/packages/plugin-dir-annotate/tsconfig.client.json +13 -0
- package/packages/plugin-dir-annotate/tsconfig.server.json +16 -0
- package/packages/plugin-dir-annotate/vite.config.ts +33 -0
- package/packages/plugin-sdk/dist/client.d.ts +56 -0
- package/packages/plugin-sdk/dist/client.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/client.js +2 -0
- package/packages/plugin-sdk/dist/client.js.map +1 -0
- package/packages/plugin-sdk/dist/index.d.ts +160 -0
- package/packages/plugin-sdk/dist/index.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/index.js +28 -0
- package/packages/plugin-sdk/dist/index.js.map +1 -0
- package/packages/plugin-sdk/dist/template.d.ts +5 -0
- package/packages/plugin-sdk/dist/template.d.ts.map +1 -0
- package/packages/plugin-sdk/dist/template.js +23 -0
- package/packages/plugin-sdk/dist/template.js.map +1 -0
- package/packages/plugin-sdk/package.json +27 -0
- package/packages/plugin-sdk/src/client.ts +63 -0
- package/packages/plugin-sdk/src/index.ts +183 -0
- package/packages/plugin-sdk/src/template.ts +24 -0
- package/packages/plugin-sdk/tsconfig.json +17 -0
- package/packages/plugin-task-template/dist/client/client.js +9 -0
- package/packages/plugin-task-template/dist/client/style.css +2 -0
- package/packages/plugin-task-template/dist/server/index.js +557 -0
- package/packages/plugin-task-template/package.json +31 -0
- package/packages/plugin-task-template/src/client/EntryForm.tsx +84 -0
- package/packages/plugin-task-template/src/client/EntryRow.tsx +15 -0
- package/packages/plugin-task-template/src/client/ManagePage.tsx +229 -0
- package/packages/plugin-task-template/src/client/index.tsx +28 -0
- package/packages/plugin-task-template/src/client/style.css +67 -0
- package/packages/plugin-task-template/src/server/builtin-body.ts +79 -0
- package/packages/plugin-task-template/src/server/index.ts +141 -0
- package/packages/plugin-task-template/src/server/scope.ts +56 -0
- package/packages/plugin-task-template/src/server/storage.ts +32 -0
- package/packages/plugin-task-template/src/server/templates.ts +317 -0
- package/packages/plugin-task-template/tsconfig.client.json +13 -0
- package/packages/plugin-task-template/tsconfig.server.json +16 -0
- package/packages/plugin-task-template/vite.config.ts +33 -0
- package/src/core/attachmentdb/resources.ts +8 -7
- package/src/core/db/bootstrap.ts +1 -10
- package/src/core/db/import-json/extras.ts +52 -32
- package/src/core/db/migrations/index.ts +10 -0
- package/src/core/db/migrations/v16-data.ts +0 -1
- package/src/core/db/migrations/v18.sql +24 -0
- package/src/core/db/migrations/v19-data.ts +62 -0
- package/src/core/db/migrations/v19.sql +41 -0
- package/src/core/db/migrations/v20-data.ts +71 -0
- package/src/core/db/migrations/v20.sql +6 -0
- package/src/core/db/migrations/v21.sql +7 -0
- package/src/core/db/repo-match.ts +0 -6
- package/src/core/db/verify.ts +4 -1
- package/src/core/db/version.ts +9 -1
- package/src/modules/db/actions/_manifest.generated.ts +3 -0
- package/src/modules/db/actions/db-data.ts +28 -0
- package/src/modules/db/service.ts +139 -0
- package/src/modules/localtask/actions/localtask-add.ts +4 -4
- package/src/modules/localtask/actions/localtask-boardtasks.ts +4 -17
- package/src/modules/localtask/actions/localtask-reopen.ts +1 -1
- package/src/modules/localtask/actions/localtask-tasks.ts +5 -18
- package/src/modules/localtask/infra/repo/tasks.ts +3 -3
- package/src/modules/localtask/infra/repo/topics.ts +8 -45
- package/src/modules/localtask/lifecycle/task-ops.ts +14 -0
- package/src/modules/localtask/lifecycle/task-view.ts +3 -6
- package/src/modules/localtask/lifecycle/topics.ts +16 -5
- package/src/modules/localtask/ops/attach-resource.ts +1 -7
- package/src/modules/plugin/actions/_manifest.generated.ts +47 -0
- package/src/modules/plugin/actions/plugin-context.ts +41 -0
- package/src/modules/plugin/actions/plugin-entries.ts +42 -0
- package/src/modules/plugin/actions/plugin-file.ts +28 -0
- package/src/modules/plugin/actions/plugin-list.ts +30 -0
- package/src/modules/plugin/actions/plugin-rpc.ts +37 -0
- package/src/modules/plugin/actions/plugin-set-default.ts +23 -0
- package/src/modules/plugin/actions/plugin-set-state.ts +26 -0
- package/src/modules/plugin/actions/plugin-set-visibility.ts +42 -0
- package/src/modules/plugin/actions/plugin-tree.ts +31 -0
- package/src/modules/plugin/actions/plugin-visibility.ts +28 -0
- package/src/modules/plugin/actions/pretask-draft.ts +47 -0
- package/src/modules/plugin/assets.ts +51 -0
- package/src/modules/plugin/context.ts +196 -0
- package/src/modules/plugin/fs.ts +169 -0
- package/src/modules/plugin/host.ts +396 -0
- package/src/modules/plugin/index.ts +21 -0
- package/src/modules/plugin/plugins.generated.ts +14 -0
- package/src/modules/plugin/registry.ts +109 -0
- package/src/modules/plugin/repo/db.ts +12 -0
- package/src/modules/plugin/repo/legacy.ts +45 -0
- package/src/modules/plugin/repo/migrations.ts +22 -0
- package/src/modules/plugin/repo/state.ts +32 -0
- package/src/modules/plugin/repo/visibility.ts +94 -0
- package/src/modules/plugin/service.ts +12 -0
- package/src/modules/plugin/template.ts +16 -0
- package/src/modules/repos/actions/_manifest.generated.ts +3 -0
- package/src/modules/repos/actions/repo-dirs.ts +37 -0
- package/src/modules/repos/service/dirs.ts +61 -0
- package/src/runtime/registry.ts +2 -2
- package/src/runtime/server.ts +36 -0
- package/src/shared/task-title.ts +32 -0
- package/src/web/frontend/App.tsx +29 -65
- package/src/web/frontend/api/cli-tree.json +164 -50
- package/src/web/frontend/api/client.generated.ts +160 -61
- package/src/web/frontend/app-context.tsx +0 -3
- package/src/web/frontend/components/layout/crumbs.ts +13 -10
- package/src/web/frontend/components/layout/vsc-crumbs-model.ts +1 -0
- package/src/web/frontend/components/layout/vsc-crumbs.css +15 -0
- package/src/web/frontend/components/layout/vsc-crumbs.tsx +11 -0
- package/src/web/frontend/components/md/attachments/attach-modal.tsx +1 -1
- package/src/web/frontend/components/md/composer/composer-panel.tsx +14 -144
- 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/md-panes-helpers.ts +1 -3
- package/src/web/frontend/components/md/panes/md-panes.tsx +2 -0
- package/src/web/frontend/components/md/pm/pm-editor-host.tsx +35 -0
- package/src/web/frontend/components/md/pm/pm-editor.tsx +209 -0
- package/src/web/frontend/components/md/pm/pm.css +47 -0
- package/src/web/frontend/components/popup/index.tsx +9 -0
- package/src/web/frontend/components/popup/style.css +4 -0
- package/src/web/frontend/components/sidebar/index.tsx +5 -3
- package/src/web/frontend/components/sidebar/ns-dialogs.tsx +2 -2
- package/src/web/frontend/components/sidebar/ns-manage-modal.tsx +75 -17
- package/src/web/frontend/components/sidebar/plugin-foot.tsx +30 -0
- package/src/web/frontend/components/sidebar/queue-nav.ts +15 -10
- package/src/web/frontend/components/sidebar/task-children.tsx +23 -3
- package/src/web/frontend/components/sidebar/use-ns.ts +12 -14
- package/src/web/frontend/components/tool-acts/layout-panel.tsx +2 -8
- package/src/web/frontend/components/tool-acts/style.css +0 -2
- package/src/web/frontend/modules/md/md-parse.ts +1 -1
- package/src/web/frontend/modules/md/pm/adapter.ts +99 -0
- package/src/web/frontend/modules/md/pm/inline.ts +241 -0
- package/src/web/frontend/modules/md/pm/schema.ts +150 -0
- package/src/web/frontend/modules/md/styles/editor.css +0 -26
- package/src/web/frontend/modules/md/styles/panels.css +3 -0
- package/src/web/frontend/modules/pretask/menu.tsx +31 -0
- package/src/web/frontend/modules/pretask/open-entry.ts +139 -0
- package/src/web/frontend/modules/pretask/types.ts +45 -0
- package/src/web/frontend/modules/pretask/use-plugins.ts +45 -0
- package/src/web/frontend/modules/pretask/use-pretask.ts +111 -0
- package/src/web/frontend/page/data/api.ts +49 -0
- package/src/web/frontend/page/data/index.tsx +89 -0
- package/src/web/frontend/page/data/style.css +84 -0
- package/src/web/frontend/page/data/table-view.tsx +126 -0
- package/src/web/frontend/page/dir/index.tsx +52 -57
- package/src/web/frontend/page/dir/task-actions.ts +6 -5
- package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
- package/src/web/frontend/page/dir/task-utils.ts +3 -2
- package/src/web/frontend/page/dir/task.tsx +15 -10
- package/src/web/frontend/page/doc/index.tsx +4 -2
- package/src/web/frontend/page/group/index.tsx +90 -72
- package/src/web/frontend/page/settings/index.tsx +14 -1
- package/src/web/frontend/page/settings/plugins-section.tsx +78 -0
- package/src/web/frontend/panels.tsx +15 -26
- package/src/web/frontend/plugin-host/loader.ts +92 -0
- package/src/web/frontend/plugin-host/plugin-component.tsx +22 -0
- package/src/web/frontend/plugin-host/plugin-page.tsx +103 -0
- package/src/web/frontend/plugin-host/registry.ts +80 -0
- package/src/web/frontend/plugin-host/session.ts +29 -0
- package/src/web/frontend/plugin-host/style.css +41 -0
- package/src/web/frontend/plugin-host/visibility-panel.tsx +233 -0
- package/src/web/frontend/registry.ts +2 -0
- package/src/web/frontend/routes/index.ts +4 -3
- package/src/web/frontend/routes/plugin.ts +37 -0
- package/src/web/frontend/routes/route-eq.ts +5 -1
- package/src/web/frontend/routes/static.ts +3 -0
- package/src/web/frontend/styles-v2/sidebar.css +21 -2
- package/src/web/frontend/types.ts +5 -40
- package/src/web/frontend/use-ns-persist.ts +15 -4
- package/src/web/frontend/workspace/areas.ts +2 -1
- package/src/web/frontend/workspace/open.ts +32 -1
- package/src/web/frontend/workspace/panels.ts +1 -1
- package/src/web/public/assets/app-context-DnSScbEM.js +1 -0
- package/src/web/public/assets/bar-BEUdeltT.js +1 -0
- package/src/web/public/assets/board-view-DS6VzeG9.js +1 -0
- package/src/web/public/assets/client-73i4d2M4.js +1 -0
- package/src/web/public/assets/composer-launch-BOiu_85p.js +1 -0
- package/src/web/public/assets/composer-panel-BTWUPrF4.js +1 -0
- package/src/web/public/assets/dag-HEqXue8k.js +1 -0
- package/src/web/public/assets/data-Br0MR-Xk.css +1 -0
- package/src/web/public/assets/data-DJR0eP7U.js +1 -0
- package/src/web/public/assets/dir-BvcqEReL.js +1 -0
- package/src/web/public/assets/doc-store-sv1-1xal.js +1 -0
- package/src/web/public/assets/group-DhOuMegf.js +1 -0
- package/src/web/public/assets/icons-B05qzdxw.js +1 -0
- package/src/web/public/assets/index-BTYjj0YL.css +1 -0
- package/src/web/public/assets/index-_cjoyGJr.js +27 -0
- package/src/web/public/assets/md-history-CumFTbbK.js +45 -0
- package/src/web/public/assets/md-parse-BhjiD83o.js +6 -0
- package/src/web/public/assets/member-picker-B2EiDJ87.js +1 -0
- package/src/web/public/assets/plugin-component-BL69zZxx.js +1 -0
- package/src/web/public/assets/plugin-page-CLYrGvrM.js +1 -0
- package/src/web/public/assets/popup-DqWl8bjK.js +1 -0
- package/src/web/public/assets/popup-DrRYEe1w.css +1 -0
- package/src/web/public/assets/progress-DeGuv-S0.js +3 -0
- package/src/web/public/assets/refs-XyV92GFq.js +2 -0
- package/src/web/public/assets/registry-B4536DGP.js +1 -0
- package/src/web/public/assets/{reopen-text-D0eQ2XAC.js → reopen-text-cEGm0jzz.js} +1 -1
- package/src/web/public/assets/repos-BtKLD2-Y.js +12 -0
- package/src/web/public/assets/session-y2Ujr5bl.js +1 -0
- package/src/web/public/assets/settings-C6Wp4TEN.js +1 -0
- package/src/web/public/assets/style-BjfD0mtO.css +1 -0
- package/src/web/public/assets/task-DGOTk3il.css +1 -0
- package/src/web/public/assets/task-Dntjc9kS.js +14 -0
- package/src/web/public/assets/task-ops-V0KvmOJt.js +2 -0
- package/src/web/public/assets/task-status-DmR2rgbz.js +1 -0
- package/src/web/public/assets/task-utils-BJnDgdnA.js +1 -0
- package/src/web/public/assets/toast-OkR-KSSm.css +1 -0
- package/src/web/public/assets/toast-RYmip1Zl.js +1 -0
- package/src/web/public/assets/{tool-bar-CLIs9Dr0.css → tool-bar-B3K3eMeS.css} +1 -1
- package/src/web/public/assets/tool-bar-CeRPJ9OK.js +1 -0
- package/src/web/public/assets/use-pretask-QAtAPePc.js +1 -0
- package/src/web/public/assets/visibility-panel-BhCkxAHB.js +1 -0
- package/src/web/public/assets/workspace-C7kkUJNn.js +28 -0
- package/src/web/public/index.html +20 -17
- package/src/core/db/seed-templates.ts +0 -202
- package/src/modules/templates/actions/_manifest.generated.ts +0 -32
- package/src/modules/templates/actions/template-add.ts +0 -52
- package/src/modules/templates/actions/template-default.ts +0 -45
- package/src/modules/templates/actions/template-list.ts +0 -34
- package/src/modules/templates/actions/template-remove.ts +0 -31
- package/src/modules/templates/actions/template-reorder.ts +0 -28
- package/src/modules/templates/actions/template-update.ts +0 -43
- package/src/modules/templates/index.ts +0 -24
- package/src/modules/templates/repo/index.ts +0 -16
- package/src/modules/templates/repo/open.ts +0 -72
- package/src/modules/templates/repo/templates.ts +0 -185
- package/src/modules/templates/scope.ts +0 -113
- package/src/modules/templates/service.ts +0 -409
- package/src/modules/templates/support.ts +0 -32
- package/src/web/frontend/modules/md/fill-session.ts +0 -36
- package/src/web/frontend/modules/md/manage-session.ts +0 -24
- package/src/web/frontend/modules/md/new-task-from-template.ts +0 -22
- package/src/web/frontend/modules/md/use-templates.ts +0 -183
- package/src/web/frontend/modules/prompts/render-template-body.ts +0 -14
- package/src/web/frontend/modules/prompts/template-preview.ts +0 -61
- package/src/web/frontend/page/templates/fill.tsx +0 -128
- package/src/web/frontend/page/templates/index.tsx +0 -297
- package/src/web/frontend/page/templates/manage.tsx +0 -188
- package/src/web/frontend/page/templates/style.css +0 -93
- package/src/web/frontend/page/templates/template-list.tsx +0 -175
- package/src/web/frontend/routes/templates.ts +0 -85
- package/src/web/public/assets/app-context-DPFYOrgE.js +0 -1
- package/src/web/public/assets/bar-I4qGaKTO.js +0 -1
- package/src/web/public/assets/board-view-jt8QixVg.js +0 -1
- package/src/web/public/assets/button-DA4lNJeC.css +0 -1
- package/src/web/public/assets/button-VP4pjVsx.js +0 -1
- package/src/web/public/assets/composer-launch-BL344XZg.js +0 -1
- package/src/web/public/assets/composer-panel-D0ojgf7z.js +0 -1
- package/src/web/public/assets/dag-BY0lf-Nl.js +0 -1
- package/src/web/public/assets/dir-BNHyviHQ.js +0 -1
- package/src/web/public/assets/doc-Ka-2V5jn.css +0 -1
- package/src/web/public/assets/doc-wmc4swmo.js +0 -6
- package/src/web/public/assets/group-BSQ9_Gjs.js +0 -1
- package/src/web/public/assets/index-D2P-v30u.js +0 -3
- package/src/web/public/assets/index-DHLeXl42.css +0 -1
- package/src/web/public/assets/manage-session-CuaL7QqQ.js +0 -1
- package/src/web/public/assets/md-history-D0bYVPZY.js +0 -47
- package/src/web/public/assets/md-parse-BjzYV8n7.js +0 -6
- package/src/web/public/assets/member-picker-BtWykPer.js +0 -1
- package/src/web/public/assets/popup-DLfU1TXG.js +0 -1
- package/src/web/public/assets/popup-DzBICcYS.css +0 -1
- package/src/web/public/assets/progress-CQAvP9-n.js +0 -3
- package/src/web/public/assets/refs-Cf4ZbAra.js +0 -2
- package/src/web/public/assets/repo-form-modal-BahZhXq3.js +0 -1
- package/src/web/public/assets/repos-C2cZtRFo.js +0 -12
- package/src/web/public/assets/route-crumb-DS76cmRK.js +0 -1
- package/src/web/public/assets/settings-C_VmzG7F.js +0 -1
- package/src/web/public/assets/task-C4Sqe4vT.js +0 -14
- package/src/web/public/assets/task-Dcd2eA8B.css +0 -1
- package/src/web/public/assets/task-ops-SFagO-OC.js +0 -2
- package/src/web/public/assets/task-utils-Y-j-zi8J.js +0 -1
- package/src/web/public/assets/template-preview-EM3OQ1Rc.js +0 -1
- package/src/web/public/assets/templates-B8jnGSAl.js +0 -10
- package/src/web/public/assets/templates-DiEKBY-m.css +0 -1
- package/src/web/public/assets/tool-bar-NHeX0Kmo.js +0 -28
- package/src/web/public/assets/use-rail-drag-CtZxisjE.js +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- v18(#200 续):修复「活任务挂在软删队列上」的存量幽灵队列。
|
|
2
|
+
--
|
|
3
|
+
-- 背景:历史版本里 prune(旧模型分支)/ 直接删除曾把带待领任务的队列软删
|
|
4
|
+
-- (tasks 保留),任务变成「任何 cwd 都领不到」的幽灵。#197 起队列必须绑
|
|
5
|
+
-- 真实仓库、任务必须可寻址——这类存量与口径冲突。
|
|
6
|
+
--
|
|
7
|
+
-- 处理口径:**恢复队列,不删任务**(数据最安全——任务内容自包含,目录虽然
|
|
8
|
+
-- 可能已不存在,agent 仍可按 cwd 显式领取;UI 的 cwdExists=false 幽灵标志
|
|
9
|
+
-- 本来就有,用户可以自行决定清掉或留着)。
|
|
10
|
+
-- · 待领(status='pending')→ 必须恢复:这是没跑完的活。
|
|
11
|
+
-- · done / cancelled → 不动:已完成的任务挂在死队列里只是历史记录,恢复
|
|
12
|
+
-- 反而让幽灵队列重新出现在侧栏。
|
|
13
|
+
-- @decision docs/decisions/versions/2026-11-25-v18.md
|
|
14
|
+
UPDATE topics
|
|
15
|
+
SET deleted_at = NULL,
|
|
16
|
+
updated_at = CAST(strftime('%s','now') AS INTEGER) * 1000
|
|
17
|
+
WHERE deleted_at IS NOT NULL
|
|
18
|
+
AND cwd <> '' -- 组队列(cwd 空)不恢复:组任务走 group_topic_id 关联寻址,不依赖目录队列可见性
|
|
19
|
+
AND EXISTS (
|
|
20
|
+
SELECT 1 FROM tasks
|
|
21
|
+
WHERE tasks.repo_topic_id = topics.id
|
|
22
|
+
AND tasks.deleted_at IS NULL
|
|
23
|
+
AND tasks.status = 'pending'
|
|
24
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// v18 → v19 数据迁移:把旧任务模板的用户行搬进 plugin_legacy_data 暂存。
|
|
2
|
+
//
|
|
3
|
+
// 内置行(builtin=1)不搬:任务模板的内置正文改为插件包代码声明。
|
|
4
|
+
// templates 表暂不删除(v20 在旧内置实现删除后 drop),这里只做一次性暂存。
|
|
5
|
+
import type { DbApi } from '../driver.js';
|
|
6
|
+
|
|
7
|
+
export interface V19Context {
|
|
8
|
+
atMs?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const KIND = 'templates';
|
|
12
|
+
const PLUGIN_ID = 'task-template';
|
|
13
|
+
|
|
14
|
+
/** 读旧 templates 的用户行;表不存在时返回空。 */
|
|
15
|
+
function readUserRows(conn: DbApi): any[] {
|
|
16
|
+
const has = conn.get("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'templates'");
|
|
17
|
+
if (!has) return [];
|
|
18
|
+
return conn.all(
|
|
19
|
+
`SELECT id, name, body, vars_schema, vars, is_default, sort_order, scope, origin_topic,
|
|
20
|
+
created_at, updated_at, builtin, category
|
|
21
|
+
FROM templates
|
|
22
|
+
WHERE category = 'newtask' AND builtin = 0 AND deleted_at IS NULL
|
|
23
|
+
ORDER BY sort_order, id`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function readDefaultId(conn: DbApi): string {
|
|
28
|
+
const has = conn.get("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'templates'");
|
|
29
|
+
if (!has) return 'newtask.ref';
|
|
30
|
+
const row = conn.get(
|
|
31
|
+
"SELECT id FROM templates WHERE category = 'newtask' AND is_default = 1 AND deleted_at IS NULL LIMIT 1",
|
|
32
|
+
);
|
|
33
|
+
return row ? String(row.id) : 'newtask.ref';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function payloadOf(conn: DbApi): { rows: any[]; defaultId: string } {
|
|
37
|
+
return { rows: readUserRows(conn), defaultId: readDefaultId(conn) };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function writePayload(conn: DbApi, payload: { rows: any[]; defaultId: string }, atMs: number): void {
|
|
41
|
+
conn.run(
|
|
42
|
+
`INSERT INTO plugin_legacy_data (plugin_id, kind, payload_json, created_at)
|
|
43
|
+
VALUES (:p, :k, :body, :at)
|
|
44
|
+
ON CONFLICT(plugin_id, kind) DO UPDATE SET payload_json = excluded.payload_json`,
|
|
45
|
+
{ p: PLUGIN_ID, k: KIND, body: JSON.stringify(payload), at: atMs },
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function stageLegacyTemplates(conn: DbApi, { atMs = Date.now() }: V19Context = {}): {
|
|
50
|
+
rows: number;
|
|
51
|
+
defaultId: string;
|
|
52
|
+
} {
|
|
53
|
+
const payload = payloadOf(conn);
|
|
54
|
+
writePayload(conn, payload, atMs);
|
|
55
|
+
conn.run(
|
|
56
|
+
`INSERT INTO plugin_state (plugin_id, enabled, updated_at)
|
|
57
|
+
VALUES (:p, 1, :at)
|
|
58
|
+
ON CONFLICT(plugin_id) DO NOTHING`,
|
|
59
|
+
{ p: PLUGIN_ID, at: atMs },
|
|
60
|
+
);
|
|
61
|
+
return { rows: payload.rows.length, defaultId: payload.defaultId };
|
|
62
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- v19:内部插件宿主的四张宿主表。
|
|
2
|
+
--
|
|
3
|
+
-- 插件自己的业务表不在这里:由插件包的 migrateStorage(db, fromVersion) 创建,
|
|
4
|
+
-- 宿主只记 plugin_storage_migrations 的版本号。本文件只建宿主级数据:
|
|
5
|
+
-- plugin_state 全局开关(缺行 = 用 manifest defaultEnabled)
|
|
6
|
+
-- plugin_entry_visibility 每个 scope 的入口可见性/顺序(缺行 = 可见)
|
|
7
|
+
-- plugin_legacy_data 旧内置能力的迁移暂存(task-template 从这里取 v18 templates)
|
|
8
|
+
-- plugin_storage_migrations 插件自有表结构的版本账本
|
|
9
|
+
-- @decision docs/decisions/versions/2026-11-27-v19.md
|
|
10
|
+
-- @decision docs/decisions/versions/2026-11-27-v19.md
|
|
11
|
+
CREATE TABLE IF NOT EXISTS plugin_state (
|
|
12
|
+
plugin_id TEXT PRIMARY KEY,
|
|
13
|
+
enabled INTEGER NOT NULL DEFAULT 1 CHECK (enabled IN (0, 1)),
|
|
14
|
+
updated_at INTEGER NOT NULL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- @decision docs/decisions/versions/2026-11-27-v19.md
|
|
18
|
+
CREATE TABLE IF NOT EXISTS plugin_entry_visibility (
|
|
19
|
+
scope_key TEXT NOT NULL, -- topic:<key> / repo:<key> / group:<key>
|
|
20
|
+
entry_id TEXT NOT NULL, -- <pluginId>:<localId>
|
|
21
|
+
visible INTEGER NOT NULL DEFAULT 1 CHECK (visible IN (0, 1)),
|
|
22
|
+
sort_order INTEGER NOT NULL DEFAULT 0,
|
|
23
|
+
updated_at INTEGER NOT NULL,
|
|
24
|
+
PRIMARY KEY (scope_key, entry_id)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
-- @decision docs/decisions/versions/2026-11-27-v19.md
|
|
28
|
+
CREATE TABLE IF NOT EXISTS plugin_legacy_data (
|
|
29
|
+
plugin_id TEXT NOT NULL,
|
|
30
|
+
kind TEXT NOT NULL,
|
|
31
|
+
payload_json TEXT NOT NULL CHECK (json_valid(payload_json)),
|
|
32
|
+
created_at INTEGER NOT NULL,
|
|
33
|
+
PRIMARY KEY (plugin_id, kind)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
-- @decision docs/decisions/versions/2026-11-27-v19.md
|
|
37
|
+
CREATE TABLE IF NOT EXISTS plugin_storage_migrations (
|
|
38
|
+
plugin_id TEXT PRIMARY KEY,
|
|
39
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
40
|
+
applied_at INTEGER NOT NULL
|
|
41
|
+
);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// v19 → v20 数据迁移:补拷最后一刻的旧用户模板,然后删除 templates 表。
|
|
2
|
+
//
|
|
3
|
+
// v19 已把当时的用户行写入 plugin_legacy_data;v19 与 v20 之间旧代码理论上还能写
|
|
4
|
+
// 新模板,所以这里按模板 id 合并一次,再 drop。插件首次激活时消费 legacy 数据。
|
|
5
|
+
import type { DbApi } from '../driver.js';
|
|
6
|
+
|
|
7
|
+
export interface V20Context {
|
|
8
|
+
atMs?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const KIND = 'templates';
|
|
12
|
+
const PLUGIN_ID = 'task-template';
|
|
13
|
+
|
|
14
|
+
function readUserRows(conn: DbApi): any[] {
|
|
15
|
+
const has = conn.get("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'templates'");
|
|
16
|
+
if (!has) return [];
|
|
17
|
+
return conn.all(
|
|
18
|
+
`SELECT id, name, body, vars_schema, vars, is_default, sort_order, scope, origin_topic,
|
|
19
|
+
created_at, updated_at, builtin, category
|
|
20
|
+
FROM templates
|
|
21
|
+
WHERE category = 'newtask' AND builtin = 0 AND deleted_at IS NULL
|
|
22
|
+
ORDER BY sort_order, id`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readDefaultId(conn: DbApi): string {
|
|
27
|
+
const has = conn.get("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'templates'");
|
|
28
|
+
if (!has) return 'newtask.ref';
|
|
29
|
+
const row = conn.get(
|
|
30
|
+
"SELECT id FROM templates WHERE category = 'newtask' AND is_default = 1 AND deleted_at IS NULL LIMIT 1",
|
|
31
|
+
);
|
|
32
|
+
return row ? String(row.id) : 'newtask.ref';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function readStaged(conn: DbApi): { rows: any[]; defaultId: string } {
|
|
36
|
+
const row = conn.get(
|
|
37
|
+
'SELECT payload_json FROM plugin_legacy_data WHERE plugin_id = :p AND kind = :k',
|
|
38
|
+
{ p: PLUGIN_ID, k: KIND },
|
|
39
|
+
);
|
|
40
|
+
if (!row) return { rows: [], defaultId: 'newtask.ref' };
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(String(row.payload_json));
|
|
43
|
+
return {
|
|
44
|
+
rows: Array.isArray(parsed?.rows) ? parsed.rows : [],
|
|
45
|
+
defaultId: typeof parsed?.defaultId === 'string' ? parsed.defaultId : 'newtask.ref',
|
|
46
|
+
};
|
|
47
|
+
} catch {
|
|
48
|
+
return { rows: [], defaultId: 'newtask.ref' };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function finalizeLegacyTemplates(conn: DbApi, { atMs = Date.now() }: V20Context = {}): {
|
|
53
|
+
rows: number;
|
|
54
|
+
dropped: boolean;
|
|
55
|
+
} {
|
|
56
|
+
const has = !!conn.get("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'templates'");
|
|
57
|
+
const staged = readStaged(conn);
|
|
58
|
+
const byId = new Map<string, any>();
|
|
59
|
+
for (const row of staged.rows) if (row && row.id) byId.set(String(row.id), row);
|
|
60
|
+
for (const row of readUserRows(conn)) if (row && row.id) byId.set(String(row.id), row);
|
|
61
|
+
const defaultId = readDefaultId(conn) || staged.defaultId || 'newtask.ref';
|
|
62
|
+
const payload = { rows: [...byId.values()], defaultId };
|
|
63
|
+
conn.run(
|
|
64
|
+
`INSERT INTO plugin_legacy_data (plugin_id, kind, payload_json, created_at)
|
|
65
|
+
VALUES (:p, :k, :body, :at)
|
|
66
|
+
ON CONFLICT(plugin_id, kind) DO UPDATE SET payload_json = excluded.payload_json`,
|
|
67
|
+
{ p: PLUGIN_ID, k: KIND, body: JSON.stringify(payload), at: atMs },
|
|
68
|
+
);
|
|
69
|
+
if (has) conn.exec('DROP TABLE templates');
|
|
70
|
+
return { rows: payload.rows.length, dropped: has };
|
|
71
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- v21:plugin_entry_visibility 增加 is_default(每个 scope 一个「新建页」默认入口)。
|
|
2
|
+
--
|
|
3
|
+
-- 只加列、不重建表:v19 已有行保持原样,is_default 默认 0 = 跟随插件声明的默认;
|
|
4
|
+
-- 配了但入口被隐藏时,宿主在 listEntries 里回落到可见入口,不改这里的行。
|
|
5
|
+
-- @decision docs/decisions/versions/2026-11-27-v21.md
|
|
6
|
+
ALTER TABLE plugin_entry_visibility
|
|
7
|
+
ADD COLUMN is_default INTEGER NOT NULL DEFAULT 0 CHECK (is_default IN (0, 1));
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// 口径与 repos 服务一致:路径归一(小写 + 反斜杠转正斜杠 + 去尾斜杠)后,
|
|
4
4
|
// 精确优先,否则最长前缀(嵌套登记时更具体的仓库赢)。
|
|
5
5
|
// #197 起队列必须绑真实仓库,不再有 __unbound__ 哨兵。
|
|
6
|
-
import { existsSync } from 'node:fs';
|
|
7
6
|
|
|
8
7
|
/** 路径归一。 */
|
|
9
8
|
export function normRepoPath(p: unknown): string {
|
|
@@ -45,8 +44,3 @@ export function autoRepoKey(cwd: unknown, taken: Set<string>): string {
|
|
|
45
44
|
while (taken.has(key)) key = `local/${base}-${n++}`;
|
|
46
45
|
return key;
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
/** 目录当前是否还在(迁移决定「保留并登记」还是「连任务清理」)。 */
|
|
50
|
-
export function cwdExists(cwd: unknown): boolean {
|
|
51
|
-
return !!cwd && existsSync(String(cwd));
|
|
52
|
-
}
|
package/src/core/db/verify.ts
CHANGED
package/src/core/db/version.ts
CHANGED
|
@@ -47,7 +47,15 @@
|
|
|
47
47
|
// topics.group_key 启用(组任务拆 (cwd, group_key) 独立队列),删哨兵仓库 #197。
|
|
48
48
|
// v17(2026-11-24):归属规范成两条 topic 关联——tasks.repo_topic_id(必填,编号/领取按它)
|
|
49
49
|
// + tasks.group_topic_id(可空,组归属);丢弃 repo_key,组队列换成 group:<组key> 形态 #197。
|
|
50
|
-
|
|
50
|
+
// v18(2026-11-25):恢复带待领任务的软删队列(幽灵队列——活任务挂软删队列任何 cwd
|
|
51
|
+
// 都领不到);prune 的旧模型分支同步补 pending 守卫 #200。
|
|
52
|
+
// v19(2026-11-27):内部插件宿主表(plugin_state / entry_visibility / legacy_data /
|
|
53
|
+
// storage_migrations);旧 templates 用户行暂存为 plugin_legacy_data。
|
|
54
|
+
// v20(2026-11-27):删除 templates(内置任务模板由 packages/plugin-task-template 接管);
|
|
55
|
+
// v20-data 先补拷最后一刻用户行再 DROP。
|
|
56
|
+
// v21(2026-11-27):plugin_entry_visibility 增加 is_default——每个 scope 可指定
|
|
57
|
+
// 「+ 新建页」默认触发哪个插件列表项(缺省仍跟随插件声明)。
|
|
58
|
+
export const CURRENT_SCHEMA_VERSION = 21;
|
|
51
59
|
|
|
52
60
|
/**
|
|
53
61
|
* 运行时最低 Node 版本。
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { ActionBase } from '../../../runtime/action-base.js';
|
|
8
8
|
import type { Container } from '../../../runtime/container.js';
|
|
9
9
|
import { DbBackupAction } from './db-backup.js';
|
|
10
|
+
import { DbDataAction } from './db-data.js';
|
|
10
11
|
import { DbMigrateAction } from './db-migrate.js';
|
|
11
12
|
import { DbStatusAction } from './db-status.js';
|
|
12
13
|
import { DbVerifyAction } from './db-verify.js';
|
|
@@ -14,6 +15,7 @@ import { DbVerifyAction } from './db-verify.js';
|
|
|
14
15
|
/** 本模块的全部 action 类(容器按这个顺序建实例)。 */
|
|
15
16
|
export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
|
|
16
17
|
DbBackupAction,
|
|
18
|
+
DbDataAction,
|
|
17
19
|
DbMigrateAction,
|
|
18
20
|
DbStatusAction,
|
|
19
21
|
DbVerifyAction,
|
|
@@ -21,6 +23,7 @@ export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
|
|
|
21
23
|
|
|
22
24
|
// 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
|
|
23
25
|
export { DbBackupAction };
|
|
26
|
+
export { DbDataAction };
|
|
24
27
|
export { DbMigrateAction };
|
|
25
28
|
export { DbStatusAction };
|
|
26
29
|
export { DbVerifyAction };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// db.data —— 库数据只读导出:不带 --table 给全表概览(行数 + 列清单),
|
|
2
|
+
// 带 --table 给该表的行窗口(LIMIT/OFFSET 分页)。面板「数据库」页的数据源。
|
|
3
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
6
|
+
import * as serviceNs from '../service.js';
|
|
7
|
+
const service: any = serviceNs;
|
|
8
|
+
|
|
9
|
+
/** db.data 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
10
|
+
const input = z.object({
|
|
11
|
+
table: z.string().optional().describe('只看这张表(缺省给全表概览)'),
|
|
12
|
+
limit: z.number().default(200).describe('行窗口大小(1–1000,缺省 200)'),
|
|
13
|
+
offset: z.number().default(0).describe('行窗口起点(缺省 0)'),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export class DbDataAction extends ActionBase<typeof input> {
|
|
17
|
+
@action({
|
|
18
|
+
id: 'db.data',
|
|
19
|
+
cli: ['db', 'data'],
|
|
20
|
+
http: ['GET', '/api/db/data'],
|
|
21
|
+
summary: '库数据只读导出:全表概览或单表行窗口(不触发导入、不升级)',
|
|
22
|
+
input,
|
|
23
|
+
render: (d: any) => service.renderData(d),
|
|
24
|
+
})
|
|
25
|
+
override async run(ctx: ActionInput<this['_input']>) {
|
|
26
|
+
return service.data({ table: ctx.table, limit: ctx.limit, offset: ctx.offset });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from '../../core/db/bootstrap.js';
|
|
18
18
|
import { backupDatabase, fileHasContent, getMeta } from '../../core/db/migrator.js';
|
|
19
19
|
import { tableCounts, statusDistribution, verifyStore } from '../../core/db/verify.js';
|
|
20
|
+
import { notFound } from '../../core/errors.js';
|
|
20
21
|
import { CURRENT_SCHEMA_VERSION, REQUIRED_NODE_VERSION } from '../../core/db/version.js';
|
|
21
22
|
import { nowMs, stampFileTag } from '../../core/db/time.js';
|
|
22
23
|
|
|
@@ -209,6 +210,128 @@ export async function backup({ dir, keep = 5 }: { dir?: string; keep?: number }
|
|
|
209
210
|
return { path: out.path, removed: out.removed, dir: target, keep: keepCount, version: inspectStore(db).userVersion };
|
|
210
211
|
}
|
|
211
212
|
|
|
213
|
+
/** 一列的形状(PRAGMA table_info 收窄后的两列)。 */
|
|
214
|
+
export interface DataColumn {
|
|
215
|
+
name: string;
|
|
216
|
+
type: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** 一张表的概要:名字、行数、列清单。 */
|
|
220
|
+
export interface DbTableInfo {
|
|
221
|
+
name: string;
|
|
222
|
+
count: number;
|
|
223
|
+
columns: DataColumn[];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** `db data`(不带 --table)的结果形状:全表概览。 */
|
|
227
|
+
export interface DbDataShape {
|
|
228
|
+
path: string;
|
|
229
|
+
exists: boolean;
|
|
230
|
+
userVersion: number;
|
|
231
|
+
currentSchemaVersion: number;
|
|
232
|
+
tables: DbTableInfo[];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** `db data --table <t>` 的结果形状:一张表的行(窗口内)。 */
|
|
236
|
+
export interface DbTableRowsShape {
|
|
237
|
+
path: string;
|
|
238
|
+
table: string;
|
|
239
|
+
count: number;
|
|
240
|
+
columns: DataColumn[];
|
|
241
|
+
rows: Record<string, unknown>[];
|
|
242
|
+
limit: number;
|
|
243
|
+
offset: number;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** 行数窗口上限:本机单用户库不大,但也不能让一个请求拖回整库。 */
|
|
247
|
+
const DATA_MAX_LIMIT = 1000;
|
|
248
|
+
const DATA_DEFAULT_LIMIT = 200;
|
|
249
|
+
|
|
250
|
+
/** sqlite_master 里的用户表清单(排除 sqlite_% 内部表),按名字排序保证输出稳定。 */
|
|
251
|
+
function userTables(db: any): string[] {
|
|
252
|
+
return db
|
|
253
|
+
.all("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name")
|
|
254
|
+
.map((r: any) => String(r.name));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** PRAGMA table_info → [{name, type}](SQLite 标识符双引号转义后拼接)。 */
|
|
258
|
+
function columnsOf(db: any, table: string): DataColumn[] {
|
|
259
|
+
const quoted = `"${table.replace(/"/g, '""')}"`;
|
|
260
|
+
return db.all(`PRAGMA table_info(${quoted})`).map((c: any) => ({
|
|
261
|
+
name: String(c.name),
|
|
262
|
+
type: String(c.type || ''),
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 面板要展示的值:node:sqlite 的 BLOB 回 Uint8Array,JSON.stringify 会变成
|
|
268
|
+
* `{"0":137,...}` 字节噪声——换成一行可读摘要;其余类型原样放行。
|
|
269
|
+
*/
|
|
270
|
+
function cellValue(v: unknown): unknown {
|
|
271
|
+
if (v instanceof Uint8Array) return `<blob ${v.byteLength} bytes>`;
|
|
272
|
+
if (typeof v === 'bigint') return v.toString();
|
|
273
|
+
return v;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function sanitizeRow(row: Record<string, unknown>): Record<string, unknown> {
|
|
277
|
+
const out: Record<string, unknown> = {};
|
|
278
|
+
for (const [k, v] of Object.entries(row)) out[k] = cellValue(v);
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 库数据只读导出(面板「数据库」页的数据源)。
|
|
284
|
+
*
|
|
285
|
+
* 不带 table → 全表概览(每表行数 + 列清单);带 table → 该表的行窗口。
|
|
286
|
+
* **只读**:有库文件时按只读连接打开(与 status() 同一纪律);表名不是拼接进
|
|
287
|
+
* SQL 的自由文本——先对 sqlite_master 清单做白名单校验,再双引号转义。
|
|
288
|
+
*/
|
|
289
|
+
export async function data(
|
|
290
|
+
{ table, limit, offset }: { table?: string; limit?: number; offset?: number } = {},
|
|
291
|
+
): Promise<DbDataShape | DbTableRowsShape> {
|
|
292
|
+
const path = dbPath();
|
|
293
|
+
const existed = fileHasContent(path);
|
|
294
|
+
const db: any = existed
|
|
295
|
+
? openStore({ readOnly: true, importLegacyData: false })
|
|
296
|
+
: openStore({ importLegacyData: false });
|
|
297
|
+
|
|
298
|
+
const cap = Math.min(DATA_MAX_LIMIT, Math.max(1, Math.floor(Number(limit) || DATA_DEFAULT_LIMIT)));
|
|
299
|
+
const skip = Math.max(0, Math.floor(Number(offset) || 0));
|
|
300
|
+
const names = userTables(db);
|
|
301
|
+
const overview: DbTableInfo[] = names.map((name) => {
|
|
302
|
+
const row = db.get(`SELECT count(*) AS c FROM "${name.replace(/"/g, '""')}"`);
|
|
303
|
+
return { name, count: Number((row && row.c) || 0), columns: columnsOf(db, name) };
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
if (!table) {
|
|
307
|
+
const state: any = inspectStore(db);
|
|
308
|
+
return {
|
|
309
|
+
path,
|
|
310
|
+
exists: existed,
|
|
311
|
+
userVersion: state.userVersion,
|
|
312
|
+
currentSchemaVersion: CURRENT_SCHEMA_VERSION,
|
|
313
|
+
tables: overview,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const hit = overview.find((t) => t.name === table);
|
|
318
|
+
if (!hit) {
|
|
319
|
+
throw notFound(`表不存在: ${table}(可用: ${names.join(', ')})`);
|
|
320
|
+
}
|
|
321
|
+
const rows = db
|
|
322
|
+
.all(`SELECT * FROM "${hit.name.replace(/"/g, '""')}" LIMIT ? OFFSET ?`, [cap, skip])
|
|
323
|
+
.map(sanitizeRow);
|
|
324
|
+
return {
|
|
325
|
+
path,
|
|
326
|
+
table: hit.name,
|
|
327
|
+
count: hit.count,
|
|
328
|
+
columns: hit.columns,
|
|
329
|
+
rows,
|
|
330
|
+
limit: cap,
|
|
331
|
+
offset: skip,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
212
335
|
// ─── 渲染(纯文本,给人和 agent 看)────────────────────────────────────
|
|
213
336
|
|
|
214
337
|
const fmtMs = (ms: any): string => (ms ? new Date(Number(ms)).toISOString() : '(无)');
|
|
@@ -338,3 +461,19 @@ export function renderBackup(d: BackupShape): string {
|
|
|
338
461
|
if (d.removed && d.removed.length) lines.push(`清理旧备份: ${d.removed.join(', ')}`);
|
|
339
462
|
return lines.join('\n');
|
|
340
463
|
}
|
|
464
|
+
|
|
465
|
+
/** db data 的文本渲染:概览 = 表行数清单;带表 = 行的紧凑 JSON。 */
|
|
466
|
+
export function renderData(d: DbDataShape | DbTableRowsShape): string {
|
|
467
|
+
if ('rows' in d) {
|
|
468
|
+
const head = `${d.table}(第 ${d.offset + 1}–${d.offset + d.rows.length} 行,共 ${d.count} 行)`;
|
|
469
|
+
if (!d.rows.length) return `${head}\n(窗口内 0 行)`;
|
|
470
|
+
return `${head}\n${d.rows.map((r) => JSON.stringify(r)).join('\n')}`;
|
|
471
|
+
}
|
|
472
|
+
const lines = [`库数据: ${d.path}(user_version=${d.userVersion},代码支持 v${d.currentSchemaVersion})`];
|
|
473
|
+
lines.push(`表 ${d.tables.length} 张:`);
|
|
474
|
+
const width = Math.max(...d.tables.map((t) => t.name.length), 8);
|
|
475
|
+
for (const t of d.tables) {
|
|
476
|
+
lines.push(` ${t.name.padEnd(width + 2)}${String(t.count).padStart(6)} (${t.columns.length} 列)`);
|
|
477
|
+
}
|
|
478
|
+
return lines.join('\n');
|
|
479
|
+
}
|
|
@@ -42,8 +42,8 @@ const input = z.object({
|
|
|
42
42
|
file: z.string().optional().describe("从本机文件读任务正文(- 表示标准输入)——长文本/多行不必靠引号硬拼"),
|
|
43
43
|
cwd: z.string().optional().describe("工作目录(作为主题;默认当前目录)。归属由 --project 决定:给了 --project 就用它推导落点,这里再给且不一致会报错"),
|
|
44
44
|
summary: z.string().optional().describe("顺带刷新该主题的当前现状(可选)"),
|
|
45
|
-
board: z.string().optional().describe("工作组(看板)id / key /
|
|
46
|
-
project: z.string().optional().describe("归属项目(仓库 key / 名称 /
|
|
45
|
+
board: z.string().optional().describe("工作组(看板)id / key / 名称:给任务建立组队列关联(#197 起是库内 topics.group_topic_id,不再写正文),该任务才会出现在组面板里;必须同时给 --project 指明归属项目"),
|
|
46
|
+
project: z.string().optional().describe("归属项目(仓库 key / 名称 / 路径):任务挂在哪个项目上,落点目录由它推导,归属仓库落库(tasks.repo_topic_id 关联);配 --board 时必须是该组成员"),
|
|
47
47
|
duration: z.string().optional().describe("时间目标时长(2h / 90m / 5小时):领取即计时,未到点不许标完成"),
|
|
48
48
|
'goal-prompt': z.string().optional().describe("时间目标的附加要求(随 check 指令一起固化,可省)"),
|
|
49
49
|
goalPrompt: z.string().optional().describe("同 --goal-prompt(驼峰写法)"),
|
|
@@ -61,7 +61,7 @@ export class LocaltaskAddAction extends ActionBase<typeof input> {
|
|
|
61
61
|
id: 'localtask.add',
|
|
62
62
|
cli: ['localtask', 'add'],
|
|
63
63
|
http: ['POST', '/api/localtasks'],
|
|
64
|
-
summary: '
|
|
64
|
+
summary: '向某主题(工作目录)的队列回填一条任务(正文可多行 markdown;--file <文件|-> 从文件/标准输入读,长文本不必靠引号硬拼;有 wait 在等则即时投递,否则排队);--duration 给任务带时间目标(领取即计时,完成前必须 check);--board/--project 让任务落库归属(组队列 + 仓库队列两条 topic 关联,正文不写任何头),并落进该项目的队列',
|
|
65
65
|
args: ['text'],
|
|
66
66
|
input,
|
|
67
67
|
output: addView,
|
|
@@ -76,7 +76,7 @@ export class LocaltaskAddAction extends ActionBase<typeof input> {
|
|
|
76
76
|
if (!body.trim()) throw badInput('任务正文为空:给 "<正文>" 或 --file <文件>');
|
|
77
77
|
|
|
78
78
|
// 派任务编排已迁 localtask/add.ts(派任务编排归 localtask 域;命令名不变)。
|
|
79
|
-
// 落点判定(--board/--project
|
|
79
|
+
// 落点判定(--board/--project 严格口径)只此一份实现,
|
|
80
80
|
// CLI、HTTP、面板提交同走这一条链路。
|
|
81
81
|
const { submitTask } = await (import('../lifecycle/add.js') as any);
|
|
82
82
|
const rawBlock: any = ctx.blockBy ?? ctx['block-by'];
|
|
@@ -22,6 +22,7 @@ import { z } from 'zod';
|
|
|
22
22
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
23
23
|
import * as boardsNs from '../../repos/boards.js';
|
|
24
24
|
import { db } from '../infra/repo/index.js';
|
|
25
|
+
import { taskHeadingOf as titleOf } from '../../../shared/task-title.js';
|
|
25
26
|
|
|
26
27
|
const boardsSvc: any = boardsNs;
|
|
27
28
|
|
|
@@ -49,7 +50,7 @@ const taskRow = z.object({
|
|
|
49
50
|
const output = z.object({
|
|
50
51
|
boards: z.array(
|
|
51
52
|
z.object({
|
|
52
|
-
id: z.string().describe('看板 id
|
|
53
|
+
id: z.string().describe('看板 id(组队列 topic 的 group_key,组页建任务时落库关联的就是它)'),
|
|
53
54
|
key: z.string().describe('看板键(board/xxx)'),
|
|
54
55
|
name: z.string().describe('看板名称'),
|
|
55
56
|
pending: z.int().describe('本组待领取数(= side bar 徽标口径)'),
|
|
@@ -65,26 +66,12 @@ function stampOf(ms: unknown): string {
|
|
|
65
66
|
return Number.isFinite(n) && n > 0 ? new Date(n).toISOString().replace('T', ' ').slice(0, 19) : '';
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
/** 取正文里的标题:跳过 frontmatter,首个 `#` 标题优先,否则首行;按 80 字截断。 */
|
|
69
|
-
function titleOf(text: unknown): string {
|
|
70
|
-
const raw = String(text ?? '');
|
|
71
|
-
let body = raw;
|
|
72
|
-
if (raw.startsWith('---')) {
|
|
73
|
-
const end = raw.indexOf('\n---', 3);
|
|
74
|
-
if (end > 0) body = raw.slice(end + 4);
|
|
75
|
-
}
|
|
76
|
-
const lines = body.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
77
|
-
const heading = lines.find((l) => /^#{1,6}\s+/.test(l));
|
|
78
|
-
const line = (heading ?? lines[0] ?? '').replace(/^#{1,6}\s+/, '');
|
|
79
|
-
return line.length > 80 ? line.slice(0, 80) + '…' : line;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
69
|
export class LocaltaskBoardTasksAction extends ActionBase<typeof input> {
|
|
83
70
|
@action({
|
|
84
71
|
id: 'localtask.boardtasks',
|
|
85
72
|
cli: ['localtask', 'boardtasks'],
|
|
86
73
|
http: ['GET', '/api/localtasks/boardtasks'],
|
|
87
|
-
summary: '全部项目组的本组任务(端侧组页 /
|
|
74
|
+
summary: '全部项目组的本组任务(端侧组页 / 侧栏徽标一次拿全):按库内组队列关联(tasks.group_topic_id)聚合,带归属项目',
|
|
88
75
|
input,
|
|
89
76
|
output,
|
|
90
77
|
render: (d: any) => {
|
|
@@ -101,7 +88,7 @@ export class LocaltaskBoardTasksAction extends ActionBase<typeof input> {
|
|
|
101
88
|
override async run(ctx: ActionInput<this['_input']>) {
|
|
102
89
|
const want = String(ctx.board ?? '').trim();
|
|
103
90
|
const boardList: any[] = ((await boardsSvc.listBoards())?.boards ?? []) as any[];
|
|
104
|
-
// 定位 & 归一:id / key / 名称都认(面板写 id
|
|
91
|
+
// 定位 & 归一:id / key / 名称都认(面板写 id,CLI 手写可能是 key/名)
|
|
105
92
|
const picked = want
|
|
106
93
|
? boardList.filter((b) => [b.id, b.key, b.name].filter(Boolean).map(String).includes(want))
|
|
107
94
|
: boardList;
|
|
@@ -11,7 +11,7 @@ const input = z.object({
|
|
|
11
11
|
id: z.number().describe("任务编号"),
|
|
12
12
|
cwd: z.string().optional(),
|
|
13
13
|
key: z.string().optional(),
|
|
14
|
-
text: z.string().optional().describe("
|
|
14
|
+
text: z.string().optional().describe("下一轮任务正文(纯 Markdown;归属在库内关联,正文不带任何头部);不给则继承旧正文,只带 --feedback 时追加轮次 callout([!NOTE] 完成总结 + [!WARNING] 验收反馈)"),
|
|
15
15
|
kind: z.string().optional().describe("reopen(验收反馈,默认)或 comment(划选评论)"),
|
|
16
16
|
quote: z.string().optional().describe("划选原文(comment 时)"),
|
|
17
17
|
feedback: z.string().optional().describe("用户反馈原文;派生出的新任务正文会追加 [!WARNING] 验收反馈 callout(base = 服务端最新正文,防连续评论丢内容)"),
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { action } from '../../../runtime/action-decorator.js';
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
15
|
+
import { taskHeadingOf as titleOf } from '../../../shared/task-title.js';
|
|
15
16
|
import * as serviceNs from '../service.js';
|
|
16
17
|
|
|
17
18
|
const service: any = serviceNs;
|
|
@@ -56,21 +57,6 @@ const output = z.object({
|
|
|
56
57
|
tasks: z.array(row),
|
|
57
58
|
});
|
|
58
59
|
|
|
59
|
-
/** 取正文里的标题:跳过 frontmatter,首个 `#` 标题优先,否则首行;按 80 字截断。 */
|
|
60
|
-
function titleOf(text: unknown): string {
|
|
61
|
-
const raw = String(text ?? '');
|
|
62
|
-
// frontmatter:文件以 --- 开头时,跳到第二个 --- 之后
|
|
63
|
-
let body = raw;
|
|
64
|
-
if (raw.startsWith('---')) {
|
|
65
|
-
const end = raw.indexOf('\n---', 3);
|
|
66
|
-
if (end > 0) body = raw.slice(end + 4);
|
|
67
|
-
}
|
|
68
|
-
const lines = body.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
69
|
-
const heading = lines.find((l) => /^#{1,6}\s+/.test(l));
|
|
70
|
-
const line = (heading ?? lines[0] ?? '').replace(/^#{1,6}\s+/, '');
|
|
71
|
-
return line.length > 80 ? line.slice(0, 80) + '…' : line;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
60
|
export class LocaltaskTasksAction extends ActionBase<typeof input> {
|
|
75
61
|
@action({
|
|
76
62
|
id: 'localtask.tasks',
|
|
@@ -91,8 +77,9 @@ export class LocaltaskTasksAction extends ActionBase<typeof input> {
|
|
|
91
77
|
override async run(ctx: ActionInput<this['_input']>) {
|
|
92
78
|
const { resolveTopicKey } = await (import('../paths.js') as any);
|
|
93
79
|
const key = resolveTopicKey({ key: ctx.key, cwd: ctx.cwd });
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
// #200 对抗审查:单主题查询直接 getTopic(一条索引 SQL),不再 listTasks
|
|
81
|
+
// 全量拉所有主题 + 全部任务正文只为 find 一个 key。
|
|
82
|
+
const topic = await service.getTopicView(key);
|
|
96
83
|
if (!topic) {
|
|
97
84
|
const { badInput } = await (import('../../../core/errors.js') as any);
|
|
98
85
|
throw badInput(`主题不存在: ${key}`);
|
|
@@ -122,7 +109,7 @@ export class LocaltaskTasksAction extends ActionBase<typeof input> {
|
|
|
122
109
|
status: t.status,
|
|
123
110
|
title: titleOf(t.text),
|
|
124
111
|
round: t.round ?? 1,
|
|
125
|
-
// 组任务标注:normalizeTask
|
|
112
|
+
// 组任务标注:normalizeTask 从 tasks.group_topic_id 带出 boardMark(#197),
|
|
126
113
|
// 这里只做「缺省为空串」的形状收口 —— 别在这层再解析一遍正文。
|
|
127
114
|
// #197:组归属来自 DB 关联(boardKey/boardMark 同源)
|
|
128
115
|
board: t.boardMark || t.boardKey || '',
|
|
@@ -139,9 +139,9 @@ function rowToTaskWithDeps(conn: DbApi, row: Record<string, any>): TaskRowWithDe
|
|
|
139
139
|
/**
|
|
140
140
|
* 插入一条任务。`task` 是 JSON 形态(text/status/createdAt/consumedAt/...),
|
|
141
141
|
* 缺省与旧 store 的「normalizeTask + push」一致:status='pending'、createdAt=now。
|
|
142
|
-
* @returns {{id: number, task: object}}
|
|
142
|
+
* @returns {{id: number, rowId: number, task: object}} id=队列内编号(seq);rowId=行主键(链/资源引用用)
|
|
143
143
|
*/
|
|
144
|
-
export function insertTask(topicId: number, task: TaskPatch = {}): { id: number; task: TaskObject } {
|
|
144
|
+
export function insertTask(topicId: number, task: TaskPatch = {}): { id: number; rowId: number; task: TaskObject } {
|
|
145
145
|
return txw((conn) => {
|
|
146
146
|
const at = nowMs();
|
|
147
147
|
// 编号必须在同一个事务里取:事务外的 next_seq 会被别的进程同时读到,
|
|
@@ -192,7 +192,7 @@ export function insertTask(topicId: number, task: TaskPatch = {}): { id: number;
|
|
|
192
192
|
writeLocalDeps(conn, topicId, Number(row.id), fields.depsLocal);
|
|
193
193
|
// 正文里已经写了 fileId / nxkv 链接:入库即建资源关系,不等到领取才解析。
|
|
194
194
|
syncTaskAttachments(conn, { taskId: Number(row.id), text: c.body ?? '', atMs: at });
|
|
195
|
-
return { id: seq, task: getTaskRow(topicId, seq, conn)!.task };
|
|
195
|
+
return { id: seq, rowId: Number(row.id), task: getTaskRow(topicId, seq, conn)!.task };
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
|