semantic-atlas 0.4.0 → 1.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 +131 -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 +134 -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 +649 -0
- package/dist/contracts/observation.d.ts.map +1 -0
- package/dist/contracts/observation.js +140 -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 +13 -0
- package/dist/observations/observation-claim-manager.d.ts.map +1 -0
- package/dist/observations/observation-claim-manager.js +247 -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 +208 -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 +116 -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 +307 -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 +428 -0
- package/docs/evaluation.md +220 -174
- package/docs/index.md +27 -45
- package/docs/map-format.md +224 -0
- package/docs/observations.md +175 -0
- package/docs/product-contract.md +295 -165
- package/examples/commerce.yaml +204 -0
- package/package.json +32 -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,5 +0,0 @@
|
|
|
1
|
-
import type { CodeGraphWorkerRequest } from "./codegraph-worker-protocol.js";
|
|
2
|
-
export declare const CODEGRAPH_WORKER_ENVIRONMENT = "SEMANTIC_ATLAS_CODEGRAPH_WORKER";
|
|
3
|
-
export declare function requiresBundledCodeGraphRuntime(): boolean;
|
|
4
|
-
export declare function runCodeGraphWorker<T>(request: CodeGraphWorkerRequest): Promise<T>;
|
|
5
|
-
//# sourceMappingURL=codegraph-worker-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegraph-worker-client.d.ts","sourceRoot":"","sources":["../../src/structural-backend/codegraph-worker-client.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAEV,sBAAsB,EAGvB,MAAM,gCAAgC,CAAC;AAGxC,eAAO,MAAM,4BAA4B,oCAAoC,CAAC;AAK9E,wBAAgB,+BAA+B,IAAI,OAAO,CAMzD;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC,CA4BvF"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH, GraphPatchConflictError, } from "../knowledge/graph-patch-conflict-error.js";
|
|
6
|
-
import { StructuralBackendError } from "./types.js";
|
|
7
|
-
export const CODEGRAPH_WORKER_ENVIRONMENT = "SEMANTIC_ATLAS_CODEGRAPH_WORKER";
|
|
8
|
-
const MAX_WORKER_OUTPUT_BYTES = 64 * 1024 * 1024;
|
|
9
|
-
const require = createRequire(import.meta.url);
|
|
10
|
-
export function requiresBundledCodeGraphRuntime() {
|
|
11
|
-
if (process.env[CODEGRAPH_WORKER_ENVIRONMENT] === "1") {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
|
|
15
|
-
return major === 22 && minor < 16;
|
|
16
|
-
}
|
|
17
|
-
export async function runCodeGraphWorker(request) {
|
|
18
|
-
let response;
|
|
19
|
-
try {
|
|
20
|
-
response = await executeWorker(request);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
throw new StructuralBackendError("STRUCTURAL_QUERY_FAILED", "The structural backend worker could not complete the operation", error);
|
|
24
|
-
}
|
|
25
|
-
if (response.ok) {
|
|
26
|
-
return response.value;
|
|
27
|
-
}
|
|
28
|
-
if (isGraphPatchConflictWorkerError(response.error)) {
|
|
29
|
-
throw new GraphPatchConflictError(response.error.baseSnapshotId, response.error.currentSnapshotId);
|
|
30
|
-
}
|
|
31
|
-
throw new StructuralBackendError(isStructuralBackendErrorCode(response.error.code)
|
|
32
|
-
? response.error.code
|
|
33
|
-
: "STRUCTURAL_QUERY_FAILED", response.error.message);
|
|
34
|
-
}
|
|
35
|
-
function isGraphPatchConflictWorkerError(error) {
|
|
36
|
-
return error.name === "GraphPatchConflictError" &&
|
|
37
|
-
error.code === GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH &&
|
|
38
|
-
typeof error.baseSnapshotId === "string" &&
|
|
39
|
-
typeof error.currentSnapshotId === "string";
|
|
40
|
-
}
|
|
41
|
-
async function executeWorker(request) {
|
|
42
|
-
const runtime = resolveBundledNodeRuntime();
|
|
43
|
-
const worker = fileURLToPath(new URL("./codegraph-worker.js", import.meta.url));
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
const child = spawn(runtime, [
|
|
46
|
-
"--liftoff-only",
|
|
47
|
-
"--disable-warning=ExperimentalWarning",
|
|
48
|
-
worker,
|
|
49
|
-
], {
|
|
50
|
-
env: {
|
|
51
|
-
...process.env,
|
|
52
|
-
[CODEGRAPH_WORKER_ENVIRONMENT]: "1",
|
|
53
|
-
},
|
|
54
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
55
|
-
});
|
|
56
|
-
const stdout = [];
|
|
57
|
-
const stderr = [];
|
|
58
|
-
let outputBytes = 0;
|
|
59
|
-
child.stdout.on("data", (chunk) => {
|
|
60
|
-
outputBytes += chunk.length;
|
|
61
|
-
if (outputBytes > MAX_WORKER_OUTPUT_BYTES) {
|
|
62
|
-
child.kill();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
stdout.push(chunk);
|
|
66
|
-
});
|
|
67
|
-
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
68
|
-
child.on("error", reject);
|
|
69
|
-
child.on("close", (code, signal) => {
|
|
70
|
-
if (outputBytes > MAX_WORKER_OUTPUT_BYTES) {
|
|
71
|
-
reject(new Error("The structural backend worker exceeded its output limit"));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const output = Buffer.concat(stdout).toString("utf8");
|
|
75
|
-
if (code !== 0) {
|
|
76
|
-
const diagnostic = Buffer.concat(stderr).toString("utf8").trim();
|
|
77
|
-
reject(new Error(`The structural backend worker exited ${signal ?? code}${diagnostic.length === 0 ? "" : `: ${diagnostic}`}`));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const response = JSON.parse(output);
|
|
82
|
-
if (!isWorkerResponse(response)) {
|
|
83
|
-
throw new Error("Invalid worker response shape");
|
|
84
|
-
}
|
|
85
|
-
resolve(response);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
reject(new Error("The structural backend worker returned an invalid response", { cause: error }));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
child.stdin.end(JSON.stringify(request));
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function resolveBundledNodeRuntime() {
|
|
95
|
-
const codeGraphPackage = require.resolve("@colbymchenry/codegraph/package.json");
|
|
96
|
-
const codeGraphRequire = createRequire(codeGraphPackage);
|
|
97
|
-
const platformPackageName = `@colbymchenry/codegraph-${process.platform}-${process.arch}`;
|
|
98
|
-
const platformPackage = codeGraphRequire.resolve(`${platformPackageName}/package.json`);
|
|
99
|
-
return join(dirname(platformPackage), process.platform === "win32" ? "node.exe" : "node");
|
|
100
|
-
}
|
|
101
|
-
function isStructuralBackendErrorCode(code) {
|
|
102
|
-
return code === "STRUCTURAL_INDEX_MISSING" ||
|
|
103
|
-
code === "STRUCTURAL_INDEX_INCOMPLETE" ||
|
|
104
|
-
code === "STRUCTURAL_QUERY_FAILED";
|
|
105
|
-
}
|
|
106
|
-
function isWorkerResponse(value) {
|
|
107
|
-
if (typeof value !== "object" || value === null || !("ok" in value)) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (value.ok === true) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
if (value.ok !== false || !("error" in value) || typeof value.error !== "object" || value.error === null) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
return "name" in value.error && typeof value.error.name === "string" &&
|
|
117
|
-
"message" in value.error && typeof value.error.message === "string";
|
|
118
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH } from "../knowledge/graph-patch-conflict-error.js";
|
|
2
|
-
import type { GitRepository } from "../repository/types.js";
|
|
3
|
-
import type { StructuralReference, StructuralProjectGraphQuery, StructuralSearchQuery, StructuralTraversalQuery } from "./types.js";
|
|
4
|
-
export type CodeGraphWorkerRequest = WorkerRequest<"inspect"> | WorkerRequest<"build"> | WorkerRequest<"sync"> | WorkerRequest<"listUnknownBoundaries"> | WorkerRequest<"listRoots"> | WorkerRequest<"readProjectGraph", StructuralProjectGraphQuery> | WorkerRequest<"search", StructuralSearchQuery> | WorkerRequest<"getNode", StructuralReference> | WorkerRequest<"traverse", StructuralTraversalQuery> | WorkerRequest<"getCallers", StructuralReference> | WorkerRequest<"getCallees", StructuralReference> | WorkerRequest<"getFileDependencies", string> | WorkerRequest<"worldBuild"> | WorkerRequest<"worldSync"> | WorkerRequest<"learn", unknown>;
|
|
5
|
-
type WorkerRequest<Operation extends string, Input = undefined> = {
|
|
6
|
-
readonly operation: Operation;
|
|
7
|
-
readonly repository: GitRepository;
|
|
8
|
-
} & (Input extends undefined ? {
|
|
9
|
-
readonly input?: never;
|
|
10
|
-
} : {
|
|
11
|
-
readonly input: Input;
|
|
12
|
-
});
|
|
13
|
-
export type CodeGraphWorkerResponse = {
|
|
14
|
-
readonly ok: true;
|
|
15
|
-
readonly value: unknown;
|
|
16
|
-
} | {
|
|
17
|
-
readonly ok: false;
|
|
18
|
-
readonly error: CodeGraphWorkerError;
|
|
19
|
-
};
|
|
20
|
-
export type CodeGraphWorkerError = {
|
|
21
|
-
readonly name: string;
|
|
22
|
-
readonly message: string;
|
|
23
|
-
readonly code?: string;
|
|
24
|
-
readonly stack?: string;
|
|
25
|
-
readonly baseSnapshotId?: string;
|
|
26
|
-
readonly currentSnapshotId?: string;
|
|
27
|
-
};
|
|
28
|
-
export type GraphPatchConflictWorkerError = CodeGraphWorkerError & {
|
|
29
|
-
readonly name: "GraphPatchConflictError";
|
|
30
|
-
readonly code: typeof GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH;
|
|
31
|
-
readonly baseSnapshotId: string;
|
|
32
|
-
readonly currentSnapshotId: string;
|
|
33
|
-
};
|
|
34
|
-
export {};
|
|
35
|
-
//# sourceMappingURL=codegraph-worker-protocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegraph-worker-protocol.d.ts","sourceRoot":"","sources":["../../src/structural-backend/codegraph-worker-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,4CAA4C,CAAC;AACrG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAC9B,aAAa,CAAC,SAAS,CAAC,GACxB,aAAa,CAAC,OAAO,CAAC,GACtB,aAAa,CAAC,MAAM,CAAC,GACrB,aAAa,CAAC,uBAAuB,CAAC,GACtC,aAAa,CAAC,WAAW,CAAC,GAC1B,aAAa,CAAC,kBAAkB,EAAE,2BAA2B,CAAC,GAC9D,aAAa,CAAC,QAAQ,EAAE,qBAAqB,CAAC,GAC9C,aAAa,CAAC,SAAS,EAAE,mBAAmB,CAAC,GAC7C,aAAa,CAAC,UAAU,EAAE,wBAAwB,CAAC,GACnD,aAAa,CAAC,YAAY,EAAE,mBAAmB,CAAC,GAChD,aAAa,CAAC,YAAY,EAAE,mBAAmB,CAAC,GAChD,aAAa,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAC5C,aAAa,CAAC,YAAY,CAAC,GAC3B,aAAa,CAAC,WAAW,CAAC,GAC1B,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEpC,KAAK,aAAa,CAAC,SAAS,SAAS,MAAM,EAAE,KAAK,GAAG,SAAS,IAAI;IAChE,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;CACpC,GAAG,CAAC,KAAK,SAAS,SAAS,GAAG;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC;AAEvF,MAAM,MAAM,uBAAuB,GAC/B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC9C;IACA,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;CACtC,CAAC;AAEJ,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,GAAG;IACjE,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,OAAO,kCAAkC,CAAC;IACzD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegraph-worker.d.ts","sourceRoot":"","sources":["../../src/structural-backend/codegraph-worker.ts"],"names":[],"mappings":""}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
import { stdin, stdout } from "node:process";
|
|
54
|
-
import { GraphStore } from "../graph/graph-store.js";
|
|
55
|
-
import { BusinessKnowledgeService } from "../knowledge/business-knowledge-service.js";
|
|
56
|
-
import { GraphPatchConflictError } from "../knowledge/graph-patch-conflict-error.js";
|
|
57
|
-
import { WorldModelService } from "../world/world-model-service.js";
|
|
58
|
-
import { CodeGraphStructuralBackend } from "./codegraph-backend.js";
|
|
59
|
-
const request = JSON.parse(await readStandardInput());
|
|
60
|
-
const backend = new CodeGraphStructuralBackend(request.repository);
|
|
61
|
-
try {
|
|
62
|
-
const value = await executeRequest(backend, request);
|
|
63
|
-
writeResponse({ ok: true, value });
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
writeResponse({ ok: false, error: serializeError(error) });
|
|
67
|
-
}
|
|
68
|
-
async function executeRequest(backend, request) {
|
|
69
|
-
switch (request.operation) {
|
|
70
|
-
case "inspect": return backend.inspect();
|
|
71
|
-
case "build": return backend.build();
|
|
72
|
-
case "sync": return backend.sync();
|
|
73
|
-
case "listUnknownBoundaries": return backend.listUnknownBoundaries();
|
|
74
|
-
case "listRoots": return backend.listRoots();
|
|
75
|
-
case "readProjectGraph": return backend.readProjectGraph(request.input);
|
|
76
|
-
case "search": return backend.search(request.input);
|
|
77
|
-
case "getNode": return backend.getNode(request.input);
|
|
78
|
-
case "traverse": return backend.traverse(request.input);
|
|
79
|
-
case "getCallers": return backend.getCallers(request.input);
|
|
80
|
-
case "getCallees": return backend.getCallees(request.input);
|
|
81
|
-
case "getFileDependencies": return backend.getFileDependencies(request.input);
|
|
82
|
-
case "worldBuild": return new WorldModelService(request.repository).build();
|
|
83
|
-
case "worldSync": return new WorldModelService(request.repository).sync();
|
|
84
|
-
case "learn": {
|
|
85
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
86
|
-
try {
|
|
87
|
-
const graph = __addDisposableResource(env_1, new GraphStore(request.repository), false);
|
|
88
|
-
return await new BusinessKnowledgeService(request.repository, graph, backend).learn(request.input);
|
|
89
|
-
}
|
|
90
|
-
catch (e_1) {
|
|
91
|
-
env_1.error = e_1;
|
|
92
|
-
env_1.hasError = true;
|
|
93
|
-
}
|
|
94
|
-
finally {
|
|
95
|
-
__disposeResources(env_1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async function readStandardInput() {
|
|
101
|
-
const chunks = [];
|
|
102
|
-
for await (const chunk of stdin) {
|
|
103
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
104
|
-
}
|
|
105
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
106
|
-
}
|
|
107
|
-
function serializeError(error) {
|
|
108
|
-
if (error instanceof GraphPatchConflictError) {
|
|
109
|
-
return {
|
|
110
|
-
name: error.name,
|
|
111
|
-
message: error.message,
|
|
112
|
-
code: error.code,
|
|
113
|
-
baseSnapshotId: error.baseSnapshotId,
|
|
114
|
-
currentSnapshotId: error.currentSnapshotId,
|
|
115
|
-
...(error.stack === undefined ? {} : { stack: error.stack }),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (!(error instanceof Error)) {
|
|
119
|
-
return { name: "Error", message: String(error) };
|
|
120
|
-
}
|
|
121
|
-
const code = "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
122
|
-
return {
|
|
123
|
-
name: error.name,
|
|
124
|
-
message: error.message,
|
|
125
|
-
...(code === undefined ? {} : { code }),
|
|
126
|
-
...(error.stack === undefined ? {} : { stack: error.stack }),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function writeResponse(response) {
|
|
130
|
-
stdout.write(JSON.stringify(response));
|
|
131
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type ProcessInstanceStatus = "matching" | "different" | "missing" | "unknown";
|
|
2
|
-
export type ProcessInstanceProof = "process-start" | "open-file";
|
|
3
|
-
export interface ProcessInstance {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
readonly proof: ProcessInstanceProof;
|
|
6
|
-
}
|
|
7
|
-
export interface ProcessLeaseIdentity {
|
|
8
|
-
readonly path: string;
|
|
9
|
-
readonly device: number;
|
|
10
|
-
readonly inode: number;
|
|
11
|
-
readonly writtenAtMs: number;
|
|
12
|
-
}
|
|
13
|
-
export declare function currentProcessInstance(): ProcessInstance;
|
|
14
|
-
export declare function currentProcessInstanceId(): string;
|
|
15
|
-
export declare function inspectProcessInstance(pid: number, expectedInstanceId: string, proof: ProcessInstanceProof, lease: ProcessLeaseIdentity): ProcessInstanceStatus;
|
|
16
|
-
export declare function processStartedAfter(pid: number, timestampMs: number): boolean | undefined;
|
|
17
|
-
export declare function isProcessAlive(pid: number): boolean;
|
|
18
|
-
//# sourceMappingURL=process-instance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process-instance.d.ts","sourceRoot":"","sources":["../../src/structural-backend/process-instance.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AACrF,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,WAAW,CAAC;AAEjE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;CACtC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAID,wBAAgB,sBAAsB,IAAI,eAAe,CASxD;AAED,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,kBAAkB,EAAE,MAAM,EAC1B,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,oBAAoB,GAC1B,qBAAqB,CAevB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAGzF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOnD"}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
const POSIX_OPEN_FILE_INSTANCE_ID = randomBytes(32).toString("hex");
|
|
5
|
-
export function currentProcessInstance() {
|
|
6
|
-
if (usesOpenFileProof()) {
|
|
7
|
-
return { id: POSIX_OPEN_FILE_INSTANCE_ID, proof: "open-file" };
|
|
8
|
-
}
|
|
9
|
-
const instanceId = readProcessStartInstanceId(process.pid);
|
|
10
|
-
if (instanceId === undefined) {
|
|
11
|
-
throw new Error("The structural backend could not identify its lock-owning process instance");
|
|
12
|
-
}
|
|
13
|
-
return { id: instanceId, proof: "process-start" };
|
|
14
|
-
}
|
|
15
|
-
export function currentProcessInstanceId() {
|
|
16
|
-
return currentProcessInstance().id;
|
|
17
|
-
}
|
|
18
|
-
export function inspectProcessInstance(pid, expectedInstanceId, proof, lease) {
|
|
19
|
-
if (!isProcessAlive(pid)) {
|
|
20
|
-
return "missing";
|
|
21
|
-
}
|
|
22
|
-
if (proof === "open-file") {
|
|
23
|
-
return inspectOpenFileProcessInstance(pid, lease);
|
|
24
|
-
}
|
|
25
|
-
const instanceId = readProcessStartInstanceId(pid);
|
|
26
|
-
if (instanceId === undefined) {
|
|
27
|
-
return isProcessAlive(pid) ? "unknown" : "missing";
|
|
28
|
-
}
|
|
29
|
-
if (instanceId !== expectedInstanceId) {
|
|
30
|
-
return "different";
|
|
31
|
-
}
|
|
32
|
-
return processStartedAfter(pid, lease.writtenAtMs) === true ? "different" : "matching";
|
|
33
|
-
}
|
|
34
|
-
export function processStartedAfter(pid, timestampMs) {
|
|
35
|
-
const startedAtMs = readProcessStartedAtMs(pid);
|
|
36
|
-
return startedAtMs === undefined ? undefined : startedAtMs > timestampMs;
|
|
37
|
-
}
|
|
38
|
-
export function isProcessAlive(pid) {
|
|
39
|
-
try {
|
|
40
|
-
process.kill(pid, 0);
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
return !isFileSystemError(error, "ESRCH");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function readProcessStartInstanceId(pid) {
|
|
48
|
-
const fingerprint = process.platform === "linux"
|
|
49
|
-
? readLinuxProcessFingerprint(pid)
|
|
50
|
-
: process.platform === "win32"
|
|
51
|
-
? readWindowsProcessFingerprint(pid)
|
|
52
|
-
: readPosixProcessFingerprint(pid);
|
|
53
|
-
return fingerprint === undefined
|
|
54
|
-
? undefined
|
|
55
|
-
: createHash("sha256").update(fingerprint).digest("hex");
|
|
56
|
-
}
|
|
57
|
-
function readProcessStartedAtMs(pid) {
|
|
58
|
-
if (process.platform === "win32") {
|
|
59
|
-
const ticks = readWindowsStartedAtTicks(pid);
|
|
60
|
-
return ticks === undefined ? undefined : Number((ticks - 621355968000000000n) / 10000n);
|
|
61
|
-
}
|
|
62
|
-
if (process.platform === "darwin") {
|
|
63
|
-
return readDarwinProcessStartedAtMs(pid);
|
|
64
|
-
}
|
|
65
|
-
const startedAt = readPosixStartedAt(pid);
|
|
66
|
-
const timestampMs = startedAt === undefined ? Number.NaN : Date.parse(`${startedAt} UTC`);
|
|
67
|
-
return Number.isFinite(timestampMs) ? timestampMs : undefined;
|
|
68
|
-
}
|
|
69
|
-
function inspectOpenFileProcessInstance(pid, lease) {
|
|
70
|
-
// The owner keeps this inode open for the entire lease, so PID reuse cannot recreate the proof.
|
|
71
|
-
try {
|
|
72
|
-
const output = execFileSync(process.platform === "darwin" ? "/usr/sbin/lsof" : "lsof", [
|
|
73
|
-
"-a",
|
|
74
|
-
"-p",
|
|
75
|
-
String(pid),
|
|
76
|
-
"-F0pDi",
|
|
77
|
-
"--",
|
|
78
|
-
lease.path,
|
|
79
|
-
], {
|
|
80
|
-
encoding: "utf8",
|
|
81
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
82
|
-
timeout: 2_000,
|
|
83
|
-
});
|
|
84
|
-
return lsofIdentities(output).some(({ device, inode }) => device === BigInt(lease.device) && inode === BigInt(lease.inode))
|
|
85
|
-
? "matching"
|
|
86
|
-
: "different";
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (isEmptyLsofResult(error)) {
|
|
90
|
-
return isProcessAlive(pid) ? "different" : "missing";
|
|
91
|
-
}
|
|
92
|
-
return isProcessAlive(pid) ? "unknown" : "missing";
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function lsofIdentities(output) {
|
|
96
|
-
const identities = [];
|
|
97
|
-
let current;
|
|
98
|
-
for (const field of output.split(/[\0\n]/u)) {
|
|
99
|
-
if (field.startsWith("f")) {
|
|
100
|
-
current = {};
|
|
101
|
-
identities.push(current);
|
|
102
|
-
}
|
|
103
|
-
else if (current !== undefined && field.startsWith("D") && /^0x[0-9a-f]+$/iu.test(field.slice(1))) {
|
|
104
|
-
current.device = BigInt(field.slice(1));
|
|
105
|
-
}
|
|
106
|
-
else if (current !== undefined && field.startsWith("i") && /^\d+$/u.test(field.slice(1))) {
|
|
107
|
-
current.inode = BigInt(field.slice(1));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return identities.flatMap((identity) => identity.device === undefined || identity.inode === undefined
|
|
111
|
-
? []
|
|
112
|
-
: [{ device: identity.device, inode: identity.inode }]);
|
|
113
|
-
}
|
|
114
|
-
function isEmptyLsofResult(error) {
|
|
115
|
-
if (!(error instanceof Error) || !("status" in error) || error.status !== 1) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
const stdout = "stdout" in error ? error.stdout : undefined;
|
|
119
|
-
const stderr = "stderr" in error ? error.stderr : undefined;
|
|
120
|
-
return typeof stdout === "string" && stdout.length === 0 &&
|
|
121
|
-
typeof stderr === "string" && stderr.length === 0;
|
|
122
|
-
}
|
|
123
|
-
function readDarwinProcessStartedAtMs(pid) {
|
|
124
|
-
try {
|
|
125
|
-
const report = execFileSync("/usr/bin/sample", [
|
|
126
|
-
String(pid),
|
|
127
|
-
"1",
|
|
128
|
-
"10",
|
|
129
|
-
"-file",
|
|
130
|
-
"/dev/stdout",
|
|
131
|
-
], {
|
|
132
|
-
encoding: "utf8",
|
|
133
|
-
env: { ...process.env, LANG: "C", LC_ALL: "C", TZ: "UTC" },
|
|
134
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
135
|
-
timeout: 2_000,
|
|
136
|
-
});
|
|
137
|
-
const launchTime = /^Launch Time:\s+(.+)$/mu.exec(report)?.[1];
|
|
138
|
-
const timestampMs = launchTime === undefined ? Number.NaN : Date.parse(launchTime);
|
|
139
|
-
return Number.isFinite(timestampMs) ? timestampMs : undefined;
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function usesOpenFileProof() {
|
|
146
|
-
return process.platform !== "linux" && process.platform !== "win32";
|
|
147
|
-
}
|
|
148
|
-
function readLinuxProcessFingerprint(pid) {
|
|
149
|
-
try {
|
|
150
|
-
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
151
|
-
const commandEnd = stat.lastIndexOf(")");
|
|
152
|
-
if (commandEnd === -1) {
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
const fieldsFromState = stat.slice(commandEnd + 2).trim().split(/\s+/u);
|
|
156
|
-
const startTimeTicks = fieldsFromState[19];
|
|
157
|
-
const bootId = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
158
|
-
return startTimeTicks === undefined || bootId.length === 0
|
|
159
|
-
? undefined
|
|
160
|
-
: `linux:${bootId}:${startTimeTicks}`;
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function readPosixProcessFingerprint(pid) {
|
|
167
|
-
const startedAt = readPosixStartedAt(pid);
|
|
168
|
-
return startedAt === undefined ? undefined : `${process.platform}:${startedAt}`;
|
|
169
|
-
}
|
|
170
|
-
function readPosixStartedAt(pid) {
|
|
171
|
-
try {
|
|
172
|
-
const startedAt = execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
173
|
-
encoding: "utf8",
|
|
174
|
-
env: { ...process.env, LANG: "C", LC_ALL: "C", TZ: "UTC" },
|
|
175
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
176
|
-
}).trim();
|
|
177
|
-
return startedAt.length === 0 ? undefined : startedAt;
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function readWindowsProcessFingerprint(pid) {
|
|
184
|
-
const startedAt = readWindowsStartedAtTicks(pid);
|
|
185
|
-
return startedAt === undefined ? undefined : `win32:${startedAt}`;
|
|
186
|
-
}
|
|
187
|
-
function readWindowsStartedAtTicks(pid) {
|
|
188
|
-
try {
|
|
189
|
-
const startedAt = execFileSync("powershell.exe", [
|
|
190
|
-
"-NoLogo",
|
|
191
|
-
"-NoProfile",
|
|
192
|
-
"-NonInteractive",
|
|
193
|
-
"-Command",
|
|
194
|
-
`(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().Ticks`,
|
|
195
|
-
], {
|
|
196
|
-
encoding: "utf8",
|
|
197
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
198
|
-
}).trim();
|
|
199
|
-
return /^\d+$/u.test(startedAt) ? BigInt(startedAt) : undefined;
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function isFileSystemError(error, code) {
|
|
206
|
-
return error instanceof Error && "code" in error && error.code === code;
|
|
207
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CodeGraph } from "@colbymchenry/codegraph";
|
|
2
|
-
import type { StructuralFactChanges } from "./types.js";
|
|
3
|
-
type StructuralFacts = Map<string, string[]>;
|
|
4
|
-
export declare function captureStructuralFacts(graph: CodeGraph): StructuralFacts;
|
|
5
|
-
export declare function compareStructuralFacts(previous: StructuralFacts, current: StructuralFacts): StructuralFactChanges;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=structural-fact-changes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structural-fact-changes.d.ts","sourceRoot":"","sources":["../../src/structural-backend/structural-fact-changes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAQ,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,KAAK,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAE7C,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,GAAG,eAAe,CA0BxE;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,eAAe,GACvB,qBAAqB,CAsBvB"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export function captureStructuralFacts(graph) {
|
|
2
|
-
const facts = new Map();
|
|
3
|
-
const nodeIdentities = new Map();
|
|
4
|
-
for (const file of graph.getFiles()) {
|
|
5
|
-
for (const node of graph.getNodesInFile(file.path)) {
|
|
6
|
-
nodeIdentities.set(node.id, structuralNodeIdentity(node));
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
for (const file of graph.getFiles()) {
|
|
10
|
-
for (const node of graph.getNodesInFile(file.path)) {
|
|
11
|
-
const identity = structuralNodeIdentity(node);
|
|
12
|
-
const { id: _id, updatedAt: _updatedAt, ...content } = node;
|
|
13
|
-
addStructuralFact(facts, `node\0${identity}`, content);
|
|
14
|
-
for (const edge of graph.getOutgoingEdges(node.id)) {
|
|
15
|
-
const source = nodeIdentities.get(edge.source) ?? `backend:${edge.source}`;
|
|
16
|
-
const target = nodeIdentities.get(edge.target) ?? `backend:${edge.target}`;
|
|
17
|
-
const { source: _source, target: _target, ...relationContent } = edge;
|
|
18
|
-
addStructuralFact(facts, `relation\0${source}\0${edge.kind}\0${target}`, { source, target, ...relationContent });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return facts;
|
|
23
|
-
}
|
|
24
|
-
export function compareStructuralFacts(previous, current) {
|
|
25
|
-
const changes = { added: 0, changed: 0, reused: 0, removed: 0 };
|
|
26
|
-
const identities = new Set([...previous.keys(), ...current.keys()]);
|
|
27
|
-
for (const identity of identities) {
|
|
28
|
-
const previousValues = countStructuralValues(previous.get(identity) ?? []);
|
|
29
|
-
const currentValues = countStructuralValues(current.get(identity) ?? []);
|
|
30
|
-
let previousRemaining = 0;
|
|
31
|
-
let currentRemaining = 0;
|
|
32
|
-
for (const value of new Set([...previousValues.keys(), ...currentValues.keys()])) {
|
|
33
|
-
const previousCount = previousValues.get(value) ?? 0;
|
|
34
|
-
const currentCount = currentValues.get(value) ?? 0;
|
|
35
|
-
const reused = Math.min(previousCount, currentCount);
|
|
36
|
-
changes.reused += reused;
|
|
37
|
-
previousRemaining += previousCount - reused;
|
|
38
|
-
currentRemaining += currentCount - reused;
|
|
39
|
-
}
|
|
40
|
-
const changed = Math.min(previousRemaining, currentRemaining);
|
|
41
|
-
changes.changed += changed;
|
|
42
|
-
changes.added += currentRemaining - changed;
|
|
43
|
-
changes.removed += previousRemaining - changed;
|
|
44
|
-
}
|
|
45
|
-
return changes;
|
|
46
|
-
}
|
|
47
|
-
function structuralNodeIdentity(node) {
|
|
48
|
-
return [normalizeRepositoryPath(node.filePath), node.kind, node.qualifiedName].join("\0");
|
|
49
|
-
}
|
|
50
|
-
function addStructuralFact(facts, identity, content) {
|
|
51
|
-
const values = facts.get(identity) ?? [];
|
|
52
|
-
values.push(stableStructuralValue(content));
|
|
53
|
-
facts.set(identity, values);
|
|
54
|
-
}
|
|
55
|
-
function countStructuralValues(values) {
|
|
56
|
-
const counts = new Map();
|
|
57
|
-
for (const value of values) {
|
|
58
|
-
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
59
|
-
}
|
|
60
|
-
return counts;
|
|
61
|
-
}
|
|
62
|
-
function stableStructuralValue(value) {
|
|
63
|
-
return JSON.stringify(sortStructuralValue(value));
|
|
64
|
-
}
|
|
65
|
-
function sortStructuralValue(value) {
|
|
66
|
-
if (Array.isArray(value)) {
|
|
67
|
-
return value.map(sortStructuralValue);
|
|
68
|
-
}
|
|
69
|
-
if (value === null || typeof value !== "object") {
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
return Object.fromEntries(Object.entries(value)
|
|
73
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
74
|
-
.map(([key, child]) => [key, sortStructuralValue(child)]));
|
|
75
|
-
}
|
|
76
|
-
function normalizeRepositoryPath(path) {
|
|
77
|
-
return path.replaceAll("\\", "/").replace(/^\.\//u, "");
|
|
78
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { GitRepository } from "../repository/types.js";
|
|
2
|
-
import type { RepositorySnapshot } from "../snapshots/types.js";
|
|
3
|
-
export declare class StructuralProjectionBootstrapper {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(repository: GitRepository);
|
|
6
|
-
bootstrap(currentSnapshot: RepositorySnapshot): Promise<boolean>;
|
|
7
|
-
private findCandidates;
|
|
8
|
-
private restoreCandidate;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=structural-projection-bootstrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structural-projection-bootstrapper.d.ts","sourceRoot":"","sources":["../../src/structural-backend/structural-projection-bootstrapper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AA2BhE,qBAAa,gCAAgC;;gBAI/B,UAAU,EAAE,aAAa;IAK/B,SAAS,CAAC,eAAe,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;YAaxD,cAAc;YA6Dd,gBAAgB;CAiD/B"}
|