@indigoai-us/hq-cli 5.345.270 → 5.345.273

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/contracts/host-canary-release.json +7 -7
  3. package/dist/command-catalog.generated.d.ts +2 -2
  4. package/dist/command-catalog.generated.js +2 -2
  5. package/dist/commands/core-checkpoint-stop-gate-native.js +2 -13
  6. package/dist/commands/core-session-journal-native.js +20 -4
  7. package/dist/commands/signals-run.d.ts +4 -1
  8. package/dist/commands/signals-run.js +6 -8
  9. package/dist/commands/sync-core.js +2 -1
  10. package/dist/lib/daemon/daemon-restart.d.ts +70 -0
  11. package/dist/lib/daemon/daemon-restart.js +114 -0
  12. package/dist/lib/daemon/hook-requests-work-mesh-shims.d.ts +41 -0
  13. package/dist/lib/daemon/hook-requests-work-mesh-shims.js +237 -0
  14. package/dist/lib/daemon/hook-requests.d.ts +4 -1
  15. package/dist/lib/daemon/hook-requests.js +23 -1
  16. package/dist/lib/daemon/hq-child-bootstrap.mjs +1 -0
  17. package/dist/lib/daemon/installed-cli-restart.js +14 -4
  18. package/dist/lib/daemon/merge-sections.d.ts +24 -1
  19. package/dist/lib/daemon/merge-sections.js +59 -11
  20. package/dist/lib/daemon/run.d.ts +1 -1
  21. package/dist/lib/daemon/run.js +67 -53
  22. package/dist/lib/daemon/supervisor.js +0 -2
  23. package/dist/lib/hook-engine/coverage.d.ts +21 -0
  24. package/dist/lib/hook-engine/coverage.js +98 -5
  25. package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
  26. package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
  27. package/dist/lib/hot-channels/signals-pass.d.ts +10 -2
  28. package/dist/lib/hot-channels/signals-pass.js +13 -3
  29. package/dist/lib/signals/engine.d.ts +0 -2
  30. package/dist/lib/signals/engine.js +12 -7
  31. package/dist/lib/signals/reply.js +35 -82
  32. package/dist/lib/signals/run-lock.d.ts +8 -0
  33. package/dist/lib/signals/run-lock.js +42 -7
  34. package/dist/lib/signals/run-record.js +2 -1
  35. package/dist/lib/signals/settings.d.ts +9 -4
  36. package/dist/lib/signals/settings.js +7 -5
  37. package/dist/lib/signals/steps/extract.d.ts +37 -10
  38. package/dist/lib/signals/steps/extract.js +88 -111
  39. package/dist/lib/signals/steps/types.d.ts +3 -2
  40. package/dist/lib/sync-core/reconcile.d.ts +7 -1
  41. package/dist/lib/sync-core/reconcile.js +105 -18
  42. package/dist/lib/sync-core/release.d.ts +52 -2
  43. package/dist/lib/sync-core/release.js +172 -11
  44. package/dist/lib/sync-core/rollout-state.d.ts +11 -0
  45. package/dist/lib/sync-core/rollout-state.js +16 -0
  46. package/dist/utils/client-health-contract.d.ts +32 -0
  47. package/dist/utils/client-health-contract.js +35 -0
  48. package/dist/utils/client-health.d.ts +43 -0
  49. package/dist/utils/client-health.js +106 -3
  50. package/dist/utils/login-browser.d.ts +1 -0
  51. package/dist/utils/login-browser.js +31 -6
  52. package/dist/utils/spawn-detached-hidden.d.ts +66 -0
  53. package/dist/utils/spawn-detached-hidden.js +222 -0
  54. package/package.json +7 -7
