@mu-agent/mu 0.2.4 → 0.3.1

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.
Files changed (63) hide show
  1. package/README.md +24 -14
  2. package/dist/index.js +358 -285
  3. package/dist/mu.js +553 -450
  4. package/dist/types/ai/errors.d.ts +2 -0
  5. package/dist/types/ai/index.d.ts +5 -4
  6. package/dist/types/ai/json.d.ts +11 -0
  7. package/dist/types/ai/provider-config.d.ts +2 -0
  8. package/dist/types/ai/providers/citation-markup.d.ts +12 -0
  9. package/dist/types/ai/providers/inception.d.ts +3 -0
  10. package/dist/types/ai/retry.d.ts +7 -0
  11. package/dist/types/ai/sse.d.ts +2 -1
  12. package/dist/types/ai/thinking.d.ts +2 -0
  13. package/dist/types/ai/types.d.ts +5 -0
  14. package/dist/types/core/checkpoint.d.ts +4 -1
  15. package/dist/types/core/commands.d.ts +6 -1
  16. package/dist/types/core/events.d.ts +37 -0
  17. package/dist/types/core/extensions.d.ts +10 -1
  18. package/dist/types/core/index.d.ts +6 -5
  19. package/dist/types/core/loop.d.ts +9 -9
  20. package/dist/types/core/messages.d.ts +3 -1
  21. package/dist/types/core/permission.d.ts +28 -1
  22. package/dist/types/core/process.d.ts +13 -2
  23. package/dist/types/core/profile.d.ts +18 -2
  24. package/dist/types/core/session.d.ts +5 -0
  25. package/dist/types/core/testing/fake-provider.d.ts +3 -1
  26. package/dist/types/core/tools.d.ts +6 -2
  27. package/dist/types/core/wire.d.ts +16 -0
  28. package/dist/types/profile-browser/actions/input.d.ts +1 -0
  29. package/dist/types/profile-browser/agent/handoff.d.ts +6 -1
  30. package/dist/types/profile-browser/agent/permissions.d.ts +1 -0
  31. package/dist/types/profile-browser/index.d.ts +0 -2
  32. package/dist/types/profile-coding/checkpoint.d.ts +39 -5
  33. package/dist/types/profile-coding/context.d.ts +1 -0
  34. package/dist/types/profile-coding/index.d.ts +5 -7
  35. package/dist/types/profile-coding/permissions.d.ts +17 -1
  36. package/dist/types/profile-coding/prompts.d.ts +1 -2
  37. package/dist/types/profile-coding/shell-permissions.d.ts +5 -0
  38. package/dist/types/profile-coding/terminal-text.d.ts +1 -0
  39. package/dist/types/profile-coding/tools/bash.d.ts +7 -2
  40. package/dist/types/profile-coding/tools/diff.d.ts +8 -0
  41. package/dist/types/profile-coding/tools/files.d.ts +5 -0
  42. package/dist/types/profile-coding/tools/tasks.d.ts +2 -1
  43. package/dist/types/profile-coding/track-commands.d.ts +9 -0
  44. package/dist/types/sdk/agent.d.ts +80 -10
  45. package/dist/types/sdk/commands.d.ts +15 -15
  46. package/dist/types/sdk/cost-report.d.ts +64 -0
  47. package/dist/types/sdk/file-store.d.ts +3 -0
  48. package/dist/types/sdk/index.d.ts +18 -14
  49. package/dist/types/sdk/markdown-commands.d.ts +3 -1
  50. package/dist/types/sdk/mcp-catalog.d.ts +36 -0
  51. package/dist/types/sdk/mcp-config.d.ts +61 -0
  52. package/dist/types/sdk/mcp.d.ts +12 -18
  53. package/dist/types/sdk/permission-gate.d.ts +15 -0
  54. package/dist/types/sdk/recall.d.ts +1 -1
  55. package/dist/types/sdk/session-replacements.d.ts +21 -0
  56. package/dist/types/sdk/side.d.ts +1 -0
  57. package/dist/types/sdk/skills.d.ts +57 -5
  58. package/dist/types/sdk/structured-output.d.ts +8 -1
  59. package/dist/types/sdk/subagents.d.ts +53 -5
  60. package/dist/types/sdk/tool.d.ts +5 -1
  61. package/dist/types/sdk/turn-changes.d.ts +18 -0
  62. package/package.json +1 -1
  63. package/dist/types/sdk/todo.d.ts +0 -16
@@ -1,4 +1,5 @@
1
1
  export type AiErrorKind = "auth" | "rate_limit" | "overloaded" | "context_too_long" | "bad_request" | "not_found" | "network" | "api";
