semantic-atlas 0.1.1 → 0.1.3

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 (36) hide show
  1. package/.agents/skills/semantic-atlas/SKILL.md +2 -2
  2. package/.agents/skills/semantic-atlas/references/snapshot-bootstrap.md +5 -1
  3. package/README.md +98 -51
  4. package/README.zh-CN.md +167 -0
  5. package/dist/cli/cli-application.d.ts.map +1 -1
  6. package/dist/cli/cli-application.js +5 -5
  7. package/dist/graph/graph-store.d.ts +6 -0
  8. package/dist/graph/graph-store.d.ts.map +1 -1
  9. package/dist/graph/graph-store.js +261 -114
  10. package/dist/storage/atlas-database.d.ts +6 -2
  11. package/dist/storage/atlas-database.d.ts.map +1 -1
  12. package/dist/storage/atlas-database.js +388 -514
  13. package/dist/storage/snapshot-store.d.ts.map +1 -1
  14. package/dist/storage/snapshot-store.js +7 -10
  15. package/dist/structural-backend/codegraph-backend.d.ts +4 -1
  16. package/dist/structural-backend/codegraph-backend.d.ts.map +1 -1
  17. package/dist/structural-backend/codegraph-backend.js +10 -4
  18. package/dist/structural-backend/structural-projection-bootstrapper.d.ts +10 -0
  19. package/dist/structural-backend/structural-projection-bootstrapper.d.ts.map +1 -0
  20. package/dist/structural-backend/structural-projection-bootstrapper.js +295 -0
  21. package/dist/structural-backend/structural-publication.d.ts +1 -0
  22. package/dist/structural-backend/structural-publication.d.ts.map +1 -1
  23. package/dist/structural-backend/structural-publication.js +5 -2
  24. package/dist/world/world-model-service.d.ts.map +1 -1
  25. package/dist/world/world-model-service.js +14 -6
  26. package/dist/world/world-snapshot-store.d.ts.map +1 -1
  27. package/dist/world/world-snapshot-store.js +92 -66
  28. package/docs/architecture/codegraph-backend.md +26 -29
  29. package/docs/contracts/cli-v1.md +2 -1
  30. package/docs/contracts/graph-model.md +2 -2
  31. package/docs/mindmaps/semantic-atlas-overview.drawio +255 -0
  32. package/docs/mindmaps/semantic-atlas-overview.png +0 -0
  33. package/docs/mindmaps/semantic-atlas-overview.zh-CN.drawio +255 -0
  34. package/docs/mindmaps/semantic-atlas-overview.zh-CN.png +0 -0
  35. package/docs/product-contract.md +20 -17
  36. package/package.json +1 -1
