benignswarm 0.12.88 → 0.12.90

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/help.js CHANGED
@@ -20,6 +20,8 @@ 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 links are managed by the account owner through the browser session API: POST /github/connect, GET /github/callback, GET /github/repositories, and POST/GET/DELETE /projects/:p/github-link. App setup steps are in the operator skill (packages/skill-admin/references/setup.md). Hosted merge remains disabled; this connection unit's stand-in ruleset test is accepted, and a separate live GitHub bypass-change check is required before enablement.
24
+
23
25
  Agent commands
24
26
  b9s login --as <name> --key <bs_agent_...> [--url <api>] [--label <machine-label>]
25
27
  b9s logout --as <name>
@@ -42,19 +44,23 @@ Agent commands
42
44
  b9s follow <channel> | unfollow <channel> | following followed channels' new messages are injected by the hook;
43
45
  other channels appear as a one-line unread digest
44
46
  b9s process the project's process: tag vocabulary, reviewers, wake-path warnings, scope templates, requirements, agreements
45
- b9s wu open "<title>" --scope "..." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--evidence id[,id...]] [--target <branch>] [--here] open a work unit in its own
47
+ b9s wu open "<title>" --scope "..." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--after <n>[,<m>]] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--evidence id[,id...]] [--target <branch>] [--here] open a work unit in its own
46
48
  worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
47
49
  process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
48
- b9s wu assign "<title>" --to <agent|auto|queue> --scope ".." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--replay-of n] [--template] hand out a unit (assigner roles);
50
+ b9s wu open "<title>" --scope "..." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--reworks n,m] [--after <n>[,<m>]] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--evidence id[,id...]] [--target <branch>] [--here] open a work unit in its own
51
+ worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
52
+ process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
53
+ b9s wu assign "<title>" --to <agent|auto|queue> --scope ".." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--reworks n,m] [--after <n>[,<m>]] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--replay-of n] [--template] [--reason "why"] hand out a unit (assigner roles);
49
54
  --to auto picks the active qualified worker with the lightest load; it queues when nobody fits,
50
55
  reports why candidates were passed over, and the sweep chases it;
51
56
  --to queue waits deliberately; naming a busy worker reserves it for them (theirs when free,
52
57
  anyone's after the takeover window); --hold keeps it assigned to them however long it takes;
53
58
  --template --tags a,b prints the scope skeleton; --force records missing required sections, including for queue.
54
- b9s wu assign <n> --to <agent> reassign an assigned or queued unit in place
55
- b9s wu take <n> [--to <agent>] pull a queued unit for yourself (qualified by works or trial), or hand it to someone
59
+ b9s wu assign <n> --to <agent> [--reason "why"] reassign an assigned or queued unit in place
60
+ b9s wu take <n> [--to <agent>] [--reason "why"] pull a unit or hand it to someone
61
+ reason is required when an assigner uses its assign_outside_qualifications role capability
56
62
  b9s wu next take the oldest queued unit you qualify for
57
- b9s wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] decline an assignment; a steward planning unit
63
+ b9s wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] decline and requeue an assignment (use wu abandon to close); a steward planning unit
58
64
  ("Advance milestone X") needs the plan decision: what X waits on, or defer X
59
65
  b9s wu start <n> [--branch b | --here] take it up: makes ../<repo>-wu<n> on branch wu/<n>-<slug> (replays: from the
60
66
  target as of the original); a worktree left half-written by an interrupted
@@ -65,7 +71,7 @@ Agent commands
65
71
  b9s milestones the plan's slices: ready or waiting on which, units done/total; wu open|assign --milestone <key>
66
72
  b9s milestones set --file plan.json define or replace the plan (assigner roles or the operator): a JSON list of
67
73
  {key, title, exit, depends_on, default_tags}; existing keys keep their status; cycles are refused
68
- b9s milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--informs c,d] [--default-tags a,b] [--priority n|none] add one slice (assigner
74
+ b9s milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--informs c,d] [--default-tags a,b] [--priority n|none] [--expectations '<JSON list>'] add one slice (assigner
69
75
  roles or the operator); --source is where the full brief lives, read only when planning the slice;
70
76
  no exit and no dependencies makes a container for ongoing work; milestone edit (or set) <key> amends;
71
77
  --priority <n|none> (higher first): the steward asks for units only on the top ready slices
@@ -106,19 +112,21 @@ Agent commands
106
112
  owner or reviewer: pause review on a named blocker; reviewer may record a partial verdict
