@cuylabs/agent-core 0.4.0 → 0.6.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 +81 -323
- package/dist/builder-BKkipazh.d.ts +34 -0
- package/dist/capabilities/index.d.ts +97 -0
- package/dist/capabilities/index.js +46 -0
- package/dist/chunk-3C4VKG4P.js +2149 -0
- package/dist/chunk-6TDTQJ4P.js +116 -0
- package/dist/chunk-7MUFEN4K.js +559 -0
- package/dist/chunk-BDBZ3SLK.js +745 -0
- package/dist/chunk-DWYX7ASF.js +26 -0
- package/dist/chunk-FG4MD5MU.js +54 -0
- package/dist/chunk-IVUJDISU.js +556 -0
- package/dist/chunk-LRHOS4ZN.js +584 -0
- package/dist/chunk-O2ZCFQL6.js +764 -0
- package/dist/chunk-P6YF7USR.js +182 -0
- package/dist/chunk-QAQADS4X.js +258 -0
- package/dist/chunk-QWFMX226.js +879 -0
- package/dist/{chunk-6VKLWNRE.js → chunk-SDSBEQXG.js} +1 -132
- package/dist/chunk-VBWWUHWI.js +724 -0
- package/dist/chunk-VEKUXUVF.js +41 -0
- package/dist/chunk-X635CM2F.js +305 -0
- package/dist/chunk-YUUJK53A.js +91 -0
- package/dist/chunk-ZXAKHMWH.js +283 -0
- package/dist/config-D2xeGEHK.d.ts +52 -0
- package/dist/context/index.d.ts +259 -0
- package/dist/context/index.js +26 -0
- package/dist/identifiers-BLUxFqV_.d.ts +12 -0
- package/dist/index-DZQJD_hp.d.ts +1067 -0
- package/dist/index-ipP3_ztp.d.ts +198 -0
- package/dist/index.d.ts +210 -5736
- package/dist/index.js +2132 -7767
- package/dist/mcp/index.d.ts +26 -0
- package/dist/mcp/index.js +14 -0
- package/dist/messages-BYWGn8TY.d.ts +110 -0
- package/dist/middleware/index.d.ts +8 -0
- package/dist/middleware/index.js +12 -0
- package/dist/models/index.d.ts +33 -0
- package/dist/models/index.js +12 -0
- package/dist/network-D76DS5ot.d.ts +5 -0
- package/dist/prompt/index.d.ts +225 -0
- package/dist/prompt/index.js +45 -0
- package/dist/reasoning/index.d.ts +71 -0
- package/dist/reasoning/index.js +47 -0
- package/dist/registry-CuRWWtcT.d.ts +164 -0
- package/dist/resolver-DOfZ-xuk.d.ts +254 -0
- package/dist/runner-G1wxEgac.d.ts +852 -0
- package/dist/runtime/index.d.ts +357 -0
- package/dist/runtime/index.js +64 -0
- package/dist/session-manager-Uawm2Le7.d.ts +274 -0
- package/dist/skill/index.d.ts +103 -0
- package/dist/skill/index.js +39 -0
- package/dist/storage/index.d.ts +167 -0
- package/dist/storage/index.js +50 -0
- package/dist/sub-agent/index.d.ts +14 -0
- package/dist/sub-agent/index.js +15 -0
- package/dist/tool/index.d.ts +174 -1
- package/dist/tool/index.js +12 -3
- package/dist/tool-DYp6-cC3.d.ts +239 -0
- package/dist/tool-pFAnJc5Y.d.ts +419 -0
- package/dist/tracker-DClqYqTj.d.ts +96 -0
- package/dist/tracking/index.d.ts +109 -0
- package/dist/tracking/index.js +20 -0
- package/dist/types-BWo810L_.d.ts +648 -0
- package/dist/types-CQaXbRsS.d.ts +47 -0
- package/dist/types-VQgymC1N.d.ts +156 -0
- package/package.json +89 -5
- package/dist/index-BlSTfS-W.d.ts +0 -470
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolHost — execution environment abstraction for agent tools.
|
|
3
|
+
*
|
|
4
|
+
* A ToolHost defines *where* tools execute: local machine, Docker container,
|
|
5
|
+
* SSH remote, etc. Every host provides two surfaces:
|
|
6
|
+
*
|
|
7
|
+
* 1. **File system** — read, write, stat, list, check existence
|
|
8
|
+
* 2. **Process execution** — spawn commands, kill processes
|
|
9
|
+
*
|
|
10
|
+
* Tools call `ctx.host.readFile()` / `ctx.host.exec()` instead of importing
|
|
11
|
+
* `fs` and `child_process` directly. The host implementation handles the rest.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Default: runs everything locally
|
|
16
|
+
* const agent = createAgent({ host: localHost() });
|
|
17
|
+
*
|
|
18
|
+
* // Future: run tools inside a Docker container
|
|
19
|
+
* const agent = createAgent({ host: dockerHost("my-container") });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
/** Options for spawning a process. */
|
|
23
|
+
interface ExecOptions {
|
|
24
|
+
/** Working directory for the command. */
|
|
25
|
+
cwd?: string;
|
|
26
|
+
/** Environment variables (merged with host defaults). */
|
|
27
|
+
env?: Record<string, string | undefined>;
|
|
28
|
+
/** Abort signal for cancellation. */
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
/** Timeout in milliseconds. 0 = no timeout. */
|
|
31
|
+
timeout?: number;
|
|
32
|
+
/** Callback for stdout data as it arrives. */
|
|
33
|
+
onStdout?: (data: Buffer) => void;
|
|
34
|
+
/** Callback for stderr data as it arrives. */
|
|
35
|
+
onStderr?: (data: Buffer) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Result of a process execution. */
|
|
38
|
+
interface ExecResult {
|
|
39
|
+
/** Combined stdout output. */
|
|
40
|
+
stdout: string;
|
|
41
|
+
/** Combined stderr output. */
|
|
42
|
+
stderr: string;
|
|
43
|
+
/** Exit code (null if killed by signal). */
|
|
44
|
+
exitCode: number | null;
|
|
45
|
+
/** Whether the process was killed due to timeout. */
|
|
46
|
+
timedOut: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** Minimal stat result — only the fields tools actually need. */
|
|
49
|
+
interface FileStat {
|
|
50
|
+
/** File size in bytes. */
|
|
51
|
+
size: number;
|
|
52
|
+
/** Last modification time. */
|
|
53
|
+
mtime: Date;
|
|
54
|
+
/** Whether this entry is a directory. */
|
|
55
|
+
isDirectory: boolean;
|
|
56
|
+
/** Whether this entry is a regular file. */
|
|
57
|
+
isFile: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** A directory entry returned by `readdir`. */
|
|
60
|
+
interface DirEntry {
|
|
61
|
+
/** Entry name (not full path). */
|
|
62
|
+
name: string;
|
|
63
|
+
/** Whether this entry is a directory. */
|
|
64
|
+
isDirectory: boolean;
|
|
65
|
+
/** Whether this entry is a regular file. */
|
|
66
|
+
isFile: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The execution environment for agent tools.
|
|
70
|
+
*
|
|
71
|
+
* Abstracts filesystem and process operations so tools work identically
|
|
72
|
+
* whether running locally, in Docker, over SSH, or in any other environment.
|
|
73
|
+
*/
|
|
74
|
+
interface ToolHost {
|
|
75
|
+
/** Human-readable host identifier (e.g. "local", "docker:my-container"). */
|
|
76
|
+
readonly name: string;
|
|
77
|
+
/** Read a file as a UTF-8 string. Throws if the file doesn't exist. */
|
|
78
|
+
readFile(path: string): Promise<string>;
|
|
79
|
+
/** Read raw bytes from a file. Throws if the file doesn't exist. */
|
|
80
|
+
readBytes(path: string, offset: number, length: number): Promise<Buffer>;
|
|
81
|
+
/** Write a UTF-8 string to a file. Creates parent directories as needed. */
|
|
82
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
83
|
+
/** Check if a path exists. Never throws. */
|
|
84
|
+
exists(path: string): Promise<boolean>;
|
|
85
|
+
/** Get file metadata. Throws if the path doesn't exist. */
|
|
86
|
+
stat(path: string): Promise<FileStat>;
|
|
87
|
+
/** List directory entries. Throws if the path is not a directory. */
|
|
88
|
+
readdir(path: string): Promise<DirEntry[]>;
|
|
89
|
+
/** Create directories recursively. No-op if they already exist. */
|
|
90
|
+
mkdir(path: string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Execute a shell command.
|
|
93
|
+
*
|
|
94
|
+
* The host decides which shell to use (e.g. local host uses the user's
|
|
95
|
+
* `$SHELL`, Docker host uses `docker exec`, SSH host uses remote shell).
|
|
96
|
+
*/
|
|
97
|
+
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Tool-related types for @cuylabs/agent-core
|
|
102
|
+
*
|
|
103
|
+
* Defines the interfaces for tool execution context, results,
|
|
104
|
+
* and metadata used throughout the agent system.
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Turn tracker interface for tool context
|
|
109
|
+
* Minimal interface to avoid circular dependencies
|
|
110
|
+
*/
|
|
111
|
+
interface TurnTrackerContext {
|
|
112
|
+
/** Capture baseline before writing to a file */
|
|
113
|
+
beforeWrite(path: string): Promise<boolean>;
|
|
114
|
+
/** Check if a file is being tracked */
|
|
115
|
+
isTracking(path: string): boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Tool execution context
|
|
119
|
+
*/
|
|
120
|
+
interface ToolContext {
|
|
121
|
+
/** Working directory for file operations */
|
|
122
|
+
cwd: string;
|
|
123
|
+
/** Abort signal for cancellation */
|
|
124
|
+
abort: AbortSignal;
|
|
125
|
+
/** Session ID */
|
|
126
|
+
sessionID: string;
|
|
127
|
+
/** Message ID */
|
|
128
|
+
messageID: string;
|
|
129
|
+
/** Agent name */
|
|
130
|
+
agent: string;
|
|
131
|
+
/**
|
|
132
|
+
* Execution environment for file and process operations.
|
|
133
|
+
*
|
|
134
|
+
* Tools should call `ctx.host.readFile()`, `ctx.host.exec()`, etc.
|
|
135
|
+
* instead of importing `fs` and `child_process` directly. This
|
|
136
|
+
* allows the same tools to work on local, Docker, SSH, or any
|
|
137
|
+
* other host without code changes.
|
|
138
|
+
*
|
|
139
|
+
* When not provided, tools may fall back to direct Node.js APIs,
|
|
140
|
+
* but new tools should always prefer `ctx.host`.
|
|
141
|
+
*/
|
|
142
|
+
host?: ToolHost;
|
|
143
|
+
/**
|
|
144
|
+
* Turn change tracker - automatically captures file baselines.
|
|
145
|
+
* Call `turnTracker.beforeWrite(path)` before modifying files
|
|
146
|
+
* for undo/diff capabilities.
|
|
147
|
+
*/
|
|
148
|
+
turnTracker?: TurnTrackerContext;
|
|
149
|
+
/** Extra context data */
|
|
150
|
+
extra?: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Result returned by a tool
|
|
154
|
+
*/
|
|
155
|
+
interface ToolResult {
|
|
156
|
+
/** Short title for display */
|
|
157
|
+
title: string;
|
|
158
|
+
/** Main output text */
|
|
159
|
+
output: string;
|
|
160
|
+
/** Optional metadata */
|
|
161
|
+
metadata?: ToolMetadata;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* File operation metadata - declare how a tool modifies files
|
|
165
|
+
* Used by TurnChangeTracker for automatic baseline capture
|
|
166
|
+
*/
|
|
167
|
+
interface FileOperationMeta {
|
|
168
|
+
/**
|
|
169
|
+
* Names of parameters that contain file paths to track.
|
|
170
|
+
* The tracker will capture baselines for these files before the tool runs.
|
|
171
|
+
* @example ['path'] for write tool, ['filePath'] for edit tool
|
|
172
|
+
*/
|
|
173
|
+
pathArgs?: string[];
|
|
174
|
+
/**
|
|
175
|
+
* Type of file operation - determines if baseline capture is needed.
|
|
176
|
+
* - 'read': No baseline capture (file not modified)
|
|
177
|
+
* - 'write': Capture baseline before overwriting
|
|
178
|
+
* - 'create': Capture baseline (to know file didn't exist)
|
|
179
|
+
* - 'delete': Capture baseline before deletion
|
|
180
|
+
*/
|
|
181
|
+
operationType?: "read" | "write" | "delete" | "create";
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Replay mode used by resume-capable runtimes after a crash.
|
|
185
|
+
*
|
|
186
|
+
* - `replay` — the tool may be executed again automatically
|
|
187
|
+
* - `skip` — the tool should not be replayed automatically
|
|
188
|
+
* - `manual` — a higher-level runtime must require an explicit decision
|
|
189
|
+
*/
|
|
190
|
+
type ToolReplayMode = "replay" | "skip" | "manual";
|
|
191
|
+
/**
|
|
192
|
+
* Coarse side-effect classification for tool execution.
|
|
193
|
+
*
|
|
194
|
+
* - `none` — read-only or otherwise safe to repeat
|
|
195
|
+
* - `local` — mutates local state such as files
|
|
196
|
+
* - `external` — may affect processes, networks, services, or systems
|
|
197
|
+
*/
|
|
198
|
+
type ToolSideEffectLevel = "none" | "local" | "external";
|
|
199
|
+
/**
|
|
200
|
+
* Declares how a resume-capable runtime should treat a tool after failure.
|
|
201
|
+
*
|
|
202
|
+
* This stays infrastructure-agnostic so Dapr and other runtimes can consume
|
|
203
|
+
* the same semantics without leaking runtime-specific types into `agent-core`.
|
|
204
|
+
*/
|
|
205
|
+
interface ToolReplayPolicy {
|
|
206
|
+
/** Replay behavior requested by the tool author. */
|
|
207
|
+
mode?: ToolReplayMode;
|
|
208
|
+
/** Coarse side-effect classification. */
|
|
209
|
+
sideEffectLevel?: ToolSideEffectLevel;
|
|
210
|
+
/** Optional human-readable rationale for audits and recovery UIs. */
|
|
211
|
+
reason?: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Fully resolved replay policy with defaults applied.
|
|
215
|
+
*/
|
|
216
|
+
interface NormalizedToolReplayPolicy {
|
|
217
|
+
mode: ToolReplayMode;
|
|
218
|
+
sideEffectLevel: ToolSideEffectLevel;
|
|
219
|
+
reason?: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Tool metadata
|
|
223
|
+
*/
|
|
224
|
+
interface ToolMetadata {
|
|
225
|
+
/** Whether output was truncated */
|
|
226
|
+
truncated?: boolean;
|
|
227
|
+
/** Path to full output if truncated */
|
|
228
|
+
outputPath?: string;
|
|
229
|
+
/**
|
|
230
|
+
* File operation metadata for automatic turn tracking.
|
|
231
|
+
* When set, the agent will automatically capture file baselines
|
|
232
|
+
* before tool execution for undo/diff capabilities.
|
|
233
|
+
*/
|
|
234
|
+
fileOps?: FileOperationMeta;
|
|
235
|
+
/** Additional metadata */
|
|
236
|
+
[key: string]: unknown;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export type { DirEntry as D, ExecOptions as E, FileOperationMeta as F, NormalizedToolReplayPolicy as N, ToolMetadata as T, ToolReplayPolicy as a, ToolContext as b, ToolResult as c, ToolHost as d, TurnTrackerContext as e, ExecResult as f, FileStat as g, ToolReplayMode as h, ToolSideEffectLevel as i };
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { T as ToolMetadata, a as ToolReplayPolicy, b as ToolContext, F as FileOperationMeta, c as ToolResult } from './tool-DYp6-cC3.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Skill System Types
|
|
6
|
+
*
|
|
7
|
+
* Skills are modular, on-demand knowledge packs that extend an agent's
|
|
8
|
+
* capabilities with specialized instructions, workflows, and resources.
|
|
9
|
+
*
|
|
10
|
+
* Design principles:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Progressive disclosure** — summaries always in context,
|
|
13
|
+
* full content loaded only when needed. Minimizes baseline token cost.
|
|
14
|
+
*
|
|
15
|
+
* 2. **Scoped priority** — project skills override user skills
|
|
16
|
+
* override global skills. Closest scope wins on name collision.
|
|
17
|
+
*
|
|
18
|
+
* 3. **Agent-initiated loading** — the agent decides when to
|
|
19
|
+
* activate a skill by calling the `skill` tool. No guesswork.
|
|
20
|
+
*
|
|
21
|
+
* 4. **Bundled resources** — skills can ship scripts,
|
|
22
|
+
* references, assets, and examples alongside instructions.
|
|
23
|
+
*
|
|
24
|
+
* 5. **Remote sources** — skills can be fetched from URLs,
|
|
25
|
+
* enabling shared skill repositories across teams.
|
|
26
|
+
*
|
|
27
|
+
* The lifecycle:
|
|
28
|
+
*
|
|
29
|
+
* Discovery → Registry → Summary injection → Agent tool call → Full load
|
|
30
|
+
*
|
|
31
|
+
* @packageDocumentation
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Where a skill was discovered, determining its override priority.
|
|
35
|
+
*
|
|
36
|
+
* When two skills share the same name, the narrower scope wins:
|
|
37
|
+
* project > user > global > builtin
|
|
38
|
+
*
|
|
39
|
+
* Uses a 4-tier hierarchy with names that are intuitive for
|
|
40
|
+
* library consumers.
|
|
41
|
+
*/
|
|
42
|
+
type SkillScope = "project" | "user" | "global" | "builtin";
|
|
43
|
+
/**
|
|
44
|
+
* How a skill was obtained — local filesystem or remote URL.
|
|
45
|
+
*/
|
|
46
|
+
type SkillSourceType = "local" | "remote";
|
|
47
|
+
/**
|
|
48
|
+
* Where a skill came from, for provenance tracking.
|
|
49
|
+
*/
|
|
50
|
+
interface SkillSource {
|
|
51
|
+
/** Local or remote origin */
|
|
52
|
+
type: SkillSourceType;
|
|
53
|
+
/** Root directory or URL this skill was discovered under */
|
|
54
|
+
root: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Classification of bundled resources within a skill directory.
|
|
58
|
+
*
|
|
59
|
+
* Resource taxonomy:
|
|
60
|
+
* - `script` — executable code for deterministic tasks (can be run without reading)
|
|
61
|
+
* - `reference` — documentation loaded into context on demand
|
|
62
|
+
* - `asset` — templates, images, fonts used in output (not read into context)
|
|
63
|
+
* - `example` — working code samples for the agent to learn from
|
|
64
|
+
*/
|
|
65
|
+
type SkillResourceType = "script" | "reference" | "asset" | "example";
|
|
66
|
+
/**
|
|
67
|
+
* A file bundled with a skill.
|
|
68
|
+
*
|
|
69
|
+
* Resources are discovered but NOT loaded into memory until the agent
|
|
70
|
+
* explicitly requests them. This is the L3 layer of progressive disclosure.
|
|
71
|
+
*/
|
|
72
|
+
interface SkillResource {
|
|
73
|
+
/** Path relative to the skill's base directory */
|
|
74
|
+
relativePath: string;
|
|
75
|
+
/** Classified resource type */
|
|
76
|
+
type: SkillResourceType;
|
|
77
|
+
/** Absolute path on disk (for local resources) */
|
|
78
|
+
absolutePath: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Lightweight skill metadata parsed from SKILL.md YAML frontmatter.
|
|
82
|
+
*
|
|
83
|
+
* This is the **L1 layer** — always present in the system prompt so the
|
|
84
|
+
* agent knows which skills exist. Kept intentionally small (~100 words each)
|
|
85
|
+
* to minimize baseline context cost.
|
|
86
|
+
*
|
|
87
|
+
* Uses YAML frontmatter in a SKILL.md file — the widely-adopted
|
|
88
|
+
* canonical format for skill definitions.
|
|
89
|
+
*/
|
|
90
|
+
interface SkillMetadata {
|
|
91
|
+
/** Unique skill identifier (from frontmatter `name`) */
|
|
92
|
+
name: string;
|
|
93
|
+
/**
|
|
94
|
+
* When to use this skill — the single most important field.
|
|
95
|
+
*
|
|
96
|
+
* This description is what the agent reads to decide whether to
|
|
97
|
+
* activate the skill. Should contain trigger phrases that match
|
|
98
|
+
* task types. Written for another LLM to consume, not humans.
|
|
99
|
+
*/
|
|
100
|
+
description: string;
|
|
101
|
+
/** Semantic version (from frontmatter, optional) */
|
|
102
|
+
version?: string;
|
|
103
|
+
/** Scope that determines override priority */
|
|
104
|
+
scope: SkillScope;
|
|
105
|
+
/** How this skill was obtained */
|
|
106
|
+
source: SkillSource;
|
|
107
|
+
/** Absolute path to the SKILL.md file */
|
|
108
|
+
filePath: string;
|
|
109
|
+
/** Directory containing the skill (parent of SKILL.md) */
|
|
110
|
+
baseDir: string;
|
|
111
|
+
/** Optional tags for categorization */
|
|
112
|
+
tags?: string[];
|
|
113
|
+
/**
|
|
114
|
+
* Names of skills this skill depends on.
|
|
115
|
+
* When this skill is loaded, its dependencies are suggested to be loaded too.
|
|
116
|
+
*/
|
|
117
|
+
dependencies?: string[];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Full skill content including the markdown body and resource listing.
|
|
121
|
+
*
|
|
122
|
+
* This is the **L2 layer** — loaded only when the agent calls the skill
|
|
123
|
+
* tool. Contains the actual instructions plus awareness of bundled resources.
|
|
124
|
+
*/
|
|
125
|
+
interface SkillContent extends SkillMetadata {
|
|
126
|
+
/**
|
|
127
|
+
* The full markdown body of SKILL.md (everything below the frontmatter).
|
|
128
|
+
* This is the core instructional content injected into the conversation.
|
|
129
|
+
*/
|
|
130
|
+
body: string;
|
|
131
|
+
/**
|
|
132
|
+
* Bundled resources discovered in the skill directory.
|
|
133
|
+
* Listed so the agent knows what's available but not yet loaded.
|
|
134
|
+
*/
|
|
135
|
+
resources: SkillResource[];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Configuration for skill discovery and loading.
|
|
139
|
+
*
|
|
140
|
+
* Controls where skills are found, how deep to scan, and which
|
|
141
|
+
* external conventions to support.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const skillConfig: SkillConfig = {
|
|
146
|
+
* // Scan standard locations
|
|
147
|
+
* externalDirs: [".agents", ".claude"],
|
|
148
|
+
* // Add custom skill roots
|
|
149
|
+
* roots: ["./company-skills"],
|
|
150
|
+
* // Limit scan depth for performance
|
|
151
|
+
* maxScanDepth: 4,
|
|
152
|
+
* };
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
interface SkillConfig {
|
|
156
|
+
/**
|
|
157
|
+
* Additional directories to scan for skills (absolute or relative to cwd).
|
|
158
|
+
* Each directory is scanned recursively for SKILL.md files.
|
|
159
|
+
*/
|
|
160
|
+
roots?: string[];
|
|
161
|
+
/**
|
|
162
|
+
* External skill directory names to scan in project and home directories.
|
|
163
|
+
*
|
|
164
|
+
* These are checked as `<project>/<dir>/skills/` and `~/<dir>/skills/`.
|
|
165
|
+
* Supports `.claude` and `.agents` directory conventions.
|
|
166
|
+
*
|
|
167
|
+
* @default [".agents", ".claude"]
|
|
168
|
+
*/
|
|
169
|
+
externalDirs?: string[];
|
|
170
|
+
/**
|
|
171
|
+
* Maximum directory depth to scan within each root.
|
|
172
|
+
* Higher values find more deeply nested skills but take longer.
|
|
173
|
+
*
|
|
174
|
+
* @default 4
|
|
175
|
+
*/
|
|
176
|
+
maxScanDepth?: number;
|
|
177
|
+
/**
|
|
178
|
+
* Maximum file size for SKILL.md files in bytes.
|
|
179
|
+
* Skills larger than this are skipped with a warning.
|
|
180
|
+
*
|
|
181
|
+
* @default 102400 (100KB)
|
|
182
|
+
*/
|
|
183
|
+
maxFileSize?: number;
|
|
184
|
+
/**
|
|
185
|
+
* Enable fetching skills from remote URLs.
|
|
186
|
+
* When false, `remoteUrls` is ignored.
|
|
187
|
+
*
|
|
188
|
+
* @default false
|
|
189
|
+
*/
|
|
190
|
+
enableRemote?: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Remote skill index URLs to fetch.
|
|
193
|
+
*
|
|
194
|
+
* Each URL should serve a JSON index listing available skills.
|
|
195
|
+
* See `RemoteSkillIndex` for the expected format.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* remoteUrls: ["https://skills.example.com/index.json"]
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
remoteUrls?: string[];
|
|
203
|
+
/**
|
|
204
|
+
* Cache directory for remote skills.
|
|
205
|
+
* Defaults to `~/.cache/cuylabs/skills/`.
|
|
206
|
+
*/
|
|
207
|
+
remoteCacheDir?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Include built-in skills bundled with agent-core.
|
|
210
|
+
* Currently reserved for future use.
|
|
211
|
+
*
|
|
212
|
+
* @default true
|
|
213
|
+
*/
|
|
214
|
+
includeBuiltin?: boolean;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Schema for remote skill index JSON files.
|
|
218
|
+
*
|
|
219
|
+
* Hosted at a URL like `https://skills.example.com/index.json`.
|
|
220
|
+
* Enables team-wide or organization-wide skill sharing.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```json
|
|
224
|
+
* {
|
|
225
|
+
* "version": 1,
|
|
226
|
+
* "skills": [
|
|
227
|
+
* {
|
|
228
|
+
* "name": "testing",
|
|
229
|
+
* "files": ["SKILL.md", "scripts/run-tests.sh", "references/patterns.md"]
|
|
230
|
+
* }
|
|
231
|
+
* ]
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
interface RemoteSkillIndex {
|
|
236
|
+
/** Schema version (currently 1) */
|
|
237
|
+
version: number;
|
|
238
|
+
/** List of available skills */
|
|
239
|
+
skills: RemoteSkillEntry[];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* A single skill listing in a remote index.
|
|
243
|
+
*/
|
|
244
|
+
interface RemoteSkillEntry {
|
|
245
|
+
/** Skill name (must match the `name` in SKILL.md frontmatter) */
|
|
246
|
+
name: string;
|
|
247
|
+
/** Relative file paths to download (SKILL.md is required) */
|
|
248
|
+
files: string[];
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Result of a full skill discovery pass.
|
|
252
|
+
*/
|
|
253
|
+
interface SkillDiscoveryResult {
|
|
254
|
+
/** All discovered skills (deduplicated, scope-prioritized) */
|
|
255
|
+
skills: SkillMetadata[];
|
|
256
|
+
/** Skills that failed to load with reasons */
|
|
257
|
+
errors: SkillDiscoveryError[];
|
|
258
|
+
/** Total directories scanned */
|
|
259
|
+
dirsScanned: number;
|
|
260
|
+
/** Discovery duration in milliseconds */
|
|
261
|
+
durationMs: number;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* An error encountered during skill discovery.
|
|
265
|
+
*/
|
|
266
|
+
interface SkillDiscoveryError {
|
|
267
|
+
/** Path that caused the error */
|
|
268
|
+
path: string;
|
|
269
|
+
/** What went wrong */
|
|
270
|
+
reason: string;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Tool definition namespace for @cuylabs/agent-core
|
|
275
|
+
*
|
|
276
|
+
* Provides consistent tool creation via Tool.define.
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* A schema type compatible with both Zod 3 and Zod 4.
|
|
281
|
+
*
|
|
282
|
+
* Uses structural typing so that schemas from either Zod version satisfy
|
|
283
|
+
* the constraint. This avoids the problem where Zod 3's `ZodType` class
|
|
284
|
+
* and Zod 4's `ZodType` class have incompatible internal shapes, causing
|
|
285
|
+
* type errors when a library compiled against one version is consumed with
|
|
286
|
+
* the other.
|
|
287
|
+
*
|
|
288
|
+
* Both Zod 3 and Zod 4 (classic API) schemas have `parse()` and `_output`.
|
|
289
|
+
*/
|
|
290
|
+
interface CompatibleSchema<T = any> {
|
|
291
|
+
/** Parse and validate input data. Present in both Zod 3 and Zod 4. */
|
|
292
|
+
parse(data: unknown): T;
|
|
293
|
+
/**
|
|
294
|
+
* Type-level output marker used by both Zod versions:
|
|
295
|
+
* - Zod 3: `readonly _output!: T` (definite assignment assertion)
|
|
296
|
+
* - Zod 4 classic: `get _output(): T` (getter)
|
|
297
|
+
*/
|
|
298
|
+
readonly _output: T;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Infer the output type from a compatible schema.
|
|
302
|
+
* Equivalent to `z.infer<T>` but works with both Zod 3 and Zod 4 schemas.
|
|
303
|
+
*/
|
|
304
|
+
type InferSchemaOutput<T extends CompatibleSchema> = T["_output"];
|
|
305
|
+
/**
|
|
306
|
+
* Tool namespace - tool definition utilities
|
|
307
|
+
*/
|
|
308
|
+
declare namespace Tool {
|
|
309
|
+
/**
|
|
310
|
+
* Tool info interface - the shape of a defined tool
|
|
311
|
+
*/
|
|
312
|
+
interface Info<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
|
|
313
|
+
/** Unique tool identifier */
|
|
314
|
+
id: string;
|
|
315
|
+
/** Recovery semantics for resume-capable runtimes. */
|
|
316
|
+
replayPolicy?: ToolReplayPolicy;
|
|
317
|
+
/** Initialize the tool (can be async for dynamic descriptions) */
|
|
318
|
+
init: (ctx?: InitContext) => Promise<InitResult<TParams, TMeta>> | InitResult<TParams, TMeta>;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Any tool info - for use in arrays and collections where generic types vary
|
|
322
|
+
*/
|
|
323
|
+
type AnyInfo = Info<any, any>;
|
|
324
|
+
/**
|
|
325
|
+
* Context passed during tool initialization
|
|
326
|
+
*/
|
|
327
|
+
interface InitContext {
|
|
328
|
+
/** Working directory */
|
|
329
|
+
cwd?: string;
|
|
330
|
+
/** Agent name (if known) */
|
|
331
|
+
agent?: string;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Result of tool initialization
|
|
335
|
+
*/
|
|
336
|
+
interface InitResult<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
|
|
337
|
+
/** Tool description for the LLM */
|
|
338
|
+
description: string;
|
|
339
|
+
/** Zod schema for parameters */
|
|
340
|
+
parameters: TParams;
|
|
341
|
+
/** Execute the tool */
|
|
342
|
+
execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
|
|
343
|
+
/** Optional custom validation error formatter */
|
|
344
|
+
formatValidationError?: (error: z.ZodError) => string;
|
|
345
|
+
/**
|
|
346
|
+
* File operation metadata for automatic turn tracking.
|
|
347
|
+
* When set, the agent will automatically capture file baselines
|
|
348
|
+
* before tool execution for undo/diff capabilities.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* // For a write tool
|
|
353
|
+
* fileOps: {
|
|
354
|
+
* pathArgs: ['path'],
|
|
355
|
+
* operationType: 'write'
|
|
356
|
+
* }
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
fileOps?: FileOperationMeta;
|
|
360
|
+
/** Optional replay metadata for resume-capable runtimes. */
|
|
361
|
+
replayPolicy?: ToolReplayPolicy;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Result of tool execution
|
|
365
|
+
*/
|
|
366
|
+
interface ExecuteResult<TMeta extends ToolMetadata = ToolMetadata> {
|
|
367
|
+
/** Short title for display */
|
|
368
|
+
title: string;
|
|
369
|
+
/** Main output text */
|
|
370
|
+
output: string;
|
|
371
|
+
/** Metadata */
|
|
372
|
+
metadata: TMeta;
|
|
373
|
+
}
|
|
374
|
+
interface DefineOptions {
|
|
375
|
+
/** Static replay metadata exposed to higher-level runtimes. */
|
|
376
|
+
replayPolicy?: ToolReplayPolicy;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Define a tool with standard patterns
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* const myTool = Tool.define("my_tool", {
|
|
384
|
+
* description: "Does something useful",
|
|
385
|
+
* parameters: z.object({
|
|
386
|
+
* input: z.string().describe("The input to process"),
|
|
387
|
+
* }),
|
|
388
|
+
* execute: async (params, ctx) => ({
|
|
389
|
+
* title: "Processed",
|
|
390
|
+
* output: `Result: ${params.input}`,
|
|
391
|
+
* metadata: {},
|
|
392
|
+
* }),
|
|
393
|
+
* });
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
function define<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, init: Info<TParams, TMeta>["init"] | Awaited<ReturnType<Info<TParams, TMeta>["init"]>>, options?: DefineOptions): Info<TParams, TMeta>;
|
|
397
|
+
/**
|
|
398
|
+
* Simple define for static tools (no async init)
|
|
399
|
+
*/
|
|
400
|
+
function defineSimple<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, config: {
|
|
401
|
+
description: string;
|
|
402
|
+
parameters: TParams;
|
|
403
|
+
execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
|
|
404
|
+
replayPolicy?: ToolReplayPolicy;
|
|
405
|
+
}): Info<TParams, TMeta>;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Legacy helper - wraps to Tool.Info format
|
|
409
|
+
*
|
|
410
|
+
* @deprecated Use Tool.define instead
|
|
411
|
+
*/
|
|
412
|
+
declare function defineTool<TParams extends CompatibleSchema>(definition: {
|
|
413
|
+
id: string;
|
|
414
|
+
description: string;
|
|
415
|
+
parameters: TParams;
|
|
416
|
+
execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ToolResult>;
|
|
417
|
+
}): Tool.Info<TParams>;
|
|
418
|
+
|
|
419
|
+
export { type CompatibleSchema as C, type InferSchemaOutput as I, type RemoteSkillEntry as R, type SkillDiscoveryResult as S, Tool as T, type SkillMetadata as a, type SkillContent as b, type SkillResource as c, type SkillConfig as d, type RemoteSkillIndex as e, type SkillDiscoveryError as f, type SkillResourceType as g, type SkillScope as h, type SkillSource as i, type SkillSourceType as j, defineTool as k };
|