@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,717 @@
1
+ /**
2
+ * WP-F: the lint checks. Model-free: file reads, schema lookups and date math.
3
+ *
4
+ * `scanGraph` reads the graph folder once (entity files, every facts file with
5
+ * line numbers, compiled pages). Each check is a pure function of that scan
6
+ * and returns findings, some with the proposal that would fix them.
7
+ */
8
+ import * as fs from "node:fs";
9
+ import * as path from "node:path";
10
+ import yaml from "js-yaml";
11
+ import { GRAPH_ENTITY_TYPES } from "../types.js";
12
+ import { isEntityRef, isSingleValued, originTier, parseEntityRef, parseSourceRef, unescapeText, validateRow, } from "../schema/index.js";
13
+ import { GRAPH_PATHS, audienceDir, graphPath, listDir, parseFactsFile, readTextIfExists } from "../store/index.js";
14
+ import { closeFactProposal, contradictionProposal, mergeProposal, proposalId, } from "../proposals/model.js";
15
+ // ---------------------------------------------------------------------------
16
+ // Classes
17
+ // ---------------------------------------------------------------------------
18
+ /** Lint classes this package reports beyond `LintKind` in types.ts. */
19
+ export const EXTRA_LINT_KINDS = ["near_duplicate", "closed_entity_edge", "audience_leak"];
20
+ /** Every class, in report order. Errors are what `--strict` fails on. */
21
+ export const LINT_CLASSES = [
22
+ { kind: "uncited", severity: "error", label: "rows without a source" },
23
+ { kind: "grammar", severity: "error", label: "lines or files that do not parse" },
24
+ { kind: "unknown_verb", severity: "error", label: "verbs outside the closed vocabulary" },
25
+ { kind: "unknown_field", severity: "error", label: "fact fields not listed in the schema" },
26
+ { kind: "dead_link", severity: "error", label: "open edges to an entity with no file" },
27
+ { kind: "audience_leak", severity: "error", label: "company-wide rows or pages citing a personal or scoped source" },
28
+ { kind: "slack_id_person", severity: "error", label: "people whose name is a Slack id" },
29
+ { kind: "conflict_copy", severity: "error", label: "sync conflict copies of entity files" },
30
+ { kind: "contradiction", severity: "warn", label: "two open values for a single-valued field" },
31
+ { kind: "stale", severity: "warn", label: "open facts with no recent confirming source" },
32
+ { kind: "orphan", severity: "warn", label: "entities with no edges and no facts" },
33
+ { kind: "near_duplicate", severity: "warn", label: "entities that look like the same thing" },
34
+ { kind: "closed_entity_edge", severity: "warn", label: "open edges to a closed entity" },
35
+ { kind: "untyped_related", severity: "warn", label: "legacy related_to pairs with no typed verb" },
36
+ ];
37
+ const SEVERITY = new Map(LINT_CLASSES.map((entry) => [entry.kind, entry.severity]));
38
+ /**
39
+ * Days after which an open fact with no newer confirming row is stale, by
40
+ * `<type>.<field>`, then `*.<field>`; edges by `E:<verb>`. Null or absent
41
+ * means the field never goes stale (a meeting's date, a decision's statement).
42
+ */
43
+ export const STALE_AGE_DAYS = {
44
+ "*.status": 120,
45
+ "*.stage": 120,
46
+ "*.crm_status": 120,
47
+ "*.role_title": 365,
48
+ "*.affiliation": 365,
49
+ "*.target_date": 180,
50
+ "*.purpose": 365,
51
+ "*.scope": 365,
52
+ "deal.close_date": 120,
53
+ "invoice.status": 90,
54
+ "contract.status": 365,
55
+ "decision.status": null,
56
+ "meeting.channel": null,
57
+ "role.title": null,
58
+ "contact.title": 365,
59
+ "E:reports_to": 365,
60
+ "E:owned_by": 365,
61
+ };
62
+ /** A `status` fact with one of these values means the entity is closed. */
63
+ export const CLOSED_STATUS_VALUES = [
64
+ "left", "inactive", "closed", "archived", "done", "complete", "completed", "cancelled", "canceled", "killed",
65
+ "abandoned", "deprecated", "churned", "lost", "retired", "dissolved",
66
+ ];
67
+ const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
68
+ const CONFLICT_NAME = /\.conflict-|conflicted copy|\(conflict/i;
69
+ const NUMBERED_COPY = / \d+\.md$/;
70
+ const PAGE_CITATION = / \| row ([0-9a-f]{12}) \| src (.+)$/;
71
+ function relative(root, file) {
72
+ return path.relative(root, file).split(path.sep).join("/");
73
+ }
74
+ function scanPages(root, only) {
75
+ const pages = [];
76
+ const base = graphPath(root, GRAPH_PATHS.pages);
77
+ for (const type of listDir(base)) {
78
+ if (!GRAPH_ENTITY_TYPES.includes(type))
79
+ continue;
80
+ for (const name of listDir(path.join(base, type))) {
81
+ if (!name.endsWith(".md") || name.startsWith("."))
82
+ continue;
83
+ const ref = `${type}/${name.slice(0, -3)}`;
84
+ if (!isEntityRef(ref))
85
+ continue;
86
+ if (only && !only.has(ref))
87
+ continue;
88
+ const file = path.join(base, type, name);
89
+ const text = readTextIfExists(file);
90
+ if (text === null)
91
+ continue;
92
+ const lines = text.split(/\r?\n/);
93
+ let audiences = [];
94
+ if (lines[0] === "---") {
95
+ const end = lines.indexOf("---", 1);
96
+ if (end > 0) {
97
+ try {
98
+ const loaded = yaml.load(lines.slice(1, end).join("\n"), { schema: yaml.CORE_SCHEMA });
99
+ if (Array.isArray(loaded?.audiences))
100
+ audiences = loaded.audiences.map(String);
101
+ }
102
+ catch {
103
+ audiences = [];
104
+ }
105
+ }
106
+ }
107
+ const citations = [];
108
+ for (const [index, line] of lines.entries()) {
109
+ const match = line.startsWith("- ") ? PAGE_CITATION.exec(line) : null;
110
+ if (match)
111
+ citations.push({ line: index + 1, row: match[1], src: unescapeText(match[2]) });
112
+ }
113
+ pages.push({ entity: ref, file: relative(root, file), audiences, citations });
114
+ }
115
+ }
116
+ return pages;
117
+ }
118
+ /**
119
+ * Reads the whole graph folder once, or with `only` the files of those
120
+ * entities. Never throws for a bad file: it becomes a problem in the scan.
121
+ */
122
+ export function scanGraph(store, options = {}) {
123
+ const only = options.only;
124
+ const root = store.root;
125
+ const schema = store.schema();
126
+ const scan = {
127
+ root,
128
+ schema,
129
+ audiences: store.listAudiences(),
130
+ entities: new Map(),
131
+ rows: new Map(),
132
+ rowCount: 0,
133
+ problems: [],
134
+ conflictCopies: [],
135
+ pages: [],
136
+ known: new Set(),
137
+ scoped: only !== undefined,
138
+ };
139
+ const entitiesDir = graphPath(root, GRAPH_PATHS.entities);
140
+ for (const type of listDir(entitiesDir)) {
141
+ const typeDir = path.join(entitiesDir, type);
142
+ if (!fs.statSync(typeDir).isDirectory())
143
+ continue;
144
+ for (const name of listDir(typeDir)) {
145
+ if (name.startsWith(".") || !name.endsWith(".md"))
146
+ continue;
147
+ const file = relative(root, path.join(typeDir, name));
148
+ if (CONFLICT_NAME.test(name) || NUMBERED_COPY.test(name)) {
149
+ scan.conflictCopies.push(file);
150
+ continue;
151
+ }
152
+ const ref = `${type}/${name.slice(0, -3)}`;
153
+ if (!isEntityRef(ref)) {
154
+ scan.problems.push({ file, code: "bad_entity_ref", message: `not an entity file name: ${type}/${name}` });
155
+ continue;
156
+ }
157
+ scan.known.add(ref);
158
+ if (only && !only.has(ref))
159
+ continue;
160
+ try {
161
+ const entity = store.readEntity(ref);
162
+ if (entity)
163
+ scan.entities.set(ref, entity);
164
+ }
165
+ catch (error) {
166
+ scan.problems.push({ file, code: "grammar", message: error instanceof Error ? error.message : String(error), entity: ref });
167
+ }
168
+ }
169
+ }
170
+ for (const audience of scan.audiences) {
171
+ const dir = audienceDir(root, audience);
172
+ for (const type of listDir(dir)) {
173
+ const typeDir = path.join(dir, type);
174
+ if (!fs.statSync(typeDir).isDirectory())
175
+ continue;
176
+ for (const name of listDir(typeDir)) {
177
+ if (name.startsWith(".") || !name.endsWith(".md"))
178
+ continue;
179
+ const absolute = path.join(typeDir, name);
180
+ const file = relative(root, absolute);
181
+ const ref = `${type}/${name.slice(0, -3)}`;
182
+ if (!isEntityRef(ref)) {
183
+ scan.problems.push({ file, code: "bad_entity_ref", message: `not a facts file name: ${type}/${name}`, audience });
184
+ continue;
185
+ }
186
+ if (only && !only.has(ref))
187
+ continue;
188
+ const text = readTextIfExists(absolute);
189
+ if (text === null)
190
+ continue;
191
+ const parsed = parseFactsFile(text);
192
+ if (parsed.entity !== null && parsed.entity !== ref) {
193
+ scan.problems.push({ file, line: 1, code: "bad_entity_ref", message: `header says ${parsed.entity}, the path says ${ref}`, entity: ref, audience });
194
+ }
195
+ for (const error of parsed.errors) {
196
+ scan.problems.push({ file, line: error.line, code: error.refusal.code, message: error.refusal.message, entity: ref, audience });
197
+ }
198
+ if (parsed.rows.length === 0)
199
+ continue;
200
+ const list = scan.rows.get(ref) ?? [];
201
+ for (const row of parsed.rows)
202
+ list.push({ id: row.id, entity: ref, audience, row: row.row, line: row.line, file });
203
+ scan.rows.set(ref, list);
204
+ scan.rowCount += parsed.rows.length;
205
+ }
206
+ }
207
+ }
208
+ scan.pages = scanPages(root, only);
209
+ return scan;
210
+ }
211
+ function finding(kind, message, extra = {}) {
212
+ return {
213
+ // The three extra classes are not in `LintKind` yet (see the request to WP-A); they are plain strings on the wire.
214
+ kind: kind,
215
+ severity: SEVERITY.get(kind) ?? "warn",
216
+ rows: [],
217
+ message,
218
+ evidence: [],
219
+ ...extra,
220
+ };
221
+ }
222
+ const isStamped = (row) => row.kind !== "T";
223
+ const isOpenRow = (row) => row.kind !== "T" && row.valid.to === undefined;
224
+ const describe = (row) => row.kind === "F" ? `${row.field} = "${row.value}"` : row.kind === "E" ? `${row.verb} -> ${row.target}` : `${row.date} ${row.signalType}`;
225
+ /** Rows without a source, and every other line or file that does not parse. */
226
+ export function checkGrammar(scan) {
227
+ const out = [];
228
+ for (const problem of scan.problems) {
229
+ const uncited = problem.code === "missing_src" || problem.code === "bad_src";
230
+ out.push({
231
+ finding: finding(uncited ? "uncited" : "grammar", `${problem.file}${problem.line ? `:${problem.line}` : ""}: ${problem.message}`, {
232
+ file: problem.file,
233
+ ...(problem.line !== undefined ? { line: problem.line } : {}),
234
+ ...(problem.entity ? { entity: problem.entity } : {}),
235
+ ...(problem.audience ? { audience: problem.audience } : {}),
236
+ }),
237
+ });
238
+ }
239
+ return out;
240
+ }
241
+ /** Rows that parse but that the schema refuses: unknown verb, unknown field, a verb between the wrong types. */
242
+ export function checkSchema(scan) {
243
+ const out = [];
244
+ for (const [entity, rows] of scan.rows) {
245
+ for (const stored of rows) {
246
+ for (const refusal of validateRow(scan.schema, entity, stored.row, stored.audience)) {
247
+ const kind = refusal.code === "unknown_verb"
248
+ ? "unknown_verb"
249
+ : refusal.code === "unknown_field"
250
+ ? "unknown_field"
251
+ : refusal.code === "missing_src" || refusal.code === "bad_src"
252
+ ? "uncited"
253
+ : "grammar";
254
+ out.push({
255
+ finding: finding(kind, `${entity} ${describe(stored.row)}: ${refusal.message}`, {
256
+ entity,
257
+ audience: stored.audience,
258
+ rows: [stored.id],
259
+ file: stored.file,
260
+ line: stored.line,
261
+ evidence: [stored.row.src],
262
+ }),
263
+ });
264
+ }
265
+ }
266
+ }
267
+ return out;
268
+ }
269
+ /** Open edges whose target has no entity file. Accept closes the edge. */
270
+ export function checkDeadLinks(scan, options) {
271
+ const out = [];
272
+ for (const [entity, rows] of scan.rows) {
273
+ for (const stored of rows) {
274
+ if (stored.row.kind !== "E" || !isOpenRow(stored.row) || scan.entities.has(stored.row.target) || scan.known.has(stored.row.target))
275
+ continue;
276
+ const message = `${entity} ${stored.row.verb} -> ${stored.row.target}: the target has no entity file`;
277
+ out.push({
278
+ finding: finding("dead_link", message, { entity, audience: stored.audience, rows: [stored.id], file: stored.file, line: stored.line, evidence: [stored.row.src] }),
279
+ proposal: closeFactProposal(entity, stored.audience, stored.id, "dead link", {
280
+ kind: "dead_link",
281
+ summary: `Close the edge ${message}`,
282
+ evidence: [stored.row.src],
283
+ filedAt: options.filedAt,
284
+ }),
285
+ });
286
+ }
287
+ }
288
+ return out;
289
+ }
290
+ /** Entities with an identity file and no F or E row in any audience. */
291
+ export function checkOrphans(scan) {
292
+ const out = [];
293
+ for (const entity of scan.entities.keys()) {
294
+ const rows = scan.rows.get(entity) ?? [];
295
+ if (rows.some((stored) => stored.row.kind !== "T"))
296
+ continue;
297
+ const timeline = rows.length;
298
+ out.push({
299
+ finding: finding("orphan", `${entity} has no edges and no facts${timeline > 0 ? ` (${timeline} timeline row${timeline === 1 ? "" : "s"})` : ""}`, { entity }),
300
+ });
301
+ }
302
+ return out;
303
+ }
304
+ const SLACK_ID = /^<?@?[UW][A-Z0-9]{7,11}>?$/;
305
+ /** Person entities named by a Slack id. Accept closes their rows and removes the identity file. */
306
+ export function checkSlackIdPeople(scan, options) {
307
+ const out = [];
308
+ for (const [ref, entity] of scan.entities) {
309
+ if (entity.type !== "person")
310
+ continue;
311
+ const byName = SLACK_ID.test(entity.canonical_name.trim());
312
+ const bySlug = /^[uw][a-z0-9]{7,11}$/.test(entity.slug) && /\d/.test(entity.slug) && entity.canonical_name.trim().toLowerCase() === entity.slug;
313
+ if (!byName && !bySlug)
314
+ continue;
315
+ const message = `${ref} is named by a Slack id ("${entity.canonical_name}")`;
316
+ out.push({
317
+ finding: finding("slack_id_person", message, { entity: ref }),
318
+ proposal: {
319
+ id: proposalId("slack_id_person", ref, []),
320
+ kind: "slack_id_person",
321
+ entity: ref,
322
+ rows: [],
323
+ summary: `Remove ${message}; its open rows are closed`,
324
+ action: { type: "remove_entity", entity: ref },
325
+ evidence: [],
326
+ filedAt: options.filedAt,
327
+ },
328
+ });
329
+ }
330
+ return out;
331
+ }
332
+ /** Sync conflict copies and numbered duplicates in `entities/`. */
333
+ export function checkConflictCopies(scan) {
334
+ return scan.conflictCopies.map((file) => ({
335
+ finding: finding("conflict_copy", `${file} is a conflict copy, not an entity`, { file }),
336
+ }));
337
+ }
338
+ function better(a, b) {
339
+ const left = a.row;
340
+ const right = b.row;
341
+ return (originTier(left.by) - originTier(right.by) ||
342
+ compareText(right.valid.from, left.valid.from) ||
343
+ right.conf - left.conf ||
344
+ compareText(a.id, b.id));
345
+ }
346
+ const valueOf = (row) => (row.kind === "F" ? row.value : row.target);
347
+ const keyOf = (row) => (row.kind === "F" ? `F:${row.field}` : `E:${row.verb}`);
348
+ /** Open rows of each single-valued field or verb, grouped per entity across audiences. */
349
+ function singleValuedGroups(scan, entity, rows) {
350
+ const groups = new Map();
351
+ const type = parseEntityRef(entity)?.type;
352
+ if (!type)
353
+ return groups;
354
+ for (const stored of rows) {
355
+ if (!isOpenRow(stored.row) || !isSingleValued(scan.schema, type, stored.row))
356
+ continue;
357
+ const key = keyOf(stored.row);
358
+ const list = groups.get(key) ?? [];
359
+ list.push(stored);
360
+ groups.set(key, list);
361
+ }
362
+ return groups;
363
+ }
364
+ /**
365
+ * Two open rows for a single-valued field (or verb) with different values.
366
+ * The proposal keeps the row authority would pick (highest tier, then newest)
367
+ * and closes the others.
368
+ */
369
+ export function checkContradictions(scan, options) {
370
+ const out = [];
371
+ for (const [entity, rows] of scan.rows) {
372
+ for (const [key, group] of singleValuedGroups(scan, entity, rows)) {
373
+ const byValue = new Map();
374
+ for (const stored of group) {
375
+ const value = valueOf(stored.row);
376
+ byValue.set(value, [...(byValue.get(value) ?? []), stored]);
377
+ }
378
+ if (byValue.size < 2)
379
+ continue;
380
+ const ranked = [...group].sort(better);
381
+ const keep = ranked[0];
382
+ const keptValue = valueOf(keep.row);
383
+ const rivals = ranked.filter((stored) => valueOf(stored.row) !== keptValue);
384
+ const proposal = contradictionProposal(entity, key.slice(2), { audience: keep.audience, id: keep.id, row: keep.row }, rivals.map((stored) => ({ audience: stored.audience, id: stored.id, row: stored.row })), { filedAt: options.filedAt });
385
+ out.push({
386
+ finding: finding("contradiction", proposal.summary, {
387
+ entity,
388
+ audience: keep.audience,
389
+ rows: proposal.rows,
390
+ file: keep.file,
391
+ line: keep.line,
392
+ evidence: proposal.evidence,
393
+ }),
394
+ proposal,
395
+ });
396
+ }
397
+ }
398
+ return out;
399
+ }
400
+ function daysBetween(from, to) {
401
+ return Math.floor((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000);
402
+ }
403
+ function staleAge(ages, type, row) {
404
+ if (row.kind === "E")
405
+ return ages[`E:${row.verb}`] ?? null;
406
+ const exact = ages[`${type}.${row.field}`];
407
+ if (exact !== undefined)
408
+ return exact;
409
+ return ages[`*.${row.field}`] ?? null;
410
+ }
411
+ /**
412
+ * Open single-valued facts (and single-valued edges) older than the field's
413
+ * age, where no row with the same value has been written since. A newer source
414
+ * that says the same thing writes a new row and keeps the fact fresh.
415
+ */
416
+ export function checkStale(scan, options) {
417
+ const out = [];
418
+ for (const [entity, rows] of scan.rows) {
419
+ const type = parseEntityRef(entity)?.type;
420
+ if (!type)
421
+ continue;
422
+ for (const [key, group] of singleValuedGroups(scan, entity, rows)) {
423
+ const age = staleAge(options.staleAgeDays, type, group[0].row);
424
+ if (age === null)
425
+ continue;
426
+ for (const stored of group) {
427
+ const row = stored.row;
428
+ const value = valueOf(row);
429
+ // Newest row on the entity that states the same value, open or closed, in any audience.
430
+ let newest = row.valid.from;
431
+ for (const other of rows) {
432
+ if (!isStamped(other.row) || keyOf(other.row) !== key || valueOf(other.row) !== value)
433
+ continue;
434
+ if (other.row.valid.from > newest)
435
+ newest = other.row.valid.from;
436
+ }
437
+ const days = daysBetween(newest, options.today);
438
+ if (days <= age)
439
+ continue;
440
+ const message = `${entity} ${describe(row)} was last confirmed ${newest}, ${days} days ago (limit for ${key.slice(2)}: ${age})`;
441
+ out.push({
442
+ finding: finding("stale", message, { entity, audience: stored.audience, rows: [stored.id], file: stored.file, line: stored.line, evidence: [row.src] }),
443
+ proposal: closeFactProposal(entity, stored.audience, stored.id, "stale", {
444
+ kind: "stale",
445
+ summary: `Close the stale fact: ${message}`,
446
+ evidence: [row.src],
447
+ filedAt: options.filedAt,
448
+ }),
449
+ });
450
+ }
451
+ }
452
+ }
453
+ return out;
454
+ }
455
+ /** Entities whose current `status` fact says they are closed. */
456
+ export function closedEntities(scan) {
457
+ const closed = new Map();
458
+ for (const [entity, rows] of scan.rows) {
459
+ const statuses = rows.filter((stored) => stored.row.kind === "F" && stored.row.field === "status" && isOpenRow(stored.row));
460
+ if (statuses.length === 0)
461
+ continue;
462
+ const current = [...statuses].sort(better)[0].row;
463
+ const value = current.value.trim().toLowerCase();
464
+ if (CLOSED_STATUS_VALUES.includes(value))
465
+ closed.set(entity, value);
466
+ }
467
+ return closed;
468
+ }
469
+ /** Open state edges (works_on, reports_to, member_of, ...) that point at a closed entity. Accept closes the edge. */
470
+ export function checkClosedEntityEdges(scan, options) {
471
+ const out = [];
472
+ const closed = closedEntities(scan);
473
+ if (closed.size === 0)
474
+ return out;
475
+ for (const [entity, rows] of scan.rows) {
476
+ for (const stored of rows) {
477
+ if (stored.row.kind !== "E" || !isOpenRow(stored.row))
478
+ continue;
479
+ const status = closed.get(stored.row.target);
480
+ if (status === undefined || scan.schema.link_types[stored.row.verb]?.class !== "state")
481
+ continue;
482
+ const message = `${entity} ${stored.row.verb} -> ${stored.row.target}: the target's status is "${status}"`;
483
+ out.push({
484
+ finding: finding("closed_entity_edge", message, { entity, audience: stored.audience, rows: [stored.id], file: stored.file, line: stored.line, evidence: [stored.row.src] }),
485
+ proposal: closeFactProposal(entity, stored.audience, stored.id, "closed entity", {
486
+ kind: "closed_entity_edge",
487
+ summary: `Close the edge ${message}`,
488
+ evidence: [stored.row.src],
489
+ filedAt: options.filedAt,
490
+ }),
491
+ });
492
+ }
493
+ }
494
+ return out;
495
+ }
496
+ const COMPANY_SUFFIXES = new Set(["inc", "llc", "ltd", "corp", "corporation", "co", "company", "gmbh", "the"]);
497
+ /** Mail providers: two entities that share one of these domains share nothing. */
498
+ export const SHARED_MAIL_DOMAINS = new Set([
499
+ "gmail.com", "googlemail.com", "yahoo.com", "ymail.com", "outlook.com", "hotmail.com", "live.com", "msn.com", "icloud.com",
500
+ "me.com", "mac.com", "aol.com", "proton.me", "protonmail.com", "pm.me", "hey.com", "fastmail.com", "gmx.com", "zoho.com",
501
+ ]);
502
+ function nameTokens(name, type) {
503
+ const tokens = name
504
+ .normalize("NFKD")
505
+ .replace(/[̀-ͯ]/g, "")
506
+ .toLowerCase()
507
+ .replace(/['’]/g, "")
508
+ .split(/[^a-z0-9]+/)
509
+ .filter((token) => token !== "");
510
+ return type === "company" ? tokens.filter((token) => !COMPANY_SUFFIXES.has(token)) : tokens;
511
+ }
512
+ /**
513
+ * Entities of one type that look like the same thing: the same name once case,
514
+ * punctuation and word order are ignored, or a shared identity key (email,
515
+ * Slack id, external id, web domain). A single first name never matches two
516
+ * people, and a mail provider's domain (gmail.com) is not a shared domain.
517
+ * Each pair becomes a merge proposal into the entity with more rows.
518
+ */
519
+ export function checkNearDuplicates(scan, options) {
520
+ const refusals = scan.schema.refusals;
521
+ const generic = new Set([...refusals.generic_words, ...refusals.job_titles].map((word) => word.toLowerCase()));
522
+ const blocks = new Map();
523
+ const add = (key, reason, ref) => {
524
+ const block = blocks.get(key) ?? { reason, members: new Set() };
525
+ block.members.add(ref);
526
+ blocks.set(key, block);
527
+ };
528
+ for (const [ref, entity] of scan.entities) {
529
+ for (const name of [entity.canonical_name, ...entity.aliases]) {
530
+ const tokens = nameTokens(name, entity.type);
531
+ const joined = tokens.join(" ");
532
+ if (joined.length < refusals.min_name_length || generic.has(joined))
533
+ continue;
534
+ if (entity.type === "person" && tokens.length < 2)
535
+ continue;
536
+ add(`${entity.type}\u0000name\u0000${[...tokens].sort(compareText).join(" ")}`, "same name", ref);
537
+ const compact = tokens.join("");
538
+ if (compact.length >= refusals.fuzzy_min_chars)
539
+ add(`${entity.type}\u0000compact\u0000${compact}`, "same name without spaces", ref);
540
+ }
541
+ for (const email of entity.keys.email)
542
+ add(`${entity.type}\u0000email\u0000${email.toLowerCase()}`, "shared email", ref);
543
+ for (const id of entity.keys.slack_id)
544
+ add(`${entity.type}\u0000slack\u0000${id}`, "shared Slack id", ref);
545
+ for (const id of entity.keys.external_ids)
546
+ add(`${entity.type}\u0000external\u0000${id}`, "shared external id", ref);
547
+ if (entity.type !== "person") {
548
+ for (const domain of entity.keys.web_domains) {
549
+ const host = domain.toLowerCase().replace(/^www\./, "");
550
+ if (!SHARED_MAIL_DOMAINS.has(host))
551
+ add(`${entity.type}\u0000domain\u0000${host}`, "shared web domain", ref);
552
+ }
553
+ }
554
+ }
555
+ const weight = (ref) => (scan.rows.get(ref) ?? []).length;
556
+ const pairs = new Map();
557
+ for (const key of [...blocks.keys()].sort(compareText)) {
558
+ const block = blocks.get(key);
559
+ // A name shared by many entities is a generic word, not a duplicate.
560
+ if (block.members.size < 2 || block.members.size > 20)
561
+ continue;
562
+ const ranked = [...block.members].sort((a, b) => weight(b) - weight(a) ||
563
+ compareText(scan.entities.get(a)?.first_seen ?? "", scan.entities.get(b)?.first_seen ?? "") ||
564
+ compareText(a, b));
565
+ for (const from of ranked.slice(1)) {
566
+ const pairKey = [ranked[0], from].sort(compareText).join("\u0000");
567
+ const pair = pairs.get(pairKey) ?? { from, into: ranked[0], reasons: new Set() };
568
+ pair.reasons.add(block.reason);
569
+ pairs.set(pairKey, pair);
570
+ }
571
+ }
572
+ const out = [];
573
+ for (const pair of pairs.values()) {
574
+ const reason = [...pair.reasons].sort(compareText).join(", ");
575
+ const from = scan.entities.get(pair.from);
576
+ const into = scan.entities.get(pair.into);
577
+ const message = `${pair.from} ("${from?.canonical_name ?? ""}") looks like ${pair.into} ("${into?.canonical_name ?? ""}"): ${reason}`;
578
+ out.push({
579
+ finding: finding("near_duplicate", message, { entity: pair.from }),
580
+ proposal: mergeProposal(pair.from, pair.into, reason, { filedAt: options.filedAt }),
581
+ });
582
+ }
583
+ return out.sort((a, b) => compareText(a.finding.entity ?? "", b.finding.entity ?? ""));
584
+ }
585
+ /**
586
+ * Who may read a source, as far as its ref tells: `personal` (a session, a
587
+ * Slack DM, a member's own signals), `scoped:<key>` (a path under an
588
+ * `@<16 hex>` audience folder), or null when the ref does not say (a signal
589
+ * id, a company document).
590
+ */
591
+ export function sourceScope(src) {
592
+ const parsed = parseSourceRef(src);
593
+ if (!parsed)
594
+ return null;
595
+ if (parsed.kind === "session")
596
+ return "personal";
597
+ if (parsed.kind !== "source" && parsed.kind !== "doc")
598
+ return null;
599
+ const segments = parsed.value.split("/");
600
+ if (segments.some((segment) => segment === "slack-dm" || segment === "member-signals" || segment === "personal" || /^prs_[A-Za-z0-9_-]+$/.test(segment))) {
601
+ return "personal";
602
+ }
603
+ const scoped = segments.find((segment) => /^@[0-9a-f]{16}$/.test(segment));
604
+ return scoped ? `scoped:${scoped.slice(1)}` : null;
605
+ }
606
+ function leak(audience, src) {
607
+ const scope = sourceScope(src);
608
+ if (scope === null)
609
+ return null;
610
+ if (scope === "personal")
611
+ return audience === "company" ? "a personal-scope source" : null;
612
+ const key = scope.slice("scoped:".length);
613
+ if (audience === "company")
614
+ return `a source scoped to audience ${key}`;
615
+ return audience === key ? null : `a source scoped to another audience (${key})`;
616
+ }
617
+ /**
618
+ * Rows in the company-wide folder (`facts/@company`) that cite a personal or
619
+ * audience-scoped source, rows in a scoped folder that cite another audience's
620
+ * source, and compiled pages built only from company rows that cite one.
621
+ */
622
+ export function checkAudienceLeaks(scan) {
623
+ const out = [];
624
+ const flagged = new Set();
625
+ for (const [entity, rows] of scan.rows) {
626
+ for (const stored of rows) {
627
+ const why = leak(stored.audience, stored.row.src);
628
+ if (!why)
629
+ continue;
630
+ flagged.add(stored.id);
631
+ out.push({
632
+ finding: finding("audience_leak", `${entity} @${stored.audience} ${describe(stored.row)} cites ${why}: ${stored.row.src}`, {
633
+ entity,
634
+ audience: stored.audience,
635
+ rows: [stored.id],
636
+ file: stored.file,
637
+ line: stored.line,
638
+ evidence: [stored.row.src],
639
+ }),
640
+ });
641
+ }
642
+ }
643
+ for (const page of scan.pages) {
644
+ if (page.audiences.length !== 1 || page.audiences[0] !== "company")
645
+ continue;
646
+ for (const citation of page.citations) {
647
+ if (flagged.has(citation.row))
648
+ continue;
649
+ const why = leak("company", citation.src);
650
+ if (!why)
651
+ continue;
652
+ out.push({
653
+ finding: finding("audience_leak", `${page.file}:${citation.line}: a company-wide page cites ${why}: ${citation.src}`, {
654
+ entity: page.entity,
655
+ audience: "company",
656
+ rows: [citation.row],
657
+ file: page.file,
658
+ line: citation.line,
659
+ evidence: parseSourceRef(citation.src) ? [citation.src] : [],
660
+ }),
661
+ });
662
+ }
663
+ }
664
+ return out;
665
+ }
666
+ /** Legacy `related_to` edges where no typed verb links the same two entities. One finding per pair. */
667
+ export function checkUntypedRelated(scan) {
668
+ const out = [];
669
+ for (const [entity, rows] of scan.rows) {
670
+ const typed = new Set();
671
+ for (const stored of rows) {
672
+ if (stored.row.kind === "E" && isOpenRow(stored.row) && scan.schema.link_types[stored.row.verb]?.class !== "reference") {
673
+ typed.add(stored.row.target);
674
+ }
675
+ }
676
+ const seen = new Set();
677
+ for (const stored of rows) {
678
+ const row = stored.row;
679
+ if (row.kind !== "E" || row.verb !== "related_to" || !isOpenRow(row) || originTier(row.by) !== 5)
680
+ continue;
681
+ // The inverse row sits on the target: report the pair once, from the side that sorts first.
682
+ if (entity > row.target || typed.has(row.target) || seen.has(row.target))
683
+ continue;
684
+ seen.add(row.target);
685
+ out.push({
686
+ finding: finding("untyped_related", `${entity} related_to ${row.target}${row.was ? ` (was "${row.was}")` : ""} has no typed verb`, {
687
+ entity,
688
+ audience: stored.audience,
689
+ rows: [stored.id],
690
+ file: stored.file,
691
+ line: stored.line,
692
+ evidence: [row.src],
693
+ }),
694
+ });
695
+ }
696
+ }
697
+ return out;
698
+ }
699
+ /** Every check, in report order. */
700
+ export function runChecks(scan, options) {
701
+ return [
702
+ ...checkGrammar(scan),
703
+ ...checkSchema(scan),
704
+ ...checkDeadLinks(scan, options),
705
+ ...checkAudienceLeaks(scan),
706
+ ...checkSlackIdPeople(scan, options),
707
+ ...checkConflictCopies(scan),
708
+ ...checkContradictions(scan, options),
709
+ ...checkStale(scan, options),
710
+ ...checkOrphans(scan),
711
+ // Two names for one thing are found by comparing every name in the graph: not on a scoped scan.
712
+ ...(scan.scoped ? [] : checkNearDuplicates(scan, options)),
713
+ ...checkClosedEntityEdges(scan, options),
714
+ ...checkUntypedRelated(scan),
715
+ ];
716
+ }
717
+ //# sourceMappingURL=checks.js.map