semantic-atlas 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/.agents/skills/semantic-atlas/SKILL.md +134 -166
  2. package/.agents/skills/semantic-atlas/agents/openai.yaml +4 -0
  3. package/.agents/skills/semantic-atlas/references/observations.md +131 -0
  4. package/.agents/skills/semantic-atlas/scripts/query-context.mjs +110 -0
  5. package/.agents/skills/semantic-atlas-maintenance/SKILL.md +93 -0
  6. package/.agents/skills/semantic-atlas-maintenance/agents/openai.yaml +4 -0
  7. package/.agents/skills/semantic-atlas-maintenance/references/reconciliation.md +56 -0
  8. package/README.md +134 -239
  9. package/dist/application/map-application.d.ts +24 -0
  10. package/dist/application/map-application.d.ts.map +1 -0
  11. package/dist/application/map-application.js +134 -0
  12. package/dist/application/map-application.js.map +1 -0
  13. package/dist/cli/bin.js +6 -35
  14. package/dist/cli/bin.js.map +1 -0
  15. package/dist/cli/observation-commands.d.ts +16 -0
  16. package/dist/cli/observation-commands.d.ts.map +1 -0
  17. package/dist/cli/observation-commands.js +118 -0
  18. package/dist/cli/observation-commands.js.map +1 -0
  19. package/dist/cli/projection-writer.d.ts +2 -0
  20. package/dist/cli/projection-writer.d.ts.map +1 -0
  21. package/dist/cli/projection-writer.js +9 -0
  22. package/dist/cli/projection-writer.js.map +1 -0
  23. package/dist/cli/reconciliation-command.d.ts +7 -0
  24. package/dist/cli/reconciliation-command.d.ts.map +1 -0
  25. package/dist/cli/reconciliation-command.js +33 -0
  26. package/dist/cli/reconciliation-command.js.map +1 -0
  27. package/dist/cli/run-cli.d.ts +21 -0
  28. package/dist/cli/run-cli.d.ts.map +1 -0
  29. package/dist/cli/run-cli.js +299 -0
  30. package/dist/cli/run-cli.js.map +1 -0
  31. package/dist/contracts/cli.d.ts +166 -1211
  32. package/dist/contracts/cli.d.ts.map +1 -1
  33. package/dist/contracts/cli.js +2 -232
  34. package/dist/contracts/cli.js.map +1 -0
  35. package/dist/contracts/insights.d.ts +39 -1
  36. package/dist/contracts/insights.d.ts.map +1 -1
  37. package/dist/contracts/insights.js +2 -1
  38. package/dist/contracts/insights.js.map +1 -0
  39. package/dist/contracts/map.d.ts +154 -0
  40. package/dist/contracts/map.d.ts.map +1 -0
  41. package/dist/contracts/map.js +60 -0
  42. package/dist/contracts/map.js.map +1 -0
  43. package/dist/contracts/observation.d.ts +649 -0
  44. package/dist/contracts/observation.d.ts.map +1 -0
  45. package/dist/contracts/observation.js +140 -0
  46. package/dist/contracts/observation.js.map +1 -0
  47. package/dist/contracts/projection.d.ts +7 -0
  48. package/dist/contracts/projection.d.ts.map +1 -0
  49. package/dist/contracts/projection.js +2 -0
  50. package/dist/contracts/projection.js.map +1 -0
  51. package/dist/contracts/reconciliation.d.ts +40 -0
  52. package/dist/contracts/reconciliation.d.ts.map +1 -0
  53. package/dist/contracts/reconciliation.js +2 -0
  54. package/dist/contracts/reconciliation.js.map +1 -0
  55. package/dist/index.d.ts +7 -17
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +3 -9
  58. package/dist/index.js.map +1 -0
  59. package/dist/insights/insight-service.d.ts +14 -0
  60. package/dist/insights/insight-service.d.ts.map +1 -0
  61. package/dist/insights/insight-service.js +129 -0
  62. package/dist/insights/insight-service.js.map +1 -0
  63. package/dist/map/business-graph.d.ts +32 -0
  64. package/dist/map/business-graph.d.ts.map +1 -0
  65. package/dist/map/business-graph.js +122 -0
  66. package/dist/map/business-graph.js.map +1 -0
  67. package/dist/map/map-document-loader.d.ts +13 -0
  68. package/dist/map/map-document-loader.d.ts.map +1 -0
  69. package/dist/map/map-document-loader.js +86 -0
  70. package/dist/map/map-document-loader.js.map +1 -0
  71. package/dist/map/map-validator.d.ts +12 -0
  72. package/dist/map/map-validator.d.ts.map +1 -0
  73. package/dist/map/map-validator.js +322 -0
  74. package/dist/map/map-validator.js.map +1 -0
  75. package/dist/observations/observation-application.d.ts +23 -0
  76. package/dist/observations/observation-application.d.ts.map +1 -0
  77. package/dist/observations/observation-application.js +62 -0
  78. package/dist/observations/observation-application.js.map +1 -0
  79. package/dist/observations/observation-claim-manager.d.ts +13 -0
  80. package/dist/observations/observation-claim-manager.d.ts.map +1 -0
  81. package/dist/observations/observation-claim-manager.js +247 -0
  82. package/dist/observations/observation-claim-manager.js.map +1 -0
  83. package/dist/observations/observation-store.d.ts +43 -0
  84. package/dist/observations/observation-store.d.ts.map +1 -0
  85. package/dist/observations/observation-store.js +208 -0
  86. package/dist/observations/observation-store.js.map +1 -0
  87. package/dist/observations/repository-identity.d.ts +12 -0
  88. package/dist/observations/repository-identity.d.ts.map +1 -0
  89. package/dist/observations/repository-identity.js +108 -0
  90. package/dist/observations/repository-identity.js.map +1 -0
  91. package/dist/query/context-query-service.d.ts +15 -0
  92. package/dist/query/context-query-service.d.ts.map +1 -0
  93. package/dist/query/context-query-service.js +36 -0
  94. package/dist/query/context-query-service.js.map +1 -0
  95. package/dist/reconciliation/reconciliation-service.d.ts +10 -0
  96. package/dist/reconciliation/reconciliation-service.d.ts.map +1 -0
  97. package/dist/reconciliation/reconciliation-service.js +116 -0
  98. package/dist/reconciliation/reconciliation-service.js.map +1 -0
  99. package/dist/rendering/map-projector.d.ts +8 -0
  100. package/dist/rendering/map-projector.d.ts.map +1 -0
  101. package/dist/rendering/map-projector.js +386 -0
  102. package/dist/rendering/map-projector.js.map +1 -0
  103. package/dist/setup/managed-skill-installer.d.ts +60 -0
  104. package/dist/setup/managed-skill-installer.d.ts.map +1 -0
  105. package/dist/setup/managed-skill-installer.js +307 -0
  106. package/dist/setup/managed-skill-installer.js.map +1 -0
  107. package/dist/setup/package-identity.d.ts +6 -0
  108. package/dist/setup/package-identity.d.ts.map +1 -0
  109. package/dist/setup/package-identity.js +16 -0
  110. package/dist/setup/package-identity.js.map +1 -0
  111. package/dist/setup/package-upgrader.d.ts +10 -22
  112. package/dist/setup/package-upgrader.d.ts.map +1 -1
  113. package/dist/setup/package-upgrader.js +60 -76
  114. package/dist/setup/package-upgrader.js.map +1 -0
  115. package/docs/architecture.md +428 -0
  116. package/docs/evaluation.md +220 -174
  117. package/docs/index.md +27 -40
  118. package/docs/map-format.md +224 -0
  119. package/docs/observations.md +175 -0
  120. package/docs/product-contract.md +295 -137
  121. package/examples/commerce.yaml +204 -0
  122. package/package.json +31 -30
  123. package/.agents/skills/semantic-atlas/references/graph-patch.md +0 -190
  124. package/.agents/skills/semantic-atlas/references/product-feedback.md +0 -34
  125. package/.agents/skills/semantic-atlas/references/result-routing.md +0 -104
  126. package/.agents/skills/semantic-atlas/references/snapshot-bootstrap.md +0 -42
  127. package/.agents/skills/semantic-atlas-insights/SKILL.md +0 -55
  128. package/README.zh-CN.md +0 -273
  129. package/dist/business-flow/business-flow-derivation-service.d.ts +0 -11
  130. package/dist/business-flow/business-flow-derivation-service.d.ts.map +0 -1
  131. package/dist/business-flow/business-flow-derivation-service.js +0 -151
  132. package/dist/business-flow/business-flow-draft.d.ts +0 -16
  133. package/dist/business-flow/business-flow-draft.d.ts.map +0 -1
  134. package/dist/business-flow/business-flow-draft.js +0 -150
  135. package/dist/business-flow/framework-business-strategy.d.ts +0 -7
  136. package/dist/business-flow/framework-business-strategy.d.ts.map +0 -1
  137. package/dist/business-flow/framework-business-strategy.js +0 -1
  138. package/dist/business-flow/strategies/bullmq-business-strategy.d.ts +0 -10
  139. package/dist/business-flow/strategies/bullmq-business-strategy.d.ts.map +0 -1
  140. package/dist/business-flow/strategies/bullmq-business-strategy.js +0 -79
  141. package/dist/business-flow/strategies/called-operation-derivation.d.ts +0 -13
  142. package/dist/business-flow/strategies/called-operation-derivation.d.ts.map +0 -1
  143. package/dist/business-flow/strategies/called-operation-derivation.js +0 -32
  144. package/dist/business-flow/strategies/graphql-business-strategy.d.ts +0 -8
  145. package/dist/business-flow/strategies/graphql-business-strategy.d.ts.map +0 -1
  146. package/dist/business-flow/strategies/graphql-business-strategy.js +0 -65
  147. package/dist/business-flow/strategies/nestjs-business-strategy.d.ts +0 -8
  148. package/dist/business-flow/strategies/nestjs-business-strategy.d.ts.map +0 -1
  149. package/dist/business-flow/strategies/nestjs-business-strategy.js +0 -72
  150. package/dist/business-flow/strategies/strategy-helpers.d.ts +0 -32
  151. package/dist/business-flow/strategies/strategy-helpers.d.ts.map +0 -1
  152. package/dist/business-flow/strategies/strategy-helpers.js +0 -49
  153. package/dist/business-flow/strategies/typeorm-business-strategy.d.ts +0 -10
  154. package/dist/business-flow/strategies/typeorm-business-strategy.d.ts.map +0 -1
  155. package/dist/business-flow/strategies/typeorm-business-strategy.js +0 -136
  156. package/dist/business-flow/strategies/verified-invariant-strategy.d.ts +0 -5
  157. package/dist/business-flow/strategies/verified-invariant-strategy.d.ts.map +0 -1
  158. package/dist/business-flow/strategies/verified-invariant-strategy.js +0 -38
  159. package/dist/business-flow/strategies/verified-test-strategy.d.ts +0 -5
  160. package/dist/business-flow/strategies/verified-test-strategy.d.ts.map +0 -1
  161. package/dist/business-flow/strategies/verified-test-strategy.js +0 -26
  162. package/dist/business-flow/structural-flow-catalog.d.ts +0 -21
  163. package/dist/business-flow/structural-flow-catalog.d.ts.map +0 -1
  164. package/dist/business-flow/structural-flow-catalog.js +0 -125
  165. package/dist/business-flow/types.d.ts +0 -51
  166. package/dist/business-flow/types.d.ts.map +0 -1
  167. package/dist/business-flow/types.js +0 -1
  168. package/dist/cli/argument-parser.d.ts +0 -3
  169. package/dist/cli/argument-parser.d.ts.map +0 -1
  170. package/dist/cli/argument-parser.js +0 -200
  171. package/dist/cli/cli-application.d.ts +0 -39
  172. package/dist/cli/cli-application.d.ts.map +0 -1
  173. package/dist/cli/cli-application.js +0 -571
  174. package/dist/cli/cli-error.d.ts +0 -12
  175. package/dist/cli/cli-error.d.ts.map +0 -1
  176. package/dist/cli/cli-error.js +0 -44
  177. package/dist/cli/cli-presenter.d.ts +0 -14
  178. package/dist/cli/cli-presenter.d.ts.map +0 -1
  179. package/dist/cli/cli-presenter.js +0 -36
  180. package/dist/cli/insights-cli.d.ts +0 -6
  181. package/dist/cli/insights-cli.d.ts.map +0 -1
  182. package/dist/cli/insights-cli.js +0 -236
  183. package/dist/cli/main.d.ts +0 -3
  184. package/dist/cli/main.d.ts.map +0 -1
  185. package/dist/cli/main.js +0 -137
  186. package/dist/cli/standalone-cli.d.ts +0 -3
  187. package/dist/cli/standalone-cli.d.ts.map +0 -1
  188. package/dist/cli/standalone-cli.js +0 -96
  189. package/dist/cli/types.d.ts +0 -49
  190. package/dist/cli/types.d.ts.map +0 -1
  191. package/dist/cli/types.js +0 -1
  192. package/dist/contracts/graph.d.ts +0 -266
  193. package/dist/contracts/graph.d.ts.map +0 -1
  194. package/dist/contracts/graph.js +0 -182
  195. package/dist/contracts/identifiers.d.ts +0 -4
  196. package/dist/contracts/identifiers.d.ts.map +0 -1
  197. package/dist/contracts/identifiers.js +0 -7
  198. package/dist/contracts/public-contracts.d.ts +0 -5
  199. package/dist/contracts/public-contracts.d.ts.map +0 -1
  200. package/dist/contracts/public-contracts.js +0 -4
  201. package/dist/evaluation/comparison.d.ts +0 -30
  202. package/dist/evaluation/comparison.d.ts.map +0 -1
  203. package/dist/evaluation/comparison.js +0 -108
  204. package/dist/evaluation/contracts.d.ts +0 -301
  205. package/dist/evaluation/contracts.d.ts.map +0 -1
  206. package/dist/evaluation/contracts.js +0 -413
  207. package/dist/graph/graph-store.d.ts +0 -55
  208. package/dist/graph/graph-store.d.ts.map +0 -1
  209. package/dist/graph/graph-store.js +0 -912
  210. package/dist/graph/types.d.ts +0 -189
  211. package/dist/graph/types.d.ts.map +0 -1
  212. package/dist/graph/types.js +0 -1
  213. package/dist/insights/contracts.d.ts +0 -266
  214. package/dist/insights/contracts.d.ts.map +0 -1
  215. package/dist/insights/contracts.js +0 -124
  216. package/dist/insights/insights-store.d.ts +0 -73
  217. package/dist/insights/insights-store.d.ts.map +0 -1
  218. package/dist/insights/insights-store.js +0 -246
  219. package/dist/knowledge/business-knowledge-service.d.ts +0 -24
  220. package/dist/knowledge/business-knowledge-service.d.ts.map +0 -1
  221. package/dist/knowledge/business-knowledge-service.js +0 -200
  222. package/dist/knowledge/graph-patch-conflict-error.d.ts +0 -8
  223. package/dist/knowledge/graph-patch-conflict-error.d.ts.map +0 -1
  224. package/dist/knowledge/graph-patch-conflict-error.js +0 -12
  225. package/dist/knowledge/structural-target-binding.d.ts +0 -14
  226. package/dist/knowledge/structural-target-binding.d.ts.map +0 -1
  227. package/dist/knowledge/structural-target-binding.js +0 -11
  228. package/dist/package-metadata.d.ts +0 -2
  229. package/dist/package-metadata.d.ts.map +0 -1
  230. package/dist/package-metadata.js +0 -9
  231. package/dist/repository/git-command.d.ts +0 -3
  232. package/dist/repository/git-command.d.ts.map +0 -1
  233. package/dist/repository/git-command.js +0 -25
  234. package/dist/repository/repository-inspector.d.ts +0 -7
  235. package/dist/repository/repository-inspector.d.ts.map +0 -1
  236. package/dist/repository/repository-inspector.js +0 -84
  237. package/dist/repository/repository-language-support.d.ts +0 -14
  238. package/dist/repository/repository-language-support.d.ts.map +0 -1
  239. package/dist/repository/repository-language-support.js +0 -64
  240. package/dist/repository/types.d.ts +0 -9
  241. package/dist/repository/types.d.ts.map +0 -1
  242. package/dist/repository/types.js +0 -1
  243. package/dist/runtime/sqlite-compatibility-process.d.ts +0 -8
  244. package/dist/runtime/sqlite-compatibility-process.d.ts.map +0 -1
  245. package/dist/runtime/sqlite-compatibility-process.js +0 -20
  246. package/dist/setup/skill-installer.d.ts +0 -20
  247. package/dist/setup/skill-installer.d.ts.map +0 -1
  248. package/dist/setup/skill-installer.js +0 -187
  249. package/dist/snapshots/repository-snapshot.d.ts +0 -4
  250. package/dist/snapshots/repository-snapshot.d.ts.map +0 -1
  251. package/dist/snapshots/repository-snapshot.js +0 -119
  252. package/dist/snapshots/types.d.ts +0 -30
  253. package/dist/snapshots/types.d.ts.map +0 -1
  254. package/dist/snapshots/types.js +0 -1
  255. package/dist/storage/atlas-database.d.ts +0 -19
  256. package/dist/storage/atlas-database.d.ts.map +0 -1
  257. package/dist/storage/atlas-database.js +0 -433
  258. package/dist/storage/snapshot-store.d.ts +0 -19
  259. package/dist/storage/snapshot-store.d.ts.map +0 -1
  260. package/dist/storage/snapshot-store.js +0 -74
  261. package/dist/structural-backend/codegraph-backend.d.ts +0 -57
  262. package/dist/structural-backend/codegraph-backend.d.ts.map +0 -1
  263. package/dist/structural-backend/codegraph-backend.js +0 -1230
  264. package/dist/structural-backend/codegraph-worker-client.d.ts +0 -5
  265. package/dist/structural-backend/codegraph-worker-client.d.ts.map +0 -1
  266. package/dist/structural-backend/codegraph-worker-client.js +0 -118
  267. package/dist/structural-backend/codegraph-worker-protocol.d.ts +0 -35
  268. package/dist/structural-backend/codegraph-worker-protocol.d.ts.map +0 -1
  269. package/dist/structural-backend/codegraph-worker-protocol.js +0 -1
  270. package/dist/structural-backend/codegraph-worker.d.ts +0 -2
  271. package/dist/structural-backend/codegraph-worker.d.ts.map +0 -1
  272. package/dist/structural-backend/codegraph-worker.js +0 -131
  273. package/dist/structural-backend/process-instance.d.ts +0 -18
  274. package/dist/structural-backend/process-instance.d.ts.map +0 -1
  275. package/dist/structural-backend/process-instance.js +0 -207
  276. package/dist/structural-backend/structural-fact-changes.d.ts +0 -7
  277. package/dist/structural-backend/structural-fact-changes.d.ts.map +0 -1
  278. package/dist/structural-backend/structural-fact-changes.js +0 -78
  279. package/dist/structural-backend/structural-projection-bootstrapper.d.ts +0 -10
  280. package/dist/structural-backend/structural-projection-bootstrapper.d.ts.map +0 -1
  281. package/dist/structural-backend/structural-projection-bootstrapper.js +0 -295
  282. package/dist/structural-backend/structural-publication.d.ts +0 -13
  283. package/dist/structural-backend/structural-publication.d.ts.map +0 -1
  284. package/dist/structural-backend/structural-publication.js +0 -255
  285. package/dist/structural-backend/structural-write-lock.d.ts +0 -8
  286. package/dist/structural-backend/structural-write-lock.d.ts.map +0 -1
  287. package/dist/structural-backend/structural-write-lock.js +0 -415
  288. package/dist/structural-backend/types.d.ts +0 -144
  289. package/dist/structural-backend/types.d.ts.map +0 -1
  290. package/dist/structural-backend/types.js +0 -11
  291. package/dist/world/business-map-projector.d.ts +0 -14
  292. package/dist/world/business-map-projector.d.ts.map +0 -1
  293. package/dist/world/business-map-projector.js +0 -178
  294. package/dist/world/types.d.ts +0 -77
  295. package/dist/world/types.d.ts.map +0 -1
  296. package/dist/world/types.js +0 -1
  297. package/dist/world/world-graph-query.d.ts +0 -26
  298. package/dist/world/world-graph-query.d.ts.map +0 -1
  299. package/dist/world/world-graph-query.js +0 -250
  300. package/dist/world/world-model-service.d.ts +0 -21
  301. package/dist/world/world-model-service.d.ts.map +0 -1
  302. package/dist/world/world-model-service.js +0 -219
  303. package/dist/world/world-snapshot-store.d.ts +0 -40
  304. package/dist/world/world-snapshot-store.d.ts.map +0 -1
  305. package/dist/world/world-snapshot-store.js +0 -581
  306. package/docs/README.md +0 -30
  307. package/docs/architecture/codegraph-backend.md +0 -190
  308. package/docs/architecture/continuous-business-learning.md +0 -240
  309. package/docs/contracts/cli-v1.md +0 -164
  310. package/docs/contracts/graph-model.md +0 -106
  311. package/docs/contracts/graph-patch-v1.md +0 -105
  312. package/docs/contracts/insights-v1.md +0 -84
  313. package/docs/log.md +0 -80
  314. package/docs/mindmaps/semantic-atlas-overview.drawio +0 -255
  315. package/docs/mindmaps/semantic-atlas-overview.png +0 -0
  316. package/docs/mindmaps/semantic-atlas-overview.zh-CN.drawio +0 -255
  317. package/docs/mindmaps/semantic-atlas-overview.zh-CN.png +0 -0
  318. package/schemas/cli-envelope-v1.schema.json +0 -1244
  319. package/schemas/evaluation-plan-v1.schema.json +0 -211
  320. package/schemas/evaluation-run-v1.schema.json +0 -659
  321. package/schemas/graph-patch-v1.schema.json +0 -392
  322. package/schemas/insights-envelope-v1.schema.json +0 -428
