@indigoai-us/hq-cli 5.345.244 → 5.345.246

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 (116) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/dist/command-catalog.generated.d.ts +93 -6
  3. package/dist/command-catalog.generated.js +114 -6
  4. package/dist/commands/bot.js +1 -1
  5. package/dist/commands/core-checkpoint-native.d.ts +5 -1
  6. package/dist/commands/core-checkpoint-native.js +13 -5
  7. package/dist/commands/deploy-comments.js +139 -0
  8. package/dist/commands/deploy-list.d.ts +5 -0
  9. package/dist/commands/deploy-list.js +8 -0
  10. package/dist/commands/dm.d.ts +4 -1
  11. package/dist/commands/dm.js +11 -2
  12. package/dist/commands/files.d.ts +11 -2
  13. package/dist/commands/files.js +48 -3
  14. package/dist/commands/lanes-loop.js +4 -1
  15. package/dist/commands/lanes.js +16 -5
  16. package/dist/commands/mesh.d.ts +2 -0
  17. package/dist/commands/mesh.js +26 -6
  18. package/dist/commands/reindex.js +2 -1
  19. package/dist/commands/rescue.d.ts +22 -1
  20. package/dist/commands/rescue.js +56 -9
  21. package/dist/commands/sources.d.ts +1 -1
  22. package/dist/commands/sources.js +1 -1
  23. package/dist/commands/storage.d.ts +15 -2
  24. package/dist/commands/storage.js +74 -7
  25. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +2033 -1829
  26. package/dist/hq-cloud-sync-runner/package.json +1 -1
  27. package/dist/lib/agent-kit/mcp/tools.js +22 -0
  28. package/dist/lib/bot/jobs/hot-signal-sync.js +4 -1
  29. package/dist/lib/daemon/fleet-members-cache.d.ts +55 -0
  30. package/dist/lib/daemon/fleet-members-cache.js +266 -0
  31. package/dist/lib/daemon/handoff.d.ts +4 -0
  32. package/dist/lib/daemon/handoff.js +2 -1
  33. package/dist/lib/daemon/hook-requests.d.ts +2 -1
  34. package/dist/lib/daemon/hook-requests.js +19 -2
  35. package/dist/lib/daemon/install.d.ts +9 -1
  36. package/dist/lib/daemon/install.js +11 -2
  37. package/dist/lib/daemon/ops/policy.d.ts +23 -3
  38. package/dist/lib/daemon/ops/policy.js +62 -15
  39. package/dist/lib/daemon/run.js +12 -0
  40. package/dist/lib/daemon/server.d.ts +5 -0
  41. package/dist/lib/daemon/server.js +1 -1
  42. package/dist/lib/daemon/supervisor.d.ts +6 -0
  43. package/dist/lib/daemon/supervisor.js +31 -2
  44. package/dist/lib/doctor/checks/sync-runtime.js +8 -1
  45. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  46. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  47. package/dist/lib/hook-engine/coverage.d.ts +68 -0
  48. package/dist/lib/hook-engine/coverage.js +163 -0
  49. package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
  50. package/dist/lib/hot-channels/signals-pass.d.ts +52 -2
  51. package/dist/lib/hot-channels/signals-pass.js +65 -3
  52. package/dist/lib/install/claude-targets.d.ts +6 -0
  53. package/dist/lib/install/claude-targets.js +9 -1
  54. package/dist/lib/lanes/reconcile-result.d.ts +1 -1
  55. package/dist/lib/lanes/reconcile.js +19 -4
  56. package/dist/lib/lanes/remote-control-lane.d.ts +6 -0
  57. package/dist/lib/lanes/remote-control-lane.js +10 -1
  58. package/dist/lib/lanes/spawn.d.ts +2 -0
  59. package/dist/lib/lanes/spawn.js +19 -3
  60. package/dist/lib/lanes/worker-env-scrub.d.ts +48 -0
  61. package/dist/lib/lanes/worker-env-scrub.js +146 -0
  62. package/dist/lib/lanes/worker-process.js +4 -1
  63. package/dist/lib/mesh/client.js +5 -1
  64. package/dist/lib/mesh/live/daemon/doctor.d.ts +9 -0
  65. package/dist/lib/mesh/live/daemon/doctor.js +51 -6
  66. package/dist/lib/mesh/live/daemon/install.d.ts +39 -0
  67. package/dist/lib/mesh/live/daemon/install.js +70 -0
  68. package/dist/lib/mesh/live/daemon/outbox-company.d.ts +47 -0
  69. package/dist/lib/mesh/live/daemon/outbox-company.js +77 -0
  70. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  71. package/dist/lib/mesh/live/daemon/run.js +48 -3
  72. package/dist/lib/mesh/live/daemon/state.d.ts +5 -0
  73. package/dist/lib/mesh/live/daemon/system-unit.d.ts +21 -0
  74. package/dist/lib/mesh/live/daemon/system-unit.js +80 -0
  75. package/dist/lib/mesh/live/daemon/transcript-watch.d.ts +4 -1
  76. package/dist/lib/mesh/live/daemon/transcript-watch.js +42 -38
  77. package/dist/lib/mesh/live/direct-drain.js +3 -1
  78. package/dist/lib/mesh/live/emit.js +4 -2
  79. package/dist/lib/mesh/live/flush.d.ts +61 -0
  80. package/dist/lib/mesh/live/flush.js +434 -114
  81. package/dist/lib/mesh/live/paths.d.ts +10 -0
  82. package/dist/lib/mesh/live/paths.js +14 -0
  83. package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -1
  84. package/dist/lib/mesh/live/reporting-privacy.js +81 -7
  85. package/dist/lib/mesh/live/spool.d.ts +171 -17
  86. package/dist/lib/mesh/live/spool.js +777 -62
  87. package/dist/lib/signals/engine.d.ts +82 -2
  88. package/dist/lib/signals/engine.js +389 -53
  89. package/dist/lib/signals/steps/extract.js +5 -0
  90. package/dist/lib/sync-core/engine-holds.d.ts +17 -1
  91. package/dist/lib/sync-core/engine-holds.js +73 -3
  92. package/dist/lib/sync-core/reconcile.js +10 -2
  93. package/dist/lib/work-context/organize.d.ts +22 -4
  94. package/dist/lib/work-context/organize.js +50 -21
  95. package/dist/lib/work-context/paths.d.ts +6 -0
  96. package/dist/lib/work-context/paths.js +9 -0
  97. package/dist/lib/work-context/reconcile.d.ts +1 -1
  98. package/dist/lib/work-context/reconcile.js +1 -1
  99. package/dist/startup-registration.d.ts +14 -0
  100. package/dist/startup-registration.js +26 -0
  101. package/dist/utils/cli-telemetry.d.ts +6 -0
  102. package/dist/utils/cli-telemetry.js +154 -9
  103. package/dist/utils/github-tag-fallback.d.ts +7 -2
  104. package/dist/utils/github-tag-fallback.js +17 -8
  105. package/dist/utils/hq-core-source.d.ts +31 -0
  106. package/dist/utils/hq-core-source.js +144 -0
  107. package/dist/utils/interactive-caller.d.ts +6 -0
  108. package/dist/utils/interactive-caller.js +8 -0
  109. package/dist/utils/shipped-codex-hooks.d.ts +6 -4
  110. package/dist/utils/shipped-codex-hooks.js +22 -10
  111. package/dist/utils/vault-api.js +1 -0
  112. package/dist/utils/version-report.d.ts +3 -1
  113. package/dist/utils/version-report.js +13 -5
  114. package/docs/anywhere-runtime.md +2 -2
  115. package/package.json +8 -8
  116. package/scripts/check-function-manifest.mjs +99 -18
