@indigoai-us/hq-cli 5.345.247 → 5.345.248

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
  3. package/contracts/host-canary-release.json +14 -0
  4. package/dist/command-catalog.generated.d.ts +1113 -0
  5. package/dist/command-catalog.generated.js +1370 -0
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/lanes-hold.js +7 -7
  9. package/dist/commands/lanes-resume.js +2 -2
  10. package/dist/commands/lanes-review.js +1 -1
  11. package/dist/commands/lanes-session-start.d.ts +1 -1
  12. package/dist/commands/lanes-session-start.js +3 -3
  13. package/dist/commands/lanes-shared.d.ts +1 -1
  14. package/dist/commands/lanes.d.ts +2 -2
  15. package/dist/commands/lanes.js +50 -50
  16. package/dist/commands/mesh.d.ts +25 -0
  17. package/dist/commands/mesh.js +48 -8
  18. package/dist/commands/ontology-graph.d.ts +62 -0
  19. package/dist/commands/ontology-graph.js +439 -0
  20. package/dist/index.js +1 -1
  21. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  22. package/dist/lanes-monitor-check-argv.js +1 -1
  23. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  24. package/dist/lanes-monitor-check-fast.js +1 -1
  25. package/dist/lanes-session-start-argv.d.ts +1 -1
  26. package/dist/lanes-session-start-argv.js +1 -1
  27. package/dist/lib/capacity/sign-in.d.ts +1 -1
  28. package/dist/lib/capacity/sign-in.js +1 -1
  29. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  30. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  31. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  32. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  33. package/dist/lib/daemon/merge-sections.js +7 -7
  34. package/dist/lib/daemon/remote-control-pools.js +1 -1
  35. package/dist/lib/daemon/run.js +1 -1
  36. package/dist/lib/daemon/state-file.d.ts +1 -1
  37. package/dist/lib/daemon/state-file.js +1 -1
  38. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  39. package/dist/lib/flag-snapshot-file.js +118 -48
  40. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  41. package/dist/lib/hook-engine/canary-gate.js +138 -6
  42. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  43. package/dist/lib/hot-channels/graph-context.js +377 -0
  44. package/dist/lib/hot-channels/signals-pass.js +27 -1
  45. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  46. package/dist/lib/lanes/claude-credential.js +1 -1
  47. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  48. package/dist/lib/lanes/delivery-core.js +1 -1
  49. package/dist/lib/lanes/delivery.d.ts +10 -10
  50. package/dist/lib/lanes/delivery.js +8 -8
  51. package/dist/lib/lanes/dropbox.d.ts +1 -1
  52. package/dist/lib/lanes/dropbox.js +1 -1
  53. package/dist/lib/lanes/hooks-install.js +2 -2
  54. package/dist/lib/lanes/index.d.ts +1 -1
  55. package/dist/lib/lanes/index.js +1 -1
  56. package/dist/lib/lanes/monitor.js +1 -1
  57. package/dist/lib/lanes/quota-notice.js +1 -1
  58. package/dist/lib/lanes/quota.d.ts +1 -1
  59. package/dist/lib/lanes/quota.js +1 -1
  60. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  61. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  62. package/dist/lib/lanes/spawn.d.ts +4 -4
  63. package/dist/lib/lanes/spawn.js +5 -5
  64. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  65. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  66. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  67. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  68. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  69. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  70. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  71. package/dist/lib/mesh/live/daemon/run.js +35 -2
  72. package/dist/lib/mesh/live/direct-drain.js +1 -1
  73. package/dist/lib/mesh/live/emit.d.ts +3 -0
  74. package/dist/lib/mesh/live/emit.js +32 -9
  75. package/dist/lib/mesh/live/flush.d.ts +3 -0
  76. package/dist/lib/mesh/live/flush.js +115 -32
  77. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  78. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  79. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  80. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  81. package/dist/lib/mesh/live/spool.d.ts +17 -2
  82. package/dist/lib/mesh/live/spool.js +22 -6
  83. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  84. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  85. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  86. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  87. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  88. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  89. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  90. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  91. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  92. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  93. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  94. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  95. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  96. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  97. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  98. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  99. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  100. package/dist/lib/ontology-graph/lint/index.js +176 -0
  101. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  102. package/dist/lib/ontology-graph/model/files.js +89 -0
  103. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  104. package/dist/lib/ontology-graph/model/index.js +100 -0
  105. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  106. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  107. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  108. package/dist/lib/ontology-graph/model/pass.js +958 -0
  109. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  110. package/dist/lib/ontology-graph/model/runner.js +160 -0
  111. package/dist/lib/ontology-graph/model/step.d.ts +195 -0
  112. package/dist/lib/ontology-graph/model/step.js +523 -0
  113. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  114. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  115. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  116. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  117. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  118. package/dist/lib/ontology-graph/org/compare.js +239 -0
  119. package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
  120. package/dist/lib/ontology-graph/org/derive.js +352 -0
  121. package/dist/lib/ontology-graph/org/index.d.ts +73 -0
  122. package/dist/lib/ontology-graph/org/index.js +513 -0
  123. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  124. package/dist/lib/ontology-graph/org/load.js +476 -0
  125. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  126. package/dist/lib/ontology-graph/org/role.js +268 -0
  127. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  128. package/dist/lib/ontology-graph/org/structure.js +437 -0
  129. package/dist/lib/ontology-graph/org/text.d.ts +95 -0
  130. package/dist/lib/ontology-graph/org/text.js +315 -0
  131. package/dist/lib/ontology-graph/org/types.d.ts +452 -0
  132. package/dist/lib/ontology-graph/org/types.js +80 -0
  133. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  134. package/dist/lib/ontology-graph/pages/index.js +193 -0
  135. package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
  136. package/dist/lib/ontology-graph/pages/render.js +682 -0
  137. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  138. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  139. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  140. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  141. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  142. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  143. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  144. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  145. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  146. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  147. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  148. package/dist/lib/ontology-graph/read/brief.js +251 -0
  149. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  150. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  151. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  152. package/dist/lib/ontology-graph/read/index.js +792 -0
  153. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  154. package/dist/lib/ontology-graph/read/member.js +34 -0
  155. package/dist/lib/ontology-graph/read/names.d.ts +44 -0
  156. package/dist/lib/ontology-graph/read/names.js +292 -0
  157. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  158. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  159. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  160. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  161. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  162. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  163. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  164. package/dist/lib/ontology-graph/replay/config.js +105 -0
  165. package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
  166. package/dist/lib/ontology-graph/replay/engine.js +1174 -0
  167. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  168. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  169. package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
  170. package/dist/lib/ontology-graph/replay/index.js +220 -0
  171. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  172. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  173. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  174. package/dist/lib/ontology-graph/replay/member.js +65 -0
  175. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  176. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  177. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  178. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  179. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  180. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  181. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  182. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  183. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  184. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  185. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  186. package/dist/lib/ontology-graph/replay/util.js +256 -0
  187. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  188. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  189. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  190. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  191. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  192. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  193. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  194. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  195. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  196. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  197. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  198. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  199. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  200. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  201. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  202. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  203. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  204. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  205. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  206. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  207. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  208. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  209. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  210. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  211. package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
  212. package/dist/lib/ontology-graph/schema/authority.js +157 -0
  213. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  214. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  215. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  216. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  217. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  218. package/dist/lib/ontology-graph/schema/index.js +10 -0
  219. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  220. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  221. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  222. package/dist/lib/ontology-graph/store/files.js +207 -0
  223. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  224. package/dist/lib/ontology-graph/store/fs.js +101 -0
  225. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  226. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  227. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  228. package/dist/lib/ontology-graph/store/index.js +15 -0
  229. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  230. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  231. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  232. package/dist/lib/ontology-graph/store/paths.js +232 -0
  233. package/dist/lib/ontology-graph/types.d.ts +1183 -0
  234. package/dist/lib/ontology-graph/types.js +131 -0
  235. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  236. package/dist/utils/frontmatter.d.ts +14 -0
  237. package/dist/utils/frontmatter.js +18 -0
  238. package/dist/utils/interactive-caller.js +1 -1
  239. package/package.json +8 -8
