pi-durable-bot 0.7.1 → 0.8.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/CHANGELOG.md +46 -0
- package/README.md +19 -11
- package/dist/agent/agent.js +160 -33
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/children.js +159 -26
- package/dist/agent/children.js.map +1 -1
- package/dist/agent/memory.js +12 -6
- package/dist/agent/memory.js.map +1 -1
- package/dist/agent/scopes.js +267 -0
- package/dist/agent/scopes.js.map +1 -0
- package/dist/agent/screen.js +37 -2
- package/dist/agent/screen.js.map +1 -1
- package/dist/bot/bot.js +65 -21
- package/dist/bot/bot.js.map +1 -1
- package/dist/bot/definition.js +25 -11
- package/dist/bot/definition.js.map +1 -1
- package/dist/bot/prompt.js +33 -13
- package/dist/bot/prompt.js.map +1 -1
- package/dist/cli/agent.js +1 -1
- package/dist/cli/agent.js.map +1 -1
- package/dist/cli/ai.js +92 -37
- package/dist/cli/ai.js.map +1 -1
- package/dist/cli/bots.js +69 -5
- package/dist/cli/bots.js.map +1 -1
- package/dist/cli/chat.js +59 -4
- package/dist/cli/chat.js.map +1 -1
- package/dist/cli/commands.js +23 -2
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/init.js +4 -18
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/login.js +20 -26
- package/dist/cli/login.js.map +1 -1
- package/dist/cli/pages.js +25 -6
- package/dist/cli/pages.js.map +1 -1
- package/dist/cli/service.js +30 -1
- package/dist/cli/service.js.map +1 -1
- package/dist/main.js +10 -0
- package/dist/main.js.map +1 -1
- package/dist/pages/desktop-page.js +293 -0
- package/dist/pages/desktop-page.js.map +1 -0
- package/dist/pages/desktop.js +672 -0
- package/dist/pages/desktop.js.map +1 -0
- package/dist/pages/host.js +55 -2
- package/dist/pages/host.js.map +1 -1
- package/dist/pages/rfb.js +389 -0
- package/dist/pages/rfb.js.map +1 -0
- package/dist/pages/server.js +172 -1
- package/dist/pages/server.js.map +1 -1
- package/dist/pages/store.js +26 -4
- package/dist/pages/store.js.map +1 -1
- package/docs/for-agents.md +27 -7
- package/kit/desktop/desktop.css +1010 -0
- package/kit/desktop/desktop.js +1421 -0
- package/kit/desktop/novnc/AUTHORS +13 -0
- package/kit/desktop/novnc/LICENSE.BSD-2-Clause +22 -0
- package/kit/desktop/novnc/LICENSE.BSD-3-Clause +24 -0
- package/kit/desktop/novnc/LICENSE.MPL-2.0 +373 -0
- package/kit/desktop/novnc/LICENSE.OFL-1.1 +91 -0
- package/kit/desktop/novnc/LICENSE.pako +21 -0
- package/kit/desktop/novnc/LICENSE.txt +62 -0
- package/kit/desktop/novnc.js +14404 -0
- package/package.json +5 -5
- package/skills/desktop-page/SKILL.md +153 -0
- package/skills/discord-channel/SKILL.md +4 -4
- package/skills/pages/SKILL.md +9 -4
- package/skills/slack-channel/SKILL.md +6 -5
- package/skills/telegram-channel/SKILL.md +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in each version of pi-durable-bot (Pots). To upgrade, run `npm install -g pi-durable-bot@latest`, then `pots service restart`.
|
|
4
4
|
|
|
5
|
+
## 0.8.0 (2026-11-15)
|
|
6
|
+
|
|
7
|
+
A person can take over the bot's screen from a link, on a phone or a computer, do one step, and hand it back. A second or third bot sets itself up as the first one does, and offers to set up a screen of its own. On Linux each command runs in a systemd scope of its own, so a command that runs out of memory no longer takes the gateway and every bot down with it, and what commands leave running stays across a restart.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **A desktop page: `pots page desktop`.** It gives the bot a one-time link to a page of Pots' own, where one person sees the bot's whole screen and controls it, through the VNC server that shows that screen on its computer. Pots signs in to that server itself, so its password never reaches the browser, a link or a log. Nothing of the desktop shows before the person presses Start, so a link preview cannot open it, and only the browser that pressed Start first can use the link; that browser can open it again, after a reload or a switch to another app, until the link ends. An unopened link stops working after an hour, a started one after 15 minutes (`--minutes`, up to 60). It goes through the page server's public address, a Quick Tunnel or your own; with a Quick Tunnel the page and the command's note say that Cloudflare can see the screen and every key typed.
|
|
11
|
+
- **Made for phones.** The picture fills the screen, and nothing else takes room from it. One group of buttons floats on it: the time left, keyboard, more, and Done; it can be dragged to any edge, stands upright on the left or right, and stays where it was put. The bot's words show in full when the picture comes, next to the buttons, for a few seconds, then fold into the first button; a tap on it shows them again, and a tap anywhere else folds them. The start screen shows long words in a calmer type with Start always in sight, and keeps the bot's line breaks: a line that starts with a number or a bullet reads as a list. When the VNC server can change its size, the bot's desktop takes the phone's shape while the person uses it (at least 500 pixels wide), and gets its own size back when the link ends, when the person's browser has been away for 20 seconds, and when Pots stops; after a crash, when the link ends. Pinching zooms the picture, not the page under it. The typing field sends each character as it is typed, also from an input method; with `--input password` it is a password field that password managers fill, and with `--input code` phones offer the code from a text message. `--area` starts a desktop that cannot change size zoomed in on the part that matters. More has Esc, Tab, Enter, arrows, select all, paste, a trackpad mode and the picture's size. On a computer the desktop takes the window's size, the keyboard types straight in, and ⌘ on a Mac becomes Ctrl. The page is in English, or in Chinese for a browser that asks for it.
|
|
12
|
+
- **The bot is woken once when the link ends**: when the person presses Done or "I can't do it", with their note, and when the link expires, unopened or after Start. It is also woken once when Pots cannot reach the VNC server for the person, at Start or later, while their page tries again by itself. While the link is started, the person holds the bot's screen: the screen commands of every agent on that screen do not run, and say why. `pots page list` lists desktop links, and `pots page unlink` ends one at once, with no wake.
|
|
13
|
+
- **`vnc` in bot.json**: the port of the VNC server on this computer and the file with its password, in the secrets folder: `VNC_PASSWORD=` as the password page writes it, or a password file as `vncpasswd` writes it. A new `desktop-page` skill says when to use the page, what the person sees, and how to set up a VNC server on Linux (X11, Wayland, or none), macOS and Windows. It also says how a bot sets up a screen of its own on a Linux computer whose desktop other bots use (a virtual desktop with its own D-Bus session bus and browser profile, as systemd user units, so it comes back after a restart), what to know when driving a Linux desktop (an input method can garble typed text; `gnome-screenshot` can give an old picture), and that a link goes to the person where they will open it.
|
|
14
|
+
- **`pots bot new` gives the new bot a first start, as `pots init` does.** The bot says hello, checks the screen, connects the chat apps the person wants, as an app of its own, and asks which models to use for which work. Its first wake says who made it and where that person is. When a bot made it, from its own shell, the new bot learns that this bot passes messages both ways with `pots chat` until it joins a chat app, and that it can wake that bot with `pots wake --bot` when something cannot wait. When other bots already work on the computer, it learns that bots on one screen wait for each other. Where another bot already uses the screen, it asks the person whether to set up a screen of its own, and recommends it: on Linux a virtual desktop such as TigerVNC's Xvnc, which takes about 0.5–1 GB of memory with its own browser, and a one-time package install with sudo when none is installed yet; on macOS and Windows a second screen is not practical, so it tells them that the bots take turns. `pots init` says the same when it makes another bot.
|
|
15
|
+
- **`pots bot new` waits until the running gateway has started the new bot**, so a `pots chat --bot <id>` right after finds it running.
|
|
16
|
+
- **"Add another bot" in the setup page for AI agents ([docs/for-agents.md](docs/for-agents.md))**: the person asks a bot they have to make one, or their agent runs `pots bot new`; the new bot then sets itself up.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **The `pages` skill and the prompt point to the desktop page**, and the prompt's choices for a computer without a desktop say that the person signs in to a virtual desktop from a desktop page link, with no SSH tunnel or open port.
|
|
20
|
+
- **A wake from a page link says that the link was used or ended**, since not every such wake is an answer now.
|
|
21
|
+
- **`ws` is a dependency of Pots**, for the desktop page's WebSocket. It was installed with Pots before, through other packages.
|
|
22
|
+
- **Linux: each command runs in a systemd scope of its own.** Where a systemd user manager runs (a desktop, or a server with lingering), every command of `bash`, `screen` and a routine runs in its own scope, in `app-pots-<id>.slice`, about 25 ms more per command. When memory runs out, systemd-oomd or the kernel stops the command that uses it, not the gateway with every bot in it: before, a heavy command, or the tabs of a browser a bot started, counted against the service, and systemd-oomd could kill the whole service with all its bots. What a command leaves running when it returns, such as a browser or a dev server, now keeps running when Pots restarts after an upgrade or a crash, and the bot's next wake lists it with its processes, so the bot decides when to stop it; a command Pots still waits on is stopped, with what it started. Stopping the service on purpose (`systemctl --user stop pots`, `pots service uninstall`) stops all of it. The prompt tells the bot these facts and the scopes' names. Elsewhere commands run as before.
|
|
23
|
+
- **Linux: the service has `OOMPolicy=continue`.** When the kernel kills one process of the service for memory, such as an MCP server, the gateway goes on instead of restarting. `pots service restart` adds the line to a unit an older version wrote.
|
|
24
|
+
- **The prompt tells the bot how to make another bot**: `pots bot new --about …`, then pass messages between it and the person until it has a chat app of its own, starting with who asked for it and where. It used to say only that a new folder with a bot.json is a new bot, so a bot made the folder itself, and the new bot got no first start. The screen facts now also say that bots that share a screen wait for each other, and that a screen per bot works best.
|
|
25
|
+
- **The bot confirms before an action that may cost money.** Its actions still need no approval, with one exception that the prompt now gives: before an action, it makes sure whether the action may cost money, and if it may, it confirms with the person before it does it.
|
|
26
|
+
- **A token file for each bot.** The Slack, Discord and Telegram skills, the pages skill and the prompt name the file for the bot, such as `slack-<bot ID>.env`, instead of one fixed `slack.env`, which another bot on the computer may already use: a second bot that followed the old text could write over the first one's tokens. Files that bots use now stay as they are. The Slack skill also says how to give the app an icon, which a manifest cannot do.
|
|
27
|
+
- **`pots chat -m` prints first what the bot sent since the last time**, such as a new bot's hello, or what the bot sent after the last `pots chat -m` ended. Before, it printed only the answers to its own message.
|
|
28
|
+
- **A mistyped command gets the command it most likely means**, for example `pots bot new Ada` for `pots bots new Ada`, instead of the whole help.
|
|
29
|
+
- **The bot knows that plain text is only one way to reply.** Its prompt says that pages, and the channel's own buttons, menus, forms and tables, often read and answer better, so it chooses what fits each time, and that a reply that runs to several messages goes out one message after another, since messages sent at the same time can arrive out of order.
|
|
30
|
+
|
|
31
|
+
## 0.7.2 (2026-11-13)
|
|
32
|
+
|
|
33
|
+
The bot sees what its children are doing and can free a stuck one, chooses each child's model, and `pots login` sets up everything in one run.
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
- **The bot sees what a working child is doing now.** Wherever a working child is described (the `task` tool's `list`, the answer to `send`, the children lines in wakes, `pots children`), indented lines say which tool it is in and for how long, the start of its command, its last output line and how old it is, and whether a message to it is still waiting: a child takes messages only between its steps.
|
|
37
|
+
- **`task interrupt` ends only a child's current command.** The child sees that its tool call was aborted, takes the messages that waited, and goes on. `stop` still ends the child.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
- **`pots login` adds all you need in one run.** After each sign-in, key or local server it says what is ready, or why not, and comes back to its menu; "Done" leaves and lists the models and judges pi can use, as `pots login --list` does. A judge's key, such as TypeSafe's for Jev, is tried at once, as `pots init` tries it.
|
|
41
|
+
- **`pots init` asks again when getting the AI fails.** A failed sign-in, a model or local server that does not answer, or Ctrl+C in one of its prompts takes you back to "How should your bot get its AI?" instead of ending `pots init`.
|
|
42
|
+
- **The setup page for AI agents ([docs/for-agents.md](docs/for-agents.md)) has the agent explain what you sign in to, and why, before it gives you `pots login`:** the model the bot thinks with, usually the subscription you already use, and a judge such as Jev, which decides which group messages wake the bot. You add both in one run.
|
|
43
|
+
- **The bot chooses each child's model.** When it starts a child, the `task` tool takes a `model` (`provider/modelId`) and any of pi's thinking levels, from `off` to `max`. A child it starts without them has the bot's model, also after a change in `bot.json`, and thinking `xhigh`. A child keeps the model chosen for it across changes of `bot.json` and restarts. A model that is unknown or not signed in on this computer is refused at once, with the reason, instead of failing at the child's first request. The prompt tells the bot that a code mode script lists the signed-in models, that it talks at `medium` thinking while children work at `xhigh` or `max`, and that which model does which work is the person's to say, kept in its AGENTS.md. A new bot asks about that at its first start.
|
|
44
|
+
- **`childModel` and `childThinking` in `bot.json` are no longer used.** A `bot.json` that still has them loads as before, and the gateway's output says that they are ignored. Children started before the upgrade have the bot's model.
|
|
45
|
+
- **Children report only when they end, and the bot knows it.** Its prompt says that for long work it can set itself a wake (`pots wake`) to look in on a child now and then and tell the person briefly how it is going.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
- **An empty API key is no longer saved.** Enter at an empty key prompt in `pots login` or `pots init` saved an empty key over the one pi had, and pi then counted the provider as not signed in: `pots login` ended with "signed in, but pi lists no model or judge for this login". Now the prompt asks again, and Ctrl+C goes back without changing the key.
|
|
49
|
+
- **For contributors: `npm test` no longer depends on the environment it runs in.** `POTS_*` variables, a desktop (`DISPLAY`) and your home folder no longer leak into the tests, and the sign-in tests can no longer open a real browser. A test of memory passes that sometimes failed under load is fixed in the code: the log line "memory pass got no answer" is written after the pass has saved its progress.
|
|
50
|
+
|
|
5
51
|
## 0.7.1 (2026-11-10)
|
|
6
52
|
|
|
7
53
|
Pots is also a pi package, so a pi user's agent can set Pots up. Nothing changed for bots: a running bot does not need this version.
|
package/README.md
CHANGED
|
@@ -24,10 +24,10 @@ does the work on its own computer, and speaks up when it should.
|
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
26
|
> [!TIP]
|
|
27
|
-
> **Setting this up with an AI agent, such as Claude Code, Codex or Cursor?** Have it read [docs/for-agents.md](https://github.com/Crokily/pi-durable-bot/blob/main/docs/for-agents.md) first. That page explains Pots to your agent and how to set it up. In short: the agent installs it and makes the bot, you sign in to your model with `pots login`, and then the bot connects Slack and your other apps itself.
|
|
27
|
+
> **Setting this up with an AI agent, such as Claude Code, Codex or Cursor?** Have it read [docs/for-agents.md](https://github.com/Crokily/pi-durable-bot/blob/main/docs/for-agents.md) first. That page explains Pots to your agent and how to set it up. In short: the agent installs it and makes the bot, you sign in to your model (and a judge such as Jev, for group chats) with `pots login`, and then the bot connects Slack and your other apps itself.
|
|
28
28
|
|
|
29
29
|
<p align="center" id="see-it-work">
|
|
30
|
-
<a href="docs/media/demo.mp4"><img src="docs/media/demo.gif" width="900" alt="Pots reads
|
|
30
|
+
<a href="docs/media/demo.mp4"><img src="docs/media/demo.gif" width="900" alt="In Slack, Pots reads every message and decides a pricing question is its job, checks the pricing page in a browser on its own computer, picks up after being killed mid-task, sends a comparison page, uses Slack's own buttons, and takes an API key on a one-time page"></a>
|
|
31
31
|
</p>
|
|
32
32
|
|
|
33
33
|
Grok Bot, dots and Claude Tag showed what an AI teammate can be. pi-durable-bot gives you the same kind of coworker as open source: it runs on your machine, with the model you choose, in the places your team already talks.
|
|
@@ -90,15 +90,17 @@ It has a real machine with a shell, files, the internet, and a screen it uses li
|
|
|
90
90
|
|
|
91
91
|
This is **code mode**: the agent gets a few general tools (`read`, `write`, `edit`, `bash`, `screen`) plus three channel actions (`send`, `react`, `call`), and builds the rest itself. One more tool, `task`, hands work to its helpers (below). With `codemode`, pi's code mode, it writes a JavaScript script that calls these tools and the tools of [MCP servers](#mcp-servers) in a sandbox; only what the script returns comes back to it.
|
|
92
92
|
|
|
93
|
-
`screen` is `bash` with the screen's environment, such as `DISPLAY`; `bash` does not have it. A screen runs one task at a time, as a person's desktop does: the first `screen` command of an agent takes the screen until its work ends, also across bots and the Pots processes of the same user on the machine. Another agent that tries then learns who has it, since when, and when it frees, and decides itself what to do. A bot that sets up its own desktop, such as an Xvfb display, writes its environment into `screen` in its `bot.json`.
|
|
93
|
+
`screen` is `bash` with the screen's environment, such as `DISPLAY`; `bash` does not have it. A screen runs one task at a time, as a person's desktop does: the first `screen` command of an agent takes the screen until its work ends, also across bots and the Pots processes of the same user on the machine. Another agent that tries then learns who has it, since when, and when it frees, and decides itself what to do. A person who takes over the screen from a desktop page link holds it the same way, until they hand it back. A bot that sets up its own desktop, such as an Xvfb display, writes its environment into `screen` in its `bot.json`.
|
|
94
94
|
|
|
95
95
|
One agent at a time per screen is enforced only on Linux, where plain `bash` has no `DISPLAY` or `WAYLAND_DISPLAY` and so cannot reach the screen. On macOS and Windows the screen does not depend on those variables, so `bash` can still use it; there the agents use the `screen` tool because the prompt tells them to.
|
|
96
96
|
|
|
97
|
+
On Linux with a systemd user manager (a desktop, or a server with lingering, which `pots service install` turns on), each command of `bash`, `screen` and a routine runs in a systemd scope of its own, in one slice per Pots home. When memory runs out, systemd-oomd or the kernel then stops the command that uses it, not the gateway with every bot in it. What a command leaves running when it returns, such as a browser, a dev server or a `nohup` job, keeps running when Pots restarts after an upgrade or a crash, and the bot's next wake lists it, so the bot decides when to stop it. A command Pots still waits on when it stops is stopped, with what it started. When you stop Pots' service on purpose (`systemctl --user stop pots`, `pots service uninstall`), everything its commands left stops too. A scope costs about 25 ms per command. Where there is no user manager (macOS, Windows, `--system` services, most containers), commands run as before.
|
|
98
|
+
|
|
97
99
|
### 👥 Its own helpers
|
|
98
100
|
|
|
99
|
-
Longer work does not keep it from talking. With its `task` tool the bot starts **children**: agents that work in the background with `read`, `write`, `edit`, `bash`, `screen` and `codemode`, without the channel actions and `task`, on a brief it writes for them. It answers the person first, hands the work to a child, and stays free for the next message. A child starts from an empty conversation and its brief, so the bot's own context stays small; it sees the bot's memory index as it was when it started. When a child ends, done, failed or with a question for a person, its final message comes back to the bot as a wake, exactly once, also across crashes and restarts; the bot passes on what matters, and sends the child the answer to its question. While a child works for a place, new messages there go to the bot, so it can pass them on.
|
|
101
|
+
Longer work does not keep it from talking. With its `task` tool the bot starts **children**: agents that work in the background with `read`, `write`, `edit`, `bash`, `screen` and `codemode`, without the channel actions and `task`, on a brief it writes for them. It answers the person first, hands the work to a child, and stays free for the next message. A child starts from an empty conversation and its brief, so the bot's own context stays small; it sees the bot's memory index as it was when it started. When a child ends, done, failed or with a question for a person, its final message comes back to the bot as a wake, exactly once, also across crashes and restarts; the bot passes on what matters, and sends the child the answer to its question. While a child works for a place, new messages there go to the bot, so it can pass them on. A child takes the bot's messages only between its steps, so a message sent while it is in a long command waits until the command ends. Wherever the bot sees a child that works (its timed and fallback wakes, the wakes from the child's place, the task tool's list and the answer to a message it sends), it sees what the child does now: the tool call it is in and for how long, the start of the command, its last line of output and how old that is, and how many of the bot's messages wait for it. When a command hangs, the bot can interrupt the child's current tool calls: the child goes on with its work so far, sees that they were aborted, and takes the messages that waited. A stopped child reports nothing and does nothing more, also when the process dies in the middle of the stop.
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
The bot chooses each child's model and thinking level when it starts it: any model signed in on this computer, and any of pi's levels. A child it starts without a choice has the bot's `model`, also after a change in `bot.json`, and thinking `xhigh`. A child keeps the model chosen for it and its level for its whole life, also across restarts; a level the model does not have becomes the nearest one it has, as in pi. A model that is unknown or not signed in is refused before the child starts, with the reason, so the bot can take another or ask you to run `pots login`. By default the bot talks at the `thinking` of `bot.json` (`medium`), and its children do the work at `xhigh` or `max`. Which model does which work is yours to say: the bot asks at its first start and keeps your answer in its `AGENTS.md`. `settings.maxChildren` (50 by default) caps how many work at once. `pots children` lists them, and `pots children --stop <id>` or `--stop-all` stops them.
|
|
102
104
|
|
|
103
105
|
It works like a [pi](https://github.com/earendil-works/pi) session: it reads `AGENTS.md` and uses [Agent Skills](https://agentskills.io) from the same places pi does, so the skills you give pi, the bot can use too. Screenshots and photos are shrunk to fit the model, as in pi.
|
|
104
106
|
|
|
@@ -112,6 +114,7 @@ Some things do not fit in a chat message. For a plan, a report or a dashboard, t
|
|
|
112
114
|
|
|
113
115
|
- **Buttons and forms in the chat.** On Slack and Discord the bot sends the platform's own buttons, menus and forms; on Telegram, inline buttons. A click wakes it within a second, and a form opens at once.
|
|
114
116
|
- **A password page for secrets.** When the bot needs an API key from you, it sends a one-time link to a page of Pots' own. You type the key there. It goes into a file in the secrets folder, never into the chat, the log or a trace.
|
|
117
|
+
- **A desktop page for the steps only you can do.** When a sign-in, a CAPTCHA or an approval needs you, the bot sends a one-time link. On your phone or computer you see its whole screen, do the step, and press Done; the bot is woken with your note and carries on. On a phone the picture fills the screen, and the bot's desktop takes your phone's shape when its VNC server can change size; you type into a field that sends each character as you go. Pots signs in to the VNC server on the bot's computer itself, so its password stays there, and nothing shows before you press Start. While you have the screen, the bot's screen commands do not run.
|
|
115
118
|
- **No public address needed.** The first link starts a Cloudflare Quick Tunnel, so pages work from a laptop behind a home router. For a fixed address, the bot sets up Tailscale Funnel with you, or uses your own domain.
|
|
116
119
|
|
|
117
120
|
### ⏰ Its own schedule
|
|
@@ -164,10 +167,12 @@ Then the gateway starts as a background service (it starts again at login) and y
|
|
|
164
167
|
|
|
165
168
|
It joins only the places it is invited to, like a new hire who is added to the right channels.
|
|
166
169
|
|
|
170
|
+
To add another bot, ask a bot you have to make one, or run `pots bot new <name> --about "<what it is for>"`. The new bot sets itself up the same way, and when another bot already uses the screen, it offers to set up one of its own ([Add another bot](docs/for-agents.md#add-another-bot)).
|
|
171
|
+
|
|
167
172
|
| Command | What it does |
|
|
168
173
|
|---|---|
|
|
169
174
|
| `pots init` | Set up your first bot, or another one |
|
|
170
|
-
| `pots login` | Sign in to
|
|
175
|
+
| `pots login` | Sign in to models and judges, or add API keys or local servers, one after another, for every bot on this computer; `--list` shows what can be used |
|
|
171
176
|
| `pots mcp add \| remove \| list \| login \| logout` | The [MCP servers](#mcp-servers) of every bot on this computer, and sign-ins to them |
|
|
172
177
|
| `pots chat` | Talk to a bot in this terminal |
|
|
173
178
|
| `pots status` | The gateway, the service and each bot |
|
|
@@ -175,20 +180,20 @@ It joins only the places it is invited to, like a new hire who is added to the r
|
|
|
175
180
|
| `pots start` | Run the gateway in this terminal instead |
|
|
176
181
|
| `pots bot new \| list` | Create and list bots |
|
|
177
182
|
| `pots trace` | What a bot did: its last wakes, or one wake from the events to its run, the runs of the children it started, and the messages it sent, with how much of each model request the provider's prompt cache served |
|
|
178
|
-
| `pots children [--stop <id> \| --stop-all]` | The children a bot started for longer work, with each one's thinking level, or stop them |
|
|
183
|
+
| `pots children [--stop <id> \| --stop-all]` | The children a bot started for longer work, with each one's thinking level, the model the bot chose for it, and what each one that works does now, or stop them |
|
|
179
184
|
|
|
180
185
|
To upgrade, run `npm install -g pi-durable-bot@latest`, then `pots service restart`. To remove it, run `pots service uninstall`, then `npm uninstall -g pi-durable-bot`. The bots stay in `~/.pots/` until you delete that folder.
|
|
181
186
|
|
|
182
187
|
### Choose the models
|
|
183
188
|
|
|
184
|
-
`pots init` sets up the model, and `pots login` signs in to
|
|
189
|
+
`pots init` sets up the model, and `pots login` signs in to others or adds keys, one after another, for every bot on the computer. Each bot's `bot.json` names its model and, if you want one, a judge, and you can change them at any time; edits apply within seconds. Logins, API keys and local endpoints are stored in pi's files in `~/.pi/agent/`, so the [pi](https://github.com/earendil-works/pi) command line, if you use it, shares them.
|
|
190
|
+
|
|
191
|
+
The bot's children, which do its longer work, have the bot's model unless it chooses another one for a child. At its first start it asks you which models you want for which work; sign in to those with `pots login` too.
|
|
185
192
|
|
|
186
193
|
| Field | What it does | Values |
|
|
187
194
|
|---|---|---|
|
|
188
195
|
| `model` | The agent that reads, thinks and acts | Any pi model as `provider/modelId`, for example `openai/gpt-6.1-sol` or `anthropic/claude-opus-5-5` |
|
|
189
196
|
| `thinking` | How hard the agent thinks. A level the model does not have becomes the nearest one it has, as in pi | `off`, `minimal`, `low`, `medium` (default), `high`, `xhigh`, `max` |
|
|
190
|
-
| `childModel` | The model of the children that do longer work in the background | Unset (default): the bot's `model` |
|
|
191
|
-
| `childThinking` | The thinking level of a child the bot starts without choosing one | As `thinking`; `xhigh` (default) |
|
|
192
197
|
| `judge` | Decides which messages that do not mention the bot should wake it | `off` (default): every message wakes the bot, and the agent decides<br>`provider/modelId` of a classifier: `typesafe/jev-latest`, `openrouter/typesafe/jev-1.14`, `opencode/jev-1.13-free`, or a llama.cpp model<br>`main`: the bot's own model judges, no extra account, but slower |
|
|
193
198
|
|
|
194
199
|
With `off`, each group of messages is a wake of the main model, which then decides. A fast classifier keeps the messages that are not for the bot away from it, and is cheaper and quicker than the main model: Jev answers in about 0.3 seconds. With `main`, each group of messages costs one short request to the main model before the bot hears of it.
|
|
@@ -296,7 +301,7 @@ One gateway process runs every bot on the machine. Everything lives in `~/.pots/
|
|
|
296
301
|
|
|
297
302
|
| File | What it is |
|
|
298
303
|
|---|---|
|
|
299
|
-
| `bot.json` | Name, model, children's model, judge, channel accounts, its screen, settings. Edits apply within seconds. |
|
|
304
|
+
| `bot.json` | Name, model, children's model, judge, channel accounts, its screen and the VNC server that shows it, settings. Edits apply within seconds. |
|
|
300
305
|
| `AGENTS.md` | Personality and voice, read the way pi reads AGENTS.md. The bot maintains it. |
|
|
301
306
|
| `responsibilities.md` | What it is responsible for. The judge reads it. The bot maintains it. |
|
|
302
307
|
| `notes.md` | Its handoff to the next page: what it is doing and what it promised. |
|
|
@@ -332,6 +337,7 @@ pi-durable-bot runs every day as a teammate in a real workspace. What works toda
|
|
|
332
337
|
- [x] `AGENTS.md`, Agent Skills and images as in a pi session
|
|
333
338
|
- [x] MCP servers and code mode, through pi's own MCP support
|
|
334
339
|
- [x] Pages, buttons, forms and a password page, with a public address that needs no setup
|
|
340
|
+
- [x] A desktop page: a person takes over the bot's screen from a link, on a phone or a computer, and hands it back
|
|
335
341
|
- [ ] More adapters: Teams, email
|
|
336
342
|
- [ ] `pots init` in a web page, for people who do not use a terminal
|
|
337
343
|
|
|
@@ -371,3 +377,5 @@ npm run tla # the TLA+ models of the inbox, outbox and waker (need
|
|
|
371
377
|
## License
|
|
372
378
|
|
|
373
379
|
MIT. The demo video, music, sky images and logo in [`docs/media`](docs/media) were made for this project and use the same license.
|
|
380
|
+
|
|
381
|
+
The desktop page bundles [noVNC](https://github.com/novnc/noVNC) 1.7.0 in [`kit/desktop/novnc.js`](kit/desktop/novnc.js), under the MPL 2.0, with the MIT-licensed pako in it; their license texts are in [`kit/desktop/novnc/`](kit/desktop/novnc). `node scripts/vendor-novnc.ts` builds that file from noVNC's release.
|
package/dist/agent/agent.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { BACKGROUND_CONTEXT, withTelemetry } from "@earendil-works/chord/context";
|
|
3
|
+
import { BACKGROUND_CONTEXT, withAbortSignal, withTelemetry } from "@earendil-works/chord/context";
|
|
4
4
|
import { calculateContextTokens, estimateMessageTokens } from "@earendil-works/pi-ai/utils/estimate";
|
|
5
|
-
import { configure, createRegistry, DEFAULT_COMPACTION_POLICY, defineExtension, defineTool, GenerationTask, Harness, hook, LiveDoc, ROOT_CONVERSATION_ID, SystemEntry, section, } from "@earendil-works/pi-durable";
|
|
5
|
+
import { configure, createRegistry, DEFAULT_COMPACTION_POLICY, defineExtension, defineTool, GenerationTask, Harness, hook, InboxDoc, LiveDoc, ROOT_CONVERSATION_ID, SystemEntry, section, } from "@earendil-works/pi-durable";
|
|
6
6
|
import { NodeExecutionEnv } from "@earendil-works/pi-durable/env/node";
|
|
7
7
|
import { createNodePhotonImages } from "@earendil-works/pi-durable/images/node";
|
|
8
8
|
import { SqliteStorage } from "@earendil-works/pi-durable/storage/sqlite";
|
|
9
9
|
import { openNodeSqliteDatabase } from "@earendil-works/pi-durable/storage/sqlite/node";
|
|
10
10
|
import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@earendil-works/pi-durable/tools";
|
|
11
11
|
import { bool, map, obj, opt, str, unknown } from "@earendil-works/pi-schema";
|
|
12
|
-
import { Children, childInfo, childrenExtension, reportRequestId } from "./children.js";
|
|
12
|
+
import { age, Children, childActivity, childInfo, childrenExtension, describeActivity, reportRequestId, } from "./children.js";
|
|
13
13
|
import { deleteLeftForks, lastAnswer, MemoryPasses, readPaths, withAgeNote } from "./memory.js";
|
|
14
14
|
import { modelRef, requireModel } from "./models.js";
|
|
15
15
|
import { NO_SCREEN, renderBusy, ScreenLeases } from "./screen.js";
|
|
@@ -20,6 +20,8 @@ export function openDatabase(path) {
|
|
|
20
20
|
}
|
|
21
21
|
/** Call results longer than this go to a file in the workspace. */
|
|
22
22
|
const CALL_OUTPUT_CHARS = 30_000;
|
|
23
|
+
/** How long an interrupt waits for a child's tool calls to end. */
|
|
24
|
+
const INTERRUPT_WAIT_MS = 10_000;
|
|
23
25
|
/** The window assumed for a model whose catalog entry gives none. */
|
|
24
26
|
const DEFAULT_WINDOW = 200_000;
|
|
25
27
|
/** Room kept free for the answer and long tool results; pi's own default is 16K. */
|
|
@@ -50,15 +52,18 @@ export class Agent {
|
|
|
50
52
|
#closing = false;
|
|
51
53
|
/** Stops the last process did not finish; resume() finishes them. */
|
|
52
54
|
#unfinishedStops = [];
|
|
55
|
+
/** The running tool calls that give output as they run, by tool task, with when their last output came. */
|
|
56
|
+
#outputs;
|
|
53
57
|
/**
|
|
54
58
|
* Crash tests: called just before and just after a child's end is handed to the main agent, right after a stop
|
|
55
59
|
* marked a child stopped, before its work ended, and right before a memory pass forks the main conversation.
|
|
56
60
|
*/
|
|
57
61
|
crashTests = {};
|
|
58
|
-
constructor(options, harness, root) {
|
|
62
|
+
constructor(options, harness, root, outputs) {
|
|
59
63
|
this.#options = options;
|
|
60
64
|
this.#harness = harness;
|
|
61
65
|
this.#root = root;
|
|
66
|
+
this.#outputs = outputs;
|
|
62
67
|
this.#models = options.models;
|
|
63
68
|
this.#model = modelRef(options.model);
|
|
64
69
|
}
|
|
@@ -95,6 +100,26 @@ export class Agent {
|
|
|
95
100
|
execution.inheritEnv = false;
|
|
96
101
|
execution.env = { ...base, ...extra, ...execution.env };
|
|
97
102
|
};
|
|
103
|
+
// When each running call of bash, screen and codemode last gave output, so a child's description can say how old its
|
|
104
|
+
// last output is. Only in memory: a call does not run on after a restart.
|
|
105
|
+
const outputs = new Map();
|
|
106
|
+
const timed = (tool) => defineTool({
|
|
107
|
+
...tool,
|
|
108
|
+
execute: async (args, api, call) => {
|
|
109
|
+
const key = String(api.taskId);
|
|
110
|
+
outputs.set(key, undefined);
|
|
111
|
+
const output = (chunk, skipped) => {
|
|
112
|
+
outputs.set(key, Date.now());
|
|
113
|
+
api.output(chunk, skipped);
|
|
114
|
+
};
|
|
115
|
+
try {
|
|
116
|
+
return await tool.execute(args, new Proxy(api, { get: (target, property) => (property === "output" ? output : Reflect.get(target, property, target)) }), call);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
outputs.delete(key);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
});
|
|
98
123
|
/** The channel actions, for the main agent only: children have no send, react or call. */
|
|
99
124
|
const channelTools = [
|
|
100
125
|
defineTool({
|
|
@@ -138,7 +163,7 @@ export class Agent {
|
|
|
138
163
|
},
|
|
139
164
|
}),
|
|
140
165
|
];
|
|
141
|
-
const screenTool = defineTool({
|
|
166
|
+
const screenTool = timed(defineTool({
|
|
142
167
|
...createBashTool(),
|
|
143
168
|
name: "screen",
|
|
144
169
|
description: "Run a bash command on your screen: like bash, with the screen's environment (such as DISPLAY), which bash does not have. " +
|
|
@@ -165,7 +190,7 @@ export class Agent {
|
|
|
165
190
|
taken.done();
|
|
166
191
|
}
|
|
167
192
|
},
|
|
168
|
-
});
|
|
193
|
+
}));
|
|
169
194
|
let harness;
|
|
170
195
|
// After an upgrade, the main conversation's pinned sections show their new text until a request with it goes out.
|
|
171
196
|
let refresh = options.refreshPinned ? "waiting" : "done";
|
|
@@ -246,14 +271,14 @@ export class Agent {
|
|
|
246
271
|
defineTool({ ...read, execute: async (args, api, call) => withAgeNote(await read.execute(args, api, call), args.path, memoryFolders(), options.workspace) }),
|
|
247
272
|
createWriteTool(),
|
|
248
273
|
createEditTool(),
|
|
249
|
-
createBashTool({ prepare: environment() }),
|
|
274
|
+
timed(createBashTool({ prepare: environment() })),
|
|
250
275
|
],
|
|
251
276
|
});
|
|
252
277
|
// pi's code mode, for the main agent and its children. As in pi, a script waits for the MCP servers it names, or for
|
|
253
278
|
// all of them when it looks tools up, so it sees their tools. A server that connected meanwhile came after this
|
|
254
279
|
// call's phase resolved the agent: then the script gets the agent as it is now, with that server's tools.
|
|
255
280
|
const [script, ...scriptModels] = options.codemode.tools;
|
|
256
|
-
const codemodeTool = defineTool({
|
|
281
|
+
const codemodeTool = timed(defineTool({
|
|
257
282
|
...script,
|
|
258
283
|
execute: async (args, api, call) => {
|
|
259
284
|
const code = args.code;
|
|
@@ -263,7 +288,7 @@ export class Agent {
|
|
|
263
288
|
const current = new Proxy(api, { get: (target, property) => (property === "agent" ? async () => now : Reflect.get(target, property, target)) });
|
|
264
289
|
return script.execute(args, current, call);
|
|
265
290
|
},
|
|
266
|
-
});
|
|
291
|
+
}));
|
|
267
292
|
const codemode = defineExtension({ name: "codemode", tools: [codemodeTool, ...scriptModels] });
|
|
268
293
|
// The servers' tools, which only scripts call: a new extension of the same name each time servers connect or go.
|
|
269
294
|
const mcp = () => options.mcp?.extension() ?? defineExtension({ name: "mcp" });
|
|
@@ -274,7 +299,8 @@ export class Agent {
|
|
|
274
299
|
return agent;
|
|
275
300
|
};
|
|
276
301
|
const tasks = childrenExtension({
|
|
277
|
-
|
|
302
|
+
mainModel: () => self().#model,
|
|
303
|
+
childModel: (model) => childModel(models, model),
|
|
278
304
|
max: () => options.children.max(),
|
|
279
305
|
place: () => options.children.place(),
|
|
280
306
|
extensions: () => ({ child: [coding, child, codemode, mcp()] }),
|
|
@@ -283,6 +309,8 @@ export class Agent {
|
|
|
283
309
|
await self().#harness.abortSubmission(Number(submission), context, ROOT_CONVERSATION_ID);
|
|
284
310
|
},
|
|
285
311
|
stop: (id) => self().stopChild(id),
|
|
312
|
+
activity: (conversation) => self().#activity(conversation),
|
|
313
|
+
interrupt: (child) => self().interruptChild(child),
|
|
286
314
|
settled: (conversation) => self().#releaseScreen(conversation),
|
|
287
315
|
beforeReport: (reporter) => self().crashTests.beforeReport?.(reporter),
|
|
288
316
|
afterReport: (reporter) => self().crashTests.afterReport?.(reporter),
|
|
@@ -312,21 +340,24 @@ export class Agent {
|
|
|
312
340
|
// The fallback when the agent does not turn the page itself.
|
|
313
341
|
get compaction() {
|
|
314
342
|
const main = agent ? agent.#model : modelRef(options.model);
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
343
|
+
const set = options.compaction();
|
|
344
|
+
const policy = compactionFor(models, main, set);
|
|
345
|
+
// Children may have other models, with other windows: each model a child has gets its own.
|
|
346
|
+
const others = new Set(children.flatMap((child) => (child.model !== undefined && child.model !== `${main.provider}/${main.modelId}` ? [child.model] : [])));
|
|
347
|
+
if (others.size === 0)
|
|
348
|
+
return policy;
|
|
349
|
+
return { ...policy, modelOverrides: Object.fromEntries([...others].map((model) => [model, compactionFor(models, modelRef(model), set)])) };
|
|
320
350
|
},
|
|
321
351
|
},
|
|
322
|
-
|
|
352
|
+
// The scopes' environment runs each shell command in a systemd scope of its own; its files are the same.
|
|
353
|
+
env: () => (options.scopes ? options.scopes.env({ cwd: options.workspace, shellEnv: options.shellEnv }) : new NodeExecutionEnv({ cwd: options.workspace, shellEnv: options.shellEnv })),
|
|
323
354
|
...(options.telemetry ? { telemetry: options.telemetry } : {}),
|
|
324
355
|
onReport: (report) => options.log("pi report", { type: report.kind, error: String(report.error) }),
|
|
325
356
|
}, context);
|
|
326
357
|
const model = modelRef(options.model);
|
|
327
358
|
const root = await harness.root(context, { agent: { model, thinkingLevel: options.thinking } });
|
|
328
359
|
await root.configure({ model, thinkingLevel: options.thinking, cwd: options.workspace }, context);
|
|
329
|
-
agent = new Agent(options, harness, root);
|
|
360
|
+
agent = new Agent(options, harness, root, outputs);
|
|
330
361
|
if (memory) {
|
|
331
362
|
memory.attach(harness, root);
|
|
332
363
|
memory.beforePass = () => agent?.crashTests.beforeMemoryPass?.();
|
|
@@ -335,8 +366,8 @@ export class Agent {
|
|
|
335
366
|
await agent.#watchRun();
|
|
336
367
|
await agent.#watchChildren((list) => (children = list));
|
|
337
368
|
await agent.#holdUnfinishedStops();
|
|
338
|
-
// bot.json may have changed while the bot was stopped: the children
|
|
339
|
-
await agent.#configureChildren(
|
|
369
|
+
// bot.json may have changed the model while the bot was stopped: the children without a model of their own get it.
|
|
370
|
+
await agent.#configureChildren();
|
|
340
371
|
return agent;
|
|
341
372
|
}
|
|
342
373
|
/** Continue the work the last process left unfinished. Call once the channels are up, so its tools can act. */
|
|
@@ -471,24 +502,93 @@ export class Agent {
|
|
|
471
502
|
get children() {
|
|
472
503
|
return this.#children;
|
|
473
504
|
}
|
|
474
|
-
/**
|
|
475
|
-
|
|
476
|
-
return
|
|
505
|
+
/** Children with what each one that works does now, read from its conversation. */
|
|
506
|
+
async childrenNow(children = this.#children) {
|
|
507
|
+
return Promise.all(children.map(async (child) => {
|
|
508
|
+
if (child.since === undefined || child.stoppedAt !== undefined)
|
|
509
|
+
return child;
|
|
510
|
+
const activity = await this.#activity(Number(child.conversationId));
|
|
511
|
+
return activity === undefined ? child : { ...child, activity };
|
|
512
|
+
}));
|
|
513
|
+
}
|
|
514
|
+
/** What a working child does now: its current tool calls or model answer, and the messages that wait for it. */
|
|
515
|
+
async #activity(conversation) {
|
|
516
|
+
try {
|
|
517
|
+
const [live, inbox] = await Promise.all([this.#harness.snapshot(LiveDoc, conversation, context), this.#harness.snapshot(InboxDoc, conversation, context)]);
|
|
518
|
+
const running = [...(live?.tools ?? []), ...(live?.nestedTools ?? [])].flatMap((slot) => (slot.taskId !== undefined && slot.status !== "done" ? [slot.taskId] : []));
|
|
519
|
+
const tasks = new Map();
|
|
520
|
+
for (const id of running) {
|
|
521
|
+
const record = await this.#harness.getTask(id, context);
|
|
522
|
+
if (!record)
|
|
523
|
+
continue;
|
|
524
|
+
const checkpoint = record.state.checkpoint;
|
|
525
|
+
tasks.set(String(id), {
|
|
526
|
+
...(record.startedAt === undefined ? {} : { startedAt: record.startedAt }),
|
|
527
|
+
...(checkpoint?.phase === "execute" && checkpoint.arguments ? { arguments: checkpoint.arguments } : {}),
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
return childActivity(live, inbox, tasks, this.#outputs);
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
this.#options.log("could not read what a child does", { conversation: String(conversation), error: String(error) });
|
|
534
|
+
return undefined;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* End the tool calls a working child is in, such as a command that hangs. The child goes on: each call's result says
|
|
539
|
+
* it was aborted, and the child takes the messages that wait for it. Returns what happened, in words for the model.
|
|
540
|
+
*/
|
|
541
|
+
async interruptChild(child) {
|
|
542
|
+
const before = await this.#activity(Number(child.conversationId));
|
|
543
|
+
if (before === undefined)
|
|
544
|
+
return `Could not read what ${child.id} does now, so nothing was interrupted.`;
|
|
545
|
+
if (before.calls.length === 0) {
|
|
546
|
+
const now = describeActivity({ ...before, waiting: 0 }, Date.now());
|
|
547
|
+
return `${child.id} is in no tool call now, so nothing was interrupted.${now.length > 0 ? ` ${now.join(" ")}` : ""}`;
|
|
548
|
+
}
|
|
549
|
+
// A tool that does not end on its abort signal would hold the main agent: wait for a while, not for ever.
|
|
550
|
+
const wait = withAbortSignal(AbortSignal.timeout(INTERRUPT_WAIT_MS), context);
|
|
551
|
+
const ended = await Promise.all(before.calls.map(async (call) => {
|
|
552
|
+
const task = Number(call.task);
|
|
553
|
+
try {
|
|
554
|
+
if ((await this.#harness.abortTask(task, wait)) === "terminal")
|
|
555
|
+
return "ended before";
|
|
556
|
+
await this.#harness.waitForTask(task, wait);
|
|
557
|
+
return "aborted";
|
|
558
|
+
}
|
|
559
|
+
catch (error) {
|
|
560
|
+
if (wait.abortSignal?.aborted)
|
|
561
|
+
return "running";
|
|
562
|
+
throw error;
|
|
563
|
+
}
|
|
564
|
+
}));
|
|
565
|
+
const now = Date.now();
|
|
566
|
+
const named = (call) => `${call.tool}${call.since === undefined ? "" : `, which ran ${age(now - call.since)}`}${call.command === undefined ? "" : ` (${call.command})`}`;
|
|
567
|
+
const done = before.calls.filter((_, index) => ended[index] === "aborted");
|
|
568
|
+
const early = before.calls.filter((_, index) => ended[index] === "ended before");
|
|
569
|
+
const left = before.calls.filter((_, index) => ended[index] === "running");
|
|
570
|
+
const lines = [];
|
|
571
|
+
if (early.length > 0)
|
|
572
|
+
lines.push(`${child.id}'s ${early.map((call) => call.tool).join(" and ")} ended by itself just before.`);
|
|
573
|
+
if (done.length > 0) {
|
|
574
|
+
const { waiting } = before;
|
|
575
|
+
const takes = waiting === 0 ? "" : `, and takes the ${waiting === 1 ? "message" : `${waiting} messages`} from you that ${waiting === 1 ? "waits" : "wait"}`;
|
|
576
|
+
lines.push(`Interrupted ${child.id}: ended its ${done.map(named).join("; its ")}. It goes on: it sees that ${done.length === 1 ? "the call was" : "the calls were"} aborted${takes}.`);
|
|
577
|
+
}
|
|
578
|
+
if (left.length > 0) {
|
|
579
|
+
lines.push(`${child.id}'s ${left.map((call) => call.tool).join(" and ")} did not end within ${INTERRUPT_WAIT_MS / 1_000} s of the interrupt; it ends when the tool gives up.`);
|
|
580
|
+
}
|
|
581
|
+
return lines.join("\n");
|
|
477
582
|
}
|
|
478
583
|
/**
|
|
479
|
-
* Give every child that is not stopped
|
|
480
|
-
*
|
|
584
|
+
* Give the main model to every child that is not stopped and has no model of its own. A child with its own model
|
|
585
|
+
* keeps it, and every child keeps its thinking level.
|
|
481
586
|
*/
|
|
482
|
-
async configureChildren(
|
|
483
|
-
|
|
484
|
-
await requireChatModel(this.#models, childModel);
|
|
485
|
-
// Not #childModel(childModel): for undefined, its default reads bot.json's childModel from before this change.
|
|
486
|
-
await this.#configureChildren(childModel ? modelRef(childModel) : this.#model);
|
|
487
|
-
}
|
|
488
|
-
async #configureChildren(model) {
|
|
489
|
-
const children = this.#children.filter((child) => child.stoppedAt === undefined);
|
|
587
|
+
async #configureChildren() {
|
|
588
|
+
const children = this.#children.filter((child) => child.stoppedAt === undefined && child.model === undefined);
|
|
490
589
|
if (children.length === 0)
|
|
491
590
|
return;
|
|
591
|
+
const model = this.#model;
|
|
492
592
|
await this.#root.commit(async (tx) => {
|
|
493
593
|
for (const child of children)
|
|
494
594
|
await configure(tx, Number(child.conversationId), { model });
|
|
@@ -648,11 +748,15 @@ export class Agent {
|
|
|
648
748
|
}
|
|
649
749
|
return use;
|
|
650
750
|
}
|
|
651
|
-
/**
|
|
751
|
+
/**
|
|
752
|
+
* Change the model ("provider/modelId") or the thinking level. The children without a model of their own get the new
|
|
753
|
+
* model too. Throws for an unknown model.
|
|
754
|
+
*/
|
|
652
755
|
async configure(model, thinking) {
|
|
653
756
|
await requireChatModel(this.#models, model);
|
|
654
757
|
this.#model = modelRef(model);
|
|
655
758
|
await this.#root.configure({ model: this.#model, thinkingLevel: thinking }, context);
|
|
759
|
+
await this.#configureChildren();
|
|
656
760
|
}
|
|
657
761
|
/**
|
|
658
762
|
* Tokens in the context: the provider's count for the last request, plus an estimate of what came after.
|
|
@@ -709,4 +813,27 @@ function compactionFor(models, ref, set) {
|
|
|
709
813
|
async function requireChatModel(models, model) {
|
|
710
814
|
await requireModel(models, model, (provider, id) => models.getModel(provider, id));
|
|
711
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* A child's model ("provider/modelId"), or why it cannot be used: an unknown model, or one that is not signed in on this
|
|
818
|
+
* computer, said now rather than as the child's first failed request.
|
|
819
|
+
*/
|
|
820
|
+
async function childModel(models, model) {
|
|
821
|
+
const ref = modelRef(model);
|
|
822
|
+
if (!ref.provider || !ref.modelId)
|
|
823
|
+
return { refused: `the model must be "provider/modelId", not "${model}".` };
|
|
824
|
+
const list = 'a codemode script lists the models you can use with models.getAvailableOfType("chat").';
|
|
825
|
+
try {
|
|
826
|
+
await requireChatModel(models, model);
|
|
827
|
+
}
|
|
828
|
+
catch {
|
|
829
|
+
return { refused: `unknown model ${model}; ${list}` };
|
|
830
|
+
}
|
|
831
|
+
const available = await models.getAvailable(ref.provider);
|
|
832
|
+
if (available.some((each) => each.id === ref.modelId))
|
|
833
|
+
return { model: ref };
|
|
834
|
+
if (available.length === 0) {
|
|
835
|
+
return { refused: `${model} is not signed in on this computer: pi has no login or key for "${ref.provider}". A person signs in with pots login in their terminal; ${list}` };
|
|
836
|
+
}
|
|
837
|
+
return { refused: `the login for "${ref.provider}" on this computer cannot use ${model}; ${list}` };
|
|
838
|
+
}
|
|
712
839
|
//# sourceMappingURL=agent.js.map
|