@antondanv/brainyard 0.1.0 → 0.3.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 +128 -0
- package/README.md +334 -105
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +23 -0
- package/dist/ask.js.map +1 -1
- package/dist/brains/adapter.d.ts +16 -2
- package/dist/brains/adapter.d.ts.map +1 -1
- package/dist/brains/adapter.js.map +1 -1
- package/dist/brains/index.d.ts.map +1 -1
- package/dist/brains/index.js +2 -1
- package/dist/brains/index.js.map +1 -1
- package/dist/brains/info.d.ts.map +1 -1
- package/dist/brains/info.js +22 -0
- package/dist/brains/info.js.map +1 -1
- package/dist/brains/opencode-bridge.d.ts +2 -0
- package/dist/brains/opencode-bridge.d.ts.map +1 -0
- package/dist/brains/opencode-bridge.js +332 -0
- package/dist/brains/opencode-bridge.js.map +1 -0
- package/dist/brains/opencode.d.ts +25 -0
- package/dist/brains/opencode.d.ts.map +1 -0
- package/dist/brains/opencode.js +491 -0
- package/dist/brains/opencode.js.map +1 -0
- package/dist/catalog.d.ts +8 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +100 -1
- package/dist/catalog.js.map +1 -1
- package/dist/codex-live.d.ts +12 -0
- package/dist/codex-live.d.ts.map +1 -0
- package/dist/codex-live.js +188 -0
- package/dist/codex-live.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/flags.d.ts.map +1 -1
- package/dist/flags.js +7 -5
- package/dist/flags.js.map +1 -1
- package/dist/humanize.d.ts.map +1 -1
- package/dist/humanize.js +19 -2
- package/dist/humanize.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/open.d.ts +109 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +338 -0
- package/dist/open.js.map +1 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +4 -2
- package/dist/options.js.map +1 -1
- package/dist/panes.d.ts +118 -0
- package/dist/panes.d.ts.map +1 -0
- package/dist/panes.js +480 -0
- package/dist/panes.js.map +1 -0
- package/dist/process.d.ts +36 -0
- package/dist/process.d.ts.map +1 -1
- package/dist/process.js +120 -2
- package/dist/process.js.map +1 -1
- package/dist/run.d.ts +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +13 -5
- package/dist/run.js.map +1 -1
- package/dist/sessions.d.ts +137 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/sessions.js +1023 -0
- package/dist/sessions.js.map +1 -0
- package/dist/status.d.ts +1 -1
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +28 -7
- package/dist/status.js.map +1 -1
- package/dist/subscription-limits.d.ts +12 -0
- package/dist/subscription-limits.d.ts.map +1 -0
- package/dist/subscription-limits.js +281 -0
- package/dist/subscription-limits.js.map +1 -0
- package/dist/types.d.ts +25 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/dist/usage-readers.d.ts +16 -0
- package/dist/usage-readers.d.ts.map +1 -0
- package/dist/usage-readers.js +194 -0
- package/dist/usage-readers.js.map +1 -0
- package/dist/usage.d.ts +71 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +403 -0
- package/dist/usage.js.map +1 -0
- package/package.json +7 -23
- package/README.ru.md +0 -334
- package/dist/cli/main.d.ts +0 -3
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js +0 -520
- package/dist/cli/main.js.map +0 -1
- package/dist/cli/term.d.ts +0 -20
- package/dist/cli/term.d.ts.map +0 -1
- package/dist/cli/term.js +0 -87
- package/dist/cli/term.js.map +0 -1
- package/dist/ui/dashboard.html +0 -693
- package/dist/ui/page.d.ts +0 -9
- package/dist/ui/page.d.ts.map +0 -1
- package/dist/ui/page.js +0 -12
- package/dist/ui/page.js.map +0 -1
- package/dist/ui/server.d.ts +0 -20
- package/dist/ui/server.d.ts.map +0 -1
- package/dist/ui/server.js +0 -409
- package/dist/ui/server.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,93 +1,141 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<img src="docs/assets/logo.svg" width="72" height="72" alt="">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/logo.svg" width="72" height="72" alt="">
|
|
4
4
|
|
|
5
5
|
# Brainyard
|
|
6
6
|
|
|
7
|
-
**One interface to the coding agents you already have: Claude Code, Codex and
|
|
7
|
+
**One interface to the coding agents you already have: Claude Code, Codex, Antigravity and OpenCode.**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
An app to watch and drive them, in a terminal or in a browser, and an API to drive them from
|
|
10
|
+
your own program: status and subscription limits, one-shot answers, runs with a live feed,
|
|
11
|
+
sessions you come back to, and CLI sessions in tmux panes that outlive whatever started them.
|
|
12
12
|
|
|
13
13
|
[](https://github.com/antondanv/brainyard/actions/workflows/ci.yml)
|
|
14
14
|
[](https://www.npmjs.com/package/@antondanv/brainyard)
|
|
15
15
|

|
|
16
16
|

|
|
17
|
-
[](LICENSE)
|
|
17
|
+
[](https://github.com/antondanv/brainyard/blob/v0.3.0/LICENSE)
|
|
18
18
|
|
|
19
|
-
**English** · [Русский](README.ru.md)
|
|
19
|
+
**English** · [Русский](https://github.com/antondanv/brainyard/blob/v0.3.0/README.ru.md)
|
|
20
20
|
|
|
21
|
-
<img src="docs/assets/
|
|
21
|
+
<img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-terminal.png" width="860" alt="The Brainyard app in a terminal window: a card for each agent with its subscription limits as bars, the panes and what each CLI does, a session running in another folder, and this folder's sessions with their tokens and cost">
|
|
22
22
|
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Two packages
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
CLI that never exits because its stdin is still open, a turn that ends silently after a refused
|
|
32
|
-
tool.
|
|
33
|
-
|
|
34
|
-
Brainyard gives them one API. The same options, the same events and the same errors for all
|
|
35
|
-
three, with the workarounds built in. It drives the CLIs you installed with your own accounts.
|
|
36
|
-
It runs no service, calls no model API and holds no keys.
|
|
37
|
-
|
|
38
|
-
It was extracted from a production system that runs all three CLIs every day. Most of the
|
|
39
|
-
behaviour below exists because a real run failed without it ([battle-tested quirks](docs/gotchas.md)).
|
|
40
|
-
|
|
41
|
-
## Features
|
|
42
|
-
|
|
43
|
-
- **Status in one command.** Installed? Which version? Signed in, and how? Which models and
|
|
44
|
-
reasoning efforts? All of it free where the CLI allows. `--live` proves each CLI with a
|
|
45
|
-
one-word call; for Claude Code it also shows how much of your 5-hour and 7-day windows is used.
|
|
46
|
-
- **`ask()`.** One prompt, one answer, isolated from your project: no `CLAUDE.md`, hooks or
|
|
47
|
-
MCP servers leaking into the prompt.
|
|
48
|
-
- **`start()` / `run()`.** An agent in a folder, streaming one closed list of events
|
|
49
|
-
(`message`, `command`, `file_write`, `tool_call`…) with a human-readable line for each.
|
|
50
|
-
- **Steering.** `hint()` sends a message to an agent while it works (Claude Code,
|
|
51
|
-
Antigravity). `stop()` stops it and everything it started.
|
|
52
|
-
- **Sessions.** Every run returns a `sessionId`; pass it as `resume` to continue.
|
|
53
|
-
- **Models and effort.** Asked from each CLI itself and checked before a run: Claude Code
|
|
54
|
-
silently ignores an effort it does not know, so you would pay for something you did not pick.
|
|
55
|
-
- **Access levels.** `full`, `workspace` and `readonly`, mapped to each CLI's own permission and
|
|
56
|
-
sandbox flags. Verified live, including "nothing outside the folder gets written".
|
|
57
|
-
- **MCP servers per run.** One config shape, delivered the way each CLI needs it, with no
|
|
58
|
-
global config touched.
|
|
59
|
-
- **Typed failures.** `usage_limit` (with the reset time), `rate_limited`, `not_logged_in`,
|
|
60
|
-
`network`… so you know whether to wait a minute, wait until 6:50pm or sign in.
|
|
61
|
-
- **Dashboard.** `brainyard ui` opens status cards and a playground over a local, token-guarded
|
|
62
|
-
HTTP API that other languages can use too.
|
|
63
|
-
- **No runtime dependencies.**
|
|
64
|
-
|
|
65
|
-
## Install
|
|
27
|
+
| Package | What is in it | For |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `@antondanv/brainyard-cli` | The full one: the `brainyard` command — the app in a terminal, `brainyard web` in a browser, commands for scripts and a local HTTP API | You, at the keyboard |
|
|
30
|
+
| `@antondanv/brainyard` | The light one: the API alone, with no runtime dependencies — status, asks, runs, sessions, panes, usage | Your program |
|
|
66
31
|
|
|
67
32
|
```sh
|
|
68
|
-
npm install -g @antondanv/brainyard # the
|
|
69
|
-
npm install @antondanv/brainyard
|
|
33
|
+
npm install -g @antondanv/brainyard-cli # the app, the browser, the commands
|
|
34
|
+
npm install @antondanv/brainyard # the API for your program
|
|
70
35
|
```
|
|
71
36
|
|
|
72
|
-
You need Node.js 22+ and at least
|
|
37
|
+
The command is built on the API, so both say and do the same. You need Node.js 22+ and at least
|
|
38
|
+
one agent CLI:
|
|
73
39
|
|
|
74
40
|
| CLI | Install | Sign in |
|
|
75
41
|
|---|---|---|
|
|
76
42
|
| Claude Code | `npm install -g @anthropic-ai/claude-code` | run `claude` once |
|
|
77
43
|
| Codex | `npm install -g @openai/codex` | `codex login` |
|
|
78
44
|
| Antigravity | `curl -fsSL https://antigravity.google/cli/install.sh \| bash` | run `agy` once |
|
|
45
|
+
| OpenCode | `npm install -g opencode-ai` | `opencode auth login` for a provider (its free models need none) |
|
|
46
|
+
|
|
47
|
+
## Why
|
|
48
|
+
|
|
49
|
+
Claude Code, Codex, Antigravity and OpenCode are excellent agents, and each speaks its own
|
|
50
|
+
dialect: its own flags, stream format and way to resume a session, pass an MCP server, pick an
|
|
51
|
+
effort or report a usage limit. Each also has quirks that only show up in real runs: a prompt
|
|
52
|
+
starting with `---` read as a command-line option, a CLI that never exits because its stdin is
|
|
53
|
+
still open, a turn that ends silently after a refused tool.
|
|
54
|
+
|
|
55
|
+
Brainyard gives them one face. For you, one app shows every agent, what is left of its
|
|
56
|
+
subscription, its sessions and its live panes. For your program, one API has the same options,
|
|
57
|
+
events and errors for all four, with the workarounds built in. It drives the CLIs you installed,
|
|
58
|
+
with your own accounts: it runs no service, calls no model API and holds no keys.
|
|
59
|
+
|
|
60
|
+
It was extracted from a production system that runs these CLIs every day. Most of what follows
|
|
61
|
+
exists because a real run failed without it ([battle-tested quirks](https://github.com/antondanv/brainyard/blob/v0.3.0/docs/gotchas.md)).
|
|
62
|
+
|
|
63
|
+
## The app
|
|
64
|
+
|
|
65
|
+
`brainyard` in a terminal is one full-screen app; piped or in a script it prints the status
|
|
66
|
+
table instead. A card for each agent shows its sign-in and its subscription limits as bars
|
|
67
|
+
(Claude Code's are the ones its own `/usage` fetched last); then the panes, with what each CLI
|
|
68
|
+
does, its memory and how long it has been quiet; sessions running in other folders; and this
|
|
69
|
+
folder's sessions with their tokens and cost. It keeps reading all of it while it is open and
|
|
70
|
+
makes no paid call of its own. It speaks English or Russian.
|
|
71
|
+
|
|
72
|
+
Enter goes into the selected pane, full screen, and Ctrl+Q comes back; on an agent Enter starts
|
|
73
|
+
a new pane of it, on a saved session it continues the session in a pane. `n` starts a new pane
|
|
74
|
+
in this folder (choose the CLI), `x` closes a pane (what was said in it stays), `s` stops a
|
|
75
|
+
Claude Code background session, `r` continues a saved session, Tab jumps between sections, `?`
|
|
76
|
+
lists the keys and `q` quits; the panes keep running. Russian keyboard letters work by their
|
|
77
|
+
place on the keyboard.
|
|
78
|
+
|
|
79
|
+
Digits 1–5 (or `[` `]`) open its pages. **Wall** — the live screens of several panes side by
|
|
80
|
+
side, the way a tiling compositor shows windows: a grid, one main tile and a stack, or columns
|
|
81
|
+
(`l`). Arrows move the focus, `z` zooms the tile, `i` types into it (every key, Ctrl+C included,
|
|
82
|
+
goes to its CLI until Ctrl+Q), Enter takes it full screen and `n` starts a new tile to type
|
|
83
|
+
into. Each pane is made the size of its tile. A tile turns yellow while its agent waits for
|
|
84
|
+
you; the header counts who waits, and the terminal rings when someone starts to.
|
|
85
|
+
|
|
86
|
+
<img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-wall.png" width="860" alt="The wall: a Codex pane waiting for an approval and a Claude Code pane at work, side by side, each in its tile">
|
|
87
|
+
|
|
88
|
+
<table>
|
|
89
|
+
<tr>
|
|
90
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-pane.png" alt="A pane full screen: Claude Code at work, and the bar below with the way back"><br><b>A pane</b>, full screen: every key goes to its CLI; Ctrl+Q — back.</td>
|
|
91
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-sessions.png" alt="The sessions page: a list with a filter and the selected session's card"><br><b>Sessions</b> — what runs elsewhere and this folder's sessions; <code>/</code> filters; a card with the tokens and the command that continues the session in its own CLI.</td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-usage.png" alt="The usage page: every subscription window as a bar, the folder's tokens and cost by CLI, the sessions that used the most"><br><b>Usage</b> — every subscription window as a bar, the folder's tokens and cost by CLI, the sessions that used the most.</td>
|
|
95
|
+
<td width="50%"><img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-settings.png" alt="The settings page: language, theme, accent, the wall's layout, the bell and the first page, with a preview"><br><b>Settings</b> — language, theme, accent, the wall's layout, the bell and the first page, kept in <code>~/.config/brainyard/app.json</code>, where <code>"colors"</code> takes your own.</td>
|
|
96
|
+
</tr>
|
|
97
|
+
</table>
|
|
98
|
+
|
|
99
|
+
In a terminal the app leaves the mouse to it, so selecting and copying text works anywhere. The
|
|
100
|
+
pictures are of `npm run demo`, the app on a made-up machine.
|
|
101
|
+
|
|
102
|
+
### In a browser
|
|
103
|
+
|
|
104
|
+
`brainyard web` opens the same app in a browser on this machine. The server draws the frames a
|
|
105
|
+
terminal would show and the page paints them cell for cell, so the pages, the wall, the
|
|
106
|
+
dialogs, the theme and the language are the same.
|
|
107
|
+
|
|
108
|
+
<img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/app-browser.png" width="860" alt="The same app in a Chrome window at 127.0.0.1:4747: the agents' cards, the panes and the sessions, as in the terminal">
|
|
109
|
+
|
|
110
|
+
Keys work as in the terminal. A click opens a tab, selects a row, focuses a tile or picks a
|
|
111
|
+
setting; a double click is Enter; the wheel moves the selection; dragging selects text to copy.
|
|
112
|
+
Enter on a pane shows its CLI full screen, with every key going to it and the wheel scrolling
|
|
113
|
+
back through what it printed, until Ctrl+Q or a click on the bar below. `q` quits the app and
|
|
114
|
+
the command with it; the panes keep running.
|
|
115
|
+
|
|
116
|
+
The same server has the dashboard at `/dashboard` (`brainyard ui` serves it alone): a status
|
|
117
|
+
card for each CLI and a playground to ask a question or run an agent with a live feed, hints,
|
|
118
|
+
stop and "continue this session".
|
|
119
|
+
|
|
120
|
+
<img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.3.0/docs/assets/dashboard.png" width="860" alt="The dashboard: a status card for each of the four CLIs, with version, account, binary, capabilities and models, and the playground below with a prompt to ask Claude Code">
|
|
121
|
+
|
|
122
|
+
Both listen on `127.0.0.1` behind the same token, `Host` and `Origin` guard as the
|
|
123
|
+
[HTTP API](#http-api), which stays under `/api/`.
|
|
79
124
|
|
|
80
125
|
## Command line
|
|
81
126
|
|
|
127
|
+
**Status.** Piped or in a script, `brainyard` prints this table, as `brainyard status` does:
|
|
128
|
+
|
|
82
129
|
```console
|
|
83
|
-
$ brainyard
|
|
84
|
-
Brainyard 0.
|
|
130
|
+
$ brainyard status
|
|
131
|
+
Brainyard 0.3.0
|
|
85
132
|
|
|
86
133
|
● Claude Code 2.1.280 ready signed in with claude.ai, pro
|
|
87
134
|
● Codex 0.153.4 ready signed in with ChatGPT · default model gpt-6-astra
|
|
88
135
|
● Antigravity 1.2.13 ready signed in · model list fetched with your account
|
|
136
|
+
● OpenCode 1.18.34 ready signed in with opencode, sber · default model sber/GigaChat-3-Pro
|
|
89
137
|
|
|
90
|
-
|
|
138
|
+
4 of 4 ready · 3.6s · prove each with a real call: brainyard status --live
|
|
91
139
|
```
|
|
92
140
|
|
|
93
141
|
**Ask.** The answer goes to stdout and the details to stderr, so pipes work as they look:
|
|
@@ -126,28 +174,90 @@ session 32a4caae-… · continue: brainyard run claude --resume 32a4caae-… "
|
|
|
126
174
|
`ask` and `run` read piped stdin and append it to the prompt; that waits for end of input, so a
|
|
127
175
|
script that leaves stdin open should pass `--no-stdin`.
|
|
128
176
|
|
|
177
|
+
**Sessions and panes.** `sessions --live` shows what runs on the machine right now, in every
|
|
178
|
+
CLI, and what it waits for. A pane is a CLI session in tmux that outlives the terminal: start
|
|
179
|
+
it, read its screen, type into it, take it full screen and close it; the conversation stays
|
|
180
|
+
resumable. A pane is named by its name or the start of its name or session id. Text selected
|
|
181
|
+
with the mouse in a full-screen pane goes to the system clipboard (`pbcopy`, `wl-copy`, `xclip`
|
|
182
|
+
or `xsel`; `BRAINYARD_COPY_COMMAND` names another).
|
|
183
|
+
|
|
184
|
+
```console
|
|
185
|
+
$ brainyard sessions --live
|
|
186
|
+
Claude Code 2dcf2506 24m ~/Projects/Brainyard CLI for the whole API ● working ▣ claude-a6d7c603
|
|
187
|
+
Claude Code 381a87e4 21h ~/Projects/shop Retry failed payments bg ● blocked
|
|
188
|
+
|
|
189
|
+
$ pane=$(brainyard pane start claude --name "release notes" "Draft the 0.2 release notes")
|
|
190
|
+
$ brainyard pane send $pane "Shorter, please" # the text, then Enter as a key of its own
|
|
191
|
+
$ brainyard pane show $pane # its screen as text
|
|
192
|
+
$ brainyard pane attach $pane # full screen; Ctrl+Q — back, it keeps running
|
|
193
|
+
$ brainyard pane close $pane
|
|
194
|
+
closed claude-1a2b3c4d · resume: brainyard pane start claude --resume 7c919bf9-…
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Usage.** What each subscription has left, and what the folder's sessions used. No model is
|
|
198
|
+
called unless you pass `--live`; `--prices` turns tokens into dollars.
|
|
199
|
+
|
|
200
|
+
```console
|
|
201
|
+
$ brainyard usage
|
|
202
|
+
Subscription limits
|
|
203
|
+
Claude Code 5h reset since seen weekly 100% · resets in 1d 12h seen 7h ago
|
|
204
|
+
Codex 5h 52% · resets in 2h 36m weekly 32% · resets in 5d 11h seen 35m ago
|
|
205
|
+
Antigravity Gemini Models: weekly 1% · resets in 3d 21h 5h 0% · resets in 1h 27m
|
|
206
|
+
Claude and GPT models: weekly 4% · resets in 3d 21h 5h 2% · resets in 2h 50m
|
|
207
|
+
OpenCode Connect OpenCode Go in OpenCode or provide OPENCODE_API_KEY to read subscription usage.
|
|
208
|
+
|
|
209
|
+
Sessions of ~/Projects/Brainyard
|
|
210
|
+
input output cache reasoning cost
|
|
211
|
+
Claude Code 2dcf2506 now CLI for the whole API 226 207k 31M 117k no price
|
|
212
|
+
Codex 01a10742 35m Usage in the API 825k 122k 17M 58k no price
|
|
213
|
+
total 2 sessions 825k 329k 48M 175k + 2 without a price
|
|
214
|
+
```
|
|
215
|
+
|
|
129
216
|
| Command | What it does |
|
|
130
217
|
|---|---|
|
|
131
|
-
| `brainyard
|
|
218
|
+
| `brainyard` | The app, full screen: agents and their limits, panes, sessions, usage; piped — the status |
|
|
219
|
+
| `brainyard status` | Which CLIs are installed, signed in and ready (`--live`, `--models`, `--json`) |
|
|
132
220
|
| `brainyard models [brain…]` | Models and efforts each CLI offers |
|
|
133
221
|
| `brainyard ask <brain\|all> <prompt>` | One prompt, one answer (`--model`, `--effort`, `--system`, `--web`) |
|
|
134
222
|
| `brainyard run <brain> <prompt>` | An agent with a live feed (`--cwd`, `--resume`, `--access`, `--mcp`, `--no-web`, `--json`) |
|
|
223
|
+
| `brainyard sessions [brain…]` | Sessions of this folder, running ones marked; `--live` — what runs on the machine now (`--all`, `--cwd`, `--json`) |
|
|
224
|
+
| `brainyard stop <session>` | Stops a Claude Code background session; its conversation stays |
|
|
225
|
+
| `brainyard open <brain> [prompt]` | A CLI here, as a session you come back to (`--resume`, `--name`, `--bg`) |
|
|
226
|
+
| `brainyard panes` | Live panes: CLI, session, memory, quiet time, folder (`--json`) |
|
|
227
|
+
| `brainyard pane start\|attach\|show\|send\|close` | A CLI session in a tmux pane that outlives the terminal |
|
|
228
|
+
| `brainyard usage [brain…]` | Subscription limits; tokens and cost of this folder's sessions (`--limits`, `--prices`, `--offline`, `--live`) |
|
|
229
|
+
| `brainyard web` | The app in a browser, on `http://127.0.0.1:4747` (`--port`, `--no-open`) |
|
|
135
230
|
| `brainyard ui` | The dashboard on `http://127.0.0.1:4747` |
|
|
231
|
+
| `brainyard serve` | The HTTP API alone, for scripts in any language (`--json`, `$BRAINYARD_TOKEN`) |
|
|
136
232
|
|
|
137
|
-
Brains are `claude`, `codex
|
|
233
|
+
Brains are `claude`, `codex`, `antigravity` (alias `agy`) and `opencode`. `brainyard help` lists every flag.
|
|
138
234
|
|
|
139
235
|
## Library
|
|
140
236
|
|
|
237
|
+
`@antondanv/brainyard` is what the app is built on, and all it does is a function your program
|
|
238
|
+
can call. Each takes a `brain` — `claude`, `codex`, `antigravity` or `opencode` — and the same
|
|
239
|
+
options for all four.
|
|
240
|
+
|
|
241
|
+
### Status and one-shot answers
|
|
242
|
+
|
|
141
243
|
```ts
|
|
142
|
-
import { ask,
|
|
244
|
+
import { ask, status } from '@antondanv/brainyard';
|
|
143
245
|
|
|
144
246
|
// Who is ready? Free checks; `live: true` adds a one-word call to each.
|
|
145
|
-
const { ready } = await status(); // ['claude', 'codex', 'antigravity']
|
|
247
|
+
const { ready } = await status(); // ['claude', 'codex', 'antigravity', 'opencode']
|
|
146
248
|
|
|
147
249
|
// One prompt, one answer.
|
|
148
250
|
const { text, costUsd } = await ask('codex', 'One-line summary of RFC 9110?', { effort: 'low' });
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
`ask()` runs in a fresh temporary folder, read-only and without your project's `CLAUDE.md`,
|
|
254
|
+
hooks or MCP servers, and throws a `BrainyardError` with a `kind` on any failure.
|
|
255
|
+
|
|
256
|
+
### An agent in a folder
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import { run, start } from '@antondanv/brainyard';
|
|
149
260
|
|
|
150
|
-
// An agent in a folder, event by event.
|
|
151
261
|
const agent = start({
|
|
152
262
|
brain: 'claude',
|
|
153
263
|
cwd: './app',
|
|
@@ -169,7 +279,10 @@ if (!result.ok) console.error(result.error); // { kind: 'usage_limit', resetsAt:
|
|
|
169
279
|
await run({ brain: 'claude', cwd: './app', resume: result.sessionId, prompt: 'Now add a benchmark' });
|
|
170
280
|
```
|
|
171
281
|
|
|
172
|
-
|
|
282
|
+
`hint()` reaches Claude Code, Antigravity and OpenCode while they work; `stop()` stops the
|
|
283
|
+
agent and everything it started. `result` rejects only when the run never started (bad options,
|
|
284
|
+
CLI not installed); once the CLI has started, it resolves: check `result.ok`. MCP servers for
|
|
285
|
+
one run go in one shape, delivered the way each CLI needs them, with no global config touched:
|
|
173
286
|
|
|
174
287
|
```ts
|
|
175
288
|
await run({
|
|
@@ -181,15 +294,122 @@ await run({
|
|
|
181
294
|
});
|
|
182
295
|
```
|
|
183
296
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
297
|
+
More in [`examples/`](https://github.com/antondanv/brainyard/blob/v0.3.0/examples).
|
|
298
|
+
|
|
299
|
+
### Sessions you come back to
|
|
187
300
|
|
|
188
|
-
|
|
301
|
+
```ts
|
|
302
|
+
import { liveSessions, open, sessions } from '@antondanv/brainyard';
|
|
303
|
+
|
|
304
|
+
// This folder's sessions in every CLI, newest first; a running one has `live`.
|
|
305
|
+
for (const session of await sessions({ cwd: './app' })) {
|
|
306
|
+
console.log(session.brain, session.id, session.title, session.live?.status);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// What runs on the machine right now, and who waits for you.
|
|
310
|
+
const waiting = (await liveSessions()).filter((session) => session.live?.status === 'waiting');
|
|
311
|
+
|
|
312
|
+
// The CLI itself in this terminal, until the person leaves it; then the way back in.
|
|
313
|
+
const { sessionId } = await open({ brain: 'claude', cwd: './app', name: 'review', prompt: 'Review the open PR' });
|
|
314
|
+
await open({ brain: 'claude', cwd: './app', resume: sessionId });
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
`sessions()` lists what the CLI's own picker lists: headless runs stay out unless
|
|
318
|
+
`headless: true`. `liveSessions()` reads each CLI's current turn: `busy`, `waiting` (and what
|
|
319
|
+
for) or `idle`. Recent Codex versions leave their approval dialogs out of the rollout, so
|
|
320
|
+
`liveSessions({ panes: {} })` also reads the dialogs on screen in Brainyard's panes.
|
|
321
|
+
`open({ background: true })` starts a Claude Code background session, and
|
|
322
|
+
`stopSession({ brain: 'claude', sessionId, cwd })` stops it with `claude stop`; the
|
|
323
|
+
conversation stays and can be opened again.
|
|
324
|
+
|
|
325
|
+
`open()` and `startPane()` take `system`, standing instructions kept out of the conversation
|
|
326
|
+
where the CLI has a slot for them: Claude Code's system prompt, Codex's `developer_instructions`
|
|
327
|
+
(its own instructions stay) and the system prompt of OpenCode's `build` and `plan` agents (set
|
|
328
|
+
through `OPENCODE_CONFIG_CONTENT`; it replaces OpenCode's own base prompt for them, while its
|
|
329
|
+
tools, `AGENTS.md` and environment block stay). Antigravity has no such slot: its agents and
|
|
330
|
+
rules are files under `.agents/` or `~/.gemini`, which Brainyard does not write, so there the
|
|
331
|
+
instructions go in front of the first message. With a `system` and no `prompt`, Claude Code,
|
|
332
|
+
Codex and OpenCode open and wait for you; Antigravity starts with the instructions as its
|
|
333
|
+
first message.
|
|
334
|
+
|
|
335
|
+
### Panes
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import { capturePane, closePane, listPanes, sendToPane, startPane } from '@antondanv/brainyard';
|
|
339
|
+
|
|
340
|
+
// A CLI session in tmux: it keeps running when this program exits.
|
|
341
|
+
const { pane } = await startPane({ brain: 'claude', cwd: './app', label: 'flaky test', prompt: 'Fix the flaky test' });
|
|
342
|
+
|
|
343
|
+
const screen = await capturePane(pane); // its rows with their colours, the cursor, the size
|
|
344
|
+
await sendToPane(pane, 'Run it ten times first');
|
|
345
|
+
await sendToPane(pane, '\r'); // Enter as a key of its own, as a person presses it
|
|
346
|
+
|
|
347
|
+
for (const each of await listPanes()) console.log(each.pane, each.brain, each.label, each.activityAt);
|
|
348
|
+
|
|
349
|
+
await closePane(pane); // the CLI ends; its conversation can be resumed
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Panes live on a tmux server of their own (`tmux -L brainyard`), so they outlive the terminal,
|
|
353
|
+
the app and your program, and the app, `brainyard pane …` and your program all see the same
|
|
354
|
+
ones. `attachPane(pane)` shows a pane full screen in this terminal until Ctrl+Q;
|
|
355
|
+
`resizePane()` fits it to your view; `findPaneSession()` finds the session a Codex,
|
|
356
|
+
Antigravity or OpenCode pane started (Claude Code's is known at once); `panesAvailable()` says
|
|
357
|
+
whether tmux is there.
|
|
358
|
+
|
|
359
|
+
### Usage and subscription limits
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import { usage } from '@antondanv/brainyard';
|
|
363
|
+
|
|
364
|
+
const report = await usage({ cwd: './app', prices }); // your dollars per million tokens, per model
|
|
365
|
+
for (const session of report.sessions) console.log(session.brain, session.id, session.usage, session.costUsd);
|
|
366
|
+
for (const brain of report.brains) console.log(brain.brain, brain.limits, brain.limitsObservedAt);
|
|
367
|
+
|
|
368
|
+
const limitsOnly = await usage({ limit: 0 }); // the account's windows, no sessions
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
`usage()` reads the saved sessions of `cwd` (the current folder by default) in all four CLIs,
|
|
372
|
+
and the windows of each subscription:
|
|
373
|
+
|
|
374
|
+
| CLI | Tokens and cost of saved sessions | Subscription limits |
|
|
375
|
+
|---|---|---|
|
|
376
|
+
| Claude Code | Whole transcript, counted once per message id; estimate from `prices` | What Claude Code itself fetched last (its `/usage`), kept in `~/.claude.json`; `rate_limit_event` with `live: true` |
|
|
377
|
+
| Codex | Last cumulative rollout total; cost by each turn's model | Freshest rollout snapshots across the account's store |
|
|
378
|
+
| Antigravity | Generation metadata in `conversations/<id>.db`; estimate from `prices` | `agy -p /usage --output-format json`: weekly and five-hour quotas by model group |
|
|
379
|
+
| OpenCode | Assistant messages in `opencode.db`, or retained session totals; reported cost or estimate from `prices` | OpenCode Go API: rolling, weekly and monthly windows |
|
|
380
|
+
|
|
381
|
+
- **No model is called** unless you pass `live: true`: one minimal, isolated Claude call with a
|
|
382
|
+
30-second timeout, which can cost money. Antigravity and OpenCode Go answer metadata requests
|
|
383
|
+
without a turn; `offline: true` skips those too and reads the stores only.
|
|
384
|
+
- **Options.** `brains` picks the CLIs, `sessionId` one session, `limit` the sessions per CLI
|
|
385
|
+
(200 by default, `0` for the limits alone), `limits: false` the sessions alone (every
|
|
386
|
+
window comes back `not_requested`), `headless: true` adds headless runs, `homes` other stores.
|
|
387
|
+
- **Windows** carry `utilization` as a fraction (`0.95` is 95%), `windowMinutes`, `resetsAt` in
|
|
388
|
+
Unix seconds, a `limitId` per quota bucket and, for Antigravity and Claude Code's per-model
|
|
389
|
+
windows, `group` and `label`. Their source and the time they were seen come along: an old
|
|
390
|
+
snapshot is not a live check, and a window whose reset has passed says nothing about now.
|
|
391
|
+
- **Claude Code's windows** are read for free from its global file (`~/.claude.json`, or the
|
|
392
|
+
one in `CLAUDE_CONFIG_DIR`); a cache of another account than the one signed in is left out
|
|
393
|
+
(`limitsUnavailable: 'other_account'`).
|
|
394
|
+
- **OpenCode Go** takes `OPENCODE_GO_API_KEY` or `OPENCODE_API_KEY`, then the keys for
|
|
395
|
+
`opencode-go`/`opencode` in its `auth.json` (or `OPENCODE_AUTH_CONTENT`); an `apiKey` in
|
|
396
|
+
OpenCode's config wins over a stored one. Antigravity needs a signed-in CLI 1.1.11 or later
|
|
397
|
+
and runs `/usage` in a private empty folder.
|
|
398
|
+
- **Nothing is passed off as zero.** Data that cannot be read is `null` with a reason
|
|
399
|
+
(`unavailableReason`, `limitsUnavailable`, `detail`); a total that cannot be priced is
|
|
400
|
+
`null`. `byModel` splits each session by model. Estimates describe model usage, not what the
|
|
401
|
+
subscription costs.
|
|
402
|
+
|
|
403
|
+
### Reference
|
|
404
|
+
|
|
405
|
+
The options of `start()`, `run()` and `ask()`, what `access` means in each CLI, the events, and what
|
|
406
|
+
each CLI can do.
|
|
407
|
+
|
|
408
|
+
#### Options
|
|
189
409
|
|
|
190
410
|
| Option | Default | |
|
|
191
411
|
|---|---|---|
|
|
192
|
-
| `brain` | | `claude`, `codex` or `
|
|
412
|
+
| `brain` | | `claude`, `codex`, `antigravity` or `opencode` |
|
|
193
413
|
| `prompt` | | Sent on stdin, never as an argument |
|
|
194
414
|
| `cwd` | `process.cwd()` | Where the agent works (`ask()`: a fresh temporary folder) |
|
|
195
415
|
| `model`, `effort` | the CLI's | Checked against the CLI's catalog before the run |
|
|
@@ -200,24 +420,25 @@ any failure. More in [`examples/`](examples).
|
|
|
200
420
|
| `steerable` | where supported | Keep stdin open for `hint()` |
|
|
201
421
|
| `nudge` | `true` | A turn that ends without text gets one follow-up in the same conversation |
|
|
202
422
|
| `timeoutMs` | none | A run killed halfway is paid for in full, so there is no default limit |
|
|
203
|
-
| `
|
|
423
|
+
| `env` | | Extra environment for the CLI. A value of `undefined` (or `null`) removes the variable the CLI would inherit: `env: { NODE_ENV: undefined }` keeps a host's `NODE_ENV=production` from reaching the agent, where `npm install` would skip devDependencies. The same for `open()` and `startPane()` (in a pane it is an `unset` in the pane's shell) |
|
|
424
|
+
| `signal`, `onEvent`, `extraArgs`, `command`, `prices`, `includeRaw` | | |
|
|
204
425
|
|
|
205
|
-
|
|
426
|
+
#### Access levels
|
|
206
427
|
|
|
207
428
|
A headless agent has nobody to ask for permission, so a tool that needs approval is simply
|
|
208
429
|
refused. Pick the level up front:
|
|
209
430
|
|
|
210
|
-
| `access` | Claude Code | Codex | Antigravity |
|
|
211
|
-
|
|
212
|
-
| `full` | every tool, no prompts | every tool, no sandbox | every tool, no prompts |
|
|
213
|
-
| `workspace` | edits and commands in its sandbox, confined to `cwd` | `workspace-write` sandbox | edits; its sandbox refuses most commands |
|
|
214
|
-
| `readonly` | reads and searches only | `read-only` sandbox | plan mode: writes refused |
|
|
431
|
+
| `access` | Claude Code | Codex | Antigravity | OpenCode |
|
|
432
|
+
|---|---|---|---|---|
|
|
433
|
+
| `full` | every tool, no prompts | every tool, no sandbox | every tool, no prompts | every tool; `--auto` approves paths outside `cwd` |
|
|
434
|
+
| `workspace` | edits and commands in its sandbox, confined to `cwd` | `workspace-write` sandbox | edits; its sandbox refuses most commands | edits inside `cwd`; no shell, since it has no sandbox |
|
|
435
|
+
| `readonly` | reads and searches only | `read-only` sandbox | plan mode: writes refused | edits and shell refused |
|
|
215
436
|
|
|
216
437
|
Checked with real runs on every CLI: in `workspace`, a file inside `cwd` gets written and a
|
|
217
438
|
write to the home directory fails. In `readonly`, nothing gets written. See
|
|
218
|
-
[`scripts/live-check.ts`](scripts/live-check.ts).
|
|
439
|
+
[`scripts/live-check.ts`](https://github.com/antondanv/brainyard/blob/v0.3.0/scripts/live-check.ts).
|
|
219
440
|
|
|
220
|
-
|
|
441
|
+
#### Events
|
|
221
442
|
|
|
222
443
|
Every CLI's stream becomes the same closed list. Each event has a `summary`: one line for
|
|
223
444
|
humans, with paths shortened and secrets masked. `feed: false` marks ceremony that is true but
|
|
@@ -235,45 +456,45 @@ not news (a reasoning block, a successful tool result).
|
|
|
235
456
|
| `error` / `stopped` | Something broke / the run was stopped |
|
|
236
457
|
| `done` | Always last |
|
|
237
458
|
|
|
238
|
-
|
|
459
|
+
#### What each CLI can do
|
|
239
460
|
|
|
240
|
-
| | Claude Code | Codex | Antigravity |
|
|
241
|
-
|
|
242
|
-
| Messages while it works (`hint`) | ✓ | — | ✓ |
|
|
243
|
-
| Resume a session | ✓ | ✓ | ✓ |
|
|
244
|
-
| MCP servers per run | ✓ | ✓ | ✓ |
|
|
245
|
-
| Reports dollar cost | ✓ | tokens only | tokens only |
|
|
246
|
-
| Lists its models | aliases | ✓ | ✓ |
|
|
247
|
-
| Web can be switched off | ✓ | ✓ | — (warns) |
|
|
248
|
-
| Shell can be switched off | ✓ | sandboxed instead | — (warns) |
|
|
249
|
-
| Subscription
|
|
461
|
+
| | Claude Code | Codex | Antigravity | OpenCode |
|
|
462
|
+
|---|:-:|:-:|:-:|:-:|
|
|
463
|
+
| Messages while it works (`hint`) | ✓ | — | ✓ | ✓ through its server |
|
|
464
|
+
| Resume a session | ✓ | ✓ | ✓ | ✓ |
|
|
465
|
+
| MCP servers per run | ✓ | ✓ | ✓ | ✓ |
|
|
466
|
+
| Reports dollar cost | ✓ | tokens only | tokens only | ✓ where the provider has prices |
|
|
467
|
+
| Lists its models | aliases | ✓ | ✓ | ✓ |
|
|
468
|
+
| Web can be switched off | ✓ | ✓ | — (warns) | ✓ |
|
|
469
|
+
| Shell can be switched off | ✓ | sandboxed instead | — (warns) | ✓ |
|
|
470
|
+
| Subscription windows (`usage`) | its `/usage` cache; a live call | rollout snapshots | `/usage` command | Go API |
|
|
250
471
|
|
|
251
472
|
An option a CLI cannot honour is never dropped silently: it comes back as a `warning` event and
|
|
252
473
|
in `result.warnings`.
|
|
253
474
|
|
|
254
|
-
##
|
|
475
|
+
## HTTP API
|
|
255
476
|
|
|
256
|
-
`brainyard
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
477
|
+
`brainyard serve` runs the API alone, for scripts in any language: status, asks and runs with a
|
|
478
|
+
live feed, sessions, stopping background ones, usage and panes. `brainyard web` and
|
|
479
|
+
`brainyard ui` serve the same API under `/api/`. Every endpoint is in
|
|
480
|
+
[`docs/http-api.md`](https://github.com/antondanv/brainyard/blob/v0.3.0/docs/http-api.md).
|
|
260
481
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
482
|
+
```sh
|
|
483
|
+
BRAINYARD_TOKEN=secret-for-scripts brainyard serve --json
|
|
484
|
+
{"url":"http://127.0.0.1:4747","port":4747,"token":"secret-for-scripts"}
|
|
485
|
+
```
|
|
265
486
|
|
|
266
487
|
The API can start agents on your machine, so it is guarded like it: it listens on `127.0.0.1`,
|
|
267
|
-
every call needs the token
|
|
268
|
-
|
|
488
|
+
every call needs the token, the `Host` header must name the server (against DNS rebinding), and
|
|
489
|
+
writes are accepted only as same-origin JSON.
|
|
269
490
|
|
|
270
491
|
## Battle-tested quirks
|
|
271
492
|
|
|
272
493
|
A few of the things Brainyard handles so you don't have to. The full list, with symptoms and
|
|
273
|
-
fixes, is in [`docs/gotchas.md`](docs/gotchas.md).
|
|
494
|
+
fixes, is in [`docs/gotchas.md`](https://github.com/antondanv/brainyard/blob/v0.3.0/docs/gotchas.md).
|
|
274
495
|
|
|
275
496
|
- **Prompts never go on the command line.** Claude Code's `-p` is a boolean flag, so a prompt
|
|
276
|
-
starting with `---` becomes `error: unknown option`.
|
|
497
|
+
starting with `---` becomes `error: unknown option`. Every CLI gets the prompt on stdin.
|
|
277
498
|
- **stdin is closed exactly when the turn ends.** With stream-json input the CLI treats stdin
|
|
278
499
|
as a conversation and waits for the next message forever. The finished work would hang until
|
|
279
500
|
killed.
|
|
@@ -285,15 +506,23 @@ fixes, is in [`docs/gotchas.md`](docs/gotchas.md).
|
|
|
285
506
|
without a word after a refused tool. A new process would not remember what it tripped over.
|
|
286
507
|
- **A usage limit is not a 429.** One is retried in seconds, the other resets in hours, and
|
|
287
508
|
the CLI says when. Brainyard keeps that time for you.
|
|
509
|
+
- **OpenCode has no final event, and a refused tool ends its turn without a word.** The reason
|
|
510
|
+
the last step finished tells a finished turn from a cut-off one, and Brainyard has the agent
|
|
511
|
+
hear a refusal out and answer.
|
|
288
512
|
|
|
289
513
|
## How it is tested
|
|
290
514
|
|
|
291
|
-
- **
|
|
292
|
-
speak each dialect. Like the real CLIs, the fakes never exit while stdin is
|
|
293
|
-
that forgets to close it hangs the test instead of passing it.
|
|
515
|
+
- **440 tests** run the real code against fake `claude`, `codex`, `agy` and `opencode`
|
|
516
|
+
executables that speak each dialect. Like the real CLIs, the fakes never exit while stdin is
|
|
517
|
+
open, so a runner that forgets to close it hangs the test instead of passing it.
|
|
518
|
+
- **The app** is a pure function from its state to the rows of the screen, so its frames are
|
|
519
|
+
tested as they are; it is also driven end to end in a real tmux of the test's own (never the
|
|
520
|
+
`brainyard` server you work in), in a terminal and through `brainyard web` over HTTP.
|
|
294
521
|
- **`npm run live`** runs every check against the real CLIs with the cheapest models: ask, a
|
|
295
522
|
prompt starting with dashes, an agent run, a hint, resume, MCP, and the access matrix. Last
|
|
296
523
|
run: Claude Code 2.1.280, Codex 0.153.4, Antigravity 1.2.13, all 21 checks passed for about $0.20.
|
|
524
|
+
OpenCode 1.18.34 passed all 7 on GigaChat 3 Pro and on the free `opencode/big-pickle`
|
|
525
|
+
(`BRAINYARD_LIVE_OPENCODE_MODEL` picks the model).
|
|
297
526
|
|
|
298
527
|
## FAQ
|
|
299
528
|
|
|
@@ -310,14 +539,14 @@ inside a container.
|
|
|
310
539
|
**Windows?** Not tested yet. Batch shims (`claude.cmd`) are handled, but the CI runs on Linux
|
|
311
540
|
and macOS.
|
|
312
541
|
|
|
313
|
-
**What about Gemini CLI
|
|
314
|
-
|
|
542
|
+
**What about Gemini CLI or Cursor?** Not yet. Adding a CLI means an adapter plus a live check,
|
|
543
|
+
and a CLI goes in once it passes one. OpenCode went in that way.
|
|
315
544
|
|
|
316
545
|
## Contributing
|
|
317
546
|
|
|
318
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md). Bug reports that include `brainyard status --json` and
|
|
547
|
+
See [CONTRIBUTING.md](https://github.com/antondanv/brainyard/blob/v0.3.0/CONTRIBUTING.md). Bug reports that include `brainyard status --json` and
|
|
319
548
|
the CLI version help most.
|
|
320
549
|
|
|
321
550
|
## License
|
|
322
551
|
|
|
323
|
-
[MIT](LICENSE)
|
|
552
|
+
[MIT](https://github.com/antondanv/brainyard/blob/v0.3.0/LICENSE)
|
package/dist/ask.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../src/ask.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../src/ask.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGjE,wBAAsB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAmD/G;AAoBD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;CAAO,GACtF,OAAO,CAAC,WAAW,EAAE,CAAC,CAgBxB"}
|
package/dist/ask.js
CHANGED
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
10
10
|
import { tmpdir } from 'node:os';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
|
+
import { ADAPTERS } from './brains/index.js';
|
|
12
13
|
import { BRAINS } from './brains/info.js';
|
|
13
14
|
import { BrainyardError } from './errors.js';
|
|
15
|
+
import { commandFor } from './options.js';
|
|
16
|
+
import { applyEnv, capture } from './process.js';
|
|
14
17
|
import { startAnswer } from './run.js';
|
|
15
18
|
import { BRAIN_IDS } from './types.js';
|
|
16
19
|
export async function ask(brain, prompt, options = {}) {
|
|
@@ -33,6 +36,7 @@ export async function ask(brain, prompt, options = {}) {
|
|
|
33
36
|
...(options.prices !== undefined ? { prices: options.prices } : {}),
|
|
34
37
|
}, options.system);
|
|
35
38
|
const result = await agent.result;
|
|
39
|
+
await forget(result.brain, result.sessionId, options);
|
|
36
40
|
if (!result.ok) {
|
|
37
41
|
throw BrainyardError.from(result.error ?? { kind: 'failed', message: 'the run failed', retryable: false }, result.brain);
|
|
38
42
|
}
|
|
@@ -61,6 +65,25 @@ export async function ask(brain, prompt, options = {}) {
|
|
|
61
65
|
rmSync(dir, { recursive: true, force: true });
|
|
62
66
|
}
|
|
63
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* An answer is not a conversation to come back to. Claude Code and Codex are
|
|
70
|
+
* told not to keep it; a CLI that cannot be told deletes it afterwards. Best
|
|
71
|
+
* effort: the answer does not depend on it.
|
|
72
|
+
*/
|
|
73
|
+
async function forget(brain, sessionId, options) {
|
|
74
|
+
const args = sessionId ? ADAPTERS[brain].forget?.(sessionId) : undefined;
|
|
75
|
+
if (!args)
|
|
76
|
+
return;
|
|
77
|
+
try {
|
|
78
|
+
await capture(commandFor(brain, options.command), args, {
|
|
79
|
+
timeoutMs: 15_000,
|
|
80
|
+
env: applyEnv(process.env, options.env),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Not installed any more, or gone already: nothing to clean.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
64
87
|
/**
|
|
65
88
|
* The same prompt to several CLIs at once. Never throws: each entry carries
|
|
66
89
|
* an answer or the reason there is none. Per-brain model and effort choices
|