@beunec/rivine 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -68
- package/dist/api/workspace.js +44 -4
- package/dist/index.js +6 -2
- package/dist/protocol/fsExecutor.js +36 -2
- package/dist/protocol/permissions.js +104 -0
- package/dist/protocol/runner.js +280 -85
- package/dist/protocol/shell.js +5 -2
- package/dist/runHeadless.js +6 -0
- package/dist/session.js +69 -3
- package/dist/ui/App.js +24 -4
- package/dist/ui/headless.js +5 -1
- package/dist/ui/slashCommands.js +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,35 +16,35 @@ files it reads and writes are **the ones already on your disk**, in the
|
|
|
16
16
|
directory you started it in, open in your editor, tracked by your git.
|
|
17
17
|
|
|
18
18
|
Nothing is uploaded. There is no "attach your repo" step and no sync. The
|
|
19
|
-
engine asks for a file, this client reads it, and the answer goes back
|
|
19
|
+
engine asks for a file, this client reads it, and the answer goes back, one
|
|
20
20
|
file at a time, only the ones it actually opens. A 40,000-file monorepo costs
|
|
21
21
|
nothing to start working in, because nothing is copied anywhere.
|
|
22
22
|
|
|
23
23
|
## What it does
|
|
24
24
|
|
|
25
25
|
- Reads, writes and edits files in your working directory
|
|
26
|
-
- Runs commands
|
|
27
|
-
-
|
|
28
|
-
|
|
26
|
+
- Runs commands: your shell, your PATH, your nvm/pyenv shims
|
|
27
|
+
- Runs as one mode, the same five as the web engine: Frontend, Backend,
|
|
28
|
+
Full Stack, Plan/Ask, or Security
|
|
29
29
|
- Asks you a question when a decision is genuinely yours to make
|
|
30
30
|
- Keeps a per-project memory in `.rivine/`, so tomorrow's session knows what
|
|
31
31
|
yesterday's did
|
|
32
32
|
|
|
33
33
|
## Running commands
|
|
34
34
|
|
|
35
|
-
Commands run in your own shell, in your working directory, streaming
|
|
35
|
+
Commands run in your own shell, in your working directory, streaming. You see
|
|
36
36
|
output as it is produced, not in one block when the command exits. A two-minute
|
|
37
37
|
install and a hung one no longer look the same.
|
|
38
38
|
|
|
39
39
|
Where the platform allows it the command gets a real terminal (a PTY), which
|
|
40
40
|
means `isatty` is true and tools behave the way they do when you run them by
|
|
41
41
|
hand: colour, progress bars, and the interactive prompts some of them open with.
|
|
42
|
-
If a command asks you something, type the answer and press Enter
|
|
42
|
+
If a command asks you something, type the answer and press Enter. While a
|
|
43
43
|
command is running your input goes to the command, not to the agent. `esc`
|
|
44
44
|
stops it; the agent sees the non-zero exit and decides what to do about it.
|
|
45
45
|
|
|
46
46
|
The terminal comes from `node-pty`, an optional dependency. If it cannot be
|
|
47
|
-
installed or a PTY cannot be allocated, commands still run and still stream
|
|
47
|
+
installed or a PTY cannot be allocated, commands still run and still stream,
|
|
48
48
|
just without a terminal. Nothing fails. `RIVINE_NO_PTY=1` forces the pipe path.
|
|
49
49
|
|
|
50
50
|
What you see and what the model is sent are deliberately different. Escape codes
|
|
@@ -56,11 +56,11 @@ cost more per turn than not having one.
|
|
|
56
56
|
## Mode and Rate
|
|
57
57
|
|
|
58
58
|
Two choices, both required, and neither is inferred from what you type. There is
|
|
59
|
-
no router
|
|
59
|
+
no router: no keyword matcher, no classifier, no extra model turn that reads
|
|
60
60
|
your request and picks a lane. A wrong guess sends a database migration to the
|
|
61
61
|
frontend agent and you never see the decision that was made for you.
|
|
62
62
|
|
|
63
|
-
### Mode
|
|
63
|
+
### Mode: what Rivine Code works on
|
|
64
64
|
|
|
65
65
|
Each Mode owns the task end to end: it searches the codebase, reads what it
|
|
66
66
|
needs, writes across as many files as the change requires, runs the build and
|
|
@@ -74,52 +74,52 @@ tests, and fixes what the terminal reports.
|
|
|
74
74
|
| `simple` | Plan, ask, document, refresh, ship | `4`, `-m simple`, `--plan` |
|
|
75
75
|
| `security` | Find, verify, and patch vulnerabilities | `5`, `-m security` |
|
|
76
76
|
|
|
77
|
-
`simple` is the only Mode with live web access
|
|
77
|
+
`simple` is the only Mode with live web access. Its work is the work that
|
|
78
78
|
depends on the world outside the repository. The build Modes are measured on
|
|
79
79
|
whether the software runs.
|
|
80
80
|
|
|
81
|
-
### Rate
|
|
81
|
+
### Rate: how edits apply
|
|
82
82
|
|
|
83
83
|
The engine runs on our servers. The decision about what happens to your machine
|
|
84
|
-
is made **here**, on your machine, before anything runs
|
|
84
|
+
is made **here**, on your machine, before anything runs, never on our servers.
|
|
85
85
|
|
|
86
86
|
| Rate | Applies without asking | How to choose |
|
|
87
87
|
|---|---|---|
|
|
88
88
|
| `manual` | Reads and read-only commands. Asks before every write, edit, or delete | `1`, `--rate manual` (default) |
|
|
89
89
|
| `bypass` | Writes and ordinary commands inside this project | `2`, `--rate bypass`, `--bypass` |
|
|
90
90
|
|
|
91
|
-
Three things ask in
|
|
91
|
+
Three things still ask in `manual`, because they are what you would want to see
|
|
92
92
|
even having said "just do it": credentials, anything outside the project
|
|
93
93
|
directory, and commands that are hard to undo (`rm -rf`, `git push --force`, a
|
|
94
|
-
deploy).
|
|
94
|
+
deploy). `bypass` does not ask. A path outside the project is refused there,
|
|
95
|
+
not approved.
|
|
95
96
|
|
|
96
97
|
The first interactive session asks for Mode, then Rate, before the prompt
|
|
97
|
-
opens
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
picker later.
|
|
98
|
+
opens, including for a one-shot `rivine "..."`. `-m …` and `--rate …` skip the
|
|
99
|
+
question you already answered on the command line. Shift+Tab toggles the Rate.
|
|
100
|
+
`/mode` and `/rate` reopen either picker later.
|
|
101
101
|
|
|
102
|
-
Without a terminal to ask on
|
|
102
|
+
Without a terminal to ask on (a pipe, CI, another agent driving this), `-m`
|
|
103
103
|
is required and the run stops with the list rather than guessing.
|
|
104
104
|
|
|
105
105
|
What stays gated:
|
|
106
106
|
|
|
107
107
|
- **Anything outside the project.** Refused in `bypass` (set
|
|
108
|
-
`RIVINE_ALLOW_OUTSIDE_PROJECT=1` if you mean it). Other
|
|
108
|
+
`RIVINE_ALLOW_OUTSIDE_PROJECT=1` if you mean it). Other Rates ask. The jail
|
|
109
109
|
resolves symlinks first, so a link pointing out of the directory is caught
|
|
110
110
|
rather than followed.
|
|
111
|
-
- **Credentials
|
|
112
|
-
`~/.aws`, service-account JSON. These ask on *read* too
|
|
111
|
+
- **Credentials:** every Rate except `bypass`. `.env`, `*.pem`, `~/.ssh`,
|
|
112
|
+
`~/.aws`, service-account JSON. These ask on *read* too. Reading one puts
|
|
113
113
|
a live secret into a model prompt.
|
|
114
|
-
- **Commands that are hard to undo
|
|
114
|
+
- **Commands that are hard to undo:** every Rate except `bypass`. `rm -rf`,
|
|
115
115
|
`git push`, `--force`, `git reset --hard`, `sudo`, `npm publish`, any
|
|
116
116
|
deploy, `terraform apply`.
|
|
117
|
-
- **Batch writes
|
|
117
|
+
- **Batch writes:** every Rate except `bypass`. Judged by their most
|
|
118
118
|
dangerous entry, so a safe first file cannot clear a whole batch.
|
|
119
119
|
|
|
120
|
-
One exemption: `.rivine
|
|
121
|
-
session start and appended to at the end of each turn. It writes without asking
|
|
122
|
-
|
|
120
|
+
One exemption: `.rivine/`, the agent's own notebook for this project, seeded at
|
|
121
|
+
session start and appended to at the end of each turn. It writes without asking,
|
|
122
|
+
for the same reason `.git/` does. It ships with its own
|
|
123
123
|
`.gitignore`.
|
|
124
124
|
|
|
125
125
|
## Commands
|
|
@@ -158,11 +158,11 @@ form that writes to the remote. It also refuses on `main`, and refuses if
|
|
|
158
158
|
There is no `/compact` or `/summarize`. Context is compacted on the server as
|
|
159
159
|
part of how the engine runs, so there is nothing here to trigger by hand.
|
|
160
160
|
Opening `rivine` in a directory you have used before continues that
|
|
161
|
-
directory's thread
|
|
161
|
+
directory's thread. Earlier turns are still in context, and the session says
|
|
162
162
|
so on startup.
|
|
163
163
|
|
|
164
164
|
Answers are single keys, and the keys are always printed: `y` allow, `n` skip,
|
|
165
|
-
`a` allow all this session, `esc` cancel. Choices are numbered
|
|
165
|
+
`a` allow all this session, `esc` cancel. Choices are numbered. Press the
|
|
166
166
|
number. Nothing here makes you type a word to answer a question.
|
|
167
167
|
|
|
168
168
|
`a` is offered for ordinary writes only. Credentials, paths outside the project
|
|
@@ -172,7 +172,7 @@ ones where per-operation consent still means something.
|
|
|
172
172
|
### Without a terminal
|
|
173
173
|
|
|
174
174
|
Piped, redirected, in CI, or driven by another tool, there is no keyboard to
|
|
175
|
-
read
|
|
175
|
+
read, so `rivine -p "..."` switches to a plain renderer with no cursor
|
|
176
176
|
movement and no repaint, safe to redirect to a log.
|
|
177
177
|
|
|
178
178
|
Anything that would prompt is **refused**, not auto-approved, and the refusal
|
|
@@ -188,7 +188,7 @@ rivine -m fullstack --rate bypass -p "..." # CI, on a machine you accept chang
|
|
|
188
188
|
|
|
189
189
|
Authorization Code with PKCE over a loopback redirect. Your browser opens to
|
|
190
190
|
`aselius.beunec.com/cli/authorize`, which recognises your existing session and
|
|
191
|
-
asks you to confirm this terminal, then redirects to `127.0.0.1:1455
|
|
191
|
+
asks you to confirm this terminal, then redirects to `127.0.0.1:1455`, a port
|
|
192
192
|
only a process on your own machine can listen on.
|
|
193
193
|
|
|
194
194
|
Device code (`--device`) exists for headless machines and is not the default,
|
|
@@ -205,19 +205,19 @@ is in use. In CI, set `RIVINE_TOKEN` and neither is touched.
|
|
|
205
205
|
**It is the same Aselius account, not a second one.** Auth0 only answers "who
|
|
206
206
|
is this person"; your cloudhandle, your BCID and your wallet live in Beunec's
|
|
207
207
|
own systems and are looked up from that answer. The terminal signs in through a
|
|
208
|
-
different OAuth client than the website, which is why you approve it separately
|
|
209
|
-
|
|
208
|
+
different OAuth client than the website, which is why you approve it separately,
|
|
209
|
+
but it resolves to the same identity, the same taskspaces and the same
|
|
210
210
|
credits. Sign in as the account you use on aselius.beunec.com and it is
|
|
211
211
|
literally the same you.
|
|
212
212
|
|
|
213
213
|
`rivine status` shows a `Renews:` line. If it says `no`, your session cannot
|
|
214
|
-
refresh itself and ends when the token expires
|
|
214
|
+
refresh itself and ends when the token expires. Sign in again when it does.
|
|
215
215
|
That depends on a tenant setting, not on anything you can change locally.
|
|
216
216
|
|
|
217
217
|
## MCP servers
|
|
218
218
|
|
|
219
219
|
Rivine hosts MCP servers **from your machine**, the same way Claude Code and
|
|
220
|
-
Codex do
|
|
220
|
+
Codex do, not from our cloud.
|
|
221
221
|
|
|
222
222
|
```
|
|
223
223
|
rivine mcp add playwright npx @playwright/mcp@latest
|
|
@@ -229,7 +229,7 @@ rivine mcp remove <name>
|
|
|
229
229
|
|
|
230
230
|
In a session, `/mcp` shows what connected and what didn't.
|
|
231
231
|
|
|
232
|
-
**Why on your machine.** A stdio server *is* a local process
|
|
232
|
+
**Why on your machine.** A stdio server *is* a local process: `npx`, `uvx`, a
|
|
233
233
|
docker container, a bridge to your own database. Nothing running in our cloud
|
|
234
234
|
can spawn it. And for remote servers, calling from here means your tokens stay
|
|
235
235
|
on your machine instead of in our infrastructure, and tool results never transit
|
|
@@ -241,7 +241,7 @@ as it asks it to read a file.
|
|
|
241
241
|
|
|
242
242
|
| File | For |
|
|
243
243
|
|---|---|
|
|
244
|
-
| `<project>/.rivine/mcp.json` | servers this repo needs
|
|
244
|
+
| `<project>/.rivine/mcp.json` | servers this repo needs, committable, so teammates get them |
|
|
245
245
|
| `~/.rivine/mcp.json` | servers you use everywhere (`--user`) |
|
|
246
246
|
|
|
247
247
|
Project wins on a name collision. Secrets are never stored: `env` values written
|
|
@@ -250,9 +250,8 @@ remote server's token is referenced by variable name (`--token-env`), never by
|
|
|
250
250
|
value.
|
|
251
251
|
|
|
252
252
|
**Permissions.** An MCP tool can read a database, drive a browser or post to an
|
|
253
|
-
API
|
|
254
|
-
Every call asks
|
|
255
|
-
not say whether it writes. "Allow all this session" is scoped to **one server**:
|
|
253
|
+
API, closer to running a command than reading a file, so it is gated like one.
|
|
254
|
+
Every call asks, because a tool's schema does not say whether it writes. "Allow all this session" is scoped to **one server**:
|
|
256
255
|
approving Playwright never silently approves a database server that connects
|
|
257
256
|
later.
|
|
258
257
|
|
|
@@ -261,20 +260,20 @@ startup. The others still connect and their tools are still offered.
|
|
|
261
260
|
|
|
262
261
|
**Only the tools a turn needs.** Rivine does not put every connected tool in
|
|
263
262
|
front of the model on every turn. Servers are scored against your prompt, and an
|
|
264
|
-
unrelated request gets none of them
|
|
263
|
+
unrelated request gets none of them. Asking to fix a typo does not hand the
|
|
265
264
|
model a browser. Naming a server always includes it (`use playwright to…`), and
|
|
266
265
|
a server comes in as a whole set, because a browser you can open but not drive
|
|
267
266
|
is worse than no browser. The session line tells you which servers were used and
|
|
268
267
|
which were skipped.
|
|
269
268
|
|
|
270
|
-
That is not only a cost control, though it is one
|
|
269
|
+
That is not only a cost control, though it is one. Every tool definition is
|
|
271
270
|
tokens you pay for on every turn. It is mostly a quality control: a model
|
|
272
271
|
holding a capability tends to find a reason to use it.
|
|
273
272
|
|
|
274
273
|
### Remote servers that need a sign-in
|
|
275
274
|
|
|
276
275
|
`--token-env` covers servers with a static API key. For hosted servers that
|
|
277
|
-
authenticate per user, there is nothing to paste
|
|
276
|
+
authenticate per user, there is nothing to paste. The credential does not
|
|
278
277
|
exist until you consent:
|
|
279
278
|
|
|
280
279
|
```bash
|
|
@@ -285,18 +284,18 @@ rivine mcp logout notion # forget it again
|
|
|
285
284
|
|
|
286
285
|
This opens your browser, runs the standard OAuth loopback flow against the
|
|
287
286
|
server's **own** authorization server, and stores the token in your OS
|
|
288
|
-
keychain
|
|
287
|
+
keychain, never in `.rivine/mcp.json`, which is a file people commit. If a
|
|
289
288
|
server publishes no OAuth metadata the command says so rather than guessing at
|
|
290
289
|
endpoints.
|
|
291
290
|
|
|
292
291
|
## In CI
|
|
293
292
|
|
|
294
293
|
```bash
|
|
295
|
-
rivine --output-format json -m bypass -p "fix the failing type errors"
|
|
294
|
+
rivine --output-format json -m fullstack --rate bypass -p "fix the failing type errors"
|
|
296
295
|
```
|
|
297
296
|
|
|
298
|
-
In `json` mode **stdout carries exactly one object** and everything else
|
|
299
|
-
tokens, notices, command output
|
|
297
|
+
In `json` mode **stdout carries exactly one object** and everything else,
|
|
298
|
+
tokens, notices, and command output, goes to stderr, so the stream stays safe to
|
|
300
299
|
pipe into `jq`:
|
|
301
300
|
|
|
302
301
|
```json
|
|
@@ -304,7 +303,7 @@ pipe into `jq`:
|
|
|
304
303
|
```
|
|
305
304
|
|
|
306
305
|
Exit codes are `0` success, `1` error, `2` out of credits (also if you run
|
|
307
|
-
`rivine` with no prompt and no terminal), and `3` nothing could be done
|
|
306
|
+
`rivine` with no prompt and no terminal), and `3` nothing could be done:
|
|
308
307
|
every operation needed approval and there was no terminal to give it. `3`
|
|
309
308
|
exists because that run still costs a turn: without it the step would go
|
|
310
309
|
green having changed nothing. The result object carries `refused` alongside
|
|
@@ -319,12 +318,14 @@ There is a composite action in `action.yml`:
|
|
|
319
318
|
RIVINE_TOKEN: ${{ secrets.RIVINE_TOKEN }}
|
|
320
319
|
with:
|
|
321
320
|
prompt: fix the failing type errors
|
|
321
|
+
mode: fullstack
|
|
322
322
|
```
|
|
323
323
|
|
|
324
|
-
`
|
|
325
|
-
anything on, and the headless renderer **refuses** rather than auto-approves
|
|
326
|
-
so
|
|
327
|
-
|
|
324
|
+
`rate` defaults to `bypass` because a workflow has no terminal to approve
|
|
325
|
+
anything on, and the headless renderer **refuses** rather than auto-approves,
|
|
326
|
+
so `manual` stops at the first write. `mode` is required: frontend, backend,
|
|
327
|
+
fullstack, simple, or security. Run it on a checkout you are willing to have
|
|
328
|
+
changed, and review the diff before merging.
|
|
328
329
|
|
|
329
330
|
One turn has to finish inside the engine's **15-minute ceiling**. Local
|
|
330
331
|
commands stream and are not the constraint; a single request that needs longer
|
|
@@ -333,19 +334,19 @@ than that is. Split the work across steps rather than raising the timeout.
|
|
|
333
334
|
## What the server stores
|
|
334
335
|
|
|
335
336
|
File operations travel through a mailbox table so the engine and your terminal
|
|
336
|
-
can hand work back and forth. Those rows carry real source
|
|
337
|
+
can hand work back and forth. Those rows carry real source. A write payload is
|
|
337
338
|
the file being written.
|
|
338
339
|
|
|
339
340
|
Each session generates an **AES-256 key on your machine**. It is sent once per
|
|
340
341
|
turn in the request body and held in memory for the length of that turn. It is
|
|
341
|
-
never written to disk here and never written to storage there
|
|
342
|
+
never written to disk here and never written to storage there, so no database
|
|
342
343
|
we keep, and no backup, replica or restore of one, contains the material needed
|
|
343
344
|
to open those rows. Rows are also deleted as soon as the engine has read them.
|
|
344
345
|
|
|
345
346
|
**This is not end-to-end encryption, and we will not call it that.** The engine
|
|
346
347
|
has to read your code to reason about it, so plaintext exists in server memory
|
|
347
348
|
while a turn is running. What the session key removes is every path that goes
|
|
348
|
-
through storage rather than through a live process
|
|
349
|
+
through storage rather than through a live process: a restored snapshot, a
|
|
349
350
|
backup bucket, a replica, a support query. That is the larger and longer-lived
|
|
350
351
|
half of the exposure, not all of it.
|
|
351
352
|
|
|
@@ -372,10 +373,10 @@ deployments:
|
|
|
372
373
|
|---|---|
|
|
373
374
|
| `RIVINE_API_URL` | `https://workspace.beunec.com` |
|
|
374
375
|
| `RIVINE_SITE_URL` | `https://aselius.beunec.com` |
|
|
375
|
-
| `RIVINE_TOKEN` | unset
|
|
376
|
-
| `RIVINE_NO_PTY` | unset
|
|
377
|
-
| `RIVINE_ALLOW_OUTSIDE_PROJECT` | unset
|
|
378
|
-
| `RIVINE_ASCII` | unset
|
|
376
|
+
| `RIVINE_TOKEN` | unset. A pre-issued token for CI |
|
|
377
|
+
| `RIVINE_NO_PTY` | unset. Set to `1` to run commands without a PTY |
|
|
378
|
+
| `RIVINE_ALLOW_OUTSIDE_PROJECT` | unset. Set to `1` only if `bypass` should be allowed to leave the project directory |
|
|
379
|
+
| `RIVINE_ASCII` | unset. Set to `1` for ASCII glyphs (narrow panes, no Unicode) |
|
|
379
380
|
|
|
380
381
|
Auth0 parameters are fetched from `GET /api/cli/config` at sign-in, so this
|
|
381
382
|
package carries no tenant configuration and a client-id change never requires
|
|
@@ -394,8 +395,8 @@ reads ./src/app.ts
|
|
|
394
395
|
◀─── SSE tokens ──────── answer streams back
|
|
395
396
|
```
|
|
396
397
|
|
|
397
|
-
The engine's file operations arrive as distinct verbs
|
|
398
|
-
`edit`, `execute
|
|
398
|
+
The engine's file operations arrive as distinct verbs, `read`, `write`,
|
|
399
|
+
`edit`, and `execute`, rather than as shell commands. That is what lets this
|
|
399
400
|
client tell a read from a write and apply the right policy, and it is why
|
|
400
401
|
nothing here needs Python on your machine.
|
|
401
402
|
|
|
@@ -417,15 +418,15 @@ tokens faster than any terminal can usefully repaint:
|
|
|
417
418
|
- Nothing is ever wider than your window. Paths truncate in the middle, keeping
|
|
418
419
|
both ends; command output keeps its tail, because that is where the error is.
|
|
419
420
|
- Colour degrades: TrueColor, 256, or 16, and `NO_COLOR` is honoured. Colour is
|
|
420
|
-
never the only signal
|
|
421
|
+
never the only signal. Every line kind has its own glyph, so the transcript
|
|
421
422
|
reads correctly in monochrome and for colour-blind readers. `RIVINE_ASCII=1`
|
|
422
423
|
swaps the glyphs and wordmark for pure ASCII.
|
|
423
|
-
- Exits restore the cursor and raw-mode state, including the abnormal ones
|
|
424
|
+
- Exits restore the cursor and raw-mode state, including the abnormal ones: a
|
|
424
425
|
kill, or an uncaught error. You should never need to run `reset`.
|
|
425
426
|
|
|
426
427
|
## Your identity
|
|
427
428
|
|
|
428
|
-
The status bar shows your **cloudhandle
|
|
429
|
+
The status bar shows your **cloudhandle**, the identity you recognise. Your
|
|
429
430
|
account key is shown only as `••••••••••••` and the CLI never receives its
|
|
430
431
|
value.
|
|
431
432
|
|
|
@@ -443,7 +444,7 @@ leak.
|
|
|
443
444
|
- File reads are capped at 2 MB. Larger files are reported rather than
|
|
444
445
|
truncated silently.
|
|
445
446
|
- `ls`, `glob` and `grep` skip `node_modules`, `.git`, `dist`, `.next`,
|
|
446
|
-
`target`, `venv` and similar
|
|
447
|
+
`target`, `venv` and similar, for cost, not secrecy.
|
|
447
448
|
- Command output is capped at 120,000 characters, keeping the tail, because a
|
|
448
449
|
failing build puts its error at the end.
|
|
449
450
|
|
|
@@ -459,11 +460,11 @@ npm run typecheck
|
|
|
459
460
|
This package ships compiled JavaScript only; the TypeScript sources are not
|
|
460
461
|
redistributed. For maintainers working in the repository, the interesting
|
|
461
462
|
code is in `src/protocol/`: `permissions.ts` decides,
|
|
462
|
-
`fsExecutor.ts` acts, `runner.ts` coordinates one turn. `src/ui/` only renders
|
|
463
|
-
|
|
463
|
+
`fsExecutor.ts` acts, `runner.ts` coordinates one turn. `src/ui/` only renders.
|
|
464
|
+
Nothing with a consequence lives there.
|
|
464
465
|
|
|
465
466
|
---
|
|
466
467
|
|
|
467
|
-
Rivine Code CLI
|
|
468
|
+
Rivine Code CLI, licensed and owned by **Beunec Technologies, Inc.**
|
|
468
469
|
Proprietary software. Not open source. Use is governed by the licence
|
|
469
470
|
agreement accompanying it.
|
package/dist/api/workspace.js
CHANGED
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
import { createHash } from 'node:crypto';
|
|
12
12
|
import { MEDIATOR_MODE, TARGET_ENGINE, apiUrl } from '../config.js';
|
|
13
13
|
import { accessToken } from '../auth/session.js';
|
|
14
|
+
export class TurnBusy extends Error {
|
|
15
|
+
detail;
|
|
16
|
+
constructor(detail) {
|
|
17
|
+
super(detail);
|
|
18
|
+
this.detail = detail;
|
|
19
|
+
this.name = 'TurnBusy';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
export class InsufficientCredits extends Error {
|
|
15
23
|
detail;
|
|
16
24
|
constructor(detail) {
|
|
@@ -28,16 +36,26 @@ async function authHeaders() {
|
|
|
28
36
|
export function projectKey(cwd) {
|
|
29
37
|
return createHash('sha256').update(cwd).digest('hex').slice(0, 40);
|
|
30
38
|
}
|
|
39
|
+
export class OnboardingRequired extends Error {
|
|
40
|
+
url;
|
|
41
|
+
constructor(message, url) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.url = url;
|
|
44
|
+
this.name = 'OnboardingRequired';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
31
47
|
export async function bootstrap(cwd, label) {
|
|
32
48
|
const url = new URL(`${apiUrl()}/api/cli/bootstrap`);
|
|
33
49
|
url.searchParams.set('project_key', projectKey(cwd));
|
|
34
50
|
url.searchParams.set('label', label);
|
|
35
51
|
const res = await fetch(url, { headers: await authHeaders() });
|
|
36
52
|
if (!res.ok) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
const body = await res.json().catch(() => null);
|
|
54
|
+
const reason = body?.detail ?? body?.error;
|
|
55
|
+
if (res.status === 403 && reason && typeof reason === 'object' && reason.code === 'onboarding_required') {
|
|
56
|
+
throw new OnboardingRequired(String(reason.message || 'Finish setting up your Aselius account to use Rivine Code.'), String(reason.onboarding_url || 'https://aselius.beunec.com/onboarding'));
|
|
57
|
+
}
|
|
58
|
+
const detail = typeof reason === 'string' ? reason.trim() : '';
|
|
41
59
|
if (res.status === 401) {
|
|
42
60
|
throw new Error('Your session is no longer valid. Run `rivine login`.');
|
|
43
61
|
}
|
|
@@ -91,6 +109,10 @@ export async function openTurn(req) {
|
|
|
91
109
|
const body = (await res.json().catch(() => ({})));
|
|
92
110
|
throw new InsufficientCredits(body.error ?? 'Not enough credits for Rivine Code.');
|
|
93
111
|
}
|
|
112
|
+
if (res.status === 409) {
|
|
113
|
+
const body = (await res.json().catch(() => ({})));
|
|
114
|
+
throw new TurnBusy(String(body.detail ?? body.error ?? 'A turn is already in progress.'));
|
|
115
|
+
}
|
|
94
116
|
if (!res.ok) {
|
|
95
117
|
const body = await res.text().catch(() => '');
|
|
96
118
|
throw new Error(`The engine refused this turn (HTTP ${res.status}). ${body.slice(0, 300)}`);
|
|
@@ -147,6 +169,24 @@ export async function closeSession(sessionId) {
|
|
|
147
169
|
catch {
|
|
148
170
|
}
|
|
149
171
|
}
|
|
172
|
+
export async function getTurnStatus(workspaceId, chatSpaceId) {
|
|
173
|
+
const res = await fetch(`${apiUrl()}/api/workspaces/${workspaceId}/chats/${chatSpaceId}/turn-status`, {
|
|
174
|
+
headers: await authHeaders(),
|
|
175
|
+
});
|
|
176
|
+
if (!res.ok)
|
|
177
|
+
throw new Error(`turn-status returned ${res.status}`);
|
|
178
|
+
return (await res.json());
|
|
179
|
+
}
|
|
180
|
+
export async function cancelTurn(workspaceId, chatSpaceId) {
|
|
181
|
+
try {
|
|
182
|
+
await fetch(`${apiUrl()}/api/workspaces/${workspaceId}/chats/${chatSpaceId}/turns/cancel`, {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: await authHeaders(),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
}
|
|
189
|
+
}
|
|
150
190
|
export async function fetchCredits(creditsUrl) {
|
|
151
191
|
if (!creditsUrl)
|
|
152
192
|
return null;
|
package/dist/index.js
CHANGED
|
@@ -261,6 +261,9 @@ mcp
|
|
|
261
261
|
function collect(value, previous) {
|
|
262
262
|
return [...previous, value];
|
|
263
263
|
}
|
|
264
|
+
function onBusyOption(value) {
|
|
265
|
+
return value === 'follow' || value === 'stop' ? value : 'fail';
|
|
266
|
+
}
|
|
264
267
|
program
|
|
265
268
|
.argument('[prompt...]', 'send one prompt and exit')
|
|
266
269
|
.option('-p, --print <prompt>', 'send one prompt, print the answer, and exit')
|
|
@@ -270,6 +273,7 @@ program
|
|
|
270
273
|
.option('--bypass', 'never ask for approval — for CI only, on a machine you are willing to have changed')
|
|
271
274
|
.option('-C, --cwd <dir>', 'run against a different directory')
|
|
272
275
|
.option('--output-format <format>', 'text | json — json puts one object on stdout and everything else on stderr', 'text')
|
|
276
|
+
.option('--on-busy <policy>', 'if an earlier turn on this project is still running: follow | stop | fail (default fail)')
|
|
273
277
|
.action(async (prompt, options) => {
|
|
274
278
|
const requested = options.cwd ? resolvePath(options.cwd) : process.cwd();
|
|
275
279
|
const cwd = await realpath(requested).catch(() => requested);
|
|
@@ -297,7 +301,7 @@ program
|
|
|
297
301
|
process.exitCode = 2;
|
|
298
302
|
return;
|
|
299
303
|
}
|
|
300
|
-
process.exitCode = await runHeadless({ cwd, mode, codeMode, prompt: oneShot, format });
|
|
304
|
+
process.exitCode = await runHeadless({ cwd, mode, codeMode, prompt: oneShot, format, onBusy: onBusyOption(options.onBusy) });
|
|
301
305
|
return;
|
|
302
306
|
}
|
|
303
307
|
if (format === 'json' && oneShot) {
|
|
@@ -308,7 +312,7 @@ program
|
|
|
308
312
|
process.exitCode = 2;
|
|
309
313
|
return;
|
|
310
314
|
}
|
|
311
|
-
process.exitCode = await runHeadless({ cwd, mode, codeMode, prompt: oneShot, format });
|
|
315
|
+
process.exitCode = await runHeadless({ cwd, mode, codeMode, prompt: oneShot, format, onBusy: onBusyOption(options.onBusy) });
|
|
312
316
|
return;
|
|
313
317
|
}
|
|
314
318
|
const { waitUntilExit } = render(React.createElement(App, {
|
|
@@ -8,14 +8,42 @@
|
|
|
8
8
|
* accompanying it; it is not open source and is not licensed for
|
|
9
9
|
* redistribution or derivative works.
|
|
10
10
|
*/
|
|
11
|
-
import { spawnSync } from 'node:child_process';
|
|
12
|
-
import { mkdir, readFile, readdir, realpath, stat, writeFile, } from 'node:fs/promises';
|
|
11
|
+
import { execFile, spawnSync } from 'node:child_process';
|
|
12
|
+
import { mkdir, readFile, readdir, realpath, stat, unlink, writeFile, } from 'node:fs/promises';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
13
14
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
15
|
+
import { promisify } from 'node:util';
|
|
14
16
|
import { runShell } from './shell.js';
|
|
15
17
|
import { applyEdit, describeFailure, writeFileAtomic } from './edit.js';
|
|
16
18
|
import { decide } from './permissions.js';
|
|
17
19
|
const VIRTUAL_ROOT = '/workspace';
|
|
18
20
|
const MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
21
|
+
const IMAGE_FILE = /\.(png|jpe?g|gif|webp|heic|heif|bmp|tiff?)$/i;
|
|
22
|
+
const IMAGE_CONVERT_ALWAYS = /\.(heic|heif|bmp|tiff?)$/i;
|
|
23
|
+
const IMAGE_SEND_BYTES = 1_500_000;
|
|
24
|
+
const execFileP = promisify(execFile);
|
|
25
|
+
export async function shrinkImage(path) {
|
|
26
|
+
const out = join(tmpdir(), `rivine-img-${process.pid}-${Date.now()}.jpg`);
|
|
27
|
+
const attempts = [];
|
|
28
|
+
if (process.platform === 'darwin')
|
|
29
|
+
attempts.push(['sips', ['-s', 'format', 'jpeg', '-Z', '1600', path, '--out', out]]);
|
|
30
|
+
attempts.push(['magick', [path, '-resize', '1600x1600>', '-quality', '85', out]]);
|
|
31
|
+
attempts.push(['convert', [path, '-resize', '1600x1600>', '-quality', '85', out]]);
|
|
32
|
+
for (const [cmd, args] of attempts) {
|
|
33
|
+
try {
|
|
34
|
+
await execFileP(cmd, args, { timeout: 30_000 });
|
|
35
|
+
const buf = await readFile(out);
|
|
36
|
+
if (buf.length)
|
|
37
|
+
return buf;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await unlink(out).catch(() => undefined);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
19
47
|
const SKIP_DIRS = new Set([
|
|
20
48
|
'node_modules', '.git', 'dist', 'build', '.next', '.turbo', '.venv', 'venv',
|
|
21
49
|
'__pycache__', '.mypy_cache', '.pytest_cache', 'target', '.cache', 'coverage',
|
|
@@ -307,6 +335,12 @@ export async function execute(root, request, hooks = {}) {
|
|
|
307
335
|
const info = await stat(target.absolute);
|
|
308
336
|
if (info.isDirectory())
|
|
309
337
|
return { ok: false, error: 'is_directory' };
|
|
338
|
+
if (IMAGE_FILE.test(target.absolute)
|
|
339
|
+
&& (info.size > IMAGE_SEND_BYTES || IMAGE_CONVERT_ALWAYS.test(target.absolute))) {
|
|
340
|
+
const small = await shrinkImage(target.absolute);
|
|
341
|
+
if (small)
|
|
342
|
+
return { ok: true, data: { content: small.toString('base64'), encoding: 'base64' } };
|
|
343
|
+
}
|
|
310
344
|
if (info.size > MAX_READ_BYTES) {
|
|
311
345
|
return {
|
|
312
346
|
ok: false,
|