(args: string[])
| 1999 | } |
| 2000 | |
| 2001 | export async function bridgeMain(args: string[]): Promise<void> { |
| 2002 | const parsed = parseArgs(args) |
| 2003 | |
| 2004 | if (parsed.help) { |
| 2005 | await printHelp() |
| 2006 | return |
| 2007 | } |
| 2008 | if (parsed.error) { |
| 2009 | console.error(`Error: ${parsed.error}`) |
| 2010 | // eslint-disable-next-line custom-rules/no-process-exit |
| 2011 | process.exit(1) |
| 2012 | } |
| 2013 | |
| 2014 | const { |
| 2015 | verbose, |
| 2016 | sandbox, |
| 2017 | debugFile, |
| 2018 | sessionTimeoutMs, |
| 2019 | permissionMode, |
| 2020 | name, |
| 2021 | spawnMode: parsedSpawnMode, |
| 2022 | capacity: parsedCapacity, |
| 2023 | createSessionInDir: parsedCreateSessionInDir, |
| 2024 | sessionId: parsedSessionId, |
| 2025 | continueSession, |
| 2026 | } = parsed |
| 2027 | // Mutable so --continue can set it from the pointer file. The #20460 |
| 2028 | // resume flow below then treats it the same as an explicit --session-id. |
| 2029 | let resumeSessionId = parsedSessionId |
| 2030 | // When --continue found a pointer, this is the directory it came from |
| 2031 | // (may be a worktree sibling, not `dir`). On resume-flow deterministic |
| 2032 | // failure, clear THIS file so --continue doesn't keep hitting the same |
| 2033 | // dead session. Undefined for explicit --session-id (leaves pointer alone). |
| 2034 | let resumePointerDir: string | undefined |
| 2035 | |
| 2036 | const usedMultiSessionFeature = |
| 2037 | parsedSpawnMode !== undefined || |
| 2038 | parsedCapacity !== undefined || |
| 2039 | parsedCreateSessionInDir !== undefined |
| 2040 | |
| 2041 | // Validate permission mode early so the user gets an error before |
| 2042 | // the bridge starts polling for work. |
| 2043 | if (permissionMode !== undefined) { |
| 2044 | const { PERMISSION_MODES } = await import('../types/permissions.js') |
| 2045 | const valid: readonly string[] = PERMISSION_MODES |
| 2046 | if (!valid.includes(permissionMode)) { |
| 2047 | console.error( |
| 2048 | `Error: Invalid permission mode '${permissionMode}'. Valid modes: ${valid.join(', ')}`, |
| 2049 | ) |
| 2050 | // eslint-disable-next-line custom-rules/no-process-exit |
| 2051 | process.exit(1) |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | const dir = resolve('.') |
| 2056 | |
| 2057 | // The bridge fast-path bypasses init.ts, so we must enable config reading |
| 2058 | // before any code that transitively calls getGlobalConfig() |
no test coverage detected