@indigoai-us/hq-cli 5.345.247 → 5.345.250

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 (284) hide show
  1. package/CHANGELOG.md +95 -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 +1198 -0
  5. package/dist/command-catalog.generated.js +1476 -0
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/core-job-run-native.js +4 -0
  9. package/dist/commands/core-knowledge-prefs.d.ts +1 -1
  10. package/dist/commands/core-knowledge-prefs.js +1 -16
  11. package/dist/commands/core.js +0 -2
  12. package/dist/commands/daemon.js +21 -0
  13. package/dist/commands/lanes-hold.js +7 -7
  14. package/dist/commands/lanes-resume.js +2 -2
  15. package/dist/commands/lanes-review.js +1 -1
  16. package/dist/commands/lanes-session-start.d.ts +1 -1
  17. package/dist/commands/lanes-session-start.js +3 -3
  18. package/dist/commands/lanes-shared.d.ts +1 -1
  19. package/dist/commands/lanes.d.ts +2 -2
  20. package/dist/commands/lanes.js +50 -50
  21. package/dist/commands/mesh.d.ts +25 -0
  22. package/dist/commands/mesh.js +48 -8
  23. package/dist/commands/ontology-graph.d.ts +63 -0
  24. package/dist/commands/ontology-graph.js +470 -0
  25. package/dist/commands/sync-core.js +6 -0
  26. package/dist/fast-scaffold.js +1 -3
  27. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
  28. package/dist/hq-cloud-sync-runner/package.json +1 -1
  29. package/dist/index.d.ts +8 -0
  30. package/dist/index.js +48 -1
  31. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  32. package/dist/lanes-monitor-check-argv.js +1 -1
  33. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  34. package/dist/lanes-monitor-check-fast.js +1 -1
  35. package/dist/lanes-session-start-argv.d.ts +1 -1
  36. package/dist/lanes-session-start-argv.js +1 -1
  37. package/dist/lib/capacity/sign-in.d.ts +1 -1
  38. package/dist/lib/capacity/sign-in.js +1 -1
  39. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  40. package/dist/lib/daemon/installed-cli-restart.d.ts +57 -0
  41. package/dist/lib/daemon/installed-cli-restart.js +114 -0
  42. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  43. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  44. package/dist/lib/daemon/legacy-journal-gate.d.ts +32 -0
  45. package/dist/lib/daemon/legacy-journal-gate.js +102 -0
  46. package/dist/lib/daemon/machine-checks.d.ts +7 -0
  47. package/dist/lib/daemon/machine-checks.js +10 -0
  48. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  49. package/dist/lib/daemon/merge-sections.js +7 -7
  50. package/dist/lib/daemon/remote-control-pools.js +1 -1
  51. package/dist/lib/daemon/run.d.ts +3 -1
  52. package/dist/lib/daemon/run.js +49 -6
  53. package/dist/lib/daemon/state-file.d.ts +1 -1
  54. package/dist/lib/daemon/state-file.js +1 -1
  55. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  56. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  57. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  58. package/dist/lib/flag-snapshot-file.js +118 -48
  59. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  60. package/dist/lib/hook-engine/canary-gate.js +138 -6
  61. package/dist/lib/hook-engine/coverage.d.ts +82 -13
  62. package/dist/lib/hook-engine/coverage.js +214 -18
  63. package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
  64. package/dist/lib/hook-engine/registration-identity.js +1 -1
  65. package/dist/lib/hook-engine/resolve.d.ts +23 -0
  66. package/dist/lib/hook-engine/resolve.js +48 -1
  67. package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
  68. package/dist/lib/hook-engine/stable-heal.js +214 -0
  69. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  70. package/dist/lib/hot-channels/graph-context.js +380 -0
  71. package/dist/lib/hot-channels/signals-pass.js +27 -1
  72. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  73. package/dist/lib/lanes/claude-credential.js +1 -1
  74. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  75. package/dist/lib/lanes/delivery-core.js +1 -1
  76. package/dist/lib/lanes/delivery.d.ts +10 -10
  77. package/dist/lib/lanes/delivery.js +8 -8
  78. package/dist/lib/lanes/dropbox.d.ts +1 -1
  79. package/dist/lib/lanes/dropbox.js +1 -1
  80. package/dist/lib/lanes/hooks-install.js +2 -2
  81. package/dist/lib/lanes/index.d.ts +1 -1
  82. package/dist/lib/lanes/index.js +1 -1
  83. package/dist/lib/lanes/monitor.js +1 -1
  84. package/dist/lib/lanes/quota-notice.js +1 -1
  85. package/dist/lib/lanes/quota.d.ts +1 -1
  86. package/dist/lib/lanes/quota.js +1 -1
  87. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  88. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  89. package/dist/lib/lanes/spawn.d.ts +4 -4
  90. package/dist/lib/lanes/spawn.js +5 -5
  91. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  92. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  93. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  94. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  95. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  96. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  97. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  98. package/dist/lib/mesh/live/daemon/run.js +35 -2
  99. package/dist/lib/mesh/live/direct-drain.js +1 -1
  100. package/dist/lib/mesh/live/emit.d.ts +3 -0
  101. package/dist/lib/mesh/live/emit.js +32 -9
  102. package/dist/lib/mesh/live/flush.d.ts +3 -0
  103. package/dist/lib/mesh/live/flush.js +115 -32
  104. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  105. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  106. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  107. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  108. package/dist/lib/mesh/live/spool.d.ts +17 -2
  109. package/dist/lib/mesh/live/spool.js +22 -6
  110. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  111. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  112. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  113. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  114. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  115. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  116. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  117. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  118. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  119. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  120. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  121. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  122. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  123. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  124. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  125. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  126. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  127. package/dist/lib/ontology-graph/lint/index.js +176 -0
  128. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  129. package/dist/lib/ontology-graph/model/files.js +89 -0
  130. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  131. package/dist/lib/ontology-graph/model/index.js +100 -0
  132. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  133. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  134. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  135. package/dist/lib/ontology-graph/model/pass.js +958 -0
  136. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  137. package/dist/lib/ontology-graph/model/runner.js +160 -0
  138. package/dist/lib/ontology-graph/model/step.d.ts +197 -0
  139. package/dist/lib/ontology-graph/model/step.js +526 -0
  140. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  141. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  142. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  143. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  144. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  145. package/dist/lib/ontology-graph/org/compare.js +239 -0
  146. package/dist/lib/ontology-graph/org/derive.d.ts +67 -0
  147. package/dist/lib/ontology-graph/org/derive.js +359 -0
  148. package/dist/lib/ontology-graph/org/index.d.ts +102 -0
  149. package/dist/lib/ontology-graph/org/index.js +630 -0
  150. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  151. package/dist/lib/ontology-graph/org/load.js +476 -0
  152. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  153. package/dist/lib/ontology-graph/org/role.js +268 -0
  154. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  155. package/dist/lib/ontology-graph/org/structure.js +437 -0
  156. package/dist/lib/ontology-graph/org/text.d.ts +97 -0
  157. package/dist/lib/ontology-graph/org/text.js +321 -0
  158. package/dist/lib/ontology-graph/org/types.d.ts +457 -0
  159. package/dist/lib/ontology-graph/org/types.js +80 -0
  160. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  161. package/dist/lib/ontology-graph/pages/index.js +193 -0
  162. package/dist/lib/ontology-graph/pages/render.d.ts +144 -0
  163. package/dist/lib/ontology-graph/pages/render.js +688 -0
  164. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  165. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  166. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  167. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  168. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  169. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  170. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  171. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  172. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  173. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  174. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  175. package/dist/lib/ontology-graph/read/brief.js +254 -0
  176. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  177. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  178. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  179. package/dist/lib/ontology-graph/read/index.js +803 -0
  180. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  181. package/dist/lib/ontology-graph/read/member.js +34 -0
  182. package/dist/lib/ontology-graph/read/names.d.ts +49 -0
  183. package/dist/lib/ontology-graph/read/names.js +297 -0
  184. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  185. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  186. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  187. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  188. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  189. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  190. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  191. package/dist/lib/ontology-graph/replay/config.js +105 -0
  192. package/dist/lib/ontology-graph/replay/engine.d.ts +146 -0
  193. package/dist/lib/ontology-graph/replay/engine.js +1240 -0
  194. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  195. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  196. package/dist/lib/ontology-graph/replay/index.d.ts +91 -0
  197. package/dist/lib/ontology-graph/replay/index.js +220 -0
  198. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  199. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  200. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  201. package/dist/lib/ontology-graph/replay/member.js +65 -0
  202. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  203. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  204. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  205. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  206. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  207. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  208. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  209. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  210. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  211. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  212. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  213. package/dist/lib/ontology-graph/replay/util.js +256 -0
  214. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  215. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  216. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  217. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  218. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  219. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  220. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  221. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  222. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  223. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  224. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  225. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  226. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  227. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  228. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  229. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  230. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  231. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  232. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  233. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  234. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  235. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  236. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  237. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  238. package/dist/lib/ontology-graph/schema/authority.d.ts +107 -0
  239. package/dist/lib/ontology-graph/schema/authority.js +186 -0
  240. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  241. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  242. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  243. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  244. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  245. package/dist/lib/ontology-graph/schema/index.js +10 -0
  246. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  247. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  248. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  249. package/dist/lib/ontology-graph/store/files.js +207 -0
  250. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  251. package/dist/lib/ontology-graph/store/fs.js +101 -0
  252. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  253. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  254. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  255. package/dist/lib/ontology-graph/store/index.js +15 -0
  256. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  257. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  258. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  259. package/dist/lib/ontology-graph/store/paths.js +232 -0
  260. package/dist/lib/ontology-graph/types.d.ts +1190 -0
  261. package/dist/lib/ontology-graph/types.js +131 -0
  262. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  263. package/dist/lib/sync-core/engine-holds.d.ts +1 -1
  264. package/dist/lib/sync-core/engine-holds.js +12 -2
  265. package/dist/lib/sync-core/hand-back.d.ts +2 -1
  266. package/dist/lib/sync-core/hand-back.js +16 -2
  267. package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
  268. package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
  269. package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
  270. package/dist/lib/sync-core/legacy-journal-export.js +241 -0
  271. package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
  272. package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
  273. package/dist/lib/sync-core/reconcile.d.ts +3 -0
  274. package/dist/lib/sync-core/reconcile.js +43 -3
  275. package/dist/utils/cli-telemetry.d.ts +1 -0
  276. package/dist/utils/cli-telemetry.js +6 -3
  277. package/dist/utils/frontmatter.d.ts +14 -0
  278. package/dist/utils/frontmatter.js +18 -0
  279. package/dist/utils/hook-engine-rollup.d.ts +96 -0
  280. package/dist/utils/hook-engine-rollup.js +725 -0
  281. package/dist/utils/interactive-caller.js +1 -1
  282. package/package.json +9 -9
  283. package/scripts/install-hook-engine.mjs +4 -0
  284. package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Ontology graph: shared types (WP-A).