2
+ export declare function isRetryableErrorKind(kind: string | undefined): boolean;
2
3
  export declare class AiError extends Error {
3
4
  readonly kind: AiErrorKind;
4
5
  readonly status?: number;
@@ -11,3 +12,4 @@ export declare class AiError extends Error {
11
12
  }
12
13
  export declare function isContextTooLongMessage(message: string): boolean;
13
14
  export declare function classifyHttpError(status: number, body: string, headers: Headers): AiError;
15
+ export declare function classifyStreamError(payload: unknown, raw: string): AiError;
@@ -3,22 +3,23 @@ export type { ModelDiscoveryOptions } from "./catalog.js";
3
3
  export { defaultModelId, defaultModelRef, discoverModels, findModel, listModels, modelRef, providerHasCredentials, refreshModels, registerModels, } from "./catalog.js";
4
4
  export { addUsage, computeCostUsd, zeroUsage } from "./cost.js";
5
5
  export type { AiErrorKind } from "./errors.js";
6
- export { AiError, classifyHttpError, isContextTooLongMessage } from "./errors.js";
7
- export { parseJsonWithRepair, parsePartialJson, repairJson, salvageToolArgs } from "./json.js";
6
+ export { AiError, classifyHttpError, classifyStreamError, isContextTooLongMessage, isRetryableErrorKind, } from "./errors.js";
7
+ export { parseJsonWithRepair, parsePartialJson, repairJson, StreamingToolArgs, salvageToolArgs, } from "./json.js";
8
8
  export { builtinProviderConfigs, modelApi, providerBaseUrl, providerConfig, providerEnvVars, } from "./provider-config.js";
9
9
  export { anthropic, streamAnthropic } from "./providers/anthropic.js";
10
10
  export { gemini, streamGemini } from "./providers/gemini.js";
11
11
  export { discoverGitHubCopilotModels } from "./providers/github-copilot.js";
12
+ export { discoverInceptionModels, inceptionProvider } from "./providers/inception.js";
12
13
  export { discoverLlamaCppModels, llamaCpp } from "./providers/llama-cpp.js";
13
14
  export { discoverOpenAICodexModels, openai, openaiCodex, streamOpenAI, } from "./providers/openai.js";
14
15
  export { openaiCompletions, streamOpenAICompletions } from "./providers/openai-completions.js";
15
16
  export { getProvider, providers, registerProvider } from "./registry.js";
16
17
  export type { RetryOpts } from "./retry.js";
17
- export { withRetries } from "./retry.js";
18
+ export { MAX_TURN_RETRIES, MAX_TURN_RETRY_DELAY_MS, sleep, turnRetryDelayMs, withRetries, } from "./retry.js";
18
19
  export type { SseEvent } from "./sse.js";
19
20
  export { iterateSse } from "./sse.js";
20
21
  export { AssistantStream, EventStream } from "./stream.js";
21
22
  export type { Cassette, RecordedInteraction, ReplayCall, ReplayHandle } from "./testing/replay.js";
22
23
  export { recordFetch, replayFetch } from "./testing/replay.js";
23
- export { defaultThinkingLevel, supportedThinkingLevels, thinkingLevelForModel, } from "./thinking.js";
24
+ export { defaultThinkingLevel, supportedThinkingLevels, THINKING_EFFORTS, thinkingEffort, thinkingLevelForModel, } from "./thinking.js";
24
25
  export * from "./types.js";
@@ -2,3 +2,14 @@ export declare function repairJson(json: string): string;
2
2
  export declare function parseJsonWithRepair<T = unknown>(json: string): T;
3
3
  export declare function parsePartialJson(text: string): unknown;
4
4
  export declare function salvageToolArgs(partialJson: string | undefined): Record<string, unknown>;
5
+ export declare class StreamingToolArgs {
6
+ private readonly now;
7
+ private text;
8
+ private value;
9
+ private parsedAt;
10
+ private costMs;
11
+ constructor(now?: () => number);
12
+ get json(): string;
13
+ append(fragment: string): Record<string, unknown>;
14
+ finish(json?: string): Record<string, unknown>;
15
+ }
@@ -7,9 +7,11 @@ export interface BuiltinProviderConfig {
7
7
  env: string[];
8
8
  auth?: "bearer" | "anthropic" | "google" | "azure" | "cloudflare" | "none";
9
9
  headers?: Record<string, string>;
10
+ cacheBreakpoints?: true | string;
10
11
  }
11
12
  export declare const builtinProviderConfigs: Map<string, BuiltinProviderConfig>;
12
13
  export declare function providerConfig(id: string): BuiltinProviderConfig | undefined;
14
+ export declare function usesCacheBreakpoints(model: ModelInfo): boolean;
13
15
  export declare function modelApi(model: ModelInfo): LlmApi;
14
16
  export declare function providerBaseUrl(model: ModelInfo): string | undefined;
15
17
  export declare function providerEnvVars(provider: string): readonly string[];
@@ -0,0 +1,12 @@
1
+ export declare class CitationMarkupFilter {
2
+ private held;
3
+ private consumed;
4
+ private emitted;
5
+ private dropSpace;
6
+ private readonly removed;
7
+ push(delta: string): string;
8
+ flush(): string;
9
+ mapIndex(raw: number): number;
10
+ private emit;
11
+ }
12
+ export declare function stripCitationMarkup(text: string): string;
@@ -0,0 +1,3 @@
1
+ import type { ModelInfo, Provider, ProviderModelDiscoveryOptions } from "../types.js";
2
+ export declare function discoverInceptionModels(options: ProviderModelDiscoveryOptions): Promise<ModelInfo[] | undefined>;
3
+ export declare const inceptionProvider: Provider;
@@ -1,6 +1,13 @@
1
+ export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
1
2
  export interface RetryOpts {
2
3
  maxRetries?: number;
3
4
  maxRetryDelayMs?: number;
4
5
  signal?: AbortSignal;
5
6
  }
6
7
  export declare function withRetries<T>(request: () => Promise<T>, opts?: RetryOpts): Promise<T>;
8
+ export declare const MAX_TURN_RETRIES = 4;
9
+ export declare const MAX_TURN_RETRY_DELAY_MS: number;
10
+ export declare function turnRetryDelayMs(failure: {
11
+ errorKind?: string;
12
+ retryAfterMs?: number;
13
+ }, attempt: number): number | undefined;
@@ -2,4 +2,5 @@ export interface SseEvent {
2
2
  event: string | null;
3
3
  data: string;
4
4
  }
5
- export declare function iterateSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseEvent>;
5
+ export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
6
+ export declare function iterateSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal, idleTimeoutMs?: number): AsyncGenerator<SseEvent>;
@@ -1,4 +1,6 @@
1
1
  import type { ModelInfo, ThinkingLevel } from "./types.js";
