agent-afk 5.84.3 → 5.84.5

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.
@@ -0,0 +1,16 @@
1
+ import type { TurnResult } from '../types.js';
2
+ export type RetryReason = 'ttfb' | 'overload' | 'stream-incomplete';
3
+ export type RoundOutcome = {
4
+ kind: 'terminated';
5
+ } | {
6
+ kind: 'retry';
7
+ reason: RetryReason;
8
+ } | {
9
+ kind: 'overload-exhausted';
10
+ } | {
11
+ kind: 'translator-errored';
12
+ } | {
13
+ kind: 'streamed';
14
+ turnResult: TurnResult | null;
15
+ };
16
+ export type RetryOutcome = 'continue' | 'terminated';
@@ -0,0 +1,15 @@
1
+ export declare const OVERLOAD_MAX_RETRIES = 3;
2
+ export declare const OVERLOAD_BASE_DELAY_MS = 5000;
3
+ export declare const STREAM_INCOMPLETE_MAX_RETRIES = 2;
4
+ export declare const STREAM_INCOMPLETE_BASE_DELAY_MS = 1000;
5
+ export declare function isTransientServerError(err: Error): boolean;
6
+ export declare function isOverloadedErrorEvent(err: unknown): boolean;
7
+ export declare class RoundRetryBudget {
8
+ overloadRetries: number;
9
+ streamIncompleteRetries: number;
10
+ ttfbRetried: boolean;
11
+ canRetryOverload(): boolean;
12
+ canRetryStreamIncomplete(): boolean;
13
+ canRetryTtfb(): boolean;
14
+ reset(): void;
15
+ }
@@ -0,0 +1,28 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { AnthropicToolDef, RunTurnInput, WireToolDef } from '../types.js';
3
+ import { type FirstByteTimeoutHandle } from '../../shared/first-byte-timeout.js';
4
+ import { type StreamStallHandle } from '../../shared/stream-stall-timeout.js';
5
+ import { type RoundRetryBudget } from './retry-budget.js';
6
+ import type { TurnAccumulator } from './turn-accumulator.js';
7
+ export declare function toWireTool(tool: AnthropicToolDef): WireToolDef;
8
+ export interface OpenRoundTransport {
9
+ kind: 'opened';
10
+ events: AsyncIterable<unknown>;
11
+ ttfb: FirstByteTimeoutHandle;
12
+ stall: StreamStallHandle;
13
+ requestStartedAt: number;
14
+ }
15
+ export type OpenRoundResult = OpenRoundTransport | {
16
+ kind: 'retry-ttfb';
17
+ requestStartedAt: number;
18
+ } | {
19
+ kind: 'terminated';
20
+ };
21
+ export interface OpenRoundContext {
22
+ input: RunTurnInput;
23
+ turn: TurnAccumulator;
24
+ retry: RoundRetryBudget;
25
+ ttfbTimeoutMs: number;
26
+ stallTimeoutMs: number;
27
+ }
28
+ export declare function openRound({ input, turn, retry, ttfbTimeoutMs, stallTimeoutMs, }: OpenRoundContext): AsyncGenerator<ProviderEvent, OpenRoundResult, void>;
@@ -0,0 +1,12 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput } from '../types.js';
3
+ import type { RetryOutcome, RetryReason } from './outcomes.js';
4
+ import { type RoundRetryBudget } from './retry-budget.js';
5
+ import type { TurnAccumulator } from './turn-accumulator.js';
6
+ export interface RoundRetryContext {
7
+ input: RunTurnInput;
8
+ turn: TurnAccumulator;
9
+ retry: RoundRetryBudget;
10
+ requestStartedAt: number;
11
+ }
12
+ export declare function handleRoundRetry(reason: RetryReason, { input, turn, retry, requestStartedAt }: RoundRetryContext): AsyncGenerator<ProviderEvent, RetryOutcome, void>;
@@ -0,0 +1,18 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput } from '../types.js';
3
+ import type { FirstByteTimeoutHandle } from '../../shared/first-byte-timeout.js';
4
+ import { type StreamStallHandle } from '../../shared/stream-stall-timeout.js';
5
+ import type { RoundRetryBudget } from './retry-budget.js';
6
+ import type { RoundOutcome } from './outcomes.js';
7
+ import type { TurnAccumulator } from './turn-accumulator.js';
8
+ export interface StreamConsumerContext {
9
+ events: AsyncIterable<unknown>;
10
+ input: RunTurnInput;
11
+ turn: TurnAccumulator;
12
+ retry: RoundRetryBudget;
13
+ ttfb: FirstByteTimeoutHandle;
14
+ stall: StreamStallHandle;
15
+ stallTimeoutMs: number;
16
+ requestStartedAt: number;
17
+ }
18
+ export declare function consumeRoundStream({ events, input, turn, retry, ttfb, stall, stallTimeoutMs, requestStartedAt, }: StreamConsumerContext): AsyncGenerator<ProviderEvent, RoundOutcome, void>;
@@ -0,0 +1,2 @@
1
+ import type { MessageParam } from '@anthropic-ai/sdk/resources';
2
+ export declare function dumpThinkingDiagnostic(messages: MessageParam[], error: Error): void;
@@ -0,0 +1,3 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput } from '../types.js';
3
+ export declare function awaitCreateWithThrottleSignals(createPromise: Promise<AsyncIterable<unknown>>, input: RunTurnInput): AsyncGenerator<ProviderEvent, AsyncIterable<unknown>, void>;
@@ -0,0 +1,12 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput, ToolCall, ToolResult, TurnResult } from '../types.js';
3
+ import type { TurnAccumulator } from './turn-accumulator.js';
4
+ export type DispatchResult = {
5
+ kind: 'dispatched';
6
+ calls: ToolCall[];
7
+ results: ToolResult[];
8
+ startTimes: Map<string, number>;
9
+ } | {
10
+ kind: 'aborted';
11
+ };
12
+ export declare function dispatchToolCalls(turnResult: TurnResult, input: RunTurnInput, turn: TurnAccumulator): AsyncGenerator<ProviderEvent, DispatchResult, void>;
@@ -0,0 +1,4 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput, ToolCall, ToolResult } from '../types.js';
3
+ export type ToolResultsOutcome = 'committed' | 'denial-tripped';
4
+ export declare function emitAndCommitToolResults(calls: ToolCall[], results: ToolResult[], startTimes: Map<string, number>, input: RunTurnInput): AsyncGenerator<ProviderEvent, ToolResultsOutcome, void>;
@@ -0,0 +1,5 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput, TurnResult } from '../types.js';
3
+ import type { TurnAccumulator } from './turn-accumulator.js';
4
+ export type ToolRoundOutcome = 'continue' | 'terminated';
5
+ export declare function runToolRound(turnResult: TurnResult, input: RunTurnInput, turn: TurnAccumulator, maxIterations: number): AsyncGenerator<ProviderEvent, ToolRoundOutcome, void>;
@@ -0,0 +1,13 @@
1
+ import type { ProviderUsage } from '../../../provider.js';
2
+ export declare class TurnAccumulator {
3
+ usage: ProviderUsage;
4
+ iterations: number;
5
+ toolCallCount: number;
6
+ capReached: boolean;
7
+ readonly taskId: string;
8
+ readonly startedAt: number;
9
+ elapsedMs(): number;
10
+ withDuration(usage: ProviderUsage): ProviderUsage;
11
+ terminalUsage(): ProviderUsage;
12
+ addRoundUsage(roundUsage: ProviderUsage): void;
13
+ }
@@ -0,0 +1,4 @@
1
+ import type { ProviderEvent } from '../../../provider.js';
2
+ import type { RunTurnInput, TurnResult } from '../types.js';
3
+ import type { TurnAccumulator } from './turn-accumulator.js';
4
+ export declare function emitNonToolUseTerminal(turnResult: TurnResult, input: RunTurnInput, turn: TurnAccumulator): Generator<ProviderEvent, void, void>;
@@ -0,0 +1,9 @@
1
+ import type { TraceWriter } from '../../../trace/index.js';
2
+ export declare class TurnTrace {
3
+ private readonly signal;
4
+ private readonly traceWriter;
5
+ private interruptedAt;
6
+ constructor(signal: AbortSignal, traceWriter: TraceWriter | undefined);
7
+ private readonly onInterrupt;
8
+ finish(turnElapsedMs: number): void;
9
+ }
@@ -1,9 +1,3 @@
1
1
  import type { ProviderEvent } from '../../provider.js';
