@indigoai-us/hq-cli 5.345.246 → 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 (256) hide show
  1. package/CHANGELOG.md +63 -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 +1116 -3
  5. package/dist/command-catalog.generated.js +1373 -3
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/install-global.d.ts +15 -0
  9. package/dist/commands/install-global.js +98 -4
  10. package/dist/commands/lanes-hold.js +7 -7
  11. package/dist/commands/lanes-resume.js +2 -2
  12. package/dist/commands/lanes-review.js +1 -1
  13. package/dist/commands/lanes-session-start.d.ts +1 -1
  14. package/dist/commands/lanes-session-start.js +3 -3
  15. package/dist/commands/lanes-shared.d.ts +1 -1
  16. package/dist/commands/lanes.d.ts +2 -2
  17. package/dist/commands/lanes.js +50 -50
  18. package/dist/commands/mcp-registration.d.ts +17 -0
  19. package/dist/commands/mcp-registration.js +119 -0
  20. package/dist/commands/mesh.d.ts +25 -0
  21. package/dist/commands/mesh.js +48 -8
  22. package/dist/commands/ontology-graph.d.ts +62 -0
  23. package/dist/commands/ontology-graph.js +439 -0
  24. package/dist/commands/pkg-install.js +1 -1
  25. package/dist/commands/reindex.js +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  28. package/dist/lanes-monitor-check-argv.js +1 -1
  29. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  30. package/dist/lanes-monitor-check-fast.js +1 -1
  31. package/dist/lanes-session-start-argv.d.ts +1 -1
  32. package/dist/lanes-session-start-argv.js +1 -1
  33. package/dist/lib/capacity/sign-in.d.ts +1 -1
  34. package/dist/lib/capacity/sign-in.js +1 -1
  35. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  36. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  37. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  38. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  39. package/dist/lib/daemon/merge-sections.js +7 -7
  40. package/dist/lib/daemon/remote-control-pools.js +1 -1
  41. package/dist/lib/daemon/run.js +1 -1
  42. package/dist/lib/daemon/state-file.d.ts +1 -1
  43. package/dist/lib/daemon/state-file.js +1 -1
  44. package/dist/lib/doctor/checks/antigravity-wiring.d.ts +21 -0
  45. package/dist/lib/doctor/checks/antigravity-wiring.js +75 -0
  46. package/dist/lib/doctor/checks/anywhere.js +30 -0
  47. package/dist/lib/doctor/checks/runtime-probe.js +13 -0
  48. package/dist/lib/doctor/platform.d.ts +1 -1
  49. package/dist/lib/doctor/platform.js +5 -0
  50. package/dist/lib/doctor/registry.js +3 -0
  51. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  52. package/dist/lib/flag-snapshot-file.js +118 -48
  53. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  54. package/dist/lib/hook-engine/canary-gate.js +138 -6
  55. package/dist/lib/hook-engine/coverage.d.ts +91 -0
  56. package/dist/lib/hook-engine/coverage.js +184 -0
  57. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  58. package/dist/lib/hot-channels/graph-context.js +377 -0
  59. package/dist/lib/hot-channels/signals-pass.js +27 -1
  60. package/dist/lib/install/antigravity-targets.d.ts +39 -0
  61. package/dist/lib/install/antigravity-targets.js +122 -0
  62. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  63. package/dist/lib/lanes/claude-credential.js +1 -1
  64. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  65. package/dist/lib/lanes/delivery-core.js +1 -1
  66. package/dist/lib/lanes/delivery.d.ts +10 -10
  67. package/dist/lib/lanes/delivery.js +8 -8
  68. package/dist/lib/lanes/dropbox.d.ts +1 -1
  69. package/dist/lib/lanes/dropbox.js +1 -1
  70. package/dist/lib/lanes/hooks-install.js +2 -2
  71. package/dist/lib/lanes/index.d.ts +1 -1
  72. package/dist/lib/lanes/index.js +1 -1
  73. package/dist/lib/lanes/monitor.js +1 -1
  74. package/dist/lib/lanes/quota-notice.js +1 -1
  75. package/dist/lib/lanes/quota.d.ts +1 -1
  76. package/dist/lib/lanes/quota.js +1 -1
  77. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  78. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  79. package/dist/lib/lanes/spawn.d.ts +4 -4
  80. package/dist/lib/lanes/spawn.js +5 -5
  81. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  82. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  83. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  84. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  85. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  86. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  87. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  88. package/dist/lib/mesh/live/daemon/run.js +35 -2
  89. package/dist/lib/mesh/live/direct-drain.js +1 -1
  90. package/dist/lib/mesh/live/emit.d.ts +3 -0
  91. package/dist/lib/mesh/live/emit.js +32 -9
  92. package/dist/lib/mesh/live/flush.d.ts +3 -0
  93. package/dist/lib/mesh/live/flush.js +115 -32
  94. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  95. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  96. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  97. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  98. package/dist/lib/mesh/live/spool.d.ts +17 -2
  99. package/dist/lib/mesh/live/spool.js +22 -6
  100. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  101. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  102. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  103. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  104. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  105. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  106. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  107. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  108. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  109. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  110. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  111. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  112. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  113. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  114. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  115. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  116. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  117. package/dist/lib/ontology-graph/lint/index.js +176 -0
  118. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  119. package/dist/lib/ontology-graph/model/files.js +89 -0
  120. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  121. package/dist/lib/ontology-graph/model/index.js +100 -0
  122. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  123. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  124. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  125. package/dist/lib/ontology-graph/model/pass.js +958 -0
  126. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  127. package/dist/lib/ontology-graph/model/runner.js +160 -0
  128. package/dist/lib/ontology-graph/model/step.d.ts +195 -0
  129. package/dist/lib/ontology-graph/model/step.js +523 -0
  130. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  131. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  132. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  133. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  134. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  135. package/dist/lib/ontology-graph/org/compare.js +239 -0
  136. package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
  137. package/dist/lib/ontology-graph/org/derive.js +352 -0
  138. package/dist/lib/ontology-graph/org/index.d.ts +73 -0
  139. package/dist/lib/ontology-graph/org/index.js +513 -0
  140. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  141. package/dist/lib/ontology-graph/org/load.js +476 -0
  142. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  143. package/dist/lib/ontology-graph/org/role.js +268 -0
  144. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  145. package/dist/lib/ontology-graph/org/structure.js +437 -0
  146. package/dist/lib/ontology-graph/org/text.d.ts +95 -0
  147. package/dist/lib/ontology-graph/org/text.js +315 -0
  148. package/dist/lib/ontology-graph/org/types.d.ts +452 -0
  149. package/dist/lib/ontology-graph/org/types.js +80 -0
  150. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  151. package/dist/lib/ontology-graph/pages/index.js +193 -0
  152. package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
  153. package/dist/lib/ontology-graph/pages/render.js +682 -0
  154. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  155. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  156. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  157. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  158. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  159. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  160. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  161. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  162. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  163. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  164. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  165. package/dist/lib/ontology-graph/read/brief.js +251 -0
  166. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  167. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  168. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  169. package/dist/lib/ontology-graph/read/index.js +792 -0
  170. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  171. package/dist/lib/ontology-graph/read/member.js +34 -0
  172. package/dist/lib/ontology-graph/read/names.d.ts +44 -0
  173. package/dist/lib/ontology-graph/read/names.js +292 -0
  174. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  175. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  176. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  177. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  178. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  179. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  180. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  181. package/dist/lib/ontology-graph/replay/config.js +105 -0
  182. package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
  183. package/dist/lib/ontology-graph/replay/engine.js +1174 -0
  184. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  185. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  186. package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
  187. package/dist/lib/ontology-graph/replay/index.js +220 -0
  188. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  189. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  190. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  191. package/dist/lib/ontology-graph/replay/member.js +65 -0
  192. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  193. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  194. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  195. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  196. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  197. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  198. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  199. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  200. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  201. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  202. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  203. package/dist/lib/ontology-graph/replay/util.js +256 -0
  204. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  205. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  206. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  207. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  208. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  209. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  210. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  211. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  212. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  213. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  214. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  215. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  216. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  217. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  218. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  219. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  220. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  221. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  222. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  223. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  224. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  225. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  226. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  227. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  228. package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
  229. package/dist/lib/ontology-graph/schema/authority.js +157 -0
  230. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  231. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  232. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  233. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  234. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  235. package/dist/lib/ontology-graph/schema/index.js +10 -0
  236. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  237. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  238. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  239. package/dist/lib/ontology-graph/store/files.js +207 -0
  240. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  241. package/dist/lib/ontology-graph/store/fs.js +101 -0
  242. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  243. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  244. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  245. package/dist/lib/ontology-graph/store/index.js +15 -0
  246. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  247. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  248. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  249. package/dist/lib/ontology-graph/store/paths.js +232 -0
  250. package/dist/lib/ontology-graph/types.d.ts +1183 -0
  251. package/dist/lib/ontology-graph/types.js +131 -0
  252. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  253. package/dist/utils/frontmatter.d.ts +14 -0
  254. package/dist/utils/frontmatter.js +18 -0
  255. package/dist/utils/interactive-caller.js +1 -1
  256. package/package.json +8 -8
