@indigoai-us/hq-cli 5.345.269 → 5.345.272

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 (61) hide show
  1. package/CHANGELOG.md +81 -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/run.d.ts +1 -1
  19. package/dist/lib/daemon/run.js +65 -51
  20. package/dist/lib/daemon/supervisor.js +0 -2
  21. package/dist/lib/hook-engine/coverage.d.ts +21 -0
  22. package/dist/lib/hook-engine/coverage.js +98 -5
  23. package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
  24. package/dist/lib/hook-engine/native-stop-compatibility.json +4 -2
  25. package/dist/lib/hook-engine/reconcile.js +8 -0
  26. package/dist/lib/hook-engine/stable-heal.d.ts +17 -1
  27. package/dist/lib/hook-engine/stable-heal.js +42 -5
  28. package/dist/lib/hook-engine/stable-link.d.ts +70 -0
  29. package/dist/lib/hook-engine/stable-link.js +300 -0
  30. package/dist/lib/hot-channels/signals-pass.d.ts +10 -2
  31. package/dist/lib/hot-channels/signals-pass.js +13 -3
  32. package/dist/lib/install/hook-target.js +4 -1
  33. package/dist/lib/signals/engine.d.ts +0 -2
  34. package/dist/lib/signals/engine.js +12 -7
  35. package/dist/lib/signals/reply.js +35 -82
  36. package/dist/lib/signals/run-lock.d.ts +8 -0
  37. package/dist/lib/signals/run-lock.js +42 -7
  38. package/dist/lib/signals/run-record.js +2 -1
  39. package/dist/lib/signals/settings.d.ts +9 -4
  40. package/dist/lib/signals/settings.js +7 -5
  41. package/dist/lib/signals/steps/extract.d.ts +64 -17
  42. package/dist/lib/signals/steps/extract.js +175 -197
  43. package/dist/lib/signals/steps/types.d.ts +3 -2
  44. package/dist/lib/sync-core/reconcile.d.ts +7 -1
  45. package/dist/lib/sync-core/reconcile.js +105 -18
  46. package/dist/lib/sync-core/release.d.ts +52 -2
  47. package/dist/lib/sync-core/release.js +172 -11
  48. package/dist/lib/sync-core/rollout-state.d.ts +11 -0
  49. package/dist/lib/sync-core/rollout-state.js +16 -0
  50. package/dist/utils/client-health-contract.d.ts +32 -0
  51. package/dist/utils/client-health-contract.js +35 -0
  52. package/dist/utils/client-health.d.ts +43 -0
  53. package/dist/utils/client-health.js +106 -3
  54. package/dist/utils/hook-trust.js +7 -1
  55. package/dist/utils/host-registration.d.ts +12 -35
  56. package/dist/utils/host-registration.js +47 -177
  57. package/dist/utils/login-browser.d.ts +1 -0
  58. package/dist/utils/login-browser.js +31 -6
  59. package/dist/utils/spawn-detached-hidden.d.ts +66 -0
  60. package/dist/utils/spawn-detached-hidden.js +222 -0
  61. package/package.json +7 -7
@@ -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;
@@ -281,15 +308,35 @@ export declare function codexFilesystemProfile(installDir: string, workDir: stri
281
308
  export declare function grokSandboxProfile(scope: TurnScope, envPath: string | undefined): string;
282
309
  /** Grok can read the source; candidate writing belongs to the host. */
283
310
  export declare function grokAllowRules(channelDir: string): string[];
284
- /** Parse literal arguments only. No shell ever interprets model output. */
285
- export declare function grokCandidateArgv(command: string, wrapperPath: string): string[] | null;
311
+ export interface DroppedCandidate {
312
+ index: number;
313
+ reason: string;
314
+ }
315
+ export type CandidateParseResult = {
316
+ ok: true;
317
+ argv: string[];
318
+ } | {
319
+ ok: false;
320
+ reason: string;
321
+ };
322
+ export interface ExecuteCandidatesResult {
323
+ error?: string;
324
+ dropped: DroppedCandidate[];
325
+ }
326
+ /**
327
+ * Validate one structured candidate object and build the fixed 7-element argv
328
+ * for the pinned candidate wrapper. No shell ever interprets model output, and
329
+ * the model can never change the executable, wrapper path, or flag shape.
330
+ */
331
+ export declare function structuredCandidateArgv(candidate: unknown, wrapperPath: string): CandidateParseResult;
286
332
  /**
287
- * Validate the whole batch before writing. Only the host executes the pinned
288
- * writer. When `expectedWrapper` is set, the file is compared to that text
289
- * immediately before each exec. Strict can write the turn directory, so a
290
- * writer that no longer matches is not run.
333
+ * Validate structured candidates and execute each valid one through the pinned
334
+ * wrapper using a fixed argv array (never a shell command string). A malformed
335
+ * or invalid candidate drops only itself, records why, and keeps the rest of
336
+ * the item's valid candidates. When `expectedWrapper` is set, the file on disk
337
+ * is compared to that text immediately before each exec.
291
338
  */
292
- export declare function executeGrokCandidates(text: string, wrapperPath: string, spawn: SpawnSyncFn, opts: Parameters<SpawnSyncFn>[2], expectedWrapper?: string, runtime?: "grok" | "codex" | "claude"): string | undefined;
339
+ export declare function executeGrokCandidates(text: string, wrapperPath: string, spawn: SpawnSyncFn, opts: Parameters<SpawnSyncFn>[2], expectedWrapper?: string, runtime?: "grok" | "codex" | "claude"): ExecuteCandidatesResult;
293
340
  /**
294
341
  * Read denies for the grok login. Grok matches a `~` tool path literally and
295
342
  * expands `~` only after that check, so the absolute temp home is not enough.
@@ -344,7 +391,7 @@ export declare function chooseExtractRuntime(main: BotRuntimeId, avail: {
344
391
  grok: () => GrokAvailability;
345
392
  claude: () => ToolAvailability;
346
393
  }, platform?: NodeJS.Platform): ExtractRuntimeChoice;
347
- 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[];
348
395
  /**
349
396
  * argv for one codex turn. The prompt goes on stdin (`-`), which keeps a long
350
397
  * transcript off argv; the reply comes back in `outputFile`.