semantic-atlas 0.1.4 → 0.3.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.
Files changed (84) hide show
  1. package/.agents/skills/semantic-atlas/SKILL.md +62 -43
  2. package/.agents/skills/semantic-atlas/references/graph-patch.md +22 -5
  3. package/.agents/skills/semantic-atlas/references/product-feedback.md +34 -0
  4. package/.agents/skills/semantic-atlas/references/result-routing.md +32 -19
  5. package/.agents/skills/semantic-atlas/references/snapshot-bootstrap.md +17 -32
  6. package/.agents/skills/semantic-atlas-insights/SKILL.md +55 -0
  7. package/README.md +209 -80
  8. package/README.zh-CN.md +187 -81
  9. package/dist/cli/argument-parser.js +49 -23
  10. package/dist/cli/bin.js +16 -3
  11. package/dist/cli/cli-application.d.ts +3 -2
  12. package/dist/cli/cli-application.d.ts.map +1 -1
  13. package/dist/cli/cli-application.js +104 -48
  14. package/dist/cli/insights-cli.d.ts +6 -0
  15. package/dist/cli/insights-cli.d.ts.map +1 -0
  16. package/dist/cli/insights-cli.js +236 -0
  17. package/dist/cli/main.d.ts.map +1 -1
  18. package/dist/cli/main.js +94 -2
  19. package/dist/cli/standalone-cli.d.ts +3 -0
  20. package/dist/cli/standalone-cli.d.ts.map +1 -0
  21. package/dist/cli/standalone-cli.js +96 -0
  22. package/dist/cli/types.d.ts +9 -6
  23. package/dist/cli/types.d.ts.map +1 -1
  24. package/dist/contracts/cli.d.ts +473 -1400
  25. package/dist/contracts/cli.d.ts.map +1 -1
  26. package/dist/contracts/cli.js +65 -65
  27. package/dist/contracts/graph.d.ts +4 -0
  28. package/dist/contracts/graph.d.ts.map +1 -1
  29. package/dist/contracts/graph.js +2 -2
  30. package/dist/contracts/insights.d.ts +2 -0
  31. package/dist/contracts/insights.d.ts.map +1 -0
  32. package/dist/contracts/insights.js +1 -0
  33. package/dist/contracts/public-contracts.d.ts +1 -0
  34. package/dist/contracts/public-contracts.d.ts.map +1 -1
  35. package/dist/contracts/public-contracts.js +1 -0
  36. package/dist/evaluation/contracts.d.ts +11 -2
  37. package/dist/evaluation/contracts.d.ts.map +1 -1
  38. package/dist/evaluation/contracts.js +7 -2
  39. package/dist/graph/graph-store.d.ts +3 -1
  40. package/dist/graph/graph-store.d.ts.map +1 -1
  41. package/dist/graph/graph-store.js +48 -2
  42. package/dist/graph/types.d.ts +30 -9
  43. package/dist/graph/types.d.ts.map +1 -1
  44. package/dist/index.d.ts +0 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/insights/contracts.d.ts +266 -0
  47. package/dist/insights/contracts.d.ts.map +1 -0
  48. package/dist/insights/contracts.js +124 -0
  49. package/dist/insights/insights-store.d.ts +73 -0
  50. package/dist/insights/insights-store.d.ts.map +1 -0
  51. package/dist/insights/insights-store.js +246 -0
  52. package/dist/package-metadata.d.ts +2 -0
  53. package/dist/package-metadata.d.ts.map +1 -0
  54. package/dist/package-metadata.js +9 -0
  55. package/dist/setup/package-upgrader.d.ts +54 -0
  56. package/dist/setup/package-upgrader.d.ts.map +1 -0
  57. package/dist/setup/package-upgrader.js +169 -0
  58. package/dist/setup/skill-installer.d.ts +20 -0
  59. package/dist/setup/skill-installer.d.ts.map +1 -0
  60. package/dist/setup/skill-installer.js +187 -0
  61. package/dist/storage/atlas-database.d.ts +1 -0
  62. package/dist/storage/atlas-database.d.ts.map +1 -1
  63. package/dist/storage/atlas-database.js +13 -6
  64. package/dist/world/business-map-projector.d.ts +14 -0
  65. package/dist/world/business-map-projector.d.ts.map +1 -0
  66. package/dist/world/business-map-projector.js +178 -0
  67. package/dist/world/world-graph-query.d.ts +8 -13
  68. package/dist/world/world-graph-query.d.ts.map +1 -1
  69. package/dist/world/world-graph-query.js +26 -229
  70. package/docs/README.md +30 -0
  71. package/docs/architecture/codegraph-backend.md +2 -2
  72. package/docs/architecture/continuous-business-learning.md +240 -0
  73. package/docs/contracts/cli-v1.md +62 -18
  74. package/docs/contracts/graph-model.md +11 -7
  75. package/docs/contracts/graph-patch-v1.md +8 -1
  76. package/docs/contracts/insights-v1.md +84 -0
  77. package/docs/evaluation.md +20 -15
  78. package/docs/index.md +43 -0
  79. package/docs/log.md +80 -0
  80. package/docs/product-contract.md +24 -12
  81. package/package.json +3 -1
  82. package/schemas/cli-envelope-v1.schema.json +450 -565
  83. package/schemas/evaluation-run-v1.schema.json +4 -1
  84. package/schemas/insights-envelope-v1.schema.json +428 -0
