@indigoai-us/hq-cli 5.345.247 → 5.345.248

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 (239) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
  3. package/contracts/host-canary-release.json +14 -0
  4. package/dist/command-catalog.generated.d.ts +1113 -0
  5. package/dist/command-catalog.generated.js +1370 -0
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/lanes-hold.js +7 -7
  9. package/dist/commands/lanes-resume.js +2 -2
  10. package/dist/commands/lanes-review.js +1 -1
  11. package/dist/commands/lanes-session-start.d.ts +1 -1
  12. package/dist/commands/lanes-session-start.js +3 -3
  13. package/dist/commands/lanes-shared.d.ts +1 -1
  14. package/dist/commands/lanes.d.ts +2 -2
  15. package/dist/commands/lanes.js +50 -50
  16. package/dist/commands/mesh.d.ts +25 -0
  17. package/dist/commands/mesh.js +48 -8
  18. package/dist/commands/ontology-graph.d.ts +62 -0
  19. package/dist/commands/ontology-graph.js +439 -0
  20. package/dist/index.js +1 -1
  21. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  22. package/dist/lanes-monitor-check-argv.js +1 -1
  23. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  24. package/dist/lanes-monitor-check-fast.js +1 -1
  25. package/dist/lanes-session-start-argv.d.ts +1 -1
  26. package/dist/lanes-session-start-argv.js +1 -1
  27. package/dist/lib/capacity/sign-in.d.ts +1 -1
  28. package/dist/lib/capacity/sign-in.js +1 -1
  29. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  30. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  31. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  32. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  33. package/dist/lib/daemon/merge-sections.js +7 -7
  34. package/dist/lib/daemon/remote-control-pools.js +1 -1
  35. package/dist/lib/daemon/run.js +1 -1
  36. package/dist/lib/daemon/state-file.d.ts +1 -1
  37. package/dist/lib/daemon/state-file.js +1 -1
  38. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  39. package/dist/lib/flag-snapshot-file.js +118 -48
  40. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  41. package/dist/lib/hook-engine/canary-gate.js +138 -6
  42. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  43. package/dist/lib/hot-channels/graph-context.js +377 -0
  44. package/dist/lib/hot-channels/signals-pass.js +27 -1
  45. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  46. package/dist/lib/lanes/claude-credential.js +1 -1
  47. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  48. package/dist/lib/lanes/delivery-core.js +1 -1
  49. package/dist/lib/lanes/delivery.d.ts +10 -10
  50. package/dist/lib/lanes/delivery.js +8 -8
  51. package/dist/lib/lanes/dropbox.d.ts +1 -1
  52. package/dist/lib/lanes/dropbox.js +1 -1
  53. package/dist/lib/lanes/hooks-install.js +2 -2
  54. package/dist/lib/lanes/index.d.ts +1 -1
  55. package/dist/lib/lanes/index.js +1 -1
  56. package/dist/lib/lanes/monitor.js +1 -1
  57. package/dist/lib/lanes/quota-notice.js +1 -1
  58. package/dist/lib/lanes/quota.d.ts +1 -1
  59. package/dist/lib/lanes/quota.js +1 -1
  60. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  61. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  62. package/dist/lib/lanes/spawn.d.ts +4 -4
  63. package/dist/lib/lanes/spawn.js +5 -5
  64. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  65. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  66. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  67. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  68. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  69. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  70. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  71. package/dist/lib/mesh/live/daemon/run.js +35 -2
  72. package/dist/lib/mesh/live/direct-drain.js +1 -1
  73. package/dist/lib/mesh/live/emit.d.ts +3 -0
  74. package/dist/lib/mesh/live/emit.js +32 -9
  75. package/dist/lib/mesh/live/flush.d.ts +3 -0
  76. package/dist/lib/mesh/live/flush.js +115 -32
  77. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  78. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  79. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  80. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  81. package/dist/lib/mesh/live/spool.d.ts +17 -2
  82. package/dist/lib/mesh/live/spool.js +22 -6
  83. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  84. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  85. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  86. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  87. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  88. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  89. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  90. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  91. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  92. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  93. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  94. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  95. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  96. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  97. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  98. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  99. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  100. package/dist/lib/ontology-graph/lint/index.js +176 -0
  101. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  102. package/dist/lib/ontology-graph/model/files.js +89 -0
  103. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  104. package/dist/lib/ontology-graph/model/index.js +100 -0
  105. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  106. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  107. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  108. package/dist/lib/ontology-graph/model/pass.js +958 -0
  109. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  110. package/dist/lib/ontology-graph/model/runner.js +160 -0
  111. package/dist/lib/ontology-graph/model/step.d.ts +195 -0
  112. package/dist/lib/ontology-graph/model/step.js +523 -0
  113. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  114. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  115. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  116. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  117. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  118. package/dist/lib/ontology-graph/org/compare.js +239 -0
  119. package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
  120. package/dist/lib/ontology-graph/org/derive.js +352 -0
  121. package/dist/lib/ontology-graph/org/index.d.ts +73 -0
  122. package/dist/lib/ontology-graph/org/index.js +513 -0
  123. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  124. package/dist/lib/ontology-graph/org/load.js +476 -0
  125. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  126. package/dist/lib/ontology-graph/org/role.js +268 -0
  127. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  128. package/dist/lib/ontology-graph/org/structure.js +437 -0
  129. package/dist/lib/ontology-graph/org/text.d.ts +95 -0
  130. package/dist/lib/ontology-graph/org/text.js +315 -0
  131. package/dist/lib/ontology-graph/org/types.d.ts +452 -0
  132. package/dist/lib/ontology-graph/org/types.js +80 -0
  133. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  134. package/dist/lib/ontology-graph/pages/index.js +193 -0
  135. package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
  136. package/dist/lib/ontology-graph/pages/render.js +682 -0
  137. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  138. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  139. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  140. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  141. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  142. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  143. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  144. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  145. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  146. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  147. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  148. package/dist/lib/ontology-graph/read/brief.js +251 -0
  149. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  150. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  151. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  152. package/dist/lib/ontology-graph/read/index.js +792 -0
  153. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  154. package/dist/lib/ontology-graph/read/member.js +34 -0
  155. package/dist/lib/ontology-graph/read/names.d.ts +44 -0
  156. package/dist/lib/ontology-graph/read/names.js +292 -0
  157. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  158. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  159. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  160. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  161. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  162. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  163. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  164. package/dist/lib/ontology-graph/replay/config.js +105 -0
  165. package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
  166. package/dist/lib/ontology-graph/replay/engine.js +1174 -0
  167. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  168. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  169. package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
  170. package/dist/lib/ontology-graph/replay/index.js +220 -0
  171. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  172. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  173. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  174. package/dist/lib/ontology-graph/replay/member.js +65 -0
  175. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  176. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  177. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  178. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  179. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  180. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  181. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  182. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  183. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  184. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  185. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  186. package/dist/lib/ontology-graph/replay/util.js +256 -0
  187. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  188. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  189. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  190. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  191. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  192. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  193. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  194. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  195. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  196. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  197. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  198. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  199. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  200. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  201. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  202. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  203. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  204. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  205. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  206. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  207. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  208. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  209. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  210. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  211. package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
  212. package/dist/lib/ontology-graph/schema/authority.js +157 -0
  213. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  214. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  215. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  216. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  217. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  218. package/dist/lib/ontology-graph/schema/index.js +10 -0
  219. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  220. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  221. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  222. package/dist/lib/ontology-graph/store/files.js +207 -0
  223. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  224. package/dist/lib/ontology-graph/store/fs.js +101 -0
  225. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  226. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  227. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  228. package/dist/lib/ontology-graph/store/index.js +15 -0
  229. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  230. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  231. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  232. package/dist/lib/ontology-graph/store/paths.js +232 -0
  233. package/dist/lib/ontology-graph/types.d.ts +1183 -0
  234. package/dist/lib/ontology-graph/types.js +131 -0
  235. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  236. package/dist/utils/frontmatter.d.ts +14 -0
  237. package/dist/utils/frontmatter.js +18 -0
  238. package/dist/utils/interactive-caller.js +1 -1
  239. package/package.json +8 -8
