semantic-atlas 0.4.0 → 2.0.0
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/.agents/skills/semantic-atlas/SKILL.md +134 -166
- package/.agents/skills/semantic-atlas/agents/openai.yaml +4 -0
- package/.agents/skills/semantic-atlas/references/observations.md +130 -0
- package/.agents/skills/semantic-atlas/scripts/query-context.mjs +110 -0
- package/.agents/skills/semantic-atlas-maintenance/SKILL.md +93 -0
- package/.agents/skills/semantic-atlas-maintenance/agents/openai.yaml +4 -0
- package/.agents/skills/semantic-atlas-maintenance/references/reconciliation.md +56 -0
- package/README.md +133 -265
- package/dist/application/map-application.d.ts +24 -0
- package/dist/application/map-application.d.ts.map +1 -0
- package/dist/application/map-application.js +134 -0
- package/dist/application/map-application.js.map +1 -0
- package/dist/cli/bin.js +6 -42
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/observation-commands.d.ts +16 -0
- package/dist/cli/observation-commands.d.ts.map +1 -0
- package/dist/cli/observation-commands.js +118 -0
- package/dist/cli/observation-commands.js.map +1 -0
- package/dist/cli/projection-writer.d.ts +2 -0
- package/dist/cli/projection-writer.d.ts.map +1 -0
- package/dist/cli/projection-writer.js +9 -0
- package/dist/cli/projection-writer.js.map +1 -0
- package/dist/cli/reconciliation-command.d.ts +7 -0
- package/dist/cli/reconciliation-command.d.ts.map +1 -0
- package/dist/cli/reconciliation-command.js +33 -0
- package/dist/cli/reconciliation-command.js.map +1 -0
- package/dist/cli/run-cli.d.ts +21 -0
- package/dist/cli/run-cli.d.ts.map +1 -0
- package/dist/cli/run-cli.js +299 -0
- package/dist/cli/run-cli.js.map +1 -0
- package/dist/contracts/cli.d.ts +166 -1211
- package/dist/contracts/cli.d.ts.map +1 -1
- package/dist/contracts/cli.js +2 -232
- package/dist/contracts/cli.js.map +1 -0
- package/dist/contracts/insights.d.ts +39 -1
- package/dist/contracts/insights.d.ts.map +1 -1
- package/dist/contracts/insights.js +2 -1
- package/dist/contracts/insights.js.map +1 -0
- package/dist/contracts/map.d.ts +154 -0
- package/dist/contracts/map.d.ts.map +1 -0
- package/dist/contracts/map.js +60 -0
- package/dist/contracts/map.js.map +1 -0
- package/dist/contracts/observation.d.ts +414 -0
- package/dist/contracts/observation.d.ts.map +1 -0
- package/dist/contracts/observation.js +125 -0
- package/dist/contracts/observation.js.map +1 -0
- package/dist/contracts/projection.d.ts +7 -0
- package/dist/contracts/projection.d.ts.map +1 -0
- package/dist/contracts/projection.js +2 -0
- package/dist/contracts/projection.js.map +1 -0
- package/dist/contracts/reconciliation.d.ts +40 -0
- package/dist/contracts/reconciliation.d.ts.map +1 -0
- package/dist/contracts/reconciliation.js +2 -0
- package/dist/contracts/reconciliation.js.map +1 -0
- package/dist/index.d.ts +7 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -0
- package/dist/insights/insight-service.d.ts +14 -0
- package/dist/insights/insight-service.d.ts.map +1 -0
- package/dist/insights/insight-service.js +129 -0
- package/dist/insights/insight-service.js.map +1 -0
- package/dist/map/business-graph.d.ts +32 -0
- package/dist/map/business-graph.d.ts.map +1 -0
- package/dist/map/business-graph.js +122 -0
- package/dist/map/business-graph.js.map +1 -0
- package/dist/map/map-document-loader.d.ts +13 -0
- package/dist/map/map-document-loader.d.ts.map +1 -0
- package/dist/map/map-document-loader.js +86 -0
- package/dist/map/map-document-loader.js.map +1 -0
- package/dist/map/map-validator.d.ts +12 -0
- package/dist/map/map-validator.d.ts.map +1 -0
- package/dist/map/map-validator.js +322 -0
- package/dist/map/map-validator.js.map +1 -0
- package/dist/observations/observation-application.d.ts +23 -0
- package/dist/observations/observation-application.d.ts.map +1 -0
- package/dist/observations/observation-application.js +62 -0
- package/dist/observations/observation-application.js.map +1 -0
- package/dist/observations/observation-claim-manager.d.ts +17 -0
- package/dist/observations/observation-claim-manager.d.ts.map +1 -0
- package/dist/observations/observation-claim-manager.js +198 -0
- package/dist/observations/observation-claim-manager.js.map +1 -0
- package/dist/observations/observation-store.d.ts +43 -0
- package/dist/observations/observation-store.d.ts.map +1 -0
- package/dist/observations/observation-store.js +213 -0
- package/dist/observations/observation-store.js.map +1 -0
- package/dist/observations/repository-identity.d.ts +12 -0
- package/dist/observations/repository-identity.d.ts.map +1 -0
- package/dist/observations/repository-identity.js +108 -0
- package/dist/observations/repository-identity.js.map +1 -0
- package/dist/query/context-query-service.d.ts +15 -0
- package/dist/query/context-query-service.d.ts.map +1 -0
- package/dist/query/context-query-service.js +36 -0
- package/dist/query/context-query-service.js.map +1 -0
- package/dist/reconciliation/reconciliation-service.d.ts +10 -0
- package/dist/reconciliation/reconciliation-service.d.ts.map +1 -0
- package/dist/reconciliation/reconciliation-service.js +114 -0
- package/dist/reconciliation/reconciliation-service.js.map +1 -0
- package/dist/rendering/map-projector.d.ts +8 -0
- package/dist/rendering/map-projector.d.ts.map +1 -0
- package/dist/rendering/map-projector.js +386 -0
- package/dist/rendering/map-projector.js.map +1 -0
- package/dist/setup/managed-skill-installer.d.ts +60 -0
- package/dist/setup/managed-skill-installer.d.ts.map +1 -0
- package/dist/setup/managed-skill-installer.js +293 -0
- package/dist/setup/managed-skill-installer.js.map +1 -0
- package/dist/setup/package-identity.d.ts +6 -0
- package/dist/setup/package-identity.d.ts.map +1 -0
- package/dist/setup/package-identity.js +16 -0
- package/dist/setup/package-identity.js.map +1 -0
- package/dist/setup/package-upgrader.d.ts +10 -22
- package/dist/setup/package-upgrader.d.ts.map +1 -1
- package/dist/setup/package-upgrader.js +60 -76
- package/dist/setup/package-upgrader.js.map +1 -0
- package/docs/architecture.md +426 -0
- package/docs/evaluation.md +220 -174
- package/docs/index.md +27 -45
- package/docs/map-format.md +225 -0
- package/docs/observations.md +167 -0
- package/docs/product-contract.md +282 -165
- package/examples/commerce.yaml +204 -0
- package/package.json +31 -32
- package/.agents/skills/semantic-atlas/references/graph-patch.md +0 -190
- package/.agents/skills/semantic-atlas/references/product-feedback.md +0 -34
- package/.agents/skills/semantic-atlas/references/result-routing.md +0 -104
- package/.agents/skills/semantic-atlas/references/snapshot-bootstrap.md +0 -42
- package/.agents/skills/semantic-atlas-insights/SKILL.md +0 -55
- package/README.zh-CN.md +0 -296
- package/dist/business-flow/business-flow-derivation-service.d.ts +0 -11
- package/dist/business-flow/business-flow-derivation-service.d.ts.map +0 -1
- package/dist/business-flow/business-flow-derivation-service.js +0 -151
- package/dist/business-flow/business-flow-draft.d.ts +0 -16
- package/dist/business-flow/business-flow-draft.d.ts.map +0 -1
- package/dist/business-flow/business-flow-draft.js +0 -150
- package/dist/business-flow/framework-business-strategy.d.ts +0 -7
- package/dist/business-flow/framework-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/framework-business-strategy.js +0 -1
- package/dist/business-flow/strategies/bullmq-business-strategy.d.ts +0 -10
- package/dist/business-flow/strategies/bullmq-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/bullmq-business-strategy.js +0 -79
- package/dist/business-flow/strategies/called-operation-derivation.d.ts +0 -13
- package/dist/business-flow/strategies/called-operation-derivation.d.ts.map +0 -1
- package/dist/business-flow/strategies/called-operation-derivation.js +0 -32
- package/dist/business-flow/strategies/graphql-business-strategy.d.ts +0 -8
- package/dist/business-flow/strategies/graphql-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/graphql-business-strategy.js +0 -65
- package/dist/business-flow/strategies/nestjs-business-strategy.d.ts +0 -8
- package/dist/business-flow/strategies/nestjs-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/nestjs-business-strategy.js +0 -72
- package/dist/business-flow/strategies/strategy-helpers.d.ts +0 -32
- package/dist/business-flow/strategies/strategy-helpers.d.ts.map +0 -1
- package/dist/business-flow/strategies/strategy-helpers.js +0 -49
- package/dist/business-flow/strategies/typeorm-business-strategy.d.ts +0 -10
- package/dist/business-flow/strategies/typeorm-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/typeorm-business-strategy.js +0 -136
- package/dist/business-flow/strategies/verified-invariant-strategy.d.ts +0 -5
- package/dist/business-flow/strategies/verified-invariant-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/verified-invariant-strategy.js +0 -38
- package/dist/business-flow/strategies/verified-test-strategy.d.ts +0 -5
- package/dist/business-flow/strategies/verified-test-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/verified-test-strategy.js +0 -26
- package/dist/business-flow/structural-flow-catalog.d.ts +0 -21
- package/dist/business-flow/structural-flow-catalog.d.ts.map +0 -1
- package/dist/business-flow/structural-flow-catalog.js +0 -125
- package/dist/business-flow/types.d.ts +0 -51
- package/dist/business-flow/types.d.ts.map +0 -1
- package/dist/business-flow/types.js +0 -1
- package/dist/cli/argument-parser.d.ts +0 -3
- package/dist/cli/argument-parser.d.ts.map +0 -1
- package/dist/cli/argument-parser.js +0 -200
- package/dist/cli/cli-application.d.ts +0 -39
- package/dist/cli/cli-application.d.ts.map +0 -1
- package/dist/cli/cli-application.js +0 -571
- package/dist/cli/cli-error.d.ts +0 -12
- package/dist/cli/cli-error.d.ts.map +0 -1
- package/dist/cli/cli-error.js +0 -44
- package/dist/cli/cli-presenter.d.ts +0 -14
- package/dist/cli/cli-presenter.d.ts.map +0 -1
- package/dist/cli/cli-presenter.js +0 -36
- package/dist/cli/insights-cli.d.ts +0 -6
- package/dist/cli/insights-cli.d.ts.map +0 -1
- package/dist/cli/insights-cli.js +0 -236
- package/dist/cli/main.d.ts +0 -3
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js +0 -137
- package/dist/cli/standalone-cli.d.ts +0 -3
- package/dist/cli/standalone-cli.d.ts.map +0 -1
- package/dist/cli/standalone-cli.js +0 -104
- package/dist/cli/types.d.ts +0 -49
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/types.js +0 -1
- package/dist/cli/web-cli.d.ts +0 -9
- package/dist/cli/web-cli.d.ts.map +0 -1
- package/dist/cli/web-cli.js +0 -134
- package/dist/contracts/graph.d.ts +0 -266
- package/dist/contracts/graph.d.ts.map +0 -1
- package/dist/contracts/graph.js +0 -182
- package/dist/contracts/identifiers.d.ts +0 -4
- package/dist/contracts/identifiers.d.ts.map +0 -1
- package/dist/contracts/identifiers.js +0 -7
- package/dist/contracts/public-contracts.d.ts +0 -5
- package/dist/contracts/public-contracts.d.ts.map +0 -1
- package/dist/contracts/public-contracts.js +0 -4
- package/dist/evaluation/comparison.d.ts +0 -30
- package/dist/evaluation/comparison.d.ts.map +0 -1
- package/dist/evaluation/comparison.js +0 -108
- package/dist/evaluation/contracts.d.ts +0 -301
- package/dist/evaluation/contracts.d.ts.map +0 -1
- package/dist/evaluation/contracts.js +0 -413
- package/dist/graph/graph-store.d.ts +0 -55
- package/dist/graph/graph-store.d.ts.map +0 -1
- package/dist/graph/graph-store.js +0 -912
- package/dist/graph/types.d.ts +0 -189
- package/dist/graph/types.d.ts.map +0 -1
- package/dist/graph/types.js +0 -1
- package/dist/insights/contracts.d.ts +0 -266
- package/dist/insights/contracts.d.ts.map +0 -1
- package/dist/insights/contracts.js +0 -124
- package/dist/insights/insights-store.d.ts +0 -73
- package/dist/insights/insights-store.d.ts.map +0 -1
- package/dist/insights/insights-store.js +0 -246
- package/dist/knowledge/business-knowledge-service.d.ts +0 -24
- package/dist/knowledge/business-knowledge-service.d.ts.map +0 -1
- package/dist/knowledge/business-knowledge-service.js +0 -200
- package/dist/knowledge/graph-patch-conflict-error.d.ts +0 -8
- package/dist/knowledge/graph-patch-conflict-error.d.ts.map +0 -1
- package/dist/knowledge/graph-patch-conflict-error.js +0 -12
- package/dist/knowledge/structural-target-binding.d.ts +0 -14
- package/dist/knowledge/structural-target-binding.d.ts.map +0 -1
- package/dist/knowledge/structural-target-binding.js +0 -11
- package/dist/package-metadata.d.ts +0 -2
- package/dist/package-metadata.d.ts.map +0 -1
- package/dist/package-metadata.js +0 -9
- package/dist/repository/git-command.d.ts +0 -3
- package/dist/repository/git-command.d.ts.map +0 -1
- package/dist/repository/git-command.js +0 -25
- package/dist/repository/repository-inspector.d.ts +0 -8
- package/dist/repository/repository-inspector.d.ts.map +0 -1
- package/dist/repository/repository-inspector.js +0 -97
- package/dist/repository/repository-language-support.d.ts +0 -14
- package/dist/repository/repository-language-support.d.ts.map +0 -1
- package/dist/repository/repository-language-support.js +0 -64
- package/dist/repository/types.d.ts +0 -9
- package/dist/repository/types.d.ts.map +0 -1
- package/dist/repository/types.js +0 -1
- package/dist/runtime/sqlite-compatibility-process.d.ts +0 -8
- package/dist/runtime/sqlite-compatibility-process.d.ts.map +0 -1
- package/dist/runtime/sqlite-compatibility-process.js +0 -20
- package/dist/setup/skill-installer.d.ts +0 -20
- package/dist/setup/skill-installer.d.ts.map +0 -1
- package/dist/setup/skill-installer.js +0 -187
- package/dist/snapshots/repository-snapshot.d.ts +0 -4
- package/dist/snapshots/repository-snapshot.d.ts.map +0 -1
- package/dist/snapshots/repository-snapshot.js +0 -119
- package/dist/snapshots/types.d.ts +0 -30
- package/dist/snapshots/types.d.ts.map +0 -1
- package/dist/snapshots/types.js +0 -1
- package/dist/storage/atlas-database.d.ts +0 -25
- package/dist/storage/atlas-database.d.ts.map +0 -1
- package/dist/storage/atlas-database.js +0 -483
- package/dist/storage/snapshot-store.d.ts +0 -19
- package/dist/storage/snapshot-store.d.ts.map +0 -1
- package/dist/storage/snapshot-store.js +0 -74
- package/dist/structural-backend/codegraph-backend.d.ts +0 -57
- package/dist/structural-backend/codegraph-backend.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-backend.js +0 -1230
- package/dist/structural-backend/codegraph-worker-client.d.ts +0 -5
- package/dist/structural-backend/codegraph-worker-client.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-worker-client.js +0 -118
- package/dist/structural-backend/codegraph-worker-protocol.d.ts +0 -35
- package/dist/structural-backend/codegraph-worker-protocol.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-worker-protocol.js +0 -1
- package/dist/structural-backend/codegraph-worker.d.ts +0 -2
- package/dist/structural-backend/codegraph-worker.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-worker.js +0 -131
- package/dist/structural-backend/process-instance.d.ts +0 -18
- package/dist/structural-backend/process-instance.d.ts.map +0 -1
- package/dist/structural-backend/process-instance.js +0 -207
- package/dist/structural-backend/structural-fact-changes.d.ts +0 -7
- package/dist/structural-backend/structural-fact-changes.d.ts.map +0 -1
- package/dist/structural-backend/structural-fact-changes.js +0 -78
- package/dist/structural-backend/structural-projection-bootstrapper.d.ts +0 -10
- package/dist/structural-backend/structural-projection-bootstrapper.d.ts.map +0 -1
- package/dist/structural-backend/structural-projection-bootstrapper.js +0 -295
- package/dist/structural-backend/structural-publication.d.ts +0 -13
- package/dist/structural-backend/structural-publication.d.ts.map +0 -1
- package/dist/structural-backend/structural-publication.js +0 -255
- package/dist/structural-backend/structural-write-lock.d.ts +0 -8
- package/dist/structural-backend/structural-write-lock.d.ts.map +0 -1
- package/dist/structural-backend/structural-write-lock.js +0 -415
- package/dist/structural-backend/types.d.ts +0 -144
- package/dist/structural-backend/types.d.ts.map +0 -1
- package/dist/structural-backend/types.js +0 -11
- package/dist/web/application/atlas-read-service.d.ts +0 -27
- package/dist/web/application/atlas-read-service.d.ts.map +0 -1
- package/dist/web/application/atlas-read-service.js +0 -216
- package/dist/web/application/primary-repository-catalog.d.ts +0 -15
- package/dist/web/application/primary-repository-catalog.d.ts.map +0 -1
- package/dist/web/application/primary-repository-catalog.js +0 -202
- package/dist/web/application/types.d.ts +0 -41
- package/dist/web/application/types.d.ts.map +0 -1
- package/dist/web/application/types.js +0 -1
- package/dist/web/server/api-router.d.ts +0 -4
- package/dist/web/server/api-router.d.ts.map +0 -1
- package/dist/web/server/api-router.js +0 -151
- package/dist/web/server/local-web-server.d.ts +0 -12
- package/dist/web/server/local-web-server.d.ts.map +0 -1
- package/dist/web/server/local-web-server.js +0 -100
- package/dist/web-client/assets/index-DneaErDj.css +0 -1
- package/dist/web-client/assets/index-cze_4vtt.js +0 -2
- package/dist/web-client/assets/index-cze_4vtt.js.map +0 -1
- package/dist/web-client/index.html +0 -61
- package/dist/world/business-map-projector.d.ts +0 -14
- package/dist/world/business-map-projector.d.ts.map +0 -1
- package/dist/world/business-map-projector.js +0 -178
- package/dist/world/types.d.ts +0 -77
- package/dist/world/types.d.ts.map +0 -1
- package/dist/world/types.js +0 -1
- package/dist/world/world-graph-query.d.ts +0 -30
- package/dist/world/world-graph-query.d.ts.map +0 -1
- package/dist/world/world-graph-query.js +0 -252
- package/dist/world/world-model-service.d.ts +0 -21
- package/dist/world/world-model-service.d.ts.map +0 -1
- package/dist/world/world-model-service.js +0 -219
- package/dist/world/world-snapshot-store.d.ts +0 -41
- package/dist/world/world-snapshot-store.d.ts.map +0 -1
- package/dist/world/world-snapshot-store.js +0 -581
- package/docs/README.md +0 -30
- package/docs/architecture/codegraph-backend.md +0 -190
- package/docs/architecture/continuous-business-learning.md +0 -240
- package/docs/architecture/web-viewer.md +0 -225
- package/docs/contracts/cli-v1.md +0 -179
- package/docs/contracts/graph-model.md +0 -106
- package/docs/contracts/graph-patch-v1.md +0 -105
- package/docs/contracts/http-api-v1.md +0 -155
- package/docs/contracts/insights-v1.md +0 -84
- package/docs/log.md +0 -159
- package/docs/mindmaps/semantic-atlas-overview.drawio +0 -255
- package/docs/mindmaps/semantic-atlas-overview.png +0 -0
- package/docs/mindmaps/semantic-atlas-overview.zh-CN.drawio +0 -255
- package/docs/mindmaps/semantic-atlas-overview.zh-CN.png +0 -0
- package/schemas/cli-envelope-v1.schema.json +0 -1244
- package/schemas/evaluation-plan-v1.schema.json +0 -211
- package/schemas/evaluation-run-v1.schema.json +0 -659
- package/schemas/graph-patch-v1.schema.json +0 -392
- package/schemas/insights-envelope-v1.schema.json +0 -428
|
@@ -1,912 +0,0 @@
|
|
|
1
|
-
import { assertionCertaintySchema, businessKeySchema, businessNodeKindSchema, businessRelationTypeSchema, evidenceSchema, relativeSourcePathSchema, sourceRangeSchema, structuralNodeIdSchema, } from "../contracts/graph.js";
|
|
2
|
-
import { contentIdentifierSchema } from "../contracts/identifiers.js";
|
|
3
|
-
import { AtlasDatabase, CURRENT_ATLAS_SCHEMA_VERSION, } from "../storage/atlas-database.js";
|
|
4
|
-
import { readStructuralTargetBinding, } from "../knowledge/structural-target-binding.js";
|
|
5
|
-
export class GraphStore {
|
|
6
|
-
databasePath;
|
|
7
|
-
#atlasDatabase;
|
|
8
|
-
#repositoryId;
|
|
9
|
-
#gitDirectory;
|
|
10
|
-
constructor(repository, options = {}) {
|
|
11
|
-
this.#atlasDatabase = new AtlasDatabase(repository, options);
|
|
12
|
-
this.databasePath = this.#atlasDatabase.databasePath;
|
|
13
|
-
this.#repositoryId = repository.repositoryId;
|
|
14
|
-
this.#gitDirectory = repository.gitDirectory;
|
|
15
|
-
}
|
|
16
|
-
get schemaVersion() {
|
|
17
|
-
return this.#atlasDatabase.schemaVersion;
|
|
18
|
-
}
|
|
19
|
-
reconcileSnapshot(snapshotId) {
|
|
20
|
-
contentIdentifierSchema.parse(snapshotId);
|
|
21
|
-
this.transaction(() => {
|
|
22
|
-
const snapshot = this.requireSnapshot(snapshotId);
|
|
23
|
-
this.reconcileEvidenceBindings(snapshot);
|
|
24
|
-
this.refreshBusinessValidity(snapshot);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
mutateBusinessGraph(mutation) {
|
|
28
|
-
this.validateBusinessMutation(mutation);
|
|
29
|
-
this.transaction(() => {
|
|
30
|
-
this.requireSnapshot(mutation.baseSnapshotId);
|
|
31
|
-
for (const selector of mutation.removeRelations) {
|
|
32
|
-
this.removeBusinessRelation(selector);
|
|
33
|
-
}
|
|
34
|
-
for (const key of mutation.removeNodeKeys) {
|
|
35
|
-
this.removeBusinessNode(key);
|
|
36
|
-
}
|
|
37
|
-
for (const node of mutation.upsertNodes) {
|
|
38
|
-
this.upsertBusinessNode(mutation.baseSnapshotId, node);
|
|
39
|
-
}
|
|
40
|
-
this.validateBusinessHierarchy(mutation.upsertRelations);
|
|
41
|
-
for (const relation of mutation.upsertRelations) {
|
|
42
|
-
this.upsertBusinessRelation(mutation.baseSnapshotId, relation);
|
|
43
|
-
}
|
|
44
|
-
this.refreshAllBusinessValidity();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
getNode(reference, snapshotId) {
|
|
48
|
-
contentIdentifierSchema.parse(snapshotId);
|
|
49
|
-
return reference.domain === "business"
|
|
50
|
-
? this.readBusinessNode(reference.key, snapshotId)
|
|
51
|
-
: undefined;
|
|
52
|
-
}
|
|
53
|
-
getEvidence(owner) {
|
|
54
|
-
const snapshotId = this.currentSnapshotId();
|
|
55
|
-
if (owner.type === "node") {
|
|
56
|
-
const nodeId = this.findBusinessNodeId(owner.node.key);
|
|
57
|
-
return nodeId === undefined ? [] : this.readNodeEvidence(nodeId, snapshotId);
|
|
58
|
-
}
|
|
59
|
-
const relation = this.findBusinessRelation(owner.relation);
|
|
60
|
-
return relation === undefined ? [] : this.readRelationEvidence(relation.relation_id, snapshotId);
|
|
61
|
-
}
|
|
62
|
-
listBusinessRelations(snapshotId) {
|
|
63
|
-
contentIdentifierSchema.parse(snapshotId);
|
|
64
|
-
return this.readBusinessRelations(snapshotId).map((row) => this.relationFromRow(row, snapshotId));
|
|
65
|
-
}
|
|
66
|
-
listBusinessNodes(snapshotId) {
|
|
67
|
-
contentIdentifierSchema.parse(snapshotId);
|
|
68
|
-
const rows = this.database.prepare(`
|
|
69
|
-
SELECT node_key
|
|
70
|
-
FROM atlas_business_nodes
|
|
71
|
-
WHERE repository_id = ?
|
|
72
|
-
ORDER BY node_key ASC
|
|
73
|
-
`).all(this.#repositoryId);
|
|
74
|
-
return rows.map(({ node_key }) => this.readBusinessNode(node_key, snapshotId))
|
|
75
|
-
.filter((node) => node !== undefined);
|
|
76
|
-
}
|
|
77
|
-
listBusinessRoots(snapshotId) {
|
|
78
|
-
contentIdentifierSchema.parse(snapshotId);
|
|
79
|
-
const rows = this.database.prepare(`
|
|
80
|
-
SELECT node.node_key
|
|
81
|
-
FROM atlas_business_nodes AS node
|
|
82
|
-
WHERE node.repository_id = ?
|
|
83
|
-
AND NOT EXISTS (
|
|
84
|
-
SELECT 1
|
|
85
|
-
FROM atlas_business_relations AS parent
|
|
86
|
-
WHERE parent.repository_id = node.repository_id
|
|
87
|
-
AND parent.from_key = node.node_key
|
|
88
|
-
AND parent.relation_type = 'part_of'
|
|
89
|
-
AND parent.to_domain = 'business'
|
|
90
|
-
)
|
|
91
|
-
ORDER BY node.node_key ASC
|
|
92
|
-
`).all(this.#repositoryId);
|
|
93
|
-
return rows.map(({ node_key }) => this.readBusinessNode(node_key, snapshotId))
|
|
94
|
-
.filter((node) => node !== undefined);
|
|
95
|
-
}
|
|
96
|
-
traverse(start, options) {
|
|
97
|
-
const maxDepth = options.maxDepth ?? 1;
|
|
98
|
-
if (!Number.isInteger(maxDepth) || maxDepth < 1 || maxDepth > 3) {
|
|
99
|
-
throw new Error("Graph traversal depth must be an integer from 1 through 3");
|
|
100
|
-
}
|
|
101
|
-
if (start.domain === "structural" || this.getNode(start, options.snapshotId) === undefined) {
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
const direction = options.direction ?? "both";
|
|
105
|
-
const relationTypes = options.relationTypes === undefined
|
|
106
|
-
? undefined
|
|
107
|
-
: new Set(options.relationTypes);
|
|
108
|
-
const queue = [
|
|
109
|
-
{ reference: start, depth: 0 },
|
|
110
|
-
];
|
|
111
|
-
const queuedNodes = new Set([start.key]);
|
|
112
|
-
const emittedRelations = new Set();
|
|
113
|
-
const result = [];
|
|
114
|
-
for (let index = 0; index < queue.length; index += 1) {
|
|
115
|
-
const current = queue[index];
|
|
116
|
-
if (current.depth >= maxDepth) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
for (const adjacent of this.readBusinessAdjacency(current.reference, options.snapshotId, direction)) {
|
|
120
|
-
if (emittedRelations.has(adjacent.relationKey)
|
|
121
|
-
|| (relationTypes !== undefined && !relationTypes.has(adjacent.relation.type))) {
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
emittedRelations.add(adjacent.relationKey);
|
|
125
|
-
const depth = current.depth + 1;
|
|
126
|
-
result.push({
|
|
127
|
-
depth,
|
|
128
|
-
direction: adjacent.direction,
|
|
129
|
-
relation: adjacent.relation,
|
|
130
|
-
node: adjacent.node,
|
|
131
|
-
});
|
|
132
|
-
if (!queuedNodes.has(adjacent.node.key)) {
|
|
133
|
-
queuedNodes.add(adjacent.node.key);
|
|
134
|
-
queue.push({
|
|
135
|
-
reference: { domain: "business", key: adjacent.node.key },
|
|
136
|
-
depth,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return result;
|
|
142
|
-
}
|
|
143
|
-
search(query, options) {
|
|
144
|
-
contentIdentifierSchema.parse(options.snapshotId);
|
|
145
|
-
const limit = options.limit ?? 20;
|
|
146
|
-
if (!Number.isInteger(limit) || limit < 1) {
|
|
147
|
-
throw new Error("Graph search limit must be a positive integer");
|
|
148
|
-
}
|
|
149
|
-
const terms = query.toLowerCase().match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
150
|
-
if (terms.length === 0) {
|
|
151
|
-
return [];
|
|
152
|
-
}
|
|
153
|
-
const rows = this.database.prepare(`
|
|
154
|
-
SELECT node_key, label, aliases, summary, symbols, paths
|
|
155
|
-
FROM atlas_graph_search
|
|
156
|
-
WHERE repository_id = ?
|
|
157
|
-
ORDER BY node_key ASC
|
|
158
|
-
`).all(this.#repositoryId);
|
|
159
|
-
return rows.flatMap((row) => {
|
|
160
|
-
const fields = [row.label, row.aliases, row.summary, row.symbols, row.paths]
|
|
161
|
-
.map((value) => value.toLowerCase());
|
|
162
|
-
if (!terms.every((term) => fields.some((field) => field.includes(term)))) {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
const node = this.readBusinessNode(row.node_key, options.snapshotId);
|
|
166
|
-
if (node === undefined) {
|
|
167
|
-
return [];
|
|
168
|
-
}
|
|
169
|
-
return [{ score: lexicalScore(terms, fields), node }];
|
|
170
|
-
}).sort((left, right) => (right.score - left.score
|
|
171
|
-
|| businessKeyOf(left.node).localeCompare(businessKeyOf(right.node)))).slice(0, limit);
|
|
172
|
-
}
|
|
173
|
-
close() {
|
|
174
|
-
this.#atlasDatabase.close();
|
|
175
|
-
}
|
|
176
|
-
[Symbol.dispose]() {
|
|
177
|
-
this.close();
|
|
178
|
-
}
|
|
179
|
-
get database() {
|
|
180
|
-
return this.#atlasDatabase.connection;
|
|
181
|
-
}
|
|
182
|
-
transaction(operation) {
|
|
183
|
-
this.database.exec("BEGIN IMMEDIATE");
|
|
184
|
-
try {
|
|
185
|
-
operation();
|
|
186
|
-
this.database.exec("COMMIT");
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
this.database.exec("ROLLBACK");
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
validateBusinessMutation(mutation) {
|
|
194
|
-
contentIdentifierSchema.parse(mutation.baseSnapshotId);
|
|
195
|
-
const upsertedKeys = new Set();
|
|
196
|
-
for (const node of mutation.upsertNodes) {
|
|
197
|
-
businessKeySchema.parse(node.key);
|
|
198
|
-
businessNodeKindSchema.parse(node.kind);
|
|
199
|
-
assertionCertaintySchema.parse(node.certainty);
|
|
200
|
-
if (node.label.length === 0 || node.summary.length === 0 || node.evidence.length === 0) {
|
|
201
|
-
throw new Error(`Business node ${node.key} requires a label, summary, and evidence`);
|
|
202
|
-
}
|
|
203
|
-
node.aliases.forEach((alias) => {
|
|
204
|
-
if (alias.length === 0) {
|
|
205
|
-
throw new Error(`Business node ${node.key} has an empty alias`);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
node.evidence.forEach((evidence) => evidenceSchema.parse(publicEvidence(evidence)));
|
|
209
|
-
if (upsertedKeys.has(node.key)) {
|
|
210
|
-
throw new Error(`Duplicate business node upsert ${node.key}`);
|
|
211
|
-
}
|
|
212
|
-
upsertedKeys.add(node.key);
|
|
213
|
-
}
|
|
214
|
-
const removedKeys = new Set(mutation.removeNodeKeys);
|
|
215
|
-
mutation.removeNodeKeys.forEach((key) => businessKeySchema.parse(key));
|
|
216
|
-
for (const key of upsertedKeys) {
|
|
217
|
-
if (removedKeys.has(key)) {
|
|
218
|
-
throw new Error(`Business node ${key} cannot be removed and upserted together`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
mutation.removeRelations.forEach((relation) => this.validateBusinessRelation(relation));
|
|
222
|
-
mutation.upsertRelations.forEach((relation) => {
|
|
223
|
-
this.validateBusinessRelation(relation);
|
|
224
|
-
assertionCertaintySchema.parse(relation.certainty);
|
|
225
|
-
if (relation.evidence.length === 0) {
|
|
226
|
-
throw new Error("Business relations require evidence");
|
|
227
|
-
}
|
|
228
|
-
relation.evidence.forEach((evidence) => evidenceSchema.parse(publicEvidence(evidence)));
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
validateBusinessRelation(relation) {
|
|
232
|
-
businessKeySchema.parse(relation.from.key);
|
|
233
|
-
businessRelationTypeSchema.parse(relation.type);
|
|
234
|
-
if (relation.to.domain === "business") {
|
|
235
|
-
businessKeySchema.parse(relation.to.key);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
structuralNodeIdSchema.parse(relation.to.id);
|
|
239
|
-
}
|
|
240
|
-
const requiresStructuralTarget = relation.type === "realized_by" || relation.type === "verified_by";
|
|
241
|
-
const expectedDomain = requiresStructuralTarget ? "structural" : "business";
|
|
242
|
-
if (relation.to.domain !== expectedDomain) {
|
|
243
|
-
throw new Error(`${relation.type} relations require a ${expectedDomain} target`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
validateBusinessHierarchy(upsertRelations) {
|
|
247
|
-
const storedParents = this.database.prepare(`
|
|
248
|
-
SELECT from_key, to_key
|
|
249
|
-
FROM atlas_business_relations
|
|
250
|
-
WHERE repository_id = ?
|
|
251
|
-
AND relation_type = 'part_of'
|
|
252
|
-
AND to_domain = 'business'
|
|
253
|
-
ORDER BY from_key, to_key
|
|
254
|
-
`).all(this.#repositoryId);
|
|
255
|
-
const parents = new Map();
|
|
256
|
-
const registerParent = (child, parent) => {
|
|
257
|
-
const existingParent = parents.get(child);
|
|
258
|
-
if (existingParent !== undefined && existingParent !== parent) {
|
|
259
|
-
throw new Error(`Business node ${child} may have only one outgoing part_of parent`);
|
|
260
|
-
}
|
|
261
|
-
parents.set(child, parent);
|
|
262
|
-
};
|
|
263
|
-
storedParents.forEach(({ from_key, to_key }) => registerParent(from_key, to_key));
|
|
264
|
-
upsertRelations.forEach((relation) => {
|
|
265
|
-
if (relation.type === "part_of" && relation.to.domain === "business") {
|
|
266
|
-
registerParent(relation.from.key, relation.to.key);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
for (const child of parents.keys()) {
|
|
270
|
-
const path = new Set();
|
|
271
|
-
let current = child;
|
|
272
|
-
while (current !== undefined) {
|
|
273
|
-
if (path.has(current)) {
|
|
274
|
-
throw new Error(`Business part_of hierarchy contains a cycle involving ${current}`);
|
|
275
|
-
}
|
|
276
|
-
path.add(current);
|
|
277
|
-
current = parents.get(current);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
validateLocation(location) {
|
|
282
|
-
relativeSourcePathSchema.parse(location.file);
|
|
283
|
-
sourceRangeSchema.parse(location.range);
|
|
284
|
-
contentIdentifierSchema.parse(location.contentHash);
|
|
285
|
-
}
|
|
286
|
-
requireSnapshot(snapshotId) {
|
|
287
|
-
const row = this.database.prepare(`
|
|
288
|
-
SELECT payload
|
|
289
|
-
FROM atlas_repository_snapshots
|
|
290
|
-
WHERE repository_id = ? AND snapshot_id = ?
|
|
291
|
-
`).get(this.#repositoryId, snapshotId);
|
|
292
|
-
if (row === undefined) {
|
|
293
|
-
throw new Error(`Repository snapshot ${snapshotId} is not stored`);
|
|
294
|
-
}
|
|
295
|
-
return JSON.parse(row.payload);
|
|
296
|
-
}
|
|
297
|
-
upsertBusinessNode(baseSnapshotId, node) {
|
|
298
|
-
const snapshot = this.requireSnapshot(baseSnapshotId);
|
|
299
|
-
node.evidence.forEach((evidence) => this.requireEvidence(snapshot, evidence));
|
|
300
|
-
this.database.prepare(`
|
|
301
|
-
INSERT INTO atlas_business_nodes (
|
|
302
|
-
repository_id,
|
|
303
|
-
node_key,
|
|
304
|
-
base_snapshot_id,
|
|
305
|
-
kind,
|
|
306
|
-
label,
|
|
307
|
-
summary,
|
|
308
|
-
certainty
|
|
309
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
310
|
-
ON CONFLICT (repository_id, node_key) DO UPDATE SET
|
|
311
|
-
base_snapshot_id = excluded.base_snapshot_id,
|
|
312
|
-
kind = excluded.kind,
|
|
313
|
-
label = excluded.label,
|
|
314
|
-
summary = excluded.summary,
|
|
315
|
-
certainty = excluded.certainty
|
|
316
|
-
`).run(this.#repositoryId, node.key, baseSnapshotId, node.kind, node.label, node.summary, node.certainty);
|
|
317
|
-
const nodeId = this.requireBusinessNodeId(node.key);
|
|
318
|
-
this.database.prepare("DELETE FROM atlas_business_node_aliases WHERE node_id = ?").run(nodeId);
|
|
319
|
-
this.database.prepare("DELETE FROM atlas_business_node_evidence WHERE node_id = ?").run(nodeId);
|
|
320
|
-
node.aliases.forEach((alias, position) => {
|
|
321
|
-
this.database.prepare(`
|
|
322
|
-
INSERT INTO atlas_business_node_aliases (node_id, position, alias)
|
|
323
|
-
VALUES (?, ?, ?)
|
|
324
|
-
`).run(nodeId, position, alias);
|
|
325
|
-
});
|
|
326
|
-
node.evidence.forEach((evidence, position) => {
|
|
327
|
-
this.insertNodeEvidence(nodeId, position, evidence, baseSnapshotId);
|
|
328
|
-
});
|
|
329
|
-
this.database.prepare(`
|
|
330
|
-
INSERT INTO atlas_graph_search (
|
|
331
|
-
repository_id,
|
|
332
|
-
node_key,
|
|
333
|
-
label,
|
|
334
|
-
aliases,
|
|
335
|
-
summary,
|
|
336
|
-
symbols,
|
|
337
|
-
paths
|
|
338
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
339
|
-
ON CONFLICT (repository_id, node_key) DO UPDATE SET
|
|
340
|
-
label = excluded.label,
|
|
341
|
-
aliases = excluded.aliases,
|
|
342
|
-
summary = excluded.summary,
|
|
343
|
-
symbols = excluded.symbols,
|
|
344
|
-
paths = excluded.paths
|
|
345
|
-
`).run(this.#repositoryId, node.key, node.label, node.aliases.join(" "), node.summary, node.evidence.map((evidence) => evidence.symbolId).join(" "), node.evidence.map((evidence) => evidence.file).join(" "));
|
|
346
|
-
}
|
|
347
|
-
upsertBusinessRelation(baseSnapshotId, relation) {
|
|
348
|
-
const snapshot = this.requireSnapshot(baseSnapshotId);
|
|
349
|
-
relation.evidence.forEach((evidence) => this.requireEvidence(snapshot, evidence));
|
|
350
|
-
this.requireBusinessNodeId(relation.from.key);
|
|
351
|
-
if (relation.to.domain === "business") {
|
|
352
|
-
this.requireBusinessNodeId(relation.to.key);
|
|
353
|
-
}
|
|
354
|
-
const targetKey = relation.to.domain === "business" ? relation.to.key : relation.to.id;
|
|
355
|
-
const target = relation.to.domain === "structural"
|
|
356
|
-
? readStructuralTargetBinding(relation) ?? inferredStructuralTarget(relation, baseSnapshotId)
|
|
357
|
-
: undefined;
|
|
358
|
-
const relationId = this.storeBusinessRelation(baseSnapshotId, relation, targetKey, target);
|
|
359
|
-
this.database.prepare(`
|
|
360
|
-
DELETE FROM atlas_business_relation_evidence
|
|
361
|
-
WHERE relation_id = ?
|
|
362
|
-
`).run(relationId);
|
|
363
|
-
relation.evidence.forEach((evidence, position) => {
|
|
364
|
-
this.insertRelationEvidence(relationId, position, evidence, baseSnapshotId);
|
|
365
|
-
});
|
|
366
|
-
if (relation.to.domain === "structural") {
|
|
367
|
-
this.insertStructuralTargetBinding(relationId, baseSnapshotId, target);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
storeBusinessRelation(baseSnapshotId, relation, targetKey, target) {
|
|
371
|
-
const existing = this.findBusinessRelation(relation);
|
|
372
|
-
if (existing === undefined) {
|
|
373
|
-
const result = this.database.prepare(`
|
|
374
|
-
INSERT INTO atlas_business_relations (
|
|
375
|
-
repository_id,
|
|
376
|
-
base_snapshot_id,
|
|
377
|
-
from_key,
|
|
378
|
-
relation_type,
|
|
379
|
-
to_domain,
|
|
380
|
-
to_key,
|
|
381
|
-
certainty,
|
|
382
|
-
target_file,
|
|
383
|
-
target_qualified_symbol,
|
|
384
|
-
target_structural_kind,
|
|
385
|
-
target_start_line,
|
|
386
|
-
target_start_column,
|
|
387
|
-
target_end_line,
|
|
388
|
-
target_end_column,
|
|
389
|
-
target_backend_locator
|
|
390
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
391
|
-
`).run(this.#repositoryId, baseSnapshotId, relation.from.key, relation.type, relation.to.domain, targetKey, relation.certainty, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.backendLocator ?? null);
|
|
392
|
-
return Number(result.lastInsertRowid);
|
|
393
|
-
}
|
|
394
|
-
this.database.prepare(`
|
|
395
|
-
UPDATE atlas_business_relations
|
|
396
|
-
SET
|
|
397
|
-
base_snapshot_id = ?,
|
|
398
|
-
to_key = ?,
|
|
399
|
-
certainty = ?,
|
|
400
|
-
target_file = ?,
|
|
401
|
-
target_qualified_symbol = ?,
|
|
402
|
-
target_structural_kind = ?,
|
|
403
|
-
target_start_line = ?,
|
|
404
|
-
target_start_column = ?,
|
|
405
|
-
target_end_line = ?,
|
|
406
|
-
target_end_column = ?,
|
|
407
|
-
target_backend_locator = ?
|
|
408
|
-
WHERE relation_id = ?
|
|
409
|
-
`).run(baseSnapshotId, targetKey, relation.certainty, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.backendLocator ?? null, existing.relation_id);
|
|
410
|
-
return existing.relation_id;
|
|
411
|
-
}
|
|
412
|
-
removeBusinessNode(key) {
|
|
413
|
-
this.requireBusinessNodeId(key);
|
|
414
|
-
const relation = this.database.prepare(`
|
|
415
|
-
SELECT relation_id
|
|
416
|
-
FROM atlas_business_relations
|
|
417
|
-
WHERE repository_id = ?
|
|
418
|
-
AND (from_key = ? OR (to_domain = 'business' AND to_key = ?))
|
|
419
|
-
LIMIT 1
|
|
420
|
-
`).get(this.#repositoryId, key, key);
|
|
421
|
-
if (relation !== undefined) {
|
|
422
|
-
throw new Error(`Business node ${key} is still referenced by a relation`);
|
|
423
|
-
}
|
|
424
|
-
this.database.prepare(`
|
|
425
|
-
DELETE FROM atlas_business_nodes
|
|
426
|
-
WHERE repository_id = ? AND node_key = ?
|
|
427
|
-
`).run(this.#repositoryId, key);
|
|
428
|
-
}
|
|
429
|
-
removeBusinessRelation(selector) {
|
|
430
|
-
this.requireBusinessNodeId(selector.from.key);
|
|
431
|
-
if (selector.to.domain === "business") {
|
|
432
|
-
this.requireBusinessNodeId(selector.to.key);
|
|
433
|
-
}
|
|
434
|
-
const relation = this.findBusinessRelation(selector);
|
|
435
|
-
if (relation !== undefined) {
|
|
436
|
-
this.database.prepare("DELETE FROM atlas_business_relations WHERE relation_id = ?")
|
|
437
|
-
.run(relation.relation_id);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
insertNodeEvidence(nodeId, position, evidence, snapshotId) {
|
|
441
|
-
this.database.prepare(`
|
|
442
|
-
INSERT INTO atlas_business_node_evidence (
|
|
443
|
-
node_id,
|
|
444
|
-
position,
|
|
445
|
-
structural_reference,
|
|
446
|
-
file,
|
|
447
|
-
start_line,
|
|
448
|
-
start_column,
|
|
449
|
-
end_line,
|
|
450
|
-
end_column,
|
|
451
|
-
content_hash,
|
|
452
|
-
qualified_symbol,
|
|
453
|
-
structural_kind,
|
|
454
|
-
backend_locator
|
|
455
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
456
|
-
`).run(nodeId, position, evidence.symbolId, evidence.file, evidence.range.start.line, evidence.range.start.column, evidence.range.end.line, evidence.range.end.column, evidence.contentHash, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.backendLocator ?? null);
|
|
457
|
-
this.insertEvidenceBinding("atlas_business_node_evidence_bindings", "node_id", nodeId, position, snapshotId, evidence);
|
|
458
|
-
}
|
|
459
|
-
insertRelationEvidence(relationId, position, evidence, snapshotId) {
|
|
460
|
-
this.database.prepare(`
|
|
461
|
-
INSERT INTO atlas_business_relation_evidence (
|
|
462
|
-
relation_id,
|
|
463
|
-
position,
|
|
464
|
-
structural_reference,
|
|
465
|
-
file,
|
|
466
|
-
start_line,
|
|
467
|
-
start_column,
|
|
468
|
-
end_line,
|
|
469
|
-
end_column,
|
|
470
|
-
content_hash,
|
|
471
|
-
qualified_symbol,
|
|
472
|
-
structural_kind,
|
|
473
|
-
backend_locator
|
|
474
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
475
|
-
`).run(relationId, position, evidence.symbolId, evidence.file, evidence.range.start.line, evidence.range.start.column, evidence.range.end.line, evidence.range.end.column, evidence.contentHash, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.backendLocator ?? null);
|
|
476
|
-
this.insertEvidenceBinding("atlas_business_relation_evidence_bindings", "relation_id", relationId, position, snapshotId, evidence);
|
|
477
|
-
}
|
|
478
|
-
insertEvidenceBinding(table, ownerColumn, ownerId, position, snapshotId, evidence) {
|
|
479
|
-
this.database.prepare(`
|
|
480
|
-
INSERT INTO ${table} (
|
|
481
|
-
${ownerColumn},
|
|
482
|
-
position,
|
|
483
|
-
repository_id,
|
|
484
|
-
snapshot_id,
|
|
485
|
-
resolved_structural_reference,
|
|
486
|
-
resolved_qualified_symbol,
|
|
487
|
-
resolved_structural_kind,
|
|
488
|
-
backend_version,
|
|
489
|
-
backend_locator,
|
|
490
|
-
binding_status
|
|
491
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'bound')
|
|
492
|
-
`).run(ownerId, position, this.#repositoryId, snapshotId, evidence.symbolId, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.backendVersion ?? null, evidence.backendLocator ?? null);
|
|
493
|
-
}
|
|
494
|
-
insertStructuralTargetBinding(relationId, snapshotId, target) {
|
|
495
|
-
this.database.prepare(`
|
|
496
|
-
INSERT INTO atlas_structural_relation_target_bindings (
|
|
497
|
-
relation_id,
|
|
498
|
-
repository_id,
|
|
499
|
-
snapshot_id,
|
|
500
|
-
resolved_structural_reference,
|
|
501
|
-
resolved_file,
|
|
502
|
-
resolved_qualified_symbol,
|
|
503
|
-
resolved_structural_kind,
|
|
504
|
-
resolved_start_line,
|
|
505
|
-
resolved_start_column,
|
|
506
|
-
resolved_end_line,
|
|
507
|
-
resolved_end_column,
|
|
508
|
-
backend_version,
|
|
509
|
-
backend_locator,
|
|
510
|
-
binding_status
|
|
511
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
512
|
-
ON CONFLICT (relation_id, snapshot_id) DO UPDATE SET
|
|
513
|
-
resolved_structural_reference = excluded.resolved_structural_reference,
|
|
514
|
-
resolved_file = excluded.resolved_file,
|
|
515
|
-
resolved_qualified_symbol = excluded.resolved_qualified_symbol,
|
|
516
|
-
resolved_structural_kind = excluded.resolved_structural_kind,
|
|
517
|
-
resolved_start_line = excluded.resolved_start_line,
|
|
518
|
-
resolved_start_column = excluded.resolved_start_column,
|
|
519
|
-
resolved_end_line = excluded.resolved_end_line,
|
|
520
|
-
resolved_end_column = excluded.resolved_end_column,
|
|
521
|
-
backend_version = excluded.backend_version,
|
|
522
|
-
backend_locator = excluded.backend_locator,
|
|
523
|
-
binding_status = excluded.binding_status
|
|
524
|
-
`).run(relationId, this.#repositoryId, snapshotId, target?.structuralReference ?? null, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.backendVersion ?? null, target?.backendLocator ?? null, target === undefined ? "unresolved" : "bound");
|
|
525
|
-
}
|
|
526
|
-
requireEvidence(snapshot, evidence) {
|
|
527
|
-
this.validateLocation(evidence);
|
|
528
|
-
if (!evidenceMatchesSnapshot(evidence, snapshot)) {
|
|
529
|
-
throw new Error(`Evidence ${evidence.symbolId} at ${evidence.file} does not match snapshot ${snapshot.snapshotId}`);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
currentSnapshotId() {
|
|
533
|
-
const row = this.database.prepare(`
|
|
534
|
-
SELECT current_snapshot_id
|
|
535
|
-
FROM atlas_worktree_states
|
|
536
|
-
WHERE repository_id = ? AND git_directory = ?
|
|
537
|
-
`).get(this.#repositoryId, this.#gitDirectory);
|
|
538
|
-
if (row.current_snapshot_id === null) {
|
|
539
|
-
throw new Error("The current worktree has no published Atlas snapshot");
|
|
540
|
-
}
|
|
541
|
-
return row.current_snapshot_id;
|
|
542
|
-
}
|
|
543
|
-
refreshAllBusinessValidity() {
|
|
544
|
-
const snapshots = this.database.prepare(`
|
|
545
|
-
SELECT payload
|
|
546
|
-
FROM atlas_repository_snapshots
|
|
547
|
-
WHERE repository_id = ?
|
|
548
|
-
ORDER BY snapshot_id ASC
|
|
549
|
-
`).all(this.#repositoryId);
|
|
550
|
-
for (const { payload } of snapshots) {
|
|
551
|
-
this.refreshBusinessValidity(JSON.parse(payload));
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
reconcileEvidenceBindings(snapshot) {
|
|
555
|
-
this.reconcileEvidenceBindingTable("atlas_business_node_evidence", "atlas_business_node_evidence_bindings", "node_id", snapshot);
|
|
556
|
-
this.reconcileEvidenceBindingTable("atlas_business_relation_evidence", "atlas_business_relation_evidence_bindings", "relation_id", snapshot);
|
|
557
|
-
}
|
|
558
|
-
reconcileEvidenceBindingTable(evidenceTable, bindingTable, ownerColumn, snapshot) {
|
|
559
|
-
const contentHashes = new Map(snapshot.files.flatMap((file) => (file.worktree === null ? [] : [[file.path, file.worktree.contentHash]])));
|
|
560
|
-
const evidenceRows = this.database.prepare(`
|
|
561
|
-
SELECT ${ownerColumn} AS owner_id, position, file, content_hash
|
|
562
|
-
FROM ${evidenceTable}
|
|
563
|
-
ORDER BY ${ownerColumn}, position
|
|
564
|
-
`).all();
|
|
565
|
-
for (const evidence of evidenceRows) {
|
|
566
|
-
if (contentHashes.get(evidence.file) !== evidence.content_hash) {
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
this.database.prepare(`
|
|
570
|
-
INSERT INTO ${bindingTable} (
|
|
571
|
-
${ownerColumn},
|
|
572
|
-
position,
|
|
573
|
-
repository_id,
|
|
574
|
-
snapshot_id,
|
|
575
|
-
resolved_structural_reference,
|
|
576
|
-
resolved_qualified_symbol,
|
|
577
|
-
resolved_structural_kind,
|
|
578
|
-
backend_version,
|
|
579
|
-
backend_locator,
|
|
580
|
-
binding_status
|
|
581
|
-
)
|
|
582
|
-
SELECT
|
|
583
|
-
${ownerColumn},
|
|
584
|
-
position,
|
|
585
|
-
repository_id,
|
|
586
|
-
?,
|
|
587
|
-
resolved_structural_reference,
|
|
588
|
-
resolved_qualified_symbol,
|
|
589
|
-
resolved_structural_kind,
|
|
590
|
-
backend_version,
|
|
591
|
-
backend_locator,
|
|
592
|
-
'bound'
|
|
593
|
-
FROM ${bindingTable}
|
|
594
|
-
WHERE ${ownerColumn} = ?
|
|
595
|
-
AND position = ?
|
|
596
|
-
AND binding_status = 'bound'
|
|
597
|
-
ORDER BY rowid DESC
|
|
598
|
-
LIMIT 1
|
|
599
|
-
ON CONFLICT (${ownerColumn}, position, snapshot_id) DO NOTHING
|
|
600
|
-
`).run(snapshot.snapshotId, evidence.owner_id, evidence.position);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
refreshBusinessValidity(snapshot) {
|
|
604
|
-
const nodeRows = this.database.prepare(`
|
|
605
|
-
SELECT node_id
|
|
606
|
-
FROM atlas_business_nodes
|
|
607
|
-
WHERE repository_id = ?
|
|
608
|
-
`).all(this.#repositoryId);
|
|
609
|
-
for (const { node_id } of nodeRows) {
|
|
610
|
-
const validity = allEvidenceMatches(this.readNodeEvidenceRows(node_id, snapshot.snapshotId), snapshot)
|
|
611
|
-
? "valid"
|
|
612
|
-
: "stale";
|
|
613
|
-
this.database.prepare(`
|
|
614
|
-
INSERT INTO atlas_business_node_validity (
|
|
615
|
-
node_id,
|
|
616
|
-
repository_id,
|
|
617
|
-
snapshot_id,
|
|
618
|
-
validity
|
|
619
|
-
) VALUES (?, ?, ?, ?)
|
|
620
|
-
ON CONFLICT (node_id, snapshot_id) DO UPDATE SET
|
|
621
|
-
validity = excluded.validity
|
|
622
|
-
`).run(node_id, this.#repositoryId, snapshot.snapshotId, validity);
|
|
623
|
-
}
|
|
624
|
-
const relationRows = this.database.prepare(`
|
|
625
|
-
SELECT
|
|
626
|
-
relation.relation_id,
|
|
627
|
-
relation.to_domain,
|
|
628
|
-
target.binding_status AS target_binding_status
|
|
629
|
-
FROM atlas_business_relations AS relation
|
|
630
|
-
LEFT JOIN atlas_structural_relation_target_bindings AS target
|
|
631
|
-
ON target.relation_id = relation.relation_id
|
|
632
|
-
AND target.snapshot_id = ?
|
|
633
|
-
WHERE relation.repository_id = ?
|
|
634
|
-
`).all(snapshot.snapshotId, this.#repositoryId);
|
|
635
|
-
for (const relation of relationRows) {
|
|
636
|
-
const targetIsBound = relation.to_domain === "business"
|
|
637
|
-
|| relation.target_binding_status === "bound";
|
|
638
|
-
const validity = targetIsBound
|
|
639
|
-
&& allEvidenceMatches(this.readRelationEvidenceRows(relation.relation_id, snapshot.snapshotId), snapshot)
|
|
640
|
-
? "valid"
|
|
641
|
-
: "stale";
|
|
642
|
-
this.database.prepare(`
|
|
643
|
-
INSERT INTO atlas_business_relation_validity (
|
|
644
|
-
relation_id,
|
|
645
|
-
repository_id,
|
|
646
|
-
snapshot_id,
|
|
647
|
-
validity
|
|
648
|
-
) VALUES (?, ?, ?, ?)
|
|
649
|
-
ON CONFLICT (relation_id, snapshot_id) DO UPDATE SET
|
|
650
|
-
validity = excluded.validity
|
|
651
|
-
`).run(relation.relation_id, this.#repositoryId, snapshot.snapshotId, validity);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
readBusinessNode(key, snapshotId) {
|
|
655
|
-
const row = this.database.prepare(`
|
|
656
|
-
SELECT
|
|
657
|
-
node.node_id,
|
|
658
|
-
node.base_snapshot_id,
|
|
659
|
-
node.kind,
|
|
660
|
-
node.label,
|
|
661
|
-
node.summary,
|
|
662
|
-
node.certainty,
|
|
663
|
-
COALESCE(validity.validity, 'stale') AS validity
|
|
664
|
-
FROM atlas_business_nodes AS node
|
|
665
|
-
LEFT JOIN atlas_business_node_validity AS validity
|
|
666
|
-
ON validity.node_id = node.node_id
|
|
667
|
-
AND validity.snapshot_id = ?
|
|
668
|
-
WHERE node.repository_id = ? AND node.node_key = ?
|
|
669
|
-
`).get(snapshotId, this.#repositoryId, key);
|
|
670
|
-
if (row === undefined) {
|
|
671
|
-
return undefined;
|
|
672
|
-
}
|
|
673
|
-
const aliases = this.database.prepare(`
|
|
674
|
-
SELECT alias
|
|
675
|
-
FROM atlas_business_node_aliases
|
|
676
|
-
WHERE node_id = ?
|
|
677
|
-
ORDER BY position ASC
|
|
678
|
-
`).all(row.node_id);
|
|
679
|
-
return {
|
|
680
|
-
domain: "business",
|
|
681
|
-
key,
|
|
682
|
-
kind: row.kind,
|
|
683
|
-
label: row.label,
|
|
684
|
-
summary: row.summary,
|
|
685
|
-
aliases: aliases.map(({ alias }) => alias),
|
|
686
|
-
certainty: row.certainty,
|
|
687
|
-
validity: row.validity,
|
|
688
|
-
evidence: this.readNodeEvidence(row.node_id, snapshotId),
|
|
689
|
-
baseSnapshotId: row.base_snapshot_id,
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
readNodeEvidence(nodeId, snapshotId) {
|
|
693
|
-
return this.readNodeEvidenceRows(nodeId, snapshotId).map(evidenceFromRow);
|
|
694
|
-
}
|
|
695
|
-
readNodeEvidenceRows(nodeId, snapshotId) {
|
|
696
|
-
return this.database.prepare(`
|
|
697
|
-
SELECT
|
|
698
|
-
COALESCE(binding.resolved_structural_reference, evidence.structural_reference)
|
|
699
|
-
AS structural_reference,
|
|
700
|
-
evidence.file,
|
|
701
|
-
evidence.start_line,
|
|
702
|
-
evidence.start_column,
|
|
703
|
-
evidence.end_line,
|
|
704
|
-
evidence.end_column,
|
|
705
|
-
evidence.content_hash,
|
|
706
|
-
COALESCE(binding.resolved_qualified_symbol, evidence.qualified_symbol) AS qualified_symbol,
|
|
707
|
-
COALESCE(binding.resolved_structural_kind, evidence.structural_kind) AS structural_kind,
|
|
708
|
-
binding.snapshot_id AS atlas_snapshot_id,
|
|
709
|
-
binding.backend_version,
|
|
710
|
-
COALESCE(binding.backend_locator, evidence.backend_locator) AS backend_locator,
|
|
711
|
-
COALESCE(binding.binding_status, 'unresolved') AS binding_status
|
|
712
|
-
FROM atlas_business_node_evidence AS evidence
|
|
713
|
-
LEFT JOIN atlas_business_node_evidence_bindings AS binding
|
|
714
|
-
ON binding.node_id = evidence.node_id
|
|
715
|
-
AND binding.position = evidence.position
|
|
716
|
-
AND binding.snapshot_id = ?
|
|
717
|
-
WHERE evidence.node_id = ?
|
|
718
|
-
ORDER BY evidence.position ASC
|
|
719
|
-
`).all(snapshotId, nodeId);
|
|
720
|
-
}
|
|
721
|
-
readRelationEvidence(relationId, snapshotId) {
|
|
722
|
-
return this.readRelationEvidenceRows(relationId, snapshotId).map(evidenceFromRow);
|
|
723
|
-
}
|
|
724
|
-
readRelationEvidenceRows(relationId, snapshotId) {
|
|
725
|
-
return this.database.prepare(`
|
|
726
|
-
SELECT
|
|
727
|
-
COALESCE(binding.resolved_structural_reference, evidence.structural_reference)
|
|
728
|
-
AS structural_reference,
|
|
729
|
-
evidence.file,
|
|
730
|
-
evidence.start_line,
|
|
731
|
-
evidence.start_column,
|
|
732
|
-
evidence.end_line,
|
|
733
|
-
evidence.end_column,
|
|
734
|
-
evidence.content_hash,
|
|
735
|
-
COALESCE(binding.resolved_qualified_symbol, evidence.qualified_symbol) AS qualified_symbol,
|
|
736
|
-
COALESCE(binding.resolved_structural_kind, evidence.structural_kind) AS structural_kind,
|
|
737
|
-
binding.snapshot_id AS atlas_snapshot_id,
|
|
738
|
-
binding.backend_version,
|
|
739
|
-
COALESCE(binding.backend_locator, evidence.backend_locator) AS backend_locator,
|
|
740
|
-
COALESCE(binding.binding_status, 'unresolved') AS binding_status
|
|
741
|
-
FROM atlas_business_relation_evidence AS evidence
|
|
742
|
-
LEFT JOIN atlas_business_relation_evidence_bindings AS binding
|
|
743
|
-
ON binding.relation_id = evidence.relation_id
|
|
744
|
-
AND binding.position = evidence.position
|
|
745
|
-
AND binding.snapshot_id = ?
|
|
746
|
-
WHERE evidence.relation_id = ?
|
|
747
|
-
ORDER BY evidence.position ASC
|
|
748
|
-
`).all(snapshotId, relationId);
|
|
749
|
-
}
|
|
750
|
-
readBusinessRelations(snapshotId) {
|
|
751
|
-
return this.database.prepare(`
|
|
752
|
-
SELECT
|
|
753
|
-
relation.relation_id,
|
|
754
|
-
relation.base_snapshot_id,
|
|
755
|
-
relation.from_key,
|
|
756
|
-
relation.relation_type,
|
|
757
|
-
relation.to_domain,
|
|
758
|
-
CASE
|
|
759
|
-
WHEN relation.to_domain = 'structural'
|
|
760
|
-
THEN COALESCE(target.resolved_structural_reference, relation.to_key)
|
|
761
|
-
ELSE relation.to_key
|
|
762
|
-
END AS to_key,
|
|
763
|
-
relation.certainty,
|
|
764
|
-
COALESCE(validity.validity, 'stale') AS validity
|
|
765
|
-
FROM atlas_business_relations AS relation
|
|
766
|
-
LEFT JOIN atlas_business_relation_validity AS validity
|
|
767
|
-
ON validity.relation_id = relation.relation_id
|
|
768
|
-
AND validity.snapshot_id = ?
|
|
769
|
-
LEFT JOIN atlas_structural_relation_target_bindings AS target
|
|
770
|
-
ON target.relation_id = relation.relation_id
|
|
771
|
-
AND target.snapshot_id = ?
|
|
772
|
-
WHERE relation.repository_id = ?
|
|
773
|
-
ORDER BY relation.from_key, relation.relation_type, relation.to_domain, relation.to_key
|
|
774
|
-
`).all(snapshotId, snapshotId, this.#repositoryId);
|
|
775
|
-
}
|
|
776
|
-
relationFromRow(row, snapshotId) {
|
|
777
|
-
return {
|
|
778
|
-
domain: "business",
|
|
779
|
-
from: { domain: "business", key: row.from_key },
|
|
780
|
-
type: row.relation_type,
|
|
781
|
-
to: row.to_domain === "business"
|
|
782
|
-
? { domain: "business", key: row.to_key }
|
|
783
|
-
: { domain: "structural", id: row.to_key },
|
|
784
|
-
baseSnapshotId: row.base_snapshot_id,
|
|
785
|
-
certainty: row.certainty,
|
|
786
|
-
validity: row.validity,
|
|
787
|
-
evidence: this.readRelationEvidence(row.relation_id, snapshotId),
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
readBusinessAdjacency(reference, snapshotId, direction) {
|
|
791
|
-
const directions = direction === "both" ? ["outgoing", "incoming"] : [direction];
|
|
792
|
-
const adjacency = [];
|
|
793
|
-
for (const currentDirection of directions) {
|
|
794
|
-
for (const row of this.readBusinessRelations(snapshotId)) {
|
|
795
|
-
const isAdjacent = currentDirection === "outgoing"
|
|
796
|
-
? row.from_key === reference.key && row.to_domain === "business"
|
|
797
|
-
: row.to_domain === "business" && row.to_key === reference.key;
|
|
798
|
-
if (!isAdjacent) {
|
|
799
|
-
continue;
|
|
800
|
-
}
|
|
801
|
-
const otherKey = currentDirection === "outgoing" ? row.to_key : row.from_key;
|
|
802
|
-
const node = this.readBusinessNode(otherKey, snapshotId);
|
|
803
|
-
if (node === undefined) {
|
|
804
|
-
continue;
|
|
805
|
-
}
|
|
806
|
-
adjacency.push({
|
|
807
|
-
relationKey: `business:${row.relation_id}`,
|
|
808
|
-
direction: currentDirection,
|
|
809
|
-
relation: this.relationFromRow(row, snapshotId),
|
|
810
|
-
node,
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
return adjacency.sort((left, right) => (left.relation.type.localeCompare(right.relation.type)
|
|
815
|
-
|| left.node.key.localeCompare(right.node.key)));
|
|
816
|
-
}
|
|
817
|
-
findBusinessRelation(selector) {
|
|
818
|
-
const targetKey = selector.to.domain === "business" ? selector.to.key : selector.to.id;
|
|
819
|
-
return this.database.prepare(`
|
|
820
|
-
SELECT relation_id
|
|
821
|
-
FROM atlas_business_relations
|
|
822
|
-
WHERE repository_id = ?
|
|
823
|
-
AND from_key = ?
|
|
824
|
-
AND relation_type = ?
|
|
825
|
-
AND to_domain = ?
|
|
826
|
-
AND (
|
|
827
|
-
to_key = ?
|
|
828
|
-
OR (
|
|
829
|
-
to_domain = 'structural'
|
|
830
|
-
AND EXISTS (
|
|
831
|
-
SELECT 1
|
|
832
|
-
FROM atlas_structural_relation_target_bindings AS binding
|
|
833
|
-
WHERE binding.relation_id = atlas_business_relations.relation_id
|
|
834
|
-
AND binding.resolved_structural_reference = ?
|
|
835
|
-
)
|
|
836
|
-
)
|
|
837
|
-
)
|
|
838
|
-
`).get(this.#repositoryId, selector.from.key, selector.type, selector.to.domain, targetKey, targetKey);
|
|
839
|
-
}
|
|
840
|
-
findBusinessNodeId(key) {
|
|
841
|
-
const row = this.database.prepare(`
|
|
842
|
-
SELECT node_id
|
|
843
|
-
FROM atlas_business_nodes
|
|
844
|
-
WHERE repository_id = ? AND node_key = ?
|
|
845
|
-
`).get(this.#repositoryId, key);
|
|
846
|
-
return row?.node_id;
|
|
847
|
-
}
|
|
848
|
-
requireBusinessNodeId(key) {
|
|
849
|
-
const nodeId = this.findBusinessNodeId(key);
|
|
850
|
-
if (nodeId === undefined) {
|
|
851
|
-
throw new Error(`Business relation endpoint ${key} is missing`);
|
|
852
|
-
}
|
|
853
|
-
return nodeId;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
function evidenceFromRow(row) {
|
|
857
|
-
return {
|
|
858
|
-
symbolId: row.structural_reference,
|
|
859
|
-
file: row.file,
|
|
860
|
-
range: {
|
|
861
|
-
start: { line: row.start_line, column: row.start_column },
|
|
862
|
-
end: { line: row.end_line, column: row.end_column },
|
|
863
|
-
},
|
|
864
|
-
contentHash: row.content_hash,
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
function publicEvidence(evidence) {
|
|
868
|
-
return {
|
|
869
|
-
symbolId: evidence.symbolId,
|
|
870
|
-
file: evidence.file,
|
|
871
|
-
range: evidence.range,
|
|
872
|
-
contentHash: evidence.contentHash,
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
function evidenceMatchesSnapshot(evidence, snapshot) {
|
|
876
|
-
return snapshot.files.some((file) => (file.path === evidence.file
|
|
877
|
-
&& file.worktree?.contentHash === evidence.contentHash));
|
|
878
|
-
}
|
|
879
|
-
function allEvidenceMatches(rows, snapshot) {
|
|
880
|
-
return rows.length > 0 && rows.every((row) => (row.binding_status === "bound"
|
|
881
|
-
&& evidenceMatchesSnapshot(evidenceFromRow(row), snapshot)));
|
|
882
|
-
}
|
|
883
|
-
function inferredStructuralTarget(relation, snapshotId) {
|
|
884
|
-
if (relation.to.domain !== "structural") {
|
|
885
|
-
return undefined;
|
|
886
|
-
}
|
|
887
|
-
const targetReference = relation.to.id;
|
|
888
|
-
const matchingEvidence = relation.evidence.find((item) => item.symbolId === targetReference);
|
|
889
|
-
if (matchingEvidence === undefined) {
|
|
890
|
-
return undefined;
|
|
891
|
-
}
|
|
892
|
-
const storedEvidence = matchingEvidence;
|
|
893
|
-
return {
|
|
894
|
-
structuralReference: targetReference,
|
|
895
|
-
file: matchingEvidence.file,
|
|
896
|
-
qualifiedSymbol: storedEvidence.qualifiedSymbol ?? null,
|
|
897
|
-
structuralKind: storedEvidence.structuralKind ?? null,
|
|
898
|
-
range: matchingEvidence.range,
|
|
899
|
-
atlasSnapshotId: storedEvidence.atlasSnapshotId ?? snapshotId,
|
|
900
|
-
backendVersion: storedEvidence.backendVersion ?? null,
|
|
901
|
-
backendLocator: storedEvidence.backendLocator ?? null,
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
|
-
function lexicalScore(terms, fields) {
|
|
905
|
-
const weights = [10, 8, 4, 6, 5];
|
|
906
|
-
const score = terms.reduce((total, term) => total + fields.reduce((fieldTotal, field, index) => fieldTotal + (field.includes(term) ? weights[index] : 0), 0), 0);
|
|
907
|
-
return score / (score + 1);
|
|
908
|
-
}
|
|
909
|
-
function businessKeyOf(node) {
|
|
910
|
-
return node.domain === "business" ? node.key : node.id;
|
|
911
|
-
}
|
|
912
|
-
export { CURRENT_ATLAS_SCHEMA_VERSION };
|