@@ -0,0 +1,67 @@
1
+ /**
2
+ * WP-C: how much of an organization the graph maps, counted from the rows in
3
+ * the store after a run. Only open rows count: a closed row, or an edge whose
4
+ * validity has an end day, says what used to be true.
5
+ */
6
+ import type { EntityRef, GraphStore } from "../types.js";
7
+ export interface OrgCoverage {
8
+ people: number;
9
+ peopleWithRole: number;
10
+ peopleWithTeam: number;
11
+ /** Open reports_to edges. */
12
+ reportsToEdges: number;
13
+ /** People with an open works_at edge to the company itself. */
14
+ internalPeople: number;
15
+ /** People who are not internal and have an open works_at edge to another company, or status `external`. */
16
+ externalPeople: number;
17
+ /** People the graph cannot place inside or outside the company. */
18
+ unplacedPeople: number;
19
+ teams: number;
20
+ roles: number;
21
+ projects: number;
22
+ projectsWithOwner: number;
23
+ /** People with an open works_on edge. */
24
+ peopleWorkingOnAProject: number;
25
+ companies: number;
26
+ /** Companies with an open customer_of edge to the company itself. */
27
+ customers: number;
28
+ customersWithStage: number;
29
+ /** Companies with any stage fact. */
30
+ companiesWithStage: number;
31
+ /** Companies by the `relation` values they carry (a company can carry two). */
32
+ companiesByRelation: Record<string, number>;
33
+ /** Open related_to edges, counted once per pair. */
34
+ relatedToEdges: number;
35
+ }
36
+ /** Counts the org structure in the store. `self` is the company the graph belongs to. */
37
+ export declare function orgCoverage(store: GraphStore, self: EntityRef | null): OrgCoverage;
38
+ /** The defects the first critique counted, counted again from the store. Each should be 0 or close to it. */
39
+ export interface GraphQuality {
40
+ /** One-word person entities that sit beside a person whose full name starts with that word. */
41
+ firstNameDuplicates: number;
42
+ /** Rows those one-word people hold. */
43
+ firstNameDuplicateRows: number;
44
+ /** The same, where the full-name person is on the roster: only a name whose key contradicts, or one two roster people share. */
45
+ firstNameDuplicatesOfRoster: number;
46
+ /** Person entities whose name or address marks a bot, a service or a group. Must be 0. */
47
+ botsAsPeople: number;
48
+ botsAsPeopleList: string[];
49
+ /** Companies no old entity file made, with no edge and no timeline row, whose every fact cites a CRM or billing record. Must be 0. */
50
+ crmOnlyCompanies: number;
51
+ /** Companies named by one of their own record ids. Must be 0. */
52
+ companiesNamedByRecordId: number;
53
+ /** Open `leads`, `owns`, `owned_by` and `works_at` rows whose origin is `legacy`. */
54
+ openLegacyStateEdges: number;
55
+ /** Open `reports_to` and `manages` rows whose origin is `legacy`. Must be 0. */
56
+ legacyReportingLines: number;
57
+ /** People with an open works_at edge to the company itself who are not on the roster. Must be 0. */
58
+ internalNotOnRoster: number;
59
+ /** Roster people with an open works_at edge to the company itself. */
60
+ rosterInternal: number;
61
+ }
62
+ export declare function graphQuality(store: GraphStore, options: {
63
+ self: EntityRef | null;
64
+ roster: readonly EntityRef[];
65
+ notAPerson: (name: string, emails: readonly string[]) => boolean;
66
+ }): GraphQuality;
67
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1,192 @@
1
+ import { isRecordIdName, nameTokens, normalizeName } from "../resolve/normalize.js";
2
+ /** Counts the org structure in the store. `self` is the company the graph belongs to. */
3
+ export function orgCoverage(store, self) {
4
+ const coverage = {
5
+ people: 0,
6
+ peopleWithRole: 0,
7
+ peopleWithTeam: 0,
8
+ reportsToEdges: 0,
9
+ internalPeople: 0,
10
+ externalPeople: 0,
11
+ unplacedPeople: 0,
12
+ teams: store.listEntities("team").length,
13
+ roles: store.listEntities("role").length,
14
+ projects: 0,
15
+ projectsWithOwner: 0,
16
+ peopleWorkingOnAProject: 0,
17
+ companies: 0,
18
+ customers: 0,
19
+ customersWithStage: 0,
20
+ companiesWithStage: 0,
21
+ companiesByRelation: {},
22
+ relatedToEdges: 0,
23
+ };
24
+ const open = (ref) => {
25
+ const facts = [];
26
+ const edges = [];
27
+ const seen = new Set();
28
+ for (const stored of store.readRows(ref, { kinds: ["F", "E"] })) {
29
+ if (seen.has(stored.id))
30
+ continue;
31
+ seen.add(stored.id);
32
+ const row = stored.row;
33
+ if (row.kind === "T" || row.closed || row.valid.to !== undefined)
34
+ continue;
35
+ if (row.kind === "F")
36
+ facts.push(row);
37
+ else
38
+ edges.push(row);
39
+ }
40
+ return { facts, edges };
41
+ };
42
+ const related = new Set();
43
+ const noteRelated = (ref, edges) => {
44
+ for (const edge of edges)
45
+ if (edge.verb === "related_to")
46
+ related.add(ref < edge.target ? `${ref}\n${edge.target}` : `${edge.target}\n${ref}`);
47
+ };
48
+ for (const ref of store.listEntities("person")) {
49
+ coverage.people += 1;
50
+ const { facts, edges } = open(ref);
51
+ noteRelated(ref, edges);
52
+ if (facts.some((fact) => fact.field === "role_title"))
53
+ coverage.peopleWithRole += 1;
54
+ if (edges.some((edge) => edge.verb === "member_of"))
55
+ coverage.peopleWithTeam += 1;
56
+ if (edges.some((edge) => edge.verb === "works_on"))
57
+ coverage.peopleWorkingOnAProject += 1;
58
+ coverage.reportsToEdges += edges.filter((edge) => edge.verb === "reports_to").length;
59
+ const employers = edges.filter((edge) => edge.verb === "works_at").map((edge) => edge.target);
60
+ if (self && employers.includes(self))
61
+ coverage.internalPeople += 1;
62
+ else if (employers.length > 0 || facts.some((fact) => fact.field === "status" && fact.value === "external"))
63
+ coverage.externalPeople += 1;
64
+ else
65
+ coverage.unplacedPeople += 1;
66
+ }
67
+ for (const ref of store.listEntities("project")) {
68
+ coverage.projects += 1;
69
+ const { edges } = open(ref);
70
+ noteRelated(ref, edges);
71
+ if (edges.some((edge) => edge.verb === "owned_by"))
72
+ coverage.projectsWithOwner += 1;
73
+ }
74
+ for (const ref of store.listEntities("company")) {
75
+ coverage.companies += 1;
76
+ const { facts, edges } = open(ref);
77
+ noteRelated(ref, edges);
78
+ const staged = facts.some((fact) => fact.field === "stage");
79
+ if (staged)
80
+ coverage.companiesWithStage += 1;
81
+ for (const relation of new Set(facts.filter((fact) => fact.field === "relation").map((fact) => fact.value))) {
82
+ coverage.companiesByRelation[relation] = (coverage.companiesByRelation[relation] ?? 0) + 1;
83
+ }
84
+ if (self && edges.some((edge) => edge.verb === "customer_of" && edge.target === self)) {
85
+ coverage.customers += 1;
86
+ if (staged)
87
+ coverage.customersWithStage += 1;
88
+ }
89
+ }
90
+ for (const type of ["concept", "tool", "product", "team", "role"]) {
91
+ for (const ref of store.listEntities(type))
92
+ noteRelated(ref, open(ref).edges);
93
+ }
94
+ coverage.relatedToEdges = related.size;
95
+ coverage.companiesByRelation = Object.fromEntries(Object.entries(coverage.companiesByRelation).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
96
+ return coverage;
97
+ }
98
+ export function graphQuality(store, options) {
99
+ const quality = {
100
+ firstNameDuplicates: 0,
101
+ firstNameDuplicateRows: 0,
102
+ firstNameDuplicatesOfRoster: 0,
103
+ botsAsPeople: 0,
104
+ botsAsPeopleList: [],
105
+ crmOnlyCompanies: 0,
106
+ companiesNamedByRecordId: 0,
107
+ openLegacyStateEdges: 0,
108
+ legacyReportingLines: 0,
109
+ internalNotOnRoster: 0,
110
+ rosterInternal: 0,
111
+ };
112
+ const roster = new Set(options.roster);
113
+ const firstOfFull = new Map();
114
+ const oneWord = [];
115
+ const people = store.listEntities("person");
116
+ for (const ref of people) {
117
+ const entity = store.readEntity(ref);
118
+ if (!entity)
119
+ continue;
120
+ const tokens = nameTokens(normalizeName(entity.canonical_name));
121
+ if (tokens.length >= 2)
122
+ firstOfFull.set(tokens[0], [...(firstOfFull.get(tokens[0]) ?? []), ref]);
123
+ else if (tokens.length === 1)
124
+ oneWord.push({ ref, word: tokens[0] });
125
+ if (!roster.has(ref) && options.notAPerson(entity.canonical_name, entity.keys.email)) {
126
+ quality.botsAsPeople += 1;
127
+ if (quality.botsAsPeopleList.length < 30)
128
+ quality.botsAsPeopleList.push(ref);
129
+ }
130
+ const seen = new Set();
131
+ for (const stored of store.readRows(ref, { kinds: ["E"] })) {
132
+ if (seen.has(stored.id))
133
+ continue;
134
+ seen.add(stored.id);
135
+ const row = stored.row;
136
+ if (row.kind !== "E" || row.closed || row.valid.to !== undefined)
137
+ continue;
138
+ if (row.by === "legacy" && (row.verb === "leads" || row.verb === "owns" || row.verb === "works_at"))
139
+ quality.openLegacyStateEdges += 1;
140
+ if (row.by === "legacy" && (row.verb === "reports_to" || row.verb === "manages"))
141
+ quality.legacyReportingLines += 1;
142
+ if (options.self && row.verb === "works_at" && row.target === options.self) {
143
+ if (roster.has(ref))
144
+ quality.rosterInternal += 1;
145
+ else
146
+ quality.internalNotOnRoster += 1;
147
+ }
148
+ }
149
+ }
150
+ // One works_at row per source can exist for one person: count people, not rows.
151
+ const internal = new Set();
152
+ const outside = new Set();
153
+ if (options.self) {
154
+ for (const ref of people) {
155
+ const works = store.readRows(ref, { kinds: ["E"] }).some((stored) => stored.row.kind === "E" && stored.row.verb === "works_at" && stored.row.target === options.self && !stored.row.closed && stored.row.valid.to === undefined);
156
+ if (!works)
157
+ continue;
158
+ if (roster.has(ref))
159
+ internal.add(ref);
160
+ else
161
+ outside.add(ref);
162
+ }
163
+ quality.rosterInternal = internal.size;
164
+ quality.internalNotOnRoster = outside.size;
165
+ }
166
+ for (const { ref, word } of oneWord) {
167
+ const beside = firstOfFull.get(word) ?? [];
168
+ if (beside.length === 0)
169
+ continue;
170
+ quality.firstNameDuplicates += 1;
171
+ quality.firstNameDuplicateRows += new Set(store.readRows(ref).map((stored) => stored.id)).size;
172
+ if (beside.some((full) => roster.has(full)))
173
+ quality.firstNameDuplicatesOfRoster += 1;
174
+ }
175
+ for (const ref of store.listEntities("company")) {
176
+ if (ref === options.self)
177
+ continue;
178
+ const entity = store.readEntity(ref);
179
+ if (entity && isRecordIdName(entity.canonical_name, entity.keys.external_ids))
180
+ quality.companiesNamedByRecordId += 1;
181
+ // A company an old entity file with relationship lines made is named by signals the replay will cite.
182
+ if (entity && entity.legacy_ids.length > 0)
183
+ continue;
184
+ const rows = store.readRows(ref);
185
+ if (rows.length === 0 || rows.some((stored) => stored.row.kind !== "F"))
186
+ continue;
187
+ if (rows.every((stored) => /^record:(?!seed:|git:|hq-org-layer:|email-domain:)/.test(stored.row.src)))
188
+ quality.crmOnlyCompanies += 1;
189
+ }
190
+ return quality;
191
+ }
192
+ //# sourceMappingURL=coverage.js.map
@@ -0,0 +1,199 @@
1
+ import { type GraphContext, type GraphEntityType, type GraphStore, type IsoDate, type IsoTimestamp, type LegacyImportResult, type Proposal } from "../types.js";
2
+ import { type IdentitySeedOptions, type IdentitySeedResult } from "../resolve/index.js";
3
+ import { type OrgLayerFetcher } from "../resolve/org-layer.js";
4
+ import { type GraphQuality, type OrgCoverage } from "./coverage.js";
5
+ import { type OrgChartDraft } from "../resolve/org-chart.js";
6
+ import { type ApplyIngest } from "../resolve/writer.js";
7
+ export { parseLegacyEntity, parseLegacyTarget, parseRelationshipLine } from "./parse.js";
8
+ export type { LegacyEntityFile, LegacyRelationship, LegacyTarget } from "./parse.js";
9
+ export { planLegacyEdge, verbMapEntry } from "./verb-map.js";
10
+ export type { LegacyEdgePlan } from "./verb-map.js";
11
+ export { renderLegacyImportReport } from "./report.js";
12
+ export { graphQuality, orgCoverage } from "./coverage.js";
13
+ export type { GraphQuality, OrgCoverage } from "./coverage.js";
14
+ /**
15
+ * State edges an old entity file states with no date and no source. They are
16
+ * imported closed unless a signal from the last `LEGACY_CONFIRM_DAYS` days
17
+ * names both ends.
18
+ */
19
+ export declare const LEGACY_CLOSED_VERBS: ReadonlySet<string>;
20
+ /** Reporting lines in old entity files were guessed by a model from one sentence. They are not imported. */
21
+ export declare const LEGACY_DROPPED_VERBS: ReadonlySet<string>;
22
+ export declare const LEGACY_CONFIRM_DAYS = 120;
23
+ /** A project this many companies' old files say they use is a product the company sells. */
24
+ export declare const PRODUCT_MIN_COMPANIES = 3;
25
+ /** A company this many project, product or concept files say they run on is a vendor. */
26
+ export declare const VENDOR_MIN_LINES = 2;
27
+ /** Old entity types the import reads. */
28
+ export declare const LEGACY_IMPORT_TYPES: readonly GraphEntityType[];
29
+ /** Old entity types that belong to the accounting domain and stay in the old folder. */
30
+ export declare const LEGACY_ACCOUNTING_TYPES: readonly string[];
31
+ /** Where proposals wait when the proposals package is not there to take them. */
32
+ export declare const LEGACY_PENDING_PROPOSALS = ".state/legacy-import-proposals.jsonl";
33
+ export interface LegacyImportOptions {
34
+ /** `learned` date stamped on imported rows. */
35
+ learned: IsoDate;
36
+ dryRun: boolean;
37
+ /** Override of `<companyRoot>/ontology/entities`, for tests. */
38
+ entitiesDir?: string;
39
+ /** Override of `<companyRoot>/signals`, for tests. */
40
+ signalsDir?: string;
41
+ /** Run the identity seed first. Default true. */
42
+ seed?: boolean;
43
+ seedOptions?: Partial<Omit<IdentitySeedOptions, "learned">>;
44
+ /**
45
+ * The org chart people keep in HQ (reporting lines, workspace members).
46
+ * `cache` (default): seed from the answer kept in `.state/org-layer.json`,
47
+ * with no network call. `fetch`: read it first with the CLI's signed-in
48
+ * session (read-only GET), keep it, and fall back to the kept answer when
49
+ * the read fails. `off`: do not use it. The env var
50
+ * `HQ_ONTOLOGY_ORG_LAYER` sets the default. A dry run never fetches.
51
+ */
52
+ orgLayer?: "fetch" | "cache" | "off";
53
+ /** Default: the signed-in session's vault API client. Injected in tests. */
54
+ orgLayerFetcher?: OrgLayerFetcher;
55
+ /**
56
+ * `missing-only` (default): a `Referenced in` link becomes a timeline row
57
+ * only when the replay will not write one itself, that is when the signal
58
+ * file is absent or does not list the entity in `entity_refs`. `all`: every
59
+ * company-scope link becomes a timeline row.
60
+ */
61
+ timeline?: "missing-only" | "all";
62
+ /**
63
+ * Build the org chart draft for the roster and file its lines as proposals.
64
+ * Default true when the seed runs. It reads the company-scope signals,
65
+ * meeting notes, policies and knowledge files once.
66
+ */
67
+ orgChart?: boolean;
68
+ /** Default: the file-backed store at `context.graphRoot`. */
69
+ store?: GraphStore;
70
+ /** Default: `applyIngest` from the store package. */
71
+ apply?: ApplyIngest;
72
+ /** Default: `fileProposals` from the proposals package. */
73
+ fileProposals?: (context: GraphContext, proposals: readonly Proposal[]) => number;
74
+ /** Timestamp for proposals, the ledger entry and the report. Default: the clock. */
75
+ now?: IsoTimestamp;
76
+ /**
77
+ * Append one `import` entry to the ledger. Default false: `runRebuild` writes
78
+ * the ledger entry for the import itself, and two entries would count the
79
+ * rows twice.
80
+ */
81
+ ledger?: boolean;
82
+ }
83
+ /** `LegacyImportResult` plus the counts the run report needs. */
84
+ export interface LegacyImportReport extends LegacyImportResult {
85
+ dryRun: boolean;
86
+ learned: IsoDate;
87
+ at: IsoTimestamp;
88
+ /** Old files read, by type. */
89
+ entitiesInByType: Record<string, number>;
90
+ /** Distinct graph entities the old files became, by type. */
91
+ entitiesOutByType: Record<string, number>;
92
+ /** Every entity in the graph after the run (seed plus import), by type. */
93
+ graphEntitiesByType: Record<string, number>;
94
+ /** Old files folded into an entity another input had already made. */
95
+ merges: number;
96
+ mergesByReason: Record<string, number>;
97
+ /** Up to 8 merges per type and reason, as `<old path> "<old name>" -> <entity>`, for a person to read. */
98
+ mergeExamples: Record<string, string[]>;
99
+ /** Old files (or mentions) that became nothing, by reason code. */
100
+ refusals: Record<string, number>;
101
+ /** Person entities in the graph whose name or slug is a Slack id. Must be 0. */
102
+ slackIdPeople: number;
103
+ /** Old Slack-id people folded into a real person through the Slack maps. */
104
+ slackIdPeopleResolved: number;
105
+ slackIdAliasesKept: number;
106
+ slackIdAliasesRejected: number;
107
+ aliasesDropped: Record<string, number>;
108
+ otherTypesSkipped: Record<string, number>;
109
+ parseFailures: number;
110
+ alreadyImported: number;
111
+ /** Distinct old labels seen, and what each became. */
112
+ labels: Record<string, {
113
+ count: number;
114
+ became: Record<string, number>;
115
+ }>;
116
+ distinctLabels: number;
117
+ relationshipLines: number;
118
+ rowsDropped: Record<string, number>;
119
+ edgesFlipped: number;
120
+ edgesCoerced: number;
121
+ edgesDowngraded: number;
122
+ edgesCitingSignal: number;
123
+ timeline: {
124
+ written: number;
125
+ deferredToReplay: number;
126
+ personalScopeSkipped: number;
127
+ audienceSkipped: number; /** Lines from a signal with no audience key, left out because no member was given (C7). */
128
+ noMemberSkipped: number; /** Slack ids in those lines written as the name of the person who holds them. */
129
+ slackIdsNamed: number;
130
+ };
131
+ rowsQueued: number;
132
+ rowsByKind: Record<string, number>;
133
+ rowsRefused: number;
134
+ rowsClosed: number;
135
+ contradictions: number;
136
+ /** Contradictions handed to the proposals package as proposals. */
137
+ contradictionProposalsFiled: number;
138
+ proposals: number;
139
+ /** Proposals by `<type>, <reason>` (seed and import). */
140
+ proposalsByKind: Record<string, number>;
141
+ /** Alias and fuzzy hints between concepts or tools: counted, not filed. */
142
+ aliasHintsNotFiled: number;
143
+ /** Old people whose alias list held an email or Slack id of a person with no name in common: the key was not used. */
144
+ keysOfAnotherName: number;
145
+ proposalsFiled: number;
146
+ proposalsPending: number;
147
+ unresolvedParked: number;
148
+ seed: IdentitySeedResult | null;
149
+ /** How the org layer was read for this run. */
150
+ orgLayer: {
151
+ mode: "fetch" | "cache" | "off";
152
+ status: "fetched" | "cached" | "unavailable" | "off";
153
+ reason?: string;
154
+ fetchedAt?: IsoTimestamp;
155
+ };
156
+ /** The org structure in the graph after the run. Null on a dry run. */
157
+ coverage: OrgCoverage | null;
158
+ /** The newest paying-customer count the company's own KPI file states, as a cross-check. */
159
+ payingCustomersStated: {
160
+ date: IsoDate;
161
+ payingCustomers: number;
162
+ } | null;
163
+ /** Names folded into a roster person without a person deciding, by reason code (seed and import). */
164
+ rosterMerges: Record<string, number>;
165
+ /** Every such merge, as `"<name>" -> <entity> (<reason>)`. */
166
+ rosterMergeList: string[];
167
+ /** Old person files that are a bot, an agent or a service: imported as a tool. */
168
+ machinesAsTools: number;
169
+ machineExamples: string[];
170
+ /** Old person files that name a group or a seat (`Indigo Team`): not imported. */
171
+ groupNamesDropped: number;
172
+ /** Old one-word person files that carry a company's name: not imported. */
173
+ companyNamesAsPeople: number;
174
+ /** Old company files with no relationship line, named by nothing else: kept out of the graph. */
175
+ companiesHeld: number;
176
+ /** Old files imported under another type, by reason (`tool_same_name`, `product_same_name`). */
177
+ typeChanges: Record<string, number>;
178
+ /** Names that became products, and why. */
179
+ products: string[];
180
+ /** State edges imported closed, by verb. */
181
+ edgesImportedClosed: Record<string, number>;
182
+ /** State edges imported open because a recent signal names both ends, by verb. */
183
+ edgesConfirmedRecent: Record<string, number>;
184
+ /** Old `Reports to` and `Manages` lines, not imported. */
185
+ reportingLinesDropped: number;
186
+ /** Companies marked `relation = vendor`. */
187
+ vendorsMarked: number;
188
+ /** Rows that would have cited a signal with no file in the vault: they cite the old entity file instead (request F7). */
189
+ signalCitationsMissing: number;
190
+ /** Counted from the graph after the run. Null on a dry run. */
191
+ quality: GraphQuality | null;
192
+ /** The org chart draft for the roster: proposals only. Null when there is no roster or the draft is turned off. */
193
+ orgChart: OrgChartDraft | null;
194
+ /** Lines of the draft filed as proposals. */
195
+ orgChartProposals: number;
196
+ }
197
+ /** Called once by `runRebuild` before the first replayed day. Idempotent. */
198
+ export declare function importLegacy(context: GraphContext, options: LegacyImportOptions): Promise<LegacyImportReport>;
199
+ //# sourceMappingURL=index.d.ts.map