@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
@@ -123,6 +123,15 @@ export declare function restartsForParent(opts: {
123
123
  managed?: boolean;
124
124
  host?: HostApp;
125
125
  }): boolean;
126
+ /**
127
+ * A parent starts the daemon again after it exits with TCC_EPERM_EXIT_CODE.
128
+ * Only the OS unit (launchd KeepAlive) restarts on any exit code; an app that
129
+ * hosts the daemon restarts it on RESTART_EXIT_CODE only.
130
+ */
131
+ export declare function restartsAfterTccEpermExit(opts: {
132
+ managed?: boolean;
133
+ host?: HostApp;
134
+ }): boolean;
126
135
  /**
127
136
  * The desktop app runs sync itself, so the daemon's sync unit waits. When the
128
137
  * app hosts the daemon it has handed sync over, and the daemon runs it.
@@ -30,9 +30,8 @@ import { assertPersonalServiceSessionCapability, readRemoteControlPoolsConfig, r
30
30
  import { loadLanesConfig } from "../lanes/config.js";
31
31
  import { daemonLanesReconcileHandler } from "../lanes/daemon-reconcile.js";
32
32
  import { ensureDaemonLanesReconcileHandler } from "./lanes-reconcile-loader.js";
33
- import { SUPERVISOR_HANDOFF_FLAG, readDaemonFlag } from "./flag.js";
34
- import { createBoundedDaemonFlagMonitor } from "./flag-monitor.js";
35
- import { DAEMON_CHILD_BOOTSTRAP_HANDOFF_WATCH_FLAG, DAEMON_LANES_RECONCILE_FILE_WATCH_FLAG, DAEMON_SEARCH_INDEX_RUNNER_OWNS_INDEX_FLAG, DAEMON_SYNC_PROCESS_SCAN_ON_MISSING_FLAG, } from "./kill-switch-flags.js";
33
+ import { SUPERVISOR_HANDOFF_FLAG, createDaemonFlagSnapshotSource, readDaemonFlag } from "./flag.js";
34
+ import { createDaemonKillSwitchMonitors } from "./timed-flag-monitors.js";
36
35
  import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
37
36
  import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
38
37
  import { readLegacySyncEnv } from "./legacy-sync-env.js";
@@ -47,6 +46,8 @@ import { updateAnywhereRuntimeRevocationMarker } from "../anywhere-runtime-revoc
47
46
  import { classifyWindowsTask, currentWindowsIdentity, daemonRootRefusal } from "./install.js";
48
47
  import { detectMachineType } from "./machine-type.js";
49
48
  import { appendPrivate, daemonPaths, ensurePrivateDir, openPrivateAppend } from "./paths.js";
49
+ import { SELF_CHECK_RESULT_FILE, readSelfCheckResult } from "./selfcheck.js";
50
+ import { createDaemonStateWriter, daemonStateFilePath, defaultDaemonStateFilePath, readVaultAccessManifest, selfCheckMachineChecks, } from "./state-file.js";
50
51
  import { hqdSocketPath } from "./protocol.js";
51
52
  import { startHqdServer, syncHqdEnabledMarker } from "./server.js";
52
53
  import { startHqdRuntimeListener } from "./anywhere-listener.js";
@@ -62,6 +63,7 @@ import { listSyncRunnerProcesses, readWatchRunnerOwnerStatus, SYNC_RUNNER_LEASE_
62
63
  import { STOP_ESCALATION_MS, SYNC_RUNNER_PERSIST_GRACE_MS, createSupervisor, planKey, } from "./supervisor.js";
63
64
  import { userToolDirs } from "./tools.js";
64
65
  import { logOffset, readLogSince, readUnitHolds, writeUnitHolds } from "./unit-holds.js";
66
+ import { createTccEpermGuard, TCC_EPERM_SENTRY_FINGERPRINT } from "./tcc-eperm.js";
65
67
  import { daemonRunGuard } from "./lanes-reconcile-guard.js";
66
68
  export const LOG_ROTATE_BYTES = 5 * 1024 * 1024;
67
69
  /** Exit code for "restart me": non-zero so every service manager relaunches (Windows tasks only restart on failure). */