@@ -0,0 +1,187 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { access, cp, mkdir, readFile, readdir, rename, rm, writeFile, } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join, relative } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ const skillName = "semantic-atlas";
7
+ const insightsSkillName = "semantic-atlas-insights";
8
+ const installationMarkerName = ".semantic-atlas-managed.json";
9
+ export class SkillInstaller {
10
+ #sourceDirectory;
11
+ #targetDirectory;
12
+ #insightsSourceDirectory;
13
+ #insightsTargetDirectory;
14
+ #legacyDirectories;
15
+ #version;
16
+ constructor(options) {
17
+ const userHome = options.userHome ?? homedir();
18
+ this.#sourceDirectory = options.sourceDirectory ?? resolveBundledSkillDirectory();
19
+ this.#targetDirectory = join(userHome, ".agents", "skills", skillName);
20
+ this.#insightsSourceDirectory = options.insightsSourceDirectory
21
+ ?? resolveBundledSkillDirectory(insightsSkillName);
22
+ this.#insightsTargetDirectory = join(userHome, ".agents", "skills", insightsSkillName);
23
+ this.#legacyDirectories = [join(userHome, ".codex", "skills", skillName)];
24
+ this.#version = options.version;
25
+ }
26
+ async install() {
27
+ await requireSemanticAtlasSkill(this.#sourceDirectory, "bundled Skill");
28
+ await requireManagedSkill(this.#insightsSourceDirectory, insightsSkillName, "bundled insights Skill");
29
+ const targetExists = await exists(this.#targetDirectory);
30
+ if (targetExists) {
31
+ await requireSemanticAtlasSkill(this.#targetDirectory, "existing shared Skill");
32
+ }
33
+ const insightsTargetExists = await exists(this.#insightsTargetDirectory);
34
+ if (insightsTargetExists) {
35
+ await requireManagedSkill(this.#insightsTargetDirectory, insightsSkillName, "existing shared insights Skill");
36
+ }
37
+ const existingLegacyDirectories = await this.existingLegacyDirectories();
38
+ for (const directory of existingLegacyDirectories) {
39
+ await requireSemanticAtlasSkill(directory, "legacy Codex Skill");
40
+ }
41
+ const sourceFingerprint = await fingerprintSkill(this.#sourceDirectory);
42
+ const targetCurrent = targetExists
43
+ && await installedSkillIsCurrent(this.#targetDirectory, this.#version, sourceFingerprint);
44
+ if (!targetCurrent || existingLegacyDirectories.length > 0) {
45
+ await installSkillAtomically(this.#sourceDirectory, this.#targetDirectory, { version: this.#version, fingerprint: sourceFingerprint });
46
+ }
47
+ const insights = await installManagedSkill({
48
+ sourceDirectory: this.#insightsSourceDirectory,
49
+ targetDirectory: this.#insightsTargetDirectory,
50
+ version: this.#version,
51
+ });
52
+ for (const directory of existingLegacyDirectories) {
53
+ await rm(directory, { recursive: true, force: true });
54
+ }
55
+ return {
56
+ outcome: targetCurrent && insights === "current" && existingLegacyDirectories.length === 0
57
+ ? "current"
58
+ : targetExists || insightsTargetExists
59
+ ? "updated"
60
+ : "installed",
61
+ targetDirectory: this.#targetDirectory,
62
+ insightsTargetDirectory: this.#insightsTargetDirectory,
63
+ removedLegacyDirectories: existingLegacyDirectories,
64
+ };
65
+ }
66
+ async existingLegacyDirectories() {
67
+ const result = [];
68
+ for (const directory of this.#legacyDirectories) {
69
+ if (await exists(directory)) {
70
+ result.push(directory);
71
+ }
72
+ }
73
+ return result;
74
+ }
75
+ }
76
+ export function resolveBundledSkillDirectory(name = skillName) {
77
+ const moduleDirectory = dirname(fileURLToPath(import.meta.url));
78
+ return join(moduleDirectory, "..", "..", ".agents", "skills", name);
79
+ }
80
+ async function installedSkillIsCurrent(directory, version, sourceFingerprint) {
81
+ const marker = await readInstallationMarker(join(directory, installationMarkerName));
82
+ if (marker?.version !== version || marker.fingerprint !== sourceFingerprint) {
83
+ return false;
84
+ }
85
+ return await fingerprintSkill(directory) === sourceFingerprint;
86
+ }
87
+ async function requireSemanticAtlasSkill(directory, description) {
88
+ return requireManagedSkill(directory, skillName, description);
89
+ }
90
+ async function requireManagedSkill(directory, name, description) {
91
+ let contents;
92
+ try {
93
+ contents = await readFile(join(directory, "SKILL.md"), "utf8");
94
+ }
95
+ catch {
96
+ throw new Error(`Refusing to replace ${description} at ${directory}: SKILL.md is missing`);
97
+ }
98
+ const escapedName = name.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
99
+ const namePattern = new RegExp(`^---\\r?\\n[\\s\\S]*?^name:\\s*["']?${escapedName}["']?\\s*$[\\s\\S]*?^---\\s*$`, "mu");
100
+ if (!namePattern.test(contents)) {
101
+ throw new Error(`Refusing to replace unrelated Skill at ${directory}`);
102
+ }
103
+ }
104
+ async function installManagedSkill(options) {
105
+ const targetExists = await exists(options.targetDirectory);
106
+ const fingerprint = await fingerprintSkill(options.sourceDirectory);
107
+ const current = targetExists && await installedSkillIsCurrent(options.targetDirectory, options.version, fingerprint);
108
+ if (current)
109
+ return "current";
110
+ await installSkillAtomically(options.sourceDirectory, options.targetDirectory, {
111
+ version: options.version,
112
+ fingerprint,
113
+ });
114
+ return targetExists ? "updated" : "installed";
115
+ }
116
+ async function installSkillAtomically(sourceDirectory, targetDirectory, marker) {
117
+ const parent = dirname(targetDirectory);
118
+ const token = `${process.pid}-${randomUUID()}`;
119
+ const temporary = `${targetDirectory}.installing-${token}`;
120
+ const backup = `${targetDirectory}.backup-${token}`;
121
+ const targetExists = await exists(targetDirectory);
122
+ await mkdir(parent, { recursive: true });
123
+ await rm(temporary, { recursive: true, force: true });
124
+ await rm(backup, { recursive: true, force: true });
125
+ await cp(sourceDirectory, temporary, { recursive: true });
126
+ await writeFile(join(temporary, installationMarkerName), `${JSON.stringify(marker, null, 2)}\n`, "utf8");
127
+ if (targetExists)
128
+ await rename(targetDirectory, backup);
129
+ try {
130
+ await rename(temporary, targetDirectory);
131
+ }
132
+ catch (error) {
133
+ if (targetExists)
134
+ await rename(backup, targetDirectory);
135
+ throw error;
136
+ }
137
+ await rm(backup, { recursive: true, force: true });
138
+ }
139
+ async function readInstallationMarker(path) {
140
+ try {
141
+ const parsed = JSON.parse(await readFile(path, "utf8"));
142
+ return typeof parsed.version === "string" && /^[a-f0-9]{64}$/u.test(parsed.fingerprint ?? "")
143
+ ? { version: parsed.version, fingerprint: parsed.fingerprint }
144
+ : undefined;
145
+ }
146
+ catch (error) {
147
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
148
+ return undefined;
149
+ }
150
+ return undefined;
151
+ }
152
+ }
153
+ async function fingerprintSkill(directory) {
154
+ const hash = createHash("sha256");
155
+ for (const path of await listFiles(directory)) {
156
+ const relativePath = relative(directory, path);
157
+ hash.update(relativePath);
158
+ hash.update("\0");
159
+ hash.update(await readFile(path));
160
+ hash.update("\0");
161
+ }
162
+ return hash.digest("hex");
163
+ }
164
+ async function listFiles(directory) {
165
+ const result = [];
166
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
167
+ if (entry.name === installationMarkerName) {
168
+ continue;
169
+ }
170
+ const path = join(directory, entry.name);
171
+ if (entry.isDirectory()) {
172
+ result.push(...await listFiles(path));
173
+ }
174
+ else {
175
+ result.push(path);
176
+ }
177
+ }
178
+ return result.sort();
179
+ }
180
+ async function exists(path) {
181
+ return access(path).then(() => true, (error) => {
182
+ if (error.code === "ENOENT") {
183
+ return false;
184
+ }
185
+ throw error;
186
+ });
187
+ }
@@ -14,5 +14,6 @@ export declare class AtlasDatabase implements Disposable {
14
14
  private registerRepository;
15
15
  }
16
16
  export declare function resolveAtlasHome(repository: GitRepository): string;
17
+ export declare function resolveInsightsDatabasePath(): string;
17
18
  export declare function resolveAtlasDatabasePath(repository: GitRepository): string;
18
19
  //# sourceMappingURL=atlas-database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"atlas-database.d.ts","sourceRoot":"","sources":["../../src/storage/atlas-database.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB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AqC3B;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,MAAM,CASlE;AAED,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAeD,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,aAAa,GAAG,MAAM,CAQ1E"}
@@ -111,6 +111,19 @@ export class AtlasDatabase {
111
111
  }
112
112
  }
113
113
  export function resolveAtlasHome(repository) {
114
+ const realAtlasHome = resolveConfiguredAtlasHome();
115
+ for (const worktreeRoot of repository.worktreeRoots) {
116
+ const realWorktreeRoot = realpathExistingPath(worktreeRoot);
117
+ if (realWorktreeRoot !== null && isPathInside(realAtlasHome, realWorktreeRoot)) {
118
+ throw new Error("The Semantic Atlas home must be outside every repository worktree");
119
+ }
120
+ }
121
+ return realAtlasHome;
122
+ }
123
+ export function resolveInsightsDatabasePath() {
124
+ return join(resolveConfiguredAtlasHome(), "insights.db");
125
+ }
126
+ function resolveConfiguredAtlasHome() {
114
127
  const configuredHome = process.env[SEMANTIC_ATLAS_HOME_ENVIRONMENT_VARIABLE];
115
128
  if (configuredHome !== undefined && !isAbsolute(configuredHome)) {
116
129
  throw new Error(`${SEMANTIC_ATLAS_HOME_ENVIRONMENT_VARIABLE} must be an absolute path`);
@@ -119,12 +132,6 @@ export function resolveAtlasHome(repository) {
119
132
  mkdirSync(atlasHome, { recursive: true, mode: 0o700 });
120
133
  requireRealDirectory(atlasHome, "The Semantic Atlas home");
121
134
  const realAtlasHome = realpathSync(atlasHome);
122
- for (const worktreeRoot of repository.worktreeRoots) {
123
- const realWorktreeRoot = realpathExistingPath(worktreeRoot);
124
- if (realWorktreeRoot !== null && isPathInside(realAtlasHome, realWorktreeRoot)) {
125
- throw new Error("The Semantic Atlas home must be outside every repository worktree");
126
- }
127
- }
128
135
  return realAtlasHome;
129
136
  }
130
137
  export function resolveAtlasDatabasePath(repository) {
@@ -0,0 +1,14 @@
1
+ import type { BusinessGraphNode, BusinessGraphRelation, BusinessMapView } from "../graph/types.js";
2
+ export declare class BusinessMapProjector {
3
+ #private;
4
+ constructor(nodes: readonly BusinessGraphNode[], relations: readonly BusinessGraphRelation[]);
5
+ project(focusKey?: string): BusinessMapView | undefined;
6
+ private rootKeys;
7
+ private pathFromRoot;
8
+ private touchesSubtree;
9
+ private isDescendantOrSelf;
10
+ private projectEndpoint;
11
+ private addContextRegion;
12
+ private addRegion;
13
+ }
14
+ //# sourceMappingURL=business-map-projector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"business-map-projector.d.ts","sourceRoot":"","sources":["../../src/world/business-map-projector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EAKrB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAuB3B,qBAAa,oBAAoB;;gBAO7B,KAAK,EAAE,SAAS,iBAAiB,EAAE,EACnC,SAAS,EAAE,SAAS,qBAAqB,EAAE;IAY7C,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IA2CvD,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,SAAS;CAYlB"}
@@ -0,0 +1,178 @@
1
+ export class BusinessMapProjector {
2
+ #nodes;
3
+ #parentByChild;
4
+ #childrenByParent;
5
+ #relations;
6
+ constructor(nodes, relations) {
7
+ this.#nodes = new Map(nodes.map((node) => [node.key, node]));
8
+ this.#parentByChild = new Map(relations.flatMap((relation) => (relation.type === "part_of" && relation.to.domain === "business"
9
+ ? [[relation.from.key, relation.to.key]]
10
+ : [])));
11
+ this.#childrenByParent = childrenByParent(this.#parentByChild);
12
+ this.#relations = relations;
13
+ }
14
+ project(focusKey) {
15
+ const focus = focusKey === undefined ? null : this.#nodes.get(focusKey);
16
+ if (focus === undefined) {
17
+ return undefined;
18
+ }
19
+ const breadcrumbs = focus === null ? [] : this.pathFromRoot(focus.key);
20
+ const regions = new Map();
21
+ const visibleKeys = focus === null
22
+ ? this.rootKeys()
23
+ : this.#childrenByParent.get(focus.key) ?? [];
24
+ const role = focus === null ? "root" : "child";
25
+ visibleKeys.forEach((key) => this.addRegion(regions, key, role));
26
+ const connections = new Map();
27
+ for (const relation of this.#relations) {
28
+ if (!isMapRelation(relation)) {
29
+ continue;
30
+ }
31
+ if (focus !== null && !this.touchesSubtree(relation, focus.key)) {
32
+ continue;
33
+ }
34
+ const projectedFrom = this.projectEndpoint(relation.from.key, focus, breadcrumbs);
35
+ const projectedTo = this.projectEndpoint(relation.to.key, focus, breadcrumbs);
36
+ if (projectedFrom === projectedTo) {
37
+ continue;
38
+ }
39
+ this.addContextRegion(regions, projectedFrom, focus);
40
+ this.addContextRegion(regions, projectedTo, focus);
41
+ const direct = projectedFrom === relation.from.key && projectedTo === relation.to.key;
42
+ addConnectionContribution(connections, projectedFrom, projectedTo, relation, direct);
43
+ }
44
+ return {
45
+ focus,
46
+ breadcrumbs,
47
+ regions: [...regions.values()].sort(compareRegions),
48
+ connections: presentConnections(connections),
49
+ };
50
+ }
51
+ rootKeys() {
52
+ return [...this.#nodes.keys()]
53
+ .filter((key) => !this.#parentByChild.has(key))
54
+ .sort((left, right) => left.localeCompare(right));
55
+ }
56
+ pathFromRoot(key) {
57
+ const path = [];
58
+ let current = key;
59
+ while (current !== undefined) {
60
+ const node = this.#nodes.get(current);
61
+ if (node === undefined) {
62
+ break;
63
+ }
64
+ path.push(node);
65
+ current = this.#parentByChild.get(current);
66
+ }
67
+ return path.reverse();
68
+ }
69
+ touchesSubtree(relation, focusKey) {
70
+ return this.isDescendantOrSelf(relation.from.key, focusKey)
71
+ || (relation.to.domain === "business" && this.isDescendantOrSelf(relation.to.key, focusKey));
72
+ }
73
+ isDescendantOrSelf(key, ancestorKey) {
74
+ let current = key;
75
+ while (current !== undefined) {
76
+ if (current === ancestorKey) {
77
+ return true;
78
+ }
79
+ current = this.#parentByChild.get(current);
80
+ }
81
+ return false;
82
+ }
83
+ projectEndpoint(key, focus, focusPath) {
84
+ const endpointPath = this.pathFromRoot(key);
85
+ if (focus === null) {
86
+ return endpointPath[0]?.key ?? key;
87
+ }
88
+ if (this.isDescendantOrSelf(key, focus.key)) {
89
+ if (key === focus.key) {
90
+ return key;
91
+ }
92
+ const focusIndex = endpointPath.findIndex((node) => node.key === focus.key);
93
+ return endpointPath[focusIndex + 1]?.key ?? key;
94
+ }
95
+ const commonLength = sharedPrefixLength(focusPath, endpointPath);
96
+ return endpointPath[commonLength]?.key ?? key;
97
+ }
98
+ addContextRegion(regions, key, focus) {
99
+ if (key !== focus?.key && !regions.has(key)) {
100
+ this.addRegion(regions, key, "context");
101
+ }
102
+ }
103
+ addRegion(regions, key, role) {
104
+ const node = this.#nodes.get(key);
105
+ if (node === undefined) {
106
+ return;
107
+ }
108
+ const childCount = this.#childrenByParent.get(key)?.length ?? 0;
109
+ regions.set(key, { node, role, childCount, expandable: childCount > 0 });
110
+ }
111
+ }
112
+ function childrenByParent(parentByChild) {
113
+ const result = new Map();
114
+ for (const [child, parent] of parentByChild) {
115
+ const children = result.get(parent) ?? [];
116
+ children.push(child);
117
+ result.set(parent, children);
118
+ }
119
+ result.forEach((children) => children.sort((left, right) => left.localeCompare(right)));
120
+ return result;
121
+ }
122
+ function isMapRelation(relation) {
123
+ return relation.to.domain === "business"
124
+ && relation.type !== "part_of"
125
+ && relation.type !== "realized_by"
126
+ && relation.type !== "verified_by";
127
+ }
128
+ function sharedPrefixLength(left, right) {
129
+ let length = 0;
130
+ while (length < left.length && length < right.length && left[length].key === right[length].key) {
131
+ length += 1;
132
+ }
133
+ return length;
134
+ }
135
+ function addConnectionContribution(connections, fromKey, toKey, relation, direct) {
136
+ const connectionKey = `${fromKey}\0${toKey}`;
137
+ const connection = connections.get(connectionKey) ?? {
138
+ fromKey,
139
+ toKey,
140
+ relations: new Map(),
141
+ };
142
+ connections.set(connectionKey, connection);
143
+ const summary = connection.relations.get(relation.type) ?? emptySummary(relation.type);
144
+ connection.relations.set(relation.type, summary);
145
+ if (direct) {
146
+ summary.directCount += 1;
147
+ }
148
+ else {
149
+ summary.aggregatedCount += 1;
150
+ }
151
+ summary.certainty[relation.certainty] += 1;
152
+ summary.validity[relation.validity] += 1;
153
+ }
154
+ function emptySummary(type) {
155
+ return {
156
+ type,
157
+ directCount: 0,
158
+ aggregatedCount: 0,
159
+ certainty: { exact: 0, inferred: 0, hypothesis: 0 },
160
+ validity: { valid: 0, stale: 0 },
161
+ };
162
+ }
163
+ function compareRegions(left, right) {
164
+ const leftRank = left.role === "context" ? 1 : 0;
165
+ const rightRank = right.role === "context" ? 1 : 0;
166
+ return leftRank - rightRank || left.node.key.localeCompare(right.node.key);
167
+ }
168
+ function presentConnections(connections) {
169
+ return [...connections.values()]
170
+ .sort((left, right) => (left.fromKey.localeCompare(right.fromKey) || left.toKey.localeCompare(right.toKey)))
171
+ .map((connection) => ({
172
+ from: { domain: "business", key: connection.fromKey },
173
+ to: { domain: "business", key: connection.toKey },
174
+ relations: [...connection.relations.values()]
175
+ .sort((left, right) => left.type.localeCompare(right.type))
176
+ .map((relation) => relation),
177
+ }));
178
+ }
@@ -1,31 +1,26 @@
1
1
  import type { GitRepository } from "../repository/types.js";
2
2
  import { GraphStore } from "../graph/graph-store.js";
3
- import type { BusinessGraphNode, GraphNode, GraphNodeReference, GraphSearchResult, GraphTraversalOptions, StructuralGraphNode, WorldGraphTraversalResult, WorldGraphView } from "../graph/types.js";
3
+ import type { BusinessGraphView, BusinessGraphNode, BusinessMapView, GraphSearchResult, StructuralGraphNode } from "../graph/types.js";
4
4
  import type { StructuralIndexBackend } from "../structural-backend/types.js";
5
5
  import type { SemanticGraphChangeOptions, SemanticGraphChanges } from "./types.js";
6
- export type WorldGraphTraversalOptions = Omit<GraphTraversalOptions, "snapshotId">;
7
6
  export declare class WorldGraphQuery implements Disposable {
8
7
  #private;
9
8
  constructor(repository: GitRepository, graph?: GraphStore, structural?: StructuralIndexBackend);
10
- roots(): Promise<readonly (BusinessGraphNode | StructuralGraphNode)[]>;
11
- children(reference: GraphNodeReference): Promise<readonly GraphNode[] | undefined>;
12
- search(query: string, options?: {
9
+ view(focusKey?: string): Promise<BusinessMapView | undefined>;
10
+ searchBusiness(query: string, options?: {
13
11
  readonly limit?: number;
14
- }): Promise<readonly GraphSearchResult[]>;
15
- show(reference: GraphNodeReference, options?: Pick<WorldGraphTraversalOptions, "maxDepth">): Promise<WorldGraphView | undefined>;
12
+ }): Promise<readonly GraphSearchResult<BusinessGraphNode>[]>;
13
+ searchCode(query: string, options?: {
14
+ readonly limit?: number;
15
+ }): Promise<readonly GraphSearchResult<StructuralGraphNode>[]>;
16
+ showBusiness(key: string): Promise<BusinessGraphView | undefined>;
16
17
  changes(options?: SemanticGraphChangeOptions): SemanticGraphChanges | undefined;
17
- traverse(start: GraphNodeReference, options?: WorldGraphTraversalOptions): Promise<WorldGraphTraversalResult>;
18
- private traverseSnapshot;
19
18
  close(): void;
20
19
  [Symbol.dispose](): void;
21
20
  private currentWorld;
22
21
  private withCurrentWorld;
23
22
  private getNode;
24
- private adjacent;
25
23
  private businessAdjacency;
26
- private structuralAdjacency;
27
- private structuralNeighbor;
28
24
  private structuralNode;
29
- private unknownBoundary;
30
25
  }
31
26
  //# sourceMappingURL=world-graph-query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"world-graph-query.d.ts","sourceRoot":"","sources":["../../src/world/world-graph-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EACV,iBAAiB,EAGjB,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EAGnB,yBAAyB,EACzB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,O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