@aionis/substrate 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +201 -0
  3. package/README.md +222 -0
  4. package/dist/backup.d.ts +38 -0
  5. package/dist/backup.d.ts.map +1 -0
  6. package/dist/backup.js +203 -0
  7. package/dist/backup.js.map +1 -0
  8. package/dist/event-log.d.ts +18 -0
  9. package/dist/event-log.d.ts.map +1 -0
  10. package/dist/event-log.js +157 -0
  11. package/dist/event-log.js.map +1 -0
  12. package/dist/file-substrate.d.ts +7 -0
  13. package/dist/file-substrate.d.ts.map +1 -0
  14. package/dist/file-substrate.js +409 -0
  15. package/dist/file-substrate.js.map +1 -0
  16. package/dist/index.d.ts +9 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +9 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/runtime-reference-corpus.d.ts +76 -0
  21. package/dist/runtime-reference-corpus.d.ts.map +1 -0
  22. package/dist/runtime-reference-corpus.js +308 -0
  23. package/dist/runtime-reference-corpus.js.map +1 -0
  24. package/dist/runtime-snapshot-corpus.d.ts +53 -0
  25. package/dist/runtime-snapshot-corpus.d.ts.map +1 -0
  26. package/dist/runtime-snapshot-corpus.js +176 -0
  27. package/dist/runtime-snapshot-corpus.js.map +1 -0
  28. package/dist/runtime-snapshot-importer.d.ts +27 -0
  29. package/dist/runtime-snapshot-importer.d.ts.map +1 -0
  30. package/dist/runtime-snapshot-importer.js +571 -0
  31. package/dist/runtime-snapshot-importer.js.map +1 -0
  32. package/dist/runtime-snapshot-parity.d.ts +40 -0
  33. package/dist/runtime-snapshot-parity.d.ts.map +1 -0
  34. package/dist/runtime-snapshot-parity.js +217 -0
  35. package/dist/runtime-snapshot-parity.js.map +1 -0
  36. package/dist/search.d.ts +3 -0
  37. package/dist/search.d.ts.map +1 -0
  38. package/dist/search.js +157 -0
  39. package/dist/search.js.map +1 -0
  40. package/dist/sqlite-substrate.d.ts +7 -0
  41. package/dist/sqlite-substrate.d.ts.map +1 -0
  42. package/dist/sqlite-substrate.js +666 -0
  43. package/dist/sqlite-substrate.js.map +1 -0
  44. package/dist/types.d.ts +253 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/types.js +2 -0
  47. package/dist/types.js.map +1 -0
  48. package/docs/ADAPTER_CONTRACT.md +155 -0
  49. package/docs/API_USAGE.md +225 -0
  50. package/docs/BACKUP_RESTORE.md +108 -0
  51. package/docs/CHECKPOINT_COMPACTION.md +75 -0
  52. package/docs/EXTERNAL_ADMISSION_PARITY.md +98 -0
  53. package/docs/RUNTIME_DUAL_WRITE_EXPERIMENT.md +132 -0
  54. package/docs/RUNTIME_MAPPING.md +69 -0
  55. package/docs/RUNTIME_REFERENCE_CORPUS.md +129 -0
  56. package/docs/RUNTIME_SNAPSHOT_CORPUS.md +81 -0
  57. package/docs/RUNTIME_SNAPSHOT_IMPORT.md +120 -0
  58. package/docs/STORE_CONTRACT.md +181 -0
  59. package/examples/basic/README.md +19 -0
  60. package/examples/basic/index.mjs +112 -0
  61. package/package.json +65 -0