@@ -1,581 +0,0 @@
1
- import { contentIdentifierSchema } from "../contracts/identifiers.js";
2
- import { isSupportedSource } from "../repository/repository-inspector.js";
3
- import { AtlasDatabase } from "../storage/atlas-database.js";
4
- export class WorldSnapshotStore {
5
- #database;
6
- #repositoryId;
7
- #gitDirectory;
8
- constructor(repository) {
9
- this.#database = new AtlasDatabase(repository);
10
- this.#repositoryId = repository.repositoryId;
11
- this.#gitDirectory = repository.gitDirectory;
12
- }
13
- readState() {
14
- const row = this.connection.prepare(`
15
- SELECT
16
- status,
17
- current_snapshot_id,
18
- target_snapshot_id,
19
- backend_version,
20
- extraction_version,
21
- failure_message,
22
- started_at,
23
- published_at,
24
- updated_at
25
- FROM atlas_worktree_states
26
- WHERE repository_id = ? AND git_directory = ?
27
- `).get(this.#repositoryId, this.#gitDirectory);
28
- return {
29
- status: row.status,
30
- currentSnapshotId: row.current_snapshot_id,
31
- targetSnapshotId: row.target_snapshot_id,
32
- backendVersion: row.backend_version,
33
- extractionVersion: row.extraction_version,
34
- failureMessage: row.failure_message,
35
- startedAt: row.started_at,
36
- publishedAt: row.published_at,
37
- updatedAt: row.updated_at,
38
- };
39
- }
40
- begin(targetSnapshotId) {
41
- const timestamp = new Date().toISOString();
42
- const state = this.readState();
43
- if (state.status === "building" && state.targetSnapshotId === targetSnapshotId) {
44
- return;
45
- }
46
- this.connection.prepare(`
47
- UPDATE atlas_worktree_states
48
- SET
49
- status = 'building',
50
- target_snapshot_id = ?,
51
- failure_message = NULL,
52
- started_at = ?,
53
- published_at = NULL,
54
- updated_at = ?
55
- WHERE repository_id = ? AND git_directory = ?
56
- `).run(targetSnapshotId, timestamp, timestamp, this.#repositoryId, this.#gitDirectory);
57
- }
58
- publish(snapshot, backendVersion, extractionVersion, resolver, changes) {
59
- let result;
60
- this.transaction(() => {
61
- this.requireBuildingSnapshot(snapshot.snapshotId);
62
- const previousPublication = this.readCurrentPublication();
63
- const previousSnapshotId = previousPublication?.snapshot_id ?? null;
64
- if (changes.fromSnapshotId !== previousSnapshotId) {
65
- throw new Error(`World publication starts at ${changes.fromSnapshotId ?? "no snapshot"}, ` +
66
- `but the current publication is ${previousSnapshotId ?? "missing"}`);
67
- }
68
- if (changes.toSnapshotId !== snapshot.snapshotId) {
69
- throw new Error(`World publication target ${changes.toSnapshotId} does not match ` +
70
- `the active snapshot ${snapshot.snapshotId}`);
71
- }
72
- this.saveSnapshot(snapshot);
73
- const staleAssertions = this.rebindEvidence(snapshot, backendVersion, resolver);
74
- staleAssertions.push(...this.rebindStructuralRelationTargets(snapshot, backendVersion, resolver));
75
- const uniqueStaleAssertions = [...new Set(staleAssertions)].sort();
76
- this.refreshValidity(snapshot.snapshotId);
77
- const timestamp = new Date().toISOString();
78
- const publicationId = this.saveWorldPublication(previousPublication?.publication_id ?? null, { ...changes, staleAssertions: uniqueStaleAssertions }, timestamp);
79
- this.connection.prepare(`
80
- UPDATE atlas_worktree_states
81
- SET
82
- status = 'current',
83
- current_snapshot_id = ?,
84
- current_publication_id = ?,
85
- target_snapshot_id = NULL,
86
- backend_version = ?,
87
- extraction_version = ?,
88
- failure_message = NULL,
89
- published_at = ?,
90
- updated_at = ?
91
- WHERE repository_id = ? AND git_directory = ?
92
- `).run(snapshot.snapshotId, publicationId, backendVersion, extractionVersion, timestamp, timestamp, this.#repositoryId, this.#gitDirectory);
93
- result = { staleAssertions: uniqueStaleAssertions };
94
- });
95
- return result;
96
- }
97
- fail(targetSnapshotId, error) {
98
- const timestamp = new Date().toISOString();
99
- this.connection.prepare(`
100
- UPDATE atlas_worktree_states
101
- SET
102
- status = 'failed',
103
- target_snapshot_id = ?,
104
- failure_message = ?,
105
- published_at = NULL,
106
- updated_at = ?
107
- WHERE repository_id = ? AND git_directory = ?
108
- `).run(targetSnapshotId, error instanceof Error ? error.message : String(error), timestamp, this.#repositoryId, this.#gitDirectory);
109
- }
110
- requireCurrentSnapshot() {
111
- return this.requireCurrentWorld().snapshot;
112
- }
113
- requireCurrentWorld() {
114
- const state = this.readState();
115
- if (state.status !== "current" || state.currentSnapshotId === null) {
116
- throw new Error(`World snapshot is ${state.status} and cannot serve map queries`);
117
- }
118
- const publication = this.readCurrentPublication();
119
- if (publication === undefined || publication.snapshot_id !== state.currentSnapshotId) {
120
- throw new Error("The current world publication is inconsistent with its snapshot");
121
- }
122
- const row = this.connection.prepare(`
123
- SELECT payload
124
- FROM atlas_repository_snapshots
125
- WHERE repository_id = ? AND snapshot_id = ?
126
- `).get(this.#repositoryId, state.currentSnapshotId);
127
- if (row === undefined) {
128
- throw new Error("The current world snapshot record is missing");
129
- }
130
- return {
131
- publicationId: publication.publication_id,
132
- snapshot: JSON.parse(row.payload),
133
- };
134
- }
135
- readSemanticChanges(options = {}) {
136
- const requestedStart = options.fromSnapshotId === undefined
137
- ? undefined
138
- : contentIdentifierSchema.parse(options.fromSnapshotId);
139
- const requestedTarget = options.toSnapshotId === undefined
140
- ? undefined
141
- : contentIdentifierSchema.parse(options.toSnapshotId);
142
- const currentPublication = this.readCurrentPublication();
143
- if (currentPublication === undefined) {
144
- return undefined;
145
- }
146
- const targetPublication = requestedTarget === undefined
147
- ? currentPublication
148
- : this.findPublication(currentPublication, requestedTarget);
149
- if (targetPublication === undefined) {
150
- return undefined;
151
- }
152
- const target = targetPublication.snapshot_id;
153
- const previousPublication = this.readPreviousPublication(targetPublication);
154
- const startPublication = requestedStart === undefined
155
- ? previousPublication
156
- : requestedStart === target
157
- ? targetPublication
158
- : previousPublication === undefined
159
- ? undefined
160
- : this.findPublication(previousPublication, requestedStart);
161
- if (startPublication === undefined) {
162
- if (requestedStart !== undefined) {
163
- throw new Error(`No persisted semantic transition connects ${requestedStart} to ${target}`);
164
- }
165
- return undefined;
166
- }
167
- const start = startPublication.snapshot_id;
168
- const nodes = compareSnapshotContents(this.readSnapshot(start), this.readSnapshot(target));
169
- return {
170
- fromSnapshotId: start,
171
- toSnapshotId: target,
172
- nodes,
173
- relations: { added: [], changed: [], removed: [] },
174
- staleAssertions: parseStringArray(targetPublication.stale_assertions),
175
- };
176
- }
177
- readCurrentPublication() {
178
- const row = this.connection.prepare(`
179
- SELECT current_publication_id
180
- FROM atlas_worktree_states
181
- WHERE repository_id = ? AND git_directory = ?
182
- `).get(this.#repositoryId, this.#gitDirectory);
183
- return row.current_publication_id === null
184
- ? undefined
185
- : this.requirePublication(row.current_publication_id);
186
- }
187
- readPublication(publicationId) {
188
- return this.connection.prepare(`
189
- SELECT
190
- publication_id,
191
- previous_publication_id,
192
- snapshot_id,
193
- stale_assertions
194
- FROM atlas_world_publications
195
- WHERE repository_id = ? AND git_directory = ? AND publication_id = ?
196
- `).get(this.#repositoryId, this.#gitDirectory, publicationId);
197
- }
198
- requirePublication(publicationId) {
199
- const publication = this.readPublication(publicationId);
200
- if (publication === undefined) {
201
- throw new Error(`World publication ${publicationId} is not stored`);
202
- }
203
- return publication;
204
- }
205
- readPreviousPublication(publication) {
206
- const previousPublicationId = publication.previous_publication_id;
207
- if (previousPublicationId === null) {
208
- return undefined;
209
- }
210
- if (previousPublicationId === publication.publication_id) {
211
- throw new Error(`Persisted world publication chain contains a cycle at ${publication.publication_id}`);
212
- }
213
- return this.requirePublication(previousPublicationId);
214
- }
215
- findPublication(target, snapshotId) {
216
- const visitedPublications = new Set();
217
- let publication = target;
218
- while (publication !== undefined) {
219
- if (visitedPublications.has(publication.publication_id)) {
220
- throw new Error(`Persisted world publication chain contains a cycle at ${publication.publication_id}`);
221
- }
222
- visitedPublications.add(publication.publication_id);
223
- if (publication.snapshot_id === snapshotId) {
224
- return publication;
225
- }
226
- publication = this.readPreviousPublication(publication);
227
- }
228
- return undefined;
229
- }
230
- readSnapshot(snapshotId) {
231
- const row = this.connection.prepare(`
232
- SELECT payload
233
- FROM atlas_repository_snapshots
234
- WHERE repository_id = ? AND snapshot_id = ?
235
- `).get(this.#repositoryId, snapshotId);
236
- if (row === undefined) {
237
- throw new Error(`Repository snapshot ${snapshotId} is not stored`);
238
- }
239
- return JSON.parse(row.payload);
240
- }
241
- close() {
242
- this.#database.close();
243
- }
244
- [Symbol.dispose]() {
245
- this.close();
246
- }
247
- get connection() {
248
- return this.#database.connection;
249
- }
250
- transaction(operation) {
251
- this.connection.exec("BEGIN IMMEDIATE");
252
- try {
253
- operation();
254
- this.connection.exec("COMMIT");
255
- }
256
- catch (error) {
257
- this.connection.exec("ROLLBACK");
258
- throw error;
259
- }
260
- }
261
- requireBuildingSnapshot(snapshotId) {
262
- const state = this.readState();
263
- if (state.status !== "building" || state.targetSnapshotId !== snapshotId) {
264
- throw new Error(`World snapshot ${snapshotId} is not the active build target`);
265
- }
266
- }
267
- saveSnapshot(snapshot) {
268
- const timestamp = new Date().toISOString();
269
- this.connection.prepare(`
270
- INSERT INTO atlas_repository_snapshots (
271
- repository_id,
272
- snapshot_id,
273
- payload,
274
- created_at
275
- ) VALUES (?, ?, ?, ?)
276
- ON CONFLICT (repository_id, snapshot_id) DO UPDATE SET
277
- payload = excluded.payload
278
- `).run(this.#repositoryId, snapshot.snapshotId, JSON.stringify(snapshot), timestamp);
279
- }
280
- rebindEvidence(snapshot, backendVersion, resolver) {
281
- const staleAssertions = [];
282
- const bindings = [
283
- ...this.rebindEvidenceTable("atlas_business_node_evidence", "node_id", snapshot, backendVersion, resolver),
284
- ...this.rebindEvidenceTable("atlas_business_relation_evidence", "relation_id", snapshot, backendVersion, resolver),
285
- ];
286
- for (const binding of bindings) {
287
- if (binding.status !== "bound") {
288
- staleAssertions.push(this.assertionIdentity(binding.ownerType, binding.ownerId));
289
- }
290
- }
291
- return [...new Set(staleAssertions)].sort();
292
- }
293
- assertionIdentity(ownerType, ownerId) {
294
- if (ownerType === "node") {
295
- const row = this.connection.prepare(`
296
- SELECT node_key
297
- FROM atlas_business_nodes
298
- WHERE node_id = ?
299
- `).get(ownerId);
300
- return row.node_key;
301
- }
302
- const row = this.connection.prepare(`
303
- SELECT from_key, relation_type, to_domain, to_key
304
- FROM atlas_business_relations
305
- WHERE relation_id = ?
306
- `).get(ownerId);
307
- return `${row.from_key}:${row.relation_type}:${row.to_domain}:${row.to_key}`;
308
- }
309
- rebindEvidenceTable(table, ownerColumn, snapshot, backendVersion, resolver) {
310
- const rows = this.connection.prepare(`
311
- SELECT
312
- ${ownerColumn} AS owner_id,
313
- position,
314
- structural_reference,
315
- file,
316
- qualified_symbol,
317
- structural_kind,
318
- start_line,
319
- start_column,
320
- end_line,
321
- end_column,
322
- content_hash,
323
- backend_locator
324
- FROM ${table}
325
- ORDER BY ${ownerColumn}, position
326
- `).all();
327
- const ownerType = ownerColumn === "node_id" ? "node" : "relation";
328
- const bindingTable = ownerColumn === "node_id"
329
- ? "atlas_business_node_evidence_bindings"
330
- : "atlas_business_relation_evidence_bindings";
331
- return rows.map((row) => {
332
- const locator = locatorFromRow(row);
333
- const match = this.resolveEvidence(locator, resolver);
334
- const source = snapshot.files.find((file) => file.path === row.file)?.worktree;
335
- const hashMatches = source !== null && source !== undefined && source.contentHash === row.content_hash;
336
- const status = match.status === "bound" && hashMatches
337
- ? "bound"
338
- : match.status === "bound"
339
- ? "missing"
340
- : match.status;
341
- this.connection.prepare(`
342
- INSERT INTO ${bindingTable} (
343
- ${ownerColumn},
344
- position,
345
- repository_id,
346
- snapshot_id,
347
- resolved_structural_reference,
348
- resolved_qualified_symbol,
349
- resolved_structural_kind,
350
- backend_version,
351
- backend_locator,
352
- binding_status
353
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
354
- ON CONFLICT (${ownerColumn}, position, snapshot_id) DO UPDATE SET
355
- resolved_structural_reference = excluded.resolved_structural_reference,
356
- resolved_qualified_symbol = excluded.resolved_qualified_symbol,
357
- resolved_structural_kind = excluded.resolved_structural_kind,
358
- backend_version = excluded.backend_version,
359
- backend_locator = excluded.backend_locator,
360
- binding_status = excluded.binding_status
361
- `).run(row.owner_id, row.position, this.#repositoryId, snapshot.snapshotId, match.node?.reference.id ?? null, match.node?.qualifiedName ?? null, match.node?.kind ?? null, backendVersion, match.node === undefined ? null : resolver.backendLocator(match.node) ?? null, status);
362
- return { ownerType, ownerId: row.owner_id, status };
363
- });
364
- }
365
- rebindStructuralRelationTargets(snapshot, backendVersion, resolver) {
366
- const rows = this.connection.prepare(`
367
- SELECT
368
- relation_id,
369
- from_key,
370
- relation_type,
371
- to_key,
372
- target_file,
373
- target_qualified_symbol,
374
- target_structural_kind,
375
- target_start_line,
376
- target_start_column,
377
- target_end_line,
378
- target_end_column,
379
- target_backend_locator
380
- FROM atlas_business_relations
381
- WHERE repository_id = ? AND to_domain = 'structural'
382
- ORDER BY relation_id
383
- `).all(this.#repositoryId);
384
- const staleAssertions = [];
385
- for (const row of rows) {
386
- const locator = structuralTargetLocatorFromRow(row);
387
- const match = locator === undefined
388
- ? { status: "unresolved" }
389
- : this.resolveStructuralLocator(locator, resolver);
390
- const identity = `${row.from_key}:${row.relation_type}:structural:${row.to_key}`;
391
- if (match.status !== "bound") {
392
- staleAssertions.push(identity);
393
- }
394
- this.connection.prepare(`
395
- INSERT INTO atlas_structural_relation_target_bindings (
396
- relation_id,
397
- repository_id,
398
- snapshot_id,
399
- resolved_structural_reference,
400
- resolved_file,
401
- resolved_qualified_symbol,
402
- resolved_structural_kind,
403
- resolved_start_line,
404
- resolved_start_column,
405
- resolved_end_line,
406
- resolved_end_column,
407
- backend_version,
408
- backend_locator,
409
- binding_status
410
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
411
- ON CONFLICT (relation_id, snapshot_id) DO UPDATE SET
412
- resolved_structural_reference = excluded.resolved_structural_reference,
413
- resolved_file = excluded.resolved_file,
414
- resolved_qualified_symbol = excluded.resolved_qualified_symbol,
415
- resolved_structural_kind = excluded.resolved_structural_kind,
416
- resolved_start_line = excluded.resolved_start_line,
417
- resolved_start_column = excluded.resolved_start_column,
418
- resolved_end_line = excluded.resolved_end_line,
419
- resolved_end_column = excluded.resolved_end_column,
420
- backend_version = excluded.backend_version,
421
- backend_locator = excluded.backend_locator,
422
- binding_status = excluded.binding_status
423
- `).run(row.relation_id, this.#repositoryId, snapshot.snapshotId, match.node?.reference.id ?? null, match.node?.path ?? null, match.node?.qualifiedName ?? null, match.node?.kind ?? null, match.node?.range.start.line ?? null, match.node?.range.start.column ?? null, match.node?.range.end.line ?? null, match.node?.range.end.column ?? null, backendVersion, match.node === undefined ? null : resolver.backendLocator(match.node) ?? null, match.status);
424
- }
425
- return staleAssertions;
426
- }
427
- resolveEvidence(locator, resolver) {
428
- return this.resolveStructuralLocator(locator, resolver);
429
- }
430
- resolveStructuralLocator(locator, resolver) {
431
- const directlyLocated = resolver.getNode(locator.structuralReference);
432
- if (directlyLocated !== undefined && nodeMatchesLocator(directlyLocated, locator)) {
433
- return { status: "bound", node: directlyLocated };
434
- }
435
- const candidates = resolver.findCandidates(locator).filter((node) => nodeMatchesLocator(node, locator));
436
- if (candidates.length === 1) {
437
- return { status: "bound", node: candidates[0] };
438
- }
439
- return { status: candidates.length === 0 ? "missing" : "ambiguous" };
440
- }
441
- refreshValidity(snapshotId) {
442
- this.refreshValidityTable("atlas_business_nodes", "atlas_business_node_evidence", "atlas_business_node_evidence_bindings", "atlas_business_node_validity", "node_id", snapshotId);
443
- this.refreshValidityTable("atlas_business_relations", "atlas_business_relation_evidence", "atlas_business_relation_evidence_bindings", "atlas_business_relation_validity", "relation_id", snapshotId);
444
- }
445
- refreshValidityTable(ownerTable, evidenceTable, bindingTable, validityTable, ownerColumn, snapshotId) {
446
- const owners = this.connection.prepare(`
447
- SELECT ${ownerColumn} AS owner_id
448
- FROM ${ownerTable}
449
- WHERE repository_id = ?
450
- `).all(this.#repositoryId);
451
- for (const { owner_id } of owners) {
452
- const row = this.connection.prepare(`
453
- SELECT
454
- COUNT(*) AS evidence_count,
455
- SUM(CASE WHEN binding.binding_status = 'bound' THEN 1 ELSE 0 END) AS bound_count
456
- FROM ${evidenceTable} AS evidence
457
- LEFT JOIN ${bindingTable} AS binding
458
- ON binding.${ownerColumn} = evidence.${ownerColumn}
459
- AND binding.position = evidence.position
460
- AND binding.snapshot_id = ?
461
- WHERE evidence.${ownerColumn} = ?
462
- `).get(snapshotId, owner_id);
463
- const validity = row.evidence_count > 0 && row.evidence_count === row.bound_count
464
- ? "valid"
465
- : "stale";
466
- const targetBindingStatus = ownerColumn === "relation_id"
467
- ? this.connection.prepare(`
468
- SELECT relation.to_domain, binding.binding_status AS target_binding_status
469
- FROM atlas_business_relations AS relation
470
- LEFT JOIN atlas_structural_relation_target_bindings AS binding
471
- ON binding.relation_id = relation.relation_id
472
- AND binding.snapshot_id = ?
473
- WHERE relation.relation_id = ?
474
- `).get(snapshotId, owner_id)
475
- : undefined;
476
- const targetIsBound = targetBindingStatus === undefined
477
- || targetBindingStatus.to_domain === "business"
478
- || targetBindingStatus.target_binding_status === "bound";
479
- const derivedValidity = targetIsBound
480
- ? validity
481
- : "stale";
482
- this.connection.prepare(`
483
- INSERT INTO ${validityTable} (${ownerColumn}, repository_id, snapshot_id, validity)
484
- VALUES (?, ?, ?, ?)
485
- ON CONFLICT (${ownerColumn}, snapshot_id) DO UPDATE SET validity = excluded.validity
486
- `).run(owner_id, this.#repositoryId, snapshotId, derivedValidity);
487
- }
488
- }
489
- saveWorldPublication(previousPublicationId, changes, timestamp) {
490
- const result = this.connection.prepare(`
491
- INSERT INTO atlas_world_publications (
492
- repository_id,
493
- git_directory,
494
- previous_publication_id,
495
- snapshot_id,
496
- added_paths,
497
- modified_paths,
498
- removed_paths,
499
- stale_assertions,
500
- published_at
501
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
502
- `).run(this.#repositoryId, this.#gitDirectory, previousPublicationId, changes.toSnapshotId, JSON.stringify(changes.structural.added), JSON.stringify(changes.structural.modified), JSON.stringify(changes.structural.removed), JSON.stringify(changes.staleAssertions), timestamp);
503
- return Number(result.lastInsertRowid);
504
- }
505
- }
506
- function locatorFromRow(row) {
507
- return {
508
- structuralReference: row.structural_reference,
509
- file: row.file,
510
- qualifiedSymbol: row.qualified_symbol,
511
- structuralKind: row.structural_kind,
512
- range: {
513
- start: { line: row.start_line, column: row.start_column },
514
- end: { line: row.end_line, column: row.end_column },
515
- },
516
- contentHash: row.content_hash,
517
- ...(row.backend_locator === null ? {} : { backendLocator: row.backend_locator }),
518
- };
519
- }
520
- function compareSnapshotContents(from, to) {
521
- const fromFiles = snapshotContents(from);
522
- const toFiles = snapshotContents(to);
523
- const added = [];
524
- const changed = [];
525
- const removed = [];
526
- const paths = new Set([...fromFiles.keys(), ...toFiles.keys()]);
527
- for (const path of [...paths].sort()) {
528
- const before = fromFiles.get(path);
529
- const after = toFiles.get(path);
530
- const reference = `file:${path}`;
531
- if (before === undefined && after !== undefined) {
532
- added.push(reference);
533
- }
534
- else if (before !== undefined && after === undefined) {
535
- removed.push(reference);
536
- }
537
- else if (before !== undefined && after !== undefined && before !== after) {
538
- changed.push(reference);
539
- }
540
- }
541
- return { added, changed, removed };
542
- }
543
- function snapshotContents(snapshot) {
544
- return new Map(snapshot.files.flatMap((file) => (file.worktree === null || !isSupportedSource(file.path)
545
- ? []
546
- : [[file.path, file.worktree.contentHash]])));
547
- }
548
- function parseStringArray(value) {
549
- return JSON.parse(value);
550
- }
551
- function structuralTargetLocatorFromRow(row) {
552
- if (row.target_file === null
553
- || row.target_start_line === null
554
- || row.target_start_column === null
555
- || row.target_end_line === null
556
- || row.target_end_column === null) {
557
- return undefined;
558
- }
559
- return {
560
- structuralReference: row.to_key,
561
- file: row.target_file,
562
- qualifiedSymbol: row.target_qualified_symbol,
563
- structuralKind: row.target_structural_kind,
564
- range: {
565
- start: { line: row.target_start_line, column: row.target_start_column },
566
- end: { line: row.target_end_line, column: row.target_end_column },
567
- },
568
- ...(row.target_backend_locator === null
569
- ? {}
570
- : { backendLocator: row.target_backend_locator }),
571
- };
572
- }
573
- function nodeMatchesLocator(node, locator) {
574
- return node.path === locator.file
575
- && (locator.qualifiedSymbol === null || node.qualifiedName === locator.qualifiedSymbol)
576
- && (locator.structuralKind === null || node.kind === locator.structuralKind)
577
- && node.range.start.line === locator.range.start.line
578
- && node.range.start.column === locator.range.start.column
579
- && node.range.end.line === locator.range.end.line
580
- && node.range.end.column === locator.range.end.column;
581
- }
package/docs/README.md DELETED
@@ -1,30 +0,0 @@
1
- # Semantic Atlas Knowledge Base
2
-
3
- This directory is the maintained knowledge layer for Semantic Atlas product
4
- contracts, architecture, graph semantics, evaluation, and agent workflows. It
5
- answers how the product behaves and why its boundaries exist; source code,
6
- tests, generated schemas, and released artifacts remain the authority for the
7
- current implementation.
8
-
9
- Use [the documentation index](index.md) to find the owning page for a topic.
10
- When a design changes, revise that owning page, update affected contracts and
11
- incoming links, and record the knowledge change in [the maintenance log](log.md).
12
-
13
- ## Source boundary
14
-
15
- - Product decisions come from accepted design discussions and are expressed in
16
- the product and graph contracts.
17
- - Runtime claims are verified against source, tests, packaged CLI behavior, and
18
- generated schemas.
19
- - CodeGraph documentation describes an internal structural dependency; Semantic
20
- Atlas public behavior remains owned by this repository.
21
- - Unknown behavior and planned work stay explicitly marked rather than being
22
- presented as implemented capability.
23
-
24
- ## Maintenance rules
25
-
26
- - Keep one authoritative page for each stable topic and link to it elsewhere.
27
- - Start pages with the question they answer, their scope, and current status.
28
- - Revise current conclusions in place; use `log.md` for chronology.
29
- - Keep public documentation free of private repositories, internal operational
30
- measurements, and maintainer-only delivery details.