@agentic-patterns/runtime 0.1.4 → 0.1.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.
package/dist/index.d.cts CHANGED
@@ -912,28 +912,59 @@ declare class ClaudeCodeRunner implements RunnerProtocol {
912
912
  }
913
913
 
914
914
  /**
915
- * ClaudeCodeAPIRunner — API-only mode wrapper on ClaudeCodeRunner.
915
+ * ClaudeCodeAPIRunner — Claude Agent SDK in plain-API mode.
916
916
  *
917
- * Uses Claude Code under the hood but blocks all Code-native tools
918
- * (file, bash, agent, etc.) so the agent behaves like a plain Claude
919
- * API call with a system prompt injected. MCP tools from agent
920
- * capabilities remain available. Uses the same Max subscription OAuth token.
917
+ * The agent runs through the Claude Code subprocess but in a sandboxed
918
+ * configuration that strips everything CC-flavored:
921
919
  *
922
- * Named "ClaudeCodeAPIRunner" (not "ClaudeAPIRunner") because it still
923
- * runs through the Claude Code subprocess — a future ClaudeAPIRunner
924
- * may talk directly to the Claude API without the Code layer.
920
+ * - System prompt: framework's, fully replacing CC's.
921
+ * - Built-in tools (Read/Bash/Edit/...): disabled via `tools: []`.
922
+ * - claude.ai connector MCP servers (Gmail/Calendar/Drive/...):
923
+ * disabled by isolating CLAUDE_CONFIG_DIR to an ephemeral tmpdir.
924
+ * - User/project settings, plugins, skills, hooks: not loaded
925
+ * (settingSources defaults to []; new CLAUDE_CONFIG_DIR is empty).
926
+ * - MCP servers from agent capabilities: still wired up.
927
+ *
928
+ * Auth: reads the Max-subscription OAuth token from the OS credential
929
+ * store and injects it via `CLAUDE_CODE_OAUTH_TOKEN`. This bypasses
930
+ * the binary's path-bound Keychain lookup (which would otherwise fail
931
+ * when CLAUDE_CONFIG_DIR is redirected) while preserving Max-sub auth.
932
+ *
933
+ * Currently macOS-only — credential lookup uses the `security` CLI.
934
+ * On other platforms, falls back to the parent ClaudeCodeRunner
935
+ * behavior (auth works, connectors leak — see ClaudeCodeRunner docs).
925
936
  *
926
937
  * Mirrors Python: agentic_patterns/core/systems/runners/claude_api.py
927
938
  */
928
939
 
940
+ interface ClaudeCodeAPIRunnerOptions extends ClaudeCodeRunnerOptions {
941
+ /**
942
+ * Disable the OAuth-injection sandboxing path. When true, behaves
943
+ * like a stripped ClaudeCodeRunner with `tools: []` only — auth and
944
+ * connectors fall through to the binary's defaults.
945
+ *
946
+ * Useful for debugging or for environments where the OS credential
947
+ * store is unavailable.
948
+ */
949
+ disableSandbox?: boolean;
950
+ /**
951
+ * Tool names or `mcp__<server>` server-prefixes to additionally
952
+ * block via SDK `disallowedTools`. Rarely needed when sandboxing
953
+ * is enabled (connectors are already stripped via config isolation).
954
+ */
955
+ extraDisallowedTools?: string[];
956
+ }
929
957
  /**
930
- * Runner that uses Claude Code SDK in API-only mode.
958
+ * Runner that uses the Claude Agent SDK as a plain Claude API call,
959
+ * sandboxed away from the user's Claude Code environment.
931
960
  *
932
- * Blocks all file/bash/agent tools so the agent behaves like a plain
933
- * Claude API call with the framework's system prompt. MCP tools from
934
- * agent capabilities remain available.
961
+ * Drops in for AgentRunner both implement RunnerProtocol identically.
935
962
  */
