MCPcopy Create free account
hub / github.com/tiann/hapi / assertCodexLocalSupported

Function assertCodexLocalSupported

cli/src/codex/utils/codexVersion.ts:55–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55export function assertCodexLocalSupported(): void {
56 let output: string
57 const codexCommand = resolveCodexCommand()
58
59 const result = spawn.sync(codexCommand.command, [...codexCommand.args, '--version'], {
60 encoding: 'utf8',
61 env: withBunRuntimeEnv(),
62 windowsHide: process.platform === 'win32'
63 })
64
65 if (result.error) {
66 const maybeError = result.error as NodeJS.ErrnoException
67 const message = maybeError?.message ? ` ${maybeError.message}` : ''
68
69 if (maybeError?.code === 'ENOENT') {
70 throw new Error(
71 `${getLocalModeRequirementMessage()} Codex was not found on PATH. Please install or upgrade Codex and retry.`,
72 { cause: result.error }
73 )
74 }
75
76 throw new Error(
77 `Could not determine Codex CLI version.${message} ` +
78 `${getLocalModeRequirementMessage()} Please upgrade Codex and retry.`,
79 { cause: result.error }
80 )
81 }
82
83 if (result.status !== 0) {
84 const detail = result.stderr ? ` ${result.stderr.trim()}` : ''
85 throw new Error(
86 `Could not determine Codex CLI version.${detail} ` +
87 `${getLocalModeRequirementMessage()} Please upgrade Codex and retry.`
88 )
89 }
90
91 output = result.stdout.trim()
92
93 const version = parseCodexVersion(output)
94 if (!version) {
95 throw new Error(
96 `Could not determine Codex CLI version. ${getLocalModeRequirementMessage()} Please upgrade Codex and retry.`
97 )
98 }
99
100 if (!isCodexVersionAtLeast(version, MIN_CODEX_HOOKS_VERSION)) {
101 throw new Error(
102 `${getLocalModeRequirementMessage()} Detected: ${version}. Please upgrade Codex and retry.`
103 )
104 }
105}

Callers 3

dispatchLocalResumeFunction · 0.90
codex.tsFile · 0.90

Calls 5

resolveCodexCommandFunction · 0.90
withBunRuntimeEnvFunction · 0.90
parseCodexVersionFunction · 0.85
isCodexVersionAtLeastFunction · 0.85

Tested by

no test coverage detected