@antondanv/brainyard 0.1.0 → 0.2.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +322 -104
  3. package/dist/ask.d.ts.map +1 -1
  4. package/dist/ask.js +23 -0
  5. package/dist/ask.js.map +1 -1
  6. package/dist/brains/adapter.d.ts +16 -2
  7. package/dist/brains/adapter.d.ts.map +1 -1
  8. package/dist/brains/adapter.js.map +1 -1
  9. package/dist/brains/index.d.ts.map +1 -1
  10. package/dist/brains/index.js +2 -1
  11. package/dist/brains/index.js.map +1 -1
  12. package/dist/brains/info.d.ts.map +1 -1
  13. package/dist/brains/info.js +22 -0
  14. package/dist/brains/info.js.map +1 -1
  15. package/dist/brains/opencode-bridge.d.ts +2 -0
  16. package/dist/brains/opencode-bridge.d.ts.map +1 -0
  17. package/dist/brains/opencode-bridge.js +332 -0
  18. package/dist/brains/opencode-bridge.js.map +1 -0
  19. package/dist/brains/opencode.d.ts +14 -0
  20. package/dist/brains/opencode.d.ts.map +1 -0
  21. package/dist/brains/opencode.js +474 -0
  22. package/dist/brains/opencode.js.map +1 -0
  23. package/dist/catalog.d.ts +8 -1
  24. package/dist/catalog.d.ts.map +1 -1
  25. package/dist/catalog.js +100 -1
  26. package/dist/catalog.js.map +1 -1
  27. package/dist/codex-live.d.ts +12 -0
  28. package/dist/codex-live.d.ts.map +1 -0
  29. package/dist/codex-live.js +188 -0
  30. package/dist/codex-live.js.map +1 -0
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/errors.js +2 -0
  33. package/dist/errors.js.map +1 -1
  34. package/dist/flags.d.ts.map +1 -1
  35. package/dist/flags.js +7 -5
  36. package/dist/flags.js.map +1 -1
  37. package/dist/humanize.d.ts.map +1 -1
  38. package/dist/humanize.js +19 -2
  39. package/dist/humanize.js.map +1 -1
  40. package/dist/index.d.ts +8 -4
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +8 -4
  43. package/dist/index.js.map +1 -1
  44. package/dist/open.d.ts +87 -0
  45. package/dist/open.d.ts.map +1 -0
  46. package/dist/open.js +324 -0
  47. package/dist/open.js.map +1 -0
  48. package/dist/options.d.ts.map +1 -1
  49. package/dist/options.js +4 -2
  50. package/dist/options.js.map +1 -1
  51. package/dist/panes.d.ts +118 -0
  52. package/dist/panes.d.ts.map +1 -0
  53. package/dist/panes.js +478 -0
  54. package/dist/panes.js.map +1 -0
  55. package/dist/process.d.ts +26 -0
  56. package/dist/process.d.ts.map +1 -1
  57. package/dist/process.js +92 -2
  58. package/dist/process.js.map +1 -1
  59. package/dist/run.d.ts +1 -1
  60. package/dist/run.d.ts.map +1 -1
  61. package/dist/run.js +11 -3
  62. package/dist/run.js.map +1 -1
  63. package/dist/sessions.d.ts +137 -0
  64. package/dist/sessions.d.ts.map +1 -0
  65. package/dist/sessions.js +1023 -0
  66. package/dist/sessions.js.map +1 -0
  67. package/dist/status.d.ts +1 -1
  68. package/dist/status.d.ts.map +1 -1
  69. package/dist/status.js +28 -7
  70. package/dist/status.js.map +1 -1
  71. package/dist/subscription-limits.d.ts +12 -0
  72. package/dist/subscription-limits.d.ts.map +1 -0
  73. package/dist/subscription-limits.js +281 -0
  74. package/dist/subscription-limits.js.map +1 -0
  75. package/dist/types.d.ts +14 -8
  76. package/dist/types.d.ts.map +1 -1
  77. package/dist/types.js +2 -2
  78. package/dist/types.js.map +1 -1
  79. package/dist/usage-readers.d.ts +16 -0
  80. package/dist/usage-readers.d.ts.map +1 -0
  81. package/dist/usage-readers.js +194 -0
  82. package/dist/usage-readers.js.map +1 -0
  83. package/dist/usage.d.ts +71 -0
  84. package/dist/usage.d.ts.map +1 -0
  85. package/dist/usage.js +403 -0
  86. package/dist/usage.js.map +1 -0
  87. package/package.json +7 -23
  88. package/README.ru.md +0 -334
  89. package/dist/cli/main.d.ts +0 -3
  90. package/dist/cli/main.d.ts.map +0 -1
  91. package/dist/cli/main.js +0 -520
  92. package/dist/cli/main.js.map +0 -1
  93. package/dist/cli/term.d.ts +0 -20
  94. package/dist/cli/term.d.ts.map +0 -1
  95. package/dist/cli/term.js +0 -87
  96. package/dist/cli/term.js.map +0 -1
  97. package/dist/ui/dashboard.html +0 -693
  98. package/dist/ui/page.d.ts +0 -9
  99. package/dist/ui/page.d.ts.map +0 -1
  100. package/dist/ui/page.js +0 -12
  101. package/dist/ui/page.js.map +0 -1
  102. package/dist/ui/server.d.ts +0 -20
  103. package/dist/ui/server.d.ts.map +0 -1
  104. package/dist/ui/server.js +0 -409
  105. 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.2.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 Antigravity.**
