benignswarm 0.12.96 → 0.12.98
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/dist/admin-index.js +0 -0
- package/dist/args.js +40 -3
- package/dist/brief.js +5 -1
- package/dist/client.js +248 -0
- package/dist/commands/admin.js +84 -22
- package/dist/commands/agent.js +15 -2
- package/dist/commands/cloud-admin.js +56 -3
- package/dist/commands/codex-start.js +340 -241
- package/dist/commands/environment-admin.js +130 -0
- package/dist/commands/environment.js +53 -0
- package/dist/commands/evidence.js +6 -3
- package/dist/commands/feedback.js +12 -1
- package/dist/commands/flow.js +153 -0
- package/dist/commands/hook.js +29 -9
- package/dist/commands/image-admin.js +77 -0
- package/dist/commands/install.js +81 -3
- package/dist/commands/lists.js +4 -0
- package/dist/commands/machine-admin.js +444 -111
- package/dist/commands/machine-resize.js +234 -0
- package/dist/commands/machine.js +960 -41
- package/dist/commands/operator.js +5 -8
- package/dist/commands/retire.js +4 -0
- package/dist/commands/templates.js +27 -0
- package/dist/commands/turn.js +21 -0
- package/dist/commands/watch.js +256 -21
- package/dist/commands/wu.js +131 -81
- package/dist/container.js +480 -0
- package/dist/environment-checks.js +79 -0
- package/dist/git.js +28 -0
- package/dist/help.js +94 -37
- package/dist/index.js +7 -1
- package/dist/install.js +43 -1
- package/dist/macos-readiness.js +173 -0
- package/dist/output.js +17 -4
- package/dist/templates.js +218 -0
- package/dist/test-workers.js +17 -0
- package/dist/turn-guard.js +5 -5
- package/dist/turn.js +6 -0
- package/dist/usage.js +117 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, join as joinPath } from "node:path";
|
|
5
|
-
import { bool, repeated, str } from "../args.js";
|
|
5
|
+
import { bool, parse, repeated, str } from "../args.js";
|
|
6
6
|
import { configRoot } from "../config.js";
|
|
7
7
|
import { startAgentIdentity, startEnrollmentIdentity, startWritableRoots } from "../start-options.js";
|
|
8
8
|
import { CliError } from "../errors.js";
|
|
9
|
-
import { requireInstall } from "../install.js";
|
|
10
|
-
import { bindSession, codexArchivedRollout, codexRollout } from "../sessions.js";
|
|
9
|
+
import { provisionContainerInstallRecord, requireInstall } from "../install.js";
|
|
10
|
+
import { bindSession, codexArchivedRollout, codexRollout, sessionOfExec } from "../sessions.js";
|
|
11
11
|
import { codexHooksPath } from "./codex.js";
|
|
12
12
|
import { isCodexManagedRequirements } from "../harness.js";
|
|
13
13
|
import { readState, writeState } from "../state.js";
|
|
14
14
|
import { join } from "./join.js";
|
|
15
|
-
import { beginTurnGuardAttempt, completePendingTurnGuard, installWatcherService } from "./watch.js";
|
|
15
|
+
import { beginTurnGuardAttempt, completePendingTurnGuard, installWatcherService, turnArgs, watch } from "./watch.js";
|
|
16
16
|
import { randomUUID } from "node:crypto";
|
|
17
17
|
import { HARNESS_BIN, HARNESS_LABEL, assertClaudeSelfCheck, claudeCodePath, claudeResultError, claudeResultFile, claudeSandboxEnv, claudeSettings, claudeTranscript, claudeTurnArgs, dshPath, dshResultError, dshSessionFromEvents, dshSettings, dshTurnLog, probeFor } from "../harnesses.js";
|
|
18
18
|
import { claudeTurnEnv } from "../providers.js";
|
|
19
19
|
import { DEFAULT_TURNS_PER_HOUR, DEFAULT_UNPRODUCTIVE_PER_HOUR, MAX_TURNS_PER_HOUR } from "../turn-guard.js";
|
|
20
|
+
import { DEFAULT_TURN_COALESCE_SECONDS, MAX_TURN_COALESCE_SECONDS } from "../turn.js";
|
|
20
21
|
import { antigravityConversationDb, antigravityLog, antigravityResumeCommand, antigravitySettings, antigravityTotalTokens, antigravityTurnArgs, antigravityTurnEnv, runAntigravityTurn } from "../antigravity.js";
|
|
21
22
|
import { configureGitCredentialForWorktree } from "./git-credential.js";
|
|
22
23
|
const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
|
|
@@ -51,261 +52,359 @@ export function startJoinArgs(p, harness, model) {
|
|
|
51
52
|
...(identity.project ? { expectedProject: identity.project } : {}),
|
|
52
53
|
};
|
|
53
54
|
}
|
|
55
|
+
export function containerStatusFile(kind, agentRef) {
|
|
56
|
+
const slug = agentRef.replace("/", ".");
|
|
57
|
+
return joinPath(configRoot(), "logs", `container-${kind}.${slug}.json`);
|
|
58
|
+
}
|
|
59
|
+
function writeContainerStatusFile(file, payload) {
|
|
60
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
61
|
+
const tmp = `${file}.tmp-${process.pid}`;
|
|
62
|
+
writeFileSync(tmp, JSON.stringify(payload, null, 2) + "\n");
|
|
63
|
+
renameSync(tmp, file);
|
|
64
|
+
}
|
|
54
65
|
export async function harnessStart(p, out, harness) {
|
|
55
66
|
const label = HARNESS_LABEL[harness];
|
|
56
67
|
const cmd = harness === "codex" ? "codex start" : "start";
|
|
57
68
|
const name = str(p.flags, "as");
|
|
58
69
|
if (!name)
|
|
59
70
|
throw new CliError("usage", `${cmd} needs --as <agent-name>`);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
const initialTurnPending = priorState.turn_guard?.turns.some((attempt) => attempt.productive === null) ?? false;
|
|
152
|
-
const rememberedSession = initialTurnPending && priorState.harness_session?.harness === harness ? priorState.harness_session.session_id : null;
|
|
153
|
-
const adopt = requestedAdopt ?? rememberedSession ?? undefined;
|
|
154
|
-
requireInstall();
|
|
155
|
-
// 2. Its session: adopt one, or start one headless with an onboarding turn.
|
|
156
|
-
let session;
|
|
157
|
-
let initialPid;
|
|
158
|
-
let firstTurnLog = null;
|
|
159
|
-
if (harness === "dsh")
|
|
160
|
-
firstTurnLog = dshTurnLog(ref);
|
|
161
|
-
if (harness === "antigravity")
|
|
162
|
-
firstTurnLog = antigravityLog(ref);
|
|
163
|
-
if (adopt) {
|
|
164
|
-
session = adopt.toLowerCase();
|
|
165
|
-
if (harness === "codex") {
|
|
166
|
-
if (!codexRollout(session)) {
|
|
167
|
-
if (codexArchivedRollout(session))
|
|
168
|
-
throw new CliError("archived", `Codex thread ${session} is archived (its session file is in ~/.codex/archived_sessions)`, "Unarchive it in the Codex app, then leave it unopened there and run this again");
|
|
169
|
-
throw new CliError("not_found", `no Codex session file for thread ${session} under ~/.codex/sessions on this machine`);
|
|
170
|
-
}
|
|
171
|
-
lines.push(`Adopted Codex thread ${session}. Leave it unopened in the Codex app (do not archive it: that moves its session file away): from now on the watcher runs its turns, and two clients on one thread conflict.`);
|
|
71
|
+
const machineSessionId = str(p.flags, "machine-session-id");
|
|
72
|
+
if (machineSessionId && !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(machineSessionId))
|
|
73
|
+
throw new CliError("usage", "--machine-session-id must be a UUID");
|
|
74
|
+
if (machineSessionId)
|
|
75
|
+
process.env.BSCHAT_MACHINE_SESSION_ID = machineSessionId;
|
|
76
|
+
const inContainer = bool(p.flags, "in-container");
|
|
77
|
+
let errorSlug = name;
|
|
78
|
+
let watchArgv = null;
|
|
79
|
+
let watcherEnv = {};
|
|
80
|
+
try {
|
|
81
|
+
const sandbox = str(p.flags, "sandbox");
|
|
82
|
+
// No default: what a headless agent may touch on this machine is the operator's call, every time.
|
|
83
|
+
if (!sandbox || !SANDBOXES.includes(sandbox))
|
|
84
|
+
throw new CliError("usage", `${cmd} needs --sandbox <${SANDBOXES.join("|")}>: what the agent may do on this machine, since a headless turn cannot ask for approval`);
|
|
85
|
+
if (harness === "antigravity" && sandbox === "read-only")
|
|
86
|
+
throw new CliError("unsupported", "Antigravity has no read-only permission mode; use workspace-write or danger-full-access");
|
|
87
|
+
const turnTimeout = Number(str(p.flags, "turn-timeout") ?? "180");
|
|
88
|
+
if (!Number.isInteger(turnTimeout) || turnTimeout < 5)
|
|
89
|
+
throw new CliError("usage", "--turn-timeout must be a whole number of minutes, at least 5");
|
|
90
|
+
const turnsPerHour = Number(str(p.flags, "turns-per-hour") ?? String(DEFAULT_TURNS_PER_HOUR));
|
|
91
|
+
if (!Number.isInteger(turnsPerHour) || turnsPerHour < 1 || turnsPerHour > MAX_TURNS_PER_HOUR)
|
|
92
|
+
throw new CliError("usage", `--turns-per-hour must be a whole number between 1 and ${MAX_TURNS_PER_HOUR}`);
|
|
93
|
+
const unproductivePerHour = Number(str(p.flags, "unproductive-per-hour") ?? String(DEFAULT_UNPRODUCTIVE_PER_HOUR));
|
|
94
|
+
if (!Number.isInteger(unproductivePerHour) || unproductivePerHour < 1 || unproductivePerHour > 60)
|
|
95
|
+
throw new CliError("usage", "--unproductive-per-hour must be a whole number between 1 and 60");
|
|
96
|
+
const turnCoalesceSeconds = Number(str(p.flags, "turn-coalesce-seconds") ?? String(DEFAULT_TURN_COALESCE_SECONDS));
|
|
97
|
+
if (!Number.isInteger(turnCoalesceSeconds) || turnCoalesceSeconds < 0 || turnCoalesceSeconds > MAX_TURN_COALESCE_SECONDS)
|
|
98
|
+
throw new CliError("usage", `--turn-coalesce-seconds must be a whole number between 0 and ${MAX_TURN_COALESCE_SECONDS}`);
|
|
99
|
+
const interval = Number(str(p.flags, "interval") ?? "30");
|
|
100
|
+
if (!Number.isInteger(interval) || interval < 5)
|
|
101
|
+
throw new CliError("usage", "--interval must be an integer number of seconds, at least 5");
|
|
102
|
+
if (!inContainer && process.platform !== "darwin" && process.platform !== "linux")
|
|
103
|
+
throw new CliError("unsupported", `${cmd} installs its watcher with launchd (macOS) or systemd (Linux)`);
|
|
104
|
+
const dshOverride = str(p.flags, "dsh");
|
|
105
|
+
if (harness !== "dsh" && dshOverride)
|
|
106
|
+
throw new CliError("usage", "--dsh is only valid with --harness dsh");
|
|
107
|
+
const agyOverride = str(p.flags, "agy");
|
|
108
|
+
if (harness !== "antigravity" && agyOverride)
|
|
109
|
+
throw new CliError("usage", "--agy is only valid with --harness antigravity");
|
|
110
|
+
const providerName = str(p.flags, "provider") ?? "anthropic";
|
|
111
|
+
if (providerName !== "anthropic" && providerName !== "deepseek")
|
|
112
|
+
throw new CliError("usage", "--provider must be anthropic or deepseek");
|
|
113
|
+
const provider = providerName;
|
|
114
|
+
if (provider === "deepseek" && harness !== "claude-code")
|
|
115
|
+
throw new CliError("usage", "--provider deepseek requires --harness claude-code");
|
|
116
|
+
const providerModel = str(p.flags, "model") ?? (provider === "deepseek" ? "deepseek-flash" : undefined);
|
|
117
|
+
const budgetFlag = str(p.flags, "max-budget-usd");
|
|
118
|
+
if (budgetFlag !== undefined && (harness !== "claude-code" || sandbox !== "workspace-write"))
|
|
119
|
+
throw new CliError("usage", "--max-budget-usd is only valid for Claude Code workspace-write sessions");
|
|
120
|
+
const maxBudgetUsd = budgetFlag === undefined ? DEFAULT_CLAUDE_MAX_BUDGET_USD : Number(budgetFlag);
|
|
121
|
+
if (harness === "claude-code" && sandbox === "workspace-write" && (!Number.isFinite(maxBudgetUsd) || maxBudgetUsd <= 0))
|
|
122
|
+
throw new CliError("usage", "--max-budget-usd must be a positive dollar amount");
|
|
123
|
+
const model = providerModel;
|
|
124
|
+
if (harness === "antigravity" && !model)
|
|
125
|
+
throw new CliError("usage", "--model is required with --harness antigravity (for example gemini-4-hydrogen-low)");
|
|
126
|
+
const bin = harness === "dsh"
|
|
127
|
+
? dshPath(dshOverride)
|
|
128
|
+
: harness === "antigravity"
|
|
129
|
+
? agyOverride ?? which(HARNESS_BIN[harness], "install Antigravity CLI (agy) and log in on this machine")
|
|
130
|
+
: harness === "claude-code" && sandbox === "workspace-write"
|
|
131
|
+
? claudeCodePath() ?? (() => { throw new CliError("not_found", "Claude Code was not found on PATH or under ~/.local/share/claude/versions; add the native installer's active version to PATH or install Claude Code with `npm i -g @anthropic-ai/claude-code`"); })()
|
|
132
|
+
: which(HARNESS_BIN[harness], harness === "codex" ? "install the Codex CLI (npm i -g @openai/codex)" : "install Claude Code (npm i -g @anthropic-ai/claude-code)");
|
|
133
|
+
if (!bin)
|
|
134
|
+
throw new CliError("not_found", "DeepSeek Harness CLI dsh was not found; install DeepSeek Harness or pass --dsh <path>");
|
|
135
|
+
if (harness === "dsh" && !existsSync(bin))
|
|
136
|
+
throw new CliError("not_found", `DeepSeek Harness CLI ${bin} does not exist; pass --dsh <path> to its runtime/cli/bin/dsh`);
|
|
137
|
+
const effort = str(p.flags, "effort");
|
|
138
|
+
const requestedAdopt = str(p.flags, "thread") ?? str(p.flags, "session");
|
|
139
|
+
// Machine-configured folders and explicit extra roots are combined with existing package caches
|
|
140
|
+
// only for workspace-write. Full-access sessions keep their previous root settings.
|
|
141
|
+
const machineWritable = (str(p.flags, "writable") ?? "").split(",").map((w) => w.trim()).filter(Boolean);
|
|
142
|
+
const explicitWritable = repeated(p, "writable-root").map((w) => w.trim());
|
|
143
|
+
const writable = startWritableRoots(sandbox, machineWritable, explicitWritable);
|
|
144
|
+
// Refuses a sandbox the harness cannot honour before anything is enrolled.
|
|
145
|
+
let settings = harness === "codex"
|
|
146
|
+
? codexSettings(sandbox, model, effort, process.cwd(), configRoot(), [...writable, ...ownWorktreeGitDir(process.cwd())])
|
|
147
|
+
: harness === "dsh"
|
|
148
|
+
? dshSettings(sandbox, process.cwd(), configRoot(), [...writable, ...ownWorktreeGitDir(process.cwd())])
|
|
149
|
+
: harness === "claude-code" ? claudeSettings(sandbox, model, effort, process.cwd(), configRoot(), writable) : [];
|
|
150
|
+
const providerEnv = { ...claudeTurnEnv(harness === "claude-code" ? provider : undefined, model), ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}) };
|
|
151
|
+
if ((harness === "claude-code" || harness === "antigravity") && sandbox === "workspace-write")
|
|
152
|
+
configureHttpsOriginForWorktree(process.cwd());
|
|
153
|
+
// 1. Who: enroll with the invite token, or use credentials already on this machine.
|
|
154
|
+
const lines = [];
|
|
155
|
+
const token = str(p.flags, "token");
|
|
156
|
+
if (token) {
|
|
157
|
+
const joined = [];
|
|
158
|
+
const enrollment = startJoinArgs(p, harness, model);
|
|
159
|
+
await join(enrollment.parsed, { json: false, print: (h) => joined.push(h) }, enrollment.expectedProject);
|
|
160
|
+
lines.push(joined.join("\n").split("\n")[0]);
|
|
172
161
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
162
|
+
const { credentials: creds, ref } = startAgentIdentity(name);
|
|
163
|
+
errorSlug = ref;
|
|
164
|
+
if ((harness === "claude-code" || harness === "antigravity") && sandbox === "workspace-write")
|
|
165
|
+
configureHttpsOriginForWorktree(process.cwd());
|
|
166
|
+
await configureGitCredentialForWorktree(process.cwd(), creds);
|
|
167
|
+
if (creds.vendor && creds.vendor !== harness)
|
|
168
|
+
throw new CliError("vendor_mismatch", `${ref} is saved as ${creds.vendor}, not ${harness}`);
|
|
169
|
+
if (harness === "antigravity")
|
|
170
|
+
settings = antigravitySettings(sandbox, process.cwd(), configRoot(), new URL(creds.url).host, [...writable, ...ownWorktreeGitDir(process.cwd())]);
|
|
171
|
+
const priorState = readState(ref);
|
|
172
|
+
if (priorState.turn_guard?.fault) {
|
|
173
|
+
const fault = priorState.turn_guard.fault;
|
|
174
|
+
throw new CliError("turn_mode_fault", `turn mode is stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; resume it with b9s-admin machine session resume; last output: ${fault.output_tail || "(empty)"}`);
|
|
175
|
+
}
|
|
176
|
+
const initialTurnPending = priorState.turn_guard?.turns.some((attempt) => attempt.productive === null) ?? false;
|
|
177
|
+
const rememberedSession = initialTurnPending && priorState.harness_session?.harness === harness ? priorState.harness_session.session_id : null;
|
|
178
|
+
const adopt = requestedAdopt ?? rememberedSession ?? undefined;
|
|
179
|
+
if (inContainer)
|
|
180
|
+
provisionContainerInstallRecord();
|
|
181
|
+
const install = requireInstall();
|
|
182
|
+
// 2. Its session: adopt one, or start one headless with an onboarding turn.
|
|
183
|
+
let session;
|
|
184
|
+
let initialPid;
|
|
185
|
+
let firstTurnLog = null;
|
|
186
|
+
if (harness === "dsh")
|
|
187
|
+
firstTurnLog = dshTurnLog(ref);
|
|
188
|
+
if (harness === "antigravity")
|
|
189
|
+
firstTurnLog = antigravityLog(ref);
|
|
190
|
+
if (adopt) {
|
|
191
|
+
session = adopt.toLowerCase();
|
|
192
|
+
if (harness === "codex") {
|
|
193
|
+
if (!codexRollout(session)) {
|
|
194
|
+
if (codexArchivedRollout(session))
|
|
195
|
+
throw new CliError("archived", `Codex thread ${session} is archived (its session file is in ~/.codex/archived_sessions)`, "Unarchive it in the Codex app, then leave it unopened there and run this again");
|
|
196
|
+
throw new CliError("not_found", `no Codex session file for thread ${session} under ~/.codex/sessions on this machine`);
|
|
179
197
|
}
|
|
180
|
-
lines.push(`Adopted
|
|
181
|
-
}
|
|
182
|
-
else if (harness === "dsh") {
|
|
183
|
-
mkdirSync(joinPath(configRoot(), "logs"), { recursive: true });
|
|
184
|
-
closeSync(openSync(dshTurnLog(ref), "a"));
|
|
185
|
-
lines.push(`Adopted DeepSeek Harness session ${session}. Do not resume it elsewhere while the watcher runs it: two clients on one session conflict.`);
|
|
198
|
+
lines.push(`Adopted Codex thread ${session}. Leave it unopened in the Codex app (do not archive it: that moves its session file away): from now on the watcher runs its turns, and two clients on one thread conflict.`);
|
|
186
199
|
}
|
|
187
200
|
else {
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
|
|
201
|
+
if (harness === "claude-code") {
|
|
202
|
+
if (!claudeTranscript(session))
|
|
203
|
+
throw new CliError("not_found", `no Claude Code transcript for session ${session} under ~/.claude/projects on this machine`);
|
|
204
|
+
if (sandbox === "workspace-write") {
|
|
205
|
+
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), randomUUID(), undefined, unproductivePerHour);
|
|
206
|
+
}
|
|
207
|
+
lines.push(`Adopted Claude Code session ${session}. Do not resume it in a terminal while the watcher runs it: two clients on one session conflict.`);
|
|
208
|
+
}
|
|
209
|
+
else if (harness === "dsh") {
|
|
210
|
+
mkdirSync(joinPath(configRoot(), "logs"), { recursive: true });
|
|
211
|
+
closeSync(openSync(dshTurnLog(ref), "a"));
|
|
212
|
+
lines.push(`Adopted DeepSeek Harness session ${session}. Do not resume it elsewhere while the watcher runs it: two clients on one session conflict.`);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (!existsSync(antigravityConversationDb(session)))
|
|
216
|
+
throw new CliError("not_found", `no Antigravity conversation database for ${session} under ~/.gemini/antigravity-cli/conversations`);
|
|
217
|
+
lines.push(`Adopted Antigravity conversation ${session}. Do not resume it elsewhere while the watcher runs it: two clients on one conversation conflict.`);
|
|
218
|
+
}
|
|
219
|
+
if (harness === "antigravity" && sandbox === "workspace-write")
|
|
220
|
+
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
191
221
|
}
|
|
192
|
-
if (harness === "antigravity" && sandbox === "workspace-write")
|
|
193
|
-
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
194
222
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), session, undefined, unproductivePerHour);
|
|
202
|
-
}
|
|
203
|
-
const logDir = joinPath(configRoot(), "logs");
|
|
204
|
-
mkdirSync(logDir, { recursive: true });
|
|
205
|
-
firstTurnLog = harness === "dsh" ? dshTurnLog(ref) : harness === "claude-code" ? claudeResultFile(ref) : harness === "antigravity" ? antigravityLog(ref) : joinPath(logDir, `${harness}.${ref.replace("/", ".")}.first-turn.jsonl`);
|
|
206
|
-
const prompt = [
|
|
207
|
-
`[b9s] You are ${ref}, a BenignSwarm agent, started headless by \`b9s ${cmd}\`; nobody is typing to you.`,
|
|
208
|
-
`Your watcher starts a turn for you whenever something needs you, so end your turn when nothing is left to do.`,
|
|
209
|
-
`Now: run \`b9s me\`, \`b9s process\` and \`b9s inbox --unread\`, then do what your role and inbox ask.`,
|
|
210
|
-
`If you ran on another machine before, read your latest note first: \`b9s handoffs --agent ${creds.agent}\` (your units, branches and chat are on the server as before).`,
|
|
211
|
-
].join("\n");
|
|
212
|
-
const diagnostic = [];
|
|
213
|
-
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (m) => diagnostic.push(m), process.env, unproductivePerHour))) {
|
|
214
|
-
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the onboarding turn");
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
if (harness === "codex") {
|
|
218
|
-
session = await startThread(bin, ["exec", "--json", ...settings, prompt], firstTurnLog, ref);
|
|
219
|
-
lines.push(`Started Codex thread ${session}; its first turn (reading its role and inbox) is running, log: ${firstTurnLog}`);
|
|
223
|
+
else {
|
|
224
|
+
// The proxy/Git preflight spends model tokens, so it is its own guarded harness launch. The
|
|
225
|
+
// first real turn resumes this same checked session and receives a separate reservation below.
|
|
226
|
+
if (harness === "claude-code" && sandbox === "workspace-write") {
|
|
227
|
+
session = randomUUID();
|
|
228
|
+
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), session, undefined, unproductivePerHour);
|
|
220
229
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
230
|
+
const logDir = joinPath(configRoot(), "logs");
|
|
231
|
+
mkdirSync(logDir, { recursive: true });
|
|
232
|
+
firstTurnLog = harness === "dsh" ? dshTurnLog(ref) : harness === "claude-code" ? claudeResultFile(ref) : harness === "antigravity" ? antigravityLog(ref) : joinPath(logDir, `${harness}.${ref.replace("/", ".")}.first-turn.jsonl`);
|
|
233
|
+
const prompt = [
|
|
234
|
+
`[b9s] You are ${ref}, a BenignSwarm agent, started headless by \`b9s ${cmd}\`; nobody is typing to you.`,
|
|
235
|
+
`Your watcher starts a turn for you whenever something needs you, so end your turn when nothing is left to do.`,
|
|
236
|
+
`Now: run \`b9s me\`, \`b9s process\` and \`b9s inbox --unread\`, then do what your role and inbox ask.`,
|
|
237
|
+
`If you ran on another machine before, read your latest note first: \`b9s handoffs --agent ${creds.agent}\` (your units, branches and chat are on the server as before).`,
|
|
238
|
+
].join("\n");
|
|
239
|
+
const diagnostic = [];
|
|
240
|
+
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (m) => diagnostic.push(m), process.env, unproductivePerHour, process.env.BSCHAT_MACHINE_SESSION_ID, harness))) {
|
|
241
|
+
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the onboarding turn");
|
|
226
242
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
await
|
|
243
|
+
try {
|
|
244
|
+
if (harness === "codex") {
|
|
245
|
+
session = await startThread(bin, ["exec", "--json", ...settings, prompt], firstTurnLog, ref);
|
|
246
|
+
lines.push(`Started Codex thread ${session}; its first turn (reading its role and inbox) is running, log: ${firstTurnLog}`);
|
|
247
|
+
}
|
|
248
|
+
else if (harness === "dsh") {
|
|
249
|
+
const started = await startDshSession(bin, dshStartArgs(settings), firstTurnLog, ref, prompt);
|
|
250
|
+
session = started.session;
|
|
251
|
+
initialPid = started.pid;
|
|
252
|
+
lines.push(`Started DeepSeek Harness session ${session}; its first turn (reading its role and inbox) is running, event log: ${firstTurnLog}`);
|
|
253
|
+
}
|
|
254
|
+
else if (harness === "antigravity") {
|
|
255
|
+
const started = runAntigravityTurn(bin, antigravityTurnArgs(prompt, model, effort, turnTimeout * 60, settings), firstTurnLog, process.cwd(), ref, undefined, undefined, antigravityTurnEnv(sandbox));
|
|
256
|
+
session = started.conversation;
|
|
257
|
+
await completePendingTurnGuard(ref, probeFor(harness, session, ref), (message) => diagnostic.push(message), started.output, antigravityTokenTotal(started.record.result?.usage));
|
|
258
|
+
lines.push(`Started Antigravity conversation ${session}; its first turn (reading its role and inbox) completed, JSON turn log: ${firstTurnLog}`);
|
|
259
|
+
if (sandbox === "workspace-write")
|
|
260
|
+
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// Claude Code takes the session id from us, so nothing has to be read back from its output.
|
|
264
|
+
session ??= randomUUID();
|
|
265
|
+
await startClaudeSession(bin, ["-p", prompt, ...settings, ...(sandbox === "workspace-write" ? claudeTurnArgs(maxBudgetUsd) : []), ...claudeSessionStartArgs(sandbox, session), "--output-format", "json"], firstTurnLog, ref, session, providerEnv, model, provider);
|
|
266
|
+
lines.push(`Started Claude Code session ${session}; its first turn (reading its role and inbox) is running, result: ${firstTurnLog}`);
|
|
267
|
+
}
|
|
234
268
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
session
|
|
238
|
-
|
|
239
|
-
|
|
269
|
+
catch (error) {
|
|
270
|
+
const raw = existsSync(firstTurnLog) ? readFileSync(firstTurnLog, "utf8").slice(-800) : "";
|
|
271
|
+
await completePendingTurnGuard(ref, probeFor(harness, session ?? "", ref), (m) => diagnostic.push(m), `${error.message}\n${raw}`.slice(-800));
|
|
272
|
+
const fault = readState(ref).turn_guard?.fault;
|
|
273
|
+
if (fault)
|
|
274
|
+
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
275
|
+
throw error;
|
|
240
276
|
}
|
|
241
277
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
278
|
+
if (!session)
|
|
279
|
+
throw new CliError("harness_failed", "the harness did not provide a session id");
|
|
280
|
+
// 3. Bind it, so the hooks in that session deliver to this agent and nobody else. Claude Code's
|
|
281
|
+
// hook knows the agent from BSCHAT_AGENT (the watcher sets it for every turn), so it needs no map.
|
|
282
|
+
if (harness === "codex")
|
|
283
|
+
bindSession("codex", session, ref);
|
|
284
|
+
if (harness === "antigravity")
|
|
285
|
+
bindSession("antigravity", session, ref);
|
|
286
|
+
const transcript = harness === "dsh" ? dshTurnLog(ref) : harness === "antigravity" ? antigravityLog(ref) : harness === "claude-code" ? claudeTranscript(session) ?? firstTurnLog ?? "" : codexRollout(session) ?? firstTurnLog ?? "";
|
|
287
|
+
writeState(ref, { ...readState(ref), harness_session: { harness, transcript, session_id: session, at: Date.now(), ...(model ? { model } : {}), ...(harness === "claude-code" ? { provider } : {}), ...(initialPid ? { initial_pid: initialPid } : {}) } });
|
|
288
|
+
// A session adopted here may end in a usage-limit error from the machine it came from, written in
|
|
289
|
+
// that machine's local time ("3:32 PM" Central read as UTC on ronald: six hours off). Only errors
|
|
290
|
+
// from turns on this machine pause it; if the account is still limited, the next turn says so here.
|
|
291
|
+
if (adopt)
|
|
292
|
+
writeState(ref, { ...readState(ref), turn_unpaused_at: Date.now() });
|
|
293
|
+
// 4. The watcher, in turn mode: it runs each later turn itself.
|
|
294
|
+
const exec = harness === "codex"
|
|
295
|
+
? [bin, "exec", "resume", session, ...settings].map(shq).join(" ") + " {text}"
|
|
296
|
+
: harness === "dsh"
|
|
297
|
+
? dshResumeCommand(bin, session, settings, dshTurnLog(ref))
|
|
298
|
+
: harness === "antigravity"
|
|
299
|
+
? antigravityResumeCommand(bin, session, model, effort, turnTimeout * 60, settings, antigravityLog(ref))
|
|
300
|
+
// The result goes to a file the watcher reads when the turn ends: Claude Code can exit 0 with is_error set.
|
|
301
|
+
: `${shq(bin)} -p {text} ${[...settings, ...(sandbox === "workspace-write" ? claudeTurnArgs(maxBudgetUsd) : []), "--resume", session, "--output-format", "json"].map(shq).join(" ")} > ${shq(claudeResultFile(ref))}`;
|
|
302
|
+
const watcherOut = [];
|
|
303
|
+
// Scratch space beside the checkout, not the system's /tmp: on a machine the checkout lives on the
|
|
304
|
+
// work volume, the folder is inside what the sandbox may write, and it survives a reboot. Learned
|
|
305
|
+
// from ronald, whose root volume filled with agents' builds under /tmp (46 GB) while the work
|
|
306
|
+
// volume had 750 GB free, and which empties /tmp at every boot.
|
|
307
|
+
const tmp = sessionTmpDir(process.cwd(), creds.agent);
|
|
308
|
+
mkdirSync(tmp, { recursive: true });
|
|
309
|
+
const followDelay = Number(str(p.flags, "follow-delay") ?? "300");
|
|
310
|
+
const prune = bool(p.flags, "prune");
|
|
311
|
+
watcherEnv = { TMPDIR: tmp, ...(machineSessionId ? { BSCHAT_MACHINE_SESSION_ID: machineSessionId } : {}), ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}), ...(harness === "antigravity" ? { BSCHAT_HARNESS: "antigravity", BSCHAT_ANTIGRAVITY_SANDBOX: sandbox, BSCHAT_MODEL: model, ...(effort ? { BSCHAT_EFFORT: effort } : {}) } : {}) };
|
|
312
|
+
const turnSpec = { harness, session, timeout: turnTimeout, turnsPerHour, unproductivePerHour, coalesceSeconds: turnCoalesceSeconds, provider, model, ...(machineSessionId ? { machineSessionId } : {}) };
|
|
313
|
+
if (inContainer) {
|
|
314
|
+
const sess = sessionOfExec(exec);
|
|
315
|
+
if (sess)
|
|
316
|
+
bindSession(sess.kind, sess.id, ref);
|
|
317
|
+
writeContainerStatusFile(containerStatusFile("watcher", ref), {
|
|
318
|
+
agent: ref,
|
|
319
|
+
bin: install.bin,
|
|
320
|
+
exec,
|
|
321
|
+
interval,
|
|
322
|
+
follow_delay: followDelay,
|
|
323
|
+
prune,
|
|
324
|
+
turn: turnSpec,
|
|
325
|
+
env_keys: Object.keys(watcherEnv),
|
|
326
|
+
cwd: process.cwd(),
|
|
327
|
+
pid: process.pid,
|
|
328
|
+
started_at: new Date().toISOString(),
|
|
329
|
+
});
|
|
330
|
+
lines.push(`Watcher: running in-container via ${install.bin} watch --turn (PID ${process.pid}).`);
|
|
331
|
+
watchArgv = [
|
|
332
|
+
"watch",
|
|
333
|
+
"--as", ref,
|
|
334
|
+
"--exec", exec,
|
|
335
|
+
"--interval", String(interval),
|
|
336
|
+
"--follow-delay", String(followDelay),
|
|
337
|
+
...(prune ? ["--prune"] : []),
|
|
338
|
+
...turnArgs(turnSpec),
|
|
339
|
+
];
|
|
249
340
|
}
|
|
341
|
+
else {
|
|
342
|
+
installWatcherService(ref, exec, interval, followDelay, watcherEnv, undefined, { json: false, print: (h) => watcherOut.push(h) }, prune, turnSpec);
|
|
343
|
+
const wl = watcherOut.join("\n").split("\n");
|
|
344
|
+
lines.push(wl[0].replace(/^Wrote /, "Watcher: wrote "), ...wl.filter((l) => l.startsWith("Linger is off")));
|
|
345
|
+
}
|
|
346
|
+
// 5. Hooks.
|
|
347
|
+
let missing = [];
|
|
348
|
+
if (harness === "codex") {
|
|
349
|
+
// A headless turn cannot show Codex's trust prompt, and b9s never pre-approves it.
|
|
350
|
+
missing = untrustedHooks();
|
|
351
|
+
lines.push(missing.length
|
|
352
|
+
? `Codex has not trusted b9s's hooks (${missing.join(", ")}) on this machine, so turns run without them: no standing rules at session start, no continuing when work arrives mid-turn. Wake-ups still work. To trust them, run \`codex\` once in a terminal here and approve the hooks when it asks.`
|
|
353
|
+
: `Codex has trust entries for b9s's hooks here. If they changed since they were trusted, Codex skips them until approved again in an interactive \`codex\`.`);
|
|
354
|
+
}
|
|
355
|
+
else if (harness === "dsh") {
|
|
356
|
+
lines.push("DeepSeek Harness runs the headless profile without an interactive approval prompt; b9s identifies this agent through BSCHAT_AGENT on each turn.");
|
|
357
|
+
}
|
|
358
|
+
else if (harness === "antigravity") {
|
|
359
|
+
lines.push("Antigravity runs headless turns with the machine's cached agy login; b9s binds this conversation and records JSON token usage.");
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
lines.push(`Claude Code runs b9s's hooks from this checkout's .claude/settings.local.json (written by join).`);
|
|
363
|
+
}
|
|
364
|
+
lines.push(`Follow it: tail -f ~/.b9s/logs/watch.${ref.replace("/", ".")}.err.log; ${harness === "codex" ? `read its thread with codex resume ${session}` : harness === "dsh" ? `read its events in ${dshTurnLog(ref)} or resume with dsh --profile headless --json --session-id ${session}` : harness === "antigravity" ? `inspect its recorded turns in ${antigravityLog(ref)}` : `read its transcript under ~/.claude/projects (session ${session})`} only while no turn is running.`);
|
|
365
|
+
lines.push(harness === "dsh"
|
|
366
|
+
? `DeepSeek Harness failures, including balance or rate limits, are recorded and retried after the ordinary 5-minute backoff; no reset time is inferred from their text.`
|
|
367
|
+
: harness === "antigravity" ? `Antigravity failures, including quota errors, are recorded verbatim and retried after the ordinary 5-minute backoff; no reset time is inferred from their text.`
|
|
368
|
+
: `If the ${label} account hits its usage limit, the watcher pauses turns until the time ${label} gives; after switching to an account with quota, resume at once: b9s unpause --as ${ref}`);
|
|
369
|
+
const startPayload = { agent: ref, harness, provider, thread: session, session, sandbox, model: model ?? null, effort: effort ?? null, exec, first_turn_log: firstTurnLog, untrusted_hooks: missing };
|
|
370
|
+
if (inContainer) {
|
|
371
|
+
writeContainerStatusFile(containerStatusFile("start", ref), {
|
|
372
|
+
...startPayload,
|
|
373
|
+
container: true,
|
|
374
|
+
pid: process.pid,
|
|
375
|
+
started_at: new Date().toISOString(),
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
out.print(lines.join("\n"), startPayload);
|
|
250
379
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// that machine's local time ("3:32 PM" Central read as UTC on ronald: six hours off). Only errors
|
|
263
|
-
// from turns on this machine pause it; if the account is still limited, the next turn says so here.
|
|
264
|
-
if (adopt)
|
|
265
|
-
writeState(ref, { ...readState(ref), turn_unpaused_at: Date.now() });
|
|
266
|
-
// 4. The watcher, in turn mode: it runs each later turn itself.
|
|
267
|
-
const exec = harness === "codex"
|
|
268
|
-
? [bin, "exec", "resume", session, ...settings].map(shq).join(" ") + " {text}"
|
|
269
|
-
: harness === "dsh"
|
|
270
|
-
? dshResumeCommand(bin, session, settings, dshTurnLog(ref))
|
|
271
|
-
: harness === "antigravity"
|
|
272
|
-
? antigravityResumeCommand(bin, session, model, effort, turnTimeout * 60, settings, antigravityLog(ref))
|
|
273
|
-
// The result goes to a file the watcher reads when the turn ends: Claude Code can exit 0 with is_error set.
|
|
274
|
-
: `${shq(bin)} -p {text} ${[...settings, ...(sandbox === "workspace-write" ? claudeTurnArgs(maxBudgetUsd) : []), "--resume", session, "--output-format", "json"].map(shq).join(" ")} > ${shq(claudeResultFile(ref))}`;
|
|
275
|
-
const watcherOut = [];
|
|
276
|
-
// Scratch space beside the checkout, not the system's /tmp: on a machine the checkout lives on the
|
|
277
|
-
// work volume, the folder is inside what the sandbox may write, and it survives a reboot. Learned
|
|
278
|
-
// from ronald, whose root volume filled with agents' builds under /tmp (46 GB) while the work
|
|
279
|
-
// volume had 750 GB free, and which empties /tmp at every boot.
|
|
280
|
-
const tmp = sessionTmpDir(process.cwd(), creds.agent);
|
|
281
|
-
mkdirSync(tmp, { recursive: true });
|
|
282
|
-
installWatcherService(ref, exec, interval, Number(str(p.flags, "follow-delay") ?? "300"), { TMPDIR: tmp, ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}), ...(harness === "antigravity" ? { BSCHAT_HARNESS: "antigravity", BSCHAT_ANTIGRAVITY_SANDBOX: sandbox, BSCHAT_MODEL: model, ...(effort ? { BSCHAT_EFFORT: effort } : {}) } : {}) }, undefined, { json: false, print: (h) => watcherOut.push(h) }, bool(p.flags, "prune"), { harness, session, timeout: turnTimeout, turnsPerHour, unproductivePerHour, provider, model });
|
|
283
|
-
const wl = watcherOut.join("\n").split("\n");
|
|
284
|
-
lines.push(wl[0].replace(/^Wrote /, "Watcher: wrote "), ...wl.filter((l) => l.startsWith("Linger is off")));
|
|
285
|
-
// 5. Hooks.
|
|
286
|
-
let missing = [];
|
|
287
|
-
if (harness === "codex") {
|
|
288
|
-
// A headless turn cannot show Codex's trust prompt, and b9s never pre-approves it.
|
|
289
|
-
missing = untrustedHooks();
|
|
290
|
-
lines.push(missing.length
|
|
291
|
-
? `Codex has not trusted b9s's hooks (${missing.join(", ")}) on this machine, so turns run without them: no standing rules at session start, no continuing when work arrives mid-turn. Wake-ups still work. To trust them, run \`codex\` once in a terminal here and approve the hooks when it asks.`
|
|
292
|
-
: `Codex has trust entries for b9s's hooks here. If they changed since they were trusted, Codex skips them until approved again in an interactive \`codex\`.`);
|
|
293
|
-
}
|
|
294
|
-
else if (harness === "dsh") {
|
|
295
|
-
lines.push("DeepSeek Harness runs the headless profile without an interactive approval prompt; b9s identifies this agent through BSCHAT_AGENT on each turn.");
|
|
296
|
-
}
|
|
297
|
-
else if (harness === "antigravity") {
|
|
298
|
-
lines.push("Antigravity runs headless turns with the machine's cached agy login; b9s binds this conversation and records JSON token usage.");
|
|
380
|
+
catch (err) {
|
|
381
|
+
if (inContainer) {
|
|
382
|
+
writeContainerStatusFile(containerStatusFile("error", errorSlug), {
|
|
383
|
+
agent: errorSlug,
|
|
384
|
+
code: err instanceof CliError ? err.code : "container_start_failed",
|
|
385
|
+
error: err instanceof Error ? err.message : String(err),
|
|
386
|
+
pid: process.pid,
|
|
387
|
+
at: new Date().toISOString(),
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
throw err;
|
|
299
391
|
}
|
|
300
|
-
|
|
301
|
-
|
|
392
|
+
if (inContainer && watchArgv) {
|
|
393
|
+
Object.assign(process.env, watcherEnv);
|
|
394
|
+
try {
|
|
395
|
+
await watch(parse(watchArgv), { json: false, print: () => { } });
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
writeContainerStatusFile(containerStatusFile("error", errorSlug), {
|
|
399
|
+
agent: errorSlug,
|
|
400
|
+
code: err instanceof CliError ? err.code : "container_watch_failed",
|
|
401
|
+
error: err instanceof Error ? err.message : String(err),
|
|
402
|
+
pid: process.pid,
|
|
403
|
+
at: new Date().toISOString(),
|
|
404
|
+
});
|
|
405
|
+
throw err;
|
|
406
|
+
}
|
|
302
407
|
}
|
|
303
|
-
lines.push(`Follow it: tail -f ~/.b9s/logs/watch.${ref.replace("/", ".")}.err.log; ${harness === "codex" ? `read its thread with codex resume ${session}` : harness === "dsh" ? `read its events in ${dshTurnLog(ref)} or resume with dsh --profile headless --json --session-id ${session}` : harness === "antigravity" ? `inspect its recorded turns in ${antigravityLog(ref)}` : `read its transcript under ~/.claude/projects (session ${session})`} only while no turn is running.`);
|
|
304
|
-
lines.push(harness === "dsh"
|
|
305
|
-
? `DeepSeek Harness failures, including balance or rate limits, are recorded and retried after the ordinary 5-minute backoff; no reset time is inferred from their text.`
|
|
306
|
-
: harness === "antigravity" ? `Antigravity failures, including quota errors, are recorded verbatim and retried after the ordinary 5-minute backoff; no reset time is inferred from their text.`
|
|
307
|
-
: `If the ${label} account hits its usage limit, the watcher pauses turns until the time ${label} gives; after switching to an account with quota, resume at once: b9s unpause --as ${ref}`);
|
|
308
|
-
out.print(lines.join("\n"), { agent: ref, harness, provider, thread: session, session, sandbox, model: model ?? null, effort: effort ?? null, exec, first_turn_log: firstTurnLog, untrusted_hooks: missing });
|
|
309
408
|
}
|
|
310
409
|
export const dshStartArgs = (settings) => ["--profile", "headless", "--json", ...settings, "-"];
|
|
311
410
|
export const dshResumeArgs = (session, settings) => ["--profile", "headless", "--json", "--session-id", session, ...settings, "-"];
|
|
@@ -458,7 +557,7 @@ export function runClaudeSandboxSelfCheck(bin, settings, maxBudgetUsd, env, cwd,
|
|
|
458
557
|
/** Guard a model-spending connectivity preflight independently from the agent's real turn. */
|
|
459
558
|
export async function runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, env, cwd, session, run = runClaudeSandboxSelfCheck, unproductivePerHour = DEFAULT_UNPRODUCTIVE_PER_HOUR) {
|
|
460
559
|
const diagnostic = [];
|
|
461
|
-
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour))) {
|
|
560
|
+
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour, process.env.BSCHAT_MACHINE_SESSION_ID, "claude-code"))) {
|
|
462
561
|
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the sandbox self-check");
|
|
463
562
|
}
|
|
464
563
|
const probe = probeFor("claude-code", session, ref);
|
|
@@ -509,7 +608,7 @@ export function assertAntigravitySelfCheck(output) {
|
|
|
509
608
|
/** Run the two connectivity checks through the real model tools inside the per-turn sandbox. */
|
|
510
609
|
export async function runAntigravitySandboxSelfCheck(ref, bin, settings, cwd, session, model, effort, timeoutSeconds, logPath, turnsPerHour = DEFAULT_TURNS_PER_HOUR, env = antigravityTurnEnv("workspace-write"), unproductivePerHour = DEFAULT_UNPRODUCTIVE_PER_HOUR) {
|
|
511
610
|
const diagnostic = [];
|
|
512
|
-
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour))) {
|
|
611
|
+
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour, process.env.BSCHAT_MACHINE_SESSION_ID, "antigravity"))) {
|
|
513
612
|
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the Antigravity sandbox self-check");
|
|
514
613
|
}
|
|
515
614
|
const prompt = [
|