@@ -1,11 +1,24 @@
1
+ import { WORK_MESH_COMPANY_REPORTING_REQUIRED, type EnforcementGap } from "./company-reporting-gaps.js";
1
2
  import { type SessionStateFile } from "../../work-context/state.js";
2
3
  /** Match the off controls used by the hook and handoff command. */
3
4
  export declare function workMeshSwitchDisabled(env?: NodeJS.ProcessEnv): boolean;
4
5
  /** Privacy gate: missing, stale or unreadable snapshots never override a member's off switch.
5
6
  * The notice hold explicitly requires confirmed on, unlike default-on kill switches.
6
7
  */
7
- export declare const WORK_MESH_COMPANY_REPORTING_REQUIRED = "work-mesh-company-reporting-required";
8
+ export { WORK_MESH_COMPANY_REPORTING_REQUIRED };
8
9
  export declare function workMeshCompanyReportingRequired(companyUid?: string, env?: NodeJS.ProcessEnv): boolean;
10
+ /**
11
+ * The company flag as the enforcement episode reads it. `on` is
12
+ * {@link workMeshCompanyReportingRequired}. When it is not on only because the
13
+ * company's snapshot is more than a day old and that snapshot said on,
14
+ * `staleOnUntil` is when the snapshot went stale: until then the flag was
15
+ * fresh and on. Otherwise null.
16
+ */
17
+ export interface CompanyReportingReading {
18
+ on: boolean;
19
+ staleOnUntil: number | null;
20
+ }
21
+ export declare function readCompanyReportingRequired(companyUid: string, env?: NodeJS.ProcessEnv): CompanyReportingReading;
9
22
  /**
10
23
  * `root` is the Work Context root the state was read from; it holds the
11
24
  * session's fleet runtime record. Defaults to the root `env` names.
@@ -15,10 +28,23 @@ export declare function workMeshCompanyReportingRequired(companyUid?: string, en
15
28
  * is that fleet session itself (`ownFleetSession`). The second keeps fleet
16
29
  * agents reporting as before when no record was written, for example an
17
30
  * agents-v2 session with Work Mesh on, where the hook never writes one.
31
+ *
32
+ * `fleet`, when given, answers the fleet question instead (one flush or emit
33
+ * pass shares one, so the binding and the backlog cutoff agree).
18
34
  */
