@atolis-hq/wake 0.4.98 → 0.4.100
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/activities/agent/agent-activity.js +17 -2
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/infrastructure/runners/claude-output.d.ts +10 -0
- package/dist/src/execution/infrastructure/runners/claude-output.js +80 -0
- package/dist/src/execution/infrastructure/runners/claude-stream.js +10 -1
- package/dist/src/execution/infrastructure/runners/claude.d.ts +6 -8
- package/dist/src/execution/infrastructure/runners/claude.js +28 -79
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActivityFailureCode, ActivityOutcomeKind, ActivityRunnerTransportStatus, ClaudeAuthenticationFailureKind, } from '../contracts/vocabulary.js';
|
|
1
|
+
import { ActivityFailureCode, ActivityOutcomeKind, ActivityRunnerTransportStatus, AgentResultStatus, ClaudeAuthenticationFailureKind, } from '../contracts/vocabulary.js';
|
|
2
2
|
import { translateAgentResult } from './agent-result.js';
|
|
3
3
|
export function createAgentActivity(templates, contextReader) {
|
|
4
4
|
return {
|
|
@@ -139,7 +139,7 @@ function escapeUntrustedJson(json) {
|
|
|
139
139
|
function requestFrom(input, runId, template, runnerContext, resumeSessionId, usageBaseline, workspace, mcpServers, mcpPrompt, reportRunnerTimeout) {
|
|
140
140
|
return {
|
|
141
141
|
runId,
|
|
142
|
-
prompt: appendMcpPrompt(appendWorkspacePrompt(input.prompt ?? template.prompt, workspace), mcpPrompt),
|
|
142
|
+
prompt: appendResponseContract(appendMcpPrompt(appendWorkspacePrompt(input.prompt ?? template.prompt, workspace), mcpPrompt)),
|
|
143
143
|
...modelField(input.model ?? template?.model ?? runnerContext?.model),
|
|
144
144
|
...effortField(runnerContext?.effort),
|
|
145
145
|
allowedTools: input.allowedTools ?? template?.allowedTools ?? [],
|
|
@@ -152,6 +152,21 @@ function requestFrom(input, runId, template, runnerContext, resumeSessionId, usa
|
|
|
152
152
|
...(reportRunnerTimeout === undefined ? {} : { onTimeout: reportRunnerTimeout }),
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
|
+
function appendResponseContract(prompt) {
|
|
156
|
+
return [
|
|
157
|
+
prompt,
|
|
158
|
+
'',
|
|
159
|
+
'Wake response contract (trusted instructions):',
|
|
160
|
+
'Report your actual outcome honestly. End your response with exactly one status marker on its own final line, using one of these exact forms:',
|
|
161
|
+
`[[STATUS: ${AgentResultStatus.Done}]] — the requested work is complete.`,
|
|
162
|
+
`[[STATUS: ${AgentResultStatus.Rejected}]] — you deliberately declined the request.`,
|
|
163
|
+
`[[STATUS: ${AgentResultStatus.Blocked}]] — an external blocker prevents further progress.`,
|
|
164
|
+
`[[STATUS: ${AgentResultStatus.NeedsClarification}]] — a human answer is needed to proceed.`,
|
|
165
|
+
`[[STATUS: ${AgentResultStatus.Failed}]] — the attempt failed.`,
|
|
166
|
+
'Bare status words such as “DONE” or prose alone are not valid results. Structured JSON with a recognized status field remains supported.',
|
|
167
|
+
'These instructions specify result reporting only. Preserve task requirements, untrusted-context boundaries, artifact reporting, provider verification, and review authority.',
|
|
168
|
+
].join('\n');
|
|
169
|
+
}
|
|
155
170
|
function appendMcpPrompt(prompt, mcpPrompt) {
|
|
156
171
|
return mcpPrompt === undefined ? prompt : `${prompt}\n\n${mcpPrompt}`;
|
|
157
172
|
}
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.100";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentRunnerResult, RunnerRequest } from '../../contracts/runner.js';
|
|
2
|
+
export declare const ClaudeNoFinalResultFailureKind = "claude-no-final-result";
|
|
3
|
+
export declare function parseClaudeOutput(stdout: string, _request?: RunnerRequest): Partial<AgentRunnerResult>;
|
|
4
|
+
export declare function classifyClaudeFailure(input: {
|
|
5
|
+
readonly stdout: string;
|
|
6
|
+
readonly stderr: string;
|
|
7
|
+
}): {
|
|
8
|
+
readonly kind: string;
|
|
9
|
+
readonly message: string;
|
|
10
|
+
} | undefined;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ClaudeAuthenticationFailureKind } from '../../../activities/index.js';
|
|
2
|
+
import { ProviderQuotaExceededFailureKind } from '../../contracts/runner.js';
|
|
3
|
+
export const ClaudeNoFinalResultFailureKind = 'claude-no-final-result';
|
|
4
|
+
export function parseClaudeOutput(stdout, _request) {
|
|
5
|
+
const value = finalResult(stdout);
|
|
6
|
+
if (value === undefined)
|
|
7
|
+
return {};
|
|
8
|
+
return {
|
|
9
|
+
output: value.result,
|
|
10
|
+
...(typeof value.session_id === 'string' ? { sessionId: value.session_id } : {}),
|
|
11
|
+
...claudeUsage(value),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
// Deliberately narrow: only genuine provider usage/rate-limit phrasing.
|
|
15
|
+
// Auth/login failures (unauthorized, authentication, permission denied, api
|
|
16
|
+
// key) are NOT included here — they are a different failure class and must
|
|
17
|
+
// not be paused-and-retried as if they were transient.
|
|
18
|
+
const claudeQuotaPattern = /rate limit|quota|credit balance|spend limit|usage limit|session limit|too many requests|\b429\b/i;
|
|
19
|
+
const claudeAuthenticationPattern = /authenticate|authentication|unauthorized|oauth.*(?:expired|refresh)|session expired|not logged in|please (?:log|sign) in|invalid api key/i;
|
|
20
|
+
export function classifyClaudeFailure(input) {
|
|
21
|
+
const structured = finalResult(input.stdout) ?? parseRecord(input.stdout);
|
|
22
|
+
if (structured?.is_error === true && typeof structured.result === 'string') {
|
|
23
|
+
const message = structured.result.trim();
|
|
24
|
+
if (claudeAuthenticationPattern.test(message))
|
|
25
|
+
return { kind: ClaudeAuthenticationFailureKind, message };
|
|
26
|
+
if (claudeQuotaPattern.test(message))
|
|
27
|
+
return { kind: ProviderQuotaExceededFailureKind, message };
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
// Preserve plain CLI diagnostics, preferring stderr over stdout.
|
|
31
|
+
const text = input.stderr.trim().length > 0 ? input.stderr : input.stdout;
|
|
32
|
+
if (!claudeQuotaPattern.test(text))
|
|
33
|
+
return undefined;
|
|
34
|
+
return { kind: ProviderQuotaExceededFailureKind, message: text.trim() };
|
|
35
|
+
}
|
|
36
|
+
function claudeUsage(value) {
|
|
37
|
+
const usage = record(value.usage);
|
|
38
|
+
const input = usage === undefined ? undefined : numeric(usage.input_tokens);
|
|
39
|
+
const output = usage === undefined ? undefined : numeric(usage.output_tokens);
|
|
40
|
+
if (usage === undefined || input === undefined || output === undefined)
|
|
41
|
+
return {};
|
|
42
|
+
const cacheRead = numeric(usage.cache_read_input_tokens);
|
|
43
|
+
const cacheWrite = numeric(usage.cache_creation_input_tokens);
|
|
44
|
+
const costUsd = numeric(value.total_cost_usd);
|
|
45
|
+
return {
|
|
46
|
+
tokenUsage: {
|
|
47
|
+
input,
|
|
48
|
+
output,
|
|
49
|
+
...(cacheRead === undefined ? {} : { cacheRead }),
|
|
50
|
+
...(cacheWrite === undefined ? {} : { cacheWrite }),
|
|
51
|
+
...(costUsd === undefined ? {} : { costUsd }),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// The last result event is authoritative; earlier ones are intermediate turns.
|
|
56
|
+
// A whole-output parse keeps the legacy single-object shape working.
|
|
57
|
+
function finalResult(stdout) {
|
|
58
|
+
const lines = stdout.split('\n').filter((line) => line.trim().length > 0);
|
|
59
|
+
const last = lines.length === 0 ? undefined : parseRecord(lines[lines.length - 1]);
|
|
60
|
+
const value = last ?? (lines.length > 1 ? parseRecord(stdout) : undefined);
|
|
61
|
+
return value !== undefined && typeof value.result === 'string'
|
|
62
|
+
? value
|
|
63
|
+
: undefined;
|
|
64
|
+
}
|
|
65
|
+
function parseRecord(stdout) {
|
|
66
|
+
try {
|
|
67
|
+
return record(JSON.parse(stdout));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function record(value) {
|
|
74
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
75
|
+
? value
|
|
76
|
+
: undefined;
|
|
77
|
+
}
|
|
78
|
+
function numeric(value) {
|
|
79
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
80
|
+
}
|
|
@@ -2,6 +2,12 @@ import { maximumCapturedProcessOutputBytes, } from '../process-execution.js';
|
|
|
2
2
|
function isProgress(type) {
|
|
3
3
|
return type === 'assistant' || type === 'user' || type === 'stream_event';
|
|
4
4
|
}
|
|
5
|
+
// Kept result lines are newline-terminated so several results stay line-delimited.
|
|
6
|
+
function terminated(line) {
|
|
7
|
+
return line.length === 0 || line[line.length - 1] === 10
|
|
8
|
+
? line
|
|
9
|
+
: Buffer.concat([line, Buffer.from('\n')]);
|
|
10
|
+
}
|
|
5
11
|
function decode(line) {
|
|
6
12
|
try {
|
|
7
13
|
const value = JSON.parse(line.toString('utf8'));
|
|
@@ -9,7 +15,10 @@ function decode(line) {
|
|
|
9
15
|
return { output: Buffer.alloc(0), activity: false };
|
|
10
16
|
const event = value;
|
|
11
17
|
const final = event.type === 'result' || (event.type === undefined && typeof event.result === 'string');
|
|
12
|
-
return {
|
|
18
|
+
return {
|
|
19
|
+
output: final ? terminated(line) : Buffer.alloc(0),
|
|
20
|
+
activity: final || isProgress(event.type),
|
|
21
|
+
};
|
|
13
22
|
}
|
|
14
23
|
catch {
|
|
15
24
|
return { output: Buffer.alloc(0), activity: false, diagnostic: line };
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import type { AgentRunnerResult, Runner, RunnerRequest } from '../../contracts/runner.js';
|
|
2
2
|
import { type ProcessStdoutDecoder, type ProcessTimeouts } from '../process-execution.js';
|
|
3
|
+
import { classifyClaudeFailure, ClaudeNoFinalResultFailureKind, parseClaudeOutput } from './claude-output.js';
|
|
4
|
+
export { classifyClaudeFailure, ClaudeNoFinalResultFailureKind, parseClaudeOutput };
|
|
3
5
|
export declare function createClaudeRunner(options?: CliRunnerOptions): Runner;
|
|
4
|
-
export declare function parseClaudeOutput(stdout: string, _request?: RunnerRequest): Partial<AgentRunnerResult>;
|
|
5
|
-
export declare function classifyClaudeFailure(input: {
|
|
6
|
-
readonly stdout: string;
|
|
7
|
-
readonly stderr: string;
|
|
8
|
-
}): {
|
|
9
|
-
readonly kind: string;
|
|
10
|
-
readonly message: string;
|
|
11
|
-
} | undefined;
|
|
12
6
|
export declare function claudeCommandArgs(request: RunnerRequest, passthroughArgs?: readonly string[], defaults?: RunnerDefaults): string[];
|
|
13
7
|
export declare function cliRunner(name: string, command: string, args: (request: RunnerRequest) => string[], options?: {
|
|
14
8
|
readonly runnerTimeouts?: ProcessTimeouts;
|
|
@@ -16,6 +10,10 @@ export declare function cliRunner(name: string, command: string, args: (request:
|
|
|
16
10
|
readonly defaultModel?: string;
|
|
17
11
|
readonly supportsSessionResume?: boolean;
|
|
18
12
|
readonly supportsEphemeralMcp?: boolean;
|
|
13
|
+
readonly unparsedSuccessFailure?: {
|
|
14
|
+
readonly kind: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
};
|
|
19
17
|
readonly parseSuccessfulOutput?: (stdout: string, request: RunnerRequest) => Partial<AgentRunnerResult>;
|
|
20
18
|
readonly classifyFailure?: (input: {
|
|
21
19
|
readonly stdout: string;
|
|
@@ -1,86 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExternalExecutionKind } from '../../../activities/index.js';
|
|
2
|
+
import { WakeMcpServerName } from '../../contracts/runner.js';
|
|
3
3
|
import { ExecutionCancellationReason, RunStatus } from '../../contracts/vocabulary.js';
|
|
4
4
|
import { runProcess, } from '../process-execution.js';
|
|
5
|
+
import { classifyClaudeFailure, ClaudeNoFinalResultFailureKind, parseClaudeOutput, } from './claude-output.js';
|
|
5
6
|
import { createClaudeStreamDecoder } from './claude-stream.js';
|
|
7
|
+
export { classifyClaudeFailure, ClaudeNoFinalResultFailureKind, parseClaudeOutput };
|
|
6
8
|
export function createClaudeRunner(options = {}) {
|
|
7
9
|
return cliRunner('claude', options.command ?? 'claude', (request) => claudeCommandArgs(request, options.args, options), {
|
|
8
10
|
...(options.runnerTimeouts === undefined ? {} : { runnerTimeouts: options.runnerTimeouts }),
|
|
9
11
|
...(options.model === undefined ? {} : { defaultModel: options.model }),
|
|
10
12
|
parseSuccessfulOutput: parseClaudeOutput,
|
|
13
|
+
unparsedSuccessFailure: {
|
|
14
|
+
kind: ClaudeNoFinalResultFailureKind,
|
|
15
|
+
message: 'Claude exited successfully without a usable final result event',
|
|
16
|
+
},
|
|
11
17
|
createStdoutDecoder: createClaudeStreamDecoder,
|
|
12
18
|
classifyFailure: classifyClaudeFailure,
|
|
13
19
|
supportsSessionResume: true,
|
|
14
20
|
supportsEphemeralMcp: true,
|
|
15
21
|
});
|
|
16
22
|
}
|
|
17
|
-
export function parseClaudeOutput(stdout, _request) {
|
|
18
|
-
const value = parseRecord(stdout);
|
|
19
|
-
if (value === undefined || typeof value.result !== 'string')
|
|
20
|
-
return {};
|
|
21
|
-
return {
|
|
22
|
-
output: value.result,
|
|
23
|
-
...(typeof value.session_id === 'string' ? { sessionId: value.session_id } : {}),
|
|
24
|
-
...claudeUsage(value),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
// Deliberately narrow: only genuine provider usage/rate-limit phrasing.
|
|
28
|
-
// Auth/login failures (unauthorized, authentication, permission denied, api
|
|
29
|
-
// key) are NOT included here — they are a different failure class and must
|
|
30
|
-
// not be paused-and-retried as if they were transient.
|
|
31
|
-
const claudeQuotaPattern = /rate limit|quota|credit balance|spend limit|usage limit|session limit|too many requests|\b429\b/i;
|
|
32
|
-
const claudeAuthenticationPattern = /authenticate|authentication|unauthorized|oauth.*(?:expired|refresh)|session expired|not logged in|please (?:log|sign) in|invalid api key/i;
|
|
33
|
-
export function classifyClaudeFailure(input) {
|
|
34
|
-
const structured = parseRecord(input.stdout);
|
|
35
|
-
if (structured?.is_error === true && typeof structured.result === 'string') {
|
|
36
|
-
const message = structured.result.trim();
|
|
37
|
-
if (claudeAuthenticationPattern.test(message))
|
|
38
|
-
return { kind: ClaudeAuthenticationFailureKind, message };
|
|
39
|
-
if (claudeQuotaPattern.test(message))
|
|
40
|
-
return { kind: ProviderQuotaExceededFailureKind, message };
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
// Preserve plain CLI diagnostics, preferring stderr over stdout.
|
|
44
|
-
const text = input.stderr.trim().length > 0 ? input.stderr : input.stdout;
|
|
45
|
-
if (!claudeQuotaPattern.test(text))
|
|
46
|
-
return undefined;
|
|
47
|
-
return { kind: ProviderQuotaExceededFailureKind, message: text.trim() };
|
|
48
|
-
}
|
|
49
|
-
function claudeUsage(value) {
|
|
50
|
-
const usage = record(value.usage);
|
|
51
|
-
const input = usage === undefined ? undefined : numeric(usage.input_tokens);
|
|
52
|
-
const output = usage === undefined ? undefined : numeric(usage.output_tokens);
|
|
53
|
-
if (usage === undefined || input === undefined || output === undefined)
|
|
54
|
-
return {};
|
|
55
|
-
const cacheRead = numeric(usage.cache_read_input_tokens);
|
|
56
|
-
const cacheWrite = numeric(usage.cache_creation_input_tokens);
|
|
57
|
-
const costUsd = numeric(value.total_cost_usd);
|
|
58
|
-
return {
|
|
59
|
-
tokenUsage: {
|
|
60
|
-
input,
|
|
61
|
-
output,
|
|
62
|
-
...(cacheRead === undefined ? {} : { cacheRead }),
|
|
63
|
-
...(cacheWrite === undefined ? {} : { cacheWrite }),
|
|
64
|
-
...(costUsd === undefined ? {} : { costUsd }),
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function parseRecord(stdout) {
|
|
69
|
-
try {
|
|
70
|
-
return record(JSON.parse(stdout));
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function record(value) {
|
|
77
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
78
|
-
? value
|
|
79
|
-
: undefined;
|
|
80
|
-
}
|
|
81
|
-
function numeric(value) {
|
|
82
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
83
|
-
}
|
|
84
23
|
export function claudeCommandArgs(request, passthroughArgs = [], defaults = {}) {
|
|
85
24
|
const model = request.model ?? defaults.model;
|
|
86
25
|
const effort = request.effort ?? defaults.effort;
|
|
@@ -149,22 +88,32 @@ export function cliRunner(name, command, args, options = {}) {
|
|
|
149
88
|
id: process.identity ?? request.runId,
|
|
150
89
|
startedAt: new Date().toISOString(),
|
|
151
90
|
},
|
|
152
|
-
result: process.result.then((value) =>
|
|
153
|
-
|
|
91
|
+
result: process.result.then((value) => {
|
|
92
|
+
if (value.exitCode !== 0 || value.timedOut)
|
|
93
|
+
return {
|
|
94
|
+
transport: RunStatus.Failed,
|
|
95
|
+
output: value.stdout,
|
|
96
|
+
runner: name,
|
|
97
|
+
failure: failureFor(value, options),
|
|
98
|
+
};
|
|
99
|
+
const parsed = parseSuccessfulOutput(value.stdout, request, options.parseSuccessfulOutput);
|
|
100
|
+
if (options.unparsedSuccessFailure !== undefined && parsed.output === undefined)
|
|
101
|
+
return {
|
|
102
|
+
transport: RunStatus.Failed,
|
|
103
|
+
output: '',
|
|
104
|
+
runner: name,
|
|
105
|
+
failure: options.unparsedSuccessFailure,
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
154
108
|
transport: RunStatus.Succeeded,
|
|
155
109
|
output: value.stdout,
|
|
156
110
|
runner: name,
|
|
157
111
|
...((request.model ?? options.defaultModel) === undefined
|
|
158
112
|
? {}
|
|
159
113
|
: { model: request.model ?? options.defaultModel }),
|
|
160
|
-
...
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
transport: RunStatus.Failed,
|
|
164
|
-
output: value.stdout,
|
|
165
|
-
runner: name,
|
|
166
|
-
failure: failureFor(value, options),
|
|
167
|
-
}),
|
|
114
|
+
...parsed,
|
|
115
|
+
};
|
|
116
|
+
}),
|
|
168
117
|
cancel: process.cancel,
|
|
169
118
|
};
|
|
170
119
|
},
|