semantic-atlas 0.1.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 +172 -0
- package/.agents/skills/semantic-atlas/references/graph-patch.md +109 -0
- package/.agents/skills/semantic-atlas/references/result-routing.md +91 -0
- package/LICENSE +21 -0
- package/README.md +118 -0
- package/dist/business-flow/business-flow-derivation-service.d.ts +11 -0
- package/dist/business-flow/business-flow-derivation-service.d.ts.map +1 -0
- package/dist/business-flow/business-flow-derivation-service.js +151 -0
- package/dist/business-flow/business-flow-draft.d.ts +16 -0
- package/dist/business-flow/business-flow-draft.d.ts.map +1 -0
- package/dist/business-flow/business-flow-draft.js +150 -0
- package/dist/business-flow/framework-business-strategy.d.ts +7 -0
- package/dist/business-flow/framework-business-strategy.d.ts.map +1 -0
- package/dist/business-flow/framework-business-strategy.js +1 -0
- package/dist/business-flow/strategies/bullmq-business-strategy.d.ts +10 -0
- package/dist/business-flow/strategies/bullmq-business-strategy.d.ts.map +1 -0
- package/dist/business-flow/strategies/bullmq-business-strategy.js +79 -0
- package/dist/business-flow/strategies/called-operation-derivation.d.ts +13 -0
- package/dist/business-flow/strategies/called-operation-derivation.d.ts.map +1 -0
- package/dist/business-flow/strategies/called-operation-derivation.js +32 -0
- package/dist/business-flow/strategies/graphql-business-strategy.d.ts +8 -0
- package/dist/business-flow/strategies/graphql-business-strategy.d.ts.map +1 -0
- package/dist/business-flow/strategies/graphql-business-strategy.js +65 -0
- package/dist/business-flow/strategies/nestjs-business-strategy.d.ts +8 -0
- package/dist/business-flow/strategies/nestjs-business-strategy.d.ts.map +1 -0
- package/dist/business-flow/strategies/nestjs-business-strategy.js +72 -0
- package/dist/business-flow/strategies/strategy-helpers.d.ts +32 -0
- package/dist/business-flow/strategies/strategy-helpers.d.ts.map +1 -0
- package/dist/business-flow/strategies/strategy-helpers.js +49 -0
- package/dist/business-flow/strategies/typeorm-business-strategy.d.ts +10 -0
- package/dist/business-flow/strategies/typeorm-business-strategy.d.ts.map +1 -0
- package/dist/business-flow/strategies/typeorm-business-strategy.js +136 -0
- package/dist/business-flow/strategies/verified-invariant-strategy.d.ts +5 -0
- package/dist/business-flow/strategies/verified-invariant-strategy.d.ts.map +1 -0
- package/dist/business-flow/strategies/verified-invariant-strategy.js +38 -0
- package/dist/business-flow/strategies/verified-test-strategy.d.ts +5 -0
- package/dist/business-flow/strategies/verified-test-strategy.d.ts.map +1 -0
- package/dist/business-flow/strategies/verified-test-strategy.js +26 -0
- package/dist/business-flow/structural-flow-catalog.d.ts +21 -0
- package/dist/business-flow/structural-flow-catalog.d.ts.map +1 -0
- package/dist/business-flow/structural-flow-catalog.js +125 -0
- package/dist/business-flow/types.d.ts +51 -0
- package/dist/business-flow/types.d.ts.map +1 -0
- package/dist/business-flow/types.js +1 -0
- package/dist/cli/argument-parser.d.ts +3 -0
- package/dist/cli/argument-parser.d.ts.map +1 -0
- package/dist/cli/argument-parser.js +174 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +23 -0
- package/dist/cli/cli-application.d.ts +38 -0
- package/dist/cli/cli-application.d.ts.map +1 -0
- package/dist/cli/cli-application.js +515 -0
- package/dist/cli/cli-error.d.ts +12 -0
- package/dist/cli/cli-error.d.ts.map +1 -0
- package/dist/cli/cli-error.js +44 -0
- package/dist/cli/cli-presenter.d.ts +14 -0
- package/dist/cli/cli-presenter.d.ts.map +1 -0
- package/dist/cli/cli-presenter.js +36 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +45 -0
- package/dist/cli/types.d.ts +46 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +1 -0
- package/dist/contracts/cli.d.ts +2139 -0
- package/dist/contracts/cli.d.ts.map +1 -0
- package/dist/contracts/cli.js +232 -0
- package/dist/contracts/graph.d.ts +262 -0
- package/dist/contracts/graph.d.ts.map +1 -0
- package/dist/contracts/graph.js +182 -0
- package/dist/contracts/identifiers.d.ts +4 -0
- package/dist/contracts/identifiers.d.ts.map +1 -0
- package/dist/contracts/identifiers.js +7 -0
- package/dist/contracts/public-contracts.d.ts +4 -0
- package/dist/contracts/public-contracts.d.ts.map +1 -0
- package/dist/contracts/public-contracts.js +3 -0
- package/dist/evaluation/comparison.d.ts +30 -0
- package/dist/evaluation/comparison.d.ts.map +1 -0
- package/dist/evaluation/comparison.js +108 -0
- package/dist/evaluation/contracts.d.ts +204 -0
- package/dist/evaluation/contracts.d.ts.map +1 -0
- package/dist/evaluation/contracts.js +269 -0
- package/dist/graph/graph-store.d.ts +47 -0
- package/dist/graph/graph-store.d.ts.map +1 -0
- package/dist/graph/graph-store.js +719 -0
- package/dist/graph/types.d.ts +168 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/knowledge/business-knowledge-service.d.ts +24 -0
- package/dist/knowledge/business-knowledge-service.d.ts.map +1 -0
- package/dist/knowledge/business-knowledge-service.js +200 -0
- package/dist/knowledge/graph-patch-conflict-error.d.ts +8 -0
- package/dist/knowledge/graph-patch-conflict-error.d.ts.map +1 -0
- package/dist/knowledge/graph-patch-conflict-error.js +12 -0
- package/dist/knowledge/structural-target-binding.d.ts +14 -0
- package/dist/knowledge/structural-target-binding.d.ts.map +1 -0
- package/dist/knowledge/structural-target-binding.js +11 -0
- package/dist/repository/git-command.d.ts +3 -0
- package/dist/repository/git-command.d.ts.map +1 -0
- package/dist/repository/git-command.js +25 -0
- package/dist/repository/repository-inspector.d.ts +7 -0
- package/dist/repository/repository-inspector.d.ts.map +1 -0
- package/dist/repository/repository-inspector.js +84 -0
- package/dist/repository/repository-language-support.d.ts +14 -0
- package/dist/repository/repository-language-support.d.ts.map +1 -0
- package/dist/repository/repository-language-support.js +64 -0
- package/dist/repository/types.d.ts +9 -0
- package/dist/repository/types.d.ts.map +1 -0
- package/dist/repository/types.js +1 -0
- package/dist/snapshots/repository-snapshot.d.ts +4 -0
- package/dist/snapshots/repository-snapshot.d.ts.map +1 -0
- package/dist/snapshots/repository-snapshot.js +119 -0
- package/dist/snapshots/types.d.ts +30 -0
- package/dist/snapshots/types.d.ts.map +1 -0
- package/dist/snapshots/types.js +1 -0
- package/dist/storage/atlas-database.d.ts +14 -0
- package/dist/storage/atlas-database.d.ts.map +1 -0
- package/dist/storage/atlas-database.js +552 -0
- package/dist/storage/snapshot-store.d.ts +19 -0
- package/dist/storage/snapshot-store.d.ts.map +1 -0
- package/dist/storage/snapshot-store.js +77 -0
- package/dist/structural-backend/codegraph-backend.d.ts +54 -0
- package/dist/structural-backend/codegraph-backend.d.ts.map +1 -0
- package/dist/structural-backend/codegraph-backend.js +1224 -0
- package/dist/structural-backend/codegraph-worker-client.d.ts +5 -0
- package/dist/structural-backend/codegraph-worker-client.d.ts.map +1 -0
- package/dist/structural-backend/codegraph-worker-client.js +118 -0
- package/dist/structural-backend/codegraph-worker-protocol.d.ts +35 -0
- package/dist/structural-backend/codegraph-worker-protocol.d.ts.map +1 -0
- package/dist/structural-backend/codegraph-worker-protocol.js +1 -0
- package/dist/structural-backend/codegraph-worker.d.ts +2 -0
- package/dist/structural-backend/codegraph-worker.d.ts.map +1 -0
- package/dist/structural-backend/codegraph-worker.js +131 -0
- package/dist/structural-backend/process-instance.d.ts +18 -0
- package/dist/structural-backend/process-instance.d.ts.map +1 -0
- package/dist/structural-backend/process-instance.js +207 -0
- package/dist/structural-backend/structural-fact-changes.d.ts +7 -0
- package/dist/structural-backend/structural-fact-changes.d.ts.map +1 -0
- package/dist/structural-backend/structural-fact-changes.js +78 -0
- package/dist/structural-backend/structural-publication.d.ts +12 -0
- package/dist/structural-backend/structural-publication.d.ts.map +1 -0
- package/dist/structural-backend/structural-publication.js +252 -0
- package/dist/structural-backend/structural-write-lock.d.ts +8 -0
- package/dist/structural-backend/structural-write-lock.d.ts.map +1 -0
- package/dist/structural-backend/structural-write-lock.js +415 -0
- package/dist/structural-backend/types.d.ts +144 -0
- package/dist/structural-backend/types.d.ts.map +1 -0
- package/dist/structural-backend/types.js +11 -0
- package/dist/world/types.d.ts +77 -0
- package/dist/world/types.d.ts.map +1 -0
- package/dist/world/types.js +1 -0
- package/dist/world/world-graph-query.d.ts +31 -0
- package/dist/world/world-graph-query.d.ts.map +1 -0
- package/dist/world/world-graph-query.js +453 -0
- package/dist/world/world-model-service.d.ts +21 -0
- package/dist/world/world-model-service.d.ts.map +1 -0
- package/dist/world/world-model-service.js +211 -0
- package/dist/world/world-snapshot-store.d.ts +40 -0
- package/dist/world/world-snapshot-store.d.ts.map +1 -0
- package/dist/world/world-snapshot-store.js +555 -0
- package/docs/architecture/codegraph-backend.md +193 -0
- package/docs/contracts/cli-v1.md +119 -0
- package/docs/contracts/graph-model.md +102 -0
- package/docs/contracts/graph-patch-v1.md +98 -0
- package/docs/evaluation.md +128 -0
- package/docs/product-contract.md +148 -0
- package/package.json +78 -0
- package/schemas/cli-envelope-v1.schema.json +1359 -0
- package/schemas/evaluation-plan-v1.schema.json +211 -0
- package/schemas/evaluation-run-v1.schema.json +365 -0
- package/schemas/graph-patch-v1.schema.json +392 -0
|
@@ -0,0 +1,453 @@
|
|
|
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 { GraphStore } from "../graph/graph-store.js";
|
|
54
|
+
import { CodeGraphStructuralBackend } from "../structural-backend/codegraph-backend.js";
|
|
55
|
+
import { WorldSnapshotStore } from "./world-snapshot-store.js";
|
|
56
|
+
export class WorldGraphQuery {
|
|
57
|
+
#repository;
|
|
58
|
+
#graph;
|
|
59
|
+
#structural;
|
|
60
|
+
#ownsGraph;
|
|
61
|
+
constructor(repository, graph, structural = new CodeGraphStructuralBackend(repository)) {
|
|
62
|
+
const dependencies = createDependencies(repository, graph, structural);
|
|
63
|
+
this.#repository = repository;
|
|
64
|
+
this.#graph = dependencies.graph;
|
|
65
|
+
this.#structural = dependencies.structural;
|
|
66
|
+
this.#ownsGraph = dependencies.ownsGraph;
|
|
67
|
+
}
|
|
68
|
+
async roots() {
|
|
69
|
+
return this.withCurrentWorld(async (snapshot) => {
|
|
70
|
+
const businessRoots = this.#graph.listCapabilityRoots(snapshot.snapshotId);
|
|
71
|
+
if (businessRoots.length > 0) {
|
|
72
|
+
return businessRoots;
|
|
73
|
+
}
|
|
74
|
+
return Promise.all((await this.#structural.listRoots())
|
|
75
|
+
.map((node) => this.structuralNode(node, snapshot)));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async children(reference) {
|
|
79
|
+
return this.withCurrentWorld(async (snapshot) => {
|
|
80
|
+
if (await this.getNode(reference, snapshot) === undefined) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const direction = reference.domain === "business" ? "incoming" : "outgoing";
|
|
84
|
+
const relationTypes = reference.domain === "business"
|
|
85
|
+
? ["part_of"]
|
|
86
|
+
: ["contains"];
|
|
87
|
+
return (await this.traverseSnapshot(reference, {
|
|
88
|
+
maxDepth: 1,
|
|
89
|
+
direction,
|
|
90
|
+
relationTypes,
|
|
91
|
+
}, snapshot)).neighbors.map(({ node }) => node);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async search(query, options = {}) {
|
|
95
|
+
const terms = lexicalTerms(query);
|
|
96
|
+
if (terms.length === 0) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
return this.withCurrentWorld(async (snapshot) => {
|
|
100
|
+
const limit = requireSearchLimit(options.limit);
|
|
101
|
+
const [businessResults, structuralResults] = await Promise.all([
|
|
102
|
+
Promise.resolve(this.#graph.search(query, { snapshotId: snapshot.snapshotId, limit })),
|
|
103
|
+
this.#structural.search({ query, limit }),
|
|
104
|
+
]);
|
|
105
|
+
const combined = [
|
|
106
|
+
...businessResults.map((result, index) => ({
|
|
107
|
+
score: reciprocalRank(index),
|
|
108
|
+
node: result.node,
|
|
109
|
+
})),
|
|
110
|
+
...await Promise.all(structuralResults.map(async (result, index) => ({
|
|
111
|
+
score: reciprocalRank(index),
|
|
112
|
+
node: await this.structuralNode(result.node, snapshot),
|
|
113
|
+
}))),
|
|
114
|
+
];
|
|
115
|
+
return uniqueSearchResults(combined)
|
|
116
|
+
.sort((left, right) => right.score - left.score || nodeIdentity(left.node).localeCompare(nodeIdentity(right.node)))
|
|
117
|
+
.slice(0, limit);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async show(reference, options = {}) {
|
|
121
|
+
return this.withCurrentWorld(async (snapshot) => {
|
|
122
|
+
const node = await this.getNode(reference, snapshot);
|
|
123
|
+
if (node === undefined) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const depth = requireTraversalDepth(options.maxDepth);
|
|
127
|
+
const traversal = await this.traverseSnapshot(reference, { maxDepth: depth }, snapshot);
|
|
128
|
+
return {
|
|
129
|
+
node,
|
|
130
|
+
depth,
|
|
131
|
+
neighbors: traversal.neighbors,
|
|
132
|
+
invariants: uniqueNodes(traversal.neighbors
|
|
133
|
+
.map(({ node: neighbor }) => neighbor)
|
|
134
|
+
.filter((neighbor) => (neighbor.domain === "business" && neighbor.kind === "Invariant"))),
|
|
135
|
+
tests: uniqueNodes(traversal.neighbors
|
|
136
|
+
.filter(({ relation }) => relation.type === "verified_by")
|
|
137
|
+
.map(({ node: neighbor }) => neighbor)
|
|
138
|
+
.filter((neighbor) => neighbor.domain === "structural")),
|
|
139
|
+
unknowns: traversal.unknowns,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
changes(options = {}) {
|
|
144
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
145
|
+
try {
|
|
146
|
+
const store = __addDisposableResource(env_1, new WorldSnapshotStore(this.#repository), false);
|
|
147
|
+
return store.readSemanticChanges(options);
|
|
148
|
+
}
|
|
149
|
+
catch (e_1) {
|
|
150
|
+
env_1.error = e_1;
|
|
151
|
+
env_1.hasError = true;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
__disposeResources(env_1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async traverse(start, options = {}) {
|
|
158
|
+
return this.withCurrentWorld((snapshot) => this.traverseSnapshot(start, options, snapshot));
|
|
159
|
+
}
|
|
160
|
+
async traverseSnapshot(start, options, snapshot) {
|
|
161
|
+
const maxDepth = requireTraversalDepth(options.maxDepth);
|
|
162
|
+
const direction = options.direction ?? "both";
|
|
163
|
+
const relationTypes = options.relationTypes === undefined
|
|
164
|
+
? undefined
|
|
165
|
+
: new Set(options.relationTypes);
|
|
166
|
+
const queue = [
|
|
167
|
+
{ reference: start, depth: 0 },
|
|
168
|
+
];
|
|
169
|
+
const visitedNodes = new Set([referenceIdentity(start)]);
|
|
170
|
+
const emittedRelations = new Set();
|
|
171
|
+
const emittedUnknowns = new Set();
|
|
172
|
+
const neighbors = [];
|
|
173
|
+
const unknowns = [];
|
|
174
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
175
|
+
const current = queue[index];
|
|
176
|
+
if (current.depth >= maxDepth) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const adjacent = await this.adjacent(current.reference, snapshot, direction);
|
|
180
|
+
for (const boundary of adjacent.unknowns) {
|
|
181
|
+
if (!emittedUnknowns.has(boundary.id)) {
|
|
182
|
+
emittedUnknowns.add(boundary.id);
|
|
183
|
+
unknowns.push(boundary);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const candidate of adjacent.neighbors) {
|
|
187
|
+
const relationKey = relationIdentity(candidate.relation);
|
|
188
|
+
if (emittedRelations.has(relationKey)
|
|
189
|
+
|| (relationTypes !== undefined && !relationTypes.has(candidate.relation.type))) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
emittedRelations.add(relationKey);
|
|
193
|
+
const depth = current.depth + 1;
|
|
194
|
+
neighbors.push({ ...candidate, depth });
|
|
195
|
+
const nextReference = referenceForNode(candidate.node);
|
|
196
|
+
const nextIdentity = referenceIdentity(nextReference);
|
|
197
|
+
if (!visitedNodes.has(nextIdentity)) {
|
|
198
|
+
visitedNodes.add(nextIdentity);
|
|
199
|
+
queue.push({ reference: nextReference, depth });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
neighbors: neighbors.sort(compareNeighbors),
|
|
205
|
+
unknowns: unknowns.sort((left, right) => left.id.localeCompare(right.id)),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
close() {
|
|
209
|
+
if (this.#ownsGraph) {
|
|
210
|
+
this.#graph.close();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
[Symbol.dispose]() {
|
|
214
|
+
this.close();
|
|
215
|
+
}
|
|
216
|
+
currentWorld() {
|
|
217
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
218
|
+
try {
|
|
219
|
+
const store = __addDisposableResource(env_2, new WorldSnapshotStore(this.#repository), false);
|
|
220
|
+
return store.requireCurrentWorld();
|
|
221
|
+
}
|
|
222
|
+
catch (e_2) {
|
|
223
|
+
env_2.error = e_2;
|
|
224
|
+
env_2.hasError = true;
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
__disposeResources(env_2);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async withCurrentWorld(query) {
|
|
231
|
+
const currentWorld = this.currentWorld();
|
|
232
|
+
const snapshot = currentWorld.snapshot;
|
|
233
|
+
const result = await query(snapshot);
|
|
234
|
+
const verifiedWorld = this.currentWorld();
|
|
235
|
+
if (verifiedWorld.publicationId !== currentWorld.publicationId) {
|
|
236
|
+
throw new Error(`World publication changed from ${currentWorld.publicationId} ` +
|
|
237
|
+
`to ${verifiedWorld.publicationId} during the query`);
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
async getNode(reference, snapshot) {
|
|
242
|
+
if (reference.domain === "business") {
|
|
243
|
+
return this.#graph.getNode(reference, snapshot.snapshotId);
|
|
244
|
+
}
|
|
245
|
+
const node = await this.#structural.getNode({ id: reference.id });
|
|
246
|
+
return node === undefined ? undefined : this.structuralNode(node, snapshot);
|
|
247
|
+
}
|
|
248
|
+
async adjacent(reference, snapshot, direction) {
|
|
249
|
+
const [business, structural] = await Promise.all([
|
|
250
|
+
this.businessAdjacency(reference, snapshot, direction),
|
|
251
|
+
reference.domain === "structural"
|
|
252
|
+
? this.structuralAdjacency(reference.id, snapshot, direction)
|
|
253
|
+
: Promise.resolve({ neighbors: [], unknowns: [] }),
|
|
254
|
+
]);
|
|
255
|
+
return {
|
|
256
|
+
neighbors: [...business, ...structural.neighbors],
|
|
257
|
+
unknowns: structural.unknowns,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
async businessAdjacency(reference, snapshot, direction) {
|
|
261
|
+
const result = [];
|
|
262
|
+
for (const relation of this.#graph.listBusinessRelations(snapshot.snapshotId)) {
|
|
263
|
+
const relationDirection = directionForRelation(reference, relation);
|
|
264
|
+
if (relationDirection === undefined || (direction !== "both" && direction !== relationDirection)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const otherReference = relationDirection === "outgoing" ? relation.to : relation.from;
|
|
268
|
+
const node = await this.getNode(otherReference, snapshot);
|
|
269
|
+
if (node !== undefined) {
|
|
270
|
+
result.push({ depth: 1, direction: relationDirection, relation, node });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
async structuralAdjacency(reference, snapshot, direction) {
|
|
276
|
+
const traversal = await this.#structural.traverse({
|
|
277
|
+
reference: { id: reference },
|
|
278
|
+
maxDepth: 1,
|
|
279
|
+
direction,
|
|
280
|
+
});
|
|
281
|
+
const nodes = new Map(traversal.nodes.map((node) => [node.reference.id, node]));
|
|
282
|
+
const neighbors = await Promise.all(traversal.relations.flatMap((relation) => {
|
|
283
|
+
const relationDirection = structuralRelationDirection(reference, relation);
|
|
284
|
+
if (relationDirection === undefined) {
|
|
285
|
+
return [];
|
|
286
|
+
}
|
|
287
|
+
const target = relationDirection === "outgoing" ? relation.to.id : relation.from.id;
|
|
288
|
+
const node = nodes.get(target);
|
|
289
|
+
if (node === undefined) {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
return [this.structuralNeighbor(relation, relationDirection, node, snapshot)];
|
|
293
|
+
}));
|
|
294
|
+
return {
|
|
295
|
+
neighbors,
|
|
296
|
+
unknowns: await Promise.all(traversal.boundaries.map((boundary) => (this.unknownBoundary(boundary, traversal, snapshot)))),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async structuralNeighbor(relation, direction, node, snapshot) {
|
|
300
|
+
return {
|
|
301
|
+
depth: 1,
|
|
302
|
+
direction,
|
|
303
|
+
relation: {
|
|
304
|
+
domain: "structural",
|
|
305
|
+
from: { domain: "structural", id: relation.from.id },
|
|
306
|
+
type: relation.type,
|
|
307
|
+
to: { domain: "structural", id: relation.to.id },
|
|
308
|
+
snapshotId: snapshot.snapshotId,
|
|
309
|
+
certainty: null,
|
|
310
|
+
validity: "valid",
|
|
311
|
+
evidence: [],
|
|
312
|
+
support: relation.support,
|
|
313
|
+
},
|
|
314
|
+
node: await this.structuralNode(node, snapshot),
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
async structuralNode(node, snapshot) {
|
|
318
|
+
return {
|
|
319
|
+
domain: "structural",
|
|
320
|
+
id: node.reference.id,
|
|
321
|
+
kind: node.kind,
|
|
322
|
+
label: node.name,
|
|
323
|
+
snapshotId: snapshot.snapshotId,
|
|
324
|
+
validity: "valid",
|
|
325
|
+
locations: node.virtual === true ? [] : [sourceLocation(node, snapshot)],
|
|
326
|
+
support: node.support,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
async unknownBoundary(boundary, traversal, snapshot) {
|
|
330
|
+
const owner = traversal.nodes.find((node) => node.reference.id === boundary.owner.id)
|
|
331
|
+
?? await this.#structural.getNode(boundary.owner);
|
|
332
|
+
const path = boundary.path ?? owner?.path;
|
|
333
|
+
const position = boundary.position ?? owner?.range.start;
|
|
334
|
+
if (path === undefined || position === undefined) {
|
|
335
|
+
throw new Error(`Unknown boundary ${boundary.reference.id} has no source owner`);
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
domain: "structural",
|
|
339
|
+
id: boundary.reference.id,
|
|
340
|
+
kind: "UnknownBoundary",
|
|
341
|
+
label: `${boundary.operation} unresolved`,
|
|
342
|
+
snapshotId: snapshot.snapshotId,
|
|
343
|
+
validity: "unknown",
|
|
344
|
+
owner: { domain: "structural", id: boundary.owner.id },
|
|
345
|
+
operation: boundary.operation,
|
|
346
|
+
reason: boundary.reason,
|
|
347
|
+
location: {
|
|
348
|
+
file: path,
|
|
349
|
+
range: { start: position, end: position },
|
|
350
|
+
contentHash: contentHashFor(path, snapshot),
|
|
351
|
+
},
|
|
352
|
+
candidates: boundary.candidates,
|
|
353
|
+
support: boundary.support,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function createDependencies(repository, graph, structural) {
|
|
358
|
+
return {
|
|
359
|
+
graph: graph ?? new GraphStore(repository),
|
|
360
|
+
structural,
|
|
361
|
+
ownsGraph: graph === undefined,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
function sourceLocation(node, snapshot) {
|
|
365
|
+
return {
|
|
366
|
+
file: node.path,
|
|
367
|
+
range: node.range,
|
|
368
|
+
contentHash: contentHashFor(node.path, snapshot),
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function contentHashFor(path, snapshot) {
|
|
372
|
+
const file = snapshot.files.find((candidate) => candidate.path === path);
|
|
373
|
+
if (file?.worktree === null || file?.worktree === undefined) {
|
|
374
|
+
throw new Error(`Structural source ${path} is absent from world snapshot ${snapshot.snapshotId}`);
|
|
375
|
+
}
|
|
376
|
+
return file.worktree.contentHash;
|
|
377
|
+
}
|
|
378
|
+
function directionForRelation(reference, relation) {
|
|
379
|
+
if (sameReference(reference, relation.from)) {
|
|
380
|
+
return "outgoing";
|
|
381
|
+
}
|
|
382
|
+
return sameReference(reference, relation.to) ? "incoming" : undefined;
|
|
383
|
+
}
|
|
384
|
+
function structuralRelationDirection(reference, relation) {
|
|
385
|
+
if (relation.from.id === reference) {
|
|
386
|
+
return "outgoing";
|
|
387
|
+
}
|
|
388
|
+
return relation.to.id === reference ? "incoming" : undefined;
|
|
389
|
+
}
|
|
390
|
+
function sameReference(left, right) {
|
|
391
|
+
return referenceIdentity(left) === referenceIdentity(right);
|
|
392
|
+
}
|
|
393
|
+
function referenceForNode(node) {
|
|
394
|
+
return node.domain === "business"
|
|
395
|
+
? { domain: "business", key: node.key }
|
|
396
|
+
: { domain: "structural", id: node.id };
|
|
397
|
+
}
|
|
398
|
+
function referenceIdentity(reference) {
|
|
399
|
+
return reference.domain === "business"
|
|
400
|
+
? `business:${reference.key}`
|
|
401
|
+
: `structural:${reference.id}`;
|
|
402
|
+
}
|
|
403
|
+
function nodeIdentity(node) {
|
|
404
|
+
return referenceIdentity(referenceForNode(node));
|
|
405
|
+
}
|
|
406
|
+
function relationIdentity(relation) {
|
|
407
|
+
return [
|
|
408
|
+
relation.domain,
|
|
409
|
+
referenceIdentity(relation.from),
|
|
410
|
+
relation.type,
|
|
411
|
+
referenceIdentity(relation.to),
|
|
412
|
+
].join("\0");
|
|
413
|
+
}
|
|
414
|
+
function compareNeighbors(left, right) {
|
|
415
|
+
return left.depth - right.depth
|
|
416
|
+
|| left.relation.type.localeCompare(right.relation.type)
|
|
417
|
+
|| nodeIdentity(left.node).localeCompare(nodeIdentity(right.node));
|
|
418
|
+
}
|
|
419
|
+
function uniqueSearchResults(results) {
|
|
420
|
+
const byNode = new Map();
|
|
421
|
+
for (const result of results) {
|
|
422
|
+
const identity = nodeIdentity(result.node);
|
|
423
|
+
const existing = byNode.get(identity);
|
|
424
|
+
if (existing === undefined || result.score > existing.score) {
|
|
425
|
+
byNode.set(identity, result);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return [...byNode.values()];
|
|
429
|
+
}
|
|
430
|
+
function uniqueNodes(nodes) {
|
|
431
|
+
return [...new Map(nodes.map((node) => [nodeIdentity(node), node])).values()]
|
|
432
|
+
.sort((left, right) => nodeIdentity(left).localeCompare(nodeIdentity(right)));
|
|
433
|
+
}
|
|
434
|
+
function reciprocalRank(index) {
|
|
435
|
+
return 1 / (index + 1);
|
|
436
|
+
}
|
|
437
|
+
function lexicalTerms(query) {
|
|
438
|
+
return query.toLowerCase().match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
439
|
+
}
|
|
440
|
+
function requireSearchLimit(limit) {
|
|
441
|
+
const resolved = limit ?? 20;
|
|
442
|
+
if (!Number.isInteger(resolved) || resolved < 1) {
|
|
443
|
+
throw new Error("World graph search limit must be a positive integer");
|
|
444
|
+
}
|
|
445
|
+
return resolved;
|
|
446
|
+
}
|
|
447
|
+
function requireTraversalDepth(depth) {
|
|
448
|
+
const resolved = depth ?? 1;
|
|
449
|
+
if (!Number.isInteger(resolved) || resolved < 1 || resolved > 3) {
|
|
450
|
+
throw new Error("World graph traversal depth must be an integer from 1 through 3");
|
|
451
|
+
}
|
|
452
|
+
return resolved;
|
|
453
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GitRepository } from "../repository/types.js";
|
|
2
|
+
import type { StructuralBuildResult } from "../structural-backend/types.js";
|
|
3
|
+
import type { RepositorySnapshot } from "../snapshots/types.js";
|
|
4
|
+
import type { IndexedSourceFile, WorldSnapshotState } from "./types.js";
|
|
5
|
+
export interface PublishedWorldSnapshot {
|
|
6
|
+
readonly snapshotId: string;
|
|
7
|
+
readonly structural: StructuralBuildResult;
|
|
8
|
+
readonly staleAssertions: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare class WorldModelService {
|
|
11
|
+
#private;
|
|
12
|
+
readonly repository: GitRepository;
|
|
13
|
+
constructor(repository: GitRepository);
|
|
14
|
+
build(): Promise<PublishedWorldSnapshot>;
|
|
15
|
+
sync(): Promise<PublishedWorldSnapshot>;
|
|
16
|
+
state(): WorldSnapshotState;
|
|
17
|
+
currentSnapshotId(): string;
|
|
18
|
+
private publish;
|
|
19
|
+
}
|
|
20
|
+
export declare function worldPublicationMismatch(indexedSnapshot: RepositorySnapshot, publishableSnapshot: RepositorySnapshot, indexedSources: readonly IndexedSourceFile[]): string | null;
|
|
21
|
+
//# sourceMappingURL=world-model-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world-model-service.d.ts","sourceRoot":"","sources":["../../src/world/world-model-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAS5D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAExE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,qBAAa,iBAAiB;;IAGhB,QAAQ,CAAC,UAAU,EAAE,aAAa;gBAAzB,UAAU,EAAE,aAAa;IAIxC,KAAK,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAIxC,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAI7C,KAAK,IAAI,kBAAkB;IAK3B,iBAAiB,IAAI,MAAM;YAKb,OAAO;CA+DtB;AAWD,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,kBAAkB,EACnC,mBAAmB,EAAE,kBAAkB,EACvC,cAAc,EAAE,SAAS,iBAAiB,EAAE,GAC3C,MAAM,GAAG,IAAI,CA6Bf"}
|
|
@@ -0,0 +1,211 @@
|
|
|
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 { createRepositorySnapshot } from "../snapshots/repository-snapshot.js";
|
|
54
|
+
import { isSupportedSource } from "../repository/repository-inspector.js";
|
|
55
|
+
import { CodeGraphStructuralBackend, } from "../structural-backend/codegraph-backend.js";
|
|
56
|
+
import { requiresBundledCodeGraphRuntime, runCodeGraphWorker, } from "../structural-backend/codegraph-worker-client.js";
|
|
57
|
+
import { WorldSnapshotStore } from "./world-snapshot-store.js";
|
|
58
|
+
export class WorldModelService {
|
|
59
|
+
repository;
|
|
60
|
+
#backend;
|
|
61
|
+
constructor(repository) {
|
|
62
|
+
this.repository = repository;
|
|
63
|
+
this.#backend = new CodeGraphStructuralBackend(repository);
|
|
64
|
+
}
|
|
65
|
+
async build() {
|
|
66
|
+
return this.publish("full");
|
|
67
|
+
}
|
|
68
|
+
async sync() {
|
|
69
|
+
return this.publish("incremental");
|
|
70
|
+
}
|
|
71
|
+
state() {
|
|
72
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
73
|
+
try {
|
|
74
|
+
const store = __addDisposableResource(env_1, new WorldSnapshotStore(this.repository), false);
|
|
75
|
+
return store.readState();
|
|
76
|
+
}
|
|
77
|
+
catch (e_1) {
|
|
78
|
+
env_1.error = e_1;
|
|
79
|
+
env_1.hasError = true;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
__disposeResources(env_1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
currentSnapshotId() {
|
|
86
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
87
|
+
try {
|
|
88
|
+
const store = __addDisposableResource(env_2, new WorldSnapshotStore(this.repository), false);
|
|
89
|
+
return store.requireCurrentSnapshot().snapshotId;
|
|
90
|
+
}
|
|
91
|
+
catch (e_2) {
|
|
92
|
+
env_2.error = e_2;
|
|
93
|
+
env_2.hasError = true;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
__disposeResources(env_2);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async publish(mode) {
|
|
100
|
+
if (requiresBundledCodeGraphRuntime()) {
|
|
101
|
+
return runCodeGraphWorker({
|
|
102
|
+
operation: mode === "full" ? "worldBuild" : "worldSync",
|
|
103
|
+
repository: this.repository,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
let snapshot;
|
|
107
|
+
let staleAssertions = [];
|
|
108
|
+
let previousSnapshotId = null;
|
|
109
|
+
const hooks = {
|
|
110
|
+
onBuilding: async () => {
|
|
111
|
+
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
112
|
+
try {
|
|
113
|
+
snapshot = await createRepositorySnapshot(this.repository);
|
|
114
|
+
const store = __addDisposableResource(env_3, new WorldSnapshotStore(this.repository), false);
|
|
115
|
+
previousSnapshotId = store.readState().currentSnapshotId;
|
|
116
|
+
store.begin(snapshot.snapshotId);
|
|
117
|
+
}
|
|
118
|
+
catch (e_3) {
|
|
119
|
+
env_3.error = e_3;
|
|
120
|
+
env_3.hasError = true;
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
__disposeResources(env_3);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
publish: async (structural, resolver, indexedSources) => {
|
|
127
|
+
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
128
|
+
try {
|
|
129
|
+
const indexedSnapshot = requireBuildSnapshot(snapshot);
|
|
130
|
+
const publishableSnapshot = await createRepositorySnapshot(this.repository);
|
|
131
|
+
const mismatch = worldPublicationMismatch(indexedSnapshot, publishableSnapshot, indexedSources);
|
|
132
|
+
if (mismatch !== null) {
|
|
133
|
+
throw new Error(`Repository changed during world publication: ${mismatch}`);
|
|
134
|
+
}
|
|
135
|
+
const store = __addDisposableResource(env_4, new WorldSnapshotStore(this.repository), false);
|
|
136
|
+
staleAssertions = store.publish(indexedSnapshot, structural.backendVersion, structural.extractionVersion, resolver, {
|
|
137
|
+
fromSnapshotId: previousSnapshotId,
|
|
138
|
+
toSnapshotId: indexedSnapshot.snapshotId,
|
|
139
|
+
structural: structural.changes,
|
|
140
|
+
}).staleAssertions;
|
|
141
|
+
}
|
|
142
|
+
catch (e_4) {
|
|
143
|
+
env_4.error = e_4;
|
|
144
|
+
env_4.hasError = true;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
__disposeResources(env_4);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
fail: (error) => {
|
|
151
|
+
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
152
|
+
try {
|
|
153
|
+
if (snapshot === undefined) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const store = __addDisposableResource(env_5, new WorldSnapshotStore(this.repository), false);
|
|
157
|
+
store.fail(snapshot.snapshotId, error);
|
|
158
|
+
}
|
|
159
|
+
catch (e_5) {
|
|
160
|
+
env_5.error = e_5;
|
|
161
|
+
env_5.hasError = true;
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
__disposeResources(env_5);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
const structural = await this.#backend.publishWorld(mode, hooks);
|
|
169
|
+
if (structural.completeness !== "complete") {
|
|
170
|
+
throw new Error(structural.diagnostics[0]?.message ?? "The structural index did not complete");
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
snapshotId: requireBuildSnapshot(snapshot).snapshotId,
|
|
174
|
+
structural,
|
|
175
|
+
staleAssertions,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function requireBuildSnapshot(snapshot) {
|
|
180
|
+
if (snapshot === undefined) {
|
|
181
|
+
throw new Error("World publication did not capture a repository snapshot");
|
|
182
|
+
}
|
|
183
|
+
return snapshot;
|
|
184
|
+
}
|
|
185
|
+
export function worldPublicationMismatch(indexedSnapshot, publishableSnapshot, indexedSources) {
|
|
186
|
+
if (publishableSnapshot.snapshotId !== indexedSnapshot.snapshotId) {
|
|
187
|
+
return `indexed ${indexedSnapshot.snapshotId}, current ${publishableSnapshot.snapshotId}`;
|
|
188
|
+
}
|
|
189
|
+
const indexedHashes = new Map(indexedSources.map((file) => [file.path, file.contentHash]));
|
|
190
|
+
for (const file of indexedSnapshot.files) {
|
|
191
|
+
if (!isSupportedSource(file.path) || file.worktree === null) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const indexedHash = indexedHashes.get(file.path);
|
|
195
|
+
if (indexedHash === undefined) {
|
|
196
|
+
return `snapshot source ${file.path} is missing from the structural index`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const snapshotHashes = new Map(indexedSnapshot.files.map((file) => [file.path, file.worktree?.contentHash]));
|
|
200
|
+
for (const file of indexedSources) {
|
|
201
|
+
if (!isSupportedSource(file.path)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const snapshotHash = snapshotHashes.get(file.path);
|
|
205
|
+
if (snapshotHash !== file.contentHash) {
|
|
206
|
+
return `indexed source ${file.path} has ${file.contentHash}, ` +
|
|
207
|
+
`snapshot has ${snapshotHash ?? "no content"}`;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|