2
- import type { AnthropicToolDef, RunTurnInput, WireToolDef } from './types.js';
3
- export { DEFAULT_MAX_TOOL_USE_ITERATIONS } from '../shared/tool-loop-cap.js';
4
- export declare function toWireTool(tool: AnthropicToolDef): WireToolDef;
5
- export declare const OVERLOAD_MAX_RETRIES = 3;
6
- export declare const STREAM_INCOMPLETE_MAX_RETRIES = 2;
7
- export declare function isTransientServerError(err: Error): boolean;
8
- export declare function isOverloadedErrorEvent(err: unknown): boolean;
2
+ import type { RunTurnInput } from './types.js';
9
3
  export declare function runTurn(input: RunTurnInput): AsyncGenerator<ProviderEvent, void, void>;
@@ -62,6 +62,7 @@ export declare class SessionToolDispatcher implements ToolDispatcher {
62
62
  private readonly readOnlyBash;
63
63
  private readonly maxOutputBytes;
64
64
  private repeatBreaker;
65
+ private readonly repeatFailureGuard;
65
66
  private denialBreaker;
66
67
  private suspectedLoopWindow;
67
68
  private readonly grantManager;
@@ -78,6 +79,7 @@ export declare class SessionToolDispatcher implements ToolDispatcher {
78
79
  private checkReadOnlyBash;
79
80
  private emitPreToolUseBlock;
80
81
  private checkRepeatCircuitBreaker;
82
+ private checkRepeatFailureGuard;
81
83
  private observeSuspectedLoop;
82
84
  private recordForkReadDenial;
83
85
  private resetDenialBreaker;
@@ -0,0 +1,14 @@
1
+ import type { ToolCall, ToolResult } from '../providers/anthropic-direct/types.js';
2
+ export declare const REPEAT_FAILURE_REFUSAL_THRESHOLD = 3;
3
+ export interface RepeatFailureVerdict {
4
+ readonly result: ToolResult;
5
+ readonly count: number;
6
+ readonly tool: string;
7
+ }
8
+ export declare function repeatFailureFingerprint(call: ToolCall): string;
9
+ export declare class RepeatFailureGuard {
10
+ private readonly streaks;
11
+ check(call: ToolCall): RepeatFailureVerdict | null;
12
+ note(call: ToolCall, result: ToolResult): void;
13
+ streakFor(call: ToolCall): number;
14
+ }
@@ -14,6 +14,7 @@ export declare const ToolFailureClassSchema: z.ZodEnum<{
14
14
  "hook-block": "hook-block";
15
15
  "elicitation-declined": "elicitation-declined";
16
16
  "denial-breaker": "denial-breaker";
17
+ "repeat-failure": "repeat-failure";
17
18
  }>;
18
19
  export declare const ToolCallCompletedPayloadSchema: z.ZodObject<{
19
20
  phase: z.ZodLiteral<"completed">;
@@ -34,6 +35,7 @@ export declare const ToolCallCompletedPayloadSchema: z.ZodObject<{
34
35
  "hook-block": "hook-block";
35
36
  "elicitation-declined": "elicitation-declined";
36
37
  "denial-breaker": "denial-breaker";
38
+ "repeat-failure": "repeat-failure";
37
39
  }>>;
38
40
  batchIndex: z.ZodOptional<z.ZodNumber>;
39
41
  batchSize: z.ZodOptional<z.ZodNumber>;
@@ -64,6 +66,7 @@ export declare const ToolCallPayloadSchema: z.ZodDiscriminatedUnion<[z.ZodObject
64
66
  "hook-block": "hook-block";
65
67
  "elicitation-declined": "elicitation-declined";
66
68
  "denial-breaker": "denial-breaker";
69
+ "repeat-failure": "repeat-failure";
67
70
  }>>;
68
71
  batchIndex: z.ZodOptional<z.ZodNumber>;
69
72
  batchSize: z.ZodOptional<z.ZodNumber>;
@@ -138,6 +141,7 @@ export declare const SubagentFailedPayloadSchema: z.ZodObject<{
138
141
  "hook-block": "hook-block";
139
142
  "elicitation-declined": "elicitation-declined";
140
143
  "denial-breaker": "denial-breaker";
144
+ "repeat-failure": "repeat-failure";
141
145
  }>>;
142
146
  }, z.core.$strip>;
143
147
  export declare const SubagentCancelledPayloadSchema: z.ZodObject<{
@@ -181,6 +185,7 @@ export declare const SubagentLifecyclePayloadSchema: z.ZodDiscriminatedUnion<[z.
181
185
  "hook-block": "hook-block";
182
186
  "elicitation-declined": "elicitation-declined";
183
187
  "denial-breaker": "denial-breaker";
188
+ "repeat-failure": "repeat-failure";
184
189
  }>>;
185
190
  }, z.core.$strip>, z.ZodObject<{
186
191
  transition: z.ZodLiteral<"cancelled">;
@@ -585,6 +590,7 @@ export declare const TraceEventInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject
585
590
  "hook-block": "hook-block";
586
591
  "elicitation-declined": "elicitation-declined";
587
592
  "denial-breaker": "denial-breaker";
593
+ "repeat-failure": "repeat-failure";
588
594
  }>>;
589
595
  batchIndex: z.ZodOptional<z.ZodNumber>;
590
596
  batchSize: z.ZodOptional<z.ZodNumber>;
@@ -652,6 +658,7 @@ export declare const TraceEventInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject
652
658
  "hook-block": "hook-block";
653
659
  "elicitation-declined": "elicitation-declined";
654
660
  "denial-breaker": "denial-breaker";
661
+ "repeat-failure": "repeat-failure";
655
662
  }>>;
656
663
  }, z.core.$strip>, z.ZodObject<{
657
664
  transition: z.ZodLiteral<"cancelled">;
@@ -904,6 +911,7 @@ export declare const TraceEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
904
911
  "hook-block": "hook-block";
905
912
  "elicitation-declined": "elicitation-declined";
906
913
  "denial-breaker": "denial-breaker";
914
+ "repeat-failure": "repeat-failure";
907
915
  }>>;
