@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
@@ -22,3 +22,4 @@ export declare function browserPermissionModes(hosts?: PermissionRule[]): Permis
22
22
  export declare function rememberedPermissionsPath(home: string): string;
23
23
  export declare function loadRememberedPermissions(home: string, onWarning?: (message: string) => void): PermissionRule[];
24
24
  export declare function rememberAllow(home: string, permission: string, pattern: string): PermissionRule[];
25
+ export declare function forgetRemembered(home: string, permission: string, pattern: string): void;
@@ -1,12 +1,10 @@
1
1
  import { type AgentMessage, type Profile } from "../core/index.js";
2
- import { TodoStore } from "../sdk/index.js";
3
2
  import { type CommitLedger, type NotesStore } from "./agent/state.js";
4
3
  import { BrowserManager } from "./browser/manager.js";
5
4
  import { type BrowserProfileOptions, type ResolvedBrowserOptions } from "./config.js";
6
5
  export interface BrowserProfile extends Profile {
7
6
  browser: BrowserManager;
8
7
  config: ResolvedBrowserOptions;
9
- todos: TodoStore;
10
8
  notes: NotesStore;
11
9
  ledger: CommitLedger;
12
10
  }
@@ -2,33 +2,67 @@ import type { CheckpointDiffFile, CheckpointProvider } from "../core/index.js";
2
2
  export interface ShadowCheckpointOptions {
3
3
  root: string;
4
4
  shadowDir?: string;
5
+ home?: string;
5
6
  scope?: string;
6
7
  run?: GitRunner;
8
+ include?: string[];
9
+ coverage?: "full" | "declared";
7
10
  }
