@imgly/codesign-mcp 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tools/edit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,OAAO;IAChD,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B;;;;OAIG;IACH,UAAU,EAAE,KAAK,CAAC;IAClB,iEAAiE;IACjE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;KACtB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,gGAAgG;IAChG,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,CAAC,CAAC;KACX,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1B,2FAA2F;IAC3F,EAAE,CAAC,EAAE,WAAW,CAAC;CAClB;AAiDD,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EACxC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC7B,2BAA2B,
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,OAAO;IAChD,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B;;;;OAIG;IACH,UAAU,EAAE,KAAK,CAAC;IAClB,iEAAiE;IACjE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;KACtB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,gGAAgG;IAChG,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,CAAC,CAAC;KACX,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1B,2FAA2F;IAC3F,EAAE,CAAC,EAAE,WAAW,CAAC;CAClB;AAiDD,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EACxC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC7B,2BAA2B,CAoH7B"}
|
package/dist/tools/edit.js
CHANGED
|
@@ -28,7 +28,7 @@ const EDIT_INPUT_SCHEMA = {
|
|
|
28
28
|
properties: {
|
|
29
29
|
parent: {
|
|
30
30
|
oneOf: [{ type: 'string' }, { type: 'null' }],
|
|
31
|
-
description: 'Parent revision id
|
|
31
|
+
description: 'Parent revision id from a previous edit (a string). To start a new design root, use the JSON null literal. REQUIRED — there is no implicit default.'
|
|
32
32
|
},
|
|
33
33
|
code: {
|
|
34
34
|
type: 'string',
|
|
@@ -66,18 +66,11 @@ export function createEditTool(opts) {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
if (args.parent === 'null') {
|
|
69
|
-
// LLMs
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
content: [
|
|
75
|
-
{
|
|
76
|
-
type: 'text',
|
|
77
|
-
text: 'edit: `parent` arrived as the four-character string "null" (with quotes). Pass JSON null (the literal, no quotes) to create a new design root.'
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
};
|
|
69
|
+
// Some LLMs / MCP clients emit the JSON string "null" instead of the
|
|
70
|
+
// bare null literal — a quoting slip, not a real revision id. Coerce it
|
|
71
|
+
// rather than reject: this quoting nuance must never block creating a
|
|
72
|
+
// new design root. (Stochastic, model-dependent; see edit.test.ts.)
|
|
73
|
+
args.parent = null;
|
|
81
74
|
}
|
|
82
75
|
if (typeof args.code !== 'string') {
|
|
83
76
|
return {
|
package/dist/tools/edit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,uBAAuB;AACvB,sDAAsD;AACtD,sEAAsE;AACtE,oEAAoE;AACpE,mEAAmE;AACnE,wDAAwD;AACxD,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AAOzE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAyB9C,MAAM,WAAW,GAAG;IAClB,yHAAyH;IACzH,EAAE;IACF,4KAA4K;IAC5K,EAAE;IACF,yMAAyM;IACzM,EAAE;IACF,oIAAoI;IACpI,EAAE;IACF,mMAAmM;CACpM,CAAC,IAAI,CAAC,IAAI,CAAC,CAA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uE;oBACzE,CAAC;gBACH,CAAC;gBACD,IAAI,aAAa,EAAE,CAAC;oBAClB,MAAM,YAAY,GAChB,IAAI,CAAC,MAAM,KAAK,IAAI;wBAClB,CAAC,CAAC,OAAO,CAAC,EAAE;wBACZ,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChD,MAAM,aAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;gBAC9D,CAAC;gBACD,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACvE,MAAM,SAAS,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;gBAC9C,OAAO;oBACL,OAAO,EAAE;wBACP,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;wBACzD,GAAG,SAAS;qBACb;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// packages/codesign-mcp/src/tools/edit.ts\n//\n// `edit` — the spec's central tool (§6.1). Replaces `exec.ts`. Differences\n// from the POC `exec`:\n// - `parent` is mandatory (null = new design root).\n// - `title?` set on root creation; `note?` annotates this revision.\n// - Writes a new revision via RevisionStore after `code` returns.\n// - Reloads engine if session slot's currentRevision !== parent.\n// - Dirty-on-throw: failed code marks the slot dirty.\n// - Returns {revision, parent} JSON as the first MessagePart (text).\n//\n// `onLeafWritten` is the viewer hook: called after a successful write so the\n// SSE broadcaster can fan out the new revision id to subscribed viewers.\n\nimport type { Mutex } from '../engine/mutex.js';\nimport type { EngineSession } from '../engine/session.js';\nimport type { RevisionStore } from '../revisions/store.js';\nimport type { CodesignMcpToolRegistration } from '../server.js';\nimport type { WorkspaceFS } from '../workspace/types.js';\nimport { normalizeResult } from './result.js';\n\nexport interface CreateEditToolOptions<E = unknown> {\n store: RevisionStore;\n session: EngineSession<E>;\n /**\n * Guards the shared engine. The acquire → run code → save → thumbnail\n * sequence below mutates one engine across several awaits; this serializes\n * it against any other engine-touching tool call (see engine/mutex.ts).\n */\n engineLock: Mutex;\n /** Called after a successful edit writes a new leaf revision. */\n onLeafWritten?: (event: {\n revision: string;\n rootRevision: string;\n }) => void | Promise<void>;\n /** Render a thumbnail for the newly committed revision. Best-effort: failures are swallowed. */\n renderThumbnail?: (event: {\n revision: string;\n engine: E;\n }) => Promise<Uint8Array>;\n /** Workspace FS for persisting the thumbnail (required if renderThumbnail is supplied). */\n fs?: WorkspaceFS;\n}\n\nconst DESCRIPTION = [\n 'Edit the CE.SDK canvas by running JavaScript against the live CreativeEngine, then commit the result as a new revision.',\n '',\n '⚠ Call `handbook` BEFORE your first `edit`. It documents the mandatory `parent` argument, the dirty-on-throw safety contract, the typeface schema, and the runtime quirks.',\n '',\n \"REQUIRED: `parent` is a revision id (returned by a previous edit), or the JSON null literal (no quotes) to start a new design. Omitting it is an error — there is no implicit 'continue from wherever'.\",\n '',\n 'Returns: the first content part is JSON `{ revision, parent }` — store `revision` so you can pass it as `parent` on the next edit.',\n '',\n \"Optional: `title` (set on parent=null only — the design's display name) and `note` (a one-liner describing what this edit accomplished — purely descriptive, helps you re-ground after a rewind).\"\n].join('\\n');\n\ninterface EditArgs {\n parent: string | null;\n code: string;\n title?: string;\n note?: string;\n}\n\nconst EDIT_INPUT_SCHEMA = {\n type: 'object' as const,\n properties: {\n parent: {\n oneOf: [{ type: 'string' as const }, { type: 'null' as const }],\n description:\n 'Parent revision id (string), or the JSON null literal (no quotes — the value null, not the four-character string \"null\") for a new design root. REQUIRED — there is no implicit default.'\n },\n code: {\n type: 'string' as const,\n description:\n 'Async JS body. `engine` is in scope. Strict return contract per the handbook.'\n },\n title: {\n type: 'string' as const,\n description:\n 'Display name for the design. Set only when parent=null (creating a new design). For mid-chain renames use the `rename` tool.'\n },\n note: {\n type: 'string' as const,\n description:\n 'Freeform descriptive text — what this edit accomplished. Metadata only; never load-bearing.'\n }\n },\n required: ['parent', 'code'],\n additionalProperties: false\n};\n\nexport function createEditTool<E = unknown>(\n opts: CreateEditToolOptions<E>\n): CodesignMcpToolRegistration {\n const { store, session, onLeafWritten, renderThumbnail, fs, engineLock } =\n opts;\n return {\n name: 'edit',\n description: DESCRIPTION,\n inputSchema: EDIT_INPUT_SCHEMA,\n call: async (rawArgs) => {\n const args = (rawArgs ?? {}) as Partial<EditArgs>;\n if (!Object.hasOwn(args, 'parent')) {\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: 'edit: `parent` is required. Pass the revision id from a previous edit, or the JSON null literal (no quotes) for a new design root. See `handbook` for the rewind-recovery flow.'\n }\n ]\n };\n }\n if (args.parent === 'null') {\n // LLMs sometimes serialize JSON null as the string \"null\" when the\n // description mentions null in backticks. Catch it explicitly so\n // the agent gets a teaching message instead of \"unknown revision\".\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: 'edit: `parent` arrived as the four-character string \"null\" (with quotes). Pass JSON null (the literal, no quotes) to create a new design root.'\n }\n ]\n };\n }\n if (typeof args.code !== 'string') {\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: 'edit: `code` (string) is required.'\n }\n ]\n };\n }\n // The shared engine is loaded, mutated by user code, then saved across\n // several awaits below. Serialize the whole sequence so a concurrent\n // session sharing this engine can't swap the scene out mid-edit.\n return engineLock.runExclusive(async () => {\n // Pre-stage scene bytes for the session if parent is non-null.\n if (args.parent !== null) {\n const parentRev = await store.read(args.parent as string);\n await session.populate(args.parent as string, parentRev.scene);\n }\n const slot = await session.acquire(args.parent ?? null);\n let codeResult: unknown;\n try {\n const AsyncFunction = Object.getPrototypeOf(\n async () => {}\n ).constructor;\n const fn = new AsyncFunction('engine', args.code);\n codeResult = await fn(slot.engine);\n } catch (err) {\n session.markDirty(slot);\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: `edit: code threw — engine slot marked dirty (next edit pays one reload). ${\n err instanceof Error\n ? (err.stack ?? err.message)\n : String(err)\n }`\n }\n ]\n };\n }\n const adapter = (\n session as unknown as {\n opts: { adapter: { saveToString(e: E): Promise<string> } };\n }\n ).opts.adapter;\n const sceneBytes = await adapter.saveToString(slot.engine);\n const written = await store.write({\n scene: sceneBytes,\n parent: args.parent ?? null,\n title: args.title,\n note: args.note,\n code: args.code\n });\n session.commit(slot, written.id);\n if (renderThumbnail && fs) {\n try {\n const bytes = await renderThumbnail({\n revision: written.id,\n engine: slot.engine\n });\n const shard = written.id.slice(0, 2);\n const rest = written.id.slice(2);\n await fs.writeFile(`exports/${shard}/${rest}/preview.webp`, bytes);\n } catch {\n // best-effort; thumbnail failure must not poison the edit success path\n }\n }\n if (onLeafWritten) {\n const rootRevision =\n args.parent === null\n ? written.id\n : (await store.historyOf(written.id))[0].id;\n await onLeafWritten({ revision: written.id, rootRevision });\n }\n const envelope = { revision: written.id, parent: args.parent ?? null };\n const codeParts = normalizeResult(codeResult);\n return {\n content: [\n { type: 'text' as const, text: JSON.stringify(envelope) },\n ...codeParts\n ]\n };\n });\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,uBAAuB;AACvB,sDAAsD;AACtD,sEAAsE;AACtE,oEAAoE;AACpE,mEAAmE;AACnE,wDAAwD;AACxD,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AAOzE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAyB9C,MAAM,WAAW,GAAG;IAClB,yHAAyH;IACzH,EAAE;IACF,4KAA4K;IAC5K,EAAE;IACF,yMAAyM;IACzM,EAAE;IACF,oIAAoI;IACpI,EAAE;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;gBACD,IAAI,aAAa,EAAE,CAAC;oBAClB,MAAM,YAAY,GAChB,IAAI,CAAC,MAAM,KAAK,IAAI;wBAClB,CAAC,CAAC,OAAO,CAAC,EAAE;wBACZ,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChD,MAAM,aAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;gBAC9D,CAAC;gBACD,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACvE,MAAM,SAAS,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;gBAC9C,OAAO;oBACL,OAAO,EAAE;wBACP,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;wBACzD,GAAG,SAAS;qBACb;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// packages/codesign-mcp/src/tools/edit.ts\n//\n// `edit` — the spec's central tool (§6.1). Replaces `exec.ts`. Differences\n// from the POC `exec`:\n// - `parent` is mandatory (null = new design root).\n// - `title?` set on root creation; `note?` annotates this revision.\n// - Writes a new revision via RevisionStore after `code` returns.\n// - Reloads engine if session slot's currentRevision !== parent.\n// - Dirty-on-throw: failed code marks the slot dirty.\n// - Returns {revision, parent} JSON as the first MessagePart (text).\n//\n// `onLeafWritten` is the viewer hook: called after a successful write so the\n// SSE broadcaster can fan out the new revision id to subscribed viewers.\n\nimport type { Mutex } from '../engine/mutex.js';\nimport type { EngineSession } from '../engine/session.js';\nimport type { RevisionStore } from '../revisions/store.js';\nimport type { CodesignMcpToolRegistration } from '../server.js';\nimport type { WorkspaceFS } from '../workspace/types.js';\nimport { normalizeResult } from './result.js';\n\nexport interface CreateEditToolOptions<E = unknown> {\n store: RevisionStore;\n session: EngineSession<E>;\n /**\n * Guards the shared engine. The acquire → run code → save → thumbnail\n * sequence below mutates one engine across several awaits; this serializes\n * it against any other engine-touching tool call (see engine/mutex.ts).\n */\n engineLock: Mutex;\n /** Called after a successful edit writes a new leaf revision. */\n onLeafWritten?: (event: {\n revision: string;\n rootRevision: string;\n }) => void | Promise<void>;\n /** Render a thumbnail for the newly committed revision. Best-effort: failures are swallowed. */\n renderThumbnail?: (event: {\n revision: string;\n engine: E;\n }) => Promise<Uint8Array>;\n /** Workspace FS for persisting the thumbnail (required if renderThumbnail is supplied). */\n fs?: WorkspaceFS;\n}\n\nconst DESCRIPTION = [\n 'Edit the CE.SDK canvas by running JavaScript against the live CreativeEngine, then commit the result as a new revision.',\n '',\n '⚠ Call `handbook` BEFORE your first `edit`. It documents the mandatory `parent` argument, the dirty-on-throw safety contract, the typeface schema, and the runtime quirks.',\n '',\n \"REQUIRED: `parent` is a revision id (returned by a previous edit), or the JSON null literal (no quotes) to start a new design. Omitting it is an error — there is no implicit 'continue from wherever'.\",\n '',\n 'Returns: the first content part is JSON `{ revision, parent }` — store `revision` so you can pass it as `parent` on the next edit.',\n '',\n \"Optional: `title` (set on parent=null only — the design's display name) and `note` (a one-liner describing what this edit accomplished — purely descriptive, helps you re-ground after a rewind).\"\n].join('\\n');\n\ninterface EditArgs {\n parent: string | null;\n code: string;\n title?: string;\n note?: string;\n}\n\nconst EDIT_INPUT_SCHEMA = {\n type: 'object' as const,\n properties: {\n parent: {\n oneOf: [{ type: 'string' as const }, { type: 'null' as const }],\n description:\n 'Parent revision id from a previous edit (a string). To start a new design root, use the JSON null literal. REQUIRED — there is no implicit default.'\n },\n code: {\n type: 'string' as const,\n description:\n 'Async JS body. `engine` is in scope. Strict return contract per the handbook.'\n },\n title: {\n type: 'string' as const,\n description:\n 'Display name for the design. Set only when parent=null (creating a new design). For mid-chain renames use the `rename` tool.'\n },\n note: {\n type: 'string' as const,\n description:\n 'Freeform descriptive text — what this edit accomplished. Metadata only; never load-bearing.'\n }\n },\n required: ['parent', 'code'],\n additionalProperties: false\n};\n\nexport function createEditTool<E = unknown>(\n opts: CreateEditToolOptions<E>\n): CodesignMcpToolRegistration {\n const { store, session, onLeafWritten, renderThumbnail, fs, engineLock } =\n opts;\n return {\n name: 'edit',\n description: DESCRIPTION,\n inputSchema: EDIT_INPUT_SCHEMA,\n call: async (rawArgs) => {\n const args = (rawArgs ?? {}) as Partial<EditArgs>;\n if (!Object.hasOwn(args, 'parent')) {\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: 'edit: `parent` is required. Pass the revision id from a previous edit, or the JSON null literal (no quotes) for a new design root. See `handbook` for the rewind-recovery flow.'\n }\n ]\n };\n }\n if (args.parent === 'null') {\n // Some LLMs / MCP clients emit the JSON string \"null\" instead of the\n // bare null literal — a quoting slip, not a real revision id. Coerce it\n // rather than reject: this quoting nuance must never block creating a\n // new design root. (Stochastic, model-dependent; see edit.test.ts.)\n args.parent = null;\n }\n if (typeof args.code !== 'string') {\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: 'edit: `code` (string) is required.'\n }\n ]\n };\n }\n // The shared engine is loaded, mutated by user code, then saved across\n // several awaits below. Serialize the whole sequence so a concurrent\n // session sharing this engine can't swap the scene out mid-edit.\n return engineLock.runExclusive(async () => {\n // Pre-stage scene bytes for the session if parent is non-null.\n if (args.parent !== null) {\n const parentRev = await store.read(args.parent as string);\n await session.populate(args.parent as string, parentRev.scene);\n }\n const slot = await session.acquire(args.parent ?? null);\n let codeResult: unknown;\n try {\n const AsyncFunction = Object.getPrototypeOf(\n async () => {}\n ).constructor;\n const fn = new AsyncFunction('engine', args.code);\n codeResult = await fn(slot.engine);\n } catch (err) {\n session.markDirty(slot);\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: `edit: code threw — engine slot marked dirty (next edit pays one reload). ${\n err instanceof Error\n ? (err.stack ?? err.message)\n : String(err)\n }`\n }\n ]\n };\n }\n const adapter = (\n session as unknown as {\n opts: { adapter: { saveToString(e: E): Promise<string> } };\n }\n ).opts.adapter;\n const sceneBytes = await adapter.saveToString(slot.engine);\n const written = await store.write({\n scene: sceneBytes,\n parent: args.parent ?? null,\n title: args.title,\n note: args.note,\n code: args.code\n });\n session.commit(slot, written.id);\n if (renderThumbnail && fs) {\n try {\n const bytes = await renderThumbnail({\n revision: written.id,\n engine: slot.engine\n });\n const shard = written.id.slice(0, 2);\n const rest = written.id.slice(2);\n await fs.writeFile(`exports/${shard}/${rest}/preview.webp`, bytes);\n } catch {\n // best-effort; thumbnail failure must not poison the edit success path\n }\n }\n if (onLeafWritten) {\n const rootRevision =\n args.parent === null\n ? written.id\n : (await store.historyOf(written.id))[0].id;\n await onLeafWritten({ revision: written.id, rootRevision });\n }\n const envelope = { revision: written.id, parent: args.parent ?? null };\n const codeParts = normalizeResult(codeResult);\n return {\n content: [\n { type: 'text' as const, text: JSON.stringify(envelope) },\n ...codeParts\n ]\n };\n });\n }\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imgly/codesign-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Codesign MCP server: SYSTEM prompt, prompts, skills, design tools as MCP resources/prompts/tools.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://github.com/imgly/imgly-codesign/tree/main/packages/codesign-mcp",
|