agent-afk 5.222.18 → 5.223.0

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.
@@ -16,6 +16,7 @@ export interface RegisterArgs {
16
16
  provenance?: BackgroundJobProvenance;
17
17
  parentSessionId?: string | undefined;
18
18
  onCleanup?: () => Promise<void>;
19
+ onSettled?: () => void;
19
20
  }
20
21
  export interface BackgroundRegistryEvents {
21
22
  started: [job: BackgroundJob];
@@ -45,7 +46,6 @@ export declare class BackgroundAgentRegistry extends EventEmitter<BackgroundRegi
45
46
  getTranscript(jobId: string): string | undefined;
46
47
  getHandle(jobId: string): SubagentHandle | undefined;
47
48
  getTouchedFiles(jobId: string): readonly string[] | undefined;
48
- private recordTouchedFile;
49
49
  private nextJobId;
50
50
  private markTerminal;
51
51
  private statusFromResult;
@@ -0,0 +1 @@
1
+ export declare function recordTouchedFile(touchedFiles: string[], toolInputJson: string): void;
@@ -3,6 +3,7 @@ import type { AgentModelInput, CanUseTool, IAgentSession } from './types.js';
3
3
  import type { ModelProvider } from './provider.js';
4
4
  import type { SubagentManager } from './subagent.js';
5
5
  import { type DAGEdge, type DAGRunResult } from './dag.js';
6
+ import type { DelegationBudget } from './tools/delegation-budget.js';
6
7
  export interface SubagentDAGNode {
7
8
  id: string;
8
9
  systemPrompt: string;
@@ -27,5 +28,6 @@ export interface SubagentDAGOptions {
27
28
  edges: DAGEdge[];
28
29
  failFast?: boolean;
29
30
  nodeTimeoutMs?: number;
31
+ delegationBudget?: DelegationBudget;
30
32
  }
31
33
  export declare function runSubagentDAG(options: SubagentDAGOptions): Promise<DAGRunResult>;
@@ -20,6 +20,7 @@ export interface ComposeExecutorContext {
20
20
  maxDepth?: number;
21
21
  getReadScopeInputs?: () => ReadScopeInputs;
22
22
  workspaceStore?: WorkspaceStore;
23
+ delegationBudget?: import('./delegation-budget.js').DelegationBudget;
23
24
  onSubagentSucceeded?: (usage: import('../subagent/result.js').SubagentTrace['usage'], costUsd: number | undefined) => void;
24
25
  }
25
26
  export interface TruncationEvent {
@@ -0,0 +1,32 @@
1
+ export interface DelegationBudgetConfig {
2
+ maxChildrenPerAgent?: number;
3
+ maxConcurrentAgents?: number;
4
+ maxTotalAgents?: number;
5
+ }
6
+ export type BudgetRefusalReason = 'max_children_per_agent' | 'max_concurrent_agents' | 'max_total_agents';
7
+ export interface BudgetCheckResult {
8
+ allowed: boolean;
9
+ reason?: BudgetRefusalReason;
10
+ detail?: string;
11
+ }
12
+ export declare function resolveDelegationBudgetConfig(): DelegationBudgetConfig | undefined;
13
+ export interface DelegationBudgetSnapshot {
14
+ concurrent: number;
15
+ total: number;
16
+ config: DelegationBudgetConfig;
17
+ }
18
+ export interface SpawnReceipt {
19
+ release: () => void;
20
+ rollback: () => void;
21
+ }
22
+ export declare class DelegationBudget {
23
+ private readonly config;
24
+ private concurrent;
25
+ private total;
26
+ private readonly childrenByAgent;
27
+ constructor(config: DelegationBudgetConfig);
28
+ canSpawn(parentId: string): BudgetCheckResult;
29
+ recordSpawn(parentId: string): SpawnReceipt;
30
+ snapshot(): DelegationBudgetSnapshot;
31
+ }
32
+ export declare function buildBudgetRefusalMessage(check: BudgetCheckResult): string;
@@ -32,7 +32,7 @@ export interface CreateChildProviderFactoryOptions {
32
32
  export declare function createChildProviderFactory(opts?: CreateChildProviderFactoryOptions): (args: ChildProviderFactoryArgs) => ModelProvider;
33
33
  export declare function buildReadOnlyReconProvider(model: AgentModelInput | undefined, openaiBaseUrl?: string, allowedTools?: readonly string[]): ModelProvider;
34
34
  export declare function buildComposeNodeProvider(model: AgentModelInput | undefined, workspaceStore: WorkspaceStore, openaiBaseUrl?: string, readOnlyBash?: boolean): ModelProvider;
35
- export declare function createChildSkillExecutorFactory(defaultModel: AgentModelInput, apiKey: string | undefined, childProviderFactory: (args: ChildProviderFactoryArgs) => ModelProvider, baseUrl?: string, traceWriter?: TraceSink, backgroundRegistry?: BackgroundAgentRegistry, cwd?: string, resolveApiKeyForModel?: (model: string) => string | undefined, surface?: Surface, defaultSubagentModel?: AgentModelInput, agentRegistry?: AgentRegistry, openaiBaseUrl?: string, xaiBaseUrl?: string, workspaceStore?: WorkspaceStore): (depth: number, maxDepth: number, signal: AbortSignal, inheritedCwd?: string, inheritedReadScope?: ReadScopeInputs, skillDispatchName?: string) => SkillExecutor;
35
+ export declare function createChildSkillExecutorFactory(defaultModel: AgentModelInput, apiKey: string | undefined, childProviderFactory: (args: ChildProviderFactoryArgs) => ModelProvider, baseUrl?: string, traceWriter?: TraceSink, backgroundRegistry?: BackgroundAgentRegistry, cwd?: string, resolveApiKeyForModel?: (model: string) => string | undefined, surface?: Surface, defaultSubagentModel?: AgentModelInput, agentRegistry?: AgentRegistry, openaiBaseUrl?: string, xaiBaseUrl?: string, workspaceStore?: WorkspaceStore, delegationBudget?: import('./delegation-budget.js').DelegationBudget): (depth: number, maxDepth: number, signal: AbortSignal, inheritedCwd?: string, inheritedReadScope?: ReadScopeInputs, skillDispatchName?: string) => SkillExecutor;
36
36
  export type PhaseRole = 'read-only' | 'read-write';
37
37
  export declare function buildSkillRestrictedProvider(allowedTools: string[], model: AgentModelInput | undefined, readOnlyBash?: boolean, openaiBaseUrl?: string): ModelProvider;
38
38
  export declare function buildPhaseRestrictedProvider(_role: 'read-only', model: AgentModelInput | undefined): ModelProvider;
@@ -29,6 +29,7 @@ export interface SkillExecutorContext {
29
29
  agentRegistry?: import('../../agents/index.js').AgentRegistry;
30
30
  skillDispatchName?: string;
31
31
  workspaceStore?: import('../../workspace/index.js').WorkspaceStore;
32
+ delegationBudget?: import('../../tools/delegation-budget.js').DelegationBudget;
32
33
  }
33
34
  export interface SkillInput {
34
35
  name: string;
@@ -9,6 +9,7 @@ export interface RunBackgroundBranchArgs {
9
9
  model: string | undefined;
10
10
  parentSessionId: string | undefined;
11
11
  onSettled?: (isError: boolean) => void;
12
+ budgetRelease?: () => void;
12
13
  onCleanup?: () => Promise<void>;
13
14
  isolationTeardown?: {
14
15
  repoRoot: string;
@@ -34,6 +34,7 @@ export interface BuildChildConfigArgs {
34
34
  parentModel?: AgentModelInput;
35
35
  traceWriter?: TraceSink;
36
36
  workspaceStore?: import('../../workspace/index.js').WorkspaceStore;
37
+ delegationBudget?: import('../../tools/delegation-budget.js').DelegationBudget;
37
38
  createChildExecutor: (ctx: SubagentExecutorContext) => SubagentExecutor;
38
39
  }
39
40
  export interface BuildChildConfigResult {
@@ -42,5 +42,9 @@ export interface RunForegroundArgs {
42
42
  repoRoot: string;
43
43
  worktreePath: string;
44
44
  };
45
+ budgetRelease?: () => void;
46
+ promotionTookBudget?: {
47
+ value: boolean;
48
+ };
45
49
  }
46
50
  export declare function runForegroundWithPromotion(args: RunForegroundArgs): Promise<ToolResult>;
@@ -0,0 +1,45 @@
1
+ import type { SubagentManager } from '../../subagent.js';
2
+ import type { ReadScopeInputs } from '../../subagent-read-scope.js';
3
+ import type { BackgroundAgentRegistry } from '../../background-registry.js';
4
+ import type { ModelProvider } from '../../provider.js';
5
+ import type { AgentModelInput, IAgentSession } from '../../types.js';
6
+ import type { AgentConfig } from '../../types/config-types.js';
7
+ import type { ChildProviderFactoryArgs } from '../nesting.js';
8
+ import type { AgentRegistry } from '../../agents/index.js';
9
+ import type { SkillExecutor } from '../skill-executor.js';
10
+ import type { Surface } from '../../awareness/types.js';
11
+ import type { TraceSink } from '../../trace/index.js';
12
+ import type { InboundAttachmentReader } from '../../content/attachment-registry.js';
13
+ import type { DelegationBudget } from '../delegation-budget.js';
14
+ import type { QueuedNoteClaim } from '../subagent/queued-note.js';
15
+ import type { PromotedSubagentInfo } from '../subagent/foreground-promotion.js';
16
+ export type { PromotedSubagentInfo, QueuedNoteClaim };
17
+ export interface SubagentExecutorContext {
18
+ subagentManager: SubagentManager;
19
+ parentSession: Pick<IAgentSession, 'sessionId' | 'getInputStreamRef' | 'abortSignal'> & Partial<Pick<IAgentSession, 'hookRegistry'>>;
20
+ defaultConfig: Pick<AgentConfig, 'apiKey' | 'systemPrompt' | 'baseUrl' | 'openaiBaseUrl' | 'xaiBaseUrl' | 'skillDispatchName'>;
21
+ surface?: Surface;
22
+ resolveApiKeyForModel?: (model: string) => string | undefined;
23
+ defaultSubagentModel: AgentModelInput;
24
+ childProviderFactory?: (args: ChildProviderFactoryArgs) => ModelProvider;
25
+ childSkillExecutorFactory?: (depth: number, maxDepth: number, signal: AbortSignal, inheritedCwd?: string, inheritedReadScope?: ReadScopeInputs, skillDispatchName?: string) => SkillExecutor;
26
+ depth: number;
27
+ maxDepth?: number;
28
+ backgroundRegistry?: BackgroundAgentRegistry;
29
+ cwd?: string;
30
+ traceWriter?: TraceSink;
31
+ workspaceStore?: import('../../workspace/index.js').WorkspaceStore;
32
+ delegationBudget?: DelegationBudget;
33
+ allowedTools?: string[];
34
+ readOnlyBash?: boolean;
35
+ nestedAgentAllowlist?: readonly string[];
36
+ agentRegistry?: AgentRegistry;
37
+ inboundAttachmentRegistry?: InboundAttachmentReader;
38
+ parentModel?: AgentModelInput;
39
+ }
40
+ export interface SubagentControl {
41
+ hasPromotableForeground(): boolean;
42
+ promoteActiveForeground(queuedNote?: QueuedNoteClaim): Promise<PromotedSubagentInfo[]>;
43
+ hasActiveForeground(): boolean;
44
+ cancelActiveForeground(): Promise<number>;
45
+ }
@@ -1,50 +1,13 @@
1
- import { SubagentManager } from '../subagent.js';
2
- import { type ReadScopeInputs } from '../subagent-read-scope.js';
3
- import { BackgroundAgentRegistry } from '../background-registry.js';
4
- import type { ModelProvider } from '../provider.js';
5
- import type { AgentModelInput, IAgentSession } from '../types.js';
6
- import type { AgentConfig } from '../types/config-types.js';
7
- import type { AnthropicToolDef, ToolCall, ToolResult } from './types.js';
8
- import { type ChildProviderFactoryArgs } from './nesting.js';
9
- import type { AgentRegistry } from '../agents/index.js';
10
- import type { SkillExecutor } from './skill-executor.js';
11
- import type { Surface } from '../awareness/types.js';
12
1
  import type { TraceSink } from '../trace/index.js';
2
+ import type { AnthropicToolDef, ToolCall, ToolResult } from './types.js';
13
3
  import { type AgentExecutionMode } from './subagent/input-parse.js';
14
- import { type PromotedSubagentInfo } from './subagent/foreground-promotion.js';
15
- import type { QueuedNoteClaim } from './subagent/queued-note.js';
16
- import { type InboundAttachmentReader } from '../content/attachment-registry.js';
4
+ import { buildSubagentsLite } from './subagent-executor.lite-snapshot.js';
5
+ import type { SubagentExecutorContext, SubagentControl } from './subagent-executor/types.js';
6
+ import type { QueuedNoteClaim, PromotedSubagentInfo } from './subagent-executor/types.js';
17
7
  export { DEFAULT_MAX_NESTING_DEPTH, type ChildProviderFactoryArgs } from './nesting.js';
18
8
  export type { AgentExecutionMode };
19
- export interface SubagentExecutorContext {
20
- subagentManager: SubagentManager;
21
- parentSession: Pick<IAgentSession, 'sessionId' | 'getInputStreamRef' | 'abortSignal'> & Partial<Pick<IAgentSession, 'hookRegistry'>>;
22
- defaultConfig: Pick<AgentConfig, 'apiKey' | 'systemPrompt' | 'baseUrl' | 'openaiBaseUrl' | 'xaiBaseUrl' | 'skillDispatchName'>;
23
- surface?: Surface;
24
- resolveApiKeyForModel?: (model: string) => string | undefined;
25
- defaultSubagentModel: AgentModelInput;
26
- childProviderFactory?: (args: ChildProviderFactoryArgs) => ModelProvider;
27
- childSkillExecutorFactory?: (depth: number, maxDepth: number, signal: AbortSignal, inheritedCwd?: string, inheritedReadScope?: ReadScopeInputs, skillDispatchName?: string) => SkillExecutor;
28
- depth: number;
29
- maxDepth?: number;
30
- backgroundRegistry?: BackgroundAgentRegistry;
31
- cwd?: string;
32
- traceWriter?: TraceSink;
33
- workspaceStore?: import('../workspace/index.js').WorkspaceStore;
34
- allowedTools?: string[];
35
- readOnlyBash?: boolean;
36
- nestedAgentAllowlist?: readonly string[];
37
- agentRegistry?: AgentRegistry;
38
- inboundAttachmentRegistry?: InboundAttachmentReader;
39
- parentModel?: AgentModelInput;
40
- }
9
+ export type { SubagentExecutorContext, SubagentControl } from './subagent-executor/types.js';
41
10
  export type { PromotedSubagentInfo } from './subagent/foreground-promotion.js';
42
- export interface SubagentControl {
43
- hasPromotableForeground(): boolean;
44
- promoteActiveForeground(queuedNote?: QueuedNoteClaim): Promise<PromotedSubagentInfo[]>;
45
- hasActiveForeground(): boolean;
46
- cancelActiveForeground(): Promise<number>;
47
- }
48
11
  export declare class SubagentExecutor implements SubagentControl {
49
12
  private readonly ctx;
50
13
  private currentCwd;
@@ -68,18 +31,7 @@ export declare class SubagentExecutor implements SubagentControl {
68
31
  private cancelGeneration;
69
32
  cancelActiveForeground(): Promise<number>;
70
33
  promoteActiveForeground(queuedNote?: QueuedNoteClaim): Promise<PromotedSubagentInfo[]>;
71
- getSubagentsLite(): {
72
- active: Array<{
73
- id: string;
74
- status: 'idle' | 'running' | 'succeeded' | 'failed' | 'cancelled';
75
- }>;
76
- backgroundJobs: Array<{
77
- jobId: string;
78
- status: 'running' | 'completed' | 'failed' | 'cancelled';
79
- startedAt: string;
80
- label: string | null;
81
- }>;
82
- };
34
+ getSubagentsLite(): ReturnType<typeof buildSubagentsLite>;
83
35
  execute(call: ToolCall): Promise<ToolResult>;
84
36
  private executeOnce;
85
37
  }
@@ -0,0 +1,15 @@
1
+ import type { SubagentManager } from '../subagent.js';
2
+ import type { BackgroundAgentRegistry } from '../background-registry.js';
3
+ export interface SubagentsLite {
4
+ active: Array<{
5
+ id: string;
6
+ status: 'idle' | 'running' | 'succeeded' | 'failed' | 'cancelled';
7
+ }>;
8
+ backgroundJobs: Array<{
9
+ jobId: string;
10
+ status: 'running' | 'completed' | 'failed' | 'cancelled';
11
+ startedAt: string;
12
+ label: string | null;
13
+ }>;
14
+ }
15
+ export declare function buildSubagentsLite(subagentManager: SubagentManager, backgroundRegistry: BackgroundAgentRegistry | undefined): SubagentsLite;