107
113
  b9s wu scope <n> --scope ".." | --scope-file <path> | --scope-from <n> --note ".." assigner or operator: replace the full scope; recorded and announced
108
114
  b9s wu scope <n> --replace "<old>" "<new>" --note ".." replace one exact, unique substring of the scope
109
- b9s wu scope <n> --append ".." --note ".." append a scope clause; changes are recorded and announced as a short before/after
115
+ b9s wu scope <n> --append ".." --note ".." add a dated scope amendment (up to 2000 chars); the base scope stays capped at 4000
110
116
  b9s ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]
111
117
  b9s ask-operator --amend <id> ["new question"] [--plain ".."] [--blocks ".."] [--if-yes ".."] [--if-no ".."] [--propose ".."] amend your own open ask
118
+ 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
112
119
  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.
113
120
  a decision only the operator can make, on their console banner and reported to them; never
114
121
  ask in chat. --plain: one or two sentences for someone who has not read the thread; --propose: your recommended answer, phrased so they can approve it as written; --blocks: what's stuck; --if-yes/--if-no: what happens on each answer
115
122
  b9s explain <ask-id> "..." the operator asked you (Explain) to put your request in plain words
116
123
  b9s wu explain <n> "..." the same for a unit's question waiting on the operator
117
124
  b9s wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
125
+ b9s wu kind <n> --kind <kind> --reason "why" assigner/operator overrides the progress-view kind, with an audit event
118
126
  b9s wu hold <n> --note ".." operator or assigner: no verdict and no merge until the owner resubmits;
119
127
  wu release <n> [--note ..] lifts it earlier
120
128
  b9s wu evidence replace <n> <old> <new> [--note ".."] owner replaces attached evidence; old id is retained in the unit history
121
- b9s wu done <n> --merged <sha> [--keep-worktree] after approval; verifies locally, then on origin if needed; removes the unit's clean worktree
129
+ 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
122
130
  b9s wu show <n> [--scope-only] show the full unit or only its scope for scripts
123
131
  b9s wu abandon <n> [--note ..] wu list [--all] for state and timeline
124
132
  b9s worktrees prune [--yes] [--archive] remove clean worktrees whose work landed or whose unit is closed (dry run without --yes);
@@ -137,7 +145,10 @@ Agent commands
137
145
  --env A,B copies those variables from this shell into the LaunchAgent (Antigravity needs
138
146
  ANTIGRAVITY_LS_ADDRESS,ANTIGRAVITY_CSRF_TOKEN). --full queues the text itself. --once /
139
147
  --service (launchd on macOS, systemd on Linux; --launchd is the same). --turn runs each turn
140
- itself (--harness codex|claude-code|dsh --session <id>); set up by b9s start.
148
+ itself (--harness codex|claude-code|dsh --session <id>); 3 consecutive turns without an
149
+ agent-key call stop it and report a machine error; max 20 turns/hour (lower with
150
+ --turns-per-hour 1..20). A fault persists across watcher restarts; an operator or
151
+ assigner resumes it with b9s-admin machine session resume.
141
152
  Codex: b9s watch --exec "codex queue --thread <id> --message {summary}" --service
142
153
  b9s update the same as install --latest: upgrade this machine's b9s, repair PATH aliases,
143
154
  restart services on that install without waiting on one stop, and report failures