@@ -6,10 +6,12 @@ export class GraphStore {
6
6
  databasePath;
7
7
  #atlasDatabase;
8
8
  #repositoryId;
9
+ #gitDirectory;
9
10
  constructor(repository) {
10
11
  this.#atlasDatabase = new AtlasDatabase(repository);
11
12
  this.databasePath = this.#atlasDatabase.databasePath;
12
13
  this.#repositoryId = repository.repositoryId;
14
+ this.#gitDirectory = repository.gitDirectory;
13
15
  }
14
16
  get schemaVersion() {
15
17
  return this.#atlasDatabase.schemaVersion;
@@ -18,6 +20,7 @@ export class GraphStore {
18
20
  contentIdentifierSchema.parse(snapshotId);
19
21
  this.transaction(() => {
20
22
  const snapshot = this.requireSnapshot(snapshotId);
23
+ this.reconcileEvidenceBindings(snapshot);
21
24
  this.refreshBusinessValidity(snapshot);
22
25
  });
23
26
  }
@@ -47,16 +50,17 @@ export class GraphStore {
47
50
  : undefined;
48
51
  }
49
52
  getEvidence(owner) {
53
+ const snapshotId = this.currentSnapshotId();
50
54
  if (owner.type === "node") {
51
55
  const nodeId = this.findBusinessNodeId(owner.node.key);
52
- return nodeId === undefined ? [] : this.readNodeEvidence(nodeId);
56
+ return nodeId === undefined ? [] : this.readNodeEvidence(nodeId, snapshotId);
53
57
  }
54
58
  const relation = this.findBusinessRelation(owner.relation);
55
- return relation === undefined ? [] : this.readRelationEvidence(relation.relation_id);
59
+ return relation === undefined ? [] : this.readRelationEvidence(relation.relation_id, snapshotId);
56
60
  }
57
61
  listBusinessRelations(snapshotId) {
58
62
  contentIdentifierSchema.parse(snapshotId);
59
- return this.readBusinessRelations(snapshotId).map((row) => this.relationFromRow(row));
63
+ return this.readBusinessRelations(snapshotId).map((row) => this.relationFromRow(row, snapshotId));
60
64
  }
61
65
  listCapabilityRoots(snapshotId) {
62
66
  contentIdentifierSchema.parse(snapshotId);
@@ -274,7 +278,7 @@ export class GraphStore {
274
278
  `).run(nodeId, position, alias);
275
279
  });
276
280
  node.evidence.forEach((evidence, position) => {
277
- this.insertNodeEvidence(nodeId, position, evidence);
281
+ this.insertNodeEvidence(nodeId, position, evidence, baseSnapshotId);
278
282
  });
279
283
  this.database.prepare(`
280
284
  INSERT INTO atlas_graph_search (
@@ -305,54 +309,59 @@ export class GraphStore {
305
309
  const target = relation.to.domain === "structural"
306
310
  ? readStructuralTargetBinding(relation) ?? inferredStructuralTarget(relation, baseSnapshotId)
307
311
  : undefined;
308
- this.database.prepare(`
309
- INSERT INTO atlas_business_relations (
310
- repository_id,
311
- base_snapshot_id,
312
- from_key,
313
- relation_type,
314
- to_domain,
315
- to_key,
316
- certainty,
317
- target_file,
318
- target_qualified_symbol,
319
- target_structural_kind,
320
- target_start_line,
321
- target_start_column,
322
- target_end_line,
323
- target_end_column,
324
- target_atlas_snapshot_id,
325
- target_backend_version,
326
- target_backend_locator,
327
- target_binding_status
328
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
329
- ON CONFLICT (repository_id, from_key, relation_type, to_domain, to_key)
330
- DO UPDATE SET
331
- base_snapshot_id = excluded.base_snapshot_id,
332
- certainty = excluded.certainty,
333
- target_file = excluded.target_file,
334
- target_qualified_symbol = excluded.target_qualified_symbol,
335
- target_structural_kind = excluded.target_structural_kind,
336
- target_start_line = excluded.target_start_line,
337
- target_start_column = excluded.target_start_column,
338
- target_end_line = excluded.target_end_line,
339
- target_end_column = excluded.target_end_column,
340
- target_atlas_snapshot_id = excluded.target_atlas_snapshot_id,
341
- target_backend_version = excluded.target_backend_version,
342
- target_backend_locator = excluded.target_backend_locator,
343
- target_binding_status = excluded.target_binding_status
344
- `).run(this.#repositoryId, baseSnapshotId, relation.from.key, relation.type, relation.to.domain, targetKey, relation.certainty, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.atlasSnapshotId ?? null, target?.backendVersion ?? null, target?.backendLocator ?? null, target === undefined ? "unresolved" : "bound");
345
- const stored = this.findBusinessRelation(relation);
346
- if (stored === undefined) {
347
- throw new Error("Business relation was not stored");
348
- }
312
+ const relationId = this.storeBusinessRelation(baseSnapshotId, relation, targetKey, target);
349
313
  this.database.prepare(`
350
314
  DELETE FROM atlas_business_relation_evidence
351
315
  WHERE relation_id = ?
352
- `).run(stored.relation_id);
316
+ `).run(relationId);
353
317
  relation.evidence.forEach((evidence, position) => {
354
- this.insertRelationEvidence(stored.relation_id, position, evidence);
318
+ this.insertRelationEvidence(relationId, position, evidence, baseSnapshotId);
355
319
  });
320
+ if (relation.to.domain === "structural") {
321
+ this.insertStructuralTargetBinding(relationId, baseSnapshotId, target);
322
+ }
323
+ }
324
+ storeBusinessRelation(baseSnapshotId, relation, targetKey, target) {
325
+ const existing = this.findBusinessRelation(relation);
326
+ if (existing === undefined) {
327
+ const result = this.database.prepare(`
328
+ INSERT INTO atlas_business_relations (
329
+ repository_id,
330
+ base_snapshot_id,
331
+ from_key,
332
+ relation_type,
333
+ to_domain,
334
+ to_key,
335
+ certainty,
336
+ target_file,
337
+ target_qualified_symbol,
338
+ target_structural_kind,
339
+ target_start_line,
340
+ target_start_column,
341
+ target_end_line,
342
+ target_end_column,
343
+ target_backend_locator
344
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
345
+ `).run(this.#repositoryId, baseSnapshotId, relation.from.key, relation.type, relation.to.domain, targetKey, relation.certainty, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.backendLocator ?? null);
346
+ return Number(result.lastInsertRowid);
347
+ }
348
+ this.database.prepare(`
349
+ UPDATE atlas_business_relations
350
+ SET
351
+ base_snapshot_id = ?,
352
+ to_key = ?,
353
+ certainty = ?,
354
+ target_file = ?,
355
+ target_qualified_symbol = ?,
356
+ target_structural_kind = ?,
357
+ target_start_line = ?,
358
+ target_start_column = ?,
359
+ target_end_line = ?,
360
+ target_end_column = ?,
361
+ target_backend_locator = ?
362
+ WHERE relation_id = ?
363
+ `).run(baseSnapshotId, targetKey, relation.certainty, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.backendLocator ?? null, existing.relation_id);
364
+ return existing.relation_id;
356
365
  }
357
366
  removeBusinessNode(key) {
358
367
  this.requireBusinessNodeId(key);
@@ -382,7 +391,7 @@ export class GraphStore {
382
391
  .run(relation.relation_id);
383
392
  }
384
393
  }
385
- insertNodeEvidence(nodeId, position, evidence) {
394
+ insertNodeEvidence(nodeId, position, evidence, snapshotId) {
386
395
  this.database.prepare(`
387
396
  INSERT INTO atlas_business_node_evidence (
388
397
  node_id,
@@ -396,14 +405,12 @@ export class GraphStore {
396
405
  content_hash,
397
406
  qualified_symbol,
398
407
  structural_kind,
399
- atlas_snapshot_id,
400
- backend_version,
401
- backend_locator,
402
- binding_status
403
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'bound')
404
- `).run(nodeId, position, evidence.symbolId, evidence.file, evidence.range.start.line, evidence.range.start.column, evidence.range.end.line, evidence.range.end.column, evidence.contentHash, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.atlasSnapshotId ?? null, evidence.backendVersion ?? null, evidence.backendLocator ?? null);
408
+ backend_locator
409
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
410
+ `).run(nodeId, position, evidence.symbolId, evidence.file, evidence.range.start.line, evidence.range.start.column, evidence.range.end.line, evidence.range.end.column, evidence.contentHash, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.backendLocator ?? null);
411
+ this.insertEvidenceBinding("atlas_business_node_evidence_bindings", "node_id", nodeId, position, snapshotId, evidence);
405
412
  }
406
- insertRelationEvidence(relationId, position, evidence) {
413
+ insertRelationEvidence(relationId, position, evidence, snapshotId) {
407
414
  this.database.prepare(`
408
415
  INSERT INTO atlas_business_relation_evidence (
409
416
  relation_id,
@@ -417,12 +424,58 @@ export class GraphStore {
417
424
  content_hash,
418
425
  qualified_symbol,
419
426
  structural_kind,
420
- atlas_snapshot_id,
427
+ backend_locator
428
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
429
+ `).run(relationId, position, evidence.symbolId, evidence.file, evidence.range.start.line, evidence.range.start.column, evidence.range.end.line, evidence.range.end.column, evidence.contentHash, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.backendLocator ?? null);
430
+ this.insertEvidenceBinding("atlas_business_relation_evidence_bindings", "relation_id", relationId, position, snapshotId, evidence);
431
+ }
432
+ insertEvidenceBinding(table, ownerColumn, ownerId, position, snapshotId, evidence) {
433
+ this.database.prepare(`
434
+ INSERT INTO ${table} (
435
+ ${ownerColumn},
436
+ position,
437
+ repository_id,
438
+ snapshot_id,
439
+ resolved_structural_reference,
440
+ resolved_qualified_symbol,
441
+ resolved_structural_kind,
442
+ backend_version,
443
+ backend_locator,
444
+ binding_status
445
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'bound')
446
+ `).run(ownerId, position, this.#repositoryId, snapshotId, evidence.symbolId, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.backendVersion ?? null, evidence.backendLocator ?? null);
447
+ }
448
+ insertStructuralTargetBinding(relationId, snapshotId, target) {
449
+ this.database.prepare(`
450
+ INSERT INTO atlas_structural_relation_target_bindings (
451
+ relation_id,
452
+ repository_id,
453
+ snapshot_id,
454
+ resolved_structural_reference,
455
+ resolved_file,
456
+ resolved_qualified_symbol,
457
+ resolved_structural_kind,
458
+ resolved_start_line,
459
+ resolved_start_column,
460
+ resolved_end_line,
461
+ resolved_end_column,
421
462
  backend_version,
422
463
  backend_locator,
423
464
  binding_status
424
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'bound')
425
- `).run(relationId, position, evidence.symbolId, evidence.file, evidence.range.start.line, evidence.range.start.column, evidence.range.end.line, evidence.range.end.column, evidence.contentHash, evidence.qualifiedSymbol ?? null, evidence.structuralKind ?? null, evidence.atlasSnapshotId ?? null, evidence.backendVersion ?? null, evidence.backendLocator ?? null);
465
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
466
+ ON CONFLICT (relation_id, snapshot_id) DO UPDATE SET
467
+ resolved_structural_reference = excluded.resolved_structural_reference,
468
+ resolved_file = excluded.resolved_file,
469
+ resolved_qualified_symbol = excluded.resolved_qualified_symbol,
470
+ resolved_structural_kind = excluded.resolved_structural_kind,
471
+ resolved_start_line = excluded.resolved_start_line,
472
+ resolved_start_column = excluded.resolved_start_column,
473
+ resolved_end_line = excluded.resolved_end_line,
474
+ resolved_end_column = excluded.resolved_end_column,
475
+ backend_version = excluded.backend_version,
476
+ backend_locator = excluded.backend_locator,
477
+ binding_status = excluded.binding_status
478
+ `).run(relationId, this.#repositoryId, snapshotId, target?.structuralReference ?? null, target?.file ?? null, target?.qualifiedSymbol ?? null, target?.structuralKind ?? null, target?.range.start.line ?? null, target?.range.start.column ?? null, target?.range.end.line ?? null, target?.range.end.column ?? null, target?.backendVersion ?? null, target?.backendLocator ?? null, target === undefined ? "unresolved" : "bound");
426
479
  }
427
480
  requireEvidence(snapshot, evidence) {
428
481
  this.validateLocation(evidence);
@@ -430,6 +483,17 @@ export class GraphStore {
430
483
  throw new Error(`Evidence ${evidence.symbolId} at ${evidence.file} does not match snapshot ${snapshot.snapshotId}`);
431
484
  }
432
485
  }
486
+ currentSnapshotId() {
487
+ const row = this.database.prepare(`
488
+ SELECT current_snapshot_id
489
+ FROM atlas_worktree_states
490
+ WHERE repository_id = ? AND git_directory = ?
491
+ `).get(this.#repositoryId, this.#gitDirectory);
492
+ if (row.current_snapshot_id === null) {
493
+ throw new Error("The current worktree has no published Atlas snapshot");
494
+ }
495
+ return row.current_snapshot_id;
496
+ }
433
497
  refreshAllBusinessValidity() {
434
498
  const snapshots = this.database.prepare(`
435
499
  SELECT payload
@@ -441,6 +505,55 @@ export class GraphStore {
441
505
  this.refreshBusinessValidity(JSON.parse(payload));
442
506
  }
443
507
  }
508
+ reconcileEvidenceBindings(snapshot) {
509
+ this.reconcileEvidenceBindingTable("atlas_business_node_evidence", "atlas_business_node_evidence_bindings", "node_id", snapshot);
510
+ this.reconcileEvidenceBindingTable("atlas_business_relation_evidence", "atlas_business_relation_evidence_bindings", "relation_id", snapshot);
511
+ }
512
+ reconcileEvidenceBindingTable(evidenceTable, bindingTable, ownerColumn, snapshot) {
513
+ const contentHashes = new Map(snapshot.files.flatMap((file) => (file.worktree === null ? [] : [[file.path, file.worktree.contentHash]])));
514
+ const evidenceRows = this.database.prepare(`
515
+ SELECT ${ownerColumn} AS owner_id, position, file, content_hash
516
+ FROM ${evidenceTable}
517
+ ORDER BY ${ownerColumn}, position
518
+ `).all();
519
+ for (const evidence of evidenceRows) {
520
+ if (contentHashes.get(evidence.file) !== evidence.content_hash) {
521
+ continue;
522
+ }
523
+ this.database.prepare(`
524
+ INSERT INTO ${bindingTable} (
525
+ ${ownerColumn},
526
+ position,
527
+ repository_id,
528
+ snapshot_id,
529
+ resolved_structural_reference,
530
+ resolved_qualified_symbol,
531
+ resolved_structural_kind,
532
+ backend_version,
533
+ backend_locator,
534
+ binding_status
535
+ )
536
+ SELECT
537
+ ${ownerColumn},
538
+ position,
539
+ repository_id,
540
+ ?,
541
+ resolved_structural_reference,
542
+ resolved_qualified_symbol,
543
+ resolved_structural_kind,
544
+ backend_version,
545
+ backend_locator,
546
+ 'bound'
547
+ FROM ${bindingTable}
548
+ WHERE ${ownerColumn} = ?
549
+ AND position = ?
550
+ AND binding_status = 'bound'
551
+ ORDER BY rowid DESC
552
+ LIMIT 1
553
+ ON CONFLICT (${ownerColumn}, position, snapshot_id) DO NOTHING
554
+ `).run(snapshot.snapshotId, evidence.owner_id, evidence.position);
555
+ }
556
+ }
444
557
  refreshBusinessValidity(snapshot) {
445
558
  const nodeRows = this.database.prepare(`
446
559
  SELECT node_id
@@ -448,7 +561,7 @@ export class GraphStore {
448
561
  WHERE repository_id = ?
449
562
  `).all(this.#repositoryId);
450
563
  for (const { node_id } of nodeRows) {
451
- const validity = allEvidenceMatches(this.readNodeEvidenceRows(node_id), snapshot)
564
+ const validity = allEvidenceMatches(this.readNodeEvidenceRows(node_id, snapshot.snapshotId), snapshot)
452
565
  ? "valid"
453
566
  : "stale";
454
567
  this.database.prepare(`
@@ -463,15 +576,21 @@ export class GraphStore {
463
576
  `).run(node_id, this.#repositoryId, snapshot.snapshotId, validity);
464
577
  }
465
578
  const relationRows = this.database.prepare(`
466
- SELECT relation_id, to_domain, target_binding_status
467
- FROM atlas_business_relations
468
- WHERE repository_id = ?
469
- `).all(this.#repositoryId);
579
+ SELECT
580
+ relation.relation_id,
581
+ relation.to_domain,
582
+ target.binding_status AS target_binding_status
583
+ FROM atlas_business_relations AS relation
584
+ LEFT JOIN atlas_structural_relation_target_bindings AS target
585
+ ON target.relation_id = relation.relation_id
586
+ AND target.snapshot_id = ?
587
+ WHERE relation.repository_id = ?
588
+ `).all(snapshot.snapshotId, this.#repositoryId);
470
589
  for (const relation of relationRows) {
471
590
  const targetIsBound = relation.to_domain === "business"
472
591
  || relation.target_binding_status === "bound";
473
592
  const validity = targetIsBound
474
- && allEvidenceMatches(this.readRelationEvidenceRows(relation.relation_id), snapshot)
593
+ && allEvidenceMatches(this.readRelationEvidenceRows(relation.relation_id, snapshot.snapshotId), snapshot)
475
594
  ? "valid"
476
595
  : "stale";
477
596
  this.database.prepare(`
@@ -520,57 +639,67 @@ export class GraphStore {
520
639
  aliases: aliases.map(({ alias }) => alias),
521
640
  certainty: row.certainty,
522
641
  validity: row.validity,
523
- evidence: this.readNodeEvidence(row.node_id),
642
+ evidence: this.readNodeEvidence(row.node_id, snapshotId),
524
643
  baseSnapshotId: row.base_snapshot_id,
525
644
  };
526
645
  }
527
- readNodeEvidence(nodeId) {
528
- return this.readNodeEvidenceRows(nodeId).map(evidenceFromRow);
646
+ readNodeEvidence(nodeId, snapshotId) {
647
+ return this.readNodeEvidenceRows(nodeId, snapshotId).map(evidenceFromRow);
529
648
  }
530
- readNodeEvidenceRows(nodeId) {
649
+ readNodeEvidenceRows(nodeId, snapshotId) {
531
650
  return this.database.prepare(`
532
651
  SELECT
533
- structural_reference,
534
- file,
535
- start_line,
536
- start_column,
537
- end_line,
538
- end_column,
539
- content_hash,
540
- qualified_symbol,
541
- structural_kind,
542
- atlas_snapshot_id,
543
- backend_version,
544
- backend_locator,
545
- binding_status
546
- FROM atlas_business_node_evidence
547
- WHERE node_id = ?
548
- ORDER BY position ASC
549
- `).all(nodeId);
550
- }
551
- readRelationEvidence(relationId) {
552
- return this.readRelationEvidenceRows(relationId).map(evidenceFromRow);
553
- }
554
- readRelationEvidenceRows(relationId) {
652
+ COALESCE(binding.resolved_structural_reference, evidence.structural_reference)
653
+ AS structural_reference,
654
+ evidence.file,
655
+ evidence.start_line,
656
+ evidence.start_column,
657
+ evidence.end_line,
658
+ evidence.end_column,
659
+ evidence.content_hash,
660
+ COALESCE(binding.resolved_qualified_symbol, evidence.qualified_symbol) AS qualified_symbol,
661
+ COALESCE(binding.resolved_structural_kind, evidence.structural_kind) AS structural_kind,
662
+ binding.snapshot_id AS atlas_snapshot_id,
663
+ binding.backend_version,
664
+ COALESCE(binding.backend_locator, evidence.backend_locator) AS backend_locator,
665
+ COALESCE(binding.binding_status, 'unresolved') AS binding_status
666
+ FROM atlas_business_node_evidence AS evidence
667
+ LEFT JOIN atlas_business_node_evidence_bindings AS binding
668
+ ON binding.node_id = evidence.node_id
669
+ AND binding.position = evidence.position
670
+ AND binding.snapshot_id = ?
671
+ WHERE evidence.node_id = ?
672
+ ORDER BY evidence.position ASC
673
+ `).all(snapshotId, nodeId);
674
+ }
675
+ readRelationEvidence(relationId, snapshotId) {
676
+ return this.readRelationEvidenceRows(relationId, snapshotId).map(evidenceFromRow);
677
+ }
678
+ readRelationEvidenceRows(relationId, snapshotId) {
555
679
  return this.database.prepare(`
556
680
  SELECT
557
- structural_reference,
558
- file,
559
- start_line,
560
- start_column,
561
- end_line,
562
- end_column,
563
- content_hash,
564
- qualified_symbol,
565
- structural_kind,
566
- atlas_snapshot_id,
567
- backend_version,
568
- backend_locator,
569
- binding_status
570
- FROM atlas_business_relation_evidence
571
- WHERE relation_id = ?
572
- ORDER BY position ASC
573
- `).all(relationId);
681
+ COALESCE(binding.resolved_structural_reference, evidence.structural_reference)
682
+ AS structural_reference,
683
+ evidence.file,
684
+ evidence.start_line,
685
+ evidence.start_column,
686
+ evidence.end_line,
687
+ evidence.end_column,
688
+ evidence.content_hash,
689
+ COALESCE(binding.resolved_qualified_symbol, evidence.qualified_symbol) AS qualified_symbol,
690
+ COALESCE(binding.resolved_structural_kind, evidence.structural_kind) AS structural_kind,
691
+ binding.snapshot_id AS atlas_snapshot_id,
692
+ binding.backend_version,
693
+ COALESCE(binding.backend_locator, evidence.backend_locator) AS backend_locator,
694
+ COALESCE(binding.binding_status, 'unresolved') AS binding_status
695
+ FROM atlas_business_relation_evidence AS evidence
696
+ LEFT JOIN atlas_business_relation_evidence_bindings AS binding
697
+ ON binding.relation_id = evidence.relation_id
698
+ AND binding.position = evidence.position
699
+ AND binding.snapshot_id = ?
700
+ WHERE evidence.relation_id = ?
701
+ ORDER BY evidence.position ASC
702
+ `).all(snapshotId, relationId);
574
703
  }
575
704
  readBusinessRelations(snapshotId) {
576
705
  return this.database.prepare(`
@@ -580,18 +709,25 @@ export class GraphStore {
580
709
  relation.from_key,
581
710
  relation.relation_type,
582
711
  relation.to_domain,
583
- relation.to_key,
712
+ CASE
713
+ WHEN relation.to_domain = 'structural'
714
+ THEN COALESCE(target.resolved_structural_reference, relation.to_key)
715
+ ELSE relation.to_key
716
+ END AS to_key,
584
717
  relation.certainty,
585
718
  COALESCE(validity.validity, 'stale') AS validity
586
719
  FROM atlas_business_relations AS relation
587
720
  LEFT JOIN atlas_business_relation_validity AS validity
588
721
  ON validity.relation_id = relation.relation_id
589
722
  AND validity.snapshot_id = ?
723
+ LEFT JOIN atlas_structural_relation_target_bindings AS target
724
+ ON target.relation_id = relation.relation_id
725
+ AND target.snapshot_id = ?
590
726
  WHERE relation.repository_id = ?
591
727
  ORDER BY relation.from_key, relation.relation_type, relation.to_domain, relation.to_key
592
- `).all(snapshotId, this.#repositoryId);
728
+ `).all(snapshotId, snapshotId, this.#repositoryId);
593
729
  }
594
- relationFromRow(row) {
730
+ relationFromRow(row, snapshotId) {
595
731
  return {
596
732
  domain: "business",
597
733
  from: { domain: "business", key: row.from_key },
@@ -602,7 +738,7 @@ export class GraphStore {
602
738
  baseSnapshotId: row.base_snapshot_id,
603
739
  certainty: row.certainty,
604
740
  validity: row.validity,
605
- evidence: this.readRelationEvidence(row.relation_id),
741
+ evidence: this.readRelationEvidence(row.relation_id, snapshotId),
606
742
  };
607
743
  }
608
744
  readBusinessAdjacency(reference, snapshotId, direction) {
@@ -624,7 +760,7 @@ export class GraphStore {
624
760
  adjacency.push({
625
761
  relationKey: `business:${row.relation_id}`,
626
762
  direction: currentDirection,
627
- relation: this.relationFromRow(row),
763
+ relation: this.relationFromRow(row, snapshotId),
628
764
  node,
629
765
  });
630
766
  }
@@ -641,8 +777,19 @@ export class GraphStore {
641
777
  AND from_key = ?
642
778
  AND relation_type = ?
643
779
  AND to_domain = ?
644
- AND to_key = ?
645
- `).get(this.#repositoryId, selector.from.key, selector.type, selector.to.domain, targetKey);
780
+ AND (
781
+ to_key = ?
782
+ OR (
783
+ to_domain = 'structural'
784
+ AND EXISTS (
785
+ SELECT 1
786
+ FROM atlas_structural_relation_target_bindings AS binding
787
+ WHERE binding.relation_id = atlas_business_relations.relation_id
788
+ AND binding.resolved_structural_reference = ?
789
+ )
790
+ )
791
+ )
792
+ `).get(this.#repositoryId, selector.from.key, selector.type, selector.to.domain, targetKey, targetKey);
646
793
  }
647
794
  findBusinessNodeId(key) {
648
795
  const row = this.database.prepare(`
@@ -1,6 +1,7 @@
1
1
  import type { DatabaseSync as NodeDatabaseSync } from "node:sqlite";
2
2
  import type { GitRepository } from "../repository/types.js";
3
- export declare const CURRENT_ATLAS_SCHEMA_VERSION = 5;
3
+ export declare const CURRENT_ATLAS_SCHEMA_VERSION = 1;
4
+ export declare const SEMANTIC_ATLAS_HOME_ENVIRONMENT_VARIABLE = "SEMANTIC_ATLAS_HOME";
4
5
  export declare class AtlasDatabase implements Disposable {
5
6
  #private;
6
7
  readonly databasePath: string;
@@ -9,6 +10,9 @@ export declare class AtlasDatabase implements Disposable {
9
10
  get schemaVersion(): number;
10
11
  close(): void;
11
12
  [Symbol.dispose](): void;
12
- private applyMigrations;
13
+ private initializeSchema;
14
+ private registerRepository;
13
15
  }
16
+ export declare function resolveAtlasHome(repository: GitRepository): string;
17
+ export declare function resolveAtlasDatabasePath(repository: GitRepository): string;
14
18
  //# 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":"AAGA,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAyc9C,qBAAa,aAAc,YAAW,UAAU;;IAC9C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;gBAG1B,UAAU,EAAE,aAAa;IAuCrC,IAAI,aAAa,IAAI,MAAM,CAM1B;IAED,KAAK,IAAI,IAAI;IAQb,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;IAIxB,OAAO,CAAC,eAAe;CAoCxB"}
1
+ {"version":3,"file":"atlas-database.d.ts","sourceRoot":"","sources":["../../src/storage/atlas-database.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,wCAAwC,wBAAwB,CAAC;AAM9E,qBAAa,aAAc,YAAW,UAAU;;IAC9C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;gBAG1B,UAAU,EAAE,aAAa;IAcrC,IAAI,aAAa,IAAI,MAAM,CAO1B;IAED,KAAK,IAAI,IAAI;IAQb,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;IAIxB,OAAO,CAAC,gBAAgB;IAuCxB,OAAO,CAAC,kBAAkB;CAqC3B;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,MAAM,CAiBlE;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,aAAa,GAAG,MAAM,CAQ1E"}