@indigoai-us/hq-cli 5.345.247 → 5.345.250
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 +95 -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 +1198 -0
- package/dist/command-catalog.generated.js +1476 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/core-job-run-native.js +4 -0
- package/dist/commands/core-knowledge-prefs.d.ts +1 -1
- package/dist/commands/core-knowledge-prefs.js +1 -16
- package/dist/commands/core.js +0 -2
- package/dist/commands/daemon.js +21 -0
- package/dist/commands/lanes-hold.js +7 -7
- package/dist/commands/lanes-resume.js +2 -2
- package/dist/commands/lanes-review.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -1
- package/dist/commands/lanes-session-start.js +3 -3
- package/dist/commands/lanes-shared.d.ts +1 -1
- package/dist/commands/lanes.d.ts +2 -2
- package/dist/commands/lanes.js +50 -50
- package/dist/commands/mesh.d.ts +25 -0
- package/dist/commands/mesh.js +48 -8
- package/dist/commands/ontology-graph.d.ts +63 -0
- package/dist/commands/ontology-graph.js +470 -0
- package/dist/commands/sync-core.js +6 -0
- package/dist/fast-scaffold.js +1 -3
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +48 -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/installed-cli-restart.d.ts +57 -0
- package/dist/lib/daemon/installed-cli-restart.js +114 -0
- 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/legacy-journal-gate.d.ts +32 -0
- package/dist/lib/daemon/legacy-journal-gate.js +102 -0
- package/dist/lib/daemon/machine-checks.d.ts +7 -0
- package/dist/lib/daemon/machine-checks.js +10 -0
- 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.d.ts +3 -1
- package/dist/lib/daemon/run.js +49 -6
- package/dist/lib/daemon/state-file.d.ts +1 -1
- package/dist/lib/daemon/state-file.js +1 -1
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-snapshot-file.d.ts +2 -0
- package/dist/lib/flag-snapshot-file.js +118 -48
- package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
- package/dist/lib/hook-engine/canary-gate.js +138 -6
- package/dist/lib/hook-engine/coverage.d.ts +82 -13
- package/dist/lib/hook-engine/coverage.js +214 -18
- package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
- package/dist/lib/hook-engine/registration-identity.js +1 -1
- package/dist/lib/hook-engine/resolve.d.ts +23 -0
- package/dist/lib/hook-engine/resolve.js +48 -1
- package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
- package/dist/lib/hook-engine/stable-heal.js +214 -0
- package/dist/lib/hot-channels/graph-context.d.ts +105 -0
- package/dist/lib/hot-channels/graph-context.js +380 -0
- package/dist/lib/hot-channels/signals-pass.js +27 -1
- package/dist/lib/lanes/claude-credential.d.ts +1 -1
- package/dist/lib/lanes/claude-credential.js +1 -1
- package/dist/lib/lanes/delivery-core.d.ts +1 -1
- package/dist/lib/lanes/delivery-core.js +1 -1
- package/dist/lib/lanes/delivery.d.ts +10 -10
- package/dist/lib/lanes/delivery.js +8 -8
- package/dist/lib/lanes/dropbox.d.ts +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +2 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.js +1 -1
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/quota.d.ts +1 -1
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
- package/dist/lib/lanes/repo-merge-hold.js +2 -2
- package/dist/lib/lanes/spawn.d.ts +4 -4
- package/dist/lib/lanes/spawn.js +5 -5
- package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
- package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
- package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
- package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
- package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
- package/dist/lib/mesh/live/daemon/run.js +35 -2
- package/dist/lib/mesh/live/direct-drain.js +1 -1
- package/dist/lib/mesh/live/emit.d.ts +3 -0
- package/dist/lib/mesh/live/emit.js +32 -9
- package/dist/lib/mesh/live/flush.d.ts +3 -0
- package/dist/lib/mesh/live/flush.js +115 -32
- package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
- package/dist/lib/mesh/live/liveness-carry.js +1 -1
- package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
- package/dist/lib/mesh/live/reporting-privacy.js +235 -11
- package/dist/lib/mesh/live/spool.d.ts +17 -2
- package/dist/lib/mesh/live/spool.js +22 -6
- package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
- package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
- package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
- package/dist/lib/ontology-graph/legacy/index.js +1150 -0
- package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
- package/dist/lib/ontology-graph/legacy/parse.js +126 -0
- package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
- package/dist/lib/ontology-graph/legacy/report.js +254 -0
- package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
- package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
- package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
- package/dist/lib/ontology-graph/lint/checks.js +717 -0
- package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
- package/dist/lib/ontology-graph/lint/coverage.js +241 -0
- package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
- package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
- package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
- package/dist/lib/ontology-graph/lint/index.js +176 -0
- package/dist/lib/ontology-graph/model/files.d.ts +20 -0
- package/dist/lib/ontology-graph/model/files.js +89 -0
- package/dist/lib/ontology-graph/model/index.d.ts +65 -0
- package/dist/lib/ontology-graph/model/index.js +100 -0
- package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
- package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
- package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
- package/dist/lib/ontology-graph/model/pass.js +958 -0
- package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
- package/dist/lib/ontology-graph/model/runner.js +160 -0
- package/dist/lib/ontology-graph/model/step.d.ts +197 -0
- package/dist/lib/ontology-graph/model/step.js +526 -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 +67 -0
- package/dist/lib/ontology-graph/org/derive.js +359 -0
- package/dist/lib/ontology-graph/org/index.d.ts +102 -0
- package/dist/lib/ontology-graph/org/index.js +630 -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 +97 -0
- package/dist/lib/ontology-graph/org/text.js +321 -0
- package/dist/lib/ontology-graph/org/types.d.ts +457 -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 +144 -0
- package/dist/lib/ontology-graph/pages/render.js +688 -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 +254 -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 +803 -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 +49 -0
- package/dist/lib/ontology-graph/read/names.js +297 -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 +146 -0
- package/dist/lib/ontology-graph/replay/engine.js +1240 -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 +91 -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 +107 -0
- package/dist/lib/ontology-graph/schema/authority.js +186 -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 +1190 -0
- package/dist/lib/ontology-graph/types.js +131 -0
- package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
- package/dist/lib/sync-core/engine-holds.d.ts +1 -1
- package/dist/lib/sync-core/engine-holds.js +12 -2
- package/dist/lib/sync-core/hand-back.d.ts +2 -1
- package/dist/lib/sync-core/hand-back.js +16 -2
- package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
- package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
- package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
- package/dist/lib/sync-core/legacy-journal-export.js +241 -0
- package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
- package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
- package/dist/lib/sync-core/reconcile.d.ts +3 -0
- package/dist/lib/sync-core/reconcile.js +43 -3
- package/dist/utils/cli-telemetry.d.ts +1 -0
- package/dist/utils/cli-telemetry.js +6 -3
- package/dist/utils/frontmatter.d.ts +14 -0
- package/dist/utils/frontmatter.js +18 -0
- package/dist/utils/hook-engine-rollup.d.ts +96 -0
- package/dist/utils/hook-engine-rollup.js +725 -0
- package/dist/utils/interactive-caller.js +1 -1
- package/package.json +9 -9
- package/scripts/install-hook-engine.mjs +4 -0
- package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-D: renders one compiled entity page from rows (design 2.10, corrections C7
|
|
3
|
+
* and C8). Pure: no file access and no model call. The same rows and the same
|
|
4
|
+
* day always give the same bytes.
|
|
5
|
+
*
|
|
6
|
+
* A page leads with what a colleague asks first, by entity type:
|
|
7
|
+
* person role, employer, team, manager, reports; what they work on now; recent timeline
|
|
8
|
+
* project status, owner, lead; team; customer; the last 30 days; decisions
|
|
9
|
+
* company relation, stage; contacts; commitments; recent meetings; decisions
|
|
10
|
+
* meeting summary; decisions; action items; attendees; topics
|
|
11
|
+
* then the remaining facts and relationships, then history. Closed rows are
|
|
12
|
+
* hidden by default and counted.
|
|
13
|
+
*
|
|
14
|
+
* Every bullet line ends with ` | @<audience> | row <row id> | src <ref>`. The
|
|
15
|
+
* audience marker says which `facts/@<key>/` folder the row came from, so a
|
|
16
|
+
* reader can drop the lines a caller may not see (`filterPageLines`). No line
|
|
17
|
+
* mixes rows of two audiences.
|
|
18
|
+
*/
|
|
19
|
+
import yaml from "js-yaml";
|
|
20
|
+
import { dropUnverifiedGuesses, effectiveFacts, escapeText, formatConf, isOpen, isSingleValued, originTier } from "../schema/index.js";
|
|
21
|
+
import { sha256Hex } from "../model/files.js";
|
|
22
|
+
export const DEFAULT_PAGE_LIMITS = {
|
|
23
|
+
edgesPerVerb: 25, timeline: 30, summarySentences: 6, recentDays: 30, decisions: 12, commitments: 12, showClosed: false,
|
|
24
|
+
};
|
|
25
|
+
const CLASS_ORDER = { state: 0, event: 1, reference: 2 };
|
|
26
|
+
function sentence(text) {
|
|
27
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
28
|
+
return /[.!?]$/.test(flat) ? flat : `${flat}.`;
|
|
29
|
+
}
|
|
30
|
+
function clip(text, max) {
|
|
31
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
32
|
+
return flat.length <= max ? flat : `${flat.slice(0, max - 1)}…`;
|
|
33
|
+
}
|
|
34
|
+
function label(token) {
|
|
35
|
+
const words = token.replace(/_/g, " ");
|
|
36
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
37
|
+
}
|
|
38
|
+
function byCode(a, b) {
|
|
39
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
40
|
+
}
|
|
41
|
+
function addDays(day, count) {
|
|
42
|
+
const date = new Date(`${day}T00:00:00Z`);
|
|
43
|
+
if (Number.isNaN(date.getTime()))
|
|
44
|
+
return day;
|
|
45
|
+
date.setUTCDate(date.getUTCDate() + count);
|
|
46
|
+
return date.toISOString().slice(0, 10);
|
|
47
|
+
}
|
|
48
|
+
/** `company` first, then audience keys, then `local`: the widest audience a row was filed under wins. */
|
|
49
|
+
function audienceRank(audience) {
|
|
50
|
+
return audience === "company" ? `0${audience}` : audience === "local" ? `2${audience}` : `1${audience}`;
|
|
51
|
+
}
|
|
52
|
+
function betterEdge(a, b) {
|
|
53
|
+
const tierA = originTier(a.row.by);
|
|
54
|
+
const tierB = originTier(b.row.by);
|
|
55
|
+
if (tierA !== tierB)
|
|
56
|
+
return tierA < tierB;
|
|
57
|
+
if (a.row.valid.from !== b.row.valid.from)
|
|
58
|
+
return a.row.valid.from > b.row.valid.from;
|
|
59
|
+
if (a.row.conf !== b.row.conf)
|
|
60
|
+
return a.row.conf > b.row.conf;
|
|
61
|
+
return a.id < b.id;
|
|
62
|
+
}
|
|
63
|
+
/** Fields that open the summary, per type, in order. Other fields follow alphabetically. */
|
|
64
|
+
const FACT_PRIORITY = {
|
|
65
|
+
person: ["role_title", "affiliation", "status"],
|
|
66
|
+
project: ["summary", "stage", "status", "target_date"],
|
|
67
|
+
product: ["summary", "status"],
|
|
68
|
+
company: ["relation", "stage", "owner", "crm_status"],
|
|
69
|
+
decision: ["statement", "status", "decided_on"],
|
|
70
|
+
meeting: ["title", "date"],
|
|
71
|
+
team: ["purpose", "status"],
|
|
72
|
+
role: ["title", "scope"],
|
|
73
|
+
};
|
|
74
|
+
/** Identity keys are listed under facts; they do not describe the entity, so the summary leaves them out. */
|
|
75
|
+
const IDENTITY_FIELDS = new Set(["email", "slack_id", "web_domain", "repo", "url", "channel"]);
|
|
76
|
+
const EDGE_PRIORITY = [
|
|
77
|
+
"reports_to", "works_at", "member_of", "leads", "owned_by", "led_by", "decided_by", "decided_in", "about",
|
|
78
|
+
"part_of", "works_on", "owns", "holds_role", "customer_of", "vendor_of", "partner_of", "manages", "has_contributor",
|
|
79
|
+
];
|
|
80
|
+
function factSentence(name, type, fact) {
|
|
81
|
+
const value = fact.value;
|
|
82
|
+
switch (`${type}.${fact.field}`) {
|
|
83
|
+
case "person.role_title":
|
|
84
|
+
return sentence(`${name} is ${value}`);
|
|
85
|
+
case "person.affiliation":
|
|
86
|
+
return sentence(`${name} is affiliated with ${value}`);
|
|
87
|
+
case "project.summary":
|
|
88
|
+
case "product.summary":
|
|
89
|
+
case "decision.statement":
|
|
90
|
+
case "team.purpose":
|
|
91
|
+
return sentence(value);
|
|
92
|
+
case "project.stage":
|
|
93
|
+
case "company.stage":
|
|
94
|
+
return sentence(`${name} is at stage ${value}`);
|
|
95
|
+
case "company.relation":
|
|
96
|
+
return value === "self" ? sentence(`${name} is this company`) : sentence(`${name} is a ${value}`);
|
|
97
|
+
case "decision.decided_on":
|
|
98
|
+
return sentence(`Decided on ${value}`);
|
|
99
|
+
default:
|
|
100
|
+
return sentence(`${label(fact.field)} is ${value}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function words(text) {
|
|
104
|
+
return text.toLowerCase().replace(/…$/, "").replace(/[^a-z0-9]+/g, " ").trim().split(" ").filter((word) => word !== "");
|
|
105
|
+
}
|
|
106
|
+
/** True when two one-line texts say the same thing: equal, one a cut-off copy of the other, or nearly the same words. */
|
|
107
|
+
export function sameStatement(a, b) {
|
|
108
|
+
const wordsA = words(a);
|
|
109
|
+
const wordsB = words(b);
|
|
110
|
+
if (wordsA.length === 0 || wordsB.length === 0)
|
|
111
|
+
return false;
|
|
112
|
+
const [short, long] = wordsA.length <= wordsB.length ? [wordsA, wordsB] : [wordsB, wordsA];
|
|
113
|
+
if (short.length >= 4 && short.every((word, i) => long[i] === word || (i === short.length - 1 && long[i].startsWith(word))))
|
|
114
|
+
return true;
|
|
115
|
+
if (short.length < 5)
|
|
116
|
+
return short.length === long.length && short.join(" ") === long.join(" ");
|
|
117
|
+
const setLong = new Set(long);
|
|
118
|
+
const shared = new Set(short.filter((word) => setLong.has(word))).size;
|
|
119
|
+
const union = new Set([...short, ...long]).size;
|
|
120
|
+
return shared / union >= 0.8;
|
|
121
|
+
}
|
|
122
|
+
/** Folds entries that say the same thing on the same day in the same audience into one line with every citation. */
|
|
123
|
+
function foldSame(entries) {
|
|
124
|
+
const out = [];
|
|
125
|
+
for (const entry of entries) {
|
|
126
|
+
const twin = out.find((kept) => kept.date === entry.date && kept.row.audience === entry.row.audience && sameStatement(kept.text, entry.text));
|
|
127
|
+
if (!twin) {
|
|
128
|
+
out.push({ ...entry });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (entry.row.id === twin.row.id || twin.also?.some((row) => row.id === entry.row.id))
|
|
132
|
+
continue;
|
|
133
|
+
twin.also = [...(twin.also ?? []), entry.row];
|
|
134
|
+
if (entry.text.replace(/…$/, "").length > twin.text.replace(/…$/, "").length)
|
|
135
|
+
twin.text = entry.text;
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
/** Builds everything the page shows from an entity's rows. `nameOf` gives a target's display name. */
|
|
140
|
+
export function buildPageModel(schema, entity, storedRows, nameOf, limits = DEFAULT_PAGE_LIMITS, options = {}) {
|
|
141
|
+
// The same row can sit in two audience folders; a page shows it once, under the widest audience.
|
|
142
|
+
const unique = new Map();
|
|
143
|
+
for (const stored of storedRows) {
|
|
144
|
+
const known = unique.get(stored.id);
|
|
145
|
+
if (!known || audienceRank(stored.audience) < audienceRank(known.audience))
|
|
146
|
+
unique.set(stored.id, stored);
|
|
147
|
+
}
|
|
148
|
+
// An open role or affiliation a model wrote at low confidence is left off the page before any winner or
|
|
149
|
+
// conflict is worked out, and counted in the frontmatter. Row counts still count every row. Relationships
|
|
150
|
+
// stay: each relationship line names who wrote it, and a customer's contact list is built from them.
|
|
151
|
+
const everyRow = [...unique.values()];
|
|
152
|
+
const { rows, leftOut: leftOutGuesses } = dropUnverifiedGuesses(everyRow);
|
|
153
|
+
const audiences = [...new Set(storedRows.map((stored) => stored.audience))].sort();
|
|
154
|
+
const type = entity.type;
|
|
155
|
+
const name = entity.canonical_name;
|
|
156
|
+
// ---- facts ----
|
|
157
|
+
const facts = effectiveFacts(schema, type, rows).sort((a, b) => {
|
|
158
|
+
const tier = originTier(a.row.by) - originTier(b.row.by);
|
|
159
|
+
if (tier !== 0)
|
|
160
|
+
return tier;
|
|
161
|
+
return byCode(a.row.field, b.row.field) || byCode(a.row.value, b.row.value) || byCode(a.id, b.id);
|
|
162
|
+
});
|
|
163
|
+
const conflicts = [];
|
|
164
|
+
const openFacts = rows.filter((stored) => stored.row.kind === "F" && isOpen(stored.row));
|
|
165
|
+
for (const shown of facts) {
|
|
166
|
+
if (!isSingleValued(schema, type, shown.row))
|
|
167
|
+
continue;
|
|
168
|
+
const others = openFacts.filter((stored) => stored.row.field === shown.row.field && stored.row.value !== shown.row.value);
|
|
169
|
+
if (others.length > 0)
|
|
170
|
+
conflicts.push({ key: shown.row.field, shown, others: others.sort((a, b) => byCode(a.id, b.id)) });
|
|
171
|
+
}
|
|
172
|
+
const conflictOf = (key) => conflicts.find((conflict) => conflict.key === key);
|
|
173
|
+
// ---- edges ----
|
|
174
|
+
const openEdges = rows.filter((stored) => stored.row.kind === "E" && isOpen(stored.row));
|
|
175
|
+
let hiddenEdges = 0;
|
|
176
|
+
const byVerb = new Map();
|
|
177
|
+
for (const stored of openEdges) {
|
|
178
|
+
const spec = schema.link_types[stored.row.verb];
|
|
179
|
+
if (spec?.class === "reference" && stored.row.by === "legacy") {
|
|
180
|
+
hiddenEdges += 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const targets = byVerb.get(stored.row.verb) ?? new Map();
|
|
184
|
+
const slot = targets.get(stored.row.target);
|
|
185
|
+
if (!slot)
|
|
186
|
+
targets.set(stored.row.target, { best: stored, sources: new Set([stored.row.src]) });
|
|
187
|
+
else {
|
|
188
|
+
slot.sources.add(stored.row.src);
|
|
189
|
+
if (betterEdge(stored, slot.best))
|
|
190
|
+
slot.best = stored;
|
|
191
|
+
}
|
|
192
|
+
byVerb.set(stored.row.verb, targets);
|
|
193
|
+
}
|
|
194
|
+
const edgeGroups = [...byVerb.entries()]
|
|
195
|
+
.map(([verb, targets]) => {
|
|
196
|
+
let all = [...targets.values()].sort((a, b) => (betterEdge(a.best, b.best) ? -1 : 1));
|
|
197
|
+
// A single-valued verb with two open targets: the best one is shown and the page flags the rest.
|
|
198
|
+
if (schema.link_types[verb]?.cardinality === "single" && all.length > 1) {
|
|
199
|
+
conflicts.push({ key: verb, shown: all[0].best, others: all.slice(1).map((slot) => slot.best) });
|
|
200
|
+
all = all.slice(0, 1);
|
|
201
|
+
}
|
|
202
|
+
return { verb, total: all.length, shown: all.slice(0, limits.edgesPerVerb).map((slot) => ({ stored: slot.best, sources: slot.sources.size })) };
|
|
203
|
+
})
|
|
204
|
+
.sort((a, b) => {
|
|
205
|
+
const classA = CLASS_ORDER[schema.link_types[a.verb]?.class ?? "reference"] ?? 2;
|
|
206
|
+
const classB = CLASS_ORDER[schema.link_types[b.verb]?.class ?? "reference"] ?? 2;
|
|
207
|
+
if (classA !== classB)
|
|
208
|
+
return classA - classB;
|
|
209
|
+
return byCode(a.verb, b.verb);
|
|
210
|
+
});
|
|
211
|
+
const groupOf = (verb) => edgeGroups.find((group) => group.verb === verb);
|
|
212
|
+
// ---- timeline ----
|
|
213
|
+
const timelineRows = rows.filter((stored) => stored.row.kind === "T");
|
|
214
|
+
const newestFirst = (a, b) => byCode(b.date, a.date) || byCode(a.row.id, b.row.id);
|
|
215
|
+
const allEntries = timelineRows.map((stored) => ({ date: stored.row.date, kind: stored.row.signalType, text: stored.row.text, row: stored })).sort(newestFirst);
|
|
216
|
+
const today = limits.today ?? rows.reduce((max, stored) => {
|
|
217
|
+
const day = stored.row.kind === "T" ? stored.row.date : stored.row.valid.from;
|
|
218
|
+
return day > max ? day : max;
|
|
219
|
+
}, "0000-00-00");
|
|
220
|
+
const closedRows = rows.filter((stored) => stored.row.kind !== "T" && stored.row.valid.to !== undefined);
|
|
221
|
+
// ---- rules summary: one row per sentence, so every sentence has one audience ----
|
|
222
|
+
const summary = [];
|
|
223
|
+
const priority = FACT_PRIORITY[type] ?? [];
|
|
224
|
+
const rank = (field) => (priority.includes(field) ? priority.indexOf(field) : priority.length);
|
|
225
|
+
const factOrder = [...facts].sort((a, b) => rank(a.row.field) - rank(b.row.field) || originTier(a.row.by) - originTier(b.row.by) || byCode(a.row.field, b.row.field));
|
|
226
|
+
const usedFields = new Set();
|
|
227
|
+
for (const stored of factOrder) {
|
|
228
|
+
if (summary.length >= 3)
|
|
229
|
+
break;
|
|
230
|
+
if (usedFields.has(stored.row.field) || IDENTITY_FIELDS.has(stored.row.field))
|
|
231
|
+
continue;
|
|
232
|
+
usedFields.add(stored.row.field);
|
|
233
|
+
summary.push({ text: factSentence(name, type, stored.row), row: stored });
|
|
234
|
+
}
|
|
235
|
+
const edgeRank = (verb) => (EDGE_PRIORITY.includes(verb) ? EDGE_PRIORITY.indexOf(verb) : EDGE_PRIORITY.length);
|
|
236
|
+
let edgeSentences = 0;
|
|
237
|
+
for (const group of [...edgeGroups].sort((a, b) => edgeRank(a.verb) - edgeRank(b.verb) || byCode(a.verb, b.verb))) {
|
|
238
|
+
if (edgeSentences >= 3 || summary.length >= limits.summarySentences - 1)
|
|
239
|
+
break;
|
|
240
|
+
if (schema.link_types[group.verb]?.class !== "state")
|
|
241
|
+
continue;
|
|
242
|
+
const first = group.shown[0];
|
|
243
|
+
if (!first)
|
|
244
|
+
continue;
|
|
245
|
+
summary.push({ text: sentence(`${label(group.verb)} ${nameOf(first.stored.row.target)}`), row: first.stored });
|
|
246
|
+
edgeSentences += 1;
|
|
247
|
+
}
|
|
248
|
+
const latest = allEntries[0];
|
|
249
|
+
if (latest && summary.length < limits.summarySentences) {
|
|
250
|
+
summary.push({ text: sentence(`Latest, a ${latest.kind} on ${latest.date}: ${clip(latest.text, 160)}`), row: latest.row });
|
|
251
|
+
}
|
|
252
|
+
// ---- sections ----
|
|
253
|
+
const sections = [];
|
|
254
|
+
const usedFacts = new Set();
|
|
255
|
+
const usedVerbs = new Set();
|
|
256
|
+
const usedTimeline = new Set();
|
|
257
|
+
const flag = (key) => {
|
|
258
|
+
const conflict = conflictOf(key);
|
|
259
|
+
return conflict ? ` | conflict: ${new Set(conflict.others.map((other) => (other.row.kind === "E" ? other.row.target : other.row.kind === "F" ? other.row.value : ""))).size + 1} open values, showing the one with the highest authority, then the newest` : "";
|
|
260
|
+
};
|
|
261
|
+
const factLine = (title, stored) => {
|
|
262
|
+
usedFacts.add(stored.id);
|
|
263
|
+
return { text: `${title}: ${escapeText(stored.row.value)} | since ${stored.row.valid.from} | by ${stored.row.by}${flag(stored.row.field)}`, row: stored };
|
|
264
|
+
};
|
|
265
|
+
const factLines = (title, field) => facts.filter((stored) => stored.row.field === field).map((stored) => factLine(title, stored));
|
|
266
|
+
const edgeLines = (title, verb, max = limits.edgesPerVerb, only) => {
|
|
267
|
+
const group = groupOf(verb);
|
|
268
|
+
if (!group)
|
|
269
|
+
return [];
|
|
270
|
+
if (!only)
|
|
271
|
+
usedVerbs.add(verb);
|
|
272
|
+
return group.shown
|
|
273
|
+
.filter(({ stored }) => !only || only(stored.row.target))
|
|
274
|
+
.slice(0, max)
|
|
275
|
+
.map(({ stored, sources }) => ({
|
|
276
|
+
text: `${title}: ${escapeText(nameOf(stored.row.target))} (${stored.row.target}) | since ${stored.row.valid.from} | by ${stored.row.by}${sources > 1 ? ` | sources ${sources}` : ""}${flag(verb)}`,
|
|
277
|
+
row: stored,
|
|
278
|
+
}));
|
|
279
|
+
};
|
|
280
|
+
const noteOf = (stored) => {
|
|
281
|
+
const note = options.modelRows?.get(`${stored.entity}|${stored.id}`);
|
|
282
|
+
// The row's own origin first; the model's citation file adds the lines of the source it quoted.
|
|
283
|
+
const by = stored.row.kind === "T" ? (stored.row.by ?? note?.by) : note?.by;
|
|
284
|
+
if (!by)
|
|
285
|
+
return "";
|
|
286
|
+
return ` | by ${by}${note?.lines ? ` | lines ${note.lines[0]}-${note.lines[1]}` : ""}`;
|
|
287
|
+
};
|
|
288
|
+
const timelineLine = (entry) => {
|
|
289
|
+
usedTimeline.add(entry.row.id);
|
|
290
|
+
for (const row of entry.also ?? [])
|
|
291
|
+
usedTimeline.add(row.id);
|
|
292
|
+
return { text: `${entry.date} | ${entry.kind} | ${escapeText(entry.text)}${noteOf(entry.row)}`, row: entry.row, ...(entry.also ? { also: entry.also } : {}) };
|
|
293
|
+
};
|
|
294
|
+
const counted = (title, shown, total) => (shown < total ? `${title} (${shown} of ${total})` : `${title} (${total})`);
|
|
295
|
+
const add = (title, lines, level = 2) => {
|
|
296
|
+
if (lines.length > 0)
|
|
297
|
+
sections.push({ title, level, lines });
|
|
298
|
+
};
|
|
299
|
+
/** Decisions about this entity: timeline rows of type decision and edges to decision entities, duplicates folded. */
|
|
300
|
+
let decisionsListed = false;
|
|
301
|
+
const decisionSection = () => {
|
|
302
|
+
decisionsListed = true;
|
|
303
|
+
const items = allEntries.filter((entry) => entry.kind === "decision").slice(0, 200);
|
|
304
|
+
usedVerbs.add("produced_decision");
|
|
305
|
+
for (const verb of ["produced_decision", "discussed_in", "decided"]) {
|
|
306
|
+
for (const stored of openEdges) {
|
|
307
|
+
if (stored.row.verb !== verb || !stored.row.target.startsWith("decision/"))
|
|
308
|
+
continue;
|
|
309
|
+
items.push({ date: stored.row.valid.from, kind: "decision", text: nameOf(stored.row.target), row: stored });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (items.length === 0)
|
|
313
|
+
return;
|
|
314
|
+
const folded = foldSame(items.sort(newestFirst));
|
|
315
|
+
const shown = folded.slice(0, limits.decisions);
|
|
316
|
+
add(counted("Decisions", shown.length, folded.length), shown.map(timelineLine));
|
|
317
|
+
for (const entry of folded) {
|
|
318
|
+
usedTimeline.add(entry.row.id);
|
|
319
|
+
for (const row of entry.also ?? [])
|
|
320
|
+
usedTimeline.add(row.id);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
const timelineSection = (title, entries, max) => {
|
|
324
|
+
const folded = foldSame(entries);
|
|
325
|
+
const shown = folded.slice(0, max);
|
|
326
|
+
add(shown.length < folded.length ? `${title} (newest ${shown.length} of ${folded.length})` : `${title} (${folded.length})`, shown.map(timelineLine));
|
|
327
|
+
};
|
|
328
|
+
const remainingTimeline = () => allEntries.filter((entry) => !usedTimeline.has(entry.row.id));
|
|
329
|
+
if (type === "person") {
|
|
330
|
+
add("Role and organization", [
|
|
331
|
+
...factLines("Role", "role_title"),
|
|
332
|
+
...edgeLines("Employer", "works_at", 3),
|
|
333
|
+
...(groupOf("works_at") ? [] : factLines("Affiliation", "affiliation")),
|
|
334
|
+
...edgeLines("Holds role", "holds_role", 3),
|
|
335
|
+
...edgeLines("Team", "member_of", 5),
|
|
336
|
+
...edgeLines("Manager", "reports_to", 1),
|
|
337
|
+
...edgeLines("Reports", "manages"),
|
|
338
|
+
...factLines("Status", "status"),
|
|
339
|
+
]);
|
|
340
|
+
const work = [];
|
|
341
|
+
for (const verb of ["leads", "owns", "works_on"]) {
|
|
342
|
+
const group = groupOf(verb);
|
|
343
|
+
if (!group)
|
|
344
|
+
continue;
|
|
345
|
+
usedVerbs.add(verb);
|
|
346
|
+
for (const { stored } of group.shown)
|
|
347
|
+
work.push({ stored, verb });
|
|
348
|
+
}
|
|
349
|
+
work.sort((a, b) => byCode(b.stored.row.valid.from, a.stored.row.valid.from) || byCode(a.stored.id, b.stored.id));
|
|
350
|
+
const total = ["leads", "owns", "works_on"].reduce((sum, verb) => sum + (groupOf(verb)?.total ?? 0), 0);
|
|
351
|
+
const shown = work.slice(0, 15);
|
|
352
|
+
add(counted("Working on now", shown.length, total), shown.map(({ stored, verb }) => ({
|
|
353
|
+
text: `${verb} ${escapeText(nameOf(stored.row.target))} (${stored.row.target}) | since ${stored.row.valid.from} | by ${stored.row.by}`,
|
|
354
|
+
row: stored,
|
|
355
|
+
})));
|
|
356
|
+
timelineSection("Recent timeline", allEntries, limits.timeline);
|
|
357
|
+
}
|
|
358
|
+
else if (type === "project" || type === "product") {
|
|
359
|
+
add("Status and ownership", [
|
|
360
|
+
...factLines("Status", "status"),
|
|
361
|
+
...factLines("Stage", "stage"),
|
|
362
|
+
...edgeLines("Owner", "owned_by", 1),
|
|
363
|
+
...edgeLines("Lead", "led_by", 3),
|
|
364
|
+
...factLines("Summary", "summary"),
|
|
365
|
+
...factLines("Started", "started"),
|
|
366
|
+
...factLines("Target date", "target_date"),
|
|
367
|
+
]);
|
|
368
|
+
add(counted("Team", Math.min(groupOf("has_contributor")?.total ?? 0, limits.edgesPerVerb), groupOf("has_contributor")?.total ?? 0), edgeLines("Contributor", "has_contributor"));
|
|
369
|
+
add("Customer", edgeLines("Customer", "part_of", 5, (target) => target.startsWith("company/")));
|
|
370
|
+
const since = addDays(today, -limits.recentDays);
|
|
371
|
+
const recent = allEntries.filter((entry) => entry.date >= since && entry.kind !== "decision");
|
|
372
|
+
timelineSection(`Last ${limits.recentDays} days to ${today}`, recent, limits.timeline);
|
|
373
|
+
decisionSection();
|
|
374
|
+
timelineSection("Earlier timeline", remainingTimeline(), limits.timeline);
|
|
375
|
+
}
|
|
376
|
+
else if (type === "company") {
|
|
377
|
+
// The org seed writes several relation values; the ones that say what the company is to us come first.
|
|
378
|
+
const relationRank = ["customer", "prospect", "former customer", "partner", "investor", "vendor", "self", "billing-account"];
|
|
379
|
+
const relationOrder = (value) => (relationRank.includes(value) ? relationRank.indexOf(value) : relationRank.length - 1);
|
|
380
|
+
add("Account", [
|
|
381
|
+
...factLines("Relation", "relation").sort((a, b) => relationOrder(a.row.row.value) - relationOrder(b.row.row.value)),
|
|
382
|
+
...factLines("Stage", "stage"),
|
|
383
|
+
...factLines("CRM status", "crm_status"),
|
|
384
|
+
...factLines("Account owner", "owner"),
|
|
385
|
+
...edgeLines("Customer of", "customer_of", 3),
|
|
386
|
+
]);
|
|
387
|
+
add(counted("Contacts", Math.min(groupOf("employs")?.total ?? 0, limits.edgesPerVerb), groupOf("employs")?.total ?? 0), edgeLines("Contact", "employs"));
|
|
388
|
+
const since = addDays(today, -90);
|
|
389
|
+
const commitments = allEntries.filter((entry) => (entry.kind === "commitment" || entry.kind === "action_item") && entry.date >= since);
|
|
390
|
+
if (commitments.length > 0)
|
|
391
|
+
timelineSection(`Commitments and action items, 90 days to ${today}`, commitments, limits.commitments);
|
|
392
|
+
const meetings = openEdges
|
|
393
|
+
.filter((stored) => stored.row.verb === "discussed_in" && stored.row.target.startsWith("meeting/"))
|
|
394
|
+
.sort((a, b) => byCode(b.row.valid.from, a.row.valid.from) || byCode(a.id, b.id));
|
|
395
|
+
const seenMeetings = new Set();
|
|
396
|
+
const meetingLines = [];
|
|
397
|
+
for (const stored of meetings) {
|
|
398
|
+
if (seenMeetings.has(stored.row.target))
|
|
399
|
+
continue;
|
|
400
|
+
seenMeetings.add(stored.row.target);
|
|
401
|
+
if (meetingLines.length < 10)
|
|
402
|
+
meetingLines.push({ text: `${stored.row.valid.from} | ${escapeText(nameOf(stored.row.target))} (${stored.row.target})`, row: stored });
|
|
403
|
+
}
|
|
404
|
+
add(counted("Recent meetings", meetingLines.length, seenMeetings.size), meetingLines);
|
|
405
|
+
decisionSection();
|
|
406
|
+
timelineSection("Recent timeline", remainingTimeline(), limits.timeline);
|
|
407
|
+
}
|
|
408
|
+
else if (type === "meeting") {
|
|
409
|
+
const pick = (kinds) => allEntries.filter((entry) => kinds.includes(entry.kind));
|
|
410
|
+
add("What was said", foldSame(pick(["summary"])).map(timelineLine));
|
|
411
|
+
decisionSection();
|
|
412
|
+
add("Action items", foldSame(pick(["action_item", "commitment"])).map(timelineLine));
|
|
413
|
+
add(counted("Attendees", Math.min(groupOf("had_attendee")?.total ?? 0, limits.edgesPerVerb), groupOf("had_attendee")?.total ?? 0), edgeLines("Attendee", "had_attendee"));
|
|
414
|
+
add(counted("Topics", Math.min(groupOf("about")?.total ?? 0, limits.edgesPerVerb), groupOf("about")?.total ?? 0), edgeLines("About", "about"));
|
|
415
|
+
add("Details", [...factLines("Date", "date"), ...factLines("Title", "title"), ...factLines("Channel", "channel")]);
|
|
416
|
+
timelineSection("Timeline", remainingTimeline(), limits.timeline);
|
|
417
|
+
}
|
|
418
|
+
else if (type === "team") {
|
|
419
|
+
add("Team", [...factLines("Purpose", "purpose"), ...edgeLines("Lead", "led_by", 3), ...factLines("Status", "status"), ...edgeLines("Part of", "part_of", 3)]);
|
|
420
|
+
add(counted("Members", Math.min(groupOf("has_member")?.total ?? 0, limits.edgesPerVerb), groupOf("has_member")?.total ?? 0), edgeLines("Member", "has_member"));
|
|
421
|
+
decisionSection();
|
|
422
|
+
timelineSection("Recent timeline", remainingTimeline(), limits.timeline);
|
|
423
|
+
}
|
|
424
|
+
else if (type === "role") {
|
|
425
|
+
add("Role", [...factLines("Title", "title"), ...factLines("Scope", "scope"), ...edgeLines("Held by", "held_by"), ...edgeLines("Part of", "part_of", 3)]);
|
|
426
|
+
timelineSection("Timeline", remainingTimeline(), limits.timeline);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
if (type !== "decision")
|
|
430
|
+
decisionSection();
|
|
431
|
+
timelineSection("Timeline", remainingTimeline(), limits.timeline);
|
|
432
|
+
}
|
|
433
|
+
const otherFacts = facts.filter((stored) => !usedFacts.has(stored.id));
|
|
434
|
+
add(sections.length === 0 || type === "decision" || !FACT_PRIORITY[type] ? "Facts" : "Other facts", otherFacts.map((stored) => ({
|
|
435
|
+
text: `${stored.row.field} = ${escapeText(stored.row.value)} | since ${stored.row.valid.from} | by ${stored.row.by} | conf ${formatConf(stored.row.conf)}${flag(stored.row.field)}`,
|
|
436
|
+
row: stored,
|
|
437
|
+
})));
|
|
438
|
+
// Links to decision entities are already under Decisions.
|
|
439
|
+
const inDecisions = (group) => decisionsListed && (group.verb === "discussed_in" || group.verb === "decided")
|
|
440
|
+
? { ...group, shown: group.shown.filter(({ stored }) => !stored.row.target.startsWith("decision/")) }
|
|
441
|
+
: group;
|
|
442
|
+
const otherGroups = edgeGroups.filter((group) => !usedVerbs.has(group.verb)).map(inDecisions).filter((group) => group.shown.length > 0);
|
|
443
|
+
if (otherGroups.length > 0) {
|
|
444
|
+
sections.push({ title: usedVerbs.size > 0 ? "Other relationships" : "Relationships", level: 2, lines: [] });
|
|
445
|
+
for (const group of otherGroups) {
|
|
446
|
+
sections.push({
|
|
447
|
+
title: group.shown.length < group.total ? `${group.verb} (${group.shown.length} of ${group.total})` : `${group.verb} (${group.shown.length})`,
|
|
448
|
+
level: 3,
|
|
449
|
+
lines: group.shown.map(({ stored, sources }) => ({
|
|
450
|
+
text: `${stored.row.verb} -> ${stored.row.target} (${escapeText(nameOf(stored.row.target))}) | since ${stored.row.valid.from} | by ${stored.row.by} | conf ${formatConf(stored.row.conf)}${sources > 1 ? ` | sources ${sources}` : ""}${flag(group.verb)}`,
|
|
451
|
+
row: stored,
|
|
452
|
+
})),
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (closedRows.length > 0) {
|
|
457
|
+
const sorted = [...closedRows].sort((a, b) => byCode(b.row.valid.to ?? "", a.row.valid.to ?? "") || byCode(a.id, b.id));
|
|
458
|
+
sections.push({
|
|
459
|
+
title: limits.showClosed ? `History (${closedRows.length} closed rows)` : `History (${closedRows.length} closed rows hidden)`,
|
|
460
|
+
level: 2,
|
|
461
|
+
lines: !limits.showClosed
|
|
462
|
+
? []
|
|
463
|
+
: sorted.map((stored) => {
|
|
464
|
+
const row = stored.row;
|
|
465
|
+
const what = row.kind === "F" ? `${row.field} = ${escapeText(row.value)}` : `${row.verb} -> ${row.target} (${escapeText(nameOf(row.target))})`;
|
|
466
|
+
return { text: `${what} | from ${row.valid.from} to ${row.valid.to ?? ""} | by ${row.by}`, row: stored };
|
|
467
|
+
}),
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
const rowsHash = sha256Hex(rows
|
|
471
|
+
.map((stored) => `${stored.id}:${stored.audience}:${stored.row.kind !== "T" && stored.row.valid.to !== undefined ? stored.row.valid.to : ""}`)
|
|
472
|
+
.sort()
|
|
473
|
+
.join("\n")).slice(0, 16);
|
|
474
|
+
const shownTimeline = foldSame(allEntries).slice(0, limits.timeline);
|
|
475
|
+
return {
|
|
476
|
+
entity,
|
|
477
|
+
audiences,
|
|
478
|
+
facts,
|
|
479
|
+
edgeGroups,
|
|
480
|
+
timeline: shownTimeline,
|
|
481
|
+
timelineTotal: allEntries.length,
|
|
482
|
+
signals: timelineRows.length,
|
|
483
|
+
counts: {
|
|
484
|
+
facts: everyRow.filter((stored) => stored.row.kind === "F").length,
|
|
485
|
+
edges: everyRow.filter((stored) => stored.row.kind === "E").length,
|
|
486
|
+
timeline: timelineRows.length,
|
|
487
|
+
},
|
|
488
|
+
hiddenEdges,
|
|
489
|
+
leftOutGuesses,
|
|
490
|
+
closedHidden: limits.showClosed ? 0 : closedRows.length,
|
|
491
|
+
conflicts,
|
|
492
|
+
rulesSummary: summary,
|
|
493
|
+
sections,
|
|
494
|
+
rowsHash,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
/** `@company`, `@local` or `@<16 hex>`: the marker a page line carries for its audience. */
|
|
498
|
+
export function audienceMarker(audience) {
|
|
499
|
+
return `@${audience}`;
|
|
500
|
+
}
|
|
501
|
+
/** ` | @<audience> | row <id> | src <ref>`: the tail every bullet line of a page carries. */
|
|
502
|
+
export function citeTail(stored) {
|
|
503
|
+
return ` | ${audienceMarker(stored.audience)} | row ${stored.id} | src ${escapeText(stored.row.src)}`;
|
|
504
|
+
}
|
|
505
|
+
const SRC = "(?:signal|source|doc|session|record|legacy):\\S";
|
|
506
|
+
const CITED_LINE = new RegExp(`^- \\S.* \\| @(company|local|[0-9a-f]{16}) \\| row [0-9a-f]{12} \\| src ${SRC}.*$`);
|
|
507
|
+
const MARKER = / \| @(company|local|[0-9a-f]{16}) \| row [0-9a-f]{12} \| src /;
|
|
508
|
+
/** The audience a page line is marked with, or null for a line with no marker (a heading, or a line that must not be shown). */
|
|
509
|
+
export function pageLineAudience(line) {
|
|
510
|
+
const match = MARKER.exec(line);
|
|
511
|
+
return match ? match[1] : null;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Body lines of a page that are not cited. Headings and blank lines carry no
|
|
515
|
+
* claim; every other line must be a bullet ending in an audience marker, a row
|
|
516
|
+
* id and a source.
|
|
517
|
+
*/
|
|
518
|
+
export function uncitedPageLines(pageText) {
|
|
519
|
+
const lines = pageText.split("\n");
|
|
520
|
+
let start = 0;
|
|
521
|
+
if (lines[0] === "---") {
|
|
522
|
+
const end = lines.indexOf("---", 1);
|
|
523
|
+
start = end === -1 ? lines.length : end + 1;
|
|
524
|
+
}
|
|
525
|
+
const out = [];
|
|
526
|
+
for (const line of lines.slice(start)) {
|
|
527
|
+
if (line.trim() === "" || line.startsWith("#"))
|
|
528
|
+
continue;
|
|
529
|
+
if (!CITED_LINE.test(line))
|
|
530
|
+
out.push(line);
|
|
531
|
+
}
|
|
532
|
+
return out;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* The page as a caller with these audiences may see it. A bullet line is kept
|
|
536
|
+
* only when its marker is one of `audiences`; a line with no marker is dropped,
|
|
537
|
+
* so nothing unmarked is ever shown. A heading with no line left under it goes
|
|
538
|
+
* too, and when anything was removed the counts in headings and frontmatter
|
|
539
|
+
* are dropped with it, so the page does not say how much the caller cannot see.
|
|
540
|
+
*/
|
|
541
|
+
export function filterPageLines(pageText, audiences) {
|
|
542
|
+
const allowed = new Set(audiences);
|
|
543
|
+
const lines = pageText.split("\n");
|
|
544
|
+
let start = 0;
|
|
545
|
+
let front = [];
|
|
546
|
+
if (lines[0] === "---") {
|
|
547
|
+
const end = lines.indexOf("---", 1);
|
|
548
|
+
start = end === -1 ? lines.length : end + 1;
|
|
549
|
+
front = lines.slice(0, start);
|
|
550
|
+
}
|
|
551
|
+
const blocks = [{ heading: null, level: 0, bullets: [] }];
|
|
552
|
+
let kept = 0;
|
|
553
|
+
let removed = 0;
|
|
554
|
+
for (const line of lines.slice(start)) {
|
|
555
|
+
if (line.trim() === "")
|
|
556
|
+
continue;
|
|
557
|
+
const heading = /^(#{1,6}) /.exec(line);
|
|
558
|
+
if (heading) {
|
|
559
|
+
blocks.push({ heading: line, level: heading[1].length, bullets: [] });
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
const audience = pageLineAudience(line);
|
|
563
|
+
if (audience !== null && allowed.has(audience)) {
|
|
564
|
+
blocks[blocks.length - 1].bullets.push(line);
|
|
565
|
+
kept += 1;
|
|
566
|
+
}
|
|
567
|
+
else
|
|
568
|
+
removed += 1;
|
|
569
|
+
}
|
|
570
|
+
const out = [];
|
|
571
|
+
blocks.forEach((block, i) => {
|
|
572
|
+
if (block.heading === null) {
|
|
573
|
+
out.push(...block.bullets);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
// A heading stays when it has a line, or a deeper heading under it has one.
|
|
577
|
+
let alive = block.bullets.length > 0 || block.level === 1;
|
|
578
|
+
for (let j = i + 1; !alive && j < blocks.length && blocks[j].level > block.level; j += 1)
|
|
579
|
+
alive = blocks[j].bullets.length > 0;
|
|
580
|
+
if (!alive)
|
|
581
|
+
return;
|
|
582
|
+
if (out.length > 0)
|
|
583
|
+
out.push("");
|
|
584
|
+
out.push(removed > 0 ? block.heading.replace(/ \([^()]*\)$/, "") : block.heading, ...block.bullets);
|
|
585
|
+
});
|
|
586
|
+
if (removed > 0 && front.length > 0) {
|
|
587
|
+
const parsed = yaml.load(front.slice(1, -1).join("\n"));
|
|
588
|
+
const keep = {};
|
|
589
|
+
for (const key of ["id", "type", "name", "aliases"])
|
|
590
|
+
if (parsed && parsed[key] !== undefined)
|
|
591
|
+
keep[key] = parsed[key];
|
|
592
|
+
keep.audiences = (Array.isArray(parsed?.audiences) ? parsed.audiences : []).filter((value) => typeof value === "string" && allowed.has(value));
|
|
593
|
+
keep.filtered = true;
|
|
594
|
+
front = ["---", yaml.dump(keep, { lineWidth: -1, noRefs: true, flowLevel: 1, sortKeys: false }).trimEnd(), "---"];
|
|
595
|
+
}
|
|
596
|
+
return { text: `${[...front, ...out].join("\n").replace(/\n+$/, "")}\n`, kept, removed };
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* The lines offered to the model summary, with the row behind each label. Only
|
|
600
|
+
* rows of one audience are offered (`company` when the entity has any, else its
|
|
601
|
+
* first audience), so a summary sentence can never carry words from a narrower
|
|
602
|
+
* audience under a wider marker.
|
|
603
|
+
*/
|
|
604
|
+
export function summaryInput(model, nameOf) {
|
|
605
|
+
const lines = [];
|
|
606
|
+
const rows = new Map();
|
|
607
|
+
const present = new Set([...model.facts, ...model.edgeGroups.flatMap((group) => group.shown.map((shown) => shown.stored)), ...model.timeline.map((entry) => entry.row)].map((stored) => stored.audience));
|
|
608
|
+
// What an audience has to say beyond links to documents that mention the entity. A customer whose only
|
|
609
|
+
// company-wide rows are two knowledge documents is summarized from the audience that holds its account lines.
|
|
610
|
+
const weight = new Map();
|
|
611
|
+
const weigh = (key) => void weight.set(key, (weight.get(key) ?? 0) + 1);
|
|
612
|
+
for (const stored of model.facts)
|
|
613
|
+
if (!IDENTITY_FIELDS.has(stored.row.field))
|
|
614
|
+
weigh(stored.audience);
|
|
615
|
+
for (const group of model.edgeGroups)
|
|
616
|
+
for (const shown of group.shown)
|
|
617
|
+
weigh(shown.stored.audience);
|
|
618
|
+
for (const entry of model.timeline)
|
|
619
|
+
if (entry.kind !== "doc")
|
|
620
|
+
weigh(entry.row.audience);
|
|
621
|
+
const heaviest = [...weight].sort((x, y) => y[1] - x[1] || (x[0] < y[0] ? -1 : 1))[0]?.[0];
|
|
622
|
+
const audience = (weight.get("company") ?? 0) > 0 ? "company" : (heaviest ?? (present.has("company") ? "company" : ([...present].sort()[0] ?? null)));
|
|
623
|
+
model.facts.filter((stored) => stored.audience === audience && !IDENTITY_FIELDS.has(stored.row.field)).slice(0, 20).forEach((stored, i) => {
|
|
624
|
+
const key = `f${i + 1}`;
|
|
625
|
+
rows.set(key, stored);
|
|
626
|
+
lines.push({ label: key, text: `${stored.row.field} = ${clip(stored.row.value, 200)} (since ${stored.row.valid.from})` });
|
|
627
|
+
});
|
|
628
|
+
let e = 0;
|
|
629
|
+
for (const group of model.edgeGroups) {
|
|
630
|
+
for (const shown of group.shown.filter((entry) => entry.stored.audience === audience).slice(0, 5)) {
|
|
631
|
+
if (e >= 20)
|
|
632
|
+
break;
|
|
633
|
+
e += 1;
|
|
634
|
+
const key = `e${e}`;
|
|
635
|
+
rows.set(key, shown.stored);
|
|
636
|
+
lines.push({ label: key, text: `${group.verb} ${clip(nameOf(shown.stored.row.target), 60)} [${shown.stored.row.target.split("/")[0]}] since ${shown.stored.row.valid.from}` });
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
model.timeline.filter((entry) => entry.row.audience === audience).slice(0, 25).forEach((entry, i) => {
|
|
640
|
+
const key = `t${i + 1}`;
|
|
641
|
+
rows.set(key, entry.row);
|
|
642
|
+
lines.push({ label: key, text: `${entry.date} ${entry.kind}: ${clip(entry.text, 180)}` });
|
|
643
|
+
});
|
|
644
|
+
return { item: { ref: model.entity.id, name: model.entity.canonical_name, lines }, rows, audience };
|
|
645
|
+
}
|
|
646
|
+
/** The page text. `summary` is the optional model layer; without it the rules sentences are the summary. */
|
|
647
|
+
export function renderPage(model, nameOf, summary, state = "rules") {
|
|
648
|
+
void nameOf;
|
|
649
|
+
const entity = model.entity;
|
|
650
|
+
const frontmatter = {
|
|
651
|
+
id: entity.id,
|
|
652
|
+
type: entity.type,
|
|
653
|
+
name: entity.canonical_name,
|
|
654
|
+
aliases: entity.aliases,
|
|
655
|
+
first_seen: entity.first_seen,
|
|
656
|
+
last_updated: entity.last_updated,
|
|
657
|
+
audiences: model.audiences,
|
|
658
|
+
rows: model.counts,
|
|
659
|
+
signals: model.signals,
|
|
660
|
+
summary_by: summary ? summary.by : "rules",
|
|
661
|
+
...(summary ? {} : state === "rules" ? {} : { model_summary: state }),
|
|
662
|
+
...(model.hiddenEdges > 0 ? { hidden_legacy_reference_edges: model.hiddenEdges } : {}),
|
|
663
|
+
...(model.leftOutGuesses > 0 ? { unconfirmed_model_guesses_left_out: model.leftOutGuesses } : {}),
|
|
664
|
+
...(model.closedHidden > 0 ? { closed_rows_hidden: model.closedHidden } : {}),
|
|
665
|
+
...(model.conflicts.length > 0 ? { conflicts: model.conflicts.map((conflict) => conflict.key).sort() } : {}),
|
|
666
|
+
rows_hash: model.rowsHash,
|
|
667
|
+
};
|
|
668
|
+
const out = ["---", yaml.dump(frontmatter, { lineWidth: -1, noRefs: true, flowLevel: 1, sortKeys: false }).trimEnd(), "---", `# ${entity.canonical_name.replace(/\s+/g, " ")}`, ""];
|
|
669
|
+
const tail = (cited) => `${citeTail(cited.row)}${(cited.also ?? []).map((row) => ` | also row ${row.id} | src ${escapeText(row.row.src)}`).join("")}`;
|
|
670
|
+
// A summary sentence is plain text and is escaped here; a section line was put together from escaped values.
|
|
671
|
+
const bullet = (cited) => `- ${escapeText(cited.text)}${tail(cited)}`;
|
|
672
|
+
const line = (cited) => `- ${cited.text}${tail(cited)}`;
|
|
673
|
+
if (summary && summary.sentences.length > 0) {
|
|
674
|
+
out.push(`## Summary (by ${summary.by})`, ...summary.sentences.map(bullet), "");
|
|
675
|
+
if (model.rulesSummary.length > 0)
|
|
676
|
+
out.push("## At a glance", ...model.rulesSummary.map(bullet), "");
|
|
677
|
+
}
|
|
678
|
+
else if (model.rulesSummary.length > 0) {
|
|
679
|
+
out.push("## Summary", ...model.rulesSummary.map(bullet), "");
|
|
680
|
+
}
|
|
681
|
+
for (const section of model.sections) {
|
|
682
|
+
if (section.level === 3 && out[out.length - 1] === "")
|
|
683
|
+
out.pop();
|
|
684
|
+
out.push(`${"#".repeat(section.level)} ${section.title}`, ...section.lines.map(line), "");
|
|
685
|
+
}
|
|
686
|
+
return `${out.join("\n").replace(/\n+$/, "")}\n`;
|
|
687
|
+
}
|
|
688
|
+
//# sourceMappingURL=render.js.map
|