benignswarm 0.12.165 → 0.12.166
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 +1 -1
- package/dist/client.js +2 -2
- package/dist/commands/admin.js +3 -0
- package/dist/commands/flow-agent.js +9 -3
- package/dist/commands/flow.js +5 -0
- package/dist/commands/gh.js +117 -14
- package/dist/commands/git-credential.js +2 -2
- package/dist/commands/join.js +20 -8
- package/dist/commands/machine.js +12 -1
- package/dist/commands/mock-admin.js +74 -0
- package/dist/commands/wu.js +19 -2
- package/dist/config.js +1 -2
- package/dist/console-links.js +5 -0
- package/dist/help.js +12 -7
- package/dist/install.js +22 -4
- package/dist/merge-train.js +84 -12
- package/dist/output.js +1 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/admin-index.js
CHANGED
|
File without changes
|
package/dist/args.js
CHANGED
|
@@ -35,7 +35,7 @@ export const STRING_FLAGS = [
|
|
|
35
35
|
"stage", "machines", "resolved-retention-days", "wont-fix-retention-days", "alert-cooldown-minutes", "alerts", "confirm-force",
|
|
36
36
|
"machine-session-id", "harness-binary", "pool-sessions", "registry", "detail", "worktree", "turn-claude-runtime", "turn-antigravity-runtime",
|
|
37
37
|
"purpose", "storage-mode", "hosts", "arn", "version-id", "kms-key",
|
|
38
|
-
"mode", "weights", "quality-target", "half-life", "min-samples", "build-explore", "review-explore", "pause-build", "pause-review", "class", "route",
|
|
38
|
+
"mode", "weights", "quality-target", "half-life", "min-samples", "build-explore", "review-explore", "pause-build", "pause-review", "class", "route", "intent", "brief", "brief-file",
|
|
39
39
|
"expires-at", "conflicts-with", "source-channel-id", "source-message-id", "plain-summary",
|
|
40
40
|
"choices", "choice", "metadata-file", "confirm-agent", "confirm-parked", "step", "compare", "merge-candidate", "outcome",
|
|
41
41
|
];
|
package/dist/client.js
CHANGED
|
@@ -154,9 +154,9 @@ function expectedTextReceiptFields(method, path, body, response) {
|
|
|
154
154
|
if (verb === "POST" && /^\/projects\/[^/]+\/locks\/[^/]+\/acquire$/.test(route))
|
|
155
155
|
return strings("note");
|
|
156
156
|
if (verb === "POST" && /^\/projects\/[^/]+\/ask-operator$/.test(route))
|
|
157
|
-
return strings("text", "blocks", "proposal", "plain", "if_yes", "if_no");
|
|
157
|
+
return strings("text", "decision", "blocks", "proposal", "plain", "if_yes", "if_no");
|
|
158
158
|
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/amend$/.test(route))
|
|
159
|
-
return strings("text", "plain", "blocks", "if_yes", "if_no", "proposal");
|
|
159
|
+
return strings("text", "decision", "plain", "blocks", "if_yes", "if_no", "proposal");
|
|
160
160
|
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/withdraw$/.test(route))
|
|
161
161
|
return strings("note");
|
|
162
162
|
if (verb === "POST" && /^\/projects\/[^/]+\/asks\/[^/]+\/explanation$/.test(route))
|
package/dist/commands/admin.js
CHANGED
|
@@ -21,12 +21,15 @@ import { flowAdmin } from "./flow.js";
|
|
|
21
21
|
import { projectSecrets } from "./project-secrets.js";
|
|
22
22
|
import { standingRuleAdmin } from "./standing-rules.js";
|
|
23
23
|
import { diagAdmin } from "./diag-admin.js";
|
|
24
|
+
import { mockAdmin } from "./mock-admin.js";
|
|
24
25
|
function adminClient(p) {
|
|
25
26
|
return Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
|
|
26
27
|
}
|
|
27
28
|
export async function admin(p, out) {
|
|
28
29
|
const [, group, action, ...rest] = p.positionals;
|
|
29
30
|
switch (group) {
|
|
31
|
+
case "mock":
|
|
32
|
+
return mockAdmin(action, rest, p, adminClient(p), out);
|
|
30
33
|
case "login": {
|
|
31
34
|
const url = (str(p.flags, "url") ?? process.env.BSCHAT_URL ?? DEFAULT_URL).replace(/\/$/, "");
|
|
32
35
|
if (str(p.flags, "key") === undefined)
|
|
@@ -32,11 +32,12 @@ Hard invariants (every level; the server refuses these with 403):
|
|
|
32
32
|
- Never approve a unit, request changes, or close one as done.
|
|
33
33
|
- Never lift an operator hold.
|
|
34
34
|
- Never touch billing, authentication or production data.
|
|
35
|
+
- Never change or exceed operator-owned per-session-hour, per-account-day, turns-per-hour, or per-turn limits.
|
|
35
36
|
|
|
36
37
|
At ${level} you may:
|
|
37
38
|
${may}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
Flow Agent action cap: at most ${limits.max_actions_per_hour} actions per hour. Account budget caps are shared with unattended turns and are owned by the operator: ${limits.account_day_tokens === null ? "no account-day token cap" : `${limits.account_day_tokens.toLocaleString()} tokens`} · ${limits.account_day_cost_micros === null ? "no account-day cost cap" : `$${(limits.account_day_cost_micros / 1_000_000).toFixed(4)}`}. Check b9s flow-agent status before acting. If the account budget is disabled, unconfigured, or reached, stop and hold for the operator.
|
|
40
41
|
|
|
41
42
|
Operating loop, once per wake-up:
|
|
42
43
|
1. Read the triggers in the wake-up message, then b9s flow-agent status.
|
|
@@ -64,9 +65,13 @@ export async function flowAgent(p, out) {
|
|
|
64
65
|
const s = await client.call("GET", `/projects/${project}/flow-agent/status`);
|
|
65
66
|
if (sub === "status") {
|
|
66
67
|
const recent = (s.recent_actions ?? []);
|
|
68
|
+
const budget = s.account_budget;
|
|
69
|
+
const tokenCap = budget.account_day_tokens === null ? "unconfigured" : `${budget.tokens_counted.toLocaleString()}/${budget.account_day_tokens.toLocaleString()} tokens`;
|
|
70
|
+
const costCap = budget.account_day_cost_micros === null ? "unconfigured" : `$${(budget.cost_micros_counted / 1_000_000).toFixed(4)}/$${(budget.account_day_cost_micros / 1_000_000).toFixed(4)}`;
|
|
67
71
|
const lines = [
|
|
68
72
|
`flow agent: ${s.enabled ? "enabled" : "disabled"} · ${s.autonomy_level}`,
|
|
69
|
-
`
|
|
73
|
+
`actions this hour: ${s.actions_this_hour}/${s.max_actions_per_hour}`,
|
|
74
|
+
`account budget · rolling 24h: ${budget.enabled ? `${tokenCap} · ${costCap}` : "disabled"}${budget.reached ? " · held" : ""} · ${budget.pending_count} pending · ${budget.uncertain_count} uncertain`,
|
|
70
75
|
`last run: ${s.last_run_at ?? "never"}`,
|
|
71
76
|
...recent.slice(0, 10).map((a) => ` ${a.at} ${a.kind}${a.unit_number === null ? "" : ` #${a.unit_number}`}${a.outcome ? ` (${a.outcome})` : ""}: ${a.summary}`),
|
|
72
77
|
];
|
|
@@ -77,6 +82,7 @@ export async function flowAgent(p, out) {
|
|
|
77
82
|
if (requested !== undefined && !FLOW_AGENT_LEVELS.includes(requested))
|
|
78
83
|
throw new CliError("usage", `--level must be one of ${FLOW_AGENT_LEVELS.join(", ")}`);
|
|
79
84
|
const level = (requested ?? s.autonomy_level);
|
|
80
|
-
const
|
|
85
|
+
const budget = s.account_budget;
|
|
86
|
+
const text = flowAgentPrompt(level, { ...budget, max_actions_per_hour: s.max_actions_per_hour });
|
|
81
87
|
out.print(text, { autonomy_level: level, enabled: s.enabled, prompt: text });
|
|
82
88
|
}
|
package/dist/commands/flow.js
CHANGED
|
@@ -54,6 +54,11 @@ function flowText(snapshot) {
|
|
|
54
54
|
lines.push("State counts: " + ["held", "blocked_on_dependency", "changes_requested", "in_review", "approved_waiting_to_merge", "in_progress", "assigned_not_started", "waiting_on_person", "ready", "starved", "unknown"].map((key) => `${key}=${show(counts[key])}`).join(" "));
|
|
55
55
|
if (counts.eligibility_coverage)
|
|
56
56
|
lines.push(` eligibility: ${counts.eligibility_coverage}`);
|
|
57
|
+
const agentSummary = record(snapshot.agent_summary);
|
|
58
|
+
if (Object.keys(agentSummary).length) {
|
|
59
|
+
const states = record(agentSummary.states);
|
|
60
|
+
lines.push(`Agent utilization: ${agentSummary.utilization == null ? "unavailable (no working, idle, or waiting agents)" : `${Math.round(agentSummary.utilization * 100)}% working`} · working ${show(states.working)}, idle ${show(states.idle)}, waiting ${show(states.waiting)}, not responding ${show(states.not_responding)} faults, away ${show(states.away)}, benched ${show(agentSummary.benched_agent_count)}`);
|
|
61
|
+
}
|
|
57
62
|
const units = record(snapshot.units), items = list(units.items);
|
|
58
63
|
lines.push(`Open units: ${show(units.total_open)} total; ${items.length} shown${units.next_cursor ? `; next page: ${units.next_cursor}` : ""}`);
|
|
59
64
|
for (const itemValue of items) {
|
package/dist/commands/gh.js
CHANGED
|
@@ -6,6 +6,57 @@ import { Client } from "../client.js";
|
|
|
6
6
|
import { loadAgent, resolveAgentName } from "../config.js";
|
|
7
7
|
import { CliError } from "../errors.js";
|
|
8
8
|
import { githubCredentialForRepository, remoteRepository } from "./git-credential.js";
|
|
9
|
+
const GH_RERUN_USAGE = 'Usage: b9s gh run rerun <run-id> --failed [--job <job-id>] --reason "..."';
|
|
10
|
+
export function parseFailedRerunArgs(args) {
|
|
11
|
+
if (args[0] !== "run" || args[1] !== "rerun")
|
|
12
|
+
throw new CliError("usage", GH_RERUN_USAGE);
|
|
13
|
+
const runId = args[2];
|
|
14
|
+
if (!runId || !/^[1-9][0-9]{0,19}$/.test(runId))
|
|
15
|
+
throw new CliError("usage", `run-id must be a positive numeric GitHub Actions run id.\n${GH_RERUN_USAGE}`);
|
|
16
|
+
let failed = false;
|
|
17
|
+
let jobId;
|
|
18
|
+
let reason;
|
|
19
|
+
for (let index = 3; index < args.length; index += 1) {
|
|
20
|
+
const arg = args[index];
|
|
21
|
+
if (arg === "--failed") {
|
|
22
|
+
if (failed)
|
|
23
|
+
throw new CliError("usage", `--failed may be specified only once.\n${GH_RERUN_USAGE}`);
|
|
24
|
+
failed = true;
|
|
25
|
+
}
|
|
26
|
+
else if (arg === "--job") {
|
|
27
|
+
if (jobId !== undefined)
|
|
28
|
+
throw new CliError("usage", `--job may be specified only once.\n${GH_RERUN_USAGE}`);
|
|
29
|
+
const value = args[++index];
|
|
30
|
+
if (!value || !/^[1-9][0-9]{0,19}$/.test(value))
|
|
31
|
+
throw new CliError("usage", `--job requires a positive numeric GitHub job id.\n${GH_RERUN_USAGE}`);
|
|
32
|
+
jobId = value;
|
|
33
|
+
}
|
|
34
|
+
else if (arg === "--reason") {
|
|
35
|
+
if (reason !== undefined)
|
|
36
|
+
throw new CliError("usage", `--reason may be specified only once.\n${GH_RERUN_USAGE}`);
|
|
37
|
+
const value = args[++index];
|
|
38
|
+
if (!value)
|
|
39
|
+
throw new CliError("usage", `--reason requires a value.\n${GH_RERUN_USAGE}`);
|
|
40
|
+
reason = value.trim();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new CliError("github_option_unsupported", `b9s gh run rerun does not support ${arg}; it never permits full-run or arbitrary GitHub commands.\n${GH_RERUN_USAGE}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!failed)
|
|
47
|
+
throw new CliError("usage", `--failed is required; full workflow-run reruns are not supported.\n${GH_RERUN_USAGE}`);
|
|
48
|
+
if (!reason || reason.length > 800)
|
|
49
|
+
throw new CliError("usage", `--reason must contain 1 to 800 non-whitespace characters.\n${GH_RERUN_USAGE}`);
|
|
50
|
+
return { runId, ...(jobId ? { jobId } : {}), reason };
|
|
51
|
+
}
|
|
52
|
+
export async function requestFailedRerun(args, project, api, parsed = parseFailedRerunArgs(args)) {
|
|
53
|
+
const request = parsed;
|
|
54
|
+
return api("POST", `/projects/${encodeURIComponent(project)}/github/runs/${encodeURIComponent(request.runId)}/rerun-failed`, {
|
|
55
|
+
failed: true,
|
|
56
|
+
...(request.jobId ? { job_id: request.jobId } : {}),
|
|
57
|
+
reason: request.reason,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
9
60
|
const run = (command, args, options) => spawnSync(command, args, options);
|
|
10
61
|
function repositoryArgument(value) {
|
|
11
62
|
if (!value)
|
|
@@ -15,18 +66,24 @@ function repositoryArgument(value) {
|
|
|
15
66
|
}
|
|
16
67
|
const GH_COMMAND_OPTIONS = {
|
|
17
68
|
"pr view": {
|
|
18
|
-
values: new Set(["--
|
|
69
|
+
values: new Set(["--json", "--jq", "--template"]),
|
|
19
70
|
booleans: new Set(["--comments"]),
|
|
20
71
|
},
|
|
21
72
|
"pr checks": {
|
|
22
|
-
values: new Set(["--
|
|
73
|
+
values: new Set(["--interval", "--json", "--jq", "--template"]),
|
|
23
74
|
booleans: new Set(["--watch", "--required", "--fail-fast"]),
|
|
24
75
|
},
|
|
25
76
|
"pr status": {
|
|
26
|
-
values: new Set(["--
|
|
77
|
+
values: new Set(["--json", "--jq", "--template"]),
|
|
27
78
|
booleans: new Set(),
|
|
28
79
|
},
|
|
80
|
+
"run view": { values: new Set(["--job", "--json"]), booleans: new Set(["--log-failed"]) },
|
|
81
|
+
"run download": { values: new Set(["-n", "-p", "-D"]), booleans: new Set() },
|
|
82
|
+
"run list": { values: new Set(["--branch", "--commit", "--limit", "--json"]), booleans: new Set() },
|
|
29
83
|
};
|
|
84
|
+
function positiveGitHubId(value) {
|
|
85
|
+
return /^[1-9]\d{0,19}$/.test(value);
|
|
86
|
+
}
|
|
30
87
|
function pullRequestTarget(value, linkedRepository) {
|
|
31
88
|
if (/^\d+$/.test(value))
|
|
32
89
|
return Number(value) > 0;
|
|
@@ -45,12 +102,13 @@ function validateGhOperation(args, linkedRepository, env) {
|
|
|
45
102
|
const operation = `${args[0] ?? ""} ${args[1] ?? ""}`;
|
|
46
103
|
const contract = GH_COMMAND_OPTIONS[operation];
|
|
47
104
|
if (!contract) {
|
|
48
|
-
throw new CliError("github_command_unsupported", "b9s gh supports only read-only gh pr view
|
|
105
|
+
throw new CliError("github_command_unsupported", "b9s gh supports only read-only gh pr view/checks/status and gh run view/download/list operations.");
|
|
49
106
|
}
|
|
50
107
|
if (env.GH_REPO && repositoryArgument(env.GH_REPO) !== linkedRepository) {
|
|
51
108
|
throw new CliError("github_repository_mismatch", `GH_REPO points to ${env.GH_REPO}, not the linked project repository ${linkedRepository}.`);
|
|
52
109
|
}
|
|
53
110
|
const positional = [];
|
|
111
|
+
const seen = new Map();
|
|
54
112
|
for (let index = 2; index < args.length; index += 1) {
|
|
55
113
|
const arg = args[index];
|
|
56
114
|
if (arg === "--")
|
|
@@ -63,23 +121,22 @@ function validateGhOperation(args, linkedRepository, env) {
|
|
|
63
121
|
const flag = equal > 0 ? arg.slice(0, equal) : (arg.startsWith("-R") && arg !== "-R" ? "-R" : arg);
|
|
64
122
|
const inlineValue = equal > 0 ? arg.slice(equal + 1) : (flag === "-R" && arg !== "-R" ? arg.slice(2) : undefined);
|
|
65
123
|
if (contract.values.has(flag)) {
|
|
124
|
+
if (seen.has(flag))
|
|
125
|
+
throw new CliError("github_option_unsupported", `${flag} may be supplied only once.`);
|
|
66
126
|
const value = inlineValue ?? args[index + 1];
|
|
67
127
|
if (!value || value.startsWith("--"))
|
|
68
128
|
throw new CliError("usage", `${flag} requires a value.`);
|
|
69
129
|
if (inlineValue === undefined)
|
|
70
130
|
index += 1;
|
|
71
|
-
|
|
72
|
-
if (repositoryArgument(value) !== linkedRepository) {
|
|
73
|
-
throw new CliError("github_repository_mismatch", `gh target ${value} is not the linked project repository ${linkedRepository}.`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else if ((flag === "--hostname" || flag === "-H") && value.toLowerCase() !== "github.com") {
|
|
77
|
-
throw new CliError("github_host_unsupported", "b9s gh is pinned to github.com.");
|
|
78
|
-
}
|
|
131
|
+
seen.set(flag, value);
|
|
79
132
|
continue;
|
|
80
133
|
}
|
|
81
|
-
if (contract.booleans.has(flag) && inlineValue === undefined)
|
|
134
|
+
if (contract.booleans.has(flag) && inlineValue === undefined) {
|
|
135
|
+
if (seen.has(flag))
|
|
136
|
+
throw new CliError("github_option_unsupported", `${flag} may be supplied only once.`);
|
|
137
|
+
seen.set(flag, true);
|
|
82
138
|
continue;
|
|
139
|
+
}
|
|
83
140
|
throw new CliError("github_option_unsupported", `b9s gh does not support ${arg}.`);
|
|
84
141
|
}
|
|
85
142
|
if (operation === "pr status" && positional.length > 0) {
|
|
@@ -91,6 +148,43 @@ function validateGhOperation(args, linkedRepository, env) {
|
|
|
91
148
|
if (positional.length > 1 || (operation === "pr status" && positional.length !== 0)) {
|
|
92
149
|
throw new CliError("github_target_unsupported", `b9s gh ${operation} accepts at most one pull request target.`);
|
|
93
150
|
}
|
|
151
|
+
if (operation === "run view" || operation === "run download") {
|
|
152
|
+
if (positional.length !== 1 || !positiveGitHubId(positional[0])) {
|
|
153
|
+
throw new CliError("github_target_unsupported", `b9s gh ${operation} requires one positive numeric GitHub run ID.`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (operation === "run view") {
|
|
157
|
+
const logFailed = seen.has("--log-failed");
|
|
158
|
+
const job = seen.get("--job");
|
|
159
|
+
const json = seen.get("--json");
|
|
160
|
+
if (job !== undefined && !positiveGitHubId(String(job)))
|
|
161
|
+
throw new CliError("github_target_unsupported", "--job requires a positive numeric GitHub job ID.");
|
|
162
|
+
if (job !== undefined && !logFailed)
|
|
163
|
+
throw new CliError("github_option_unsupported", "--job is supported only with --log-failed.");
|
|
164
|
+
if (json !== undefined && (!/^[A-Za-z][A-Za-z0-9]*(,[A-Za-z][A-Za-z0-9]*)*$/.test(String(json)) || logFailed || job !== undefined)) {
|
|
165
|
+
throw new CliError("github_option_unsupported", "run view --json requires a comma-separated field list and cannot be combined with log options.");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (operation === "run download" && seen.has("-n") && seen.has("-p")) {
|
|
169
|
+
throw new CliError("github_option_unsupported", "run download accepts either -n <name> or -p <pattern>, not both.");
|
|
170
|
+
}
|
|
171
|
+
if (operation === "run list") {
|
|
172
|
+
if (positional.length !== 0)
|
|
173
|
+
throw new CliError("github_target_unsupported", "b9s gh run list does not accept a run ID.");
|
|
174
|
+
if (seen.has("--branch") && seen.has("--commit"))
|
|
175
|
+
throw new CliError("github_option_unsupported", "run list accepts either --branch or --commit, not both.");
|
|
176
|
+
const commit = seen.get("--commit");
|
|
177
|
+
if (commit !== undefined && !/^[0-9a-f]{7,64}$/i.test(String(commit)))
|
|
178
|
+
throw new CliError("github_option_unsupported", "--commit requires a 7-64 character hexadecimal commit SHA.");
|
|
179
|
+
const limit = seen.get("--limit");
|
|
180
|
+
if (limit !== undefined && (!/^\d+$/.test(String(limit)) || Number(limit) < 1 || Number(limit) > 1000)) {
|
|
181
|
+
throw new CliError("github_option_unsupported", "--limit must be an integer from 1 to 1000.");
|
|
182
|
+
}
|
|
183
|
+
const json = seen.get("--json");
|
|
184
|
+
if (json !== undefined && !/^[A-Za-z][A-Za-z0-9]*(,[A-Za-z][A-Za-z0-9]*)*$/.test(String(json))) {
|
|
185
|
+
throw new CliError("github_option_unsupported", "--json requires a comma-separated field list.");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
94
188
|
}
|
|
95
189
|
export async function runGhWithProjectCredential(args, cwd, api, runner = run, parentEnv = process.env) {
|
|
96
190
|
if (args.length === 0)
|
|
@@ -104,7 +198,8 @@ export async function runGhWithProjectCredential(args, cwd, api, runner = run, p
|
|
|
104
198
|
throw new CliError("github_repository_required", "b9s gh only supports GitHub HTTPS or SSH repository origins.");
|
|
105
199
|
}
|
|
106
200
|
validateGhOperation(args, repository.path, parentEnv);
|
|
107
|
-
const
|
|
201
|
+
const needsActionsRead = args[0] === "run";
|
|
202
|
+
const credential = await githubCredentialForRepository(repository.path, api, true, needsActionsRead ? "actions:read" : undefined);
|
|
108
203
|
if (!credential?.password)
|
|
109
204
|
throw new CliError("github_credential_missing", "The linked repository did not return a GitHub credential.");
|
|
110
205
|
// The scoped installation token exists only in the gh child's environment. It is never
|
|
@@ -132,6 +227,8 @@ export async function runGhWithProjectCredential(args, cwd, api, runner = run, p
|
|
|
132
227
|
encoding: "utf8",
|
|
133
228
|
env: childEnv,
|
|
134
229
|
stdio: ["inherit", "pipe", "pipe"],
|
|
230
|
+
// Failed workflow logs can be much larger than the 1 MiB spawnSync default.
|
|
231
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
135
232
|
});
|
|
136
233
|
}
|
|
137
234
|
finally {
|
|
@@ -151,6 +248,12 @@ export async function gh(args) {
|
|
|
151
248
|
if (!agent.project)
|
|
152
249
|
throw new CliError("github_not_connected", "b9s gh requires a project-scoped agent identity.");
|
|
153
250
|
const client = Client.forAgent(agent, undefined, { presence: false });
|
|
251
|
+
if (args[0] === "run" && args[1] === "rerun") {
|
|
252
|
+
const request = parseFailedRerunArgs(args);
|
|
253
|
+
const result = await requestFailedRerun(args, agent.project, (method, path, body) => client.call(method, path, body), request);
|
|
254
|
+
process.stdout.write(`Requested failed-job rerun for run ${request.runId}${request.jobId ? `, job ${request.jobId}` : ""}. Audit: ${typeof result === "object" && result !== null && "audit_id" in result ? String(result.audit_id) : "recorded"}.\n`);
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
154
257
|
const base = `/projects/${encodeURIComponent(agent.project)}/git-credentials`;
|
|
155
258
|
return runGhWithProjectCredential(args, process.cwd(), (method, _path, body) => client.call(method, base, body));
|
|
156
259
|
}
|
|
@@ -39,7 +39,7 @@ export async function credentialResponse(input, api) {
|
|
|
39
39
|
return `username=${credential.username}\npassword=${credential.password}\n\n`;
|
|
40
40
|
}
|
|
41
41
|
/** Resolve a short-lived token through the same scoped credential endpoint used by Git. */
|
|
42
|
-
export async function githubCredentialForRepository(wanted, api, refuseUnlinkedRepository = false) {
|
|
42
|
+
export async function githubCredentialForRepository(wanted, api, refuseUnlinkedRepository = false, requiredPermission) {
|
|
43
43
|
const metadata = await api("GET", "");
|
|
44
44
|
if (!metadata.linked || !metadata.repository) {
|
|
45
45
|
throw new CliError("github_not_connected", "GitHub is not connected for this project. Connect GitHub in the console to enable repository access.");
|
|
@@ -51,7 +51,7 @@ export async function githubCredentialForRepository(wanted, api, refuseUnlinkedR
|
|
|
51
51
|
}
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
-
return api("POST", "", {});
|
|
54
|
+
return api("POST", "", requiredPermission ? { required_permission: requiredPermission } : {});
|
|
55
55
|
}
|
|
56
56
|
function missingRepositoryPathHint(input) {
|
|
57
57
|
const request = credentialInput(input);
|
package/dist/commands/join.js
CHANGED
|
@@ -4,9 +4,10 @@ import { agentRef, DEFAULT_URL, loadAgent, resolveModel, saveAgent } from "../co
|
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { join as pathJoin } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
7
8
|
import { CliError } from "../errors.js";
|
|
8
9
|
import { defaultMachine } from "../git.js";
|
|
9
|
-
import { assertMachineInstallNotNewer,
|
|
10
|
+
import { assertMachineInstallNotNewer, ensureInstall, isLiveExecutable, readInstall, requireInstall } from "../install.js";
|
|
10
11
|
import { claudeCheckoutOwner, claudeCheckoutTaken, reconcileCodexHooks, HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
|
|
11
12
|
import { detectVendor } from "../vendor.js";
|
|
12
13
|
import { CLI_VERSION } from "../version.js";
|
|
@@ -103,6 +104,15 @@ export async function join(p, out, expectedProject) {
|
|
|
103
104
|
// A newer recorded install must reject this copy before the single-use enrollment token is sent.
|
|
104
105
|
// Otherwise wait to move/install the machine-wide CLI until credentials have been saved.
|
|
105
106
|
assertMachineInstallNotNewer(CLI_VERSION);
|
|
107
|
+
// Validate the recorded binary (or canonical bootstrap runtime) before consuming a token.
|
|
108
|
+
if (readInstall()) {
|
|
109
|
+
const recorded = requireInstall();
|
|
110
|
+
if (!isLiveExecutable(recorded.bin))
|
|
111
|
+
throw new CliError("recorded_bin_unavailable", `the recorded b9s executable ${recorded.bin} is not executable`, "Ask the machine operator to repair the recorded install before joining");
|
|
112
|
+
}
|
|
113
|
+
else if (!isLiveExecutable(pathJoin(homedir(), ".local", "node", "bin", "npm")) || !isLiveExecutable(pathJoin(homedir(), ".local", "node", "bin", "node"))) {
|
|
114
|
+
throw new CliError("canonical_node_missing", "the canonical ~/.local/node npm is missing", `Follow ${url}/onboard to prepare Node before joining`);
|
|
115
|
+
}
|
|
106
116
|
let res;
|
|
107
117
|
try {
|
|
108
118
|
res = await fetch(`${url}/enroll`, { method: "POST", headers: { "content-type": "application/json", "user-agent": cliUserAgent() }, body: JSON.stringify({ token, name, vendor, machine }) });
|
|
@@ -192,14 +202,16 @@ export function assertVendorMatchesRepo(root, name, vendor, replace) {
|
|
|
192
202
|
throw new CliError("vendor_mismatch", `${p} says ${name} runs in ${mapped.join(" and ")} here, but this command detected ${vendor}`, `If ${name} runs in ${mapped[0]}, run this from that harness or pass --vendor ${mapped[0]}. If the file is wrong, pass --replace.`);
|
|
193
203
|
}
|
|
194
204
|
/** This machine's one install, at least this CLI's version (installed or upgraded when needed). */
|
|
195
|
-
/**
|
|
196
|
-
* The machine's install, upgraded to this version if older. An existing record keeps its npm, so a
|
|
197
|
-
* join run from another Node (an nvm shell, an npx cache) upgrades the machine's install in place
|
|
198
|
-
* instead of moving it there and leaving every watcher on the old copy. Only a first install uses
|
|
199
|
-
* the npm next to the running Node.
|
|
200
|
-
*/
|
|
205
|
+
/** Reuse an existing machine install without rewriting it or restarting services. */
|
|
201
206
|
function machineInstall() {
|
|
202
|
-
|
|
207
|
+
assertMachineInstallNotNewer(CLI_VERSION);
|
|
208
|
+
if (readInstall())
|
|
209
|
+
return requireInstall();
|
|
210
|
+
const npm = pathJoin(homedir(), ".local", "node", "bin", "npm");
|
|
211
|
+
const node = pathJoin(homedir(), ".local", "node", "bin", "node");
|
|
212
|
+
if (!isLiveExecutable(npm) || !isLiveExecutable(node))
|
|
213
|
+
throw new CliError("canonical_node_missing", "the canonical ~/.local/node runtime is missing", "Follow the /onboard instructions before joining");
|
|
214
|
+
return ensureInstall(CLI_VERSION, (m) => process.stderr.write(`b9s: ${m}\n`), npm, true, false, node);
|
|
203
215
|
}
|
|
204
216
|
function writeIdentityDryRun(root, vendor, name, replace) {
|
|
205
217
|
const p = findIdentityFile(root);
|
package/dist/commands/machine.js
CHANGED
|
@@ -186,6 +186,17 @@ export function bareDigestOf(imageRef) {
|
|
|
186
186
|
}
|
|
187
187
|
const MACHINE_REQUEST_TIMEOUT_MS = 45_000;
|
|
188
188
|
const MACHINE_NETWORK_RETRY_MS = 5 * 60_000;
|
|
189
|
+
const MACHINE_REPORT_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
190
|
+
/** Keep malformed local UX job state from making the server reject an otherwise valid machine report. */
|
|
191
|
+
export function validatedUxJobIdsForMachineReport(ids, log) {
|
|
192
|
+
return ids.filter((id) => {
|
|
193
|
+
if (MACHINE_REPORT_UUID.test(id))
|
|
194
|
+
return true;
|
|
195
|
+
const printable = id.replace(/[\u0000-\u001f\u007f]/g, "?").slice(0, 100);
|
|
196
|
+
log(`ignoring non-UUID active UX job id in machine report: ${printable}`);
|
|
197
|
+
return false;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
189
200
|
const MACHINE_PASS_BUDGET_MS = 4 * 60_000;
|
|
190
201
|
const MACHINE_WATCHDOG_MS = 5 * 60_000;
|
|
191
202
|
export function resolvePinnedImageRef(image) {
|
|
@@ -2214,7 +2225,7 @@ export async function reconcile(m, log, reportIntervalSeconds = 30, deps) {
|
|
|
2214
2225
|
report_interval_seconds: reportIntervalSeconds,
|
|
2215
2226
|
sessions: out,
|
|
2216
2227
|
capabilities,
|
|
2217
|
-
active_ux_job_ids: uxJobIdsForMachineReport(deps?.uxJobsInFlight, deps?.uxJobDeps),
|
|
2228
|
+
active_ux_job_ids: validatedUxJobIdsForMachineReport(uxJobIdsForMachineReport(deps?.uxJobsInFlight, deps?.uxJobDeps), log),
|
|
2218
2229
|
...(imageProbes.length ? { image_probes: imageProbes } : {}),
|
|
2219
2230
|
}, { retryForMs: MACHINE_NETWORK_RETRY_MS });
|
|
2220
2231
|
const uxSessionHints = desired.map((session) => ({
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { need, repeated, str } from "../args.js";
|
|
3
|
+
import { consoleLink } from "../console-links.js";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
const usage = "mock create|list|iterate|approve <project> ... (see b9s-admin --help)";
|
|
6
|
+
function describeStudy(study, project) {
|
|
7
|
+
if (!study || typeof study.id !== "string" || !Array.isArray(study.rounds))
|
|
8
|
+
throw new CliError("bad_response", "design study response omitted study id or rounds; inspect the study before retrying a write");
|
|
9
|
+
const units = study.rounds.flatMap(round => round.variants.map(v => `${v.label}: ${v.work_unit_number == null ? "unavailable" : `WU #${v.work_unit_number}`}`));
|
|
10
|
+
return `Study ${study.id}${units.length ? `\nVariants: ${units.join(", ")}` : ""}\nViewer: ${consoleLink("mock", project, study.id)}`;
|
|
11
|
+
}
|
|
12
|
+
export async function mockAdmin(action, args, p, client, out) {
|
|
13
|
+
const [project, studyId, variantId] = args;
|
|
14
|
+
if (!action || !project || !["create", "list", "iterate", "approve"].includes(action))
|
|
15
|
+
throw new CliError("usage", usage);
|
|
16
|
+
if ((action === "create" || action === "list") && args.length !== 1 || action === "iterate" && args.length !== 2 || action === "approve" && args.length !== 3)
|
|
17
|
+
throw new CliError("usage", usage);
|
|
18
|
+
const base = `/projects/${encodeURIComponent(project)}/design-studies`;
|
|
19
|
+
if (action === "list") {
|
|
20
|
+
const status = str(p.flags, "status");
|
|
21
|
+
if (status !== undefined && !["active", "approved", "archived"].includes(status))
|
|
22
|
+
throw new CliError("usage", "--status must be active, approved, or archived");
|
|
23
|
+
const result = await client.call("GET", `${base}${status ? `?status=${encodeURIComponent(status)}` : ""}`);
|
|
24
|
+
if (!Array.isArray(result.studies))
|
|
25
|
+
throw new CliError("bad_response", "design study list response omitted studies");
|
|
26
|
+
out.print(result.studies.map((s) => `${s.id} [${s.status}] ${s.title}\n ${consoleLink("mock", project, s.id)}`).join("\n") || "No design studies.", result);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (action === "create") {
|
|
30
|
+
const title = need(p.flags, "title"), target = need(p.flags, "target");
|
|
31
|
+
const briefText = str(p.flags, "brief"), briefFile = str(p.flags, "brief-file");
|
|
32
|
+
if ((briefText === undefined) === (briefFile === undefined))
|
|
33
|
+
throw new CliError("usage", "choose exactly one of --brief or --brief-file");
|
|
34
|
+
const brief = briefFile !== undefined ? readFileSync(briefFile, "utf8") : briefText;
|
|
35
|
+
if (!brief.trim())
|
|
36
|
+
throw new CliError("usage", "brief must not be empty");
|
|
37
|
+
const intent = str(p.flags, "intent");
|
|
38
|
+
if (intent !== undefined && !["explore", "refine", "focus", "audit"].includes(intent))
|
|
39
|
+
throw new CliError("usage", "--intent must be explore, refine, focus, or audit");
|
|
40
|
+
const variants = repeated(p, "variant").map(v => v.trim());
|
|
41
|
+
if (variants.length < 1 || variants.length > 8 || variants.some(v => !v || /^(agent|model):\s*$/.test(v)))
|
|
42
|
+
throw new CliError("usage", "supply 1..8 nonempty --variant values");
|
|
43
|
+
let names = new Set();
|
|
44
|
+
if (variants.some(v => !v.startsWith("agent:") && !v.startsWith("model:"))) {
|
|
45
|
+
const agents = await client.call("GET", `/projects/${encodeURIComponent(project)}/agents`);
|
|
46
|
+
if (!Array.isArray(agents.agents) || agents.agents.some((a) => !a || typeof a !== "object" || typeof a.name !== "string"))
|
|
47
|
+
throw new CliError("bad_response", "project agent response omitted agent names");
|
|
48
|
+
names = new Set(agents.agents.map((a) => a.name));
|
|
49
|
+
}
|
|
50
|
+
const specs = variants.map(raw => {
|
|
51
|
+
const v = raw.trim();
|
|
52
|
+
if (v.startsWith("agent:"))
|
|
53
|
+
return { agent_name: v.slice(6).trim() };
|
|
54
|
+
if (v.startsWith("model:"))
|
|
55
|
+
return { model: v.slice(6).trim() };
|
|
56
|
+
return names.has(v) ? { agent_name: v } : { model: v };
|
|
57
|
+
});
|
|
58
|
+
const route = str(p.flags, "route");
|
|
59
|
+
const result = await client.call("POST", base, { title, target_area: target, brief, variants: specs, ...(route !== undefined ? { target_route: route } : {}), ...(intent !== undefined ? { intent_mode: intent } : {}) });
|
|
60
|
+
out.print(describeStudy(result.study, project), { ...result, viewer_url: consoleLink("mock", project, result.study.id) });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (action === "iterate") {
|
|
64
|
+
const variants = repeated(p, "variant");
|
|
65
|
+
if (variants.length > 1 || variants.some(v => !v.trim()))
|
|
66
|
+
throw new CliError("usage", "iterate accepts at most one nonempty --variant");
|
|
67
|
+
const note = str(p.flags, "note");
|
|
68
|
+
const result = await client.call("POST", `${base}/${encodeURIComponent(studyId)}/iterate`, { ...(variants.length ? { variant_id: variants[0] } : {}), ...(note !== undefined ? { note } : {}) });
|
|
69
|
+
out.print(describeStudy(result.study, project), { ...result, viewer_url: consoleLink("mock", project, result.study.id) });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const result = await client.call("POST", `${base}/${encodeURIComponent(studyId)}/approve`, { variant_id: variantId });
|
|
73
|
+
out.print(describeStudy(result.study, project), { ...result, viewer_url: consoleLink("mock", project, result.study.id) });
|
|
74
|
+
}
|
package/dist/commands/wu.js
CHANGED
|
@@ -2562,8 +2562,14 @@ export async function askOperator(p, out) {
|
|
|
2562
2562
|
if (value !== undefined)
|
|
2563
2563
|
body[field] = value;
|
|
2564
2564
|
}
|
|
2565
|
+
const decision = str(p.flags, "decision");
|
|
2566
|
+
if (decision !== undefined)
|
|
2567
|
+
body.decision = decision;
|
|
2568
|
+
const kind = str(p.flags, "kind");
|
|
2569
|
+
if (kind !== undefined)
|
|
2570
|
+
body.kind = kind;
|
|
2565
2571
|
if (!Object.keys(body).length)
|
|
2566
|
-
throw new CliError("usage", "ask-operator --amend <id> [new question] [--plain ...] [--blocks ...] [--if-yes ...] [--if-no ...] [--propose ...]");
|
|
2572
|
+
throw new CliError("usage", "ask-operator --amend <id> [new question] [--decision ...] [--kind ...] [--plain ...] [--blocks ...] [--if-yes ...] [--if-no ...] [--propose ...]");
|
|
2567
2573
|
const result = await client.call("POST", "/projects/" + project + "/asks/" + amend + "/amend", body);
|
|
2568
2574
|
out.print("Amended your open ask " + amend + "; the operator was told.", result);
|
|
2569
2575
|
return;
|
|
@@ -2574,11 +2580,22 @@ export async function askOperator(p, out) {
|
|
|
2574
2580
|
if (!text || missing.length)
|
|
2575
2581
|
throw new CliError("usage", `ask-operator "exactly what you need the operator to do or decide" --plain "one or two plain sentences for someone who has not read the thread: what this is about (no unit numbers or jargon unexplained)" --blocks "what's stuck until they answer" --if-yes "what happens then" --if-no "what happens then" [--propose "your recommended answer, approvable as written"]${missing.length ? `\nmissing: ${missing.join(", ")}` : ""}`);
|
|
2576
2582
|
const proposal = str(p.flags, "propose") ?? "";
|
|
2583
|
+
const decision = str(p.flags, "decision");
|
|
2584
|
+
const kind = str(p.flags, "kind");
|
|
2585
|
+
const askKinds = ["ci_rerun", "ci_log", "ci_artifact", "pr_label", "git_push", "decision", "approval", "scope_change", "access", "milestone_close", "other"];
|
|
2586
|
+
if (decision !== undefined && (!decision.trim() || decision.trim().length > 120 || /[\r\n]/.test(decision.trim())))
|
|
2587
|
+
throw new CliError("usage", "--decision must be a non-empty one-line headline of at most 120 characters");
|
|
2588
|
+
if (kind !== undefined && !askKinds.includes(kind))
|
|
2589
|
+
throw new CliError("usage", `--kind must be one of: ${askKinds.join(", ")}`);
|
|
2590
|
+
const headline = decision?.trim() ?? (() => {
|
|
2591
|
+
const firstLine = text.split(/[\r\n]/, 1)[0].trim();
|
|
2592
|
+
return firstLine.length <= 120 ? firstLine : `${firstLine.slice(0, 117).trimEnd()}...`;
|
|
2593
|
+
})();
|
|
2577
2594
|
const milestone = str(p.flags, "milestone");
|
|
2578
2595
|
const rawUnit = str(p.flags, "unit");
|
|
2579
2596
|
if (rawUnit !== undefined && !/^[1-9]\d*$/.test(rawUnit))
|
|
2580
2597
|
throw new CliError("usage", "--unit must be a positive work unit number");
|
|
2581
|
-
const r = await client.call("POST", `/projects/${project}/ask-operator`, { text, ...fields, proposal, ...(milestone !== undefined ? { milestone } : {}), ...(rawUnit !== undefined ? { unit: Number(rawUnit) } : {}) });
|
|
2598
|
+
const r = await client.call("POST", `/projects/${project}/ask-operator`, { text, ...fields, proposal, decision: headline, ...(kind !== undefined ? { kind } : {}), ...(milestone !== undefined ? { milestone } : {}), ...(rawUnit !== undefined ? { unit: Number(rawUnit) } : {}) });
|
|
2582
2599
|
out.print(`Asked the operator${proposal ? " with your proposal (they can approve it as written)" : ""}; it is on their console banner and reported to them. You will be @mentioned with the decision. Carry on with what does not depend on it.`, r);
|
|
2583
2600
|
}
|
|
2584
2601
|
async function reviewUsage(client, project, name) {
|
package/dist/config.js
CHANGED
|
@@ -7,7 +7,6 @@ import { writeFileAtomic } from "./shared-file.js";
|
|
|
7
7
|
import { readState, updateState } from "./state.js";
|
|
8
8
|
import { detectVendor } from "./vendor.js";
|
|
9
9
|
import { configDirectory } from "./directories.js";
|
|
10
|
-
import { CLI_VERSION } from "./version.js";
|
|
11
10
|
export const DEFAULT_URL = "https://api.benignswarm.org";
|
|
12
11
|
export function configRoot(env = process.env) {
|
|
13
12
|
return configDirectory(env);
|
|
@@ -168,7 +167,7 @@ export function resolveAgentName(asFlag, env = process.env, cwd = process.cwd())
|
|
|
168
167
|
const saved = listSaved("agents", env);
|
|
169
168
|
throw new CliError("no_identity", `BSCHAT_AGENT is not set and --as was not given; b9s cannot tell which agent you are${identityWalkStoppedAt() ? ` (it looked for this checkout's identity file up to ${identityWalkStoppedAt()}, where it is not permitted to look)` : ""}`, saved.length
|
|
170
169
|
? `Saved identities on this machine: ${saved.join(", ")}. Ask the user which one is yours, then: export BSCHAT_AGENT=<project>/<name> (or run: b9s setup --as <project>/<name> to record it for this repo)`
|
|
171
|
-
: `No identities are saved here. Ask the account owner for an invite
|
|
170
|
+
: `No identities are saved here. Ask the account owner for an invite, then follow ${DEFAULT_URL}/onboard to use the recorded install or prepare the canonical runtime.`);
|
|
172
171
|
}
|
|
173
172
|
return isRef(name) ? name : resolveSavedRef(name, env);
|
|
174
173
|
}
|
package/dist/console-links.js
CHANGED
|
@@ -2,6 +2,11 @@ const CONSOLE_URL = "https://benignswarm.org";
|
|
|
2
2
|
/** Build the canonical console destination used when CLI output names a record. */
|
|
3
3
|
export function consoleLink(kind, project, id) {
|
|
4
4
|
const base = CONSOLE_URL;
|
|
5
|
+
if (kind === "mock") {
|
|
6
|
+
if (!project)
|
|
7
|
+
throw new Error("A mock viewer link requires its project");
|
|
8
|
+
return `${base}/projects/${encodeURIComponent(project)}/mocks/${encodeURIComponent(String(id))}`;
|
|
9
|
+
}
|
|
5
10
|
if (kind === "work") {
|
|
6
11
|
if (!project)
|
|
7
12
|
throw new Error("A work-unit console link requires its project");
|
package/dist/help.js
CHANGED
|
@@ -29,7 +29,7 @@ Mac capacity/signing API (profiles, leases, signer-only references, TestFlight a
|
|
|
29
29
|
Standing rules are resolved by account, project, role, and exact-agent scope. GET /agents/me/standing-rules and GET /projects/:p/standing-rules return complete authorized sets and fingerprints; their separate ack endpoints accept only a current fingerprint after complete delivery. Operators and authorized assigners manage rules through the API; limits, compatibility confirmation, audit, and authorization are in packages/skill/references/api.md. Console management and chat promotion are WU #313.
|
|
30
30
|
Claude Code, Codex, and Antigravity SessionStart hooks retrieve the complete effective rules at fresh start, resume, compaction, and clear into a new thread. They acknowledge only after complete output; an unavailable or over-budget payload points to b9s process without acknowledgment. b9s me shows concise rule text and acknowledgment, b9s process shows the full project rules and acknowledges that fingerprint after display, and b9s resume includes the effective rulesets.
|
|
31
31
|
|
|
32
|
-
GitHub connection and repository status are available in the console and through b9s-admin github status and b9s-admin project github <project> status|unlink. A repository link enables agent credentials without requiring a ruleset. An agent can inspect its effective repository permission with GET /projects/:p/git-credentials; a project admin can inspect a named agent with GET /projects/:p/git-credentials?agent=<name-or-id>. Each issuance records its permission reason without storing the token. Open or reuse a PR for a unit's pushed branch with b9s wu pr <n>; add --auto-merge to ask GitHub to merge it after required checks pass. Use b9s gh <args> for
|
|
32
|
+
GitHub connection and repository status are available in the console and through b9s-admin github status and b9s-admin project github <project> status|unlink. A repository link enables agent credentials without requiring a ruleset. An agent can inspect its effective repository permission with GET /projects/:p/git-credentials; a project admin can inspect a named agent with GET /projects/:p/git-credentials?agent=<name-or-id>. Each issuance records its permission reason without storing the token. Open or reuse a PR for a unit's pushed branch with b9s wu pr <n>; add --auto-merge to ask GitHub to merge it after required checks pass. Use b9s gh <args> for read-only PR view/checks/status and workflow run view/download/list from that linked repository. Run views support --log-failed, --job <job-id> --log-failed, or --json <fields>; downloads support -n <name> or -p <pattern> and -D <dir>; run lists support --branch, --commit, --limit, and --json. Rerun transient failures with b9s gh run rerun <run-id> --failed [--job <job-id>] --reason "..."; full-run reruns are refused, with a cap of two reruns per project/head SHA and one rerun per run ID per five minutes. This server-proxied operation requires Actions: write on the linked GitHub App and keeps credentials server-side. Workflow read commands require the linked GitHub App to grant Actions: read. The wrapper pins GH_HOST and GH_REPO, requests repository-scoped credentials, and sets GH_TOKEN only in the gh child environment. Other commands, hosts, repositories, and repository/host override flags are refused before token issuance; the token is never printed or stored. The API scopes its installation token to the linked repository, stores the PR URL on the unit, and never prints or persists the token. Verify an exact target ruleset in Account -> GitHub connection before enabling hosted merge; the CLI cannot perform this owner OAuth step. Disconnect an installation with b9s-admin github disconnect <installation-id>. Hosted merge execution and status use b9s wu merge <n> and b9s wu merge status <n>; they call POST/GET /projects/:p/work-units/:n/merge and never inspect local Git state. API role checks use merge.merged_by and operator override; operator_hold is checked, merges serialize in MergeTargetDO, and retries reconcile idempotently. Manual wu done remains disabled for enabled linked targets. Enable with b9s-admin project hosted-merge <project> enable --confirm-bypass-signal only after ruleset verification and the live GitHub bypass-change check; disable with b9s-admin project hosted-merge <project> disable. The console control is WU #196. App setup steps are in packages/skill-admin/references/setup.md.
|
|
33
33
|
|
|
34
34
|
Environment problems: agents report bounded, redacted observations with b9s environment report; reports use scoped project or machine access, account-scoped evidence, and only the agent's own blocked units. Agents can append observations but cannot claim, diagnose, or resolve issues. Operators and agents whose role has own_environment_problems can manage visible issues. Operators use Account → Environment in the console to filter and inspect issues, claim/assign/reassign, record diagnoses, and resolve with a note and verification. Manual diagnoses use source agent; doctor/daemon provenance is for actual check results. Banner links open the same issue detail with impact context. Issue detail links active notices in the same scope and current machine-session faults related to its machine or explicitly linked unit owner. The read-only steward summary lists active linked issues and currently waiting linked units, without publishing notices or creating work. Machine issue views respect linked-project access. Spending impact is unknown and creates no banner until unit-attributed telemetry lands in WU #236; see packages/skill/references/api.md.
|
|
35
35
|
|
|
@@ -46,7 +46,8 @@ Agent commands
|
|
|
46
46
|
b9s identities list saved identities on this machine
|
|
47
47
|
b9s me who am I, role, permissions, channels, standing rules and acknowledgment; --json includes your machine sessions
|
|
48
48
|
b9s git-credential get|store|erase linked GitHub helper; Git must send the repo path (credential.https://github.com.useHttpPath true)
|
|
49
|
-
b9s gh <gh arguments> run
|
|
49
|
+
b9s gh <gh arguments> read PR status and Actions run details, or request a guarded failed-job rerun from this linked checkout
|
|
50
|
+
b9s gh run rerun <run-id> --failed [--job <job-id>] --reason "..." request an audited failed-job rerun (max 2 per head SHA)
|
|
50
51
|
b9s resume compact recovery brief: units, reviews, asks, slices, decisions, outcomes, process, standing rules and notices
|
|
51
52
|
b9s notice add --project <p> "<text>" [--until <time>] [--command-pattern <regex>]
|
|
52
53
|
assigner only: add a project notice; matching commands warn but continue
|
|
@@ -188,8 +189,8 @@ Machine placement enforces configured session slots and reports machine pressure
|
|
|
188
189
|
b9s wu target <n> <branch|default> [--summary "reviewed work summary"] owner, assigner or operator: change where this unit lands
|
|
189
190
|
b9s wu branch <n> [<branch>] [--clear] [--reason "why"] [--base <branch-or-sha>] [--continue] assigner or operator: set, correct, or clear a unit's recorded branch
|
|
190
191
|
b9s wu head <n> <full-sha> --reason "why" assigner or operator: record a commit verified on the unit's branch
|
|
191
|
-
b9s ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."] [--milestone <key> | --unit <n>] [--question <text>]
|
|
192
|
-
b9s ask-operator --amend <id> ["new question"] [--plain ".."] [--blocks ".."] [--if-yes ".."] [--if-no ".."] [--propose ".."] [--question <text>] amend your own open ask
|
|
192
|
+
b9s ask-operator "what you need from them" [--decision "one-line headline (120 chars max)"] [--kind <ask-kind>] --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."] [--milestone <key> | --unit <n>] [--question <text>]
|
|
193
|
+
b9s ask-operator --amend <id> ["new question"] [--decision "headline"] [--kind <ask-kind>] [--plain ".."] [--blocks ".."] [--if-yes ".."] [--if-no ".."] [--propose ".."] [--question <text>] amend your own open ask
|
|
193
194
|
b9s ask-operator withdraw <key> --note "why it no longer needs an operator answer" withdraw your own ask, a steward-raised declared-wait ask, or an ask if you are a project assigner
|
|
194
195
|
b9s ask-operator refuses a second ask naming the same WU; use --amend <id>. Account needs group asks/questions by unit and can answer several together.
|
|
195
196
|
a decision only the operator can make, on their console banner and reported to them; never
|
|
@@ -230,7 +231,7 @@ Machine placement enforces configured session slots and reports machine pressure
|
|
|
230
231
|
b9s mock upload <studyId> <variantId> <file.html> [--summary <text>] upload and attach a mock
|
|
231
232
|
b9s mock gaps <studyId> --json <gapsJson> | --clear submit gaps (field, missing, build_summary, adapt_summary, omit_summary?, prerequisite_tags?)
|
|
232
233
|
b9s flow-agent run [--force] [--admin <name>] [--project <name>] request a Flow Agent tick
|
|
233
|
-
b9s flow-agent status Flow Agent: autonomy level,
|
|
234
|
+
b9s flow-agent status Flow Agent: autonomy level, actions this hour, rolling account budget, recent actions
|
|
234
235
|
b9s flow-agent prompt [--level advisory|flow_ops|autonomous_ops]
|
|
235
236
|
the Flow Agent's operating rules for the project's level (or --level): hard
|
|
236
237
|
invariants, what the level may change, limits and the per-wake-up loop
|
|
@@ -390,6 +391,10 @@ Project agents inspect work waits with b9s wu stalled [--all]; its default inclu
|
|
|
390
391
|
b9s-admin text-check <project> find bschat mentions in working agreements, charter, tags, roles and open scopes
|
|
391
392
|
b9s-admin signup --url <api> --key <signup-code> <account-name> <email>
|
|
392
393
|
b9s-admin project create|list|delete <name>
|
|
394
|
+
b9s-admin mock create <project> --title <text> --target <area> [--route <path>] [--intent explore|refine|focus|audit] (--brief <text> | --brief-file <path>) --variant <agent_or_model> [--variant <agent_or_model>] [--json]
|
|
395
|
+
b9s-admin mock list <project> [--status active|approved|archived] [--json]
|
|
396
|
+
b9s-admin mock iterate <project> <studyId> [--variant <variantId>] [--note <text>] [--json]
|
|
397
|
+
b9s-admin mock approve <project> <studyId> <variantId> [--json]
|
|
393
398
|
b9s-admin project pause <project> --note "why" | resume <project> stop dispatch, steward actions, escalations, stall faults and new turns; queued and assigned work stays unchanged
|
|
394
399
|
b9s-admin github status | disconnect <installation-id>
|
|
395
400
|
b9s-admin project github <project> status | unlink
|
|
@@ -444,9 +449,9 @@ Project agents inspect work waits with b9s wu stalled [--all]; its default inclu
|
|
|
444
449
|
b9s-admin role list [--project p]
|
|
445
450
|
Flow Agent: create a role whose permissions include "flow_agent": true and give it to one agent, then
|
|
446
451
|
set the process's flow_agent {enabled, autonomy_level advisory|flow_ops|autonomous_ops,
|
|
447
|
-
|
|
452
|
+
max_actions_per_hour}. The steward wakes its holders on coalesced stall, dependency,
|
|
448
453
|
send-back and merge-train triggers (3-minute debounce) and a 30-minute sweep while a unit is open;
|
|
449
|
-
the agent reads its rules with b9s flow-agent prompt and
|
|
454
|
+
the agent reads its rules with b9s flow-agent prompt and shared account budget with b9s flow-agent status.
|
|
450
455
|
b9s-admin wu assign <project> <n> --to <agent> [--reason "why"] operator: reassign a unit in place
|
|
451
456
|
b9s-admin wu abandon <project> <n> --note "why" operator: close work that is no longer needed
|
|
452
457
|
b9s-admin wu supersede <project> <n> --by <m> operator: close this unit as continued by #m
|
package/dist/install.js
CHANGED
|
@@ -11,14 +11,32 @@ import { watcherMemoryLimits } from "./watcher-memory.js";
|
|
|
11
11
|
export const installFile = () => join(configRoot(), "install.json");
|
|
12
12
|
export function readInstall() {
|
|
13
13
|
const p = installFile();
|
|
14
|
-
if (!existsSync(p))
|
|
15
|
-
return null;
|
|
16
14
|
try {
|
|
17
|
-
|
|
15
|
+
lstatSync(p);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code === "ENOENT")
|
|
19
|
+
return null;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
let contents;
|
|
23
|
+
try {
|
|
24
|
+
contents = readFileSync(p, "utf8");
|
|
18
25
|
}
|
|
19
26
|
catch {
|
|
20
|
-
throw new CliError("bad_install_record", `${p}
|
|
27
|
+
throw new CliError("bad_install_record", `${p} cannot be read`, "Ask the machine operator to repair the recorded install");
|
|
28
|
+
}
|
|
29
|
+
let value;
|
|
30
|
+
try {
|
|
31
|
+
value = JSON.parse(contents);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw new CliError("bad_install_record", `${p} is not valid JSON`, "Ask the machine operator to repair the recorded install");
|
|
35
|
+
}
|
|
36
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || typeof value.bin !== "string" || !isAbsolute(value.bin)) {
|
|
37
|
+
throw new CliError("bad_install_record", `${p} does not contain an absolute bin path`, "Ask the machine operator to repair the recorded install");
|
|
21
38
|
}
|
|
39
|
+
return value;
|
|
22
40
|
}
|
|
23
41
|
/** The recorded install, checked to still exist; what watchers and hooks are pointed at. */
|
|
24
42
|
export function requireInstall() {
|
package/dist/merge-train.js
CHANGED
|
@@ -12,8 +12,10 @@ export const CLI_VERSION_CONFLICT_FILES = [
|
|
|
12
12
|
"packages/cli/package.json",
|
|
13
13
|
"packages/cli/src/version.ts",
|
|
14
14
|
];
|
|
15
|
+
export const PG_BASELINE_CONFLICT_FILE = "apps/api/pg-migrations/0001_baseline.sql";
|
|
15
16
|
export const MECHANICALLY_RESOLVABLE_CONFLICT_FILES = [
|
|
16
17
|
...CLI_VERSION_CONFLICT_FILES,
|
|
18
|
+
PG_BASELINE_CONFLICT_FILE,
|
|
17
19
|
];
|
|
18
20
|
const MAX_RE_GATE_ATTEMPTS = 3;
|
|
19
21
|
const SHA_RE = /^[0-9a-f]{7,64}$/i;
|
|
@@ -26,8 +28,12 @@ export function shaMatches(left, right) {
|
|
|
26
28
|
return false;
|
|
27
29
|
return a.startsWith(b) || b.startsWith(a);
|
|
28
30
|
}
|
|
31
|
+
export const TRAIN_GATE_STAGES = ["typecheck", "api tests", "cli tests", "web tests", "web build", "cli build", "published CLI contract"];
|
|
32
|
+
export function supportedTrainGateStage(stage) {
|
|
33
|
+
return TRAIN_GATE_STAGES.find(name => name === stage);
|
|
34
|
+
}
|
|
29
35
|
/** Resolve the shell command and complete-suite lock label from merge.gate_command. */
|
|
30
|
-
export function resolveTrainGateCommand(gateCommand, anchorUnitNumber, candidateSha, worktreeDir) {
|
|
36
|
+
export function resolveTrainGateCommand(gateCommand, anchorUnitNumber, candidateSha, worktreeDir, stage) {
|
|
31
37
|
let resolved = gateCommand ? gateCommand.trim() : null;
|
|
32
38
|
if (resolved) {
|
|
33
39
|
resolved = resolved.replaceAll("{unit}", String(anchorUnitNumber)).replaceAll("{head}", candidateSha);
|
|
@@ -42,11 +48,12 @@ export function resolveTrainGateCommand(gateCommand, anchorUnitNumber, candidate
|
|
|
42
48
|
}
|
|
43
49
|
const parts = resolved.split(/\s+/).filter(Boolean);
|
|
44
50
|
if (parts.length >= 1 && parts[0] === "scripts/gate.sh") {
|
|
51
|
+
const args = stage ? [...parts, "--stage", stage] : parts;
|
|
45
52
|
return {
|
|
46
|
-
commandLine: resolved,
|
|
47
|
-
commandLabel:
|
|
53
|
+
commandLine: stage ? `${resolved} --stage ${JSON.stringify(stage)}` : resolved,
|
|
54
|
+
commandLabel: args,
|
|
48
55
|
execCmd: "/bin/sh",
|
|
49
|
-
execArgs:
|
|
56
|
+
execArgs: args,
|
|
50
57
|
};
|
|
51
58
|
}
|
|
52
59
|
return {
|
|
@@ -345,6 +352,25 @@ async function tryResolveMechanicalMergeConflicts(worktreeDir, entry, conflictin
|
|
|
345
352
|
return false;
|
|
346
353
|
}
|
|
347
354
|
}
|
|
355
|
+
if (conflictingFiles.includes(PG_BASELINE_CONFLICT_FILE)) {
|
|
356
|
+
// This file is generated from the complete SQLite migration set. Keep the current
|
|
357
|
+
// accumulated baseline while merging each unit; the post-batch generator below writes
|
|
358
|
+
// the authoritative baseline after every included migration has landed.
|
|
359
|
+
const ours = await runner("git", ["-C", worktreeDir, "checkout", "--ours", "--", PG_BASELINE_CONFLICT_FILE], {
|
|
360
|
+
cwd: worktreeDir,
|
|
361
|
+
env,
|
|
362
|
+
timeoutMs: 30_000,
|
|
363
|
+
});
|
|
364
|
+
if (ours.status !== 0)
|
|
365
|
+
return false;
|
|
366
|
+
const add = await runner("git", ["-C", worktreeDir, "add", "--", PG_BASELINE_CONFLICT_FILE], {
|
|
367
|
+
cwd: worktreeDir,
|
|
368
|
+
env,
|
|
369
|
+
timeoutMs: 30_000,
|
|
370
|
+
});
|
|
371
|
+
if (add.status !== 0)
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
348
374
|
const remaining = await runner("git", ["-C", worktreeDir, "diff", "--name-only", "--diff-filter=U"], {
|
|
349
375
|
cwd: worktreeDir,
|
|
350
376
|
env,
|
|
@@ -402,6 +428,9 @@ async function mergeEntryIntoHead(worktreeDir, entry, resolvedSha, requireMergeC
|
|
|
402
428
|
export function cliVersionBumpRequired(paths) {
|
|
403
429
|
return paths.some((path) => path.startsWith("packages/cli/") || path.startsWith("packages/skill"));
|
|
404
430
|
}
|
|
431
|
+
export function pgBaselineRefreshRequired(paths) {
|
|
432
|
+
return paths.some((path) => path.startsWith("apps/api/migrations/") && path.endsWith(".sql"));
|
|
433
|
+
}
|
|
405
434
|
/**
|
|
406
435
|
* Executes a claimed merge-train gate job: merges queued approved heads onto origin/<target>
|
|
407
436
|
* in order, leaves conflicting units out, runs the configured gate under complete-suite lock,
|
|
@@ -500,6 +529,42 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
500
529
|
},
|
|
501
530
|
};
|
|
502
531
|
}
|
|
532
|
+
// SQLite migrations from every included unit land together. Regenerate the PostgreSQL
|
|
533
|
+
// baseline once from that complete merged tree before running the gate, then commit the
|
|
534
|
+
// generated file into the exact candidate that the gate verifies.
|
|
535
|
+
await h.runStep("refresh merged PostgreSQL baseline", async () => {
|
|
536
|
+
const changed = await h.runner("git", ["-C", h.worktreeDir, "diff", "--name-only", baseSha, "HEAD"], {
|
|
537
|
+
cwd: h.worktreeDir, env: gitEnv, timeoutMs: 15_000,
|
|
538
|
+
});
|
|
539
|
+
if (changed.status !== 0)
|
|
540
|
+
throw new Error(`could not inspect merged migration paths: ${(changed.stderr || changed.stdout).trim().slice(0, 300)}`);
|
|
541
|
+
if (!pgBaselineRefreshRequired(changed.stdout.split(/\r?\n/).filter(Boolean)))
|
|
542
|
+
return 0;
|
|
543
|
+
const generate = await h.runner("npm", ["run", "pg:generate-baseline", "-w", "apps/api"], {
|
|
544
|
+
cwd: h.worktreeDir, env: gitEnv, timeoutMs: 120_000,
|
|
545
|
+
});
|
|
546
|
+
if (generate.status !== 0)
|
|
547
|
+
throw new Error(`PostgreSQL baseline generation failed: ${(generate.stderr || generate.stdout).trim().slice(0, 500)}`);
|
|
548
|
+
h.onLogLine(generate.stdout.trim());
|
|
549
|
+
const pending = await h.runner("git", ["-C", h.worktreeDir, "diff", "--quiet", "--", "apps/api/pg-migrations/0001_baseline.sql"], {
|
|
550
|
+
cwd: h.worktreeDir, env: gitEnv, timeoutMs: 15_000,
|
|
551
|
+
});
|
|
552
|
+
if (pending.status === 1) {
|
|
553
|
+
const add = await h.runner("git", ["-C", h.worktreeDir, "add", "--", "apps/api/pg-migrations/0001_baseline.sql"], {
|
|
554
|
+
cwd: h.worktreeDir, env: gitEnv, timeoutMs: 15_000,
|
|
555
|
+
});
|
|
556
|
+
if (add.status !== 0)
|
|
557
|
+
throw new Error(`could not stage generated PostgreSQL baseline: ${(add.stderr || add.stdout).trim().slice(0, 300)}`);
|
|
558
|
+
const commit = await h.runner("git", ["-C", h.worktreeDir, "commit", "-m", "chore(api): refresh PostgreSQL baseline after migration batch"], {
|
|
559
|
+
cwd: h.worktreeDir, env: gitEnv, timeoutMs: 30_000,
|
|
560
|
+
});
|
|
561
|
+
if (commit.status !== 0)
|
|
562
|
+
throw new Error(`could not commit generated PostgreSQL baseline: ${(commit.stderr || commit.stdout).trim().slice(0, 300)}`);
|
|
563
|
+
}
|
|
564
|
+
else if (pending.status !== 0)
|
|
565
|
+
throw new Error(`could not check generated PostgreSQL baseline changes: ${(pending.stderr || pending.stdout).trim().slice(0, 300)}`);
|
|
566
|
+
return 0;
|
|
567
|
+
}, () => 0);
|
|
503
568
|
// The published CLI version identifies an immutable source tree. When this train lands
|
|
504
569
|
// CLI or skill changes, bump the version before calculating the candidate head and gate.
|
|
505
570
|
await h.runStep("bump merged CLI version", async () => {
|
|
@@ -623,9 +688,10 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
623
688
|
const runGateAtHead = async (stepName, unitForCmd, headSha, options = {}) => {
|
|
624
689
|
throwIfHeartbeatFailed();
|
|
625
690
|
const worktreeDir = options.worktreeDir ?? h.worktreeDir;
|
|
626
|
-
const gateEnv = options.env ?? lockedEnv;
|
|
691
|
+
const gateEnv = { ...(options.env ?? lockedEnv) };
|
|
692
|
+
delete gateEnv.GATE_STAGE;
|
|
627
693
|
const lockContextForGate = options.lockContext ?? lockContext;
|
|
628
|
-
const spec = resolveTrainGateCommand(trainRun.gate_command, unitForCmd, headSha, worktreeDir);
|
|
694
|
+
const spec = resolveTrainGateCommand(trainRun.gate_command, unitForCmd, headSha, worktreeDir, options.stage);
|
|
629
695
|
if (!spec)
|
|
630
696
|
return { status: 0, output: "" };
|
|
631
697
|
return h.runStep(stepName, async () => {
|
|
@@ -667,6 +733,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
667
733
|
return { status: res.status ?? 1, output };
|
|
668
734
|
}, (r) => r.status);
|
|
669
735
|
};
|
|
736
|
+
let probeStage;
|
|
670
737
|
const runIsolatedProbe = async (stepName, parts) => {
|
|
671
738
|
const probeId = randomBytes(8).toString("hex");
|
|
672
739
|
const probeRoot = join(dirname(h.worktreeDir), `parallel-${job.id}-${probeId}`);
|
|
@@ -696,7 +763,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
696
763
|
if (rev.status !== 0)
|
|
697
764
|
return { status: 2, output: "could not resolve isolated probe candidate", sha: null };
|
|
698
765
|
const probeSha = rev.stdout.trim().toLowerCase();
|
|
699
|
-
const spec = resolveTrainGateCommand(trainRun.gate_command, anchorUnit, probeSha, probeWorktree);
|
|
766
|
+
const spec = resolveTrainGateCommand(trainRun.gate_command, anchorUnit, probeSha, probeWorktree, probeStage);
|
|
700
767
|
if (!spec)
|
|
701
768
|
return { status: 0, output: "", sha: probeSha };
|
|
702
769
|
const result = await h.runWithLock({
|
|
@@ -708,7 +775,10 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
708
775
|
note: `merge-train ${trainRun.id} probe ${stepName} (${parts.map((part) => `#${part.entry.work_unit_number}`).join(",")}) @ ${probeSha.slice(0, 9)}`,
|
|
709
776
|
commandLabel: spec.commandLabel,
|
|
710
777
|
...(h.lockPollMs === undefined ? {} : { pollMs: h.lockPollMs }),
|
|
711
|
-
|
|
778
|
+
// Do not reuse remoteJobId across parallel bisect probes: remoteJobId derives a
|
|
779
|
+
// single deterministic job_token, which causes parallel probes to collide on the
|
|
780
|
+
// same complete-suite slot (note receipt mismatch + premature release failure).
|
|
781
|
+
...(h.signal ? { signal: h.signal } : {}),
|
|
712
782
|
run: async (probeLock) => {
|
|
713
783
|
const probeEnv = {
|
|
714
784
|
...gitEnv,
|
|
@@ -717,6 +787,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
717
787
|
TEMP: scratchDir,
|
|
718
788
|
BSCHAT_UX_JOB_ARTIFACT_DIR: artifactDir,
|
|
719
789
|
};
|
|
790
|
+
delete probeEnv.GATE_STAGE;
|
|
720
791
|
if (probeLock?.jobId)
|
|
721
792
|
probeEnv.B9S_LOCK_JOB_ID = probeLock.jobId;
|
|
722
793
|
if (!Number.isSafeInteger(probeLock?.slot) || probeLock.slot < 1 || probeLock.slot > 3) {
|
|
@@ -844,7 +915,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
844
915
|
};
|
|
845
916
|
const scanner = createGateMarkerScanner();
|
|
846
917
|
try {
|
|
847
|
-
const mainRun = await runGateAtHead("gate", anchorUnit, candidateSha, { keepSuccessfulResultOnHeartbeatError: true });
|
|
918
|
+
const mainRun = await runGateAtHead("gate", anchorUnit, candidateSha, { scanReceipt: true, keepSuccessfulResultOnHeartbeatError: true });
|
|
848
919
|
scanner.push("", true);
|
|
849
920
|
const scanResult = scanner.result();
|
|
850
921
|
gateOutputText = mainRun.output;
|
|
@@ -879,6 +950,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
879
950
|
h.onLogLine(`merge-train ${trainRun.id}: gate failed with retryable ${retryGateReason} signature`);
|
|
880
951
|
if (!retryGateReason) {
|
|
881
952
|
const initialFailedStep = failedStep;
|
|
953
|
+
probeStage = supportedTrainGateStage(initialFailedStep);
|
|
882
954
|
const outputHint = detectUnitAttributedFailureFromOutput(mainRun.output, included.map((i) => i.entry));
|
|
883
955
|
let candidateIndex = outputHint
|
|
884
956
|
? included.findIndex((item) => item.entry.work_unit_number === outputHint.unitNumber)
|
|
@@ -917,7 +989,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
917
989
|
if (midRev.status !== 0)
|
|
918
990
|
throw new Error("could not resolve bisection prefix HEAD");
|
|
919
991
|
const midSha = midRev.stdout.trim().toLowerCase();
|
|
920
|
-
const probe = await runGateAtHead(`bisect WU #${included.slice(0, mid + 1).map((x) => x.entry.work_unit_number).join(",#")}`, included[0].entry.work_unit_number, midSha);
|
|
992
|
+
const probe = await runGateAtHead(`bisect WU #${included.slice(0, mid + 1).map((x) => x.entry.work_unit_number).join(",#")}`, included[0].entry.work_unit_number, midSha, { stage: probeStage });
|
|
921
993
|
if (probe.status !== 0)
|
|
922
994
|
retryGateReason = classifyRetryableGateFailure(probe.output, probe.status);
|
|
923
995
|
if (retryGateReason)
|
|
@@ -935,7 +1007,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
935
1007
|
// A first-unit failure may already exist on target/main; never blame its only addition without checking.
|
|
936
1008
|
if (candidateIndex === 0) {
|
|
937
1009
|
await resetCleanWorktree(h.worktreeDir, baseSha, h.runner, gitEnv);
|
|
938
|
-
const baseProbe = await runGateAtHead(`bisect target ${baseSha.slice(0, 9)}`, anchorUnit, baseSha);
|
|
1010
|
+
const baseProbe = await runGateAtHead(`bisect target ${baseSha.slice(0, 9)}`, anchorUnit, baseSha, { stage: probeStage });
|
|
939
1011
|
if (baseProbe.status !== 0) {
|
|
940
1012
|
retryGateReason = classifyRetryableGateFailure(baseProbe.output, baseProbe.status);
|
|
941
1013
|
if (retryGateReason) {
|
|
@@ -976,7 +1048,7 @@ export async function runMergeTrainWorkflow(job, trainRun, h) {
|
|
|
976
1048
|
});
|
|
977
1049
|
if (confirmRev.status !== 0)
|
|
978
1050
|
throw new Error("could not resolve confirmation prefix HEAD");
|
|
979
|
-
const confirmation = await runGateAtHead(`confirm failing half through WU #${candidate.entry.work_unit_number}`, included[0].entry.work_unit_number, confirmRev.stdout.trim().toLowerCase());
|
|
1051
|
+
const confirmation = await runGateAtHead(`confirm failing half through WU #${candidate.entry.work_unit_number}`, included[0].entry.work_unit_number, confirmRev.stdout.trim().toLowerCase(), { stage: probeStage });
|
|
980
1052
|
if (confirmation.status !== 0)
|
|
981
1053
|
retryGateReason = classifyRetryableGateFailure(confirmation.output, confirmation.status);
|
|
982
1054
|
if (retryGateReason)
|
package/dist/output.js
CHANGED
|
@@ -65,6 +65,7 @@ export function fmtMessage(m) {
|
|
|
65
65
|
export function fmtStatus(s) {
|
|
66
66
|
const parts = [
|
|
67
67
|
`${s.state === "benched" ? "BENCHED " : ""}${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.away ? ` (away until ${s.away.until}: ${s.away.reason})` : s.usage_limit_until ? ` (usage limit until ${s.usage_limit_until})` : s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : s.liveness === "scheduled" ? ` (checks every ${s.checks_every} min, next ${(s.next_check_at ?? "").slice(11, 16)} UTC)` : s.liveness === "missed" ? ` (missed its ${s.checks_every}-min check)` : ""}`,
|
|
68
|
+
s.agent_state ? `agent_state=${s.agent_state} (${s.agent_state_source ?? "source unavailable"}: ${s.agent_state_reason ?? "reason unavailable"})${s.agent_state_fix ? `; fix=${s.agent_state_fix}` : ""}` : null,
|
|
68
69
|
`state=${s.state ?? "-"}`,
|
|
69
70
|
s.watcher_state ? `watcher=${s.watcher_state}${s.watcher_state === "errored" && s.watcher?.last_error ? `(${s.watcher.last_error})` : ""}` : null,
|
|
70
71
|
s.goal ? `goal="${s.goal}"` : null,
|
package/dist/version.js
CHANGED