@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.217

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 (241) hide show
  1. package/CHANGELOG.md +206 -1
  2. package/README.md +45 -0
  3. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  4. package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
  5. package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
  6. package/dist/command-catalog.generated.d.ts +105 -10
  7. package/dist/command-catalog.generated.js +127 -10
  8. package/dist/command-help.js +3 -1
  9. package/dist/command-registration-plan.d.ts +6 -0
  10. package/dist/command-registration-plan.js +1 -0
  11. package/dist/commands/auth.d.ts +1 -1
  12. package/dist/commands/auth.js +11 -52
  13. package/dist/commands/bot.js +75 -10
  14. package/dist/commands/capacity.d.ts +4 -1
  15. package/dist/commands/capacity.js +46 -10
  16. package/dist/commands/cloud-demote.d.ts +19 -4
  17. package/dist/commands/cloud-demote.js +85 -12
  18. package/dist/commands/cloud-provision.d.ts +5 -1
  19. package/dist/commands/cloud-provision.js +6 -2
  20. package/dist/commands/cloud.d.ts +36 -0
  21. package/dist/commands/cloud.js +110 -27
  22. package/dist/commands/core-delegate-w1b.js +15 -1
  23. package/dist/commands/core-policy.js +67 -8
  24. package/dist/commands/core.js +1 -0
  25. package/dist/commands/daemon.js +9 -1
  26. package/dist/commands/dm.js +7 -0
  27. package/dist/commands/doctor-usage.d.ts +8 -0
  28. package/dist/commands/doctor-usage.js +20 -0
  29. package/dist/commands/doctor.js +7 -1
  30. package/dist/commands/env.d.ts +18 -0
  31. package/dist/commands/env.js +82 -0
  32. package/dist/commands/files-browse.d.ts +11 -4
  33. package/dist/commands/files-browse.js +21 -4
  34. package/dist/commands/files.d.ts +1 -1
  35. package/dist/commands/files.js +25 -11
  36. package/dist/commands/install-global.js +2 -2
  37. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  38. package/dist/commands/integrations-auth-rules.js +79 -0
  39. package/dist/commands/integrations-import.js +124 -12
  40. package/dist/commands/lanes.js +102 -26
  41. package/dist/commands/logout.d.ts +7 -0
  42. package/dist/commands/logout.js +41 -34
  43. package/dist/commands/mesh.d.ts +2 -0
  44. package/dist/commands/mesh.js +60 -35
  45. package/dist/commands/sources.d.ts +8 -2
  46. package/dist/commands/sources.js +65 -9
  47. package/dist/commands/sync-held.js +5 -2
  48. package/dist/commands/whoami.js +26 -1
  49. package/dist/data/command-states.json +15 -0
  50. package/dist/index.js +52 -4
  51. package/dist/lazy-commands.js +5 -6
  52. package/dist/lib/anywhere-person-setting.d.ts +2 -0
  53. package/dist/lib/anywhere-person-setting.js +6 -3
  54. package/dist/lib/billing/usage-card.d.ts +25 -4
  55. package/dist/lib/billing/usage-card.js +76 -9
  56. package/dist/lib/billing/usage-cost.d.ts +3 -3
  57. package/dist/lib/billing/usage-cost.js +35 -13
  58. package/dist/lib/billing/usage-only.js +4 -2
  59. package/dist/lib/billing/usage-rate-card.d.ts +2 -2
  60. package/dist/lib/billing/usage-rate-card.js +3 -0
  61. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  62. package/dist/lib/bot/fleet-cron.js +126 -7
  63. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  64. package/dist/lib/bot/fleet-daemon.js +99 -1
  65. package/dist/lib/bot/inflight.d.ts +9 -0
  66. package/dist/lib/bot/inflight.js +10 -0
  67. package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
  68. package/dist/lib/bot/probe.js +7 -1
  69. package/dist/lib/bot/run.js +20 -1
  70. package/dist/lib/bot/runtime/codex.js +1 -1
  71. package/dist/lib/bot/runtime/grok-acp.d.ts +6 -1
  72. package/dist/lib/bot/runtime/grok-acp.js +32 -14
  73. package/dist/lib/bot/runtime/grok.js +1 -1
  74. package/dist/lib/bot/runtime/index.js +19 -9
  75. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  76. package/dist/lib/bot/runtime/types.d.ts +15 -0
  77. package/dist/lib/bot/runtime/types.js +9 -0
  78. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  79. package/dist/lib/bot/runtime-failure.js +43 -1
  80. package/dist/lib/capacity/accounts.d.ts +8 -0
  81. package/dist/lib/capacity/accounts.js +19 -0
  82. package/dist/lib/capacity/available.d.ts +154 -0
  83. package/dist/lib/capacity/available.js +905 -0
  84. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  85. package/dist/lib/capacity/codex-availability.js +26 -1
  86. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  87. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  88. package/dist/lib/capacity/collectors/codex.js +10 -7
  89. package/dist/lib/capacity/ledger.d.ts +37 -1
  90. package/dist/lib/capacity/ledger.js +207 -30
  91. package/dist/lib/capacity/project.d.ts +26 -0
  92. package/dist/lib/capacity/project.js +137 -8
  93. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  94. package/dist/lib/capacity/refusal-rows.js +61 -0
  95. package/dist/lib/capacity/refusal.d.ts +53 -2
  96. package/dist/lib/capacity/refusal.js +284 -65
  97. package/dist/lib/capacity/route.js +46 -11
  98. package/dist/lib/capacity/widget.d.ts +12 -1
  99. package/dist/lib/capacity/widget.js +91 -3
  100. package/dist/lib/daemon/flag-monitor.d.ts +8 -0
  101. package/dist/lib/daemon/flag-monitor.js +17 -6
  102. package/dist/lib/daemon/flag.d.ts +65 -1
  103. package/dist/lib/daemon/flag.js +190 -40
  104. package/dist/lib/daemon/ops/policy.js +62 -5
  105. package/dist/lib/daemon/paths.d.ts +72 -2
  106. package/dist/lib/daemon/paths.js +154 -3
  107. package/dist/lib/daemon/resolver.d.ts +2 -0
  108. package/dist/lib/daemon/resolver.js +3 -0
  109. package/dist/lib/daemon/run.d.ts +9 -0
  110. package/dist/lib/daemon/run.js +79 -21
  111. package/dist/lib/daemon/selfcheck.d.ts +22 -0
  112. package/dist/lib/daemon/selfcheck.js +40 -1
  113. package/dist/lib/daemon/server.d.ts +5 -1
  114. package/dist/lib/daemon/server.js +17 -23
  115. package/dist/lib/daemon/state-file-switch.d.ts +57 -0
  116. package/dist/lib/daemon/state-file-switch.js +88 -0
  117. package/dist/lib/daemon/state-file.d.ts +198 -0
  118. package/dist/lib/daemon/state-file.js +419 -0
  119. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  120. package/dist/lib/daemon/tcc-eperm.js +310 -0
  121. package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
  122. package/dist/lib/daemon/timed-flag-monitors.js +75 -0
  123. package/dist/lib/delivery/admission.d.ts +86 -0
  124. package/dist/lib/delivery/admission.js +148 -0
  125. package/dist/lib/delivery/artifacts.d.ts +7 -1
  126. package/dist/lib/delivery/artifacts.js +29 -10
  127. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  128. package/dist/lib/delivery/attempt-id.js +16 -0
  129. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  130. package/dist/lib/delivery/disposable-target.js +111 -0
  131. package/dist/lib/delivery/effects.d.ts +136 -0
  132. package/dist/lib/delivery/effects.js +541 -0
  133. package/dist/lib/delivery/enrollment.d.ts +21 -17
  134. package/dist/lib/delivery/enrollment.js +83 -5
  135. package/dist/lib/delivery/escalations.d.ts +51 -0
  136. package/dist/lib/delivery/escalations.js +60 -0
  137. package/dist/lib/delivery/lease.d.ts +80 -0
  138. package/dist/lib/delivery/lease.js +134 -0
  139. package/dist/lib/delivery/migrations.d.ts +120 -4
  140. package/dist/lib/delivery/migrations.js +215 -15
  141. package/dist/lib/delivery/mqtt.d.ts +2 -0
  142. package/dist/lib/delivery/mqtt.js +7 -0
  143. package/dist/lib/delivery/reconciler.d.ts +65 -1
  144. package/dist/lib/delivery/reconciler.js +224 -13
  145. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  146. package/dist/lib/delivery/rpc/client.js +159 -0
  147. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  148. package/dist/lib/delivery/rpc/port.js +16 -0
  149. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  150. package/dist/lib/delivery/rpc/server.js +205 -0
  151. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  152. package/dist/lib/delivery/rpc/wire.js +143 -0
  153. package/dist/lib/delivery/store.d.ts +2 -0
  154. package/dist/lib/delivery/store.js +4 -0
  155. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  156. package/dist/lib/delivery/windows-service-install.js +892 -0
  157. package/dist/lib/delivery/workers/macos.d.ts +16 -1
  158. package/dist/lib/delivery/workers/macos.js +54 -12
  159. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  160. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  161. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  162. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  163. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  164. package/dist/lib/delivery/workers/windows-service.js +584 -0
  165. package/dist/lib/delivery/workers/windows.d.ts +32 -22
  166. package/dist/lib/delivery/workers/windows.js +50 -64
  167. package/dist/lib/doctor/checks/host-core.d.ts +50 -0
  168. package/dist/lib/doctor/checks/host-core.js +269 -0
  169. package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
  170. package/dist/lib/doctor/checks/replay-recorder.js +261 -0
  171. package/dist/lib/doctor/registry.js +4 -0
  172. package/dist/lib/environment/profile.d.ts +239 -0
  173. package/dist/lib/environment/profile.js +251 -0
  174. package/dist/lib/hook-engine/reconcile.js +39 -13
  175. package/dist/lib/hook-engine/registration.d.ts +9 -0
  176. package/dist/lib/hook-engine/registration.js +19 -0
  177. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  178. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  179. package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
  180. package/dist/lib/hot-channels/adapters/slack.js +64 -21
  181. package/dist/lib/hot-channels/alert.d.ts +2 -0
  182. package/dist/lib/hot-channels/alert.js +8 -1
  183. package/dist/lib/hot-channels/contract.d.ts +12 -0
  184. package/dist/lib/hot-channels/contract.js +7 -0
  185. package/dist/lib/hot-channels/loop.js +1 -0
  186. package/dist/lib/hot-channels/run.d.ts +6 -0
  187. package/dist/lib/hot-channels/run.js +4 -0
  188. package/dist/lib/hot-channels/signals-pass.d.ts +74 -1
  189. package/dist/lib/hot-channels/signals-pass.js +82 -41
  190. package/dist/lib/hot-channels/signals-redo.js +10 -2
  191. package/dist/lib/install/claude-targets.d.ts +12 -1
  192. package/dist/lib/install/claude-targets.js +57 -5
  193. package/dist/lib/install/codex-targets.d.ts +2 -2
  194. package/dist/lib/install/codex-targets.js +36 -6
  195. package/dist/lib/install/hook-target.d.ts +3 -0
  196. package/dist/lib/install/hook-target.js +11 -0
  197. package/dist/lib/lanes/canonical-host.d.ts +35 -0
  198. package/dist/lib/lanes/canonical-host.js +65 -0
  199. package/dist/lib/lanes/host-capacity.d.ts +30 -0
  200. package/dist/lib/lanes/host-capacity.js +29 -3
  201. package/dist/lib/lanes/watcher.js +35 -0
  202. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  203. package/dist/lib/mesh/live/daemon/run.js +5 -2
  204. package/dist/lib/mesh/live/flush.d.ts +5 -1
  205. package/dist/lib/mesh/live/flush.js +12 -6
  206. package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
  207. package/dist/lib/mesh/live/reporting-privacy.js +56 -1
  208. package/dist/lib/mesh/live/spool.d.ts +7 -0
  209. package/dist/lib/mesh/live/spool.js +25 -0
  210. package/dist/lib/person-setting-cache.d.ts +38 -0
  211. package/dist/lib/person-setting-cache.js +98 -0
  212. package/dist/lib/safe-store.d.ts +245 -0
  213. package/dist/lib/safe-store.js +777 -0
  214. package/dist/lib/signals/engine.d.ts +29 -2
  215. package/dist/lib/signals/engine.js +103 -4
  216. package/dist/lib/signals/reply.js +73 -18
  217. package/dist/lib/signals/steps/adapters.js +7 -2
  218. package/dist/lib/signals/steps/extract.d.ts +13 -0
  219. package/dist/lib/signals/steps/extract.js +122 -6
  220. package/dist/main.js +46 -3
  221. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  222. package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
  223. package/dist/utils/auth-expiry.d.ts +8 -0
  224. package/dist/utils/auth-expiry.js +53 -0
  225. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  226. package/dist/utils/catalog-runtime-paths.js +53 -0
  227. package/dist/utils/cli-telemetry.d.ts +21 -0
  228. package/dist/utils/cli-telemetry.js +34 -0
  229. package/dist/utils/command-usage.d.ts +275 -0
  230. package/dist/utils/command-usage.js +797 -0
  231. package/dist/utils/files-browse-acl.js +1 -1
  232. package/dist/utils/hook-trust.d.ts +7 -0
  233. package/dist/utils/hook-trust.js +31 -4
  234. package/dist/utils/host-registration.d.ts +126 -0
  235. package/dist/utils/host-registration.js +378 -0
  236. package/dist/utils/resident-package-preload.js +2 -0
  237. package/package.json +10 -8
  238. package/scripts/bench-core.mjs +1096 -0
  239. package/scripts/check-function-manifest.mjs +702 -0
  240. package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
  241. package/dist/lib/delivery/workers/windows-boundary.js +0 -693
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Replay recorder: is it on, and how much does it hold?
3
+ *
4
+ * The recorder (`hq-hook record`, crates/hq-hook/src/recorder.rs) appends
5
+ * redacted hook events to `~/.hq/replay-recorder/` when the flag
6
+ * `core.replay-recorder` is on for the person or machine. It is off by default.
7
+ * This check reads the same three inputs the recorder reads (the kill switch
8
+ * variable, the kill switch file and the cached person flag snapshot) and the
9
+ * size of the store. It starts no process and makes no network call.
10
+ */
11
+ import * as fs from "node:fs";
12
+ import * as os from "node:os";
13
+ import * as path from "node:path";
14
+ import { FLAG_SNAPSHOT_MAX_AGE_MS } from "../../flag-snapshot-file.js";
15
+ export const REPLAY_RECORDER_FLAG = "core.replay-recorder";
16
+ export const REPLAY_RECORDER_KILL_ENV = "HQ_REPLAY_RECORDER";
17
+ export const REPLAY_RECORDER_MAX_BYTES_ENV = "HQ_REPLAY_RECORDER_MAX_BYTES";
18
+ const CHECK_ID = "replay-recorder.state";
19
+ const STORE_DISPLAY = "~/.hq/replay-recorder";
20
+ const DEFAULT_MAX_BYTES = 64 * 1024 * 1024;
21
+ const MIN_MAX_BYTES = 8 * 1024;
22
+ const MAX_MAX_BYTES = 1024 * 1024 * 1024;
23
+ /** `HQ_REPLAY_RECORDER` values that turn recording off, in any case. Mirrors `recorder::KILL_SWITCH_VALUES`. */
24
+ export const REPLAY_RECORDER_KILL_VALUES = ["off", "0", "false", "no", "disabled"];
25
+ function storeDir(home) {
26
+ return path.join(home, ".hq", "replay-recorder");
27
+ }
28
+ /** One snapshot file, when it is for the person scope and fresh. */
29
+ function readPersonSnapshot(file, now) {
30
+ let parsed;
31
+ try {
32
+ parsed = JSON.parse(fs.readFileSync(file, "utf8"));
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
38
+ return null;
39
+ const value = parsed;
40
+ if (Object.keys(value).sort().join(",") !== "fetched_at,flags,scope" || value.scope !== "person")
41
+ return null;
42
+ if (typeof value.fetched_at !== "string")
43
+ return null;
44
+ const fetchedAt = Date.parse(value.fetched_at);
45
+ const age = now - fetchedAt;
46
+ if (!Number.isFinite(age) || age < 0 || age > FLAG_SNAPSHOT_MAX_AGE_MS)
47
+ return null;
48
+ const flags = value.flags;
49
+ if (!flags || typeof flags !== "object" || Array.isArray(flags))
50
+ return null;
51
+ return { fetchedAt, flags: flags };
52
+ }
53
+ /**
54
+ * The snapshot the CLI writes in its private temporary folder when it cannot
55
+ * write the cache folder (`fallbackPersonSnapshotPath` in
56
+ * `flag-snapshot-file.ts`). Only a folder chain this user owns and nobody else
57
+ * can enter is read.
58
+ */
59
+ function fallbackPersonSnapshotFile(tmpdir) {
60
+ if (typeof process.getuid !== "function")
61
+ return null;
62
+ const uid = process.getuid();
63
+ const root = path.join(tmpdir, `hq-cli-flag-snapshots-${uid}`);
64
+ const directories = [root, path.join(root, "hq"), path.join(root, "hq", "flags")];
65
+ for (const directory of directories) {
66
+ try {
67
+ const stat = fs.lstatSync(directory);
68
+ if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== uid)
69
+ return null;
70
+ if ((stat.mode & 0o077) !== 0)
71
+ return null;
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ return path.join(root, "hq", "flags", "snapshot-person.json");
78
+ }
79
+ /**
80
+ * Same rule as `flags::person_flag_enabled` in the engine: the newer valid one
81
+ * of the cache snapshot and the permission-fallback snapshot decides, and the
82
+ * flag is on only as the boolean `true`. Equal timestamps keep the cache file.
83
+ */
84
+ function personFlagOn(home, env, now, tmpdir) {
85
+ const cacheHome = env.XDG_CACHE_HOME || path.join(home, ".cache");
86
+ const primary = readPersonSnapshot(path.join(cacheHome, "hq", "flags", "snapshot-person.json"), now);
87
+ const fallbackFile = fallbackPersonSnapshotFile(tmpdir);
88
+ const fallback = fallbackFile ? readPersonSnapshot(fallbackFile, now) : null;
89
+ const chosen = primary && fallback ? (fallback.fetchedAt > primary.fetchedAt ? fallback : primary) : (primary ?? fallback);
90
+ return chosen?.flags[REPLAY_RECORDER_FLAG] === true;
91
+ }
92
+ function hasRepoOrHqMarkerAbove(directory) {
93
+ let current = directory;
94
+ for (;;) {
95
+ if (fs.existsSync(path.join(current, ".git")))
96
+ return true;
97
+ try {
98
+ if (fs.statSync(path.join(current, "core", "core.yaml")).isFile())
99
+ return true;
100
+ }
101
+ catch {
102
+ // No HQ root marker at this level.
103
+ }
104
+ const parent = path.dirname(current);
105
+ if (parent === current)
106
+ return false;
107
+ current = parent;
108
+ }
109
+ }
110
+ /**
111
+ * The store path as written, and where it really is: a symlinked parent
112
+ * (`~/.hq` pointing into a checkout) hides the checkout from a walk over the
113
+ * written path, so the nearest ancestor that exists is resolved and walked too.
114
+ */
115
+ function insideRepoOrHqTree(directory) {
116
+ if (hasRepoOrHqMarkerAbove(directory))
117
+ return true;
118
+ let current = path.dirname(directory);
119
+ for (;;) {
120
+ try {
121
+ return hasRepoOrHqMarkerAbove(fs.realpathSync(current));
122
+ }
123
+ catch {
124
+ // This ancestor does not exist yet; try the one above it.
125
+ }
126
+ const parent = path.dirname(current);
127
+ if (parent === current)
128
+ return false;
129
+ current = parent;
130
+ }
131
+ }
132
+ /** Why the recorder is off, or `null` when it is recording. Mirrors `recorder::gate`. */
133
+ export function replayRecorderOffReason(probe = {}) {
134
+ const env = probe.env ?? process.env;
135
+ const home = probe.home ?? os.homedir();
136
+ if (REPLAY_RECORDER_KILL_VALUES.includes((env[REPLAY_RECORDER_KILL_ENV] ?? "").trim().toLowerCase())) {
137
+ return "kill-switch-env";
138
+ }
139
+ // The recorder records only on Unix until US-022, whatever the flag says.
140
+ if ((probe.platform ?? process.platform) === "win32")
141
+ return "off-on-windows";
142
+ if (fs.existsSync(path.join(home, ".hq", "replay-recorder.off")))
143
+ return "kill-switch-file";
144
+ if (!personFlagOn(home, env, probe.now ?? Date.now(), probe.tmpdir ?? os.tmpdir()))
145
+ return "flag-off";
146
+ if (insideRepoOrHqTree(storeDir(home)))
147
+ return "store-inside-repo";
148
+ if (storeDirNotPrivate(storeDir(home)))
149
+ return "store-not-private";
150
+ return null;
151
+ }
152
+ /**
153
+ * An existing store folder owned by another user, or one group or others can
154
+ * write to. The recorder refuses it and leaves its permissions as they are.
155
+ * Unix only, as in the recorder.
156
+ */
157
+ function storeDirNotPrivate(store) {
158
+ if (typeof process.getuid !== "function")
159
+ return false;
160
+ let stat;
161
+ try {
162
+ stat = fs.lstatSync(store);
163
+ }
164
+ catch {
165
+ return false;
166
+ }
167
+ return stat.isDirectory() && (stat.uid !== process.getuid() || (stat.mode & 0o022) !== 0);
168
+ }
169
+ /** Segment count and total size of the store. An absent store holds nothing. */
170
+ export function readReplayRecorderStore(home = os.homedir()) {
171
+ const store = { segments: 0, bytes: 0 };
172
+ let names;
173
+ try {
174
+ names = fs.readdirSync(storeDir(home));
175
+ }
176
+ catch {
177
+ return store;
178
+ }
179
+ for (const name of names) {
180
+ if (!/^segment-\d+\.jsonl$/.test(name))
181
+ continue;
182
+ try {
183
+ const stat = fs.statSync(path.join(storeDir(home), name));
184
+ if (!stat.isFile())
185
+ continue;
186
+ store.segments += 1;
187
+ store.bytes += stat.size;
188
+ }
189
+ catch {
190
+ // A segment removed by a rotation while this check ran.
191
+ }
192
+ }
193
+ return store;
194
+ }
195
+ function capBytes(env) {
196
+ const raw = (env[REPLAY_RECORDER_MAX_BYTES_ENV] ?? "").trim();
197
+ if (!/^\d+$/.test(raw))
198
+ return DEFAULT_MAX_BYTES;
199
+ return Math.min(MAX_MAX_BYTES, Math.max(MIN_MAX_BYTES, Number(raw)));
200
+ }
201
+ function megabytes(bytes) {
202
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
203
+ }
204
+ const OFF_TEXT = {
205
+ "kill-switch-env": `${REPLAY_RECORDER_KILL_ENV} is set to turn it off`,
206
+ "kill-switch-file": "~/.hq/replay-recorder.off exists",
207
+ "flag-off": `flag ${REPLAY_RECORDER_FLAG} is not on for this person or machine`,
208
+ "store-inside-repo": "the home directory, or the folder ~/.hq links to, is inside a git checkout or an HQ tree",
209
+ "store-not-private": `${STORE_DISPLAY} is owned by another user or writable by group or others`,
210
+ "off-on-windows": "off on Windows until US-022",
211
+ };
212
+ export function checkReplayRecorder(probe = {}) {
213
+ const env = probe.env ?? process.env;
214
+ const home = probe.home ?? os.homedir();
215
+ const reason = replayRecorderOffReason({ ...probe, env, home });
216
+ const store = readReplayRecorderStore(home);
217
+ const cap = capBytes(env);
218
+ const holds = store.segments === 0
219
+ ? "It holds nothing."
220
+ : `It holds ${store.segments} segment${store.segments === 1 ? "" : "s"}, ${megabytes(store.bytes)} of a ${megabytes(cap)} cap.`;
221
+ const details = {
222
+ enabled: reason === null,
223
+ reason: reason ?? "on",
224
+ segments: store.segments,
225
+ bytes: store.bytes,
226
+ capBytes: cap,
227
+ };
228
+ if (reason === null) {
229
+ return {
230
+ checkId: CHECK_ID,
231
+ status: "WARN",
232
+ target: STORE_DISPLAY,
233
+ message: `Replay recorder is on: hook events on this machine are redacted and recorded to ${STORE_DISPLAY}. ${holds}`,
234
+ details,
235
+ remediation: `To stop recording, set ${REPLAY_RECORDER_KILL_ENV}=off or create ~/.hq/replay-recorder.off. Delete ${STORE_DISPLAY} to remove what it holds.`,
236
+ };
237
+ }
238
+ if (store.segments > 0) {
239
+ return {
240
+ checkId: CHECK_ID,
241
+ status: "WARN",
242
+ target: STORE_DISPLAY,
243
+ message: `Replay recorder is off (${OFF_TEXT[reason]}), but an earlier recording is still on disk. ${holds}`,
244
+ details,
245
+ remediation: `Delete ${STORE_DISPLAY} when the recording is no longer needed.`,
246
+ };
247
+ }
248
+ return {
249
+ checkId: CHECK_ID,
250
+ status: "PASS",
251
+ target: STORE_DISPLAY,
252
+ message: `Replay recorder is off (${OFF_TEXT[reason]}). ${holds}`,
253
+ details,
254
+ };
255
+ }
256
+ export const replayRecorderFamily = {
257
+ id: "replay-recorder",
258
+ title: "Replay recorder",
259
+ run: async () => [checkReplayRecorder()],
260
+ };
261
+ //# sourceMappingURL=replay-recorder.js.map
@@ -32,6 +32,7 @@ import { releaseLinksFamily } from "./checks/release-links.js";
32
32
  import { cliPathFamily } from "./checks/cli-path.js";
33
33
  import { ps1ShimsFamily } from "./checks/ps1-shims.js";
34
34
  import { tempHomesFamily } from "./checks/temp-homes.js";
35
+ import { replayRecorderFamily } from "./checks/replay-recorder.js";
35
36
  import { fixtureCoverageFamily } from "./fixtures/discover.js";
36
37
  import { checkClaudeWiring } from "./checks/claude-wiring.js";
37
38
  /**
@@ -289,6 +290,9 @@ export function createDefaultRegistry() {
289
290
  // Idle tmp.* throwaway homes holding a Rust toolchain download. Dry-run
290
291
  // scan only; `hq doctor --sweep-temp-homes` is the delete path.
291
292
  registry.register(tempHomesFamily);
293
+ // Replay recorder (flag core.replay-recorder, off by default): whether hook
294
+ // events are being recorded on this machine and how much the store holds.
295
+ registry.register(replayRecorderFamily);
292
296
  return registry;
293
297
  }
294
298
  //# sourceMappingURL=registry.js.map
@@ -0,0 +1,239 @@
1
+ /**
2
+ * hq-environment-profile.v1: one profile per place that can do work (the
3
+ * local machine, an Outpost, a MicroVM, a bot, a fleet box), published as a
4
+ * company-scoped view.
5
+ *
6
+ * This module holds the TypeScript shape, and a loader that validates a
7
+ * document against src/schemas/hq-environment-profile.v1.schema.json and
8
+ * refuses any other schema_version. It reads; it does not write a profile and
9
+ * it does not match work to an environment.
10
+ *
11
+ * Failure text never contains a value taken from the document, apart from a
12
+ * shortened schema_version. A rejected field may be holding a credential, so
13
+ * issues carry the path, the rule that failed and at most a property name,
14
+ * and a property name is printed only when it looks like a plain field name.
15
+ */
16
+ import type { Availability } from "../capacity/available.js";
17
+ export declare const ENVIRONMENT_PROFILE_SCHEMA_VERSION = "hq-environment-profile.v1";
18
+ export declare const ENVIRONMENT_PROFILE_SCHEMA_ID = "urn:hq:schema:hq-environment-profile:v1";
19
+ export declare const ENVIRONMENT_PROFILE_SCHEMA_PATH: string;
20
+ export type EnvironmentKind = "local" | "outpost" | "microvm" | "bot" | "fleet-box";
21
+ export type EnvironmentState = "running" | "template" | "stopped";
22
+ export type EnvironmentEngine = "claude" | "codex" | "grok";
23
+ export type EnvironmentDispatchMethod = "lane-local" | "lane-ssm" | "lane-endpoint" | "dm" | "fleet-task";
24
+ export interface EnvironmentProvenance {
25
+ source: string;
26
+ /** true only when read from the live system at observed time. */
27
+ verified: boolean;
28
+ }
29
+ export interface EnvironmentTaint {
30
+ /** key:value; work tolerates it by listing the same string. */
31
+ key: string;
32
+ effect: "no-place" | "prefer-not";
33
+ reason: string;
34
+ }
35
+ export interface EnvironmentImage {
36
+ name: string;
37
+ version: string;
38
+ /** Registry or snapshot reference; null when the image is not built yet. */
39
+ ref: string | null;
40
+ contents?: string[];
41
+ }
42
+ export interface EnvironmentDeclared {
43
+ kind: EnvironmentKind;
44
+ /** kind:native-id. */
45
+ id: string;
46
+ aliases?: string[];
47
+ /** Companies this environment may do work for. */
48
+ companies: string[];
49
+ state: EnvironmentState;
50
+ lifecycle: {
51
+ type: "persistent" | "ephemeral";
52
+ /** 0 for a running environment; null when unknown. */
53
+ start_seconds_estimate: number | null;
54
+ provenance?: EnvironmentProvenance;
55
+ };
56
+ limits: {
57
+ vcpu?: number | null;
58
+ memory_mb?: number | null;
59
+ disk_gb?: number | null;
60
+ max_concurrent?: number | null;
61
+ /** Hard ceiling on one run. null means no ceiling. */
62
+ max_run_seconds: number | null;
63
+ workspace_survives: boolean;
64
+ provenance?: EnvironmentProvenance;
65
+ };
66
+ /** key:value labels, for example os:macos, tool:git, engine:claude. */
67
+ labels: string[];
68
+ image?: EnvironmentImage | null;
69
+ dispatch: {
70
+ method: EnvironmentDispatchMethod;
71
+ target?: string;
72
+ /** false when the method is proposed and not built. */
73
+ exists_today: boolean;
74
+ };
75
+ cost: {
76
+ model: "owned" | "fixed" | "metered";
77
+ marginal_usd_per_hour: number | null;
78
+ fixed_usd_per_month?: number | null;
79
+ suspend_usd_per_hour?: number | null;
80
+ basis?: string;
81
+ provenance: EnvironmentProvenance;
82
+ };
83
+ taints: EnvironmentTaint[];
84
+ }
85
+ /** Carried by every reading. */
86
+ export interface EnvironmentReadingMeta {
87
+ /** RFC 3339 date-time. */
88
+ observed_at: string;
89
+ ttl_seconds: number;
90
+ source: string;
91
+ }
92
+ export interface EnvironmentComputeReading extends EnvironmentReadingMeta {
93
+ vcpu_online: number;
94
+ load_1m?: number | null;
95
+ load_per_vcpu?: number | null;
96
+ mem_total_mb?: number;
97
+ mem_available_mb: number;
98
+ disk_total_gb?: number;
99
+ disk_free_gb: number;
100
+ }
101
+ export interface EnvironmentSlotsReading extends EnvironmentReadingMeta {
102
+ host_ref: {
103
+ kind: string;
104
+ id: string;
105
+ };
106
+ providers: Array<{
107
+ engine: EnvironmentEngine;
108
+ max_running: number;
109
+ max_queued?: number;
110
+ running: number;
111
+ queued: number;
112
+ }>;
113
+ queued_lanes?: number;
114
+ }
115
+ export interface EnvironmentAccountReading extends EnvironmentReadingMeta {
116
+ engine: EnvironmentEngine;
117
+ /** Lane-config account label. */
118
+ account_id: string;
119
+ provider_account_id?: string | null;
120
+ provider_account_join_verified?: boolean;
121
+ /** Company slug, "personal" or "unknown". */
122
+ owning_company: string;
123
+ owning_company_source?: string;
124
+ /**
125
+ * Who holds the login. An owner-held login may be used for any of the
126
+ * owner's businesses, so owning_company is a reporting and ranking input
127
+ * for it and not a filter. A login held by another person is never an
128
+ * account; it is an EnvironmentForeignAccount.
129
+ */
130
+ holder: "owner" | "unknown";
131
+ holder_source?: string;
132
+ /**
133
+ * Whether work may be paired with this login. true only when holder is
134
+ * "owner", enabled is true and signed_in is true.
135
+ */
136
+ usable: boolean;
137
+ /** Companies the owner explicitly designated; a record, not a limit. */
138
+ usable_for_companies?: string[];
139
+ enabled: boolean;
140
+ /** null when sources disagree or no reading exists. */
141
+ signed_in: boolean | null;
142
+ sign_in_evidence?: string[];
143
+ slots?: {
144
+ max_running?: number;
145
+ running?: number;
146
+ queued?: number;
147
+ quota_held?: boolean;
148
+ };
149
+ room: {
150
+ left_percent: number | null;
151
+ /** The hq-available-ai.v1 word, unchanged; null when there is no reading. */
152
+ availability: Availability | null;
153
+ back_at?: string | null;
154
+ tranche?: string;
155
+ usage_ref?: string | null;
156
+ observed_at: string | null;
157
+ ttl_seconds: number;
158
+ };
159
+ }
160
+ /**
161
+ * A login held by a person other than the owner: its existence, engine and
162
+ * holder only. It has no account id and is never paired with work.
163
+ */
164
+ export interface EnvironmentForeignAccount {
165
+ engine: EnvironmentEngine;
166
+ /** "other", or "other:<person-slug>" when the person is known. */
167
+ holder: string;
168
+ observed_at: string;
169
+ ttl_seconds: number;
170
+ source: string;
171
+ }
172
+ export interface EnvironmentAccessProbe extends EnvironmentReadingMeta {
173
+ /** kind:name, for example secret:NAME or repo:hq-pro. A name, never a value. */
174
+ name: string;
175
+ result: "pass" | "fail" | "unknown";
176
+ /** What the probe proves. */
177
+ checks: string;
178
+ }
179
+ export interface EnvironmentBaseReadiness extends EnvironmentReadingMeta {
180
+ result: "ready" | "degraded" | "not-ready" | "unknown";
181
+ document_ref?: string | null;
182
+ }
183
+ export interface EnvironmentReadings {
184
+ compute?: EnvironmentComputeReading;
185
+ slots?: EnvironmentSlotsReading;
186
+ accounts: EnvironmentAccountReading[];
187
+ foreign_accounts: EnvironmentForeignAccount[];
188
+ access: EnvironmentAccessProbe[];
189
+ base_readiness?: EnvironmentBaseReadiness;
190
+ }
191
+ export interface EnvironmentProfile {
192
+ schema_version: typeof ENVIRONMENT_PROFILE_SCHEMA_VERSION;
193
+ view: {
194
+ company: string;
195
+ generated_at: string;
196
+ generated_by: string;
197
+ };
198
+ declared: EnvironmentDeclared;
199
+ readings: EnvironmentReadings;
200
+ notes?: string[];
201
+ }
202
+ export interface EnvironmentProfileIssue {
203
+ /** JSON pointer into the document; "" is the document itself. */
204
+ path: string;
205
+ message: string;
206
+ }
207
+ export type EnvironmentProfileFailureCode = "invalid_json" | "not_an_object" | "missing_schema_version" | "unsupported_schema_version" | "invalid";
208
+ export interface EnvironmentProfileSuccess {
209
+ ok: true;
210
+ profile: EnvironmentProfile;
211
+ }
212
+ export interface EnvironmentProfileFailure {
213
+ ok: false;
214
+ code: EnvironmentProfileFailureCode;
215
+ message: string;
216
+ /** At most ENVIRONMENT_PROFILE_MAX_ISSUES entries. */
217
+ issues: EnvironmentProfileIssue[];
218
+ /** How many further issues were found and not listed. */
219
+ issues_omitted: number;
220
+ }
221
+ export type EnvironmentProfileResult = EnvironmentProfileSuccess | EnvironmentProfileFailure;
222
+ /** RFC 3339 date-time with a real calendar date and in-range clock fields. */
223
+ export declare function isRfc3339DateTime(value: string): boolean;
224
+ /** At most this many issues are listed; the rest are counted. */
225
+ export declare const ENVIRONMENT_PROFILE_MAX_ISSUES = 100;
226
+ /**
227
+ * Validate a parsed document. The schema_version is checked first, so a
228
+ * document from a later major version is refused by name and is not reported
229
+ * as a list of field errors against the v1 schema.
230
+ *
231
+ * Beyond the schema, two rules are checked here because JSON Schema cannot
232
+ * express them: view.company is one of declared.companies, and no string is
233
+ * shaped like a credential. At most ENVIRONMENT_PROFILE_MAX_ISSUES issues are
234
+ * returned; issues_omitted counts the rest.
235
+ */
236
+ export declare function validateEnvironmentProfile(value: unknown): EnvironmentProfileResult;
237
+ /** Parse JSON text and validate it. The text is never echoed in a failure. */
238
+ export declare function parseEnvironmentProfile(text: string): EnvironmentProfileResult;
239
+ //# sourceMappingURL=profile.d.ts.map