@atolis-hq/wake 0.4.90 → 0.4.92

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.
@@ -1,4 +1,4 @@
1
- import { ActivityFailureCode, ActivityOutcomeKind, ActivityRunnerTransportStatus, } from '../contracts/vocabulary.js';
1
+ import { ActivityFailureCode, ActivityOutcomeKind, ActivityRunnerTransportStatus, ClaudeAuthenticationFailureKind, } from '../contracts/vocabulary.js';
2
2
  import { translateAgentResult } from './agent-result.js';
3
3
  export function createAgentActivity(templates, contextReader) {
4
4
  return {
@@ -185,6 +185,15 @@ function agentOutcome(result) {
185
185
  kind: ActivityOutcomeKind.Blocked,
186
186
  data: { reason: ActivityFailureCode.AmbiguousRunnerResult },
187
187
  };
188
+ if (result.transport !== ActivityRunnerTransportStatus.Succeeded &&
189
+ result.failure?.kind === ClaudeAuthenticationFailureKind)
190
+ return {
191
+ kind: ActivityOutcomeKind.Blocked,
192
+ data: {
193
+ reason: ActivityFailureCode.RunnerAuthenticationRequired,
194
+ message: result.failure.message,
195
+ },
196
+ };
188
197
  if (result.transport !== ActivityRunnerTransportStatus.Succeeded)
189
198
  return {
190
199
  kind: ActivityOutcomeKind.Failed,
@@ -23,7 +23,11 @@ export declare const agentActivityOutcomeSchema: z.ZodUnion<readonly [z.ZodObjec
23
23
  }, z.core.$catchall<z.ZodUnknown>>, z.ZodObject<{
24
24
  status: z.ZodLiteral<"NEEDS_CLARIFICATION">;
25
25
  }, z.core.$catchall<z.ZodUnknown>>, z.ZodObject<{
26
- reason: z.ZodLiteral<"ambiguous-runner-result">;
26
+ reason: z.ZodEnum<{
27
+ "ambiguous-runner-result": "ambiguous-runner-result";
28
+ "runner-authentication-required": "runner-authentication-required";
29
+ }>;
30
+ message: z.ZodOptional<z.ZodString>;
27
31
  }, z.core.$strict>]>;
28
32
  }, z.core.$strict>, z.ZodObject<{
29
33
  kind: z.ZodLiteral<"failed">;
@@ -9,7 +9,11 @@ export const reportedArtifactSchema = z
9
9
  const structuredResult = (status) => z.object({ status: z.literal(status) }).catchall(z.unknown());
10
10
  const blockedReason = z
11
11
  .object({
12
- reason: z.literal(ActivityFailureCode.AmbiguousRunnerResult),
12
+ reason: z.enum([
13
+ ActivityFailureCode.AmbiguousRunnerResult,
14
+ ActivityFailureCode.RunnerAuthenticationRequired,
15
+ ]),
16
+ message: z.string().optional(),
13
17
  })
14
18
  .strict();
15
19
  const failedReason = z
@@ -36,6 +36,7 @@ export declare const ActivityFailureCode: {
36
36
  readonly InvalidAgentResult: "invalid-agent-result";
37
37
  readonly AmbiguousRunnerResult: "ambiguous-runner-result";
38
38
  readonly RunnerFailed: "runner-failed";
39
+ readonly RunnerAuthenticationRequired: "runner-authentication-required";
39
40
  readonly RunnerQuotaExceeded: "runner-quota-exceeded";
40
41
  };
41
42
  export type ActivityFailureCode = ValueOf<typeof ActivityFailureCode>;
@@ -75,3 +76,4 @@ export declare const AgentResultStatus: {
75
76
  readonly Failed: "FAILED";
76
77
  };
77
78
  export type AgentResultStatus = ValueOf<typeof AgentResultStatus>;
79
+ export declare const ClaudeAuthenticationFailureKind = "claude-authentication-required";
@@ -31,6 +31,7 @@ export const ActivityFailureCode = defineClosedVocabulary({
31
31
  InvalidAgentResult: 'invalid-agent-result',
32
32
  AmbiguousRunnerResult: 'ambiguous-runner-result',
33
33
  RunnerFailed: 'runner-failed',
34
+ RunnerAuthenticationRequired: 'runner-authentication-required',
34
35
  RunnerQuotaExceeded: 'runner-quota-exceeded',
35
36
  });
36
37
  export const ActivityOutcomeKind = defineClosedVocabulary({
@@ -65,3 +66,4 @@ export const AgentResultStatus = {
65
66
  NeedsClarification: 'NEEDS_CLARIFICATION',
66
67
  Failed: 'FAILED',
67
68
  };
69
+ export const ClaudeAuthenticationFailureKind = 'claude-authentication-required';
@@ -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.90";
127
+ export const wakeVersion = "v0.4.92";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -1,5 +1,6 @@
1
1
  import { type DurationReport, type ReportDescriptor, type ReportQuery, type TimeSeriesReport } from '../../kernel/index.js';
2
2
  import type { RunView } from '../contracts/views.js';
3
+ export declare function runDuration(run: RunView): number | null;
3
4
  export declare function collectDurations(query: ReportQuery, buckets: TimeSeriesReport['buckets'], dimensions: readonly {
4
5
  readonly id: string;
5
6
  readonly title: string;
@@ -1,7 +1,7 @@
1
1
  import { yieldScan } from '@atolis-hq/eventing';
2
2
  import { median, } from '../../kernel/index.js';
3
3
  import { RunReportValue } from '../contracts/run-report-value.js';
4
- function runDuration(run) {
4
+ export function runDuration(run) {
5
5
  if (run.finishedAt === undefined)
6
6
  return null;
7
7
  const duration = Date.parse(run.finishedAt) - Date.parse(run.startedAt);
@@ -0,0 +1,3 @@
1
+ import type { BreakdownReport } from '../../kernel/index.js';
2
+ import type { RunView } from '../contracts/views.js';
3
+ export declare function runBreakdownMetrics(run: RunView): Omit<BreakdownReport['dimensions'][number]['rows'][number], 'value' | 'share'>;
@@ -0,0 +1,22 @@
1
+ import { agentTokenUsage } from '../contracts/runner.js';
2
+ import { runDuration } from './run-duration.js';
3
+ export function runBreakdownMetrics(run) {
4
+ const usage = agentTokenUsage(run.agent?.metadata);
5
+ const metadata = run.agent?.metadata;
6
+ const hasFinite = (key) => typeof metadata?.[key] === 'number' && Number.isFinite(metadata[key]);
7
+ const duration = runDuration(run);
8
+ return {
9
+ count: 1,
10
+ tokens: finiteOrZero(usage.tokens),
11
+ costUsd: finiteOrZero(usage.costUsd),
12
+ durationMs: duration ?? 0,
13
+ tokenRuns: ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens'].some(hasFinite)
14
+ ? 1
15
+ : 0,
16
+ costRuns: hasFinite('costUsd') ? 1 : 0,
17
+ durationRuns: duration === null ? 0 : 1,
18
+ };
19
+ }
20
+ function finiteOrZero(value) {
21
+ return Number.isFinite(value) ? value : 0;
22
+ }
@@ -3,10 +3,10 @@ import { ActivityOutcomeKind } from '../../activities/index.js';
3
3
  import { defineClosedVocabulary, } from '../../kernel/index.js';
4
4
  import { selectRunExecutionEvent } from '../contracts/events.js';
5
5
  import { RunReportValue } from '../contracts/run-report-value.js';
6
- import { agentTokenUsage } from '../contracts/runner.js';
7
6
  import { RunStatus } from '../contracts/vocabulary.js';
8
7
  import { foldRunEvent } from '../domain/run.js';
9
8
  import { collectDurations } from './run-duration.js';
9
+ import { runBreakdownMetrics } from './run-metrics.js';
10
10
  export const RunReportId = defineClosedVocabulary({
11
11
  Duration: 'run-duration',
12
12
  Outcomes: 'run-outcomes-over-time',
@@ -132,10 +132,9 @@ export async function queryRunAnalytics(journal, query, repositories) {
132
132
  totals[outcome]++;
133
133
  buckets[Math.floor((start - first) / query.window.bucketMs)].values[outcome]++;
134
134
  runs++;
135
- countDimensions(run, counts, repositoryForRun);
136
- const usage = agentTokenUsage(run.agent?.metadata);
137
- const tokens = finiteOrZero(usage.tokens);
138
- const cost = finiteOrZero(usage.costUsd);
135
+ const metrics = runBreakdownMetrics(run);
136
+ const { tokens, costUsd: cost } = metrics;
137
+ countDimensions(run, counts, metrics, repositoryForRun);
139
138
  totalTokens += tokens;
140
139
  totalCostUsd += cost;
141
140
  const bucket = usageBuckets[Math.floor((start - first) / query.window.bucketMs)];
@@ -173,9 +172,6 @@ export async function queryRunAnalytics(journal, query, repositories) {
173
172
  },
174
173
  };
175
174
  }
176
- function finiteOrZero(value) {
177
- return Number.isFinite(value) ? value : 0;
178
- }
179
175
  async function readRuns(journal, query) {
180
176
  const grouped = new Map();
181
177
  for await (const event of scanJournal(journal, query.signal)) {
@@ -195,8 +191,8 @@ function runBreakdown(query, runs, counts) {
195
191
  id,
196
192
  title,
197
193
  rows: [...counts[index].entries()]
198
- .sort(([a, ac], [b, bc]) => bc - ac || (a < b ? -1 : a > b ? 1 : 0))
199
- .map(([value, count]) => ({ value, count, share: count / runs })),
194
+ .sort(([a, ac], [b, bc]) => bc.count - ac.count || (a < b ? -1 : a > b ? 1 : 0))
195
+ .map(([value, metrics]) => ({ value, ...metrics, share: metrics.count / runs })),
200
196
  })),
201
197
  };
202
198
  }
@@ -210,12 +206,23 @@ function outcomeBuckets(first, to, bucketMs) {
210
206
  });
211
207
  return buckets;
212
208
  }
213
- function countDimensions(run, counts, repositoryForRun) {
209
+ function countDimensions(run, counts, metrics, repositoryForRun) {
214
210
  dimensions.forEach((dimension, index) => {
215
211
  const value = (dimension.id === RunReportDimension.Repository
216
212
  ? repositoryForRun?.(run)
217
213
  : dimension.value(run)) ?? RunReportValue.Unknown;
218
214
  const groups = counts[index];
219
- groups.set(value, (groups.get(value) ?? 0) + 1);
215
+ const previous = groups.get(value);
216
+ groups.set(value, previous === undefined
217
+ ? { ...metrics }
218
+ : {
219
+ count: previous.count + metrics.count,
220
+ tokens: previous.tokens + metrics.tokens,
221
+ costUsd: previous.costUsd + metrics.costUsd,
222
+ durationMs: previous.durationMs + metrics.durationMs,
223
+ tokenRuns: previous.tokenRuns + metrics.tokenRuns,
224
+ costRuns: previous.costRuns + metrics.costRuns,
225
+ durationRuns: previous.durationRuns + metrics.durationRuns,
226
+ });
220
227
  });
221
228
  }
@@ -1,4 +1,4 @@
1
- import { AgentResultStatus, parseAgentStatusMarker, translateAgentResult, } from '../../activities/index.js';
1
+ import { AgentResultStatus, ClaudeAuthenticationFailureKind, parseAgentStatusMarker, translateAgentResult, } from '../../activities/index.js';
2
2
  import { RunStatus } from '../contracts/vocabulary.js';
3
3
  export function parseAgentRunnerResponse(result) {
4
4
  const parsed = parseResult(result.output);
@@ -6,7 +6,9 @@ export function parseAgentRunnerResponse(result) {
6
6
  ? AgentResultStatus.Blocked
7
7
  : result.transport === RunStatus.Succeeded
8
8
  ? parsed.outcome
9
- : AgentResultStatus.Failed;
9
+ : result.failure?.kind === ClaudeAuthenticationFailureKind
10
+ ? AgentResultStatus.Blocked
11
+ : AgentResultStatus.Failed;
10
12
  return {
11
13
  outcome,
12
14
  displayBody: result.transport === RunStatus.Succeeded && result.unverifiedCompletionReason === undefined
@@ -1,4 +1,4 @@
1
- import { ExternalExecutionKind } from '../../../activities/index.js';
1
+ import { ClaudeAuthenticationFailureKind, ExternalExecutionKind, } from '../../../activities/index.js';
2
2
  import { ProviderQuotaExceededFailureKind, WakeMcpServerName } from '../../contracts/runner.js';
3
3
  import { ExecutionCancellationReason, RunStatus } from '../../contracts/vocabulary.js';
4
4
  import { runProcess, } from '../process-execution.js';
@@ -29,10 +29,18 @@ export function parseClaudeOutput(stdout, _request) {
29
29
  // key) are NOT included here — they are a different failure class and must
30
30
  // not be paused-and-retried as if they were transient.
31
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;
32
33
  export function classifyClaudeFailure(input) {
33
- // Prefer stderr — a CLI's own diagnostic stream — over stdout, which on a
34
- // failed run can carry the agent's own generated text; only fall back to
35
- // stdout when stderr is empty.
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.
36
44
  const text = input.stderr.trim().length > 0 ? input.stderr : input.stdout;
37
45
  if (!claudeQuotaPattern.test(text))
38
46
  return undefined;
@@ -50,6 +50,12 @@ export interface BreakdownReport {
50
50
  readonly value: string;
51
51
  readonly count: number;
52
52
  readonly share: number;
53
+ readonly tokens: number;
54
+ readonly costUsd: number;
55
+ readonly durationMs: number;
56
+ readonly tokenRuns: number;
57
+ readonly costRuns: number;
58
+ readonly durationRuns: number;
53
59
  }[];
54
60
  })[];
55
61
  }