@robota-sdk/agent-sdk 3.0.0-beta.4 → 3.0.0-beta.43
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 +322 -21
- package/dist/node/index.cjs +2205 -139
- package/dist/node/index.d.cts +897 -178
- package/dist/node/index.d.ts +897 -178
- package/dist/node/index.js +2213 -157
- package/package.json +5 -5
package/dist/node/index.d.cts
CHANGED
|
@@ -1,180 +1,84 @@
|
|
|
1
|
-
import { TTrustLevel, TPermissionMode, IAIProvider, TToolArgs, IToolWithEventService } from '@robota-sdk/agent-core';
|
|
1
|
+
import { IHookTypeExecutor, IHookDefinition, IHookInput, IHookResult, THooksConfig, TTrustLevel, TPermissionMode, IAIProvider, TToolArgs, IToolWithEventService, TUniversalMessage, IContextWindowState } from '@robota-sdk/agent-core';
|
|
2
2
|
export { IContextTokenUsage, IContextWindowState, IHookInput, IPermissionLists, THookEvent, THooksConfig, TPermissionDecision, TPermissionMode, TRUST_TO_MODE, TToolArgs, TTrustLevel, evaluatePermission, runHooks } from '@robota-sdk/agent-core';
|
|
3
|
-
import
|
|
3
|
+
import { createZodFunctionTool } from '@robota-sdk/agent-tools';
|
|
4
4
|
export { TToolResult, bashTool, editTool, globTool, grepTool, readTool, writeTool } from '@robota-sdk/agent-tools';
|
|
5
|
-
import { ITerminalOutput, SessionStore, TPermissionHandler, ISessionLogger, Session } from '@robota-sdk/agent-sessions';
|
|
5
|
+
import { ITerminalOutput, SessionStore, TPermissionHandler, ISessionLogger, Session, FileSessionLogger, TPermissionResult } from '@robota-sdk/agent-sessions';
|
|
6
6
|
export { FileSessionLogger, ISessionLogger, ISessionOptions, ISessionRecord, ISpinner, ITerminalOutput, Session, SessionStore, SilentSessionLogger, TPermissionHandler, TPermissionResult, TSessionLogData } from '@robota-sdk/agent-sessions';
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Prompt hook executor — evaluates a prompt via an AI model.
|
|
10
|
+
*
|
|
11
|
+
* Makes a single-turn LLM call with hook input context as the prompt.
|
|
12
|
+
* Parses { ok: boolean, reason?: string } from the AI response.
|
|
13
|
+
*
|
|
14
|
+
* Exit codes:
|
|
15
|
+
* - 0: ok: true (allow/proceed)
|
|
16
|
+
* - 2: ok: false (block/deny), reason in stderr
|
|
17
|
+
* - 1: execution error (provider failure, parse error)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** A minimal provider interface for single-turn completion. */
|
|
21
|
+
interface IPromptProvider {
|
|
22
|
+
complete(prompt: string): Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
/** Factory that creates a provider instance, optionally for a specific model. */
|
|
25
|
+
type TProviderFactory = (model?: string) => IPromptProvider;
|
|
26
|
+
/** Constructor options for PromptExecutor. */
|
|
27
|
+
interface IPromptExecutorOptions {
|
|
28
|
+
providerFactory: TProviderFactory;
|
|
29
|
+
defaultModel?: string;
|
|
30
|
+
}
|
|
31
|
+
declare class PromptExecutor implements IHookTypeExecutor {
|
|
32
|
+
readonly type: "prompt";
|
|
33
|
+
private readonly providerFactory;
|
|
34
|
+
private readonly defaultModel;
|
|
35
|
+
constructor(options: IPromptExecutorOptions);
|
|
36
|
+
execute(definition: IHookDefinition, input: IHookInput): Promise<IHookResult>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Agent hook executor — delegates to a sub-agent session.
|
|
41
|
+
*
|
|
42
|
+
* Creates a subagent session with maxTurns and timeout limits,
|
|
43
|
+
* runs hook input as the initial prompt, and parses the result.
|
|
44
|
+
*
|
|
45
|
+
* Exit codes:
|
|
46
|
+
* - 0: ok: true (allow/proceed)
|
|
47
|
+
* - 2: ok: false (block/deny), reason in stderr
|
|
48
|
+
* - 1: execution error (session failure, parse error)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/** A minimal session interface for running a prompt. */
|
|
52
|
+
interface IAgentSession {
|
|
53
|
+
run(prompt: string): Promise<string>;
|
|
54
|
+
}
|
|
55
|
+
/** Factory that creates a session instance with the given options. */
|
|
56
|
+
type TSessionFactory = (options: {
|
|
57
|
+
maxTurns?: number;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
}) => IAgentSession;
|
|
60
|
+
/** Constructor options for AgentExecutor. */
|
|
61
|
+
interface IAgentExecutorOptions {
|
|
62
|
+
sessionFactory: TSessionFactory;
|
|
63
|
+
}
|
|
64
|
+
declare class AgentExecutor implements IHookTypeExecutor {
|
|
65
|
+
readonly type: "agent";
|
|
66
|
+
private readonly sessionFactory;
|
|
67
|
+
constructor(options: IAgentExecutorOptions);
|
|
68
|
+
execute(definition: IHookDefinition, input: IHookInput): Promise<IHookResult>;
|
|
69
|
+
}
|
|
8
70
|
|
|
9
71
|
/**
|
|
10
72
|
* Zod schemas and TypeScript types for Robota CLI settings
|
|
11
73
|
*/
|
|
12
74
|
|
|
13
|
-
declare const HooksSchema: z.ZodOptional<z.ZodObject<{
|
|
14
|
-
PreToolUse: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
15
|
-
matcher: z.ZodString;
|
|
16
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
17
|
-
type: z.ZodLiteral<"command">;
|
|
18
|
-
command: z.ZodString;
|
|
19
|
-
}, "strip", z.ZodTypeAny, {
|
|
20
|
-
type: "command";
|
|
21
|
-
command: string;
|
|
22
|
-
}, {
|
|
23
|
-
type: "command";
|
|
24
|
-
command: string;
|
|
25
|
-
}>, "many">;
|
|
26
|
-
}, "strip", z.ZodTypeAny, {
|
|
27
|
-
matcher: string;
|
|
28
|
-
hooks: {
|
|
29
|
-
type: "command";
|
|
30
|
-
command: string;
|
|
31
|
-
}[];
|
|
32
|
-
}, {
|
|
33
|
-
matcher: string;
|
|
34
|
-
hooks: {
|
|
35
|
-
type: "command";
|
|
36
|
-
command: string;
|
|
37
|
-
}[];
|
|
38
|
-
}>, "many">>;
|
|
39
|
-
PostToolUse: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
40
|
-
matcher: z.ZodString;
|
|
41
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
42
|
-
type: z.ZodLiteral<"command">;
|
|
43
|
-
command: z.ZodString;
|
|
44
|
-
}, "strip", z.ZodTypeAny, {
|
|
45
|
-
type: "command";
|
|
46
|
-
command: string;
|
|
47
|
-
}, {
|
|
48
|
-
type: "command";
|
|
49
|
-
command: string;
|
|
50
|
-
}>, "many">;
|
|
51
|
-
}, "strip", z.ZodTypeAny, {
|
|
52
|
-
matcher: string;
|
|
53
|
-
hooks: {
|
|
54
|
-
type: "command";
|
|
55
|
-
command: string;
|
|
56
|
-
}[];
|
|
57
|
-
}, {
|
|
58
|
-
matcher: string;
|
|
59
|
-
hooks: {
|
|
60
|
-
type: "command";
|
|
61
|
-
command: string;
|
|
62
|
-
}[];
|
|
63
|
-
}>, "many">>;
|
|
64
|
-
SessionStart: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
65
|
-
matcher: z.ZodString;
|
|
66
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
67
|
-
type: z.ZodLiteral<"command">;
|
|
68
|
-
command: z.ZodString;
|
|
69
|
-
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
type: "command";
|
|
71
|
-
command: string;
|
|
72
|
-
}, {
|
|
73
|
-
type: "command";
|
|
74
|
-
command: string;
|
|
75
|
-
}>, "many">;
|
|
76
|
-
}, "strip", z.ZodTypeAny, {
|
|
77
|
-
matcher: string;
|
|
78
|
-
hooks: {
|
|
79
|
-
type: "command";
|
|
80
|
-
command: string;
|
|
81
|
-
}[];
|
|
82
|
-
}, {
|
|
83
|
-
matcher: string;
|
|
84
|
-
hooks: {
|
|
85
|
-
type: "command";
|
|
86
|
-
command: string;
|
|
87
|
-
}[];
|
|
88
|
-
}>, "many">>;
|
|
89
|
-
Stop: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
90
|
-
matcher: z.ZodString;
|
|
91
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
92
|
-
type: z.ZodLiteral<"command">;
|
|
93
|
-
command: z.ZodString;
|
|
94
|
-
}, "strip", z.ZodTypeAny, {
|
|
95
|
-
type: "command";
|
|
96
|
-
command: string;
|
|
97
|
-
}, {
|
|
98
|
-
type: "command";
|
|
99
|
-
command: string;
|
|
100
|
-
}>, "many">;
|
|
101
|
-
}, "strip", z.ZodTypeAny, {
|
|
102
|
-
matcher: string;
|
|
103
|
-
hooks: {
|
|
104
|
-
type: "command";
|
|
105
|
-
command: string;
|
|
106
|
-
}[];
|
|
107
|
-
}, {
|
|
108
|
-
matcher: string;
|
|
109
|
-
hooks: {
|
|
110
|
-
type: "command";
|
|
111
|
-
command: string;
|
|
112
|
-
}[];
|
|
113
|
-
}>, "many">>;
|
|
114
|
-
}, "strip", z.ZodTypeAny, {
|
|
115
|
-
PreToolUse?: {
|
|
116
|
-
matcher: string;
|
|
117
|
-
hooks: {
|
|
118
|
-
type: "command";
|
|
119
|
-
command: string;
|
|
120
|
-
}[];
|
|
121
|
-
}[] | undefined;
|
|
122
|
-
PostToolUse?: {
|
|
123
|
-
matcher: string;
|
|
124
|
-
hooks: {
|
|
125
|
-
type: "command";
|
|
126
|
-
command: string;
|
|
127
|
-
}[];
|
|
128
|
-
}[] | undefined;
|
|
129
|
-
SessionStart?: {
|
|
130
|
-
matcher: string;
|
|
131
|
-
hooks: {
|
|
132
|
-
type: "command";
|
|
133
|
-
command: string;
|
|
134
|
-
}[];
|
|
135
|
-
}[] | undefined;
|
|
136
|
-
Stop?: {
|
|
137
|
-
matcher: string;
|
|
138
|
-
hooks: {
|
|
139
|
-
type: "command";
|
|
140
|
-
command: string;
|
|
141
|
-
}[];
|
|
142
|
-
}[] | undefined;
|
|
143
|
-
}, {
|
|
144
|
-
PreToolUse?: {
|
|
145
|
-
matcher: string;
|
|
146
|
-
hooks: {
|
|
147
|
-
type: "command";
|
|
148
|
-
command: string;
|
|
149
|
-
}[];
|
|
150
|
-
}[] | undefined;
|
|
151
|
-
PostToolUse?: {
|
|
152
|
-
matcher: string;
|
|
153
|
-
hooks: {
|
|
154
|
-
type: "command";
|
|
155
|
-
command: string;
|
|
156
|
-
}[];
|
|
157
|
-
}[] | undefined;
|
|
158
|
-
SessionStart?: {
|
|
159
|
-
matcher: string;
|
|
160
|
-
hooks: {
|
|
161
|
-
type: "command";
|
|
162
|
-
command: string;
|
|
163
|
-
}[];
|
|
164
|
-
}[] | undefined;
|
|
165
|
-
Stop?: {
|
|
166
|
-
matcher: string;
|
|
167
|
-
hooks: {
|
|
168
|
-
type: "command";
|
|
169
|
-
command: string;
|
|
170
|
-
}[];
|
|
171
|
-
}[] | undefined;
|
|
172
|
-
}>>;
|
|
173
75
|
/**
|
|
174
76
|
* Fully resolved config after merging all settings files and applying defaults.
|
|
175
77
|
*/
|
|
176
78
|
interface IResolvedConfig {
|
|
177
79
|
defaultTrustLevel: 'safe' | 'moderate' | 'full';
|
|
80
|
+
/** Response language code (e.g., "ko", "en"). Undefined = no language constraint. */
|
|
81
|
+
language?: string;
|
|
178
82
|
provider: {
|
|
179
83
|
name: string;
|
|
180
84
|
model: string;
|
|
@@ -185,7 +89,19 @@ interface IResolvedConfig {
|
|
|
185
89
|
deny: string[];
|
|
186
90
|
};
|
|
187
91
|
env: Record<string, string>;
|
|
188
|
-
hooks?:
|
|
92
|
+
hooks?: THooksConfig;
|
|
93
|
+
/** Plugin enablement map: plugin name -> enabled/disabled */
|
|
94
|
+
enabledPlugins?: Record<string, boolean>;
|
|
95
|
+
/** Extra marketplace sources: name -> { source } */
|
|
96
|
+
extraKnownMarketplaces?: Record<string, {
|
|
97
|
+
source: {
|
|
98
|
+
type: string;
|
|
99
|
+
repo?: string;
|
|
100
|
+
url?: string;
|
|
101
|
+
path?: string;
|
|
102
|
+
ref?: string;
|
|
103
|
+
};
|
|
104
|
+
}>;
|
|
189
105
|
}
|
|
190
106
|
|
|
191
107
|
interface ILoadedContext {
|
|
@@ -235,10 +151,17 @@ interface ISystemPromptParams {
|
|
|
235
151
|
trustLevel: TTrustLevel;
|
|
236
152
|
/** Detected project metadata */
|
|
237
153
|
projectInfo: IProjectInfo;
|
|
154
|
+
/** Current working directory */
|
|
155
|
+
cwd?: string;
|
|
156
|
+
/** Response language code (e.g., "ko", "en"). If set, AI must respond in this language. */
|
|
157
|
+
language?: string;
|
|
158
|
+
/** Discovered skills to expose in the system prompt */
|
|
159
|
+
skills?: Array<{
|
|
160
|
+
name: string;
|
|
161
|
+
description: string;
|
|
162
|
+
disableModelInvocation?: boolean;
|
|
163
|
+
}>;
|
|
238
164
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Assemble the full system prompt string from the provided parameters.
|
|
241
|
-
*/
|
|
242
165
|
declare function buildSystemPrompt(params: ISystemPromptParams): string;
|
|
243
166
|
|
|
244
167
|
/**
|
|
@@ -276,6 +199,13 @@ interface ICreateSessionOptions {
|
|
|
276
199
|
promptForApproval?: (terminal: ITerminalOutput, toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
277
200
|
/** Additional tools to register beyond the defaults (e.g. agent-tool) */
|
|
278
201
|
additionalTools?: IToolWithEventService[];
|
|
202
|
+
/** Callback when a tool starts or finishes execution — enables real-time tool display in UI */
|
|
203
|
+
onToolExecution?: (event: {
|
|
204
|
+
type: 'start' | 'end';
|
|
205
|
+
toolName: string;
|
|
206
|
+
toolArgs?: TToolArgs;
|
|
207
|
+
success?: boolean;
|
|
208
|
+
}) => void;
|
|
279
209
|
/** Callback when context is compacted */
|
|
280
210
|
onCompact?: (summary: string) => void;
|
|
281
211
|
/** Instructions to include in the compaction prompt (e.g. from CLAUDE.md) */
|
|
@@ -286,6 +216,12 @@ interface ICreateSessionOptions {
|
|
|
286
216
|
toolDescriptions?: string[];
|
|
287
217
|
/** Session logger — injected for pluggable session event logging. */
|
|
288
218
|
sessionLogger?: ISessionLogger;
|
|
219
|
+
/** Provider factory for prompt hook executors (DI). */
|
|
220
|
+
providerFactory?: TProviderFactory;
|
|
221
|
+
/** Session factory for agent hook executors (DI). */
|
|
222
|
+
sessionFactory?: TSessionFactory;
|
|
223
|
+
/** Additional hook type executors beyond the defaults (prompt, agent). */
|
|
224
|
+
additionalHookExecutors?: IHookTypeExecutor[];
|
|
289
225
|
}
|
|
290
226
|
/**
|
|
291
227
|
* Create a fully-configured Session instance.
|
|
@@ -317,6 +253,146 @@ declare function createDefaultTools(): IToolWithEventService[];
|
|
|
317
253
|
*/
|
|
318
254
|
declare function createProvider(config: IResolvedConfig): IAIProvider;
|
|
319
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Framework system prompt suffixes for subagent sessions.
|
|
258
|
+
*
|
|
259
|
+
* These functions generate the standard prompt content injected into
|
|
260
|
+
* subagent sessions to control output format and behavior.
|
|
261
|
+
*/
|
|
262
|
+
/** Options for assembling a subagent system prompt. */
|
|
263
|
+
interface ISubagentPromptOptions {
|
|
264
|
+
/** Agent definition markdown body. */
|
|
265
|
+
agentBody: string;
|
|
266
|
+
/** CLAUDE.md content to include. */
|
|
267
|
+
claudeMd?: string;
|
|
268
|
+
/** AGENTS.md content to include. */
|
|
269
|
+
agentsMd?: string;
|
|
270
|
+
/** When true, use fork worker suffix instead of standard subagent suffix. */
|
|
271
|
+
isForkWorker: boolean;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Returns the standard subagent suffix appended to agent body for normal subagents.
|
|
275
|
+
*/
|
|
276
|
+
declare function getSubagentSuffix(): string;
|
|
277
|
+
/**
|
|
278
|
+
* Returns the fork worker suffix for context:fork skill workers.
|
|
279
|
+
*/
|
|
280
|
+
declare function getForkWorkerSuffix(): string;
|
|
281
|
+
/**
|
|
282
|
+
* Assembles the full system prompt for a subagent.
|
|
283
|
+
*
|
|
284
|
+
* Assembly order:
|
|
285
|
+
* 1. Agent definition body
|
|
286
|
+
* 2. CLAUDE.md content (if provided)
|
|
287
|
+
* 3. AGENTS.md content (if provided)
|
|
288
|
+
* 4. Framework suffix (fork worker OR standard subagent)
|
|
289
|
+
*/
|
|
290
|
+
declare function assembleSubagentPrompt(options: ISubagentPromptOptions): string;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Definition of an agent that can be spawned as a subagent.
|
|
294
|
+
*
|
|
295
|
+
* Built-in agents and custom (user-defined) agents share this shape.
|
|
296
|
+
* Optional fields inherit from the parent session when omitted.
|
|
297
|
+
*/
|
|
298
|
+
interface IAgentDefinition {
|
|
299
|
+
/** Unique name used to reference the agent (e.g., 'Explore', 'Plan'). */
|
|
300
|
+
name: string;
|
|
301
|
+
/** Human-readable description of the agent's purpose. */
|
|
302
|
+
description: string;
|
|
303
|
+
/** Markdown body content used as the agent's system prompt. */
|
|
304
|
+
systemPrompt: string;
|
|
305
|
+
/** Model override (e.g., 'claude-haiku-4-5', 'sonnet', 'opus'). Inherits parent model when omitted. */
|
|
306
|
+
model?: string;
|
|
307
|
+
/** Maximum number of agentic turns the subagent may execute. */
|
|
308
|
+
maxTurns?: number;
|
|
309
|
+
/** Allowlist of tool names. Only these tools are available when set. */
|
|
310
|
+
tools?: string[];
|
|
311
|
+
/** Denylist of tool names. These tools are removed from the inherited set. */
|
|
312
|
+
disallowedTools?: string[];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Subagent session factory — assembles an isolated child Session for subagent execution.
|
|
317
|
+
*
|
|
318
|
+
* Unlike `createSession`, this factory does not load config files or context from disk.
|
|
319
|
+
* It receives pre-resolved config and context from the parent session, applies tool
|
|
320
|
+
* filtering and model resolution from the agent definition, and creates a lightweight
|
|
321
|
+
* Session suitable for subagent use.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/** Options for creating a subagent session. */
|
|
325
|
+
interface ISubagentOptions {
|
|
326
|
+
/** Agent definition (built-in or custom). */
|
|
327
|
+
agentDefinition: IAgentDefinition;
|
|
328
|
+
/** Parent's resolved config (for provider, permissions, etc.). */
|
|
329
|
+
parentConfig: IResolvedConfig;
|
|
330
|
+
/** Parent's loaded context (CLAUDE.md, AGENTS.md). */
|
|
331
|
+
parentContext: ILoadedContext;
|
|
332
|
+
/** Parent session's available tools (to inherit/filter). */
|
|
333
|
+
parentTools: IToolWithEventService[];
|
|
334
|
+
/** Terminal output interface. */
|
|
335
|
+
terminal: ITerminalOutput;
|
|
336
|
+
/** Whether this is a fork worker (uses fork suffix instead of standard). */
|
|
337
|
+
isForkWorker?: boolean;
|
|
338
|
+
/** Permission mode from parent (bypassPermissions, acceptEdits, etc.). */
|
|
339
|
+
permissionMode?: TPermissionMode;
|
|
340
|
+
/** Permission handler from parent. */
|
|
341
|
+
permissionHandler?: TPermissionHandler;
|
|
342
|
+
/** Plugin hooks configuration from parent session. */
|
|
343
|
+
hooks?: Record<string, unknown>;
|
|
344
|
+
/** Hook type executors from parent session (prompt, agent, etc.). */
|
|
345
|
+
hookTypeExecutors?: IHookTypeExecutor[];
|
|
346
|
+
/** Streaming callback. */
|
|
347
|
+
onTextDelta?: (delta: string) => void;
|
|
348
|
+
/** Tool execution callback. */
|
|
349
|
+
onToolExecution?: (event: {
|
|
350
|
+
type: 'start' | 'end';
|
|
351
|
+
toolName: string;
|
|
352
|
+
toolArgs?: TToolArgs;
|
|
353
|
+
success?: boolean;
|
|
354
|
+
}) => void;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Create a fully-configured Session for subagent execution.
|
|
358
|
+
*
|
|
359
|
+
* Assembles provider, tools, and system prompt from parent context and
|
|
360
|
+
* agent definition, then returns a new Session instance.
|
|
361
|
+
*/
|
|
362
|
+
declare function createSubagentSession(options: ISubagentOptions): Session;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Subagent transcript logger — creates a FileSessionLogger that writes
|
|
366
|
+
* subagent session logs into a subdirectory of the parent session's log folder.
|
|
367
|
+
*
|
|
368
|
+
* Log structure:
|
|
369
|
+
* {baseLogsDir}/{parentSessionId}/subagents/{agentId}.jsonl
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Create a FileSessionLogger for a subagent session.
|
|
374
|
+
*
|
|
375
|
+
* The logger writes JSONL files into a `subagents/` subdirectory under the
|
|
376
|
+
* parent session's log folder. The directory is created if it does not exist.
|
|
377
|
+
*
|
|
378
|
+
* @param parentSessionId - ID of the parent session (used as directory name)
|
|
379
|
+
* @param agentId - Unique identifier for this subagent run
|
|
380
|
+
* @param baseLogsDir - Root logs directory (e.g., `.robota/logs`)
|
|
381
|
+
* @returns A FileSessionLogger writing to the subagent directory
|
|
382
|
+
*/
|
|
383
|
+
declare function createSubagentLogger(parentSessionId: string, _agentId: string, baseLogsDir: string): FileSessionLogger;
|
|
384
|
+
/**
|
|
385
|
+
* Resolve the subagent log directory path without creating it.
|
|
386
|
+
*
|
|
387
|
+
* Useful when the caller needs the path for display or configuration
|
|
388
|
+
* but does not want to create the directory immediately.
|
|
389
|
+
*
|
|
390
|
+
* @param parentSessionId - ID of the parent session
|
|
391
|
+
* @param baseLogsDir - Root logs directory
|
|
392
|
+
* @returns The resolved subagent log directory path
|
|
393
|
+
*/
|
|
394
|
+
declare function resolveSubagentLogDir(parentSessionId: string, baseLogsDir: string): string;
|
|
395
|
+
|
|
320
396
|
/**
|
|
321
397
|
* query() — single entry point for running an AI agent conversation.
|
|
322
398
|
* Automatically loads config, context, and project info.
|
|
@@ -342,14 +418,14 @@ declare function query(prompt: string, options?: IQueryOptions): Promise<string>
|
|
|
342
418
|
/**
|
|
343
419
|
* Load and merge all settings files, validate with Zod, return resolved config.
|
|
344
420
|
*
|
|
345
|
-
* @param cwd - The working directory (project root) to search for
|
|
421
|
+
* @param cwd - The working directory (project root) to search for settings
|
|
346
422
|
*/
|
|
347
423
|
declare function loadConfig(cwd: string): Promise<IResolvedConfig>;
|
|
348
424
|
|
|
349
425
|
/**
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
426
|
+
* Interactive permission prompt — asks the user whether to allow a tool invocation
|
|
427
|
+
* using an arrow-key selector. Canonical implementation (SSOT).
|
|
428
|
+
* Used by both agent-sdk query() and agent-cli.
|
|
353
429
|
*/
|
|
354
430
|
|
|
355
431
|
/**
|
|
@@ -376,14 +452,657 @@ declare function userPaths(): {
|
|
|
376
452
|
sessions: string;
|
|
377
453
|
};
|
|
378
454
|
|
|
379
|
-
/**
|
|
455
|
+
/**
|
|
456
|
+
* PluginSettingsStore — single point of read/write for plugin-related settings.
|
|
457
|
+
*
|
|
458
|
+
* Shared by MarketplaceClient and BundlePluginInstaller to prevent
|
|
459
|
+
* concurrent writes from overwriting each other's changes.
|
|
460
|
+
*/
|
|
461
|
+
/** Source type for a marketplace registry. */
|
|
462
|
+
type IMarketplaceSource$1 = {
|
|
463
|
+
type: 'github';
|
|
464
|
+
repo: string;
|
|
465
|
+
ref?: string;
|
|
466
|
+
} | {
|
|
467
|
+
type: 'git';
|
|
468
|
+
url: string;
|
|
469
|
+
ref?: string;
|
|
470
|
+
} | {
|
|
471
|
+
type: 'local';
|
|
472
|
+
path: string;
|
|
473
|
+
} | {
|
|
474
|
+
type: 'url';
|
|
475
|
+
url: string;
|
|
476
|
+
};
|
|
477
|
+
/** Persisted marketplace source entry. */
|
|
478
|
+
interface IPersistedMarketplaceSource {
|
|
479
|
+
source: IMarketplaceSource$1;
|
|
480
|
+
}
|
|
481
|
+
/** Shape of the plugin-related keys in settings.json. */
|
|
482
|
+
interface IPluginSettings {
|
|
483
|
+
enabledPlugins: Record<string, boolean>;
|
|
484
|
+
extraKnownMarketplaces: Record<string, IPersistedMarketplaceSource>;
|
|
485
|
+
}
|
|
486
|
+
/** Centralized settings store for plugin configuration. */
|
|
487
|
+
declare class PluginSettingsStore {
|
|
488
|
+
private readonly settingsPath;
|
|
489
|
+
constructor(settingsPath: string);
|
|
490
|
+
/** Read the full settings file from disk. */
|
|
491
|
+
private readAll;
|
|
492
|
+
/** Write the full settings file to disk. */
|
|
493
|
+
private writeAll;
|
|
494
|
+
/** Get the enabledPlugins map. */
|
|
495
|
+
getEnabledPlugins(): Record<string, boolean>;
|
|
496
|
+
/** Set a single plugin's enabled state. */
|
|
497
|
+
setPluginEnabled(pluginId: string, enabled: boolean): void;
|
|
498
|
+
/** Remove a plugin from enabledPlugins. */
|
|
499
|
+
removePluginEntry(pluginId: string): void;
|
|
500
|
+
/** Get all persisted marketplace sources. */
|
|
501
|
+
getMarketplaceSources(): Record<string, IPersistedMarketplaceSource>;
|
|
502
|
+
/** Add or update a marketplace source. */
|
|
503
|
+
setMarketplaceSource(name: string, source: IMarketplaceSource$1): void;
|
|
504
|
+
/** Remove a marketplace source. */
|
|
505
|
+
removeMarketplaceSource(name: string): void;
|
|
506
|
+
private getEnabledPluginsFrom;
|
|
507
|
+
private getMarketplaceSourcesFrom;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Types for the BundlePlugin system.
|
|
512
|
+
*
|
|
513
|
+
* A BundlePlugin is a directory-based plugin package that bundles
|
|
514
|
+
* skills, hooks, agents, and MCP server configurations.
|
|
515
|
+
*/
|
|
516
|
+
/** Feature flags indicating what a bundle plugin provides. */
|
|
517
|
+
interface IBundlePluginFeatures {
|
|
518
|
+
commands?: boolean;
|
|
519
|
+
agents?: boolean;
|
|
520
|
+
skills?: boolean;
|
|
521
|
+
hooks?: boolean;
|
|
522
|
+
mcp?: boolean;
|
|
523
|
+
}
|
|
524
|
+
/** Manifest read from `.claude-plugin/plugin.json`. */
|
|
525
|
+
interface IBundlePluginManifest {
|
|
526
|
+
name: string;
|
|
527
|
+
version: string;
|
|
528
|
+
description: string;
|
|
529
|
+
features: IBundlePluginFeatures;
|
|
530
|
+
}
|
|
531
|
+
/** A skill loaded from a bundle plugin's `skills/` directory. */
|
|
532
|
+
interface IBundleSkill {
|
|
533
|
+
name: string;
|
|
534
|
+
description: string;
|
|
535
|
+
skillContent: string;
|
|
536
|
+
[key: string]: unknown;
|
|
537
|
+
}
|
|
538
|
+
/** A fully loaded bundle plugin with all its assets. */
|
|
539
|
+
interface ILoadedBundlePlugin {
|
|
540
|
+
manifest: IBundlePluginManifest;
|
|
541
|
+
skills: IBundleSkill[];
|
|
542
|
+
commands: IBundleSkill[];
|
|
543
|
+
hooks: Record<string, unknown>;
|
|
544
|
+
mcpConfig?: unknown;
|
|
545
|
+
agents: string[];
|
|
546
|
+
pluginDir: string;
|
|
547
|
+
}
|
|
548
|
+
/** Map of plugin identifiers to enabled/disabled state. */
|
|
549
|
+
type TEnabledPlugins = Record<string, boolean>;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* BundlePluginLoader — discovers and loads directory-based bundle plugins.
|
|
553
|
+
*
|
|
554
|
+
* Scans the cache directory (`<pluginsDir>/cache/<marketplace>/<plugin>/<version>/`)
|
|
555
|
+
* for subdirectories containing `.claude-plugin/plugin.json`,
|
|
556
|
+
* reads manifests, loads skills (with frontmatter parsing), hooks, and agent definitions.
|
|
557
|
+
*
|
|
558
|
+
* For each plugin, the latest version directory (lexicographically last) is loaded.
|
|
559
|
+
*/
|
|
560
|
+
|
|
561
|
+
/** Loader for directory-based bundle plugins from the cache directory. */
|
|
562
|
+
declare class BundlePluginLoader {
|
|
563
|
+
private readonly pluginsDir;
|
|
564
|
+
private readonly enabledPlugins;
|
|
565
|
+
constructor(pluginsDir: string, enabledPlugins?: TEnabledPlugins);
|
|
566
|
+
/** Load all discovered and enabled bundle plugins (sync). */
|
|
567
|
+
loadPluginsSync(): ILoadedBundlePlugin[];
|
|
568
|
+
/** Load all discovered and enabled bundle plugins (async wrapper). */
|
|
569
|
+
loadAll(): Promise<ILoadedBundlePlugin[]>;
|
|
570
|
+
/**
|
|
571
|
+
* Discover and load plugins from the cache directory.
|
|
572
|
+
*
|
|
573
|
+
* Directory structure: `<pluginsDir>/cache/<marketplace>/<plugin>/<version>/`
|
|
574
|
+
* For each marketplace/plugin pair, the latest version (lexicographically last) is loaded.
|
|
575
|
+
*/
|
|
576
|
+
private discoverAndLoad;
|
|
577
|
+
/** Read and validate a plugin.json manifest. Returns null on failure. */
|
|
578
|
+
private readManifest;
|
|
579
|
+
/**
|
|
580
|
+
* Check if a plugin is explicitly disabled.
|
|
581
|
+
* Checks both `name@marketplace` and `name` keys.
|
|
582
|
+
* Plugins not listed in enabledPlugins are enabled by default.
|
|
583
|
+
*/
|
|
584
|
+
private isDisabled;
|
|
585
|
+
/** Load a single plugin's skills, hooks, agents, and MCP config. */
|
|
586
|
+
private loadPlugin;
|
|
587
|
+
/** Load skills from the plugin's skills/ directory. */
|
|
588
|
+
private loadSkills;
|
|
589
|
+
/** Load commands from the plugin's commands/ directory (flat .md files). */
|
|
590
|
+
private loadCommands;
|
|
591
|
+
/** Load hooks from hooks/hooks.json if present. */
|
|
592
|
+
private loadHooks;
|
|
593
|
+
/** Load MCP server configuration if present. Checks `.mcp.json` at plugin root first. */
|
|
594
|
+
private loadMcpConfig;
|
|
595
|
+
/** Load agent definitions from agents/ directory if present. */
|
|
596
|
+
private loadAgents;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* MarketplaceClient — manages marketplace registries via shallow git clones.
|
|
601
|
+
*
|
|
602
|
+
* Marketplaces are git repositories containing `.claude-plugin/marketplace.json`.
|
|
603
|
+
* They are cloned to `~/.robota/plugins/marketplaces/<name>/` and tracked
|
|
604
|
+
* in `known_marketplaces.json`.
|
|
605
|
+
*/
|
|
606
|
+
/** Source specification for a marketplace. */
|
|
607
|
+
type IMarketplaceSource = {
|
|
608
|
+
type: 'github';
|
|
609
|
+
repo: string;
|
|
610
|
+
ref?: string;
|
|
611
|
+
} | {
|
|
612
|
+
type: 'git';
|
|
613
|
+
url: string;
|
|
614
|
+
ref?: string;
|
|
615
|
+
} | {
|
|
616
|
+
type: 'local';
|
|
617
|
+
path: string;
|
|
618
|
+
} | {
|
|
619
|
+
type: 'url';
|
|
620
|
+
url: string;
|
|
621
|
+
};
|
|
622
|
+
/** A single plugin entry in a marketplace manifest. */
|
|
623
|
+
interface IMarketplacePluginEntry {
|
|
624
|
+
name: string;
|
|
625
|
+
title: string;
|
|
626
|
+
description: string;
|
|
627
|
+
source: string | {
|
|
628
|
+
type: 'github';
|
|
629
|
+
repo: string;
|
|
630
|
+
} | {
|
|
631
|
+
type: 'url';
|
|
632
|
+
url: string;
|
|
633
|
+
};
|
|
634
|
+
tags: string[];
|
|
635
|
+
}
|
|
636
|
+
/** Manifest format read from `.claude-plugin/marketplace.json`. */
|
|
637
|
+
interface IMarketplaceManifest {
|
|
638
|
+
name: string;
|
|
639
|
+
version: string;
|
|
640
|
+
plugins: IMarketplacePluginEntry[];
|
|
641
|
+
}
|
|
642
|
+
/** Entry in known_marketplaces.json. */
|
|
643
|
+
interface IKnownMarketplaceEntry {
|
|
644
|
+
source: IMarketplaceSource;
|
|
645
|
+
installLocation: string;
|
|
646
|
+
lastUpdated: string;
|
|
647
|
+
}
|
|
648
|
+
/** Shape of known_marketplaces.json. */
|
|
649
|
+
type IKnownMarketplacesRegistry = Record<string, IKnownMarketplaceEntry>;
|
|
650
|
+
/** Exec function type for running shell commands. */
|
|
651
|
+
type ExecFn$1 = (command: string, options: {
|
|
652
|
+
timeout: number;
|
|
653
|
+
stdio?: string;
|
|
654
|
+
}) => string | Buffer;
|
|
655
|
+
/** Options for constructing a MarketplaceClient. */
|
|
656
|
+
interface IMarketplaceClientOptions {
|
|
657
|
+
/** Base plugins directory (e.g., `~/.robota/plugins`). */
|
|
658
|
+
pluginsDir: string;
|
|
659
|
+
/** Custom exec function for testing (replaces child_process.execSync). */
|
|
660
|
+
exec?: ExecFn$1;
|
|
661
|
+
}
|
|
662
|
+
/** Manages marketplace registries via shallow git clones. */
|
|
663
|
+
declare class MarketplaceClient {
|
|
664
|
+
private readonly pluginsDir;
|
|
665
|
+
private readonly exec;
|
|
666
|
+
private readonly marketplacesDir;
|
|
667
|
+
private readonly registryPath;
|
|
668
|
+
constructor(options: IMarketplaceClientOptions);
|
|
669
|
+
/**
|
|
670
|
+
* Add a marketplace by cloning its repository.
|
|
671
|
+
*
|
|
672
|
+
* 1. Parse source: `owner/repo` string becomes a GitHub source.
|
|
673
|
+
* 2. Shallow git clone (`--depth 1`) to `marketplaces/<name>/`.
|
|
674
|
+
* 3. Read `.claude-plugin/marketplace.json` for the `name` field.
|
|
675
|
+
* 4. Register in `known_marketplaces.json`.
|
|
676
|
+
*
|
|
677
|
+
* Returns the registered marketplace name from the manifest.
|
|
678
|
+
*/
|
|
679
|
+
addMarketplace(source: IMarketplaceSource): string;
|
|
680
|
+
/**
|
|
681
|
+
* Remove a marketplace.
|
|
682
|
+
* Uninstalls all plugins from that marketplace, then deletes the clone directory
|
|
683
|
+
* and removes from the registry.
|
|
684
|
+
*/
|
|
685
|
+
removeMarketplace(name: string): void;
|
|
686
|
+
/**
|
|
687
|
+
* Update a marketplace by running git pull on its clone.
|
|
688
|
+
* The manifest is re-read from disk on demand (via fetchManifest), so the
|
|
689
|
+
* updated manifest is automatically available after pull.
|
|
690
|
+
*
|
|
691
|
+
* TODO: After pull, detect version changes in installed plugins and offer
|
|
692
|
+
* to update them (re-install at new version).
|
|
693
|
+
*/
|
|
694
|
+
updateMarketplace(name: string): void;
|
|
695
|
+
/** List all registered marketplaces. */
|
|
696
|
+
listMarketplaces(): Array<{
|
|
697
|
+
name: string;
|
|
698
|
+
source: IMarketplaceSource;
|
|
699
|
+
lastUpdated: string;
|
|
700
|
+
}>;
|
|
701
|
+
/**
|
|
702
|
+
* Read the marketplace manifest from a registered marketplace's clone.
|
|
703
|
+
*/
|
|
704
|
+
fetchManifest(marketplaceName: string): IMarketplaceManifest;
|
|
705
|
+
/** Get the clone directory path for a registered marketplace. */
|
|
706
|
+
getMarketplaceDir(name: string): string;
|
|
707
|
+
/**
|
|
708
|
+
* Get the current git SHA (first 12 chars) for a marketplace clone.
|
|
709
|
+
* Used as a version identifier when plugins lack explicit versions.
|
|
710
|
+
*/
|
|
711
|
+
getMarketplaceSha(name: string): string;
|
|
712
|
+
/** List all available plugins across all marketplaces. */
|
|
713
|
+
listAvailablePlugins(): Array<IMarketplacePluginEntry & {
|
|
714
|
+
marketplace: string;
|
|
715
|
+
}>;
|
|
716
|
+
/** Resolve a marketplace source to a git clone URL. */
|
|
717
|
+
private resolveCloneUrl;
|
|
718
|
+
/**
|
|
719
|
+
* Remove all installed plugins that belong to a given marketplace.
|
|
720
|
+
* Reads installed_plugins.json, deletes cache directories for matching plugins,
|
|
721
|
+
* and updates the registry.
|
|
722
|
+
*/
|
|
723
|
+
private removeInstalledPluginsForMarketplace;
|
|
724
|
+
/** Read and parse a marketplace.json from a file path. */
|
|
725
|
+
private readManifestFromPath;
|
|
726
|
+
/** Read the known_marketplaces.json registry. */
|
|
727
|
+
private readRegistry;
|
|
728
|
+
/** Write the known_marketplaces.json registry. */
|
|
729
|
+
private writeRegistry;
|
|
730
|
+
/** Default exec implementation using child_process. */
|
|
731
|
+
private defaultExec;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* BundlePluginInstaller — installs, uninstalls, enables, and disables bundle plugins.
|
|
736
|
+
*
|
|
737
|
+
* Resolves plugin sources from marketplace manifests, copies/clones to the
|
|
738
|
+
* cache directory, and tracks installations in `installed_plugins.json`.
|
|
739
|
+
*/
|
|
740
|
+
|
|
741
|
+
/** Record of an installed plugin in installed_plugins.json. */
|
|
742
|
+
interface IInstalledPluginRecord {
|
|
743
|
+
pluginName: string;
|
|
744
|
+
marketplace: string;
|
|
745
|
+
version: string;
|
|
746
|
+
installPath: string;
|
|
747
|
+
installedAt: string;
|
|
748
|
+
}
|
|
749
|
+
/** Shape of installed_plugins.json. */
|
|
750
|
+
type IInstalledPluginsRegistry = Record<string, IInstalledPluginRecord>;
|
|
751
|
+
/** Exec function type for running shell commands. */
|
|
752
|
+
type ExecFn = (command: string, options: {
|
|
753
|
+
timeout: number;
|
|
754
|
+
stdio?: string;
|
|
755
|
+
}) => string | Buffer;
|
|
756
|
+
/** Options for constructing a BundlePluginInstaller. */
|
|
757
|
+
interface IBundlePluginInstallerOptions {
|
|
758
|
+
/** Base plugins directory (e.g., `~/.robota/plugins`). */
|
|
759
|
+
pluginsDir: string;
|
|
760
|
+
/** Shared settings store for enable/disable persistence. */
|
|
761
|
+
settingsStore: PluginSettingsStore;
|
|
762
|
+
/** MarketplaceClient for reading marketplace manifests. */
|
|
763
|
+
marketplaceClient: MarketplaceClient;
|
|
764
|
+
/** Custom exec function for testing (replaces child_process.execSync). */
|
|
765
|
+
exec?: ExecFn;
|
|
766
|
+
}
|
|
767
|
+
/** Installs, uninstalls, enables, and disables bundle plugins. */
|
|
768
|
+
declare class BundlePluginInstaller {
|
|
769
|
+
private readonly pluginsDir;
|
|
770
|
+
private readonly cacheDir;
|
|
771
|
+
private readonly registryPath;
|
|
772
|
+
private readonly settingsStore;
|
|
773
|
+
private readonly marketplaceClient;
|
|
774
|
+
private readonly exec;
|
|
775
|
+
constructor(options: IBundlePluginInstallerOptions);
|
|
776
|
+
/**
|
|
777
|
+
* Install a plugin from a marketplace.
|
|
778
|
+
*
|
|
779
|
+
* 1. Read marketplace manifest to find the plugin entry.
|
|
780
|
+
* 2. Resolve source (relative path, github, or url).
|
|
781
|
+
* 3. Copy/clone to `cache/<marketplace>/<plugin>/<version>/`.
|
|
782
|
+
* 4. Record in `installed_plugins.json`.
|
|
783
|
+
*/
|
|
784
|
+
install(pluginName: string, marketplaceName: string): Promise<void>;
|
|
785
|
+
/**
|
|
786
|
+
* Uninstall a plugin.
|
|
787
|
+
* Removes from cache and from installed_plugins.json.
|
|
788
|
+
*/
|
|
789
|
+
uninstall(pluginId: string): Promise<void>;
|
|
790
|
+
/** Enable a plugin by setting its enabledPlugins entry to true. */
|
|
791
|
+
enable(pluginId: string): Promise<void>;
|
|
792
|
+
/** Disable a plugin by setting its enabledPlugins entry to false. */
|
|
793
|
+
disable(pluginId: string): Promise<void>;
|
|
794
|
+
/** Get all installed plugins. */
|
|
795
|
+
getInstalledPlugins(): IInstalledPluginsRegistry;
|
|
796
|
+
/** Get plugins installed from a specific marketplace. */
|
|
797
|
+
getPluginsByMarketplace(marketplaceName: string): IInstalledPluginRecord[];
|
|
798
|
+
/** Resolve the version for a plugin entry. */
|
|
799
|
+
private resolveVersion;
|
|
800
|
+
/**
|
|
801
|
+
* Normalize source object — Claude Code manifests use `source` key instead of `type`.
|
|
802
|
+
* e.g., { source: "url", url: "..." } → { type: "url", url: "..." }
|
|
803
|
+
*/
|
|
804
|
+
private normalizeSource;
|
|
805
|
+
/** Resolve the source and install the plugin. */
|
|
806
|
+
private resolveAndInstall;
|
|
807
|
+
/** Clone a git repository to the target directory. */
|
|
808
|
+
private cloneToDir;
|
|
809
|
+
/** Read the installed_plugins.json registry. */
|
|
810
|
+
private readRegistry;
|
|
811
|
+
/** Write the installed_plugins.json registry. */
|
|
812
|
+
private writeRegistry;
|
|
813
|
+
/** Default exec implementation using child_process. */
|
|
814
|
+
private defaultExec;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* All built-in agent definitions shipped with the SDK.
|
|
819
|
+
* Order matters: general-purpose is the default fallback.
|
|
820
|
+
*/
|
|
821
|
+
declare const BUILT_IN_AGENTS: IAgentDefinition[];
|
|
822
|
+
/**
|
|
823
|
+
* Look up a built-in agent definition by name.
|
|
824
|
+
* Returns `undefined` if no built-in agent matches.
|
|
825
|
+
*/
|
|
826
|
+
declare function getBuiltInAgent(name: string): IAgentDefinition | undefined;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* AgentTool — spawn a sub-agent with isolated context.
|
|
830
|
+
*
|
|
831
|
+
* Uses `createSubagentSession` to assemble a child Session with filtered tools,
|
|
832
|
+
* model resolution, and framework system prompt. The sub-agent shares the same
|
|
833
|
+
* config and context but has its own conversation history.
|
|
834
|
+
*
|
|
835
|
+
* Each call to `createAgentTool(deps)` returns a fresh tool instance with deps
|
|
836
|
+
* captured in closure, eliminating module-level mutable state and enabling
|
|
837
|
+
* multiple concurrent sessions without race conditions.
|
|
838
|
+
*/
|
|
839
|
+
|
|
840
|
+
/** Dependencies injected at creation time via createAgentTool factory */
|
|
380
841
|
interface IAgentToolDeps {
|
|
381
842
|
config: IResolvedConfig;
|
|
382
843
|
context: ILoadedContext;
|
|
383
|
-
|
|
844
|
+
tools: IToolWithEventService[];
|
|
845
|
+
terminal: ITerminalOutput;
|
|
846
|
+
/** Permission mode from parent session (bypassPermissions, acceptEdits, etc.). */
|
|
847
|
+
permissionMode?: TPermissionMode;
|
|
848
|
+
permissionHandler?: TPermissionHandler;
|
|
849
|
+
/** Plugin hooks configuration from parent session. */
|
|
850
|
+
hooks?: Record<string, unknown>;
|
|
851
|
+
/** Hook type executors from parent session (prompt, agent, etc.). */
|
|
852
|
+
hookTypeExecutors?: IHookTypeExecutor[];
|
|
853
|
+
onTextDelta?: (delta: string) => void;
|
|
854
|
+
onToolExecution?: (event: {
|
|
855
|
+
type: 'start' | 'end';
|
|
856
|
+
toolName: string;
|
|
857
|
+
toolArgs?: TToolArgs;
|
|
858
|
+
success?: boolean;
|
|
859
|
+
}) => void;
|
|
860
|
+
/** Optional custom agent registry for resolving non-built-in agent types. */
|
|
861
|
+
customAgentRegistry?: (name: string) => IAgentDefinition | undefined;
|
|
862
|
+
}
|
|
863
|
+
/** Store agent tool deps keyed by a session (or any object). */
|
|
864
|
+
declare function storeAgentToolDeps(key: object, deps: IAgentToolDeps): void;
|
|
865
|
+
/** Retrieve agent tool deps for a given session key. */
|
|
866
|
+
declare function retrieveAgentToolDeps(key: object): IAgentToolDeps | undefined;
|
|
867
|
+
/**
|
|
868
|
+
* Create an agent tool instance with deps captured in closure.
|
|
869
|
+
*
|
|
870
|
+
* Each session gets its own tool instance — no shared mutable state.
|
|
871
|
+
*/
|
|
872
|
+
declare function createAgentTool(deps: IAgentToolDeps): ReturnType<typeof createZodFunctionTool>;
|
|
873
|
+
|
|
874
|
+
/** A slash command entry */
|
|
875
|
+
interface ISlashCommand {
|
|
876
|
+
/** Command name without slash (e.g., "mode") */
|
|
877
|
+
name: string;
|
|
878
|
+
/** Short description shown in autocomplete */
|
|
879
|
+
description: string;
|
|
880
|
+
/** Source identifier (e.g., "builtin", "skill") */
|
|
881
|
+
source: string;
|
|
882
|
+
/** Subcommands for hierarchical menus */
|
|
883
|
+
subcommands?: ISlashCommand[];
|
|
884
|
+
/** Execute the command. Args is everything after the command name. */
|
|
885
|
+
execute?: (args: string) => void | Promise<void>;
|
|
886
|
+
/** Full SKILL.md content (only for skill commands) */
|
|
887
|
+
skillContent?: string;
|
|
888
|
+
/** Hint for the expected argument (Claude Code frontmatter) */
|
|
889
|
+
argumentHint?: string;
|
|
890
|
+
/** When true, models cannot invoke this skill autonomously */
|
|
891
|
+
disableModelInvocation?: boolean;
|
|
892
|
+
/** When false, users cannot invoke this skill directly */
|
|
893
|
+
userInvocable?: boolean;
|
|
894
|
+
/** List of tools this skill is allowed to use */
|
|
895
|
+
allowedTools?: string[];
|
|
896
|
+
/** Preferred model for executing this skill */
|
|
897
|
+
model?: string;
|
|
898
|
+
/** Effort level hint for the skill */
|
|
899
|
+
effort?: string;
|
|
900
|
+
/** Context scope for the skill (e.g., "project") */
|
|
901
|
+
context?: string;
|
|
902
|
+
/** Agent identity to use when executing this skill */
|
|
903
|
+
agent?: string;
|
|
904
|
+
/** Plugin installation directory (plugin skills/commands only) */
|
|
905
|
+
pluginDir?: string;
|
|
906
|
+
}
|
|
907
|
+
/** A source that provides slash commands */
|
|
908
|
+
interface ICommandSource {
|
|
909
|
+
name: string;
|
|
910
|
+
getCommands(): ISlashCommand[];
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/** Aggregates commands from multiple sources */
|
|
914
|
+
declare class CommandRegistry {
|
|
915
|
+
private sources;
|
|
916
|
+
addSource(source: ICommandSource): void;
|
|
917
|
+
/** Get all commands, optionally filtered by prefix */
|
|
918
|
+
getCommands(filter?: string): ISlashCommand[];
|
|
919
|
+
/** Resolve a short name to its fully qualified plugin:name form */
|
|
920
|
+
resolveQualifiedName(shortName: string): string | null;
|
|
921
|
+
/** Get subcommands for a specific command */
|
|
922
|
+
getSubcommands(commandName: string): ISlashCommand[];
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/** Command source for built-in commands */
|
|
926
|
+
declare class BuiltinCommandSource implements ICommandSource {
|
|
927
|
+
readonly name = "builtin";
|
|
928
|
+
private readonly commands;
|
|
929
|
+
constructor();
|
|
930
|
+
getCommands(): ISlashCommand[];
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
interface IFrontmatter {
|
|
934
|
+
name?: string;
|
|
935
|
+
description?: string;
|
|
936
|
+
argumentHint?: string;
|
|
937
|
+
disableModelInvocation?: boolean;
|
|
938
|
+
userInvocable?: boolean;
|
|
939
|
+
allowedTools?: string[];
|
|
940
|
+
model?: string;
|
|
941
|
+
effort?: string;
|
|
942
|
+
context?: string;
|
|
943
|
+
agent?: string;
|
|
944
|
+
}
|
|
945
|
+
/** Parse YAML-like frontmatter between --- markers */
|
|
946
|
+
declare function parseFrontmatter(content: string): IFrontmatter | null;
|
|
947
|
+
/** Command source that discovers skills from multiple directories */
|
|
948
|
+
declare class SkillCommandSource implements ICommandSource {
|
|
949
|
+
readonly name = "skill";
|
|
950
|
+
private readonly cwd;
|
|
951
|
+
private readonly home;
|
|
952
|
+
private cachedCommands;
|
|
953
|
+
constructor(cwd: string, home?: string);
|
|
954
|
+
getCommands(): ISlashCommand[];
|
|
955
|
+
getModelInvocableSkills(): ISlashCommand[];
|
|
956
|
+
getUserInvocableSkills(): ISlashCommand[];
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Types for InteractiveSession — event-driven session wrapper.
|
|
961
|
+
*/
|
|
962
|
+
|
|
963
|
+
/** Tool execution state visible to clients. */
|
|
964
|
+
interface IToolState {
|
|
965
|
+
toolName: string;
|
|
966
|
+
firstArg: string;
|
|
967
|
+
isRunning: boolean;
|
|
968
|
+
result?: 'success' | 'error' | 'denied';
|
|
969
|
+
diffLines?: IDiffLine[];
|
|
970
|
+
diffFile?: string;
|
|
971
|
+
}
|
|
972
|
+
/** A single diff line for Edit tool display. */
|
|
973
|
+
interface IDiffLine {
|
|
974
|
+
type: 'add' | 'remove' | 'context';
|
|
975
|
+
content: string;
|
|
976
|
+
lineNumber?: number;
|
|
977
|
+
}
|
|
978
|
+
/** Result of a completed prompt execution. */
|
|
979
|
+
interface IExecutionResult {
|
|
980
|
+
response: string;
|
|
981
|
+
messages: TUniversalMessage[];
|
|
982
|
+
toolSummaries: IToolSummary[];
|
|
983
|
+
contextState: IContextWindowState;
|
|
984
|
+
}
|
|
985
|
+
/** Summary of a tool call extracted from history. */
|
|
986
|
+
interface IToolSummary {
|
|
987
|
+
name: string;
|
|
988
|
+
args: string;
|
|
989
|
+
}
|
|
990
|
+
/** Permission handler delegate — clients provide their own UI. */
|
|
991
|
+
type TInteractivePermissionHandler = (toolName: string, toolArgs: TToolArgs) => Promise<TPermissionResult>;
|
|
992
|
+
/** Events emitted by InteractiveSession. */
|
|
993
|
+
interface IInteractiveSessionEvents {
|
|
994
|
+
text_delta: (delta: string) => void;
|
|
995
|
+
tool_start: (state: IToolState) => void;
|
|
996
|
+
tool_end: (state: IToolState) => void;
|
|
997
|
+
thinking: (isThinking: boolean) => void;
|
|
998
|
+
complete: (result: IExecutionResult) => void;
|
|
999
|
+
error: (error: Error) => void;
|
|
1000
|
+
context_update: (state: IContextWindowState) => void;
|
|
1001
|
+
interrupted: (result: IExecutionResult) => void;
|
|
1002
|
+
}
|
|
1003
|
+
type TInteractiveEventName = keyof IInteractiveSessionEvents;
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* InteractiveSession — event-driven session wrapper for any client.
|
|
1007
|
+
*
|
|
1008
|
+
* Wraps Session (composition) to provide streaming text accumulation,
|
|
1009
|
+
* tool execution state tracking, prompt queuing, abort orchestration,
|
|
1010
|
+
* and message history management. Previously embedded in CLI React hooks.
|
|
1011
|
+
*
|
|
1012
|
+
* Clients (CLI, web, API server, Dynamic Worker) subscribe to events
|
|
1013
|
+
* and call submit/abort/cancelQueue.
|
|
1014
|
+
*/
|
|
1015
|
+
|
|
1016
|
+
interface IInteractiveSessionOptions {
|
|
1017
|
+
config: ICreateSessionOptions['config'];
|
|
1018
|
+
context: ICreateSessionOptions['context'];
|
|
1019
|
+
projectInfo?: ICreateSessionOptions['projectInfo'];
|
|
1020
|
+
sessionStore?: ICreateSessionOptions['sessionStore'];
|
|
1021
|
+
permissionMode?: ICreateSessionOptions['permissionMode'];
|
|
1022
|
+
maxTurns?: number;
|
|
1023
|
+
cwd?: string;
|
|
1024
|
+
permissionHandler?: TInteractivePermissionHandler;
|
|
1025
|
+
/** Optional: inject pre-built session (for testing). */
|
|
1026
|
+
session?: Session;
|
|
1027
|
+
}
|
|
1028
|
+
declare class InteractiveSession {
|
|
1029
|
+
private readonly session;
|
|
1030
|
+
private readonly listeners;
|
|
1031
|
+
private streamingText;
|
|
1032
|
+
private flushTimer;
|
|
1033
|
+
private activeTools;
|
|
1034
|
+
private executing;
|
|
1035
|
+
private pendingPrompt;
|
|
1036
|
+
private pendingDisplayInput;
|
|
1037
|
+
private pendingRawInput;
|
|
1038
|
+
private messages;
|
|
1039
|
+
constructor(options: IInteractiveSessionOptions);
|
|
1040
|
+
on<E extends TInteractiveEventName>(event: E, handler: IInteractiveSessionEvents[E]): void;
|
|
1041
|
+
off<E extends TInteractiveEventName>(event: E, handler: IInteractiveSessionEvents[E]): void;
|
|
1042
|
+
private emit;
|
|
1043
|
+
/** Submit a prompt. Queues if already executing (max 1 queued).
|
|
1044
|
+
* displayInput overrides what appears as the user message (e.g., "/audit" instead of full skill prompt).
|
|
1045
|
+
* rawInput is passed to Session.run() for hook matching (e.g., "/rulebased-harness:audit"). */
|
|
1046
|
+
submit(input: string, displayInput?: string, rawInput?: string): Promise<void>;
|
|
1047
|
+
/** Abort current execution and clear queue. */
|
|
1048
|
+
abort(): void;
|
|
1049
|
+
/** Cancel queued prompt without aborting current execution. */
|
|
1050
|
+
cancelQueue(): void;
|
|
1051
|
+
isExecuting(): boolean;
|
|
1052
|
+
getPendingPrompt(): string | null;
|
|
1053
|
+
getMessages(): TUniversalMessage[];
|
|
1054
|
+
getStreamingText(): string;
|
|
1055
|
+
getActiveTools(): IToolState[];
|
|
1056
|
+
getContextState(): IContextWindowState;
|
|
1057
|
+
getSession(): Session;
|
|
1058
|
+
private executePrompt;
|
|
1059
|
+
private handleTextDelta;
|
|
1060
|
+
private handleToolExecution;
|
|
1061
|
+
private clearStreaming;
|
|
1062
|
+
private flushStreaming;
|
|
1063
|
+
private buildResult;
|
|
1064
|
+
private buildInterruptedResult;
|
|
1065
|
+
private extractToolSummaries;
|
|
1066
|
+
private trimCompletedTools;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* System commands — SDK-level command execution logic.
|
|
1071
|
+
*
|
|
1072
|
+
* Pure functions that operate on InteractiveSession.
|
|
1073
|
+
* No React, no TUI, no framework dependencies.
|
|
1074
|
+
* CLI wraps these as slash commands with UI chrome.
|
|
1075
|
+
*/
|
|
1076
|
+
|
|
1077
|
+
/** Result of a system command execution. */
|
|
1078
|
+
interface ICommandResult {
|
|
1079
|
+
/** Human-readable output message */
|
|
1080
|
+
message: string;
|
|
1081
|
+
/** Command completed successfully */
|
|
1082
|
+
success: boolean;
|
|
1083
|
+
/** Additional structured data (command-specific) */
|
|
1084
|
+
data?: Record<string, unknown>;
|
|
1085
|
+
}
|
|
1086
|
+
/** A system command with name, description, and execute logic. */
|
|
1087
|
+
interface ISystemCommand {
|
|
1088
|
+
name: string;
|
|
1089
|
+
description: string;
|
|
1090
|
+
execute(session: InteractiveSession, args: string): Promise<ICommandResult> | ICommandResult;
|
|
1091
|
+
}
|
|
1092
|
+
/** Built-in system commands. */
|
|
1093
|
+
declare function createSystemCommands(): ISystemCommand[];
|
|
1094
|
+
/** Registry for system commands. */
|
|
1095
|
+
declare class SystemCommandExecutor {
|
|
1096
|
+
private readonly commands;
|
|
1097
|
+
constructor(commands?: ISystemCommand[]);
|
|
1098
|
+
/** Register an additional command. */
|
|
1099
|
+
register(command: ISystemCommand): void;
|
|
1100
|
+
/** Execute a command by name. Returns null if command not found. */
|
|
1101
|
+
execute(name: string, session: InteractiveSession, args: string): Promise<ICommandResult | null>;
|
|
1102
|
+
/** List all registered commands. */
|
|
1103
|
+
listCommands(): ISystemCommand[];
|
|
1104
|
+
/** Check if a command exists. */
|
|
1105
|
+
hasCommand(name: string): boolean;
|
|
384
1106
|
}
|
|
385
|
-
/** Set dependencies for the agent tool. Must be called before tool is used. */
|
|
386
|
-
declare function setAgentToolDeps(deps: IAgentToolDeps): void;
|
|
387
|
-
declare const agentTool: _robota_sdk_agent_tools.FunctionTool;
|
|
388
1107
|
|
|
389
|
-
export { DEFAULT_TOOL_DESCRIPTIONS, type ICreateSessionOptions, type ILoadedContext, type IProjectInfo, type IQueryOptions, type IResolvedConfig, type ISystemPromptParams,
|
|
1108
|
+
export { AgentExecutor, BUILT_IN_AGENTS, BuiltinCommandSource, BundlePluginInstaller, BundlePluginLoader, CommandRegistry, DEFAULT_TOOL_DESCRIPTIONS, type IAgentDefinition, type IAgentExecutorOptions, type IAgentSession, type IAgentToolDeps, type IBundlePluginFeatures, type IBundlePluginInstallerOptions, type IBundlePluginManifest, type IBundleSkill, type ICommandResult, type ICommandSource, type ICreateSessionOptions, type IDiffLine, type IExecutionResult, type IInstalledPluginRecord, type IInstalledPluginsRegistry, type IInteractiveSessionEvents, type IInteractiveSessionOptions, type IKnownMarketplaceEntry, type IKnownMarketplacesRegistry, type ILoadedBundlePlugin, type ILoadedContext, type IMarketplaceClientOptions, type IMarketplaceManifest, type IMarketplacePluginEntry, type IMarketplaceSource, type IPluginSettings, type IProjectInfo, type IPromptExecutorOptions, type IPromptProvider, type IQueryOptions, type IResolvedConfig, type ISlashCommand, type ISubagentOptions, type ISubagentPromptOptions, type ISystemCommand, type ISystemPromptParams, type IToolState, type IToolSummary, InteractiveSession, MarketplaceClient, PluginSettingsStore, PromptExecutor, SkillCommandSource, SystemCommandExecutor, type TEnabledPlugins, type TInteractiveEventName, type TInteractivePermissionHandler, type TProviderFactory, type TSessionFactory, assembleSubagentPrompt, buildSystemPrompt, createAgentTool, createDefaultTools, createProvider, createSession, createSubagentLogger, createSubagentSession, createSystemCommands, detectProject, getBuiltInAgent, getForkWorkerSuffix, getSubagentSuffix, loadConfig, loadContext, parseFrontmatter, projectPaths, promptForApproval, query, resolveSubagentLogDir, retrieveAgentToolDeps, storeAgentToolDeps, userPaths };
|