@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,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-E: `hq ontology brief` writes `brief.md`, the small summary a session
|
|
3
|
+
* starts with (design 4.2). The SessionStart hook prints the file as is; it
|
|
4
|
+
* never walks the graph, so everything a session should know up front is
|
|
5
|
+
* decided here.
|
|
6
|
+
*
|
|
7
|
+
* Sections: who the member is, their manager and teams; active projects with
|
|
8
|
+
* owner and stage; top customers with stage; what changed in the last 7 days;
|
|
9
|
+
* the four commands that return more. The text is kept under
|
|
10
|
+
* `BRIEF_MAX_TOKENS` by a character estimate that overstates the count, and
|
|
11
|
+
* by dropping list lines from the longest section until it fits.
|
|
12
|
+
*/
|
|
13
|
+
import { isUnverifiedGuess, originTier } from "../schema/index.js";
|
|
14
|
+
import { GRAPH_PATHS, atomicWriteFile, graphPath, openGraphStore } from "../store/index.js";
|
|
15
|
+
import { COMPANY_AUDIENCE, } from "../types.js";
|
|
16
|
+
import { graphExists, loadReadIndex, rowVisible, visible, } from "./graph-index.js";
|
|
17
|
+
import { indexedFacts } from "./names.js";
|
|
18
|
+
import { readReaderSetting } from "./reader-setting.js";
|
|
19
|
+
export const BRIEF_MAX_TOKENS = 1500;
|
|
20
|
+
export const BRIEF_MAX_PROJECTS = 15;
|
|
21
|
+
export const BRIEF_MAX_CUSTOMERS = 8;
|
|
22
|
+
export const BRIEF_MAX_CHANGES = 12;
|
|
23
|
+
export const BRIEF_WINDOW_DAYS = 7;
|
|
24
|
+
/**
|
|
25
|
+
* Upper estimate of the token count. English prose runs near four characters
|
|
26
|
+
* a token; ids, dates and slugs run shorter, so three is used.
|
|
27
|
+
*/
|
|
28
|
+
export function estimateTokens(text) {
|
|
29
|
+
return Math.ceil(text.length / 3);
|
|
30
|
+
}
|
|
31
|
+
const ENDED = /\b(done|complete|completed|shipped|archived|cancell?ed|closed|paused|dead|deprecated|abandoned|inactive|retired)\b/i;
|
|
32
|
+
function clip(text, max) {
|
|
33
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
34
|
+
return flat.length <= max ? flat : `${flat.slice(0, max - 1)}…`;
|
|
35
|
+
}
|
|
36
|
+
function isoDay(date) {
|
|
37
|
+
return date.toISOString().slice(0, 10);
|
|
38
|
+
}
|
|
39
|
+
function factValue(index, schema, entity, filter, field) {
|
|
40
|
+
return indexedFacts(index, schema, entity, filter).find((stored) => stored.row.field === field)?.row.value ?? "";
|
|
41
|
+
}
|
|
42
|
+
function openEdges(store, ref, filter) {
|
|
43
|
+
const rows = store.readRows(ref, {
|
|
44
|
+
kinds: ["E"],
|
|
45
|
+
openOnly: true,
|
|
46
|
+
...(filter === null ? {} : { audiences: [...filter] }),
|
|
47
|
+
});
|
|
48
|
+
return rows
|
|
49
|
+
.filter((stored) => stored.row.kind === "E" && !stored.row.valid.to && rowVisible(stored.audience, filter))
|
|
50
|
+
.sort((a, b) => originTier(a.row.by) - originTier(b.row.by) ||
|
|
51
|
+
(a.row.valid.from < b.row.valid.from ? 1 : a.row.valid.from > b.row.valid.from ? -1 : 0) ||
|
|
52
|
+
(a.row.target < b.row.target ? -1 : 1));
|
|
53
|
+
}
|
|
54
|
+
function findMember(context, index, filter, extras) {
|
|
55
|
+
const named = extras.memberEntity ?? readReaderSetting(context.hqRoot).member;
|
|
56
|
+
if (named) {
|
|
57
|
+
const position = index.byId.get(named);
|
|
58
|
+
const entity = position === undefined ? undefined : index.entities[position];
|
|
59
|
+
if (entity && entity.type === "person" && visible(entity, filter))
|
|
60
|
+
return entity;
|
|
61
|
+
}
|
|
62
|
+
const uid = context.member?.personUid.toLowerCase();
|
|
63
|
+
if (uid) {
|
|
64
|
+
for (const [key, list] of index.byKey) {
|
|
65
|
+
if (key !== uid && !key.endsWith(`:${uid}`))
|
|
66
|
+
continue;
|
|
67
|
+
const entity = index.entities[list[0] ?? -1];
|
|
68
|
+
if (list.length === 1 && entity && entity.type === "person" && visible(entity, filter))
|
|
69
|
+
return entity;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function render(sections) {
|
|
75
|
+
const block = (title, lines) => (lines.length > 0 ? ["", `## ${title}`, ...lines] : []);
|
|
76
|
+
return [
|
|
77
|
+
...sections.head,
|
|
78
|
+
...block("You", sections.you),
|
|
79
|
+
...block("Active projects", sections.projects),
|
|
80
|
+
...block("Top customers", sections.customers),
|
|
81
|
+
...block(`Last ${String(BRIEF_WINDOW_DAYS)} days`, sections.changes),
|
|
82
|
+
...block("Ask the graph before answering about people, projects, customers or decisions", sections.commands),
|
|
83
|
+
"",
|
|
84
|
+
].join("\n");
|
|
85
|
+
}
|
|
86
|
+
/** Builds the brief text. Pure apart from reads through the store. */
|
|
87
|
+
export function buildBrief(context, extras = {}) {
|
|
88
|
+
const store = extras.store ?? openGraphStore(context.graphRoot, { company: context.company });
|
|
89
|
+
const schema = store.schema();
|
|
90
|
+
const index = loadReadIndex(context.graphRoot, { store });
|
|
91
|
+
const filter = extras.audiences
|
|
92
|
+
? new Set(extras.audiences)
|
|
93
|
+
: context.member
|
|
94
|
+
? new Set([COMPANY_AUDIENCE, ...context.member.audienceKeys])
|
|
95
|
+
: null;
|
|
96
|
+
const now = extras.now ?? new Date();
|
|
97
|
+
const today = isoDay(now);
|
|
98
|
+
const cutoff = isoDay(new Date(now.getTime() - BRIEF_WINDOW_DAYS * 86_400_000));
|
|
99
|
+
const shown = index.entities.filter((entity) => visible(entity, filter));
|
|
100
|
+
const label = (ref) => {
|
|
101
|
+
const entity = index.entities[index.byId.get(ref) ?? -1];
|
|
102
|
+
return entity && visible(entity, filter) ? `${clip(entity.name, 40)} (${ref})` : ref;
|
|
103
|
+
};
|
|
104
|
+
const newest = shown.reduce((latest, entity) => (entity.last > latest ? entity.last : latest), "");
|
|
105
|
+
const sections = {
|
|
106
|
+
head: [
|
|
107
|
+
`# Company graph brief: ${context.company}`,
|
|
108
|
+
`Generated ${today}. ${String(shown.length)} entities; newest fact ${newest || "none"}. Facts in the graph carry a source and a date. This brief is a summary: look a thing up before stating it as fact.`,
|
|
109
|
+
],
|
|
110
|
+
you: [],
|
|
111
|
+
projects: [],
|
|
112
|
+
customers: [],
|
|
113
|
+
changes: [],
|
|
114
|
+
commands: [
|
|
115
|
+
`- \`hq ontology lookup "<name or id>" --company ${context.company}\`: one entity, its current facts and main relationships.`,
|
|
116
|
+
`- \`hq ontology neighbors <id> [--verb V] --company ${context.company}\`: everything one step away, with sources and recent signals.`,
|
|
117
|
+
`- \`hq ontology search "<words>" --company ${context.company}\`: find entities by name, alias or fact text.`,
|
|
118
|
+
`- \`hq ontology traverse <id> [--verb V] [--depth 1-3] --company ${context.company}\`: follow relationships outward.`,
|
|
119
|
+
"A name that matches several entities returns candidates. Pick an id from them; do not guess.",
|
|
120
|
+
"Use the graph to find where a thing is written down. Each fact and relationship prints a `file:` path: open it and confirm before you answer.",
|
|
121
|
+
"The graph does not hold everything. When it has little or nothing on a name, search the vault; never answer that a thing is not known because the graph lacks it.",
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
// Who the member is.
|
|
125
|
+
const member = findMember(context, index, filter, extras);
|
|
126
|
+
if (member) {
|
|
127
|
+
const role = factValue(index, schema, member, filter, "role_title");
|
|
128
|
+
const edges = openEdges(store, member.id, filter);
|
|
129
|
+
const targets = (verb, cap) => edges.filter((stored) => stored.row.verb === verb).slice(0, cap).map((stored) => label(stored.row.target));
|
|
130
|
+
sections.you.push(`- ${member.name} (${member.id})${role ? `, ${clip(role, 60)}` : ""}`);
|
|
131
|
+
const manager = targets("reports_to", 1);
|
|
132
|
+
if (manager.length > 0)
|
|
133
|
+
sections.you.push(`- Reports to: ${manager.join(", ")}`);
|
|
134
|
+
const teams = targets("member_of", 3);
|
|
135
|
+
if (teams.length > 0)
|
|
136
|
+
sections.you.push(`- Teams: ${teams.join(", ")}`);
|
|
137
|
+
const leads = targets("leads", 3);
|
|
138
|
+
if (leads.length > 0)
|
|
139
|
+
sections.you.push(`- Leads: ${leads.join(", ")}`);
|
|
140
|
+
const reports = edges.filter((stored) => stored.row.verb === "manages");
|
|
141
|
+
if (reports.length > 0) {
|
|
142
|
+
sections.you.push(`- Manages ${String(reports.length)}: ${reports.slice(0, 5).map((stored) => label(stored.row.target)).join(", ")}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
sections.you.push("- Member not identified in the graph. Set `member: person/<slug>` in personal/settings/ontology-reader.yaml and run `hq ontology brief` again.");
|
|
147
|
+
}
|
|
148
|
+
// Active projects, most recently touched first.
|
|
149
|
+
const projects = shown
|
|
150
|
+
.filter((entity) => entity.type === "project")
|
|
151
|
+
.map((entity) => ({
|
|
152
|
+
entity,
|
|
153
|
+
status: factValue(index, schema, entity, filter, "status"),
|
|
154
|
+
stage: factValue(index, schema, entity, filter, "stage"),
|
|
155
|
+
}))
|
|
156
|
+
.filter((entry) => !ENDED.test(entry.status) && !ENDED.test(entry.stage))
|
|
157
|
+
.sort((a, b) => (a.entity.last < b.entity.last ? 1 : a.entity.last > b.entity.last ? -1 : b.entity.rows - a.entity.rows))
|
|
158
|
+
.slice(0, BRIEF_MAX_PROJECTS);
|
|
159
|
+
for (const entry of projects) {
|
|
160
|
+
const owner = openEdges(store, entry.entity.id, filter).find((stored) => stored.row.verb === "owned_by" || stored.row.verb === "led_by");
|
|
161
|
+
const parts = [
|
|
162
|
+
`${clip(entry.entity.name, 48)} (${entry.entity.id})`,
|
|
163
|
+
...(entry.stage ? [`stage ${clip(entry.stage, 24)}`] : entry.status ? [`status ${clip(entry.status, 24)}`] : []),
|
|
164
|
+
...(owner ? [`owner ${owner.row.target}`] : []),
|
|
165
|
+
];
|
|
166
|
+
sections.projects.push(`- ${parts.join(" | ")}`);
|
|
167
|
+
}
|
|
168
|
+
// Customers.
|
|
169
|
+
const customers = shown
|
|
170
|
+
.filter((entity) => entity.type === "company")
|
|
171
|
+
.map((entity) => {
|
|
172
|
+
const facts = indexedFacts(index, schema, entity, filter);
|
|
173
|
+
return {
|
|
174
|
+
entity,
|
|
175
|
+
customer: facts.some((stored) => stored.row.field === "relation" && /customer/i.test(stored.row.value)),
|
|
176
|
+
stage: facts.find((stored) => stored.row.field === "stage")?.row.value ?? "",
|
|
177
|
+
crm: facts.find((stored) => stored.row.field === "crm_status")?.row.value ?? "",
|
|
178
|
+
};
|
|
179
|
+
})
|
|
180
|
+
.filter((entry) => entry.customer)
|
|
181
|
+
.sort((a, b) => (a.entity.last < b.entity.last ? 1 : a.entity.last > b.entity.last ? -1 : b.entity.rows - a.entity.rows))
|
|
182
|
+
.slice(0, BRIEF_MAX_CUSTOMERS);
|
|
183
|
+
for (const entry of customers) {
|
|
184
|
+
const stage = entry.stage || entry.crm;
|
|
185
|
+
sections.customers.push(`- ${clip(entry.entity.name, 48)} (${entry.entity.id})${stage ? ` | stage ${clip(stage, 24)}` : ""}`);
|
|
186
|
+
}
|
|
187
|
+
// What changed in the window: decisions first, then changed single-valued facts.
|
|
188
|
+
const changes = [];
|
|
189
|
+
for (const entity of shown) {
|
|
190
|
+
if (entity.type !== "decision")
|
|
191
|
+
continue;
|
|
192
|
+
const day = factValue(index, schema, entity, filter, "decided_on") || entity.firstSeen;
|
|
193
|
+
if (day >= cutoff && day <= today)
|
|
194
|
+
changes.push({ day, line: `- ${day} decision: ${clip(entity.name, 90)} (${entity.id})` });
|
|
195
|
+
}
|
|
196
|
+
const decisions = changes.sort((a, b) => (a.day < b.day ? 1 : a.day > b.day ? -1 : 0)).slice(0, 8);
|
|
197
|
+
const moved = [];
|
|
198
|
+
for (const entry of index.facts) {
|
|
199
|
+
const entity = index.entities[entry.e];
|
|
200
|
+
if (!entity || entity.type === "decision" || entity.type === "meeting")
|
|
201
|
+
continue;
|
|
202
|
+
if (!rowVisible(entry.a, filter) || entry.row.by === "legacy")
|
|
203
|
+
continue;
|
|
204
|
+
// A model's low-confidence guess at a role or affiliation is not reported as a change either.
|
|
205
|
+
if (isUnverifiedGuess(entry.row))
|
|
206
|
+
continue;
|
|
207
|
+
if (entry.row.valid.from < cutoff || entry.row.valid.from > today)
|
|
208
|
+
continue;
|
|
209
|
+
if (schema.entity_types[entity.type].facts[entry.row.field]?.cardinality !== "single")
|
|
210
|
+
continue;
|
|
211
|
+
if (entry.row.field === "summary")
|
|
212
|
+
continue;
|
|
213
|
+
moved.push({ day: entry.row.valid.from, line: `- ${entry.row.valid.from} ${entity.id}: ${entry.row.field} = ${clip(entry.row.value, 50)}` });
|
|
214
|
+
}
|
|
215
|
+
moved.sort((a, b) => (a.day < b.day ? 1 : a.day > b.day ? -1 : a.line < b.line ? -1 : 1));
|
|
216
|
+
sections.changes = [...decisions, ...moved.slice(0, BRIEF_MAX_CHANGES - decisions.length)].map((entry) => entry.line);
|
|
217
|
+
if (sections.changes.length === 0)
|
|
218
|
+
sections.changes = [`- Nothing recorded since ${cutoff}.`];
|
|
219
|
+
// Fit the cap: drop the last line of the longest list until the text fits.
|
|
220
|
+
const cap = Math.min(BRIEF_MAX_TOKENS, extras.maxTokens ?? BRIEF_MAX_TOKENS);
|
|
221
|
+
let text = render(sections);
|
|
222
|
+
while (estimateTokens(text) > cap) {
|
|
223
|
+
const lists = [sections.projects, sections.changes, sections.customers, sections.you].sort((a, b) => b.length - a.length);
|
|
224
|
+
const longest = lists[0];
|
|
225
|
+
if (!longest || longest.length === 0)
|
|
226
|
+
break;
|
|
227
|
+
longest.pop();
|
|
228
|
+
text = render(sections);
|
|
229
|
+
}
|
|
230
|
+
if (estimateTokens(text) > cap)
|
|
231
|
+
text = `${text.slice(0, cap * 3 - 1)}\n`;
|
|
232
|
+
return text;
|
|
233
|
+
}
|
|
234
|
+
/** `hq ontology brief`: writes brief.md (1,500 tokens max). */
|
|
235
|
+
export async function briefCommand(context, options) {
|
|
236
|
+
if (!options.store && !graphExists(context.graphRoot)) {
|
|
237
|
+
return {
|
|
238
|
+
text: `ontology graph: no graph at ${context.graphRoot}. Build it with: hq ontology rebuild --company ${context.company}`,
|
|
239
|
+
json: { status: "no_graph", graphRoot: context.graphRoot },
|
|
240
|
+
exitCode: 1,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const text = buildBrief(context, options);
|
|
244
|
+
const tokens = estimateTokens(text);
|
|
245
|
+
if (options.stdout)
|
|
246
|
+
return { text, json: { status: "ok", written: false, tokens, brief: text } };
|
|
247
|
+
const file = graphPath(context.graphRoot, GRAPH_PATHS.brief);
|
|
248
|
+
atomicWriteFile(file, text);
|
|
249
|
+
return {
|
|
250
|
+
text: `wrote ${file} (about ${String(tokens)} tokens, cap ${String(BRIEF_MAX_TOKENS)})`,
|
|
251
|
+
json: { status: "ok", written: true, file, tokens },
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=brief.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type AudienceKey, type EntityKeys, type EntityRef, type FactRow, type GraphEntityType, type GraphStore, type IsoDate, type RowId } from "../types.js";
|
|
2
|
+
export declare const READ_INDEX_RELATIVE = ".state/read-index.json";
|
|
3
|
+
export declare const READ_INDEX_VERSION = 2;
|
|
4
|
+
export interface IndexedEntity {
|
|
5
|
+
id: EntityRef;
|
|
6
|
+
type: GraphEntityType;
|
|
7
|
+
name: string;
|
|
8
|
+
aliases: string[];
|
|
9
|
+
/** Identity keys as the entity file holds them. */
|
|
10
|
+
keys: EntityKeys;
|
|
11
|
+
/** Audiences that have at least one row for this entity, sorted. */
|
|
12
|
+
audiences: AudienceKey[];
|
|
13
|
+
/** Row count over all audiences. */
|
|
14
|
+
rows: number;
|
|
15
|
+
firstSeen: IsoDate;
|
|
16
|
+
/** Newest day on any row (valid-from or timeline date), else last_updated. */
|
|
17
|
+
last: IsoDate;
|
|
18
|
+
}
|
|
19
|
+
export interface IndexedFact {
|
|
20
|
+
/** Position in `entities`. */
|
|
21
|
+
e: number;
|
|
22
|
+
a: AudienceKey;
|
|
23
|
+
id: RowId;
|
|
24
|
+
row: FactRow;
|
|
25
|
+
}
|
|
26
|
+
export interface ReadIndexFile {
|
|
27
|
+
version: number;
|
|
28
|
+
stamp: string;
|
|
29
|
+
builtAt: string;
|
|
30
|
+
entities: IndexedEntity[];
|
|
31
|
+
facts: IndexedFact[];
|
|
32
|
+
}
|
|
33
|
+
export interface ReadIndex extends ReadIndexFile {
|
|
34
|
+
byId: Map<string, number>;
|
|
35
|
+
/** Normalized name or alias -> entity positions. */
|
|
36
|
+
byName: Map<string, number[]>;
|
|
37
|
+
/** Lower-cased identity key -> entity positions. */
|
|
38
|
+
byKey: Map<string, number[]>;
|
|
39
|
+
/** First word of a person's name (normalized) -> person positions. */
|
|
40
|
+
byFirstWord: Map<string, number[]>;
|
|
41
|
+
/** Entity position -> positions in `facts`. */
|
|
42
|
+
factsOf: Map<number, number[]>;
|
|
43
|
+
}
|
|
44
|
+
/** Lower case, accents removed, anything that is not a letter or digit becomes one space. */
|
|
45
|
+
export declare function normalizeName(text: string): string;
|
|
46
|
+
/** Size and mtime of the files that change whenever the graph changes. Null: do not cache on disk. */
|
|
47
|
+
export declare function graphStamp(root: string): string | null;
|
|
48
|
+
/** True when the folder looks like a graph (it has an entities folder). */
|
|
49
|
+
export declare function graphExists(root: string): boolean;
|
|
50
|
+
/** Every identity key of an entity, as written. */
|
|
51
|
+
export declare function allKeys(keys: EntityKeys): string[];
|
|
52
|
+
/** Builds the index from the store. Reads every entity once. */
|
|
53
|
+
export declare function buildReadIndex(store: GraphStore, stamp: string): ReadIndexFile;
|
|
54
|
+
/** Drops the in-process copy (tests that rewrite a graph in place). */
|
|
55
|
+
export declare function forgetReadIndex(root?: string): void;
|
|
56
|
+
export interface LoadReadIndexOptions {
|
|
57
|
+
/** Store to build from. Default: `openGraphStore(root)`. */
|
|
58
|
+
store?: GraphStore;
|
|
59
|
+
/** Rebuild even when the file on disk is current. */
|
|
60
|
+
rebuild?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The index for a graph root: from this process's memory, else from
|
|
64
|
+
* `.state/read-index.json` when its stamp matches, else built and written.
|
|
65
|
+
* A failed write is ignored; the index is a cache and the commands only read.
|
|
66
|
+
*/
|
|
67
|
+
export declare function loadReadIndex(root: string, options?: LoadReadIndexOptions): ReadIndex;
|
|
68
|
+
/** The audiences a caller may see. `null` means every audience in the graph. */
|
|
69
|
+
export type AudienceFilter = ReadonlySet<AudienceKey> | null;
|
|
70
|
+
export declare function rowVisible(audience: AudienceKey, filter: AudienceFilter): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* An entity is visible when at least one of its rows is in an allowed
|
|
73
|
+
* audience. With no restriction, an entity that has no rows yet is visible too.
|
|
74
|
+
*/
|
|
75
|
+
export declare function visible(entity: IndexedEntity, filter: AudienceFilter): boolean;
|
|
76
|
+
//# sourceMappingURL=graph-index.d.ts.map
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-E: the read index.
|
|
3
|
+
*
|
|
4
|
+
* A read command must answer in well under a second on a graph of about ten
|
|
5
|
+
* thousand entities, so it cannot open every entity file per call. The index
|
|
6
|
+
* is one JSON file, `.state/read-index.json`, built lazily through the store
|
|
7
|
+
* (`listEntities`, `readEntity`, `readRows`) the first time a read command
|
|
8
|
+
* runs after the graph changed, and reused until it changes again.
|
|
9
|
+
*
|
|
10
|
+
* It holds identity (name, aliases, keys), which audiences have rows for each
|
|
11
|
+
* entity, and every open fact row. Edges and timeline rows are not indexed:
|
|
12
|
+
* commands read those for one entity at a time through the store.
|
|
13
|
+
*
|
|
14
|
+
* Freshness: the index records the size and mtime of `log.md` (every ingest,
|
|
15
|
+
* import, decision and lint appends to it) and the mtime of each
|
|
16
|
+
* `entities/<type>` folder. A graph with no `log.md` is never cached on disk.
|
|
17
|
+
*
|
|
18
|
+
* Audience: every indexed fact keeps its audience key, and every entity keeps
|
|
19
|
+
* the list of audiences that have rows for it. `visible()` is the one check
|
|
20
|
+
* all commands use: an entity with no row in an allowed audience is not
|
|
21
|
+
* returned, not even by name.
|
|
22
|
+
*/
|
|
23
|
+
import * as fs from "node:fs";
|
|
24
|
+
import * as path from "node:path";
|
|
25
|
+
import { isOpen } from "../schema/index.js";
|
|
26
|
+
import { GRAPH_PATHS, atomicWriteFile, graphPath, openGraphStore } from "../store/index.js";
|
|
27
|
+
import { GRAPH_ENTITY_TYPES, } from "../types.js";
|
|
28
|
+
export const READ_INDEX_RELATIVE = ".state/read-index.json";
|
|
29
|
+
export const READ_INDEX_VERSION = 2;
|
|
30
|
+
/** Lower case, accents removed, anything that is not a letter or digit becomes one space. */
|
|
31
|
+
export function normalizeName(text) {
|
|
32
|
+
return text
|
|
33
|
+
.normalize("NFKD")
|
|
34
|
+
.replace(/[̀-ͯ]/g, "")
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
37
|
+
.trim();
|
|
38
|
+
}
|
|
39
|
+
/** Size and mtime of the files that change whenever the graph changes. Null: do not cache on disk. */
|
|
40
|
+
export function graphStamp(root) {
|
|
41
|
+
let log;
|
|
42
|
+
try {
|
|
43
|
+
log = fs.statSync(graphPath(root, GRAPH_PATHS.log));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const parts = [`log:${String(log.size)}:${String(Math.floor(log.mtimeMs))}`];
|
|
49
|
+
for (const type of GRAPH_ENTITY_TYPES) {
|
|
50
|
+
try {
|
|
51
|
+
const stat = fs.statSync(path.join(root, GRAPH_PATHS.entities, type));
|
|
52
|
+
parts.push(`${type}:${String(Math.floor(stat.mtimeMs))}`);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// A type with no folder has no entities.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return parts.join("|");
|
|
59
|
+
}
|
|
60
|
+
/** True when the folder looks like a graph (it has an entities folder). */
|
|
61
|
+
export function graphExists(root) {
|
|
62
|
+
try {
|
|
63
|
+
return fs.statSync(path.join(root, GRAPH_PATHS.entities)).isDirectory();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Every identity key of an entity, as written. */
|
|
70
|
+
export function allKeys(keys) {
|
|
71
|
+
return [...keys.email, ...keys.slack_id, ...keys.external_ids, ...keys.web_domains];
|
|
72
|
+
}
|
|
73
|
+
function push(map, key, value) {
|
|
74
|
+
const list = map.get(key);
|
|
75
|
+
if (!list)
|
|
76
|
+
map.set(key, [value]);
|
|
77
|
+
else if (list[list.length - 1] !== value && !list.includes(value))
|
|
78
|
+
list.push(value);
|
|
79
|
+
}
|
|
80
|
+
function hydrate(file) {
|
|
81
|
+
const byId = new Map();
|
|
82
|
+
const byName = new Map();
|
|
83
|
+
const byKey = new Map();
|
|
84
|
+
const byFirstWord = new Map();
|
|
85
|
+
const factsOf = new Map();
|
|
86
|
+
file.entities.forEach((entity, position) => {
|
|
87
|
+
byId.set(entity.id, position);
|
|
88
|
+
for (const name of [entity.name, ...entity.aliases]) {
|
|
89
|
+
const normalized = normalizeName(name);
|
|
90
|
+
if (normalized)
|
|
91
|
+
push(byName, normalized, position);
|
|
92
|
+
}
|
|
93
|
+
for (const key of allKeys(entity.keys))
|
|
94
|
+
push(byKey, key.toLowerCase(), position);
|
|
95
|
+
if (entity.type === "person") {
|
|
96
|
+
const first = normalizeName(entity.name).split(" ")[0];
|
|
97
|
+
if (first)
|
|
98
|
+
push(byFirstWord, first, position);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
file.facts.forEach((fact, position) => push(factsOf, fact.e, position));
|
|
102
|
+
return { ...file, byId, byName, byKey, byFirstWord, factsOf };
|
|
103
|
+
}
|
|
104
|
+
/** Builds the index from the store. Reads every entity once. */
|
|
105
|
+
export function buildReadIndex(store, stamp) {
|
|
106
|
+
const entities = [];
|
|
107
|
+
const facts = [];
|
|
108
|
+
for (const ref of store.listEntities()) {
|
|
109
|
+
const entity = store.readEntity(ref);
|
|
110
|
+
if (!entity)
|
|
111
|
+
continue;
|
|
112
|
+
const rows = store.readRows(ref);
|
|
113
|
+
const audiences = new Set();
|
|
114
|
+
let last = entity.last_updated;
|
|
115
|
+
const position = entities.length;
|
|
116
|
+
for (const stored of rows) {
|
|
117
|
+
audiences.add(stored.audience);
|
|
118
|
+
const day = stored.row.kind === "T" ? stored.row.date : stored.row.valid.from;
|
|
119
|
+
if (day > last)
|
|
120
|
+
last = day;
|
|
121
|
+
if (stored.row.kind === "F" && isOpen(stored.row)) {
|
|
122
|
+
facts.push({ e: position, a: stored.audience, id: stored.id, row: stored.row });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
entities.push({
|
|
126
|
+
id: entity.id,
|
|
127
|
+
type: entity.type,
|
|
128
|
+
name: entity.canonical_name,
|
|
129
|
+
aliases: entity.aliases,
|
|
130
|
+
keys: entity.keys,
|
|
131
|
+
audiences: [...audiences].sort(),
|
|
132
|
+
rows: rows.length,
|
|
133
|
+
firstSeen: entity.first_seen,
|
|
134
|
+
last,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return { version: READ_INDEX_VERSION, stamp, builtAt: new Date().toISOString(), entities, facts };
|
|
138
|
+
}
|
|
139
|
+
const memo = new Map();
|
|
140
|
+
/** Drops the in-process copy (tests that rewrite a graph in place). */
|
|
141
|
+
export function forgetReadIndex(root) {
|
|
142
|
+
if (root === undefined)
|
|
143
|
+
memo.clear();
|
|
144
|
+
else
|
|
145
|
+
memo.delete(path.resolve(root));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The index for a graph root: from this process's memory, else from
|
|
149
|
+
* `.state/read-index.json` when its stamp matches, else built and written.
|
|
150
|
+
* A failed write is ignored; the index is a cache and the commands only read.
|
|
151
|
+
*/
|
|
152
|
+
export function loadReadIndex(root, options = {}) {
|
|
153
|
+
const key = path.resolve(root);
|
|
154
|
+
const stamp = graphStamp(key);
|
|
155
|
+
if (!options.rebuild && stamp !== null) {
|
|
156
|
+
const held = memo.get(key);
|
|
157
|
+
if (held && held.stamp === stamp)
|
|
158
|
+
return held;
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(fs.readFileSync(graphPath(key, READ_INDEX_RELATIVE), "utf8"));
|
|
161
|
+
if (parsed.version === READ_INDEX_VERSION && parsed.stamp === stamp && Array.isArray(parsed.entities)) {
|
|
162
|
+
const index = hydrate(parsed);
|
|
163
|
+
memo.set(key, index);
|
|
164
|
+
return index;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Missing, torn or old: rebuild below.
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const store = options.store ?? openGraphStore(key);
|
|
172
|
+
const file = buildReadIndex(store, stamp ?? "uncached");
|
|
173
|
+
if (stamp !== null) {
|
|
174
|
+
try {
|
|
175
|
+
atomicWriteFile(graphPath(key, READ_INDEX_RELATIVE), JSON.stringify(file));
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Read-only folder: serve from memory.
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const index = hydrate(file);
|
|
182
|
+
if (stamp !== null)
|
|
183
|
+
memo.set(key, index);
|
|
184
|
+
return index;
|
|
185
|
+
}
|
|
186
|
+
export function rowVisible(audience, filter) {
|
|
187
|
+
return filter === null || filter.has(audience);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* An entity is visible when at least one of its rows is in an allowed
|
|
191
|
+
* audience. With no restriction, an entity that has no rows yet is visible too.
|
|
192
|
+
*/
|
|
193
|
+
export function visible(entity, filter) {
|
|
194
|
+
if (filter === null)
|
|
195
|
+
return true;
|
|
196
|
+
return entity.audiences.some((audience) => filter.has(audience));
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=graph-index.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type AudienceKey, type CommandOutput, type GraphContext, type GraphStore, type LookupOptions, type NeighborsOptions, type Resolver, type SearchOptions, type TraverseOptions } from "../types.js";
|
|
2
|
+
import { type AudienceFilter } from "./graph-index.js";
|
|
3
|
+
export { briefCommand, buildBrief, estimateTokens, BRIEF_MAX_TOKENS } from "./brief.js";
|
|
4
|
+
export type { BriefExtras } from "./brief.js";
|
|
5
|
+
export { graphReaderEnabled, readReaderSetting, readerSettingFile } from "./reader-setting.js";
|
|
6
|
+
export { loadReadIndex, forgetReadIndex, READ_INDEX_RELATIVE } from "./graph-index.js";
|
|
7
|
+
export { resolveName, searchIndex } from "./names.js";
|
|
8
|
+
export { resolveReadMember } from "./member.js";
|
|
9
|
+
export type { ResolveReadMemberOptions } from "./member.js";
|
|
10
|
+
/** Optional inputs every read command accepts beside its contract options. */
|
|
11
|
+
export interface ReadExtras {
|
|
12
|
+
/** Audiences the caller may see. Overrides `context.member`. */
|
|
13
|
+
audiences?: readonly AudienceKey[];
|
|
14
|
+
/** Store to read through. Default: `openGraphStore(context.graphRoot)`. */
|
|
15
|
+
store?: GraphStore;
|
|
16
|
+
/** The WP-C resolver, or `null` to resolve from the index only. */
|
|
17
|
+
resolver?: Resolver | null;
|
|
18
|
+
/** Most rows printed. */
|
|
19
|
+
limit?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Verbs that say two things appear together in a meeting, a decision or a
|
|
23
|
+
* document. They are evidence to open, not a relationship between the two.
|
|
24
|
+
*/
|
|
25
|
+
export declare const CO_MENTION_VERBS: ReadonlySet<string>;
|
|
26
|
+
/** Entities a path search opens before it gives up. */
|
|
27
|
+
export declare const PATH_EXPAND_LIMIT = 600;
|
|
28
|
+
/** Below this many rows of any kind, `lookup` says the graph holds little on the entity. */
|
|
29
|
+
export declare const THIN_ROW_COUNT = 5;
|
|
30
|
+
export declare const DEFAULT_EDGE_LIMIT = 40;
|
|
31
|
+
export declare const LOOKUP_EDGE_LIMIT = 12;
|
|
32
|
+
export declare const SIGNAL_LIMIT = 5;
|
|
33
|
+
export declare const LOOKUP_RECENT_LIMIT = 3;
|
|
34
|
+
export declare const WALK_NODE_LIMIT = 300;
|
|
35
|
+
export declare function audienceFilterFor(context: GraphContext, extras?: ReadExtras): AudienceFilter;
|
|
36
|
+
/** `hq ontology lookup <name> [--as-of D]`. */
|
|
37
|
+
export declare function lookupCommand(context: GraphContext, options: LookupOptions & ReadExtras & {
|
|
38
|
+
page?: boolean;
|
|
39
|
+
}): Promise<CommandOutput>;
|
|
40
|
+
/** `hq ontology neighbors <id> [--verb V] [--depth N] [--as-of D]`. */
|
|
41
|
+
export declare function neighborsCommand(context: GraphContext, options: NeighborsOptions & ReadExtras & {
|
|
42
|
+
depth?: number;
|
|
43
|
+
}): Promise<CommandOutput>;
|
|
44
|
+
/**
|
|
45
|
+
* `hq ontology search <text>`: names, aliases, identity keys and open facts,
|
|
46
|
+
* from the local index. qmd is not used: it skips dot folders and the graph
|
|
47
|
+
* lives in `.hq/` (correction C1).
|
|
48
|
+
*/
|
|
49
|
+
export declare function searchCommand(context: GraphContext, options: SearchOptions & ReadExtras): Promise<CommandOutput>;
|
|
50
|
+
/**
|
|
51
|
+
* `hq ontology traverse <from> [<to>] [--verb V[,V]] [--depth 1-3]`.
|
|
52
|
+
* With `to`: the shortest path between two entities. Without: everything
|
|
53
|
+
* reachable from `from` along the verbs.
|
|
54
|
+
*/
|
|
55
|
+
export declare function traverseCommand(context: GraphContext, options: TraverseOptions & ReadExtras & {
|
|
56
|
+
to?: string;
|
|
57
|
+
verbs?: readonly string[];
|
|
58
|
+
}): Promise<CommandOutput>;
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|