@mu-agent/mu 0.0.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.
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/THIRD_PARTY_LICENSES.txt +32 -0
- package/dist/index.js +226 -0
- package/dist/mu.js +397 -0
- package/dist/types/ai/auth.d.ts +2 -0
- package/dist/types/ai/catalog.d.ts +20 -0
- package/dist/types/ai/cost.d.ts +4 -0
- package/dist/types/ai/errors.d.ts +13 -0
- package/dist/types/ai/index.d.ts +22 -0
- package/dist/types/ai/json.d.ts +4 -0
- package/dist/types/ai/provider-config.d.ts +15 -0
- package/dist/types/ai/providers/anthropic.d.ts +4 -0
- package/dist/types/ai/providers/gemini.d.ts +4 -0
- package/dist/types/ai/providers/github-copilot.d.ts +2 -0
- package/dist/types/ai/providers/openai-completions.d.ts +4 -0
- package/dist/types/ai/providers/openai.d.ts +6 -0
- package/dist/types/ai/providers/radius.d.ts +5 -0
- package/dist/types/ai/providers/request.d.ts +6 -0
- package/dist/types/ai/providers/shared.d.ts +6 -0
- package/dist/types/ai/registry.d.ts +4 -0
- package/dist/types/ai/retry.d.ts +6 -0
- package/dist/types/ai/sse.d.ts +5 -0
- package/dist/types/ai/stream.d.ts +18 -0
- package/dist/types/ai/testing/replay.d.ts +31 -0
- package/dist/types/ai/types.d.ts +187 -0
- package/dist/types/core/checkpoint.d.ts +39 -0
- package/dist/types/core/commands.d.ts +30 -0
- package/dist/types/core/compaction.d.ts +45 -0
- package/dist/types/core/events.d.ts +109 -0
- package/dist/types/core/extensions.d.ts +97 -0
- package/dist/types/core/index.d.ts +27 -0
- package/dist/types/core/loop.d.ts +69 -0
- package/dist/types/core/messages.d.ts +15 -0
- package/dist/types/core/microcompaction.d.ts +14 -0
- package/dist/types/core/permission.d.ts +27 -0
- package/dist/types/core/process.d.ts +79 -0
- package/dist/types/core/profile.d.ts +46 -0
- package/dist/types/core/recovery.d.ts +14 -0
- package/dist/types/core/session.d.ts +103 -0
- package/dist/types/core/testing/fake-provider.d.ts +19 -0
- package/dist/types/core/tools.d.ts +22 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/profile-coding/checkpoint.d.ts +29 -0
- package/dist/types/profile-coding/context.d.ts +76 -0
- package/dist/types/profile-coding/index.d.ts +35 -0
- package/dist/types/profile-coding/permissions.d.ts +13 -0
- package/dist/types/profile-coding/prompts.d.ts +2 -0
- package/dist/types/profile-coding/shell.d.ts +12 -0
- package/dist/types/profile-coding/state.d.ts +10 -0
- package/dist/types/profile-coding/tools/bash.d.ts +21 -0
- package/dist/types/profile-coding/tools/files.d.ts +32 -0
- package/dist/types/profile-coding/tools/search.d.ts +23 -0
- package/dist/types/profile-coding/tools/tasks.d.ts +9 -0
- package/dist/types/profile-coding/tools/todo.d.ts +16 -0
- package/dist/types/profile-coding/truncate.d.ts +8 -0
- package/dist/types/sdk/agent.d.ts +144 -0
- package/dist/types/sdk/auth-page.d.ts +9 -0
- package/dist/types/sdk/auth.d.ts +78 -0
- package/dist/types/sdk/budget.d.ts +9 -0
- package/dist/types/sdk/commands.d.ts +30 -0
- package/dist/types/sdk/extension-loader.d.ts +15 -0
- package/dist/types/sdk/file-store.d.ts +13 -0
- package/dist/types/sdk/index.d.ts +31 -0
- package/dist/types/sdk/markdown-commands.d.ts +29 -0
- package/dist/types/sdk/mcp.d.ts +22 -0
- package/dist/types/sdk/profile.d.ts +6 -0
- package/dist/types/sdk/shell-hooks.d.ts +14 -0
- package/dist/types/sdk/skills.d.ts +12 -0
- package/dist/types/sdk/structured-output.d.ts +5 -0
- package/dist/types/sdk/testing/mcp-fixture-server.d.ts +1 -0
- package/dist/types/sdk/tool.d.ts +19 -0
- package/package.json +72 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ModelInfo, Provider } from "../ai/index.js";
|
|
2
|
+
import { type Command, CommandRegistry } from "./commands.js";
|
|
3
|
+
import type { AgentEvent } from "./events.js";
|
|
4
|
+
import type { AgentMessage } from "./messages.js";
|
|
5
|
+
import type { AnyTool, ToolResult } from "./tools.js";
|
|
6
|
+
export interface ToolCallDirective {
|
|
7
|
+
block?: boolean;
|
|
8
|
+
reason?: string;
|
|
9
|
+
args?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface ToolResultDirective {
|
|
12
|
+
content?: ToolResult["content"];
|
|
13
|
+
isError?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface InputDirective {
|
|
16
|
+
consume?: boolean;
|
|
17
|
+
text?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ToolCallHookInfo {
|
|
20
|
+
toolName: string;
|
|
21
|
+
toolCallId: string;
|
|
22
|
+
args: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export interface ToolResultHookInfo {
|
|
25
|
+
toolName: string;
|
|
26
|
+
toolCallId: string;
|
|
27
|
+
result: ToolResult;
|
|
28
|
+
isError: boolean;
|
|
29
|
+
}
|
|
30
|
+
export type LifecycleNotification = {
|
|
31
|
+
type: "session_start";
|
|
32
|
+
sessionId: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: "session_shutdown";
|
|
35
|
+
sessionId: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: "input";
|
|
38
|
+
text: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "model_select";
|
|
41
|
+
model: string;
|
|
42
|
+
};
|
|
43
|
+
export type LifecycleEvent = LifecycleNotification["type"];
|
|
44
|
+
export type ExtensionEvent = AgentEvent | LifecycleNotification;
|
|
45
|
+
export type ExtensionEventType = ExtensionEvent["type"];
|
|
46
|
+
export type ExtensionEventFor<T extends ExtensionEventType> = Extract<ExtensionEvent, {
|
|
47
|
+
type: T;
|
|
48
|
+
}>;
|
|
49
|
+
export interface ToolRenderer {
|
|
50
|
+
render: (info: {
|
|
51
|
+
toolName: string;
|
|
52
|
+
args: unknown;
|
|
53
|
+
result?: ToolResult;
|
|
54
|
+
}) => string[];
|
|
55
|
+
}
|
|
56
|
+
export interface ExtensionAPI {
|
|
57
|
+
on<T extends ExtensionEventType>(event: T, handler: (event: ExtensionEventFor<T>) => void): void;
|
|
58
|
+
onToolCall(handler: (info: ToolCallHookInfo) => ToolCallDirective | undefined | Promise<ToolCallDirective | undefined>): void;
|
|
59
|
+
onToolResult(handler: (info: ToolResultHookInfo) => ToolResultDirective | undefined | Promise<ToolResultDirective | undefined>): void;
|
|
60
|
+
onContext(handler: (messages: AgentMessage[]) => AgentMessage[] | Promise<AgentMessage[]>): void;
|
|
61
|
+
onInput(handler: (text: string) => InputDirective | undefined | Promise<InputDirective | undefined>): void;
|
|
62
|
+
registerTool(tool: AnyTool): void;
|
|
63
|
+
registerCommand(command: Command): void;
|
|
64
|
+
registerProvider(provider: Provider): void;
|
|
65
|
+
registerModels(models: ModelInfo[]): void;
|
|
66
|
+
registerRenderer(toolName: string, renderer: ToolRenderer): void;
|
|
67
|
+
log(message: string): void;
|
|
68
|
+
}
|
|
69
|
+
export interface Extension {
|
|
70
|
+
name: string;
|
|
71
|
+
activate: (api: ExtensionAPI) => void | Promise<void>;
|
|
72
|
+
deactivate?: () => void | Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
export declare class ExtensionHost {
|
|
75
|
+
readonly tools: Map<string, AnyTool>;
|
|
76
|
+
readonly commands: CommandRegistry;
|
|
77
|
+
readonly providers: Map<string, Provider>;
|
|
78
|
+
readonly models: Map<string, ModelInfo>;
|
|
79
|
+
readonly renderers: Map<string, ToolRenderer>;
|
|
80
|
+
readonly logs: string[];
|
|
81
|
+
private extensions;
|
|
82
|
+
private eventHandlers;
|
|
83
|
+
private toolCallHooks;
|
|
84
|
+
private toolResultHooks;
|
|
85
|
+
private contextHooks;
|
|
86
|
+
private inputHooks;
|
|
87
|
+
register(extension: Extension): Promise<void>;
|
|
88
|
+
shutdown(): Promise<void>;
|
|
89
|
+
emit(event: AgentEvent): void;
|
|
90
|
+
emitLifecycle(event: LifecycleNotification): void;
|
|
91
|
+
findModel(ref: string): ModelInfo | undefined;
|
|
92
|
+
runToolCallHooks(info: ToolCallHookInfo): Promise<ToolCallDirective | undefined>;
|
|
93
|
+
runToolResultHooks(info: ToolResultHookInfo): Promise<ToolResultDirective | undefined>;
|
|
94
|
+
runContextHooks(messages: AgentMessage[]): Promise<AgentMessage[]>;
|
|
95
|
+
runInputHooks(text: string): Promise<InputDirective | undefined>;
|
|
96
|
+
get hasContextHooks(): boolean;
|
|
97
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type { CheckpointDiffFile, CheckpointEntry, CheckpointProvider, } from "./checkpoint.js";
|
|
2
|
+
export { CheckpointHistory } from "./checkpoint.js";
|
|
3
|
+
export type { Command, CommandContext, CommandResult } from "./commands.js";
|
|
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";
|
|
8
|
+
export type { Extension, ExtensionAPI, ExtensionEvent, ExtensionEventFor, ExtensionEventType, InputDirective, LifecycleEvent, LifecycleNotification, ToolCallDirective, ToolCallHookInfo, ToolRenderer, ToolResultDirective, ToolResultHookInfo, } from "./extensions.js";
|
|
9
|
+
export { ExtensionHost } from "./extensions.js";
|
|
10
|
+
export type { AfterToolCallInfo, AgentContext, AgentRunResult, BeforeToolCallInfo, ContextPreparation, LoopConfig, NextTurnDirective, TurnInfo, } from "./loop.js";
|
|
11
|
+
export { AgentEventStream, runAgent, runLoop } from "./loop.js";
|
|
12
|
+
export type { AgentMessage, CustomMessage } from "./messages.js";
|
|
13
|
+
export * from "./messages.js";
|
|
14
|
+
export { customMessage, isCustomMessage, renderCustomMessage, toAiMessages, userMessage, } from "./messages.js";
|
|
15
|
+
export type { MicrocompactionOptions, MicrocompactionResult } from "./microcompaction.js";
|
|
16
|
+
export { IMAGE_TOMBSTONE, MICROCOMPACT_THRESHOLD, microcompact, TOMBSTONE, } from "./microcompaction.js";
|
|
17
|
+
export type { PermissionAction, PermissionPreview, PermissionRequest, PermissionRule, ToolPermissionDetails, } from "./permission.js";
|
|
18
|
+
export { evaluate } from "./permission.js";
|
|
19
|
+
export type { ManagedProcessHandle, ProcessEvents, Spawner, SpawnRequest, TaskInfo, TaskStatus, } from "./process.js";
|
|
20
|
+
export { exitNotification, OutputBuffer, ProcessManager } from "./process.js";
|
|
21
|
+
export type { PermissionMode, Profile, ProfileFactory, ProfileRuntime, ProfileRuntimeHost, } from "./profile.js";
|
|
22
|
+
export type { RecoveryAttempt } from "./recovery.js";
|
|
23
|
+
export { isContextTooLongError, isContextTooLongResult, withContextRecovery, } from "./recovery.js";
|
|
24
|
+
export type { NewTreeEntry, SessionEntry, SessionStore, TreeEntry } from "./session.js";
|
|
25
|
+
export { isTreeEntry, MemorySessionStore, newEntryId, parseEntry, parseSession, SESSION_VERSION, SessionTree, serializeEntry, serializeSession, } from "./session.js";
|
|
26
|
+
export type { AnyTool, Tool, ToolResult } from "./tools.js";
|
|
27
|
+
export { concurrencySafe, errorResult, textResult } from "./tools.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type AssistantMessage, EventStream, type LlmContext, type ModelInfo, type Provider, type StreamOpts, type ThinkingLevel, type ToolCallContent, type ToolResultContent, type ToolResultMessage } from "../ai/index.js";
|
|
2
|
+
import type { AgentEndReason, AgentEvent, EventSink } from "./events.js";
|
|
3
|
+
import type { AgentMessage } from "./messages.js";
|
|
4
|
+
import { type AnyTool, type ToolResult } from "./tools.js";
|
|
5
|
+
export interface AgentContext {
|
|
6
|
+
systemPrompt?: LlmContext["systemPrompt"];
|
|
7
|
+
messages: AgentMessage[];
|
|
8
|
+
tools?: AnyTool[];
|
|
9
|
+
}
|
|
10
|
+
export interface TurnInfo {
|
|
11
|
+
message: AssistantMessage;
|
|
12
|
+
toolResults: ToolResultMessage[];
|
|
13
|
+
context: AgentContext;
|
|
14
|
+
requestMessages: AgentMessage[];
|
|
15
|
+
newMessages: AgentMessage[];
|
|
16
|
+
}
|
|
17
|
+
export interface BeforeToolCallInfo {
|
|
18
|
+
assistantMessage: AssistantMessage;
|
|
19
|
+
toolCall: ToolCallContent;
|
|
20
|
+
args: Record<string, unknown>;
|
|
21
|
+
context: AgentContext;
|
|
22
|
+
}
|
|
23
|
+
export interface AfterToolCallInfo extends BeforeToolCallInfo {
|
|
24
|
+
result: ToolResult;
|
|
25
|
+
isError: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface NextTurnDirective {
|
|
28
|
+
model?: ModelInfo;
|
|
29
|
+
thinkingLevel?: ThinkingLevel;
|
|
30
|
+
context?: AgentContext;
|
|
31
|
+
}
|
|
32
|
+
export interface ContextPreparation {
|
|
33
|
+
messages: AgentMessage[];
|
|
34
|
+
stop?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface LoopConfig {
|
|
37
|
+
provider: Provider;
|
|
38
|
+
model: ModelInfo;
|
|
39
|
+
streamOpts?: StreamOpts;
|
|
40
|
+
thinkingLevel?: ThinkingLevel;
|
|
41
|
+
maxTurns?: number;
|
|
42
|
+
getSteeringMessages?: () => AgentMessage[] | Promise<AgentMessage[]>;
|
|
43
|
+
getFollowUpMessages?: () => AgentMessage[] | Promise<AgentMessage[]>;
|
|
44
|
+
beforeToolCall?: (info: BeforeToolCallInfo, signal: AbortSignal) => {
|
|
45
|
+
block?: boolean;
|
|
46
|
+
reason?: string;
|
|
47
|
+
rewrittenArgs?: Record<string, unknown>;
|
|
48
|
+
} | undefined | Promise<{
|
|
49
|
+
block?: boolean;
|
|
50
|
+
reason?: string;
|
|
51
|
+
rewrittenArgs?: Record<string, unknown>;
|
|
52
|
+
} | undefined>;
|
|
53
|
+
afterToolCall?: (info: AfterToolCallInfo, signal: AbortSignal) => ToolResult | undefined | Promise<ToolResult | undefined>;
|
|
54
|
+
shouldStopAfterTurn?: (turn: TurnInfo) => boolean | Promise<boolean>;
|
|
55
|
+
recoverFromError?: (message: AssistantMessage) => boolean | Promise<boolean>;
|
|
56
|
+
prepareNextTurn?: (turn: TurnInfo) => NextTurnDirective | undefined | Promise<NextTurnDirective | undefined>;
|
|
57
|
+
prepareContext?: (messages: AgentMessage[]) => ContextPreparation | AgentMessage[] | Promise<ContextPreparation | AgentMessage[]>;
|
|
58
|
+
transformContext?: (messages: AgentMessage[]) => AgentMessage[] | Promise<AgentMessage[]>;
|
|
59
|
+
}
|
|
60
|
+
export interface AgentRunResult {
|
|
61
|
+
messages: AgentMessage[];
|
|
62
|
+
reason: AgentEndReason;
|
|
63
|
+
}
|
|
64
|
+
export declare class AgentEventStream extends EventStream<AgentEvent, AgentRunResult> {
|
|
65
|
+
constructor();
|
|
66
|
+
}
|
|
67
|
+
export declare function runAgent(prompts: AgentMessage[], context: AgentContext, config: LoopConfig, signal?: AbortSignal): AgentEventStream;
|
|
68
|
+
export declare function runLoop(prompts: AgentMessage[], context: AgentContext, config: LoopConfig, emit: EventSink, signal?: AbortSignal): Promise<AgentRunResult>;
|
|
69
|
+
export type { ToolResultContent };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AiMessage, AssistantMessage, ImageContent, TextContent, ToolResultMessage, UserMessage } from "../ai/index.js";
|
|
2
|
+
export type { AssistantContent, AssistantMessage, ImageContent, StopReason, TextContent, ThinkingContent, ToolCallContent, ToolResultContent, ToolResultMessage, Usage, UserContent, UserMessage, } from "../ai/index.js";
|
|
3
|
+
export interface CustomMessage {
|
|
4
|
+
role: "custom";
|
|
5
|
+
customType: string;
|
|
6
|
+
content: (TextContent | ImageContent)[];
|
|
7
|
+
display?: boolean;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
}
|
|
10
|
+
export type AgentMessage = UserMessage | AssistantMessage | ToolResultMessage | CustomMessage;
|
|
11
|
+
export declare function isCustomMessage(message: AgentMessage): message is CustomMessage;
|
|
12
|
+
export declare function renderCustomMessage(message: CustomMessage): UserMessage;
|
|
13
|
+
export declare function toAiMessages(messages: AgentMessage[]): AiMessage[];
|
|
14
|
+
export declare function userMessage(text: string): UserMessage;
|
|
15
|
+
export declare function customMessage(customType: string, text: string, display?: boolean): CustomMessage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentMessage } from "./messages.js";
|
|
2
|
+
export declare const TOMBSTONE = "[output cleared to save context \u2014 re-run the tool if you need it]";
|
|
3
|
+
export declare const IMAGE_TOMBSTONE = "[image cleared to save context]";
|
|
4
|
+
export interface MicrocompactionOptions {
|
|
5
|
+
keepRecent?: number;
|
|
6
|
+
targetTokens?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MicrocompactionResult {
|
|
9
|
+
messages: AgentMessage[];
|
|
10
|
+
evicted: number;
|
|
11
|
+
tokensFreed: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function microcompact(messages: AgentMessage[], options?: MicrocompactionOptions): MicrocompactionResult;
|
|
14
|
+
export declare const MICROCOMPACT_THRESHOLD = 0.6;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CheckpointDiffFile } from "./checkpoint.js";
|
|
2
|
+
export type PermissionAction = "allow" | "ask" | "deny";
|
|
3
|
+
export interface PermissionRule {
|
|
4
|
+
permission: string;
|
|
5
|
+
pattern: string;
|
|
6
|
+
action: PermissionAction;
|
|
7
|
+
}
|
|
8
|
+
export interface PermissionRequest {
|
|
9
|
+
id: string;
|
|
10
|
+
toolCallId: string;
|
|
11
|
+
toolName: string;
|
|
12
|
+
pattern: string;
|
|
13
|
+
description: string;
|
|
14
|
+
preview?: PermissionPreview;
|
|
15
|
+
}
|
|
16
|
+
export type PermissionPreview = {
|
|
17
|
+
kind: "text";
|
|
18
|
+
lines: string[];
|
|
19
|
+
} | {
|
|
20
|
+
kind: "diff";
|
|
21
|
+
file: CheckpointDiffFile;
|
|
22
|
+
};
|
|
23
|
+
export interface ToolPermissionDetails {
|
|
24
|
+
description?: string;
|
|
25
|
+
preview?: PermissionPreview;
|
|
26
|
+
}
|
|
27
|
+
export declare function evaluate(rules: PermissionRule[], permission: string, pattern: string): PermissionAction;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export interface ManagedProcessHandle {
|
|
2
|
+
write: (data: string) => void;
|
|
3
|
+
resize: (cols: number, rows: number) => void;
|
|
4
|
+
detach: () => void;
|
|
5
|
+
kill: () => void;
|
|
6
|
+
exited: Promise<number | null>;
|
|
7
|
+
}
|
|
8
|
+
export interface SpawnRequest {
|
|
9
|
+
command: string;
|
|
10
|
+
onOutput: (chunk: string) => void;
|
|
11
|
+
cols: number;
|
|
12
|
+
rows: number;
|
|
13
|
+
}
|
|
14
|
+
export type Spawner = (request: SpawnRequest) => ManagedProcessHandle;
|
|
15
|
+
export type TaskStatus = "running" | "exited" | "killed";
|
|
16
|
+
export interface TaskInfo {
|
|
17
|
+
id: string;
|
|
18
|
+
command: string;
|
|
19
|
+
status: TaskStatus;
|
|
20
|
+
exitCode: number | null;
|
|
21
|
+
startedAt: number;
|
|
22
|
+
endedAt?: number;
|
|
23
|
+
outputBytes: number;
|
|
24
|
+
truncated: boolean;
|
|
25
|
+
detached: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare class OutputBuffer {
|
|
28
|
+
private headLimit;
|
|
29
|
+
private tailLimit;
|
|
30
|
+
private head;
|
|
31
|
+
private tail;
|
|
32
|
+
private headComplete;
|
|
33
|
+
private total;
|
|
34
|
+
constructor(headLimit?: number, tailLimit?: number);
|
|
35
|
+
append(chunk: string): void;
|
|
36
|
+
get bytes(): number;
|
|
37
|
+
get truncated(): boolean;
|
|
38
|
+
read(): string;
|
|
39
|
+
readSince(position: number): {
|
|
40
|
+
text: string;
|
|
41
|
+
offset: number;
|
|
42
|
+
gap: boolean;
|
|
43
|
+
};
|
|
44
|
+
private get droppedBytes();
|
|
45
|
+
}
|
|
46
|
+
export interface ProcessEvents {
|
|
47
|
+
onStarted?: (task: TaskInfo) => void;
|
|
48
|
+
onOutput?: (taskId: string, chunk: string) => void;
|
|
49
|
+
onExited?: (task: TaskInfo) => void;
|
|
50
|
+
}
|
|
51
|
+
export declare class ProcessManager {
|
|
52
|
+
private spawn;
|
|
53
|
+
private events;
|
|
54
|
+
private tasks;
|
|
55
|
+
private counter;
|
|
56
|
+
constructor(spawn: Spawner, events?: ProcessEvents);
|
|
57
|
+
setEvents(events: ProcessEvents): void;
|
|
58
|
+
start(command: string, size?: {
|
|
59
|
+
cols?: number;
|
|
60
|
+
rows?: number;
|
|
61
|
+
}): TaskInfo;
|
|
62
|
+
get(id: string): TaskInfo | undefined;
|
|
63
|
+
list(): TaskInfo[];
|
|
64
|
+
get runningCount(): number;
|
|
65
|
+
output(id: string, since?: "start" | "new"): {
|
|
66
|
+
text: string;
|
|
67
|
+
truncated: boolean;
|
|
68
|
+
} | undefined;
|
|
69
|
+
writeStdin(id: string, data: string): boolean;
|
|
70
|
+
resize(id: string, cols: number, rows: number): boolean;
|
|
71
|
+
resizeAll(cols: number, rows: number): void;
|
|
72
|
+
detach(id: string): boolean;
|
|
73
|
+
kill(id: string): boolean;
|
|
74
|
+
stopAll(): void;
|
|
75
|
+
killAll(): Promise<void>;
|
|
76
|
+
private requestStops;
|
|
77
|
+
wait(id: string): Promise<TaskInfo | undefined>;
|
|
78
|
+
}
|
|
79
|
+
export declare function exitNotification(task: TaskInfo): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PromptSection } from "../ai/index.js";
|
|
2
|
+
import type { CheckpointProvider } from "./checkpoint.js";
|
|
3
|
+
import type { Command } from "./commands.js";
|
|
4
|
+
import type { AgentEvent } from "./events.js";
|
|
5
|
+
import type { ToolRenderer } from "./extensions.js";
|
|
6
|
+
import type { AgentMessage } from "./messages.js";
|
|
7
|
+
import type { PermissionRule } from "./permission.js";
|
|
8
|
+
import type { AnyTool } from "./tools.js";
|
|
9
|
+
export interface PermissionMode {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
description: string;
|
|
13
|
+
rules: PermissionRule[];
|
|
14
|
+
}
|
|
15
|
+
export interface ProfileRuntimeHost {
|
|
16
|
+
emit: (event: AgentEvent) => void;
|
|
17
|
+
followUp: (message: string) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface ProfileRuntime {
|
|
20
|
+
attach: (host: ProfileRuntimeHost) => void;
|
|
21
|
+
resize?: (cols: number, rows: number) => void;
|
|
22
|
+
stop?: () => void;
|
|
23
|
+
shutdown?: () => void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface Profile {
|
|
26
|
+
name: string;
|
|
27
|
+
toolset: AnyTool[];
|
|
28
|
+
promptFor: (modelRef: string) => PromptSection[];
|
|
29
|
+
permissionDefaults: PermissionRule[];
|
|
30
|
+
permissionModes?: PermissionMode[];
|
|
31
|
+
defaultPermissionMode?: string;
|
|
32
|
+
rememberPermission?: (permission: string, pattern: string) => void | Promise<void>;
|
|
33
|
+
renderers?: Record<string, ToolRenderer>;
|
|
34
|
+
commands?: Command[];
|
|
35
|
+
environment?: () => Promise<Record<string, string>> | Record<string, string>;
|
|
36
|
+
contextMessages?: () => Promise<AgentMessage[]> | AgentMessage[];
|
|
37
|
+
refreshContext?: (messages: AgentMessage[], context: {
|
|
38
|
+
sessionId: string;
|
|
39
|
+
}) => Promise<AgentMessage[]> | AgentMessage[];
|
|
40
|
+
diagnostics?: string[];
|
|
41
|
+
carryoverExtractor?: (messages: AgentMessage[]) => unknown;
|
|
42
|
+
checkpointProvider?: CheckpointProvider;
|
|
43
|
+
runtime?: ProfileRuntime;
|
|
44
|
+
scope?: () => Promise<string> | string;
|
|
45
|
+
}
|
|
46
|
+
export type ProfileFactory = (options?: Record<string, unknown>) => Profile | Promise<Profile>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function isContextTooLongError(error: unknown): boolean;
|
|
2
|
+
export declare function isContextTooLongResult(result: {
|
|
3
|
+
stopReason: string;
|
|
4
|
+
errorMessage?: string | undefined;
|
|
5
|
+
}): boolean;
|
|
6
|
+
export interface RecoveryAttempt<T> {
|
|
7
|
+
run: () => Promise<T>;
|
|
8
|
+
recover: () => Promise<void>;
|
|
9
|
+
isRecoverable: (value: T) => boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function withContextRecovery<T>(attempt: RecoveryAttempt<T>): Promise<{
|
|
12
|
+
value: T;
|
|
13
|
+
recovered: boolean;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { AgentMessage } from "./messages.js";
|
|
2
|
+
export declare const SESSION_VERSION = 1;
|
|
3
|
+
export type SessionEntry = {
|
|
4
|
+
type: "session";
|
|
5
|
+
version: number;
|
|
6
|
+
id: string;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
profile: string;
|
|
9
|
+
environment: Record<string, string>;
|
|
10
|
+
} | {
|
|
11
|
+
type: "message";
|
|
12
|
+
id: string;
|
|
13
|
+
parentId: string | null;
|
|
14
|
+
message: AgentMessage;
|
|
15
|
+
checkpointRef?: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "compaction";
|
|
18
|
+
id: string;
|
|
19
|
+
parentId: string | null;
|
|
20
|
+
summary: string;
|
|
21
|
+
carryover?: unknown;
|
|
22
|
+
firstKeptEntryId: string | null;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: "microcompaction";
|
|
26
|
+
id: string;
|
|
27
|
+
parentId: string | null;
|
|
28
|
+
replacements: {
|
|
29
|
+
entryId: string;
|
|
30
|
+
message: AgentMessage;
|
|
31
|
+
}[];
|
|
32
|
+
} | {
|
|
33
|
+
type: "checkpoint";
|
|
34
|
+
id: string;
|
|
35
|
+
parentId: string | null;
|
|
36
|
+
beforeEntryId: string | null;
|
|
37
|
+
checkpointRef: string;
|
|
38
|
+
checkpointAfterRef: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "settings-change";
|
|
42
|
+
id: string;
|
|
43
|
+
parentId: string | null;
|
|
44
|
+
model?: string;
|
|
45
|
+
thinkingLevel?: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "custom";
|
|
48
|
+
id: string;
|
|
49
|
+
parentId: string | null;
|
|
50
|
+
customType: string;
|
|
51
|
+
data: unknown;
|
|
52
|
+
};
|
|
53
|
+
export type TreeEntry = Exclude<SessionEntry, {
|
|
54
|
+
type: "session";
|
|
55
|
+
}>;
|
|
56
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
57
|
+
export type NewTreeEntry = DistributiveOmit<TreeEntry, "id" | "parentId"> & {
|
|
58
|
+
id?: string;
|
|
59
|
+
parentId?: string | null;
|
|
60
|
+
};
|
|
61
|
+
export declare function isTreeEntry(entry: SessionEntry): entry is TreeEntry;
|
|
62
|
+
export declare function serializeEntry(entry: SessionEntry): string;
|
|
63
|
+
export declare function parseEntry(line: string): SessionEntry;
|
|
64
|
+
export declare function serializeSession(entries: SessionEntry[]): string;
|
|
65
|
+
export declare function parseSession(jsonl: string): SessionEntry[];
|
|
66
|
+
export declare function newEntryId(): string;
|
|
67
|
+
export declare class SessionTree {
|
|
68
|
+
private entries;
|
|
69
|
+
private byId;
|
|
70
|
+
private headId;
|
|
71
|
+
constructor(header?: SessionEntry & {
|
|
72
|
+
type: "session";
|
|
73
|
+
});
|
|
74
|
+
static fromJsonl(jsonl: string): SessionTree;
|
|
75
|
+
toJsonl(): string;
|
|
76
|
+
get header(): (SessionEntry & {
|
|
77
|
+
type: "session";
|
|
78
|
+
}) | undefined;
|
|
79
|
+
get head(): string | null;
|
|
80
|
+
all(): SessionEntry[];
|
|
81
|
+
get(id: string): TreeEntry | undefined;
|
|
82
|
+
has(id: string | null): boolean;
|
|
83
|
+
push(entry: SessionEntry): void;
|
|
84
|
+
append(entry: NewTreeEntry): TreeEntry;
|
|
85
|
+
appendMessage(message: AgentMessage, checkpointRef?: string): TreeEntry;
|
|
86
|
+
pathTo(id: string): TreeEntry[];
|
|
87
|
+
activePath(): TreeEntry[];
|
|
88
|
+
entryIdForMessage(message: AgentMessage): string | undefined;
|
|
89
|
+
messagesAt(id?: string | null): AgentMessage[];
|
|
90
|
+
fork(entryId: string | null): void;
|
|
91
|
+
}
|
|
92
|
+
export interface SessionStore {
|
|
93
|
+
load(sessionId: string): Promise<SessionTree | undefined>;
|
|
94
|
+
save(sessionId: string, tree: SessionTree): Promise<void>;
|
|
95
|
+
list(): Promise<string[]>;
|
|
96
|
+
}
|
|
97
|
+
export declare class MemorySessionStore implements SessionStore {
|
|
98
|
+
private sessions;
|
|
99
|
+
load(sessionId: string): Promise<SessionTree | undefined>;
|
|
100
|
+
save(sessionId: string, tree: SessionTree): Promise<void>;
|
|
101
|
+
list(): Promise<string[]>;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AssistantContent, AssistantStream, type LlmContext, type ModelInfo, type Provider, type StopReason, type StreamOpts, type Usage } from "../../ai/index.js";
|
|
2
|
+
export interface ScriptedTurn {
|
|
3
|
+
content: AssistantContent[];
|
|
4
|
+
stopReason?: StopReason;
|
|
5
|
+
errorMessage?: string;
|
|
6
|
+
usage?: Partial<Usage>;
|
|
7
|
+
delayMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const fakeModel: ModelInfo;
|
|
10
|
+
export declare class FakeProvider implements Provider {
|
|
11
|
+
private turns;
|
|
12
|
+
readonly id = "fake";
|
|
13
|
+
readonly requests: LlmContext[];
|
|
14
|
+
readonly streamOptions: (StreamOpts | undefined)[];
|
|
15
|
+
private index;
|
|
16
|
+
constructor(turns: ScriptedTurn[]);
|
|
17
|
+
get callCount(): number;
|
|
18
|
+
stream(model: ModelInfo, ctx: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ToolResultContent } from "../ai/index.js";
|
|
2
|
+
import type { ToolPermissionDetails } from "./permission.js";
|
|
3
|
+
export interface ToolResult {
|
|
4
|
+
content: ToolResultContent[];
|
|
5
|
+
details?: unknown;
|
|
6
|
+
isError?: boolean;
|
|
7
|
+
terminate?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface Tool<Args = Record<string, unknown>> {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
inputSchema: Record<string, unknown>;
|
|
13
|
+
isConcurrencySafe?: (args: Args) => boolean;
|
|
14
|
+
executionMode?: "sequential";
|
|
15
|
+
changesState?: boolean | ((args: Args) => boolean);
|
|
16
|
+
permissionDetails?: (args: Args) => ToolPermissionDetails | undefined | Promise<ToolPermissionDetails | undefined>;
|
|
17
|
+
execute: (toolCallId: string, args: Args, signal: AbortSignal, onUpdate?: (partial: ToolResultContent[]) => void) => Promise<ToolResult>;
|
|
18
|
+
}
|
|
19
|
+
export type AnyTool = Tool<any>;
|
|
20
|
+
export declare function errorResult(message: string): ToolResult;
|
|
21
|
+
export declare function textResult(text: string): ToolResult;
|
|
22
|
+
export declare function concurrencySafe(tool: AnyTool, args: unknown): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CodingProfile, type CodingProfileOptions, codingProfile } from "./profile-coding/index.js";
|
|
2
|
+
import { Agent, type AgentOptions, type Profile } from "./sdk/index.js";
|
|
3
|
+
export * from "./sdk/index.js";
|
|
4
|
+
export { codingProfile };
|
|
5
|
+
export type { CodingProfile, CodingProfileOptions };
|
|
6
|
+
export interface CreateAgentOptions extends AgentOptions {
|
|
7
|
+
profile?: "coding" | Profile;
|
|
8
|
+
profileOptions?: CodingProfileOptions;
|
|
9
|
+
}
|
|
10
|
+
export declare function createAgent(options?: CreateAgentOptions): Promise<Agent>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CheckpointDiffFile, CheckpointProvider } from "../core/index.js";
|
|
2
|
+
export interface ShadowCheckpointOptions {
|
|
3
|
+
root: string;
|
|
4
|
+
shadowDir?: string;
|
|
5
|
+
scope?: string;
|
|
6
|
+
run?: GitRunner;
|
|
7
|
+
}
|
|
8
|
+
export type GitRunner = (args: string[], env: Record<string, string>, cwd: string) => Promise<{
|
|
9
|
+
stdout: string;
|
|
10
|
+
stderr: string;
|
|
11
|
+
exitCode: number;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function gitConfigNullDevice(platform?: NodeJS.Platform): string;
|
|
14
|
+
export declare class ShadowCheckpointProvider implements CheckpointProvider {
|
|
15
|
+
private readonly root;
|
|
16
|
+
private readonly shadowDir;
|
|
17
|
+
private readonly run;
|
|
18
|
+
private readonly excludedPathspecs;
|
|
19
|
+
private initialized;
|
|
20
|
+
constructor(options: ShadowCheckpointOptions);
|
|
21
|
+
get directory(): string;
|
|
22
|
+
private env;
|
|
23
|
+
private git;
|
|
24
|
+
private ensure;
|
|
25
|
+
snapshot(label?: string): Promise<string | undefined>;
|
|
26
|
+
restore(ref: string): Promise<void>;
|
|
27
|
+
restoreResources(ref: string, resources: string[]): Promise<void>;
|
|
28
|
+
diff(fromRef: string, toRef?: string): Promise<CheckpointDiffFile[]>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type AgentMessage } from "../core/index.js";
|
|
2
|
+
export declare const DEFAULT_INSTRUCTION_MAX_BYTES: number;
|
|
3
|
+
export declare const DEFAULT_PROJECT_ROOT_MARKERS: string[];
|
|
4
|
+
export declare const DEFAULT_INSTRUCTION_FALLBACKS: string[];
|
|
5
|
+
export declare const INSTRUCTION_PRIMARY_NAMES: string[];
|
|
6
|
+
export interface InstructionSettings {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
maxBytes?: number;
|
|
9
|
+
fallbackFilenames?: string[];
|
|
10
|
+
projectRootMarkers?: string[];
|
|
11
|
+
imports?: boolean;
|
|
12
|
+
claudeRules?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface InstructionLoaderOptions extends InstructionSettings {
|
|
15
|
+
root: string;
|
|
16
|
+
home?: string;
|
|
17
|
+
managedPaths?: string[];
|
|
18
|
+
}
|
|
19
|
+
export type InstructionScope = "managed" | "global" | "project" | "local" | "rule" | "import";
|
|
20
|
+
export interface InstructionSource {
|
|
21
|
+
path: string;
|
|
22
|
+
content: string;
|
|
23
|
+
scope: InstructionScope;
|
|
24
|
+
parent?: string;
|
|
25
|
+
truncated?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface InstructionDiagnostic {
|
|
28
|
+
level: "warning";
|
|
29
|
+
path?: string;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
export interface InstructionSnapshot {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
projectRoot: string;
|
|
35
|
+
sources: InstructionSource[];
|
|
36
|
+
diagnostics: InstructionDiagnostic[];
|
|
37
|
+
bytes: number;
|
|
38
|
+
maxBytes: number;
|
|
39
|
+
truncated: boolean;
|
|
40
|
+
signature: string;
|
|
41
|
+
}
|
|
42
|
+
export declare class InstructionLoader {
|
|
43
|
+
readonly root: string;
|
|
44
|
+
readonly home: string;
|
|
45
|
+
readonly settings: Required<InstructionSettings>;
|
|
46
|
+
private readonly managedPaths;
|
|
47
|
+
private readonly settingDiagnostics;
|
|
48
|
+
private current;
|
|
49
|
+
private nestedSources;
|
|
50
|
+
private nestedSerial;
|
|
51
|
+
private activeSessionId;
|
|
52
|
+
constructor(options: InstructionLoaderOptions);
|
|
53
|
+
get snapshot(): InstructionSnapshot;
|
|
54
|
+
reload(options?: {
|
|
55
|
+
resetNested?: boolean;
|
|
56
|
+
}): Promise<InstructionSnapshot>;
|
|
57
|
+
refreshedMessages(existing: AgentMessage[], sessionId?: string): Promise<AgentMessage[]>;
|
|
58
|
+
instructionsForPath(targetPath: string): Promise<{
|
|
59
|
+
text: string;
|
|
60
|
+
sources: string[];
|
|
61
|
+
}>;
|
|
62
|
+
formatStatus(prefix?: string): string;
|
|
63
|
+
discoverPrimaryFiles(stopAt?: string): Promise<string[]>;
|
|
64
|
+
private findProjectRoot;
|
|
65
|
+
private dirsBetween;
|
|
66
|
+
private primaryForDirectory;
|
|
67
|
+
private firstReadableCandidate;
|
|
68
|
+
private ruleFiles;
|
|
69
|
+
private rulesForDirectory;
|
|
70
|
+
private loadSource;
|
|
71
|
+
private loadNested;
|
|
72
|
+
}
|
|
73
|
+
export declare function discoverContextFiles(root: string, stopAt?: string): Promise<string[]>;
|
|
74
|
+
export declare function contextMessages(root: string): Promise<AgentMessage[]>;
|
|
75
|
+
export declare function codingEnvironment(root: string): Promise<Record<string, string>>;
|
|
76
|
+
export declare function environmentMessage(env: Record<string, string>): AgentMessage;
|