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,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2023", "DOM"],
|
|
6
|
+
"module": "NodeNext",
|
|
7
|
+
"moduleResolution": "NodeNext",
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationMap": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"composite": false,
|
|
14
|
+
"types": ["node"]
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*.ts"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
(function(e,t){function n({entry:t}){return(0,e.jsxs)(`span`,{className:`tpl-row`,children:[(0,e.jsx)(`span`,{className:`tpl-row-name`,children:t.label}),t.builtin?(0,e.jsx)(`span`,{className:`tpl-badge soft`,children:`内置`}):null,t.description?(0,e.jsx)(`span`,{className:`tpl-row-desc`,children:t.description}):null]})}function r({api:n}){let r=n.entry,i=r?.slots||[],[a,o]=(0,t.useState)(()=>{let e={};for(let t of i)e[t.key]=String(r?.values?.[t.key]??t.default??``);return e}),[s,c]=(0,t.useState)(!1);if(!r)return(0,e.jsx)(`div`,{className:`rp-page tpl-fill-page`,children:(0,e.jsx)(`div`,{className:`muted`,style:{padding:20},children:`参数会话已失效——请从「新建任务」下拉重新选择模板。`})});let l=async(e=!1)=>{if(!s){c(!0);try{let t=await n.draft(r.id,a);n.createDraft(t,{submit:e})}catch(e){n.toast(String(e.message||e))}finally{c(!1)}}};return(0,e.jsxs)(`div`,{className:`rp-page tpl-fill-page`,children:[(0,e.jsxs)(`div`,{className:`page-head`,children:[(0,e.jsxs)(`div`,{className:`title-block`,children:[(0,e.jsx)(`h2`,{children:`填写模板参数`}),(0,e.jsxs)(`p`,{className:`muted tpl-head-note`,children:[`「`,r.label,`」· 全部可选,留空即为空白。生成的是纯文本任务,编辑页不会再出现槽位框。`]})]}),(0,e.jsx)(`div`,{className:`acts`,children:(0,e.jsx)(`button`,{type:`button`,className:`btn ghost sm`,onClick:()=>n.closePage(),children:`返回`})})]}),(0,e.jsx)(`div`,{className:`tpl-fill-body`,children:i.length===0?(0,e.jsx)(`div`,{className:`muted tpl-fill-empty`,children:`这条模板没有参数槽位,可直接进入任务编辑。`}):i.map(t=>(0,e.jsxs)(`label`,{className:`tpl-fill-field`,children:[(0,e.jsx)(`span`,{className:`tpl-fill-label`,children:t.label||t.key}),(0,e.jsx)(`textarea`,{className:`tpl-fill-input`,value:a[t.key]??``,placeholder:t.hint||`填写「${t.label||t.key}」(可留空)`,onChange:e=>o(n=>({...n,[t.key]:e.target.value})),rows:4})]},t.key))}),(0,e.jsxs)(`div`,{className:`tpl-fill-foot`,children:[(0,e.jsx)(`button`,{type:`button`,className:`btn ghost sm`,onClick:()=>n.closePage(),children:`返回`}),(0,e.jsx)(`button`,{type:`button`,className:`btn ghost sm`,disabled:s,onClick:()=>void l(!1),children:`进入编辑页(草稿)`}),(0,e.jsx)(`button`,{type:`button`,className:`btn primary sm`,disabled:s,onClick:()=>void l(!0),children:`直接提交`})]})]})}function i({api:n}){let[r,i]=(0,t.useState)(null),[o,s]=(0,t.useState)(null),[c,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(``),f=e=>{e&&Array.isArray(e.templates)&&i({defaultId:String(e.defaultId||``),templates:e.templates})},p=async()=>{l(!0);try{let e=await n.rpc(`listTemplates`);i(e)}catch(e){n.toast(String(e.message||e))}finally{l(!1)}};(0,t.useEffect)(()=>{p()},[]);let m=()=>s({id:``,name:``,body:`## 背景
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## 验收
|
|
5
|
+
- [ ] …
|
|
6
|
+
|
|
7
|
+
## 约束
|
|
8
|
+
- …`}),h=e=>s({id:e.id,name:e.name,body:e.body}),g=()=>s(null),_=async()=>{if(o&&!c){if(!o.name.trim()){n.toast(`模板名不能为空`);return}l(!0);try{let e=o.id?await n.rpc(`updateTemplate`,{id:o.id,name:o.name.trim(),body:o.body}):await n.rpc(`addTemplate`,{name:o.name.trim(),body:o.body});f(e),s(null),n.toast(o.id?`模板已保存`:`模板已创建`)}catch(e){n.toast(String(e.message||e))}finally{l(!1)}}},v=async e=>{if(!c){l(!0);try{f(await n.rpc(`setDefault`,{id:e.id})),n.toast(`插件默认模板已设为「${e.name}」`)}catch(e){n.toast(String(e.message||e))}finally{l(!1)}}},y=async e=>{if(!c){l(!0);try{f(await n.rpc(`removeTemplate`,{id:e.id})),d(``),n.toast(`已删除「${e.name}」`)}catch(e){n.toast(String(e.message||e))}finally{l(!1)}}},b=async(e,t)=>{if(!r||c)return;let i=r.templates.map(e=>e.id),a=e+t;if(a<0||a>=i.length||r.templates[e]?.builtin||r.templates[a]?.builtin)return;let o=[...i],s=o[e];o[e]=o[a],o[a]=s,l(!0);try{f(await n.rpc(`reorder`,{ids:o}))}catch(e){n.toast(String(e.message||e))}finally{l(!1)}},x=r?.templates||[];return(0,e.jsxs)(`div`,{className:`rp-page tpl-page`,children:[(0,e.jsxs)(`div`,{className:`page-head`,children:[(0,e.jsxs)(`div`,{className:`title-block`,children:[(0,e.jsx)(`h2`,{children:`任务模板`}),(0,e.jsxs)(`p`,{className:`muted tpl-head-note`,children:[`新建任务时的正文骨架。主题没有单独配置「新建页行为」时,插件默认模板是回落项;带 `,`{{槽位}}`,` 的模板会先进入参数填写页。`]})]}),(0,e.jsx)(`div`,{className:`acts`,children:(0,e.jsx)(`button`,{type:`button`,className:`btn primary sm`,disabled:c,onClick:m,children:`新建模板`})})]}),o?(0,e.jsxs)(`div`,{className:`tpl-editor`,children:[(0,e.jsx)(`input`,{className:`tpl-name-input`,value:o.name,placeholder:`模板名(如:缺陷修复 / 调研任务)`,onChange:e=>s(t=>t&&{...t,name:e.target.value})}),(0,e.jsx)(`textarea`,{className:`tpl-fill-input tpl-body-input`,value:o.body,onChange:e=>s(t=>t&&{...t,body:e.target.value})}),(0,e.jsxs)(`div`,{className:`tpl-editor-foot`,children:[(0,e.jsx)(`button`,{type:`button`,className:`btn ghost sm`,disabled:c,onClick:g,children:`取消`}),(0,e.jsx)(`button`,{type:`button`,className:`btn primary sm`,disabled:c,onClick:()=>void _(),children:o.id?`保存`:`创建`})]})]}):null,c&&!x.length?(0,e.jsx)(`div`,{className:`muted`,style:{padding:8},children:`读取模板…`}):null,(0,e.jsx)(`div`,{className:`tpl-mng-list`,children:x.map((t,n)=>(0,e.jsxs)(`div`,{className:`tpl-mng-row`,children:[(0,e.jsx)(`span`,{className:`tpl-mng-grip`,"aria-hidden":!0,children:`⋮`}),(0,e.jsxs)(`div`,{className:`tpl-mng-main`,children:[(0,e.jsxs)(`div`,{className:`tpl-mng-line`,children:[(0,e.jsx)(`span`,{className:`tpl-mng-name`,children:t.name}),t.default?(0,e.jsx)(`span`,{className:`tpl-badge`,children:`插件默认`}):null,t.builtin?(0,e.jsx)(`span`,{className:`tpl-badge soft`,children:`内置`}):null,t.slots.length?(0,e.jsxs)(`span`,{className:`tpl-badge soft`,children:[t.slots.length,` 个槽位`]}):null]}),(0,e.jsx)(`div`,{className:`tpl-card-sum`,children:a(t.body)||`(空模板)`})]}),(0,e.jsxs)(`div`,{className:`tpl-mng-acts`,children:[t.builtin?null:(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,title:`编辑`,disabled:c,onClick:()=>h(t),children:`编辑`}),t.default?null:(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,title:`设为插件默认(主题未配置时回落)`,disabled:c,onClick:()=>void v(t),children:`设默认`}),(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,title:`上移`,disabled:c||t.builtin,onClick:()=>void b(n,-1),children:`↑`}),(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,title:`下移`,disabled:c||t.builtin,onClick:()=>void b(n,1),children:`↓`}),t.builtin?null:u===t.id?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,disabled:c,onClick:()=>void y(t),children:`确认删除`}),(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,disabled:c,onClick:()=>d(``),children:`取消`})]}):(0,e.jsx)(`button`,{type:`button`,className:`iconbtn`,disabled:c,onClick:()=>d(t.id),children:`删除`})]})]},t.id))})]})}function a(e){return String(e||``).split(`
|
|
9
|
+
`).map(e=>e.trim().replace(/^#{1,6}\s+/,``).replace(/^[-*+]\s+/,``)).filter(Boolean).slice(0,2).join(` · `)}var o={api:`^1`,components:{"entry-row":n,"entry-form":r,manage:i},pages:{"entry-form":{title:`填写模板参数`},manage:{title:`任务模板`}},sidebar:[{id:`manage`,label:`任务模板`,icon:`list`,order:10,page:`manage`}]};window.NxkvPluginHost?window.NxkvPluginHost.registerPlugin(`task-template`,o):console.warn(`[task-template] NxkvPluginHost 未注入,插件 UI 未注册`)})(NxkvJsxRuntime,NxkvReact);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.tpl-page{flex-direction:column;gap:12px;display:flex}.tpl-head-note{margin:2px 0 0;font-size:12px}.tpl-row{flex-wrap:wrap;align-items:baseline;gap:6px;min-width:0;display:inline-flex}.tpl-row-name{color:var(--ink,#222);font-size:12.5px;font-weight:600}.tpl-row-desc{color:var(--mid,#8a8578);text-overflow:ellipsis;white-space:nowrap;max-width:260px;font-size:11px;overflow:hidden}.tpl-badge{background:var(--mdw-accent-soft,#e8f2ee);color:var(--mdw-accent,#2f6f5e);border:1px solid var(--mdw-accent-line,#b7d4c8);border-radius:999px;padding:0 6px;font-size:10.5px;line-height:1.7}.tpl-badge.soft{background:var(--soft,#f1f0ec);color:var(--mid,#8a8578);border-color:var(--line,#e4e2dc)}.tpl-list{flex-direction:column;gap:8px;min-width:0;display:flex}.tpl-card{border:1px solid var(--line,#e4e2dc);background:var(--paper,#fff);border-radius:10px;flex-direction:column;gap:6px;min-width:0;padding:10px 12px;display:flex}.tpl-card-head{flex-wrap:wrap;align-items:center;gap:8px;min-width:0;display:flex}.tpl-card-name{font-size:13px;font-weight:600}.tpl-card-sum{color:var(--ink-2,#4b515a);-webkit-line-clamp:3;-webkit-box-orient:vertical;font-size:11.5px;line-height:1.6;display:-webkit-box;overflow:hidden}.tpl-fill-page{gap:12px}.tpl-fill-page .page-head h2{align-items:center;gap:7px;display:flex}.tpl-fill-body{border:1px solid var(--line,#e4e2dc);background:var(--paper,#fff);border-radius:10px;flex-direction:column;gap:14px;min-width:0;max-width:720px;padding:14px;display:flex}.tpl-fill-field{flex-direction:column;gap:6px;min-width:0;display:flex}.tpl-fill-label{color:var(--ink-2,#4b515a);font-size:12px;font-weight:600}.tpl-fill-input{resize:vertical;box-sizing:border-box;width:100%;min-height:84px;color:var(--ink,#222);background:var(--paper,#fff);border:1px solid var(--line,#e4e2dc);border-radius:8px;padding:8px 10px;font:400 12.5px/1.6 inherit}.tpl-fill-input:focus{border-color:var(--mdw-accent-line,#b7d4c8);outline:none}.tpl-fill-empty{padding:8px 0}.tpl-fill-foot{justify-content:flex-end;gap:8px;max-width:720px;display:flex}.tpl-mng-list{flex-direction:column;gap:6px;min-width:0;display:flex}.tpl-mng-row{border:1px solid var(--line,#e4e2dc);background:var(--paper,#fff);border-radius:9px;grid-template-columns:22px minmax(0,1fr) auto;align-items:center;gap:8px;padding:8px 10px;display:grid}.tpl-mng-grip{cursor:default;color:var(--mid,#8a8578);justify-content:center;align-items:center;display:flex}.tpl-mng-main{min-width:0}.tpl-mng-line{flex-wrap:wrap;align-items:center;gap:6px;min-width:0;display:flex}.tpl-mng-name{color:var(--ink,#222);font-size:12.5px;font-weight:600}.tpl-mng-acts{flex-wrap:nowrap;justify-content:flex-end;align-items:center;gap:2px;display:flex}.tpl-mng-acts .iconbtn{color:var(--mid,#8a8578);white-space:nowrap;padding:4px 6px;font-size:11px}.tpl-mng-acts .iconbtn:hover:not(:disabled){color:var(--ink,#222);background:var(--soft,#f1f0ec)}.tpl-editor{border:1px solid var(--mdw-accent-line,#b7d4c8);background:var(--paper,#fff);border-radius:10px;flex-direction:column;gap:8px;padding:12px;display:flex}.tpl-name-input{box-sizing:border-box;width:100%;color:var(--ink,#222);background:var(--paper,#fff);border:1px solid var(--line,#e4e2dc);border-radius:8px;padding:8px 10px;font:600 13px/1.5 inherit}.tpl-body-input{min-height:260px;font-family:ui-monospace,Consolas,monospace;font-size:12px}.tpl-editor-foot{justify-content:flex-end;gap:8px;display:flex}
|
|
2
|
+
/*$vite$:1*/
|
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
//#region packages/plugin-sdk/dist/index.js
|
|
3
|
+
/** 插件 server 入口的默认导出必须包一层,宿主据此做运行时校验。 */
|
|
4
|
+
function definePlugin(plugin) {
|
|
5
|
+
if (!plugin || typeof plugin !== "object") throw new Error("definePlugin: 需要插件对象");
|
|
6
|
+
if (!plugin.id || /[:.]/.test(plugin.id)) throw new Error(`definePlugin: 非法插件 id「${String(plugin.id)}」(只允许字母/数字/短横线)`);
|
|
7
|
+
if (!plugin.api || !/^\^1(\.|$)/.test(plugin.api)) throw new Error(`definePlugin: 不支持的 api「${String(plugin.api)}」(当前 '^1')`);
|
|
8
|
+
if (!plugin.version) throw new Error("definePlugin: 需要 version");
|
|
9
|
+
if (!plugin.name) throw new Error("definePlugin: 需要 name");
|
|
10
|
+
if (typeof plugin.entries !== "function") throw new Error("definePlugin: 需要 entries()");
|
|
11
|
+
if (typeof plugin.buildDraft !== "function") throw new Error("definePlugin: 需要 buildDraft()");
|
|
12
|
+
return plugin;
|
|
13
|
+
}
|
|
14
|
+
/** 供插件做 rpc 参数兜底:把未知值收成普通对象。 */
|
|
15
|
+
function paramsOf(raw) {
|
|
16
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region packages/plugin-sdk/dist/template.js
|
|
20
|
+
var SLOT_RE = /\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g;
|
|
21
|
+
/** 模板正文里声明了哪些槽位(按首次出现顺序去重)。 */
|
|
22
|
+
function templateSlots(body) {
|
|
23
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const m of String(body ?? "").matchAll(SLOT_RE)) {
|
|
25
|
+
const key = String(m[1] ?? "").trim();
|
|
26
|
+
if (key) seen.add(key);
|
|
27
|
+
}
|
|
28
|
+
return [...seen];
|
|
29
|
+
}
|
|
30
|
+
/** 渲染模板正文:{{槽位名}} → 槽位值(没值留空)。 */
|
|
31
|
+
function renderTemplateBody(body, values) {
|
|
32
|
+
const vals = values && typeof values === "object" ? values : {};
|
|
33
|
+
return String(body ?? "").replace(SLOT_RE, (_all, name) => {
|
|
34
|
+
const key = String(name).trim();
|
|
35
|
+
const v = vals[key];
|
|
36
|
+
return v === void 0 || v === null ? "" : String(v);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region packages/plugin-task-template/src/server/builtin-body.ts
|
|
41
|
+
var NEWTASK_REF_BODY = `## 本轮问题
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 怎么干(零知识起步的 SOP)
|
|
47
|
+
|
|
48
|
+
你没有这个仓库 / 项目组的既有知识,**不要凭空回答**。按五步走:
|
|
49
|
+
|
|
50
|
+
### 1. 先摸清仓库(只读)
|
|
51
|
+
|
|
52
|
+
\`\`\`bash
|
|
53
|
+
nx-kv repo list --json # 仓库清单(key / 名称 / 路径)
|
|
54
|
+
nx-kv docs list --json # 这个仓库已有的文档(refs)
|
|
55
|
+
nx-kv docs get --ref <refId> # 读某篇文档的正文
|
|
56
|
+
nx-kv localtask show --id <id> --cwd "<项目目录>" # 任务本体 + 附件清单
|
|
57
|
+
\`\`\`
|
|
58
|
+
|
|
59
|
+
### 2. 先判断任务来源,决定文档挂哪里(关键,别跳过)
|
|
60
|
+
|
|
61
|
+
归档文档必须挂在**任务来源的宿主**上:仓库提交的任务挂仓库,组提交的任务挂组。
|
|
62
|
+
判断依据只有一处——\`show --json\` 的 \`boardMark\`(组任务归属来自库内关联;
|
|
63
|
+
正文是纯 markdown,**没有也不会有** frontmatter 头):
|
|
64
|
+
|
|
65
|
+
\`\`\`bash
|
|
66
|
+
nx-kv localtask show --id <id> --cwd "<项目目录>" --json # 看 boardMark / repoKey
|
|
67
|
+
\`\`\`
|
|
68
|
+
|
|
69
|
+
- \`boardMark\` 非空 → **组任务**(组页「新增任务」提交的)。文档挂**组**:
|
|
70
|
+
\`\`\`bash
|
|
71
|
+
nx-kv docs ref add --owner group --group <boardMark> --desc "<一句话短描述>" --json
|
|
72
|
+
\`\`\`
|
|
73
|
+
**不要用 group_repo**——那是「组对某成员仓库的组内描述」,一个 (组,仓库) 只有一篇,会被覆盖。
|
|
74
|
+
- \`boardMark\` 为空 → **仓库任务**(目录页提交的)。文档挂**仓库**:
|
|
75
|
+
\`\`\`bash
|
|
76
|
+
nx-kv docs ref add --owner repo --repo <仓库key> --desc "<一句话短描述>" --json
|
|
77
|
+
\`\`\`
|
|
78
|
+
\`<仓库key>\` 直接用 show --json 的 \`repoKey\`(任务归属仓库的 key);没有就用第 1 步
|
|
79
|
+
\`repo list\` 里 \`path\` 匹配 <项目目录> 的那条 key。
|
|
80
|
+
|
|
81
|
+
### 3. 初始化:给这轮问答建一篇 ref
|
|
82
|
+
|
|
83
|
+
ref 是**文档库里的一篇文档**(正文进 ref_bodies,身份是 \`ref:<16位hex>\`),
|
|
84
|
+
不是附件;按第 2 步判断的宿主绑定,挂上就出现在那个宿主的「文档列表」里。
|
|
85
|
+
|
|
86
|
+
**标题与 desc 都要给**(缺一个,列表里就只是一行没头没尾的条目):
|
|
87
|
+
|
|
88
|
+
- **desc** = 一句话短描述(列表 / 提示词模板里的定位标签,如「面板扩展附件类型的九个改动点」);
|
|
89
|
+
- **标题(title)** = 正文第一行的 \`# <标题>\`(文档标题,取用与列表里显示的就是它)。
|
|
90
|
+
|
|
91
|
+
按第 2 步的宿主二选一执行(仓库任务):
|
|
92
|
+
|
|
93
|
+
\`\`\`bash
|
|
94
|
+
nx-kv docs ref add --owner repo --repo <仓库key> --desc "<一句话短描述>" --json
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
这一步就按第 2 步判断的宿主**完成绑定**:仓库任务 → repo,组任务 → group。
|
|
98
|
+
**主篇 / 附加篇只是这个宿主文档列表里的位置**(position=0 是主篇),**不是另一处绑定**:
|
|
99
|
+
不要调用 \`docs main\` / \`docs bind\` 去「争主篇」——那是换主篇操作,不是归档。
|
|
100
|
+
同一篇只 \`ref add\` 一次(重复挂会在列表里出现两条)。
|
|
101
|
+
|
|
102
|
+
### 4. 回答问题,再把这轮问答写进那篇 ref
|
|
103
|
+
|
|
104
|
+
正文**第一行必须是 \`# <标题>\`**(就是上面说的标题),长文本**写进文件**再传
|
|
105
|
+
(不受命令行长度限制):
|
|
106
|
+
|
|
107
|
+
\`\`\`bash
|
|
108
|
+
nx-kv docs set --ref <refId> --body-file <本轮问答.md> --json
|
|
109
|
+
\`\`\`
|
|
110
|
+
|
|
111
|
+
### 5. 收尾
|
|
112
|
+
|
|
113
|
+
\`\`\`bash
|
|
114
|
+
nx-kv localtask done --id <id> --cwd "<项目目录>" --summary "<回答了什么 + 这篇文档的标题>"
|
|
115
|
+
\`\`\`
|
|
116
|
+
|
|
117
|
+
**收尾报告这篇文档的标题**(如「面板如何扩展附件类型」)——用户看的是标题,
|
|
118
|
+
\`refId\` 是内部地址,不用报给用户;但它要写进交付正文里,方便以后取用。`;
|
|
119
|
+
function migrateStorage(db, fromVersion) {
|
|
120
|
+
if (fromVersion < 1) db.exec(`
|
|
121
|
+
CREATE TABLE IF NOT EXISTS plugin_task_templates (
|
|
122
|
+
id TEXT PRIMARY KEY,
|
|
123
|
+
name TEXT NOT NULL,
|
|
124
|
+
body TEXT NOT NULL,
|
|
125
|
+
vars_schema TEXT NOT NULL DEFAULT '[]',
|
|
126
|
+
vars TEXT NOT NULL DEFAULT '{}',
|
|
127
|
+
sort_order INTEGER NOT NULL DEFAULT 0,
|
|
128
|
+
scope TEXT NOT NULL DEFAULT '[]',
|
|
129
|
+
origin_topic TEXT NOT NULL DEFAULT '',
|
|
130
|
+
created_at INTEGER NOT NULL,
|
|
131
|
+
updated_at INTEGER NOT NULL,
|
|
132
|
+
deleted_at INTEGER
|
|
133
|
+
);
|
|
134
|
+
CREATE INDEX IF NOT EXISTS ix_plugin_task_templates_order
|
|
135
|
+
ON plugin_task_templates (sort_order, id) WHERE deleted_at IS NULL;
|
|
136
|
+
CREATE TABLE IF NOT EXISTS plugin_task_template_settings (
|
|
137
|
+
key TEXT PRIMARY KEY,
|
|
138
|
+
value_json TEXT NOT NULL,
|
|
139
|
+
updated_at INTEGER NOT NULL
|
|
140
|
+
);
|
|
141
|
+
`);
|
|
142
|
+
return 1;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region packages/plugin-task-template/src/server/scope.ts
|
|
146
|
+
var KINDS = [
|
|
147
|
+
"topic",
|
|
148
|
+
"repo",
|
|
149
|
+
"group"
|
|
150
|
+
];
|
|
151
|
+
var MAX_ENTRIES = 32;
|
|
152
|
+
function isScopeEntry(value) {
|
|
153
|
+
const s = String(value ?? "");
|
|
154
|
+
if (s === "*") return true;
|
|
155
|
+
const i = s.indexOf(":");
|
|
156
|
+
if (i <= 0) return false;
|
|
157
|
+
const kind = s.slice(0, i);
|
|
158
|
+
const key = s.slice(i + 1);
|
|
159
|
+
return KINDS.includes(kind) && !!key && key.length <= 200 && !/\s/.test(key);
|
|
160
|
+
}
|
|
161
|
+
function normalizeScope(raw) {
|
|
162
|
+
let value = raw;
|
|
163
|
+
if (typeof value === "string") {
|
|
164
|
+
const text = value.trim();
|
|
165
|
+
if (!text) return [];
|
|
166
|
+
try {
|
|
167
|
+
value = JSON.parse(text);
|
|
168
|
+
} catch {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!Array.isArray(value)) return [];
|
|
173
|
+
const out = [];
|
|
174
|
+
for (const item of value) {
|
|
175
|
+
const s = String(item ?? "").trim();
|
|
176
|
+
if (!isScopeEntry(s) || out.includes(s)) continue;
|
|
177
|
+
out.push(s);
|
|
178
|
+
if (out.length >= MAX_ENTRIES) break;
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
function canUse(scope, ctx) {
|
|
183
|
+
if (!!!(ctx.topicKey || ctx.repoKey || ctx.groupKey)) return true;
|
|
184
|
+
if (!scope.length) return false;
|
|
185
|
+
if (scope.includes("*")) return true;
|
|
186
|
+
if (ctx.topicKey && scope.includes(`topic:${ctx.topicKey}`)) return true;
|
|
187
|
+
if (ctx.repoKey && scope.includes(`repo:${ctx.repoKey}`)) return true;
|
|
188
|
+
if (ctx.groupKey && scope.includes(`group:${ctx.groupKey}`)) return true;
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region packages/plugin-task-template/src/server/templates.ts
|
|
193
|
+
var PLUGIN_ID = "task-template";
|
|
194
|
+
var BUILTIN_ENTRY_ID = `${PLUGIN_ID}:ref`;
|
|
195
|
+
var DEFAULT_SETTING_KEY = "default_entry";
|
|
196
|
+
var at = () => Date.now();
|
|
197
|
+
function parseObject(raw) {
|
|
198
|
+
try {
|
|
199
|
+
const value = JSON.parse(String(raw ?? "{}"));
|
|
200
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
201
|
+
const out = {};
|
|
202
|
+
for (const [k, v] of Object.entries(value)) out[String(k)] = String(v ?? "");
|
|
203
|
+
return out;
|
|
204
|
+
} catch {
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function parseScope(raw) {
|
|
209
|
+
return normalizeScope(raw);
|
|
210
|
+
}
|
|
211
|
+
/** 供 entries 展示模板默认槽位值。 */
|
|
212
|
+
function varsOfRow(raw) {
|
|
213
|
+
return parseObject(raw);
|
|
214
|
+
}
|
|
215
|
+
function slotsOf(body) {
|
|
216
|
+
return templateSlots(body).map((key) => ({
|
|
217
|
+
key,
|
|
218
|
+
label: key,
|
|
219
|
+
type: "text"
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
function entryIdOf(localId) {
|
|
223
|
+
return `${PLUGIN_ID}:${localId}`;
|
|
224
|
+
}
|
|
225
|
+
function localIdOf(entryId) {
|
|
226
|
+
const s = String(entryId || "");
|
|
227
|
+
return s.startsWith(`task-template:`) ? s.slice(14) : s;
|
|
228
|
+
}
|
|
229
|
+
function getSetting(db, key) {
|
|
230
|
+
const row = db.get("SELECT value_json FROM plugin_task_template_settings WHERE key = :k", { k: key });
|
|
231
|
+
if (!row) return "";
|
|
232
|
+
try {
|
|
233
|
+
const value = JSON.parse(String(row.value_json));
|
|
234
|
+
return typeof value === "string" ? value : "";
|
|
235
|
+
} catch {
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function setSetting(db, key, value) {
|
|
240
|
+
db.run(`INSERT INTO plugin_task_template_settings (key, value_json, updated_at)
|
|
241
|
+
VALUES (:k, :v, :at)
|
|
242
|
+
ON CONFLICT(key) DO UPDATE SET value_json = excluded.value_json, updated_at = excluded.updated_at`, {
|
|
243
|
+
k: key,
|
|
244
|
+
v: JSON.stringify(value),
|
|
245
|
+
at: at()
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function listRows(db) {
|
|
249
|
+
return db.all(`SELECT id, name, body, vars_schema, vars, sort_order, scope, origin_topic,
|
|
250
|
+
created_at, updated_at, deleted_at
|
|
251
|
+
FROM plugin_task_templates
|
|
252
|
+
WHERE deleted_at IS NULL
|
|
253
|
+
ORDER BY sort_order, id`);
|
|
254
|
+
}
|
|
255
|
+
function getRow(db, localId) {
|
|
256
|
+
return db.get(`SELECT id, name, body, vars_schema, vars, sort_order, scope, origin_topic,
|
|
257
|
+
created_at, updated_at, deleted_at
|
|
258
|
+
FROM plugin_task_templates WHERE id = :id AND deleted_at IS NULL`, { id: localId }) || null;
|
|
259
|
+
}
|
|
260
|
+
function getDefaultEntryId(db) {
|
|
261
|
+
const stored = getSetting(db, DEFAULT_SETTING_KEY);
|
|
262
|
+
if (stored === BUILTIN_ENTRY_ID) return stored;
|
|
263
|
+
const local = localIdOf(stored);
|
|
264
|
+
if (stored && local && getRow(db, local)) return stored;
|
|
265
|
+
return BUILTIN_ENTRY_ID;
|
|
266
|
+
}
|
|
267
|
+
function setDefaultEntry(db, entryId) {
|
|
268
|
+
const local = localIdOf(entryId);
|
|
269
|
+
if (local !== "ref" && !getRow(db, local)) throw new Error(`模板不存在:${entryId}`);
|
|
270
|
+
setSetting(db, DEFAULT_SETTING_KEY, entryId);
|
|
271
|
+
}
|
|
272
|
+
function viewOf(row, defaultEntryId) {
|
|
273
|
+
return {
|
|
274
|
+
id: entryIdOf(row.id),
|
|
275
|
+
name: row.name,
|
|
276
|
+
body: row.body,
|
|
277
|
+
builtin: false,
|
|
278
|
+
default: entryIdOf(row.id) === defaultEntryId,
|
|
279
|
+
scope: parseScope(row.scope),
|
|
280
|
+
vars: parseObject(row.vars),
|
|
281
|
+
sortOrder: Number(row.sort_order) || 0,
|
|
282
|
+
slots: slotsOf(row.body),
|
|
283
|
+
createdAt: Number(row.created_at) || 0,
|
|
284
|
+
updatedAt: Number(row.updated_at) || 0
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function builtinView(defaultEntryId) {
|
|
288
|
+
return {
|
|
289
|
+
id: BUILTIN_ENTRY_ID,
|
|
290
|
+
name: "ref 生成",
|
|
291
|
+
body: NEWTASK_REF_BODY,
|
|
292
|
+
builtin: true,
|
|
293
|
+
default: defaultEntryId === BUILTIN_ENTRY_ID,
|
|
294
|
+
scope: ["*"],
|
|
295
|
+
vars: {},
|
|
296
|
+
sortOrder: 0,
|
|
297
|
+
slots: slotsOf(NEWTASK_REF_BODY),
|
|
298
|
+
createdAt: 0,
|
|
299
|
+
updatedAt: 0
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function listTemplates(db) {
|
|
303
|
+
const defaultId = getDefaultEntryId(db);
|
|
304
|
+
return {
|
|
305
|
+
defaultId,
|
|
306
|
+
templates: [builtinView(defaultId), ...listRows(db).map((r) => viewOf(r, defaultId))]
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function addTemplate(db, input) {
|
|
310
|
+
const name = String(input.name || "").trim();
|
|
311
|
+
if (!name) throw new Error("需要模板名");
|
|
312
|
+
const body = String(input.body ?? "").trim() ? String(input.body) : NEWTASK_REF_BODY;
|
|
313
|
+
const topic = String(input.topic || "").trim();
|
|
314
|
+
const scope = input.scope !== void 0 ? normalizeScope(input.scope) : topic ? [`topic:${topic}`] : ["*"];
|
|
315
|
+
const now = at();
|
|
316
|
+
const id = `t_${crypto.randomBytes(5).toString("hex")}`;
|
|
317
|
+
const sortRow = db.get("SELECT MAX(sort_order) AS m FROM plugin_task_templates WHERE deleted_at IS NULL");
|
|
318
|
+
const sort = (sortRow && sortRow.m !== null && sortRow.m !== void 0 ? Number(sortRow.m) : -1) + 1;
|
|
319
|
+
db.run(`INSERT INTO plugin_task_templates
|
|
320
|
+
(id, name, body, vars_schema, vars, sort_order, scope, origin_topic, created_at, updated_at, deleted_at)
|
|
321
|
+
VALUES (:id, :name, :body, '[]', '{}', :sort, :scope, :origin, :at, :at, NULL)`, {
|
|
322
|
+
id,
|
|
323
|
+
name: name.slice(0, 60),
|
|
324
|
+
body,
|
|
325
|
+
sort,
|
|
326
|
+
scope: JSON.stringify(scope),
|
|
327
|
+
origin: topic,
|
|
328
|
+
at: now
|
|
329
|
+
});
|
|
330
|
+
const row = getRow(db, id);
|
|
331
|
+
if (!row) throw new Error("模板写入失败");
|
|
332
|
+
return viewOf(row, getDefaultEntryId(db));
|
|
333
|
+
}
|
|
334
|
+
function updateTemplate(db, input) {
|
|
335
|
+
const local = localIdOf(input.id);
|
|
336
|
+
if (local === "ref") throw new Error("内置模板不可修改");
|
|
337
|
+
if (!(local ? getRow(db, local) : null)) throw new Error(`模板不存在:${String(input.id)}`);
|
|
338
|
+
const sets = [];
|
|
339
|
+
const params = {
|
|
340
|
+
id: local,
|
|
341
|
+
at: at()
|
|
342
|
+
};
|
|
343
|
+
if (input.name !== void 0) {
|
|
344
|
+
const name = String(input.name || "").trim();
|
|
345
|
+
if (!name) throw new Error("模板名不能为空");
|
|
346
|
+
sets.push("name = :name");
|
|
347
|
+
params.name = name.slice(0, 60);
|
|
348
|
+
}
|
|
349
|
+
if (input.body !== void 0) {
|
|
350
|
+
sets.push("body = :body");
|
|
351
|
+
params.body = String(input.body ?? "");
|
|
352
|
+
}
|
|
353
|
+
if (input.scope !== void 0) {
|
|
354
|
+
sets.push("scope = :scope");
|
|
355
|
+
params.scope = JSON.stringify(normalizeScope(input.scope));
|
|
356
|
+
}
|
|
357
|
+
if (sets.length) {
|
|
358
|
+
sets.push("updated_at = :at");
|
|
359
|
+
db.run(`UPDATE plugin_task_templates SET ${sets.join(", ")} WHERE id = :id`, params);
|
|
360
|
+
}
|
|
361
|
+
const next = getRow(db, local);
|
|
362
|
+
if (!next) throw new Error("模板更新后读不到");
|
|
363
|
+
return viewOf(next, getDefaultEntryId(db));
|
|
364
|
+
}
|
|
365
|
+
function removeTemplate(db, id) {
|
|
366
|
+
const local = localIdOf(id);
|
|
367
|
+
if (local === "ref") throw new Error("内置模板不可删除");
|
|
368
|
+
if (!(local ? getRow(db, local) : null)) throw new Error(`模板不存在:${String(id)}`);
|
|
369
|
+
db.run("DELETE FROM plugin_task_templates WHERE id = :id", { id: local });
|
|
370
|
+
if (getDefaultEntryId(db) === entryIdOf(local)) setSetting(db, DEFAULT_SETTING_KEY, BUILTIN_ENTRY_ID);
|
|
371
|
+
return {
|
|
372
|
+
removed: entryIdOf(local),
|
|
373
|
+
defaultId: getDefaultEntryId(db)
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function reorderTemplates(db, ids) {
|
|
377
|
+
const list = Array.isArray(ids) ? ids.map((x) => localIdOf(x)).filter(Boolean) : [];
|
|
378
|
+
if (!list.length) throw new Error("需要 ids(模板入口 id 的有序数组)");
|
|
379
|
+
const now = at();
|
|
380
|
+
list.forEach((local, index) => {
|
|
381
|
+
if (local === "ref") return;
|
|
382
|
+
db.run("UPDATE plugin_task_templates SET sort_order = :sort, updated_at = :at WHERE id = :id", {
|
|
383
|
+
sort: index + 1,
|
|
384
|
+
at: now,
|
|
385
|
+
id: local
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
return listTemplates(db).templates;
|
|
389
|
+
}
|
|
390
|
+
/** 宿主 v19/v20 暂存的旧用户模板:按旧 id 幂等导入。 */
|
|
391
|
+
function importLegacy(db, payload) {
|
|
392
|
+
const data = payload && typeof payload === "object" ? payload : {};
|
|
393
|
+
const rows = Array.isArray(data.rows) ? data.rows : [];
|
|
394
|
+
let imported = 0;
|
|
395
|
+
for (const raw of rows) {
|
|
396
|
+
if (!raw || !raw.id) continue;
|
|
397
|
+
const id = String(raw.id);
|
|
398
|
+
const now = at();
|
|
399
|
+
db.run(`INSERT INTO plugin_task_templates
|
|
400
|
+
(id, name, body, vars_schema, vars, sort_order, scope, origin_topic, created_at, updated_at, deleted_at)
|
|
401
|
+
VALUES (:id, :name, :body, :schema, :vars, :sort, :scope, :origin, :created, :updated, NULL)
|
|
402
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
403
|
+
name = excluded.name,
|
|
404
|
+
body = excluded.body,
|
|
405
|
+
vars_schema = excluded.vars_schema,
|
|
406
|
+
vars = excluded.vars,
|
|
407
|
+
sort_order = excluded.sort_order,
|
|
408
|
+
scope = excluded.scope,
|
|
409
|
+
origin_topic = excluded.origin_topic,
|
|
410
|
+
updated_at = excluded.updated_at`, {
|
|
411
|
+
id,
|
|
412
|
+
name: String(raw.name || id).slice(0, 60),
|
|
413
|
+
body: String(raw.body || ""),
|
|
414
|
+
schema: typeof raw.vars_schema === "string" ? raw.vars_schema : JSON.stringify(raw.vars_schema ?? []),
|
|
415
|
+
vars: typeof raw.vars === "string" ? raw.vars : JSON.stringify(raw.vars ?? {}),
|
|
416
|
+
sort: Number(raw.sort_order) || 0,
|
|
417
|
+
scope: typeof raw.scope === "string" ? raw.scope : JSON.stringify(raw.scope ?? ["*"]),
|
|
418
|
+
origin: String(raw.origin_topic || ""),
|
|
419
|
+
created: Number(raw.created_at) || now,
|
|
420
|
+
updated: Number(raw.updated_at) || now
|
|
421
|
+
});
|
|
422
|
+
imported += 1;
|
|
423
|
+
}
|
|
424
|
+
const wanted = String(data.defaultId || "");
|
|
425
|
+
const local = localIdOf(wanted);
|
|
426
|
+
if (wanted && local && local !== "ref" && getRow(db, local)) setSetting(db, DEFAULT_SETTING_KEY, entryIdOf(local));
|
|
427
|
+
else if (!getSetting(db, DEFAULT_SETTING_KEY)) setSetting(db, DEFAULT_SETTING_KEY, BUILTIN_ENTRY_ID);
|
|
428
|
+
return imported;
|
|
429
|
+
}
|
|
430
|
+
function rowsForEntries(db, ctx) {
|
|
431
|
+
return listRows(db).filter((row) => canUse(parseScope(row.scope), ctx));
|
|
432
|
+
}
|
|
433
|
+
function templateOfEntry(db, entryId) {
|
|
434
|
+
const local = localIdOf(entryId);
|
|
435
|
+
if (local === "ref") return {
|
|
436
|
+
row: null,
|
|
437
|
+
body: NEWTASK_REF_BODY
|
|
438
|
+
};
|
|
439
|
+
const row = getRow(db, local);
|
|
440
|
+
return row ? {
|
|
441
|
+
row,
|
|
442
|
+
body: row.body
|
|
443
|
+
} : null;
|
|
444
|
+
}
|
|
445
|
+
function slotsOfBody(body) {
|
|
446
|
+
return slotsOf(body);
|
|
447
|
+
}
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region packages/plugin-task-template/src/server/index.ts
|
|
450
|
+
function summaryOf(body) {
|
|
451
|
+
return String(body || "").split("\n").map((line) => line.trim().replace(/^#{1,6}\s+/, "").replace(/^[-*+]\s+/, "")).find(Boolean)?.slice(0, 60) || "";
|
|
452
|
+
}
|
|
453
|
+
function draftEntry(input) {
|
|
454
|
+
const slots = slotsOfBody(input.body);
|
|
455
|
+
return {
|
|
456
|
+
id: input.entryId,
|
|
457
|
+
pluginId: PLUGIN_ID,
|
|
458
|
+
label: input.label,
|
|
459
|
+
description: input.description,
|
|
460
|
+
icon: "list",
|
|
461
|
+
kind: "draft",
|
|
462
|
+
order: input.order,
|
|
463
|
+
default: input.isDefault,
|
|
464
|
+
builtin: input.builtin,
|
|
465
|
+
previewBody: input.body,
|
|
466
|
+
slots,
|
|
467
|
+
values: input.values,
|
|
468
|
+
ui: {
|
|
469
|
+
row: "entry-row",
|
|
470
|
+
...slots.length ? { form: "entry-form" } : {}
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
var server_default = definePlugin({
|
|
475
|
+
id: PLUGIN_ID,
|
|
476
|
+
version: "0.1.0",
|
|
477
|
+
api: "^1",
|
|
478
|
+
name: "任务模板",
|
|
479
|
+
description: "新建任务时的正文模板与槽位填写;内置 ref 生成 + 用户模板。",
|
|
480
|
+
order: 10,
|
|
481
|
+
defaultEnabled: true,
|
|
482
|
+
storageVersion: 1,
|
|
483
|
+
migrateStorage,
|
|
484
|
+
async migrateLegacy(ctx, kind, payload) {
|
|
485
|
+
if (kind === "templates") importLegacy(ctx.storage, payload);
|
|
486
|
+
},
|
|
487
|
+
entries(ctx) {
|
|
488
|
+
const defaultId = getDefaultEntryId(ctx.storage);
|
|
489
|
+
const out = [draftEntry({
|
|
490
|
+
entryId: BUILTIN_ENTRY_ID,
|
|
491
|
+
label: "ref 生成",
|
|
492
|
+
description: "零知识起步:先摸仓库,再归档成一篇 ref",
|
|
493
|
+
body: NEWTASK_REF_BODY,
|
|
494
|
+
values: {},
|
|
495
|
+
order: 0,
|
|
496
|
+
isDefault: defaultId === BUILTIN_ENTRY_ID,
|
|
497
|
+
builtin: true
|
|
498
|
+
})];
|
|
499
|
+
for (const row of rowsForEntries(ctx.storage, ctx)) {
|
|
500
|
+
const entryId = entryIdOf(row.id);
|
|
501
|
+
out.push(draftEntry({
|
|
502
|
+
entryId,
|
|
503
|
+
label: row.name,
|
|
504
|
+
description: summaryOf(row.body),
|
|
505
|
+
body: row.body,
|
|
506
|
+
values: varsOfRow(row.vars),
|
|
507
|
+
order: Number(row.sort_order) + 1,
|
|
508
|
+
isDefault: defaultId === entryId,
|
|
509
|
+
builtin: false
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
return out;
|
|
513
|
+
},
|
|
514
|
+
async buildDraft(ctx, entryId, values) {
|
|
515
|
+
const hit = templateOfEntry(ctx.storage, entryId);
|
|
516
|
+
if (!hit) throw new Error(`模板不存在:${entryId}`);
|
|
517
|
+
return { body: renderTemplateBody(hit.body, values) };
|
|
518
|
+
},
|
|
519
|
+
rpc: {
|
|
520
|
+
async listTemplates(ctx) {
|
|
521
|
+
return listTemplates(ctx.storage);
|
|
522
|
+
},
|
|
523
|
+
async addTemplate(ctx, raw) {
|
|
524
|
+
const params = paramsOf(raw);
|
|
525
|
+
return {
|
|
526
|
+
template: addTemplate(ctx.storage, params),
|
|
527
|
+
...listTemplates(ctx.storage)
|
|
528
|
+
};
|
|
529
|
+
},
|
|
530
|
+
async updateTemplate(ctx, raw) {
|
|
531
|
+
const params = paramsOf(raw);
|
|
532
|
+
return {
|
|
533
|
+
template: updateTemplate(ctx.storage, params),
|
|
534
|
+
...listTemplates(ctx.storage)
|
|
535
|
+
};
|
|
536
|
+
},
|
|
537
|
+
async removeTemplate(ctx, raw) {
|
|
538
|
+
const params = paramsOf(raw);
|
|
539
|
+
return {
|
|
540
|
+
...removeTemplate(ctx.storage, params.id),
|
|
541
|
+
...listTemplates(ctx.storage)
|
|
542
|
+
};
|
|
543
|
+
},
|
|
544
|
+
async setDefault(ctx, raw) {
|
|
545
|
+
const params = paramsOf(raw);
|
|
546
|
+
setDefaultEntry(ctx.storage, String(params.id || ""));
|
|
547
|
+
return listTemplates(ctx.storage);
|
|
548
|
+
},
|
|
549
|
+
async reorder(ctx, raw) {
|
|
550
|
+
const params = paramsOf(raw);
|
|
551
|
+
reorderTemplates(ctx.storage, params.ids);
|
|
552
|
+
return listTemplates(ctx.storage);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
//#endregion
|
|
557
|
+
export { server_default as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nx-kv/plugin-task-template",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/server/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./server": {
|
|
9
|
+
"types": "./dist/server/index.d.ts",
|
|
10
|
+
"import": "./dist/server/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"nxkv": {
|
|
15
|
+
"api": "^1",
|
|
16
|
+
"server": "dist/server/index.js",
|
|
17
|
+
"client": "dist/client/client.js",
|
|
18
|
+
"style": "dist/client/style.css"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@nx-kv/plugin-sdk": "workspace:*"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^19.3.0",
|
|
25
|
+
"react-dom": "^19.3.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"package.json"
|
|
30
|
+
]
|
|
31
|
+
}
|