@indigoai-us/hq-cli 5.345.247 → 5.345.248
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -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 +1113 -0
- package/dist/command-catalog.generated.js +1370 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- 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/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/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/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/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/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,631 @@
|
|
|
1
|
+
import { SHARED_MAIL_DOMAINS, isEmail, nameTokens, normalizeEmail, normalizeName, slackIdOf, sortedUnique } from "./normalize.js";
|
|
2
|
+
import { functionLabel, functionsOf, ledFunction, titleFrom, withoutBrackets } from "./org-sources.js";
|
|
3
|
+
import { edgeRow, factRow, proposalId } from "./writer.js";
|
|
4
|
+
const AUDIENCE = "company";
|
|
5
|
+
const PERSON_UID_RE = /^prs_[0-9A-Za-z]+$/;
|
|
6
|
+
export function emptyOrgSeedCounts() {
|
|
7
|
+
return {
|
|
8
|
+
rolesDerived: 0,
|
|
9
|
+
rolesBySource: {},
|
|
10
|
+
roleStatementsUnresolved: 0,
|
|
11
|
+
signalRolesOneDocument: 0,
|
|
12
|
+
teamsAsserted: 0,
|
|
13
|
+
teamsProposed: 0,
|
|
14
|
+
teamMembers: 0,
|
|
15
|
+
teamMembersProposed: 0,
|
|
16
|
+
teamLeads: 0,
|
|
17
|
+
teamLeadsProposed: 0,
|
|
18
|
+
channelsNotATeam: 0,
|
|
19
|
+
orgLayerEdges: 0,
|
|
20
|
+
orgLayerHumanEdges: 0,
|
|
21
|
+
orgLayerAgentEdges: 0,
|
|
22
|
+
orgLayerUnresolved: 0,
|
|
23
|
+
orgLayerSpeaksFor: 0,
|
|
24
|
+
orgLayerSuggestions: 0,
|
|
25
|
+
prdOwners: 0,
|
|
26
|
+
prdOwnersUnresolved: 0,
|
|
27
|
+
clients: 0,
|
|
28
|
+
clientsWithStage: 0,
|
|
29
|
+
clientCustomers: 0,
|
|
30
|
+
clientOwners: 0,
|
|
31
|
+
clientOwnersUnresolved: 0,
|
|
32
|
+
clientContacts: 0,
|
|
33
|
+
internalByDomain: 0,
|
|
34
|
+
ownDomainNotOnRoster: 0,
|
|
35
|
+
internalByAttendance: 0,
|
|
36
|
+
externalByDomain: 0,
|
|
37
|
+
standupAttendees: 0,
|
|
38
|
+
firstNamesResolved: 0,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function bump(record, key) {
|
|
42
|
+
record[key] = (record[key] ?? 0) + 1;
|
|
43
|
+
}
|
|
44
|
+
function fileProposal(state, proposal, kindLabel) {
|
|
45
|
+
if (state.writer.proposals.has(proposal.id))
|
|
46
|
+
return;
|
|
47
|
+
state.writer.proposals.set(proposal.id, { ...proposal, filedAt: state.now });
|
|
48
|
+
state.writer.counts.proposals += 1;
|
|
49
|
+
bump(state.writer.proposalsByKind, kindLabel);
|
|
50
|
+
}
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Names
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
/** First names of the company's own people, each mapped to everyone who has it. */
|
|
55
|
+
function firstNames(state) {
|
|
56
|
+
const map = new Map();
|
|
57
|
+
for (const ref of state.internal) {
|
|
58
|
+
const entity = state.index.get(ref);
|
|
59
|
+
if (!entity)
|
|
60
|
+
continue;
|
|
61
|
+
const firsts = new Set();
|
|
62
|
+
if (entity.tokens[0])
|
|
63
|
+
firsts.add(entity.tokens[0]);
|
|
64
|
+
for (const alias of entity.aliasNorms) {
|
|
65
|
+
const tokens = nameTokens(alias);
|
|
66
|
+
if (tokens.length >= 2 && tokens[0])
|
|
67
|
+
firsts.add(tokens[0]);
|
|
68
|
+
}
|
|
69
|
+
for (const first of firsts) {
|
|
70
|
+
if (first.length < 3)
|
|
71
|
+
continue;
|
|
72
|
+
let set = map.get(first);
|
|
73
|
+
if (!set)
|
|
74
|
+
map.set(first, (set = new Set()));
|
|
75
|
+
set.add(ref);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return new Map([...map].map(([first, refs]) => [first, sortedUnique(refs)]));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Resolves a person written in an internal file: by email, person uid, Slack
|
|
82
|
+
* id or old entity path first, then by full name, then (one word only) by the
|
|
83
|
+
* one member of the company with that first name.
|
|
84
|
+
*/
|
|
85
|
+
export function resolvePersonName(state, written, email = "") {
|
|
86
|
+
const value = written.replace(/\s+/g, " ").trim();
|
|
87
|
+
const address = normalizeEmail(email || (isEmail(value) ? value : ""));
|
|
88
|
+
if (isEmail(address)) {
|
|
89
|
+
const keyed = state.index.byKeys({ email: [address] }, ["person"]);
|
|
90
|
+
if (keyed.length === 1)
|
|
91
|
+
return { ref: keyed[0], how: "key" };
|
|
92
|
+
if (isEmail(value))
|
|
93
|
+
return { ref: null, how: "key" };
|
|
94
|
+
}
|
|
95
|
+
if (PERSON_UID_RE.test(value)) {
|
|
96
|
+
const keyed = state.index.byKeys({ external_ids: [`hq:${value}`] }, ["person"]);
|
|
97
|
+
return { ref: keyed.length === 1 ? keyed[0] : null, how: "key" };
|
|
98
|
+
}
|
|
99
|
+
if (value === "")
|
|
100
|
+
return { ref: null, how: "name" };
|
|
101
|
+
if (slackIdOf(value) || /^person\/\S+$/.test(value)) {
|
|
102
|
+
const keyed = state.index.resolve({ text: value, types: ["person"] });
|
|
103
|
+
return { ref: keyed.status === "resolved" && keyed.entity ? keyed.entity : null, how: "key" };
|
|
104
|
+
}
|
|
105
|
+
const tokens = nameTokens(normalizeName(value));
|
|
106
|
+
if (tokens.length >= 2) {
|
|
107
|
+
const named = state.index.resolve({ text: value, types: ["person"] });
|
|
108
|
+
if (named.status === "resolved" && named.entity)
|
|
109
|
+
return { ref: named.entity, how: "name" };
|
|
110
|
+
return { ref: null, how: "name" };
|
|
111
|
+
}
|
|
112
|
+
if (tokens.length === 1) {
|
|
113
|
+
const sameFirst = firstNames(state).get(tokens[0]) ?? [];
|
|
114
|
+
if (sameFirst.length === 1)
|
|
115
|
+
return { ref: sameFirst[0], how: "first_name" };
|
|
116
|
+
}
|
|
117
|
+
return { ref: null, how: "first_name" };
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Org layer: reporting lines
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
export function applyOrgLayerLinks(state, orgLayer) {
|
|
123
|
+
if (!orgLayer)
|
|
124
|
+
return;
|
|
125
|
+
const personOf = (uid) => {
|
|
126
|
+
if (!PERSON_UID_RE.test(uid))
|
|
127
|
+
return null;
|
|
128
|
+
const keyed = state.index.byKeys({ external_ids: [`hq:${uid}`] }, ["person"]);
|
|
129
|
+
return keyed.length === 1 ? keyed[0] : null;
|
|
130
|
+
};
|
|
131
|
+
for (const edge of orgLayer.edges) {
|
|
132
|
+
if (edge.managerUid.startsWith("agt_") || edge.reportUid.startsWith("agt_")) {
|
|
133
|
+
state.counts.orgLayerAgentEdges += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const report = personOf(edge.reportUid);
|
|
137
|
+
const manager = personOf(edge.managerUid);
|
|
138
|
+
if (!report || !manager || report === manager) {
|
|
139
|
+
state.counts.orgLayerUnresolved += 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const by = edge.human ? `human:${edge.setBy || "unknown"}` : "record";
|
|
143
|
+
const stamp = { from: edge.day ?? state.learned, src: `record:hq-org-layer:${edge.reportUid}`, learned: state.learned, by, conf: edge.human ? 0.95 : 0.85 };
|
|
144
|
+
if (edge.relation === "speaks-for") {
|
|
145
|
+
// An older schema.yaml may not list the verb: then it is kept as related_to with the label.
|
|
146
|
+
const verb = state.writer.schema.link_types.speaks_for ? "speaks_for" : "related_to";
|
|
147
|
+
if (state.writer.claimEdge(manager, verb, report) && state.writer.addRow(manager, AUDIENCE, edgeRow(verb, report, stamp, verb === "related_to" ? "speaks_for" : undefined)))
|
|
148
|
+
state.counts.orgLayerSpeaksFor += 1;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (!state.writer.claimEdge(report, "reports_to", manager))
|
|
152
|
+
continue;
|
|
153
|
+
if (state.writer.addRow(report, AUDIENCE, edgeRow("reports_to", manager, stamp))) {
|
|
154
|
+
state.counts.orgLayerEdges += 1;
|
|
155
|
+
if (edge.human)
|
|
156
|
+
state.counts.orgLayerHumanEdges += 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// A reporting line the reconciler suggested and nobody accepted is a proposal, never an edge.
|
|
160
|
+
for (const suggestion of orgLayer.suggestions) {
|
|
161
|
+
const report = personOf(suggestion.reportUid);
|
|
162
|
+
const manager = personOf(suggestion.managerUid);
|
|
163
|
+
if (!report || !manager || report === manager)
|
|
164
|
+
continue;
|
|
165
|
+
if (state.writer.hasEdge(report, "reports_to", manager))
|
|
166
|
+
continue;
|
|
167
|
+
const src = `record:hq-org-layer:${suggestion.reportUid}`;
|
|
168
|
+
const row = edgeRow("reports_to", manager, { from: state.learned, src, learned: state.learned, by: "rule:org-layer-suggestion", conf: Math.round(Math.min(suggestion.confidence, 0.6) * 100) / 100 });
|
|
169
|
+
fileProposal(state, {
|
|
170
|
+
id: proposalId("org-layer-reporting-line", report, [manager]),
|
|
171
|
+
kind: "retype",
|
|
172
|
+
entity: report,
|
|
173
|
+
audience: AUDIENCE,
|
|
174
|
+
rows: [],
|
|
175
|
+
summary: `The org chart reconciler suggests ${report} reports to ${manager} (its confidence ${suggestion.confidence.toFixed(2)}). Nobody has accepted it in the org chart. Not written.`,
|
|
176
|
+
action: { type: "write_row", entity: report, audience: AUDIENCE, row },
|
|
177
|
+
evidence: [src, ...suggestion.sources.map((source) => `source:${source}`)].slice(0, 5),
|
|
178
|
+
}, "person, org_layer_suggestion");
|
|
179
|
+
state.counts.orgLayerSuggestions += 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function writeRole(state, person, role) {
|
|
183
|
+
const stamp = { from: role.day, src: role.src, learned: state.learned, by: role.by, conf: role.conf };
|
|
184
|
+
if (!state.writer.addRow(person, AUDIENCE, factRow("role_title", role.title, stamp)))
|
|
185
|
+
return;
|
|
186
|
+
const made = state.writer.ensure({ type: "role", name: role.title, seen: role.day, evidence: role.src });
|
|
187
|
+
if (made.ref) {
|
|
188
|
+
if (made.created)
|
|
189
|
+
state.writer.addRow(made.ref, AUDIENCE, factRow("title", role.title, stamp));
|
|
190
|
+
if (state.writer.claimEdge(person, "holds_role", made.ref))
|
|
191
|
+
state.writer.addRow(person, AUDIENCE, edgeRow("holds_role", made.ref, stamp));
|
|
192
|
+
}
|
|
193
|
+
state.titled.set(person, { title: role.title, conf: role.conf, src: role.src, day: role.day });
|
|
194
|
+
state.counts.rolesDerived += 1;
|
|
195
|
+
bump(state.counts.rolesBySource, role.source);
|
|
196
|
+
for (const fn of functionsOf(role.title)) {
|
|
197
|
+
state.teamEvidence.push({ person, team: fn, label: functionLabel(fn), source: role.source, src: role.src, day: role.day });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* One role title per person who has none on record: a statement in a policy
|
|
202
|
+
* first, then a title two or more signal documents agree on.
|
|
203
|
+
*/
|
|
204
|
+
export function applyRoleStatements(state, sources) {
|
|
205
|
+
const best = new Map();
|
|
206
|
+
const offer = (person, candidate) => {
|
|
207
|
+
if (state.titled.has(person))
|
|
208
|
+
return;
|
|
209
|
+
const held = best.get(person);
|
|
210
|
+
if (!held || candidate.conf > held.conf || (candidate.conf === held.conf && candidate.title < held.title))
|
|
211
|
+
best.set(person, candidate);
|
|
212
|
+
};
|
|
213
|
+
for (const statement of sources.policyRoles) {
|
|
214
|
+
const who = resolvePersonName(state, statement.name, statement.email);
|
|
215
|
+
if (!who.ref) {
|
|
216
|
+
state.counts.roleStatementsUnresolved += 1;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
offer(who.ref, { title: statement.title, conf: who.how === "first_name" ? 0.55 : 0.6, by: "rule:policy-role-statement", src: statement.src, day: statement.day ?? state.learned, source: "policy" });
|
|
220
|
+
}
|
|
221
|
+
// Signals: count documents per person and title.
|
|
222
|
+
const byPerson = new Map();
|
|
223
|
+
for (const statement of sources.signalRoles) {
|
|
224
|
+
const who = resolvePersonName(state, statement.name);
|
|
225
|
+
if (!who.ref || who.how === "first_name") {
|
|
226
|
+
state.counts.roleStatementsUnresolved += 1;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
let titles = byPerson.get(who.ref);
|
|
230
|
+
if (!titles)
|
|
231
|
+
byPerson.set(who.ref, (titles = new Map()));
|
|
232
|
+
const key = normalizeName(statement.title);
|
|
233
|
+
let entry = titles.get(key);
|
|
234
|
+
if (!entry)
|
|
235
|
+
titles.set(key, (entry = { title: statement.title, docs: new Set(), first: statement }));
|
|
236
|
+
entry.docs.add(statement.doc);
|
|
237
|
+
if (statement.src < entry.first.src)
|
|
238
|
+
entry.first = statement;
|
|
239
|
+
}
|
|
240
|
+
for (const [person, titles] of byPerson) {
|
|
241
|
+
const ranked = [...titles.values()].sort((a, b) => b.docs.size - a.docs.size || (a.title < b.title ? -1 : 1));
|
|
242
|
+
const top = ranked[0];
|
|
243
|
+
if (top.docs.size < 2) {
|
|
244
|
+
state.counts.signalRolesOneDocument += 1;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
offer(person, { title: top.title, conf: top.docs.size >= 4 ? 0.5 : 0.4, by: "rule:signal-participant-role", src: top.first.src, day: state.learned, source: "signal" });
|
|
248
|
+
}
|
|
249
|
+
for (const person of sortedUnique(best.keys()))
|
|
250
|
+
writeRole(state, person, best.get(person));
|
|
251
|
+
}
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Teams
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
const SOURCE_ORDER = ["roster", "standup", "policy", "channel", "signal", "git"];
|
|
256
|
+
/** A leads edge is written only from a title at least this sure (a people file or a policy statement). */
|
|
257
|
+
const LEADS_MIN_CONF = 0.55;
|
|
258
|
+
const sourceRank = (source) => {
|
|
259
|
+
const index = SOURCE_ORDER.indexOf(source.split(":")[0]);
|
|
260
|
+
return index < 0 ? SOURCE_ORDER.length : index;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Writes a team when at least two independent sources point at it, and a
|
|
264
|
+
* membership when the team stands and either two sources or a kept roster
|
|
265
|
+
* file place the person in it. Everything short of that is a proposal.
|
|
266
|
+
*/
|
|
267
|
+
export function applyTeams(state, channels) {
|
|
268
|
+
const byTeam = new Map();
|
|
269
|
+
for (const evidence of state.teamEvidence) {
|
|
270
|
+
let entries = byTeam.get(evidence.team);
|
|
271
|
+
if (!entries)
|
|
272
|
+
byTeam.set(evidence.team, (entries = []));
|
|
273
|
+
entries.push(evidence);
|
|
274
|
+
}
|
|
275
|
+
const teamRefs = new Map();
|
|
276
|
+
for (const team of sortedUnique(byTeam.keys())) {
|
|
277
|
+
const entries = byTeam.get(team).slice().sort((a, b) => sourceRank(a.source) - sourceRank(b.source) || (a.src < b.src ? -1 : a.src > b.src ? 1 : a.person < b.person ? -1 : 1));
|
|
278
|
+
const label = entries[0].label;
|
|
279
|
+
const sources = sortedUnique(entries.map((entry) => entry.source));
|
|
280
|
+
const people = sortedUnique(entries.map((entry) => entry.person));
|
|
281
|
+
if (sources.length < 2) {
|
|
282
|
+
fileProposal(state, {
|
|
283
|
+
id: proposalId("team-one-source", `team/${team}`, sources),
|
|
284
|
+
kind: "retype",
|
|
285
|
+
rows: [],
|
|
286
|
+
summary: `Team "${label}" is named by one source (${sources[0].split(":")[0]}) for ${people.length} ${people.length === 1 ? "person" : "people"}: ${people.slice(0, 6).join(", ")}. A team needs two independent sources. Not created.`,
|
|
287
|
+
action: { type: "none" },
|
|
288
|
+
evidence: sortedUnique(entries.map((entry) => entry.src)).slice(0, 5),
|
|
289
|
+
}, "team, one_source");
|
|
290
|
+
state.counts.teamsProposed += 1;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
// Two sources that each point at a different person place nobody in the team: still a proposal.
|
|
294
|
+
const placed = people.filter((person) => {
|
|
295
|
+
const mine = sortedUnique(entries.filter((entry) => entry.person === person).map((entry) => entry.source));
|
|
296
|
+
return mine.length >= 2 || mine.some((source) => source.startsWith("roster"));
|
|
297
|
+
});
|
|
298
|
+
if (placed.length === 0) {
|
|
299
|
+
fileProposal(state, {
|
|
300
|
+
id: proposalId("team-no-member", `team/${team}`, sources),
|
|
301
|
+
kind: "retype",
|
|
302
|
+
rows: [],
|
|
303
|
+
summary: `Team "${label}" is named by ${sources.length} sources (${sortedUnique(sources.map((source) => source.split(":")[0])).join(", ")}), each for a different person: ${people.slice(0, 6).join(", ")}. No one is placed in it by two sources or a roster entry. Not created.`,
|
|
304
|
+
action: { type: "none" },
|
|
305
|
+
evidence: sortedUnique(entries.map((entry) => entry.src)).slice(0, 5),
|
|
306
|
+
}, "team, no_member");
|
|
307
|
+
state.counts.teamsProposed += 1;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const firstDay = entries.map((entry) => entry.day).sort()[0];
|
|
311
|
+
const made = state.writer.ensure({ type: "team", name: label, seen: firstDay, evidence: entries[0].src });
|
|
312
|
+
if (!made.ref)
|
|
313
|
+
continue;
|
|
314
|
+
teamRefs.set(team, made.ref);
|
|
315
|
+
if (made.created)
|
|
316
|
+
state.counts.teamsAsserted += 1;
|
|
317
|
+
if (state.selfRef && state.writer.claimEdge(made.ref, "part_of", state.selfRef)) {
|
|
318
|
+
state.writer.addRow(made.ref, AUDIENCE, edgeRow("part_of", state.selfRef, { from: firstDay, src: entries[0].src, learned: state.learned, by: "rule:team-two-sources", conf: 0.6 }));
|
|
319
|
+
}
|
|
320
|
+
for (const person of people) {
|
|
321
|
+
const mine = entries.filter((entry) => entry.person === person);
|
|
322
|
+
const mySources = sortedUnique(mine.map((entry) => entry.source));
|
|
323
|
+
const rostered = mySources.some((source) => source.startsWith("roster"));
|
|
324
|
+
const from = mine.map((entry) => entry.day).sort()[0];
|
|
325
|
+
const conf = rostered ? (mySources.length >= 2 ? 0.8 : 0.7) : mySources.length >= 3 ? 0.6 : 0.5;
|
|
326
|
+
const stamp = { from, src: mine[0].src, learned: state.learned, by: rostered ? "rule:team-roster" : "rule:team-two-sources", conf };
|
|
327
|
+
if (rostered || mySources.length >= 2) {
|
|
328
|
+
if (state.writer.claimEdge(person, "member_of", made.ref) && state.writer.addRow(person, AUDIENCE, edgeRow("member_of", made.ref, stamp)))
|
|
329
|
+
state.counts.teamMembers += 1;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (state.writer.hasEdge(person, "member_of", made.ref))
|
|
333
|
+
continue;
|
|
334
|
+
fileProposal(state, {
|
|
335
|
+
id: proposalId("team-member-one-source", person, [made.ref]),
|
|
336
|
+
kind: "retype",
|
|
337
|
+
entity: person,
|
|
338
|
+
audience: AUDIENCE,
|
|
339
|
+
rows: [],
|
|
340
|
+
summary: `One source (${mySources[0]}) places ${person} in ${made.ref}. A membership needs two independent sources or a roster entry. Not written.`,
|
|
341
|
+
action: { type: "write_row", entity: person, audience: AUDIENCE, row: edgeRow("member_of", made.ref, { ...stamp, by: "rule:team-one-source", conf: 0.4 }) },
|
|
342
|
+
evidence: [mine[0].src],
|
|
343
|
+
}, "person, team_one_source");
|
|
344
|
+
state.counts.teamMembersProposed += 1;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// A channel names the place a team talks; it is a fact on a team that stands, never a team of its own.
|
|
348
|
+
for (const channel of channels) {
|
|
349
|
+
const functions = functionsOf(channel.name.replace(/[-_]/g, " "));
|
|
350
|
+
const refs = functions.map((fn) => teamRefs.get(fn)).filter((ref) => ref !== undefined);
|
|
351
|
+
if (refs.length > 0) {
|
|
352
|
+
for (const ref of refs)
|
|
353
|
+
state.writer.addRow(ref, AUDIENCE, factRow("channel", `#${channel.name}`, { from: channel.firstDay, src: channel.src, learned: state.learned, by: "rule:slack-channel", conf: 0.8 }));
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (channel.frequent < 2)
|
|
357
|
+
continue;
|
|
358
|
+
fileProposal(state, {
|
|
359
|
+
id: proposalId("channel-not-a-team", `channel/${normalizeName(channel.name)}`, []),
|
|
360
|
+
kind: "retype",
|
|
361
|
+
rows: [],
|
|
362
|
+
summary: `Channel #${channel.name} has ${channel.frequent} frequent participants and matches no working group that two sources name. Not made a team.`,
|
|
363
|
+
action: { type: "none" },
|
|
364
|
+
evidence: [channel.src],
|
|
365
|
+
}, "team, channel_only");
|
|
366
|
+
state.counts.channelsNotATeam += 1;
|
|
367
|
+
}
|
|
368
|
+
// "Head of X" leads team X, when team X stands.
|
|
369
|
+
for (const person of sortedUnique(state.titled.keys())) {
|
|
370
|
+
const role = state.titled.get(person);
|
|
371
|
+
const led = ledFunction(role.title);
|
|
372
|
+
const team = led ? teamRefs.get(led) : undefined;
|
|
373
|
+
if (!team)
|
|
374
|
+
continue;
|
|
375
|
+
const stamp = { from: role.day, src: role.src, learned: state.learned, by: "rule:role-title-leads", conf: Math.min(role.conf, 0.7) };
|
|
376
|
+
// Who leads a team is a strong statement. A title only signals suggest does not carry it: that is a proposal.
|
|
377
|
+
if (role.conf < LEADS_MIN_CONF) {
|
|
378
|
+
if (state.writer.hasEdge(person, "leads", team))
|
|
379
|
+
continue;
|
|
380
|
+
fileProposal(state, {
|
|
381
|
+
id: proposalId("team-lead-weak-title", person, [team]),
|
|
382
|
+
kind: "retype",
|
|
383
|
+
entity: person,
|
|
384
|
+
audience: AUDIENCE,
|
|
385
|
+
rows: [],
|
|
386
|
+
summary: `The title "${role.title}" (confidence ${role.conf.toFixed(2)}) suggests ${person} leads ${team}. The title rests on signals only. Not written.`,
|
|
387
|
+
action: { type: "write_row", entity: person, audience: AUDIENCE, row: edgeRow("leads", team, stamp) },
|
|
388
|
+
evidence: [role.src],
|
|
389
|
+
}, "person, team_lead_weak_title");
|
|
390
|
+
state.counts.teamLeadsProposed += 1;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (!state.writer.claimEdge(person, "leads", team))
|
|
394
|
+
continue;
|
|
395
|
+
if (state.writer.addRow(person, AUDIENCE, edgeRow("leads", team, stamp)))
|
|
396
|
+
state.counts.teamLeads += 1;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/** Standup headings: `## <Name> — <area>` is one source for the person's working group. */
|
|
400
|
+
export function collectStandupEvidence(state, sources) {
|
|
401
|
+
const seen = new Set();
|
|
402
|
+
for (const area of sources.standups.areas) {
|
|
403
|
+
const who = resolvePersonName(state, area.name);
|
|
404
|
+
if (!who.ref)
|
|
405
|
+
continue;
|
|
406
|
+
if (who.how === "first_name")
|
|
407
|
+
state.counts.firstNamesResolved += 1;
|
|
408
|
+
for (const fn of area.functions) {
|
|
409
|
+
const key = `${who.ref}\n${fn}`;
|
|
410
|
+
if (seen.has(key))
|
|
411
|
+
continue;
|
|
412
|
+
seen.add(key);
|
|
413
|
+
state.teamEvidence.push({ person: who.ref, team: fn, label: functionLabel(fn), source: "standup", src: area.src, day: area.day });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
// ---------------------------------------------------------------------------
|
|
418
|
+
// Standup attendance and email domains: who is inside the company
|
|
419
|
+
// ---------------------------------------------------------------------------
|
|
420
|
+
function markInternal(state, person, stamp) {
|
|
421
|
+
if (!state.selfRef || state.internal.has(person))
|
|
422
|
+
return false;
|
|
423
|
+
if (state.rosterAuthoritative)
|
|
424
|
+
return false;
|
|
425
|
+
state.internal.add(person);
|
|
426
|
+
if (state.writer.claimEdge(person, "works_at", state.selfRef))
|
|
427
|
+
state.writer.addRow(person, AUDIENCE, edgeRow("works_at", state.selfRef, stamp));
|
|
428
|
+
if (!state.writer.hasFact(person, "affiliation", state.selfName))
|
|
429
|
+
state.writer.addRow(person, AUDIENCE, factRow("affiliation", state.selfName, stamp));
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
/** Marks people by the mail domain of an address they hold: the company's own domain, or the web domain of exactly one other company. */
|
|
433
|
+
export function applyEmailAffiliation(state) {
|
|
434
|
+
for (const ref of state.index.refs()) {
|
|
435
|
+
const entity = state.index.get(ref);
|
|
436
|
+
if (!entity || entity.type !== "person" || state.internal.has(ref))
|
|
437
|
+
continue;
|
|
438
|
+
const domains = sortedUnique([...entity.emails].map((email) => email.slice(email.lastIndexOf("@") + 1))).filter((domain) => !SHARED_MAIL_DOMAINS.has(domain));
|
|
439
|
+
if (domains.length === 0)
|
|
440
|
+
continue;
|
|
441
|
+
const src = `record:email-domain:${domains[0]}`;
|
|
442
|
+
if (domains.some((domain) => state.ownDomains.has(domain))) {
|
|
443
|
+
if (markInternal(state, ref, { from: state.learned, src, learned: state.learned, by: "rule:email-domain-own", conf: 0.7 }))
|
|
444
|
+
state.counts.internalByDomain += 1;
|
|
445
|
+
else if (state.rosterAuthoritative)
|
|
446
|
+
state.counts.ownDomainNotOnRoster += 1;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const employers = sortedUnique(domains.flatMap((domain) => state.index.byKeys({ web_domains: [domain] }, ["company"])));
|
|
450
|
+
if (employers.length !== 1 || employers[0] === state.selfRef)
|
|
451
|
+
continue;
|
|
452
|
+
const employer = employers[0];
|
|
453
|
+
if (state.writer.hasEdge(ref, "works_at", employer) || !state.writer.claimEdge(ref, "works_at", employer))
|
|
454
|
+
continue;
|
|
455
|
+
const stamp = { from: state.learned, src, learned: state.learned, by: "rule:email-domain-company", conf: 0.6 };
|
|
456
|
+
if (!state.writer.addRow(ref, AUDIENCE, edgeRow("works_at", employer, stamp)))
|
|
457
|
+
continue;
|
|
458
|
+
state.writer.addRow(ref, AUDIENCE, factRow("status", "external", stamp));
|
|
459
|
+
const name = state.index.get(employer)?.name;
|
|
460
|
+
if (name)
|
|
461
|
+
state.writer.addRow(ref, AUDIENCE, factRow("affiliation", name, stamp));
|
|
462
|
+
state.counts.externalByDomain += 1;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/** A timeline line per regular standup attendee, and membership of the company for one found by full name. */
|
|
466
|
+
export function applyStandupAttendance(state, sources, minNotes = 3) {
|
|
467
|
+
for (const attendee of sources.standups.attendance) {
|
|
468
|
+
if (attendee.notes < minNotes)
|
|
469
|
+
continue;
|
|
470
|
+
const who = resolvePersonName(state, attendee.name);
|
|
471
|
+
if (!who.ref)
|
|
472
|
+
continue;
|
|
473
|
+
state.counts.standupAttendees += 1;
|
|
474
|
+
state.writer.addRow(who.ref, AUDIENCE, {
|
|
475
|
+
kind: "T",
|
|
476
|
+
date: attendee.lastDay,
|
|
477
|
+
signalType: "attendance",
|
|
478
|
+
text: `Listed as attending ${attendee.notes} standups, ${attendee.firstDay} to ${attendee.lastDay}`,
|
|
479
|
+
src: attendee.lastSrc,
|
|
480
|
+
});
|
|
481
|
+
if (who.how !== "name")
|
|
482
|
+
continue;
|
|
483
|
+
if (markInternal(state, who.ref, { from: attendee.firstDay, src: attendee.lastSrc, learned: state.learned, by: "rule:standup-attendance", conf: 0.6 }))
|
|
484
|
+
state.counts.internalByAttendance += 1;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
// ---------------------------------------------------------------------------
|
|
488
|
+
// Project owners from PRDs
|
|
489
|
+
// ---------------------------------------------------------------------------
|
|
490
|
+
export function applyPrdOwners(state, sources, phase) {
|
|
491
|
+
let created = 0;
|
|
492
|
+
for (const prd of sources.prdOwners) {
|
|
493
|
+
const day = prd.day ?? state.learned;
|
|
494
|
+
let project;
|
|
495
|
+
if (phase.anchors) {
|
|
496
|
+
const made = state.writer.ensure({ type: "project", name: prd.project, aliases: prd.title !== "" && prd.title !== prd.project ? [prd.title] : [], seen: day, evidence: prd.src });
|
|
497
|
+
project = made.ref;
|
|
498
|
+
if (made.created)
|
|
499
|
+
created += 1;
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
project = state.index.findSameName("project", prd.project)[0] ?? null;
|
|
503
|
+
}
|
|
504
|
+
if (!project || !phase.links)
|
|
505
|
+
continue;
|
|
506
|
+
const owner = resolvePersonName(state, prd.owner);
|
|
507
|
+
if (!owner.ref) {
|
|
508
|
+
state.counts.prdOwnersUnresolved += 1;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (owner.how === "first_name")
|
|
512
|
+
state.counts.firstNamesResolved += 1;
|
|
513
|
+
if (!state.writer.claimEdge(project, "owned_by", owner.ref))
|
|
514
|
+
continue;
|
|
515
|
+
const stamp = { from: day, src: prd.src, learned: state.learned, by: "record", conf: owner.how === "first_name" ? 0.6 : 0.8 };
|
|
516
|
+
if (state.writer.addRow(project, AUDIENCE, edgeRow("owned_by", owner.ref, stamp)))
|
|
517
|
+
state.counts.prdOwners += 1;
|
|
518
|
+
}
|
|
519
|
+
return created;
|
|
520
|
+
}
|
|
521
|
+
// ---------------------------------------------------------------------------
|
|
522
|
+
// Clients
|
|
523
|
+
// ---------------------------------------------------------------------------
|
|
524
|
+
/** Titles a client's contact can hold that the stricter title rule does not list. */
|
|
525
|
+
const CONTACT_TITLE_RE = /\b(?:owner|operator|executive|strategist|producer|editor|specialist|coordinator|administrator|associate|buyer|investor|chair|chairman|chairwoman|treasurer|secretary)\b/i;
|
|
526
|
+
function contactTitle(raw) {
|
|
527
|
+
const title = titleFrom(raw);
|
|
528
|
+
if (title)
|
|
529
|
+
return title;
|
|
530
|
+
const first = withoutBrackets(raw).split(/[,;]/)[0].replace(/\s+/g, " ").trim();
|
|
531
|
+
return /^[A-Z][A-Za-z &/-]{2,40}$/.test(first) && CONTACT_TITLE_RE.test(first) ? first : "";
|
|
532
|
+
}
|
|
533
|
+
const PROSPECT_STAGES = new Set(["prospect", "demo", "demo_done", "proposal"]);
|
|
534
|
+
/** Stages from the least to the furthest along. A churned client was signed once. */
|
|
535
|
+
const STAGE_RANK = ["", "prospect", "demo", "demo_done", "proposal", "churned", "signed"];
|
|
536
|
+
/**
|
|
537
|
+
* Companies from the clients folder: a stage where a file states one, a
|
|
538
|
+
* customer edge only where a file says an agreement is signed or in effect,
|
|
539
|
+
* the people named as contacts, and the account owner.
|
|
540
|
+
*/
|
|
541
|
+
export function applyClients(state, clients, phase) {
|
|
542
|
+
let created = 0;
|
|
543
|
+
// Two folders can be one company (`acme` and `acme-inc`). The folder that states the furthest stage speaks for it.
|
|
544
|
+
const strongest = new Map();
|
|
545
|
+
const companyKey = (client) => (client.domain !== "" && !SHARED_MAIL_DOMAINS.has(client.domain) ? `domain:${client.domain}` : `name:${normalizeName(client.name)}`);
|
|
546
|
+
for (const client of clients) {
|
|
547
|
+
const held = strongest.get(companyKey(client));
|
|
548
|
+
if (!held || STAGE_RANK.indexOf(client.stage) > STAGE_RANK.indexOf(held.stage))
|
|
549
|
+
strongest.set(companyKey(client), client);
|
|
550
|
+
}
|
|
551
|
+
const staged = new Set();
|
|
552
|
+
const ordered = [...clients].sort((a, b) => STAGE_RANK.indexOf(b.stage) - STAGE_RANK.indexOf(a.stage) || (a.slug < b.slug ? -1 : 1));
|
|
553
|
+
for (const client of ordered) {
|
|
554
|
+
const day = client.day ?? state.learned;
|
|
555
|
+
const domains = client.domain !== "" && !SHARED_MAIL_DOMAINS.has(client.domain) ? [client.domain] : [];
|
|
556
|
+
let company;
|
|
557
|
+
if (phase.anchors) {
|
|
558
|
+
const made = state.writer.ensure({ type: "company", name: client.name, keys: { external_ids: client.externalIds, web_domains: domains }, seen: day, evidence: client.src });
|
|
559
|
+
company = made.ref;
|
|
560
|
+
if (made.created)
|
|
561
|
+
created += 1;
|
|
562
|
+
if (company && company !== state.selfRef) {
|
|
563
|
+
state.counts.clients += 1;
|
|
564
|
+
const stamp = { from: day, src: client.src, learned: state.learned, by: "record", conf: 0.8 };
|
|
565
|
+
for (const domain of domains)
|
|
566
|
+
state.writer.addRow(company, AUDIENCE, factRow("web_domain", domain, stamp));
|
|
567
|
+
// One stage per company: the furthest any of its folders states. Folders run strongest first.
|
|
568
|
+
const speaks = strongest.get(companyKey(client)) === client && !staged.has(company);
|
|
569
|
+
if (speaks)
|
|
570
|
+
staged.add(company);
|
|
571
|
+
if (speaks && client.stage !== "") {
|
|
572
|
+
if (state.writer.addRow(company, AUDIENCE, factRow("stage", client.stage, stamp)))
|
|
573
|
+
state.counts.clientsWithStage += 1;
|
|
574
|
+
}
|
|
575
|
+
const relation = !speaks ? "" : client.customer ? "customer" : client.stage === "churned" ? "former customer" : PROSPECT_STAGES.has(client.stage) ? "prospect" : "";
|
|
576
|
+
if (relation !== "")
|
|
577
|
+
state.writer.addRow(company, AUDIENCE, factRow("relation", relation, stamp));
|
|
578
|
+
if (speaks && client.customer && state.selfRef && state.writer.claimEdge(company, "customer_of", state.selfRef)) {
|
|
579
|
+
const customerStamp = { ...stamp, from: client.effective ?? day, by: "rule:client-agreement", conf: 0.85 };
|
|
580
|
+
if (state.writer.addRow(company, AUDIENCE, edgeRow("customer_of", state.selfRef, customerStamp)))
|
|
581
|
+
state.counts.clientCustomers += 1;
|
|
582
|
+
}
|
|
583
|
+
for (const contact of client.contacts) {
|
|
584
|
+
if (contact.side.startsWith("in") || nameTokens(normalizeName(contact.name)).length < 2)
|
|
585
|
+
continue;
|
|
586
|
+
const person = state.writer.ensure({ type: "person", name: contact.name, keys: { email: contact.email !== "" ? [contact.email] : [] }, seen: day, evidence: client.src });
|
|
587
|
+
if (!person.ref || state.internal.has(person.ref))
|
|
588
|
+
continue;
|
|
589
|
+
const contactStamp = { from: day, src: client.src, learned: state.learned, by: "rule:client-contact", conf: 0.7 };
|
|
590
|
+
if (contact.email !== "")
|
|
591
|
+
state.writer.addRow(person.ref, AUDIENCE, factRow("email", contact.email, contactStamp));
|
|
592
|
+
if (state.writer.claimEdge(person.ref, "works_at", company))
|
|
593
|
+
state.writer.addRow(person.ref, AUDIENCE, edgeRow("works_at", company, contactStamp));
|
|
594
|
+
state.writer.addRow(person.ref, AUDIENCE, factRow("status", "external", contactStamp));
|
|
595
|
+
state.writer.addRow(person.ref, AUDIENCE, factRow("affiliation", client.name, contactStamp));
|
|
596
|
+
const title = contactTitle(contact.title);
|
|
597
|
+
if (title !== "" && !state.titled.has(person.ref)) {
|
|
598
|
+
writeRole(state, person.ref, { title, conf: 0.65, by: "rule:client-contact", src: client.src, day, source: "client" });
|
|
599
|
+
// A contact's title says nothing about this company's own working groups.
|
|
600
|
+
state.teamEvidence = state.teamEvidence.filter((evidence) => evidence.person !== person.ref);
|
|
601
|
+
}
|
|
602
|
+
state.counts.clientContacts += 1;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
company = (domains.length > 0 ? state.index.byKeys({ web_domains: domains }, ["company"])[0] : undefined) ?? state.index.findSameName("company", client.name)[0] ?? null;
|
|
608
|
+
}
|
|
609
|
+
if (!company || company === state.selfRef || !phase.links || client.owner === "")
|
|
610
|
+
continue;
|
|
611
|
+
const owner = resolvePersonName(state, client.owner);
|
|
612
|
+
if (!owner.ref) {
|
|
613
|
+
state.counts.clientOwnersUnresolved += 1;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (owner.how === "first_name")
|
|
617
|
+
state.counts.firstNamesResolved += 1;
|
|
618
|
+
const stamp = { from: day, src: client.src, learned: state.learned, by: "record", conf: owner.how === "first_name" ? 0.6 : 0.8 };
|
|
619
|
+
// The company type has no owner field and no owning verb in the closed vocabulary: kept as a labelled related_to.
|
|
620
|
+
if (state.writer.schema.entity_types.company?.facts.owner) {
|
|
621
|
+
if (state.writer.addRow(company, AUDIENCE, factRow("owner", owner.ref, stamp)))
|
|
622
|
+
state.counts.clientOwners += 1;
|
|
623
|
+
}
|
|
624
|
+
else if (state.writer.claimEdge(company, "related_to", owner.ref)) {
|
|
625
|
+
if (state.writer.addRow(company, AUDIENCE, edgeRow("related_to", owner.ref, stamp, "account owner")))
|
|
626
|
+
state.counts.clientOwners += 1;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return created;
|
|
630
|
+
}
|
|
631
|
+
//# sourceMappingURL=org-seed.js.map
|