@xiaobuyu/nodesign 0.0.1 → 0.0.3
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/README.md +156 -106
- package/bin/nodesign.js +0 -0
- package/package.json +1 -1
- package/server/api/README.md +45 -45
- package/server/api/_guard.js +75 -75
- package/server/api/admin.js +187 -187
- package/server/api/assets/docx-page.js +103 -103
- package/server/api/assets/helpers.js +42 -22
- package/server/api/assets/notes.js +194 -144
- package/server/api/assets.js +891 -896
- package/server/api/board.js +134 -57
- package/server/api/browse.js +138 -138
- package/server/api/canvas.js +444 -444
- package/server/api/chatai.js +324 -324
- package/server/api/exports/build-standalone.js +980 -980
- package/server/api/exports/cards.js +118 -118
- package/server/api/exports/docx-pdf.js +46 -46
- package/server/api/exports/export-page.js +142 -142
- package/server/api/exports/handoff.js +147 -147
- package/server/api/exports.js +690 -690
- package/server/api/instruction.js +75 -75
- package/server/api/me.js +116 -116
- package/server/api/memory.js +185 -185
- package/server/api/pending-changes.js +366 -366
- package/server/api/plugins.js +164 -164
- package/server/api/projects.js +220 -220
- package/server/api/publish.js +64 -64
- package/server/api/recent.js +73 -73
- package/server/api/sessions.js +589 -589
- package/server/api/skills.js +77 -77
- package/server/api/standalone-fit.js +168 -168
- package/server/api/turn-compose.js +180 -180
- package/server/api/turn-inflight.js +44 -44
- package/server/auth/README.md +17 -17
- package/server/auth/middleware.js +138 -138
- package/server/auth/origin-guard.js +71 -71
- package/server/auth/session.js +108 -108
- package/server/auth/tier.js +113 -113
- package/server/auth/users-store.js +348 -348
- package/server/edit/README.md +29 -29
- package/server/engine/README.md +113 -113
- package/server/engine/agent/agent-shared.js +550 -550
- package/server/engine/agent/auto-mode-default-hard-deny.txt +4 -4
- package/server/engine/agent/auto-mode-rules.js +78 -78
- package/server/engine/agent/context.js +418 -418
- package/server/engine/agent/events.js +465 -464
- package/server/engine/agent/hooks/canvas-validate.js +199 -199
- package/server/engine/agent/hooks/failure.js +120 -120
- package/server/engine/agent/hooks/file-events.js +75 -75
- package/server/engine/agent/hooks/lifecycle.js +233 -233
- package/server/engine/agent/hooks/post-canvas-focus.js +80 -80
- package/server/engine/agent/hooks/post-guidance.js +206 -206
- package/server/engine/agent/hooks/post-subagent-report.js +104 -104
- package/server/engine/agent/hooks/post-trim.js +58 -58
- package/server/engine/agent/hooks/pre-board-neighborhood.js +34 -34
- package/server/engine/agent/hooks/pre-defaults.js +84 -84
- package/server/engine/agent/hooks/pre-injectors.js +277 -277
- package/server/engine/agent/hooks/pre-performance-log-guard.js +78 -78
- package/server/engine/agent/hooks/pre-starter-files.js +61 -61
- package/server/engine/agent/hooks/pre-workspace-scope-guard.js +78 -78
- package/server/engine/agent/hooks/site-validate.js +94 -94
- package/server/engine/agent/hooks/tool-prompts.js +31 -31
- package/server/engine/agent/hooks/turn-state-memory.js +56 -56
- package/server/engine/agent/hooks/user-prompt-submit.js +258 -215
- package/server/engine/agent/hooks.js +354 -354
- package/server/engine/agent/init-contract.js +69 -69
- package/server/engine/agent/isolation.js +159 -159
- package/server/engine/agent/model-table.js +292 -292
- package/server/engine/agent/plugin-loader.js +266 -266
- package/server/engine/agent/prompts/nodesign-prelude.md +388 -336
- package/server/engine/agent/prompts/tools/ask-user-question-protocol.md +71 -71
- package/server/engine/agent/prompts/tools/direct-edit-protocol.md +98 -98
- package/server/engine/agent/prompts/tools/generate-image-cookbook.gemini-gateway.md +583 -583
- package/server/engine/agent/prompts/tools/generate-image-cookbook.md +483 -483
- package/server/engine/agent/prompts/tools/hybrid-reference.md +100 -100
- package/server/engine/agent/prompts/tools/paint-still-cookbook.md +270 -270
- package/server/engine/agent/prompts/tools/roll-film-cookbook.md +70 -70
- package/server/engine/agent/prompts/tools/site-reference.md +106 -106
- package/server/engine/agent/prompts/tools/tweaks-syntax.md +125 -125
- package/server/engine/agent/prompts/tools/vision-checker-dispatch.md +48 -48
- package/server/engine/agent/session-loop.js +1035 -1024
- package/server/engine/agent/session-model.js +164 -164
- package/server/engine/agent/skill.js +204 -204
- package/server/engine/agent/task-events.js +78 -78
- package/server/engine/agents/ds-extractor.md +132 -132
- package/server/engine/agents/explorer.md +190 -190
- package/server/engine/agents/index.js +230 -230
- package/server/engine/agents/schemas/design-system.json +156 -156
- package/server/engine/agents/schemas/tweak-schema.json +113 -113
- package/server/engine/agents/tweak-proposer.md +127 -127
- package/server/engine/agents/vision-checker.md +254 -254
- package/server/engine/browse/capture.js +422 -422
- package/server/engine/browse/card.js +137 -137
- package/server/engine/browse/handover.js +59 -59
- package/server/engine/browse/page-digest.js +119 -119
- package/server/engine/browse/refs.js +196 -196
- package/server/engine/browse/registry.js +307 -307
- package/server/engine/browse/screencast.js +170 -170
- package/server/engine/browse/state.js +121 -121
- package/server/engine/chatai/chat-log.js +79 -79
- package/server/engine/chatai/index.js +193 -193
- package/server/engine/chatai/openai-compat.js +152 -152
- package/server/engine/chatai/orchestrate.js +309 -309
- package/server/engine/chatai/perform.js +40 -40
- package/server/engine/chatai/summarize.js +79 -79
- package/server/engine/mcp/capability-gate.js +52 -52
- package/server/engine/mcp/index.js +351 -339
- package/server/engine/mcp/param-sanitizer.js +142 -142
- package/server/engine/mcp/tools/arrange-on-board.js +124 -124
- package/server/engine/mcp/tools/artifact-session.js +278 -278
- package/server/engine/mcp/tools/browse-computer.js +421 -421
- package/server/engine/mcp/tools/browse-find-batch.js +183 -183
- package/server/engine/mcp/tools/browse-screenshot.js +157 -157
- package/server/engine/mcp/tools/browse.js +480 -480
- package/server/engine/mcp/tools/build-docx.js +101 -101
- package/server/engine/mcp/tools/clear-pending-changes.js +99 -99
- package/server/engine/mcp/tools/create-on-board.js +152 -155
- package/server/engine/mcp/tools/crystallize-skill.js +168 -168
- package/server/engine/mcp/tools/edit-sketch.js +167 -0
- package/server/engine/mcp/tools/explain-style.js +237 -237
- package/server/engine/mcp/tools/export-handoff.js +133 -133
- package/server/engine/mcp/tools/expose-tweaks.js +149 -149
- package/server/engine/mcp/tools/generate-image.js +842 -842
- package/server/engine/mcp/tools/get-computed-styles.js +164 -164
- package/server/engine/mcp/tools/get-pending-changes.js +205 -205
- package/server/engine/mcp/tools/h3box-ssh.js +84 -84
- package/server/engine/mcp/tools/helpers/acquire-page.js +82 -82
- package/server/engine/mcp/tools/helpers/motion-lab.js +554 -554
- package/server/engine/mcp/tools/helpers/motion-scroll.js +112 -112
- package/server/engine/mcp/tools/helpers/perception-page.js +215 -215
- package/server/engine/mcp/tools/helpers/reference-download.js +103 -103
- package/server/engine/mcp/tools/helpers/rembg-bridge.py +80 -80
- package/server/engine/mcp/tools/helpers/shot-pipeline.js +280 -280
- package/server/engine/mcp/tools/highlight.js +68 -68
- package/server/engine/mcp/tools/list-pages.js +222 -222
- package/server/engine/mcp/tools/look-at-board.js +124 -0
- package/server/engine/mcp/tools/lookup-tags.js +59 -59
- package/server/engine/mcp/tools/navigate-to-page.js +60 -60
- package/server/engine/mcp/tools/organize-board.js +64 -64
- package/server/engine/mcp/tools/paint-still.js +434 -434
- package/server/engine/mcp/tools/pin-to-board.js +130 -130
- package/server/engine/mcp/tools/preview-deck.js +130 -130
- package/server/engine/mcp/tools/profile-scroll.js +305 -305
- package/server/engine/mcp/tools/publish-site.js +102 -102
- package/server/engine/mcp/tools/query-elements.js +195 -195
- package/server/engine/mcp/tools/read-board.js +190 -103
- package/server/engine/mcp/tools/read-document.js +93 -93
- package/server/engine/mcp/tools/read-page.js +264 -264
- package/server/engine/mcp/tools/read-tavern-json.js +143 -143
- package/server/engine/mcp/tools/read-user-view.js +59 -0
- package/server/engine/mcp/tools/record-decision.js +140 -140
- package/server/engine/mcp/tools/relate-on-board.js +112 -110
- package/server/engine/mcp/tools/report-issue.js +115 -115
- package/server/engine/mcp/tools/roll-film.js +266 -266
- package/server/engine/mcp/tools/screenshot-docx.js +138 -138
- package/server/engine/mcp/tools/screenshot-url.js +195 -195
- package/server/engine/mcp/tools/screenshot.js +583 -583
- package/server/engine/mcp/tools/sketch-on-board.js +337 -0
- package/server/engine/mcp/tools/tier-gate.js +96 -96
- package/server/engine/mcp/tools/trace-motion.js +215 -215
- package/server/engine/mcp/tools/web-search.js +548 -548
- package/server/engine/mcp/tools/write-on-board.js +130 -0
- package/server/engine/motion/inventory.js +349 -349
- package/server/engine/perception/session.js +235 -235
- package/server/engine/plugins/nodesign/.claude-plugin/plugin.json +5 -5
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/SKILL.md +199 -192
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/canvas.template.html +667 -667
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/hybrid-grid.md +22 -22
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/image-led-cover.md +25 -25
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/portrait.md +23 -23
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/quote-backdrop.md +21 -21
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/section-divider.md +23 -23
- package/server/engine/plugins/nodesign/skills/deskskill-engine-mini/patterns/text-led.md +21 -21
- package/server/engine/plugins/nodesign/skills/docx-craft/SKILL.md +169 -162
- package/server/engine/plugins/nodesign/skills/docx-craft/references/token-schema.md +407 -407
- package/server/engine/plugins/nodesign/skills/docx-craft//346/226/207/346/241/243.template.json +80 -80
- package/server/engine/plugins/nodesign/skills/rp-craft/SKILL.md +235 -228
- package/server/engine/plugins/nodesign/skills/rp-craft/patterns//346/274/224/345/207/272/351/241/265-/346/234/200/345/260/217/345/256/236/347/216/260.html +78 -78
- package/server/engine/plugins/nodesign/skills/rp-craft//346/274/224/345/207/272.template.js +268 -268
- package/server/engine/plugins/nodesign/skills/site-craft/SKILL.md +330 -323
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/build-lane.md +134 -134
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/cutout-collage.md +61 -61
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/mock-app.md +163 -163
- package/server/engine/plugins/nodesign/skills/site-craft/patterns/page-transitions.md +86 -86
- package/server/engine/runs/active-runs.js +698 -698
- package/server/engine/runs/board-tasklist.js +130 -0
- package/server/engine/runs/live-turn.js +252 -252
- package/server/engine/runs/store.js +364 -364
- package/server/engine/runs/turn-relay.js +217 -217
- package/server/engine/runtime/workspace.js +164 -164
- package/server/index.js +3 -0
- package/server/lib/artifact-file-path.js +80 -80
- package/server/lib/artifact-target.js +284 -284
- package/server/lib/asset-refs.js +239 -239
- package/server/lib/async-queue.js +104 -104
- package/server/lib/auto-relations.js +130 -130
- package/server/lib/binding-types.js +72 -60
- package/server/lib/board-graph-export.js +191 -0
- package/server/lib/board-groups.js +167 -0
- package/server/lib/board-hero.js +76 -0
- package/server/lib/board-kind-sizes.js +85 -62
- package/server/lib/board-relations.js +133 -133
- package/server/lib/browse-proxy.js +180 -180
- package/server/lib/canvas-id.js +36 -36
- package/server/lib/chalk.js +121 -0
- package/server/lib/cover.js +227 -227
- package/server/lib/danbooru-tags.js +291 -291
- package/server/lib/doc-extract.js +156 -156
- package/server/lib/docx/build-from-source.js +260 -260
- package/server/lib/docx/build.js +490 -490
- package/server/lib/docx/dump-styles.js +287 -287
- package/server/lib/docx/fonts/nodesign-cjk.conf +164 -164
- package/server/lib/docx/merge-runs.js +129 -129
- package/server/lib/docx/numbering.js +218 -218
- package/server/lib/docx/order.js +152 -152
- package/server/lib/docx/rawzip.js +172 -172
- package/server/lib/docx/render.js +92 -92
- package/server/lib/docx/text-lint.js +225 -225
- package/server/lib/docx/tokens.js +335 -335
- package/server/lib/docx/units.js +29 -29
- package/server/lib/docx/xml.js +291 -291
- package/server/lib/docx-pages.js +187 -187
- package/server/lib/export-collect.js +289 -289
- package/server/lib/export-package.js +210 -210
- package/server/lib/html-srcset.js +145 -145
- package/server/lib/image-variant.js +460 -460
- package/server/lib/ingress/forward-openai-chat.js +305 -305
- package/server/lib/ingress/openai-chat.js +491 -491
- package/server/lib/ingress/session-notice.js +66 -66
- package/server/lib/ingress/session-routes.js +68 -68
- package/server/lib/ingress/slot-probe.js +130 -130
- package/server/lib/ingress/upstream-billing.js +52 -52
- package/server/lib/ingress/upstream-fail-streak.js +72 -72
- package/server/lib/ingress/upstream-truncation.js +48 -48
- package/server/lib/issues-store.js +182 -182
- package/server/lib/kinds/deck.js +72 -72
- package/server/lib/kinds/docx.js +283 -283
- package/server/lib/kinds/file-kinds.js +113 -113
- package/server/lib/kinds/index.js +202 -202
- package/server/lib/kinds/site.js +161 -161
- package/server/lib/model-ingress.js +543 -543
- package/server/lib/moderation.js +255 -255
- package/server/lib/notice-store.js +103 -103
- package/server/lib/plugin-install.js +104 -104
- package/server/lib/plugin-validator.js +721 -721
- package/server/lib/publish-store.js +115 -115
- package/server/lib/quick-summary.js +52 -52
- package/server/lib/quota.js +270 -270
- package/server/lib/rate-window.js +29 -29
- package/server/lib/reference-assets.js +92 -92
- package/server/lib/region-shot.js +135 -135
- package/server/lib/safe-path.js +73 -73
- package/server/lib/sdk-session.js +33 -33
- package/server/lib/showcase-store.js +92 -92
- package/server/lib/site-publish.js +465 -465
- package/server/lib/sketch-layout.js +277 -0
- package/server/lib/ssrf-guard.js +432 -432
- package/server/lib/task-scan.js +158 -158
- package/server/lib/tavern-json.js +154 -154
- package/server/lib/video-variant.js +237 -237
- package/server/lib/workspace-path.js +33 -33
- package/server/ops/fix-sdk-musl.mjs +40 -40
- package/server/ops/install-macos-fonts.sh +114 -114
- package/server/ops/macos-fonts.conf +336 -336
- package/server/ops/sandbox-shim/bwrap +57 -57
- package/server/projects/assets-summary.js +119 -119
- package/server/projects/auto-name.js +53 -53
- package/server/projects/board-limits.js +12 -0
- package/server/projects/board-sanitize.js +252 -0
- package/server/projects/board-store.js +507 -640
- package/server/projects/move-entry.js +103 -103
- package/server/projects/store.js +270 -270
- package/server/projects/ui-config.js +60 -54
- package/server/projects/viewpoint-store.js +78 -0
- package/server/projects/workspace-templates.js +53 -53
- package/server/projects/workspace.js +1025 -1025
- package/server/runtime/local-config.js +177 -177
- package/server/runtime/profile.js +72 -72
- package/server/services/rembg-service.py +334 -334
- package/server/shared/README.md +25 -25
- package/server/shared/deck.js +54 -54
- package/server/shared/time.js +49 -49
- package/server/style-pipeline/README.md +53 -53
- package/server/ws/broker.js +39 -36
- package/server/ws/browse-channel.js +177 -177
- package/server/ws/index.js +386 -386
- package/web/README.md +89 -89
- package/web/dist/assets/BrowserWindow-P_vIdh-G.js +11 -0
- package/web/dist/assets/{DeckWindow-4G0xX7P3.js → DeckWindow-BpLv5082.js} +3 -3
- package/web/dist/assets/{DocxWindow-BXQsoPkh.js → DocxWindow-DSAU1-tD.js} +4 -4
- package/web/dist/assets/MermaidBlock-DR1GikCv.js +313 -0
- package/web/dist/assets/SiteWindow-92uBuRRR.js +18 -0
- package/web/dist/assets/abnfDiagram-VCTEODGH-uA8Esix4.js +1 -0
- package/web/dist/assets/arc-D_khH_xN.js +1 -0
- package/web/dist/assets/architectureDiagram-5GKGNRK7-DydJHqOt.js +36 -0
- package/web/dist/assets/blockDiagram-NRAW4CY4-B7wBbKiW.js +129 -0
- package/web/dist/assets/c4Diagram-UCG6FXSJ-6mrH0x7Y.js +38 -0
- package/web/dist/assets/channel-DGkccMO1.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-Cuikho5Q.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-3-KZ5AUz.js +15 -0
- package/web/dist/assets/chunk-F27PBJKO-Bkwq2gGU.js +1 -0
- package/web/dist/assets/chunk-G27WJ6UU-BLyQzdGE.js +231 -0
- package/web/dist/assets/chunk-JWPE2WC7-B7HxxQds.js +1 -0
- package/web/dist/assets/chunk-LCL6LL3I-CtXrnUwF.js +206 -0
- package/web/dist/assets/chunk-POPQ4Y6H-dxddZlXt.js +1 -0
- package/web/dist/assets/chunk-SVP7TREG-DpkmrgHn.js +88 -0
- package/web/dist/assets/chunk-XXDRQBXY-BwZ7RbpQ.js +1 -0
- package/web/dist/assets/classDiagram-DTDB5LWJ-BGscw3OD.js +1 -0
- package/web/dist/assets/classDiagram-v2-JRS7N3AN-BGscw3OD.js +1 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-DGFOsMUt.js +1 -0
- package/web/dist/assets/cynefin-OW5HDTMX-DUwn3ehS.js +178 -0
- package/web/dist/assets/cynefinDiagram-5FMLGOSQ-DlLAOZ9x.js +62 -0
- package/web/dist/assets/cytoscape.esm-BjAbmLdb.js +331 -0
- package/web/dist/assets/dagre-3AP2YEHR-CyourLfz.js +4 -0
- package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/web/dist/assets/diagram-S7CK7UJ4-BTMbx2np.js +30 -0
- package/web/dist/assets/diagram-UQ7AKVKN-UK94_1-P.js +41 -0
- package/web/dist/assets/diagram-VSXAHHWV-C7zS-v9v.js +3 -0
- package/web/dist/assets/diagram-VX7I27RA-DKJRa6CK.js +24 -0
- package/web/dist/assets/diagram-Z3DM3KII-kUbAfGAp.js +24 -0
- package/web/dist/assets/ebnfDiagram-PWID7BFC-CVW16_vb.js +1 -0
- package/web/dist/assets/erDiagram-SSCWMZ5O-BRQMFQ5y.js +99 -0
- package/web/dist/assets/flowDiagram-A5DVABFB-S34LpLtK.js +168 -0
- package/web/dist/assets/ganttDiagram-EL5Y4UJY-BFiqk1-G.js +292 -0
- package/web/dist/assets/gitGraphDiagram-WWUBYQGX-LZsrdyyv.js +106 -0
- package/web/dist/assets/index-GAamh1p4.js +2152 -0
- package/web/dist/assets/infoDiagram-RXCK75RN-0DvN6KIp.js +2 -0
- package/web/dist/assets/init-Gi6I4Gst.js +1 -0
- package/web/dist/assets/ishikawaDiagram-5VMMS53U-CaY3A-Bx.js +70 -0
- package/web/dist/assets/journeyDiagram-EYS64GPL-BBeiaCrj.js +139 -0
- package/web/dist/assets/kanban-definition-3QL26DDD-ux42DRXQ.js +89 -0
- package/web/dist/assets/layout-CnXiF_NB.js +1 -0
- package/web/dist/assets/linear-BMW0u6G6.js +1 -0
- package/web/dist/assets/mindmap-definition-FBJOCRG2-hUxSpdKn.js +96 -0
- package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/web/dist/assets/pegDiagram-XKGWAZYB-aCaQPH0w.js +1 -0
- package/web/dist/assets/{pending-edit-apply-DTjo2geW.js → pending-edit-apply-AcdOQ9Ij.js} +6 -6
- package/web/dist/assets/pieDiagram-E7YTZNPT-CmOEZ8zg.js +39 -0
- package/web/dist/assets/quadrantDiagram-AXDQQJYC-VW6fAhsV.js +7 -0
- package/web/dist/assets/railroadDiagram-O6MQD6OU-CKJ7Ba5K.js +1 -0
- package/web/dist/assets/requirementDiagram-EFPCY7ZU-pNGkq9Vw.js +84 -0
- package/web/dist/assets/{rotate-cw-LMT3x1Zj.js → rotate-cw-KAfChbGV.js} +1 -1
- package/web/dist/assets/sankeyDiagram-P5KCCOFB-BIMmDTfZ.js +40 -0
- package/web/dist/assets/sequenceDiagram-WJ2MYXX4-BBW7wzKY.js +162 -0
- package/web/dist/assets/sizeCapture-X5ZJPWSS-DdkXmLYR.js +1 -0
- package/web/dist/assets/{square-dashed-mouse-pointer-CBoAkfhi.js → square-dashed-mouse-pointer-CDUlhUP7.js} +1 -1
- package/web/dist/assets/stateDiagram-HBIQ2CUA-W313Uz16.js +1 -0
- package/web/dist/assets/stateDiagram-v2-4QOOHH4V-DDhJBZzf.js +1 -0
- package/web/dist/assets/swimlanes-XN3QIQJK-C29TL26K.js +1 -0
- package/web/dist/assets/swimlanesDiagram-VK2B7HYN-BfN-Xdmu.js +8 -0
- package/web/dist/assets/timeline-definition-24CTP7MA-CF0JMObX.js +120 -0
- package/web/dist/assets/vennDiagram-4TSXK5OY-DrDFsaH3.js +34 -0
- package/web/dist/assets/wardleyDiagram-VM6X3IG4-CVrnRIS_.js +78 -0
- package/web/dist/assets/xychartDiagram-S5SC5T6Z-BvkN1zsT.js +7 -0
- package/web/dist/index.html +17 -17
- package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +0 -11
- package/web/dist/assets/SiteWindow-D6eS-2gM.js +0 -18
- package/web/dist/assets/index-Cbl3ATvp.js +0 -2125
package/server/projects/store.js
CHANGED
|
@@ -1,270 +1,270 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* server/projects/store.js — Project DB(SQLite)
|
|
3
|
-
*
|
|
4
|
-
* 跟 runs/store.js 共享同一个 better-sqlite3 connection(import 即拿 db 实例)。
|
|
5
|
-
*
|
|
6
|
-
* 表 projects:
|
|
7
|
-
* id proj_<base36-ts>_<rand4>
|
|
8
|
-
* name 人类可读
|
|
9
|
-
* skill_id 默认 deskskill-engine-mini
|
|
10
|
-
* active_session_id SDK query() 返回的 sessionId(用 query({ resume }) 续 turn)
|
|
11
|
-
* created_at / updated_at
|
|
12
|
-
*
|
|
13
|
-
* 同时给 runs 表加 project_id 列(ALTER 幂等),追溯 run 归属哪个 project。
|
|
14
|
-
*
|
|
15
|
-
* project 删除时由调用层负责级联删 workspace 目录 + 关联 runs。
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import db from '../engine/runs/store.js';
|
|
19
|
-
|
|
20
|
-
// ── Schema ──
|
|
21
|
-
db.exec(`
|
|
22
|
-
CREATE TABLE IF NOT EXISTS projects (
|
|
23
|
-
id TEXT PRIMARY KEY,
|
|
24
|
-
name TEXT NOT NULL,
|
|
25
|
-
skill_id TEXT NOT NULL DEFAULT 'deskskill-engine-mini',
|
|
26
|
-
description TEXT,
|
|
27
|
-
active_session_id TEXT,
|
|
28
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
29
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
CREATE INDEX IF NOT EXISTS idx_projects_updated ON projects(updated_at DESC);
|
|
33
|
-
`);
|
|
34
|
-
|
|
35
|
-
// ALTER runs 加 project_id(幂等)
|
|
36
|
-
const runsCols = db.prepare('PRAGMA table_info(runs)').all();
|
|
37
|
-
if (!runsCols.some(c => c.name === 'project_id')) {
|
|
38
|
-
db.exec('ALTER TABLE runs ADD COLUMN project_id TEXT');
|
|
39
|
-
db.exec('CREATE INDEX IF NOT EXISTS idx_runs_project_created ON runs(project_id, created_at DESC)');
|
|
40
|
-
console.log('[projects/store] runs.project_id column added');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 兼容老 DB:projects 表可能创建于 active_session_id 字段加入之前,
|
|
44
|
-
// 缺这列。CREATE TABLE IF NOT EXISTS 不会修改已存在表,需要 ALTER 补。
|
|
45
|
-
const projectsCols = db.prepare('PRAGMA table_info(projects)').all();
|
|
46
|
-
const projectsColNames = new Set(projectsCols.map(c => c.name));
|
|
47
|
-
if (!projectsColNames.has('active_session_id')) {
|
|
48
|
-
db.exec('ALTER TABLE projects ADD COLUMN active_session_id TEXT');
|
|
49
|
-
console.log('[projects/store] projects.active_session_id column added (old DB compat)');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// S1:projects 表加 description 列(幂等)+ 一次性清洗老 active_session_id。
|
|
53
|
-
//
|
|
54
|
-
// 旧 active_session_id 全是无效值——之前 session-loop.js persistSession=false 时 SDK
|
|
55
|
-
// 不写 JSONL 但 setActiveSession 依然把 sessionId 写回(写不成功也被 turn.js
|
|
56
|
-
// 的 try/catch 吞掉,列存在时则成功写入幽灵 sid)。S1 切换 persistSession=true
|
|
57
|
-
// 之前必须把这些幽灵 sid 清掉,否则首次 resume 全 fail(兜底有 try/catch retry
|
|
58
|
-
// 但能少踩就少踩)。
|
|
59
|
-
//
|
|
60
|
-
// 清洗跟 description 加列绑定 — if 进过一次后 description 列存在,下次启动
|
|
61
|
-
// 不再进,自然只跑一次。
|
|
62
|
-
if (!projectsColNames.has('description')) {
|
|
63
|
-
db.exec('ALTER TABLE projects ADD COLUMN description TEXT');
|
|
64
|
-
db.exec("UPDATE projects SET active_session_id = NULL WHERE active_session_id IS NOT NULL");
|
|
65
|
-
console.log('[projects/store] projects.description column added; active_session_id cleared');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 入口流程重构:kind 区分「标准项目(project)」vs「闪聊(quick)」。
|
|
69
|
-
// 默认 'project' 让老数据零行为变化;闪聊由 Home 大输入框隐式建出,标 'quick'。
|
|
70
|
-
// 用户可在 Workspace 顶栏「升级为项目」把 quick → project(PATCH kind)。
|
|
71
|
-
if (!projectsColNames.has('kind')) {
|
|
72
|
-
db.exec("ALTER TABLE projects ADD COLUMN kind TEXT NOT NULL DEFAULT 'project'");
|
|
73
|
-
db.exec("CREATE INDEX IF NOT EXISTS idx_projects_kind_updated ON projects(kind, updated_at DESC)");
|
|
74
|
-
console.log('[projects/store] projects.kind column added (default project)');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 首页入口重构(2026-07-28):主页大输入框不再建"闪聊",直接建真项目,
|
|
78
|
-
// 名字先用用户那句话垫着,第一轮跑完再用 SDK helper 写的会话摘要改名一次。
|
|
79
|
-
// auto_named=1 表示"这名字是系统垫的,可以被摘要覆盖";用户一改名就清零。
|
|
80
|
-
if (!projectsColNames.has('auto_named')) {
|
|
81
|
-
db.exec('ALTER TABLE projects ADD COLUMN auto_named INTEGER NOT NULL DEFAULT 0');
|
|
82
|
-
console.log('[projects/store] projects.auto_named column added');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 多用户内测(2026-07-30):项目归属。NULL 的存量行由 bootstrapAuth() 回填 admin
|
|
86
|
-
if (!projectsColNames.has('owner_id')) {
|
|
87
|
-
db.exec('ALTER TABLE projects ADD COLUMN owner_id TEXT');
|
|
88
|
-
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_owner_updated ON projects(owner_id, updated_at DESC)');
|
|
89
|
-
console.log('[projects/store] projects.owner_id column added');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 多用户内测(2026-07-30):runs 计量真列 + 归属。原来 usage 全塞 metadata JSON
|
|
93
|
-
// (且值全 0,absorbResult 断链),配额查询要 sum,promote 成真列
|
|
94
|
-
const RUN_METRIC_COLS = [
|
|
95
|
-
['user_id', 'TEXT'],
|
|
96
|
-
['input_tokens', 'INTEGER'],
|
|
97
|
-
['output_tokens', 'INTEGER'],
|
|
98
|
-
['cache_read_tokens', 'INTEGER'],
|
|
99
|
-
['cache_create_tokens', 'INTEGER'],
|
|
100
|
-
['total_cost_usd', 'REAL'],
|
|
101
|
-
];
|
|
102
|
-
{
|
|
103
|
-
const cols = new Set(db.prepare('PRAGMA table_info(runs)').all().map(c => c.name));
|
|
104
|
-
let added = false;
|
|
105
|
-
for (const [name, type] of RUN_METRIC_COLS) {
|
|
106
|
-
if (!cols.has(name)) {
|
|
107
|
-
db.exec(`ALTER TABLE runs ADD COLUMN ${name} ${type}`);
|
|
108
|
-
added = true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (added) {
|
|
112
|
-
db.exec('CREATE INDEX IF NOT EXISTS idx_runs_user_created ON runs(user_id, created_at DESC)');
|
|
113
|
-
console.log('[projects/store] runs 计量列 + user_id added');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 07-31 定案的欠账:runs 记会话归属 —— 回答"哪个会话最烧钱/最长"不用去数
|
|
118
|
-
// sessions/ 目录。存量行 NULL 不回填(目录里还能对出来,不值得写迁移)。
|
|
119
|
-
{
|
|
120
|
-
const cols = new Set(db.prepare('PRAGMA table_info(runs)').all().map(c => c.name));
|
|
121
|
-
if (!cols.has('session_id')) {
|
|
122
|
-
db.exec('ALTER TABLE runs ADD COLUMN session_id TEXT');
|
|
123
|
-
db.exec('CREATE INDEX IF NOT EXISTS idx_runs_session ON runs(session_id)');
|
|
124
|
-
console.log('[projects/store] runs.session_id added');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ── ID ──
|
|
129
|
-
|
|
130
|
-
export function newProjectId() {
|
|
131
|
-
const ts = Date.now().toString(36);
|
|
132
|
-
const rand = Math.random().toString(36).slice(2, 6);
|
|
133
|
-
return `proj_${ts}_${rand}`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const PROJECT_ID_RE = /^proj_[a-z0-9_]{6,80}$/i;
|
|
137
|
-
|
|
138
|
-
export function validateProjectId(pid) {
|
|
139
|
-
if (typeof pid !== 'string' || !PROJECT_ID_RE.test(pid)) {
|
|
140
|
-
throw Object.assign(new Error(`非法 projectId: ${JSON.stringify(pid)}`), { code: 'INVALID_PROJECT_ID' });
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// ── 行 ↔ 对象 ──
|
|
145
|
-
|
|
146
|
-
function rowToProject(row) {
|
|
147
|
-
if (!row) return null;
|
|
148
|
-
return {
|
|
149
|
-
id: row.id,
|
|
150
|
-
name: row.name,
|
|
151
|
-
skillId: row.skill_id,
|
|
152
|
-
description: row.description || null,
|
|
153
|
-
kind: row.kind || 'project',
|
|
154
|
-
autoNamed: !!row.auto_named,
|
|
155
|
-
ownerId: row.owner_id || null,
|
|
156
|
-
activeSessionId: row.active_session_id,
|
|
157
|
-
createdAt: row.created_at,
|
|
158
|
-
updatedAt: row.updated_at,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// ── CRUD ──
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 列项目(按 updated_at 倒序)。
|
|
166
|
-
* @param {object} opts
|
|
167
|
-
* @param {string|null} opts.owner **必填**:用户 id 只看自己的;null = 全量
|
|
168
|
-
* (admin / 内部调用显式声明)。做成必填是防"漏传就全库泄漏"——kind 的
|
|
169
|
-
* 默认值语义已经踩过一次这种坑
|
|
170
|
-
* @param {'project'|'quick'} [opts.kind]
|
|
171
|
-
*/
|
|
172
|
-
export function listProjects({ limit = 100, kind, owner } = {}) {
|
|
173
|
-
if (owner === undefined) {
|
|
174
|
-
throw new Error('listProjects: owner 必填(用户 id 或 null=全量)');
|
|
175
|
-
}
|
|
176
|
-
const wheres = [];
|
|
177
|
-
const args = [];
|
|
178
|
-
if (kind) { wheres.push('kind = ?'); args.push(kind); }
|
|
179
|
-
if (owner !== null) { wheres.push('owner_id = ?'); args.push(owner); }
|
|
180
|
-
const whereSql = wheres.length ? `WHERE ${wheres.join(' AND ')}` : '';
|
|
181
|
-
const rows = db.prepare(
|
|
182
|
-
`SELECT * FROM projects ${whereSql} ORDER BY updated_at DESC LIMIT ?`,
|
|
183
|
-
).all(...args, limit);
|
|
184
|
-
return rows.map(rowToProject);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** 读单条 */
|
|
188
|
-
export function getProject(id) {
|
|
189
|
-
validateProjectId(id);
|
|
190
|
-
const row = db.prepare('SELECT * FROM projects WHERE id = ?').get(id);
|
|
191
|
-
return rowToProject(row);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* 创建 project。
|
|
196
|
-
* @param {object} opts
|
|
197
|
-
* @param {string} opts.name
|
|
198
|
-
* @param {string} [opts.skillId='deskskill-engine-mini']
|
|
199
|
-
* @param {string} [opts.description] 人类可读的项目描述(agent 不读,仅 UI 用)
|
|
200
|
-
* @param {'project'|'quick'} [opts.kind='project'] 标准项目 / 闪聊(Home 隐式建)
|
|
201
|
-
*/
|
|
202
|
-
export function createProject({
|
|
203
|
-
name,
|
|
204
|
-
skillId = 'deskskill-engine-mini',
|
|
205
|
-
description = null,
|
|
206
|
-
kind = 'project',
|
|
207
|
-
autoNamed = false,
|
|
208
|
-
ownerId = null,
|
|
209
|
-
}) {
|
|
210
|
-
if (!name || typeof name !== 'string') throw new Error('createProject: name 必填');
|
|
211
|
-
if (kind !== 'project' && kind !== 'quick') {
|
|
212
|
-
throw new Error(`createProject: kind 非法 (${kind})`);
|
|
213
|
-
}
|
|
214
|
-
const id = newProjectId();
|
|
215
|
-
const desc = (typeof description === 'string' && description.trim()) ? description.trim() : null;
|
|
216
|
-
db.prepare(
|
|
217
|
-
`INSERT INTO projects (id, name, skill_id, description, kind, auto_named, owner_id) VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
218
|
-
).run(id, name.trim(), skillId, desc, kind, autoNamed ? 1 : 0, ownerId);
|
|
219
|
-
return getProject(id);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** 更新(仅允许 name / skill_id / description / active_session_id / kind / autoNamed) */
|
|
223
|
-
export function updateProject(id, patch) {
|
|
224
|
-
validateProjectId(id);
|
|
225
|
-
// 用户显式改名 = 这名字他自己定了,系统不再拿摘要覆盖
|
|
226
|
-
if ('name' in patch && !('autoNamed' in patch)) patch = { ...patch, autoNamed: false };
|
|
227
|
-
// kind 只允许枚举值(升级闪聊用 PATCH { kind: 'project' })
|
|
228
|
-
if ('kind' in patch && patch.kind !== 'project' && patch.kind !== 'quick') {
|
|
229
|
-
throw new Error(`updateProject: kind 非法 (${patch.kind})`);
|
|
230
|
-
}
|
|
231
|
-
const map = {
|
|
232
|
-
name: 'name',
|
|
233
|
-
skillId: 'skill_id',
|
|
234
|
-
description: 'description',
|
|
235
|
-
activeSessionId: 'active_session_id',
|
|
236
|
-
kind: 'kind',
|
|
237
|
-
autoNamed: 'auto_named',
|
|
238
|
-
};
|
|
239
|
-
const sets = [];
|
|
240
|
-
const args = [];
|
|
241
|
-
for (const [camelK, sqlK] of Object.entries(map)) {
|
|
242
|
-
if (camelK in patch) {
|
|
243
|
-
sets.push(`${sqlK} = ?`);
|
|
244
|
-
args.push(camelK === 'autoNamed' ? (patch[camelK] ? 1 : 0) : patch[camelK]);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (sets.length === 0) return getProject(id);
|
|
248
|
-
sets.push("updated_at = datetime('now')");
|
|
249
|
-
args.push(id);
|
|
250
|
-
db.prepare(`UPDATE projects SET ${sets.join(', ')} WHERE id = ?`).run(...args);
|
|
251
|
-
return getProject(id);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** 删除(不级联 — 调用层负责删 workspace 目录 + 关联 runs) */
|
|
255
|
-
export function deleteProject(id) {
|
|
256
|
-
validateProjectId(id);
|
|
257
|
-
const row = db.prepare('DELETE FROM projects WHERE id = ? RETURNING *').get(id);
|
|
258
|
-
return rowToProject(row);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/** 设置 active_session_id(封装常用) */
|
|
262
|
-
export function setActiveSession(projectId, sessionId) {
|
|
263
|
-
return updateProject(projectId, { activeSessionId: sessionId });
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/** 列 project 关联的 runs(用于级联清理) */
|
|
267
|
-
export function listRunsForProject(projectId) {
|
|
268
|
-
validateProjectId(projectId);
|
|
269
|
-
return db.prepare('SELECT id FROM runs WHERE project_id = ? ORDER BY created_at DESC').all(projectId);
|
|
270
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* server/projects/store.js — Project DB(SQLite)
|
|
3
|
+
*
|
|
4
|
+
* 跟 runs/store.js 共享同一个 better-sqlite3 connection(import 即拿 db 实例)。
|
|
5
|
+
*
|
|
6
|
+
* 表 projects:
|
|
7
|
+
* id proj_<base36-ts>_<rand4>
|
|
8
|
+
* name 人类可读
|
|
9
|
+
* skill_id 默认 deskskill-engine-mini
|
|
10
|
+
* active_session_id SDK query() 返回的 sessionId(用 query({ resume }) 续 turn)
|
|
11
|
+
* created_at / updated_at
|
|
12
|
+
*
|
|
13
|
+
* 同时给 runs 表加 project_id 列(ALTER 幂等),追溯 run 归属哪个 project。
|
|
14
|
+
*
|
|
15
|
+
* project 删除时由调用层负责级联删 workspace 目录 + 关联 runs。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import db from '../engine/runs/store.js';
|
|
19
|
+
|
|
20
|
+
// ── Schema ──
|
|
21
|
+
db.exec(`
|
|
22
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
23
|
+
id TEXT PRIMARY KEY,
|
|
24
|
+
name TEXT NOT NULL,
|
|
25
|
+
skill_id TEXT NOT NULL DEFAULT 'deskskill-engine-mini',
|
|
26
|
+
description TEXT,
|
|
27
|
+
active_session_id TEXT,
|
|
28
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
29
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_projects_updated ON projects(updated_at DESC);
|
|
33
|
+
`);
|
|
34
|
+
|
|
35
|
+
// ALTER runs 加 project_id(幂等)
|
|
36
|
+
const runsCols = db.prepare('PRAGMA table_info(runs)').all();
|
|
37
|
+
if (!runsCols.some(c => c.name === 'project_id')) {
|
|
38
|
+
db.exec('ALTER TABLE runs ADD COLUMN project_id TEXT');
|
|
39
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_runs_project_created ON runs(project_id, created_at DESC)');
|
|
40
|
+
console.log('[projects/store] runs.project_id column added');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 兼容老 DB:projects 表可能创建于 active_session_id 字段加入之前,
|
|
44
|
+
// 缺这列。CREATE TABLE IF NOT EXISTS 不会修改已存在表,需要 ALTER 补。
|
|
45
|
+
const projectsCols = db.prepare('PRAGMA table_info(projects)').all();
|
|
46
|
+
const projectsColNames = new Set(projectsCols.map(c => c.name));
|
|
47
|
+
if (!projectsColNames.has('active_session_id')) {
|
|
48
|
+
db.exec('ALTER TABLE projects ADD COLUMN active_session_id TEXT');
|
|
49
|
+
console.log('[projects/store] projects.active_session_id column added (old DB compat)');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// S1:projects 表加 description 列(幂等)+ 一次性清洗老 active_session_id。
|
|
53
|
+
//
|
|
54
|
+
// 旧 active_session_id 全是无效值——之前 session-loop.js persistSession=false 时 SDK
|
|
55
|
+
// 不写 JSONL 但 setActiveSession 依然把 sessionId 写回(写不成功也被 turn.js
|
|
56
|
+
// 的 try/catch 吞掉,列存在时则成功写入幽灵 sid)。S1 切换 persistSession=true
|
|
57
|
+
// 之前必须把这些幽灵 sid 清掉,否则首次 resume 全 fail(兜底有 try/catch retry
|
|
58
|
+
// 但能少踩就少踩)。
|
|
59
|
+
//
|
|
60
|
+
// 清洗跟 description 加列绑定 — if 进过一次后 description 列存在,下次启动
|
|
61
|
+
// 不再进,自然只跑一次。
|
|
62
|
+
if (!projectsColNames.has('description')) {
|
|
63
|
+
db.exec('ALTER TABLE projects ADD COLUMN description TEXT');
|
|
64
|
+
db.exec("UPDATE projects SET active_session_id = NULL WHERE active_session_id IS NOT NULL");
|
|
65
|
+
console.log('[projects/store] projects.description column added; active_session_id cleared');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 入口流程重构:kind 区分「标准项目(project)」vs「闪聊(quick)」。
|
|
69
|
+
// 默认 'project' 让老数据零行为变化;闪聊由 Home 大输入框隐式建出,标 'quick'。
|
|
70
|
+
// 用户可在 Workspace 顶栏「升级为项目」把 quick → project(PATCH kind)。
|
|
71
|
+
if (!projectsColNames.has('kind')) {
|
|
72
|
+
db.exec("ALTER TABLE projects ADD COLUMN kind TEXT NOT NULL DEFAULT 'project'");
|
|
73
|
+
db.exec("CREATE INDEX IF NOT EXISTS idx_projects_kind_updated ON projects(kind, updated_at DESC)");
|
|
74
|
+
console.log('[projects/store] projects.kind column added (default project)');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 首页入口重构(2026-07-28):主页大输入框不再建"闪聊",直接建真项目,
|
|
78
|
+
// 名字先用用户那句话垫着,第一轮跑完再用 SDK helper 写的会话摘要改名一次。
|
|
79
|
+
// auto_named=1 表示"这名字是系统垫的,可以被摘要覆盖";用户一改名就清零。
|
|
80
|
+
if (!projectsColNames.has('auto_named')) {
|
|
81
|
+
db.exec('ALTER TABLE projects ADD COLUMN auto_named INTEGER NOT NULL DEFAULT 0');
|
|
82
|
+
console.log('[projects/store] projects.auto_named column added');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 多用户内测(2026-07-30):项目归属。NULL 的存量行由 bootstrapAuth() 回填 admin
|
|
86
|
+
if (!projectsColNames.has('owner_id')) {
|
|
87
|
+
db.exec('ALTER TABLE projects ADD COLUMN owner_id TEXT');
|
|
88
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_owner_updated ON projects(owner_id, updated_at DESC)');
|
|
89
|
+
console.log('[projects/store] projects.owner_id column added');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 多用户内测(2026-07-30):runs 计量真列 + 归属。原来 usage 全塞 metadata JSON
|
|
93
|
+
// (且值全 0,absorbResult 断链),配额查询要 sum,promote 成真列
|
|
94
|
+
const RUN_METRIC_COLS = [
|
|
95
|
+
['user_id', 'TEXT'],
|
|
96
|
+
['input_tokens', 'INTEGER'],
|
|
97
|
+
['output_tokens', 'INTEGER'],
|
|
98
|
+
['cache_read_tokens', 'INTEGER'],
|
|
99
|
+
['cache_create_tokens', 'INTEGER'],
|
|
100
|
+
['total_cost_usd', 'REAL'],
|
|
101
|
+
];
|
|
102
|
+
{
|
|
103
|
+
const cols = new Set(db.prepare('PRAGMA table_info(runs)').all().map(c => c.name));
|
|
104
|
+
let added = false;
|
|
105
|
+
for (const [name, type] of RUN_METRIC_COLS) {
|
|
106
|
+
if (!cols.has(name)) {
|
|
107
|
+
db.exec(`ALTER TABLE runs ADD COLUMN ${name} ${type}`);
|
|
108
|
+
added = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (added) {
|
|
112
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_runs_user_created ON runs(user_id, created_at DESC)');
|
|
113
|
+
console.log('[projects/store] runs 计量列 + user_id added');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 07-31 定案的欠账:runs 记会话归属 —— 回答"哪个会话最烧钱/最长"不用去数
|
|
118
|
+
// sessions/ 目录。存量行 NULL 不回填(目录里还能对出来,不值得写迁移)。
|
|
119
|
+
{
|
|
120
|
+
const cols = new Set(db.prepare('PRAGMA table_info(runs)').all().map(c => c.name));
|
|
121
|
+
if (!cols.has('session_id')) {
|
|
122
|
+
db.exec('ALTER TABLE runs ADD COLUMN session_id TEXT');
|
|
123
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_runs_session ON runs(session_id)');
|
|
124
|
+
console.log('[projects/store] runs.session_id added');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── ID ──
|
|
129
|
+
|
|
130
|
+
export function newProjectId() {
|
|
131
|
+
const ts = Date.now().toString(36);
|
|
132
|
+
const rand = Math.random().toString(36).slice(2, 6);
|
|
133
|
+
return `proj_${ts}_${rand}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const PROJECT_ID_RE = /^proj_[a-z0-9_]{6,80}$/i;
|
|
137
|
+
|
|
138
|
+
export function validateProjectId(pid) {
|
|
139
|
+
if (typeof pid !== 'string' || !PROJECT_ID_RE.test(pid)) {
|
|
140
|
+
throw Object.assign(new Error(`非法 projectId: ${JSON.stringify(pid)}`), { code: 'INVALID_PROJECT_ID' });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ── 行 ↔ 对象 ──
|
|
145
|
+
|
|
146
|
+
function rowToProject(row) {
|
|
147
|
+
if (!row) return null;
|
|
148
|
+
return {
|
|
149
|
+
id: row.id,
|
|
150
|
+
name: row.name,
|
|
151
|
+
skillId: row.skill_id,
|
|
152
|
+
description: row.description || null,
|
|
153
|
+
kind: row.kind || 'project',
|
|
154
|
+
autoNamed: !!row.auto_named,
|
|
155
|
+
ownerId: row.owner_id || null,
|
|
156
|
+
activeSessionId: row.active_session_id,
|
|
157
|
+
createdAt: row.created_at,
|
|
158
|
+
updatedAt: row.updated_at,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ── CRUD ──
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 列项目(按 updated_at 倒序)。
|
|
166
|
+
* @param {object} opts
|
|
167
|
+
* @param {string|null} opts.owner **必填**:用户 id 只看自己的;null = 全量
|
|
168
|
+
* (admin / 内部调用显式声明)。做成必填是防"漏传就全库泄漏"——kind 的
|
|
169
|
+
* 默认值语义已经踩过一次这种坑
|
|
170
|
+
* @param {'project'|'quick'} [opts.kind]
|
|
171
|
+
*/
|
|
172
|
+
export function listProjects({ limit = 100, kind, owner } = {}) {
|
|
173
|
+
if (owner === undefined) {
|
|
174
|
+
throw new Error('listProjects: owner 必填(用户 id 或 null=全量)');
|
|
175
|
+
}
|
|
176
|
+
const wheres = [];
|
|
177
|
+
const args = [];
|
|
178
|
+
if (kind) { wheres.push('kind = ?'); args.push(kind); }
|
|
179
|
+
if (owner !== null) { wheres.push('owner_id = ?'); args.push(owner); }
|
|
180
|
+
const whereSql = wheres.length ? `WHERE ${wheres.join(' AND ')}` : '';
|
|
181
|
+
const rows = db.prepare(
|
|
182
|
+
`SELECT * FROM projects ${whereSql} ORDER BY updated_at DESC LIMIT ?`,
|
|
183
|
+
).all(...args, limit);
|
|
184
|
+
return rows.map(rowToProject);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** 读单条 */
|
|
188
|
+
export function getProject(id) {
|
|
189
|
+
validateProjectId(id);
|
|
190
|
+
const row = db.prepare('SELECT * FROM projects WHERE id = ?').get(id);
|
|
191
|
+
return rowToProject(row);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 创建 project。
|
|
196
|
+
* @param {object} opts
|
|
197
|
+
* @param {string} opts.name
|
|
198
|
+
* @param {string} [opts.skillId='deskskill-engine-mini']
|
|
199
|
+
* @param {string} [opts.description] 人类可读的项目描述(agent 不读,仅 UI 用)
|
|
200
|
+
* @param {'project'|'quick'} [opts.kind='project'] 标准项目 / 闪聊(Home 隐式建)
|
|
201
|
+
*/
|
|
202
|
+
export function createProject({
|
|
203
|
+
name,
|
|
204
|
+
skillId = 'deskskill-engine-mini',
|
|
205
|
+
description = null,
|
|
206
|
+
kind = 'project',
|
|
207
|
+
autoNamed = false,
|
|
208
|
+
ownerId = null,
|
|
209
|
+
}) {
|
|
210
|
+
if (!name || typeof name !== 'string') throw new Error('createProject: name 必填');
|
|
211
|
+
if (kind !== 'project' && kind !== 'quick') {
|
|
212
|
+
throw new Error(`createProject: kind 非法 (${kind})`);
|
|
213
|
+
}
|
|
214
|
+
const id = newProjectId();
|
|
215
|
+
const desc = (typeof description === 'string' && description.trim()) ? description.trim() : null;
|
|
216
|
+
db.prepare(
|
|
217
|
+
`INSERT INTO projects (id, name, skill_id, description, kind, auto_named, owner_id) VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
218
|
+
).run(id, name.trim(), skillId, desc, kind, autoNamed ? 1 : 0, ownerId);
|
|
219
|
+
return getProject(id);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 更新(仅允许 name / skill_id / description / active_session_id / kind / autoNamed) */
|
|
223
|
+
export function updateProject(id, patch) {
|
|
224
|
+
validateProjectId(id);
|
|
225
|
+
// 用户显式改名 = 这名字他自己定了,系统不再拿摘要覆盖
|
|
226
|
+
if ('name' in patch && !('autoNamed' in patch)) patch = { ...patch, autoNamed: false };
|
|
227
|
+
// kind 只允许枚举值(升级闪聊用 PATCH { kind: 'project' })
|
|
228
|
+
if ('kind' in patch && patch.kind !== 'project' && patch.kind !== 'quick') {
|
|
229
|
+
throw new Error(`updateProject: kind 非法 (${patch.kind})`);
|
|
230
|
+
}
|
|
231
|
+
const map = {
|
|
232
|
+
name: 'name',
|
|
233
|
+
skillId: 'skill_id',
|
|
234
|
+
description: 'description',
|
|
235
|
+
activeSessionId: 'active_session_id',
|
|
236
|
+
kind: 'kind',
|
|
237
|
+
autoNamed: 'auto_named',
|
|
238
|
+
};
|
|
239
|
+
const sets = [];
|
|
240
|
+
const args = [];
|
|
241
|
+
for (const [camelK, sqlK] of Object.entries(map)) {
|
|
242
|
+
if (camelK in patch) {
|
|
243
|
+
sets.push(`${sqlK} = ?`);
|
|
244
|
+
args.push(camelK === 'autoNamed' ? (patch[camelK] ? 1 : 0) : patch[camelK]);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (sets.length === 0) return getProject(id);
|
|
248
|
+
sets.push("updated_at = datetime('now')");
|
|
249
|
+
args.push(id);
|
|
250
|
+
db.prepare(`UPDATE projects SET ${sets.join(', ')} WHERE id = ?`).run(...args);
|
|
251
|
+
return getProject(id);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** 删除(不级联 — 调用层负责删 workspace 目录 + 关联 runs) */
|
|
255
|
+
export function deleteProject(id) {
|
|
256
|
+
validateProjectId(id);
|
|
257
|
+
const row = db.prepare('DELETE FROM projects WHERE id = ? RETURNING *').get(id);
|
|
258
|
+
return rowToProject(row);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 设置 active_session_id(封装常用) */
|
|
262
|
+
export function setActiveSession(projectId, sessionId) {
|
|
263
|
+
return updateProject(projectId, { activeSessionId: sessionId });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** 列 project 关联的 runs(用于级联清理) */
|
|
267
|
+
export function listRunsForProject(projectId) {
|
|
268
|
+
validateProjectId(projectId);
|
|
269
|
+
return db.prepare('SELECT id FROM runs WHERE project_id = ? ORDER BY created_at DESC').all(projectId);
|
|
270
|
+
}
|
|
@@ -1,54 +1,60 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 项目级 UI 配置 —— `<工作区根>/ui-config.json`(#25,2026-08-13)。
|
|
3
|
-
*
|
|
4
|
-
* 前身叫 session-config.json。扁平化(2026-08-07)之前一个会话一个沙盒,
|
|
5
|
-
* "会话配置"和"工作区配置"是同一件事;之后工作区全项目共用,这份文件
|
|
6
|
-
* 实际上早就是**项目级**的了,名字却还挂着 session —— 跟
|
|
7
|
-
* `.nd/<sid>/session-config.json`(真·会话级,存模型覆盖,session-model.js
|
|
8
|
-
* 专管,那份**不改名**)同名不同域。两份同名文件各自内部一致,但每个新
|
|
9
|
-
* 读者都要重新分辨一次"这是哪个 session-config"—— 评审点名的那种暗病。
|
|
10
|
-
*
|
|
11
|
-
* 迁移策略:读取认旧名回落(老项目的 tweaks 开关不丢),写入只写新名。
|
|
12
|
-
* 旧文件留在原地不动 —— 它同时是回滚的退路。
|
|
13
|
-
*
|
|
14
|
-
* 字段:
|
|
15
|
-
* - tweaks_mode_enabled: bool 是否启用 Tweaks 模式(默认启用)
|
|
16
|
-
*/
|
|
17
|
-
import path from 'path';
|
|
18
|
-
import { promises as fs } from 'fs';
|
|
19
|
-
|
|
20
|
-
export const UI_CONFIG_NAME = 'ui-config.json';
|
|
21
|
-
const LEGACY_NAME = 'session-config.json';
|
|
22
|
-
|
|
23
|
-
export const DEFAULT_UI_CONFIG = Object.freeze({
|
|
24
|
-
tweaks_mode_enabled: true,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 项目级 UI 配置 —— `<工作区根>/ui-config.json`(#25,2026-08-13)。
|
|
3
|
+
*
|
|
4
|
+
* 前身叫 session-config.json。扁平化(2026-08-07)之前一个会话一个沙盒,
|
|
5
|
+
* "会话配置"和"工作区配置"是同一件事;之后工作区全项目共用,这份文件
|
|
6
|
+
* 实际上早就是**项目级**的了,名字却还挂着 session —— 跟
|
|
7
|
+
* `.nd/<sid>/session-config.json`(真·会话级,存模型覆盖,session-model.js
|
|
8
|
+
* 专管,那份**不改名**)同名不同域。两份同名文件各自内部一致,但每个新
|
|
9
|
+
* 读者都要重新分辨一次"这是哪个 session-config"—— 评审点名的那种暗病。
|
|
10
|
+
*
|
|
11
|
+
* 迁移策略:读取认旧名回落(老项目的 tweaks 开关不丢),写入只写新名。
|
|
12
|
+
* 旧文件留在原地不动 —— 它同时是回滚的退路。
|
|
13
|
+
*
|
|
14
|
+
* 字段:
|
|
15
|
+
* - tweaks_mode_enabled: bool 是否启用 Tweaks 模式(默认启用)
|
|
16
|
+
*/
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { promises as fs } from 'fs';
|
|
19
|
+
|
|
20
|
+
export const UI_CONFIG_NAME = 'ui-config.json';
|
|
21
|
+
const LEGACY_NAME = 'session-config.json';
|
|
22
|
+
|
|
23
|
+
export const DEFAULT_UI_CONFIG = Object.freeze({
|
|
24
|
+
tweaks_mode_enabled: true,
|
|
25
|
+
/**
|
|
26
|
+
* 黑板模式(2026-08-23):用户专注头脑风暴时,画布取代侧栏成为主交互窗口 ——
|
|
27
|
+
* agent 每轮的主体内容落画布(sketch_on_board / edit_sketch),聊天里只留一两句;
|
|
28
|
+
* 草图落定时服务端广播 board.focus,前端把镜头带过去。
|
|
29
|
+
*/
|
|
30
|
+
blackboard_mode: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 读原始文件(新名 → 旧名回落)。**没有文件返回 null** —— hooks.js 靠
|
|
35
|
+
* "文件存在与否"决定注不注入提示(没碰过 toggle = 沉默),不能用默认值糊掉。
|
|
36
|
+
*/
|
|
37
|
+
export async function readUiConfigFile(workspaceRoot) {
|
|
38
|
+
for (const name of [UI_CONFIG_NAME, LEGACY_NAME]) {
|
|
39
|
+
try {
|
|
40
|
+
const raw = await fs.readFile(path.join(workspaceRoot, name), 'utf8');
|
|
41
|
+
const cfg = JSON.parse(raw);
|
|
42
|
+
if (cfg && typeof cfg === 'object' && !Array.isArray(cfg)) return cfg;
|
|
43
|
+
} catch { /* 试下一个名字 */ }
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 补齐默认字段(API 返回用) */
|
|
49
|
+
export function withUiDefaults(cfg) {
|
|
50
|
+
return { ...DEFAULT_UI_CONFIG, ...(cfg || {}) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 整份写入。只写新名;旧文件留着当回落/退路,不删不改 */
|
|
54
|
+
export async function writeUiConfig(workspaceRoot, cfg) {
|
|
55
|
+
await fs.writeFile(
|
|
56
|
+
path.join(workspaceRoot, UI_CONFIG_NAME),
|
|
57
|
+
JSON.stringify(cfg, null, 2),
|
|
58
|
+
'utf8',
|
|
59
|
+
);
|
|
60
|
+
}
|