semantic-atlas 0.1.2 → 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.
- package/.agents/skills/semantic-atlas/SKILL.md +2 -2
- package/.agents/skills/semantic-atlas/references/snapshot-bootstrap.md +5 -1
- package/README.md +15 -14
- package/README.zh-CN.md +15 -14
- package/dist/cli/cli-application.d.ts.map +1 -1
- package/dist/cli/cli-application.js +5 -5
- package/dist/graph/graph-store.d.ts +6 -0
- package/dist/graph/graph-store.d.ts.map +1 -1
- package/dist/graph/graph-store.js +261 -114
- package/dist/storage/atlas-database.d.ts +6 -2
- package/dist/storage/atlas-database.d.ts.map +1 -1
- package/dist/storage/atlas-database.js +388 -514
- package/dist/storage/snapshot-store.d.ts.map +1 -1
- package/dist/storage/snapshot-store.js +7 -10
- package/dist/structural-backend/codegraph-backend.d.ts +4 -1
- package/dist/structural-backend/codegraph-backend.d.ts.map +1 -1
- package/dist/structural-backend/codegraph-backend.js +10 -4
- package/dist/structural-backend/structural-projection-bootstrapper.d.ts +10 -0
- package/dist/structural-backend/structural-projection-bootstrapper.d.ts.map +1 -0
- package/dist/structural-backend/structural-projection-bootstrapper.js +295 -0
- package/dist/structural-backend/structural-publication.d.ts +1 -0
- package/dist/structural-backend/structural-publication.d.ts.map +1 -1
- package/dist/structural-backend/structural-publication.js +5 -2
- package/dist/world/world-model-service.d.ts.map +1 -1
- package/dist/world/world-model-service.js +14 -6
- package/dist/world/world-snapshot-store.d.ts.map +1 -1
- package/dist/world/world-snapshot-store.js +92 -66
- package/docs/architecture/codegraph-backend.md +26 -29
- package/docs/contracts/cli-v1.md +2 -1
- package/docs/contracts/graph-model.md +2 -2
- package/docs/product-contract.md +20 -17
- 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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
|
|
440
|
-
|
|
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
|
-
|
|
449
|
-
|
|
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
|
|
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,
|
|
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 --
|
|
23
|
+
|-- BusinessKnowledgeStore -- ~/.semantic-atlas/repositories/<id>/atlas.db
|
|
24
24
|
|
|
|
25
25
|
`-- WorldGraphQuery -------- normalizes and composes both domains
|
|
26
26
|
|
|
|
27
|
-
|
|
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
|
|
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 |
|
|
39
|
-
| Atlas | `
|
|
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
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
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
|
|
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
|
-
###
|
|
180
|
+
### Share one mutable CodeGraph database across worktrees
|
|
184
181
|
|
|
185
|
-
|
|
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
|
|
package/docs/contracts/cli-v1.md
CHANGED
|
@@ -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": "/
|
|
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
|
-
|
|
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.
|
|
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
|
|
package/docs/product-contract.md
CHANGED
|
@@ -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
|
-
|
|
|
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
|
-
|
|
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
|
-
-
|
|
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.
|
|
69
|
-
-
|
|
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
|
|
77
|
-
2. initialize or open CodeGraph with `CODEGRAPH_DIR=.atlas`;
|
|
78
|
-
3. run CodeGraph indexing or incremental sync and
|
|
79
|
-
4.
|
|
80
|
-
5. record the
|
|
81
|
-
6.
|
|
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
|
-
|
|
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
|
|
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.
|
|
132
|
-
4. Initial index, incremental sync, interrupted index recovery, and
|
|
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.
|