@atolis-hq/wake 0.3.115 → 0.3.117
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/README.md +4 -1
- package/dist/src/bootstrap/surface-cli-applications.js +40 -11
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/infrastructure/codex-stop-hook.js +34 -248
- package/dist/src/execution/infrastructure/runners/codex.js +5 -20
- package/dist/src/surfaces/api/http-server.js +116 -77
- package/dist/src/surfaces/auth/credentials.js +134 -0
- package/dist/src/surfaces/auth/vocabulary.js +7 -0
- package/dist/src/surfaces/cli/main.js +42 -1
- package/dist/src/surfaces/cli/usage.js +2 -0
- package/dist/src/surfaces/contracts/config.js +10 -2
- package/dist/src/surfaces/index.js +2 -0
- package/dist/src/surfaces/web-assets/assets/index-CFfq35Jj.js +1179 -0
- package/dist/src/surfaces/web-assets/assets/{index-D543o6jw.css → index-Dj-RskGs.css} +1 -1
- package/dist/src/surfaces/web-assets/index.html +2 -2
- package/package.json +6 -1
- package/dist/src/execution/infrastructure/codex-stop-hook-protocol.js +0 -219
- package/dist/src/surfaces/web-assets/assets/index-B31Oxnbk.js +0 -1179
package/README.md
CHANGED
|
@@ -127,7 +127,10 @@ nothing new to learn, no separate dashboard to babysit.
|
|
|
127
127
|
|
|
128
128
|
A local control-plane UI exists for operators who want to watch runs, inspect
|
|
129
129
|
events, or resume a session directly, but it's a window into the same state -
|
|
130
|
-
not a required part of the workflow.
|
|
130
|
+
not a required part of the workflow. The API and UI require an operator login:
|
|
131
|
+
run `wake ui token` to print the access key, then enter it in the UI. Use
|
|
132
|
+
`wake ui token set <key>` to replace it; replacement signs out existing
|
|
133
|
+
sessions.
|
|
131
134
|
|
|
132
135
|
## Supported Agent CLIs
|
|
133
136
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { execFile as nodeExecFile, spawn } from 'node:child_process';
|
|
2
|
-
import { once } from 'node:events';
|
|
3
2
|
import { access, copyFile, mkdir, writeFile as writeFileContent } from 'node:fs/promises';
|
|
4
3
|
import { join } from 'node:path';
|
|
5
4
|
import { createInterface } from 'node:readline/promises';
|
|
@@ -9,7 +8,7 @@ import { IntakeHost, ResidentHost, TickHost } from '../control-plane/index.js';
|
|
|
9
8
|
import { ExecutionCancellationReason, ExecutionFailureCode, RunStatus, loadPromptTemplate, } from '../execution/index.js';
|
|
10
9
|
import { EventActorKind, JOURNAL_CHANGE_FALLBACK_MS, correlationId } from '../kernel/index.js';
|
|
11
10
|
import { ResourceCorrelationRole, resourceId } from '../resources/index.js';
|
|
12
|
-
import { DockerProcessError, createApiDispatcher,
|
|
11
|
+
import { DockerProcessError, createApiDispatcher, createLoggedDockerCli, createPackagedAssetSource, createPairingGrant, createProcessLogSink, createSandboxDockerPort, createSurfaceHttpServer, drainProcessOutput, loadOrCreateCredentials, redeemPairingGrant, replaceAccessKey, runDoctor, runSandbox, runSandboxEntrypoint, runSandboxSetup, runSelfUpdateLatestLoop, runTargetSmoke, verifyResidentStart, waitForActiveRuns, waitForever, } from '../surfaces/index.js';
|
|
13
12
|
import { WorkStreamKind, workItemId } from '../work/index.js';
|
|
14
13
|
import { loadConfig } from './config/load-config.js';
|
|
15
14
|
import { runtimeProjectionDefinitions } from './projection-runtime.js';
|
|
@@ -91,6 +90,30 @@ export function createSurfaceCliApplications(root, api, now) {
|
|
|
91
90
|
},
|
|
92
91
|
api: { start: (options) => startHttp(options, false) },
|
|
93
92
|
ui: { start: (options) => startHttp(options, true) },
|
|
93
|
+
auth: {
|
|
94
|
+
async token(accessKey) {
|
|
95
|
+
if (root.config.surfaces.web.auth.disabled)
|
|
96
|
+
return 'UI authentication is disabled by surfaces.web.auth.disabled.';
|
|
97
|
+
if (accessKey !== undefined)
|
|
98
|
+
await replaceAccessKey(root.paths.wakeRoot, accessKey);
|
|
99
|
+
const grant = await createPairingGrant(root.paths.wakeRoot);
|
|
100
|
+
const localHost = root.config.surfaces.api.host === '0.0.0.0' ? 'localhost' : root.config.surfaces.api.host;
|
|
101
|
+
const local = `http://${localHost}:${root.config.surfaces.api.port}/?grant=${encodeURIComponent(grant.value)}`;
|
|
102
|
+
const publicUrl = root.config.surfaces.web.publicUrl;
|
|
103
|
+
return [
|
|
104
|
+
'Wake login link (single use; expires in 10 minutes):',
|
|
105
|
+
` Local: ${local}`,
|
|
106
|
+
...(publicUrl === undefined
|
|
107
|
+
? []
|
|
108
|
+
: [
|
|
109
|
+
` Public: ${new URL(`?grant=${encodeURIComponent(grant.value)}`, publicUrl).href}`,
|
|
110
|
+
]),
|
|
111
|
+
'',
|
|
112
|
+
'Open a link on this device or scan its QR code from a mobile device. Do not share the link.',
|
|
113
|
+
'',
|
|
114
|
+
].join('\n');
|
|
115
|
+
},
|
|
116
|
+
},
|
|
94
117
|
audit: {
|
|
95
118
|
async read(id) {
|
|
96
119
|
return (await root.journal.readAll(0))
|
|
@@ -167,14 +190,21 @@ function createHttpStarter(root, api, servers) {
|
|
|
167
190
|
const assets = web ? createPackagedAssetSource() : undefined;
|
|
168
191
|
if (web && (await assets.get('/index.html')) === undefined)
|
|
169
192
|
throw new Error('Packaged Wake web assets are missing');
|
|
170
|
-
const server =
|
|
193
|
+
const server = createSurfaceHttpServer({
|
|
194
|
+
dispatcher: createApiDispatcher(api),
|
|
195
|
+
credentials: await loadOrCreateCredentials(root.paths.wakeRoot),
|
|
196
|
+
auth: {
|
|
197
|
+
disabled: root.config.surfaces.web.auth.disabled,
|
|
198
|
+
redeemGrant: (grant) => redeemPairingGrant(root.paths.wakeRoot, grant),
|
|
199
|
+
},
|
|
200
|
+
...(assets === undefined ? {} : { assets }),
|
|
201
|
+
});
|
|
171
202
|
servers.add(server);
|
|
172
|
-
server.listen(options.port ?? root.config.surfaces.api.port, options.host ?? root.config.surfaces.api.host);
|
|
173
203
|
try {
|
|
174
|
-
await
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
204
|
+
await server.listen({
|
|
205
|
+
port: options.port ?? root.config.surfaces.api.port,
|
|
206
|
+
host: options.host ?? root.config.surfaces.api.host,
|
|
207
|
+
});
|
|
178
208
|
}
|
|
179
209
|
catch (error) {
|
|
180
210
|
servers.delete(server);
|
|
@@ -637,10 +667,9 @@ function commandContext(commandId, occurredAt) {
|
|
|
637
667
|
}
|
|
638
668
|
async function closeAll(servers) {
|
|
639
669
|
await Promise.all([...servers].map(async (server) => {
|
|
640
|
-
if (!server.listening)
|
|
670
|
+
if (!server.server.listening)
|
|
641
671
|
return;
|
|
642
|
-
server.close();
|
|
643
|
-
await once(server, 'close');
|
|
672
|
+
await server.close();
|
|
644
673
|
servers.delete(server);
|
|
645
674
|
}));
|
|
646
675
|
}
|
|
@@ -1,266 +1,55 @@
|
|
|
1
|
-
import { readFile
|
|
2
|
-
import { join } from 'node:path';
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
3
2
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
|
|
5
|
-
export const unverifiedCodexCompletionReason = 'unverified: could not confirm background command completion from Codex structured telemetry';
|
|
3
|
+
export const waitBackgroundStatus = 'WAIT_BACKGROUND';
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* to yield for (observed from ~1s to 50s+ per call in production), so a
|
|
12
|
-
* fixed count either gives up far too early on a real multi-minute command
|
|
13
|
-
* or far too late on a broken loop that isn't waiting on anything real.
|
|
14
|
-
*
|
|
15
|
-
* Real observed `npm run verify`/`verify:ci` durations range from ~90s to
|
|
16
|
-
* over 20 minutes, so this value is a deliberate tradeoff rather than a safe
|
|
17
|
-
* upper bound on every legitimate case: a genuinely long-running command that
|
|
18
|
-
* outlasts it will have its live retry loop give up before finishing, and
|
|
19
|
-
* fall through to a `BLOCKED` outcome needing a human `/retry` instead of
|
|
20
|
-
* confirming cleanly on its own. That's an accepted cost, not a correctness
|
|
21
|
-
* gap — giving up here never weakens the guarantee, since the post-run
|
|
22
|
-
* fallback (`verifyCodexSession`) independently re-scans the same transcript
|
|
23
|
-
* after the process exits and still reports the run as unverified if the
|
|
24
|
-
* cell is genuinely still unresolved. This limit exists only to bound
|
|
25
|
-
* wasted time/tokens against a detection gap we haven't found yet, not to
|
|
26
|
-
* replace correct detection.
|
|
27
|
-
*/
|
|
28
|
-
export const maxLiveHookRetryMs = 10 * 60 * 1000;
|
|
29
|
-
/**
|
|
30
|
-
* Inspect only Codex's structured function-call protocol. Command output is
|
|
31
|
-
* opaque except for the protocol's managed-cell and terminal-result envelopes.
|
|
32
|
-
*
|
|
33
|
-
* Exec/wait cells live in one `codex exec` process's memory and never survive
|
|
34
|
-
* a resume into a new process, so only the segment of the transcript since
|
|
35
|
-
* the current process attached (its `session_meta`/`turn_context` marker)
|
|
36
|
-
* can hold a cell that might still be genuinely pending. A cell referenced
|
|
37
|
-
* only in an earlier segment belongs to a process that has already exited
|
|
38
|
-
* and can never return an exit code again — scoping to the latest segment
|
|
39
|
-
* is what makes that structurally certain, rather than trying to recognise
|
|
40
|
-
* every shape of "this cell is gone" text a stale reference might produce.
|
|
5
|
+
* WAIT_BACKGROUND is a Codex-only, intermediate final response. It is not a
|
|
6
|
+
* Wake outcome: the hook rejects it and gives Codex another turn to obtain a
|
|
7
|
+
* terminal result before it reports DONE, BLOCKED, NEEDS_CLARIFICATION, or
|
|
8
|
+
* FAILED.
|
|
41
9
|
*/
|
|
42
10
|
export function inspectCodexTranscript(transcript) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
unresolvableCells: new Set(),
|
|
50
|
-
sessionsByCell: new Map(),
|
|
51
|
-
};
|
|
52
|
-
for (const line of lines.slice(boundary + 1)) {
|
|
53
|
-
const event = parseJson(line);
|
|
54
|
-
if (event === undefined)
|
|
55
|
-
return blocked('could not parse Codex structured telemetry');
|
|
56
|
-
const payload = record(event.payload);
|
|
57
|
-
if (payload !== undefined)
|
|
58
|
-
consumePayload(payload, telemetry);
|
|
59
|
-
}
|
|
60
|
-
const unresolved = [...telemetry.pendingCells].filter((cellId) => !telemetry.resolvedCells.has(cellId));
|
|
61
|
-
if (unresolved.length === 0)
|
|
62
|
-
return {};
|
|
63
|
-
// A cell whose own `wait` call has already reported it gone (a distinct,
|
|
64
|
-
// cell-identity-specific protocol error, not a general failure) can never
|
|
65
|
-
// return an exit code no matter how many more times it's polled. Asking
|
|
66
|
-
// the model to keep retrying it is not just wasted effort, it's actively
|
|
67
|
-
// wrong instructions — so stop retrying that specific cell immediately
|
|
68
|
-
// rather than waiting out the general time backstop. The cell still
|
|
69
|
-
// counts as unresolved for the block decision itself: it genuinely never
|
|
70
|
-
// confirmed completion, it just isn't worth telling the model to poll
|
|
71
|
-
// again.
|
|
72
|
-
const retryable = unresolved.filter((cellId) => !telemetry.unresolvableCells.has(cellId));
|
|
73
|
-
if (retryable.length === 0)
|
|
74
|
-
return {};
|
|
75
|
-
if (liveHookRetryElapsedMs(lines.slice(boundary + 1)) >= maxLiveHookRetryMs)
|
|
76
|
-
return {};
|
|
77
|
-
return blocked(`Codex cell ${retryable[0]} has no terminal exit_code; continue polling that cell`);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Elapsed wall-clock time since this hook's own first continuation prompt
|
|
81
|
-
* within the current process segment, using the transcript's own event
|
|
82
|
-
* timestamps rather than a call/retry count. Returns 0 (never give up) when
|
|
83
|
-
* there is no prior retry yet, or when a timestamp can't be established —
|
|
84
|
-
* giving up is the direction that stops enforcing, so any doubt should keep
|
|
85
|
-
* blocking rather than silently switch to time-based give-up on weak evidence.
|
|
86
|
-
*/
|
|
87
|
-
function liveHookRetryElapsedMs(segment) {
|
|
88
|
-
let firstRetryAt;
|
|
89
|
-
let latestAt;
|
|
90
|
-
for (const line of segment) {
|
|
91
|
-
const event = parseJson(line);
|
|
92
|
-
if (event === undefined)
|
|
93
|
-
continue;
|
|
94
|
-
const at = timestampMs(event.timestamp);
|
|
95
|
-
if (at !== undefined)
|
|
96
|
-
latestAt = at;
|
|
97
|
-
const payload = record(event.payload);
|
|
98
|
-
if (payload?.type !== 'message' || payload.role !== 'user')
|
|
99
|
-
continue;
|
|
100
|
-
if (firstRetryAt === undefined &&
|
|
101
|
-
at !== undefined &&
|
|
102
|
-
userMessageText(payload.content).includes('<hook_prompt'))
|
|
103
|
-
firstRetryAt = at;
|
|
104
|
-
}
|
|
105
|
-
return firstRetryAt === undefined || latestAt === undefined ? 0 : latestAt - firstRetryAt;
|
|
106
|
-
}
|
|
107
|
-
function timestampMs(value) {
|
|
108
|
-
if (typeof value !== 'string')
|
|
109
|
-
return undefined;
|
|
110
|
-
const parsed = Date.parse(value);
|
|
111
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
112
|
-
}
|
|
113
|
-
function userMessageText(content) {
|
|
114
|
-
if (!Array.isArray(content))
|
|
115
|
-
return '';
|
|
116
|
-
return content
|
|
117
|
-
.map((item) => {
|
|
118
|
-
const entry = record(item);
|
|
119
|
-
return entry === undefined ? '' : (string(entry.text) ?? '');
|
|
120
|
-
})
|
|
121
|
-
.join('');
|
|
122
|
-
}
|
|
123
|
-
function lastProcessBoundary(lines) {
|
|
124
|
-
let boundary = -1;
|
|
125
|
-
lines.forEach((line, index) => {
|
|
126
|
-
const event = parseJson(line);
|
|
127
|
-
if (event?.type === 'session_meta' || event?.type === 'turn_context')
|
|
128
|
-
boundary = index;
|
|
129
|
-
});
|
|
130
|
-
return boundary;
|
|
131
|
-
}
|
|
132
|
-
function consumePayload(payload, telemetry) {
|
|
133
|
-
if (payload.type === 'function_call' || payload.type === 'custom_tool_call') {
|
|
134
|
-
recordToolCall(payload, telemetry.calls);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (payload.type === 'custom_tool_call_output' || payload.type === 'function_call_output')
|
|
138
|
-
recordToolOutput(payload, telemetry);
|
|
139
|
-
}
|
|
140
|
-
function recordToolCall(payload, calls) {
|
|
141
|
-
const callId = string(payload.call_id);
|
|
142
|
-
const name = toolName(payload.name);
|
|
143
|
-
if (callId === undefined || name === undefined)
|
|
144
|
-
return;
|
|
145
|
-
calls.set(callId, {
|
|
146
|
-
name,
|
|
147
|
-
...(name === 'wait' ? cellArgument(payload.arguments ?? payload.input) : {}),
|
|
148
|
-
...(name === 'exec' ? { spawnsBackgroundJob: spawnsBackgroundJob(payload.input) } : {}),
|
|
149
|
-
...(name === 'exec' ? writeStdinSessionArgument(payload.input) : {}),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The `exec` tool is a shared JS sandbox: `tools.exec_command(...)` spawns a
|
|
154
|
-
* genuine one-shot background job whose cell should eventually resolve to a
|
|
155
|
-
* real exit code. `tools.write_stdin(...)` instead interacts with an
|
|
156
|
-
* already-existing, intentionally long-lived session (e.g. a dev server kept
|
|
157
|
-
* running for e2e checks) — that cell is never meant to terminate, so
|
|
158
|
-
* flagging it as an unresolved background command would be a false positive.
|
|
159
|
-
* Default to treating a call as job-spawning whenever it can't be positively
|
|
160
|
-
* identified as pure session interaction, matching the fail-closed posture
|
|
161
|
-
* used everywhere else in this file.
|
|
162
|
-
*/
|
|
163
|
-
function spawnsBackgroundJob(input) {
|
|
164
|
-
if (typeof input !== 'string')
|
|
165
|
-
return true;
|
|
166
|
-
const interactsWithSession = /tools\.write_stdin\s*\(/.test(input);
|
|
167
|
-
const spawnsJob = /tools\.exec_command\s*\(/.test(input);
|
|
168
|
-
return spawnsJob || !interactsWithSession;
|
|
169
|
-
}
|
|
170
|
-
function recordToolOutput(payload, telemetry) {
|
|
171
|
-
const callId = string(payload.call_id);
|
|
172
|
-
const call = callId === undefined ? undefined : telemetry.calls.get(callId);
|
|
173
|
-
if (call === undefined)
|
|
174
|
-
return;
|
|
175
|
-
const result = structuredResult(payload.output);
|
|
176
|
-
if (call.name === 'exec')
|
|
177
|
-
return recordExecOutput(call, result, telemetry);
|
|
178
|
-
recordWaitOutput(call, result, payload.output, telemetry);
|
|
179
|
-
}
|
|
180
|
-
function recordExecOutput(call, result, telemetry) {
|
|
181
|
-
if (call.spawnsBackgroundJob === true && result.exitCode === undefined && result.pendingCellId)
|
|
182
|
-
telemetry.pendingCells.add(result.pendingCellId);
|
|
183
|
-
if (call.writeStdinSessionId !== undefined && result.pendingCellId !== undefined)
|
|
184
|
-
telemetry.sessionsByCell.set(result.pendingCellId, call.writeStdinSessionId);
|
|
185
|
-
if (call.writeStdinSessionId === undefined || result.jsonExitCode === undefined)
|
|
186
|
-
return;
|
|
187
|
-
resolveSession(call.writeStdinSessionId, telemetry);
|
|
188
|
-
}
|
|
189
|
-
function resolveSession(sessionId, telemetry) {
|
|
190
|
-
for (const [cellId, recordedSessionId] of telemetry.sessionsByCell) {
|
|
191
|
-
if (recordedSessionId === sessionId)
|
|
192
|
-
telemetry.resolvedCells.add(cellId);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
function recordWaitOutput(call, result, output, telemetry) {
|
|
196
|
-
if (call.cellId === undefined)
|
|
197
|
-
return;
|
|
198
|
-
const nativeTerminal = result.sessionId === undefined && isTerminalWaitOutput(output);
|
|
199
|
-
const terminal = result.exitCode !== undefined || nativeTerminal;
|
|
200
|
-
if (terminal) {
|
|
201
|
-
telemetry.resolvedCells.add(call.cellId);
|
|
202
|
-
const sessionId = telemetry.sessionsByCell.get(call.cellId);
|
|
203
|
-
if (sessionId !== undefined && (result.jsonExitCode !== undefined || nativeTerminal))
|
|
204
|
-
resolveSession(sessionId, telemetry);
|
|
205
|
-
}
|
|
206
|
-
if (result.sessionId !== undefined)
|
|
207
|
-
telemetry.sessionsByCell.set(call.cellId, result.sessionId);
|
|
208
|
-
if (result.notFoundCellId === call.cellId)
|
|
209
|
-
telemetry.unresolvableCells.add(call.cellId);
|
|
11
|
+
return lastAssistantMessage(transcript) === waitBackgroundStatus
|
|
12
|
+
? {
|
|
13
|
+
decision: 'block',
|
|
14
|
+
reason: 'Codex reported WAIT_BACKGROUND. Do not end this turn. Poll every command still running from this turn and report a normal terminal status only after each has settled.',
|
|
15
|
+
}
|
|
16
|
+
: {};
|
|
210
17
|
}
|
|
211
18
|
export async function runCodexStopHook(input) {
|
|
212
19
|
const payload = record(input);
|
|
213
20
|
const transcriptPath = payload === undefined ? undefined : string(payload.transcript_path);
|
|
214
21
|
if (transcriptPath === undefined)
|
|
215
|
-
return
|
|
22
|
+
return {};
|
|
216
23
|
try {
|
|
217
24
|
return inspectCodexTranscript(await readFile(transcriptPath, 'utf8'));
|
|
218
25
|
}
|
|
219
26
|
catch {
|
|
220
|
-
return
|
|
27
|
+
return {};
|
|
221
28
|
}
|
|
222
29
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
234
|
-
const path = join(directory, entry.name);
|
|
235
|
-
if (entry.isDirectory()) {
|
|
236
|
-
const nested = await transcriptForSession(path, sessionId);
|
|
237
|
-
if (nested !== undefined)
|
|
238
|
-
return nested;
|
|
239
|
-
}
|
|
240
|
-
else if (entry.isFile() && entry.name.endsWith(`-${sessionId}.jsonl`))
|
|
241
|
-
return path;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
catch {
|
|
245
|
-
return undefined;
|
|
30
|
+
function lastAssistantMessage(transcript) {
|
|
31
|
+
const lines = transcript.split(/\r?\n/);
|
|
32
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
33
|
+
const event = parseJson(lines[index] ?? '');
|
|
34
|
+
const payload = event === undefined ? undefined : record(event.payload);
|
|
35
|
+
if (payload?.type !== 'message' ||
|
|
36
|
+
payload.role !== 'assistant' ||
|
|
37
|
+
payload.phase !== 'final_answer')
|
|
38
|
+
continue;
|
|
39
|
+
return messageText(payload.content);
|
|
246
40
|
}
|
|
247
41
|
return undefined;
|
|
248
42
|
}
|
|
249
|
-
function
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return
|
|
259
|
-
}
|
|
260
|
-
function postRunDecision(decision) {
|
|
261
|
-
return decision.decision === 'block' && decision.reason !== undefined
|
|
262
|
-
? { ...decision, reason: `caught by post-run verification: ${decision.reason}` }
|
|
263
|
-
: decision;
|
|
43
|
+
function messageText(content) {
|
|
44
|
+
if (!Array.isArray(content))
|
|
45
|
+
return undefined;
|
|
46
|
+
const texts = content.map((item) => {
|
|
47
|
+
const entry = record(item);
|
|
48
|
+
if (entry?.type !== 'output_text')
|
|
49
|
+
return undefined;
|
|
50
|
+
return string(entry.text);
|
|
51
|
+
});
|
|
52
|
+
return texts.every((text) => text !== undefined) ? texts.join('') : undefined;
|
|
264
53
|
}
|
|
265
54
|
function parseJson(value) {
|
|
266
55
|
try {
|
|
@@ -270,9 +59,6 @@ function parseJson(value) {
|
|
|
270
59
|
return undefined;
|
|
271
60
|
}
|
|
272
61
|
}
|
|
273
|
-
function toolName(value) {
|
|
274
|
-
return value === 'exec' || value === 'wait' ? value : undefined;
|
|
275
|
-
}
|
|
276
62
|
function record(value) {
|
|
277
63
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
278
64
|
? value
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ProviderQuotaExceededFailureKind } from '../../contracts/runner.js';
|
|
2
|
-
import {
|
|
3
|
-
import { verifyCodexSession } from '../codex-stop-hook.js';
|
|
2
|
+
import { WorkspaceMode } from '../../contracts/vocabulary.js';
|
|
4
3
|
import { cliRunner } from './claude.js';
|
|
5
4
|
// Deliberately narrow: only genuine provider usage/rate-limit phrasing.
|
|
6
5
|
// Auth/login failures (unauthorized, authentication, api key, not logged
|
|
@@ -45,23 +44,7 @@ export function createCodexRunner(options = {}) {
|
|
|
45
44
|
classifyFailure: classifyCodexFailure,
|
|
46
45
|
supportsSessionResume: true,
|
|
47
46
|
});
|
|
48
|
-
return
|
|
49
|
-
supportsSessionResume: true,
|
|
50
|
-
async start(request, signal) {
|
|
51
|
-
const execution = await runner.start(request, signal);
|
|
52
|
-
return {
|
|
53
|
-
...execution,
|
|
54
|
-
result: execution.result.then(async (result) => {
|
|
55
|
-
if (result.transport !== RunStatus.Succeeded)
|
|
56
|
-
return result;
|
|
57
|
-
const decision = await verifyCodexSession(options.codexHome ?? process.env.CODEX_HOME, result.sessionId);
|
|
58
|
-
return decision.decision === undefined
|
|
59
|
-
? result
|
|
60
|
-
: { ...result, unverifiedCompletionReason: decision.reason };
|
|
61
|
-
}),
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
};
|
|
47
|
+
return runner;
|
|
65
48
|
}
|
|
66
49
|
export function codexCommandArgs(request, passthroughArgs = [], defaults = {}) {
|
|
67
50
|
const model = request.model ?? defaults.model;
|
|
@@ -79,9 +62,11 @@ export function codexCommandArgs(request, passthroughArgs = [], defaults = {}) {
|
|
|
79
62
|
: ['-c', `model_reasoning_effort=${request.effort ?? defaults.effort}`]),
|
|
80
63
|
...(request.resumeSessionId === undefined ? [] : ['resume', request.resumeSessionId]),
|
|
81
64
|
...passthroughArgs,
|
|
82
|
-
request.prompt
|
|
65
|
+
`${request.prompt}\n\n${waitBackgroundInstruction}`,
|
|
83
66
|
];
|
|
84
67
|
}
|
|
68
|
+
// Work around Codex's missing background-command lifecycle contract (https://github.com/openai/codex/issues/32505, https://github.com/openai/codex/issues/34866).
|
|
69
|
+
const waitBackgroundInstruction = `When a command you started is still running or lacks a terminal result, do not report a normal Wake outcome. Make your entire final response exactly WAIT_BACKGROUND. Wake will reject that stop attempt and ask you to continue. After that hook prompt, poll the still-running command and report a normal terminal status only after it has settled. Do not use WAIT_BACKGROUND for a human-input or implementation blocker.`;
|
|
85
70
|
function codexSandboxMode(workspaceMode) {
|
|
86
71
|
return workspaceMode === WorkspaceMode.Branch ? 'danger-full-access' : 'workspace-write';
|
|
87
72
|
}
|