benignswarm 0.12.93 → 0.12.95
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/antigravity.js +167 -46
- package/dist/args.js +3 -3
- package/dist/boot-time.js +39 -0
- package/dist/brief.js +1 -1
- package/dist/build-caches.js +891 -0
- package/dist/client.js +20 -0
- package/dist/commands/admin.js +97 -2
- package/dist/commands/cloud-admin.js +74 -0
- package/dist/commands/codex-start.js +131 -31
- package/dist/commands/machine-admin.js +98 -14
- package/dist/commands/machine.js +130 -28
- package/dist/commands/watch.js +29 -23
- package/dist/commands/wu.js +215 -7
- package/dist/git.js +20 -6
- package/dist/harnesses.js +7 -6
- package/dist/help.js +35 -15
- package/dist/index.js +1 -1
- package/dist/recovery-archive.js +149 -0
- package/dist/turn-guard.js +32 -11
- package/dist/usage.js +6 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/help.js
CHANGED
|
@@ -20,7 +20,7 @@ GET /account/usage reports used and allowed micro-dollars, uncertain calls and t
|
|
|
20
20
|
Session/admin clients can use GET /assistant/conversations, GET /assistant/conversations/:id/messages (paged history with saved tool notices), POST /assistant/conversations/:id/messages (SSE), and DELETE /assistant/conversations/:id. Old assistant messages report notices_available=false. The assistant can draft changes; POST /assistant/proposals/:id/apply or /discard is the operator's explicit action. See the agent/operator skill API reference for events and tools.
|
|
21
21
|
Free and paid accounts without a live Stripe subscription use the UTC calendar month; subscribed paid accounts reset at current_period_end.
|
|
22
22
|
|
|
23
|
-
GitHub repository
|
|
23
|
+
GitHub connection and repository status are available in the console and through b9s-admin github status and b9s-admin project github <project> status|unlink. 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 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.
|
|
24
24
|
|
|
25
25
|
Agent commands
|
|
26
26
|
b9s login --as <name> --key <bs_agent_...> [--url <api>] [--label <machine-label>]
|
|
@@ -56,7 +56,8 @@ Agent commands
|
|
|
56
56
|
reports why candidates were passed over, and the sweep chases it;
|
|
57
57
|
--to queue waits deliberately; naming a busy worker reserves it for them (theirs when free,
|
|
58
58
|
anyone's after the takeover window); --hold keeps it assigned to them however long it takes;
|
|
59
|
-
--template --tags a,b prints the scope skeleton; --force records missing required sections, including for queue
|
|
59
|
+
--template --tags a,b prints the scope skeleton; --force records missing required sections, including for queue;
|
|
60
|
+
assignment reports advisory scope/tier suggestions from recorded causes, with counts and source dates; nothing is applied.
|
|
60
61
|
b9s wu assign <n> --to <agent> [--reason "why"] [--allow-lower-tier] reassign an assigned or queued unit in place; a lower-tier target needs both flags and a reason
|
|
61
62
|
b9s wu take <n> [--to <agent>] [--reason "why"] pull a unit or hand it to someone
|
|
62
63
|
reason is required when an assigner uses its assign_outside_qualifications role capability
|
|
@@ -70,8 +71,8 @@ Agent commands
|
|
|
70
71
|
target as of the original); a worktree left half-written by an interrupted
|
|
71
72
|
checkout is removed and made again; wu open does the same for your own units;
|
|
72
73
|
--branch continues existing work; --here uses this checkout
|
|
73
|
-
b9s record per agent
|
|
74
|
-
b9s record --by model
|
|
74
|
+
b9s record per agent/tag; --json also includes project cause aggregates, cohorts, and role-scoped attribution
|
|
75
|
+
b9s record --by model same counters keyed by model and effort; JSON also includes cause aggregates by stamped model and effort
|
|
75
76
|
b9s milestones the plan's slices: ready or waiting on which, units done/total; wu open|assign --milestone <key>
|
|
76
77
|
b9s milestones set --file plan.json define or replace the plan (assigner roles or the operator): a JSON list of
|
|
77
78
|
{key, title, exit, depends_on, default_tags}; existing keys keep their status; cycles are refused
|
|
@@ -132,7 +133,11 @@ Agent commands
|
|
|
132
133
|
wu release <n> [--note ..] lifts it earlier
|
|
133
134
|
b9s wu evidence replace <n> <old> <new> [--note ".."] owner replaces attached evidence; old id is retained in the unit history
|
|
134
135
|
b9s wu done <n> --merged <sha> | --no-source --evidence id[,id...] [--keep-worktree] after approval; no-source closes an evidence-only unit without a merge SHA and checks its branch has no commits beyond the target
|
|
136
|
+
b9s wu merge <n> [--note "..."] role-checked hosted merge through the API; never inspects local Git credentials or state
|
|
137
|
+
b9s wu merge status <n> operation status and non-secret audit trail for a hosted merge
|
|
135
138
|
b9s wu show <n> [--scope-only] show the full unit or only its scope for scripts
|
|
139
|
+
b9s wu recovery save <n> --reason "..." save a WIP branch commit and encrypted cutoff bundle; keep the source volume until safe_to_delete
|
|
140
|
+
b9s wu recovery restore <n> next owner: verify and restore the restricted recovery bundle into the unit worktree
|
|
136
141
|
b9s wu abandon <n> [--note ..] wu list [--all] for state and timeline
|
|
137
142
|
b9s worktrees prune [--yes] [--archive] remove clean worktrees whose work landed or whose unit is closed (dry run without --yes);
|
|
138
143
|
--archive also saves a closed unit's uncommitted files to archive/wu<n>-leftovers and removes it
|
|
@@ -150,10 +155,11 @@ Agent commands
|
|
|
150
155
|
--env A,B copies those variables from this shell into the LaunchAgent (Antigravity needs
|
|
151
156
|
ANTIGRAVITY_LS_ADDRESS,ANTIGRAVITY_CSRF_TOKEN). --full queues the text itself. --once /
|
|
152
157
|
--service (launchd on macOS, systemd on Linux; --launchd is the same). --turn runs each turn
|
|
153
|
-
itself (--harness codex|claude-code|dsh --session <id>); 3 consecutive turns without an
|
|
154
|
-
agent-key call
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
itself (--harness codex|claude-code|dsh|antigravity --session <id>); 3 consecutive turns without an
|
|
159
|
+
agent-key call faults it; six unproductive turns in a rolling hour also fault. The 60-turn
|
|
160
|
+
hourly cap pauses a busy agent until a turn rolls out, then resumes automatically. Set
|
|
161
|
+
--turns-per-hour 1..60 and --unproductive-per-hour 1..60; an operator or assigner can
|
|
162
|
+
resume a latched fault with b9s-admin machine session resume.
|
|
157
163
|
Codex: b9s watch --exec "codex queue --thread <id> --message {summary}" --service
|
|
158
164
|
b9s update the same as install --latest: upgrade this machine's b9s, repair PATH aliases,
|
|
159
165
|
restart services on that install without waiting on one stop, and report failures
|
|
@@ -162,12 +168,12 @@ Agent commands
|
|
|
162
168
|
b9s doctor every b9s on this machine and who runs which (PATH, npx caches, this repo's
|
|
163
169
|
hook and instructions, each watcher's plist versus what launchd runs), with fixes
|
|
164
170
|
b9s codex hooks | bind <thread-id> | sync install b9s's Codex hooks (~/.codex/hooks.json) and say which thread is you
|
|
165
|
-
b9s start --harness codex|claude-code|dsh --as <project>/<name> --sandbox <mode> [--provider anthropic|deepseek] [--token t] [--thread id] [--model m] [--effort e] [--writable-root path]... [--max-budget-usd n] [--turns-per-hour 1..
|
|
171
|
+
b9s start --harness codex|claude-code|dsh|antigravity --as <project>/<name> --sandbox <mode> [--provider anthropic|deepseek] [--token t] [--thread id] [--model m] [--effort e] [--writable-root path]... [--max-budget-usd n] [--turns-per-hour 1..60] [--unproductive-per-hour 1..60] [--dsh path] [--agy path]
|
|
166
172
|
run an agent headless: enroll, start or adopt its session, turn-mode watcher
|
|
167
173
|
Claude Code workspace-write defaults to a $1 per-turn cap; configure it with --max-budget-usd
|
|
168
174
|
(b9s codex start is the same with --harness codex)
|
|
169
175
|
b9s unpause [--as <a>] lift a usage-limit pause now (the harness was switched to an account with quota)
|
|
170
|
-
b9s machine run | once | status | prepare | service
|
|
176
|
+
b9s machine run [--interval seconds] | once | status | prepare | service default 30s, 1..3600; prepare checks dsh availability/version (Linux has no DSH build)
|
|
171
177
|
b9s checkpoint "<title>" --body "..." a resume note without retiring: what you are doing, open threads, next steps;
|
|
172
178
|
your next session (after a move to another machine) reads it first
|
|
173
179
|
b9s antigravity bind <conversation-id> | sync which Antigravity conversation is you, for its hook (watchers bind theirs)
|
|
@@ -222,15 +228,21 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
|
|
|
222
228
|
b9s-admin text-check <project> find bschat mentions in working agreements, charter, tags, roles and open scopes
|
|
223
229
|
b9s-admin signup --url <api> --key <signup-code> <account-name> <email>
|
|
224
230
|
b9s-admin project create|list|delete <name>
|
|
231
|
+
b9s-admin github status | disconnect <installation-id>
|
|
232
|
+
b9s-admin project github <project> status | unlink
|
|
233
|
+
b9s-admin project hosted-merge <project> enable|disable [--confirm-bypass-signal]
|
|
234
|
+
enable only after the live GitHub bypass-change signal check; status/link controls are also in console WU #196
|
|
225
235
|
b9s-admin agent create <project> <name> --vendor <v> [--role r] [--machine m]
|
|
226
236
|
b9s-admin agent --account create <name> --vendor <v> --role <r> account-wide agent (role's --projects decides access)
|
|
227
237
|
b9s-admin agent --account list|role|tier|rotate-key|bench|unbench|delete ...
|
|
228
238
|
b9s-admin agent --account bench|unbench <agent> [--note <text>]
|
|
239
|
+
b9s-admin agent --account retire <agent> [--note <text> | --note-file <file>] --yes
|
|
229
240
|
b9s-admin agent list <project>
|
|
230
241
|
b9s-admin agent tier <project>/<agent> <routine|careful|expert> set the routing tier (unset agents are routine)
|
|
231
242
|
b9s-admin agent --account tier <agent> <routine|careful|expert> set an account-wide agent's tier
|
|
232
243
|
b9s-admin agent bench <project>/<agent> [--note <text>] suspend keys and free an active seat
|
|
233
244
|
b9s-admin agent unbench <project>/<agent> restore keys if a seat is available
|
|
245
|
+
b9s-admin agent retire <project>/<agent> [--note <text> | --note-file <file>] --yes revoke keys, release its units, optionally save a resume handoff
|
|
234
246
|
b9s-admin agent away <project>/<agent> (--for <minutes|hours> | --until <ISO timestamp>) --reason "why"
|
|
235
247
|
b9s-admin agent back <project>/<agent>
|
|
236
248
|
b9s-admin enroll create <project> [--name n | --prefix p] [--role r] [--uses n] [--expires-hours h] prints the invite text
|
|
@@ -279,7 +291,7 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
|
|
|
279
291
|
b9s-admin worktree forget <project> <id> delete a stale worktree record (never the directory)
|
|
280
292
|
|
|
281
293
|
Machines (provisioned over your own ssh; a daemon on each runs the agent sessions you declare)
|
|
282
|
-
b9s-admin machine add <name> --ssh <host> [--rotate] [--codex-userns] [--bwrap-userns] install Node and b9s (no sudo), linger,
|
|
294
|
+
b9s-admin machine add <name> --ssh <host> [--rotate] [--codex-userns] [--bwrap-userns] install Node and b9s (no sudo), linger, harness login checks,
|
|
283
295
|
b9s's Codex hooks in /etc/codex (passwordless sudo only), register, start the daemon;
|
|
284
296
|
--codex-userns: where Linux restricts user namespaces (Ubuntu 24.04+), install a
|
|
285
297
|
Codex-only AppArmor profile so sandboxed agents can run; --bwrap-userns: the same
|
|
@@ -287,10 +299,10 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
287
299
|
b9s-admin machine list | show <name> | remove <name>
|
|
288
300
|
b9s-admin machine maintenance <name> --at <ISO | HH:MM> --for <30m | 2h> | --cancel a window: no new turns from
|
|
289
301
|
15 min before, its agents away until the machine reports back after booting
|
|
290
|
-
b9s-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access> [--harness codex|claude-code] [--provider anthropic|deepseek]
|
|
291
|
-
[--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min] [--turns-per-hour 1..
|
|
302
|
+
b9s-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access> [--harness codex|claude-code|dsh|antigravity] [--provider anthropic|deepseek]
|
|
303
|
+
[--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min] [--turns-per-hour 1..60] [--unproductive-per-hour 1..60]
|
|
292
304
|
b9s-admin machine session thread <machine> <project>/<agent> <thread-id|none> set or clear the thread a pool session adopts
|
|
293
|
-
b9s-admin machine session stop|start|resume|limit|remove <machine> <project>/<agent> resume a latched
|
|
305
|
+
b9s-admin machine session stop|start|resume|limit|remove <machine> <project>/<agent> resume a latched fault or set its busy and unproductive hourly limits
|
|
294
306
|
(change its count/settings, pause scaling, pin, or bench the agent)
|
|
295
307
|
b9s-admin agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--harness codex|claude-code] [--provider anthropic|deepseek] [--carry note|thread]
|
|
296
308
|
[--from local|<ssh host>] [--model m] [--effort e] [--wait min] [--force]
|
|
@@ -300,12 +312,20 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
300
312
|
b9s-admin machine slots <name> <n | auto> how many sessions it takes (auto: one per 4 GB of RAM)
|
|
301
313
|
b9s-admin machine writable <name> <path...> | none folders workspace-write agents there may also write (~/.cargo, ~/.ester)
|
|
302
314
|
b9s-admin machine workdir <name> <path | default> where its daemon clones projects for pool sessions (default ~/bschat)
|
|
315
|
+
b9s-admin machine cache-budget <name> [<GB> | default] [--floor <pct | default>] per-cache budget (default 40 GB) and volume free-space floor (default 15%)
|
|
316
|
+
b9s-admin machine caches <name> <path...> | none [--tool auto|cargo|generic] [--processes cmd,...] declared build-cache directories managed by the daemon
|
|
317
|
+
|
|
318
|
+
BYO AWS cloud machines (the connection is account-scoped; AWS bills the account directly)
|
|
319
|
+
b9s-admin cloud connect --file connection.json connect an IAM role, show its external ID once, and print the reviewed trust/permissions policies
|
|
320
|
+
b9s-admin cloud show | policy | test | disconnect
|
|
321
|
+
b9s-admin cloud launch --machine <id> --idempotency-key <key> request one capped on-demand instance; retries with the same key return the same operation
|
|
322
|
+
b9s-admin cloud operations | inspect <operation-id> | terminate <operation-id> --reason <why> terminate refuses unless signed ownership proof and immutable tags verify
|
|
303
323
|
|
|
304
324
|
Pools (a role, variants and a count; the server names the agents and places them on machines)
|
|
305
325
|
b9s-admin project repo <project> <git url | none> what machines clone for the project's pool sessions
|
|
306
326
|
b9s-admin project checkout <project> --exclude <path,path | none> paths new worktrees leave out (sparse checkout), e.g. logs/
|
|
307
327
|
b9s-admin pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight][@anthropic|deepseek] [--variant ...]
|
|
308
|
-
--count <n> --sandbox <mode> [--needs label,label] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..
|
|
328
|
+
--count <n> --sandbox <mode> [--needs label,label] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..60] [--unproductive-per-hour 1..60]
|
|
309
329
|
slots are agents named <name>-<tag>-<n>; fewer retires the extra ones
|
|
310
330
|
b9s-admin pool list [project] | show <project>/<name> | remove <project>/<name>
|
|
311
331
|
b9s-admin delete-account --confirm "delete everything"
|
package/dist/index.js
CHANGED
|
@@ -73,7 +73,7 @@ const COMMANDS = {
|
|
|
73
73
|
start: async (p, out) => {
|
|
74
74
|
const h = str(p.flags, "harness");
|
|
75
75
|
if (!h)
|
|
76
|
-
throw new CliError("usage", "start needs --harness <codex|claude-code>");
|
|
76
|
+
throw new CliError("usage", "start needs --harness <codex|claude-code|dsh|antigravity>");
|
|
77
77
|
return harnessStart(p, out, turnHarness(h));
|
|
78
78
|
},
|
|
79
79
|
unpause: async (p, out) => unpause(p, out),
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { open, mkdir, lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute, resolve, sep } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { gunzipSync, gzipSync } from "node:zlib";
|
|
5
|
+
import { CliError } from "./errors.js";
|
|
6
|
+
const MAGIC = new TextEncoder().encode("BSRECOV1");
|
|
7
|
+
function safePath(root, path) {
|
|
8
|
+
if (!path || path.length > 4096 || isAbsolute(path) || path.includes("\\") || path.includes("\0") || path.split("/").some((part) => !part || part === "." || part === ".."))
|
|
9
|
+
throw new CliError("unsafe_recovery", `unsafe recovery path ${JSON.stringify(path)}`);
|
|
10
|
+
const target = resolve(root, path);
|
|
11
|
+
if (target !== root && !target.startsWith(root + sep))
|
|
12
|
+
throw new CliError("unsafe_recovery", `recovery path escapes worktree: ${path}`);
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
15
|
+
/** Restores the simple length-prefixed regular-file format emitted by b9s recovery save. */
|
|
16
|
+
export async function restoreRecoveryArchive(data, worktree) {
|
|
17
|
+
try {
|
|
18
|
+
data = gunzipSync(data, { maxOutputLength: 1024 * 1024 * 1024 + 16 * 1024 * 1024 + 12 });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new CliError("bad_recovery_archive", "recovery bundle is not valid gzip data or expands beyond the 1 GiB recovery limit");
|
|
22
|
+
}
|
|
23
|
+
if (data.length < 12 || !MAGIC.every((v, i) => data[i] === v))
|
|
24
|
+
throw new CliError("bad_recovery_archive", "recovery bundle has an unsupported archive format");
|
|
25
|
+
const manifestSize = new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(8);
|
|
26
|
+
if (manifestSize > 16 * 1024 * 1024 || 12 + manifestSize > data.length)
|
|
27
|
+
throw new CliError("bad_recovery_archive", "recovery archive manifest is truncated or too large");
|
|
28
|
+
let files;
|
|
29
|
+
try {
|
|
30
|
+
files = JSON.parse(new TextDecoder().decode(data.subarray(12, 12 + manifestSize)));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new CliError("bad_recovery_archive", "recovery archive manifest is invalid JSON");
|
|
34
|
+
}
|
|
35
|
+
if (!Array.isArray(files) || files.length > 100_000)
|
|
36
|
+
throw new CliError("bad_recovery_archive", "recovery archive file list is invalid");
|
|
37
|
+
let archiveSize = 0;
|
|
38
|
+
let archiveOffset = 12 + manifestSize;
|
|
39
|
+
const archivePaths = new Set();
|
|
40
|
+
for (const entry of files) {
|
|
41
|
+
if (!entry || typeof entry.path !== "string" || !Number.isSafeInteger(entry.size) || entry.size < 0 || archivePaths.has(entry.path))
|
|
42
|
+
throw new CliError("bad_recovery_archive", "recovery archive contains an invalid or duplicate file entry");
|
|
43
|
+
safePath(worktree, entry.path);
|
|
44
|
+
archivePaths.add(entry.path);
|
|
45
|
+
archiveSize += entry.size;
|
|
46
|
+
if (!Number.isSafeInteger(archiveSize) || archiveSize > 1024 * 1024 * 1024)
|
|
47
|
+
throw new CliError("bad_recovery_archive", "recovery archive file data exceeds the 1 GiB recovery limit");
|
|
48
|
+
archiveOffset += entry.size;
|
|
49
|
+
}
|
|
50
|
+
if (archiveOffset > data.length)
|
|
51
|
+
throw new CliError("bad_recovery_archive", "recovery archive file data is truncated");
|
|
52
|
+
if (archiveOffset !== data.length)
|
|
53
|
+
throw new CliError("bad_recovery_archive", "recovery archive has trailing bytes");
|
|
54
|
+
const root = await realpath(worktree);
|
|
55
|
+
let offset = 12 + manifestSize;
|
|
56
|
+
const restored = [];
|
|
57
|
+
const seen = new Set();
|
|
58
|
+
// Validate all existing paths first so a later symlink cannot cause a partial restore.
|
|
59
|
+
for (const entry of files) {
|
|
60
|
+
const target = safePath(root, entry.path);
|
|
61
|
+
let parent = root;
|
|
62
|
+
for (const part of entry.path.split("/").slice(0, -1)) {
|
|
63
|
+
parent = resolve(parent, part);
|
|
64
|
+
try {
|
|
65
|
+
const stat = await lstat(parent);
|
|
66
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
67
|
+
throw new CliError("unsafe_recovery", `recovery path crosses a symlink or non-directory: ${entry.path}`);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error.code === "ENOENT")
|
|
71
|
+
break;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const stat = await lstat(target);
|
|
77
|
+
if (stat.isSymbolicLink() || !stat.isFile())
|
|
78
|
+
throw new CliError("unsafe_recovery", `refusing to replace a symlink or non-file: ${entry.path}`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error.code !== "ENOENT")
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const entry of files) {
|
|
86
|
+
if (!entry || typeof entry.path !== "string" || !Number.isSafeInteger(entry.size) || entry.size < 0 || seen.has(entry.path))
|
|
87
|
+
throw new CliError("bad_recovery_archive", "recovery archive contains an invalid or duplicate file entry");
|
|
88
|
+
seen.add(entry.path);
|
|
89
|
+
const target = safePath(root, entry.path);
|
|
90
|
+
if (offset + entry.size > data.length)
|
|
91
|
+
throw new CliError("bad_recovery_archive", `recovery archive is truncated at ${entry.path}`);
|
|
92
|
+
const parts = entry.path.split("/");
|
|
93
|
+
let parent = root;
|
|
94
|
+
for (const part of parts.slice(0, -1)) {
|
|
95
|
+
parent = resolve(parent, part);
|
|
96
|
+
try {
|
|
97
|
+
const stat = await lstat(parent);
|
|
98
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
99
|
+
throw new CliError("unsafe_recovery", `recovery path crosses a symlink or non-directory: ${entry.path}`);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error.code !== "ENOENT")
|
|
103
|
+
throw error;
|
|
104
|
+
await mkdir(parent);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const stat = await lstat(target);
|
|
109
|
+
if (stat.isSymbolicLink() || !stat.isFile())
|
|
110
|
+
throw new CliError("unsafe_recovery", `refusing to replace a symlink or non-file: ${entry.path}`);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error.code !== "ENOENT")
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
const file = await open(target, "w", 0o600);
|
|
117
|
+
try {
|
|
118
|
+
await file.write(data.subarray(offset, offset + entry.size));
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
await file.close();
|
|
122
|
+
}
|
|
123
|
+
offset += entry.size;
|
|
124
|
+
restored.push(entry.path);
|
|
125
|
+
}
|
|
126
|
+
if (offset !== data.length)
|
|
127
|
+
throw new CliError("bad_recovery_archive", "recovery archive has trailing bytes");
|
|
128
|
+
return restored;
|
|
129
|
+
}
|
|
130
|
+
export function sha256(data) { return createHash("sha256").update(data).digest("hex"); }
|
|
131
|
+
export function recoveryArchiveHeader(files) {
|
|
132
|
+
const json = new TextEncoder().encode(JSON.stringify(files));
|
|
133
|
+
const header = new Uint8Array(12 + json.length);
|
|
134
|
+
header.set(MAGIC);
|
|
135
|
+
new DataView(header.buffer).setUint32(8, json.length);
|
|
136
|
+
header.set(json, 12);
|
|
137
|
+
return header;
|
|
138
|
+
}
|
|
139
|
+
export function createRecoveryArchive(files) {
|
|
140
|
+
const header = recoveryArchiveHeader(files.map(({ path, bytes }) => ({ path, size: bytes.length })));
|
|
141
|
+
const raw = new Uint8Array(header.length + files.reduce((n, entry) => n + entry.bytes.length, 0));
|
|
142
|
+
raw.set(header);
|
|
143
|
+
let offset = header.length;
|
|
144
|
+
for (const entry of files) {
|
|
145
|
+
raw.set(entry.bytes, offset);
|
|
146
|
+
offset += entry.bytes.length;
|
|
147
|
+
}
|
|
148
|
+
return gzipSync(raw, { level: 6 });
|
|
149
|
+
}
|
package/dist/turn-guard.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export const DEFAULT_TURNS_PER_HOUR =
|
|
1
|
+
export const DEFAULT_TURNS_PER_HOUR = 60;
|
|
2
|
+
export const MAX_TURNS_PER_HOUR = 60;
|
|
3
|
+
export const DEFAULT_UNPRODUCTIVE_PER_HOUR = 6;
|
|
2
4
|
export const MAX_UNPRODUCTIVE_TURNS = 3;
|
|
3
5
|
const HOUR_MS = 60 * 60_000;
|
|
4
6
|
const OUTPUT_TAIL_LIMIT = 800;
|
|
@@ -11,27 +13,40 @@ function recentTurns(state, now) {
|
|
|
11
13
|
function estimatedTokens(turns) {
|
|
12
14
|
return turns.reduce((sum, turn) => sum + Math.max(0, Math.floor(turn.estimated_tokens)), 0);
|
|
13
15
|
}
|
|
14
|
-
function
|
|
16
|
+
export function busyTurnPause(state, turnCap, now) {
|
|
17
|
+
if (!state)
|
|
18
|
+
return null;
|
|
19
|
+
const turns = recentTurns(state, now);
|
|
20
|
+
if (turns.length < turnCap)
|
|
21
|
+
return null;
|
|
22
|
+
return {
|
|
23
|
+
state: "busy",
|
|
24
|
+
turns_last_hour: turns.length,
|
|
25
|
+
turn_cap: turnCap,
|
|
26
|
+
estimated_tokens: estimatedTokens(turns),
|
|
27
|
+
resumes_at: new Date(turns[0].at + HOUR_MS).toISOString(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function faultFor(state, reason, now, turns, output, tokenTurns = turns) {
|
|
15
31
|
return {
|
|
16
32
|
at: now,
|
|
17
33
|
reason,
|
|
18
34
|
consecutive_unproductive: state.consecutive_unproductive,
|
|
19
35
|
turns_last_hour: turns.length,
|
|
20
|
-
|
|
36
|
+
unproductive_last_hour: turns.filter((turn) => turn.productive === false).length,
|
|
37
|
+
estimated_tokens: estimatedTokens(tokenTurns),
|
|
21
38
|
likely_cause: output.trim() || "no BenignSwarm call reached the server; possible network or sandbox restriction",
|
|
22
39
|
output_tail: output.slice(-OUTPUT_TAIL_LIMIT),
|
|
23
40
|
};
|
|
24
41
|
}
|
|
25
|
-
export function beginGuardedTurn(state, maxTurnsPerHour, now, activitySeqBefore) {
|
|
42
|
+
export function beginGuardedTurn(state, maxTurnsPerHour, now, activitySeqBefore, unproductivePerHour) {
|
|
26
43
|
const current = state ?? emptyTurnGuard();
|
|
27
44
|
const turns = recentTurns(current, now);
|
|
28
|
-
const next = { ...current, turns };
|
|
45
|
+
const next = { ...current, turns, unproductive_per_hour: unproductivePerHour ?? current.unproductive_per_hour ?? DEFAULT_UNPRODUCTIVE_PER_HOUR };
|
|
29
46
|
if (current.fault)
|
|
30
47
|
return { state: current, start: false };
|
|
31
48
|
if (turns.length >= maxTurnsPerHour) {
|
|
32
|
-
|
|
33
|
-
next.fault = faultFor(next, "hourly_limit", now, turns, lastOutput || `the configured ceiling of ${maxTurnsPerHour} turns per hour was reached`);
|
|
34
|
-
return { state: next, start: false };
|
|
49
|
+
return { state: next, start: false, pause_until: turns[0].at + HOUR_MS };
|
|
35
50
|
}
|
|
36
51
|
next.turns = [...turns, { at: now, productive: null, estimated_tokens: 0, ...(activitySeqBefore === undefined ? {} : { activity_seq_before: activitySeqBefore }) }];
|
|
37
52
|
return { state: next, start: true };
|
|
@@ -54,12 +69,18 @@ export function completeGuardedTurn(state, now, productive, output, tokens) {
|
|
|
54
69
|
: turn);
|
|
55
70
|
const currentHour = recentTurns({ ...state, turns: completed }, now);
|
|
56
71
|
const consecutive = productive ? 0 : state.consecutive_unproductive + 1;
|
|
57
|
-
const next = { turns: currentHour, consecutive_unproductive: consecutive, fault: null };
|
|
72
|
+
const next = { turns: currentHour, consecutive_unproductive: consecutive, unproductive_per_hour: state.unproductive_per_hour, fault: null };
|
|
58
73
|
if (!productive && consecutive >= MAX_UNPRODUCTIVE_TURNS) {
|
|
59
|
-
const fault = faultFor(next, "unproductive", now, currentHour, output);
|
|
60
|
-
fault.estimated_tokens = estimatedTokens(completed.slice(-MAX_UNPRODUCTIVE_TURNS));
|
|
74
|
+
const fault = faultFor(next, "unproductive", now, currentHour, output, completed.slice(-MAX_UNPRODUCTIVE_TURNS));
|
|
61
75
|
next.fault = fault;
|
|
62
76
|
}
|
|
77
|
+
else if (!productive) {
|
|
78
|
+
const unproductive = currentHour.filter((turn) => turn.productive === false);
|
|
79
|
+
const limit = state.unproductive_per_hour ?? DEFAULT_UNPRODUCTIVE_PER_HOUR;
|
|
80
|
+
if (unproductive.length >= limit) {
|
|
81
|
+
next.fault = faultFor(next, "unproductive_hourly", now, currentHour, output, unproductive);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
63
84
|
return next;
|
|
64
85
|
}
|
|
65
86
|
/** Resume clears the latched fault and unproductive streak, but keeps hourly starts. */
|
package/dist/usage.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { claudeTranscript, dshUsage } from "./harnesses.js";
|
|
3
|
+
import { antigravityUsage } from "./antigravity.js";
|
|
3
4
|
const zero = () => ({ input: 0, cached_input: 0, output: 0, reasoning: 0, total: 0 });
|
|
4
5
|
function lines(path) {
|
|
5
6
|
return readFileSync(path, "utf8").split("\n").filter(Boolean).flatMap((l) => {
|
|
@@ -90,6 +91,11 @@ export function sessionUsage(session, since, until) {
|
|
|
90
91
|
const base = { harness: "dsh", source: "dsh-step-end-events", scope: "session", since, until, tokens: null };
|
|
91
92
|
return tokens.total ? { ...base, tokens } : { ...base, reason: "no step_end usage events in the DeepSeek Harness turn log during this window" };
|
|
92
93
|
}
|
|
94
|
+
if (session.harness === "antigravity") {
|
|
95
|
+
const tokens = antigravityUsage(session.transcript, since, until);
|
|
96
|
+
const base = { harness: "antigravity", source: "agy-json-turn-records", scope: "session", since, until, tokens };
|
|
97
|
+
return tokens ? base : { ...base, reason: "no Antigravity usage records in the window" };
|
|
98
|
+
}
|
|
93
99
|
return none(session.harness, `${session.harness} keeps no readable token counts locally`);
|
|
94
100
|
}
|
|
95
101
|
/** Usage for a Claude Code session identified by the watcher, when no hook bound it to this agent. */
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.95";
|