@robota-sdk/agent-sdk 3.0.0-beta.4 → 3.0.0-beta.44

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