2
2
  export declare function supportedThinkingLevels(model: ModelInfo): ThinkingLevel[];
3
3
  export declare function defaultThinkingLevel(model: ModelInfo): ThinkingLevel;
4
+ export declare const THINKING_EFFORTS: readonly ThinkingLevel[];
5
+ export declare function thinkingEffort(level: ThinkingLevel): number | undefined;
4
6
  export declare function thinkingLevelForModel(model: ModelInfo, requested: ThinkingLevel | undefined): ThinkingLevel;
@@ -1,3 +1,4 @@
1
+ import type { AiErrorKind } from "./errors.js";
1
2
  export interface TextContent {
2
3
  type: "text";
3
4
  text: string;
@@ -71,6 +72,8 @@ export interface AssistantMessage {
71
72
  usage: Usage;
72
73
  stopReason: StopReason;
73
74
  errorMessage?: string;
75
+ errorKind?: AiErrorKind;
76
+ retryAfterMs?: number;
74
77
  timestamp: number;
75
78
  }
76
79
  export interface ToolResultMessage {
@@ -130,6 +133,7 @@ export interface ModelInfo {
130
133
  defaultThinkingLevel?: ThinkingLevel;
131
134
  thinkingMode?: "adaptive" | "budget";
132
135
  pricing: ModelPricing;
136
+ inferred?: boolean;
133
137
  }
134
138
  export type ThinkingLevel = "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | (string & {});
135
139
  export type Credential = {
@@ -160,6 +164,7 @@ export interface StreamOpts {
160
164
  thinkingLevel?: ThinkingLevel;
161
165
  signal?: AbortSignal;
162
166
  maxRetries?: number;
167
+ idleTimeoutMs?: number;
163
168
  headers?: Record<string, string>;
164
169
  fetch?: typeof fetch;
165
170
  }
@@ -3,9 +3,12 @@ export interface CheckpointDiffFile {
3
3
  added: number;
4
4
  removed: number;
5
5
  hunks: string[];
6
+ approximate?: boolean;
6
7
  }
7
8
  export interface CheckpointProvider {
8
- snapshot(label?: string): Promise<string | undefined>;
9
+ readonly coverage?: "full" | "declared";
10
+ snapshot(label?: string, signal?: AbortSignal): Promise<string | undefined>;
11
+ snapshotResources?(baseRef: string | undefined, resources: string[], label?: string): Promise<string | undefined>;
9
12
  restore(ref: string): Promise<void>;
10
13
  restoreResources?(ref: string, resources: string[]): Promise<void>;
11
14
  diff(fromRef: string, toRef?: string): Promise<CheckpointDiffFile[]>;
@@ -5,6 +5,7 @@ export interface CommandContext {
5
5
  print: (text: string) => void;
6
6
  getModel: () => string;
7
7
  setModel: (ref: string) => void;
8
+ isRunning?: () => boolean;
8
9
  }
9
10
  export interface CommandResult {
10
11
  handled: boolean;
@@ -14,13 +15,17 @@ export interface CommandResult {
14
15
  export interface Command {
15
16
  name: string;
16
17
  description: string;
17
- sessionScoped?: boolean;
18
+ side?: boolean;
19
+ fallback?: boolean;
20
+ kind?: "skill";
21
+ hidden?: () => boolean;
18
22
  run: (ctx: CommandContext) => CommandResult | void | Promise<CommandResult | void>;
19
23
  }
20
24
  export declare class CommandRegistry {
21
25
  private commands;
22
26
  register(command: Command): void;
23
27
  get(name: string): Command | undefined;
28
+ all(): Command[];
24
29
  list(): Command[];
25
30
  has(name: string): boolean;
26
31
  parse(input: string): {
@@ -24,6 +24,8 @@ export type StreamDelta = {
24
24
  } | {
25
25
  kind: "toolcall_start";
26
26
  contentIndex: number;
27
+ toolCallId?: string;
28
+ toolName?: string;
27
29
  } | {
28
30
  kind: "toolcall_delta";
29
31
  contentIndex: number;
@@ -32,6 +34,8 @@ export type StreamDelta = {
32
34
  kind: "toolcall_end";
33
35
  contentIndex: number;
34
36
  toolCallId: string;
37
+ toolName?: string;
38
+ args?: Record<string, unknown>;
35
39
  };
36
40
  export type AgentEndReason = "done" | "aborted" | "budget" | "maxTurns" | "error";
37
41
  export type CompactionTrigger = "manual" | "threshold" | "overflow" | "model-change";
@@ -72,6 +76,7 @@ export type AgentEvent = {
72
76
  toolCallId: string;
73
77
  toolName: string;
74
78
  args: unknown;
79
+ backgroundable?: true;
75
80
  } | {
76
81
  type: "tool_execution_update";
77
82
  toolCallId: string;
@@ -123,6 +128,7 @@ export type AgentEvent = {
123
128
  taskId: string;
124
129
  command: string;
125
130
  background: boolean;
131
+ startedAt?: number;
126
132
  } | {
127
133
  type: "task_output";
128
134
  taskId: string;
@@ -132,6 +138,37 @@ export type AgentEvent = {
132
138
  taskId: string;
133
139
  exitCode: number | null;
134
140
  status?: "exited" | "killed";
141
+ } | {
142
+ type: "provider_retry";
143
+ attempt: number;
144
+ maxAttempts: number;
145
+ delayMs: number;
146
+ errorMessage: string;
147
+ } | {
148
+ type: "notices_held";
149
+ count: number;
150
+ } | {
151
+ type: "thinking_adjusted";
152
+ model: string;
153
+ requested: string;
154
+ level: string;
155
+ inferredModel?: boolean;
156
+ } | {
157
+ type: "subagent_started";
158
+ subagentId: string;
159
+ toolCallId: string;
160
+ kind: string;
161
+ description: string;
162
+ } | {
163
+ type: "subagent_progress";
164
+ subagentId: string;
165
+ details: unknown;
166
+ } | {
167
+ type: "subagent_ended";
168
+ subagentId: string;
169
+ status: "done" | "error" | "stopped";
170
+ content: ToolResultContent[];
171
+ details?: unknown;
135
172
  } | {
136
173
  type: "usage_updated";
137
174
  sessionTotals: Usage;
@@ -1,7 +1,7 @@
1
1
  import type { ModelInfo, Provider } from "../ai/index.js";
2
2
  import { type Command, CommandRegistry } from "./commands.js";
3
3
  import type { AgentEvent } from "./events.js";
4
- import type { AgentMessage } from "./messages.js";
4
+ import type { AgentMessage, CustomMessage } from "./messages.js";
5
5
  import type { AnyTool, ToolResult } from "./tools.js";
6
6
  export interface ToolCallDirective {
7
7
  block?: boolean;
@@ -15,6 +15,7 @@ export interface ToolResultDirective {
15
15
  export interface InputDirective {
16
16
  consume?: boolean;
17
17
  text?: string;
18
+ context?: CustomMessage[];
18
19
  }
19
20
  export interface ToolCallHookInfo {
20
21
  toolName: string;
@@ -53,11 +54,15 @@ export interface ToolRenderer {
53
54
  result?: ToolResult;
54
55
  }) => string[];
55
56
  }
57
+ export type ContextProvider = (messages: AgentMessage[], context: {
58
+ sessionId: string;
59
+ }) => AgentMessage[] | Promise<AgentMessage[]>;
56
60
  export interface ExtensionAPI {
57
61
  on<T extends ExtensionEventType>(event: T, handler: (event: ExtensionEventFor<T>) => void): void;
58
62
  onToolCall(handler: (info: ToolCallHookInfo) => ToolCallDirective | undefined | Promise<ToolCallDirective | undefined>): void;
59
63
  onToolResult(handler: (info: ToolResultHookInfo) => ToolResultDirective | undefined | Promise<ToolResultDirective | undefined>): void;
60
64
  onContext(handler: (messages: AgentMessage[]) => AgentMessage[] | Promise<AgentMessage[]>): void;
65
+ registerContextProvider(provider: ContextProvider): void;
61
66
  onInput(handler: (text: string) => InputDirective | undefined | Promise<InputDirective | undefined>): void;
62
67
  registerTool(tool: AnyTool): void;
63
68
  registerCommand(command: Command): void;
@@ -83,6 +88,7 @@ export declare class ExtensionHost {
83
88
  private toolCallHooks;
84
89
  private toolResultHooks;
85
90
  private contextHooks;
91
+ private contextProviders;
86
92
  private inputHooks;
87
93
  register(extension: Extension): Promise<void>;
88
94
  shutdown(): Promise<void>;
@@ -92,6 +98,9 @@ export declare class ExtensionHost {
92
98
  runToolCallHooks(info: ToolCallHookInfo): Promise<ToolCallDirective | undefined>;
93
99
  runToolResultHooks(info: ToolResultHookInfo): Promise<ToolResultDirective | undefined>;
94
100
  runContextHooks(messages: AgentMessage[]): Promise<AgentMessage[]>;
101
+ runContextProviders(messages: AgentMessage[], context: {
102
+ sessionId: string;
103
+ }): Promise<AgentMessage[]>;
95
104
  runInputHooks(text: string): Promise<InputDirective | undefined>;
96
105
  get hasContextHooks(): boolean;
97
106
  }
@@ -5,7 +5,7 @@ export { CommandRegistry } from "./commands.js";
5
5
  export type { CompactionPlan, CompactionRequest, CompactionResult, CompactorOptions, ContextState, } from "./compaction.js";
6
6
  export { AUTO_COMPACT_THRESHOLD, applyCompaction, CompactionError, compact, compactionSummaryMessage, contextState, DEFAULT_KEEP_RECENT_TOKENS, estimateTextTokens, estimateTokens, formatCarryover, planCompaction, SUMMARY_PROMPT, serializeCompactionMessages, shouldCompact, } from "./compaction.js";
7
7
  export type { AgentEndReason, AgentEvent, AgentEventType, CompactionProgress, CompactionStage, CompactionTrigger, EventSink, StreamDelta, } from "./events.js";
8
- export type { Extension, ExtensionAPI, ExtensionEvent, ExtensionEventFor, ExtensionEventType, InputDirective, LifecycleEvent, LifecycleNotification, ToolCallDirective, ToolCallHookInfo, ToolRenderer, ToolResultDirective, ToolResultHookInfo, } from "./extensions.js";
8
+ export type { ContextProvider, Extension, ExtensionAPI, ExtensionEvent, ExtensionEventFor, ExtensionEventType, InputDirective, LifecycleEvent, LifecycleNotification, ToolCallDirective, ToolCallHookInfo, ToolRenderer, ToolResultDirective, ToolResultHookInfo, } from "./extensions.js";
9
9
  export { ExtensionHost } from "./extensions.js";
10
10
  export type { AfterToolCallInfo, AgentContext, AgentRunResult, BeforeToolCallInfo, ContextPreparation, LoopConfig, NextTurnDirective, TurnInfo, } from "./loop.js";
11
11
  export { AgentEventStream, runAgent, runLoop } from "./loop.js";
@@ -14,14 +14,15 @@ export * from "./messages.js";
14
14
  export { customMessage, isCustomMessage, renderCustomMessage, toAiMessages, userMessage, } from "./messages.js";
15
15
  export type { MicrocompactionOptions, MicrocompactionResult } from "./microcompaction.js";
16
16
  export { IMAGE_TOMBSTONE, MICROCOMPACT_THRESHOLD, microcompact, SUPERSEDE_WITHIN_TURNS, TOMBSTONE, } from "./microcompaction.js";
17
- export type { PermissionAction, PermissionField, PermissionPreview, PermissionRequest, PermissionRule, PermissionSection, ToolPermissionDetails, } from "./permission.js";
18
- export { evaluate, permissionPreviewLines } from "./permission.js";
17
+ export type { PermissionAction, PermissionField, PermissionPreview, PermissionReply, PermissionRequest, PermissionRule, PermissionSection, PermissionTarget, SavedPermissionRule, ToolPermissionDetails, } from "./permission.js";
18
+ export { evaluate, evaluateTargets, permissionOutcome, permissionPreviewLines, } from "./permission.js";
19
19
  export type { ManagedProcessHandle, ProcessEvents, Spawner, SpawnRequest, TaskInfo, TaskStatus, } from "./process.js";
20
20
  export { exitNotification, OutputBuffer, ProcessManager } from "./process.js";
21
- export type { PermissionMode, PermissionModeTone, Profile, ProfileFactory, ProfileRuntime, ProfileRuntimeHost, ProfileSubagents, TaskSubagentSession, } from "./profile.js";
21
+ export type { PermissionMode, PermissionModeTone, Profile, ProfileFactory, ProfileRuntime, ProfileRuntimeHost, ProfileSideAccess, ProfileSubagents, TaskSubagentSession, } from "./profile.js";
22
22
  export type { RecoveryAttempt } from "./recovery.js";
23
23
  export { isContextTooLongError, isContextTooLongResult, withContextRecovery, } from "./recovery.js";
24
24
  export type { NewTreeEntry, SessionEntry, SessionStore, TreeEntry } from "./session.js";
25
25
  export { isTreeEntry, MemorySessionStore, newEntryId, parseEntry, parseSession, SESSION_VERSION, SessionTree, serializeEntry, serializeSession, } from "./session.js";
26
26
  export type { AnyTool, Tool, ToolResult } from "./tools.js";
27
- export { concurrencySafe, errorResult, textResult } from "./tools.js";
27
+ export { canBackground, concurrencySafe, errorResult, textResult } from "./tools.js";
28
+ export { toWireEvent, type WireAgentEvent, WireEventDecoder } from "./wire.js";
@@ -34,6 +34,12 @@ export interface ContextPreparation {
34
34
  messages: AgentMessage[];
35
35
  stop?: boolean;
36
36
  }
37
+ export interface BeforeToolCallDirective {
38
+ block?: boolean;
39
+ denied?: boolean;
40
+ reason?: string;
41
+ rewrittenArgs?: Record<string, unknown>;
42
+ }
37
43
  export interface LoopConfig {
38
44
  provider: Provider;
39
45
  model: ModelInfo;
@@ -42,21 +48,15 @@ export interface LoopConfig {
42
48
  maxTurns?: number;
43
49
  getSteeringMessages?: () => AgentMessage[] | Promise<AgentMessage[]>;
44
50
  getFollowUpMessages?: () => AgentMessage[] | Promise<AgentMessage[]>;
45
- beforeToolCall?: (info: BeforeToolCallInfo, signal: AbortSignal) => {
46
- block?: boolean;
47
- reason?: string;
48
- rewrittenArgs?: Record<string, unknown>;
49
- } | undefined | Promise<{
50
- block?: boolean;
51
- reason?: string;
52
- rewrittenArgs?: Record<string, unknown>;
53
- } | undefined>;
51
+ getNotices?: () => AgentMessage[] | Promise<AgentMessage[]>;
52
+ beforeToolCall?: (info: BeforeToolCallInfo, signal: AbortSignal) => BeforeToolCallDirective | undefined | Promise<BeforeToolCallDirective | undefined>;
54
53
  afterToolCall?: (info: AfterToolCallInfo, signal: AbortSignal) => ToolResult | undefined | Promise<ToolResult | undefined>;
55
54
  shouldStopAfterTurn?: (turn: TurnInfo) => boolean | Promise<boolean>;
56
55
  recoverFromError?: (message: AssistantMessage) => boolean | Promise<boolean>;
57
56
  prepareNextTurn?: (turn: TurnInfo) => NextTurnDirective | undefined | Promise<NextTurnDirective | undefined>;
58
57
  prepareContext?: (messages: AgentMessage[]) => ContextPreparation | AgentMessage[] | Promise<ContextPreparation | AgentMessage[]>;
59
58
  transformContext?: (messages: AgentMessage[]) => AgentMessage[] | Promise<AgentMessage[]>;
59
+ backgroundCalls?: Map<string, AbortController>;
60
60
  }
61
61
  export interface AgentRunResult {
62
62
  messages: AgentMessage[];
@@ -1,4 +1,4 @@
1
- import type { AiMessage, AssistantMessage, ImageContent, TextContent, ToolResultMessage, UserMessage } from "../ai/index.js";
1
+ import type { AiMessage, AssistantMessage, ImageContent, TextContent, ToolResultMessage, Usage, UserMessage } from "../ai/index.js";
2
2
  export type { AssistantContent, AssistantMessage, ImageContent, StopReason, TextContent, ThinkingContent, ToolCallContent, ToolResultContent, ToolResultMessage, Usage, UserContent, UserMessage, WebSearchAction, WebSearchCitation, WebSearchContent, } from "../ai/index.js";
3
3
  export interface CustomMessage {
4
4
  role: "custom";
@@ -8,6 +8,8 @@ export interface CustomMessage {
8
8
  retention?: {
9
9
  key: string;
10
10
  };
11
+ details?: unknown;
12
+ usage?: Usage;
11
13
  timestamp: number;
12
14
  }
13
15
  export type AgentMessage = UserMessage | AssistantMessage | ToolResultMessage | CustomMessage;
@@ -5,6 +5,9 @@ export interface PermissionRule {
5
5
  pattern: string;
6
6
  action: PermissionAction;
7
7
  }
8
+ export interface SavedPermissionRule extends PermissionRule {
9
+ source: string;
10
+ }
8
11
  export interface PermissionRequest {
9
12
  id: string;
10
13
  toolCallId: string;
@@ -13,6 +16,24 @@ export interface PermissionRequest {
13
16
  pattern: string;
14
17
  description: string;
15
18
  preview?: PermissionPreview;
19
+ allowRules?: {
20
+ permission: string;
21
+ pattern: string;
22
+ }[];
23
+ }
24
+ export type PermissionReply = "allow" | "deny" | {
25
+ outcome: "allow" | "deny";
26
+ message?: string | undefined;
27
+ };
28
+ export declare function permissionOutcome(reply: PermissionReply): {
29
+ outcome: "allow" | "deny";
30
+ message?: string;
31
+ };
32
+ export interface PermissionTarget {
33
+ permission?: string;
34
+ pattern: string;
35
+ exact?: boolean;
36
+ remember?: string;
16
37
  }
17
38
  export type PermissionPreview = {
18
39
  kind: "text";
@@ -37,4 +58,10 @@ export interface ToolPermissionDetails {
37
58
  description?: string;
38
59
  preview?: PermissionPreview;
39
60
  }
40
- export declare function evaluate(rules: PermissionRule[], permission: string | readonly string[], pattern: string): PermissionAction;
61
+ export declare function evaluate(rules: PermissionRule[], permission: string | readonly string[], pattern: string, options?: {
62
+ exact?: boolean | undefined;
63
+ }): PermissionAction;
64
+ export declare function evaluateTargets(rules: PermissionRule[], toolName: string, targets: readonly PermissionTarget[]): {
65
+ action: PermissionAction;
66
+ asked: PermissionTarget[];
67
+ };
@@ -1,5 +1,6 @@
1
1
  export interface ManagedProcessHandle {
2
2
  write: (data: string) => void;
3
+ acceptsInput?: boolean;
3
4
  resize: (cols: number, rows: number) => void;
4
5
  detach: () => void;
5
6
  kill: () => void;
@@ -23,6 +24,7 @@ export interface TaskInfo {
23
24
  outputBytes: number;
24
25
  truncated: boolean;
25
26
  detached: boolean;
27
+ acceptsInput?: false;
26
28
  }
27
29
  export declare class OutputBuffer {
28
30
  private headLimit;
@@ -59,10 +61,19 @@ export declare class ProcessManager {
59
61
  cols?: number;
60
62
  rows?: number;
61
63
  }): TaskInfo;
64
+ adopt(command: string, handle: ManagedProcessHandle, options: {
65
+ startedAt: number;
66
+ output?: string;
67
+ }): {
68
+ task: TaskInfo;
69
+ onOutput: (chunk: string) => void;
70
+ };
71
+ private prepare;
72
+ private register;
62
73
  get(id: string): TaskInfo | undefined;
63
74
  list(): TaskInfo[];
64
75
  get runningCount(): number;
65
- output(id: string, since?: "start" | "new"): {
76
+ output(id: string, since?: "start" | "new" | "peek"): {
66
77
  text: string;
67
78
  truncated: boolean;
68
79
  } | undefined;
@@ -76,4 +87,4 @@ export declare class ProcessManager {
76
87
  private requestStops;
77
88
  wait(id: string): Promise<TaskInfo | undefined>;
78
89
  }
79
- export declare function exitNotification(task: TaskInfo): string;
90
+ export declare function exitNotification(task: TaskInfo, stoppedByUser?: boolean): string;
@@ -4,7 +4,7 @@ import type { Command } from "./commands.js";
4
4
  import type { AgentEvent } from "./events.js";
5
5
  import type { ToolRenderer } from "./extensions.js";
6
6
  import type { AgentMessage, CustomMessage } from "./messages.js";
7
- import type { PermissionRule } from "./permission.js";
7
+ import type { PermissionRule, SavedPermissionRule } from "./permission.js";
8
8
  import type { AnyTool } from "./tools.js";
9
9
  export type PermissionModeTone = "restrictive" | "permissive" | "unrestricted";
10
10
  export interface PermissionMode {
@@ -17,10 +17,17 @@ export interface PermissionMode {
17
17
  export interface ProfileRuntimeHost {
18
18
  emit: (event: AgentEvent) => void;
19
19
  followUp: (message: string | CustomMessage) => void;
20
+ notify?: (message: CustomMessage) => void;
21
+ record?: (message: CustomMessage) => void;
20
22
  }
21
23
  export interface ProfileRuntime {
22
24
  attach: (host: ProfileRuntimeHost) => void;
23
25
  resize?: (cols: number, rows: number) => void;
26
+ stopTask?: (taskId: string) => boolean;
27
+ waitingOnUser?: () => {
28
+ reason: string;
29
+ done: Promise<void>;
30
+ } | undefined;
24
31
  stop?: () => void;
25
32
  shutdown?: () => void | Promise<void>;
26
33
  }
@@ -33,10 +40,13 @@ export interface TaskSubagentSession {
33
40
  export interface ProfileSubagents {
34
41
  taskSession?: (description: string, signal: AbortSignal) => Promise<TaskSubagentSession>;
35
42
  inspectionTools: string[];
36
- searchPrompt?: string;
37
43
  counselPrompt?: string;
38
44
  recallScope?: Record<string, string>;
39
45
  }
46
+ export interface ProfileSideAccess {
47
+ tools: string[];
48
+ permissions: PermissionRule[];
49
+ }
40
50
  export interface Profile {
41
51
  name: string;
42
52
  toolset: AnyTool[];
@@ -45,11 +55,15 @@ export interface Profile {
45
55
  permissionModes?: PermissionMode[];
46
56
  defaultPermissionMode?: string;
47
57
  rememberPermission?: (permission: string, pattern: string) => void | Promise<void>;
58
+ savedPermissions?: () => SavedPermissionRule[] | Promise<SavedPermissionRule[]>;
59
+ forgetPermission?: (rule: SavedPermissionRule) => void | Promise<void>;
48
60
  renderers?: Record<string, ToolRenderer>;
49
61
  commands?: Command[];
50
62
  environment?: () => Promise<Record<string, string>> | Record<string, string>;
51
63
  contextMessages?: () => Promise<AgentMessage[]> | AgentMessage[];
52
64
  sideBoundary?: () => string;
65
+ sideAccess?: ProfileSideAccess;
66
+ contextLabel?: (customType: string) => string | undefined;
53
67
  subagents?: ProfileSubagents;
54
68
  refreshContext?: (messages: AgentMessage[], context: {
55
69
  sessionId: string;
@@ -57,6 +71,8 @@ export interface Profile {
57
71
  diagnostics?: string[];
58
72
  carryoverExtractor?: (messages: AgentMessage[]) => unknown;
59
73
  checkpointProvider?: CheckpointProvider;
74
+ checkpointUnavailable?: string;
75
+ checkpointNotice?: string;
60
76
  runtime?: ProfileRuntime;
61
77
  scope?: () => Promise<string> | string;
62
78
  }
@@ -8,6 +8,10 @@ export type SessionEntry = {
8
8
  profile: string;
9
9
  environment: Record<string, string>;
10
10
  title?: string;
11
+ forkedFrom?: {
12
+ sessionId: string;
13
+ entryId: string | null;
14
+ };
11
15
  } | {
12
16
  type: "message";
13
17
  id: string;
@@ -94,6 +98,7 @@ export declare class SessionTree {
94
98
  type: "session";
95
99
  });
96
100
  static fromJsonl(jsonl: string): SessionTree;
101
+ clone(): SessionTree;
97
102
  toJsonl(): string;
98
103
  get header(): (SessionEntry & {
99
104
  type: "session";
@@ -1,8 +1,10 @@
1
- import { type AssistantContent, AssistantStream, type LlmContext, type ModelInfo, type Provider, type StopReason, type StreamOpts, type Usage } from "../../ai/index.js";
1
+ import { type AiErrorKind, type AssistantContent, AssistantStream, type LlmContext, type ModelInfo, type Provider, type StopReason, type StreamOpts, type Usage } from "../../ai/index.js";
2
2
  export interface ScriptedTurn {
3
3
  content: AssistantContent[];
4
4
  stopReason?: StopReason;
5
5
  errorMessage?: string;
6
+ errorKind?: AiErrorKind;
7
+ retryAfterMs?: number;
6
8
  usage?: Partial<Usage>;
7
9
  delayMs?: number;
8
10
  }
@@ -1,5 +1,5 @@
1
1
  import type { ToolResultContent, Usage } from "../ai/index.js";
2
- import type { ToolPermissionDetails } from "./permission.js";
2
+ import type { PermissionTarget, ToolPermissionDetails } from "./permission.js";
3
3
  export interface ToolResult {
4
4
  content: ToolResultContent[];
5
5
  details?: unknown;
@@ -19,12 +19,16 @@ export interface Tool<Args = Record<string, unknown>> {
19
19
  isConcurrencySafe?: (args: Args) => boolean;
20
20
  executionMode?: "sequential";
21
21
  changesState?: boolean | ((args: Args) => boolean);
22
+ changedResources?: (args: Args) => string[];
22
23
  permissionScope?: (args: Args) => string;
23
24
  permissionPattern?: (args: Args) => string;
25
+ permissionTargets?: (args: Args) => PermissionTarget[];
24
26
  permissionDetails?: (args: Args) => ToolPermissionDetails | undefined | Promise<ToolPermissionDetails | undefined>;
25
- execute: (toolCallId: string, args: Args, signal: AbortSignal, onUpdate?: (partial: ToolResultContent[], details?: unknown) => void) => Promise<ToolResult>;
27
+ canBackground?: (args: Args) => boolean;
28
+ execute: (toolCallId: string, args: Args, signal: AbortSignal, onUpdate?: (partial: ToolResultContent[], details?: unknown) => void, background?: AbortSignal) => Promise<ToolResult>;
26
29
  }
27
30
  export type AnyTool = Tool<any>;
28
31
  export declare function errorResult(message: string): ToolResult;
29
32
  export declare function textResult(text: string): ToolResult;
33
+ export declare function canBackground(tool: AnyTool, args: unknown): boolean;
30
34
  export declare function concurrencySafe(tool: AnyTool, args: unknown): boolean;
@@ -0,0 +1,16 @@
1
+ import { type AssistantMessage } from "../ai/index.js";
2
+ import type { AgentEvent, StreamDelta } from "./events.js";
3
+ export type WireAgentEvent = Exclude<AgentEvent, {
4
+ type: "message_update";
5
+ }> | {
6
+ type: "message_update";
7
+ delta: StreamDelta;
8
+ message?: AssistantMessage;
9
+ };
10
+ export declare function toWireEvent(event: AgentEvent): WireAgentEvent;
11
+ export declare class WireEventDecoder {
12
+ private partial;
13
+ private args;
14
+ decode(event: WireAgentEvent): AgentEvent;
15
+ private apply;
16
+ }
@@ -5,6 +5,7 @@ export interface TypeOptions {
5
5
  submit?: boolean;
6
6
  keystrokes?: boolean;
7
7
  settle?: boolean;
8
+ choosing?: boolean;
8
9
  }
9
10
  export declare function typeText(ctx: ActionContext, ref: string, text: string, options?: TypeOptions): Promise<ActionResult>;
10
11
  export declare function pressKeys(ctx: ActionContext, keys: string, ref?: string): Promise<ActionResult>;
@@ -5,10 +5,15 @@ export declare class Handoffs {
5
5
  private readonly pollMs;
6
6
  private host;
7
7
  private timer;
8
+ private waiting;
8
9
  constructor(pollMs?: number);
9
10
  attach(host: ProfileRuntimeHost): void;
11
+ get pending(): {
12
+ reason: string;
13
+ done: Promise<void>;
14
+ } | undefined;
10
15
  start(tab: Tab, reason: string): void;
11
- cancel(): void;
16
+ cancel(settle?: boolean): void;
12
17
  }
13
18
  export declare function handoffTool(browser: BrowserManager, handoffs: Handoffs): import("../../sdk/index.js").Tool<{
14
19
  reason: string;