crewbus 10.0.8 → 10.0.10
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 +22 -0
- package/README.md +41 -8
- package/bin/crewbus.js +315 -24
- package/bin/lib/identity.js +20 -14
- package/bin/lib/launch.js +4 -1
- package/bin/lib/mail.js +14 -2
- package/bin/lib/spawn.js +397 -20
- package/bin/lib/store.js +5 -3
- package/bin/lib/web.js +108 -26
- package/bin/lib/workbench.js +188 -0
- package/docs/LEAD_ASSIGN.md +75 -0
- package/docs/SPLIT.md +5 -4
- package/docs/VERSION_SKEW.md +1 -1
- package/documentation.html +366 -361
- package/index.html +7 -7
- package/package.json +2 -2
- package/packages/contracts/launch.json +4 -3
package/bin/crewbus.js
CHANGED
|
@@ -46,10 +46,11 @@ import { VALID_ROLES, agentTokenMatches, assertMintWon, authorize, authorizeChec
|
|
|
46
46
|
import { saveTokenFile } from "./lib/tokenfile.js";
|
|
47
47
|
import { CLIENT_TLS, SYNC_LWW, cleanSyncRel, clientInsecureFromArgs, crewSurvey, httpJson, readPemFlag, readSyncState, readTombstones, relayAuthEntries, relayCredFor, relayCredHeaders, setupClientTls, splitByWeight, syncRound, syncWalk, warnInsecureOnce, writeSyncState, writeTombstone, SYNC_SUBS, SYNC_UNION, RELAY_CAPS, SUB_CAP, SUB_CAP_NOTE, tombstoneIdForRel, readSyncDoc } from "./lib/sync.js";
|
|
48
48
|
import { devicePath, isLoopbackHost, newDeviceCred, newPairToken, pairingPath, parseDeviceCred, readDevice, readRelayState, relaySecretFromArgs, remoteSpawn, requireRelayClientCert, requireRelaySecret, requireScope, tryAcquireFence, verifyOidcJwt, writeRelayState, relayStatePath, bearerFromReq, getOidcConfig, getOidcJwks, b64urlDecode, b64urlJson, jwsRawToDer, oidcGetJson, OIDC_SKEW_SEC, OIDC_JWKS_TTL_MS, OIDC_ALG_HASH, OIDC_EC_SIZE, deviceFromReq } from "./lib/relay.js";
|
|
49
|
-
import { assertGitCheckout, bootRespawnedWorker, bootWorker, buildCrewContext, buildRespawnBrief, buildRespawnTarget, buildSpawnPrompt, buildSpawnTarget, formatSpawnCmd, isPidStale, killWorkers, maybeIsolate, parseAllowEnv, pidAlive, provisionBranch, provisionWorktree, readWorkerSession, requireAutoConfirm, sandboxPresent, scrubChildEnv, syncWorkerSession, workerStatus, worktreeStamp, defaultMaxTurnsFor, ensureBoardCliShim, installCliToUserPath } from "./lib/spawn.js";
|
|
49
|
+
import { assertGitCheckout, bootRespawnedWorker, bootWorker, buildCoordinatorPrompt, buildCrewContext, buildRespawnBrief, buildRespawnTarget, buildSpawnPrompt, buildSpawnTarget, formatSpawnCmd, isPidStale, killWorkers, LEAD_NAME, maybeIsolate, opencodeStorageStatus, parseAllowEnv, pidAlive, provisionAutoLead, provisionBranch, provisionWorktree, readWorkerSession, requireAutoConfirm, resolveOpencodeExe, sandboxPresent, scrubChildEnv, syncWorkerSession, workerStatus, worktreeStamp, defaultMaxTurnsFor, ensureBoardCliShim, installCliToUserPath } from "./lib/spawn.js";
|
|
50
50
|
import { appendChainRecord, auditHmacKey, boardTotalBytes, chainFilePath, countChannels, dirSize, doExportToFile, enforceAgentQuota, enforceBytesQuota, enforceChannelQuota, holdActive, holdDocPath, holdRefusal, parseQuotaBytes, parseQuotaCount, readBackupInner, readBoardQuotas, readChainRecords, readHold, readSnapshotSchedule, resolveBackupKeyMaterial, setAuditForward, snapshotStamp, startAuditForwarder, verifyChainRecords, collectBoardFiles, encryptBackupPayload, decryptBackupPayload, rawKeyFromMaterial, deriveBackupKey, toAuditExport, spoolAuditEvent, postAuditEvent, auditSpoolDir, drainAuditSpool, enqueueAuditForward, signAuditRecord, chainRecordHash, AUDIT_FORWARD_URL, AUDIT_FORWARD_KEY } from "./lib/export.js";
|
|
51
51
|
import { ackedIds, checkSendRateLimit, deliverDMs, enforceMaxChars, filterDigest, findDuplicateSend, findMessageById, heartbeat, isVerified, loadManifest, manifestPath, msgTimeMs, parseRecipients, printDigest, printMsg, readDMs, readVisible, recordBroadcastManifest, requireFanoutConfirm, resolveFwdDepth, runVerifier, verifyMessageSig, isHigh, signMessage, untrustedEnvelope, relTime, rateFilePath, broadcastTargets, readBroadcastsFor, formatTo, msgHeader, readAckMarker, splitCommand, readRecipientsFile } from "./lib/mail.js";
|
|
52
52
|
import { batchReplyIds, collectBatch, contributingGroups, expandGroups, expandGroupsOrFail, gatherTelemetry, groupTelemetryData, heuristicSenderType, readGroup, ensureGroupCreatedAt, readResultRecord, writeResultRecord, findFirstVerifiedReply } from "./lib/groups.js";
|
|
53
|
+
import { publishArtifact, adoptArtifact, verifyArtifact, readArtifactById, listArtifacts, listLessons, postLesson, selectLessons, renderWorkbenchBlock, workbenchMetrics, cleanArtifactId, cleanLessonScope, parseArtifactDeps } from "./lib/workbench.js";
|
|
53
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";
|
|
54
55
|
import { boardSnapshot, cmdWeb, escapeHtml, fleetSnapshot, channelsSnapshot, resultsSnapshot, auditSnapshot, handleApiAck, renderBoardHtml, handleApiKill, handleApiLaunch, handleWebDashboardRoute } from "./lib/web.js";
|
|
55
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";
|
|
@@ -2720,6 +2721,15 @@ function cmdSend(args) {
|
|
|
2720
2721
|
const priority = cleanPriority(getFlag(args, "--priority"));
|
|
2721
2722
|
const checkpoint = args.includes("--checkpoint");
|
|
2722
2723
|
const alsoChannel = args.includes("--also-channel");
|
|
2724
|
+
// Needs-by (L4 handoff): a deadline the sender stamps on the DM, so a
|
|
2725
|
+
// blocked peer can triage with inbox --overdue instead of re-polling.
|
|
2726
|
+
const needsByRaw = getFlag(args, "--needs-by");
|
|
2727
|
+
let needsBy;
|
|
2728
|
+
if (needsByRaw !== undefined) {
|
|
2729
|
+
const ms = parseDuration(needsByRaw);
|
|
2730
|
+
if (!(ms > 0)) fail("--needs-by must be a positive duration (e.g. 30m, 2h)");
|
|
2731
|
+
needsBy = new Date(Date.now() + ms).toISOString();
|
|
2732
|
+
}
|
|
2723
2733
|
const toGroupRaw = getFlag(args, "--to-group");
|
|
2724
2734
|
if (alsoChannel && (!toGroupRaw || !String(toGroupRaw).trim())) fail("--also-channel needs --to-group <g,...> (it mirrors the brief into each group's channel)");
|
|
2725
2735
|
const groupNames = String(toGroupRaw || "").split(",").map((s) => String(s).trim().toLowerCase().replace(/[^a-z0-9_.-]/g, "-").slice(0, 40)).filter(Boolean);
|
|
@@ -2752,7 +2762,7 @@ function cmdSend(args) {
|
|
|
2752
2762
|
const rev = gitRevForBoard(root);
|
|
2753
2763
|
const at = new Date().toISOString();
|
|
2754
2764
|
const forceBroadcast = args.includes("--broadcast");
|
|
2755
|
-
const res = deliverDMs(d, { from, recipients, body: body.trim(), subject, replyTo, artifact, priority, checkpoint, senderType, fwd, rev, at, forceBroadcast });
|
|
2765
|
+
const res = deliverDMs(d, { from, recipients, body: body.trim(), subject, replyTo, artifact, priority, checkpoint, senderType, fwd, rev, at, forceBroadcast, needsBy });
|
|
2756
2766
|
appendChainRecord(d, from, "send", { to: recipients.slice(0, 20), count: recipients.length, batch: res.batch });
|
|
2757
2767
|
const mirrored = alsoChannel
|
|
2758
2768
|
? mirrorToGroupChannels(d, { groups: groupNames, from, body: body.trim(), subject, replyTo, batch: res.batch || (res.items[0] && res.items[0].id), priority, rev, at })
|
|
@@ -2883,7 +2893,30 @@ function cmdSpawn(args) {
|
|
|
2883
2893
|
rosterGroups.sort((a, b) => String(a.name).localeCompare(String(b.name)));
|
|
2884
2894
|
const taskGroups = rosterGroups.filter((g) => groupNames.includes(g.name));
|
|
2885
2895
|
const offTask = rosterGroups.length - taskGroups.length;
|
|
2886
|
-
const crewFor = (to) => buildCrewContext({ name: to, from, subject, groups: taskGroups, myGroups: taskGroups.filter((g) => g.members.includes(to)).map((g) => g.name), offTask });
|
|
2896
|
+
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 });
|
|
2897
|
+
// Lead auto-assignment (§auto-lead): `--lead auto|board|none` (default: auto).
|
|
2898
|
+
// Under `board` (or `auto` with a coding harness), spawn and lead are
|
|
2899
|
+
// separated: workers pin replies to the board's standing 'lead' lane and a
|
|
2900
|
+
// detached persistent coordinator is provisioned after the crew boots; the
|
|
2901
|
+
// spawner stays boss (reads, milestone DMs). `--lead none` (or `auto` with
|
|
2902
|
+
// purely generic harnesses) is the legacy star topology: replies pin to the
|
|
2903
|
+
// spawner, nothing else is provisioned.
|
|
2904
|
+
const leadFlagRaw = getFlag(args, "--lead");
|
|
2905
|
+
const hasCodingHarness = harnesses.some((h) => h !== "generic");
|
|
2906
|
+
let leadMode;
|
|
2907
|
+
if (leadFlagRaw === undefined) {
|
|
2908
|
+
leadMode = hasCodingHarness ? "board" : "none";
|
|
2909
|
+
} else {
|
|
2910
|
+
leadMode = String(leadFlagRaw).trim().toLowerCase();
|
|
2911
|
+
if (leadMode === "auto") {
|
|
2912
|
+
leadMode = hasCodingHarness ? "board" : "none";
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
if (!["board", "none"].includes(leadMode)) fail(`invalid --lead "${leadFlagRaw}" (want auto|board|none)`);
|
|
2916
|
+
if (leadMode === "board" && !hasCodingHarness) {
|
|
2917
|
+
fail('--lead board needs a coding harness for the auto-coordinator (add --harness opencode, or pass --lead none under --harness generic)');
|
|
2918
|
+
}
|
|
2919
|
+
const leadTarget = leadMode === "board" ? "lead" : from;
|
|
2887
2920
|
const model = getFlag(args, "--model");
|
|
2888
2921
|
const auto = args.includes("--auto");
|
|
2889
2922
|
requireAutoConfirm(args);
|
|
@@ -2921,6 +2954,24 @@ function cmdSpawn(args) {
|
|
|
2921
2954
|
if (!(ms > 0)) fail("--timeout must be a positive duration (e.g. 10m)");
|
|
2922
2955
|
deadlineAt = new Date(Date.now() + ms).toISOString();
|
|
2923
2956
|
}
|
|
2957
|
+
// Needs-by (L4 handoff): deadline stamped on the brief DMs, so leads can
|
|
2958
|
+
// spot unclaimed/overdue briefs with inbox --overdue --unacked.
|
|
2959
|
+
const needsByRaw = getFlag(args, "--needs-by");
|
|
2960
|
+
let needsBy;
|
|
2961
|
+
if (needsByRaw !== undefined) {
|
|
2962
|
+
const ms = parseDuration(needsByRaw);
|
|
2963
|
+
if (!(ms > 0)) fail("--needs-by must be a positive duration (e.g. 30m, 2h)");
|
|
2964
|
+
needsBy = new Date(Date.now() + ms).toISOString();
|
|
2965
|
+
}
|
|
2966
|
+
// Workbench (L2/L3): lessons scoped to this spawn's groups (+global) and
|
|
2967
|
+
// the newest board artifacts, rendered once per worker so the brief
|
|
2968
|
+
// carries prior output instead of re-deriving it.
|
|
2969
|
+
const wbFor = (to) =>
|
|
2970
|
+
renderWorkbenchBlock({
|
|
2971
|
+
lessons: selectLessons(d, { scopes: groupNames, limit: 8 }),
|
|
2972
|
+
artifacts: listArtifacts(d, { limit: 6 }),
|
|
2973
|
+
me: to,
|
|
2974
|
+
});
|
|
2924
2975
|
const isolateInfo = maybeIsolate(args, d.root);
|
|
2925
2976
|
if ((worktreePrefix !== undefined || branchPrefix !== undefined) && !dry) assertGitCheckout(cwd);
|
|
2926
2977
|
const minted = ensureSender(d, from, resolveToken(args));
|
|
@@ -2939,17 +2990,34 @@ function cmdSpawn(args) {
|
|
|
2939
2990
|
const driver = harnesses[i % harnesses.length];
|
|
2940
2991
|
const itemMaxTurns = maxTurnsNum !== undefined ? maxTurnsNum : ((driver === "claude" || driver === "grok") ? 50 : undefined);
|
|
2941
2992
|
const itemSpawnOpts = { ...spawnOpts, harness: driver, maxTurns: itemMaxTurns, allowTools: driver === "claude" ? allowTools : undefined };
|
|
2942
|
-
const previewPrompt = buildSpawnPrompt({ name: to, from, subject, body: body.trim(), replyId: previewBatch || "msg-<id>", rev, cwd, root, crew: crewFor(to) });
|
|
2993
|
+
const previewPrompt = buildSpawnPrompt({ name: to, from, lead: leadTarget, subject, body: body.trim(), replyId: previewBatch || "msg-<id>", rev, cwd, root, crew: crewFor(to, leadTarget), workbench: wbFor(to) });
|
|
2943
2994
|
const t = buildSpawnTarget({ ...itemSpawnOpts, name: to, promptPath: `<logs>/${to}-<stamp>.prompt.md`, prompt: previewPrompt });
|
|
2944
2995
|
const wtNote = worktreePrefix !== undefined ? ` worktree ../${to}-<stamp> (branch ${worktreePrefix}/${to}-<stamp>)` : branchPrefix !== undefined ? ` branch ${branchPrefix}/${to}-<stamp>` : "";
|
|
2945
2996
|
console.log(`would spawn ${to} [${driver}] (${lifetime}) cwd ${cwd}${wtNote} cmd: ${formatSpawnCmd(t)} [board ${d.root}]`);
|
|
2946
2997
|
});
|
|
2947
|
-
console.log(`--- prompt (first worker) ---\n${buildSpawnPrompt({ name: recipients[0], from, subject, body: body.trim(), replyId: previewBatch || "msg-<id>", rev, cwd, root, crew: crewFor(recipients[0]) })}`);
|
|
2998
|
+
console.log(`--- prompt (first worker) ---\n${buildSpawnPrompt({ name: recipients[0], from, lead: leadTarget, subject, body: body.trim(), replyId: previewBatch || "msg-<id>", rev, cwd, root, crew: crewFor(recipients[0], leadTarget), workbench: wbFor(recipients[0]) })}`);
|
|
2999
|
+
if (leadMode === "board") {
|
|
3000
|
+
const existingLead = readAgent(d, "lead");
|
|
3001
|
+
const standing = existingLead && typeof existingLead.spawnedPid === "number" && pidAlive(existingLead.spawnedPid);
|
|
3002
|
+
if (standing) {
|
|
3003
|
+
console.log(`--- lead ---\na live coordinator already runs on the 'lead' lane (pid ${existingLead.spawnedPid}) — reused, not duplicated [board ${d.root}]`);
|
|
3004
|
+
} else if (existingLead && existingLead.offboarded) {
|
|
3005
|
+
console.log(`--- lead ---\nlane "lead" is offboarded: provision would be SKIPPED (re-onboard it, or pass --lead none) [board ${d.root}]`);
|
|
3006
|
+
} else {
|
|
3007
|
+
const coordPreview = buildCoordinatorPrompt({
|
|
3008
|
+
name: "lead", from, subject, body: body.trim(), batch: previewBatch,
|
|
3009
|
+
workers: recipients.map((name, i) => ({ name, id: previewBatch ? `${previewBatch}-${i + 1}` : "msg-<id>", harness: harnesses[i % harnesses.length] })),
|
|
3010
|
+
crew: crewFor(recipients[0], leadTarget), cwd, root, auto, workbench: wbFor(recipients[0]),
|
|
3011
|
+
});
|
|
3012
|
+
console.log(`--- lead ---\nwould spawn lead [${harnesses[0]}] (persistent — auto-provisioned lead, owner of this crew) cwd ${cwd} [board ${d.root}]`);
|
|
3013
|
+
console.log(`--- coordinator prompt (preview) ---\n${coordPreview}`);
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
2948
3016
|
return;
|
|
2949
3017
|
}
|
|
2950
3018
|
// Direct (N-copy) path is forced here (every worker needs its own message
|
|
2951
3019
|
// id to thread the reply against) — --broadcast is not accepted by spawn.
|
|
2952
|
-
const res = deliverDMs(d, { from, recipients, body: body.trim(), subject, replyTo, priority, senderType, fwd, rev, at, forceBroadcast: false, forceDirect: true });
|
|
3020
|
+
const res = deliverDMs(d, { from, recipients, body: body.trim(), subject, replyTo, priority, senderType, fwd, rev, at, forceBroadcast: false, forceDirect: true, needsBy });
|
|
2953
3021
|
if (res.mode !== "direct") fail("spawn: internal error — expected direct delivery");
|
|
2954
3022
|
appendChainRecord(d, from, "spawn", { to: recipients.slice(), harness, harnesses, auto, cwd, isolate: isolateInfo.isolated || false, budgetTokens, budgetMinutes, deadlineAt });
|
|
2955
3023
|
if (alsoChannel) {
|
|
@@ -2978,13 +3046,38 @@ function cmdSpawn(args) {
|
|
|
2978
3046
|
} else if (branchPrefix !== undefined) {
|
|
2979
3047
|
workerBranch = provisionBranch(cwd, branchPrefix, to).branch;
|
|
2980
3048
|
}
|
|
2981
|
-
const r = bootWorker(d, { ...itemSpawnOpts, cwd: workerCwd }, { to, id, from, subject, body: body.trim(), rev, logDir, budgetTokens, budgetMinutes, deadlineAt, spawnedWorktree: workerWorktree, spawnedBranch: workerBranch, spawnedLifetime: lifetime, crew: crewFor(to) });
|
|
3049
|
+
const r = bootWorker(d, { ...itemSpawnOpts, cwd: workerCwd }, { to, id, from, lead: leadTarget, subject, body: body.trim(), rev, logDir, budgetTokens, budgetMinutes, deadlineAt, spawnedWorktree: workerWorktree, spawnedBranch: workerBranch, spawnedLifetime: lifetime, crew: crewFor(to, leadTarget), workbench: wbFor(to) });
|
|
2982
3050
|
const where = workerWorktree ? ` worktree ${workerWorktree}` : workerBranch ? ` branch ${workerBranch}` : "";
|
|
2983
3051
|
console.log(`spawned ${to} pid ${r.pid} [${driver}] (${lifetime}) log ${r.logPath} reply ${id}${where} [board ${d.root}]`);
|
|
2984
3052
|
} catch (e) {
|
|
2985
3053
|
console.log(`spawn FAILED ${to}: ${e.message} (brief ${id} still waits on the board) [board ${d.root}]`);
|
|
2986
3054
|
}
|
|
2987
3055
|
}
|
|
3056
|
+
// Auto-provisioned lead: runs after the crew boots so the coordinator's
|
|
3057
|
+
// roster carries the real brief ids, and so a lead boot failure can never
|
|
3058
|
+
// block worker boots.
|
|
3059
|
+
if (leadMode === "board") {
|
|
3060
|
+
const coordHarness = [ // first coding harness wins; generic is excluded above
|
|
3061
|
+
...harnesses.filter((h) => h !== "generic"),
|
|
3062
|
+
][0] || "opencode";
|
|
3063
|
+
const provision = provisionAutoLead(d, {
|
|
3064
|
+
spawnOpts: { ...spawnOpts, harness: coordHarness, maxTurns: undefined, allowTools: undefined },
|
|
3065
|
+
from, subject, body: body.trim(), rev, logDir,
|
|
3066
|
+
workers: res.items.map((it, i) => ({ name: it.to, id: it.id, harness: harnesses[i % harnesses.length] })),
|
|
3067
|
+
batch: res.batch, crew: crewFor(recipients[0], leadTarget), workbench: wbFor(recipients[0]), auto,
|
|
3068
|
+
});
|
|
3069
|
+
if (provision.action === "minted" && provision.pid) {
|
|
3070
|
+
console.log(`auto-lead provisioned: minted lane '${provision.leadName}' (role lead — owns this crew), coordinator pid ${provision.pid} (persistent, ${coordHarness}) log ${provision.logPath} [board ${d.root}]`);
|
|
3071
|
+
if (provision.token) console.log(`lead token (set CREWBUS_TOKEN=${provision.token} to act as '${provision.leadName}'): also saved to logs/lead.token`);
|
|
3072
|
+
} else if (provision.action === "minted") {
|
|
3073
|
+
console.log(`auto-lead provisioned with a caveat: ${provision.reason} [board ${d.root}]`);
|
|
3074
|
+
} else if (provision.action === "reused") {
|
|
3075
|
+
const standing = provision.pid ? `coordinator pid ${provision.pid} (standing)` : `claimed, no live coordinator — boot with: spawn --from ${from} --to ${provision.leadName} --persistent --body "you are the lead, read your crew"`;
|
|
3076
|
+
console.log(`auto-lead reused: '${provision.leadName}' lane (${standing}); this crew transferred to it (${provision.transferred} worker(s)) [board ${d.root}]`);
|
|
3077
|
+
} else {
|
|
3078
|
+
console.log(`auto-lead SKIPPED: ${provision.reason || "no reason recorded"} [board ${d.root}]`);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
2988
3081
|
}
|
|
2989
3082
|
|
|
2990
3083
|
// Control-plane M1: `launch` validates the plan against
|
|
@@ -3302,6 +3395,10 @@ async function cmdRespawn(args) {
|
|
|
3302
3395
|
const name = names[0];
|
|
3303
3396
|
const force = args.includes("--force");
|
|
3304
3397
|
const dry = args.includes("--dry-run");
|
|
3398
|
+
// --fresh: when the harness session id was never captured (opencode kills
|
|
3399
|
+
// its buffered output before the log scan can read it), skip the resume
|
|
3400
|
+
// requirement and boot the catch-up brief fresh — same as the generic path.
|
|
3401
|
+
const fresh = args.includes("--fresh");
|
|
3305
3402
|
const extraBody = getFlag(args, "--body");
|
|
3306
3403
|
if (extraBody !== undefined && String(extraBody).length > MAX_BODY_CHARS) fail(`message body too large (max ${MAX_BODY_CHARS} chars)`);
|
|
3307
3404
|
const minted = ensureSender(d, from, resolveToken(args));
|
|
@@ -3317,7 +3414,7 @@ async function cmdRespawn(args) {
|
|
|
3317
3414
|
const harness = prev.harness;
|
|
3318
3415
|
if (!harness) fail(`no harness recorded for "${name}" (spawned before session capture — re-boot fresh with spawn --to ${name})`);
|
|
3319
3416
|
const sessionId = prev.harnessSessionId;
|
|
3320
|
-
if (!sessionId && harness !== "generic") 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>"} or spawn a fresh worker`);
|
|
3417
|
+
if (!sessionId && harness !== "generic" && !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`);
|
|
3321
3418
|
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)`);
|
|
3322
3419
|
if (args.includes("--auto")) requireAutoConfirm(args);
|
|
3323
3420
|
if (!prev.promptPath) fail(`no original prompt on record for "${name}" (spawned before prompt capture — re-boot fresh with spawn --to ${name})`);
|
|
@@ -3501,13 +3598,136 @@ function cmdGather(args) {
|
|
|
3501
3598
|
if (!res) fail(`unknown batch "${batch}" (check send echoes / inbox batch lines)`);
|
|
3502
3599
|
const groups = contributingGroups(d, res.items);
|
|
3503
3600
|
const tele = gatherTelemetry(res.items);
|
|
3601
|
+
// Workbench metrics: did any downstream message consume an upstream
|
|
3602
|
+
// artifact (feed-forward edge), and how much of it held up (adopted/
|
|
3603
|
+
// verified). This is the multiplicative-discovery measure — additive
|
|
3604
|
+
// crews score 0 across the board.
|
|
3605
|
+
const wb = workbenchMetrics(res.items, (id) => readArtifactById(d, id));
|
|
3504
3606
|
if (json) {
|
|
3505
|
-
console.log(JSON.stringify({ ...res, contributingGroups: groups, telemetry: tele }, null, 2));
|
|
3607
|
+
console.log(JSON.stringify({ ...res, contributingGroups: groups, telemetry: tele, workbench: wb }, null, 2));
|
|
3506
3608
|
return;
|
|
3507
3609
|
}
|
|
3508
3610
|
console.log(`batch ${batch}: ${res.briefs} brief(s), ${res.replies} replies [board ${d.root}]\n`);
|
|
3509
3611
|
for (const m of res.items) printMsg(m, true, false);
|
|
3510
3612
|
console.log(`-- telemetry: ${tele.messages} msgs, ~${tele.tokensEst} tokens (chars/4), contributing groups: ${groups.join(",") || "none"} --`);
|
|
3613
|
+
if (wb.artifactRefs > 0) {
|
|
3614
|
+
console.log(`-- workbench: ${wb.artifactRefs} artifact(s) referenced, ${wb.feedForward} feed-forward edge(s), ${wb.adopted} adopted, ${wb.verified} verified --`);
|
|
3615
|
+
} else {
|
|
3616
|
+
console.log(`-- workbench: no artifacts referenced (additive shape; publish with: crewbus artifact publish --path <p>) --`);
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
|
|
3620
|
+
// artifact: board objects for worker output that should outlive the DM
|
|
3621
|
+
// thread (L2). publish|list|show|adopt|verify — adoption + verification
|
|
3622
|
+
// land ON the object, so a later crew can see what was reused and what
|
|
3623
|
+
// held up instead of re-deriving it from prose.
|
|
3624
|
+
function cmdArtifact(args) {
|
|
3625
|
+
const root = boardDir(args);
|
|
3626
|
+
refuseDriveRootBoard(root, args);
|
|
3627
|
+
const d = requireBoard(root);
|
|
3628
|
+
const json = args.includes("--json");
|
|
3629
|
+
const sub = String(args[0] || "").toLowerCase();
|
|
3630
|
+
const rest = args.slice(1);
|
|
3631
|
+
const token = resolveToken(rest);
|
|
3632
|
+
const ensureWriter = () => {
|
|
3633
|
+
const from = resolveAgent(rest, "sender");
|
|
3634
|
+
ensureSender(d, from, token);
|
|
3635
|
+
authorize(d, from, "artifact-write", {});
|
|
3636
|
+
return from;
|
|
3637
|
+
};
|
|
3638
|
+
if (sub === "publish") {
|
|
3639
|
+
const from = ensureWriter();
|
|
3640
|
+
const deps = parseArtifactDeps(getFlag(rest, "--deps"));
|
|
3641
|
+
const doc = publishArtifact(d, { from, ref: getFlag(rest, "--path"), summary: getFlag(rest, "--summary"), deps, at: new Date().toISOString() });
|
|
3642
|
+
appendChainRecord(d, from, "artifact-publish", { id: doc.id });
|
|
3643
|
+
console.log(`published artifact ${doc.id} (${doc.path})${doc.deps.length ? ` deps: ${doc.deps.join(",")}` : ""} [board ${d.root}]`);
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
if (sub === "adopt" || sub === "verify") {
|
|
3647
|
+
const from = ensureWriter();
|
|
3648
|
+
const id = cleanArtifactId(getFlag(rest, "--id"));
|
|
3649
|
+
const at = new Date().toISOString();
|
|
3650
|
+
const note = getFlag(rest, "--note");
|
|
3651
|
+
const doc = sub === "adopt" ? adoptArtifact(d, { id, from, at, note }) : verifyArtifact(d, { id, from, at, note });
|
|
3652
|
+
appendChainRecord(d, from, sub === "adopt" ? "artifact-adopt" : "artifact-verify", { id });
|
|
3653
|
+
const n = sub === "adopt" ? doc.adoptedBy.length : doc.verifiedBy.length;
|
|
3654
|
+
console.log(`${sub === "adopt" ? "adopted" : "verified"} ${id} by ${from} (${n} total) [board ${d.root}]`);
|
|
3655
|
+
return;
|
|
3656
|
+
}
|
|
3657
|
+
if (sub === "show") {
|
|
3658
|
+
const id = cleanArtifactId(getFlag(rest, "--id"));
|
|
3659
|
+
const a = readArtifactById(d, id);
|
|
3660
|
+
if (!a) fail(`unknown artifact ${id} [board ${d.root}]`);
|
|
3661
|
+
if (json) {
|
|
3662
|
+
console.log(JSON.stringify(a, null, 2));
|
|
3663
|
+
return;
|
|
3664
|
+
}
|
|
3665
|
+
console.log(`artifact ${a.id}`);
|
|
3666
|
+
console.log(` path: ${a.path}`);
|
|
3667
|
+
if (a.summary) console.log(` summary: ${a.summary}`);
|
|
3668
|
+
console.log(` producer: ${a.from} @ ${a.at}`);
|
|
3669
|
+
if (a.deps.length) console.log(` deps: ${a.deps.join(", ")}`);
|
|
3670
|
+
console.log(` adopted by: ${a.adoptedBy.map((e) => e.by).join(", ") || "(nobody)"}`);
|
|
3671
|
+
console.log(` verified by: ${a.verifiedBy.map((e) => e.by).join(", ") || "(nobody)"}`);
|
|
3672
|
+
return;
|
|
3673
|
+
}
|
|
3674
|
+
if (sub === "list" || sub === "") {
|
|
3675
|
+
const all = listArtifacts(d);
|
|
3676
|
+
if (json) {
|
|
3677
|
+
console.log(JSON.stringify(all, null, 2));
|
|
3678
|
+
return;
|
|
3679
|
+
}
|
|
3680
|
+
if (all.length === 0) {
|
|
3681
|
+
console.log(`no artifacts [board ${d.root}]`);
|
|
3682
|
+
return;
|
|
3683
|
+
}
|
|
3684
|
+
for (const a of all) {
|
|
3685
|
+
const state = [];
|
|
3686
|
+
if (a.adoptedBy.length) state.push(`adopted x${a.adoptedBy.length}`);
|
|
3687
|
+
if (a.verifiedBy.length) state.push("verified");
|
|
3688
|
+
console.log(`${a.id} ${a.path}${state.length ? ` (${state.join(", ")})` : ""}`);
|
|
3689
|
+
}
|
|
3690
|
+
return;
|
|
3691
|
+
}
|
|
3692
|
+
fail(`unknown artifact subcommand "${sub}" (want publish|list|show|adopt|verify)`);
|
|
3693
|
+
}
|
|
3694
|
+
|
|
3695
|
+
// lesson: one-or-two-line learnings scoped to a group/task; post|list.
|
|
3696
|
+
// New spawn briefs with a matching scope (or global) auto-inject the
|
|
3697
|
+
// latest lessons, so a lesson learned once is paid forward (L3).
|
|
3698
|
+
function cmdLesson(args) {
|
|
3699
|
+
const root = boardDir(args);
|
|
3700
|
+
refuseDriveRootBoard(root, args);
|
|
3701
|
+
const d = requireBoard(root);
|
|
3702
|
+
const json = args.includes("--json");
|
|
3703
|
+
const sub = String(args[0] || "").toLowerCase();
|
|
3704
|
+
const rest = args.slice(1);
|
|
3705
|
+
const token = resolveToken(rest);
|
|
3706
|
+
if (sub === "post") {
|
|
3707
|
+
const from = resolveAgent(rest, "sender");
|
|
3708
|
+
ensureSender(d, from, token);
|
|
3709
|
+
authorize(d, from, "lesson-write", {});
|
|
3710
|
+
const doc = postLesson(d, { from, scope: getFlag(rest, "--scope"), text: getFlag(rest, "--text"), at: new Date().toISOString() });
|
|
3711
|
+
appendChainRecord(d, from, "lesson-post", { id: doc.id, scope: doc.scope });
|
|
3712
|
+
console.log(`lesson ${doc.id} [${doc.scope}] (later spawns in scope ${doc.scope} get it injected) [board ${d.root}]`);
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3715
|
+
if (sub === "list" || sub === "") {
|
|
3716
|
+
const scopeRaw = getFlag(args, "--scope");
|
|
3717
|
+
const scope = scopeRaw !== undefined ? cleanLessonScope(scopeRaw) : undefined;
|
|
3718
|
+
const items = listLessons(d, { scope });
|
|
3719
|
+
if (json) {
|
|
3720
|
+
console.log(JSON.stringify(items, null, 2));
|
|
3721
|
+
return;
|
|
3722
|
+
}
|
|
3723
|
+
if (items.length === 0) {
|
|
3724
|
+
console.log(`no lessons${scope ? ` scoped ${scope}` : ""} [board ${d.root}]`);
|
|
3725
|
+
return;
|
|
3726
|
+
}
|
|
3727
|
+
for (const l of items) console.log(`${l.id} [${l.scope}] ${l.text}`);
|
|
3728
|
+
return;
|
|
3729
|
+
}
|
|
3730
|
+
fail(`unknown lesson subcommand "${sub}" (want post|list)`);
|
|
3511
3731
|
}
|
|
3512
3732
|
|
|
3513
3733
|
function cmdInbox(args) {
|
|
@@ -3520,6 +3740,7 @@ function cmdInbox(args) {
|
|
|
3520
3740
|
const json = args.includes("--json");
|
|
3521
3741
|
let items;
|
|
3522
3742
|
let showTo = false;
|
|
3743
|
+
let acked = null;
|
|
3523
3744
|
if (showAll) {
|
|
3524
3745
|
items = [];
|
|
3525
3746
|
let subs = [];
|
|
@@ -3554,7 +3775,7 @@ function cmdInbox(args) {
|
|
|
3554
3775
|
authorize(d, agent, "inbox"); // reads allow all roles (auditor read-ok)
|
|
3555
3776
|
heartbeat(d, agent, 0); // reading your mail proves you're alive
|
|
3556
3777
|
items = readVisible(d, agent);
|
|
3557
|
-
|
|
3778
|
+
acked = ackedIds(d, agent);
|
|
3558
3779
|
if (json) {
|
|
3559
3780
|
items = items.map((m) => (acked.has(m.id) ? { ...m, acked: true } : m));
|
|
3560
3781
|
}
|
|
@@ -3563,6 +3784,12 @@ function cmdInbox(args) {
|
|
|
3563
3784
|
items = items.filter((m) => !acked.has(m.id) && m.checkpoint !== true);
|
|
3564
3785
|
}
|
|
3565
3786
|
}
|
|
3787
|
+
// Overdue triage (L4): messages whose --needs-by deadline passed and that
|
|
3788
|
+
// are still open work (not acked, not checkpoints). In --all mode there is
|
|
3789
|
+
// no ack state to consult — deadline alone decides.
|
|
3790
|
+
if (args.includes("--overdue")) {
|
|
3791
|
+
items = items.filter((m) => m.checkpoint !== true && (m.needsBy && !Number.isNaN(Date.parse(m.needsBy)) && Date.parse(m.needsBy) < Date.now()) && (showAll || !acked.has(m.id)));
|
|
3792
|
+
}
|
|
3566
3793
|
if (after) {
|
|
3567
3794
|
const idx = items.findIndex((m) => m.id === after);
|
|
3568
3795
|
if (idx !== -1) items = items.slice(idx + 1);
|
|
@@ -4331,6 +4558,7 @@ function cmdDoctor(args) {
|
|
|
4331
4558
|
console.log(`FAIL ${label}${hint ? ` — ${hint}` : ""}`);
|
|
4332
4559
|
};
|
|
4333
4560
|
const info = (label) => console.log(`info ${label}`);
|
|
4561
|
+
const warn = (label) => console.log(`warn ${label}`);
|
|
4334
4562
|
|
|
4335
4563
|
const nodeMajor = Number(String(process.version).replace(/^v/, "").split(".")[0]);
|
|
4336
4564
|
if (nodeMajor >= 18) ok(`node ${process.version} (>= 18)`);
|
|
@@ -4424,6 +4652,41 @@ function cmdDoctor(args) {
|
|
|
4424
4652
|
else no("opencode tool .opencode/tools/dm-send.js", "run: crewbus init --harness opencode (then restart opencode)");
|
|
4425
4653
|
if (fs.existsSync(path.join(cwd, ".opencode", "plugins", "dm-watch.js"))) ok("opencode plugin .opencode/plugins/dm-watch.js");
|
|
4426
4654
|
else no("opencode plugin .opencode/plugins/dm-watch.js", "run: crewbus init --harness opencode (then restart opencode)");
|
|
4655
|
+
// Binary + schema sanity for the respawn capture path (only when the
|
|
4656
|
+
// harness is actually installed): the log stream the session-id
|
|
4657
|
+
// capture reads (--format json events) and the storage-fallback DB.
|
|
4658
|
+
// --help is captured through a file descriptor, not a pipe —
|
|
4659
|
+
// opencode drops output onto some piped stdios (first-byte quirk).
|
|
4660
|
+
{
|
|
4661
|
+
const exe = resolveOpencodeExe();
|
|
4662
|
+
if (exe) {
|
|
4663
|
+
info(`opencode binary ${exe} (direct spawn, no shim)`);
|
|
4664
|
+
try {
|
|
4665
|
+
const helpFile = path.join(os.tmpdir(), `crewbus-oc-help-${process.pid}.txt`);
|
|
4666
|
+
let fd;
|
|
4667
|
+
try {
|
|
4668
|
+
fd = fs.openSync(helpFile, "w");
|
|
4669
|
+
execFileSync(exe, ["run", "--help"], { stdio: ["ignore", fd, fd], timeout: 15000 });
|
|
4670
|
+
} finally {
|
|
4671
|
+
try { fs.closeSync(fd); } catch {}
|
|
4672
|
+
}
|
|
4673
|
+
let h = "";
|
|
4674
|
+
try { h = fs.readFileSync(helpFile, "utf8"); } catch {}
|
|
4675
|
+
try { fs.rmSync(helpFile, { force: true }); } catch {}
|
|
4676
|
+
if (h.includes("--format") && /\bjson\b/.test(h)) ok("opencode run --help exposes --format json (capture flag present)");
|
|
4677
|
+
else no("opencode run --help flags", `--format json not offered by this opencode build — schema drift; session-id capture may not work (bin ${exe})`);
|
|
4678
|
+
} catch (e) {
|
|
4679
|
+
const detail = String((e && (e.message || e.stderr)) || e).slice(0, 120);
|
|
4680
|
+
no("opencode run --help", `could not run the resolved binary ${exe}: ${detail}`);
|
|
4681
|
+
}
|
|
4682
|
+
const st = opencodeStorageStatus();
|
|
4683
|
+
if (st.status === "ok") ok(`opencode storage DB session table readable ${st.dbPath}`);
|
|
4684
|
+
else if (st.status === "no-db") warn(`opencode storage DB not found (${st.dbPath}) — respawn capture limited to log scan`);
|
|
4685
|
+
else if (st.status === "no-sqlite") warn(`node:sqlite unavailable (needs Node >= 22) — respawn capture limited to log scan`);
|
|
4686
|
+
else if (st.status === "drift") no(`opencode storage DB session table ${st.dbPath}`, "schema drift — storage fallback cannot read session rows; update crewbus");
|
|
4687
|
+
else warn(`opencode storage DB unreadable (${st.detail || "transient lock"}) — respawn capture falls back to log scan`);
|
|
4688
|
+
}
|
|
4689
|
+
}
|
|
4427
4690
|
break;
|
|
4428
4691
|
case "claude": {
|
|
4429
4692
|
if (hasHookRef(path.join(cwd, ".claude", "settings.json"), ["SessionStart", "Stop"])) ok("claude hooks .claude/settings.json");
|
|
@@ -6350,7 +6613,7 @@ Identity (first claim wins, token after that):
|
|
|
6350
6613
|
the CLI, not local file tampering — separate boards per trust zone.)
|
|
6351
6614
|
|
|
6352
6615
|
Messaging (primitive — just a tool call, whenever you want):
|
|
6353
|
-
crewbus send --from <you> --to <peer> --body "..." [--subject "..."] [--reply <msg-id>] [--artifact <path-or-url>] [--priority high|normal] [--checkpoint] [--session <id>] [--to-file <path>] [--broadcast] [--also-channel] [--sender-type human|lead|peer] [--fwd <n>] [--yes] [--no-rate-limit]
|
|
6616
|
+
crewbus send --from <you> --to <peer> --body "..." [--subject "..."] [--reply <msg-id>] [--artifact <path-or-url>] [--priority high|normal] [--checkpoint] [--needs-by 30m] [--session <id>] [--to-file <path>] [--broadcast] [--also-channel] [--sender-type human|lead|peer] [--fwd <n>] [--yes] [--no-rate-limit]
|
|
6354
6617
|
(--to accepts a comma list for broadcast: --to alice,bob,carol — one DM
|
|
6355
6618
|
each, same brief, shared batch id, up to 10000 recipients; --to-file reads
|
|
6356
6619
|
the list from a file for large fan-outs; --to @all reaches every
|
|
@@ -6360,6 +6623,8 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6360
6623
|
addresses named groups (same thing in spawn); unknown groups fail loudly.
|
|
6361
6624
|
--priority high flags urgent mail (inbox --priority filters it).
|
|
6362
6625
|
--checkpoint marks a progress note on a thread (labeled in transcripts, skipped by --unacked and spawn-status reply detection — never needs ack).
|
|
6626
|
+
--needs-by stamps a handoff deadline on the DM (inbox --overdue lists
|
|
6627
|
+
it once the deadline passes, so open work is never silently stale).
|
|
6363
6628
|
--also-channel (with --to-group) also appends the brief to each group's
|
|
6364
6629
|
channel, stamped with the DM batch id so gather picks it up.)
|
|
6365
6630
|
crewbus channel create|post|tail|search|summarize|list <name> [--body "..."] [--from <you>] [--limit 20] [--cursor <msg-id>] [--grep <pattern>] [--priority high|normal] [--max-chars <n>] [--digest] [--json]
|
|
@@ -6402,13 +6667,29 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6402
6667
|
crewbus gather --batch <batch-id> [--json]
|
|
6403
6668
|
(the reduce step: the brief(s) plus every reply, across inboxes, oldest
|
|
6404
6669
|
first — one transcript to aggregate, summarize, or feed a reducer agent.
|
|
6405
|
-
Footer shows telemetry + contributing groups
|
|
6670
|
+
Footer shows telemetry + contributing groups, plus workbench metrics
|
|
6671
|
+
(artifacts referenced, feed-forward edges, adopted/verified counts) —
|
|
6672
|
+
additive crews score 0, feed-forward crews score >0.
|
|
6406
6673
|
Group-channel mirrors (send --also-channel) carrying the batch join as briefs.)
|
|
6407
|
-
crewbus
|
|
6674
|
+
crewbus artifact publish|list|show|adopt|verify [--path <path-or-url>] [--summary "..."] [--deps <id,id>] [--id <artifact-id>] [--note "..."] [--from <you>] [--json]
|
|
6675
|
+
(board objects for worker output that should outlive the DM thread:
|
|
6676
|
+
publish a path/url + one-line summary, chain pieces with --deps,
|
|
6677
|
+
adopt when you reuse one, verify when you checked it holds up.
|
|
6678
|
+
adoption/verification record ON the object; later spawn briefs list
|
|
6679
|
+
the newest artifacts, so prior output compounds instead of being
|
|
6680
|
+
re-derived. publish/adopt/verify need your token; reads are open.)
|
|
6681
|
+
crewbus lesson post|list [--scope <group-or-task>] [--text "..."] [--from <you>] [--json]
|
|
6682
|
+
(scoped one-or-two-line learnings: what happened + what to do
|
|
6683
|
+
differently. Later spawn briefs whose groups (or --scope-less/global)
|
|
6684
|
+
match auto-inject the latest lessons, so a lesson learned once is
|
|
6685
|
+
paid forward. post needs your token; list is open.)
|
|
6686
|
+
crewbus inbox --from <you> [--limit 20] [--after <msg-id>] [--all] [--unacked] [--overdue] [--older-than 10m] [--grep <pattern>] [--priority high|normal] [--max-chars <n>] [--digest] [--verify] [--json]
|
|
6408
6687
|
(--older-than keeps only messages older than the window: inbox --unacked
|
|
6409
6688
|
--older-than 10m lists briefs nobody picked up (retry via redeliver or
|
|
6410
|
-
re-send). --
|
|
6411
|
-
--
|
|
6689
|
+
re-send). --overdue lists still-open briefs whose --needs-by deadline
|
|
6690
|
+
passed (skip in --all mode where ack state doesn't apply). --grep
|
|
6691
|
+
filters subject+body, --priority filters urgency, --max-chars
|
|
6692
|
+
fair-share truncates bodies with [truncated], --digest prints
|
|
6412
6693
|
one line per message.)
|
|
6413
6694
|
crewbus ack --from <you> (--id <msg-id> | --all) [--verify "<command>"] [--timeout <dur>]
|
|
6414
6695
|
("handled it" — orthogonal to delivery; leads ack workers' replies;
|
|
@@ -6427,7 +6708,7 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6427
6708
|
(recover mail a dead watcher consumed: clears delivered markers and
|
|
6428
6709
|
rewinds the cursor so the next poll/push treats it as fresh;
|
|
6429
6710
|
use after re-registering with the live session)
|
|
6430
|
-
crewbus spawn --from <you> (--to <workers> | --count <n> [--prefix <p>]) --body "..." [--subject "..."] [--priority high|normal] [--harness opencode|claude|codex|grok|antigravity|cursor|generic] [--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] [--timeout 10m] [--keep-env] [--allow-env ANTHROPIC_,GITHUB_] [--workdir-root <dir>] [--sender-type human|lead|peer] [--dry-run]
|
|
6711
|
+
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|generic] [--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] [--timeout 10m] [--keep-env] [--allow-env ANTHROPIC_,GITHUB_] [--workdir-root <dir>] [--sender-type human|lead|peer] [--dry-run]
|
|
6431
6712
|
(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.)
|
|
6432
6713
|
(brief N workers AND boot them detached: the DM lands first so the brief
|
|
6433
6714
|
waits even if a launch fails. opencode: \`run\` + brief via --file;
|
|
@@ -6435,6 +6716,9 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6435
6716
|
file; grok: headless via --prompt-file; antigravity: \`--print\` with the
|
|
6436
6717
|
brief inline; cursor: headless via \`-p --force --trust\` pointing at the
|
|
6437
6718
|
brief file; generic: --cmd with CREWBUS_DIR + CREWBUS_AGENT set.
|
|
6719
|
+
Briefs auto-inject the latest scoped lessons + newest board artifacts
|
|
6720
|
+
(the Workbench block) so prior output compounds; --needs-by stamps a
|
|
6721
|
+
handoff deadline on the brief DMs.
|
|
6438
6722
|
Logs to .crewbus/logs/<name>.log, pid recorded on the agent. Caps at
|
|
6439
6723
|
20/call by default (--max-spawn overrides, needs the compute) — bigger
|
|
6440
6724
|
crews get a broadcast DM. --worktree is recommended for write tasks (one
|
|
@@ -6454,13 +6738,16 @@ Messaging (primitive — just a tool call, whenever you want):
|
|
|
6454
6738
|
crewbus spawn-kill --from <you> (--to <worker,...> | --all)
|
|
6455
6739
|
(the kill switch: closing the terminal does NOT stop detached workers.
|
|
6456
6740
|
Terminates by recorded pid, confirms death, reports. Needs your token.)
|
|
6457
|
-
crewbus respawn --from <you> --to <worker> [--body "..."] [--force] [--cwd <dir>] [--cmd "..."] [--keep-env] [--allow-env ...] [--dry-run]
|
|
6741
|
+
crewbus respawn --from <you> --to <worker> [--body "..."] [--force] [--fresh] [--cwd <dir>] [--cmd "..."] [--keep-env] [--allow-env ...] [--dry-run]
|
|
6458
6742
|
(reboot one DEAD worker in its SAME harness conversation: needs the
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6743
|
+
captured session id (spawn-status shows it; generic re-boots fresh).
|
|
6744
|
+
--fresh skips the resume requirement when the id can't be captured
|
|
6745
|
+
(e.g. an opencode worker died before its log revealed anything) and
|
|
6746
|
+
re-boots the catch-up brief as a fresh session.
|
|
6747
|
+
Refuses live workers unless --force (kills first, own crew only).
|
|
6748
|
+
The catch-up brief points at the original prompt file and threads the
|
|
6749
|
+
same reply id; --body appends lead instructions. Attempt counted on
|
|
6750
|
+
the worker-session record. Lead/admin only.)
|
|
6464
6751
|
crewbus stop --all --from <you>
|
|
6465
6752
|
(global stop: kills every spawned worker truly (whole process tree).)
|
|
6466
6753
|
crewbus token rotate --from <you> [--expires-in <dur>]
|
|
@@ -7103,14 +7390,15 @@ async function cmdPool(args) {
|
|
|
7103
7390
|
state.active[name] = r.pid;
|
|
7104
7391
|
state.launched++;
|
|
7105
7392
|
state.results.push({ to: name, id: idByName.get(name), pid: r.pid, log: r.logPath, promptPath: r.promptPath });
|
|
7393
|
+
saveState();
|
|
7106
7394
|
console.log(`pool ${poolId}: spawned ${name} pid ${r.pid} [board ${d.root}]`);
|
|
7107
7395
|
} catch (e) {
|
|
7108
7396
|
delete state.active[name];
|
|
7109
7397
|
state.done++;
|
|
7110
7398
|
state.results.push({ to: name, id: idByName.get(name), error: (e && e.message) || String(e) });
|
|
7399
|
+
saveState();
|
|
7111
7400
|
console.log(`pool ${poolId}: spawn FAILED ${name}: ${(e && e.message) || e} (brief still waits on the board)`);
|
|
7112
7401
|
}
|
|
7113
|
-
saveState();
|
|
7114
7402
|
};
|
|
7115
7403
|
const initial = Math.min(poolSize, queue.length);
|
|
7116
7404
|
for (; state.cursor < initial; state.cursor++) launchOne(queue[state.cursor]);
|
|
@@ -7221,14 +7509,15 @@ async function cmdPoolResume(args) {
|
|
|
7221
7509
|
state.active[name] = r.pid;
|
|
7222
7510
|
state.launched++;
|
|
7223
7511
|
state.results.push({ to: name, id: state.idByName[name], pid: r.pid, log: r.logPath, promptPath: r.promptPath, resumed: true });
|
|
7512
|
+
saveState();
|
|
7224
7513
|
console.log(`pool ${state.id}: spawned ${name} pid ${r.pid} [board ${d.root}]`);
|
|
7225
7514
|
} catch (e) {
|
|
7226
7515
|
delete state.active[name];
|
|
7227
7516
|
state.done++;
|
|
7228
7517
|
state.results.push({ to: name, id: state.idByName[name], error: (e && e.message) || String(e) });
|
|
7518
|
+
saveState();
|
|
7229
7519
|
console.log(`pool ${state.id}: spawn FAILED ${name}: ${(e && e.message) || e} (brief still waits on the board)`);
|
|
7230
7520
|
}
|
|
7231
|
-
saveState();
|
|
7232
7521
|
};
|
|
7233
7522
|
const finish = (completed) => {
|
|
7234
7523
|
if (completed) state.finishedAt = new Date().toISOString();
|
|
@@ -7462,6 +7751,8 @@ async function main() {
|
|
|
7462
7751
|
case "agents": return cmdAgents(rest);
|
|
7463
7752
|
case "send": return cmdSend(rest);
|
|
7464
7753
|
case "channel": return cmdChannel(rest);
|
|
7754
|
+
case "artifact": return cmdArtifact(rest);
|
|
7755
|
+
case "lesson": return cmdLesson(rest);
|
|
7465
7756
|
case "lock": return cmdLock(rest);
|
|
7466
7757
|
case "group": return cmdGroup(rest);
|
|
7467
7758
|
case "gather": return cmdGather(rest);
|
package/bin/lib/identity.js
CHANGED
|
@@ -330,7 +330,7 @@ export function authorizeCheck(d, agent, action, scope) { // line 537
|
|
|
330
330
|
const act = String(action || "");
|
|
331
331
|
const ADMIN_ONLY = new Set(["prune", "acl-set", "role-grant", "offboard", "group-restrict", "serve-remote", "import", "snapshot-schedule", "quota-set", "hold-place", "hold-lift", "pairing"]);
|
|
332
332
|
const LEAD_PLUS = new Set(["spawn", "respawn", "pool", "group-manage", "channel-post", "result-record", "race-close"]);
|
|
333
|
-
const WORKER_WRITES = new Set(["send", "ack", "redeliver", "lock"]);
|
|
333
|
+
const WORKER_WRITES = new Set(["send", "ack", "redeliver", "lock", "artifact-write", "lesson-write"]);
|
|
334
334
|
const EXPORT_ROLES = new Set(["admin", "auditor"]);
|
|
335
335
|
if (act === "export") {
|
|
336
336
|
if (!EXPORT_ROLES.has(role)) return { ok: false, reason: `role "${role}" cannot export (need admin|auditor)` };
|
|
@@ -405,26 +405,32 @@ export function mergeAgentDoc(prev, patch) {
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
// Loopback operator auto-provision (desktop plug-and-play):
|
|
408
|
-
// `serve`/`web` on 127.0.0.1 auto-creates
|
|
408
|
+
// `serve`/`web` on 127.0.0.1 auto-creates an operator identity on first boot so
|
|
409
409
|
// the dashboard can launch without any terminal step. First agent on the
|
|
410
410
|
// board becomes admin (see defaultRoleForNew), so this is the board owner.
|
|
411
|
-
//
|
|
411
|
+
// Under the 3-lane model (boss / lead / peers), fresh boards mint `boss` as the
|
|
412
|
+
// desktop human operator, allowing crew bursts to auto-provision `lead` as the
|
|
413
|
+
// autonomous coordinator. Existing boards that already claimed `lead` (or `boss`)
|
|
414
|
+
// are kept without disruption.
|
|
415
|
+
// CLI boards are untouched: this only fires when operator is missing AND the
|
|
412
416
|
// bind is loopback. Returns { from, token } or null when not applicable.
|
|
413
417
|
export function ensureLoopbackOperator(d, host) {
|
|
414
418
|
const loop = String(host || "127.0.0.1");
|
|
415
419
|
if (loop !== "127.0.0.1" && loop !== "localhost" && loop !== "::1") return null;
|
|
416
|
-
let
|
|
417
|
-
try {
|
|
418
|
-
|
|
420
|
+
let recBoss = null, recLead = null;
|
|
421
|
+
try { recBoss = readAgent(d, "boss"); } catch { recBoss = null; }
|
|
422
|
+
try { recLead = readAgent(d, "lead"); } catch { recLead = null; }
|
|
423
|
+
if (recBoss && (recBoss.tokenHash || recBoss.token)) return null; // already provisioned
|
|
424
|
+
if (recLead && (recLead.tokenHash || recLead.token)) return null; // already provisioned (legacy board)
|
|
419
425
|
if (countAgentRecords(d) > 0) return null; // board already has registered agents
|
|
420
426
|
const fresh = mintToken();
|
|
421
427
|
const salt = newSalt();
|
|
422
428
|
const now = new Date().toISOString();
|
|
423
429
|
let prev = null;
|
|
424
|
-
try { prev = readJson(path.join(d.agents, "
|
|
430
|
+
try { prev = readJson(path.join(d.agents, "boss.json")); } catch { prev = null; }
|
|
425
431
|
const { v, hlc } = stampSyncDoc(prev);
|
|
426
432
|
const doc = mergeAgentDoc(prev, {
|
|
427
|
-
name: "
|
|
433
|
+
name: "boss",
|
|
428
434
|
firstSeen: (prev && prev.firstSeen) || now,
|
|
429
435
|
lastSeen: now,
|
|
430
436
|
tokenHash: hashToken(fresh, salt),
|
|
@@ -438,9 +444,9 @@ export function ensureLoopbackOperator(d, host) {
|
|
|
438
444
|
let won = false;
|
|
439
445
|
try {
|
|
440
446
|
if (!prev) {
|
|
441
|
-
won = writeExclusiveJson(path.join(d.agents, "
|
|
447
|
+
won = writeExclusiveJson(path.join(d.agents, "boss.json"), doc);
|
|
442
448
|
} else {
|
|
443
|
-
writeAgentFile(d, "
|
|
449
|
+
writeAgentFile(d, "boss", doc);
|
|
444
450
|
won = true;
|
|
445
451
|
}
|
|
446
452
|
} catch { won = false; }
|
|
@@ -449,14 +455,14 @@ export function ensureLoopbackOperator(d, host) {
|
|
|
449
455
|
return null;
|
|
450
456
|
}
|
|
451
457
|
if (won) {
|
|
452
|
-
try { chmodAgentFile(path.join(d.agents, "
|
|
458
|
+
try { chmodAgentFile(path.join(d.agents, "boss.json")); } catch {}
|
|
453
459
|
try {
|
|
454
460
|
fs.mkdirSync(path.join(d.root, "logs"), { recursive: true });
|
|
455
|
-
fs.writeFileSync(path.join(d.root, "logs", "
|
|
456
|
-
try { fs.chmodSync(path.join(d.root, "logs", "
|
|
461
|
+
fs.writeFileSync(path.join(d.root, "logs", "boss.token"), fresh + "\n", "utf8");
|
|
462
|
+
try { fs.chmodSync(path.join(d.root, "logs", "boss.token"), 0o600); } catch {}
|
|
457
463
|
} catch {}
|
|
458
464
|
}
|
|
459
|
-
return won ? { from: "
|
|
465
|
+
return won ? { from: "boss", token: fresh } : null;
|
|
460
466
|
}
|
|
461
467
|
|
|
462
468
|
export function touchAgent(d, name, extra) { // line 2647
|