@dibssoftware/dibs 0.0.180 → 0.0.181
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 +8 -0
- package/README.md +1 -1
- package/bin/dibs.mjs +9 -1
- package/docs/relay.md +15 -2
- package/docs/windows.md +3 -3
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +2 -2
- package/src/acquire.mjs +2 -1
- package/src/alerts.mjs +16 -8
- package/src/commands.mjs +13 -6
- package/src/cool.mjs +1 -1
- package/src/files.mjs +3 -1
- package/src/guard.mjs +52 -22
- package/src/lock.mjs +19 -3
- package/src/measure.mjs +18 -3
- package/src/platform.mjs +10 -7
- package/src/proc.mjs +10 -0
- package/src/relay.mjs +127 -10
- package/src/service.mjs +5 -1
- package/src/state.mjs +1 -1
- package/src/talk.mjs +9 -6
- package/src/version.mjs +1 -1
- package/src/web.mjs +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Each version's notes are shown once to every Claude session the first time it runs that version, so write them for agents: what to do differently, not how it works inside.
|
|
4
4
|
|
|
5
|
+
## 0.0.181
|
|
6
|
+
- When you end a turn with no `dibs listen` running, the hook asks you to start one. Start it with run_in_background, and again each time it exits: its output now opens with that reminder. Subagents and teammates aren't asked.
|
|
7
|
+
- New for the person: `dibs pair --remote` prints a QR code and a 12-character code (like 7KQM-2XRP-9DHT), and app.dibs.cc has a box to type the code in. The browser and the Mac stay encrypted end to end. If another Mac already holds a code that starts the same way, dibs picks a new one. Never type a code for the person.
|
|
8
|
+
- dibs no longer crashes (exit 70) when whatever reads its output stops reading. It goes quiet on that stream, the job runs on, and dibs exits with the job's code.
|
|
9
|
+
- Plain `dibs` shows the board in about 0.2 s, even on a busy Mac.
|
|
10
|
+
- Windows: dibs finds its own files from any drive, says what command a hung lock holder runs, guards Claude Code's session temp folders, measures what jobs use and tells a job when it used more than it asked, and no longer crashes when a write meets a reader of the state file. The Windows tests now have to pass on every change.
|
|
11
|
+
- Two tests that failed on timing alone (on-demand VM packing, boost on Linux) hold now. Nothing to do.
|
|
12
|
+
|
|
5
13
|
## 0.0.180
|
|
6
14
|
- Slots are a hard limit again. A session's hold now covers one of its runs per resource at a time, so a second run from the same session or its subagents needs a slot of its own and passes the memory and disk checks. On 11-10 five subagent runs under one playwright hold started at once and froze the Mac. If your subagents share a hold, expect them to queue.
|
|
7
15
|
- dibs no longer crashes (exit 70) or exits 75 with "state lock stuck" when two dibs write at once. Every shared file in ~/.dibs uses one new lock. A slow holder is waited for and never taken over; a dead, zombie or stopped one is. If a live dibs hangs holding the lock for over a minute, `dibs alerts` and the board name it ("dibs is stuck behind pid N") with the fix, and plain `dibs` shows the last state instead of waiting. A stale lock dibs can't remove ends the wait with exit 75 naming the path.
|
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ With `dibs guard install`, an agent that forgets gets turned away with the exact
|
|
|
54
54
|
|
|
55
55
|
## Details
|
|
56
56
|
|
|
57
|
-
**Install.** `install.sh` downloads the release from dibs.cc and checks its sha256 before installing anything, puts dibs in `~/.dibs-cli` and links `~/.local/bin/dibs`. If anything fails, it says what and installs nothing. Each release is at `https://dibs.cc/releases/dibs-v<version>.tar.gz`, with its `.sha256` beside it. A pinned version from GitHub: `curl -fsSL https://raw.githubusercontent.com/dibssoftware/dibs/v0.0.
|
|
57
|
+
**Install.** `install.sh` downloads the release from dibs.cc and checks its sha256 before installing anything, puts dibs in `~/.dibs-cli` and links `~/.local/bin/dibs`. If anything fails, it says what and installs nothing. Each release is at `https://dibs.cc/releases/dibs-v<version>.tar.gz`, with its `.sha256` beside it. A pinned version from GitHub: `curl -fsSL https://raw.githubusercontent.com/dibssoftware/dibs/v0.0.181/install.sh | sh`. From a clone: `DIBS_SOURCE=<the clone> sh install.sh`.
|
|
58
58
|
|
|
59
59
|
**Windows.** From PowerShell, no admin rights needed: `irm https://dibs.cc/install.ps1 | iex`. It checks the sha256 the same way, puts dibs in `~\.dibs-cli`, and makes `dibs.cmd` (PowerShell and cmd) and `dibs` (Git Bash, where Claude Code runs its commands on Windows) in `~\.local\bin`.
|
|
60
60
|
|
package/bin/dibs.mjs
CHANGED
|
@@ -148,7 +148,7 @@ the person's page and MCP server
|
|
|
148
148
|
dibs pair --list | --revoke <id|all> what's signed in (MCP clients: can act or look only; on the coordinator, its machines)
|
|
149
149
|
dibs pair --machine [--name x] on the coordinator: a one-time code another machine joins with (10 minutes, one use);
|
|
150
150
|
dibs pair --revoke <machine> removes one that joined
|
|
151
|
-
dibs pair --remote [--allow-actions] a one-time
|
|
151
|
+
dibs pair --remote [--allow-actions] a one-time QR code, and a code to type, to pair a phone or any browser with https://app.dibs.cc,
|
|
152
152
|
end-to-end encrypted through the relay (dibs service install relay keeps it connected).
|
|
153
153
|
It can only look unless --allow-actions; the hook and hours never change remotely
|
|
154
154
|
dibs relay [--url wss://app.dibs.cc] the relay connection itself, in the foreground
|
|
@@ -536,6 +536,14 @@ const crash = e => die(`dibs itself crashed (a bug in dibs, not in your command;
|
|
|
536
536
|
// A lock dibs can't take over (src/lock.mjs LockBroken) is no bug either: the message names what to remove.
|
|
537
537
|
const fail = e => (noSpace(e) ? die(fullDisk(e), 74) : e?.code === 'ELOCKBROKEN' ? die(e.message, 75) : crash(e));
|
|
538
538
|
process.on('uncaughtException', fail);
|
|
539
|
+
// A caller that stops reading (a `| head`, a closed terminal, a tool call that gave up) closes our
|
|
540
|
+
// stdout or stderr. That's no bug, and the job dibs runs must go on and keep its exit code: from then
|
|
541
|
+
// on dibs says nothing on that stream. On 2026-11-11 a run whose stderr reader went away crashed
|
|
542
|
+
// with EPIPE (exit 70) mid-wait, twice in 8 minutes.
|
|
543
|
+
for (const s of [process.stdout, process.stderr]) s.on('error', e => {
|
|
544
|
+
if (e?.code !== 'EPIPE' && e?.code !== 'ERR_STREAM_DESTROYED') return fail(e);
|
|
545
|
+
s.write = (_c, enc, cb) => { (typeof enc === 'function' ? enc : cb)?.(); return true; };
|
|
546
|
+
});
|
|
539
547
|
|
|
540
548
|
// A job lost on its way to or on another machine (76, 77) and dibs's own crash
|
|
541
549
|
// (70) go in the event log, so the person hears of them (src/alerts.mjs), not
|
package/docs/relay.md
CHANGED
|
@@ -6,7 +6,7 @@ Turn it on:
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
dibs service install relay # keeps the outbound connection up, with backoff; off until you do this
|
|
9
|
-
dibs pair --remote #
|
|
9
|
+
dibs pair --remote # shows a QR code and a code; scan it with the phone or type the code at app.dibs.cc. That browser can only look
|
|
10
10
|
dibs pair --remote --allow-actions # the same, and that browser may also boost, pause, resume and stop jobs, cap an agent, set the pace and cancel scheduled runs
|
|
11
11
|
dibs pair --list # local sign-ins and remote devices
|
|
12
12
|
dibs pair --revoke <id|all> # a revoked device's open session ends within 25 seconds
|
|
@@ -45,6 +45,18 @@ The fragment never goes in a request, and the page removes it from the address b
|
|
|
45
45
|
|
|
46
46
|
So pairing needs the secret (256 bits, one use, ten minutes; there's nothing to brute force), and a relay that swaps either key is caught: the device key by the HMAC and the device's own signature, the Mac's key by the fingerprint and the HMAC.
|
|
47
47
|
|
|
48
|
+
### The typed code
|
|
49
|
+
|
|
50
|
+
Beside the QR code, `dibs pair --remote` shows a code to type at app.dibs.cc instead, like `7KQM-2XRP-9DHT`: 12 Crockford base32 characters (no I, L, O or U; the page reads O as 0 and I and L as 1). The first 4 are a drop name `R`, the other 8 are `K`, 40 random bits that never leave the Mac or the person's eyes.
|
|
51
|
+
|
|
52
|
+
The Mac seals the link's fragment, `<mid>.<secret>.<fp>`, with AES-256-GCM under PBKDF2-SHA256(`K`, salt "dibs-code-v1" ‖ `R`, 600,000 iterations), a random 12-byte nonce and the salt as associated data, and sends the box to the relay as `{t: "drops", d: [{r, b, exp}]}` over its authenticated socket, the whole list of its open links' boxes each time it changes. The relay's code index keeps each box under `R` for the machine that sent it, until the link's ten minutes run out or the Mac stops listing it: when the link is used, revoked, or replaced past five open links.
|
|
53
|
+
|
|
54
|
+
A name another machine already holds stays theirs. The relay answers every drops message with `{t: "drops-res", ok, taken}`, the names it now holds for this Mac and the ones another machine holds, and `dibs pair --remote` waits up to 5 seconds for that answer before printing its code. A taken name gets the same link sealed again under a fresh code (three tries, then no code, only the QR code); no answer prints the code with a warning that it may not work yet. So the code it prints is one the relay took.
|
|
55
|
+
|
|
56
|
+
The page sends `R` to `POST /pair/code`, same origin only, and gets the box back, at most 3 times per box. A name nobody holds, an expired box and one already handed out 3 times all get the same 404. It derives the key from `K`, opens the box, and pairs with the link inside exactly as if the QR code had been scanned. A wrong `K` fails in the page, which keeps the box, so retyping never fetches again.
|
|
57
|
+
|
|
58
|
+
The relay never sees `K`. Whoever holds a box (the relay, or someone who guessed a live `R` out of 1,048,576 within the per-address limits) has 2^40 keys to try at 600,000 PBKDF2 rounds each: 3.3e17 HMAC-SHA256 calls on average. A top-end GPU does about 9e9 a second, so opening one box inside its ten minutes takes some 60,000 of them, and what's inside is worthless once those ten minutes are up or the link is used. The worst a guesser can do cheaply is spend a live box's 3 fetches; the person then runs `dibs pair --remote` again.
|
|
59
|
+
|
|
48
60
|
## A session
|
|
49
61
|
|
|
50
62
|
Every connection, including the first right after pairing:
|
|
@@ -80,8 +92,9 @@ Errors before a session exists (`{t: "err", code}`) are unauthenticated, so the
|
|
|
80
92
|
|
|
81
93
|
| path | who | what the relay does |
|
|
82
94
|
|---|---|---|
|
|
83
|
-
| `wss://app.dibs.cc/ws/m/<mid>` | the Mac (also sends `{t: "tokens", h, p}`: the hashes of its paired browsers' relay tokens and of its open links' pairing tickets, within a second of any change in `relay.json`) | sends a 32-byte challenge; the Mac answers with its relay public key and `Sign_R(tx("dibs-relay-auth-v1", mid, challenge, host))`. The relay checks that the key hashes to `<mid>` and the signature; then routes. The newest authenticated connection replaces the old one |
|
|
95
|
+
| `wss://app.dibs.cc/ws/m/<mid>` | the Mac (also sends `{t: "tokens", h, p}`: the hashes of its paired browsers' relay tokens and of its open links' pairing tickets, and `{t: "drops", d}`, its open links' sealed code boxes, within a second of any change in `relay.json`) | sends a 32-byte challenge; the Mac answers with its relay public key and `Sign_R(tx("dibs-relay-auth-v1", mid, challenge, host))`. The relay checks that the key hashes to `<mid>` and the signature; then routes. The newest authenticated connection replaces the old one |
|
|
84
96
|
| `wss://app.dibs.cc/ws/b/<mid>` | a browser tab | only from the page's own Origin. A tab gets a slot only by proving it's paired: its first message is `{t: "hello", rt}`, and the relay admits it if the hash of `rt` is one the Mac registered (compared in constant time), or `{t: "pair", ticket}` with a ticket whose hash the Mac registered for an open link, into a pool of 2 with a 30 s deadline that ends when the Mac admits it. A wrong ticket and no open link get the same answer, so the relay's answers say nothing about whether a link is open, and nobody without the link can take the pairing pool. Anything else (a byte, a made-up token, silence for 5 s) closes it. An admitted tab gets a random channel id; its binary messages go to the Mac prefixed with the id, and the Mac's go back by id. Text from the relay: `{t: "mac", up}`, and `{t: "refused", why: "unpaired" or "no-pairing"}`, which the page turns into its own words |
|
|
97
|
+
| `https://app.dibs.cc/pair/code` | the page (`POST {r}`, same Origin only) | a typed code's sealed box by its drop name (see "The typed code"), 3 times per box at most; the Worker's limit of 20 a minute per address and the code index's own count apply |
|
|
85
98
|
| `https://app.dibs.cc/` | anyone | the page, with the headers below |
|
|
86
99
|
| `https://dibs.cc/app`, `https://dibs.cc/app/*` | anyone | a 301 to `https://app.dibs.cc/`, which keeps the fragment. Exactly these two route patterns, so `/apple-touch-icon.png` and the like stay the waitlist's |
|
|
87
100
|
|
package/docs/windows.md
CHANGED
|
@@ -7,8 +7,8 @@ Install from PowerShell with `install.ps1`, or use WSL, where dibs is the Linux
|
|
|
7
7
|
## What's missing
|
|
8
8
|
|
|
9
9
|
- **No pausing.** Windows has no SIGSTOP. dibs never pauses a job there: urgent work waits its turn instead, memory and disk pressure hold new work back but don't freeze running jobs, and `dibs pause` says so and suggests `dibs stop`.
|
|
10
|
-
- **
|
|
10
|
+
- **Memory is the working set.** dibs measures a job's process tree by its working set and CPU, a few seconds apart, the same way it learns sizes elsewhere.
|
|
11
11
|
- **No process groups.** dibs ends a job's whole process tree, but a process whose parent already exited can escape it, unless dibs saw it on one of its checks every 3 seconds.
|
|
12
12
|
- **No signals.** Windows can't deliver SIGTERM or SIGINT to a job: stopping one ends it outright, with no chance to clean up.
|
|
13
|
-
- **Slower
|
|
14
|
-
- **Not tested on Windows:** on-demand VMs (boat) sent from a Windows machine
|
|
13
|
+
- **Slower.** Each look at the process table is a PowerShell call, so a dozen dibs at once on a 4-core machine take seconds each to get through the state file's lock.
|
|
14
|
+
- **Not tested on Windows:** on-demand VMs (boat) sent from a Windows machine.
|
package/package.json
CHANGED
package/skills/dibs/SKILL.md
CHANGED
|
@@ -56,9 +56,9 @@ dibs run test -- sh -c 'npm run build && npm test' # a shell li
|
|
|
56
56
|
- dibs on this machine was updated: it prints what changed since your last version, once
|
|
57
57
|
- a newer dibs is out on dibs.cc ("dibs X is out (you have Y)"): the person upgrades it; don't upgrade it yourself. Asked at most every 6 hours per machine, never from a git checkout, off with `"updateCheck": false` in config.json.
|
|
58
58
|
|
|
59
|
-
Exit 0
|
|
59
|
+
Exit 0 starts with "First start dibs listen again with run_in_background": do that before anything else. It has no time limit: it waits until something comes, and when your session ends it exits quietly on its own. `--for 30m` sets a limit; then exit 3 means nothing came in that time, and you start it again. `--json` gives `{ messages }`, `{ updated, changes }` or `{ release }`.
|
|
60
60
|
|
|
61
|
-
One listener per agent: the main agent of a session, and each subagent, separately. A newer one replaces the older, which exits 0 saying another took over. Messages that arrive while you work come with your next tool call instead; none is lost or handed over twice. If
|
|
61
|
+
One listener per agent: the main agent of a session, and each subagent, separately. A newer one replaces the older, which exits 0 saying another took over. Messages that arrive while you work come with your next tool call instead; none is lost or handed over twice. If the main agent of a session ends a turn with no listener running, the hook keeps it going to start one ("no dibs listen is running for you"), once a turn and at most 3 turns in a row without one starting. Subagents are never kept going for it. The board, `dibs threads` and `dibs tell` say who is listening.
|
|
62
62
|
|
|
63
63
|
### Holding across tool calls
|
|
64
64
|
|
package/src/acquire.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { resCfg, machine, paths, HOME, loadConfig } from './config.mjs';
|
|
6
7
|
import { identity, pstart, tag } from './proc.mjs';
|
|
7
8
|
import { processes, parent, OS } from './platform.mjs';
|
|
@@ -22,7 +23,7 @@ import { noticeScan } from './notices.mjs';
|
|
|
22
23
|
import { notify } from './talk.mjs';
|
|
23
24
|
import { mayShip, loadShipTarget } from './remote.mjs';
|
|
24
25
|
|
|
25
|
-
const BIN = path.join(path.dirname(
|
|
26
|
+
const BIN = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'dibs.mjs');
|
|
26
27
|
|
|
27
28
|
// How long dibs run waits in line outside Claude Code, where nothing moves a
|
|
28
29
|
// long call to the background and the tool may kill it.
|
package/src/alerts.mjs
CHANGED
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
//
|
|
20
20
|
// alerts.json keeps the open ones, the resolved ones for a day, and what the
|
|
21
21
|
// scan needs between runs: how far into the event log and the hook's log it
|
|
22
|
-
// has read, recent waits per resource, and the services' start counts.
|
|
23
|
-
//
|
|
24
|
-
//
|
|
22
|
+
// has read, recent waits per resource, and the services' start counts. The
|
|
23
|
+
// throttle watcher scans every SCAN_EVERY, so alerts keep up even when nobody
|
|
24
|
+
// looks; whatever shows the board scans too, every SCAN_EVERY without a
|
|
25
|
+
// watcher and every READER_EVERY with one.
|
|
25
26
|
import fs from 'node:fs';
|
|
26
27
|
import path from 'node:path';
|
|
27
28
|
import { HOME, paths, machine } from './config.mjs';
|
|
@@ -33,7 +34,7 @@ import { withState, history } from './state.mjs';
|
|
|
33
34
|
import { markIdle, tableFirst } from './acquire.mjs';
|
|
34
35
|
import { sessionFiles } from './proc.mjs';
|
|
35
36
|
import { EVENTS } from './events.mjs';
|
|
36
|
-
import { serviceHealth } from './service.mjs';
|
|
37
|
+
import { serviceHealth, logName } from './service.mjs';
|
|
37
38
|
import { hogHint } from './hogs.mjs';
|
|
38
39
|
import { underLock, heldBy } from './lock.mjs';
|
|
39
40
|
import { now, bytes, clock, gb, die } from './util.mjs';
|
|
@@ -53,6 +54,13 @@ const STUCK_AFTER = 5 * MIN;
|
|
|
53
54
|
// Reads are cheap but not free (a verdict per waiter, the tail of two logs);
|
|
54
55
|
// the app polls every 2 s, so a scan stands for this long.
|
|
55
56
|
const SCAN_EVERY = 15e3;
|
|
57
|
+
// While the throttle watcher runs it scans every SCAN_EVERY, and a board, the page or the app
|
|
58
|
+
// scan only when nobody has for this long. A scan reads launchd once per service and top for
|
|
59
|
+
// memory: on 2026-11-11 that made every fifteenth-second board 2 s instead of 0.8. With no
|
|
60
|
+
// watcher, they scan every SCAN_EVERY as before.
|
|
61
|
+
const READER_EVERY = 60e3;
|
|
62
|
+
// A liveness hint only (kill 0, no ps): a reused pid costs alerts up to a minute's lag.
|
|
63
|
+
const watching = () => { try { process.kill(Number(fs.readFileSync(path.join(HOME, 'cool.pid'), 'utf8')), 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
56
64
|
// A wait is long past this, or past WAIT_TIMES its usual wait, whichever is later.
|
|
57
65
|
const WAIT_FLOOR = 10 * MIN;
|
|
58
66
|
const WAIT_TIMES = 3;
|
|
@@ -330,13 +338,13 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
330
338
|
if (!h.running)
|
|
331
339
|
out.push({ id: `service:${k}`, cause: 'dibs', level: 'urgent',
|
|
332
340
|
title: `dibs's ${k} service isn't running${h.exit ? ` (it last exited with code ${h.exit})` : ''}: ${h.what}`,
|
|
333
|
-
fix: `Start it again: dibs service install ${k}. Why it stopped is in ~/.dibs/${k}
|
|
341
|
+
fix: `Start it again: dibs service install ${k}. Why it stopped is in ~/.dibs/${logName(k)}.` });
|
|
334
342
|
for (const k of new Set((st.restarts || []).map(r => r.k))) {
|
|
335
343
|
const rs = st.restarts.filter(r => r.k === k);
|
|
336
344
|
const last = rs[rs.length - 1];
|
|
337
345
|
out.push({ id: `restart:${k}`, cause: 'dibs', level: 'warn', at: rs[0].at,
|
|
338
346
|
title: `dibs's ${k} service crashed (exit ${last.exit}) and launchd started it again${rs.length > 1 ? `, ${rs.length} times in the last hour` : ''}, last at ${stamp(last.at, t)}`,
|
|
339
|
-
fix: `Look in ~/.dibs/${k}
|
|
347
|
+
fix: `Look in ~/.dibs/${logName(k)} for why, and report it: dibs ask "the ${k} service keeps exiting with ${last.exit}"` });
|
|
340
348
|
}
|
|
341
349
|
if (st.hook?.length) {
|
|
342
350
|
const last = st.hook[st.hook.length - 1];
|
|
@@ -438,10 +446,10 @@ export function merge(st, found, t) {
|
|
|
438
446
|
// Read what's new and bring alerts.json up to date, unless another process
|
|
439
447
|
// did within SCAN_EVERY. Returns the list to show. Never throws: the board,
|
|
440
448
|
// the watcher and the page call it, and none of them may fail over an alert.
|
|
441
|
-
export function scan({ s, cfg, hist, m = machine(), t = now(), force = false } = {}) {
|
|
449
|
+
export function scan({ s, cfg, hist, m = machine(), t = now(), force = false, watcher = false } = {}) {
|
|
442
450
|
try {
|
|
443
451
|
const was = load();
|
|
444
|
-
if (!force && was.at && t - was.at < SCAN_EVERY) return shown(was, t);
|
|
452
|
+
if (!force && was.at && t - was.at < (watcher || !watching() ? SCAN_EVERY : READER_EVERY)) return shown(was, t);
|
|
445
453
|
const st = locked(() => {
|
|
446
454
|
const st = load();
|
|
447
455
|
// Alerts made by older rules aren't resolved, only no longer said that way: start the open list over.
|
package/src/commands.mjs
CHANGED
|
@@ -3,11 +3,12 @@ import fs from 'node:fs';
|
|
|
3
3
|
import net from 'node:net';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
6
7
|
import { resCfg, machine, HOME, paths, PACES, PACE_OVERLAP, paced, paceKnobs, hardware, writePace, loadConfig } from './config.mjs';
|
|
7
8
|
import { logChange } from './owner.mjs';
|
|
8
|
-
import { identity, isMine, tag } from './proc.mjs';
|
|
9
|
+
import { identity, isMine, tag, makeAlive } from './proc.mjs';
|
|
9
10
|
import { launch, stopTree, processes, descendants, which, starts, scoped, watchdog, OS } from './platform.mjs';
|
|
10
|
-
import { withState, withStateIfRoom, history, record, peakOf, peek, KEEP_PLACE } from './state.mjs';
|
|
11
|
+
import { withState, withStateIfRoom, history, record, peakOf, peek, pidsOf, KEEP_PLACE } from './state.mjs';
|
|
11
12
|
import { acquire, markIdle, tableFirst, idleFor, describeLease, commandKey, holdUntil, outerLease, defaultMaxWait, HOLD_CAP } from './acquire.mjs';
|
|
12
13
|
import { rank, rankParts, byRank, forecast, verdict, remaining, used, sum, lent, pausedFor, overLoad, loadWhy, loadAhead, holdingOf, swapping, swapWhy, diskSqueeze, BACKGROUND, roomFor } from './schedule.mjs';
|
|
13
14
|
import { noticeHandler } from './preempt.mjs';
|
|
@@ -19,7 +20,7 @@ import { bold, dim, amber, columns, wrap, quoted } from './style.mjs';
|
|
|
19
20
|
import { quotasNow, isQuota } from './quota.mjs';
|
|
20
21
|
import { agentsNow } from './agents.mjs';
|
|
21
22
|
import { forYou } from './questions.mjs';
|
|
22
|
-
import { notesForYou, listeners } from './talk.mjs';
|
|
23
|
+
import { notesForYou, listeners, listenerPids } from './talk.mjs';
|
|
23
24
|
import { remoteConf, shortHost } from './remote.mjs';
|
|
24
25
|
import { sample, sized, grewLine, grewPlain, tellOverAsk } from './measure.mjs';
|
|
25
26
|
import { clash, isFiles, short, takeAgent, callKey, sameAgent, fileKey, shellRes, projectKey } from './files.mjs';
|
|
@@ -186,8 +187,11 @@ export async function run(o, cfg) {
|
|
|
186
187
|
// Low and idle work can be paused for urgent work (src/preempt.mjs); say so when it happens.
|
|
187
188
|
// Notices about this job and others go to their agents while it runs (src/notices.mjs).
|
|
188
189
|
setInterval(noticeScan, NOTICE_EVERY).unref();
|
|
190
|
+
// Windows has no SIGUSR2: there each tick of this run reads its own lease (a plain read, no lock)
|
|
191
|
+
// and says the same things, a few seconds later at most.
|
|
189
192
|
const notify = OS !== 'windows';
|
|
190
|
-
|
|
193
|
+
const heard = noticeHandler(() => (notify ? withStateIfRoom(s => s.leases.find(x => x.id === lease.id)) : peek().leases?.find(x => x.id === lease.id)));
|
|
194
|
+
if (notify) process.on('SIGUSR2', heard);
|
|
191
195
|
// The command starts only once its group is on record, so a wrapper killed
|
|
192
196
|
// at any point has its job reaped with it, or the job never starts.
|
|
193
197
|
// The gate shell execs the command, so its start time is the command's.
|
|
@@ -207,7 +211,7 @@ export async function run(o, cfg) {
|
|
|
207
211
|
if (child.pid) wd.add(child.pid);
|
|
208
212
|
if (child.pid && !pgstart) withStateIfRoom(note({ pgstart: starts([child.pid])?.get(child.pid) ?? null }));
|
|
209
213
|
// Each tick also measures every lease on the machine, when it's this run's turn (src/measure.mjs).
|
|
210
|
-
tracker = setInterval(() => { track(); sample(); }, 3000);
|
|
214
|
+
tracker = setInterval(() => { track(); sample(); if (!notify) heard(); }, 3000);
|
|
211
215
|
tracker.unref();
|
|
212
216
|
child.on('error', e => { say(`couldn't start ${o.cmd[0]}: ${e.message}`); finish(127); });
|
|
213
217
|
// No last track(): once the child has exited, its process groups are found by the
|
|
@@ -242,7 +246,7 @@ function requeue(s, l, cfg) {
|
|
|
242
246
|
// Run the same dibs run again, as this same process where Node allows it
|
|
243
247
|
// (process.execve keeps the pid the agent's tool call is waiting on), so it
|
|
244
248
|
// waits in line like any other and picks up the place requeue() kept.
|
|
245
|
-
const BIN = path.join(path.dirname(
|
|
249
|
+
const BIN = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'dibs.mjs');
|
|
246
250
|
let handedOn = false;
|
|
247
251
|
function runAgain(o, lease, again) {
|
|
248
252
|
say(again.why === 'over'
|
|
@@ -718,6 +722,9 @@ function marked() {
|
|
|
718
722
|
const BOARD_WAIT = 2000;
|
|
719
723
|
export async function status(o, cfg) {
|
|
720
724
|
const hist = history();
|
|
725
|
+
// One ps for the start times of the state's pids and the listeners' (src/proc.mjs keeps
|
|
726
|
+
// them 10 s): the state lock's own read and the board's line of listeners took one each.
|
|
727
|
+
try { makeAlive([...pidsOf(peek()), ...listenerPids()]); } catch {}
|
|
721
728
|
tableFirst();
|
|
722
729
|
const s = withState(s => { markIdle(s); return s; }, BOARD_WAIT) ?? peek();
|
|
723
730
|
const m = machine();
|
package/src/cool.mjs
CHANGED
|
@@ -242,7 +242,7 @@ export async function throttle(o, cfg) {
|
|
|
242
242
|
// Not awaited: measuring a full temp folder can take a minute, and this loop keeps the machine's pace meanwhile.
|
|
243
243
|
hogsOnce(cfg, machine());
|
|
244
244
|
// Alerts open and close even while nobody looks at the board (src/alerts.mjs); the scan itself keeps its pace.
|
|
245
|
-
scanAlerts({ s: peek(), cfg, hist: history() });
|
|
245
|
+
scanAlerts({ s: peek(), cfg, hist: history(), watcher: true });
|
|
246
246
|
// Open progress tasks gone quiet or past their ETA: their agents hear about it (src/notices.mjs).
|
|
247
247
|
if (now() - nudged >= SAMPLE_EVERY) { nudged = now(); progressScan(); }
|
|
248
248
|
if (now() - sampled >= SAMPLE_EVERY) {
|
package/src/files.mjs
CHANGED
|
@@ -63,7 +63,9 @@ function sibling(l, w) {
|
|
|
63
63
|
let tmpRoots = null;
|
|
64
64
|
export function claudeTmp() {
|
|
65
65
|
if (tmpRoots) return tmpRoots;
|
|
66
|
-
|
|
66
|
+
// Claude Code names it claude-<getuid() ?? 0>: claude-0 on Windows, which has no uid, under
|
|
67
|
+
// CLAUDE_CODE_TMPDIR or /tmp, which there is \tmp on the current drive (Claude Code 2.1.323).
|
|
68
|
+
const uid = process.getuid?.() ?? (WIN ? 0 : null);
|
|
67
69
|
if (uid == null) return (tmpRoots = []);
|
|
68
70
|
// DIBS_CLAUDE_TMP: tests put the temp folder somewhere of their own.
|
|
69
71
|
const bases = process.env.DIBS_CLAUDE_TMP ? [process.env.DIBS_CLAUDE_TMP]
|
package/src/guard.mjs
CHANGED
|
@@ -24,11 +24,17 @@ const LOG = path.join(DIBS_HOME, 'guard.log');
|
|
|
24
24
|
// Who has a message from the person waiting: { session_id: [agent ids] }, or
|
|
25
25
|
// no file at all. src/talk.mjs keeps it; the hook only reads it.
|
|
26
26
|
const INBOX = path.join(DIBS_HOME, 'inbox.json');
|
|
27
|
-
// dibs listen's list of who listens (src/talk.mjs), and the
|
|
27
|
+
// dibs listen's list of who listens (src/talk.mjs), and the sessions kept going at a stop to start one.
|
|
28
28
|
const LISTENERS = path.join(DIBS_HOME, 'listeners.json');
|
|
29
|
-
const
|
|
30
|
-
// Sessions remembered in
|
|
29
|
+
const REARMED = path.join(DIBS_HOME, 'rearm.json');
|
|
30
|
+
// Sessions remembered in REARMED: enough for every session a machine runs in a day or two.
|
|
31
31
|
const REMIND_KEEP = 200;
|
|
32
|
+
// Stops in a row a session is kept going with no listener starting in between. A listen that
|
|
33
|
+
// can't start (dibs broken, no background tasks here) would otherwise wake the agent, fail, and
|
|
34
|
+
// keep it going again at every stop, for ever; after this many it's left alone until one starts.
|
|
35
|
+
const REARM_MAX = 3;
|
|
36
|
+
// A Bash background task running dibs listen, however dibs was named: dibs, ~/bin/dibs, dibs.mjs.
|
|
37
|
+
const LISTEN_CMD = /(^|[\s;&|(/'"])dibs(\.mjs)?['"]?\s+listen\b/;
|
|
32
38
|
// The threads themselves, which the hook only searches for a subagent's id.
|
|
33
39
|
const MESSAGES = path.join(DIBS_HOME, 'messages.json');
|
|
34
40
|
const SETTINGS = process.env.DIBS_CLAUDE_SETTINGS || path.join(os.homedir(), '.claude', 'settings.json');
|
|
@@ -441,27 +447,51 @@ function talked(input) {
|
|
|
441
447
|
try { return fs.readFileSync(MESSAGES, 'utf8').includes(JSON.stringify(input.agent_id)); } catch { return false; }
|
|
442
448
|
}
|
|
443
449
|
|
|
444
|
-
// A main agent ending its turn
|
|
445
|
-
//
|
|
446
|
-
//
|
|
447
|
-
//
|
|
448
|
-
//
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
450
|
+
// A main agent ending its turn with no dibs listen running is kept going to start one, so it
|
|
451
|
+
// never has to remember: a message sent while it waits wakes it. Claude Code (2.1.3xx) lists the
|
|
452
|
+
// session's running background tasks at a stop, which says it outright; older versions don't,
|
|
453
|
+
// so then listeners.json does. Never for a subagent or teammate (agent_id: Stop is the main
|
|
454
|
+
// thread's, but a stray one costs nothing to skip), never on the continuation a stop hook caused
|
|
455
|
+
// (stop_hook_active: at most once a turn), never for Codex (turn_id) or the SDK and -p (their
|
|
456
|
+
// background tasks die with the run), and at most REARM_MAX stops in a row with no listener
|
|
457
|
+
// starting in between. Claude Code fires no Stop for an interrupt or a session that's ending.
|
|
458
|
+
// Returns the line to keep the agent going with, or null.
|
|
459
|
+
function rearm(input, env = process.env) {
|
|
460
|
+
if (input?.hook_event_name !== 'Stop' || input.stop_hook_active || input.agent_id || 'turn_id' in input) return null;
|
|
461
|
+
const sid = input.session_id;
|
|
462
|
+
if (typeof sid !== 'string' || !sid) return null;
|
|
463
|
+
if (/^sdk-/.test(env.CLAUDE_CODE_ENTRYPOINT || '') || /^(1|true|yes|on)$/i.test(env.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS || '')) return null;
|
|
464
|
+
let l = null;
|
|
465
|
+
try { l = JSON.parse(fs.readFileSync(LISTENERS, 'utf8'))[`${sid}|main`] || null; } catch {}
|
|
466
|
+
if (Array.isArray(input.background_tasks)) {
|
|
467
|
+
if (input.background_tasks.some(t => LISTEN_CMD.test(String(t?.command || '')))) return null;
|
|
468
|
+
} else if (Number.isInteger(l?.pid)) {
|
|
469
|
+
try { process.kill(l.pid, 0); return null; } catch (e) { if (e.code !== 'ESRCH') return null; }
|
|
470
|
+
}
|
|
455
471
|
let told = {};
|
|
456
|
-
try { told = JSON.parse(fs.readFileSync(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
472
|
+
try { told = JSON.parse(fs.readFileSync(REARMED, 'utf8')); } catch {}
|
|
473
|
+
const last = told[sid];
|
|
474
|
+
// A listener that started since the last time counts the stops from zero again.
|
|
475
|
+
const n = last && !(l?.at > last.at) ? last.n : 0;
|
|
476
|
+
if (n >= REARM_MAX) return null;
|
|
477
|
+
delete told[sid];
|
|
478
|
+
told[sid] = { n: n + 1, at: Date.now() };
|
|
460
479
|
const keys = Object.keys(told);
|
|
461
480
|
for (const k of keys.slice(0, Math.max(0, keys.length - REMIND_KEEP))) delete told[k];
|
|
462
|
-
fs.
|
|
463
|
-
fs.
|
|
464
|
-
|
|
481
|
+
fs.mkdirSync(DIBS_HOME, { recursive: true });
|
|
482
|
+
fs.writeFileSync(`${REARMED}.${process.pid}`, JSON.stringify(told));
|
|
483
|
+
fs.renameSync(`${REARMED}.${process.pid}`, REARMED);
|
|
484
|
+
return 'dibs: no dibs listen is running for you, so a message sent while you wait can\'t wake you. ' +
|
|
485
|
+
'Before you end your turn, start it with the Bash tool and run_in_background: dibs listen';
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// The re-arm line added to a stop's answer: alone, or after the messages handed over at that stop.
|
|
489
|
+
// additionalContext keeps the agent going without the "blocking error" a decision: 'block' shows.
|
|
490
|
+
function withRearm(input, out) {
|
|
491
|
+
const line = rearm(input);
|
|
492
|
+
if (!line) return out;
|
|
493
|
+
const prev = out?.hookSpecificOutput?.additionalContext;
|
|
494
|
+
return { ...out, hookSpecificOutput: { ...out?.hookSpecificOutput, hookEventName: 'Stop', additionalContext: [prev, line].filter(Boolean).join('\n\n') } };
|
|
465
495
|
}
|
|
466
496
|
|
|
467
497
|
// The hook itself: Claude Code's JSON on stdin, a decision on stdout. Any
|
|
@@ -487,7 +517,7 @@ export async function decide(input) {
|
|
|
487
517
|
if (queuedFor(input)) out = (await import('./talk.mjs')).deliver(input, out);
|
|
488
518
|
else if (input?.hook_event_name === 'SubagentStop' && talked(input)) (await import('./talk.mjs')).finished(input);
|
|
489
519
|
} catch (e) { logError(e, input); }
|
|
490
|
-
try {
|
|
520
|
+
try { out = withRearm(input, out); } catch (e) { logError(e, input); }
|
|
491
521
|
return out;
|
|
492
522
|
}
|
|
493
523
|
|
package/src/lock.mjs
CHANGED
|
@@ -168,9 +168,12 @@ function stale(o, seen) {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// The command line a pid runs, for saying who dibs is stuck behind, or '' when ps can't say.
|
|
171
|
+
// Windows has no ps: the process's command line comes from WMI, as src/platform.mjs reads it.
|
|
171
172
|
export function commandOf(pid) {
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
const r = WIN
|
|
174
|
+
? spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', `(Get-CimInstance Win32_Process -Filter "ProcessId=${Number(pid)}").CommandLine`],
|
|
175
|
+
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 30e3 })
|
|
176
|
+
: spawnSync('ps', ['-o', 'command=', '-p', String(pid)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000 });
|
|
174
177
|
return (r.stdout || '').trim().slice(0, 200);
|
|
175
178
|
}
|
|
176
179
|
|
|
@@ -275,10 +278,23 @@ export function commitAll(h, files) {
|
|
|
275
278
|
}
|
|
276
279
|
if (!h.owns()) throw new LostLock(path.dirname(files[0][0]));
|
|
277
280
|
} catch (e) { for (const tmp of tmps) try { fs.rmSync(tmp, { force: true }); } catch {} throw e; }
|
|
278
|
-
files.forEach(([file], i) =>
|
|
281
|
+
files.forEach(([file], i) => replace(tmps[i], file));
|
|
279
282
|
return h.owns();
|
|
280
283
|
}
|
|
281
284
|
|
|
285
|
+
// Windows refuses to rename over a file another process has open (EPERM, EACCES or EBUSY), and
|
|
286
|
+
// readers open the state without the lock, for a few milliseconds each: on 4-core CI runners a
|
|
287
|
+
// writer in the five-writer lock test crashed on it in 3 of 6 runs (2026-11-13). Those clear in a moment, so the
|
|
288
|
+
// rename is tried again for up to REPLACE_FOR; anything else, or past that, throws as before.
|
|
289
|
+
const REPLACE_FOR = 2000, BUSY = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
290
|
+
function replace(tmp, file) {
|
|
291
|
+
for (let t0 = Date.now(), gap = 5; ; gap = Math.min(gap * 2, 100)) {
|
|
292
|
+
try { return fs.renameSync(tmp, file); }
|
|
293
|
+
catch (e) { if (!WIN || !BUSY.has(e.code) || Date.now() - t0 > REPLACE_FOR) throw e; }
|
|
294
|
+
sleepSync(gap);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
282
298
|
// fn under the lock, done again from the start if the lock was lost before it wrote.
|
|
283
299
|
// null when wait passes first.
|
|
284
300
|
export function underLock(lock, fn, opts = {}) {
|
package/src/measure.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const GB = b => gb(b).replace(/G$/, ' GB');
|
|
|
5
5
|
// its peak goes into history with its run time, and the next run of the same
|
|
6
6
|
// command is planned at what it really took.
|
|
7
7
|
//
|
|
8
|
-
// Memory is physical footprint (src/platform.mjs footprints), CPU is the
|
|
8
|
+
// Memory is physical footprint (src/platform.mjs footprints; the working set on Windows), CPU is the
|
|
9
9
|
// process table's % of a core, both summed over every process group the lease
|
|
10
10
|
// spans plus, for a pool simulator, the simulator's own launchd_sim tree,
|
|
11
11
|
// which runs outside the job's. Reading footprints costs a top call, so
|
|
@@ -48,7 +48,7 @@ export function treeOf(l, s, procs) {
|
|
|
48
48
|
for (const x of s.leases || [])
|
|
49
49
|
if (x.id !== l.id && x.kind === 'run' && x.pgid && x.pgid !== l.pgid && groups.has(x.pgid))
|
|
50
50
|
for (const g of [x.pgid, ...(x.groups || [])]) groups.delete(g);
|
|
51
|
-
const pids = new Set(procs.filter(p => groups.has(p.pgid)).map(p => p.pid));
|
|
51
|
+
const pids = OS === 'windows' ? windowsTree(l, groups, s, procs) : new Set(procs.filter(p => groups.has(p.pgid)).map(p => p.pid));
|
|
52
52
|
const holds = new Set(s.leases.filter(h => h.kind === 'hold' && h.pid && h.pid === l.spid).map(h => h.id));
|
|
53
53
|
// A hold's simulator counts in one of the runs under it, the first: two test
|
|
54
54
|
// runs on one held simulator each counting it charged it twice.
|
|
@@ -74,6 +74,21 @@ export function treeOf(l, s, procs) {
|
|
|
74
74
|
return pids;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// Windows has no process groups (each process's group is its pid): a lease is its groups' processes
|
|
78
|
+
// and everything under them by parent, less the trees of runs nested in it, measured as their own.
|
|
79
|
+
function windowsTree(l, groups, s, procs) {
|
|
80
|
+
const kids = new Map();
|
|
81
|
+
for (const p of procs) if (p.ppid !== p.pid) { if (!kids.has(p.ppid)) kids.set(p.ppid, []); kids.get(p.ppid).push(p.pid); }
|
|
82
|
+
const nested = new Set((s.leases || []).filter(x => x.id !== l.id && x.kind === 'run' && x.pgid && x.pgid !== l.pgid).map(x => x.pgid));
|
|
83
|
+
const pids = new Set(), stack = procs.filter(p => groups.has(p.pgid)).map(p => p.pid);
|
|
84
|
+
while (stack.length) {
|
|
85
|
+
const pid = stack.pop();
|
|
86
|
+
if (pids.has(pid) || nested.has(pid)) continue;
|
|
87
|
+
pids.add(pid);
|
|
88
|
+
stack.push(...(kids.get(pid) || []));
|
|
89
|
+
}
|
|
90
|
+
return pids;
|
|
91
|
+
}
|
|
77
92
|
// Memory in bytes and CPU in cores for a set of pids. A process top didn't
|
|
78
93
|
// list (it started since) counts at its RSS.
|
|
79
94
|
export function usage(pids, procs, foot) {
|
|
@@ -126,7 +141,7 @@ function shareDisk(s, got, m, t) {
|
|
|
126
141
|
// Measure every run lease on the machine, if this process won the slot.
|
|
127
142
|
// Called from each `dibs run` on its group-tracking tick. True if it measured.
|
|
128
143
|
export function sample(t = now()) {
|
|
129
|
-
if (
|
|
144
|
+
if (!claim(t)) return false;
|
|
130
145
|
// A plain read: the state file is replaced whole, never written in place.
|
|
131
146
|
let s;
|
|
132
147
|
try { s = JSON.parse(fs.readFileSync(paths.state, 'utf8')); } catch { return false; }
|
package/src/platform.mjs
CHANGED
|
@@ -119,8 +119,8 @@ export function parent(pid) {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// Every process: pid, parent, process group, % of one core, resident bytes
|
|
122
|
-
// (
|
|
123
|
-
// no process groups.
|
|
122
|
+
// (the working set on Windows), command line. The group is the pid on Windows,
|
|
123
|
+
// which has no process groups.
|
|
124
124
|
let procCache = null;
|
|
125
125
|
export function processes() {
|
|
126
126
|
if (procCache && Date.now() - procCache.at < 5000) return procCache.list;
|
|
@@ -129,12 +129,15 @@ export function processes() {
|
|
|
129
129
|
|
|
130
130
|
function readProcesses() {
|
|
131
131
|
if (WIN) {
|
|
132
|
-
// Two samples of total processor time, a second apart, give a CPU
|
|
132
|
+
// Two samples of total processor time, a second apart, give a CPU %; one WMI query gives
|
|
133
|
+
// parents, working sets and command lines. One PowerShell for all of it, never one per pid.
|
|
134
|
+
// WMI's ProcessId is a UInt32 and Get-Process's Id an Int32: as hashtable keys they never match uncast.
|
|
133
135
|
const txt = ps(`$a = @{}; Get-Process | ForEach-Object { $a[$_.Id] = $_.TotalProcessorTime.TotalMilliseconds }; Start-Sleep -Milliseconds 1000;`
|
|
134
|
-
+ ` Get-
|
|
135
|
-
+ `
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
+ ` $b = @{}; Get-Process | ForEach-Object { $b[$_.Id] = $_.TotalProcessorTime.TotalMilliseconds };`
|
|
137
|
+
+ ` Get-CimInstance Win32_Process | ForEach-Object { $i = [int]$_.ProcessId;`
|
|
138
|
+
+ ` if ($a[$i] -ne $null -and $b[$i] -ne $null) { "$i\`t$($_.ParentProcessId)\`t$([math]::Round(($b[$i] - $a[$i]) / 10, 1))\`t$($_.WorkingSetSize)\`t$($_.CommandLine)" } }`);
|
|
139
|
+
return (txt ?? '').split(/\r?\n/).map(l => l.split('\t')).filter(f => f.length === 5 && f[4])
|
|
140
|
+
.map(([pid, ppid, cpu, rss, args]) => ({ pid: Number(pid), ppid: Number(ppid), pgid: Number(pid), cpu: Number(cpu), rss: Number(rss) || 0, args }));
|
|
138
141
|
}
|
|
139
142
|
return run('ps', ['-Ao', 'pid=,ppid=,pgid=,pcpu=,rss=,args=']).split('\n')
|
|
140
143
|
.map(l => l.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+([\d.]+)\s+(\d+)\s+(.*)$/)).filter(Boolean)
|
package/src/proc.mjs
CHANGED
|
@@ -37,11 +37,21 @@ export function makeAlive(pids) {
|
|
|
37
37
|
// The agent session that owns this call (Claude Code, Codex, Cursor...), found
|
|
38
38
|
// by walking up the process tree. Holds outlive a single tool call, so they
|
|
39
39
|
// hang off this process. For Claude Code, its name is the one SendMessage uses.
|
|
40
|
+
// What other agent programs set (src/owner.mjs AGENT_ENV, less Claude Code's own).
|
|
41
|
+
const OTHER_AGENTS = ['CODEX_SANDBOX', 'CODEX_THREAD_ID', 'CURSOR_AGENT', 'GEMINI_CLI', 'OPENCODE'];
|
|
40
42
|
let cached;
|
|
41
43
|
function session() {
|
|
42
44
|
if (cached !== undefined) return cached;
|
|
43
45
|
cached = null;
|
|
44
46
|
if (process.env.DIBS_NO_SESSION) return cached; // tests act as several agents from one session
|
|
47
|
+
// Inside Claude Code the session names itself: its file in SESSIONS gives the pid without
|
|
48
|
+
// walking up the tree, one ps per level (3 of them, 190 ms of a board at load 60 on
|
|
49
|
+
// 2026-11-11). Not when another agent program runs under it: then the nearest is that one.
|
|
50
|
+
const sid = process.env.CLAUDE_CODE_SESSION_ID;
|
|
51
|
+
if (sid && !OTHER_AGENTS.some(k => process.env[k])) {
|
|
52
|
+
const f = sessionFiles().find(x => x.sessionId === sid && answers(x.pid));
|
|
53
|
+
if (f) return (cached = { pid: f.pid, name: f.name, app: 'claude', start: pstart(f.pid) });
|
|
54
|
+
}
|
|
45
55
|
let pid = callerPid();
|
|
46
56
|
for (let i = 0; i < 25 && pid > 1; i++) {
|
|
47
57
|
const p = parent(pid);
|
package/src/relay.mjs
CHANGED
|
@@ -112,6 +112,52 @@ export const tokenHash = rt => b64u(sha(Buffer.concat([utf8('dibs-relay-token-v1
|
|
|
112
112
|
const MAX_HASHES = 56;
|
|
113
113
|
// Sign-in codes the relay's index takes from one machine at once (relay/src/index.js MAX_CODES).
|
|
114
114
|
const MAX_CODES = 10;
|
|
115
|
+
|
|
116
|
+
// The pairing code shown beside the QR code, for typing at app.dibs.cc instead of scanning:
|
|
117
|
+
// 12 Crockford base32 characters, 7KQM-2XRP-9DHT. The first 4 (R) name a drop at the relay; the
|
|
118
|
+
// other 8 (K, 40 bits) never leave this Mac and the person's eyes. The drop holds the link's
|
|
119
|
+
// fragment (mid, secret, fingerprint) sealed with AES-256-GCM under
|
|
120
|
+
// PBKDF2-SHA256(K, salt "dibs-code-v1" || R, 600,000 iterations). The page fetches the drop by R,
|
|
121
|
+
// derives the key from K and opens it, then pairs exactly as the link does, so the relay never
|
|
122
|
+
// learns the secret. Someone who gets the box (the relay itself, or a guesser who hit a live R)
|
|
123
|
+
// has 2^40 keys to try at 600,000 PBKDF2 rounds each: 3.3e17 HMAC-SHA256 calls on average. A
|
|
124
|
+
// top-end GPU does about 9e9 a second, so finding K inside the link's ten minutes takes some
|
|
125
|
+
// 60,000 of them, and the secret inside is worthless after those ten minutes or once the link is
|
|
126
|
+
// used. The relay hands out each box at most 3 times (relay/src/codebook.js), limits fetches per
|
|
127
|
+
// address, and drops the box when the link is used, revoked or expires.
|
|
128
|
+
const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
129
|
+
export const CODE_ITERATIONS = 600000;
|
|
130
|
+
const CODE_SALT = 'dibs-code-v1';
|
|
131
|
+
// What people type: lower case, spaces and dashes are fine, and O, I and L read as 0, 1 and 1.
|
|
132
|
+
export const normCode = s => String(s || '').toUpperCase().replace(/[^0-9A-Z]/g, '').replace(/O/g, '0').replace(/[IL]/g, '1');
|
|
133
|
+
export const isCode = s => /^[0-9A-HJKMNP-TV-Z]{12}$/.test(s);
|
|
134
|
+
const randomCrockford = n => Array.from({ length: n }, () => CROCKFORD[crypto.randomInt(32)]).join('');
|
|
135
|
+
// DIBS_FAKE_CODES: codes to hand out first, comma-separated, so a test can make two Macs pick the
|
|
136
|
+
// same drop name. Read once per process.
|
|
137
|
+
const fakeCodes = (process.env.DIBS_FAKE_CODES || '').split(',').map(normCode).filter(isCode);
|
|
138
|
+
// A new code whose drop name none of this Mac's open links uses.
|
|
139
|
+
function freshCode() {
|
|
140
|
+
const mine = new Set(load().pairs.map(p => p.cr));
|
|
141
|
+
for (;;) {
|
|
142
|
+
const c = fakeCodes.shift() || randomCrockford(12);
|
|
143
|
+
if (!mine.has(c.slice(0, 4))) return c;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// How long dibs pair --remote waits for the relay to take its code (the connector notices the new
|
|
147
|
+
// link within TOKEN_SYNC, then it's one round trip), and how many fresh codes it tries when
|
|
148
|
+
// another Mac already holds the drop name. One clash is a 1 in a million event; three in a row
|
|
149
|
+
// means something else is wrong.
|
|
150
|
+
const CODE_ACK_WAIT = 5000;
|
|
151
|
+
const CODE_TRIES = 3;
|
|
152
|
+
export const showCode = c => `${c.slice(0, 4)}-${c.slice(4, 8)}-${c.slice(8, 12)}`;
|
|
153
|
+
const codeKey = (k, r) => crypto.pbkdf2Sync(utf8(k), utf8(CODE_SALT + r), CODE_ITERATIONS, 32, 'sha256');
|
|
154
|
+
// iv (12) || ciphertext || tag (16), base64url, with the salt as associated data.
|
|
155
|
+
export function sealCode(frag, r, k) {
|
|
156
|
+
const iv = crypto.randomBytes(12);
|
|
157
|
+
const c = crypto.createCipheriv('aes-256-gcm', codeKey(k, r), iv);
|
|
158
|
+
c.setAAD(utf8(CODE_SALT + r));
|
|
159
|
+
return b64u(Buffer.concat([iv, c.update(utf8(frag)), c.final(), c.getAuthTag()]));
|
|
160
|
+
}
|
|
115
161
|
function openBox(key, box) {
|
|
116
162
|
if (box.length !== BOX_LEN) return null;
|
|
117
163
|
try {
|
|
@@ -176,12 +222,57 @@ function locked(fn) {
|
|
|
176
222
|
export function newPairing({ act = false, account = false } = {}) {
|
|
177
223
|
const k = keys();
|
|
178
224
|
const secret = crypto.randomBytes(32);
|
|
225
|
+
const frag = `${k.mid}.${b64u(secret)}.${k.fp}`;
|
|
226
|
+
// A browser link gets a code to type as well. The account link opens on /account, which has
|
|
227
|
+
// its own sign-in, so it has none.
|
|
228
|
+
const code = account ? null : freshCode();
|
|
229
|
+
const box = code && sealCode(frag, code.slice(0, 4), code.slice(4));
|
|
230
|
+
const pid = b64u(pairId(secret));
|
|
179
231
|
locked(w => {
|
|
180
|
-
w.pairs.push({ pid
|
|
232
|
+
w.pairs.push({ pid, key: b64u(pairKey(secret)), nk: b64u(nameKey(secret)), th: tokenHash(pairTicket(secret)), exp: now() + PAIR_LIFE, fails: 0, ...(act ? { act: true } : {}), ...(account ? { acct: true } : {}), ...(code ? { cr: code.slice(0, 4), cb: box } : {}) });
|
|
181
233
|
w.pairs = w.pairs.slice(-MAX_PAIRS);
|
|
182
234
|
});
|
|
183
|
-
|
|
184
|
-
|
|
235
|
+
return { link: account ? `${PAGE}account#join=${frag}` : `${PAGE}#p=${frag}`, ...(code ? { code: showCode(code) } : {}), pid, frag, mid: k.mid, fp: k.fp, life: PAIR_LIFE, exp: now() + PAIR_LIFE, act };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// A new code for an open link whose drop name another Mac holds at the relay: the same link,
|
|
239
|
+
// sealed again under a fresh drop name and key. Null if the link is gone (used, revoked, expired).
|
|
240
|
+
export function recode(pid, frag) {
|
|
241
|
+
const code = freshCode();
|
|
242
|
+
const box = sealCode(frag, code.slice(0, 4), code.slice(4));
|
|
243
|
+
return locked(w => {
|
|
244
|
+
const p = w.pairs.find(x => x.pid === pid);
|
|
245
|
+
if (!p) return null;
|
|
246
|
+
Object.assign(p, { cr: code.slice(0, 4), cb: box });
|
|
247
|
+
delete p.ca;
|
|
248
|
+
return showCode(code);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// The relay's answer to a drops message: which drop names it holds for this Mac (ok) and which
|
|
253
|
+
// another machine already holds (taken). Kept on each open link as ca, for pairRemote to wait on.
|
|
254
|
+
export function dropsAck(m) {
|
|
255
|
+
const ok = new Set(Array.isArray(m?.ok) ? m.ok : []), taken = new Set(Array.isArray(m?.taken) ? m.taken : []);
|
|
256
|
+
locked(w => {
|
|
257
|
+
for (const p of w.pairs) {
|
|
258
|
+
if (typeof p.cr !== 'string') continue;
|
|
259
|
+
if (taken.has(p.cr)) p.ca = 'taken';
|
|
260
|
+
else if (ok.has(p.cr)) p.ca = 'ok';
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// What the relay said about this link's code: 'ok', 'taken', 'gone' (the link was used or
|
|
266
|
+
// revoked meanwhile, so the code no longer matters), or null if it hasn't said within CODE_ACK_WAIT.
|
|
267
|
+
async function codeAck(pid, code) {
|
|
268
|
+
const r = normCode(code).slice(0, 4), until = now() + CODE_ACK_WAIT;
|
|
269
|
+
while (now() < until) {
|
|
270
|
+
const p = load().pairs.find(x => x.pid === pid);
|
|
271
|
+
if (!p) return 'gone';
|
|
272
|
+
if (p.cr === r && p.ca) return p.ca;
|
|
273
|
+
await sleep(100);
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
185
276
|
}
|
|
186
277
|
|
|
187
278
|
export const devices = () => Object.entries(load().devices).map(([id, d]) => ({ id, ...d }));
|
|
@@ -550,6 +641,12 @@ export function relayTokens(w = load(), t = now()) {
|
|
|
550
641
|
return { t: 'tokens', h, p: w.pairs.filter(p => p.exp > t && typeof p.th === 'string').map(p => p.th), c: w.mcp ? mcpCodes().slice(-MAX_CODES) : [] };
|
|
551
642
|
}
|
|
552
643
|
|
|
644
|
+
// The sealed boxes of open links' codes, by drop name, for the relay to hand to whoever types
|
|
645
|
+
// the code (see CROCKFORD above). Sent apart from the tokens, which have a size limit of their own.
|
|
646
|
+
export function relayDrops(w = load(), t = now()) {
|
|
647
|
+
return { t: 'drops', d: w.pairs.filter(p => p.exp > t && typeof p.cr === 'string' && typeof p.cb === 'string' && p.ca !== 'taken').map(p => ({ r: p.cr, b: p.cb, exp: p.exp })) };
|
|
648
|
+
}
|
|
649
|
+
|
|
553
650
|
function status(state, extra = {}) {
|
|
554
651
|
try {
|
|
555
652
|
const tmp = `${STATUS}.${process.pid}`;
|
|
@@ -657,13 +754,15 @@ export function connectOnce(base, k, call) {
|
|
|
657
754
|
let ws;
|
|
658
755
|
try { ws = new WebSocket(url); } catch (e) { return resolve(e.message); }
|
|
659
756
|
ws.binaryType = 'arraybuffer';
|
|
660
|
-
let authed = false, lastHeard = now(), done = false, sentTokens = '';
|
|
757
|
+
let authed = false, lastHeard = now(), done = false, sentTokens = '', sentDrops = '';
|
|
661
758
|
const finish = why => { if (done) return; done = true; clearInterval(beat); clearInterval(watch); clearInterval(approvals); peer.closeAll(); try { ws.close(); } catch {} resolve(why); };
|
|
662
759
|
// The relay's list of who may connect follows relay.json within a second: a new link opens
|
|
663
760
|
// the pairing pool, a pairing adds a hash, a revoke removes one (and its open sessions end).
|
|
664
761
|
const syncTokens = () => {
|
|
665
762
|
if (!authed || ws.readyState !== 1) return;
|
|
666
|
-
const
|
|
763
|
+
const w = load();
|
|
764
|
+
const t = JSON.stringify(relayTokens(w)), d = JSON.stringify(relayDrops(w));
|
|
765
|
+
if (d !== sentDrops) { sentDrops = d; ws.send(d); }
|
|
667
766
|
if (t === sentTokens) return;
|
|
668
767
|
sentTokens = t;
|
|
669
768
|
ws.send(t);
|
|
@@ -711,6 +810,7 @@ export function connectOnce(base, k, call) {
|
|
|
711
810
|
if (m.t === 'http' && typeof m.id === 'string') {
|
|
712
811
|
return mcpAnswer(m, k).catch(() => offJson(500)).then(r => { if (ws.readyState === 1) ws.send(httpRes(m.id, r)); });
|
|
713
812
|
}
|
|
813
|
+
if (m.t === 'drops-res') { try { dropsAck(m); } catch (e) { log(`relay: couldn't note which codes the relay took: ${e.message}`); } return; }
|
|
714
814
|
if (m.t === 'open' && unb64u(m.ch, 16)) return peer.open(m.ch);
|
|
715
815
|
if (m.t === 'gone' && unb64u(m.ch, 16)) return peer.gone(m.ch);
|
|
716
816
|
return;
|
|
@@ -728,15 +828,32 @@ export function connectOnce(base, k, call) {
|
|
|
728
828
|
const ago = t => (t ? `${dur(now() - t)} ago` : 'never');
|
|
729
829
|
|
|
730
830
|
// The remote half of `dibs pair`: --remote [--allow-actions], and its rows in --list and --revoke.
|
|
731
|
-
export function pairRemote({ act = false } = {}) {
|
|
831
|
+
export async function pairRemote({ act = false } = {}) {
|
|
732
832
|
const p = newPairing({ act });
|
|
733
833
|
logChange('pair remote', { actions: act });
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
834
|
+
// The code is shown only once the relay has taken it, so the one printed works. Another Mac
|
|
835
|
+
// holding the same drop name gets a fresh code for the same link; no answer from the relay
|
|
836
|
+
// (it's slow, or the connector isn't running) prints the code with a warning.
|
|
837
|
+
const s = statusLine();
|
|
838
|
+
const connected = !!s?.startsWith('connected');
|
|
839
|
+
let code = p.code, ack = connected ? await codeAck(p.pid, code) : null;
|
|
840
|
+
for (let i = 1; ack === 'taken' && i < CODE_TRIES; i++) {
|
|
841
|
+
code = recode(p.pid, p.frag);
|
|
842
|
+
ack = code ? await codeAck(p.pid, code) : 'gone';
|
|
843
|
+
}
|
|
844
|
+
const page = PAGE.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
|
845
|
+
if (ack === 'taken') {
|
|
846
|
+
console.log(`${render(qr(p.link))}\n`);
|
|
847
|
+
console.log(`Scan the QR code with your phone. Its code clashed with another Mac's at the relay, so there's none to type this time: run dibs pair --remote again for one.`);
|
|
848
|
+
} else {
|
|
849
|
+
console.log(`${render(qr(p.link))}\nCode: ${code}\n`);
|
|
850
|
+
console.log(`Scan the QR code with your phone, or type the code at ${page}.`);
|
|
851
|
+
if (connected && !ack) console.log(`The relay hasn't confirmed the code yet, so it may not work. The QR code works either way.`);
|
|
852
|
+
}
|
|
853
|
+
console.log(`It works once, until ${clockOf(p.exp)} (${p.life / MIN} minutes). That browser checks it reached this Mac by its fingerprint ${p.fp.slice(0, 16)}...`);
|
|
854
|
+
console.log(`The QR code as a link:\n${p.link}\n`);
|
|
737
855
|
console.log(act ? 'It can act: boost, pause, resume and stop jobs, cap an agent, set the pace, cancel scheduled runs. Never message agents, answer their questions, or change the hook or your hours. Revoke it if the device is lost.'
|
|
738
856
|
: 'It can only look. To let a browser change things too: dibs pair --remote --allow-actions');
|
|
739
|
-
const s = statusLine();
|
|
740
857
|
if (!s || s.startsWith('not running')) console.log(`\nThis Mac isn't connected to the relay yet. Turn it on: dibs service install relay`);
|
|
741
858
|
}
|
|
742
859
|
// dibs connect --account: a link a browser signed in to a dibs account opens, to add this Mac to
|
package/src/service.mjs
CHANGED
|
@@ -30,7 +30,11 @@ const label = k => `dev.dibs.${k}`;
|
|
|
30
30
|
const plist = k => path.join(process.env.DIBS_LAUNCH_AGENTS || path.join(os.homedir(), 'Library', 'LaunchAgents'), `${label(k)}.plist`);
|
|
31
31
|
const LAUNCHCTL = process.env.DIBS_LAUNCHCTL || 'launchctl';
|
|
32
32
|
const unit = k => path.join(process.env.DIBS_LAUNCH_AGENTS || path.join(os.homedir(), '.config', 'systemd', 'user'), `dibs-${k}.service`);
|
|
33
|
-
|
|
33
|
+
// The guard service's output can't go in guard.log: that's the hook's own error
|
|
34
|
+
// log, which the alerts read as hook failures (src/alerts.mjs readHook).
|
|
35
|
+
const LOGS = { guard: 'guard-service.log' };
|
|
36
|
+
export const logName = k => LOGS[k] || `${k}.log`;
|
|
37
|
+
const logFile = k => path.join(HOME, logName(k));
|
|
34
38
|
const sh = (cmd, args) => { try { return execFileSync(cmd, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }); } catch (e) { return e.stdout || ''; } };
|
|
35
39
|
const esc = s => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
36
40
|
const uid = () => process.getuid?.() ?? 0;
|
package/src/state.mjs
CHANGED
|
@@ -105,7 +105,7 @@ function change(fn, lock) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// Every pid the state names, whose start times reap() checks.
|
|
108
|
-
const pidsOf = s => [...(s.leases || []).map(l => l.pid), ...(s.queue || []).map(q => q.pid || q.keptFor), ...(s.resets || []).flatMap(x => [x.pid, x.cpid])];
|
|
108
|
+
export const pidsOf = s => [...(s.leases || []).map(l => l.pid), ...(s.queue || []).map(q => q.pid || q.keptFor), ...(s.resets || []).flatMap(x => [x.pid, x.cpid])];
|
|
109
109
|
|
|
110
110
|
// Read those start times before taking the lock, so reap() under it finds them in
|
|
111
111
|
// makeAlive's cache instead of running ps: on 2026-11-11 that ps (100 to 700 ms on a
|
package/src/talk.mjs
CHANGED
|
@@ -439,9 +439,9 @@ function writeListeners(l, h) {
|
|
|
439
439
|
if (!Object.keys(l).length) return fs.rmSync(LISTENERS, { force: true });
|
|
440
440
|
commit(h, LISTENERS, JSON.stringify(l));
|
|
441
441
|
}
|
|
442
|
-
// Said when it hands
|
|
443
|
-
//
|
|
444
|
-
const AGAIN = '
|
|
442
|
+
// Said first when it hands something over: listening stops with this run, so the agent's first
|
|
443
|
+
// move is to start it again. If it doesn't, the hook keeps it going at its stop until it does (src/guard.mjs rearm).
|
|
444
|
+
const AGAIN = 'First start dibs listen again with run_in_background, so the next message wakes you too.';
|
|
445
445
|
export async function listen(args) {
|
|
446
446
|
const o = { for: Infinity, json: false, words: [] };
|
|
447
447
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -535,12 +535,12 @@ export async function listen(args) {
|
|
|
535
535
|
const changes = since(seenBy(th.seenKey) || VERSION, r.updated);
|
|
536
536
|
markSeen(th.seenKey, r.updated);
|
|
537
537
|
if (o.json) return console.log(JSON.stringify({ updated: r.updated, changes, again: AGAIN }));
|
|
538
|
-
return console.log(
|
|
538
|
+
return console.log(`${AGAIN}\n\ndibs was updated to ${r.updated}. What changed for you:\n\n${changes.map(c => `${c.version}\n${c.body}`).join('\n\n') || '(no notes)'}`);
|
|
539
539
|
}
|
|
540
540
|
if (r.release) {
|
|
541
541
|
toldRelease(th.key, r.release);
|
|
542
542
|
if (o.json) return console.log(JSON.stringify({ release: r.release, have: VERSION, upgrade: UPGRADE, again: AGAIN }));
|
|
543
|
-
return console.log(
|
|
543
|
+
return console.log(`${AGAIN}\n\ndibs ${r.release} is out (you have ${VERSION}). The person upgrades with: ${UPGRADE}\nDon't upgrade it yourself; mention it to the person if it matters to your work.`);
|
|
544
544
|
}
|
|
545
545
|
if (r.timeout) {
|
|
546
546
|
if (o.json) console.log(JSON.stringify({ timeout: true, messages: [] }));
|
|
@@ -548,9 +548,12 @@ export async function listen(args) {
|
|
|
548
548
|
process.exit(LISTEN_TIMEOUT);
|
|
549
549
|
}
|
|
550
550
|
if (o.json) return console.log(JSON.stringify({ messages: r.got.map(m => ({ from: m.kind === 'notice' ? 'dibs' : m.by ? 'agent' : 'person', ...(m.by && { by: m.by }), kind: m.kind, text: m.text, at: m.at })), again: AGAIN }));
|
|
551
|
-
console.log(`${
|
|
551
|
+
console.log(`${AGAIN}\n\n${texts(r.got)}`);
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
+
// The pids of every dibs listen on record, for the board to check with the state's in one ps.
|
|
555
|
+
export const listenerPids = () => Object.values(readListeners()).map(x => x.pid);
|
|
556
|
+
|
|
554
557
|
// Who's listening now, by thread key, read without the lock: for the board and dibs threads.
|
|
555
558
|
export function listening() {
|
|
556
559
|
const l = Object.entries(readListeners());
|
package/src/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Bump with every release and add a matching section at the top of CHANGELOG.md.
|
|
2
|
-
export const VERSION = '0.0.
|
|
2
|
+
export const VERSION = '0.0.181';
|
package/src/web.mjs
CHANGED
|
@@ -591,7 +591,8 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
591
591
|
const r = await act(['pair', '--remote', ...(a.act === true ? ['--allow-actions'] : [])]);
|
|
592
592
|
const link = r.status === 200 ? r.json.said.split('\n').find(l => /^https:\/\//.test(l.trim()))?.trim() : null;
|
|
593
593
|
if (!link) return r.status === 200 ? { status: 502, json: { error: 'dibs pair --remote printed no link' } } : r;
|
|
594
|
-
|
|
594
|
+
const code = /^Code: ([0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{4})$/m.exec(r.json.said)?.[1] || null;
|
|
595
|
+
return ok({ link, code, qr: qr(link).map(row => row.map(Boolean)), act: a.act === true });
|
|
595
596
|
}
|
|
596
597
|
// A machine joins the group with this code: dibs pair --machine. Local only, never through the relay:
|
|
597
598
|
// whoever joins can run commands on every machine in the group.
|