@robota-sdk/agent-sdk 3.0.0-beta.3 → 3.0.0-beta.4
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 +188 -128
- package/dist/node/index.d.cts +111 -35
- package/dist/node/index.d.ts +111 -35
- package/dist/node/index.js +187 -122
- package/package.json +5 -5
package/dist/node/index.cjs
CHANGED
|
@@ -30,43 +30,184 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
DEFAULT_TOOL_DESCRIPTIONS: () => DEFAULT_TOOL_DESCRIPTIONS,
|
|
34
|
+
FileSessionLogger: () => import_agent_sessions3.FileSessionLogger,
|
|
35
|
+
Session: () => import_agent_sessions2.Session,
|
|
36
|
+
SessionStore: () => import_agent_sessions4.SessionStore,
|
|
37
|
+
SilentSessionLogger: () => import_agent_sessions3.SilentSessionLogger,
|
|
37
38
|
TRUST_TO_MODE: () => import_agent_core.TRUST_TO_MODE,
|
|
38
39
|
agentTool: () => agentTool,
|
|
39
|
-
bashTool: () =>
|
|
40
|
+
bashTool: () => import_agent_tools3.bashTool,
|
|
40
41
|
buildSystemPrompt: () => buildSystemPrompt,
|
|
42
|
+
createDefaultTools: () => createDefaultTools,
|
|
43
|
+
createProvider: () => createProvider,
|
|
44
|
+
createSession: () => createSession,
|
|
41
45
|
detectProject: () => detectProject,
|
|
42
|
-
editTool: () =>
|
|
46
|
+
editTool: () => import_agent_tools6.editTool,
|
|
43
47
|
evaluatePermission: () => import_agent_core2.evaluatePermission,
|
|
44
|
-
globTool: () =>
|
|
45
|
-
grepTool: () =>
|
|
48
|
+
globTool: () => import_agent_tools7.globTool,
|
|
49
|
+
grepTool: () => import_agent_tools8.grepTool,
|
|
46
50
|
loadConfig: () => loadConfig,
|
|
47
51
|
loadContext: () => loadContext,
|
|
48
52
|
projectPaths: () => projectPaths,
|
|
49
53
|
promptForApproval: () => promptForApproval,
|
|
50
54
|
query: () => query,
|
|
51
|
-
readTool: () =>
|
|
55
|
+
readTool: () => import_agent_tools4.readTool,
|
|
52
56
|
runHooks: () => import_agent_core3.runHooks,
|
|
53
57
|
setAgentToolDeps: () => setAgentToolDeps,
|
|
54
58
|
userPaths: () => userPaths,
|
|
55
|
-
writeTool: () =>
|
|
59
|
+
writeTool: () => import_agent_tools5.writeTool
|
|
56
60
|
});
|
|
57
61
|
module.exports = __toCommonJS(index_exports);
|
|
58
62
|
|
|
59
63
|
// src/types.ts
|
|
60
64
|
var import_agent_core = require("@robota-sdk/agent-core");
|
|
61
65
|
|
|
62
|
-
// src/session.ts
|
|
66
|
+
// src/assembly/create-session.ts
|
|
63
67
|
var import_agent_sessions = require("@robota-sdk/agent-sessions");
|
|
64
68
|
|
|
65
|
-
// src/
|
|
66
|
-
var
|
|
69
|
+
// src/context/system-prompt-builder.ts
|
|
70
|
+
var TRUST_LEVEL_DESCRIPTIONS = {
|
|
71
|
+
safe: "safe (read-only / plan mode \u2014 only read-access tools are available)",
|
|
72
|
+
moderate: "moderate (default mode \u2014 write and bash tools require approval)",
|
|
73
|
+
full: "full (acceptEdits mode \u2014 file writes are auto-approved; bash requires approval)"
|
|
74
|
+
};
|
|
75
|
+
function buildProjectSection(info) {
|
|
76
|
+
const lines = ["## Current Project"];
|
|
77
|
+
if (info.name !== void 0) {
|
|
78
|
+
lines.push(`- **Name:** ${info.name}`);
|
|
79
|
+
}
|
|
80
|
+
if (info.type !== "unknown") {
|
|
81
|
+
lines.push(`- **Type:** ${info.type}`);
|
|
82
|
+
}
|
|
83
|
+
if (info.language !== "unknown") {
|
|
84
|
+
lines.push(`- **Language:** ${info.language}`);
|
|
85
|
+
}
|
|
86
|
+
if (info.packageManager !== void 0) {
|
|
87
|
+
lines.push(`- **Package manager:** ${info.packageManager}`);
|
|
88
|
+
}
|
|
89
|
+
return lines.join("\n");
|
|
90
|
+
}
|
|
91
|
+
function buildToolsSection(descriptions) {
|
|
92
|
+
if (descriptions.length === 0) {
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
const lines = ["## Available Tools", ...descriptions.map((d) => `- ${d}`)];
|
|
96
|
+
return lines.join("\n");
|
|
97
|
+
}
|
|
98
|
+
function buildSystemPrompt(params) {
|
|
99
|
+
const { agentsMd, claudeMd, toolDescriptions, trustLevel, projectInfo } = params;
|
|
100
|
+
const sections = [];
|
|
101
|
+
sections.push(
|
|
102
|
+
[
|
|
103
|
+
"## Role",
|
|
104
|
+
"You are an AI coding assistant with access to tools that let you read and modify code.",
|
|
105
|
+
"You help developers understand, write, and improve their codebase.",
|
|
106
|
+
"Always be precise, follow existing code conventions, and prefer minimal changes."
|
|
107
|
+
].join("\n")
|
|
108
|
+
);
|
|
109
|
+
sections.push(buildProjectSection(projectInfo));
|
|
110
|
+
sections.push(
|
|
111
|
+
[
|
|
112
|
+
"## Permission Mode",
|
|
113
|
+
`Your current trust level is **${TRUST_LEVEL_DESCRIPTIONS[trustLevel]}**.`
|
|
114
|
+
].join("\n")
|
|
115
|
+
);
|
|
116
|
+
if (agentsMd.trim().length > 0) {
|
|
117
|
+
sections.push(["## Agent Instructions", agentsMd].join("\n"));
|
|
118
|
+
}
|
|
119
|
+
if (claudeMd.trim().length > 0) {
|
|
120
|
+
sections.push(["## Project Notes", claudeMd].join("\n"));
|
|
121
|
+
}
|
|
122
|
+
sections.push(
|
|
123
|
+
[
|
|
124
|
+
"## Web Search",
|
|
125
|
+
"You have access to web search. When the user asks to search, look up, or find current/latest information,",
|
|
126
|
+
"you MUST use the web_search tool. Do NOT answer from training data when the user explicitly asks to search.",
|
|
127
|
+
"Always prefer web search for: news, latest versions, current events, live documentation."
|
|
128
|
+
].join("\n")
|
|
129
|
+
);
|
|
130
|
+
const toolsSection = buildToolsSection(toolDescriptions);
|
|
131
|
+
if (toolsSection.length > 0) {
|
|
132
|
+
sections.push(toolsSection);
|
|
133
|
+
}
|
|
134
|
+
return sections.join("\n\n");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/assembly/create-tools.ts
|
|
138
|
+
var import_agent_tools = require("@robota-sdk/agent-tools");
|
|
139
|
+
var DEFAULT_TOOL_DESCRIPTIONS = [
|
|
140
|
+
"Bash \u2014 execute shell commands",
|
|
141
|
+
"Read \u2014 read file contents with line numbers",
|
|
142
|
+
"Write \u2014 write content to a file",
|
|
143
|
+
"Edit \u2014 replace a string in a file",
|
|
144
|
+
"Glob \u2014 find files matching a pattern",
|
|
145
|
+
"Grep \u2014 search file contents with regex",
|
|
146
|
+
"WebSearch \u2014 search the internet (Anthropic built-in)"
|
|
147
|
+
];
|
|
148
|
+
function createDefaultTools() {
|
|
149
|
+
return [
|
|
150
|
+
import_agent_tools.bashTool,
|
|
151
|
+
import_agent_tools.readTool,
|
|
152
|
+
import_agent_tools.writeTool,
|
|
153
|
+
import_agent_tools.editTool,
|
|
154
|
+
import_agent_tools.globTool,
|
|
155
|
+
import_agent_tools.grepTool,
|
|
156
|
+
import_agent_tools.webFetchTool,
|
|
157
|
+
import_agent_tools.webSearchTool
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/assembly/create-provider.ts
|
|
162
|
+
var import_agent_provider_anthropic = require("@robota-sdk/agent-provider-anthropic");
|
|
163
|
+
function createProvider(config) {
|
|
164
|
+
const apiKey = config.provider.apiKey ?? process.env["ANTHROPIC_API_KEY"];
|
|
165
|
+
if (!apiKey) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
"ANTHROPIC_API_KEY is not set. Set the environment variable or configure provider.apiKey in ~/.robota/settings.json"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return new import_agent_provider_anthropic.AnthropicProvider({ apiKey });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/assembly/create-session.ts
|
|
174
|
+
function createSession(options) {
|
|
175
|
+
const provider = options.provider ?? createProvider(options.config);
|
|
176
|
+
const defaultTools = createDefaultTools();
|
|
177
|
+
const tools = [...defaultTools, ...options.additionalTools ?? []];
|
|
178
|
+
const buildPrompt = options.systemPromptBuilder ?? buildSystemPrompt;
|
|
179
|
+
const systemMessage = buildPrompt({
|
|
180
|
+
agentsMd: options.context.agentsMd,
|
|
181
|
+
claudeMd: options.context.claudeMd,
|
|
182
|
+
toolDescriptions: options.toolDescriptions ?? DEFAULT_TOOL_DESCRIPTIONS,
|
|
183
|
+
trustLevel: options.config.defaultTrustLevel,
|
|
184
|
+
projectInfo: options.projectInfo ?? { type: "unknown", language: "unknown" }
|
|
185
|
+
});
|
|
186
|
+
return new import_agent_sessions.Session({
|
|
187
|
+
tools,
|
|
188
|
+
provider,
|
|
189
|
+
systemMessage,
|
|
190
|
+
terminal: options.terminal,
|
|
191
|
+
permissions: options.config.permissions,
|
|
192
|
+
hooks: options.config.hooks,
|
|
193
|
+
permissionMode: options.permissionMode,
|
|
194
|
+
defaultTrustLevel: options.config.defaultTrustLevel,
|
|
195
|
+
model: options.config.provider.model,
|
|
196
|
+
maxTurns: options.maxTurns,
|
|
197
|
+
sessionStore: options.sessionStore,
|
|
198
|
+
permissionHandler: options.permissionHandler,
|
|
199
|
+
onTextDelta: options.onTextDelta,
|
|
200
|
+
promptForApproval: options.promptForApproval,
|
|
201
|
+
onCompact: options.onCompact,
|
|
202
|
+
compactInstructions: options.compactInstructions ?? options.context.compactInstructions,
|
|
203
|
+
sessionLogger: options.sessionLogger
|
|
204
|
+
});
|
|
205
|
+
}
|
|
67
206
|
|
|
68
|
-
// src/
|
|
207
|
+
// src/index.ts
|
|
69
208
|
var import_agent_sessions2 = require("@robota-sdk/agent-sessions");
|
|
209
|
+
var import_agent_sessions3 = require("@robota-sdk/agent-sessions");
|
|
210
|
+
var import_agent_sessions4 = require("@robota-sdk/agent-sessions");
|
|
70
211
|
|
|
71
212
|
// src/config/config-loader.ts
|
|
72
213
|
var import_fs = require("fs");
|
|
@@ -331,77 +472,6 @@ async function detectProject(cwd) {
|
|
|
331
472
|
};
|
|
332
473
|
}
|
|
333
474
|
|
|
334
|
-
// src/context/system-prompt-builder.ts
|
|
335
|
-
var TRUST_LEVEL_DESCRIPTIONS = {
|
|
336
|
-
safe: "safe (read-only / plan mode \u2014 only read-access tools are available)",
|
|
337
|
-
moderate: "moderate (default mode \u2014 write and bash tools require approval)",
|
|
338
|
-
full: "full (acceptEdits mode \u2014 file writes are auto-approved; bash requires approval)"
|
|
339
|
-
};
|
|
340
|
-
function buildProjectSection(info) {
|
|
341
|
-
const lines = ["## Current Project"];
|
|
342
|
-
if (info.name !== void 0) {
|
|
343
|
-
lines.push(`- **Name:** ${info.name}`);
|
|
344
|
-
}
|
|
345
|
-
if (info.type !== "unknown") {
|
|
346
|
-
lines.push(`- **Type:** ${info.type}`);
|
|
347
|
-
}
|
|
348
|
-
if (info.language !== "unknown") {
|
|
349
|
-
lines.push(`- **Language:** ${info.language}`);
|
|
350
|
-
}
|
|
351
|
-
if (info.packageManager !== void 0) {
|
|
352
|
-
lines.push(`- **Package manager:** ${info.packageManager}`);
|
|
353
|
-
}
|
|
354
|
-
return lines.join("\n");
|
|
355
|
-
}
|
|
356
|
-
function buildToolsSection(descriptions) {
|
|
357
|
-
if (descriptions.length === 0) {
|
|
358
|
-
return "";
|
|
359
|
-
}
|
|
360
|
-
const lines = ["## Available Tools", ...descriptions.map((d) => `- ${d}`)];
|
|
361
|
-
return lines.join("\n");
|
|
362
|
-
}
|
|
363
|
-
function buildSystemPrompt(params) {
|
|
364
|
-
const { agentsMd, claudeMd, toolDescriptions, trustLevel, projectInfo } = params;
|
|
365
|
-
const sections = [];
|
|
366
|
-
sections.push(
|
|
367
|
-
[
|
|
368
|
-
"## Role",
|
|
369
|
-
"You are an AI coding assistant with access to tools that let you read and modify code.",
|
|
370
|
-
"You help developers understand, write, and improve their codebase.",
|
|
371
|
-
"Always be precise, follow existing code conventions, and prefer minimal changes."
|
|
372
|
-
].join("\n")
|
|
373
|
-
);
|
|
374
|
-
sections.push(buildProjectSection(projectInfo));
|
|
375
|
-
sections.push(
|
|
376
|
-
[
|
|
377
|
-
"## Permission Mode",
|
|
378
|
-
`Your current trust level is **${TRUST_LEVEL_DESCRIPTIONS[trustLevel]}**.`
|
|
379
|
-
].join("\n")
|
|
380
|
-
);
|
|
381
|
-
if (agentsMd.trim().length > 0) {
|
|
382
|
-
sections.push(["## Agent Instructions", agentsMd].join("\n"));
|
|
383
|
-
}
|
|
384
|
-
if (claudeMd.trim().length > 0) {
|
|
385
|
-
sections.push(["## Project Notes", claudeMd].join("\n"));
|
|
386
|
-
}
|
|
387
|
-
sections.push(
|
|
388
|
-
[
|
|
389
|
-
"## Web Search",
|
|
390
|
-
"You have access to web search. When the user asks to search, look up, or find current/latest information,",
|
|
391
|
-
"you MUST use the web_search tool. Do NOT answer from training data when the user explicitly asks to search.",
|
|
392
|
-
"Always prefer web search for: news, latest versions, current events, live documentation."
|
|
393
|
-
].join("\n")
|
|
394
|
-
);
|
|
395
|
-
const toolsSection = buildToolsSection(toolDescriptions);
|
|
396
|
-
if (toolsSection.length > 0) {
|
|
397
|
-
sections.push(toolsSection);
|
|
398
|
-
}
|
|
399
|
-
return sections.join("\n\n");
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// src/query.ts
|
|
403
|
-
var import_agent_sessions3 = require("@robota-sdk/agent-sessions");
|
|
404
|
-
|
|
405
475
|
// src/permissions/permission-prompt.ts
|
|
406
476
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
407
477
|
var PERMISSION_OPTIONS = ["Allow", "Deny"];
|
|
@@ -445,7 +515,7 @@ async function query(prompt, options) {
|
|
|
445
515
|
}, update: () => {
|
|
446
516
|
} })
|
|
447
517
|
};
|
|
448
|
-
const session =
|
|
518
|
+
const session = createSession({
|
|
449
519
|
config,
|
|
450
520
|
context,
|
|
451
521
|
terminal: noopTerminal,
|
|
@@ -457,16 +527,13 @@ async function query(prompt, options) {
|
|
|
457
527
|
onTextDelta: options?.onTextDelta,
|
|
458
528
|
onCompact: options?.onCompact,
|
|
459
529
|
compactInstructions: context.compactInstructions,
|
|
460
|
-
systemPromptBuilder: buildSystemPrompt,
|
|
461
530
|
promptForApproval
|
|
462
531
|
});
|
|
463
532
|
return session.run(prompt);
|
|
464
533
|
}
|
|
465
534
|
|
|
466
|
-
// src/
|
|
535
|
+
// src/index.ts
|
|
467
536
|
var import_agent_core2 = require("@robota-sdk/agent-core");
|
|
468
|
-
|
|
469
|
-
// src/hooks/hook-runner.ts
|
|
470
537
|
var import_agent_core3 = require("@robota-sdk/agent-core");
|
|
471
538
|
|
|
472
539
|
// src/paths.ts
|
|
@@ -489,28 +556,9 @@ function userPaths() {
|
|
|
489
556
|
};
|
|
490
557
|
}
|
|
491
558
|
|
|
492
|
-
// src/tools/bash-tool.ts
|
|
493
|
-
var import_agent_tools = require("@robota-sdk/agent-tools");
|
|
494
|
-
|
|
495
|
-
// src/tools/read-tool.ts
|
|
496
|
-
var import_agent_tools2 = require("@robota-sdk/agent-tools");
|
|
497
|
-
|
|
498
|
-
// src/tools/write-tool.ts
|
|
499
|
-
var import_agent_tools3 = require("@robota-sdk/agent-tools");
|
|
500
|
-
|
|
501
|
-
// src/tools/edit-tool.ts
|
|
502
|
-
var import_agent_tools4 = require("@robota-sdk/agent-tools");
|
|
503
|
-
|
|
504
|
-
// src/tools/glob-tool.ts
|
|
505
|
-
var import_agent_tools5 = require("@robota-sdk/agent-tools");
|
|
506
|
-
|
|
507
|
-
// src/tools/grep-tool.ts
|
|
508
|
-
var import_agent_tools6 = require("@robota-sdk/agent-tools");
|
|
509
|
-
|
|
510
559
|
// src/tools/agent-tool.ts
|
|
511
560
|
var import_zod2 = require("zod");
|
|
512
|
-
var
|
|
513
|
-
var import_agent_sessions4 = require("@robota-sdk/agent-sessions");
|
|
561
|
+
var import_agent_tools2 = require("@robota-sdk/agent-tools");
|
|
514
562
|
function asZodSchema(schema) {
|
|
515
563
|
return schema;
|
|
516
564
|
}
|
|
@@ -531,26 +579,26 @@ async function runAgent(args) {
|
|
|
531
579
|
};
|
|
532
580
|
return JSON.stringify(result);
|
|
533
581
|
}
|
|
534
|
-
const
|
|
582
|
+
const noopTerminal = {
|
|
583
|
+
write: () => {
|
|
584
|
+
},
|
|
585
|
+
writeLine: () => {
|
|
586
|
+
},
|
|
587
|
+
writeMarkdown: () => {
|
|
588
|
+
},
|
|
589
|
+
writeError: () => {
|
|
590
|
+
},
|
|
591
|
+
prompt: () => Promise.resolve(""),
|
|
592
|
+
select: () => Promise.resolve(0),
|
|
593
|
+
spinner: () => ({ stop: () => {
|
|
594
|
+
}, update: () => {
|
|
595
|
+
} })
|
|
596
|
+
};
|
|
597
|
+
const subSession = createSession({
|
|
535
598
|
config: agentToolDeps.config,
|
|
536
599
|
context: agentToolDeps.context,
|
|
537
600
|
projectInfo: agentToolDeps.projectInfo,
|
|
538
|
-
|
|
539
|
-
terminal: {
|
|
540
|
-
write: () => {
|
|
541
|
-
},
|
|
542
|
-
writeLine: () => {
|
|
543
|
-
},
|
|
544
|
-
writeMarkdown: () => {
|
|
545
|
-
},
|
|
546
|
-
writeError: () => {
|
|
547
|
-
},
|
|
548
|
-
prompt: () => Promise.resolve(""),
|
|
549
|
-
select: () => Promise.resolve(0),
|
|
550
|
-
spinner: () => ({ stop: () => {
|
|
551
|
-
}, update: () => {
|
|
552
|
-
} })
|
|
553
|
-
},
|
|
601
|
+
terminal: noopTerminal,
|
|
554
602
|
// Sub-agents bypass permissions — they inherit parent's trust
|
|
555
603
|
permissionMode: "bypassPermissions"
|
|
556
604
|
});
|
|
@@ -571,7 +619,7 @@ async function runAgent(args) {
|
|
|
571
619
|
return JSON.stringify(result);
|
|
572
620
|
}
|
|
573
621
|
}
|
|
574
|
-
var agentTool = (0,
|
|
622
|
+
var agentTool = (0, import_agent_tools2.createZodFunctionTool)(
|
|
575
623
|
"Agent",
|
|
576
624
|
"Spawn a sub-agent with isolated context to handle a task. The sub-agent has its own conversation history and can use all tools.",
|
|
577
625
|
asZodSchema(AgentSchema),
|
|
@@ -579,8 +627,17 @@ var agentTool = (0, import_agent_tools7.createZodFunctionTool)(
|
|
|
579
627
|
return runAgent(params);
|
|
580
628
|
}
|
|
581
629
|
);
|
|
630
|
+
|
|
631
|
+
// src/index.ts
|
|
632
|
+
var import_agent_tools3 = require("@robota-sdk/agent-tools");
|
|
633
|
+
var import_agent_tools4 = require("@robota-sdk/agent-tools");
|
|
634
|
+
var import_agent_tools5 = require("@robota-sdk/agent-tools");
|
|
635
|
+
var import_agent_tools6 = require("@robota-sdk/agent-tools");
|
|
636
|
+
var import_agent_tools7 = require("@robota-sdk/agent-tools");
|
|
637
|
+
var import_agent_tools8 = require("@robota-sdk/agent-tools");
|
|
582
638
|
// Annotate the CommonJS export names for ESM import in node:
|
|
583
639
|
0 && (module.exports = {
|
|
640
|
+
DEFAULT_TOOL_DESCRIPTIONS,
|
|
584
641
|
FileSessionLogger,
|
|
585
642
|
Session,
|
|
586
643
|
SessionStore,
|
|
@@ -589,6 +646,9 @@ var agentTool = (0, import_agent_tools7.createZodFunctionTool)(
|
|
|
589
646
|
agentTool,
|
|
590
647
|
bashTool,
|
|
591
648
|
buildSystemPrompt,
|
|
649
|
+
createDefaultTools,
|
|
650
|
+
createProvider,
|
|
651
|
+
createSession,
|
|
592
652
|
detectProject,
|
|
593
653
|
editTool,
|
|
594
654
|
evaluatePermission,
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
import { TPermissionMode, IAIProvider, TToolArgs,
|
|
1
|
+
import { 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
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* query() — single entry point for running an AI agent conversation.
|
|
11
|
-
* Automatically loads config, context, and project info.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
interface IQueryOptions {
|
|
15
|
-
cwd?: string;
|
|
16
|
-
permissionMode?: TPermissionMode;
|
|
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;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* query() — single entry point for running an AI agent conversation.
|
|
26
|
-
* Equivalent to Claude Agent SDK's query() function.
|
|
27
|
-
* Automatically loads config, context, and project info.
|
|
28
|
-
*/
|
|
29
|
-
declare function query(prompt: string, options?: IQueryOptions): Promise<string>;
|
|
30
|
-
|
|
31
9
|
/**
|
|
32
10
|
* Zod schemas and TypeScript types for Robota CLI settings
|
|
33
11
|
*/
|
|
@@ -210,13 +188,6 @@ interface IResolvedConfig {
|
|
|
210
188
|
hooks?: z.infer<typeof HooksSchema>;
|
|
211
189
|
}
|
|
212
190
|
|
|
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
191
|
interface ILoadedContext {
|
|
221
192
|
/** Concatenated content of all AGENTS.md files found (root-first) */
|
|
222
193
|
agentsMd: string;
|
|
@@ -270,6 +241,111 @@ interface ISystemPromptParams {
|
|
|
270
241
|
*/
|
|
271
242
|
declare function buildSystemPrompt(params: ISystemPromptParams): string;
|
|
272
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Session factory — assembles a fully-configured Session from config, context,
|
|
246
|
+
* tools, and provider.
|
|
247
|
+
*
|
|
248
|
+
* This is the main entry point for creating sessions. It wires together
|
|
249
|
+
* the provider, tools, system prompt, and configuration that Session now
|
|
250
|
+
* expects as pre-constructed dependencies.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
/** Options for the createSession factory */
|
|
254
|
+
interface ICreateSessionOptions {
|
|
255
|
+
/** Resolved CLI configuration (model, API key, permissions) */
|
|
256
|
+
config: IResolvedConfig;
|
|
257
|
+
/** Loaded AGENTS.md / CLAUDE.md context */
|
|
258
|
+
context: ILoadedContext;
|
|
259
|
+
/** Terminal I/O for permission prompts */
|
|
260
|
+
terminal: ITerminalOutput;
|
|
261
|
+
/** Project metadata for system prompt */
|
|
262
|
+
projectInfo?: IProjectInfo;
|
|
263
|
+
/** Initial permission mode (defaults to config.defaultTrustLevel → mode mapping) */
|
|
264
|
+
permissionMode?: TPermissionMode;
|
|
265
|
+
/** Maximum number of agentic turns per run() call. Undefined = unlimited. */
|
|
266
|
+
maxTurns?: number;
|
|
267
|
+
/** Optional session store for persistence */
|
|
268
|
+
sessionStore?: SessionStore;
|
|
269
|
+
/** Inject a pre-constructed AI provider (used by tests to avoid real API calls) */
|
|
270
|
+
provider?: IAIProvider;
|
|
271
|
+
/** Custom permission handler (overrides terminal-based prompts, used by Ink UI) */
|
|
272
|
+
permissionHandler?: TPermissionHandler;
|
|
273
|
+
/** Callback for text deltas — enables streaming text to the UI in real-time */
|
|
274
|
+
onTextDelta?: (delta: string) => void;
|
|
275
|
+
/** Custom prompt-for-approval function (injected from CLI) */
|
|
276
|
+
promptForApproval?: (terminal: ITerminalOutput, toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
277
|
+
/** Additional tools to register beyond the defaults (e.g. agent-tool) */
|
|
278
|
+
additionalTools?: IToolWithEventService[];
|
|
279
|
+
/** Callback when context is compacted */
|
|
280
|
+
onCompact?: (summary: string) => void;
|
|
281
|
+
/** Instructions to include in the compaction prompt (e.g. from CLAUDE.md) */
|
|
282
|
+
compactInstructions?: string;
|
|
283
|
+
/** Custom system prompt builder function */
|
|
284
|
+
systemPromptBuilder?: (params: ISystemPromptParams) => string;
|
|
285
|
+
/** Custom tool descriptions for the system prompt */
|
|
286
|
+
toolDescriptions?: string[];
|
|
287
|
+
/** Session logger — injected for pluggable session event logging. */
|
|
288
|
+
sessionLogger?: ISessionLogger;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Create a fully-configured Session instance.
|
|
292
|
+
*
|
|
293
|
+
* Assembles provider, tools, and system prompt, then passes them
|
|
294
|
+
* to Session as pre-constructed dependencies.
|
|
295
|
+
*/
|
|
296
|
+
declare function createSession(options: ICreateSessionOptions): Session;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Default tool set factory — creates the standard set of CLI tools.
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
/** Human-readable descriptions of the built-in tools (for system prompt) */
|
|
303
|
+
declare const DEFAULT_TOOL_DESCRIPTIONS: string[];
|
|
304
|
+
/**
|
|
305
|
+
* Create the default set of CLI tools.
|
|
306
|
+
* Returns the 8 standard tools as IToolWithEventService[].
|
|
307
|
+
*/
|
|
308
|
+
declare function createDefaultTools(): IToolWithEventService[];
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Provider factory — creates an AI provider from resolved config.
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Create an AI provider from the resolved config.
|
|
316
|
+
* Currently supports Anthropic only. Throws if no API key is available.
|
|
317
|
+
*/
|
|
318
|
+
declare function createProvider(config: IResolvedConfig): IAIProvider;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* query() — single entry point for running an AI agent conversation.
|
|
322
|
+
* Automatically loads config, context, and project info.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
interface IQueryOptions {
|
|
326
|
+
cwd?: string;
|
|
327
|
+
permissionMode?: TPermissionMode;
|
|
328
|
+
maxTurns?: number;
|
|
329
|
+
provider?: IAIProvider;
|
|
330
|
+
permissionHandler?: (toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
331
|
+
onTextDelta?: (delta: string) => void;
|
|
332
|
+
/** Callback when context is compacted */
|
|
333
|
+
onCompact?: (summary: string) => void;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* query() — single entry point for running an AI agent conversation.
|
|
337
|
+
* Equivalent to Claude Agent SDK's query() function.
|
|
338
|
+
* Automatically loads config, context, and project info.
|
|
339
|
+
*/
|
|
340
|
+
declare function query(prompt: string, options?: IQueryOptions): Promise<string>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Load and merge all settings files, validate with Zod, return resolved config.
|
|
344
|
+
*
|
|
345
|
+
* @param cwd - The working directory (project root) to search for .robota/
|
|
346
|
+
*/
|
|
347
|
+
declare function loadConfig(cwd: string): Promise<IResolvedConfig>;
|
|
348
|
+
|
|
273
349
|
/**
|
|
274
350
|
* Permission prompt — this is now CLI-specific.
|
|
275
351
|
* Re-exported here for backward compatibility.
|
|
@@ -302,12 +378,12 @@ declare function userPaths(): {
|
|
|
302
378
|
|
|
303
379
|
/** Dependencies injected at registration time */
|
|
304
380
|
interface IAgentToolDeps {
|
|
305
|
-
config: IResolvedConfig
|
|
306
|
-
context: ILoadedContext
|
|
307
|
-
projectInfo?: IProjectInfo
|
|
381
|
+
config: IResolvedConfig;
|
|
382
|
+
context: ILoadedContext;
|
|
383
|
+
projectInfo?: IProjectInfo;
|
|
308
384
|
}
|
|
309
385
|
/** Set dependencies for the agent tool. Must be called before tool is used. */
|
|
310
386
|
declare function setAgentToolDeps(deps: IAgentToolDeps): void;
|
|
311
387
|
declare const agentTool: _robota_sdk_agent_tools.FunctionTool;
|
|
312
388
|
|
|
313
|
-
export { type ILoadedContext, type IProjectInfo, type IQueryOptions, type IResolvedConfig, type ISystemPromptParams, agentTool, buildSystemPrompt, detectProject, loadConfig, loadContext, projectPaths, promptForApproval, query, setAgentToolDeps, userPaths };
|
|
389
|
+
export { DEFAULT_TOOL_DESCRIPTIONS, type ICreateSessionOptions, type ILoadedContext, type IProjectInfo, type IQueryOptions, type IResolvedConfig, type ISystemPromptParams, agentTool, buildSystemPrompt, createDefaultTools, createProvider, createSession, detectProject, loadConfig, loadContext, projectPaths, promptForApproval, query, setAgentToolDeps, userPaths };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
import { TPermissionMode, IAIProvider, TToolArgs,
|
|
1
|
+
import { 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
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* query() — single entry point for running an AI agent conversation.
|
|
11
|
-
* Automatically loads config, context, and project info.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
interface IQueryOptions {
|
|
15
|
-
cwd?: string;
|
|
16
|
-
permissionMode?: TPermissionMode;
|
|
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;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* query() — single entry point for running an AI agent conversation.
|
|
26
|
-
* Equivalent to Claude Agent SDK's query() function.
|
|
27
|
-
* Automatically loads config, context, and project info.
|
|
28
|
-
*/
|
|
29
|
-
declare function query(prompt: string, options?: IQueryOptions): Promise<string>;
|
|
30
|
-
|
|
31
9
|
/**
|
|
32
10
|
* Zod schemas and TypeScript types for Robota CLI settings
|
|
33
11
|
*/
|
|
@@ -210,13 +188,6 @@ interface IResolvedConfig {
|
|
|
210
188
|
hooks?: z.infer<typeof HooksSchema>;
|
|
211
189
|
}
|
|
212
190
|
|
|
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
191
|
interface ILoadedContext {
|
|
221
192
|
/** Concatenated content of all AGENTS.md files found (root-first) */
|
|
222
193
|
agentsMd: string;
|
|
@@ -270,6 +241,111 @@ interface ISystemPromptParams {
|
|
|
270
241
|
*/
|
|
271
242
|
declare function buildSystemPrompt(params: ISystemPromptParams): string;
|
|
272
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Session factory — assembles a fully-configured Session from config, context,
|
|
246
|
+
* tools, and provider.
|
|
247
|
+
*
|
|
248
|
+
* This is the main entry point for creating sessions. It wires together
|
|
249
|
+
* the provider, tools, system prompt, and configuration that Session now
|
|
250
|
+
* expects as pre-constructed dependencies.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
/** Options for the createSession factory */
|
|
254
|
+
interface ICreateSessionOptions {
|
|
255
|
+
/** Resolved CLI configuration (model, API key, permissions) */
|
|
256
|
+
config: IResolvedConfig;
|
|
257
|
+
/** Loaded AGENTS.md / CLAUDE.md context */
|
|
258
|
+
context: ILoadedContext;
|
|
259
|
+
/** Terminal I/O for permission prompts */
|
|
260
|
+
terminal: ITerminalOutput;
|
|
261
|
+
/** Project metadata for system prompt */
|
|
262
|
+
projectInfo?: IProjectInfo;
|
|
263
|
+
/** Initial permission mode (defaults to config.defaultTrustLevel → mode mapping) */
|
|
264
|
+
permissionMode?: TPermissionMode;
|
|
265
|
+
/** Maximum number of agentic turns per run() call. Undefined = unlimited. */
|
|
266
|
+
maxTurns?: number;
|
|
267
|
+
/** Optional session store for persistence */
|
|
268
|
+
sessionStore?: SessionStore;
|
|
269
|
+
/** Inject a pre-constructed AI provider (used by tests to avoid real API calls) */
|
|
270
|
+
provider?: IAIProvider;
|
|
271
|
+
/** Custom permission handler (overrides terminal-based prompts, used by Ink UI) */
|
|
272
|
+
permissionHandler?: TPermissionHandler;
|
|
273
|
+
/** Callback for text deltas — enables streaming text to the UI in real-time */
|
|
274
|
+
onTextDelta?: (delta: string) => void;
|
|
275
|
+
/** Custom prompt-for-approval function (injected from CLI) */
|
|
276
|
+
promptForApproval?: (terminal: ITerminalOutput, toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
277
|
+
/** Additional tools to register beyond the defaults (e.g. agent-tool) */
|
|
278
|
+
additionalTools?: IToolWithEventService[];
|
|
279
|
+
/** Callback when context is compacted */
|
|
280
|
+
onCompact?: (summary: string) => void;
|
|
281
|
+
/** Instructions to include in the compaction prompt (e.g. from CLAUDE.md) */
|
|
282
|
+
compactInstructions?: string;
|
|
283
|
+
/** Custom system prompt builder function */
|
|
284
|
+
systemPromptBuilder?: (params: ISystemPromptParams) => string;
|
|
285
|
+
/** Custom tool descriptions for the system prompt */
|
|
286
|
+
toolDescriptions?: string[];
|
|
287
|
+
/** Session logger — injected for pluggable session event logging. */
|
|
288
|
+
sessionLogger?: ISessionLogger;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Create a fully-configured Session instance.
|
|
292
|
+
*
|
|
293
|
+
* Assembles provider, tools, and system prompt, then passes them
|
|
294
|
+
* to Session as pre-constructed dependencies.
|
|
295
|
+
*/
|
|
296
|
+
declare function createSession(options: ICreateSessionOptions): Session;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Default tool set factory — creates the standard set of CLI tools.
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
/** Human-readable descriptions of the built-in tools (for system prompt) */
|
|
303
|
+
declare const DEFAULT_TOOL_DESCRIPTIONS: string[];
|
|
304
|
+
/**
|
|
305
|
+
* Create the default set of CLI tools.
|
|
306
|
+
* Returns the 8 standard tools as IToolWithEventService[].
|
|
307
|
+
*/
|
|
308
|
+
declare function createDefaultTools(): IToolWithEventService[];
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Provider factory — creates an AI provider from resolved config.
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Create an AI provider from the resolved config.
|
|
316
|
+
* Currently supports Anthropic only. Throws if no API key is available.
|
|
317
|
+
*/
|
|
318
|
+
declare function createProvider(config: IResolvedConfig): IAIProvider;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* query() — single entry point for running an AI agent conversation.
|
|
322
|
+
* Automatically loads config, context, and project info.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
interface IQueryOptions {
|
|
326
|
+
cwd?: string;
|
|
327
|
+
permissionMode?: TPermissionMode;
|
|
328
|
+
maxTurns?: number;
|
|
329
|
+
provider?: IAIProvider;
|
|
330
|
+
permissionHandler?: (toolName: string, toolArgs: TToolArgs) => Promise<boolean>;
|
|
331
|
+
onTextDelta?: (delta: string) => void;
|
|
332
|
+
/** Callback when context is compacted */
|
|
333
|
+
onCompact?: (summary: string) => void;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* query() — single entry point for running an AI agent conversation.
|
|
337
|
+
* Equivalent to Claude Agent SDK's query() function.
|
|
338
|
+
* Automatically loads config, context, and project info.
|
|
339
|
+
*/
|
|
340
|
+
declare function query(prompt: string, options?: IQueryOptions): Promise<string>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Load and merge all settings files, validate with Zod, return resolved config.
|
|
344
|
+
*
|
|
345
|
+
* @param cwd - The working directory (project root) to search for .robota/
|
|
346
|
+
*/
|
|
347
|
+
declare function loadConfig(cwd: string): Promise<IResolvedConfig>;
|
|
348
|
+
|
|
273
349
|
/**
|
|
274
350
|
* Permission prompt — this is now CLI-specific.
|
|
275
351
|
* Re-exported here for backward compatibility.
|
|
@@ -302,12 +378,12 @@ declare function userPaths(): {
|
|
|
302
378
|
|
|
303
379
|
/** Dependencies injected at registration time */
|
|
304
380
|
interface IAgentToolDeps {
|
|
305
|
-
config: IResolvedConfig
|
|
306
|
-
context: ILoadedContext
|
|
307
|
-
projectInfo?: IProjectInfo
|
|
381
|
+
config: IResolvedConfig;
|
|
382
|
+
context: ILoadedContext;
|
|
383
|
+
projectInfo?: IProjectInfo;
|
|
308
384
|
}
|
|
309
385
|
/** Set dependencies for the agent tool. Must be called before tool is used. */
|
|
310
386
|
declare function setAgentToolDeps(deps: IAgentToolDeps): void;
|
|
311
387
|
declare const agentTool: _robota_sdk_agent_tools.FunctionTool;
|
|
312
388
|
|
|
313
|
-
export { type ILoadedContext, type IProjectInfo, type IQueryOptions, type IResolvedConfig, type ISystemPromptParams, agentTool, buildSystemPrompt, detectProject, loadConfig, loadContext, projectPaths, promptForApproval, query, setAgentToolDeps, userPaths };
|
|
389
|
+
export { DEFAULT_TOOL_DESCRIPTIONS, type ICreateSessionOptions, type ILoadedContext, type IProjectInfo, type IQueryOptions, type IResolvedConfig, type ISystemPromptParams, agentTool, buildSystemPrompt, createDefaultTools, createProvider, createSession, detectProject, loadConfig, loadContext, projectPaths, promptForApproval, query, setAgentToolDeps, userPaths };
|
package/dist/node/index.js
CHANGED
|
@@ -1,13 +1,159 @@
|
|
|
1
1
|
// src/types.ts
|
|
2
2
|
import { TRUST_TO_MODE } from "@robota-sdk/agent-core";
|
|
3
3
|
|
|
4
|
-
// src/session.ts
|
|
4
|
+
// src/assembly/create-session.ts
|
|
5
5
|
import { Session } from "@robota-sdk/agent-sessions";
|
|
6
6
|
|
|
7
|
+
// src/context/system-prompt-builder.ts
|
|
8
|
+
var TRUST_LEVEL_DESCRIPTIONS = {
|
|
9
|
+
safe: "safe (read-only / plan mode \u2014 only read-access tools are available)",
|
|
10
|
+
moderate: "moderate (default mode \u2014 write and bash tools require approval)",
|
|
11
|
+
full: "full (acceptEdits mode \u2014 file writes are auto-approved; bash requires approval)"
|
|
12
|
+
};
|
|
13
|
+
function buildProjectSection(info) {
|
|
14
|
+
const lines = ["## Current Project"];
|
|
15
|
+
if (info.name !== void 0) {
|
|
16
|
+
lines.push(`- **Name:** ${info.name}`);
|
|
17
|
+
}
|
|
18
|
+
if (info.type !== "unknown") {
|
|
19
|
+
lines.push(`- **Type:** ${info.type}`);
|
|
20
|
+
}
|
|
21
|
+
if (info.language !== "unknown") {
|
|
22
|
+
lines.push(`- **Language:** ${info.language}`);
|
|
23
|
+
}
|
|
24
|
+
if (info.packageManager !== void 0) {
|
|
25
|
+
lines.push(`- **Package manager:** ${info.packageManager}`);
|
|
26
|
+
}
|
|
27
|
+
return lines.join("\n");
|
|
28
|
+
}
|
|
29
|
+
function buildToolsSection(descriptions) {
|
|
30
|
+
if (descriptions.length === 0) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
const lines = ["## Available Tools", ...descriptions.map((d) => `- ${d}`)];
|
|
34
|
+
return lines.join("\n");
|
|
35
|
+
}
|
|
36
|
+
function buildSystemPrompt(params) {
|
|
37
|
+
const { agentsMd, claudeMd, toolDescriptions, trustLevel, projectInfo } = params;
|
|
38
|
+
const sections = [];
|
|
39
|
+
sections.push(
|
|
40
|
+
[
|
|
41
|
+
"## Role",
|
|
42
|
+
"You are an AI coding assistant with access to tools that let you read and modify code.",
|
|
43
|
+
"You help developers understand, write, and improve their codebase.",
|
|
44
|
+
"Always be precise, follow existing code conventions, and prefer minimal changes."
|
|
45
|
+
].join("\n")
|
|
46
|
+
);
|
|
47
|
+
sections.push(buildProjectSection(projectInfo));
|
|
48
|
+
sections.push(
|
|
49
|
+
[
|
|
50
|
+
"## Permission Mode",
|
|
51
|
+
`Your current trust level is **${TRUST_LEVEL_DESCRIPTIONS[trustLevel]}**.`
|
|
52
|
+
].join("\n")
|
|
53
|
+
);
|
|
54
|
+
if (agentsMd.trim().length > 0) {
|
|
55
|
+
sections.push(["## Agent Instructions", agentsMd].join("\n"));
|
|
56
|
+
}
|
|
57
|
+
if (claudeMd.trim().length > 0) {
|
|
58
|
+
sections.push(["## Project Notes", claudeMd].join("\n"));
|
|
59
|
+
}
|
|
60
|
+
sections.push(
|
|
61
|
+
[
|
|
62
|
+
"## Web Search",
|
|
63
|
+
"You have access to web search. When the user asks to search, look up, or find current/latest information,",
|
|
64
|
+
"you MUST use the web_search tool. Do NOT answer from training data when the user explicitly asks to search.",
|
|
65
|
+
"Always prefer web search for: news, latest versions, current events, live documentation."
|
|
66
|
+
].join("\n")
|
|
67
|
+
);
|
|
68
|
+
const toolsSection = buildToolsSection(toolDescriptions);
|
|
69
|
+
if (toolsSection.length > 0) {
|
|
70
|
+
sections.push(toolsSection);
|
|
71
|
+
}
|
|
72
|
+
return sections.join("\n\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/assembly/create-tools.ts
|
|
76
|
+
import {
|
|
77
|
+
bashTool,
|
|
78
|
+
readTool,
|
|
79
|
+
writeTool,
|
|
80
|
+
editTool,
|
|
81
|
+
globTool,
|
|
82
|
+
grepTool,
|
|
83
|
+
webFetchTool,
|
|
84
|
+
webSearchTool
|
|
85
|
+
} from "@robota-sdk/agent-tools";
|
|
86
|
+
var DEFAULT_TOOL_DESCRIPTIONS = [
|
|
87
|
+
"Bash \u2014 execute shell commands",
|
|
88
|
+
"Read \u2014 read file contents with line numbers",
|
|
89
|
+
"Write \u2014 write content to a file",
|
|
90
|
+
"Edit \u2014 replace a string in a file",
|
|
91
|
+
"Glob \u2014 find files matching a pattern",
|
|
92
|
+
"Grep \u2014 search file contents with regex",
|
|
93
|
+
"WebSearch \u2014 search the internet (Anthropic built-in)"
|
|
94
|
+
];
|
|
95
|
+
function createDefaultTools() {
|
|
96
|
+
return [
|
|
97
|
+
bashTool,
|
|
98
|
+
readTool,
|
|
99
|
+
writeTool,
|
|
100
|
+
editTool,
|
|
101
|
+
globTool,
|
|
102
|
+
grepTool,
|
|
103
|
+
webFetchTool,
|
|
104
|
+
webSearchTool
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/assembly/create-provider.ts
|
|
109
|
+
import { AnthropicProvider } from "@robota-sdk/agent-provider-anthropic";
|
|
110
|
+
function createProvider(config) {
|
|
111
|
+
const apiKey = config.provider.apiKey ?? process.env["ANTHROPIC_API_KEY"];
|
|
112
|
+
if (!apiKey) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
"ANTHROPIC_API_KEY is not set. Set the environment variable or configure provider.apiKey in ~/.robota/settings.json"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return new AnthropicProvider({ apiKey });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/assembly/create-session.ts
|
|
121
|
+
function createSession(options) {
|
|
122
|
+
const provider = options.provider ?? createProvider(options.config);
|
|
123
|
+
const defaultTools = createDefaultTools();
|
|
124
|
+
const tools = [...defaultTools, ...options.additionalTools ?? []];
|
|
125
|
+
const buildPrompt = options.systemPromptBuilder ?? buildSystemPrompt;
|
|
126
|
+
const systemMessage = buildPrompt({
|
|
127
|
+
agentsMd: options.context.agentsMd,
|
|
128
|
+
claudeMd: options.context.claudeMd,
|
|
129
|
+
toolDescriptions: options.toolDescriptions ?? DEFAULT_TOOL_DESCRIPTIONS,
|
|
130
|
+
trustLevel: options.config.defaultTrustLevel,
|
|
131
|
+
projectInfo: options.projectInfo ?? { type: "unknown", language: "unknown" }
|
|
132
|
+
});
|
|
133
|
+
return new Session({
|
|
134
|
+
tools,
|
|
135
|
+
provider,
|
|
136
|
+
systemMessage,
|
|
137
|
+
terminal: options.terminal,
|
|
138
|
+
permissions: options.config.permissions,
|
|
139
|
+
hooks: options.config.hooks,
|
|
140
|
+
permissionMode: options.permissionMode,
|
|
141
|
+
defaultTrustLevel: options.config.defaultTrustLevel,
|
|
142
|
+
model: options.config.provider.model,
|
|
143
|
+
maxTurns: options.maxTurns,
|
|
144
|
+
sessionStore: options.sessionStore,
|
|
145
|
+
permissionHandler: options.permissionHandler,
|
|
146
|
+
onTextDelta: options.onTextDelta,
|
|
147
|
+
promptForApproval: options.promptForApproval,
|
|
148
|
+
onCompact: options.onCompact,
|
|
149
|
+
compactInstructions: options.compactInstructions ?? options.context.compactInstructions,
|
|
150
|
+
sessionLogger: options.sessionLogger
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
7
154
|
// src/index.ts
|
|
155
|
+
import { Session as Session2 } from "@robota-sdk/agent-sessions";
|
|
8
156
|
import { FileSessionLogger, SilentSessionLogger } from "@robota-sdk/agent-sessions";
|
|
9
|
-
|
|
10
|
-
// src/session-store.ts
|
|
11
157
|
import { SessionStore } from "@robota-sdk/agent-sessions";
|
|
12
158
|
|
|
13
159
|
// src/config/config-loader.ts
|
|
@@ -273,77 +419,6 @@ async function detectProject(cwd) {
|
|
|
273
419
|
};
|
|
274
420
|
}
|
|
275
421
|
|
|
276
|
-
// src/context/system-prompt-builder.ts
|
|
277
|
-
var TRUST_LEVEL_DESCRIPTIONS = {
|
|
278
|
-
safe: "safe (read-only / plan mode \u2014 only read-access tools are available)",
|
|
279
|
-
moderate: "moderate (default mode \u2014 write and bash tools require approval)",
|
|
280
|
-
full: "full (acceptEdits mode \u2014 file writes are auto-approved; bash requires approval)"
|
|
281
|
-
};
|
|
282
|
-
function buildProjectSection(info) {
|
|
283
|
-
const lines = ["## Current Project"];
|
|
284
|
-
if (info.name !== void 0) {
|
|
285
|
-
lines.push(`- **Name:** ${info.name}`);
|
|
286
|
-
}
|
|
287
|
-
if (info.type !== "unknown") {
|
|
288
|
-
lines.push(`- **Type:** ${info.type}`);
|
|
289
|
-
}
|
|
290
|
-
if (info.language !== "unknown") {
|
|
291
|
-
lines.push(`- **Language:** ${info.language}`);
|
|
292
|
-
}
|
|
293
|
-
if (info.packageManager !== void 0) {
|
|
294
|
-
lines.push(`- **Package manager:** ${info.packageManager}`);
|
|
295
|
-
}
|
|
296
|
-
return lines.join("\n");
|
|
297
|
-
}
|
|
298
|
-
function buildToolsSection(descriptions) {
|
|
299
|
-
if (descriptions.length === 0) {
|
|
300
|
-
return "";
|
|
301
|
-
}
|
|
302
|
-
const lines = ["## Available Tools", ...descriptions.map((d) => `- ${d}`)];
|
|
303
|
-
return lines.join("\n");
|
|
304
|
-
}
|
|
305
|
-
function buildSystemPrompt(params) {
|
|
306
|
-
const { agentsMd, claudeMd, toolDescriptions, trustLevel, projectInfo } = params;
|
|
307
|
-
const sections = [];
|
|
308
|
-
sections.push(
|
|
309
|
-
[
|
|
310
|
-
"## Role",
|
|
311
|
-
"You are an AI coding assistant with access to tools that let you read and modify code.",
|
|
312
|
-
"You help developers understand, write, and improve their codebase.",
|
|
313
|
-
"Always be precise, follow existing code conventions, and prefer minimal changes."
|
|
314
|
-
].join("\n")
|
|
315
|
-
);
|
|
316
|
-
sections.push(buildProjectSection(projectInfo));
|
|
317
|
-
sections.push(
|
|
318
|
-
[
|
|
319
|
-
"## Permission Mode",
|
|
320
|
-
`Your current trust level is **${TRUST_LEVEL_DESCRIPTIONS[trustLevel]}**.`
|
|
321
|
-
].join("\n")
|
|
322
|
-
);
|
|
323
|
-
if (agentsMd.trim().length > 0) {
|
|
324
|
-
sections.push(["## Agent Instructions", agentsMd].join("\n"));
|
|
325
|
-
}
|
|
326
|
-
if (claudeMd.trim().length > 0) {
|
|
327
|
-
sections.push(["## Project Notes", claudeMd].join("\n"));
|
|
328
|
-
}
|
|
329
|
-
sections.push(
|
|
330
|
-
[
|
|
331
|
-
"## Web Search",
|
|
332
|
-
"You have access to web search. When the user asks to search, look up, or find current/latest information,",
|
|
333
|
-
"you MUST use the web_search tool. Do NOT answer from training data when the user explicitly asks to search.",
|
|
334
|
-
"Always prefer web search for: news, latest versions, current events, live documentation."
|
|
335
|
-
].join("\n")
|
|
336
|
-
);
|
|
337
|
-
const toolsSection = buildToolsSection(toolDescriptions);
|
|
338
|
-
if (toolsSection.length > 0) {
|
|
339
|
-
sections.push(toolsSection);
|
|
340
|
-
}
|
|
341
|
-
return sections.join("\n\n");
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// src/query.ts
|
|
345
|
-
import { Session as Session2 } from "@robota-sdk/agent-sessions";
|
|
346
|
-
|
|
347
422
|
// src/permissions/permission-prompt.ts
|
|
348
423
|
import chalk from "chalk";
|
|
349
424
|
var PERMISSION_OPTIONS = ["Allow", "Deny"];
|
|
@@ -387,7 +462,7 @@ async function query(prompt, options) {
|
|
|
387
462
|
}, update: () => {
|
|
388
463
|
} })
|
|
389
464
|
};
|
|
390
|
-
const session =
|
|
465
|
+
const session = createSession({
|
|
391
466
|
config,
|
|
392
467
|
context,
|
|
393
468
|
terminal: noopTerminal,
|
|
@@ -399,16 +474,13 @@ async function query(prompt, options) {
|
|
|
399
474
|
onTextDelta: options?.onTextDelta,
|
|
400
475
|
onCompact: options?.onCompact,
|
|
401
476
|
compactInstructions: context.compactInstructions,
|
|
402
|
-
systemPromptBuilder: buildSystemPrompt,
|
|
403
477
|
promptForApproval
|
|
404
478
|
});
|
|
405
479
|
return session.run(prompt);
|
|
406
480
|
}
|
|
407
481
|
|
|
408
|
-
// src/
|
|
482
|
+
// src/index.ts
|
|
409
483
|
import { evaluatePermission } from "@robota-sdk/agent-core";
|
|
410
|
-
|
|
411
|
-
// src/hooks/hook-runner.ts
|
|
412
484
|
import { runHooks } from "@robota-sdk/agent-core";
|
|
413
485
|
|
|
414
486
|
// src/paths.ts
|
|
@@ -431,28 +503,9 @@ function userPaths() {
|
|
|
431
503
|
};
|
|
432
504
|
}
|
|
433
505
|
|
|
434
|
-
// src/tools/bash-tool.ts
|
|
435
|
-
import { bashTool } from "@robota-sdk/agent-tools";
|
|
436
|
-
|
|
437
|
-
// src/tools/read-tool.ts
|
|
438
|
-
import { readTool } from "@robota-sdk/agent-tools";
|
|
439
|
-
|
|
440
|
-
// src/tools/write-tool.ts
|
|
441
|
-
import { writeTool } from "@robota-sdk/agent-tools";
|
|
442
|
-
|
|
443
|
-
// src/tools/edit-tool.ts
|
|
444
|
-
import { editTool } from "@robota-sdk/agent-tools";
|
|
445
|
-
|
|
446
|
-
// src/tools/glob-tool.ts
|
|
447
|
-
import { globTool } from "@robota-sdk/agent-tools";
|
|
448
|
-
|
|
449
|
-
// src/tools/grep-tool.ts
|
|
450
|
-
import { grepTool } from "@robota-sdk/agent-tools";
|
|
451
|
-
|
|
452
506
|
// src/tools/agent-tool.ts
|
|
453
507
|
import { z as z2 } from "zod";
|
|
454
508
|
import { createZodFunctionTool } from "@robota-sdk/agent-tools";
|
|
455
|
-
import { Session as Session3 } from "@robota-sdk/agent-sessions";
|
|
456
509
|
function asZodSchema(schema) {
|
|
457
510
|
return schema;
|
|
458
511
|
}
|
|
@@ -473,26 +526,26 @@ async function runAgent(args) {
|
|
|
473
526
|
};
|
|
474
527
|
return JSON.stringify(result);
|
|
475
528
|
}
|
|
476
|
-
const
|
|
529
|
+
const noopTerminal = {
|
|
530
|
+
write: () => {
|
|
531
|
+
},
|
|
532
|
+
writeLine: () => {
|
|
533
|
+
},
|
|
534
|
+
writeMarkdown: () => {
|
|
535
|
+
},
|
|
536
|
+
writeError: () => {
|
|
537
|
+
},
|
|
538
|
+
prompt: () => Promise.resolve(""),
|
|
539
|
+
select: () => Promise.resolve(0),
|
|
540
|
+
spinner: () => ({ stop: () => {
|
|
541
|
+
}, update: () => {
|
|
542
|
+
} })
|
|
543
|
+
};
|
|
544
|
+
const subSession = createSession({
|
|
477
545
|
config: agentToolDeps.config,
|
|
478
546
|
context: agentToolDeps.context,
|
|
479
547
|
projectInfo: agentToolDeps.projectInfo,
|
|
480
|
-
|
|
481
|
-
terminal: {
|
|
482
|
-
write: () => {
|
|
483
|
-
},
|
|
484
|
-
writeLine: () => {
|
|
485
|
-
},
|
|
486
|
-
writeMarkdown: () => {
|
|
487
|
-
},
|
|
488
|
-
writeError: () => {
|
|
489
|
-
},
|
|
490
|
-
prompt: () => Promise.resolve(""),
|
|
491
|
-
select: () => Promise.resolve(0),
|
|
492
|
-
spinner: () => ({ stop: () => {
|
|
493
|
-
}, update: () => {
|
|
494
|
-
} })
|
|
495
|
-
},
|
|
548
|
+
terminal: noopTerminal,
|
|
496
549
|
// Sub-agents bypass permissions — they inherit parent's trust
|
|
497
550
|
permissionMode: "bypassPermissions"
|
|
498
551
|
});
|
|
@@ -521,28 +574,40 @@ var agentTool = createZodFunctionTool(
|
|
|
521
574
|
return runAgent(params);
|
|
522
575
|
}
|
|
523
576
|
);
|
|
577
|
+
|
|
578
|
+
// src/index.ts
|
|
579
|
+
import { bashTool as bashTool2 } from "@robota-sdk/agent-tools";
|
|
580
|
+
import { readTool as readTool2 } from "@robota-sdk/agent-tools";
|
|
581
|
+
import { writeTool as writeTool2 } from "@robota-sdk/agent-tools";
|
|
582
|
+
import { editTool as editTool2 } from "@robota-sdk/agent-tools";
|
|
583
|
+
import { globTool as globTool2 } from "@robota-sdk/agent-tools";
|
|
584
|
+
import { grepTool as grepTool2 } from "@robota-sdk/agent-tools";
|
|
524
585
|
export {
|
|
586
|
+
DEFAULT_TOOL_DESCRIPTIONS,
|
|
525
587
|
FileSessionLogger,
|
|
526
|
-
Session,
|
|
588
|
+
Session2 as Session,
|
|
527
589
|
SessionStore,
|
|
528
590
|
SilentSessionLogger,
|
|
529
591
|
TRUST_TO_MODE,
|
|
530
592
|
agentTool,
|
|
531
|
-
bashTool,
|
|
593
|
+
bashTool2 as bashTool,
|
|
532
594
|
buildSystemPrompt,
|
|
595
|
+
createDefaultTools,
|
|
596
|
+
createProvider,
|
|
597
|
+
createSession,
|
|
533
598
|
detectProject,
|
|
534
|
-
editTool,
|
|
599
|
+
editTool2 as editTool,
|
|
535
600
|
evaluatePermission,
|
|
536
|
-
globTool,
|
|
537
|
-
grepTool,
|
|
601
|
+
globTool2 as globTool,
|
|
602
|
+
grepTool2 as grepTool,
|
|
538
603
|
loadConfig,
|
|
539
604
|
loadContext,
|
|
540
605
|
projectPaths,
|
|
541
606
|
promptForApproval,
|
|
542
607
|
query,
|
|
543
|
-
readTool,
|
|
608
|
+
readTool2 as readTool,
|
|
544
609
|
runHooks,
|
|
545
610
|
setAgentToolDeps,
|
|
546
611
|
userPaths,
|
|
547
|
-
writeTool
|
|
612
|
+
writeTool2 as writeTool
|
|
548
613
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robota-sdk/agent-sdk",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
4
4
|
"description": "Programmatic SDK for building AI agents with Robota — provides Session, query(), built-in tools, permissions, hooks, and context loading",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/node/index.js",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"chalk": "^5.3.0",
|
|
26
26
|
"zod": "^3.24.0",
|
|
27
|
-
"@robota-sdk/agent-core": "3.0.0-beta.
|
|
28
|
-
"@robota-sdk/agent-provider-anthropic": "3.0.0-beta.
|
|
29
|
-
"@robota-sdk/agent-sessions": "3.0.0-beta.
|
|
30
|
-
"@robota-sdk/agent-tools": "3.0.0-beta.
|
|
27
|
+
"@robota-sdk/agent-core": "3.0.0-beta.4",
|
|
28
|
+
"@robota-sdk/agent-provider-anthropic": "3.0.0-beta.4",
|
|
29
|
+
"@robota-sdk/agent-sessions": "3.0.0-beta.4",
|
|
30
|
+
"@robota-sdk/agent-tools": "3.0.0-beta.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"rimraf": "^5.0.5",
|