908
916
  batchIndex: z.ZodOptional<z.ZodNumber>;
909
917
  batchSize: z.ZodOptional<z.ZodNumber>;
@@ -975,6 +983,7 @@ export declare const TraceEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
975
983
  "hook-block": "hook-block";
976
984
  "elicitation-declined": "elicitation-declined";
977
985
  "denial-breaker": "denial-breaker";
986
+ "repeat-failure": "repeat-failure";
978
987
  }>>;
979
988
  }, z.core.$strip>, z.ZodObject<{
980
989
  transition: z.ZodLiteral<"cancelled">;
@@ -6,7 +6,7 @@ export interface ToolCallStartedPayload {
6
6
  inputBytes: number;
7
7
  subagentId?: string;
8
8
  }
9
- export declare const TOOL_FAILURE_CLASSES: readonly ["policy-refusal", "timeout", "permission-denied", "hook-block", "abort", "elicitation-declined", "denial-breaker"];
9
+ export declare const TOOL_FAILURE_CLASSES: readonly ["policy-refusal", "timeout", "permission-denied", "hook-block", "abort", "elicitation-declined", "denial-breaker", "repeat-failure"];
10
10
  export type ToolFailureClass = (typeof TOOL_FAILURE_CLASSES)[number];
11
11
  export interface ToolCallCompletedPayload {
12
12
  phase: 'completed';