@@ -16,6 +16,14 @@
16
16
  * a watcher can miss a change: on macOS fs.watch is backed by an FSEvents
17
17
  * stream that starts asynchronously, so a change made right after a rebuild
18
18
  * re-arms the watchers is never reported.
19
+ *
20
+ * A stamp alone can also miss a change. Linux sets a directory's mtime from
21
+ * the coarse kernel clock (one tick, about 1-10 ms), so a change made in the
22
+ * same tick as the rebuild's stat leaves dev:ino:mtime unchanged. This is git's
23
+ * "racy index" problem and gets git's answer: a directory whose mtime is within
24
+ * RACY_WINDOW_MS of the rebuild is racy, its names are kept, and list()
25
+ * re-reads it and compares names until its mtime is older than the window.
26
+ * Directories outside the window cost one stat per list(), as before.
19
27
  */
20
28
  import { spawn } from "node:child_process";
21
29
  import * as fs from "node:fs";
@@ -36,20 +44,32 @@ export class PolicyOpError extends Error {
36
44
  this.name = "PolicyOpError";
37
45
  }
38
46
  }
47
+ /**
48
+ * How close to a rebuild a directory's mtime may be before a later change could
49
+ * leave it unchanged. It must exceed the filesystem's mtime granularity: one
50
+ * kernel tick on Linux (up to 10 ms), nanoseconds on APFS, and 2 s on FAT and
51
+ * exFAT volumes, which set the bound. A wider window only means a recently
52
+ * changed directory is re-read (one readdir) on each list() for that long.
53
+ */
54
+ export const RACY_WINDOW_MS = 2_000;
39
55
  /** Cached list of policy files under HQ_ROOT, invalidated by fs.watch. */
