@dibssoftware/dibs 0.0.0-stage → 0.0.179
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 +594 -0
- package/LICENSE +670 -0
- package/README.md +85 -2
- package/bin/dibs-guard.mjs +7 -0
- package/bin/dibs.mjs +548 -0
- package/docs/benchmarks.md +193 -0
- package/docs/files.md +30 -0
- package/docs/guard.md +91 -0
- package/docs/later.md +43 -0
- package/docs/machines.md +147 -0
- package/docs/questions.md +78 -0
- package/docs/reference.md +157 -0
- package/docs/relay.md +196 -0
- package/docs/releasing.md +27 -0
- package/docs/scheduling.md +163 -0
- package/docs/simulators.md +17 -0
- package/package.json +45 -4
- package/skills/dibs/SKILL.md +183 -0
- package/src/acquire.mjs +700 -0
- package/src/admin.mjs +145 -0
- package/src/agents.mjs +145 -0
- package/src/alerts.mjs +499 -0
- package/src/answers.mjs +65 -0
- package/src/board.mjs +202 -0
- package/src/broker.mjs +369 -0
- package/src/commands.mjs +810 -0
- package/src/config.mjs +324 -0
- package/src/connect.mjs +106 -0
- package/src/cool.mjs +160 -0
- package/src/diskwarn.mjs +154 -0
- package/src/events.mjs +96 -0
- package/src/files.mjs +1123 -0
- package/src/guard.mjs +613 -0
- package/src/history.mjs +247 -0
- package/src/hogs.mjs +227 -0
- package/src/later.mjs +487 -0
- package/src/measure.mjs +262 -0
- package/src/news.mjs +101 -0
- package/src/nodecheck.mjs +17 -0
- package/src/notes.mjs +171 -0
- package/src/notices.mjs +160 -0
- package/src/ondemand.mjs +572 -0
- package/src/overlap.mjs +151 -0
- package/src/override.mjs +360 -0
- package/src/owner.mjs +30 -0
- package/src/plain.mjs +470 -0
- package/src/platform.mjs +357 -0
- package/src/preempt.mjs +438 -0
- package/src/primer.mjs +89 -0
- package/src/proc.mjs +99 -0
- package/src/progress.mjs +187 -0
- package/src/qr.mjs +204 -0
- package/src/questions.mjs +389 -0
- package/src/quota.mjs +81 -0
- package/src/reads.mjs +54 -0
- package/src/relay.mjs +779 -0
- package/src/remote.mjs +584 -0
- package/src/reset.mjs +127 -0
- package/src/schedule.mjs +1020 -0
- package/src/scratch.mjs +61 -0
- package/src/serve.mjs +742 -0
- package/src/service.mjs +221 -0
- package/src/shard.mjs +59 -0
- package/src/simctl.mjs +42 -0
- package/src/simpool.mjs +258 -0
- package/src/state.mjs +201 -0
- package/src/stats.mjs +328 -0
- package/src/style.mjs +44 -0
- package/src/talk.mjs +702 -0
- package/src/thin.sh +130 -0
- package/src/trust.mjs +152 -0
- package/src/util.mjs +184 -0
- package/src/version.mjs +2 -0
- package/src/web.mjs +1119 -0
- package/src/worker.mjs +318 -0
package/bin/dibs.mjs
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
":" //; case "$1" in run|hold) [ "${DIBS_THIN:-}" != 0 ] && ! grep -qsE '"waits"[[:space:]]*:[[:space:]]*"(fat|node)"' "${DIBS_HOME:-$HOME/.dibs}/config.json" && ! { grep -qs '"leases": \[\]' "${DIBS_HOME:-$HOME/.dibs}/state.json" && grep -qs '"queue": \[\]' "${DIBS_HOME:-$HOME/.dibs}/state.json"; } && { f=$0; while [ -L "$f" ]; do l=$(readlink "$f"); case $l in /*) f=$l;; *) f=${f%/*}/$l;; esac; done; exec /bin/sh "${f%/*}/../src/thin.sh" "$f" "$@"; };; esac; exec node --max-semi-space-size=1 "$0" "$@"
|
|
3
|
+
// Line 2 is read by sh and ignored by Node (a string, then a comment). sh
|
|
4
|
+
// sends run and hold to src/thin.sh unless config.json says "waits": "fat"
|
|
5
|
+
// (or "node") or DIBS_THIN=0 is set, and everything else to Node, as before.
|
|
6
|
+
// With nothing held and nobody in line it goes straight to Node too: a thin
|
|
7
|
+
// wait starts Node twice (to get in line, then to run), 75 ms more, for a wait
|
|
8
|
+
// that won't happen.
|
|
9
|
+
// dibs: take turns on shared machine resources so parallel agents stop colliding.
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { loadConfig, paths, profiled } from '../src/config.mjs';
|
|
14
|
+
import { identity } from '../src/proc.mjs';
|
|
15
|
+
import { changelog, seenBy, markSeen, newer } from '../src/news.mjs';
|
|
16
|
+
import { PRIORITY_SHIFT, PRIORITIES, priority } from '../src/schedule.mjs';
|
|
17
|
+
import { VERSION } from '../src/version.mjs';
|
|
18
|
+
import { run, notifyOnExit, hold, release, when, why, mine, who, yieldTo, ask, requests, status, freePort, pace, checkNames, nearest } from '../src/commands.mjs';
|
|
19
|
+
import { remoteRun, join, machines } from '../src/remote.mjs';
|
|
20
|
+
import { sims } from '../src/simpool.mjs';
|
|
21
|
+
import { question, questions, answer, hoursCmd } from '../src/questions.mjs';
|
|
22
|
+
import { say, tell, threads, noticesFor, listen } from '../src/talk.mjs';
|
|
23
|
+
import { bytes, ms, deadline, die, noSpace, fullDisk, setCaller, lastDie, lastDieCode } from '../src/util.mjs';
|
|
24
|
+
import { event } from '../src/events.mjs';
|
|
25
|
+
import { fileRes, isFiles, resList } from '../src/files.mjs';
|
|
26
|
+
import { boost, pause, resume, stop, cap } from '../src/override.mjs';
|
|
27
|
+
import { later } from '../src/later.mjs';
|
|
28
|
+
import { isQuota } from '../src/quota.mjs';
|
|
29
|
+
|
|
30
|
+
// Commands no waiting or running dibs needs load when called: a waiter is a
|
|
31
|
+
// long-lived process, and each module it never uses costs it memory.
|
|
32
|
+
const lazy = name => import(`../src/${name}.mjs`);
|
|
33
|
+
|
|
34
|
+
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
35
|
+
|
|
36
|
+
const HELP = `dibs ${VERSION}: agents take turns on this machine's simulator, builds, test runs and deploys.
|
|
37
|
+
|
|
38
|
+
Wait your turn
|
|
39
|
+
dibs run test -m "why" -- npm test wait for a turn, run, give it back when it exits
|
|
40
|
+
dibs run sim,xcode-build -- <command> need two things? ask for both at once
|
|
41
|
+
dibs hold sim --for 20m -m "why" keep it across several commands, each still in dibs run sim -- <cmd>
|
|
42
|
+
(no wait under your hold); give it back: dibs release sim
|
|
43
|
+
dibs hold 'files:src/auth/**' -m "why" keep other agents' edits off these files
|
|
44
|
+
dibs run test --anywhere -- <command> on whichever machine in the group starts it soonest (--on <machine>: that one)
|
|
45
|
+
dibs run deploy --quick -- ./ship.sh a command over in under 15 s starts at once (or --est 10s; dibs learns it after)
|
|
46
|
+
|
|
47
|
+
Tell the person
|
|
48
|
+
dibs progress "what you did or found" --task <name> --eta 30m as often as you commit; then --blocked or --done
|
|
49
|
+
dibs question "Ship 123 now?" --options yes,no --recommend yes -m why --one-way "testers get it at once"
|
|
50
|
+
only one-way doors reach the person; the same command plus --wait reads the answer
|
|
51
|
+
dibs say "done: tests pass" an FYI in your thread, no question
|
|
52
|
+
|
|
53
|
+
Other agents and their jobs
|
|
54
|
+
dibs tell <agent> "..." a message that reaches it with its next tool call (or dibs say --to <agent>)
|
|
55
|
+
dibs boost <id> high -m "why" move a job up (urgent|high|normal|low|idle); --owner <its session> if not yours
|
|
56
|
+
|
|
57
|
+
Look around
|
|
58
|
+
dibs what each resource is doing and who's next
|
|
59
|
+
dibs why where you are in the queue and what you're waiting for
|
|
60
|
+
dibs when sim when you'd get it, without joining the queue
|
|
61
|
+
dibs who sim | dibs mine | dibs history who has it, what you have (exit 1: nothing), what happened this week
|
|
62
|
+
dibs yield web-app let another agent go first
|
|
63
|
+
|
|
64
|
+
Set up
|
|
65
|
+
dibs pace quiet|normal|max how hard dibs drives this machine
|
|
66
|
+
dibs guard install make Claude Code agents use dibs when they forget
|
|
67
|
+
dibs init point your agents' CLAUDE.md and AGENTS.md at dibs.md (install does it)
|
|
68
|
+
dibs machines other machines in the group
|
|
69
|
+
|
|
70
|
+
Priority: -p urgent|high|normal|low|idle (urgent and high need -m "why"). Due by a time: --by 23:30.
|
|
71
|
+
Exit 75: your command never ran (you gave up waiting) and didn't fail. Run the same command again within 2 minutes.
|
|
72
|
+
Everything else: dibs help all`;
|
|
73
|
+
|
|
74
|
+
const LATER_HELP = `run it later
|
|
75
|
+
dibs later <res> --at 02:00 -- <cmd> schedule a run for a time (at most 7 days out); returns at once with its id
|
|
76
|
+
dibs later <res> --in 3h -- <cmd> ...or a while from now
|
|
77
|
+
dibs later <res> --after <what> -- <cmd> ...or when something ends: #42 on the board, an agent (web-app, or web-app:deploy
|
|
78
|
+
for its deploy), or an earlier later job (l3). --after-ok: only if it succeeded
|
|
79
|
+
When due, it runs as dibs run --wait with your flags, in this folder, with PATH,
|
|
80
|
+
HOME and LANG (more with --env NAME). Output: ~/.dibs/later/<id>.log
|
|
81
|
+
dibs later list [--json] scheduled, waiting, running, and how the finished ones ended
|
|
82
|
+
dibs later cancel <id> drop it, or stop it if it's running`;
|
|
83
|
+
|
|
84
|
+
const HELP_ALL = `dibs ${VERSION}: take turns on shared machine resources.
|
|
85
|
+
|
|
86
|
+
get a turn
|
|
87
|
+
dibs run <res>[,<res>] [flags] -- <cmd> wait for the resources, run cmd, release when it exits
|
|
88
|
+
dibs run <res> --after #42 -- <cmd> ...but join the line only once job #42 has ended
|
|
89
|
+
dibs hold <res> [--for 20m] keep a resource across several tool calls (max 1h); again to extend
|
|
90
|
+
dibs release [<res>] give back your holds
|
|
91
|
+
dibs hold 'files:src/auth/**' -m "why" keep other agents' edits off these paths (from the git root; * ** ?; quote it)
|
|
92
|
+
|
|
93
|
+
ask without joining the queue
|
|
94
|
+
dibs [--detail] the board: what each resource is doing and who's next (--detail: ids and numbers)
|
|
95
|
+
dibs who <res> who holds it, until when, who's next
|
|
96
|
+
dibs when <res>[,<res>] when you'd get it if you asked now
|
|
97
|
+
dibs why [--detail] why you're waiting, in sentences (--detail: how your place was worked out)
|
|
98
|
+
dibs mine [<res>] what you hold and wait for (exit 1 if nothing: "do I hold sim?")
|
|
99
|
+
dibs alerts [--json] [--all] what's wrong, each with its fix: long waits, memory holding work back, stuck or failed
|
|
100
|
+
jobs, dibs's services and hook, a full disk. dibs alerts dismiss <id|all> closes one for a day
|
|
101
|
+
dibs history [--since 7d] [--json] what happened: busy time, waits and who waited, by resource, agent and hour
|
|
102
|
+
dibs stats [--json] waits against run times, today and the last 7 days: median and 90% by resource
|
|
103
|
+
dibs stats --me | --agent <name> [--since 30d] [--json]
|
|
104
|
+
per agent and resource: run and wait time, failures by exit code, what held
|
|
105
|
+
jobs back, top commands, ETAs met, the machine's load and memory over time
|
|
106
|
+
|
|
107
|
+
${LATER_HELP}
|
|
108
|
+
|
|
109
|
+
work with other agents
|
|
110
|
+
dibs yield <agent> [<res>] let another agent go first (and release your hold on what they need)
|
|
111
|
+
dibs ask "..." send a request or bug report to whoever maintains dibs
|
|
112
|
+
|
|
113
|
+
ask the person (one-way doors only)
|
|
114
|
+
dibs question "..." --recommend <option> -m why [--options a,b] [--one-way "what can't be undone"] [--wait]
|
|
115
|
+
without --one-way: decided at once with your recommendation (printed on
|
|
116
|
+
stdout, logged, shown to the person as done). With it: queued for the person;
|
|
117
|
+
--wait prints only the answer; --timeout 1m caps the wait (exit 75: no answer
|
|
118
|
+
by then, or dismissed; a question asked first without --wait stays open for the person)
|
|
119
|
+
dibs questions [--json] open questions first, by priority then age
|
|
120
|
+
dibs answer <id> <text> answer one with an option or any words (words reach the asker as a message too)
|
|
121
|
+
dibs questions dismiss <id> dismiss one; its waiting agent gets exit 75
|
|
122
|
+
dibs hours [09:00-23:00|off] [--json] the person's hours: outside them, questions below urgent wait for morning
|
|
123
|
+
dibs say "..." [--as label] [--to person] an FYI to the person in your thread: progress, done, blocked on X.
|
|
124
|
+
--to person: a reply to what they said (the desk's answers); --to <agent>: a message to that agent,
|
|
125
|
+
the same as dibs tell
|
|
126
|
+
|
|
127
|
+
progress (post as often as you commit)
|
|
128
|
+
dibs progress "..." [--task <name>] [--eta 30m|17:30] [--done|--blocked]
|
|
129
|
+
what you just did, found or decided, in a sentence or a paragraph. The person
|
|
130
|
+
reads every post live; other agents read them too. Post at each step, not at the end
|
|
131
|
+
dibs progress [--agent <name>] [-n 50] [--json] recent posts
|
|
132
|
+
dibs progress list [--all] [--json] your session's open tasks (--all: every session's), owner, state, ETA, last post
|
|
133
|
+
|
|
134
|
+
the person's page and MCP server
|
|
135
|
+
dibs web [--port 7421] [--bind <address>] every agent's jobs, tasks and posts at http://127.0.0.1:7421, and the same as
|
|
136
|
+
MCP tools at /mcp (read-only unless signed in with --allow-actions). dibs service install web keeps it up
|
|
137
|
+
dibs connect connect a browser, a phone, your dibs account, another Claude's MCP or another
|
|
138
|
+
machine: it explains each, and on a terminal asks which
|
|
139
|
+
dibs connect --list | --remove <id> everything connected to this Mac; disconnect one
|
|
140
|
+
dibs connect --approve <code> let a new browser of your dibs account in: the 6 digits it shows
|
|
141
|
+
dibs connect --accounts [--json] the dibs accounts this Mac is on, and the browsers waiting for its approval
|
|
142
|
+
dibs connect --refuse <id> turn down a waiting browser (its id from dibs connect --accounts)
|
|
143
|
+
dibs pair a one-time code to sign the page or an MCP client in (10 minutes, one use)
|
|
144
|
+
dibs pair --allow-actions a code that also lets an MCP client act: post progress, answer, message agents, hold,
|
|
145
|
+
boost, pause, resume and stop jobs, as an agent named after it (mcp-<name>)
|
|
146
|
+
dibs pair --allow-commands all that, and queue_run: commands to run on this Mac, as dibs later. Only on this
|
|
147
|
+
Mac's own MCP (127.0.0.1:7421/mcp), never through mcp.dibs.cc
|
|
148
|
+
dibs pair --list | --revoke <id|all> what's signed in (MCP clients: can act or look only; on the coordinator, its machines)
|
|
149
|
+
dibs pair --machine [--name x] on the coordinator: a one-time code another machine joins with (10 minutes, one use);
|
|
150
|
+
dibs pair --revoke <machine> removes one that joined
|
|
151
|
+
dibs pair --remote [--allow-actions] a one-time link and QR code to pair a phone or any browser with https://app.dibs.cc,
|
|
152
|
+
end-to-end encrypted through the relay (dibs service install relay keeps it connected).
|
|
153
|
+
It can only look unless --allow-actions; the hook and hours never change remotely
|
|
154
|
+
dibs relay [--url wss://app.dibs.cc] the relay connection itself, in the foreground
|
|
155
|
+
dibs relay mcp on|off let MCP clients (another Claude account's connectors) reach this Mac's read-only MCP at
|
|
156
|
+
https://mcp.dibs.cc/mcp through the relay, signing in with a dibs pair code. Off by default
|
|
157
|
+
|
|
158
|
+
talk with your agents
|
|
159
|
+
dibs threads [--json] one thread per agent: its notes, questions, and your messages
|
|
160
|
+
dibs threads read <agent> the conversation; marks its notes read
|
|
161
|
+
dibs tell <agent> "..." a message for that agent: it gets it with its next tool call, or as it
|
|
162
|
+
finishes its turn (needs dibs guard install). From an agent, it says which agent sent it
|
|
163
|
+
dibs tell desk "..." to the agent config.json names as "desk": it answers with dibs say --to person
|
|
164
|
+
dibs listen [--for 60m] [--json] waits until a message, an answer or a notice is queued for you, prints all of it
|
|
165
|
+
and exits 0 (exit 3: none in time). Start it with run_in_background at the start of
|
|
166
|
+
a session and again each time it exits: its exit wakes you even while idle
|
|
167
|
+
|
|
168
|
+
several machines
|
|
169
|
+
dibs run <res> --anywhere -- <cmd> run it on whichever machine would start it soonest (maybe this one)
|
|
170
|
+
dibs run <res> --on <machine> -- <cmd> run it on that machine
|
|
171
|
+
dibs machines every machine, its load and line, and the jobs moving between them
|
|
172
|
+
dibs serve be the coordinator (one machine does this); then dibs pair --machine or dibs invite <machine>
|
|
173
|
+
dibs join <code> [--at <address>] join with a code from dibs pair --machine: finds the coordinator on this network
|
|
174
|
+
or through Tailscale (--at when it's elsewhere), then dibs service install worker
|
|
175
|
+
dibs join <url> <token> [--name x] connect this machine to a coordinator with a line from dibs invite
|
|
176
|
+
dibs worker take jobs here (dibs service install worker keeps it running)
|
|
177
|
+
dibs leave this machine out of its group: it stops taking jobs and forgets the coordinator.
|
|
178
|
+
On the coordinator, only once no other machine is joined (dibs kick each first)
|
|
179
|
+
dibs invite <machine> on the coordinator: a token for that machine, and the join line to run there
|
|
180
|
+
dibs kick <machine> on the coordinator: remove it now; its jobs stop and its token stops working
|
|
181
|
+
dibs limit <machine> --only test,heavy on the coordinator: the only jobs it takes from others (--any lifts it)
|
|
182
|
+
dibs limit <machine> --sends test|none on the coordinator: the only jobs it may send to other machines
|
|
183
|
+
.dibs.json {"stayOn": ["mini"]} at a project's root: the machines its code may go to (besides its own)
|
|
184
|
+
dibs service install|remove|status [serve] [worker] [throttle] [web] [relay] start them at login and keep them up
|
|
185
|
+
join, leave, invite, kick, limit, service, guard install/remove, pace, hours and cap go in the history with who ran them
|
|
186
|
+
|
|
187
|
+
priorities and pauses (ids are the #numbers on dibs --detail; anyone, person or agent, on any job; the board names who.
|
|
188
|
+
An agent acting on a job that isn't its own adds --owner <session>, or session/agent, as the board names it)
|
|
189
|
+
dibs boost <id|agent> <prio> [-m why] change a waiter's or running job's priority: re-ranks it, and moves a run
|
|
190
|
+
onto or off the efficiency cores (an agent name changes all its work).
|
|
191
|
+
An agent raising a job to high or urgent passes -m, which everyone sees
|
|
192
|
+
dibs pause <id> [--force] [-m why] freeze a running job where it stands; it keeps its lease (sim, xcode-build
|
|
193
|
+
and deploy need --force: frozen midway they can fail)
|
|
194
|
+
dibs resume <id> [-m why] continue a paused job
|
|
195
|
+
dibs stop <id> [-m why] end a job and kill its processes, as a crash would; its agent is told
|
|
196
|
+
dibs cap <agent> <prio|off> that agent's work never waits or runs above prio until off
|
|
197
|
+
|
|
198
|
+
other
|
|
199
|
+
dibs port print a free port
|
|
200
|
+
dibs sims [prune] the simulators behind sim-own; prune deletes the idle ones
|
|
201
|
+
dibs pace [quiet|normal|max|off] how hard dibs drives this machine: quiet keeps the fan calm, max finishes fast
|
|
202
|
+
dibs throttle [--watch] move CPU hogs running outside dibs to background priority when the machine is hot
|
|
203
|
+
dibs setup scratch [--size 40G] print the one-time commands for a capped volume for build output (--check: how full)
|
|
204
|
+
dibs changes what changed in recent versions
|
|
205
|
+
dibs guard install|remove|status|check a Claude Code hook that runs heavy commands through dibs when an agent forgets
|
|
206
|
+
dibs init [--repo] [--remove] write dibs.md (the agent instructions) and a note pointing at it in ~/.claude/CLAUDE.md,
|
|
207
|
+
~/.codex/AGENTS.md and this repo's CLAUDE.md and AGENTS.md (install does it; --repo makes
|
|
208
|
+
this repo's CLAUDE.md; --remove takes it all out; DIBS_NO_AGENT_NOTES=1 skips it)
|
|
209
|
+
|
|
210
|
+
flags
|
|
211
|
+
-m "why" shown to everyone (required with urgent and high)
|
|
212
|
+
-p <level> priority, how far it moves you in the queue:
|
|
213
|
+
urgent (1) 2 hr ahead something is broken or a person is waiting now
|
|
214
|
+
high (2) 1 hr ahead on the critical path
|
|
215
|
+
normal (3) arrival order
|
|
216
|
+
low (4) 10 min back nobody is waiting on it; runs at background priority
|
|
217
|
+
idle (5) 60 min back only when nobody else waits; runs at background priority
|
|
218
|
+
low and idle runs may be paused (not killed) for urgent or high work, or under memory pressure
|
|
219
|
+
--by 23:30|20m deadline: as it nears you move up the queue (up to an hour), and you're warned if it's at risk
|
|
220
|
+
--est 5m how long the job takes, when dibs has no history for it. Short jobs move up a little
|
|
221
|
+
--quick it takes under 15 s (quickUnder): it starts at once, past the line and full slots, at most 2 at a time.
|
|
222
|
+
On the simulator, or a deploy of the same repo, it goes to the front of the line instead. Trusted the
|
|
223
|
+
first time; a run that goes over loses the pass until it runs under again. A command dibs has seen run
|
|
224
|
+
under 15 s gets it without the flag
|
|
225
|
+
--cost 3 tokens a quota:<name> job takes from its bucket (default 1)
|
|
226
|
+
--mem 4G memory the job needs (default from the resource). dibs measures what it really uses
|
|
227
|
+
and plans the next run at that when it's more
|
|
228
|
+
--cpu 2 cores the job keeps busy (default from the resource)
|
|
229
|
+
--disk 10G free disk the job needs
|
|
230
|
+
--port NAME put a free port in env NAME for the command (repeatable)
|
|
231
|
+
--wait wait in the queue as long as it takes. The default inside Claude Code, which moves a
|
|
232
|
+
tool call that reaches its timeout to the background instead of killing it
|
|
233
|
+
--max-wait 8m stop waiting after this with exit 75. The default (8m) everywhere else
|
|
234
|
+
--no-wait don't wait at all
|
|
235
|
+
--notify <file> when dibs exits, append one JSON line to file: {"code", "started", "res", "cmd", ...}
|
|
236
|
+
--as label a label shown next to your agent name (for subagents)
|
|
237
|
+
--json machine-readable output (board, when, mine, requests, machines, history, questions, threads, hours, pace, guard status)
|
|
238
|
+
--anywhere send it to the least busy machine (see "several machines")
|
|
239
|
+
--shards N split a playwright test, vitest or node --test run into N pieces across machines, output and exit codes merged.
|
|
240
|
+
vitest and node --test suites that usually take over 5 minutes split in two on their own; --no-shard keeps one
|
|
241
|
+
--on <machine> send it to that machine
|
|
242
|
+
--bring <path> with --anywhere/--on: copy this file or folder back when the job ends (repeatable)
|
|
243
|
+
|
|
244
|
+
Your place in the queue is your arrival time, moved by priority, a near deadline, a short known run time
|
|
245
|
+
(up to 5 min), heavy use of the same resource in the last hour (up to 10 min back), and already holding a
|
|
246
|
+
lease (like high). dibs why says which moved you; dibs why --detail shows the math.
|
|
247
|
+
|
|
248
|
+
Agents are listed by session name, the same name SendMessage uses.
|
|
249
|
+
Resources: sim, sim-own, xcode-build, playwright, test, deploy, heavy, or any name you make up (use the same one as others).
|
|
250
|
+
quota:<name> is a rate limit shared by every script here (config.json "quotas": {"asc": {"per": "1h", "limit": 300}}):
|
|
251
|
+
a job waits until its bucket has --cost tokens, so scripts calling one API wait instead of getting 429s.
|
|
252
|
+
Subagents: with dibs guard installed, at most agents.slots (default 8) run at once across every Claude Code
|
|
253
|
+
session here. A spawn past that is denied, unless the session has none running; wait for one of yours to finish.
|
|
254
|
+
A profile is a name for a resource with its ports and sizes, set once in config.json "profiles":
|
|
255
|
+
{"playwright:web": {"res": "playwright", "ports": ["WEB", "API"], "mem": "3G", "cpu": 2}}, then dibs run playwright:web -- <command>.
|
|
256
|
+
files:<path or glob> is a file lease: while you hold it, dibs guard turns away other sessions' edits and writes there.
|
|
257
|
+
sim is the one shared booted simulator. sim-own boots a private one for your command: its udid is in $SIM, its name in $SIM_NAME.
|
|
258
|
+
Exit codes: the command's own, or 75 gave up waiting (NOT a failure: your command never started; run the
|
|
259
|
+
same command again within 2 minutes to keep your place), 74 not enough disk,
|
|
260
|
+
76 lost the coordinator or the other machine before the job started (safe to send again),
|
|
261
|
+
77 lost it after the job started on another machine (it may have run: check before running it again),
|
|
262
|
+
127 command didn't start, 2 bad usage (also: you already have this exact command waiting or running),
|
|
263
|
+
1 nothing matched (mine, release), 3 dibs listen heard nothing in time, 70 dibs itself crashed (a bug in dibs; report it: dibs ask "...").
|
|
264
|
+
A job sent to another machine takes the git working copy (tracked files plus new ones git doesn't ignore;
|
|
265
|
+
outside git, the folder minus build output). .env files, keys and certificates never leave this machine.
|
|
266
|
+
Config: ${paths.config}`;
|
|
267
|
+
|
|
268
|
+
function parse(argv) {
|
|
269
|
+
const o = { res: [], cmd: null, ports: [], bring: [] };
|
|
270
|
+
const dd = argv.indexOf('--');
|
|
271
|
+
if (dd >= 0) { o.cmd = argv.slice(dd + 1); argv = argv.slice(0, dd); }
|
|
272
|
+
for (let i = 0; i < argv.length; i++) {
|
|
273
|
+
const a = argv[i], next = () => argv[++i] ?? die(`${a} needs a value`);
|
|
274
|
+
if (a === '-m' || a === '--msg') o.purpose = next();
|
|
275
|
+
else if (a === '-p' || a === '--priority') { o.prio = priority(next()); if (!(o.prio in PRIORITY_SHIFT)) die(`priority is one of ${PRIORITIES.join(', ')} (or 1-5)`); }
|
|
276
|
+
else if (a === '--by') o.by = deadline(next());
|
|
277
|
+
else if (a === '--est') o.est = ms(next());
|
|
278
|
+
else if (a === '--quick') o.quick = true;
|
|
279
|
+
else if (a === '--cost') { o.cost = Number(next()); if (!(o.cost > 0)) die('--cost takes a number of tokens above 0'); }
|
|
280
|
+
else if (a === '--mem') o.mem = bytes(next());
|
|
281
|
+
else if (a === '--cpu') { o.cpu = Number(next()); if (!(o.cpu >= 0)) die('--cpu takes a number of cores'); }
|
|
282
|
+
else if (a === '--disk') o.disk = bytes(next());
|
|
283
|
+
else if (a === '--max-wait') o.maxWait = ms(next());
|
|
284
|
+
else if (a === '--no-wait') o.maxWait = 0;
|
|
285
|
+
else if (a === '--wait') o.maxWait = Infinity;
|
|
286
|
+
else if (a === '--notify') o.notify = next();
|
|
287
|
+
else if (a === '--for') o.for = ms(next());
|
|
288
|
+
else if (a === '--lease') o.lease = Number(next()); // src/thin.sh's, on its turn
|
|
289
|
+
else if (a === '--after') o.after = next();
|
|
290
|
+
else if (a === '--since') o.since = next();
|
|
291
|
+
else if (a === '--as') o.as = next();
|
|
292
|
+
else if (a === '--port') o.ports.push(next());
|
|
293
|
+
else if (a === '--json') o.json = true;
|
|
294
|
+
else if (a === '--detail') o.detail = true;
|
|
295
|
+
else if (a === '--watch') o.watch = true;
|
|
296
|
+
else if (a === '--anywhere') o.anywhere = true;
|
|
297
|
+
else if (a === '--shards') { o.shards = Number(next()); if (!(Number.isInteger(o.shards) && o.shards >= 1 && o.shards <= 8)) die('--shards takes how many pieces to split a suite into, 1 to 8 (1: none)'); }
|
|
298
|
+
else if (a === '--no-shard') o.shards = 1;
|
|
299
|
+
else if (a === '--on') o.on = next();
|
|
300
|
+
else if (a === '--bring') o.bring.push(next());
|
|
301
|
+
else if (a === '--name') o.name = next();
|
|
302
|
+
else if (a === '--at') o.at = next();
|
|
303
|
+
else if (a === '--ephemeral') o.ephemeral = true; // a worker on an on-demand VM (src/ondemand.mjs)
|
|
304
|
+
else if (a === '--listen') { o.listen = Number(next()); if (!(o.listen > 0 && o.listen < 65536)) die('--listen takes a port number'); }
|
|
305
|
+
else if (a === '--bind') o.bind = next();
|
|
306
|
+
else if (a === '--only') { o.only = next().split(',').filter(Boolean); if (!o.only.length) die('--only takes resource names, e.g. --only test,heavy'); }
|
|
307
|
+
else if (a === '--any') o.any = true;
|
|
308
|
+
else if (a === '--sends') { const v = next(); o.sends = v === 'none' ? [] : v.split(',').filter(Boolean); if (v !== 'none' && !o.sends.length) die('--sends takes resource names, e.g. --sends test,heavy, or none'); }
|
|
309
|
+
else if (a === '--force') o.force = true;
|
|
310
|
+
else if (a === '--size') o.size = next();
|
|
311
|
+
else if (a === '--check') o.check = true;
|
|
312
|
+
else if (a.startsWith('-')) die(`unknown flag ${a}. Every flag: dibs help all`);
|
|
313
|
+
else o.res.push(...resList(a).map(r => fileRes(r) ?? die("files: needs a path or glob, e.g. 'files:src/auth/**'")));
|
|
314
|
+
}
|
|
315
|
+
return o;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// The first time each agent session runs a new version, one line pointing at
|
|
319
|
+
// what changed. Only for an agent that ran an older one here: a brand-new
|
|
320
|
+
// install, or a session that never ran dibs before, has nothing to compare.
|
|
321
|
+
// Written to stderr, so it never lands in output a script reads.
|
|
322
|
+
function announce() {
|
|
323
|
+
const id = identity();
|
|
324
|
+
const key = String(id.spid || id.who);
|
|
325
|
+
const before = seenBy(key);
|
|
326
|
+
// Already heard of this one, or of a newer one (a dibs listen told it of an update this older
|
|
327
|
+
// process hasn't been replaced by yet): nothing to say, and never move it back.
|
|
328
|
+
if (before === VERSION || (before && newer(before, VERSION))) return;
|
|
329
|
+
markSeen(key, VERSION);
|
|
330
|
+
if (before) process.stderr.write(`dibs was updated to ${VERSION}: see \`dibs changes\`\n`);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// An npm install has no install script (the package runs none, by design), so the first
|
|
334
|
+
// command after an install or upgrade writes dibs.md and the agents' notes (src/notes.mjs).
|
|
335
|
+
// Only from node_modules: a checkout or install.sh's folder has dibs init and install.sh.
|
|
336
|
+
async function npmNotes() {
|
|
337
|
+
if (!ROOT.split(path.sep).includes('node_modules')) return;
|
|
338
|
+
try {
|
|
339
|
+
const notes = await lazy('notes');
|
|
340
|
+
if (!notes.stale()) return;
|
|
341
|
+
for (const f of notes.write()) process.stderr.write(`dibs: wrote ${f}\n`);
|
|
342
|
+
} catch (e) { process.stderr.write(`dibs: couldn't write dibs.md or the agents' notes (${e.message}). dibs init tries again\n`); }
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// A caller with no hook to hand it notices (outside Claude Code) gets them here.
|
|
346
|
+
function notices() {
|
|
347
|
+
if (process.env.CLAUDE_CODE_SESSION_ID) return;
|
|
348
|
+
const n = noticesFor(identity().who);
|
|
349
|
+
if (n) process.stderr.write(`${n}\n`);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Old names keep working, so nothing that already calls dibs breaks.
|
|
353
|
+
const ALIASES = { done: 'release', renew: 'hold', news: 'changes', cool: 'throttle', ls: 'status', board: 'status' };
|
|
354
|
+
const VERBS = new Set(['run', 'hold', 'release', 'when', 'why', 'mine', 'who', 'yield', 'ask', 'requests', 'port', 'throttle', 'changes', 'status', 'help',
|
|
355
|
+
'machines', 'serve', 'join', 'leave', 'worker', 'service', 'invite', 'kick', 'limit', 'guard', 'sims', 'pace', 'setup', 'history', 'stats',
|
|
356
|
+
'question', 'questions', 'answer', 'hours', 'say', 'tell', 'threads', 'listen', 'boost', 'pause', 'resume', 'stop', 'cap', 'later',
|
|
357
|
+
'progress', 'web', 'pair', 'relay', 'connect', 'alerts', 'init']);
|
|
358
|
+
|
|
359
|
+
// A job sent from another machine ends when the worker that started it does,
|
|
360
|
+
// even if the worker was killed outright and couldn't say so.
|
|
361
|
+
function followParent() {
|
|
362
|
+
const parent = process.ppid;
|
|
363
|
+
setInterval(() => { if (process.ppid !== parent) process.kill(process.pid, 'SIGTERM'); }, 2000).unref();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// A suite split across machines (src/shard.mjs), or null: --shards N, or on its own
|
|
367
|
+
// for a vitest or node --test suite that usually takes over 5 minutes, with an
|
|
368
|
+
// on-demand machine to send the other half to.
|
|
369
|
+
async function shardsFor(o, cfg) {
|
|
370
|
+
if (!o.cmd?.length || o.shards === 1 || o.anywhere || o.on || o.lease || o.after || process.env.DIBS_SHARD) return null;
|
|
371
|
+
const { sharder, runShards, AUTO_OVER, AUTO_SHARDS } = await lazy('shard');
|
|
372
|
+
const split = sharder(o.cmd);
|
|
373
|
+
if (!split) { if (o.shards > 1) die(`--shards splits a playwright test, vitest or node --test run, which this isn't: ${o.cmd.join(' ')}`); return null; }
|
|
374
|
+
const { ondemandOf } = await lazy('ondemand');
|
|
375
|
+
let vm = null;
|
|
376
|
+
try { vm = ondemandOf(cfg).find(m => !m.temp)?.name || null; } catch {}
|
|
377
|
+
let n = o.shards;
|
|
378
|
+
if (!n && vm && split.which !== 'playwright') {
|
|
379
|
+
const { typical } = await import('../src/schedule.mjs');
|
|
380
|
+
const { history } = await import('../src/state.mjs');
|
|
381
|
+
const { commandKey } = await lazy('acquire');
|
|
382
|
+
if (typical(history(), `${o.res.join(',')}|${commandKey(o.cmd)}`) > AUTO_OVER) n = AUTO_SHARDS;
|
|
383
|
+
}
|
|
384
|
+
return n > 1 ? () => runShards(o, n, split, vm) : null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
async function main() {
|
|
388
|
+
let argv = process.argv.slice(2);
|
|
389
|
+
// Not for thin waits' own calls (_enqueue, _broker, _rewait, _leave): the broker follows
|
|
390
|
+
// a remote job's worker for its waiter, and the broker outlives whoever started it.
|
|
391
|
+
if (process.env.DIBS_REMOTE_JOB && !String(argv[0]).startsWith('_')) followParent();
|
|
392
|
+
let verb = argv[0];
|
|
393
|
+
if (verb === '--version' || verb === '-v' || verb === 'version') return console.log(VERSION);
|
|
394
|
+
if (verb === '-h' || verb === '--help') verb = 'help';
|
|
395
|
+
verb = ALIASES[verb] || verb;
|
|
396
|
+
if (verb === 'help') return console.log(argv[1] === 'all' ? HELP_ALL : HELP);
|
|
397
|
+
if (verb === 'changes') return console.log(changelog().slice(0, 3).map(c => `${c.version}\n${c.body}`).join('\n\n'));
|
|
398
|
+
// The hook runs on every Bash call: no config file writes, no what's-new notice.
|
|
399
|
+
if (verb === 'guard') {
|
|
400
|
+
if (argv[1] === 'install' || argv[1] === 'remove') (await import('../src/owner.mjs')).logChange(`guard ${argv[1]}`);
|
|
401
|
+
return (await lazy('guard')).guard(argv.slice(1));
|
|
402
|
+
}
|
|
403
|
+
// src/thin.sh's own calls, not commands anyone types (src/broker.mjs).
|
|
404
|
+
if (verb === '_broker') return (await import('../src/broker.mjs')).broker();
|
|
405
|
+
// The Mac app's reader: its polls, answered by one process that stays up (src/reads.mjs).
|
|
406
|
+
if (verb === '_reads') return (await import('../src/reads.mjs')).reads(readOne);
|
|
407
|
+
if (verb === '_rewait') { if (!(await import('../src/broker.mjs')).ensureBroker()) process.exitCode = 1; return; }
|
|
408
|
+
if (verb === '_leave') return (await import('../src/broker.mjs')).leaveLine(Number(argv[1]), Number(argv[2]), argv[3]);
|
|
409
|
+
let thin = null;
|
|
410
|
+
if (verb === '_enqueue') {
|
|
411
|
+
thin = (await import('../src/broker.mjs')).thinCall(Number(argv[1]), argv[3]);
|
|
412
|
+
// Node's parent is the waiting shell; the caller, for twins and nesting, is the shell's parent.
|
|
413
|
+
setCaller(Number(argv[2]));
|
|
414
|
+
process.argv.splice(2, 4); // the command as typed, for the line that says how to run it again
|
|
415
|
+
argv = process.argv.slice(2);
|
|
416
|
+
verb = argv[0];
|
|
417
|
+
}
|
|
418
|
+
calledVerb = verb;
|
|
419
|
+
const cfg = loadConfig();
|
|
420
|
+
// Services, jobs sent from another machine and scheduled ones have nobody to read the notes.
|
|
421
|
+
// A thin waiter's turn has had them already, when it got in line.
|
|
422
|
+
const lease = argv.slice(0, argv.indexOf('--') >>> 0).includes('--lease');
|
|
423
|
+
if (!process.env.DIBS_REMOTE_JOB && !process.env.DIBS_LATER_JOB && !lease && !['serve', 'worker', 'service', 'relay', 'init'].includes(verb)) { announce(); notices(); }
|
|
424
|
+
if (verb !== 'init') await npmNotes();
|
|
425
|
+
// `dibs sim -- cmd` (no verb) means run; a bare `dibs` or `dibs --json` is the board.
|
|
426
|
+
// `dibs -m why sim -- cmd` is a run too: anything with a command after -- is.
|
|
427
|
+
if (!verb || (verb.startsWith('-') && verb !== '--' && !argv.includes('--'))) return status(parse(argv), cfg);
|
|
428
|
+
if (!VERBS.has(verb) && !argv.includes('--') && !cfg.resources[verb] && !isFiles(verb) && !isQuota(verb)) {
|
|
429
|
+
// `dibs list`, `dibs stauts`: a command that doesn't exist, not a run missing its --.
|
|
430
|
+
const near = nearest(verb, [...VERBS, ...Object.keys(ALIASES)]);
|
|
431
|
+
die(`unknown command ${verb}.${near ? ` Did you mean dibs ${near}?` : ''} Commands: dibs help. To run something: dibs run <resource> -- <command>`);
|
|
432
|
+
}
|
|
433
|
+
const rest = VERBS.has(verb) ? argv.slice(1) : argv;
|
|
434
|
+
if (!VERBS.has(verb)) verb = 'run';
|
|
435
|
+
switch (verb) {
|
|
436
|
+
case 'run': {
|
|
437
|
+
const o = profiled(parse(rest), cfg);
|
|
438
|
+
if (o.bring.length && !o.anywhere && !o.on) die('--bring only means something with --anywhere or --on');
|
|
439
|
+
if ((o.anywhere || o.on) && o.res.some(isFiles)) die("file leases cover this machine's files. Take them here (dibs hold files:...), then send the job without them");
|
|
440
|
+
if (o.after && (o.anywhere || o.on)) die('--after works for a run on this machine; for another, use dibs later --after');
|
|
441
|
+
checkNames(o.res, cfg);
|
|
442
|
+
const shards = await shardsFor(o, cfg);
|
|
443
|
+
// Paths thin waits don't cover: a shell's Node hands back to it to wait in Node; one already
|
|
444
|
+
// the shell's own Node (src/broker.mjs inlineCall) just goes on here.
|
|
445
|
+
if (thin?.inline && (shards || o.anywhere || o.on || o.after)) thin = null;
|
|
446
|
+
if (shards) { if (thin) return thin.fat(); notifyOnExit(o); return shards(); }
|
|
447
|
+
// Waiting thin covers a plain run here: the rest wait in-process.
|
|
448
|
+
// A run sent to another machine waits there (thin, through its worker); --after waits outside the line.
|
|
449
|
+
if (thin && (o.anywhere || o.on || o.after)) return thin.fat();
|
|
450
|
+
o.thin = thin;
|
|
451
|
+
notifyOnExit(o);
|
|
452
|
+
return o.anywhere || o.on ? remoteRun(o, cfg) : run(o, cfg);
|
|
453
|
+
}
|
|
454
|
+
case 'machines': return machines(parse(rest));
|
|
455
|
+
case 'serve': return (await lazy('serve')).serve(parse(rest));
|
|
456
|
+
case 'join': return join(parse(rest));
|
|
457
|
+
case 'worker': return (await lazy('worker')).worker(parse(rest), cfg);
|
|
458
|
+
case 'invite': return (await lazy('admin')).invite(parse(rest));
|
|
459
|
+
case 'kick': return (await lazy('admin')).kick(parse(rest));
|
|
460
|
+
case 'leave': return (await lazy('admin')).leave();
|
|
461
|
+
case 'limit': return (await lazy('admin')).limit(parse(rest));
|
|
462
|
+
case 'service': return (await lazy('service')).service(rest);
|
|
463
|
+
case 'hold': { const o = profiled(parse(rest), cfg); if (o.notify || o.after) die(`${o.notify ? '--notify' : '--after'} works with dibs run`); checkNames(o.res, cfg); o.thin = thin; return hold(o, cfg); }
|
|
464
|
+
case 'release': return release(parse(rest));
|
|
465
|
+
case 'when': { const o = profiled(parse(rest), cfg); checkNames(o.res, cfg); return when(o, cfg); }
|
|
466
|
+
case 'why': return why(parse(rest), cfg);
|
|
467
|
+
case 'mine': return mine(parse(rest), cfg);
|
|
468
|
+
case 'who': return who(parse(rest), cfg);
|
|
469
|
+
case 'yield': return yieldTo(parse(rest));
|
|
470
|
+
case 'ask': return ask(rest, cfg);
|
|
471
|
+
case 'requests': return requests(parse(rest));
|
|
472
|
+
case 'port': return console.log(await freePort());
|
|
473
|
+
case 'throttle': return (await lazy('cool')).throttle(parse(rest), cfg);
|
|
474
|
+
case 'status': return status(parse(rest), cfg);
|
|
475
|
+
case 'sims': { const o = parse(rest); return sims(o, o.res, cfg); }
|
|
476
|
+
case 'pace': return pace(rest);
|
|
477
|
+
case 'setup': { const o = parse(rest); return (await lazy('scratch')).setup(o.res, o); }
|
|
478
|
+
case 'history': return (await lazy('history')).history(parse(rest), cfg);
|
|
479
|
+
case 'stats': return (await lazy('stats')).stats(rest, cfg);
|
|
480
|
+
case 'alerts': return (await lazy('alerts')).alerts(rest, cfg);
|
|
481
|
+
case 'question': return question(rest, cfg);
|
|
482
|
+
case 'questions': return questions(rest, cfg);
|
|
483
|
+
case 'answer': return answer(rest);
|
|
484
|
+
case 'hours': return hoursCmd(rest, cfg);
|
|
485
|
+
case 'say': return say(rest);
|
|
486
|
+
case 'progress': return (await lazy('progress')).post(rest);
|
|
487
|
+
case 'web': return (await lazy('web')).web(rest);
|
|
488
|
+
case 'pair': return (await lazy('web')).pair(rest);
|
|
489
|
+
case 'connect': return (await lazy('connect')).connect(rest);
|
|
490
|
+
case 'init': return (await lazy('notes')).init(rest);
|
|
491
|
+
case 'relay': return (await lazy('relay')).relay(rest);
|
|
492
|
+
case 'tell': return tell(rest);
|
|
493
|
+
case 'threads': return threads(rest);
|
|
494
|
+
case 'listen': return listen(rest);
|
|
495
|
+
case 'boost': return boost(rest, cfg);
|
|
496
|
+
case 'pause': return pause(rest, cfg);
|
|
497
|
+
case 'resume': return resume(rest);
|
|
498
|
+
case 'stop': return stop(rest);
|
|
499
|
+
case 'cap': return cap(rest);
|
|
500
|
+
case 'later': return /^(help|-h|--help)$/.test(rest[0] || '') ? console.log(LATER_HELP) : later(rest, cfg, parse);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// One of the CLI's read-only verbs, exactly as main() runs it, for the Mac app's
|
|
505
|
+
// reader. Anything else is refused: the reader never changes anything.
|
|
506
|
+
const COUNT = /^\d{1,5}$/;
|
|
507
|
+
async function readOne(argv) {
|
|
508
|
+
const cfg = loadConfig();
|
|
509
|
+
const [verb, ...rest] = argv;
|
|
510
|
+
const only = (...want) => rest.length === want.length && want.every((w, i) => (w instanceof RegExp ? w.test(rest[i]) : w === rest[i]));
|
|
511
|
+
if (verb === '--version' && !rest.length) return console.log(VERSION);
|
|
512
|
+
if (verb === '--json' && !rest.length) return status(parse(argv), cfg);
|
|
513
|
+
if (verb === 'questions' && only('--json')) return questions(rest, cfg);
|
|
514
|
+
if (verb === 'threads' && only('--json')) return threads(rest);
|
|
515
|
+
if (verb === 'progress' && (only('--json') || only('--json', '-n', COUNT))) return (await lazy('progress')).post(rest);
|
|
516
|
+
if (verb === 'later' && only('list', '--json')) return later(rest, cfg, parse);
|
|
517
|
+
if (verb === 'history' && only('--json', '--since', /^\d+[mhd]$/)) return (await lazy('history')).history(parse(rest), cfg);
|
|
518
|
+
if (verb === 'stats' && rest[0] === '--json' && (only('--json', '--since', /^\d+[mhd]$/) || only('--json', '--since', /^\d+[mhd]$/, '--agent', /^[^-]/)))
|
|
519
|
+
return (await lazy('stats')).stats(rest, cfg);
|
|
520
|
+
if (verb === 'guard' && only('status', '--json')) return (await lazy('guard')).guard(rest);
|
|
521
|
+
if (verb === 'pace' && only('--json')) return pace(rest);
|
|
522
|
+
if (verb === 'pair' && only('--list')) return (await lazy('web')).pair(rest);
|
|
523
|
+
if (verb === 'connect' && only('--accounts', '--json')) return (await lazy('connect')).connect(rest);
|
|
524
|
+
if (verb === 'service' && rest[0] === 'status' && rest.slice(1).every(k => /^[a-z]+$/.test(k))) return (await lazy('service')).service(rest);
|
|
525
|
+
if (verb === 'sims' && only('--json')) { const o = parse(rest); return sims(o, o.res, cfg); }
|
|
526
|
+
die(`the app's reader answers only the read-only verbs, not dibs ${argv.join(' ')}`, 2);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// A crash gets a code of its own (70, EX_SOFTWARE), never one an agent reads as
|
|
530
|
+
// "nothing matched" (1) or as its command's own failure.
|
|
531
|
+
const CRASHED = 70;
|
|
532
|
+
const crash = e => die(`dibs itself crashed (a bug in dibs, not in your command; exit ${CRASHED}). Report it: dibs ask "..."\n${e?.stack || String(e)}`, CRASHED);
|
|
533
|
+
// A full disk is no bug: say what to do, with the exit code agents know (74), not a stack.
|
|
534
|
+
const fail = e => (noSpace(e) ? die(fullDisk(e), 74) : crash(e));
|
|
535
|
+
process.on('uncaughtException', fail);
|
|
536
|
+
|
|
537
|
+
// A job lost on its way to or on another machine (76, 77) and dibs's own crash
|
|
538
|
+
// (70) go in the event log, so the person hears of them (src/alerts.mjs), not
|
|
539
|
+
// only the agent whose tool call ended.
|
|
540
|
+
let calledVerb = '';
|
|
541
|
+
process.on('exit', code => {
|
|
542
|
+
if (code !== lastDieCode || !(code === CRASHED || ((code === 76 || code === 77) && calledVerb === 'run'))) return;
|
|
543
|
+
try {
|
|
544
|
+
event({ kind: code === CRASHED ? 'crash' : 'lost', code, verb: calledVerb, who: identity().who,
|
|
545
|
+
cmd: process.argv.slice(2).join(' ').slice(0, 160), why: lastDie.split('\n')[0].slice(0, 300) });
|
|
546
|
+
} catch {}
|
|
547
|
+
});
|
|
548
|
+
main().catch(fail);
|