@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,634 @@
1
+ /**
2
+ * WP-C: readers for the files that state how a company is organized, beyond
3
+ * the identity anchors in seed.ts. Every reader is a rule: it parses fields
4
+ * and fixed text shapes, cites the file it read, and never calls a model.
5
+ * Nothing here names a company; folder and field names are HQ conventions.
6
+ *
7
+ * meetings/notes/<day>-*.md attendance lines; `## <Name> — <area>` headings
8
+ * policies/*.md "<Name> is <Company>'s <Title>" statements
9
+ * projects/<slug>/prd.json metadata.owner
10
+ * signals/<type>/*.md (company scope) participant role, `Decided by`, `Owner`
11
+ * clients/<slug>/ README.md status, engagement.md, prospect.json
12
+ * customer-kpis.json paying-customer count, as a cross-check
13
+ * repos under <hq>/repos/ every clone whose origin is one of the company's GitHub owners
14
+ */
15
+ import * as fs from "node:fs";
16
+ import * as path from "node:path";
17
+ import yaml from "js-yaml";
18
+ import { splitLenientFrontmatter } from "../../../utils/frontmatter.js";
19
+ import { isEmail, nameTokens, normalizeDomain, normalizeEmail, normalizeName, slackIdInside, sortedUnique } from "./normalize.js";
20
+ // ---------------------------------------------------------------------------
21
+ // Small readers
22
+ // ---------------------------------------------------------------------------
23
+ const COPY_NAME_RE = /(?: \d+(?=\.[^.]+$)|\.conflict-)/;
24
+ const isCopy = (name) => COPY_NAME_RE.test(name) || / \d+$/.test(name);
25
+ function names(dir) {
26
+ try {
27
+ return fs.readdirSync(dir).filter((name) => !name.startsWith(".") && !isCopy(name)).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
28
+ }
29
+ catch {
30
+ return [];
31
+ }
32
+ }
33
+ function read(file) {
34
+ try {
35
+ return fs.readFileSync(file, "utf8");
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ }
41
+ function isDir(file) {
42
+ try {
43
+ return fs.statSync(file).isDirectory();
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ }
49
+ function json(file) {
50
+ const content = read(file);
51
+ if (content === null)
52
+ return null;
53
+ try {
54
+ return JSON.parse(content);
55
+ }
56
+ catch {
57
+ return null;
58
+ }
59
+ }
60
+ const text = (value) => (typeof value === "string" ? value.trim() : "");
61
+ const list = (value) => (Array.isArray(value) ? value : []);
62
+ const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
63
+ function splitFrontmatter(content) {
64
+ const split = splitLenientFrontmatter(content);
65
+ if (!split)
66
+ return { frontmatter: {}, body: content };
67
+ let loaded;
68
+ try {
69
+ loaded = yaml.load(split.yaml, { schema: yaml.CORE_SCHEMA });
70
+ }
71
+ catch {
72
+ loaded = null;
73
+ }
74
+ return { frontmatter: record(loaded), body: split.body };
75
+ }
76
+ function dayIn(value) {
77
+ if (value instanceof Date && !Number.isNaN(value.getTime()))
78
+ return value.toISOString().slice(0, 10);
79
+ const match = /^(\d{4}-\d{2}-\d{2})(?:$|[T _-]|\b)/.exec(text(value));
80
+ return match ? match[1] : null;
81
+ }
82
+ const oneLine = (value, max) => {
83
+ const flat = value.replace(/\s+/g, " ").trim();
84
+ return flat.length <= max ? flat : `${flat.slice(0, max - 1).trimEnd()}…`;
85
+ };
86
+ /** Text in round brackets removed, nested or not, and an opening bracket that never closes cut with what follows it. */
87
+ export function withoutBrackets(value) {
88
+ let out = value;
89
+ for (let pass = 0; pass < 5; pass += 1) {
90
+ const next = out.replace(/\([^()]*\)/g, " ");
91
+ if (next === out)
92
+ break;
93
+ out = next;
94
+ }
95
+ const open = out.indexOf("(");
96
+ if (open >= 0)
97
+ out = out.slice(0, open);
98
+ return out.replace(/\)/g, " ").replace(/\s+/g, " ").trim();
99
+ }
100
+ /** Markdown emphasis, code ticks and link syntax removed. */
101
+ const plain = (value) => value.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[*_`]/g, "").trim();
102
+ // ---------------------------------------------------------------------------
103
+ // Functions (working groups) and job titles
104
+ // ---------------------------------------------------------------------------
105
+ /**
106
+ * The working groups a company of any kind tends to have, and the words that
107
+ * point at each. A word list, not a company's org chart: a group becomes a
108
+ * team in the graph only when two independent sources point at it.
109
+ */
110
+ export const FUNCTION_TERMS = {
111
+ engineering: ["engineering", "engineer", "engineers", "eng", "dev", "devs", "developer", "developers", "development", "infrastructure", "infra", "backend", "frontend", "fullstack", "devops", "sre", "architect", "cto", "technical"],
112
+ product: ["product", "cpo"],
113
+ design: ["design", "designer", "designers", "ux"],
114
+ gtm: ["gtm", "go to market"],
115
+ sales: ["sales", "deals", "revenue", "business development", "account executive", "partnerships"],
116
+ marketing: ["marketing", "content", "brand", "growth", "cmo"],
117
+ support: ["support", "helpdesk", "customer success", "customer support", "customer experience", "cx"],
118
+ operations: ["operations", "ops", "coo"],
119
+ finance: ["finance", "cfo", "accounting", "controller"],
120
+ people: ["people", "hr", "recruiting", "talent"],
121
+ legal: ["legal", "counsel", "compliance"],
122
+ leadership: ["leadership", "exec", "executive", "executives", "founder", "founders", "cofounder", "co founder", "ceo", "president"],
123
+ };
124
+ const FUNCTION_LABELS = {
125
+ engineering: "Engineering",
126
+ product: "Product",
127
+ design: "Design",
128
+ gtm: "GTM",
129
+ sales: "Sales",
130
+ marketing: "Marketing",
131
+ support: "Support",
132
+ operations: "Operations",
133
+ finance: "Finance",
134
+ people: "People",
135
+ legal: "Legal",
136
+ leadership: "Leadership",
137
+ };
138
+ const TERM_TO_FUNCTION = new Map();
139
+ for (const [fn, terms] of Object.entries(FUNCTION_TERMS))
140
+ for (const term of terms)
141
+ TERM_TO_FUNCTION.set(term, fn);
142
+ /** The display name of a function key, or the key itself for a team a roster named. */
143
+ export function functionLabel(key) {
144
+ return FUNCTION_LABELS[key] ?? key;
145
+ }
146
+ /**
147
+ * The functions a channel name, a heading or a title points at. Two-word terms
148
+ * win over their parts, so `business development` is sales, not engineering.
149
+ */
150
+ export function functionsOf(value) {
151
+ const tokens = nameTokens(normalizeName(value));
152
+ const found = [];
153
+ for (let index = 0; index < tokens.length; index += 1) {
154
+ const three = tokens.slice(index, index + 3).join(" ");
155
+ const two = tokens.slice(index, index + 2).join(" ");
156
+ const hit3 = tokens.length - index >= 3 ? TERM_TO_FUNCTION.get(three) : undefined;
157
+ const hit2 = tokens.length - index >= 2 ? TERM_TO_FUNCTION.get(two) : undefined;
158
+ if (hit3) {
159
+ found.push(hit3);
160
+ index += 2;
161
+ }
162
+ else if (hit2) {
163
+ found.push(hit2);
164
+ index += 1;
165
+ }
166
+ else {
167
+ const hit = TERM_TO_FUNCTION.get(tokens[index]);
168
+ if (hit)
169
+ found.push(hit);
170
+ }
171
+ }
172
+ return sortedUnique(found);
173
+ }
174
+ const TITLE_HEAD_RE = /\b(?:head of|vp|vice president|director|chief|ceo|cto|coo|cfo|cmo|cpo|founder|co-?founder|president|partner|principal|lead|manager|engineer|developer|designer|architect|analyst|consultant|advisor|officer|recruiter|marketer|scientist|strategist|counsel|controller)\b/i;
175
+ /** Words that describe what someone did in one thread or call, not the job they hold. */
176
+ const SITUATIONAL_RE = /\b(?:reporter|contributor|initiator|reviewer|approver|requester|requestor|attendee|participant|responder|respondent|team member|stakeholder|thread|bug|assignee|escalat\w*|validator|supporter|presenter|organizer|host|creator|sender|user|prospect\w*|likely|unknown|unresolved|agent|bot|automated|decision[- ]maker|implementer|investigator|claimant|author|troubleshooter|executor|communicator|coordinator|advocate|input|feedback|representative|working on|responding)\b/i;
177
+ /**
178
+ * A job title from free text, or null. `Co-founder / Leadership` gives
179
+ * `Co-founder`; `Thread initiator` and `Engineer / fix author` give null and
180
+ * `Engineer`. A title is kept only when a part of the text names a job and
181
+ * says nothing situational.
182
+ */
183
+ export function titleFrom(value) {
184
+ for (const part of withoutBrackets(plain(value)).split(/\s*(?:\/|;|\||,| - | — | – )\s*/)) {
185
+ const candidate = part.replace(/\s+/g, " ").trim();
186
+ if (candidate.length < 3 || candidate.length > 60)
187
+ continue;
188
+ if (!TITLE_HEAD_RE.test(candidate) || SITUATIONAL_RE.test(candidate))
189
+ continue;
190
+ if (slackIdInside(candidate) || /[_@:]/.test(candidate))
191
+ continue;
192
+ return candidate.replace(/^(?:the|our|a|an)\s+/i, "");
193
+ }
194
+ return null;
195
+ }
196
+ /** `Head of GTM`, `VP of Sales`, `Director of Engineering`, `Engineering Lead`: the function the title leads, or null. */
197
+ export function ledFunction(title) {
198
+ const lead = /^(?:fractional |interim |acting )?(?:head|vp|vice president|director|chief)(?: of)? (.+)$/i.exec(title.trim())?.[1] ??
199
+ /^(.+) (?:lead|director|manager)$/i.exec(title.trim())?.[1];
200
+ if (!lead)
201
+ return null;
202
+ const functions = functionsOf(lead);
203
+ return functions.length === 1 ? functions[0] : null;
204
+ }
205
+ const PERSON_NAME = "[A-Z][A-Za-z'’.-]+(?: [A-Z][A-Za-z'’.-]+){0,2}";
206
+ const AREA_HEADING_RE = new RegExp(`^#{2,4}\\s+(${PERSON_NAME}(?:\\s*/\\s*${PERSON_NAME})?)\\s+[—–-]\\s+(.+)$`);
207
+ const ATTENDANCE_RE = /(?:^|[.\s*_])(?:Attendees|Attendance|Present)\s*:\s*\**\s*([^\n]+)/i;
208
+ /** Names from `Corey, Hassaan, + **Jonathan Bach** (new — GTM/X). Pulled from the recording.` */
209
+ export function attendanceNames(line) {
210
+ const cut = plain(line).replace(/\([^)]*\)/g, " ");
211
+ const sentence = cut.split(/\.(?:\s|$)/)[0] ?? "";
212
+ return sortedUnique(sentence
213
+ .split(/,|;|\band\b|\+|&/)
214
+ .map((part) => part.replace(/\s+/g, " ").trim())
215
+ .filter((part) => new RegExp(`^${PERSON_NAME}$`).test(part)));
216
+ }
217
+ export function readStandupNotes(companyRoot) {
218
+ const dir = path.join(companyRoot, "meetings", "notes");
219
+ const areas = [];
220
+ const attendance = new Map();
221
+ let files = 0;
222
+ for (const name of names(dir)) {
223
+ const day = dayIn(name);
224
+ if (!name.endsWith(".md") || !day)
225
+ continue;
226
+ const content = read(path.join(dir, name));
227
+ if (content === null)
228
+ continue;
229
+ files += 1;
230
+ const src = `doc:meetings/notes/${name}`;
231
+ const present = new Set();
232
+ for (const line of content.split("\n")) {
233
+ const heading = AREA_HEADING_RE.exec(plain(line).replace(/^(#+)/, "$1").trimEnd());
234
+ if (heading && line.startsWith("#")) {
235
+ const area = (heading[2] ?? "").replace(/\([^)]*\)/g, " ");
236
+ const functions = sortedUnique(area.split(/[·,|/]/).slice(0, 3).flatMap((part) => functionsOf(part)));
237
+ if (functions.length > 0) {
238
+ for (const person of (heading[1] ?? "").split(/\s*\/\s*/))
239
+ areas.push({ name: person.trim(), functions, src, day });
240
+ }
241
+ continue;
242
+ }
243
+ const listed = ATTENDANCE_RE.exec(line);
244
+ if (listed)
245
+ for (const person of attendanceNames(listed[1] ?? ""))
246
+ present.add(person);
247
+ }
248
+ for (const person of present) {
249
+ const seen = attendance.get(person);
250
+ if (!seen)
251
+ attendance.set(person, { name: person, notes: 1, firstDay: day, lastDay: day, lastSrc: src });
252
+ else {
253
+ seen.notes += 1;
254
+ if (day < seen.firstDay)
255
+ seen.firstDay = day;
256
+ if (day >= seen.lastDay) {
257
+ seen.lastDay = day;
258
+ seen.lastSrc = src;
259
+ }
260
+ }
261
+ }
262
+ }
263
+ return { files, areas, attendance: [...attendance.values()].sort((a, b) => (a.name < b.name ? -1 : 1)) };
264
+ }
265
+ const TITLE_START = "(?:fractional |interim |acting )?(?:Head of|VP of|VP|Vice President of|Director of|Chief|CEO|CTO|COO|CFO|CMO|CPO|Founder|Co-?founder|President|General Counsel|Managing Partner|Managing Director)";
266
+ const ROLE_IS_RE = new RegExp(`\\b(${PERSON_NAME})(?:\\s*\\(([^)\\n]{0,80})\\))?\\s+is\\s+(?:(?:the|our|a|an)\\s+|[A-Z][A-Za-z]+(?:'s|’s)\\s+)?(${TITLE_START}\\b[A-Za-z&/ -]{0,40}?)(?=\\s*(?:[,.;:()\\n—–]|\\band\\b|\\bwho\\b|\\bat\\b|$))`, "g");
267
+ const ROLE_PAREN_RE = new RegExp(`\\b(${PERSON_NAME})\\s*\\((${TITLE_START}\\b[A-Za-z&/ -]{0,30}?)\\s*[,)]`, "g");
268
+ /** Words that start a sentence and are not a person's name. */
269
+ const NOT_A_NAME = new Set(["this", "that", "there", "here", "it", "he", "she", "who", "what", "which", "the", "always", "never", "when", "if", "each", "every", "one", "someone", "nobody", "anyone"]);
270
+ /** Role statements in one document's text. */
271
+ export function roleStatements(content, base) {
272
+ const found = [];
273
+ const seen = new Set();
274
+ const add = (name, beside, rawTitle) => {
275
+ const person = name.trim();
276
+ if (NOT_A_NAME.has(person.split(" ")[0].toLowerCase()))
277
+ return;
278
+ const title = titleFrom(rawTitle.split("/")[0] ?? "") ?? titleFrom(rawTitle);
279
+ if (!title)
280
+ return;
281
+ const email = normalizeEmail(/[^\s`<>()"',;]+@[a-z0-9.-]+\.[a-z]{2,}/i.exec(beside)?.[0] ?? "");
282
+ const key = `${normalizeName(person)}\n${normalizeName(title)}`;
283
+ if (seen.has(key))
284
+ return;
285
+ seen.add(key);
286
+ found.push({ ...base, name: person, email: isEmail(email) ? email : "", title });
287
+ };
288
+ const flat = content.replace(/`/g, "");
289
+ for (const match of flat.matchAll(ROLE_IS_RE))
290
+ add(match[1] ?? "", match[2] ?? "", match[3] ?? "");
291
+ for (const match of flat.matchAll(ROLE_PAREN_RE))
292
+ add(match[1] ?? "", "", match[2] ?? "");
293
+ return found;
294
+ }
295
+ export function readPolicyRoles(companyRoot) {
296
+ const dir = path.join(companyRoot, "policies");
297
+ const statements = [];
298
+ let files = 0;
299
+ for (const name of names(dir)) {
300
+ if (!name.endsWith(".md"))
301
+ continue;
302
+ const content = read(path.join(dir, name));
303
+ if (content === null)
304
+ continue;
305
+ files += 1;
306
+ // Cheap gate: most policies name no title at all.
307
+ if (!/\b(?:Head of|VP|Vice President|Director of|Chief|C[ETOFMP]O|[Ff]ounder|President|General Counsel|Managing)\b/.test(content))
308
+ continue;
309
+ const { frontmatter, body } = splitFrontmatter(content);
310
+ const titleLine = text(frontmatter.title);
311
+ const src = `doc:policies/${name}`;
312
+ statements.push(...roleStatements(`${titleLine}\n${body}`, { src, day: dayIn(frontmatter.created) ?? dayIn(frontmatter.updated), kind: "policy", doc: src }));
313
+ }
314
+ return { files, statements };
315
+ }
316
+ export function readPrdOwners(companyRoot) {
317
+ const dir = path.join(companyRoot, "projects");
318
+ const owners = [];
319
+ let files = 0;
320
+ for (const slug of names(dir)) {
321
+ const prd = record(json(path.join(dir, slug, "prd.json")));
322
+ if (Object.keys(prd).length === 0)
323
+ continue;
324
+ files += 1;
325
+ const metadata = record(prd.metadata);
326
+ const owner = text(metadata.owner) || text(prd.owner);
327
+ if (owner === "")
328
+ continue;
329
+ owners.push({
330
+ project: slug,
331
+ title: text(prd.name),
332
+ owner,
333
+ day: dayIn(metadata.createdAt) ?? dayIn(prd.createdAt),
334
+ src: `doc:projects/${slug}/prd.json`,
335
+ });
336
+ }
337
+ return { files, owners };
338
+ }
339
+ // ---------------------------------------------------------------------------
340
+ // Signals: participant roles, deciders and owners (company scope only)
341
+ // ---------------------------------------------------------------------------
342
+ const SIGNAL_ROLE_FOLDERS = ["participant_contribution", "decision", "action_item", "commitment"];
343
+ const LABEL_RE = /^\*{0,2}(Participant|Role|Decided by|Owner):\*{0,2}\s*(.+?)\s*$/;
344
+ /**
345
+ * Role statements from signals a company-wide reader may see. DM signals and
346
+ * per-audience folders are not read here. A signal says what one document
347
+ * suggested, so the caller needs two documents that agree.
348
+ */
349
+ export function readSignalRoles(companyRoot) {
350
+ const statements = [];
351
+ let files = 0;
352
+ for (const folder of SIGNAL_ROLE_FOLDERS) {
353
+ const dir = path.join(companyRoot, "signals", folder);
354
+ for (const name of names(dir)) {
355
+ if (!name.endsWith(".md"))
356
+ continue;
357
+ const content = read(path.join(dir, name));
358
+ if (content === null)
359
+ continue;
360
+ files += 1;
361
+ if (!/(?:^|\n)\*{0,2}(?:Role|Decided by|Owner|role|decided_by|owner):/.test(content))
362
+ continue;
363
+ const { frontmatter, body } = splitFrontmatter(content);
364
+ const signalId = text(frontmatter.signal_id).toLowerCase();
365
+ if (!/^[0-9a-f]{12,}$/.test(signalId))
366
+ continue;
367
+ const doc = text(frontmatter.source_ref) || name;
368
+ const base = { src: `signal:${signalId.slice(0, 12)}`, day: null, kind: "signal", doc };
369
+ const people = list(frontmatter.entity_refs).map((ref) => text(ref)).filter((ref) => ref.startsWith("person/"));
370
+ const labels = {};
371
+ for (const key of ["participant", "role", "decided_by", "owner"])
372
+ if (text(frontmatter[key]) !== "")
373
+ labels[key] = text(frontmatter[key]);
374
+ for (const line of body.split("\n")) {
375
+ const match = LABEL_RE.exec(line.trim());
376
+ if (match)
377
+ labels[match[1].toLowerCase().replace(" ", "_")] ??= plain(match[2] ?? "");
378
+ }
379
+ // `Role:` beside one participant.
380
+ const role = labels.role ? titleFrom(labels.role) : null;
381
+ if (role) {
382
+ const who = people.length === 1 ? people[0] : nameTokens(normalizeName(labels.participant ?? "")).length >= 2 && !slackIdInside(labels.participant ?? "") ? labels.participant : "";
383
+ if (who !== "")
384
+ statements.push({ ...base, name: who, email: "", title: role });
385
+ }
386
+ // `Decided by: Product Lead (U082XQ9F70Q)` or `Owner: Jane Roe (Head of Sales)`.
387
+ for (const key of ["decided_by", "owner"]) {
388
+ const value = labels[key];
389
+ if (!value)
390
+ continue;
391
+ const shaped = /^([^()]{2,60})\(([^()]{2,60})\)$/.exec(value.trim());
392
+ if (!shaped)
393
+ continue;
394
+ const left = shaped[1].trim();
395
+ const right = shaped[2].trim();
396
+ const rightSlack = slackIdInside(right);
397
+ const leftTitle = titleFrom(left);
398
+ const rightTitle = titleFrom(right);
399
+ if (leftTitle && rightSlack && right === rightSlack)
400
+ statements.push({ ...base, name: rightSlack, email: "", title: leftTitle });
401
+ else if (rightTitle && !leftTitle && nameTokens(normalizeName(left)).length >= 2 && !slackIdInside(left))
402
+ statements.push({ ...base, name: left, email: "", title: rightTitle });
403
+ }
404
+ }
405
+ }
406
+ return { files, statements };
407
+ }
408
+ /**
409
+ * The stage a status line states, in the order checked. Words only: `No signed
410
+ * agreement` is not signed, and a file with no status states no stage.
411
+ */
412
+ export function stageFromStatus(status) {
413
+ const flat = ` ${normalizeName(status)} `;
414
+ if (/ churn(?:ed)? | cancel(?:l)?ed | terminated | ended /.test(flat))
415
+ return "churned";
416
+ const negated = / (?:no|not|un|pre|pending|awaiting|draft|before|until|once|when|if) (?:\w+ ){0,3}sign(?:ed|ature|ing)? /.test(flat) || / unsigned /.test(flat) || / (?:to be|not yet|yet to be) signed /.test(flat);
417
+ if (!negated && / (?:signed|executed|countersigned) /.test(flat))
418
+ return "signed";
419
+ if (/ (?:proposal|proposed|sow|quote|pricing sent|contract sent|agreement sent|negotiat\w*) /.test(flat))
420
+ return "proposal";
421
+ if (/ demo (?:complete|completed|done|held) /.test(flat))
422
+ return "demo_done";
423
+ if (/ (?:demo|call booked|discovery|pilot|trial) /.test(flat))
424
+ return "demo";
425
+ if (/ (?:prospect|lead|pre nda|outbound|cold) /.test(flat))
426
+ return "prospect";
427
+ return "";
428
+ }
429
+ const BULLET_FIELD_RE = /^\s*(?:[-*]\s+)?\*{0,2}([A-Za-z][A-Za-z -]{1,40}?)\*{0,2}\s*:\*{0,2}\s*(.*)$/;
430
+ /** `- **Client:** Acme — retention agency` and `Commercial owner: Jane Roe`: the first value of each label. */
431
+ export function labelledLines(content) {
432
+ const out = {};
433
+ for (const line of content.split("\n")) {
434
+ if (line.startsWith("#") || line.startsWith(">") || line.startsWith("|"))
435
+ continue;
436
+ const match = BULLET_FIELD_RE.exec(line);
437
+ if (!match)
438
+ continue;
439
+ const key = normalizeName(match[1] ?? "");
440
+ const value = plain(match[2] ?? "");
441
+ if (key !== "" && value !== "" && out[key] === undefined)
442
+ out[key] = value;
443
+ }
444
+ return out;
445
+ }
446
+ function tableContacts(content) {
447
+ const contacts = [];
448
+ let header = null;
449
+ for (const line of content.split("\n")) {
450
+ if (!line.trim().startsWith("|")) {
451
+ header = null;
452
+ continue;
453
+ }
454
+ const cells = line.trim().replace(/^\||\|$/g, "").split("|").map((cell) => plain(cell));
455
+ if (cells.every((cell) => /^:?-+:?$/.test(cell) || cell === ""))
456
+ continue;
457
+ if (!header) {
458
+ header = cells.map((cell) => normalizeName(cell));
459
+ continue;
460
+ }
461
+ const at = (label) => {
462
+ const index = header.indexOf(label);
463
+ return index >= 0 ? (cells[index] ?? "") : "";
464
+ };
465
+ const name = at("name");
466
+ const email = normalizeEmail(at("email"));
467
+ if (name === "" || !header.includes("name") || !(header.includes("email") || header.includes("role")))
468
+ continue;
469
+ contacts.push({ name, email: isEmail(email) ? email : "", title: at("role") || at("title"), side: normalizeName(at("side")) });
470
+ }
471
+ return contacts;
472
+ }
473
+ function contactFromLine(value, side) {
474
+ // `Drew Fallon, CEO, drew@example.co` or `Andrew Lim, Co-Founder / Creative Director (list note)`.
475
+ const parts = withoutBrackets(value).split(",").map((part) => part.trim()).filter((part) => part !== "");
476
+ const name = parts[0] ?? "";
477
+ if (!new RegExp(`^${PERSON_NAME}$`).test(name) || nameTokens(normalizeName(name)).length < 2)
478
+ return null;
479
+ const email = normalizeEmail(parts.find((part) => isEmail(part)) ?? "");
480
+ const title = parts.slice(1).find((part) => !isEmail(part)) ?? "";
481
+ return { name, email: isEmail(email) ? email : "", title, side };
482
+ }
483
+ export function readClients(companyRoot) {
484
+ const dir = path.join(companyRoot, "clients");
485
+ const clients = [];
486
+ let folders = 0;
487
+ for (const slug of names(dir)) {
488
+ if (slug.startsWith("_") || !isDir(path.join(dir, slug)))
489
+ continue;
490
+ folders += 1;
491
+ const readme = read(path.join(dir, slug, "README.md"));
492
+ const engagement = read(path.join(dir, slug, "engagement.md"));
493
+ const prospect = record(json(path.join(dir, slug, "prospect.json")));
494
+ if (readme === null && engagement === null && Object.keys(prospect).length === 0)
495
+ continue;
496
+ const readmeFields = readme ? labelledLines(readme) : {};
497
+ const engagementFields = engagement ? labelledLines(splitFrontmatter(engagement).body) : {};
498
+ const heading = (content) => {
499
+ const line = (content ?? "").split("\n").find((entry) => /^#\s+\S/.test(entry));
500
+ return line ? plain(line.replace(/^#\s+/, "")).split(/\s+[—–:-]\s+|:\s+/)[0].replace(/\s+(?:engagement|retainer)$/i, "").trim() : "";
501
+ };
502
+ const clientLine = engagementFields.client ?? engagementFields["client as typed in the signed agreement"] ?? "";
503
+ // A prospect file is sometimes named after the person, not the company. A person's name is not a company's:
504
+ // such a client is named by its folder.
505
+ const contactNorm = normalizeName(text(record(prospect.contact).name));
506
+ const companyNamed = (candidate) => (candidate !== "" && !(contactNorm !== "" && normalizeName(candidate).startsWith(contactNorm)) ? candidate : "");
507
+ const name = companyNamed(text(prospect.name)) ||
508
+ plain(clientLine).split(/\s+[—–]\s+|\.\s|\s+\(/)[0].replace(/^"|"$/g, "").trim() ||
509
+ companyNamed(heading(engagement)) ||
510
+ companyNamed(heading(readme)) ||
511
+ (contactNorm !== "" ? slug : "");
512
+ if (name === "" || name.length > 80)
513
+ continue;
514
+ const contacts = [];
515
+ const prospectContact = record(prospect.contact);
516
+ if (text(prospectContact.name) !== "") {
517
+ const email = normalizeEmail(text(prospectContact.email));
518
+ contacts.push({ name: text(prospectContact.name), email: isEmail(email) ? email : "", title: text(prospectContact.title), side: "client" });
519
+ }
520
+ for (const label of ["signer", "day to day contact", "billing contact", "contact", "lead contact"]) {
521
+ const value = engagementFields[label] ?? (label === "contact" ? readmeFields.contact : undefined);
522
+ const contact = value ? contactFromLine(value, "client") : null;
523
+ if (contact)
524
+ contacts.push(contact);
525
+ }
526
+ if (engagement)
527
+ contacts.push(...tableContacts(engagement));
528
+ const statusText = engagementFields.status ?? engagementFields.engagement ?? readmeFields.status ?? "";
529
+ const effective = dayIn(engagementFields["effective date"]);
530
+ const signedWords = stageFromStatus(statusText) === "signed" || (effective !== null && stageFromStatus(statusText) !== "churned");
531
+ const stage = stageFromStatus(statusText) || (effective ? "signed" : engagement ? "" : Object.keys(prospect).length > 0 ? "prospect" : "");
532
+ const owner = engagementFields["commercial owner"] ?? engagementFields["account owner"] ?? engagementFields.owner ?? readmeFields.owner ?? text(prospect.sender) ?? "";
533
+ const internalOwner = contacts.find((contact) => contact.side.startsWith("in") && /\bowner\b/i.test(contact.title));
534
+ const attio = text(record(record(prospect.history).attio).record_id);
535
+ const src = (engagement !== null ? `doc:clients/${slug}/engagement.md` : Object.keys(prospect).length > 0 ? `doc:clients/${slug}/prospect.json` : `doc:clients/${slug}/README.md`);
536
+ clients.push({
537
+ slug,
538
+ name,
539
+ domain: normalizeDomain(text(prospect.domain) || text(prospect.website) || readmeFields.website || ""),
540
+ stage: signedWords ? "signed" : stage,
541
+ statusText: oneLine(statusText, 160),
542
+ owner: plain(owner || internalOwner?.name || "").replace(/\s*\([^)]*\)\s*/g, " ").trim(),
543
+ customer: signedWords,
544
+ effective,
545
+ externalIds: attio !== "" ? [`attio:${attio}`] : [],
546
+ contacts: contacts.filter((contact, index) => contacts.findIndex((other) => normalizeName(other.name) === normalizeName(contact.name)) === index),
547
+ src,
548
+ day: effective ?? dayIn(record(prospect.call).date),
549
+ });
550
+ }
551
+ return { folders, clients };
552
+ }
553
+ /** The newest paying-customer count in `customer-kpis.json`, as a cross-check for the customer rule. */
554
+ export function readPayingCustomerCount(companyRoot) {
555
+ const days = list(record(json(path.join(companyRoot, "customer-kpis.json"))).days).map((day) => record(day));
556
+ let newest = null;
557
+ for (const day of days) {
558
+ const date = dayIn(day.date);
559
+ if (!date || typeof day.payingCustomers !== "number")
560
+ continue;
561
+ if (!newest || date > newest.date)
562
+ newest = { date, payingCustomers: day.payingCustomers };
563
+ }
564
+ return newest;
565
+ }
566
+ // ---------------------------------------------------------------------------
567
+ // Repos
568
+ // ---------------------------------------------------------------------------
569
+ /** The GitHub owner and repo name of a clone, read from its `.git/config`. Null for a linked worktree or a folder that is not a clone. */
570
+ export function originOf(repo) {
571
+ const config = read(path.join(repo, ".git", "config"));
572
+ if (config === null)
573
+ return null;
574
+ const section = /\[remote "origin"\]([^[]*)/.exec(config)?.[1] ?? "";
575
+ const url = /^\s*url\s*=\s*(\S+)/m.exec(section)?.[1] ?? "";
576
+ const match = /github\.com[:/]([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/.exec(url);
577
+ return match ? { owner: match[1].toLowerCase(), name: match[2] } : null;
578
+ }
579
+ /**
580
+ * Every clone under `<hqRoot>/repos/{public,private}` whose origin belongs to
581
+ * one of the GitHub owners of the company's listed repos. A linked worktree
582
+ * (its `.git` is a file) and a second clone of the same origin are left out,
583
+ * so no commit is counted twice.
584
+ */
585
+ export function discoverCompanyRepos(hqRoot, listed) {
586
+ const owners = new Set();
587
+ for (const repo of listed) {
588
+ const origin = originOf(repo);
589
+ if (origin)
590
+ owners.add(origin.owner);
591
+ }
592
+ if (owners.size === 0)
593
+ return [...listed];
594
+ const byOrigin = new Map();
595
+ const consider = (repo) => {
596
+ const origin = originOf(repo);
597
+ if (!origin || !owners.has(origin.owner))
598
+ return;
599
+ const key = `${origin.owner}/${origin.name.toLowerCase()}`;
600
+ const kept = byOrigin.get(key);
601
+ // Prefer the clone whose folder carries the repo's own name.
602
+ if (!kept || (path.basename(kept) !== origin.name && path.basename(repo) === origin.name))
603
+ byOrigin.set(key, repo);
604
+ };
605
+ for (const repo of listed)
606
+ consider(repo);
607
+ for (const scope of ["private", "public"]) {
608
+ const dir = path.join(hqRoot, "repos", scope);
609
+ for (const name of names(dir))
610
+ consider(path.join(dir, name));
611
+ }
612
+ return sortedUnique(byOrigin.values());
613
+ }
614
+ /** The repo name a clone is known by: its origin's name, else its folder name. */
615
+ export function repoNameOf(repo) {
616
+ return originOf(repo)?.name ?? path.basename(repo);
617
+ }
618
+ export function readOrgSources(companyRoot) {
619
+ const standups = readStandupNotes(companyRoot);
620
+ const policies = readPolicyRoles(companyRoot);
621
+ const signals = readSignalRoles(companyRoot);
622
+ const prds = readPrdOwners(companyRoot);
623
+ const clients = readClients(companyRoot);
624
+ return {
625
+ standups,
626
+ policyRoles: policies.statements,
627
+ signalRoles: signals.statements,
628
+ prdOwners: prds.owners,
629
+ clients: clients.clients,
630
+ payingCustomers: readPayingCustomerCount(companyRoot),
631
+ counts: { standupFiles: standups.files, policyFiles: policies.files, signalFiles: signals.files, prdFiles: prds.files, clientFolders: clients.folders },
632
+ };
633
+ }
634
+ //# sourceMappingURL=org-sources.js.map