{"record":{"id":"78789936b0b0b53a","repo":"windmill-labs/windmill","slug":"no-script-code-available-to-edit-please-ensure-yo","errorCode":null,"errorMessage":"No script code available to edit. Please ensure you have a script open in the editor.","messagePattern":"No script code available to edit\\. Please ensure you have a script open in the editor\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/script/core.ts","lineNumber":781,"sourceCode":"\t\t\trequired: []\n\t\t}\n\t}\n}\n\nexport const editCodeToolWithDiff: Tool<ScriptChatHelpers> = {\n\tdef: EDIT_CODE_TOOL_WITH_DIFF,\n\tstreamArguments: true,\n\tshowDetails: true,\n\tshowFade: true,\n\tfn: async function ({ args, helpers, toolCallbacks, toolId }) {\n\t\tconst scriptOptions = helpers.getScriptOptions()\n\n\t\tif (!scriptOptions) {\n\t\t\ttoolCallbacks.setToolStatus(toolId, {\n\t\t\t\tcontent: 'No script available to edit',\n\t\t\t\terror: 'No script found in current context'\n\t\t\t})\n\t\t\tthrow new Error(\n\t\t\t\t'No script code available to edit. Please ensure you have a script open in the editor.'\n\t\t\t)\n\t\t}\n\n\t\tif (!args.diffs || !Array.isArray(args.diffs)) {\n\t\t\ttoolCallbacks.setToolStatus(toolId, {\n\t\t\t\tcontent: 'Invalid diffs provided',\n\t\t\t\terror: 'Diffs parameter is required and must be an array'\n\t\t\t})\n\t\t\tthrow new Error('Diffs parameter is required and must be an array')\n\t\t}\n\n\t\ttoolCallbacks.setToolStatus(toolId, { content: 'Applying code changes...' })\n\n\t\ttry {\n\t\t\t// Save old code\n\t\t\tconst oldCode = scriptOptions.code\n","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/script/core.ts#L763-L799","documentation":"The AI edit-code tool applies LLM-produced diffs to the script currently open in the editor. scriptOptions holds that code; when it is undefined (no script/flow editor context), the tool throws this error and reports 'No script found in current context' in the tool status.","triggerScenarios":"Calling editCodeTool from a chat with no script open — global chat on the home page, a chat on a non-editor page, or the editor lost its script binding (e.g. after navigation).","commonSituations":"Asking the copilot to 'fix my script' from the dashboard; script editor still loading when the tool runs; chat session disconnected from the editor context.","solutions":["Open the target script in the script editor before asking the AI to edit it","Verify the chat session is the one attached to the open editor (editor-scoped chat)","Reload the editor page if the script is visibly open but context was lost","Copy the code into the prompt or use a flow-scoped chat if editing within a flow step"],"exampleFix":"// before (global chat) — 'edit my script' -> throws\n// after\n// open /scripts/run/my_script, then ask in that page's chat\n'fix the error in this script'","handlingStrategy":"validation","validationCode":"if (!scriptOptions || typeof scriptOptions.code !== 'string') {\n  // no script open: ask the user to open the script editor first\n}","typeGuard":"function hasScriptContext(scriptOptions) {\n  return scriptOptions != null && typeof scriptOptions.code === 'string'\n}","tryCatchPattern":null,"preventionTips":["Only use edit tools from a chat bound to an open script editor","Re-open the editor after navigation if context seems lost","Fallback to pasting code into the prompt when no editor is available"],"tags":["script","ai-copilot","missing-context","frontend"],"backgroundTag":"missing-editor-context","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}