@@ -147,11 +147,25 @@ exports.sendPrompt = async function (params) {
147147
148148 // Prepend selection context to the prompt if available
149149 let enrichedPrompt = prompt ;
150- if ( selectionContext && selectionContext . selectedText ) {
151- enrichedPrompt =
152- "The user has selected the following text in " + selectionContext . filePath +
153- " (lines " + selectionContext . startLine + "-" + selectionContext . endLine + "):\n" +
154- "```\n" + selectionContext . selectedText + "\n```\n\n" + prompt ;
150+ if ( selectionContext ) {
151+ if ( selectionContext . selectedText ) {
152+ enrichedPrompt =
153+ "The user has selected the following text in " + selectionContext . filePath +
154+ " (lines " + selectionContext . startLine + "-" + selectionContext . endLine + "):\n" +
155+ "```\n" + selectionContext . selectedText + "\n```\n\n" + prompt ;
156+ } else {
157+ let previewSnippet = "" ;
158+ if ( selectionContext . selectionPreview ) {
159+ previewSnippet = "\nPreview of selection:\n```\n" +
160+ selectionContext . selectionPreview + "\n```\n" ;
161+ }
162+ enrichedPrompt =
163+ "The user has selected lines " + selectionContext . startLine + "-" +
164+ selectionContext . endLine + " in " + selectionContext . filePath +
165+ ". Use the Read tool with offset=" + ( selectionContext . startLine - 1 ) +
166+ " and limit=" + ( selectionContext . endLine - selectionContext . startLine + 1 ) +
167+ " to read the selected content if needed." + previewSnippet + "\n" + prompt ;
168+ }
155169 }
156170
157171 // Run the query asynchronously — don't await here so we return requestId immediately
@@ -222,7 +236,9 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale)
222236 "mcp__phoenix-editor__getEditorState" ,
223237 "mcp__phoenix-editor__takeScreenshot" ,
224238 "mcp__phoenix-editor__execJsInLivePreview" ,
225- "mcp__phoenix-editor__controlEditor"
239+ "mcp__phoenix-editor__controlEditor" ,
240+ "mcp__phoenix-editor__resizeLivePreview" ,
241+ "mcp__phoenix-editor__wait"
226242 ] ,
227243 mcpServers : { "phoenix-editor" : editorMcpServer } ,
228244 permissionMode : "acceptEdits" ,
@@ -253,21 +269,33 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale)
253269 newText : input . tool_input . new_string
254270 } ;
255271 editCount ++ ;
272+ let editResult ;
256273 try {
257- await nodeConnector . execPeer ( "applyEditToBuffer" , edit ) ;
274+ editResult = await nodeConnector . execPeer ( "applyEditToBuffer" , edit ) ;
258275 } catch ( err ) {
259276 console . warn ( "[Phoenix AI] Failed to apply edit to buffer:" , err . message ) ;
277+ editResult = { applied : false , error : err . message } ;
260278 }
261279 nodeConnector . triggerPeer ( "aiToolEdit" , {
262280 requestId : requestId ,
263281 toolId : myToolId ,
264282 edit : edit
265283 } ) ;
284+ let reason ;
285+ if ( editResult && editResult . applied === false ) {
286+ reason = "Edit FAILED: " + ( editResult . error || "unknown error" ) ;
287+ } else {
288+ reason = "Edit applied successfully via Phoenix editor." ;
289+ if ( editResult && editResult . isLivePreviewRelated ) {
290+ reason += " The edited file is part of the active live preview." +
291+ " Reload when ready with execJsInLivePreview: `location.reload()`" ;
292+ }
293+ }
266294 return {
267295 hookSpecificOutput : {
268296 hookEventName : "PreToolUse" ,
269297 permissionDecision : "deny" ,
270- permissionDecisionReason : "Edit applied successfully via Phoenix editor."
298+ permissionDecisionReason : reason
271299 }
272300 } ;
273301 }
@@ -326,21 +354,33 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale)
326354 newText : input . tool_input . content
327355 } ;
328356 editCount ++ ;
357+ let writeResult ;
329358 try {
330- await nodeConnector . execPeer ( "applyEditToBuffer" , edit ) ;
359+ writeResult = await nodeConnector . execPeer ( "applyEditToBuffer" , edit ) ;
331360 } catch ( err ) {
332361 console . warn ( "[Phoenix AI] Failed to apply write to buffer:" , err . message ) ;
362+ writeResult = { applied : false , error : err . message } ;
333363 }
334364 nodeConnector . triggerPeer ( "aiToolEdit" , {
335365 requestId : requestId ,
336366 toolId : myToolId ,
337367 edit : edit
338368 } ) ;
369+ let reason ;
370+ if ( writeResult && writeResult . applied === false ) {
371+ reason = "Write FAILED: " + ( writeResult . error || "unknown error" ) ;
372+ } else {
373+ reason = "Write applied successfully via Phoenix editor." ;
374+ if ( writeResult && writeResult . isLivePreviewRelated ) {
375+ reason += " The written file is part of the active live preview." +
376+ " Reload when ready with execJsInLivePreview: `location.reload()`" ;
377+ }
378+ }
339379 return {
340380 hookSpecificOutput : {
341381 hookEventName : "PreToolUse" ,
342382 permissionDecision : "deny" ,
343- permissionDecisionReason : "Write applied successfully via Phoenix editor."
383+ permissionDecisionReason : reason
344384 }
345385 } ;
346386 }
0 commit comments