936
963
  declare class ClaudeCodeAPIRunner extends ClaudeCodeRunner {
964
+ private readonly _disableSandbox;
965
+ private readonly _extraDisallowed;
966
+ private readonly _isolatedConfigDir;
967
+ constructor(opts?: ClaudeCodeAPIRunnerOptions);
937
968
  protected _buildOptions(agent: AgentLikeForBridge, options: RunOptions | undefined, context: {
938
969
  runId: string;
939
970
  traceId: string;
@@ -1165,7 +1196,16 @@ interface ClaudeCodeProviderOptions {
1165
1196
  defaults?: Partial<Options>;
1166
1197
  /** Include Claude Code's built-in tools (Read/Write/Bash/…). Default: false. */
1167
1198
  allowBuiltinTools?: boolean;
1168
- /** Max turns inside the SDK loop. Default: 1 (one Claude call per model step). */
1199
+ /**
1200
+ * Max turns inside the SDK loop. Default: 10.
1201
+ *
1202
+ * Within one `doGenerate`, Claude may emit prose-only on its first turn
1203
+ * and produce a tool call on a later turn. `canUseTool` aborts on the
1204
+ * first tool call regardless, so this only needs to be generous enough
1205
+ * to allow "plan-then-tool" sequences. A too-low value causes the SDK
1206
+ * to throw `Reached maximum number of turns` before Claude reaches any
1207
+ * tool call.
1208
+ */
1169
1209
  maxTurns?: number;
1170
1210
  }
1171
1211
  declare class ClaudeCodeLanguageModel implements LanguageModelV1 {
@@ -1249,12 +1289,20 @@ interface CreateRunnerOptions {
1249
1289
  /**
1250
1290
  * Explicit model id. Falls through to the provider's tier default.
1251
1291
  * Ignored if `runner` or `model` is set.
1292
+ *
1293
+ * When omitted, `process.env.AGENT_MODEL` is read as a default — this
1294
+ * is the only way to pin an exact model from a `.env` file (e.g.
1295
+ * `AGENT_MODEL=qwen3.6:27b` to use a model the framework's tier map
1296
+ * doesn't list).
1252
1297
  */
1253
1298
  modelId?: string;
1254
1299
  /**
1255
1300
  * Cross-provider tier selector — "opus" | "sonnet" | "haiku". Resolved
1256
1301
  * via each `ProviderProtocol.tiers` map. Default: "sonnet".
1257
1302
  * Ignored if `modelId` is set.
1303
+ *
1304
+ * When omitted, `process.env.AGENT_TIER` is read as a default. Invalid
1305
+ * values are silently ignored (fall through to the "sonnet" default).
1258
1306
  */
1259
1307
  tier?: ProviderTier;
1260
1308
  /**
@@ -3403,4 +3451,4 @@ declare class StdioAdapter {
3403
3451
  private _getConversation;
3404
3452
  }
3405
3453
 
3406
- export { ANALYSIS, type AdminServiceProtocol, AgencyRuntime, type AgentAddress, type AgentBroadcastEvent, type AgentEvent, AgentEventBus, type AgentEventType, type AgentJoinEvent, type AgentLeaveEvent, type AgentLike, type AgentLikeForBridge, type AgentMessageEvent, AgentNode, type AgentNodeOptions, AgentRunner, type AgentStats, AgentStatsSchema, type ApprovalCallback, AuditGate, type AuditLogger, BATCH_WINDOW, type BackoffStrategy, type BaseEvent, BaseExporter, BaseGate, type BaseSandboxEvent, CLAUDE_CODE_HOOK_EVENTS, CalculatorToolbox, type CanonicalMessage, type CanonicalMessagePart, ClaudeCodeAPIRunner, type ClaudeCodeHookEvent, type ClaudeCodeHookName, ClaudeCodeLanguageModel, type ClaudeCodeProviderOptions, ClaudeCodeRunner, type ClaudeCodeRunnerOptions, CompositeRefinementEvaluator, ConsoleExporter, type ConsoleLogger, type Consolidator, Conversation, type ConversationEndEvent, type ConversationExitReason, ConversationLoop, type ConversationLoopOptions, type ConversationResult, type ConversationRunOptions, type ConversationStartEvent, type ConversationStoreProtocol, type ConversationSummary, ConversationSummarySchema, type CreateRunnerOptions, DEFAULT_GLOBAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_MAX_TURNS, type DashboardStats, DashboardStatsSchema, type DateFilters, DateFiltersSchema, EVIDENCE_QUALITY, type ErrorEvent, EvaluatorChain, EvaluatorLoop, type EvaluatorLoopOptions, type EvaluatorRunOptions, EventBus, type EventHandlerFn, EventProfile, type Exchange, ExponentialBackoff, type Exporter, FixedBackoff, GATE_CATEGORY_NAMES, type Gate, GateAllow, GateBlock, GateCategory, GateModify, type GateResult, type GoalEvaluationResult, type GoalEvaluatorProtocol, type HealthPingEvent, type HealthPongEvent, HumanApprovalGate, INFORMATION_RETRIEVAL, INTENT_CLASSIFICATION, INTENT_ROUTING, InMemoryAdminService, InMemoryEventCollector, InProcessTransport, type IterationEndEvent, type IterationStartEvent, JitteredBackoff, type LLMCallEndEvent, type LLMCallStartEvent, LLMGoalEvaluator, type LLMGoalEvaluatorOptions, LLMRefinementEvaluator, type LLMRefinementEvaluatorOptions, type LangfuseClient, LangfuseExporter, type LangfuseObservation, type LangfuseSpan, MemoryStore, type MessageCancelEvent, type MessageChunkEvent, type MessageCompleteEvent, type MessageStartEvent, type MessageTemplate, MessagingToolbox, type MiddlewareFn, type MockCall, type MockResponse, MockRunner, type NodeLifecycleEvent, ORCHESTRATION, OTelExporter, type OTelSpan, OTelStatusCode, type OTelTracer, PROFILE_EVENT_TYPES, PROVIDERS, PROVIDER_PRIORITY, Parallel, type ParallelOptions, type ParallelResult, type PatternCompleteEvent, type PatternContext, type PatternEvent, type PatternHooks, type PatternIterationCompleteEvent, type PatternIterationStartEvent, type PatternProtocol, type PatternResult, type PatternRunOptions, type PatternStartEvent, type PatternStepCompleteEvent, type PatternStepErrorEvent, type PatternStepStartEvent, type ProviderProtocol, type ProviderTier, QUALITY_GATE, QUALITY_REVIEW, RESPONSE_SYNTHESIS, RETRIEVAL_STRATEGY, ROUTING, RateLimitGate, type ReasoningEvent, type Refinement, type RefinementEvaluator, type RefinementExitReason, type RefinementResult, type RetryExitReason, RetryLoop, type RetryLoopOptions, type RetryResult, type RetryRunOptions, type RubricCriterion, RubricEvaluator, type RunOptions, type RunResult, type RunnerProtocol, type RunnerSelection, type RunnerSource, type SSEEventName, SSEExporter, SSEFormatter, type SSEMapping, SSE_EVENT_NAMES, SafetyGate, type SandboxEvent, SandboxEventBus, type SandboxEventType, SelfEvalGoalEvaluator, Sequential, type SequentialOptions, type SequentialResult, SimpleGoalEvaluator, type SimpleGoalEvaluatorOptions, StdioAdapter, type Step, type StepResult, type StoredConversation, type StoredMessage, type StoredMessagePart, type StreamEvent, type SupportedProvider, type TaskAssignEvent, type TaskCreateEvent, type TaskExitReason, TaskLoop, type TaskLoopOptions, type TaskResult, type TaskRunOptions, type TaskState, type TaskUpdateEvent, type ThinkingStartEvent, TodoToolbox, type TokenUsageGroup, TokenUsageGroupSchema, type TokenUsageRow, TokenUsageRowSchema, type ToolAnalytics, ToolAnalyticsSchema, ToolCallBlocked, type ToolCallEndEvent, type ToolCallIntent, type ToolCallRecord, type ToolCallRejectedEvent, type ToolCallStartEvent, type ToolExecutor, type ToolProgressEvent, type ToolStats, ToolStatsSchema, type TraceEvent, TraceEventSchema, type TraceIteration, TraceIterationSchema, type TraceResponse, TraceResponseSchema, type TraceSummary, TraceSummarySchema, type Transport, type TransportMessage, type WeightedEvaluator, agentAddressToString, analystRole, anthropicProvider, buildAgentServers, buildCalculatorAgent, buildCapabilityServer, buildTodoAgent, buildWritingCoachAgent, claudeCode, collectByName, collectContents, convertHistory, coordinatorRole, createAgentAddress, createConsoleExporter, createEvent, createRunner, createStepResult, createToolboxExecutor, deepseekProvider, deserializeSandboxEvent, deserializeSandboxEventFromString, exchangeTotalTokens, executeStep, formatSSE, getAgentEventBus, getEventBus, googleProvider, groqProvider, isClaudeCodeHookName, makeStepName, mapClaudeCodeHookToAgentEvents, matchSubject, mistralProvider, ollamaProvider, openaiProvider, openrouterProvider, orchestratorRole, resolveMessage, resolveModelId, retrievalRole, serializeSandboxEvent, serializeSandboxEventToString, setAgentEventBus, setEventBus, subjectToRegex, subscribeProfile, subscribeProfiles, toSSEMapping, unsubscribeProfile, xaiProvider };
3454
+ export { ANALYSIS, type AdminServiceProtocol, AgencyRuntime, type AgentAddress, type AgentBroadcastEvent, type AgentEvent, AgentEventBus, type AgentEventType, type AgentJoinEvent, type AgentLeaveEvent, type AgentLike, type AgentLikeForBridge, type AgentMessageEvent, AgentNode, type AgentNodeOptions, AgentRunner, type AgentStats, AgentStatsSchema, type ApprovalCallback, AuditGate, type AuditLogger, BATCH_WINDOW, type BackoffStrategy, type BaseEvent, BaseExporter, BaseGate, type BaseSandboxEvent, CLAUDE_CODE_HOOK_EVENTS, CalculatorToolbox, type CanonicalMessage, type CanonicalMessagePart, ClaudeCodeAPIRunner, type ClaudeCodeAPIRunnerOptions, type ClaudeCodeHookEvent, type ClaudeCodeHookName, ClaudeCodeLanguageModel, type ClaudeCodeProviderOptions, ClaudeCodeRunner, type ClaudeCodeRunnerOptions, CompositeRefinementEvaluator, ConsoleExporter, type ConsoleLogger, type Consolidator, Conversation, type ConversationEndEvent, type ConversationExitReason, ConversationLoop, type ConversationLoopOptions, type ConversationResult, type ConversationRunOptions, type ConversationStartEvent, type ConversationStoreProtocol, type ConversationSummary, ConversationSummarySchema, type CreateRunnerOptions, DEFAULT_GLOBAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_MAX_TURNS, type DashboardStats, DashboardStatsSchema, type DateFilters, DateFiltersSchema, EVIDENCE_QUALITY, type ErrorEvent, EvaluatorChain, EvaluatorLoop, type EvaluatorLoopOptions, type EvaluatorRunOptions, EventBus, type EventHandlerFn, EventProfile, type Exchange, ExponentialBackoff, type Exporter, FixedBackoff, GATE_CATEGORY_NAMES, type Gate, GateAllow, GateBlock, GateCategory, GateModify, type GateResult, type GoalEvaluationResult, type GoalEvaluatorProtocol, type HealthPingEvent, type HealthPongEvent, HumanApprovalGate, INFORMATION_RETRIEVAL, INTENT_CLASSIFICATION, INTENT_ROUTING, InMemoryAdminService, InMemoryEventCollector, InProcessTransport, type IterationEndEvent, type IterationStartEvent, JitteredBackoff, type LLMCallEndEvent, type LLMCallStartEvent, LLMGoalEvaluator, type LLMGoalEvaluatorOptions, LLMRefinementEvaluator, type LLMRefinementEvaluatorOptions, type LangfuseClient, LangfuseExporter, type LangfuseObservation, type LangfuseSpan, MemoryStore, type MessageCancelEvent, type MessageChunkEvent, type MessageCompleteEvent, type MessageStartEvent, type MessageTemplate, MessagingToolbox, type MiddlewareFn, type MockCall, type MockResponse, MockRunner, type NodeLifecycleEvent, ORCHESTRATION, OTelExporter, type OTelSpan, OTelStatusCode, type OTelTracer, PROFILE_EVENT_TYPES, PROVIDERS, PROVIDER_PRIORITY, Parallel, type ParallelOptions, type ParallelResult, type PatternCompleteEvent, type PatternContext, type PatternEvent, type PatternHooks, type PatternIterationCompleteEvent, type PatternIterationStartEvent, type PatternProtocol, type PatternResult, type PatternRunOptions, type PatternStartEvent, type PatternStepCompleteEvent, type PatternStepErrorEvent, type PatternStepStartEvent, type ProviderProtocol, type ProviderTier, QUALITY_GATE, QUALITY_REVIEW, RESPONSE_SYNTHESIS, RETRIEVAL_STRATEGY, ROUTING, RateLimitGate, type ReasoningEvent, type Refinement, type RefinementEvaluator, type RefinementExitReason, type RefinementResult, type RetryExitReason, RetryLoop, type RetryLoopOptions, type RetryResult, type RetryRunOptions, type RubricCriterion, RubricEvaluator, type RunOptions, type RunResult, type RunnerProtocol, type RunnerSelection, type RunnerSource, type SSEEventName, SSEExporter, SSEFormatter, type SSEMapping, SSE_EVENT_NAMES, SafetyGate, type SandboxEvent, SandboxEventBus, type SandboxEventType, SelfEvalGoalEvaluator, Sequential, type SequentialOptions, type SequentialResult, SimpleGoalEvaluator, type SimpleGoalEvaluatorOptions, StdioAdapter, type Step, type StepResult, type StoredConversation, type StoredMessage, type StoredMessagePart, type StreamEvent, type SupportedProvider, type TaskAssignEvent, type TaskCreateEvent, type TaskExitReason, TaskLoop, type TaskLoopOptions, type TaskResult, type TaskRunOptions, type TaskState, type TaskUpdateEvent, type ThinkingStartEvent, TodoToolbox, type TokenUsageGroup, TokenUsageGroupSchema, type TokenUsageRow, TokenUsageRowSchema, type ToolAnalytics, ToolAnalyticsSchema, ToolCallBlocked, type ToolCallEndEvent, type ToolCallIntent, type ToolCallRecord, type ToolCallRejectedEvent, type ToolCallStartEvent, type ToolExecutor, type ToolProgressEvent, type ToolStats, ToolStatsSchema, type TraceEvent, TraceEventSchema, type TraceIteration, TraceIterationSchema, type TraceResponse, TraceResponseSchema, type TraceSummary, TraceSummarySchema, type Transport, type TransportMessage, type WeightedEvaluator, agentAddressToString, analystRole, anthropicProvider, buildAgentServers, buildCalculatorAgent, buildCapabilityServer, buildTodoAgent, buildWritingCoachAgent, claudeCode, collectByName, collectContents, convertHistory, coordinatorRole, createAgentAddress, createConsoleExporter, createEvent, createRunner, createStepResult, createToolboxExecutor, deepseekProvider, deserializeSandboxEvent, deserializeSandboxEventFromString, exchangeTotalTokens, executeStep, formatSSE, getAgentEventBus, getEventBus, googleProvider, groqProvider, isClaudeCodeHookName, makeStepName, mapClaudeCodeHookToAgentEvents, matchSubject, mistralProvider, ollamaProvider, openaiProvider, openrouterProvider, orchestratorRole, resolveMessage, resolveModelId, retrievalRole, serializeSandboxEvent, serializeSandboxEventToString, setAgentEventBus, setEventBus, subjectToRegex, subscribeProfile, subscribeProfiles, toSSEMapping, unsubscribeProfile, xaiProvider };
package/dist/index.d.ts CHANGED
@@ -912,28 +912,59 @@ declare class ClaudeCodeRunner implements RunnerProtocol {
912
912
  }
913
913
 
914
914
  /**
915
- * ClaudeCodeAPIRunner — API-only mode wrapper on ClaudeCodeRunner.
915
+ * ClaudeCodeAPIRunner — Claude Agent SDK in plain-API mode.
916
916
  *
917
- * Uses Claude Code under the hood but blocks all Code-native tools
918
- * (file, bash, agent, etc.) so the agent behaves like a plain Claude
919
- * API call with a system prompt injected. MCP tools from agent
920
- * capabilities remain available. Uses the same Max subscription OAuth token.
917
+ * The agent runs through the Claude Code subprocess but in a sandboxed
918
+ * configuration that strips everything CC-flavored:
921
919
  *
922
- * Named "ClaudeCodeAPIRunner" (not "ClaudeAPIRunner") because it still
923
- * runs through the Claude Code subprocess — a future ClaudeAPIRunner
924
- * may talk directly to the Claude API without the Code layer.
920
+ * - System prompt: framework's, fully replacing CC's.
921
+ * - Built-in tools (Read/Bash/Edit/...): disabled via `tools: []`.
922
+ * - claude.ai connector MCP servers (Gmail/Calendar/Drive/...):
923
+ * disabled by isolating CLAUDE_CONFIG_DIR to an ephemeral tmpdir.
924
+ * - User/project settings, plugins, skills, hooks: not loaded
925
+ * (settingSources defaults to []; new CLAUDE_CONFIG_DIR is empty).
926
+ * - MCP servers from agent capabilities: still wired up.
927
+ *
928
+ * Auth: reads the Max-subscription OAuth token from the OS credential
929
+ * store and injects it via `CLAUDE_CODE_OAUTH_TOKEN`. This bypasses
930
+ * the binary's path-bound Keychain lookup (which would otherwise fail
931
+ * when CLAUDE_CONFIG_DIR is redirected) while preserving Max-sub auth.
932
+ *
933
+ * Currently macOS-only — credential lookup uses the `security` CLI.
934
+ * On other platforms, falls back to the parent ClaudeCodeRunner
935
+ * behavior (auth works, connectors leak — see ClaudeCodeRunner docs).
925
936
  *
926
937
  * Mirrors Python: agentic_patterns/core/systems/runners/claude_api.py
927
938
  */
928
939
 
940
+ interface ClaudeCodeAPIRunnerOptions extends ClaudeCodeRunnerOptions {
941
+ /**
942
+ * Disable the OAuth-injection sandboxing path. When true, behaves
943
+ * like a stripped ClaudeCodeRunner with `tools: []` only — auth and
944
+ * connectors fall through to the binary's defaults.
945
+ *
946
+ * Useful for debugging or for environments where the OS credential
947
+ * store is unavailable.
948
+ */
949
+ disableSandbox?: boolean;
950
+ /**
951
+ * Tool names or `mcp__<server>` server-prefixes to additionally
952
+ * block via SDK `disallowedTools`. Rarely needed when sandboxing
953
+ * is enabled (connectors are already stripped via config isolation).
954
+ */
955
+ extraDisallowedTools?: string[];
956
+ }
929
957
  /**
930
- * Runner that uses Claude Code SDK in API-only mode.
958
+ * Runner that uses the Claude Agent SDK as a plain Claude API call,
959
+ * sandboxed away from the user's Claude Code environment.
931
960
  *
932
- * Blocks all file/bash/agent tools so the agent behaves like a plain
933
- * Claude API call with the framework's system prompt. MCP tools from
934
- * agent capabilities remain available.
961
+ * Drops in for AgentRunner both implement RunnerProtocol identically.
935
962
  */
936
963
  declare class ClaudeCodeAPIRunner extends ClaudeCodeRunner {
964
+ private readonly _disableSandbox;
965
+ private readonly _extraDisallowed;
966
+ private readonly _isolatedConfigDir;
967
+ constructor(opts?: ClaudeCodeAPIRunnerOptions);
937
968
  protected _buildOptions(agent: AgentLikeForBridge, options: RunOptions | undefined, context: {
938
969
  runId: string;
939
970
  traceId: string;
@@ -1165,7 +1196,16 @@ interface ClaudeCodeProviderOptions {
1165
1196
  defaults?: Partial<Options>;
1166
1197
  /** Include Claude Code's built-in tools (Read/Write/Bash/…). Default: false. */
1167
1198
  allowBuiltinTools?: boolean;
1168
- /** Max turns inside the SDK loop. Default: 1 (one Claude call per model step). */
1199
+ /**
1200
+ * Max turns inside the SDK loop. Default: 10.
1201
+ *
1202
+ * Within one `doGenerate`, Claude may emit prose-only on its first turn
1203
+ * and produce a tool call on a later turn. `canUseTool` aborts on the
1204
+ * first tool call regardless, so this only needs to be generous enough
1205
+ * to allow "plan-then-tool" sequences. A too-low value causes the SDK
1206
+ * to throw `Reached maximum number of turns` before Claude reaches any
1207
+ * tool call.
1208
+ */
1169
1209
  maxTurns?: number;
1170
1210
  }
1171
1211
  declare class ClaudeCodeLanguageModel implements LanguageModelV1 {
@@ -1249,12 +1289,20 @@ interface CreateRunnerOptions {
1249
1289
  /**
1250
1290
  * Explicit model id. Falls through to the provider's tier default.
1251
1291
  * Ignored if `runner` or `model` is set.
1292
+ *
1293
+ * When omitted, `process.env.AGENT_MODEL` is read as a default — this
1294
+ * is the only way to pin an exact model from a `.env` file (e.g.
1295
+ * `AGENT_MODEL=qwen3.6:27b` to use a model the framework's tier map
1296
+ * doesn't list).
1252
1297
  */
1253
1298
  modelId?: string;
1254
1299
  /**
1255
1300
  * Cross-provider tier selector — "opus" | "sonnet" | "haiku". Resolved
1256
1301
  * via each `ProviderProtocol.tiers` map. Default: "sonnet".
1257
1302
  * Ignored if `modelId` is set.
1303
+ *
1304
+ * When omitted, `process.env.AGENT_TIER` is read as a default. Invalid
1305
+ * values are silently ignored (fall through to the "sonnet" default).
1258
1306
  */
1259
1307
  tier?: ProviderTier;
1260
1308
  /**
@@ -3403,4 +3451,4 @@ declare class StdioAdapter {
3403
3451
  private _getConversation;
3404
3452
  }
3405
3453
 
3406
- export { ANALYSIS, type AdminServiceProtocol, AgencyRuntime, type AgentAddress, type AgentBroadcastEvent, type AgentEvent, AgentEventBus, type AgentEventType, type AgentJoinEvent, type AgentLeaveEvent, type AgentLike, type AgentLikeForBridge, type AgentMessageEvent, AgentNode, type AgentNodeOptions, AgentRunner, type AgentStats, AgentStatsSchema, type ApprovalCallback, AuditGate, type AuditLogger, BATCH_WINDOW, type BackoffStrategy, type BaseEvent, BaseExporter, BaseGate, type BaseSandboxEvent, CLAUDE_CODE_HOOK_EVENTS, CalculatorToolbox, type CanonicalMessage, type CanonicalMessagePart, ClaudeCodeAPIRunner, type ClaudeCodeHookEvent, type ClaudeCodeHookName, ClaudeCodeLanguageModel, type ClaudeCodeProviderOptions, ClaudeCodeRunner, type ClaudeCodeRunnerOptions, CompositeRefinementEvaluator, ConsoleExporter, type ConsoleLogger, type Consolidator, Conversation, type ConversationEndEvent, type ConversationExitReason, ConversationLoop, type ConversationLoopOptions, type ConversationResult, type ConversationRunOptions, type ConversationStartEvent, type ConversationStoreProtocol, type ConversationSummary, ConversationSummarySchema, type CreateRunnerOptions, DEFAULT_GLOBAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_MAX_TURNS, type DashboardStats, DashboardStatsSchema, type DateFilters, DateFiltersSchema, EVIDENCE_QUALITY, type ErrorEvent, EvaluatorChain, EvaluatorLoop, type EvaluatorLoopOptions, type EvaluatorRunOptions, EventBus, type EventHandlerFn, EventProfile, type Exchange, ExponentialBackoff, type Exporter, FixedBackoff, GATE_CATEGORY_NAMES, type Gate, GateAllow, GateBlock, GateCategory, GateModify, type GateResult, type GoalEvaluationResult, type GoalEvaluatorProtocol, type HealthPingEvent, type HealthPongEvent, HumanApprovalGate, INFORMATION_RETRIEVAL, INTENT_CLASSIFICATION, INTENT_ROUTING, InMemoryAdminService, InMemoryEventCollector, InProcessTransport, type IterationEndEvent, type IterationStartEvent, JitteredBackoff, type LLMCallEndEvent, type LLMCallStartEvent, LLMGoalEvaluator, type LLMGoalEvaluatorOptions, LLMRefinementEvaluator, type LLMRefinementEvaluatorOptions, type LangfuseClient, LangfuseExporter, type LangfuseObservation, type LangfuseSpan, MemoryStore, type MessageCancelEvent, type MessageChunkEvent, type MessageCompleteEvent, type MessageStartEvent, type MessageTemplate, MessagingToolbox, type MiddlewareFn, type MockCall, type MockResponse, MockRunner, type NodeLifecycleEvent, ORCHESTRATION, OTelExporter, type OTelSpan, OTelStatusCode, type OTelTracer, PROFILE_EVENT_TYPES, PROVIDERS, PROVIDER_PRIORITY, Parallel, type ParallelOptions, type ParallelResult, type PatternCompleteEvent, type PatternContext, type PatternEvent, type PatternHooks, type PatternIterationCompleteEvent, type PatternIterationStartEvent, type PatternProtocol, type PatternResult, type PatternRunOptions, type PatternStartEvent, type PatternStepCompleteEvent, type PatternStepErrorEvent, type PatternStepStartEvent, type ProviderProtocol, type ProviderTier, QUALITY_GATE, QUALITY_REVIEW, RESPONSE_SYNTHESIS, RETRIEVAL_STRATEGY, ROUTING, RateLimitGate, type ReasoningEvent, type Refinement, type RefinementEvaluator, type RefinementExitReason, type RefinementResult, type RetryExitReason, RetryLoop, type RetryLoopOptions, type RetryResult, type RetryRunOptions, type RubricCriterion, RubricEvaluator, type RunOptions, type RunResult, type RunnerProtocol, type RunnerSelection, type RunnerSource, type SSEEventName, SSEExporter, SSEFormatter, type SSEMapping, SSE_EVENT_NAMES, SafetyGate, type SandboxEvent, SandboxEventBus, type SandboxEventType, SelfEvalGoalEvaluator, Sequential, type SequentialOptions, type SequentialResult, SimpleGoalEvaluator, type SimpleGoalEvaluatorOptions, StdioAdapter, type Step, type StepResult, type StoredConversation, type StoredMessage, type StoredMessagePart, type StreamEvent, type SupportedProvider, type TaskAssignEvent, type TaskCreateEvent, type TaskExitReason, TaskLoop, type TaskLoopOptions, type TaskResult, type TaskRunOptions, type TaskState, type TaskUpdateEvent, type ThinkingStartEvent, TodoToolbox, type TokenUsageGroup, TokenUsageGroupSchema, type TokenUsageRow, TokenUsageRowSchema, type ToolAnalytics, ToolAnalyticsSchema, ToolCallBlocked, type ToolCallEndEvent, type ToolCallIntent, type ToolCallRecord, type ToolCallRejectedEvent, type ToolCallStartEvent, type ToolExecutor, type ToolProgressEvent, type ToolStats, ToolStatsSchema, type TraceEvent, TraceEventSchema, type TraceIteration, TraceIterationSchema, type TraceResponse, TraceResponseSchema, type TraceSummary, TraceSummarySchema, type Transport, type TransportMessage, type WeightedEvaluator, agentAddressToString, analystRole, anthropicProvider, buildAgentServers, buildCalculatorAgent, buildCapabilityServer, buildTodoAgent, buildWritingCoachAgent, claudeCode, collectByName, collectContents, convertHistory, coordinatorRole, createAgentAddress, createConsoleExporter, createEvent, createRunner, createStepResult, createToolboxExecutor, deepseekProvider, deserializeSandboxEvent, deserializeSandboxEventFromString, exchangeTotalTokens, executeStep, formatSSE, getAgentEventBus, getEventBus, googleProvider, groqProvider, isClaudeCodeHookName, makeStepName, mapClaudeCodeHookToAgentEvents, matchSubject, mistralProvider, ollamaProvider, openaiProvider, openrouterProvider, orchestratorRole, resolveMessage, resolveModelId, retrievalRole, serializeSandboxEvent, serializeSandboxEventToString, setAgentEventBus, setEventBus, subjectToRegex, subscribeProfile, subscribeProfiles, toSSEMapping, unsubscribeProfile, xaiProvider };
3454
+ export { ANALYSIS, type AdminServiceProtocol, AgencyRuntime, type AgentAddress, type AgentBroadcastEvent, type AgentEvent, AgentEventBus, type AgentEventType, type AgentJoinEvent, type AgentLeaveEvent, type AgentLike, type AgentLikeForBridge, type AgentMessageEvent, AgentNode, type AgentNodeOptions, AgentRunner, type AgentStats, AgentStatsSchema, type ApprovalCallback, AuditGate, type AuditLogger, BATCH_WINDOW, type BackoffStrategy, type BaseEvent, BaseExporter, BaseGate, type BaseSandboxEvent, CLAUDE_CODE_HOOK_EVENTS, CalculatorToolbox, type CanonicalMessage, type CanonicalMessagePart, ClaudeCodeAPIRunner, type ClaudeCodeAPIRunnerOptions, type ClaudeCodeHookEvent, type ClaudeCodeHookName, ClaudeCodeLanguageModel, type ClaudeCodeProviderOptions, ClaudeCodeRunner, type ClaudeCodeRunnerOptions, CompositeRefinementEvaluator, ConsoleExporter, type ConsoleLogger, type Consolidator, Conversation, type ConversationEndEvent, type ConversationExitReason, ConversationLoop, type ConversationLoopOptions, type ConversationResult, type ConversationRunOptions, type ConversationStartEvent, type ConversationStoreProtocol, type ConversationSummary, ConversationSummarySchema, type CreateRunnerOptions, DEFAULT_GLOBAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_MAX_TURNS, type DashboardStats, DashboardStatsSchema, type DateFilters, DateFiltersSchema, EVIDENCE_QUALITY, type ErrorEvent, EvaluatorChain, EvaluatorLoop, type EvaluatorLoopOptions, type EvaluatorRunOptions, EventBus, type EventHandlerFn, EventProfile, type Exchange, ExponentialBackoff, type Exporter, FixedBackoff, GATE_CATEGORY_NAMES, type Gate, GateAllow, GateBlock, GateCategory, GateModify, type GateResult, type GoalEvaluationResult, type GoalEvaluatorProtocol, type HealthPingEvent, type HealthPongEvent, HumanApprovalGate, INFORMATION_RETRIEVAL, INTENT_CLASSIFICATION, INTENT_ROUTING, InMemoryAdminService, InMemoryEventCollector, InProcessTransport, type IterationEndEvent, type IterationStartEvent, JitteredBackoff, type LLMCallEndEvent, type LLMCallStartEvent, LLMGoalEvaluator, type LLMGoalEvaluatorOptions, LLMRefinementEvaluator, type LLMRefinementEvaluatorOptions, type LangfuseClient, LangfuseExporter, type LangfuseObservation, type LangfuseSpan, MemoryStore, type MessageCancelEvent, type MessageChunkEvent, type MessageCompleteEvent, type MessageStartEvent, type MessageTemplate, MessagingToolbox, type MiddlewareFn, type MockCall, type MockResponse, MockRunner, type NodeLifecycleEvent, ORCHESTRATION, OTelExporter, type OTelSpan, OTelStatusCode, type OTelTracer, PROFILE_EVENT_TYPES, PROVIDERS, PROVIDER_PRIORITY, Parallel, type ParallelOptions, type ParallelResult, type PatternCompleteEvent, type PatternContext, type PatternEvent, type PatternHooks, type PatternIterationCompleteEvent, type PatternIterationStartEvent, type PatternProtocol, type PatternResult, type PatternRunOptions, type PatternStartEvent, type PatternStepCompleteEvent, type PatternStepErrorEvent, type PatternStepStartEvent, type ProviderProtocol, type ProviderTier, QUALITY_GATE, QUALITY_REVIEW, RESPONSE_SYNTHESIS, RETRIEVAL_STRATEGY, ROUTING, RateLimitGate, type ReasoningEvent, type Refinement, type RefinementEvaluator, type RefinementExitReason, type RefinementResult, type RetryExitReason, RetryLoop, type RetryLoopOptions, type RetryResult, type RetryRunOptions, type RubricCriterion, RubricEvaluator, type RunOptions, type RunResult, type RunnerProtocol, type RunnerSelection, type RunnerSource, type SSEEventName, SSEExporter, SSEFormatter, type SSEMapping, SSE_EVENT_NAMES, SafetyGate, type SandboxEvent, SandboxEventBus, type SandboxEventType, SelfEvalGoalEvaluator, Sequential, type SequentialOptions, type SequentialResult, SimpleGoalEvaluator, type SimpleGoalEvaluatorOptions, StdioAdapter, type Step, type StepResult, type StoredConversation, type StoredMessage, type StoredMessagePart, type StreamEvent, type SupportedProvider, type TaskAssignEvent, type TaskCreateEvent, type TaskExitReason, TaskLoop, type TaskLoopOptions, type TaskResult, type TaskRunOptions, type TaskState, type TaskUpdateEvent, type ThinkingStartEvent, TodoToolbox, type TokenUsageGroup, TokenUsageGroupSchema, type TokenUsageRow, TokenUsageRowSchema, type ToolAnalytics, ToolAnalyticsSchema, ToolCallBlocked, type ToolCallEndEvent, type ToolCallIntent, type ToolCallRecord, type ToolCallRejectedEvent, type ToolCallStartEvent, type ToolExecutor, type ToolProgressEvent, type ToolStats, ToolStatsSchema, type TraceEvent, TraceEventSchema, type TraceIteration, TraceIterationSchema, type TraceResponse, TraceResponseSchema, type TraceSummary, TraceSummarySchema, type Transport, type TransportMessage, type WeightedEvaluator, agentAddressToString, analystRole, anthropicProvider, buildAgentServers, buildCalculatorAgent, buildCapabilityServer, buildTodoAgent, buildWritingCoachAgent, claudeCode, collectByName, collectContents, convertHistory, coordinatorRole, createAgentAddress, createConsoleExporter, createEvent, createRunner, createStepResult, createToolboxExecutor, deepseekProvider, deserializeSandboxEvent, deserializeSandboxEventFromString, exchangeTotalTokens, executeStep, formatSSE, getAgentEventBus, getEventBus, googleProvider, groqProvider, isClaudeCodeHookName, makeStepName, mapClaudeCodeHookToAgentEvents, matchSubject, mistralProvider, ollamaProvider, openaiProvider, openrouterProvider, orchestratorRole, resolveMessage, resolveModelId, retrievalRole, serializeSandboxEvent, serializeSandboxEventToString, setAgentEventBus, setEventBus, subjectToRegex, subscribeProfile, subscribeProfiles, toSSEMapping, unsubscribeProfile, xaiProvider };
package/dist/index.js CHANGED
@@ -2114,24 +2114,60 @@ var ClaudeCodeRunner = class {
2114
2114
  };
2115
2115
 
2116
2116
  // src/runner/claude-code-api-runner.ts
2117
- var BLOCKED_TOOLS = [
2118
- "Read",
2119
- "Write",
2120
- "Edit",
2121
- "Bash",
2122
- "Glob",
2123
- "Grep",
2124
- "Agent",
2125
- "NotebookEdit",
2126
- "TodoRead",
2127
- "TodoWrite",
2128
- "WebFetch",
2129
- "WebSearch"
2130
- ];
2117
+ import { execSync } from "child_process";
2118
+ import { mkdtempSync } from "fs";
2119
+ import { tmpdir } from "os";
2120
+ import { join } from "path";
2121
+ function loadMaxSubOAuth() {
2122
+ if (process.platform !== "darwin") return null;
2123
+ const user = process.env.USER;
2124
+ if (!user) return null;
2125
+ try {
2126
+ const raw = execSync(
2127
+ `security find-generic-password -a "${user}" -s "Claude Code-credentials" -w`,
2128
+ { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
2129
+ ).trim();
2130
+ const parsed = JSON.parse(raw);
2131
+ const oauth = parsed.claudeAiOauth;
2132
+ if (!oauth?.accessToken) return null;
2133
+ return oauth;
2134
+ } catch {
2135
+ return null;
2136
+ }
2137
+ }
2131
2138
  var ClaudeCodeAPIRunner = class extends ClaudeCodeRunner {
2139
+ _disableSandbox;
2140
+ _extraDisallowed;
2141
+ _isolatedConfigDir;
2142
+ constructor(opts) {
2143
+ super(opts);
2144
+ this._disableSandbox = opts?.disableSandbox ?? false;
2145
+ this._extraDisallowed = opts?.extraDisallowedTools ?? [];
2146
+ this._isolatedConfigDir = this._disableSandbox ? null : mkdtempSync(join(tmpdir(), "ap-cc-api-"));
2147
+ }
2132
2148
  _buildOptions(agent, options, context) {
2133
2149
  const sdkOpts = super._buildOptions(agent, options, context);
2134
- sdkOpts.disallowedTools = [...BLOCKED_TOOLS];
2150
+ sdkOpts.tools = [];
2151
+ if (this._extraDisallowed.length > 0) {
2152
+ sdkOpts.disallowedTools = [
2153
+ ...sdkOpts.disallowedTools ?? [],
2154
+ ...this._extraDisallowed
2155
+ ];
2156
+ }
2157
+ if (!this._disableSandbox && this._isolatedConfigDir) {
2158
+ const oauth = loadMaxSubOAuth();
2159
+ if (oauth) {
2160
+ const baseEnv = Object.fromEntries(
2161
+ Object.entries(process.env).filter(([, v]) => typeof v === "string")
2162
+ );
2163
+ sdkOpts.env = {
2164
+ ...baseEnv,
2165
+ ...sdkOpts.env ?? {},
2166
+ CLAUDE_CONFIG_DIR: this._isolatedConfigDir,
2167
+ CLAUDE_CODE_OAUTH_TOKEN: oauth.accessToken
2168
+ };
2169
+ }
2170
+ }
2135
2171
  return sdkOpts;
2136
2172
  }
2137
2173
  };
@@ -2322,9 +2358,7 @@ function createToolboxExecutor(agent) {
2322
2358
  const actualName = name.includes("__") ? name.split("__").pop() : name;
2323
2359
  return tb.execute(actualName, args);
2324
2360
  }
2325
- throw new Error(
2326
- `Tool "${name}" not found. Available: ${[...lookup.keys()].join(", ")}`
2327
- );
2361
+ throw new Error(`Tool "${name}" not found. Available: ${[...lookup.keys()].join(", ")}`);
2328
2362
  }
2329
2363
  };
2330
2364
  }
@@ -2800,7 +2834,7 @@ var ClaudeCodeLanguageModel = class {
2800
2834
  const sdkOptions = {
2801
2835
  ...this._opts.defaults ?? {},
2802
2836
  model: mapModel2(this.modelId) ?? this._opts.defaults?.model ?? this.modelId,
2803
- maxTurns: this._opts.maxTurns ?? 1,
2837
+ maxTurns: this._opts.maxTurns ?? 10,
2804
2838
  permissionMode: "default",
2805
2839
  canUseTool
2806
2840
  };
@@ -2869,6 +2903,8 @@ function resolveModelId(provider, explicitModelId, tier = "sonnet") {
2869
2903
  // src/runner/create-runner.ts
2870
2904
  async function createRunner(opts = {}) {
2871
2905
  const verbose = opts.verbose ?? true;
2906
+ const tier = opts.tier ?? envTier();
2907
+ const modelId = opts.modelId ?? process.env.AGENT_MODEL;
2872
2908
  if (opts.runner) {
2873
2909
  return log(verbose, {
2874
2910
  runner: opts.runner,
@@ -2885,11 +2921,11 @@ async function createRunner(opts = {}) {
2885
2921
  }
2886
2922
  if (opts.provider) {
2887
2923
  const provider = PROVIDERS[opts.provider];
2888
- const modelId = resolveModelId(provider, opts.modelId, opts.tier);
2889
- const model = await provider.load(modelId);
2924
+ const resolved = resolveModelId(provider, modelId, tier);
2925
+ const model = await provider.load(resolved);
2890
2926
  return log(verbose, {
2891
2927
  runner: new AgentRunner(model, opts.eventBus),
2892
- reason: `using ${opts.provider} (explicit, model=${modelId})`,
2928
+ reason: `using ${opts.provider} (explicit, model=${resolved})`,
2893
2929
  source: "explicit-provider"
2894
2930
  });
2895
2931
  }
@@ -2897,11 +2933,11 @@ async function createRunner(opts = {}) {
2897
2933
  const provider = PROVIDERS[name];
2898
2934
  const matchedEnv = provider.envVars.find((v) => process.env[v]);
2899
2935
  if (matchedEnv) {
2900
- const modelId = resolveModelId(provider, opts.modelId, opts.tier);
2901
- const model = await provider.load(modelId);
2936
+ const resolved = resolveModelId(provider, modelId, tier);
2937
+ const model = await provider.load(resolved);
2902
2938
  return log(verbose, {
2903
2939
  runner: new AgentRunner(model, opts.eventBus),
2904
- reason: `using ${name} (env ${matchedEnv}, model=${modelId})`,
2940
+ reason: `using ${name} (env ${matchedEnv}, model=${resolved})`,
2905
2941
  source: `env-${name}`
2906
2942
  });
2907
2943
  }
@@ -2939,6 +2975,10 @@ async function createRunner(opts = {}) {
2939
2975
  ].join("\n")
2940
2976
  );
2941
2977
  }
2978
+ function envTier() {
2979
+ const v = process.env.AGENT_TIER;
2980
+ return v === "opus" || v === "sonnet" || v === "haiku" ? v : void 0;
2981
+ }
2942
2982
  function log(verbose, selection) {
2943
2983
  if (verbose) {
2944
2984
  process.stdout.write(`[runner] ${selection.reason}