@mu-agent/mu 0.0.1 → 0.0.3

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.
@@ -19,4 +19,5 @@ export { iterateSse } from "./sse.js";
19
19
  export { AssistantStream, EventStream } from "./stream.js";
20
20
  export type { Cassette, RecordedInteraction, ReplayCall, ReplayHandle } from "./testing/replay.js";
21
21
  export { recordFetch, replayFetch } from "./testing/replay.js";
22
+ export { defaultThinkingLevel, supportedThinkingLevels, thinkingLevelForModel, } from "./thinking.js";
22
23
  export * from "./types.js";
@@ -0,0 +1,4 @@
1
+ import type { ModelInfo, ThinkingLevel } from "./types.js";
2
+ export declare function supportedThinkingLevels(model: ModelInfo): ThinkingLevel[];
3
+ export declare function defaultThinkingLevel(model: ModelInfo): ThinkingLevel;
4
+ export declare function thinkingLevelForModel(model: ModelInfo, requested: ThinkingLevel | undefined): ThinkingLevel;
@@ -89,10 +89,12 @@ export interface ModelInfo {
89
89
  maxOutput: number;
90
90
  modalities: ("text" | "image")[];
91
91
  thinking?: boolean;
92
+ thinkingLevels?: ThinkingLevel[];
93
+ defaultThinkingLevel?: ThinkingLevel;
92
94
  thinkingMode?: "adaptive" | "budget";
93
95
  pricing: ModelPricing;
94
96
  }
