benignswarm 0.12.99 → 0.12.100
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 +2 -2
- package/dist/client.js +12 -2
- package/dist/command-runner.js +16 -0
- package/dist/errors.js +12 -0
- package/dist/help.js +3 -0
- package/dist/index.js +2 -2
- package/dist/output.js +20 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/admin-index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { makeOut } from "./output.js";
|
|
|
8
8
|
import { CLI_VERSION } from "./version.js";
|
|
9
9
|
import { applyEnvAliases } from "./env-aliases.js";
|
|
10
10
|
import { versionLine, warnLegacyAlias } from "./legacy-alias.js";
|
|
11
|
+
import { runCommandSafely } from "./command-runner.js";
|
|
11
12
|
/** b9s-admin: the operator binary. Agents use b9s, whose help never lists these. */
|
|
12
13
|
async function main(argv) {
|
|
13
14
|
warnLegacyAlias();
|
|
@@ -28,8 +29,7 @@ async function main(argv) {
|
|
|
28
29
|
process.stdout.write(ADMIN_HELP);
|
|
29
30
|
return p.positionals[0] ? 0 : 2;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
return 0;
|
|
32
|
+
return runCommandSafely(() => admin({ ...p, positionals: ["admin", ...p.positionals] }, out), out);
|
|
33
33
|
}
|
|
34
34
|
main(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (err) => {
|
|
35
35
|
const e = err instanceof CliError ? { error: err.code, message: err.message, hint: err.hint } : { error: "internal", message: err instanceof Error ? err.stack ?? err.message : String(err) };
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { CliError } from "./errors.js";
|
|
2
|
+
import { CliError, WrittenReceiptMismatchError } from "./errors.js";
|
|
3
3
|
import { collectAuto } from "./git.js";
|
|
4
4
|
import { resolveEffort } from "./model.js";
|
|
5
5
|
import { cliUserAgent } from "./legacy-alias.js";
|
|
@@ -96,6 +96,8 @@ function expectedTextReceiptFields(method, path, body, response) {
|
|
|
96
96
|
}
|
|
97
97
|
if (action === "assign" || action === "kind" || action === "mandatory-reviewer" || action === "required-class")
|
|
98
98
|
return strings("reason");
|
|
99
|
+
if (action === "take")
|
|
100
|
+
return strings("reason");
|
|
99
101
|
if (action === "compare")
|
|
100
102
|
return strings("note", "primary_note", "twin_note");
|
|
101
103
|
if (action === "ask")
|
|
@@ -347,7 +349,15 @@ export class Client {
|
|
|
347
349
|
throw new CliError(err.error ?? `http_${res.status}`, err.message ?? text, hint);
|
|
348
350
|
}
|
|
349
351
|
const allowsRedactedExcerpt = method.toUpperCase() === "POST" && /^\/agents\/me\/sessions\/[^/]+\/turns\/[^/]+\/complete(?:\?|$)/.test(path);
|
|
350
|
-
|
|
352
|
+
try {
|
|
353
|
+
verifyTextReceipts(json, body, expectedTextReceiptFields(method, path, body, json), allowsRedactedExcerpt ? ["excerpt"] : [], allowsRedactedExcerpt ? ["excerpt"] : []);
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
if (res.status >= 200 && res.status < 300 && error instanceof CliError && !["GET", "HEAD"].includes(method.toUpperCase())) {
|
|
357
|
+
throw new WrittenReceiptMismatchError(json, error);
|
|
358
|
+
}
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
351
361
|
return json;
|
|
352
362
|
}
|
|
353
363
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WrittenReceiptMismatchError, WRITTEN_RECEIPT_MISMATCH_EXIT_CODE } from "./errors.js";
|
|
2
|
+
import { printWrittenReceiptMismatch } from "./output.js";
|
|
3
|
+
/** Print committed write results when their receipt is invalid; ordinary API refusals stay errors. */
|
|
4
|
+
export async function runCommandSafely(run, out) {
|
|
5
|
+
try {
|
|
6
|
+
return (await run()) ?? 0;
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error instanceof WrittenReceiptMismatchError) {
|
|
10
|
+
const detail = error.message.replace(/^write succeeded; receipt mismatch:\s*/, "");
|
|
11
|
+
printWrittenReceiptMismatch(out, error.response, detail);
|
|
12
|
+
return WRITTEN_RECEIPT_MISMATCH_EXIT_CODE;
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -7,5 +7,17 @@ export class CliError extends Error {
|
|
|
7
7
|
this.hint = hint;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
/** A 2xx response committed a write, but its text receipt did not prove the stored text. */
|
|
11
|
+
export class WrittenReceiptMismatchError extends CliError {
|
|
12
|
+
response;
|
|
13
|
+
receiptErrorCode;
|
|
14
|
+
constructor(response, receiptError) {
|
|
15
|
+
super("written_receipt_mismatch", `write succeeded; receipt mismatch: ${receiptError.message}`);
|
|
16
|
+
this.response = response;
|
|
17
|
+
this.receiptErrorCode = receiptError.code;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
10
20
|
/** systemd's EX_CONFIG status: stop restarting a watcher until its local configuration is fixed. */
|
|
11
21
|
export const DIRECTORY_CONFLICT_EXIT_CODE = 78;
|
|
22
|
+
/** The write succeeded, but its receipt did not verify. Callers must inspect the object, not retry. */
|
|
23
|
+
export const WRITTEN_RECEIPT_MISMATCH_EXIT_CODE = 3;
|
package/dist/help.js
CHANGED
|
@@ -6,6 +6,7 @@ Identity (required for agent commands): --as <project>/<name> or BSCHAT_AGENT=<p
|
|
|
6
6
|
Model: detected automatically (hook input, transcript, harness config); --model or BSCHAT_MODEL override
|
|
7
7
|
Provider: set BSCHAT_PROVIDER when the harness does not report it; unknown is never inferred from the harness
|
|
8
8
|
Output: --json for machine-readable output; successful text writes print stored bytes and SHA-256
|
|
9
|
+
b9s and b9s-admin: a 2xx write with a receipt mismatch prints the returned object and warning, then exits 3; inspect it and do not retry
|
|
9
10
|
Environment: BSCHAT_* names remain supported; matching B9S_* names are aliases when BSCHAT_* is unset
|
|
10
11
|
|
|
11
12
|
Joining (first time on a machine, with an enrollment token from the account owner)
|
|
@@ -267,6 +268,8 @@ These act for the account's owner: projects, agents, invites, roles, the process
|
|
|
267
268
|
waiting on you. Agents in projects use b9s and never need this. An AI agent driving this
|
|
268
269
|
tool should run b9s-admin --agent first, then install the operator skill. Sign in once per machine with
|
|
269
270
|
b9s-admin login (approve it in your signed-in browser); the session lasts 30 days, like the console's.
|
|
271
|
+
Successful writes verify stored-text receipts. If a 2xx write receipt mismatches, b9s-admin prints
|
|
272
|
+
the returned object and warning, then exits 3. Inspect the object and do not retry that write.
|
|
270
273
|
|
|
271
274
|
b9s-admin login [--as <nickname>] [--url <api>]
|
|
272
275
|
prints a link and a code and opens it: approve it in a browser already signed in to BenignSwarm
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import { versionLine, warnLegacyAlias } from "./legacy-alias.js";
|
|
|
35
35
|
import { gitCredentialMain } from "./commands/git-credential.js";
|
|
36
36
|
import { templates } from "./commands/templates.js";
|
|
37
37
|
import { environment } from "./commands/environment.js";
|
|
38
|
+
import { runCommandSafely } from "./command-runner.js";
|
|
38
39
|
const COMMANDS = {
|
|
39
40
|
join,
|
|
40
41
|
setup,
|
|
@@ -151,8 +152,7 @@ async function main(argv) {
|
|
|
151
152
|
process.stderr.write(`[b9s] command notice check failed; command will continue unchecked: ${e.message}\n`);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
-
return code ?? 0;
|
|
155
|
+
return runCommandSafely(() => fn(p, out), out);
|
|
156
156
|
}
|
|
157
157
|
main(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (err) => {
|
|
158
158
|
const isWatcherDirectoryConflict = err instanceof CliError && err.code === "directory_conflict" && invokedCommand === "watch";
|
package/dist/output.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
export function printWrittenReceiptMismatch(out, response, detail) {
|
|
2
|
+
const record = response && typeof response === "object" ? response : { response };
|
|
3
|
+
const unit = record.unit && typeof record.unit === "object" ? record.unit : null;
|
|
4
|
+
const message = record.message && typeof record.message === "object" ? record.message : null;
|
|
5
|
+
const seq = Number.isInteger(record.seq) ? record.seq : message && Number.isInteger(message.seq) ? message.seq : null;
|
|
6
|
+
const channel = typeof record.channel === "string" ? record.channel : typeof message?.channel === "string" ? message.channel : null;
|
|
7
|
+
const human = unit && Number.isInteger(unit.number)
|
|
8
|
+
? `Write succeeded for WU #${unit.number}; inspect the returned object below.`
|
|
9
|
+
: seq !== null
|
|
10
|
+
? `Write succeeded; returned message${channel ? ` #${seq} in #${channel}` : ` #${seq}`} is shown below.`
|
|
11
|
+
: "Write succeeded; the returned object is shown below.";
|
|
12
|
+
const warning = `write succeeded; receipt mismatch: ${detail}. Do not retry this write; inspect the returned object.`;
|
|
13
|
+
if (out.json)
|
|
14
|
+
out.print(human, { ...record, receipt_warning: warning });
|
|
15
|
+
else {
|
|
16
|
+
out.print(human, response);
|
|
17
|
+
process.stdout.write(`${JSON.stringify(record, null, 2)}\n`);
|
|
18
|
+
process.stderr.write(`WARNING: ${warning}\n`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
1
21
|
function receiptLine(data) {
|
|
2
22
|
const receipts = Array.isArray(data?.receipts) ? data.receipts : data?.receipt ? [data.receipt] : [];
|
|
3
23
|
if (!receipts.length)
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.100";
|