Skip to content

Commit be2dce7

Browse files
committed
feat(ai): add getEditorState hint and toggleLivePreview operation
Hint the AI to call getEditorState when asked about the current file. Add toggleLivePreview operation to controlEditor MCP tool.
1 parent 82307a3 commit be2dce7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src-node/claude-code-agent.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale,
364364
"multiple Edit calls to make targeted changes rather than rewriting the entire " +
365365
"file with Write. This is critical because Write replaces the entire file content " +
366366
"which is slow and loses undo history." +
367+
"\n\nWhen the user asks about the current file, open files, or what they are working on, " +
368+
"call getEditorState first — it returns the active file path, working set, cursor position, " +
369+
"and selection. Do NOT search the filesystem to answer these questions blindly." +
367370
"\n\nAlways use full absolute paths for all file operations (Read, Edit, Write, " +
368371
"controlEditor). Never use relative paths." +
369372
"\n\nWhen a tool response mentions the user has typed a clarification, immediately " +

src-node/mcp-editor-tools.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,19 @@ function createEditorMcpServer(sdkModule, nodeConnector, clarificationAccessors)
169169
"- close: Close a file (force, no save prompt). Params: filePath\n" +
170170
"- openInWorkingSet: Open a file and pin it to the working set. Params: filePath\n" +
171171
"- setSelection: Open a file and select a range. Params: filePath, startLine, startCh, endLine, endCh\n" +
172-
"- setCursorPos: Open a file and set cursor position. Params: filePath, line, ch",
172+
"- setCursorPos: Open a file and set cursor position. Params: filePath, line, ch\n" +
173+
"- toggleLivePreview: Show or hide the live preview panel. Params: show (boolean)",
173174
{
174175
operations: z.array(z.object({
175-
operation: z.enum(["open", "close", "openInWorkingSet", "setSelection", "setCursorPos"]),
176-
filePath: z.string().describe("Absolute path to the file"),
176+
operation: z.enum(["open", "close", "openInWorkingSet", "setSelection", "setCursorPos", "toggleLivePreview"]),
177+
filePath: z.string().optional().describe("Absolute path to the file (not required for toggleLivePreview)"),
177178
startLine: z.number().optional().describe("Start line (1-based) for setSelection"),
178179
startCh: z.number().optional().describe("Start column (1-based) for setSelection"),
179180
endLine: z.number().optional().describe("End line (1-based) for setSelection"),
180181
endCh: z.number().optional().describe("End column (1-based) for setSelection"),
181182
line: z.number().optional().describe("Line number (1-based) for setCursorPos"),
182-
ch: z.number().optional().describe("Column (1-based) for setCursorPos")
183+
ch: z.number().optional().describe("Column (1-based) for setCursorPos"),
184+
showPreview: z.boolean().optional().describe("true to show, false to hide live preview (for toggleLivePreview)")
183185
})).describe("Array of editor operations to execute sequentially")
184186
},
185187
async function (args) {

0 commit comments

Comments
 (0)