@tryinget/pi-designmd-foundry 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +78 -0
- package/README.md +193 -0
- package/docs/adr/.gitkeep +0 -0
- package/docs/engineering.local.md +68 -0
- package/docs/org/operating_model.md +34 -0
- package/docs/project/contributing.md +51 -0
- package/docs/project/extension-sop.md +47 -0
- package/docs/project/foundation.md +31 -0
- package/docs/project/incentives.md +17 -0
- package/docs/project/integration-contract.md +74 -0
- package/docs/project/resources.md +23 -0
- package/docs/project/trusted-publishing.md +47 -0
- package/docs/project/vision.md +18 -0
- package/examples/.gitkeep +0 -0
- package/extensions/designmd.ts +1576 -0
- package/package.json +97 -0
- package/policy/engineering-lane.json +36 -0
- package/policy/security-policy.json +10 -0
- package/prompts/pi-designmd-foundry-implementation-planning.md +21 -0
- package/prompts/pi-designmd-foundry-security-review.md +21 -0
- package/skills/designmd-foundry/SKILL.md +112 -0
- package/src/.gitkeep +0 -0
- package/src/toolboxBundle.ts +67 -0
|
@@ -0,0 +1,1576 @@
|
|
|
1
|
+
import { type SpawnSyncReturns, spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
6
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { Type } from "typebox";
|
|
8
|
+
|
|
9
|
+
type PiToolParameters = Parameters<ExtensionAPI["registerTool"]>[0]["parameters"];
|
|
10
|
+
type ToolResult = Awaited<ReturnType<Parameters<ExtensionAPI["registerTool"]>[0]["execute"]>>;
|
|
11
|
+
|
|
12
|
+
type DesignmdFormat =
|
|
13
|
+
| "css"
|
|
14
|
+
| "oat"
|
|
15
|
+
| "tailwind"
|
|
16
|
+
| "dtcg"
|
|
17
|
+
| "tokens"
|
|
18
|
+
| "agent-prompt"
|
|
19
|
+
| "xstate"
|
|
20
|
+
| "rive"
|
|
21
|
+
| "json";
|
|
22
|
+
type OpenPencilExportFormat = "svg" | "png" | "jpg" | "webp" | "fig";
|
|
23
|
+
type SessionArtifactKind = "html" | "svg" | "image" | "markdown" | "css" | "json" | "text";
|
|
24
|
+
|
|
25
|
+
interface BaseParams {
|
|
26
|
+
cwd?: string;
|
|
27
|
+
foundryRoot?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface LintParams extends BaseParams {
|
|
31
|
+
designPath?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ExportParams extends BaseParams {
|
|
35
|
+
designPath?: string;
|
|
36
|
+
format: DesignmdFormat;
|
|
37
|
+
mode?: string;
|
|
38
|
+
objective?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface PromptParams extends BaseParams {
|
|
42
|
+
designPath?: string;
|
|
43
|
+
mode?: string;
|
|
44
|
+
objective?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface OatVisualSnapshotParams extends BaseParams {
|
|
48
|
+
designPath?: string;
|
|
49
|
+
referenceTitle?: string;
|
|
50
|
+
referenceUrl?: string;
|
|
51
|
+
observations?: string[];
|
|
52
|
+
cdn?: boolean;
|
|
53
|
+
stylesheet?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface OpenPencilFileParams extends BaseParams {
|
|
57
|
+
filePath: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface OpenPencilExportParams extends BaseParams {
|
|
61
|
+
filePath: string;
|
|
62
|
+
format: OpenPencilExportFormat;
|
|
63
|
+
outputPath: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface ImportPenpotParams extends BaseParams {
|
|
67
|
+
tokenPath: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface PaletteParams extends BaseParams {
|
|
73
|
+
paletteText?: string;
|
|
74
|
+
palettePath?: string;
|
|
75
|
+
applyDesignPath?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface PenpotMcpInspectParams extends BaseParams {
|
|
79
|
+
endpoint?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface PenpotMcpBridgeParams extends BaseParams {
|
|
83
|
+
bridgePath: string;
|
|
84
|
+
apply?: boolean;
|
|
85
|
+
outputPath?: string;
|
|
86
|
+
endpoint?: string;
|
|
87
|
+
boardName?: string;
|
|
88
|
+
maxNodes?: number;
|
|
89
|
+
updateLatest?: boolean;
|
|
90
|
+
updateBoardId?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface PenpotMcpExportParams extends BaseParams {
|
|
94
|
+
outputPath: string;
|
|
95
|
+
boardId?: string;
|
|
96
|
+
latest?: boolean;
|
|
97
|
+
endpoint?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface SessionPlanParams extends BaseParams {
|
|
101
|
+
projectId?: string;
|
|
102
|
+
sessionId?: string;
|
|
103
|
+
materialize?: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface SessionVariantsParams extends BaseParams {
|
|
107
|
+
projectId?: string;
|
|
108
|
+
sessionId?: string;
|
|
109
|
+
materialize?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface SessionCloseoutParams extends BaseParams {
|
|
113
|
+
projectId?: string;
|
|
114
|
+
sessionId?: string;
|
|
115
|
+
materialize?: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface SessionHandoffParams extends BaseParams {
|
|
119
|
+
projectId?: string;
|
|
120
|
+
sessionId?: string;
|
|
121
|
+
laneId?: string;
|
|
122
|
+
materialize?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface SessionGuidedRunParams extends BaseParams {
|
|
126
|
+
projectId?: string;
|
|
127
|
+
sessionId?: string;
|
|
128
|
+
laneId?: string;
|
|
129
|
+
materialize?: boolean;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface SessionBrowserAgentHandoffParams extends BaseParams {
|
|
133
|
+
projectId?: string;
|
|
134
|
+
sessionId?: string;
|
|
135
|
+
target?: "sitegeist" | "manual-browser-agent";
|
|
136
|
+
baseUrl?: string;
|
|
137
|
+
materialize?: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface SessionPromotionCandidateParams extends BaseParams {
|
|
141
|
+
projectId?: string;
|
|
142
|
+
sessionId?: string;
|
|
143
|
+
materialize?: boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface VisualDossierPiCritiqueParams extends BaseParams {
|
|
147
|
+
projectId?: string;
|
|
148
|
+
sourceId: string;
|
|
149
|
+
dossierId: string;
|
|
150
|
+
markdown?: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface ReadinessParams extends BaseParams {}
|
|
154
|
+
|
|
155
|
+
interface SessionArtifactSpec {
|
|
156
|
+
kind: SessionArtifactKind;
|
|
157
|
+
title: string;
|
|
158
|
+
mimeType: string;
|
|
159
|
+
content?: string;
|
|
160
|
+
path?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface SessionReportOptions {
|
|
164
|
+
toolName: string;
|
|
165
|
+
objective?: string;
|
|
166
|
+
requiredArtifactPath?: string;
|
|
167
|
+
artifact?: (result: CommandResult) => SessionArtifactSpec | undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface WatchSession {
|
|
171
|
+
id: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interface CommandResult {
|
|
175
|
+
ok: boolean;
|
|
176
|
+
command: string;
|
|
177
|
+
args: string[];
|
|
178
|
+
cwd: string;
|
|
179
|
+
status: number | null;
|
|
180
|
+
signal: NodeJS.Signals | null;
|
|
181
|
+
stdout: string;
|
|
182
|
+
stderr: string;
|
|
183
|
+
error: string | undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const FORMAT_VALUES = [
|
|
187
|
+
"css",
|
|
188
|
+
"oat",
|
|
189
|
+
"tailwind",
|
|
190
|
+
"dtcg",
|
|
191
|
+
"tokens",
|
|
192
|
+
"agent-prompt",
|
|
193
|
+
"xstate",
|
|
194
|
+
"rive",
|
|
195
|
+
"json",
|
|
196
|
+
] as const;
|
|
197
|
+
const MODE_VALUES = ["iterate", "remix", "expand", "audit"] as const;
|
|
198
|
+
const OPENPENCIL_EXPORT_FORMAT_VALUES = ["svg", "png", "jpg", "webp", "fig"] as const;
|
|
199
|
+
const WATCH_FETCH_TIMEOUT_MS = 5_000;
|
|
200
|
+
const MAX_PENPOT_BRIDGE_NODES = 10_000;
|
|
201
|
+
|
|
202
|
+
const baseFields = {
|
|
203
|
+
cwd: Type.Optional(
|
|
204
|
+
Type.String({
|
|
205
|
+
description:
|
|
206
|
+
"Working directory for relative DESIGN.md/input paths. Defaults to Pi process cwd.",
|
|
207
|
+
}),
|
|
208
|
+
),
|
|
209
|
+
foundryRoot: Type.Optional(
|
|
210
|
+
Type.String({
|
|
211
|
+
description:
|
|
212
|
+
"DesignMD Foundry repo root. Defaults to DESIGNMD_FOUNDRY_HOME or ~/ai-society/softwareco/owned/designmd-foundry.",
|
|
213
|
+
}),
|
|
214
|
+
),
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const modeField = Type.Optional(
|
|
218
|
+
StringEnum(MODE_VALUES, {
|
|
219
|
+
description: "Design operation mode. Allowed values: iterate, remix, expand, audit.",
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
function asPiToolParameters(schema: unknown): PiToolParameters {
|
|
224
|
+
return schema as PiToolParameters;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export default function (pi: ExtensionAPI) {
|
|
228
|
+
pi.registerCommand("designmd", {
|
|
229
|
+
description: "Show DesignMD Foundry Pi adapter status and setup hints",
|
|
230
|
+
handler: async (_args, ctx) => {
|
|
231
|
+
const foundryRoot = resolveFoundryRoot({});
|
|
232
|
+
const status = fs.existsSync(foundryRoot)
|
|
233
|
+
? `DesignMD Foundry root: ${foundryRoot}`
|
|
234
|
+
: `DesignMD Foundry root not found: ${foundryRoot}`;
|
|
235
|
+
if (ctx.hasUI) ctx.ui.notify(status, fs.existsSync(foundryRoot) ? "info" : "warning");
|
|
236
|
+
else console.log(status);
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
pi.registerTool({
|
|
241
|
+
name: "designmd_lint",
|
|
242
|
+
label: "DesignMD lint",
|
|
243
|
+
description:
|
|
244
|
+
"Lint a DESIGN.md file through the DesignMD Foundry CLI and return the JSON report.",
|
|
245
|
+
parameters: asPiToolParameters(
|
|
246
|
+
Type.Object({
|
|
247
|
+
...baseFields,
|
|
248
|
+
designPath: Type.Optional(
|
|
249
|
+
Type.String({
|
|
250
|
+
description: "DESIGN.md path relative to cwd, or absolute. Defaults to DESIGN.md.",
|
|
251
|
+
}),
|
|
252
|
+
),
|
|
253
|
+
}),
|
|
254
|
+
),
|
|
255
|
+
async execute(_toolCallId, params) {
|
|
256
|
+
const request = params as LintParams;
|
|
257
|
+
const result = await runDesignmdWithSession(
|
|
258
|
+
request,
|
|
259
|
+
["lint", resolveInputPath(request.cwd, request.designPath || "DESIGN.md")],
|
|
260
|
+
{ toolName: "designmd_lint" },
|
|
261
|
+
);
|
|
262
|
+
return toolResult(result);
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
pi.registerTool({
|
|
267
|
+
name: "designmd_export",
|
|
268
|
+
label: "DesignMD export",
|
|
269
|
+
description:
|
|
270
|
+
"Export DesignMD artifacts such as CSS, Oat theme, Tailwind theme, DTCG tokens, or agent prompt.",
|
|
271
|
+
parameters: asPiToolParameters(
|
|
272
|
+
Type.Object({
|
|
273
|
+
...baseFields,
|
|
274
|
+
designPath: Type.Optional(
|
|
275
|
+
Type.String({
|
|
276
|
+
description: "DESIGN.md path relative to cwd, or absolute. Defaults to DESIGN.md.",
|
|
277
|
+
}),
|
|
278
|
+
),
|
|
279
|
+
format: StringEnum(FORMAT_VALUES),
|
|
280
|
+
mode: modeField,
|
|
281
|
+
objective: Type.Optional(
|
|
282
|
+
Type.String({ description: "Optional objective for agent-prompt export." }),
|
|
283
|
+
),
|
|
284
|
+
}),
|
|
285
|
+
),
|
|
286
|
+
async execute(_toolCallId, params) {
|
|
287
|
+
const request = params as ExportParams;
|
|
288
|
+
const args = ["export", "--format", request.format];
|
|
289
|
+
if (request.mode) args.push("--mode", request.mode);
|
|
290
|
+
if (request.objective) args.push("--objective", request.objective);
|
|
291
|
+
args.push(resolveInputPath(request.cwd, request.designPath || "DESIGN.md"));
|
|
292
|
+
return toolResult(
|
|
293
|
+
await runDesignmdWithSession(request, args, {
|
|
294
|
+
toolName: "designmd_export",
|
|
295
|
+
objective: request.objective,
|
|
296
|
+
artifact: (result) => artifactForExport(request.format, result.stdout),
|
|
297
|
+
}),
|
|
298
|
+
);
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
pi.registerTool({
|
|
303
|
+
name: "designmd_agent_prompt",
|
|
304
|
+
label: "DesignMD agent prompt",
|
|
305
|
+
description: "Generate an agent-facing design prompt from DESIGN.md.",
|
|
306
|
+
parameters: asPiToolParameters(
|
|
307
|
+
Type.Object({
|
|
308
|
+
...baseFields,
|
|
309
|
+
designPath: Type.Optional(
|
|
310
|
+
Type.String({
|
|
311
|
+
description: "DESIGN.md path relative to cwd, or absolute. Defaults to DESIGN.md.",
|
|
312
|
+
}),
|
|
313
|
+
),
|
|
314
|
+
mode: modeField,
|
|
315
|
+
objective: Type.Optional(
|
|
316
|
+
Type.String({ description: "Implementation or audit objective for the prompt." }),
|
|
317
|
+
),
|
|
318
|
+
}),
|
|
319
|
+
),
|
|
320
|
+
async execute(_toolCallId, params) {
|
|
321
|
+
const request = params as PromptParams;
|
|
322
|
+
const args = ["export", "--format", "agent-prompt"];
|
|
323
|
+
if (request.mode) args.push("--mode", request.mode);
|
|
324
|
+
if (request.objective) args.push("--objective", request.objective);
|
|
325
|
+
args.push(resolveInputPath(request.cwd, request.designPath || "DESIGN.md"));
|
|
326
|
+
return toolResult(
|
|
327
|
+
await runDesignmdWithSession(request, args, {
|
|
328
|
+
toolName: "designmd_agent_prompt",
|
|
329
|
+
objective: request.objective,
|
|
330
|
+
artifact: (result) => ({
|
|
331
|
+
kind: "markdown",
|
|
332
|
+
title: "DesignMD agent prompt",
|
|
333
|
+
mimeType: "text/markdown; charset=utf-8",
|
|
334
|
+
content: result.stdout,
|
|
335
|
+
}),
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
pi.registerTool({
|
|
342
|
+
name: "designmd_oat_visual_snapshot",
|
|
343
|
+
label: "DesignMD Oat visual snapshot",
|
|
344
|
+
description:
|
|
345
|
+
"Generate a deterministic Oat visual snapshot HTML file from DESIGN.md. Returns HTML only; no canonical files are written.",
|
|
346
|
+
parameters: asPiToolParameters(
|
|
347
|
+
Type.Object({
|
|
348
|
+
...baseFields,
|
|
349
|
+
designPath: Type.Optional(
|
|
350
|
+
Type.String({
|
|
351
|
+
description: "DESIGN.md path relative to cwd, or absolute. Defaults to DESIGN.md.",
|
|
352
|
+
}),
|
|
353
|
+
),
|
|
354
|
+
referenceTitle: Type.Optional(
|
|
355
|
+
Type.String({ description: "Optional title for the visual reference context." }),
|
|
356
|
+
),
|
|
357
|
+
referenceUrl: Type.Optional(
|
|
358
|
+
Type.String({ description: "Optional URL for the visual reference context." }),
|
|
359
|
+
),
|
|
360
|
+
observations: Type.Optional(
|
|
361
|
+
Type.Array(
|
|
362
|
+
Type.String({
|
|
363
|
+
description:
|
|
364
|
+
"Reference cue or review observation to include in the snapshot handoff.",
|
|
365
|
+
}),
|
|
366
|
+
),
|
|
367
|
+
),
|
|
368
|
+
cdn: Type.Optional(
|
|
369
|
+
Type.Boolean({ description: "Opt into loading the external Oat CDN stylesheet." }),
|
|
370
|
+
),
|
|
371
|
+
stylesheet: Type.Optional(
|
|
372
|
+
Type.String({
|
|
373
|
+
description: "Optional local stylesheet path or URL to include explicitly.",
|
|
374
|
+
}),
|
|
375
|
+
),
|
|
376
|
+
}),
|
|
377
|
+
),
|
|
378
|
+
async execute(_toolCallId, params) {
|
|
379
|
+
const request = params as OatVisualSnapshotParams;
|
|
380
|
+
const args = ["oat-visual-snapshot"];
|
|
381
|
+
if (request.cdn) args.push("--cdn");
|
|
382
|
+
if (request.stylesheet) args.push("--stylesheet", request.stylesheet);
|
|
383
|
+
if (request.referenceTitle) args.push("--reference-title", request.referenceTitle);
|
|
384
|
+
if (request.referenceUrl) args.push("--reference-url", request.referenceUrl);
|
|
385
|
+
if (request.observations?.length) args.push("--observations", request.observations.join(";"));
|
|
386
|
+
args.push(resolveInputPath(request.cwd, request.designPath || "DESIGN.md"));
|
|
387
|
+
return toolResult(
|
|
388
|
+
await runDesignmdWithSession(request, args, {
|
|
389
|
+
toolName: "designmd_oat_visual_snapshot",
|
|
390
|
+
objective: request.referenceUrl || request.referenceTitle,
|
|
391
|
+
artifact: (result) => ({
|
|
392
|
+
kind: "html",
|
|
393
|
+
title: "Oat visual snapshot",
|
|
394
|
+
mimeType: "text/html; charset=utf-8",
|
|
395
|
+
content: result.stdout,
|
|
396
|
+
}),
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
},
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
pi.registerTool({
|
|
403
|
+
name: "designmd_openpencil_prompt",
|
|
404
|
+
label: "DesignMD OpenPencil prompt",
|
|
405
|
+
description:
|
|
406
|
+
"Generate an OpenPencil handoff prompt from DESIGN.md. This does not require the OpenPencil CLI.",
|
|
407
|
+
parameters: asPiToolParameters(
|
|
408
|
+
Type.Object({
|
|
409
|
+
...baseFields,
|
|
410
|
+
designPath: Type.Optional(
|
|
411
|
+
Type.String({
|
|
412
|
+
description: "DESIGN.md path relative to cwd, or absolute. Defaults to DESIGN.md.",
|
|
413
|
+
}),
|
|
414
|
+
),
|
|
415
|
+
mode: modeField,
|
|
416
|
+
objective: Type.Optional(Type.String({ description: "OpenPencil handoff objective." })),
|
|
417
|
+
}),
|
|
418
|
+
),
|
|
419
|
+
async execute(_toolCallId, params) {
|
|
420
|
+
const request = params as PromptParams;
|
|
421
|
+
const args = ["openpencil-prompt"];
|
|
422
|
+
if (request.mode) args.push("--mode", request.mode);
|
|
423
|
+
if (request.objective) args.push("--objective", request.objective);
|
|
424
|
+
args.push(resolveInputPath(request.cwd, request.designPath || "DESIGN.md"));
|
|
425
|
+
return toolResult(
|
|
426
|
+
await runDesignmdWithSession(request, args, {
|
|
427
|
+
toolName: "designmd_openpencil_prompt",
|
|
428
|
+
objective: request.objective,
|
|
429
|
+
artifact: (result) => ({
|
|
430
|
+
kind: "markdown",
|
|
431
|
+
title: "OpenPencil handoff prompt",
|
|
432
|
+
mimeType: "text/markdown; charset=utf-8",
|
|
433
|
+
content: result.stdout,
|
|
434
|
+
}),
|
|
435
|
+
}),
|
|
436
|
+
);
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
pi.registerTool({
|
|
441
|
+
name: "designmd_openpencil_info",
|
|
442
|
+
label: "DesignMD OpenPencil info",
|
|
443
|
+
description:
|
|
444
|
+
"Inspect a .fig or .pen file through DesignMD Foundry's OpenPencil info adapter. Read-only; does not export or write files.",
|
|
445
|
+
parameters: asPiToolParameters(
|
|
446
|
+
Type.Object({
|
|
447
|
+
...baseFields,
|
|
448
|
+
filePath: Type.String({
|
|
449
|
+
description: ".fig or .pen path relative to cwd, or absolute.",
|
|
450
|
+
}),
|
|
451
|
+
}),
|
|
452
|
+
),
|
|
453
|
+
async execute(_toolCallId, params) {
|
|
454
|
+
const request = params as OpenPencilFileParams;
|
|
455
|
+
return toolResult(
|
|
456
|
+
await runDesignmdWithSession(
|
|
457
|
+
request,
|
|
458
|
+
["openpencil-info", resolveInputPath(request.cwd, request.filePath)],
|
|
459
|
+
{ toolName: "designmd_openpencil_info" },
|
|
460
|
+
),
|
|
461
|
+
);
|
|
462
|
+
},
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
pi.registerTool({
|
|
466
|
+
name: "designmd_openpencil_lint",
|
|
467
|
+
label: "DesignMD OpenPencil lint",
|
|
468
|
+
description:
|
|
469
|
+
"Lint a .fig or .pen file through DesignMD Foundry's OpenPencil lint adapter. Read-only; export remains intentionally unwrapped.",
|
|
470
|
+
parameters: asPiToolParameters(
|
|
471
|
+
Type.Object({
|
|
472
|
+
...baseFields,
|
|
473
|
+
filePath: Type.String({
|
|
474
|
+
description: ".fig or .pen path relative to cwd, or absolute.",
|
|
475
|
+
}),
|
|
476
|
+
}),
|
|
477
|
+
),
|
|
478
|
+
async execute(_toolCallId, params) {
|
|
479
|
+
const request = params as OpenPencilFileParams;
|
|
480
|
+
return toolResult(
|
|
481
|
+
await runDesignmdWithSession(
|
|
482
|
+
request,
|
|
483
|
+
["openpencil-lint", resolveInputPath(request.cwd, request.filePath)],
|
|
484
|
+
{ toolName: "designmd_openpencil_lint" },
|
|
485
|
+
),
|
|
486
|
+
);
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
pi.registerTool({
|
|
491
|
+
name: "designmd_openpencil_export",
|
|
492
|
+
label: "DesignMD OpenPencil export",
|
|
493
|
+
description:
|
|
494
|
+
"Export a .fig or .pen file through DesignMD Foundry's restricted OpenPencil export adapter. Allowed formats: svg, png, jpg, webp, fig. JSX is intentionally not exposed.",
|
|
495
|
+
parameters: asPiToolParameters(
|
|
496
|
+
Type.Object({
|
|
497
|
+
...baseFields,
|
|
498
|
+
filePath: Type.String({
|
|
499
|
+
description: ".fig or .pen path relative to cwd, or absolute.",
|
|
500
|
+
}),
|
|
501
|
+
format: StringEnum(OPENPENCIL_EXPORT_FORMAT_VALUES, {
|
|
502
|
+
description: "Verified OpenPencil export format. JSX is intentionally excluded.",
|
|
503
|
+
}),
|
|
504
|
+
outputPath: Type.String({
|
|
505
|
+
description:
|
|
506
|
+
"Output artifact path relative to cwd, or absolute. The tool writes this requested file.",
|
|
507
|
+
}),
|
|
508
|
+
}),
|
|
509
|
+
),
|
|
510
|
+
async execute(_toolCallId, params) {
|
|
511
|
+
const request = params as OpenPencilExportParams;
|
|
512
|
+
const resolvedOutputPath = resolveInputPath(request.cwd, request.outputPath);
|
|
513
|
+
const result = await runDesignmdWithSession(
|
|
514
|
+
request,
|
|
515
|
+
[
|
|
516
|
+
"openpencil-export",
|
|
517
|
+
resolveInputPath(request.cwd, request.filePath),
|
|
518
|
+
"--format",
|
|
519
|
+
request.format,
|
|
520
|
+
"--output",
|
|
521
|
+
resolvedOutputPath,
|
|
522
|
+
],
|
|
523
|
+
{
|
|
524
|
+
toolName: "designmd_openpencil_export",
|
|
525
|
+
requiredArtifactPath: resolvedOutputPath,
|
|
526
|
+
artifact: () => artifactForOpenPencilExport(request.format, resolvedOutputPath),
|
|
527
|
+
},
|
|
528
|
+
);
|
|
529
|
+
return toolResult(requireExportArtifact(result, resolvedOutputPath));
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
pi.registerTool({
|
|
534
|
+
name: "designmd_import_penpot",
|
|
535
|
+
label: "DesignMD import Penpot/DTCG",
|
|
536
|
+
description:
|
|
537
|
+
"Convert a DTCG/Penpot token JSON file into DESIGN.md text. Returns text only; it does not overwrite canonical files.",
|
|
538
|
+
parameters: asPiToolParameters(
|
|
539
|
+
Type.Object({
|
|
540
|
+
...baseFields,
|
|
541
|
+
tokenPath: Type.String({
|
|
542
|
+
description: "DTCG/Penpot token JSON path relative to cwd, or absolute.",
|
|
543
|
+
}),
|
|
544
|
+
name: Type.Optional(Type.String({ description: "Optional imported design system name." })),
|
|
545
|
+
description: Type.Optional(
|
|
546
|
+
Type.String({ description: "Optional imported design system description." }),
|
|
547
|
+
),
|
|
548
|
+
}),
|
|
549
|
+
),
|
|
550
|
+
async execute(_toolCallId, params) {
|
|
551
|
+
const request = params as ImportPenpotParams;
|
|
552
|
+
const args = ["import-penpot"];
|
|
553
|
+
if (request.name) args.push("--name", request.name);
|
|
554
|
+
if (request.description) args.push("--description", request.description);
|
|
555
|
+
args.push(resolveInputPath(request.cwd, request.tokenPath));
|
|
556
|
+
return toolResult(
|
|
557
|
+
await runDesignmdWithSession(request, args, {
|
|
558
|
+
toolName: "designmd_import_penpot",
|
|
559
|
+
artifact: (result) => ({
|
|
560
|
+
kind: "markdown",
|
|
561
|
+
title: "Imported Penpot/DTCG DESIGN.md",
|
|
562
|
+
mimeType: "text/markdown; charset=utf-8",
|
|
563
|
+
content: result.stdout,
|
|
564
|
+
}),
|
|
565
|
+
}),
|
|
566
|
+
);
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
pi.registerTool({
|
|
571
|
+
name: "designmd_palette_from_text",
|
|
572
|
+
label: "DesignMD palette from text",
|
|
573
|
+
description:
|
|
574
|
+
"Parse Pigmnts-style hex palette text and optionally apply it to DESIGN.md text. Returns output only; it does not overwrite canonical files.",
|
|
575
|
+
parameters: asPiToolParameters(
|
|
576
|
+
Type.Object({
|
|
577
|
+
...baseFields,
|
|
578
|
+
paletteText: Type.Optional(
|
|
579
|
+
Type.String({ description: "Raw text containing hex colors. Use this or palettePath." }),
|
|
580
|
+
),
|
|
581
|
+
palettePath: Type.Optional(
|
|
582
|
+
Type.String({
|
|
583
|
+
description:
|
|
584
|
+
"Text file containing hex colors, relative to cwd or absolute. Use this or paletteText.",
|
|
585
|
+
}),
|
|
586
|
+
),
|
|
587
|
+
applyDesignPath: Type.Optional(
|
|
588
|
+
Type.String({
|
|
589
|
+
description:
|
|
590
|
+
"Optional DESIGN.md path to apply palette to; otherwise returns parsed color JSON.",
|
|
591
|
+
}),
|
|
592
|
+
),
|
|
593
|
+
}),
|
|
594
|
+
),
|
|
595
|
+
async execute(_toolCallId, params) {
|
|
596
|
+
const request = params as PaletteParams;
|
|
597
|
+
const paletteArg =
|
|
598
|
+
request.paletteText !== undefined
|
|
599
|
+
? "-"
|
|
600
|
+
: resolveInputPath(request.cwd, request.palettePath || "");
|
|
601
|
+
if (!request.paletteText && !request.palettePath) {
|
|
602
|
+
return messageResult("paletteText or palettePath is required.", { ok: false });
|
|
603
|
+
}
|
|
604
|
+
const args = ["palette", paletteArg, "--fromText"];
|
|
605
|
+
if (request.applyDesignPath)
|
|
606
|
+
args.push("--apply", resolveInputPath(request.cwd, request.applyDesignPath));
|
|
607
|
+
return toolResult(
|
|
608
|
+
await runDesignmdWithSession(
|
|
609
|
+
request,
|
|
610
|
+
args,
|
|
611
|
+
{
|
|
612
|
+
toolName: "designmd_palette_from_text",
|
|
613
|
+
artifact: (result) => ({
|
|
614
|
+
kind: request.applyDesignPath ? "markdown" : "json",
|
|
615
|
+
title: request.applyDesignPath
|
|
616
|
+
? "Palette-applied DESIGN.md"
|
|
617
|
+
: "Parsed palette colors",
|
|
618
|
+
mimeType: request.applyDesignPath
|
|
619
|
+
? "text/markdown; charset=utf-8"
|
|
620
|
+
: "application/json; charset=utf-8",
|
|
621
|
+
content: result.stdout,
|
|
622
|
+
}),
|
|
623
|
+
},
|
|
624
|
+
request.paletteText,
|
|
625
|
+
),
|
|
626
|
+
);
|
|
627
|
+
},
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
pi.registerTool({
|
|
631
|
+
name: "designmd_penpot_mcp_inspect",
|
|
632
|
+
label: "DesignMD Penpot MCP inspect",
|
|
633
|
+
description:
|
|
634
|
+
"Read-only inspect of the active Penpot file through the official Penpot MCP server. Requires the Penpot MCP plugin to be connected; does not mutate the file.",
|
|
635
|
+
parameters: asPiToolParameters(
|
|
636
|
+
Type.Object({
|
|
637
|
+
...baseFields,
|
|
638
|
+
endpoint: Type.Optional(
|
|
639
|
+
Type.String({
|
|
640
|
+
description:
|
|
641
|
+
"Penpot MCP HTTP endpoint. Defaults to PENPOT_MCP_URL or http://127.0.0.1:4401/mcp.",
|
|
642
|
+
}),
|
|
643
|
+
),
|
|
644
|
+
}),
|
|
645
|
+
),
|
|
646
|
+
async execute(_toolCallId, params) {
|
|
647
|
+
const request = params as PenpotMcpInspectParams;
|
|
648
|
+
const args = ["penpot-mcp-inspect"];
|
|
649
|
+
if (request.endpoint) args.push("--endpoint", request.endpoint);
|
|
650
|
+
return toolResult(
|
|
651
|
+
await runDesignmdWithSession(request, args, {
|
|
652
|
+
toolName: "designmd_penpot_mcp_inspect",
|
|
653
|
+
objective: "Inspect active Penpot MCP file",
|
|
654
|
+
artifact: (result) => ({
|
|
655
|
+
kind: "json",
|
|
656
|
+
title: "Penpot MCP inspect result",
|
|
657
|
+
mimeType: "application/json; charset=utf-8",
|
|
658
|
+
content: result.stdout,
|
|
659
|
+
}),
|
|
660
|
+
}),
|
|
661
|
+
);
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
pi.registerTool({
|
|
666
|
+
name: "designmd_penpot_mcp_bridge",
|
|
667
|
+
label: "DesignMD Penpot MCP bridge",
|
|
668
|
+
description:
|
|
669
|
+
"Plan or explicitly apply a bounded DesignMD canvas-bridge to Penpot through the official Penpot MCP server. Plan-only by default; apply requires a connected Penpot MCP plugin and creates one board unless updateLatest/updateBoardId selects an existing DesignMD bridge board to rebuild.",
|
|
670
|
+
parameters: asPiToolParameters(
|
|
671
|
+
Type.Object({
|
|
672
|
+
...baseFields,
|
|
673
|
+
bridgePath: Type.String({
|
|
674
|
+
description:
|
|
675
|
+
"designmd.canvas-bridge.v1 JSON path, relative to cwd or absolute. Use /api/session/:id/canvas-bridge to obtain one.",
|
|
676
|
+
}),
|
|
677
|
+
apply: Type.Optional(
|
|
678
|
+
Type.Boolean({
|
|
679
|
+
description:
|
|
680
|
+
"When true, explicitly apply the bridge to the active Penpot file through MCP. Defaults to false (plan only).",
|
|
681
|
+
}),
|
|
682
|
+
),
|
|
683
|
+
outputPath: Type.Optional(
|
|
684
|
+
Type.String({
|
|
685
|
+
description:
|
|
686
|
+
"Optional SVG proof output path for apply=true, relative to cwd or absolute.",
|
|
687
|
+
}),
|
|
688
|
+
),
|
|
689
|
+
endpoint: Type.Optional(
|
|
690
|
+
Type.String({
|
|
691
|
+
description:
|
|
692
|
+
"Penpot MCP HTTP endpoint. Defaults to PENPOT_MCP_URL or http://127.0.0.1:4401/mcp.",
|
|
693
|
+
}),
|
|
694
|
+
),
|
|
695
|
+
boardName: Type.Optional(
|
|
696
|
+
Type.String({ description: "Optional Penpot board name for the bridge apply plan." }),
|
|
697
|
+
),
|
|
698
|
+
maxNodes: Type.Optional(
|
|
699
|
+
Type.Integer({
|
|
700
|
+
minimum: 1,
|
|
701
|
+
maximum: MAX_PENPOT_BRIDGE_NODES,
|
|
702
|
+
description: `Optional positive maximum number of bridge nodes to render (1-${MAX_PENPOT_BRIDGE_NODES}).`,
|
|
703
|
+
}),
|
|
704
|
+
),
|
|
705
|
+
updateLatest: Type.Optional(
|
|
706
|
+
Type.Boolean({
|
|
707
|
+
description:
|
|
708
|
+
"When true, update the latest existing DesignMD bridge board instead of creating a new board. Still plan-only unless apply=true.",
|
|
709
|
+
}),
|
|
710
|
+
),
|
|
711
|
+
updateBoardId: Type.Optional(
|
|
712
|
+
Type.String({
|
|
713
|
+
description:
|
|
714
|
+
"Optional exact existing DesignMD bridge board id to update instead of creating a new board. Still plan-only unless apply=true.",
|
|
715
|
+
}),
|
|
716
|
+
),
|
|
717
|
+
}),
|
|
718
|
+
),
|
|
719
|
+
async execute(_toolCallId, params) {
|
|
720
|
+
const request = params as PenpotMcpBridgeParams;
|
|
721
|
+
const args = ["penpot-mcp-bridge", resolveInputPath(request.cwd, request.bridgePath)];
|
|
722
|
+
if (request.apply) args.push("--apply");
|
|
723
|
+
const resolvedOutputPath = request.outputPath
|
|
724
|
+
? resolveInputPath(request.cwd, request.outputPath)
|
|
725
|
+
: undefined;
|
|
726
|
+
if (resolvedOutputPath) args.push("--output", resolvedOutputPath);
|
|
727
|
+
if (request.endpoint) args.push("--endpoint", request.endpoint);
|
|
728
|
+
if (request.updateLatest && request.updateBoardId) {
|
|
729
|
+
return messageResult("Pass either updateLatest or updateBoardId, not both.", { ok: false });
|
|
730
|
+
}
|
|
731
|
+
if (request.boardName) args.push("--board-name", request.boardName);
|
|
732
|
+
if (
|
|
733
|
+
request.maxNodes !== undefined &&
|
|
734
|
+
(!Number.isInteger(request.maxNodes) ||
|
|
735
|
+
request.maxNodes < 1 ||
|
|
736
|
+
request.maxNodes > MAX_PENPOT_BRIDGE_NODES)
|
|
737
|
+
) {
|
|
738
|
+
return messageResult(
|
|
739
|
+
`maxNodes must be a positive integer no greater than ${MAX_PENPOT_BRIDGE_NODES}.`,
|
|
740
|
+
{ ok: false },
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
if (request.maxNodes !== undefined) args.push("--max-nodes", String(request.maxNodes));
|
|
744
|
+
if (request.updateLatest) args.push("--update-latest");
|
|
745
|
+
if (request.updateBoardId) args.push("--update-board-id", request.updateBoardId);
|
|
746
|
+
return toolResult(
|
|
747
|
+
await runDesignmdWithSession(request, args, {
|
|
748
|
+
toolName: "designmd_penpot_mcp_bridge",
|
|
749
|
+
objective: request.apply ? "Apply Penpot MCP bridge" : "Plan Penpot MCP bridge",
|
|
750
|
+
artifact: (result) =>
|
|
751
|
+
artifactForPenpotMcpBridge(request, result.stdout, resolvedOutputPath),
|
|
752
|
+
}),
|
|
753
|
+
);
|
|
754
|
+
},
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
pi.registerTool({
|
|
758
|
+
name: "designmd_penpot_mcp_export",
|
|
759
|
+
label: "DesignMD Penpot MCP export",
|
|
760
|
+
description:
|
|
761
|
+
"Read-only SVG export of an existing DesignMD bridge board from the active Penpot file through the official Penpot MCP server. Requires an explicit outputPath; does not mutate the Penpot file.",
|
|
762
|
+
parameters: asPiToolParameters(
|
|
763
|
+
Type.Object({
|
|
764
|
+
...baseFields,
|
|
765
|
+
outputPath: Type.String({
|
|
766
|
+
description:
|
|
767
|
+
"SVG output path, relative to cwd or absolute. The tool writes this requested artifact.",
|
|
768
|
+
}),
|
|
769
|
+
boardId: Type.Optional(
|
|
770
|
+
Type.String({
|
|
771
|
+
description:
|
|
772
|
+
"Optional exact existing Penpot bridge board id. When omitted, the latest DesignMD bridge board is exported.",
|
|
773
|
+
}),
|
|
774
|
+
),
|
|
775
|
+
latest: Type.Optional(
|
|
776
|
+
Type.Boolean({
|
|
777
|
+
description:
|
|
778
|
+
"Export the latest DesignMD bridge board when boardId is omitted. Defaults to true.",
|
|
779
|
+
}),
|
|
780
|
+
),
|
|
781
|
+
endpoint: Type.Optional(
|
|
782
|
+
Type.String({
|
|
783
|
+
description:
|
|
784
|
+
"Penpot MCP HTTP endpoint. Defaults to PENPOT_MCP_URL or http://127.0.0.1:4401/mcp.",
|
|
785
|
+
}),
|
|
786
|
+
),
|
|
787
|
+
}),
|
|
788
|
+
),
|
|
789
|
+
async execute(_toolCallId, params) {
|
|
790
|
+
const request = params as PenpotMcpExportParams;
|
|
791
|
+
if (!request.boardId && request.latest === false) {
|
|
792
|
+
return messageResult("Provide boardId or leave latest enabled for Penpot MCP export.", {
|
|
793
|
+
ok: false,
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
const resolvedOutputPath = resolveInputPath(request.cwd, request.outputPath);
|
|
797
|
+
const args = ["penpot-mcp-export", "--output", resolvedOutputPath];
|
|
798
|
+
if (request.boardId) args.push("--board-id", request.boardId);
|
|
799
|
+
else args.push("--latest");
|
|
800
|
+
if (request.endpoint) args.push("--endpoint", request.endpoint);
|
|
801
|
+
const result = await runDesignmdWithSession(request, args, {
|
|
802
|
+
toolName: "designmd_penpot_mcp_export",
|
|
803
|
+
requiredArtifactPath: resolvedOutputPath,
|
|
804
|
+
objective: request.boardId
|
|
805
|
+
? `Export Penpot MCP bridge board ${request.boardId}`
|
|
806
|
+
: "Export latest Penpot MCP bridge board",
|
|
807
|
+
artifact: (result) => artifactForPenpotMcpExport(result.stdout, resolvedOutputPath),
|
|
808
|
+
});
|
|
809
|
+
return toolResult(requireExportArtifact(result, resolvedOutputPath));
|
|
810
|
+
},
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
pi.registerTool({
|
|
814
|
+
name: "designmd_session_plan",
|
|
815
|
+
label: "DesignMD session plan",
|
|
816
|
+
description:
|
|
817
|
+
"Build or materialize a local DesignMD Watch Mode session plan packet. This is Watch Mode planning guidance only, not canonical AK/society authority.",
|
|
818
|
+
parameters: asPiToolParameters(
|
|
819
|
+
Type.Object({
|
|
820
|
+
...baseFields,
|
|
821
|
+
projectId: Type.Optional(
|
|
822
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
823
|
+
),
|
|
824
|
+
sessionId: Type.Optional(
|
|
825
|
+
Type.String({
|
|
826
|
+
description:
|
|
827
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
828
|
+
}),
|
|
829
|
+
),
|
|
830
|
+
materialize: Type.Optional(
|
|
831
|
+
Type.Boolean({
|
|
832
|
+
description:
|
|
833
|
+
"When true, write the plan packet as a local session artifact and check. Defaults to false.",
|
|
834
|
+
}),
|
|
835
|
+
),
|
|
836
|
+
}),
|
|
837
|
+
),
|
|
838
|
+
async execute(_toolCallId, params) {
|
|
839
|
+
const request = params as SessionPlanParams;
|
|
840
|
+
const args = ["session-plan", request.sessionId || "current"];
|
|
841
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
842
|
+
if (request.materialize) args.push("--materialize");
|
|
843
|
+
return toolResult(
|
|
844
|
+
await runDesignmdWithSession(request, args, {
|
|
845
|
+
toolName: "designmd_session_plan",
|
|
846
|
+
objective: request.materialize
|
|
847
|
+
? "Materialize DesignMD session plan"
|
|
848
|
+
: "Build DesignMD session plan",
|
|
849
|
+
artifact: (result) => ({
|
|
850
|
+
kind: "json",
|
|
851
|
+
title: request.materialize
|
|
852
|
+
? "DesignMD materialized session plan result"
|
|
853
|
+
: "DesignMD session plan packet",
|
|
854
|
+
mimeType: "application/json; charset=utf-8",
|
|
855
|
+
content: result.stdout,
|
|
856
|
+
}),
|
|
857
|
+
}),
|
|
858
|
+
);
|
|
859
|
+
},
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
pi.registerTool({
|
|
863
|
+
name: "designmd_session_variants",
|
|
864
|
+
label: "DesignMD session variants",
|
|
865
|
+
description:
|
|
866
|
+
"Build or materialize bounded local DesignMD Watch Mode session variant lanes. These are proposal lanes only, not accepted durable variants or canonical direction.",
|
|
867
|
+
parameters: asPiToolParameters(
|
|
868
|
+
Type.Object({
|
|
869
|
+
...baseFields,
|
|
870
|
+
projectId: Type.Optional(
|
|
871
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
872
|
+
),
|
|
873
|
+
sessionId: Type.Optional(
|
|
874
|
+
Type.String({
|
|
875
|
+
description:
|
|
876
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
877
|
+
}),
|
|
878
|
+
),
|
|
879
|
+
materialize: Type.Optional(
|
|
880
|
+
Type.Boolean({
|
|
881
|
+
description:
|
|
882
|
+
"When true, write the variant lanes packet as a local session artifact and check. Defaults to false.",
|
|
883
|
+
}),
|
|
884
|
+
),
|
|
885
|
+
}),
|
|
886
|
+
),
|
|
887
|
+
async execute(_toolCallId, params) {
|
|
888
|
+
const request = params as SessionVariantsParams;
|
|
889
|
+
const args = ["session-variants", request.sessionId || "current"];
|
|
890
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
891
|
+
if (request.materialize) args.push("--materialize");
|
|
892
|
+
return toolResult(
|
|
893
|
+
await runDesignmdWithSession(request, args, {
|
|
894
|
+
toolName: "designmd_session_variants",
|
|
895
|
+
objective: request.materialize
|
|
896
|
+
? "Materialize DesignMD session variant lanes"
|
|
897
|
+
: "Build DesignMD session variant lanes",
|
|
898
|
+
artifact: (result) => ({
|
|
899
|
+
kind: "json",
|
|
900
|
+
title: request.materialize
|
|
901
|
+
? "DesignMD materialized session variant lanes result"
|
|
902
|
+
: "DesignMD session variant lanes packet",
|
|
903
|
+
mimeType: "application/json; charset=utf-8",
|
|
904
|
+
content: result.stdout,
|
|
905
|
+
}),
|
|
906
|
+
}),
|
|
907
|
+
);
|
|
908
|
+
},
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
pi.registerTool({
|
|
912
|
+
name: "designmd_session_closeout",
|
|
913
|
+
label: "DesignMD session closeout",
|
|
914
|
+
description:
|
|
915
|
+
"Build or materialize a local DesignMD Watch Mode session closeout packet. This is Watch Mode evidence only, not canonical AK/society promotion.",
|
|
916
|
+
parameters: asPiToolParameters(
|
|
917
|
+
Type.Object({
|
|
918
|
+
...baseFields,
|
|
919
|
+
projectId: Type.Optional(
|
|
920
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
921
|
+
),
|
|
922
|
+
sessionId: Type.Optional(
|
|
923
|
+
Type.String({
|
|
924
|
+
description:
|
|
925
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
926
|
+
}),
|
|
927
|
+
),
|
|
928
|
+
materialize: Type.Optional(
|
|
929
|
+
Type.Boolean({
|
|
930
|
+
description:
|
|
931
|
+
"When true, write the closeout packet as a local session artifact and check. Defaults to false.",
|
|
932
|
+
}),
|
|
933
|
+
),
|
|
934
|
+
}),
|
|
935
|
+
),
|
|
936
|
+
async execute(_toolCallId, params) {
|
|
937
|
+
const request = params as SessionCloseoutParams;
|
|
938
|
+
const args = ["session-closeout", request.sessionId || "current"];
|
|
939
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
940
|
+
if (request.materialize) args.push("--materialize");
|
|
941
|
+
return toolResult(
|
|
942
|
+
await runDesignmdWithSession(request, args, {
|
|
943
|
+
toolName: "designmd_session_closeout",
|
|
944
|
+
objective: request.materialize
|
|
945
|
+
? "Materialize DesignMD session closeout"
|
|
946
|
+
: "Build DesignMD session closeout",
|
|
947
|
+
artifact: (result) => ({
|
|
948
|
+
kind: "json",
|
|
949
|
+
title: request.materialize
|
|
950
|
+
? "DesignMD materialized session closeout result"
|
|
951
|
+
: "DesignMD session closeout packet",
|
|
952
|
+
mimeType: "application/json; charset=utf-8",
|
|
953
|
+
content: result.stdout,
|
|
954
|
+
}),
|
|
955
|
+
}),
|
|
956
|
+
);
|
|
957
|
+
},
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
pi.registerTool({
|
|
961
|
+
name: "designmd_session_handoff",
|
|
962
|
+
label: "DesignMD session handoff",
|
|
963
|
+
description:
|
|
964
|
+
"Build or materialize a local DesignMD session handoff prompt for one variant lane. This is local agent/operator guidance only, not canonical authority.",
|
|
965
|
+
parameters: asPiToolParameters(
|
|
966
|
+
Type.Object({
|
|
967
|
+
...baseFields,
|
|
968
|
+
projectId: Type.Optional(
|
|
969
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
970
|
+
),
|
|
971
|
+
sessionId: Type.Optional(
|
|
972
|
+
Type.String({
|
|
973
|
+
description:
|
|
974
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
975
|
+
}),
|
|
976
|
+
),
|
|
977
|
+
laneId: Type.Optional(
|
|
978
|
+
Type.String({
|
|
979
|
+
description:
|
|
980
|
+
"Optional variant lane id or suffix such as safe-iterate, edge-remix, evidence-audit, or microscope-a11y-motion.",
|
|
981
|
+
}),
|
|
982
|
+
),
|
|
983
|
+
materialize: Type.Optional(
|
|
984
|
+
Type.Boolean({
|
|
985
|
+
description:
|
|
986
|
+
"When true, write the handoff prompt as a local session artifact and check. Defaults to false.",
|
|
987
|
+
}),
|
|
988
|
+
),
|
|
989
|
+
}),
|
|
990
|
+
),
|
|
991
|
+
async execute(_toolCallId, params) {
|
|
992
|
+
const request = params as SessionHandoffParams;
|
|
993
|
+
const args = ["session-handoff", request.sessionId || "current"];
|
|
994
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
995
|
+
if (request.laneId) args.push("--lane", request.laneId);
|
|
996
|
+
if (request.materialize) args.push("--materialize");
|
|
997
|
+
return toolResult(
|
|
998
|
+
await runDesignmdWithSession(request, args, {
|
|
999
|
+
toolName: "designmd_session_handoff",
|
|
1000
|
+
objective: request.materialize
|
|
1001
|
+
? "Materialize DesignMD session handoff"
|
|
1002
|
+
: "Build DesignMD session handoff",
|
|
1003
|
+
artifact: (result) => ({
|
|
1004
|
+
kind: "json",
|
|
1005
|
+
title: request.materialize
|
|
1006
|
+
? "DesignMD materialized session handoff result"
|
|
1007
|
+
: "DesignMD session handoff packet",
|
|
1008
|
+
mimeType: "application/json; charset=utf-8",
|
|
1009
|
+
content: result.stdout,
|
|
1010
|
+
}),
|
|
1011
|
+
}),
|
|
1012
|
+
);
|
|
1013
|
+
},
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
pi.registerTool({
|
|
1017
|
+
name: "designmd_session_guided_run",
|
|
1018
|
+
label: "DesignMD guided design run",
|
|
1019
|
+
description:
|
|
1020
|
+
"Build or materialize the full local DesignMD Guided Design Run loop: plan, memory, variant lanes, handoff, and report-back instructions. This prepares Watch Mode orchestration only; it does not execute Pi or promote authority.",
|
|
1021
|
+
parameters: asPiToolParameters(
|
|
1022
|
+
Type.Object({
|
|
1023
|
+
...baseFields,
|
|
1024
|
+
projectId: Type.Optional(
|
|
1025
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
1026
|
+
),
|
|
1027
|
+
sessionId: Type.Optional(
|
|
1028
|
+
Type.String({
|
|
1029
|
+
description:
|
|
1030
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
1031
|
+
}),
|
|
1032
|
+
),
|
|
1033
|
+
laneId: Type.Optional(
|
|
1034
|
+
Type.String({
|
|
1035
|
+
description:
|
|
1036
|
+
"Optional variant lane id or suffix such as safe-iterate, edge-remix, evidence-audit, or microscope-a11y-motion.",
|
|
1037
|
+
}),
|
|
1038
|
+
),
|
|
1039
|
+
materialize: Type.Optional(
|
|
1040
|
+
Type.Boolean({
|
|
1041
|
+
description:
|
|
1042
|
+
"When true, write source lifecycle packets plus the guided run packet as local session artifacts/checks. Defaults to false.",
|
|
1043
|
+
}),
|
|
1044
|
+
),
|
|
1045
|
+
}),
|
|
1046
|
+
),
|
|
1047
|
+
async execute(_toolCallId, params) {
|
|
1048
|
+
const request = params as SessionGuidedRunParams;
|
|
1049
|
+
const args = ["session-guided-run", request.sessionId || "current"];
|
|
1050
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
1051
|
+
if (request.laneId) args.push("--lane", request.laneId);
|
|
1052
|
+
if (request.materialize) args.push("--materialize");
|
|
1053
|
+
return toolResult(
|
|
1054
|
+
await runDesignmdWithSession(request, args, {
|
|
1055
|
+
toolName: "designmd_session_guided_run",
|
|
1056
|
+
objective: request.materialize
|
|
1057
|
+
? "Materialize DesignMD guided design run"
|
|
1058
|
+
: "Build DesignMD guided design run",
|
|
1059
|
+
artifact: (result) => ({
|
|
1060
|
+
kind: "json",
|
|
1061
|
+
title: request.materialize
|
|
1062
|
+
? "DesignMD materialized guided design run result"
|
|
1063
|
+
: "DesignMD guided design run packet",
|
|
1064
|
+
mimeType: "application/json; charset=utf-8",
|
|
1065
|
+
content: result.stdout,
|
|
1066
|
+
}),
|
|
1067
|
+
}),
|
|
1068
|
+
);
|
|
1069
|
+
},
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
pi.registerTool({
|
|
1073
|
+
name: "designmd_session_browser_agent_handoff",
|
|
1074
|
+
label: "DesignMD browser-agent handoff",
|
|
1075
|
+
description:
|
|
1076
|
+
"Build or materialize a local DesignMD browser-agent handoff prompt for optional browser-side review, such as Sitegeist. This is local Watch Mode guidance only, not mutation or promotion authority.",
|
|
1077
|
+
parameters: asPiToolParameters(
|
|
1078
|
+
Type.Object({
|
|
1079
|
+
...baseFields,
|
|
1080
|
+
projectId: Type.Optional(
|
|
1081
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
1082
|
+
),
|
|
1083
|
+
sessionId: Type.Optional(
|
|
1084
|
+
Type.String({
|
|
1085
|
+
description:
|
|
1086
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
1087
|
+
}),
|
|
1088
|
+
),
|
|
1089
|
+
target: Type.Optional(
|
|
1090
|
+
StringEnum(["sitegeist", "manual-browser-agent"] as const, {
|
|
1091
|
+
description: "Optional browser-agent handoff target. Defaults to sitegeist.",
|
|
1092
|
+
}),
|
|
1093
|
+
),
|
|
1094
|
+
baseUrl: Type.Optional(
|
|
1095
|
+
Type.String({
|
|
1096
|
+
description:
|
|
1097
|
+
"Local Foundry base URL to include in the handoff, for example http://127.0.0.1:8787.",
|
|
1098
|
+
}),
|
|
1099
|
+
),
|
|
1100
|
+
materialize: Type.Optional(
|
|
1101
|
+
Type.Boolean({
|
|
1102
|
+
description:
|
|
1103
|
+
"When true, write the browser-agent handoff prompt as a local session artifact and check. Defaults to false.",
|
|
1104
|
+
}),
|
|
1105
|
+
),
|
|
1106
|
+
}),
|
|
1107
|
+
),
|
|
1108
|
+
async execute(_toolCallId, params) {
|
|
1109
|
+
const request = params as SessionBrowserAgentHandoffParams;
|
|
1110
|
+
const args = ["session-browser-agent-handoff", request.sessionId || "current"];
|
|
1111
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
1112
|
+
if (request.target) args.push("--target", request.target);
|
|
1113
|
+
if (request.baseUrl) args.push("--base-url", request.baseUrl);
|
|
1114
|
+
if (request.materialize) args.push("--materialize");
|
|
1115
|
+
return toolResult(
|
|
1116
|
+
await runDesignmdWithSession(request, args, {
|
|
1117
|
+
toolName: "designmd_session_browser_agent_handoff",
|
|
1118
|
+
objective: request.materialize
|
|
1119
|
+
? "Materialize DesignMD browser-agent handoff"
|
|
1120
|
+
: "Build DesignMD browser-agent handoff",
|
|
1121
|
+
artifact: (result) => ({
|
|
1122
|
+
kind: "json",
|
|
1123
|
+
title: request.materialize
|
|
1124
|
+
? "DesignMD materialized browser-agent handoff result"
|
|
1125
|
+
: "DesignMD browser-agent handoff packet",
|
|
1126
|
+
mimeType: "application/json; charset=utf-8",
|
|
1127
|
+
content: result.stdout,
|
|
1128
|
+
}),
|
|
1129
|
+
}),
|
|
1130
|
+
);
|
|
1131
|
+
},
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
pi.registerTool({
|
|
1135
|
+
name: "designmd_session_promotion_candidate",
|
|
1136
|
+
label: "DesignMD session promotion candidate",
|
|
1137
|
+
description:
|
|
1138
|
+
"Build or materialize a local DesignMD promotion candidate packet for owner-surface review. This does not promote, publish, merge, or mutate AK/society authority.",
|
|
1139
|
+
parameters: asPiToolParameters(
|
|
1140
|
+
Type.Object({
|
|
1141
|
+
...baseFields,
|
|
1142
|
+
projectId: Type.Optional(
|
|
1143
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
1144
|
+
),
|
|
1145
|
+
sessionId: Type.Optional(
|
|
1146
|
+
Type.String({
|
|
1147
|
+
description:
|
|
1148
|
+
"Watch Mode session id. Defaults to current running session in local Foundry storage.",
|
|
1149
|
+
}),
|
|
1150
|
+
),
|
|
1151
|
+
materialize: Type.Optional(
|
|
1152
|
+
Type.Boolean({
|
|
1153
|
+
description:
|
|
1154
|
+
"When true, write the promotion candidate packet as a local session artifact and check. Defaults to false.",
|
|
1155
|
+
}),
|
|
1156
|
+
),
|
|
1157
|
+
}),
|
|
1158
|
+
),
|
|
1159
|
+
async execute(_toolCallId, params) {
|
|
1160
|
+
const request = params as SessionPromotionCandidateParams;
|
|
1161
|
+
const args = ["session-promotion-candidate", request.sessionId || "current"];
|
|
1162
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
1163
|
+
if (request.materialize) args.push("--materialize");
|
|
1164
|
+
return toolResult(
|
|
1165
|
+
await runDesignmdWithSession(request, args, {
|
|
1166
|
+
toolName: "designmd_session_promotion_candidate",
|
|
1167
|
+
objective: request.materialize
|
|
1168
|
+
? "Materialize DesignMD promotion candidate"
|
|
1169
|
+
: "Build DesignMD promotion candidate",
|
|
1170
|
+
artifact: (result) => ({
|
|
1171
|
+
kind: "json",
|
|
1172
|
+
title: request.materialize
|
|
1173
|
+
? "DesignMD materialized promotion candidate result"
|
|
1174
|
+
: "DesignMD promotion candidate packet",
|
|
1175
|
+
mimeType: "application/json; charset=utf-8",
|
|
1176
|
+
content: result.stdout,
|
|
1177
|
+
}),
|
|
1178
|
+
}),
|
|
1179
|
+
);
|
|
1180
|
+
},
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
pi.registerTool({
|
|
1184
|
+
name: "designmd_visual_dossier_pi_critique",
|
|
1185
|
+
label: "DesignMD visual-dossier Pi critique",
|
|
1186
|
+
description:
|
|
1187
|
+
"Emit a DesignMD visual-dossier Pi critique/handoff packet over validated dossier state. This is local review evidence/handoff only; it cannot accept dossier guidance, approve docs/design, mutate DESIGN.md, apply proposals, claim DSPx fitness, or create AK/society authority.",
|
|
1188
|
+
parameters: asPiToolParameters(
|
|
1189
|
+
Type.Object({
|
|
1190
|
+
...baseFields,
|
|
1191
|
+
projectId: Type.Optional(
|
|
1192
|
+
Type.String({ description: "DesignMD project id. Defaults to default." }),
|
|
1193
|
+
),
|
|
1194
|
+
sourceId: Type.String({ description: "Visual source id, for example vsrc_..." }),
|
|
1195
|
+
dossierId: Type.String({ description: "Visual dossier id to critique or hand off." }),
|
|
1196
|
+
markdown: Type.Optional(
|
|
1197
|
+
Type.Boolean({
|
|
1198
|
+
description:
|
|
1199
|
+
"When true, return the Foundry markdown handoff prompt. Defaults to JSON packet output.",
|
|
1200
|
+
}),
|
|
1201
|
+
),
|
|
1202
|
+
}),
|
|
1203
|
+
),
|
|
1204
|
+
async execute(_toolCallId, params) {
|
|
1205
|
+
const request = params as VisualDossierPiCritiqueParams;
|
|
1206
|
+
const args = ["visual-dossier", "pi-critique", request.sourceId, request.dossierId];
|
|
1207
|
+
if (request.projectId) args.push("--project", request.projectId);
|
|
1208
|
+
if (request.markdown) args.push("--markdown");
|
|
1209
|
+
return toolResult(
|
|
1210
|
+
await runDesignmdWithSession(request, args, {
|
|
1211
|
+
toolName: "designmd_visual_dossier_pi_critique",
|
|
1212
|
+
objective: "Build DesignMD visual-dossier Pi critique handoff",
|
|
1213
|
+
artifact: (result) => ({
|
|
1214
|
+
kind: request.markdown ? "markdown" : "json",
|
|
1215
|
+
title: request.markdown
|
|
1216
|
+
? "DesignMD visual-dossier Pi critique prompt"
|
|
1217
|
+
: "DesignMD visual-dossier Pi critique packet",
|
|
1218
|
+
mimeType: request.markdown
|
|
1219
|
+
? "text/markdown; charset=utf-8"
|
|
1220
|
+
: "application/json; charset=utf-8",
|
|
1221
|
+
content: result.stdout,
|
|
1222
|
+
}),
|
|
1223
|
+
}),
|
|
1224
|
+
);
|
|
1225
|
+
},
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
pi.registerTool({
|
|
1229
|
+
name: "designmd_readiness",
|
|
1230
|
+
label: "DesignMD readiness",
|
|
1231
|
+
description:
|
|
1232
|
+
"Run DesignMD Foundry integration-readiness checks for Penpot, OpenPencil, Pigmnts, Oat, and agent-prompt workflows.",
|
|
1233
|
+
parameters: asPiToolParameters(Type.Object({ ...baseFields })),
|
|
1234
|
+
async execute(_toolCallId, params) {
|
|
1235
|
+
const request = params as ReadinessParams;
|
|
1236
|
+
const foundryRoot = resolveFoundryRoot(request);
|
|
1237
|
+
const result = spawnSync(
|
|
1238
|
+
process.execPath,
|
|
1239
|
+
["scripts/run-ts.mjs", "scripts/integration-readiness.ts"],
|
|
1240
|
+
{
|
|
1241
|
+
cwd: foundryRoot,
|
|
1242
|
+
encoding: "utf8",
|
|
1243
|
+
timeout: 120_000,
|
|
1244
|
+
maxBuffer: 5 * 1024 * 1024,
|
|
1245
|
+
},
|
|
1246
|
+
);
|
|
1247
|
+
return toolResult(
|
|
1248
|
+
await reportCommandResult(
|
|
1249
|
+
commandResult(
|
|
1250
|
+
"node",
|
|
1251
|
+
["scripts/run-ts.mjs", "scripts/integration-readiness.ts"],
|
|
1252
|
+
foundryRoot,
|
|
1253
|
+
result,
|
|
1254
|
+
),
|
|
1255
|
+
{
|
|
1256
|
+
toolName: "designmd_readiness",
|
|
1257
|
+
artifact: (command) => ({
|
|
1258
|
+
kind: "json",
|
|
1259
|
+
title: "DesignMD integration readiness",
|
|
1260
|
+
mimeType: "application/json; charset=utf-8",
|
|
1261
|
+
content: command.stdout,
|
|
1262
|
+
}),
|
|
1263
|
+
},
|
|
1264
|
+
),
|
|
1265
|
+
);
|
|
1266
|
+
},
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
async function runDesignmdWithSession(
|
|
1271
|
+
params: BaseParams,
|
|
1272
|
+
cliArgs: string[],
|
|
1273
|
+
options: SessionReportOptions,
|
|
1274
|
+
stdin?: string,
|
|
1275
|
+
): Promise<CommandResult> {
|
|
1276
|
+
const session = await ensureWatchSession(options);
|
|
1277
|
+
await postSessionActivity(session, {
|
|
1278
|
+
kind: "action",
|
|
1279
|
+
source: "pi-designmd",
|
|
1280
|
+
message: `${options.toolName} started`,
|
|
1281
|
+
detail: cliArgs.join(" "),
|
|
1282
|
+
});
|
|
1283
|
+
const result = runDesignmd(params, cliArgs, stdin);
|
|
1284
|
+
return reportCommandResult(result, options, session);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
async function reportCommandResult(
|
|
1288
|
+
result: CommandResult,
|
|
1289
|
+
options: SessionReportOptions,
|
|
1290
|
+
existingSession?: WatchSession | null,
|
|
1291
|
+
): Promise<CommandResult> {
|
|
1292
|
+
if (options.requiredArtifactPath) {
|
|
1293
|
+
result = requireExportArtifact(result, options.requiredArtifactPath);
|
|
1294
|
+
}
|
|
1295
|
+
const session =
|
|
1296
|
+
existingSession === undefined ? await ensureWatchSession(options) : existingSession;
|
|
1297
|
+
await postSessionActivity(session, {
|
|
1298
|
+
kind: result.ok ? "success" : "error",
|
|
1299
|
+
source: "pi-designmd",
|
|
1300
|
+
message: `${options.toolName} ${result.ok ? "passed" : "failed"}`,
|
|
1301
|
+
detail: result.ok
|
|
1302
|
+
? result.stdout.slice(0, 1200)
|
|
1303
|
+
: [result.stderr, result.error].filter(Boolean).join("\n").slice(0, 1200),
|
|
1304
|
+
});
|
|
1305
|
+
if (result.ok && options.artifact) {
|
|
1306
|
+
const artifact = options.artifact(result);
|
|
1307
|
+
if (artifact) await postSessionArtifact(session, artifact);
|
|
1308
|
+
}
|
|
1309
|
+
return result;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
function runDesignmd(params: BaseParams, cliArgs: string[], stdin?: string): CommandResult {
|
|
1313
|
+
const foundryRoot = resolveFoundryRoot(params);
|
|
1314
|
+
const { command, args } = designmdCli(foundryRoot);
|
|
1315
|
+
return commandResult(
|
|
1316
|
+
command,
|
|
1317
|
+
[...args, ...cliArgs],
|
|
1318
|
+
foundryRoot,
|
|
1319
|
+
spawnSync(command, [...args, ...cliArgs], {
|
|
1320
|
+
cwd: foundryRoot,
|
|
1321
|
+
input: stdin,
|
|
1322
|
+
encoding: "utf8",
|
|
1323
|
+
timeout: 120_000,
|
|
1324
|
+
maxBuffer: 5 * 1024 * 1024,
|
|
1325
|
+
}),
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function commandResult(
|
|
1330
|
+
command: string,
|
|
1331
|
+
args: string[],
|
|
1332
|
+
cwd: string,
|
|
1333
|
+
result: SpawnSyncReturns<string>,
|
|
1334
|
+
): CommandResult {
|
|
1335
|
+
return {
|
|
1336
|
+
ok: !result.error && result.status === 0,
|
|
1337
|
+
command,
|
|
1338
|
+
args,
|
|
1339
|
+
cwd,
|
|
1340
|
+
status: result.status,
|
|
1341
|
+
signal: result.signal,
|
|
1342
|
+
stdout: result.stdout || "",
|
|
1343
|
+
stderr: result.stderr || "",
|
|
1344
|
+
error: result.error ? result.error.message : undefined,
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function toolResult(result: CommandResult): ToolResult {
|
|
1349
|
+
const details = {
|
|
1350
|
+
ok: result.ok,
|
|
1351
|
+
command: result.command,
|
|
1352
|
+
args: result.args,
|
|
1353
|
+
cwd: result.cwd,
|
|
1354
|
+
status: result.status,
|
|
1355
|
+
signal: result.signal,
|
|
1356
|
+
stderr: result.stderr,
|
|
1357
|
+
error: result.error,
|
|
1358
|
+
};
|
|
1359
|
+
const text = result.ok
|
|
1360
|
+
? result.stdout
|
|
1361
|
+
: [result.stdout, result.stderr, result.error].filter(Boolean).join("\n");
|
|
1362
|
+
return {
|
|
1363
|
+
content: [{ type: "text", text: text || JSON.stringify(details, null, 2) }],
|
|
1364
|
+
details,
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
function messageResult(text: string, details: Record<string, unknown>): ToolResult {
|
|
1369
|
+
return { content: [{ type: "text", text }], details };
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
function artifactForExport(format: DesignmdFormat, content: string): SessionArtifactSpec {
|
|
1373
|
+
switch (format) {
|
|
1374
|
+
case "css":
|
|
1375
|
+
case "oat":
|
|
1376
|
+
return {
|
|
1377
|
+
kind: "css",
|
|
1378
|
+
title: `DesignMD ${format} export`,
|
|
1379
|
+
mimeType: "text/css; charset=utf-8",
|
|
1380
|
+
content,
|
|
1381
|
+
};
|
|
1382
|
+
case "agent-prompt":
|
|
1383
|
+
return {
|
|
1384
|
+
kind: "markdown",
|
|
1385
|
+
title: "DesignMD agent prompt export",
|
|
1386
|
+
mimeType: "text/markdown; charset=utf-8",
|
|
1387
|
+
content,
|
|
1388
|
+
};
|
|
1389
|
+
case "tailwind":
|
|
1390
|
+
case "dtcg":
|
|
1391
|
+
case "tokens":
|
|
1392
|
+
case "xstate":
|
|
1393
|
+
case "rive":
|
|
1394
|
+
case "json":
|
|
1395
|
+
return {
|
|
1396
|
+
kind: "json",
|
|
1397
|
+
title: `DesignMD ${format} export`,
|
|
1398
|
+
mimeType: "application/json; charset=utf-8",
|
|
1399
|
+
content,
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function artifactForOpenPencilExport(
|
|
1405
|
+
format: OpenPencilExportFormat,
|
|
1406
|
+
outputPath: string,
|
|
1407
|
+
): SessionArtifactSpec {
|
|
1408
|
+
if (format === "svg" && fs.existsSync(outputPath)) {
|
|
1409
|
+
return {
|
|
1410
|
+
kind: "svg",
|
|
1411
|
+
title: "OpenPencil SVG export",
|
|
1412
|
+
mimeType: "image/svg+xml",
|
|
1413
|
+
content: fs.readFileSync(outputPath, "utf8"),
|
|
1414
|
+
path: outputPath,
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
return {
|
|
1418
|
+
kind: format === "png" || format === "jpg" || format === "webp" ? "image" : "text",
|
|
1419
|
+
title: `OpenPencil ${format.toUpperCase()} export`,
|
|
1420
|
+
mimeType:
|
|
1421
|
+
format === "fig" ? "application/octet-stream" : `image/${format === "jpg" ? "jpeg" : format}`,
|
|
1422
|
+
path: outputPath,
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
function artifactForPenpotMcpBridge(
|
|
1427
|
+
request: PenpotMcpBridgeParams,
|
|
1428
|
+
stdout: string,
|
|
1429
|
+
outputPath?: string,
|
|
1430
|
+
): SessionArtifactSpec {
|
|
1431
|
+
if (request.apply && outputPath && fs.existsSync(outputPath)) {
|
|
1432
|
+
return {
|
|
1433
|
+
kind: "svg",
|
|
1434
|
+
title: "Penpot MCP bridge proof SVG",
|
|
1435
|
+
mimeType: "image/svg+xml",
|
|
1436
|
+
content: fs.readFileSync(outputPath, "utf8"),
|
|
1437
|
+
path: outputPath,
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
return {
|
|
1441
|
+
kind: "json",
|
|
1442
|
+
title: request.apply ? "Penpot MCP bridge apply result" : "Penpot MCP bridge plan",
|
|
1443
|
+
mimeType: "application/json; charset=utf-8",
|
|
1444
|
+
content: stdout,
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
function artifactForPenpotMcpExport(stdout: string, outputPath: string): SessionArtifactSpec {
|
|
1449
|
+
if (fs.existsSync(outputPath)) {
|
|
1450
|
+
return {
|
|
1451
|
+
kind: "svg",
|
|
1452
|
+
title: "Penpot MCP existing board SVG export",
|
|
1453
|
+
mimeType: "image/svg+xml",
|
|
1454
|
+
content: fs.readFileSync(outputPath, "utf8"),
|
|
1455
|
+
path: outputPath,
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
return {
|
|
1459
|
+
kind: "json",
|
|
1460
|
+
title: "Penpot MCP existing board export result",
|
|
1461
|
+
mimeType: "application/json; charset=utf-8",
|
|
1462
|
+
content: stdout,
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
async function ensureWatchSession(options: SessionReportOptions): Promise<WatchSession | null> {
|
|
1467
|
+
const endpoint = normalizedSessionEndpoint();
|
|
1468
|
+
if (!endpoint) return null;
|
|
1469
|
+
const explicitSessionId = process.env.DESIGNMD_SESSION_ID;
|
|
1470
|
+
if (explicitSessionId) return { id: explicitSessionId };
|
|
1471
|
+
|
|
1472
|
+
const current = await postJson<{ session?: { id?: string } | null }>(
|
|
1473
|
+
`${endpoint}/current`,
|
|
1474
|
+
null,
|
|
1475
|
+
"GET",
|
|
1476
|
+
);
|
|
1477
|
+
if (current?.session?.id) return { id: current.session.id };
|
|
1478
|
+
|
|
1479
|
+
const created = await postJson<{ session?: { id?: string } }>(endpoint, {
|
|
1480
|
+
objective: options.objective || `Pi DesignMD tool: ${options.toolName}`,
|
|
1481
|
+
actor: process.env.DESIGNMD_SESSION_ACTOR || "pi-designmd",
|
|
1482
|
+
});
|
|
1483
|
+
return created?.session?.id ? { id: created.session.id } : null;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
async function postSessionActivity(
|
|
1487
|
+
session: WatchSession | null,
|
|
1488
|
+
activity: { kind: string; source: string; message: string; detail?: string },
|
|
1489
|
+
): Promise<void> {
|
|
1490
|
+
const endpoint = normalizedSessionEndpoint();
|
|
1491
|
+
if (!endpoint || !session) return;
|
|
1492
|
+
await postJson(`${endpoint}/${encodeURIComponent(session.id)}/activity`, activity);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
async function postSessionArtifact(
|
|
1496
|
+
session: WatchSession | null,
|
|
1497
|
+
artifact: SessionArtifactSpec,
|
|
1498
|
+
): Promise<void> {
|
|
1499
|
+
const endpoint = normalizedSessionEndpoint();
|
|
1500
|
+
if (!endpoint || !session) return;
|
|
1501
|
+
await postJson(`${endpoint}/${encodeURIComponent(session.id)}/artifact`, artifact);
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
async function postJson<T = unknown>(
|
|
1505
|
+
url: string,
|
|
1506
|
+
body: unknown,
|
|
1507
|
+
method = "POST",
|
|
1508
|
+
): Promise<T | null> {
|
|
1509
|
+
try {
|
|
1510
|
+
const headers: Record<string, string> = { Accept: "application/json" };
|
|
1511
|
+
if (body !== null) headers["Content-Type"] = "application/json";
|
|
1512
|
+
const token = process.env.DESIGNMD_SESSION_TOKEN || process.env.DESIGNMD_API_TOKEN;
|
|
1513
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
1514
|
+
const response = await fetch(url, {
|
|
1515
|
+
method,
|
|
1516
|
+
headers,
|
|
1517
|
+
body: body === null ? undefined : JSON.stringify(body),
|
|
1518
|
+
signal: AbortSignal.timeout(WATCH_FETCH_TIMEOUT_MS),
|
|
1519
|
+
});
|
|
1520
|
+
if (!response.ok) return null;
|
|
1521
|
+
return (await response.json()) as T;
|
|
1522
|
+
} catch {
|
|
1523
|
+
return null;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
function requireExportArtifact(result: CommandResult, outputPath: string): CommandResult {
|
|
1528
|
+
if (!result.ok || fs.existsSync(outputPath)) return result;
|
|
1529
|
+
return {
|
|
1530
|
+
...result,
|
|
1531
|
+
ok: false,
|
|
1532
|
+
error: `Export command completed without creating required artifact: ${outputPath}`,
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
function normalizedSessionEndpoint(): string | undefined {
|
|
1537
|
+
const raw = process.env.DESIGNMD_SESSION_ENDPOINT;
|
|
1538
|
+
return raw ? raw.replace(/\/+$/, "") : undefined;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
function designmdCli(foundryRoot: string): { command: string; args: string[] } {
|
|
1542
|
+
const distCli = path.join(foundryRoot, "dist", "cli.js");
|
|
1543
|
+
if (fs.existsSync(distCli)) return { command: process.execPath, args: [distCli] };
|
|
1544
|
+
const sourceCli = path.join(foundryRoot, "src", "cli.ts");
|
|
1545
|
+
return {
|
|
1546
|
+
command: process.execPath,
|
|
1547
|
+
args: ["--disable-warning=ExperimentalWarning", "--experimental-strip-types", sourceCli],
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function resolveFoundryRoot(params: BaseParams): string {
|
|
1552
|
+
const explicit = params.foundryRoot || process.env.DESIGNMD_FOUNDRY_HOME;
|
|
1553
|
+
const foundryRoot =
|
|
1554
|
+
explicit || path.join(os.homedir(), "ai-society", "softwareco", "owned", "designmd-foundry");
|
|
1555
|
+
return path.resolve(expandHome(foundryRoot));
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
function resolveInputPath(cwd: string | undefined, inputPath: string): string {
|
|
1559
|
+
if (!inputPath) return inputPath;
|
|
1560
|
+
const expanded = expandHome(inputPath);
|
|
1561
|
+
if (path.isAbsolute(expanded)) return path.resolve(expanded);
|
|
1562
|
+
return path.resolve(cwd ? expandHome(cwd) : process.cwd(), expanded);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
function expandHome(value: string): string {
|
|
1566
|
+
if (value === "~") return os.homedir();
|
|
1567
|
+
if (value.startsWith("~/")) return path.join(os.homedir(), value.slice(2));
|
|
1568
|
+
return value;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
export const _test = {
|
|
1572
|
+
WATCH_FETCH_TIMEOUT_MS,
|
|
1573
|
+
MAX_PENPOT_BRIDGE_NODES,
|
|
1574
|
+
postJson,
|
|
1575
|
+
requireExportArtifact,
|
|
1576
|
+
};
|