crewbus 10.0.10 → 10.0.11
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 +28 -0
- package/bin/crewbus-hook.js +57 -2
- package/bin/crewbus-mcp.js +25 -3
- package/bin/crewbus.js +321 -57
- package/bin/lib/channels.js +11 -1
- package/bin/lib/identity.js +145 -1
- package/bin/lib/kidproc.js +92 -0
- package/bin/lib/launch.js +9 -4
- package/bin/lib/relay.js +4 -2
- package/bin/lib/spawn.js +54 -16
- package/bin/lib/store.js +2 -1
- package/bin/lib/web.js +6 -3
- package/docs/GROUPS.md +4 -2
- package/docs/IDENTITY.md +36 -0
- package/docs/LEAD_ASSIGN.md +10 -0
- package/docs/LONG_RUNS.md +3 -2
- package/docs/RBAC.md +73 -69
- package/docs/TROUBLESHOOTING.md +1 -0
- package/opencode/plugins/dm-watch.js +70 -8
- package/package.json +2 -2
package/docs/RBAC.md
CHANGED
|
@@ -1,69 +1,73 @@
|
|
|
1
|
-
# RBAC + per-board ACLs + group-scoped send permissions (Phase 1b)
|
|
2
|
-
|
|
3
|
-
Zero-dependency, file-local. Composes with Phase 1a tokens: `checkToken()`
|
|
4
|
-
proves WHO you are; `authorize()` decides WHAT your role may do. `authorize()`
|
|
5
|
-
is a SEPARATE function called AFTER `checkToken()` passes — never before,
|
|
6
|
-
never instead, never merged into token code.
|
|
7
|
-
|
|
8
|
-
## Roles
|
|
9
|
-
|
|
10
|
-
Agent records carry `role` in `{admin, lead, worker, auditor}`.
|
|
11
|
-
|
|
12
|
-
- First-registered agent on a board becomes **admin**; everyone else gets
|
|
13
|
-
`acl.defaultRole` (default `"worker"`).
|
|
14
|
-
- `register --role <r>` is only honored when the caller is **admin**,
|
|
15
|
-
otherwise ignored with a warning on stderr (no self-promotion).
|
|
16
|
-
- Grant/change: `register --from <admin> --for <target> [--role <r>]`
|
|
17
|
-
(admin-only, bypasses frozen boards; also re-onboards offboarded names).
|
|
18
|
-
- `agents --json` exposes roles (secrets stripped, role kept).
|
|
19
|
-
|
|
20
|
-
## Permission matrix (minimal)
|
|
21
|
-
|
|
22
|
-
| action | admin | lead | worker | auditor |
|
|
23
|
-
|---|---|---|---|---|
|
|
24
|
-
| send / inbox / ack / redeliver / lock (scoped) | yes | yes | yes | read-only: inbox yes; send/ack/lock NO |
|
|
25
|
-
| spawn / pool / spawn-kill (own crew) / group manage /
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
# RBAC + per-board ACLs + group-scoped send permissions (Phase 1b)
|
|
2
|
+
|
|
3
|
+
Zero-dependency, file-local. Composes with Phase 1a tokens: `checkToken()`
|
|
4
|
+
proves WHO you are; `authorize()` decides WHAT your role may do. `authorize()`
|
|
5
|
+
is a SEPARATE function called AFTER `checkToken()` passes — never before,
|
|
6
|
+
never instead, never merged into token code.
|
|
7
|
+
|
|
8
|
+
## Roles
|
|
9
|
+
|
|
10
|
+
Agent records carry `role` in `{admin, lead, worker, auditor}`.
|
|
11
|
+
|
|
12
|
+
- First-registered agent on a board becomes **admin**; everyone else gets
|
|
13
|
+
`acl.defaultRole` (default `"worker"`).
|
|
14
|
+
- `register --role <r>` is only honored when the caller is **admin**,
|
|
15
|
+
otherwise ignored with a warning on stderr (no self-promotion).
|
|
16
|
+
- Grant/change: `register --from <admin> --for <target> [--role <r>]`
|
|
17
|
+
(admin-only, bypasses frozen boards; also re-onboards offboarded names).
|
|
18
|
+
- `agents --json` exposes roles (secrets stripped, role kept).
|
|
19
|
+
|
|
20
|
+
## Permission matrix (minimal)
|
|
21
|
+
|
|
22
|
+
| action | admin | lead | worker | auditor |
|
|
23
|
+
|---|---|---|---|---|
|
|
24
|
+
| send / inbox / ack / redeliver / lock (scoped) | yes | yes | yes | read-only: inbox yes; send/ack/lock NO |
|
|
25
|
+
| spawn / pool / spawn-kill (own crew) / group manage / result record / race close | yes | yes | NO | NO |
|
|
26
|
+
| channel post | yes (anywhere) | yes (anywhere) | members-only: the channel's own group only (`grp-<group>` where the caller is a member) | NO |
|
|
27
|
+
| launch (same RBAC + audit as spawn: `cmdLaunch` delegates to `cmdSpawn`; `handleApiLaunch` checks `spawn`) | yes | yes | NO | NO |
|
|
28
|
+
| relay pair issue / devices / revoke (`pairing`: CLI gate + `POST /api/pair/*`, `GET /api/pair/devices`) | yes | NO | NO | NO |
|
|
29
|
+
| prune / acl set / role-grant / offboard / group restrict / serve `--allow-remote-spawn` | yes | NO | NO | NO |
|
|
30
|
+
| reads (gather / thread / log / channel tail / group show / result show / spawn-status / agents) | yes | yes | yes | yes |
|
|
31
|
+
|
|
32
|
+
Notes:
|
|
33
|
+
|
|
34
|
+
- Reads not listed above default-allow (fail-closed only for writes).
|
|
35
|
+
- `spawn-kill` for leads is own-crew only: every target's `spawnedBy` must
|
|
36
|
+
equal the caller (or the target was never spawned). Admins may kill any.
|
|
37
|
+
- `lock release` still requires ownership even when acquire is allowed.
|
|
38
|
+
- MCP twins: `dm_send`→send, `dm_inbox`→inbox, `dm_ack`→ack,
|
|
39
|
+
`dm_channel_post`→channel-post (member-scoped like the CLI: lead|admin post anywhere, members post only to their own group's channel). `dm_gather` /
|
|
40
|
+
`dm_channel_tail` are identity-less reads (like CLI `gather`), default-allow.
|
|
41
|
+
- Member-scoped channel posting (C4) is default-on with no flag (briefs sent
|
|
42
|
+
with `--also-channel` to a group the sender is not a member of still
|
|
43
|
+
deliver as DMs; only the channel mirror is skipped, with a visible note).
|
|
44
|
+
- Relay: `POST /api/spawn`→spawn, `POST /api/launch`→spawn, `POST /api/kill`→spawn-kill (403 on denial); pair endpoints→`pairing` (admin): `POST /api/pair/issue|exchange|revoke`, `GET /api/pair/devices`.
|
|
45
|
+
- Device-scope layer: transport credential scopes (`requireScope` in `bin/lib/relay.js`) compose UNDER role checks — a narrowed device can only further restrict, never widen, what the agent token's role allows.
|
|
46
|
+
- `prune` and `group create/add/remove` keep the bare operator path (no
|
|
47
|
+
`--from`) open for back-compat; with `--from` the caller is token-checked
|
|
48
|
+
and authorized. `serve --allow-remote-spawn` with `--from` requires admin.
|
|
49
|
+
|
|
50
|
+
## Per-board ACLs
|
|
51
|
+
|
|
52
|
+
`board.json` gains `acl: {defaultRole, frozen?}`.
|
|
53
|
+
|
|
54
|
+
- `acl set --from <admin> [--default-role worker] [--freeze|--unfreeze]`
|
|
55
|
+
(admin-only). `acl show [--json]` is read-only.
|
|
56
|
+
- Frozen boards refuse new registrations (including first-send auto-mint),
|
|
57
|
+
except by admin grant (`register --from <admin> --for <new>`).
|
|
58
|
+
|
|
59
|
+
## Group-scoped send permissions
|
|
60
|
+
|
|
61
|
+
- `group restrict <name> --from <admin>` sets `restricted: true`
|
|
62
|
+
(`group unrestrict` clears it). Admin-only. The flag survives member edits.
|
|
63
|
+
- Sends with `--to-group` (or `to_group` / relay `to_group`) to a restricted
|
|
64
|
+
group are refused unless the caller is admin/lead or a group member.
|
|
65
|
+
- Pattern: curate a private crew (`group create elite --add a,b`),
|
|
66
|
+
then `group restrict elite --from <admin>`; outsiders get a loud refusal,
|
|
67
|
+
members + leads keep working.
|
|
68
|
+
|
|
69
|
+
## Back-compat
|
|
70
|
+
|
|
71
|
+
Boards/agents without roles behave as today: legacy records without `role`
|
|
72
|
+
map to **lead**, so existing crews keep working (and keep spawn/group/channel
|
|
73
|
+
powers). Token-less legacy records keep the existing migrate-on-auth behavior.
|
package/docs/TROUBLESHOOTING.md
CHANGED
|
@@ -10,6 +10,7 @@ Start with `crewbus doctor` — it prints the resolved board,
|
|
|
10
10
|
| `drive root` refusal (`/.crewbus`, `C:\.crewbus`) | cwd resolution failed (detached harness worktree) | Pass an explicit `--board` path or set `CREWBUS_DIR`; see one Windows note below |
|
|
11
11
|
| Group has one member like `cam-1-cam-2-cam-3` | PowerShell array-splatted an unquoted `--add a,b,c` (npm shim rejoins with spaces) | Quote comma lists on PowerShell: `--add "cam-1,cam-2,cam-3"` (same for `--to`, `--to-group`). List flags also accept whitespace separation, so a space-joined list still parses as several names |
|
|
12
12
|
| `wrong token` / auth failure | Token missing or from a different name | Tokens print once and never re-print — reuse the `register` output saved at claim time (or `token rotate --from <name>` with the current token); export `CREWBUS_TOKEN`; names are lowercase (`Alice` == `alice`) |
|
|
13
|
+
| After compaction you "do not know" your identity (the `unknown` trap) | The harness summarized your session; register binding survives on the board doc | Run `crewbus recover [--session <id>]` — read-only candidate ranking (register binding, token-file↔hash cross-check, cwd); never re-register as `unknown`/`me`/`you` (those names refuse to mint), and never mint a throwaway name to "get moving" |
|
|
13
14
|
| Push never arrives (non-opencode harness) | Hooks not trusted / harness not restarted after `init` | Re-run `crewbus init --harness <name>` (merges, never overwrites), approve MCP/trust prompts (`/hooks`, `/hooks-trust`), restart harness |
|
|
14
15
|
| `doctor` FAIL on hooks/MCP entries | Wiring edited or installed for another harness | Re-run `init --harness <name>`, then follow the printed follow-ups |
|
|
15
16
|
| Duplicate or replayed DMs | Two push paths racing, or pruned markers | Markers in `delivered/` + `cursors/` dedupe across restarts; `redeliver --from <name> --all` after re-registering a dead watcher; `prune` keeps surviving markers so cursors never replay |
|
|
@@ -431,23 +431,85 @@ export const DmWatchPlugin = async ({ client, directory }) => {
|
|
|
431
431
|
}, POLL_MS);
|
|
432
432
|
poll().catch(() => {});
|
|
433
433
|
|
|
434
|
+
// C1 lite recovery (self-contained: no bin/lib imports — the plugin ships
|
|
435
|
+
// standalone). Same scoring spirit as `crewbus recover`, minus the
|
|
436
|
+
// token-hash cross-check: session binding +4, token file +1, cwd match +1.
|
|
437
|
+
// Returns [{ name, role, score, proven, why }] best-first.
|
|
438
|
+
function recoverCandidatesLite(sessionID) {
|
|
439
|
+
const cands = [];
|
|
440
|
+
try {
|
|
441
|
+
const agentsDir = path.join(root, "agents");
|
|
442
|
+
const logsDir = path.join(root, "logs");
|
|
443
|
+
const tokenNames = new Set();
|
|
444
|
+
try {
|
|
445
|
+
for (const f of fs.readdirSync(logsDir)) if (f.endsWith(".token")) tokenNames.add(f.slice(0, -6).toLowerCase());
|
|
446
|
+
} catch {}
|
|
447
|
+
const cwd = String(process.cwd() || "").replace(/\\/g, "/").toLowerCase();
|
|
448
|
+
for (const f of fs.readdirSync(agentsDir)) {
|
|
449
|
+
if (!f.endsWith(".json")) continue;
|
|
450
|
+
const doc = readJsonSafe(path.join(agentsDir, f));
|
|
451
|
+
if (!doc || !doc.name || doc.offboarded) continue;
|
|
452
|
+
let score = 0;
|
|
453
|
+
const why = [];
|
|
454
|
+
if (sessionID && doc.sessionId && String(doc.sessionId) === String(sessionID)) {
|
|
455
|
+
score += 4;
|
|
456
|
+
why.push("session id matches register binding");
|
|
457
|
+
}
|
|
458
|
+
if (tokenNames.has(String(doc.name).toLowerCase())) {
|
|
459
|
+
score += 1;
|
|
460
|
+
why.push("token file exists for this name");
|
|
461
|
+
}
|
|
462
|
+
if (doc.lastDir && cwd && String(doc.lastDir).replace(/\\/g, "/").toLowerCase() === cwd) {
|
|
463
|
+
score += 1;
|
|
464
|
+
why.push("worked from this directory");
|
|
465
|
+
}
|
|
466
|
+
if (score <= 0) continue;
|
|
467
|
+
cands.push({ name: doc.name, role: doc.role || "peer", score, proven: false, why: why.join("; ") });
|
|
468
|
+
}
|
|
469
|
+
} catch {}
|
|
470
|
+
cands.sort((a, b) => b.score - a.score || String(a.name).localeCompare(String(b.name)));
|
|
471
|
+
return cands;
|
|
472
|
+
}
|
|
473
|
+
|
|
434
474
|
return {
|
|
435
475
|
// Compaction rehydration: opencode summarizes this session, so the agent
|
|
436
476
|
// wakes up forgetting its name, board, and token. Push the same identity
|
|
437
|
-
// card `crewbus-hook compact` prints into the summary prompt.
|
|
477
|
+
// card `crewbus-hook compact` prints into the summary prompt. When the
|
|
478
|
+
// session↔agent map misses, try board-side recovery BEFORE calling the
|
|
479
|
+
// agent "unknown" (post-compaction rehydration: C1):
|
|
480
|
+
// 1. register --session <id> binding stored on the agent doc
|
|
481
|
+
// 2. CREWBUS_AGENT env (set when the session boots via launch)
|
|
482
|
+
// 3. token-file + cwd evidence (agents roster ∩ logs/*.token)
|
|
483
|
+
// A resolved candidate drives the card; an unresolved one prints the
|
|
484
|
+
// crewbus recover path instead — never suggest re-registering a thrown
|
|
485
|
+
// "unknown" (those sentinel names refuse to mint, and for good reason).
|
|
438
486
|
"experimental.session.compacting": async (input, output) => {
|
|
439
487
|
try {
|
|
440
488
|
if (!output || !Array.isArray(output.context)) return;
|
|
441
489
|
refreshAgentMap();
|
|
442
490
|
let agent = null;
|
|
443
491
|
for (const [name, sid] of agentToSession) if (sid === (input && input.sessionID)) agent = name;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
492
|
+
let proven = false;
|
|
493
|
+
if (!agent) agent = (process.env.CREWBUS_AGENT || "").trim() || null;
|
|
494
|
+
if (!agent) {
|
|
495
|
+
const cands = recoverCandidatesLite(input && input.sessionID);
|
|
496
|
+
if (cands[0] && cands[0].score >= 2) {
|
|
497
|
+
agent = cands[0].name;
|
|
498
|
+
proven = cands[0].proven || cands[0].score >= 3;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (agent) {
|
|
502
|
+
output.context.push(`crewbus: context refreshed after compaction. You are '${agent}' on board ${root}${proven ? " (identity cross-checked)" : ""}.`);
|
|
503
|
+
output.context.push(`Token: read ${path.join(root, "logs", agent + ".token")} into CREWBUS_TOKEN (0600 file written at register/mint). Lost it? Ask your lead/admin to revoke it, then re-register for a fresh one.`);
|
|
504
|
+
output.context.push(`Then: crewbus inbox --from ${agent} --unacked --digest (escalate to full reads on hits).`);
|
|
505
|
+
const doc = readJsonSafe(path.join(root, "agents", agent + ".json"));
|
|
506
|
+
const ws = doc && doc.briefId ? readJsonSafe(path.join(root, "worker-sessions", agent + ".json")) : null;
|
|
507
|
+
if (ws && (ws.promptPath || ws.origPromptPath)) output.context.push(`Your brief: re-read ${ws.promptPath || ws.origPromptPath} from worker-sessions if present.`);
|
|
508
|
+
} else {
|
|
509
|
+
output.context.push(`crewbus: context refreshed after compaction, but THIS session's agent could not be identified on board ${root}.`);
|
|
510
|
+
output.context.push(`Recover (read-only, never mints): crewbus recover${input && input.sessionID ? ` --session ${input.sessionID}` : ""} — it ranks candidate identities from the board (register session binding, token files, cwd history) and prints exact resume commands.`);
|
|
511
|
+
output.context.push(`NEVER re-register as 'unknown'/'me'/'you' — those sentinel names are reserved and refuse to mint; recover your real identity instead.`);
|
|
512
|
+
}
|
|
451
513
|
} catch {}
|
|
452
514
|
},
|
|
453
515
|
dispose: async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crewbus",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.11",
|
|
4
4
|
"description": "Zero-dependency message bus for AI coding-agent crews: message another agent, inserted into context, just a tool call.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"crewbus-hook": "bin/crewbus-hook.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "node test/crewbus.smoke.mjs && node test/crewbus.harness.mjs && node test/crewbus.lead-assign.mjs && node test/crewbus.opencode-respawn.mjs && node test/crewbus.compact.mjs && node test/crewbus.tokenfile.mjs && node test/crewbus.digest.mjs && node test/crewbus.workbench.mjs && node test/crewbus.control-plane.mjs && node test/crewbus.launch.mjs && node test/crewbus.web-launch.mjs && node test/crewbus.pair-api.mjs && node test/crewbus.web-panel.mjs && node test/crewbus.web-approot.mjs && node test/crewbus.client-runtime.mjs && node test/crewbus.runtime-wiring.mjs && node test/crewbus.desktop-sidecar.mjs && node test/crewbus.mobile-client.mjs && node test/crewbus.grok-hooks.mjs && node test/crewbus.holds-quotas.mjs && node test/crewbus.approval-protocol.mjs && node test/crewbus.approvals-init.mjs && node test/crewbus.approvals-web.mjs && node test/fault-injection.mjs && node test/integration.mjs",
|
|
12
|
+
"test": "node test/crewbus.smoke.mjs && node test/crewbus.kidproc.mjs && node test/crewbus.recover.mjs && node test/crewbus.harness.mjs && node test/crewbus.lead-assign.mjs && node test/crewbus.lead-budget.mjs && node test/crewbus.channel-member.mjs && node test/crewbus.inbox-archive.mjs && node test/crewbus.opencode-respawn.mjs && node test/crewbus.compact.mjs && node test/crewbus.tokenfile.mjs && node test/crewbus.digest.mjs && node test/crewbus.workbench.mjs && node test/crewbus.control-plane.mjs && node test/crewbus.launch.mjs && node test/crewbus.web-launch.mjs && node test/crewbus.pair-api.mjs && node test/crewbus.web-panel.mjs && node test/crewbus.web-approot.mjs && node test/crewbus.client-runtime.mjs && node test/crewbus.runtime-wiring.mjs && node test/crewbus.desktop-sidecar.mjs && node test/crewbus.mobile-client.mjs && node test/crewbus.grok-hooks.mjs && node test/crewbus.holds-quotas.mjs && node test/crewbus.approval-protocol.mjs && node test/crewbus.approvals-init.mjs && node test/crewbus.approvals-web.mjs && node test/fault-injection.mjs && node test/integration.mjs",
|
|
13
13
|
"bench": "node test/bench.mjs",
|
|
14
14
|
"bench:load": "node test/load.mjs",
|
|
15
15
|
"vendor": "node scripts/vendor-runtime.mjs"
|