@robota-sdk/agent-sdk 3.0.0-beta.5 → 3.0.0-beta.50

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