@atolis-hq/wake 0.3.104 → 0.3.105

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.
@@ -168,6 +168,11 @@ function contextField(runnerContext, templateName) {
168
168
  return { context: { ...runnerContext, action: templateName ?? 'prompt' } };
169
169
  }
170
170
  function agentOutcome(result) {
171
+ if (result.unverifiedCompletionReason !== undefined)
172
+ return {
173
+ kind: ActivityOutcomeKind.Blocked,
174
+ data: { status: 'BLOCKED', unverifiedCompletionReason: result.unverifiedCompletionReason },
175
+ };
171
176
  if (result.transport === ActivityRunnerTransportStatus.Ambiguous)
172
177
  return {
173
178
  kind: ActivityOutcomeKind.Blocked,
@@ -371,6 +371,22 @@ COPY . .
371
371
  ARG WAKE_BUILD_TAG
372
372
  RUN WAKE_BUILD_TAG="$WAKE_BUILD_TAG" npm run build:docker
373
373
 
374
+ RUN mkdir -p /etc/codex /usr/local/lib/wake \\
375
+ && cp /app/dist/src/execution/infrastructure/codex-stop-hook.js /usr/local/lib/wake/codex-stop-hook.js \\
376
+ && printf '%s\\n' \\
377
+ '[features]' \\
378
+ 'hooks = true' \\
379
+ '' \\
380
+ '[hooks]' \\
381
+ 'managed_dir = "/usr/local/lib/wake"' \\
382
+ '' \\
383
+ '[[hooks.Stop]]' \\
384
+ '[[hooks.Stop.hooks]]' \\
385
+ 'type = "command"' \\
386
+ 'command = "node /usr/local/lib/wake/codex-stop-hook.js"' \\
387
+ 'timeout = 10' \\
388
+ > /etc/codex/requirements.toml
389
+
374
390
  USER root
375
391
  WORKDIR /home/wake
376
392
 
@@ -418,6 +434,22 @@ ARG WAKE_VERSION=0.1.0
418
434
  RUN --mount=type=cache,target=/root/.npm \\
419
435
  npm install -g @anthropic-ai/claude-code @openai/codex "@atolis-hq/wake@\${WAKE_VERSION}"
420
436
 
437
+ RUN mkdir -p /etc/codex /usr/local/lib/wake \\
438
+ && cp /usr/local/lib/node_modules/@atolis-hq/wake/dist/src/execution/infrastructure/codex-stop-hook.js /usr/local/lib/wake/codex-stop-hook.js \\
439
+ && printf '%s\\n' \\
440
+ '[features]' \\
441
+ 'hooks = true' \\
442
+ '' \\
443
+ '[hooks]' \\
444
+ 'managed_dir = "/usr/local/lib/wake"' \\
445
+ '' \\
446
+ '[[hooks.Stop]]' \\
447
+ '[[hooks.Stop.hooks]]' \\
448
+ 'type = "command"' \\
449
+ 'command = "node /usr/local/lib/wake/codex-stop-hook.js"' \\
450
+ 'timeout = 10' \\
451
+ > /etc/codex/requirements.toml
452
+
421
453
  RUN useradd --create-home --shell /bin/bash wake \\
422
454
  && mkdir -p /home/wake/.codex-runtime \\
423
455
  && mkdir -p /home/wake/.cursor \\
@@ -108,4 +108,4 @@ export function resolveWakeVersion(options = {}) {
108
108
  return `g${headHash.slice(0, 7)}`;
109
109
  return '0.1.0-dev';
110
110
  }
111
- export const wakeVersion = "gfb06c98";
111
+ export const wakeVersion = "g9d4371e";
@@ -21,6 +21,7 @@ export * from './domain/run.js';
21
21
  export * from './infrastructure/prompt-templates.js';
22
22
  export * from './infrastructure/runners/claude.js';
23
23
  export * from './infrastructure/runners/codex.js';
24
+ export * from './infrastructure/codex-stop-hook.js';
24
25
  export * from './infrastructure/runners/command.js';
25
26
  export * from './infrastructure/runners/cursor.js';
26
27
  export * from './infrastructure/runners/fake.js';
@@ -1,11 +1,18 @@
1
1
  import { RunStatus } from '../contracts/vocabulary.js';
2
2
  export function parseAgentRunnerResponse(result) {
3
3
  const parsed = parseResult(result.output);
4
+ const outcome = result.transport === RunStatus.Succeeded && result.unverifiedCompletionReason !== undefined
5
+ ? 'BLOCKED'
6
+ : result.transport === RunStatus.Succeeded
7
+ ? parsed.outcome
8
+ : 'FAILED';
4
9
  return {
5
- outcome: result.transport === RunStatus.Succeeded ? parsed.outcome : 'FAILED',
6
- displayBody: result.transport === RunStatus.Succeeded
10
+ outcome,
11
+ displayBody: result.transport === RunStatus.Succeeded && result.unverifiedCompletionReason === undefined
7
12
  ? parsed.displayBody
8
- : result.failure?.message || parsed.displayBody || 'Runner failed without a response.',
13
+ : result.unverifiedCompletionReason !== undefined
14
+ ? result.unverifiedCompletionReason
15
+ : result.failure?.message || parsed.displayBody || 'Runner failed without a response.',
9
16
  metadata: metadata(result),
10
17
  };
11
18
  }
@@ -0,0 +1,183 @@
1
+ import { readFile, readdir } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ export const unverifiedCodexCompletionReason = 'unverified: could not confirm background command completion from Codex structured telemetry';
5
+ /**
6
+ * Inspect only Codex's structured function-call protocol. Command output is
7
+ * opaque except for the protocol's managed-cell and terminal-result envelopes.
8
+ */
9
+ export function inspectCodexTranscript(transcript) {
10
+ const telemetry = {
11
+ calls: new Map(),
12
+ pendingCells: new Set(),
13
+ resolvedCells: new Set(),
14
+ };
15
+ for (const line of transcript.split(/\r?\n/)) {
16
+ if (line.trim().length === 0)
17
+ continue;
18
+ const event = parseJson(line);
19
+ if (event === undefined)
20
+ return blocked('could not parse Codex structured telemetry');
21
+ const payload = record(event.payload);
22
+ if (payload !== undefined)
23
+ consumePayload(payload, telemetry);
24
+ }
25
+ const unresolved = [...telemetry.pendingCells].filter((cellId) => !telemetry.resolvedCells.has(cellId));
26
+ return unresolved.length === 0
27
+ ? {}
28
+ : blocked(`Codex cell ${unresolved[0]} has no terminal exit_code; continue polling that cell`);
29
+ }
30
+ function consumePayload(payload, telemetry) {
31
+ if (payload.type === 'function_call' || payload.type === 'custom_tool_call') {
32
+ recordToolCall(payload, telemetry.calls);
33
+ return;
34
+ }
35
+ if (payload.type === 'custom_tool_call_output' || payload.type === 'function_call_output')
36
+ recordToolOutput(payload, telemetry);
37
+ }
38
+ function recordToolCall(payload, calls) {
39
+ const callId = string(payload.call_id);
40
+ const name = toolName(payload.name);
41
+ if (callId === undefined || name === undefined)
42
+ return;
43
+ calls.set(callId, {
44
+ name,
45
+ ...(name === 'wait' ? cellArgument(payload.arguments ?? payload.input) : {}),
46
+ });
47
+ }
48
+ function recordToolOutput(payload, telemetry) {
49
+ const callId = string(payload.call_id);
50
+ if (callId === undefined)
51
+ return;
52
+ const call = telemetry.calls.get(callId);
53
+ if (call === undefined)
54
+ return;
55
+ const result = structuredResult(payload.output);
56
+ if (call.name === 'exec') {
57
+ if (result.exitCode === undefined && result.pendingCellId !== undefined)
58
+ telemetry.pendingCells.add(result.pendingCellId);
59
+ return;
60
+ }
61
+ if (call.cellId !== undefined && result.exitCode !== undefined)
62
+ telemetry.resolvedCells.add(call.cellId);
63
+ }
64
+ export async function runCodexStopHook(input) {
65
+ const payload = record(input);
66
+ const transcriptPath = payload === undefined ? undefined : string(payload.transcript_path);
67
+ if (transcriptPath === undefined)
68
+ return blocked('Stop hook received no transcript_path');
69
+ try {
70
+ return inspectCodexTranscript(await readFile(transcriptPath, 'utf8'));
71
+ }
72
+ catch {
73
+ return blocked('could not read Codex transcript');
74
+ }
75
+ }
76
+ export async function verifyCodexSession(codexHome, sessionId) {
77
+ if (codexHome === undefined || sessionId === undefined)
78
+ return postRunBlocked('could not locate Codex structured telemetry');
79
+ const transcriptPath = await transcriptForSession(join(codexHome, 'sessions'), sessionId);
80
+ if (transcriptPath === undefined)
81
+ return postRunBlocked('could not locate Codex structured telemetry');
82
+ return postRunDecision(await runCodexStopHook({ transcript_path: transcriptPath }));
83
+ }
84
+ async function transcriptForSession(directory, sessionId) {
85
+ try {
86
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
87
+ const path = join(directory, entry.name);
88
+ if (entry.isDirectory()) {
89
+ const nested = await transcriptForSession(path, sessionId);
90
+ if (nested !== undefined)
91
+ return nested;
92
+ }
93
+ else if (entry.isFile() && entry.name.endsWith(`-${sessionId}.jsonl`))
94
+ return path;
95
+ }
96
+ }
97
+ catch {
98
+ return undefined;
99
+ }
100
+ return undefined;
101
+ }
102
+ function structuredResult(value) {
103
+ const texts = outputTexts(value);
104
+ let exitCode;
105
+ let pendingCellId;
106
+ for (const text of texts) {
107
+ const parsed = parseJson(text);
108
+ const result = parsed === undefined ? undefined : record(parsed);
109
+ const code = result === undefined ? undefined : number(result.exit_code);
110
+ const renderedCode = /Exit code:\s*(-?\d+)/.exec(text)?.[1];
111
+ if (code !== undefined)
112
+ exitCode = code;
113
+ else if (renderedCode !== undefined)
114
+ exitCode = Number(renderedCode);
115
+ const pending = /Script running with cell ID ([^\s]+)/.exec(text)?.[1];
116
+ if (pending !== undefined)
117
+ pendingCellId = pending;
118
+ }
119
+ return {
120
+ ...(exitCode === undefined ? {} : { exitCode }),
121
+ ...(pendingCellId === undefined ? {} : { pendingCellId }),
122
+ };
123
+ }
124
+ function outputTexts(value) {
125
+ if (typeof value === 'string')
126
+ return [value];
127
+ if (!Array.isArray(value))
128
+ return [];
129
+ return value.flatMap((item) => {
130
+ const content = record(item);
131
+ const text = content === undefined ? undefined : string(content.text);
132
+ return text === undefined ? [] : [text];
133
+ });
134
+ }
135
+ function cellArgument(value) {
136
+ const arguments_ = typeof value === 'string' ? parseJson(value) : record(value);
137
+ const cellId = arguments_ === undefined ? undefined : string(arguments_.cell_id);
138
+ return cellId === undefined ? {} : { cellId };
139
+ }
140
+ function blocked(detail) {
141
+ return { decision: 'block', reason: `${unverifiedCodexCompletionReason}: ${detail}` };
142
+ }
143
+ function postRunBlocked(detail) {
144
+ return postRunDecision(blocked(detail));
145
+ }
146
+ function postRunDecision(decision) {
147
+ return decision.decision === 'block' && decision.reason !== undefined
148
+ ? { ...decision, reason: `caught by post-run verification: ${decision.reason}` }
149
+ : decision;
150
+ }
151
+ function parseJson(value) {
152
+ try {
153
+ return record(JSON.parse(value));
154
+ }
155
+ catch {
156
+ return undefined;
157
+ }
158
+ }
159
+ function toolName(value) {
160
+ return value === 'exec' || value === 'wait' ? value : undefined;
161
+ }
162
+ function record(value) {
163
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
164
+ ? value
165
+ : undefined;
166
+ }
167
+ function string(value) {
168
+ return typeof value === 'string' ? value : undefined;
169
+ }
170
+ function number(value) {
171
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
172
+ }
173
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
174
+ let input = '';
175
+ process.stdin.setEncoding('utf8');
176
+ process.stdin.on('data', (chunk) => {
177
+ input += chunk;
178
+ });
179
+ process.stdin.on('end', () => {
180
+ const payload = parseJson(input);
181
+ void runCodexStopHook(payload).then((decision) => process.stdout.write(JSON.stringify(decision)));
182
+ });
183
+ }
@@ -1,5 +1,6 @@
1
1
  import { ProviderQuotaExceededFailureKind } from '../../contracts/runner.js';