@@ -169,33 +169,17 @@ export function runCountItems(record, summary, opts) {
169
169
  function spendUsd(record) {
170
170
  return record.steps.reduce((n, s) => n + (s.estimatedSpendUsd ?? 0), 0);
171
171
  }
172
- function spendBlock(record) {
173
- if (!(record.maxBudgetUsd > 0))
174
- return null;
175
- const spend = spendUsd(record);
176
- const value = Math.max(0, Math.min(100, Math.round((spend / record.maxBudgetUsd) * 100)));
177
- // Some coding tools report no cost; the step then counts a flat amount per source. Say it is an estimate.
178
- const estimated = record.steps.some((s) => s.detail?.spendEstimated === true);
179
- return {
180
- kind: "progress",
181
- value,
182
- label: `${estimated ? "Estimated spend" : "Spend"} $${spend.toFixed(2)} of the $${record.maxBudgetUsd.toFixed(2)} cap`,
183
- tone: "neutral",
184
- };
185
- }
186
172
  /**
187
- * A run that stopped at the spend cap on estimated spend, in plain words:
188
- * how many sources were processed, how many are left, and what controls it.
189
- * Null for any other outcome.
173
+ * The run's estimated spend as one key/value row, or null when nothing was
174
+ * spent. It is information only: there is no cap to compare it with.
190
175
  */
191
- function estimatedBudgetStop(record) {
192
- const step = record.steps.find((s) => s.error === "budget-exceeded" && s.detail?.spendEstimated === true && typeof s.detail.sourcesProcessed === "number");
193
- const d = step?.detail;
194
- if (!d)
176
+ function spendItem(record) {
177
+ const spend = spendUsd(record);
178
+ if (!(spend > 0))
195
179
  return null;
196
- const each = typeof d.unpricedSourceEstimateUsd === "number" ? `$${d.unpricedSourceEstimateUsd.toFixed(2)}` : "a set amount";
197
- const left = typeof d.sourcesLeft === "number" && d.sourcesLeft > 0 ? `, with at least ${plural(d.sourcesLeft, "source")} left for the next run` : "";
198
- return `Signals stopped at the $${record.maxBudgetUsd.toFixed(2)} spend cap after ${plural(d.sourcesProcessed, "source")}${left}. The spend is an estimate: this coding tool does not report its cost, so each source counts as ${each}. To process more in one run, raise the cap with --max-budget-usd.`;
180
+ // Some coding tools report no cost; the step then counts a flat amount per source. Say it is an estimate.
181
+ const estimated = record.steps.some((s) => s.detail?.spendEstimated === true);
182
+ return { key: estimated ? "Estimated spend" : "Spend", value: `$${spend.toFixed(2)}` };
199
183
  }
200
184
  /**
201
185
  * The non-desktop brief decision. It says the brief builds next only when a
@@ -231,48 +215,22 @@ function listInWords(parts) {
231
215
  function capitalize(text) {
232
216
  return text ? text[0].toUpperCase() + text.slice(1) : text;
233
217
  }
234
- /** The extract step that stopped because the run reached its spend cap, if any. */
235
- function budgetStopStep(record) {
218
+ /**
219
+ * Run records written while runs had a spend cap can hold an extract step that
220
+ * stopped with error "budget-exceeded". No run stops that way now. The reply
221
+ * for such a record says only that the run stopped early.
222
+ */
223
+ function legacyEarlyStopStep(record) {
236
224
  return record.steps.find((s) => s.name === "extract" && (s.status === "partial" || s.status === "failed") && s.error === "budget-exceeded");
237
225
  }
238
- /** "$2.00", or null when the record carries no usable cap. */
239
- function capInWords(record) {
240
- return Number.isFinite(record.maxBudgetUsd) && record.maxBudgetUsd >= 0 ? `$${record.maxBudgetUsd.toFixed(2)}` : null;
241
- }
226
+ const LEGACY_EARLY_STOP_TITLE = "Finding signals stopped early.";
227
+ const LEGACY_EARLY_STOP_MAIN = "Finding signals stopped before it read every source. The sources it did not reach wait for the next run.";
228
+ const LEGACY_EARLY_STOP_NOTE = "Finding signals also stopped early, so some sources wait for the next run.";
242
229
  /** The run's first problem, picked the way finalizeRecord picks the step behind failureReason. */
243
230
  function firstProblem(record) {
244
231
  const problems = record.steps.filter((s) => s.status === "failed" || s.status === "partial");
245
232
  return problems.find((s) => s.status === "failed") ?? problems[0];
246
233
  }
247
- /**
248
- * The per-run way to raise the cap. Only the flag is named: the default lives
249
- * in core/settings/signals.yaml, which is release-owned and replaced on
250
- * update, so a member edit there would be lost. The flag also sets the cap of
251
- * an --incremental run.
252
- */
253
- function raiseCapLine(record) {
254
- return `To raise the cap for one run, use hq signals run --company ${record.company} --max-budget-usd <amount>.`;
255
- }
256
- /**
257
- * A budget stop in words: the source it stopped at (detail.budgetStoppedAt),
258
- * that the rest waits for the next run, and how to raise the cap for a run.
259
- */
260
- function budgetGuidance(record, stopped) {
261
- // Estimated spend has its own sentence (counts and the per-source amount).
262
- // A metered stop still names the source it stopped at.
263
- const estimated = estimatedBudgetStop(record);
264
- if (estimated)
265
- return estimated;
266
- const raw = stopped.detail?.budgetStoppedAt;
267
- const at = typeof raw === "string" && raw.trim() ? raw.trim() : null;
268
- const cap = capInWords(record);
269
- const reached = cap ? `its spend cap of ${cap}` : "its spend cap";
270
- return [
271
- at ? `Finding signals stopped at ${at} because the run reached ${reached}.` : `Finding signals stopped because the run reached ${reached}.`,
272
- at ? "That source and any after it wait for the next run." : "The sources it did not reach wait for the next run.",
273
- raiseCapLine(record),
274
- ].join(" ");
275
- }
276
234
  /**
277
235
  * The extract step's signed-out kind is the coding tool's login, never HQ's:
278
236
  * the Fleet bot's own login when extract ran on it (detail.login "fleet"),
@@ -296,17 +254,16 @@ function codingToolSignedOut(step) {
296
254
  * (reconnect, signed-out) is on the failing step; the record carries only the
297
255
  * coarse v2 kind (auth, config, transient).
298
256
  *
299
- * `main` answers the run's first problem. A budget stop that is not the first
300
- * problem is added as a short `note` after it, so neither problem goes unsaid.
257
+ * `main` answers the run's first problem. An early stop on an older record
258
+ * (legacyEarlyStopStep) that is not the first problem is added as a short
259
+ * `note` after it, so neither problem goes unsaid.
301
260
  */
302
261
  function failureGuidance(record, failed, company) {
303
- const stopped = budgetStopStep(record);
304
- const budgetFirst = stopped !== undefined && firstProblem(record) === stopped;
305
- const cap = capInWords(record);
306
- const shortNote = `Finding signals also reached ${cap ? `its ${cap} spend cap` : "its spend cap"}, so some sources wait for the next run. ${raiseCapLine(record)}`;
262
+ const stopped = legacyEarlyStopStep(record);
263
+ const stoppedFirst = stopped !== undefined && firstProblem(record) === stopped;
307
264
  const kindStep = failed?.errorKind ? failed : record.steps.find((s) => s.status === "failed" || s.status === "partial");
308
265
  const stepKind = kindStep?.errorKind;
309
- // Sign-in and setup problems come first; a budget stop is then added after them.
266
+ // Sign-in and setup problems come first; an older record's early stop is then added after them.
310
267
  const urgent = stepKind === "reconnect" ? `A connection for ${company} needs reconnecting.`
311
268
  : stepKind === "signed-out" && kindStep?.name === "extract" ? codingToolSignedOut(kindStep)
312
269
  : stepKind === "signed-out" ? "You are signed out of HQ. Sign in again with hq login."
@@ -314,13 +271,13 @@ function failureGuidance(record, failed, company) {
314
271
  : record.errorKind === "config" ? `Something in the signals setup for ${company} needs fixing first.`
315
272
  : null;
316
273
  if (urgent)
317
- return { main: urgent, note: stopped ? (budgetFirst ? budgetGuidance(record, stopped) : shortNote) : null };
318
- if (budgetFirst)
319
- return { main: budgetGuidance(record, stopped), note: null };
274
+ return { main: urgent, note: stopped ? (stoppedFirst ? LEGACY_EARLY_STOP_MAIN : LEGACY_EARLY_STOP_NOTE) : null };
275
+ if (stoppedFirst)
276
+ return { main: LEGACY_EARLY_STOP_MAIN, note: null };
320
277
  const main = record.errorKind === "transient" ? "This looks temporary."
321
278
  : failed ? `${STEP_DOING[failed.name]} for ${company} failed.`
322
279
  : `Signals for ${company} failed.`;
323
- return { main, note: stopped ? shortNote : null };
280
+ return { main, note: stopped ? LEGACY_EARLY_STOP_NOTE : null };
324
281
  }
325
282
  /** First sentence of an error, trimmed to one plain line. */
326
283
  function oneSentence(text) {
@@ -432,12 +389,9 @@ export function formatRunReply(record, summary, opts) {
432
389
  const stoppedProse = `${job} stopped at ${finished}.`;
433
390
  return build(opts.desktopLinks ? `${stoppedProse}\n\n${briefLinkLine(opts)}` : stoppedProse, blocks, "failed");
434
391
  }
435
- const counts = runCountItems(record, summary, opts);
436
- const spend = spendBlock(record);
437
- const tail = [
438
- ...(counts.length ? [{ kind: "keyValue", items: counts }] : []),
439
- ...(spend ? [spend] : []),
440
- ];
392
+ const spend = spendItem(record);
393
+ const counts = [...runCountItems(record, summary, opts), ...(spend ? [spend] : [])];
394
+ const tail = counts.length ? [{ kind: "keyValue", items: counts }] : [];
441
395
  const due = timeInWords(opts.scheduledFor, tz);
442
396
  const catchUpBadge = { kind: "badge", label: "Catch-up", tone: "warning", icon: "clock" };
443
397
  const partialReason = record.partialReason ?? record.partial ?? null;
@@ -450,12 +404,11 @@ export function formatRunReply(record, summary, opts) {
450
404
  ], "late-start");
451
405
  }
452
406
  if (record.status === "partial") {
453
- // The budget title only when the budget stop is the run's first problem
454
- // (the step finalizeRecord builds failureReason from).
407
+ // An older record's early stop gets its own title only when it is the
408
+ // run's first problem (the step finalizeRecord builds failureReason from).
455
409
  const first = firstProblem(record);
456
- const budgetCap = first && first === budgetStopStep(record) ? capInWords(record) : null;
457
- const title = budgetCap
458
- ? `Finding signals reached the ${budgetCap} spend cap.`
410
+ const title = first && first === legacyEarlyStopStep(record)
411
+ ? LEGACY_EARLY_STOP_TITLE
459
412
  : record.failureReason
460
413
  ? oneSentence(record.failureReason)
461
414
  : partialReason
@@ -464,7 +417,7 @@ export function formatRunReply(record, summary, opts) {
464
417
  const guidance = failureGuidance(record, failedStep, company);
465
418
  // A signals pass that was blocked or failed: the owner's plain notice and
466
419
  // its one fix lead, never the pass's error code. The run's own guidance
467
- // (a reconnect step, the spend cap) stays after it. A run reply is always
420
+ // (a reconnect step) stays after it. A run reply is always
468
421
  // a bot's, so a signed-out pass names the bot's own sign-in, never a
469
422
  // Claude Code sign-in.
470
423
  const notice = signalsNoticeProblem(record);
@@ -3,7 +3,13 @@ export interface LockHolder {
3
3
  pid: number;
4
4
  startedAt: string;
5
5
  trigger: string;
6
+ /** When the holder last refreshed the lock. Absent until the first refresh. */
7
+ heartbeatAt?: string;
6
8
  }
9
+ /** The lock's last sign of life in epoch ms: its heartbeat, else its start. NaN when neither parses. */
10
+ export declare function lockLastAliveMs(holder: Pick<LockHolder, "startedAt" | "heartbeatAt">): number;
11
+ /** True when the lock's last sign of life is more than LOCK_STALE_MS before `nowMs`. */
12
+ export declare function isLockExpired(holder: Pick<LockHolder, "startedAt" | "heartbeatAt">, nowMs: number): boolean;
7
13
  export interface LockTakeover extends LockHolder {
8
14
  takenOverAt: string;
9
15
  reason: "pid-dead" | "expired" | "unreadable";
@@ -11,6 +17,8 @@ export interface LockTakeover extends LockHolder {
11
17
  export type AcquireResult = {
12
18
  ok: true;
13
19
  takeover: LockTakeover | null;
20
+ /** Refresh the lock's heartbeatAt. A no-op when the lock no longer names this holder. Never throws. */
21
+ heartbeat: () => void;
14
22
  release: () => void;
15
23
  } | {
16
24
  ok: false;
@@ -3,10 +3,23 @@
3
3
  * (run record contract v2).
4
4
  *
5
5
  * Lock file: workspace/signals/runs/{date}/{company}.lock, created with
6
- * O_EXCL ("wx") and holding JSON { pid, startedAt, trigger }. A lock is stale
7
- * when its pid is not alive or its startedAt is older than 3 hours; a stale
8
- * lock is removed and taken over, and the caller logs the takeover in the
9
- * run record.
6
+ * O_EXCL ("wx") and holding JSON { pid, startedAt, trigger, heartbeatAt }. A
7
+ * lock is stale when its pid is not alive, or when its last sign of life is
8
+ * older than 3 hours; a stale lock is removed and taken over, and the caller
9
+ * logs the takeover in the run record.
10
+ *
11
+ * The last sign of life is heartbeatAt, or startedAt for a lock that has no
12
+ * heartbeat yet (and for a lock written by an older hq-cli). The holder
13
+ * refreshes heartbeatAt only when it makes progress (`heartbeat` on the
14
+ * acquire result): the engine when a step starts or finishes, and the extract
15
+ * step when a source starts or finishes. There is no timer, so a refresh is
16
+ * evidence of work, not of a live process. A run that keeps making progress
17
+ * keeps its lock however long it takes. A run that makes no progress for 3
18
+ * hours loses it, even when its process is alive (an awaited step that never
19
+ * settles, for example).
20
+ *
21
+ * 3 hours is far above the longest gap between two refreshes in the extract
22
+ * step, MAX_SOURCE_GAP_MS in steps/extract.ts (about 26 minutes).
10
23
  */
11
24
  import * as fs from "node:fs";
12
25
  import * as path from "node:path";
@@ -14,6 +27,15 @@ import { assertAllowedPath } from "./write-guard.js";
14
27
  export const LOCK_STALE_MS = 3 * 60 * 60 * 1000;
15
28
  /** An unreadable lock younger than this is treated as being written right now. */
16
29
  const UNREADABLE_GRACE_MS = 60 * 1000;
30
+ /** The lock's last sign of life in epoch ms: its heartbeat, else its start. NaN when neither parses. */
31
+ export function lockLastAliveMs(holder) {
32
+ const beat = typeof holder.heartbeatAt === "string" ? Date.parse(holder.heartbeatAt) : Number.NaN;
33
+ return Number.isNaN(beat) ? Date.parse(holder.startedAt) : beat;
34
+ }
35
+ /** True when the lock's last sign of life is more than LOCK_STALE_MS before `nowMs`. */
36
+ export function isLockExpired(holder, nowMs) {
37
+ return nowMs - lockLastAliveMs(holder) > LOCK_STALE_MS;
38
+ }
17
39
  export function companyLockRel(date, company) {
18
40
  return `workspace/signals/runs/${date}/${company}.lock`;
19
41
  }
@@ -33,7 +55,7 @@ function readHolder(abs) {
33
55
  try {
34
56
  const v = JSON.parse(fs.readFileSync(abs, "utf8"));
35
57
  if (typeof v.pid === "number" && typeof v.startedAt === "string" && typeof v.trigger === "string") {
36
- return { pid: v.pid, startedAt: v.startedAt, trigger: v.trigger };
58
+ return { pid: v.pid, startedAt: v.startedAt, trigger: v.trigger, ...(typeof v.heartbeatAt === "string" ? { heartbeatAt: v.heartbeatAt } : {}) };
37
59
  }
38
60
  }
39
61
  catch {
@@ -73,7 +95,20 @@ export function acquireCompanyLock(input) {
73
95
  fs.rmSync(abs, { force: true });
74
96
  }
75
97
  };
76
- return { ok: true, takeover, release };
98
+ const heartbeat = () => {
99
+ try {
100
+ const current = readHolder(abs);
101
+ if (!current || current.pid !== mine.pid || current.startedAt !== mine.startedAt)
102
+ return;
103
+ const tmp = `${abs}.hb-${process.pid}`;
104
+ fs.writeFileSync(tmp, JSON.stringify({ ...mine, heartbeatAt: input.now().toISOString() }));
105
+ fs.renameSync(tmp, abs);
106
+ }
107
+ catch {
108
+ // A missed refresh is not an error: the next one writes again.
109
+ }
110
+ };
111
+ return { ok: true, takeover, heartbeat, release };
77
112
  }
78
113
  const holder = readHolder(abs);
79
114
  const nowMs = input.now().getTime();
@@ -94,7 +129,7 @@ export function acquireCompanyLock(input) {
94
129
  else if (!isAlive(holder.pid)) {
95
130
  reason = "pid-dead";
96
131
  }
97
- else if (nowMs - Date.parse(holder.startedAt) > LOCK_STALE_MS) {
132
+ else if (isLockExpired(holder, nowMs)) {
98
133
  reason = "expired";
99
134
  }
100
135
  if (reason === null && holder)
@@ -58,7 +58,8 @@ export function isRunRecord(v) {
58
58
  (v.currentStep === null || oneOf(STEP_NAMES, v.currentStep)) &&
59
59
  Array.isArray(v.steps) &&
60
60
  v.steps.every(isStepRecord) &&
61
- isNum(v.maxBudgetUsd) &&
61
+ // `maxBudgetUsd` is on records written while runs had a spend cap. It is
62
+ // not read and not checked, so those records still load.
62
63
  isNum(v.maxTurns) &&
63
64
  strOrNull(v.jobRanAt) &&
64
65
  strOrNull(v.nextRetryAt) &&
@@ -1,20 +1,25 @@
1
1
  export interface SignalsSettings {
2
2
  maxTurns: number;
3
- maxBudgetUsd: number;
4
3
  lateStartHour: number;
5
4
  briefWaitMinutes: number;
6
5
  /**
7
- * What one source counts as against maxBudgetUsd when the coding tool reports
8
- * no cost for it (Codex always, Grok sometimes). 0 turns the charge off.
6
+ * What one source adds to a run's estimated spend when the coding tool
7
+ * reports no cost for it (Codex always, Grok sometimes). 0 turns it off.
8
+ * The estimate is reported as information; no run stops on it.
9
9
  */
10
10
  unpricedSourceEstimateUsd: number;
11
11
  }
12
12
  export declare const DEFAULT_SIGNALS_SETTINGS: SignalsSettings;
13
13
  export declare const SIGNALS_SETTINGS_REL: string;
14
+ /**
15
+ * Keys in core/settings/signals.yaml that are not settings here are ignored
16
+ * without a message. That covers `maxBudgetUsd` and
17
+ * `incremental.max_budget_usd`, which older settings files still carry from
18
+ * when runs had a spend cap.
19
+ */
14
20
  export declare function loadSignalsSettings(hqRoot: string): SignalsSettings;
15
21
  /** Per-pass limits for a growing source; normal runs retain their own defaults. */
16
22
  export declare function loadIncrementalSettings(hqRoot: string): {
17
23
  maxTurns: number;
18
- maxBudgetUsd: number;
19
24
  };
20
25
  //# sourceMappingURL=settings.d.ts.map
@@ -4,7 +4,6 @@ import * as path from "node:path";
4
4
  import yaml from "js-yaml";
5
5
  export const DEFAULT_SIGNALS_SETTINGS = {
6
6
  maxTurns: 40,
7
- maxBudgetUsd: 2.0,
8
7
  lateStartHour: 22,
9
8
  briefWaitMinutes: 20,
10
9
  unpricedSourceEstimateUsd: 0.1,
@@ -12,12 +11,17 @@ export const DEFAULT_SIGNALS_SETTINGS = {
12
11
  /** maxTurns: whole number >= 1. lateStartHour: whole hour 1-24 (0 would make every job late; 24 turns it off). */
13
12
  const VALID = {
14
13
  maxTurns: (v) => Number.isInteger(v) && v >= 1,
15
- maxBudgetUsd: (v) => Number.isFinite(v) && v >= 0,
16
14
  lateStartHour: (v) => Number.isInteger(v) && v >= 1 && v <= 24,
17
15
  briefWaitMinutes: (v) => Number.isFinite(v) && v >= 0,
18
16
  unpricedSourceEstimateUsd: (v) => Number.isFinite(v) && v >= 0,
19
17
  };
20
18
  export const SIGNALS_SETTINGS_REL = path.join("core", "settings", "signals.yaml");
19
+ /**
20
+ * Keys in core/settings/signals.yaml that are not settings here are ignored
21
+ * without a message. That covers `maxBudgetUsd` and
22
+ * `incremental.max_budget_usd`, which older settings files still carry from
23
+ * when runs had a spend cap.
24
+ */
21
25
  export function loadSignalsSettings(hqRoot) {
22
26
  const out = { ...DEFAULT_SIGNALS_SETTINGS };
23
27
  let raw;
@@ -49,14 +53,12 @@ export function loadSignalsSettings(hqRoot) {
49
53
  }
50
54
  /** Per-pass limits for a growing source; normal runs retain their own defaults. */
51
55
  export function loadIncrementalSettings(hqRoot) {
52
- const out = { maxTurns: 12, maxBudgetUsd: 0.4 };
56
+ const out = { maxTurns: 12 };
53
57
  try {
54
58
  const raw = yaml.load(fs.readFileSync(path.join(hqRoot, SIGNALS_SETTINGS_REL), "utf8"));
55
59
  const v = raw?.incremental;
56
60
  if (typeof v?.max_turns === "number" && VALID.maxTurns(v.max_turns))
57
61
  out.maxTurns = v.max_turns;
58
- if (typeof v?.max_budget_usd === "number" && VALID.maxBudgetUsd(v.max_budget_usd))
59
- out.maxBudgetUsd = v.max_budget_usd;
60
62
  }
61
63
  catch (err) {
62
64
  if (err.code !== "ENOENT")
@@ -13,6 +13,16 @@ export declare const WORKLIST_ITEM_TIMEOUT_MS = 10000;
13
13
  * fixed script budget plus WORKLIST_ITEM_TIMEOUT_MS per item.
14
14
  */
15
15
  export declare function worklistTimeoutMs(limit: number): number;
16
+ /**
17
+ * The longest the step can go between two refreshes of the run lock, which it
18
+ * refreshes when a source starts and when it finishes: one channel's redo and
19
+ * listing calls before the first source, then one source's turn on the Fleet
20
+ * helper, its second turn on the claude CLI when the helper refuses it as too
21
+ * large, and its mark-done call. With the defaults: 60 s + 260 s + 600 s +
22
+ * 600 s + 60 s = 1,580 s, about 26 minutes. LOCK_STALE_MS (3 hours) is more
23
+ * than six times that.
24
+ */
25
+ export declare const MAX_SOURCE_GAP_MS: number;
16
26
  export declare const CODEX_PERMISSION_PROFILE = "hq_signals_extract";
17
27
  export declare const CANDIDATE_WRAPPER_NAME = "write-candidate.sh";
18
28
  /** The sandbox profile the step writes to <turn dir>/.grok/sandbox.toml for a grok turn. */
@@ -44,7 +54,7 @@ export interface PartialDocument {
44
54
  audience: string[];
45
55
  }
46
56
  export interface ExtractStepOptions {
47
- /** Charge per source when the runtime reports no cost. Default UNPRICED_SOURCE_ESTIMATE_USD. */
57
+ /** Estimated spend per source when the runtime reports no cost. Default UNPRICED_SOURCE_ESTIMATE_USD. */
48
58
  unpricedSourceEstimateUsd?: number;
49
59
  documentOverride?: PartialDocument;
50
60
  priorSignals?: readonly PriorSignal[];
@@ -85,18 +95,17 @@ interface WorkItem {
85
95
  skip?: string;
86
96
  }
87
97
  /**
88
- * What one source is charged against the run budget when the runtime reports
89
- * no cost for it. `codex exec` has no turn or budget option and its event
90
- * stream carries no cost, and a grok end event can omit total_cost_usd. Without
91
- * a charge the run's spend stays 0 and the budget stop never fires.
98
+ * What one source adds to the run's estimated spend when the runtime reports
99
+ * no cost for it. `codex exec` reports no cost in its event stream, and a grok
100
+ * end event can omit total_cost_usd. The figure is reported as information
101
+ * only: nothing stops a run on it.
92
102
  *
93
103
  * 0.10 USD (owner decision, 2026-11-16) is an assumption, not a measurement:
94
- * no priced codex or grok extract run exists to derive it from. With the
95
- * default 2.00 USD run budget it lets at most 20 such sources run. A codex turn
96
- * that fails or is refused is not charged. The run record marks the spend as
104
+ * no priced codex or grok extract run exists to derive it from. A codex turn
105
+ * that fails or is refused adds nothing. The run record marks the spend as
97
106
  * estimated.
98
107
  * Set `unpricedSourceEstimateUsd` in core/settings/signals.yaml to change it;
99
- * 0 turns the charge off.
108
+ * 0 turns the estimate off.
100
109
  */
101
110
  export declare const UNPRICED_SOURCE_ESTIMATE_USD = 0.1;
102
111
  /** The Executive bot's runtime (lib/bot/executive.ts), or null when there is no personal bot. */
@@ -247,6 +256,24 @@ export declare function validateNewCandidates(files: string[], expectedAudienceK
247
256
  updated?: number;
248
257
  skipped?: number;
249
258
  };
259
+ /**
260
+ * Whether a claude turn was refused for a provider limit, read from claude's
261
+ * own result event and nothing else. stderr and the turn's output are never
262
+ * read: they can carry the source's words, and a source that says "429" or
263
+ * "rate limit" must not stop a run.
264
+ *
265
+ * The event must be one claude marked as failed (`is_error`, or an `error*`
266
+ * subtype). Then:
267
+ * - `rate`: its `api_error_status` field is the number 429.
268
+ * - `usage`: its whole `result` is the provider's usage-limit sentence, by the
269
+ * rule the hot-channel signals pass uses (isUsageLimitSentence: short, opens
270
+ * as the sentence, no clause after it). claude gives a plan limit no code of
271
+ * its own, so this one field is read as text.
272
+ *
273
+ * codex and grok report no code for a limit, so a limit on those tools is not
274
+ * detected here: each remaining source fails and the run ends as it did before.
275
+ */
276
+ export declare function claudeProviderLimit(result: Record<string, unknown> | null): "usage" | "rate" | null;
250
277
  /** Paths a turn may touch, all resolved through symlinks. */
251
278
  export interface TurnScope {
252
279
  hqRoot: string;
@@ -364,7 +391,7 @@ export declare function chooseExtractRuntime(main: BotRuntimeId, avail: {
364
391
  grok: () => GrokAvailability;
365
392
  claude: () => ToolAvailability;
366
393
  }, platform?: NodeJS.Platform): ExtractRuntimeChoice;
367
- export declare function claudeTurnArgs(prompt: string, scope: TurnScope, maxTurns: number, budgetUsd: number): string[];
394
+ export declare function claudeTurnArgs(prompt: string, scope: TurnScope, maxTurns: number): string[];
368
395
  /**
369
396
  * argv for one codex turn. The prompt goes on stdin (`-`), which keeps a long
370
397
  * transcript off argv; the reply comes back in `outputFile`.