3
+ *
4
+ * Every package under src/lib/ontology-graph/ codes against this file. After
5
+ * the first publish, changes here are additive only. The on-disk layout, the
6
+ * row grammar and package ownership are described in CONTRACT.md beside it.
7
+ *
8
+ * Conventions:
9
+ * - Rows are plain serializable objects. String-typed stamps (`src`, `by`,
10
+ * entity refs) use the exact text that appears in the markdown file, so a
11
+ * row can be built with literals: `{ src: "signal:4f35becbeabe", by: "legacy" }`.
12
+ * - Dates are calendar days, `YYYY-MM-DD`, in UTC.
13
+ * - The audience key is not part of a row. It is the `facts/@{key}/` folder
14
+ * the row lives in, and travels beside the row as `StoredRow.audience`.
15
+ */
16
+ /**
17
+ * Entity types that live in the graph folder. The four accounting types
18
+ * (account, journal-entry, ar-invoice, ap-bill) are not here on purpose: they
19
+ * stay in the old `ontology/entities/` folder and are never replayed.
20
+ */
21
+ export const GRAPH_ENTITY_TYPES = [
22
+ "person",
23
+ "team",
24
+ "role",
25
+ "project",
26
+ "product",
27
+ "company",
28
+ "meeting",
29
+ "decision",
30
+ "concept",
31
+ "tool",
32
+ "contact",
33
+ "deal",
34
+ "contract",
35
+ "invoice",
36
+ ];
37
+ export const COMPANY_AUDIENCE = "company";
38
+ // ---------------------------------------------------------------------------
39
+ // Source refs and origin
40
+ // ---------------------------------------------------------------------------
41
+ export const SOURCE_REF_KINDS = ["signal", "source", "doc", "session", "record", "legacy"];
42
+ export const ORIGIN_KINDS = ["human", "record", "rule", "agent", "legacy"];
43
+ /**
44
+ * Authority tier of an origin (design 2.7). 1 is highest. For one entity and
45
+ * field, the open row with the lowest tier number is the answer. A lower
46
+ * authority row never closes a higher authority row.
47
+ */
48
+ export const ORIGIN_TIER = {
49
+ human: 1,
50
+ record: 2,
51
+ rule: 3,
52
+ agent: 4,
53
+ legacy: 5,
54
+ };
55
+ /**
56
+ * The closed vocabulary (design 2.4). Each verb names its inverse; symmetric
57
+ * verbs (partner_of, related_to) are their own inverse. schema.yaml
58
+ * `link_types` is generated from this table and may narrow it, never widen it.
59
+ */
60
+ export const VERBS = {
61
+ // State
62
+ reports_to: { inverse: "manages", class: "state", subjects: ["person"], objects: ["person"], cardinality: "single" },
63
+ manages: { inverse: "reports_to", class: "state", subjects: ["person"], objects: ["person"], cardinality: "multi" },
64
+ // Governance (the org layer's relation of the same name): the subject may speak for the object.
65
+ speaks_for: { inverse: "spoken_for_by", class: "state", subjects: ["person"], objects: ["person"], cardinality: "multi" },
66
+ spoken_for_by: { inverse: "speaks_for", class: "state", subjects: ["person"], objects: ["person"], cardinality: "multi" },
67
+ member_of: { inverse: "has_member", class: "state", subjects: ["person"], objects: ["team"], cardinality: "multi" },
68
+ has_member: { inverse: "member_of", class: "state", subjects: ["team"], objects: ["person"], cardinality: "multi" },
69
+ holds_role: { inverse: "held_by", class: "state", subjects: ["person"], objects: ["role"], cardinality: "multi" },
70
+ held_by: { inverse: "holds_role", class: "state", subjects: ["role"], objects: ["person"], cardinality: "multi" },
71
+ leads: { inverse: "led_by", class: "state", subjects: ["person"], objects: ["team", "project"], cardinality: "multi" },
72
+ led_by: { inverse: "leads", class: "state", subjects: ["team", "project"], objects: ["person"], cardinality: "multi" },
73
+ works_on: { inverse: "has_contributor", class: "state", subjects: ["person"], objects: ["project", "product"], cardinality: "multi" },
74
+ has_contributor: { inverse: "works_on", class: "state", subjects: ["project", "product"], objects: ["person"], cardinality: "multi" },
75
+ owns: { inverse: "owned_by", class: "state", subjects: ["person", "team"], objects: ["project", "product"], cardinality: "multi" },
76
+ owned_by: { inverse: "owns", class: "state", subjects: ["project", "product"], objects: ["person", "team"], cardinality: "single" },
77
+ works_at: { inverse: "employs", class: "state", subjects: ["person"], objects: ["company"], cardinality: "multi" },
78
+ employs: { inverse: "works_at", class: "state", subjects: ["company"], objects: ["person"], cardinality: "multi" },
79
+ part_of: { inverse: "has_part", class: "state", subjects: ["team", "project", "product", "role", "concept", "tool"], objects: ["team", "project", "product", "role", "concept", "tool", "company"], cardinality: "multi" },
80
+ has_part: { inverse: "part_of", class: "state", subjects: ["team", "project", "product", "role", "concept", "tool", "company"], objects: ["team", "project", "product", "role", "concept", "tool"], cardinality: "multi" },
81
+ customer_of: { inverse: "has_customer", class: "state", subjects: ["company"], objects: ["company"], cardinality: "multi" },
82
+ has_customer: { inverse: "customer_of", class: "state", subjects: ["company"], objects: ["company"], cardinality: "multi" },
83
+ vendor_of: { inverse: "has_vendor", class: "state", subjects: ["company"], objects: ["company"], cardinality: "multi" },
84
+ has_vendor: { inverse: "vendor_of", class: "state", subjects: ["company"], objects: ["company"], cardinality: "multi" },
85
+ partner_of: { inverse: "partner_of", class: "state", subjects: ["company"], objects: ["company"], cardinality: "multi" },
86
+ uses: { inverse: "used_by", class: "state", subjects: ["project", "product"], objects: ["tool", "project"], cardinality: "multi" },
87
+ used_by: { inverse: "uses", class: "state", subjects: ["tool", "project"], objects: ["project", "product"], cardinality: "multi" },
88
+ depends_on: { inverse: "dependency_of", class: "state", subjects: ["project", "product"], objects: ["tool", "project"], cardinality: "multi" },
89
+ dependency_of: { inverse: "depends_on", class: "state", subjects: ["tool", "project"], objects: ["project", "product"], cardinality: "multi" },
90
+ // Event
91
+ attended: { inverse: "had_attendee", class: "event", subjects: ["person"], objects: ["meeting"], cardinality: "multi" },
92
+ had_attendee: { inverse: "attended", class: "event", subjects: ["meeting"], objects: ["person"], cardinality: "multi" },
93
+ decided: { inverse: "decided_by", class: "event", subjects: ["person"], objects: ["decision"], cardinality: "multi" },
94
+ decided_by: { inverse: "decided", class: "event", subjects: ["decision"], objects: ["person"], cardinality: "multi" },
95
+ decided_in: { inverse: "produced_decision", class: "event", subjects: ["decision"], objects: ["meeting"], cardinality: "multi" },
96
+ produced_decision: { inverse: "decided_in", class: "event", subjects: ["meeting"], objects: ["decision"], cardinality: "multi" },
97
+ about: { inverse: "discussed_in", class: "event", subjects: ["decision", "meeting"], objects: ["*"], cardinality: "multi" },
98
+ discussed_in: { inverse: "about", class: "event", subjects: ["*"], objects: ["decision", "meeting"], cardinality: "multi" },
99
+ supersedes: { inverse: "superseded_by", class: "event", subjects: ["decision"], objects: ["decision"], cardinality: "multi" },
100
+ superseded_by: { inverse: "supersedes", class: "event", subjects: ["decision"], objects: ["decision"], cardinality: "multi" },
101
+ // Reference
102
+ mentions: { inverse: "mentioned_in", class: "reference", subjects: ["*"], objects: ["*"], cardinality: "multi" },
103
+ mentioned_in: { inverse: "mentions", class: "reference", subjects: ["*"], objects: ["*"], cardinality: "multi" },
104
+ related_to: { inverse: "related_to", class: "reference", subjects: ["*"], objects: ["*"], cardinality: "multi" },
105
+ };
106
+ export const VERB_NAMES = Object.keys(VERBS);
107
+ /** Thrown by the store when a row fails validation. Nothing is written. */
108
+ export class RowRefusedError extends Error {
109
+ code;
110
+ entity;
111
+ refusals;
112
+ constructor(entity, refusals) {
113
+ super(`ontology graph: row refused on ${entity}: ${refusals.map((r) => `${r.code} (${r.message})`).join("; ")}`);
114
+ this.name = "RowRefusedError";
115
+ this.entity = entity;
116
+ this.refusals = refusals;
117
+ this.code = refusals[0]?.code ?? "grammar";
118
+ }
119
+ }
120
+ // ---------------------------------------------------------------------------
121
+ // Replay (WP-B)
122
+ // ---------------------------------------------------------------------------
123
+ export const REPLAY_INPUT_KINDS = ["legacy", "signal", "source", "doc", "prd", "session", "org-layer"];
124
+ /** Thrown by a reader factory or entry point that needs a member and has none. */
125
+ export class MemberIdentityRequiredError extends Error {
126
+ constructor(what) {
127
+ super(`ontology graph: ${what} needs a member identity (--member <person uid> or HQ_ONTOLOGY_MEMBER)`);
128
+ this.name = "MemberIdentityRequiredError";
129
+ }
130
+ }
131
+ //# sourceMappingURL=types.js.map
@@ -32,7 +32,7 @@ export const GITLEAKS_CONFIG = {
32
32
  "(?:^|/)\\.git$"
33
33
  ],
