@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,65 @@
1
+ /**
2
+ * WP-B: who a run is for when no `--member` was given (correction C5).
3
+ *
4
+ * The member is the person signed in to the CLI on this machine, found the way
5
+ * `hq whoami` finds them and with no network call:
6
+ * 1. the daemon's cached whoami answer, when it is current for this session;
7
+ * 2. else the signed-in email from the local token cache, matched to the
8
+ * company roster entry (`people/<slug>/meta.yaml`) that carries a person uid.
9
+ * The audience keys the member holds are discovered from the vault by
10
+ * `resolveMemberScope` (the `@key` folders whose audience lists the member).
11
+ */
12
+ import * as path from "node:path";
13
+ import { readCachedWhoami } from "../../daemon/whoami-cache.js";
14
+ import { localWhoamiIdentity } from "../../../utils/whoami-identity.js";
15
+ import { asRecord, asString, listFolders, readYamlFile } from "./util.js";
16
+ const PERSON_UID = /^prs_[A-Za-z0-9]{6,}$/;
17
+ /**
18
+ * The member for a signed-in person: the cached person uid when there is one,
19
+ * else the one roster entry whose email is the signed-in email. A machine
20
+ * (agent) sign-in, a signed-out session, or an email on two roster entries
21
+ * gives no answer.
22
+ */
23
+ export function memberFromIdentity(context, identity, cachedPersonUid = null) {
24
+ if (!identity.authenticated || identity.tokenSource !== "person")
25
+ return null;
26
+ if (cachedPersonUid && PERSON_UID.test(cachedPersonUid))
27
+ return { personUid: cachedPersonUid, audienceKeys: [] };
28
+ const email = (identity.delegatedEmail ?? identity.email ?? "").toLowerCase();
29
+ if (!email)
30
+ return null;
31
+ const matches = new Set();
32
+ for (const slug of listFolders(path.join(context.companyRoot, "people"))) {
33
+ if (slug.startsWith("_"))
34
+ continue;
35
+ const meta = readYamlFile(path.join(context.companyRoot, "people", slug, "meta.yaml"));
36
+ const uid = asString(asRecord(meta.handles).hq_person_uid);
37
+ if (asString(meta.email).toLowerCase() === email && PERSON_UID.test(uid))
38
+ matches.add(uid);
39
+ }
40
+ return matches.size === 1 ? { personUid: [...matches][0], audienceKeys: [] } : null;
41
+ }
42
+ export function resolveSignedInMember(context, env = process.env) {
43
+ try {
44
+ const local = localWhoamiIdentity(env);
45
+ let cached;
46
+ try {
47
+ cached = readCachedWhoami({ env, local: () => local })?.personUid ?? null;
48
+ }
49
+ catch {
50
+ cached = null;
51
+ }
52
+ return memberFromIdentity(context, local, cached);
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
58
+ /** `context` with its member filled in from the sign-in when it had none. */
59
+ export function withMember(context, resolve = (ctx) => resolveSignedInMember(ctx)) {
60
+ if (context.member)
61
+ return context;
62
+ const member = resolve(context);
63
+ return member ? { ...context, member } : context;
64
+ }
65
+ //# sourceMappingURL=member.js.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * WP-B: finding names in text and asking the resolver about them.
3
+ *
4
+ * The replay never decides who a name is. It proposes candidates (old entity
5
+ * refs, name fields, capitalized runs and dash-joined tokens in free text) and
6
+ * WP-C's resolver answers. Answers are memoized per resolver for the run.
7
+ */
8
+ import type { AudienceKey, EntityRef, GraphEntityType, GraphSchema, GraphStore, Resolver } from "../types.js";
9
+ /**
10
+ * The resolver as the replay uses it: counts questions and answers, and tells
11
+ * the resolver which audience an entity gained rows in when it can take that
12
+ * (WP-C's resolver keeps audiences per entity; dedup never crosses them).
13
+ * Answers within one input are memoized; the memo is dropped whenever the
14
+ * resolver learns something, so it never outlives what it was computed from.
15
+ */
16
+ export interface CountingResolver extends Resolver {
17
+ readonly calls: {
18
+ asked: number;
19
+ memoHits: number;
20
+ resolved: number;
21
+ };
22
+ noteAudience(ref: EntityRef, audience: AudienceKey): void;
23
+ /** Drops memoized answers: the resolver underneath was told something new (a fuzzy pair was answered). */
24
+ forget(): void;
25
+ }
26
+ export declare function countingResolver(inner: Resolver): CountingResolver;
27
+ /**
28
+ * Candidate names in free text, longest first: runs of capitalized words (up
29
+ * to four words) and their sub-runs, then dash-joined lower-case tokens
30
+ * (`hq-cli`). Deterministic. The resolver decides which are entities.
31
+ */
32
+ export declare function nameCandidates(text: string, maxChars?: number): string[];
33
+ /** Entities named in free text. Silent about misses: free text is full of words that are not names. */
34
+ export declare function resolveNamesInText(resolver: Resolver, text: string, options?: {
35
+ types?: readonly GraphEntityType[];
36
+ audiences?: readonly AudienceKey[];
37
+ limit?: number;
38
+ }): EntityRef[];
39
+ /**
40
+ * Open edges already on a subject, loaded once per subject. A state edge that
41
+ * many inputs would repeat (a person works on a project) is written from the
42
+ * first input that shows it; later inputs add timeline rows only.
43
+ */
44
+ export interface EdgeMemo {
45
+ has(subject: EntityRef, audience: AudienceKey, verb: string, target: EntityRef): boolean;
46
+ add(subject: EntityRef, audience: AudienceKey, verb: string, target: EntityRef): void;
47
+ }
48
+ export declare function createEdgeMemo(store: GraphStore): EdgeMemo;
49
+ /**
50
+ * A minimal stand-in used only while WP-C's resolver is still a stub, so the
51
+ * replay and its tests can run: identity keys, then exact normalized name or
52
+ * alias, with the schema's refusal lists. No fuzzy pass. A name shared by two
53
+ * entities is ambiguous.
54
+ */
55
+ export declare function createFallbackResolver(store: GraphStore, schema: GraphSchema): Resolver;
56
+ /** A slug for a new entity made from a name; empty when the name has nothing usable. */
57
+ export declare function slugForName(name: string): string;
58
+ //# sourceMappingURL=mentions.d.ts.map
@@ -0,0 +1,239 @@
1
+ import { slugify } from "../schema/index.js";
2
+ function mentionKey(mention) {
3
+ const keys = mention.keys ?? {};
4
+ return [
5
+ mention.text.trim().toLowerCase(),
6
+ (mention.types ?? []).join(","),
7
+ (keys.email ?? []).join(","),
8
+ (keys.slack_id ?? []).join(","),
9
+ (keys.external_ids ?? []).join(","),
10
+ (keys.web_domains ?? []).join(","),
11
+ (mention.audiences ?? []).join(","),
12
+ ].join("\u0001");
13
+ }
14
+ export function countingResolver(inner) {
15
+ const memo = new Map();
16
+ const calls = { asked: 0, memoHits: 0, resolved: 0 };
17
+ const noted = new Set();
18
+ const note = inner.noteAudience?.bind(inner);
19
+ const resolve = (mention) => {
20
+ const key = mentionKey(mention);
21
+ const known = memo.get(key);
22
+ if (known) {
23
+ calls.memoHits += 1;
24
+ return known;
25
+ }
26
+ calls.asked += 1;
27
+ const answer = inner.resolve(mention);
28
+ if (answer.status === "resolved")
29
+ calls.resolved += 1;
30
+ memo.set(key, answer);
31
+ return answer;
32
+ };
33
+ return {
34
+ calls,
35
+ resolve,
36
+ resolveMany: (mentions) => mentions.map(resolve),
37
+ forget: () => memo.clear(),
38
+ remember(entity) {
39
+ inner.remember(entity);
40
+ memo.clear();
41
+ },
42
+ noteAudience(ref, audience) {
43
+ const key = `${ref}@${audience}`;
44
+ if (noted.has(key))
45
+ return;
46
+ noted.add(key);
47
+ if (note) {
48
+ note(ref, audience);
49
+ memo.clear();
50
+ }
51
+ },
52
+ };
53
+ }
54
+ const CONNECTORS = new Set(["of", "the", "and", "for", "&", "de", "van", "von"]);
55
+ const SLUG_TOKEN = /\b[a-z][a-z0-9]*(?:-[a-z0-9]+)+\b/g;
56
+ /**
57
+ * Candidate names in free text, longest first: runs of capitalized words (up
58
+ * to four words) and their sub-runs, then dash-joined lower-case tokens
59
+ * (`hq-cli`). Deterministic. The resolver decides which are entities.
60
+ */
61
+ export function nameCandidates(text, maxChars = 2400) {
62
+ const sample = text.length > maxChars ? text.slice(0, maxChars) : text;
63
+ const found = new Set();
64
+ const words = sample.split(/[\s]+/).map((word) => word.replace(/^[^\p{L}\p{N}@#]+|[^\p{L}\p{N}]+$/gu, ""));
65
+ let run = [];
66
+ const flush = () => {
67
+ while (run.length > 0 && CONNECTORS.has(run[run.length - 1].toLowerCase()))
68
+ run.pop();
69
+ for (let size = Math.min(4, run.length); size >= 1; size--) {
70
+ for (let start = 0; start + size <= run.length; start++) {
71
+ const slice = run.slice(start, start + size);
72
+ if (CONNECTORS.has(slice[0].toLowerCase()) || CONNECTORS.has(slice[slice.length - 1].toLowerCase()))
73
+ continue;
74
+ found.add(slice.join(" "));
75
+ }
76
+ }
77
+ run = [];
78
+ };
79
+ for (const word of words) {
80
+ const capital = /^\p{Lu}/u.test(word) && !word.startsWith("@") && !word.startsWith("#");
81
+ if (word !== "" && (capital || (run.length > 0 && CONNECTORS.has(word.toLowerCase())))) {
82
+ run.push(word.replace(/['’]s$/u, ""));
83
+ if (run.length >= 6)
84
+ flush();
85
+ }
86
+ else {
87
+ flush();
88
+ }
89
+ }
90
+ flush();
91
+ for (const match of sample.match(SLUG_TOKEN) ?? [])
92
+ found.add(match);
93
+ return [...found].sort((a, b) => b.length - a.length || (a < b ? -1 : a > b ? 1 : 0));
94
+ }
95
+ /** Entities named in free text. Silent about misses: free text is full of words that are not names. */
96
+ export function resolveNamesInText(resolver, text, options = {}) {
97
+ const refs = [];
98
+ const seen = new Set();
99
+ for (const candidate of nameCandidates(text)) {
100
+ const answer = resolver.resolve({
101
+ text: candidate,
102
+ ...(options.types ? { types: options.types } : {}),
103
+ ...(options.audiences ? { audiences: options.audiences } : {}),
104
+ });
105
+ if (answer.status !== "resolved" || !answer.entity || seen.has(answer.entity))
106
+ continue;
107
+ seen.add(answer.entity);
108
+ refs.push(answer.entity);
109
+ if (options.limit && refs.length >= options.limit)
110
+ break;
111
+ }
112
+ return refs;
113
+ }
114
+ export function createEdgeMemo(store) {
115
+ const known = new Map();
116
+ const load = (subject, audience) => {
117
+ const key = `${subject}@${audience}`;
118
+ let set = known.get(key);
119
+ if (!set) {
120
+ set = new Set();
121
+ try {
122
+ for (const stored of store.readRows(subject, { audiences: [audience], kinds: ["E"] })) {
123
+ if (stored.row.kind === "E")
124
+ set.add(`${stored.row.verb}>${stored.row.target}`);
125
+ }
126
+ }
127
+ catch {
128
+ // an unreadable facts file is lint's finding, not a reason to stop the replay
129
+ }
130
+ known.set(key, set);
131
+ }
132
+ return set;
133
+ };
134
+ return {
135
+ has: (subject, audience, verb, target) => load(subject, audience).has(`${verb}>${target}`),
136
+ add: (subject, audience, verb, target) => void load(subject, audience).add(`${verb}>${target}`),
137
+ };
138
+ }
139
+ function normalizeName(name) {
140
+ return name.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
141
+ }
142
+ /**
143
+ * A minimal stand-in used only while WP-C's resolver is still a stub, so the
144
+ * replay and its tests can run: identity keys, then exact normalized name or
145
+ * alias, with the schema's refusal lists. No fuzzy pass. A name shared by two
146
+ * entities is ambiguous.
147
+ */
148
+ export function createFallbackResolver(store, schema) {
149
+ const byKey = new Map();
150
+ const byName = new Map();
151
+ const firstWords = new Map();
152
+ const paths = new Set();
153
+ const index = (entity) => {
154
+ paths.add(entity.id);
155
+ const keys = entity.keys ?? {};
156
+ for (const email of keys.email ?? [])
157
+ byKey.set(`email:${email.toLowerCase()}`, entity.id);
158
+ for (const id of keys.slack_id ?? [])
159
+ byKey.set(`slack:${id}`, entity.id);
160
+ for (const id of keys.external_ids ?? [])
161
+ byKey.set(`ext:${id}`, entity.id);
162
+ for (const domain of keys.web_domains ?? [])
163
+ byKey.set(`domain:${domain.toLowerCase()}`, entity.id);
164
+ for (const name of [entity.canonical_name, entity.slug.replace(/-/g, " "), ...(entity.aliases ?? [])]) {
165
+ const normal = normalizeName(name);
166
+ if (normal === "")
167
+ continue;
168
+ const set = byName.get(normal) ?? new Set();
169
+ set.add(entity.id);
170
+ byName.set(normal, set);
171
+ }
172
+ if (entity.type === "person") {
173
+ const first = normalizeName(entity.canonical_name).split(" ")[0];
174
+ if (first) {
175
+ const set = firstWords.get(first) ?? new Set();
176
+ set.add(entity.id);
177
+ firstWords.set(first, set);
178
+ }
179
+ }
180
+ };
181
+ for (const ref of store.listEntities()) {
182
+ const entity = store.readEntity(ref);
183
+ if (entity)
184
+ index(entity);
185
+ }
186
+ const allowed = (ref, types) => !types || types.length === 0 || types.includes(ref.slice(0, ref.indexOf("/")));
187
+ const refusals = schema.refusals;
188
+ const generic = new Set(refusals.generic_words.map((word) => word.toLowerCase()));
189
+ const titles = refusals.job_titles.map((title) => title.toLowerCase());
190
+ const resolve = (mention) => {
191
+ const keys = mention.keys ?? {};
192
+ const keyed = [
193
+ ...(keys.email ?? []).map((value) => `email:${value.toLowerCase()}`),
194
+ ...(keys.slack_id ?? []).map((value) => `slack:${value}`),
195
+ ...(keys.external_ids ?? []).map((value) => `ext:${value}`),
196
+ ...(keys.web_domains ?? []).map((value) => `domain:${value.toLowerCase()}`),
197
+ ];
198
+ for (const key of keyed) {
199
+ const hit = byKey.get(key);
200
+ if (hit && allowed(hit, mention.types))
201
+ return { status: "resolved", entity: hit, reason: "identity_key", candidates: [hit], score: 1 };
202
+ }
203
+ const text = mention.text.trim();
204
+ const asPath = text.replace(/^ontology\/entities\//, "").replace(/\.md$/, "");
205
+ if (/^[a-z][a-z-]*\/\S+$/.test(asPath) && paths.has(asPath) && allowed(asPath, mention.types)) {
206
+ return { status: "resolved", entity: asPath, reason: "identity_key", candidates: [asPath], score: 1 };
207
+ }
208
+ if (/^[UW][A-Z0-9]{7,}$/.test(text))
209
+ return { status: "unresolved", reason: "unknown_slack_id", candidates: [], score: 0 };
210
+ const normal = normalizeName(text);
211
+ if (normal.length < refusals.min_name_length)
212
+ return { status: "refused", reason: "refused_short", candidates: [], score: 0 };
213
+ if (generic.has(normal))
214
+ return { status: "refused", reason: "refused_generic", candidates: [], score: 0 };
215
+ if (titles.includes(normal) || titles.some((title) => normal.endsWith(` ${title}`) && normal.includes("s "))) {
216
+ return { status: "refused", reason: "refused_job_title", candidates: [], score: 0 };
217
+ }
218
+ const named = [...(byName.get(normal) ?? [])].filter((ref) => allowed(ref, mention.types)).sort();
219
+ if (named.length === 1) {
220
+ const entity = store.readEntity(named[0]);
221
+ const exact = entity ? normalizeName(entity.canonical_name) === normal : false;
222
+ return { status: "resolved", entity: named[0], reason: exact ? "exact_name" : "alias", candidates: named, score: 1 };
223
+ }
224
+ if (named.length > 1)
225
+ return { status: "ambiguous", reason: "ambiguous_name", candidates: named, score: 0.5 };
226
+ if (!normal.includes(" ")) {
227
+ const people = [...(firstWords.get(normal) ?? [])].filter((ref) => allowed(ref, mention.types)).sort();
228
+ if (people.length > 1)
229
+ return { status: "ambiguous", reason: "ambiguous_first_word", candidates: people, score: 0.5 };
230
+ }
231
+ return { status: "unresolved", reason: "no_match", candidates: [], score: 0 };
232
+ };
233
+ return { resolve, resolveMany: (mentions) => mentions.map(resolve), remember: index };
234
+ }
235
+ /** A slug for a new entity made from a name; empty when the name has nothing usable. */
236
+ export function slugForName(name) {
237
+ return slugify(name);
238
+ }
239
+ //# sourceMappingURL=mentions.js.map
@@ -0,0 +1,98 @@
1
+ import type { AudienceKey, EntityRef, GraphContext, IsoDate, ReplayDocument, ReplayInput, ReplayInputKind, ReplayInputReader } from "../types.js";
2
+ import { type ReplayConfig } from "./config.js";
3
+ import { type ListingManifest } from "./listing-manifest.js";
4
+ import { type MemberScope } from "./scope.js";
5
+ export type ClassScope = "company" | "audience" | "personal";
6
+ /** A replay input with its source class. Extractors select on `cls`. */
7
+ export interface ClassedInput extends ReplayInput {
8
+ /** Source class id, as in the corpus manifest (`sources.meetings`, `signals.audience`). */
9
+ cls: string;
10
+ /** Order within a day; lower runs first. */
11
+ priority: number;
12
+ /** When the thing happened. Rows use it for `valid` and timeline dates. */
13
+ eventDate: IsoDate;
14
+ /** The parsed record for inputs that are one entry of a larger file (a CRM account, a commit day). */
15
+ record?: Record<string, unknown>;
16
+ }
17
+ export interface SourceClass {
18
+ readonly id: string;
19
+ readonly kind: ReplayInputKind;
20
+ readonly priority: number;
21
+ readonly scope: ClassScope;
22
+ scan(): ClassedInput[];
23
+ read(input: ClassedInput): ReplayDocument;
24
+ }
25
+ /** What the listing knows about one file under `sources/`. */
26
+ export interface SourceEntry {
27
+ day: IsoDate | null;
28
+ /** Null: the member may not read this source. */
29
+ audience: AudienceKey | null;
30
+ channel: "meeting" | "slack" | "slack-dm" | "other";
31
+ title: string;
32
+ /** `meeting/<slug>` for meetings. */
33
+ entity?: EntityRef;
34
+ owner?: string;
35
+ /** A personal source known to be another person's (this run read its owner, or an earlier run did). */
36
+ foreign?: boolean;
37
+ }
38
+ export interface CorpusStats {
39
+ /** Inputs listed, by class. */
40
+ listed: Record<string, number>;
41
+ /** Files left out, by reason (`personal_not_owner`, `audience_not_held`, `undated`, `no_audience`). */
42
+ excluded: Record<string, number>;
43
+ /** Listing time per class, in ms. The first class that needs the sources catalog pays for it. */
44
+ classMs: Record<string, number>;
45
+ scanMs: number;
46
+ /** Files the listing opened and read in this run. */
47
+ filesRead: number;
48
+ /** Files it did not open because the manifest held their answer (size and mtime unchanged). */
49
+ filesReused: number;
50
+ /** Files it did not open because an earlier run found them withheld and they have not changed since. */
51
+ filesWithheldKnown: number;
52
+ /** `git log` runs made, and repos whose kept history was used because HEAD had not moved. */
53
+ gitRuns: number;
54
+ gitReused: number;
55
+ }
56
+ export interface Corpus {
57
+ readonly scope: MemberScope;
58
+ readonly config: ReplayConfig;
59
+ readonly classes: readonly SourceClass[];
60
+ /** Sorted by day, then class priority, then path. */
61
+ readonly inputs: readonly ClassedInput[];
62
+ readonly days: readonly IsoDate[];
63
+ readonly stats: CorpusStats;
64
+ forDay(day: IsoDate): ClassedInput[];
65
+ read(input: ClassedInput): ReplayDocument;
66
+ }
67
+ export interface ScanOptions {
68
+ config?: ReplayConfig;
69
+ scope?: MemberScope;
70
+ /** Only these class ids. */
71
+ only?: readonly string[];
72
+ /** Folder with the transcript extract cache; null to scan without one. */
73
+ transcriptCacheFile?: string | null;
74
+ /** May the transcript cache be written. */
75
+ writeTranscriptCache?: boolean;
76
+ /** The day the listing runs, for telling a finished week of commits from the one still running. Default: the clock. */
77
+ today?: IsoDate;
78
+ /**
79
+ * The listing manifest file (`.state/replay-listing.json`). Null or absent:
80
+ * nothing is kept and every file is read.
81
+ */
82
+ manifestFile?: string | null;
83
+ /** Use the manifest's kept answers for unchanged files. False lists everything again. Default false. */
84
+ incremental?: boolean;
85
+ /** May the manifest be written. Default false. */
86
+ writeManifest?: boolean;
87
+ /** A manifest opened by the caller, in place of `manifestFile`. */
88
+ manifest?: ListingManifest;
89
+ }
90
+ /** `2026-08-06-hq-dev-standup-ff4acd73`: stable from the day, the title and the source id. */
91
+ export declare function meetingSlug(day: IsoDate | null, title: string, sourceId: string): string;
92
+ export declare function scanCorpus(context: GraphContext, options?: ScanOptions): Corpus;
93
+ /**
94
+ * The contract's per-kind readers: each one is the union of the source classes
95
+ * of that kind, filtered for `context.member`.
96
+ */
97
+ export declare function kindReaders(context: GraphContext, corpus: Corpus): Partial<Record<ReplayInputKind, ReplayInputReader>>;
98
+ //# sourceMappingURL=readers.d.ts.map