mirror of
https://github.com/stablyai/orca.git
synced 2026-11-01 01:27:35 +00:00
Post-merge cleanup after the agent-integration fixes: remove the unreachable Windows hook-script stdin drain epilogue; Windows statusline exits instead of draining outside an Orca pane; Codex CLI fork uses the \\?\-aware rollout path; WSL browser-network relay falls back to orcad's pinned Node (shared launcher revision stamp); stranded sleep records only drop for their own worktree; renames (hidden probe cwd, local Windows ConPTY helper).
70 lines
2.9 KiB
TypeScript
70 lines
2.9 KiB
TypeScript
import { posixCurlCommand } from '../agent-hooks/hook-post-command'
|
|
import {
|
|
buildWindowsAgentHookPostCommand,
|
|
getSharedManagedScriptPath
|
|
} from '../agent-hooks/installer-utils'
|
|
import {
|
|
buildPosixHookPayloadCapture,
|
|
buildPosixHookSpoolLines,
|
|
buildWindowsHookEnvironmentGuardLines
|
|
} from '../agent-hooks/hook-stdin-contract'
|
|
|
|
export function getManagedScriptFileName(): string {
|
|
return process.platform === 'win32' ? 'copilot-hook.cmd' : 'copilot-hook.sh'
|
|
}
|
|
|
|
export function getManagedScriptPath(): string {
|
|
return getSharedManagedScriptPath(getManagedScriptFileName())
|
|
}
|
|
|
|
export function getManagedScript(target: 'local' | 'posix' = 'local'): string {
|
|
if (target === 'local' && process.platform === 'win32') {
|
|
return [
|
|
'@echo off',
|
|
'setlocal',
|
|
// Why: Copilot consumes stdout for some hooks, so answer before any guard can exit.
|
|
'echo {}',
|
|
// Why: the direct registration passes the event as %1; the encoded fallback sets the env var.
|
|
'if not "%~1"=="" set "ORCA_COPILOT_HOOK_EVENT=%~1"',
|
|
// Why: refresh endpoint coordinates for PTYs surviving an Orca restart.
|
|
'if defined ORCA_AGENT_HOOK_ENDPOINT if exist "%ORCA_AGENT_HOOK_ENDPOINT%" call "%ORCA_AGENT_HOOK_ENDPOINT%" 2>nul',
|
|
...buildWindowsHookEnvironmentGuardLines(),
|
|
buildWindowsAgentHookPostCommand('copilot', [
|
|
' --data-urlencode "hookEventName=%ORCA_COPILOT_HOOK_EVENT%" ^'
|
|
]),
|
|
'exit /b 0',
|
|
''
|
|
].join('\r\n')
|
|
}
|
|
|
|
return [
|
|
'#!/bin/sh',
|
|
"printf '{}\\n'",
|
|
...buildPosixHookPayloadCapture(),
|
|
...buildPosixHookSpoolLines('copilot'),
|
|
// Answer Copilot before endpoint refresh, stdin parsing or posting can fail.
|
|
'if [ -n "$ORCA_AGENT_HOOK_ENDPOINT" ] && [ -r "$ORCA_AGENT_HOOK_ENDPOINT" ]; then',
|
|
' . "$ORCA_AGENT_HOOK_ENDPOINT" 2>/dev/null || :',
|
|
'fi',
|
|
'if [ -z "$ORCA_AGENT_HOOK_PORT" ] || [ -z "$ORCA_AGENT_HOOK_TOKEN" ] || [ -z "$ORCA_PANE_KEY" ]; then',
|
|
' spool_hook_event',
|
|
' exit 0',
|
|
'fi',
|
|
// Keep large tool payloads off curl's command line to avoid EDR false positives.
|
|
`printf '%s' "$payload" | ${posixCurlCommand()} -sS -X POST "http://127.0.0.1:\${ORCA_AGENT_HOOK_PORT}/hook/copilot" \\`,
|
|
' --connect-timeout 0.5 --max-time 1.5 \\',
|
|
' -H "Content-Type: application/x-www-form-urlencoded" \\',
|
|
' -H "X-Orca-Agent-Hook-Token: ${ORCA_AGENT_HOOK_TOKEN}" \\',
|
|
' --data-urlencode "paneKey=${ORCA_PANE_KEY}" \\',
|
|
' --data-urlencode "tabId=${ORCA_TAB_ID}" \\',
|
|
' --data-urlencode "launchToken=${ORCA_AGENT_LAUNCH_TOKEN}" \\',
|
|
' --data-urlencode "worktreeId=${ORCA_WORKTREE_ID}" \\',
|
|
' --data-urlencode "hookEventName=${ORCA_COPILOT_HOOK_EVENT}" \\',
|
|
' --data-urlencode "env=${ORCA_AGENT_HOOK_ENV}" \\',
|
|
' --data-urlencode "version=${ORCA_AGENT_HOOK_VERSION}" \\',
|
|
' --data-urlencode "payload@-" >/dev/null 2>&1 || spool_hook_event',
|
|
'exit 0',
|
|
''
|
|
].join('\n')
|
|
}
|