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.
Files changed (175) hide show
  1. package/.agents/skills/semantic-atlas/SKILL.md +172 -0
  2. package/.agents/skills/semantic-atlas/references/graph-patch.md +109 -0
  3. package/.agents/skills/semantic-atlas/references/result-routing.md +91 -0
  4. package/LICENSE +21 -0
  5. package/README.md +118 -0
  6. package/dist/business-flow/business-flow-derivation-service.d.ts +11 -0
  7. package/dist/business-flow/business-flow-derivation-service.d.ts.map +1 -0
  8. package/dist/business-flow/business-flow-derivation-service.js +151 -0
  9. package/dist/business-flow/business-flow-draft.d.ts +16 -0
  10. package/dist/business-flow/business-flow-draft.d.ts.map +1 -0
  11. package/dist/business-flow/business-flow-draft.js +150 -0
  12. package/dist/business-flow/framework-business-strategy.d.ts +7 -0
  13. package/dist/business-flow/framework-business-strategy.d.ts.map +1 -0
  14. package/dist/business-flow/framework-business-strategy.js +1 -0
  15. package/dist/business-flow/strategies/bullmq-business-strategy.d.ts +10 -0
  16. package/dist/business-flow/strategies/bullmq-business-strategy.d.ts.map +1 -0
  17. package/dist/business-flow/strategies/bullmq-business-strategy.js +79 -0
  18. package/dist/business-flow/strategies/called-operation-derivation.d.ts +13 -0
  19. package/dist/business-flow/strategies/called-operation-derivation.d.ts.map +1 -0
  20. package/dist/business-flow/strategies/called-operation-derivation.js +32 -0
  21. package/dist/business-flow/strategies/graphql-business-strategy.d.ts +8 -0
  22. package/dist/business-flow/strategies/graphql-business-strategy.d.ts.map +1 -0
  23. package/dist/business-flow/strategies/graphql-business-strategy.js +65 -0
  24. package/dist/business-flow/strategies/nestjs-business-strategy.d.ts +8 -0
  25. package/dist/business-flow/strategies/nestjs-business-strategy.d.ts.map +1 -0
  26. package/dist/business-flow/strategies/nestjs-business-strategy.js +72 -0
  27. package/dist/business-flow/strategies/strategy-helpers.d.ts +32 -0
  28. package/dist/business-flow/strategies/strategy-helpers.d.ts.map +1 -0
  29. package/dist/business-flow/strategies/strategy-helpers.js +49 -0
  30. package/dist/business-flow/strategies/typeorm-business-strategy.d.ts +10 -0
  31. package/dist/business-flow/strategies/typeorm-business-strategy.d.ts.map +1 -0
  32. package/dist/business-flow/strategies/typeorm-business-strategy.js +136 -0
  33. package/dist/business-flow/strategies/verified-invariant-strategy.d.ts +5 -0
  34. package/dist/business-flow/strategies/verified-invariant-strategy.d.ts.map +1 -0
  35. package/dist/business-flow/strategies/verified-invariant-strategy.js +38 -0
  36. package/dist/business-flow/strategies/verified-test-strategy.d.ts +5 -0
  37. package/dist/business-flow/strategies/verified-test-strategy.d.ts.map +1 -0
  38. package/dist/business-flow/strategies/verified-test-strategy.js +26 -0
  39. package/dist/business-flow/structural-flow-catalog.d.ts +21 -0
  40. package/dist/business-flow/structural-flow-catalog.d.ts.map +1 -0
  41. package/dist/business-flow/structural-flow-catalog.js +125 -0
  42. package/dist/business-flow/types.d.ts +51 -0
  43. package/dist/business-flow/types.d.ts.map +1 -0
  44. package/dist/business-flow/types.js +1 -0
  45. package/dist/cli/argument-parser.d.ts +3 -0
  46. package/dist/cli/argument-parser.d.ts.map +1 -0
  47. package/dist/cli/argument-parser.js +174 -0
  48. package/dist/cli/bin.d.ts +3 -0
  49. package/dist/cli/bin.d.ts.map +1 -0
  50. package/dist/cli/bin.js +23 -0
  51. package/dist/cli/cli-application.d.ts +38 -0
  52. package/dist/cli/cli-application.d.ts.map +1 -0
  53. package/dist/cli/cli-application.js +515 -0
  54. package/dist/cli/cli-error.d.ts +12 -0
  55. package/dist/cli/cli-error.d.ts.map +1 -0
  56. package/dist/cli/cli-error.js +44 -0
  57. package/dist/cli/cli-presenter.d.ts +14 -0
  58. package/dist/cli/cli-presenter.d.ts.map +1 -0
  59. package/dist/cli/cli-presenter.js +36 -0
  60. package/dist/cli/main.d.ts +3 -0
  61. package/dist/cli/main.d.ts.map +1 -0
  62. package/dist/cli/main.js +45 -0
  63. package/dist/cli/types.d.ts +46 -0
  64. package/dist/cli/types.d.ts.map +1 -0
  65. package/dist/cli/types.js +1 -0
  66. package/dist/contracts/cli.d.ts +2139 -0
  67. package/dist/contracts/cli.d.ts.map +1 -0
  68. package/dist/contracts/cli.js +232 -0
  69. package/dist/contracts/graph.d.ts +262 -0
  70. package/dist/contracts/graph.d.ts.map +1 -0
  71. package/dist/contracts/graph.js +182 -0
  72. package/dist/contracts/identifiers.d.ts +4 -0
  73. package/dist/contracts/identifiers.d.ts.map +1 -0
  74. package/dist/contracts/identifiers.js +7 -0
  75. package/dist/contracts/public-contracts.d.ts +4 -0
  76. package/dist/contracts/public-contracts.d.ts.map +1 -0
  77. package/dist/contracts/public-contracts.js +3 -0
  78. package/dist/evaluation/comparison.d.ts +30 -0
  79. package/dist/evaluation/comparison.d.ts.map +1 -0
  80. package/dist/evaluation/comparison.js +108 -0
  81. package/dist/evaluation/contracts.d.ts +204 -0
  82. package/dist/evaluation/contracts.d.ts.map +1 -0
  83. package/dist/evaluation/contracts.js +269 -0
  84. package/dist/graph/graph-store.d.ts +47 -0
  85. package/dist/graph/graph-store.d.ts.map +1 -0
  86. package/dist/graph/graph-store.js +719 -0
  87. package/dist/graph/types.d.ts +168 -0
  88. package/dist/graph/types.d.ts.map +1 -0
  89. package/dist/graph/types.js +1 -0
  90. package/dist/index.d.ts +19 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +9 -0
  93. package/dist/knowledge/business-knowledge-service.d.ts +24 -0
  94. package/dist/knowledge/business-knowledge-service.d.ts.map +1 -0
  95. package/dist/knowledge/business-knowledge-service.js +200 -0
  96. package/dist/knowledge/graph-patch-conflict-error.d.ts +8 -0
  97. package/dist/knowledge/graph-patch-conflict-error.d.ts.map +1 -0
  98. package/dist/knowledge/graph-patch-conflict-error.js +12 -0
  99. package/dist/knowledge/structural-target-binding.d.ts +14 -0
  100. package/dist/knowledge/structural-target-binding.d.ts.map +1 -0
  101. package/dist/knowledge/structural-target-binding.js +11 -0
  102. package/dist/repository/git-command.d.ts +3 -0
  103. package/dist/repository/git-command.d.ts.map +1 -0
  104. package/dist/repository/git-command.js +25 -0
  105. package/dist/repository/repository-inspector.d.ts +7 -0
  106. package/dist/repository/repository-inspector.d.ts.map +1 -0
  107. package/dist/repository/repository-inspector.js +84 -0
  108. package/dist/repository/repository-language-support.d.ts +14 -0
  109. package/dist/repository/repository-language-support.d.ts.map +1 -0
  110. package/dist/repository/repository-language-support.js +64 -0
  111. package/dist/repository/types.d.ts +9 -0
  112. package/dist/repository/types.d.ts.map +1 -0
  113. package/dist/repository/types.js +1 -0
  114. package/dist/snapshots/repository-snapshot.d.ts +4 -0
  115. package/dist/snapshots/repository-snapshot.d.ts.map +1 -0
  116. package/dist/snapshots/repository-snapshot.js +119 -0
  117. package/dist/snapshots/types.d.ts +30 -0
  118. package/dist/snapshots/types.d.ts.map +1 -0
  119. package/dist/snapshots/types.js +1 -0
  120. package/dist/storage/atlas-database.d.ts +14 -0
  121. package/dist/storage/atlas-database.d.ts.map +1 -0
  122. package/dist/storage/atlas-database.js +552 -0
  123. package/dist/storage/snapshot-store.d.ts +19 -0
  124. package/dist/storage/snapshot-store.d.ts.map +1 -0
  125. package/dist/storage/snapshot-store.js +77 -0
  126. package/dist/structural-backend/codegraph-backend.d.ts +54 -0
  127. package/dist/structural-backend/codegraph-backend.d.ts.map +1 -0
  128. package/dist/structural-backend/codegraph-backend.js +1224 -0
  129. package/dist/structural-backend/codegraph-worker-client.d.ts +5 -0
  130. package/dist/structural-backend/codegraph-worker-client.d.ts.map +1 -0
  131. package/dist/structural-backend/codegraph-worker-client.js +118 -0
  132. package/dist/structural-backend/codegraph-worker-protocol.d.ts +35 -0
  133. package/dist/structural-backend/codegraph-worker-protocol.d.ts.map +1 -0
  134. package/dist/structural-backend/codegraph-worker-protocol.js +1 -0
  135. package/dist/structural-backend/codegraph-worker.d.ts +2 -0
  136. package/dist/structural-backend/codegraph-worker.d.ts.map +1 -0
  137. package/dist/structural-backend/codegraph-worker.js +131 -0
  138. package/dist/structural-backend/process-instance.d.ts +18 -0
  139. package/dist/structural-backend/process-instance.d.ts.map +1 -0
  140. package/dist/structural-backend/process-instance.js +207 -0
  141. package/dist/structural-backend/structural-fact-changes.d.ts +7 -0
  142. package/dist/structural-backend/structural-fact-changes.d.ts.map +1 -0
  143. package/dist/structural-backend/structural-fact-changes.js +78 -0
  144. package/dist/structural-backend/structural-publication.d.ts +12 -0
  145. package/dist/structural-backend/structural-publication.d.ts.map +1 -0
  146. package/dist/structural-backend/structural-publication.js +252 -0
  147. package/dist/structural-backend/structural-write-lock.d.ts +8 -0
  148. package/dist/structural-backend/structural-write-lock.d.ts.map +1 -0
  149. package/dist/structural-backend/structural-write-lock.js +415 -0
  150. package/dist/structural-backend/types.d.ts +144 -0
  151. package/dist/structural-backend/types.d.ts.map +1 -0
  152. package/dist/structural-backend/types.js +11 -0
  153. package/dist/world/types.d.ts +77 -0
  154. package/dist/world/types.d.ts.map +1 -0
  155. package/dist/world/types.js +1 -0
  156. package/dist/world/world-graph-query.d.ts +31 -0
  157. package/dist/world/world-graph-query.d.ts.map +1 -0
  158. package/dist/world/world-graph-query.js +453 -0
  159. package/dist/world/world-model-service.d.ts +21 -0
  160. package/dist/world/world-model-service.d.ts.map +1 -0
  161. package/dist/world/world-model-service.js +211 -0
  162. package/dist/world/world-snapshot-store.d.ts +40 -0
  163. package/dist/world/world-snapshot-store.d.ts.map +1 -0
  164. package/dist/world/world-snapshot-store.js +555 -0
  165. package/docs/architecture/codegraph-backend.md +193 -0
  166. package/docs/contracts/cli-v1.md +119 -0
  167. package/docs/contracts/graph-model.md +102 -0
  168. package/docs/contracts/graph-patch-v1.md +98 -0
  169. package/docs/evaluation.md +128 -0
  170. package/docs/product-contract.md +148 -0
  171. package/package.json +78 -0
  172. package/schemas/cli-envelope-v1.schema.json +1359 -0
  173. package/schemas/evaluation-plan-v1.schema.json +211 -0
  174. package/schemas/evaluation-run-v1.schema.json +365 -0
  175. package/schemas/graph-patch-v1.schema.json +392 -0
