@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,7 @@
|
|
|
1
|
+
import type { GraphContext, MemberIdentity } from "../types.js";
|
|
2
|
+
export interface ResolveReadMemberOptions {
|
|
3
|
+
/** Finds the signed-in member. Default: the CLI's local whoami answer. */
|
|
4
|
+
resolveMember?: (context: GraphContext) => MemberIdentity | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveReadMember(context: GraphContext, options?: ResolveReadMemberOptions): GraphContext;
|
|
7
|
+
//# sourceMappingURL=member.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who a read command runs for when no identity flag was given (correction C5).
|
|
3
|
+
*
|
|
4
|
+
* - The member: `context.member` when `--member` (or its env var) named one,
|
|
5
|
+
* else the person signed in to the CLI, found the way `hq whoami` finds them
|
|
6
|
+
* with no network call (`resolveSignedInMember` in replay/member.ts, the
|
|
7
|
+
* same lookup `rebuild` and `update` use).
|
|
8
|
+
* - The audience keys: the ones passed with `--audience-key` when there are
|
|
9
|
+
* any, else every `facts/@<key>` folder in the graph root. The graph folder
|
|
10
|
+
* is built for one member from files that member can read, so the folders
|
|
11
|
+
* present are the keys the member holds.
|
|
12
|
+
*
|
|
13
|
+
* With no flag and nobody signed in the context comes back unchanged; the read
|
|
14
|
+
* commands then show every audience in the folder and the brief names nobody.
|
|
15
|
+
*/
|
|
16
|
+
import { resolveSignedInMember } from "../replay/member.js";
|
|
17
|
+
import { heldAudienceKeys } from "../store/paths.js";
|
|
18
|
+
export function resolveReadMember(context, options = {}) {
|
|
19
|
+
let member = context.member ?? null;
|
|
20
|
+
if (!member) {
|
|
21
|
+
try {
|
|
22
|
+
member = (options.resolveMember ?? ((ctx) => resolveSignedInMember(ctx)))(context);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
member = null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!member)
|
|
29
|
+
return context;
|
|
30
|
+
if (member.audienceKeys.length > 0)
|
|
31
|
+
return context.member === member ? context : { ...context, member };
|
|
32
|
+
return { ...context, member: { personUid: member.personUid, audienceKeys: heldAudienceKeys(context.graphRoot) } };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=member.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type AudienceKey, type FactRow, type GraphSchema, type GraphStore, type Resolver, type StoredRow } from "../types.js";
|
|
2
|
+
import { type AudienceFilter, type IndexedEntity, type ReadIndex } from "./graph-index.js";
|
|
3
|
+
export type NameReason = "id" | "identity_key" | "exact_name" | "alias" | "unique_first_word" | "fuzzy" | "fuzzy_adjudicated" | "refused_short" | "refused_generic" | "refused_job_title" | "ambiguous_first_word" | "ambiguous_name" | "unknown_slack_id" | "no_match";
|
|
4
|
+
export interface NameResolution {
|
|
5
|
+
status: "resolved" | "ambiguous" | "refused" | "unresolved";
|
|
6
|
+
reason: NameReason;
|
|
7
|
+
entity?: IndexedEntity;
|
|
8
|
+
/** For `ambiguous`: the entities to choose from. For `unresolved`: near matches, possibly none. */
|
|
9
|
+
candidates: IndexedEntity[];
|
|
10
|
+
}
|
|
11
|
+
export interface ResolveNameOptions {
|
|
12
|
+
filter: AudienceFilter;
|
|
13
|
+
/** The WP-C resolver. `null` skips it. Undefined: built on demand from `store`. */
|
|
14
|
+
resolver?: Resolver | null;
|
|
15
|
+
store?: GraphStore;
|
|
16
|
+
/** Most candidates returned. */
|
|
17
|
+
maxCandidates?: number;
|
|
18
|
+
}
|
|
19
|
+
/** The WP-C resolver over the index, or null when it is not available. Never throws. */
|
|
20
|
+
export declare function graphResolver(store: GraphStore, schema: GraphSchema, index: ReadIndex, audiences?: readonly AudienceKey[]): Resolver | null;
|
|
21
|
+
export declare function resolveName(index: ReadIndex, schema: GraphSchema, text: string, options: ResolveNameOptions): NameResolution;
|
|
22
|
+
export interface SearchHit {
|
|
23
|
+
entity: IndexedEntity;
|
|
24
|
+
score: number;
|
|
25
|
+
/** What matched: `name`, `alias`, `key`, or `fact`. */
|
|
26
|
+
matched: "name" | "alias" | "key" | "fact";
|
|
27
|
+
/** The fact row that matched, when `matched` is `fact`. */
|
|
28
|
+
fact?: {
|
|
29
|
+
audience: AudienceKey;
|
|
30
|
+
row: FactRow;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface SearchIndexOptions {
|
|
34
|
+
filter: AudienceFilter;
|
|
35
|
+
limit?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Scores every visible entity against the query. Each query word must match
|
|
39
|
+
* somewhere on the entity (name, alias, key or one open fact) to count.
|
|
40
|
+
*/
|
|
41
|
+
export declare function searchIndex(index: ReadIndex, _schema: GraphSchema, text: string, options: SearchIndexOptions): SearchHit[];
|
|
42
|
+
/**
|
|
43
|
+
* The facts that answer "what is true" for one indexed entity, limited to the allowed audiences.
|
|
44
|
+
* A model's low-confidence guess at a role or affiliation is left out before the winner of a
|
|
45
|
+
* field is chosen, so every reader built on this (lookup's candidates, the brief, the signals
|
|
46
|
+
* graph context) shows the established row or nothing.
|
|
47
|
+
*/
|
|
48
|
+
export declare function indexedFacts(index: ReadIndex, schema: GraphSchema, entity: IndexedEntity, filter: AudienceFilter): StoredRow<FactRow>[];
|
|
49
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-E: turning what a caller typed into one entity, or into candidates.
|
|
3
|
+
*
|
|
4
|
+
* `resolveName` never guesses. An exact id, identity key, name or alias that
|
|
5
|
+
* points at one visible entity resolves. A name that points at several, or a
|
|
6
|
+
* single first name shared by several people, returns the candidates and the
|
|
7
|
+
* reason. Anything else goes to the graph resolver (WP-C) when it is there,
|
|
8
|
+
* and only then to a strict local token match. Every step applies the
|
|
9
|
+
* audience filter, so a hidden entity is never a candidate.
|
|
10
|
+
*
|
|
11
|
+
* `searchIndex` is the keyword and fuzzy search over names, aliases, identity
|
|
12
|
+
* keys and open facts.
|
|
13
|
+
*/
|
|
14
|
+
import { dropUnverifiedGuesses, effectiveFacts, isEntityRef, slugify } from "../schema/index.js";
|
|
15
|
+
import { createResolver } from "../resolve/index.js";
|
|
16
|
+
import { GRAPH_ENTITY_TYPES, } from "../types.js";
|
|
17
|
+
import { allKeys, normalizeName, rowVisible, visible, } from "./graph-index.js";
|
|
18
|
+
function positions(index, list, filter) {
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const position of list ?? []) {
|
|
21
|
+
const entity = index.entities[position];
|
|
22
|
+
if (entity && visible(entity, filter))
|
|
23
|
+
out.push(entity);
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function unique(entities) {
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
return entities.filter((entity) => (seen.has(entity.id) ? false : (seen.add(entity.id), true)));
|
|
30
|
+
}
|
|
31
|
+
/** Most rows first, then id, so the busiest entity leads a candidate list. */
|
|
32
|
+
function ranked(entities, cap) {
|
|
33
|
+
return [...entities].sort((a, b) => b.rows - a.rows || (a.id < b.id ? -1 : 1)).slice(0, cap);
|
|
34
|
+
}
|
|
35
|
+
function jaccard(a, b) {
|
|
36
|
+
let shared = 0;
|
|
37
|
+
for (const token of a)
|
|
38
|
+
if (b.has(token))
|
|
39
|
+
shared += 1;
|
|
40
|
+
const union = a.size + b.size - shared;
|
|
41
|
+
return union === 0 ? 0 : shared / union;
|
|
42
|
+
}
|
|
43
|
+
/** A store that answers identity reads from the index, so the resolver loads in memory. */
|
|
44
|
+
function indexBackedStore(store, index) {
|
|
45
|
+
const facade = Object.create(store);
|
|
46
|
+
facade.listEntities = (type) => index.entities.filter((entity) => type === undefined || entity.type === type).map((entity) => entity.id);
|
|
47
|
+
facade.readEntity = (ref) => {
|
|
48
|
+
const position = index.byId.get(ref);
|
|
49
|
+
const entity = position === undefined ? undefined : index.entities[position];
|
|
50
|
+
if (!entity)
|
|
51
|
+
return null;
|
|
52
|
+
return {
|
|
53
|
+
id: entity.id,
|
|
54
|
+
type: entity.type,
|
|
55
|
+
canonical_name: entity.name,
|
|
56
|
+
slug: entity.id.slice(entity.type.length + 1),
|
|
57
|
+
aliases: entity.aliases,
|
|
58
|
+
keys: entity.keys,
|
|
59
|
+
first_seen: entity.firstSeen,
|
|
60
|
+
last_updated: entity.last,
|
|
61
|
+
legacy_ids: [],
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
return facade;
|
|
65
|
+
}
|
|
66
|
+
/** The WP-C resolver over the index, or null when it is not available. Never throws. */
|
|
67
|
+
export function graphResolver(store, schema, index, audiences) {
|
|
68
|
+
try {
|
|
69
|
+
return createResolver(indexBackedStore(store, index), schema, audiences ? { audiences } : {});
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function resolveName(index, schema, text, options) {
|
|
76
|
+
const filter = options.filter;
|
|
77
|
+
const cap = options.maxCandidates ?? 8;
|
|
78
|
+
const typed = text.trim();
|
|
79
|
+
const normalized = normalizeName(typed);
|
|
80
|
+
const none = { status: "unresolved", reason: "no_match", candidates: [] };
|
|
81
|
+
if (!typed)
|
|
82
|
+
return none;
|
|
83
|
+
// 1. Exact id.
|
|
84
|
+
if (isEntityRef(typed)) {
|
|
85
|
+
const hit = positions(index, [index.byId.get(typed) ?? -1], filter)[0];
|
|
86
|
+
if (hit)
|
|
87
|
+
return { status: "resolved", reason: "id", entity: hit, candidates: [] };
|
|
88
|
+
}
|
|
89
|
+
// 2. Identity key (email, Slack id, external id, web domain).
|
|
90
|
+
const byKey = positions(index, index.byKey.get(typed.toLowerCase()), filter);
|
|
91
|
+
if (byKey.length === 1)
|
|
92
|
+
return { status: "resolved", reason: "identity_key", entity: byKey[0], candidates: [] };
|
|
93
|
+
if (byKey.length > 1)
|
|
94
|
+
return { status: "ambiguous", reason: "ambiguous_name", candidates: ranked(byKey, cap) };
|
|
95
|
+
// 3. Exact normalized name, alias or slug.
|
|
96
|
+
const exact = [...positions(index, index.byName.get(normalized), filter)];
|
|
97
|
+
const slug = slugify(typed);
|
|
98
|
+
if (slug) {
|
|
99
|
+
for (const type of GRAPH_ENTITY_TYPES) {
|
|
100
|
+
const position = index.byId.get(`${type}/${slug}`);
|
|
101
|
+
if (position !== undefined)
|
|
102
|
+
exact.push(...positions(index, [position], filter));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const exactUnique = unique(exact);
|
|
106
|
+
if (exactUnique.length === 1) {
|
|
107
|
+
const entity = exactUnique[0];
|
|
108
|
+
const reason = normalizeName(entity.name) === normalized ? "exact_name" : "alias";
|
|
109
|
+
return { status: "resolved", reason, entity, candidates: [] };
|
|
110
|
+
}
|
|
111
|
+
if (exactUnique.length > 1) {
|
|
112
|
+
return { status: "ambiguous", reason: "ambiguous_name", candidates: ranked(exactUnique, cap) };
|
|
113
|
+
}
|
|
114
|
+
// 4. Refusals, then a single first name.
|
|
115
|
+
const refusals = schema.refusals;
|
|
116
|
+
const tokens = normalized.split(" ").filter(Boolean);
|
|
117
|
+
if (normalized.length < refusals.min_name_length)
|
|
118
|
+
return { status: "refused", reason: "refused_short", candidates: [] };
|
|
119
|
+
if (refusals.generic_words.includes(normalized))
|
|
120
|
+
return { status: "refused", reason: "refused_generic", candidates: [] };
|
|
121
|
+
if (refusals.job_titles.includes(normalized))
|
|
122
|
+
return { status: "refused", reason: "refused_job_title", candidates: [] };
|
|
123
|
+
if (tokens.length === 1) {
|
|
124
|
+
const sharing = positions(index, index.byFirstWord.get(normalized), filter);
|
|
125
|
+
if (sharing.length > 1) {
|
|
126
|
+
return { status: "ambiguous", reason: "ambiguous_first_word", candidates: ranked(sharing, cap) };
|
|
127
|
+
}
|
|
128
|
+
if (sharing.length === 1) {
|
|
129
|
+
return { status: "resolved", reason: "unique_first_word", entity: sharing[0], candidates: [] };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// 5. The graph resolver, when WP-C's is in place.
|
|
133
|
+
const resolver = options.resolver !== undefined
|
|
134
|
+
? options.resolver
|
|
135
|
+
: options.store
|
|
136
|
+
? graphResolver(options.store, schema, index, filter === null ? undefined : [...filter])
|
|
137
|
+
: null;
|
|
138
|
+
if (resolver) {
|
|
139
|
+
try {
|
|
140
|
+
const answer = resolver.resolve({ text: typed, ...(filter === null ? {} : { audiences: [...filter] }) });
|
|
141
|
+
const mapped = positions(index, [...(answer.entity ? [answer.entity] : []), ...answer.candidates].map((ref) => index.byId.get(ref) ?? -1), filter);
|
|
142
|
+
if (answer.status === "resolved" && answer.entity && mapped[0]?.id === answer.entity) {
|
|
143
|
+
return { status: "resolved", reason: answer.reason, entity: mapped[0], candidates: [] };
|
|
144
|
+
}
|
|
145
|
+
if (answer.status === "ambiguous" && mapped.length > 0) {
|
|
146
|
+
return { status: "ambiguous", reason: answer.reason, candidates: ranked(unique(mapped), cap) };
|
|
147
|
+
}
|
|
148
|
+
if (answer.status === "refused")
|
|
149
|
+
return { status: "refused", reason: answer.reason, candidates: [] };
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// The resolver is another package's code; a failure there falls through to the local match.
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// 6. Strict token match: the same words in another order.
|
|
156
|
+
if (normalized.length >= refusals.fuzzy_min_chars && tokens.length >= refusals.fuzzy_min_tokens) {
|
|
157
|
+
const wanted = new Set(tokens);
|
|
158
|
+
const close = [];
|
|
159
|
+
for (const entity of index.entities) {
|
|
160
|
+
if (!visible(entity, filter))
|
|
161
|
+
continue;
|
|
162
|
+
for (const name of [entity.name, ...entity.aliases]) {
|
|
163
|
+
const have = new Set(normalizeName(name).split(" ").filter(Boolean));
|
|
164
|
+
if (jaccard(wanted, have) >= refusals.fuzzy_min_jaccard) {
|
|
165
|
+
close.push(entity);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (close.length === 1)
|
|
171
|
+
return { status: "resolved", reason: "fuzzy", entity: close[0], candidates: [] };
|
|
172
|
+
if (close.length > 1)
|
|
173
|
+
return { status: "ambiguous", reason: "ambiguous_name", candidates: ranked(close, cap) };
|
|
174
|
+
}
|
|
175
|
+
// 7. Nothing certain: offer near matches, resolved by nobody.
|
|
176
|
+
const near = searchIndex(index, schema, typed, { filter, limit: Math.min(cap, 5) }).map((hit) => hit.entity);
|
|
177
|
+
return { status: "unresolved", reason: "no_match", candidates: near };
|
|
178
|
+
}
|
|
179
|
+
/** One edit (insert, delete, substitute or swap) apart. Used for typos in longer words. */
|
|
180
|
+
function oneEditApart(a, b) {
|
|
181
|
+
if (a === b)
|
|
182
|
+
return true;
|
|
183
|
+
const la = a.length;
|
|
184
|
+
const lb = b.length;
|
|
185
|
+
if (Math.abs(la - lb) > 1)
|
|
186
|
+
return false;
|
|
187
|
+
let i = 0;
|
|
188
|
+
while (i < la && i < lb && a[i] === b[i])
|
|
189
|
+
i += 1;
|
|
190
|
+
if (la === lb) {
|
|
191
|
+
if (a.slice(i + 1) === b.slice(i + 1))
|
|
192
|
+
return true;
|
|
193
|
+
return a[i] === b[i + 1] && a[i + 1] === b[i] && a.slice(i + 2) === b.slice(i + 2);
|
|
194
|
+
}
|
|
195
|
+
return la > lb ? a.slice(i + 1) === b.slice(i) : a.slice(i) === b.slice(i + 1);
|
|
196
|
+
}
|
|
197
|
+
function tokenScore(token, words) {
|
|
198
|
+
let best = 0;
|
|
199
|
+
for (const word of words) {
|
|
200
|
+
if (word === token)
|
|
201
|
+
return 30;
|
|
202
|
+
if (word.startsWith(token) && token.length >= 3)
|
|
203
|
+
best = Math.max(best, 20);
|
|
204
|
+
else if (token.length >= 4 && word.includes(token))
|
|
205
|
+
best = Math.max(best, 12);
|
|
206
|
+
else if (token.length >= 5 && oneEditApart(token, word))
|
|
207
|
+
best = Math.max(best, 10);
|
|
208
|
+
}
|
|
209
|
+
return best;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Scores every visible entity against the query. Each query word must match
|
|
213
|
+
* somewhere on the entity (name, alias, key or one open fact) to count.
|
|
214
|
+
*/
|
|
215
|
+
export function searchIndex(index, _schema, text, options) {
|
|
216
|
+
const query = normalizeName(text);
|
|
217
|
+
const tokens = query.split(" ").filter(Boolean);
|
|
218
|
+
if (tokens.length === 0)
|
|
219
|
+
return [];
|
|
220
|
+
const limit = options.limit ?? 10;
|
|
221
|
+
const hits = [];
|
|
222
|
+
const lowered = text.trim().toLowerCase();
|
|
223
|
+
index.entities.forEach((entity, position) => {
|
|
224
|
+
if (!visible(entity, options.filter))
|
|
225
|
+
return;
|
|
226
|
+
const name = normalizeName(entity.name);
|
|
227
|
+
const nameWords = name.split(" ");
|
|
228
|
+
const aliasWords = entity.aliases.flatMap((alias) => normalizeName(alias).split(" "));
|
|
229
|
+
let score = 0;
|
|
230
|
+
let matched = "name";
|
|
231
|
+
let fact;
|
|
232
|
+
let all = true;
|
|
233
|
+
const visibleFacts = (index.factsOf.get(position) ?? [])
|
|
234
|
+
.map((at) => index.facts[at])
|
|
235
|
+
.filter((entry) => entry !== undefined && rowVisible(entry.a, options.filter));
|
|
236
|
+
for (const token of tokens) {
|
|
237
|
+
const onName = tokenScore(token, nameWords);
|
|
238
|
+
const onAlias = onName === 0 ? tokenScore(token, aliasWords) : 0;
|
|
239
|
+
let onKey = 0;
|
|
240
|
+
let onFact = 0;
|
|
241
|
+
if (onName === 0 && onAlias === 0) {
|
|
242
|
+
if (allKeys(entity.keys).some((key) => key.toLowerCase().includes(token)))
|
|
243
|
+
onKey = 15;
|
|
244
|
+
if (onKey === 0) {
|
|
245
|
+
for (const entry of visibleFacts) {
|
|
246
|
+
if (normalizeName(entry.row.value).split(" ").includes(token)) {
|
|
247
|
+
onFact = 8;
|
|
248
|
+
fact ??= { audience: entry.a, row: entry.row };
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const got = onName || onAlias * 0.8 || onKey || onFact;
|
|
255
|
+
if (got === 0) {
|
|
256
|
+
all = false;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
score += got;
|
|
260
|
+
if (onName === 0)
|
|
261
|
+
matched = onAlias ? "alias" : onKey ? "key" : "fact";
|
|
262
|
+
}
|
|
263
|
+
if (!all)
|
|
264
|
+
return;
|
|
265
|
+
if (name === query)
|
|
266
|
+
score += 100;
|
|
267
|
+
else if (name.startsWith(query))
|
|
268
|
+
score += 40;
|
|
269
|
+
else if (entity.keys.email.some((key) => key.toLowerCase() === lowered))
|
|
270
|
+
score += 100;
|
|
271
|
+
if (matched !== "fact")
|
|
272
|
+
fact = undefined;
|
|
273
|
+
hits.push({ entity, score, matched, ...(fact ? { fact } : {}) });
|
|
274
|
+
});
|
|
275
|
+
return hits
|
|
276
|
+
.sort((a, b) => b.score - a.score || b.entity.rows - a.entity.rows || (a.entity.id < b.entity.id ? -1 : 1))
|
|
277
|
+
.slice(0, limit);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* The facts that answer "what is true" for one indexed entity, limited to the allowed audiences.
|
|
281
|
+
* A model's low-confidence guess at a role or affiliation is left out before the winner of a
|
|
282
|
+
* field is chosen, so every reader built on this (lookup's candidates, the brief, the signals
|
|
283
|
+
* graph context) shows the established row or nothing.
|
|
284
|
+
*/
|
|
285
|
+
export function indexedFacts(index, schema, entity, filter) {
|
|
286
|
+
const position = index.byId.get(entity.id);
|
|
287
|
+
if (position === undefined)
|
|
288
|
+
return [];
|
|
289
|
+
const rows = [];
|
|
290
|
+
for (const at of index.factsOf.get(position) ?? []) {
|
|
291
|
+
const entry = index.facts[at];
|
|
292
|
+
if (entry && rowVisible(entry.a, filter))
|
|
293
|
+
rows.push({ id: entry.id, entity: entity.id, audience: entry.a, row: entry.row });
|
|
294
|
+
}
|
|
295
|
+
return effectiveFacts(schema, entity.type, dropUnverifiedGuesses(rows).rows);
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const READER_SETTING_RELATIVE = "personal/settings/ontology-reader.yaml";
|
|
2
|
+
export type OntologyReader = "entities" | "graph";
|
|
3
|
+
export interface ReaderSetting {
|
|
4
|
+
reader: OntologyReader;
|
|
5
|
+
/** Company slug the setting names, or "" when absent or not a slug. */
|
|
6
|
+
company: string;
|
|
7
|
+
/** `person/<slug>` of the member, or "" when absent. */
|
|
8
|
+
member: string;
|
|
9
|
+
/** False when the file is missing or unreadable (the default applies). */
|
|
10
|
+
present: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function readerSettingFile(hqRoot: string): string;
|
|
13
|
+
/** Parses the setting text. Unknown keys and comments are ignored. */
|
|
14
|
+
export declare function parseReaderSetting(text: string): ReaderSetting;
|
|
15
|
+
/** Reads the setting. Never throws: any problem is the default (old reader). */
|
|
16
|
+
export declare function readReaderSetting(hqRoot: string): ReaderSetting;
|
|
17
|
+
/** True when this machine reads the new graph for `company`. */
|
|
18
|
+
export declare function graphReaderEnabled(hqRoot: string, company: string): boolean;
|
|
19
|
+
//# sourceMappingURL=reader-setting.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-E: the one reader setting (design 4.2).
|
|
3
|
+
*
|
|
4
|
+
* `<hqRoot>/personal/settings/ontology-reader.yaml` switches this machine
|
|
5
|
+
* between the old entity files and the new graph. The SessionStart hook, the
|
|
6
|
+
* graph skill and the signals context pack all read this file and nothing
|
|
7
|
+
* else. A missing or unreadable file, or any value other than `graph`, means
|
|
8
|
+
* the old reader: the default stays OLD until someone flips it.
|
|
9
|
+
*
|
|
10
|
+
* reader: entities # entities (old files) | graph (new graph)
|
|
11
|
+
* company: indigo # company whose graph the session brief comes from
|
|
12
|
+
* member: person/<slug> # optional: the member's own entity, for the brief
|
|
13
|
+
*
|
|
14
|
+
* The file is parsed line by line on purpose: the hook reads it with shell
|
|
15
|
+
* builtins and both readers must agree on what counts as a value.
|
|
16
|
+
*/
|
|
17
|
+
import * as fs from "node:fs";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
export const READER_SETTING_RELATIVE = "personal/settings/ontology-reader.yaml";
|
|
20
|
+
const DEFAULT_SETTING = { reader: "entities", company: "", member: "", present: false };
|
|
21
|
+
const MAX_SETTING_BYTES = 4096;
|
|
22
|
+
export function readerSettingFile(hqRoot) {
|
|
23
|
+
return path.join(hqRoot, ...READER_SETTING_RELATIVE.split("/"));
|
|
24
|
+
}
|
|
25
|
+
/** Parses the setting text. Unknown keys and comments are ignored. */
|
|
26
|
+
export function parseReaderSetting(text) {
|
|
27
|
+
const out = { ...DEFAULT_SETTING, present: true };
|
|
28
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
29
|
+
const match = /^([a-z_]+):[ \t]*([^#]*?)[ \t]*(?:#.*)?$/.exec(raw);
|
|
30
|
+
if (!match)
|
|
31
|
+
continue;
|
|
32
|
+
const key = match[1] ?? "";
|
|
33
|
+
const value = (match[2] ?? "").replace(/^["']|["']$/g, "");
|
|
34
|
+
if (key === "reader")
|
|
35
|
+
out.reader = value === "graph" ? "graph" : "entities";
|
|
36
|
+
else if (key === "company")
|
|
37
|
+
out.company = /^[a-z0-9][a-z0-9-]*$/.test(value) ? value : "";
|
|
38
|
+
else if (key === "member") {
|
|
39
|
+
out.member = /^person\/[a-z0-9][a-z0-9._-]*$/.test(value) && !value.includes("..") ? value : "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Reads the setting. Never throws: any problem is the default (old reader). */
|
|
45
|
+
export function readReaderSetting(hqRoot) {
|
|
46
|
+
try {
|
|
47
|
+
const file = readerSettingFile(hqRoot);
|
|
48
|
+
const stat = fs.statSync(file);
|
|
49
|
+
if (!stat.isFile() || stat.size > MAX_SETTING_BYTES)
|
|
50
|
+
return { ...DEFAULT_SETTING };
|
|
51
|
+
return parseReaderSetting(fs.readFileSync(file, "utf8"));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return { ...DEFAULT_SETTING };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** True when this machine reads the new graph for `company`. */
|
|
58
|
+
export function graphReaderEnabled(hqRoot, company) {
|
|
59
|
+
const setting = readReaderSetting(hqRoot);
|
|
60
|
+
return setting.reader === "graph" && setting.company === company;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=reader-setting.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AudienceKey, EdgeRow, EntityRef, EntityUpsert, FactRow, GraphContext, GraphStore, IngestRow, Origin, SourceRef, TimelineRow, Verb } from "../types.js";
|
|
2
|
+
export declare const PRIVATE: AudienceKey;
|
|
3
|
+
export declare const COMPANY: AudienceKey;
|
|
4
|
+
export interface TestGraph {
|
|
5
|
+
dir: string;
|
|
6
|
+
hqRoot: string;
|
|
7
|
+
root: string;
|
|
8
|
+
store: GraphStore;
|
|
9
|
+
context: GraphContext;
|
|
10
|
+
cleanup(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function upsert(ref: EntityRef, name: string, extra?: Partial<EntityUpsert>): EntityUpsert;
|
|
13
|
+
export declare function fact(field: string, value: string, from?: string, src?: SourceRef, by?: Origin): FactRow;
|
|
14
|
+
export declare function edge(verb: Verb, target: EntityRef, from?: string, src?: SourceRef, by?: Origin): EdgeRow;
|
|
15
|
+
export declare function timeline(date: string, text: string, src?: SourceRef, signalType?: string): TimelineRow;
|
|
16
|
+
export declare function rows(audience: AudienceKey, entity: EntityRef, list: readonly IngestRow["row"][]): IngestRow[];
|
|
17
|
+
/** An empty graph in a temp HQ root, with the folder skeleton written. */
|
|
18
|
+
export declare function emptyTestGraph(company?: string): TestGraph;
|
|
19
|
+
export declare const COREY: EntityRef;
|
|
20
|
+
export declare const STEFAN: EntityRef;
|
|
21
|
+
export declare const CAITLIN_A: EntityRef;
|
|
22
|
+
export declare const CAITLIN_B: EntityRef;
|
|
23
|
+
export declare const DANA: EntityRef;
|
|
24
|
+
export declare const ALEX_PERSON: EntityRef;
|
|
25
|
+
export declare const ALEX_CONTACT: EntityRef;
|
|
26
|
+
export declare const PLATFORM: EntityRef;
|
|
27
|
+
export declare const HQ_CLI: EntityRef;
|
|
28
|
+
export declare const SIGNALS: EntityRef;
|
|
29
|
+
export declare const OLD_THING: EntityRef;
|
|
30
|
+
export declare const ATLAS: EntityRef;
|
|
31
|
+
export declare const ACME: EntityRef;
|
|
32
|
+
export declare const DECISION: EntityRef;
|
|
33
|
+
/** The fixture graph. Company-wide rows plus one private audience (`PRIVATE`). */
|
|
34
|
+
export declare function buildTestGraph(): TestGraph;
|
|
35
|
+
/** Writes the reader setting into the fixture HQ root. */
|
|
36
|
+
export declare function writeReaderSetting(hqRoot: string, text: string): void;
|
|
37
|
+
//# sourceMappingURL=test-graph.d.ts.map
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-E test fixture: a small graph with one private audience, written through
|
|
3
|
+
* the real store. Not a test file; imported by the read, brief and signals
|
|
4
|
+
* context tests.
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { applyIngest, openGraphStore } from "../store/index.js";
|
|
10
|
+
export const PRIVATE = "aaaaaaaaaaaaaaaa";
|
|
11
|
+
export const COMPANY = "company";
|
|
12
|
+
export function upsert(ref, name, extra = {}) {
|
|
13
|
+
const cut = ref.indexOf("/");
|
|
14
|
+
return {
|
|
15
|
+
type: ref.slice(0, cut),
|
|
16
|
+
slug: ref.slice(cut + 1),
|
|
17
|
+
canonical_name: name,
|
|
18
|
+
seen: "2026-06-25",
|
|
19
|
+
...extra,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function fact(field, value, from = "2026-06-25", src = "signal:4f35becbeabe", by = "rule:test") {
|
|
23
|
+
return { kind: "F", field, value, valid: { from }, src, learned: from, by, conf: 0.8 };
|
|
24
|
+
}
|
|
25
|
+
export function edge(verb, target, from = "2026-06-25", src = "signal:4f35becbeabe", by = "rule:test") {
|
|
26
|
+
return { kind: "E", verb, target, valid: { from }, src, learned: from, by, conf: 0.8 };
|
|
27
|
+
}
|
|
28
|
+
export function timeline(date, text, src = "signal:4f35becbeabe", signalType = "decision") {
|
|
29
|
+
return { kind: "T", date, signalType, text, src };
|
|
30
|
+
}
|
|
31
|
+
export function rows(audience, entity, list) {
|
|
32
|
+
return list.map((row) => ({ entity, audience, row }));
|
|
33
|
+
}
|
|
34
|
+
/** An empty graph in a temp HQ root, with the folder skeleton written. */
|
|
35
|
+
export function emptyTestGraph(company = "acme") {
|
|
36
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "og-read-"));
|
|
37
|
+
const hqRoot = path.join(dir, "hq");
|
|
38
|
+
const companyRoot = path.join(hqRoot, "companies", company);
|
|
39
|
+
const root = path.join(companyRoot, ".hq", "ontology-graph");
|
|
40
|
+
const store = openGraphStore(root);
|
|
41
|
+
store.init();
|
|
42
|
+
return {
|
|
43
|
+
dir,
|
|
44
|
+
hqRoot,
|
|
45
|
+
root,
|
|
46
|
+
store,
|
|
47
|
+
context: { hqRoot, company, companyRoot, graphRoot: root, json: false },
|
|
48
|
+
cleanup: () => fs.rmSync(dir, { recursive: true, force: true }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export const COREY = "person/corey-epstein";
|
|
52
|
+
export const STEFAN = "person/stefan-johnson";
|
|
53
|
+
export const CAITLIN_A = "person/caitlin-adams";
|
|
54
|
+
export const CAITLIN_B = "person/caitlin-brown";
|
|
55
|
+
export const DANA = "person/dana-secret";
|
|
56
|
+
export const ALEX_PERSON = "person/alex-kim";
|
|
57
|
+
export const ALEX_CONTACT = "contact/alex-kim";
|
|
58
|
+
export const PLATFORM = "team/platform";
|
|
59
|
+
export const HQ_CLI = "project/hq-cli";
|
|
60
|
+
export const SIGNALS = "project/signals";
|
|
61
|
+
export const OLD_THING = "project/old-thing";
|
|
62
|
+
export const ATLAS = "project/atlas-secret";
|
|
63
|
+
export const ACME = "company/acme-corp";
|
|
64
|
+
export const DECISION = "decision/release-hq-cli-v5";
|
|
65
|
+
/** The fixture graph. Company-wide rows plus one private audience (`PRIVATE`). */
|
|
66
|
+
export function buildTestGraph() {
|
|
67
|
+
const graph = emptyTestGraph();
|
|
68
|
+
applyIngest(graph.store, {
|
|
69
|
+
input: "signal:4f35becbeabe",
|
|
70
|
+
date: "2026-06-25",
|
|
71
|
+
entities: [
|
|
72
|
+
upsert(COREY, "Corey Epstein", {
|
|
73
|
+
aliases: ["Corey E"],
|
|
74
|
+
keys: { email: ["corey@example.com"], slack_id: ["U065YSKUCJK"] },
|
|
75
|
+
}),
|
|
76
|
+
upsert(STEFAN, "Stefan Johnson", { keys: { external_ids: ["hq:prs_stefan0001"] } }),
|
|
77
|
+
upsert(CAITLIN_A, "Caitlin Adams"),
|
|
78
|
+
upsert(CAITLIN_B, "Caitlin Brown"),
|
|
79
|
+
upsert(ALEX_PERSON, "Alex Kim"),
|
|
80
|
+
upsert(ALEX_CONTACT, "Alex Kim"),
|
|
81
|
+
upsert(PLATFORM, "Platform"),
|
|
82
|
+
upsert(HQ_CLI, "hq-cli", { aliases: ["HQ command line"] }),
|
|
83
|
+
upsert(SIGNALS, "Signals"),
|
|
84
|
+
upsert(OLD_THING, "Old Thing"),
|
|
85
|
+
upsert(ACME, "Acme Corp", { keys: { web_domains: ["acme.example"] } }),
|
|
86
|
+
upsert(DECISION, "Release hq-cli v5", { seen: "2026-11-20" }),
|
|
87
|
+
],
|
|
88
|
+
rows: [
|
|
89
|
+
...rows(COMPANY, COREY, [
|
|
90
|
+
fact("role_title", "CEO", "2026-06-25", "legacy:1486e2a03f83", "legacy"),
|
|
91
|
+
edge("works_on", HQ_CLI),
|
|
92
|
+
edge("leads", PLATFORM),
|
|
93
|
+
]),
|
|
94
|
+
...rows(COMPANY, STEFAN, [
|
|
95
|
+
fact("role_title", "Engineer"),
|
|
96
|
+
edge("reports_to", COREY),
|
|
97
|
+
edge("member_of", PLATFORM),
|
|
98
|
+
edge("works_on", HQ_CLI),
|
|
99
|
+
]),
|
|
100
|
+
...rows(COMPANY, CAITLIN_A, [fact("role_title", "Designer")]),
|
|
101
|
+
...rows(COMPANY, CAITLIN_B, [fact("role_title", "Recruiter")]),
|
|
102
|
+
...rows(COMPANY, ALEX_PERSON, [fact("role_title", "Analyst")]),
|
|
103
|
+
...rows(COMPANY, ALEX_CONTACT, [fact("title", "Buyer")]),
|
|
104
|
+
...rows(COMPANY, HQ_CLI, [
|
|
105
|
+
fact("status", "active"),
|
|
106
|
+
fact("stage", "beta", "2026-11-19"),
|
|
107
|
+
edge("owned_by", STEFAN),
|
|
108
|
+
timeline("2026-06-25", "Release hq-cli v5.50.2"),
|
|
109
|
+
timeline("2026-11-20", "Ship the graph reader", "signal:ab12cd34ef56"),
|
|
110
|
+
]),
|
|
111
|
+
...rows(COMPANY, SIGNALS, [fact("status", "active")]),
|
|
112
|
+
...rows(COMPANY, OLD_THING, [fact("status", "archived")]),
|
|
113
|
+
...rows(COMPANY, ACME, [fact("relation", "customer"), fact("stage", "demo")]),
|
|
114
|
+
...rows(COMPANY, DECISION, [
|
|
115
|
+
fact("decided_on", "2026-11-20", "2026-11-20"),
|
|
116
|
+
fact("statement", "Release hq-cli v5 this week", "2026-11-20"),
|
|
117
|
+
edge("about", HQ_CLI, "2026-11-20"),
|
|
118
|
+
edge("decided_by", COREY, "2026-11-20"),
|
|
119
|
+
]),
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
applyIngest(graph.store, {
|
|
123
|
+
input: "source:sources/slack/private-thread.md",
|
|
124
|
+
date: "2026-07-01",
|
|
125
|
+
entities: [upsert(DANA, "Dana Secret"), upsert(ATLAS, "Project Atlas")],
|
|
126
|
+
rows: [
|
|
127
|
+
...rows(PRIVATE, DANA, [
|
|
128
|
+
fact("role_title", "Acquisition lead", "2026-07-01", "source:sources/slack/private-thread.md"),
|
|
129
|
+
edge("works_on", ATLAS, "2026-07-01", "source:sources/slack/private-thread.md"),
|
|
130
|
+
]),
|
|
131
|
+
...rows(PRIVATE, ATLAS, [
|
|
132
|
+
fact("status", "active", "2026-07-01", "source:sources/slack/private-thread.md"),
|
|
133
|
+
fact("summary", "Confidential merger with Zebra Holdings", "2026-07-01", "source:sources/slack/private-thread.md"),
|
|
134
|
+
]),
|
|
135
|
+
...rows(PRIVATE, COREY, [
|
|
136
|
+
fact("affiliation", "Zebra Holdings", "2026-07-01", "source:sources/slack/private-thread.md"),
|
|
137
|
+
edge("works_on", ATLAS, "2026-07-01", "source:sources/slack/private-thread.md"),
|
|
138
|
+
]),
|
|
139
|
+
...rows(PRIVATE, HQ_CLI, [timeline("2026-07-01", "Private note about pricing", "source:sources/slack/private-thread.md", "note")]),
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
return graph;
|
|
143
|
+
}
|
|
144
|
+
/** Writes the reader setting into the fixture HQ root. */
|
|
145
|
+
export function writeReaderSetting(hqRoot, text) {
|
|
146
|
+
const file = path.join(hqRoot, "personal", "settings", "ontology-reader.yaml");
|
|
147
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
148
|
+
fs.writeFileSync(file, text);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=test-graph.js.map
|