@@ -0,0 +1,232 @@
1
+ import { GRAPH_PATHS, graphPath, openGraphStore, readJsonLines } from "../store/index.js";
2
+ import { NAME_VARIANT_SET, mergeGroupProposal } from "./model.js";
3
+ const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
4
+ const isPerson = (ref) => typeof ref === "string" && ref.startsWith("person/");
5
+ /** A pair proposal between two people: `from` would be merged into `into`. */
6
+ function pairOf(proposal) {
7
+ if (proposal.kind !== "merge" || proposal.action.type !== "merge")
8
+ return null;
9
+ const { from, into } = proposal.action;
10
+ return isPerson(from) && isPerson(into) && from !== into ? { from, into } : null;
11
+ }
12
+ function nameWords(name) {
13
+ return name
14
+ .normalize("NFKD")
15
+ .replace(/[̀-ͯ]/g, "")
16
+ .toLowerCase()
17
+ .split(/[^a-z0-9]+/)
18
+ .filter((word) => word !== "");
19
+ }
20
+ /**
21
+ * A proposal that names several people one short name could be ("Adam" may be
22
+ * one of 8) and changes nothing on accept. It is about one of the names; when
23
+ * that name goes into a group with another name it lists, the group answers it.
24
+ */
25
+ function hintOf(proposal) {
26
+ return proposal.kind === "merge" && proposal.action.type === "none" && isPerson(proposal.entity) ? proposal.entity : null;
27
+ }
28
+ function mentions(summary, ref) {
29
+ const at = summary.indexOf(ref);
30
+ return at >= 0 && !/[a-z0-9-]/.test(summary[at + ref.length] ?? "");
31
+ }
32
+ /** A name a person would go by: two or more words, and not two names joined by "and". */
33
+ function isFullName(name) {
34
+ const words = nameWords(name);
35
+ return words.length >= 2 && !words.includes("and") && !name.includes("&");
36
+ }
37
+ /** The company the graph belongs to: the one with an open `relation = self` fact, else `company/<slug>`. */
38
+ function selfCompany(store, context) {
39
+ for (const ref of store.listEntities("company")) {
40
+ const self = store
41
+ .readRows(ref, { kinds: ["F"] })
42
+ .some((stored) => stored.row.kind === "F" && stored.row.field === "relation" && stored.row.value === "self" && stored.row.valid.to === undefined);
43
+ if (self)
44
+ return ref;
45
+ }
46
+ return `company/${context.company}`;
47
+ }
48
+ export function groupNameVariants(context, options) {
49
+ const minNames = Math.max(3, options.minNames ?? 3);
50
+ const filedAt = (options.now ?? new Date()).toISOString();
51
+ const open = options.io.readOpen(context);
52
+ const result = { groups: [], filed: 0, replaced: 0, skippedDifferentEmails: 0, skippedDeclined: 0 };
53
+ // The standing answer per proposal id: a declined group is not formed again, an answered pair is not brought back.
54
+ const standing = new Map();
55
+ for (const record of readJsonLines(graphPath(context.graphRoot, GRAPH_PATHS.proposalsDecided))) {
56
+ if (typeof record?.id === "string")
57
+ standing.set(record.id, record.decision);
58
+ }
59
+ const answered = (id) => standing.has(id) && standing.get(id) !== "undo";
60
+ // The pool: every pair proposal that is open, or held inside a group that is open.
61
+ const isGroup = (proposal) => proposal.action.type === "merge_group" && proposal.set === NAME_VARIANT_SET;
62
+ const oldGroups = open.filter(isGroup);
63
+ const pool = new Map();
64
+ for (const proposal of open)
65
+ if (!isGroup(proposal) && (pairOf(proposal) || hintOf(proposal)))
66
+ pool.set(proposal.id, proposal);
67
+ const openPairIds = new Set(pool.keys());
68
+ for (const group of oldGroups) {
69
+ for (const held of group.replaces ?? [])
70
+ if (typeof held?.id === "string" && !pool.has(held.id) && !answered(held.id))
71
+ pool.set(held.id, held);
72
+ }
73
+ if (pool.size === 0 && oldGroups.length === 0)
74
+ return result;
75
+ const store = options.store ?? openGraphStore(context.graphRoot, { company: context.company });
76
+ const self = selfCompany(store, context);
77
+ const people = new Map();
78
+ const info = (ref) => {
79
+ let held = people.get(ref);
80
+ if (!held) {
81
+ held = { ref, entity: store.readEntity(ref), companies: new Set(), internal: false, rows: 0 };
82
+ const seen = new Set();
83
+ for (const stored of store.readRows(ref)) {
84
+ if (seen.has(stored.id))
85
+ continue;
86
+ seen.add(stored.id);
87
+ held.rows += 1;
88
+ const row = stored.row;
89
+ if (row.kind !== "E" || row.verb !== "works_at")
90
+ continue;
91
+ if (row.target === self) {
92
+ if (row.valid.to === undefined)
93
+ held.internal = true;
94
+ }
95
+ else
96
+ held.companies.add(row.target);
97
+ }
98
+ people.set(ref, held);
99
+ }
100
+ return held;
101
+ };
102
+ // Pairs whose two people are both outside and share a company, per company.
103
+ const links = new Map();
104
+ for (const proposal of [...pool.values()].sort((a, b) => compareText(a.id, b.id))) {
105
+ const pair = pairOf(proposal);
106
+ if (!pair)
107
+ continue;
108
+ const from = info(pair.from);
109
+ const into = info(pair.into);
110
+ if (from.internal || into.internal || !from.entity || !into.entity)
111
+ continue;
112
+ for (const company of from.companies) {
113
+ if (!into.companies.has(company))
114
+ continue;
115
+ const graph = links.get(company) ?? new Map();
116
+ graph.set(pair.from, (graph.get(pair.from) ?? new Set()).add(pair.into));
117
+ graph.set(pair.into, (graph.get(pair.into) ?? new Set()).add(pair.from));
118
+ links.set(company, graph);
119
+ }
120
+ }
121
+ // Connected groups, largest first; a name belongs to one group only.
122
+ const candidates = [];
123
+ for (const [company, graph] of links) {
124
+ const seen = new Set();
125
+ for (const start of [...graph.keys()].sort(compareText)) {
126
+ if (seen.has(start))
127
+ continue;
128
+ const names = [];
129
+ const queue = [start];
130
+ seen.add(start);
131
+ while (queue.length > 0) {
132
+ const current = queue.shift();
133
+ names.push(current);
134
+ for (const next of [...(graph.get(current) ?? [])].sort(compareText)) {
135
+ if (!seen.has(next)) {
136
+ seen.add(next);
137
+ queue.push(next);
138
+ }
139
+ }
140
+ }
141
+ if (names.length >= minNames)
142
+ candidates.push({ company, names: names.sort(compareText) });
143
+ }
144
+ }
145
+ candidates.sort((a, b) => b.names.length - a.names.length || compareText(a.company, b.company) || compareText(a.names[0], b.names[0]));
146
+ const taken = new Set();
147
+ const consumed = new Set();
148
+ const groups = [];
149
+ const companyOf = new Map();
150
+ const oldById = new Map(oldGroups.map((group) => [group.id, group]));
151
+ for (const candidate of candidates) {
152
+ const names = candidate.names.filter((ref) => !taken.has(ref));
153
+ if (names.length < minNames)
154
+ continue;
155
+ // Different addresses on two names: two people. Leave the pairs for a person to answer one by one.
156
+ const withEmail = names.map((ref) => new Set(info(ref).entity?.keys.email ?? [])).filter((emails) => emails.size > 0);
157
+ const clash = withEmail.some((left, index) => withEmail.slice(index + 1).some((right) => ![...left].some((email) => right.has(email))));
158
+ if (clash) {
159
+ result.skippedDifferentEmails += 1;
160
+ continue;
161
+ }
162
+ const ranked = [...names].sort((a, b) => {
163
+ const left = info(a);
164
+ const right = info(b);
165
+ return (Number(isFullName(right.entity.canonical_name)) - Number(isFullName(left.entity.canonical_name)) ||
166
+ right.rows - left.rows ||
167
+ compareText(left.entity.first_seen, right.entity.first_seen) ||
168
+ compareText(a, b));
169
+ });
170
+ const into = ranked[0];
171
+ const from = ranked.slice(1);
172
+ const members = new Set(names);
173
+ const replaces = [...pool.values()]
174
+ .filter((proposal) => {
175
+ const pair = pairOf(proposal);
176
+ if (pair)
177
+ return members.has(pair.from) && members.has(pair.into);
178
+ const about = hintOf(proposal);
179
+ return about !== null && members.has(about) && names.some((ref) => ref !== about && mentions(proposal.summary, ref));
180
+ })
181
+ .sort((a, b) => compareText(a.id, b.id));
182
+ const companyName = store.readEntity(candidate.company)?.canonical_name ?? candidate.company;
183
+ const said = (ref) => `"${info(ref).entity.canonical_name}" (${ref}, ${info(ref).rows} ${info(ref).rows === 1 ? "row" : "rows"})`;
184
+ const group = mergeGroupProposal(into, from, candidate.company, {
185
+ filedAt,
186
+ replaces,
187
+ evidence: [...new Set(replaces.flatMap((proposal) => proposal.evidence))].sort(compareText).slice(0, 12),
188
+ summary: `[${NAME_VARIANT_SET}] ${names.length} names at ${companyName} look like one person. Keep ${said(into)}; merge into it: ${from.map(said).join(", ")}. ` +
189
+ `Accept merges them all. Nope keeps them apart and brings back the ${replaces.length} ${replaces.length === 1 ? "proposal" : "proposals"} this one stands in for.`,
190
+ });
191
+ if (standing.get(group.id) === "nope") {
192
+ result.skippedDeclined += 1;
193
+ continue;
194
+ }
195
+ if (standing.get(group.id) === "accept")
196
+ continue;
197
+ for (const ref of names)
198
+ taken.add(ref);
199
+ for (const proposal of replaces)
200
+ consumed.add(proposal.id);
201
+ companyOf.set(group.id, candidate.company);
202
+ // The same group as before keeps the day it was first filed.
203
+ const before = oldById.get(group.id);
204
+ groups.push(before ? { ...group, filedAt: before.filedAt } : group);
205
+ }
206
+ // The new open list: everything that is not a pair or a group, as it was; the pairs no group took; the groups.
207
+ const next = [];
208
+ for (const proposal of open) {
209
+ if (isGroup(proposal))
210
+ continue;
211
+ if (pool.has(proposal.id) && consumed.has(proposal.id))
212
+ continue;
213
+ next.push(proposal);
214
+ }
215
+ // Pairs a group held that no group holds now come back.
216
+ for (const proposal of [...pool.values()].sort((a, b) => compareText(a.id, b.id))) {
217
+ if (!openPairIds.has(proposal.id) && !consumed.has(proposal.id))
218
+ next.push(proposal);
219
+ }
220
+ next.push(...groups.sort((a, b) => compareText(a.id, b.id)));
221
+ result.filed = groups.filter((group) => !oldById.has(group.id)).length;
222
+ result.replaced = [...consumed].filter((id) => openPairIds.has(id)).length;
223
+ result.groups = groups.map((group) => {
224
+ const action = group.action;
225
+ return { id: group.id, company: companyOf.get(group.id), into: action.into, names: [action.into, ...action.from], replaced: group.replaces?.length ?? 0 };
226
+ });
227
+ const changed = next.length !== open.length || next.some((proposal, index) => JSON.stringify(proposal) !== JSON.stringify(open[index]));
228
+ if (changed && !options.dryRun)
229
+ options.io.writeOpen(context, next);
230
+ return result;
231
+ }
232
+ //# sourceMappingURL=group.js.map
@@ -0,0 +1,173 @@
1
+ /**
2
+ * WP-F entry points: proposals (design 2.6).
3
+ *
4
+ * Lint, the replay and the resolver file proposals as JSON lines in
5
+ * `proposals/open.jsonl` under the graph root. A member answers each one:
6
+ *
7
+ * hq ontology proposals list [--kind K] [--set NAME] [--limit N]
8
+ * hq ontology proposals accept <id> | nope <id> | undo <id> [--as <prs id>]
9
+ * hq ontology proposals accept --set NAME | nope --set NAME | undo --set NAME
10
+ *
11
+ * A set is a group of proposals reviewed as one (`org chart draft`, `name
12
+ * variants`): the `set` field of a proposal, else the name in square brackets
13
+ * its summary starts with. `--set` answers every open proposal in it.
14
+ *
15
+ * An accept applies the change through the store as `by human:<prs id>` rows
16
+ * at confidence 1 (tier 1, so no agent, rule or legacy row can close them),
17
+ * creates the entity an accepted edge points at when it has no file yet, records the
18
+ * decision in `proposals/decided.jsonl`, and logs it. `replayDecisions` applies
19
+ * every standing accept again: the rebuild calls it before the first input and
20
+ * after the last, so a decision survives any number of rebuilds. A "nope" is
21
+ * remembered too: the same proposal is not filed again and lint stops
22
+ * reporting it.
23
+ */
24
+ import type { CommandOutput, DecidedProposal, EdgeRow, EntityRef, FactRow, GraphContext, GraphStore, MemberIdentity, Proposal, ProposalDecisionOptions, ProposalsListOptions } from "../types.js";
25
+ import { type UndoResult } from "./apply.js";
26
+ import { type GroupNameVariantsOptions, type GroupNameVariantsResult } from "./group.js";
27
+ import { type DecisionRecord, type GraphProposal } from "./model.js";
28
+ export { ProposalApplyError, RecordingStore, applyAction, undoAccept } from "./apply.js";
29
+ export type { ApplyContext, UndoRecord, UndoResult } from "./apply.js";
30
+ export type { GroupNameVariantsOptions, GroupNameVariantsResult, NameVariantGroup } from "./group.js";
31
+ export { NAME_VARIANT_SET, closeFactProposal, contradictionProposal, humanOrigin, mergeGroupProposal, mergeProposal, normalizeSetName, proposalSet, proposalId, proposalRef, proposalsFromContradictions, retypeProposal, splitProposal, } from "./model.js";
32
+ export type { AppliedSummary, DecisionRecord, GraphProposal, GraphProposalAction, GraphProposalKind, KeepFactAction, MergeGroupAction, RetypeEdgeAction, RowAddress, SplitAction, WriteRowAction, } from "./model.js";
33
+ export declare class ProposalUsageError extends Error {
34
+ constructor(message: string);
35
+ }
36
+ /** Every open proposal, as this package files them (with `set` and `replaces`). */
37
+ export declare function readOpenGraphProposals(context: GraphContext): GraphProposal[];
38
+ /**
39
+ * Files one merge proposal per person for name variants at one outside company,
40
+ * in place of the pair proposals between those names (see group.ts). Lint runs
41
+ * it after it files; the import or the replay may call it too. Idempotent.
42
+ */
43
+ export declare function groupNameVariantProposals(context: GraphContext, options?: Omit<GroupNameVariantsOptions, "io">): GroupNameVariantsResult;
44
+ /** Every decision line, oldest first. */
45
+ export declare function readDecisions(context: GraphContext): DecisionRecord[];
46
+ /** The decision that currently stands for each proposal id: the last line for that id. */
47
+ export declare function standingDecisions(context: GraphContext): Map<string, DecisionRecord>;
48
+ /** Ids whose standing decision is "nope". Lint leaves these findings out. */
49
+ export declare function declinedProposalIds(context: GraphContext): Set<string>;
50
+ /**
51
+ * Ids that have a standing answer: decided proposals, the pair proposals an
52
+ * accepted group stood in for, and the proposals an accept made pointless.
53
+ * None of them is filed again while the answer stands.
54
+ */
55
+ export declare function answeredProposalIds(context: GraphContext): Set<string>;
56
+ /** Appends to proposals/open.jsonl, skipping ids already open or decided. Returns how many were new. */
57
+ export declare function fileProposals(context: GraphContext, proposals: readonly (Proposal | GraphProposal)[]): number;
58
+ export declare function readOpenProposals(context: GraphContext): Proposal[];
59
+ /** Finds the member signed in to the CLI on this machine. Default: the replay's lookup, the one `hq whoami` uses. */
60
+ export type ResolveMember = (context: GraphContext) => MemberIdentity | null;
61
+ export interface GraphDecisionOptions extends ProposalDecisionOptions {
62
+ /** Default: the clock. */
63
+ now?: Date;
64
+ resolveMember?: ResolveMember;
65
+ }
66
+ /** Moves the proposal to decided.jsonl; on accept, applies its action as a `by human:<prs id>` row and logs it. */
67
+ export declare function decideProposal(context: GraphContext, options: GraphDecisionOptions): Promise<DecidedProposal>;
68
+ export interface SetDecisionOptions {
69
+ /** The set name, as `proposals list` prints it. */
70
+ set: string;
71
+ decision: "accept" | "nope";
72
+ as?: string;
73
+ now?: Date;
74
+ resolveMember?: ResolveMember;
75
+ }
76
+ export interface SetDecisionResult {
77
+ set: string;
78
+ decision: "accept" | "nope";
79
+ /** Open proposals the set held when the command started. */
80
+ matched: number;
81
+ decided: DecisionRecord[];
82
+ failed: {
83
+ id: string;
84
+ summary: string;
85
+ error: string;
86
+ }[];
87
+ rowsAdded: number;
88
+ rowsClosed: number;
89
+ touched: EntityRef[];
90
+ }
91
+ /** Open proposals in one set, in file order. */
92
+ export declare function openProposalsInSet(context: GraphContext, set: string): GraphProposal[];
93
+ /**
94
+ * Answers every open proposal of a set the same way, one after the other, each
95
+ * with its own decision line and undo record. A proposal that cannot be
96
+ * applied stays open, is reported in `failed`, and does not stop the rest.
97
+ */
98
+ export declare function decideProposalSet(context: GraphContext, options: SetDecisionOptions): Promise<SetDecisionResult>;
99
+ export interface UndoDecisionOptions {
100
+ id: string;
101
+ as?: string;
102
+ now?: Date;
103
+ resolveMember?: ResolveMember;
104
+ }
105
+ export interface UndoDecisionResult extends UndoResult {
106
+ id: string;
107
+ /** The decision that was reversed. */
108
+ undid: "accept" | "nope";
109
+ reopened: boolean;
110
+ }
111
+ /**
112
+ * Takes back a decision. An accept is reversed row by row (see `undoAccept`);
113
+ * either way the proposal returns to the open list and the rebuild stops
114
+ * replaying it.
115
+ */
116
+ export declare function undoDecision(context: GraphContext, options: UndoDecisionOptions): Promise<UndoDecisionResult>;
117
+ export interface SetUndoResult {
118
+ set: string;
119
+ matched: number;
120
+ undone: UndoDecisionResult[];
121
+ failed: {
122
+ id: string;
123
+ error: string;
124
+ }[];
125
+ }
126
+ /** Takes back every standing answer to the proposals of one set, newest first. */
127
+ export declare function undoDecisionSet(context: GraphContext, options: Omit<UndoDecisionOptions, "id"> & {
128
+ set: string;
129
+ }): Promise<SetUndoResult>;
130
+ export interface ReplayDecisionsResult {
131
+ /** Standing accepts found. */
132
+ accepted: number;
133
+ applied: number;
134
+ rowsAdded: number;
135
+ rowsClosed: number;
136
+ touched: EntityRef[];
137
+ failed: {
138
+ id: string;
139
+ error: string;
140
+ }[];
141
+ }
142
+ /**
143
+ * Applies every standing accept again, oldest first, with the decider and day
144
+ * it was first made on. The rebuild calls this before the legacy import (so
145
+ * human rows are in place and outrank what the replay writes) and again after
146
+ * the last day (so rows the replay wrote again are closed or moved again).
147
+ * Idempotent. A decision that can no longer be applied is reported in
148
+ * `failed` and does not stop the others.
149
+ */
150
+ export declare function replayDecisions(context: GraphContext, options?: {
151
+ store?: GraphStore;
152
+ }): ReplayDecisionsResult;
153
+ /** Reads one row for `proposalsFromContradictions`. */
154
+ export declare function rowLookup(store: GraphStore): (entity: EntityRef, audience: string, id: string) => FactRow | EdgeRow | null;
155
+ export interface GraphProposalsListOptions extends ProposalsListOptions {
156
+ /** Only proposals of this set. */
157
+ set?: string;
158
+ }
159
+ /** `hq ontology proposals list`. */
160
+ export declare function proposalsListCommand(context: GraphContext, options: GraphProposalsListOptions): Promise<CommandOutput>;
161
+ export interface GraphDecideCommandOptions extends Omit<GraphDecisionOptions, "id"> {
162
+ id?: string;
163
+ /** Answer every open proposal of this set. */
164
+ set?: string;
165
+ }
166
+ /** `hq ontology proposals accept|nope <id>`, or `--set <name>` for a whole set. */
167
+ export declare function proposalsDecideCommand(context: GraphContext, options: GraphDecideCommandOptions): Promise<CommandOutput>;
168
+ /** `hq ontology proposals undo <id>`, or `--set <name>` for every answer given to a set. */
169
+ export declare function proposalsUndoCommand(context: GraphContext, options: Omit<UndoDecisionOptions, "id"> & {
170
+ id?: string;
171
+ set?: string;
172
+ }): Promise<CommandOutput>;
173
+ //# sourceMappingURL=index.d.ts.map