noumen 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +767 -51
- package/dist/a2a/index.d.ts +148 -0
- package/dist/a2a/index.js +579 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/acp/index.d.ts +129 -0
- package/dist/acp/index.js +498 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/agent-BrkbZyOT.d.ts +1028 -0
- package/dist/cache-DVqaCX8v.d.ts +38 -0
- package/dist/chunk-2ZTGQLYK.js +356 -0
- package/dist/chunk-2ZTGQLYK.js.map +1 -0
- package/dist/chunk-42PHHZUA.js +132 -0
- package/dist/chunk-42PHHZUA.js.map +1 -0
- package/dist/chunk-4SQA2UCV.js +26 -0
- package/dist/chunk-4SQA2UCV.js.map +1 -0
- package/dist/chunk-5GEX6ZSB.js +179 -0
- package/dist/chunk-5GEX6ZSB.js.map +1 -0
- package/dist/chunk-7ZMN7XJE.js +94 -0
- package/dist/chunk-7ZMN7XJE.js.map +1 -0
- package/dist/chunk-AMYIJSAZ.js +57 -0
- package/dist/chunk-AMYIJSAZ.js.map +1 -0
- package/dist/chunk-BGG2E6JD.js +10 -0
- package/dist/chunk-BGG2E6JD.js.map +1 -0
- package/dist/chunk-BZSFUEWM.js +43 -0
- package/dist/chunk-BZSFUEWM.js.map +1 -0
- package/dist/chunk-CPFHEPW4.js +139 -0
- package/dist/chunk-CPFHEPW4.js.map +1 -0
- package/dist/chunk-D43BWEZA.js +346 -0
- package/dist/chunk-D43BWEZA.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-JACGEMTF.js +43 -0
- package/dist/chunk-JACGEMTF.js.map +1 -0
- package/dist/chunk-JX7CLUCV.js +21 -0
- package/dist/chunk-JX7CLUCV.js.map +1 -0
- package/dist/chunk-KXDB56YW.js +39 -0
- package/dist/chunk-KXDB56YW.js.map +1 -0
- package/dist/chunk-KY6ZPWHO.js +112 -0
- package/dist/chunk-KY6ZPWHO.js.map +1 -0
- package/dist/chunk-NBDFQYUZ.js +7992 -0
- package/dist/chunk-NBDFQYUZ.js.map +1 -0
- package/dist/chunk-OGXNFXFA.js +196 -0
- package/dist/chunk-OGXNFXFA.js.map +1 -0
- package/dist/chunk-QTJ7VTJY.js +1994 -0
- package/dist/chunk-QTJ7VTJY.js.map +1 -0
- package/dist/chunk-UVSSQBDY.js +192 -0
- package/dist/chunk-UVSSQBDY.js.map +1 -0
- package/dist/chunk-Y45R3PQL.js +684 -0
- package/dist/chunk-Y45R3PQL.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +868 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/index.d.ts +64 -0
- package/dist/client/index.js +409 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client-CRRO2376.js +10 -0
- package/dist/client-CRRO2376.js.map +1 -0
- package/dist/headless-Q7XHHZIW.js +143 -0
- package/dist/headless-Q7XHHZIW.js.map +1 -0
- package/dist/history-snip-64GYP4ZL.js +12 -0
- package/dist/history-snip-64GYP4ZL.js.map +1 -0
- package/dist/index.d.ts +1305 -418
- package/dist/index.js +384 -1757
- package/dist/index.js.map +1 -1
- package/dist/jsonrpc/index.d.ts +54 -0
- package/dist/jsonrpc/index.js +34 -0
- package/dist/jsonrpc/index.js.map +1 -0
- package/dist/lsp/index.d.ts +36 -0
- package/dist/lsp/index.js +16 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp-PS3BWIHC.js +8 -0
- package/dist/lsp-PS3BWIHC.js.map +1 -0
- package/dist/manager-DLXK63XC.js +8 -0
- package/dist/manager-DLXK63XC.js.map +1 -0
- package/dist/mcp/index.d.ts +111 -0
- package/dist/mcp/index.js +104 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp-auth-AEI2R4ZC.js +9 -0
- package/dist/mcp-auth-AEI2R4ZC.js.map +1 -0
- package/dist/ollama-YNXAYP3R.js +18 -0
- package/dist/ollama-YNXAYP3R.js.map +1 -0
- package/dist/provider-factory-34MSWJZ3.js +20 -0
- package/dist/provider-factory-34MSWJZ3.js.map +1 -0
- package/dist/providers/anthropic.d.ts +19 -0
- package/dist/providers/anthropic.js +33 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/bedrock.d.ts +39 -0
- package/dist/providers/bedrock.js +54 -0
- package/dist/providers/bedrock.js.map +1 -0
- package/dist/providers/gemini.d.ts +16 -0
- package/dist/providers/gemini.js +224 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/openai.d.ts +18 -0
- package/dist/providers/openai.js +8 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +16 -0
- package/dist/providers/openrouter.js +23 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/vertex.d.ts +40 -0
- package/dist/providers/vertex.js +64 -0
- package/dist/providers/vertex.js.map +1 -0
- package/dist/render-GRN4ZSSW.js +14 -0
- package/dist/render-GRN4ZSSW.js.map +1 -0
- package/dist/resolve-XM52G7YE.js +14 -0
- package/dist/resolve-XM52G7YE.js.map +1 -0
- package/dist/server/index.d.ts +128 -0
- package/dist/server/index.js +626 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server-Cg1yWGaV.d.ts +96 -0
- package/dist/spinner-OJNR6NFO.js +8 -0
- package/dist/spinner-OJNR6NFO.js.map +1 -0
- package/dist/types-2kTLUCnD.d.ts +107 -0
- package/dist/types-3c88cRKH.d.ts +547 -0
- package/dist/types-CwKKucOF.d.ts +620 -0
- package/dist/types-DwdzmXfs.d.ts +107 -0
- package/dist/types-NIyVwQ4h.d.ts +109 -0
- package/dist/types-QwfylltH.d.ts +71 -0
- package/package.json +134 -6
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
import { c as CheckpointConfig, F as FileCheckpointState, D as DiffStats, d as FileCheckpointSnapshot, S as StreamEvent, e as ContentPart } from './types-3c88cRKH.js';
|
|
2
|
+
import { a as PermissionMode, b as PermissionResult } from './types-DwdzmXfs.js';
|
|
3
|
+
|
|
4
|
+
interface FileEntry {
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
isDirectory: boolean;
|
|
8
|
+
isFile: boolean;
|
|
9
|
+
size?: number;
|
|
10
|
+
}
|
|
11
|
+
interface FileStat {
|
|
12
|
+
size: number;
|
|
13
|
+
isDirectory: boolean;
|
|
14
|
+
isFile: boolean;
|
|
15
|
+
createdAt?: Date;
|
|
16
|
+
modifiedAt?: Date;
|
|
17
|
+
}
|
|
18
|
+
interface ReadOptions {
|
|
19
|
+
encoding?: BufferEncoding;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sandboxed filesystem interface.
|
|
23
|
+
*
|
|
24
|
+
* `VirtualFs` is noumen's primary isolation boundary for file I/O. Every
|
|
25
|
+
* built-in tool that touches the filesystem (ReadFile, WriteFile, EditFile)
|
|
26
|
+
* delegates to this interface — the agent never accesses `node:fs` directly.
|
|
27
|
+
*
|
|
28
|
+
* Swap implementations to control where files live and what the agent can reach:
|
|
29
|
+
* - `LocalFs` — reads/writes on the host filesystem (no isolation, for local dev)
|
|
30
|
+
* - `SpritesFs` — reads/writes inside a remote sprites.dev container (full sandbox)
|
|
31
|
+
* - Custom — implement this interface for Docker volumes, E2B, S3, in-memory, etc.
|
|
32
|
+
*/
|
|
33
|
+
interface VirtualFs {
|
|
34
|
+
readFile(path: string, opts?: ReadOptions): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Read raw bytes from a file. Used for binary content (images, PDFs).
|
|
37
|
+
* Implementations SHOULD cap the read at `maxBytes` to prevent OOM on
|
|
38
|
+
* very large files. When `maxBytes` is omitted, the entire file is read.
|
|
39
|
+
*
|
|
40
|
+
* Returns a Buffer (Node.js) or Uint8Array.
|
|
41
|
+
*/
|
|
42
|
+
readFileBytes?(path: string, maxBytes?: number): Promise<Buffer>;
|
|
43
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
44
|
+
appendFile(path: string, content: string): Promise<void>;
|
|
45
|
+
deleteFile(path: string, opts?: {
|
|
46
|
+
recursive?: boolean;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
mkdir(path: string, opts?: {
|
|
49
|
+
recursive?: boolean;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
readdir(path: string, opts?: {
|
|
52
|
+
recursive?: boolean;
|
|
53
|
+
}): Promise<FileEntry[]>;
|
|
54
|
+
exists(path: string): Promise<boolean>;
|
|
55
|
+
stat(path: string): Promise<FileStat>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ExecOptions {
|
|
59
|
+
timeout?: number;
|
|
60
|
+
cwd?: string;
|
|
61
|
+
env?: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
interface CommandResult {
|
|
64
|
+
exitCode: number;
|
|
65
|
+
stdout: string;
|
|
66
|
+
stderr: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sandboxed shell execution interface.
|
|
70
|
+
*
|
|
71
|
+
* `VirtualComputer` is noumen's primary isolation boundary for command
|
|
72
|
+
* execution. Every built-in tool that runs shell commands (Bash, Glob, Grep)
|
|
73
|
+
* delegates to this interface — the agent never spawns processes directly.
|
|
74
|
+
*
|
|
75
|
+
* Swap implementations to control where and how commands run:
|
|
76
|
+
* - `LocalComputer` — runs on the host machine (no isolation, for local dev)
|
|
77
|
+
* - `SpritesComputer` — runs in a remote sprites.dev container (full sandbox)
|
|
78
|
+
* - Custom — implement this interface for Docker, E2B, Daytona, etc.
|
|
79
|
+
*/
|
|
80
|
+
interface VirtualComputer {
|
|
81
|
+
executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Zod integration utilities. Users bring their own `zod` dependency — these
|
|
86
|
+
* helpers accept duck-typed schemas so we don't force a hard dependency.
|
|
87
|
+
*/
|
|
88
|
+
type JsonSchemaType = Record<string, unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Minimal interface matching Zod v4's safeParse return. Allows noumen to
|
|
91
|
+
* validate tool input without depending on zod directly.
|
|
92
|
+
*/
|
|
93
|
+
interface SafeParseResult {
|
|
94
|
+
success: boolean;
|
|
95
|
+
data?: unknown;
|
|
96
|
+
error?: {
|
|
97
|
+
issues: Array<{
|
|
98
|
+
code: string;
|
|
99
|
+
path: (string | number)[];
|
|
100
|
+
message: string;
|
|
101
|
+
}>;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
interface ZodLikeSchema {
|
|
105
|
+
safeParse(data: unknown): SafeParseResult;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Convert a Zod v4 schema to JSON Schema. Caches by schema identity.
|
|
109
|
+
* Requires `zod/v4` to be installed — calls its native `toJSONSchema`.
|
|
110
|
+
*/
|
|
111
|
+
declare function zodToJsonSchema(schema: ZodLikeSchema): JsonSchemaType;
|
|
112
|
+
/**
|
|
113
|
+
* Register the `toJSONSchema` function from `zod/v4` so `zodToJsonSchema` can use it.
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { toJSONSchema } from "zod/v4";
|
|
117
|
+
* import { registerZodToJsonSchema } from "noumen";
|
|
118
|
+
* registerZodToJsonSchema(toJSONSchema);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function registerZodToJsonSchema(fn: (schema: unknown) => JsonSchemaType): void;
|
|
122
|
+
/**
|
|
123
|
+
* Format a Zod validation error into a human-readable string suitable
|
|
124
|
+
* for feeding back to the model as a tool_result error.
|
|
125
|
+
*/
|
|
126
|
+
declare function formatZodValidationError(toolName: string, issues: SafeParseResult["error"]): string;
|
|
127
|
+
|
|
128
|
+
type HookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "PreCompact" | "PostCompact" | "TurnStart" | "TurnEnd" | "SubagentStart" | "SubagentStop" | "SessionStart" | "SessionEnd" | "PermissionRequest" | "PermissionDenied" | "FileWrite" | "ModelSwitch" | "RetryAttempt" | "MemoryUpdate" | "Error";
|
|
129
|
+
interface PreToolUseHookInput {
|
|
130
|
+
event: "PreToolUse";
|
|
131
|
+
toolName: string;
|
|
132
|
+
toolInput: Record<string, unknown>;
|
|
133
|
+
toolUseId: string;
|
|
134
|
+
sessionId: string;
|
|
135
|
+
}
|
|
136
|
+
interface PreToolUseHookOutput {
|
|
137
|
+
decision?: "allow" | "deny" | "passthrough";
|
|
138
|
+
updatedInput?: Record<string, unknown>;
|
|
139
|
+
message?: string;
|
|
140
|
+
preventContinuation?: boolean;
|
|
141
|
+
}
|
|
142
|
+
interface PostToolUseHookInput {
|
|
143
|
+
event: "PostToolUse";
|
|
144
|
+
toolName: string;
|
|
145
|
+
toolInput: Record<string, unknown>;
|
|
146
|
+
toolUseId: string;
|
|
147
|
+
toolOutput: string;
|
|
148
|
+
isError: boolean;
|
|
149
|
+
sessionId: string;
|
|
150
|
+
}
|
|
151
|
+
interface PostToolUseHookOutput {
|
|
152
|
+
updatedOutput?: string;
|
|
153
|
+
preventContinuation?: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface PostToolUseFailureHookInput {
|
|
156
|
+
event: "PostToolUseFailure";
|
|
157
|
+
toolName: string;
|
|
158
|
+
toolInput: Record<string, unknown>;
|
|
159
|
+
toolUseId: string;
|
|
160
|
+
toolOutput: string;
|
|
161
|
+
errorMessage: string;
|
|
162
|
+
sessionId: string;
|
|
163
|
+
}
|
|
164
|
+
type PostToolUseFailureHookOutput = PostToolUseHookOutput;
|
|
165
|
+
interface SubagentStartHookInput {
|
|
166
|
+
event: "SubagentStart";
|
|
167
|
+
sessionId: string;
|
|
168
|
+
parentSessionId: string;
|
|
169
|
+
prompt: string;
|
|
170
|
+
}
|
|
171
|
+
interface SubagentStopHookInput {
|
|
172
|
+
event: "SubagentStop";
|
|
173
|
+
sessionId: string;
|
|
174
|
+
parentSessionId: string;
|
|
175
|
+
result: string;
|
|
176
|
+
}
|
|
177
|
+
interface SessionStartHookInput {
|
|
178
|
+
event: "SessionStart";
|
|
179
|
+
sessionId: string;
|
|
180
|
+
prompt: string | unknown[];
|
|
181
|
+
isResume: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface SessionEndHookInput {
|
|
184
|
+
event: "SessionEnd";
|
|
185
|
+
sessionId: string;
|
|
186
|
+
reason: "complete" | "abort" | "maxTurns" | "error";
|
|
187
|
+
}
|
|
188
|
+
interface PermissionRequestHookInput {
|
|
189
|
+
event: "PermissionRequest";
|
|
190
|
+
sessionId: string;
|
|
191
|
+
toolName: string;
|
|
192
|
+
input: Record<string, unknown>;
|
|
193
|
+
mode: string;
|
|
194
|
+
}
|
|
195
|
+
interface PermissionDeniedHookInput {
|
|
196
|
+
event: "PermissionDenied";
|
|
197
|
+
sessionId: string;
|
|
198
|
+
toolName: string;
|
|
199
|
+
input: Record<string, unknown>;
|
|
200
|
+
reason: string;
|
|
201
|
+
}
|
|
202
|
+
interface FileWriteHookInput {
|
|
203
|
+
event: "FileWrite";
|
|
204
|
+
sessionId: string;
|
|
205
|
+
toolName: string;
|
|
206
|
+
filePath: string;
|
|
207
|
+
isNew: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface ModelSwitchHookInput {
|
|
210
|
+
event: "ModelSwitch";
|
|
211
|
+
sessionId: string;
|
|
212
|
+
previousModel: string | undefined;
|
|
213
|
+
newModel: string;
|
|
214
|
+
}
|
|
215
|
+
interface RetryAttemptHookInput {
|
|
216
|
+
event: "RetryAttempt";
|
|
217
|
+
sessionId: string;
|
|
218
|
+
attempt: number;
|
|
219
|
+
maxAttempts: number;
|
|
220
|
+
error: string;
|
|
221
|
+
delay: number;
|
|
222
|
+
}
|
|
223
|
+
interface MemoryUpdateHookInput {
|
|
224
|
+
event: "MemoryUpdate";
|
|
225
|
+
sessionId: string;
|
|
226
|
+
entries: Array<{
|
|
227
|
+
type: string;
|
|
228
|
+
content: string;
|
|
229
|
+
}>;
|
|
230
|
+
}
|
|
231
|
+
interface NotificationHookInput {
|
|
232
|
+
event: "TurnStart" | "TurnEnd" | "Error" | "PreCompact" | "PostCompact";
|
|
233
|
+
sessionId: string;
|
|
234
|
+
[key: string]: unknown;
|
|
235
|
+
}
|
|
236
|
+
type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | SubagentStartHookInput | SubagentStopHookInput | SessionStartHookInput | SessionEndHookInput | PermissionRequestHookInput | PermissionDeniedHookInput | FileWriteHookInput | ModelSwitchHookInput | RetryAttemptHookInput | MemoryUpdateHookInput | NotificationHookInput;
|
|
237
|
+
type HookOutput = PreToolUseHookOutput | PostToolUseHookOutput | PostToolUseFailureHookOutput | void;
|
|
238
|
+
interface HookDefinition {
|
|
239
|
+
event: HookEvent;
|
|
240
|
+
/** Optional tool name glob filter (e.g. "Bash", "mcp__*") */
|
|
241
|
+
matcher?: string;
|
|
242
|
+
handler: (input: HookInput) => Promise<HookOutput> | HookOutput;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
type TaskStatus = "pending" | "in_progress" | "completed";
|
|
246
|
+
interface Task {
|
|
247
|
+
id: string;
|
|
248
|
+
subject: string;
|
|
249
|
+
description?: string;
|
|
250
|
+
status: TaskStatus;
|
|
251
|
+
owner?: string;
|
|
252
|
+
/** Task IDs that this task blocks (downstream dependents). */
|
|
253
|
+
blocks: string[];
|
|
254
|
+
/** Task IDs that must complete before this task can start. */
|
|
255
|
+
blockedBy: string[];
|
|
256
|
+
createdAt: string;
|
|
257
|
+
updatedAt: string;
|
|
258
|
+
}
|
|
259
|
+
interface TaskCreateInput {
|
|
260
|
+
subject: string;
|
|
261
|
+
description?: string;
|
|
262
|
+
}
|
|
263
|
+
interface TaskUpdateInput {
|
|
264
|
+
status?: TaskStatus;
|
|
265
|
+
description?: string;
|
|
266
|
+
owner?: string;
|
|
267
|
+
blockedBy?: string[];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* File-backed task store persisted on a VirtualFs instance.
|
|
272
|
+
* Tasks are stored as individual JSON files under a configurable directory.
|
|
273
|
+
*/
|
|
274
|
+
declare class TaskStore {
|
|
275
|
+
private dir;
|
|
276
|
+
private fs;
|
|
277
|
+
private nextId;
|
|
278
|
+
private initialized;
|
|
279
|
+
constructor(fs: VirtualFs, dir: string);
|
|
280
|
+
private ensureDir;
|
|
281
|
+
private taskPath;
|
|
282
|
+
create(input: TaskCreateInput): Promise<Task>;
|
|
283
|
+
get(id: string): Promise<Task | null>;
|
|
284
|
+
list(): Promise<Task[]>;
|
|
285
|
+
update(id: string, input: TaskUpdateInput): Promise<Task | null>;
|
|
286
|
+
delete(id: string): Promise<boolean>;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface LspServerConfig {
|
|
290
|
+
/** Command to start the LSP server. */
|
|
291
|
+
command: string;
|
|
292
|
+
/** Arguments to pass to the command. */
|
|
293
|
+
args?: string[];
|
|
294
|
+
/** Root URI for the workspace. */
|
|
295
|
+
rootUri?: string;
|
|
296
|
+
/** File extensions this server handles (e.g., [".ts", ".tsx", ".js"]). */
|
|
297
|
+
fileExtensions: string[];
|
|
298
|
+
/** Environment variables for the server process. */
|
|
299
|
+
env?: Record<string, string>;
|
|
300
|
+
}
|
|
301
|
+
type LspServerState = "stopped" | "starting" | "running" | "error";
|
|
302
|
+
interface LspDiagnostic {
|
|
303
|
+
filePath: string;
|
|
304
|
+
line: number;
|
|
305
|
+
character: number;
|
|
306
|
+
severity: "error" | "warning" | "info" | "hint";
|
|
307
|
+
message: string;
|
|
308
|
+
source?: string;
|
|
309
|
+
}
|
|
310
|
+
type LspOperation = "goToDefinition" | "findReferences" | "hover" | "documentSymbol" | "workspaceSymbol";
|
|
311
|
+
interface LspLocation {
|
|
312
|
+
filePath: string;
|
|
313
|
+
line: number;
|
|
314
|
+
character: number;
|
|
315
|
+
}
|
|
316
|
+
interface LspSymbol {
|
|
317
|
+
name: string;
|
|
318
|
+
kind: string;
|
|
319
|
+
location: LspLocation;
|
|
320
|
+
containerName?: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Accumulates LSP diagnostics and provides them for injection into the agent context.
|
|
325
|
+
*/
|
|
326
|
+
declare class DiagnosticRegistry {
|
|
327
|
+
private pending;
|
|
328
|
+
/**
|
|
329
|
+
* Register diagnostics from an LSP server's publishDiagnostics notification.
|
|
330
|
+
* Replaces all diagnostics for the given file.
|
|
331
|
+
*/
|
|
332
|
+
register(diagnostics: LspDiagnostic[]): void;
|
|
333
|
+
/**
|
|
334
|
+
* Clear diagnostics for a specific file (e.g., after a write/edit).
|
|
335
|
+
*/
|
|
336
|
+
clearForFile(filePath: string): void;
|
|
337
|
+
/**
|
|
338
|
+
* Get all pending diagnostics and clear them.
|
|
339
|
+
*/
|
|
340
|
+
flush(): LspDiagnostic[];
|
|
341
|
+
/**
|
|
342
|
+
* Get pending diagnostics without clearing.
|
|
343
|
+
*/
|
|
344
|
+
peek(): LspDiagnostic[];
|
|
345
|
+
hasPending(): boolean;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Manages multiple LSP servers, maps file extensions to servers,
|
|
350
|
+
* and handles lifecycle (lazy start, file sync, shutdown).
|
|
351
|
+
*/
|
|
352
|
+
declare class LspServerManager {
|
|
353
|
+
private servers;
|
|
354
|
+
private extensionMap;
|
|
355
|
+
private diagnostics;
|
|
356
|
+
private rootUri;
|
|
357
|
+
constructor(configs: Record<string, LspServerConfig>, rootUri: string);
|
|
358
|
+
/**
|
|
359
|
+
* Get the server that handles a given file path.
|
|
360
|
+
*/
|
|
361
|
+
private getServerForFile;
|
|
362
|
+
/**
|
|
363
|
+
* Ensure a server is started, starting it lazily if needed.
|
|
364
|
+
*/
|
|
365
|
+
private ensureStarted;
|
|
366
|
+
/**
|
|
367
|
+
* Send a request to the appropriate server for a file.
|
|
368
|
+
*/
|
|
369
|
+
sendRequest<T>(filePath: string, method: string, params: unknown): Promise<T | null>;
|
|
370
|
+
/**
|
|
371
|
+
* Notify LSP servers that a file was opened or changed.
|
|
372
|
+
*/
|
|
373
|
+
notifyFileChanged(filePath: string, content: string, version: number): Promise<void>;
|
|
374
|
+
/**
|
|
375
|
+
* Notify LSP servers that a file was saved.
|
|
376
|
+
*/
|
|
377
|
+
notifyFileSaved(filePath: string): void;
|
|
378
|
+
private ensureFileOpen;
|
|
379
|
+
/**
|
|
380
|
+
* Get the diagnostic registry for reading pending diagnostics.
|
|
381
|
+
*/
|
|
382
|
+
getDiagnostics(): DiagnosticRegistry;
|
|
383
|
+
/**
|
|
384
|
+
* Check if any LSP server is connected and running.
|
|
385
|
+
*/
|
|
386
|
+
isConnected(): boolean;
|
|
387
|
+
/**
|
|
388
|
+
* Return the name and state of every configured LSP server.
|
|
389
|
+
*/
|
|
390
|
+
getServerStatus(): Array<{
|
|
391
|
+
name: string;
|
|
392
|
+
state: string;
|
|
393
|
+
}>;
|
|
394
|
+
/**
|
|
395
|
+
* Shut down all LSP servers.
|
|
396
|
+
*/
|
|
397
|
+
shutdown(): Promise<void>;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
declare class FileCheckpointManager {
|
|
401
|
+
private fs;
|
|
402
|
+
private maxSnapshots;
|
|
403
|
+
private backupDir;
|
|
404
|
+
private state;
|
|
405
|
+
constructor(fs: VirtualFs, config: CheckpointConfig);
|
|
406
|
+
getState(): FileCheckpointState;
|
|
407
|
+
private sessionBackupDir;
|
|
408
|
+
private resolveBackupPath;
|
|
409
|
+
private ensureBackupDir;
|
|
410
|
+
private createBackup;
|
|
411
|
+
private restoreBackup;
|
|
412
|
+
private hasFileChanged;
|
|
413
|
+
/**
|
|
414
|
+
* Create a new snapshot at the start of a user turn.
|
|
415
|
+
* For each tracked file, checks if it changed since the last backup and
|
|
416
|
+
* creates a new versioned backup if so.
|
|
417
|
+
*/
|
|
418
|
+
makeSnapshot(messageId: string, sessionId: string): Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Track a file before it is edited. Creates the v1 backup (pre-edit state)
|
|
421
|
+
* and attaches it to the current (latest) snapshot.
|
|
422
|
+
* Called by write/edit tools before mutation.
|
|
423
|
+
*/
|
|
424
|
+
trackEdit(filePath: string, messageId: string, sessionId: string): Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* Restore all tracked files to the state captured in the snapshot
|
|
427
|
+
* matching the given messageId. Files that didn't exist at that point
|
|
428
|
+
* are deleted; files that existed are restored from backups.
|
|
429
|
+
*/
|
|
430
|
+
rewind(messageId: string, sessionId: string): Promise<void>;
|
|
431
|
+
canRestore(messageId: string): boolean;
|
|
432
|
+
getDiffStats(messageId: string, sessionId: string): Promise<DiffStats>;
|
|
433
|
+
/**
|
|
434
|
+
* Rebuild checkpoint state from persisted JSONL entries (for session resume).
|
|
435
|
+
* Mirrors claude-code's buildFileHistorySnapshotChain + fileHistoryRestoreStateFromLog.
|
|
436
|
+
*/
|
|
437
|
+
restoreStateFromEntries(snapshots: FileCheckpointSnapshot[]): void;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
interface FileState {
|
|
441
|
+
/** The content the model saw (may be a line slice, not the full file). */
|
|
442
|
+
content: string;
|
|
443
|
+
/** File mtime at the time of read (ms since epoch). */
|
|
444
|
+
timestamp: number;
|
|
445
|
+
/** 1-based start line of the read window (undefined = full file or post-edit snapshot). */
|
|
446
|
+
offset?: number;
|
|
447
|
+
/** Line count of the read window (undefined = full file or post-edit snapshot). */
|
|
448
|
+
limit?: number;
|
|
449
|
+
/**
|
|
450
|
+
* When true, the model saw a transformed/truncated view (e.g. injected memory).
|
|
451
|
+
* Edit/Write tools still require an explicit Read when this is set.
|
|
452
|
+
*/
|
|
453
|
+
isPartialView?: boolean;
|
|
454
|
+
}
|
|
455
|
+
interface FileStateCacheConfig {
|
|
456
|
+
enabled?: boolean;
|
|
457
|
+
/** Maximum number of cached file entries. Default: 100. */
|
|
458
|
+
maxEntries?: number;
|
|
459
|
+
/** Maximum total cached content in bytes. Default: 25 * 1024 * 1024 (25 MB). */
|
|
460
|
+
maxBytes?: number;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* LRU cache tracking which files the model has read and at what mtime.
|
|
465
|
+
*
|
|
466
|
+
* Used by ReadFile to record reads and by EditFile/WriteFile to enforce
|
|
467
|
+
* "read-before-edit" — the model cannot edit a file it hasn't seen,
|
|
468
|
+
* preventing hallucinated edits on unseen content.
|
|
469
|
+
*/
|
|
470
|
+
declare class FileStateCache {
|
|
471
|
+
private entries;
|
|
472
|
+
private maxEntries;
|
|
473
|
+
private maxBytes;
|
|
474
|
+
private currentBytes;
|
|
475
|
+
constructor(config?: FileStateCacheConfig);
|
|
476
|
+
private key;
|
|
477
|
+
private byteSize;
|
|
478
|
+
set(path: string, state: FileState): void;
|
|
479
|
+
get(path: string): FileState | undefined;
|
|
480
|
+
has(path: string): boolean;
|
|
481
|
+
delete(path: string): void;
|
|
482
|
+
get size(): number;
|
|
483
|
+
get totalBytes(): number;
|
|
484
|
+
clear(): void;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
interface ToolResult {
|
|
488
|
+
content: string | ContentPart[];
|
|
489
|
+
isError?: boolean;
|
|
490
|
+
/** Opaque metadata bag for tool-specific information (e.g. git operations). */
|
|
491
|
+
metadata?: Record<string, unknown>;
|
|
492
|
+
}
|
|
493
|
+
interface SubagentConfig {
|
|
494
|
+
prompt: string;
|
|
495
|
+
systemPrompt?: string;
|
|
496
|
+
/** Tool name allowlist. When set, only these tools are available. */
|
|
497
|
+
allowedTools?: string[];
|
|
498
|
+
permissionMode?: PermissionMode;
|
|
499
|
+
maxTurns?: number;
|
|
500
|
+
model?: string;
|
|
501
|
+
}
|
|
502
|
+
/** Async generator of stream events from a subagent run. */
|
|
503
|
+
interface SubagentRun {
|
|
504
|
+
sessionId: string;
|
|
505
|
+
events: AsyncGenerator<StreamEvent, void, unknown>;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Execution context passed to every tool call. All file and shell access
|
|
509
|
+
* goes through `fs` and `computer`, which are the sandboxing boundary —
|
|
510
|
+
* tools never touch `node:fs` or `child_process` directly. The isolation
|
|
511
|
+
* level is determined by which VirtualFs/VirtualComputer implementations
|
|
512
|
+
* the consumer provides (e.g. `LocalFs` for local dev, `SpritesFs` for
|
|
513
|
+
* remote sandboxed containers).
|
|
514
|
+
*/
|
|
515
|
+
interface ToolContext {
|
|
516
|
+
fs: VirtualFs;
|
|
517
|
+
computer: VirtualComputer;
|
|
518
|
+
cwd: string;
|
|
519
|
+
/** The session ID of the current thread (used by Agent tool for hook events). */
|
|
520
|
+
sessionId?: string;
|
|
521
|
+
/** Hook definitions from the parent thread (used by Agent tool for subagent lifecycle hooks). */
|
|
522
|
+
hooks?: HookDefinition[];
|
|
523
|
+
/** Factory for spawning isolated subagent threads. */
|
|
524
|
+
spawnSubagent?: (config: SubagentConfig) => SubagentRun;
|
|
525
|
+
/** Handler for user input requests from the AskUser tool. */
|
|
526
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
527
|
+
/** Task store for TaskCreate/List/Get/Update tools. */
|
|
528
|
+
taskStore?: TaskStore;
|
|
529
|
+
/** Set the current permission mode (used by PlanMode tools). */
|
|
530
|
+
setPermissionMode?: (mode: PermissionMode) => void;
|
|
531
|
+
/** Get the current permission mode. */
|
|
532
|
+
getPermissionMode?: () => PermissionMode;
|
|
533
|
+
/** Set the thread's working directory (used by Worktree tools). */
|
|
534
|
+
setCwd?: (cwd: string) => void;
|
|
535
|
+
/** LSP server manager for the LSP tool. */
|
|
536
|
+
lspManager?: LspServerManager;
|
|
537
|
+
/** File checkpoint manager for pre-edit backup tracking. */
|
|
538
|
+
checkpointManager?: FileCheckpointManager;
|
|
539
|
+
/** Current message ID for checkpoint tracking (set per user turn). */
|
|
540
|
+
currentMessageId?: string;
|
|
541
|
+
/** File state cache for read-before-edit enforcement and dedup. */
|
|
542
|
+
fileStateCache?: FileStateCache;
|
|
543
|
+
/** Fire a notification hook from within a tool (populated by Thread). */
|
|
544
|
+
notifyHook?: (event: string, input: Record<string, unknown>) => Promise<void>;
|
|
545
|
+
}
|
|
546
|
+
interface ToolParameterProperty {
|
|
547
|
+
type: string;
|
|
548
|
+
description?: string;
|
|
549
|
+
enum?: string[];
|
|
550
|
+
default?: unknown;
|
|
551
|
+
minimum?: number;
|
|
552
|
+
maximum?: number;
|
|
553
|
+
}
|
|
554
|
+
interface ToolParameters {
|
|
555
|
+
type: "object";
|
|
556
|
+
properties: Record<string, ToolParameterProperty>;
|
|
557
|
+
required?: string[];
|
|
558
|
+
}
|
|
559
|
+
interface Tool {
|
|
560
|
+
name: string;
|
|
561
|
+
description: string;
|
|
562
|
+
/**
|
|
563
|
+
* Long model-facing instructions sent as the tool's API description.
|
|
564
|
+
* When omitted, `description` is used instead. This allows a short
|
|
565
|
+
* `description` for UI/permission prompts while sending detailed
|
|
566
|
+
* usage guidance to the model.
|
|
567
|
+
*/
|
|
568
|
+
prompt?: string | (() => string);
|
|
569
|
+
parameters: ToolParameters;
|
|
570
|
+
/**
|
|
571
|
+
* Optional Zod schema for input validation. When present, tool input is
|
|
572
|
+
* validated via `safeParse` before execution. Validation errors are returned
|
|
573
|
+
* to the model as tool_result errors so it can self-correct.
|
|
574
|
+
*/
|
|
575
|
+
inputSchema?: ZodLikeSchema;
|
|
576
|
+
/**
|
|
577
|
+
* Raw JSON Schema for tool input — sent directly to providers that support
|
|
578
|
+
* strict mode. When omitted, `parameters` is used as the JSON schema.
|
|
579
|
+
*/
|
|
580
|
+
inputJSONSchema?: Record<string, unknown>;
|
|
581
|
+
/** Present on tools sourced from an MCP server */
|
|
582
|
+
mcpInfo?: {
|
|
583
|
+
serverName: string;
|
|
584
|
+
toolName: string;
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* Whether this tool only reads state and never mutates it.
|
|
588
|
+
* When `true`, the tool is auto-allowed in `default` mode for working directories
|
|
589
|
+
* and is permitted in `plan` mode. Can be a static boolean or a function of the input.
|
|
590
|
+
* Defaults to `false` when omitted.
|
|
591
|
+
*/
|
|
592
|
+
isReadOnly?: boolean | ((args: Record<string, unknown>) => boolean);
|
|
593
|
+
/**
|
|
594
|
+
* Whether this tool performs irreversible/destructive operations.
|
|
595
|
+
* Used as metadata in permission requests so handlers can make informed decisions.
|
|
596
|
+
* Defaults to `false` when omitted.
|
|
597
|
+
*/
|
|
598
|
+
isDestructive?: boolean | ((args: Record<string, unknown>) => boolean);
|
|
599
|
+
/**
|
|
600
|
+
* Whether this tool can safely run concurrently with other concurrency-safe
|
|
601
|
+
* tools. Read-only tools are typically safe; tools that mutate shared state
|
|
602
|
+
* (filesystem writes, shell commands) are not. Can be a static boolean or a
|
|
603
|
+
* function of the input. Defaults to `false` when omitted.
|
|
604
|
+
*/
|
|
605
|
+
isConcurrencySafe?: boolean | ((args: Record<string, unknown>) => boolean);
|
|
606
|
+
/**
|
|
607
|
+
* Tool-specific permission check, called by the permission pipeline before
|
|
608
|
+
* global rules and mode-based decisions. Return `passthrough` to delegate
|
|
609
|
+
* to the global pipeline, or `allow`/`deny`/`ask` for tool-specific logic.
|
|
610
|
+
*/
|
|
611
|
+
checkPermissions?: (args: Record<string, unknown>, ctx: ToolContext) => Promise<PermissionResult> | PermissionResult;
|
|
612
|
+
/**
|
|
613
|
+
* When true, this tool always requires interactive user input and must
|
|
614
|
+
* prompt even in bypassPermissions mode (e.g. AskUser).
|
|
615
|
+
*/
|
|
616
|
+
requiresUserInteraction?: boolean;
|
|
617
|
+
call(args: Record<string, unknown>, ctx: ToolContext): Promise<ToolResult>;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export { type ZodLikeSchema as $, type PermissionDeniedHookInput as A, type PermissionRequestHookInput as B, type CommandResult as C, DiagnosticRegistry as D, type ExecOptions as E, type FileEntry as F, type RetryAttemptHookInput as G, type HookDefinition as H, type SafeParseResult as I, type JsonSchemaType as J, type SessionEndHookInput as K, type LspServerConfig as L, type MemoryUpdateHookInput as M, type NotificationHookInput as N, type SessionStartHookInput as O, type PostToolUseFailureHookInput as P, type SubagentStartHookInput as Q, type ReadOptions as R, type SubagentConfig as S, type Tool as T, type SubagentStopHookInput as U, type VirtualFs as V, type Task as W, type TaskCreateInput as X, type TaskStatus as Y, type TaskUpdateInput as Z, type ToolParameters as _, type LspServerState as a, formatZodValidationError as a0, registerZodToJsonSchema as a1, zodToJsonSchema as a2, type LspDiagnostic as b, type LspLocation as c, type LspOperation as d, LspServerManager as e, type LspSymbol as f, type ToolResult as g, type ToolContext as h, type FileStat as i, type VirtualComputer as j, type SubagentRun as k, TaskStore as l, FileCheckpointManager as m, type FileStateCacheConfig as n, type HookEvent as o, type HookInput as p, type PostToolUseFailureHookOutput as q, type PostToolUseHookInput as r, type PostToolUseHookOutput as s, type PreToolUseHookInput as t, type PreToolUseHookOutput as u, type FileState as v, FileStateCache as w, type FileWriteHookInput as x, type HookOutput as y, type ModelSwitchHookInput as z };
|