8
- export type GitRunner = (args: string[], env: Record<string, string>, cwd: string) => Promise<{
11
+ export interface GitRunOptions {
12
+ signal?: AbortSignal;
13
+ stdin?: string;
14
+ background?: boolean;
15
+ }
16
+ export type GitRunner = (args: string[], env: Record<string, string>, cwd: string, options?: GitRunOptions) => Promise<{
9
17
  stdout: string;
10
18
  stderr: string;
11
19
  exitCode: number;
12
20
  }>;
13
21
  export declare function gitConfigNullDevice(platform?: NodeJS.Platform): string;
22
+ export declare function partialCheckpointNotice(root: string, home?: string, run?: GitRunner): Promise<string | undefined>;
14
23
  export declare class ShadowCheckpointProvider implements CheckpointProvider {
24
+ readonly coverage: "full" | "declared";
15
25
  private readonly root;
16
26
  private readonly shadowDir;
17
27
  private readonly run;
18
28
  private readonly lockDir;
19
- private readonly excludedPathspecs;
29
+ private readonly excludedPrefixes;
30
+ private included;
20
31
  private initialized;
32
+ private lastMaintenance;
33
+ private maintenance;
21
34
  constructor(options: ShadowCheckpointOptions);
22
35
  get directory(): string;
36
+ get includedPaths(): string[];
37
+ setIncludedPaths(paths: string[]): void;
38
+ workspacePath(path: string): string;
39
+ private isIncluded;
23
40
  private env;
24
41
  private git;
42
+ private cancellableGit;
43
+ private workspaceGit;
44
+ private isExcluded;
25
45
  private acquireLock;
26
46
  private locked;
27
47
  private ensure;
28
- private ignoredDisposableDirectories;
29
- private checkpointPathspecs;
30
- snapshot(label?: string): Promise<string | undefined>;
48
+ private workspacePaths;
49
+ private updateIndex;
50
+ private stage;
51
+ snapshot(label?: string, signal?: AbortSignal): Promise<string | undefined>;
52
+ settled(): Promise<void>;
53
+ private startMaintenance;
54
+ private maintain;
55
+ private capture;
56
+ private commit;
57
+ snapshotResources(baseRef: string | undefined, resources: string[], label?: string): Promise<string | undefined>;
58
+ private captureResources;
59
+ private buildTree;
60
+ private recordedPaths;
61
+ private head;
62
+ private resourceScope;
63
+ private requireCheckpoints;
31
64
  restore(ref: string): Promise<void>;
65
+ private removeEmptyParents;
32
66
  restoreResources(ref: string, resources: string[]): Promise<void>;
33
67
  diff(fromRef: string, toRef?: string): Promise<CheckpointDiffFile[]>;
34
68
  }
@@ -2,6 +2,7 @@ import { type AgentMessage } from "../core/index.js";
2
2
  export declare const DEFAULT_PROJECT_ROOT_MARKERS: string[];
3
3
  export declare const DEFAULT_INSTRUCTION_FALLBACKS: string[];
4
4
  export declare const INSTRUCTION_PRIMARY_NAMES: string[];
5
+ export declare const SNAPSHOT_TYPE_PREFIX = "project-instructions-";
5
6
  export interface InstructionSettings {
6
7
  enabled?: boolean;
7
8
  fallbackFilenames?: string[];
@@ -1,5 +1,4 @@
1
1
  import { ProcessManager, type Profile } from "../core/index.js";
2
- import { TodoStore } from "../sdk/index.js";
3
2
  import { InstructionLoader, type InstructionSettings } from "./context.js";
4
3
  import { FileState } from "./state.js";
5
4
  import { bashTool } from "./tools/bash.js";
@@ -11,25 +10,24 @@ export interface CodingProfileOptions {
11
10
  home?: string;
12
11
  instructions?: InstructionSettings;
13
12
  managedInstructionPaths?: string[];
13
+ checkpoints?: boolean;
14
14
  }
15
15
  export interface CodingProfile extends Profile {
16
16
  fileState: FileState;
17
- todos: TodoStore;
18
17
  processes: ProcessManager;
19
18
  instructions: InstructionLoader;
20
19
  }
21
20
  export declare function codingProfile(options?: CodingProfileOptions): Promise<CodingProfile>;
22
- export type { TodoItem } from "../sdk/index.js";
23
- export { renderTodos, TodoStore, todoTool } from "../sdk/index.js";
24
21
  export type { GitRunner, ShadowCheckpointOptions } from "./checkpoint.js";
25
- export { gitConfigNullDevice, ShadowCheckpointProvider } from "./checkpoint.js";
22
+ export { gitConfigNullDevice, partialCheckpointNotice, ShadowCheckpointProvider, } from "./checkpoint.js";
26
23
  export { codingEnvironment, contextMessages, DEFAULT_INSTRUCTION_FALLBACKS, DEFAULT_PROJECT_ROOT_MARKERS, discoverContextFiles, environmentMessage, type InstructionDiagnostic, InstructionLoader, type InstructionLoaderOptions, type InstructionSettings, type InstructionSnapshot, type InstructionSource, } from "./context.js";
27
- export { CODING_PERMISSION_DEFAULTS, CODING_PERMISSION_MODES, layerPermissions, loadProjectConfig, rememberAllow, } from "./permissions.js";
24
+ export { CODING_PERMISSION_DEFAULTS, CODING_PERMISSION_MODES, codingPermissionModes, codingSideAccess, layerPermissions, loadProjectConfig, localConfigPath, rememberAllow, } from "./permissions.js";
28
25
  export { codingPrompt } from "./prompts.js";
29
26
  export { shellCommand, terminateProcessTree, windowsTaskkillCommand } from "./shell.js";
30
27
  export { classifyShellCommand, isInspectionShellCommand, parseInspectionCommands, type ShellCommandClassification, } from "./shell-inspection.js";
28
+ export { shellPermissionTargets } from "./shell-permissions.js";
31
29
  export { FileState } from "./state.js";
32
30
  export { bashTool } from "./tools/bash.js";
33
- export { editTool, lsTool, readTool, resolveInRoot, writeTool } from "./tools/files.js";
31
+ export { editPreviewProbe, editTool, lsTool, readTool, resolveInRoot, writeTool, } from "./tools/files.js";
34
32
  export { shellSpawner, taskTools } from "./tools/tasks.js";
35
33
  export { MAX_OUTPUT_CHARS, truncateOutput, withNotice } from "./truncate.js";
@@ -1,12 +1,19 @@
1
- import type { PermissionMode, PermissionRule } from "../core/index.js";
1
+ import type { PermissionMode, PermissionRule, ProfileSideAccess, SavedPermissionRule } from "../core/index.js";
2
2
  import { z } from "zod";
3
3
  import type { InstructionSettings } from "./context.js";
4
4
  export declare const CODING_PERMISSION_DEFAULTS: PermissionRule[];
5
+ export declare function codingPermissionModes(configured?: PermissionRule[]): PermissionMode[];
6
+ export declare function codingSideAccess(configured?: PermissionRule[]): ProfileSideAccess;
5
7
  export declare const CODING_PERMISSION_MODES: PermissionMode[];
6
8
  export interface ProjectConfig {
7
9
  permissions?: PermissionRule[];
8
10
  model?: string;
9
11
  instructions?: InstructionSettings;
12
+ checkpoints?: {
13
+ enabled?: boolean | undefined;
14
+ include?: string[] | undefined;
15
+ [key: string]: unknown;
16
+ };
10
17
  [key: string]: unknown;
11
18
  }
12
19
  export declare const instructionSettingsSchema: z.ZodObject<{
@@ -16,7 +23,16 @@ export declare const instructionSettingsSchema: z.ZodObject<{
16
23
  imports: z.ZodOptional<z.ZodBoolean>;
17
24
  claudeRules: z.ZodOptional<z.ZodBoolean>;
18
25
  }, z.core.$strip>;
26
+ export declare const checkpointSettingsSchema: z.ZodObject<{
27
+ enabled: z.ZodOptional<z.ZodBoolean>;
28
+ include: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ }, z.core.$loose>;
19
30
  export declare function configPath(root: string): string;
20
31
  export declare function loadProjectConfig(root: string, onWarning?: (message: string) => void): Promise<ProjectConfig>;
21
32
  export declare function layerPermissions(...layers: (PermissionRule[] | undefined)[]): PermissionRule[];
33
+ export declare function localConfigPath(root: string): string;
34
+ export declare function loadPermissionsFile(path: string, onWarning?: (message: string) => void): Promise<PermissionRule[]>;
22
35
  export declare function rememberAllow(root: string, permission: string, pattern: string): Promise<void>;
36
+ export declare function savedPermissions(paths: string[]): Promise<SavedPermissionRule[]>;
37
+ export declare function forgetPermission(rule: SavedPermissionRule): Promise<void>;
38
+ export declare function saveCheckpointIncludes(root: string, include: string[]): Promise<void>;
@@ -1,5 +1,4 @@
1
1
  import type { PromptSection } from "../ai/index.js";
2
- export declare const CODING_SIDE_BOUNDARY = "This is a coding side conversation. Do not modify files, source, git state, configuration, or workspace state unless the user deliberately changes the side conversation's permission mode. Do not request broader permissions or use subagents.";
3
- export declare const CODING_SEARCH_PROMPT = "Use rg and rg --files through bash for broad discovery, then use read offsets and limits to inspect only the relevant ranges. Do not read a whole file merely to inspect one symbol or range. Ground every finding in exact workspace-relative paths and 1-based line ranges. Distinguish observed code behavior from hypotheses.";
2
+ export declare const CODING_SIDE_BOUNDARY = "This is a read-only coding side conversation for answering questions about the session, the project and what the main agent is doing. You can read files, list directories, run read-only shell commands and read background task output; anything else is denied. When an answer needs a command that changes state or runs a build or tests, say so instead of attempting it.";
4
3
  export declare const CODING_COUNSEL_PROMPT = "Inspect the current implementation and tests before judging. Cite exact workspace-relative paths and 1-based line ranges for the evidence behind the recommendation.";
5
4
  export declare function codingPrompt(modelRef: string): PromptSection[];
@@ -0,0 +1,5 @@
1
+ import type { PermissionTarget } from "../core/index.js";
2
+ export declare function shellPermissionTargets(command: string, options?: {
3
+ background?: boolean;
4
+ platform?: NodeJS.Platform;
5
+ }): PermissionTarget[];
@@ -0,0 +1 @@
1
+ export declare function plainTerminalText(text: string): string;
@@ -1,4 +1,4 @@
1
- import { type ProcessManager } from "../../core/index.js";
1
+ import { type ManagedProcessHandle, type ProcessManager } from "../../core/index.js";
2
2
  type OutputStream = "stdout" | "stderr";
3
3
  type OutputChunk = (text: string, stream: OutputStream) => void;
4
4
  interface SpawnResult {
@@ -6,11 +6,16 @@ interface SpawnResult {
6
6
  stderr: string;
7
7
  exitCode: number | null;
8
8
  timedOut: boolean;
9
+ backgrounded?: boolean;
10
+ }
11
+ export interface BackgroundHandOff {
12
+ signal: AbortSignal;
13
+ adopt: (handle: ManagedProcessHandle) => (chunk: string) => void;
9
14
  }
10
15
  export interface BashDeps {
11
16
  root: string;
12
17
  processes?: ProcessManager;
13
- spawn?: (command: string, cwd: string, signal: AbortSignal, timeoutMs: number, onOutput?: OutputChunk) => Promise<SpawnResult>;
18
+ spawn?: (command: string, cwd: string, signal: AbortSignal, timeoutMs: number, onOutput?: OutputChunk, background?: BackgroundHandOff) => Promise<SpawnResult>;
14
19
  }
15
20
  export declare function bashTool(deps: BashDeps): import("../../sdk/index.js").Tool<{
16
21
  command: string;
@@ -0,0 +1,8 @@
1
+ import type { CheckpointDiffFile } from "../../core/index.js";
2
+ export declare function fileDiff(path: string, before: string | undefined, after: string): CheckpointDiffFile;
3
+ export interface Replacement {
4
+ start: number;
5
+ end: number;
6
+ newString: string;
7
+ }
8
+ export declare function replacementDiff(path: string, content: string, replacements: readonly Replacement[]): CheckpointDiffFile;
@@ -13,6 +13,7 @@ export interface ToolDeps {
13
13
  export declare function resolveInRoot(root: string, path: string): string;
14
14
  export declare function resolveExistingInRoot(root: string, path: string): Promise<string>;
15
15
  export declare function resolveForWriteInRoot(root: string, path: string): Promise<string>;
16
+ export declare function checkpointResource(root: string, path: string): string;
16
17
  export declare function filePermissionDiff(path: string, before: string | undefined, after: string): CheckpointDiffFile;
17
18
  export declare function readTool(deps: ToolDeps): import("../../sdk/index.js").Tool<{
18
19
  path: string;
@@ -23,6 +24,10 @@ export declare function writeTool(deps: ToolDeps): import("../../sdk/index.js").
23
24
  path: string;
24
25
  content: string;
25
26
  }>;
27
+ export declare function editPreviewProbe(root: string): {
28
+ occurrences(path: string, text: string): number | undefined;
29
+ exists(path: string): boolean | undefined;
30
+ };
26
31
  export declare function coerceEditInput(raw: unknown): unknown;
27
32
  export declare function editTool(deps: ToolDeps): import("../../sdk/index.js").Tool<{
28
33
  path: string;
@@ -1,8 +1,9 @@
1
1
  import { type ProcessManager, type Spawner } from "../../core/index.js";
2
2
  export declare function shellSpawner(root: string): Spawner;
3
- export declare function taskTools(manager: ProcessManager): (import("../../sdk/index.js").Tool<{
3
+ export declare function taskTools(manager: ProcessManager, waiting?: Map<string, number>): (import("../../sdk/index.js").Tool<{
4
4
  taskId: string;
5
5
  full?: boolean | undefined;
6
+ timeoutMs?: number | undefined;
6
7
  }> | import("../../sdk/index.js").Tool<{
7
8
  taskId: string;
8
9
  data: string;
@@ -0,0 +1,9 @@
1
+ import type { Command } from "../core/index.js";
2
+ import type { ShadowCheckpointProvider } from "./checkpoint.js";
3
+ export interface TrackCommandOptions {
4
+ root: string;
5
+ checkpoints?: ShadowCheckpointProvider;
6
+ unavailable?: string;
7
+ save?: (root: string, include: string[]) => Promise<void>;
8
+ }
9
+ export declare function trackCommands(options: TrackCommandOptions): Command[];
@@ -1,7 +1,8 @@
1
1
  import { type Credential, type ModelInfo, type PromptSection, type Provider, type ThinkingLevel, type Usage } from "../ai/index.js";
2
- import { type AgentEvent, type AgentMessage, type AnyTool, type CheckpointDiffFile, CheckpointHistory, type CheckpointProvider, type CustomMessage, type EventSink, type ExtensionHost, type PermissionRequest, type PermissionRule, type ProfileRuntime, type SessionStore, SessionTree, type UserContent } from "../core/index.js";
2
+ import { type AgentEvent, type AgentMessage, type AnyTool, type CheckpointDiffFile, CheckpointHistory, type CheckpointProvider, type CustomMessage, type EventSink, type ExtensionHost, type PermissionReply, type PermissionRequest, type PermissionRule, type ProfileRuntime, type SessionStore, SessionTree, type UserContent } from "../core/index.js";
3
3
  import type { z } from "zod";
4
4
  import { type Budget } from "./budget.js";
5
+ import { type CostReport, type ExternalUsageData, type UsageLine } from "./cost-report.js";
5
6
  export type HaltReason = "done" | "aborted" | "error" | "maxTurns" | "maxCostUsd" | "maxTokens";
6
7
  export interface AgentOptions {
7
8
  model?: string | ModelInfo;
@@ -9,7 +10,7 @@ export interface AgentOptions {
9
10
  systemPrompt?: string | PromptSection[];
10
11
  tools?: AnyTool[];
11
12
  permissions?: PermissionRule[];
12
- onPermission?: (request: PermissionRequest) => Promise<"allow" | "deny">;
13
+ onPermission?: (request: PermissionRequest) => Promise<PermissionReply>;
13
14
  budget?: Budget;
14
15
  session?: SessionStore;
15
16
  sessionId?: string;
@@ -28,8 +29,13 @@ export interface AgentOptions {
28
29
  imageRetentionTurns?: number;
29
30
  imageBudgetTokens?: number;
30
31
  checkpointProvider?: CheckpointProvider;
32
+ checkpointUnavailable?: string;
33
+ checkpointNotice?: string;
31
34
  runtime?: ProfileRuntime;
32
35
  extensions?: ExtensionHost;
36
+ toolNames?: string[];
37
+ extensionContext?: boolean;
38
+ contextLabel?: (customType: string) => string | undefined;
33
39
  }
34
40
  export interface RunResult {
35
41
  text: string;
@@ -37,6 +43,7 @@ export interface RunResult {
37
43
  usage: Usage;
38
44
  reason: HaltReason;
39
45
  sessionId: string;
46
+ error?: string;
40
47
  }
41
48
  export interface CheckpointActionData {
42
49
  kind: "checkpoint";
@@ -51,6 +58,17 @@ export interface CheckpointActionResult {
51
58
  message: string;
52
59
  data?: CheckpointActionData;
53
60
  }
61
+ export interface ForkPoint {
62
+ id: string;
63
+ prompt: string;
64
+ }
65
+ export interface ForkResult {
66
+ ok: boolean;
67
+ message: string;
68
+ sessionId?: string;
69
+ sourceSessionId?: string;
70
+ prompt?: string;
71
+ }
54
72
  export interface UndoPoint {
55
73
  steps: number;
56
74
  prompt: string;
@@ -69,6 +87,7 @@ export interface AgentRunOptions<T = unknown> {
69
87
  output?: z.ZodType<T>;
70
88
  model?: string | ModelInfo;
71
89
  allowedTools?: string[];
90
+ context?: CustomMessage[];
72
91
  }
73
92
  export interface ChildAgentOptions {
74
93
  model?: ModelInfo;
@@ -79,6 +98,12 @@ export interface ChildAgentOptions {
79
98
  budget?: Budget;
80
99
  inheritContext?: boolean;
81
100
  refreshContext?: AgentOptions["refreshContext"];
101
+ permissionLabel?: string | (() => string | undefined);
102
+ }
103
+ export interface BackgroundWork {
104
+ label: string;
105
+ done: Promise<unknown>;
106
+ stop: (reason: "user" | "session") => void;
82
107
  }
83
108
  export declare class Agent {
84
109
  private readonly options;
@@ -90,7 +115,11 @@ export declare class Agent {
90
115
  private controller;
91
116
  private steering;
92
117
  private followUps;
118
+ private notices;
119
+ private noticesHeld;
120
+ private heldPublished;
93
121
  private totals;
122
+ private ledger;
94
123
  private compactRequested;
95
124
  private compactRequestedFocus;
96
125
  private queuedManualCompactionFocus;
@@ -102,9 +131,14 @@ export declare class Agent {
102
131
  private lastContextUsage;
103
132
  private readonly checkpoints;
104
133
  private recoveryAttempted;
134
+ private turnRetries;
105
135
  private reactiveRecoveryPending;
106
136
  private pendingCheckpoint;
137
+ private readonly runningTasks;
138
+ private readonly backgroundCalls;
107
139
  private currentThinking;
140
+ private requestedThinking;
141
+ private readonly thinkingNotices;
108
142
  private running;
109
143
  private stopping;
110
144
  private activeEmit;
@@ -116,8 +150,14 @@ export declare class Agent {
116
150
  private shutdownPromise;
117
151
  private sessionStarted;
118
152
  private permissionRules;
153
+ private parentAgent;
154
+ private inheritsPermissions;
155
+ private readonly children;
156
+ private readonly background;
119
157
  constructor(options?: AgentOptions);
120
158
  get sessionId(): string;
159
+ get checkpointUnavailable(): string | undefined;
160
+ get checkpointNotice(): string | undefined;
121
161
  get usage(): Usage;
122
162
  get session(): SessionTree;
123
163
  get sessionStore(): SessionStore;
@@ -128,12 +168,25 @@ export declare class Agent {
128
168
  get thinkingLevels(): ThinkingLevel[];
129
169
  get isRunning(): boolean;
130
170
  get isCompacting(): boolean;
171
+ get isStopping(): boolean;
131
172
  get permissions(): PermissionRule[];
173
+ get waitingOnUser(): {
174
+ reason: string;
175
+ done: Promise<void>;
176
+ } | undefined;
177
+ get backgroundWork(): string[];
132
178
  get tools(): AnyTool[];
133
179
  availableModel(ref: string): ModelInfo | undefined;
134
180
  createChild(options: ChildAgentOptions): Agent;
135
181
  setPermissions(rules: PermissionRule[]): void;
136
182
  addPermissionRule(rule: PermissionRule): void;
183
+ chargeUsage(usage: Usage, lines?: UsageLine[]): void;
184
+ trackBackground(work: BackgroundWork): void;
185
+ stopBackgroundWork(label: string): boolean;
186
+ waitForSettled(): Promise<void>;
187
+ recordMessage(message: CustomMessage): Promise<void>;
188
+ recordExternalUsage(data: ExternalUsageData): Promise<void>;
189
+ costReport(): CostReport;
137
190
  setModel(ref: string | ModelInfo): void;
138
191
  refreshModelInfo(): boolean;
139
192
  setThinking(level: ThinkingLevel): void;
@@ -141,6 +194,10 @@ export declare class Agent {
141
194
  newSession(sessionId?: string): void;
142
195
  send(message: string): void;
143
196
  followUp(message: string | CustomMessage): void;
197
+ notify(message: CustomMessage): void;
198
+ private publishHeld;
199
+ private releaseHeld;
200
+ withdrawFollowUp(message: AgentMessage): boolean;
144
201
  removeQueuedMessage(kind: "steer" | "follow-up", text: string): boolean;
145
202
  emitTaskEvent(event: AgentEvent): void;
146
203
  subscribe(listener: EventSink): () => void;
@@ -149,22 +206,20 @@ export declare class Agent {
149
206
  stop(): void;
150
207
  shutdown(): Promise<void>;
151
208
  abort(): void;
209
+ get backgroundableCalls(): string[];
210
+ backgroundToolCalls(ids?: readonly string[]): string[];
152
211
  requestCompaction(focus?: string): void;
153
212
  compactNow(focus?: string): Promise<ManualCompactionResult>;
213
+ private releaseNotices;
154
214
  private executeManualCompaction;
155
215
  get checkpointHistory(): CheckpointHistory;
156
216
  undoPoints(): UndoPoint[];
157
217
  undo(turnCount?: number): Promise<CheckpointActionResult>;
158
218
  redo(): Promise<CheckpointActionResult>;
159
219
  sessionDiff(): Promise<Awaited<ReturnType<CheckpointProvider["diff"]>>>;
160
- forkPoints(): {
161
- id: string;
162
- description: string;
163
- }[];
164
- fork(entryId: string): Promise<{
165
- ok: boolean;
166
- message: string;
167
- }>;
220
+ forkPoints(): ForkPoint[];
221
+ createFork(beforeEntryId?: string): Promise<ForkResult>;
222
+ fork(beforeEntryId?: string): Promise<ForkResult>;
168
223
  get contextPercent(): number;
169
224
  get contextTokens(): number;
170
225
  run<T>(prompt: string | UserContent[], opts: AgentRunOptions<T> & {
@@ -179,13 +234,28 @@ export declare class Agent {
179
234
  private beginCheckpoint;
180
235
  private finishCheckpoint;
181
236
  private appendCheckpointCursor;
237
+ private captureCurrent;
182
238
  private restoreCheckpointResources;
183
239
  private checkpointDetails;
184
240
  private rebuildCheckpointHistory;
185
241
  private execute;
186
242
  private executeRun;
243
+ private runContextState;
244
+ private recordRunUsage;
245
+ private prepareRunContext;
246
+ private recoverRunError;
247
+ private finishRunTurn;
248
+ private summarize;
249
+ private appendCompactionAttempt;
187
250
  private compactionContextTokens;
188
251
  private providerFor;
252
+ private backgroundBlocker;
253
+ private effectivePermissionRules;
254
+ private stopBackground;
255
+ private combinedUsage;
256
+ private claimChildUsage;
257
+ private budgetBreach;
258
+ private budgetBreachWithChild;
189
259
  private resolveChildPermission;
190
260
  private publishEvent;
191
261
  private refreshContextAccounting;
@@ -1,9 +1,16 @@
1
- import type { Usage } from "../ai/index.js";
2
1
  import { type CheckpointDiffFile, type Command, CommandRegistry } from "../core/index.js";
3
- import type { CheckpointActionResult, ManualCompactionResult, UndoPoint } from "./agent.js";
4
- export interface ForkPoint {
5
- id: string;
6
- description: string;
2
+ import type { CheckpointActionResult, ForkPoint, ForkResult, ManualCompactionResult, UndoPoint } from "./agent.js";
3
+ import type { CostReport } from "./cost-report.js";
4
+ export type { ForkPoint } from "./agent.js";
5
+ export interface ForkPointsCommandData {
6
+ kind: "fork-points";
7
+ points: ForkPoint[];
8
+ }
9
+ export interface ForkedCommandData {
10
+ kind: "forked";
11
+ sessionId: string;
12
+ sourceSessionId: string;
13
+ prompt?: string;
7
14
  }
8
15
  export interface DiffCommandData {
9
16
  kind: "diff";
@@ -15,21 +22,14 @@ export interface UndoPointsCommandData {
15
22
  }
16
23
  export interface CoreCommandHooks {
17
24
  requestCompaction?: (focus?: string) => ManualCompactionResult | undefined | Promise<ManualCompactionResult | undefined>;
18
- usage?: () => Usage & {
19
- contextPercent: number;
20
- };
25
+ costReport?: () => CostReport;
21
26
  undo?: (turnCount?: number) => Promise<CheckpointActionResult>;
22
27
  undoPoints?: () => UndoPoint[];
23
28
  redo?: () => Promise<CheckpointActionResult>;
24
- fork?: (entryId: string) => Promise<{
25
- ok: boolean;
26
- message: string;
27
- }>;
29
+ fork?: (beforeEntryId?: string) => Promise<ForkResult>;
28
30
  forkPoints?: () => ForkPoint[];
29
31
  diff?: () => Promise<CheckpointDiffFile[]>;
32
+ checkpointUnavailable?: string;
30
33
  }
31
- export declare function formatUsageBreakdown(usage: Usage & {
32
- contextPercent: number;
33
- }): string;
34
34
  export declare function coreCommands(hooks?: CoreCommandHooks): Command[];
35
35
  export declare function registryWithCoreCommands(hooks?: CoreCommandHooks): CommandRegistry;
@@ -0,0 +1,64 @@
1
+ import { type PromptSection, type Usage } from "../ai/index.js";
2
+ import { type AgentMessage } from "../core/index.js";
3
+ export type UsageSource = "main" | "subagents" | "tools" | "compaction" | "other" | (string & {});
4
+ export interface UsageLine {
5
+ source: UsageSource;
6
+ model: string;
7
+ usage: Usage;
8
+ turns: number;
9
+ }
10
+ export interface ContextPart {
11
+ id: "system" | "tools" | "context" | "summary" | "messages" | "toolResults";
12
+ label: string;
13
+ tokens: number;
14
+ count?: number;
15
+ children?: {
16
+ id: string;
17
+ tokens: number;
18
+ }[];
19
+ }
20
+ export interface ContextBreakdown {
21
+ tokens: number;
22
+ window: number;
23
+ reported: boolean;
24
+ autoCompactAt: number;
25
+ parts: ContextPart[];
26
+ }
27
+ export interface CostReport {
28
+ kind: "cost";
29
+ totals: Usage;
30
+ lines: UsageLine[];
31
+ context: ContextBreakdown;
32
+ }
33
+ export declare class UsageLedger {
34
+ private lines;
35
+ add(line: UsageLine): void;
36
+ list(): UsageLine[];
37
+ clear(): void;
38
+ }
39
+ export declare function usageDelta(after: Usage, before: Usage): Usage;
40
+ export declare function attachedUsageLines(usage: Usage, details: unknown, fallbackModel: string): UsageLine[];
41
+ export interface ExternalUsageData {
42
+ source: UsageSource;
43
+ model: string;
44
+ usage: Usage;
45
+ turns: number;
46
+ }
47
+ export declare const EXTERNAL_USAGE_TYPE = "usage";
48
+ export declare function isExternalUsageData(value: unknown): value is ExternalUsageData;
49
+ export interface ContextBreakdownInput {
50
+ systemPrompt: PromptSection[];
51
+ tools: {
52
+ name: string;
53
+ description: string;
54
+ inputSchema: unknown;
55
+ }[];
56
+ messages: AgentMessage[];
57
+ compactions: number;
58
+ tokens: number;
59
+ window: number;
60
+ reported: boolean;
61
+ autoCompactAt: number;
62
+ label?: (customType: string) => string | undefined;
63
+ }
64
+ export declare function contextBreakdown(input: ContextBreakdownInput): ContextBreakdown;
@@ -5,11 +5,14 @@ export interface FileSessionStoreOptions {
5
5
  }
6
6
  export declare class FileSessionStore implements SessionStore {
7
7
  private readonly dir;
8
+ private readonly written;
9
+ private readonly queue;
8
10
  constructor(options?: FileSessionStoreOptions);
9
11
  private path;
10
12
  private fallbackId;
11
13
  load(sessionId: string): Promise<SessionTree | undefined>;
12
14
  save(sessionId: string, tree: SessionTree): Promise<void>;
15
+ private write;
13
16
  list(): Promise<string[]>;
14
17
  delete(sessionId: string): Promise<boolean>;
15
18
  }