@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,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown forms of an entity file, a facts file and log.md. Render and
|
|
3
|
+
* parse are inverses, and render is deterministic: the same content always
|
|
4
|
+
* gives the same bytes.
|
|
5
|
+
*/
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
import { splitFrontmatterBody } from "../../../utils/frontmatter.js";
|
|
8
|
+
import { GRAPH_ENTITY_TYPES, } from "../types.js";
|
|
9
|
+
import { compareRows, escapeText, formatRow, isAudienceKey, isEntityRef, isIsoDate, isRowLine, rowId, tryParseRow, unescapeText, } from "../schema/grammar.js";
|
|
10
|
+
import { GraphFileError } from "./fs.js";
|
|
11
|
+
const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
12
|
+
/** Sorted, trimmed, without blanks or repeats. */
|
|
13
|
+
export function sortedUnique(values) {
|
|
14
|
+
return [...new Set(values.map((value) => value.trim()).filter((value) => value !== ""))].sort(compareText);
|
|
15
|
+
}
|
|
16
|
+
function splitFrontmatter(text, file) {
|
|
17
|
+
const split = splitFrontmatterBody(text);
|
|
18
|
+
if (!split)
|
|
19
|
+
throw new GraphFileError(file, "missing frontmatter");
|
|
20
|
+
let loaded;
|
|
21
|
+
try {
|
|
22
|
+
loaded = yaml.load(split.yaml, { schema: yaml.CORE_SCHEMA });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new GraphFileError(file, `frontmatter is not valid YAML (${error.name})`);
|
|
26
|
+
}
|
|
27
|
+
if (!loaded || typeof loaded !== "object" || Array.isArray(loaded)) {
|
|
28
|
+
throw new GraphFileError(file, "frontmatter is not a mapping");
|
|
29
|
+
}
|
|
30
|
+
return { frontmatter: loaded, body: split.body };
|
|
31
|
+
}
|
|
32
|
+
function dumpFrontmatter(value) {
|
|
33
|
+
return yaml.dump(value, { schema: yaml.CORE_SCHEMA, lineWidth: -1, noRefs: true, sortKeys: false });
|
|
34
|
+
}
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// Entity file
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
export function renderEntityFile(entity) {
|
|
39
|
+
const frontmatter = {
|
|
40
|
+
id: entity.id,
|
|
41
|
+
type: entity.type,
|
|
42
|
+
canonical_name: entity.canonical_name,
|
|
43
|
+
slug: entity.slug,
|
|
44
|
+
aliases: sortedUnique(entity.aliases),
|
|
45
|
+
keys: {
|
|
46
|
+
email: sortedUnique(entity.keys.email),
|
|
47
|
+
slack_id: sortedUnique(entity.keys.slack_id),
|
|
48
|
+
external_ids: sortedUnique(entity.keys.external_ids),
|
|
49
|
+
web_domains: sortedUnique(entity.keys.web_domains),
|
|
50
|
+
},
|
|
51
|
+
first_seen: entity.first_seen,
|
|
52
|
+
last_updated: entity.last_updated,
|
|
53
|
+
legacy_ids: sortedUnique(entity.legacy_ids),
|
|
54
|
+
};
|
|
55
|
+
return `---\n${dumpFrontmatter(frontmatter)}---\n# ${entity.canonical_name}\n`;
|
|
56
|
+
}
|
|
57
|
+
function textList(value, file, what) {
|
|
58
|
+
if (value === undefined || value === null)
|
|
59
|
+
return [];
|
|
60
|
+
if (!Array.isArray(value))
|
|
61
|
+
throw new GraphFileError(file, `${what} is not a list`);
|
|
62
|
+
return sortedUnique(value.map((entry) => String(entry)));
|
|
63
|
+
}
|
|
64
|
+
export function parseEntityFile(text, file) {
|
|
65
|
+
const { frontmatter } = splitFrontmatter(text, file);
|
|
66
|
+
const { id, type, canonical_name: name, slug } = frontmatter;
|
|
67
|
+
if (typeof type !== "string" || !GRAPH_ENTITY_TYPES.includes(type)) {
|
|
68
|
+
throw new GraphFileError(file, `unknown entity type: ${String(type)}`);
|
|
69
|
+
}
|
|
70
|
+
if (typeof slug !== "string" || id !== `${type}/${slug}` || !isEntityRef(id)) {
|
|
71
|
+
throw new GraphFileError(file, `id does not match type and slug: ${String(id)}`);
|
|
72
|
+
}
|
|
73
|
+
if (typeof name !== "string" || name.trim() === "")
|
|
74
|
+
throw new GraphFileError(file, "canonical_name is missing");
|
|
75
|
+
if (!isIsoDate(frontmatter.first_seen) || !isIsoDate(frontmatter.last_updated)) {
|
|
76
|
+
throw new GraphFileError(file, "first_seen or last_updated is not a date");
|
|
77
|
+
}
|
|
78
|
+
const rawKeys = (frontmatter.keys ?? {});
|
|
79
|
+
if (typeof rawKeys !== "object" || Array.isArray(rawKeys))
|
|
80
|
+
throw new GraphFileError(file, "keys is not a mapping");
|
|
81
|
+
const keys = {
|
|
82
|
+
email: textList(rawKeys.email, file, "keys.email"),
|
|
83
|
+
slack_id: textList(rawKeys.slack_id, file, "keys.slack_id"),
|
|
84
|
+
external_ids: textList(rawKeys.external_ids, file, "keys.external_ids"),
|
|
85
|
+
web_domains: textList(rawKeys.web_domains, file, "keys.web_domains"),
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
id: id,
|
|
89
|
+
type: type,
|
|
90
|
+
canonical_name: name,
|
|
91
|
+
slug,
|
|
92
|
+
aliases: textList(frontmatter.aliases, file, "aliases"),
|
|
93
|
+
keys,
|
|
94
|
+
first_seen: frontmatter.first_seen,
|
|
95
|
+
last_updated: frontmatter.last_updated,
|
|
96
|
+
legacy_ids: textList(frontmatter.legacy_ids, file, "legacy_ids"),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Facts file
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
/** Rows in file order: F, E, T, each group sorted; ties broken by row id. */
|
|
103
|
+
export function sortRows(rows) {
|
|
104
|
+
return rows
|
|
105
|
+
.map((row) => ({ row, id: rowId(row) }))
|
|
106
|
+
.sort((a, b) => compareRows(a.row, b.row) || compareText(a.id, b.id))
|
|
107
|
+
.map((entry) => entry.row);
|
|
108
|
+
}
|
|
109
|
+
export function renderFactsFile(entity, audience, rows) {
|
|
110
|
+
const lines = sortRows(rows).map(formatRow);
|
|
111
|
+
return `---\nentity: ${entity}\naudience: ${audience}\n---\n${lines.join("\n")}${lines.length > 0 ? "\n" : ""}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Lenient parse, used by lint and by read commands: bad lines are returned in
|
|
115
|
+
* `errors` and never thrown. Lines that are not rows (blank, headings, prose)
|
|
116
|
+
* are ignored.
|
|
117
|
+
*/
|
|
118
|
+
export function parseFactsFile(text) {
|
|
119
|
+
const parsed = { entity: null, audience: null, rows: [], errors: [] };
|
|
120
|
+
const lines = text.split(/\r?\n/);
|
|
121
|
+
let start = 0;
|
|
122
|
+
if (lines[0] === "---") {
|
|
123
|
+
const end = lines.indexOf("---", 1);
|
|
124
|
+
if (end < 0) {
|
|
125
|
+
parsed.errors.push({ line: 1, refusal: { code: "grammar", message: "frontmatter is not closed" }, text: lines[0] });
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
for (const line of lines.slice(1, end)) {
|
|
129
|
+
const match = /^(entity|audience):\s*(.+?)\s*$/.exec(line);
|
|
130
|
+
if (match?.[1] === "entity" && isEntityRef(match[2]))
|
|
131
|
+
parsed.entity = match[2];
|
|
132
|
+
if (match?.[1] === "audience" && isAudienceKey(match[2]))
|
|
133
|
+
parsed.audience = match[2];
|
|
134
|
+
}
|
|
135
|
+
start = end + 1;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
for (let index = start; index < lines.length; index += 1) {
|
|
140
|
+
const line = lines[index];
|
|
141
|
+
if (!isRowLine(line))
|
|
142
|
+
continue;
|
|
143
|
+
const result = tryParseRow(line);
|
|
144
|
+
if (!result.ok) {
|
|
145
|
+
parsed.errors.push({ line: index + 1, refusal: result.refusal, text: line });
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const id = rowId(result.row);
|
|
149
|
+
if (seen.has(id))
|
|
150
|
+
continue;
|
|
151
|
+
seen.add(id);
|
|
152
|
+
parsed.rows.push({ id, row: result.row, line: index + 1 });
|
|
153
|
+
}
|
|
154
|
+
return parsed;
|
|
155
|
+
}
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
// log.md
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
export const LOG_HEADER = "# Ontology graph log\n\nAppend-only. One entry per ingest, lint run and decision.\n\n";
|
|
160
|
+
const LOG_OPS = ["ingest", "lint", "decision", "rebuild", "update", "import", "compile"];
|
|
161
|
+
export function formatLogEntry(entry) {
|
|
162
|
+
const touched = sortedUnique(entry.touched);
|
|
163
|
+
const lines = [
|
|
164
|
+
`## [${entry.date}] ${entry.op} | ${escapeText(entry.subject)} | touched ${touched.length} | rows +${entry.rowsAdded} closed ${entry.rowsClosed}`,
|
|
165
|
+
];
|
|
166
|
+
if (touched.length > 0)
|
|
167
|
+
lines.push(touched.join(", "));
|
|
168
|
+
if (entry.note !== undefined && entry.note.trim() !== "")
|
|
169
|
+
lines.push(`note: ${entry.note.replace(/\s*[\r\n]+\s*/g, " ")}`);
|
|
170
|
+
return `${lines.join("\n")}\n\n`;
|
|
171
|
+
}
|
|
172
|
+
const LOG_HEADING = /^## \[(\d{4}-\d{2}-\d{2})\] ([a-z]+) \| (.*) \| touched (\d+) \| rows \+(\d+) closed (\d+)$/;
|
|
173
|
+
/** Entries in file order (oldest first). Lines that are not part of an entry are ignored. */
|
|
174
|
+
export function parseLog(text) {
|
|
175
|
+
const entries = [];
|
|
176
|
+
let current = null;
|
|
177
|
+
for (const line of text.split(/\r?\n/)) {
|
|
178
|
+
const match = LOG_HEADING.exec(line);
|
|
179
|
+
if (match && LOG_OPS.includes(match[2])) {
|
|
180
|
+
current = {
|
|
181
|
+
date: match[1],
|
|
182
|
+
op: match[2],
|
|
183
|
+
subject: unescapeText(match[3]),
|
|
184
|
+
touched: [],
|
|
185
|
+
rowsAdded: Number(match[5]),
|
|
186
|
+
rowsClosed: Number(match[6]),
|
|
187
|
+
};
|
|
188
|
+
entries.push(current);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!current || line.trim() === "")
|
|
192
|
+
continue;
|
|
193
|
+
if (line.startsWith("note: ")) {
|
|
194
|
+
current.note = line.slice(6);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (line.startsWith("#")) {
|
|
198
|
+
current = null;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const refs = line.split(", ").filter(isEntityRef);
|
|
202
|
+
if (refs.length > 0 && current.touched.length === 0)
|
|
203
|
+
current.touched = refs;
|
|
204
|
+
}
|
|
205
|
+
return entries;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** A graph file that cannot be read as what it should be. */
|
|
2
|
+
export declare class GraphFileError extends Error {
|
|
3
|
+
readonly file: string;
|
|
4
|
+
readonly line?: number;
|
|
5
|
+
constructor(file: string, message: string, line?: number);
|
|
6
|
+
}
|
|
7
|
+
export declare function readTextIfExists(file: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Writes a temp file beside the target, then renames it over the target, so a
|
|
10
|
+
* reader sees the old bytes or the new bytes and never a partial file. Creates
|
|
11
|
+
* parent folders. Returns false, and writes nothing, when the target already
|
|
12
|
+
* holds exactly `text`. `knownChanged` skips that comparison (and the read it
|
|
13
|
+
* needs) for a caller that already knows the bytes differ.
|
|
14
|
+
*/
|
|
15
|
+
export declare function atomicWriteFile(file: string, text: string, options?: {
|
|
16
|
+
knownChanged?: boolean;
|
|
17
|
+
}): boolean;
|
|
18
|
+
/** Appends text in one write call. Creates the file and parent folders. */
|
|
19
|
+
export declare function appendText(file: string, text: string): void;
|
|
20
|
+
/** Appends one JSON line. Creates the file and parent folders. */
|
|
21
|
+
export declare function appendJsonLine(file: string, value: unknown): void;
|
|
22
|
+
/**
|
|
23
|
+
* Reads a JSONL file. A missing file is an empty list. A last line that was
|
|
24
|
+
* cut off mid-write (no trailing newline and not valid JSON) is skipped; any
|
|
25
|
+
* other unreadable line throws GraphFileError.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readJsonLines<T>(file: string): T[];
|
|
28
|
+
/** Names in a folder, sorted by code unit. A missing folder is empty. */
|
|
29
|
+
export declare function listDir(dir: string): string[];
|
|
30
|
+
//# sourceMappingURL=fs.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File primitives for the graph folder: atomic replace, JSONL append and read.
|
|
3
|
+
* Other packages use these for the files they own (pages, proposals, cache).
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
/** A graph file that cannot be read as what it should be. */
|
|
9
|
+
export class GraphFileError extends Error {
|
|
10
|
+
file;
|
|
11
|
+
line;
|
|
12
|
+
constructor(file, message, line) {
|
|
13
|
+
super(`ontology graph: ${file}${line === undefined ? "" : `:${line}`}: ${message}`);
|
|
14
|
+
this.name = "GraphFileError";
|
|
15
|
+
this.file = file;
|
|
16
|
+
if (line !== undefined)
|
|
17
|
+
this.line = line;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function readTextIfExists(file) {
|
|
21
|
+
try {
|
|
22
|
+
return fs.readFileSync(file, "utf8");
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code === "ENOENT")
|
|
26
|
+
return null;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Writes a temp file beside the target, then renames it over the target, so a
|
|
32
|
+
* reader sees the old bytes or the new bytes and never a partial file. Creates
|
|
33
|
+
* parent folders. Returns false, and writes nothing, when the target already
|
|
34
|
+
* holds exactly `text`. `knownChanged` skips that comparison (and the read it
|
|
35
|
+
* needs) for a caller that already knows the bytes differ.
|
|
36
|
+
*/
|
|
37
|
+
export function atomicWriteFile(file, text, options = {}) {
|
|
38
|
+
if (!options.knownChanged && readTextIfExists(file) === text)
|
|
39
|
+
return false;
|
|
40
|
+
const dir = path.dirname(file);
|
|
41
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
42
|
+
const temp = path.join(dir, `.${path.basename(file)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
|
|
43
|
+
try {
|
|
44
|
+
fs.writeFileSync(temp, text, { encoding: "utf8", flag: "wx" });
|
|
45
|
+
fs.renameSync(temp, file);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
fs.rmSync(temp, { force: true });
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/** Appends text in one write call. Creates the file and parent folders. */
|
|
54
|
+
export function appendText(file, text) {
|
|
55
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
56
|
+
fs.appendFileSync(file, text, "utf8");
|
|
57
|
+
}
|
|
58
|
+
/** Appends one JSON line. Creates the file and parent folders. */
|
|
59
|
+
export function appendJsonLine(file, value) {
|
|
60
|
+
appendText(file, `${JSON.stringify(value)}\n`);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reads a JSONL file. A missing file is an empty list. A last line that was
|
|
64
|
+
* cut off mid-write (no trailing newline and not valid JSON) is skipped; any
|
|
65
|
+
* other unreadable line throws GraphFileError.
|
|
66
|
+
*/
|
|
67
|
+
export function readJsonLines(file) {
|
|
68
|
+
const text = readTextIfExists(file);
|
|
69
|
+
if (text === null)
|
|
70
|
+
return [];
|
|
71
|
+
const lines = text.split("\n");
|
|
72
|
+
const complete = text.endsWith("\n");
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const [index, line] of lines.entries()) {
|
|
75
|
+
if (line.trim() === "")
|
|
76
|
+
continue;
|
|
77
|
+
try {
|
|
78
|
+
out.push(JSON.parse(line));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
if (index === lines.length - 1 && !complete)
|
|
82
|
+
continue;
|
|
83
|
+
throw new GraphFileError(file, "not a JSON line", index + 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** Names in a folder, sorted by code unit. A missing folder is empty. */
|
|
89
|
+
export function listDir(dir) {
|
|
90
|
+
let names;
|
|
91
|
+
try {
|
|
92
|
+
names = fs.readdirSync(dir);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.code === "ENOENT")
|
|
96
|
+
return [];
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
return names.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type GraphSchema, type GraphStore } from "../types.js";
|
|
2
|
+
export interface OpenGraphStoreOptions {
|
|
3
|
+
/** Written to schema.yaml when the folder has none. Default: DEFAULT_SCHEMA. */
|
|
4
|
+
schema?: GraphSchema;
|
|
5
|
+
/**
|
|
6
|
+
* The company the graph is opened for. A folder stamped for another company
|
|
7
|
+
* (see `assertGraphCompany` in paths.ts) is refused. Every caller that knows
|
|
8
|
+
* its company passes it.
|
|
9
|
+
*/
|
|
10
|
+
company?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Opens the graph folder at `graphRoot`. Nothing is created until `init()` or the first write. */
|
|
13
|
+
export declare function openGraphStore(graphRoot: string, options?: OpenGraphStoreOptions): GraphStore;
|
|
14
|
+
//# sourceMappingURL=graph-store.d.ts.map
|