@xiaobuyu/nodesign 0.0.1 → 0.0.2
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 +22 -22
- package/server/api/assets/notes.js +144 -144
- package/server/api/assets.js +896 -896
- package/server/api/board.js +57 -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 +464 -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 +215 -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 +336 -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 +1024 -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 +339 -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 +155 -155
- package/server/engine/mcp/tools/crystallize-skill.js +168 -168
- 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/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 +103 -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/record-decision.js +140 -140
- package/server/engine/mcp/tools/relate-on-board.js +110 -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/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/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 +192 -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 +162 -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 +228 -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 +323 -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/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/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 +60 -60
- package/server/lib/board-kind-sizes.js +62 -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/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/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-store.js +640 -640
- package/server/projects/move-entry.js +103 -103
- package/server/projects/store.js +270 -270
- package/server/projects/ui-config.js +54 -54
- 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 +36 -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-BYCgizHw.js +11 -0
- package/web/dist/assets/{DeckWindow-4G0xX7P3.js → DeckWindow-pNydEM4L.js} +1 -1
- package/web/dist/assets/{DocxWindow-BXQsoPkh.js → DocxWindow-PPgzh3Gq.js} +1 -1
- package/web/dist/assets/{SiteWindow-D6eS-2gM.js → SiteWindow-DM0LQPCO.js} +1 -1
- package/web/dist/assets/{index-Cbl3ATvp.js → index-BHTBJlpY.js} +32 -32
- package/web/dist/assets/{pending-edit-apply-DTjo2geW.js → pending-edit-apply-C0I13CbD.js} +1 -1
- package/web/dist/assets/{rotate-cw-LMT3x1Zj.js → rotate-cw-B1UQ8Hld.js} +1 -1
- package/web/dist/assets/{square-dashed-mouse-pointer-CBoAkfhi.js → square-dashed-mouse-pointer-8lrgqmfv.js} +1 -1
- package/web/dist/index.html +17 -17
- package/web/dist/assets/BrowserWindow-Dc7J7CYc.js +0 -11
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/export-handoff.js — export_handoff MCP tool
|
|
3
|
-
*
|
|
4
|
-
* agent 觉得设计到了交付时机时主动调,把 canvas.html / spec.json /
|
|
5
|
-
* assets / chat-history / README 打包成 handoff.zip。
|
|
6
|
-
*
|
|
7
|
-
* 复用 server/api/exports.js 的 buildHandoffZip pipeline,agent 端和
|
|
8
|
-
* 用户按钮路径输出一致。
|
|
9
|
-
*
|
|
10
|
-
* 输出位置:写到 workspace/exports/handoff-<ts>.zip。agent 不能直接给
|
|
11
|
-
* 用户文件,所以告诉用户路径,用户从前端 UI 看到 / 下载。
|
|
12
|
-
*
|
|
13
|
-
* 调用约定(agent 端):
|
|
14
|
-
* mcp__nodesign__export_handoff
|
|
15
|
-
* notes?: string 可选记录"为什么这个时机交付"
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import path from 'node:path';
|
|
19
|
-
import fs from 'node:fs/promises';
|
|
20
|
-
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
21
|
-
import { z } from 'zod';
|
|
22
|
-
import { buildHandoffZip } from '../../../api/exports.js';
|
|
23
|
-
import { getProject, listRunsForProject } from '../../../projects/store.js';
|
|
24
|
-
import { resolveCanvasTarget, CANVAS_PATH_DESC } from '../../../lib/artifact-target.js';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @param {object} deps
|
|
28
|
-
* @param {string} deps.workspaceRoot
|
|
29
|
-
* @param {string} [deps.projectId]
|
|
30
|
-
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
31
|
-
*/
|
|
32
|
-
export function makeExportHandoffTool({ workspaceRoot, sharedRoot, projectId, sessionId, ctx }) {
|
|
33
|
-
return tool(
|
|
34
|
-
'export_handoff',
|
|
35
|
-
`Build a handoff zip: the artifact's source, the assets it actually
|
|
36
|
-
references, and a README that says what it is, how to run it, and — for a
|
|
37
|
-
mock-data app — which backend endpoints the recipient needs to implement.
|
|
38
|
-
|
|
39
|
-
Use this when the work is done and the user wants to take it away. The point of
|
|
40
|
-
this package is that **someone else can pick the project up and keep building**;
|
|
41
|
-
it is not the "give me a pretty file to look at" path (that's the export menu's
|
|
42
|
-
PDF / single-page HTML).
|
|
43
|
-
|
|
44
|
-
The zip is written to workspace/exports/handoff-<timestamp>.zip. After building,
|
|
45
|
-
tell the user the path so they can download it via the UI.
|
|
46
|
-
|
|
47
|
-
Use this tool when:
|
|
48
|
-
- The artifact meets the brief and you've verified it (e.g., via screenshot_canvas)
|
|
49
|
-
- The user says "give me the files" / "package it up" / "I want to host this myself"
|
|
50
|
-
|
|
51
|
-
Do NOT use this tool when:
|
|
52
|
-
- The work is still in iteration
|
|
53
|
-
- The artifact doesn't exist yet (nothing has been written)`,
|
|
54
|
-
{
|
|
55
|
-
notes: z
|
|
56
|
-
.string()
|
|
57
|
-
.optional()
|
|
58
|
-
.describe('Optional notes about why exporting now (gets logged but not in the zip)'),
|
|
59
|
-
path: z.string().optional().describe(CANVAS_PATH_DESC),
|
|
60
|
-
},
|
|
61
|
-
async ({ notes, path: relPath }) => {
|
|
62
|
-
try {
|
|
63
|
-
let projectMeta = null;
|
|
64
|
-
let runs = [];
|
|
65
|
-
if (projectId) {
|
|
66
|
-
try {
|
|
67
|
-
projectMeta = getProject(projectId);
|
|
68
|
-
runs = listRunsForProject(projectId);
|
|
69
|
-
} catch { /* DB not available 或 project 已删 */ }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 2026-07-28:这里以前少传了 sharedRoot(签名是 (sessionRoot, sharedRoot, opts)),
|
|
73
|
-
// opts 被当成 sharedRoot —— 导出的 zip 里 assets 全空、元数据全 unknown。
|
|
74
|
-
const target = await resolveCanvasTarget(workspaceRoot, relPath, sessionId);
|
|
75
|
-
if (!target.ok) return { content: [{ type: 'text', text: target.message }], isError: true };
|
|
76
|
-
const buf = await buildHandoffZip(workspaceRoot, sharedRoot || workspaceRoot, {
|
|
77
|
-
projectId: projectMeta?.id || projectId || 'unknown',
|
|
78
|
-
projectName: projectMeta?.name || 'design',
|
|
79
|
-
skillId: projectMeta?.skillId,
|
|
80
|
-
sessionId,
|
|
81
|
-
runs,
|
|
82
|
-
deckPath: target.relPath,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const exportDir = path.join(workspaceRoot, 'exports');
|
|
86
|
-
await fs.mkdir(exportDir, { recursive: true });
|
|
87
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
88
|
-
// 名字不能再叫 relPath:它会遮蔽入参 relPath,而上面 resolveCanvasTarget
|
|
89
|
-
// 已经读过那个入参 —— 同一个块里先读后声明 = TDZ,整个工具每次调用必炸
|
|
90
|
-
const zipRel = `exports/handoff-${stamp}.zip`;
|
|
91
|
-
const absPath = path.join(workspaceRoot, zipRel);
|
|
92
|
-
await fs.writeFile(absPath, buf);
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
ctx?.emit?.({
|
|
96
|
-
type: 'run.export_built',
|
|
97
|
-
format: 'handoff',
|
|
98
|
-
path: zipRel,
|
|
99
|
-
sizeBytes: buf.length,
|
|
100
|
-
notes: notes || null,
|
|
101
|
-
});
|
|
102
|
-
// 打完包直接进用户的下载列表,不用他再去导出菜单里翻(2026-07-28)
|
|
103
|
-
ctx?.emit?.({
|
|
104
|
-
type: 'run.download_ready',
|
|
105
|
-
url: `/api/projects/${encodeURIComponent(projectId || '')}`
|
|
106
|
-
+ `/sessions/${encodeURIComponent(sessionId || '')}`
|
|
107
|
-
+ `/exports/file/${encodeURIComponent(path.basename(zipRel))}`,
|
|
108
|
-
filename: path.basename(zipRel),
|
|
109
|
-
sizeBytes: buf.length,
|
|
110
|
-
count: 1,
|
|
111
|
-
note: notes || '工程交付包',
|
|
112
|
-
});
|
|
113
|
-
} catch { /* emit fail-safe */ }
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
content: [{
|
|
117
|
-
type: 'text',
|
|
118
|
-
text: `Handoff zip built: ${zipRel} (${(buf.length / 1024).toFixed(1)} KB), deck = ${target.relPath}. `
|
|
119
|
-
+ `Tell the user the package is ready — they can download it from the UI's export menu.`,
|
|
120
|
-
}],
|
|
121
|
-
};
|
|
122
|
-
} catch (err) {
|
|
123
|
-
return {
|
|
124
|
-
content: [{
|
|
125
|
-
type: 'text',
|
|
126
|
-
text: `Export handoff failed: ${err?.message || String(err)}`,
|
|
127
|
-
}],
|
|
128
|
-
isError: true,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
);
|
|
133
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/export-handoff.js — export_handoff MCP tool
|
|
3
|
+
*
|
|
4
|
+
* agent 觉得设计到了交付时机时主动调,把 canvas.html / spec.json /
|
|
5
|
+
* assets / chat-history / README 打包成 handoff.zip。
|
|
6
|
+
*
|
|
7
|
+
* 复用 server/api/exports.js 的 buildHandoffZip pipeline,agent 端和
|
|
8
|
+
* 用户按钮路径输出一致。
|
|
9
|
+
*
|
|
10
|
+
* 输出位置:写到 workspace/exports/handoff-<ts>.zip。agent 不能直接给
|
|
11
|
+
* 用户文件,所以告诉用户路径,用户从前端 UI 看到 / 下载。
|
|
12
|
+
*
|
|
13
|
+
* 调用约定(agent 端):
|
|
14
|
+
* mcp__nodesign__export_handoff
|
|
15
|
+
* notes?: string 可选记录"为什么这个时机交付"
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import fs from 'node:fs/promises';
|
|
20
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
import { buildHandoffZip } from '../../../api/exports.js';
|
|
23
|
+
import { getProject, listRunsForProject } from '../../../projects/store.js';
|
|
24
|
+
import { resolveCanvasTarget, CANVAS_PATH_DESC } from '../../../lib/artifact-target.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {object} deps
|
|
28
|
+
* @param {string} deps.workspaceRoot
|
|
29
|
+
* @param {string} [deps.projectId]
|
|
30
|
+
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
31
|
+
*/
|
|
32
|
+
export function makeExportHandoffTool({ workspaceRoot, sharedRoot, projectId, sessionId, ctx }) {
|
|
33
|
+
return tool(
|
|
34
|
+
'export_handoff',
|
|
35
|
+
`Build a handoff zip: the artifact's source, the assets it actually
|
|
36
|
+
references, and a README that says what it is, how to run it, and — for a
|
|
37
|
+
mock-data app — which backend endpoints the recipient needs to implement.
|
|
38
|
+
|
|
39
|
+
Use this when the work is done and the user wants to take it away. The point of
|
|
40
|
+
this package is that **someone else can pick the project up and keep building**;
|
|
41
|
+
it is not the "give me a pretty file to look at" path (that's the export menu's
|
|
42
|
+
PDF / single-page HTML).
|
|
43
|
+
|
|
44
|
+
The zip is written to workspace/exports/handoff-<timestamp>.zip. After building,
|
|
45
|
+
tell the user the path so they can download it via the UI.
|
|
46
|
+
|
|
47
|
+
Use this tool when:
|
|
48
|
+
- The artifact meets the brief and you've verified it (e.g., via screenshot_canvas)
|
|
49
|
+
- The user says "give me the files" / "package it up" / "I want to host this myself"
|
|
50
|
+
|
|
51
|
+
Do NOT use this tool when:
|
|
52
|
+
- The work is still in iteration
|
|
53
|
+
- The artifact doesn't exist yet (nothing has been written)`,
|
|
54
|
+
{
|
|
55
|
+
notes: z
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Optional notes about why exporting now (gets logged but not in the zip)'),
|
|
59
|
+
path: z.string().optional().describe(CANVAS_PATH_DESC),
|
|
60
|
+
},
|
|
61
|
+
async ({ notes, path: relPath }) => {
|
|
62
|
+
try {
|
|
63
|
+
let projectMeta = null;
|
|
64
|
+
let runs = [];
|
|
65
|
+
if (projectId) {
|
|
66
|
+
try {
|
|
67
|
+
projectMeta = getProject(projectId);
|
|
68
|
+
runs = listRunsForProject(projectId);
|
|
69
|
+
} catch { /* DB not available 或 project 已删 */ }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 2026-07-28:这里以前少传了 sharedRoot(签名是 (sessionRoot, sharedRoot, opts)),
|
|
73
|
+
// opts 被当成 sharedRoot —— 导出的 zip 里 assets 全空、元数据全 unknown。
|
|
74
|
+
const target = await resolveCanvasTarget(workspaceRoot, relPath, sessionId);
|
|
75
|
+
if (!target.ok) return { content: [{ type: 'text', text: target.message }], isError: true };
|
|
76
|
+
const buf = await buildHandoffZip(workspaceRoot, sharedRoot || workspaceRoot, {
|
|
77
|
+
projectId: projectMeta?.id || projectId || 'unknown',
|
|
78
|
+
projectName: projectMeta?.name || 'design',
|
|
79
|
+
skillId: projectMeta?.skillId,
|
|
80
|
+
sessionId,
|
|
81
|
+
runs,
|
|
82
|
+
deckPath: target.relPath,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const exportDir = path.join(workspaceRoot, 'exports');
|
|
86
|
+
await fs.mkdir(exportDir, { recursive: true });
|
|
87
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
88
|
+
// 名字不能再叫 relPath:它会遮蔽入参 relPath,而上面 resolveCanvasTarget
|
|
89
|
+
// 已经读过那个入参 —— 同一个块里先读后声明 = TDZ,整个工具每次调用必炸
|
|
90
|
+
const zipRel = `exports/handoff-${stamp}.zip`;
|
|
91
|
+
const absPath = path.join(workspaceRoot, zipRel);
|
|
92
|
+
await fs.writeFile(absPath, buf);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
ctx?.emit?.({
|
|
96
|
+
type: 'run.export_built',
|
|
97
|
+
format: 'handoff',
|
|
98
|
+
path: zipRel,
|
|
99
|
+
sizeBytes: buf.length,
|
|
100
|
+
notes: notes || null,
|
|
101
|
+
});
|
|
102
|
+
// 打完包直接进用户的下载列表,不用他再去导出菜单里翻(2026-07-28)
|
|
103
|
+
ctx?.emit?.({
|
|
104
|
+
type: 'run.download_ready',
|
|
105
|
+
url: `/api/projects/${encodeURIComponent(projectId || '')}`
|
|
106
|
+
+ `/sessions/${encodeURIComponent(sessionId || '')}`
|
|
107
|
+
+ `/exports/file/${encodeURIComponent(path.basename(zipRel))}`,
|
|
108
|
+
filename: path.basename(zipRel),
|
|
109
|
+
sizeBytes: buf.length,
|
|
110
|
+
count: 1,
|
|
111
|
+
note: notes || '工程交付包',
|
|
112
|
+
});
|
|
113
|
+
} catch { /* emit fail-safe */ }
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
content: [{
|
|
117
|
+
type: 'text',
|
|
118
|
+
text: `Handoff zip built: ${zipRel} (${(buf.length / 1024).toFixed(1)} KB), deck = ${target.relPath}. `
|
|
119
|
+
+ `Tell the user the package is ready — they can download it from the UI's export menu.`,
|
|
120
|
+
}],
|
|
121
|
+
};
|
|
122
|
+
} catch (err) {
|
|
123
|
+
return {
|
|
124
|
+
content: [{
|
|
125
|
+
type: 'text',
|
|
126
|
+
text: `Export handoff failed: ${err?.message || String(err)}`,
|
|
127
|
+
}],
|
|
128
|
+
isError: true,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp/tools/expose-tweaks.js — expose_tweaks MCP tool
|
|
3
|
-
*
|
|
4
|
-
* agent 看完 deck 内容后,把这份 deck 专属的"可调参数控制台"暴露成 schema,
|
|
5
|
-
* 写到 spec.json 的 spec.tweaks 字段。前端 TweaksPanel 读 schema 渲染
|
|
6
|
-
* sliders / color picker / segmented,拖动直接改 iframe :root CSS variable
|
|
7
|
-
* 实时预览(不落盘);用户点 Apply 触发新 chat run,让 agent 把当前数值固化
|
|
8
|
-
* 进 canvas.html 的 :root。
|
|
9
|
-
*
|
|
10
|
-
* spec.json 结构:
|
|
11
|
-
* spec.tweaks = {
|
|
12
|
-
* version: 1,
|
|
13
|
-
* controls: [{ id, type, label, target_var?, target_class_on?, ... }],
|
|
14
|
-
* updatedAt, updatedBy: 'agent',
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* 触发时机(详见 SKILL.md "Tweaks 暴露协议"):
|
|
18
|
-
* - 写完 deck 主动暴露 5-8 个核心可调参数
|
|
19
|
-
* - 用户问"哪些可以调"时
|
|
20
|
-
* - 用户在前端点了 Apply 时把 inline style 固化进 :root(这种 case agent
|
|
21
|
-
* 除了写 canvas.html 还应该 expose_tweaks 更新 default 值)
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
25
|
-
import { z } from 'zod';
|
|
26
|
-
import { mutateSpecJson } from '../../../projects/workspace.js';
|
|
27
|
-
|
|
28
|
-
const ControlSchema = z.object({
|
|
29
|
-
id: z.string().min(1).max(64).regex(/^[a-z0-9_-]+$/, 'id must be kebab/snake case'),
|
|
30
|
-
type: z.enum(['slider', 'color', 'segmented', 'toggle', 'select']),
|
|
31
|
-
label: z.string().min(1).max(80),
|
|
32
|
-
description: z.string().max(200).optional(),
|
|
33
|
-
target_var: z
|
|
34
|
-
.string()
|
|
35
|
-
.regex(/^--[a-zA-Z0-9-]+$/, 'target_var must be a CSS custom property starting with --')
|
|
36
|
-
.optional(),
|
|
37
|
-
target_class_on: z.string().optional(),
|
|
38
|
-
// A6.2:CSS selector 限定 control 影响范围。不传默认 ":root"(全局)。
|
|
39
|
-
// 例:'section[data-page="1"]' / '[data-layout="hero-split"]'(layout 名由 agent
|
|
40
|
-
// 按隐喻自由命名)。配合 SKILL.md HTML 规范的"per-page scoped override"教学
|
|
41
|
-
// (让"封面字号"slider 不牵连内页字号)。前端 TweaksPanel 应用时
|
|
42
|
-
// doc.querySelector(scope) 找元素在它身上 setProperty 而不是 :root。
|
|
43
|
-
target_scope: z
|
|
44
|
-
.string()
|
|
45
|
-
.max(120)
|
|
46
|
-
.optional()
|
|
47
|
-
.describe('CSS selector for scope (e.g. \'section[data-page="1"]\'); default ":root" applies globally. Use to limit one control to one page / one layout type.'),
|
|
48
|
-
min: z.number().optional(),
|
|
49
|
-
max: z.number().optional(),
|
|
50
|
-
step: z.number().optional(),
|
|
51
|
-
default: z.union([z.string(), z.number(), z.boolean()]),
|
|
52
|
-
unit: z.string().max(8).optional().describe('Suffix appended to numeric value, e.g. "px", "%"'),
|
|
53
|
-
options: z.array(z.object({
|
|
54
|
-
label: z.string(),
|
|
55
|
-
value: z.union([z.string(), z.number()]),
|
|
56
|
-
})).optional(),
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @param {object} deps
|
|
61
|
-
* @param {string} deps.workspaceRoot
|
|
62
|
-
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
63
|
-
*/
|
|
64
|
-
export function makeExposeTweaksTool({ workspaceRoot, ctx }) {
|
|
65
|
-
return tool(
|
|
66
|
-
'expose_tweaks',
|
|
67
|
-
`Expose a "tweaks schema" for the current deck — a list of UI controls
|
|
68
|
-
(slider, color picker, segmented control, toggle, select) that the user can
|
|
69
|
-
drag in the frontend to live-tweak the design without going through chat.
|
|
70
|
-
|
|
71
|
-
Each control points at a CSS custom property (target_var, must start with --)
|
|
72
|
-
or a class to toggle on root (target_class_on). Frontend renders the controls,
|
|
73
|
-
binds onChange to set CSS variable on iframe :root for instant preview.
|
|
74
|
-
|
|
75
|
-
Use this tool when:
|
|
76
|
-
- You finished writing/editing canvas.html and want to expose 5-8 most
|
|
77
|
-
valuable tunables (hero font size, accent color, layout density, etc.)
|
|
78
|
-
- The user asks "what can I adjust"
|
|
79
|
-
- After the user clicks Apply on the frontend Tweaks panel — re-expose with
|
|
80
|
-
updated default values matching what was just baked into :root
|
|
81
|
-
|
|
82
|
-
The schema is merged into spec.json's spec.tweaks field. Pass replace=true
|
|
83
|
-
to wipe existing controls; default false merges by id.
|
|
84
|
-
|
|
85
|
-
Frontend will refresh once it sees run.tweaks_exposed event.`,
|
|
86
|
-
{
|
|
87
|
-
controls: z.array(ControlSchema).min(1).max(20).describe('Tweak controls to expose'),
|
|
88
|
-
replace: z
|
|
89
|
-
.boolean()
|
|
90
|
-
.optional()
|
|
91
|
-
.describe('If true, replace all existing controls; default false merges by id'),
|
|
92
|
-
},
|
|
93
|
-
async ({ controls, replace }) => {
|
|
94
|
-
try {
|
|
95
|
-
if (!workspaceRoot) {
|
|
96
|
-
return {
|
|
97
|
-
content: [{ type: 'text', text: 'No workspace bound; cannot expose tweaks.' }],
|
|
98
|
-
isError: true,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 串行 read-modify-write 防 spec.json 三路并发覆盖(详见 workspace.js mutateSpecJson)
|
|
103
|
-
let merged;
|
|
104
|
-
await mutateSpecJson(workspaceRoot, (spec) => {
|
|
105
|
-
const existing = (spec.tweaks && Array.isArray(spec.tweaks.controls))
|
|
106
|
-
? spec.tweaks.controls
|
|
107
|
-
: [];
|
|
108
|
-
if (replace) {
|
|
109
|
-
merged = controls;
|
|
110
|
-
} else {
|
|
111
|
-
const byId = new Map(existing.map(c => [c.id, c]));
|
|
112
|
-
for (const c of controls) byId.set(c.id, c);
|
|
113
|
-
merged = [...byId.values()];
|
|
114
|
-
}
|
|
115
|
-
spec.tweaks = {
|
|
116
|
-
version: 1,
|
|
117
|
-
controls: merged,
|
|
118
|
-
updatedAt: new Date().toISOString(),
|
|
119
|
-
updatedBy: 'agent',
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
ctx?.emit?.({
|
|
125
|
-
type: 'run.tweaks_exposed',
|
|
126
|
-
count: merged.length,
|
|
127
|
-
added: controls.length,
|
|
128
|
-
replaced: !!replace,
|
|
129
|
-
});
|
|
130
|
-
} catch { /* emit fail-safe */ }
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
content: [{
|
|
134
|
-
type: 'text',
|
|
135
|
-
text: `Exposed ${controls.length} tweak control(s); spec.tweaks now has ${merged.length} total.`,
|
|
136
|
-
}],
|
|
137
|
-
};
|
|
138
|
-
} catch (err) {
|
|
139
|
-
return {
|
|
140
|
-
content: [{
|
|
141
|
-
type: 'text',
|
|
142
|
-
text: `expose_tweaks failed: ${err?.message || String(err)}`,
|
|
143
|
-
}],
|
|
144
|
-
isError: true,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* mcp/tools/expose-tweaks.js — expose_tweaks MCP tool
|
|
3
|
+
*
|
|
4
|
+
* agent 看完 deck 内容后,把这份 deck 专属的"可调参数控制台"暴露成 schema,
|
|
5
|
+
* 写到 spec.json 的 spec.tweaks 字段。前端 TweaksPanel 读 schema 渲染
|
|
6
|
+
* sliders / color picker / segmented,拖动直接改 iframe :root CSS variable
|
|
7
|
+
* 实时预览(不落盘);用户点 Apply 触发新 chat run,让 agent 把当前数值固化
|
|
8
|
+
* 进 canvas.html 的 :root。
|
|
9
|
+
*
|
|
10
|
+
* spec.json 结构:
|
|
11
|
+
* spec.tweaks = {
|
|
12
|
+
* version: 1,
|
|
13
|
+
* controls: [{ id, type, label, target_var?, target_class_on?, ... }],
|
|
14
|
+
* updatedAt, updatedBy: 'agent',
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* 触发时机(详见 SKILL.md "Tweaks 暴露协议"):
|
|
18
|
+
* - 写完 deck 主动暴露 5-8 个核心可调参数
|
|
19
|
+
* - 用户问"哪些可以调"时
|
|
20
|
+
* - 用户在前端点了 Apply 时把 inline style 固化进 :root(这种 case agent
|
|
21
|
+
* 除了写 canvas.html 还应该 expose_tweaks 更新 default 值)
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
25
|
+
import { z } from 'zod';
|
|
26
|
+
import { mutateSpecJson } from '../../../projects/workspace.js';
|
|
27
|
+
|
|
28
|
+
const ControlSchema = z.object({
|
|
29
|
+
id: z.string().min(1).max(64).regex(/^[a-z0-9_-]+$/, 'id must be kebab/snake case'),
|
|
30
|
+
type: z.enum(['slider', 'color', 'segmented', 'toggle', 'select']),
|
|
31
|
+
label: z.string().min(1).max(80),
|
|
32
|
+
description: z.string().max(200).optional(),
|
|
33
|
+
target_var: z
|
|
34
|
+
.string()
|
|
35
|
+
.regex(/^--[a-zA-Z0-9-]+$/, 'target_var must be a CSS custom property starting with --')
|
|
36
|
+
.optional(),
|
|
37
|
+
target_class_on: z.string().optional(),
|
|
38
|
+
// A6.2:CSS selector 限定 control 影响范围。不传默认 ":root"(全局)。
|
|
39
|
+
// 例:'section[data-page="1"]' / '[data-layout="hero-split"]'(layout 名由 agent
|
|
40
|
+
// 按隐喻自由命名)。配合 SKILL.md HTML 规范的"per-page scoped override"教学
|
|
41
|
+
// (让"封面字号"slider 不牵连内页字号)。前端 TweaksPanel 应用时
|
|
42
|
+
// doc.querySelector(scope) 找元素在它身上 setProperty 而不是 :root。
|
|
43
|
+
target_scope: z
|
|
44
|
+
.string()
|
|
45
|
+
.max(120)
|
|
46
|
+
.optional()
|
|
47
|
+
.describe('CSS selector for scope (e.g. \'section[data-page="1"]\'); default ":root" applies globally. Use to limit one control to one page / one layout type.'),
|
|
48
|
+
min: z.number().optional(),
|
|
49
|
+
max: z.number().optional(),
|
|
50
|
+
step: z.number().optional(),
|
|
51
|
+
default: z.union([z.string(), z.number(), z.boolean()]),
|
|
52
|
+
unit: z.string().max(8).optional().describe('Suffix appended to numeric value, e.g. "px", "%"'),
|
|
53
|
+
options: z.array(z.object({
|
|
54
|
+
label: z.string(),
|
|
55
|
+
value: z.union([z.string(), z.number()]),
|
|
56
|
+
})).optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {object} deps
|
|
61
|
+
* @param {string} deps.workspaceRoot
|
|
62
|
+
* @param {import('../../agent/context.js').AgentContext} [deps.ctx]
|
|
63
|
+
*/
|
|
64
|
+
export function makeExposeTweaksTool({ workspaceRoot, ctx }) {
|
|
65
|
+
return tool(
|
|
66
|
+
'expose_tweaks',
|
|
67
|
+
`Expose a "tweaks schema" for the current deck — a list of UI controls
|
|
68
|
+
(slider, color picker, segmented control, toggle, select) that the user can
|
|
69
|
+
drag in the frontend to live-tweak the design without going through chat.
|
|
70
|
+
|
|
71
|
+
Each control points at a CSS custom property (target_var, must start with --)
|
|
72
|
+
or a class to toggle on root (target_class_on). Frontend renders the controls,
|
|
73
|
+
binds onChange to set CSS variable on iframe :root for instant preview.
|
|
74
|
+
|
|
75
|
+
Use this tool when:
|
|
76
|
+
- You finished writing/editing canvas.html and want to expose 5-8 most
|
|
77
|
+
valuable tunables (hero font size, accent color, layout density, etc.)
|
|
78
|
+
- The user asks "what can I adjust"
|
|
79
|
+
- After the user clicks Apply on the frontend Tweaks panel — re-expose with
|
|
80
|
+
updated default values matching what was just baked into :root
|
|
81
|
+
|
|
82
|
+
The schema is merged into spec.json's spec.tweaks field. Pass replace=true
|
|
83
|
+
to wipe existing controls; default false merges by id.
|
|
84
|
+
|
|
85
|
+
Frontend will refresh once it sees run.tweaks_exposed event.`,
|
|
86
|
+
{
|
|
87
|
+
controls: z.array(ControlSchema).min(1).max(20).describe('Tweak controls to expose'),
|
|
88
|
+
replace: z
|
|
89
|
+
.boolean()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe('If true, replace all existing controls; default false merges by id'),
|
|
92
|
+
},
|
|
93
|
+
async ({ controls, replace }) => {
|
|
94
|
+
try {
|
|
95
|
+
if (!workspaceRoot) {
|
|
96
|
+
return {
|
|
97
|
+
content: [{ type: 'text', text: 'No workspace bound; cannot expose tweaks.' }],
|
|
98
|
+
isError: true,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 串行 read-modify-write 防 spec.json 三路并发覆盖(详见 workspace.js mutateSpecJson)
|
|
103
|
+
let merged;
|
|
104
|
+
await mutateSpecJson(workspaceRoot, (spec) => {
|
|
105
|
+
const existing = (spec.tweaks && Array.isArray(spec.tweaks.controls))
|
|
106
|
+
? spec.tweaks.controls
|
|
107
|
+
: [];
|
|
108
|
+
if (replace) {
|
|
109
|
+
merged = controls;
|
|
110
|
+
} else {
|
|
111
|
+
const byId = new Map(existing.map(c => [c.id, c]));
|
|
112
|
+
for (const c of controls) byId.set(c.id, c);
|
|
113
|
+
merged = [...byId.values()];
|
|
114
|
+
}
|
|
115
|
+
spec.tweaks = {
|
|
116
|
+
version: 1,
|
|
117
|
+
controls: merged,
|
|
118
|
+
updatedAt: new Date().toISOString(),
|
|
119
|
+
updatedBy: 'agent',
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
ctx?.emit?.({
|
|
125
|
+
type: 'run.tweaks_exposed',
|
|
126
|
+
count: merged.length,
|
|
127
|
+
added: controls.length,
|
|
128
|
+
replaced: !!replace,
|
|
129
|
+
});
|
|
130
|
+
} catch { /* emit fail-safe */ }
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
content: [{
|
|
134
|
+
type: 'text',
|
|
135
|
+
text: `Exposed ${controls.length} tweak control(s); spec.tweaks now has ${merged.length} total.`,
|
|
136
|
+
}],
|
|
137
|
+
};
|
|
138
|
+
} catch (err) {
|
|
139
|
+
return {
|
|
140
|
+
content: [{
|
|
141
|
+
type: 'text',
|
|
142
|
+
text: `expose_tweaks failed: ${err?.message || String(err)}`,
|
|
143
|
+
}],
|
|
144
|
+
isError: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
}
|