@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,1251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-B input readers: one per source class in the corpus manifest. Each class
|
|
3
|
+
* lists dated inputs for one member and reads one input into a document.
|
|
4
|
+
*
|
|
5
|
+
* Scope (correction C2) is decided at listing time, so an input the member may
|
|
6
|
+
* not read is never returned and never opened for reading:
|
|
7
|
+
* - company classes are listed for everyone;
|
|
8
|
+
* - per-audience folders and sources are listed only for keys the member holds;
|
|
9
|
+
* - personal classes are listed only when the member owns the file. Ownership
|
|
10
|
+
* of a DM file is its `person_uid` frontmatter line; the check reads that one
|
|
11
|
+
* line from the first 4 KB and nothing else.
|
|
12
|
+
*
|
|
13
|
+
* Listing reads frontmatter only. Bodies are read once, when the day is replayed.
|
|
14
|
+
*
|
|
15
|
+
* Every read the listing makes goes through the listing manifest
|
|
16
|
+
* (listing-manifest.ts): with a manifest from an earlier run, a file whose size
|
|
17
|
+
* and mtime are unchanged is not opened again, and a `git log` is not run
|
|
18
|
+
* again for a repo whose HEAD has not moved. The listing code is the same on
|
|
19
|
+
* both paths, so both return the same inputs.
|
|
20
|
+
*/
|
|
21
|
+
import { execFileSync } from "node:child_process";
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
|
+
import * as fs from "node:fs";
|
|
24
|
+
import * as path from "node:path";
|
|
25
|
+
import { slugify } from "../schema/index.js";
|
|
26
|
+
import { loadReplayConfig, otherCompanyRepoDirs } from "./config.js";
|
|
27
|
+
import { gitHeadCommit, openListingManifest } from "./listing-manifest.js";
|
|
28
|
+
import { audienceForInput, companyScopesIn, namesAnotherCompany, weekEnd, weekStart } from "./rules.js";
|
|
29
|
+
import { resolveMemberScope, toAudienceKey } from "./scope.js";
|
|
30
|
+
import { readTranscripts } from "./transcripts.js";
|
|
31
|
+
import { asList, asRecord, asString, byCodeUnit, firstDay, isCopyName, listFiles, listFolders, mtimeDay, probeFrontmatterKey, readFrontmatterOnly, readJsonFile, readYamlFile, splitFrontmatter, stringList, toDay, walkFiles, } from "./util.js";
|
|
32
|
+
/** `2026-08-06-hq-dev-standup-ff4acd73`: stable from the day, the title and the source id. */
|
|
33
|
+
export function meetingSlug(day, title, sourceId) {
|
|
34
|
+
const id = slugify(sourceId).slice(0, 8) || "meeting";
|
|
35
|
+
const name = slugify(title).slice(0, 48).replace(/-+$/g, "");
|
|
36
|
+
return [day ?? "undated", name, id].filter((part) => part !== "").join("-");
|
|
37
|
+
}
|
|
38
|
+
function signalRef(id) {
|
|
39
|
+
const hex = id.toLowerCase();
|
|
40
|
+
return /^[0-9a-f]{12,}$/.test(hex) ? `signal:${hex.slice(0, 12)}` : null;
|
|
41
|
+
}
|
|
42
|
+
/** Git first-add day per path, from one `git log` over the given folders. */
|
|
43
|
+
function gitFirstAddDays(repoRoot, pathspecs, since = null) {
|
|
44
|
+
const added = new Map();
|
|
45
|
+
let output;
|
|
46
|
+
try {
|
|
47
|
+
output = execFileSync("git", ["-C", repoRoot, "log", "--diff-filter=A", "--name-only", "--no-renames", "--format=@%aI", ...(since ? [`${since}..HEAD`] : []), "--", ...pathspecs], { encoding: "utf8", maxBuffer: 512 * 1024 * 1024, stdio: ["ignore", "pipe", "ignore"], timeout: 180_000 });
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// With a range: the old commit is gone (history was rewritten), so the caller asks for everything.
|
|
51
|
+
return since ? null : added;
|
|
52
|
+
}
|
|
53
|
+
let day = null;
|
|
54
|
+
for (const line of output.split("\n")) {
|
|
55
|
+
if (line.startsWith("@"))
|
|
56
|
+
day = toDay(line.slice(1));
|
|
57
|
+
else if (line !== "" && day) {
|
|
58
|
+
const known = added.get(line);
|
|
59
|
+
if (!known || day < known)
|
|
60
|
+
added.set(line, day);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return added;
|
|
64
|
+
}
|
|
65
|
+
function originOf(repoDir) {
|
|
66
|
+
let text;
|
|
67
|
+
try {
|
|
68
|
+
if (!fs.statSync(path.join(repoDir, ".git")).isDirectory())
|
|
69
|
+
return null;
|
|
70
|
+
text = fs.readFileSync(path.join(repoDir, ".git", "config"), "utf8");
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const section = /\[remote "origin"\]([^[]*)/.exec(text);
|
|
76
|
+
const url = section ? /^\s*url\s*=\s*(\S+)/m.exec(section[1])?.[1] : undefined;
|
|
77
|
+
if (!url)
|
|
78
|
+
return null;
|
|
79
|
+
const match = /[:/]([^/:@]+)\/([^/]+?)(?:\.git)?\/?$/.exec(url);
|
|
80
|
+
if (!match)
|
|
81
|
+
return null;
|
|
82
|
+
return { owner: match[1].toLowerCase(), name: match[2], url: `${match[1].toLowerCase()}/${match[2].toLowerCase()}` };
|
|
83
|
+
}
|
|
84
|
+
/** The commit a ref names, read from the clone's files: a loose ref, a symbolic ref, or a line of packed-refs. */
|
|
85
|
+
function readGitRef(gitDir, ref, depth = 0) {
|
|
86
|
+
if (depth > 4 || ref.includes(".."))
|
|
87
|
+
return null;
|
|
88
|
+
try {
|
|
89
|
+
const loose = fs.readFileSync(path.join(gitDir, ...ref.split("/")), "utf8").trim();
|
|
90
|
+
if (/^[0-9a-f]{40,64}$/.test(loose))
|
|
91
|
+
return loose;
|
|
92
|
+
const target = /^ref:\s*(\S+)$/.exec(loose)?.[1];
|
|
93
|
+
if (target)
|
|
94
|
+
return readGitRef(gitDir, target, depth + 1);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// not a loose ref: look in packed-refs
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
for (const line of fs.readFileSync(path.join(gitDir, "packed-refs"), "utf8").split("\n")) {
|
|
101
|
+
const [sha, name] = line.split(" ");
|
|
102
|
+
if (name === ref && /^[0-9a-f]{40,64}$/.test(sha ?? ""))
|
|
103
|
+
return sha;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// no packed refs
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The commit whose history says what happened in a repo: the remote's default
|
|
113
|
+
* branch as last fetched. A clone's own HEAD is whatever branch someone left
|
|
114
|
+
* checked out, often months behind, so it is used only when the clone has no
|
|
115
|
+
* remote default branch.
|
|
116
|
+
*/
|
|
117
|
+
function historyCommit(repoDir) {
|
|
118
|
+
const gitDir = path.join(repoDir, ".git");
|
|
119
|
+
for (const ref of ["refs/remotes/origin/HEAD", "refs/remotes/origin/main", "refs/remotes/origin/master"]) {
|
|
120
|
+
const sha = readGitRef(gitDir, ref);
|
|
121
|
+
if (sha)
|
|
122
|
+
return sha;
|
|
123
|
+
}
|
|
124
|
+
return gitHeadCommit(repoDir);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The company's clones: the folders named for it, plus every clone under the
|
|
128
|
+
* repo roots whose remote owner is one of the company's. A clone the manifest
|
|
129
|
+
* lists for another company is never taken, by folder or by origin, whoever
|
|
130
|
+
* its remote owner is: two companies can keep repos under one GitHub owner.
|
|
131
|
+
* With no readable manifest nothing is found by owner.
|
|
132
|
+
*/
|
|
133
|
+
function discoverRepos(context, config) {
|
|
134
|
+
const listedElsewhere = otherCompanyRepoDirs(context.hqRoot, context.company);
|
|
135
|
+
const otherDirs = new Set(listedElsewhere ?? []);
|
|
136
|
+
const otherOrigins = new Set();
|
|
137
|
+
for (const dir of otherDirs) {
|
|
138
|
+
const origin = originOf(dir);
|
|
139
|
+
if (origin)
|
|
140
|
+
otherOrigins.add(origin.url);
|
|
141
|
+
}
|
|
142
|
+
const isOther = (dir, origin) => otherDirs.has(dir) || (origin !== null && otherOrigins.has(origin.url));
|
|
143
|
+
const named = config.git.repos.map((relative) => path.resolve(context.hqRoot, relative));
|
|
144
|
+
const owners = new Set(listedElsewhere === null ? [] : config.git.remoteOwners);
|
|
145
|
+
if (owners.size === 0 && listedElsewhere !== null) {
|
|
146
|
+
for (const dir of named) {
|
|
147
|
+
const origin = originOf(dir);
|
|
148
|
+
if (origin && !isOther(dir, origin))
|
|
149
|
+
owners.add(origin.owner);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const byOrigin = new Map();
|
|
153
|
+
const ownDirs = new Set();
|
|
154
|
+
let excluded = 0;
|
|
155
|
+
const consider = (dir) => {
|
|
156
|
+
const origin = originOf(dir);
|
|
157
|
+
const wanted = named.includes(dir) || (origin !== null && owners.has(origin.owner));
|
|
158
|
+
if (!wanted)
|
|
159
|
+
return;
|
|
160
|
+
if (isOther(dir, origin)) {
|
|
161
|
+
excluded += 1;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
ownDirs.add(dir);
|
|
165
|
+
if (!origin || byOrigin.has(origin.url))
|
|
166
|
+
return;
|
|
167
|
+
byOrigin.set(origin.url, { name: origin.name, dir });
|
|
168
|
+
};
|
|
169
|
+
for (const dir of named)
|
|
170
|
+
consider(dir);
|
|
171
|
+
// Every clone under the repo roots is looked at, so that a worktree record can be checked against all of them.
|
|
172
|
+
const unknownClones = new Set();
|
|
173
|
+
for (const root of config.git.repoRoots) {
|
|
174
|
+
const base = path.resolve(context.hqRoot, root);
|
|
175
|
+
for (const folder of listFolders(base)) {
|
|
176
|
+
const dir = path.join(base, folder);
|
|
177
|
+
if (named.includes(dir))
|
|
178
|
+
continue;
|
|
179
|
+
consider(dir);
|
|
180
|
+
if (!otherDirs.has(dir))
|
|
181
|
+
unknownClones.add(dir);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const worktreeRecords = [];
|
|
185
|
+
const record = (clone, side) => {
|
|
186
|
+
for (const folder of worktreesOf(clone))
|
|
187
|
+
worktreeRecords.push({ folder, clone, side });
|
|
188
|
+
};
|
|
189
|
+
for (const dir of named)
|
|
190
|
+
record(dir, isOther(dir, originOf(dir)) ? "other" : "own");
|
|
191
|
+
for (const dir of otherDirs)
|
|
192
|
+
if (!named.includes(dir))
|
|
193
|
+
record(dir, "other");
|
|
194
|
+
for (const dir of unknownClones)
|
|
195
|
+
record(dir, originOf(dir) !== null && otherOrigins.has(originOf(dir).url) ? "other" : "unknown");
|
|
196
|
+
const otherPaths = new Set();
|
|
197
|
+
const hqRoot = path.resolve(context.hqRoot);
|
|
198
|
+
for (const dir of otherDirs) {
|
|
199
|
+
for (const folder of [dir, ...worktreesOf(dir)]) {
|
|
200
|
+
otherPaths.add(folder.split(path.sep).join("/").toLowerCase());
|
|
201
|
+
const relative = path.relative(hqRoot, folder);
|
|
202
|
+
if (relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative))
|
|
203
|
+
otherPaths.add(relative.split(path.sep).join("/").toLowerCase());
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
repos: [...byOrigin.values()].sort((a, b) => byCodeUnit(a.name, b.name)),
|
|
208
|
+
ownDirs,
|
|
209
|
+
ownOrigins: new Set(byOrigin.keys()),
|
|
210
|
+
otherDirs,
|
|
211
|
+
otherOrigins,
|
|
212
|
+
otherPaths: [...otherPaths].sort(),
|
|
213
|
+
worktreeRecords,
|
|
214
|
+
excluded,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** The clone a folder is the top of: itself, or for a linked worktree the clone it was added from. */
|
|
218
|
+
function cloneAt(dir) {
|
|
219
|
+
const dotGit = path.join(dir, ".git");
|
|
220
|
+
let stat;
|
|
221
|
+
try {
|
|
222
|
+
stat = fs.statSync(dotGit);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
if (stat.isDirectory())
|
|
228
|
+
return dir;
|
|
229
|
+
try {
|
|
230
|
+
const target = /^gitdir:\s*(.+)$/m.exec(fs.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
231
|
+
const main = target ? /^(.*)[\\/]\.git[\\/]worktrees[\\/][^\\/]+[\\/]?$/.exec(path.resolve(dir, target))?.[1] : undefined;
|
|
232
|
+
// A `.git` file that names no clone (a submodule, a broken link) still marks a clone of its own.
|
|
233
|
+
return main ?? dir;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return dir;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/** The folders of a clone's linked worktrees, read from `.git/worktrees/<name>/gitdir`. */
|
|
240
|
+
function worktreesOf(clone) {
|
|
241
|
+
const base = path.join(clone, ".git", "worktrees");
|
|
242
|
+
const found = [];
|
|
243
|
+
for (const name of listFolders(base)) {
|
|
244
|
+
try {
|
|
245
|
+
const gitFile = fs.readFileSync(path.join(base, name, "gitdir"), "utf8").trim();
|
|
246
|
+
if (gitFile !== "")
|
|
247
|
+
found.push(path.dirname(path.resolve(base, name, gitFile)));
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// a worktree record with no gitdir file
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return found;
|
|
254
|
+
}
|
|
255
|
+
function inside(parent, child) {
|
|
256
|
+
const relative = path.relative(parent, child);
|
|
257
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Places a working directory that lies in no clone on disk, most often a
|
|
261
|
+
* worktree that was removed after the session. One thing proves whose repo it
|
|
262
|
+
* was: git's own record of the worktree (`.git/worktrees/<name>/gitdir`, kept
|
|
263
|
+
* until `git worktree prune`). A folder's name proves nothing.
|
|
264
|
+
*
|
|
265
|
+
* The record counts only when it cannot be about anything else:
|
|
266
|
+
* - a record of a clone another company lists makes the folder that company's;
|
|
267
|
+
* - otherwise every record that covers the folder has to belong to one clone,
|
|
268
|
+
* and that clone has to be a repo named for this company. Two clones that
|
|
269
|
+
* both record the folder mean the path was used again, and a clone that is
|
|
270
|
+
* only known by its remote owner is not proof;
|
|
271
|
+
* - the recorded folder has to be gone. If something is at that path again
|
|
272
|
+
* the record is about an earlier folder, not this one.
|
|
273
|
+
*
|
|
274
|
+
* Null when nothing proves it. Isolation comes first: an unplaced folder
|
|
275
|
+
* leaves its session out.
|
|
276
|
+
*/
|
|
277
|
+
function goneWorktreePlace(repos, dir) {
|
|
278
|
+
const records = repos.worktreeRecords.filter((entry) => inside(entry.folder, dir));
|
|
279
|
+
if (records.length === 0)
|
|
280
|
+
return null;
|
|
281
|
+
if (records.some((entry) => entry.side === "other"))
|
|
282
|
+
return "other";
|
|
283
|
+
if (new Set(records.map((entry) => entry.clone)).size !== 1 || records.some((entry) => entry.side !== "own"))
|
|
284
|
+
return null;
|
|
285
|
+
if (records.some((entry) => fs.existsSync(entry.folder)))
|
|
286
|
+
return null;
|
|
287
|
+
return "own";
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Places one working directory. The folder and its parents are tried in turn,
|
|
291
|
+
* up to the first clone found. A folder that no longer exists is placed only
|
|
292
|
+
* when it lies under a folder known to be a repo of this or another company.
|
|
293
|
+
*/
|
|
294
|
+
function placeCwd(context, repos, start, known) {
|
|
295
|
+
const cached = known.get(start);
|
|
296
|
+
if (cached !== undefined)
|
|
297
|
+
return cached;
|
|
298
|
+
const hqRoot = path.resolve(context.hqRoot);
|
|
299
|
+
const listed = (dir) => (repos.otherDirs.has(dir) ? "other" : repos.ownDirs.has(dir) ? "own" : null);
|
|
300
|
+
const walk = () => {
|
|
301
|
+
let dir = path.resolve(start);
|
|
302
|
+
if (dir === hqRoot)
|
|
303
|
+
return "hq";
|
|
304
|
+
for (let depth = 0; depth < 40; depth += 1) {
|
|
305
|
+
const byFolder = listed(dir);
|
|
306
|
+
if (byFolder)
|
|
307
|
+
return byFolder;
|
|
308
|
+
// The HQ root is a clone too, of nobody's repo: reaching it means no repo was found on the way.
|
|
309
|
+
if (dir === hqRoot)
|
|
310
|
+
break;
|
|
311
|
+
const clone = cloneAt(dir);
|
|
312
|
+
if (clone) {
|
|
313
|
+
const origin = originOf(clone);
|
|
314
|
+
if (origin && repos.otherOrigins.has(origin.url))
|
|
315
|
+
return "other";
|
|
316
|
+
return listed(clone) ?? (origin && repos.ownOrigins.has(origin.url) ? "own" : "elsewhere");
|
|
317
|
+
}
|
|
318
|
+
const parent = path.dirname(dir);
|
|
319
|
+
if (parent === dir)
|
|
320
|
+
break;
|
|
321
|
+
dir = parent;
|
|
322
|
+
}
|
|
323
|
+
// Not in any clone: the company's own folder is the company's.
|
|
324
|
+
if (inside(path.resolve(context.companyRoot), path.resolve(start)))
|
|
325
|
+
return "company";
|
|
326
|
+
// A worktree folder that is gone can still be placed when something proves whose repo it was.
|
|
327
|
+
return goneWorktreePlace(repos, path.resolve(start)) ?? "elsewhere";
|
|
328
|
+
};
|
|
329
|
+
const place = walk();
|
|
330
|
+
known.set(start, place);
|
|
331
|
+
return place;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* True when the text holds the path of a repo the manifest lists for another
|
|
335
|
+
* company, or of one of that clone's linked worktrees: as an absolute path, or
|
|
336
|
+
* relative to the HQ root. Letter case is not told apart, since the file
|
|
337
|
+
* systems these paths live on do not tell it apart either.
|
|
338
|
+
*/
|
|
339
|
+
function mentionsOtherCompanyRepo(text, repos) {
|
|
340
|
+
if (repos.otherPaths.length === 0)
|
|
341
|
+
return false;
|
|
342
|
+
const lower = text.toLowerCase().replace(/\\/g, "/");
|
|
343
|
+
for (const needle of repos.otherPaths) {
|
|
344
|
+
for (let at = lower.indexOf(needle); at >= 0; at = lower.indexOf(needle, at + 1)) {
|
|
345
|
+
const before = at === 0 ? "" : lower[at - 1];
|
|
346
|
+
const after = lower[at + needle.length] ?? "";
|
|
347
|
+
if (!/[a-z0-9_.-]/.test(before) && !/[a-z0-9_-]/.test(after))
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
export function scanCorpus(context, options = {}) {
|
|
354
|
+
const started = Date.now();
|
|
355
|
+
const config = options.config ?? loadReplayConfig(context);
|
|
356
|
+
const scope = options.scope ?? resolveMemberScope(context, config);
|
|
357
|
+
const root = context.companyRoot;
|
|
358
|
+
const stats = { listed: {}, excluded: {}, classMs: {}, scanMs: 0, filesRead: 0, filesReused: 0, filesWithheldKnown: 0, gitRuns: 0, gitReused: 0 };
|
|
359
|
+
const exclude = (reason) => void (stats.excluded[reason] = (stats.excluded[reason] ?? 0) + 1);
|
|
360
|
+
const abs = (relative) => path.join(root, ...relative.split("/"));
|
|
361
|
+
/** The company's clones and the ones the manifest gives to another company, found once per scan. */
|
|
362
|
+
let foundRepos = null;
|
|
363
|
+
const repoScope = () => (foundRepos ??= discoverRepos(context, config));
|
|
364
|
+
// ---- listing manifest: what an earlier run learned from each file, kept by size and mtime ----
|
|
365
|
+
// Tied to the member and the keys they hold: a manifest kept for anyone else is not used.
|
|
366
|
+
const manifestScope = createHash("sha256").update(JSON.stringify([context.company, scope.personUid, [...scope.keys].sort()])).digest("hex").slice(0, 16);
|
|
367
|
+
const manifest = options.manifest ?? openListingManifest({ file: options.manifestFile ?? null, reuse: Boolean(options.incremental), scope: manifestScope });
|
|
368
|
+
/** The member may not read this file: nothing about it stays in the manifest. */
|
|
369
|
+
const withheld = (relative) => manifest.forget(abs(relative));
|
|
370
|
+
/** The manifest section answers are kept under: the class being listed, or a shared section. */
|
|
371
|
+
let section = "shared";
|
|
372
|
+
const inSection = (name, run) => {
|
|
373
|
+
const outer = section;
|
|
374
|
+
section = name;
|
|
375
|
+
manifest.visit(name);
|
|
376
|
+
try {
|
|
377
|
+
return run();
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
section = outer;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
/** One question about one file, answered from the manifest when the file is unchanged. */
|
|
384
|
+
const kept = (op, file, compute) => manifest.file(section, op, file, compute);
|
|
385
|
+
/** Frontmatter of a file under the company folder. */
|
|
386
|
+
const frontmatterOf = (relative) => kept("fm", abs(relative), () => readFrontmatterOnly(abs(relative)).frontmatter);
|
|
387
|
+
const probeOf = (relative, key) => kept(`probe:${key}`, abs(relative), () => probeFrontmatterKey(abs(relative), key));
|
|
388
|
+
// ---- sources catalog: day, audience and title of every file under sources/ ----
|
|
389
|
+
const sources = new Map();
|
|
390
|
+
let catalogBuilt = false;
|
|
391
|
+
const buildCatalog = () => {
|
|
392
|
+
if (catalogBuilt)
|
|
393
|
+
return;
|
|
394
|
+
catalogBuilt = true;
|
|
395
|
+
inSection("sources.catalog", fillCatalog);
|
|
396
|
+
};
|
|
397
|
+
const fillCatalog = () => {
|
|
398
|
+
for (const name of listFiles(abs("sources/meetings"), ".md")) {
|
|
399
|
+
const rel = `sources/meetings/${name}`;
|
|
400
|
+
const frontmatter = frontmatterOf(rel);
|
|
401
|
+
const id = asString(frontmatter.source_id) || name.replace(/\.md$/, "");
|
|
402
|
+
const day = firstDay(frontmatter.scheduled_start_time, frontmatter.created_at, frontmatter.ingested_at);
|
|
403
|
+
const title = asString(frontmatter.title) || "Meeting";
|
|
404
|
+
const sidecarFile = abs(`sources/meetings/${id}.audience.json`);
|
|
405
|
+
const sidecar = asRecord(kept("json", sidecarFile, () => readJsonFile(sidecarFile)));
|
|
406
|
+
const key = toAudienceKey(frontmatter.audience_key) ?? toAudienceKey(sidecar.audienceKey);
|
|
407
|
+
let audience = "company";
|
|
408
|
+
if (key && key !== "company") {
|
|
409
|
+
const invited = stringList(sidecar.invitedMemberUids);
|
|
410
|
+
const allowed = scope.holds(key) || scope.owns(frontmatter.person_uid) || invited.some((uid) => scope.owns(uid));
|
|
411
|
+
audience = allowed ? key : null;
|
|
412
|
+
}
|
|
413
|
+
if (audience === null) {
|
|
414
|
+
withheld(rel);
|
|
415
|
+
manifest.forget(sidecarFile);
|
|
416
|
+
}
|
|
417
|
+
sources.set(rel, { day, audience, channel: "meeting", title, entity: `meeting/${meetingSlug(day, title, id)}` });
|
|
418
|
+
}
|
|
419
|
+
for (const name of listFiles(abs("sources/slack"), ".md")) {
|
|
420
|
+
const rel = `sources/slack/${name}`;
|
|
421
|
+
const frontmatter = frontmatterOf(rel);
|
|
422
|
+
sources.set(rel, {
|
|
423
|
+
day: firstDay(frontmatter.first_message_at, frontmatter.last_message_at, frontmatter.ingested_at),
|
|
424
|
+
audience: "company",
|
|
425
|
+
channel: "slack",
|
|
426
|
+
title: asString(frontmatter.title),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
for (const name of listFiles(abs("sources/slack-dm"), ".md")) {
|
|
430
|
+
const rel = `sources/slack-dm/${name}`;
|
|
431
|
+
// Another person's DM an earlier run already recognised, unchanged since: not opened again.
|
|
432
|
+
if (manifest.withheldReason(abs(rel))) {
|
|
433
|
+
sources.set(rel, { day: null, audience: null, channel: "slack-dm", title: "", foreign: true });
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
// Ownership first, from one frontmatter line. Another person's DM stops here.
|
|
437
|
+
const owner = probeOf(rel, "person_uid");
|
|
438
|
+
if (!owner || !scope.owns(owner) || !scope.personalKey) {
|
|
439
|
+
const foreign = Boolean(owner) && !scope.owns(owner);
|
|
440
|
+
// Whose DM it is cannot change while the file does not: remembered by hash, never by path.
|
|
441
|
+
if (foreign)
|
|
442
|
+
manifest.withhold(abs(rel), "personal_not_owner");
|
|
443
|
+
else
|
|
444
|
+
withheld(rel);
|
|
445
|
+
sources.set(rel, { day: null, audience: null, channel: "slack-dm", title: "", ...(owner ? { owner } : {}), ...(foreign ? { foreign } : {}) });
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const frontmatter = frontmatterOf(rel);
|
|
449
|
+
sources.set(rel, {
|
|
450
|
+
day: firstDay(frontmatter.first_message_at, frontmatter.last_message_at, frontmatter.ingested_at),
|
|
451
|
+
audience: scope.personalKey,
|
|
452
|
+
channel: "slack-dm",
|
|
453
|
+
title: asString(frontmatter.title),
|
|
454
|
+
owner,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
const sourceEntry = (ref) => {
|
|
459
|
+
buildCatalog();
|
|
460
|
+
return sources.get(ref);
|
|
461
|
+
};
|
|
462
|
+
/** True when the source is in this vault and the member may read it. */
|
|
463
|
+
const readable = (ref) => {
|
|
464
|
+
const entry = sourceEntry(ref);
|
|
465
|
+
return entry !== undefined && entry.audience !== null;
|
|
466
|
+
};
|
|
467
|
+
// ---- signals index: written_at and source_ref by signal id, without opening signal files ----
|
|
468
|
+
let signalIndex = null;
|
|
469
|
+
const signalIndexEntry = (id) => {
|
|
470
|
+
if (!signalIndex) {
|
|
471
|
+
const index = new Map();
|
|
472
|
+
inSection("signals.index", () => {
|
|
473
|
+
for (const name of listFiles(abs("signals/_index"), ".json")) {
|
|
474
|
+
const file = abs(`signals/_index/${name}`);
|
|
475
|
+
// Kept per index file: [signal id, written day, source ref].
|
|
476
|
+
const rows = kept("signal-index", file, () => {
|
|
477
|
+
const list = [];
|
|
478
|
+
for (const entry of asList(readJsonFile(file))) {
|
|
479
|
+
const row = asRecord(entry);
|
|
480
|
+
const signalId = asString(row.signal_id);
|
|
481
|
+
const source = asString(row.source_ref);
|
|
482
|
+
// Only a row whose source the member can read (or that names none) is kept. A row
|
|
483
|
+
// about a withheld source, or one that is not in this vault, is asked of the signal
|
|
484
|
+
// file itself on every run, so its id and its source path never sit in the manifest.
|
|
485
|
+
if (signalId && (!source || readable(source)))
|
|
486
|
+
list.push([signalId, toDay(row.written_at), source]);
|
|
487
|
+
}
|
|
488
|
+
return list;
|
|
489
|
+
});
|
|
490
|
+
for (const [signalId, written, source] of rows)
|
|
491
|
+
index.set(signalId, { written, source });
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
signalIndex = index;
|
|
495
|
+
}
|
|
496
|
+
return signalIndex.get(id);
|
|
497
|
+
};
|
|
498
|
+
let gitAdds = null;
|
|
499
|
+
const firstAddDay = (relative) => {
|
|
500
|
+
if (!gitAdds) {
|
|
501
|
+
const prefix = path.relative(context.hqRoot, root).split(path.sep).join("/");
|
|
502
|
+
const pathspecs = [`${prefix}/knowledge`, `${prefix}/projects`, `${prefix}/clients`];
|
|
503
|
+
// Kept against the HQ root's HEAD. When HEAD has moved only the new commits are asked for:
|
|
504
|
+
// a file's first-add day never moves later, and the earliest day wins.
|
|
505
|
+
const days = manifest.keyed("git.first-add", prefix, gitHeadCommit(context.hqRoot), (previous) => {
|
|
506
|
+
stats.gitRuns += 1;
|
|
507
|
+
const fresh = previous ? gitFirstAddDays(context.hqRoot, pathspecs, previous.key) : null;
|
|
508
|
+
if (!previous || !fresh)
|
|
509
|
+
return Object.fromEntries(gitFirstAddDays(context.hqRoot, pathspecs) ?? []);
|
|
510
|
+
const merged = { ...previous.value };
|
|
511
|
+
for (const [file, day] of fresh)
|
|
512
|
+
if (!merged[file] || day < merged[file])
|
|
513
|
+
merged[file] = day;
|
|
514
|
+
return merged;
|
|
515
|
+
});
|
|
516
|
+
const strip = `${prefix}/`;
|
|
517
|
+
gitAdds = new Map(Object.entries(days).map(([file, day]) => [file.startsWith(strip) ? file.slice(strip.length) : file, day]));
|
|
518
|
+
}
|
|
519
|
+
return gitAdds.get(relative) ?? null;
|
|
520
|
+
};
|
|
521
|
+
const fileInput = (cls, relPath, ref, day, audience, extra = {}) => {
|
|
522
|
+
if (!day) {
|
|
523
|
+
exclude("undated");
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
// A source with no audience key is filed under the member's local audience, never `company` (C7).
|
|
527
|
+
// Only a class the company publishes as a record keeps `company`. With no member there is no
|
|
528
|
+
// local audience, so such a source is not listed.
|
|
529
|
+
const placed = audienceForInput(cls.id, audience, scope.localKey);
|
|
530
|
+
if (!placed) {
|
|
531
|
+
exclude(audience ? "no_member_for_local" : "no_audience");
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
return { kind: cls.kind, cls: cls.id, priority: cls.priority, ref, path: abs(relPath), relPath, date: day, eventDate: day, audience: placed, ...extra };
|
|
535
|
+
};
|
|
536
|
+
const readMarkdown = (input) => {
|
|
537
|
+
const { frontmatter, body } = splitFrontmatter(fs.readFileSync(input.path, "utf8"));
|
|
538
|
+
return { input, frontmatter, body };
|
|
539
|
+
};
|
|
540
|
+
const readRecord = (input) => ({ input, frontmatter: input.record ?? {}, body: "" });
|
|
541
|
+
const push = (list, input) => {
|
|
542
|
+
if (input)
|
|
543
|
+
list.push(input);
|
|
544
|
+
};
|
|
545
|
+
const classes = [];
|
|
546
|
+
const define = (id, kind, priority, classScope, scan, read = readMarkdown) => {
|
|
547
|
+
const self = { id, kind, priority, scope: classScope, scan: () => scan(self), read };
|
|
548
|
+
classes.push(self);
|
|
549
|
+
};
|
|
550
|
+
/** Day and audience of a signal from the source it cites. */
|
|
551
|
+
const signalPlacement = (sourceRef, written, file, fallback) => {
|
|
552
|
+
const source = sourceRef ? sourceEntry(sourceRef) : undefined;
|
|
553
|
+
if (source && source.audience === null)
|
|
554
|
+
return { day: null, audience: null, blocked: true, source };
|
|
555
|
+
const audience = source && source.audience !== "company" ? source.audience : fallback;
|
|
556
|
+
return { day: source?.day ?? written ?? mtimeDay(file), audience, blocked: false, source };
|
|
557
|
+
};
|
|
558
|
+
const signalExtra = (source, sourceRef) => ({
|
|
559
|
+
__source_ref: sourceRef,
|
|
560
|
+
...(source?.entity ? { __source_entity: source.entity, __source_title: source.title, __source_day: source.day } : {}),
|
|
561
|
+
});
|
|
562
|
+
// 1. Older signals (company layout). Most carry entity_refs.
|
|
563
|
+
define("signals.legacy.meeting", "signal", 10, "company", (self) => {
|
|
564
|
+
const list = [];
|
|
565
|
+
for (const type of listFolders(abs("signals"))) {
|
|
566
|
+
if (type.startsWith("@") || type.startsWith("_") || type === "slack-dm")
|
|
567
|
+
continue;
|
|
568
|
+
for (const name of listFiles(abs(`signals/${type}`), ".md")) {
|
|
569
|
+
const rel = `signals/${type}/${name}`;
|
|
570
|
+
const id = name.replace(/\.md$/, "");
|
|
571
|
+
const ref = signalRef(id);
|
|
572
|
+
if (!ref)
|
|
573
|
+
continue;
|
|
574
|
+
const known = manifest.withheldReason(abs(rel));
|
|
575
|
+
if (known) {
|
|
576
|
+
exclude(known);
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const indexed = signalIndexEntry(id);
|
|
580
|
+
const sourceRef = indexed?.source || kept("fm:source_ref", abs(rel), () => asString(readFrontmatterOnly(abs(rel)).frontmatter.source_ref));
|
|
581
|
+
const placed = signalPlacement(sourceRef, indexed?.written ?? null, abs(rel), "company");
|
|
582
|
+
// The source path read from a signal is kept only when the member can read that source.
|
|
583
|
+
if (!indexed?.source && sourceRef && !readable(sourceRef))
|
|
584
|
+
withheld(rel);
|
|
585
|
+
if (placed.blocked) {
|
|
586
|
+
// Made from another person's DM: that never changes. A meeting's audience can, so it is asked again.
|
|
587
|
+
if (placed.source?.foreign)
|
|
588
|
+
manifest.withhold(abs(rel), "personal_not_owner");
|
|
589
|
+
else
|
|
590
|
+
withheld(rel);
|
|
591
|
+
exclude(placed.source?.channel === "slack-dm" ? "personal_not_owner" : "audience_not_held");
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
push(list, fileInput(self, rel, ref, placed.day, placed.audience, { record: signalExtra(placed.source, sourceRef) }));
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return list;
|
|
598
|
+
}, (input) => {
|
|
599
|
+
const document = readMarkdown(input);
|
|
600
|
+
return { ...document, frontmatter: { ...document.frontmatter, ...input.record } };
|
|
601
|
+
});
|
|
602
|
+
// Older signals made from personal DMs: own only.
|
|
603
|
+
define("signals.legacy.slack-dm", "signal", 11, "personal", (self) => {
|
|
604
|
+
const list = [];
|
|
605
|
+
if (!scope.personalKey)
|
|
606
|
+
return list;
|
|
607
|
+
for (const type of listFolders(abs("signals/slack-dm"))) {
|
|
608
|
+
for (const name of listFiles(abs(`signals/slack-dm/${type}`), ".md")) {
|
|
609
|
+
const rel = `signals/slack-dm/${type}/${name}`;
|
|
610
|
+
const id = name.replace(/\.md$/, "");
|
|
611
|
+
const ref = signalRef(id);
|
|
612
|
+
if (!ref)
|
|
613
|
+
continue;
|
|
614
|
+
const known = manifest.withheldReason(abs(rel));
|
|
615
|
+
if (known) {
|
|
616
|
+
exclude(known);
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
const indexed = signalIndexEntry(id);
|
|
620
|
+
const sourceRef = indexed?.source || probeOf(rel, "source_ref") || "";
|
|
621
|
+
const source = sourceRef ? sourceEntry(sourceRef) : undefined;
|
|
622
|
+
// A personal signal with no provable owner is skipped.
|
|
623
|
+
if (!source || source.audience === null || !scope.owns(source.owner)) {
|
|
624
|
+
// Another person's DM is remembered. A signal whose source is not here yet is asked again: the source may arrive.
|
|
625
|
+
if (source?.foreign)
|
|
626
|
+
manifest.withhold(abs(rel), "personal_not_owner");
|
|
627
|
+
else
|
|
628
|
+
withheld(rel);
|
|
629
|
+
exclude("personal_not_owner");
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
push(list, fileInput(self, rel, ref, source.day ?? indexed?.written ?? mtimeDay(abs(rel)), scope.personalKey, {
|
|
633
|
+
ownerPersonUid: source.owner,
|
|
634
|
+
record: signalExtra(source, sourceRef),
|
|
635
|
+
}));
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return list;
|
|
639
|
+
}, (input) => {
|
|
640
|
+
const document = readMarkdown(input);
|
|
641
|
+
return { ...document, frontmatter: { ...document.frontmatter, ...input.record } };
|
|
642
|
+
});
|
|
643
|
+
// 2. Hot-channel signals, one folder per audience key.
|
|
644
|
+
define("signals.audience", "signal", 20, "audience", (self) => {
|
|
645
|
+
const list = [];
|
|
646
|
+
for (const folder of listFolders(abs("signals"))) {
|
|
647
|
+
if (!folder.startsWith("@"))
|
|
648
|
+
continue;
|
|
649
|
+
const key = folder.slice(1);
|
|
650
|
+
if (!scope.holds(key) || key === "company") {
|
|
651
|
+
exclude("audience_not_held");
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
for (const type of listFolders(abs(`signals/${folder}`))) {
|
|
655
|
+
for (const name of listFiles(abs(`signals/${folder}/${type}`), ".md")) {
|
|
656
|
+
const rel = `signals/${folder}/${type}/${name}`;
|
|
657
|
+
const ref = signalRef(name.replace(/\.md$/, ""));
|
|
658
|
+
if (!ref)
|
|
659
|
+
continue;
|
|
660
|
+
const frontmatter = frontmatterOf(rel);
|
|
661
|
+
const payload = asString(frontmatter.payload_ref) || asString(frontmatter.source_ref);
|
|
662
|
+
const source = payload ? sourceEntry(payload) : undefined;
|
|
663
|
+
const day = firstDay(frontmatter.written_at) ?? source?.day ?? mtimeDay(abs(rel));
|
|
664
|
+
const eventDate = source?.day ?? day;
|
|
665
|
+
push(list, fileInput(self, rel, ref, day, key, {
|
|
666
|
+
...(eventDate ? { eventDate } : {}),
|
|
667
|
+
record: signalExtra(source, payload),
|
|
668
|
+
}));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return list;
|
|
673
|
+
}, (input) => {
|
|
674
|
+
const document = readMarkdown(input);
|
|
675
|
+
return { ...document, frontmatter: { ...document.frontmatter, ...input.record } };
|
|
676
|
+
});
|
|
677
|
+
// The member's own sanitized contributions.
|
|
678
|
+
define("member-signals", "signal", 21, "personal", (self) => {
|
|
679
|
+
const list = [];
|
|
680
|
+
if (!scope.personUid || !scope.personalKey)
|
|
681
|
+
return list;
|
|
682
|
+
for (const folder of listFolders(abs("member-signals"))) {
|
|
683
|
+
if (folder !== scope.personUid) {
|
|
684
|
+
exclude("personal_not_owner");
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const base = `member-signals/${folder}/observations`;
|
|
688
|
+
for (const file of walkFiles(abs(base), ".md")) {
|
|
689
|
+
const rel = `${base}/${file}`;
|
|
690
|
+
const ref = signalRef(path.basename(file, ".md"));
|
|
691
|
+
if (!ref)
|
|
692
|
+
continue;
|
|
693
|
+
const frontmatter = frontmatterOf(rel);
|
|
694
|
+
const sourceRef = asString(frontmatter.sourceRef);
|
|
695
|
+
const source = sourceRef ? sourceEntry(sourceRef) : undefined;
|
|
696
|
+
push(list, fileInput(self, rel, ref, source?.day ?? mtimeDay(abs(rel)), scope.personalKey, {
|
|
697
|
+
ownerPersonUid: scope.personUid,
|
|
698
|
+
record: signalExtra(source, sourceRef),
|
|
699
|
+
}));
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return list;
|
|
703
|
+
}, (input) => {
|
|
704
|
+
const document = readMarkdown(input);
|
|
705
|
+
const fm = document.frontmatter;
|
|
706
|
+
return {
|
|
707
|
+
...document,
|
|
708
|
+
frontmatter: {
|
|
709
|
+
...fm,
|
|
710
|
+
type: asString(fm.signalType),
|
|
711
|
+
canonical_content: asString(fm.content),
|
|
712
|
+
entity_refs: stringList(fm.entityRefs),
|
|
713
|
+
...input.record,
|
|
714
|
+
},
|
|
715
|
+
};
|
|
716
|
+
});
|
|
717
|
+
// 3. PRDs and the board.
|
|
718
|
+
define("projects.prd", "prd", 30, "company", (self) => {
|
|
719
|
+
const list = [];
|
|
720
|
+
for (const project of listFolders(abs("projects"))) {
|
|
721
|
+
const rel = `projects/${project}/prd.json`;
|
|
722
|
+
if (!fs.existsSync(abs(rel)))
|
|
723
|
+
continue;
|
|
724
|
+
const createdAt = kept("prd:createdAt", abs(rel), () => asRecord(asRecord(readJsonFile(abs(rel))).metadata).createdAt ?? null);
|
|
725
|
+
const day = firstDay(createdAt, firstAddDay(rel), mtimeDay(abs(rel)));
|
|
726
|
+
push(list, fileInput(self, rel, `doc:${rel}`, day, "company"));
|
|
727
|
+
}
|
|
728
|
+
return list;
|
|
729
|
+
}, (input) => ({ input, frontmatter: asRecord(readJsonFile(input.path)), body: "" }));
|
|
730
|
+
define("board", "prd", 31, "company", (self) => {
|
|
731
|
+
const list = [];
|
|
732
|
+
const rel = "board.json";
|
|
733
|
+
const board = asRecord(readJsonFile(abs(rel)));
|
|
734
|
+
for (const entry of asList(board.projects)) {
|
|
735
|
+
const project = asRecord(entry);
|
|
736
|
+
const id = asString(project.id);
|
|
737
|
+
if (!id)
|
|
738
|
+
continue;
|
|
739
|
+
const ref = `record:board:${id}`;
|
|
740
|
+
const created = firstDay(project.created_at, project.updated_at);
|
|
741
|
+
push(list, fileInput(self, rel, ref, created, "company", { record: { ...project, __phase: "created" } }));
|
|
742
|
+
const updated = firstDay(project.updated_at);
|
|
743
|
+
if (updated && created && updated > created) {
|
|
744
|
+
push(list, fileInput(self, rel, ref, updated, "company", { record: { ...project, __phase: "status" } }));
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return list;
|
|
748
|
+
}, readRecord);
|
|
749
|
+
// 4. Roster.
|
|
750
|
+
define("people", "org-layer", 40, "company", (self) => {
|
|
751
|
+
const list = [];
|
|
752
|
+
for (const slug of listFolders(abs("people"))) {
|
|
753
|
+
if (slug.startsWith("_"))
|
|
754
|
+
continue;
|
|
755
|
+
const rel = `people/${slug}/meta.yaml`;
|
|
756
|
+
if (!fs.existsSync(abs(rel)))
|
|
757
|
+
continue;
|
|
758
|
+
const meta = kept("yaml", abs(rel), () => readYamlFile(abs(rel)));
|
|
759
|
+
const added = firstDay(meta.added, meta.updated, mtimeDay(abs(rel)));
|
|
760
|
+
push(list, fileInput(self, rel, `doc:${rel}`, added, "company"));
|
|
761
|
+
// The file is one snapshot. It is read again on the day of its last change or note, so a note
|
|
762
|
+
// that ends something ("off the work since ...") acts on the edges that exist by then.
|
|
763
|
+
const later = [toDay(meta.updated), ...asList(meta.notes).map((note) => toDay(asRecord(note).date))]
|
|
764
|
+
.filter((day) => day !== null)
|
|
765
|
+
.sort(byCodeUnit)
|
|
766
|
+
.pop();
|
|
767
|
+
if (added && later && later > added)
|
|
768
|
+
push(list, fileInput(self, rel, `doc:${rel}`, later, "company"));
|
|
769
|
+
}
|
|
770
|
+
return list;
|
|
771
|
+
}, (input) => ({ input, frontmatter: readYamlFile(input.path), body: "" }));
|
|
772
|
+
// 5. CRM projection: one input per account.
|
|
773
|
+
define("crm", "org-layer", 50, "company", (self) => {
|
|
774
|
+
const list = [];
|
|
775
|
+
const rel = "crm-projection.json";
|
|
776
|
+
const crm = asRecord(readJsonFile(abs(rel)));
|
|
777
|
+
const synced = firstDay(crm.synced_at, mtimeDay(abs(rel)));
|
|
778
|
+
for (const entry of asList(crm.accounts)) {
|
|
779
|
+
const account = asRecord(entry);
|
|
780
|
+
const id = asString(account.id);
|
|
781
|
+
if (!id)
|
|
782
|
+
continue;
|
|
783
|
+
const external = asRecord(account.external_ids);
|
|
784
|
+
const system = Object.keys(external).sort()[0];
|
|
785
|
+
const ref = (system ? `record:${system}:${asString(external[system])}` : `record:crm:${id.slice(0, 12)}`);
|
|
786
|
+
const timeline = asList(account.timeline).map((item) => {
|
|
787
|
+
const row = asRecord(item);
|
|
788
|
+
const source = asString(row.sourceMeetingRef);
|
|
789
|
+
const known = source ? sourceEntry(source) : undefined;
|
|
790
|
+
// A timeline line made from a source the member may not read is dropped.
|
|
791
|
+
if (known && known.audience === null)
|
|
792
|
+
return null;
|
|
793
|
+
return { ...row, __day: firstDay(row.date) ?? known?.day ?? null, __audience: known?.audience ?? "company" };
|
|
794
|
+
}).filter((row) => row !== null);
|
|
795
|
+
push(list, fileInput(self, rel, ref, firstDay(account.lastActivity) ?? synced, "company", { record: { ...account, timeline } }));
|
|
796
|
+
}
|
|
797
|
+
return list;
|
|
798
|
+
}, readRecord);
|
|
799
|
+
define("customers", "org-layer", 51, "company", (self) => {
|
|
800
|
+
const list = [];
|
|
801
|
+
const rel = "customer-kpis.json";
|
|
802
|
+
const kpis = asRecord(readJsonFile(abs(rel)));
|
|
803
|
+
for (const entry of asList(kpis.days)) {
|
|
804
|
+
const day = asRecord(entry);
|
|
805
|
+
const date = toDay(day.date);
|
|
806
|
+
if (date)
|
|
807
|
+
push(list, fileInput(self, rel, `record:customer-kpis:${date}`, date, "company", { record: { ...day, currency: kpis.currency } }));
|
|
808
|
+
}
|
|
809
|
+
return list;
|
|
810
|
+
}, readRecord);
|
|
811
|
+
// 6. Commitments, action items, standing decisions.
|
|
812
|
+
const frontmatterDated = (id, kind, priority, folder, fields, filter = () => true) => define(id, kind, priority, "company", (self) => {
|
|
813
|
+
const list = [];
|
|
814
|
+
for (const name of listFiles(abs(folder), ".md")) {
|
|
815
|
+
if (!filter(name))
|
|
816
|
+
continue;
|
|
817
|
+
const rel = `${folder}/${name}`;
|
|
818
|
+
const frontmatter = frontmatterOf(rel);
|
|
819
|
+
const day = firstDay(...fields.map((field) => frontmatter[field])) ?? mtimeDay(abs(rel));
|
|
820
|
+
push(list, fileInput(self, rel, `doc:${rel}`, day, "company"));
|
|
821
|
+
}
|
|
822
|
+
return list;
|
|
823
|
+
});
|
|
824
|
+
frontmatterDated("commitments", "doc", 60, "commitments", ["created_at"], (name) => name.startsWith("cm-"));
|
|
825
|
+
frontmatterDated("action-items", "doc", 61, "action-items", ["created_at", "updated_at"]);
|
|
826
|
+
frontmatterDated("context.decisions", "doc", 62, "context/decisions", ["heard_at", "valid_from"]);
|
|
827
|
+
// 7. Policies.
|
|
828
|
+
frontmatterDated("policies", "doc", 70, "policies", ["created", "updated"]);
|
|
829
|
+
// 8. Knowledge: a date field, else the first-add commit in HQ root git, else mtime.
|
|
830
|
+
define("knowledge", "doc", 80, "company", (self) => {
|
|
831
|
+
const list = [];
|
|
832
|
+
for (const file of walkFiles(abs("knowledge"), ".md")) {
|
|
833
|
+
const rel = `knowledge/${file}`;
|
|
834
|
+
const frontmatter = frontmatterOf(rel);
|
|
835
|
+
const day = firstDay(frontmatter.created, frontmatter.date, frontmatter.created_at) ?? firstAddDay(rel) ?? mtimeDay(abs(rel));
|
|
836
|
+
push(list, fileInput(self, rel, `doc:${rel}`, day, "company"));
|
|
837
|
+
}
|
|
838
|
+
return list;
|
|
839
|
+
});
|
|
840
|
+
// 9. Project READMEs.
|
|
841
|
+
define("projects.readme", "doc", 90, "company", (self) => {
|
|
842
|
+
const list = [];
|
|
843
|
+
for (const project of listFolders(abs("projects"))) {
|
|
844
|
+
const rel = `projects/${project}/README.md`;
|
|
845
|
+
if (!fs.existsSync(abs(rel)))
|
|
846
|
+
continue;
|
|
847
|
+
push(list, fileInput(self, rel, `doc:${rel}`, firstAddDay(rel) ?? mtimeDay(abs(rel)), "company"));
|
|
848
|
+
}
|
|
849
|
+
return list;
|
|
850
|
+
});
|
|
851
|
+
// 10. Clients: README and engagement only.
|
|
852
|
+
define("clients.md", "doc", 100, "company", (self) => {
|
|
853
|
+
const list = [];
|
|
854
|
+
for (const client of listFolders(abs("clients"))) {
|
|
855
|
+
if (client.startsWith("_"))
|
|
856
|
+
continue;
|
|
857
|
+
for (const name of ["README.md", "engagement.md"]) {
|
|
858
|
+
const rel = `clients/${client}/${name}`;
|
|
859
|
+
if (!fs.existsSync(abs(rel)))
|
|
860
|
+
continue;
|
|
861
|
+
const frontmatter = frontmatterOf(rel);
|
|
862
|
+
const day = firstDay(frontmatter.date, frontmatter.created) ?? firstAddDay(rel) ?? mtimeDay(abs(rel));
|
|
863
|
+
push(list, fileInput(self, rel, `doc:${rel}`, day, "company"));
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return list;
|
|
867
|
+
});
|
|
868
|
+
// 11. Standup notes, dated by file name.
|
|
869
|
+
define("meetings.notes", "doc", 110, "company", (self) => {
|
|
870
|
+
const list = [];
|
|
871
|
+
for (const name of listFiles(abs("meetings/notes"), ".md")) {
|
|
872
|
+
const rel = `meetings/notes/${name}`;
|
|
873
|
+
push(list, fileInput(self, rel, `doc:${rel}`, toDay(name.slice(0, 10)), "company"));
|
|
874
|
+
}
|
|
875
|
+
return list;
|
|
876
|
+
});
|
|
877
|
+
// 12. Meetings: frontmatter, attendees, speakers.
|
|
878
|
+
const sourceClass = (id, priority, classScope, folder, channel) => define(id, "source", priority, classScope, (self) => {
|
|
879
|
+
buildCatalog();
|
|
880
|
+
const list = [];
|
|
881
|
+
for (const [rel, entry] of sources) {
|
|
882
|
+
if (entry.channel !== channel || !rel.startsWith(`${folder}/`))
|
|
883
|
+
continue;
|
|
884
|
+
if (entry.audience === null) {
|
|
885
|
+
exclude(channel === "slack-dm" ? "personal_not_owner" : "audience_not_held");
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
push(list, fileInput(self, rel, `source:${rel}`, entry.day, entry.audience, {
|
|
889
|
+
...(entry.owner ? { ownerPersonUid: entry.owner } : {}),
|
|
890
|
+
record: entry.entity ? { __entity: entry.entity } : {},
|
|
891
|
+
}));
|
|
892
|
+
}
|
|
893
|
+
return list;
|
|
894
|
+
}, (input) => {
|
|
895
|
+
const document = readMarkdown(input);
|
|
896
|
+
const extra = { ...input.record };
|
|
897
|
+
if (channel !== "meeting") {
|
|
898
|
+
// Identity only: Slack profile names beside the thread.
|
|
899
|
+
const raw = asRecord(readJsonFile(input.path.replace(/\.md$/, ".raw.json")));
|
|
900
|
+
const profiles = [];
|
|
901
|
+
const seen = new Set();
|
|
902
|
+
for (const message of asList(raw.messages ?? raw.thread ?? raw)) {
|
|
903
|
+
const row = asRecord(message);
|
|
904
|
+
const user = asString(row.user);
|
|
905
|
+
const profile = asRecord(row.user_profile);
|
|
906
|
+
if (!user || seen.has(user) || Object.keys(profile).length === 0)
|
|
907
|
+
continue;
|
|
908
|
+
seen.add(user);
|
|
909
|
+
profiles.push({ id: user, real_name: asString(profile.real_name), display_name: asString(profile.display_name) });
|
|
910
|
+
}
|
|
911
|
+
extra.__profiles = profiles;
|
|
912
|
+
}
|
|
913
|
+
return { ...document, frontmatter: { ...document.frontmatter, ...extra } };
|
|
914
|
+
});
|
|
915
|
+
sourceClass("sources.meetings", 120, "audience", "sources/meetings", "meeting");
|
|
916
|
+
// 13. Slack channel threads and the member's own DMs.
|
|
917
|
+
sourceClass("sources.slack", 130, "company", "sources/slack", "slack");
|
|
918
|
+
sourceClass("sources.slack-dm", 131, "personal", "sources/slack-dm", "slack-dm");
|
|
919
|
+
// Hot-channel event envelopes: audience is the list in the frontmatter.
|
|
920
|
+
define("sources.events", "source", 132, "audience", (self) => {
|
|
921
|
+
const list = [];
|
|
922
|
+
for (const folder of ["sources/meeting-events", "sources/slack-events", "sources/linear"]) {
|
|
923
|
+
for (const name of listFiles(abs(folder), ".md")) {
|
|
924
|
+
const rel = `${folder}/${name}`;
|
|
925
|
+
const frontmatter = frontmatterOf(rel);
|
|
926
|
+
const audience = scope.audienceFor(stringList(frontmatter.audience));
|
|
927
|
+
if (!audience) {
|
|
928
|
+
withheld(rel);
|
|
929
|
+
exclude(stringList(frontmatter.audience).length === 0 ? "no_audience" : "audience_not_held");
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
push(list, fileInput(self, rel, `source:${rel}`, firstDay(frontmatter.when, frontmatter.created_at), audience));
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return list;
|
|
936
|
+
});
|
|
937
|
+
// 14. Company session records and the member's own HQ threads.
|
|
938
|
+
const threadDay = (name) => toDay(/^T-(\d{8})/.exec(name)?.[1]);
|
|
939
|
+
define("company.workspace.sessions", "session", 140, "company", (self) => {
|
|
940
|
+
const list = [];
|
|
941
|
+
for (const name of listFiles(abs("workspace/sessions"), ".json")) {
|
|
942
|
+
if (!name.startsWith("T-"))
|
|
943
|
+
continue;
|
|
944
|
+
const rel = `workspace/sessions/${name}`;
|
|
945
|
+
// A company session record is a company document: cited as `doc:`. `session:` refs are personal.
|
|
946
|
+
push(list, fileInput(self, rel, `doc:${rel}`, threadDay(name), "company"));
|
|
947
|
+
}
|
|
948
|
+
return list;
|
|
949
|
+
}, (input) => ({ input, frontmatter: asRecord(readJsonFile(input.path)), body: "" }));
|
|
950
|
+
define("hq.workspace.threads", "session", 141, "personal", (self) => {
|
|
951
|
+
const list = [];
|
|
952
|
+
if (!scope.personUid || !scope.personalKey)
|
|
953
|
+
return list;
|
|
954
|
+
const dir = path.join(context.hqRoot, "workspace", "threads");
|
|
955
|
+
const marker = `companies/${context.company}/`;
|
|
956
|
+
for (const name of listFiles(dir, ".json")) {
|
|
957
|
+
if (!name.startsWith("T-"))
|
|
958
|
+
continue;
|
|
959
|
+
const file = path.join(dir, name);
|
|
960
|
+
// Another company's thread an earlier run recognised, unchanged since: not opened again.
|
|
961
|
+
const known = manifest.withheldReason(file);
|
|
962
|
+
if (known) {
|
|
963
|
+
exclude(known);
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
// What the listing needs from a thread; the thread itself is read when its day is replayed.
|
|
967
|
+
const digest = kept(`thread:${marker}`, file, () => {
|
|
968
|
+
let text;
|
|
969
|
+
try {
|
|
970
|
+
text = fs.readFileSync(file, "utf8");
|
|
971
|
+
}
|
|
972
|
+
catch {
|
|
973
|
+
return null;
|
|
974
|
+
}
|
|
975
|
+
let thread;
|
|
976
|
+
try {
|
|
977
|
+
thread = asRecord(JSON.parse(text));
|
|
978
|
+
}
|
|
979
|
+
catch {
|
|
980
|
+
return null;
|
|
981
|
+
}
|
|
982
|
+
const metadata = asRecord(thread.metadata);
|
|
983
|
+
return {
|
|
984
|
+
companies: [...stringList(thread.company), ...stringList(metadata.company), ...stringList(metadata.company_slugs)],
|
|
985
|
+
marker: text.includes(marker),
|
|
986
|
+
created: asString(thread.created_at),
|
|
987
|
+
id: asString(thread.thread_id),
|
|
988
|
+
};
|
|
989
|
+
});
|
|
990
|
+
if (!digest)
|
|
991
|
+
continue;
|
|
992
|
+
const companies = digest.companies;
|
|
993
|
+
// A thread that names any other company is left out; so is one with no tie to this company.
|
|
994
|
+
if (companies.some((slug) => slug !== context.company)) {
|
|
995
|
+
// Another company's thread: nothing about it is kept in this company's graph folder but a hash that says so.
|
|
996
|
+
manifest.withhold(file, "other_company");
|
|
997
|
+
exclude("other_company");
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
if (!companies.includes(context.company) && !digest.marker)
|
|
1001
|
+
continue;
|
|
1002
|
+
const day = threadDay(name) ?? firstDay(digest.created);
|
|
1003
|
+
const id = digest.id || name.replace(/\.json$/, "");
|
|
1004
|
+
const input = fileInput(self, `workspace/threads/${name}`, `session:${id}`, day, scope.personalKey, {
|
|
1005
|
+
ownerPersonUid: scope.personUid,
|
|
1006
|
+
});
|
|
1007
|
+
if (input)
|
|
1008
|
+
list.push({ ...input, path: file });
|
|
1009
|
+
}
|
|
1010
|
+
return list;
|
|
1011
|
+
}, (input) => ({ input, frontmatter: asRecord(readJsonFile(input.path)), body: "" }));
|
|
1012
|
+
// 15. Git commit authors per repo: one input per repo and day.
|
|
1013
|
+
define("git.history", "session", 150, "company", (self) => {
|
|
1014
|
+
const list = [];
|
|
1015
|
+
const today = options.today ?? toDay(new Date());
|
|
1016
|
+
const found = repoScope();
|
|
1017
|
+
for (let left = found.excluded; left > 0; left -= 1)
|
|
1018
|
+
exclude("other_company_repo");
|
|
1019
|
+
for (const repo of found.repos) {
|
|
1020
|
+
// One `git log` per repo, over the remote default branch as last fetched (the clone's HEAD only when
|
|
1021
|
+
// there is none), kept against that commit: a repo with no new commit is not asked again.
|
|
1022
|
+
const head = historyCommit(repo.dir);
|
|
1023
|
+
let ran = false;
|
|
1024
|
+
const history = manifest.keyed(self.id, repo.dir, head, () => {
|
|
1025
|
+
ran = true;
|
|
1026
|
+
stats.gitRuns += 1;
|
|
1027
|
+
let output;
|
|
1028
|
+
try {
|
|
1029
|
+
output = execFileSync("git", ["-C", repo.dir, "log", "--no-merges", "--format=%H%x1f%aI%x1f%aN%x1f%aE%x1f%s", ...(head ? [head] : [])], { encoding: "utf8", maxBuffer: 512 * 1024 * 1024, stdio: ["ignore", "pipe", "ignore"], timeout: 180_000 });
|
|
1030
|
+
}
|
|
1031
|
+
catch {
|
|
1032
|
+
return { failed: true, days: [] };
|
|
1033
|
+
}
|
|
1034
|
+
const days = new Map();
|
|
1035
|
+
for (const line of output.split("\n")) {
|
|
1036
|
+
const [sha, when, name, email, subject] = line.split("\x1f");
|
|
1037
|
+
const day = toDay(when);
|
|
1038
|
+
if (!sha || !day)
|
|
1039
|
+
continue;
|
|
1040
|
+
const bucket = days.get(day) ?? [];
|
|
1041
|
+
bucket.push({ sha, name: name ?? "", email: (email ?? "").toLowerCase(), subject: subject ?? "" });
|
|
1042
|
+
days.set(day, bucket);
|
|
1043
|
+
}
|
|
1044
|
+
return {
|
|
1045
|
+
failed: false,
|
|
1046
|
+
days: [...days].map(([day, commits]) => {
|
|
1047
|
+
commits.sort((a, b) => byCodeUnit(a.sha, b.sha));
|
|
1048
|
+
return [day, commits.length, commits.slice(0, 400)];
|
|
1049
|
+
}),
|
|
1050
|
+
};
|
|
1051
|
+
});
|
|
1052
|
+
if (!ran)
|
|
1053
|
+
stats.gitReused += 1;
|
|
1054
|
+
if (history.failed) {
|
|
1055
|
+
exclude("git_log_failed");
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
const relative = path.relative(context.hqRoot, repo.dir).split(path.sep).join("/");
|
|
1059
|
+
// A finished week is one input (one line per project and per author for the week), replayed on the
|
|
1060
|
+
// day of its last commit. The week still running stays one input per day, so today's work is in the graph.
|
|
1061
|
+
const weeks = new Map();
|
|
1062
|
+
for (const [day, count, commits] of history.days) {
|
|
1063
|
+
const week = weekStart(day);
|
|
1064
|
+
if (weekEnd(week) >= today) {
|
|
1065
|
+
const input = fileInput(self, relative, `record:git:${repo.name}@${day}`, day, "company", {
|
|
1066
|
+
record: { repo: repo.name, count, commits },
|
|
1067
|
+
});
|
|
1068
|
+
if (input)
|
|
1069
|
+
list.push({ ...input, path: repo.dir });
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
const known = weeks.get(week);
|
|
1073
|
+
if (known) {
|
|
1074
|
+
known.count += count;
|
|
1075
|
+
known.commits.push(...commits);
|
|
1076
|
+
if (day > known.last)
|
|
1077
|
+
known.last = day;
|
|
1078
|
+
if (day < known.first)
|
|
1079
|
+
known.first = day;
|
|
1080
|
+
}
|
|
1081
|
+
else
|
|
1082
|
+
weeks.set(week, { last: day, first: day, count, commits: [...commits] });
|
|
1083
|
+
}
|
|
1084
|
+
for (const [week, rolled] of weeks) {
|
|
1085
|
+
rolled.commits.sort((a, b) => byCodeUnit(a.sha, b.sha));
|
|
1086
|
+
const input = fileInput(self, relative, `record:git:${repo.name}@week-${week}`, rolled.last, "company", {
|
|
1087
|
+
record: { repo: repo.name, week, from: rolled.first, to: rolled.last, count: rolled.count, commits: rolled.commits.slice(0, 600) },
|
|
1088
|
+
});
|
|
1089
|
+
if (input)
|
|
1090
|
+
list.push({ ...input, path: repo.dir });
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return list;
|
|
1094
|
+
}, readRecord);
|
|
1095
|
+
// 16. Work mesh cache: this member's contacts and this company's projects.
|
|
1096
|
+
define("work-mesh.cache", "session", 160, "personal", (self) => {
|
|
1097
|
+
const list = [];
|
|
1098
|
+
if (!scope.personUid || !scope.personalKey)
|
|
1099
|
+
return list;
|
|
1100
|
+
const contacts = path.join(config.meshCacheDir, "contacts", `${scope.personUid}.json`);
|
|
1101
|
+
if (fs.existsSync(contacts)) {
|
|
1102
|
+
const input = fileInput(self, `work-mesh/contacts/${scope.personUid}.json`, `record:mesh-contacts:${scope.personUid}`, mtimeDay(contacts), scope.personalKey, {
|
|
1103
|
+
ownerPersonUid: scope.personUid,
|
|
1104
|
+
record: { __mesh: "contacts", ...asRecord(readJsonFile(contacts)) },
|
|
1105
|
+
});
|
|
1106
|
+
if (input)
|
|
1107
|
+
list.push({ ...input, path: contacts });
|
|
1108
|
+
}
|
|
1109
|
+
if (config.companyUid) {
|
|
1110
|
+
const dir = path.join(config.meshCacheDir, "projects", config.companyUid);
|
|
1111
|
+
for (const name of listFiles(dir, ".json")) {
|
|
1112
|
+
const file = path.join(dir, name);
|
|
1113
|
+
// Kept with the stories cut to the four fields the rules read.
|
|
1114
|
+
const project = kept("mesh-project", file, () => {
|
|
1115
|
+
const loaded = asRecord(readJsonFile(file));
|
|
1116
|
+
return { ...loaded, stories: asList(loaded.stories).map((story) => {
|
|
1117
|
+
const row = asRecord(story);
|
|
1118
|
+
return { id: row.id, title: row.title, status: row.status, passes: row.passes };
|
|
1119
|
+
}) };
|
|
1120
|
+
});
|
|
1121
|
+
if (asString(project.companyUid) !== config.companyUid)
|
|
1122
|
+
continue;
|
|
1123
|
+
const id = asString(project.projectId) || name.replace(/\.json$/, "");
|
|
1124
|
+
const input = fileInput(self, `work-mesh/projects/${name}`, `record:mesh:${id}`, firstDay(project.updatedAt, project.createdAt, mtimeDay(file)), scope.personalKey, {
|
|
1125
|
+
ownerPersonUid: scope.personUid,
|
|
1126
|
+
record: { __mesh: "project", ...project },
|
|
1127
|
+
});
|
|
1128
|
+
if (input)
|
|
1129
|
+
list.push({ ...input, path: file });
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return list;
|
|
1133
|
+
}, readRecord);
|
|
1134
|
+
// 17. Session transcripts, last: the member's own, user prompts and the final message only.
|
|
1135
|
+
define("claude.transcripts.main", "session", 170, "personal", (self) => {
|
|
1136
|
+
const list = [];
|
|
1137
|
+
if (!scope.personUid || !scope.personalKey)
|
|
1138
|
+
return list;
|
|
1139
|
+
const repos = repoScope();
|
|
1140
|
+
const placed = new Map();
|
|
1141
|
+
const own = context.company.toLowerCase();
|
|
1142
|
+
for (const extract of readTranscripts(config.transcripts.dir, {
|
|
1143
|
+
maxPrompts: config.transcripts.maxPrompts,
|
|
1144
|
+
maxChars: config.transcripts.maxChars,
|
|
1145
|
+
cacheFile: options.transcriptCacheFile ?? null,
|
|
1146
|
+
writeCache: options.writeTranscriptCache ?? false,
|
|
1147
|
+
})) {
|
|
1148
|
+
// The transcript folder holds the sessions of every company on this machine. A session that names
|
|
1149
|
+
// another company's folder or scope, ran in another company's repo, or points at one is not this
|
|
1150
|
+
// company's material (C7).
|
|
1151
|
+
const typed = [...extract.cwds, ...extract.prompts].join("\n");
|
|
1152
|
+
const typedScopes = [...extract.typedCompanies, ...companyScopesIn(typed)];
|
|
1153
|
+
const places = extract.cwds.map((cwd) => placeCwd(context, repos, cwd, placed));
|
|
1154
|
+
if (namesAnotherCompany([...extract.companies, ...typedScopes], context.company) || places.includes("other") || mentionsOtherCompanyRepo(`${typed}\n${extract.final}`, repos)) {
|
|
1155
|
+
exclude("other_company");
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
// Where the session ran decides. Every working directory has to be this company's ground or the HQ
|
|
1159
|
+
// root: one in a clone that is not provably this company's, in a folder that is gone, or with no
|
|
1160
|
+
// working directory on record, leaves the session out whatever it mentions.
|
|
1161
|
+
if (places.length === 0 || places.includes("elsewhere")) {
|
|
1162
|
+
exclude("ran_elsewhere");
|
|
1163
|
+
continue;
|
|
1164
|
+
}
|
|
1165
|
+
// A session that ran in one of the company's repos or in its folder is the company's. One that ran
|
|
1166
|
+
// only at the HQ root is the company's when the user typed its scope (its folder, a company tag);
|
|
1167
|
+
// what the assistant wrote in its last message ties nothing.
|
|
1168
|
+
if (!places.includes("own") && !places.includes("company") && !typedScopes.includes(own)) {
|
|
1169
|
+
exclude("no_company_tie");
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
const day = toDay(extract.firstAt);
|
|
1173
|
+
const input = fileInput(self, `transcripts/${extract.sessionId}.jsonl`, `session:${extract.sessionId}`, day, scope.personalKey, {
|
|
1174
|
+
ownerPersonUid: scope.personUid,
|
|
1175
|
+
record: { ...extract, __company: context.company },
|
|
1176
|
+
});
|
|
1177
|
+
if (input)
|
|
1178
|
+
list.push({ ...input, path: extract.file });
|
|
1179
|
+
}
|
|
1180
|
+
return list;
|
|
1181
|
+
}, readRecord);
|
|
1182
|
+
const only = options.only ? new Set(options.only) : null;
|
|
1183
|
+
const active = classes.filter((cls) => !config.disabled.has(cls.id) && (!only || only.has(cls.id)));
|
|
1184
|
+
const inputs = [];
|
|
1185
|
+
for (const cls of active) {
|
|
1186
|
+
const classStarted = Date.now();
|
|
1187
|
+
const listed = inSection(cls.id, () => cls.scan()).filter((input) => !isCopyName(path.basename(input.relPath)));
|
|
1188
|
+
stats.listed[cls.id] = listed.length;
|
|
1189
|
+
stats.classMs[cls.id] = Date.now() - classStarted;
|
|
1190
|
+
for (const input of listed)
|
|
1191
|
+
inputs.push(input);
|
|
1192
|
+
}
|
|
1193
|
+
inputs.sort((a, b) => byCodeUnit(a.date, b.date) || a.priority - b.priority || byCodeUnit(a.relPath, b.relPath) || byCodeUnit(a.ref, b.ref) || byCodeUnit(a.eventDate, b.eventDate));
|
|
1194
|
+
const byDay = new Map();
|
|
1195
|
+
for (const input of inputs) {
|
|
1196
|
+
const bucket = byDay.get(input.date);
|
|
1197
|
+
if (bucket)
|
|
1198
|
+
bucket.push(input);
|
|
1199
|
+
else
|
|
1200
|
+
byDay.set(input.date, [input]);
|
|
1201
|
+
}
|
|
1202
|
+
const byId = new Map(classes.map((cls) => [cls.id, cls]));
|
|
1203
|
+
stats.filesRead = manifest.stats.filesRead;
|
|
1204
|
+
stats.filesReused = manifest.stats.filesReused;
|
|
1205
|
+
stats.filesWithheldKnown = manifest.stats.withheldKnown;
|
|
1206
|
+
if (options.writeManifest && !options.manifest) {
|
|
1207
|
+
try {
|
|
1208
|
+
// Records of files that are gone are dropped for every class this run listed.
|
|
1209
|
+
manifest.save({ prune: true });
|
|
1210
|
+
}
|
|
1211
|
+
catch {
|
|
1212
|
+
// The manifest is a cache: a run that cannot write it lists in full next time.
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
stats.scanMs = Date.now() - started;
|
|
1216
|
+
return {
|
|
1217
|
+
scope,
|
|
1218
|
+
config,
|
|
1219
|
+
classes: active,
|
|
1220
|
+
inputs,
|
|
1221
|
+
days: [...byDay.keys()].sort(byCodeUnit),
|
|
1222
|
+
stats,
|
|
1223
|
+
forDay: (day) => byDay.get(day) ?? [],
|
|
1224
|
+
read(input) {
|
|
1225
|
+
const cls = byId.get(input.cls);
|
|
1226
|
+
if (!cls)
|
|
1227
|
+
throw new Error(`ontology replay: no reader for source class ${input.cls}`);
|
|
1228
|
+
return cls.read(input);
|
|
1229
|
+
},
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* The contract's per-kind readers: each one is the union of the source classes
|
|
1234
|
+
* of that kind, filtered for `context.member`.
|
|
1235
|
+
*/
|
|
1236
|
+
export function kindReaders(context, corpus) {
|
|
1237
|
+
const readers = {};
|
|
1238
|
+
const member = context.member;
|
|
1239
|
+
for (const kind of new Set(corpus.classes.map((cls) => cls.kind))) {
|
|
1240
|
+
const inRange = (day, range) => (!range?.from || day >= range.from) && (!range?.to || day <= range.to);
|
|
1241
|
+
readers[kind] = {
|
|
1242
|
+
kind,
|
|
1243
|
+
...(member ? { member } : {}),
|
|
1244
|
+
listDays: (range) => corpus.days.filter((day) => inRange(day, range) && corpus.forDay(day).some((input) => input.kind === kind)),
|
|
1245
|
+
list: (day) => corpus.forDay(day).filter((input) => input.kind === kind),
|
|
1246
|
+
read: (input) => corpus.read(input),
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
return readers;
|
|
1250
|
+
}
|
|
1251
|
+
//# sourceMappingURL=readers.js.map
|