@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,578 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-C: the org chart draft. For each person on the roster it gathers what
|
|
3
|
+
* the company's files suggest about their role title, team and manager, and
|
|
4
|
+
* proposes one line. Nothing here is written as a fact: every line is a
|
|
5
|
+
* proposal with its evidence and a confidence, for a person to confirm.
|
|
6
|
+
*
|
|
7
|
+
* Evidence, all company scope, all cited:
|
|
8
|
+
* people files a role a person typed
|
|
9
|
+
* policies "<Name> is <Company>'s <Title>"
|
|
10
|
+
* signals `Role:` beside a participant; `Decided by: <Name> (<Title>)`
|
|
11
|
+
* signals, meeting notes, knowledge "<Full Name> (<descriptor>)", counted per document
|
|
12
|
+
* standup notes `## <Name> — <area>` headings; attendance
|
|
13
|
+
* Slack channels, git history working-group evidence the seed already collected
|
|
14
|
+
* board and PRDs projects the person owns
|
|
15
|
+
* the org layer reporting lines the reconciler suggested
|
|
16
|
+
*
|
|
17
|
+
* The accept path has two doors, both ending in rows of origin `human`:
|
|
18
|
+
* 1. each line is a proposal (`write_row`); accepting it writes the row as the member's own;
|
|
19
|
+
* 2. `people/org-chart.yaml` in the company folder, which a person keeps and the seed reads on every run.
|
|
20
|
+
*/
|
|
21
|
+
import * as fs from "node:fs";
|
|
22
|
+
import * as path from "node:path";
|
|
23
|
+
import yaml from "js-yaml";
|
|
24
|
+
import { slugify } from "../schema/index.js";
|
|
25
|
+
import { githubLoginFromEmail, nameTokens, normalizeName, slackIdInside, sortedUnique } from "./normalize.js";
|
|
26
|
+
import { functionLabel, functionsOf, ledFunction, titleFrom } from "./org-sources.js";
|
|
27
|
+
import { edgeRow, factRow, proposalId } from "./writer.js";
|
|
28
|
+
export const ORG_CHART_SET = "org chart draft";
|
|
29
|
+
export const ORG_CHART_STATE = ".state/org-chart-draft.json";
|
|
30
|
+
/** The file a person keeps: confirmed role, team and manager per person. Relative to the company folder. */
|
|
31
|
+
export const ORG_CHART_FILE = "people/org-chart.yaml";
|
|
32
|
+
/** Words a bracket uses for a role that the stricter title rule does not list. */
|
|
33
|
+
const LOOSE_TITLE_RE = /\b(?:operator|professional|counsel|attorney|lawyer|accountant|bookkeeper|investor|contractor|freelancer|intern|editor|writer|producer)\b/i;
|
|
34
|
+
/** Brackets that say what someone did or when they spoke, not what they are. */
|
|
35
|
+
const NOT_A_ROLE_RE = /\b(?:agreed|proposed|recommended|confirmed|affirmed|absent|speaking time|sign-off|pending|concurring|involved|referred|consensus|decision|for himself|for herself|with|from|approx|~|\d{1,2}:\d{2})\b|[%@`[]/i;
|
|
36
|
+
/**
|
|
37
|
+
* The job a bracket states, or null: `Indigo/HQ co-founder` gives
|
|
38
|
+
* `Co-founder`, `Sr. Engineer` gives `Sr. Engineer`, `agreed` gives null. The
|
|
39
|
+
* company's own words are dropped from the front of each part.
|
|
40
|
+
*/
|
|
41
|
+
export function descriptorTitle(text, ownWords) {
|
|
42
|
+
if (slackIdInside(text) || NOT_A_ROLE_RE.test(text) || text.length > 60)
|
|
43
|
+
return null;
|
|
44
|
+
for (const part of text.split(/\s*(?:\/|;|,|\||—|–)\s*/)) {
|
|
45
|
+
const words = part.replace(/\s+/g, " ").trim().split(" ");
|
|
46
|
+
while (words.length > 0 && ownWords.has(normalizeName(words[0])))
|
|
47
|
+
words.shift();
|
|
48
|
+
const candidate = words.join(" ").trim();
|
|
49
|
+
if (candidate.length < 3)
|
|
50
|
+
continue;
|
|
51
|
+
const strict = titleFrom(candidate);
|
|
52
|
+
const title = strict ?? (LOOSE_TITLE_RE.test(candidate) && /^[A-Za-z][A-Za-z .&-]{2,40}$/.test(candidate) ? candidate : null);
|
|
53
|
+
if (title)
|
|
54
|
+
return title[0].toUpperCase() + title.slice(1);
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const COPY_NAME_RE = /(?: \d+(?=\.[^.]+$)|\.conflict-)/;
|
|
59
|
+
function listFiles(dir, depth, out, limit) {
|
|
60
|
+
if (out.length >= limit)
|
|
61
|
+
return;
|
|
62
|
+
let entries;
|
|
63
|
+
try {
|
|
64
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const entry of entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
70
|
+
if (entry.name.startsWith(".") || entry.name.startsWith("_") || entry.name.startsWith("@") || COPY_NAME_RE.test(entry.name))
|
|
71
|
+
continue;
|
|
72
|
+
const full = path.join(dir, entry.name);
|
|
73
|
+
if (entry.isDirectory()) {
|
|
74
|
+
if (depth > 0)
|
|
75
|
+
listFiles(full, depth - 1, out, limit);
|
|
76
|
+
}
|
|
77
|
+
else if (entry.name.endsWith(".md") && out.length < limit)
|
|
78
|
+
out.push(full);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Signal folders a company-wide reader may see. DM signals and per-audience folders are never read here. */
|
|
82
|
+
const SIGNAL_FOLDERS = ["summary", "key_point", "decision", "participant_contribution", "action_item", "commitment", "question", "risk"];
|
|
83
|
+
/**
|
|
84
|
+
* Reads the company-scope documents and counts, per roster name, the titles
|
|
85
|
+
* written in a bracket right after the full name. One count per document.
|
|
86
|
+
*/
|
|
87
|
+
export function readNameDescriptors(companyRoot, names, ownWords, maxFiles = 40_000) {
|
|
88
|
+
const full = names.filter((name) => nameTokens(normalizeName(name)).length >= 2);
|
|
89
|
+
if (full.length === 0)
|
|
90
|
+
return [];
|
|
91
|
+
const patterns = full.map((name) => ({ name, re: new RegExp(`${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\(([^)\\n]{2,80})\\)`, "g") }));
|
|
92
|
+
const files = [];
|
|
93
|
+
for (const folder of SIGNAL_FOLDERS) {
|
|
94
|
+
const found = [];
|
|
95
|
+
listFiles(path.join(companyRoot, "signals", folder), 0, found, maxFiles);
|
|
96
|
+
for (const file of found)
|
|
97
|
+
files.push({ file, signal: true });
|
|
98
|
+
}
|
|
99
|
+
for (const [folder, depth] of [["meetings/notes", 0], ["policies", 0], ["knowledge", 3]]) {
|
|
100
|
+
const found = [];
|
|
101
|
+
listFiles(path.join(companyRoot, ...folder.split("/")), depth, found, maxFiles);
|
|
102
|
+
for (const file of found)
|
|
103
|
+
files.push({ file, signal: false });
|
|
104
|
+
}
|
|
105
|
+
for (const name of ["README.md"])
|
|
106
|
+
if (fs.existsSync(path.join(companyRoot, name)))
|
|
107
|
+
files.push({ file: path.join(companyRoot, name), signal: false });
|
|
108
|
+
const counted = new Map();
|
|
109
|
+
for (const { file, signal } of files.slice(0, maxFiles)) {
|
|
110
|
+
let content;
|
|
111
|
+
try {
|
|
112
|
+
content = fs.readFileSync(file, "utf8");
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
let src = null;
|
|
118
|
+
const seen = new Set();
|
|
119
|
+
for (const { name, re } of patterns) {
|
|
120
|
+
if (!content.includes(name))
|
|
121
|
+
continue;
|
|
122
|
+
// Wiki links around a name or a title are markup, not text.
|
|
123
|
+
const flat = content.replace(/\[\[[^\]|]*\|([^\]]*)\]\]/g, "$1");
|
|
124
|
+
for (const match of flat.matchAll(re)) {
|
|
125
|
+
const title = descriptorTitle(match[1] ?? "", ownWords);
|
|
126
|
+
if (!title)
|
|
127
|
+
continue;
|
|
128
|
+
const key = `${name}\n${normalizeName(title)}`;
|
|
129
|
+
if (seen.has(key))
|
|
130
|
+
continue;
|
|
131
|
+
seen.add(key);
|
|
132
|
+
if (!src) {
|
|
133
|
+
const signalId = signal ? /^signal_id:\s*["']?([0-9a-f]{12,})/m.exec(content)?.[1] : undefined;
|
|
134
|
+
src = (signalId ? `signal:${signalId.slice(0, 12)}` : `doc:${path.relative(companyRoot, file).split(path.sep).join("/")}`);
|
|
135
|
+
}
|
|
136
|
+
const held = counted.get(key);
|
|
137
|
+
if (held)
|
|
138
|
+
held.docs += 1;
|
|
139
|
+
else
|
|
140
|
+
counted.set(key, { name, title, docs: 1, src, sample: (match[1] ?? "").replace(/\s+/g, " ").trim() });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return [...counted.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : b.docs - a.docs || (a.title < b.title ? -1 : 1)));
|
|
145
|
+
}
|
|
146
|
+
const round2 = (value) => Math.round(value * 100) / 100;
|
|
147
|
+
function docsConf(docs) {
|
|
148
|
+
return docs >= 10 ? 0.6 : docs >= 4 ? 0.5 : docs >= 2 ? 0.4 : 0.3;
|
|
149
|
+
}
|
|
150
|
+
function pick(candidates) {
|
|
151
|
+
const ranked = [...candidates.values()].sort((a, b) => b.conf - a.conf || b.kinds.size - a.kinds.size || b.evidence.length - a.evidence.length || (a.value < b.value ? -1 : 1));
|
|
152
|
+
const top = ranked[0];
|
|
153
|
+
if (!top)
|
|
154
|
+
return null;
|
|
155
|
+
// Each further independent kind of source adds a little; a typed people file is never raised.
|
|
156
|
+
// A default has nothing behind it and raises nothing.
|
|
157
|
+
const independent = [...top.kinds].filter((kind) => kind !== "default").length;
|
|
158
|
+
const conf = top.conf >= 0.9 ? top.conf : Math.min(0.75, top.conf + 0.05 * Math.max(0, independent - 1));
|
|
159
|
+
return {
|
|
160
|
+
value: top.value,
|
|
161
|
+
...(top.target ? { target: top.target } : {}),
|
|
162
|
+
conf: round2(conf),
|
|
163
|
+
evidence: top.evidence.slice(0, 6),
|
|
164
|
+
alternatives: ranked.slice(1, 4).map((other) => `${other.value} (${round2(other.conf).toFixed(2)})`),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function offer(candidates, key, value, conf, kind, evidence, target) {
|
|
168
|
+
const held = candidates.get(key);
|
|
169
|
+
if (!held) {
|
|
170
|
+
candidates.set(key, { value, ...(target ? { target } : {}), conf, evidence: [evidence], kinds: new Set([kind]) });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (conf > held.conf) {
|
|
174
|
+
held.conf = conf;
|
|
175
|
+
held.value = value;
|
|
176
|
+
held.evidence.unshift(evidence);
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
held.evidence.push(evidence);
|
|
180
|
+
held.kinds.add(kind);
|
|
181
|
+
}
|
|
182
|
+
const CEO_RE = /\b(?:ceo|chief executive)\b/i;
|
|
183
|
+
const EXECUTIVE_RE = /^(?:C[A-Z]O|Chief [A-Za-z ]+)$/;
|
|
184
|
+
const FOUNDER_RE = /^(?:co-?)?founder$/i;
|
|
185
|
+
export function buildOrgChartDraft(input) {
|
|
186
|
+
const { seed, result } = input;
|
|
187
|
+
const members = [...input.roster].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
188
|
+
const byNorm = new Map();
|
|
189
|
+
const byFirst = new Map();
|
|
190
|
+
const byUid = new Map();
|
|
191
|
+
const byEmail = new Map();
|
|
192
|
+
for (const member of members) {
|
|
193
|
+
const tokens = nameTokens(normalizeName(member.name));
|
|
194
|
+
byNorm.set(tokens.join(" "), member);
|
|
195
|
+
byFirst.set(tokens[0] ?? "", [...(byFirst.get(tokens[0] ?? "") ?? []), member]);
|
|
196
|
+
for (const uid of member.personUids)
|
|
197
|
+
byUid.set(uid, member);
|
|
198
|
+
for (const email of member.emails)
|
|
199
|
+
byEmail.set(email, member);
|
|
200
|
+
}
|
|
201
|
+
/** The roster person a file means by a name, an email or a person uid. A first name only when one member has it. */
|
|
202
|
+
const who = (written, email = "") => {
|
|
203
|
+
const value = written.trim();
|
|
204
|
+
if (email && byEmail.has(email.toLowerCase()))
|
|
205
|
+
return byEmail.get(email.toLowerCase());
|
|
206
|
+
if (byEmail.has(value.toLowerCase()))
|
|
207
|
+
return byEmail.get(value.toLowerCase());
|
|
208
|
+
if (byUid.has(value))
|
|
209
|
+
return byUid.get(value);
|
|
210
|
+
const tokens = nameTokens(normalizeName(value));
|
|
211
|
+
if (tokens.length >= 2)
|
|
212
|
+
return byNorm.get(tokens.join(" ")) ?? null;
|
|
213
|
+
const sameFirst = byFirst.get(tokens[0] ?? "") ?? [];
|
|
214
|
+
return sameFirst.length === 1 ? sameFirst[0] : null;
|
|
215
|
+
};
|
|
216
|
+
const roles = new Map();
|
|
217
|
+
const teams = new Map();
|
|
218
|
+
const activity = new Map();
|
|
219
|
+
for (const member of members) {
|
|
220
|
+
roles.set(member.ref, new Map());
|
|
221
|
+
teams.set(member.ref, new Map());
|
|
222
|
+
activity.set(member.ref, []);
|
|
223
|
+
}
|
|
224
|
+
const role = (member, written, conf, kind, evidence) => {
|
|
225
|
+
// `Acme Co-founder` and `HQ Founder` state the titles `Co-founder` and `Founder`.
|
|
226
|
+
const words = written.trim().split(/\s+/);
|
|
227
|
+
while (words.length > 1 && (input.ownWords?.has(normalizeName(words[0])) ?? false))
|
|
228
|
+
words.shift();
|
|
229
|
+
const title = words.join(" ").replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
230
|
+
offer(roles.get(member.ref), normalizeName(title), title, conf, kind, evidence);
|
|
231
|
+
for (const fn of functionsOf(title))
|
|
232
|
+
offer(teams.get(member.ref), fn, functionLabel(fn), 0.3, "title", { text: `The title "${title}" points at ${functionLabel(fn)}`, src: evidence.src });
|
|
233
|
+
};
|
|
234
|
+
// Role titles.
|
|
235
|
+
for (const person of seed.people) {
|
|
236
|
+
if (!person.role || !person.from.includes("people"))
|
|
237
|
+
continue;
|
|
238
|
+
const member = who(person.name);
|
|
239
|
+
if (member)
|
|
240
|
+
role(member, person.role, 0.9, "people-file", { text: `The people file states the role "${person.role}"`, src: person.src });
|
|
241
|
+
}
|
|
242
|
+
for (const statement of seed.org?.policyRoles ?? []) {
|
|
243
|
+
const member = who(statement.name, statement.email);
|
|
244
|
+
if (member)
|
|
245
|
+
role(member, statement.title, 0.6, "policy", { text: `A policy says ${statement.name} is ${statement.title}`, src: statement.src });
|
|
246
|
+
}
|
|
247
|
+
const signalDocs = new Map();
|
|
248
|
+
for (const statement of seed.org?.signalRoles ?? []) {
|
|
249
|
+
const member = who(statement.name.replace(/^person\//, "").replace(/-/g, " "));
|
|
250
|
+
if (!member)
|
|
251
|
+
continue;
|
|
252
|
+
const key = `${member.ref}\n${normalizeName(statement.title)}`;
|
|
253
|
+
const held = signalDocs.get(key) ?? { member, title: statement.title, docs: new Set(), src: statement.src };
|
|
254
|
+
held.docs.add(statement.doc);
|
|
255
|
+
signalDocs.set(key, held);
|
|
256
|
+
}
|
|
257
|
+
for (const held of signalDocs.values()) {
|
|
258
|
+
role(held.member, held.title, docsConf(held.docs.size), "signal-role", { text: `${held.docs.size} ${held.docs.size === 1 ? "document's signals give" : "documents' signals give"} the role "${held.title}"`, src: held.src });
|
|
259
|
+
}
|
|
260
|
+
for (const descriptor of input.descriptors) {
|
|
261
|
+
const member = who(descriptor.name);
|
|
262
|
+
if (member)
|
|
263
|
+
role(member, descriptor.title, docsConf(descriptor.docs), "descriptor", { text: `${descriptor.docs} ${descriptor.docs === 1 ? "document writes" : "documents write"} "${descriptor.name} (${descriptor.sample})"`, src: descriptor.src });
|
|
264
|
+
}
|
|
265
|
+
// Working groups: what the seed collected, per independent source.
|
|
266
|
+
const refToMember = new Map(members.map((member) => [member.ref, member]));
|
|
267
|
+
const perTeam = new Map();
|
|
268
|
+
for (const evidence of result.teamEvidence ?? []) {
|
|
269
|
+
if (!refToMember.has(evidence.person))
|
|
270
|
+
continue;
|
|
271
|
+
const key = `${evidence.person}\n${evidence.team}`;
|
|
272
|
+
perTeam.set(key, [...(perTeam.get(key) ?? []), evidence]);
|
|
273
|
+
}
|
|
274
|
+
for (const [key, entries] of perTeam) {
|
|
275
|
+
const [ref, team] = key.split("\n");
|
|
276
|
+
const sources = sortedUnique(entries.map((entry) => entry.source.split(":")[0]));
|
|
277
|
+
for (const source of sources) {
|
|
278
|
+
const first = entries.find((entry) => entry.source.split(":")[0] === source);
|
|
279
|
+
const conf = source === "roster" ? 0.7 : 0.35;
|
|
280
|
+
const count = entries.filter((entry) => entry.source.split(":")[0] === source).length;
|
|
281
|
+
const said = {
|
|
282
|
+
roster: "The people file places them here",
|
|
283
|
+
standup: "A standup note lists their area under this group",
|
|
284
|
+
channel: "Frequent in a Slack channel named for this group",
|
|
285
|
+
git: "Commits to the company's repos",
|
|
286
|
+
policy: "A policy gives a title in this group",
|
|
287
|
+
signal: "Signals give a title in this group",
|
|
288
|
+
client: "A client file gives a title in this group",
|
|
289
|
+
};
|
|
290
|
+
offer(teams.get(ref), team, first.label, conf, source, { text: `${said[source] ?? `Source: ${source}`}${count > 1 ? ` (${count} times)` : ""}`, src: first.src });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Two independent sources are worth more than either: the same rule the seed uses for a team.
|
|
294
|
+
for (const candidates of teams.values()) {
|
|
295
|
+
for (const candidate of candidates.values()) {
|
|
296
|
+
const independent = [...candidate.kinds].filter((kind) => kind !== "title").length;
|
|
297
|
+
if (candidate.conf < 0.7 && independent >= 3)
|
|
298
|
+
candidate.conf = 0.6;
|
|
299
|
+
else if (candidate.conf < 0.7 && independent === 2)
|
|
300
|
+
candidate.conf = 0.5;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Activity: commits, standups, projects owned.
|
|
304
|
+
const commits = new Map();
|
|
305
|
+
for (const repo of seed.repos) {
|
|
306
|
+
for (const author of repo.authors) {
|
|
307
|
+
const login = githubLoginFromEmail(author.email);
|
|
308
|
+
const person = seed.people.find((entry) => (login ? entry.externalIds.includes(`github:${login}`) : entry.emails.includes(author.email)));
|
|
309
|
+
const member = person ? who(person.name) : (byEmail.get(author.email) ?? null);
|
|
310
|
+
if (!member)
|
|
311
|
+
continue;
|
|
312
|
+
const held = commits.get(member.ref) ?? { commits: 0, repos: new Set(), last: author.lastDay, top: repo.name, topCount: 0 };
|
|
313
|
+
held.commits += author.commits;
|
|
314
|
+
held.repos.add(repo.name);
|
|
315
|
+
if (author.lastDay > held.last)
|
|
316
|
+
held.last = author.lastDay;
|
|
317
|
+
if (author.commits > held.topCount) {
|
|
318
|
+
held.topCount = author.commits;
|
|
319
|
+
held.top = repo.name;
|
|
320
|
+
}
|
|
321
|
+
commits.set(member.ref, held);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const [ref, held] of commits) {
|
|
325
|
+
const evidence = { text: `${held.commits} commits across ${held.repos.size} ${held.repos.size === 1 ? "repo" : "repos"} (most to ${held.top}), last on ${held.last}`, src: `record:git:${held.top}` };
|
|
326
|
+
activity.get(ref).push(evidence);
|
|
327
|
+
// Someone who commits a lot and has no title anywhere is at least an engineer. A weak line, for a person to fix.
|
|
328
|
+
if (held.commits >= 50 && roles.get(ref).size === 0)
|
|
329
|
+
offer(roles.get(ref), "engineer", "Engineer", 0.25, "git", { text: `No file states a title. ${evidence.text}`, src: evidence.src });
|
|
330
|
+
}
|
|
331
|
+
for (const attendee of seed.org?.standups.attendance ?? []) {
|
|
332
|
+
const member = who(attendee.name);
|
|
333
|
+
if (member)
|
|
334
|
+
activity.get(member.ref).push({ text: `Listed at ${attendee.notes} standups, ${attendee.firstDay} to ${attendee.lastDay}`, src: attendee.lastSrc });
|
|
335
|
+
}
|
|
336
|
+
const owned = new Map();
|
|
337
|
+
for (const project of seed.boardProjects) {
|
|
338
|
+
const member = project.owner ? who(project.owner) : null;
|
|
339
|
+
if (!member)
|
|
340
|
+
continue;
|
|
341
|
+
const held = owned.get(member.ref) ?? { board: [], prd: [] };
|
|
342
|
+
held.board.push(project.name);
|
|
343
|
+
owned.set(member.ref, held);
|
|
344
|
+
}
|
|
345
|
+
for (const prd of seed.org?.prdOwners ?? []) {
|
|
346
|
+
const member = who(prd.owner);
|
|
347
|
+
if (!member)
|
|
348
|
+
continue;
|
|
349
|
+
const held = owned.get(member.ref) ?? { board: [], prd: [] };
|
|
350
|
+
held.prd.push(prd.project);
|
|
351
|
+
owned.set(member.ref, held);
|
|
352
|
+
}
|
|
353
|
+
for (const [ref, held] of owned) {
|
|
354
|
+
if (held.board.length > 0)
|
|
355
|
+
activity.get(ref).push({ text: `Owns ${held.board.length} board ${held.board.length === 1 ? "project" : "projects"}: ${held.board.slice(0, 4).join(", ")}${held.board.length > 4 ? ", …" : ""}`, src: "doc:board.json" });
|
|
356
|
+
if (held.prd.length > 0)
|
|
357
|
+
activity.get(ref).push({ text: `Owner of ${held.prd.length} ${held.prd.length === 1 ? "PRD" : "PRDs"}: ${held.prd.slice(0, 4).join(", ")}${held.prd.length > 4 ? ", …" : ""}`, src: `doc:projects/${held.prd[0]}/prd.json` });
|
|
358
|
+
}
|
|
359
|
+
// First pass: role and team per person.
|
|
360
|
+
const lines = new Map();
|
|
361
|
+
for (const member of members) {
|
|
362
|
+
const notes = [];
|
|
363
|
+
if (member.personUids.length > 1)
|
|
364
|
+
notes.push(`${member.personUids.length} member accounts in the workspace, treated as one person.`);
|
|
365
|
+
// "Founder" says how someone came to the company, an executive title says what they do. When the files give
|
|
366
|
+
// both, the line proposes both, at the confidence of the weaker one.
|
|
367
|
+
const candidates = roles.get(member.ref);
|
|
368
|
+
const top = pick(candidates);
|
|
369
|
+
// One document that calls someone a CEO is not enough to say so: two or more, or a policy or a people file.
|
|
370
|
+
const executive = [...candidates.values()].filter((candidate) => EXECUTIVE_RE.test(candidate.value) && candidate.conf >= 0.4).sort((a, b) => b.conf - a.conf || (a.value < b.value ? -1 : 1))[0];
|
|
371
|
+
const proposedRole = top && executive && FOUNDER_RE.test(top.value)
|
|
372
|
+
? { ...top, value: `${executive.value}, ${top.value}`, conf: round2(Math.min(top.conf, executive.conf)), evidence: [...executive.evidence.slice(0, 2), ...top.evidence].slice(0, 6), alternatives: top.alternatives.filter((other) => !other.startsWith(`${executive.value} (`)) }
|
|
373
|
+
: top;
|
|
374
|
+
lines.set(member.ref, {
|
|
375
|
+
person: member.ref,
|
|
376
|
+
name: member.name,
|
|
377
|
+
accounts: Math.max(1, member.personUids.length),
|
|
378
|
+
role: proposedRole,
|
|
379
|
+
team: pick(teams.get(member.ref)),
|
|
380
|
+
manager: null,
|
|
381
|
+
activity: activity.get(member.ref),
|
|
382
|
+
notes,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
for (const line of lines.values()) {
|
|
386
|
+
if (line.team)
|
|
387
|
+
line.team.target = `team/${slugify(line.team.value)}`;
|
|
388
|
+
if (!line.role)
|
|
389
|
+
line.notes.push("No file states or suggests a role title.");
|
|
390
|
+
if (!line.team)
|
|
391
|
+
line.notes.push("No file places them in a working group.");
|
|
392
|
+
}
|
|
393
|
+
// Managers: a suggested reporting line, else the person whose title leads the team, else the CEO.
|
|
394
|
+
const ceo = [...lines.values()].filter((line) => line.role && CEO_RE.test(line.role.value));
|
|
395
|
+
const leads = new Map();
|
|
396
|
+
for (const line of lines.values()) {
|
|
397
|
+
const led = line.role ? ledFunction(line.role.value) : null;
|
|
398
|
+
if (led)
|
|
399
|
+
leads.set(led, [...(leads.get(led) ?? []), line]);
|
|
400
|
+
}
|
|
401
|
+
for (const member of members) {
|
|
402
|
+
const line = lines.get(member.ref);
|
|
403
|
+
const candidates = new Map();
|
|
404
|
+
for (const suggestion of seed.orgLayer?.suggestions ?? []) {
|
|
405
|
+
if (!member.personUids.includes(suggestion.reportUid))
|
|
406
|
+
continue;
|
|
407
|
+
const manager = byUid.get(suggestion.managerUid);
|
|
408
|
+
if (!manager || manager.ref === member.ref)
|
|
409
|
+
continue;
|
|
410
|
+
const contradicts = line.role !== null && CEO_RE.test(line.role.value);
|
|
411
|
+
offer(candidates, manager.ref, manager.name, contradicts ? 0.2 : 0.5, "org-layer", {
|
|
412
|
+
text: `The org chart reconciler suggests it (its confidence ${suggestion.confidence.toFixed(2)}, ${suggestion.sources.length === 0 ? "no citation" : `${suggestion.sources.length} cited files`}); nobody has accepted it${contradicts ? `. It contradicts the title "${line.role.value}"` : ""}`,
|
|
413
|
+
src: `record:hq-org-layer:${suggestion.reportUid}`,
|
|
414
|
+
}, manager.ref);
|
|
415
|
+
}
|
|
416
|
+
const teamKey = line.team ? Object.keys(Object.fromEntries(teams.get(member.ref))).find((key) => teams.get(member.ref).get(key).value === line.team.value) : undefined;
|
|
417
|
+
for (const lead of teamKey ? (leads.get(teamKey) ?? []) : []) {
|
|
418
|
+
if (lead.person === member.ref)
|
|
419
|
+
continue;
|
|
420
|
+
offer(candidates, lead.person, lead.name, 0.35, "team-lead", { text: `${lead.name} holds the title "${lead.role.value}", which leads ${line.team.value}. No file names a manager`, src: lead.role.evidence[0].src }, lead.person);
|
|
421
|
+
}
|
|
422
|
+
if (ceo.length === 1 && ceo[0].person !== member.ref) {
|
|
423
|
+
offer(candidates, ceo[0].person, ceo[0].name, 0.25, "default", { text: `No file names a manager. Default: the person with the title "${ceo[0].role.value}"`, src: ceo[0].role.evidence[0].src }, ceo[0].person);
|
|
424
|
+
}
|
|
425
|
+
line.manager = pick(candidates);
|
|
426
|
+
if (!line.manager)
|
|
427
|
+
line.notes.push(ceo.length === 1 && ceo[0].person === member.ref ? "Top of the chart by title: no manager proposed." : "No file names or suggests a manager.");
|
|
428
|
+
}
|
|
429
|
+
return { company: input.company, at: input.now, learned: input.learned, lines: members.map((member) => lines.get(member.ref)) };
|
|
430
|
+
}
|
|
431
|
+
// ---------------------------------------------------------------------------
|
|
432
|
+
// Proposals
|
|
433
|
+
// ---------------------------------------------------------------------------
|
|
434
|
+
const AUDIENCE = "company";
|
|
435
|
+
const DRAFT_ORIGIN = "rule:org-chart-draft";
|
|
436
|
+
function evidenceText(field) {
|
|
437
|
+
return field.evidence.slice(0, 3).map((entry) => entry.text).join("; ");
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* One proposal per proposed line, all in the set `org chart draft`. Each
|
|
441
|
+
* carries the row an accept writes: the proposals package stamps it with the
|
|
442
|
+
* member's own origin, which outranks every other source.
|
|
443
|
+
*/
|
|
444
|
+
export function orgChartProposals(draft) {
|
|
445
|
+
const proposals = [];
|
|
446
|
+
const stamp = (field) => ({ from: draft.learned, src: field.evidence[0].src, learned: draft.learned, by: DRAFT_ORIGIN, conf: field.conf });
|
|
447
|
+
const file = (line, what, field, row) => {
|
|
448
|
+
proposals.push({
|
|
449
|
+
id: proposalId(`org-chart-${what}`, line.person, [normalizeName(field.target ?? field.value)]),
|
|
450
|
+
kind: "retype",
|
|
451
|
+
entity: line.person,
|
|
452
|
+
audience: AUDIENCE,
|
|
453
|
+
rows: [],
|
|
454
|
+
summary: `[${ORG_CHART_SET}] ${line.name}: ${what} "${field.value}" (confidence ${field.conf.toFixed(2)}). ${evidenceText(field)}. Not written.`,
|
|
455
|
+
action: row,
|
|
456
|
+
evidence: sortedUnique(field.evidence.map((entry) => entry.src)).slice(0, 5),
|
|
457
|
+
filedAt: draft.at,
|
|
458
|
+
});
|
|
459
|
+
};
|
|
460
|
+
for (const line of draft.lines) {
|
|
461
|
+
if (line.role)
|
|
462
|
+
file(line, "role", line.role, { type: "write_row", entity: line.person, audience: AUDIENCE, row: factRow("role_title", line.role.value, stamp(line.role)) });
|
|
463
|
+
if (line.team?.target)
|
|
464
|
+
file(line, "team", line.team, { type: "write_row", entity: line.person, audience: AUDIENCE, row: edgeRow("member_of", line.team.target, stamp(line.team)) });
|
|
465
|
+
if (line.manager?.target)
|
|
466
|
+
file(line, "manager", line.manager, { type: "write_row", entity: line.person, audience: AUDIENCE, row: edgeRow("reports_to", line.manager.target, stamp(line.manager)) });
|
|
467
|
+
}
|
|
468
|
+
return proposals.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
469
|
+
}
|
|
470
|
+
// ---------------------------------------------------------------------------
|
|
471
|
+
// The reviewable file
|
|
472
|
+
// ---------------------------------------------------------------------------
|
|
473
|
+
const cell = (value) => value.replace(/\|/g, "/").replace(/\s+/g, " ").trim();
|
|
474
|
+
const confText = (field) => (field ? field.conf.toFixed(2) : "none");
|
|
475
|
+
function strongest(line) {
|
|
476
|
+
const fields = [line.role, line.team, line.manager].filter((field) => field !== null).sort((a, b) => b.conf - a.conf);
|
|
477
|
+
const top = fields[0]?.evidence[0] ?? line.activity[0];
|
|
478
|
+
return top ? `${top.text} (${top.src})` : "No evidence in the files";
|
|
479
|
+
}
|
|
480
|
+
export function renderOrgChartDraft(draft, meta = {}) {
|
|
481
|
+
const out = [];
|
|
482
|
+
out.push(`# Org chart draft (${draft.company})`, "");
|
|
483
|
+
out.push(`Written ${draft.at}. ${draft.lines.length} people. Every line is a proposal from the files. None of it is written to the graph as a fact.`, "");
|
|
484
|
+
for (const line of meta.intro ?? [])
|
|
485
|
+
out.push(line);
|
|
486
|
+
if ((meta.intro ?? []).length > 0)
|
|
487
|
+
out.push("");
|
|
488
|
+
out.push("To correct it: edit the Proposed role, Team and Manager cells in the table. Leave a cell empty, or write `none`, to state nothing. The other columns are not read back.", "");
|
|
489
|
+
out.push("| Person | Proposed role | Team | Manager | Confidence (role / team / manager) | Strongest evidence |");
|
|
490
|
+
out.push("| --- | --- | --- | --- | --- | --- |");
|
|
491
|
+
for (const line of draft.lines) {
|
|
492
|
+
out.push(`| ${cell(line.name)} | ${cell(line.role?.value ?? "")} | ${cell(line.team?.value ?? "")} | ${cell(line.manager?.value ?? "")} | ${confText(line.role)} / ${confText(line.team)} / ${confText(line.manager)} | ${cell(strongest(line))} |`);
|
|
493
|
+
}
|
|
494
|
+
out.push("", "Confidence: 0.90 a people file states it; 0.60 a policy states it, or ten or more documents agree; 0.50 two independent sources, or a suggested reporting line; 0.35 one source; 0.25 a default with nothing behind it.", "");
|
|
495
|
+
out.push("## Evidence per person", "");
|
|
496
|
+
for (const line of draft.lines) {
|
|
497
|
+
out.push(`### ${line.name}`, "");
|
|
498
|
+
const field = (label, value) => {
|
|
499
|
+
if (!value)
|
|
500
|
+
return;
|
|
501
|
+
out.push(`- ${label}: ${value.value} (${value.conf.toFixed(2)})${value.alternatives.length > 0 ? `. Also seen: ${value.alternatives.join(", ")}` : ""}`);
|
|
502
|
+
for (const entry of value.evidence.slice(0, 4))
|
|
503
|
+
out.push(` - ${entry.text} (\`${entry.src}\`)`);
|
|
504
|
+
};
|
|
505
|
+
field("Role", line.role);
|
|
506
|
+
field("Team", line.team);
|
|
507
|
+
field("Manager", line.manager);
|
|
508
|
+
for (const entry of line.activity.slice(0, 4))
|
|
509
|
+
out.push(`- Activity: ${entry.text} (\`${entry.src}\`)`);
|
|
510
|
+
for (const note of line.notes)
|
|
511
|
+
out.push(`- Note: ${note}`);
|
|
512
|
+
out.push("");
|
|
513
|
+
}
|
|
514
|
+
return out.join("\n");
|
|
515
|
+
}
|
|
516
|
+
const blank = (value) => (/^(?:none|n\/a|-|—|\?)?$/i.test(value.trim()) ? "" : value.trim());
|
|
517
|
+
/** Reads the table back from the draft file after a person edited it. Only the first four columns are read. */
|
|
518
|
+
export function parseOrgChartDraft(markdown) {
|
|
519
|
+
const rows = [];
|
|
520
|
+
let inTable = false;
|
|
521
|
+
for (const line of markdown.split("\n")) {
|
|
522
|
+
const trimmed = line.trim();
|
|
523
|
+
if (!trimmed.startsWith("|")) {
|
|
524
|
+
if (inTable)
|
|
525
|
+
break;
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
const cells = trimmed.replace(/^\||\|$/g, "").split("|").map((value) => value.trim());
|
|
529
|
+
if (!inTable) {
|
|
530
|
+
inTable = normalizeName(cells[0] ?? "") === "person";
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (cells.every((value) => /^:?-+:?$/.test(value) || value === ""))
|
|
534
|
+
continue;
|
|
535
|
+
const name = cells[0] ?? "";
|
|
536
|
+
if (name === "")
|
|
537
|
+
continue;
|
|
538
|
+
rows.push({ name, role: blank(cells[1] ?? ""), team: blank(cells[2] ?? ""), manager: blank(cells[3] ?? "") });
|
|
539
|
+
}
|
|
540
|
+
return rows;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* The text of `people/org-chart.yaml` for the rows a person confirmed. The
|
|
544
|
+
* seed reads that file on every run and writes each line as origin
|
|
545
|
+
* `human:<confirmedBy>`, so a confirmed line outranks every other source and
|
|
546
|
+
* is written again by every rebuild.
|
|
547
|
+
*/
|
|
548
|
+
export function orgChartYaml(rows, confirmedBy, confirmedOn) {
|
|
549
|
+
const people = rows
|
|
550
|
+
.filter((row) => row.role !== "" || row.team !== "" || row.manager !== "")
|
|
551
|
+
.map((row) => ({ name: row.name, ...(row.role ? { role: row.role } : {}), ...(row.team ? { team: row.team } : {}), ...(row.manager ? { manager: row.manager } : {}) }));
|
|
552
|
+
const header = ["# The org chart a person confirmed. Read by `hq ontology rebuild` and `update` on every run.", "# Each line is written to the ontology graph as that person's own statement (origin human).", ""].join("\n");
|
|
553
|
+
return header + yaml.dump({ confirmed_by: confirmedBy, confirmed_on: confirmedOn, people }, { lineWidth: 120, noRefs: true });
|
|
554
|
+
}
|
|
555
|
+
/** Reads `people/org-chart.yaml`. Null when the file is absent or names no person uid: an unsigned file states nothing. */
|
|
556
|
+
export function readConfirmedOrgChart(companyRoot) {
|
|
557
|
+
let loaded;
|
|
558
|
+
try {
|
|
559
|
+
loaded = yaml.load(fs.readFileSync(path.join(companyRoot, ...ORG_CHART_FILE.split("/")), "utf8"), { schema: yaml.CORE_SCHEMA });
|
|
560
|
+
}
|
|
561
|
+
catch {
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
if (!loaded || typeof loaded !== "object" || Array.isArray(loaded))
|
|
565
|
+
return null;
|
|
566
|
+
const record = loaded;
|
|
567
|
+
const confirmedBy = typeof record.confirmed_by === "string" ? record.confirmed_by.trim() : "";
|
|
568
|
+
const confirmedOn = typeof record.confirmed_on === "string" ? record.confirmed_on.trim() : record.confirmed_on instanceof Date ? record.confirmed_on.toISOString().slice(0, 10) : "";
|
|
569
|
+
if (!/^prs_[0-9A-Za-z]+$/.test(confirmedBy) || !/^\d{4}-\d{2}-\d{2}$/.test(confirmedOn))
|
|
570
|
+
return null;
|
|
571
|
+
const text = (value) => (typeof value === "string" ? value.trim() : "");
|
|
572
|
+
const people = (Array.isArray(record.people) ? record.people : [])
|
|
573
|
+
.map((entry) => (entry && typeof entry === "object" ? entry : {}))
|
|
574
|
+
.map((entry) => ({ name: text(entry.name), role: text(entry.role), team: text(entry.team), manager: text(entry.manager) }))
|
|
575
|
+
.filter((row) => row.name !== "");
|
|
576
|
+
return { confirmedBy, confirmedOn, people };
|
|
577
|
+
}
|
|
578
|
+
//# sourceMappingURL=org-chart.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { GraphContext, IsoDate, IsoTimestamp } from "../types.js";
|
|
2
|
+
export declare const ORG_LAYER_CACHE = ".state/org-layer.json";
|
|
3
|
+
/** What the service answered, kept as it came, with when and for which company. */
|
|
4
|
+
export interface OrgLayerSnapshot {
|
|
5
|
+
schema: 1;
|
|
6
|
+
company: string;
|
|
7
|
+
companyUid: string;
|
|
8
|
+
fetchedAt: IsoTimestamp;
|
|
9
|
+
/** Body of `GET /v1/org-layer/graph`: edges, nodes, okrRows, suggestions. */
|
|
10
|
+
graph: unknown;
|
|
11
|
+
/** Body of `GET /v1/org-layer/graph/aggregate` (member names and emails), or null when that call failed. */
|
|
12
|
+
aggregate: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface OrgLayerEdge {
|
|
15
|
+
managerUid: string;
|
|
16
|
+
reportUid: string;
|
|
17
|
+
relation: "reports-to" | "speaks-for";
|
|
18
|
+
/** True when a person set the line (`origin: human-set`). */
|
|
19
|
+
human: boolean;
|
|
20
|
+
/** Person uid of who set it, when the service names one. */
|
|
21
|
+
setBy: string;
|
|
22
|
+
day: IsoDate | null;
|
|
23
|
+
}
|
|
24
|
+
export interface OrgLayerMember {
|
|
25
|
+
uid: string;
|
|
26
|
+
name: string;
|
|
27
|
+
email: string;
|
|
28
|
+
kind: "human" | "agent";
|
|
29
|
+
/** The workspace role (owner, admin, member, guest). Not a job title. */
|
|
30
|
+
membershipRole: string;
|
|
31
|
+
}
|
|
32
|
+
export interface OrgLayerSuggestion {
|
|
33
|
+
managerUid: string;
|
|
34
|
+
reportUid: string;
|
|
35
|
+
confidence: number;
|
|
36
|
+
/** Vault paths the reconciler cited. */
|
|
37
|
+
sources: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface OrgLayerSeed {
|
|
40
|
+
fetchedAt: IsoTimestamp;
|
|
41
|
+
edges: OrgLayerEdge[];
|
|
42
|
+
members: OrgLayerMember[];
|
|
43
|
+
/** Reporting lines the reconciler suggested and nobody has accepted. */
|
|
44
|
+
suggestions: OrgLayerSuggestion[];
|
|
45
|
+
}
|
|
46
|
+
export interface OrgLayerFetchResult {
|
|
47
|
+
companyUid: string;
|
|
48
|
+
graph: unknown;
|
|
49
|
+
aggregate: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** Reads the org layer for a company slug. Throws when it cannot. */
|
|
52
|
+
export type OrgLayerFetcher = (company: string) => Promise<OrgLayerFetchResult>;
|
|
53
|
+
/**
|
|
54
|
+
* The default fetcher: the CLI's signed-in person session and its vault API
|
|
55
|
+
* client. It never opens a browser sign-in (a member who is signed out gets an
|
|
56
|
+
* error, and the caller falls back to the kept answer).
|
|
57
|
+
*/
|
|
58
|
+
export declare const signedInOrgLayerFetcher: OrgLayerFetcher;
|
|
59
|
+
export declare function readOrgLayerCache(graphRoot: string): OrgLayerSnapshot | null;
|
|
60
|
+
export interface RefreshOrgLayerResult {
|
|
61
|
+
/** `fetched`: read from the service and kept. `cached`: the service could not be read and a kept answer exists. `unavailable`: neither. */
|
|
62
|
+
status: "fetched" | "cached" | "unavailable";
|
|
63
|
+
/** Why the service could not be read. Never holds a token. */
|
|
64
|
+
reason?: string;
|
|
65
|
+
fetchedAt?: IsoTimestamp;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reads the org layer and keeps it under the graph root. On any failure the
|
|
69
|
+
* kept answer stays as it was. The error text is cut to its first line and to
|
|
70
|
+
* 200 characters, so a response body never reaches a log.
|
|
71
|
+
*/
|
|
72
|
+
export declare function refreshOrgLayerCache(context: Pick<GraphContext, "company" | "graphRoot">, options?: {
|
|
73
|
+
fetcher?: OrgLayerFetcher;
|
|
74
|
+
now?: IsoTimestamp;
|
|
75
|
+
}): Promise<RefreshOrgLayerResult>;
|
|
76
|
+
/** Turns a kept answer into seed input. Rows that do not name two member ids are left out. */
|
|
77
|
+
export declare function parseOrgLayer(snapshot: OrgLayerSnapshot | null): OrgLayerSeed | null;
|
|
78
|
+
//# sourceMappingURL=org-layer.d.ts.map
|