@robota-sdk/agent-sdk 3.0.0-beta.3 → 3.0.0-beta.31
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/dist/node/index.cjs +1250 -145
- package/dist/node/index.d.cts +569 -195
- package/dist/node/index.d.ts +569 -195
- package/dist/node/index.js +1251 -139
- package/package.json +5 -5
package/dist/node/index.d.ts
CHANGED
|
@@ -1,202 +1,84 @@
|
|
|
1
|
-
import { TPermissionMode, IAIProvider, TToolArgs,
|
|
1
|
+
import { IHookTypeExecutor, IHookDefinition, IHookInput, IHookResult, THooksConfig, TTrustLevel, TPermissionMode, IAIProvider, TToolArgs, IToolWithEventService } from '@robota-sdk/agent-core';
|
|
2
2
|
export { IContextTokenUsage, IContextWindowState, IHookInput, IPermissionLists, THookEvent, THooksConfig, TPermissionDecision, TPermissionMode, TRUST_TO_MODE, TToolArgs, TTrustLevel, evaluatePermission, runHooks } from '@robota-sdk/agent-core';
|
|
3
3
|
import * as _robota_sdk_agent_tools from '@robota-sdk/agent-tools';
|
|
4
4
|
export { TToolResult, bashTool, editTool, globTool, grepTool, readTool, writeTool } from '@robota-sdk/agent-tools';
|
|
5
|
-
import { ITerminalOutput,
|
|
5
|
+
import { ITerminalOutput, SessionStore, TPermissionHandler, ISessionLogger, Session } from '@robota-sdk/agent-sessions';
|
|
6
6
|
export { FileSessionLogger, ISessionLogger, ISessionOptions, ISessionRecord, ISpinner, ITerminalOutput, Session, SessionStore, SilentSessionLogger, TPermissionHandler, TPermissionResult, TSessionLogData } from '@robota-sdk/agent-sessions';
|
|
7
|
-
import { z } from 'zod';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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)
|
|
12
18
|
*/
|
|
13
19
|
|
|
14
|
-
interface
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
maxTurns?: number;
|
|
18
|
-
provider?: IAIProvider;
|
|
19
|
-
permissionHandler?: (toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
20
|
-
onTextDelta?: (delta: string) => void;
|
|
21
|
-
/** Callback when context is compacted */
|
|
22
|
-
onCompact?: (summary: string) => void;
|
|
20
|
+
/** A minimal provider interface for single-turn completion. */
|
|
21
|
+
interface IPromptProvider {
|
|
22
|
+
complete(prompt: string): Promise<string>;
|
|
23
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
|
+
|
|
24
39
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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)
|
|
28
49
|
*/
|
|
29
|
-
|
|
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
|
+
}
|
|
30
70
|
|
|
31
71
|
/**
|
|
32
72
|
* Zod schemas and TypeScript types for Robota CLI settings
|
|
33
73
|
*/
|
|
34
74
|
|
|
35
|
-
declare const HooksSchema: z.ZodOptional<z.ZodObject<{
|
|
36
|
-
PreToolUse: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
37
|
-
matcher: z.ZodString;
|
|
38
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
39
|
-
type: z.ZodLiteral<"command">;
|
|
40
|
-
command: z.ZodString;
|
|
41
|
-
}, "strip", z.ZodTypeAny, {
|
|
42
|
-
type: "command";
|
|
43
|
-
command: string;
|
|
44
|
-
}, {
|
|
45
|
-
type: "command";
|
|
46
|
-
command: string;
|
|
47
|
-
}>, "many">;
|
|
48
|
-
}, "strip", z.ZodTypeAny, {
|
|
49
|
-
matcher: string;
|
|
50
|
-
hooks: {
|
|
51
|
-
type: "command";
|
|
52
|
-
command: string;
|
|
53
|
-
}[];
|
|
54
|
-
}, {
|
|
55
|
-
matcher: string;
|
|
56
|
-
hooks: {
|
|
57
|
-
type: "command";
|
|
58
|
-
command: string;
|
|
59
|
-
}[];
|
|
60
|
-
}>, "many">>;
|
|
61
|
-
PostToolUse: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
62
|
-
matcher: z.ZodString;
|
|
63
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
64
|
-
type: z.ZodLiteral<"command">;
|
|
65
|
-
command: z.ZodString;
|
|
66
|
-
}, "strip", z.ZodTypeAny, {
|
|
67
|
-
type: "command";
|
|
68
|
-
command: string;
|
|
69
|
-
}, {
|
|
70
|
-
type: "command";
|
|
71
|
-
command: string;
|
|
72
|
-
}>, "many">;
|
|
73
|
-
}, "strip", z.ZodTypeAny, {
|
|
74
|
-
matcher: string;
|
|
75
|
-
hooks: {
|
|
76
|
-
type: "command";
|
|
77
|
-
command: string;
|
|
78
|
-
}[];
|
|
79
|
-
}, {
|
|
80
|
-
matcher: string;
|
|
81
|
-
hooks: {
|
|
82
|
-
type: "command";
|
|
83
|
-
command: string;
|
|
84
|
-
}[];
|
|
85
|
-
}>, "many">>;
|
|
86
|
-
SessionStart: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
87
|
-
matcher: z.ZodString;
|
|
88
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
89
|
-
type: z.ZodLiteral<"command">;
|
|
90
|
-
command: z.ZodString;
|
|
91
|
-
}, "strip", z.ZodTypeAny, {
|
|
92
|
-
type: "command";
|
|
93
|
-
command: string;
|
|
94
|
-
}, {
|
|
95
|
-
type: "command";
|
|
96
|
-
command: string;
|
|
97
|
-
}>, "many">;
|
|
98
|
-
}, "strip", z.ZodTypeAny, {
|
|
99
|
-
matcher: string;
|
|
100
|
-
hooks: {
|
|
101
|
-
type: "command";
|
|
102
|
-
command: string;
|
|
103
|
-
}[];
|
|
104
|
-
}, {
|
|
105
|
-
matcher: string;
|
|
106
|
-
hooks: {
|
|
107
|
-
type: "command";
|
|
108
|
-
command: string;
|
|
109
|
-
}[];
|
|
110
|
-
}>, "many">>;
|
|
111
|
-
Stop: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
112
|
-
matcher: z.ZodString;
|
|
113
|
-
hooks: z.ZodArray<z.ZodObject<{
|
|
114
|
-
type: z.ZodLiteral<"command">;
|
|
115
|
-
command: z.ZodString;
|
|
116
|
-
}, "strip", z.ZodTypeAny, {
|
|
117
|
-
type: "command";
|
|
118
|
-
command: string;
|
|
119
|
-
}, {
|
|
120
|
-
type: "command";
|
|
121
|
-
command: string;
|
|
122
|
-
}>, "many">;
|
|
123
|
-
}, "strip", z.ZodTypeAny, {
|
|
124
|
-
matcher: string;
|
|
125
|
-
hooks: {
|
|
126
|
-
type: "command";
|
|
127
|
-
command: string;
|
|
128
|
-
}[];
|
|
129
|
-
}, {
|
|
130
|
-
matcher: string;
|
|
131
|
-
hooks: {
|
|
132
|
-
type: "command";
|
|
133
|
-
command: string;
|
|
134
|
-
}[];
|
|
135
|
-
}>, "many">>;
|
|
136
|
-
}, "strip", z.ZodTypeAny, {
|
|
137
|
-
PreToolUse?: {
|
|
138
|
-
matcher: string;
|
|
139
|
-
hooks: {
|
|
140
|
-
type: "command";
|
|
141
|
-
command: string;
|
|
142
|
-
}[];
|
|
143
|
-
}[] | undefined;
|
|
144
|
-
PostToolUse?: {
|
|
145
|
-
matcher: string;
|
|
146
|
-
hooks: {
|
|
147
|
-
type: "command";
|
|
148
|
-
command: string;
|
|
149
|
-
}[];
|
|
150
|
-
}[] | undefined;
|
|
151
|
-
SessionStart?: {
|
|
152
|
-
matcher: string;
|
|
153
|
-
hooks: {
|
|
154
|
-
type: "command";
|
|
155
|
-
command: string;
|
|
156
|
-
}[];
|
|
157
|
-
}[] | undefined;
|
|
158
|
-
Stop?: {
|
|
159
|
-
matcher: string;
|
|
160
|
-
hooks: {
|
|
161
|
-
type: "command";
|
|
162
|
-
command: string;
|
|
163
|
-
}[];
|
|
164
|
-
}[] | undefined;
|
|
165
|
-
}, {
|
|
166
|
-
PreToolUse?: {
|
|
167
|
-
matcher: string;
|
|
168
|
-
hooks: {
|
|
169
|
-
type: "command";
|
|
170
|
-
command: string;
|
|
171
|
-
}[];
|
|
172
|
-
}[] | undefined;
|
|
173
|
-
PostToolUse?: {
|
|
174
|
-
matcher: string;
|
|
175
|
-
hooks: {
|
|
176
|
-
type: "command";
|
|
177
|
-
command: string;
|
|
178
|
-
}[];
|
|
179
|
-
}[] | undefined;
|
|
180
|
-
SessionStart?: {
|
|
181
|
-
matcher: string;
|
|
182
|
-
hooks: {
|
|
183
|
-
type: "command";
|
|
184
|
-
command: string;
|
|
185
|
-
}[];
|
|
186
|
-
}[] | undefined;
|
|
187
|
-
Stop?: {
|
|
188
|
-
matcher: string;
|
|
189
|
-
hooks: {
|
|
190
|
-
type: "command";
|
|
191
|
-
command: string;
|
|
192
|
-
}[];
|
|
193
|
-
}[] | undefined;
|
|
194
|
-
}>>;
|
|
195
75
|
/**
|
|
196
76
|
* Fully resolved config after merging all settings files and applying defaults.
|
|
197
77
|
*/
|
|
198
78
|
interface IResolvedConfig {
|
|
199
79
|
defaultTrustLevel: 'safe' | 'moderate' | 'full';
|
|
80
|
+
/** Response language code (e.g., "ko", "en"). Undefined = no language constraint. */
|
|
81
|
+
language?: string;
|
|
200
82
|
provider: {
|
|
201
83
|
name: string;
|
|
202
84
|
model: string;
|
|
@@ -207,16 +89,21 @@ interface IResolvedConfig {
|
|
|
207
89
|
deny: string[];
|
|
208
90
|
};
|
|
209
91
|
env: Record<string, string>;
|
|
210
|
-
hooks?:
|
|
92
|
+
hooks?: THooksConfig;
|
|
93
|
+
/** Plugin enablement map: plugin name -> enabled/disabled */
|
|
94
|
+
enabledPlugins?: Record<string, boolean>;
|
|
95
|
+
/** Extra marketplace sources: name -> { source } */
|
|
96
|
+
extraKnownMarketplaces?: Record<string, {
|
|
97
|
+
source: {
|
|
98
|
+
type: string;
|
|
99
|
+
repo?: string;
|
|
100
|
+
url?: string;
|
|
101
|
+
path?: string;
|
|
102
|
+
ref?: string;
|
|
103
|
+
};
|
|
104
|
+
}>;
|
|
211
105
|
}
|
|
212
106
|
|
|
213
|
-
/**
|
|
214
|
-
* Load and merge all settings files, validate with Zod, return resolved config.
|
|
215
|
-
*
|
|
216
|
-
* @param cwd - The working directory (project root) to search for .robota/
|
|
217
|
-
*/
|
|
218
|
-
declare function loadConfig(cwd: string): Promise<IResolvedConfig>;
|
|
219
|
-
|
|
220
107
|
interface ILoadedContext {
|
|
221
108
|
/** Concatenated content of all AGENTS.md files found (root-first) */
|
|
222
109
|
agentsMd: string;
|
|
@@ -264,16 +151,141 @@ interface ISystemPromptParams {
|
|
|
264
151
|
trustLevel: TTrustLevel;
|
|
265
152
|
/** Detected project metadata */
|
|
266
153
|
projectInfo: IProjectInfo;
|
|
154
|
+
/** Current working directory */
|
|
155
|
+
cwd?: string;
|
|
156
|
+
/** Response language code (e.g., "ko", "en"). If set, AI must respond in this language. */
|
|
157
|
+
language?: string;
|
|
158
|
+
/** Discovered skills to expose in the system prompt */
|
|
159
|
+
skills?: Array<{
|
|
160
|
+
name: string;
|
|
161
|
+
description: string;
|
|
162
|
+
disableModelInvocation?: boolean;
|
|
163
|
+
}>;
|
|
267
164
|
}
|
|
165
|
+
declare function buildSystemPrompt(params: ISystemPromptParams): string;
|
|
166
|
+
|
|
268
167
|
/**
|
|
269
|
-
*
|
|
168
|
+
* Session factory — assembles a fully-configured Session from config, context,
|
|
169
|
+
* tools, and provider.
|
|
170
|
+
*
|
|
171
|
+
* This is the main entry point for creating sessions. It wires together
|
|
172
|
+
* the provider, tools, system prompt, and configuration that Session now
|
|
173
|
+
* expects as pre-constructed dependencies.
|
|
270
174
|
*/
|
|
271
|
-
|
|
175
|
+
|
|
176
|
+
/** Options for the createSession factory */
|
|
177
|
+
interface ICreateSessionOptions {
|
|
178
|
+
/** Resolved CLI configuration (model, API key, permissions) */
|
|
179
|
+
config: IResolvedConfig;
|
|
180
|
+
/** Loaded AGENTS.md / CLAUDE.md context */
|
|
181
|
+
context: ILoadedContext;
|
|
182
|
+
/** Terminal I/O for permission prompts */
|
|
183
|
+
terminal: ITerminalOutput;
|
|
184
|
+
/** Project metadata for system prompt */
|
|
185
|
+
projectInfo?: IProjectInfo;
|
|
186
|
+
/** Initial permission mode (defaults to config.defaultTrustLevel → mode mapping) */
|
|
187
|
+
permissionMode?: TPermissionMode;
|
|
188
|
+
/** Maximum number of agentic turns per run() call. Undefined = unlimited. */
|
|
189
|
+
maxTurns?: number;
|
|
190
|
+
/** Optional session store for persistence */
|
|
191
|
+
sessionStore?: SessionStore;
|
|
192
|
+
/** Inject a pre-constructed AI provider (used by tests to avoid real API calls) */
|
|
193
|
+
provider?: IAIProvider;
|
|
194
|
+
/** Custom permission handler (overrides terminal-based prompts, used by Ink UI) */
|
|
195
|
+
permissionHandler?: TPermissionHandler;
|
|
196
|
+
/** Callback for text deltas — enables streaming text to the UI in real-time */
|
|
197
|
+
onTextDelta?: (delta: string) => void;
|
|
198
|
+
/** Custom prompt-for-approval function (injected from CLI) */
|
|
199
|
+
promptForApproval?: (terminal: ITerminalOutput, toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
200
|
+
/** Additional tools to register beyond the defaults (e.g. agent-tool) */
|
|
201
|
+
additionalTools?: IToolWithEventService[];
|
|
202
|
+
/** Callback when a tool starts or finishes execution — enables real-time tool display in UI */
|
|
203
|
+
onToolExecution?: (event: {
|
|
204
|
+
type: 'start' | 'end';
|
|
205
|
+
toolName: string;
|
|
206
|
+
toolArgs?: TToolArgs;
|
|
207
|
+
success?: boolean;
|
|
208
|
+
}) => void;
|
|
209
|
+
/** Callback when context is compacted */
|
|
210
|
+
onCompact?: (summary: string) => void;
|
|
211
|
+
/** Instructions to include in the compaction prompt (e.g. from CLAUDE.md) */
|
|
212
|
+
compactInstructions?: string;
|
|
213
|
+
/** Custom system prompt builder function */
|
|
214
|
+
systemPromptBuilder?: (params: ISystemPromptParams) => string;
|
|
215
|
+
/** Custom tool descriptions for the system prompt */
|
|
216
|
+
toolDescriptions?: string[];
|
|
217
|
+
/** Session logger — injected for pluggable session event logging. */
|
|
218
|
+
sessionLogger?: ISessionLogger;
|
|
219
|
+
/** Provider factory for prompt hook executors (DI). */
|
|
220
|
+
providerFactory?: TProviderFactory;
|
|
221
|
+
/** Session factory for agent hook executors (DI). */
|
|
222
|
+
sessionFactory?: TSessionFactory;
|
|
223
|
+
/** Additional hook type executors beyond the defaults (prompt, agent). */
|
|
224
|
+
additionalHookExecutors?: IHookTypeExecutor[];
|
|
225
|
+
}
|
|
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
|
+
|
|
256
|
+
/**
|
|
257
|
+
* query() — single entry point for running an AI agent conversation.
|
|
258
|
+
* Automatically loads config, context, and project info.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
interface IQueryOptions {
|
|
262
|
+
cwd?: string;
|
|
263
|
+
permissionMode?: TPermissionMode;
|
|
264
|
+
maxTurns?: number;
|
|
265
|
+
provider?: IAIProvider;
|
|
266
|
+
permissionHandler?: (toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
267
|
+
onTextDelta?: (delta: string) => void;
|
|
268
|
+
/** Callback when context is compacted */
|
|
269
|
+
onCompact?: (summary: string) => void;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* query() — single entry point for running an AI agent conversation.
|
|
273
|
+
* Equivalent to Claude Agent SDK's query() function.
|
|
274
|
+
* Automatically loads config, context, and project info.
|
|
275
|
+
*/
|
|
276
|
+
declare function query(prompt: string, options?: IQueryOptions): Promise<string>;
|
|
272
277
|
|
|
273
278
|
/**
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* The
|
|
279
|
+
* Load and merge all settings files, validate with Zod, return resolved config.
|
|
280
|
+
*
|
|
281
|
+
* @param cwd - The working directory (project root) to search for settings
|
|
282
|
+
*/
|
|
283
|
+
declare function loadConfig(cwd: string): Promise<IResolvedConfig>;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Interactive permission prompt — asks the user whether to allow a tool invocation
|
|
287
|
+
* using an arrow-key selector. Canonical implementation (SSOT).
|
|
288
|
+
* Used by both agent-sdk query() and agent-cli.
|
|
277
289
|
*/
|
|
278
290
|
|
|
279
291
|
/**
|
|
@@ -300,14 +312,376 @@ declare function userPaths(): {
|
|
|
300
312
|
sessions: string;
|
|
301
313
|
};
|
|
302
314
|
|
|
315
|
+
/**
|
|
316
|
+
* PluginSettingsStore — single point of read/write for plugin-related settings.
|
|
317
|
+
*
|
|
318
|
+
* Shared by MarketplaceClient and BundlePluginInstaller to prevent
|
|
319
|
+
* concurrent writes from overwriting each other's changes.
|
|
320
|
+
*/
|
|
321
|
+
/** Source type for a marketplace registry. */
|
|
322
|
+
type IMarketplaceSource$1 = {
|
|
323
|
+
type: 'github';
|
|
324
|
+
repo: string;
|
|
325
|
+
ref?: string;
|
|
326
|
+
} | {
|
|
327
|
+
type: 'git';
|
|
328
|
+
url: string;
|
|
329
|
+
ref?: string;
|
|
330
|
+
} | {
|
|
331
|
+
type: 'local';
|
|
332
|
+
path: string;
|
|
333
|
+
} | {
|
|
334
|
+
type: 'url';
|
|
335
|
+
url: string;
|
|
336
|
+
};
|
|
337
|
+
/** Persisted marketplace source entry. */
|
|
338
|
+
interface IPersistedMarketplaceSource {
|
|
339
|
+
source: IMarketplaceSource$1;
|
|
340
|
+
}
|
|
341
|
+
/** Shape of the plugin-related keys in settings.json. */
|
|
342
|
+
interface IPluginSettings {
|
|
343
|
+
enabledPlugins: Record<string, boolean>;
|
|
344
|
+
extraKnownMarketplaces: Record<string, IPersistedMarketplaceSource>;
|
|
345
|
+
}
|
|
346
|
+
/** Centralized settings store for plugin configuration. */
|
|
347
|
+
declare class PluginSettingsStore {
|
|
348
|
+
private readonly settingsPath;
|
|
349
|
+
constructor(settingsPath: string);
|
|
350
|
+
/** Read the full settings file from disk. */
|
|
351
|
+
private readAll;
|
|
352
|
+
/** Write the full settings file to disk. */
|
|
353
|
+
private writeAll;
|
|
354
|
+
/** Get the enabledPlugins map. */
|
|
355
|
+
getEnabledPlugins(): Record<string, boolean>;
|
|
356
|
+
/** Set a single plugin's enabled state. */
|
|
357
|
+
setPluginEnabled(pluginId: string, enabled: boolean): void;
|
|
358
|
+
/** Remove a plugin from enabledPlugins. */
|
|
359
|
+
removePluginEntry(pluginId: string): void;
|
|
360
|
+
/** Get all persisted marketplace sources. */
|
|
361
|
+
getMarketplaceSources(): Record<string, IPersistedMarketplaceSource>;
|
|
362
|
+
/** Add or update a marketplace source. */
|
|
363
|
+
setMarketplaceSource(name: string, source: IMarketplaceSource$1): void;
|
|
364
|
+
/** Remove a marketplace source. */
|
|
365
|
+
removeMarketplaceSource(name: string): void;
|
|
366
|
+
private getEnabledPluginsFrom;
|
|
367
|
+
private getMarketplaceSourcesFrom;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Types for the BundlePlugin system.
|
|
372
|
+
*
|
|
373
|
+
* A BundlePlugin is a directory-based plugin package that bundles
|
|
374
|
+
* skills, hooks, agents, and MCP server configurations.
|
|
375
|
+
*/
|
|
376
|
+
/** Feature flags indicating what a bundle plugin provides. */
|
|
377
|
+
interface IBundlePluginFeatures {
|
|
378
|
+
commands?: boolean;
|
|
379
|
+
agents?: boolean;
|
|
380
|
+
skills?: boolean;
|
|
381
|
+
hooks?: boolean;
|
|
382
|
+
mcp?: boolean;
|
|
383
|
+
}
|
|
384
|
+
/** Manifest read from `.claude-plugin/plugin.json`. */
|
|
385
|
+
interface IBundlePluginManifest {
|
|
386
|
+
name: string;
|
|
387
|
+
version: string;
|
|
388
|
+
description: string;
|
|
389
|
+
features: IBundlePluginFeatures;
|
|
390
|
+
}
|
|
391
|
+
/** A skill loaded from a bundle plugin's `skills/` directory. */
|
|
392
|
+
interface IBundleSkill {
|
|
393
|
+
name: string;
|
|
394
|
+
description: string;
|
|
395
|
+
skillContent: string;
|
|
396
|
+
[key: string]: unknown;
|
|
397
|
+
}
|
|
398
|
+
/** A fully loaded bundle plugin with all its assets. */
|
|
399
|
+
interface ILoadedBundlePlugin {
|
|
400
|
+
manifest: IBundlePluginManifest;
|
|
401
|
+
skills: IBundleSkill[];
|
|
402
|
+
commands: IBundleSkill[];
|
|
403
|
+
hooks: Record<string, unknown>;
|
|
404
|
+
mcpConfig?: unknown;
|
|
405
|
+
agents: string[];
|
|
406
|
+
pluginDir: string;
|
|
407
|
+
}
|
|
408
|
+
/** Map of plugin identifiers to enabled/disabled state. */
|
|
409
|
+
type TEnabledPlugins = Record<string, boolean>;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* BundlePluginLoader — discovers and loads directory-based bundle plugins.
|
|
413
|
+
*
|
|
414
|
+
* Scans the cache directory (`<pluginsDir>/cache/<marketplace>/<plugin>/<version>/`)
|
|
415
|
+
* for subdirectories containing `.claude-plugin/plugin.json`,
|
|
416
|
+
* reads manifests, loads skills (with frontmatter parsing), hooks, and agent definitions.
|
|
417
|
+
*
|
|
418
|
+
* For each plugin, the latest version directory (lexicographically last) is loaded.
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
/** Loader for directory-based bundle plugins from the cache directory. */
|
|
422
|
+
declare class BundlePluginLoader {
|
|
423
|
+
private readonly pluginsDir;
|
|
424
|
+
private readonly enabledPlugins;
|
|
425
|
+
constructor(pluginsDir: string, enabledPlugins?: TEnabledPlugins);
|
|
426
|
+
/** Load all discovered and enabled bundle plugins (sync). */
|
|
427
|
+
loadPluginsSync(): ILoadedBundlePlugin[];
|
|
428
|
+
/** Load all discovered and enabled bundle plugins (async wrapper). */
|
|
429
|
+
loadAll(): Promise<ILoadedBundlePlugin[]>;
|
|
430
|
+
/**
|
|
431
|
+
* Discover and load plugins from the cache directory.
|
|
432
|
+
*
|
|
433
|
+
* Directory structure: `<pluginsDir>/cache/<marketplace>/<plugin>/<version>/`
|
|
434
|
+
* For each marketplace/plugin pair, the latest version (lexicographically last) is loaded.
|
|
435
|
+
*/
|
|
436
|
+
private discoverAndLoad;
|
|
437
|
+
/** Read and validate a plugin.json manifest. Returns null on failure. */
|
|
438
|
+
private readManifest;
|
|
439
|
+
/**
|
|
440
|
+
* Check if a plugin is explicitly disabled.
|
|
441
|
+
* Checks both `name@marketplace` and `name` keys.
|
|
442
|
+
* Plugins not listed in enabledPlugins are enabled by default.
|
|
443
|
+
*/
|
|
444
|
+
private isDisabled;
|
|
445
|
+
/** Load a single plugin's skills, hooks, agents, and MCP config. */
|
|
446
|
+
private loadPlugin;
|
|
447
|
+
/** Load skills from the plugin's skills/ directory. */
|
|
448
|
+
private loadSkills;
|
|
449
|
+
/** Load commands from the plugin's commands/ directory (flat .md files). */
|
|
450
|
+
private loadCommands;
|
|
451
|
+
/** Load hooks from hooks/hooks.json if present. */
|
|
452
|
+
private loadHooks;
|
|
453
|
+
/** Load MCP server configuration if present. Checks `.mcp.json` at plugin root first. */
|
|
454
|
+
private loadMcpConfig;
|
|
455
|
+
/** Load agent definitions from agents/ directory if present. */
|
|
456
|
+
private loadAgents;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* MarketplaceClient — manages marketplace registries via shallow git clones.
|
|
461
|
+
*
|
|
462
|
+
* Marketplaces are git repositories containing `.claude-plugin/marketplace.json`.
|
|
463
|
+
* They are cloned to `~/.robota/plugins/marketplaces/<name>/` and tracked
|
|
464
|
+
* in `known_marketplaces.json`.
|
|
465
|
+
*/
|
|
466
|
+
/** Source specification for a marketplace. */
|
|
467
|
+
type IMarketplaceSource = {
|
|
468
|
+
type: 'github';
|
|
469
|
+
repo: string;
|
|
470
|
+
ref?: string;
|
|
471
|
+
} | {
|
|
472
|
+
type: 'git';
|
|
473
|
+
url: string;
|
|
474
|
+
ref?: string;
|
|
475
|
+
} | {
|
|
476
|
+
type: 'local';
|
|
477
|
+
path: string;
|
|
478
|
+
} | {
|
|
479
|
+
type: 'url';
|
|
480
|
+
url: string;
|
|
481
|
+
};
|
|
482
|
+
/** A single plugin entry in a marketplace manifest. */
|
|
483
|
+
interface IMarketplacePluginEntry {
|
|
484
|
+
name: string;
|
|
485
|
+
title: string;
|
|
486
|
+
description: string;
|
|
487
|
+
source: string | {
|
|
488
|
+
type: 'github';
|
|
489
|
+
repo: string;
|
|
490
|
+
} | {
|
|
491
|
+
type: 'url';
|
|
492
|
+
url: string;
|
|
493
|
+
};
|
|
494
|
+
tags: string[];
|
|
495
|
+
}
|
|
496
|
+
/** Manifest format read from `.claude-plugin/marketplace.json`. */
|
|
497
|
+
interface IMarketplaceManifest {
|
|
498
|
+
name: string;
|
|
499
|
+
version: string;
|
|
500
|
+
plugins: IMarketplacePluginEntry[];
|
|
501
|
+
}
|
|
502
|
+
/** Entry in known_marketplaces.json. */
|
|
503
|
+
interface IKnownMarketplaceEntry {
|
|
504
|
+
source: IMarketplaceSource;
|
|
505
|
+
installLocation: string;
|
|
506
|
+
lastUpdated: string;
|
|
507
|
+
}
|
|
508
|
+
/** Shape of known_marketplaces.json. */
|
|
509
|
+
type IKnownMarketplacesRegistry = Record<string, IKnownMarketplaceEntry>;
|
|
510
|
+
/** Exec function type for running shell commands. */
|
|
511
|
+
type ExecFn$1 = (command: string, options: {
|
|
512
|
+
timeout: number;
|
|
513
|
+
stdio?: string;
|
|
514
|
+
}) => string | Buffer;
|
|
515
|
+
/** Options for constructing a MarketplaceClient. */
|
|
516
|
+
interface IMarketplaceClientOptions {
|
|
517
|
+
/** Base plugins directory (e.g., `~/.robota/plugins`). */
|
|
518
|
+
pluginsDir: string;
|
|
519
|
+
/** Custom exec function for testing (replaces child_process.execSync). */
|
|
520
|
+
exec?: ExecFn$1;
|
|
521
|
+
}
|
|
522
|
+
/** Manages marketplace registries via shallow git clones. */
|
|
523
|
+
declare class MarketplaceClient {
|
|
524
|
+
private readonly pluginsDir;
|
|
525
|
+
private readonly exec;
|
|
526
|
+
private readonly marketplacesDir;
|
|
527
|
+
private readonly registryPath;
|
|
528
|
+
constructor(options: IMarketplaceClientOptions);
|
|
529
|
+
/**
|
|
530
|
+
* Add a marketplace by cloning its repository.
|
|
531
|
+
*
|
|
532
|
+
* 1. Parse source: `owner/repo` string becomes a GitHub source.
|
|
533
|
+
* 2. Shallow git clone (`--depth 1`) to `marketplaces/<name>/`.
|
|
534
|
+
* 3. Read `.claude-plugin/marketplace.json` for the `name` field.
|
|
535
|
+
* 4. Register in `known_marketplaces.json`.
|
|
536
|
+
*
|
|
537
|
+
* Returns the registered marketplace name from the manifest.
|
|
538
|
+
*/
|
|
539
|
+
addMarketplace(source: IMarketplaceSource): string;
|
|
540
|
+
/**
|
|
541
|
+
* Remove a marketplace.
|
|
542
|
+
* Uninstalls all plugins from that marketplace, then deletes the clone directory
|
|
543
|
+
* and removes from the registry.
|
|
544
|
+
*/
|
|
545
|
+
removeMarketplace(name: string): void;
|
|
546
|
+
/**
|
|
547
|
+
* Update a marketplace by running git pull on its clone.
|
|
548
|
+
* The manifest is re-read from disk on demand (via fetchManifest), so the
|
|
549
|
+
* updated manifest is automatically available after pull.
|
|
550
|
+
*
|
|
551
|
+
* TODO: After pull, detect version changes in installed plugins and offer
|
|
552
|
+
* to update them (re-install at new version).
|
|
553
|
+
*/
|
|
554
|
+
updateMarketplace(name: string): void;
|
|
555
|
+
/** List all registered marketplaces. */
|
|
556
|
+
listMarketplaces(): Array<{
|
|
557
|
+
name: string;
|
|
558
|
+
source: IMarketplaceSource;
|
|
559
|
+
lastUpdated: string;
|
|
560
|
+
}>;
|
|
561
|
+
/**
|
|
562
|
+
* Read the marketplace manifest from a registered marketplace's clone.
|
|
563
|
+
*/
|
|
564
|
+
fetchManifest(marketplaceName: string): IMarketplaceManifest;
|
|
565
|
+
/** Get the clone directory path for a registered marketplace. */
|
|
566
|
+
getMarketplaceDir(name: string): string;
|
|
567
|
+
/**
|
|
568
|
+
* Get the current git SHA (first 12 chars) for a marketplace clone.
|
|
569
|
+
* Used as a version identifier when plugins lack explicit versions.
|
|
570
|
+
*/
|
|
571
|
+
getMarketplaceSha(name: string): string;
|
|
572
|
+
/** List all available plugins across all marketplaces. */
|
|
573
|
+
listAvailablePlugins(): Array<IMarketplacePluginEntry & {
|
|
574
|
+
marketplace: string;
|
|
575
|
+
}>;
|
|
576
|
+
/** Resolve a marketplace source to a git clone URL. */
|
|
577
|
+
private resolveCloneUrl;
|
|
578
|
+
/**
|
|
579
|
+
* Remove all installed plugins that belong to a given marketplace.
|
|
580
|
+
* Reads installed_plugins.json, deletes cache directories for matching plugins,
|
|
581
|
+
* and updates the registry.
|
|
582
|
+
*/
|
|
583
|
+
private removeInstalledPluginsForMarketplace;
|
|
584
|
+
/** Read and parse a marketplace.json from a file path. */
|
|
585
|
+
private readManifestFromPath;
|
|
586
|
+
/** Read the known_marketplaces.json registry. */
|
|
587
|
+
private readRegistry;
|
|
588
|
+
/** Write the known_marketplaces.json registry. */
|
|
589
|
+
private writeRegistry;
|
|
590
|
+
/** Default exec implementation using child_process. */
|
|
591
|
+
private defaultExec;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* BundlePluginInstaller — installs, uninstalls, enables, and disables bundle plugins.
|
|
596
|
+
*
|
|
597
|
+
* Resolves plugin sources from marketplace manifests, copies/clones to the
|
|
598
|
+
* cache directory, and tracks installations in `installed_plugins.json`.
|
|
599
|
+
*/
|
|
600
|
+
|
|
601
|
+
/** Record of an installed plugin in installed_plugins.json. */
|
|
602
|
+
interface IInstalledPluginRecord {
|
|
603
|
+
pluginName: string;
|
|
604
|
+
marketplace: string;
|
|
605
|
+
version: string;
|
|
606
|
+
installPath: string;
|
|
607
|
+
installedAt: string;
|
|
608
|
+
}
|
|
609
|
+
/** Shape of installed_plugins.json. */
|
|
610
|
+
type IInstalledPluginsRegistry = Record<string, IInstalledPluginRecord>;
|
|
611
|
+
/** Exec function type for running shell commands. */
|
|
612
|
+
type ExecFn = (command: string, options: {
|
|
613
|
+
timeout: number;
|
|
614
|
+
stdio?: string;
|
|
615
|
+
}) => string | Buffer;
|
|
616
|
+
/** Options for constructing a BundlePluginInstaller. */
|
|
617
|
+
interface IBundlePluginInstallerOptions {
|
|
618
|
+
/** Base plugins directory (e.g., `~/.robota/plugins`). */
|
|
619
|
+
pluginsDir: string;
|
|
620
|
+
/** Shared settings store for enable/disable persistence. */
|
|
621
|
+
settingsStore: PluginSettingsStore;
|
|
622
|
+
/** MarketplaceClient for reading marketplace manifests. */
|
|
623
|
+
marketplaceClient: MarketplaceClient;
|
|
624
|
+
/** Custom exec function for testing (replaces child_process.execSync). */
|
|
625
|
+
exec?: ExecFn;
|
|
626
|
+
}
|
|
627
|
+
/** Installs, uninstalls, enables, and disables bundle plugins. */
|
|
628
|
+
declare class BundlePluginInstaller {
|
|
629
|
+
private readonly pluginsDir;
|
|
630
|
+
private readonly cacheDir;
|
|
631
|
+
private readonly registryPath;
|
|
632
|
+
private readonly settingsStore;
|
|
633
|
+
private readonly marketplaceClient;
|
|
634
|
+
private readonly exec;
|
|
635
|
+
constructor(options: IBundlePluginInstallerOptions);
|
|
636
|
+
/**
|
|
637
|
+
* Install a plugin from a marketplace.
|
|
638
|
+
*
|
|
639
|
+
* 1. Read marketplace manifest to find the plugin entry.
|
|
640
|
+
* 2. Resolve source (relative path, github, or url).
|
|
641
|
+
* 3. Copy/clone to `cache/<marketplace>/<plugin>/<version>/`.
|
|
642
|
+
* 4. Record in `installed_plugins.json`.
|
|
643
|
+
*/
|
|
644
|
+
install(pluginName: string, marketplaceName: string): Promise<void>;
|
|
645
|
+
/**
|
|
646
|
+
* Uninstall a plugin.
|
|
647
|
+
* Removes from cache and from installed_plugins.json.
|
|
648
|
+
*/
|
|
649
|
+
uninstall(pluginId: string): Promise<void>;
|
|
650
|
+
/** Enable a plugin by setting its enabledPlugins entry to true. */
|
|
651
|
+
enable(pluginId: string): Promise<void>;
|
|
652
|
+
/** Disable a plugin by setting its enabledPlugins entry to false. */
|
|
653
|
+
disable(pluginId: string): Promise<void>;
|
|
654
|
+
/** Get all installed plugins. */
|
|
655
|
+
getInstalledPlugins(): IInstalledPluginsRegistry;
|
|
656
|
+
/** Get plugins installed from a specific marketplace. */
|
|
657
|
+
getPluginsByMarketplace(marketplaceName: string): IInstalledPluginRecord[];
|
|
658
|
+
/** Resolve the version for a plugin entry. */
|
|
659
|
+
private resolveVersion;
|
|
660
|
+
/**
|
|
661
|
+
* Normalize source object — Claude Code manifests use `source` key instead of `type`.
|
|
662
|
+
* e.g., { source: "url", url: "..." } → { type: "url", url: "..." }
|
|
663
|
+
*/
|
|
664
|
+
private normalizeSource;
|
|
665
|
+
/** Resolve the source and install the plugin. */
|
|
666
|
+
private resolveAndInstall;
|
|
667
|
+
/** Clone a git repository to the target directory. */
|
|
668
|
+
private cloneToDir;
|
|
669
|
+
/** Read the installed_plugins.json registry. */
|
|
670
|
+
private readRegistry;
|
|
671
|
+
/** Write the installed_plugins.json registry. */
|
|
672
|
+
private writeRegistry;
|
|
673
|
+
/** Default exec implementation using child_process. */
|
|
674
|
+
private defaultExec;
|
|
675
|
+
}
|
|
676
|
+
|
|
303
677
|
/** Dependencies injected at registration time */
|
|
304
678
|
interface IAgentToolDeps {
|
|
305
|
-
config: IResolvedConfig
|
|
306
|
-
context: ILoadedContext
|
|
307
|
-
projectInfo?: IProjectInfo
|
|
679
|
+
config: IResolvedConfig;
|
|
680
|
+
context: ILoadedContext;
|
|
681
|
+
projectInfo?: IProjectInfo;
|
|
308
682
|
}
|
|
309
683
|
/** Set dependencies for the agent tool. Must be called before tool is used. */
|
|
310
684
|
declare function setAgentToolDeps(deps: IAgentToolDeps): void;
|
|
311
685
|
declare const agentTool: _robota_sdk_agent_tools.FunctionTool;
|
|
312
686
|
|
|
313
|
-
export { type ILoadedContext, type IProjectInfo, type IQueryOptions, type IResolvedConfig, type ISystemPromptParams, agentTool, buildSystemPrompt, detectProject, loadConfig, loadContext, projectPaths, promptForApproval, query, setAgentToolDeps, userPaths };
|
|
687
|
+
export { AgentExecutor, BundlePluginInstaller, BundlePluginLoader, DEFAULT_TOOL_DESCRIPTIONS, type IAgentExecutorOptions, type IAgentSession, type IBundlePluginFeatures, type IBundlePluginInstallerOptions, type IBundlePluginManifest, type IBundleSkill, type ICreateSessionOptions, type IInstalledPluginRecord, type IInstalledPluginsRegistry, 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 ISystemPromptParams, MarketplaceClient, PluginSettingsStore, PromptExecutor, type TEnabledPlugins, type TProviderFactory, type TSessionFactory, agentTool, buildSystemPrompt, createDefaultTools, createProvider, createSession, detectProject, loadConfig, loadContext, projectPaths, promptForApproval, query, setAgentToolDeps, userPaths };
|