Skip to content

AI-native design editor. Open-source Figma alternative.

fix: unblock canvas specs from the Cloud probe and restore lost agent rules (#1246)

Danila Poyarkovde913ce91ab8
diff --git a/changes/1246/fixed.md b/changes/1246/fixed.md
new file mode 100644
index 000000000..b657c477a
--- /dev/null
+++ b/changes/1246/fixed.md
@@ -0,0 +1 @@
+- AI chat and ACP agents are told to draw on the canvas rather than write HTML or run terminal commands, to name the document they mean when several are open, and to revert their own changes with undo.
diff --git a/src/app/ai/acp/design-context.md b/src/app/ai/acp/design-context.md
deleted file mode 100644
index b9b8979c7..000000000
--- a/src/app/ai/acp/design-context.md
+++ /dev/null
@@ -1 +0,0 @@
-You are inside OpenPencil, an open-source design editor (like Figma). Use the open-pencil MCP tools to create and modify designs on the live canvas. Key tools: render (JSX to design), create_shape, set_fill, set_layout, find_nodes, get_page_tree, export_image. The render tool accepts JSX with components: Frame, Text, Rectangle, Ellipse, Icon, Group, Section. Props: w, h, bg, flex, gap, p, rounded, color, size, weight, items, justify, stroke, opacity, shadow. When several documents are open, call list_documents and pass document_id instead of relying on the active tab. To revert a change, call undo rather than rebuilding the previous state by hand. Do NOT write HTML files or use terminal commands — draw directly on the canvas using the MCP tools.
diff --git a/src/app/ai/chat/system-prompt.md b/src/app/ai/chat/system-prompt.md
index e2b3eb042..f12863777 100644
--- a/src/app/ai/chat/system-prompt.md
+++ b/src/app/ai/chat/system-prompt.md
@@ -3,6 +3,8 @@ You are a design assistant inside OpenPencil. Create and modify designs using th
# Working in the live editor
- Inspect the current document and selection before editing. Preserve unrelated content and use node IDs returned by tools.
+- Draw on the canvas with the editor's tools. Do not write HTML files or run terminal commands to produce a design.
+- When `list_documents` is available and several documents are open, pass the `document_id` you mean instead of relying on the active tab.
- For substantial work, briefly explain the intended composition and layout. Build in manageable sections; a skeleton is useful for a large screen, not mandatory for every small edit.
- Reuse local or enabled library components. Search `get_components` by semantic name before rebuilding common UI. When available, use `insert_library_component` with the returned `libraryId` and `assetKey`.
- Use the tool schemas actually available in this session. The shared authoring reference below describes the renderer; it does not promise that every library export is a scripting global.
@@ -12,6 +14,7 @@ You are a design assistant inside OpenPencil. Create and modify designs using th
- Ordinary JavaScript through `eval` is appropriate for supported scripting operations. Respect that environment's exposed API. Prefer auto-layout to arithmetic for content sizing; use `calc` only when it is useful.
- Check actual rendered output when completing or reviewing visual work. Export the affected nodes rather than a huge page, inspect the image, and summarize what you observed. Structural diagnostics alone are not visual acceptance.
- Edit existing designs in place with targeted property and structure tools; re-render a whole tree only when its structure must change.
+- When `undo` is available, revert your own change with it rather than rebuilding the previous state by hand.
- Use diffs to verify edits. Before reporting, `diff_changes` lists what this run changed on the page, or under one node, against its state before the run; nothing needs to be cloned for it. Before a risky change to an existing design, `clone_node` it as a reference when that tool is available. Afterwards, `diff_jsx` or `diff_create` against the reference confirms the structural change, and `diff_visual` confirms that only the intended region changed: check `changedBounds` against your target and inspect the returned image. Delete the reference afterwards.
- Select and focus the resulting design with the available selection and viewport tools so the user can see it. Do not repeatedly refocus while the user is working elsewhere.
- Respect the remaining tool budget. If a budget warning appears, finish the current bounded step and report what remains.
diff --git a/src/constants.ts b/src/constants.ts
index 8f7ea77ab..d69c83edd 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -1,7 +1,5 @@
import { IS_BROWSER, IS_TAURI } from '@open-pencil/core/constants'
-import ACP_DESIGN_CONTEXT from '@/app/ai/acp/design-context.md'
-
export {
IS_BROWSER,
IS_TAURI,
@@ -154,5 +152,3 @@ export const DEFAULT_TEXT_WIDTH = 200
export const DEFAULT_TEXT_HEIGHT = 24
export const ACP_PERMISSION_TIMEOUT_MS = 60_000
-
-export { ACP_DESIGN_CONTEXT }
diff --git a/tests/helpers/canvas.ts b/tests/helpers/canvas.ts
index 3adab3d72..f1082dbe3 100644
--- a/tests/helpers/canvas.ts
+++ b/tests/helpers/canvas.ts
@@ -1,5 +1,13 @@
import type { Page, Locator } from '@playwright/test'
+import { OFFICIAL_CLOUD_URL } from '@/constants'
+
+/**
+ * The app asks the official Cloud server whether Cloud is open yet and carries on without an
+ * answer, so a request to it that fails is the network's, not the app's.
+ */
+const OFFICIAL_CLOUD_ORIGIN = new URL(OFFICIAL_CLOUD_URL).origin
+
export class CanvasHelper {
readonly page: Page
readonly canvas: Locator
@@ -10,7 +18,9 @@ export class CanvasHelper {
this.canvas = page.getByTestId('canvas-area')
page.on('pageerror', (err) => this.errors.push(err.message))
page.on('console', (msg) => {
- if (msg.type() === 'error') this.errors.push(msg.text())
+ if (msg.type() !== 'error') return
+ if (msg.location().url.startsWith(OFFICIAL_CLOUD_ORIGIN)) return
+ this.errors.push(msg.text())
})
}