2
- import { WorkspaceMode } from '../../contracts/vocabulary.js';
2
+ import { RunStatus, WorkspaceMode } from '../../contracts/vocabulary.js';
3
+ import { verifyCodexSession } from '../codex-stop-hook.js';
3
4
  import { cliRunner } from './claude.js';
4
5
  // Deliberately narrow: only genuine provider usage/rate-limit phrasing.
5
6
  // Auth/login failures (unauthorized, authentication, api key, not logged
@@ -37,13 +38,30 @@ function extractCodexErrorMessage(stdout) {
37
38
  return undefined;
38
39
  }
39
40
  export function createCodexRunner(options = {}) {
40
- return cliRunner('codex', options.command ?? 'codex', (request) => codexCommandArgs(request, options.args, options), {
41
+ const runner = cliRunner('codex', options.command ?? 'codex', (request) => codexCommandArgs(request, options.args, options), {
41
42
  ...(options.runnerTimeouts === undefined ? {} : { runnerTimeouts: options.runnerTimeouts }),
42
43
  ...(options.model === undefined ? {} : { defaultModel: options.model }),
43
44
  parseSuccessfulOutput: parseCodexOutput,
44
45
  classifyFailure: classifyCodexFailure,
45
46
  supportsSessionResume: true,
46
47
  });
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
65
  }
48
66
  export function codexCommandArgs(request, passthroughArgs = [], defaults = {}) {
49
67
  const model = request.model ?? defaults.model;
package/docker/Dockerfile CHANGED
@@ -53,6 +53,22 @@ COPY src/ src/
53
53
  ARG WAKE_BUILD_TAG
54
54
  RUN WAKE_BUILD_TAG="$WAKE_BUILD_TAG" npm run build:docker
55
55
 
56
+ RUN mkdir -p /etc/codex /usr/local/lib/wake \
57
+ && cp /app/dist/src/execution/infrastructure/codex-stop-hook.js /usr/local/lib/wake/codex-stop-hook.js \
58
+ && printf '%s\n' \
59
+ '[features]' \
60
+ 'hooks = true' \
61
+ '' \
62
+ '[hooks]' \
63
+ 'managed_dir = "/usr/local/lib/wake"' \
64
+ '' \
65
+ '[[hooks.Stop]]' \
66
+ '[[hooks.Stop.hooks]]' \
67
+ 'type = "command"' \
68
+ 'command = "node /usr/local/lib/wake/codex-stop-hook.js"' \
69
+ 'timeout = 10' \
70
+ > /etc/codex/requirements.toml
71
+
56
72
  USER root
57
73
  WORKDIR /home/wake
58
74
 
@@ -25,6 +25,22 @@ RUN test -n "$WAKE_VERSION" || (echo "WAKE_VERSION build arg is required" && exi
25
25
  RUN --mount=type=cache,target=/root/.npm \
26
26
  npm install -g @anthropic-ai/claude-code @openai/codex "@atolis-hq/wake@${WAKE_VERSION}"
27
27
 
28
+ RUN mkdir -p /etc/codex /usr/local/lib/wake \
29
+ && cp /usr/local/lib/node_modules/@atolis-hq/wake/dist/src/execution/infrastructure/codex-stop-hook.js /usr/local/lib/wake/codex-stop-hook.js \
30
+ && printf '%s\n' \
31
+ '[features]' \
32
+ 'hooks = true' \
33
+ '' \
34
+ '[hooks]' \
35
+ 'managed_dir = "/usr/local/lib/wake"' \
36
+ '' \
37
+ '[[hooks.Stop]]' \
38
+ '[[hooks.Stop.hooks]]' \
39
+ 'type = "command"' \
40
+ 'command = "node /usr/local/lib/wake/codex-stop-hook.js"' \
41
+ 'timeout = 10' \
42
+ > /etc/codex/requirements.toml
43
+
28
44
  RUN useradd --create-home --shell /bin/bash wake \
29
45
  && mkdir -p /home/wake/.codex-runtime \
30
46
  && mkdir -p /home/wake/.cursor \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.3.104",
3
+ "version": "0.3.105",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {