@soft-boy/agentschema 0.5.0 → 0.5.2
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 +3 -3
- package/dist/bin/agentschema.js +3 -3
- package/dist/lib/channels.d.ts +9 -0
- package/dist/lib/channels.js +76 -7
- package/dist/lib/check.js +1 -1
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +2 -2
- package/dist/lib/scaffold.js +4 -4
- package/dist/lib/tools.d.ts +22 -0
- package/dist/lib/tools.js +139 -27
- package/dist/src/init.js +1 -1
- package/dist/src/tools-menu.js +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ my-agent/
|
|
|
14
14
|
├── system_prompt/
|
|
15
15
|
│ └── rules.md # more of the system prompt
|
|
16
16
|
├── tools/
|
|
17
|
-
│ ├── agent_toolset_20260401.md # the
|
|
17
|
+
│ ├── agent_toolset_20260401.md # the computer tools to enable
|
|
18
18
|
│ └── get_weather.md # a custom tool
|
|
19
19
|
├── skills/
|
|
20
20
|
│ └── code-review/
|
|
@@ -100,7 +100,7 @@ The computer the agent runs on. The frontmatter uses the fields of a [Managed Ag
|
|
|
100
100
|
|
|
101
101
|
Every `.md` file under `tools/`, at any depth, is a tool file, and subfolders are only for organizing. `agentschema tools create` writes any of the three kinds.
|
|
102
102
|
|
|
103
|
-
**
|
|
103
|
+
**Computer tools** run in the agent's container. One file lists them, with a Permission of `always_allow`, `always_ask` or `auto`:
|
|
104
104
|
|
|
105
105
|
```markdown
|
|
106
106
|
---
|
|
@@ -207,7 +207,7 @@ agentschema deploy [dir] # create or update the agent and everythin
|
|
|
207
207
|
agentschema run [dir] # chat with the deployed agent in the terminal
|
|
208
208
|
agentschema list # list the agents in your workspace
|
|
209
209
|
agentschema delete <agent_id> # archive an agent
|
|
210
|
-
agentschema tools create [dir] # add
|
|
210
|
+
agentschema tools create [dir] # add computer tools, a custom tool or an MCP server
|
|
211
211
|
agentschema sessions list # list the sessions in your workspace
|
|
212
212
|
agentschema sessions delete <id> # delete a session
|
|
213
213
|
agentschema cred create [dir] # add a credential to a vault, asking a few questions
|
package/dist/bin/agentschema.js
CHANGED
|
@@ -27,7 +27,7 @@ Commands:
|
|
|
27
27
|
run [dir] Chat with the deployed agent in a new session, loading dir/.env for your tools
|
|
28
28
|
list List the agents in your workspace
|
|
29
29
|
delete <agent_id> Archive an agent (agents can't be deleted outright)
|
|
30
|
-
tools <command> Add
|
|
30
|
+
tools <command> Add computer tools, custom tools and MCP servers (agentschema tools -h)
|
|
31
31
|
sessions <command> List and delete sessions (agentschema sessions -h)
|
|
32
32
|
cred <command> Create and manage the credentials in vaults/ (agentschema cred -h)
|
|
33
33
|
|
|
@@ -43,11 +43,11 @@ Options:
|
|
|
43
43
|
${FOOTER}`;
|
|
44
44
|
const TOOLS_USAGE = `Usage: agentschema tools <command> [options]
|
|
45
45
|
|
|
46
|
-
Each tool is a file in tools/. The
|
|
46
|
+
Each tool is a file in tools/. The computer tools share one file, each custom tool has its own,
|
|
47
47
|
and so does each MCP server.
|
|
48
48
|
|
|
49
49
|
Commands:
|
|
50
|
-
create [dir] Add a tool: asks whether it's the
|
|
50
|
+
create [dir] Add a tool: asks whether it's the computer tools, a custom tool or an
|
|
51
51
|
MCP server, then writes its file
|
|
52
52
|
|
|
53
53
|
Options:
|
package/dist/lib/channels.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Frontmatter, type MarkdownFile } from "./markdown.ts";
|
|
|
4
4
|
import { type AgentbookCatalog, type Tool } from "./tools.ts";
|
|
5
5
|
export declare const CHANNELS_DIR = "channels";
|
|
6
6
|
export declare const ANYONE = "*";
|
|
7
|
+
export declare const CONTACTS = "contacts";
|
|
7
8
|
export interface Channel extends MarkdownFile {
|
|
8
9
|
file: string;
|
|
9
10
|
name: string;
|
|
@@ -20,6 +21,11 @@ export interface ChannelType {
|
|
|
20
21
|
hasGroups: boolean;
|
|
21
22
|
expiresAfter?: string;
|
|
22
23
|
allow: Check;
|
|
24
|
+
sendTo?: {
|
|
25
|
+
place: Check;
|
|
26
|
+
contacts: boolean;
|
|
27
|
+
anyone: boolean;
|
|
28
|
+
};
|
|
23
29
|
fields: Record<string, ChannelField>;
|
|
24
30
|
identity?: (data: Frontmatter) => string | null;
|
|
25
31
|
}
|
|
@@ -61,5 +67,8 @@ export declare function checkChannels(channels: Channel[], { agent, systemPrompt
|
|
|
61
67
|
};
|
|
62
68
|
export declare function durationMs(value: unknown): number | null;
|
|
63
69
|
export declare function channelSettings({ data }: Pick<Channel, "data">): ChannelSettings;
|
|
70
|
+
export declare function maySendTo({ sendTo }: Pick<ChannelSettings, "sendTo">, to: string, { isContact }?: {
|
|
71
|
+
isContact?: boolean;
|
|
72
|
+
}): boolean;
|
|
64
73
|
export declare const channelSystem: (instance: ChannelSystemSource, channel: Pick<Channel, "body">) => string;
|
|
65
74
|
export {};
|
package/dist/lib/channels.js
CHANGED
|
@@ -8,13 +8,15 @@ import { AGENTBOOK, MCP_TOOLSET } from "./tools.js";
|
|
|
8
8
|
// doesn't receive these messages and `run` shouldn't either. So nothing here is sent to the API.
|
|
9
9
|
export const CHANNELS_DIR = "channels";
|
|
10
10
|
export const ANYONE = "*";
|
|
11
|
+
// In `send_to`, everyone who has messaged the agent on the channel.
|
|
12
|
+
export const CONTACTS = "contacts";
|
|
11
13
|
const DEFAULT_RESPOND_TO = ["direct", "mention"];
|
|
12
14
|
const DEFAULT_EXPIRES_AFTER = "24h";
|
|
13
15
|
// An email thread can go quiet for days and still be one conversation.
|
|
14
16
|
const EMAIL_EXPIRES_AFTER = "7d";
|
|
15
17
|
const RESPOND_TO = ["direct", "mention", "reply", "all"];
|
|
16
18
|
const LIMITS = ["messages_per_sender_per_hour", "messages_per_day", "messages_sent_per_hour"];
|
|
17
|
-
const SHARED_FIELDS = ["type", "enabled", "allow", "respond_to", "scope", "expires_after", "approvals", "limits", "greeting"];
|
|
19
|
+
const SHARED_FIELDS = ["type", "enabled", "allow", "respond_to", "scope", "expires_after", "approvals", "limits", "greeting", "send_to"];
|
|
18
20
|
const MAX_GREETING = 1000;
|
|
19
21
|
const MAX_SYSTEM_PROMPT = 100_000;
|
|
20
22
|
const code = (value) => `\`${value}\``;
|
|
@@ -34,6 +36,8 @@ const listOf = (check) => (value) => {
|
|
|
34
36
|
};
|
|
35
37
|
const PHONE = /^\+[1-9]\d{6,14}$/;
|
|
36
38
|
const DISCORD_ID = /^\d{17,20}$/;
|
|
39
|
+
const SLACK_MEMBER = /^[UW][A-Z0-9]{2,}$/;
|
|
40
|
+
const SLACK_CHANNEL = /^[CG][A-Z0-9]{2,}$/;
|
|
37
41
|
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
38
42
|
const EMAIL_ALLOW = matches(/^(\*|[^\s@]+)@[^\s@]+\.[^\s@]+$/, "an email address, or *@ and a domain");
|
|
39
43
|
// What differs between channels. Each `secrets` entry is something the host asks for and keeps: never
|
|
@@ -47,6 +51,8 @@ export const CHANNEL_TYPES = {
|
|
|
47
51
|
approvals: ["deny", "sender"],
|
|
48
52
|
hasGroups: true,
|
|
49
53
|
allow: matches(/^(\d+|@[A-Za-z0-9_]{5,32})$/, "a numeric user ID or an @username"),
|
|
54
|
+
// A bot can only message a chat that has started it, so there's no one else to send to.
|
|
55
|
+
sendTo: { place: matches(/^-?\d+$/, "a numeric chat ID"), contacts: true, anyone: false },
|
|
50
56
|
fields: {},
|
|
51
57
|
},
|
|
52
58
|
twilio: {
|
|
@@ -55,6 +61,7 @@ export const CHANNEL_TYPES = {
|
|
|
55
61
|
approvals: ["deny", "sender"],
|
|
56
62
|
hasGroups: false,
|
|
57
63
|
allow: matches(PHONE, "a phone number like +14155550123"),
|
|
64
|
+
sendTo: { place: matches(PHONE, "a phone number like +14155550123"), contacts: true, anyone: true },
|
|
58
65
|
fields: {
|
|
59
66
|
transport: { required: true, check: oneOf("sms", "whatsapp") },
|
|
60
67
|
from: { required: true, check: matches(PHONE, "a phone number like +14155550123") },
|
|
@@ -69,6 +76,7 @@ export const CHANNEL_TYPES = {
|
|
|
69
76
|
hasGroups: false,
|
|
70
77
|
expiresAfter: EMAIL_EXPIRES_AFTER,
|
|
71
78
|
allow: EMAIL_ALLOW,
|
|
79
|
+
sendTo: { place: EMAIL_ALLOW, contacts: true, anyone: true },
|
|
72
80
|
fields: {
|
|
73
81
|
address: { required: true, check: matches(EMAIL, "an email address") },
|
|
74
82
|
from_name: { check: text },
|
|
@@ -84,6 +92,7 @@ export const CHANNEL_TYPES = {
|
|
|
84
92
|
hasGroups: false,
|
|
85
93
|
expiresAfter: EMAIL_EXPIRES_AFTER,
|
|
86
94
|
allow: EMAIL_ALLOW,
|
|
95
|
+
sendTo: { place: EMAIL_ALLOW, contacts: true, anyone: true },
|
|
87
96
|
fields: {
|
|
88
97
|
address: { check: matches(EMAIL, "an email address") },
|
|
89
98
|
from_name: { check: text },
|
|
@@ -95,9 +104,12 @@ export const CHANNEL_TYPES = {
|
|
|
95
104
|
scopes: ["thread", "sender", "room"],
|
|
96
105
|
approvals: ["deny", "sender"],
|
|
97
106
|
hasGroups: true,
|
|
98
|
-
allow: matches(
|
|
107
|
+
allow: matches(SLACK_MEMBER, "a member ID like U012AB3CD"),
|
|
108
|
+
// A bot can post in a channel, or message a member directly, anywhere in its own workspace.
|
|
109
|
+
sendTo: { place: matches(/^[CGUW][A-Z0-9]{2,}$/, "a channel ID like C012AB3CD, or a member ID like U012AB3CD"), contacts: false, anyone: false },
|
|
99
110
|
fields: {
|
|
100
|
-
channels: { check: listOf(matches(
|
|
111
|
+
channels: { check: listOf(matches(SLACK_CHANNEL, "a channel ID like C012AB3CD")) },
|
|
112
|
+
dedicated_channels: { check: listOf(matches(SLACK_CHANNEL, "a channel ID like C012AB3CD")) },
|
|
101
113
|
},
|
|
102
114
|
},
|
|
103
115
|
discord: {
|
|
@@ -106,13 +118,13 @@ export const CHANNEL_TYPES = {
|
|
|
106
118
|
approvals: ["deny", "sender"],
|
|
107
119
|
hasGroups: true,
|
|
108
120
|
allow: matches(DISCORD_ID, "a numeric user ID"),
|
|
121
|
+
sendTo: { place: matches(DISCORD_ID, "a numeric channel ID"), contacts: false, anyone: false },
|
|
109
122
|
fields: {
|
|
110
123
|
application_id: { required: true, check: matches(DISCORD_ID, "a numeric application ID") },
|
|
111
124
|
public_key: { required: true, check: matches(/^[0-9a-f]{64}$/, "the 64-character public key") },
|
|
112
125
|
guilds: { check: listOf(matches(DISCORD_ID, "a numeric server ID")) },
|
|
113
126
|
channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
114
127
|
dedicated_channels: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
115
|
-
send_to: { check: listOf(matches(DISCORD_ID, "a numeric channel ID")) },
|
|
116
128
|
command: { check: matches(/^[a-z0-9_-]{1,32}$/, "a slash command's name, like ask") },
|
|
117
129
|
},
|
|
118
130
|
identity: ({ application_id: id }) => id,
|
|
@@ -169,6 +181,7 @@ export function checkChannels(channels, { agent = { body: "" }, systemPrompt = [
|
|
|
169
181
|
}
|
|
170
182
|
checkAllow(data, type, err, warn);
|
|
171
183
|
checkShared(data, type, err, warn);
|
|
184
|
+
checkSendTo(data, type, err, warn);
|
|
172
185
|
for (const [field, { required, check }] of Object.entries(type.fields)) {
|
|
173
186
|
if (data[field] === undefined) {
|
|
174
187
|
if (required)
|
|
@@ -197,7 +210,8 @@ export function checkChannels(channels, { agent = { body: "" }, systemPrompt = [
|
|
|
197
210
|
else
|
|
198
211
|
identities.set(identity, channel.file);
|
|
199
212
|
}
|
|
200
|
-
|
|
213
|
+
// A Discord channel can only be in one file's `send_to`. An address or number can be in several.
|
|
214
|
+
if (data.type === "discord" && Array.isArray(data.send_to)) {
|
|
201
215
|
for (const place of data.send_to) {
|
|
202
216
|
if (typeof place !== "string")
|
|
203
217
|
continue;
|
|
@@ -235,6 +249,45 @@ function checkAllow({ allow, approvals }, type, err, warn) {
|
|
|
235
249
|
warn(`\`allow\`: ${entry} can change hands, because Telegram usernames can be given up and reclaimed; a numeric user ID is safer`);
|
|
236
250
|
}
|
|
237
251
|
}
|
|
252
|
+
// `send_to`: where the agent may send on its own, through a host's tool. A list of places, which can
|
|
253
|
+
// include "contacts", for everyone who has messaged the agent on the channel, or "*" for anywhere, alone.
|
|
254
|
+
// Email takes "*@" and a domain, for anyone there.
|
|
255
|
+
function checkSendTo({ send_to: sendTo, type: name, allow }, type, err, warn) {
|
|
256
|
+
if (sendTo === undefined)
|
|
257
|
+
return;
|
|
258
|
+
if (!type.sendTo)
|
|
259
|
+
return err(`\`send_to\` isn't available on ${name} yet`);
|
|
260
|
+
const { place, contacts, anyone } = type.sendTo;
|
|
261
|
+
if (sendTo === ANYONE || sendTo === CONTACTS) {
|
|
262
|
+
if (sendTo === ANYONE && !anyone)
|
|
263
|
+
return err(`\`send_to: "${ANYONE}"\` isn't available on ${name}${contacts ? `; use ${CONTACTS} for everyone who's messaged it` : "; list where it can send"}`);
|
|
264
|
+
if (sendTo === CONTACTS && !contacts)
|
|
265
|
+
return err(`\`send_to: ${CONTACTS}\` isn't available on ${name}; list where it can send`);
|
|
266
|
+
}
|
|
267
|
+
else if (!Array.isArray(sendTo)) {
|
|
268
|
+
return err(`\`send_to\` must be a list of where it can send${anyone ? `, or "${ANYONE}"` : ""}`);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
for (const entry of sendTo) {
|
|
272
|
+
if (entry === ANYONE)
|
|
273
|
+
return err(anyone ? `write \`send_to: "${ANYONE}"\` on its own, not in a list` : `\`send_to\` can't be "${ANYONE}" on ${name}`);
|
|
274
|
+
if (entry === CONTACTS) {
|
|
275
|
+
if (!contacts)
|
|
276
|
+
err(`\`send_to\`: ${CONTACTS} isn't available on ${name}`);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
const problem = place(entry);
|
|
280
|
+
if (problem)
|
|
281
|
+
err(`\`send_to\`: ${JSON.stringify(entry)} ${problem}${contacts ? `, or ${CONTACTS}` : ""}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (sendTo === ANYONE && name === "twilio") {
|
|
285
|
+
warn(`\`send_to: "${ANYONE}"\` lets the agent text any number. Texting people who haven't agreed to hear from you can break US law and carrier rules, so ${CONTACTS} or a list is safer`);
|
|
286
|
+
}
|
|
287
|
+
else if (sendTo === ANYONE && allow === ANYONE) {
|
|
288
|
+
warn(`anyone can message this channel, and \`send_to: "${ANYONE}"\` lets the agent send anywhere; a host should only let the owner's own conversations send to places that aren't listed`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
238
291
|
function checkShared(data, type, err, warn) {
|
|
239
292
|
if (data.enabled !== undefined && typeof data.enabled !== "boolean")
|
|
240
293
|
err("`enabled` must be true or false");
|
|
@@ -286,7 +339,7 @@ function checkShared(data, type, err, warn) {
|
|
|
286
339
|
}
|
|
287
340
|
}
|
|
288
341
|
// The tools that act through the owner's sign-ins and connections without anyone approving each call.
|
|
289
|
-
//
|
|
342
|
+
// Computer tools aren't here, since they run in the session's own container. In a toolset's table, a
|
|
290
343
|
// blank permission means the file's default, which for an MCP server is the API's default of asking.
|
|
291
344
|
function toolsThatRunUnasked(tools, toolsets) {
|
|
292
345
|
const isOn = (row) => row.enabled.toLowerCase() === "true";
|
|
@@ -324,7 +377,7 @@ export function channelSettings({ data }) {
|
|
|
324
377
|
allow: data.allow,
|
|
325
378
|
respondTo: data.respond_to ?? DEFAULT_RESPOND_TO,
|
|
326
379
|
dedicatedChannels: data.dedicated_channels ?? [],
|
|
327
|
-
sendTo: data.send_to
|
|
380
|
+
sendTo: data.send_to === undefined ? [] : Array.isArray(data.send_to) ? data.send_to : [data.send_to],
|
|
328
381
|
scope: data.scope ?? type.scopes[0],
|
|
329
382
|
expiresAfterMs: durationMs(data.expires_after ?? type.expiresAfter ?? DEFAULT_EXPIRES_AFTER),
|
|
330
383
|
approvals: data.approvals ?? "deny",
|
|
@@ -332,6 +385,22 @@ export function channelSettings({ data }) {
|
|
|
332
385
|
greeting: data.greeting ?? null,
|
|
333
386
|
};
|
|
334
387
|
}
|
|
388
|
+
// Whether a channel's `send_to` lets the agent send to `to`, given whether `to` has messaged the agent
|
|
389
|
+
// on that channel before. Email addresses are compared without regard to case.
|
|
390
|
+
export function maySendTo({ sendTo }, to, { isContact = false } = {}) {
|
|
391
|
+
if (sendTo.includes(ANYONE))
|
|
392
|
+
return true;
|
|
393
|
+
if (isContact && sendTo.includes(CONTACTS))
|
|
394
|
+
return true;
|
|
395
|
+
const address = to.toLowerCase();
|
|
396
|
+
return sendTo.some((place) => {
|
|
397
|
+
if (place === CONTACTS || place === ANYONE)
|
|
398
|
+
return false;
|
|
399
|
+
if (place.startsWith("*@"))
|
|
400
|
+
return address.endsWith(place.slice(1).toLowerCase());
|
|
401
|
+
return place.includes("@") ? place.toLowerCase() === address : place === to;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
335
404
|
// The system prompt for a conversation on this channel: the agent's, then the channel's own instructions.
|
|
336
405
|
// A session can override `system` for itself, so a channel doesn't need its own copy of the agent.
|
|
337
406
|
// `instance` is what checkFiles returns, so the agent's prompt includes system_prompt/. An agent alone,
|
package/dist/lib/check.js
CHANGED
|
@@ -58,7 +58,7 @@ export function checkFiles(files, options = {}) {
|
|
|
58
58
|
checkScheduled(scheduled, { tools }, errors, warnings);
|
|
59
59
|
const vaultFiles = vaults.flatMap((v) => [...(v.file ? [[`${v.path}/${VAULT_FILE}`, v.file]] : []), ...v.credentials.map((c) => [c.file, c])]);
|
|
60
60
|
const skillTexts = skills.flatMap((s) => s.files.map((f) => [`${s.path}/${f.rel}`, { raw: textOf(f.bytes) }]));
|
|
61
|
-
const scanned = [[AGENT_FILE, agent], [env?.file, env], ...tools.
|
|
61
|
+
const scanned = [[AGENT_FILE, agent], [env?.file, env], ...tools.flatMap((t) => [[t.file, t], ...(t.members ?? []).map((m) => [m.file, m])]), ...vaultFiles, ...skillTexts, ...channels.map((c) => [c.file, c]), ...scheduled.map((t) => [t.file, t]), ...systemPrompt.map((p) => [p.file, { raw: p.text }])];
|
|
62
62
|
for (const [file, parsed] of scanned) {
|
|
63
63
|
if (!parsed)
|
|
64
64
|
continue;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ANYONE, CHANNELS_DIR, CHANNEL_TYPES, channelSettings, channelSystem, durationMs, readChannels } from "./channels.ts";
|
|
1
|
+
export { ANYONE, CHANNELS_DIR, CHANNEL_TYPES, CONTACTS, channelSettings, channelSystem, durationMs, maySendTo, readChannels } from "./channels.ts";
|
|
2
2
|
export { checkFiles } from "./check.ts";
|
|
3
3
|
export { bytesOf, isIgnoredPath, pathsUnder, textOf } from "./files.ts";
|
|
4
4
|
export { AGENT_FILE, COMPUTER_FILE, ENVIRONMENT_KEY, OLD_COMPUTER_FILE, agentBody, envBody, environmentEntry, readInstance, upgradeLock, } from "./instance.ts";
|
|
@@ -8,7 +8,7 @@ export { SCHEDULED_DIR, cronProblem, isTimeZone, readScheduled, taskBody, taskKe
|
|
|
8
8
|
export { SYSTEM_PROMPT_DIR, readSystemPrompt, systemPromptOf } from "./system-prompt.ts";
|
|
9
9
|
export { MAX_UPLOAD_BYTES, SKILLS_DIR, SKILL_FILE, readSkills, skillKey, skillRefs } from "./skills.ts";
|
|
10
10
|
export { agentMessageText, textStream } from "./stream.ts";
|
|
11
|
-
export { AGENTBOOK, MCP_TOOLSET, POLICIES, PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR, agentbookTools, compileTools, mcpToolsetFile, readTools, } from "./tools.ts";
|
|
11
|
+
export { AGENTBOOK, MCP_TOOLSET, OWNER_NOTES, POLICIES, COMPUTER_TOOLS, PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLSET_FOLDER_FILE, TOOLS_DIR, agentbookTools, agentbookToolsetFiles, compileTools, mcpToolsetFile, readTools, } from "./tools.ts";
|
|
12
12
|
export { CREDENTIAL_TYPES, ENV_VAR, MCP_OAUTH, SECRET_FIELDS, TOKEN_ENDPOINT_AUTH, VAULTS_DIR, VAULT_FILE, changedImmutableFields, credentialCreateBody, credentialKey, credentialSettings, readVaults, secretsNeeded, vaultBody, vaultKey, } from "./vaults.ts";
|
|
13
13
|
export type { Channel, ChannelSettings, ChannelSystemSource, ChannelType, CheckChannelsOptions, ReadChannelsResult, } from "./channels.ts";
|
|
14
14
|
export type { CheckOptions, CheckResult } from "./check.ts";
|
|
@@ -20,5 +20,5 @@ export type { ReadScheduledResult, ScheduledTask, TaskBody, TaskSettings } from
|
|
|
20
20
|
export type { ReadSkillsResult, Skill, SkillFile, SkillRef } from "./skills.ts";
|
|
21
21
|
export type { AgentMessageEvent, ContentBlock, StreamEvent, TextStream } from "./stream.ts";
|
|
22
22
|
export type { ReadSystemPromptResult, SystemPromptPart } from "./system-prompt.ts";
|
|
23
|
-
export type { AgentbookCatalog, AgentbookTool, AgentbookToolDefinition, CheckToolsOptions, CompileOptions, CompiledTool, InputSchema, JsonSchema, ReadToolsResult, Tool, ToolCode, ToolParam, ToolRow, } from "./tools.ts";
|
|
23
|
+
export type { AgentbookCatalog, AgentbookTool, AgentbookToolDefinition, CheckToolsOptions, CompileOptions, CompiledTool, InputSchema, JsonSchema, ReadToolsResult, Tool, ToolCode, ToolMember, ToolParam, ToolRow, } from "./tools.ts";
|
|
24
24
|
export type { Credential, CredentialSecrets, CredentialSettings, ReadVaultsResult, SecretsNeeded, Vault, VaultBody, } from "./vaults.ts";
|
package/dist/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The browser-safe core of agentschema: no Node APIs, and `yaml` as the only dependency. It works
|
|
2
2
|
// on file maps (see files.js), so it doesn't care whether an agent lives on disk or in a database.
|
|
3
|
-
export { ANYONE, CHANNELS_DIR, CHANNEL_TYPES, channelSettings, channelSystem, durationMs, readChannels } from "./channels.js";
|
|
3
|
+
export { ANYONE, CHANNELS_DIR, CHANNEL_TYPES, CONTACTS, channelSettings, channelSystem, durationMs, maySendTo, readChannels } from "./channels.js";
|
|
4
4
|
export { checkFiles } from "./check.js";
|
|
5
5
|
export { bytesOf, isIgnoredPath, pathsUnder, textOf } from "./files.js";
|
|
6
6
|
export { AGENT_FILE, COMPUTER_FILE, ENVIRONMENT_KEY, OLD_COMPUTER_FILE, agentBody, envBody, environmentEntry, readInstance, upgradeLock, } from "./instance.js";
|
|
@@ -10,5 +10,5 @@ export { SCHEDULED_DIR, cronProblem, isTimeZone, readScheduled, taskBody, taskKe
|
|
|
10
10
|
export { SYSTEM_PROMPT_DIR, readSystemPrompt, systemPromptOf } from "./system-prompt.js";
|
|
11
11
|
export { MAX_UPLOAD_BYTES, SKILLS_DIR, SKILL_FILE, readSkills, skillKey, skillRefs } from "./skills.js";
|
|
12
12
|
export { agentMessageText, textStream } from "./stream.js";
|
|
13
|
-
export { AGENTBOOK, MCP_TOOLSET, POLICIES, PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR, agentbookTools, compileTools, mcpToolsetFile, readTools, } from "./tools.js";
|
|
13
|
+
export { AGENTBOOK, MCP_TOOLSET, OWNER_NOTES, POLICIES, COMPUTER_TOOLS, PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLSET_FOLDER_FILE, TOOLS_DIR, agentbookTools, agentbookToolsetFiles, compileTools, mcpToolsetFile, readTools, } from "./tools.js";
|
|
14
14
|
export { CREDENTIAL_TYPES, ENV_VAR, MCP_OAUTH, SECRET_FIELDS, TOKEN_ENDPOINT_AUTH, VAULTS_DIR, VAULT_FILE, changedImmutableFields, credentialCreateBody, credentialKey, credentialSettings, readVaults, secretsNeeded, vaultBody, vaultKey, } from "./vaults.js";
|
package/dist/lib/scaffold.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringify } from "yaml";
|
|
2
2
|
import { AGENT_FILE, COMPUTER_FILE } from "./instance.js";
|
|
3
|
-
import {
|
|
3
|
+
import { COMPUTER_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR } from "./tools.js";
|
|
4
4
|
export const MODELS = ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
|
|
5
5
|
export const NETWORKING = ["limited", "unrestricted"];
|
|
6
6
|
// The answers used for a new agent called `name`, when a question is skipped.
|
|
@@ -18,7 +18,7 @@ export function defaultAnswers(name) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
// Returns { path: text } for a set of answers: agent.md, env.md, and tools/agent_toolset_20260401.md
|
|
21
|
-
// listing every
|
|
21
|
+
// listing every computer tool when the agent gets them.
|
|
22
22
|
export function scaffold(answers) {
|
|
23
23
|
const agent = { name: answers.name, model: answers.model };
|
|
24
24
|
const networking = { type: answers.networking };
|
|
@@ -33,11 +33,11 @@ export function scaffold(answers) {
|
|
|
33
33
|
[COMPUTER_FILE]: `---\n${stringify(env)}---\nCloud container with ${access}.\n`,
|
|
34
34
|
};
|
|
35
35
|
if (answers.tools) {
|
|
36
|
-
files[`${TOOLS_DIR}/${TOOLSET_FILE}`] = builtInFile(
|
|
36
|
+
files[`${TOOLS_DIR}/${TOOLSET_FILE}`] = builtInFile(COMPUTER_TOOLS, COMPUTER_TOOLS, answers.permission);
|
|
37
37
|
}
|
|
38
38
|
return files;
|
|
39
39
|
}
|
|
40
|
-
// The
|
|
40
|
+
// The computer toolset file, with a row for each of `names`: on if it's in `enabled`, each with
|
|
41
41
|
// `permission`, so what's chosen is there to read and change. `auto` is what the API recommends for
|
|
42
42
|
// these tools: Anthropic judges each call, and asks when it can't tell.
|
|
43
43
|
export function builtInFile(names, enabled = names, permission = "auto") {
|
package/dist/lib/tools.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ export declare const TOOLSET = "agent_toolset_20260401";
|
|
|
5
5
|
export declare const TOOLSET_FILE = "agent_toolset_20260401.md";
|
|
6
6
|
export declare const MCP_TOOLSET = "mcp_toolset";
|
|
7
7
|
export declare const AGENTBOOK = "agentbook";
|
|
8
|
+
export declare const TOOLSET_FOLDER_FILE = "toolset.md";
|
|
9
|
+
export declare const COMPUTER_TOOLS: string[];
|
|
10
|
+
/** @deprecated Their old name: use COMPUTER_TOOLS. */
|
|
8
11
|
export declare const PREBUILT_TOOLS: string[];
|
|
9
12
|
export declare const POLICIES: string[];
|
|
10
13
|
export interface ToolParam {
|
|
@@ -18,6 +21,10 @@ export interface ToolRow {
|
|
|
18
21
|
enabled: string;
|
|
19
22
|
permission?: string;
|
|
20
23
|
}
|
|
24
|
+
export interface ToolMember extends MarkdownFile {
|
|
25
|
+
file: string;
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
21
28
|
export interface ToolCode {
|
|
22
29
|
lang: string;
|
|
23
30
|
source: string;
|
|
@@ -28,6 +35,7 @@ export interface Tool extends MarkdownFile {
|
|
|
28
35
|
params: ToolParam[] | null;
|
|
29
36
|
code: ToolCode | null;
|
|
30
37
|
rows: ToolRow[] | null;
|
|
38
|
+
members?: ToolMember[];
|
|
31
39
|
path?: string;
|
|
32
40
|
}
|
|
33
41
|
export interface ReadToolsResult {
|
|
@@ -47,8 +55,10 @@ export type AgentbookCatalog = Record<string, {
|
|
|
47
55
|
}>;
|
|
48
56
|
export interface AgentbookTool extends AgentbookToolDefinition {
|
|
49
57
|
file: string;
|
|
58
|
+
group: string;
|
|
50
59
|
toolset: string;
|
|
51
60
|
permission: string;
|
|
61
|
+
notes: string;
|
|
52
62
|
}
|
|
53
63
|
export interface CompileOptions {
|
|
54
64
|
toolsets?: AgentbookCatalog;
|
|
@@ -101,5 +111,17 @@ export declare function mcpToolsetFile({ name, tools, permission }: {
|
|
|
101
111
|
permission?: string;
|
|
102
112
|
}): string;
|
|
103
113
|
export declare function agentbookTools(tools: Tool[], toolsets?: AgentbookCatalog): AgentbookTool[];
|
|
114
|
+
export declare const OWNER_NOTES = "Notes from the agent's owner:";
|
|
115
|
+
export declare function agentbookToolsetFiles({ folder, toolset, note, tools }: {
|
|
116
|
+
folder: string;
|
|
117
|
+
toolset: string;
|
|
118
|
+
note?: string;
|
|
119
|
+
tools: {
|
|
120
|
+
name: string;
|
|
121
|
+
permission?: string;
|
|
122
|
+
enabled?: boolean;
|
|
123
|
+
notes?: string;
|
|
124
|
+
}[];
|
|
125
|
+
}): FileMap;
|
|
104
126
|
export declare function compileTools(tools: Tool[], { toolsets }?: CompileOptions): CompiledTool[];
|
|
105
127
|
export declare const wrapToolCode: (source: string) => string;
|
package/dist/lib/tools.js
CHANGED
|
@@ -6,7 +6,12 @@ export const TOOLSET = "agent_toolset_20260401";
|
|
|
6
6
|
export const TOOLSET_FILE = `${TOOLSET}.md`;
|
|
7
7
|
export const MCP_TOOLSET = "mcp_toolset";
|
|
8
8
|
export const AGENTBOOK = "agentbook";
|
|
9
|
-
|
|
9
|
+
// A folder of an agentbook toolset's tools has this file, saying which toolset it is.
|
|
10
|
+
export const TOOLSET_FOLDER_FILE = "toolset.md";
|
|
11
|
+
// The tools Claude runs on the agent's computer, its container, which computer.md describes.
|
|
12
|
+
export const COMPUTER_TOOLS = ["bash", "edit", "glob", "grep", "read", "web_fetch", "web_search", "write"];
|
|
13
|
+
/** @deprecated Their old name: use COMPUTER_TOOLS. */
|
|
14
|
+
export const PREBUILT_TOOLS = COMPUTER_TOOLS;
|
|
10
15
|
export const POLICIES = ["always_allow", "always_ask", "auto"];
|
|
11
16
|
// agentbook tools reach the API as custom tools, which have no permission policy: agentbook
|
|
12
17
|
// enforces these itself, and has nothing like the API's per-call `auto` judgement.
|
|
@@ -14,7 +19,7 @@ const AGENTBOOK_POLICIES = ["always_allow", "always_ask"];
|
|
|
14
19
|
const TYPES = ["string", "number", "integer", "boolean", "object", "array"];
|
|
15
20
|
// Reads every .md file under tools/, in any subfolder, sorted by name. Folders are only for
|
|
16
21
|
// organizing: a custom tool's name is its file name, and its path isn't compiled into anything.
|
|
17
|
-
// The
|
|
22
|
+
// The computer toolset is one file (by convention tools/agent_toolset_20260401.md) that lists its tools.
|
|
18
23
|
// No tools/ folder means no tools.
|
|
19
24
|
// Returns { tools, errors }; a tool file that can't be parsed has an entry in errors.
|
|
20
25
|
export function readTools(files) {
|
|
@@ -22,17 +27,71 @@ export function readTools(files) {
|
|
|
22
27
|
return { tools: [], errors: [`${TOOLS_DIR}: not a directory`] };
|
|
23
28
|
const tools = [];
|
|
24
29
|
const errors = [];
|
|
25
|
-
|
|
30
|
+
const parse = (file) => {
|
|
26
31
|
try {
|
|
27
|
-
|
|
28
|
-
const name = file.slice(file.lastIndexOf("/") + 1, -".md".length);
|
|
29
|
-
tools.push({ file, name, ...parsed, ...parseSections(parsed.body, file) });
|
|
32
|
+
return parseMarkdown(textOf(files[file]), file);
|
|
30
33
|
}
|
|
31
34
|
catch (err) {
|
|
32
35
|
if (!(err instanceof FileError))
|
|
33
36
|
throw err;
|
|
34
37
|
errors.push(err.message);
|
|
38
|
+
return null;
|
|
35
39
|
}
|
|
40
|
+
};
|
|
41
|
+
// A tool file, with its tables and code. A table that can't be read is an error too.
|
|
42
|
+
const asTool = (file, name, parsed, extra = {}) => {
|
|
43
|
+
try {
|
|
44
|
+
return { file, name, ...parsed, ...parseSections(parsed.body, file), ...extra };
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (!(err instanceof FileError))
|
|
48
|
+
throw err;
|
|
49
|
+
errors.push(err.message);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const paths = pathsUnder(files, TOOLS_DIR).filter((path) => path.endsWith(".md"));
|
|
54
|
+
const folderOf = (path) => path.slice(0, path.lastIndexOf("/"));
|
|
55
|
+
const nameOf = (path) => path.slice(path.lastIndexOf("/") + 1).replace(/\.md$/, "");
|
|
56
|
+
// A folder with a toolset.md of `type: agentbook` is one toolset, and every other file in it is one of
|
|
57
|
+
// its tools. tools/ itself can't be one, since its files are tools of every kind.
|
|
58
|
+
const folders = new Set();
|
|
59
|
+
for (const path of paths) {
|
|
60
|
+
if (!path.endsWith(`/${TOOLSET_FOLDER_FILE}`) || folderOf(path) === TOOLS_DIR)
|
|
61
|
+
continue;
|
|
62
|
+
const parsed = parse(path);
|
|
63
|
+
if (!parsed || parsed.data.type !== AGENTBOOK)
|
|
64
|
+
continue;
|
|
65
|
+
const folder = folderOf(path);
|
|
66
|
+
folders.add(folder);
|
|
67
|
+
const members = [];
|
|
68
|
+
for (const file of paths) {
|
|
69
|
+
if (file === path || !file.startsWith(`${folder}/`))
|
|
70
|
+
continue;
|
|
71
|
+
if (folderOf(file) !== folder) {
|
|
72
|
+
errors.push(`${file}: a toolset's folder holds its tools' files directly, without folders inside it`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// A tool's file can be only notes, without properties.
|
|
76
|
+
const text = textOf(files[file]).replace(/^\uFEFF/, "");
|
|
77
|
+
const member = /^---\r?\n/.test(text) ? parse(file) : { data: {}, body: text.trim(), raw: text };
|
|
78
|
+
if (member)
|
|
79
|
+
members.push({ file, name: nameOf(file), ...member });
|
|
80
|
+
}
|
|
81
|
+
members.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
82
|
+
const rows = members.map(({ name, data }) => ({ name, enabled: data.enabled === false ? "false" : "true", permission: typeof data.permission === "string" ? data.permission : "" }));
|
|
83
|
+
const tool = asTool(path, nameOf(folder), parsed, { rows, members });
|
|
84
|
+
if (tool)
|
|
85
|
+
tools.push(tool);
|
|
86
|
+
}
|
|
87
|
+
const inFolder = (path) => [...folders].some((folder) => path.startsWith(`${folder}/`));
|
|
88
|
+
for (const file of paths) {
|
|
89
|
+
if (inFolder(file))
|
|
90
|
+
continue;
|
|
91
|
+
const parsed = parse(file);
|
|
92
|
+
const tool = parsed && asTool(file, nameOf(file), parsed);
|
|
93
|
+
if (tool)
|
|
94
|
+
tools.push(tool);
|
|
36
95
|
}
|
|
37
96
|
// Names must be unique across folders, since the folders are dropped.
|
|
38
97
|
for (const [type, what] of [["custom", "tool"], [MCP_TOOLSET, "MCP server"], [AGENTBOOK, "agentbook toolset"]]) {
|
|
@@ -41,9 +100,14 @@ export function readTools(files) {
|
|
|
41
100
|
errors.push(`${TOOLS_DIR}: more than one ${what} is named \`${name}\` (${same.map((t) => t.file).join(", ")})`);
|
|
42
101
|
}
|
|
43
102
|
}
|
|
103
|
+
for (const [toolset, same] of groupBy(tools.filter((t) => t.data.type === AGENTBOOK && typeof t.data.toolset === "string"), (t) => t.data.toolset)) {
|
|
104
|
+
if (same.length > 1 && new Set(same.map((t) => t.name)).size > 1) {
|
|
105
|
+
errors.push(`${TOOLS_DIR}: more than one file turns on the agentbook toolset \`${toolset}\` (${same.map((t) => t.file).join(", ")})`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
44
108
|
const toolsets = tools.filter((t) => t.data.type === TOOLSET);
|
|
45
109
|
if (toolsets.length > 1) {
|
|
46
|
-
errors.push(`${TOOLS_DIR}: more than one \`${TOOLSET}\` file (${toolsets.map((t) => t.file).join(", ")}); list every
|
|
110
|
+
errors.push(`${TOOLS_DIR}: more than one \`${TOOLSET}\` file (${toolsets.map((t) => t.file).join(", ")}); list every computer tool in one file`);
|
|
47
111
|
}
|
|
48
112
|
return { tools: tools.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)), errors };
|
|
49
113
|
}
|
|
@@ -148,11 +212,11 @@ export function checkTools(tools, errors, warnings = [], options = {}) {
|
|
|
148
212
|
extra(["type", "name", "description"]);
|
|
149
213
|
}
|
|
150
214
|
else if (type === AGENTBOOK) {
|
|
151
|
-
checkAgentbook(tool, err, (msg) => warnings.push(`${tool.file}: ${msg}`), options);
|
|
215
|
+
checkAgentbook(tool, err, (msg) => warnings.push(`${tool.file}: ${msg}`), options, (file, msg) => errors.push(`${file}: ${msg}`));
|
|
152
216
|
extra(["type", "toolset"]);
|
|
153
217
|
}
|
|
154
218
|
else {
|
|
155
|
-
err(`\`type\` must be \`${TOOLSET}\` (the
|
|
219
|
+
err(`\`type\` must be \`${TOOLSET}\` (the computer tools), \`${MCP_TOOLSET}\` (an MCP server), \`custom\` or \`${AGENTBOOK}\``);
|
|
156
220
|
}
|
|
157
221
|
}
|
|
158
222
|
}
|
|
@@ -188,28 +252,54 @@ function checkMcpToolset(tool, err) {
|
|
|
188
252
|
}
|
|
189
253
|
// A toolset from agentbook's catalog. `## Tools` turns its tools on one by one, so a tool without
|
|
190
254
|
// a row is off: a new tool in the catalog never reaches a deployed agent by itself.
|
|
191
|
-
|
|
255
|
+
//
|
|
256
|
+
// It's either one file with a `## Tools` table, named after the toolset, or a folder: a toolset.md, and a
|
|
257
|
+
// file for each tool, named after it, whose body is notes for the agent. A tool without a row, or a
|
|
258
|
+
// file, is off.
|
|
259
|
+
function checkAgentbook(tool, err, warn, { toolsets }, errAt) {
|
|
192
260
|
const { toolset } = tool.data;
|
|
193
261
|
if (typeof toolset !== "string" || toolset === "")
|
|
194
262
|
return err("`toolset` is required");
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
263
|
+
if (tool.members) {
|
|
264
|
+
const hasTable = /^##\s+tools\s*$/im.test(tool.body);
|
|
265
|
+
if (hasTable)
|
|
266
|
+
err("a toolset's folder lists its tools as files beside this one, not as a `## Tools` table");
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
if (toolset !== tool.name)
|
|
270
|
+
err(`\`toolset\` must match the file name (${tool.name})`);
|
|
271
|
+
if (!tool.rows)
|
|
272
|
+
err("a `## Tools` table listing the tools to enable is required");
|
|
273
|
+
}
|
|
199
274
|
if (!toolsets)
|
|
200
275
|
warn("this toolset runs on agentbook, so `agentschema deploy` can't deploy it");
|
|
201
276
|
else if (!Object.hasOwn(toolsets, toolset))
|
|
202
277
|
err(`\`${toolset}\` isn't an agentbook toolset; use ${Object.keys(toolsets).join(", ")}`);
|
|
203
278
|
const known = toolsets && Object.hasOwn(toolsets, toolset) ? toolsets[toolset].tools.map((t) => t.name) : null;
|
|
204
|
-
|
|
279
|
+
if (!tool.members)
|
|
280
|
+
return checkRows(tool.rows ?? [], err, { known, what: `a tool in \`${toolset}\``, policies: AGENTBOOK_POLICIES });
|
|
281
|
+
for (const member of tool.members) {
|
|
282
|
+
const memberErr = (msg) => errAt(member.file, msg);
|
|
283
|
+
if (known && !known.includes(member.name))
|
|
284
|
+
memberErr(`\`${member.name}\` is not a tool in \`${toolset}\`; use ${known.join(", ")}`);
|
|
285
|
+
const { enabled, permission } = member.data;
|
|
286
|
+
if (enabled !== undefined && typeof enabled !== "boolean")
|
|
287
|
+
memberErr("`enabled` must be true or false");
|
|
288
|
+
if (permission !== undefined && permission !== null && !AGENTBOOK_POLICIES.includes(permission)) {
|
|
289
|
+
memberErr(`\`permission\` must be ${AGENTBOOK_POLICIES.join(" or ")}, or left out`);
|
|
290
|
+
}
|
|
291
|
+
for (const key of Object.keys(member.data))
|
|
292
|
+
if (!["enabled", "permission"].includes(key))
|
|
293
|
+
memberErr(`unknown field \`${key}\``);
|
|
294
|
+
}
|
|
205
295
|
}
|
|
206
296
|
function checkToolset(tool, err) {
|
|
207
297
|
if (!tool.rows) {
|
|
208
|
-
// 0.2.0 had one file per
|
|
209
|
-
const hint =
|
|
210
|
-
return err(`a \`## Tools\` table listing the
|
|
298
|
+
// 0.2.0 had one file per computer tool, with no table.
|
|
299
|
+
const hint = COMPUTER_TOOLS.includes(tool.name) ? `; since 0.2.1 all computer tools go in one file, ${TOOLS_DIR}/${TOOLSET_FILE}` : "";
|
|
300
|
+
return err(`a \`## Tools\` table listing the computer tools to enable is required${hint}`);
|
|
211
301
|
}
|
|
212
|
-
checkRows(tool.rows, err, { known:
|
|
302
|
+
checkRows(tool.rows, err, { known: COMPUTER_TOOLS, what: "a computer tool" });
|
|
213
303
|
}
|
|
214
304
|
// The rows of a `## Tools` table. `known` is the list of valid tool names, when there is one.
|
|
215
305
|
function checkRows(rows, err, { known, what, policies = POLICIES }) {
|
|
@@ -235,8 +325,8 @@ function checkCustom(tool, err) {
|
|
|
235
325
|
err(`\`name\` must match the file name (${tool.name})`);
|
|
236
326
|
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(tool.name))
|
|
237
327
|
err("the name may only use letters, digits, _ and -, up to 64 characters");
|
|
238
|
-
if (
|
|
239
|
-
err(`\`${tool.name}\` is a
|
|
328
|
+
if (COMPUTER_TOOLS.includes(tool.name))
|
|
329
|
+
err(`\`${tool.name}\` is a computer tool's name; the API rejects custom tools that reuse one`);
|
|
240
330
|
if (/^(mcp__|ant__)/.test(tool.name))
|
|
241
331
|
err("custom tool names can't start with mcp__ or ant__");
|
|
242
332
|
if (typeof description !== "string" || description.trim() === "")
|
|
@@ -285,9 +375,10 @@ export function mcpToolsetFile({ name, tools = [], permission = "always_ask" })
|
|
|
285
375
|
front.default_config = { permission_policy: { type: permission } };
|
|
286
376
|
return `---\n${stringify(front)}---\n\nEvery tool the server offers is on. Its tools get listed here once it's been signed in to.\n`;
|
|
287
377
|
}
|
|
288
|
-
// The agentbook tools a folder turns on, as { file, toolset, name, description, input_schema,
|
|
289
|
-
// permission }. `toolsets` is the catalog, { [toolset]: { tools: [{ name, description,
|
|
290
|
-
// A blank permission means `always_ask`, the safe choice for a tool with no policy of
|
|
378
|
+
// The agentbook tools a folder turns on, as { file, group, toolset, name, description, input_schema,
|
|
379
|
+
// permission, notes }. `toolsets` is the catalog, { [toolset]: { tools: [{ name, description,
|
|
380
|
+
// input_schema }] } }. A blank permission means `always_ask`, the safe choice for a tool with no policy of
|
|
381
|
+
// its own. A tool's own file in a toolset folder can add notes, which follow the catalog's description.
|
|
291
382
|
export function agentbookTools(tools, toolsets = {}) {
|
|
292
383
|
return byName(tools.filter((t) => t.data.type === AGENTBOOK)).flatMap((tool) => {
|
|
293
384
|
const { toolset } = tool.data;
|
|
@@ -297,18 +388,39 @@ export function agentbookTools(tools, toolsets = {}) {
|
|
|
297
388
|
const row = tool.rows?.find((r) => r.name === definition.name);
|
|
298
389
|
if (row?.enabled.toLowerCase() !== "true")
|
|
299
390
|
return [];
|
|
300
|
-
|
|
391
|
+
const member = tool.members?.find((m) => m.name === definition.name);
|
|
392
|
+
const notes = member?.body.trim() ?? "";
|
|
393
|
+
const description = notes ? `${definition.description}\n\n${OWNER_NOTES}\n${notes}` : definition.description;
|
|
394
|
+
return [{ ...definition, description, file: member?.file ?? tool.file, group: tool.name, toolset, permission: row.permission || "always_ask", notes }];
|
|
301
395
|
});
|
|
302
396
|
});
|
|
303
397
|
}
|
|
304
|
-
//
|
|
398
|
+
// What comes before a tool's notes from its file, in the description the agent gets.
|
|
399
|
+
export const OWNER_NOTES = "Notes from the agent's owner:";
|
|
400
|
+
// The files of an agentbook toolset as a folder: tools/<folder>/toolset.md, saying which toolset, with
|
|
401
|
+
// `note` for people in its body, and a file for each tool in `tools`, with its permission and notes.
|
|
402
|
+
export function agentbookToolsetFiles({ folder, toolset, note = "", tools }) {
|
|
403
|
+
const dir = `${TOOLS_DIR}/${folder}`;
|
|
404
|
+
const files = { [`${dir}/${TOOLSET_FOLDER_FILE}`]: `---\n${stringify({ type: AGENTBOOK, toolset })}---\n${note ? `\n${note.trim()}\n` : ""}` };
|
|
405
|
+
for (const { name, permission, enabled, notes = "" } of tools) {
|
|
406
|
+
const front = {};
|
|
407
|
+
if (enabled === false)
|
|
408
|
+
front.enabled = false;
|
|
409
|
+
if (permission)
|
|
410
|
+
front.permission = permission;
|
|
411
|
+
const head = Object.keys(front).length > 0 ? `---\n${stringify(front)}---\n` : "";
|
|
412
|
+
files[`${dir}/${name}.md`] = `${head}${notes ? `${head ? "\n" : ""}${notes.trim()}\n` : ""}`;
|
|
413
|
+
}
|
|
414
|
+
return files;
|
|
415
|
+
}
|
|
416
|
+
// The tools list sent to the API, each kind sorted by name: the computer toolset with a config
|
|
305
417
|
// for each row of its table (tools it doesn't list keep the API's defaults), then a toolset for
|
|
306
418
|
// each MCP server, then the custom tools, and last agentbook's tools, which reach the API as
|
|
307
419
|
// custom tools. Only their name, description and input schema are sent.
|
|
308
420
|
export function compileTools(tools, { toolsets } = {}) {
|
|
309
421
|
const compiled = [];
|
|
310
422
|
const toolset = tools.find((t) => t.data.type === TOOLSET);
|
|
311
|
-
// check requires the
|
|
423
|
+
// check requires the computer toolset's table, so its rows are there.
|
|
312
424
|
if (toolset)
|
|
313
425
|
compiled.push({ type: TOOLSET, configs: configs(toolset.rows) });
|
|
314
426
|
for (const tool of byName(tools.filter((t) => t.data.type === MCP_TOOLSET))) {
|
package/dist/src/init.js
CHANGED
|
@@ -23,7 +23,7 @@ export async function init(dir, { yes = false, input = process.stdin, output = p
|
|
|
23
23
|
mkdirSync(dirname(resolve(dir, file)), { recursive: true });
|
|
24
24
|
writeFileSync(resolve(dir, file), text);
|
|
25
25
|
}
|
|
26
|
-
const tools = answers.tools ? `, and ${dir}/${TOOLS_DIR}/${TOOLSET_FILE} with the
|
|
26
|
+
const tools = answers.tools ? `, and ${dir}/${TOOLS_DIR}/${TOOLSET_FILE} with the computer tools (set Enabled to false to turn one off)` : "";
|
|
27
27
|
output.write(`\nCreated ${dir}/${AGENT_FILE} and ${dir}/${COMPUTER_FILE}${tools}.\n\nNext:\n`);
|
|
28
28
|
output.write(` agentschema deploy ${dir}\n agentschema run ${dir}\n`);
|
|
29
29
|
return files;
|
package/dist/src/tools-menu.js
CHANGED
|
@@ -8,8 +8,8 @@ import { AGENT_FILE, COMPUTER_FILE, OLD_COMPUTER_FILE } from "../lib/instance.js
|
|
|
8
8
|
import { builtInFile } from "../lib/scaffold.js";
|
|
9
9
|
import { updateFrontmatter } from "./folder.js";
|
|
10
10
|
import { listMcpTools } from "./mcp.js";
|
|
11
|
-
import { MCP_TOOLSET, POLICIES,
|
|
12
|
-
const
|
|
11
|
+
import { MCP_TOOLSET, POLICIES, COMPUTER_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR, mcpToolsetFile } from "../lib/tools.js";
|
|
12
|
+
const COMPUTER = "Computer tools (bash, files, web search)";
|
|
13
13
|
const CUSTOM = "Custom tool (JavaScript that runs on your machine)";
|
|
14
14
|
const MCP = "MCP server";
|
|
15
15
|
const INPUT_TYPES = ["string", "number", "integer", "boolean", "object", "string[]", "number[]", "integer[]", "boolean[]", "object[]"];
|
|
@@ -19,8 +19,8 @@ export async function toolsCreate(dir = ".", { io, fetch = globalThis.fetch, log
|
|
|
19
19
|
const { errors, instance } = check(dir);
|
|
20
20
|
if (!instance)
|
|
21
21
|
throw new DeployError(`${dir} isn't an agent folder:\n ${errors.join("\n ")}`);
|
|
22
|
-
const kind = await io.select("What kind of tool?", [
|
|
23
|
-
const write = kind ===
|
|
22
|
+
const kind = await io.select("What kind of tool?", [COMPUTER, CUSTOM, MCP], COMPUTER);
|
|
23
|
+
const write = kind === COMPUTER ? computerTools : kind === CUSTOM ? custom : mcp;
|
|
24
24
|
const { path, text, addServer } = await write(dir, instance, io, { fetch, log });
|
|
25
25
|
const file = join(dir, path);
|
|
26
26
|
mkdirSync(dirname(file), { recursive: true });
|
|
@@ -49,19 +49,19 @@ export async function toolsCreate(dir = ".", { io, fetch = globalThis.fetch, log
|
|
|
49
49
|
log(`\nDeploy with:\n agentschema deploy ${dir}`);
|
|
50
50
|
return file;
|
|
51
51
|
}
|
|
52
|
-
// The
|
|
53
|
-
async function
|
|
52
|
+
// The computer toolset: one file, with a row for each tool.
|
|
53
|
+
async function computerTools(dir, { tools }, io) {
|
|
54
54
|
const existing = tools.find((t) => t.data.type === TOOLSET);
|
|
55
55
|
if (existing)
|
|
56
|
-
throw new DeployError(`the agent already has its
|
|
57
|
-
let enabled =
|
|
58
|
-
if (!(await io.confirm(`Turn on all eight (${
|
|
56
|
+
throw new DeployError(`the agent already has its computer tools in ${existing.file}; edit that file's table to turn tools on or off`);
|
|
57
|
+
let enabled = COMPUTER_TOOLS;
|
|
58
|
+
if (!(await io.confirm(`Turn on all eight (${COMPUTER_TOOLS.join(", ")})?`, true))) {
|
|
59
59
|
enabled = [];
|
|
60
|
-
for (const name of
|
|
60
|
+
for (const name of COMPUTER_TOOLS)
|
|
61
61
|
if (await io.confirm(` ${name}?`, true))
|
|
62
62
|
enabled.push(name);
|
|
63
63
|
}
|
|
64
|
-
return { path: `${TOOLS_DIR}/${TOOLSET_FILE}`, text: builtInFile(
|
|
64
|
+
return { path: `${TOOLS_DIR}/${TOOLSET_FILE}`, text: builtInFile(COMPUTER_TOOLS, enabled, await choosePermission(io, "auto")) };
|
|
65
65
|
}
|
|
66
66
|
// A custom tool: its name, description and inputs, with a code block to fill in.
|
|
67
67
|
async function custom(dir, { tools }, io) {
|
|
@@ -70,8 +70,8 @@ async function custom(dir, { tools }, io) {
|
|
|
70
70
|
validate: (n) => {
|
|
71
71
|
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(n))
|
|
72
72
|
return "Use letters, digits, _ and -, up to 64 characters";
|
|
73
|
-
if (
|
|
74
|
-
return `${n} is a
|
|
73
|
+
if (COMPUTER_TOOLS.includes(n))
|
|
74
|
+
return `${n} is a computer tool's name`;
|
|
75
75
|
if (/^(mcp__|ant__)/.test(n))
|
|
76
76
|
return "A custom tool's name can't start with mcp__ or ant__";
|
|
77
77
|
if (taken.has(n) || existsSync(join(dir, TOOLS_DIR, `${n}.md`)))
|