@@ -490,6 +492,14 @@ export function desktopAppRunning(platform) {
490
492
  export function restartsForParent(opts) {
491
493
  return opts.managed === true || opts.host !== undefined;
492
494
  }
495
+ /**
496
+ * A parent starts the daemon again after it exits with TCC_EPERM_EXIT_CODE.
497
+ * Only the OS unit (launchd KeepAlive) restarts on any exit code; an app that
498
+ * hosts the daemon restarts it on RESTART_EXIT_CODE only.
499
+ */
500
+ export function restartsAfterTccEpermExit(opts) {
501
+ return opts.managed === true && opts.host === undefined;
502
+ }
493
503
  /**
494
504
  * The desktop app runs sync itself, so the daemon's sync unit waits. When the
495
505
  * app hosts the daemon it has handed sync over, and the daemon runs it.
@@ -896,20 +906,24 @@ export async function runDaemon(opts) {
896
906
  };
897
907
  const daemonSyncRunnerPids = new Set();
898
908
  let supervisor = null;
899
- const killSwitchMonitor = (flagKey) => createBoundedDaemonFlagMonitor({
900
- fallback: true,
901
- read: () => readDaemonFlag(flagKey, {
902
- env,
903
- fallback: true,
904
- localOverrideMode: "ignore",
905
- throwOnError: true,
906
- }),
907
- onReadError: (error) => log("warn", `could not read ${flagKey}; keeping its default-on behavior (${error instanceof Error ? error.name : "UnknownError"})`),
909
+ // One registry request per 30-second tick decides every timed daemon flag.
910
+ // The same request also refreshes the state file hooks read (state-file.ts).
911
+ const stateWriter = createDaemonStateWriter({
912
+ file: daemonStateFilePath(home, env),
913
+ defaultFile: defaultDaemonStateFilePath(home, env),
914
+ log,
915
+ readVaultAccess: () => {
916
+ const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
917
+ return readVaultAccessManifest(configured && fs.existsSync(configured) ? configured : undefined);
918
+ },
919
+ readMachineChecks: () => selfCheckMachineChecks(readSelfCheckResult(path.join(paths.root, SELF_CHECK_RESULT_FILE))),
908
920
  });
909
- const childBootstrapHandoffWatchFlag = killSwitchMonitor(DAEMON_CHILD_BOOTSTRAP_HANDOFF_WATCH_FLAG);
910
- const lanesReconcileFileWatchFlag = killSwitchMonitor(DAEMON_LANES_RECONCILE_FILE_WATCH_FLAG);
911
- const searchIndexRunnerOwnsIndexFlag = killSwitchMonitor(DAEMON_SEARCH_INDEX_RUNNER_OWNS_INDEX_FLAG);
912
- const syncProcessScanOnMissingFlag = killSwitchMonitor(DAEMON_SYNC_PROCESS_SCAN_ON_MISSING_FLAG);
921
+ const flagSnapshots = createDaemonFlagSnapshotSource({ onRead: stateWriter.onRegistryRead });
922
+ const killSwitches = createDaemonKillSwitchMonitors({ env, log, snapshots: flagSnapshots });
923
+ const childBootstrapHandoffWatchFlag = killSwitches.childBootstrapHandoffWatch;
924
+ const lanesReconcileFileWatchFlag = killSwitches.lanesReconcileFileWatch;
925
+ const searchIndexRunnerOwnsIndexFlag = killSwitches.searchIndexRunnerOwnsIndex;
926
+ const syncProcessScanOnMissingFlag = killSwitches.syncProcessScanOnMissing;
913
927
  let laneReconcileWatcher = null;
914
928
  let laneReconcileWatcherRoot = null;
915
929
  let laneReconcileWatchFailedRoot = null;
@@ -936,10 +950,9 @@ export async function runDaemon(opts) {
936
950
  laneReconcileWatcher?.close();
937
951
  laneReconcileWatcher = null;
938
952
  laneReconcileWatcherRoot = null;
939
- childBootstrapHandoffWatchFlag.close();
940
- lanesReconcileFileWatchFlag.close();
941
- searchIndexRunnerOwnsIndexFlag.close();
942
- syncProcessScanOnMissingFlag.close();
953
+ killSwitches.close();
954
+ flagSnapshots.close();
955
+ stateWriter.close();
943
956
  };
944
957
  const plan = () => {
945
958
  const config = readDaemonConfig(paths.configPath);
@@ -1435,6 +1448,22 @@ export async function runDaemon(opts) {
1435
1448
  env,
1436
1449
  onError: (name) => log("warn", `hqd person setting read failed (${name}); keeping the last read value for up to ${HQD_PERSON_SETTING_GRACE_MS / 60_000} minutes`),
1437
1450
  }), { graceMs: HQD_PERSON_SETTING_GRACE_MS });
1451
+ // macOS can stop granting this process access to the HQ folder (TCC) after
1452
+ // HQ.app replaces its bundle. A fresh process gets access again, so trip,
1453
+ // report once, and exit for launchd's KeepAlive to start a new daemon.
1454
+ let daemonStopping = false;
1455
+ let tccEpermExit = () => { };
1456
+ let hqdRootForGuard;
1457
+ const tccEpermGuard = createTccEpermGuard({
1458
+ hqRoot: () => hqdRootForGuard,
1459
+ platform,
1460
+ daemonDir: paths.root,
1461
+ restartable: restartsAfterTccEpermExit(opts),
1462
+ isStopping: () => daemonStopping,
1463
+ log,
1464
+ report: reportTccEperm,
1465
+ exit: (code) => tccEpermExit(code),
1466
+ });
1438
1467
  const hqdListener = await startHqdRuntimeListener({
1439
1468
  isEnabled: async () => refreshHqdRuntimeDecision(async () => shouldStartHqd(await anywhereRuntimeAllowed(env, {
1440
1469
  refreshFlag: async () => {
@@ -1445,13 +1474,17 @@ export async function runDaemon(opts) {
1445
1474
  })), home, env, (error) => log("warn", `hqd runtime marker update failed: ${error.message ?? String(error)}`), (enabled) => syncHqdEnabledMarker(hqdSocketPath(home, env), enabled)),
1446
1475
  startServer: async () => {
1447
1476
  const startConfig = readDaemonConfig(paths.configPath);
1477
+ const hqRoot = startConfig.hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
1478
+ hqdRootForGuard = hqRoot;
1448
1479
  return startHqdServer({
1449
1480
  socketPath: hqdSocketPath(home, env),
1450
1481
  registryPath: registryFile(registryDir(home, env)),
1451
- hqRoot: startConfig.hqRoot ?? (env.HQ_ROOT?.trim() || undefined),
1482
+ hqRoot,
1452
1483
  log,
1484
+ flagSnapshots,
1453
1485
  onShutdown: () => hqdShutdown?.(),
1454
1486
  reportError: reportHqdCrash,
1487
+ observeError: (err) => tccEpermGuard.observe(err),
1455
1488
  });
1456
1489
  },
1457
1490
  onServerChange: (server) => {
@@ -1480,6 +1513,8 @@ export async function runDaemon(opts) {
1480
1513
  if (stopping)
1481
1514
  return;
1482
1515
  stopping = true;
1516
+ daemonStopping = true;
1517
+ tccEpermGuard.dispose();
1483
1518
  log("info", `${why}; stopping services`);
1484
1519
  closeHqd();
1485
1520
  closeRuntimeWatchers();
@@ -1509,6 +1544,8 @@ export async function runDaemon(opts) {
1509
1544
  if (stopping)
1510
1545
  return;
1511
1546
  stopping = true;
1547
+ daemonStopping = true;
1548
+ tccEpermGuard.dispose();
1512
1549
  closeHqd();
1513
1550
  closeRuntimeWatchers();
1514
1551
  const released = supervisor.release();
@@ -1569,6 +1606,7 @@ export async function runDaemon(opts) {
1569
1606
  });
1570
1607
  };
1571
1608
  hqdShutdown = () => shutdown("hqd shutdown request");
1609
+ tccEpermExit = (code) => shutdown("macOS refused file access under the HQ root; exiting so launchd starts a fresh daemon", code);
1572
1610
  process.on("SIGTERM", () => shutdown("received SIGTERM"));
1573
1611
  process.on("SIGINT", () => shutdown("received SIGINT"));
1574
1612
  if (platform !== "win32")
@@ -1592,6 +1630,26 @@ export async function runDaemon(opts) {
1592
1630
  }
1593
1631
  });
1594
1632
  }
1633
+ /** Report one macOS file-access trip under a fixed fingerprint (counts only, no paths), then flush before the exit. */
1634
+ async function reportTccEperm(event) {
1635
+ try {
1636
+ const { Sentry, preloadSentrySdk } = await import("../../sentry.js");
1637
+ preloadSentrySdk();
1638
+ Sentry.withScope((scope) => {
1639
+ scope.setLevel("error");
1640
+ scope.setFingerprint([...TCC_EPERM_SENTRY_FINGERPRINT]);
1641
+ scope.setTag("component", "hqd");
1642
+ scope.setTag("hqd.event", event.event);
1643
+ scope.setTag("hqd.tcc_eperm.decision", event.decision);
1644
+ scope.setContext("hqd_tcc_eperm", { ...event });
1645
+ Sentry.captureMessage("hqd lost file access under the HQ root (macOS EPERM)");
1646
+ });
1647
+ await Sentry.flush(2_000);
1648
+ }
1649
+ catch (err) {
1650
+ process.stderr.write(`hqd could not report the file access failure: ${String(err)}\n`);
1651
+ }
1652
+ }
1595
1653
  /** Report an hqd op crash to the CLI's existing Sentry integration, tagged with the failing op. */
1596
1654
  function reportHqdCrash(op, err) {
1597
1655
  void import("../../sentry.js").then(({ Sentry }) => {
@@ -8,6 +8,7 @@
8
8
  * units are affected, naming every affected vault in that one DM. The 16-hour outage of 2026-11-03 was
9
9
  * found by hand; this makes the next one reach the owner.
10
10
  */
11
+ import { type StoreFileWriteOptions } from "./paths.js";
11
12
  import type { DaemonState, PersistedHolds } from "./supervisor.js";
12
13
  /** An engine unit that has been held or failing this long needs a person. */
13
14
  export declare const ATTENTION_AFTER_MS: number;
@@ -31,6 +32,25 @@ export interface SelfCheckRecord {
31
32
  }
32
33
  export declare function readSelfCheckRecord(file: string): SelfCheckRecord | null;
33
34
  export declare function writeSelfCheckRecord(file: string, record: SelfCheckRecord): void;
35
+ /**
36
+ * What the latest self-check run found, written on every run whether or not a
37
+ * DM was sent. The DM record above only changes when a DM goes out, so it
38
+ * cannot say that a machine is healthy or has recovered; this can.
39
+ */
40
+ export declare const SELF_CHECK_RESULT_FILE = "selfcheck-result.json";
41
+ export interface SelfCheckResult {
42
+ checkedAt: number;
43
+ /** Engine units needing attention at that time. */
44
+ problems: number;
45
+ }
46
+ /**
47
+ * The latest result, or null. A file that is a symlink, has another link, is
48
+ * not this user's, or that group or others can write is not read: its value
49
+ * reaches the state file hooks trust.
50
+ */
51
+ export declare function readSelfCheckResult(file: string): SelfCheckResult | null;
52
+ /** Written atomically through src/lib/safe-store.ts in the daemon's private folder; a link at the path is replaced, never written through. */
53
+ export declare function writeSelfCheckResult(file: string, result: SelfCheckResult, options?: StoreFileWriteOptions): void;
34
54
  /**
35
55
  * Send now: something is wrong and this machine has not sent a self-check DM
36
56
  * in the last day. Which units are affected does not matter, so units that
@@ -48,6 +68,8 @@ export interface SelfCheckDeps {
48
68
  statePath: string;
49
69
  holdsPath: string;
50
70
  recordPath: string;
71
+ /** Where the latest run's result is written, for the daemon's state file. Not written when omitted. */
72
+ resultPath?: string;
51
73
  now: () => number;
52
74
  machine: string;
53
75
  readState: () => DaemonState | null;
@@ -11,7 +11,7 @@
11
11
  import * as fs from "node:fs";
12
12
  import * as path from "node:path";
13
13
  import { syncCoreUnitId } from "../sync-core/engine-home.js";
14
- import { ensurePrivateDir } from "./paths.js";
14
+ import { ensurePrivateDir, readStoreFile, writeStoreFile } from "./paths.js";
15
15
  /** An engine unit that has been held or failing this long needs a person. */
16
16
  export const ATTENTION_AFTER_MS = 30 * 60_000;
17
17
  /** This machine sends at most one self-check DM per this long. */
@@ -96,6 +96,37 @@ export function writeSelfCheckRecord(file, record) {
96
96
  fs.writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\n`, { mode: 0o600 });
97
97
  fs.renameSync(tmp, file);
98
98
  }
99
+ /**
100
+ * What the latest self-check run found, written on every run whether or not a
101
+ * DM was sent. The DM record above only changes when a DM goes out, so it
102
+ * cannot say that a machine is healthy or has recovered; this can.
103
+ */
104
+ export const SELF_CHECK_RESULT_FILE = "selfcheck-result.json";
105
+ /**
106
+ * The latest result, or null. A file that is a symlink, has another link, is
107
+ * not this user's, or that group or others can write is not read: its value
108
+ * reaches the state file hooks trust.
109
+ */
110
+ export function readSelfCheckResult(file) {
111
+ const read = readStoreFile(file, 4096);
112
+ if (!read)
113
+ return null;
114
+ try {
115
+ const parsed = JSON.parse(read.text);
116
+ if (typeof parsed.checkedAt !== "number" || !Number.isFinite(parsed.checkedAt))
117
+ return null;
118
+ if (typeof parsed.problems !== "number" || !Number.isInteger(parsed.problems) || parsed.problems < 0)
119
+ return null;
120
+ return { checkedAt: parsed.checkedAt, problems: parsed.problems };
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ }
126
+ /** Written atomically through src/lib/safe-store.ts in the daemon's private folder; a link at the path is replaced, never written through. */
127
+ export function writeSelfCheckResult(file, result, options = {}) {
128
+ writeStoreFile(file, `${JSON.stringify(result)}\n`, { create: true, ...options });
129
+ }
99
130
  /**
100
131
  * Send now: something is wrong and this machine has not sent a self-check DM
101
132
  * in the last day. Which units are affected does not matter, so units that
@@ -127,6 +158,14 @@ vaultName = () => undefined) {
127
158
  export async function runSelfCheck(deps) {
128
159
  const now = deps.now();
129
160
  const problems = engineUnitsNeedingAttention(deps.readState(), deps.readHolds(), now, deps.wanted);
161
+ if (deps.resultPath) {
162
+ try {
163
+ writeSelfCheckResult(deps.resultPath, { checkedAt: now, problems: problems.length });
164
+ }
165
+ catch (error) {
166
+ deps.log(`sync engine self-check: could not record this run's result (${error.code ?? "error"})`);
167
+ }
168
+ }
130
169
  if (problems.length === 0) {
131
170
  deps.log("sync engine self-check: every engine unit is healthy");
132
171
  return "healthy";
@@ -12,7 +12,7 @@ export { createResolver };
12
12
  import { SessionRegistry } from "./session-registry.js";
13
13
  import { HqMcpBridge, type RunWorkerRequest } from "./ops/mcp.js";
14
14
  import { type StdinMachineCredentials } from "./machine-login.js";
15
- import { type ReadDaemonFlagOptions } from "./flag.js";
15
+ import type { DaemonFlagSnapshotSource, ReadDaemonFlagOptions } from "./flag.js";
16
16
  import { type WindowsPipeAclReport, type WindowsPipeHost } from "./windows-pipe-host.js";
17
17
  export interface HqdServerOptions {
18
18
  socketPath: string;
@@ -45,6 +45,8 @@ export interface HqdServerOptions {
45
45
  runtimeFlagReader?: (options: ReadDaemonFlagOptions) => Promise<boolean>;
46
46
  /** Test seam for the human opt-in setting; production reads hq-pro. */
47
47
  personSettingReader?: () => Promise<boolean | null>;
48
+ /** The daemon's shared flag read, so this server's runtime gate adds no registry request of its own. */
49
+ flagSnapshots?: DaemonFlagSnapshotSource;
48
50
  /** Test seam for the hosted Streamable HTTP MCP transport. */
49
51
  mcpBridge?: HqMcpBridge;
50
52
  /** Test seam for machine login while keeping production credentials off disk. */
@@ -55,6 +57,8 @@ export interface HqdServerOptions {
55
57
  workerDispatch?: (request: RunWorkerRequest, hqRoot: string, env: NodeJS.ProcessEnv, now: Date) => Promise<Record<string, unknown>>;
56
58
  /** Crash reporter for internal op failures (US-012); run.ts wires Sentry here. */
57
59
  reportError?: (op: string, err: unknown) => void;
60
+ /** Sees every op failure before it is classified; run.ts watches it for macOS EPERM under the HQ root (tcc-eperm.ts). */
61
+ observeError?: (err: unknown) => void;
58
62
  }
59
63
  export interface HqdServer {
60
64
  socketPath: string;
@@ -26,9 +26,7 @@ import { authenticateMachineCredentials, machineTokenExpiresAt, MachineLoginErro
26
26
  import { HQ_MCP_TOOL_NAMES, HQD_NATIVE_TOOL_NAMES } from "../mcp/tools.js";
27
27
  import { HQ_ANYWHERE_RUNTIME_FLAG } from "../../commands/anywhere-runtime-flag.js";
28
28
  import { updateAnywhereRuntimeRevocationMarker } from "../anywhere-runtime-revocation-marker.js";
29
- import { readHqAnywherePersonSetting } from "../anywhere-person-setting.js";
30
- import { createBoundedDaemonFlagMonitor } from "./flag-monitor.js";
31
- import { readDaemonFlag } from "./flag.js";
29
+ import { createHqdRuntimeFlagMonitor } from "./timed-flag-monitors.js";
32
30
  import { startWindowsPipeHost, validateWindowsPipeAcl, WINDOWS_PIPE_STARTUP_REFUSAL } from "./windows-pipe-host.js";
33
31
  // The allowlist is deliberately read-only. A newly added hosted MCP tool must
34
32
  // pass hq.policy_check until it is explicitly reviewed as read-only here.
@@ -306,7 +304,15 @@ export async function startHqdServer(opts) {
306
304
  const startedAtMs = (opts.now ?? (() => new Date()))().getTime();
307
305
  const sessions = new SessionRegistry(opts.now);
308
306
  const log = opts.log ?? (() => { });
309
- const resolve = createResolver(opts.registryPath ?? registryFile(), { hqRoot: opts.hqRoot, log });
307
+ const observeError = (err) => {
308
+ try {
309
+ opts.observeError?.(err);
310
+ }
311
+ catch (observeErr) {
312
+ log("warn", `hqd error observer failed: ${observeErr.message}`);
313
+ }
314
+ };
315
+ const resolve = createResolver(opts.registryPath ?? registryFile(), { hqRoot: opts.hqRoot, log, onFsError: observeError });
310
316
  const clock = opts.now ?? (() => new Date());
311
317
  const env = opts.env ?? process.env;
312
318
  const policyIndex = opts.hqRoot ? new PolicyIndex(opts.hqRoot, log) : null;
@@ -387,25 +393,12 @@ export async function startHqdServer(opts) {
387
393
  }
388
394
  }
389
395
  }
390
- const runtimeFlagMonitor = opts.mcpEnabled ? undefined : createBoundedDaemonFlagMonitor({
391
- read: async () => {
392
- const options = {
393
- env,
394
- throwOnError: true,
395
- // A local opt-out is honored, while a local opt-in cannot override the operator kill switch.
396
- localOverrideMode: "off-only",
397
- };
398
- const flagEnabled = await (opts.runtimeFlagReader
399
- ? opts.runtimeFlagReader(options)
400
- : readDaemonFlag(HQ_ANYWHERE_RUNTIME_FLAG, options));
401
- if (!flagEnabled)
402
- return false;
403
- const personSetting = await (opts.personSettingReader ?? (() => readHqAnywherePersonSetting({
404
- env,
405
- onError: (name) => log("warn", `hqd person setting refresh failed (${name}); keeping HQ Anywhere off`),
406
- })))();
407
- return personSetting === true;
408
- },
396
+ const runtimeFlagMonitor = opts.mcpEnabled ? undefined : createHqdRuntimeFlagMonitor({
397
+ env,
398
+ log,
399
+ ...(opts.flagSnapshots ? { snapshots: opts.flagSnapshots } : {}),
400
+ ...(opts.runtimeFlagReader ? { runtimeFlagReader: opts.runtimeFlagReader } : {}),
401
+ ...(opts.personSettingReader ? { personSettingReader: opts.personSettingReader } : {}),
409
402
  onChange: (enabled) => {
410
403
  try {
411
404
  updateAnywhereRuntimeRevocationMarker(enabled, env.HOME?.trim() || undefined, env);
@@ -717,6 +710,7 @@ export async function startHqdServer(opts) {
717
710
  }
718
711
  };
719
712
  const fail = (err) => {
713
+ observeError(err);
720
714
  const error = err instanceof OpError ||
721
715
  err instanceof PolicyOpError ||
722
716
  err instanceof JournalOpError ||
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The switch for the daemon's state file (state-file.ts, hq-core-rust US-009).
3
+ * Default ON: with nothing configured the daemon writes the state file and
4
+ * the hook engine reads it, exactly as #2624 shipped.
5
+ *
6
+ * Off when any of these says off (the first one found wins):
7
+ * - env `HQ_FLAG_DAEMON_STATE_FILE=false` (also `0`, `off`, `no`), the
8
+ * CLI's local flag override (`HQ_FLAG_<KEY>`); `true` keeps it on and
9
+ * skips the remaining checks except the off file;
10
+ * - the file `~/.hq/daemon-state-file.off` (any file or link at that path);
11
+ * - flag `daemon-state-file` is `false` in the offline flag snapshot
12
+ * (readDefaultOnFlagSnapshot: a default-on kill switch) or in the flag
13
+ * registry answer the daemon just received.
14
+ *
15
+ * Off means: the daemon writes no hq-state.json and no self-check result for
16
+ * it, the daemon folder is not refused for being a link or another user's
17
+ * (ensurePrivateDir falls back to its behavior before #2624), and the engine
18
+ * (crates/hq-hook/src/state.rs, which reads the same env var, file and
19
+ * snapshot flag) does not read the state file.
20
+ *
21
+ * Where the two sides differ (each difference only ever leads to "no fresh
22
+ * state file, use the flag snapshot", so neither can turn the file on):
23
+ * - Scope: with no company uid, the daemon's snapshot read scans every
24
+ * company's snapshot and the person snapshot, so a `false` in any of them
25
+ * stops the writer. The engine reads only the snapshot of its own
26
+ * HQ_COMPANY_UID (or the person snapshot).
27
+ * - Age: the daemon keeps a snapshot `false` however old it is; the engine
28
+ * uses snapshots up to 24 h old.
29
+ * - Registry only: when the switch is turned off only by the registry flag
30
+ * (no env var, no off file, and the hook's snapshot does not hold `false`
31
+ * yet), the engine cannot see it. The daemon removes its own state file
32
+ * when it first sees the switch off (state-file.ts
33
+ * removeDaemonStateFile); if that removal is refused, the engine keeps
34
+ * reading the last file until it expires (600 s, at most 660 s).
35
+ *
36
+ * Read only: nothing here writes a flag.
37
+ */
38
+ export declare const DAEMON_STATE_FILE_FLAG = "daemon-state-file";
39
+ /** The local override, named as the CLI names every `HQ_FLAG_<KEY>` override. */
40
+ export declare const DAEMON_STATE_FILE_ENV = "HQ_FLAG_DAEMON_STATE_FILE";
41
+ /** Under the home folder; any file or link here turns the state file off on this machine. */
42
+ export declare const DAEMON_STATE_FILE_OFF_FILE: string;
43
+ export type DaemonStateFileOffReason = "env" | "file" | "flag";
44
+ export interface DaemonStateFileSwitchOptions {
45
+ env?: NodeJS.ProcessEnv;
46
+ /** Home folder for the off file. Default: HOME (USERPROFILE on Windows), else os.homedir(). */
47
+ home?: string;
48
+ /** The flag value from a registry answer the caller already has (the daemon's poll). */
49
+ registryValue?: unknown;
50
+ /** Replaces the offline snapshot read (tests). */
51
+ readSnapshot?: (env: NodeJS.ProcessEnv) => boolean;
52
+ }
53
+ /** Why the state file is off, or null while it is on (the default). */
54
+ export declare function daemonStateFileOffReason(options?: DaemonStateFileSwitchOptions): DaemonStateFileOffReason | null;
55
+ /** True unless something turns the state file off (see the module comment). */
56
+ export declare function daemonStateFileEnabled(options?: DaemonStateFileSwitchOptions): boolean;
57
+ //# sourceMappingURL=state-file-switch.d.ts.map
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The switch for the daemon's state file (state-file.ts, hq-core-rust US-009).
3
+ * Default ON: with nothing configured the daemon writes the state file and
4
+ * the hook engine reads it, exactly as #2624 shipped.
5
+ *
6
+ * Off when any of these says off (the first one found wins):
7
+ * - env `HQ_FLAG_DAEMON_STATE_FILE=false` (also `0`, `off`, `no`), the
8
+ * CLI's local flag override (`HQ_FLAG_<KEY>`); `true` keeps it on and
9
+ * skips the remaining checks except the off file;
10
+ * - the file `~/.hq/daemon-state-file.off` (any file or link at that path);
11
+ * - flag `daemon-state-file` is `false` in the offline flag snapshot
12
+ * (readDefaultOnFlagSnapshot: a default-on kill switch) or in the flag
13
+ * registry answer the daemon just received.
14
+ *
15
+ * Off means: the daemon writes no hq-state.json and no self-check result for
16
+ * it, the daemon folder is not refused for being a link or another user's
17
+ * (ensurePrivateDir falls back to its behavior before #2624), and the engine
18
+ * (crates/hq-hook/src/state.rs, which reads the same env var, file and
19
+ * snapshot flag) does not read the state file.
20
+ *
21
+ * Where the two sides differ (each difference only ever leads to "no fresh
22
+ * state file, use the flag snapshot", so neither can turn the file on):
23
+ * - Scope: with no company uid, the daemon's snapshot read scans every
24
+ * company's snapshot and the person snapshot, so a `false` in any of them
25
+ * stops the writer. The engine reads only the snapshot of its own
26
+ * HQ_COMPANY_UID (or the person snapshot).
27
+ * - Age: the daemon keeps a snapshot `false` however old it is; the engine
28
+ * uses snapshots up to 24 h old.
29
+ * - Registry only: when the switch is turned off only by the registry flag
30
+ * (no env var, no off file, and the hook's snapshot does not hold `false`
31
+ * yet), the engine cannot see it. The daemon removes its own state file
32
+ * when it first sees the switch off (state-file.ts
33
+ * removeDaemonStateFile); if that removal is refused, the engine keeps
34
+ * reading the last file until it expires (600 s, at most 660 s).
35
+ *
36
+ * Read only: nothing here writes a flag.
37
+ */
38
+ import * as fs from "node:fs";
39
+ import * as os from "node:os";
40
+ import * as path from "node:path";
41
+ import { readDefaultOnFlagSnapshot } from "../flag-snapshot-file.js";
42
+ import { resolveProcessFlagCompanyContext } from "../process-flag-company-context.js";
43
+ export const DAEMON_STATE_FILE_FLAG = "daemon-state-file";
44
+ /** The local override, named as the CLI names every `HQ_FLAG_<KEY>` override. */
45
+ export const DAEMON_STATE_FILE_ENV = "HQ_FLAG_DAEMON_STATE_FILE";
46
+ /** Under the home folder; any file or link here turns the state file off on this machine. */
47
+ export const DAEMON_STATE_FILE_OFF_FILE = path.join(".hq", "daemon-state-file.off");
48
+ const OFF_WORDS = new Set(["false", "0", "off", "no"]);
49
+ const ON_WORDS = new Set(["true", "1", "on", "yes"]);
50
+ function homeOf(env) {
51
+ const fromEnv = (process.platform === "win32" ? env.USERPROFILE : env.HOME)?.trim();
52
+ return fromEnv || os.homedir();
53
+ }
54
+ function offFilePresent(home) {
55
+ try {
56
+ fs.lstatSync(path.join(home, DAEMON_STATE_FILE_OFF_FILE));
57
+ return true;
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ /** False only when a snapshot holds `daemon-state-file: false`; a missing or unreadable snapshot is on. */
64
+ function snapshotAllows(env) {
65
+ const { companyUid } = resolveProcessFlagCompanyContext(env);
66
+ return readDefaultOnFlagSnapshot(DAEMON_STATE_FILE_FLAG, companyUid, env);
67
+ }
68
+ /** Why the state file is off, or null while it is on (the default). */
69
+ export function daemonStateFileOffReason(options = {}) {
70
+ const env = options.env ?? process.env;
71
+ const override = env[DAEMON_STATE_FILE_ENV]?.trim().toLowerCase();
72
+ if (override && OFF_WORDS.has(override))
73
+ return "env";
74
+ if (offFilePresent(options.home ?? homeOf(env)))
75
+ return "file";
76
+ if (override && ON_WORDS.has(override))
77
+ return null;
78
+ if (options.registryValue === false)
79
+ return "flag";
80
+ if (!(options.readSnapshot ?? snapshotAllows)(env))
81
+ return "flag";
82
+ return null;
83
+ }
84
+ /** True unless something turns the state file off (see the module comment). */
85
+ export function daemonStateFileEnabled(options = {}) {
86
+ return daemonStateFileOffReason(options) === null;
87
+ }
88
+ //# sourceMappingURL=state-file-switch.js.map