Files
orca/src/main/opencode/status-plugin-post-source.ts
T
Neil f7b1f9d8be fix(opencode): select tmux status on the execution host
Track the attested tmux selected pane in the canonical status store and fence retired refreshes after asynchronous root resolution.

Fixes #10039.
2026-10-02 20:41:24 -07:00

50 lines
2.3 KiB
TypeScript

export function getStatusPluginPostSource(hookPathname: string): string[] {
return [
'async function post(hookEventName, extraProperties) {',
' // Why: resolve coords per post — the endpoint file may have been',
' // rewritten by a newer Orca since the last call. Pane/tab/worktree IDs',
' // stay on process.env because they are per-PTY (stable for the life of',
' // the OpenCode process), not per-Orca-instance.',
' const coords = resolveHookCoords();',
' const paneKey = process.env.ORCA_PANE_KEY;',
' if (!coords.port || !coords.token || !paneKey) return false;',
' const tmuxMatch = /^(.*),[0-9]+,[0-9]+$/.exec(process.env.TMUX || "");',
' const tmuxPane = process.env.TMUX_PANE;',
` const url = \`http://127.0.0.1:\${coords.port}${hookPathname}\`;`,
' const body = JSON.stringify({',
' paneKey,',
' ...(tmuxMatch && /^%[0-9]+$/.test(tmuxPane || "") ? { tmux: { socket: tmuxMatch[1], pane: tmuxPane } } : {}),',
' launchToken: process.env.ORCA_AGENT_LAUNCH_TOKEN || "",',
' tabId: process.env.ORCA_TAB_ID || "",',
' worktreeId: process.env.ORCA_WORKTREE_ID || "",',
' env: coords.env,',
' version: coords.version,',
// opencodeMajor is set only by the OpenCode 2 setup() path, never read from OpenCode's version.
' ...(reportingOpenCodeMajor ? { opencodeMajor: reportingOpenCodeMajor } : {}),',
' payload: { hook_event_name: hookEventName, ...(extraProperties || {}) },',
' });',
' const controller = new AbortController();',
' const timeout = setTimeout(() => controller.abort(), HOOK_POST_TIMEOUT_MS);',
' if (timeout.unref) timeout.unref();',
' try {',
' const response = await fetch(url, {',
' method: "POST",',
' headers: {',
' "Content-Type": "application/json",',
' "X-Orca-Agent-Hook-Token": coords.token,',
' },',
' body,',
' signal: controller.signal,',
' });',
' return response.ok;',
' } catch {',
' // Why: OpenCode session events must never fail the agent run just',
' // because Orca is unavailable or the local loopback request failed.',
' return false;',
' } finally {',
' clearTimeout(timeout);',
' }',
'}'
]
}