@rowan-agent/agent 0.29.0 → 0.30.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.
@@ -0,0 +1,2423 @@
1
+ import * as _rowan_agent_models from '@rowan-agent/models';
2
+ import { LlmContentPart, ModelRef, LlmTokenUsage, JsonObject as JsonObject$1, ScopeRef, ToolCallStatus, JsonValue as JsonValue$1, ToolProgress, ToolCallContent, ToolCallLocation, ToolKind, ModelConfig, StreamFn, ToolAnnotations, ThinkingLevel, ContentBlock, ToolCall as ToolCall$1, ToolCallUpdate, ProviderConfig } from '@rowan-agent/models';
3
+ import Type from 'typebox';
4
+
5
+ type AgentMessage = {
6
+ id: string;
7
+ role: "system" | "user" | "assistant" | "tool";
8
+ content: string | LlmContentPart[];
9
+ createdAt: string;
10
+ metadata?: Record<string, unknown> & {
11
+ phase?: string;
12
+ };
13
+ contexts?: readonly ContextCandidate[];
14
+ model?: ModelRef;
15
+ usage?: LlmTokenUsage;
16
+ };
17
+ type Skill = {
18
+ name: string;
19
+ description: string;
20
+ /** Absolute path to the SKILL.md file */
21
+ filePath: string;
22
+ /** Directory containing the SKILL.md file */
23
+ baseDir: string;
24
+ /** Full body content of the SKILL.md (after frontmatter) */
25
+ content: string;
26
+ /** Do not automatically inject this Skill into the model Context. */
27
+ disableAutoInvocation?: boolean;
28
+ /** Do not expose this Skill to direct user invocation. */
29
+ disableImplicitInvocation?: boolean;
30
+ /** @deprecated Use disableAutoInvocation; kept only for old in-memory callers during cutover. */
31
+ disableModelInvocation?: boolean;
32
+ };
33
+ type Outcome$1 = {
34
+ id: string;
35
+ message: string;
36
+ /** Publish this outcome's message as an assistant message before completing the run. */
37
+ display?: boolean;
38
+ payload?: unknown;
39
+ toolResults?: Array<{
40
+ toolCallId: string;
41
+ toolName: string;
42
+ ok: boolean;
43
+ content: unknown;
44
+ error?: string;
45
+ }>;
46
+ };
47
+ type ToolCall = {
48
+ id: string;
49
+ name: string;
50
+ args: unknown;
51
+ };
52
+ type ToolResult = {
53
+ toolCallId: string;
54
+ toolName: string;
55
+ ok: boolean;
56
+ content: unknown;
57
+ error?: string;
58
+ structuredContent?: unknown;
59
+ isError?: boolean;
60
+ };
61
+
62
+ type PhaseRegistrySelection = Readonly<{
63
+ entryPhaseId: string | null;
64
+ phaseIds: readonly string[];
65
+ }>;
66
+ type AgentDefinition = Readonly<{
67
+ name: string;
68
+ description: string;
69
+ prompt: string;
70
+ tools?: readonly string[];
71
+ skills?: readonly string[];
72
+ /** Host-supplied Skills private to this Agent Definition/Bundle. */
73
+ bundledSkills?: readonly Skill[];
74
+ phases?: PhaseRegistrySelection;
75
+ contexts?: readonly string[];
76
+ model?: ModelRef;
77
+ }>;
78
+ /** Parse one Markdown definition using the same frontmatter vocabulary as Phase resources. */
79
+ declare function parseAgentDefinition(raw: string): AgentDefinition;
80
+
81
+ type ResourceKind = "agent" | "tool" | "skill" | "phase";
82
+ type ResourceSourceId = string;
83
+ /** Rowan-native contribution aliases. Hosts may adapt their domain handlers to
84
+ * these existing Tool/Phase lifecycles without importing host Scope types. */
85
+ type ToolContribution = Tool;
86
+ type PhaseContribution = Phase;
87
+ type ResourceView = Readonly<{
88
+ agents: readonly ResourceSourceId[];
89
+ tools: readonly ResourceSourceId[];
90
+ skills: readonly ResourceSourceId[];
91
+ phases: readonly ResourceSourceId[];
92
+ }>;
93
+ type ResourceRef = Readonly<{
94
+ kind: ResourceKind;
95
+ sourceId: ResourceSourceId;
96
+ name: string;
97
+ }>;
98
+ type ResourceDiagnostic = Readonly<{
99
+ kind: "invalid" | "missing" | "collision";
100
+ sourceId: ResourceSourceId;
101
+ message: string;
102
+ path?: string;
103
+ }>;
104
+ type LoadResult = Readonly<{
105
+ revision: string;
106
+ registered: readonly ResourceRef[];
107
+ skipped: readonly ResourceDiagnostic[];
108
+ }>;
109
+ type LoadInput<T> = Readonly<{
110
+ sourceId: ResourceSourceId;
111
+ directory?: string;
112
+ values?: readonly T[];
113
+ }>;
114
+ type ResolvedResourceView = Readonly<{
115
+ agents: readonly AgentDefinition[];
116
+ tools: readonly Tool[];
117
+ skills: readonly Skill[];
118
+ phases: readonly Phase[];
119
+ revisions: Readonly<Record<ResourceKind, readonly string[]>>;
120
+ refs: Readonly<Record<ResourceKind, readonly ResourceRef[]>>;
121
+ }>;
122
+ type ResourceRegistryErrorCode = "invalid_source_id" | "invalid_resource_name" | "resource_collision" | "resource_input_missing" | "resource_directory_not_supported" | "unknown_resource_source" | "implicit_source_protected";
123
+ declare class ResourceRegistryError extends Error {
124
+ readonly code: ResourceRegistryErrorCode;
125
+ constructor(code: ResourceRegistryErrorCode, message: string);
126
+ }
127
+ type RegistryValue = AgentDefinition | Tool | Skill | Phase;
128
+ /**
129
+ * Runtime Resource Registry source transaction and view resolver.
130
+ *
131
+ * Directory normalization is intentionally added by the typed loader slice;
132
+ * this first module owns only the atomic source/revision/collision semantics.
133
+ */
134
+ declare class ResourceRegistry {
135
+ private readonly sources;
136
+ /** Sources registered by the bootstrap boundary (currently Extensions). */
137
+ private readonly implicitSources;
138
+ private revisionSequence;
139
+ loadAgents(input: LoadInput<AgentDefinition>): Promise<LoadResult>;
140
+ loadSkills(input: LoadInput<Skill>): Promise<LoadResult>;
141
+ loadPhases(input: LoadInput<Phase>): Promise<LoadResult>;
142
+ loadTools(input: Readonly<{
143
+ sourceId: ResourceSourceId;
144
+ values: readonly ToolContribution[];
145
+ }>): Promise<LoadResult>;
146
+ unload(input: Readonly<{
147
+ kind: ResourceKind;
148
+ sourceId: ResourceSourceId;
149
+ }>): Promise<LoadResult>;
150
+ resolveView(view: ResourceView): ResolvedResourceView;
151
+ /** Mark one already-loaded source as implicit for every Resource View. */
152
+ protected markImplicit(kind: ResourceKind, sourceId: ResourceSourceId): void;
153
+ /** Bootstrap-only helper for replacing an implicit contribution source. */
154
+ protected replaceImplicit<T extends RegistryValue>(kind: ResourceKind, sourceId: ResourceSourceId, values: readonly T[]): Promise<LoadResult>;
155
+ protected hasImplicit(kind: ResourceKind, sourceId: ResourceSourceId): boolean;
156
+ private withImplicit;
157
+ private collect;
158
+ private commit;
159
+ private resolveKind;
160
+ private resolveRevisions;
161
+ private resolveRefs;
162
+ private sourcesFor;
163
+ private nextRevision;
164
+ }
165
+
166
+ /**
167
+ * EventBus — simple pub/sub for inter-extension communication.
168
+ *
169
+ * Extensions can emit and subscribe to arbitrary events via `api.events`.
170
+ * This allows extensions to coordinate without direct coupling.
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Extension A
175
+ * api.events.on("my-plugin:ready", (data) => {
176
+ * console.log("Plugin ready:", data);
177
+ * });
178
+ *
179
+ * // Extension B
180
+ * api.events.emit("my-plugin:ready", { version: "1.0" });
181
+ * ```
182
+ */
183
+ type Listener = (...args: unknown[]) => void;
184
+ interface EventBus {
185
+ /** Subscribe to an event. Returns unsubscribe function. */
186
+ on(event: string, listener: Listener): () => void;
187
+ /** Emit an event to all subscribers. */
188
+ emit(event: string, ...args: unknown[]): void;
189
+ /** Remove all listeners for an event, or all listeners if no event specified. */
190
+ off(event?: string): void;
191
+ /** Check if there are listeners for an event. */
192
+ has(event: string): boolean;
193
+ /** Get listener count for an event. */
194
+ count(event: string): number;
195
+ }
196
+
197
+ /**
198
+ * @module extensions/context
199
+ *
200
+ * Extension context types — runtime state and phase execution context.
201
+ *
202
+ * For ExtensionAPI and createExtensionAPI, see ./api.ts
203
+ */
204
+
205
+ /**
206
+ * Runtime context available to extensions during event handler execution.
207
+ */
208
+ interface ExtensionContext {
209
+ /** Current working directory */
210
+ readonly cwd: string;
211
+ /** Abort signal — fires when the agent operation is cancelled */
212
+ readonly signal: AbortSignal | undefined;
213
+ /**
214
+ * Execute a shell command.
215
+ *
216
+ * @param command - The command to run
217
+ * @param args - Command arguments
218
+ * @param options - Execution options (cwd, env, timeout, signal)
219
+ * @returns Execution result with exitCode, stdout, stderr
220
+ */
221
+ exec(command: string, args: string[], options?: ExecOptions): Promise<ExecResult>;
222
+ }
223
+
224
+ type LoopMetrics = {
225
+ /** Number of phase iterations executed. */
226
+ iterations: number;
227
+ /** Phase transition history. */
228
+ phaseTransitions: Array<{
229
+ from: string;
230
+ to: string;
231
+ ts: string;
232
+ }>;
233
+ /** Number of times compaction was triggered. */
234
+ compactionCount: number;
235
+ /** Number of retry attempts due to transient errors. */
236
+ retryCount: number;
237
+ /** Loop start timestamp. */
238
+ startedAt: string;
239
+ /** Loop start time as epoch ms (for duration calculation). */
240
+ startedAtMs: number;
241
+ /** Loop end timestamp (set on completion). */
242
+ endedAt?: string;
243
+ /** Total wall-clock duration in ms. */
244
+ durationMs?: number;
245
+ };
246
+ type ExecutionState = {
247
+ currentPhase: string;
248
+ attempt: number;
249
+ metrics: LoopMetrics;
250
+ status: "idle" | "running" | "suspended" | "completed" | "aborted" | "failed";
251
+ initialPhasePayload?: JsonValue;
252
+ entryPhases?: readonly EntryPhaseSpec[];
253
+ continuation?: ExecutionContinuationState;
254
+ runInteractions?: RunInteractionState;
255
+ phaseInteractions?: RunInteractionState;
256
+ };
257
+ type ExecutionContinuationState = {
258
+ isContinuing: boolean;
259
+ previousPayload?: unknown;
260
+ previousResults: Array<{
261
+ name: string;
262
+ output?: unknown;
263
+ }>;
264
+ pendingInstruction?: string;
265
+ previousPhaseMessageId?: string;
266
+ };
267
+
268
+ type ToolContext = Pick<AgentContext, "skills"> & {
269
+ toolCallId: string;
270
+ interaction?: RunInteractionDriver;
271
+ };
272
+ type ToolExecutionMode = "sequential" | "parallel";
273
+ type Tool$1<TArgs = unknown> = {
274
+ name: string;
275
+ /** Rowan-owned Core Tool; Core Tools bypass Phase filtering. */
276
+ core?: boolean;
277
+ description: string;
278
+ parameters: Type.TSchema;
279
+ /** One-line snippet shown in the system prompt tool list. */
280
+ promptSnippet?: string;
281
+ /** Additional guidelines appended to the system prompt when this tool is active. */
282
+ promptGuidelines?: string[];
283
+ /** Whether this tool can run concurrently with others. Default: "parallel". */
284
+ executionMode?: ToolExecutionMode;
285
+ _meta?: JsonObject$1;
286
+ execute(args: TArgs, context: ToolContext, signal?: AbortSignal): Promise<ToolResult>;
287
+ };
288
+ /** Context snapshot passed into the low-level agent loop. */
289
+ type AgentContext = {
290
+ /** System prompt included with the request. */
291
+ systemPrompt: string;
292
+ /** Transcript visible to the model. */
293
+ messages: AgentMessage[];
294
+ /** Tools available for this run. */
295
+ tools: Tool$1[];
296
+ /** Skills available for this run. */
297
+ skills: Skill[];
298
+ /** Custom phases for this run. Agent normalizes this with the built-in default phase. */
299
+ phases?: PhaseRegistry;
300
+ cwd?: string;
301
+ };
302
+
303
+ interface BeforePhaseEvent {
304
+ type: "before_phase";
305
+ phaseId: string;
306
+ input: PhaseContext;
307
+ }
308
+ interface AfterPhaseEvent {
309
+ type: "after_phase";
310
+ phaseId: string;
311
+ output: PhaseOutput;
312
+ }
313
+ interface BeforePromptEvent {
314
+ type: "before_prompt";
315
+ phaseId: string;
316
+ input: PhaseContext;
317
+ }
318
+ interface BeforeToolCallEvent {
319
+ type: "before_tool_call";
320
+ tool: Tool$1;
321
+ args: unknown;
322
+ readonly runId?: string;
323
+ readonly agentId?: string;
324
+ readonly toolCallId?: string;
325
+ readonly metadata?: Readonly<Record<string, unknown>>;
326
+ /** The invoking Agent's metadata, as the Tool's own call context carries it. */
327
+ readonly agentMetadata?: Readonly<Record<string, unknown>>;
328
+ readonly answer?: unknown;
329
+ readonly scope?: ScopeRef;
330
+ readonly turn?: JsonObject;
331
+ readonly phase?: ToolCallPhase;
332
+ }
333
+ interface AfterToolCallEvent {
334
+ type: "after_tool_call";
335
+ tool: Tool$1;
336
+ result: ToolResult;
337
+ readonly runId?: string;
338
+ readonly agentId?: string;
339
+ readonly toolCallId?: string;
340
+ readonly metadata?: Readonly<Record<string, unknown>>;
341
+ readonly scope?: ScopeRef;
342
+ readonly turn?: JsonObject;
343
+ readonly phase?: ToolCallPhase;
344
+ }
345
+ interface RunStartEvent {
346
+ type: "run_start";
347
+ runId: string;
348
+ agentId: string;
349
+ metadata: Readonly<Record<string, unknown>>;
350
+ turn: JsonObject;
351
+ }
352
+ interface RunEndEvent {
353
+ type: "run_end";
354
+ runId: string;
355
+ agentId: string;
356
+ outcome: unknown;
357
+ }
358
+ type HookEvent = BeforePhaseEvent | AfterPhaseEvent | BeforePromptEvent | BeforeToolCallEvent | AfterToolCallEvent | RunStartEvent | RunEndEvent;
359
+ interface BeforePhaseResult {
360
+ abort?: Outcome$1;
361
+ skip?: {
362
+ route: string;
363
+ message: string;
364
+ };
365
+ input?: PhaseContext;
366
+ }
367
+ interface AfterPhaseResult {
368
+ abort?: Outcome$1;
369
+ retry?: PhaseContext;
370
+ output?: PhaseOutput;
371
+ }
372
+ interface BeforePromptResult {
373
+ input?: PhaseContext;
374
+ }
375
+ interface BeforeToolCallResult {
376
+ allow?: boolean;
377
+ reason?: string;
378
+ interaction?: RunInteractionRequest;
379
+ }
380
+ interface AfterToolCallResult {
381
+ result?: ToolResult;
382
+ }
383
+ interface HookResultMap {
384
+ before_phase: BeforePhaseResult | undefined;
385
+ after_phase: AfterPhaseResult | undefined;
386
+ before_prompt: BeforePromptResult | undefined;
387
+ before_tool_call: BeforeToolCallResult | undefined;
388
+ after_tool_call: AfterToolCallResult | undefined;
389
+ run_start: void;
390
+ run_end: void;
391
+ }
392
+ type HookEventType = HookEvent["type"];
393
+ type HookHandler<K extends HookEventType> = (event: Extract<HookEvent, {
394
+ type: K;
395
+ }>) => HookResultMap[K] | Promise<HookResultMap[K]> | void | Promise<void>;
396
+ declare class HooksManager {
397
+ private handlers;
398
+ on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
399
+ off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
400
+ emit<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
401
+ type: K;
402
+ }>): Promise<void>;
403
+ emitFirst<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
404
+ type: K;
405
+ }>): Promise<HookResultMap[K] | undefined>;
406
+ }
407
+
408
+ /** The Resource Source an Extension registration lands in: Global (`[]`) is `rowan.extensions`, any other Scope `rowan.extensions:<scopeToKey(scope)>`. */
409
+ declare function extensionSourceId(scope?: ScopeRef): string;
410
+ type ExtensionRunnerOptions = {
411
+ entryPhaseId?: string | null;
412
+ cwd?: string;
413
+ host?: ExtensionHost;
414
+ };
415
+ /**
416
+ * Manages extensions and provides hooks for the agent loop.
417
+ *
418
+ * Features:
419
+ * - Per-extension tracking (handlers, tools, phases)
420
+ * - Shared runtime with lifecycle protection (invalidate/assertActive)
421
+ * - Error listener pattern for structured error handling
422
+ * - Direct hook API and extension-loaded hook API
423
+ * - Tool registration for LLM-callable tools
424
+ * - EventBus for inter-extension communication
425
+ *
426
+ * @example
427
+ * ```ts
428
+ * const runner = createExtensionRunner();
429
+ *
430
+ * // Direct hook registration
431
+ * const unsub = runner.on("before_tool_call", (event) => {
432
+ * return { allow: false, reason: "Blocked" };
433
+ * });
434
+ *
435
+ * // Error handling
436
+ * runner.onError((error) => {
437
+ * console.error(`Extension error in ${error.extensionPath}:`, error.error);
438
+ * });
439
+ *
440
+ * // Load extensions
441
+ * await runner.loadExtensions(extensions);
442
+ * runner.bind();
443
+ * ```
444
+ */
445
+ declare class ExtensionRunner {
446
+ readonly hooks: HooksManager;
447
+ readonly runtime: ExtensionRuntime;
448
+ readonly events: EventBus;
449
+ readonly host: ExtensionHost;
450
+ private readonly cwd;
451
+ private readonly abortController;
452
+ private _idle;
453
+ private readonly extensions;
454
+ private readonly runState;
455
+ private readonly configChangeListeners;
456
+ private readonly hostUnsubscribers;
457
+ private readonly phases;
458
+ private _phaseCache;
459
+ private readonly skills;
460
+ private readonly pendingProviders;
461
+ private bound;
462
+ private readonly errorListeners;
463
+ private readonly capabilityListeners;
464
+ private readonly resourceChangeListeners;
465
+ private runtimeAgents?;
466
+ private readonly activeExtensionPhases;
467
+ /** Current agent context — set by the agent before each phase */
468
+ currentContext?: AgentContext;
469
+ constructor(options?: ExtensionRunnerOptions);
470
+ setRuntime(runtime: ExtensionAgentsRuntimeDelegate): void;
471
+ /** Whether the agent is currently idle (not streaming). */
472
+ get isIdle(): boolean;
473
+ /** Set idle state — called by the agent loop. */
474
+ setIdle(idle: boolean): void;
475
+ /** Abort signal for the current runner instance. */
476
+ get signal(): AbortSignal;
477
+ /** Abort the current runner operation. */
478
+ abort(): void;
479
+ /**
480
+ * Register an error listener.
481
+ * Returns an unsubscribe function.
482
+ */
483
+ onError(listener: ExtensionErrorListener): () => void;
484
+ /**
485
+ * Emit a structured extension error to all listeners.
486
+ */
487
+ emitError(error: ExtensionError): void;
488
+ /**
489
+ * Mark all extension contexts as stale.
490
+ * After calling this, any captured ExtensionAPI or ExtensionContext will throw
491
+ * on use. Used during runtime replacement or reload.
492
+ */
493
+ invalidate(message?: string): void;
494
+ /**
495
+ * Subscribe to a specific hook event type.
496
+ * Returns an unsubscribe function.
497
+ *
498
+ * @example
499
+ * ```ts
500
+ * const unsub = runner.on("before_tool_call", (event) => {
501
+ * return { allow: false, reason: "Blocked" };
502
+ * });
503
+ * unsub(); // Cancel subscription
504
+ * ```
505
+ */
506
+ on<K extends HookEventType>(type: K, handler: HookHandler<K>): () => void;
507
+ /**
508
+ * Load and initialize extensions.
509
+ * Creates Extension tracking objects and calls each factory with an ExtensionAPI.
510
+ */
511
+ loadExtensions(extensions: LoadedExtension[]): Promise<void>;
512
+ activatePhase(phase: Phase, scope?: ScopeRef, sourceId?: string): Promise<void>;
513
+ getPhaseHandler(phaseName: string, scope?: ScopeRef): PhaseRunHandler | undefined;
514
+ deactivatePhase(phaseName: string, scope?: ScopeRef): Promise<void>;
515
+ deactivatePhasesForSource(sourceId: string): Promise<void>;
516
+ /** Dispose all active Extensions in reverse activation order. */
517
+ close(): Promise<void>;
518
+ get extensionHost(): ExtensionHost;
519
+ notifyConfigChanged(extensionId: string, scope: ScopeRef): Promise<void>;
520
+ getRunState(runId: string, extensionId: string, key: string): JsonValue | undefined;
521
+ setRunState(runId: string, extensionId: string, key: string, value: JsonValue): void;
522
+ deleteRunState(runId: string, extensionId: string, key: string): void;
523
+ dropRunState(runId: string): void;
524
+ /** Get all registered tools from all extensions. */
525
+ getAllRegisteredTools(): RegisteredTool[];
526
+ /**
527
+ * Get a tool definition by name. Returns undefined if not found.
528
+ */
529
+ getToolDefinition(toolName: string): RegisteredTool["definition"] | undefined;
530
+ /** Get all contributed capabilities across all extensions. */
531
+ getCapabilities(): readonly ExtensionCapability[];
532
+ /**
533
+ * Subscribe to capability changes (contributions added, removed, or extensions disposed).
534
+ * Returns an unsubscribe function.
535
+ */
536
+ onCapabilitiesChanged(listener: (capabilities: readonly ExtensionCapability[]) => void): () => void;
537
+ /**
538
+ * Subscribe to resource changes (tools, phases, skills registered, unregistered, or disposed).
539
+ * Used by RuntimeBootstrapRegistry to re-commit implicit sources after activation.
540
+ */
541
+ onResourceChange(listener: (kind: "tool" | "phase" | "skill") => Promise<void> | void): () => void;
542
+ private notifyResourceChange;
543
+ triggerUiAction(event: {
544
+ contributionId: string;
545
+ actionId: string;
546
+ scope?: ScopeRef;
547
+ }): void;
548
+ getPhase(name: string): Phase | undefined;
549
+ getPhases(): Phase[];
550
+ getRegisteredPhases(): readonly RegisteredPhase[];
551
+ createPhaseRegistry(input?: {
552
+ entryPhaseId?: string | null;
553
+ }): PhaseRegistry;
554
+ /** Adapt an extension RegisteredPhase to the core Phase type. */
555
+ adaptToPhase(reg: RegisteredPhase): Phase;
556
+ getSkills(): Skill[];
557
+ getRegisteredSkills(): readonly RegisteredSkill[];
558
+ /**
559
+ * Bind the runner — flushes pending provider registrations and
560
+ * replaces runtime stubs with real implementations.
561
+ */
562
+ bind(): void;
563
+ /**
564
+ * Generic emit — fire-and-forget for any event type.
565
+ */
566
+ emit<K extends HookEventType>(eventType: K, event: Parameters<HookHandler<K>>[0]): Promise<void>;
567
+ /**
568
+ * Unified hook emission — returns the first non-undefined result.
569
+ */
570
+ private emitHook;
571
+ emitBeforePhase(phaseId: string, input: PhaseContext): Promise<{
572
+ abort?: any;
573
+ skip?: any;
574
+ input?: PhaseContext;
575
+ }>;
576
+ emitAfterPhase(phaseId: string, output: PhaseOutput): Promise<{
577
+ abort?: any;
578
+ retry?: PhaseContext;
579
+ output?: PhaseOutput;
580
+ }>;
581
+ emitBeforePrompt(phaseId: string, input: PhaseContext): Promise<PhaseContext>;
582
+ emitRunStart(event: {
583
+ runId: string;
584
+ agentId: string;
585
+ metadata: Readonly<Record<string, unknown>>;
586
+ turn: JsonObject;
587
+ }): Promise<void>;
588
+ emitRunEnd(event: {
589
+ runId: string;
590
+ agentId: string;
591
+ outcome: unknown;
592
+ }): Promise<void>;
593
+ emitBeforeToolCall(tool: Tool$1, args: unknown, context?: {
594
+ runId?: string;
595
+ agentId?: string;
596
+ toolCallId?: string;
597
+ metadata?: Readonly<Record<string, unknown>>;
598
+ agentMetadata?: Readonly<Record<string, unknown>>;
599
+ answer?: unknown;
600
+ scope?: ScopeRef;
601
+ turn?: JsonObject;
602
+ phase?: ToolCallPhase;
603
+ }): Promise<BeforeToolCallResult>;
604
+ emitAfterToolCall(tool: Tool$1, result: ToolResult, context?: {
605
+ runId?: string;
606
+ agentId?: string;
607
+ toolCallId?: string;
608
+ metadata?: Readonly<Record<string, unknown>>;
609
+ scope?: ScopeRef;
610
+ turn?: JsonObject;
611
+ phase?: ToolCallPhase;
612
+ }): Promise<ToolResult>;
613
+ /**
614
+ * Create an ExtensionAPI for a specific extension.
615
+ * Registration methods write to the extension tracking object.
616
+ * Action methods delegate to the shared runtime.
617
+ */
618
+ private createExtensionAPI;
619
+ private registerTool;
620
+ private unregisterTool;
621
+ private contributeCapability;
622
+ private notifyCapabilitiesChanged;
623
+ private registerPhase;
624
+ private registerPhaseDefinition;
625
+ private unregisterPhase;
626
+ private loadRegisteredPhase;
627
+ private registerSkill;
628
+ private registerSkillDefinition;
629
+ private unregisterSkill;
630
+ private loadRegisteredSkill;
631
+ private registerProvider;
632
+ private unregisterProvider;
633
+ private flushPendingProviders;
634
+ private getRegisteredPhase;
635
+ private collectRegisteredPhases;
636
+ private rollbackExtension;
637
+ private disposeExtension;
638
+ }
639
+
640
+ type ToolCallPresentationInput = Readonly<{
641
+ status: ToolCallStatus;
642
+ args: JsonValue$1;
643
+ progress?: ToolProgress;
644
+ result?: ToolExecutionResult;
645
+ }>;
646
+ type ToolCallPresentationOutput = {
647
+ title?: string;
648
+ content?: ToolCallContent[];
649
+ locations?: ToolCallLocation[];
650
+ _meta?: JsonObject$1;
651
+ };
652
+ type ToolCallMergeTarget = {
653
+ title?: string;
654
+ kind?: ToolKind;
655
+ status?: ToolCallStatus;
656
+ locations?: ToolCallLocation[];
657
+ content?: ToolCallContent[];
658
+ rawInput?: JsonValue$1;
659
+ rawOutput?: JsonValue$1;
660
+ _meta?: JsonObject$1;
661
+ };
662
+ type ToolCallMergePatch = {
663
+ title?: string;
664
+ kind?: ToolKind;
665
+ status?: ToolCallStatus;
666
+ locations?: ToolCallLocation[];
667
+ content?: ToolCallContent[];
668
+ rawInput?: JsonValue$1;
669
+ rawOutput?: JsonValue$1;
670
+ _meta?: JsonObject$1;
671
+ };
672
+ declare function mergeToolCall<T extends ToolCallMergeTarget>(target: T, patch: ToolCallMergePatch): T;
673
+
674
+ type ExtensionContribution = LoadedExtension;
675
+ type ExtensionLoadInput = LoadInput<ExtensionContribution>;
676
+ type ExtensionActivationError = Readonly<{
677
+ path: string;
678
+ error: string;
679
+ }>;
680
+ type ExtensionActivationResult = Readonly<{
681
+ active: readonly string[];
682
+ errors: readonly ExtensionActivationError[];
683
+ revision?: string;
684
+ registered?: readonly string[];
685
+ skipped?: readonly ResourceDiagnostic[];
686
+ }>;
687
+ type ExtensionLifetimeErrorCode = "extensions_frozen" | "extensions_closed";
688
+ declare class ExtensionLifetimeError extends Error {
689
+ readonly code: ExtensionLifetimeErrorCode;
690
+ constructor(code: ExtensionLifetimeErrorCode, message: string);
691
+ }
692
+ /** Runtime-global Extension activation and lifetime boundary. */
693
+ declare class RuntimeExtensionLifetime {
694
+ private readonly runner;
695
+ private frozen;
696
+ private closed;
697
+ constructor(options?: {
698
+ cwd?: string;
699
+ host?: ExtensionHost;
700
+ });
701
+ activate(extensions: readonly LoadedExtension[]): Promise<ExtensionActivationResult>;
702
+ tools(): readonly RegisteredTool[];
703
+ phases(): readonly Phase[];
704
+ registeredPhases(): readonly RegisteredPhase[];
705
+ skills(): readonly Skill[];
706
+ registeredSkills(): readonly RegisteredSkill[];
707
+ get extensionRunner(): ExtensionRunner;
708
+ get extensionHost(): ExtensionHost;
709
+ onResourceChange(listener: (kind: "tool" | "phase" | "skill") => Promise<void> | void): () => void;
710
+ dropRunState(runId: string): void;
711
+ close(): Promise<void>;
712
+ }
713
+ /** Bootstrap-only Registry facade; its Extension method disappears after init. */
714
+ declare class RuntimeBootstrapRegistry extends ResourceRegistry {
715
+ private readonly extensions;
716
+ private readonly knownSources;
717
+ private commitQueue;
718
+ constructor(extensions?: RuntimeExtensionLifetime);
719
+ private recommit;
720
+ get extensionHost(): ExtensionHost;
721
+ /** Install Rowan-owned implicit resources before any host source is read. */
722
+ ensureCoreResources(): Promise<void>;
723
+ loadExtensions(input: readonly LoadedExtension[] | ExtensionLoadInput): Promise<ExtensionActivationResult>;
724
+ get extensionRunner(): ExtensionRunner;
725
+ get extensionTools(): readonly RegisteredTool[];
726
+ get extensionPhases(): readonly Phase[];
727
+ closeExtensions(): Promise<void>;
728
+ }
729
+
730
+ type DefinitionLayer = Readonly<{
731
+ description?: string;
732
+ prompt?: string;
733
+ model?: ModelRef;
734
+ tools?: readonly string[];
735
+ skills?: readonly string[];
736
+ phases?: PhaseRegistrySelection;
737
+ }>;
738
+ type AgentConfiguration = Readonly<{
739
+ identity: string;
740
+ definition: Readonly<{
741
+ name: string;
742
+ layer?: DefinitionLayer;
743
+ }>;
744
+ resourceView: ResourceView;
745
+ contexts?: readonly ContextCandidate[];
746
+ /** Trusted Host-owned Contexts rendered as durable user messages. */
747
+ additionalContexts?: readonly ContextCandidate[];
748
+ cwd?: string;
749
+ maxAttempts?: number;
750
+ model: ModelConfig | ModelRef;
751
+ stream?: StreamFn;
752
+ }>;
753
+ type ConfigurationSnapshot = Readonly<{
754
+ identity: string;
755
+ definition: AgentDefinition;
756
+ resources: Readonly<{
757
+ tools: readonly Tool[];
758
+ skills: readonly Skill[];
759
+ phases?: PhaseRegistry;
760
+ revisions: Readonly<Record<ResourceKind, readonly string[]>>;
761
+ refs: Readonly<Record<ResourceKind, readonly ResourceRef[]>>;
762
+ }>;
763
+ contexts: readonly ContextCandidate[];
764
+ additionalContexts: readonly ContextCandidate[];
765
+ resourceView: ResourceView;
766
+ cwd?: string;
767
+ maxAttempts?: number;
768
+ model: ModelConfig | ModelRef;
769
+ stream?: StreamFn;
770
+ }>;
771
+ /** Resolve one Definition request into one immutable, source-qualified snapshot. */
772
+ declare function resolveConfigurationSnapshot(registry: ResourceRegistry, input: AgentConfiguration): ConfigurationSnapshot;
773
+ /** Whether one stored configuration is already a resolved snapshot. A snapshot
774
+ * is used as it stands; a request is resolved against the current sources. */
775
+ declare function isConfigurationSnapshot(config: AgentConfiguration | ConfigurationSnapshot): config is ConfigurationSnapshot;
776
+
777
+ type UserInput = string | Readonly<{
778
+ content: UserContent;
779
+ metadata?: Metadata;
780
+ thinkingLevel?: ThinkingLevel;
781
+ providerOptions?: JsonObject;
782
+ }>;
783
+ type HistorySeed = readonly Message[];
784
+ type ContextStatus = Readonly<{
785
+ tokens: number;
786
+ contextWindow: number;
787
+ percent: number;
788
+ thresholdTokens: number;
789
+ estimated: boolean;
790
+ coveredThrough?: Readonly<{
791
+ messageId: MessageId;
792
+ sequence: number;
793
+ }>;
794
+ }>;
795
+ type ContextCompactionRecord = Readonly<{
796
+ id: string;
797
+ agentId: AgentId;
798
+ summary: string;
799
+ coveredThrough?: Readonly<{
800
+ messageId: MessageId;
801
+ sequence: number;
802
+ }>;
803
+ instructions?: string;
804
+ createdAt: string;
805
+ }>;
806
+ /** Who is calling which tool, without the ability to ask or suspend. Hosts that
807
+ * describe a call before it runs (for example to build a confirmation) only
808
+ * have this much. */
809
+ /** The Phase whose execution issued a Tool call, with its PHASE.md metadata. */
810
+ type ToolCallPhase = Readonly<{
811
+ name: string;
812
+ metadata?: Readonly<Record<string, JsonValue>>;
813
+ }>;
814
+ type ToolCallContext = Readonly<{
815
+ agentId: AgentId;
816
+ runId: RunId;
817
+ /** Opaque JSON metadata captured from the Agent and Run records. Rowan does
818
+ * not interpret host/domain fields. */
819
+ agentMetadata?: Metadata;
820
+ runMetadata?: Metadata;
821
+ toolCallId: ToolCallId;
822
+ /** The model's id for this call, matching `tool_call_delta` events; absent when a host runs the tool itself. */
823
+ providerToolCallId?: string;
824
+ scope?: ScopeRef;
825
+ turn?: JsonObject;
826
+ phase?: ToolCallPhase;
827
+ reportProgress(progress: ToolProgress): void;
828
+ }>;
829
+ type ToolInvocationContext = ToolCallContext & Readonly<{
830
+ interaction: RunInteractionDriver;
831
+ }>;
832
+
833
+ type Tool = Readonly<{
834
+ name: string;
835
+ /** Rowan-owned Core Tool; Core Tools bypass Definition/Phase filtering. */
836
+ core?: boolean;
837
+ description: string;
838
+ parameters: Type.TSchema;
839
+ promptSnippet?: string;
840
+ promptGuidelines?: readonly string[];
841
+ kind?: ToolKind;
842
+ annotations?: ToolAnnotations;
843
+ _meta?: JsonObject;
844
+ present?(call: ToolCallPresentationInput): {
845
+ title?: string;
846
+ content?: ToolCallContent[];
847
+ locations?: ToolCallLocation[];
848
+ _meta?: JsonObject;
849
+ } | undefined | void | Promise<{
850
+ title?: string;
851
+ content?: ToolCallContent[];
852
+ locations?: ToolCallLocation[];
853
+ _meta?: JsonObject;
854
+ } | undefined | void>;
855
+ execute(args: JsonValue, context: ToolInvocationContext, signal: AbortSignal): Promise<ToolExecutionResult>;
856
+ }>;
857
+ type BeforeToolCallDecision = Readonly<{
858
+ allow: true;
859
+ }> | Readonly<{
860
+ allow: false;
861
+ reason: string;
862
+ }> | Readonly<{
863
+ interaction: RunInteractionRequest;
864
+ }>;
865
+ type BeforeToolCall = (input: Readonly<{
866
+ tool: Tool;
867
+ args: JsonValue;
868
+ context: ToolInvocationContext;
869
+ signal: AbortSignal;
870
+ answer?: JsonValue;
871
+ }>) => BeforeToolCallDecision | Promise<BeforeToolCallDecision>;
872
+ type AfterToolCall = (input: Readonly<{
873
+ tool: Tool;
874
+ result: ToolExecutionResult;
875
+ context: ToolInvocationContext;
876
+ signal: AbortSignal;
877
+ }>) => ToolExecutionResult | Promise<ToolExecutionResult>;
878
+ type InvocationSource = "auto" | "implicit" | "external";
879
+ type InvocationCatalogEntry = Readonly<{
880
+ kind: "phase" | "skill";
881
+ name: string;
882
+ description: string;
883
+ input?: Phase["input"];
884
+ core?: boolean;
885
+ disableAutoInvocation: boolean;
886
+ disableImplicitInvocation: boolean;
887
+ filePath: string;
888
+ }>;
889
+ type AgentRecord = Readonly<{
890
+ id: AgentId;
891
+ metadata?: Metadata;
892
+ currentConfigToken?: ConfigToken;
893
+ currentConfigIdentity?: string;
894
+ createdAt: string;
895
+ activatedAt?: string;
896
+ updatedAt: string;
897
+ }>;
898
+ type AgentDeletionRequest = Readonly<{
899
+ agentId: AgentId;
900
+ expectedRunIds: readonly RunId[];
901
+ confirmation: "agent-delete-v1";
902
+ }>;
903
+ type ExecutionToken = Readonly<{
904
+ runId: RunId;
905
+ ownerEpoch: number;
906
+ executionId: ExecutionId;
907
+ }>;
908
+ type ExecutionCheckpoint = Readonly<{
909
+ codec: string;
910
+ version: number;
911
+ data: JsonValue;
912
+ }>;
913
+ type OwnerLease = Readonly<{
914
+ ownerId: string;
915
+ token: OwnerToken;
916
+ epoch: number;
917
+ expiresAt: string;
918
+ }>;
919
+ type RunClaim = Readonly<{
920
+ run: RunRecord;
921
+ execution: ExecutionToken;
922
+ history: readonly Message[];
923
+ }>;
924
+ type ToolCallReservation = Readonly<{
925
+ providerToolCallId: string;
926
+ name: string;
927
+ args: JsonValue;
928
+ toolCallId?: ToolCallId;
929
+ title?: string;
930
+ kind?: ToolKind;
931
+ locations?: ToolCallLocation[];
932
+ content?: ToolCallContent[];
933
+ _meta?: JsonObject;
934
+ }>;
935
+ type ToolCommit = Readonly<{
936
+ run: RunRecord;
937
+ toolCall: ToolCallSnapshot;
938
+ }>;
939
+ type ToolBatchCommit = Readonly<{
940
+ run: RunRecord;
941
+ toolCalls: readonly ToolCallSnapshot[];
942
+ }>;
943
+ type EntryPhaseSpec = Readonly<{
944
+ phase: string;
945
+ payload?: JsonValue;
946
+ }>;
947
+ type RunRecord = Readonly<{
948
+ id: RunId;
949
+ agentId: AgentId;
950
+ agentSequence: number;
951
+ readySequence: number;
952
+ revision: number;
953
+ state: RunState;
954
+ input: UserInput;
955
+ scope?: ScopeRef;
956
+ cwd?: string;
957
+ initialMessageId?: MessageId;
958
+ invalidatedBy?: Readonly<{
959
+ messageId: MessageId;
960
+ messageRevision: number;
961
+ }>;
962
+ metadata?: Metadata;
963
+ phasePayload?: JsonValue;
964
+ entryPhases?: readonly EntryPhaseSpec[];
965
+ pinnedConfigToken?: ConfigToken;
966
+ checkpoint?: ExecutionCheckpoint;
967
+ currentPhaseId?: string;
968
+ openInteractions?: readonly RunInteraction[];
969
+ interactionAnswers?: Readonly<Record<string, JsonValue>>;
970
+ execution?: ExecutionToken;
971
+ outcome?: Outcome;
972
+ failure?: RunFailure;
973
+ cancellationReason?: string;
974
+ createdAt: string;
975
+ updatedAt: string;
976
+ }>;
977
+ type MessageRevisionResult = Readonly<{
978
+ message: UserMessage & Readonly<{
979
+ messageRevision: number;
980
+ }>;
981
+ replacementRun: RunRecord;
982
+ invalidatedRunIds: readonly RunId[];
983
+ affectedToolCallIds: readonly ToolCallId[];
984
+ effectDigest?: string;
985
+ }>;
986
+ type RetentionResult = Readonly<{
987
+ deletedRunIds: readonly RunId[];
988
+ deletedToolCallIds: readonly ToolCallId[];
989
+ deletedEventCount: number;
990
+ retentionFloor: EventCursor;
991
+ skipped?: "active_consumers" | "no_eligible_events";
992
+ }>;
993
+ type AgentSummary = Readonly<{
994
+ id: AgentId;
995
+ metadata?: Metadata;
996
+ currentConfigIdentity?: string;
997
+ createdAt: string;
998
+ activatedAt: string;
999
+ updatedAt: string;
1000
+ }>;
1001
+ type RunSummary = Readonly<{
1002
+ id: RunId;
1003
+ agentId: AgentId;
1004
+ agentSequence: number;
1005
+ state: RunState;
1006
+ metadata?: Metadata;
1007
+ createdAt: string;
1008
+ updatedAt: string;
1009
+ }>;
1010
+ type Page<T, Cursor> = Readonly<{
1011
+ items: readonly T[];
1012
+ next?: Cursor;
1013
+ }>;
1014
+ type RunSnapshotBase = Readonly<{
1015
+ runId: RunId;
1016
+ agentId: AgentId;
1017
+ agentSequence: number;
1018
+ revision: number;
1019
+ input: UserInput;
1020
+ scope?: ScopeRef;
1021
+ cwd?: string;
1022
+ metadata?: Metadata;
1023
+ /** Effective entry Phase payload the Run started with (defaults filled). */
1024
+ phasePayload?: JsonValue;
1025
+ entryPhases?: readonly EntryPhaseSpec[];
1026
+ messageCount: number;
1027
+ toolCallCount: number;
1028
+ currentPhaseId?: string;
1029
+ createdAt: string;
1030
+ updatedAt: string;
1031
+ cursor: EventCursor;
1032
+ }>;
1033
+ type RunSnapshot = RunSnapshotBase & (Readonly<{
1034
+ state: "queued" | "running";
1035
+ currentPhaseId?: string;
1036
+ interactions?: readonly RunInteraction[];
1037
+ }> | Readonly<{
1038
+ state: "input_required";
1039
+ interactions: readonly RunInteraction[];
1040
+ answers: Readonly<Record<string, JsonValue>>;
1041
+ }> | Readonly<{
1042
+ state: "completed";
1043
+ outcome: Outcome;
1044
+ output?: AssistantMessage;
1045
+ }> | Readonly<{
1046
+ state: "failed";
1047
+ failure: RunFailure;
1048
+ }> | Readonly<{
1049
+ state: "cancelled";
1050
+ reason?: string;
1051
+ }>);
1052
+ type RunBoundary = Readonly<{
1053
+ type: "input_required";
1054
+ interactions: readonly RunInteraction[];
1055
+ answers: Readonly<Record<string, JsonValue>>;
1056
+ }> | Readonly<{
1057
+ type: "completed";
1058
+ outcome: Outcome;
1059
+ output?: AssistantMessage;
1060
+ }> | Readonly<{
1061
+ type: "failed";
1062
+ failure: RunFailure;
1063
+ }> | Readonly<{
1064
+ type: "cancelled";
1065
+ reason?: string;
1066
+ }>;
1067
+ type ConfigResolution = Readonly<{
1068
+ kind: "available";
1069
+ config: AgentConfiguration | ConfigurationSnapshot;
1070
+ } | {
1071
+ kind: "deferred";
1072
+ retryAfterMs?: number;
1073
+ } | {
1074
+ kind: "unavailable";
1075
+ reason: string;
1076
+ }>;
1077
+ type ConfigPutResult = Readonly<{
1078
+ kind: "stored";
1079
+ token: string;
1080
+ } | {
1081
+ kind: "identity_conflict";
1082
+ }>;
1083
+ interface ConfigProvider {
1084
+ put(input: {
1085
+ agentId: AgentId;
1086
+ agentMetadata?: Metadata;
1087
+ config: AgentConfiguration | ConfigurationSnapshot;
1088
+ operationId: string;
1089
+ signal: AbortSignal;
1090
+ }): Promise<ConfigPutResult>;
1091
+ resolve(input: {
1092
+ agentId: AgentId;
1093
+ agentMetadata?: Metadata;
1094
+ token: ConfigToken;
1095
+ signal: AbortSignal;
1096
+ }): Promise<ConfigResolution>;
1097
+ }
1098
+ interface OwnedStore {
1099
+ readonly lease: OwnerLease;
1100
+ reserveAgent(input: {
1101
+ idempotencyKey: string;
1102
+ metadata?: Metadata;
1103
+ configIdentity?: string;
1104
+ historySeed?: HistorySeed;
1105
+ }): Promise<AgentRecord>;
1106
+ activateAgent(agentId: AgentId, configToken?: ConfigToken, configIdentity?: string): Promise<AgentRecord>;
1107
+ updateAgentConfigToken(input: {
1108
+ agentId: AgentId;
1109
+ token: ConfigToken;
1110
+ configIdentity?: string;
1111
+ idempotencyKey: string;
1112
+ }): Promise<AgentRecord>;
1113
+ deleteAgent(input: AgentDeletionRequest): Promise<void>;
1114
+ reviseMessage(input: {
1115
+ agentId: AgentId;
1116
+ messageId: MessageId;
1117
+ expectedMessageRevision: number;
1118
+ content: UserContent;
1119
+ operationId: string;
1120
+ effectDigestConfirmation?: string;
1121
+ }): Promise<MessageRevisionResult>;
1122
+ compact(input?: {
1123
+ now?: string;
1124
+ retentionMs?: number;
1125
+ }): Promise<RetentionResult>;
1126
+ contextStatus(agentId: AgentId, contextWindow: number): Promise<ContextStatus>;
1127
+ contextMessages(agentId: AgentId, recentTokenBudget?: number): Promise<readonly Message[]>;
1128
+ commitContextCompaction(record: ContextCompactionRecord): Promise<ContextCompactionRecord>;
1129
+ createRun(input: {
1130
+ agentId: AgentId;
1131
+ input: UserInput;
1132
+ metadata?: Metadata;
1133
+ scope?: ScopeRef;
1134
+ cwd?: string;
1135
+ phasePayload?: JsonValue;
1136
+ entryPhases?: readonly EntryPhaseSpec[];
1137
+ pinnedConfigToken?: ConfigToken;
1138
+ idempotencyKey: string;
1139
+ }): Promise<RunRecord>;
1140
+ claimRun(input: {
1141
+ runId: RunId;
1142
+ expectedRevision: number;
1143
+ executionId?: ExecutionId;
1144
+ messageId?: MessageId;
1145
+ configToken?: ConfigToken;
1146
+ additionalContexts?: readonly ContextCandidate[];
1147
+ }): Promise<RunClaim>;
1148
+ failQueuedRun(input: {
1149
+ runId: RunId;
1150
+ expectedRevision: number;
1151
+ failure: QueuedRunFailure;
1152
+ }): Promise<RunRecord>;
1153
+ commitPhaseEntered(input: {
1154
+ runId: RunId;
1155
+ execution: ExecutionToken;
1156
+ expectedRevision: number;
1157
+ phaseId: string;
1158
+ visit: number;
1159
+ }): Promise<RunRecord>;
1160
+ commitPhaseOutput(input: {
1161
+ runId: RunId;
1162
+ execution: ExecutionToken;
1163
+ expectedRevision: number;
1164
+ message: AssistantMessage;
1165
+ }): Promise<RunRecord>;
1166
+ commitInputRequired(input: {
1167
+ runId: RunId;
1168
+ execution: ExecutionToken;
1169
+ expectedRevision: number;
1170
+ phase: string;
1171
+ prompt?: AssistantMessage;
1172
+ checkpoint: ExecutionCheckpoint;
1173
+ interactions?: readonly RunInteraction[];
1174
+ interactionAnswers?: Readonly<Record<string, JsonValue>>;
1175
+ pendingToolCallIds?: readonly ToolCallId[];
1176
+ }): Promise<RunRecord>;
1177
+ answerInteraction(input: {
1178
+ runId: RunId;
1179
+ interactionId: string;
1180
+ expectedRevision: number;
1181
+ input?: JsonValue;
1182
+ cancel?: boolean;
1183
+ }): Promise<RunRecord>;
1184
+ commitOutcome(input: {
1185
+ runId: RunId;
1186
+ execution: ExecutionToken;
1187
+ expectedRevision: number;
1188
+ outcome?: Outcome;
1189
+ failure?: RunFailure;
1190
+ output?: AssistantMessage;
1191
+ }): Promise<RunRecord>;
1192
+ reserveToolCall(input: {
1193
+ runId: RunId;
1194
+ execution: ExecutionToken;
1195
+ expectedRevision: number;
1196
+ requestMessageId: MessageId;
1197
+ name: string;
1198
+ args: JsonValue;
1199
+ toolCallId?: ToolCallId;
1200
+ providerToolCallId?: string;
1201
+ title?: string;
1202
+ kind?: ToolKind;
1203
+ locations?: ToolCallLocation[];
1204
+ content?: ToolCallContent[];
1205
+ _meta?: JsonObject;
1206
+ model?: ModelRef;
1207
+ usage?: LlmTokenUsage;
1208
+ }): Promise<ToolCommit>;
1209
+ reserveToolCalls(input: {
1210
+ runId: RunId;
1211
+ execution: ExecutionToken;
1212
+ expectedRevision: number;
1213
+ requestMessageId: MessageId;
1214
+ calls: readonly ToolCallReservation[];
1215
+ /** The model response's blocks, so the request message keeps what preceded the Tool Calls. */
1216
+ contentBlocks?: readonly ContentBlock[];
1217
+ model?: ModelRef;
1218
+ usage?: LlmTokenUsage;
1219
+ }): Promise<ToolBatchCommit>;
1220
+ startToolCall(input: {
1221
+ runId: RunId;
1222
+ execution: ExecutionToken;
1223
+ expectedRevision: number;
1224
+ toolCallId: ToolCallId;
1225
+ title?: string;
1226
+ kind?: ToolKind;
1227
+ locations?: ToolCallLocation[];
1228
+ content?: ToolCallContent[];
1229
+ _meta?: JsonObject;
1230
+ }): Promise<ToolCommit>;
1231
+ suspendToolCall(input: {
1232
+ runId: RunId;
1233
+ execution: ExecutionToken;
1234
+ expectedRevision: number;
1235
+ toolCallId: ToolCallId;
1236
+ }): Promise<ToolCommit>;
1237
+ commitToolResult(input: {
1238
+ runId: RunId;
1239
+ execution: ExecutionToken;
1240
+ expectedRevision: number;
1241
+ toolCallId: ToolCallId;
1242
+ result: ToolExecutionResult;
1243
+ state: "completed" | "failed" | "indeterminate";
1244
+ reason?: string;
1245
+ title?: string;
1246
+ kind?: ToolKind;
1247
+ content?: ToolCallContent[];
1248
+ locations?: ToolCallLocation[];
1249
+ rawOutput?: JsonValue;
1250
+ _meta?: JsonObject;
1251
+ }): Promise<ToolCommit>;
1252
+ cancelRun(input: {
1253
+ runId: RunId;
1254
+ expectedRevision?: number;
1255
+ reason?: string;
1256
+ output?: AssistantMessage;
1257
+ }): Promise<RunRecord>;
1258
+ recordToolCall(input: {
1259
+ runId: RunId;
1260
+ execution?: ExecutionToken;
1261
+ update: ToolCall$1 | ToolCallUpdate;
1262
+ external?: boolean;
1263
+ contentIndex?: number;
1264
+ }): Promise<DurableRunEvent>;
1265
+ snapshotRun(runId: RunId): Promise<RunSnapshot>;
1266
+ history(agentId: AgentId): Promise<readonly Message[]>;
1267
+ listAgents(): Promise<readonly AgentRecord[]>;
1268
+ listRuns(input?: {
1269
+ agentId?: AgentId;
1270
+ states?: readonly RunState[];
1271
+ }): Promise<readonly RunRecord[]>;
1272
+ listEvents(input?: {
1273
+ after?: EventCursor;
1274
+ }): Promise<readonly DurableRunEvent[]>;
1275
+ openConsumer(consumerId: string): Promise<ConsumerRegistration>;
1276
+ advanceConsumerCheckpoint(input: {
1277
+ consumerId: string;
1278
+ cursor: EventCursor;
1279
+ }): Promise<void>;
1280
+ renewOwner(leaseMs: number): Promise<OwnerLease>;
1281
+ sealAndReleaseOwner(): Promise<void>;
1282
+ }
1283
+ interface DurableStore {
1284
+ openOwner(input: {
1285
+ ownerId: string;
1286
+ leaseMs: number;
1287
+ }): Promise<OwnedStore>;
1288
+ }
1289
+ type AgentRuntimeOptions = Readonly<{
1290
+ store: DurableStore;
1291
+ configs?: ConfigProvider;
1292
+ concurrency?: number;
1293
+ bootstrap?: (registry: RuntimeBootstrapRegistry) => void | Promise<void>;
1294
+ host?: ExtensionHost;
1295
+ sessionFiles?: Readonly<{
1296
+ dir: string;
1297
+ }>;
1298
+ /** @internal Private / testing parameter to override retry delay */
1299
+ retryDelayMs?: number;
1300
+ }>;
1301
+ type DurableConsumer = Readonly<{
1302
+ caughtUp: Promise<void>;
1303
+ done: Promise<void>;
1304
+ stop(): void;
1305
+ }>;
1306
+ interface AgentRun {
1307
+ readonly id: RunId;
1308
+ snapshot(): Promise<RunSnapshot>;
1309
+ observe(options?: {
1310
+ after?: EventCursor;
1311
+ signal?: AbortSignal;
1312
+ }): AsyncIterable<RunEvent>;
1313
+ wait(options?: {
1314
+ signal?: AbortSignal;
1315
+ }): Promise<RunBoundary>;
1316
+ respondInteraction(input: {
1317
+ interactionId: string;
1318
+ input?: JsonValue;
1319
+ cancel?: boolean;
1320
+ }): Promise<void>;
1321
+ cancel(reason?: string): Promise<RunBoundary>;
1322
+ }
1323
+ interface AgentRuntime {
1324
+ readonly host: ExtensionHost;
1325
+ loadAgents(input: LoadInput<AgentDefinition>): Promise<LoadResult>;
1326
+ loadSkills(input: LoadInput<Skill>): Promise<LoadResult>;
1327
+ loadPhases(input: LoadInput<Phase>): Promise<LoadResult>;
1328
+ loadTools(input: Readonly<{
1329
+ sourceId: string;
1330
+ values: readonly Tool[];
1331
+ }>): Promise<LoadResult>;
1332
+ unload(input: Readonly<{
1333
+ kind: ResourceKind;
1334
+ sourceId: string;
1335
+ }>): Promise<LoadResult>;
1336
+ createAgent(config: AgentConfiguration, options?: {
1337
+ idempotencyKey?: string;
1338
+ metadata?: Metadata;
1339
+ historySeed?: HistorySeed;
1340
+ }): Promise<AgentId>;
1341
+ updateAgentConfig(agentId: AgentId, config: AgentConfiguration, options: {
1342
+ idempotencyKey: string;
1343
+ }): Promise<void>;
1344
+ deleteAgent(input: AgentDeletionRequest): Promise<void>;
1345
+ revise(agentId: AgentId, input: {
1346
+ messageId: MessageId;
1347
+ expectedMessageRevision: number;
1348
+ content: UserContent;
1349
+ operationId: string;
1350
+ effectDigestConfirmation?: string;
1351
+ }): Promise<MessageRevisionResult>;
1352
+ compact(input?: {
1353
+ now?: string;
1354
+ retentionMs?: number;
1355
+ }): Promise<RetentionResult>;
1356
+ start(agentId: AgentId, input: UserInput, options: {
1357
+ idempotencyKey: string;
1358
+ metadata?: Metadata;
1359
+ scope?: ScopeRef;
1360
+ cwd?: string;
1361
+ phasePayload?: JsonValue;
1362
+ entryPhases?: ReadonlyArray<EntryPhaseSpec>;
1363
+ }): Promise<AgentRun>;
1364
+ run(runId: RunId): AgentRun;
1365
+ contextStatus(agentId: AgentId, options?: {
1366
+ contextWindow?: number;
1367
+ }): Promise<ContextStatus>;
1368
+ compactContext(agentId: AgentId, options?: {
1369
+ input?: UserInput;
1370
+ instructions?: string;
1371
+ idempotencyKey?: string;
1372
+ }): Promise<AgentRun>;
1373
+ runPhase(agentId: AgentId, options: {
1374
+ phase: string;
1375
+ payload?: JsonValue;
1376
+ input?: UserInput;
1377
+ yieldToInput?: boolean;
1378
+ idempotencyKey?: string;
1379
+ }): Promise<AgentRun>;
1380
+ listInvocations(agentId: AgentId, options: {
1381
+ source: InvocationSource;
1382
+ }): Promise<readonly InvocationCatalogEntry[]>;
1383
+ history(agentId: AgentId): Promise<readonly Message[]>;
1384
+ listAgents(input?: {
1385
+ after?: AgentListCursor;
1386
+ limit?: number;
1387
+ }): Promise<Page<AgentSummary, AgentListCursor>>;
1388
+ listRuns(input?: {
1389
+ agentId?: AgentId;
1390
+ states?: readonly RunState[];
1391
+ after?: RunListCursor;
1392
+ limit?: number;
1393
+ }): Promise<Page<RunSummary, RunListCursor>>;
1394
+ consume(input: {
1395
+ consumerId: string;
1396
+ signal: AbortSignal;
1397
+ onEvent(event: DurableRunEvent, context: Readonly<{
1398
+ signal: AbortSignal;
1399
+ }>): void | Promise<void>;
1400
+ }): Promise<DurableConsumer>;
1401
+ listCapabilities(): readonly ExtensionCapability[];
1402
+ onCapabilitiesChanged(listener: (capabilities: readonly ExtensionCapability[]) => void): () => void;
1403
+ triggerUiAction(event: {
1404
+ contributionId: string;
1405
+ actionId: string;
1406
+ scope?: ScopeRef;
1407
+ }): void;
1408
+ close(): Promise<void>;
1409
+ }
1410
+ type ConsumerRegistration = Readonly<{
1411
+ cursor?: EventCursor;
1412
+ waterline: EventCursor;
1413
+ }>;
1414
+
1415
+ type ModelInvokeOutput = {
1416
+ text: string;
1417
+ contentBlocks: ContentBlock[];
1418
+ toolCalls: ToolCall[];
1419
+ stopReason?: string;
1420
+ model?: ModelRef;
1421
+ usage?: LlmTokenUsage;
1422
+ };
1423
+ type InternalModelLoopOptions = {
1424
+ prompt: string;
1425
+ tools?: readonly string[];
1426
+ maxToolRounds?: number;
1427
+ };
1428
+ /** Execution capabilities for a phase — operates on PhaseContext. */
1429
+ type PhaseExecution = {
1430
+ invokeModel(context: PhaseContext, options?: {
1431
+ output?: "reply" | "internal";
1432
+ }): Promise<ModelInvokeOutput>;
1433
+ runInternalModelLoop(context: PhaseContext, options: InternalModelLoopOptions): Promise<ModelInvokeOutput>;
1434
+ reportStatus(status: PhaseStatus): Promise<void>;
1435
+ executeTools(context: AgentContext, toolCalls: readonly ToolCall[], contentBlocks?: readonly ContentBlock[], meta?: {
1436
+ model?: ModelRef;
1437
+ usage?: LlmTokenUsage;
1438
+ }): Promise<readonly ToolResult[]>;
1439
+ interaction: RunInteractionDriver;
1440
+ /** Message lifecycle manager for streaming updates from programmatic phases */
1441
+ messages: PhaseMessageManager;
1442
+ };
1443
+ /** Message lifecycle manager for streaming updates */
1444
+ type PhaseMessageManager = {
1445
+ /** Get all visible messages in the transcript */
1446
+ visible(): AgentMessage[];
1447
+ /** Reserve the eventual message identity before stream deltas arrive. */
1448
+ reserve(role: "assistant" | "tool", metadata?: Record<string, unknown>): string;
1449
+ /** Start a new message stream, returns message id */
1450
+ start(role: "assistant" | "tool", content: AgentMessage["content"], metadata?: Record<string, unknown>): string;
1451
+ /** Stream a text delta */
1452
+ update(messageId: string, delta: string): Promise<void>;
1453
+ /** Replace the active message content with model-native content parts */
1454
+ replaceContent(messageId: string, content: string | LlmContentPart[]): void;
1455
+ /** End the message stream, appends to transcript */
1456
+ end(messageId: string, meta?: {
1457
+ model?: ModelRef;
1458
+ usage?: LlmTokenUsage;
1459
+ }): Promise<void>;
1460
+ /** Drop an unstarted stream that produced no content. */
1461
+ discard(messageId: string): void;
1462
+ };
1463
+
1464
+ interface ExtensionStateStore {
1465
+ get(key: string): Promise<JsonValue | undefined>;
1466
+ set(key: string, value: JsonValue): Promise<void>;
1467
+ delete(key: string): Promise<void>;
1468
+ }
1469
+ interface ExtensionHost {
1470
+ getConfig(extensionId: string, scope?: ScopeRef): Promise<JsonObject | null> | JsonObject | null;
1471
+ onConfigChanged?(listener: (extensionId: string, scope: ScopeRef) => void): (() => void) | void;
1472
+ getAgentState(extensionId: string, agentId: string, key: string): Promise<JsonValue | undefined> | JsonValue | undefined;
1473
+ setAgentState(extensionId: string, agentId: string, key: string, value: JsonValue): Promise<void> | void;
1474
+ deleteAgentState(extensionId: string, agentId: string, key: string): Promise<void> | void;
1475
+ getGlobalState(extensionId: string, key: string): Promise<JsonValue | undefined> | JsonValue | undefined;
1476
+ setGlobalState(extensionId: string, key: string, value: JsonValue): Promise<void> | void;
1477
+ deleteGlobalState(extensionId: string, key: string): Promise<void> | void;
1478
+ /**
1479
+ * Called once per extension load. The returned namespaces are merged into that extension's `api`
1480
+ * (a name already used by Rowan's own API is an error). `dispose` runs when the extension is
1481
+ * unloaded, reloaded or fails activation, so the host can drop everything that extension registered.
1482
+ */
1483
+ extendApi?(extensionId: string): HostApiExtension | undefined;
1484
+ }
1485
+ interface HostApiExtension {
1486
+ readonly namespaces: Readonly<Record<string, unknown>>;
1487
+ dispose?(): void;
1488
+ }
1489
+ type ExtensionToolContribution = {
1490
+ kind: "tool";
1491
+ name: string;
1492
+ description: string;
1493
+ };
1494
+ type ExtensionCapabilityContribution = ExtensionToolContribution;
1495
+ type ExtensionCapability = {
1496
+ extensionId: string;
1497
+ kind: "tool";
1498
+ name: string;
1499
+ description: string;
1500
+ };
1501
+ interface SourceInfo {
1502
+ source: string;
1503
+ baseDir?: string;
1504
+ displayName?: string;
1505
+ }
1506
+ /** A loaded directory Bundle used by an extension. */
1507
+ type PhaseDefinition = Phase;
1508
+ /** Register a Phase by directory path or Phase object; PHASE.md and direct child Skills are loaded atomically when a path is supplied. */
1509
+ type PhaseRegistration = string | Phase;
1510
+ type RegisteredPhase = {
1511
+ definition: PhaseDefinition;
1512
+ source: {
1513
+ extensionPath: string;
1514
+ };
1515
+ sourceId: string;
1516
+ scope?: ScopeRef;
1517
+ };
1518
+ /** Register a Skill directory (containing SKILL.md) or a Skill object. Registering an existing name replaces it. */
1519
+ type SkillRegistration = string | Skill;
1520
+ type RegisteredSkill = {
1521
+ definition: Skill;
1522
+ source: {
1523
+ extensionPath: string;
1524
+ };
1525
+ sourceId: string;
1526
+ scope?: ScopeRef;
1527
+ };
1528
+ /**
1529
+ * Tool definition for registering LLM-callable tools via `api.tools.register()`.
1530
+ *
1531
+ * @example
1532
+ * ```typescript
1533
+ * api.tools.register({
1534
+ * name: "search_docs",
1535
+ * description: "Search documentation",
1536
+ * parameters: { type: "object", properties: { query: { type: "string" } } },
1537
+ * execute: async (args, ctx) => {
1538
+ * return { content: [{ type: "text", text: "result" }] };
1539
+ * },
1540
+ * });
1541
+ * ```
1542
+ */
1543
+ interface ToolDefinition {
1544
+ /** Tool name (used in LLM tool calls) */
1545
+ name: string;
1546
+ /** Description for LLM */
1547
+ description: string;
1548
+ /** Parameter schema (JSON Schema) */
1549
+ parameters: Record<string, unknown>;
1550
+ /** Optional: one-line snippet shown in the system prompt tool list */
1551
+ promptSnippet?: string;
1552
+ /** Optional: additional guidelines appended to system prompt */
1553
+ promptGuidelines?: string[];
1554
+ kind?: ToolKind;
1555
+ annotations?: ToolAnnotations;
1556
+ _meta?: JsonObject;
1557
+ present?: (call: {
1558
+ status: ToolCallStatus;
1559
+ args: JsonValue;
1560
+ progress?: ToolProgress;
1561
+ result?: ToolExecutionResult;
1562
+ }) => {
1563
+ title?: string;
1564
+ content?: ToolCallContent[];
1565
+ locations?: ToolCallLocation[];
1566
+ _meta?: JsonObject;
1567
+ } | undefined | void | Promise<{
1568
+ title?: string;
1569
+ content?: ToolCallContent[];
1570
+ locations?: ToolCallLocation[];
1571
+ _meta?: JsonObject;
1572
+ } | undefined | void>;
1573
+ /** Execute the tool */
1574
+ execute: (args: unknown, context: ToolInvocationContext, signal?: AbortSignal) => Promise<ToolExecutionResult>;
1575
+ /** Optional: per-tool execution mode override */
1576
+ executionMode?: "sequential" | "parallel";
1577
+ }
1578
+
1579
+ /**
1580
+ * Registered tool with source metadata.
1581
+ */
1582
+ interface RegisteredTool {
1583
+ definition: ToolDefinition;
1584
+ sourceInfo: SourceInfo;
1585
+ sourceId: string;
1586
+ scope?: ScopeRef;
1587
+ }
1588
+ /**
1589
+ * Structured extension error with attribution.
1590
+ */
1591
+ interface ExtensionError {
1592
+ /** Path of the extension that caused the error */
1593
+ extensionPath: string;
1594
+ /** Event or operation that caused the error */
1595
+ event: string;
1596
+ /** Error message */
1597
+ error: string;
1598
+ /** Optional stack trace */
1599
+ stack?: string;
1600
+ }
1601
+ /** Error listener callback type. */
1602
+ type ExtensionErrorListener = (error: ExtensionError) => void;
1603
+ type ExecOptions = {
1604
+ /** Working directory for the command. Defaults to cwd passed to runtime. */
1605
+ cwd?: string;
1606
+ /** Environment variables to add/override. */
1607
+ env?: Record<string, string>;
1608
+ /** Timeout in milliseconds. */
1609
+ timeout?: number;
1610
+ /** AbortSignal for cancellation. */
1611
+ signal?: AbortSignal;
1612
+ };
1613
+ type ExecResult = {
1614
+ exitCode: number;
1615
+ stdout: string;
1616
+ stderr: string;
1617
+ };
1618
+ /**
1619
+ * Shared runtime state created by loader, used during registration and runtime.
1620
+ * All ExtensionAPI instances reference this shared state.
1621
+ *
1622
+ * It only owns the lifetime guard shared by captured Extension API objects.
1623
+ */
1624
+ interface ExtensionRuntime {
1625
+ /** Throws when this extension instance is stale after runtime replacement. */
1626
+ assertActive: () => void;
1627
+ /** Marks this extension instance as stale after runtime replacement or reload. */
1628
+ invalidate: (message?: string) => void;
1629
+ }
1630
+ /**
1631
+ * Result of loading extensions from filesystem.
1632
+ * The runner takes these and creates Extension tracking objects.
1633
+ */
1634
+ type LoadExtensionsResult = {
1635
+ extensions: LoadedExtension[];
1636
+ errors: Array<{
1637
+ path: string;
1638
+ error: string;
1639
+ }>;
1640
+ };
1641
+ /**
1642
+ * Pre-initialization extension form — factory + metadata.
1643
+ * Runner.loadExtensions() calls the factory and creates the full Extension object.
1644
+ */
1645
+ interface LoadedExtension {
1646
+ id?: string;
1647
+ path: string;
1648
+ name: string;
1649
+ factory: ExtensionFactory;
1650
+ manifest?: ExtensionManifest;
1651
+ }
1652
+ /** Extension manifest from package.json `rowan` field. */
1653
+ interface ExtensionManifest {
1654
+ id?: string;
1655
+ entry?: string;
1656
+ name?: string;
1657
+ }
1658
+
1659
+ type ExtensionAgentConsumerDisposer = (() => void) & {
1660
+ readonly stop: () => void;
1661
+ readonly caughtUp: Promise<void>;
1662
+ readonly done: Promise<void>;
1663
+ };
1664
+ interface ExtensionAgentsAPI {
1665
+ list(input?: {
1666
+ after?: AgentListCursor;
1667
+ limit?: number;
1668
+ }): Promise<Page<AgentSummary, AgentListCursor>>;
1669
+ history(agentId: AgentId | string): Promise<readonly Message[]>;
1670
+ contextStatus(agentId: AgentId | string, options?: {
1671
+ contextWindow?: number;
1672
+ }): Promise<ContextStatus>;
1673
+ runs(agentId: AgentId | string, filter?: {
1674
+ states?: readonly RunState[];
1675
+ after?: RunListCursor;
1676
+ limit?: number;
1677
+ }): Promise<Page<RunSummary, RunListCursor>>;
1678
+ runPhase(agentId: AgentId | string, options: {
1679
+ phase: string;
1680
+ payload?: JsonValue;
1681
+ input?: UserInput;
1682
+ yieldToInput?: boolean;
1683
+ idempotencyKey?: string;
1684
+ }): Promise<AgentRun>;
1685
+ consume(consumerId: string, onEvent: (event: DurableRunEvent, context: Readonly<{
1686
+ signal: AbortSignal;
1687
+ }>) => void | Promise<void>): Promise<ExtensionAgentConsumerDisposer>;
1688
+ }
1689
+ interface ExtensionAgentsRuntimeDelegate {
1690
+ listAgents(input?: {
1691
+ after?: AgentListCursor;
1692
+ limit?: number;
1693
+ }): Promise<Page<AgentSummary, AgentListCursor>>;
1694
+ history(agentId: AgentId): Promise<readonly Message[]>;
1695
+ contextStatus(agentId: AgentId, options?: {
1696
+ contextWindow?: number;
1697
+ }): Promise<ContextStatus>;
1698
+ listRuns(input?: {
1699
+ agentId?: AgentId;
1700
+ states?: readonly RunState[];
1701
+ after?: RunListCursor;
1702
+ limit?: number;
1703
+ }): Promise<Page<RunSummary, RunListCursor>>;
1704
+ runPhase(agentId: AgentId, options: {
1705
+ phase: string;
1706
+ payload?: JsonValue;
1707
+ input?: UserInput;
1708
+ yieldToInput?: boolean;
1709
+ idempotencyKey?: string;
1710
+ }): Promise<AgentRun>;
1711
+ consume(input: {
1712
+ consumerId: string;
1713
+ signal: AbortSignal;
1714
+ onEvent(event: DurableRunEvent, context: Readonly<{
1715
+ signal: AbortSignal;
1716
+ }>): void | Promise<void>;
1717
+ }): Promise<DurableConsumer>;
1718
+ }
1719
+ /**
1720
+ * Extension API object passed to extension factory function.
1721
+ *
1722
+ * @example
1723
+ * ```typescript
1724
+ * export default function(api: ExtensionAPI) {
1725
+ * // api provides all extension APIs
1726
+ * }
1727
+ * ```
1728
+ */
1729
+ interface ExtensionAPI {
1730
+ /** Hook events — subscribe or unsubscribe. */
1731
+ hooks: {
1732
+ /**
1733
+ * Subscribe to a hook event.
1734
+ *
1735
+ * @param eventType - Hook type, e.g. "before_tool_call"
1736
+ * @param handler - Hook handler, can return result to modify behavior
1737
+ */
1738
+ on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
1739
+ /** Unsubscribe from a hook event. */
1740
+ off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
1741
+ };
1742
+ /** Extension configuration — read own layered config or listen for changes. */
1743
+ config: {
1744
+ /** Get the extension's own effective configuration block. */
1745
+ get(scope?: ScopeRef): Promise<JsonObject | null>;
1746
+ /** Listen for configuration changes for a scope. */
1747
+ changed(handler: (scope: ScopeRef) => void): void;
1748
+ };
1749
+ /** Extension state — scoped to run (in-memory) or agent (durable) or global (durable). */
1750
+ state: {
1751
+ /** Run-scoped in-memory state; dropped when the Run ends. */
1752
+ run(runId: string): ExtensionStateStore;
1753
+ /** Agent-scoped durable state; persisted with the Agent record. */
1754
+ agent(agentId: string): ExtensionStateStore;
1755
+ /** Extension-scoped durable state; survives process restarts. */
1756
+ global(): ExtensionStateStore;
1757
+ };
1758
+ /** Tool capabilities — register and unregister custom tools. */
1759
+ tools: {
1760
+ /** Register a custom LLM-callable tool. */
1761
+ register(tool: ToolDefinition, scope?: ScopeRef): Promise<void>;
1762
+ /** Unregister a previously registered tool by name. */
1763
+ unregister(toolName: string, scope?: ScopeRef): Promise<void>;
1764
+ };
1765
+ /** Skill capabilities — register and unregister standalone skills. */
1766
+ skills: {
1767
+ /** Register a Skill directory (containing SKILL.md) or a Skill object. Registering an existing name replaces it. */
1768
+ register(skill: SkillRegistration, scope?: ScopeRef): Promise<void>;
1769
+ /** Unregister a previously registered Skill by name. */
1770
+ unregister(skillName: string, scope?: ScopeRef): Promise<void> | void;
1771
+ };
1772
+ /** Phase capabilities — register, unregister, and execute. */
1773
+ phases: {
1774
+ /** Register a Phase directory bundle or Phase object. */
1775
+ register(phase: PhaseRegistration, scope?: ScopeRef): Promise<void>;
1776
+ /** Unregister a previously registered phase by name. */
1777
+ unregister(phaseName: string, scope?: ScopeRef): Promise<void> | void;
1778
+ /** Set the Phase's execution handler. Only available within an Extension Phase factory. */
1779
+ execute(handler: PhaseRunHandler): void;
1780
+ };
1781
+ /** Model provider registration. */
1782
+ models: {
1783
+ /** Register a model provider. Registering with an existing id replaces it. */
1784
+ registerProvider(config: ProviderConfig): void;
1785
+ /** Unregister a model provider by id. */
1786
+ unregisterProvider(id: string): void;
1787
+ };
1788
+ /** Runtime Agent control and consumption. Delegates to the AgentRuntime the Extension is activated in. */
1789
+ agents: ExtensionAgentsAPI;
1790
+ /** Shared event bus for inter-extension communication. */
1791
+ events: EventBus;
1792
+ /** Capability contributions — advertise tools or features to the host. */
1793
+ capabilities: {
1794
+ /** Contribute a capability to the host. Returns a disposer to remove the contribution. */
1795
+ contribute(contribution: ExtensionCapabilityContribution): () => void;
1796
+ };
1797
+ /** Runtime context — cwd, signal, exec. */
1798
+ context: ExtensionContext;
1799
+ }
1800
+ /**
1801
+ * Extension factory function.
1802
+ * Receives ExtensionAPI for registering hooks, phases, and providers.
1803
+ */
1804
+ type ExtensionDisposer = () => void | Promise<void>;
1805
+ type ExtensionFactoryResult = void | ExtensionDisposer;
1806
+ type ExtensionFactory = (api: ExtensionAPI) => ExtensionFactoryResult | Promise<ExtensionFactoryResult>;
1807
+
1808
+ type PhaseStatusState = "running" | "completed";
1809
+ /** Normalized status event exposed to Runtime consumers. */
1810
+ type PhaseStatus = Readonly<{
1811
+ state: PhaseStatusState;
1812
+ /** Stable consumer-facing status identifier, e.g. `compacting`. */
1813
+ kind: string;
1814
+ /** Optional human-readable detail for UI/status consumers. */
1815
+ message?: string;
1816
+ /** Structured status payload. */
1817
+ payload?: unknown;
1818
+ }>;
1819
+ /** Unified phase output — model-driven routing is optional; programmatic phases may normalize omission to stop. */
1820
+ type PhaseOutput = {
1821
+ /** User-visible assistant message. */
1822
+ message?: string;
1823
+ /** Final status update for non-conversational consumers. */
1824
+ status?: PhaseStatus;
1825
+ /** Route to next phase, or "continue" to re-execute current phase, or "stop" to end. Undefined means no model route. */
1826
+ route?: string;
1827
+ /** Phase name that produced this output */
1828
+ phase?: string;
1829
+ /** Tool calls from the model invocation (used by framework for route extraction) */
1830
+ toolCalls?: Array<{
1831
+ id: string;
1832
+ name: string;
1833
+ args: unknown;
1834
+ }>;
1835
+ /** Route reason extracted from route tool call (for hooks to inspect) */
1836
+ routeReason?: string;
1837
+ /** Structured data from this phase, passed to the next phase */
1838
+ payload?: unknown;
1839
+ };
1840
+ /** Phase machine state — tracks position and inter-phase data */
1841
+ interface PhaseState {
1842
+ current: string;
1843
+ available: string[];
1844
+ iterations: number;
1845
+ payload?: unknown;
1846
+ }
1847
+ type PhaseInvocation = {
1848
+ mode: "serial";
1849
+ instanceId: string;
1850
+ } | {
1851
+ mode: "parallel";
1852
+ instanceId: string;
1853
+ groupId: string;
1854
+ index: number;
1855
+ count: number;
1856
+ sourcePhaseId: string;
1857
+ };
1858
+ /** Durable identity of the Run execution currently invoking a Phase. */
1859
+ type PhaseExecutionIdentity = Readonly<{
1860
+ agentId: string;
1861
+ runId: string;
1862
+ executionId: string;
1863
+ /** Original durable Run input, before any Phase-local interpretation. */
1864
+ input?: UserContent;
1865
+ /** Opaque metadata captured at the durable boundary; Rowan does not decode it. */
1866
+ agentMetadata?: Readonly<Record<string, unknown>>;
1867
+ runMetadata?: Readonly<Record<string, unknown>>;
1868
+ scope?: _rowan_agent_models.ScopeRef;
1869
+ cwd?: string;
1870
+ }>;
1871
+ /** Everything a phase needs to execute */
1872
+ interface PhaseContext {
1873
+ systemPrompt: string;
1874
+ messages: AgentMessage[];
1875
+ /** Phase-filtered tools */
1876
+ tools: Tool$1[];
1877
+ /** Phase-filtered skills */
1878
+ skills: Skill[];
1879
+ /** Phase machine state */
1880
+ state: PhaseState;
1881
+ /** Identity and dispatch metadata for this phase execution */
1882
+ readonly invocation: PhaseInvocation;
1883
+ /** Durable Run identity for cross-store integrations and idempotent commands. */
1884
+ readonly execution: PhaseExecutionIdentity;
1885
+ /** Additional guideline bullets appended to the system prompt */
1886
+ promptGuidelines?: string[];
1887
+ /** Text to append after the system prompt */
1888
+ appendSystemPrompt?: string;
1889
+ }
1890
+ /** JSON-safe structural defaults declared by a Phase's `input` mapping. */
1891
+ type PhaseInput = Readonly<Record<string, JsonValue>>;
1892
+ /** JSON-safe option metadata exposed to a host Settings surface. */
1893
+ interface SettingsOption {
1894
+ value: string;
1895
+ label: string;
1896
+ description?: string;
1897
+ disabled?: boolean;
1898
+ }
1899
+ interface SettingsBadge {
1900
+ label: string;
1901
+ tone?: "neutral" | "success" | "review" | "danger";
1902
+ }
1903
+ interface SettingsItem {
1904
+ id: string;
1905
+ title: string;
1906
+ description?: string;
1907
+ badges?: readonly SettingsBadge[];
1908
+ }
1909
+ type SettingsControl = {
1910
+ type: "boolean";
1911
+ path: string;
1912
+ label: string;
1913
+ description?: string;
1914
+ } | {
1915
+ type: "number";
1916
+ path: string;
1917
+ label: string;
1918
+ description?: string;
1919
+ min?: number;
1920
+ max?: number;
1921
+ step?: number;
1922
+ unit?: string;
1923
+ scale?: number;
1924
+ } | {
1925
+ type: "select";
1926
+ path: string;
1927
+ label: string;
1928
+ description?: string;
1929
+ options: readonly SettingsOption[];
1930
+ } | {
1931
+ type: "text";
1932
+ path: string;
1933
+ label: string;
1934
+ description?: string;
1935
+ placeholder?: string;
1936
+ format?: "string" | "string-array" | "key-value";
1937
+ multiline?: boolean;
1938
+ } | {
1939
+ type: "collection";
1940
+ path: string;
1941
+ label: string;
1942
+ description?: string;
1943
+ items: readonly SettingsItem[];
1944
+ fields: readonly SettingsControl[];
1945
+ add?: {
1946
+ label: string;
1947
+ idLabel?: string;
1948
+ fields: readonly SettingsControl[];
1949
+ };
1950
+ removeLabel?: string;
1951
+ };
1952
+ interface SettingsSection {
1953
+ id: string;
1954
+ title: string;
1955
+ description?: string;
1956
+ controls: readonly SettingsControl[];
1957
+ }
1958
+ /** Declarative, host-neutral Settings surface. */
1959
+ interface SettingsDefinition {
1960
+ description?: string;
1961
+ sections: readonly SettingsSection[];
1962
+ }
1963
+ type PhaseRunHandler = (context: PhaseContext, execution: PhaseExecution) => Promise<PhaseOutput | void> | PhaseOutput | void;
1964
+ /**
1965
+ * Loaded Phase object
1966
+ */
1967
+ interface Phase {
1968
+ /** Unique phase identity and display name. */
1969
+ name: string;
1970
+ /** Rowan-owned built-in Phase; built-ins are never filtered or disabled. */
1971
+ core?: boolean;
1972
+ /** Description */
1973
+ description: string;
1974
+ /** Restricted tools (undefined = all tools available) */
1975
+ tools?: string[];
1976
+ /** Skills bundled directly inside this phase directory. Inline phases may omit this (equivalent to []). */
1977
+ skills?: Skill[];
1978
+ /** Forced next phase */
1979
+ target?: string;
1980
+ /** Additional system-prompt guidance while this Phase is in the auto route catalog. */
1981
+ promptGuidelines?: string[];
1982
+ /** Structural JSON-safe input defaults */
1983
+ input?: PhaseInput;
1984
+ /** If true, phase gets a fresh context when executed in parallel */
1985
+ isolated?: boolean;
1986
+ /** Path to PHASE.md file */
1987
+ filePath: string;
1988
+ /** Phase directory path */
1989
+ baseDir: string;
1990
+ /** PHASE.md body content */
1991
+ content: string;
1992
+ /** Model override for this phase (resolved from frontmatter) */
1993
+ model?: ModelRef;
1994
+ /** Do not automatically inject this Phase into the model route catalog/context. */
1995
+ disableAutoInvocation?: boolean;
1996
+ /** Do not expose this Phase to direct user invocation. */
1997
+ disableImplicitInvocation?: boolean;
1998
+ metadata?: Readonly<Record<string, JsonValue>>;
1999
+ /** Extension factory function used for Extension Phase execution. */
2000
+ extensionFactory?: ExtensionFactory;
2001
+ /** Direct run function */
2002
+ run?: PhaseRunHandler;
2003
+ }
2004
+ /**
2005
+ * Phase registry containing all loaded phases
2006
+ */
2007
+ interface PhaseRegistry {
2008
+ /** Map of phase name to Phase object */
2009
+ phases: Map<string, Phase>;
2010
+ /** Entry phase name (null until Agent applies its default phase) */
2011
+ entryPhaseId: string | null;
2012
+ }
2013
+
2014
+ declare const opaqueIdBrand: unique symbol;
2015
+ type OpaqueId<Kind extends string> = string & {
2016
+ readonly [opaqueIdBrand]: Kind;
2017
+ };
2018
+ type AgentId = OpaqueId<"AgentId">;
2019
+ type RunId = OpaqueId<"RunId">;
2020
+ type MessageId = OpaqueId<"MessageId">;
2021
+ type ToolCallId = OpaqueId<"ToolCallId">;
2022
+ type EventId = OpaqueId<"EventId">;
2023
+ type ExecutionId = OpaqueId<"ExecutionId">;
2024
+ type OutcomeId = OpaqueId<"OutcomeId">;
2025
+ type ConfigToken = OpaqueId<"ConfigToken">;
2026
+ type OwnerToken = OpaqueId<"OwnerToken">;
2027
+ type EventCursor = OpaqueId<"EventCursor">;
2028
+ type AgentListCursor = OpaqueId<"AgentListCursor">;
2029
+ type RunListCursor = OpaqueId<"RunListCursor">;
2030
+ type JsonPrimitive = null | boolean | number | string;
2031
+ type JsonValue = JsonPrimitive | readonly JsonValue[] | {
2032
+ readonly [key: string]: JsonValue;
2033
+ };
2034
+ type JsonObject = Readonly<Record<string, JsonValue>>;
2035
+ type Metadata = JsonObject;
2036
+ type TextContent = Readonly<{
2037
+ type: "text";
2038
+ text: string;
2039
+ }>;
2040
+ type ImageContent = Readonly<{
2041
+ type: "image";
2042
+ data: string;
2043
+ mimeType: string;
2044
+ }>;
2045
+ type ThinkingContent = Readonly<{
2046
+ type: "thinking";
2047
+ thinking: string;
2048
+ signature?: string;
2049
+ }>;
2050
+ type ToolUseContent = Readonly<{
2051
+ type: "tool_use";
2052
+ toolCallId: ToolCallId;
2053
+ /** Provider/model correlation, retained only to reconstruct the next request. */
2054
+ providerToolCallId?: string;
2055
+ name: string;
2056
+ input: JsonValue;
2057
+ }>;
2058
+ type ToolExecutionResult = Readonly<{
2059
+ ok: true;
2060
+ content: JsonValue;
2061
+ structuredContent?: JsonValue;
2062
+ isError?: boolean;
2063
+ }> | Readonly<{
2064
+ ok: false;
2065
+ content: JsonValue;
2066
+ error: string;
2067
+ structuredContent?: JsonValue;
2068
+ isError?: boolean;
2069
+ }> | Readonly<{
2070
+ content: readonly ContentBlock[];
2071
+ structuredContent?: JsonValue;
2072
+ isError?: boolean;
2073
+ ok?: boolean;
2074
+ error?: string;
2075
+ }>;
2076
+ type DurableToolResult = Readonly<{
2077
+ toolCallId: ToolCallId;
2078
+ toolName: string;
2079
+ }> & ToolExecutionResult;
2080
+ type ToolResultContent = Readonly<{
2081
+ type: "tool_result";
2082
+ toolCallId: ToolCallId;
2083
+ /** Provider/model correlation, retained only to reconstruct the next request. */
2084
+ providerToolCallId?: string;
2085
+ result: ToolExecutionResult;
2086
+ }>;
2087
+ type UserContent = string | readonly (TextContent | ImageContent)[];
2088
+ type AssistantContent = string | readonly (TextContent | ThinkingContent | ToolUseContent)[];
2089
+ type ToolMessageContent = readonly [ToolResultContent, ...ToolResultContent[]];
2090
+ type MessageContent = UserContent | AssistantContent | ToolMessageContent;
2091
+ type MessageBase = Readonly<{
2092
+ id: MessageId;
2093
+ agentId: AgentId;
2094
+ runId: RunId;
2095
+ /** Monotonic active revision. Omitted on legacy/initial messages and read as 0. */
2096
+ messageRevision?: number;
2097
+ metadata?: Metadata;
2098
+ sequenceWithinRun: number;
2099
+ createdAt: string;
2100
+ }>;
2101
+ type ContextCandidate = Readonly<{
2102
+ name: string;
2103
+ value: JsonValue;
2104
+ }>;
2105
+ type UserMessage = MessageBase & Readonly<{
2106
+ role: "user";
2107
+ content: UserContent;
2108
+ contexts?: readonly ContextCandidate[];
2109
+ }>;
2110
+ type AssistantMessage = MessageBase & Readonly<{
2111
+ role: "assistant";
2112
+ content: AssistantContent;
2113
+ interrupted?: boolean;
2114
+ model?: ModelRef;
2115
+ usage?: LlmTokenUsage;
2116
+ }>;
2117
+ type ToolMessage = MessageBase & Readonly<{
2118
+ role: "tool";
2119
+ content: ToolMessageContent;
2120
+ }>;
2121
+ type InteractionRecord = MessageBase & Readonly<{
2122
+ role: "interaction";
2123
+ interactionId: string;
2124
+ kind: "user_input" | "permission" | "elicitation" | "confirmation";
2125
+ prompt: string;
2126
+ phase: string;
2127
+ status: "answered" | "replied" | "cancelled";
2128
+ answer?: JsonValue;
2129
+ reply?: string;
2130
+ toolCallId?: ToolCallId;
2131
+ result?: Readonly<{
2132
+ answered?: string;
2133
+ replied?: string;
2134
+ cancelled?: string;
2135
+ }>;
2136
+ }>;
2137
+ type Message = UserMessage | AssistantMessage | ToolMessage | InteractionRecord;
2138
+ type Outcome = Readonly<{
2139
+ id: OutcomeId;
2140
+ message: string;
2141
+ payload?: JsonValue;
2142
+ toolResults?: readonly DurableToolResult[];
2143
+ }>;
2144
+ type RunState = "queued" | "running" | "input_required" | "completed" | "failed" | "cancelled";
2145
+ type WithdrawnUserInput = Readonly<{
2146
+ messageId: MessageId;
2147
+ content: UserContent;
2148
+ }>;
2149
+ type RunFailure = Readonly<{
2150
+ code: "configuration_unavailable";
2151
+ message: string;
2152
+ withdrawnInput?: WithdrawnUserInput;
2153
+ }> | Readonly<{
2154
+ code: "checkpoint_incompatible";
2155
+ message: string;
2156
+ expected: Readonly<{
2157
+ codec: string;
2158
+ versions: readonly number[];
2159
+ }>;
2160
+ actual: Readonly<{
2161
+ codec: string;
2162
+ version: number;
2163
+ }>;
2164
+ withdrawnInput?: WithdrawnUserInput;
2165
+ }> | Readonly<{
2166
+ code: "runtime_interrupted";
2167
+ message: string;
2168
+ ownerEpoch: number;
2169
+ withdrawnInput?: WithdrawnUserInput;
2170
+ }> | Readonly<{
2171
+ code: "tool_indeterminate";
2172
+ message: string;
2173
+ toolCallIds: readonly [ToolCallId, ...ToolCallId[]];
2174
+ withdrawnInput?: WithdrawnUserInput;
2175
+ }> | Readonly<{
2176
+ code: "execution_failed";
2177
+ message: string;
2178
+ details?: JsonValue;
2179
+ withdrawnInput?: WithdrawnUserInput;
2180
+ }>;
2181
+ type QueuedRunFailure = Extract<RunFailure, {
2182
+ code: "configuration_unavailable" | "checkpoint_incompatible";
2183
+ }>;
2184
+ type RunningRunFailure = Extract<RunFailure, {
2185
+ code: "runtime_interrupted" | "tool_indeterminate" | "execution_failed";
2186
+ }>;
2187
+ type ToolCallState = ToolCallStatus;
2188
+ type ToolCallSnapshot = ToolCall$1 & Readonly<{
2189
+ id: ToolCallId;
2190
+ providerToolCallId?: string;
2191
+ agentId?: AgentId;
2192
+ runId?: RunId;
2193
+ executionId?: ExecutionId;
2194
+ requestMessageId?: MessageId;
2195
+ name?: string;
2196
+ args?: JsonValue;
2197
+ state?: ToolCallStatus;
2198
+ result?: DurableToolResult;
2199
+ resultMessageId?: MessageId;
2200
+ reason?: string;
2201
+ external?: boolean;
2202
+ contentIndex?: number;
2203
+ createdAt?: string;
2204
+ updatedAt?: string;
2205
+ }>;
2206
+ type DurableEventBase = Readonly<{
2207
+ id: EventId;
2208
+ schemaVersion: 1;
2209
+ cursor: EventCursor;
2210
+ durability: "durable";
2211
+ agentId: AgentId;
2212
+ runId: RunId;
2213
+ runRevision: number;
2214
+ metadata?: Metadata;
2215
+ createdAt: string;
2216
+ }>;
2217
+ type PhaseEntered = DurableEventBase & Readonly<{
2218
+ kind: "phase_entered";
2219
+ executionId: ExecutionId;
2220
+ phaseId: string;
2221
+ visit: number;
2222
+ }>;
2223
+ type MessageCommitted = DurableEventBase & Readonly<{
2224
+ kind: "message_committed";
2225
+ message: Message;
2226
+ }>;
2227
+ type MessageRevised = DurableEventBase & Readonly<{
2228
+ kind: "message_revised";
2229
+ message: UserMessage;
2230
+ previousRevision: number;
2231
+ invalidatedRunIds: readonly RunId[];
2232
+ targetRunId: RunId;
2233
+ cutoffSequenceWithinRun: number;
2234
+ }>;
2235
+ type RunStateChanged = DurableEventBase & (Readonly<{
2236
+ kind: "run_state_changed";
2237
+ from: null;
2238
+ to: "queued";
2239
+ }> | Readonly<{
2240
+ kind: "run_state_changed";
2241
+ from: "input_required";
2242
+ to: "queued";
2243
+ }> | Readonly<{
2244
+ kind: "run_state_changed";
2245
+ from: "queued";
2246
+ to: "running";
2247
+ }> | Readonly<{
2248
+ kind: "run_state_changed";
2249
+ from: "running";
2250
+ to: "input_required";
2251
+ interactions: readonly RunInteraction[];
2252
+ answers: Readonly<Record<string, JsonValue>>;
2253
+ }> | Readonly<{
2254
+ kind: "run_state_changed";
2255
+ from: "running";
2256
+ to: "completed";
2257
+ outcome: Outcome;
2258
+ output?: AssistantMessage;
2259
+ }> | Readonly<{
2260
+ kind: "run_state_changed";
2261
+ from: "queued";
2262
+ to: "failed";
2263
+ failure: QueuedRunFailure;
2264
+ withdrawnInput?: WithdrawnUserInput;
2265
+ }> | Readonly<{
2266
+ kind: "run_state_changed";
2267
+ from: "running";
2268
+ to: "failed";
2269
+ failure: RunningRunFailure;
2270
+ withdrawnInput?: WithdrawnUserInput;
2271
+ }> | Readonly<{
2272
+ kind: "run_state_changed";
2273
+ from: "queued" | "running" | "input_required";
2274
+ to: "cancelled";
2275
+ reason?: string;
2276
+ }>);
2277
+ type ToolStateChanged = (DurableEventBase & Readonly<{
2278
+ kind: "tool_state_changed";
2279
+ transition: Readonly<{
2280
+ from: ToolCallStatus | null;
2281
+ to: ToolCallStatus;
2282
+ }>;
2283
+ toolCall: ToolCall$1;
2284
+ external?: boolean;
2285
+ /** For a provider-reported call: assistant content blocks streamed before it. */
2286
+ contentIndex?: number;
2287
+ }>) | Readonly<{
2288
+ kind: "tool_state_changed";
2289
+ durability: "transient";
2290
+ runId: RunId;
2291
+ executionId?: ExecutionId;
2292
+ transition: Readonly<{
2293
+ from: ToolCallStatus | null;
2294
+ to: ToolCallStatus;
2295
+ }>;
2296
+ toolCall: ToolCall$1 | ToolCallUpdate;
2297
+ external?: boolean;
2298
+ contentIndex?: number;
2299
+ }>;
2300
+ type DurableRunEvent = PhaseEntered | MessageCommitted | MessageRevised | RunStateChanged | Extract<ToolStateChanged, {
2301
+ durability: "durable";
2302
+ }>;
2303
+ type MessageDelta = Readonly<{
2304
+ kind: "message_delta";
2305
+ durability: "transient";
2306
+ runId: RunId;
2307
+ executionId: ExecutionId;
2308
+ messageId: MessageId;
2309
+ offset: number;
2310
+ text: string;
2311
+ }>;
2312
+ type ThinkingDelta = Readonly<{
2313
+ kind: "thinking_delta";
2314
+ durability: "transient";
2315
+ runId: RunId;
2316
+ executionId: ExecutionId;
2317
+ messageId: MessageId;
2318
+ blockIndex: number;
2319
+ offset: number;
2320
+ text: string;
2321
+ }>;
2322
+ type ToolCallDelta = Readonly<{
2323
+ kind: "tool_call_delta";
2324
+ durability: "transient";
2325
+ runId: RunId;
2326
+ executionId: ExecutionId;
2327
+ messageId: MessageId;
2328
+ providerToolCallId: string;
2329
+ toolName: string;
2330
+ arguments: string;
2331
+ args: JsonValue | undefined;
2332
+ }>;
2333
+ type PhaseStatusEvent = Readonly<{
2334
+ kind: "phase_status";
2335
+ durability: "transient";
2336
+ runId: RunId;
2337
+ executionId: ExecutionId;
2338
+ phaseId: string;
2339
+ status: PhaseStatus;
2340
+ }>;
2341
+ type ModelRetry = Readonly<{
2342
+ kind: "model_retry";
2343
+ durability: "transient";
2344
+ runId: RunId;
2345
+ executionId: ExecutionId;
2346
+ attempt: number;
2347
+ maxRetries: number;
2348
+ delayMs: number;
2349
+ error: string;
2350
+ }>;
2351
+ type LiveInteractionEvent = Readonly<{
2352
+ kind: "live_interaction";
2353
+ durability: "transient";
2354
+ runId: RunId;
2355
+ executionId?: ExecutionId;
2356
+ interaction: RunInteraction;
2357
+ }>;
2358
+ type RunEvent = DurableRunEvent | MessageDelta | ThinkingDelta | ToolCallDelta | PhaseStatusEvent | ModelRetry | LiveInteractionEvent | Extract<ToolStateChanged, {
2359
+ durability: "transient";
2360
+ }>;
2361
+
2362
+ type RunInteractionKind = "user_input" | "permission" | "elicitation" | "confirmation";
2363
+ type RunInteractionStatus = "pending" | "answered" | "replied" | "cancelled";
2364
+ type RunInteraction = Readonly<{
2365
+ id: string;
2366
+ phase: string;
2367
+ kind: RunInteractionKind;
2368
+ prompt: string;
2369
+ payload?: JsonValue;
2370
+ createdAt: string;
2371
+ status: RunInteractionStatus;
2372
+ answer?: JsonValue;
2373
+ reply?: string;
2374
+ /** The Run is only waiting for the next user message, not asking a question. */
2375
+ turnBoundary?: true;
2376
+ toolCallId?: string;
2377
+ result?: Readonly<{
2378
+ answered?: string;
2379
+ replied?: string;
2380
+ cancelled?: string;
2381
+ }>;
2382
+ }>;
2383
+ type RunInteractionRequest = Readonly<{
2384
+ id?: string;
2385
+ kind: RunInteractionKind;
2386
+ prompt: string;
2387
+ payload?: JsonValue;
2388
+ toolCallId?: string;
2389
+ result?: Readonly<{
2390
+ answered?: string;
2391
+ replied?: string;
2392
+ cancelled?: string;
2393
+ }>;
2394
+ }>;
2395
+ type RunInteractionState = Readonly<{
2396
+ requests: readonly RunInteraction[];
2397
+ answers: Readonly<Record<string, JsonValue>>;
2398
+ checkpoint?: JsonValue;
2399
+ }>;
2400
+ type RunInteractionDriver = Readonly<{
2401
+ signal: AbortSignal;
2402
+ request(input: RunInteractionRequest): RunInteraction;
2403
+ pending(): readonly RunInteraction[];
2404
+ answers(): ReadonlyMap<string, JsonValue>;
2405
+ checkpoint(): JsonValue | undefined;
2406
+ clearCheckpoint(): void;
2407
+ answer?(id: string, value: JsonValue): void;
2408
+ clearAnswer?(id: string): void;
2409
+ suspend(input?: Readonly<{
2410
+ checkpoint?: JsonValue;
2411
+ }>): never;
2412
+ }>;
2413
+ declare class RunInteractionCancelledError extends Error {
2414
+ readonly code: "run_interaction_cancelled";
2415
+ constructor(message?: string);
2416
+ }
2417
+ declare class RunInteractionBoundary extends Error {
2418
+ readonly state: ExecutionState;
2419
+ readonly interactions: readonly RunInteraction[];
2420
+ constructor(state: ExecutionState, interactions: readonly RunInteraction[]);
2421
+ }
2422
+
2423
+ export { type ConfigToken as $, type AgentRuntime as A, type Message as B, type ContextStatus as C, type DurableRunEvent as D, type ExtensionHost as E, type RunBoundary as F, type RunEvent as G, type HostApiExtension as H, type InvocationSource as I, type JsonObject as J, type DurableStore as K, type LoadInput as L, type Metadata as M, type AgentRecord as N, type RunRecord as O, type Phase as P, type ExecutionId as Q, type ResourceKind as R, type Skill as S, type Tool as T, type UserContent as U, type ToolCallState as V, type DurableToolResult as W, type ContextCompactionRecord as X, type ToolCallSnapshot as Y, type OwnerLease as Z, type OwnedStore as _, type JsonValue as a, type ExtensionFactory as a$, type ContextCandidate as a0, type RunClaim as a1, type RunFailure as a2, type ExecutionToken as a3, type AssistantMessage as a4, type ExecutionCheckpoint as a5, type RunInteraction as a6, type ToolCommit as a7, type ToolCallReservation as a8, type ToolBatchCommit as a9, type ResourceRef as aA, ResourceRegistry as aB, ResourceRegistryError as aC, type ResourceRegistryErrorCode as aD, type ResourceSourceId as aE, type ResourceView as aF, RuntimeBootstrapRegistry as aG, RuntimeExtensionLifetime as aH, type ToolContribution as aI, extensionSourceId as aJ, isConfigurationSnapshot as aK, mergeToolCall as aL, parseAgentDefinition as aM, resolveConfigurationSnapshot as aN, type AfterToolCall as aO, type AssistantContent as aP, type BeforeToolCall as aQ, type EventBus as aR, type EventId as aS, type ExecOptions as aT, type ExecResult as aU, type ExtensionAPI as aV, type ExtensionAgentConsumerDisposer as aW, type ExtensionAgentsAPI as aX, type ExtensionCapabilityContribution as aY, type ExtensionContext as aZ, type ExtensionDisposer as a_, type ToolExecutionResult as aa, type Outcome as ab, type ConsumerRegistration as ac, type RetentionResult as ad, type ConfigProvider as ae, type ConfigurationSnapshot as af, type ConfigPutResult as ag, type ConfigResolution as ah, type PhaseRegistry as ai, type LoadedExtension as aj, type DefinitionLayer as ak, type ExtensionActivationError as al, type ExtensionActivationResult as am, type ExtensionContribution as an, ExtensionLifetimeError as ao, type ExtensionLifetimeErrorCode as ap, type ExtensionLoadInput as aq, type InteractionRecord as ar, type LoadExtensionsResult as as, type ModelRetry as at, type OpaqueId as au, type OwnerToken as av, type PhaseContribution as aw, type PhaseRegistrySelection as ax, type ResolvedResourceView as ay, type ResourceDiagnostic as az, type AgentRuntimeOptions as b, type ExtensionFactoryResult as b0, type ExtensionStateStore as b1, type ExtensionToolContribution as b2, type HookEvent as b3, type HookEventType as b4, type HookHandler as b5, type InternalModelLoopOptions as b6, type JsonPrimitive as b7, type LiveInteractionEvent as b8, type MessageBase as b9, type RunStateChanged as bA, type SettingsBadge as bB, type SettingsControl as bC, type SettingsDefinition as bD, type SettingsItem as bE, type SettingsOption as bF, type SettingsSection as bG, type SkillRegistration as bH, type TextContent as bI, type ThinkingContent as bJ, type ThinkingDelta as bK, type ToolCallContext as bL, type ToolCallDelta as bM, type ToolCallPhase as bN, type ToolCallPresentationInput as bO, type ToolCallPresentationOutput as bP, type ToolDefinition as bQ, type ToolInvocationContext as bR, type ToolMessage as bS, type ToolMessageContent as bT, type ToolResultContent as bU, type ToolStateChanged as bV, type ToolUseContent as bW, type UserMessage as bX, type WithdrawnUserInput as bY, type MessageCommitted as ba, type MessageContent as bb, type MessageDelta as bc, type MessageRevised as bd, type ModelInvokeOutput as be, type PhaseContext as bf, type PhaseExecution as bg, type PhaseExecutionIdentity as bh, type PhaseInput as bi, type PhaseInvocation as bj, type PhaseMessageManager as bk, type PhaseOutput as bl, type PhaseRegistration as bm, type PhaseRunHandler as bn, type PhaseState as bo, type PhaseStatus as bp, type PhaseStatusState as bq, type RunEndEvent as br, RunInteractionBoundary as bs, RunInteractionCancelledError as bt, type RunInteractionDriver as bu, type RunInteractionKind as bv, type RunInteractionRequest as bw, type RunInteractionState as bx, type RunInteractionStatus as by, type RunStartEvent as bz, type AgentDefinition as c, type LoadResult as d, type AgentConfiguration as e, type HistorySeed as f, type AgentId as g, type AgentDeletionRequest as h, type MessageId as i, type MessageRevisionResult as j, type RunId as k, type ToolCallId as l, type EventCursor as m, type UserInput as n, type AgentRun as o, type EntryPhaseSpec as p, type AgentListCursor as q, type Page as r, type AgentSummary as s, type RunState as t, type RunListCursor as u, type RunSummary as v, type InvocationCatalogEntry as w, type DurableConsumer as x, type ExtensionCapability as y, type RunSnapshot as z };