Skip to content

feat(ai): execJsInEditor + editorPreferences + editorDocs #2920

Merged
abose merged 3 commits into
mainfrom
ai
May 16, 2026
Merged

feat(ai): execJsInEditor + editorPreferences + editorDocs #2920
abose merged 3 commits into
mainfrom
ai

Conversation

@abose
Copy link
Copy Markdown
Member

@abose abose commented May 16, 2026

Three new MCP tools that broaden the AI's reach over the editor beyond the fixed controlEditor operations. Companion to phoenix-pro's browser handlers.

mcp-editor-tools.js:

  • execJsInEditor: caller-supplied JS evaluated in Phoenix's own JS space (parent window — distinct from execJsInLivePreview which targets the iframe). Same shape as execJsInLivePreview (code + optional timeoutMs, floored at 5000, default 10000, no upper limit). Description lists the __PR helpers and points the model at editorDocs before writing non-trivial JS, plus a hint to use takeScreenshot (with arbitrary CSS selector) to verify mutations visually.
  • editorPreferences: list / get / set with explicit scope. Description teaches user-friendly scope names ("system-wide" / "for this project" / "just for this session") and tells the model to PICK a sensible scope per pref nature instead of reflexively offering all three. No platform-specific paths in the description — purely API-level.
  • editorDocs: returns absolute apiDocsPath (the build-mirrored API reference) + apiDocsURL + featureDocsURL + sourceRepoURL. Tool DOES NOT fetch content — it's just a "where to look" index so the model Read / Greps the bundled docs and WebFetches the live ones.
  • takeScreenshot description rewritten with a clean binary selector rule (live preview vs everything else) plus an arbitrary-CSS- selector option for verifying execJsInEditor mutations.
  • getEditorState response now appends a fallback hint pointing the model at takeScreenshot for any UI question the JSON doesn't answer (Problems panel, sidebar, etc.).

claude-code-agent.js (system prompt + tool registration):

  • allowedTools + agents.researcher / agents.coder gain the three new mcp__phoenix-editor__ tool names.
  • New "live preview is" definition line so the model has a mental model of what the preview shows.
  • Broadened getEditorState trigger: ALWAYS call it first on any question that references the user's current work — not just "what file am I on" but also implicit-context phrasings like "the page", "this layout", "the nav bar", "scroll down on the page". Stops the model from blind whole-codebase grep when context is one tool call away.
  • Phoenix-vs-Claude-Code name-collision rule: when the user says "set / configure / change X" without naming a product, default to editorPreferences. Don't touch ~/.claude/, ~/.claude.json, or the built-in update-config skill unless the user explicitly mentions "Claude" / "Claude Code" / "SDK" / "agent". Skip and ask if genuinely ambiguous.
  • Per-tool entries for execJsInEditor, editorPreferences, editorDocs added to the tool list.

build/api-docs-generator.js + .gitignore:

  • copyApiDocsToSrcNode() mirrors docs/API-Reference/ → src-node/apiDocs/ in a finally block so a partial generation (e.g. one source file's jsdoc errored mid-batch) still ships whatever made it. Cross-platform via fs.cp + path.join.
  • /src-node/apiDocs added to root .gitignore.

strings.js: AI_CHAT_TOOL_EDITOR_JS ("Inspecting editor"), AI_CHAT_TOOL_EDITOR_PREFERENCES ("Editor preferences"), AI_CHAT_TOOL_EDITOR_DOCS ("Editor docs").

abose added 3 commits May 16, 2026 12:01
…ompt

Three new MCP tools that broaden the AI's reach over the editor
beyond the fixed controlEditor operations. Companion to phoenix-pro's
browser handlers.

mcp-editor-tools.js:
- execJsInEditor: caller-supplied JS evaluated in Phoenix's own JS
  space (parent window — distinct from execJsInLivePreview which
  targets the iframe). Same shape as execJsInLivePreview (code +
  optional timeoutMs, floored at 5000, default 10000, no upper limit).
  Description lists the __PR helpers and points the model at editorDocs
  before writing non-trivial JS, plus a hint to use takeScreenshot
  (with arbitrary CSS selector) to verify mutations visually.
- editorPreferences: list / get / set with explicit scope. Description
  teaches user-friendly scope names ("system-wide" / "for this project"
  / "just for this session") and tells the model to PICK a sensible
  scope per pref nature instead of reflexively offering all three.
  No platform-specific paths in the description — purely API-level.
- editorDocs: returns absolute apiDocsPath (the build-mirrored API
  reference) + apiDocsURL + featureDocsURL + sourceRepoURL. Tool DOES
  NOT fetch content — it's just a "where to look" index so the model
  Read / Greps the bundled docs and WebFetches the live ones.
- takeScreenshot description rewritten with a clean binary selector
  rule (live preview vs everything else) plus an arbitrary-CSS-
  selector option for verifying execJsInEditor mutations.
- getEditorState response now appends a fallback hint pointing the
  model at takeScreenshot for any UI question the JSON doesn't
  answer (Problems panel, sidebar, etc.).

claude-code-agent.js (system prompt + tool registration):
- allowedTools + agents.researcher / agents.coder gain the three new
  mcp__phoenix-editor__ tool names.
- New "live preview is" definition line so the model has a mental
  model of what the preview shows.
- Broadened getEditorState trigger: ALWAYS call it first on any
  question that references the user's current work — not just "what
  file am I on" but also implicit-context phrasings like "the page",
  "this layout", "the nav bar", "scroll down on the page". Stops the
  model from blind whole-codebase grep when context is one tool call
  away.
- Phoenix-vs-Claude-Code name-collision rule: when the user says
  "set / configure / change X" without naming a product, default to
  editorPreferences. Don't touch ~/.claude/, ~/.claude.json, or the
  built-in update-config skill unless the user explicitly mentions
  "Claude" / "Claude Code" / "SDK" / "agent". Skip and ask if
  genuinely ambiguous.
- Per-tool entries for execJsInEditor, editorPreferences, editorDocs
  added to the tool list.

build/api-docs-generator.js + .gitignore:
- copyApiDocsToSrcNode() mirrors docs/API-Reference/ →
  src-node/apiDocs/ in a finally block so a partial generation (e.g.
  one source file's jsdoc errored mid-batch) still ships whatever
  made it. Cross-platform via fs.cp + path.join.
- /src-node/apiDocs added to root .gitignore.

strings.js: AI_CHAT_TOOL_EDITOR_JS ("Inspecting editor"),
AI_CHAT_TOOL_EDITOR_PREFERENCES ("Editor preferences"),
AI_CHAT_TOOL_EDITOR_DOCS ("Editor docs").
@abose abose merged commit a5fb5e2 into main May 16, 2026
11 of 18 checks passed
@abose abose deleted the ai branch May 16, 2026 07:43
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant