@operad-io/bot 0.0.1 → 0.1.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/README.md CHANGED
@@ -1,160 +1,13 @@
1
- # `@operad-io/bot`
1
+ # @operad-io/bot
2
2
 
3
- The `bot` plugin. Its object is a **bot**: a working directory, a default
4
- agent, skills, a speaker and an access profile. A bot is one row in lists and
5
- the parent of its chats. The chat itself belongs to the `chat` plugin.
3
+ **The bot plugin.** A bot is a working directory, a default agent, skills, a speaker and an access profile. It is the parent of its chats. Optional: turn it on with `operad plugin enable bot`.
6
4
 
7
- Optional: `operad plugin enable bot`.
5
+ This package is part of [operad](https://github.com/operad-io/operad). Most people install only [`@operad-io/cli`](https://www.npmjs.com/package/@operad-io/cli).
8
6
 
9
- ## Settings
7
+ ## Documentation
10
8
 
11
- The `bot` section of `config.json` (`plugins.bot.settings`), checked against
12
- `bot.schema.json` and editable through the settings interface:
9
+ - User guide: [docs/user/chats-and-bots.md](https://github.com/operad-io/operad/blob/main/docs/user/chats-and-bots.md)
10
+ - Website: <https://operad.io>
11
+ - Developer reference: `REFERENCE.md` in this directory
13
12
 
14
- ```json
15
- { "bots": { "reader": { "harness": "pi", "speaker": "Nova", "skills": ["~/skills/brain"], "access": { "readOnly": true } } } }
16
- ```
17
-
18
- `default` exists even when it is not written. A bot name is lowercase letters,
19
- digits, `-` and `_`. Fields: `cwd`, `harness` (the default agent), `skills`,
20
- `speaker`, `access`.
21
-
22
- - **Working directory**: `~/.operad/bot/` for `default`, `~/.operad/bot/<name>`
23
- for another bot, created when missing. A `cwd` that is the operad home, holds
24
- it, or is inside it outside `bot/` is refused: the chat works in a
25
- subdirectory, never the home.
26
- - **Access profile**: the default one (no credentials, no shell profile writes, no
27
- `operad` command; the agent uses operad's tools) plus what the bot adds. A bot
28
- can tighten it, never loosen it. Everything in the operad home except `bot/` is
29
- in `denyPaths` (what is there now, and `store`, `secrets`, `config.json`), so
30
- the fact log, secrets and the token are out of reach. The bot's skill
31
- directories, and `<cwd>/skills`, are in `denyPaths` too: the agent proposes a
32
- skill through operad's tools and never writes one itself.
33
- - **Skills**: directories with a `SKILL.md`, given to the agent as `skills` in
34
- its step params. A missing `SKILL.md` fails the reply and names the directory.
35
- - **Speaker**: how a chat of this bot labels the model's messages in its
36
- transcript; without it, the chat plugin's `speaker` is used.
37
-
38
- ## `bot:chat <bot> [--agent <name>] [--model <name>] [--effort <level>] [--title <text>]`
39
-
40
- Creates a `chat` with the bot as parent, titled `Bot (<name>)` unless given a
41
- title. The agent is the one given, else the bot's, else the first loaded one;
42
- it is fixed once chosen. The model and effort are the ones given, else the
43
- bot's own, else the agent's default; each must be one the agent lists and can
44
- change later. The chat reaches repositories only through operad's
45
- tools (`operadTools`) and `dev`'s verbs, never by editing their files: the paths
46
- of the repositories `dev` knows are in `denyPaths` (read again at every reply, so
47
- a repository added later is covered), its directory is not a repository and
48
- `operad` is a denied command.
49
-
50
- At every reply the chat runs the step `bot/settings`, which reads `config.json`
51
- again: tightening access or adding a skill applies to the next reply of the same
52
- chat. A bot taken out of the settings, or one that cannot be used, fails the
53
- reply; it is never answered from an older copy.
54
-
55
- ## A bot changes itself only through a proposal
56
-
57
- A bot does not write its skills or `config.json`. Its access profile denies
58
- those paths, so a direct write is refused like any other denied path. It asks
59
- for the change through operad's own tools instead. An agent with operad's MCP
60
- tools calls the `command` tool:
61
-
62
- ```json
63
- { "plugin": "bot", "verb": "skill", "args": ["default", "brain"],
64
- "input": "{\"skill_md\": \"---\\nname: brain\\n---\\n...\", \"files\": {\"scripts/save.sh\": \"...\"}}" }
65
- ```
66
-
67
- `bot skill <bot> <name> [--from <dir>]` proposes a new or changed skill. Without
68
- `--from`, its stdin is JSON with `skill_md` and an optional `files` map; with
69
- `--from`, it reads that directory. A changed skill is the one the bot already
70
- mounts under that name; a new one goes to `<cwd>/skills/<name>` when approved.
71
- Files under `scripts/`, and executable files, are listed as scripts.
72
-
73
- `bot setting <bot>` proposes a change to the bot's settings. Its stdin is a JSON
74
- object with the fields to change (`speaker`, `harness`, `skills`, `access`, and
75
- so on); the fields it does not name keep their value. The kernel validates the
76
- result against `bot.schema.json` before the proposal exists.
77
-
78
- Each proposal is one pending item of its bot, with the actions `Review`,
79
- `approve` and `reject`. `Review` shows the change: the full `SKILL.md`, the file
80
- list with scripts apart and, for a changed skill, the diff; a settings proposal
81
- shows the settings before and after. `approve` applies the change and `reject`
82
- leaves every file and setting as it was. Nothing changes until the person acts,
83
- and an unanswered proposal neither changes anything nor blocks the chat.
84
-
85
- An approved skill is on disk before the approval returns, so the bot's next
86
- reply reads it (`bot/settings` already reads `config.json` again at every
87
- reply). A settings proposal is written to `config.json` the same way. A run
88
- nobody started on the spot, such as a scheduled or event-started run, can make
89
- the same proposals; it still cannot approve one.
90
-
91
- ## Telegram
92
-
93
- Chats bound from Telegram are not built here. When they are, they open with
94
- `openChat` on `default`; a rule that names another bot goes in the same place.
95
-
96
- ## MCP servers
97
-
98
- A bot can use local MCP servers: a command with arguments, started on this
99
- machine. Remote servers (an HTTPS address) are not supported yet. operad talks
100
- to no marketplace and does no search; you bring the command.
101
-
102
- `bot mcp <bot> <name> <command> [args...]` proposes a server. With no command,
103
- stdin is a pasted `mcpServers` entry of the same form (a whole `mcpServers` map
104
- works when it holds one server or one called `<name>`):
105
-
106
- ```
107
- operad bot mcp default notes npx -y @acme/notes-mcp@1.2.3
108
- echo '{"mcpServers":{"notes":{"command":"npx","args":["-y","@acme/notes-mcp@1.2.3"],"env":{"TOKEN":"…"}}}}' | operad bot mcp default notes
109
- ```
110
-
111
- An agent with operad's MCP tools calls the `command` tool the same way as for
112
- a skill. Registering is a pending item of the bot, never applied without a
113
- person (`Review`, `approve`, `reject`). `Review` lists the command, the package
114
- and its pinned version, the tools the server offers (name and description) and
115
- the secrets it needs, and says that **approving trusts the package**: it runs on
116
- your machine as you and nothing contains it yet (there is no shell). The tools
117
- are read by starting the server once, in the bot's working directory with a bare
118
- environment (`PATH`, `HOME`, `TMPDIR`, `LANG`) and the bot's access profile
119
- applied to the command; a server that does not start is not proposed.
120
-
121
- - **Pinned versions only.** A package runner (`npx`, `bunx`, `pnpm dlx`, `uvx`,
122
- …) must name an exact version, `name@1.2.3`. `@latest`, a tag, a range
123
- (`^1.2.0`, `1.x`) or no version is refused with a message saying to pin it, and
124
- the server is not started. A command that is not a package runner (a program
125
- or script you already have) has no version to pin.
126
- - **Upgrades.** Registering the same name again is its own pending item, showing
127
- the version and the tool-list change (added, removed and changed tools).
128
- - **Settings.** On `approve` the server is written to the bot's `mcpServers`
129
- setting (`command`, `args`, `package`, `version`, `secrets`, `tools`, `digest`;
130
- see `bot.schema.json`). The digest is of tool names and descriptions. `bot
131
- setting` cannot add or edit `mcpServers`; only this review can.
132
- - **Secrets.** The names of the environment variables a server needs are kept
133
- (from the `env` keys of a pasted entry); the values never are. A value pasted
134
- with the entry is used once, to start the server for the tool list, and then
135
- dropped. Store each value with `operad secret set bot <name>.<VARIABLE>`. The
136
- value reaches the server only at its start, from the bot plugin's secrets, in
137
- the server's environment: not in the transcript, not in the agent's
138
- environment, not in the settings the harness is given.
139
- - **What a chat mounts.** Only the servers in the bot's `mcpServers`, and only
140
- on the harnesses that take MCP servers natively: `claude` and `radian`. A chat
141
- on `pi` does not mount them, and the bot's page says so rather than leaving it
142
- silent. Each server is started through a guard (`src/guard.ts`) that the
143
- harness runs in its place; the guard starts the real server and holds its
144
- secrets.
145
- - **A server whose tools change is switched off.** Each time a chat starts a
146
- server, and each time the agent asks for its tool list, the guard compares the
147
- tool names and descriptions with the stored digest. If one differs, the guard
148
- offers no tools for that server, refuses calls to it, and leaves a report;
149
- the bot plugin turns the report into a pending item that shows the difference
150
- (`+` added, `-` removed, `~` changed with before and after). The chat goes on
151
- without the server. `approve` accepts the new tools and switches it on;
152
- `reject` keeps it off, and the same list is not proposed again.
153
- - **Tool results are material.** The text a tool returns is passed to the agent
154
- after a line saying it is material from an MCP server, not instructions.
155
- - **Calling a tool asks.** The bot's access profile carries `allowMcp`, the tools
156
- that run without asking (`<server>.<tool>` or `<server>.*`), set from the bot's
157
- `mcpAllow` setting (changed with `bot setting`, so a person approves it). A tool
158
- not listed counts as a write and asks first, as one-time or always-allow
159
- permission like any other call. `radian` cannot ask, so it refuses a tool that
160
- is not listed.
13
+ MIT licensed.
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@operad-io/bot",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
7
7
  },
8
8
  "dependencies": {
9
- "@operad-io/chat": "0.0.1",
10
- "@operad-io/engine": "0.0.1",
11
- "@operad-io/access-match": "0.0.1"
9
+ "@operad-io/chat": "0.1.0",
10
+ "@operad-io/engine": "0.1.0",
11
+ "@operad-io/access-match": "0.1.0"
12
12
  },
13
- "description": "operad: the bot plugin (in development)",
13
+ "description": "operad: the bot plugin",
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git+https://github.com/operad-io/operad.git",
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * built yet, and this is the one place it goes.
10
10
  */
11
11
 
12
+ import pkg from "../package.json" with { type: "json" };
12
13
  import { mkdirSync } from "node:fs";
13
14
  import { fileURLToPath } from "node:url";
14
15
  import { CHAT_TYPE, agentConditionals, type AgentChoices, chatData, createChat, sendMessage, startingEffort, startingModel, titleFromMessage } from "@operad-io/chat";
@@ -111,6 +112,8 @@ export interface OpenChat {
111
112
  readonly model?: string | undefined;
112
113
  readonly effort?: string | undefined;
113
114
  readonly title?: string | undefined;
115
+ /** The channels (`telegram:<chat>`) whose messages land in this chat. */
116
+ readonly channels?: readonly string[] | undefined;
114
117
  readonly cause: string;
115
118
  }
116
119
 
@@ -151,6 +154,7 @@ export async function openChat(input: OpenChat): Promise<string> {
151
154
  access: bot.access,
152
155
  skills: bot.skills,
153
156
  title: input.title ?? `Bot (${bot.name})`,
157
+ ...(input.channels === undefined ? {} : { channels: input.channels }),
154
158
  refresh: SETTINGS_STEP,
155
159
  },
156
160
  input.cause,
@@ -190,6 +194,12 @@ function chatArgs(
190
194
  "The effort the agent uses; one from that agent's list. The bot's effort, else the agent's default, when left out. It can be changed later.",
191
195
  },
192
196
  title: { type: "string", minLength: 1, maxLength: 120, description: "What the chat is called." },
197
+ channels: {
198
+ type: "array",
199
+ items: { type: "string", pattern: "^telegram:[^\\s]+$" },
200
+ description:
201
+ "The channels whose messages land in this chat, as telegram:<Telegram chat id>. A channel opens a chat with its own id here.",
202
+ },
193
203
  message: {
194
204
  type: "string",
195
205
  role: "note",
@@ -235,6 +245,7 @@ const chatAction: ActionTypeDefinition = {
235
245
  readonly model?: string;
236
246
  readonly effort?: string;
237
247
  readonly title?: string;
248
+ readonly channels?: readonly string[];
238
249
  readonly message?: string;
239
250
  };
240
251
  const id = await openChat({
@@ -249,6 +260,7 @@ const chatAction: ActionTypeDefinition = {
249
260
  model: input.model,
250
261
  effort: input.effort,
251
262
  title: input.title ?? (input.message === undefined ? undefined : titleFromMessage(input.message)),
263
+ channels: input.channels,
252
264
  cause: "action:bot/chat",
253
265
  });
254
266
  const sent = input.message === undefined ? undefined : await sendMessage(ctx, id, input.message);
@@ -329,8 +341,10 @@ export function createBotPlugin() {
329
341
  return definePlugin({
330
342
  name: "bot",
331
343
  kind: "domain",
332
- version: "0.0.0",
333
- requires: { plugins: { chat: "^0.0.0" } },
344
+ // The version comes from package.json so the two cannot drift apart.
345
+ version: pkg.version,
346
+ // Patch releases of chat only: a new minor may change what bot relies on.
347
+ requires: { plugins: { chat: "~0.1.0" } },
334
348
  settings: BOT_SETTINGS,
335
349
  // A bot page is that bot's settings page; bots live under settings, not in a tab.
336
350
  objectsUnderSettings: true,
package/src/mcp-client.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * mounts. It speaks newline-delimited JSON-RPC and nothing else of MCP.
5
5
  */
6
6
 
7
+ import pkg from "../package.json" with { type: "json" };
7
8
  import { spawn, type ChildProcess } from "node:child_process";
8
9
  import { createInterface } from "node:readline";
9
10
  import { isRecord, messageOf } from "@operad-io/engine";
@@ -147,7 +148,7 @@ export class StdioServer {
147
148
  const reply = await this.request("initialize", {
148
149
  protocolVersion: MCP_PROTOCOL_VERSION,
149
150
  capabilities: {},
150
- clientInfo: { name: client, version: "0.0.0" },
151
+ clientInfo: { name: client, version: pkg.version },
151
152
  });
152
153
  if ("result" in reply) this.send({ jsonrpc: "2.0", method: "notifications/initialized" });
153
154
  return reply;