semantic-atlas 0.1.2 → 0.1.4

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 +15 -14
  4. package/README.zh-CN.md +15 -14
  5. package/dist/cli/bin.js +7 -15
  6. package/dist/cli/cli-application.d.ts.map +1 -1
  7. package/dist/cli/cli-application.js +5 -5
  8. package/dist/graph/graph-store.d.ts +6 -0
  9. package/dist/graph/graph-store.d.ts.map +1 -1
  10. package/dist/graph/graph-store.js +261 -114
  11. package/dist/runtime/sqlite-compatibility-process.d.ts +8 -0
  12. package/dist/runtime/sqlite-compatibility-process.d.ts.map +1 -0
  13. package/dist/runtime/sqlite-compatibility-process.js +20 -0
  14. package/dist/storage/atlas-database.d.ts +6 -2
  15. package/dist/storage/atlas-database.d.ts.map +1 -1
  16. package/dist/storage/atlas-database.js +388 -514
  17. package/dist/storage/snapshot-store.d.ts.map +1 -1
  18. package/dist/storage/snapshot-store.js +7 -10
  19. package/dist/structural-backend/codegraph-backend.d.ts +4 -1
  20. package/dist/structural-backend/codegraph-backend.d.ts.map +1 -1
  21. package/dist/structural-backend/codegraph-backend.js +10 -4
  22. package/dist/structural-backend/structural-projection-bootstrapper.d.ts +10 -0
  23. package/dist/structural-backend/structural-projection-bootstrapper.d.ts.map +1 -0
  24. package/dist/structural-backend/structural-projection-bootstrapper.js +295 -0
  25. package/dist/structural-backend/structural-publication.d.ts +1 -0
  26. package/dist/structural-backend/structural-publication.d.ts.map +1 -1
  27. package/dist/structural-backend/structural-publication.js +5 -2
  28. package/dist/world/world-model-service.d.ts.map +1 -1
  29. package/dist/world/world-model-service.js +14 -6
  30. package/dist/world/world-snapshot-store.d.ts.map +1 -1
  31. package/dist/world/world-snapshot-store.js +92 -66
  32. package/docs/architecture/codegraph-backend.md +26 -29
  33. package/docs/contracts/cli-v1.md +2 -1
  34. package/docs/contracts/graph-model.md +2 -2
  35. package/docs/product-contract.md +20 -17
  36. package/package.json +1 -1
