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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @robota-sdk/agent-sdk
2
2
 
3
- Programmatic SDK for building AI agents with Robota. Provides a single `query()` entry point along with Session management, built-in tools, permissions, hooks, streaming, and context loading.
3
+ Programmatic SDK for building AI agents with Robota. Provides `InteractiveSession` as the central client-facing API, `query()` for one-shot use, session management, built-in tools, permissions, hooks, streaming, and context loading.
4
4
 
5
- This is the **assembly layer** of the Robota ecosystem -- it composes lower-level packages (`agent-core`, `agent-tools`, `agent-sessions`) into a cohesive SDK.
5
+ This is the **assembly layer** of the Robota ecosystem it composes lower-level packages (`agent-core`, `agent-tools`, `agent-sessions`, `agent-provider-anthropic`) into a cohesive SDK.
6
+
7
+ **Version**: 3.0.0-beta.33
6
8
 
7
9
  ## Installation
8
10
 
@@ -31,39 +33,338 @@ const response = await query('Analyze the code', {
31
33
 
32
34
  ## Features
33
35
 
34
- - **query()** -- Single entry point for AI agent interactions with streaming support
35
- - **Session** -- Wraps the Robota engine with permission checks, tool wiring, history, and streaming
36
- - **Built-in Tools** -- Bash, Read, Write, Edit, Glob, Grep (from `@robota-sdk/agent-tools`)
37
- - **Agent Tool** -- Sub-agent session creation for multi-agent workflows
38
- - **Permissions** -- 3-step evaluation (deny list, allow list, mode policy) with four modes: `plan`, `default`, `acceptEdits`, `bypassPermissions`
39
- - **Hooks** -- `PreToolUse`, `PostToolUse`, `SessionStart`, `Stop` events with shell command execution
40
- - **Streaming** -- Real-time text delta callbacks via `onTextDelta`
41
- - **Context Loading** -- AGENTS.md / CLAUDE.md walk-up discovery and system prompt assembly
42
- - **Config Loading** -- 3-layer merge (user global, project, local) with `$ENV:VAR` substitution
43
- - **Context Window Management** -- Token tracking, auto-compaction at ~83.5%, manual `session.compact()`
36
+ - **InteractiveSession** — Event-driven session wrapper (composition over Session). Central client-facing API for CLI, web, API server, or any other client
37
+ - **SystemCommandExecutor + ISystemCommand** SDK-level command execution. Built-in commands: `help`, `clear`, `compact`, `mode`, `model`, `language`, `cost`, `context`, `permissions`, `reset`
38
+ - **CommandRegistry, BuiltinCommandSource, SkillCommandSource** Slash command registry and discovery (owned by SDK; agent-cli re-exports `CommandRegistry` from here)
39
+ - **query()** Single entry point for one-shot AI agent interactions with streaming support
40
+ - **createSession()** Assembly factory: wires tools, provider, config, and context into a Session
41
+ - **Built-in Tools** Bash, Read, Write, Edit, Glob, Grep (re-exported from `@robota-sdk/agent-tools`)
42
+ - **Agent Tool** Sub-agent session creation for multi-agent workflows
43
+ - **Permissions** 3-step evaluation (deny list, allow list, mode policy) with four modes: `plan`, `default`, `acceptEdits`, `bypassPermissions`
44
+ - **Hooks** `PreToolUse`, `PostToolUse`, `PreCompact`, `PostCompact`, `SessionStart`, `UserPromptSubmit`, `Stop` events with shell command execution
45
+ - **Streaming** Real-time text delta callbacks via `onTextDelta`
46
+ - **Context Loading** — AGENTS.md / CLAUDE.md walk-up discovery and system prompt assembly
47
+ - **Config Loading** — 6-layer merge (CLI flags, local, project, Claude Code compat, user global, user global Claude Code compat) with `$ENV:VAR` substitution
48
+ - **Context Window Management** — Token tracking, auto-compaction at ~83.5%, manual `session.compact()`
49
+ - **Bundle Plugin System** — Install and manage reusable extensions packaged as bundle plugins
44
50
 
45
51
  ## Architecture
46
52
 
47
53
  ```
48
54
  agent-sdk (assembly layer)
49
- -> agent-sessions (Session, SessionStore)
50
- -> agent-tools (tool infrastructure + 6 built-in tools)
51
- -> agent-core (Robota engine, providers, permissions, hooks)
55
+ ├── InteractiveSession ← central client-facing API (event-driven)
56
+ └── Session ← generic session (agent-sessions)
57
+ ├── SystemCommandExecutor SDK-level command execution
58
+ ├── CommandRegistry / BuiltinCommandSource / SkillCommandSource
59
+ ├── query() ← one-shot entry point
60
+ ├── createSession() ← assembly factory
61
+ └── deps:
62
+ agent-sessions (Session, SessionStore)
63
+ agent-tools (tool infrastructure + 8 built-in tools)
64
+ agent-provider-anthropic (Anthropic LLM provider)
65
+ agent-core (Robota engine, providers, permissions, hooks)
66
+
67
+ agent-cli (TUI layer — bridges InteractiveSession events to React/Ink state)
68
+ → agent-sdk
69
+ ```
70
+
71
+ The SDK is **pure TypeScript with no React dependency**. The CLI is a thin TUI-only layer that consumes `InteractiveSession` events and maps them to React state. Any other client (web app, API server, worker) can do the same.
72
+
73
+ ## API
74
+
75
+ ### InteractiveSession — Central Client-Facing API
76
+
77
+ `InteractiveSession` wraps `Session` (composition over inheritance) to provide event-driven interaction for any client. It manages streaming text accumulation, tool execution state tracking, prompt queuing, abort orchestration, and message history. Logic that was previously embedded in CLI React hooks now lives here.
78
+
79
+ ```typescript
80
+ import { InteractiveSession } from '@robota-sdk/agent-sdk';
81
+ import type { IInteractiveSessionOptions } from '@robota-sdk/agent-sdk';
82
+
83
+ const session = new InteractiveSession({
84
+ config,
85
+ context,
86
+ projectInfo,
87
+ sessionStore,
88
+ permissionMode: 'default',
89
+ maxTurns: 10,
90
+ cwd: process.cwd(),
91
+ permissionHandler: async (toolName, toolArgs) => ({ allowed: true }),
92
+ });
93
+
94
+ // Subscribe to events
95
+ session.on('text_delta', (delta: string) => {
96
+ process.stdout.write(delta); // streaming text chunk
97
+ });
98
+ session.on('tool_start', (state) => {
99
+ console.log(`Running: ${state.toolName}`);
100
+ });
101
+ session.on('tool_end', (state) => {
102
+ console.log(`Done: ${state.toolName} — ${state.result}`);
103
+ });
104
+ session.on('thinking', (isThinking: boolean) => {
105
+ // show/hide spinner
106
+ });
107
+ session.on('complete', (result) => {
108
+ console.log(result.response);
109
+ });
110
+ session.on('error', (error: Error) => {
111
+ console.error(error);
112
+ });
113
+ session.on('context_update', (state) => {
114
+ // token usage updated
115
+ });
116
+ session.on('interrupted', (result) => {
117
+ // abort completed
118
+ });
119
+
120
+ // Submit a prompt (queues if already executing, max 1 queued)
121
+ await session.submit('Explain this code');
122
+
123
+ // Submit with display override (shown in UI) and raw input (for hook matching)
124
+ await session.submit(fullPrompt, '/audit', '/rulebased-harness:audit');
125
+
126
+ // Abort current execution and clear queue
127
+ session.abort();
128
+
129
+ // Cancel queued prompt without aborting current execution
130
+ session.cancelQueue();
131
+
132
+ // State queries
133
+ session.isExecuting(); // boolean
134
+ session.getPendingPrompt(); // string | null
135
+ session.getMessages(); // TUniversalMessage[]
136
+ session.getContextState(); // IContextWindowState
137
+ session.getStreamingText(); // string (accumulated so far)
138
+ session.getActiveTools(); // IToolState[]
139
+
140
+ // Access underlying Session for advanced use
141
+ session.getSession(); // Session
52
142
  ```
53
143
 
54
- `agent-sdk` assembles existing packages -- it does not re-implement functionality that belongs in lower layers.
144
+ ### SystemCommandExecutor SDK-Level Commands
55
145
 
56
- ## Session Usage
146
+ `SystemCommandExecutor` executes named system commands against an `InteractiveSession`. Commands are pure TypeScript — no React, no TUI dependency. The CLI wraps them as slash commands with UI chrome.
57
147
 
58
148
  ```typescript
59
- import { Session } from '@robota-sdk/agent-sessions';
149
+ import { SystemCommandExecutor, createSystemCommands } from '@robota-sdk/agent-sdk';
150
+ import type { ICommandResult } from '@robota-sdk/agent-sdk';
60
151
 
61
- const session = new Session({ config, context, terminal, permissionMode });
152
+ const executor = new SystemCommandExecutor(); // loads built-in commands by default
153
+
154
+ // Execute a command
155
+ const result: ICommandResult | null = await executor.execute('context', session, '');
156
+ if (result) {
157
+ console.log(result.message); // "Context: 12,345 / 200,000 tokens (6%)"
158
+ console.log(result.data); // { usedTokens, maxTokens, percentage }
159
+ }
160
+
161
+ // Register a custom command
162
+ executor.register({
163
+ name: 'status',
164
+ description: 'Show agent status',
165
+ execute: (session, args) => ({ message: 'OK', success: true }),
166
+ });
167
+
168
+ // List all commands
169
+ executor.listCommands(); // ISystemCommand[]
170
+ executor.hasCommand('mode'); // boolean
171
+ ```
172
+
173
+ Built-in commands:
174
+
175
+ | Command | Description |
176
+ | ------------- | ------------------------------------------------------- |
177
+ | `help` | Show available commands |
178
+ | `clear` | Clear conversation history |
179
+ | `compact` | Compress context window (optional focus instructions) |
180
+ | `mode [m]` | Show or change permission mode |
181
+ | `model <id>` | Change AI model |
182
+ | `language` | Set response language (ko, en, ja, zh) |
183
+ | `cost` | Show session info (session ID, message count) |
184
+ | `context` | Context window token usage |
185
+ | `permissions` | Show current permission mode and session-approved tools |
186
+ | `reset` | Delete settings (caller handles file I/O and exit) |
187
+
188
+ ### CommandRegistry, BuiltinCommandSource, SkillCommandSource
189
+
190
+ These classes provide slash command discovery and aggregation for clients that expose a command palette or autocomplete UI.
191
+
192
+ ```typescript
193
+ import { CommandRegistry, BuiltinCommandSource, SkillCommandSource } from '@robota-sdk/agent-sdk';
194
+
195
+ const registry = new CommandRegistry();
196
+ registry.addSource(new BuiltinCommandSource());
197
+ registry.addSource(new SkillCommandSource(process.cwd()));
198
+
199
+ // Get all commands (returns ICommand[])
200
+ const commands = registry.getCommands();
201
+
202
+ // Filter by prefix (for autocomplete)
203
+ const filtered = registry.getCommands('mod'); // matches "mode", "model"
204
+
205
+ // Resolve short plugin name to fully qualified form
206
+ registry.resolveQualifiedName('audit'); // "my-plugin:audit"
207
+ ```
208
+
209
+ `SkillCommandSource` discovers skills from (highest priority first):
210
+
211
+ - `<cwd>/.claude/skills/*/SKILL.md`
212
+ - `<cwd>/.claude/commands/*.md` (Claude Code compatible)
213
+ - `~/.robota/skills/*/SKILL.md`
214
+ - `<cwd>/.agents/skills/*/SKILL.md`
215
+
216
+ ### query()
217
+
218
+ ```typescript
219
+ import { query } from '@robota-sdk/agent-sdk';
220
+
221
+ const response = await query('Show me the file list');
222
+
223
+ const response = await query('Analyze the code', {
224
+ cwd: '/path/to/project',
225
+ permissionMode: 'acceptEdits',
226
+ maxTurns: 10,
227
+ onTextDelta: (delta) => process.stdout.write(delta),
228
+ onCompact: () => console.log('Context compacted'),
229
+ });
230
+ ```
231
+
232
+ ### createSession()
233
+
234
+ ```typescript
235
+ import { createSession, loadConfig, loadContext, detectProject } from '@robota-sdk/agent-sdk';
236
+
237
+ const [config, context, projectInfo] = await Promise.all([
238
+ loadConfig(cwd),
239
+ loadContext(cwd),
240
+ detectProject(cwd),
241
+ ]);
242
+
243
+ const session = createSession({ config, context, terminal, projectInfo, permissionMode });
62
244
  const response = await session.run('Hello');
63
- session.getHistory();
64
- session.clearHistory();
65
245
  ```
66
246
 
247
+ ### Built-in Tools
248
+
249
+ `@robota-sdk/agent-sdk` re-exports 6 of the 8 built-in tools from `@robota-sdk/agent-tools`:
250
+
251
+ ```typescript
252
+ import { bashTool, readTool, writeTool, editTool, globTool, grepTool } from '@robota-sdk/agent-sdk';
253
+ ```
254
+
255
+ `webFetchTool` and `webSearchTool` are **not** re-exported from `@robota-sdk/agent-sdk`. Import them directly from the owning package:
256
+
257
+ ```typescript
258
+ import { webFetchTool, webSearchTool } from '@robota-sdk/agent-tools';
259
+ ```
260
+
261
+ ## Subagent Sessions
262
+
263
+ `createSubagentSession()` creates an isolated child session for delegating subtasks. The subagent receives pre-resolved config and context from the parent — it does not load config files or context from disk.
264
+
265
+ ```typescript
266
+ import { createSubagentSession } from '@robota-sdk/agent-sdk';
267
+
268
+ const subSession = createSubagentSession({
269
+ parentSession: session,
270
+ agentDefinition: 'explore',
271
+ prompt: 'Analyze the test coverage gaps',
272
+ });
273
+ const result = await subSession.run();
274
+ ```
275
+
276
+ ### Agent Definitions
277
+
278
+ `IAgentDefinition` describes a reusable agent configuration (system prompt, allowed tools, permission mode). Custom agents are discovered from `.robota/agents/` (project), `.claude/agents/` (Claude Code compatible), and `~/.robota/agents/` (user). `AgentDefinitionLoader` is an internal class — it is not part of the public API.
279
+
280
+ Built-in agents: `general-purpose` (full tool access), `Explore` (read-only, Haiku model), `Plan` (read-only planning).
281
+
282
+ ### createAgentTool()
283
+
284
+ `createAgentTool()` wraps subagent creation into a tool the AI can invoke directly. The parent session's hooks, permissions, and context are forwarded to the child.
285
+
286
+ ## Hook Executors (SDK-Specific)
287
+
288
+ `agent-sdk` provides two `IHookTypeExecutor` implementations beyond the `command` and `http` executors in `agent-core`:
289
+
290
+ | Executor | Hook Type | Description |
291
+ | ---------------- | --------- | ------------------------------------------------------------------------- |
292
+ | `PromptExecutor` | `prompt` | Injects the hook's prompt text into the session as a system instruction |
293
+ | `AgentExecutor` | `agent` | Creates a sub-agent session to process the hook input and return a result |
294
+
295
+ ## Bundle Plugin System
296
+
297
+ Bundle plugins package reusable extensions (tools, hooks, permissions, system prompt additions) into installable units.
298
+
299
+ ### Types
300
+
301
+ | Type | Description |
302
+ | ----------------------- | --------------------------------------------------------------- |
303
+ | `IBundlePluginManifest` | Plugin metadata: name, version, description, author, keywords |
304
+ | `ILoadedBundlePlugin` | Full bundle: manifest + tools, hooks, permissions, systemPrompt |
305
+
306
+ ### BundlePluginLoader
307
+
308
+ Loads a bundle plugin from a directory path. Reads the manifest, resolves tool/hook definitions, and validates the bundle structure.
309
+
310
+ ### BundlePluginInstaller
311
+
312
+ Manages plugin installation and uninstallation:
313
+
314
+ - Installs bundles to `~/.robota/plugins/` (user) or `.robota/plugins/` (project)
315
+ - Tracks installed plugins in a registry file
316
+ - Handles enable/disable state per plugin
317
+
318
+ ## Configuration
319
+
320
+ Settings are loaded from (highest priority first):
321
+
322
+ | Layer | Path | Scope |
323
+ | ----- | --------------------------------- | ------------------------------------ |
324
+ | 1 | CLI flags / environment variables | Invocation |
325
+ | 2 | `.robota/settings.local.json` | Project (local) |
326
+ | 3 | `.robota/settings.json` | Project |
327
+ | 4 | `.claude/settings.json` | Project (Claude Code compatible) |
328
+ | 5 | `~/.robota/settings.json` | User global |
329
+ | 6 | `~/.claude/settings.json` | User global (Claude Code compatible) |
330
+
331
+ `$ENV:VAR` substitution is applied after merge.
332
+
333
+ ```json
334
+ {
335
+ "defaultMode": "default",
336
+ "provider": {
337
+ "name": "anthropic",
338
+ "model": "claude-sonnet-4-6",
339
+ "apiKey": "$ENV:ANTHROPIC_API_KEY"
340
+ },
341
+ "permissions": {
342
+ "allow": ["Bash(pnpm *)"],
343
+ "deny": ["Bash(rm -rf *)"]
344
+ }
345
+ }
346
+ ```
347
+
348
+ ## Permission Modes
349
+
350
+ | Mode | Read/Glob/Grep | Write/Edit | Bash |
351
+ | ------------------- | :------------: | :--------: | :-----: |
352
+ | `plan` | auto | deny | deny |
353
+ | `default` | auto | approve | approve |
354
+ | `acceptEdits` | auto | auto | approve |
355
+ | `bypassPermissions` | auto | auto | auto |
356
+
357
+ ## Dependencies
358
+
359
+ | Package | Purpose |
360
+ | -------------------------------------- | ------------------------------------- |
361
+ | `@robota-sdk/agent-core` | Engine, providers, permissions, hooks |
362
+ | `@robota-sdk/agent-sessions` | Session, SessionStore |
363
+ | `@robota-sdk/agent-tools` | Tool infrastructure + built-in tools |
364
+ | `@robota-sdk/agent-provider-anthropic` | Anthropic LLM provider |
365
+ | `chalk` | Terminal colors (permission prompt) |
366
+ | `zod` | Settings schema validation |
367
+
67
368
  ## Documentation
68
369
 
69
370
  See [docs/SPEC.md](./docs/SPEC.md) for the full specification, architecture details, and design decisions.