crewbus 10.0.11 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.template.md +4 -4
- package/CHANGELOG.md +151 -0
- package/README.md +713 -706
- package/TEAM.template.md +1 -1
- package/bin/crewbus-hook.js +22 -5
- package/bin/crewbus-mcp.js +56 -48
- package/bin/crewbus.js +486 -355
- package/bin/lib/channels.js +1 -1
- package/bin/lib/export.js +1 -1
- package/bin/lib/groups.js +1 -5
- package/bin/lib/identity.js +92 -152
- package/bin/lib/launch.js +128 -30
- package/bin/lib/qrcode.js +2971 -0
- package/bin/lib/relay.js +26 -54
- package/bin/lib/spawn.js +241 -194
- package/bin/lib/store.js +2 -2
- package/bin/lib/web.js +277 -59
- package/claude-plugin/skills/crewbus/SKILL.md +1 -1
- package/docs/APPROVALS.md +8 -8
- package/docs/AUDIT_EXPORT.md +7 -7
- package/docs/CERT_READINESS.md +120 -120
- package/docs/COMPATIBILITY.md +196 -194
- package/docs/CONSOLIDATOR.md +6 -6
- package/docs/CONTROL_PLANE_SPEC.md +12 -14
- package/docs/CREWS.md +16 -13
- package/docs/DELIVERY.md +213 -210
- package/docs/GROUPS.md +8 -8
- package/docs/HA.md +151 -151
- package/docs/IDENTITY.md +6 -6
- package/docs/LEAD_ASSIGN.md +3 -85
- package/docs/LONG_RUNS.md +3 -3
- package/docs/M1_CLI_DRAFT.md +9 -9
- package/docs/ORCHESTRATOR.md +87 -0
- package/docs/PAIRING.md +7 -7
- package/docs/QUICKSTART.md +24 -13
- package/docs/RBAC.md +84 -73
- package/docs/SPLIT.md +82 -82
- package/docs/TENANCY.md +10 -10
- package/docs/THREAT_MODEL.md +68 -69
- package/docs/VERIFIER.md +10 -10
- package/docs/VERSION_SKEW.md +57 -57
- package/documentation.html +37 -29
- package/examples/hermes-pairing.md +3 -3
- package/examples/t3-pairing.md +1 -1
- package/index.html +13 -14
- package/opencode/plugins/dm-watch.js +1 -1
- package/opencode/tools/dm-send.js +4 -13
- package/package.json +75 -50
- package/packages/client-runtime/README.md +40 -40
- package/packages/contracts/harness.json +108 -111
- package/packages/contracts/launch.json +2 -3
- package/packages/contracts/pairing.json +3 -3
- package/docs/DESKTOP_SPIKE.md +0 -223
package/bin/lib/channels.js
CHANGED
|
@@ -107,7 +107,7 @@ export function mirrorToGroupChannels(d, { groups, from, body, subject, replyTo,
|
|
|
107
107
|
const skipped = [];
|
|
108
108
|
for (const g of groups || []) {
|
|
109
109
|
// Member-scoped mirrors (C4): a worker's brief lands on grp-<g> channel
|
|
110
|
-
// only if it is a member of <g> (or
|
|
110
|
+
// only if it is a member of <g> (or orchestrator). Non-members' DMs still
|
|
111
111
|
// deliver — the channel mirror is skipped with a visible note.
|
|
112
112
|
const gate = authorizeCheck(d, from, "channel-post", { channelGroup: g });
|
|
113
113
|
if (!gate || !gate.ok) {
|
package/bin/lib/export.js
CHANGED
|
@@ -56,7 +56,7 @@ export function holdRefusal(d) { // line 5588
|
|
|
56
56
|
const who = h.placedBy || "unknown";
|
|
57
57
|
const when = h.placedAt || "unknown time";
|
|
58
58
|
const why = h.reason ? `: ${h.reason}` : "";
|
|
59
|
-
return `prune REFUSED — legal hold ACTIVE (placed by ${who} at ${when}${why}) [board ${d.root}] — lift with: hold lift --from
|
|
59
|
+
return `prune REFUSED — legal hold ACTIVE (placed by ${who} at ${when}${why}) [board ${d.root}] — lift with: hold lift --from orchestrator`;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// readBoardMeta/writeBoardMeta/writeAtomicFile live in store.js (canonical home).
|
package/bin/lib/groups.js
CHANGED
|
@@ -324,9 +324,5 @@ export function findFirstVerifiedReply(d, items) {
|
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
export function heuristicSenderType(d, from) { // line 1188
|
|
327
|
-
|
|
328
|
-
const g = readGroup(d, "lead");
|
|
329
|
-
if (g && Array.isArray(g.members) && g.members.includes(from)) return "lead";
|
|
330
|
-
} catch {}
|
|
331
|
-
return "peer";
|
|
327
|
+
return String(from || "") === "orchestrator" ? "orchestrator" : "peer";
|
|
332
328
|
}
|
package/bin/lib/identity.js
CHANGED
|
@@ -70,7 +70,6 @@ export function agentTokenMatches(rec, token) { // line 273
|
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
if (rec.token) return timingSafeEqualStr(t, String(rec.token));
|
|
74
73
|
return false;
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -92,8 +91,6 @@ export function mergeSyncedAgent(local, incoming) { // line 299
|
|
|
92
91
|
const merged = { ...clean };
|
|
93
92
|
if (local.tokenHash !== undefined) merged.tokenHash = local.tokenHash;
|
|
94
93
|
if (local.salt !== undefined) merged.salt = local.salt;
|
|
95
|
-
// Legacy plaintext in flight: keep local secret, never adopt remote one.
|
|
96
|
-
if (local.token !== undefined && incoming.token === undefined) merged.token = local.token;
|
|
97
94
|
return merged;
|
|
98
95
|
}
|
|
99
96
|
|
|
@@ -158,28 +155,18 @@ export function checkToken(d, agent, token) { // line 361
|
|
|
158
155
|
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
159
156
|
return rec;
|
|
160
157
|
}
|
|
161
|
-
|
|
162
|
-
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
163
|
-
// Migrate: re-hash + drop plaintext now that the owner proved possession.
|
|
164
|
-
const salt = newSalt();
|
|
165
|
-
const migrated = { ...rec, tokenHash: hashToken(String(token), salt), salt };
|
|
166
|
-
delete migrated.token;
|
|
167
|
-
migrated.lastSeen = new Date().toISOString();
|
|
168
|
-
writeAgentFile(d, agent, migrated);
|
|
169
|
-
return migrated;
|
|
170
|
-
}
|
|
171
|
-
fail(`agent "${agent}" predates tokens — re-register to claim it: register --from ${agent}`);
|
|
158
|
+
fail(`bad/missing token hash for "${agent}" — re-register to claim it: register --from ${agent}`);
|
|
172
159
|
}
|
|
173
160
|
|
|
174
161
|
// First send as a new name mints its record + token (same first-claim-wins
|
|
175
162
|
// as register, zero extra round-trip). Returns { created } so callers can
|
|
176
163
|
// print the token exactly once — it is never shown again via send.
|
|
177
164
|
export function ensureSender(d, agent, token) { // line 387
|
|
178
|
-
const sentinel = reservedNameReason(agent);
|
|
179
|
-
if (sentinel) fail(sentinel);
|
|
180
165
|
const rec = readAgent(d, agent);
|
|
181
166
|
if (!rec) {
|
|
182
|
-
|
|
167
|
+
const sentinel = reservedNameReason(agent);
|
|
168
|
+
if (sentinel) fail(sentinel);
|
|
169
|
+
if (isBoardFrozen(d)) fail(`board is frozen — new registrations refused (ask the orchestrator to register --from orchestrator --for ${agent})`);
|
|
183
170
|
const fresh = mintToken();
|
|
184
171
|
const salt = newSalt();
|
|
185
172
|
// Fresh claims race (parallel first sends): exactly one may win, via
|
|
@@ -213,16 +200,7 @@ export function ensureSender(d, agent, token) { // line 387
|
|
|
213
200
|
assertMintWon(d, agent, rec.tokenHash);
|
|
214
201
|
return { created: true, token: fresh };
|
|
215
202
|
}
|
|
216
|
-
if (
|
|
217
|
-
// Legacy file: must present the old plaintext once; then migrate.
|
|
218
|
-
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
219
|
-
const salt = newSalt();
|
|
220
|
-
rec.tokenHash = hashToken(String(token), salt);
|
|
221
|
-
rec.salt = salt;
|
|
222
|
-
delete rec.token;
|
|
223
|
-
writeAgentFile(d, agent, rec);
|
|
224
|
-
return { created: false, migrated: true };
|
|
225
|
-
}
|
|
203
|
+
if (!rec.tokenHash) fail(`bad/missing token hash for "${agent}" — re-register to claim: register --from ${agent}`);
|
|
226
204
|
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
227
205
|
if (rec.offboarded) fail(`agent "${agent}" is offboarded — sends as that name are refused (inbox preserved for audit)`);
|
|
228
206
|
if (tokenExpired(rec)) fail(`token for "${agent}" expired at ${rec.expiresAt} — re-register to renew: register --from ${agent} --token <old-or-new> --expires-in <dur>`);
|
|
@@ -347,46 +325,41 @@ export const RESERVED_SENTINELS = ["unknown", "me", "you"];
|
|
|
347
325
|
|
|
348
326
|
export function reservedNameReason(agent) {
|
|
349
327
|
const s = String(agent || "").trim().toLowerCase();
|
|
328
|
+
if (s === ORCHESTRATOR_NAME) {
|
|
329
|
+
return `"${agent}" is reserved for the board orchestrator (auto-provisioned by spawn; do not register it)`;
|
|
330
|
+
}
|
|
350
331
|
return RESERVED_SENTINELS.includes(s)
|
|
351
|
-
? `"${agent}" is a reserved sentinel name (amnesia-throwaway)
|
|
332
|
+
? `"${agent}" is a reserved sentinel name (amnesia-throwaway) - identity lost? run: crewbus recover, then re-register/claim your real name`
|
|
352
333
|
: null;
|
|
353
|
-
}
|
|
334
|
+
}
|
|
354
335
|
|
|
355
336
|
// ---------------------------------------------------------------------------
|
|
356
|
-
//
|
|
337
|
+
// RBAC: two roles only.
|
|
357
338
|
//
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
//
|
|
339
|
+
// orchestrator — the board's single control-plane identity. Reads and writes
|
|
340
|
+
// everything: spawn/respawn/kill, approvals, groups, channels,
|
|
341
|
+
// ACLs, pairing, admin operations. The board bootstraps exactly
|
|
342
|
+
// one, named `orchestrator` (see ensureOrchestrator).
|
|
343
|
+
// worker — the data plane. send/inbox/ack/redeliver/lock, artifacts,
|
|
344
|
+
// lessons, member-scoped channel posts. No control-plane acts.
|
|
361
345
|
//
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
// when the caller is admin, else ignored-with-warning.
|
|
366
|
-
// - legacy records without `role` map to `lead` so existing crews keep
|
|
367
|
-
// working (documented in docs/RBAC.md).
|
|
368
|
-
// Permission matrix (minimal):
|
|
369
|
-
// - admin: all, incl. role grants / offboard / prune / acl set /
|
|
370
|
-
// group restrict / serve --allow-remote-spawn.
|
|
371
|
-
// - lead: send / spawn / respawn / pool / spawn-kill (OWN crew only:
|
|
372
|
-
// target.spawnedBy must equal caller, or target never spawned;
|
|
373
|
-
// respawn --force reuses the spawn-kill scope check) / group manage /
|
|
374
|
-
// result record / race close / channel post / lock / inbox / ack /
|
|
375
|
-
// redeliver + all reads.
|
|
376
|
-
// - worker: send / inbox / ack / redeliver / lock (scoped: release still
|
|
377
|
-
// requires ownership) / channel tail (read) + all reads. No spawn,
|
|
378
|
-
// no kills, no group mgmt, no channel post, no result/race writes.
|
|
379
|
-
// - auditor: read-only everything (inbox / gather / thread / log /
|
|
380
|
-
// channel tail / group show / result show / spawn-status, ...). Zero
|
|
381
|
-
// writes: send/spawn/kill/prune/ack/lock/channel-post all refused.
|
|
382
|
-
// Reads not listed above default-allow (fail-closed only for writes).
|
|
346
|
+
// Records with any other/missing role are treated as workers (safe fallback:
|
|
347
|
+
// an unknown role can never gain orchestrator powers).
|
|
348
|
+
// Reads that are not routed through authorize() stay default-open.
|
|
383
349
|
// ---------------------------------------------------------------------------
|
|
384
350
|
|
|
385
|
-
export const
|
|
351
|
+
export const ORCHESTRATOR_NAME = "orchestrator";
|
|
352
|
+
export const VALID_ROLES = ["orchestrator", "worker"];
|
|
353
|
+
|
|
354
|
+
// Worker-allowed write/read actions. Everything else is orchestrator-only.
|
|
355
|
+
const WORKER_ACTIONS = new Set([
|
|
356
|
+
"send", "inbox", "ack", "redeliver", "lock", "artifact-write", "lesson-write",
|
|
357
|
+
"hold-status",
|
|
358
|
+
]);
|
|
386
359
|
|
|
387
360
|
export function cleanRole(raw) { // line 472
|
|
388
361
|
const r = String(raw || "").trim().toLowerCase();
|
|
389
|
-
if (!VALID_ROLES.includes(r)) fail(`invalid --role "${raw}" (want
|
|
362
|
+
if (!VALID_ROLES.includes(r)) fail(`invalid --role "${raw}" (want orchestrator|worker)`);
|
|
390
363
|
return r;
|
|
391
364
|
}
|
|
392
365
|
|
|
@@ -394,7 +367,7 @@ export function roleOfRecord(rec) { // line 478
|
|
|
394
367
|
if (rec && typeof rec.role === "string" && VALID_ROLES.includes(String(rec.role).toLowerCase())) {
|
|
395
368
|
return String(rec.role).toLowerCase();
|
|
396
369
|
}
|
|
397
|
-
return "
|
|
370
|
+
return "worker"; // unknown/missing role: never grant control-plane powers
|
|
398
371
|
}
|
|
399
372
|
|
|
400
373
|
export function getRole(d, agent) { // line 485
|
|
@@ -417,10 +390,7 @@ export function readBoardAcl(d) { // line 497
|
|
|
417
390
|
meta = null;
|
|
418
391
|
}
|
|
419
392
|
const acl = (meta && typeof meta.acl === "object" && meta.acl) || {};
|
|
420
|
-
|
|
421
|
-
? String(acl.defaultRole).toLowerCase()
|
|
422
|
-
: "worker";
|
|
423
|
-
return { defaultRole: def, frozen: acl.frozen === true };
|
|
393
|
+
return { defaultRole: "worker", frozen: acl.frozen === true };
|
|
424
394
|
}
|
|
425
395
|
|
|
426
396
|
export function writeBoardAcl(d, acl) { // line 511
|
|
@@ -439,75 +409,46 @@ export function isBoardFrozen(d) { // line 523
|
|
|
439
409
|
return readBoardAcl(d).frozen === true;
|
|
440
410
|
}
|
|
441
411
|
|
|
442
|
-
//
|
|
443
|
-
//
|
|
412
|
+
// Every self-registering identity is a worker. The orchestrator is minted only
|
|
413
|
+
// by ensureOrchestrator (spawn/bootstrap) or an explicit orchestrator grant.
|
|
444
414
|
export function defaultRoleForNew(d) { // line 529
|
|
445
|
-
return
|
|
415
|
+
return "worker";
|
|
446
416
|
}
|
|
447
417
|
|
|
448
418
|
// Core RBAC decision: returns { ok, reason }. Never exits (CLI authorize()
|
|
449
419
|
// turns !ok into fail(); relay/MCP turn it into 403/throw). Restricted-group
|
|
450
|
-
// scope is checked here too when scope.toGroups is present
|
|
451
|
-
// addressing a restricted group is allowed only for admin/lead or a member.
|
|
420
|
+
// scope is checked here too when scope.toGroups is present.
|
|
452
421
|
export function authorizeCheck(d, agent, action, scope) { // line 537
|
|
453
422
|
const role = getRole(d, agent);
|
|
454
423
|
const act = String(action || "");
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (!EXPORT_ROLES.has(role)) return { ok: false, reason: `role "${role}" cannot export (need admin|auditor)` };
|
|
461
|
-
} else if (role === "admin") {
|
|
462
|
-
// admins still honor restricted groups? No: admin/lead bypass membership.
|
|
463
|
-
} else if (ADMIN_ONLY.has(act)) {
|
|
464
|
-
return { ok: false, reason: `role "${role}" cannot ${act} (need admin)` };
|
|
465
|
-
} else if (LEAD_PLUS.has(act)) {
|
|
466
|
-
if (role !== "lead") return { ok: false, reason: `role "${role}" cannot ${act} (need lead|admin)` };
|
|
467
|
-
} else if (act === "channel-post") {
|
|
468
|
-
// Member-scoped channel posting (C4, default-on): workers may post to the
|
|
469
|
-
// channels of groups they are a MEMBER of (scope.channelGroup); lead/admin
|
|
470
|
-
// post anywhere (board channels + every group channel). Everyone else,
|
|
471
|
-
// and workers targeting a foreign group's channel or a board channel with
|
|
472
|
-
// no member mapping, are refused.
|
|
473
|
-
if (role === "admin" || role === "lead") {
|
|
474
|
-
// board-wide + group channels
|
|
475
|
-
} else if (role !== "worker") {
|
|
476
|
-
return { ok: false, reason: `role "${role}" cannot ${act} (member-posting is scoped to group members; need lead|admin)` };
|
|
477
|
-
} else {
|
|
424
|
+
if (role === "orchestrator") {
|
|
425
|
+
// Full control plane.
|
|
426
|
+
} else if (role === "worker") {
|
|
427
|
+
if (act === "channel-post") {
|
|
428
|
+
// Member-scoped: a worker may post only to a group channel it belongs to.
|
|
478
429
|
const targetGroup = scope && scope.channelGroup ? String(scope.channelGroup) : undefined;
|
|
479
430
|
if (!targetGroup) {
|
|
480
|
-
return { ok: false, reason: `role "worker" may post only to a group channel it belongs to (
|
|
431
|
+
return { ok: false, reason: `role "worker" may post only to a group channel it belongs to (board channels are orchestrator-only)` };
|
|
481
432
|
}
|
|
482
433
|
const gdoc = readGroup(d, targetGroup);
|
|
483
|
-
if (!gdoc) return { ok: false, reason: `channel group "${targetGroup}" not found (
|
|
434
|
+
if (!gdoc) return { ok: false, reason: `channel group "${targetGroup}" not found (board channels are orchestrator-only)` };
|
|
484
435
|
const members = Array.isArray(gdoc.members) ? gdoc.members : [];
|
|
485
|
-
if (!members.includes(agent)) return { ok: false, reason: `group channel "${targetGroup}" — members only
|
|
436
|
+
if (!members.includes(agent)) return { ok: false, reason: `group channel "${targetGroup}" — members only` };
|
|
437
|
+
} else if (!WORKER_ACTIONS.has(act)) {
|
|
438
|
+
return { ok: false, reason: `role "worker" cannot ${act} (orchestrator only)` };
|
|
486
439
|
}
|
|
487
|
-
} else if (act === "spawn-kill") {
|
|
488
|
-
if (role !== "lead") return { ok: false, reason: `role "${role}" cannot spawn-kill (need lead|admin)` };
|
|
489
|
-
const targets = (scope && Array.isArray(scope.targets)) ? scope.targets : [];
|
|
490
|
-
for (const t of targets) {
|
|
491
|
-
const rec = readAgent(d, t);
|
|
492
|
-
if (rec && rec.spawnedBy && rec.spawnedBy !== agent) {
|
|
493
|
-
return { ok: false, reason: `lead "${agent}" cannot kill "${t}" (spawned by ${rec.spawnedBy}; own crew only)` };
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
} else if (WORKER_WRITES.has(act)) {
|
|
497
|
-
if (role !== "lead" && role !== "worker") return { ok: false, reason: `role "${role}" cannot ${act} (auditor is read-only)` };
|
|
498
440
|
} else {
|
|
499
|
-
|
|
500
|
-
// race-start/spawn-status/agents/...) default-allow for all roles.
|
|
441
|
+
return { ok: false, reason: `unknown role "${role}" (want orchestrator|worker)` };
|
|
501
442
|
}
|
|
502
|
-
// Group-scoped sends: restricted groups need
|
|
443
|
+
// Group-scoped sends: restricted groups need the orchestrator or membership.
|
|
503
444
|
const toGroups = (scope && Array.isArray(scope.toGroups)) ? scope.toGroups : [];
|
|
504
445
|
if ((act === "send" || act === "spawn" || act === "pool") && toGroups.length > 0) {
|
|
505
446
|
for (const g of toGroups) {
|
|
506
447
|
const doc = readGroup(d, g);
|
|
507
448
|
if (doc && doc.restricted === true) {
|
|
508
449
|
const members = Array.isArray(doc.members) ? doc.members : [];
|
|
509
|
-
if (role !== "
|
|
510
|
-
return { ok: false, reason: `group "${g}" is restricted (member or
|
|
450
|
+
if (role !== "orchestrator" && !members.includes(agent)) {
|
|
451
|
+
return { ok: false, reason: `group "${g}" is restricted (member or orchestrator only)` };
|
|
511
452
|
}
|
|
512
453
|
}
|
|
513
454
|
}
|
|
@@ -548,65 +489,64 @@ export function mergeAgentDoc(prev, patch) {
|
|
|
548
489
|
return base;
|
|
549
490
|
}
|
|
550
491
|
|
|
551
|
-
//
|
|
552
|
-
//
|
|
553
|
-
// the
|
|
554
|
-
//
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
492
|
+
// One standing control-plane identity per board. Called by spawn and by the
|
|
493
|
+
// local web/serve servers. Reads the existing token file when it still matches
|
|
494
|
+
// the record; otherwise mints (or rotates) and persists logs/orchestrator.token.
|
|
495
|
+
// Never fails for bookkeeping reasons; returns { from, token, created }.
|
|
496
|
+
export function ensureOrchestrator(d) {
|
|
497
|
+
const name = ORCHESTRATOR_NAME;
|
|
498
|
+
const tokenPath = path.join(d.root, "logs", `${name}.token`);
|
|
499
|
+
const readTokenFile = () => {
|
|
500
|
+
try {
|
|
501
|
+
const t = fs.readFileSync(tokenPath, "utf8").trim();
|
|
502
|
+
return t || null;
|
|
503
|
+
} catch { return null; }
|
|
504
|
+
};
|
|
505
|
+
const writeTokenFile = (token) => {
|
|
506
|
+
try {
|
|
507
|
+
fs.mkdirSync(path.dirname(tokenPath), { recursive: true });
|
|
508
|
+
fs.writeFileSync(tokenPath, token + "\n", "utf8");
|
|
509
|
+
try { fs.chmodSync(tokenPath, 0o600); } catch {}
|
|
510
|
+
} catch {}
|
|
511
|
+
};
|
|
512
|
+
let prev = null;
|
|
513
|
+
try { prev = readAgent(d, name); } catch { prev = null; }
|
|
514
|
+
if (prev && prev.tokenHash) {
|
|
515
|
+
const tok = readTokenFile();
|
|
516
|
+
if (tok && agentTokenMatches(prev, tok)) return { from: name, token: tok, created: false };
|
|
517
|
+
}
|
|
570
518
|
const fresh = mintToken();
|
|
571
519
|
const salt = newSalt();
|
|
572
520
|
const now = new Date().toISOString();
|
|
573
|
-
let prev = null;
|
|
574
|
-
try { prev = readJson(path.join(d.agents, "boss.json")); } catch { prev = null; }
|
|
575
521
|
const { v, hlc } = stampSyncDoc(prev);
|
|
576
522
|
const doc = mergeAgentDoc(prev, {
|
|
577
|
-
name
|
|
523
|
+
name,
|
|
578
524
|
firstSeen: (prev && prev.firstSeen) || now,
|
|
579
525
|
lastSeen: now,
|
|
580
526
|
tokenHash: hashToken(fresh, salt),
|
|
581
527
|
salt,
|
|
582
528
|
revokedAt: undefined,
|
|
583
529
|
offboarded: undefined,
|
|
584
|
-
role: "
|
|
530
|
+
role: "orchestrator",
|
|
585
531
|
v, hlc,
|
|
586
532
|
});
|
|
587
|
-
//
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
533
|
+
// Fresh record: atomic first claim. Existing record (or lost race): rewrite
|
|
534
|
+
// only when the token file is missing/stale, otherwise reuse the winner.
|
|
535
|
+
if (!prev) {
|
|
536
|
+
let won = false;
|
|
537
|
+
try { won = writeExclusiveJson(path.join(d.agents, `${name}.json`), doc); } catch { won = false; }
|
|
538
|
+
if (!won) {
|
|
539
|
+
const again = readAgent(d, name);
|
|
540
|
+
const tok = readTokenFile();
|
|
541
|
+
if (again && again.tokenHash && tok && agentTokenMatches(again, tok)) {
|
|
542
|
+
return { from: name, token: tok, created: false };
|
|
543
|
+
}
|
|
595
544
|
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
// Lost the race (parallel boot): read the winner, no token to return.
|
|
599
|
-
return null;
|
|
600
|
-
}
|
|
601
|
-
if (won) {
|
|
602
|
-
try { chmodAgentFile(path.join(d.agents, "boss.json")); } catch {}
|
|
603
|
-
try {
|
|
604
|
-
fs.mkdirSync(path.join(d.root, "logs"), { recursive: true });
|
|
605
|
-
fs.writeFileSync(path.join(d.root, "logs", "boss.token"), fresh + "\n", "utf8");
|
|
606
|
-
try { fs.chmodSync(path.join(d.root, "logs", "boss.token"), 0o600); } catch {}
|
|
607
|
-
} catch {}
|
|
545
|
+
} else {
|
|
546
|
+
writeAgentFile(d, name, doc);
|
|
608
547
|
}
|
|
609
|
-
|
|
548
|
+
writeTokenFile(fresh);
|
|
549
|
+
return { from: name, token: fresh, created: true };
|
|
610
550
|
}
|
|
611
551
|
|
|
612
552
|
export function touchAgent(d, name, extra) { // line 2647
|
package/bin/lib/launch.js
CHANGED
|
@@ -28,7 +28,7 @@ export const LAUNCH_DRIVER_FALLBACK = [
|
|
|
28
28
|
{ driver: "grok", displayName: "grok-build", binary: "grok", briefDelivery: "file", sessionCapture: "preassigned", resume: true, spawnArgs: "--prompt-file <brief> -s <uuid>", resumeArgs: "--prompt-file <catchup> -r <id>" },
|
|
29
29
|
{ driver: "antigravity", displayName: "Antigravity", binary: "agy", briefDelivery: "inline", sessionCapture: "none", resume: false, spawnArgs: "--print --mode accept-edits \"<brief>\"", resumeArgs: "unsupported (no stable conversation id)" },
|
|
30
30
|
{ driver: "cursor", displayName: "Cursor", binary: "cursor-agent", briefDelivery: "inline", sessionCapture: "none", resume: false, spawnArgs: "cursor-agent -p --force --trust \"<brief>\"", resumeArgs: "unsupported (id lives in stream-json)" },
|
|
31
|
-
{ driver: "
|
|
31
|
+
{ driver: "qwen", displayName: "Qwen Code", binary: "qwen", briefDelivery: "inline", sessionCapture: "preassigned", resume: true, spawnArgs: "--output-format json -y --approval-mode yolo \"<brief>\"", resumeArgs: "--resume <id> \"<catchup>\"" },
|
|
32
32
|
];
|
|
33
33
|
// Resolve the driver table: contracts file wins, fallback otherwise.
|
|
34
34
|
export function launchDrivers() {
|
|
@@ -36,7 +36,7 @@ export function launchDrivers() {
|
|
|
36
36
|
const here = path.dirname(new URL(import.meta.url).pathname);
|
|
37
37
|
const p = path.join(here, "..", "..", "packages", "contracts", "harness.json");
|
|
38
38
|
const doc = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
39
|
-
if (doc && Array.isArray(doc.drivers) && doc.drivers.length
|
|
39
|
+
if (doc && Array.isArray(doc.drivers) && doc.drivers.length >= 7) return doc.drivers;
|
|
40
40
|
} catch {}
|
|
41
41
|
return LAUNCH_DRIVER_FALLBACK;
|
|
42
42
|
}
|
|
@@ -151,7 +151,13 @@ export const HARNESS_MODELS = {
|
|
|
151
151
|
{ id: "claude-3.7-sonnet", label: "Claude 3.7 Sonnet (Legacy)", tier: "standard" },
|
|
152
152
|
{ id: "gpt-4o", label: "GPT-4o (Legacy)", tier: "standard" },
|
|
153
153
|
],
|
|
154
|
-
|
|
154
|
+
qwen: [
|
|
155
|
+
{ id: "qwen3.8-max", label: "Qwen 3.8 Max (Flagship Reasoning & Coding)", tier: "frontier" },
|
|
156
|
+
{ id: "qwen3.7-plus", label: "Qwen 3.7 Plus (Balanced Agentic Reasoning)", tier: "standard" },
|
|
157
|
+
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash (Fast / High-Throughput)", tier: "fast" },
|
|
158
|
+
{ id: "deepseek-v4-pro-0813", label: "DeepSeek v4 Pro (Coding & Math)", tier: "frontier" },
|
|
159
|
+
{ id: "qwen-coder-plus", label: "Qwen Coder Plus (Code Specialist)", tier: "standard" },
|
|
160
|
+
],
|
|
155
161
|
};
|
|
156
162
|
|
|
157
163
|
// Dynamic discovered model cache for harnesses capable of live discovery (e.g., opencode).
|
|
@@ -183,27 +189,99 @@ export function refreshDiscoveredModels(timeoutMs = 15000) {
|
|
|
183
189
|
const { execFile } = await import("node:child_process");
|
|
184
190
|
const { promisify } = await import("node:util");
|
|
185
191
|
const execFileAsync = promisify(execFile);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.filter((l) => l && !l.startsWith("⠀") && !l.startsWith("█") && !l.includes(" "));
|
|
193
|
-
if (rawLines.length > 0) {
|
|
194
|
-
const opencodeModels = rawLines.map((m) => {
|
|
195
|
-
const parts = m.split("/");
|
|
196
|
-
const name = parts[1] || parts[0];
|
|
197
|
-
const tier = /pro|r1|opus|3\.7|o3|o1|gpt-5|grok-4|max/i.test(m)
|
|
198
|
-
? "frontier"
|
|
199
|
-
: /haiku|flash|mini|nano|free/i.test(m)
|
|
200
|
-
? "fast"
|
|
201
|
-
: "standard";
|
|
202
|
-
return { id: m, label: `${name} (${parts[0]})`, tier };
|
|
192
|
+
|
|
193
|
+
// opencode model discovery
|
|
194
|
+
try {
|
|
195
|
+
const { stdout } = await execFileAsync("opencode", ["models"], {
|
|
196
|
+
timeout: timeoutMs,
|
|
197
|
+
shell: isWin,
|
|
203
198
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
const rawLines = String(stdout || "").split("\n")
|
|
200
|
+
.map((l) => l.trim())
|
|
201
|
+
.filter((l) => l && !l.startsWith("⠀") && !l.startsWith("█") && !l.includes(" "));
|
|
202
|
+
if (rawLines.length > 0) {
|
|
203
|
+
const opencodeModels = rawLines.map((m) => {
|
|
204
|
+
const parts = m.split("/");
|
|
205
|
+
const name = parts[1] || parts[0];
|
|
206
|
+
const tier = /pro|r1|opus|3\.7|o3|o1|gpt-5|grok-4|max/i.test(m)
|
|
207
|
+
? "frontier"
|
|
208
|
+
: /haiku|flash|mini|nano|free/i.test(m)
|
|
209
|
+
? "fast"
|
|
210
|
+
: "standard";
|
|
211
|
+
return { id: m, label: `${name} (${parts[0]})`, tier };
|
|
212
|
+
});
|
|
213
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
214
|
+
_cachedDiscoveredModels.opencode = opencodeModels;
|
|
215
|
+
}
|
|
216
|
+
} catch {}
|
|
217
|
+
|
|
218
|
+
// grok model discovery
|
|
219
|
+
try {
|
|
220
|
+
const { stdout: gOut } = await execFileAsync("grok", ["models"], {
|
|
221
|
+
timeout: timeoutMs,
|
|
222
|
+
shell: isWin,
|
|
223
|
+
});
|
|
224
|
+
const gLines = String(gOut || "").split("\n")
|
|
225
|
+
.map((l) => l.trim())
|
|
226
|
+
.filter((l) => l.startsWith("*") || l.startsWith("-"))
|
|
227
|
+
.map((l) => l.replace(/^[*-\s]+/, "").split(" ")[0].trim())
|
|
228
|
+
.filter(Boolean);
|
|
229
|
+
if (gLines.length > 0) {
|
|
230
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
231
|
+
_cachedDiscoveredModels.grok = gLines.map((id) => ({
|
|
232
|
+
id,
|
|
233
|
+
label: `${id.charAt(0).toUpperCase() + id.slice(1)} (Discovered)`,
|
|
234
|
+
tier: /4\.[6-9]|5/i.test(id) ? "frontier" : "standard",
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
} catch {}
|
|
238
|
+
|
|
239
|
+
// antigravity model discovery
|
|
240
|
+
try {
|
|
241
|
+
const { stdout: aOut } = await execFileAsync("agy", ["models"], {
|
|
242
|
+
timeout: timeoutMs,
|
|
243
|
+
shell: isWin,
|
|
244
|
+
});
|
|
245
|
+
const aLines = String(aOut || "").split("\n")
|
|
246
|
+
.map((l) => l.trim())
|
|
247
|
+
.filter((l) => l && !l.toLowerCase().startsWith("fetching") && l.includes("\t"))
|
|
248
|
+
.map((l) => {
|
|
249
|
+
const [id, label] = l.split("\t");
|
|
250
|
+
const tier = /high|pro|opus|4/i.test(label || id) ? "frontier" : /low|lite|mini/i.test(label || id) ? "fast" : "standard";
|
|
251
|
+
return { id: id.trim(), label: (label || id).trim(), tier };
|
|
252
|
+
});
|
|
253
|
+
if (aLines.length > 0) {
|
|
254
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
255
|
+
_cachedDiscoveredModels.antigravity = aLines;
|
|
256
|
+
}
|
|
257
|
+
} catch {}
|
|
258
|
+
|
|
259
|
+
// qwen model discovery
|
|
260
|
+
try {
|
|
261
|
+
const homeDir = os.homedir();
|
|
262
|
+
const settingsPath = path.join(homeDir, ".qwen", "settings.json");
|
|
263
|
+
const qModels = [];
|
|
264
|
+
if (fs.existsSync(settingsPath)) {
|
|
265
|
+
const sObj = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
|
|
266
|
+
if (sObj && sObj.modelProviders && typeof sObj.modelProviders === "object") {
|
|
267
|
+
for (const list of Object.values(sObj.modelProviders)) {
|
|
268
|
+
if (Array.isArray(list)) {
|
|
269
|
+
for (const item of list) {
|
|
270
|
+
if (item && item.id) {
|
|
271
|
+
const tier = /max|pro|plus|r1/i.test(item.id) ? "frontier" : /flash|mini|fast/i.test(item.id) ? "fast" : "standard";
|
|
272
|
+
qModels.push({ id: item.id, label: `${item.name || item.id} (Configured)`, tier });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (qModels.length > 0) {
|
|
280
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
281
|
+
_cachedDiscoveredModels.qwen = qModels;
|
|
282
|
+
}
|
|
283
|
+
} catch {}
|
|
284
|
+
|
|
207
285
|
} catch {
|
|
208
286
|
// Ignore discovery errors — static catalog remains available
|
|
209
287
|
} finally {
|
|
@@ -278,22 +356,42 @@ export function validateLaunchPlan(raw) {
|
|
|
278
356
|
}
|
|
279
357
|
}
|
|
280
358
|
|
|
281
|
-
|
|
282
|
-
|
|
359
|
+
// Per-worker models: "--model a,b,c" (or a models[] array over the RPC)
|
|
360
|
+
// applies a/b/c to workers in order, cycling when there are more workers
|
|
361
|
+
// than models — same semantics as --harness. A single value applies to all.
|
|
362
|
+
const modelList = Array.isArray(r.models)
|
|
363
|
+
? r.models
|
|
364
|
+
: (r.model === undefined || r.model === null ? [] : String(r.model).split(","));
|
|
365
|
+
const models = modelList
|
|
366
|
+
.map((m) => (m === undefined || m === null ? "" : String(m).trim()))
|
|
367
|
+
.filter(Boolean);
|
|
368
|
+
if (models.length === 0 && r.model !== undefined && r.model !== null && String(r.model).trim() !== "") {
|
|
369
|
+
errors.push("invalid model (empty after splitting on commas)");
|
|
370
|
+
}
|
|
371
|
+
for (const m of models) {
|
|
372
|
+
if (m.length > 100) errors.push("model name too long (max 100 chars)");
|
|
373
|
+
}
|
|
374
|
+
const model = models.length > 0 ? models.join(",") : undefined;
|
|
283
375
|
|
|
284
|
-
|
|
285
|
-
|
|
376
|
+
// The orchestrator lane is one process, so it takes one model (not a list).
|
|
377
|
+
const orchestratorModelRaw = r.orchestratorModel;
|
|
378
|
+
let orchestratorModel;
|
|
379
|
+
if (orchestratorModelRaw !== undefined && orchestratorModelRaw !== null && String(orchestratorModelRaw).trim() !== "") {
|
|
380
|
+
orchestratorModel = String(orchestratorModelRaw).trim();
|
|
381
|
+
if (orchestratorModel.includes(",")) errors.push("orchestratorModel takes one model (not a comma list)");
|
|
382
|
+
if (orchestratorModel.length > 100) errors.push("orchestrator model name too long (max 100 chars)");
|
|
383
|
+
}
|
|
286
384
|
|
|
287
385
|
const plan = {
|
|
288
|
-
harness, harnesses: harnesses.length > 0 ? harnesses : ["
|
|
289
|
-
model, body, count: Number.isInteger(count) && count > 0 ? count : 1,
|
|
386
|
+
harness, harnesses: harnesses.length > 0 ? harnesses : ["opencode"],
|
|
387
|
+
model, models, orchestratorModel, body, count: Number.isInteger(count) && count > 0 ? count : 1,
|
|
290
388
|
prefix: r.prefix === undefined ? undefined : String(r.prefix),
|
|
291
389
|
to: r.to === undefined ? undefined : String(r.to),
|
|
292
390
|
subject: r.subject === undefined ? undefined : String(r.subject),
|
|
293
391
|
priority: r.priority === undefined ? undefined : String(r.priority),
|
|
294
392
|
maxTurns: r.maxTurns === undefined ? undefined : String(r.maxTurns),
|
|
295
393
|
allowTools: r.allowTools === undefined ? undefined : String(r.allowTools),
|
|
296
|
-
permission, lifetime,
|
|
394
|
+
permission, lifetime,
|
|
297
395
|
isolate: !!r.isolate, worktree: r.worktree, branch: r.branch,
|
|
298
396
|
budgetTokens: r.budgetTokens, budgetMinutes: r.budgetMinutes, timeout: r.timeout,
|
|
299
397
|
target: r.target === undefined ? "local" : r.target,
|