@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
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Company flag snapshots for every company with bound session work on this
3
+ * machine (rq_20261121230415_a549af8f50, informational 2).
4
+ *
5
+ * `work-mesh-company-reporting-required` is read from the company's local flag
6
+ * snapshot, which is trusted for 24 hours. A CLI process refreshes only the
7
+ * snapshot of its own company scope, and the desktop app and the mesh daemon
8
+ * usually run with none. A company whose sessions run under such a process,
9
+ * or whose member ran no company-scoped command for a day, then had no fresh
10
+ * snapshot, and its sessions fell back to the member's HQ Anywhere switch
11
+ * while the flag was meant to be on.
12
+ *
13
+ * The mesh daemon now keeps those snapshots fresh. On an interval it lists the
14
+ * companies of recent session records with a verified company binding, and
15
+ * for each one whose snapshot is missing or older than
16
+ * COMPANY_FLAG_REFRESH_AGE_MS it asks the flag registry in that company's
17
+ * context and writes the answer. The registry authenticates the member and
18
+ * decides the values: nothing here can turn a flag on that the registry did
19
+ * not return. A signed-out or failed read writes nothing, so the snapshot
20
+ * keeps the registry's last answer until it expires, as before.
21
+ */
22
+ import * as fs from "node:fs";
23
+ import * as path from "node:path";
24
+ import { createFlagClient } from "@indigoai-us/hq-flags-client";
25
+ import { resolveFlagRegistryEndpoint } from "../../flag-registry-endpoint.js";
26
+ import { readFlagSnapshotFile, writeFlagSnapshotFile } from "../../flag-snapshot-file.js";
27
+ import { isNonCloudCompanySlug } from "../../work-context/company-rebind.js";
28
+ import { isWorkContextSessionStateFileName, workContextSessionsDir } from "../../work-context/paths.js";
29
+ import { readSessionState } from "../../work-context/state.js";
30
+ /** How often the daemon looks for snapshots to refresh. */
31
+ export const COMPANY_FLAG_REFRESH_INTERVAL_MS = 15 * 60 * 1_000;
32
+ /** A snapshot older than this is fetched again: well inside the 24-hour trust window. */
33
+ export const COMPANY_FLAG_REFRESH_AGE_MS = 6 * 60 * 60 * 1_000;
34
+ /** Session records updated within this window name the companies to keep fresh. */
35
+ export const COMPANY_FLAG_REFRESH_SESSION_WINDOW_MS = 14 * 24 * 60 * 60 * 1_000;
36
+ /** At most this many companies per refresh, and this many session records read. */
37
+ export const COMPANY_FLAG_REFRESH_MAX_COMPANIES = 20;
38
+ const SESSION_SCAN_MAX = 2_000;
39
+ const REQUEST_TIMEOUT_MS = 5_000;
40
+ const COMPANY_UID_RE = /^cmp_[A-Za-z0-9]{3,128}$/;
41
+ /**
42
+ * A session record whose company the member verified: the binding the
43
+ * reporting predicate requires before it reads the flag at all.
44
+ */
45
+ function verifiedCompanyOf(state) {
46
+ if (state?.contractVersion !== 1 ||
47
+ typeof state.companyUid !== "string" || !COMPANY_UID_RE.test(state.companyUid) ||
48
+ !(state.contextStatus === "bound" || state.contextStatus === "needs_project" || state.contextStatus === "needs_task") ||
49
+ state.companyConfidence === "device_default" ||
50
+ state.ownerMismatch?.companyUid === state.companyUid ||
51
+ (state.companySlug !== undefined && typeof state.companySlug !== "string") ||
52
+ isNonCloudCompanySlug(state.companySlug))
53
+ return null;
54
+ return { uid: state.companyUid, ...(state.companySlug?.trim() ? { slug: state.companySlug.trim() } : {}) };
55
+ }
56
+ /**
57
+ * The companies of recent verified session records whose flag snapshot is
58
+ * missing, unreadable or older than `refreshAgeMs`, newest session first.
59
+ */
60
+ export function companiesNeedingFlagRefresh(workContextRoot, env, now = () => new Date(), refreshAgeMs = COMPANY_FLAG_REFRESH_AGE_MS) {
61
+ const nowMs = now().getTime();
62
+ const dir = workContextSessionsDir(workContextRoot);
63
+ let names;
64
+ try {
65
+ names = fs.readdirSync(dir).filter(isWorkContextSessionStateFileName).slice(0, SESSION_SCAN_MAX);
66
+ }
67
+ catch {
68
+ return [];
69
+ }
70
+ const latest = new Map();
71
+ for (const name of names) {
72
+ const sessionId = path.basename(name, ".json");
73
+ let state;
74
+ try {
75
+ state = readSessionState(sessionId, workContextRoot);
76
+ }
77
+ catch {
78
+ continue;
79
+ }
80
+ if (state?.sessionId !== sessionId)
81
+ continue;
82
+ const company = verifiedCompanyOf(state);
83
+ if (!company)
84
+ continue;
85
+ const at = Date.parse(state.updatedAt);
86
+ if (!Number.isFinite(at) || at > nowMs || nowMs - at > COMPANY_FLAG_REFRESH_SESSION_WINDOW_MS)
87
+ continue;
88
+ const seen = latest.get(company.uid);
89
+ if (!seen || at > seen.at)
90
+ latest.set(company.uid, { ...company, slug: company.slug ?? seen?.slug, at });
91
+ }
92
+ return [...latest.values()]
93
+ .sort((a, b) => b.at - a.at)
94
+ .filter(({ uid }) => readFlagSnapshotFile(uid, { env, now: nowMs, maxAgeMs: refreshAgeMs }) === null)
95
+ .slice(0, COMPANY_FLAG_REFRESH_MAX_COMPANIES)
96
+ .map(({ uid, slug }) => (slug ? { uid, slug } : { uid }));
97
+ }
98
+ /**
99
+ * Refresh the flag snapshot of every company that needs it. Never rejects.
100
+ * Returns the uids whose snapshot was written.
101
+ */
102
+ export async function refreshCompanyFlagSnapshots(options) {
103
+ const written = [];
104
+ let companies;
105
+ try {
106
+ companies = companiesNeedingFlagRefresh(options.workContextRoot, options.env, options.now);
107
+ }
108
+ catch {
109
+ return written;
110
+ }
111
+ if (companies.length === 0)
112
+ return written;
113
+ let token;
114
+ try {
115
+ token = await options.getToken();
116
+ }
117
+ catch {
118
+ return written; // signed out: the snapshots keep the registry's last answer
119
+ }
120
+ if (typeof token !== "string" || !token.trim())
121
+ return written;
122
+ const endpoint = resolveFlagRegistryEndpoint(undefined, options.env);
123
+ for (const company of companies) {
124
+ let client;
125
+ try {
126
+ client = (options.createClient ?? createFlagClient)({
127
+ endpoint,
128
+ companyUid: company.uid,
129
+ ...(company.slug ? { companyIdentifiers: [company.slug] } : {}),
130
+ getToken: () => token,
131
+ env: {},
132
+ refreshIntervalMs: 0,
133
+ requestTimeoutMs: REQUEST_TIMEOUT_MS,
134
+ onError: () => { },
135
+ });
136
+ await client.ready();
137
+ const snapshot = client.snapshot();
138
+ if (!snapshot)
139
+ continue;
140
+ (options.write ?? writeFlagSnapshotFile)(company.uid, snapshot.flags, { env: options.env });
141
+ written.push(company.uid);
142
+ }
143
+ catch (error) {
144
+ options.log?.(`company flag refresh failed company=${company.uid}: ${String(error).slice(0, 120)}`);
145
+ }
146
+ finally {
147
+ try {
148
+ client?.close();
149
+ }
150
+ catch {
151
+ // one client cannot stop the rest
152
+ }
153
+ }
154
+ }
155
+ if (written.length > 0)
156
+ options.log?.(`company flag refresh: wrote ${written.length} snapshot(s)`);
157
+ return written;
158
+ }
159
+ //# sourceMappingURL=company-flag-refresh.js.map
@@ -0,0 +1,61 @@
1
+ /** The company flag that makes Work Mesh reporting required. */
2
+ export declare const WORK_MESH_COMPANY_REPORTING_REQUIRED = "work-mesh-company-reporting-required";
3
+ /**
4
+ * One file per company whose snapshot this machine saw go stale while it
5
+ * said on: when it went stale. The stretch from then is held; the episode
6
+ * itself carries on (review of #3469, INFO-2).
7
+ */
8
+ export declare const COMPANY_REPORTING_STALE_DIRNAME = "company-reporting-stale-since";
9
+ /**
10
+ * One file per company: the stale stretches seen during the current episode,
11
+ * one `<from> <to>` line each (ISO times; `-` for a start that could not be
12
+ * read).
13
+ */
14
+ export declare const COMPANY_REPORTING_GAPS_DIRNAME = "company-reporting-stale-gaps";
15
+ /** The most stale stretches kept per company. Past it the two oldest merge into one, which holds more, not less. */
16
+ export declare const COMPANY_REPORTING_GAPS_MAX = 32;
17
+ /** A stale stretch, [from, to) in epoch ms. */
18
+ export type EnforcementGap = readonly [number, number];
19
+ export declare function readTimeFile(file: string): number | null;
20
+ /**
21
+ * The stretches recorded in `file`. A file that exists but cannot be read,
22
+ * or a line that cannot be read, holds everything up to when the file was
23
+ * last written, as the episode did before stretches were kept.
24
+ */
25
+ export declare function readGaps(file: string, now: () => Date): EnforcementGap[];
26
+ /** A lock older than this was left by a process that stopped; it is taken over. */
27
+ export declare const COMPANY_REPORTING_GAPS_LOCK_STALE_MS = 10000;
28
+ /** How long {@link addCompanyReportingGap} waits for another process's lock by default. */
29
+ export declare const COMPANY_REPORTING_GAPS_LOCK_WAIT_MS = 2000;
30
+ /**
31
+ * Adds a stale stretch for the company. The append, and the rewrite with the
32
+ * oldest merged once there are more than {@link COMPANY_REPORTING_GAPS_MAX}
33
+ * lines, happen under the company's gaps lock, so a daemon flush and an hq
34
+ * command adding one at the same time both keep theirs: no line can be
35
+ * appended between the rewrite's read and its rename (review of #3469,
36
+ * INFO-1 of round 3). False when it could not be stored, including when
37
+ * another process held the lock for `lockWaitMs`.
38
+ */
39
+ export declare function addCompanyReportingGap(workMeshRootDir: string, companyUid: string, gap: EnforcementGap, now?: () => Date, lockWaitMs?: number): boolean;
40
+ /**
41
+ * The stale stretches of the company's current episode on this machine. A
42
+ * stretch still open (a flush saw the snapshot stale and no fresh one has been
43
+ * read since, or closing it could not be stored) runs to now.
44
+ */
45
+ export declare function companyReportingGaps(workMeshRootDir: string, companyUid: string, now?: () => Date): EnforcementGap[];
46
+ /**
47
+ * Called by the company snapshot writer before it replaces `previous`, the
48
+ * snapshot on disk (whatever its age). When that snapshot said reporting is
49
+ * required and is older than `snapshotMaxAgeMs` (the snapshot reader's limit,
50
+ * a day) at `nowMs`, the stretch from when it
51
+ * went stale to now is recorded: no daemon flush may have seen it stale (the
52
+ * daemon was down or asleep), and once the fresh snapshot is on disk the
53
+ * stretch could no longer be told apart (review of #3469, INFO-A). Only on a
54
+ * machine whose Work Mesh root exists. Never throws: the snapshot is written
55
+ * whatever happens here.
56
+ */
57
+ export declare function noteReplacedCompanySnapshot(companyUid: string, previous: {
58
+ fetchedAtMs: number;
59
+ flags: Readonly<Record<string, unknown>>;
60
+ } | null, env: NodeJS.ProcessEnv, snapshotMaxAgeMs: number, nowMs?: number): void;
61
+ //# sourceMappingURL=company-reporting-gaps.d.ts.map
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Stale stretches of a company's enforcement episode (review of #3469, INFO-2
3
+ * and INFO-A). A company "reporting required" snapshot more than a day old
4
+ * counts as off. When it last said on, the episode carries on and only the
5
+ * stretch from when the snapshot went stale until a fresh one is read is
6
+ * held: events dated inside a stretch are not sent while the member's HQ
7
+ * Anywhere opt-out holds them.
8
+ *
9
+ * A stretch is recorded in two places: by a daemon flush that reads the stale
10
+ * snapshot (it notes the start, and closes the stretch when it reads a fresh
11
+ * on), and by the snapshot writer when it replaces a stale snapshot that said
12
+ * on, for a stretch no flush saw (the daemon was down or asleep).
13
+ *
14
+ * This module has no dependency on the flag snapshot reader or the reporting
15
+ * gate, so the snapshot writer can use it.
16
+ */
17
+ import * as fs from "node:fs";
18
+ import * as os from "node:os";
19
+ import * as path from "node:path";
20
+ import { workMeshRoot } from "./paths.js";
21
+ import { createLockFile, lockIsStale, parsePidLockRecord, readLockFile, releaseLockFile, } from "../../../utils/exclusive-lock.js";
22
+ /** The company flag that makes Work Mesh reporting required. */
23
+ export const WORK_MESH_COMPANY_REPORTING_REQUIRED = "work-mesh-company-reporting-required";
24
+ /**
25
+ * One file per company whose snapshot this machine saw go stale while it
26
+ * said on: when it went stale. The stretch from then is held; the episode
27
+ * itself carries on (review of #3469, INFO-2).
28
+ */
29
+ export const COMPANY_REPORTING_STALE_DIRNAME = "company-reporting-stale-since";
30
+ /**
31
+ * One file per company: the stale stretches seen during the current episode,
32
+ * one `<from> <to>` line each (ISO times; `-` for a start that could not be
33
+ * read).
34
+ */
35
+ export const COMPANY_REPORTING_GAPS_DIRNAME = "company-reporting-stale-gaps";
36
+ /** The most stale stretches kept per company. Past it the two oldest merge into one, which holds more, not less. */
37
+ export const COMPANY_REPORTING_GAPS_MAX = 32;
38
+ const SAFE_COMPANY_UID = /^[A-Za-z0-9_-]{1,128}$/;
39
+ export function readTimeFile(file) {
40
+ try {
41
+ const at = Date.parse(fs.readFileSync(file, "utf8").trim());
42
+ return Number.isFinite(at) ? at : null;
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ function fileTimeOr(file, now) {
49
+ try {
50
+ return fs.statSync(file).mtimeMs;
51
+ }
52
+ catch {
53
+ return now().getTime();
54
+ }
55
+ }
56
+ /**
57
+ * The stretches recorded in `file`. A file that exists but cannot be read,
58
+ * or a line that cannot be read, holds everything up to when the file was
59
+ * last written, as the episode did before stretches were kept.
60
+ */
61
+ export function readGaps(file, now) {
62
+ let raw;
63
+ try {
64
+ raw = fs.readFileSync(file, "utf8");
65
+ }
66
+ catch (error) {
67
+ if (error?.code === "ENOENT")
68
+ return [];
69
+ return [[Number.NEGATIVE_INFINITY, fileTimeOr(file, now)]];
70
+ }
71
+ const gaps = [];
72
+ for (const line of raw.split("\n")) {
73
+ if (!line.trim())
74
+ continue;
75
+ const [fromText, toText, extra] = line.trim().split(" ");
76
+ const from = fromText === "-" ? Number.NEGATIVE_INFINITY : Date.parse(fromText ?? "");
77
+ const to = Date.parse(toText ?? "");
78
+ if (extra !== undefined || Number.isNaN(from) || !Number.isFinite(to)) {
79
+ gaps.push([Number.NEGATIVE_INFINITY, fileTimeOr(file, now)]);
80
+ continue;
81
+ }
82
+ gaps.push([from, to]);
83
+ }
84
+ return gaps;
85
+ }
86
+ function gapLine([from, to]) {
87
+ return `${Number.isFinite(from) ? new Date(from).toISOString() : "-"} ${new Date(to).toISOString()}\n`;
88
+ }
89
+ /** Rewrites `file` with `gaps`, merging the oldest past {@link COMPANY_REPORTING_GAPS_MAX}. */
90
+ function writeGaps(folder, file, gaps) {
91
+ const kept = [...gaps].sort((a, b) => a[0] - b[0]);
92
+ while (kept.length > COMPANY_REPORTING_GAPS_MAX) {
93
+ const [first, second] = kept.splice(0, 2);
94
+ kept.unshift([Math.min(first[0], second[0]), Math.max(first[1], second[1])]);
95
+ }
96
+ try {
97
+ fs.mkdirSync(folder, { recursive: true, mode: 0o700 });
98
+ const tmp = `${file}.${process.pid}.tmp`;
99
+ fs.writeFileSync(tmp, kept.map(gapLine).join(""), { mode: 0o600 });
100
+ fs.renameSync(tmp, file);
101
+ return true;
102
+ }
103
+ catch {
104
+ return false;
105
+ }
106
+ }
107
+ /** A lock older than this was left by a process that stopped; it is taken over. */
108
+ export const COMPANY_REPORTING_GAPS_LOCK_STALE_MS = 10_000;
109
+ /** How long {@link addCompanyReportingGap} waits for another process's lock by default. */
110
+ export const COMPANY_REPORTING_GAPS_LOCK_WAIT_MS = 2_000;
111
+ function sleepSync(ms) {
112
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
113
+ }
114
+ /**
115
+ * Runs `fn` holding the company's gaps lock (`<uid>.lock`, created
116
+ * exclusively through the shared lock helpers, body `pid=<n>\nts=<n>`). A
117
+ * lock older than {@link COMPANY_REPORTING_GAPS_LOCK_STALE_MS} is reclaimed.
118
+ * Null when the lock could not be taken within `waitMs`.
119
+ */
120
+ function withGapsLock(folder, companyUid, waitMs, fn) {
121
+ const lock = path.join(folder, `${companyUid}.lock`);
122
+ const deadline = Date.now() + waitMs;
123
+ const body = `pid=${process.pid}\nts=${Date.now()}`;
124
+ const mine = parsePidLockRecord(body);
125
+ for (;;) {
126
+ try {
127
+ if (createLockFile(lock, body))
128
+ break;
129
+ }
130
+ catch {
131
+ return null;
132
+ }
133
+ let ageMs;
134
+ try {
135
+ ageMs = Date.now() - fs.statSync(lock).mtimeMs;
136
+ }
137
+ catch {
138
+ continue; // released meanwhile
139
+ }
140
+ if (lockIsStale({ kind: "age", maxAgeMs: COMPANY_REPORTING_GAPS_LOCK_STALE_MS }, { ageMs })) {
141
+ try {
142
+ fs.rmSync(lock, { force: true });
143
+ }
144
+ catch { /* taken over by another process */ }
145
+ continue;
146
+ }
147
+ if (Date.now() >= deadline)
148
+ return null;
149
+ sleepSync(10);
150
+ }
151
+ try {
152
+ return fn();
153
+ }
154
+ finally {
155
+ try {
156
+ releaseLockFile(lock, {
157
+ read: (file) => readLockFile(file, parsePidLockRecord),
158
+ owns: (owner) => owner.pid === mine.pid && owner.ts === mine.ts,
159
+ remove: (file) => fs.rmSync(file, { force: true }),
160
+ });
161
+ }
162
+ catch { /* the next taker finds it stale */ }
163
+ }
164
+ }
165
+ /**
166
+ * Adds a stale stretch for the company. The append, and the rewrite with the
167
+ * oldest merged once there are more than {@link COMPANY_REPORTING_GAPS_MAX}
168
+ * lines, happen under the company's gaps lock, so a daemon flush and an hq
169
+ * command adding one at the same time both keep theirs: no line can be
170
+ * appended between the rewrite's read and its rename (review of #3469,
171
+ * INFO-1 of round 3). False when it could not be stored, including when
172
+ * another process held the lock for `lockWaitMs`.
173
+ */
174
+ export function addCompanyReportingGap(workMeshRootDir, companyUid, gap, now = () => new Date(), lockWaitMs = COMPANY_REPORTING_GAPS_LOCK_WAIT_MS) {
175
+ if (!SAFE_COMPANY_UID.test(companyUid))
176
+ return false;
177
+ const folder = path.join(workMeshRootDir, COMPANY_REPORTING_GAPS_DIRNAME);
178
+ const file = path.join(folder, companyUid);
179
+ const stored = [gap[0], Math.max(gap[0], gap[1])];
180
+ try {
181
+ fs.mkdirSync(folder, { recursive: true, mode: 0o700 });
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ return withGapsLock(folder, companyUid, lockWaitMs, () => {
187
+ try {
188
+ fs.appendFileSync(file, gapLine(stored), { mode: 0o600 });
189
+ }
190
+ catch {
191
+ return false;
192
+ }
193
+ const gaps = readGaps(file, now);
194
+ return gaps.length <= COMPANY_REPORTING_GAPS_MAX || writeGaps(folder, file, gaps);
195
+ }) ?? false;
196
+ }
197
+ /**
198
+ * The stale stretches of the company's current episode on this machine. A
199
+ * stretch still open (a flush saw the snapshot stale and no fresh one has been
200
+ * read since, or closing it could not be stored) runs to now.
201
+ */
202
+ export function companyReportingGaps(workMeshRootDir, companyUid, now = () => new Date()) {
203
+ if (!SAFE_COMPANY_UID.test(companyUid))
204
+ return [];
205
+ const gaps = readGaps(path.join(workMeshRootDir, COMPANY_REPORTING_GAPS_DIRNAME, companyUid), now);
206
+ const staleFile = path.join(workMeshRootDir, COMPANY_REPORTING_STALE_DIRNAME, companyUid);
207
+ if (fs.existsSync(staleFile))
208
+ gaps.push([readTimeFile(staleFile) ?? Number.NEGATIVE_INFINITY, now().getTime()]);
209
+ return gaps;
210
+ }
211
+ /**
212
+ * Called by the company snapshot writer before it replaces `previous`, the
213
+ * snapshot on disk (whatever its age). When that snapshot said reporting is
214
+ * required and is older than `snapshotMaxAgeMs` (the snapshot reader's limit,
215
+ * a day) at `nowMs`, the stretch from when it
216
+ * went stale to now is recorded: no daemon flush may have seen it stale (the
217
+ * daemon was down or asleep), and once the fresh snapshot is on disk the
218
+ * stretch could no longer be told apart (review of #3469, INFO-A). Only on a
219
+ * machine whose Work Mesh root exists. Never throws: the snapshot is written
220
+ * whatever happens here.
221
+ */
222
+ export function noteReplacedCompanySnapshot(companyUid, previous, env, snapshotMaxAgeMs, nowMs = Date.now()) {
223
+ try {
224
+ if (!previous || previous.flags[WORK_MESH_COMPANY_REPORTING_REQUIRED] !== true)
225
+ return;
226
+ const staleFrom = previous.fetchedAtMs + snapshotMaxAgeMs;
227
+ if (!Number.isFinite(staleFrom) || staleFrom >= nowMs)
228
+ return;
229
+ const root = workMeshRoot(env.HOME?.trim() || os.homedir(), env);
230
+ if (!fs.existsSync(root))
231
+ return;
232
+ addCompanyReportingGap(root, companyUid, [staleFrom, nowMs], () => new Date(nowMs));
233
+ }
234
+ catch {
235
+ /* the snapshot write goes ahead */
236
+ }
237
+ }
238
+ //# sourceMappingURL=company-reporting-gaps.js.map
@@ -0,0 +1,156 @@
1
+ import { type SystemUnitState } from "./system-unit.js";
2
+ import type { RunCommand } from "../../../service-manager/launchd.js";
3
+ export declare const DUPLICATE_UNIT_RECORD = "duplicate-unit.json";
4
+ export declare const REMOVED_USER_UNIT_BACKUP = "hq-mesh-daemon.service.removed.bak";
5
+ export type DuplicateUnitAction =
6
+ /** Nothing to do: not Linux, no user unit, no system unit, another user's system unit, or a process of neither unit. */
7
+ "none"
8
+ /** The system unit's daemon held the lock for the settle time; the user unit was backed up and removed. */
9
+ | "removed-user-unit"
10
+ /** The user unit was backed up, but its file or wants link could not be deleted; the removal is retried. */
11
+ | "partial-removal"
12
+ /** Both units exist but the user unit was kept; `reason` says why. */
13
+ | "kept-user-unit"
14
+ /** This process belongs to the system unit: removal waits until it has held the pid lock. */
15
+ | "deferred-until-lock"
16
+ /** This process belongs to the user unit and the system unit's daemon holds this home's lock: exit, remove nothing. */
17
+ | "deferred-to-system-unit";
18
+ /** Which unit started this process. */
19
+ export type MeshUnitRole = "user-unit" | "system-unit" | "other";
20
+ export interface DuplicateUnitResult {
21
+ action: DuplicateUnitAction;
22
+ role?: MeshUnitRole;
23
+ reason?: string;
24
+ systemState?: SystemUnitState | null;
25
+ /** Steps that failed while removing the user unit (the removal still went ahead). */
26
+ warnings?: string[];
27
+ /** Where the removed user unit was copied before it was deleted. */
28
+ backupPath?: string;
29
+ /** Files that are still present after a removal attempt (partial-removal). */
30
+ remaining?: string[];
31
+ /** Which removal attempt this result comes from (settled path). */
32
+ attempt?: number;
33
+ /**
34
+ * True when this process was started by the user unit and the system
35
+ * unit's daemon holds this home's pid lock: this one exits instead of
36
+ * competing for the lock. Nothing is removed.
37
+ */
38
+ exitAfter?: boolean;
39
+ /** True when the caller should run {@link removeDuplicateUserUnitOnceSettled} once it holds the pid lock. */
40
+ removeAfterLock?: boolean;
41
+ }
42
+ export interface DuplicateUnitDeps {
43
+ platform?: NodeJS.Platform;
44
+ home?: string;
45
+ env?: NodeJS.ProcessEnv;
46
+ /** Directory holding the box's system units (tests pass a fake root). */
47
+ systemUnitDir?: string;
48
+ /**
49
+ * This process's user name and uid, compared with the system unit's User=
50
+ * (tests inject; null: unknown, so nothing is removed).
51
+ */
52
+ user?: {
53
+ username: string;
54
+ uid: number;
55
+ } | null;
56
+ /** systemctl runner (tests inject a fake; never the real binary). */
57
+ run?: RunCommand;
58
+ sleep?: (ms: number) => Promise<void>;
59
+ /** /proc/self/cgroup text, to tell which unit started this process. */
60
+ readCgroup?: () => string | null;
61
+ /** Whether a pid is alive (tests inject; default signal 0). */
62
+ isProcessAlive?: (pid: number) => boolean;
63
+ /** How long the system unit's daemon must hold the pid lock before the user unit goes. */
64
+ settleMs?: number;
65
+ /** Wait between attempts after a partial removal. */
66
+ retryMs?: number;
67
+ /** Removal attempts before a partial removal is left as it is. */
68
+ maxAttempts?: number;
69
+ /** Delete a file (tests inject failures; default fs.unlinkSync). */
70
+ unlink?: (file: string) => void;
71
+ /** Flush a file or directory to disk (tests observe; default open + fsync). */
72
+ fsyncPath?: (file: string) => void;
73
+ /** Drop-in and environment.d locations for the user unit (tests pass fake dirs). */
74
+ userEnvironmentSources?: UserEnvironmentSources;
75
+ now?: () => Date;
76
+ log?: (line: string) => void;
77
+ }
78
+ export interface AfterLockDeps extends DuplicateUnitDeps {
79
+ /** Daemon dir holding the pid lock (the running daemon's handle.dir). */
80
+ lockDir?: string;
81
+ /** This process's pid, as written in the lock. */
82
+ pid?: number;
83
+ }
84
+ export declare const DEFAULT_SETTLE_MS = 30000;
85
+ export declare const DEFAULT_RETRY_MS: number;
86
+ export declare const DEFAULT_MAX_ATTEMPTS = 12;
87
+ export declare function meshUserUnitPath(home: string): string;
88
+ /** Where the user manager may read unit drop-ins and environment.d files (tests pass fake dirs). */
89
+ export interface UserEnvironmentSources {
90
+ /** Drop-in directories that apply to the user unit, besides ~/.config/systemd/user/<unit>.d. */
91
+ dropInDirs?: string[];
92
+ /** environment.d directories the user manager reads. */
93
+ environmentDirs?: string[];
94
+ }
95
+ /**
96
+ * The daemon dir the user unit's daemon locks: HQ_WORK_MESH_ROOT/daemon when
97
+ * its environment sets that, else <HOME>/.hq/work-mesh/daemon, with HOME
98
+ * taken from its environment when set there. The user manager is asked
99
+ * first. When it cannot be reached, the unit file is read, and the answer is
100
+ * null (do nothing) if the environment could also come from somewhere the
101
+ * file does not show: EnvironmentFile=, a drop-in, or an environment.d file
102
+ * that sets HOME or HQ_WORK_MESH_ROOT.
103
+ */
104
+ export declare function userUnitDaemonDir(home: string, run?: RunCommand, sources?: UserEnvironmentSources): string | null;
105
+ /**
106
+ * Runner with the user manager's bus address filled in, so `systemctl --user`
107
+ * reaches it from a system service that runs as the box user.
108
+ */
109
+ export declare function defaultDuplicateUnitRun(env?: NodeJS.ProcessEnv): RunCommand;
110
+ /** True when the cgroup text places this process in a user manager's hq-mesh-daemon.service. */
111
+ export declare function cgroupIsMeshUserUnit(cgroup: string | null): boolean;
112
+ /** True when the cgroup text places this process in the system manager's hq-mesh-daemon.service. */
113
+ export declare function cgroupIsMeshSystemUnit(cgroup: string | null): boolean;
114
+ /**
115
+ * Which unit started this process: the cgroup first, then systemd's
116
+ * INVOCATION_ID compared with the system unit's own InvocationID.
117
+ */
118
+ export declare function meshUnitRole(cgroup: string | null, env: NodeJS.ProcessEnv, run: RunCommand): MeshUnitRole;
119
+ /** What systemd says about who the system unit runs as and its main process. */
120
+ export interface SystemUnitIdentity {
121
+ user: string;
122
+ dynamicUser: string;
123
+ mainPid: number;
124
+ loadState: string;
125
+ }
126
+ /**
127
+ * Read the system unit's effective identity from systemd, which has already
128
+ * merged every unit file and drop-in location in its own order. Null when
129
+ * systemctl cannot answer.
130
+ */
131
+ export declare function readSystemUnitIdentity(run: RunCommand): SystemUnitIdentity | null;
132
+ /**
133
+ * Null when the system unit runs this user's Work Mesh as far as systemd
134
+ * says; otherwise why it does not (and nothing should happen).
135
+ */
136
+ export declare function systemUnitIdentityMismatch(identity: SystemUnitIdentity | null, user: {
137
+ username: string;
138
+ uid: number;
139
+ } | null): string | null;
140
+ /**
141
+ * Runs at the start of `hq mesh daemon run`, before the pid lock. Never
142
+ * removes anything. A process started by the system unit gets
143
+ * `removeAfterLock`; a process started by the user unit gets `exitAfter`
144
+ * only when the system unit's daemon holds this home's pid lock.
145
+ */
146
+ export declare function reconcileDuplicateMeshUnit(deps?: DuplicateUnitDeps): Promise<DuplicateUnitResult>;
147
+ /**
148
+ * Runs in the system unit's daemon once it holds the pid lock. Waits the
149
+ * settle time, then backs up and removes the user unit only if the system
150
+ * unit still runs as this user, this process still holds the lock, that lock
151
+ * is the user unit's own (same daemon dir), and the system unit is still
152
+ * active. A partial removal is recorded and retried while all of that still
153
+ * holds. Never throws.
154
+ */
155
+ export declare function removeDuplicateUserUnitOnceSettled(deps?: AfterLockDeps): Promise<DuplicateUnitResult>;
156
+ //# sourceMappingURL=duplicate-unit.d.ts.map