@cuylabs/agent-core 0.3.0 → 0.5.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.
Files changed (66) hide show
  1. package/README.md +216 -41
  2. package/dist/builder-RcTZuYnO.d.ts +34 -0
  3. package/dist/capabilities/index.d.ts +97 -0
  4. package/dist/capabilities/index.js +46 -0
  5. package/dist/chunk-6TDTQJ4P.js +116 -0
  6. package/dist/chunk-7MUFEN4K.js +559 -0
  7. package/dist/chunk-BDBZ3SLK.js +745 -0
  8. package/dist/chunk-DWYX7ASF.js +26 -0
  9. package/dist/chunk-FG4MD5MU.js +54 -0
  10. package/dist/chunk-IMGQOTU2.js +2019 -0
  11. package/dist/chunk-IVUJDISU.js +556 -0
  12. package/dist/chunk-LRHOS4ZN.js +584 -0
  13. package/dist/chunk-OTUGSCED.js +691 -0
  14. package/dist/chunk-P6YF7USR.js +182 -0
  15. package/dist/chunk-QAQADS4X.js +258 -0
  16. package/dist/chunk-QWFMX226.js +879 -0
  17. package/dist/{chunk-6VKLWNRE.js → chunk-SDSBEQXG.js} +1 -132
  18. package/dist/chunk-VBWWUHWI.js +724 -0
  19. package/dist/chunk-VEKUXUVF.js +41 -0
  20. package/dist/chunk-X635CM2F.js +305 -0
  21. package/dist/chunk-YUUJK53A.js +91 -0
  22. package/dist/chunk-ZXAKHMWH.js +283 -0
  23. package/dist/config-D2xeGEHK.d.ts +52 -0
  24. package/dist/context/index.d.ts +259 -0
  25. package/dist/context/index.js +26 -0
  26. package/dist/identifiers-BLUxFqV_.d.ts +12 -0
  27. package/dist/index-p0kOsVsE.d.ts +1067 -0
  28. package/dist/index-tmhaADz5.d.ts +198 -0
  29. package/dist/index.d.ts +185 -4316
  30. package/dist/index.js +1238 -5368
  31. package/dist/mcp/index.d.ts +26 -0
  32. package/dist/mcp/index.js +14 -0
  33. package/dist/messages-BYWGn8TY.d.ts +110 -0
  34. package/dist/middleware/index.d.ts +7 -0
  35. package/dist/middleware/index.js +12 -0
  36. package/dist/models/index.d.ts +33 -0
  37. package/dist/models/index.js +12 -0
  38. package/dist/network-D76DS5ot.d.ts +5 -0
  39. package/dist/prompt/index.d.ts +224 -0
  40. package/dist/prompt/index.js +45 -0
  41. package/dist/reasoning/index.d.ts +71 -0
  42. package/dist/reasoning/index.js +47 -0
  43. package/dist/registry-CuRWWtcT.d.ts +164 -0
  44. package/dist/resolver-DOfZ-xuk.d.ts +254 -0
  45. package/dist/runner-C7aMP_x3.d.ts +596 -0
  46. package/dist/runtime/index.d.ts +357 -0
  47. package/dist/runtime/index.js +64 -0
  48. package/dist/session-manager-Uawm2Le7.d.ts +274 -0
  49. package/dist/skill/index.d.ts +103 -0
  50. package/dist/skill/index.js +39 -0
  51. package/dist/storage/index.d.ts +167 -0
  52. package/dist/storage/index.js +50 -0
  53. package/dist/sub-agent/index.d.ts +14 -0
  54. package/dist/sub-agent/index.js +15 -0
  55. package/dist/tool/index.d.ts +173 -1
  56. package/dist/tool/index.js +12 -3
  57. package/dist/tool-DYp6-cC3.d.ts +239 -0
  58. package/dist/tool-pFAnJc5Y.d.ts +419 -0
  59. package/dist/tracker-DClqYqTj.d.ts +96 -0
  60. package/dist/tracking/index.d.ts +109 -0
  61. package/dist/tracking/index.js +20 -0
  62. package/dist/types-CQaXbRsS.d.ts +47 -0
  63. package/dist/types-MM1JoX5T.d.ts +810 -0
  64. package/dist/types-VQgymC1N.d.ts +156 -0
  65. package/package.json +89 -5
  66. package/dist/index-QR704uRr.d.ts +0 -472