95
- export type ThinkingLevel = "off" | "low" | "medium" | "high";
97
+ export type ThinkingLevel = "off" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | (string & {});
96
98
  export type Credential = {
97
99
  type: "apiKey";
98
100
  apiKey: string;
@@ -14,6 +14,12 @@ export interface CompactionRequest {
14
14
  keepFromIndex: number;
15
15
  carryover?: unknown;
16
16
  }
17
+ export interface CompactionPlan {
18
+ keepFromIndex: number;
19
+ keptTokens: number;
20
+ isSplitTurn: boolean;
21
+ turnStartIndex: number | null;
22
+ }
17
23
  export interface CompactionResult {
18
24
  summary: string;
19
25
  carryover?: unknown;
@@ -26,15 +32,16 @@ export declare class CompactionError extends Error {
26
32
  readonly usage?: Usage | undefined;
27
33
  constructor(message: string, usage?: Usage | undefined);
28
34
  }
29
- export declare function planCompaction(messages: AgentMessage[], keepRatio?: number): {
30
- keepFromIndex: number;
31
- };
35
+ export declare const DEFAULT_KEEP_RECENT_TOKENS = 20000;
36
+ export declare function planCompaction(messages: AgentMessage[], keepRecentTokens?: number): CompactionPlan;
32
37
  export declare const SUMMARY_PROMPT = "Summarize the conversation so far so that work can continue without the original transcript.\n\nPreserve, in this order:\n1. What the user asked for \u2014 the goal, in their terms, including any constraints they stated.\n2. Decisions taken and why, including approaches tried and rejected.\n3. Current task state: what is done, what is in progress, what remains.\n4. Concrete facts discovered that would be expensive to rediscover (file locations, API shapes, error messages, command invocations that work).\n5. Anything the user corrected you on.\n\nBe specific and factual. Do not include pleasantries or narration. This summary replaces the transcript, so anything you omit is lost.";
38
+ export declare function serializeCompactionMessages(messages: AgentMessage[]): string;
33
39
  export interface CompactorOptions {
34
40
  provider: Provider;
35
41
  model: ModelInfo;
36
42
  carryoverExtractor?: (messages: AgentMessage[]) => unknown;
37
- keepRatio?: number;
43
+ keepRecentTokens?: number;
44
+ customInstructions?: string;
38
45
  signal?: AbortSignal;
39
46
  streamOpts?: StreamOpts;
40
47
  }
@@ -34,6 +34,8 @@ export type StreamDelta = {
34
34
  toolCallId: string;
35
35
  };
36
36
  export type AgentEndReason = "done" | "aborted" | "budget" | "maxTurns" | "error";
37
+ export type CompactionTrigger = "manual" | "threshold" | "overflow" | "model-change";
38
+ export type CompactionStage = "clearing-tool-output" | "summarizing" | "installing";
37
39
  export type AgentEvent = {
38
40
  type: "agent_start";
39
41
  } | {
@@ -80,11 +82,25 @@ export type AgentEvent = {
80
82
  } | {
81
83
  type: "compaction_start";
82
84
  layer: 1 | 2 | 3;
85
+ trigger?: CompactionTrigger;
86
+ contextTokensBefore?: number;
87
+ } | {
88
+ type: "compaction_update";
89
+ layer: 1 | 2 | 3;
90
+ stage: CompactionStage;
91
+ toolResultsCleared?: number;
83
92
  } | {
84
93
  type: "compaction_end";
85
94
  layer: 1 | 2 | 3;
86
95
  tokensFreed: number;
87
96
  summaryEntryId?: string;
97
+ trigger?: CompactionTrigger;
98
+ status?: "completed" | "failed" | "cancelled" | "noop";
99
+ contextTokensBefore?: number;
100
+ contextTokensAfter?: number;
101
+ toolResultsCleared?: number;
102
+ keptTokens?: number;
103
+ errorMessage?: string;
88
104
  } | {
89
105
  type: "task_started";
90
106
  taskId: string;
@@ -2,9 +2,9 @@ export type { CheckpointDiffFile, CheckpointEntry, CheckpointProvider, } from ".
2
2
  export { CheckpointHistory } from "./checkpoint.js";
3
3
  export type { Command, CommandContext, CommandResult } from "./commands.js";
4
4
  export { CommandRegistry } from "./commands.js";
5
- export type { CompactionRequest, CompactionResult, CompactorOptions, ContextState, } from "./compaction.js";
6
- export { AUTO_COMPACT_THRESHOLD, applyCompaction, CompactionError, compact, compactionSummaryMessage, contextState, estimateTokens, formatCarryover, planCompaction, SUMMARY_PROMPT, shouldCompact, } from "./compaction.js";
7
- export type { AgentEndReason, AgentEvent, AgentEventType, EventSink, StreamDelta, } from "./events.js";
5
+ export type { CompactionPlan, CompactionRequest, CompactionResult, CompactorOptions, ContextState, } from "./compaction.js";
6
+ export { AUTO_COMPACT_THRESHOLD, applyCompaction, CompactionError, compact, compactionSummaryMessage, contextState, DEFAULT_KEEP_RECENT_TOKENS, estimateTokens, formatCarryover, planCompaction, SUMMARY_PROMPT, serializeCompactionMessages, shouldCompact, } from "./compaction.js";
7
+ export type { AgentEndReason, AgentEvent, AgentEventType, CompactionStage, CompactionTrigger, EventSink, StreamDelta, } from "./events.js";
8
8
  export type { 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";
@@ -18,7 +18,7 @@ export type { PermissionAction, PermissionPreview, PermissionRequest, Permission
18
18
  export { evaluate } 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, Profile, ProfileFactory, ProfileRuntime, ProfileRuntimeHost, } from "./profile.js";
21
+ export type { PermissionMode, PermissionModeTone, Profile, ProfileFactory, ProfileRuntime, ProfileRuntimeHost, } 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";
@@ -9,6 +9,7 @@ export interface PermissionRequest {
9
9
  id: string;
10
10
  toolCallId: string;
11
11
  toolName: string;
12
+ permission: string;
12
13
  pattern: string;
13
14
  description: string;
14
15
  preview?: PermissionPreview;
@@ -24,4 +25,4 @@ export interface ToolPermissionDetails {
24
25
  description?: string;
25
26
  preview?: PermissionPreview;
26
27
  }
27
- export declare function evaluate(rules: PermissionRule[], permission: string, pattern: string): PermissionAction;
28
+ export declare function evaluate(rules: PermissionRule[], permission: string | readonly string[], pattern: string): PermissionAction;
@@ -6,10 +6,12 @@ import type { ToolRenderer } from "./extensions.js";
6
6
  import type { AgentMessage } from "./messages.js";
7
7
  import type { PermissionRule } from "./permission.js";
8
8
  import type { AnyTool } from "./tools.js";
9
+ export type PermissionModeTone = "restrictive" | "permissive" | "unrestricted";
9
10
  export interface PermissionMode {
10
11
  id: string;
11
12
  label: string;
12
13
  description: string;
14
+ tone?: PermissionModeTone;
13
15
  rules: PermissionRule[];
14
16
  }
15
17
  export interface ProfileRuntimeHost {
@@ -1,4 +1,4 @@
1
- import type { AgentMessage } from "./messages.js";
1
+ import type { AgentMessage, Usage } from "./messages.js";
2
2
  export declare const SESSION_VERSION = 1;
3
3
  export type SessionEntry = {
4
4
  type: "session";
@@ -21,6 +21,16 @@ export type SessionEntry = {
21
21
  carryover?: unknown;
22
22
  firstKeptEntryId: string | null;
23
23
  timestamp?: number;
24
+ trigger?: "manual" | "threshold" | "overflow" | "model-change";
25
+ contextTokensBefore?: number;
26
+ contextTokensAfter?: number;
27
+ model?: string;
28
+ compactorModel?: string;
29
+ windowNumber?: number;
30
+ strategy?: "summary-tail";
31
+ keptTokens?: number;
32
+ toolResultsCleared?: number;
33
+ usage?: Usage;
24
34
  } | {
25
35
  type: "microcompaction";
26
36
  id: string;
@@ -13,6 +13,8 @@ export interface Tool<Args = Record<string, unknown>> {
13
13
  isConcurrencySafe?: (args: Args) => boolean;
14
14
  executionMode?: "sequential";
15
15
  changesState?: boolean | ((args: Args) => boolean);
16
+ permissionScope?: (args: Args) => string;
17
+ permissionPattern?: (args: Args) => string;
16
18
  permissionDetails?: (args: Args) => ToolPermissionDetails | undefined | Promise<ToolPermissionDetails | undefined>;
17
19
  execute: (toolCallId: string, args: Args, signal: AbortSignal, onUpdate?: (partial: ToolResultContent[]) => void) => Promise<ToolResult>;
18
20
  }
@@ -22,6 +22,8 @@ export declare class ShadowCheckpointProvider implements CheckpointProvider {
22
22
  private env;
23
23
  private git;
24
24
  private ensure;
25
+ private ignoredDisposableDirectories;
26
+ private checkpointPathspecs;
25
27
  snapshot(label?: string): Promise<string | undefined>;
26
28
  restore(ref: string): Promise<void>;
27
29
  restoreResources(ref: string, resources: string[]): Promise<void>;
@@ -25,6 +25,7 @@ export { codingEnvironment, contextMessages, DEFAULT_INSTRUCTION_FALLBACKS, DEFA
25
25
  export { CODING_PERMISSION_DEFAULTS, CODING_PERMISSION_MODES, layerPermissions, loadProjectConfig, rememberAllow, } from "./permissions.js";
26
26
  export { codingPrompt } from "./prompts.js";
27
27
  export { shellCommand, terminateProcessTree, windowsTaskkillCommand } from "./shell.js";
28
+ export { classifyShellCommand, isInspectionShellCommand, parseInspectionCommands, type ShellCommandClassification, } from "./shell-inspection.js";
28
29
  export { FileState } from "./state.js";
29
30
  export { bashTool } from "./tools/bash.js";
30
31
  export { editTool, lsTool, readTool, resolveInRoot, writeTool } from "./tools/files.js";
@@ -0,0 +1,4 @@
1
+ export type ShellCommandClassification = "inspect" | "other";
2
+ export declare function parseInspectionCommands(source: string): string[][] | undefined;
3
+ export declare function classifyShellCommand(command: string): ShellCommandClassification;
4
+ export declare function isInspectionShellCommand(command: string): boolean;
@@ -21,11 +21,14 @@ export declare function writeTool(deps: ToolDeps): import("../../sdk/index.js").
21
21
  path: string;
22
22
  content: string;
23
23
  }>;
24
+ export declare function coerceEditInput(raw: unknown): unknown;
24
25
  export declare function editTool(deps: ToolDeps): import("../../sdk/index.js").Tool<{
25
26
  path: string;
26
- oldString: string;
27
- newString: string;
28
- replaceAll?: boolean | undefined;
27
+ edits: {
28
+ oldString: string;
29
+ newString: string;
30
+ replaceAll?: boolean | undefined;
31
+ }[];
29
32
  }>;
30
33
  export declare function lsTool(deps: ToolDeps): import("../../sdk/index.js").Tool<{
31
34
  path?: string | undefined;
@@ -46,6 +46,15 @@ export interface CheckpointActionResult {
46
46
  message: string;
47
47
  data?: CheckpointActionData;
48
48
  }
49
+ export interface ManualCompactionResult {
50
+ status: "completed" | "queued" | "failed" | "cancelled" | "noop";
51
+ message: string;
52
+ tokensBefore?: number;
53
+ tokensAfter?: number;
54
+ tokensFreed?: number;
55
+ toolResultsCleared?: number;
56
+ summaryEntryId?: string;
57
+ }
49
58
  export interface AgentRunOptions<T = unknown> {
50
59
  output?: z.ZodType<T>;
51
60
  model?: string | ModelInfo;
@@ -63,7 +72,13 @@ export declare class Agent {
63
72
  private followUps;
64
73
  private totals;
65
74
  private compactRequested;
75
+ private compactRequestedFocus;
76
+ private queuedManualCompactionFocus;
77
+ private manualCompactionQueued;
78
+ private compacting;
79
+ private compactorOverride;
66
80
  private lastContextPercent;
81
+ private lastContextTokens;
67
82
  private lastContextUsage;
68
83
  private readonly checkpoints;
69
84
  private recoveryAttempted;
@@ -88,7 +103,9 @@ export declare class Agent {
88
103
  get modelRef(): string;
89
104
  get contextWindow(): number;
90
105
  get thinking(): ThinkingLevel;
106
+ get thinkingLevels(): ThinkingLevel[];
91
107
  get isRunning(): boolean;
108
+ get isCompacting(): boolean;
92
109
  get permissions(): PermissionRule[];
93
110
  setPermissions(rules: PermissionRule[]): void;
94
111
  addPermissionRule(rule: PermissionRule): void;
@@ -106,7 +123,9 @@ export declare class Agent {
106
123
  stop(): void;
107
124
  shutdown(): Promise<void>;
108
125
  abort(): void;
109
- requestCompaction(): void;
126
+ requestCompaction(focus?: string): void;
127
+ compactNow(focus?: string): Promise<ManualCompactionResult>;
128
+ private executeManualCompaction;
110
129
  get checkpointHistory(): CheckpointHistory;
111
130
  undo(): Promise<CheckpointActionResult>;
112
131
  redo(): Promise<CheckpointActionResult>;
@@ -120,6 +139,7 @@ export declare class Agent {
120
139
  message: string;
121
140
  }>;
122
141
  get contextPercent(): number;
142
+ get contextTokens(): number;
123
143
  run<T>(prompt: string | UserContent[], opts: AgentRunOptions<T> & {
124
144
  output: z.ZodType<T>;
125
145
  }): Promise<RunResult & {
@@ -138,7 +158,10 @@ export declare class Agent {
138
158
  private execute;
139
159
  private executeRun;
140
160
  private providerFor;
161
+ private publishEvent;
162
+ private refreshContextAccounting;
141
163
  private publishToSubscribers;
142
164
  private scheduleAutonomousRun;
165
+ private scheduleManualCompaction;
143
166
  private resolveIdleIfDone;
144
167
  }
@@ -1,6 +1,6 @@
1
1
  import { type Usage } from "../ai/index.js";
2
2
  import { type CheckpointDiffFile, type Command, CommandRegistry } from "../core/index.js";
3
- import type { CheckpointActionResult } from "./agent.js";
3
+ import type { CheckpointActionResult, ManualCompactionResult } from "./agent.js";
4
4
  export interface ForkPoint {
5
5
  id: string;
6
6
  description: string;
@@ -10,7 +10,7 @@ export interface DiffCommandData {
10
10
  files: CheckpointDiffFile[];
11
11
  }
12
12
  export interface CoreCommandHooks {
13
- requestCompaction?: () => void;
13
+ requestCompaction?: (focus?: string) => ManualCompactionResult | undefined | Promise<ManualCompactionResult | undefined>;
14
14
  usage?: () => Usage & {
15
15
  contextPercent: number;
16
16
  };
@@ -1,8 +1,8 @@
1
1
  export type { Credential, ModelDiscoveryOptions, ModelInfo, Provider, ProviderModelDiscoveryOptions, ThinkingLevel, Usage, } from "../ai/index.js";
2
- export { builtinProviderConfigs, defaultModelRef, discoverModels, findModel, listModels, providerHasCredentials, refreshModels, registerModels, registerProvider, } from "../ai/index.js";
3
- export type { AgentEvent, AgentMessage, AnyTool, Command, CommandContext, CommandResult, CustomMessage, Extension, ExtensionAPI, ExtensionEvent, ExtensionEventFor, ExtensionEventType, LifecycleEvent, LifecycleNotification, PermissionMode, PermissionRequest, PermissionRule, ProfileRuntime, ProfileRuntimeHost, SessionStore, StreamDelta, Tool, ToolRenderer, UserContent, } from "../core/index.js";
2
+ export { builtinProviderConfigs, defaultModelRef, defaultThinkingLevel, discoverModels, findModel, listModels, providerHasCredentials, refreshModels, registerModels, registerProvider, supportedThinkingLevels, thinkingLevelForModel, } from "../ai/index.js";
3
+ export type { AgentEvent, AgentMessage, AnyTool, Command, CommandContext, CommandResult, CustomMessage, Extension, ExtensionAPI, ExtensionEvent, ExtensionEventFor, ExtensionEventType, LifecycleEvent, LifecycleNotification, PermissionMode, PermissionModeTone, PermissionRequest, PermissionRule, ProfileRuntime, ProfileRuntimeHost, SessionStore, StreamDelta, Tool, ToolRenderer, UserContent, } from "../core/index.js";
4
4
  export { CommandRegistry, customMessage, ExtensionHost, errorResult, MemorySessionStore, SessionTree, textResult, userMessage, } from "../core/index.js";
5
- export type { AgentOptions, AgentRunOptions, CheckpointActionData, CheckpointActionResult, HaltReason, RunResult, } from "./agent.js";
5
+ export type { AgentOptions, AgentRunOptions, CheckpointActionData, CheckpointActionResult, HaltReason, ManualCompactionResult, RunResult, } from "./agent.js";
6
6
  export { Agent } from "./agent.js";
7
7
  export type { AuthFile, AuthStoreOptions, OpenAiCallbackServer, OpenAiLoginOptions, OpenAiLoginResult, PlanLoginCallbackServer, PlanLoginOptions, PlanLoginResult, StoredApiKey, StoredCredential, StoredOpenAiOAuth, StoredPlanOAuth, } from "./auth.js";
8
8
  export { createCredentialResolver, defaultAuthFile, loginGitHubCopilot, loginKimiCoding, loginOpenAI, loginOpenRouter, loginXai, preferredAuthProvider, readAuthFile, removeStoredCredential, saveApiKey, storedAuthProviders, } from "./auth.js";
@@ -29,3 +29,5 @@ export { defaultSkillRoots, discoverSkills, loadSkill, skillListing, skillsExten
29
29
  export { STRUCTURED_OUTPUT_TOOL, structuredOutputPrompt, structuredOutputTool, } from "./structured-output.js";
30
30
  export type { ToolDefinition, ToolResult } from "./tool.js";
31
31
  export { tool } from "./tool.js";
32
+ export type { MarkdownTranscript, TranscriptMarkdownOptions, } from "./transcript-markdown.js";
33
+ export { sessionToMarkdown } from "./transcript-markdown.js";
@@ -5,9 +5,12 @@ export interface ToolDefinition<Schema extends z.ZodType> {
5
5
  name: string;
6
6
  description: string;
7
7
  inputSchema: Schema;
8
+ coerceInput?: (raw: unknown) => unknown;
8
9
  isConcurrencySafe?: (args: z.infer<Schema>) => boolean;
9
10
  executionMode?: "sequential";
10
11
  changesState?: boolean | ((args: z.infer<Schema>) => boolean);
12
+ permissionScope?: (args: z.infer<Schema>) => string;
13
+ permissionPattern?: (args: z.infer<Schema>) => string;
11
14
  permissionDetails?: (args: z.infer<Schema>) => ToolPermissionDetails | undefined | Promise<ToolPermissionDetails | undefined>;
12
15
  execute: (args: z.infer<Schema>, ctx: {
13
16
  toolCallId: string;
@@ -0,0 +1,11 @@
1
+ import type { SessionTree } from "../core/index.js";
2
+ export interface TranscriptMarkdownOptions {
3
+ sessionId?: string;
4
+ model?: string;
5
+ exportedAt?: Date;
6
+ }
7
+ export interface MarkdownTranscript {
8
+ markdown: string;
9
+ messageCount: number;
10
+ }
11
+ export declare function sessionToMarkdown(session: SessionTree, options?: TranscriptMarkdownOptions): MarkdownTranscript;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-agent/mu",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Mu, a general-purpose extensible AI agent platform for the terminal and TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -64,9 +64,9 @@
64
64
  "registry": "https://registry.npmjs.org/"
65
65
  },
66
66
  "devDependencies": {
67
- "@mu/profile-coding": "0.0.1",
68
- "@mu/tui": "0.0.1",
69
- "mu": "0.0.1",
70
- "@mu/core": "0.0.1"
67
+ "@mu/profile-coding": "workspace:*",
68
+ "@mu/tui": "workspace:*",
69
+ "mu": "workspace:*",
70
+ "@mu/core": "workspace:*"
71
71
  }
72
72
  }
@@ -1,5 +0,0 @@
1
- import type { AssistantStream } from "../stream.js";
2
- import type { LlmContext, ModelInfo, Provider, ProviderModelDiscoveryOptions, StreamOpts } from "../types.js";
3
- export declare function discoverRadiusModels(options: ProviderModelDiscoveryOptions): Promise<ModelInfo[] | undefined>;
4
- export declare function streamRadius(model: ModelInfo, context: LlmContext, opts?: StreamOpts): AssistantStream;
5
- export declare const radius: Provider;