ds4-context-engine 0.1.2 → 0.2.0-beta.2
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/README.md +84 -14
- package/docs/ARCHITECTURE.md +42 -16
- package/docs/CONTEXT_MANIFEST.md +3 -1
- package/docs/CONTEXT_PLANNER.md +9 -1
- package/docs/CONTEXT_QUALITY.md +91 -0
- package/docs/HYBRID_RETRIEVAL.md +117 -0
- package/docs/LEARNED_RANKING.md +90 -0
- package/docs/LOCAL_KV_REUSE.md +131 -0
- package/docs/MEMORY_AND_PINS.md +11 -5
- package/docs/PORTABLE_CORE.md +15 -8
- package/docs/PROJECT_KNOWLEDGE.md +26 -16
- package/docs/RELEASING.md +18 -13
- package/docs/RETRIEVAL.md +1 -1
- package/docs/ROADMAP_0.2.0.md +15 -1
- package/docs/RUNTIME_ADAPTER_KIT.md +145 -0
- package/docs/STORAGE.md +37 -7
- package/package.json +12 -7
- package/quality/corpus-v1.json +208 -0
- package/quality/semantic-corpus-v1.json +84 -0
- package/quality/symbol-corpus-v1.json +38 -0
- package/scripts/compare-context-quality.mjs +23 -0
- package/src/extension/commands.ts +213 -1
- package/src/extension/index.ts +1 -0
- package/src/extension/runtime.ts +622 -16
- package/src/pi-adapter/local-embedding.ts +132 -0
- package/src/pi-adapter/memory-adapter.ts +18 -8
- package/src/pi-adapter/project-memory-sync.ts +499 -0
- package/src/pi-adapter/ranking-adapter.ts +72 -0
- package/src/pi-adapter/runtime-contract.ts +86 -0
- package/src/pi-adapter/version.ts +3 -3
package/docs/RELEASING.md
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
# Releasing DS4
|
|
2
2
|
|
|
3
|
-
DS4 publishes
|
|
3
|
+
DS4 publishes three packages with the same version:
|
|
4
4
|
|
|
5
|
-
1. `ds4-context-core`, the runtime-neutral compiled package;
|
|
6
|
-
2. `ds4-context-
|
|
5
|
+
1. `ds4-context-core`, the runtime-neutral compiled package and adapter kit;
|
|
6
|
+
2. `ds4-context-reference-adapter`, the non-Pi callback/JSONL reference implementation;
|
|
7
|
+
3. `ds4-context-engine`, the Pi adapter.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
Both adapters have an exact dependency on the matching core version, so core must be published first.
|
|
9
10
|
|
|
10
11
|
## Prerequisites
|
|
11
12
|
|
|
12
13
|
- use a clean `main` checkout synchronized with `origin/main`;
|
|
13
|
-
- use a supported Node.js release and npm account authorized for
|
|
14
|
-
- verify that
|
|
15
|
-
- verify that
|
|
14
|
+
- use a supported Node.js release and npm account authorized for all three package names;
|
|
15
|
+
- verify that all three `package.json` files use the intended version;
|
|
16
|
+
- verify that both adapters depend exactly on that version of `ds4-context-core`;
|
|
16
17
|
- do not include session data, `.pi` state, databases, credentials, or provider payloads.
|
|
17
18
|
|
|
18
|
-
The automated package check enforces matching versions,
|
|
19
|
+
The automated package check enforces matching versions, exact core dependencies, runtime-SDK isolation, bounded tarball inventories, clean consumer installation, core ESM exports, compiled reference-adapter conformance, and packaged Pi extension startup through isolated RPC state.
|
|
19
20
|
|
|
20
21
|
## Validate
|
|
21
22
|
|
|
@@ -29,26 +30,29 @@ git status --short
|
|
|
29
30
|
|
|
30
31
|
CI runs the same checks on the minimum supported Node.js version and the current Node.js LTS line. `npm run pack:check` uses a temporary directory and removes it when complete. Set `DS4_KEEP_PACK_TMP=1` only when diagnosing a failed package check.
|
|
31
32
|
|
|
32
|
-
Review
|
|
33
|
+
Review all public tarballs before publishing:
|
|
33
34
|
|
|
34
35
|
```bash
|
|
35
36
|
npm pack --dry-run --workspace ds4-context-core
|
|
37
|
+
npm pack --dry-run --workspace ds4-context-reference-adapter
|
|
36
38
|
npm pack --dry-run
|
|
37
39
|
```
|
|
38
40
|
|
|
39
41
|
## Version
|
|
40
42
|
|
|
41
|
-
Keep the root package,
|
|
43
|
+
Keep the root package, both workspaces, and exact adapter dependencies synchronized. For a future version stored in `$VERSION`:
|
|
42
44
|
|
|
43
45
|
```bash
|
|
44
46
|
npm pkg set version="$VERSION"
|
|
45
47
|
npm pkg set version="$VERSION" --workspace ds4-context-core
|
|
48
|
+
npm pkg set version="$VERSION" --workspace ds4-context-reference-adapter
|
|
46
49
|
npm pkg set dependencies.ds4-context-core="$VERSION"
|
|
50
|
+
npm pkg set dependencies.ds4-context-core="$VERSION" --workspace ds4-context-reference-adapter
|
|
47
51
|
npm install --package-lock-only
|
|
48
52
|
npm run pack:check
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
Review `package.json`,
|
|
55
|
+
Review `package.json`, both workspace package manifests, and `package-lock.json` before committing the release change.
|
|
52
56
|
|
|
53
57
|
## Publish
|
|
54
58
|
|
|
@@ -57,12 +61,13 @@ Authenticate with npm, verify the active account, and publish in dependency orde
|
|
|
57
61
|
```bash
|
|
58
62
|
npm whoami
|
|
59
63
|
npm publish --workspace ds4-context-core --access public
|
|
64
|
+
npm publish --workspace ds4-context-reference-adapter --access public
|
|
60
65
|
npm publish --access public
|
|
61
66
|
```
|
|
62
67
|
|
|
63
|
-
If core succeeds but adapter publication fails, fix
|
|
68
|
+
If core succeeds but an adapter publication fails, fix that adapter release and retry it with the same version. Do not rewrite or unpublish a valid core release merely to make the commands appear atomic.
|
|
64
69
|
|
|
65
|
-
After
|
|
70
|
+
After all registry packages are available:
|
|
66
71
|
|
|
67
72
|
1. install them in a fresh temporary project and rerun the package smoke check if registry propagation was delayed;
|
|
68
73
|
2. create and push the signed or annotated `v$VERSION` tag;
|
package/docs/RETRIEVAL.md
CHANGED
|
@@ -15,7 +15,7 @@ M6 recovers original session evidence that Pi compaction removed from the active
|
|
|
15
15
|
9. Deduplicate normalized identical text, preferring the higher-ranked/newer source.
|
|
16
16
|
10. Build individually bounded evidence messages, enforce the active provider privacy policy, and let the managed planner fit allowed groups after recent turns but before summaries.
|
|
17
17
|
|
|
18
|
-
No LLM is called during retrieval. `retrieval.semantic: true`
|
|
18
|
+
No chat LLM is called during retrieval. Since M16, `retrieval.semantic: true` adds opt-in vectors through the runtime-neutral `EmbeddingPort`; exact and FTS retrieval remain authoritative and any embedding failure falls back to lexical results. See [Hybrid Semantic Retrieval](HYBRID_RETRIEVAL.md).
|
|
19
19
|
|
|
20
20
|
## Ranking
|
|
21
21
|
|
package/docs/ROADMAP_0.2.0.md
CHANGED
|
@@ -49,6 +49,8 @@ M14 is first because adaptive ranking must be measured against a stable baseline
|
|
|
49
49
|
|
|
50
50
|
## M14 — Context Quality Metrics
|
|
51
51
|
|
|
52
|
+
Status: **implemented on `main` for `0.2.0-alpha.1`**. The active planner remains the 0.1 deterministic baseline; quality collection is opt-in and candidate strategies are replay-only.
|
|
53
|
+
|
|
52
54
|
### Deliverables
|
|
53
55
|
|
|
54
56
|
- A sanitized replay corpus with expected evidence source IDs and task descriptors.
|
|
@@ -70,6 +72,8 @@ Quality samples store planner/profile versions, source-kind counts, token totals
|
|
|
70
72
|
|
|
71
73
|
## M15 — Rich Symbol Indexing
|
|
72
74
|
|
|
75
|
+
Status: **implemented on `main` for `0.2.0-alpha.1`**. Structural parsing remains a disposable local projection; unsupported or invalid source retains deterministic text-window behavior.
|
|
76
|
+
|
|
73
77
|
### Deliverables
|
|
74
78
|
|
|
75
79
|
- A parser interface in `ds4-context-core` with deterministic regex fallback.
|
|
@@ -90,6 +94,8 @@ The parser implementation must not introduce a mandatory native build dependency
|
|
|
90
94
|
|
|
91
95
|
## M16 — Hybrid Semantic Retrieval
|
|
92
96
|
|
|
97
|
+
Status: **implemented on `main` for `0.2.0-alpha.2`**. Semantic retrieval remains opt-in; exact/FTS ranking and lexical-only failure behavior remain available.
|
|
98
|
+
|
|
93
99
|
### Deliverables
|
|
94
100
|
|
|
95
101
|
- A runtime-neutral embedding port; model invocation remains outside core.
|
|
@@ -111,6 +117,8 @@ Semantic retrieval does not replace exact matching. Exact paths, symbols, quoted
|
|
|
111
117
|
|
|
112
118
|
## M17 — Cross-Session Project Memory
|
|
113
119
|
|
|
120
|
+
Status: **implemented on `main` behind `memory.crossSession` for `0.2.0-alpha.3`**. Discovery remains opt-in and exact trusted project identity is mandatory.
|
|
121
|
+
|
|
114
122
|
### Deliverables
|
|
115
123
|
|
|
116
124
|
- Discovery of canonical Pi session JSONL files associated with the same trusted canonical project identity.
|
|
@@ -131,6 +139,8 @@ Version 0.2.0 does not silently extract new memories from conversation text. A d
|
|
|
131
139
|
|
|
132
140
|
## M18 — Learned Ranking
|
|
133
141
|
|
|
142
|
+
Status: **implemented on `main` for `0.2.0-beta.1` with `off`, aggregate-only `shadow`, and promotion-gated `active` modes**. Static ranking remains authoritative for missing, corrupt, incompatible, unpromoted or regressing artifacts.
|
|
143
|
+
|
|
134
144
|
### Deliverables
|
|
135
145
|
|
|
136
146
|
- A bounded feature schema based on metadata such as source kind, exact/FTS/vector scores, recency, branch relation, symbol relation, classification eligibility, token cost and prior selection outcome.
|
|
@@ -153,6 +163,8 @@ If the gate is not met, 0.2.0 ships shadow mode but keeps static ranking active.
|
|
|
153
163
|
|
|
154
164
|
## M19 — Runtime Adapter Kit
|
|
155
165
|
|
|
166
|
+
Status: **implemented on `main` and released in `0.2.0-beta.1`**. Core ships `runtime-adapter-v1` plus a framework-neutral conformance runner; Pi exposes contract capability diagnostics, and the separately packaged callback/JSONL reference adapter passes all seven conformance cases.
|
|
167
|
+
|
|
156
168
|
### Deliverables
|
|
157
169
|
|
|
158
170
|
- A documented adapter contract for canonical history snapshots, model limits, tool atomicity, trusted project roots, completion, privacy enforcement and lifecycle shutdown.
|
|
@@ -170,6 +182,8 @@ If the gate is not met, 0.2.0 ships shadow mode but keeps static ranking active.
|
|
|
170
182
|
|
|
171
183
|
## M20 — Local KV Capability
|
|
172
184
|
|
|
185
|
+
Status: **implemented on `main` and released in `0.2.0-beta.2` behind `localKvReuse.enabled`**. Core derives exact metadata-only eligibility fingerprints and guarantees full replay on every non-hit; injected runtime ports retain all volatile handles and transport. Pi remains explicitly unsupported.
|
|
186
|
+
|
|
173
187
|
### Deliverables
|
|
174
188
|
|
|
175
189
|
- An optional adapter capability for local inference runtimes that expose reusable prefix/KV state.
|
|
@@ -219,10 +233,10 @@ SQLite schema changes use forward migrations plus complete rebuild tests from ca
|
|
|
219
233
|
|
|
220
234
|
- M18 learned ranker in shadow mode.
|
|
221
235
|
- Privacy, rebuild, corruption and performance hardening for M14–M18.
|
|
236
|
+
- M19 adapter contract, conformance kit and reference adapter.
|
|
222
237
|
|
|
223
238
|
### `0.2.0-beta.2`
|
|
224
239
|
|
|
225
|
-
- M19 adapter contract, conformance kit and reference adapter.
|
|
226
240
|
- M20 local KV capability for runtimes that support it.
|
|
227
241
|
|
|
228
242
|
### `0.2.0-rc.1`
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Runtime Adapter Kit
|
|
2
|
+
|
|
3
|
+
M19 defines `runtime-adapter-v1`, a runtime-neutral boundary between DS4 policy and an agent host. The kit lives in `ds4-context-core/adapter/*`; the non-Pi implementation is published separately as `ds4-context-reference-adapter`. Core imports no runtime SDK.
|
|
4
|
+
|
|
5
|
+
## Dependency and state boundary
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
native agent runtime / provider SDK
|
|
9
|
+
↓
|
|
10
|
+
runtime adapter package
|
|
11
|
+
↓
|
|
12
|
+
ds4-context-core/adapter/runtime-adapter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
An adapter owns native history conversion, trusted-root discovery, provider completion, final privacy enforcement, optional runtime capabilities, and shutdown. Core owns contract types, deterministic capability negotiation, canonical tool-group validation, and the framework-neutral conformance runner.
|
|
16
|
+
|
|
17
|
+
The runtime's native history remains canonical. A `RuntimeHistorySnapshot` is a read-only projection with:
|
|
18
|
+
|
|
19
|
+
- `runtimeId`, `sessionId`, schema version, and deterministic source revision;
|
|
20
|
+
- one exact trusted canonical project root;
|
|
21
|
+
- ordered `CanonicalMessage` values with stable source-entry provenance;
|
|
22
|
+
- complete tool call/result atomic groups derived from canonical blocks.
|
|
23
|
+
|
|
24
|
+
Applying a DS4 context plan must not write provider-facing synthetic messages back into canonical history. Rebuild deletes or discards only adapter/DS4 projections and reproduces the snapshot from the native source.
|
|
25
|
+
|
|
26
|
+
## Contract
|
|
27
|
+
|
|
28
|
+
`RuntimeAdapter` requires:
|
|
29
|
+
|
|
30
|
+
| Method | Responsibility | Failure rule |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `snapshotHistory()` | Project the active canonical history and tool relations. | Reject an invalid, corrupt, identity-mismatched, or untrusted source. Never invent history. |
|
|
33
|
+
| `rebuildDerivedState()` | Discard adapter caches/projections and replay canonical state. | Preserve canonical files and the previous valid source. |
|
|
34
|
+
| `currentModel()` | Return provider/model limits through `ModelDescriptor`. | Return `undefined` when no model is selected. |
|
|
35
|
+
| `trustedProjectRoot()` | Return the runtime-approved canonical root. | Reject untrusted roots; do not broaden them. |
|
|
36
|
+
| `enforcePrivacy()` | Sanitize a provider payload immediately before transport. | Fail closed and do not invoke transport on error. |
|
|
37
|
+
| `complete()` | Invoke the runtime/provider boundary with the sanitized payload. | Return an explicit fallback result for invalid input, privacy failure, transport failure, or closed lifecycle. |
|
|
38
|
+
| `capabilityDeclarations()` / `negotiateCapabilities()` | Version and independently enable optional host features. | Missing or malformed declarations are unsupported, not fatal to other features. |
|
|
39
|
+
| `diagnostics()` | Return bounded metadata-only state. | Never include prompts, history, credentials, payloads, cache handles, or provider output. |
|
|
40
|
+
| `shutdown()` | Release adapter resources idempotently. | Further writes/completions fall back; history reads are rejected. |
|
|
41
|
+
|
|
42
|
+
Completion output remains runtime-owned and is not automatically canonical. An adapter must append a final runtime-native message through its ordinary canonical history API if the host chooses to persist it.
|
|
43
|
+
|
|
44
|
+
M20-capable adapters may additionally expose `localKvPort` and aggregate `localKvDiagnostics()`. Both are optional because most runtimes, including Pi, expose no native KV state. The port interface carries eligibility hashes and complete sanitized replay payloads but never returns or accepts a cache handle.
|
|
45
|
+
|
|
46
|
+
## Tool atomicity
|
|
47
|
+
|
|
48
|
+
`buildCanonicalToolAtomicGroups()` connects every canonical `toolCall` block to all matching `toolResult` blocks. Calls sharing one assistant message form one component, so parallel tool batches cannot be split. `validateRuntimeHistorySnapshot()` rejects missing, overlapping, unknown, or mismatched groups. An incomplete live call is represented by a group with `complete: false`; it cannot be treated as a complete selectable exchange.
|
|
49
|
+
|
|
50
|
+
## Capability negotiation
|
|
51
|
+
|
|
52
|
+
The v1 registry is fixed and additive contracts must use a later contract version:
|
|
53
|
+
|
|
54
|
+
- `compaction`;
|
|
55
|
+
- `provider-continuation`;
|
|
56
|
+
- `embeddings`;
|
|
57
|
+
- `local-kv-reuse`.
|
|
58
|
+
|
|
59
|
+
A supported capability requires a non-empty implementation version. Unsupported capabilities require a bounded reason. `negotiateRuntimeCapabilities()` evaluates each request independently:
|
|
60
|
+
|
|
61
|
+
- a supported requested capability is enabled;
|
|
62
|
+
- an unsupported optional capability is disabled with an informational diagnostic;
|
|
63
|
+
- an unsupported required capability is disabled with a warning;
|
|
64
|
+
- a duplicate, missing, or unversioned declaration is malformed and disabled;
|
|
65
|
+
- no failure in one capability disables canonical history, privacy, completion fallback, or another valid capability.
|
|
66
|
+
|
|
67
|
+
M19 introduced negotiation for `local-kv-reuse`; M20 adds `local-kv-eligibility-v1`, `LocalKvReuseController`, and the handle-free `LocalKvRuntimePort`. KV handles are never part of canonical history, core state, manifests, or diagnostics. See [Local KV Reuse](LOCAL_KV_REUSE.md).
|
|
68
|
+
|
|
69
|
+
Pi advertises versioned compaction, OpenAI Responses continuation, and embedding-port support. It explicitly reports local KV reuse as unavailable. `/context adapter` shows the complete negotiation; `/context status` shows aggregate enabled/disabled counts.
|
|
70
|
+
|
|
71
|
+
## Reusable conformance kit
|
|
72
|
+
|
|
73
|
+
The conformance runner has no Vitest/Jest dependency. Adapter packages provide a factory that maps a versioned fixture and injected completion transport into their native runtime:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import {
|
|
77
|
+
assertRuntimeAdapterConformance,
|
|
78
|
+
runRuntimeAdapterConformance,
|
|
79
|
+
} from "ds4-context-core/adapter/conformance";
|
|
80
|
+
|
|
81
|
+
const report = await runRuntimeAdapterConformance({
|
|
82
|
+
name: "my-runtime",
|
|
83
|
+
async create(fixture, transport) {
|
|
84
|
+
// Create native canonical history from fixture.messages.
|
|
85
|
+
// Inject transport at the final provider boundary.
|
|
86
|
+
return { adapter, expectedProjectRoot, cleanup };
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
assertRuntimeAdapterConformance(report);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The seven checks cover:
|
|
93
|
+
|
|
94
|
+
1. adapter/contract identity, model limits, and trusted root;
|
|
95
|
+
2. complete capability declarations and isolated unsupported diagnostics;
|
|
96
|
+
3. ordered canonical history and tool atomicity;
|
|
97
|
+
4. deterministic rebuild from canonical state;
|
|
98
|
+
5. remote privacy filtering plus synthetic sanitizer failure before observed transport;
|
|
99
|
+
6. safe transport failure with native fallback still available;
|
|
100
|
+
7. idempotent shutdown and closed-state behavior.
|
|
101
|
+
|
|
102
|
+
Reports contain case IDs, booleans, and fixed failure codes only. The private marker and credential probes never appear in a report. Package smoke tests install core, Pi, and reference tarballs in a clean consumer and rerun reference conformance from compiled exports.
|
|
103
|
+
|
|
104
|
+
## Reference-adapter compatibility spike
|
|
105
|
+
|
|
106
|
+
M19 compared three reference targets:
|
|
107
|
+
|
|
108
|
+
| Candidate | Strength | M19 risk |
|
|
109
|
+
|---|---|---|
|
|
110
|
+
| another full agent SDK | realistic lifecycle | adds fast-moving SDK/version coupling and obscures which behavior belongs to DS4 versus the SDK |
|
|
111
|
+
| provider-client-only adapter | realistic completion | has no canonical branch, tool-group, or lifecycle contract to validate |
|
|
112
|
+
| callback runtime with append-only JSONL | exercises every adapter responsibility with no vendor SDK | intentionally minimal; not a production orchestration framework |
|
|
113
|
+
|
|
114
|
+
The callback JSONL target was selected because it covers the full contract while keeping the example inspectable and dependency-neutral. `ds4-context-reference-adapter` is therefore a non-Pi executable boundary example, not a claim of production support for a specific third-party agent framework.
|
|
115
|
+
|
|
116
|
+
Its `ds4-runtime-session-v1` file is canonical and append-only. The header binds runtime ID, session ID, and canonical project root. Message records contain DS4 canonical messages. `createReferenceHistory()` refuses overwrite, `appendReferenceHistoryMessage()` checks provenance before append, and `rebuildDerivedState()` discards only the in-memory snapshot. File size and message count are bounded. Files are mode `0600` where supported.
|
|
117
|
+
|
|
118
|
+
The reference adapter provides a callback completion transport, enabled fail-closed privacy by default, and optional `EmbeddingPort`. Native compaction and provider continuation remain explicitly unsupported. Local KV reuse is unsupported by default but becomes a versioned supported capability when the host injects a `LocalKvRuntimePort`; configuration remains disabled until explicitly enabled.
|
|
119
|
+
|
|
120
|
+
## Packaging rules
|
|
121
|
+
|
|
122
|
+
All release packages use the same version.
|
|
123
|
+
|
|
124
|
+
- `ds4-context-core` has no runtime SDK dependency.
|
|
125
|
+
- `ds4-context-engine` contains the Pi SDK boundary and depends exactly on matching core.
|
|
126
|
+
- `ds4-context-reference-adapter` contains no Pi SDK and depends exactly on matching core.
|
|
127
|
+
- Adapter source is not bundled into the core tarball; core source is not bundled into adapter tarballs.
|
|
128
|
+
- Core and reference TypeScript compile to ESM JavaScript and declarations before packing.
|
|
129
|
+
- Publish core first, then reference, then Pi.
|
|
130
|
+
|
|
131
|
+
Use:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm run check
|
|
135
|
+
npm run pack:check
|
|
136
|
+
npm pack --dry-run --workspace ds4-context-core
|
|
137
|
+
npm pack --dry-run --workspace ds4-context-reference-adapter
|
|
138
|
+
npm pack --dry-run
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Limitations and rollback
|
|
142
|
+
|
|
143
|
+
The reference adapter is intentionally synchronous-history/callback-completion infrastructure: it does not implement streaming, native compaction, branch editing, provider continuation, or a built-in provider-specific KV cache. Its optional KV path requires a host-owned port that retains handles and transport. Unsupported features remain disabled and visible rather than emulated.
|
|
144
|
+
|
|
145
|
+
Removing the reference package does not affect Pi or core. A runtime can roll back its adapter by stopping it and returning to native history/context behavior; no canonical migration or SQLite downgrade is required. Deleting adapter caches is safe and produces a transparent full replay. Never delete the runtime-owned JSONL file as part of DS4 rollback.
|
package/docs/STORAGE.md
CHANGED
|
@@ -8,7 +8,11 @@ Pi's session JSONL is canonical for conversations and live project files are can
|
|
|
8
8
|
/context rebuild-index
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
The extension never edits or rewrites Pi JSONL or project source files. Manual memory/pin commands append versioned Pi `CustomEntry` records through Pi's official `appendEntry()` API.
|
|
11
|
+
The extension never edits or rewrites Pi JSONL or project source files. Manual memory/pin commands and learned-ranking feedback append versioned classified Pi `CustomEntry` records through Pi's official `appendEntry()` API.
|
|
12
|
+
|
|
13
|
+
The M19 non-Pi reference adapter owns a separate `ds4-runtime-session-v1` JSONL source selected by its host runtime. Its header binds runtime/session identity and the exact canonical project root; following records contain provenance-checked canonical messages. DS4 snapshots and capability diagnostics are disposable. `createReferenceHistory()` refuses overwrite, append uses a dedicated provenance-checked operation, files are mode `0600` where supported, and rebuild never edits this runtime-owned canonical file. Reference JSONL is not imported into Pi or `context.db`.
|
|
14
|
+
|
|
15
|
+
M20 local KV state is entirely runtime-owned and volatile. Core returns only an in-memory eligibility fingerprint to the runtime port; it has no cache-handle field or serialization API. Prefixes, fingerprints, handles and provider outputs are absent from Pi/reference JSONL, Context Manifests, ranking artifacts and every SQLite table. Aggregate hit/miss/prefill counters live only on the adapter controller, and a restart safely resets them with the runtime cache. M20 adds no database migration.
|
|
12
16
|
|
|
13
17
|
## Session index
|
|
14
18
|
|
|
@@ -45,19 +49,33 @@ Malformed newline-terminated records are skipped consistently and counted. A val
|
|
|
45
49
|
|
|
46
50
|
## Project knowledge index
|
|
47
51
|
|
|
48
|
-
Schema v7 adds `project_states`, `project_files`, `project_snippets`, and `project_snippets_fts`. The state row records canonical root plus Git branch/HEAD/dirty paths. Current file rows store SHA-256, size, mtime, language, indexed Git HEAD, tracked/modified state
|
|
52
|
+
Schema v7 adds `project_states`, `project_files`, `project_snippets`, and `project_snippets_fts`. The state row records canonical root plus Git branch/HEAD/dirty paths. Current file rows store SHA-256, size, mtime, language, indexed Git HEAD, tracked/modified state and lifecycle. Snippet rows store the immutable file hash, line range, source text, estimate and stale bit.
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
Schema v12 extends snippet rows with text/symbol chunk kind, parser ID, stable symbol ID, simple and qualified names, kind, signature, parent, imports and references. The exact-name indexes and all parser output are disposable. Built-in TypeScript/JavaScript/Python/Go structural parsing has no native dependency; unsupported, invalid or declaration-free files retain bounded v7 text windows.
|
|
55
|
+
|
|
56
|
+
Changed hashes never overwrite old snippet rows silently: only the changed path's prior rows become stale and new hash-derived snippet/symbol IDs become current. Unrelated files preserve their rows and IDs. Deleted, renamed, oversized, binary, symlinked or newly sensitive files similarly invalidate prior snippets. Exact path/symbol and FTS queries join current files and require `stale = 0`; stale FTS rows may remain locally for derived-history diagnostics but cannot enter context.
|
|
51
57
|
|
|
52
58
|
Project source text is duplicated in SQLite only to provide local FTS and bounded snippet injection. Deleting the database loses no source truth. `/context rebuild-index` clears/rebuilds current projections from trusted live files. No project table is read or written while Pi reports the project untrusted.
|
|
53
59
|
|
|
60
|
+
## Derived embedding index
|
|
61
|
+
|
|
62
|
+
Schema v13 adds `derived_embeddings` for opt-in M16 historical/project vectors. The compound key contains source kind/scope/key/hash, chunking version, embedding provider/model and dimensions. Rows store only source grouping metadata, numeric vector JSON and indexing time; no query text, copied evidence text, provider response ID or remote handle is added.
|
|
63
|
+
|
|
64
|
+
Current source keys and hashes prune obsolete vectors without touching unrelated sources. Provider/model/dimension profiles coexist, so changing one profile does not rewrite another. Query vectors live only in a bounded volatile cache. The table is ignored when semantic retrieval is disabled and can always be recreated from Pi JSONL plus trusted live project files and the configured runtime embedding port.
|
|
65
|
+
|
|
66
|
+
Remote embedding text is privacy-filtered before the port is called. `local-only` values are omitted entirely and allowed values are secret-redacted. These rules govern transport; SQLite remains a local disposable projection.
|
|
67
|
+
|
|
54
68
|
## Memory and pin event projection
|
|
55
69
|
|
|
56
70
|
Schema v9 adds append-only `memory_mutations` and `pin_mutations`, each keyed to the canonical scoped `entries.entry_key` for its Pi custom entry. Mutation payloads describe immutable add, explicit supersede, or lifecycle status operations. `entry_order` preserves causal order when several Pi entries share one millisecond timestamp.
|
|
57
71
|
|
|
58
72
|
`memory_items`, `memory_sources`, `memory_fts`, and `pins` are materialized transactionally by replaying every known mutation. Materialized memory records retain normalized keys, origin session, source entries, optional privacy classification, active/superseded/invalid/expired status and immutable replacement links. Pins retain session/branch/project scope, creation leaf, optional classification, source entry/file and active/superseded/deleted lifecycle. Classification lives in canonical mutation JSON and derived `metadata_json`; M10 required no schema migration beyond v9.
|
|
59
73
|
|
|
60
|
-
Before replay, the current session's mutation rows are replaced from its complete Pi entry tree. Other indexed sessions remain available,
|
|
74
|
+
Before replay, the current session's mutation rows are replaced from its complete Pi entry tree. Other indexed sessions remain available, preserving the 0.1 project-scope behavior.
|
|
75
|
+
|
|
76
|
+
Schema v15 adds `project_memory_sessions`, `project_memory_source_exclusions`, and mutation creation-parent columns. When `memory.crossSession` is opted in, DS4 enumerates at most `memory.maxProjectSessions` sibling Pi JSONL files, validates each header against the exact trusted canonical project path, indexes only changed suffixes, and materializes their explicit mutations. Source rows retain header/checkpoint hashes, offsets, record/mutation counts, malformed-line counts, status and bounded error text. Exclusions are local derived policy; mutation content remains only in canonical JSONL and existing local projection tables.
|
|
77
|
+
|
|
78
|
+
A missing, moved, truncated, identity-mismatched or corrupt sibling source stops contributing unverifiable project-scoped mutations without discarding its isolated session-scoped projection. The active session retains its last transactional projection if an auxiliary cross-session refresh fails. Restored files rebuild deterministically. Deleting the database loses no canonical mutation; source discovery recreates the complete project projection without opening every source session. Unbacked legacy pre-v9 materialized rows are inspectable immediately after migration but are not treated as canonical during a later full replay.
|
|
61
79
|
|
|
62
80
|
Custom entries have empty lexical search text and never enter Pi context directly. The managed planner creates bounded, source-labelled synthetic pin/memory messages. Context Manifests store only metadata and hashes, never content/claims.
|
|
63
81
|
|
|
@@ -67,9 +85,21 @@ Schema v10 extends `context_manifests` and `token_calibration` with separate unc
|
|
|
67
85
|
|
|
68
86
|
Calibration rows are derived telemetry, isolated by exact provider/model and bounded to the latest configured window at read time. The runtime recomputes median/MAD outlier filtering deterministically; no learned model or mutable provider state is stored. Deleting the database loses calibration and cache history but never session content. Ephemeral sessions and configurations that disable manifest persistence keep only a bounded in-memory window.
|
|
69
87
|
|
|
88
|
+
## Context quality samples
|
|
89
|
+
|
|
90
|
+
Schema v11 adds bounded `context_quality_samples` for opt-in M14 measurement. Rows contain only metric/corpus/planner/profile versions, source-kind/token/budget/decision counts, normalized outcome labels and separate planning duration. Prompt text, evidence text, paths, memory claims, provider payloads, response IDs and raw source IDs are never stored. Invalid or corrupt rows are skipped during aggregation.
|
|
91
|
+
|
|
92
|
+
The table is a disposable replay projection. Deleting it loses no canonical state; replaying the versioned sanitized corpus recreates byte-stable non-timing aggregates. Runtime samples without expected-evidence labels remain explicitly unlabeled. See [`CONTEXT_QUALITY.md`](CONTEXT_QUALITY.md).
|
|
93
|
+
|
|
94
|
+
## Learned-ranking labels and model artifact
|
|
95
|
+
|
|
96
|
+
M18 adds no SQLite table. Classified `ds4-context-ranking-feedback-v1` Pi custom entries are canonical and contain only version/hash/label metadata plus ten bounded numeric features. Stable repository and candidate identities are SHA-256 hashes; raw prompt, evidence, claim, path and symbol text are absent. Sanitized replay labels use the same entry schema and explicitly identify their label source.
|
|
97
|
+
|
|
98
|
+
The trained `ds4-context/ranking-model.json` file is a disposable private artifact containing schema/algorithm versions, bounded weights, aggregate training counts, optional promotion-gate metrics and a stable-payload checksum. Deleting or corrupting it restores static ranking; canonical labels remain available for local retraining. Shadow comparison stores only aggregate disagreement in Context Manifests. No label, feature vector or candidate ID is copied into a manifest. See [`LEARNED_RANKING.md`](LEARNED_RANKING.md).
|
|
99
|
+
|
|
70
100
|
## Native continuation state
|
|
71
101
|
|
|
72
|
-
M12 adds no
|
|
102
|
+
M12 adds no continuation table. It was introduced at schema v10; M14 adds quality samples in v11, M15 adds project-symbol columns/indexes in v12, and M16 adds only disposable vectors in v13. The active process keeps only deterministic SHA-256 hashes of the previous full request items and serialized response items, a hash of non-input request options, completion time, and the minimum provider response handle needed for `previous_response_id`.
|
|
73
103
|
|
|
74
104
|
The volatile state is cleared on lifecycle/model/branch/compaction boundaries and is not reconstructed on resume. The first request after a cold start is therefore always the complete managed replay. Pi may persist its normal `AssistantMessage.responseId` in canonical JSONL, but DS4 does not create a custom entry, copy that ID into SQLite/manifest/logs, or depend on it for recovery.
|
|
75
105
|
|
|
@@ -83,7 +113,7 @@ A full index rebuild replays all message entries, recreates missing qualifying o
|
|
|
83
113
|
|
|
84
114
|
## Context manifests
|
|
85
115
|
|
|
86
|
-
For persisted sessions, each `context` hook stores a metadata-only manifest containing token counts, session/project/pin/memory source and atomic-group IDs, inclusion/exclusion reasons, classifications and scores, original/selected counts, exact-model override/calibration/adaptive budgets, model-switch/cache disposition, provider destination/allow names, privacy counters, optional continuation mode/item counts/retry reasons, project revision/hash/line references, tool names, a SHA-256 prompt hash, and planner/policy versions. Prompt text, message text, pin content, memory claims, project snippet text, tool arguments, image data, rendered provider payloads, and provider response/conversation IDs are not stored in the manifest.
|
|
116
|
+
For persisted sessions, each `context` hook stores a metadata-only manifest containing token counts, session/project/pin/memory source and atomic-group IDs, inclusion/exclusion reasons, classifications and scores, original/selected counts, exact-model override/calibration/adaptive budgets, aggregate learned-ranking status/disagreement, model-switch/cache disposition, provider destination/allow names, privacy counters, optional continuation mode/item counts/retry reasons, project revision/hash/line references, tool names, a SHA-256 prompt hash, and planner/policy versions. Prompt text, message text, pin content, memory claims, project snippet text, tool arguments, image data, rendered provider payloads, and provider response/conversation IDs are not stored in the manifest.
|
|
87
117
|
|
|
88
118
|
`before_provider_request` updates the pending manifest with final-check/redaction counters but never the provider payload. The following finalized assistant response updates it with uncached input, cache-read, cache-write and total provider input usage, then adds at most one exact-model calibration sample. Ephemeral sessions retain this information only in memory.
|
|
89
119
|
|
|
@@ -99,4 +129,4 @@ Schema-v2 `CompactionEntry.details.ds4ContextEngine` records the active/segment
|
|
|
99
129
|
|
|
100
130
|
A full rebuild does not blindly delete unchanged entries. It upserts all observed entries, marks them in a temporary seen-set, and removes only stale rows. This preserves foreign-key provenance for unchanged source entries. FTS rows and checkpoint state update in the same transaction.
|
|
101
131
|
|
|
102
|
-
Session reconciliation is transactional. Memory/pin mutation replacement and full materialization
|
|
132
|
+
Session reconciliation is transactional. Memory/pin mutation replacement, checkpoint update, source exclusion and full materialization each occur under the shared write coordinator. Each quality upsert and bounded-retention prune share one transaction; quality failures do not affect manifests or planning. Each changed project file is also replaced transactionally with its snippets and FTS rows; embedding upserts and canonical-source pruning are transactional; artifact object/reference metadata and project deletion batches are atomic. A filesystem artifact write precedes its metadata transaction, so an interrupted metadata write may leave only an unreferenced content-addressed cache file; canonical JSONL remains sufficient for recovery. If parsing, validation, or SQLite writing fails, the prior derived state remains available. Artifact/project failures contribute no replacement/snippets; planner failures discard all synthetic evidence; Pi continues with its native context.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ds4-context-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.2",
|
|
4
4
|
"description": "Non-destructive, provider-independent context management for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"src",
|
|
31
31
|
"docs",
|
|
32
|
+
"quality",
|
|
33
|
+
"scripts/compare-context-quality.mjs",
|
|
32
34
|
"README.md",
|
|
33
35
|
"LICENSE"
|
|
34
36
|
],
|
|
@@ -37,12 +39,15 @@
|
|
|
37
39
|
},
|
|
38
40
|
"scripts": {
|
|
39
41
|
"build:core": "npm run build --workspace ds4-context-core",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
42
|
+
"build:reference-adapter": "npm run build --workspace ds4-context-reference-adapter",
|
|
43
|
+
"build:adapters": "npm run build:reference-adapter",
|
|
44
|
+
"typecheck": "npm run build:core && npm run build:adapters && tsc --noEmit",
|
|
45
|
+
"test": "npm run build:core && npm run build:adapters && vitest run",
|
|
46
|
+
"test:watch": "npm run build:core && npm run build:adapters && vitest",
|
|
47
|
+
"check": "npm run build:core && npm run build:adapters && tsc --noEmit && vitest run",
|
|
48
|
+
"quality:compare": "node scripts/compare-context-quality.mjs",
|
|
44
49
|
"pack:check": "node scripts/verify-packages.mjs",
|
|
45
|
-
"prepare": "npm run build:core"
|
|
50
|
+
"prepare": "npm run build:core && npm run build:adapters"
|
|
46
51
|
},
|
|
47
52
|
"pi": {
|
|
48
53
|
"extensions": [
|
|
@@ -50,7 +55,7 @@
|
|
|
50
55
|
]
|
|
51
56
|
},
|
|
52
57
|
"dependencies": {
|
|
53
|
-
"ds4-context-core": "0.
|
|
58
|
+
"ds4-context-core": "0.2.0-beta.2"
|
|
54
59
|
},
|
|
55
60
|
"peerDependencies": {
|
|
56
61
|
"@earendil-works/pi-ai": "0.84.3",
|