@@ -4,9 +4,11 @@ import { AtlasDatabase } from "../storage/atlas-database.js";
4
4
  export class WorldSnapshotStore {
5
5
  #database;
6
6
  #repositoryId;
7
+ #gitDirectory;
7
8
  constructor(repository) {
8
9
  this.#database = new AtlasDatabase(repository);
9
10
  this.#repositoryId = repository.repositoryId;
11
+ this.#gitDirectory = repository.gitDirectory;
10
12
  }
11
13
  readState() {
12
14
  const row = this.connection.prepare(`
@@ -20,9 +22,9 @@ export class WorldSnapshotStore {
20
22
  started_at,
21
23
  published_at,
22
24
  updated_at
23
- FROM atlas_world_state
24
- WHERE repository_id = ?
25
- `).get(this.#repositoryId);
25
+ FROM atlas_worktree_states
26
+ WHERE repository_id = ? AND git_directory = ?
27
+ `).get(this.#repositoryId, this.#gitDirectory);
26
28
  return {
27
29
  status: row.status,
28
30
  currentSnapshotId: row.current_snapshot_id,
@@ -42,7 +44,7 @@ export class WorldSnapshotStore {
42
44
  return;
43
45
  }
44
46
  this.connection.prepare(`
45
- UPDATE atlas_world_state
47
+ UPDATE atlas_worktree_states
46
48
  SET
47
49
  status = 'building',
48
50
  target_snapshot_id = ?,
@@ -50,8 +52,8 @@ export class WorldSnapshotStore {
50
52
  started_at = ?,
51
53
  published_at = NULL,
52
54
  updated_at = ?
53
- WHERE repository_id = ?
54
- `).run(targetSnapshotId, timestamp, timestamp, this.#repositoryId);
55
+ WHERE repository_id = ? AND git_directory = ?
56
+ `).run(targetSnapshotId, timestamp, timestamp, this.#repositoryId, this.#gitDirectory);
55
57
  }
56
58
  publish(snapshot, backendVersion, extractionVersion, resolver, changes) {
57
59
  let result;
@@ -75,7 +77,7 @@ export class WorldSnapshotStore {
75
77
  const timestamp = new Date().toISOString();
76
78
  const publicationId = this.saveWorldPublication(previousPublication?.publication_id ?? null, { ...changes, staleAssertions: uniqueStaleAssertions }, timestamp);
77
79
  this.connection.prepare(`
78
- UPDATE atlas_world_state
80
+ UPDATE atlas_worktree_states
79
81
  SET
80
82
  status = 'current',
81
83
  current_snapshot_id = ?,
@@ -86,8 +88,8 @@ export class WorldSnapshotStore {
86
88
  failure_message = NULL,
87
89
  published_at = ?,
88
90
  updated_at = ?
89
- WHERE repository_id = ?
90
- `).run(snapshot.snapshotId, publicationId, backendVersion, extractionVersion, timestamp, timestamp, this.#repositoryId);
91
+ WHERE repository_id = ? AND git_directory = ?
92
+ `).run(snapshot.snapshotId, publicationId, backendVersion, extractionVersion, timestamp, timestamp, this.#repositoryId, this.#gitDirectory);
91
93
  result = { staleAssertions: uniqueStaleAssertions };
92
94
  });
93
95
  return result;
@@ -95,15 +97,15 @@ export class WorldSnapshotStore {
95
97
  fail(targetSnapshotId, error) {
96
98
  const timestamp = new Date().toISOString();
97
99
  this.connection.prepare(`
98
- UPDATE atlas_world_state
100
+ UPDATE atlas_worktree_states
99
101
  SET
100
102
  status = 'failed',
101
103
  target_snapshot_id = ?,
102
104
  failure_message = ?,
103
105
  published_at = NULL,
104
106
  updated_at = ?
105
- WHERE repository_id = ?
106
- `).run(targetSnapshotId, error instanceof Error ? error.message : String(error), timestamp, this.#repositoryId);
107
+ WHERE repository_id = ? AND git_directory = ?
108
+ `).run(targetSnapshotId, error instanceof Error ? error.message : String(error), timestamp, this.#repositoryId, this.#gitDirectory);
107
109
  }
108
110
  requireCurrentSnapshot() {
109
111
  return this.requireCurrentWorld().snapshot;
@@ -175,9 +177,9 @@ export class WorldSnapshotStore {
175
177
  readCurrentPublication() {
176
178
  const row = this.connection.prepare(`
177
179
  SELECT current_publication_id
178
- FROM atlas_world_state
179
- WHERE repository_id = ?
180
- `).get(this.#repositoryId);
180
+ FROM atlas_worktree_states
181
+ WHERE repository_id = ? AND git_directory = ?
182
+ `).get(this.#repositoryId, this.#gitDirectory);
181
183
  return row.current_publication_id === null
182
184
  ? undefined
183
185
  : this.requirePublication(row.current_publication_id);
@@ -190,8 +192,8 @@ export class WorldSnapshotStore {
190
192
  snapshot_id,
191
193
  stale_assertions
192
194
  FROM atlas_world_publications
193
- WHERE repository_id = ? AND publication_id = ?
194
- `).get(this.#repositoryId, publicationId);
195
+ WHERE repository_id = ? AND git_directory = ? AND publication_id = ?
196
+ `).get(this.#repositoryId, this.#gitDirectory, publicationId);
195
197
  }
196
198
  requirePublication(publicationId) {
197
199
  const publication = this.readPublication(publicationId);
@@ -274,11 +276,6 @@ export class WorldSnapshotStore {
274
276
  ON CONFLICT (repository_id, snapshot_id) DO UPDATE SET
275
277
  payload = excluded.payload
276
278
  `).run(this.#repositoryId, snapshot.snapshotId, JSON.stringify(snapshot), timestamp);
277
- this.connection.prepare(`
278
- UPDATE atlas_repositories
279
- SET latest_snapshot_id = ?, updated_at = ?
280
- WHERE repository_id = ?
281
- `).run(snapshot.snapshotId, timestamp, this.#repositoryId);
282
279
  }
283
280
  rebindEvidence(snapshot, backendVersion, resolver) {
284
281
  const staleAssertions = [];
@@ -328,6 +325,9 @@ export class WorldSnapshotStore {
328
325
  ORDER BY ${ownerColumn}, position
329
326
  `).all();
330
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
331
  return rows.map((row) => {
332
332
  const locator = locatorFromRow(row);
333
333
  const match = this.resolveEvidence(locator, resolver);
@@ -339,19 +339,26 @@ export class WorldSnapshotStore {
339
339
  ? "missing"
340
340
  : match.status;
341
341
  this.connection.prepare(`
342
- UPDATE ${table}
343
- SET
344
- structural_reference = ?,
345
- qualified_symbol = ?,
346
- structural_kind = ?,
347
- atlas_snapshot_id = ?,
348
- backend_version = ?,
349
- backend_locator = ?,
350
- binding_status = ?
351
- WHERE ${ownerColumn} = ? AND position = ?
352
- `).run(match.node?.reference.id ?? row.structural_reference, match.node?.qualifiedName ?? row.qualified_symbol, match.node?.kind ?? row.structural_kind, snapshot.snapshotId, backendVersion, match.node === undefined
353
- ? row.backend_locator
354
- : resolver.backendLocator(match.node) ?? null, status, row.owner_id, row.position);
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);
355
362
  return { ownerType, ownerId: row.owner_id, status };
356
363
  });
357
364
  }
@@ -385,24 +392,35 @@ export class WorldSnapshotStore {
385
392
  staleAssertions.push(identity);
386
393
  }
387
394
  this.connection.prepare(`
388
- UPDATE atlas_business_relations
389
- SET
390
- to_key = ?,
391
- target_file = ?,
392
- target_qualified_symbol = ?,
393
- target_structural_kind = ?,
394
- target_start_line = ?,
395
- target_start_column = ?,
396
- target_end_line = ?,
397
- target_end_column = ?,
398
- target_atlas_snapshot_id = ?,
399
- target_backend_version = ?,
400
- target_backend_locator = ?,
401
- target_binding_status = ?
402
- WHERE relation_id = ?
403
- `).run(match.node?.reference.id ?? row.to_key, match.node?.path ?? row.target_file, match.node?.qualifiedName ?? row.target_qualified_symbol, match.node?.kind ?? row.target_structural_kind, match.node?.range.start.line ?? row.target_start_line, match.node?.range.start.column ?? row.target_start_column, match.node?.range.end.line ?? row.target_end_line, match.node?.range.end.column ?? row.target_end_column, snapshot.snapshotId, backendVersion, match.node === undefined
404
- ? row.target_backend_locator
405
- : resolver.backendLocator(match.node) ?? null, match.status, row.relation_id);
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);
406
424
  }
407
425
  return staleAssertions;
408
426
  }
@@ -421,10 +439,10 @@ export class WorldSnapshotStore {
421
439
  return { status: candidates.length === 0 ? "missing" : "ambiguous" };
422
440
  }
423
441
  refreshValidity(snapshotId) {
424
- this.refreshValidityTable("atlas_business_nodes", "atlas_business_node_evidence", "atlas_business_node_validity", "node_id", snapshotId);
425
- this.refreshValidityTable("atlas_business_relations", "atlas_business_relation_evidence", "atlas_business_relation_validity", "relation_id", 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);
426
444
  }
427
- refreshValidityTable(ownerTable, evidenceTable, validityTable, ownerColumn, snapshotId) {
445
+ refreshValidityTable(ownerTable, evidenceTable, bindingTable, validityTable, ownerColumn, snapshotId) {
428
446
  const owners = this.connection.prepare(`
429
447
  SELECT ${ownerColumn} AS owner_id
430
448
  FROM ${ownerTable}
@@ -434,19 +452,26 @@ export class WorldSnapshotStore {
434
452
  const row = this.connection.prepare(`
435
453
  SELECT
436
454
  COUNT(*) AS evidence_count,
437
- SUM(CASE WHEN binding_status = 'bound' THEN 1 ELSE 0 END) AS bound_count
438
- FROM ${evidenceTable}
439
- WHERE ${ownerColumn} = ?
440
- `).get(owner_id);
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);
441
463
  const validity = row.evidence_count > 0 && row.evidence_count === row.bound_count
442
464
  ? "valid"
443
465
  : "stale";
444
466
  const targetBindingStatus = ownerColumn === "relation_id"
445
467
  ? this.connection.prepare(`
446
- SELECT to_domain, target_binding_status
447
- FROM atlas_business_relations
448
- WHERE relation_id = ?
449
- `).get(owner_id)
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)
450
475
  : undefined;
451
476
  const targetIsBound = targetBindingStatus === undefined
452
477
  || targetBindingStatus.to_domain === "business"
@@ -465,6 +490,7 @@ export class WorldSnapshotStore {
465
490
  const result = this.connection.prepare(`
466
491
  INSERT INTO atlas_world_publications (
467
492
  repository_id,
493
+ git_directory,
468
494
  previous_publication_id,
469
495
  snapshot_id,
470
496
  added_paths,
@@ -472,8 +498,8 @@ export class WorldSnapshotStore {
472
498
  removed_paths,
473
499
  stale_assertions,
474
500
  published_at
475
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
476
- `).run(this.#repositoryId, previousPublicationId, changes.toSnapshotId, JSON.stringify(changes.structural.added), JSON.stringify(changes.structural.modified), JSON.stringify(changes.structural.removed), JSON.stringify(changes.staleAssertions), timestamp);
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);
477
503
  return Number(result.lastInsertRowid);
478
504
  }
479
505
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  ## Decision
4
4
 
5
- Semantic Atlas embeds the verified `@colbymchenry/codegraph` 1.5.0 package as its initial structural-index SDK. It sets `CODEGRAPH_DIR=.atlas` and accepts `.atlas/codegraph.db` as the v0.1 physical database path.
5
+ Semantic Atlas embeds the verified `@colbymchenry/codegraph` 1.5.0 package as its structural-index SDK. It uses the SDK's fixed `.atlas/codegraph.db` path as a worktree-local disposable projection and stores durable Atlas knowledge in a separate user-level repository database.
6
6
 
7
- This decision produces one product, one index command, one durable SQLite database, and one logical world graph. It avoids waiting for an upstream database-path option and avoids copying a large language-analysis implementation into Atlas.
7
+ This decision produces one product, one index command, two explicit storage lifecycles, and one logical world graph. It requires no upstream database-path option and lets linked worktrees share durable business meaning without sharing one mutable structural index.
8
8
 
9
9
  ## System model
10
10
 
@@ -20,25 +20,25 @@ WorldModelService
20
20
  | |-- extraction and resolution
21
21
  | |-- structural search and traversal
22
22
  |
23
- |-- BusinessKnowledgeStore -- capabilities, flows, data, rules, evidence
23
+ |-- BusinessKnowledgeStore -- ~/.semantic-atlas/repositories/<id>/atlas.db
24
24
  |
25
25
  `-- WorldGraphQuery -------- normalizes and composes both domains
26
26
  |
27
- .atlas/codegraph.db
27
+ <worktree>/.atlas/codegraph.db
28
28
  ```
29
29
 
30
30
  `CodeGraphBackend` is an anti-corruption layer, not a second public API. Atlas domain code depends on Atlas structural query types. Backend node kinds, edge kinds, identifiers, errors, and version metadata are translated at this boundary.
31
31
 
32
32
  ## Physical and logical ownership
33
33
 
34
- The SQLite file contains multiple table families because they have different writers and lifecycles. They are one database, not two exported datasets.
34
+ The two SQLite files have different owners and lifecycles. They remain internal stores behind one Atlas query contract.
35
35
 
36
36
  | Owner | Table family | Lifecycle |
37
37
  | --- | --- | --- |
38
- | CodeGraph | `nodes`, `edges`, `files`, `unresolved_refs`, FTS, schema and backend metadata | Rebuilt or incrementally synchronized from source |
39
- | Atlas | `atlas_metadata`, `atlas_snapshots`, `atlas_business_nodes`, `atlas_business_relations`, `atlas_evidence`, `atlas_assertion_validity` | Migrated and updated by Atlas only |
38
+ | CodeGraph worktree projection | `nodes`, `edges`, `files`, `unresolved_refs`, FTS, schema and backend metadata | Copied from a compatible sibling, rebuilt, or incrementally synchronized from source |
39
+ | Atlas repository store | `atlas_*` business, snapshot, binding, validity, worktree-state, and publication objects | Shared by all worktrees and updated by Atlas only |
40
40
 
41
- Atlas accesses structural behavior through the CodeGraph public SDK. Atlas SQL migrations and repositories access only `atlas_*` objects. The world graph is composed in `WorldGraphQuery`; the public CLI never exposes table origin.
41
+ Atlas accesses structural behavior through the CodeGraph public SDK and durable knowledge through its user-level database. `WorldGraphQuery` joins evidence locators and structural references in memory; the public CLI never exposes table origin or a second workflow.
42
42
 
43
43
  The implementation contains no Atlas-owned structural projection tables. Keeping those tables would duplicate CodeGraph data and restore the two-graph problem this design resolves.
44
44
 
@@ -91,7 +91,7 @@ Atlas business knowledge does not own CodeGraph rows. An evidence record contain
91
91
  - a source content hash;
92
92
  - the Atlas snapshot and structural-backend version observed at learning time.
93
93
 
94
- No cascading foreign key points from `atlas_*` evidence to a CodeGraph structural table. CodeGraph may clear and recreate its structural rows during a supported rebuild. After every successful index, Atlas attempts to rebind evidence from the durable locator tuple. A unique match is current, a missing or ambiguous match is stale, and certainty remains unchanged.
94
+ No cascading foreign key points from `atlas_*` evidence to a CodeGraph structural table. The original evidence locator remains repository-wide. After every successful index, Atlas writes a binding for that content snapshot; a unique match is current, a missing or ambiguous match is stale, and certainty remains unchanged. One worktree's rebinding never overwrites another snapshot's result.
95
95
 
96
96
  Structural relation targets own the same kind of durable locator independently from their supporting evidence. A relation may target one structural node while its evidence cites another; Atlas resolves both locators separately and marks the relation stale when either one is missing or ambiguous.
97
97
 
@@ -107,6 +107,8 @@ Atlas owns directory preparation:
107
107
 
108
108
  The environment override is contained inside `CodeGraphBackend`; callers do not configure CodeGraph. Each worktree has its own `.atlas/` because CodeGraph's index, SQLite locks, and dirty source state are worktree- and operating-system-specific.
109
109
 
110
+ When `codegraph.db` is missing, `StructuralProjectionBootstrapper` reads compatible `current` sibling states from the repository Atlas database. Exact-snapshot candidates sort first, followed by the most recent successful publication and normalized path. Under the sibling's existing structural lock, Atlas rejects symlinks, integrity failures, incomplete metadata, version mismatches, and source-manifest mismatches; it copies only the SQLite database with `node:sqlite.backup()`, atomically installs the destination, and always runs incremental `sync` in the destination root. All failed candidates lead to the normal full-index fallback.
111
+
110
112
  ## Index state machine
111
113
 
112
114
  ```text
@@ -129,60 +131,55 @@ Normal updates use CodeGraph incremental sync. A full structural rebuild uses `C
129
131
  - `CodeGraph.uninitialize()`, which removes the entire `.atlas/` directory;
130
132
  - the CodeGraph CLI rebuild path, which is allowed to choose destructive lifecycle operations.
131
133
 
132
- Before mutating an existing structural index, the adapter captures an online backup of the shared database. Both full rebuild and incremental sync discard that backup only after a complete result; an incomplete result or exception restores the previously published structural graph and colocated `atlas_*` data before the Atlas lock is released.
134
+ Before mutating an existing structural index, the adapter captures an online backup of the CodeGraph database. Both full rebuild and incremental sync discard that backup only after a complete result; an incomplete result or exception restores the previously published structural graph before the Atlas lock is released.
133
135
 
134
- A future physical-database recovery command must copy or export Atlas-owned tables, replace the structural database, restore Atlas data, and verify evidence before publishing `current`.
136
+ The structural database contains no Atlas-owned tables, so replacing or deleting a worktree projection cannot delete durable business knowledge.
135
137
 
136
138
  ## Snapshot semantics
137
139
 
138
140
  CodeGraph's structural tables represent the current code projection. Atlas snapshots record repository content identity, Git state, relevant file hashes, the CodeGraph package and extraction versions, build outcome, and evidence validity.
139
141
 
140
- Atlas does not preserve a second full historical structural graph. Repository snapshots are content-addressed and may recur, while every successful index/sync creates a distinct immutable Atlas publication occurrence. The current world state points to the latest occurrence; each occurrence points to its predecessor, its content snapshot, target validity metadata, and path-level backend diagnostics. Business assertions remain durable across snapshots and expose validity for the requested current snapshot.
142
+ Atlas does not preserve a second full historical structural graph. Repository snapshots are content-addressed and may recur, while every successful index/sync creates a distinct immutable publication occurrence scoped to `(repository_id, git_directory)`. Each worktree state points to its own latest occurrence and predecessor chain. Business assertions remain repository-wide and expose binding-derived validity for the requested snapshot.
141
143
 
142
144
  The change query proves the requested source snapshot is an ancestor of the target by following the immutable publication-occurrence chain. Repeated content identities resolve deterministically within the current chain: `to` selects the latest matching occurrence and `from` selects the latest match at or before that target; equal endpoints select the same occurrence. Atlas compares the supported source content stored in the two endpoint snapshots and returns the net added, changed, and removed `file:` references. This endpoint comparison is independent of the structural backend's incremental Git baseline: intermediate additions that are later removed and removals restored with identical content cancel naturally. Stale assertions describe validity at the selected target occurrence rather than the union of intermediate failures. Atlas does not query mutable CodeGraph rows as if they were a historical snapshot or reconstruct unsupported historical node and relation changes.
143
145
 
144
- World publication captures the repository snapshot after acquiring the Atlas write lock, verifies it again after structural indexing, and compares its source hashes with CodeGraph's indexed file manifest. If source changes during that interval, including a transient change that restores the same final snapshot, Atlas rolls the structural database back and leaves the prior world snapshot as the last published revision. Every publication occurrence is immutable, so a later sync of identical content appends a new occurrence instead of replacing earlier path-level diagnostics.
146
+ World publication captures the repository snapshot after acquiring the Atlas write lock, verifies it again after structural indexing, and compares its source hashes with CodeGraph's indexed file manifest. A mismatch rolls back the structural database and leaves the prior world snapshot current. After validation, Atlas commits CodeGraph first and then publishes the user-level Atlas transaction. If that central transaction fails, the durable CodeGraph projection remains, the worktree state is non-current, and the next `index` repairs publication through incremental sync. Every successful occurrence is immutable.
145
147
 
146
148
  ## Failure and upgrade behavior
147
149
 
148
150
  - A CodeGraph index or sync error fails the Atlas index command and leaves the world snapshot non-current.
149
- - Atlas schema migration failure leaves CodeGraph structural data present but unpublished through Atlas until migration succeeds.
151
+ - A user-level Atlas transaction failure leaves complete CodeGraph structural data present but unavailable to map and learn until a later index republishes the worktree state.
150
152
  - Unsupported structure is returned as backend support metadata or an unresolved boundary; Atlas does not invent an exact edge.
151
- - The dependency version is pinned exactly rather than selected through a semver range. The compatible host range is Node.js 22.12 through 24. Node.js 22.12 through 22.15 lack the FTS5 module required by CodeGraph 1.5.0, so the adapter runs its private SDK worker with the dependency's bundled Node.js runtime on those hosts; Node.js 22.16 through 24 use the SDK in process. Both paths expose the same Atlas contract and invoke no CodeGraph CLI, MCP, or daemon lifecycle. Upgrades run fixture repositories through index, sync, rebuild, query normalization, schema coexistence, and evidence-rebinding tests before changing the lockfile.
153
+ - The dependency version is pinned exactly rather than selected through a semver range. The compatible host range is Node.js 22.12 through 24. Node.js 22.12 through 22.15 lack the FTS5 module required by CodeGraph 1.5.0, so the adapter runs its private SDK worker with the dependency's bundled Node.js runtime on those hosts; Node.js 22.16 through 24 use the SDK in process. Both paths expose the same Atlas contract and invoke no CodeGraph CLI, MCP, or daemon lifecycle. Upgrades run fixture repositories through index, sync, rebuild, query normalization, split-schema ownership, and evidence-rebinding tests before changing the lockfile.
152
154
  - If an upstream release changes structural IDs, locator-based rebinding preserves stable Atlas business keys and makes unmatched evidence stale.
153
155
 
154
156
  Run `pnpm validation:backend` to validate the installed tarball against the
155
157
  current exact dependency. To evaluate a new release before changing the pin,
156
158
  run `pnpm validation:backend -- --candidate <version> --allow-network`. The
157
159
  isolated consumer overrides only its installed candidate; the source manifest
158
- and lockfile remain unchanged. A pinned consumer first creates the database and
159
- learns business knowledge; after it closes, a separate candidate consumer must
160
- open and preserve that same store through incremental and full operations. The
161
- command also compares required structural endpoints and bounded false exact
162
- links with the pinned baseline. It rejects candidates that change the database
163
- location, SDK lifecycle, schema ownership, normalized support, business data,
164
- evidence, prior publications, recovery, structural quality, or worktree
165
- isolation contracts, and prints the measured index, database, and query costs.
160
+ and lockfile remain unchanged. The gate validates a pure CodeGraph worktree
161
+ projection, the user-level Atlas schema, sibling bootstrap plus incremental
162
+ sync, snapshot-specific rebinding, and business-knowledge preservation. It also
163
+ compares required structural endpoints and bounded false exact links with the
164
+ pinned baseline, and prints measured index, database, and query costs.
166
165
 
167
166
  ## Pre-release storage transition
168
167
 
169
- The pre-release external `atlas.sqlite` layout is intentionally reset rather than imported. It contains the superseded duplicate structural projection, was never part of a published release, and cannot be copied into the shared database without violating schema ownership. Rebuild the worktree-local structural index, then relearn any experimental business assertions through GraphPatch.
170
-
171
- The shared layout preserves the business node, relation, GraphPatch, evidence, certainty, validity, transaction, and lexical contracts in `atlas_*` objects. Evidence keeps public structural references without foreign keys to CodeGraph rows. The following reconciliation task extends those records with backend locators, qualified names, structural kinds, snapshot/backend versions, and the combined publication state machine.
168
+ The previous colocated `.atlas/codegraph.db` layout is intentionally reset rather than imported. Existing `.atlas` data is a disposable development cache. The user-level schema starts at v1, and durable knowledge is learned through the current GraphPatch contract.
172
169
 
173
170
  ## Alternatives considered
174
171
 
175
172
  ### Wait for an upstream database-path option
176
173
 
177
- This would permit an `atlas.db` filename, but the filename has no product value and waiting creates schedule risk. `.atlas/codegraph.db` already satisfies the single-directory and single-database boundary.
174
+ This would permit relocating CodeGraph itself, but the product no longer needs that capability. Atlas accepts the SDK's local path and moves only its own durable state.
178
175
 
179
176
  ### Run CodeGraph as a separate CLI or MCP product
180
177
 
181
178
  This would force agents to coordinate two tools, two public contracts, and two failure models. It conflicts with the single Semantic Atlas workflow.
182
179
 
183
- ### Store a CodeGraph database and an Atlas database
180
+ ### Share one mutable CodeGraph database across worktrees
184
181
 
185
- This creates duplicate lifecycle, backup, freshness, and joining problems. Co-locating the schemas in one SQLite file provides clear ownership without creating data islands.
182
+ Different branches and dirty files require independent structural projections. Sharing a mutable projection would mix snapshots and locks; sibling backup plus incremental sync reuses work without sharing mutation.
186
183
 
187
184
  ### Copy CodeGraph source into Semantic Atlas
188
185
 
@@ -45,7 +45,7 @@ Every command writes one JSON envelope to standard output. The normative discrim
45
45
  "changes": { "staged": 0, "unstaged": 0, "untracked": 0 }
46
46
  },
47
47
  "freshness": "missing",
48
- "storeLocation": "/workspace/example/.atlas/codegraph.db",
48
+ "storeLocation": "/home/agent/.semantic-atlas/repositories/0123456789abcdef/atlas.db",
49
49
  "languages": [
50
50
  { "language": "typescript", "support": "supported" }
51
51
  ]
@@ -59,6 +59,7 @@ Every command writes one JSON envelope to standard output. The normative discrim
59
59
  - `partial` means usable data contains explicit unsupported, stale, or unknown boundaries.
60
60
  - Business map nodes and relations always include `certainty`, derived `validity`, and evidence. Structural relations preserve normalized backend provenance and support as additive result metadata; unknown boundaries expose `unknown`, their reason, location, and candidates. Unsupported languages include a reason instead of an approximate analysis.
61
61
  - `warnings` contains stable codes and descriptions for non-fatal conditions. Consumers use codes rather than parsing messages.
62
+ - `storeLocation` identifies the repository-wide Atlas knowledge database. The current worktree's `.atlas/codegraph.db` path remains an internal structural-backend detail.
62
63
 
63
64
  ## Command data
64
65
 
@@ -8,7 +8,7 @@ Semantic Atlas exposes one world graph. Its two domains have different authoriti
8
8
  - business nodes and relations are evidence-bound Atlas assertions changed only through GraphPatch;
9
9
  - evidence relations connect the domains and are rebound after indexing.
10
10
 
11
- Both domains live in `.atlas/codegraph.db`, but Atlas does not copy CodeGraph nodes and edges into parallel structural tables. The world-graph query layer composes CodeGraph SDK results with Atlas-owned `atlas_*` tables and returns one versioned Atlas contract.
11
+ The domains are physically separated by lifecycle: CodeGraph structure lives in the current worktree's disposable `.atlas/codegraph.db`, while repository-wide Atlas knowledge and snapshot bindings live in `~/.semantic-atlas/repositories/<repository-id>/atlas.db`. Atlas does not copy CodeGraph nodes and edges into parallel structural tables. The world-graph query layer composes both stores in memory and returns one versioned Atlas contract.
12
12
 
13
13
  ## Node kinds
14
14
 
@@ -74,7 +74,7 @@ Every learned business node summary and learned relation has a certainty and one
74
74
  - the SHA-256 content hash observed at learning time;
75
75
  - the Atlas snapshot and structural-backend version observed at learning time.
76
76
 
77
- Evidence does not have a cascading foreign key to CodeGraph rows. After indexing, Atlas rebinds each evidence locator to the current structural graph.
77
+ Evidence does not have a cascading foreign key to CodeGraph rows. Its original locator is repository-wide; every successful worktree publication records a separate snapshot binding. Indexing one branch therefore cannot overwrite another branch's resolved reference or validity.
78
78
 
79
79
  Certainty and validity are independent:
80
80
 
@@ -47,43 +47,46 @@ An explicit project-initialization request begins at current structural roots, s
47
47
  | Business world model | Stores and queries capabilities, scenarios, operations, invariants, interfaces, data, and their relationships | Understands natural language and decides which business assertions are justified |
48
48
  | Unified graph | Connects business assertions to structural evidence and returns one Atlas graph contract | Uses graph results as bounded context |
49
49
  | Evidence lifecycle | Records source locators and hashes, then derives `valid` or `stale` after indexing | Revalidates or replaces stale assertions |
50
- | Source changes | Writes generated state only under `.atlas/` | Edits source and project configuration |
50
+ | Generated state | Writes durable knowledge under the user Atlas home and disposable structure under ignored `.atlas/` | Edits source and project configuration |
51
51
  | Verification | Reports evidence, freshness, support, and unresolved boundaries | Runs tests, reviews diffs, and judges correctness |
52
52
  | Git workflow | Reads Git state for snapshots without changing tracked state | Commits, merges, rebases, reviews, and releases |
53
53
 
54
54
  ## Storage and zero-intrusion contract
55
55
 
56
- Each Git worktree owns one local store:
56
+ Atlas separates repository knowledge from worktree structure:
57
57
 
58
58
  ```text
59
+ ~/.semantic-atlas/repositories/<repository-id>/
60
+ └── atlas.db repository-wide durable knowledge
61
+
59
62
  <worktree>/
60
63
  └── .atlas/
61
64
  ├── .gitignore
62
- ├── codegraph.db
65
+ ├── codegraph.db worktree-local disposable CodeGraph projection
63
66
  └── transient lock and SQLite sidecar files
64
67
  ```
65
68
 
66
- - `.atlas/codegraph.db` is the single durable SQLite database. Its filename is an internal consequence of the embedded CodeGraph API, not a second product or a public compatibility promise.
69
+ - The user-level `atlas.db` stores business knowledge, repository snapshots, snapshot-specific evidence bindings and validity, plus one publication chain for each Git directory.
70
+ - `SEMANTIC_ATLAS_HOME` is the only storage override. It must be absolute; the default is `~/.semantic-atlas`.
67
71
  - Atlas prepares `.atlas/.gitignore` so generated state does not change normal Git status. No tracked source file or project configuration is created or modified.
68
- - Every worktree has an independent index because its checked-out and dirty source state can differ. v0.1 does not share one mutable structural database across worktrees or operating systems.
69
- - CodeGraph owns its structural schema. Atlas owns namespaced business, evidence, snapshot, validity, and integration metadata in the same database.
72
+ - Every worktree has an independent CodeGraph index because its checked-out and dirty source state can differ. A missing index is copied from the best compatible sibling through SQLite backup and always incrementally synchronized before publication; full indexing is the fallback.
73
+ - `.atlas/codegraph.db` contains only CodeGraph-owned structural schema. Deleting a worktree discards this projection without deleting repository knowledge.
70
74
  - Atlas never copies CodeGraph structural nodes and edges into parallel Atlas structural tables. The Atlas query layer composes both ownership domains into one logical world graph.
71
75
 
72
76
  ## Index and consistency lifecycle
73
77
 
74
78
  `semantic-atlas index` is the only public owner of the combined lifecycle:
75
79
 
76
- 1. acquire the Atlas worktree lock and mark the projection as building;
77
- 2. initialize or open CodeGraph with `CODEGRAPH_DIR=.atlas`;
78
- 3. run CodeGraph indexing or incremental sync and require a successful, complete result;
79
- 4. close the CodeGraph write lifecycle;
80
- 5. record the Atlas snapshot and structural-backend version;
81
- 6. rebind business evidence to the current structural graph and derive assertion validity;
82
- 7. publish the completed world snapshot and release the lock.
80
+ 1. acquire the Atlas worktree lock and mark that Git directory's central state as `building`;
81
+ 2. bootstrap a missing CodeGraph projection from a compatible sibling when possible, then initialize or open CodeGraph with `CODEGRAPH_DIR=.atlas`;
82
+ 3. run CodeGraph indexing or incremental sync and verify the repository snapshot against its indexed source manifest;
83
+ 4. commit the local structural publication so the CodeGraph projection is durable;
84
+ 5. atomically record the snapshot-specific bindings, validity, and worktree publication in the user-level Atlas database;
85
+ 6. move that worktree state to `current` and release the lock.
83
86
 
84
87
  An interrupted or failed build remains explicit. Map commands do not present a partial structural graph as current.
85
88
 
86
- Normal rebuilds use CodeGraph operations that preserve unknown tables in the same database. The Atlas adapter does not expose or invoke CodeGraph `recreate()` or `uninitialize()`, because those operations delete the physical database and therefore Atlas-owned business knowledge. Any future corruption-recovery path must preserve and restore Atlas-owned data before replacing the database file.
89
+ Structural failure restores the previous worktree projection. If the local projection commits but the central Atlas transaction fails, the worktree stays fail closed; the next `index` performs an incremental no-op or sync and republishes central state. No Atlas business data needs to be restored into CodeGraph.
87
90
 
88
91
  `learn` is an optimistic-concurrency transaction. It validates all evidence against the current completed snapshot and commits all operations together or none of them.
89
92
 
@@ -118,7 +121,7 @@ v0.1 does not provide:
118
121
 
119
122
  ## Dependency policy
120
123
 
121
- The first implementation directly depends on a pinned, verified `@colbymchenry/codegraph` npm version and uses its public SDK. No upstream change or source copy is required for v0.1. An upgrade must pass adapter contract tests for directory placement, schema coexistence, index/sync behavior, structural query normalization, business-data preservation, evidence rebinding, and Node.js compatibility before the pinned version changes.
124
+ The first implementation directly depends on pinned `@colbymchenry/codegraph` 1.5.0 and uses its existing public SDK. No upstream change or source copy is required. An upgrade must pass adapter contract tests for directory placement, index/sync behavior, sibling bootstrap compatibility, structural query normalization, evidence rebinding, and Node.js compatibility before the pin changes.
122
125
 
123
126
  The fallback order is direct dependency, a small upstream extension, a thin maintained fork, then selective vendoring. Vendoring retains the upstream MIT notice and is used only when a required product boundary cannot be maintained through the SDK.
124
127
 
@@ -128,8 +131,8 @@ The v0.1.0 release requires all of the following on the release commit:
128
131
 
129
132
  1. A packaged install uses the pinned CodeGraph SDK through an Atlas-owned adapter and exposes no CodeGraph CLI or MCP workflow.
130
133
  2. `semantic-atlas index` creates only ignored `.atlas/` state in the target worktree and leaves tracked files and normal Git status unchanged.
131
- 3. CodeGraph and Atlas migrations coexist in one `.atlas/codegraph.db` without schema ownership collisions.
132
- 4. Initial index, incremental sync, interrupted index recovery, and structural-only rebuild preserve Atlas-owned business knowledge.
134
+ 3. The user Atlas database contains `atlas_*` objects while every worktree CodeGraph database contains none.
135
+ 4. Initial index, sibling bootstrap, incremental sync, interrupted index recovery, and worktree deletion preserve Atlas-owned business knowledge.
133
136
  5. Business evidence rebinds after stable structural changes and becomes visibly stale after changed or missing evidence.
134
137
  6. Unified map queries traverse business and structural relationships through one versioned Atlas response contract.
135
138
  7. Packaged CLI smoke flows pass on supported Node.js versions and operating systems.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semantic-atlas",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A local, revision-aware project world model for AI coding agents.",
5
5
  "keywords": [
6
6
  "ai-agents",