@soft-boy/agentschema 0.3.11 → 0.4.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eric Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # agentschema
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@soft-boy/agentschema)](https://www.npmjs.com/package/@soft-boy/agentschema)
4
+ [![downloads](https://img.shields.io/npm/dm/@soft-boy/agentschema)](https://www.npmjs.com/package/@soft-boy/agentschema)
5
+ [![node](https://img.shields.io/node/v/@soft-boy/agentschema)](https://nodejs.org)
6
+ [![license](https://img.shields.io/npm/l/@soft-boy/agentschema)](LICENSE)
7
+
3
8
  Define an AI-Agent as a folder of Markdown files.
4
9
 
5
10
  ```
6
11
  my-agent/
7
12
  ├── agent.md # the agent
8
- ├── env.md # the environment it runs in
13
+ ├── computer.md # the computer it runs on
14
+ ├── system_prompt/
15
+ │ └── rules.md # more of the system prompt
9
16
  ├── tools/
10
17
  │ ├── agent_toolset_20260401.md # the pre-built tools to enable
11
18
  │ └── get_weather.md # a custom tool
@@ -21,7 +28,25 @@ my-agent/
21
28
  └── good-morning.md # a task it runs on a timetable
22
29
  ```
23
30
 
24
- **Status:** v0.2 draft. v0.2 breaks from the Claude Managed Agents schema: tools move out of `agent.md` and into `tools/`.
31
+ ## Table of contents
32
+
33
+ - [Philosophy](#philosophy)
34
+ - [Install](#install)
35
+ - [Authentication](#authentication)
36
+ - [Getting started](#getting-started)
37
+ - [Specification](#specification)
38
+ - [`agent.md`](#agentmd)
39
+ - [`system_prompt/`](#system_prompt)
40
+ - [`computer.md`](#computermd)
41
+ - [`tools/`](#tools)
42
+ - [`skills/`](#skills)
43
+ - [`vaults/`](#vaults)
44
+ - [`channels/`](#channels)
45
+ - [`scheduled/`](#scheduled)
46
+ - [Usage](#usage)
47
+ - [Library](#library)
48
+ - [Development](#development)
49
+ - [License](#license)
25
50
 
26
51
  ## Philosophy
27
52
 
@@ -57,15 +82,19 @@ agentschema run my-agent
57
82
 
58
83
  ## Specification
59
84
 
60
- `agent.md` and `env.md` are required; everything else is optional. `agentschema check` validates a folder without calling the API. This is the short version, and the full specification is in [docs/](docs/README.md).
85
+ `agent.md` and `computer.md` are required; everything else is optional. `agentschema check` validates a folder without calling the API. This is the short version, and the full specification is in [docs/](docs/README.md).
61
86
 
62
87
  ### `agent.md`
63
88
 
64
89
  The frontmatter uses the fields of a [Managed Agents agent](https://platform.claude.com/docs/en/managed-agents/agent-setup), and `name` and `model` are required. The body is the system prompt.
65
90
 
66
- ### `env.md`
91
+ ### `system_prompt/`
92
+
93
+ A long system prompt can be split into files here, at any depth. They're added after `agent.md`'s body, in the order `tree` lists them, with a blank line between each one, so number them to keep them in order, like `01-role.md` and `02-rules.md`. Each file is taken as written. See [System prompt](docs/system_prompt.md).
94
+
95
+ ### `computer.md`
67
96
 
68
- The frontmatter uses the fields of a [Managed Agents environment](https://platform.claude.com/docs/en/managed-agents/environments). The body is a note for people, and isn't sent anywhere.
97
+ The computer the agent runs on. The frontmatter uses the fields of a [Managed Agents environment](https://platform.claude.com/docs/en/managed-agents/environments), and the body is a note for people, and isn't sent anywhere. It used to be called `env.md`, which still works, with a warning to rename it.
69
98
 
70
99
  ### `tools/`
71
100
 
@@ -208,3 +237,7 @@ npm install
208
237
  npm test # unit tests; deploy runs against a fake API client
209
238
  npm link # makes `agentschema` available globally from this checkout
210
239
  ```
240
+
241
+ ## License
242
+
243
+ [MIT](LICENSE)
package/lib/channels.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { pathsUnder, textOf } from "./files.js";
2
2
  import { AGENT_FILE } from "./instance.js";
3
+ import { systemPromptOf } from "./system-prompt.js";
3
4
  import { FileError, parseMarkdown } from "./markdown.js";
4
5
  import { AGENTBOOK, MCP_TOOLSET } from "./tools.js";
5
6
 
@@ -152,7 +153,7 @@ export function readChannels(files) {
152
153
 
153
154
  // Errors and warnings for the channel files, in check's format. `agent` and `tools` are what the channel
154
155
  // is attached to, and `toolsets` is the catalog behind `type: agentbook` files.
155
- export function checkChannels(channels, { agent = { body: "" }, tools = [], toolsets } = {}, errors = [], warnings = []) {
156
+ export function checkChannels(channels, { agent = { body: "" }, systemPrompt = [], tools = [], toolsets } = {}, errors = [], warnings = []) {
156
157
  const unasked = toolsThatRunUnasked(tools, toolsets);
157
158
  const identities = new Map();
158
159
  // Where each place in a `send_to` came from: only one bot can post there, so it's clear which one does.
@@ -188,7 +189,7 @@ export function checkChannels(channels, { agent = { body: "" }, tools = [], tool
188
189
  else if (!SHARED_FIELDS.includes(key) && !Object.hasOwn(type.fields, key)) err(`unknown field \`${key}\``);
189
190
  }
190
191
 
191
- if (channelSystem(agent, channel).length > MAX_SYSTEM_PROMPT) {
192
+ if (channelSystem({ agent, systemPrompt }, channel).length > MAX_SYSTEM_PROMPT) {
192
193
  err(`with ${AGENT_FILE}'s system prompt, this comes to more than ${MAX_SYSTEM_PROMPT.toLocaleString("en-US")} characters; the limit is the API's`);
193
194
  }
194
195
 
@@ -331,4 +332,7 @@ export function channelSettings({ data }) {
331
332
 
332
333
  // The system prompt for a conversation on this channel: the agent's, then the channel's own instructions.
333
334
  // A session can override `system` for itself, so a channel doesn't need its own copy of the agent.
334
- export const channelSystem = (agent, channel) => [agent.body, channel.body].filter(Boolean).join("\n\n");
335
+ // `instance` is what checkFiles returns, so the agent's prompt includes system_prompt/. An agent alone,
336
+ // as before, still works, with only agent.md's body.
337
+ export const channelSystem = (instance, channel) =>
338
+ [instance.agent ? systemPromptOf(instance) : instance.body, channel.body].filter(Boolean).join("\n\n");
package/lib/check.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { checkChannels, readChannels } from "./channels.js";
2
2
  import { textOf } from "./files.js";
3
- import { AGENT_FILE, ENV_FILE, readInstance } from "./instance.js";
3
+ import { AGENT_FILE, readInstance } from "./instance.js";
4
4
  import { checkScheduled, readScheduled } from "./scheduled.js";
5
+ import { SYSTEM_PROMPT_DIR, readSystemPrompt, systemPromptOf } from "./system-prompt.js";
5
6
  import { MAX_UPLOAD_BYTES, SKILLS_DIR, readSkills } from "./skills.js";
6
7
  import { MCP_TOOLSET, TOOLS_DIR, checkTools, readTools } from "./tools.js";
7
8
  import { CREDENTIAL_TYPES, ENV_VAR, SECRET_FIELDS, TOKEN_ENDPOINT_AUTH, VAULT_FILE, get, readVaults } from "./vaults.js";
@@ -30,16 +31,17 @@ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v)
30
31
  // `options` is what checkTools takes: { customTools, toolsets }.
31
32
  // Returns { errors, warnings, instance }; instance is null when the files can't be read.
32
33
  export function checkFiles(files, options = {}) {
33
- const { agent, env, errors } = readInstance(files);
34
+ const { agent, env, errors, warnings } = readInstance(files);
34
35
  const { tools, errors: toolErrors } = readTools(files);
35
36
  const { vaults, errors: vaultErrors } = readVaults(files);
36
37
  const { skills, errors: skillErrors } = readSkills(files);
37
38
  const { channels, errors: channelErrors } = readChannels(files);
38
39
  const { tasks: scheduled, errors: scheduledErrors } = readScheduled(files);
39
- errors.push(...toolErrors, ...vaultErrors, ...skillErrors, ...channelErrors, ...scheduledErrors);
40
- const warnings = [];
40
+ const { parts: systemPrompt, errors: systemPromptErrors } = readSystemPrompt(files);
41
+ errors.push(...toolErrors, ...vaultErrors, ...skillErrors, ...channelErrors, ...scheduledErrors, ...systemPromptErrors);
41
42
 
42
43
  if (agent) checkAgent(agent, errors, warnings);
44
+ if (agent) checkSystemPromptLength({ agent, systemPrompt }, errors);
43
45
  if (env) checkEnv(env, errors, warnings);
44
46
  checkTools(tools, errors, warnings, options);
45
47
  if (agent) checkMcpServers(agent, tools, errors);
@@ -49,19 +51,30 @@ export function checkFiles(files, options = {}) {
49
51
  if (declaredSkills + skills.length > 500) errors.push(`${declaredSkills + skills.length} skills; the limit is 500`);
50
52
  for (const vault of vaults) checkVault(vault, errors, warnings);
51
53
  checkEnvVarCredentials(vaults, env, warnings);
52
- checkChannels(channels, { agent: agent ?? undefined, tools, toolsets: options.toolsets }, errors, warnings);
54
+ checkChannels(channels, { agent: agent ?? undefined, systemPrompt, tools, toolsets: options.toolsets }, errors, warnings);
53
55
  checkScheduled(scheduled, { tools }, errors, warnings);
54
56
 
55
57
  const vaultFiles = vaults.flatMap((v) => [...(v.file ? [[`${v.path}/${VAULT_FILE}`, v.file]] : []), ...v.credentials.map((c) => [c.file, c])]);
56
58
  const skillTexts = skills.flatMap((s) => s.files.map((f) => [`${s.path}/${f.rel}`, { raw: textOf(f.bytes) }]));
57
- for (const [file, parsed] of [[AGENT_FILE, agent], [ENV_FILE, env], ...tools.map((t) => [t.file, t]), ...vaultFiles, ...skillTexts, ...channels.map((c) => [c.file, c]), ...scheduled.map((t) => [t.file, t])]) {
59
+ for (const [file, parsed] of [[AGENT_FILE, agent], [env?.file, env], ...tools.map((t) => [t.file, t]), ...vaultFiles, ...skillTexts, ...channels.map((c) => [c.file, c]), ...scheduled.map((t) => [t.file, t]), ...systemPrompt.map((p) => [p.file, { raw: p.text }])]) {
58
60
  if (!parsed) continue;
59
61
  for (const [pattern, what] of SECRET_PATTERNS) {
60
62
  if (pattern.test(parsed.raw)) errors.push(`${file}: looks like it contains ${what}; keep secrets out of these files`);
61
63
  }
62
64
  }
63
65
 
64
- return { errors, warnings, instance: agent && env ? { agent, env, tools, vaults, skills, channels, scheduled } : null };
66
+ return { errors, warnings, instance: agent && env ? { agent, env, tools, vaults, skills, channels, scheduled, systemPrompt } : null };
67
+ }
68
+
69
+ const MAX_SYSTEM_PROMPT = 100_000;
70
+
71
+ // The system prompt is agent.md's body and system_prompt/'s files together, and the API's limit is on
72
+ // all of it.
73
+ function checkSystemPromptLength(instance, errors) {
74
+ const { length } = systemPromptOf(instance);
75
+ if (length <= MAX_SYSTEM_PROMPT) return;
76
+ const where = instance.systemPrompt.length > 0 ? `${AGENT_FILE} and ${SYSTEM_PROMPT_DIR}/` : AGENT_FILE;
77
+ errors.push(`${where}: the system prompt is ${length.toLocaleString("en-US")} characters; the limit is ${MAX_SYSTEM_PROMPT.toLocaleString("en-US")}`);
65
78
  }
66
79
 
67
80
  function checkAgent({ data, body }, errors, warnings) {
@@ -76,7 +89,6 @@ function checkAgent({ data, body }, errors, warnings) {
76
89
  }
77
90
 
78
91
  if ("system" in data) err("`system` is not allowed in frontmatter; the Markdown body is the system prompt");
79
- if (body.length > 100_000) err(`system prompt is ${body.length} characters; the limit is 100,000`);
80
92
 
81
93
  if (data.description !== undefined && data.description !== null) {
82
94
  if (typeof data.description !== "string") err("`description` must be a string");
@@ -104,8 +116,8 @@ function checkAgent({ data, body }, errors, warnings) {
104
116
  }
105
117
  }
106
118
 
107
- function checkEnv({ data }, errors, warnings) {
108
- const err = (msg) => errors.push(`${ENV_FILE}: ${msg}`);
119
+ function checkEnv({ data, file }, errors, warnings) {
120
+ const err = (msg) => errors.push(`${file}: ${msg}`);
109
121
 
110
122
  if (typeof data.name !== "string" || data.name.trim() === "") err("`name` is required");
111
123
 
@@ -128,7 +140,7 @@ function checkEnv({ data }, errors, warnings) {
128
140
  checkMetadata(data.metadata, Infinity, err);
129
141
 
130
142
  for (const key of Object.keys(data)) {
131
- if (!ENV_FIELDS.has(key)) warnings.push(`${ENV_FILE}: unknown field \`${key}\` will be sent to the API as written`);
143
+ if (!ENV_FIELDS.has(key)) warnings.push(`${file}: unknown field \`${key}\` will be sent to the API as written`);
132
144
  }
133
145
  }
134
146
 
@@ -214,7 +226,7 @@ function checkMcpNetworking(agent, env, warnings) {
214
226
  }
215
227
  if (!allowed.includes(host)) {
216
228
  warnings.push(
217
- `${ENV_FILE}: its limited networking doesn't allow MCP server \`${server.name}\` (${host}), so sessions won't start; ` +
229
+ `${env.file}: its limited networking doesn't allow MCP server \`${server.name}\` (${host}), so sessions won't start; ` +
218
230
  `set config.networking.allow_mcp_servers to true, or add ${host} to allowed_hosts`,
219
231
  );
220
232
  }
@@ -274,7 +286,7 @@ function checkEnvVarCredentials(vaults, env, warnings) {
274
286
  if (net?.type === "limited" && networking?.type === "limited" && Array.isArray(networking.allowed_hosts)) {
275
287
  for (const host of networking.allowed_hosts) {
276
288
  if (!(net.allowed_hosts ?? []).includes(host)) {
277
- warn(`${ENV_FILE}'s limited networking doesn't allow ${host}, so requests to it will be blocked; add it to allowed_hosts in ${ENV_FILE}`);
289
+ warn(`${env.file}'s limited networking doesn't allow ${host}, so requests to it will be blocked; add it to allowed_hosts in ${env.file}`);
278
290
  }
279
291
  }
280
292
  }
package/lib/index.js CHANGED
@@ -3,10 +3,13 @@
3
3
  export { ANYONE, CHANNELS_DIR, CHANNEL_TYPES, channelSettings, channelSystem, durationMs, readChannels } from "./channels.js";
4
4
  export { checkFiles } from "./check.js";
5
5
  export { bytesOf, isIgnoredPath, pathsUnder, textOf } from "./files.js";
6
- export { AGENT_FILE, ENV_FILE, agentBody, envBody, readInstance } from "./instance.js";
6
+ export {
7
+ AGENT_FILE, COMPUTER_FILE, ENVIRONMENT_KEY, OLD_COMPUTER_FILE, agentBody, envBody, environmentEntry, readInstance, upgradeLock,
8
+ } from "./instance.js";
7
9
  export { FileError, editFrontmatter, parseMarkdown } from "./markdown.js";
8
10
  export { MODELS, NETWORKING, builtInFile, defaultAnswers, scaffold } from "./scaffold.js";
9
11
  export { SCHEDULED_DIR, cronProblem, isTimeZone, readScheduled, taskBody, taskKey, taskSettings } from "./scheduled.js";
12
+ export { SYSTEM_PROMPT_DIR, readSystemPrompt, systemPromptOf } from "./system-prompt.js";
10
13
  export { MAX_UPLOAD_BYTES, SKILLS_DIR, SKILL_FILE, readSkills, skillKey, skillRefs } from "./skills.js";
11
14
  export { agentMessageText, textStream } from "./stream.js";
12
15
  export {
package/lib/instance.js CHANGED
@@ -1,15 +1,20 @@
1
1
  import { textOf } from "./files.js";
2
2
  import { FileError, parseMarkdown } from "./markdown.js";
3
+ import { systemPromptOf } from "./system-prompt.js";
3
4
  import { compileTools } from "./tools.js";
4
5
 
5
6
  export const AGENT_FILE = "agent.md";
6
- export const ENV_FILE = "env.md";
7
+ export const COMPUTER_FILE = "computer.md";
8
+ // computer.md's old name. A folder that still has it works, with a warning to rename it.
9
+ export const OLD_COMPUTER_FILE = "env.md";
7
10
 
8
- // Reads agent.md and env.md. Returns { agent, env, errors }; a file that can't be read is null
9
- // and has an entry in errors.
11
+ // Reads agent.md and computer.md. Returns { agent, env, errors, warnings }; a file that can't be
12
+ // read is null and has an entry in errors. `env` is computer.md, the agent's environment, and its
13
+ // `file` says which name it was read from.
10
14
  export function readInstance(files) {
11
15
  const names = Object.keys(files).filter((path) => !path.includes("/"));
12
16
  const errors = [];
17
+ const warnings = [];
13
18
  const read = (name) => {
14
19
  try {
15
20
  // Exact names only, so an agent behaves the same on a case-sensitive file system.
@@ -25,20 +30,46 @@ export function readInstance(files) {
25
30
  return null;
26
31
  }
27
32
  };
28
- return { agent: read(AGENT_FILE), env: read(ENV_FILE), errors };
33
+ const agent = read(AGENT_FILE);
34
+ const hasOldName = names.includes(OLD_COMPUTER_FILE);
35
+ const computerFile = hasOldName && !names.includes(COMPUTER_FILE) ? OLD_COMPUTER_FILE : COMPUTER_FILE;
36
+ if (computerFile === OLD_COMPUTER_FILE) warnings.push(`${OLD_COMPUTER_FILE}: this is ${COMPUTER_FILE}'s old name; rename it to ${COMPUTER_FILE}`);
37
+ else if (hasOldName) errors.push(`${OLD_COMPUTER_FILE}: this is ${COMPUTER_FILE}'s old name, and the folder has both; remove ${OLD_COMPUTER_FILE}`);
38
+ const env = read(computerFile);
39
+ return { agent, env: env && { ...env, file: computerFile }, errors, warnings };
29
40
  }
30
41
 
31
42
  // The bodies sent to POST /v1/agents and POST /v1/environments.
32
43
  // The agent's tools come from tools/, compiled into the API's `tools` list. `skills` are the
33
- // references to the skills deployed from skills/, added to any in agent.md's frontmatter.
44
+ // references to the skills deployed from skills/, added to any in agent.md's frontmatter. The system
45
+ // prompt is agent.md's body, then system_prompt/'s files.
34
46
  // `options.toolsets` is the catalog behind `type: agentbook` tool files.
35
- export function agentBody({ agent, tools }, skills = [], options = {}) {
47
+ export function agentBody(instance, skills = [], options = {}) {
48
+ const { agent, tools } = instance;
36
49
  const body = { ...agent.data, tools: compileTools(tools, options) };
37
50
  if (skills.length > 0) body.skills = [...(agent.data.skills ?? []), ...skills];
38
- if (agent.body) body.system = agent.body;
51
+ const system = systemPromptOf(instance);
52
+ if (system) body.system = system;
39
53
  return body;
40
54
  }
41
55
 
42
56
  export function envBody({ env }) {
43
57
  return { ...env.data };
44
58
  }
59
+
60
+ // The lock's entry for the environment is under "./computer.md". A lock written before computer.md
61
+ // was renamed has it under "./env.md": environmentEntry finds it either way, and upgradeLock moves
62
+ // it, so the next deploy updates that environment rather than making another.
63
+ export const ENVIRONMENT_KEY = `./${COMPUTER_FILE}`;
64
+ const OLD_ENVIRONMENT_KEY = `./${OLD_COMPUTER_FILE}`;
65
+
66
+ export const environmentEntry = (lock) => lock?.resources?.[ENVIRONMENT_KEY] ?? lock?.resources?.[OLD_ENVIRONMENT_KEY];
67
+
68
+ export function upgradeLock(lock) {
69
+ const resources = lock?.resources;
70
+ if (resources?.[OLD_ENVIRONMENT_KEY] && !resources[ENVIRONMENT_KEY]) {
71
+ resources[ENVIRONMENT_KEY] = resources[OLD_ENVIRONMENT_KEY];
72
+ delete resources[OLD_ENVIRONMENT_KEY];
73
+ }
74
+ return lock;
75
+ }
package/lib/scaffold.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { stringify } from "yaml";
2
- import { AGENT_FILE, ENV_FILE } from "./instance.js";
2
+ import { AGENT_FILE, COMPUTER_FILE } from "./instance.js";
3
3
  import { PREBUILT_TOOLS, TOOLSET, TOOLSET_FILE, TOOLS_DIR } from "./tools.js";
4
4
 
5
5
  export const MODELS = ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
@@ -34,7 +34,7 @@ export function scaffold(answers) {
34
34
  : answers.packageManagers ? "limited networking and package manager access" : "limited networking";
35
35
  const files = {
36
36
  [AGENT_FILE]: `---\n${stringify(agent)}---\n\n${answers.system.trim()}\n`,
37
- [ENV_FILE]: `---\n${stringify(env)}---\nCloud container with ${access}.\n`,
37
+ [COMPUTER_FILE]: `---\n${stringify(env)}---\nCloud container with ${access}.\n`,
38
38
  };
39
39
  if (answers.tools) {
40
40
  files[`${TOOLS_DIR}/${TOOLSET_FILE}`] = builtInFile(PREBUILT_TOOLS, PREBUILT_TOOLS, answers.permission);
@@ -0,0 +1,32 @@
1
+ import { pathsUnder, textOf } from "./files.js";
2
+
3
+ // A long system prompt can be split into files in system_prompt/, which go after agent.md's body. Every
4
+ // file in the folder counts, at any depth, in the order `tree` lists them, so the folder reads top to
5
+ // bottom the way the prompt does: each folder's entries sorted by name, character by character, with a
6
+ // folder's files right where the folder sorts. Each file is taken as written, with no frontmatter.
7
+ export const SYSTEM_PROMPT_DIR = "system_prompt";
8
+
9
+ // Text that came from something other than a text file: decoding bytes that aren't UTF-8 leaves
10
+ // replacement characters, and binary files have NULs.
11
+ const isBinary = (text) => text.includes("\uFFFD") || text.includes("\u0000");
12
+
13
+ // Reads system_prompt/. Returns { parts, errors }, where each part is { file, text } in tree order.
14
+ // No system_prompt/ folder means no parts.
15
+ export function readSystemPrompt(files) {
16
+ if (SYSTEM_PROMPT_DIR in files) return { parts: [], errors: [`${SYSTEM_PROMPT_DIR}: not a directory`] };
17
+ const parts = [];
18
+ const errors = [];
19
+ // pathsUnder already lists them in tree's order.
20
+ for (const file of pathsUnder(files, SYSTEM_PROMPT_DIR)) {
21
+ const text = textOf(files[file]);
22
+ if (isBinary(text)) errors.push(`${file}: isn't a text file, so it can't be part of the system prompt`);
23
+ else parts.push({ file, text });
24
+ }
25
+ return { parts, errors };
26
+ }
27
+
28
+ // The whole system prompt: agent.md's body, then each file in system_prompt/, with a blank line between
29
+ // them. Empty files add nothing.
30
+ export function systemPromptOf({ agent, systemPrompt = [] }) {
31
+ return [agent?.body ?? "", ...systemPrompt.map((part) => part.text.trim())].filter(Boolean).join("\n\n");
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soft-boy/agentschema",
3
- "version": "0.3.11",
3
+ "version": "0.4.0",
4
4
  "description": "Markdown based AI agent schema",
5
5
  "type": "module",
6
6
  "bin": {
package/src/deploy.js CHANGED
@@ -2,7 +2,7 @@ import { join } from "node:path";
2
2
  import Anthropic, { toFile } from "@anthropic-ai/sdk";
3
3
  import { CHANNELS_DIR, readChannels } from "../lib/channels.js";
4
4
  import { checkFiles } from "../lib/check.js";
5
- import { AGENT_FILE, ENV_FILE, agentBody, envBody } from "../lib/instance.js";
5
+ import { AGENT_FILE, ENVIRONMENT_KEY, agentBody, envBody, environmentEntry, upgradeLock } from "../lib/instance.js";
6
6
  import { taskBody, taskKey, taskSettings } from "../lib/scheduled.js";
7
7
  import { skillKey, skillRefs } from "../lib/skills.js";
8
8
  import { AGENTBOOK } from "../lib/tools.js";
@@ -68,11 +68,10 @@ export async function deployFiles({
68
68
  });
69
69
 
70
70
  const steps = [
71
- { file: ENV_FILE, kind: "environment", body: envBody(instance) },
72
- { file: AGENT_FILE, kind: "agent", body: agentBody(instance, refs, checkOptions) },
71
+ { file: instance.env.file, key: ENVIRONMENT_KEY, kind: "environment", body: envBody(instance) },
72
+ { file: AGENT_FILE, key: `./${AGENT_FILE}`, kind: "agent", body: agentBody(instance, refs, checkOptions) },
73
73
  ];
74
74
  for (const step of steps) {
75
- step.key = `./${step.file}`;
76
75
  step.hash = hashBody(step.body);
77
76
  step.entry = lock.resources[step.key];
78
77
  if (step.entry && step.entry.kind !== step.kind) {
@@ -122,7 +121,7 @@ export async function deployFiles({
122
121
  // deployment archived, because a schedule left behind would keep running, and costing money.
123
122
  async function deployScheduled(instance, { client, lock, dryRun, log, saveLock, pendingAgent, pendingVaults }) {
124
123
  const agentEntry = lock.resources[`./${AGENT_FILE}`];
125
- const envEntry = lock.resources[`./${ENV_FILE}`];
124
+ const envEntry = environmentEntry(lock);
126
125
  const agent = { type: "agent", id: agentEntry?.id ?? "pending", version: pendingAgent || !agentEntry ? "pending" : Number(agentEntry.version) };
127
126
  const vaultIds = instance.vaults.map((vault) => lock.resources[vaultKey(vault)]?.id ?? (pendingVaults.includes(vaultKey(vault)) ? `pending:${vault.path}` : null)).filter(Boolean);
128
127
 
@@ -222,6 +221,7 @@ export function prepareLock(previous, client) {
222
221
  const baseURL = client.baseURL;
223
222
  const lock = previous ?? { version: 1, origin: { base_url: baseURL }, resources: {} };
224
223
  lock.resources ??= {};
224
+ upgradeLock(lock);
225
225
  if (lock.origin?.base_url && lock.origin.base_url !== baseURL) {
226
226
  throw new DeployError(
227
227
  `${LOCK_FILE} was written for ${lock.origin.base_url}, but this client uses ${baseURL}`,
package/src/folder.js CHANGED
@@ -2,14 +2,15 @@ import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { CHANNELS_DIR } from "../lib/channels.js";
4
4
  import { editFrontmatter } from "../lib/markdown.js";
5
- import { AGENT_FILE, ENV_FILE } from "../lib/instance.js";
5
+ import { AGENT_FILE, COMPUTER_FILE, OLD_COMPUTER_FILE } from "../lib/instance.js";
6
6
  import { SCHEDULED_DIR } from "../lib/scheduled.js";
7
7
  import { SKILLS_DIR } from "../lib/skills.js";
8
+ import { SYSTEM_PROMPT_DIR } from "../lib/system-prompt.js";
8
9
  import { TOOLS_DIR } from "../lib/tools.js";
9
10
  import { VAULTS_DIR } from "../lib/vaults.js";
10
11
 
11
- const FOLDERS = [TOOLS_DIR, SKILLS_DIR, VAULTS_DIR, CHANNELS_DIR, SCHEDULED_DIR];
12
- const TOP_LEVEL_FILES = [AGENT_FILE, ENV_FILE];
12
+ const FOLDERS = [TOOLS_DIR, SKILLS_DIR, VAULTS_DIR, CHANNELS_DIR, SCHEDULED_DIR, SYSTEM_PROMPT_DIR];
13
+ const TOP_LEVEL_FILES = [AGENT_FILE, COMPUTER_FILE, OLD_COMPUTER_FILE];
13
14
 
14
15
  // Why `dir` can't be read as an agent folder, or null when it can.
15
16
  export function folderProblem(dir) {
package/src/init.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
2
2
  import { basename, dirname, resolve } from "node:path";
3
- import { AGENT_FILE, ENV_FILE } from "../lib/instance.js";
3
+ import { AGENT_FILE, COMPUTER_FILE } from "../lib/instance.js";
4
4
  import { MODELS, NETWORKING, defaultAnswers, scaffold } from "../lib/scaffold.js";
5
5
  import { TOOLSET_FILE, TOOLS_DIR } from "../lib/tools.js";
6
6
  import { choosePermission } from "./tools-menu.js";
@@ -27,7 +27,7 @@ export async function init(dir, { yes = false, input = process.stdin, output = p
27
27
  }
28
28
 
29
29
  const tools = answers.tools ? `, and ${dir}/${TOOLS_DIR}/${TOOLSET_FILE} with the pre-built tools (set Enabled to false to turn one off)` : "";
30
- output.write(`\nCreated ${dir}/${AGENT_FILE} and ${dir}/${ENV_FILE}${tools}.\n\nNext:\n`);
30
+ output.write(`\nCreated ${dir}/${AGENT_FILE} and ${dir}/${COMPUTER_FILE}${tools}.\n\nNext:\n`);
31
31
  output.write(` agentschema deploy ${dir}\n agentschema run ${dir}\n`);
32
32
  return files;
33
33
  }
package/src/session.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { join } from "node:path";
2
- import { AGENT_FILE, ENV_FILE, agentBody, envBody } from "../lib/instance.js";
2
+ import { AGENT_FILE, agentBody, envBody, environmentEntry } from "../lib/instance.js";
3
+ import { SYSTEM_PROMPT_DIR } from "../lib/system-prompt.js";
3
4
  import { skillKey, skillRefs } from "../lib/skills.js";
4
5
  import { TOOLS_DIR } from "../lib/tools.js";
5
6
  import { credentialKey, vaultKey } from "../lib/vaults.js";
@@ -19,7 +20,7 @@ export async function openSession(dir, { client, sessionId }) {
19
20
 
20
21
  const lock = readLock(dir);
21
22
  const agent = lock?.resources?.[`./${AGENT_FILE}`];
22
- const env = lock?.resources?.[`./${ENV_FILE}`];
23
+ const env = environmentEntry(lock);
23
24
  if (!agent || !env) {
24
25
  throw new SessionError(`${dir} hasn't been deployed (no agent or environment in ${LOCK_FILE}); run agentschema deploy first`);
25
26
  }
@@ -28,12 +29,12 @@ export async function openSession(dir, { client, sessionId }) {
28
29
  const { instance, errors } = check(dir);
29
30
  if (instance && errors.length === 0) {
30
31
  if (hashBody(agentBody(instance, skillRefs(instance.skills, lock))) !== agent.hash) {
31
- notes.push(`${AGENT_FILE} or ${TOOLS_DIR}/ has changed since the last deploy`);
32
+ notes.push(`${AGENT_FILE}, ${SYSTEM_PROMPT_DIR}/ or ${TOOLS_DIR}/ has changed since the last deploy`);
32
33
  }
33
34
  for (const skill of instance.skills) {
34
35
  if (hashBody(skillFingerprint(skill)) !== lock.resources[skillKey(skill)]?.hash) notes.push(`${skill.path} has changed since the last deploy`);
35
36
  }
36
- if (hashBody(envBody(instance)) !== env.hash) notes.push(`${ENV_FILE} has changed since the last deploy`);
37
+ if (hashBody(envBody(instance)) !== env.hash) notes.push(`${instance.env.file} has changed since the last deploy`);
37
38
  if (notes.length > 0) notes.push(`this session uses the deployed version; run agentschema deploy to pick up the changes`);
38
39
  }
39
40
 
@@ -59,7 +60,7 @@ export async function openSession(dir, { client, sessionId }) {
59
60
  // Returns { session, notes }.
60
61
  export async function startSession({ instance, lock, client, agentVersion, system, title, budget, pathOf = (file) => file }) {
61
62
  const agent = lock?.resources?.[`./${AGENT_FILE}`];
62
- const env = lock?.resources?.[`./${ENV_FILE}`];
63
+ const env = environmentEntry(lock);
63
64
  if (!agent || !env) throw new SessionError("this agent hasn't been deployed (no agent or environment in its lock)");
64
65
 
65
66
  const pinned = { id: agent.id, version: Number(agentVersion ?? agent.version) };
package/src/tools-menu.js CHANGED
@@ -4,7 +4,7 @@ import { stringify } from "yaml";
4
4
  import { check } from "./check.js";
5
5
  import { serviceName } from "./cred-menu.js";
6
6
  import { DeployError } from "./deploy.js";
7
- import { AGENT_FILE, ENV_FILE } from "../lib/instance.js";
7
+ 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";
@@ -38,7 +38,7 @@ export async function toolsCreate(dir = ".", { io, fetch = globalThis.fetch, log
38
38
  }
39
39
 
40
40
  const after = check(dir);
41
- const related = (m) => m.startsWith(path) || (kind === MCP && (m.startsWith(AGENT_FILE) || m.startsWith(ENV_FILE)));
41
+ const related = (m) => m.startsWith(path) || (kind === MCP && [AGENT_FILE, COMPUTER_FILE, OLD_COMPUTER_FILE].some((file) => m.startsWith(file)));
42
42
  for (const w of after.warnings.filter(related)) log(`warning: ${w}`);
43
43
  for (const e of after.errors.filter(related)) log(`error: ${e}`);
44
44
  if (kind === CUSTOM) log(`\nWrite the tool's code in its ## Code block, then deploy with:\n agentschema deploy ${dir}`);