@robota-sdk/agent-sdk 3.0.0-beta.43 → 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.
- package/README.md +1 -1
- package/dist/node/index.cjs +843 -639
- package/dist/node/index.d.cts +339 -314
- package/dist/node/index.d.ts +339 -314
- package/dist/node/index.js +871 -649
- package/package.json +4 -5
package/dist/node/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IHookTypeExecutor, IHookDefinition, IHookInput, IHookResult, THooksConfig, TTrustLevel, TPermissionMode, IAIProvider, TToolArgs, IToolWithEventService,
|
|
2
|
-
export { IContextTokenUsage, IContextWindowState, IHookInput, IPermissionLists, THookEvent, THooksConfig, TPermissionDecision, TPermissionMode, TRUST_TO_MODE, TToolArgs, TTrustLevel, evaluatePermission, runHooks } from '@robota-sdk/agent-core';
|
|
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';
|
|
3
5
|
import { createZodFunctionTool } from '@robota-sdk/agent-tools';
|
|
4
|
-
export { TToolResult
|
|
5
|
-
import { ITerminalOutput, SessionStore, TPermissionHandler, ISessionLogger, Session, FileSessionLogger, TPermissionResult } from '@robota-sdk/agent-sessions';
|
|
6
|
-
export { FileSessionLogger, ISessionLogger, ISessionOptions, ISessionRecord, ISpinner, ITerminalOutput, Session, SessionStore, SilentSessionLogger, TPermissionHandler, TPermissionResult, TSessionLogData } from '@robota-sdk/agent-sessions';
|
|
6
|
+
export { TToolResult } from '@robota-sdk/agent-tools';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Prompt hook executor — evaluates a prompt via an AI model.
|
|
@@ -112,13 +112,6 @@ interface ILoadedContext {
|
|
|
112
112
|
/** Extracted "Compact Instructions" section from CLAUDE.md, if present */
|
|
113
113
|
compactInstructions?: string;
|
|
114
114
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Load all AGENTS.md and CLAUDE.md files found by walking up from `cwd`.
|
|
117
|
-
* Files from higher directories appear before files from lower directories.
|
|
118
|
-
*
|
|
119
|
-
* @param cwd - Starting directory for the walk-up search
|
|
120
|
-
*/
|
|
121
|
-
declare function loadContext(cwd: string): Promise<ILoadedContext>;
|
|
122
115
|
|
|
123
116
|
type TProjectType = 'node' | 'python' | 'rust' | 'go' | 'unknown';
|
|
124
117
|
type TPackageManager = 'pnpm' | 'yarn' | 'npm' | 'bun';
|
|
@@ -129,10 +122,6 @@ interface IProjectInfo {
|
|
|
129
122
|
packageManager?: TPackageManager;
|
|
130
123
|
language: TLanguage;
|
|
131
124
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Detect the project type, language, name, and package manager from `cwd`.
|
|
134
|
-
*/
|
|
135
|
-
declare function detectProject(cwd: string): Promise<IProjectInfo>;
|
|
136
125
|
|
|
137
126
|
/**
|
|
138
127
|
* System prompt builder — assembles the system message sent to the AI model
|
|
@@ -162,7 +151,6 @@ interface ISystemPromptParams {
|
|
|
162
151
|
disableModelInvocation?: boolean;
|
|
163
152
|
}>;
|
|
164
153
|
}
|
|
165
|
-
declare function buildSystemPrompt(params: ISystemPromptParams): string;
|
|
166
154
|
|
|
167
155
|
/**
|
|
168
156
|
* Session factory — assembles a fully-configured Session from config, context,
|
|
@@ -223,35 +211,6 @@ interface ICreateSessionOptions {
|
|
|
223
211
|
/** Additional hook type executors beyond the defaults (prompt, agent). */
|
|
224
212
|
additionalHookExecutors?: IHookTypeExecutor[];
|
|
225
213
|
}
|
|
226
|
-
/**
|
|
227
|
-
* Create a fully-configured Session instance.
|
|
228
|
-
*
|
|
229
|
-
* Assembles provider, tools, and system prompt, then passes them
|
|
230
|
-
* to Session as pre-constructed dependencies.
|
|
231
|
-
*/
|
|
232
|
-
declare function createSession(options: ICreateSessionOptions): Session;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Default tool set factory — creates the standard set of CLI tools.
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
/** Human-readable descriptions of the built-in tools (for system prompt) */
|
|
239
|
-
declare const DEFAULT_TOOL_DESCRIPTIONS: string[];
|
|
240
|
-
/**
|
|
241
|
-
* Create the default set of CLI tools.
|
|
242
|
-
* Returns the 8 standard tools as IToolWithEventService[].
|
|
243
|
-
*/
|
|
244
|
-
declare function createDefaultTools(): IToolWithEventService[];
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Provider factory — creates an AI provider from resolved config.
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Create an AI provider from the resolved config.
|
|
252
|
-
* Currently supports Anthropic only. Throws if no API key is available.
|
|
253
|
-
*/
|
|
254
|
-
declare function createProvider(config: IResolvedConfig): IAIProvider;
|
|
255
214
|
|
|
256
215
|
/**
|
|
257
216
|
* Framework system prompt suffixes for subagent sessions.
|
|
@@ -331,6 +290,8 @@ interface ISubagentOptions {
|
|
|
331
290
|
parentContext: ILoadedContext;
|
|
332
291
|
/** Parent session's available tools (to inherit/filter). */
|
|
333
292
|
parentTools: IToolWithEventService[];
|
|
293
|
+
/** AI provider instance. */
|
|
294
|
+
provider: IAIProvider;
|
|
334
295
|
/** Terminal output interface. */
|
|
335
296
|
terminal: ITerminalOutput;
|
|
336
297
|
/** Whether this is a fork worker (uses fork suffix instead of standard). */
|
|
@@ -394,63 +355,260 @@ declare function createSubagentLogger(parentSessionId: string, _agentId: string,
|
|
|
394
355
|
declare function resolveSubagentLogDir(parentSessionId: string, baseLogsDir: string): string;
|
|
395
356
|
|
|
396
357
|
/**
|
|
397
|
-
*
|
|
398
|
-
* Automatically loads config, context, and project info.
|
|
358
|
+
* Types for InteractiveSession — event-driven session wrapper.
|
|
399
359
|
*/
|
|
400
360
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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;
|
|
410
372
|
}
|
|
411
|
-
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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;
|
|
417
405
|
|
|
418
406
|
/**
|
|
419
|
-
*
|
|
407
|
+
* InteractiveSession — the single entry point for all SDK consumers.
|
|
420
408
|
*
|
|
421
|
-
*
|
|
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.
|
|
422
414
|
*/
|
|
423
|
-
declare function loadConfig(cwd: string): Promise<IResolvedConfig>;
|
|
424
415
|
|
|
425
|
-
/**
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
+
}
|
|
430
492
|
|
|
431
493
|
/**
|
|
432
|
-
*
|
|
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?');
|
|
433
499
|
*/
|
|
434
|
-
declare function promptForApproval(terminal: ITerminalOutput, toolName: string, toolArgs: TToolArgs): Promise<boolean>;
|
|
435
500
|
|
|
501
|
+
interface ICreateQueryOptions {
|
|
502
|
+
/** AI provider instance (required). */
|
|
503
|
+
provider: IAIProvider;
|
|
504
|
+
/** Working directory. Defaults to process.cwd(). */
|
|
505
|
+
cwd?: string;
|
|
506
|
+
/** Permission mode. Defaults to 'bypassPermissions' for programmatic use. */
|
|
507
|
+
permissionMode?: TPermissionMode;
|
|
508
|
+
/** Maximum agentic turns per query. */
|
|
509
|
+
maxTurns?: number;
|
|
510
|
+
/** Permission handler callback. */
|
|
511
|
+
permissionHandler?: TInteractivePermissionHandler;
|
|
512
|
+
/** Streaming text callback. */
|
|
513
|
+
onTextDelta?: (delta: string) => void;
|
|
514
|
+
}
|
|
436
515
|
/**
|
|
437
|
-
*
|
|
516
|
+
* Create a prompt-only query function bound to a provider.
|
|
438
517
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
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
|
+
* ```
|
|
441
525
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
+
}
|
|
454
612
|
|
|
455
613
|
/**
|
|
456
614
|
* PluginSettingsStore — single point of read/write for plugin-related settings.
|
|
@@ -814,6 +972,75 @@ declare class BundlePluginInstaller {
|
|
|
814
972
|
private defaultExec;
|
|
815
973
|
}
|
|
816
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
|
+
|
|
817
1044
|
/**
|
|
818
1045
|
* All built-in agent definitions shipped with the SDK.
|
|
819
1046
|
* Order matters: general-purpose is the default fallback.
|
|
@@ -843,6 +1070,8 @@ interface IAgentToolDeps {
|
|
|
843
1070
|
context: ILoadedContext;
|
|
844
1071
|
tools: IToolWithEventService[];
|
|
845
1072
|
terminal: ITerminalOutput;
|
|
1073
|
+
/** AI provider instance (passed from consumer). */
|
|
1074
|
+
provider: IAIProvider;
|
|
846
1075
|
/** Permission mode from parent session (bypassPermissions, acceptEdits, etc.). */
|
|
847
1076
|
permissionMode?: TPermissionMode;
|
|
848
1077
|
permissionHandler?: TPermissionHandler;
|
|
@@ -871,238 +1100,34 @@ declare function retrieveAgentToolDeps(key: object): IAgentToolDeps | undefined;
|
|
|
871
1100
|
*/
|
|
872
1101
|
declare function createAgentTool(deps: IAgentToolDeps): ReturnType<typeof createZodFunctionTool>;
|
|
873
1102
|
|
|
874
|
-
/** A slash command entry */
|
|
875
|
-
interface ISlashCommand {
|
|
876
|
-
/** Command name without slash (e.g., "mode") */
|
|
877
|
-
name: string;
|
|
878
|
-
/** Short description shown in autocomplete */
|
|
879
|
-
description: string;
|
|
880
|
-
/** Source identifier (e.g., "builtin", "skill") */
|
|
881
|
-
source: string;
|
|
882
|
-
/** Subcommands for hierarchical menus */
|
|
883
|
-
subcommands?: ISlashCommand[];
|
|
884
|
-
/** Execute the command. Args is everything after the command name. */
|
|
885
|
-
execute?: (args: string) => void | Promise<void>;
|
|
886
|
-
/** Full SKILL.md content (only for skill commands) */
|
|
887
|
-
skillContent?: string;
|
|
888
|
-
/** Hint for the expected argument (Claude Code frontmatter) */
|
|
889
|
-
argumentHint?: string;
|
|
890
|
-
/** When true, models cannot invoke this skill autonomously */
|
|
891
|
-
disableModelInvocation?: boolean;
|
|
892
|
-
/** When false, users cannot invoke this skill directly */
|
|
893
|
-
userInvocable?: boolean;
|
|
894
|
-
/** List of tools this skill is allowed to use */
|
|
895
|
-
allowedTools?: string[];
|
|
896
|
-
/** Preferred model for executing this skill */
|
|
897
|
-
model?: string;
|
|
898
|
-
/** Effort level hint for the skill */
|
|
899
|
-
effort?: string;
|
|
900
|
-
/** Context scope for the skill (e.g., "project") */
|
|
901
|
-
context?: string;
|
|
902
|
-
/** Agent identity to use when executing this skill */
|
|
903
|
-
agent?: string;
|
|
904
|
-
/** Plugin installation directory (plugin skills/commands only) */
|
|
905
|
-
pluginDir?: string;
|
|
906
|
-
}
|
|
907
|
-
/** A source that provides slash commands */
|
|
908
|
-
interface ICommandSource {
|
|
909
|
-
name: string;
|
|
910
|
-
getCommands(): ISlashCommand[];
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
/** Aggregates commands from multiple sources */
|
|
914
|
-
declare class CommandRegistry {
|
|
915
|
-
private sources;
|
|
916
|
-
addSource(source: ICommandSource): void;
|
|
917
|
-
/** Get all commands, optionally filtered by prefix */
|
|
918
|
-
getCommands(filter?: string): ISlashCommand[];
|
|
919
|
-
/** Resolve a short name to its fully qualified plugin:name form */
|
|
920
|
-
resolveQualifiedName(shortName: string): string | null;
|
|
921
|
-
/** Get subcommands for a specific command */
|
|
922
|
-
getSubcommands(commandName: string): ISlashCommand[];
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
/** Command source for built-in commands */
|
|
926
|
-
declare class BuiltinCommandSource implements ICommandSource {
|
|
927
|
-
readonly name = "builtin";
|
|
928
|
-
private readonly commands;
|
|
929
|
-
constructor();
|
|
930
|
-
getCommands(): ISlashCommand[];
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
interface IFrontmatter {
|
|
934
|
-
name?: string;
|
|
935
|
-
description?: string;
|
|
936
|
-
argumentHint?: string;
|
|
937
|
-
disableModelInvocation?: boolean;
|
|
938
|
-
userInvocable?: boolean;
|
|
939
|
-
allowedTools?: string[];
|
|
940
|
-
model?: string;
|
|
941
|
-
effort?: string;
|
|
942
|
-
context?: string;
|
|
943
|
-
agent?: string;
|
|
944
|
-
}
|
|
945
|
-
/** Parse YAML-like frontmatter between --- markers */
|
|
946
|
-
declare function parseFrontmatter(content: string): IFrontmatter | null;
|
|
947
|
-
/** Command source that discovers skills from multiple directories */
|
|
948
|
-
declare class SkillCommandSource implements ICommandSource {
|
|
949
|
-
readonly name = "skill";
|
|
950
|
-
private readonly cwd;
|
|
951
|
-
private readonly home;
|
|
952
|
-
private cachedCommands;
|
|
953
|
-
constructor(cwd: string, home?: string);
|
|
954
|
-
getCommands(): ISlashCommand[];
|
|
955
|
-
getModelInvocableSkills(): ISlashCommand[];
|
|
956
|
-
getUserInvocableSkills(): ISlashCommand[];
|
|
957
|
-
}
|
|
958
|
-
|
|
959
1103
|
/**
|
|
960
|
-
*
|
|
1104
|
+
* Standard Robota storage paths.
|
|
1105
|
+
*
|
|
1106
|
+
* All CLI runtime data lives under .robota/ (project) or ~/.robota/ (user).
|
|
1107
|
+
* .agents/ is read-only from CLI's perspective (owned by AGENTS.md standard).
|
|
961
1108
|
*/
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
type: 'add' | 'remove' | 'context';
|
|
975
|
-
content: string;
|
|
976
|
-
lineNumber?: number;
|
|
977
|
-
}
|
|
978
|
-
/** Result of a completed prompt execution. */
|
|
979
|
-
interface IExecutionResult {
|
|
980
|
-
response: string;
|
|
981
|
-
messages: TUniversalMessage[];
|
|
982
|
-
toolSummaries: IToolSummary[];
|
|
983
|
-
contextState: IContextWindowState;
|
|
984
|
-
}
|
|
985
|
-
/** Summary of a tool call extracted from history. */
|
|
986
|
-
interface IToolSummary {
|
|
987
|
-
name: string;
|
|
988
|
-
args: string;
|
|
989
|
-
}
|
|
990
|
-
/** Permission handler delegate — clients provide their own UI. */
|
|
991
|
-
type TInteractivePermissionHandler = (toolName: string, toolArgs: TToolArgs) => Promise<TPermissionResult>;
|
|
992
|
-
/** Events emitted by InteractiveSession. */
|
|
993
|
-
interface IInteractiveSessionEvents {
|
|
994
|
-
text_delta: (delta: string) => void;
|
|
995
|
-
tool_start: (state: IToolState) => void;
|
|
996
|
-
tool_end: (state: IToolState) => void;
|
|
997
|
-
thinking: (isThinking: boolean) => void;
|
|
998
|
-
complete: (result: IExecutionResult) => void;
|
|
999
|
-
error: (error: Error) => void;
|
|
1000
|
-
context_update: (state: IContextWindowState) => void;
|
|
1001
|
-
interrupted: (result: IExecutionResult) => void;
|
|
1002
|
-
}
|
|
1003
|
-
type TInteractiveEventName = keyof IInteractiveSessionEvents;
|
|
1109
|
+
/** Project-level .robota/ paths (relative to cwd). */
|
|
1110
|
+
declare function projectPaths(cwd: string): {
|
|
1111
|
+
settings: string;
|
|
1112
|
+
settingsLocal: string;
|
|
1113
|
+
logs: string;
|
|
1114
|
+
sessions: string;
|
|
1115
|
+
};
|
|
1116
|
+
/** User-level ~/.robota/ paths. */
|
|
1117
|
+
declare function userPaths(): {
|
|
1118
|
+
settings: string;
|
|
1119
|
+
sessions: string;
|
|
1120
|
+
};
|
|
1004
1121
|
|
|
1005
1122
|
/**
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1009
|
-
* tool execution state tracking, prompt queuing, abort orchestration,
|
|
1010
|
-
* and message history management. Previously embedded in CLI React hooks.
|
|
1011
|
-
*
|
|
1012
|
-
* Clients (CLI, web, API server, Dynamic Worker) subscribe to events
|
|
1013
|
-
* and call submit/abort/cancelQueue.
|
|
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.
|
|
1014
1126
|
*/
|
|
1015
1127
|
|
|
1016
|
-
interface IInteractiveSessionOptions {
|
|
1017
|
-
config: ICreateSessionOptions['config'];
|
|
1018
|
-
context: ICreateSessionOptions['context'];
|
|
1019
|
-
projectInfo?: ICreateSessionOptions['projectInfo'];
|
|
1020
|
-
sessionStore?: ICreateSessionOptions['sessionStore'];
|
|
1021
|
-
permissionMode?: ICreateSessionOptions['permissionMode'];
|
|
1022
|
-
maxTurns?: number;
|
|
1023
|
-
cwd?: string;
|
|
1024
|
-
permissionHandler?: TInteractivePermissionHandler;
|
|
1025
|
-
/** Optional: inject pre-built session (for testing). */
|
|
1026
|
-
session?: Session;
|
|
1027
|
-
}
|
|
1028
|
-
declare class InteractiveSession {
|
|
1029
|
-
private readonly session;
|
|
1030
|
-
private readonly listeners;
|
|
1031
|
-
private streamingText;
|
|
1032
|
-
private flushTimer;
|
|
1033
|
-
private activeTools;
|
|
1034
|
-
private executing;
|
|
1035
|
-
private pendingPrompt;
|
|
1036
|
-
private pendingDisplayInput;
|
|
1037
|
-
private pendingRawInput;
|
|
1038
|
-
private messages;
|
|
1039
|
-
constructor(options: IInteractiveSessionOptions);
|
|
1040
|
-
on<E extends TInteractiveEventName>(event: E, handler: IInteractiveSessionEvents[E]): void;
|
|
1041
|
-
off<E extends TInteractiveEventName>(event: E, handler: IInteractiveSessionEvents[E]): void;
|
|
1042
|
-
private emit;
|
|
1043
|
-
/** Submit a prompt. Queues if already executing (max 1 queued).
|
|
1044
|
-
* displayInput overrides what appears as the user message (e.g., "/audit" instead of full skill prompt).
|
|
1045
|
-
* rawInput is passed to Session.run() for hook matching (e.g., "/rulebased-harness:audit"). */
|
|
1046
|
-
submit(input: string, displayInput?: string, rawInput?: string): Promise<void>;
|
|
1047
|
-
/** Abort current execution and clear queue. */
|
|
1048
|
-
abort(): void;
|
|
1049
|
-
/** Cancel queued prompt without aborting current execution. */
|
|
1050
|
-
cancelQueue(): void;
|
|
1051
|
-
isExecuting(): boolean;
|
|
1052
|
-
getPendingPrompt(): string | null;
|
|
1053
|
-
getMessages(): TUniversalMessage[];
|
|
1054
|
-
getStreamingText(): string;
|
|
1055
|
-
getActiveTools(): IToolState[];
|
|
1056
|
-
getContextState(): IContextWindowState;
|
|
1057
|
-
getSession(): Session;
|
|
1058
|
-
private executePrompt;
|
|
1059
|
-
private handleTextDelta;
|
|
1060
|
-
private handleToolExecution;
|
|
1061
|
-
private clearStreaming;
|
|
1062
|
-
private flushStreaming;
|
|
1063
|
-
private buildResult;
|
|
1064
|
-
private buildInterruptedResult;
|
|
1065
|
-
private extractToolSummaries;
|
|
1066
|
-
private trimCompletedTools;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
1128
|
/**
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1072
|
-
* Pure functions that operate on InteractiveSession.
|
|
1073
|
-
* No React, no TUI, no framework dependencies.
|
|
1074
|
-
* CLI wraps these as slash commands with UI chrome.
|
|
1129
|
+
* Prompt the user for approval before running a tool.
|
|
1075
1130
|
*/
|
|
1131
|
+
declare function promptForApproval(terminal: ITerminalOutput, toolName: string, toolArgs: TToolArgs): Promise<boolean>;
|
|
1076
1132
|
|
|
1077
|
-
|
|
1078
|
-
interface ICommandResult {
|
|
1079
|
-
/** Human-readable output message */
|
|
1080
|
-
message: string;
|
|
1081
|
-
/** Command completed successfully */
|
|
1082
|
-
success: boolean;
|
|
1083
|
-
/** Additional structured data (command-specific) */
|
|
1084
|
-
data?: Record<string, unknown>;
|
|
1085
|
-
}
|
|
1086
|
-
/** A system command with name, description, and execute logic. */
|
|
1087
|
-
interface ISystemCommand {
|
|
1088
|
-
name: string;
|
|
1089
|
-
description: string;
|
|
1090
|
-
execute(session: InteractiveSession, args: string): Promise<ICommandResult> | ICommandResult;
|
|
1091
|
-
}
|
|
1092
|
-
/** Built-in system commands. */
|
|
1093
|
-
declare function createSystemCommands(): ISystemCommand[];
|
|
1094
|
-
/** Registry for system commands. */
|
|
1095
|
-
declare class SystemCommandExecutor {
|
|
1096
|
-
private readonly commands;
|
|
1097
|
-
constructor(commands?: ISystemCommand[]);
|
|
1098
|
-
/** Register an additional command. */
|
|
1099
|
-
register(command: ISystemCommand): void;
|
|
1100
|
-
/** Execute a command by name. Returns null if command not found. */
|
|
1101
|
-
execute(name: string, session: InteractiveSession, args: string): Promise<ICommandResult | null>;
|
|
1102
|
-
/** List all registered commands. */
|
|
1103
|
-
listCommands(): ISystemCommand[];
|
|
1104
|
-
/** Check if a command exists. */
|
|
1105
|
-
hasCommand(name: string): boolean;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
export { AgentExecutor, BUILT_IN_AGENTS, BuiltinCommandSource, BundlePluginInstaller, BundlePluginLoader, CommandRegistry, DEFAULT_TOOL_DESCRIPTIONS, type IAgentDefinition, type IAgentExecutorOptions, type IAgentSession, type IAgentToolDeps, type IBundlePluginFeatures, type IBundlePluginInstallerOptions, type IBundlePluginManifest, type IBundleSkill, type ICommandResult, type ICommandSource, type ICreateSessionOptions, type IDiffLine, type IExecutionResult, type IInstalledPluginRecord, type IInstalledPluginsRegistry, type IInteractiveSessionEvents, type IInteractiveSessionOptions, type IKnownMarketplaceEntry, type IKnownMarketplacesRegistry, type ILoadedBundlePlugin, type ILoadedContext, type IMarketplaceClientOptions, type IMarketplaceManifest, type IMarketplacePluginEntry, type IMarketplaceSource, type IPluginSettings, type IProjectInfo, type IPromptExecutorOptions, type IPromptProvider, type IQueryOptions, type IResolvedConfig, type ISlashCommand, type ISubagentOptions, type ISubagentPromptOptions, type ISystemCommand, type ISystemPromptParams, type IToolState, type IToolSummary, InteractiveSession, MarketplaceClient, PluginSettingsStore, PromptExecutor, SkillCommandSource, SystemCommandExecutor, type TEnabledPlugins, type TInteractiveEventName, type TInteractivePermissionHandler, type TProviderFactory, type TSessionFactory, assembleSubagentPrompt, buildSystemPrompt, createAgentTool, createDefaultTools, createProvider, createSession, createSubagentLogger, createSubagentSession, createSystemCommands, detectProject, getBuiltInAgent, getForkWorkerSuffix, getSubagentSuffix, loadConfig, loadContext, parseFrontmatter, projectPaths, promptForApproval, query, resolveSubagentLogDir, retrieveAgentToolDeps, storeAgentToolDeps, userPaths };
|
|
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 };
|