@@ -0,0 +1,69 @@
1
+ # Aionis Runtime to Substrate Mapping
2
+
3
+ This document maps current Aionis Runtime product capabilities onto the Substrate contract. It is a design map only. It does not imply Runtime is already using Substrate.
4
+
5
+ ## Product Loop Mapping
6
+
7
+ | Runtime surface | Substrate primitive | Notes |
8
+ |---|---|---|
9
+ | `observe` | `memory.node.upsert`, `memory.relation.upsert`, `memory.feedback.recorded` | Runtime observations become durable evidence events. Execution memory, ordinary memory, feedback, and trace pointers are all nodes or events. |
10
+ | `guide` | `compileContext` | Runtime guide is a governed context compile: `use_now`, `inspect_before_use`, `do_not_use`, and `rehydrate`. |
11
+ | `feedback` | `memory.feedback.recorded`, optional `memory.lifecycle.transition` | Feedback is evidence first. Authority changes require substrate-visible transitions. |
12
+ | `forget` | `memory.lifecycle.transition`, `requires_payload` relation | Forgetting is suppress/archive/rehydrate/revalidate state, not physical deletion. |
13
+ | `measure` | `memory.decision.recorded`, feedback and transition events | Measure reads decision traces and evidence history. It does not silently mutate memory. |
14
+
15
+ ## Runtime Data Mapping
16
+
17
+ | Current Runtime concept | Substrate representation |
18
+ |---|---|
19
+ | Execution memory | `AionisMemoryNode(kind="execution")` |
20
+ | Workflow/procedure memory | `AionisMemoryNode(kind="procedure")` |
21
+ | Ordinary facts/preferences | `kind="fact"` / `kind="preference"` |
22
+ | Claim ledger item | `kind="claim"` |
23
+ | Handoff or trace pointer | `kind="trace_pointer"` with `payloadRef` |
24
+ | Lifecycle relation | `AionisRelation(kind="supersedes" | "contradicts" | "invalidates")` |
25
+ | Rehydrate hook | `lifecycle="rehydrate_required"` or `requires_payload` relation |
26
+ | Suppression/archive | `memory.lifecycle.transition` |
27
+ | Decision trace | `memory.decision.recorded` |
28
+ | Outcome attribution | `memory.feedback.recorded` |
29
+
30
+ Runtime product snapshot imports also preserve two agent-facing boundaries:
31
+
32
+ - execution outcome contracts can override weak textual trust. A succeeded
33
+ execution observation such as `passed_solution` becomes active/trusted
34
+ substrate memory, while a failed branch or failed verifier becomes
35
+ blocked/rejected memory.
36
+ - audit-only nodes marked `not_agent_facing` are skipped by the agent-facing
37
+ snapshot importer. Guide exposure ledgers and measure receipts remain Runtime
38
+ audit evidence; they must not become rehydrate hooks in compiled Agent context.
39
+
40
+ ## Admission Boundary
41
+
42
+ Runtime currently owns the richer product policy. Substrate owns the minimum storage-level contract:
43
+
44
+ - authoritative active memory may be directly used.
45
+ - unknown/candidate memory must be inspected.
46
+ - rejected/suppressed/retired memory must not be used.
47
+ - archived/payload-required memory must be a rehydrate hook.
48
+ - supersede/contradict/invalidate relations can block direct use.
49
+
50
+ This separation matters:
51
+
52
+ - Runtime can evolve admission policy without changing the storage event model.
53
+ - Substrate can remain deterministic and auditable.
54
+ - Future adapters can be tested against the same contract.
55
+
56
+ ## Safe Integration Sequence
57
+
58
+ 1. Keep Substrate independent.
59
+ 2. Export a small read-only Runtime snapshot into Substrate.
60
+ 3. Compare Runtime guide buckets with Substrate compiled buckets.
61
+ 4. Add experimental dual-write outside Runtime core.
62
+ 5. Only after repeated parity runs, consider a Runtime adapter.
63
+
64
+ ## Explicit Non-goals
65
+
66
+ - Do not replace Runtime SQLite/Zvec yet.
67
+ - Do not add benchmark-specific rules to Substrate.
68
+ - Do not make Substrate responsible for LLM reasoning.
69
+ - Do not let Substrate output source-code repair procedures.
@@ -0,0 +1,129 @@
1
+ # Runtime Reference Corpus Parity
2
+
3
+ `runtime-reference-corpus` checks whether exported Runtime `agent_context` or
4
+ `memory_decision_trace` JSON can be tied back to real Runtime Lite SQLite data.
5
+
6
+ It is intentionally stricter than demo validation:
7
+
8
+ - references are parsed for concrete memory ids only;
9
+ - Runtime scopes are discovered from `lite_memory_nodes`;
10
+ - a reference is matched to a scope only when memory ids overlap;
11
+ - unmatched references stay in `unmatched_reference_reports` and are not counted
12
+ as parity evidence.
13
+
14
+ ## Run
15
+
16
+ ```bash
17
+ npm run check:runtime-reference-corpus -- \
18
+ --source-root /Volumes/ziel/AionisRuntime-focused/.tmp \
19
+ --reference-root /Volumes/ziel/AionisRuntime-focused/docs/examples \
20
+ --max-source-files all \
21
+ --max-scopes-per-file 20 \
22
+ --max-scopes 100 \
23
+ --max-references all
24
+ ```
25
+
26
+ The default output is written under `reports/runtime-reference-corpus-*/summary.json`.
27
+
28
+ ## Report fields
29
+
30
+ - `matched_references`: reference JSON files with at least `min_overlap` ids
31
+ found in a Runtime SQLite scope.
32
+ - `unmatched_references`: reference JSON files that had no Runtime scope overlap,
33
+ or contained no recognizable Runtime admission surfaces.
34
+ - `exact_matches`: matched references where Substrate `compileContext` buckets
35
+ exactly match Runtime reference buckets.
36
+ - `partial_matches`: matched references where both sides were available but at
37
+ least one bucket differed.
38
+
39
+ This tool does not prove Runtime product behavior by itself. It proves whether a
40
+ reference artifact is a real, traceable Runtime parity artifact or only an
41
+ unmatched demo/export file.
42
+
43
+ ## Current focused Runtime check
44
+
45
+ On 2026-06-25, the tool was run against:
46
+
47
+ ```bash
48
+ npm run check:runtime-reference-corpus -- \
49
+ --source-root /Volumes/ziel/AionisRuntime-focused \
50
+ --reference-root /Volumes/ziel/AionisRuntime-focused/docs/examples \
51
+ --max-source-files all \
52
+ --max-scopes all \
53
+ --max-scopes-per-file 100 \
54
+ --max-references all
55
+ ```
56
+
57
+ Result: 30 SQLite files were discovered, 14 contained Runtime Lite scopes, 228
58
+ candidate scopes were scanned, 36 reference JSON files were scanned, and 4 files
59
+ contained extractable Runtime admission surfaces. None of those 4 reference files
60
+ shared memory ids with the scanned Runtime SQLite scopes.
61
+
62
+ That means the current `docs/examples` files are useful product examples, but
63
+ they are not current real Runtime reference parity artifacts for the local
64
+ SQLite corpus. A future real parity run should export guide/measure JSON from
65
+ the same Runtime database snapshot that is supplied as `--source-root`.
66
+
67
+ ## Same-source reference fixture
68
+
69
+ Use `make:runtime-product-reference` to create a same-source artifact pair:
70
+
71
+ 1. start `AionisRuntime-focused` as a local Lite Runtime;
72
+ 2. force its write/replay SQLite files into the output directory;
73
+ 3. run a real `/v1/observe -> /v1/guide -> /v1/feedback -> /v1/measure`
74
+ product loop through the Runtime SDK;
75
+ 4. write `reference.json` containing the returned `agent_context` and
76
+ `memory_decision_trace`;
77
+ 5. run `check:runtime-reference-corpus` against that exact SQLite/reference pair.
78
+
79
+ ```bash
80
+ npm run make:runtime-product-reference -- \
81
+ --runtime-root /Volumes/ziel/AionisRuntime-focused \
82
+ --scenario-count 4
83
+ ```
84
+
85
+ Outputs are written to `reports/runtime-product-reference-*/`:
86
+
87
+ - `runtime-write.sqlite`
88
+ - `runtime-replay.sqlite`
89
+ - `references/*.json`
90
+ - `scenario-summaries/*.json`
91
+ - `parity-summary.json`
92
+ - `run-summary.json`
93
+
94
+ The default `--scenario-count` is `1` for quick smoke checks. Use
95
+ `--scenario-count 4` to exercise the current built-in same-source corpus:
96
+ active route, schema migration, context compiler, and feedback attribution.
97
+ Every scenario is written through the focused Runtime SDK into the same Runtime
98
+ SQLite file, then matched back to its own exported Runtime guide/measure
99
+ reference by concrete memory id overlap.
100
+
101
+ This command is intentionally outside Runtime core. It creates a traceable
102
+ reference artifact for Substrate parity; it does not mutate the focused Runtime
103
+ repository and does not use `docs/examples` as evidence.
104
+
105
+ ## Current same-source boundary
106
+
107
+ The built-in same-source product fixture currently validates the execution
108
+ continuity path that Runtime itself exposes from the same Lite SQLite file:
109
+
110
+ - accepted execution state enters `use_now`;
111
+ - failed execution branches enter `do_not_use`;
112
+ - measure/debug/audit records are retained as audit evidence and excluded from
113
+ agent-facing Substrate import.
114
+
115
+ It does not claim full four-bucket Runtime parity. In particular,
116
+ `inspect_before_use` and `rehydrate` have separate Runtime product paths:
117
+
118
+ - ordinary/candidate memory admission is surfaced through planning recall and
119
+ external candidate governance;
120
+ - archived/payload evidence becomes a rehydration hook only when the Runtime
121
+ guide surface returns that hook.
122
+
123
+ Substrate already supports those buckets at the store contract level, and the
124
+ contract benchmark covers them. The same-source Runtime reference corpus should
125
+ only count `inspect_before_use` or `rehydrate` when the focused Runtime exports
126
+ those exact memory ids in `agent_context` or `memory_decision_trace`. Do not
127
+ force extra local SQLite rows into those buckets just to increase apparent
128
+ coverage; that would turn parity into a runner-specific assertion instead of a
129
+ Runtime reference.
@@ -0,0 +1,81 @@
1
+ # Runtime Snapshot Corpus Validation
2
+
3
+ The corpus checker validates whether Aionis Substrate can represent real Aionis Runtime Lite SQLite snapshots without mutating Runtime data.
4
+
5
+ It is a read-only validation path:
6
+
7
+ 1. scan Runtime SQLite files;
8
+ 2. select Runtime scopes;
9
+ 3. import each scope into a temporary Substrate SQLite store;
10
+ 4. compile Substrate context;
11
+ 5. aggregate import coverage, bucket counts, warnings, and failures.
12
+
13
+ It does not replace Runtime storage and does not install dual-write.
14
+
15
+ ## CLI
16
+
17
+ ```bash
18
+ npm run check:runtime-corpus -- \
19
+ --root /path/to/AionisRuntime-focused/.tmp \
20
+ --max-files all \
21
+ --max-scopes 100 \
22
+ --max-scopes-per-file 20 \
23
+ --min-nodes 1 \
24
+ --max-per-bucket 50
25
+ ```
26
+
27
+ The command writes a report under `reports/runtime-snapshot-corpus-*` unless `--output` is supplied.
28
+
29
+ ## Report Fields
30
+
31
+ - `discovered_sqlite_files`: SQLite-like files found under the root.
32
+ - `runtime_sqlite_files`: files with Runtime `lite_memory_nodes`.
33
+ - `candidate_scopes`: scopes selected from Runtime files before global truncation.
34
+ - `attempted_scopes`: scopes actually imported.
35
+ - `passed_scopes`: scopes imported and compiled successfully.
36
+ - `failed_scopes`: scopes that failed import or compile.
37
+ - `total_nodes_imported`: imported Runtime nodes.
38
+ - `total_warnings`: scan and import warnings.
39
+ - `scope_reports`: per-scope import and bucket summary.
40
+
41
+ ## Interpretation
42
+
43
+ This checker proves storage-contract coverage, not Runtime policy superiority.
44
+
45
+ Good results mean:
46
+
47
+ - Runtime SQLite sources can be opened read-only;
48
+ - Runtime memory nodes can be mapped into Substrate nodes;
49
+ - Substrate can compile governed context for real scopes;
50
+ - warnings and failures are visible.
51
+
52
+ Bad results should be treated as mapping or substrate-contract evidence, not as a reason to mutate Aionis Runtime core.
53
+
54
+ ## Local Validation Snapshot
55
+
56
+ Latest local run:
57
+
58
+ ```bash
59
+ npm run check:runtime-corpus -- \
60
+ --root /Volumes/ziel/AionisRuntime-focused/.tmp \
61
+ --max-files all \
62
+ --max-scopes 100 \
63
+ --max-scopes-per-file 20 \
64
+ --min-nodes 1 \
65
+ --max-per-bucket 50
66
+ ```
67
+
68
+ Result on 2026-06-25:
69
+
70
+ - discovered SQLite files: 30
71
+ - Runtime SQLite files: 14
72
+ - candidate scopes: 128
73
+ - attempted scopes: 100
74
+ - passed scopes: 100
75
+ - failed scopes: 0
76
+ - imported Runtime nodes: 8,948
77
+ - warnings: 0
78
+
79
+ Local report:
80
+
81
+ `reports/runtime-snapshot-corpus-2026-06-25T11-54-32-014Z/summary.json`
@@ -0,0 +1,120 @@
1
+ # Runtime Lite Snapshot Import
2
+
3
+ This importer reads an existing Aionis Runtime Lite SQLite database and writes a one-way snapshot into an independent Aionis Substrate store.
4
+
5
+ It is intentionally not a Runtime integration path:
6
+
7
+ - source Runtime SQLite is opened read-only;
8
+ - no Runtime table is created, altered, or updated;
9
+ - no dual-write is installed;
10
+ - no Runtime guide/admission rule is changed;
11
+ - no benchmark or host-specific behavior is encoded.
12
+
13
+ The importer exists to answer one engineering question:
14
+
15
+ > Can the Substrate contract represent Runtime memory evidence, relations, feedback, and decision traces without polluting the focused Runtime?
16
+
17
+ ## Source Tables
18
+
19
+ The importer currently understands the focused Runtime Lite write-store tables:
20
+
21
+ - `lite_memory_nodes`
22
+ - `lite_memory_edges`
23
+ - `lite_memory_execution_native_index`
24
+ - `lite_memory_rule_feedback`
25
+ - `lite_memory_execution_decisions`
26
+
27
+ `lite_memory_nodes` is required. Other tables are optional; missing optional tables are treated as empty.
28
+
29
+ ## Mapping
30
+
31
+ Runtime nodes become Substrate memory nodes:
32
+
33
+ - `id`, `scope`, `title`, `text_summary`, `confidence`, agent/team ownership, and Runtime metadata are preserved.
34
+ - `slots_json` and execution-native index fields are preserved under `metadata.runtime_slots` and `metadata.runtime_execution_index`.
35
+ - execution target files are collected from `slots_json` and `lite_memory_execution_native_index`.
36
+ - Runtime raw/evidence references become `payloadRef`.
37
+
38
+ Admission state is mapped conservatively:
39
+
40
+ - explicit active/trusted/current/workflow-anchor evidence can enter `use_now`;
41
+ - candidate/advisory/unknown evidence enters `inspect_before_use`;
42
+ - archived/cold payload evidence enters `rehydrate`;
43
+ - `supersedes`, `contradicts`, and `invalidates` relations block direct use through `do_not_use`.
44
+
45
+ Runtime edges become Substrate relations:
46
+
47
+ - `supersedes`, `contradicts`, `invalidates`, `requires_payload`, `derived_from`, or `supports`.
48
+ - relation metadata preserves Runtime edge type, weight, decay, commit id, and metadata JSON.
49
+
50
+ Rule feedback becomes Substrate feedback when the referenced rule node was imported.
51
+
52
+ Execution decisions become Substrate decision traces when their referenced source rules were imported.
53
+
54
+ ## CLI
55
+
56
+ SQLite target:
57
+
58
+ ```bash
59
+ node scripts/import-runtime-snapshot.ts \
60
+ --source /path/to/aionis-runtime-lite.sqlite \
61
+ --target /tmp/aionis-substrate.sqlite \
62
+ --adapter sqlite \
63
+ --scope repo-a
64
+ ```
65
+
66
+ File target:
67
+
68
+ ```bash
69
+ node scripts/import-runtime-snapshot.ts \
70
+ --source /path/to/aionis-runtime-lite.sqlite \
71
+ --target /tmp/aionis-substrate-file-store \
72
+ --adapter file
73
+ ```
74
+
75
+ The command prints a JSON summary with imported/skipped counts and warnings.
76
+
77
+ ## Parity Checker
78
+
79
+ The parity checker imports a Runtime Lite SQLite snapshot into an isolated SQLite Substrate store, compiles a Substrate context, and optionally compares its bucket ids with a Runtime guide/measure JSON file.
80
+
81
+ Smoke mode, without Runtime reference JSON:
82
+
83
+ ```bash
84
+ npm run check:runtime-snapshot -- \
85
+ --source /path/to/aionis-runtime-lite.sqlite \
86
+ --scope repo-a \
87
+ --output /tmp/runtime-snapshot-smoke.json
88
+ ```
89
+
90
+ Parity mode, with a Runtime response containing `agent_context` and/or `memory_decision_trace`:
91
+
92
+ ```bash
93
+ npm run check:runtime-snapshot -- \
94
+ --source /path/to/aionis-runtime-lite.sqlite \
95
+ --scope repo-a \
96
+ --reference /path/to/runtime-guide-or-measure.json \
97
+ --output /tmp/runtime-snapshot-parity.json
98
+ ```
99
+
100
+ The checker compares:
101
+
102
+ - `use_now`
103
+ - `inspect_before_use`
104
+ - `do_not_use`
105
+ - `rehydrate`
106
+
107
+ The Runtime reference may be a direct `agent_context`, a direct `memory_decision_trace`, or a larger JSON object containing either surface.
108
+
109
+ When no reference is supplied, the report is still useful: it gives import coverage, skipped rows, warnings, and Substrate bucket counts for a real Runtime DB.
110
+
111
+ ## Product Boundary
112
+
113
+ This is a read-only bridge for validation. It is not a replacement for Runtime Lite SQLite, Zvec, AIFS, or the product facade.
114
+
115
+ The safe sequence remains:
116
+
117
+ 1. import Runtime snapshots into an isolated Substrate store;
118
+ 2. compare admission buckets and decision traces outside Runtime;
119
+ 3. run parity and negative-control tests;
120
+ 4. only then decide whether any Runtime adapter is worth productizing.
@@ -0,0 +1,181 @@
1
+ # Aionis Store Contract
2
+
3
+ This document defines the first Aionis Substrate boundary. It is intentionally about memory semantics, not about a storage engine.
4
+
5
+ ## Non-goals
6
+
7
+ - It is not a general database.
8
+ - It is not a vector database.
9
+ - It is not an Agent framework.
10
+ - It is not connected to Aionis Runtime yet.
11
+ - It must not encode task-specific repair rules or benchmark fixtures.
12
+
13
+ ## Core Model
14
+
15
+ ### Event Log
16
+
17
+ Every durable mutation is recorded as an append-only event:
18
+
19
+ - `memory.node.upsert`
20
+ - `memory.lifecycle.transition`
21
+ - `memory.relation.upsert`
22
+ - `memory.feedback.recorded`
23
+ - `memory.decision.recorded`
24
+ - `substrate.checkpoint.created`
25
+
26
+ The event log is the evidence trail. Read models may be rebuilt from it or maintained alongside it, but they are not the authority boundary.
27
+
28
+ `substrate.checkpoint.created` is a physical compaction event. It contains a checksum-covered snapshot of the current substrate state plus metadata about the covered event history. It does not suppress, archive, delete, or promote memory by itself.
29
+
30
+ ### Store Schema Version
31
+
32
+ Every store has a substrate schema version. The current schema version is `1`.
33
+
34
+ Adapters must expose schema metadata through `getStoreInfo`:
35
+
36
+ - adapter kind
37
+ - schema version
38
+ - last event sequence
39
+ - event count
40
+
41
+ The SQLite adapter persists schema metadata in `substrate_metadata` and mirrors the same version into SQLite `user_version`. Opening a store with a newer unsupported schema must fail before any mutation occurs.
42
+
43
+ The file adapter writes the same schema version into `snapshot.json`. The append-only event log remains the durable evidence source; the snapshot schema is the derived read-model format.
44
+
45
+ ### Backup Boundary
46
+
47
+ Backups export the append-only event log plus schema metadata and a SHA-256 checksum over the canonical event list.
48
+
49
+ Restore must verify the backup before writing a target store. Restored stores preserve original event ids and sequence numbers, then rebuild derived read models.
50
+
51
+ Payload files referenced by `payloadRef` are not embedded in the Substrate backup. They remain external artifacts and need their own retention policy.
52
+
53
+ ### Checkpoint Compaction
54
+
55
+ Adapters may compact a long event log into a `substrate.checkpoint.created` event.
56
+
57
+ The checkpoint must preserve:
58
+
59
+ - covered event count;
60
+ - covered last sequence;
61
+ - SHA-256 checksum of the covered event list;
62
+ - current memory nodes;
63
+ - current relations;
64
+ - current feedback records;
65
+ - current decision traces.
66
+
67
+ After compaction, the physical log sequence restarts at the checkpoint event. Future writes continue after that checkpoint. This is a storage-maintenance boundary only; it must not change admission buckets or lifecycle state.
68
+
69
+ ### Memory Node
70
+
71
+ A memory node is a governed memory object:
72
+
73
+ - `scope`
74
+ - `kind`
75
+ - `summary`
76
+ - `lifecycle`
77
+ - `authority`
78
+ - `confidence`
79
+ - optional target files
80
+ - optional payload pointer
81
+ - optional owner identity
82
+
83
+ The store treats execution memory, procedure memory, facts, preferences, claims, feedback, and trace pointers as first-class node kinds. It does not flatten all memory into free text.
84
+
85
+ ### Search Contract
86
+
87
+ `searchNodes` is a read-only substrate query over memory nodes.
88
+
89
+ It must:
90
+
91
+ - require an explicit `scope`;
92
+ - keep all results scoped;
93
+ - support exact filters for kind, lifecycle, authority, target file, owner identity, confidence, and update time;
94
+ - provide deterministic lexical query scoring over node id, title, summary, target files, payload pointer, owner ids, and primitive metadata;
95
+ - return scored results with inspectable reason codes;
96
+ - avoid writing decision events or mutating lifecycle state.
97
+
98
+ Search is not admission. It may find candidate evidence, but it must not decide whether memory can influence the next Agent turn. Governed prompt surfaces are produced by `compileContext`.
99
+
100
+ ### Relation Graph
101
+
102
+ Relations connect memory evidence:
103
+
104
+ - `supports`
105
+ - `derived_from`
106
+ - `supersedes`
107
+ - `contradicts`
108
+ - `invalidates`
109
+ - `requires_payload`
110
+
111
+ Relations are scoped. A relation in one scope must never affect admission in another scope.
112
+
113
+ ### Lifecycle
114
+
115
+ Forgetting is represented as state, not deletion.
116
+
117
+ Allowed lifecycle states:
118
+
119
+ - `active`
120
+ - `candidate`
121
+ - `contested`
122
+ - `suppressed`
123
+ - `archived`
124
+ - `retired`
125
+ - `blocked`
126
+ - `rehydrate_required`
127
+
128
+ The store must keep the old evidence and express changes through lifecycle transitions and relations.
129
+
130
+ ## Admission Contract
131
+
132
+ The store compiles memory into four buckets:
133
+
134
+ - `use_now`: directly usable context.
135
+ - `inspect_before_use`: relevant but not authoritative.
136
+ - `do_not_use`: blocked, superseded, contradicted, invalidated, rejected, suppressed, retired, or unsafe.
137
+ - `rehydrate`: payload exists but should not be stuffed into the prompt until requested.
138
+
139
+ The current deterministic admission baseline is deliberately conservative:
140
+
141
+ - active + trusted/verified memory may enter `use_now`.
142
+ - candidate/contested/advisory/unknown memory enters `inspect_before_use`.
143
+ - suppressed/retired/blocked/rejected memory enters `do_not_use`.
144
+ - archived or payload-required memory enters `rehydrate`.
145
+ - high-confidence supersede/contradict/invalidate relations block direct use.
146
+ - payload-required relations route to `rehydrate`.
147
+
148
+ This is not the final Aionis Runtime admission policy. It is the substrate-level minimum contract.
149
+
150
+ ## Decision Trace
151
+
152
+ Every compiled context must include a decision trace:
153
+
154
+ - which memory id was routed
155
+ - what bucket it entered
156
+ - which reason code caused the decision
157
+ - which relation caused the decision when applicable
158
+
159
+ The trace is for audit/debug/measure. It must not mutate admission by itself.
160
+
161
+ `previewContext` is the side-effect-free admission preview. It returns the same bucket and reason-code shape as `compileContext`, but it must not append events or insert decision rows.
162
+
163
+ `compileContext` is intentionally not a pure read. It records `memory.decision.recorded` so every exported context has an auditable receipt. Tools that need a side-effect-free view must use `previewContext` instead of treating `compileContext` as read-only.
164
+
165
+ ## Adapter Requirements
166
+
167
+ Every adapter must satisfy the same observable contract:
168
+
169
+ 1. Persist append-only events.
170
+ 2. Preserve scope isolation.
171
+ 3. Keep lifecycle transitions instead of deleting memory.
172
+ 4. Compile the same admission buckets from the same node/relation state.
173
+ 5. Return the same scoped search results from the same node state.
174
+ 6. Record decision traces as events.
175
+ 7. Reopen cleanly and recover the same read model.
176
+ 8. If compaction is supported, compact only through a validated checkpoint event.
177
+
178
+ Current adapters:
179
+
180
+ - `openFileAionisSubstrate`: append-only JSONL plus derived JSON snapshot.
181
+ - `openSqliteAionisSubstrate`: SQLite event table plus structured read model tables.
@@ -0,0 +1,19 @@
1
+ # Basic Example
2
+
3
+ This example runs the smallest useful Substrate loop:
4
+
5
+ 1. open a file-backed store;
6
+ 2. write current and stale execution memories;
7
+ 3. link the stale memory with a `supersedes` relation;
8
+ 4. preview context without writing a receipt;
9
+ 5. compile context with a `memory.decision.recorded` receipt;
10
+ 6. record positive feedback;
11
+ 7. search deterministic memory candidates;
12
+ 8. export and verify a backup;
13
+ 9. open a SQLite store and compile a rehydrate hook.
14
+
15
+ Run it from the repository root:
16
+
17
+ ```bash
18
+ npm run example:basic
19
+ ```