19
- export declare function hasWorkMeshCompanyBinding(state: SessionStateFile | null, env?: NodeJS.ProcessEnv, root?: string): state is SessionStateFile & {
35
+ export declare function hasWorkMeshCompanyBinding(state: SessionStateFile | null, env?: NodeJS.ProcessEnv, root?: string, fleet?: FleetSessionJudge): state is SessionStateFile & {
20
36
  companyUid: string;
21
37
  };
38
+ /** Whether a session is a fleet agent's, answered for one flush or emit pass. */
39
+ export type FleetSessionJudge = (sessionId: string) => boolean;
40
+ /**
41
+ * A fleet judge for one pass: each session's answer (`ownFleetSession` or
42
+ * `recordedFleetSession`) is worked out once and reused, so the session's
43
+ * fleet runtime record is read once per pass. A record that appears during
44
+ * the pass is seen by the next one, and every answer within a pass agrees
45
+ * (review of #3469, INFO-1).
46
+ */
47
+ export declare function fleetSessionJudge(env: NodeJS.ProcessEnv, root: string): FleetSessionJudge;
22
48
  /**
23
49
  * This process runs under a fleet agent adapter and `sessionId` is the
24
50
  * session its environment names. A fleet agent judging its own session is
@@ -52,7 +78,11 @@ export declare function fleetAgentRuntime(env?: NodeJS.ProcessEnv): boolean;
52
78
  */
53
79
  export declare function operatorAllowsHqAnywhere(env?: NodeJS.ProcessEnv): boolean;
54
80
  export declare function eventMatchesWorkMeshCompany(event: Record<string, unknown>, companySlug: string | undefined): boolean;
55
- export declare function hasWorkMeshEventCompanyBinding(event: Record<string, unknown>, env: NodeJS.ProcessEnv): boolean;
81
+ /** The event's session state when it holds a verified company binding for the event's company; else null. */
82
+ export declare function workMeshEventBinding(event: Record<string, unknown>, env: NodeJS.ProcessEnv, fleet?: FleetSessionJudge): (SessionStateFile & {
83
+ companyUid: string;
84
+ }) | null;
85
+ export declare function hasWorkMeshEventCompanyBinding(event: Record<string, unknown>, env: NodeJS.ProcessEnv, fleet?: FleetSessionJudge): boolean;
56
86
  /** The file, in the Work Mesh root, that holds when HQ Anywhere was first seen off on this machine. */
57
87
  export declare const ANYWHERE_OFF_SINCE_BASENAME = "anywhere-off-since";
58
88
  /**
@@ -63,8 +93,72 @@ export declare const ANYWHERE_OFF_SINCE_BASENAME = "anywhere-off-since";
63
93
  */
64
94
  export declare function logAnywhereOffSinceAhead(workMeshRootDir: string, offSinceMs: number, nowMs: number, log?: (message: string) => void): void;
65
95
  export declare function anywhereOffSince(workMeshRootDir: string, now?: () => Date): number;
96
+ /** The recorded first-seen-off time, or null when none is recorded. Never writes. */
97
+ export declare function readAnywhereOffSince(workMeshRootDir: string): number | null;
98
+ /**
99
+ * Folder, in the Work Mesh root, with one file per company: when this machine
100
+ * first saw `work-mesh-company-reporting-required` confirmed on for it again
101
+ * after seeing it not on (the notice hold, or a later kill switch).
102
+ */
103
+ export declare const COMPANY_REPORTING_SINCE_DIRNAME = "company-reporting-required-since";
104
+ /** One file per company whose flag this machine saw not on since the last episode started. */
105
+ export declare const COMPANY_REPORTING_HOLD_DIRNAME = "company-reporting-held";
106
+ export { COMPANY_REPORTING_GAPS_DIRNAME, COMPANY_REPORTING_GAPS_MAX, COMPANY_REPORTING_STALE_DIRNAME, companyReportingGaps, type EnforcementGap, } from "./company-reporting-gaps.js";
107
+ /**
108
+ * The start of the company's current enforcement episode on this machine, or
109
+ * null when there is none to apply. Seeing the flag not on ends the episode
110
+ * and notes the hold; seeing it confirmed on after a hold starts a new
111
+ * episode now. Events a member's HQ Anywhere opt-out kept back during a hold
112
+ * are then not sent when enforcement turns on or on again
113
+ * (rq_20261121230415_a549af8f50, informational 1). A machine that never saw
114
+ * the flag not on has no episode cutoff. When the start cannot be stored,
115
+ * the answer is now, so nothing older than this call goes.
116
+ *
117
+ * A snapshot that is not on only because it is more than a day old and said
118
+ * on (the machine has not synced for a day) does not end the episode: the
119
+ * time it went stale is noted, and when the flag is read fresh and on again
120
+ * the stretch from then to now is kept as a stale stretch
121
+ * ({@link companyReportingGaps}). So only the events from the stale stretch
122
+ * are held, not those from while the flag was still fresh and on (review of
123
+ * #3469, INFO-2). A confirmed off (or a missing or unreadable snapshot) ends
124
+ * the episode as before, and with it its stale stretches.
125
+ */
126
+ export declare function companyReportingRequiredSince(workMeshRootDir: string, companyUid: string, reading: CompanyReportingReading | boolean, now?: () => Date): number | null;
127
+ /**
128
+ * The earliest event time a bound session may send while HQ Anywhere is not
129
+ * on. A confirmed off records the first-seen-off time. An unknown answer only
130
+ * reads it; with no record, null: the events wait, unsent and unrecorded,
131
+ * until the setting can be read. When enforcement came from the company flag,
132
+ * the start of the enforcement episode is a second cutoff and the later of
133
+ * the two applies.
134
+ */
135
+ export declare function anywhereBacklogCutoff(workMeshRootDir: string, state: ReportingState, enforcedSince: number | null, now?: () => Date): number | null;
136
+ /**
137
+ * The enforcement episode that applies to a session's events: `since`, its
138
+ * start when enforcement came from the flag (else null), and `gaps`, its stale
139
+ * stretches. A fleet session (judged by `fleet`, per session, never by the
140
+ * judging process's environment alone, #3464) gets neither: it is not held.
141
+ * Forgets the episode when the flag is not on.
142
+ */
143
+ export interface EnforcementEpisode {
144
+ since: number | null;
145
+ gaps: EnforcementGap[];
146
+ }
147
+ export declare function enforcementEpisode(workMeshRootDir: string, state: SessionStateFile & {
148
+ companyUid: string;
149
+ }, env: NodeJS.ProcessEnv, fleet: FleetSessionJudge, now?: () => Date): EnforcementEpisode;
150
+ /**
151
+ * The key of a backlog cutoff: the company and whether the session is a
152
+ * fleet session, since only member sessions get the enforcement-episode
153
+ * cutoff.
154
+ */
155
+ export declare function backlogCutoffKey(state: SessionStateFile & {
156
+ companyUid: string;
157
+ }, fleet: FleetSessionJudge): string;
66
158
  /** The event is dated at or after `sinceMs`. An event with no readable date is not. */
67
159
  export declare function eventDatedSince(event: Record<string, unknown>, sinceMs: number): boolean;
160
+ /** The event is dated at or after `sinceMs` and inside none of `gaps`. An event with no readable date is not. */
161
+ export declare function eventDatedOutsideGaps(event: Record<string, unknown>, sinceMs: number, gaps: readonly EnforcementGap[]): boolean;
68
162
  /**
69
163
  * The most `.json` files one check reads, sidecar files beside the session
70
164
  * states included. Past it the check answers "no recent company session".
@@ -90,6 +184,26 @@ export declare const MESH_SERVICE_REQUIRED_NOTICE: string;
90
184
  /** Legacy emit must not let the server infer a company for conversation text. */
91
185
  export declare function mayEmitConversation(event: Record<string, unknown>, env?: NodeJS.ProcessEnv): boolean;
92
186
  /** Fleet identities have no person preference; operator and local controls still apply. */
187
+ /**
188
+ * Whether HQ Anywhere reporting is on for this process. "unknown" means the
189
+ * person setting could not be read (no token, a timeout, a bad answer): it is
190
+ * not a member's opt-out. Unknown still sends nothing for a session without
191
+ * a company binding, but it never records that the member switched HQ
192
+ * Anywhere off (`anywhereOffSince`), so a slow or failed read cannot move the
193
+ * backlog cutoff (rq_20261121230415_a549af8f50, finding 2).
194
+ */
195
+ export type ReportingState = "on" | "off" | "unknown";
196
+ /** `reportingRuntimeAllowed` with the unread case kept apart. */
197
+ export declare function reportingRuntimeState(machine: boolean, env?: NodeJS.ProcessEnv): Promise<ReportingState>;
198
+ /**
199
+ * The HQ Anywhere answer an emit or flush acts on. The local switch is a
200
+ * confirmed off. `reportingState` (the daemon's gate) can say unknown; the
201
+ * older boolean `reportingAllowed` cannot, so its false is taken as off.
202
+ */
203
+ export declare function resolveReportingState(env: NodeJS.ProcessEnv, deps: {
204
+ reportingState?: () => Promise<ReportingState>;
205
+ reportingAllowed?: () => Promise<boolean>;
206
+ }): ReportingState | Promise<ReportingState>;
93
207
  export declare function reportingRuntimeAllowed(machine: boolean, env?: NodeJS.ProcessEnv): Promise<boolean>;
94
208
  /**
95
209
  * Local state that moves when the person's HQ Anywhere answer may have moved:
@@ -123,4 +237,6 @@ export interface ReportingGateOptions {
123
237
  * is still checked on every call. Unknown stays closed.
124
238
  */
125
239
  export declare function createReportingGate(machine: boolean, env?: NodeJS.ProcessEnv, options?: ReportingGateOptions): () => Promise<boolean>;
240
+ /** `createReportingGate` with the unread case kept apart (see `ReportingState`). */
241
+ export declare function createReportingStateGate(machine: boolean, env?: NodeJS.ProcessEnv, options?: ReportingGateOptions): () => Promise<ReportingState>;
126
242
  //# sourceMappingURL=reporting-privacy.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import * as fs from "node:fs";
2
- import { readFlagSnapshotFile, readPersonFlagSnapshotFile } from "../../flag-snapshot-file.js";
2
+ import { FLAG_SNAPSHOT_MAX_AGE_MS, parseSnapshotTime, readFlagSnapshotFile, readPersonFlagSnapshotFile, } from "../../flag-snapshot-file.js";
3
3
  import * as os from "node:os";
4
4
  import { anywhereRuntimeAllowed, personTokenCachePath, readHqAnywherePersonSetting } from "../../anywhere-person-setting.js";
5
5
  import { anywhereRuntimeRevocationMarkerPath } from "../../anywhere-runtime-revocation-marker.js";
@@ -13,6 +13,7 @@ import * as path from "node:path";
13
13
  import { isSafeWorkContextSegment, isWorkContextSessionStateFileName, workContextFleetRuntimePath, workContextRoot, workContextSessionsDir, } from "../../work-context/paths.js";
14
14
  import { SESSION_COMPANY_CHANGE_COMMAND } from "../../work-context/errors.js";
15
15
  import { sessionIdFromEnv } from "../../core-utils/session-id.js";
16
+ import { COMPANY_REPORTING_GAPS_DIRNAME, COMPANY_REPORTING_STALE_DIRNAME, WORK_MESH_COMPANY_REPORTING_REQUIRED, addCompanyReportingGap, companyReportingGaps, readTimeFile, } from "./company-reporting-gaps.js";
16
17
  import { readSessionState } from "../../work-context/state.js";
17
18
  /** Match the off controls used by the hook and handoff command. */
18
19
  export function workMeshSwitchDisabled(env = process.env) {
@@ -23,13 +24,22 @@ export function workMeshSwitchDisabled(env = process.env) {
23
24
  /** Privacy gate: missing, stale or unreadable snapshots never override a member's off switch.
24
25
  * The notice hold explicitly requires confirmed on, unlike default-on kill switches.
25
26
  */
26
- export const WORK_MESH_COMPANY_REPORTING_REQUIRED = "work-mesh-company-reporting-required";
27
+ export { WORK_MESH_COMPANY_REPORTING_REQUIRED };
27
28
  export function workMeshCompanyReportingRequired(companyUid, env = process.env) {
28
29
  const snapshot = companyUid
29
30
  ? readFlagSnapshotFile(companyUid, { env })
30
31
  : readPersonFlagSnapshotFile({ env });
31
32
  return snapshot?.flags[WORK_MESH_COMPANY_REPORTING_REQUIRED] === true;
32
33
  }
34
+ export function readCompanyReportingRequired(companyUid, env = process.env) {
35
+ if (workMeshCompanyReportingRequired(companyUid, env))
36
+ return { on: true, staleOnUntil: null };
37
+ const last = readFlagSnapshotFile(companyUid, { env, maxAgeMs: Number.POSITIVE_INFINITY });
38
+ if (last?.flags[WORK_MESH_COMPANY_REPORTING_REQUIRED] !== true)
39
+ return { on: false, staleOnUntil: null };
40
+ const fetchedAt = parseSnapshotTime(last.fetched_at);
41
+ return { on: false, staleOnUntil: Number.isFinite(fetchedAt) ? fetchedAt + FLAG_SNAPSHOT_MAX_AGE_MS : null };
42
+ }
33
43
  /**
34
44
  * `root` is the Work Context root the state was read from; it holds the
35
45
  * session's fleet runtime record. Defaults to the root `env` names.
@@ -39,18 +49,39 @@ export function workMeshCompanyReportingRequired(companyUid, env = process.env)
39
49
  * is that fleet session itself (`ownFleetSession`). The second keeps fleet
40
50
  * agents reporting as before when no record was written, for example an
41
51
  * agents-v2 session with Work Mesh on, where the hook never writes one.
52
+ *
53
+ * `fleet`, when given, answers the fleet question instead (one flush or emit
54
+ * pass shares one, so the binding and the backlog cutoff agree).
42
55
  */
43
- export function hasWorkMeshCompanyBinding(state, env = process.env, root) {
56
+ export function hasWorkMeshCompanyBinding(state, env = process.env, root, fleet) {
44
57
  return state?.contractVersion === 1 && typeof state.companyUid === "string" && !!state.companyUid.trim() &&
45
58
  (state.contextStatus === "bound" || state.contextStatus === "needs_project" || state.contextStatus === "needs_task") &&
46
59
  state.companyConfidence !== "device_default" &&
47
60
  state.ownerMismatch?.companyUid !== state.companyUid &&
48
61
  (state.companySlug === undefined || typeof state.companySlug === "string") &&
49
62
  !isNonCloudCompanySlug(state.companySlug) &&
50
- (ownFleetSession(state.sessionId, env) ||
51
- recordedFleetSession(state.sessionId, root ?? workContextRoot(undefined, env)) ||
63
+ ((fleet ? fleet(state.sessionId) : ownFleetSession(state.sessionId, env) ||
64
+ recordedFleetSession(state.sessionId, root ?? workContextRoot(undefined, env))) ||
52
65
  workMeshCompanyReportingRequired(state.companyUid, env));
53
66
  }
67
+ /**
68
+ * A fleet judge for one pass: each session's answer (`ownFleetSession` or
69
+ * `recordedFleetSession`) is worked out once and reused, so the session's
70
+ * fleet runtime record is read once per pass. A record that appears during
71
+ * the pass is seen by the next one, and every answer within a pass agrees
72
+ * (review of #3469, INFO-1).
73
+ */
74
+ export function fleetSessionJudge(env, root) {
75
+ const answers = new Map();
76
+ return (sessionId) => {
77
+ let answer = answers.get(sessionId);
78
+ if (answer === undefined) {
79
+ answer = ownFleetSession(sessionId, env) || recordedFleetSession(sessionId, root);
80
+ answers.set(sessionId, answer);
81
+ }
82
+ return answer;
83
+ };
84
+ }
54
85
  /**
55
86
  * This process runs under a fleet agent adapter and `sessionId` is the
56
87
  * session its environment names. A fleet agent judging its own session is
@@ -118,14 +149,22 @@ export function eventMatchesWorkMeshCompany(event, companySlug) {
118
149
  return [event.companySlug, evidence?.companySlug].every(slug => typeof slug !== "string" || !slug.trim() ||
119
150
  (!isNonCloudCompanySlug(slug) && slug === companySlug));
120
151
  }
121
- export function hasWorkMeshEventCompanyBinding(event, env) {
152
+ /** The event's session state when it holds a verified company binding for the event's company; else null. */
153
+ export function workMeshEventBinding(event, env, fleet) {
154
+ if (typeof event.sessionId !== "string")
155
+ return null;
156
+ const root = workContextRoot(undefined, env);
157
+ const state = readSessionState(event.sessionId, root);
158
+ return hasWorkMeshCompanyBinding(state, env, root, fleet) && eventMatchesWorkMeshCompany(event, state.companySlug) ? state : null;
159
+ }
160
+ export function hasWorkMeshEventCompanyBinding(event, env, fleet) {
122
161
  if (typeof event.sessionId !== "string")
123
162
  return false;
124
163
  // The scope files SessionStart can mint from a guess do not grant the
125
164
  // switch exception. Use the established binding for this exact session.
126
165
  const root = workContextRoot(undefined, env);
127
166
  const state = readSessionState(event.sessionId, root);
128
- return hasWorkMeshCompanyBinding(state, env, root) && eventMatchesWorkMeshCompany(event, state.companySlug);
167
+ return hasWorkMeshCompanyBinding(state, env, root, fleet) && eventMatchesWorkMeshCompany(event, state.companySlug);
129
168
  }
130
169
  /** The file, in the Work Mesh root, that holds when HQ Anywhere was first seen off on this machine. */
131
170
  export const ANYWHERE_OFF_SINCE_BASENAME = "anywhere-off-since";
@@ -194,11 +233,159 @@ export function anywhereOffSince(workMeshRootDir, now = () => new Date()) {
194
233
  }
195
234
  return at.getTime();
196
235
  }
236
+ /** The recorded first-seen-off time, or null when none is recorded. Never writes. */
237
+ export function readAnywhereOffSince(workMeshRootDir) {
238
+ try {
239
+ const at = Date.parse(fs.readFileSync(path.join(workMeshRootDir, ANYWHERE_OFF_SINCE_BASENAME), "utf8").trim());
240
+ return Number.isFinite(at) ? at : null;
241
+ }
242
+ catch {
243
+ return null;
244
+ }
245
+ }
246
+ /**
247
+ * Folder, in the Work Mesh root, with one file per company: when this machine
248
+ * first saw `work-mesh-company-reporting-required` confirmed on for it again
249
+ * after seeing it not on (the notice hold, or a later kill switch).
250
+ */
251
+ export const COMPANY_REPORTING_SINCE_DIRNAME = "company-reporting-required-since";
252
+ /** One file per company whose flag this machine saw not on since the last episode started. */
253
+ export const COMPANY_REPORTING_HOLD_DIRNAME = "company-reporting-held";
254
+ export { COMPANY_REPORTING_GAPS_DIRNAME, COMPANY_REPORTING_GAPS_MAX, COMPANY_REPORTING_STALE_DIRNAME, companyReportingGaps, } from "./company-reporting-gaps.js";
255
+ function writeTime(folder, file, at) {
256
+ try {
257
+ fs.mkdirSync(folder, { recursive: true, mode: 0o700 });
258
+ const tmp = `${file}.${process.pid}.tmp`;
259
+ fs.writeFileSync(tmp, `${at.toISOString()}\n`, { mode: 0o600 });
260
+ fs.renameSync(tmp, file);
261
+ return true;
262
+ }
263
+ catch {
264
+ return false;
265
+ }
266
+ }
267
+ /**
268
+ * The start of the company's current enforcement episode on this machine, or
269
+ * null when there is none to apply. Seeing the flag not on ends the episode
270
+ * and notes the hold; seeing it confirmed on after a hold starts a new
271
+ * episode now. Events a member's HQ Anywhere opt-out kept back during a hold
272
+ * are then not sent when enforcement turns on or on again
273
+ * (rq_20261121230415_a549af8f50, informational 1). A machine that never saw
274
+ * the flag not on has no episode cutoff. When the start cannot be stored,
275
+ * the answer is now, so nothing older than this call goes.
276
+ *
277
+ * A snapshot that is not on only because it is more than a day old and said
278
+ * on (the machine has not synced for a day) does not end the episode: the
279
+ * time it went stale is noted, and when the flag is read fresh and on again
280
+ * the stretch from then to now is kept as a stale stretch
281
+ * ({@link companyReportingGaps}). So only the events from the stale stretch
282
+ * are held, not those from while the flag was still fresh and on (review of
283
+ * #3469, INFO-2). A confirmed off (or a missing or unreadable snapshot) ends
284
+ * the episode as before, and with it its stale stretches.
285
+ */
286
+ export function companyReportingRequiredSince(workMeshRootDir, companyUid, reading, now = () => new Date()) {
287
+ const flag = typeof reading === "boolean" ? { on: reading, staleOnUntil: null } : reading;
288
+ if (!/^[A-Za-z0-9_-]{1,128}$/.test(companyUid))
289
+ return flag.on ? now().getTime() : null;
290
+ const sinceFolder = path.join(workMeshRootDir, COMPANY_REPORTING_SINCE_DIRNAME);
291
+ const holdFolder = path.join(workMeshRootDir, COMPANY_REPORTING_HOLD_DIRNAME);
292
+ const staleFolder = path.join(workMeshRootDir, COMPANY_REPORTING_STALE_DIRNAME);
293
+ const gapsFolder = path.join(workMeshRootDir, COMPANY_REPORTING_GAPS_DIRNAME);
294
+ const since = path.join(sinceFolder, companyUid);
295
+ const hold = path.join(holdFolder, companyUid);
296
+ const stale = path.join(staleFolder, companyUid);
297
+ const gaps = path.join(gapsFolder, companyUid);
298
+ if (!flag.on) {
299
+ // Stale but last said on, with no hold open: the episode carries on.
300
+ if (flag.staleOnUntil !== null && !fs.existsSync(hold) &&
301
+ (fs.existsSync(stale) || writeTime(staleFolder, stale, new Date(flag.staleOnUntil)))) {
302
+ return null;
303
+ }
304
+ try {
305
+ fs.rmSync(since, { force: true });
306
+ }
307
+ catch { /* nothing recorded */ }
308
+ if (!fs.existsSync(hold))
309
+ writeTime(holdFolder, hold, now());
310
+ try {
311
+ fs.rmSync(stale, { force: true });
312
+ }
313
+ catch { /* nothing recorded */ }
314
+ try {
315
+ fs.rmSync(gaps, { force: true });
316
+ }
317
+ catch { /* nothing recorded */ }
318
+ return null;
319
+ }
320
+ if (fs.existsSync(stale)) {
321
+ // Fresh and on again: close the stale stretch at now. Until it is stored,
322
+ // the open stretch runs to now (companyReportingGaps).
323
+ const from = readTimeFile(stale) ?? Number.NEGATIVE_INFINITY;
324
+ const to = now().getTime();
325
+ if (addCompanyReportingGap(workMeshRootDir, companyUid, [from, to], now)) {
326
+ try {
327
+ fs.rmSync(stale, { force: true });
328
+ }
329
+ catch { /* closed; the next read keeps it open to now */ }
330
+ }
331
+ }
332
+ try {
333
+ const at = Date.parse(fs.readFileSync(since, "utf8").trim());
334
+ if (Number.isFinite(at))
335
+ return at;
336
+ }
337
+ catch { /* no episode recorded */ }
338
+ if (!fs.existsSync(hold))
339
+ return null;
340
+ const at = now();
341
+ if (writeTime(sinceFolder, since, at)) {
342
+ try {
343
+ fs.rmSync(hold, { force: true });
344
+ }
345
+ catch { /* the start is recorded */ }
346
+ }
347
+ return at.getTime();
348
+ }
349
+ /**
350
+ * The earliest event time a bound session may send while HQ Anywhere is not
351
+ * on. A confirmed off records the first-seen-off time. An unknown answer only
352
+ * reads it; with no record, null: the events wait, unsent and unrecorded,
353
+ * until the setting can be read. When enforcement came from the company flag,
354
+ * the start of the enforcement episode is a second cutoff and the later of
355
+ * the two applies.
356
+ */
357
+ export function anywhereBacklogCutoff(workMeshRootDir, state, enforcedSince, now = () => new Date()) {
358
+ const offSince = state === "off" ? anywhereOffSince(workMeshRootDir, now) : readAnywhereOffSince(workMeshRootDir);
359
+ if (offSince === null)
360
+ return null;
361
+ return enforcedSince === null ? offSince : Math.max(offSince, enforcedSince);
362
+ }
363
+ export function enforcementEpisode(workMeshRootDir, state, env, fleet, now = () => new Date()) {
364
+ const since = companyReportingRequiredSince(workMeshRootDir, state.companyUid, readCompanyReportingRequired(state.companyUid, env), now);
365
+ if (fleet(state.sessionId))
366
+ return { since: null, gaps: [] };
367
+ return { since, gaps: companyReportingGaps(workMeshRootDir, state.companyUid, now) };
368
+ }
369
+ /**
370
+ * The key of a backlog cutoff: the company and whether the session is a
371
+ * fleet session, since only member sessions get the enforcement-episode
372
+ * cutoff.
373
+ */
374
+ export function backlogCutoffKey(state, fleet) {
375
+ return `${state.companyUid}\u0000${fleet(state.sessionId) ? "fleet" : "member"}`;
376
+ }
197
377
  /** The event is dated at or after `sinceMs`. An event with no readable date is not. */
198
378
  export function eventDatedSince(event, sinceMs) {
199
379
  const at = typeof event.at === "string" ? Date.parse(event.at) : Number.NaN;
200
380
  return Number.isFinite(at) && at >= sinceMs;
201
381
  }
382
+ /** The event is dated at or after `sinceMs` and inside none of `gaps`. An event with no readable date is not. */
383
+ export function eventDatedOutsideGaps(event, sinceMs, gaps) {
384
+ if (!eventDatedSince(event, sinceMs))
385
+ return false;
386
+ const at = Date.parse(event.at);
387
+ return !gaps.some(([from, to]) => at >= from && at < to);
388
+ }
202
389
  /**
203
390
  * The most `.json` files one check reads, sidecar files beside the session
204
391
  * states included. Past it the check answers "no recent company session".
@@ -282,7 +469,39 @@ export function mayEmitConversation(event, env = process.env) {
282
469
  trusted: { companySlug: text("companySlug") }, existingState: state });
283
470
  return resolved.status === "resolved" && !isNonCloudCompanySlug(resolved.company.slug);
284
471
  }
285
- /** Fleet identities have no person preference; operator and local controls still apply. */
472
+ function personReportingState(env, readSetting) {
473
+ // The same answer as anywhereRuntimeAllowed, which also decides "on"; the
474
+ // setting it read tells an unread one (null) from an opt-out. No extra
475
+ // async frames: the daemon's flush and outbox paths race on the same
476
+ // session, and this keeps the gate as quick as the boolean one it replaces.
477
+ let read;
478
+ return anywhereRuntimeAllowed(env, {
479
+ readSetting: async () => (read = readSetting ? await readSetting() : await readHqAnywherePersonSetting({ env })),
480
+ }).then((allowed) => (allowed ? "on" : read === null ? "unknown" : "off"));
481
+ }
482
+ /** `reportingRuntimeAllowed` with the unread case kept apart. */
483
+ export async function reportingRuntimeState(machine, env = process.env) {
484
+ if (hqAnywhereRuntimeLocallyDisabled(env))
485
+ return "off";
486
+ if (machine)
487
+ return anywhereRuntimeEnabledFromSnapshot(env) ? "on" : "off";
488
+ return personReportingState(env);
489
+ }
490
+ /**
491
+ * The HQ Anywhere answer an emit or flush acts on. The local switch is a
492
+ * confirmed off. `reportingState` (the daemon's gate) can say unknown; the
493
+ * older boolean `reportingAllowed` cannot, so its false is taken as off.
494
+ */
495
+ export function resolveReportingState(env, deps) {
496
+ // Answers at once when no gate is asked, as the boolean check it replaces did.
497
+ if (hqAnywhereRuntimeLocallyDisabled(env))
498
+ return "off";
499
+ if (deps.reportingState)
500
+ return deps.reportingState();
501
+ if (deps.reportingAllowed)
502
+ return deps.reportingAllowed().then((allowed) => (allowed ? "on" : "off"));
503
+ return "on";
504
+ }
286
505
  export async function reportingRuntimeAllowed(machine, env = process.env) {
287
506
  if (hqAnywhereRuntimeLocallyDisabled(env))
288
507
  return false;
@@ -325,6 +544,11 @@ export function reportingSettingChangeSignal(env = process.env, home) {
325
544
  * is still checked on every call. Unknown stays closed.
326
545
  */
327
546
  export function createReportingGate(machine, env = process.env, options = {}) {
547
+ const state = createReportingStateGate(machine, env, options);
548
+ return async () => (await state()) === "on";
549
+ }
550
+ /** `createReportingGate` with the unread case kept apart (see `ReportingState`). */
551
+ export function createReportingStateGate(machine, env = process.env, options = {}) {
328
552
  const readSetting = cachedPersonSettingReader(options.readSetting ?? (() => readHqAnywherePersonSetting({ env, home: options.home })), {
329
553
  refreshMs: options.refreshMs,
330
554
  failureRetryMs: options.failureRetryMs,
@@ -333,10 +557,10 @@ export function createReportingGate(machine, env = process.env, options = {}) {
333
557
  });
334
558
  return async () => {
335
559
  if (hqAnywhereRuntimeLocallyDisabled(env))
336
- return false;
560
+ return "off";
337
561
  if (machine)
338
- return anywhereRuntimeEnabledFromSnapshot(env);
339
- return anywhereRuntimeAllowed(env, { readSetting });
562
+ return anywhereRuntimeEnabledFromSnapshot(env) ? "on" : "off";
563
+ return personReportingState(env, readSetting);
340
564
  };
341
565
  }
342
566
  //# sourceMappingURL=reporting-privacy.js.map
@@ -105,7 +105,18 @@ export interface ParkedIndex {
105
105
  export interface ParkedSegment {
106
106
  lines: number;
107
107
  parkedAt: string | null;
108
+ /**
109
+ * Parked while the person's HQ Anywhere setting could not be read: a bound
110
+ * session's events waiting for it, not lines a confirmed opt-out kept back.
111
+ * They are never dropped for age (rq_20261121230415_a549af8f50).
112
+ */
113
+ unread?: true;
108
114
  }
115
+ /**
116
+ * True when the parked file holds lines parked while the person setting was
117
+ * unread (`unread` segments) and its recorded segments still describe it.
118
+ */
119
+ export declare function parkedHasUnreadLines(root: string): boolean;
109
120
  /** The oldest and newest known parked-at times of the parked file, or null when none is known. */
110
121
  export declare function parkedTimesRange(root: string): {
111
122
  oldestMs: number;
@@ -154,8 +165,12 @@ export declare function createStagedAppender(root: string, target: string): Stag
154
165
  * flush. `bindingOf` gives the binding to record for a session.
155
166
  */
156
167
  export declare function createParkedAppender(root: string, bindingOf: (sessionId: string) => string): {
157
- /** `parkedAt`: when the line was first parked (now, for a line not parked before). */
158
- push(line: string, sessionId: string | null, parkedAt: string): void;
168
+ /**
169
+ * `parkedAt`: when the line was first parked (now, for a line not parked
170
+ * before). `unread`: parked while the person setting was unread, so never
171
+ * aged.
172
+ */
173
+ push(line: string, sessionId: string | null, parkedAt: string, unread?: boolean): void;
159
174
  commit(): void;
160
175
  /** Append the staged lines to `target` instead (no index), then remove the staging file. */
161
176
  commitTo(target: string): void;
@@ -487,12 +487,14 @@ function parseSegments(value) {
487
487
  for (const entry of value) {
488
488
  if (!entry || typeof entry !== "object")
489
489
  return undefined;
490
- const { lines, parkedAt } = entry;
490
+ const { lines, parkedAt, unread } = entry;
491
491
  if (typeof lines !== "number" || !Number.isInteger(lines) || lines < 0)
492
492
  return undefined;
493
493
  if (parkedAt !== null && (typeof parkedAt !== "string" || !Number.isFinite(Date.parse(parkedAt))))
494
494
  return undefined;
495
- out.push({ lines, parkedAt: parkedAt });
495
+ if (unread !== undefined && unread !== true)
496
+ return undefined;
497
+ out.push({ lines, parkedAt: parkedAt, ...(unread ? { unread: true } : {}) });
496
498
  }
497
499
  return out;
498
500
  }
@@ -522,6 +524,19 @@ function readParkedIndex(root) {
522
524
  return null;
523
525
  }
524
526
  }
527
+ /**
528
+ * True when the parked file holds lines parked while the person setting was
529
+ * unread (`unread` segments) and its recorded segments still describe it.
530
+ */
531
+ export function parkedHasUnreadLines(root) {
532
+ const size = fileSizeOrZero(workMeshParkedPath(root));
533
+ if (size === 0)
534
+ return false;
535
+ const index = readParkedIndex(root);
536
+ if (!index?.segments || index.bytes !== size)
537
+ return false;
538
+ return index.segments.some((segment) => segment.unread === true && segment.lines > 0);
539
+ }
525
540
  /** The oldest and newest known parked-at times of the parked file, or null when none is known. */
526
541
  export function parkedTimesRange(root) {
527
542
  const size = fileSizeOrZero(workMeshParkedPath(root));
@@ -553,7 +568,8 @@ export function segmentsRange(segments) {
553
568
  let oldestMs = Infinity;
554
569
  let newestMs = -Infinity;
555
570
  for (const segment of segments) {
556
- if (segment.parkedAt === null || segment.lines === 0)
571
+ // Lines parked while the setting was unread are never aged.
572
+ if (segment.parkedAt === null || segment.lines === 0 || segment.unread)
557
573
  continue;
558
574
  const at = Date.parse(segment.parkedAt);
559
575
  if (at < oldestMs)
@@ -604,7 +620,7 @@ function appendSegments(into, add) {
604
620
  if (segment.lines === 0)
605
621
  continue;
606
622
  const last = into[into.length - 1];
607
- if (last && last.parkedAt === segment.parkedAt)
623
+ if (last && last.parkedAt === segment.parkedAt && last.unread === segment.unread)
608
624
  last.lines += segment.lines;
609
625
  else
610
626
  into.push({ ...segment });
@@ -759,11 +775,11 @@ export function createParkedAppender(root, bindingOf) {
759
775
  let count = 0;
760
776
  let bytes = 0;
761
777
  return {
762
- push(line, sessionId, parkedAt) {
778
+ push(line, sessionId, parkedAt, unread) {
763
779
  if (sessionId && !sessions.has(sessionId))
764
780
  sessions.set(sessionId, bindingOf(sessionId));
765
781
  out.push(line);
766
- appendSegments(segments, [{ lines: 1, parkedAt }]);
782
+ appendSegments(segments, [{ lines: 1, parkedAt, ...(unread ? { unread: true } : {}) }]);
767
783
  count += 1;
768
784
  bytes += Buffer.byteLength(line, "utf8") + 1;
769
785
  },