@botbuddy/cli 1.6.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/pw/coordinator.mjs +1 -1
- package/src/pw/host.mjs +17 -0
- package/src/pw/run.mjs +49 -4
- package/src/wait-profile.mjs +4 -0
- package/src/wait.mjs +24 -0
- package/src/botbuddy-release-repair.json +0 -1
package/package.json
CHANGED
package/src/pw/coordinator.mjs
CHANGED
|
@@ -8,5 +8,5 @@ export function createProfileCoordinator({ profile, identity, fetchImpl = fetch
|
|
|
8
8
|
const json = await response.json(); if (json.error) throw new Error(json.error.message || "BotBuddy lock verification failed");
|
|
9
9
|
const text = json.result?.content?.find((item) => item.type === "text")?.text; try { return text ? JSON.parse(text) : {}; } catch { throw new Error("BotBuddy lock verification returned invalid JSON"); }
|
|
10
10
|
}
|
|
11
|
-
return { kind: "profile", async status({ host, slot }) { const result = await call("list_resources", { host, subtype: "playwright_lane" }); const list = Array.isArray(result) ? result : result.resources ?? []; const resource = list.find((item) => item.name === `playwright_lane:${host}:${slot}` || String(item.slot) === String(slot)); return resource ? { held: resource.status !== "free", heldBy: resource.owner_agent_id ?? null } : { held: false, heldBy: null }; }, async emit(event) { await call("record_lane_event", event); }, agentId: identity.agentId };
|
|
11
|
+
return { kind: "profile", async status({ host, slot }) { const result = await call("list_resources", { host, subtype: "playwright_lane" }); const list = Array.isArray(result) ? result : result.resources ?? []; const resource = list.find((item) => item.name === `playwright_lane:${host}:${slot}` || String(item.slot) === String(slot)); return resource ? { held: resource.status !== "free", heldBy: resource.owner_agent_id ?? null, heldByName: resource.agents?.name ?? null } : { held: false, heldBy: null, heldByName: null }; }, async emit(event) { await call("record_lane_event", event); }, agentId: identity.agentId };
|
|
12
12
|
}
|
package/src/pw/host.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// BOT-1488: name the Playwright lane the SAME way the lock kernel stores it.
|
|
2
|
+
// `acquire_resources` canonicalizes the host server-side (normalize_host_string /
|
|
3
|
+
// canonical_host in supabase/functions/_shared/state.ts), so a raw
|
|
4
|
+
// `os.hostname()` like "Jonos-MBP.localdomain" never string-matches the stored
|
|
5
|
+
// "jonos-mbp:<slot>" lane — the gate then refuses a lane the operator holds and
|
|
6
|
+
// prints a lane name that does not exist server-side.
|
|
7
|
+
//
|
|
8
|
+
// This mirrors the PURE string half of the server's normalizeHostString:
|
|
9
|
+
// lowercase + trim + strip a trailing `.local`/`.localdomain`. The server's
|
|
10
|
+
// alias map (canonical_host) is the authority for cross-alias merges; replicating
|
|
11
|
+
// that map here is out of scope for BOT-1488 (and would need invalidation to stay
|
|
12
|
+
// correct), so we fold exactly the case/suffix drift that bites local runs and
|
|
13
|
+
// otherwise defer to the canonical `host` field the server returns.
|
|
14
|
+
export function canonicalizeHostString(host) {
|
|
15
|
+
if (host === null || host === undefined) return host ?? null;
|
|
16
|
+
return String(host).trim().toLowerCase().replace(/\.(local|localdomain)$/, "");
|
|
17
|
+
}
|
package/src/pw/run.mjs
CHANGED
|
@@ -3,14 +3,59 @@ import { planInvocation } from "./args.mjs";
|
|
|
3
3
|
import { actionTypeFromMethod, NAV } from "./readiness.mjs";
|
|
4
4
|
import { isStaleRefError, staleRefRemediation } from "./targets.mjs";
|
|
5
5
|
import { createProfileCoordinator } from "./coordinator.mjs";
|
|
6
|
+
import { canonicalizeHostString } from "./host.mjs";
|
|
6
7
|
import { resolveAgentProfile } from "../wait-profile.mjs";
|
|
7
8
|
import { readProfileIdentity } from "../agent-credential-store.mjs";
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
import { loadConfig, getConfig } from "../config.mjs";
|
|
10
|
+
// BOT-1488: canonicalize the raw hostname the SAME way acquire_resources does
|
|
11
|
+
// server-side, so the lane name bb-pw builds/matches/prints is the one the lock
|
|
12
|
+
// kernel actually stored ("jonos-mbp:8", not "Jonos-MBP.localdomain:8").
|
|
13
|
+
const hostFor = (env) => canonicalizeHostString(env.PLAYWRIGHT_MCP_HOST || env.HOSTNAME || os.hostname());
|
|
14
|
+
function help(out) { out.write("Usage: botbuddy pw [--profile <name>] [--session-id <id>] <lane> <verb> [args…]\n\nAlias: bb-pw <lane> <verb> [args…]\n\n--session-id <id> accept a lane held by this arming-session agent id (from\n register_agent); defaults to $BOTBUDDY_SESSION_ID, then the\n id saved by `botbuddy register`.\n"); }
|
|
10
15
|
function redact(value, secretValues = []) { return secretValues.reduce((text, secret) => secret ? text.split(secret).join("[redacted]") : text, String(value ?? "")); }
|
|
11
|
-
|
|
16
|
+
// BOT-1488: the register_agent identity for this machine, persisted by
|
|
17
|
+
// `botbuddy register` into ~/.botbuddy/config.json. This is the SESSION agent
|
|
18
|
+
// that acquire_resources binds a lane to — distinct from the tenant-bound
|
|
19
|
+
// profile agent the gate historically demanded. bb-pw is not always launched
|
|
20
|
+
// through the `botbuddy` entrypoint (bb-pw.mjs imports runPw directly), so load
|
|
21
|
+
// the config here rather than assuming it is already in memory.
|
|
22
|
+
function readRegisteredAgentId() { try { loadConfig(); const id = getConfig()?.agent_id; return typeof id === "string" && id ? id : null; } catch { return null; } }
|
|
23
|
+
async function gate({ env, host, lane, deps }) {
|
|
24
|
+
if (env.BB_PW_NO_LOCK === "1") return { allowed: true };
|
|
25
|
+
let profile, identity;
|
|
26
|
+
try {
|
|
27
|
+
profile = await (deps.resolveProfile ?? resolveAgentProfile)({ cwd: deps.cwd ?? process.cwd(), env, explicitProfile: deps.profile ?? null });
|
|
28
|
+
identity = await (deps.readIdentity ?? readProfileIdentity)(profile.name);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return { allowed: false, message: `bb-pw: profile verification failed (${error.message}). Run botbuddy profile setup or set BB_PW_NO_LOCK=1 for local-only work.` };
|
|
31
|
+
}
|
|
32
|
+
const coordinator = deps.coordinator ?? createProfileCoordinator({ profile, identity, fetchImpl: deps.fetch });
|
|
33
|
+
if (!profile.token || !identity || identity.tenant !== profile.tenant || coordinator.kind !== "profile") return { allowed: false, message: "bb-pw: profile identity is missing or tenant-mismatched. Run botbuddy profile setup or set BB_PW_NO_LOCK=1 for local-only work." };
|
|
34
|
+
const laneName = `playwright_lane:${host}:${lane}`;
|
|
35
|
+
// The operator's own holder identities: the tenant-bound profile agent (today's
|
|
36
|
+
// happy path) OR the arming session agent — named explicitly with --session-id /
|
|
37
|
+
// $BOTBUDDY_SESSION_ID (BOT-1467 precedent) or read from the local register_agent
|
|
38
|
+
// identity. A foreign operator's agent is in none of these, so the gate stays a
|
|
39
|
+
// real refusal (AC-3).
|
|
40
|
+
const sessionAgentId = deps.sessionId ?? env.BOTBUDDY_SESSION_ID ?? null;
|
|
41
|
+
const registeredAgentId = (deps.readSessionAgentId ?? readRegisteredAgentId)();
|
|
42
|
+
const selfAgentIds = new Set([identity.agentId, sessionAgentId, registeredAgentId].filter(Boolean));
|
|
43
|
+
try {
|
|
44
|
+
const status = await coordinator.status({ host, slot: lane });
|
|
45
|
+
if (status.held && selfAgentIds.has(status.heldBy)) return { allowed: true, coordinator };
|
|
46
|
+
// Distinguish an expired/free lane from one another operator holds so the
|
|
47
|
+
// operator knows whether to re-acquire vs. wait for a handover (BOT-660).
|
|
48
|
+
if (!status.held) return { allowed: false, message: `bb-pw: lane lock ${laneName} is not held (caller ${identity.agentId}). Acquire it via BotBuddy first, or set BB_PW_NO_LOCK=1 for local-only work.` };
|
|
49
|
+
const holder = status.heldBy ?? "unknown";
|
|
50
|
+
const holderName = status.heldByName ? ` (${status.heldByName})` : "";
|
|
51
|
+
return { allowed: false, message: `bb-pw: lane lock ${laneName} is held by ${holder}${holderName}, not you (caller ${identity.agentId}). Acquire it first or set BB_PW_NO_LOCK=1 for local-only work.` };
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return { allowed: false, message: `bb-pw: could not verify lane lock ${laneName} (${error.message}). Set BB_PW_NO_LOCK=1 for local-only work.` };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
12
56
|
export async function runPw(argv, deps = {}) {
|
|
13
|
-
const env = deps.env ?? process.env, stdout = deps.stdout ?? process.stdout, stderr = deps.stderr ?? process.stderr; let args = [...argv]; if (["--help", "-h"].includes(args[0])) { help(stdout); return 0; }
|
|
57
|
+
const env = deps.env ?? process.env, stdout = deps.stdout ?? process.stdout, stderr = deps.stderr ?? process.stderr; let args = [...argv]; if (["--help", "-h"].includes(args[0])) { help(stdout); return 0; }
|
|
58
|
+
while (args[0] === "--profile" || args[0] === "--session-id") { const flag = args[0]; if (!args[1]) { stderr.write(`bb-pw: ${flag} needs a value\n`); return 2; } deps = flag === "--profile" ? { ...deps, profile: args[1] } : { ...deps, sessionId: args[1] }; args = args.slice(2); }
|
|
14
59
|
let plan; try { plan = planInvocation(args, env); } catch (error) { stderr.write(`${error.message}\n`); return 2; }
|
|
15
60
|
const { spawnExec, socketRun } = deps.daemon ?? await import("./daemon.mjs");
|
|
16
61
|
if (plan.scope === "global") { if (plan.mode === "reap") { await (deps.reap ?? (await import("./reap.mjs")).reap)({ env, stdout }); return 0; } if (env.BB_PW_NO_LOCK !== "1") { stderr.write("bb-pw: close-all and kill-all require BB_PW_NO_LOCK=1 because they can affect lanes you do not own.\n"); return 3; } return spawnExec(plan, env); }
|
package/src/wait-profile.mjs
CHANGED
|
@@ -79,6 +79,10 @@ export function withPrincipalReceipt(receipt, profile, registration = {}) {
|
|
|
79
79
|
profile: profile.name,
|
|
80
80
|
tenant_id: registration.sessionTenant ?? profile.tenant,
|
|
81
81
|
agent_id: registration.agentId ?? null,
|
|
82
|
+
// BOT-1467: the arming session's agent, when the relay attributed the wait
|
|
83
|
+
// to it instead of the profile agent (null for an ordinary profile wait).
|
|
84
|
+
session_id: registration.sessionId ?? null,
|
|
85
|
+
session_agent_id: registration.sessionAgentId ?? null,
|
|
82
86
|
},
|
|
83
87
|
};
|
|
84
88
|
}
|
package/src/wait.mjs
CHANGED
|
@@ -93,6 +93,7 @@ OPTIONS
|
|
|
93
93
|
--heartbeat keep this agent session alive while waiting (so it is not reaped)
|
|
94
94
|
--url <base> relay base URL (default $BOTBUDDY_RELAY_URL or https://api.bot-buddy.ai/functions/v1)
|
|
95
95
|
--profile <name> tenant-bound machine profile (normally read from .botbuddy-agent.json)
|
|
96
|
+
--session-id <uuid> attribute this wait to the arming session (the work-graph session id from register_agent); default $BOTBUDDY_SESSION_ID
|
|
96
97
|
--token <key> explicit agent key override; otherwise the profile-specific env is used
|
|
97
98
|
--help show this help
|
|
98
99
|
|
|
@@ -133,6 +134,9 @@ function parseArgv(argv) {
|
|
|
133
134
|
url: process.env.BOTBUDDY_RELAY_URL || "https://api.bot-buddy.ai/functions/v1",
|
|
134
135
|
token: null,
|
|
135
136
|
profile: null,
|
|
137
|
+
// BOT-1467: attribute this wait to the arming session's agent (the id from
|
|
138
|
+
// register_agent) instead of the tenant-bound profile agent. Env fallback.
|
|
139
|
+
sessionId: process.env.BOTBUDDY_SESSION_ID || null,
|
|
136
140
|
help: false,
|
|
137
141
|
};
|
|
138
142
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -155,6 +159,7 @@ function parseArgv(argv) {
|
|
|
155
159
|
else if (a === "--url") opts.url = optionValue();
|
|
156
160
|
else if (a === "--token") opts.token = optionValue();
|
|
157
161
|
else if (a === "--profile") opts.profile = optionValue();
|
|
162
|
+
else if (a === "--session-id") opts.sessionId = optionValue();
|
|
158
163
|
else if (a.startsWith("--")) opts.unknown = a;
|
|
159
164
|
else opts.conditions.push(a);
|
|
160
165
|
}
|
|
@@ -176,6 +181,9 @@ async function registerWait(opts, conditions, deadlineIso) {
|
|
|
176
181
|
action: "register",
|
|
177
182
|
profile: opts.agentProfile.name,
|
|
178
183
|
expected_tenant: opts.agentProfile.tenant,
|
|
184
|
+
// BOT-1467: name the arming work-graph session so the relay resolves and attributes
|
|
185
|
+
// the wait to its agent (validated same-owner) instead of the profile agent.
|
|
186
|
+
...(opts.sessionId ? { session_id: opts.sessionId } : {}),
|
|
179
187
|
client_version: VERSION,
|
|
180
188
|
wait_protocol_version: WAIT_PROTOCOL_VERSION,
|
|
181
189
|
conditions,
|
|
@@ -224,6 +232,11 @@ async function registerWait(opts, conditions, deadlineIso) {
|
|
|
224
232
|
// can't bind to one workspace (ci / pr-review / bare tenant-primary event). A hard
|
|
225
233
|
// stop — arming it untracked would only ever park to timeout.
|
|
226
234
|
"tenant_ambiguous",
|
|
235
|
+
// BOT-1467: a caller-actionable session-attribution rejection — a malformed
|
|
236
|
+
// --session-id, or one passed without a profile. Arming it untracked would
|
|
237
|
+
// only ever park to timeout, so it's a hard stop, not the live-only fallback.
|
|
238
|
+
"invalid_session_agent",
|
|
239
|
+
"session_agent_requires_profile",
|
|
227
240
|
]);
|
|
228
241
|
if (INVALID_CONDITION_CODES.has(body.error)) {
|
|
229
242
|
const err = new Error(body.detail || body.error);
|
|
@@ -293,6 +306,10 @@ async function registerWait(opts, conditions, deadlineIso) {
|
|
|
293
306
|
// new relay (the deploy-skew case, acceptable because waits are short-lived).
|
|
294
307
|
sessionTenant: body.session_tenant ?? null,
|
|
295
308
|
agentId: body.agent_id ?? null,
|
|
309
|
+
// BOT-1467: the session agent the relay attributed the wait to, if any (it
|
|
310
|
+
// echoes session_agent_id only when it overrode the profile agent).
|
|
311
|
+
sessionId: body.session_id ?? null,
|
|
312
|
+
sessionAgentId: body.session_agent_id ?? null,
|
|
296
313
|
};
|
|
297
314
|
}
|
|
298
315
|
|
|
@@ -565,6 +582,9 @@ export async function runWait(argv) {
|
|
|
565
582
|
// pre-BOT-1259 behaviour for a wait the server never scoped.
|
|
566
583
|
let sessionTenant;
|
|
567
584
|
let registeredAgentId = null;
|
|
585
|
+
// BOT-1467: the session agent the relay attributed the wait to (when overridden).
|
|
586
|
+
let registeredSessionAgentId = null;
|
|
587
|
+
let registeredSessionId = null;
|
|
568
588
|
if (needsRelay) {
|
|
569
589
|
try {
|
|
570
590
|
const reg = await registerWait(opts, conditions, new Date(deadlineMs).toISOString());
|
|
@@ -572,6 +592,8 @@ export async function runWait(argv) {
|
|
|
572
592
|
opts.waitSessionId = waitSessionId;
|
|
573
593
|
sessionTenant = reg.sessionTenant;
|
|
574
594
|
registeredAgentId = reg.agentId;
|
|
595
|
+
registeredSessionAgentId = reg.sessionAgentId;
|
|
596
|
+
registeredSessionId = reg.sessionId;
|
|
575
597
|
// BOT-1184: adopt the server's canonical host for each lock condition so the
|
|
576
598
|
// local matcher builds the same subject_key the availability/claim-grant
|
|
577
599
|
// signals carry (armed under an alias like 'jono-mac', the signal uses the
|
|
@@ -709,6 +731,8 @@ export async function runWait(argv) {
|
|
|
709
731
|
withClientIdentity(withPrincipalReceipt(receipt, opts.agentProfile, {
|
|
710
732
|
sessionTenant,
|
|
711
733
|
agentId: registeredAgentId,
|
|
734
|
+
sessionAgentId: registeredSessionAgentId,
|
|
735
|
+
sessionId: registeredSessionId,
|
|
712
736
|
})),
|
|
713
737
|
opts.receiptMaxBytes,
|
|
714
738
|
);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"schema_version":1,"source_version":"1.6.3","source_identity":"2deb439f7afdbb1918d76fe15665ed6ca14c30bcfd5d65524083695cc939814c"}
|