crewbus 10.0.10 → 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 +44 -0
- package/README.md +690 -708
- package/bin/crewbus-hook.js +57 -2
- package/bin/crewbus-mcp.js +25 -3
- package/bin/crewbus.js +364 -190
- package/bin/lib/channels.js +11 -1
- package/bin/lib/identity.js +148 -26
- package/bin/lib/kidproc.js +92 -0
- package/bin/lib/launch.js +77 -29
- package/bin/lib/qrcode.js +2971 -0
- package/bin/lib/relay.js +6 -15
- package/bin/lib/spawn.js +138 -46
- package/bin/lib/store.js +2 -1
- package/bin/lib/web.js +241 -23
- 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/GROUPS.md +4 -2
- package/docs/HA.md +151 -151
- package/docs/IDENTITY.md +36 -0
- package/docs/LEAD_ASSIGN.md +74 -75
- package/docs/LONG_RUNS.md +3 -2
- package/docs/M1_CLI_DRAFT.md +2 -2
- package/docs/QUICKSTART.md +70 -70
- package/docs/RBAC.md +73 -69
- package/docs/SPLIT.md +82 -82
- package/docs/THREAT_MODEL.md +68 -69
- package/docs/TROUBLESHOOTING.md +1 -0
- 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/plugins/dm-watch.js +70 -8
- 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/lib/channels.js
CHANGED
|
@@ -9,6 +9,7 @@ import path from "node:path";
|
|
|
9
9
|
import crypto from "node:crypto";
|
|
10
10
|
import { readJson, writeJson, newId, fail, cleanChannelName, listJson } from "./store.js";
|
|
11
11
|
import { isHigh, relTime } from "./mail.js";
|
|
12
|
+
import { authorizeCheck } from "./identity.js"; // member-scoped channel mirrors (C4; call-time use only — hoisted declarations tolerate the identity→groups→channels cycle)
|
|
12
13
|
|
|
13
14
|
// cleanChannelName lives in store.js (canonical home for all clean* helpers).
|
|
14
15
|
|
|
@@ -103,7 +104,16 @@ export function summarizePosts(posts, limit) {
|
|
|
103
104
|
|
|
104
105
|
export function mirrorToGroupChannels(d, { groups, from, body, subject, replyTo, batch, priority, rev, at }) {
|
|
105
106
|
const mirrored = [];
|
|
107
|
+
const skipped = [];
|
|
106
108
|
for (const g of groups || []) {
|
|
109
|
+
// Member-scoped mirrors (C4): a worker's brief lands on grp-<g> channel
|
|
110
|
+
// only if it is a member of <g> (or lead/admin). Non-members' DMs still
|
|
111
|
+
// deliver — the channel mirror is skipped with a visible note.
|
|
112
|
+
const gate = authorizeCheck(d, from, "channel-post", { channelGroup: g });
|
|
113
|
+
if (!gate || !gate.ok) {
|
|
114
|
+
skipped.push({ group: g, reason: (gate && gate.reason) || "member posting required" });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
107
117
|
const chan = groupChannelName(g);
|
|
108
118
|
const post = { id: newId("ch"), from, body, at };
|
|
109
119
|
if (subject) post.subject = subject;
|
|
@@ -114,7 +124,7 @@ export function mirrorToGroupChannels(d, { groups, from, body, subject, replyTo,
|
|
|
114
124
|
appendChannelPost(d, chan, post);
|
|
115
125
|
mirrored.push({ group: g, channel: chan, id: post.id });
|
|
116
126
|
}
|
|
117
|
-
return mirrored;
|
|
127
|
+
return { mirrored, skipped };
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
export function lockHash(scope) {
|
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,23 +155,15 @@ export function checkToken(d, agent, token) { // line 361
|
|
|
158
155
|
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
159
156
|
return rec;
|
|
160
157
|
}
|
|
161
|
-
|
|
162
|
-
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
163
|
-
// Migrate: re-hash + drop plaintext now that the owner proved possession.
|
|
164
|
-
const salt = newSalt();
|
|
165
|
-
const migrated = { ...rec, tokenHash: hashToken(String(token), salt), salt };
|
|
166
|
-
delete migrated.token;
|
|
167
|
-
migrated.lastSeen = new Date().toISOString();
|
|
168
|
-
writeAgentFile(d, agent, migrated);
|
|
169
|
-
return migrated;
|
|
170
|
-
}
|
|
171
|
-
fail(`agent "${agent}" predates tokens — re-register to claim it: register --from ${agent}`);
|
|
158
|
+
fail(`bad/missing token hash for "${agent}" — re-register to claim it: register --from ${agent}`);
|
|
172
159
|
}
|
|
173
160
|
|
|
174
161
|
// First send as a new name mints its record + token (same first-claim-wins
|
|
175
162
|
// as register, zero extra round-trip). Returns { created } so callers can
|
|
176
163
|
// print the token exactly once — it is never shown again via send.
|
|
177
164
|
export function ensureSender(d, agent, token) { // line 387
|
|
165
|
+
const sentinel = reservedNameReason(agent);
|
|
166
|
+
if (sentinel) fail(sentinel);
|
|
178
167
|
const rec = readAgent(d, agent);
|
|
179
168
|
if (!rec) {
|
|
180
169
|
if (isBoardFrozen(d)) fail(`board is frozen — new registrations refused (ask an admin to register --from <admin> --for ${agent})`);
|
|
@@ -211,16 +200,7 @@ export function ensureSender(d, agent, token) { // line 387
|
|
|
211
200
|
assertMintWon(d, agent, rec.tokenHash);
|
|
212
201
|
return { created: true, token: fresh };
|
|
213
202
|
}
|
|
214
|
-
if (
|
|
215
|
-
// Legacy file: must present the old plaintext once; then migrate.
|
|
216
|
-
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
217
|
-
const salt = newSalt();
|
|
218
|
-
rec.tokenHash = hashToken(String(token), salt);
|
|
219
|
-
rec.salt = salt;
|
|
220
|
-
delete rec.token;
|
|
221
|
-
writeAgentFile(d, agent, rec);
|
|
222
|
-
return { created: false, migrated: true };
|
|
223
|
-
}
|
|
203
|
+
if (!rec.tokenHash) fail(`bad/missing token hash for "${agent}" — re-register to claim: register --from ${agent}`);
|
|
224
204
|
if (!agentTokenMatches(rec, token)) fail(`bad token for "${agent}" (pass --token or set CREWBUS_TOKEN)`);
|
|
225
205
|
if (rec.offboarded) fail(`agent "${agent}" is offboarded — sends as that name are refused (inbox preserved for audit)`);
|
|
226
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>`);
|
|
@@ -228,6 +208,128 @@ export function ensureSender(d, agent, token) { // line 387
|
|
|
228
208
|
return { created: false };
|
|
229
209
|
}
|
|
230
210
|
|
|
211
|
+
// ---------------------------------------------------------------------------
|
|
212
|
+
// Identity recovery (C1): an agent that survives compaction/restart amnesia
|
|
213
|
+
// loses its name. The compaction hooks rehydrate from a session map; when
|
|
214
|
+
// even that is lost the harness texts used to mint throwaway identities
|
|
215
|
+
// (logs/unknown.token) that nobody owns. Two fixes: reserved sentinel names
|
|
216
|
+
// never mint, and a read-only recovery cross-check finds the real identity
|
|
217
|
+
// from what the board still knows.
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
// Scan logs/<name>.token: { name -> token | null } (best-effort; a missing
|
|
221
|
+
// or unreadable file is just "no evidence").
|
|
222
|
+
function listTokenFiles(d) {
|
|
223
|
+
const out = new Map();
|
|
224
|
+
try {
|
|
225
|
+
for (const f of fs.readdirSync(path.join(d.root, "logs"))) {
|
|
226
|
+
const m = /^([A-Za-z0-9_-]+)\.token$/.exec(f);
|
|
227
|
+
if (!m) continue;
|
|
228
|
+
try {
|
|
229
|
+
const t = fs.readFileSync(path.join(d.root, "logs", f), "utf8").trim();
|
|
230
|
+
if (t) out.set(m[1], t);
|
|
231
|
+
} catch {}
|
|
232
|
+
}
|
|
233
|
+
} catch {}
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// { name, role, sessionId, lastDir, lastSeen, tokenHash, salt } for the scan.
|
|
238
|
+
function findAgentRecords(d) {
|
|
239
|
+
const records = [];
|
|
240
|
+
try {
|
|
241
|
+
for (const f of fs.readdirSync(d.agents)) {
|
|
242
|
+
if (!f.endsWith(".json")) continue;
|
|
243
|
+
try {
|
|
244
|
+
const doc = readJson(path.join(d.agents, f));
|
|
245
|
+
if (!doc || !doc.name || doc.offboarded) continue;
|
|
246
|
+
records.push({
|
|
247
|
+
name: String(doc.name),
|
|
248
|
+
role: roleOfRecord(doc),
|
|
249
|
+
sessionId: doc.sessionId || undefined,
|
|
250
|
+
lastDir: doc.lastDir || undefined,
|
|
251
|
+
lastSeen: doc.lastSeen || undefined,
|
|
252
|
+
tokenHash: doc.tokenHash || undefined,
|
|
253
|
+
salt: doc.salt || undefined,
|
|
254
|
+
});
|
|
255
|
+
} catch {}
|
|
256
|
+
}
|
|
257
|
+
} catch {}
|
|
258
|
+
return records;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Rank identity candidates for an amnesiac agent. Read-only, never throws.
|
|
262
|
+
// opts: { sessionID, cwd, hashToken?, loadTokenFile? } (injectors let the
|
|
263
|
+
// CLI do the token-file↔tokenHash cross-check; plugin copies ship a lite
|
|
264
|
+
// variant without hash-verify).
|
|
265
|
+
// Returns [{ name, role, score, proven, why }] best-first.
|
|
266
|
+
export function recoverIdentity(d, opts = {}) {
|
|
267
|
+
const records = findAgentRecords(d);
|
|
268
|
+
const tokens = listTokenFiles(d);
|
|
269
|
+
const cwd = opts.cwd ? String(opts.cwd) : undefined;
|
|
270
|
+
const sessionID = opts.sessionID ? String(opts.sessionID) : undefined;
|
|
271
|
+
const canVerify = typeof opts.hashToken === "function" && typeof opts.loadTokenFile === "function";
|
|
272
|
+
const cands = [];
|
|
273
|
+
for (const rec of records) {
|
|
274
|
+
let score = 0;
|
|
275
|
+
let proven = false;
|
|
276
|
+
const why = [];
|
|
277
|
+
// Register-time session binding (register --session <id>) is the
|
|
278
|
+
// strongest cross-check: it names THIS harness session explicitly.
|
|
279
|
+
if (sessionID && rec.sessionId && rec.sessionId === sessionID) {
|
|
280
|
+
score += 4;
|
|
281
|
+
why.push("session id matches register binding");
|
|
282
|
+
}
|
|
283
|
+
// Token-file evidence: existence is a hint; a real cross-check against
|
|
284
|
+
// the stored hash is proof (hashToken(token, salt) === tokenHash).
|
|
285
|
+
if (tokens.has(rec.name)) {
|
|
286
|
+
score += 1;
|
|
287
|
+
why.push("token file exists for this name");
|
|
288
|
+
if (canVerify && rec.tokenHash && rec.salt) {
|
|
289
|
+
try {
|
|
290
|
+
const t = opts.loadTokenFile(d.root, rec.name);
|
|
291
|
+
if (t && opts.hashToken(t, rec.salt) === rec.tokenHash) {
|
|
292
|
+
proven = true;
|
|
293
|
+
score += 3;
|
|
294
|
+
why.push("token file cross-checks the stored hash");
|
|
295
|
+
}
|
|
296
|
+
} catch {}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (cwd && rec.lastDir && arePathsSameDir(rec.lastDir, cwd)) {
|
|
300
|
+
score += 1;
|
|
301
|
+
why.push("worked from this directory");
|
|
302
|
+
}
|
|
303
|
+
if (score <= 0) continue;
|
|
304
|
+
cands.push({ name: rec.name, role: rec.role, score, proven, why: why.join("; ") });
|
|
305
|
+
}
|
|
306
|
+
cands.sort((a, b) => b.score - a.score || String(a.name).localeCompare(String(b.name)));
|
|
307
|
+
return cands;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Case-insensitive directory comparison for Windows case-insensitivity +
|
|
311
|
+
// symlink noise tolerance (best-effort: trailing slashes, backslashes).
|
|
312
|
+
function arePathsSameDir(a, b) {
|
|
313
|
+
const norm = (p) => String(p).replace(/[\\/]+$/, "").toLowerCase();
|
|
314
|
+
if (norm(a) === norm(b)) return true;
|
|
315
|
+
// Partial tolerance: a registered cwd may be a subpath of the board root.
|
|
316
|
+
const aN = norm(a).split(/[\\/]/);
|
|
317
|
+
const bN = norm(b).split(/[\\/]/);
|
|
318
|
+
return aN.length !== bN.length && (aN.join("/").includes(bN.join("/")) || bN.join("/").includes(aN.join("/")));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Reserved sentinel names never mint — they come from amnesia bugs, and
|
|
322
|
+
// minting them loses real identity data forever (the 10.0.9-run "lead"
|
|
323
|
+
// lockout came from exactly this).
|
|
324
|
+
export const RESERVED_SENTINELS = ["unknown", "me", "you"];
|
|
325
|
+
|
|
326
|
+
export function reservedNameReason(agent) {
|
|
327
|
+
const s = String(agent || "").trim().toLowerCase();
|
|
328
|
+
return RESERVED_SENTINELS.includes(s)
|
|
329
|
+
? `"${agent}" is a reserved sentinel name (amnesia-throwaway) — identity lost? run: crewbus recover, then re-register/claim your real name`
|
|
330
|
+
: null;
|
|
331
|
+
}
|
|
332
|
+
|
|
231
333
|
// ---------------------------------------------------------------------------
|
|
232
334
|
// Phase 1b RBAC + per-board ACLs + group-scoped send permissions.
|
|
233
335
|
//
|
|
@@ -329,7 +431,7 @@ export function authorizeCheck(d, agent, action, scope) { // line 537
|
|
|
329
431
|
const role = getRole(d, agent);
|
|
330
432
|
const act = String(action || "");
|
|
331
433
|
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
|
-
const LEAD_PLUS = new Set(["spawn", "respawn", "pool", "group-manage", "
|
|
434
|
+
const LEAD_PLUS = new Set(["spawn", "respawn", "pool", "group-manage", "result-record", "race-close"]);
|
|
333
435
|
const WORKER_WRITES = new Set(["send", "ack", "redeliver", "lock", "artifact-write", "lesson-write"]);
|
|
334
436
|
const EXPORT_ROLES = new Set(["admin", "auditor"]);
|
|
335
437
|
if (act === "export") {
|
|
@@ -340,6 +442,26 @@ export function authorizeCheck(d, agent, action, scope) { // line 537
|
|
|
340
442
|
return { ok: false, reason: `role "${role}" cannot ${act} (need admin)` };
|
|
341
443
|
} else if (LEAD_PLUS.has(act)) {
|
|
342
444
|
if (role !== "lead") return { ok: false, reason: `role "${role}" cannot ${act} (need lead|admin)` };
|
|
445
|
+
} else if (act === "channel-post") {
|
|
446
|
+
// Member-scoped channel posting (C4, default-on): workers may post to the
|
|
447
|
+
// channels of groups they are a MEMBER of (scope.channelGroup); lead/admin
|
|
448
|
+
// post anywhere (board channels + every group channel). Everyone else,
|
|
449
|
+
// and workers targeting a foreign group's channel or a board channel with
|
|
450
|
+
// no member mapping, are refused.
|
|
451
|
+
if (role === "admin" || role === "lead") {
|
|
452
|
+
// board-wide + group channels
|
|
453
|
+
} else if (role !== "worker") {
|
|
454
|
+
return { ok: false, reason: `role "${role}" cannot ${act} (member-posting is scoped to group members; need lead|admin)` };
|
|
455
|
+
} else {
|
|
456
|
+
const targetGroup = scope && scope.channelGroup ? String(scope.channelGroup) : undefined;
|
|
457
|
+
if (!targetGroup) {
|
|
458
|
+
return { ok: false, reason: `role "worker" may post only to a group channel it belongs to (${targetGroup === undefined ? "board channels are lead|admin" : "need lead|admin"})` };
|
|
459
|
+
}
|
|
460
|
+
const gdoc = readGroup(d, targetGroup);
|
|
461
|
+
if (!gdoc) return { ok: false, reason: `channel group "${targetGroup}" not found (groups register their channels — board channels are lead|admin)` };
|
|
462
|
+
const members = Array.isArray(gdoc.members) ? gdoc.members : [];
|
|
463
|
+
if (!members.includes(agent)) return { ok: false, reason: `group channel "${targetGroup}" — members only (member or lead|admin)` };
|
|
464
|
+
}
|
|
343
465
|
} else if (act === "spawn-kill") {
|
|
344
466
|
if (role !== "lead") return { ok: false, reason: `role "${role}" cannot spawn-kill (need lead|admin)` };
|
|
345
467
|
const targets = (scope && Array.isArray(scope.targets)) ? scope.targets : [];
|
|
@@ -421,7 +543,7 @@ export function ensureLoopbackOperator(d, host) {
|
|
|
421
543
|
try { recBoss = readAgent(d, "boss"); } catch { recBoss = null; }
|
|
422
544
|
try { recLead = readAgent(d, "lead"); } catch { recLead = null; }
|
|
423
545
|
if (recBoss && (recBoss.tokenHash || recBoss.token)) return null; // already provisioned
|
|
424
|
-
if (recLead &&
|
|
546
|
+
if (recLead && recLead.tokenHash) return null; // already provisioned (legacy board)
|
|
425
547
|
if (countAgentRecords(d) > 0) return null; // board already has registered agents
|
|
426
548
|
const fresh = mintToken();
|
|
427
549
|
const salt = newSalt();
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// bin/lib/kidproc.js — shell-mode child processes without DEP0190.
|
|
2
|
+
//
|
|
3
|
+
// Node >=22 deprecates `spawn(exe, args, { shell: true })` when `args` is
|
|
4
|
+
// non-empty (DEP0190) — args are passed through the shell UNESCAPED (the
|
|
5
|
+
// warning exists because the old wire is unsafe: `"arg one"` emitted raw
|
|
6
|
+
// splits into two argv tokens on the receiving process). This module
|
|
7
|
+
// reproduces the intended semantics with CORRECT quoting:
|
|
8
|
+
//
|
|
9
|
+
// Windows old: spawn(exe, args, { shell:true }) (unescaped raw concat)
|
|
10
|
+
// new: spawn("cmd.exe", ["/d","/s","/c", quoted line],
|
|
11
|
+
// { windowsVerbatimArguments: true })
|
|
12
|
+
// POSIX old: spawn(exe, args, { shell:true })
|
|
13
|
+
// new: spawn("/bin/sh", ["-c", quoted line], { shell:false })
|
|
14
|
+
//
|
|
15
|
+
// (On win32 `windowsVerbatimArguments` matters: without it node re-quotes the
|
|
16
|
+
// already-quoted outer string and cmd would double-parse the escapes.)
|
|
17
|
+
//
|
|
18
|
+
// NOTE: this is intentionally NOT bit-identical to the deprecated wire —
|
|
19
|
+
// the old wire mangled args (space splitting, quote eating) and let bare
|
|
20
|
+
// cmd metacharacters (& | ^) inject into the command line. The regression
|
|
21
|
+
// bar here is argv IDENTITY: what the child receives equals what the
|
|
22
|
+
// caller passed. Known cmd limitation documented here: a matched %VAR%
|
|
23
|
+
// pattern inside a quoted token still expands at the cmd layer (no escape
|
|
24
|
+
// exists for cmd quoted context) — unmatched % passes through intact.
|
|
25
|
+
// Standalone by design (see docs/SPLIT.md): zero local imports, cycle-free.
|
|
26
|
+
// Escape hatch for exactly one release: CREWBUS_SHELL_LEGACY=1 restores the
|
|
27
|
+
// pre-refactor `shell: true` behavior at call sites.
|
|
28
|
+
|
|
29
|
+
const WIN_SHELL = "cmd.exe";
|
|
30
|
+
const POSIX_SHELL = "/bin/sh";
|
|
31
|
+
|
|
32
|
+
// MS CRT / CreateProcess argument quoting, plus the cmd.exe pass layer:
|
|
33
|
+
// wrap on whitespace, quotes, AND cmd metacharacters (& | ^ < > %) — bare
|
|
34
|
+
// metachars split commands even inside the overall quoted /c line (probes:
|
|
35
|
+
// "a&b|c^d" quoted argv arrives intact; bare flexes). Inside the wrap:
|
|
36
|
+
// backslashes double before quotes per MS standard, % stays raw (cmd does
|
|
37
|
+
// NOT expand unmatched %; a matched %VAR% *does* expand even inside quotes —
|
|
38
|
+
// a known cmd limitation, no escape hatch exists — see docs note), ^ is
|
|
39
|
+
// literal inside quotes. Bare tokens without any of those pass unwrapped
|
|
40
|
+
// (already valid single argv tokens).
|
|
41
|
+
function msQuote(s) {
|
|
42
|
+
s = String(s);
|
|
43
|
+
if (s === "") return '""';
|
|
44
|
+
if (!/[\s"&|^<>%]/.test(s)) return s;
|
|
45
|
+
let out = '"';
|
|
46
|
+
let backslashes = 0;
|
|
47
|
+
for (const c of s) {
|
|
48
|
+
if (c === "\\") { backslashes++; continue; }
|
|
49
|
+
if (c === '"') {
|
|
50
|
+
out += "\\".repeat(backslashes * 2 + 1) + '"';
|
|
51
|
+
} else {
|
|
52
|
+
out += "\\".repeat(backslashes) + c;
|
|
53
|
+
}
|
|
54
|
+
backslashes = 0;
|
|
55
|
+
}
|
|
56
|
+
// Backslashes before the closing wrap double up too.
|
|
57
|
+
out += "\\".repeat(backslashes * 2);
|
|
58
|
+
return out + '"';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// POSIX single-quote joining (' -> '\'').
|
|
62
|
+
function shQuote(s) {
|
|
63
|
+
s = String(s);
|
|
64
|
+
// A bare empty token would vanish outright (two words `a ''` parse to
|
|
65
|
+
// [a, ""] — `a ` parses to [a] only), losing the operand.
|
|
66
|
+
// (note: `;` is deliberately NOT in the safe class — POSIX shells treat a
|
|
67
|
+
// bare `;` as a command separator; cmd tolerates it. cmd metacharacters
|
|
68
|
+
// (& | ^ < > %) never appear here — msQuote owns the win line.)
|
|
69
|
+
if (s === "") return "''";
|
|
70
|
+
return /^[-#%+,.:=?@_a-zA-Z0-9\/]*$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// { exe, args } one should hand to spawn(..., { shell: false }) to keep the
|
|
74
|
+
// old shell:true semantics for (exe, args). Returns null when args is empty
|
|
75
|
+
// — callers keep their existing behavior in that case (empty args never hit
|
|
76
|
+
// DEP0190).
|
|
77
|
+
function shellChildSpec(exe, args, platform = process.platform) {
|
|
78
|
+
const a = (args || []).map(String);
|
|
79
|
+
if (a.length === 0) return null;
|
|
80
|
+
const line = [String(exe), ...a];
|
|
81
|
+
if (platform === "win32") {
|
|
82
|
+
return { exe: WIN_SHELL, args: ["/d", "/s", "/c", `"${line.map(msQuote).join(" ")}"`] };
|
|
83
|
+
}
|
|
84
|
+
return { exe: POSIX_SHELL, args: ["-c", line.map(shQuote).join(" ")] };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Spawn-time options a caller must add when using shellChildSpec output.
|
|
88
|
+
function shellChildOptions(platform = process.platform) {
|
|
89
|
+
return platform === "win32" ? { windowsVerbatimArguments: true } : {};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { msQuote, shQuote, shellChildSpec, shellChildOptions };
|
package/bin/lib/launch.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { shellChildSpec, shellChildOptions } from "./kidproc.js";
|
|
9
10
|
|
|
10
11
|
export const LAUNCH_PERMISSIONS = ["supervised", "autoEdits", "auto", "full"];
|
|
11
12
|
export const LAUNCH_LIFETIMES = ["oneshot", "persistent"];
|
|
@@ -27,7 +28,6 @@ export const LAUNCH_DRIVER_FALLBACK = [
|
|
|
27
28
|
{ driver: "grok", displayName: "grok-build", binary: "grok", briefDelivery: "file", sessionCapture: "preassigned", resume: true, spawnArgs: "--prompt-file <brief> -s <uuid>", resumeArgs: "--prompt-file <catchup> -r <id>" },
|
|
28
29
|
{ driver: "antigravity", displayName: "Antigravity", binary: "agy", briefDelivery: "inline", sessionCapture: "none", resume: false, spawnArgs: "--print --mode accept-edits \"<brief>\"", resumeArgs: "unsupported (no stable conversation id)" },
|
|
29
30
|
{ driver: "cursor", displayName: "Cursor", binary: "cursor-agent", briefDelivery: "inline", sessionCapture: "none", resume: false, spawnArgs: "cursor-agent -p --force --trust \"<brief>\"", resumeArgs: "unsupported (id lives in stream-json)" },
|
|
30
|
-
{ driver: "generic", displayName: "generic", binary: null, briefDelivery: "file", sessionCapture: "none", resume: false, spawnArgs: "--cmd \"<arbitrary>\"", resumeArgs: "fresh boot only" },
|
|
31
31
|
];
|
|
32
32
|
// Resolve the driver table: contracts file wins, fallback otherwise.
|
|
33
33
|
export function launchDrivers() {
|
|
@@ -35,21 +35,25 @@ export function launchDrivers() {
|
|
|
35
35
|
const here = path.dirname(new URL(import.meta.url).pathname);
|
|
36
36
|
const p = path.join(here, "..", "..", "packages", "contracts", "harness.json");
|
|
37
37
|
const doc = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
38
|
-
if (doc && Array.isArray(doc.drivers) && doc.drivers.length ===
|
|
38
|
+
if (doc && Array.isArray(doc.drivers) && doc.drivers.length === 6) return doc.drivers;
|
|
39
39
|
} catch {}
|
|
40
40
|
return LAUNCH_DRIVER_FALLBACK;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Probe one binary for presence + version. Never throws: missing binaries
|
|
44
44
|
// report { found: false } ("not installed", not failure).
|
|
45
|
-
// On Windows, global npm CLIs are batch scripts (.cmd) which require shell
|
|
45
|
+
// On Windows, global npm CLIs are batch scripts (.cmd) which require a shell;
|
|
46
|
+
// the legacy spawn(exe, args, {shell:true}) shape is DEP0190 on modern Node —
|
|
47
|
+
// run cmd.exe as an explicit argv0 with the same wire format (bin/lib/kidproc.js).
|
|
46
48
|
export function probeBinary(binary, probeArgs) {
|
|
47
49
|
if (!binary) return { found: false, version: null, detail: "operator-supplied --cmd" };
|
|
48
50
|
try {
|
|
49
51
|
const isWin = process.platform === "win32";
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
}
|
|
52
|
+
const args = probeArgs && probeArgs.length > 0 ? probeArgs : ["--version"];
|
|
53
|
+
const spec = isWin ? shellChildSpec(binary, args) : { exe: binary, args };
|
|
54
|
+
const opts = { stdio: ["ignore", "pipe", "pipe"], timeout: 8000 };
|
|
55
|
+
if (isWin) Object.assign(opts, shellChildOptions());
|
|
56
|
+
const out = execFileSync(spec.exe, spec.args, opts);
|
|
53
57
|
const first = String(out || "").split("\n")[0].trim().slice(0, 80);
|
|
54
58
|
return { found: true, version: first || "installed", detail: null };
|
|
55
59
|
} catch (e) {
|
|
@@ -146,7 +150,6 @@ export const HARNESS_MODELS = {
|
|
|
146
150
|
{ id: "claude-3.7-sonnet", label: "Claude 3.7 Sonnet (Legacy)", tier: "standard" },
|
|
147
151
|
{ id: "gpt-4o", label: "GPT-4o (Legacy)", tier: "standard" },
|
|
148
152
|
],
|
|
149
|
-
generic: [],
|
|
150
153
|
};
|
|
151
154
|
|
|
152
155
|
// Dynamic discovered model cache for harnesses capable of live discovery (e.g., opencode).
|
|
@@ -178,27 +181,72 @@ export function refreshDiscoveredModels(timeoutMs = 15000) {
|
|
|
178
181
|
const { execFile } = await import("node:child_process");
|
|
179
182
|
const { promisify } = await import("node:util");
|
|
180
183
|
const execFileAsync = promisify(execFile);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
.filter((l) => l && !l.startsWith("⠀") && !l.startsWith("█") && !l.includes(" "));
|
|
188
|
-
if (rawLines.length > 0) {
|
|
189
|
-
const opencodeModels = rawLines.map((m) => {
|
|
190
|
-
const parts = m.split("/");
|
|
191
|
-
const name = parts[1] || parts[0];
|
|
192
|
-
const tier = /pro|r1|opus|3\.7|o3|o1|gpt-5|grok-4|max/i.test(m)
|
|
193
|
-
? "frontier"
|
|
194
|
-
: /haiku|flash|mini|nano|free/i.test(m)
|
|
195
|
-
? "fast"
|
|
196
|
-
: "standard";
|
|
197
|
-
return { id: m, label: `${name} (${parts[0]})`, tier };
|
|
184
|
+
|
|
185
|
+
// opencode model discovery
|
|
186
|
+
try {
|
|
187
|
+
const { stdout } = await execFileAsync("opencode", ["models"], {
|
|
188
|
+
timeout: timeoutMs,
|
|
189
|
+
shell: isWin,
|
|
198
190
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
191
|
+
const rawLines = String(stdout || "").split("\n")
|
|
192
|
+
.map((l) => l.trim())
|
|
193
|
+
.filter((l) => l && !l.startsWith("⠀") && !l.startsWith("█") && !l.includes(" "));
|
|
194
|
+
if (rawLines.length > 0) {
|
|
195
|
+
const opencodeModels = rawLines.map((m) => {
|
|
196
|
+
const parts = m.split("/");
|
|
197
|
+
const name = parts[1] || parts[0];
|
|
198
|
+
const tier = /pro|r1|opus|3\.7|o3|o1|gpt-5|grok-4|max/i.test(m)
|
|
199
|
+
? "frontier"
|
|
200
|
+
: /haiku|flash|mini|nano|free/i.test(m)
|
|
201
|
+
? "fast"
|
|
202
|
+
: "standard";
|
|
203
|
+
return { id: m, label: `${name} (${parts[0]})`, tier };
|
|
204
|
+
});
|
|
205
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
206
|
+
_cachedDiscoveredModels.opencode = opencodeModels;
|
|
207
|
+
}
|
|
208
|
+
} catch {}
|
|
209
|
+
|
|
210
|
+
// grok model discovery
|
|
211
|
+
try {
|
|
212
|
+
const { stdout: gOut } = await execFileAsync("grok", ["models"], {
|
|
213
|
+
timeout: timeoutMs,
|
|
214
|
+
shell: isWin,
|
|
215
|
+
});
|
|
216
|
+
const gLines = String(gOut || "").split("\n")
|
|
217
|
+
.map((l) => l.trim())
|
|
218
|
+
.filter((l) => l.startsWith("*") || l.startsWith("-"))
|
|
219
|
+
.map((l) => l.replace(/^[*-\s]+/, "").split(" ")[0].trim())
|
|
220
|
+
.filter(Boolean);
|
|
221
|
+
if (gLines.length > 0) {
|
|
222
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
223
|
+
_cachedDiscoveredModels.grok = gLines.map((id) => ({
|
|
224
|
+
id,
|
|
225
|
+
label: `${id.charAt(0).toUpperCase() + id.slice(1)} (Discovered)`,
|
|
226
|
+
tier: /4\.[6-9]|5/i.test(id) ? "frontier" : "standard",
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
} catch {}
|
|
230
|
+
|
|
231
|
+
// antigravity model discovery
|
|
232
|
+
try {
|
|
233
|
+
const { stdout: aOut } = await execFileAsync("agy", ["models"], {
|
|
234
|
+
timeout: timeoutMs,
|
|
235
|
+
shell: isWin,
|
|
236
|
+
});
|
|
237
|
+
const aLines = String(aOut || "").split("\n")
|
|
238
|
+
.map((l) => l.trim())
|
|
239
|
+
.filter((l) => l && !l.toLowerCase().startsWith("fetching") && l.includes("\t"))
|
|
240
|
+
.map((l) => {
|
|
241
|
+
const [id, label] = l.split("\t");
|
|
242
|
+
const tier = /high|pro|opus|4/i.test(label || id) ? "frontier" : /low|lite|mini/i.test(label || id) ? "fast" : "standard";
|
|
243
|
+
return { id: id.trim(), label: (label || id).trim(), tier };
|
|
244
|
+
});
|
|
245
|
+
if (aLines.length > 0) {
|
|
246
|
+
if (!_cachedDiscoveredModels) _cachedDiscoveredModels = {};
|
|
247
|
+
_cachedDiscoveredModels.antigravity = aLines;
|
|
248
|
+
}
|
|
249
|
+
} catch {}
|
|
202
250
|
} catch {
|
|
203
251
|
// Ignore discovery errors — static catalog remains available
|
|
204
252
|
} finally {
|
|
@@ -277,10 +325,10 @@ export function validateLaunchPlan(raw) {
|
|
|
277
325
|
if (model && model.length > 100) errors.push("model name too long (max 100 chars)");
|
|
278
326
|
|
|
279
327
|
const lead = r.lead === undefined || r.lead === null || String(r.lead).trim() === "" ? "auto" : String(r.lead).trim().toLowerCase();
|
|
280
|
-
if (
|
|
328
|
+
if (lead !== "auto") errors.push(`bad lead mode "${r.lead}" (only "auto" supported)`);
|
|
281
329
|
|
|
282
330
|
const plan = {
|
|
283
|
-
harness, harnesses: harnesses.length > 0 ? harnesses : ["
|
|
331
|
+
harness, harnesses: harnesses.length > 0 ? harnesses : ["opencode"],
|
|
284
332
|
model, body, count: Number.isInteger(count) && count > 0 ? count : 1,
|
|
285
333
|
prefix: r.prefix === undefined ? undefined : String(r.prefix),
|
|
286
334
|
to: r.to === undefined ? undefined : String(r.to),
|