crewbus 10.0.11 → 10.0.12
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 +16 -0
- package/README.md +690 -708
- package/bin/crewbus.js +49 -139
- package/bin/lib/identity.js +3 -25
- package/bin/lib/launch.js +68 -25
- package/bin/lib/qrcode.js +2971 -0
- package/bin/lib/relay.js +2 -13
- package/bin/lib/spawn.js +95 -41
- package/bin/lib/web.js +235 -20
- package/docs/CERT_READINESS.md +120 -120
- package/docs/COMPATIBILITY.md +192 -194
- package/docs/CONTROL_PLANE_SPEC.md +9 -11
- package/docs/CREWS.md +55 -55
- package/docs/DELIVERY.md +210 -210
- package/docs/HA.md +151 -151
- package/docs/LEAD_ASSIGN.md +74 -85
- package/docs/M1_CLI_DRAFT.md +2 -2
- package/docs/QUICKSTART.md +70 -70
- package/docs/SPLIT.md +82 -82
- package/docs/THREAT_MODEL.md +68 -69
- package/docs/VERSION_SKEW.md +57 -57
- package/documentation.html +10 -11
- package/examples/hermes-pairing.md +2 -2
- package/index.html +10 -11
- package/opencode/tools/dm-send.js +3 -12
- package/package.json +50 -50
- package/packages/client-runtime/README.md +40 -40
- package/packages/contracts/harness.json +93 -110
- package/packages/contracts/launch.json +1 -1
- package/docs/DESKTOP_SPIKE.md +0 -223
package/bin/crewbus.js
CHANGED
|
@@ -52,7 +52,7 @@ import { ackedIds, checkSendRateLimit, deliverDMs, enforceMaxChars, filterDigest
|
|
|
52
52
|
import { batchReplyIds, collectBatch, contributingGroups, expandGroups, expandGroupsOrFail, gatherTelemetry, groupTelemetryData, heuristicSenderType, readGroup, ensureGroupCreatedAt, readResultRecord, writeResultRecord, findFirstVerifiedReply } from "./lib/groups.js";
|
|
53
53
|
import { publishArtifact, adoptArtifact, verifyArtifact, readArtifactById, listArtifacts, listLessons, postLesson, selectLessons, renderWorkbenchBlock, workbenchMetrics, cleanArtifactId, cleanLessonScope, parseArtifactDeps } from "./lib/workbench.js";
|
|
54
54
|
import { appendChannelPost, channelLogPath, groupChannelName, lockAlive, lockPath, mergeChannelText, mirrorToGroupChannels, printChannelPost, readChannelPosts, readLock, summarizePosts, writeChannelCursor, SUMMARY_STOP, channelCursorPath, readChannelCursor, lockHash, acquireLockDoc, releaseLockDoc, tailChannelPosts, listLocks, parseChannelText } from "./lib/channels.js";
|
|
55
|
-
import { boardSnapshot, cmdWeb, escapeHtml, fleetSnapshot, channelsSnapshot, resultsSnapshot, auditSnapshot, handleApiAck, renderBoardHtml, handleApiKill, handleApiLaunch, handleWebDashboardRoute } from "./lib/web.js";
|
|
55
|
+
import { boardSnapshot, cmdWeb, escapeHtml, fleetSnapshot, channelsSnapshot, resultsSnapshot, auditSnapshot, handleApiAck, renderBoardHtml, handleApiKill, handleApiLaunch, handleWebDashboardRoute, renderPairHtml } from "./lib/web.js";
|
|
56
56
|
import { LAUNCH_DRIVER_FALLBACK, PAIR_SCOPES, advertiseEnv, buildPairUrl, detectHarnessBinaries, formatHarnessMenu, isBodyFileRef, launchDrivers, parseCountChoice, parseHarnessChoice, parsePermissionChoice, parseYesNo, probeBinary, validateLaunchPlan, HARNESS_MODELS, getDiscoveredModels, refreshDiscoveredModels } from "./lib/launch.js";
|
|
57
57
|
import readline from "node:readline";
|
|
58
58
|
|
|
@@ -319,7 +319,6 @@ function agentTokenMatches(rec, token) {
|
|
|
319
319
|
return false;
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
if (rec.token) return timingSafeEqual(String(token), String(rec.token));
|
|
323
322
|
return false;
|
|
324
323
|
}
|
|
325
324
|
|
|
@@ -345,7 +344,7 @@ function resolveToken(args) {
|
|
|
345
344
|
}
|
|
346
345
|
|
|
347
346
|
// First send as a new name mints its record + token (first-claim-wins).
|
|
348
|
-
// Stores only a salted hash
|
|
347
|
+
// Stores only a salted hash.
|
|
349
348
|
function ensureSender(root, agent, token) {
|
|
350
349
|
const rec = readAgent(root, agent);
|
|
351
350
|
if (!rec) {
|
|
@@ -355,7 +354,7 @@ function ensureSender(root, agent, token) {
|
|
|
355
354
|
writeAgentHashed(path.join(root, "agents", agent + ".json"), { name: agent, firstSeen: now, lastSeen: now, tokenHash: hashToken(fresh, salt), salt });
|
|
356
355
|
return { created: true, token: fresh };
|
|
357
356
|
}
|
|
358
|
-
if (!rec.tokenHash
|
|
357
|
+
if (!rec.tokenHash) {
|
|
359
358
|
const fresh = mintToken();
|
|
360
359
|
const salt = newSalt();
|
|
361
360
|
rec.tokenHash = hashToken(fresh, salt);
|
|
@@ -364,15 +363,7 @@ function ensureSender(root, agent, token) {
|
|
|
364
363
|
writeAgentHashed(path.join(root, "agents", agent + ".json"), rec);
|
|
365
364
|
return { created: true, token: fresh };
|
|
366
365
|
}
|
|
367
|
-
|
|
368
|
-
if (!agentTokenMatches(rec, token)) throw new Error(\`bad token for "\${agent}" (pass token or set CREWBUS_TOKEN)\`);
|
|
369
|
-
const salt = newSalt();
|
|
370
|
-
rec.tokenHash = hashToken(String(token), salt);
|
|
371
|
-
rec.salt = salt;
|
|
372
|
-
delete rec.token;
|
|
373
|
-
writeAgentHashed(path.join(root, "agents", agent + ".json"), rec);
|
|
374
|
-
return { created: false };
|
|
375
|
-
}
|
|
366
|
+
|
|
376
367
|
if (!agentTokenMatches(rec, token)) throw new Error(\`bad token for "\${agent}" (pass token or set CREWBUS_TOKEN)\`);
|
|
377
368
|
return { created: false };
|
|
378
369
|
}
|
|
@@ -1251,21 +1242,6 @@ function upsertAgentsMd(cwd, snippet) {
|
|
|
1251
1242
|
console.log("Updated crewbus section in AGENTS.md");
|
|
1252
1243
|
return;
|
|
1253
1244
|
}
|
|
1254
|
-
// Remove legacy v1 block if present (it starts with "## Agent board" and mentions the old workflow)
|
|
1255
|
-
if (cur.includes("COORDINATOR PRIME DIRECTIVE") || cur.includes("tasks ready")) {
|
|
1256
|
-
const lines = cur.split("\n");
|
|
1257
|
-
const out = [];
|
|
1258
|
-
let skipping = false;
|
|
1259
|
-
for (const ln of lines) {
|
|
1260
|
-
if (/^## Agent board/.test(ln)) { skipping = true; continue; }
|
|
1261
|
-
if (skipping && /^## /.test(ln)) { skipping = false; }
|
|
1262
|
-
if (!skipping) out.push(ln);
|
|
1263
|
-
}
|
|
1264
|
-
cur = out.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n";
|
|
1265
|
-
fs.writeFileSync(agentsMd, cur);
|
|
1266
|
-
console.log("Removed legacy crewbus v1 section from AGENTS.md");
|
|
1267
|
-
cur = fs.readFileSync(agentsMd, "utf8");
|
|
1268
|
-
}
|
|
1269
1245
|
if (!cur.includes("crewbus") && !cur.includes("crewbus DM")) {
|
|
1270
1246
|
fs.appendFileSync(agentsMd, "\n" + snippet);
|
|
1271
1247
|
console.log("Appended crewbus DM section to AGENTS.md");
|
|
@@ -1319,7 +1295,7 @@ function installOpencodeFiles(cwd, force) {
|
|
|
1319
1295
|
// marker dirs (.opencode/.claude/.codex/.agents/.grok/.cursor). No markers at all
|
|
1320
1296
|
// keeps the legacy default (opencode) so existing checkouts don't change.
|
|
1321
1297
|
|
|
1322
|
-
const HARNESSES = ["opencode", "claude", "codex", "antigravity", "grok", "cursor"
|
|
1298
|
+
const HARNESSES = ["opencode", "claude", "codex", "antigravity", "grok", "cursor"];
|
|
1323
1299
|
const HARNESS_MARKERS = {
|
|
1324
1300
|
opencode: ".opencode",
|
|
1325
1301
|
claude: ".claude",
|
|
@@ -1603,7 +1579,6 @@ function mergeCursorHooks(file, hookAbs, boardExtra) {
|
|
|
1603
1579
|
// `mcp(server/*)`, `command(...)`); .agents/ has no documented
|
|
1604
1580
|
// project-local permissions allowlist.
|
|
1605
1581
|
// - copilot: SKIPPED — not an init --harness adapter in this repo.
|
|
1606
|
-
// - generic: SKIPPED — no config surface.
|
|
1607
1582
|
const CLAUDE_BOARD_ALLOW = [
|
|
1608
1583
|
"mcp__crewbus__*",
|
|
1609
1584
|
"Bash(node *crewbus* *)",
|
|
@@ -1762,8 +1737,6 @@ waiters (PostToolUse/SessionStart \`asyncRewake\`) wake the session when mail la
|
|
|
1762
1737
|
cursor: (cli) =>
|
|
1763
1738
|
`On Cursor use the \`crewbus\` MCP server (\`.cursor/mcp.json\`) for DM tools — approve/enable it in Cursor settings.\n` +
|
|
1764
1739
|
`SessionStart + stop hooks (\`.cursor/hooks.json\`) inject waiting DMs. Set \`CREWBUS_AGENT=<you>\` once per terminal so hooks know who you are.`,
|
|
1765
|
-
generic: (cli) =>
|
|
1766
|
-
`On any other harness: send with \`${cli} send\`, read with \`inbox\`, or block with \`listen\`. Poll \`inbox\` at session start and after each task.`,
|
|
1767
1740
|
};
|
|
1768
1741
|
|
|
1769
1742
|
function upsertHarnessSections(cwd, cli, ids) {
|
|
@@ -1936,7 +1909,6 @@ function cmdInit(args) {
|
|
|
1936
1909
|
}
|
|
1937
1910
|
}
|
|
1938
1911
|
if (noOpencode) ids = ids.filter((h) => h !== "opencode");
|
|
1939
|
-
if (ids.includes("generic") && ids.length > 1) ids = ids.filter((h) => h !== "generic");
|
|
1940
1912
|
const nonLocal = root !== path.join(process.cwd(), ".crewbus");
|
|
1941
1913
|
const boardExtra = nonLocal ? `--board "${root.split(path.sep).join("/")}"` : "";
|
|
1942
1914
|
const mcpEnv = nonLocal ? { CREWBUS_DIR: root } : null;
|
|
@@ -1945,7 +1917,6 @@ function cmdInit(args) {
|
|
|
1945
1917
|
const ctx = { force, hookAbs: binAbs("crewbus-hook.js"), mcpAbs: binAbs("crewbus-mcp.js"), boardExtra, mcpEnv, portable };
|
|
1946
1918
|
const followUps = [];
|
|
1947
1919
|
for (const h of ids) {
|
|
1948
|
-
if (h === "generic") continue;
|
|
1949
1920
|
for (const f of applyHarness(process.cwd(), h, ctx)) {
|
|
1950
1921
|
if (!followUps.includes(f)) followUps.push(f);
|
|
1951
1922
|
}
|
|
@@ -2203,14 +2174,6 @@ function cmdRegister(args) {
|
|
|
2203
2174
|
return;
|
|
2204
2175
|
}
|
|
2205
2176
|
if (!agentTokenMatches(prev, token)) fail(`name "${agent}" is claimed (bad/missing token — pass --token or set CREWBUS_TOKEN)`);
|
|
2206
|
-
// Migrate legacy plaintext on successful auth.
|
|
2207
|
-
if (prev.token && !prev.tokenHash) {
|
|
2208
|
-
const salt = newSalt();
|
|
2209
|
-
prev.tokenHash = hashToken(String(token), salt);
|
|
2210
|
-
prev.salt = salt;
|
|
2211
|
-
delete prev.token;
|
|
2212
|
-
writeAgentFile(d, agent, prev);
|
|
2213
|
-
}
|
|
2214
2177
|
// `extra` (built right after --session parsing above) has sessionId only
|
|
2215
2178
|
// when given, so sessionless re-registers keep the prior binding.
|
|
2216
2179
|
if (expiresRaw !== undefined) extra.expiresAt = expiresAt;
|
|
@@ -2228,10 +2191,6 @@ function cmdRegister(args) {
|
|
|
2228
2191
|
}
|
|
2229
2192
|
process.stderr.write(`crewbus: warning: --role ignored (only an admin can grant roles; current role "${roleOfRecord(prev)}")\n`);
|
|
2230
2193
|
}
|
|
2231
|
-
if (!prev.role) {
|
|
2232
|
-
prev.role = "lead"; // backfill legacy records so agents --json exposes roles
|
|
2233
|
-
try { writeAgentFile(d, agent, prev); } catch {}
|
|
2234
|
-
}
|
|
2235
2194
|
const doc = touchAgent(d, agent, extra);
|
|
2236
2195
|
console.log(`registered ${agent}${doc.sessionId ? ` (session ${doc.sessionId})` : ""} [board ${d.root}]`);
|
|
2237
2196
|
}
|
|
@@ -2932,7 +2891,7 @@ function cmdSend(args) {
|
|
|
2932
2891
|
// fails to launch. Children inherit CREWBUS_DIR + CREWBUS_AGENT, log
|
|
2933
2892
|
// to .crewbus/logs/<name>-<stamp>.log, and report their pid back here.
|
|
2934
2893
|
// opencode runs `opencode run` with the brief attached via --file (no shell
|
|
2935
|
-
// quoting of the long prompt);
|
|
2894
|
+
// quoting of the long prompt); each driver runs with the same
|
|
2936
2895
|
// board env. Spawn caps at MAX_SPAWN — bigger crews get a broadcast DM.
|
|
2937
2896
|
// ---------------------------------------------------------------------------
|
|
2938
2897
|
|
|
@@ -2998,13 +2957,11 @@ function cmdSpawn(args) {
|
|
|
2998
2957
|
return s;
|
|
2999
2958
|
}).filter(Boolean);
|
|
3000
2959
|
if (harnesses.length === 0) harnesses.push("opencode");
|
|
3001
|
-
const validDrivers = ["opencode", "claude", "codex", "grok", "antigravity", "cursor"
|
|
2960
|
+
const validDrivers = ["opencode", "claude", "codex", "grok", "antigravity", "cursor"];
|
|
3002
2961
|
for (const h of harnesses) {
|
|
3003
2962
|
if (!validDrivers.includes(h)) fail(`unknown --harness "${h}" (want ${validDrivers.join("|")})`);
|
|
3004
2963
|
}
|
|
3005
2964
|
const harness = harnesses.join(",");
|
|
3006
|
-
const cmd = getFlag(args, "--cmd");
|
|
3007
|
-
if (harnesses.includes("generic") && !cmd) fail('generic harness needs --cmd "..." (runs with CREWBUS_DIR + CREWBUS_AGENT set)');
|
|
3008
2965
|
const maxTurns = getFlag(args, "--max-turns");
|
|
3009
2966
|
if (maxTurns !== undefined && !(Number(maxTurns) > 0)) fail("--max-turns must be a positive number");
|
|
3010
2967
|
if (maxTurns !== undefined && !harnesses.some((h) => h === "claude" || h === "grok")) fail(`--max-turns only applies to claude/grok (got --harness ${harness})`);
|
|
@@ -3038,32 +2995,16 @@ function cmdSpawn(args) {
|
|
|
3038
2995
|
const taskGroups = rosterGroups.filter((g) => groupNames.includes(g.name));
|
|
3039
2996
|
const offTask = rosterGroups.length - taskGroups.length;
|
|
3040
2997
|
const crewFor = (to, leadTarget) => buildCrewContext({ name: to, from, lead: leadTarget, subject, groups: taskGroups, myGroups: taskGroups.filter((g) => g.members.includes(to)).map((g) => g.name), offTask });
|
|
3041
|
-
// Lead auto-assignment (§auto-lead):
|
|
3042
|
-
//
|
|
3043
|
-
//
|
|
3044
|
-
//
|
|
3045
|
-
// spawner stays boss (reads, milestone DMs). `--lead none` (or `auto` with
|
|
3046
|
-
// purely generic harnesses) is the legacy star topology: replies pin to the
|
|
3047
|
-
// spawner, nothing else is provisioned.
|
|
2998
|
+
// Lead auto-assignment (§auto-lead): default: auto.
|
|
2999
|
+
// Workers pin replies to the board's standing 'lead' lane and a detached
|
|
3000
|
+
// persistent coordinator is provisioned after the crew boots; the spawner
|
|
3001
|
+
// stays boss (reads, milestone DMs).
|
|
3048
3002
|
const leadFlagRaw = getFlag(args, "--lead");
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
leadMode = hasCodingHarness ? "board" : "none";
|
|
3053
|
-
} else {
|
|
3054
|
-
leadMode = String(leadFlagRaw).trim().toLowerCase();
|
|
3055
|
-
if (leadMode === "auto") {
|
|
3056
|
-
leadMode = hasCodingHarness ? "board" : "none";
|
|
3057
|
-
}
|
|
3058
|
-
}
|
|
3059
|
-
if (!["board", "none"].includes(leadMode)) fail(`invalid --lead "${leadFlagRaw}" (want auto|board|none)`);
|
|
3060
|
-
if (leadMode === "board" && !hasCodingHarness) {
|
|
3061
|
-
fail('--lead board needs a coding harness for the auto-coordinator (add --harness opencode, or pass --lead none under --harness generic)');
|
|
3003
|
+
if (leadFlagRaw !== undefined) {
|
|
3004
|
+
const raw = String(leadFlagRaw).trim().toLowerCase();
|
|
3005
|
+
if (raw !== "auto") fail(`invalid --lead "${leadFlagRaw}" (only --lead auto is supported)`);
|
|
3062
3006
|
}
|
|
3063
|
-
|
|
3064
|
-
fail("--count 0 is the lead-revive path: it needs the auto-coordinator (--lead board — the default when a coding harness is present)");
|
|
3065
|
-
}
|
|
3066
|
-
const leadTarget = leadMode === "board" ? "lead" : from;
|
|
3007
|
+
const leadTarget = "lead";
|
|
3067
3008
|
const model = getFlag(args, "--model");
|
|
3068
3009
|
const auto = args.includes("--auto");
|
|
3069
3010
|
requireAutoConfirm(args);
|
|
@@ -3138,7 +3079,7 @@ if (leadBudgetMinutesRaw !== undefined && !(leadBudgetMinutes > 0)) fail("--lead
|
|
|
3138
3079
|
const at = new Date().toISOString();
|
|
3139
3080
|
const logDir = path.join(d.root, "logs");
|
|
3140
3081
|
if (!dry) fs.mkdirSync(logDir, { recursive: true });
|
|
3141
|
-
const spawnOpts = { harness,
|
|
3082
|
+
const spawnOpts = { harness, model, auto, maxTurns: maxTurnsNum, allowTools, cwd, root: d.root, prompt: null, keepEnv: args.includes("--keep-env"), allowEnv: parseAllowEnv(getFlag(args, "--allow-env")) };
|
|
3142
3083
|
if (dry) {
|
|
3143
3084
|
// Preview only: nothing touches the board (ids below are illustrative).
|
|
3144
3085
|
const previewBatch = !revive && recipients.length > 1 ? newId("batch") : undefined;
|
|
@@ -3156,7 +3097,7 @@ if (leadBudgetMinutesRaw !== undefined && !(leadBudgetMinutes > 0)) fail("--lead
|
|
|
3156
3097
|
} else {
|
|
3157
3098
|
console.log(`lead-revive: would ONLY provision/reuse the auto-coordinator on the '${leadTarget}' lane (0 workers, no DMs delivered) [board ${d.root}]`);
|
|
3158
3099
|
}
|
|
3159
|
-
if (
|
|
3100
|
+
if (leadTarget === "lead") {
|
|
3160
3101
|
const existingLead = readAgent(d, "lead");
|
|
3161
3102
|
// Stale-pid guard (C2): preview says "fresh provision" when the pid
|
|
3162
3103
|
// record is recycled (reboot + OS pid reuse).
|
|
@@ -3164,7 +3105,7 @@ if (leadBudgetMinutesRaw !== undefined && !(leadBudgetMinutes > 0)) fail("--lead
|
|
|
3164
3105
|
if (standing) {
|
|
3165
3106
|
console.log(`--- lead ---\na live coordinator already runs on the 'lead' lane (pid ${existingLead.spawnedPid}) — reused, not duplicated [board ${d.root}]`);
|
|
3166
3107
|
} else if (existingLead && existingLead.offboarded) {
|
|
3167
|
-
console.log(`--- lead ---\nlane "lead" is offboarded: provision would be SKIPPED (re-onboard it
|
|
3108
|
+
console.log(`--- lead ---\nlane "lead" is offboarded: provision would be SKIPPED (re-onboard it) [board ${d.root}]`);
|
|
3168
3109
|
} else {
|
|
3169
3110
|
const coordPreview = buildCoordinatorPrompt({
|
|
3170
3111
|
name: "lead", from, subject, body: body.trim(), batch: previewBatch,
|
|
@@ -3226,15 +3167,13 @@ if (leadBudgetMinutesRaw !== undefined && !(leadBudgetMinutes > 0)) fail("--lead
|
|
|
3226
3167
|
}
|
|
3227
3168
|
}
|
|
3228
3169
|
}
|
|
3229
|
-
// Auto-provisioned lead: runs after the crew boots so the coordinator's
|
|
3170
|
+
// Auto-provisioned lead: runs after the crew boots so the coordinator's
|
|
3230
3171
|
// roster carries the real brief ids, and so a lead boot failure can never
|
|
3231
3172
|
// block worker boots. Lead-revive (C9): also runs here with an EMPTY
|
|
3232
3173
|
// roster — the revive mission text becomes the coordinator's reminder of
|
|
3233
3174
|
// what the crew was on about (worker threads/scope live on the board).
|
|
3234
|
-
|
|
3235
|
-
const coordHarness = [
|
|
3236
|
-
...harnesses.filter((h) => h !== "generic"),
|
|
3237
|
-
][0] || "opencode";
|
|
3175
|
+
{
|
|
3176
|
+
const coordHarness = harnesses[0] || "opencode";
|
|
3238
3177
|
const provision = provisionAutoLead(d, {
|
|
3239
3178
|
spawnOpts: { ...spawnOpts, harness: coordHarness, maxTurns: undefined, allowTools: undefined },
|
|
3240
3179
|
from, subject, body: body.trim(), rev, logDir,
|
|
@@ -3267,9 +3206,6 @@ function printLaunchDryRun(v, args, from, root, asJson, cmdOpt) {
|
|
|
3267
3206
|
const names = p.to ? String(p.to).split(",").map((s) => s.trim()).filter(Boolean)
|
|
3268
3207
|
: Array.from({ length: p.count }, (_, i) => `${p.prefix || "w"}-${i + 1}`);
|
|
3269
3208
|
const harnesses = Array.isArray(p.harnesses) && p.harnesses.length > 0 ? p.harnesses : [p.harness || "opencode"];
|
|
3270
|
-
if (harnesses.includes("generic") && !cmdOpt) {
|
|
3271
|
-
fail("launch --harness generic needs --cmd \"...\" (no command to preview)");
|
|
3272
|
-
}
|
|
3273
3209
|
const rev = gitRevForBoard(root);
|
|
3274
3210
|
const rows = names.map((to, i) => {
|
|
3275
3211
|
const driver = harnesses[i % harnesses.length];
|
|
@@ -3306,7 +3242,7 @@ async function askLoop(rl, q, parse, hint) {
|
|
|
3306
3242
|
}
|
|
3307
3243
|
|
|
3308
3244
|
// Fills raw.harness/raw.to/raw.count/raw.prefix/raw.body/raw.permission
|
|
3309
|
-
//
|
|
3245
|
+
// by prompting. Assumes a TTY; pure parse logic
|
|
3310
3246
|
// lives in bin/lib/launch.js (unit-tested), this only loops.
|
|
3311
3247
|
async function runLaunchWizard(rl, raw, cmdOpt) {
|
|
3312
3248
|
const rows = detectHarnessBinaries();
|
|
@@ -3346,10 +3282,6 @@ async function runLaunchWizard(rl, raw, cmdOpt) {
|
|
|
3346
3282
|
if (i === 2) fail("too many invalid answers — re-run non-interactively with explicit flags");
|
|
3347
3283
|
}
|
|
3348
3284
|
raw.permission = await askLoop(rl, "permission [1 supervised (default) | 2 autoEdits | 3 auto | 4 full]: ", (a) => parsePermissionChoice(a, "supervised"), "1-4 or name");
|
|
3349
|
-
if (raw.harness === "generic" && !cmdOpt.value) {
|
|
3350
|
-
const cmdRaw = await askLoop(rl, 'command to run [--cmd, required for generic]: ', (a) => String(a).trim() || null, "non-empty command");
|
|
3351
|
-
cmdOpt.value = cmdRaw;
|
|
3352
|
-
}
|
|
3353
3285
|
return raw;
|
|
3354
3286
|
}
|
|
3355
3287
|
|
|
@@ -3490,7 +3422,7 @@ function cmdHarnesses(args) {
|
|
|
3490
3422
|
for (const r of rows) {
|
|
3491
3423
|
const found = r.found ? "yes" : "no";
|
|
3492
3424
|
const ver = (r.version || r.detail || "").slice(0, 26).padEnd(26);
|
|
3493
|
-
console.log(`${r.driver.padEnd(12)} ${(r.binary || "
|
|
3425
|
+
console.log(`${r.driver.padEnd(12)} ${(r.binary || "-").padEnd(14)} ${found.padEnd(6)} ${ver} ${(r.briefDelivery || "").padEnd(7)} ${r.resume ? "yes" : "NO (honest)"}`);
|
|
3494
3426
|
}
|
|
3495
3427
|
console.log("missing binaries mean not installed — install + authenticate per docs/COMPATIBILITY.md");
|
|
3496
3428
|
}
|
|
@@ -3549,8 +3481,7 @@ async function cmdSpawnKill(args) {
|
|
|
3549
3481
|
// crewbus respawn --from <lead> --to <worker> [--body "..."] [--force] [--dry-run]
|
|
3550
3482
|
// Preconditions: the worker was booted by spawn (worker-sessions record),
|
|
3551
3483
|
// its process is dead (or --force kills it first), and a harness session id
|
|
3552
|
-
// was captured
|
|
3553
|
-
// re-boots the catch-up brief fresh. The catch-up brief points at the
|
|
3484
|
+
// was captured. The catch-up brief points at the
|
|
3554
3485
|
// original prompt file and threads the same reply id, so a resumed worker
|
|
3555
3486
|
// continues instead of restarting. Lead/admin only (like spawn); --force
|
|
3556
3487
|
// additionally checks spawn-kill scope (own crew).
|
|
@@ -3573,7 +3504,7 @@ async function cmdRespawn(args) {
|
|
|
3573
3504
|
const dry = args.includes("--dry-run");
|
|
3574
3505
|
// --fresh: when the harness session id was never captured (opencode kills
|
|
3575
3506
|
// its buffered output before the log scan can read it), skip the resume
|
|
3576
|
-
// requirement and boot the catch-up brief fresh
|
|
3507
|
+
// requirement and boot the catch-up brief fresh.
|
|
3577
3508
|
const fresh = args.includes("--fresh");
|
|
3578
3509
|
const extraBody = getFlag(args, "--body");
|
|
3579
3510
|
if (extraBody !== undefined && String(extraBody).length > MAX_BODY_CHARS) fail(`message body too large (max ${MAX_BODY_CHARS} chars)`);
|
|
@@ -3590,7 +3521,7 @@ async function cmdRespawn(args) {
|
|
|
3590
3521
|
const harness = prev.harness;
|
|
3591
3522
|
if (!harness) fail(`no harness recorded for "${name}" (spawned before session capture — re-boot fresh with spawn --to ${name})`);
|
|
3592
3523
|
const sessionId = prev.harnessSessionId;
|
|
3593
|
-
if (!sessionId &&
|
|
3524
|
+
if (!sessionId && !fresh) fail(`no harness session id recorded for "${name}"${prev.idSource ? ` (source: ${prev.idSource})` : ""} — its conversation can't be resumed; re-brief with send --reply ${prev.briefId || "<brief-id>"}, respawn with --fresh to reboot it without the old conversation, or spawn a fresh worker`);
|
|
3594
3525
|
if ((prev.auto || false) && !args.includes("--auto")) fail(`worker "${name}" was spawned --auto (fully-unattended) — pass --auto to confirm the respawn carries the same danger (see docs/ISOLATION.md)`);
|
|
3595
3526
|
if (args.includes("--auto")) requireAutoConfirm(args);
|
|
3596
3527
|
if (!prev.promptPath) fail(`no original prompt on record for "${name}" (spawned before prompt capture — re-boot fresh with spawn --to ${name})`);
|
|
@@ -3602,21 +3533,16 @@ async function cmdRespawn(args) {
|
|
|
3602
3533
|
const briefId = prev.briefId || rec.briefId;
|
|
3603
3534
|
if (!briefId) fail(`no brief id on record for "${name}" — re-boot fresh with spawn --to ${name}`);
|
|
3604
3535
|
const cwd = getFlag(args, "--cwd") ? path.resolve(getFlag(args, "--cwd")) : (prev.cwd || path.dirname(root));
|
|
3605
|
-
|
|
3606
|
-
if (harness === "generic") {
|
|
3607
|
-
const cmdOverride = getFlag(args, "--cmd");
|
|
3608
|
-
if (cmdOverride !== undefined) cmd = cmdOverride;
|
|
3609
|
-
if (!cmd) fail(`generic respawn needs the original --cmd (not recorded — re-boot fresh with spawn --harness generic --cmd "..." --to ${name})`);
|
|
3610
|
-
}
|
|
3611
|
-
const spawnOpts = { harness, cmd, model: prev.model, maxTurns: prev.maxTurns, auto: !!prev.auto, allowTools: prev.allowTools, cwd, root: d.root, prompt: null, keepEnv: args.includes("--keep-env"), allowEnv: parseAllowEnv(getFlag(args, "--allow-env")) };
|
|
3536
|
+
const spawnOpts = { harness, model: prev.model, maxTurns: prev.maxTurns, auto: !!prev.auto, allowTools: prev.allowTools, cwd, root: d.root, prompt: null, keepEnv: args.includes("--keep-env"), allowEnv: parseAllowEnv(getFlag(args, "--allow-env")) };
|
|
3612
3537
|
const attempt = ((prev.respawnCount) || 0) + 1;
|
|
3613
3538
|
// Recycled-pid records read dead for respawn gating too (C2): a live pid
|
|
3614
3539
|
// that postdates the spawn belongs to an unrelated process.
|
|
3615
3540
|
const alive = typeof rec.spawnedPid === "number" && pidAlive(rec.spawnedPid) && !isPidStale(rec.spawnedPid, rec.spawnedAt);
|
|
3541
|
+
const effectiveSessionId = fresh ? undefined : (sessionId || undefined);
|
|
3616
3542
|
if (dry) {
|
|
3617
|
-
const catchup = buildRespawnBrief({ name, attempt, origPromptPath: prev.promptPath, briefId, harnessSessionId:
|
|
3618
|
-
const t = buildRespawnTarget({ ...spawnOpts, name, promptPath: `<logs>/${name}-<stamp>.respawn.md`, prompt: catchup, sessionId:
|
|
3619
|
-
console.log(`would respawn ${name} [${harness}] attempt ${attempt}${
|
|
3543
|
+
const catchup = buildRespawnBrief({ name, attempt, origPromptPath: prev.promptPath, briefId, harnessSessionId: effectiveSessionId || null, harness, lead: from, extraBody });
|
|
3544
|
+
const t = buildRespawnTarget({ ...spawnOpts, name, promptPath: `<logs>/${name}-<stamp>.respawn.md`, prompt: catchup, sessionId: effectiveSessionId });
|
|
3545
|
+
console.log(`would respawn ${name} [${harness}] attempt ${attempt}${effectiveSessionId ? ` session ${effectiveSessionId}` : " (fresh boot, no session continuity)"} cmd: ${formatSpawnCmd(t)} [board ${d.root}]`);
|
|
3620
3546
|
console.log(`--- catch-up brief ---\n${catchup}`);
|
|
3621
3547
|
return;
|
|
3622
3548
|
}
|
|
@@ -3629,9 +3555,9 @@ async function cmdRespawn(args) {
|
|
|
3629
3555
|
}
|
|
3630
3556
|
const logDir = path.join(d.root, "logs");
|
|
3631
3557
|
fs.mkdirSync(logDir, { recursive: true });
|
|
3632
|
-
const r = bootRespawnedWorker(d, spawnOpts, { to: name, briefId, from, sessionId:
|
|
3633
|
-
appendChainRecord(d, from, "respawn", { to: name, harness, attempt, sessionId:
|
|
3634
|
-
console.log(`respawned ${name} [${harness}] attempt ${attempt} pid ${r.pid}${
|
|
3558
|
+
const r = bootRespawnedWorker(d, spawnOpts, { to: name, briefId, from, sessionId: effectiveSessionId, attempt, origPromptPath: prev.promptPath, extraBody, logDir });
|
|
3559
|
+
appendChainRecord(d, from, "respawn", { to: name, harness, attempt, sessionId: effectiveSessionId || null });
|
|
3560
|
+
console.log(`respawned ${name} [${harness}] attempt ${attempt} pid ${r.pid}${effectiveSessionId ? ` session ${effectiveSessionId}` : " (fresh boot)"} [board ${d.root}]`);
|
|
3635
3561
|
}
|
|
3636
3562
|
|
|
3637
3563
|
// Global stop: kill every spawned worker truly (whole process tree).
|
|
@@ -4831,7 +4757,7 @@ function cmdDoctor(args) {
|
|
|
4831
4757
|
if (meta && Array.isArray(meta.harnesses) && meta.harnesses.length > 0) ids = meta.harnesses.filter((h) => HARNESSES.includes(h));
|
|
4832
4758
|
else {
|
|
4833
4759
|
ids = detectHarnesses(cwd);
|
|
4834
|
-
if (ids.length === 0) ids = ["
|
|
4760
|
+
if (ids.length === 0) ids = ["opencode"];
|
|
4835
4761
|
}
|
|
4836
4762
|
}
|
|
4837
4763
|
// Dead-man scan (read-only, board-local only — no cwd needed): the
|
|
@@ -5009,9 +4935,6 @@ function cmdDoctor(args) {
|
|
|
5009
4935
|
else no("cursor MCP .cursor/mcp.json", "run: crewbus init --harness cursor (then approve/enable it in Cursor settings)");
|
|
5010
4936
|
break;
|
|
5011
4937
|
}
|
|
5012
|
-
default:
|
|
5013
|
-
info(`generic harness: CLI pull only (inbox/listen), nothing to validate`);
|
|
5014
|
-
break;
|
|
5015
4938
|
}
|
|
5016
4939
|
}
|
|
5017
4940
|
// Reconcile hint (read-only): workers whose pids look recycled since a
|
|
@@ -5025,16 +4948,6 @@ function cmdDoctor(args) {
|
|
|
5025
4948
|
} catch {}
|
|
5026
4949
|
if (!process.env.CREWBUS_AGENT) info("CREWBUS_AGENT is unset — hooks need it to know who you are");
|
|
5027
4950
|
if (!process.env.CREWBUS_TOKEN) info("CREWBUS_TOKEN is unset — sends/reads as a claimed name need it");
|
|
5028
|
-
try {
|
|
5029
|
-
const legacy = fs.readdirSync(path.join(root, "agents")).filter((f) => f.endsWith(".json")).map((f) => {
|
|
5030
|
-
try {
|
|
5031
|
-
return readJson(path.join(root, "agents", f));
|
|
5032
|
-
} catch {
|
|
5033
|
-
return null;
|
|
5034
|
-
}
|
|
5035
|
-
}).filter((x) => x && x.name && !x.token && !x.tokenHash);
|
|
5036
|
-
if (legacy.length > 0) info(`${legacy.length} agent(s) predate tokens (${legacy.slice(0, 5).map((x) => x.name).join(",")}${legacy.length > 5 ? "…" : ""}) — re-register to claim`);
|
|
5037
|
-
} catch {}
|
|
5038
4951
|
console.log(bad === 0 ? "doctor: healthy" : `doctor: ${bad} problem(s)`);
|
|
5039
4952
|
if (bad > 0) process.exitCode = 1;
|
|
5040
4953
|
}
|
|
@@ -6833,7 +6746,7 @@ const USAGE = `crewbus — DM-only minimal bus for AI agent coordination (v2)
|
|
|
6833
6746
|
|
|
6834
6747
|
Setup:
|
|
6835
6748
|
crewbus init [--global] [--board <path>] [--force] [--no-opencode] [--portable]
|
|
6836
|
-
[--harness opencode,claude,codex,antigravity,grok,cursor
|
|
6749
|
+
[--harness opencode,claude,codex,antigravity,grok,cursor]
|
|
6837
6750
|
create board in ./.crewbus, write AGENTS.md block, install harness
|
|
6838
6751
|
crewbus install-cli
|
|
6839
6752
|
install standalone CLI wrapper to user PATH (~/.crewbus/bin)
|
|
@@ -6968,7 +6881,7 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6968
6881
|
(recover mail a dead watcher consumed: clears delivered markers and
|
|
6969
6882
|
rewinds the cursor so the next poll/push treats it as fresh;
|
|
6970
6883
|
use after re-registering with the live session)
|
|
6971
|
-
crewbus spawn --from <you> (--to <workers> | --count <n> [--prefix <p>]) --body "..." [--subject "..."] [--priority high|normal] [--needs-by 30m] [--harness opencode|claude|codex|grok|antigravity|cursor
|
|
6884
|
+
crewbus spawn --from <you> (--to <workers> | --count <n> [--prefix <p>]) --body "..." [--subject "..."] [--priority high|normal] [--needs-by 30m] [--harness opencode|claude|codex|grok|antigravity|cursor] [--cmd "..."] [--cwd <dir>] [--worktree <branch-prefix> | --branch <branch-prefix>] [--oneshot | --persistent] [--model <m>] [--max-turns <n>] [--allow-tools "..."] [--max-spawn <n>] [--auto --i-understand-danger] [--isolate] [--budget-tokens N] [--budget-minutes M] [--lead-budget-tokens N] [--lead-budget-minutes M] [--timeout 10m] [--keep-env] [--allow-env ANTHROPIC_,GITHUB_] [--workdir-root <dir>] [--sender-type human|lead|peer] [--dry-run]
|
|
6972
6885
|
(--budget-* cap the WORKERS; --lead-budget-* cap the auto-provisioned coordinator lane — same semantics, e.g. a 400k-token lead that posts its aggregate and exits. Unset = persistent boss-supervised coordinator (default). A standing coordinator keeps its boot-time budget; the flags cannot change it mid-flight.)
|
|
6973
6886
|
(workers boot with cloud/AI credential vars scrubbed from their environment by default (lead's keys never leak into briefs); pass --keep-env to inherit everything or --allow-env <prefix,...> to keep listed names. CREWBUS_TOKEN is never inherited — workers claim their own identity.)
|
|
6974
6887
|
(brief N workers AND boot them detached: the DM lands first so the brief
|
|
@@ -6976,7 +6889,7 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6976
6889
|
claude: \`-p\` + brief on stdin; codex: \`exec\` pointing at the brief
|
|
6977
6890
|
file; grok: headless via --prompt-file; antigravity: \`--print\` with the
|
|
6978
6891
|
brief inline; cursor: headless via \`-p --force --trust\` pointing at the
|
|
6979
|
-
brief file
|
|
6892
|
+
brief file.
|
|
6980
6893
|
Briefs auto-inject the latest scoped lessons + newest board artifacts
|
|
6981
6894
|
(the Workbench block) so prior output compounds; --needs-by stamps a
|
|
6982
6895
|
handoff deadline on the brief DMs.
|
|
@@ -7003,7 +6916,7 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
7003
6916
|
Terminates by recorded pid, confirms death, reports. Needs your token.)
|
|
7004
6917
|
crewbus respawn --from <you> --to <worker> [--body "..."] [--force] [--fresh] [--cwd <dir>] [--cmd "..."] [--keep-env] [--allow-env ...] [--dry-run]
|
|
7005
6918
|
(reboot one DEAD worker in its SAME harness conversation: needs the
|
|
7006
|
-
captured session id (spawn-status shows it;
|
|
6919
|
+
captured session id (spawn-status shows it; respawn --fresh re-boots without prior context).
|
|
7007
6920
|
--fresh skips the resume requirement when the id can't be captured
|
|
7008
6921
|
(e.g. an opencode worker died before its log revealed anything) and
|
|
7009
6922
|
re-boots the catch-up brief as a fresh session.
|
|
@@ -7016,7 +6929,6 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
7016
6929
|
crewbus token rotate --from <you> [--expires-in <dur>]
|
|
7017
6930
|
(issue a replacement token; the old one dies immediately. New token
|
|
7018
6931
|
printed once — agent files store only a salted hash, never plaintext.
|
|
7019
|
-
Legacy plaintext 'token' files migrate on next successful auth.
|
|
7020
6932
|
--expires-in 30/90s/15m/24h/7d sets expiry; token status shows it.)
|
|
7021
6933
|
crewbus token status --from <you> [--json]
|
|
7022
6934
|
(expiry/rotation state, no secrets.)
|
|
@@ -7049,7 +6961,7 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
7049
6961
|
Surviving markers are kept, so nothing replays. Pruned ids leave
|
|
7050
6962
|
tombstones/ entries replicated via sync so deletes don't return.
|
|
7051
6963
|
Refused while a legal hold is active — see hold.)
|
|
7052
|
-
crewbus pool --from <you> --count N --pool-size S --body "..." [--harness
|
|
6964
|
+
crewbus pool --from <you> --count N --pool-size S --body "..." [--harness opencode] [--prefix p] [--queue a,b] [--json]
|
|
7053
6965
|
(lean async runner: brief N workers but boot at most S concurrently,
|
|
7054
6966
|
watch exits and auto-replace until N total. Queue backpressure refuses
|
|
7055
6967
|
when pending > 4*poolSize. State in pool-state/<id>.json, token-checked;
|
|
@@ -7120,12 +7032,10 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
7120
7032
|
--mtls-ca additionally requires verified client certs on /sync/* (mTLS,
|
|
7121
7033
|
opt-in; tunnel alternative -- plain http behind your terminator -- stays
|
|
7122
7034
|
fine). /api/spawn + /api/kill are OPT-IN (default OFF
|
|
7123
|
-
→ 403) via --allow-remote-spawn. Remote
|
|
7124
|
-
it matches --allow-cmd (default harness-only); remote cwd must sit under
|
|
7125
|
-
--workdir-root when set. Remote spawn/kill append to logs/audit.jsonl.
|
|
7035
|
+
→ 403) via --allow-remote-spawn. Remote cwd must sit under --workdir-root when set. Remote spawn/kill append to logs/audit.jsonl.
|
|
7126
7036
|
Control plane (M1): POST /api/launch validates the launch plan then
|
|
7127
7037
|
boots via the same core (same OPT-IN + secret gates; --dry-run previews
|
|
7128
|
-
without booting); GET /api/harnesses lists the
|
|
7038
|
+
without booting); GET /api/harnesses lists the 6 drivers with binary
|
|
7129
7039
|
presence; GET /api/routes + /healthz publish --advertise-routes hints;
|
|
7130
7040
|
--pair-qrcode prints a one-time crewbus://pair URL at boot (needs
|
|
7131
7041
|
--from <admin>; same mint + audit as relay pair).
|
|
@@ -7610,9 +7520,7 @@ async function cmdPool(args) {
|
|
|
7610
7520
|
if (queue.length > 4 * poolSize) fail(`pool queue full (${queue.length} > 4*poolSize ${4 * poolSize}) — raise --pool-size or shrink --count`);
|
|
7611
7521
|
let harness = String(getFlag(args, "--harness") || "opencode").toLowerCase();
|
|
7612
7522
|
if (harness === "agy") harness = "antigravity";
|
|
7613
|
-
if (!
|
|
7614
|
-
const cmd = getFlag(args, "--cmd");
|
|
7615
|
-
if (harness === "generic" && !cmd) fail('generic harness needs --cmd "..."');
|
|
7523
|
+
if (!HARNESSES.includes(harness)) fail(`unknown --harness "${harness}"`);
|
|
7616
7524
|
const maxTurnsFlag = getFlag(args, "--max-turns");
|
|
7617
7525
|
if (maxTurnsFlag !== undefined && !(Number(maxTurnsFlag) > 0)) fail("--max-turns must be a positive number");
|
|
7618
7526
|
if (maxTurnsFlag !== undefined && harness !== "claude" && harness !== "grok") fail(`--max-turns only applies to claude/grok (got --harness ${harness})`);
|
|
@@ -7629,11 +7537,11 @@ async function cmdPool(args) {
|
|
|
7629
7537
|
fs.mkdirSync(logDir, { recursive: true });
|
|
7630
7538
|
const poolId = newId("pool");
|
|
7631
7539
|
const statePath = path.join(d.root, "pool-state", `${poolId}.json`);
|
|
7632
|
-
const spawnOpts = { harness,
|
|
7540
|
+
const spawnOpts = { harness, model, auto, maxTurns: maxTurnsNum, allowTools: getFlag(args, "--allow-tools"), cwd, root: d.root, prompt: null, keepEnv: args.includes("--keep-env"), allowEnv: parseAllowEnv(getFlag(args, "--allow-env")) };
|
|
7633
7541
|
// Resumable state: queue/cursor/idByName let a later `pool resume` pick up
|
|
7634
7542
|
// supervision; spawnOpts/body/subject/rev reproduce relaunches exactly.
|
|
7635
7543
|
// `pending` stays a frozen full-queue snapshot for old readers.
|
|
7636
|
-
const state = { id: poolId, from, total: queue.length, poolSize, harness, createdAt: at, launched: 0, done: 0, active: {}, pending: queue.slice(), results: [], body: body.trim(), subject, queue: queue.slice(), cursor: 0, idByName: {}, spawnOpts: { harness,
|
|
7544
|
+
const state = { id: poolId, from, total: queue.length, poolSize, harness, createdAt: at, launched: 0, done: 0, active: {}, pending: queue.slice(), results: [], body: body.trim(), subject, queue: queue.slice(), cursor: 0, idByName: {}, spawnOpts: { harness, model, auto, maxTurns: maxTurnsNum, allowTools: getFlag(args, "--allow-tools"), cwd }, rev };
|
|
7637
7545
|
const saveState = () => {
|
|
7638
7546
|
try {
|
|
7639
7547
|
const { v, hlc } = stampSyncDoc(null);
|
|
@@ -7664,8 +7572,10 @@ async function cmdPool(args) {
|
|
|
7664
7572
|
}
|
|
7665
7573
|
};
|
|
7666
7574
|
const initial = Math.min(poolSize, queue.length);
|
|
7667
|
-
|
|
7668
|
-
|
|
7575
|
+
while (state.cursor < initial) {
|
|
7576
|
+
const next = queue[state.cursor++];
|
|
7577
|
+
launchOne(next);
|
|
7578
|
+
}
|
|
7669
7579
|
const deadline = Date.now() + POOL_SUPERVISE_MS;
|
|
7670
7580
|
while (state.done < queue.length && Date.now() < deadline) {
|
|
7671
7581
|
await new Promise((r) => setTimeout(r, 500));
|
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,17 +155,7 @@ 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
|
|
@@ -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>`);
|
|
@@ -565,7 +543,7 @@ export function ensureLoopbackOperator(d, host) {
|
|
|
565
543
|
try { recBoss = readAgent(d, "boss"); } catch { recBoss = null; }
|
|
566
544
|
try { recLead = readAgent(d, "lead"); } catch { recLead = null; }
|
|
567
545
|
if (recBoss && (recBoss.tokenHash || recBoss.token)) return null; // already provisioned
|
|
568
|
-
if (recLead &&
|
|
546
|
+
if (recLead && recLead.tokenHash) return null; // already provisioned (legacy board)
|
|
569
547
|
if (countAgentRecords(d) > 0) return null; // board already has registered agents
|
|
570
548
|
const fresh = mintToken();
|
|
571
549
|
const salt = newSalt();
|