@@ -0,0 +1,168 @@
1
+ import type { z } from "zod";
2
+ import type { assertionCertaintySchema, businessNodeKindSchema, businessRelationTypeSchema, evidenceSchema, knowledgeValiditySchema, sourceRangeSchema, structuralNodeKindSchema, structuralRelationTypeSchema, structuralSupportSchema } from "../contracts/graph.js";
3
+ export type StructuralNodeKind = z.infer<typeof structuralNodeKindSchema>;
4
+ export type BusinessNodeKind = z.infer<typeof businessNodeKindSchema>;
5
+ export type StructuralRelationType = z.infer<typeof structuralRelationTypeSchema>;
6
+ export type BusinessRelationType = z.infer<typeof businessRelationTypeSchema>;
7
+ export type AssertionCertainty = z.infer<typeof assertionCertaintySchema>;
8
+ export type KnowledgeValidity = z.infer<typeof knowledgeValiditySchema>;
9
+ export type SourceRange = z.infer<typeof sourceRangeSchema>;
10
+ export type Evidence = z.infer<typeof evidenceSchema>;
11
+ type StructuralSupport = z.infer<typeof structuralSupportSchema>;
12
+ export interface GraphSourceLocation {
13
+ readonly file: string;
14
+ readonly range: SourceRange;
15
+ readonly contentHash: string;
16
+ }
17
+ export interface StructuralNodeInput {
18
+ readonly id: string;
19
+ readonly kind: Exclude<StructuralNodeKind, "UnknownBoundary">;
20
+ readonly label: string;
21
+ readonly locations: readonly GraphSourceLocation[];
22
+ }
23
+ export interface UnknownBoundaryInput {
24
+ readonly id: string;
25
+ readonly kind: "UnknownBoundary";
26
+ readonly label: string;
27
+ readonly reason: string;
28
+ readonly location: GraphSourceLocation;
29
+ readonly candidates: readonly string[];
30
+ }
31
+ export type StructuralGraphNodeInput = StructuralNodeInput | UnknownBoundaryInput;
32
+ export interface BusinessNodeInput {
33
+ readonly key: string;
34
+ readonly kind: BusinessNodeKind;
35
+ readonly label: string;
36
+ readonly summary: string;
37
+ readonly aliases: readonly string[];
38
+ readonly certainty: AssertionCertainty;
39
+ readonly evidence: readonly Evidence[];
40
+ }
41
+ export interface StructuralNodeReference {
42
+ readonly domain: "structural";
43
+ readonly id: string;
44
+ }
45
+ export interface BusinessNodeReference {
46
+ readonly domain: "business";
47
+ readonly key: string;
48
+ }
49
+ export type GraphNodeReference = StructuralNodeReference | BusinessNodeReference;
50
+ export interface StructuralRelationInput {
51
+ readonly from: string;
52
+ readonly type: StructuralRelationType;
53
+ readonly to: string;
54
+ }
55
+ export interface BusinessRelationSelector {
56
+ readonly from: BusinessNodeReference;
57
+ readonly type: BusinessRelationType;
58
+ readonly to: GraphNodeReference;
59
+ }
60
+ export interface BusinessRelationInput extends BusinessRelationSelector {
61
+ readonly certainty: AssertionCertainty;
62
+ readonly evidence: readonly Evidence[];
63
+ }
64
+ export interface BusinessGraphMutation {
65
+ readonly baseSnapshotId: string;
66
+ readonly upsertNodes: readonly BusinessNodeInput[];
67
+ readonly removeNodeKeys: readonly string[];
68
+ readonly upsertRelations: readonly BusinessRelationInput[];
69
+ readonly removeRelations: readonly BusinessRelationSelector[];
70
+ }
71
+ export interface StructuralGraphNode {
72
+ readonly domain: "structural";
73
+ readonly id: string;
74
+ readonly kind: Exclude<StructuralNodeKind, "UnknownBoundary">;
75
+ readonly label: string;
76
+ readonly snapshotId: string;
77
+ readonly validity: KnowledgeValidity;
78
+ readonly locations: readonly GraphSourceLocation[];
79
+ readonly support: StructuralSupport;
80
+ }
81
+ export interface UnknownBoundary {
82
+ readonly domain: "structural";
83
+ readonly id: string;
84
+ readonly kind: "UnknownBoundary";
85
+ readonly label: string;
86
+ readonly snapshotId: string;
87
+ readonly validity: "unknown";
88
+ readonly owner: StructuralNodeReference;
89
+ readonly operation: string;
90
+ readonly reason: string;
91
+ readonly location: GraphSourceLocation;
92
+ readonly candidates: readonly string[];
93
+ readonly support: StructuralSupport;
94
+ }
95
+ export interface BusinessGraphNode {
96
+ readonly domain: "business";
97
+ readonly key: string;
98
+ readonly kind: BusinessNodeKind;
99
+ readonly label: string;
100
+ readonly summary: string;
101
+ readonly aliases: readonly string[];
102
+ readonly certainty: AssertionCertainty;
103
+ readonly validity: KnowledgeValidity;
104
+ readonly evidence: readonly Evidence[];
105
+ readonly baseSnapshotId: string;
106
+ }
107
+ export type GraphNode = StructuralGraphNode | UnknownBoundary | BusinessGraphNode;
108
+ export interface StructuralGraphRelation {
109
+ readonly domain: "structural";
110
+ readonly from: StructuralNodeReference;
111
+ readonly type: StructuralRelationType;
112
+ readonly to: StructuralNodeReference;
113
+ readonly snapshotId: string;
114
+ readonly certainty: null;
115
+ readonly validity: KnowledgeValidity;
116
+ readonly evidence: readonly [];
117
+ readonly support: StructuralSupport;
118
+ }
119
+ export interface BusinessGraphRelation extends BusinessRelationSelector {
120
+ readonly domain: "business";
121
+ readonly baseSnapshotId: string;
122
+ readonly certainty: AssertionCertainty;
123
+ readonly validity: KnowledgeValidity;
124
+ readonly evidence: readonly Evidence[];
125
+ }
126
+ export type GraphRelation = StructuralGraphRelation | BusinessGraphRelation;
127
+ export type TraversalDirection = "incoming" | "outgoing" | "both";
128
+ export interface GraphTraversalOptions {
129
+ readonly snapshotId: string;
130
+ readonly maxDepth?: number;
131
+ readonly direction?: TraversalDirection;
132
+ readonly relationTypes?: readonly (StructuralRelationType | BusinessRelationType)[];
133
+ }
134
+ export interface GraphNeighbor {
135
+ readonly depth: number;
136
+ readonly direction: Exclude<TraversalDirection, "both">;
137
+ readonly relation: GraphRelation;
138
+ readonly node: GraphNode;
139
+ }
140
+ export interface GraphSearchOptions {
141
+ readonly snapshotId: string;
142
+ readonly limit?: number;
143
+ }
144
+ export interface GraphSearchResult {
145
+ readonly score: number;
146
+ readonly node: GraphNode;
147
+ }
148
+ export interface WorldGraphView {
149
+ readonly node: GraphNode;
150
+ readonly depth: number;
151
+ readonly neighbors: readonly GraphNeighbor[];
152
+ readonly invariants: readonly BusinessGraphNode[];
153
+ readonly tests: readonly StructuralGraphNode[];
154
+ readonly unknowns: readonly UnknownBoundary[];
155
+ }
156
+ export interface WorldGraphTraversalResult {
157
+ readonly neighbors: readonly GraphNeighbor[];
158
+ readonly unknowns: readonly UnknownBoundary[];
159
+ }
160
+ export type EvidenceOwner = {
161
+ readonly type: "node";
162
+ readonly node: BusinessNodeReference;
163
+ } | {
164
+ readonly type: "relation";
165
+ readonly relation: BusinessRelationSelector;
166
+ };
167
+ export {};
168
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graph/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,cAAc,EACd,uBAAuB,EACvB,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACtE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC9E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AACtD,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI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19 @@
1
+ export { CURRENT_ATLAS_SCHEMA_VERSION, GraphStore, } from "./graph/graph-store.js";
2
+ export type * from "./graph/types.js";
3
+ export { BusinessFlowDerivationService } from "./business-flow/business-flow-derivation-service.js";
4
+ export type * from "./business-flow/types.js";
5
+ export { BusinessKnowledgeService, GraphPatchConflictError, } from "./knowledge/business-knowledge-service.js";
6
+ export type { AppliedGraphPatch } from "./knowledge/business-knowledge-service.js";
7
+ export { discoverTargetSources, inspectGitRepository, isTargetSource, readCurrentHead, } from "./repository/repository-inspector.js";
8
+ export type { GitRepository } from "./repository/types.js";
9
+ export { createRepositorySnapshot } from "./snapshots/repository-snapshot.js";
10
+ export type { RepositoryChanges, RepositorySnapshot, SnapshotFile, } from "./snapshots/types.js";
11
+ export { SnapshotStore } from "./storage/snapshot-store.js";
12
+ export { WorldModelService } from "./world/world-model-service.js";
13
+ export type { PublishedWorldSnapshot } from "./world/world-model-service.js";
14
+ export { WorldGraphQuery } from "./world/world-graph-query.js";
15
+ export type { WorldGraphTraversalOptions } from "./world/world-graph-query.js";
16
+ export type { SemanticGraphChangeOptions, SemanticGraphChanges, WorldSnapshotState, WorldSnapshotStatus, } from "./world/types.js";
17
+ export { STRUCTURAL_BACKEND_VERSION, StructuralBackendError, } from "./structural-backend/types.js";
18
+ export type * from "./structural-backend/types.js";
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,UAAU,GACX,MAAM,wBAAwB,CAAC;AAChC,mBAAmB,kBAAkB,CAAC;AACtC,OAAO,EAAE,6BAA6B,EAAE,MAAM,qDAAqD,CAAC;AACpG,mBAAmB,0BAA0B,CAAC;AAC9C,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,2CAA2C,CAAC;AACnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,sCAAsC,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,YAAY,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,YAAY,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,mBAAmB,+BAA+B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { CURRENT_ATLAS_SCHEMA_VERSION, GraphStore, } from "./graph/graph-store.js";
2
+ export { BusinessFlowDerivationService } from "./business-flow/business-flow-derivation-service.js";
3
+ export { BusinessKnowledgeService, GraphPatchConflictError, } from "./knowledge/business-knowledge-service.js";
4
+ export { discoverTargetSources, inspectGitRepository, isTargetSource, readCurrentHead, } from "./repository/repository-inspector.js";
5
+ export { createRepositorySnapshot } from "./snapshots/repository-snapshot.js";
6
+ export { SnapshotStore } from "./storage/snapshot-store.js";
7
+ export { WorldModelService } from "./world/world-model-service.js";
8
+ export { WorldGraphQuery } from "./world/world-graph-query.js";
9
+ export { STRUCTURAL_BACKEND_VERSION, StructuralBackendError, } from "./structural-backend/types.js";
@@ -0,0 +1,24 @@
1
+ import type { GraphStore } from "../graph/graph-store.js";
2
+ import type { GitRepository } from "../repository/types.js";
3
+ import type { StructuralIndexBackend } from "../structural-backend/types.js";
4
+ import type { WorldWriteCoordinator } from "../world/types.js";
5
+ export { GraphPatchConflictError } from "./graph-patch-conflict-error.js";
6
+ export interface AppliedGraphPatch {
7
+ readonly baseSnapshotId: string;
8
+ readonly snapshotId: string;
9
+ readonly applied: {
10
+ readonly nodeOperations: number;
11
+ readonly relationOperations: number;
12
+ };
13
+ }
14
+ export declare class BusinessKnowledgeService {
15
+ private readonly repository;
16
+ private readonly graph;
17
+ private readonly structural;
18
+ constructor(repository: GitRepository, graph: GraphStore, structural?: StructuralIndexBackend & WorldWriteCoordinator);
19
+ learn(input: unknown): Promise<AppliedGraphPatch>;
20
+ private learnLocked;
21
+ private requireCurrentBaseSnapshot;
22
+ private requireCurrentStructuralEvidence;
23
+ }
24
+ //# sourceMappingURL=business-knowledge-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"business-knowledge-service.d.ts","sourceRoot":"","sources":["../../src/knowledge/business-knowledge-service.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAO5D,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAEV,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;QAChC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;KACrC,CAAC;CACH;AAUD,qBAAa,wBAAwB;IAEjC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAFV,UAAU,EAAE,aAAa,EACzB,KAAK,EAAE,UAAU,EACjB,UAAU,GAAE,sBAAsB,GAAG,qBACV;IAGxC,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;YASzC,WAAW;IAkCzB,OAAO,CAAC,0BAA0B;IASlC,OAAO,CAAC,gCAAgC;CA0CzC"}
@@ -0,0 +1,200 @@
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 { graphPatchV1Schema, } from "../contracts/graph.js";
54
+ import { createRepositorySnapshot } from "../snapshots/repository-snapshot.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/world-snapshot-store.js";
58
+ import { bindStructuralTarget as attachStructuralTargetBinding, } from "./structural-target-binding.js";
59
+ import { GraphPatchConflictError } from "./graph-patch-conflict-error.js";
60
+ export { GraphPatchConflictError } from "./graph-patch-conflict-error.js";
61
+ export class BusinessKnowledgeService {
62
+ repository;
63
+ graph;
64
+ structural;
65
+ constructor(repository, graph, structural = new CodeGraphStructuralBackend(repository)) {
66
+ this.repository = repository;
67
+ this.graph = graph;
68
+ this.structural = structural;
69
+ }
70
+ async learn(input) {
71
+ if (requiresBundledCodeGraphRuntime()) {
72
+ return runCodeGraphWorker({ operation: "learn", repository: this.repository, input });
73
+ }
74
+ return this.structural.withWorldWriteLock((state, resolver) => (this.learnLocked(input, state, resolver)));
75
+ }
76
+ async learnLocked(input, structuralState, resolver) {
77
+ const env_1 = { stack: [], error: void 0, hasError: false };
78
+ try {
79
+ const patch = graphPatchV1Schema.parse(input);
80
+ const currentSnapshot = await createRepositorySnapshot(this.repository);
81
+ this.requireCurrentBaseSnapshot(patch, currentSnapshot.snapshotId);
82
+ const world = __addDisposableResource(env_1, new WorldSnapshotStore(this.repository), false);
83
+ if (world.requireCurrentSnapshot().snapshotId !== patch.baseSnapshotId) {
84
+ throw new Error("GraphPatch base snapshot is not the current world snapshot");
85
+ }
86
+ const structuralNodes = this.requireCurrentStructuralEvidence(patch, resolver);
87
+ const verifiedSnapshot = await createRepositorySnapshot(this.repository);
88
+ this.requireCurrentBaseSnapshot(patch, verifiedSnapshot.snapshotId);
89
+ this.graph.mutateBusinessGraph(toBusinessGraphMutation(patch, structuralNodes, resolver, verifiedSnapshot.snapshotId, structuralState.backendVersion));
90
+ return {
91
+ baseSnapshotId: patch.baseSnapshotId,
92
+ snapshotId: verifiedSnapshot.snapshotId,
93
+ applied: {
94
+ nodeOperations: patch.nodeOperations.length,
95
+ relationOperations: patch.relationOperations.length,
96
+ },
97
+ };
98
+ }
99
+ catch (e_1) {
100
+ env_1.error = e_1;
101
+ env_1.hasError = true;
102
+ }
103
+ finally {
104
+ __disposeResources(env_1);
105
+ }
106
+ }
107
+ requireCurrentBaseSnapshot(patch, currentSnapshotId) {
108
+ if (patch.baseSnapshotId !== currentSnapshotId) {
109
+ throw new GraphPatchConflictError(patch.baseSnapshotId, currentSnapshotId);
110
+ }
111
+ }
112
+ requireCurrentStructuralEvidence(patch, resolver) {
113
+ const nodes = new Map();
114
+ const resolve = (id) => {
115
+ const known = nodes.get(id);
116
+ if (known !== undefined) {
117
+ return known;
118
+ }
119
+ const node = resolver.getNode(id);
120
+ if (node === undefined) {
121
+ throw new Error(`Structural reference ${id} does not resolve in the current index`);
122
+ }
123
+ nodes.set(id, node);
124
+ return node;
125
+ };
126
+ const evidence = [
127
+ ...patch.nodeOperations.flatMap((operation) => (operation.op === "upsert" ? operation.node.evidence : [])),
128
+ ...patch.relationOperations.flatMap((operation) => (operation.op === "upsert" ? operation.relation.evidence : [])),
129
+ ];
130
+ for (const item of evidence) {
131
+ const node = resolve(item.symbolId);
132
+ if (node.path !== item.file || !sameRange(node, item.range)) {
133
+ throw new Error(`Evidence ${item.symbolId} at ${item.file} does not match the current structural index`);
134
+ }
135
+ }
136
+ for (const operation of patch.relationOperations) {
137
+ if (operation.op === "upsert" && operation.relation.to.domain === "structural") {
138
+ resolve(operation.relation.to.id);
139
+ }
140
+ }
141
+ return nodes;
142
+ }
143
+ }
144
+ function sameRange(node, range) {
145
+ return node.range.start.line === range.start.line
146
+ && node.range.start.column === range.start.column
147
+ && node.range.end.line === range.end.line
148
+ && node.range.end.column === range.end.column;
149
+ }
150
+ function toBusinessGraphMutation(patch, structuralNodes, resolver, snapshotId, backendVersion) {
151
+ const bindEvidence = (evidence) => {
152
+ const node = structuralNodes.get(evidence.symbolId);
153
+ if (node === undefined) {
154
+ throw new Error(`Structural reference ${evidence.symbolId} was not verified`);
155
+ }
156
+ return {
157
+ ...evidence,
158
+ qualifiedSymbol: node.qualifiedName,
159
+ structuralKind: node.kind,
160
+ atlasSnapshotId: snapshotId,
161
+ backendVersion,
162
+ backendLocator: resolver.backendLocator(node) ?? node.reference.id,
163
+ };
164
+ };
165
+ const createStructuralTargetBinding = (reference) => {
166
+ const node = structuralNodes.get(reference);
167
+ if (node === undefined) {
168
+ throw new Error(`Structural relation target ${reference} was not verified`);
169
+ }
170
+ return {
171
+ structuralReference: reference,
172
+ file: node.path,
173
+ qualifiedSymbol: node.qualifiedName,
174
+ structuralKind: node.kind,
175
+ range: node.range,
176
+ atlasSnapshotId: snapshotId,
177
+ backendVersion,
178
+ backendLocator: resolver.backendLocator(node) ?? node.reference.id,
179
+ };
180
+ };
181
+ return {
182
+ baseSnapshotId: patch.baseSnapshotId,
183
+ upsertNodes: patch.nodeOperations.flatMap((operation) => (operation.op === "upsert"
184
+ ? [{ ...operation.node, evidence: operation.node.evidence.map(bindEvidence) }]
185
+ : [])),
186
+ removeNodeKeys: patch.nodeOperations.flatMap((operation) => (operation.op === "remove" ? [operation.key] : [])),
187
+ upsertRelations: patch.relationOperations.flatMap((operation) => (operation.op === "upsert"
188
+ ? [operation.relation.to.domain === "structural"
189
+ ? attachStructuralTargetBinding({
190
+ ...operation.relation,
191
+ evidence: operation.relation.evidence.map(bindEvidence),
192
+ }, createStructuralTargetBinding(operation.relation.to.id))
193
+ : {
194
+ ...operation.relation,
195
+ evidence: operation.relation.evidence.map(bindEvidence),
196
+ }]
197
+ : [])),
198
+ removeRelations: patch.relationOperations.flatMap((operation) => (operation.op === "remove" ? [operation.relation] : [])),
199
+ };
200
+ }
@@ -0,0 +1,8 @@
1
+ export declare const GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH = "BASE_SNAPSHOT_MISMATCH";
2
+ export declare class GraphPatchConflictError extends Error {
3
+ readonly baseSnapshotId: string;
4
+ readonly currentSnapshotId: string;
5
+ readonly code = "BASE_SNAPSHOT_MISMATCH";
6
+ constructor(baseSnapshotId: string, currentSnapshotId: string);
7
+ }
8
+ //# sourceMappingURL=graph-patch-conflict-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-patch-conflict-error.d.ts","sourceRoot":"","sources":["../../src/knowledge/graph-patch-conflict-error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kCAAkC,2BAA2B,CAAC;AAE3E,qBAAa,uBAAwB,SAAQ,KAAK;IAI9C,QAAQ,CAAC,cAAc,EAAE,MAAM;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAJpC,QAAQ,CAAC,IAAI,4BAAsC;gBAGxC,cAAc,EAAE,MAAM,EACtB,iBAAiB,EAAE,MAAM;CAOrC"}
@@ -0,0 +1,12 @@
1
+ export const GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH = "BASE_SNAPSHOT_MISMATCH";
2
+ export class GraphPatchConflictError extends Error {
3
+ baseSnapshotId;
4
+ currentSnapshotId;
5
+ code = GRAPH_PATCH_BASE_SNAPSHOT_MISMATCH;
6
+ constructor(baseSnapshotId, currentSnapshotId) {
7
+ super(`GraphPatch base snapshot ${baseSnapshotId} does not match current snapshot ${currentSnapshotId}`);
8
+ this.baseSnapshotId = baseSnapshotId;
9
+ this.currentSnapshotId = currentSnapshotId;
10
+ this.name = "GraphPatchConflictError";
11
+ }
12
+ }
@@ -0,0 +1,14 @@
1
+ import type { BusinessRelationInput, SourceRange, StructuralNodeKind } from "../graph/types.js";
2
+ export interface StructuralTargetBinding {
3
+ readonly structuralReference: string;
4
+ readonly file: string;
5
+ readonly qualifiedSymbol: string | null;
6
+ readonly structuralKind: Exclude<StructuralNodeKind, "UnknownBoundary"> | null;
7
+ readonly range: SourceRange;
8
+ readonly atlasSnapshotId: string;
9
+ readonly backendVersion: string | null;
10
+ readonly backendLocator: string | null;
11
+ }
12
+ export declare function bindStructuralTarget(relation: BusinessRelationInput, binding: StructuralTargetBinding): BusinessRelationInput;
13
+ export declare function readStructuralTargetBinding(relation: BusinessRelationInput): StructuralTargetBinding | undefined;
14
+ //# sourceMappingURL=structural-target-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-target-binding.d.ts","sourceRoot":"","sources":["../../src/knowledge/structural-target-binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAI3B,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,GAAG,IAAI,CAAC;IAC/E,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC;AAMD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,qBAAqB,EAC/B,OAAO,EAAE,uBAAuB,GAC/B,qBAAqB,CAMvB;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,qBAAqB,GAC9B,uBAAuB,GAAG,SAAS,CAErC"}
@@ -0,0 +1,11 @@
1
+ const structuralTargetBinding = Symbol("structuralTargetBinding");
2
+ export function bindStructuralTarget(relation, binding) {
3
+ const boundRelation = {
4
+ ...relation,
5
+ [structuralTargetBinding]: binding,
6
+ };
7
+ return boundRelation;
8
+ }
9
+ export function readStructuralTargetBinding(relation) {
10
+ return relation[structuralTargetBinding];
11
+ }
@@ -0,0 +1,3 @@
1
+ export declare function runGit(workingDirectory: string, arguments_: readonly string[]): Promise<Buffer>;
2
+ export declare function runGitText(workingDirectory: string, arguments_: readonly string[]): Promise<string>;
3
+ //# sourceMappingURL=git-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-command.d.ts","sourceRoot":"","sources":["../../src/repository/git-command.ts"],"names":[],"mappings":"AAQA,wBAAsB,MAAM,CAC1B,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAED,wBAAsB,UAAU,CAC9B,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,OAAO,CAAC,MAAM,CAAC,CAEjB"}
@@ -0,0 +1,25 @@
1
+ import { execFile } from "node:child_process";
2
+ const READ_ONLY_GIT_ENVIRONMENT = {
3
+ ...process.env,
4
+ // Git must not refresh the target repository's index during inspection.
5
+ GIT_OPTIONAL_LOCKS: "0",
6
+ };
7
+ export async function runGit(workingDirectory, arguments_) {
8
+ return new Promise((resolve, reject) => {
9
+ execFile("git", ["-C", workingDirectory, ...arguments_], {
10
+ encoding: "buffer",
11
+ env: READ_ONLY_GIT_ENVIRONMENT,
12
+ maxBuffer: 64 * 1024 * 1024,
13
+ windowsHide: true,
14
+ }, (error, stdout) => {
15
+ if (error) {
16
+ reject(error);
17
+ return;
18
+ }
19
+ resolve(stdout);
20
+ });
21
+ });
22
+ }
23
+ export async function runGitText(workingDirectory, arguments_) {
24
+ return (await runGit(workingDirectory, arguments_)).toString("utf8").trim();
25
+ }
@@ -0,0 +1,7 @@
1
+ import type { GitRepository } from "./types.js";
2
+ export declare function isSupportedSource(path: string): boolean;
3
+ export declare function isTargetSource(path: string): boolean;
4
+ export declare function inspectGitRepository(startPath: string): Promise<GitRepository>;
5
+ export declare function discoverTargetSources(repository: GitRepository): Promise<string[]>;
6
+ export declare function readCurrentHead(repository: GitRepository): Promise<string>;
7
+ //# sourceMappingURL=repository-inspector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-inspector.d.ts","sourceRoot":"","sources":["../../src/repository/repository-inspector.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA4ChD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMvD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAuBpF;AAED,wBAAsB,qBAAqB,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAcxF;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAEhF"}
@@ -0,0 +1,84 @@
1
+ import { createHash } from "node:crypto";
2
+ import { realpath } from "node:fs/promises";
3
+ import { basename, isAbsolute, resolve } from "node:path";
4
+ import { runGit, runGitText } from "./git-command.js";
5
+ const SUPPORTED_SOURCE_EXTENSIONS = new Set([
6
+ ".cjs",
7
+ ".cts",
8
+ ".js",
9
+ ".jsx",
10
+ ".mjs",
11
+ ".mts",
12
+ ".ts",
13
+ ".tsx",
14
+ ]);
15
+ function resolveGitPath(workingDirectory, path) {
16
+ return isAbsolute(path) ? path : resolve(workingDirectory, path);
17
+ }
18
+ function normalizeIdentityPath(path) {
19
+ const normalized = path.replaceAll("\\", "/");
20
+ return process.platform === "win32" ? normalized.toLowerCase() : normalized;
21
+ }
22
+ function createRepositoryId(commonGitDirectory) {
23
+ return createHash("sha256")
24
+ .update("semantic-atlas:git-common-directory:v1\0")
25
+ .update(normalizeIdentityPath(commonGitDirectory))
26
+ .digest("hex");
27
+ }
28
+ function compareRepositoryPaths(left, right) {
29
+ return left < right ? -1 : left > right ? 1 : 0;
30
+ }
31
+ async function discoverWorktreeRoots(workingDirectory) {
32
+ const output = await runGit(workingDirectory, ["worktree", "list", "--porcelain", "-z"]);
33
+ const worktreePaths = output
34
+ .toString("utf8")
35
+ .split("\0")
36
+ .filter((field) => field.startsWith("worktree "))
37
+ .map((field) => resolveGitPath(workingDirectory, field.slice("worktree ".length)));
38
+ return [...new Set(worktreePaths)].sort(compareRepositoryPaths);
39
+ }
40
+ export function isSupportedSource(path) {
41
+ const extensionIndex = path.lastIndexOf(".");
42
+ if (extensionIndex < 0) {
43
+ return false;
44
+ }
45
+ return SUPPORTED_SOURCE_EXTENSIONS.has(path.slice(extensionIndex).toLowerCase());
46
+ }
47
+ export function isTargetSource(path) {
48
+ const fileName = basename(path);
49
+ return (isSupportedSource(path) ||
50
+ fileName === "package.json" ||
51
+ /^(?:ts|js)config(?:\.[^.]+)*\.json$/u.test(fileName));
52
+ }
53
+ export async function inspectGitRepository(startPath) {
54
+ const worktreeRoot = await realpath(await runGitText(startPath, ["rev-parse", "--show-toplevel"]));
55
+ const gitDirectory = await realpath(resolveGitPath(startPath, await runGitText(startPath, ["rev-parse", "--git-dir"])));
56
+ const commonGitDirectory = await realpath(resolveGitPath(startPath, await runGitText(startPath, ["rev-parse", "--git-common-dir"])));
57
+ const indexPath = resolveGitPath(startPath, await runGitText(startPath, ["rev-parse", "--git-path", "index"]));
58
+ const worktreeRoots = await discoverWorktreeRoots(worktreeRoot);
59
+ return {
60
+ repositoryId: createRepositoryId(commonGitDirectory),
61
+ worktreeRoot,
62
+ gitDirectory,
63
+ commonGitDirectory,
64
+ worktreeRoots,
65
+ indexPath,
66
+ };
67
+ }
68
+ export async function discoverTargetSources(repository) {
69
+ const output = await runGit(repository.worktreeRoot, [
70
+ "ls-files",
71
+ "--cached",
72
+ "--others",
73
+ "--exclude-standard",
74
+ "-z",
75
+ ]);
76
+ return output
77
+ .toString("utf8")
78
+ .split("\0")
79
+ .filter((path) => path.length > 0 && isTargetSource(path))
80
+ .sort(compareRepositoryPaths);
81
+ }
82
+ export async function readCurrentHead(repository) {
83
+ return runGitText(repository.worktreeRoot, ["rev-parse", "--verify", "HEAD"]);
84
+ }