@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.
- package/CHANGELOG.md +63 -0
- package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
- package/contracts/host-canary-release.json +14 -0
- package/dist/command-catalog.generated.d.ts +1116 -3
- package/dist/command-catalog.generated.js +1373 -3
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/install-global.d.ts +15 -0
- package/dist/commands/install-global.js +98 -4
- package/dist/commands/lanes-hold.js +7 -7
- package/dist/commands/lanes-resume.js +2 -2
- package/dist/commands/lanes-review.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -1
- package/dist/commands/lanes-session-start.js +3 -3
- package/dist/commands/lanes-shared.d.ts +1 -1
- package/dist/commands/lanes.d.ts +2 -2
- package/dist/commands/lanes.js +50 -50
- package/dist/commands/mcp-registration.d.ts +17 -0
- package/dist/commands/mcp-registration.js +119 -0
- package/dist/commands/mesh.d.ts +25 -0
- package/dist/commands/mesh.js +48 -8
- package/dist/commands/ontology-graph.d.ts +62 -0
- package/dist/commands/ontology-graph.js +439 -0
- package/dist/commands/pkg-install.js +1 -1
- package/dist/commands/reindex.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lanes-monitor-check-argv.d.ts +1 -1
- package/dist/lanes-monitor-check-argv.js +1 -1
- package/dist/lanes-monitor-check-fast.d.ts +1 -1
- package/dist/lanes-monitor-check-fast.js +1 -1
- package/dist/lanes-session-start-argv.d.ts +1 -1
- package/dist/lanes-session-start-argv.js +1 -1
- package/dist/lib/capacity/sign-in.d.ts +1 -1
- package/dist/lib/capacity/sign-in.js +1 -1
- package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
- package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
- package/dist/lib/daemon/lanes-monitor-state.js +2 -2
- package/dist/lib/daemon/merge-sections.d.ts +3 -3
- package/dist/lib/daemon/merge-sections.js +7 -7
- package/dist/lib/daemon/remote-control-pools.js +1 -1
- package/dist/lib/daemon/run.js +1 -1
- package/dist/lib/daemon/state-file.d.ts +1 -1
- package/dist/lib/daemon/state-file.js +1 -1
- package/dist/lib/doctor/checks/antigravity-wiring.d.ts +21 -0
- package/dist/lib/doctor/checks/antigravity-wiring.js +75 -0
- package/dist/lib/doctor/checks/anywhere.js +30 -0
- package/dist/lib/doctor/checks/runtime-probe.js +13 -0
- package/dist/lib/doctor/platform.d.ts +1 -1
- package/dist/lib/doctor/platform.js +5 -0
- package/dist/lib/doctor/registry.js +3 -0
- package/dist/lib/flag-snapshot-file.d.ts +2 -0
- package/dist/lib/flag-snapshot-file.js +118 -48
- package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
- package/dist/lib/hook-engine/canary-gate.js +138 -6
- package/dist/lib/hook-engine/coverage.d.ts +91 -0
- package/dist/lib/hook-engine/coverage.js +184 -0
- package/dist/lib/hot-channels/graph-context.d.ts +105 -0
- package/dist/lib/hot-channels/graph-context.js +377 -0
- package/dist/lib/hot-channels/signals-pass.js +27 -1
- package/dist/lib/install/antigravity-targets.d.ts +39 -0
- package/dist/lib/install/antigravity-targets.js +122 -0
- package/dist/lib/lanes/claude-credential.d.ts +1 -1
- package/dist/lib/lanes/claude-credential.js +1 -1
- package/dist/lib/lanes/delivery-core.d.ts +1 -1
- package/dist/lib/lanes/delivery-core.js +1 -1
- package/dist/lib/lanes/delivery.d.ts +10 -10
- package/dist/lib/lanes/delivery.js +8 -8
- package/dist/lib/lanes/dropbox.d.ts +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +2 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.js +1 -1
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/quota.d.ts +1 -1
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
- package/dist/lib/lanes/repo-merge-hold.js +2 -2
- package/dist/lib/lanes/spawn.d.ts +4 -4
- package/dist/lib/lanes/spawn.js +5 -5
- package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
- package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
- package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
- package/dist/lib/mesh/live/daemon/run.js +35 -2
- package/dist/lib/mesh/live/direct-drain.js +1 -1
- package/dist/lib/mesh/live/emit.d.ts +3 -0
- package/dist/lib/mesh/live/emit.js +32 -9
- package/dist/lib/mesh/live/flush.d.ts +3 -0
- package/dist/lib/mesh/live/flush.js +115 -32
- package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
- package/dist/lib/mesh/live/liveness-carry.js +1 -1
- package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
- package/dist/lib/mesh/live/reporting-privacy.js +235 -11
- package/dist/lib/mesh/live/spool.d.ts +17 -2
- package/dist/lib/mesh/live/spool.js +22 -6
- package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
- package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
- package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
- package/dist/lib/ontology-graph/legacy/index.js +1150 -0
- package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
- package/dist/lib/ontology-graph/legacy/parse.js +126 -0
- package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
- package/dist/lib/ontology-graph/legacy/report.js +254 -0
- package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
- package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
- package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
- package/dist/lib/ontology-graph/lint/checks.js +717 -0
- package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
- package/dist/lib/ontology-graph/lint/coverage.js +241 -0
- package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
- package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
- package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
- package/dist/lib/ontology-graph/lint/index.js +176 -0
- package/dist/lib/ontology-graph/model/files.d.ts +20 -0
- package/dist/lib/ontology-graph/model/files.js +89 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -0
- package/dist/lib/ontology-graph/model/index.js +100 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
- package/dist/lib/ontology-graph/model/pass.js +958 -0
- package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
- package/dist/lib/ontology-graph/model/runner.js +160 -0
- package/dist/lib/ontology-graph/model/step.d.ts +195 -0
- package/dist/lib/ontology-graph/model/step.js +523 -0
- package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
- package/dist/lib/ontology-graph/model/tasks.js +349 -0
- package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
- package/dist/lib/ontology-graph/not-implemented.js +8 -0
- package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
- package/dist/lib/ontology-graph/org/compare.js +239 -0
- package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
- package/dist/lib/ontology-graph/org/derive.js +352 -0
- package/dist/lib/ontology-graph/org/index.d.ts +73 -0
- package/dist/lib/ontology-graph/org/index.js +513 -0
- package/dist/lib/ontology-graph/org/load.d.ts +31 -0
- package/dist/lib/ontology-graph/org/load.js +476 -0
- package/dist/lib/ontology-graph/org/role.d.ts +38 -0
- package/dist/lib/ontology-graph/org/role.js +268 -0
- package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
- package/dist/lib/ontology-graph/org/structure.js +437 -0
- package/dist/lib/ontology-graph/org/text.d.ts +95 -0
- package/dist/lib/ontology-graph/org/text.js +315 -0
- package/dist/lib/ontology-graph/org/types.d.ts +452 -0
- package/dist/lib/ontology-graph/org/types.js +80 -0
- package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
- package/dist/lib/ontology-graph/pages/index.js +193 -0
- package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
- package/dist/lib/ontology-graph/pages/render.js +682 -0
- package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
- package/dist/lib/ontology-graph/proposals/apply.js +468 -0
- package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
- package/dist/lib/ontology-graph/proposals/group.js +232 -0
- package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
- package/dist/lib/ontology-graph/proposals/index.js +474 -0
- package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
- package/dist/lib/ontology-graph/proposals/model.js +196 -0
- package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
- package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
- package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
- package/dist/lib/ontology-graph/read/brief.js +251 -0
- package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
- package/dist/lib/ontology-graph/read/graph-index.js +198 -0
- package/dist/lib/ontology-graph/read/index.d.ts +59 -0
- package/dist/lib/ontology-graph/read/index.js +792 -0
- package/dist/lib/ontology-graph/read/member.d.ts +7 -0
- package/dist/lib/ontology-graph/read/member.js +34 -0
- package/dist/lib/ontology-graph/read/names.d.ts +44 -0
- package/dist/lib/ontology-graph/read/names.js +292 -0
- package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
- package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
- package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
- package/dist/lib/ontology-graph/read/test-graph.js +150 -0
- package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
- package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
- package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
- package/dist/lib/ontology-graph/replay/config.js +105 -0
- package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
- package/dist/lib/ontology-graph/replay/engine.js +1174 -0
- package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
- package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
- package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
- package/dist/lib/ontology-graph/replay/index.js +220 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
- package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
- package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
- package/dist/lib/ontology-graph/replay/member.js +65 -0
- package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
- package/dist/lib/ontology-graph/replay/mentions.js +239 -0
- package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
- package/dist/lib/ontology-graph/replay/readers.js +1251 -0
- package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
- package/dist/lib/ontology-graph/replay/rules.js +374 -0
- package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
- package/dist/lib/ontology-graph/replay/scope.js +115 -0
- package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
- package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
- package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
- package/dist/lib/ontology-graph/replay/util.js +256 -0
- package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
- package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
- package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
- package/dist/lib/ontology-graph/resolve/index.js +214 -0
- package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
- package/dist/lib/ontology-graph/resolve/machine.js +95 -0
- package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
- package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
- package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
- package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
- package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
- package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
- package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
- package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
- package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
- package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
- package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
- package/dist/lib/ontology-graph/resolve/roster.js +226 -0
- package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
- package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
- package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
- package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
- package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
- package/dist/lib/ontology-graph/resolve/writer.js +351 -0
- package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
- package/dist/lib/ontology-graph/schema/authority.js +157 -0
- package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
- package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
- package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
- package/dist/lib/ontology-graph/schema/grammar.js +409 -0
- package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
- package/dist/lib/ontology-graph/schema/index.js +10 -0
- package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
- package/dist/lib/ontology-graph/schema/validate.js +132 -0
- package/dist/lib/ontology-graph/store/files.d.ts +34 -0
- package/dist/lib/ontology-graph/store/files.js +207 -0
- package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
- package/dist/lib/ontology-graph/store/fs.js +101 -0
- package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
- package/dist/lib/ontology-graph/store/graph-store.js +520 -0
- package/dist/lib/ontology-graph/store/index.d.ts +18 -0
- package/dist/lib/ontology-graph/store/index.js +15 -0
- package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
- package/dist/lib/ontology-graph/store/ingest.js +323 -0
- package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
- package/dist/lib/ontology-graph/store/paths.js +232 -0
- package/dist/lib/ontology-graph/types.d.ts +1183 -0
- package/dist/lib/ontology-graph/types.js +131 -0
- package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
- package/dist/utils/frontmatter.d.ts +14 -0
- package/dist/utils/frontmatter.js +18 -0
- package/dist/utils/interactive-caller.js +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,1198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-C: the identity seed. Before any day is replayed it reads the places a
|
|
3
|
+
* company keeps identity anchors and writes the org structure they state:
|
|
4
|
+
* people, the roles they hold, teams, who works on and owns what, and which
|
|
5
|
+
* companies are customers.
|
|
6
|
+
*
|
|
7
|
+
* Sources, all relative to the company folder unless noted, all optional:
|
|
8
|
+
* people/<slug>/meta.yaml name, email, other addresses, HQ person uid, GitHub login, role, team, manager
|
|
9
|
+
* sources/slack-dm/*.md frontmatter Slack id to email and HQ person uid (only DMs the member owns, correction C2)
|
|
10
|
+
* sources/slack/*.md frontmatter channel name and participant Slack ids
|
|
11
|
+
* sources/slack and slack-dm raw JSON Slack id to real name
|
|
12
|
+
* <mesh contacts dir>/<member>.json HQ person uid, email, display name (the member's own contacts file)
|
|
13
|
+
* git history of the company's repos author name and email, GitHub login from a noreply address
|
|
14
|
+
* board.json project owner
|
|
15
|
+
* crm-projection.json account name, domain, CRM ids, stage
|
|
16
|
+
* company.yaml the company itself
|
|
17
|
+
* <graph root>/.state/org-layer.json the org chart people keep in HQ (org-layer.ts fills it)
|
|
18
|
+
* meetings/notes, policies, projects/<slug>/prd.json, signals, clients (org-sources.ts)
|
|
19
|
+
*
|
|
20
|
+
* A Slack id never becomes a person. It joins a person through an email or a
|
|
21
|
+
* real name from the maps above, or it stays in the Slack directory for the
|
|
22
|
+
* resolver to park. Nothing in this file names a company.
|
|
23
|
+
*/
|
|
24
|
+
import { execFileSync } from "node:child_process";
|
|
25
|
+
import * as fs from "node:fs";
|
|
26
|
+
import * as os from "node:os";
|
|
27
|
+
import * as path from "node:path";
|
|
28
|
+
import yaml from "js-yaml";
|
|
29
|
+
import { splitLenientFrontmatter } from "../../../utils/frontmatter.js";
|
|
30
|
+
import { SHARED_MAIL_DOMAINS, githubLoginFromEmail, isEmail, isRecordIdName, nameTokens, normalizeDomain, normalizeEmail, normalizeName, slackIdOf, sortedUnique, } from "./normalize.js";
|
|
31
|
+
import { isMachineEmail, isMachineName } from "./machine.js";
|
|
32
|
+
import { readConfirmedOrgChart, ORG_CHART_FILE } from "./org-chart.js";
|
|
33
|
+
import { parseOrgLayer, readOrgLayerCache } from "./org-layer.js";
|
|
34
|
+
import { Roster } from "./roster.js";
|
|
35
|
+
import { applyClients, applyEmailAffiliation, applyOrgLayerLinks, applyPrdOwners, applyRoleStatements, applyStandupAttendance, applyTeams, collectStandupEvidence, emptyOrgSeedCounts, resolvePersonName, } from "./org-seed.js";
|
|
36
|
+
import { FUNCTION_TERMS, discoverCompanyRepos, functionLabel, functionsOf, readOrgSources, repoNameOf } from "./org-sources.js";
|
|
37
|
+
import { repoProjectName } from "./upsert.js";
|
|
38
|
+
import { dayOf, edgeRow, factRow, proposalId } from "./writer.js";
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Reading
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
const COPY_NAME_RE = /(?: \d+(?=\.[^.]+$)|\.conflict-)/;
|
|
43
|
+
/** True for a sync conflict copy: `name 2.md` or `name.md.conflict-<stamp>.md`. */
|
|
44
|
+
export function isCopyName(name) {
|
|
45
|
+
return COPY_NAME_RE.test(name) || / \d+$/.test(name);
|
|
46
|
+
}
|
|
47
|
+
function listNames(dir) {
|
|
48
|
+
try {
|
|
49
|
+
return fs.readdirSync(dir).filter((name) => !name.startsWith(".")).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function readText(file) {
|
|
56
|
+
try {
|
|
57
|
+
return fs.readFileSync(file, "utf8");
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function loadYaml(text) {
|
|
64
|
+
if (text === null)
|
|
65
|
+
return null;
|
|
66
|
+
try {
|
|
67
|
+
const loaded = yaml.load(text, { schema: yaml.CORE_SCHEMA });
|
|
68
|
+
return loaded && typeof loaded === "object" && !Array.isArray(loaded) ? loaded : null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The YAML frontmatter of a markdown file, or null. */
|
|
75
|
+
export function readFrontmatter(text) {
|
|
76
|
+
const split = text === null ? null : splitLenientFrontmatter(text);
|
|
77
|
+
return split ? loadYaml(split.yaml) : null;
|
|
78
|
+
}
|
|
79
|
+
function loadJson(file) {
|
|
80
|
+
const text = readText(file);
|
|
81
|
+
if (text === null)
|
|
82
|
+
return null;
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(text);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const text = (value) => (typeof value === "string" ? value.trim() : "");
|
|
91
|
+
const list = (value) => (Array.isArray(value) ? value : []);
|
|
92
|
+
const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
93
|
+
function readGraphSettings(companyRoot) {
|
|
94
|
+
const loaded = loadYaml(readText(path.join(companyRoot, "settings", "ontology-graph.yaml")));
|
|
95
|
+
const words = (value) => list(value).map((entry) => text(entry)).filter((entry) => entry !== "");
|
|
96
|
+
return {
|
|
97
|
+
products: words(loaded?.products),
|
|
98
|
+
vendors: words(loaded?.vendors),
|
|
99
|
+
ownCompanies: words(loaded?.own_companies),
|
|
100
|
+
machineIdentities: words(loaded?.machine_identities),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function defaultGitLog(repo) {
|
|
104
|
+
// One process per repo. The default branch on the remote is read too, so a clone parked on an old branch still counts.
|
|
105
|
+
const refs = ["HEAD", "--glob=refs/remotes/origin/HEAD", "--glob=refs/remotes/origin/main", "--glob=refs/remotes/origin/master"];
|
|
106
|
+
const out = execFileSync("git", ["-C", repo, "log", "--no-merges", "--format=%aN%x09%aE%x09%as", ...refs], {
|
|
107
|
+
encoding: "utf8",
|
|
108
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
109
|
+
timeout: 120_000,
|
|
110
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
111
|
+
});
|
|
112
|
+
const lines = [];
|
|
113
|
+
for (const line of out.split("\n")) {
|
|
114
|
+
const [name, email, day] = line.split("\t");
|
|
115
|
+
if (name && email && day && dayOf(day))
|
|
116
|
+
lines.push({ name: name.trim(), email: email.trim().toLowerCase(), day });
|
|
117
|
+
}
|
|
118
|
+
return lines;
|
|
119
|
+
}
|
|
120
|
+
function isBotAuthor(name, email, check = {}) {
|
|
121
|
+
if (isMachineName(name, check) || isMachineEmail(email))
|
|
122
|
+
return true;
|
|
123
|
+
if (/\[bot\]/i.test(name) || /\[bot\]@/i.test(email))
|
|
124
|
+
return true;
|
|
125
|
+
const local = email.split("@")[0] ?? "";
|
|
126
|
+
if (/^(?:noreply|no-reply|donotreply|actions|bot)$/i.test(local))
|
|
127
|
+
return true;
|
|
128
|
+
return /(?:^|[^a-z])(?:bot|agent|automation|github actions|dependabot|renovate)$/i.test(name.trim());
|
|
129
|
+
}
|
|
130
|
+
function manifestRepos(context) {
|
|
131
|
+
const manifest = loadYaml(readText(path.join(context.hqRoot, "companies", "manifest.yaml")));
|
|
132
|
+
const absolute = (value) => list(record(value).repos)
|
|
133
|
+
.map((entry) => text(entry))
|
|
134
|
+
.filter((entry) => entry !== "")
|
|
135
|
+
.map((entry) => (path.isAbsolute(entry) ? entry : path.join(context.hqRoot, entry)));
|
|
136
|
+
const companies = record(manifest?.companies);
|
|
137
|
+
return {
|
|
138
|
+
listed: absolute(companies[context.company]),
|
|
139
|
+
otherCompanies: Object.keys(companies).filter((slug) => slug !== context.company).flatMap((slug) => absolute(companies[slug])),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Slack id maps and channel participation from the company's Slack sources, limited to what the member may read. */
|
|
143
|
+
export function loadSlackDirectory(companyRoot, member) {
|
|
144
|
+
const directory = { idToEmail: {}, idToName: {} };
|
|
145
|
+
const uidBySlackId = {};
|
|
146
|
+
const channels = new Map();
|
|
147
|
+
let dmFilesRead = 0;
|
|
148
|
+
let dmFilesSkipped = 0;
|
|
149
|
+
const noteParticipant = (entry) => {
|
|
150
|
+
const slackId = slackIdOf(text(entry.slack_user_id));
|
|
151
|
+
if (!slackId)
|
|
152
|
+
return;
|
|
153
|
+
const email = normalizeEmail(text(entry.email));
|
|
154
|
+
if (isEmail(email) && !directory.idToEmail[slackId])
|
|
155
|
+
directory.idToEmail[slackId] = email;
|
|
156
|
+
const uid = text(entry.person_uid);
|
|
157
|
+
if (/^prs_[0-9A-Za-z]+$/.test(uid) && !uidBySlackId[slackId])
|
|
158
|
+
uidBySlackId[slackId] = uid;
|
|
159
|
+
};
|
|
160
|
+
const noteProfiles = (file) => {
|
|
161
|
+
const raw = record(loadJson(file));
|
|
162
|
+
for (const message of list(raw.messages)) {
|
|
163
|
+
const entry = record(message);
|
|
164
|
+
const slackId = slackIdOf(text(entry.user));
|
|
165
|
+
const profile = record(entry.user_profile);
|
|
166
|
+
const realName = text(profile.real_name) || text(profile.display_name);
|
|
167
|
+
if (slackId && realName !== "" && !slackIdOf(realName) && !directory.idToName[slackId])
|
|
168
|
+
directory.idToName[slackId] = realName;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
// Channel threads are company scope.
|
|
172
|
+
const channelDir = path.join(companyRoot, "sources", "slack");
|
|
173
|
+
for (const name of listNames(channelDir)) {
|
|
174
|
+
if (isCopyName(name))
|
|
175
|
+
continue;
|
|
176
|
+
const file = path.join(channelDir, name);
|
|
177
|
+
if (name.endsWith(".raw.json")) {
|
|
178
|
+
noteProfiles(file);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!name.endsWith(".md"))
|
|
182
|
+
continue;
|
|
183
|
+
const frontmatter = readFrontmatter(readText(file));
|
|
184
|
+
if (!frontmatter)
|
|
185
|
+
continue;
|
|
186
|
+
const channelName = text(frontmatter.channel_name);
|
|
187
|
+
const day = dayOf(frontmatter.first_message_at) ?? dayOf(frontmatter.ingested_at);
|
|
188
|
+
if (channelName === "" || !day)
|
|
189
|
+
continue;
|
|
190
|
+
let channel = channels.get(channelName);
|
|
191
|
+
if (!channel)
|
|
192
|
+
channels.set(channelName, (channel = { name: channelName, firstFile: name, firstDay: day, participants: {} }));
|
|
193
|
+
if (day < channel.firstDay) {
|
|
194
|
+
channel.firstDay = day;
|
|
195
|
+
channel.firstFile = name;
|
|
196
|
+
}
|
|
197
|
+
for (const participant of list(frontmatter.participants)) {
|
|
198
|
+
const slackId = slackIdOf(text(participant));
|
|
199
|
+
if (!slackId)
|
|
200
|
+
continue;
|
|
201
|
+
const seen = channel.participants[slackId];
|
|
202
|
+
if (!seen)
|
|
203
|
+
channel.participants[slackId] = { threads: 1, firstDay: day };
|
|
204
|
+
else {
|
|
205
|
+
seen.threads += 1;
|
|
206
|
+
if (day < seen.firstDay)
|
|
207
|
+
seen.firstDay = day;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// DMs are personal scope: only the member's own (correction C2).
|
|
212
|
+
const dmDir = path.join(companyRoot, "sources", "slack-dm");
|
|
213
|
+
const owned = new Set();
|
|
214
|
+
const dmNames = listNames(dmDir).filter((name) => !isCopyName(name));
|
|
215
|
+
for (const name of dmNames) {
|
|
216
|
+
if (!name.endsWith(".md"))
|
|
217
|
+
continue;
|
|
218
|
+
if (!member) {
|
|
219
|
+
dmFilesSkipped += 1;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const frontmatter = readFrontmatter(readText(path.join(dmDir, name)));
|
|
223
|
+
if (!frontmatter || text(frontmatter.person_uid) !== member.personUid) {
|
|
224
|
+
dmFilesSkipped += 1;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
dmFilesRead += 1;
|
|
228
|
+
owned.add(name.slice(0, -3));
|
|
229
|
+
for (const participant of [...list(frontmatter.resolved_participants), ...list(frontmatter.unresolved_participants)]) {
|
|
230
|
+
noteParticipant(record(participant));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
for (const name of dmNames) {
|
|
234
|
+
if (name.endsWith(".raw.json") && owned.has(name.slice(0, -".raw.json".length)))
|
|
235
|
+
noteProfiles(path.join(dmDir, name));
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
directory,
|
|
239
|
+
channels: [...channels.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)),
|
|
240
|
+
uidBySlackId,
|
|
241
|
+
dmFilesRead,
|
|
242
|
+
dmFilesSkipped,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/** Reads every identity source. Writes nothing. */
|
|
246
|
+
export function buildIdentitySeed(context, options) {
|
|
247
|
+
const member = options.member ?? context.member;
|
|
248
|
+
const companyRoot = context.companyRoot;
|
|
249
|
+
const counts = {
|
|
250
|
+
peopleFiles: 0,
|
|
251
|
+
dmFilesRead: 0,
|
|
252
|
+
dmFilesSkippedOtherOwner: 0,
|
|
253
|
+
slackIdsWithEmail: 0,
|
|
254
|
+
slackIdsWithName: 0,
|
|
255
|
+
meshContacts: 0,
|
|
256
|
+
meshContactsMatched: 0,
|
|
257
|
+
meshContactsUnmatched: 0,
|
|
258
|
+
meshAgentsSkipped: 0,
|
|
259
|
+
gitRepos: 0,
|
|
260
|
+
gitReposFailed: 0,
|
|
261
|
+
gitAuthors: 0,
|
|
262
|
+
gitBotsSkipped: 0,
|
|
263
|
+
gitAuthorsSameNameOtherEmail: 0,
|
|
264
|
+
boardProjects: 0,
|
|
265
|
+
crmAccounts: 0,
|
|
266
|
+
crmAccountsUnnamed: 0,
|
|
267
|
+
namelessIdentities: 0,
|
|
268
|
+
};
|
|
269
|
+
const people = [];
|
|
270
|
+
const byKey = new Map();
|
|
271
|
+
const byName = new Map();
|
|
272
|
+
const sameNameOtherEmail = [];
|
|
273
|
+
const keysOf = (person) => [
|
|
274
|
+
...person.emails.map((email) => `email:${email}`),
|
|
275
|
+
...person.slackIds.map((id) => `slack:${id}`),
|
|
276
|
+
...person.externalIds.map((id) => `ext:${id}`),
|
|
277
|
+
];
|
|
278
|
+
const fileKeys = (person) => {
|
|
279
|
+
for (const key of keysOf(person))
|
|
280
|
+
if (!byKey.has(key))
|
|
281
|
+
byKey.set(key, person);
|
|
282
|
+
};
|
|
283
|
+
const addPerson = (person) => {
|
|
284
|
+
people.push(person);
|
|
285
|
+
fileKeys(person);
|
|
286
|
+
const norm = normalizeName(person.name);
|
|
287
|
+
byName.set(norm, [...(byName.get(norm) ?? []), person]);
|
|
288
|
+
return person;
|
|
289
|
+
};
|
|
290
|
+
const find = (keys) => {
|
|
291
|
+
for (const key of keys) {
|
|
292
|
+
const hit = byKey.get(key);
|
|
293
|
+
if (hit)
|
|
294
|
+
return hit;
|
|
295
|
+
}
|
|
296
|
+
return undefined;
|
|
297
|
+
};
|
|
298
|
+
const attach = (person, extra) => {
|
|
299
|
+
person.emails = sortedUnique([...person.emails, ...(extra.emails ?? [])]);
|
|
300
|
+
person.slackIds = sortedUnique([...person.slackIds, ...(extra.slackIds ?? [])]);
|
|
301
|
+
person.externalIds = sortedUnique([...person.externalIds, ...(extra.externalIds ?? [])]);
|
|
302
|
+
if (extra.alias && normalizeName(extra.alias) !== normalizeName(person.name))
|
|
303
|
+
person.aliases = sortedUnique([...person.aliases, extra.alias]);
|
|
304
|
+
if (!person.from.includes(extra.from))
|
|
305
|
+
person.from.push(extra.from);
|
|
306
|
+
fileKeys(person);
|
|
307
|
+
};
|
|
308
|
+
// 1. The company itself.
|
|
309
|
+
const companyYaml = loadYaml(readText(path.join(companyRoot, "company.yaml")));
|
|
310
|
+
const selfName = text(companyYaml?.name);
|
|
311
|
+
const self = selfName !== "" ? { name: selfName, slug: text(companyYaml?.slug) || context.company } : null;
|
|
312
|
+
// 2. People files: the roster a human keeps.
|
|
313
|
+
const peopleDir = path.join(companyRoot, "people");
|
|
314
|
+
for (const slug of listNames(peopleDir)) {
|
|
315
|
+
if (slug.startsWith("_") || isCopyName(slug))
|
|
316
|
+
continue;
|
|
317
|
+
const meta = loadYaml(readText(path.join(peopleDir, slug, "meta.yaml")));
|
|
318
|
+
const name = text(meta?.name);
|
|
319
|
+
if (!meta || name === "")
|
|
320
|
+
continue;
|
|
321
|
+
counts.peopleFiles += 1;
|
|
322
|
+
const handles = record(meta.handles);
|
|
323
|
+
const emails = [];
|
|
324
|
+
const externalIds = [];
|
|
325
|
+
const push = (address) => {
|
|
326
|
+
const email = normalizeEmail(text(address));
|
|
327
|
+
if (isEmail(email))
|
|
328
|
+
emails.push(email);
|
|
329
|
+
};
|
|
330
|
+
push(meta.email);
|
|
331
|
+
for (const other of list(meta.other_addresses)) {
|
|
332
|
+
push(record(other).address);
|
|
333
|
+
const account = text(record(other).hq_account);
|
|
334
|
+
if (/^prs_[0-9A-Za-z]+$/.test(account))
|
|
335
|
+
externalIds.push(`hq:${account}`);
|
|
336
|
+
}
|
|
337
|
+
const uid = text(handles.hq_person_uid);
|
|
338
|
+
if (/^prs_[0-9A-Za-z]+$/.test(uid))
|
|
339
|
+
externalIds.push(`hq:${uid}`);
|
|
340
|
+
const github = text(handles.github).replace(/^@/, "").toLowerCase();
|
|
341
|
+
if (/^[a-z0-9][a-z0-9-]*$/.test(github))
|
|
342
|
+
externalIds.push(`github:${github}`);
|
|
343
|
+
const linear = text(handles.linear);
|
|
344
|
+
if (linear !== "")
|
|
345
|
+
externalIds.push(`linear:${linear}`);
|
|
346
|
+
const slackHandle = slackIdOf(text(handles.slack));
|
|
347
|
+
const teams = [...list(meta.teams), meta.team].map((entry) => text(entry)).filter((entry) => entry !== "");
|
|
348
|
+
const role = text(meta.role);
|
|
349
|
+
const tags = list(meta.tags).map((entry) => text(entry)).filter((entry) => entry !== "");
|
|
350
|
+
const organization = text(meta.organization);
|
|
351
|
+
const manager = text(meta.reports_to) || text(meta.manager);
|
|
352
|
+
addPerson({
|
|
353
|
+
name,
|
|
354
|
+
aliases: [],
|
|
355
|
+
emails: sortedUnique(emails),
|
|
356
|
+
slackIds: slackHandle ? [slackHandle] : [],
|
|
357
|
+
externalIds: sortedUnique(externalIds),
|
|
358
|
+
...(role !== "" ? { role } : {}),
|
|
359
|
+
internal: text(meta.type) === "internal",
|
|
360
|
+
roster: text(meta.type) === "internal",
|
|
361
|
+
personUids: sortedUnique(externalIds.filter((id) => id.startsWith("hq:prs_")).map((id) => id.slice(3))),
|
|
362
|
+
...(organization !== "" ? { organization } : {}),
|
|
363
|
+
teams: sortedUnique(teams),
|
|
364
|
+
tags: sortedUnique(tags),
|
|
365
|
+
...(manager !== "" ? { manager } : {}),
|
|
366
|
+
seen: dayOf(meta.added) ?? options.learned,
|
|
367
|
+
src: `doc:people/${slug}/meta.yaml`,
|
|
368
|
+
by: "record",
|
|
369
|
+
conf: 0.9,
|
|
370
|
+
from: ["people"],
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
// 3. Slack: id to email, person uid and real name.
|
|
374
|
+
const slack = loadSlackDirectory(companyRoot, member);
|
|
375
|
+
counts.dmFilesRead = slack.dmFilesRead;
|
|
376
|
+
counts.dmFilesSkippedOtherOwner = slack.dmFilesSkipped;
|
|
377
|
+
counts.slackIdsWithEmail = Object.keys(slack.directory.idToEmail).length;
|
|
378
|
+
counts.slackIdsWithName = Object.keys(slack.directory.idToName).length;
|
|
379
|
+
/** Identities known by keys only, waiting for a name. */
|
|
380
|
+
const nameless = new Map();
|
|
381
|
+
const slackIds = sortedUnique([...Object.keys(slack.directory.idToEmail), ...Object.keys(slack.uidBySlackId), ...Object.keys(slack.directory.idToName)]);
|
|
382
|
+
for (const slackId of slackIds) {
|
|
383
|
+
const email = slack.directory.idToEmail[slackId];
|
|
384
|
+
const uid = slack.uidBySlackId[slackId];
|
|
385
|
+
const realName = slack.directory.idToName[slackId];
|
|
386
|
+
const keys = [...(email ? [`email:${email}`] : []), ...(uid ? [`ext:hq:${uid}`] : []), `slack:${slackId}`];
|
|
387
|
+
let person = find(keys);
|
|
388
|
+
if (!person && realName && nameTokens(normalizeName(realName)).length >= 2) {
|
|
389
|
+
// The Slack id-to-name map: joins a person only when exactly one carries that full name.
|
|
390
|
+
const named = byName.get(normalizeName(realName)) ?? [];
|
|
391
|
+
const emailClash = email !== undefined && named.length === 1 && named[0].emails.length > 0 && !named[0].emails.includes(email);
|
|
392
|
+
if (named.length === 1 && !emailClash)
|
|
393
|
+
person = named[0];
|
|
394
|
+
else if (emailClash)
|
|
395
|
+
sameNameOtherEmail.push({ name: realName, email: email, src: `record:slack:${slackId}` });
|
|
396
|
+
}
|
|
397
|
+
if (person) {
|
|
398
|
+
attach(person, { ...(email ? { emails: [email] } : {}), slackIds: [slackId], ...(uid ? { externalIds: [`hq:${uid}`] } : {}), ...(realName ? { alias: realName } : {}), from: "slack" });
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (realName && email && !isMachineName(realName) && !isMachineEmail(email) && !sameNameOtherEmail.some((entry) => entry.email === email)) {
|
|
402
|
+
// A real name and an email from two Slack sources: enough for a person. The id alone never is.
|
|
403
|
+
addPerson({
|
|
404
|
+
name: realName,
|
|
405
|
+
aliases: [],
|
|
406
|
+
emails: [email],
|
|
407
|
+
slackIds: [slackId],
|
|
408
|
+
externalIds: uid ? [`hq:${uid}`] : [],
|
|
409
|
+
teams: [],
|
|
410
|
+
seen: options.learned,
|
|
411
|
+
src: `record:slack:${slackId}`,
|
|
412
|
+
by: "record",
|
|
413
|
+
conf: 0.8,
|
|
414
|
+
from: ["slack"],
|
|
415
|
+
});
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (email || uid)
|
|
419
|
+
nameless.set(slackId, { emails: email ? [email] : [], slackIds: [slackId], externalIds: uid ? [`hq:${uid}`] : [] });
|
|
420
|
+
}
|
|
421
|
+
/** Addresses that belong to agents, from the contacts file and the org layer. */
|
|
422
|
+
const agentEmails = new Set();
|
|
423
|
+
const settings = readGraphSettings(companyRoot);
|
|
424
|
+
/** Names of agents and services. A person on the roster with the same name stays a person. */
|
|
425
|
+
const machineNames = new Set(settings.machineIdentities.map((name) => normalizeName(name)).filter((name) => name !== ""));
|
|
426
|
+
// 4. The member's contacts file: joins by key, and names an identity Slack left nameless.
|
|
427
|
+
const contactsDir = options.meshContactsDir === undefined ? path.join(os.homedir(), ".hq", "work-mesh", "cache", "contacts") : options.meshContactsDir;
|
|
428
|
+
if (contactsDir && member) {
|
|
429
|
+
const file = record(loadJson(path.join(contactsDir, `${member.personUid}.json`)));
|
|
430
|
+
for (const entry of list(file.contacts)) {
|
|
431
|
+
const contact = record(entry);
|
|
432
|
+
const uid = text(contact.personUid);
|
|
433
|
+
const email = normalizeEmail(text(contact.email));
|
|
434
|
+
const displayName = text(contact.displayName);
|
|
435
|
+
if (!/^prs_[0-9A-Za-z]+$/.test(uid)) {
|
|
436
|
+
counts.meshAgentsSkipped += 1;
|
|
437
|
+
// An agent's address is remembered so its commits are not taken for a person's.
|
|
438
|
+
if (isEmail(email))
|
|
439
|
+
agentEmails.add(email);
|
|
440
|
+
if (displayName !== "")
|
|
441
|
+
machineNames.add(normalizeName(displayName));
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
counts.meshContacts += 1;
|
|
445
|
+
const keys = [`ext:hq:${uid}`, ...(isEmail(email) ? [`email:${email}`] : [])];
|
|
446
|
+
const person = find(keys);
|
|
447
|
+
if (person) {
|
|
448
|
+
attach(person, { ...(isEmail(email) ? { emails: [email] } : {}), externalIds: [`hq:${uid}`], ...(displayName ? { alias: displayName } : {}), from: "mesh-contacts" });
|
|
449
|
+
counts.meshContactsMatched += 1;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
const pending = [...nameless].find(([, identity]) => identity.externalIds.includes(`hq:${uid}`) || (isEmail(email) && identity.emails.includes(email)));
|
|
453
|
+
if (pending && displayName !== "" && !slackIdOf(displayName)) {
|
|
454
|
+
const [slackId, identity] = pending;
|
|
455
|
+
nameless.delete(slackId);
|
|
456
|
+
addPerson({
|
|
457
|
+
name: displayName,
|
|
458
|
+
aliases: [],
|
|
459
|
+
emails: sortedUnique([...identity.emails, ...(isEmail(email) ? [email] : [])]),
|
|
460
|
+
slackIds: identity.slackIds,
|
|
461
|
+
externalIds: sortedUnique([...identity.externalIds, `hq:${uid}`]),
|
|
462
|
+
teams: [],
|
|
463
|
+
seen: options.learned,
|
|
464
|
+
src: `record:hq:${uid}`,
|
|
465
|
+
by: "record",
|
|
466
|
+
conf: 0.8,
|
|
467
|
+
from: ["slack", "mesh-contacts"],
|
|
468
|
+
});
|
|
469
|
+
counts.meshContactsMatched += 1;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
// A contact with no tie to this company's own sources may belong to another company: left out.
|
|
473
|
+
counts.meshContactsUnmatched += 1;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
counts.namelessIdentities = nameless.size;
|
|
477
|
+
// The company's own mail domains: named in company.yaml, or shared by two people the roster calls internal.
|
|
478
|
+
const domainOf = (email) => email.slice(email.lastIndexOf("@") + 1);
|
|
479
|
+
const ownDomains = new Set();
|
|
480
|
+
for (const value of [companyYaml?.domain, companyYaml?.email_domain, companyYaml?.website, ...list(companyYaml?.domains)]) {
|
|
481
|
+
const domain = normalizeDomain(text(value));
|
|
482
|
+
if (domain !== "" && !SHARED_MAIL_DOMAINS.has(domain))
|
|
483
|
+
ownDomains.add(domain);
|
|
484
|
+
}
|
|
485
|
+
const rosterDomains = new Map();
|
|
486
|
+
for (const person of people) {
|
|
487
|
+
if (!person.internal || !person.from.includes("people"))
|
|
488
|
+
continue;
|
|
489
|
+
for (const domain of sortedUnique(person.emails.map(domainOf)))
|
|
490
|
+
rosterDomains.set(domain, (rosterDomains.get(domain) ?? 0) + 1);
|
|
491
|
+
}
|
|
492
|
+
for (const [domain, count] of rosterDomains)
|
|
493
|
+
if (count >= 2 && !SHARED_MAIL_DOMAINS.has(domain))
|
|
494
|
+
ownDomains.add(domain);
|
|
495
|
+
// 4b. The org chart people keep in HQ: its human members join by person uid or email.
|
|
496
|
+
const orgLayer = options.orgLayer === undefined ? parseOrgLayer(readOrgLayerCache(context.graphRoot)) : options.orgLayer;
|
|
497
|
+
counts.orgLayerMembers = 0;
|
|
498
|
+
counts.orgLayerAgentsSkipped = 0;
|
|
499
|
+
counts.orgLayerMembersAdded = 0;
|
|
500
|
+
counts.orgLayerAccountsMerged = 0;
|
|
501
|
+
counts.orgLayerMachinesSkipped = 0;
|
|
502
|
+
counts.orgLayerUnnamed = 0;
|
|
503
|
+
for (const entry of orgLayer?.members ?? []) {
|
|
504
|
+
if (entry.kind !== "human" || !entry.uid.startsWith("prs_")) {
|
|
505
|
+
counts.orgLayerAgentsSkipped += 1;
|
|
506
|
+
if (entry.email !== "")
|
|
507
|
+
agentEmails.add(entry.email);
|
|
508
|
+
if (entry.name !== "")
|
|
509
|
+
machineNames.add(normalizeName(entry.name));
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
counts.orgLayerMembers += 1;
|
|
513
|
+
const src = `record:hq-org-layer:${entry.uid}`;
|
|
514
|
+
let person = find([`ext:hq:${entry.uid}`, ...(entry.email !== "" ? [`email:${entry.email}`] : [])]);
|
|
515
|
+
// A member account listed as human whose name or address marks a machine is not a person.
|
|
516
|
+
if (!person && (isMachineName(entry.name) || (entry.email !== "" && isMachineEmail(entry.email)))) {
|
|
517
|
+
counts.orgLayerMachinesSkipped += 1;
|
|
518
|
+
if (entry.name !== "")
|
|
519
|
+
machineNames.add(normalizeName(entry.name));
|
|
520
|
+
if (entry.email !== "")
|
|
521
|
+
agentEmails.add(entry.email);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const sameName = entry.name !== "" && nameTokens(normalizeName(entry.name)).length >= 2 ? (byName.get(normalizeName(entry.name)) ?? []).filter((held) => held.roster) : [];
|
|
525
|
+
if (!person && sameName.length === 1) {
|
|
526
|
+
// A second member account of a person the roster already holds (a personal and a work address): one person.
|
|
527
|
+
person = sameName[0];
|
|
528
|
+
counts.orgLayerAccountsMerged += 1;
|
|
529
|
+
}
|
|
530
|
+
if (person) {
|
|
531
|
+
// The member list knows the full name where another source knew one word of it: the full name is the person's name.
|
|
532
|
+
if (nameTokens(normalizeName(person.name)).length < 2 && nameTokens(normalizeName(entry.name)).length >= 2 && !slackIdOf(entry.name)) {
|
|
533
|
+
const short = person.name;
|
|
534
|
+
byName.set(normalizeName(short), (byName.get(normalizeName(short)) ?? []).filter((held) => held !== person));
|
|
535
|
+
person.name = entry.name;
|
|
536
|
+
person.aliases = sortedUnique([...person.aliases.filter((alias) => normalizeName(alias) !== normalizeName(entry.name)), short]);
|
|
537
|
+
byName.set(normalizeName(entry.name), [...(byName.get(normalizeName(entry.name)) ?? []), person]);
|
|
538
|
+
}
|
|
539
|
+
attach(person, { ...(entry.email !== "" ? { emails: [entry.email] } : {}), externalIds: [`hq:${entry.uid}`], ...(entry.name !== "" ? { alias: entry.name } : {}), from: "org-layer" });
|
|
540
|
+
}
|
|
541
|
+
else if (entry.name !== "" && nameTokens(normalizeName(entry.name)).length >= 2 && !slackIdOf(entry.name) && (byName.get(normalizeName(entry.name)) ?? []).length === 0) {
|
|
542
|
+
person = addPerson({
|
|
543
|
+
name: entry.name,
|
|
544
|
+
aliases: [],
|
|
545
|
+
emails: entry.email !== "" ? [entry.email] : [],
|
|
546
|
+
slackIds: [],
|
|
547
|
+
externalIds: [`hq:${entry.uid}`],
|
|
548
|
+
teams: [],
|
|
549
|
+
seen: options.learned,
|
|
550
|
+
src,
|
|
551
|
+
by: "record",
|
|
552
|
+
conf: 0.85,
|
|
553
|
+
from: ["org-layer"],
|
|
554
|
+
});
|
|
555
|
+
counts.orgLayerMembersAdded += 1;
|
|
556
|
+
}
|
|
557
|
+
else if (entry.name !== "" && entry.email !== "") {
|
|
558
|
+
sameNameOtherEmail.push({ name: entry.name, email: entry.email, src });
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
counts.orgLayerUnnamed += 1;
|
|
562
|
+
}
|
|
563
|
+
if (!person)
|
|
564
|
+
continue;
|
|
565
|
+
person.workspaceRole = person.workspaceRole ?? entry.membershipRole;
|
|
566
|
+
person.personUids = sortedUnique([...(person.personUids ?? []), entry.uid]);
|
|
567
|
+
// The working members of the company's own workspace are the roster: the record of who is inside.
|
|
568
|
+
// A guest is somebody the company let in, not one of its own.
|
|
569
|
+
if (!["owner", "admin", "member"].includes(entry.membershipRole))
|
|
570
|
+
continue;
|
|
571
|
+
person.roster = true;
|
|
572
|
+
if (!person.internal) {
|
|
573
|
+
person.internal = true;
|
|
574
|
+
person.internalBy = { by: "record", conf: 0.9, src };
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
// A roster person who shares a name with an agent stays a person; the name is not a machine's.
|
|
578
|
+
for (const person of people)
|
|
579
|
+
if (person.roster)
|
|
580
|
+
machineNames.delete(normalizeName(person.name));
|
|
581
|
+
// An agent called by two letters (`JB`) shares them with people's initials: too short to mark anything.
|
|
582
|
+
for (const name of [...machineNames])
|
|
583
|
+
if (name.replace(/ /g, "").length < 3)
|
|
584
|
+
machineNames.delete(name);
|
|
585
|
+
counts.rosterPeople = people.filter((person) => person.roster).length;
|
|
586
|
+
const machineCheck = { knownNames: machineNames };
|
|
587
|
+
// 5. Git authors of the company's repos.
|
|
588
|
+
const repos = [];
|
|
589
|
+
const gitLog = options.gitLog ?? defaultGitLog;
|
|
590
|
+
const manifest = options.repos ? null : manifestRepos(context);
|
|
591
|
+
const otherCompanies = new Set(manifest?.otherCompanies ?? []);
|
|
592
|
+
const repoPaths = options.repos ?? discoverCompanyRepos(context.hqRoot, manifest.listed).filter((repo) => !otherCompanies.has(repo));
|
|
593
|
+
counts.gitReposListed = manifest?.listed.length ?? repoPaths.length;
|
|
594
|
+
for (const repo of repoPaths) {
|
|
595
|
+
let lines;
|
|
596
|
+
try {
|
|
597
|
+
lines = gitLog(repo);
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
counts.gitReposFailed += 1;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
counts.gitRepos += 1;
|
|
604
|
+
const authors = new Map();
|
|
605
|
+
for (const line of lines) {
|
|
606
|
+
const email = normalizeEmail(line.email);
|
|
607
|
+
let author = authors.get(email);
|
|
608
|
+
if (!author)
|
|
609
|
+
authors.set(email, (author = { names: new Map(), commits: 0, firstDay: line.day, lastDay: line.day }));
|
|
610
|
+
author.names.set(line.name, (author.names.get(line.name) ?? 0) + 1);
|
|
611
|
+
author.commits += 1;
|
|
612
|
+
if (line.day < author.firstDay)
|
|
613
|
+
author.firstDay = line.day;
|
|
614
|
+
if (line.day > author.lastDay)
|
|
615
|
+
author.lastDay = line.day;
|
|
616
|
+
}
|
|
617
|
+
const seedRepo = { name: repoNameOf(repo), authors: [] };
|
|
618
|
+
const newest = lines.map((line) => line.day).sort().pop();
|
|
619
|
+
if (newest)
|
|
620
|
+
seedRepo.lastDay = newest;
|
|
621
|
+
for (const email of sortedUnique(authors.keys())) {
|
|
622
|
+
const author = authors.get(email);
|
|
623
|
+
const name = [...author.names].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))[0][0];
|
|
624
|
+
if (isBotAuthor(name, email, machineCheck) || agentEmails.has(email)) {
|
|
625
|
+
counts.gitBotsSkipped += 1;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
counts.gitAuthors += 1;
|
|
629
|
+
seedRepo.authors.push({ name, email, commits: author.commits, firstDay: author.firstDay, lastDay: author.lastDay });
|
|
630
|
+
const login = githubLoginFromEmail(email);
|
|
631
|
+
const keys = [...(login ? [`ext:github:${login}`] : []), ...(isEmail(email) && !login ? [`email:${email}`] : [])];
|
|
632
|
+
const person = find(keys);
|
|
633
|
+
if (person) {
|
|
634
|
+
attach(person, { ...(login ? { externalIds: [`github:${login}`] } : { emails: [email] }), alias: name, from: "git" });
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
const norm = normalizeName(name);
|
|
638
|
+
if (nameTokens(norm).length < 2 || slackIdOf(name))
|
|
639
|
+
continue;
|
|
640
|
+
const named = byName.get(norm) ?? [];
|
|
641
|
+
if (named.length > 0) {
|
|
642
|
+
// Same full name as a person we have. A noreply address carries no second email, so the login joins;
|
|
643
|
+
// a real second email is never merged on the name.
|
|
644
|
+
if (login && named.length === 1)
|
|
645
|
+
attach(named[0], { externalIds: [`github:${login}`], from: "git" });
|
|
646
|
+
else {
|
|
647
|
+
counts.gitAuthorsSameNameOtherEmail += 1;
|
|
648
|
+
sameNameOtherEmail.push({ name, email, src: `record:git:${seedRepo.name}` });
|
|
649
|
+
}
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
addPerson({
|
|
653
|
+
name,
|
|
654
|
+
aliases: [],
|
|
655
|
+
emails: login ? [] : [email],
|
|
656
|
+
slackIds: [],
|
|
657
|
+
externalIds: login ? [`github:${login}`] : [],
|
|
658
|
+
teams: [],
|
|
659
|
+
seen: author.firstDay,
|
|
660
|
+
src: `record:git:${seedRepo.name}`,
|
|
661
|
+
by: "record",
|
|
662
|
+
conf: 0.7,
|
|
663
|
+
from: ["git"],
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
repos.push(seedRepo);
|
|
667
|
+
}
|
|
668
|
+
// 6. Board: project owners.
|
|
669
|
+
const boardProjects = [];
|
|
670
|
+
const board = record(loadJson(path.join(companyRoot, "board.json")));
|
|
671
|
+
for (const entry of list(board.projects)) {
|
|
672
|
+
const project = record(entry);
|
|
673
|
+
const title = text(project.title);
|
|
674
|
+
const id = text(project.id);
|
|
675
|
+
const created = dayOf(project.created_at);
|
|
676
|
+
if (title === "" || id === "" || !created)
|
|
677
|
+
continue;
|
|
678
|
+
const folder = /(?:^|\/)projects\/([^/]+)\/prd\.json$/.exec(text(project.prd_path))?.[1] ?? "";
|
|
679
|
+
boardProjects.push({ id, name: folder || title, title, status: text(project.status), owner: text(project.owner), created });
|
|
680
|
+
}
|
|
681
|
+
counts.boardProjects = boardProjects.length;
|
|
682
|
+
// 7. CRM accounts.
|
|
683
|
+
const accounts = [];
|
|
684
|
+
const crm = record(loadJson(path.join(companyRoot, "crm-projection.json")));
|
|
685
|
+
const synced = dayOf(crm.synced_at) ?? options.learned;
|
|
686
|
+
for (const entry of list(crm.accounts)) {
|
|
687
|
+
const account = record(entry);
|
|
688
|
+
const name = text(account.name);
|
|
689
|
+
const id = text(account.id);
|
|
690
|
+
if (id === "")
|
|
691
|
+
continue;
|
|
692
|
+
const externalIds = Object.entries(record(account.external_ids))
|
|
693
|
+
.map(([system, value]) => `${system.toLowerCase()}:${text(value)}`)
|
|
694
|
+
.filter((value) => !value.endsWith(":"));
|
|
695
|
+
if (name === "" || isRecordIdName(name, externalIds)) {
|
|
696
|
+
counts.crmAccountsUnnamed += 1;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
accounts.push({
|
|
700
|
+
id,
|
|
701
|
+
name,
|
|
702
|
+
domain: normalizeDomain(text(account.domain)),
|
|
703
|
+
stage: text(account.stage),
|
|
704
|
+
externalIds: sortedUnique(externalIds),
|
|
705
|
+
day: dayOf(account.lastActivity) ?? synced,
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
counts.crmAccounts = accounts.length;
|
|
709
|
+
// A stage every account shares is a default the projection filled in, not something anyone recorded.
|
|
710
|
+
const stages = new Set(accounts.map((account) => normalizeName(account.stage)));
|
|
711
|
+
counts.crmStageConstant = 0;
|
|
712
|
+
if (accounts.length >= 5 && stages.size === 1 && !stages.has("")) {
|
|
713
|
+
counts.crmStageConstant = accounts.length;
|
|
714
|
+
for (const account of accounts)
|
|
715
|
+
account.stage = "";
|
|
716
|
+
}
|
|
717
|
+
const org = options.orgSources === false ? null : readOrgSources(companyRoot);
|
|
718
|
+
return {
|
|
719
|
+
self,
|
|
720
|
+
people,
|
|
721
|
+
directory: slack.directory,
|
|
722
|
+
channels: slack.channels,
|
|
723
|
+
repos,
|
|
724
|
+
boardProjects,
|
|
725
|
+
accounts,
|
|
726
|
+
sameNameOtherEmail,
|
|
727
|
+
counts,
|
|
728
|
+
ownDomains: sortedUnique(ownDomains),
|
|
729
|
+
orgLayer,
|
|
730
|
+
org,
|
|
731
|
+
machineNames: sortedUnique(machineNames),
|
|
732
|
+
settings,
|
|
733
|
+
confirmedOrgChart: readConfirmedOrgChart(companyRoot),
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
const CUSTOMER_STAGES = new Set(["customer", "client", "won", "closed won", "active", "paying", "subscribed", "signed"]);
|
|
737
|
+
/** Systems whose id on an account is a billing record, not a pipeline record. */
|
|
738
|
+
const BILLING_SYSTEMS = new Set(["stripe", "chargebee", "recurly", "paddle", "quickbooks", "xero"]);
|
|
739
|
+
export function applyIdentitySeed(seed, writer, options) {
|
|
740
|
+
const index = writer.index;
|
|
741
|
+
index.setSlackDirectory(seed.directory);
|
|
742
|
+
// The company's own words (its name, its products) and the names of its agents, for the "not a person" rules.
|
|
743
|
+
const ownWords = new Set([seed.self?.name ?? "", seed.self?.slug ?? "", ...(seed.settings?.products ?? [])].flatMap((word) => nameTokens(normalizeName(word))));
|
|
744
|
+
index.setMachineCheck({ knownNames: new Set(seed.machineNames ?? []), ownWords }, Object.values(FUNCTION_TERMS).flat().flatMap((term) => nameTokens(term)));
|
|
745
|
+
const learned = options.learned;
|
|
746
|
+
const minCommits = options.minCommits ?? 3;
|
|
747
|
+
const minThreads = options.minChannelThreads ?? 3;
|
|
748
|
+
const anchors = options.phase !== "links";
|
|
749
|
+
const links = options.phase !== "anchors";
|
|
750
|
+
const inactiveDays = options.inactiveAfterDays ?? 90;
|
|
751
|
+
const minEngineeringCommits = options.minEngineeringCommits ?? 10;
|
|
752
|
+
const result = options.previous ?? {
|
|
753
|
+
counts: seed.counts,
|
|
754
|
+
peopleSeeded: 0,
|
|
755
|
+
peopleMerged: 0,
|
|
756
|
+
peopleRefused: 0,
|
|
757
|
+
roles: 0,
|
|
758
|
+
teams: 0,
|
|
759
|
+
projects: 0,
|
|
760
|
+
companies: 0,
|
|
761
|
+
customerEdges: 0,
|
|
762
|
+
worksOnEdges: 0,
|
|
763
|
+
ownsEdges: 0,
|
|
764
|
+
reportsToEdges: 0,
|
|
765
|
+
memberOfEdges: 0,
|
|
766
|
+
unresolvedOwners: 0,
|
|
767
|
+
org: emptyOrgSeedCounts(),
|
|
768
|
+
proposals: [],
|
|
769
|
+
};
|
|
770
|
+
const audience = "company";
|
|
771
|
+
const seenType = (created, key) => {
|
|
772
|
+
if (created)
|
|
773
|
+
result[key] += 1;
|
|
774
|
+
};
|
|
775
|
+
/** The entity a seeded person became, found again by key or name (the `links` phase runs later). */
|
|
776
|
+
const personRef = (person) => {
|
|
777
|
+
const keyed = index.byKeys({ email: person.emails, slack_id: person.slackIds, external_ids: person.externalIds }, ["person"]);
|
|
778
|
+
return keyed[0] ?? index.findSameName("person", person.name)[0] ?? null;
|
|
779
|
+
};
|
|
780
|
+
// The company itself.
|
|
781
|
+
let selfRef = null;
|
|
782
|
+
if (seed.self && anchors) {
|
|
783
|
+
const src = "doc:company.yaml";
|
|
784
|
+
const made = writer.ensure({ type: "company", name: seed.self.name, aliases: [], slugFallback: seed.self.slug, seen: learned, evidence: src });
|
|
785
|
+
selfRef = made.ref;
|
|
786
|
+
seenType(made.created, "companies");
|
|
787
|
+
if (selfRef)
|
|
788
|
+
writer.addRow(selfRef, audience, factRow("relation", "self", { from: learned, src, learned, by: "record", conf: 0.95 }));
|
|
789
|
+
}
|
|
790
|
+
else if (seed.self) {
|
|
791
|
+
selfRef = index.findSameName("company", seed.self.name)[0] ?? null;
|
|
792
|
+
}
|
|
793
|
+
const state = {
|
|
794
|
+
writer,
|
|
795
|
+
index,
|
|
796
|
+
learned,
|
|
797
|
+
now: options.now ?? `${learned}T00:00:00.000Z`,
|
|
798
|
+
selfRef,
|
|
799
|
+
selfName: seed.self?.name ?? "",
|
|
800
|
+
ownDomains: new Set(seed.ownDomains ?? []),
|
|
801
|
+
internal: new Set(),
|
|
802
|
+
titled: new Map(),
|
|
803
|
+
teamEvidence: [],
|
|
804
|
+
counts: result.org,
|
|
805
|
+
};
|
|
806
|
+
const teamsBefore = state.counts.teamsAsserted;
|
|
807
|
+
const membersBefore = state.counts.teamMembers;
|
|
808
|
+
/** Sets the roster on the index from the seeded people a record lists as the company's own. */
|
|
809
|
+
const setRoster = () => {
|
|
810
|
+
const members = [];
|
|
811
|
+
for (const person of seed.people) {
|
|
812
|
+
if (!person.roster)
|
|
813
|
+
continue;
|
|
814
|
+
const ref = personRef(person);
|
|
815
|
+
if (!ref || members.some((member) => member.ref === ref))
|
|
816
|
+
continue;
|
|
817
|
+
members.push({ ref, name: person.name, emails: person.emails, slackIds: person.slackIds, personUids: person.personUids ?? [], from: person.from });
|
|
818
|
+
}
|
|
819
|
+
result.roster = members;
|
|
820
|
+
state.rosterAuthoritative = members.length > 0;
|
|
821
|
+
index.setRoster(members.length > 0 ? new Roster(members, ownWords) : null);
|
|
822
|
+
};
|
|
823
|
+
if (!anchors)
|
|
824
|
+
setRoster();
|
|
825
|
+
// People, with role, team and employer. Roster people first, so every other name is weighed against them.
|
|
826
|
+
const seedPeople = anchors ? [...seed.people.filter((person) => person.roster), ...seed.people.filter((person) => !person.roster)] : [];
|
|
827
|
+
let rosterSet = false;
|
|
828
|
+
for (const person of seedPeople) {
|
|
829
|
+
if (!person.roster && !rosterSet) {
|
|
830
|
+
setRoster();
|
|
831
|
+
rosterSet = true;
|
|
832
|
+
}
|
|
833
|
+
const made = writer.ensure({
|
|
834
|
+
type: "person",
|
|
835
|
+
name: person.name,
|
|
836
|
+
aliases: person.aliases,
|
|
837
|
+
keys: { email: person.emails, slack_id: person.slackIds, external_ids: person.externalIds },
|
|
838
|
+
seen: person.seen,
|
|
839
|
+
evidence: person.src,
|
|
840
|
+
});
|
|
841
|
+
if (!made.ref) {
|
|
842
|
+
result.peopleRefused += 1;
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (made.created)
|
|
846
|
+
result.peopleSeeded += 1;
|
|
847
|
+
else
|
|
848
|
+
result.peopleMerged += 1;
|
|
849
|
+
const stamp = { from: person.seen, src: person.src, learned, by: person.by, conf: person.conf };
|
|
850
|
+
for (const email of person.emails)
|
|
851
|
+
writer.addRow(made.ref, audience, factRow("email", email, stamp));
|
|
852
|
+
for (const slackId of person.slackIds)
|
|
853
|
+
writer.addRow(made.ref, audience, factRow("slack_id", slackId, stamp));
|
|
854
|
+
if (person.role) {
|
|
855
|
+
writer.addRow(made.ref, audience, factRow("role_title", person.role, stamp));
|
|
856
|
+
const role = writer.ensure({ type: "role", name: person.role, seen: person.seen, evidence: person.src });
|
|
857
|
+
seenType(role.created, "roles");
|
|
858
|
+
if (role.ref) {
|
|
859
|
+
if (role.created)
|
|
860
|
+
writer.addRow(role.ref, audience, factRow("title", person.role, stamp));
|
|
861
|
+
writer.addRow(made.ref, audience, edgeRow("holds_role", role.ref, stamp));
|
|
862
|
+
}
|
|
863
|
+
state.titled.set(made.ref, { title: person.role, conf: person.conf, src: person.src, day: person.seen });
|
|
864
|
+
}
|
|
865
|
+
if (person.internal && selfRef) {
|
|
866
|
+
// The people file says so, or a rule does (a working member of the workspace on the company's own mail domain).
|
|
867
|
+
const inside = person.internalBy ? { ...stamp, from: learned, ...person.internalBy } : stamp;
|
|
868
|
+
state.internal.add(made.ref);
|
|
869
|
+
if (!person.internalBy)
|
|
870
|
+
writer.addRow(made.ref, audience, factRow("status", "active", stamp));
|
|
871
|
+
writer.claimEdge(made.ref, "works_at", selfRef);
|
|
872
|
+
writer.addRow(made.ref, audience, edgeRow("works_at", selfRef, inside));
|
|
873
|
+
if (seed.self)
|
|
874
|
+
writer.addRow(made.ref, audience, factRow("affiliation", seed.self.name, inside));
|
|
875
|
+
}
|
|
876
|
+
else if (person.organization) {
|
|
877
|
+
const employer = writer.ensure({ type: "company", name: person.organization, seen: person.seen, evidence: person.src });
|
|
878
|
+
seenType(employer.created, "companies");
|
|
879
|
+
if (employer.ref) {
|
|
880
|
+
writer.claimEdge(made.ref, "works_at", employer.ref);
|
|
881
|
+
writer.addRow(made.ref, audience, edgeRow("works_at", employer.ref, stamp));
|
|
882
|
+
writer.addRow(made.ref, audience, factRow("affiliation", person.organization, stamp));
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (anchors && !rosterSet)
|
|
887
|
+
setRoster();
|
|
888
|
+
// The same full name with a different email and no shared key: a proposal, never a merge.
|
|
889
|
+
for (const entry of anchors ? seed.sameNameOtherEmail : []) {
|
|
890
|
+
const same = index.findSameName("person", entry.name);
|
|
891
|
+
if (same.length === 0)
|
|
892
|
+
continue;
|
|
893
|
+
// There is no second entity to point at, so this is a note for a person to decide, with no action.
|
|
894
|
+
const proposal = {
|
|
895
|
+
id: proposalId("merge-note", same[0], [normalizeName(entry.name), entry.email]),
|
|
896
|
+
kind: "merge",
|
|
897
|
+
entity: same[0],
|
|
898
|
+
rows: [],
|
|
899
|
+
summary: `"${entry.name}" appears with another email (${entry.email}) and no shared identity key. Not attached to ${same[0]}.`,
|
|
900
|
+
action: { type: "none" },
|
|
901
|
+
evidence: [entry.src],
|
|
902
|
+
filedAt: options.now ?? `${learned}T00:00:00.000Z`,
|
|
903
|
+
};
|
|
904
|
+
if (!writer.proposals.has(proposal.id)) {
|
|
905
|
+
writer.proposals.set(proposal.id, proposal);
|
|
906
|
+
writer.counts.proposals += 1;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
// Customers and prospects from the clients folder. Account owners follow with the links.
|
|
910
|
+
if (seed.org && anchors)
|
|
911
|
+
result.companies += applyClients(state, seed.org.clients, { anchors: true, links: false });
|
|
912
|
+
if (seed.org && anchors)
|
|
913
|
+
result.projects += applyPrdOwners(state, seed.org, { anchors: true, links: false });
|
|
914
|
+
// Projects from repos. Who commits to them follows with the links, so an author found by a key
|
|
915
|
+
// another input holds (an old entity file's email) is found the same way on every run.
|
|
916
|
+
const repoProjects = [];
|
|
917
|
+
for (const repo of seed.repos) {
|
|
918
|
+
const src = `record:git:${repo.name}`;
|
|
919
|
+
const firstDay = repo.authors.map((author) => author.firstDay).sort()[0] ?? learned;
|
|
920
|
+
let projectRef;
|
|
921
|
+
if (anchors) {
|
|
922
|
+
// A repo's remote name and the name the board uses are one project: `hq-desktop-app-src` is the
|
|
923
|
+
// source tree of `hq-desktop-app`, and the remote name is kept as an alias so commits land there.
|
|
924
|
+
const projectName = repoProjectName(repo.name);
|
|
925
|
+
const project = writer.ensure({ type: "project", name: projectName, ...(projectName !== repo.name ? { aliases: [repo.name] } : {}), seen: firstDay, evidence: src });
|
|
926
|
+
seenType(project.created, "projects");
|
|
927
|
+
projectRef = project.ref;
|
|
928
|
+
if (projectRef) {
|
|
929
|
+
writer.addRow(projectRef, audience, factRow("repo", repo.name, { from: firstDay, src, learned, by: "record", conf: 0.9 }));
|
|
930
|
+
if (selfRef)
|
|
931
|
+
writer.addRow(projectRef, audience, edgeRow("part_of", selfRef, { from: firstDay, src, learned, by: "rule:company-repo", conf: 0.8 }));
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
projectRef = index.findSameName("project", repoProjectName(repo.name))[0] ?? index.findSameName("project", repo.name)[0] ?? null;
|
|
936
|
+
}
|
|
937
|
+
if (projectRef)
|
|
938
|
+
repoProjects.push({ repo, project: projectRef, src });
|
|
939
|
+
}
|
|
940
|
+
// Board projects and their owners.
|
|
941
|
+
const boardOwners = [];
|
|
942
|
+
for (const item of seed.boardProjects) {
|
|
943
|
+
const src = "doc:board.json";
|
|
944
|
+
const stamp = { from: item.created, src, learned, by: "record", conf: 0.8 };
|
|
945
|
+
let projectRef;
|
|
946
|
+
if (anchors) {
|
|
947
|
+
const made = writer.ensure({ type: "project", name: item.name, aliases: item.title !== item.name ? [item.title] : [], seen: item.created, evidence: src });
|
|
948
|
+
seenType(made.created, "projects");
|
|
949
|
+
projectRef = made.ref;
|
|
950
|
+
if (projectRef && item.status !== "")
|
|
951
|
+
writer.addRow(projectRef, audience, factRow("status", item.status, stamp));
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
projectRef = index.findSameName("project", item.name)[0] ?? null;
|
|
955
|
+
}
|
|
956
|
+
if (projectRef && item.owner !== "")
|
|
957
|
+
boardOwners.push({ project: projectRef, owner: item.owner, stamp });
|
|
958
|
+
}
|
|
959
|
+
// CRM accounts never make a company. A CRM row alone says a record exists, not that anyone dealt with the
|
|
960
|
+
// company. An account's ids, domain and stage are attached to a company another source names (a client
|
|
961
|
+
// folder, an old entity file with a relationship, a people file); the rest stay out of the graph. This runs
|
|
962
|
+
// with the links, after every other source has had its say.
|
|
963
|
+
seed.counts.crmAccountsHeld = links ? 0 : (seed.counts.crmAccountsHeld ?? 0);
|
|
964
|
+
seed.counts.crmAccountsAttached = links ? 0 : (seed.counts.crmAccountsAttached ?? 0);
|
|
965
|
+
for (const account of links ? seed.accounts : []) {
|
|
966
|
+
const system = account.externalIds[0]?.split(":")[0] ?? "crm";
|
|
967
|
+
const recordId = account.externalIds[0]?.slice(system.length + 1) ?? account.id.slice(0, 12);
|
|
968
|
+
const src = `record:${system}:${recordId}`;
|
|
969
|
+
const domains = account.domain !== "" && !SHARED_MAIL_DOMAINS.has(account.domain) ? [account.domain] : [];
|
|
970
|
+
const keyed = index.byKeys({ external_ids: account.externalIds, web_domains: domains }, ["company"]);
|
|
971
|
+
const named = keyed.length > 0 ? keyed : index.findSameName("company", account.name).filter((ref) => !index.recordsConflict(ref, { external_ids: account.externalIds, web_domains: domains }));
|
|
972
|
+
if (named.length !== 1) {
|
|
973
|
+
seed.counts.crmAccountsHeld += 1;
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
const company = { ref: named[0] };
|
|
977
|
+
writer.enrich(named[0], { keys: { external_ids: account.externalIds, web_domains: domains }, seen: account.day });
|
|
978
|
+
seed.counts.crmAccountsAttached += 1;
|
|
979
|
+
if (!company.ref || company.ref === selfRef)
|
|
980
|
+
continue;
|
|
981
|
+
const stamp = { from: account.day, src, learned, by: "record", conf: 0.9 };
|
|
982
|
+
if (account.stage !== "")
|
|
983
|
+
writer.addRow(company.ref, audience, factRow("stage", account.stage, stamp));
|
|
984
|
+
for (const domain of domains)
|
|
985
|
+
writer.addRow(company.ref, audience, factRow("web_domain", domain, stamp));
|
|
986
|
+
if (!selfRef)
|
|
987
|
+
continue;
|
|
988
|
+
const billing = account.externalIds.find((id) => BILLING_SYSTEMS.has(id.split(":")[0]));
|
|
989
|
+
const staged = CUSTOMER_STAGES.has(normalizeName(account.stage));
|
|
990
|
+
if (!staged) {
|
|
991
|
+
// A billing customer id says the account once reached checkout. It does not say the account pays: no customer edge.
|
|
992
|
+
if (billing && !writer.hasFact(company.ref, "relation", "customer")) {
|
|
993
|
+
writer.addRow(company.ref, audience, factRow("relation", "billing-account", { from: account.day, src: `record:${billing}`, learned, by: "rule:crm-billing-account", conf: 0.5 }));
|
|
994
|
+
}
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
if (!writer.claimEdge(company.ref, "customer_of", selfRef))
|
|
998
|
+
continue;
|
|
999
|
+
const customerStamp = { ...stamp, by: "rule:crm-stage", conf: 0.8 };
|
|
1000
|
+
if (writer.addRow(company.ref, audience, edgeRow("customer_of", selfRef, customerStamp))) {
|
|
1001
|
+
result.customerEdges += 1;
|
|
1002
|
+
writer.addRow(company.ref, audience, factRow("relation", "customer", customerStamp));
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
// Everything that rests on resolving a name runs last, against every entity, in one fixed order.
|
|
1006
|
+
if (links) {
|
|
1007
|
+
// What the seed already knows: who is inside the company, and whose title a people file states.
|
|
1008
|
+
for (const person of seed.people) {
|
|
1009
|
+
const ref = personRef(person);
|
|
1010
|
+
if (!ref)
|
|
1011
|
+
continue;
|
|
1012
|
+
if (person.internal)
|
|
1013
|
+
state.internal.add(ref);
|
|
1014
|
+
if (person.role && !state.titled.has(ref))
|
|
1015
|
+
state.titled.set(ref, { title: person.role, conf: person.conf, src: person.src, day: person.seen });
|
|
1016
|
+
}
|
|
1017
|
+
// Reporting lines: a people file first, then the org chart people keep in HQ.
|
|
1018
|
+
for (const person of seed.people) {
|
|
1019
|
+
if (!person.manager)
|
|
1020
|
+
continue;
|
|
1021
|
+
const ref = personRef(person);
|
|
1022
|
+
if (!ref)
|
|
1023
|
+
continue;
|
|
1024
|
+
const manager = resolvePersonName(state, person.manager);
|
|
1025
|
+
if (!manager.ref || manager.ref === ref) {
|
|
1026
|
+
result.unresolvedOwners += 1;
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
const stamp = { from: person.seen, src: person.src, learned, by: person.by, conf: person.conf };
|
|
1030
|
+
if (writer.claimEdge(ref, "reports_to", manager.ref) && writer.addRow(ref, audience, edgeRow("reports_to", manager.ref, stamp)))
|
|
1031
|
+
result.reportsToEdges += 1;
|
|
1032
|
+
}
|
|
1033
|
+
applyOrgLayerLinks(state, seed.orgLayer ?? null);
|
|
1034
|
+
// The org chart a person confirmed: their own statement, above every other source, written again on every run.
|
|
1035
|
+
const confirmed = seed.confirmedOrgChart ?? null;
|
|
1036
|
+
if (confirmed) {
|
|
1037
|
+
const by = `human:${confirmed.confirmedBy}`;
|
|
1038
|
+
const stamp = { from: confirmed.confirmedOn, src: `doc:${ORG_CHART_FILE}`, learned, by, conf: 1 };
|
|
1039
|
+
const counts = { roles: 0, teams: 0, managers: 0, unresolved: [] };
|
|
1040
|
+
for (const row of confirmed.people) {
|
|
1041
|
+
const person = resolvePersonName(state, row.name).ref;
|
|
1042
|
+
if (!person) {
|
|
1043
|
+
counts.unresolved.push(row.name);
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
if (row.role !== "" && writer.addRow(person, audience, factRow("role_title", row.role, stamp))) {
|
|
1047
|
+
counts.roles += 1;
|
|
1048
|
+
state.titled.set(person, { title: row.role, conf: 1, src: stamp.src, day: stamp.from });
|
|
1049
|
+
}
|
|
1050
|
+
if (row.team !== "") {
|
|
1051
|
+
const team = writer.ensure({ type: "team", name: row.team, seen: stamp.from, evidence: stamp.src });
|
|
1052
|
+
seenType(team.created, "teams");
|
|
1053
|
+
if (team.ref && writer.claimEdge(person, "member_of", team.ref) && writer.addRow(person, audience, edgeRow("member_of", team.ref, stamp)))
|
|
1054
|
+
counts.teams += 1;
|
|
1055
|
+
if (team.ref && selfRef && writer.claimEdge(team.ref, "part_of", selfRef))
|
|
1056
|
+
writer.addRow(team.ref, audience, edgeRow("part_of", selfRef, stamp));
|
|
1057
|
+
}
|
|
1058
|
+
if (row.manager !== "") {
|
|
1059
|
+
const manager = resolvePersonName(state, row.manager).ref;
|
|
1060
|
+
if (!manager || manager === person)
|
|
1061
|
+
counts.unresolved.push(`${row.name}: manager ${row.manager}`);
|
|
1062
|
+
else if (writer.claimEdge(person, "reports_to", manager) && writer.addRow(person, audience, edgeRow("reports_to", manager, stamp)))
|
|
1063
|
+
counts.managers += 1;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
result.confirmedOrgChart = counts;
|
|
1067
|
+
}
|
|
1068
|
+
// Who commits to which repo: first and last commit day are the validity, the commit count is a timeline row.
|
|
1069
|
+
const lastActive = new Date(Date.parse(`${learned}T00:00:00Z`) - inactiveDays * 86_400_000).toISOString().slice(0, 10);
|
|
1070
|
+
for (const { repo, project, src } of repoProjects) {
|
|
1071
|
+
for (const author of repo.authors) {
|
|
1072
|
+
if (author.commits < minCommits)
|
|
1073
|
+
continue;
|
|
1074
|
+
const login = githubLoginFromEmail(author.email);
|
|
1075
|
+
const person = index.resolve({
|
|
1076
|
+
text: author.name,
|
|
1077
|
+
types: ["person"],
|
|
1078
|
+
keys: login ? { external_ids: [`github:${login}`] } : { email: [author.email] },
|
|
1079
|
+
});
|
|
1080
|
+
if (person.status !== "resolved" || !person.entity || person.reason !== "identity_key")
|
|
1081
|
+
continue;
|
|
1082
|
+
if (!writer.claimEdge(person.entity, "works_on", project))
|
|
1083
|
+
continue;
|
|
1084
|
+
const stamp = { from: author.firstDay, src, learned, by: "rule:git-author", conf: 0.7 };
|
|
1085
|
+
const edge = edgeRow("works_on", project, stamp);
|
|
1086
|
+
// Someone who committed lately is still on it: the row stays open.
|
|
1087
|
+
if (author.lastDay < lastActive && author.lastDay >= author.firstDay)
|
|
1088
|
+
edge.valid = { from: author.firstDay, to: author.lastDay };
|
|
1089
|
+
if (writer.addRow(person.entity, audience, edge)) {
|
|
1090
|
+
result.worksOnEdges += 1;
|
|
1091
|
+
const span = author.firstDay === author.lastDay ? `on ${author.firstDay}` : `${author.firstDay} to ${author.lastDay}`;
|
|
1092
|
+
writer.addRow(person.entity, audience, { kind: "T", date: author.lastDay, signalType: "commits", text: `${author.commits} commits to ${repo.name}, ${span}`, src });
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
// Who is inside the company and who works elsewhere.
|
|
1097
|
+
applyEmailAffiliation(state);
|
|
1098
|
+
if (seed.org)
|
|
1099
|
+
applyStandupAttendance(state, seed.org);
|
|
1100
|
+
// Role titles nobody put in a people file.
|
|
1101
|
+
if (seed.org)
|
|
1102
|
+
applyRoleStatements(state, seed.org);
|
|
1103
|
+
// Team evidence, one entry per person, team and source.
|
|
1104
|
+
for (const person of seed.people) {
|
|
1105
|
+
if (!person.from.includes("people"))
|
|
1106
|
+
continue;
|
|
1107
|
+
const ref = personRef(person);
|
|
1108
|
+
if (!ref)
|
|
1109
|
+
continue;
|
|
1110
|
+
const source = `roster:${person.src}`;
|
|
1111
|
+
for (const teamName of person.teams) {
|
|
1112
|
+
const functions = functionsOf(teamName);
|
|
1113
|
+
const plainFunction = functions.length === 1 && nameTokens(normalizeName(teamName)).length === 1;
|
|
1114
|
+
const team = plainFunction ? functions[0] : `name:${normalizeName(teamName)}`;
|
|
1115
|
+
state.teamEvidence.push({ person: ref, team, label: plainFunction ? functionLabel(team) : teamName, source, src: person.src, day: person.seen });
|
|
1116
|
+
}
|
|
1117
|
+
for (const fn of sortedUnique([...(person.tags ?? []).flatMap((tag) => functionsOf(tag)), ...functionsOf(person.role ?? "")])) {
|
|
1118
|
+
state.teamEvidence.push({ person: ref, team: fn, label: functionLabel(fn), source, src: person.src, day: person.seen });
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
if (seed.org)
|
|
1122
|
+
collectStandupEvidence(state, seed.org);
|
|
1123
|
+
const channelsSeen = [];
|
|
1124
|
+
for (const channel of seed.channels) {
|
|
1125
|
+
const src = `source:sources/slack/${channel.firstFile}`;
|
|
1126
|
+
const functions = functionsOf(channel.name.replace(/[-_]/g, " "));
|
|
1127
|
+
let frequent = 0;
|
|
1128
|
+
for (const slackId of sortedUnique(Object.keys(channel.participants))) {
|
|
1129
|
+
const seen = channel.participants[slackId];
|
|
1130
|
+
if (seen.threads < minThreads)
|
|
1131
|
+
continue;
|
|
1132
|
+
frequent += 1;
|
|
1133
|
+
const person = index.resolve({ text: slackId, types: ["person"] });
|
|
1134
|
+
if (person.status !== "resolved" || !person.entity)
|
|
1135
|
+
continue;
|
|
1136
|
+
for (const fn of functions)
|
|
1137
|
+
state.teamEvidence.push({ person: person.entity, team: fn, label: functionLabel(fn), source: "channel", src, day: seen.firstDay });
|
|
1138
|
+
}
|
|
1139
|
+
channelsSeen.push({ name: channel.name, src, firstDay: channel.firstDay, frequent });
|
|
1140
|
+
}
|
|
1141
|
+
const commits = new Map();
|
|
1142
|
+
for (const repo of seed.repos) {
|
|
1143
|
+
for (const author of repo.authors) {
|
|
1144
|
+
const login = githubLoginFromEmail(author.email);
|
|
1145
|
+
const person = index.resolve({ text: author.name, types: ["person"], keys: login ? { external_ids: [`github:${login}`] } : { email: [author.email] } });
|
|
1146
|
+
if (person.status !== "resolved" || !person.entity || person.reason !== "identity_key")
|
|
1147
|
+
continue;
|
|
1148
|
+
const held = commits.get(person.entity);
|
|
1149
|
+
if (!held)
|
|
1150
|
+
commits.set(person.entity, { commits: author.commits, firstDay: author.firstDay, repo: repo.name, most: author.commits });
|
|
1151
|
+
else {
|
|
1152
|
+
held.commits += author.commits;
|
|
1153
|
+
if (author.firstDay < held.firstDay)
|
|
1154
|
+
held.firstDay = author.firstDay;
|
|
1155
|
+
if (author.commits > held.most) {
|
|
1156
|
+
held.most = author.commits;
|
|
1157
|
+
held.repo = repo.name;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
for (const ref of sortedUnique(commits.keys())) {
|
|
1163
|
+
const held = commits.get(ref);
|
|
1164
|
+
if (held.commits < minEngineeringCommits)
|
|
1165
|
+
continue;
|
|
1166
|
+
state.teamEvidence.push({ person: ref, team: "engineering", label: functionLabel("engineering"), source: "git", src: `record:git:${held.repo}`, day: held.firstDay });
|
|
1167
|
+
}
|
|
1168
|
+
applyTeams(state, channelsSeen);
|
|
1169
|
+
// Owners: board, PRD, client account.
|
|
1170
|
+
for (const entry of boardOwners) {
|
|
1171
|
+
const owner = resolvePersonName(state, entry.owner);
|
|
1172
|
+
if (!owner.ref) {
|
|
1173
|
+
result.unresolvedOwners += 1;
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
if (owner.how === "first_name")
|
|
1177
|
+
state.counts.firstNamesResolved += 1;
|
|
1178
|
+
if (!writer.claimEdge(entry.project, "owned_by", owner.ref))
|
|
1179
|
+
continue;
|
|
1180
|
+
const stamp = owner.how === "first_name" ? { ...entry.stamp, conf: 0.6 } : entry.stamp;
|
|
1181
|
+
if (writer.addRow(entry.project, audience, edgeRow("owned_by", owner.ref, stamp)))
|
|
1182
|
+
result.ownsEdges += 1;
|
|
1183
|
+
}
|
|
1184
|
+
if (seed.org) {
|
|
1185
|
+
applyPrdOwners(state, seed.org, { anchors: false, links: true });
|
|
1186
|
+
applyClients(state, seed.org.clients, { anchors: false, links: true });
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
result.teams += state.counts.teamsAsserted - teamsBefore;
|
|
1190
|
+
result.memberOfEdges += state.counts.teamMembers - membersBefore;
|
|
1191
|
+
result.proposals = [...writer.proposals.values()];
|
|
1192
|
+
if (links) {
|
|
1193
|
+
result.teamEvidence = [...state.teamEvidence];
|
|
1194
|
+
result.titled = Object.fromEntries([...state.titled].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
1195
|
+
}
|
|
1196
|
+
return result;
|
|
1197
|
+
}
|
|
1198
|
+
//# sourceMappingURL=seed.js.map
|