40
56
  export class PolicyIndex {
41
57
  hqRoot;
42
58
  log;
59
+ now;
43
60
  entries = null;
44
- /** Directory stat stamps taken while building `entries` (dir -> stamp). */
45
- stamps = new Map();
61
+ /** Directory state taken while building `entries` (dir -> stamp, plus names while racy). */
62
+ dirStates = new Map();
46
63
  watchers = [];
47
64
  closed = false;
48
65
  /** Bumped on every invalidation; lets callers see that the cache was rebuilt. */
49
66
  version = 0;
50
- constructor(hqRoot, log = () => { }) {
67
+ constructor(hqRoot, log = () => { },
68
+ /** Wall clock in ms, compared with directory mtimes. Injectable for tests. */
69
+ now = Date.now) {
51
70
  this.hqRoot = hqRoot;
52
71
  this.log = log;
72
+ this.now = now;
53
73
  }
54
74
  /** Policies visible to `company`: core, personal, and that company only. */
55
75
  list(company) {
@@ -73,15 +93,36 @@ export class PolicyIndex {
73
93
  }
74
94
  /** True when any directory scanned by the last rebuild changed since. */
75
95
  isStale() {
76
- for (const [dir, stamp] of this.stamps)
77
- if (dirStamp(dir) !== stamp)
96
+ // Read the clock before any readdir: a change after that readdir lands more
97
+ // than RACY_WINDOW_MS after a settled directory's mtime, so it moves the
98
+ // mtime and the stamp check alone sees it from then on.
99
+ const now = this.now();
100
+ for (const [dir, state] of this.dirStates) {
101
+ if (dirStat(dir).stamp !== state.stamp)
102
+ return true;
103
+ if (state.names === undefined)
104
+ continue;
105
+ if (!sameNames(sortedDirNames(dir), state.names))
78
106
  return true;
107
+ if (now - state.mtimeMs > RACY_WINDOW_MS)
108
+ state.names = undefined;
109
+ }
79
110
  return false;
80
111
  }
81
112
  rebuild() {
82
113
  // Stamp each directory before reading it, so a change racing the read
83
114
  // either shows up in the read or leaves a stale stamp for the next list().
84
- const stamps = new Map();
115
+ // A racy directory's names are read right after its stamp, before the
116
+ // reads below, so a change in between at worst costs one extra rebuild.
117
+ const start = this.now();
118
+ const dirStates = new Map();
119
+ const record = (dir) => {
120
+ const st = dirStat(dir);
121
+ const state = { stamp: st.stamp, mtimeMs: st.mtimeMs };
122
+ if (st.stamp !== "missing" && st.mtimeMs >= start - RACY_WINDOW_MS)
123
+ state.names = sortedDirNames(dir);
124
+ dirStates.set(dir, state);
125
+ };
85
126
  const dirs = [
86
127
  { dir: path.join(this.hqRoot, "core", "policies"), scope: "core" },
87
128
  { dir: path.join(this.hqRoot, "personal", "policies"), scope: "personal" },
@@ -89,18 +130,18 @@ export class PolicyIndex {
89
130
  const companiesDir = path.join(this.hqRoot, "companies");
90
131
  const companyDirs = [];
91
132
  for (const d of dirs)
92
- stamps.set(d.dir, dirStamp(d.dir));
93
- stamps.set(companiesDir, dirStamp(companiesDir));
133
+ record(d.dir);
134
+ record(companiesDir);
94
135
  for (const co of readDirNames(companiesDir)) {
95
136
  if (!SLUG_RE.test(co))
96
137
  continue;
97
138
  const companyDir = path.join(companiesDir, co);
98
- stamps.set(companyDir, dirStamp(companyDir));
139
+ record(companyDir);
99
140
  if (isDir(companyDir))
100
141
  companyDirs.push(companyDir);
101
142
  const dir = path.join(companiesDir, co, "policies");
102
143
  if (isDir(dir)) {
103
- stamps.set(dir, dirStamp(dir));
144
+ record(dir);
104
145
  dirs.push({ dir, scope: "company", company: co });
105
146
  }
106
147
  }
@@ -113,7 +154,7 @@ export class PolicyIndex {
113
154
  }
114
155
  }
115
156
  this.entries = entries;
116
- this.stamps = stamps;
157
+ this.dirStates = dirStates;
117
158
  this.rewatch([...dirs.map((d) => d.dir), ...companyDirs, companiesDir]);
118
159
  }
119
160
  rewatch(dirs) {
@@ -149,14 +190,20 @@ function readDirNames(dir) {
149
190
  throw err;
150
191
  }
151
192
  }
152
- /** Identity plus modification time of a directory, or "missing". */
153
- function dirStamp(dir) {
193
+ function sortedDirNames(dir) {
194
+ return readDirNames(dir).sort();
195
+ }
196
+ function sameNames(a, b) {
197
+ return a.length === b.length && a.every((name, i) => name === b[i]);
198
+ }
199
+ /** Identity plus modification time of a directory ("missing" if absent), and that mtime in ms. */
200
+ function dirStat(dir) {
154
201
  try {
155
202
  const st = fs.statSync(dir, { bigint: true });
156
- return `${st.dev}:${st.ino}:${st.mtimeNs}`;
203
+ return { stamp: `${st.dev}:${st.ino}:${st.mtimeNs}`, mtimeMs: Number(st.mtimeNs) / 1e6 };
157
204
  }
158
205
  catch {
159
- return "missing";
206
+ return { stamp: "missing", mtimeMs: 0 };
160
207
  }
161
208
  }
162
209
  function isDir(dir) {
@@ -41,6 +41,7 @@ import { daemonLanesReconcileHandler } from "../lanes/daemon-reconcile.js";
41
41
  import { computeLanesMonitorSection } from "./lanes-monitor-state.js";
42
42
  import { ensureDaemonLanesReconcileHandler, runDaemonLanesReconcileInProcess } from "./lanes-reconcile-loader.js";
43
43
  import { startWhoamiCacheWriter } from "./whoami-cache.js";
44
+ import { hqMembersList, startFleetMembersWarmer } from "./fleet-members-cache.js";
44
45
  import { SUPERVISOR_HANDOFF_FLAG, readDaemonFlag } from "./flag.js";
45
46
  import { createDaemonSharedFlagReads, hqdListenerFlagGate } from "./shared-flag-reads.js";
46
47
  import { createDaemonKillSwitchMonitors } from "./timed-flag-monitors.js";
@@ -1226,6 +1227,16 @@ export async function runDaemon(opts) {
1226
1227
  lookupPersonUid: async (token) => (await import("../../commands/whoami.js")).readPersonUid(token),
1227
1228
  })
1228
1229
  : null;
1230
+ const fleetMembersAbort = new AbortController();
1231
+ const fleetMembers = path.resolve(home) === path.resolve(os.homedir())
1232
+ ? startFleetMembersWarmer({
1233
+ home,
1234
+ env,
1235
+ log,
1236
+ abort: fleetMembersAbort,
1237
+ list: hqMembersList({ nodeBinary: opts.nodeBinary, hqBinary: opts.hqBinary, env, signal: fleetMembersAbort.signal }),
1238
+ })
1239
+ : null;
1229
1240
  // The hqd listener checks again when a shared read's HQ Anywhere answer
1230
1241
  // changes, or the running server's runtime gate changes; it has no timer of
1231
1242
  // its own beyond a rare fallback (anywhere-listener.ts).
@@ -1369,6 +1380,7 @@ export async function runDaemon(opts) {
1369
1380
  mergeSections.close();
1370
1381
  stateWriter.close();
1371
1382
  whoamiCache?.close();
1383
+ fleetMembers?.close();
1372
1384
  return stopJobsClosed;
1373
1385
  };
1374
1386
  const plan = () => {
@@ -45,6 +45,11 @@ export interface HqdServerOptions {
45
45
  env?: NodeJS.ProcessEnv;
46
46
  /** Test seam for the hq-anywhere-runtime fail-safe gate. */
47
47
  mcpEnabled?: () => boolean | Promise<boolean>;
48
+ /**
49
+ * Time a skill.command request may run, from when hqd received it. Defaults
50
+ * to HQD_DEFAULT_REQUEST_TIMEOUT_MS; tests set it shorter.
51
+ */
52
+ skillCommandTimeoutMs?: number;
48
53
  /** Test seam for the live hq-flags read used by the daemon's bounded runtime monitor. */
49
54
  runtimeFlagReader?: (options: ReadDaemonFlagOptions) => Promise<boolean>;
50
55
  /** Test seam for the human opt-in setting; production reads hq-pro. */
@@ -564,7 +564,7 @@ export async function startHqdServer(opts) {
564
564
  case "skill.command":
565
565
  return runSkillCommand(parseSkillCommandArgs(args), {
566
566
  daemonRoot: requireRoot(),
567
- deadlineMs: requestStartedAt + HQD_DEFAULT_REQUEST_TIMEOUT_MS,
567
+ deadlineMs: requestStartedAt + (opts.skillCommandTimeoutMs ?? HQD_DEFAULT_REQUEST_TIMEOUT_MS),
568
568
  });
569
569
  case "mcp.call": {
570
570
  const name = stringArg(args, "name");
@@ -244,6 +244,12 @@ export interface Supervisor {
244
244
  * `keepAcrossCliUpdates` running.
245
245
  */
246
246
  export declare function planKey(plan: UnitPlan, cliVersion?: string): string;
247
+ /**
248
+ * The line of a unit's output that names why it stopped: V8's FATAL ERROR
249
+ * line, else the last line that looks like a thrown error. Stack frames and
250
+ * plain log lines are not causes. Bounded to 200 characters.
251
+ */
252
+ export declare function exitCauseLine(outputTail: string | undefined): string | undefined;
247
253
  export declare const DAEMON_REQUEST_POLL_MS = 250;
248
254
  export declare function createSupervisor(deps: SupervisorDeps): Supervisor;
249
255
  export {};
@@ -187,6 +187,20 @@ export function planKey(plan, cliVersion) {
187
187
  fields.push(cliVersion);
188
188
  return JSON.stringify(fields);
189
189
  }
190
+ /**
191
+ * The line of a unit's output that names why it stopped: V8's FATAL ERROR
192
+ * line, else the last line that looks like a thrown error. Stack frames and
193
+ * plain log lines are not causes. Bounded to 200 characters.
194
+ */
195
+ export function exitCauseLine(outputTail) {
196
+ if (!outputTail)
197
+ return undefined;
198
+ const lines = outputTail.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
199
+ const fatal = [...lines].reverse().find((line) => line.startsWith("FATAL ERROR:"));
200
+ const thrown = [...lines].reverse().find((line) => /^(Uncaught )?([A-Z][A-Za-z]*Error|Error)(\s*\[[A-Z_]+\])?:/.test(line));
201
+ const cause = fatal ?? thrown;
202
+ return cause ? cause.slice(0, 200) : undefined;
203
+ }
190
204
  function errorMessage(err) {
191
205
  return err instanceof Error ? err.message : String(err);
192
206
  }
@@ -936,7 +950,22 @@ export function createSupervisor(deps) {
936
950
  emit();
937
951
  return;
938
952
  }
939
- deps.log("warn", `${slot.plan.id} exited (code=${code ?? "null"} signal=${signal ?? "none"})`);
953
+ // An abnormal exit names its cause from the unit's own output (for
954
+ // example V8's "JavaScript heap out of memory" before a SIGABRT), so
955
+ // the daemon log says why without opening the unit log.
956
+ // The output is read at most once per exit.
957
+ let tailRead = false;
958
+ let tail;
959
+ const exitTail = () => {
960
+ if (!tailRead) {
961
+ tailRead = true;
962
+ tail = readExitOutputTail(slot);
963
+ }
964
+ return tail;
965
+ };
966
+ const abnormal = code !== 0 && signal !== "SIGTERM" && signal !== "SIGINT";
967
+ const cause = abnormal && slot.lastSpawnError === undefined ? exitCauseLine(exitTail()) : undefined;
968
+ deps.log("warn", `${slot.plan.id} exited (code=${code ?? "null"} signal=${signal ?? "none"})${cause ? `: ${cause}` : ""}`);
940
969
  if (ranFor >= HEALTHY_RUN_MS)
941
970
  slot.attempts = 0;
942
971
  if (ranFor >= EPISODE_HEALTHY_RESET_MS) {
@@ -954,7 +983,7 @@ export function createSupervisor(deps) {
954
983
  else {
955
984
  const spawnError = slot.lastSpawnError;
956
985
  delete slot.lastSpawnError;
957
- const outputTail = spawnError === undefined ? readExitOutputTail(slot) : undefined;
986
+ const outputTail = spawnError === undefined ? exitTail() : undefined;
958
987
  delete slot.lastLockHolderPid;
959
988
  if (slot.plan.service === "sync-core" && code === SYNC_CORE_LOCK_HELD_EXIT) {
960
989
  const holder = lockHolderPidFromOutput(outputTail);
@@ -324,7 +324,14 @@ export function analyzeSyncRuntimeLog(lines, options) {
324
324
  function readLogTail(file) {
325
325
  const fd = fs.openSync(file, "r");
326
326
  try {
327
- const size = fs.fstatSync(fd).size;
327
+ const stat = fs.fstatSync(fd);
328
+ // Opening a directory read-only succeeds on Linux, and where a directory's
329
+ // size reads as 0 (btrfs, overlayfs on btrfs) the zero-length read below
330
+ // succeeds too. Refuse anything that is not a regular file so a directory
331
+ // at the log path reads as unreadable on every filesystem.
332
+ if (!stat.isFile())
333
+ throw new Error(`sync log is not a regular file: ${file}`);
334
+ const size = stat.size;
328
335
  const length = Math.min(size, LOG_TAIL_BYTES);
329
336
  const buffer = Buffer.alloc(length);
330
337
  fs.readSync(fd, buffer, 0, length, size - length);