{"record":{"id":"ee0ac1dce144c280","repo":"Hmbown/CodeWhale","slug":"select-text-needs-an-element-target-type-element-index-from","errorCode":null,"errorMessage":"select_text needs an element target — {type:'element',index} from get_app_state","messagePattern":"select_text needs an element target — (.+?) from get_app_state","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/darwin.mjs","lineNumber":1182,"sourceCode":"        const value = String(args.value ?? \"\");\n        await native(\"focus_element\", { target: args.target });\n        // cmd+a through the record channel: menu key equivalents only\n        // validate against a key window, which the lease provides. bg_key\n        // posts a complete press (down and up); the `down` field is unused.\n        await native(\"bg_key\", { code: 0, flags: 1 << 20 });\n        await new Promise((r) => setTimeout(r, 60));\n        await native(\"type\", { text: value });\n        const back = await native(\"get_value\", { target: args.target });\n        const verified = back?.value === value;\n        return { action_sent: true, strategy: \"focus-type-replace\", role: back?.role ?? null,\n                 after: back?.value ?? null, verified,\n                 ...(verified ? {} : { note: \"replacement did not verify against the control's own value; observe before relying on it\" }) };\n      }\n    },\n    focus: (args = {}) => native(\"focus_element\", args),\n    get_value: (args = {}) => native(\"get_value\", args),\n    select_text: async (args = {}) => {\n      if (args.target?.type !== \"element\") throw new ExecError(\"select_text needs an element target — {type:'element',index} from get_app_state\");\n      return native(\"select_text\", args);\n    },\n    perform_action: async (args = {}) => {\n      if (args.target?.type !== \"element\") throw new ExecError(\"perform_action needs an element target — {type:'element',index} from get_app_state\");\n      return native(\"perform_action\", args);\n    },\n    invoke_menu: async ({ path: menuPath } = {}) => invokeMenu(menuPath),\n    app_script: appScript,\n    read_clipboard: readClipboard,\n    write_clipboard: writeClipboard,\n    cursor_position: cursorPosition,\n    recordingStart,\n    recordingStop,\n    recordingStatus,\n    recordingList,\n    closeSession,\n    list_sessions: async () => ({\n      via: \"direct\",","sourceCodeStart":1164,"sourceCodeEnd":1200,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/darwin.mjs#L1164-L1200","documentation":"The macOS computer-use backend's select_text only accepts a semantic element target ({type:'element', index}) obtained from get_app_state. Passing a coordinate target, no target, or a target typed as something else is rejected with this ExecError so the request is not silently misinterpreted. It is a fail-fast argument contract check before delegating to the native bridge.","triggerScenarios":"Calling select_text({}) with no args, select_text({target:{type:'coordinate',...}}), select_text({target:{type:'text',...}}), or omitting target entirely on the darwin backend.","commonSituations":"Agents reusing a click-style coordinate target for select_text; tool callers copying args between select_text and coordinate-based actions; older code written before element targets were required.","solutions":["Call get_app_state first and pass {target:{type:'element', index:<i>}} using an index from that snapshot.","If you only have coordinates, re-observe with get_app_state to resolve the element instead of guessing.","Wrap the call in try/catch and fall back to get_app_state + retry when the target type is wrong."],"exampleFix":"// before\nawait backend.select_text({ target: { type: 'coordinate', x: 120, y: 40 } });\n// after\nconst state = await backend.get_app_state();\nawait backend.select_text({ target: { type: 'element', index: state.elements.findIndex(e => e.role === 'textArea') } });","handlingStrategy":"validation","validationCode":"if (!args || args.target?.type !== 'element' || !Number.isInteger(args.target.index)) throw new TypeError('select_text requires {target:{type:\"element\", index}} from get_app_state');","typeGuard":"const isElementTarget = (t) => !!t && typeof t === 'object' && t.type === 'element' && Number.isInteger(t.index);","tryCatchPattern":"try { await backend.select_text(args); } catch (e) { if (String(e.message).includes('needs an element target')) { const s = await backend.get_app_state(); await backend.select_text({ target: { type: 'element', index: s.elements.findIndex(el => el.focused || el.role === 'textArea') } }); } else throw e; }","preventionTips":["Always call get_app_state immediately before element-targeted actions.","Centralize element-target construction in a helper that asserts the shape.","Never reuse coordinate targets for semantic actions."],"tags":["automation","argument-validation","element-target"],"backgroundTag":"invalid-argument-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}