7
+ **One interface to the coding agents you already have: Claude Code, Codex, Antigravity and OpenCode.**
8
8
 
9
- See which are installed and signed in, ask them one-shot questions, or run an agent in a folder
10
- and watch a live, human-readable feed of what it does. From the terminal, from TypeScript, or
11
- from a local dashboard.
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
  [![CI](https://github.com/antondanv/brainyard/actions/workflows/ci.yml/badge.svg)](https://github.com/antondanv/brainyard/actions/workflows/ci.yml)
14
14
  [![npm](https://img.shields.io/npm/v/@antondanv/brainyard?color=6d7dfc)](https://www.npmjs.com/package/@antondanv/brainyard)
15
15
  ![node](https://img.shields.io/badge/node-%E2%89%A522-3c873a)
16
16
  ![dependencies](https://img.shields.io/badge/runtime%20dependencies-0-3c873a)
17
- [![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
17
+ [![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/antondanv/brainyard/blob/v0.2.0/LICENSE)
18
18
 
19
- **English** · [Русский](README.ru.md)
19
+ **English** · [Русский](https://github.com/antondanv/brainyard/blob/v0.2.0/README.ru.md)
20
20
 
21
- <img src="docs/assets/dashboard.png" width="860" alt="The Brainyard dashboard: three status cards, and a Claude Code run that wrote fib.py, ran it and reported the output">
21
+ <img src="https://raw.githubusercontent.com/antondanv/brainyard/v0.2.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
- ## Why
25
+ ## Two packages
26
26
 
27
- Claude Code, Codex and Antigravity are all excellent headless agents, and all three speak a
28
- different dialect: different flags, different stream formats, different ways to resume a
29
- session, pass an MCP server, pick an effort level or report a usage limit. Each also has quirks
30
- that only show up in real runs: a prompt starting with `---` read as a command-line option, a
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 `brainyard` command
69
- npm install @antondanv/brainyard # the library
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 one agent CLI:
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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.1.0
130
+ $ brainyard status
131
+ Brainyard 0.2.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
- 3 of 3 ready · 3.6s · prove each with a real call: brainyard status --live
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 [status]` | Which CLIs are installed, signed in and ready (`--live`, `--models`, `--json`) |
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` and `antigravity` (alias `agy`). `brainyard help` lists every flag.
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, run, start, status } from '@antondanv/brainyard';
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
- MCP servers for one run:
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,112 @@ await run({
181
294
  });
182
295
  ```
183
296
 
184
- `result` rejects only when the run never started (bad options, CLI not installed). Once the CLI
185
- has started, it resolves: check `result.ok`. `ask()` throws a `BrainyardError` with a `kind` on
186
- any failure. More in [`examples/`](examples).
297
+ More in [`examples/`](https://github.com/antondanv/brainyard/blob/v0.2.0/examples).
298
+
299
+ ### Sessions you come back to
300
+
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
+ ### Panes
326
+
327
+ ```ts
328
+ import { capturePane, closePane, listPanes, sendToPane, startPane } from '@antondanv/brainyard';
329
+
330
+ // A CLI session in tmux: it keeps running when this program exits.
331
+ const { pane } = await startPane({ brain: 'claude', cwd: './app', label: 'flaky test', prompt: 'Fix the flaky test' });
332
+
333
+ const screen = await capturePane(pane); // its rows with their colours, the cursor, the size
334
+ await sendToPane(pane, 'Run it ten times first');
335
+ await sendToPane(pane, '\r'); // Enter as a key of its own, as a person presses it
336
+
337
+ for (const each of await listPanes()) console.log(each.pane, each.brain, each.label, each.activityAt);
338
+
339
+ await closePane(pane); // the CLI ends; its conversation can be resumed
340
+ ```
187
341
 
188
- ### Options
342
+ Panes live on a tmux server of their own (`tmux -L brainyard`), so they outlive the terminal,
343
+ the app and your program, and the app, `brainyard pane …` and your program all see the same
344
+ ones. `attachPane(pane)` shows a pane full screen in this terminal until Ctrl+Q;
345
+ `resizePane()` fits it to your view; `findPaneSession()` finds the session a Codex,
346
+ Antigravity or OpenCode pane started (Claude Code's is known at once); `panesAvailable()` says
347
+ whether tmux is there.
348
+
349
+ ### Usage and subscription limits
350
+
351
+ ```ts
352
+ import { usage } from '@antondanv/brainyard';
353
+
354
+ const report = await usage({ cwd: './app', prices }); // your dollars per million tokens, per model
355
+ for (const session of report.sessions) console.log(session.brain, session.id, session.usage, session.costUsd);
356
+ for (const brain of report.brains) console.log(brain.brain, brain.limits, brain.limitsObservedAt);
357
+
358
+ const limitsOnly = await usage({ limit: 0 }); // the account's windows, no sessions
359
+ ```
360
+
361
+ `usage()` reads the saved sessions of `cwd` (the current folder by default) in all four CLIs,
362
+ and the windows of each subscription:
363
+
364
+ | CLI | Tokens and cost of saved sessions | Subscription limits |
365
+ |---|---|---|
366
+ | 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` |
367
+ | Codex | Last cumulative rollout total; cost by each turn's model | Freshest rollout snapshots across the account's store |
368
+ | Antigravity | Generation metadata in `conversations/<id>.db`; estimate from `prices` | `agy -p /usage --output-format json`: weekly and five-hour quotas by model group |
369
+ | OpenCode | Assistant messages in `opencode.db`, or retained session totals; reported cost or estimate from `prices` | OpenCode Go API: rolling, weekly and monthly windows |
370
+
371
+ - **No model is called** unless you pass `live: true`: one minimal, isolated Claude call with a
372
+ 30-second timeout, which can cost money. Antigravity and OpenCode Go answer metadata requests
373
+ without a turn; `offline: true` skips those too and reads the stores only.
374
+ - **Options.** `brains` picks the CLIs, `sessionId` one session, `limit` the sessions per CLI
375
+ (200 by default, `0` for the limits alone), `limits: false` the sessions alone (every
376
+ window comes back `not_requested`), `headless: true` adds headless runs, `homes` other stores.
377
+ - **Windows** carry `utilization` as a fraction (`0.95` is 95%), `windowMinutes`, `resetsAt` in
378
+ Unix seconds, a `limitId` per quota bucket and, for Antigravity and Claude Code's per-model
379
+ windows, `group` and `label`. Their source and the time they were seen come along: an old
380
+ snapshot is not a live check, and a window whose reset has passed says nothing about now.
381
+ - **Claude Code's windows** are read for free from its global file (`~/.claude.json`, or the
382
+ one in `CLAUDE_CONFIG_DIR`); a cache of another account than the one signed in is left out
383
+ (`limitsUnavailable: 'other_account'`).
384
+ - **OpenCode Go** takes `OPENCODE_GO_API_KEY` or `OPENCODE_API_KEY`, then the keys for
385
+ `opencode-go`/`opencode` in its `auth.json` (or `OPENCODE_AUTH_CONTENT`); an `apiKey` in
386
+ OpenCode's config wins over a stored one. Antigravity needs a signed-in CLI 1.1.11 or later
387
+ and runs `/usage` in a private empty folder.
388
+ - **Nothing is passed off as zero.** Data that cannot be read is `null` with a reason
389
+ (`unavailableReason`, `limitsUnavailable`, `detail`); a total that cannot be priced is
390
+ `null`. `byModel` splits each session by model. Estimates describe model usage, not what the
391
+ subscription costs.
392
+
393
+ ### Reference
394
+
395
+ The options of `start()`, `run()` and `ask()`, what `access` means in each CLI, the events, and what
396
+ each CLI can do.
397
+
398
+ #### Options
189
399
 
190
400
  | Option | Default | |
191
401
  |---|---|---|
192
- | `brain` | | `claude`, `codex` or `antigravity` |
402
+ | `brain` | | `claude`, `codex`, `antigravity` or `opencode` |
193
403
  | `prompt` | | Sent on stdin, never as an argument |
194
404
  | `cwd` | `process.cwd()` | Where the agent works (`ask()`: a fresh temporary folder) |
195
405
  | `model`, `effort` | the CLI's | Checked against the CLI's catalog before the run |
@@ -202,22 +412,22 @@ any failure. More in [`examples/`](examples).
202
412
  | `timeoutMs` | none | A run killed halfway is paid for in full, so there is no default limit |
203
413
  | `signal`, `onEvent`, `env`, `extraArgs`, `command`, `prices`, `includeRaw` | | |
204
414
 
205
- ### Access levels
415
+ #### Access levels
206
416
 
207
417
  A headless agent has nobody to ask for permission, so a tool that needs approval is simply
208
418
  refused. Pick the level up front:
209
419
 
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 |
420
+ | `access` | Claude Code | Codex | Antigravity | OpenCode |
421
+ |---|---|---|---|---|
422
+ | `full` | every tool, no prompts | every tool, no sandbox | every tool, no prompts | every tool; `--auto` approves paths outside `cwd` |
423
+ | `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 |
424
+ | `readonly` | reads and searches only | `read-only` sandbox | plan mode: writes refused | edits and shell refused |
215
425
 
216
426
  Checked with real runs on every CLI: in `workspace`, a file inside `cwd` gets written and a
217
427
  write to the home directory fails. In `readonly`, nothing gets written. See
218
- [`scripts/live-check.ts`](scripts/live-check.ts).
428
+ [`scripts/live-check.ts`](https://github.com/antondanv/brainyard/blob/v0.2.0/scripts/live-check.ts).
219
429
 
220
- ### Events
430
+ #### Events
221
431
 
222
432
  Every CLI's stream becomes the same closed list. Each event has a `summary`: one line for
223
433
  humans, with paths shortened and secrets masked. `feed: false` marks ceremony that is true but
@@ -235,45 +445,45 @@ not news (a reasoning block, a successful tool result).
235
445
  | `error` / `stopped` | Something broke / the run was stopped |
236
446
  | `done` | Always last |
237
447
 
238
- ### What each CLI can do
448
+ #### What each CLI can do
239
449
 
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 window usage | ✓ | — | — |
450
+ | | Claude Code | Codex | Antigravity | OpenCode |
451
+ |---|:-:|:-:|:-:|:-:|
452
+ | Messages while it works (`hint`) | ✓ | — | ✓ | ✓ through its server |
453
+ | Resume a session | ✓ | ✓ | ✓ | ✓ |
454
+ | MCP servers per run | ✓ | ✓ | ✓ | ✓ |
455
+ | Reports dollar cost | ✓ | tokens only | tokens only | ✓ where the provider has prices |
456
+ | Lists its models | aliases | ✓ | ✓ | ✓ |
457
+ | Web can be switched off | ✓ | ✓ | — (warns) | ✓ |
458
+ | Shell can be switched off | ✓ | sandboxed instead | — (warns) | ✓ |
459
+ | Subscription windows (`usage`) | its `/usage` cache; a live call | rollout snapshots | `/usage` command | Go API |
250
460
 
251
461
  An option a CLI cannot honour is never dropped silently: it comes back as a `warning` event and
252
462
  in `result.warnings`.
253
463
 
254
- ## Dashboard and HTTP API
464
+ ## HTTP API
255
465
 
256
- `brainyard ui` serves the dashboard shown at the top: status cards and a playground to ask
257
- questions or run agents with a live feed, hints, stop and "continue this session". **Live
258
- check** sends each CLI a one-word prompt and shows how much of Claude Code's subscription
259
- windows is used, or why a CLI did not answer:
466
+ `brainyard serve` runs the API alone, for scripts in any language: status, asks and runs with a
467
+ live feed, sessions, stopping background ones, usage and panes. `brainyard web` and
468
+ `brainyard ui` serve the same API under `/api/`. Every endpoint is in
469
+ [`docs/http-api.md`](https://github.com/antondanv/brainyard/blob/v0.2.0/docs/http-api.md).
260
470
 
261
- <img src="docs/assets/live-check.png" width="860" alt="Live check: Claude Code and Antigravity answered pong, Codex shows the error for a model its ChatGPT account cannot use; Claude Code also shows its 5-hour and 7-day subscription windows">
262
-
263
- The dashboard uses a small HTTP API you can call from any language:
264
- [`docs/http-api.md`](docs/http-api.md).
471
+ ```sh
472
+ BRAINYARD_TOKEN=secret-for-scripts brainyard serve --json
473
+ {"url":"http://127.0.0.1:4747","port":4747,"token":"secret-for-scripts"}
474
+ ```
265
475
 
266
476
  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 printed at start, the `Host` header must name the server (against
268
- DNS rebinding), and writes are accepted only as same-origin JSON.
477
+ every call needs the token, the `Host` header must name the server (against DNS rebinding), and
478
+ writes are accepted only as same-origin JSON.
269
479
 
270
480
  ## Battle-tested quirks
271
481
 
272
482
  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).
483
+ fixes, is in [`docs/gotchas.md`](https://github.com/antondanv/brainyard/blob/v0.2.0/docs/gotchas.md).
274
484
 
275
485
  - **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`. All three get the prompt on stdin.
486
+ starting with `---` becomes `error: unknown option`. Every CLI gets the prompt on stdin.
277
487
  - **stdin is closed exactly when the turn ends.** With stream-json input the CLI treats stdin
278
488
  as a conversation and waits for the next message forever. The finished work would hang until
279
489
  killed.
@@ -285,15 +495,23 @@ fixes, is in [`docs/gotchas.md`](docs/gotchas.md).
285
495
  without a word after a refused tool. A new process would not remember what it tripped over.
286
496
  - **A usage limit is not a 429.** One is retried in seconds, the other resets in hours, and
287
497
  the CLI says when. Brainyard keeps that time for you.
498
+ - **OpenCode has no final event, and a refused tool ends its turn without a word.** The reason
499
+ the last step finished tells a finished turn from a cut-off one, and Brainyard has the agent
500
+ hear a refusal out and answer.
288
501
 
289
502
  ## How it is tested
290
503
 
291
- - **144 tests** run the real code against fake `claude`, `codex` and `agy` executables that
292
- speak each dialect. Like the real CLIs, the fakes never exit while stdin is open, so a runner
293
- that forgets to close it hangs the test instead of passing it.
504
+ - **440 tests** run the real code against fake `claude`, `codex`, `agy` and `opencode`
505
+ executables that speak each dialect. Like the real CLIs, the fakes never exit while stdin is
506
+ open, so a runner that forgets to close it hangs the test instead of passing it.
507
+ - **The app** is a pure function from its state to the rows of the screen, so its frames are
508
+ tested as they are; it is also driven end to end in a real tmux of the test's own (never the
509
+ `brainyard` server you work in), in a terminal and through `brainyard web` over HTTP.
294
510
  - **`npm run live`** runs every check against the real CLIs with the cheapest models: ask, a
295
511
  prompt starting with dashes, an agent run, a hint, resume, MCP, and the access matrix. Last
296
512
  run: Claude Code 2.1.280, Codex 0.153.4, Antigravity 1.2.13, all 21 checks passed for about $0.20.
513
+ OpenCode 1.18.34 passed all 7 on GigaChat 3 Pro and on the free `opencode/big-pickle`
514
+ (`BRAINYARD_LIVE_OPENCODE_MODEL` picks the model).
297
515
 
298
516
  ## FAQ
299
517
 
@@ -310,14 +528,14 @@ inside a container.
310
528
  **Windows?** Not tested yet. Batch shims (`claude.cmd`) are handled, but the CI runs on Linux
311
529
  and macOS.
312
530
 
313
- **What about Gemini CLI, Cursor, opencode…?** Not yet. Adding a CLI means an adapter plus a
314
- live check, and a CLI goes in once it passes one.
531
+ **What about Gemini CLI or Cursor?** Not yet. Adding a CLI means an adapter plus a live check,
532
+ and a CLI goes in once it passes one. OpenCode went in that way.
315
533
 
316
534
  ## Contributing
317
535
 
318
- See [CONTRIBUTING.md](CONTRIBUTING.md). Bug reports that include `brainyard status --json` and
536
+ See [CONTRIBUTING.md](https://github.com/antondanv/brainyard/blob/v0.2.0/CONTRIBUTING.md). Bug reports that include `brainyard status --json` and
319
537
  the CLI version help most.
320
538
 
321
539
  ## License
322
540
 
323
- [MIT](LICENSE)
541
+ [MIT](https://github.com/antondanv/brainyard/blob/v0.2.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":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,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,CAkD/G;AAED,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"}
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 { 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: { ...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