@lesliechan721/aw 0.1.0-beta.67 → 0.1.0-beta.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/commands/options.d.ts +0 -1
- package/dist/src/commands/options.js +0 -3
- package/dist/src/commands/options.js.map +1 -1
- package/dist/src/commands/rebuild-command.d.ts +1 -2
- package/dist/src/commands/rebuild-command.js +60 -48
- package/dist/src/commands/rebuild-command.js.map +1 -1
- package/dist/src/commands/status-v6.d.ts +6 -1
- package/dist/src/commands/status-v6.js +24 -6
- package/dist/src/commands/status-v6.js.map +1 -1
- package/dist/src/commands/write-commands.js +2 -8
- package/dist/src/commands/write-commands.js.map +1 -1
- package/dist/src/index.d.ts +1 -26
- package/dist/src/index.js +1 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/output/command-receipt.js +4 -4
- package/dist/src/output/command-receipt.js.map +1 -1
- package/dist/src/recovery/coordinator.d.ts +0 -1
- package/dist/src/recovery/coordinator.js +2 -3
- package/dist/src/recovery/coordinator.js.map +1 -1
- package/dist/src/recovery/joint-coordinator.js +2 -2
- package/dist/src/recovery/joint-coordinator.js.map +1 -1
- package/dist/src/recovery/status.js +2 -1
- package/dist/src/recovery/status.js.map +1 -1
- package/dist/src/tui/controller.d.ts +3 -2
- package/dist/src/tui/controller.js +13 -16
- package/dist/src/tui/controller.js.map +1 -1
- package/dist/src/tui/diagnostic-projection.js +1 -1
- package/dist/src/tui/diagnostic-projection.js.map +1 -1
- package/dist/src/tui/operation-review-planner.js +28 -21
- package/dist/src/tui/operation-review-planner.js.map +1 -1
- package/dist/src/types.d.ts +0 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/codex-executable-discovery.d.ts +26 -0
- package/dist/src/utils/codex-executable-discovery.js +397 -0
- package/dist/src/utils/codex-executable-discovery.js.map +1 -0
- package/dist/src/utils/codex-manager.d.ts +19 -36
- package/dist/src/utils/codex-manager.js +79 -686
- package/dist/src/utils/codex-manager.js.map +1 -1
- package/dist/src/utils/codex-native-observation.d.ts +1 -1
- package/dist/src/utils/codex-native-observation.js +5 -6
- package/dist/src/utils/codex-native-observation.js.map +1 -1
- package/dist/src/utils/native-cli.d.ts +1 -2
- package/dist/src/utils/native-cli.js +2 -1
- package/dist/src/utils/native-cli.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { tryParseStrictSemVer } from './manifest.js';
|
|
8
|
-
import { getDefaultNativeCliRunner, runNativeCli, } from './native-cli.js';
|
|
9
|
-
import { getCodexHome, readEnvironmentValue, resolveAwHome } from './state-paths.js';
|
|
10
|
-
export const MANAGED_CODEX_PACKAGE_NAME = '@openai/codex';
|
|
11
|
-
export const MANAGED_CODEX_VERSION = '0.151.0';
|
|
12
|
-
export const MANAGED_CODEX_REGISTRY = 'https://registry.npmjs.org/';
|
|
13
|
-
export const MANAGED_CODEX_MARKER_FILE = '.aw-managed-runtime.json';
|
|
1
|
+
import { DEFAULT_AGENT_VERSION_PROBE_TIMEOUT_MS } from '../constants.js';
|
|
2
|
+
import { extractStrictSemVerTokenFromVersionOutput, getCodexOperationRequirement } from './agent-version.js';
|
|
3
|
+
import { discoverCodexExecutables, rethrowFatalError, } from './codex-executable-discovery.js';
|
|
4
|
+
import { compareStrictSemVer } from './manifest.js';
|
|
5
|
+
import { runNativeCli } from './native-cli.js';
|
|
6
|
+
import { getCodexHome } from './state-paths.js';
|
|
14
7
|
export class CodexManagerError extends Error {
|
|
15
8
|
code;
|
|
16
9
|
constructor(code, detail) {
|
|
@@ -19,710 +12,110 @@ export class CodexManagerError extends Error {
|
|
|
19
12
|
this.code = code;
|
|
20
13
|
}
|
|
21
14
|
}
|
|
22
|
-
const
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const arch = options.arch ?? process.arch;
|
|
27
|
-
return path.join(path.resolve(resolveAwHome(env)), 'runtimes', 'codex', MANAGED_CODEX_VERSION, `${platform}-${arch}`);
|
|
15
|
+
const MISSING_DIAGNOSTIC = 'No Codex CLI was found in PATH or a supported Codex App. Install Codex CLI or App, repair PATH, and retry.';
|
|
16
|
+
function unsupportedDiagnostic(requiredMinVersion, detectedVersion) {
|
|
17
|
+
const detected = detectedVersion ? ` Detected ${detectedVersion}.` : '';
|
|
18
|
+
return `The Codex CLI is unsupported or its version could not be confirmed.${detected} Required minimum: ${requiredMinVersion}. Install or upgrade Codex CLI or App, repair its launcher or PATH, and retry.`;
|
|
28
19
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function managedRuntimeMarker(options) {
|
|
39
|
-
return {
|
|
40
|
-
schemaVersion: 1,
|
|
41
|
-
owner: 'aw',
|
|
42
|
-
packageName: MANAGED_CODEX_PACKAGE_NAME,
|
|
43
|
-
version: MANAGED_CODEX_VERSION,
|
|
44
|
-
platform: options.platform ?? process.platform,
|
|
45
|
-
arch: options.arch ?? process.arch,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function managedLauncher(runtimeRoot) {
|
|
49
|
-
return path.join(runtimeRoot, 'node_modules', '@openai', 'codex', 'bin', 'codex.js');
|
|
50
|
-
}
|
|
51
|
-
function managedPackageRoot(runtimeRoot) {
|
|
52
|
-
return path.join(runtimeRoot, 'node_modules', '@openai', 'codex');
|
|
53
|
-
}
|
|
54
|
-
function managedPackageJson(runtimeRoot) {
|
|
55
|
-
return path.join(runtimeRoot, 'node_modules', '@openai', 'codex', 'package.json');
|
|
56
|
-
}
|
|
57
|
-
function managerForRuntime(runtimeRoot, launcher, execPath) {
|
|
58
|
-
return {
|
|
59
|
-
kind: 'aw-managed',
|
|
60
|
-
version: MANAGED_CODEX_VERSION,
|
|
61
|
-
command: execPath,
|
|
62
|
-
argsPrefix: [launcher],
|
|
63
|
-
runtimeRoot,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function isPathWithin(rootPath, targetPath) {
|
|
67
|
-
const relative = path.relative(rootPath, targetPath);
|
|
68
|
-
return relative === '' || (!path.isAbsolute(relative) && relative !== '..'
|
|
69
|
-
&& !relative.startsWith(`..${path.sep}`));
|
|
70
|
-
}
|
|
71
|
-
async function inspectCanonicalManagedPackagePaths(runtimeRoot) {
|
|
72
|
-
const runtimeStats = await lstatOrUndefined(runtimeRoot);
|
|
73
|
-
if (!runtimeStats?.isDirectory() || runtimeStats.isSymbolicLink()) {
|
|
74
|
-
return { state: 'unsafe', diagnostic: 'The managed runtime root is not a regular directory.' };
|
|
75
|
-
}
|
|
76
|
-
let canonicalRuntimeRoot;
|
|
77
|
-
try {
|
|
78
|
-
canonicalRuntimeRoot = await fs.realpath(runtimeRoot);
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return { state: 'incomplete' };
|
|
82
|
-
}
|
|
83
|
-
const candidates = [
|
|
84
|
-
['package root', managedPackageRoot(runtimeRoot), 'directory'],
|
|
85
|
-
['package.json', managedPackageJson(runtimeRoot), 'file'],
|
|
86
|
-
['launcher', managedLauncher(runtimeRoot), 'file'],
|
|
87
|
-
];
|
|
88
|
-
const canonicalPaths = [];
|
|
89
|
-
let canonicalPackageRoot;
|
|
90
|
-
for (const [label, candidatePath, expectedKind] of candidates) {
|
|
91
|
-
let canonicalPath;
|
|
20
|
+
/** Discovers PATH and supported Apps without writing to the host or AW state. */
|
|
21
|
+
export async function inspectSystemCodex(options) {
|
|
22
|
+
const requiredMinVersion = options.operationRequirement.minimumVersion;
|
|
23
|
+
const discovery = await discoverCodexExecutables(options);
|
|
24
|
+
const diagnostics = [...discovery.diagnostics];
|
|
25
|
+
let selected;
|
|
26
|
+
for (const candidate of discovery.candidates) {
|
|
27
|
+
options.signal?.throwIfAborted();
|
|
28
|
+
let version = null;
|
|
92
29
|
try {
|
|
93
|
-
|
|
30
|
+
const env = options.env ?? process.env;
|
|
31
|
+
const result = await runNativeCli({
|
|
32
|
+
command: candidate.manager.command,
|
|
33
|
+
args: [...candidate.manager.argsPrefix, '--version'],
|
|
34
|
+
agentKind: 'codex',
|
|
35
|
+
cwd: options.cwd,
|
|
36
|
+
env: { ...env, CODEX_HOME: getCodexHome(env) },
|
|
37
|
+
timeoutMs: DEFAULT_AGENT_VERSION_PROBE_TIMEOUT_MS,
|
|
38
|
+
signal: options.signal,
|
|
39
|
+
}, options.runner);
|
|
40
|
+
if (result.exitCode === 0) {
|
|
41
|
+
version = extractStrictSemVerTokenFromVersionOutput(`${result.stdout}\n${result.stderr}`);
|
|
42
|
+
}
|
|
94
43
|
}
|
|
95
44
|
catch (error) {
|
|
96
|
-
|
|
97
|
-
return { state: 'incomplete' };
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
const containmentRoot = canonicalPackageRoot ?? canonicalRuntimeRoot;
|
|
101
|
-
if (!isPathWithin(containmentRoot, canonicalPath)) {
|
|
102
|
-
return {
|
|
103
|
-
state: 'unsafe',
|
|
104
|
-
diagnostic: `The managed Codex ${label} resolves outside its managed ${canonicalPackageRoot ? 'package root' : 'runtime'}.`,
|
|
105
|
-
};
|
|
45
|
+
rethrowFatalError(error);
|
|
106
46
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
47
|
+
if (!version) {
|
|
48
|
+
const message = 'A Codex CLI candidate failed its version query or returned an invalid version and was excluded.';
|
|
49
|
+
if (!diagnostics.includes(message))
|
|
50
|
+
diagnostics.push(message);
|
|
51
|
+
continue;
|
|
110
52
|
}
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
state: 'complete',
|
|
117
|
-
paths: {
|
|
118
|
-
packageJson: canonicalPaths[1],
|
|
119
|
-
launcher: canonicalPaths[2],
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
async function lstatOrUndefined(targetPath) {
|
|
124
|
-
try {
|
|
125
|
-
return await fs.lstat(targetPath);
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
if (error.code === 'ENOENT')
|
|
129
|
-
return undefined;
|
|
130
|
-
throw error;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async function inspectRegularDirectoryChain(paths) {
|
|
134
|
-
for (const targetPath of paths) {
|
|
135
|
-
const stats = await lstatOrUndefined(targetPath);
|
|
136
|
-
if (!stats)
|
|
137
|
-
return { state: 'missing' };
|
|
138
|
-
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
139
|
-
return {
|
|
140
|
-
state: 'blocked',
|
|
141
|
-
diagnostic: `The managed runtime path chain contains a non-directory or symbolic link: ${targetPath}.`,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return { state: 'complete' };
|
|
146
|
-
}
|
|
147
|
-
async function ensureRegularManagedRuntimeAncestors(options) {
|
|
148
|
-
for (const targetPath of managedRuntimeAncestors(options)) {
|
|
149
|
-
const stats = await lstatOrUndefined(targetPath);
|
|
150
|
-
if (!stats)
|
|
151
|
-
await fs.mkdir(targetPath);
|
|
152
|
-
const current = await lstatOrUndefined(targetPath);
|
|
153
|
-
if (!current?.isDirectory() || current.isSymbolicLink()) {
|
|
154
|
-
throw new Error(`The managed runtime path chain is not a regular directory: ${targetPath}.`);
|
|
53
|
+
if (candidate.expectedVersion && version !== candidate.expectedVersion) {
|
|
54
|
+
const message = 'A Windows npm Codex launcher did not match its package version and was excluded. Repair the npm installation.';
|
|
55
|
+
if (!diagnostics.includes(message))
|
|
56
|
+
diagnostics.push(message);
|
|
57
|
+
continue;
|
|
155
58
|
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
async function assertManagedStoreDirectory(options) {
|
|
159
|
-
const storeRoot = path.join(path.resolve(resolveAwHome(options.env ?? process.env)), 'runtimes', '.pnpm-store');
|
|
160
|
-
const stats = await lstatOrUndefined(storeRoot);
|
|
161
|
-
if (!stats) {
|
|
162
|
-
await fs.mkdir(storeRoot);
|
|
163
|
-
}
|
|
164
|
-
else if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
165
|
-
throw new Error('The AW-managed pnpm store path is not a regular directory.');
|
|
166
|
-
}
|
|
167
|
-
const current = await lstatOrUndefined(storeRoot);
|
|
168
|
-
if (!current?.isDirectory() || current.isSymbolicLink()) {
|
|
169
|
-
throw new Error('The AW-managed pnpm store path is not a regular directory.');
|
|
170
|
-
}
|
|
171
|
-
return storeRoot;
|
|
172
|
-
}
|
|
173
|
-
function isExpectedMarker(value, expected) {
|
|
174
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
175
|
-
return false;
|
|
176
|
-
const marker = value;
|
|
177
|
-
return marker.schemaVersion === expected.schemaVersion
|
|
178
|
-
&& marker.owner === expected.owner
|
|
179
|
-
&& marker.packageName === expected.packageName
|
|
180
|
-
&& marker.version === expected.version
|
|
181
|
-
&& marker.platform === expected.platform
|
|
182
|
-
&& marker.arch === expected.arch;
|
|
183
|
-
}
|
|
184
|
-
async function runManagedVersionCheck(launcher, options) {
|
|
185
|
-
const runner = options.runner ?? getDefaultNativeCliRunner();
|
|
186
|
-
const execPath = options.execPath ?? process.execPath;
|
|
187
|
-
const env = options.env ?? process.env;
|
|
188
|
-
try {
|
|
189
|
-
const result = await runNativeCli({
|
|
190
|
-
command: execPath,
|
|
191
|
-
args: [launcher, '--version'],
|
|
192
|
-
agentKind: 'codex',
|
|
193
|
-
cwd: options.cwd,
|
|
194
|
-
env: { ...env, CODEX_HOME: getCodexHome(env) },
|
|
195
|
-
}, runner);
|
|
196
|
-
if (result.exitCode !== 0)
|
|
197
|
-
return undefined;
|
|
198
|
-
return extractStrictSemVerTokenFromVersionOutput(`${result.stdout}\n${result.stderr}`)
|
|
199
|
-
?? undefined;
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async function inspectManagedCodexRuntime(options) {
|
|
206
|
-
const runtimeRoot = managedRuntimeRoot(options);
|
|
207
|
-
try {
|
|
208
|
-
const pathChain = await inspectRegularDirectoryChain([
|
|
209
|
-
...managedRuntimeAncestors(options),
|
|
210
|
-
runtimeRoot,
|
|
211
|
-
]);
|
|
212
|
-
if (pathChain.state === 'missing')
|
|
213
|
-
return { state: 'absent' };
|
|
214
|
-
if (pathChain.state === 'blocked')
|
|
215
|
-
return pathChain;
|
|
216
|
-
const markerPath = path.join(runtimeRoot, MANAGED_CODEX_MARKER_FILE);
|
|
217
|
-
const markerStats = await lstatOrUndefined(markerPath);
|
|
218
|
-
if (!markerStats?.isFile() || markerStats.isSymbolicLink()) {
|
|
219
|
-
return { state: 'blocked', diagnostic: 'The managed runtime has no valid AW owner marker.' };
|
|
220
|
-
}
|
|
221
|
-
const marker = await fs.readJson(markerPath).catch(() => undefined);
|
|
222
|
-
if (!isExpectedMarker(marker, managedRuntimeMarker(options))) {
|
|
223
|
-
return { state: 'blocked', diagnostic: 'The managed runtime has an invalid AW owner marker.' };
|
|
224
|
-
}
|
|
225
|
-
const packagePaths = await inspectCanonicalManagedPackagePaths(runtimeRoot);
|
|
226
|
-
if (packagePaths.state === 'incomplete') {
|
|
227
|
-
return { state: 'rebuildable', diagnostic: 'The AW-owned managed runtime is incomplete.' };
|
|
228
|
-
}
|
|
229
|
-
if (packagePaths.state === 'unsafe') {
|
|
230
|
-
return { state: 'blocked', diagnostic: packagePaths.diagnostic };
|
|
231
|
-
}
|
|
232
|
-
const packageJson = await fs.readJson(packagePaths.paths.packageJson).catch(() => undefined);
|
|
233
|
-
if (packageJson?.name !== MANAGED_CODEX_PACKAGE_NAME
|
|
234
|
-
|| packageJson.version !== MANAGED_CODEX_VERSION) {
|
|
235
|
-
return { state: 'rebuildable', diagnostic: 'The AW-owned managed runtime package does not match the pinned package.' };
|
|
236
|
-
}
|
|
237
|
-
const detectedVersion = await runManagedVersionCheck(packagePaths.paths.launcher, options);
|
|
238
|
-
if (detectedVersion !== MANAGED_CODEX_VERSION) {
|
|
239
|
-
return { state: 'rebuildable', diagnostic: 'The AW-owned managed runtime failed its version self-check.' };
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
state: 'valid',
|
|
243
|
-
manager: managerForRuntime(runtimeRoot, packagePaths.paths.launcher, options.execPath ?? process.execPath),
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
return {
|
|
248
|
-
state: 'blocked',
|
|
249
|
-
diagnostic: `The managed runtime cannot be inspected: ${error instanceof Error ? error.message : String(error)}`,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async function assertAwOwnedRuntimeBeforeReplacement(runtimeRoot, options) {
|
|
254
|
-
const chain = await inspectRegularDirectoryChain([
|
|
255
|
-
...managedRuntimeAncestors(options),
|
|
256
|
-
runtimeRoot,
|
|
257
|
-
]);
|
|
258
|
-
if (chain.state !== 'complete') {
|
|
259
|
-
throw new Error(chain.state === 'blocked' ? chain.diagnostic : 'The managed runtime disappeared before replacement.');
|
|
260
|
-
}
|
|
261
|
-
const markerPath = path.join(runtimeRoot, MANAGED_CODEX_MARKER_FILE);
|
|
262
|
-
const markerStats = await lstatOrUndefined(markerPath);
|
|
263
|
-
const marker = markerStats?.isFile() && !markerStats.isSymbolicLink()
|
|
264
|
-
? await fs.readJson(markerPath).catch(() => undefined)
|
|
265
|
-
: undefined;
|
|
266
|
-
if (!isExpectedMarker(marker, managedRuntimeMarker(options))) {
|
|
267
|
-
throw new Error('The managed runtime owner marker changed before replacement.');
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
async function resolveBundledPnpmEntry() {
|
|
271
|
-
let packageJsonPath;
|
|
272
|
-
try {
|
|
273
|
-
packageJsonPath = requireFromCli.resolve('pnpm');
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
return undefined;
|
|
277
|
-
}
|
|
278
|
-
const packageJson = await fs.readJson(packageJsonPath).catch(() => undefined);
|
|
279
|
-
if (packageJson?.name !== 'pnpm' || packageJson.version !== '10.33.0')
|
|
280
|
-
return undefined;
|
|
281
|
-
const entry = path.join(path.dirname(packageJsonPath), 'bin', 'pnpm.cjs');
|
|
282
|
-
const stats = await lstatOrUndefined(entry);
|
|
283
|
-
return stats?.isFile() && !stats.isSymbolicLink() ? entry : undefined;
|
|
284
|
-
}
|
|
285
|
-
function neutralPnpmEnv(env, userConfigPath) {
|
|
286
|
-
const result = {};
|
|
287
|
-
for (const [key, value] of Object.entries(env)) {
|
|
288
|
-
if (!key.toLowerCase().startsWith('npm_config_'))
|
|
289
|
-
result[key] = value;
|
|
290
|
-
}
|
|
291
|
-
result.npm_config_userconfig = userConfigPath;
|
|
292
|
-
result.NPM_CONFIG_USERCONFIG = userConfigPath;
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
|
-
async function validateAcquiredRuntime(stagingRoot, options) {
|
|
296
|
-
const packagePaths = await inspectCanonicalManagedPackagePaths(stagingRoot);
|
|
297
|
-
const packageJson = packagePaths.state === 'complete'
|
|
298
|
-
? await fs.readJson(packagePaths.paths.packageJson).catch(() => undefined)
|
|
299
|
-
: undefined;
|
|
300
|
-
if (packagePaths.state !== 'complete'
|
|
301
|
-
|| packageJson?.name !== MANAGED_CODEX_PACKAGE_NAME
|
|
302
|
-
|| packageJson.version !== MANAGED_CODEX_VERSION) {
|
|
303
|
-
throw new Error('The installed Codex package does not match the pinned package and launcher contract.');
|
|
304
|
-
}
|
|
305
|
-
const runner = options.runner ?? getDefaultNativeCliRunner();
|
|
306
|
-
const execPath = options.execPath ?? process.execPath;
|
|
307
|
-
const env = options.env ?? process.env;
|
|
308
|
-
const invocationBase = {
|
|
309
|
-
command: execPath,
|
|
310
|
-
agentKind: 'codex',
|
|
311
|
-
cwd: options.cwd,
|
|
312
|
-
env: { ...env, CODEX_HOME: getCodexHome(env) },
|
|
313
|
-
};
|
|
314
|
-
const versionResult = await runNativeCli({
|
|
315
|
-
...invocationBase,
|
|
316
|
-
args: [packagePaths.paths.launcher, '--version'],
|
|
317
|
-
}, runner);
|
|
318
|
-
const detectedVersion = extractStrictSemVerTokenFromVersionOutput(`${versionResult.stdout}\n${versionResult.stderr}`);
|
|
319
|
-
if (versionResult.exitCode !== 0 || detectedVersion !== MANAGED_CODEX_VERSION) {
|
|
320
|
-
throw new Error('The installed Codex package failed its version self-check.');
|
|
321
|
-
}
|
|
322
|
-
const helpResult = await runNativeCli({
|
|
323
|
-
...invocationBase,
|
|
324
|
-
args: [packagePaths.paths.launcher, 'plugin', '--help'],
|
|
325
|
-
}, runner);
|
|
326
|
-
if (helpResult.exitCode !== 0) {
|
|
327
|
-
throw new Error('The installed Codex package failed its plugin help self-check.');
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async function adoptManagedRuntime(stagingRoot, options) {
|
|
331
|
-
const runtimeRoot = managedRuntimeRoot(options);
|
|
332
|
-
const current = await inspectManagedCodexRuntime(options);
|
|
333
|
-
if (current.state === 'valid')
|
|
334
|
-
return current.manager;
|
|
335
|
-
if (current.state === 'blocked')
|
|
336
|
-
throw new Error(current.diagnostic);
|
|
337
|
-
if (current.state === 'absent') {
|
|
338
|
-
const parentChain = await inspectRegularDirectoryChain(managedRuntimeAncestors(options));
|
|
339
|
-
if (parentChain.state !== 'complete' || await lstatOrUndefined(runtimeRoot)) {
|
|
340
|
-
throw new Error('The managed runtime path changed before adoption.');
|
|
341
|
-
}
|
|
342
|
-
await fs.rename(stagingRoot, runtimeRoot);
|
|
343
|
-
const packagePaths = await inspectCanonicalManagedPackagePaths(runtimeRoot);
|
|
344
|
-
if (packagePaths.state !== 'complete') {
|
|
345
|
-
throw new Error('The managed runtime changed during adoption.');
|
|
346
|
-
}
|
|
347
|
-
return managerForRuntime(runtimeRoot, packagePaths.paths.launcher, options.execPath ?? process.execPath);
|
|
348
|
-
}
|
|
349
|
-
const backupRoot = path.join(path.dirname(runtimeRoot), `.${path.basename(runtimeRoot)}.replaced-${randomUUID()}`);
|
|
350
|
-
await assertAwOwnedRuntimeBeforeReplacement(runtimeRoot, options);
|
|
351
|
-
await fs.rename(runtimeRoot, backupRoot);
|
|
352
|
-
try {
|
|
353
|
-
await fs.rename(stagingRoot, runtimeRoot);
|
|
354
|
-
}
|
|
355
|
-
catch (error) {
|
|
356
|
-
await assertAwOwnedRuntimeBeforeReplacement(backupRoot, options);
|
|
357
|
-
await fs.rename(backupRoot, runtimeRoot).catch(() => undefined);
|
|
358
|
-
throw error;
|
|
359
|
-
}
|
|
360
|
-
await assertAwOwnedRuntimeBeforeReplacement(backupRoot, options);
|
|
361
|
-
await fs.remove(backupRoot).catch(() => undefined);
|
|
362
|
-
const packagePaths = await inspectCanonicalManagedPackagePaths(runtimeRoot);
|
|
363
|
-
if (packagePaths.state !== 'complete') {
|
|
364
|
-
throw new Error('The managed runtime changed during adoption.');
|
|
365
|
-
}
|
|
366
|
-
return managerForRuntime(runtimeRoot, packagePaths.paths.launcher, options.execPath ?? process.execPath);
|
|
367
|
-
}
|
|
368
|
-
async function acquireManagedCodexRuntime(options) {
|
|
369
|
-
const runtimeRoot = managedRuntimeRoot(options);
|
|
370
|
-
const runtimeParent = path.dirname(runtimeRoot);
|
|
371
|
-
const pnpmEntry = options.pnpmEntry ?? await resolveBundledPnpmEntry();
|
|
372
|
-
if (!pnpmEntry)
|
|
373
|
-
throw new Error('The bundled pnpm@10.33.0 entry is unavailable.');
|
|
374
|
-
await ensureRegularManagedRuntimeAncestors(options);
|
|
375
|
-
const storeRoot = await assertManagedStoreDirectory(options);
|
|
376
|
-
const stagingRoot = await fs.mkdtemp(path.join(runtimeParent, `.${path.basename(runtimeRoot)}.staging-`));
|
|
377
|
-
try {
|
|
378
|
-
await fs.writeJson(path.join(stagingRoot, 'package.json'), {
|
|
379
|
-
private: true,
|
|
380
|
-
dependencies: { [MANAGED_CODEX_PACKAGE_NAME]: MANAGED_CODEX_VERSION },
|
|
381
|
-
}, { spaces: 2 });
|
|
382
|
-
const neutralUserConfig = path.join(stagingRoot, '.npmrc');
|
|
383
|
-
const runner = options.runner ?? getDefaultNativeCliRunner();
|
|
384
|
-
const env = options.env ?? process.env;
|
|
385
|
-
const installResult = await runNativeCli({
|
|
386
|
-
command: options.execPath ?? process.execPath,
|
|
387
|
-
args: [
|
|
388
|
-
pnpmEntry,
|
|
389
|
-
'install',
|
|
390
|
-
'--prod',
|
|
391
|
-
'--ignore-scripts',
|
|
392
|
-
'--ignore-workspace',
|
|
393
|
-
// Adoption renames staging; absolute Windows junctions would retain its old path.
|
|
394
|
-
'--config.node-linker=hoisted',
|
|
395
|
-
`--registry=${MANAGED_CODEX_REGISTRY}`,
|
|
396
|
-
`--store-dir=${storeRoot}`,
|
|
397
|
-
`--config.userconfig=${neutralUserConfig}`,
|
|
398
|
-
],
|
|
399
|
-
cwd: stagingRoot,
|
|
400
|
-
env: neutralPnpmEnv(env, neutralUserConfig),
|
|
401
|
-
}, runner);
|
|
402
|
-
if (installResult.exitCode !== 0) {
|
|
403
|
-
throw new Error('pnpm could not install the pinned Codex package.');
|
|
59
|
+
if (!selected || compareStrictSemVer(version, selected.version) > 0) {
|
|
60
|
+
selected = { ...candidate.manager, version };
|
|
404
61
|
}
|
|
405
|
-
await validateAcquiredRuntime(stagingRoot, options);
|
|
406
|
-
await fs.writeJson(path.join(stagingRoot, MANAGED_CODEX_MARKER_FILE), managedRuntimeMarker(options), { spaces: 2 });
|
|
407
|
-
return await adoptManagedRuntime(stagingRoot, options);
|
|
408
62
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
function executableNames(command, env, platform) {
|
|
414
|
-
if (platform !== 'win32')
|
|
415
|
-
return [command];
|
|
416
|
-
const pathExt = readEnvironmentValue(env, 'PATHEXT', platform) ?? '.COM;.EXE;.BAT;.CMD';
|
|
417
|
-
const supportedExtensions = new Set(['.com', '.exe', '.bat', '.cmd']);
|
|
418
|
-
const extensions = pathExt.split(';')
|
|
419
|
-
.map((extension) => extension.trim())
|
|
420
|
-
.filter((extension) => supportedExtensions.has(extension.toLowerCase()));
|
|
421
|
-
const orderedExtensions = [
|
|
422
|
-
...extensions.filter((extension) => ['.com', '.exe'].includes(extension.toLowerCase())),
|
|
423
|
-
...extensions.filter((extension) => ['.bat', '.cmd'].includes(extension.toLowerCase())),
|
|
424
|
-
];
|
|
425
|
-
return [...orderedExtensions.map((extension) => `${command}${extension}`), command];
|
|
426
|
-
}
|
|
427
|
-
function unsupportedSystemResolution(reason) {
|
|
428
|
-
return {
|
|
429
|
-
state: 'unsupported',
|
|
430
|
-
diagnostic: `The installed system Codex CLI is not supported. ${reason} Install or upgrade the official Codex CLI, or remove the invalid shim and retry; AW does not use managed fallback for this installation.`,
|
|
63
|
+
const evidence = {
|
|
64
|
+
requiredMinVersion,
|
|
65
|
+
...(diagnostics.length > 0 ? { diagnostics } : {}),
|
|
431
66
|
};
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const shimStats = await fs.lstat(shimPath);
|
|
436
|
-
if (!shimStats.isFile() || shimStats.isSymbolicLink()) {
|
|
437
|
-
return unsupportedSystemResolution('The Windows npm shim is not a regular file.');
|
|
438
|
-
}
|
|
439
|
-
const prefixRoot = path.dirname(shimPath);
|
|
440
|
-
const packageRoot = path.join(prefixRoot, 'node_modules', '@openai', 'codex');
|
|
441
|
-
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
442
|
-
const launcherPath = path.join(packageRoot, 'bin', 'codex.js');
|
|
443
|
-
const [packageStats, packageJsonStats, launcherStats] = await Promise.all([
|
|
444
|
-
fs.lstat(packageRoot),
|
|
445
|
-
fs.lstat(packageJsonPath),
|
|
446
|
-
fs.lstat(launcherPath),
|
|
447
|
-
]);
|
|
448
|
-
if (!packageStats.isDirectory()
|
|
449
|
-
|| packageStats.isSymbolicLink()
|
|
450
|
-
|| !packageJsonStats.isFile()
|
|
451
|
-
|| packageJsonStats.isSymbolicLink()
|
|
452
|
-
|| !launcherStats.isFile()
|
|
453
|
-
|| launcherStats.isSymbolicLink()) {
|
|
454
|
-
return unsupportedSystemResolution('The npm package or launcher is not a regular file tree.');
|
|
455
|
-
}
|
|
456
|
-
const [canonicalPrefix, canonicalPackageRoot, canonicalLauncher] = await Promise.all([
|
|
457
|
-
fs.realpath(prefixRoot),
|
|
458
|
-
fs.realpath(packageRoot),
|
|
459
|
-
fs.realpath(launcherPath),
|
|
460
|
-
]);
|
|
461
|
-
if (!isPathWithin(canonicalPrefix, canonicalPackageRoot)
|
|
462
|
-
|| !isPathWithin(canonicalPackageRoot, canonicalLauncher)) {
|
|
463
|
-
return unsupportedSystemResolution('The npm package or launcher resolves outside its npm prefix.');
|
|
464
|
-
}
|
|
465
|
-
const packageJson = await fs.readJson(packageJsonPath).catch(() => undefined);
|
|
466
|
-
const bin = packageJson?.bin;
|
|
467
|
-
if (packageJson?.name !== MANAGED_CODEX_PACKAGE_NAME
|
|
468
|
-
|| typeof packageJson.version !== 'string'
|
|
469
|
-
|| !tryParseStrictSemVer(packageJson.version)
|
|
470
|
-
|| !bin
|
|
471
|
-
|| typeof bin !== 'object'
|
|
472
|
-
|| Array.isArray(bin)
|
|
473
|
-
|| bin.codex !== 'bin/codex.js') {
|
|
474
|
-
return unsupportedSystemResolution('The npm package identity, version, or launcher contract is invalid.');
|
|
475
|
-
}
|
|
67
|
+
if (!selected) {
|
|
68
|
+
if (!discovery.foundEntry && diagnostics.length === 0)
|
|
69
|
+
return { ...evidence, state: 'missing' };
|
|
476
70
|
return {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
version: packageJson.version,
|
|
482
|
-
command: process.execPath,
|
|
483
|
-
argsPrefix: [canonicalLauncher],
|
|
484
|
-
},
|
|
71
|
+
...evidence,
|
|
72
|
+
state: 'unresolved',
|
|
73
|
+
code: 'codexSystemCliUnsupported',
|
|
74
|
+
diagnostic: unsupportedDiagnostic(requiredMinVersion),
|
|
485
75
|
};
|
|
486
76
|
}
|
|
487
|
-
|
|
488
|
-
return unsupportedSystemResolution('The Windows npm package is missing or unreadable.');
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
/** Probes only the PATH consumer; never inspects or acquires a managed runtime. */
|
|
492
|
-
export async function inspectSystemCodex(options) {
|
|
493
|
-
const requiredMinVersion = options.operationRequirement.minimumVersion;
|
|
494
|
-
const unresolved = (diagnostic) => ({
|
|
495
|
-
state: 'unresolved',
|
|
496
|
-
code: 'codexSystemCliUnsupported',
|
|
497
|
-
diagnostic,
|
|
498
|
-
requiredMinVersion,
|
|
499
|
-
});
|
|
500
|
-
let system;
|
|
501
|
-
try {
|
|
502
|
-
system = await probeSystemCodex(options);
|
|
503
|
-
}
|
|
504
|
-
catch (error) {
|
|
505
|
-
if (error instanceof Error && error.name === 'AbortError')
|
|
506
|
-
throw error;
|
|
507
|
-
return unresolved('The PATH Codex launcher could not be inspected. Check the launcher and retry.');
|
|
508
|
-
}
|
|
509
|
-
if (system.state === 'missing')
|
|
510
|
-
return { state: 'missing', requiredMinVersion };
|
|
511
|
-
if (system.state === 'unsupported')
|
|
512
|
-
return unresolved(system.diagnostic);
|
|
513
|
-
const { result } = system;
|
|
514
|
-
if (result.status === 'supported') {
|
|
515
|
-
return { state: 'compatible', detectedVersion: result.detectedVersion, requiredMinVersion };
|
|
516
|
-
}
|
|
517
|
-
if (result.status === 'tooOld') {
|
|
77
|
+
if (compareStrictSemVer(selected.version, requiredMinVersion) < 0) {
|
|
518
78
|
return {
|
|
79
|
+
...evidence,
|
|
519
80
|
state: 'incompatible',
|
|
520
81
|
code: 'codexSystemCliUnsupported',
|
|
521
|
-
detectedVersion:
|
|
522
|
-
diagnostic:
|
|
523
|
-
requiredMinVersion,
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
return unresolved('The PATH Codex version query failed or returned an invalid version. Check the launcher and retry.');
|
|
527
|
-
}
|
|
528
|
-
async function resolveSystemCommandManager(command, options) {
|
|
529
|
-
const platform = options.platform ?? process.platform;
|
|
530
|
-
const extension = path.extname(command).toLowerCase();
|
|
531
|
-
if (platform !== 'win32' || (extension !== '.cmd' && extension !== '.bat')) {
|
|
532
|
-
return {
|
|
533
|
-
state: 'supported',
|
|
534
|
-
manager: {
|
|
535
|
-
kind: 'system',
|
|
536
|
-
version: 'unknown',
|
|
537
|
-
command,
|
|
538
|
-
argsPrefix: [],
|
|
539
|
-
},
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
if (extension === '.bat') {
|
|
543
|
-
return unsupportedSystemResolution('Only the official Windows npm .cmd launcher is supported.');
|
|
544
|
-
}
|
|
545
|
-
return resolveWindowsNpmCodexManager(command);
|
|
546
|
-
}
|
|
547
|
-
async function resolvePathExecutable(command, options) {
|
|
548
|
-
const env = options.env ?? process.env;
|
|
549
|
-
const platform = options.platform ?? process.platform;
|
|
550
|
-
const cwd = options.cwd ?? process.cwd();
|
|
551
|
-
const delimiter = platform === 'win32' ? ';' : ':';
|
|
552
|
-
const pathEnvironment = readEnvironmentValue(env, 'PATH', platform);
|
|
553
|
-
if (pathEnvironment === undefined)
|
|
554
|
-
return undefined;
|
|
555
|
-
for (const rawEntry of pathEnvironment.split(delimiter)) {
|
|
556
|
-
const entry = rawEntry.replace(/^"|"$/gu, '');
|
|
557
|
-
const directory = path.resolve(cwd, entry || '.');
|
|
558
|
-
for (const executableName of executableNames(command, env, platform)) {
|
|
559
|
-
const candidate = path.join(directory, executableName);
|
|
560
|
-
try {
|
|
561
|
-
if (!(await fs.stat(candidate)).isFile())
|
|
562
|
-
continue;
|
|
563
|
-
if (platform === 'win32')
|
|
564
|
-
return candidate;
|
|
565
|
-
await fs.access(candidate, fsConstants.X_OK);
|
|
566
|
-
return await fs.realpath(candidate);
|
|
567
|
-
}
|
|
568
|
-
catch (error) {
|
|
569
|
-
const code = error.code;
|
|
570
|
-
if (code === 'ENOENT' || code === 'EACCES' || code === 'ENOTDIR')
|
|
571
|
-
continue;
|
|
572
|
-
throw error;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return undefined;
|
|
577
|
-
}
|
|
578
|
-
async function probeSystemCodex(options) {
|
|
579
|
-
const command = await resolvePathExecutable('codex', options);
|
|
580
|
-
if (!command)
|
|
581
|
-
return { state: 'missing' };
|
|
582
|
-
const resolution = await resolveSystemCommandManager(command, options);
|
|
583
|
-
if (resolution.state === 'unsupported')
|
|
584
|
-
return resolution;
|
|
585
|
-
const { manager } = resolution;
|
|
586
|
-
const result = await probeAgentVersion('codex', {
|
|
587
|
-
argsPrefix: manager.argsPrefix,
|
|
588
|
-
cache: false,
|
|
589
|
-
command: manager.command,
|
|
590
|
-
cwd: options.cwd,
|
|
591
|
-
env: options.env,
|
|
592
|
-
minimumVersion: options.operationRequirement?.minimumVersion,
|
|
593
|
-
runner: options.runner,
|
|
594
|
-
});
|
|
595
|
-
if (resolution.expectedVersion
|
|
596
|
-
&& result.status === 'supported'
|
|
597
|
-
&& result.detectedVersion !== resolution.expectedVersion) {
|
|
598
|
-
return {
|
|
599
|
-
state: 'unsupported',
|
|
600
|
-
diagnostic: 'The installed system Codex CLI is not supported. The npm package version does not match its launcher output. Reinstall or upgrade the official Codex CLI and retry; AW does not use managed fallback for this installation.',
|
|
82
|
+
detectedVersion: selected.version,
|
|
83
|
+
diagnostic: unsupportedDiagnostic(requiredMinVersion, selected.version),
|
|
601
84
|
};
|
|
602
85
|
}
|
|
603
|
-
return { state: '
|
|
86
|
+
return { ...evidence, state: 'compatible', detectedVersion: selected.version, manager: selected };
|
|
604
87
|
}
|
|
605
|
-
function unsupportedSystemDiagnostic(system) {
|
|
606
|
-
const detected = system.detectedVersion ? ` Detected ${system.detectedVersion}.` : '';
|
|
607
|
-
return `The installed system Codex CLI is not supported.${detected} Required minimum: ${system.requiredMinVersion}. Upgrade the official Codex CLI and retry; AW does not bypass an installed but unsupported system CLI.`;
|
|
608
|
-
}
|
|
609
|
-
const MANAGED_AUTHORIZATION_DIAGNOSTIC = 'This operation must acquire or rebuild the pinned AW-managed Codex runtime. Retry with --allow-managed-codex-install, or approve the interactive prompt.';
|
|
610
|
-
const MANAGED_UNAVAILABLE_DIAGNOSTIC = 'The AW-managed Codex runtime is unavailable. Retry the command, upgrade AW, or install a compatible official Codex CLI.';
|
|
611
88
|
export async function previewCodexManager(options = {}) {
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
},
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
if (system.state === 'unsupported') {
|
|
623
|
-
return {
|
|
624
|
-
state: 'blocked',
|
|
625
|
-
code: 'codexSystemCliUnsupported',
|
|
626
|
-
diagnostic: system.diagnostic,
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
if (system.state === 'probed') {
|
|
630
|
-
return {
|
|
631
|
-
state: 'blocked',
|
|
632
|
-
code: 'codexSystemCliUnsupported',
|
|
633
|
-
diagnostic: unsupportedSystemDiagnostic(system.result),
|
|
634
|
-
};
|
|
89
|
+
const inspection = await inspectSystemCodex({
|
|
90
|
+
...options,
|
|
91
|
+
operationRequirement: options.operationRequirement ?? getCodexOperationRequirement('user'),
|
|
92
|
+
});
|
|
93
|
+
const evidence = inspection.diagnostics ? { diagnostics: inspection.diagnostics } : {};
|
|
94
|
+
if (inspection.state === 'compatible') {
|
|
95
|
+
return { ...evidence, state: 'system', manager: inspection.manager };
|
|
635
96
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return { state: 'cached', manager: managed.manager };
|
|
639
|
-
if (managed.state === 'absent' || managed.state === 'rebuildable') {
|
|
640
|
-
return { state: 'requires-install' };
|
|
97
|
+
if (inspection.state === 'missing') {
|
|
98
|
+
return { ...evidence, state: 'blocked', code: 'codexCliNotFound', diagnostic: MISSING_DIAGNOSTIC };
|
|
641
99
|
}
|
|
642
100
|
return {
|
|
101
|
+
...evidence,
|
|
643
102
|
state: 'blocked',
|
|
644
|
-
code: '
|
|
645
|
-
diagnostic:
|
|
103
|
+
code: 'codexSystemCliUnsupported',
|
|
104
|
+
diagnostic: 'diagnostic' in inspection
|
|
105
|
+
? inspection.diagnostic
|
|
106
|
+
: unsupportedDiagnostic(inspection.requiredMinVersion),
|
|
646
107
|
};
|
|
647
108
|
}
|
|
648
109
|
export async function resolveCodexManager(options = {}) {
|
|
649
|
-
const
|
|
650
|
-
if (
|
|
651
|
-
return
|
|
652
|
-
|
|
653
|
-
version: system.result.detectedVersion,
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
if (system.state === 'unsupported') {
|
|
657
|
-
throw new CodexManagerError('codexSystemCliUnsupported', system.diagnostic);
|
|
658
|
-
}
|
|
659
|
-
if (system.state === 'probed') {
|
|
660
|
-
throw new CodexManagerError('codexSystemCliUnsupported', unsupportedSystemDiagnostic(system.result));
|
|
661
|
-
}
|
|
662
|
-
return resolveManagedCodexAfterMissingSystem(options);
|
|
663
|
-
}
|
|
664
|
-
async function resolveManagedCodexAfterMissingSystem(options) {
|
|
665
|
-
const managed = await inspectManagedCodexRuntime(options);
|
|
666
|
-
if (managed.state === 'valid')
|
|
667
|
-
return managed.manager;
|
|
668
|
-
if (managed.state === 'blocked') {
|
|
669
|
-
throw new CodexManagerError('managedCodexUnavailable', MANAGED_UNAVAILABLE_DIAGNOSTIC);
|
|
670
|
-
}
|
|
671
|
-
if (!options.authorizer) {
|
|
672
|
-
throw new CodexManagerError('managedCodexAuthorizationRequired', MANAGED_AUTHORIZATION_DIAGNOSTIC);
|
|
673
|
-
}
|
|
674
|
-
let authorized;
|
|
675
|
-
try {
|
|
676
|
-
authorized = await options.authorizer();
|
|
677
|
-
}
|
|
678
|
-
catch (error) {
|
|
679
|
-
throw new CodexManagerError('managedCodexUnavailable', MANAGED_UNAVAILABLE_DIAGNOSTIC);
|
|
680
|
-
}
|
|
681
|
-
if (!authorized) {
|
|
682
|
-
throw new CodexManagerError('managedCodexAuthorizationRequired', MANAGED_AUTHORIZATION_DIAGNOSTIC);
|
|
683
|
-
}
|
|
684
|
-
try {
|
|
685
|
-
return await acquireManagedCodexRuntime(options);
|
|
686
|
-
}
|
|
687
|
-
catch (error) {
|
|
688
|
-
throw new CodexManagerError('managedCodexUnavailable', MANAGED_UNAVAILABLE_DIAGNOSTIC);
|
|
689
|
-
}
|
|
110
|
+
const preview = await previewCodexManager(options);
|
|
111
|
+
if (preview.state === 'system')
|
|
112
|
+
return preview.manager;
|
|
113
|
+
throw new CodexManagerError(preview.code, preview.diagnostic);
|
|
690
114
|
}
|
|
691
115
|
export async function resolveCodexOperationConsumer(options) {
|
|
692
|
-
const system = await probeSystemCodex(options);
|
|
693
|
-
if (system.state === 'probed' && system.result.status === 'supported') {
|
|
694
|
-
return {
|
|
695
|
-
support: 'observed',
|
|
696
|
-
manager: {
|
|
697
|
-
...system.manager,
|
|
698
|
-
version: system.result.detectedVersion,
|
|
699
|
-
},
|
|
700
|
-
requirement: options.operationRequirement,
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
if (system.state === 'unsupported') {
|
|
704
|
-
throw new CodexManagerError('codexSystemCliUnsupported', system.diagnostic);
|
|
705
|
-
}
|
|
706
|
-
if (system.state === 'probed') {
|
|
707
|
-
throw new CodexManagerError('codexSystemCliUnsupported', unsupportedSystemDiagnostic(system.result));
|
|
708
|
-
}
|
|
709
|
-
if (!options.requiresNativeMaterialization) {
|
|
710
|
-
const managed = await inspectManagedCodexRuntime(options);
|
|
711
|
-
if (managed.state === 'valid') {
|
|
712
|
-
return {
|
|
713
|
-
support: 'observed',
|
|
714
|
-
manager: managed.manager,
|
|
715
|
-
requirement: options.operationRequirement,
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
return {
|
|
719
|
-
support: 'assumed',
|
|
720
|
-
requirement: options.operationRequirement,
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
116
|
return {
|
|
724
117
|
support: 'observed',
|
|
725
|
-
manager: await
|
|
118
|
+
manager: await resolveCodexManager(options),
|
|
726
119
|
requirement: options.operationRequirement,
|
|
727
120
|
};
|
|
728
121
|
}
|