@mono-agent/agent-runtime 0.18.1 → 0.18.2

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.
@@ -85,6 +85,9 @@ import { instrumentLiveInputAppliedEvents } from "./live-input-events.js";
85
85
  * Returned options are never copied into router telemetry.
86
86
  * @property {AgentRuntimeInstance} [runtime]
87
87
  * @property {Object<string, *>} [options]
88
+ * @property {{allowedTools?: ReadonlyArray<string>, disallowedTools?: ReadonlyArray<string>, permissionMode?: string}} [policyOptions]
89
+ * Provider-specific projection of the logical tool policy. This deliberately
90
+ * cannot replace any other protected request field.
88
91
  * @property {() => (void|Promise<void>)} [cleanup]
89
92
  */
90
93
 
@@ -243,6 +246,7 @@ export function createRouterRuntime({ host = {}, chain = [], routeSafety = "unif
243
246
  attemptCleanup = resolution?.cleanup;
244
247
  if (resolveAttempt !== undefined) {
245
248
  callOptions = mergeAttemptOptions(callOptions, resolution?.options);
249
+ callOptions = mergeAttemptPolicyOptions(callOptions, resolution?.policyOptions);
246
250
  }
247
251
  if (routeSafety === "per-route-native") {
248
252
  callOptions = projectPerRouteNativeOptions(entry, callOptions);
@@ -804,6 +808,33 @@ function normalizeAttemptResolution(value) {
804
808
  if (value.cleanup !== undefined && typeof value.cleanup !== "function") {
805
809
  throw new Error("route attempt resolver cleanup must be a function");
806
810
  }
811
+ return {
812
+ ...value,
813
+ ...(value.policyOptions === undefined
814
+ ? {}
815
+ : { policyOptions: normalizeAttemptPolicyOptions(value.policyOptions) }),
816
+ };
817
+ }
818
+
819
+ const ATTEMPT_POLICY_OPTION_KEYS = new Set(["allowedTools", "disallowedTools", "permissionMode"]);
820
+
821
+ function normalizeAttemptPolicyOptions(value) {
822
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
823
+ throw new Error("route attempt resolver policyOptions must be an object");
824
+ }
825
+ for (const key of Object.keys(value)) {
826
+ if (!ATTEMPT_POLICY_OPTION_KEYS.has(key)) {
827
+ throw new Error(`route attempt resolver policyOptions cannot override ${key}`);
828
+ }
829
+ }
830
+ for (const key of ["allowedTools", "disallowedTools"]) {
831
+ if (value[key] !== undefined && !Array.isArray(value[key])) {
832
+ throw new Error(`route attempt resolver policyOptions.${key} must be an array or undefined`);
833
+ }
834
+ }
835
+ if (value.permissionMode !== undefined && typeof value.permissionMode !== "string") {
836
+ throw new Error("route attempt resolver policyOptions.permissionMode must be a string or undefined");
837
+ }
807
838
  return value;
808
839
  }
809
840
 
@@ -826,6 +857,17 @@ function mergeAttemptOptions(base, resolved) {
826
857
  return merged;
827
858
  }
828
859
 
860
+ function mergeAttemptPolicyOptions(base, policyOptions) {
861
+ if (policyOptions === undefined) return base;
862
+ const merged = { ...base };
863
+ for (const key of ATTEMPT_POLICY_OPTION_KEYS) {
864
+ if (!Object.hasOwn(policyOptions, key)) continue;
865
+ if (policyOptions[key] === undefined) delete merged[key];
866
+ else merged[key] = policyOptions[key];
867
+ }
868
+ return merged;
869
+ }
870
+
829
871
  /**
830
872
  * @param {Object<string, *>} options
831
873
  * @returns {Object<string, *>}
package/src/ai/types.js CHANGED
@@ -40,10 +40,80 @@
40
40
  */
41
41
 
42
42
  /**
43
- * @typedef {{type: string, [key: string]: *}} RuntimeEvent
44
- * Structured runtime/telemetry event. `type` is the only required field;
45
- * every event kind (tool_approval_pending, provider_failover_started,
46
- * context_compaction_applied, ...) adds its own extra fields.
43
+ * @typedef {Object} RuntimeNativeSubagentDefinition
44
+ * One caller-defined Claude native `Task` profile. Codex collaboration-agent
45
+ * definitions are owned by Codex and are not represented by this type.
46
+ * @property {string} name
47
+ * @property {string} [displayName]
48
+ * @property {string} [description]
49
+ * @property {string} [helperSystemPrompt]
50
+ * @property {string} [instructions]
51
+ * @property {ReadonlyArray<string>} [allowedTools]
52
+ * @property {ReadonlyArray<string>} [disallowedTools]
53
+ * @property {string | RuntimeModelRef} [modelRef]
54
+ * @property {RuntimeModelRef} [model]
55
+ * @property {string} [effort]
56
+ * @property {Object<string, Object>} [mcpServers]
57
+ */
58
+
59
+ /**
60
+ * @typedef {Object} RuntimeNativeSubagentsOptions
61
+ * Caller-defined native profiles are supported only by the Claude bridges.
62
+ * Codex owns its collaboration agents; use `codexLoadProjectDocs` when those
63
+ * agents should receive repository instructions.
64
+ * @property {"claude"} provider
65
+ * @property {ReadonlyArray<RuntimeNativeSubagentDefinition>} teammates
66
+ */
67
+
68
+ /**
69
+ * @typedef {Object} RuntimeSubagentIdentity
70
+ * Provider-neutral identity attached to every `subagent_activity` event.
71
+ * @property {string} id The canonical parent attachment key: the initiating
72
+ * parent tool-use id when the provider exposes it, or a stable synthetic key
73
+ * for an orphan lifecycle record. A provider-native task/thread id never replaces it.
74
+ * @property {string} [nativeId] Provider-native task or thread id, retained only
75
+ * as diagnostic/correlation metadata.
76
+ * @property {string} name Provider-neutral profile/agent name.
77
+ * @property {number} callIndex Provider call-order ordinal; consumers must not
78
+ * use it as an identity key.
79
+ * @property {string} [label] Short task label or description.
80
+ * @property {string} [agentPath] Provider-reported ancestry for a
81
+ * nested native agent. Informational only; `id` remains the attachment key.
82
+ * @property {number} [costUsd] Priced delegation cost, when the runtime can
83
+ * attribute it to this subagent.
84
+ */
85
+
86
+ /**
87
+ * @typedef {"agent_started"|"started"|"completed"|"message"|"agent_completed"} RuntimeSubagentActivityPhase
88
+ * `agent_started`/`agent_completed` bracket the delegation; `started`/`completed`
89
+ * bracket one child tool call; `message` carries optional child-only prose or
90
+ * thinking and must never be treated as parent answer text or a completed tool.
91
+ */
92
+
93
+ /**
94
+ * @typedef {Object} RuntimeSubagentActivityEvent
95
+ * One normalized native or in-process subagent activity event.
96
+ * @property {"subagent_activity"} type
97
+ * @property {RuntimeSubagentIdentity} subagent
98
+ * @property {RuntimeSubagentActivityPhase} phase
99
+ * @property {string} id Unique activity-row id, namespaced from the canonical
100
+ * `subagent.id` for lifecycle and tool rows.
101
+ * @property {string} [name]
102
+ * @property {*} [arguments]
103
+ * @property {*} [content]
104
+ * @property {"text"|"thinking"|"status"|"warning"|"error"} [kind] Present on a
105
+ * `message` phase when known.
106
+ * @property {"assistant"|"user"} [role] Present on a `message` phase when known.
107
+ * @property {boolean} [isError]
108
+ * @property {number} [executionMs]
109
+ * @property {number} [totalTokens]
110
+ */
111
+
112
+ /**
113
+ * @typedef {RuntimeSubagentActivityEvent | {type: string, [key: string]: *}} RuntimeEvent
114
+ * Structured runtime/telemetry event. Subagent activity uses the normalized
115
+ * shape above; every other event kind (tool_approval_pending,
116
+ * provider_failover_started, context_compaction, ...) adds its own fields.
47
117
  */
48
118
 
49
119
  /** @typedef {"uniform"|"per-route-native"} RuntimeRouteSafetyMode */
@@ -171,7 +241,20 @@
171
241
  * @property {"sequential"|"safe-parallel"} [piToolExecutionMode] Pi built-in tool scheduling mode. Safe parallelism is the default.
172
242
  * @property {"one-at-a-time"|"all"} [piToolParallelismMode] DEPRECATED. Compatibility alias mapped to piToolExecutionMode.
173
243
  * @property {Object} [settings] DEPRECATED. Legacy flat settings bag; consumed only as a per-group FALLBACK when the corresponding typed object (`toolLimits` / `compaction`) is absent. Consuming any key emits one `deprecated_settings_option` runtime_warning per run. Migrate via resolveRuntimePolicies (@mono-agent/runtime-adapter).
174
- * @property {Object} [nativeSubagents] Same-runtime teammate helpers exposed through native provider subagent surfaces.
244
+ * @property {ReadonlyArray<"user" | "project" | "local">} [settingSources] Claude Agent SDK only. Filesystem
245
+ * settings the SDK may load for this run. Omitted/empty disables user, project, and local sources, including their
246
+ * CLAUDE.md, hooks, plugins, and on-disk agent profiles. Anthropic managed settings remain in force and may still
247
+ * configure hooks or plugins; this option is not a managed-policy bypass. Each opted-in source may execute configured
248
+ * hooks and plugins, so enable only trusted settings and avoid these sources in an untrusted checkout. Include
249
+ * `"project"`/`"user"` to let the native `Task` tool discover `.claude/agents` definitions. Unrecognized entries are
250
+ * dropped. The Claude Code CLI bridge does not take this option: that binary performs its own settings discovery and
251
+ * mono-agent passes no `--setting-sources`, so a CLI run already reads the host config regardless of this value.
252
+ * @property {boolean} [codexLoadProjectDocs] Codex app-server only. Omitted/false starts the managed app-server with
253
+ * `project_doc_max_bytes=0`, preventing automatic repository-instruction discovery. True restores Codex's native
254
+ * project-doc loading defaults. An explicit `codexAppServerArgs` array wins over this convenience option.
255
+ * @property {RuntimeNativeSubagentsOptions} [nativeSubagents] Caller-defined Claude native `Task` profiles. Direct
256
+ * Codex owns its collaboration agents and rejects configured teammate definitions; `codexLoadProjectDocs` controls
257
+ * whether Codex loads repository instructions for its own agents.
175
258
  * @property {RuntimeSubagentsOptions} [subagents] In-process `Agent` built-in: profiles, caps, and the nested-run callback.
176
259
  * @property {Object} [diagnosticsSeed] Set by createRouterRuntime (ai/runtime/router.js) with a `resume_snapshot` when
177
260
  * failing over mid-chain; a host-level coordinator may relay it forward (see agent/transcript.js), not read by any
@@ -222,11 +305,14 @@
222
305
 
223
306
  /**
224
307
  * @typedef {Object} RuntimeInlineSubagentsOptions
225
- * Policy for subagents the model authors at call time rather than picking from
226
- * `definitions`. Absent suppresses authoring entirely.
308
+ * Policy for the runtime-owned general-purpose helper and subagents the model
309
+ * authors at call time rather than picking from `definitions`. Absent
310
+ * suppresses authoring entirely and leaves general-purpose on its safe default.
227
311
  * @property {boolean} [enabled] Only `false` turns authoring off.
228
- * @property {ReadonlyArray<string>} [allowedTools] Ceiling on what an authored subagent may
229
- * request. Absent means the safe read-only default set, never every built-in.
312
+ * @property {ReadonlyArray<string>} [allowedTools] Ceiling on general-purpose's
313
+ * read-only tools and what an authored subagent may request. Configured
314
+ * definitions keep their explicit contracts. Absent means the safe read-only
315
+ * default set, never every built-in.
230
316
  */
231
317
 
232
318
  /**
@@ -282,7 +368,9 @@
282
368
  * @property {boolean} [supports_skills]
283
369
  * @property {boolean} [supports_builtin_tools]
284
370
  * @property {boolean} [supports_live_input]
285
- * @property {boolean} [supports_native_subagents]
371
+ * @property {boolean} [supports_native_subagents] Whether the bridge exposes provider-native subagent surfaces and
372
+ * normalized activity. This does not imply it accepts caller-defined `nativeSubagents`: Codex owns its collaboration
373
+ * agents, while only the Claude bridges project caller-defined profiles.
286
374
  * @property {boolean} [supports_request_tool_environment]
287
375
  * @property {boolean} [supports_fast_mode]
288
376
  * @property {"projected"|"allow_all_only"} [tool_policy] Whether the bridge can
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * One ephemeral web-tool controller for one model run. It owns in-memory
3
- * deduplication, result caches, anonymous browser namespaces, and cleanup.
3
+ * deduplication, the fetch result cache, anonymous browser namespaces, and
4
+ * cleanup. Search results are the exception: they live in the process-wide
5
+ * cache above so sibling subagents and later turns can reuse them.
4
6
  *
5
7
  * @param {{searchConfig?: any, fetchConfig?: any, sandboxPolicy?: any, sandboxEngine?: any, ctx?: any, fetchImpl?: typeof fetch, browserRenderer?: any}} [options]
6
8
  */
@@ -18,3 +20,5 @@ export function createWebToolController({ searchConfig, fetchConfig, sandboxPoli
18
20
  fetch(params: any, execution?: {}): Promise<any>;
19
21
  close(): Promise<void>;
20
22
  };
23
+ /** Test hook: the shared cache is module state and would leak between cases. */
24
+ export function __resetSharedSearchCacheForTests(): void;
@@ -68,9 +68,22 @@ export function performWebSearch({ query, limit, alternate_queries, domains, exc
68
68
  truncated: boolean;
69
69
  resultCount: number;
70
70
  providerFailureCount: number;
71
+ rateLimited: boolean;
72
+ cooldownBackends: string[];
71
73
  };
72
74
  error: boolean;
73
75
  }>;
76
+ /**
77
+ * Test hook: restores the shipped throttle values and clears cooldown/spacing
78
+ * state. Module-scoped state would otherwise leak between test cases.
79
+ *
80
+ * @param {{maxConcurrency?: number, minSpacingMs?: number, cooldownMs?: number}} [overrides]
81
+ */
82
+ export function __resetWebSearchThrottleForTests(overrides?: {
83
+ maxConcurrency?: number;
84
+ minSpacingMs?: number;
85
+ cooldownMs?: number;
86
+ }): void;
74
87
  export function parseDuckDuckGoResults(html: any): {
75
88
  title: string;
76
89
  url: string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Correlate Claude's live native-agent stream into provider-neutral
3
+ * `subagent_activity` events.
4
+ *
5
+ * `observe()` returns `consumed: true` for every event owned by a native
6
+ * subagent. Provider bridges must not additionally forward or interpret those
7
+ * records as parent events. Non-agent background tasks are consumed without
8
+ * creating activity.
9
+ */
10
+ export function createClaudeSubagentActivityNormalizer(): {
11
+ observe: (raw: Record<string, any>) => {
12
+ consumed: boolean;
13
+ events: {
14
+ type: string;
15
+ subagent: {
16
+ label?: any;
17
+ nativeId?: any;
18
+ id: any;
19
+ name: any;
20
+ callIndex: any;
21
+ };
22
+ }[];
23
+ forwarded?: undefined;
24
+ } | {
25
+ consumed: boolean;
26
+ events: {
27
+ type: string;
28
+ subagent: {
29
+ label?: any;
30
+ nativeId?: any;
31
+ id: any;
32
+ name: any;
33
+ callIndex: any;
34
+ };
35
+ }[];
36
+ forwarded: {
37
+ message: any;
38
+ };
39
+ };
40
+ /** Close every still-open child and its tools exactly once. */
41
+ drain(reason?: string): {
42
+ type: string;
43
+ subagent: {
44
+ label?: any;
45
+ nativeId?: any;
46
+ id: any;
47
+ name: any;
48
+ callIndex: any;
49
+ };
50
+ }[];
51
+ subagentInvoked: () => boolean;
52
+ nativeSubagentsUsed: () => any[];
53
+ };
@@ -73,5 +73,14 @@ export type RouterAttemptResolution = {
73
73
  options?: {
74
74
  [x: string]: any;
75
75
  };
76
+ /**
77
+ * Provider-specific projection of the logical tool policy. This deliberately
78
+ * cannot replace any other protected request field.
79
+ */
80
+ policyOptions?: {
81
+ allowedTools?: ReadonlyArray<string>;
82
+ disallowedTools?: ReadonlyArray<string>;
83
+ permissionMode?: string;
84
+ };
76
85
  cleanup?: () => (void | Promise<void>);
77
86
  };
@@ -20,10 +20,75 @@
20
20
  * @property {string} [provider] Pi/OpenCode provider id when sdk === "pi" | "opencode".
21
21
  */
22
22
  /**
23
- * @typedef {{type: string, [key: string]: *}} RuntimeEvent
24
- * Structured runtime/telemetry event. `type` is the only required field;
25
- * every event kind (tool_approval_pending, provider_failover_started,
26
- * context_compaction_applied, ...) adds its own extra fields.
23
+ * @typedef {Object} RuntimeNativeSubagentDefinition
24
+ * One caller-defined Claude native `Task` profile. Codex collaboration-agent
25
+ * definitions are owned by Codex and are not represented by this type.
26
+ * @property {string} name
27
+ * @property {string} [displayName]
28
+ * @property {string} [description]
29
+ * @property {string} [helperSystemPrompt]
30
+ * @property {string} [instructions]
31
+ * @property {ReadonlyArray<string>} [allowedTools]
32
+ * @property {ReadonlyArray<string>} [disallowedTools]
33
+ * @property {string | RuntimeModelRef} [modelRef]
34
+ * @property {RuntimeModelRef} [model]
35
+ * @property {string} [effort]
36
+ * @property {Object<string, Object>} [mcpServers]
37
+ */
38
+ /**
39
+ * @typedef {Object} RuntimeNativeSubagentsOptions
40
+ * Caller-defined native profiles are supported only by the Claude bridges.
41
+ * Codex owns its collaboration agents; use `codexLoadProjectDocs` when those
42
+ * agents should receive repository instructions.
43
+ * @property {"claude"} provider
44
+ * @property {ReadonlyArray<RuntimeNativeSubagentDefinition>} teammates
45
+ */
46
+ /**
47
+ * @typedef {Object} RuntimeSubagentIdentity
48
+ * Provider-neutral identity attached to every `subagent_activity` event.
49
+ * @property {string} id The canonical parent attachment key: the initiating
50
+ * parent tool-use id when the provider exposes it, or a stable synthetic key
51
+ * for an orphan lifecycle record. A provider-native task/thread id never replaces it.
52
+ * @property {string} [nativeId] Provider-native task or thread id, retained only
53
+ * as diagnostic/correlation metadata.
54
+ * @property {string} name Provider-neutral profile/agent name.
55
+ * @property {number} callIndex Provider call-order ordinal; consumers must not
56
+ * use it as an identity key.
57
+ * @property {string} [label] Short task label or description.
58
+ * @property {string} [agentPath] Provider-reported ancestry for a
59
+ * nested native agent. Informational only; `id` remains the attachment key.
60
+ * @property {number} [costUsd] Priced delegation cost, when the runtime can
61
+ * attribute it to this subagent.
62
+ */
63
+ /**
64
+ * @typedef {"agent_started"|"started"|"completed"|"message"|"agent_completed"} RuntimeSubagentActivityPhase
65
+ * `agent_started`/`agent_completed` bracket the delegation; `started`/`completed`
66
+ * bracket one child tool call; `message` carries optional child-only prose or
67
+ * thinking and must never be treated as parent answer text or a completed tool.
68
+ */
69
+ /**
70
+ * @typedef {Object} RuntimeSubagentActivityEvent
71
+ * One normalized native or in-process subagent activity event.
72
+ * @property {"subagent_activity"} type
73
+ * @property {RuntimeSubagentIdentity} subagent
74
+ * @property {RuntimeSubagentActivityPhase} phase
75
+ * @property {string} id Unique activity-row id, namespaced from the canonical
76
+ * `subagent.id` for lifecycle and tool rows.
77
+ * @property {string} [name]
78
+ * @property {*} [arguments]
79
+ * @property {*} [content]
80
+ * @property {"text"|"thinking"|"status"|"warning"|"error"} [kind] Present on a
81
+ * `message` phase when known.
82
+ * @property {"assistant"|"user"} [role] Present on a `message` phase when known.
83
+ * @property {boolean} [isError]
84
+ * @property {number} [executionMs]
85
+ * @property {number} [totalTokens]
86
+ */
87
+ /**
88
+ * @typedef {RuntimeSubagentActivityEvent | {type: string, [key: string]: *}} RuntimeEvent
89
+ * Structured runtime/telemetry event. Subagent activity uses the normalized
90
+ * shape above; every other event kind (tool_approval_pending,
91
+ * provider_failover_started, context_compaction, ...) adds its own fields.
27
92
  */
28
93
  /** @typedef {"uniform"|"per-route-native"} RuntimeRouteSafetyMode */
29
94
  /**
@@ -142,7 +207,20 @@
142
207
  * @property {"sequential"|"safe-parallel"} [piToolExecutionMode] Pi built-in tool scheduling mode. Safe parallelism is the default.
143
208
  * @property {"one-at-a-time"|"all"} [piToolParallelismMode] DEPRECATED. Compatibility alias mapped to piToolExecutionMode.
144
209
  * @property {Object} [settings] DEPRECATED. Legacy flat settings bag; consumed only as a per-group FALLBACK when the corresponding typed object (`toolLimits` / `compaction`) is absent. Consuming any key emits one `deprecated_settings_option` runtime_warning per run. Migrate via resolveRuntimePolicies (@mono-agent/runtime-adapter).
145
- * @property {Object} [nativeSubagents] Same-runtime teammate helpers exposed through native provider subagent surfaces.
210
+ * @property {ReadonlyArray<"user" | "project" | "local">} [settingSources] Claude Agent SDK only. Filesystem
211
+ * settings the SDK may load for this run. Omitted/empty disables user, project, and local sources, including their
212
+ * CLAUDE.md, hooks, plugins, and on-disk agent profiles. Anthropic managed settings remain in force and may still
213
+ * configure hooks or plugins; this option is not a managed-policy bypass. Each opted-in source may execute configured
214
+ * hooks and plugins, so enable only trusted settings and avoid these sources in an untrusted checkout. Include
215
+ * `"project"`/`"user"` to let the native `Task` tool discover `.claude/agents` definitions. Unrecognized entries are
216
+ * dropped. The Claude Code CLI bridge does not take this option: that binary performs its own settings discovery and
217
+ * mono-agent passes no `--setting-sources`, so a CLI run already reads the host config regardless of this value.
218
+ * @property {boolean} [codexLoadProjectDocs] Codex app-server only. Omitted/false starts the managed app-server with
219
+ * `project_doc_max_bytes=0`, preventing automatic repository-instruction discovery. True restores Codex's native
220
+ * project-doc loading defaults. An explicit `codexAppServerArgs` array wins over this convenience option.
221
+ * @property {RuntimeNativeSubagentsOptions} [nativeSubagents] Caller-defined Claude native `Task` profiles. Direct
222
+ * Codex owns its collaboration agents and rejects configured teammate definitions; `codexLoadProjectDocs` controls
223
+ * whether Codex loads repository instructions for its own agents.
146
224
  * @property {RuntimeSubagentsOptions} [subagents] In-process `Agent` built-in: profiles, caps, and the nested-run callback.
147
225
  * @property {Object} [diagnosticsSeed] Set by createRouterRuntime (ai/runtime/router.js) with a `resume_snapshot` when
148
226
  * failing over mid-chain; a host-level coordinator may relay it forward (see agent/transcript.js), not read by any
@@ -189,11 +267,14 @@
189
267
  */
190
268
  /**
191
269
  * @typedef {Object} RuntimeInlineSubagentsOptions
192
- * Policy for subagents the model authors at call time rather than picking from
193
- * `definitions`. Absent suppresses authoring entirely.
270
+ * Policy for the runtime-owned general-purpose helper and subagents the model
271
+ * authors at call time rather than picking from `definitions`. Absent
272
+ * suppresses authoring entirely and leaves general-purpose on its safe default.
194
273
  * @property {boolean} [enabled] Only `false` turns authoring off.
195
- * @property {ReadonlyArray<string>} [allowedTools] Ceiling on what an authored subagent may
196
- * request. Absent means the safe read-only default set, never every built-in.
274
+ * @property {ReadonlyArray<string>} [allowedTools] Ceiling on general-purpose's
275
+ * read-only tools and what an authored subagent may request. Configured
276
+ * definitions keep their explicit contracts. Absent means the safe read-only
277
+ * default set, never every built-in.
197
278
  */
198
279
  /**
199
280
  * @typedef {Object} RuntimeSubagentsOptions
@@ -246,7 +327,9 @@
246
327
  * @property {boolean} [supports_skills]
247
328
  * @property {boolean} [supports_builtin_tools]
248
329
  * @property {boolean} [supports_live_input]
249
- * @property {boolean} [supports_native_subagents]
330
+ * @property {boolean} [supports_native_subagents] Whether the bridge exposes provider-native subagent surfaces and
331
+ * normalized activity. This does not imply it accepts caller-defined `nativeSubagents`: Codex owns its collaboration
332
+ * agents, while only the Claude bridges project caller-defined profiles.
250
333
  * @property {boolean} [supports_request_tool_environment]
251
334
  * @property {boolean} [supports_fast_mode]
252
335
  * @property {"projected"|"allow_all_only"} [tool_policy] Whether the bridge can
@@ -390,11 +473,112 @@ export type RuntimeModelRef = {
390
473
  provider?: string;
391
474
  };
392
475
  /**
393
- * Structured runtime/telemetry event. `type` is the only required field;
394
- * every event kind (tool_approval_pending, provider_failover_started,
395
- * context_compaction_applied, ...) adds its own extra fields.
476
+ * One caller-defined Claude native `Task` profile. Codex collaboration-agent
477
+ * definitions are owned by Codex and are not represented by this type.
478
+ */
479
+ export type RuntimeNativeSubagentDefinition = {
480
+ name: string;
481
+ displayName?: string;
482
+ description?: string;
483
+ helperSystemPrompt?: string;
484
+ instructions?: string;
485
+ allowedTools?: ReadonlyArray<string>;
486
+ disallowedTools?: ReadonlyArray<string>;
487
+ modelRef?: string | RuntimeModelRef;
488
+ model?: RuntimeModelRef;
489
+ effort?: string;
490
+ mcpServers?: {
491
+ [x: string]: any;
492
+ };
493
+ };
494
+ /**
495
+ * Caller-defined native profiles are supported only by the Claude bridges.
496
+ * Codex owns its collaboration agents; use `codexLoadProjectDocs` when those
497
+ * agents should receive repository instructions.
498
+ */
499
+ export type RuntimeNativeSubagentsOptions = {
500
+ provider: "claude";
501
+ teammates: ReadonlyArray<RuntimeNativeSubagentDefinition>;
502
+ };
503
+ /**
504
+ * Provider-neutral identity attached to every `subagent_activity` event.
396
505
  */
397
- export type RuntimeEvent = {
506
+ export type RuntimeSubagentIdentity = {
507
+ /**
508
+ * The canonical parent attachment key: the initiating
509
+ * parent tool-use id when the provider exposes it, or a stable synthetic key
510
+ * for an orphan lifecycle record. A provider-native task/thread id never replaces it.
511
+ */
512
+ id: string;
513
+ /**
514
+ * Provider-native task or thread id, retained only
515
+ * as diagnostic/correlation metadata.
516
+ */
517
+ nativeId?: string;
518
+ /**
519
+ * Provider-neutral profile/agent name.
520
+ */
521
+ name: string;
522
+ /**
523
+ * Provider call-order ordinal; consumers must not
524
+ * use it as an identity key.
525
+ */
526
+ callIndex: number;
527
+ /**
528
+ * Short task label or description.
529
+ */
530
+ label?: string;
531
+ /**
532
+ * Provider-reported ancestry for a
533
+ * nested native agent. Informational only; `id` remains the attachment key.
534
+ */
535
+ agentPath?: string;
536
+ /**
537
+ * Priced delegation cost, when the runtime can
538
+ * attribute it to this subagent.
539
+ */
540
+ costUsd?: number;
541
+ };
542
+ /**
543
+ * `agent_started`/`agent_completed` bracket the delegation; `started`/`completed`
544
+ * bracket one child tool call; `message` carries optional child-only prose or
545
+ * thinking and must never be treated as parent answer text or a completed tool.
546
+ */
547
+ export type RuntimeSubagentActivityPhase = "agent_started" | "started" | "completed" | "message" | "agent_completed";
548
+ /**
549
+ * One normalized native or in-process subagent activity event.
550
+ */
551
+ export type RuntimeSubagentActivityEvent = {
552
+ type: "subagent_activity";
553
+ subagent: RuntimeSubagentIdentity;
554
+ phase: RuntimeSubagentActivityPhase;
555
+ /**
556
+ * Unique activity-row id, namespaced from the canonical
557
+ * `subagent.id` for lifecycle and tool rows.
558
+ */
559
+ id: string;
560
+ name?: string;
561
+ arguments?: any;
562
+ content?: any;
563
+ /**
564
+ * Present on a
565
+ * `message` phase when known.
566
+ */
567
+ kind?: "text" | "thinking" | "status" | "warning" | "error";
568
+ /**
569
+ * Present on a `message` phase when known.
570
+ */
571
+ role?: "assistant" | "user";
572
+ isError?: boolean;
573
+ executionMs?: number;
574
+ totalTokens?: number;
575
+ };
576
+ /**
577
+ * Structured runtime/telemetry event. Subagent activity uses the normalized
578
+ * shape above; every other event kind (tool_approval_pending,
579
+ * provider_failover_started, context_compaction, ...) adds its own fields.
580
+ */
581
+ export type RuntimeEvent = RuntimeSubagentActivityEvent | {
398
582
  type: string;
399
583
  [key: string]: any;
400
584
  };
@@ -675,9 +859,28 @@ export type RuntimeRunOptions = {
675
859
  */
676
860
  settings?: any;
677
861
  /**
678
- * Same-runtime teammate helpers exposed through native provider subagent surfaces.
862
+ * Claude Agent SDK only. Filesystem
863
+ * settings the SDK may load for this run. Omitted/empty disables user, project, and local sources, including their
864
+ * CLAUDE.md, hooks, plugins, and on-disk agent profiles. Anthropic managed settings remain in force and may still
865
+ * configure hooks or plugins; this option is not a managed-policy bypass. Each opted-in source may execute configured
866
+ * hooks and plugins, so enable only trusted settings and avoid these sources in an untrusted checkout. Include
867
+ * `"project"`/`"user"` to let the native `Task` tool discover `.claude/agents` definitions. Unrecognized entries are
868
+ * dropped. The Claude Code CLI bridge does not take this option: that binary performs its own settings discovery and
869
+ * mono-agent passes no `--setting-sources`, so a CLI run already reads the host config regardless of this value.
870
+ */
871
+ settingSources?: ReadonlyArray<"user" | "project" | "local">;
872
+ /**
873
+ * Codex app-server only. Omitted/false starts the managed app-server with
874
+ * `project_doc_max_bytes=0`, preventing automatic repository-instruction discovery. True restores Codex's native
875
+ * project-doc loading defaults. An explicit `codexAppServerArgs` array wins over this convenience option.
679
876
  */
680
- nativeSubagents?: any;
877
+ codexLoadProjectDocs?: boolean;
878
+ /**
879
+ * Caller-defined Claude native `Task` profiles. Direct
880
+ * Codex owns its collaboration agents and rejects configured teammate definitions; `codexLoadProjectDocs` controls
881
+ * whether Codex loads repository instructions for its own agents.
882
+ */
883
+ nativeSubagents?: RuntimeNativeSubagentsOptions;
681
884
  /**
682
885
  * In-process `Agent` built-in: profiles, caps, and the nested-run callback.
683
886
  */
@@ -752,8 +955,9 @@ export type RuntimeSubagentDefinition = {
752
955
  */
753
956
  export type RuntimeSubagentRun = (request: any) => Promise<RuntimeResult>;
754
957
  /**
755
- * Policy for subagents the model authors at call time rather than picking from
756
- * `definitions`. Absent suppresses authoring entirely.
958
+ * Policy for the runtime-owned general-purpose helper and subagents the model
959
+ * authors at call time rather than picking from `definitions`. Absent
960
+ * suppresses authoring entirely and leaves general-purpose on its safe default.
757
961
  */
758
962
  export type RuntimeInlineSubagentsOptions = {
759
963
  /**
@@ -761,8 +965,10 @@ export type RuntimeInlineSubagentsOptions = {
761
965
  */
762
966
  enabled?: boolean;
763
967
  /**
764
- * Ceiling on what an authored subagent may
765
- * request. Absent means the safe read-only default set, never every built-in.
968
+ * Ceiling on general-purpose's
969
+ * read-only tools and what an authored subagent may request. Configured
970
+ * definitions keep their explicit contracts. Absent means the safe read-only
971
+ * default set, never every built-in.
766
972
  */
767
973
  allowedTools?: ReadonlyArray<string>;
768
974
  };
@@ -864,6 +1070,11 @@ export type RuntimeCapabilities = {
864
1070
  supports_skills?: boolean;
865
1071
  supports_builtin_tools?: boolean;
866
1072
  supports_live_input?: boolean;
1073
+ /**
1074
+ * Whether the bridge exposes provider-native subagent surfaces and
1075
+ * normalized activity. This does not imply it accepts caller-defined `nativeSubagents`: Codex owns its collaboration
1076
+ * agents, while only the Claude bridges project caller-defined profiles.
1077
+ */
867
1078
  supports_native_subagents?: boolean;
868
1079
  supports_request_tool_environment?: boolean;
869
1080
  supports_fast_mode?: boolean;