@@ -1,472 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * ToolHost — execution environment abstraction for agent tools.
5
- *
6
- * A ToolHost defines *where* tools execute: local machine, Docker container,
7
- * SSH remote, etc. Every host provides two surfaces:
8
- *
9
- * 1. **File system** — read, write, stat, list, check existence
10
- * 2. **Process execution** — spawn commands, kill processes
11
- *
12
- * Tools call `ctx.host.readFile()` / `ctx.host.exec()` instead of importing
13
- * `fs` and `child_process` directly. The host implementation handles the rest.
14
- *
15
- * @example
16
- * ```typescript
17
- * // Default: runs everything locally
18
- * const agent = createAgent({ host: localHost() });
19
- *
20
- * // Future: run tools inside a Docker container
21
- * const agent = createAgent({ host: dockerHost("my-container") });
22
- * ```
23
- */
24
- /** Options for spawning a process. */
25
- interface ExecOptions {
26
- /** Working directory for the command. */
27
- cwd?: string;
28
- /** Environment variables (merged with host defaults). */
29
- env?: Record<string, string | undefined>;
30
- /** Abort signal for cancellation. */
31
- signal?: AbortSignal;
32
- /** Timeout in milliseconds. 0 = no timeout. */
33
- timeout?: number;
34
- /** Callback for stdout data as it arrives. */
35
- onStdout?: (data: Buffer) => void;
36
- /** Callback for stderr data as it arrives. */
37
- onStderr?: (data: Buffer) => void;
38
- }
39
- /** Result of a process execution. */
40
- interface ExecResult {
41
- /** Combined stdout output. */
42
- stdout: string;
43
- /** Combined stderr output. */
44
- stderr: string;
45
- /** Exit code (null if killed by signal). */
46
- exitCode: number | null;
47
- /** Whether the process was killed due to timeout. */
48
- timedOut: boolean;
49
- }
50
- /** Minimal stat result — only the fields tools actually need. */
51
- interface FileStat {
52
- /** File size in bytes. */
53
- size: number;
54
- /** Last modification time. */
55
- mtime: Date;
56
- /** Whether this entry is a directory. */
57
- isDirectory: boolean;
58
- /** Whether this entry is a regular file. */
59
- isFile: boolean;
60
- }
61
- /** A directory entry returned by `readdir`. */
62
- interface DirEntry {
63
- /** Entry name (not full path). */
64
- name: string;
65
- /** Whether this entry is a directory. */
66
- isDirectory: boolean;
67
- /** Whether this entry is a regular file. */
68
- isFile: boolean;
69
- }
70
- /**
71
- * The execution environment for agent tools.
72
- *
73
- * Abstracts filesystem and process operations so tools work identically
74
- * whether running locally, in Docker, over SSH, or in any other environment.
75
- */
76
- interface ToolHost {
77
- /** Human-readable host identifier (e.g. "local", "docker:my-container"). */
78
- readonly name: string;
79
- /** Read a file as a UTF-8 string. Throws if the file doesn't exist. */
80
- readFile(path: string): Promise<string>;
81
- /** Read raw bytes from a file. Throws if the file doesn't exist. */
82
- readBytes(path: string, offset: number, length: number): Promise<Buffer>;
83
- /** Write a UTF-8 string to a file. Creates parent directories as needed. */
84
- writeFile(path: string, content: string): Promise<void>;
85
- /** Check if a path exists. Never throws. */
86
- exists(path: string): Promise<boolean>;
87
- /** Get file metadata. Throws if the path doesn't exist. */
88
- stat(path: string): Promise<FileStat>;
89
- /** List directory entries. Throws if the path is not a directory. */
90
- readdir(path: string): Promise<DirEntry[]>;
91
- /** Create directories recursively. No-op if they already exist. */
92
- mkdir(path: string): Promise<void>;
93
- /**
94
- * Execute a shell command.
95
- *
96
- * The host decides which shell to use (e.g. local host uses the user's
97
- * `$SHELL`, Docker host uses `docker exec`, SSH host uses remote shell).
98
- */
99
- exec(command: string, options?: ExecOptions): Promise<ExecResult>;
100
- }
101
-
102
- /**
103
- * Tool-related types for @cuylabs/agent-core
104
- *
105
- * Defines the interfaces for tool execution context, results,
106
- * and metadata used throughout the agent system.
107
- */
108
-
109
- /**
110
- * Turn tracker interface for tool context
111
- * Minimal interface to avoid circular dependencies
112
- */
113
- interface TurnTrackerContext {
114
- /** Capture baseline before writing to a file */
115
- beforeWrite(path: string): Promise<boolean>;
116
- /** Check if a file is being tracked */
117
- isTracking(path: string): boolean;
118
- }
119
- /**
120
- * Tool execution context
121
- */
122
- interface ToolContext {
123
- /** Working directory for file operations */
124
- cwd: string;
125
- /** Abort signal for cancellation */
126
- abort: AbortSignal;
127
- /** Session ID */
128
- sessionID: string;
129
- /** Message ID */
130
- messageID: string;
131
- /** Agent name */
132
- agent: string;
133
- /**
134
- * Execution environment for file and process operations.
135
- *
136
- * Tools should call `ctx.host.readFile()`, `ctx.host.exec()`, etc.
137
- * instead of importing `fs` and `child_process` directly. This
138
- * allows the same tools to work on local, Docker, SSH, or any
139
- * other host without code changes.
140
- *
141
- * When not provided, tools may fall back to direct Node.js APIs,
142
- * but new tools should always prefer `ctx.host`.
143
- */
144
- host?: ToolHost;
145
- /**
146
- * Turn change tracker - automatically captures file baselines.
147
- * Call `turnTracker.beforeWrite(path)` before modifying files
148
- * for undo/diff capabilities.
149
- */
150
- turnTracker?: TurnTrackerContext;
151
- /** Extra context data */
152
- extra?: Record<string, unknown>;
153
- }
154
- /**
155
- * Result returned by a tool
156
- */
157
- interface ToolResult {
158
- /** Short title for display */
159
- title: string;
160
- /** Main output text */
161
- output: string;
162
- /** Optional metadata */
163
- metadata?: ToolMetadata;
164
- }
165
- /**
166
- * File operation metadata - declare how a tool modifies files
167
- * Used by TurnChangeTracker for automatic baseline capture
168
- */
169
- interface FileOperationMeta {
170
- /**
171
- * Names of parameters that contain file paths to track.
172
- * The tracker will capture baselines for these files before the tool runs.
173
- * @example ['path'] for write tool, ['filePath'] for edit tool
174
- */
175
- pathArgs?: string[];
176
- /**
177
- * Type of file operation - determines if baseline capture is needed.
178
- * - 'read': No baseline capture (file not modified)
179
- * - 'write': Capture baseline before overwriting
180
- * - 'create': Capture baseline (to know file didn't exist)
181
- * - 'delete': Capture baseline before deletion
182
- */
183
- operationType?: "read" | "write" | "delete" | "create";
184
- }
185
- /**
186
- * Tool metadata
187
- */
188
- interface ToolMetadata {
189
- /** Whether output was truncated */
190
- truncated?: boolean;
191
- /** Path to full output if truncated */
192
- outputPath?: string;
193
- /**
194
- * File operation metadata for automatic turn tracking.
195
- * When set, the agent will automatically capture file baselines
196
- * before tool execution for undo/diff capabilities.
197
- */
198
- fileOps?: FileOperationMeta;
199
- /** Additional metadata */
200
- [key: string]: unknown;
201
- }
202
-
203
- /**
204
- * Tool definition namespace for @cuylabs/agent-core
205
- *
206
- * Following OpenCode's Tool.define pattern for consistent tool creation.
207
- */
208
-
209
- /**
210
- * A schema type compatible with both Zod 3 and Zod 4.
211
- *
212
- * Uses structural typing so that schemas from either Zod version satisfy
213
- * the constraint. This avoids the problem where Zod 3's `ZodType` class
214
- * and Zod 4's `ZodType` class have incompatible internal shapes, causing
215
- * type errors when a library compiled against one version is consumed with
216
- * the other.
217
- *
218
- * Both Zod 3 and Zod 4 (classic API) schemas have `parse()` and `_output`.
219
- */
220
- interface CompatibleSchema<T = any> {
221
- /** Parse and validate input data. Present in both Zod 3 and Zod 4. */
222
- parse(data: unknown): T;
223
- /**
224
- * Type-level output marker used by both Zod versions:
225
- * - Zod 3: `readonly _output!: T` (definite assignment assertion)
226
- * - Zod 4 classic: `get _output(): T` (getter)
227
- */
228
- readonly _output: T;
229
- }
230
- /**
231
- * Infer the output type from a compatible schema.
232
- * Equivalent to `z.infer<T>` but works with both Zod 3 and Zod 4 schemas.
233
- */
234
- type InferSchemaOutput<T extends CompatibleSchema> = T["_output"];
235
- /**
236
- * Tool namespace - OpenCode-style tool definition
237
- */
238
- declare namespace Tool {
239
- /**
240
- * Tool info interface - the shape of a defined tool
241
- */
242
- interface Info<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
243
- /** Unique tool identifier */
244
- id: string;
245
- /** Initialize the tool (can be async for dynamic descriptions) */
246
- init: (ctx?: InitContext) => Promise<InitResult<TParams, TMeta>> | InitResult<TParams, TMeta>;
247
- }
248
- /**
249
- * Any tool info - for use in arrays and collections where generic types vary
250
- */
251
- type AnyInfo = Info<any, any>;
252
- /**
253
- * Context passed during tool initialization
254
- */
255
- interface InitContext {
256
- /** Working directory */
257
- cwd?: string;
258
- /** Agent name (if known) */
259
- agent?: string;
260
- }
261
- /**
262
- * Result of tool initialization
263
- */
264
- interface InitResult<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
265
- /** Tool description for the LLM */
266
- description: string;
267
- /** Zod schema for parameters */
268
- parameters: TParams;
269
- /** Execute the tool */
270
- execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
271
- /** Optional custom validation error formatter */
272
- formatValidationError?: (error: z.ZodError) => string;
273
- /**
274
- * File operation metadata for automatic turn tracking.
275
- * When set, the agent will automatically capture file baselines
276
- * before tool execution for undo/diff capabilities.
277
- *
278
- * @example
279
- * ```typescript
280
- * // For a write tool
281
- * fileOps: {
282
- * pathArgs: ['path'],
283
- * operationType: 'write'
284
- * }
285
- * ```
286
- */
287
- fileOps?: FileOperationMeta;
288
- }
289
- /**
290
- * Result of tool execution
291
- */
292
- interface ExecuteResult<TMeta extends ToolMetadata = ToolMetadata> {
293
- /** Short title for display */
294
- title: string;
295
- /** Main output text */
296
- output: string;
297
- /** Metadata */
298
- metadata: TMeta;
299
- }
300
- /**
301
- * Define a tool with OpenCode-style patterns
302
- *
303
- * @example
304
- * ```typescript
305
- * const myTool = Tool.define("my_tool", {
306
- * description: "Does something useful",
307
- * parameters: z.object({
308
- * input: z.string().describe("The input to process"),
309
- * }),
310
- * execute: async (params, ctx) => ({
311
- * title: "Processed",
312
- * output: `Result: ${params.input}`,
313
- * metadata: {},
314
- * }),
315
- * });
316
- * ```
317
- */
318
- function define<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, init: Info<TParams, TMeta>["init"] | Awaited<ReturnType<Info<TParams, TMeta>["init"]>>): Info<TParams, TMeta>;
319
- /**
320
- * Simple define for static tools (no async init)
321
- */
322
- function defineSimple<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, config: {
323
- description: string;
324
- parameters: TParams;
325
- execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
326
- }): Info<TParams, TMeta>;
327
- }
328
- /**
329
- * Legacy helper - wraps to Tool.Info format
330
- *
331
- * @deprecated Use Tool.define instead
332
- */
333
- declare function defineTool<TParams extends CompatibleSchema>(definition: {
334
- id: string;
335
- description: string;
336
- parameters: TParams;
337
- execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ToolResult>;
338
- }): Tool.Info<TParams>;
339
-
340
- /**
341
- * Tool registry for @cuylabs/agent-core
342
- *
343
- * Manages available tools, named groups, and resolution from specs.
344
- */
345
-
346
- /**
347
- * A tool spec that can be resolved to an array of tools.
348
- *
349
- * - `string` — group name (`"read-only"`), single tool ID (`"bash"`),
350
- * or comma-separated list (`"read,grep,glob"`).
351
- * Prefix with `-` to exclude: `"all,-bash"`.
352
- * - `string[]` — array of tool IDs and/or group names.
353
- * - `Tool.AnyInfo[]` — pass-through (already resolved).
354
- * - `true` — all registered tools.
355
- * - `false` — no tools.
356
- */
357
- type ToolSpec = string | string[] | Tool.AnyInfo[] | boolean;
358
- /**
359
- * Tool registry — manages available tools and named groups.
360
- *
361
- * Tools are registered individually. Groups are named collections of tool IDs
362
- * that resolve against the registry at lookup time.
363
- *
364
- * @example
365
- * ```typescript
366
- * const reg = new ToolRegistry();
367
- * reg.registerAll([readTool, grepTool, bashTool]);
368
- * reg.registerGroup("read-only", ["read", "grep", "glob"]);
369
- *
370
- * // Resolve a spec to a tool array
371
- * reg.resolve("read-only"); // → [readTool, grepTool]
372
- * reg.resolve("all,-bash"); // → [readTool, grepTool]
373
- * reg.resolve(["read", "grep"]); // → [readTool, grepTool]
374
- * reg.resolve(true); // → all tools
375
- * ```
376
- */
377
- declare class ToolRegistry {
378
- private tools;
379
- private groups;
380
- /**
381
- * Register a tool. Throws if a tool with the same ID is already registered.
382
- * Use `set()` for upsert semantics.
383
- */
384
- register(tool: Tool.AnyInfo): void;
385
- /** Register multiple tools (throws on duplicates). */
386
- registerAll(tools: Tool.AnyInfo[]): void;
387
- /** Register or replace a tool (upsert). */
388
- set(tool: Tool.AnyInfo): void;
389
- /** Unregister a tool by ID. Returns `true` if it existed. */
390
- unregister(id: string): boolean;
391
- /** Get a tool by ID. */
392
- get(id: string): Tool.AnyInfo | undefined;
393
- /** Check if a tool is registered. */
394
- has(id: string): boolean;
395
- /** Get all tool IDs. */
396
- ids(): string[];
397
- /** Get all tools. */
398
- all(): Tool.AnyInfo[];
399
- /** Clear all tools and groups. */
400
- clear(): void;
401
- /** Number of registered tools. */
402
- get size(): number;
403
- /**
404
- * Register a named group of tool IDs.
405
- * The group name can be used in `resolve()` specs.
406
- * Tool IDs don't need to be registered yet — resolution is lazy.
407
- */
408
- registerGroup(name: string, toolIds: string[]): void;
409
- /** Get tools in a group (only returns registered tools). */
410
- getGroup(name: string): Tool.AnyInfo[] | undefined;
411
- /** Check if a group is registered. */
412
- hasGroup(name: string): boolean;
413
- /** List all group names. */
414
- listGroups(): string[];
415
- /**
416
- * Resolve a `ToolSpec` to an array of tools.
417
- *
418
- * Supports group names, individual tool IDs, comma-separated strings,
419
- * exclusions with `-` prefix, booleans, and pass-through arrays.
420
- *
421
- * @example
422
- * ```typescript
423
- * registry.resolve("read-only"); // group name
424
- * registry.resolve("read,grep,glob"); // comma-separated IDs
425
- * registry.resolve("all,-bash"); // all except bash
426
- * registry.resolve(["read", "grep"]); // array of IDs
427
- * registry.resolve(true); // all registered tools
428
- * registry.resolve(false); // empty array
429
- * ```
430
- */
431
- resolve(spec: ToolSpec): Tool.AnyInfo[];
432
- }
433
- /**
434
- * Default tool registry instance.
435
- * Shared across the application — register tools here for global access.
436
- */
437
- declare const defaultRegistry: ToolRegistry;
438
-
439
- /**
440
- * Output truncation utilities for @cuylabs/agent-core
441
- *
442
- * Based on OpenCode's tool/truncation.ts
443
- */
444
- /** Maximum lines before truncation */
445
- declare const MAX_LINES = 2000;
446
- /** Maximum bytes before truncation */
447
- declare const MAX_BYTES = 100000;
448
- /** Directory for storing truncated outputs */
449
- declare const TRUNCATE_DIR: string;
450
- /** Glob pattern for truncation directory */
451
- declare const TRUNCATE_GLOB: string;
452
- interface TruncateResult {
453
- /** The (possibly truncated) content */
454
- content: string;
455
- /** Whether the content was truncated */
456
- truncated: boolean;
457
- /** Path to full output if truncated */
458
- outputPath?: string;
459
- }
460
- /**
461
- * Truncate output if it exceeds limits
462
- */
463
- declare function truncateOutput(output: string, options?: {
464
- maxLines?: number;
465
- maxBytes?: number;
466
- }): TruncateResult;
467
- /**
468
- * Format file size for display
469
- */
470
- declare function formatSize(bytes: number): string;
471
-
472
- export { type CompatibleSchema as C, type DirEntry as D, type ExecOptions as E, type FileOperationMeta as F, type InferSchemaOutput as I, MAX_BYTES as M, type ToolHost as T, Tool as a, type TurnTrackerContext as b, type ExecResult as c, type FileStat as d, MAX_LINES as e, TRUNCATE_DIR as f, TRUNCATE_GLOB as g, type ToolContext as h, type ToolMetadata as i, ToolRegistry as j, type ToolResult as k, type ToolSpec as l, type TruncateResult as m, defaultRegistry as n, defineTool as o, formatSize as p, truncateOutput as t };