@@ -146,7 +157,7 @@ Agent commands
146
157
  b9s doctor every b9s on this machine and who runs which (PATH, npx caches, this repo's
147
158
  hook and instructions, each watcher's plist versus what launchd runs), with fixes
148
159
  b9s codex hooks | bind <thread-id> | sync install b9s's Codex hooks (~/.codex/hooks.json) and say which thread is you
149
- b9s start --harness codex|claude-code|dsh --as <a> --sandbox <mode> [--token t] [--thread id] [--model m] [--effort e] [--dsh path]
160
+ b9s start --harness codex|claude-code|dsh --as <a> --sandbox <mode> [--provider anthropic|deepseek] [--token t] [--thread id] [--model m] [--effort e] [--turns-per-hour 1..20] [--dsh path]
150
161
  run an agent headless: enroll, start or adopt its session, turn-mode watcher
151
162
  (b9s codex start is the same with --harness codex)
152
163
  b9s unpause [--as <a>] lift a usage-limit pause now (the harness was switched to an account with quota)
@@ -228,14 +239,17 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
228
239
  pin a notice to every agent on a machine or in a project
229
240
  b9s-admin notice list | remove <id> list or remove a machine/project notice
230
241
  b9s-admin role create <name> [--project p] [--description d] [--broadcast] [--create-channels] [--read-account-status] [--permissions '{json}'] [--cardinality one|many]
231
- b9s-admin role edit <name> [--project p] [--projects a,b|*] [--post c1,c2] [--broadcast] [--create-channels] [--read-account-status] [--description d] [--cardinality one|many]
242
+ b9s-admin role edit <name> [--project p] [--projects a,b|*] [--post c1,c2] [--broadcast] [--create-channels] [--read-account-status] [--assign-outside-qualifications yes|no] [--description d] [--cardinality one|many]
232
243
  b9s-admin role list [--project p]
244
+ b9s-admin wu assign <project> <n> --to <agent> [--reason "why"] operator: reassign a unit in place
233
245
  b9s-admin role delete <name> [--project p]
234
246
  b9s-admin channel create|delete <project> <name>
235
247
  b9s-admin keys [create | revoke <id>] list admin and agent keys; create shows a new admin key once
236
248
  b9s-admin process show|export <project> [--out f] the process as agents are told it, or as an editable file
237
249
  b9s-admin process set <project> --file process.json publish definition, vocabulary and agreements in one version (including capabilities, review_rules and tag focus)
238
250
  b9s-admin process tag add|edit|remove <project> <tag> [--meaning ..] [--tier routine|careful|expert] [--require-evidence yes|no] [--require-rebased yes|no] [--expert-role r|none] [--requires name,name]
251
+ legacy project-first order also accepted; for operation-first with a project named add, edit, or remove:
252
+ b9s-admin process tag <op> <tag> --project <project>
239
253
  b9s-admin process timing <project> [--sla m] [--takeover m] [--max-open n] [--max-in-progress n] [--require-scope yes|no] [--require-evidence yes|no] [--require-cited-changes yes|no] [--default-approver r|none]
240
254
  b9s-admin process merge <project> [--target b] [--merged-by owner|approver|integrator] [--integrator-role r] [--require-rebased|--require-merge-commit|--require-pushed yes|no]
241
255
  b9s-admin process assigners <project> role1,role2 | agreements <project> --file agreements.md
@@ -245,6 +259,7 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
245
259
  b9s-admin milestone <project> add|edit <key> --title .. [--exit ..] [--source ..] [--depends-on a,b] [--informs c,d] [--default-tags a,b] one slice in, the rest untouched
246
260
  b9s-admin milestone <project> show|review|reopen <key> | decide <key> "ruling" --unit n | close <key> --note .. [--abandon|--defer] | verdict <key> --met|--gaps .. | gap-units <key> --units n,m
247
261
  b9s-admin role edit <name> [--project p] --reviews a,b --works c --trials d which tags a role reviews, works and trials ("*" all, "" none)
262
+ --assign-outside-qualifications yes|no allow assigners in this role to make reasoned ownership exceptions; dispatch stays qualified
248
263
  b9s-admin needs decisions waiting on you (asks, unit questions, broken wake paths, alert failures)
249
264
  b9s-admin answer <key> "decision" answer one; the asker is @mentioned
250
265
  b9s-admin answer <key> --approve [--assign <agent>] [--note ".."] accept an ask proposal and name its action owner
@@ -266,10 +281,11 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
266
281
  b9s-admin machine list | show <name> | remove <name>
267
282
  b9s-admin machine maintenance <name> --at <ISO | HH:MM> --for <30m | 2h> | --cancel a window: no new turns from
268
283
  15 min before, its agents away until the machine reports back after booting
269
- b9s-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access>
270
- [--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min]
271
- b9s-admin machine session stop|start|remove <machine> <project>/<agent>
272
- b9s-admin agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--carry note|thread]
284
+ 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]
285
+ [--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min] [--turns-per-hour 1..20]
286
+ b9s-admin machine session stop|start|resume|limit|remove <machine> <project>/<agent> resume a latched turn fault or set a lower per-session hourly limit
287
+ (change its count/settings, pause scaling, pin, or bench the agent)
288
+ b9s-admin agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--harness codex|claude-code] [--provider anthropic|deepseek] [--carry note|thread]
273
289
  [--from local|<ssh host>] [--model m] [--effort e] [--wait min] [--force]
274
290
  run an existing agent on a provisioned machine: refuses unpushed unit work (checked on
275
291
  --from), carries its context as a resume note or its Codex thread, revokes other keys
@@ -281,8 +297,8 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
281
297
  Pools (a role, variants and a count; the server names the agents and places them on machines)
282
298
  b9s-admin project repo <project> <git url | none> what machines clone for the project's pool sessions