34
34
  "regexes": [
35
- "(?i)^true|false|null$",
35
+ "(?i)^(?:true|false|null)$",
36
36
  "^(?i:a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+|y+|z+|\\*+|\\.+)$",
37
37
  "^\\$(?:\\d+|{\\d+})$",
38
38
  "^\\$(?:[A-Z_]+|[a-z_]+)$",
@@ -25,6 +25,6 @@ export declare function writeHandbackKeep(home: string, vault: {
25
25
  /** Test seam: runs after the temp file is written, before the re-read that guards the rename. */
26
26
  beforeRename?: (attempt: number) => void): void;
27
27
  export declare function engineHoldFile(engineHome: string, vaultUid: string): string;
28
- export declare function readEngineHeldDeletes(engineHome: string, vaultUid: string): EngineHeldDeletes | "unreadable" | null;
28
+ export declare function readEngineHeldDeletes(engineHome: string, vaultUid: string, warn?: (line: string) => void): EngineHeldDeletes | "unreadable" | null;
29
29
  export declare function heldDeletesHandoverLine(vaultUid: string, held: EngineHeldDeletes | "unreadable", engineHome: string, home: string): string;
30
30
  //# sourceMappingURL=engine-holds.d.ts.map
@@ -78,7 +78,7 @@ function readTextOrNull(file) {
78
78
  export function engineHoldFile(engineHome, vaultUid) {
79
79
  return path.join(engineHome, ".hq", "sync-core", "holds", `${vaultUid}.json`);
80
80
  }
81
- export function readEngineHeldDeletes(engineHome, vaultUid) {
81
+ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
82
82
  let text;
83
83
  try {
84
84
  const file = engineHoldFile(engineHome, vaultUid);
@@ -100,11 +100,21 @@ export function readEngineHeldDeletes(engineHome, vaultUid) {
100
100
  if (!hold || !Array.isArray(hold.groups))
101
101
  return "unreadable";
102
102
  const deletes = [];
103
+ const unknown = new Set();
103
104
  let count = 0;
104
105
  for (const value of hold.groups) {
105
106
  const group = record(value);
106
- if (!group || (group.direction !== "delete_local" && group.direction !== "delete_remote"))
107
+ if (!group || typeof group.direction !== "string")
107
108
  return "unreadable";
109
+ if (group.direction === "overwrite_local")
110
+ continue;
111
+ if (group.direction !== "delete_local" && group.direction !== "delete_remote") {
112
+ if (!unknown.has(group.direction)) {
113
+ unknown.add(group.direction);
114
+ warn(`${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} has a kind of hold this hq does not know (direction ${JSON.stringify(group.direction.slice(0, 64))}); it is not passed to the current sync, the deletes held beside it are`);
115
+ }
116
+ continue;
117
+ }
108
118
  const paths = Array.isArray(group.paths) ? group.paths.filter((p) => typeof p === "string") : [];
109
119
  const declared = typeof group.count === "number" && Number.isSafeInteger(group.count) && group.count >= 0 ? group.count : 0;
110
120
  count += Math.max(paths.length, declared);
@@ -1,4 +1,5 @@
1
1
  import { legacySwitchRestorePatch, type VaultSyncSwitches } from "../vault-sync-switches.js";
2
+ import { removeLegacyJournalExport } from "./legacy-journal-export.js";
2
3
  export interface HandBackVault {
3
4
  uid: string;
4
5
  kind: "personal" | "company";
@@ -13,5 +14,5 @@ export declare function engineOwnsVault(home: string, uid: string): boolean;
13
14
  * has exited; the runner resumes a vault as soon as both are done. Throws
14
15
  * before removing any record when menubar.json cannot be written.
15
16
  */
16
- export declare function finishLegacyHandBack(home: string, vaults: readonly HandBackVault[], switches?: Pick<VaultSyncSwitches, "personalOff" | "offCompanies">): ReturnType<typeof legacySwitchRestorePatch>;
17
+ export declare function finishLegacyHandBack(home: string, vaults: readonly HandBackVault[], switches?: Pick<VaultSyncSwitches, "personalOff" | "offCompanies">, warn?: (line: string) => void, removeExport?: typeof removeLegacyJournalExport): ReturnType<typeof legacySwitchRestorePatch>;
17
18
  //# sourceMappingURL=hand-back.d.ts.map
@@ -2,6 +2,8 @@ import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { legacySwitchRestorePatch, writeVaultSyncSwitches } from "../vault-sync-switches.js";
4
4
  import { removeEngineOwnership, syncCoreEngineHome } from "./engine-home.js";
5
+ import { removeLegacyJournalExport } from "./legacy-journal-export.js";
6
+ const reportedRemovalFailures = new Set();
5
7
  export function engineOwnsVault(home, uid) {
6
8
  return fs.existsSync(path.join(syncCoreEngineHome(home, uid), ".hq", "sync-core", "owned", `${uid}.json`));
7
9
  }
@@ -12,12 +14,24 @@ export function engineOwnsVault(home, uid) {
12
14
  * has exited; the runner resumes a vault as soon as both are done. Throws
13
15
  * before removing any record when menubar.json cannot be written.
14
16
  */
15
- export function finishLegacyHandBack(home, vaults, switches) {
17
+ export function finishLegacyHandBack(home, vaults, switches, warn = (line) => void process.stderr.write(`${line}\n`), removeExport = removeLegacyJournalExport) {
16
18
  const patch = legacySwitchRestorePatch(vaults, switches);
17
19
  if (patch.personal || Object.keys(patch.companies).length > 0)
18
20
  writeVaultSyncSwitches(home, patch);
19
- for (const vault of vaults)
21
+ for (const vault of vaults) {
22
+ const key = `${home}\0${vault.uid}`;
23
+ try {
24
+ removeExport(home, vault);
25
+ reportedRemovalFailures.delete(key);
26
+ }
27
+ catch (error) {
28
+ if (!reportedRemovalFailures.has(key)) {
29
+ reportedRemovalFailures.add(key);
30
+ warn(`${vault.uid}: could not remove the copy of the current sync's record of ${vault.slug ?? vault.uid} kept for the new sync engine: ${error instanceof Error ? error.message : String(error)}`);
31
+ }
32
+ }
20
33
  removeEngineOwnership(home, vault.uid);
34
+ }
21
35
  return patch;
22
36
  }
23
37
  //# sourceMappingURL=hand-back.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=legacy-journal-export-child.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { bundledHqCloud, currentHqCloud } from "../daemon/hq-cloud.js";
2
+ import { daemonPaths } from "../daemon/paths.js";
3
+ import { writeLegacyJournalExport } from "./legacy-journal-export.js";
4
+ import { loadLegacyJournalReader } from "./legacy-journal-reader.js";
5
+ const [home, uid, slug, offSince] = process.argv.slice(2);
6
+ try {
7
+ if (!home || !uid || !slug)
8
+ throw new Error("usage: legacy-journal-export-child <home> <vault uid> <slug>");
9
+ const loaded = await loadLegacyJournalReader([currentHqCloud(daemonPaths(home, process.env).root), bundledHqCloud()]);
10
+ if (!loaded.reader)
11
+ throw new Error(loaded.reason);
12
+ writeLegacyJournalExport({
13
+ home,
14
+ vault: { uid, kind: "company", slug },
15
+ readJournal: loaded.reader,
16
+ ...(offSince && Number.isFinite(Date.parse(offSince)) ? { offSince: Date.parse(offSince) } : {}),
17
+ });
18
+ process.exit(0);
19
+ }
20
+ catch (error) {
21
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
22
+ process.exit(1);
23
+ }
24
+ //# sourceMappingURL=legacy-journal-export-child.js.map
@@ -0,0 +1,39 @@
1
+ export interface LegacyJournalSource {
2
+ files: Record<string, unknown>;
3
+ }
4
+ export type LegacyJournalReader = (slug: string, stateDir: string) => LegacyJournalSource;
5
+ export interface LegacyJournalExportVault {
6
+ uid: string;
7
+ kind: "personal" | "company";
8
+ slug?: string;
9
+ }
10
+ export type LegacyJournalExportResult = {
11
+ status: "written";
12
+ entries: number;
13
+ file: string;
14
+ replaced: boolean;
15
+ } | {
16
+ status: "present" | "consumed" | "not-company" | "no-journal";
17
+ };
18
+ export type LegacyJournalExportState = "present" | "unusable" | "consumed" | "missing" | "not-company";
19
+ export declare const LEGACY_JOURNAL_EXPORT_MAX_BYTES: number;
20
+ export declare const LEGACY_JOURNAL_EXPORT_MAX_AHEAD_MS: number;
21
+ export declare function legacyJournalExportPath(home: string, uid: string, slug: string): string;
22
+ export declare function legacyJournalConsumedPath(home: string, uid: string, slug: string): string;
23
+ export declare function legacyJournalUnprovenPath(home: string, uid: string, slug: string): string;
24
+ export declare function legacyJournalExportState(home: string, vault: LegacyJournalExportVault, now?: number): LegacyJournalExportState;
25
+ export declare function legacyStateDir(home: string, env: NodeJS.ProcessEnv): string;
26
+ export declare function legacyStateDirs(home: string, env: NodeJS.ProcessEnv): string[];
27
+ export declare function legacyJournalDirs(home: string, env: NodeJS.ProcessEnv, slug: string): string[];
28
+ export declare function removeLegacyJournalTemps(home: string, vault: LegacyJournalExportVault): void;
29
+ export interface WriteLegacyJournalExportOptions {
30
+ home: string;
31
+ vault: LegacyJournalExportVault;
32
+ readJournal: LegacyJournalReader;
33
+ env?: NodeJS.ProcessEnv;
34
+ now?: () => number;
35
+ offSince?: number;
36
+ }
37
+ export declare function writeLegacyJournalExport(opts: WriteLegacyJournalExportOptions): LegacyJournalExportResult;
38
+ export declare function removeLegacyJournalExport(home: string, vault: LegacyJournalExportVault): void;
39
+ //# sourceMappingURL=legacy-journal-export.d.ts.map
@@ -0,0 +1,241 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { machineTokenStateDir } from "../../utils/machine-token-cache.js";
4
+ import { syncCoreEngineHome } from "./engine-home.js";
5
+ export const LEGACY_JOURNAL_EXPORT_MAX_BYTES = 256 * 1024 * 1024;
6
+ export const LEGACY_JOURNAL_EXPORT_MAX_AHEAD_MS = 5 * 60 * 1000;
7
+ const ENTRY_FIELDS = ["hash", "size", "kind", "syncedAt", "localDiverges", "removedAt", "localDeleteIntent"];
8
+ const SLUG = /^[A-Za-z0-9_-]+$/;
9
+ const CHUNK_ENTRIES = 512;
10
+ const HEAD_BYTES = 256;
11
+ function exportDir(home, uid) {
12
+ return path.join(syncCoreEngineHome(home, uid), ".hq", "sync-core", "legacy-journal");
13
+ }
14
+ export function legacyJournalExportPath(home, uid, slug) {
15
+ return path.join(exportDir(home, uid), `${slug}.json`);
16
+ }
17
+ export function legacyJournalConsumedPath(home, uid, slug) {
18
+ return `${legacyJournalExportPath(home, uid, slug)}.consumed`;
19
+ }
20
+ export function legacyJournalUnprovenPath(home, uid, slug) {
21
+ return `${legacyJournalExportPath(home, uid, slug)}.unproven`;
22
+ }
23
+ function exportable(vault) {
24
+ return vault.kind === "company" && vault.uid.startsWith("cmp_") && typeof vault.slug === "string" && SLUG.test(vault.slug);
25
+ }
26
+ function exists(file) {
27
+ try {
28
+ fs.lstatSync(file);
29
+ return true;
30
+ }
31
+ catch (error) {
32
+ if (error.code === "ENOENT")
33
+ return false;
34
+ throw error;
35
+ }
36
+ }
37
+ function usableExport(file, now) {
38
+ const stat = fs.lstatSync(file);
39
+ if (!stat.isFile() || stat.size > LEGACY_JOURNAL_EXPORT_MAX_BYTES)
40
+ return false;
41
+ const fd = fs.openSync(file, "r");
42
+ let head;
43
+ try {
44
+ const buffer = Buffer.alloc(HEAD_BYTES);
45
+ head = buffer.subarray(0, fs.readSync(fd, buffer, 0, HEAD_BYTES, 0)).toString("utf8");
46
+ }
47
+ finally {
48
+ fs.closeSync(fd);
49
+ }
50
+ const match = /^\{"version":"2","exportedAt":(\d{1,16}),"files":\{/.exec(head);
51
+ if (!match)
52
+ return false;
53
+ const exportedAt = Number(match[1]);
54
+ return Number.isSafeInteger(exportedAt) && exportedAt - now <= LEGACY_JOURNAL_EXPORT_MAX_AHEAD_MS;
55
+ }
56
+ export function legacyJournalExportState(home, vault, now = Date.now()) {
57
+ if (!exportable(vault))
58
+ return "not-company";
59
+ if (exists(legacyJournalConsumedPath(home, vault.uid, vault.slug)))
60
+ return "consumed";
61
+ const file = legacyJournalExportPath(home, vault.uid, vault.slug);
62
+ if (!exists(file))
63
+ return "missing";
64
+ return usableExport(file, now) ? "present" : "unusable";
65
+ }
66
+ export function legacyStateDir(home, env) {
67
+ return env.HQ_STATE_DIR ?? path.join(home, ".hq");
68
+ }
69
+ export function legacyStateDirs(home, env) {
70
+ return [...new Set([legacyStateDir(home, env), path.join(home, ".hq"), machineTokenStateDir(home, env)])];
71
+ }
72
+ export function legacyJournalDirs(home, env, slug) {
73
+ return legacyStateDirs(home, env).filter((dir) => fs.existsSync(path.join(dir, `sync-journal.${slug}.json`)));
74
+ }
75
+ function syncedAtMs(value) {
76
+ if (typeof value === "number")
77
+ return Number.isFinite(value) ? value : 0;
78
+ if (typeof value !== "string")
79
+ return 0;
80
+ const ms = Date.parse(value);
81
+ return Number.isFinite(ms) ? ms : 0;
82
+ }
83
+ function newestSyncedAt(files) {
84
+ let newest = 0;
85
+ for (const key of Object.keys(files)) {
86
+ const at = entrySyncedAt(files[key]);
87
+ if (at > newest)
88
+ newest = at;
89
+ }
90
+ return newest;
91
+ }
92
+ function entrySyncedAt(entry) {
93
+ return entry && typeof entry === "object" ? syncedAtMs(entry.syncedAt) : 0;
94
+ }
95
+ function entryHash(entry) {
96
+ return entry && typeof entry === "object" ? entry.hash : undefined;
97
+ }
98
+ function lastSyncedEntries(slug, dirs, readJournal, offSince) {
99
+ const read = dirs
100
+ .map((dir) => {
101
+ const files = readJournal(slug, dir).files;
102
+ return { dir, files, count: files && typeof files === "object" ? Object.keys(files).length : 0 };
103
+ })
104
+ .filter((journal) => journal.count > 0);
105
+ if (read.length === 0)
106
+ throw new Error(`the current sync has a journal for ${slug} but it read as empty`);
107
+ if (read.length === 1)
108
+ return read[0].files;
109
+ if (offSince !== undefined && Number.isFinite(offSince) && read.some((journal) => newestSyncedAt(journal.files) > offSince)) {
110
+ throw new Error(`the current sync has journals for ${slug} in ${read.map((journal) => journal.dir).join(" and ")}, and one was written after its switch was turned off, so it is not clear what it last synced`);
111
+ }
112
+ const merged = Object.create(null);
113
+ const disputed = new Set();
114
+ for (const journal of read) {
115
+ for (const key of Object.keys(journal.files)) {
116
+ const entry = journal.files[key];
117
+ if (!(key in merged)) {
118
+ merged[key] = entry;
119
+ continue;
120
+ }
121
+ const kept = merged[key];
122
+ const at = entrySyncedAt(entry);
123
+ const keptAt = entrySyncedAt(kept);
124
+ if (at > keptAt) {
125
+ merged[key] = entry;
126
+ disputed.delete(key);
127
+ }
128
+ else if (at === keptAt && entryHash(entry) !== entryHash(kept)) {
129
+ disputed.add(key);
130
+ }
131
+ }
132
+ }
133
+ for (const key of disputed)
134
+ delete merged[key];
135
+ return merged;
136
+ }
137
+ export function removeLegacyJournalTemps(home, vault) {
138
+ if (!exportable(vault))
139
+ return;
140
+ const dir = exportDir(home, vault.uid);
141
+ let names;
142
+ try {
143
+ names = fs.readdirSync(dir);
144
+ }
145
+ catch (error) {
146
+ if (error.code === "ENOENT")
147
+ return;
148
+ throw error;
149
+ }
150
+ const prefix = `${vault.slug}.json.`;
151
+ for (const name of names) {
152
+ if (name.startsWith(prefix) && name.endsWith(".tmp"))
153
+ fs.rmSync(path.join(dir, name), { recursive: true, force: true });
154
+ }
155
+ }
156
+ function exportedEntry(value) {
157
+ if (!value || typeof value !== "object" || Array.isArray(value))
158
+ return undefined;
159
+ const entry = value;
160
+ const out = {};
161
+ for (const field of ENTRY_FIELDS) {
162
+ if (entry[field] !== undefined)
163
+ out[field] = entry[field];
164
+ }
165
+ return out;
166
+ }
167
+ export function writeLegacyJournalExport(opts) {
168
+ const { home, vault } = opts;
169
+ const now = opts.now ?? Date.now;
170
+ const state = legacyJournalExportState(home, vault, now());
171
+ if (state !== "missing" && state !== "unusable")
172
+ return { status: state };
173
+ const slug = vault.slug;
174
+ const dirs = legacyJournalDirs(home, opts.env ?? process.env, slug);
175
+ if (dirs.length === 0)
176
+ return { status: "no-journal" };
177
+ const files = lastSyncedEntries(slug, dirs, opts.readJournal, opts.offSince);
178
+ const keys = Object.keys(files);
179
+ const file = legacyJournalExportPath(home, vault.uid, slug);
180
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
181
+ removeLegacyJournalTemps(home, vault);
182
+ const tmp = `${file}.${process.pid}.tmp`;
183
+ const fd = fs.openSync(tmp, "wx", 0o600);
184
+ let entries = 0;
185
+ let closed = false;
186
+ try {
187
+ fs.writeSync(fd, `{"version":"2","exportedAt":${now()},"files":{`);
188
+ let chunk = [];
189
+ for (const key of keys) {
190
+ const entry = exportedEntry(files[key]);
191
+ if (!entry)
192
+ continue;
193
+ chunk.push(`${entries > 0 ? "," : ""}${JSON.stringify(key)}:${JSON.stringify(entry)}`);
194
+ entries += 1;
195
+ if (chunk.length >= CHUNK_ENTRIES) {
196
+ fs.writeSync(fd, chunk.join(""));
197
+ chunk = [];
198
+ }
199
+ }
200
+ fs.writeSync(fd, `${chunk.join("")}}}\n`);
201
+ if (entries === 0)
202
+ throw new Error(`the current sync's journal for ${slug} has no usable entries`);
203
+ if (fs.fstatSync(fd).size > LEGACY_JOURNAL_EXPORT_MAX_BYTES) {
204
+ throw new Error(`the copy of the current sync's journal for ${slug} is over ${LEGACY_JOURNAL_EXPORT_MAX_BYTES / (1024 * 1024)} MB, more than the new sync engine reads`);
205
+ }
206
+ fs.fsyncSync(fd);
207
+ closed = true;
208
+ fs.closeSync(fd);
209
+ }
210
+ catch (error) {
211
+ if (!closed)
212
+ fs.closeSync(fd);
213
+ fs.rmSync(tmp, { force: true });
214
+ throw error;
215
+ }
216
+ try {
217
+ const settled = legacyJournalExportState(home, vault, now());
218
+ if (settled !== "missing" && settled !== "unusable") {
219
+ fs.rmSync(tmp, { force: true });
220
+ return { status: settled };
221
+ }
222
+ if (settled === "unusable" && !fs.lstatSync(file).isFile())
223
+ fs.rmSync(file, { recursive: true, force: true });
224
+ fs.renameSync(tmp, file);
225
+ return { status: "written", entries, file, replaced: settled === "unusable" };
226
+ }
227
+ catch (error) {
228
+ fs.rmSync(tmp, { force: true });
229
+ throw error;
230
+ }
231
+ }
232
+ export function removeLegacyJournalExport(home, vault) {
233
+ if (!exportable(vault))
234
+ return;
235
+ const file = legacyJournalExportPath(home, vault.uid, vault.slug);
236
+ for (const target of [file, `${file}.consumed`, `${file}.unproven`, `${file}.unproven.bad`]) {
237
+ fs.rmSync(target, { recursive: true, force: true });
238
+ }
239
+ removeLegacyJournalTemps(home, vault);
240
+ }
241
+ //# sourceMappingURL=legacy-journal-export.js.map
@@ -0,0 +1,15 @@
1
+ import type { LegacyJournalReader } from "./legacy-journal-export.js";
2
+ export declare const LEGACY_JOURNAL_READ_API = "readJournalWithoutWrites";
3
+ export interface LegacyJournalReaderSource {
4
+ root: string;
5
+ version: string;
6
+ }
7
+ export type LoadedLegacyJournalReader = {
8
+ reader: LegacyJournalReader;
9
+ source: LegacyJournalReaderSource;
10
+ } | {
11
+ reader?: undefined;
12
+ reason: string;
13
+ };
14
+ export declare function loadLegacyJournalReader(copies: readonly (LegacyJournalReaderSource | null | undefined)[], importModule?: (url: string) => Promise<Record<string, unknown>>): Promise<LoadedLegacyJournalReader>;
15
+ //# sourceMappingURL=legacy-journal-reader.d.ts.map
@@ -0,0 +1,56 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ export const LEGACY_JOURNAL_READ_API = "readJournalWithoutWrites";
5
+ function entryFile(root) {
6
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
7
+ return path.join(root, typeof pkg.main === "string" ? pkg.main : "dist/index.js");
8
+ }
9
+ function readerFrom(module) {
10
+ const read = module[LEGACY_JOURNAL_READ_API];
11
+ if (typeof read !== "function")
12
+ return undefined;
13
+ return (slug, stateDir) => {
14
+ const before = process.env.HQ_STATE_DIR;
15
+ process.env.HQ_STATE_DIR = stateDir;
16
+ let result;
17
+ try {
18
+ result = read(slug);
19
+ }
20
+ finally {
21
+ if (before === undefined)
22
+ delete process.env.HQ_STATE_DIR;
23
+ else
24
+ process.env.HQ_STATE_DIR = before;
25
+ }
26
+ if (!result || typeof result !== "object")
27
+ throw new Error(`${LEGACY_JOURNAL_READ_API} returned no result for ${slug}`);
28
+ if (result.status === "empty")
29
+ return { files: {} };
30
+ if (result.status !== "ok" || !result.files || typeof result.files !== "object") {
31
+ const why = typeof result.errorClass === "string" ? ` (${result.errorClass})` : "";
32
+ throw new Error(`the current sync's journal for ${slug} in ${stateDir} could not be read${why}`);
33
+ }
34
+ return { files: result.files };
35
+ };
36
+ }
37
+ export async function loadLegacyJournalReader(copies, importModule = (url) => import(url)) {
38
+ const seen = new Set();
39
+ const reasons = [];
40
+ for (const copy of copies) {
41
+ if (!copy || seen.has(copy.root))
42
+ continue;
43
+ seen.add(copy.root);
44
+ try {
45
+ const reader = readerFrom(await importModule(pathToFileURL(entryFile(copy.root)).href));
46
+ if (reader)
47
+ return { reader, source: copy };
48
+ reasons.push(`hq-cloud ${copy.version} cannot read a journal without writing to it`);
49
+ }
50
+ catch (error) {
51
+ reasons.push(`hq-cloud ${copy.version} at ${copy.root} could not be loaded: ${error instanceof Error ? error.message : String(error)}`);
52
+ }
53
+ }
54
+ return { reason: reasons.length > 0 ? reasons.join("; ") : "no hq-cloud copy was found" };
55
+ }
56
+ //# sourceMappingURL=legacy-journal-reader.js.map
@@ -2,6 +2,7 @@ import { type SyncCoreVault } from "./engine-home.js";
2
2
  import { type SyncCoreBinaryInstall, type SyncCorePin } from "./release.js";
3
3
  import type { MachineType } from "../daemon/machine-type.js";
4
4
  import { type SyncCoreCompanyEntity } from "./company-adoption.js";
5
+ import { type LegacyJournalReader } from "./legacy-journal-export.js";
5
6
  import { type SyncCoreRolloutState } from "./rollout-state.js";
6
7
  export interface SyncCoreMembership {
7
8
  companyUid: string;
@@ -27,6 +28,8 @@ export interface SyncCoreReconcileDeps {
27
28
  * can adopt it without a pass of the current sync. Omitted: nothing is set up.
28
29
  */
29
30
  resolveCompany?: (companyUid: string) => Promise<SyncCoreCompanyEntity | null>;
31
+ readLegacyJournal?: LegacyJournalReader;
32
+ legacyJournalUnavailable?: string;
30
33
  /** Only desktop and self-hosted machines set up a joined company. */
31
34
  machineType?: MachineType;
32
35
  ensureBinary: (release: string) => Promise<SyncCoreBinaryInstall>;