@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/api/projects.js
CHANGED
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* server/api/projects.js — Project CRUD
|
|
3
|
-
*
|
|
4
|
-
* GET /api/projects 列项目(按 updated_at 倒序)
|
|
5
|
-
* POST /api/projects { name, skillId?, description? } → 创建 + ensureProjectWorkspace
|
|
6
|
-
* GET /api/projects/:pid 单项目
|
|
7
|
-
* PATCH /api/projects/:pid { name?, skillId?, description? } 部分更新
|
|
8
|
-
* DELETE /api/projects/:pid 删项目 + workspace + 关联 runs
|
|
9
|
-
*
|
|
10
|
-
* description: 可选,<= 2000 字符。仅 NoDesign 后端/前端 UI 用,agent 不感知
|
|
11
|
-
* (agent 看的是项目级 instruction = workspace/.claude/CLAUDE.md)。
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import express from 'express';
|
|
15
|
-
import {
|
|
16
|
-
listProjects, createProject, updateProject, deleteProject,
|
|
17
|
-
listRunsForProject,
|
|
18
|
-
} from '../projects/store.js';
|
|
19
|
-
import { guardProject } from './_guard.js';
|
|
20
|
-
import { taskManifest } from '../lib/artifact-target.js';
|
|
21
|
-
import { countPublishedByUser } from '../lib/publish-store.js';
|
|
22
|
-
import { checkQuota } from '../lib/quota.js';
|
|
23
|
-
import { ensureProjectWorkspace, removeProjectWorkspace, getSharedDir, validateSessionId } from '../projects/workspace.js';
|
|
24
|
-
import { removeEntriesForProject } from '../lib/showcase-store.js';
|
|
25
|
-
import { disposeProjectBus, getProjectBus } from '../ws/broker.js';
|
|
26
|
-
import { Events } from '../engine/agent/events.js';
|
|
27
|
-
|
|
28
|
-
const router = express.Router();
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 列表的归属口径:一律只列自己的。
|
|
32
|
-
*
|
|
33
|
-
* 2026-08-03 收窄:原本 admin 拿的是全库,于是「我的项目」首页把所有内测用户的
|
|
34
|
-
* 项目名铺在一起(16 张卡里只有 7 张是自己的)。admin 要看全站有 /admin;
|
|
35
|
-
* 要打开别人的项目 guardProject 仍然放行 —— 越权能力没变,变的是首页的口径:
|
|
36
|
-
* 「我的项目」就是我的。
|
|
37
|
-
*/
|
|
38
|
-
const ownerScope = (req) => req.user?.id ?? null;
|
|
39
|
-
|
|
40
|
-
const KIND_VALUES = new Set(['project', 'quick']);
|
|
41
|
-
const KIND_QUERY_VALUES = new Set(['project', 'quick', 'all']);
|
|
42
|
-
|
|
43
|
-
// GET /api/projects 默认行为(2026-05-07):不带 ?kind= 时 **只返 kind='project'**,
|
|
44
|
-
// 把闪聊(kind='quick')从主项目列表里挡掉 —— 避免老 client / 任何漏传 kind 的调用
|
|
45
|
-
// 把闪聊泄漏到「我的项目」UI。要拿全集显式传 ?kind=all。kind=quick 仍可单独筛。
|
|
46
|
-
router.get('/', (req, res, next) => {
|
|
47
|
-
try {
|
|
48
|
-
const raw = typeof req.query.kind === 'string' ? req.query.kind : undefined;
|
|
49
|
-
if (raw && !KIND_QUERY_VALUES.has(raw)) {
|
|
50
|
-
return res.status(400).json({ error: `kind must be project|quick|all (got ${raw})` });
|
|
51
|
-
}
|
|
52
|
-
const effectiveKind = raw === 'all' ? undefined : (raw || 'project');
|
|
53
|
-
res.json({ projects: listProjects({ kind: effectiveKind, owner: ownerScope(req) }) });
|
|
54
|
-
} catch (err) { next(err); }
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* GET /api/projects/stats —— 首页卡片那行元信息(这个项目里躺着什么)
|
|
59
|
-
*
|
|
60
|
-
* 卡片上原来印的是 skill_id,全站同一个值 'deskskill-engine-mini',等于一行噪声。
|
|
61
|
-
* 真正配占那一行的是「这里出了几件东西、都是什么形态」,而这个事实不在库里,
|
|
62
|
-
* 在 workspace 的 tasks/ 目录里。所以单开一条而不是并进列表接口:列项目不能
|
|
63
|
-
* 因为要读一圈磁盘而变慢,前端拿到列表先把卡画出来,这条回来了再补那行字。
|
|
64
|
-
*
|
|
65
|
-
* kind=null 的任务是开了头还没写出产物的,计入 tasks 但不计入 kinds。
|
|
66
|
-
*
|
|
67
|
-
* summary 是首页写在板子上那几笔账(已上线几件、今天花了多少)。搭这趟车而不是
|
|
68
|
-
* 单开端点:首页为了这四行字已经要发一次请求了,没必要发第三次。两个数都是
|
|
69
|
-
* 单条 SQL,不额外读盘。
|
|
70
|
-
*
|
|
71
|
-
* 注意:必须注册在 '/:pid' 之前,否则 'stats' 会被当成项目 id。
|
|
72
|
-
*/
|
|
73
|
-
router.get('/stats', async (req, res, next) => {
|
|
74
|
-
try {
|
|
75
|
-
const projects = listProjects({ kind: 'project', owner: ownerScope(req) });
|
|
76
|
-
const stats = {};
|
|
77
|
-
await Promise.all(projects.map(async (p) => {
|
|
78
|
-
// 首页卡上的"有几件东西"。扁平化前数的是任务数(每项目恒为 1,
|
|
79
|
-
// 所以那张卡上永远写着 1),现在数**产物**——一个项目里并排的 deck /
|
|
80
|
-
// 目录型产物各算一件,这才是用户眼里的"这个项目里有什么"。
|
|
81
|
-
let artifacts = [];
|
|
82
|
-
try {
|
|
83
|
-
artifacts = (await taskManifest(getSharedDir(p.id)))?.artifacts || [];
|
|
84
|
-
} catch { /* 目录没了:算 0 件 */ }
|
|
85
|
-
const kinds = {};
|
|
86
|
-
for (const a of artifacts) if (a.kind) kinds[a.kind] = (kinds[a.kind] || 0) + 1;
|
|
87
|
-
stats[p.id] = { tasks: artifacts.length, kinds };
|
|
88
|
-
}));
|
|
89
|
-
// dev 模式(不要求登录)没有 req.user,这两笔账就没有主语,整块不下发
|
|
90
|
-
const summary = req.user
|
|
91
|
-
? {
|
|
92
|
-
published: countPublishedByUser(req.user.id),
|
|
93
|
-
usedToday: checkQuota(req.user).usedToday,
|
|
94
|
-
}
|
|
95
|
-
: null;
|
|
96
|
-
res.json({ stats, summary });
|
|
97
|
-
} catch (err) { next(err); }
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const DESCRIPTION_MAX = 2000;
|
|
101
|
-
|
|
102
|
-
router.post('/', async (req, res, next) => {
|
|
103
|
-
try {
|
|
104
|
-
const { name, skillId, description, kind, autoNamed } = req.body || {};
|
|
105
|
-
if (!name || typeof name !== 'string' || !name.trim()) {
|
|
106
|
-
return res.status(400).json({ error: 'name required' });
|
|
107
|
-
}
|
|
108
|
-
if (description != null && typeof description !== 'string') {
|
|
109
|
-
return res.status(400).json({ error: 'description must be string' });
|
|
110
|
-
}
|
|
111
|
-
if (typeof description === 'string' && description.length > DESCRIPTION_MAX) {
|
|
112
|
-
return res.status(400).json({ error: `description too long (max ${DESCRIPTION_MAX})` });
|
|
113
|
-
}
|
|
114
|
-
if (kind != null && !KIND_VALUES.has(kind)) {
|
|
115
|
-
return res.status(400).json({ error: `kind must be project|quick (got ${kind})` });
|
|
116
|
-
}
|
|
117
|
-
const project = createProject({
|
|
118
|
-
name, skillId, description, kind, autoNamed: !!autoNamed,
|
|
119
|
-
ownerId: req.user?.id ?? null,
|
|
120
|
-
});
|
|
121
|
-
await ensureProjectWorkspace(project.id);
|
|
122
|
-
res.status(201).json({ project });
|
|
123
|
-
} catch (err) { next(err); }
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
router.get('/:pid', (req, res, next) => {
|
|
127
|
-
try {
|
|
128
|
-
const project = guardProject(req, res);
|
|
129
|
-
if (!project) return;
|
|
130
|
-
res.json({ project });
|
|
131
|
-
} catch (err) { next(err); }
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
router.patch('/:pid', (req, res, next) => {
|
|
135
|
-
try {
|
|
136
|
-
const project = guardProject(req, res);
|
|
137
|
-
if (!project) return;
|
|
138
|
-
const patch = {};
|
|
139
|
-
if (typeof req.body?.name === 'string') patch.name = req.body.name.trim();
|
|
140
|
-
if (typeof req.body?.skillId === 'string') patch.skillId = req.body.skillId;
|
|
141
|
-
if ('description' in (req.body || {})) {
|
|
142
|
-
const d = req.body.description;
|
|
143
|
-
if (d != null && typeof d !== 'string') {
|
|
144
|
-
return res.status(400).json({ error: 'description must be string' });
|
|
145
|
-
}
|
|
146
|
-
if (typeof d === 'string' && d.length > DESCRIPTION_MAX) {
|
|
147
|
-
return res.status(400).json({ error: `description too long (max ${DESCRIPTION_MAX})` });
|
|
148
|
-
}
|
|
149
|
-
patch.description = (typeof d === 'string' && d.trim()) ? d.trim() : null;
|
|
150
|
-
}
|
|
151
|
-
if ('kind' in (req.body || {})) {
|
|
152
|
-
if (!KIND_VALUES.has(req.body.kind)) {
|
|
153
|
-
return res.status(400).json({ error: `kind must be project|quick (got ${req.body.kind})` });
|
|
154
|
-
}
|
|
155
|
-
patch.kind = req.body.kind;
|
|
156
|
-
}
|
|
157
|
-
// E1a(2026-08-13):会话真相源收敛到 projects.active_session_id 之后,
|
|
158
|
-
// 前端切会话得能直接写这个指针(此前唯一的写入方是 turn.js —— 不发消息、
|
|
159
|
-
// 只是切着看,指针就不动,别的标签页也就永远对不齐)。接受 null(清空)
|
|
160
|
-
// 或合法 sid 形状;不校验会话是否真实存在 —— 跟 turn.js 对 body.sessionId
|
|
161
|
-
// 的信任口径一致(指错了顶多下次 turn 起新会话)。
|
|
162
|
-
if ('active_session_id' in (req.body || {}) || 'activeSessionId' in (req.body || {})) {
|
|
163
|
-
const v = req.body.active_session_id ?? req.body.activeSessionId ?? null;
|
|
164
|
-
if (v !== null) {
|
|
165
|
-
try { validateSessionId(v); } catch (err) {
|
|
166
|
-
return res.status(400).json({ error: err.message || 'invalid active_session_id' });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
patch.activeSessionId = v;
|
|
170
|
-
}
|
|
171
|
-
const updated = updateProject(req.params.pid, patch);
|
|
172
|
-
// 指针**实际变化**才广播(project 是 guardProject 读的更新前快照)。
|
|
173
|
-
// 为什么这条事件不带 sessionId 字段:见 events.js projectActiveSession 注释。
|
|
174
|
-
if ('activeSessionId' in patch && patch.activeSessionId !== project.activeSessionId) {
|
|
175
|
-
try {
|
|
176
|
-
getProjectBus(req.params.pid).publish({
|
|
177
|
-
...Events.projectActiveSession(patch.activeSessionId),
|
|
178
|
-
ts: new Date().toISOString(),
|
|
179
|
-
});
|
|
180
|
-
} catch (err) {
|
|
181
|
-
console.warn(`[projects] active_session broadcast failed: ${err.message}`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
res.json({ project: updated });
|
|
185
|
-
} catch (err) { next(err); }
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
router.delete('/:pid', async (req, res, next) => {
|
|
189
|
-
try {
|
|
190
|
-
const project = guardProject(req, res);
|
|
191
|
-
if (!project) return;
|
|
192
|
-
|
|
193
|
-
// 常驻浏览器要先关:它的 profile 就在这个工作区里(`.browser/`),不关的话
|
|
194
|
-
// chromium 攥着一个已被 rm 的 user-data-dir,而只有 2 个的常驻名额被一个
|
|
195
|
-
// 已删项目占着,直到 5 分钟空闲计时器到点。(动态 import:别把 playwright
|
|
196
|
-
// 那一层拖进这个路由文件的启动图。)
|
|
197
|
-
try {
|
|
198
|
-
const { closeFor } = await import('../engine/browse/registry.js');
|
|
199
|
-
await closeFor(req.params.pid, 'project deleted');
|
|
200
|
-
} catch { /* 没起过浏览器不该挡住删项目 */ }
|
|
201
|
-
// 级联:先清 workspace 文件,再删 DB row(DB row 删了找不到,先文件后 DB 顺序保险)
|
|
202
|
-
try { await removeProjectWorkspace(req.params.pid); } catch (err) {
|
|
203
|
-
console.warn(`[projects] removeWorkspace failed for ${req.params.pid}:`, err.message);
|
|
204
|
-
}
|
|
205
|
-
// 关联 runs:标记为 cancelled? 或直接 delete? MVP 直接 delete 关联 runs 行
|
|
206
|
-
const runs = listRunsForProject(req.params.pid);
|
|
207
|
-
if (runs.length) {
|
|
208
|
-
const { default: db } = await import('../engine/runs/store.js');
|
|
209
|
-
const stmt = db.prepare('DELETE FROM runs WHERE id = ?');
|
|
210
|
-
for (const r of runs) stmt.run(r.id);
|
|
211
|
-
}
|
|
212
|
-
// 橱窗卡片指着这个项目的产物,作品没了卡片留着只会点出 404
|
|
213
|
-
removeEntriesForProject(req.params.pid);
|
|
214
|
-
deleteProject(req.params.pid);
|
|
215
|
-
disposeProjectBus(req.params.pid);
|
|
216
|
-
res.status(204).end();
|
|
217
|
-
} catch (err) { next(err); }
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
export default router;
|
|
1
|
+
/**
|
|
2
|
+
* server/api/projects.js — Project CRUD
|
|
3
|
+
*
|
|
4
|
+
* GET /api/projects 列项目(按 updated_at 倒序)
|
|
5
|
+
* POST /api/projects { name, skillId?, description? } → 创建 + ensureProjectWorkspace
|
|
6
|
+
* GET /api/projects/:pid 单项目
|
|
7
|
+
* PATCH /api/projects/:pid { name?, skillId?, description? } 部分更新
|
|
8
|
+
* DELETE /api/projects/:pid 删项目 + workspace + 关联 runs
|
|
9
|
+
*
|
|
10
|
+
* description: 可选,<= 2000 字符。仅 NoDesign 后端/前端 UI 用,agent 不感知
|
|
11
|
+
* (agent 看的是项目级 instruction = workspace/.claude/CLAUDE.md)。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import express from 'express';
|
|
15
|
+
import {
|
|
16
|
+
listProjects, createProject, updateProject, deleteProject,
|
|
17
|
+
listRunsForProject,
|
|
18
|
+
} from '../projects/store.js';
|
|
19
|
+
import { guardProject } from './_guard.js';
|
|
20
|
+
import { taskManifest } from '../lib/artifact-target.js';
|
|
21
|
+
import { countPublishedByUser } from '../lib/publish-store.js';
|
|
22
|
+
import { checkQuota } from '../lib/quota.js';
|
|
23
|
+
import { ensureProjectWorkspace, removeProjectWorkspace, getSharedDir, validateSessionId } from '../projects/workspace.js';
|
|
24
|
+
import { removeEntriesForProject } from '../lib/showcase-store.js';
|
|
25
|
+
import { disposeProjectBus, getProjectBus } from '../ws/broker.js';
|
|
26
|
+
import { Events } from '../engine/agent/events.js';
|
|
27
|
+
|
|
28
|
+
const router = express.Router();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 列表的归属口径:一律只列自己的。
|
|
32
|
+
*
|
|
33
|
+
* 2026-08-03 收窄:原本 admin 拿的是全库,于是「我的项目」首页把所有内测用户的
|
|
34
|
+
* 项目名铺在一起(16 张卡里只有 7 张是自己的)。admin 要看全站有 /admin;
|
|
35
|
+
* 要打开别人的项目 guardProject 仍然放行 —— 越权能力没变,变的是首页的口径:
|
|
36
|
+
* 「我的项目」就是我的。
|
|
37
|
+
*/
|
|
38
|
+
const ownerScope = (req) => req.user?.id ?? null;
|
|
39
|
+
|
|
40
|
+
const KIND_VALUES = new Set(['project', 'quick']);
|
|
41
|
+
const KIND_QUERY_VALUES = new Set(['project', 'quick', 'all']);
|
|
42
|
+
|
|
43
|
+
// GET /api/projects 默认行为(2026-05-07):不带 ?kind= 时 **只返 kind='project'**,
|
|
44
|
+
// 把闪聊(kind='quick')从主项目列表里挡掉 —— 避免老 client / 任何漏传 kind 的调用
|
|
45
|
+
// 把闪聊泄漏到「我的项目」UI。要拿全集显式传 ?kind=all。kind=quick 仍可单独筛。
|
|
46
|
+
router.get('/', (req, res, next) => {
|
|
47
|
+
try {
|
|
48
|
+
const raw = typeof req.query.kind === 'string' ? req.query.kind : undefined;
|
|
49
|
+
if (raw && !KIND_QUERY_VALUES.has(raw)) {
|
|
50
|
+
return res.status(400).json({ error: `kind must be project|quick|all (got ${raw})` });
|
|
51
|
+
}
|
|
52
|
+
const effectiveKind = raw === 'all' ? undefined : (raw || 'project');
|
|
53
|
+
res.json({ projects: listProjects({ kind: effectiveKind, owner: ownerScope(req) }) });
|
|
54
|
+
} catch (err) { next(err); }
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* GET /api/projects/stats —— 首页卡片那行元信息(这个项目里躺着什么)
|
|
59
|
+
*
|
|
60
|
+
* 卡片上原来印的是 skill_id,全站同一个值 'deskskill-engine-mini',等于一行噪声。
|
|
61
|
+
* 真正配占那一行的是「这里出了几件东西、都是什么形态」,而这个事实不在库里,
|
|
62
|
+
* 在 workspace 的 tasks/ 目录里。所以单开一条而不是并进列表接口:列项目不能
|
|
63
|
+
* 因为要读一圈磁盘而变慢,前端拿到列表先把卡画出来,这条回来了再补那行字。
|
|
64
|
+
*
|
|
65
|
+
* kind=null 的任务是开了头还没写出产物的,计入 tasks 但不计入 kinds。
|
|
66
|
+
*
|
|
67
|
+
* summary 是首页写在板子上那几笔账(已上线几件、今天花了多少)。搭这趟车而不是
|
|
68
|
+
* 单开端点:首页为了这四行字已经要发一次请求了,没必要发第三次。两个数都是
|
|
69
|
+
* 单条 SQL,不额外读盘。
|
|
70
|
+
*
|
|
71
|
+
* 注意:必须注册在 '/:pid' 之前,否则 'stats' 会被当成项目 id。
|
|
72
|
+
*/
|
|
73
|
+
router.get('/stats', async (req, res, next) => {
|
|
74
|
+
try {
|
|
75
|
+
const projects = listProjects({ kind: 'project', owner: ownerScope(req) });
|
|
76
|
+
const stats = {};
|
|
77
|
+
await Promise.all(projects.map(async (p) => {
|
|
78
|
+
// 首页卡上的"有几件东西"。扁平化前数的是任务数(每项目恒为 1,
|
|
79
|
+
// 所以那张卡上永远写着 1),现在数**产物**——一个项目里并排的 deck /
|
|
80
|
+
// 目录型产物各算一件,这才是用户眼里的"这个项目里有什么"。
|
|
81
|
+
let artifacts = [];
|
|
82
|
+
try {
|
|
83
|
+
artifacts = (await taskManifest(getSharedDir(p.id)))?.artifacts || [];
|
|
84
|
+
} catch { /* 目录没了:算 0 件 */ }
|
|
85
|
+
const kinds = {};
|
|
86
|
+
for (const a of artifacts) if (a.kind) kinds[a.kind] = (kinds[a.kind] || 0) + 1;
|
|
87
|
+
stats[p.id] = { tasks: artifacts.length, kinds };
|
|
88
|
+
}));
|
|
89
|
+
// dev 模式(不要求登录)没有 req.user,这两笔账就没有主语,整块不下发
|
|
90
|
+
const summary = req.user
|
|
91
|
+
? {
|
|
92
|
+
published: countPublishedByUser(req.user.id),
|
|
93
|
+
usedToday: checkQuota(req.user).usedToday,
|
|
94
|
+
}
|
|
95
|
+
: null;
|
|
96
|
+
res.json({ stats, summary });
|
|
97
|
+
} catch (err) { next(err); }
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const DESCRIPTION_MAX = 2000;
|
|
101
|
+
|
|
102
|
+
router.post('/', async (req, res, next) => {
|
|
103
|
+
try {
|
|
104
|
+
const { name, skillId, description, kind, autoNamed } = req.body || {};
|
|
105
|
+
if (!name || typeof name !== 'string' || !name.trim()) {
|
|
106
|
+
return res.status(400).json({ error: 'name required' });
|
|
107
|
+
}
|
|
108
|
+
if (description != null && typeof description !== 'string') {
|
|
109
|
+
return res.status(400).json({ error: 'description must be string' });
|
|
110
|
+
}
|
|
111
|
+
if (typeof description === 'string' && description.length > DESCRIPTION_MAX) {
|
|
112
|
+
return res.status(400).json({ error: `description too long (max ${DESCRIPTION_MAX})` });
|
|
113
|
+
}
|
|
114
|
+
if (kind != null && !KIND_VALUES.has(kind)) {
|
|
115
|
+
return res.status(400).json({ error: `kind must be project|quick (got ${kind})` });
|
|
116
|
+
}
|
|
117
|
+
const project = createProject({
|
|
118
|
+
name, skillId, description, kind, autoNamed: !!autoNamed,
|
|
119
|
+
ownerId: req.user?.id ?? null,
|
|
120
|
+
});
|
|
121
|
+
await ensureProjectWorkspace(project.id);
|
|
122
|
+
res.status(201).json({ project });
|
|
123
|
+
} catch (err) { next(err); }
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
router.get('/:pid', (req, res, next) => {
|
|
127
|
+
try {
|
|
128
|
+
const project = guardProject(req, res);
|
|
129
|
+
if (!project) return;
|
|
130
|
+
res.json({ project });
|
|
131
|
+
} catch (err) { next(err); }
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
router.patch('/:pid', (req, res, next) => {
|
|
135
|
+
try {
|
|
136
|
+
const project = guardProject(req, res);
|
|
137
|
+
if (!project) return;
|
|
138
|
+
const patch = {};
|
|
139
|
+
if (typeof req.body?.name === 'string') patch.name = req.body.name.trim();
|
|
140
|
+
if (typeof req.body?.skillId === 'string') patch.skillId = req.body.skillId;
|
|
141
|
+
if ('description' in (req.body || {})) {
|
|
142
|
+
const d = req.body.description;
|
|
143
|
+
if (d != null && typeof d !== 'string') {
|
|
144
|
+
return res.status(400).json({ error: 'description must be string' });
|
|
145
|
+
}
|
|
146
|
+
if (typeof d === 'string' && d.length > DESCRIPTION_MAX) {
|
|
147
|
+
return res.status(400).json({ error: `description too long (max ${DESCRIPTION_MAX})` });
|
|
148
|
+
}
|
|
149
|
+
patch.description = (typeof d === 'string' && d.trim()) ? d.trim() : null;
|
|
150
|
+
}
|
|
151
|
+
if ('kind' in (req.body || {})) {
|
|
152
|
+
if (!KIND_VALUES.has(req.body.kind)) {
|
|
153
|
+
return res.status(400).json({ error: `kind must be project|quick (got ${req.body.kind})` });
|
|
154
|
+
}
|
|
155
|
+
patch.kind = req.body.kind;
|
|
156
|
+
}
|
|
157
|
+
// E1a(2026-08-13):会话真相源收敛到 projects.active_session_id 之后,
|
|
158
|
+
// 前端切会话得能直接写这个指针(此前唯一的写入方是 turn.js —— 不发消息、
|
|
159
|
+
// 只是切着看,指针就不动,别的标签页也就永远对不齐)。接受 null(清空)
|
|
160
|
+
// 或合法 sid 形状;不校验会话是否真实存在 —— 跟 turn.js 对 body.sessionId
|
|
161
|
+
// 的信任口径一致(指错了顶多下次 turn 起新会话)。
|
|
162
|
+
if ('active_session_id' in (req.body || {}) || 'activeSessionId' in (req.body || {})) {
|
|
163
|
+
const v = req.body.active_session_id ?? req.body.activeSessionId ?? null;
|
|
164
|
+
if (v !== null) {
|
|
165
|
+
try { validateSessionId(v); } catch (err) {
|
|
166
|
+
return res.status(400).json({ error: err.message || 'invalid active_session_id' });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
patch.activeSessionId = v;
|
|
170
|
+
}
|
|
171
|
+
const updated = updateProject(req.params.pid, patch);
|
|
172
|
+
// 指针**实际变化**才广播(project 是 guardProject 读的更新前快照)。
|
|
173
|
+
// 为什么这条事件不带 sessionId 字段:见 events.js projectActiveSession 注释。
|
|
174
|
+
if ('activeSessionId' in patch && patch.activeSessionId !== project.activeSessionId) {
|
|
175
|
+
try {
|
|
176
|
+
getProjectBus(req.params.pid).publish({
|
|
177
|
+
...Events.projectActiveSession(patch.activeSessionId),
|
|
178
|
+
ts: new Date().toISOString(),
|
|
179
|
+
});
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.warn(`[projects] active_session broadcast failed: ${err.message}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
res.json({ project: updated });
|
|
185
|
+
} catch (err) { next(err); }
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
router.delete('/:pid', async (req, res, next) => {
|
|
189
|
+
try {
|
|
190
|
+
const project = guardProject(req, res);
|
|
191
|
+
if (!project) return;
|
|
192
|
+
|
|
193
|
+
// 常驻浏览器要先关:它的 profile 就在这个工作区里(`.browser/`),不关的话
|
|
194
|
+
// chromium 攥着一个已被 rm 的 user-data-dir,而只有 2 个的常驻名额被一个
|
|
195
|
+
// 已删项目占着,直到 5 分钟空闲计时器到点。(动态 import:别把 playwright
|
|
196
|
+
// 那一层拖进这个路由文件的启动图。)
|
|
197
|
+
try {
|
|
198
|
+
const { closeFor } = await import('../engine/browse/registry.js');
|
|
199
|
+
await closeFor(req.params.pid, 'project deleted');
|
|
200
|
+
} catch { /* 没起过浏览器不该挡住删项目 */ }
|
|
201
|
+
// 级联:先清 workspace 文件,再删 DB row(DB row 删了找不到,先文件后 DB 顺序保险)
|
|
202
|
+
try { await removeProjectWorkspace(req.params.pid); } catch (err) {
|
|
203
|
+
console.warn(`[projects] removeWorkspace failed for ${req.params.pid}:`, err.message);
|
|
204
|
+
}
|
|
205
|
+
// 关联 runs:标记为 cancelled? 或直接 delete? MVP 直接 delete 关联 runs 行
|
|
206
|
+
const runs = listRunsForProject(req.params.pid);
|
|
207
|
+
if (runs.length) {
|
|
208
|
+
const { default: db } = await import('../engine/runs/store.js');
|
|
209
|
+
const stmt = db.prepare('DELETE FROM runs WHERE id = ?');
|
|
210
|
+
for (const r of runs) stmt.run(r.id);
|
|
211
|
+
}
|
|
212
|
+
// 橱窗卡片指着这个项目的产物,作品没了卡片留着只会点出 404
|
|
213
|
+
removeEntriesForProject(req.params.pid);
|
|
214
|
+
deleteProject(req.params.pid);
|
|
215
|
+
disposeProjectBus(req.params.pid);
|
|
216
|
+
res.status(204).end();
|
|
217
|
+
} catch (err) { next(err); }
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
export default router;
|
package/server/api/publish.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* server/api/publish.js — 站点一键上线的 HTTP 面(2026-08-02)
|
|
3
|
-
*
|
|
4
|
-
* GET /:pid/publish/:task → { published, site? }
|
|
5
|
-
* POST /:pid/publish/:task → 发布/重发布(同步等 deploy 完,前端转圈)
|
|
6
|
-
* DELETE /:pid/publish/:task → 下线
|
|
7
|
-
*
|
|
8
|
-
* 核心逻辑(闸门/staging/wrangler/custom domain)在 lib/site-publish.js ——
|
|
9
|
-
* agent 的 MCP 工具 publish_site 和这里共用同一套。权限:HTTP 面按请求者算
|
|
10
|
-
* (guardProject 已保证是 owner 或 admin)。
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import express from 'express';
|
|
14
|
-
import { guardProject } from './_guard.js';
|
|
15
|
-
import { publishSite, unpublishSite, validTaskName, lookupPublished } from '../lib/site-publish.js';
|
|
16
|
-
|
|
17
|
-
const router = express.Router();
|
|
18
|
-
|
|
19
|
-
// 根站(扁平化后站点住工作区根)的 store key 是 '.',但 '.' 进不了 URL 路径段:
|
|
20
|
-
// WHATWG URL 规范把单点段(含 %2E)就地归一掉,浏览器发出去就成了 /publish/。
|
|
21
|
-
// 所以路由双注册:无 :task 段 = 根站。
|
|
22
|
-
const taskOf = (req) => (req.params.task ?? '.');
|
|
23
|
-
|
|
24
|
-
router.get(['/:pid/publish', '/:pid/publish/:task'], async (req, res) => {
|
|
25
|
-
if (!guardProject(req, res)) return;
|
|
26
|
-
const task = taskOf(req);
|
|
27
|
-
if (!validTaskName(task)) return res.status(400).json({ error: 'invalid task' });
|
|
28
|
-
// lookupPublished 而不是 getPublished:key 已经收敛到站点根,但界面/老链接
|
|
29
|
-
// 传别名过来时也该认得出,否则会显示"未上线"→ 用户再点一次 → 造出第二个部署
|
|
30
|
-
const site = await lookupPublished(req.params.pid, task);
|
|
31
|
-
res.json({ published: !!site, site });
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
router.post(['/:pid/publish', '/:pid/publish/:task'], async (req, res) => {
|
|
35
|
-
if (!guardProject(req, res)) return;
|
|
36
|
-
try {
|
|
37
|
-
const { site, warning, certReady, root, files, entry } = await publishSite({
|
|
38
|
-
projectId: req.params.pid, task: taskOf(req),
|
|
39
|
-
root: typeof req.body?.root === 'string' ? req.body.root : undefined,
|
|
40
|
-
slug: typeof req.body?.slug === 'string' ? req.body.slug : undefined,
|
|
41
|
-
user: req.user,
|
|
42
|
-
});
|
|
43
|
-
res.json({ site, warning, certReady, root, files, entry });
|
|
44
|
-
} catch (err) {
|
|
45
|
-
if (err.status) return res.status(err.status).json({ error: err.message });
|
|
46
|
-
console.error('[publish] deploy failed:', err.stderr || err.message);
|
|
47
|
-
res.status(502).json({ error: '发布失败:Cloudflare 部署没成功,稍后再试' });
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
router.delete(['/:pid/publish', '/:pid/publish/:task'], async (req, res) => {
|
|
52
|
-
if (!guardProject(req, res)) return;
|
|
53
|
-
try {
|
|
54
|
-
const removed = await unpublishSite({ projectId: req.params.pid, task: taskOf(req) });
|
|
55
|
-
if (!removed) return res.status(404).json({ error: 'not published' });
|
|
56
|
-
res.json({ removed: true });
|
|
57
|
-
} catch (err) {
|
|
58
|
-
if (err.status) return res.status(err.status).json({ error: err.message });
|
|
59
|
-
console.error('[publish] delete failed:', err.stderr || err.message);
|
|
60
|
-
res.status(502).json({ error: '下线失败,稍后再试' });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export default router;
|
|
1
|
+
/**
|
|
2
|
+
* server/api/publish.js — 站点一键上线的 HTTP 面(2026-08-02)
|
|
3
|
+
*
|
|
4
|
+
* GET /:pid/publish/:task → { published, site? }
|
|
5
|
+
* POST /:pid/publish/:task → 发布/重发布(同步等 deploy 完,前端转圈)
|
|
6
|
+
* DELETE /:pid/publish/:task → 下线
|
|
7
|
+
*
|
|
8
|
+
* 核心逻辑(闸门/staging/wrangler/custom domain)在 lib/site-publish.js ——
|
|
9
|
+
* agent 的 MCP 工具 publish_site 和这里共用同一套。权限:HTTP 面按请求者算
|
|
10
|
+
* (guardProject 已保证是 owner 或 admin)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import express from 'express';
|
|
14
|
+
import { guardProject } from './_guard.js';
|
|
15
|
+
import { publishSite, unpublishSite, validTaskName, lookupPublished } from '../lib/site-publish.js';
|
|
16
|
+
|
|
17
|
+
const router = express.Router();
|
|
18
|
+
|
|
19
|
+
// 根站(扁平化后站点住工作区根)的 store key 是 '.',但 '.' 进不了 URL 路径段:
|
|
20
|
+
// WHATWG URL 规范把单点段(含 %2E)就地归一掉,浏览器发出去就成了 /publish/。
|
|
21
|
+
// 所以路由双注册:无 :task 段 = 根站。
|
|
22
|
+
const taskOf = (req) => (req.params.task ?? '.');
|
|
23
|
+
|
|
24
|
+
router.get(['/:pid/publish', '/:pid/publish/:task'], async (req, res) => {
|
|
25
|
+
if (!guardProject(req, res)) return;
|
|
26
|
+
const task = taskOf(req);
|
|
27
|
+
if (!validTaskName(task)) return res.status(400).json({ error: 'invalid task' });
|
|
28
|
+
// lookupPublished 而不是 getPublished:key 已经收敛到站点根,但界面/老链接
|
|
29
|
+
// 传别名过来时也该认得出,否则会显示"未上线"→ 用户再点一次 → 造出第二个部署
|
|
30
|
+
const site = await lookupPublished(req.params.pid, task);
|
|
31
|
+
res.json({ published: !!site, site });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
router.post(['/:pid/publish', '/:pid/publish/:task'], async (req, res) => {
|
|
35
|
+
if (!guardProject(req, res)) return;
|
|
36
|
+
try {
|
|
37
|
+
const { site, warning, certReady, root, files, entry } = await publishSite({
|
|
38
|
+
projectId: req.params.pid, task: taskOf(req),
|
|
39
|
+
root: typeof req.body?.root === 'string' ? req.body.root : undefined,
|
|
40
|
+
slug: typeof req.body?.slug === 'string' ? req.body.slug : undefined,
|
|
41
|
+
user: req.user,
|
|
42
|
+
});
|
|
43
|
+
res.json({ site, warning, certReady, root, files, entry });
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (err.status) return res.status(err.status).json({ error: err.message });
|
|
46
|
+
console.error('[publish] deploy failed:', err.stderr || err.message);
|
|
47
|
+
res.status(502).json({ error: '发布失败:Cloudflare 部署没成功,稍后再试' });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
router.delete(['/:pid/publish', '/:pid/publish/:task'], async (req, res) => {
|
|
52
|
+
if (!guardProject(req, res)) return;
|
|
53
|
+
try {
|
|
54
|
+
const removed = await unpublishSite({ projectId: req.params.pid, task: taskOf(req) });
|
|
55
|
+
if (!removed) return res.status(404).json({ error: 'not published' });
|
|
56
|
+
res.json({ removed: true });
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (err.status) return res.status(err.status).json({ error: err.message });
|
|
59
|
+
console.error('[publish] delete failed:', err.stderr || err.message);
|
|
60
|
+
res.status(502).json({ error: '下线失败,稍后再试' });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export default router;
|