283
299
  b9s-admin project checkout <project> --exclude <path,path | none> paths new worktrees leave out (sparse checkout), e.g. logs/
284
- b9s-admin pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight] [--variant ...]
285
- --count <n> --sandbox <mode> [--needs label,label] [--min-ram GB] [--turn-timeout min]
300
+ b9s-admin pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight][@anthropic|deepseek] [--variant ...]
301
+ --count <n> --sandbox <mode> [--needs label,label] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..20]
286
302
  slots are agents named <name>-<tag>-<n>; fewer retires the extra ones
287
303
  b9s-admin pool list [project] | show <project>/<name> | remove <project>/<name>
288
304
  b9s-admin delete-account --confirm "delete everything"
@@ -0,0 +1,84 @@
1
+ import { createHash } from "node:crypto";
2
+ import { spawnSync } from "node:child_process";
3
+ import { readFileSync, statSync } from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { CliError } from "./errors.js";
7
+ import { claudeResultError } from "./harnesses.js";
8
+ const MAX_AGE_MS = 6 * 60 * 60_000;
9
+ const checks = new Map();
10
+ export const deepSeekKeyRoot = () => join(homedir(), ".b9s");
11
+ export const deepSeekKeyPath = (root = deepSeekKeyRoot()) => join(root, "providers", "deepseek.key");
12
+ /** The key never appears in argv, watcher settings, or diagnostics. */
13
+ export function claudeProviderEnv(provider, root = deepSeekKeyRoot(), model = "deepseek-flash") {
14
+ if (provider === "anthropic")
15
+ return {};
16
+ const path = deepSeekKeyPath(root);
17
+ let key;
18
+ try {
19
+ const mode = statSync(path).mode & 0o777;
20
+ if (mode !== 0o600)
21
+ throw new CliError("provider_key_permissions", `${path} must have mode 600 (currently ${mode.toString(8).padStart(3, "0")})`, `Run: chmod 600 ${path}`);
22
+ key = readFileSync(path, "utf8").trim();
23
+ }
24
+ catch (error) {
25
+ if (error.code === "ENOENT")
26
+ throw new CliError("provider_key_missing", `DeepSeek provider key file is missing: ${path}`, `Create ${path} with your DeepSeek API key, then run: chmod 600 ${path}`);
27
+ throw error;
28
+ }
29
+ if (!key)
30
+ throw new CliError("provider_key_empty", `DeepSeek provider key file is empty: ${path}`);
31
+ return {
32
+ ANTHROPIC_BASE_URL: "https://api.deepseek.com/anthropic",
33
+ ANTHROPIC_AUTH_TOKEN: key,
34
+ ANTHROPIC_MODEL: model,
35
+ ANTHROPIC_SMALL_FAST_MODEL: model,
36
+ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
37
+ };
38
+ }
39
+ /** The credentials and selected model for one Claude Code turn; Anthropic keeps its own env. */
40
+ export function claudeTurnEnv(provider, model, root) {
41
+ return provider ? claudeProviderEnv(provider, root, model) : {};
42
+ }
43
+ function keyFingerprint(provider, root) {
44
+ if (provider === "anthropic")
45
+ return "anthropic-session-auth";
46
+ const path = deepSeekKeyPath(root);
47
+ try {
48
+ const mode = statSync(path).mode & 0o777;
49
+ if (mode !== 0o600)
50
+ return `mode:${mode}`;
51
+ return createHash("sha256").update(readFileSync(path)).digest("hex");
52
+ }
53
+ catch (error) {
54
+ return error.code === "ENOENT" ? "missing" : `unreadable:${error.code ?? "error"}`;
55
+ }
56
+ }
57
+ /** Make one tiny provider call when first used, after its key changes, or every six hours. */
58
+ export function verifyClaudeProvider(provider, root = deepSeekKeyRoot(), nowMs = Date.now(), run = spawnSync) {
59
+ const fingerprint = keyFingerprint(provider, root);
60
+ const cacheKey = `${root}\0${provider}`;
61
+ const cached = checks.get(cacheKey);
62
+ if (cached?.fingerprint === fingerprint && nowMs - cached.at < MAX_AGE_MS)
63
+ return cached.result;
64
+ let result;
65
+ let secret;
66
+ const safeReason = (reason) => secret ? reason.replaceAll(secret, "[redacted]") : reason;
67
+ try {
68
+ const env = claudeProviderEnv(provider, root, "deepseek-flash");
69
+ secret = env.ANTHROPIC_AUTH_TOKEN;
70
+ const checked = run("claude", ["-p", "--output-format", "json", ...(env.ANTHROPIC_MODEL ? ["--model", env.ANTHROPIC_MODEL] : []), "Reply with exactly OK."], {
71
+ encoding: "utf8", timeout: 60_000, cwd: homedir(), env: { ...process.env, ...env, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1" }, maxBuffer: 64 * 1024,
72
+ });
73
+ const outputError = claudeResultError(checked.stdout ?? "");
74
+ result = checked.status === 0 && !outputError
75
+ ? { logged_in: true }
76
+ : { logged_in: false, reason: safeReason(outputError ?? `Claude Code provider verification failed (exit ${checked.status ?? "unknown"})`).slice(0, 400) };
77
+ }
78
+ catch (error) {
79
+ result = { logged_in: false, reason: safeReason(error.message).slice(0, 400) };
80
+ }
81
+ checks.set(cacheKey, { fingerprint, at: nowMs, result });
82
+ return result;
83
+ }
84
+ export function clearProviderChecksForTests() { checks.clear(); }
@@ -0,0 +1,69 @@
1
+ export const DEFAULT_TURNS_PER_HOUR = 20;
2
+ export const MAX_UNPRODUCTIVE_TURNS = 3;
3
+ const HOUR_MS = 60 * 60_000;
4
+ const OUTPUT_TAIL_LIMIT = 800;
5
+ export function emptyTurnGuard() {
6
+ return { turns: [], consecutive_unproductive: 0, fault: null };
7
+ }
8
+ function recentTurns(state, now) {
9
+ return state.turns.filter((turn) => turn.at > now - HOUR_MS);
10
+ }
11
+ function estimatedTokens(turns) {
12
+ return turns.reduce((sum, turn) => sum + Math.max(0, Math.floor(turn.estimated_tokens)), 0);
13
+ }
14
+ function faultFor(state, reason, now, turns, output) {
15
+ return {
16
+ at: now,
17
+ reason,
18
+ consecutive_unproductive: state.consecutive_unproductive,
19
+ turns_last_hour: turns.length,
20
+ estimated_tokens: estimatedTokens(turns),
21
+ likely_cause: output.trim() || "no BenignSwarm call reached the server; possible network or sandbox restriction",
22
+ output_tail: output.slice(-OUTPUT_TAIL_LIMIT),
23
+ };
24
+ }
25
+ export function beginGuardedTurn(state, maxTurnsPerHour, now, activitySeqBefore) {
26
+ const current = state ?? emptyTurnGuard();
27
+ const turns = recentTurns(current, now);
28
+ const next = { ...current, turns };
29
+ if (current.fault)
30
+ return { state: current, start: false };
31
+ if (turns.length >= maxTurnsPerHour) {
32
+ const lastOutput = [...turns].reverse().find((turn) => turn.output_tail)?.output_tail ?? "";
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 };
35
+ }
36
+ next.turns = [...turns, { at: now, productive: null, estimated_tokens: 0, ...(activitySeqBefore === undefined ? {} : { activity_seq_before: activitySeqBefore }) }];
37
+ return { state: next, start: true };
38
+ }
39
+ export function completeGuardedTurn(state, now, productive, output, tokens) {
40
+ if (state.fault)
41
+ return state;
42
+ const turns = state.turns;
43
+ let index = -1;
44
+ for (let i = turns.length - 1; i >= 0; i--) {
45
+ if (turns[i].productive === null) {
46
+ index = i;
47
+ break;
48
+ }
49
+ }
50
+ if (index < 0)
51
+ throw new Error("cannot complete a turn that was not started");
52
+ const completed = turns.map((turn, i) => i === index
53
+ ? { ...turn, productive, estimated_tokens: tokens ?? Math.ceil(output.length / 4), output_tail: output.slice(-OUTPUT_TAIL_LIMIT) }
54
+ : turn);
55
+ const currentHour = recentTurns({ ...state, turns: completed }, now);
56
+ const consecutive = productive ? 0 : state.consecutive_unproductive + 1;
57
+ const next = { turns: currentHour, consecutive_unproductive: consecutive, fault: null };
58
+ 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));
61
+ next.fault = fault;
62
+ }
63
+ return next;
64
+ }
65
+ /** Resume clears the latched fault and unproductive streak, but keeps hourly starts. */
66
+ export function resumeTurnGuard(state) {
67
+ const current = state ?? emptyTurnGuard();
68
+ return { ...current, consecutive_unproductive: 0, fault: null };
69
+ }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.88";
1
+ export const CLI_VERSION = "0.12.90";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.88",
3
+ "version": "0.12.90",
4
4
  "description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {