prime-agent-dsh 0.2.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,50 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project intends to follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) once its public API stabilizes.
6
+
7
+ ## Unreleased
8
+
9
+ ### Documentation
10
+
11
+ - Added production-oriented installation, support, contribution, conduct, roadmap, and release documentation.
12
+
13
+ ## 0.2.0 - 2026-09-21
14
+
15
+ ### Added
16
+
17
+ - Per-root and per-native-RLM-child context scopes.
18
+ - Immutable branch snapshots, bounded transcript reads and search, private artifacts, and explicit durable admission through the `dsh-context` Python skill.
19
+ - Automatic bounded parent-to-child evidence capsules and explicit expiring context grants.
20
+ - Provider-reported turn and session cache metrics in a native Prime widget.
21
+ - Incremental append-only Prime JSONL reference indexing with verified rebuild and recovery paths.
22
+ - Optional diagnostic-only shadow telemetry.
23
+
24
+ ### Changed
25
+
26
+ - Reworked the integration as a fail-open context sidecar around Prime's native `AgentSession`.
27
+ - Made Prime JSONL the sole canonical full-content history and Prime the sole model, tool, session, branching, deletion, and compaction authority.
28
+ - Reduced user commands to `/dsh`, `/dsh on`, and `/dsh off`; these control display only.
29
+ - Pinned DeepSeek Harness dependencies to `0.1.6-alpha.2` and set the runtime target to Prime Agent 0.9.5 or newer.
30
+
31
+ ### Removed
32
+
33
+ - DSH-driven compaction and warm-prefix compaction behavior.
34
+ - Alternate DSH agent loops, provider wrappers, ACP delegation, and independent conversation authority from the supported design.
35
+
36
+ ### Security
37
+
38
+ - Added bounded stores, verified locators and digests, restrictive file modes, quota/free-space checks, grant expiry, and fail-open handling.
39
+ - Clarified that same-OS-user processes remain outside the filesystem threat boundary.
40
+
41
+ ## 0.1.0 - 2026-09-01
42
+
43
+ ### Added
44
+
45
+ - Initial experimental Prime Agent and DeepSeek Harness integration.
46
+
47
+ ### Notes
48
+
49
+ - The 0.1.x line explored routing, shadow context, persistence, and compaction approaches. Those experiments are not the authority model supported by 0.2.0.
50
+ - No npm release is asserted for this version; repository history is the source of record.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 prime-agent-dsh contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # prime-agent-dsh
2
+
3
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4
+ [![Node.js](https://img.shields.io/badge/node-%5E22.19.0%20%7C%7C%20%3E%3D24-339933.svg)](package.json)
5
+ [![Status: developer preview](https://img.shields.io/badge/status-developer%20preview-orange.svg)](#project-status)
6
+
7
+ A context sidecar for Prime Agent. It turns the active Prime branch into a searchable, rebuildable DeepSeek Harness (DSH) projection, exposes bounded context tools in Python, and reports provider cache use. Prime remains the only agent loop and the only session authority.
8
+
9
+ > **Not published to npm.** Install from this GitHub repository or a local checkout. The pinned DeepSeek Harness `0.1.6-alpha.2` dependencies are also developer previews.
10
+
11
+ ## Why use it?
12
+
13
+ - Search and inspect a long Prime session without placing the whole transcript in the next request.
14
+ - Pin immutable views, create private artifacts, and explicitly admit selected evidence.
15
+ - Give native RLM descendants bounded inherited evidence or an explicit expiring grant.
16
+ - See provider-reported turn and session cache rates in a native Prime widget.
17
+ - Keep failures non-blocking: projection errors leave the Prime request unchanged.
18
+
19
+ ## Quick start
20
+
21
+ Requirements, source installation, verification, upgrades, removal, and troubleshooting are in **[Getting started](docs/getting-started.md)**.
22
+
23
+ ```bash
24
+ git clone https://github.com/moreWax/prime-agent-dsh.git
25
+ cd prime-agent-dsh
26
+ npm install
27
+ npm run release:check
28
+ prime-agent package install "$PWD"
29
+ ```
30
+
31
+ Restart Prime Agent after installation. Then run `/dsh` and try `dsh_context.current()` in IPython.
32
+
33
+ ## Architecture invariants
34
+
35
+ 1. **Prime owns inference.** Prime selects models, streams responses, authenticates, retries, and controls approvals.
36
+ 2. **Prime owns execution.** Tools, IPython, skills, MCP, native `rlm.spawn`, and goals stay in Prime's loop.
37
+ 3. **Prime owns content and lifecycle.** Prime JSONL is the only full-content session authority. Prime alone branches, compacts, and deletes sessions.
38
+ 4. **DSH is derived and fail-open.** Its per-session projection and indexes are bounded, content-addressed, and rebuildable. DSH does not compact Prime context.
39
+ 5. **Scopes stay isolated.** Each root and native RLM child gets its own scope. Sharing uses a bounded capsule or explicit grant, never a live transcript or parent authority.
40
+ 6. **Admission is explicit.** Reading DSH data does not silently add it to model context. Printed or returned `ctx.inject(...)` output becomes a normal Prime tool result.
41
+
42
+ The package does not ship a DSH `AgentLoop`, provider wrapper, ACP delegation path, custom model loop, or independent conversation store. See [Single-window cache architecture](docs/single-window-cache-architecture.md).
43
+
44
+ ## Feature status
45
+
46
+ | Capability | Status | Notes |
47
+ |---|---|---|
48
+ | Active-branch projection | Available | Append/no-op/rebuild tracking; Prime JSONL stays canonical. |
49
+ | Transcript reads and search | Available | Bounded Python API over immutable session snapshots. |
50
+ | Snapshots and private artifacts | Available | Content-addressed and stored in the matching session artifacts. |
51
+ | Explicit context admission | Available | Use `ctx.inject(...)`; Prime records the resulting tool output. |
52
+ | Native RLM inheritance | Available | Bounded untrusted evidence through Prime 0.9.5 lifecycle hooks. |
53
+ | Explicit parent-to-child grants | Available | Bounded, read-only, expiring capabilities. |
54
+ | Provider cache metrics | Available when reported | No cache hit is inferred if the provider omits usage fields. |
55
+ | `/dsh` display toggle | Available | Changes widget visibility only; indexing continues. |
56
+ | Shadow telemetry | Optional | Diagnostic only; never changes provider context. |
57
+ | DSH-driven compaction | Not included | Prime alone decides and performs compaction. |
58
+ | DSH agent loop or tools | Not included | Would create a second execution authority. |
59
+ | npm installation | Not available | Source installation only for this release. |
60
+
61
+ ## Python API at a glance
62
+
63
+ ```python
64
+ ctx = dsh_context.current()
65
+ ctx.entries(last=10)
66
+ ctx.messages(last=10)
67
+ ctx.search("authentication", limit=20)
68
+ ctx.metrics
69
+
70
+ snapshot = ctx.snapshot()
71
+ selection = ctx.search("migration decision", limit=8)
72
+ artifact = ctx.artifact(selection, label="Migration evidence")
73
+ print(ctx.inject(selection, label="Relevant migration decisions"))
74
+ ```
75
+
76
+ For grants and API rules, see [Getting started](docs/getting-started.md#use-the-python-context-skill) and the [`dsh-context` skill reference](skills/dsh-context/SKILL.md).
77
+
78
+ ## Configuration
79
+
80
+ | Variable | Default | Purpose |
81
+ |---|---:|---|
82
+ | `PRIME_DSH_CACHE_DISPLAY` | `on` | Initial cache-rate widget visibility. Set `off` to hide it. |
83
+ | `PRIME_DSH_SHADOW_MODE` | `off` | Enable a second diagnostic-only round-trip mirror. |
84
+ | `PRIME_DSH_SHADOW_MAX_MESSAGES` | `500` | Bound shadow work by message count. |
85
+ | `PRIME_DSH_SHADOW_MAX_BYTES` | `4194304` | Bound shadow work by serialized bytes. |
86
+
87
+ ## Documentation
88
+
89
+ - [Getting started](docs/getting-started.md)
90
+ - [Single-window cache architecture](docs/single-window-cache-architecture.md)
91
+ - [Durable context query](docs/durable-context-query.md)
92
+ - [Context spill](docs/context-spill.md)
93
+ - [Shadow telemetry validation](docs/shadow-telemetry-validation.md)
94
+ - [Contributing](CONTRIBUTING.md)
95
+ - [Support](SUPPORT.md)
96
+ - [Roadmap](ROADMAP.md)
97
+ - [Changelog](CHANGELOG.md)
98
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
99
+
100
+ ## Project status
101
+
102
+ `0.2.0` is a developer preview. The Prime integration, storage formats, and Python API may change before a stable release. The test suite covers the documented core paths, but this package is not a security boundary against another process running as the same OS user.
103
+
104
+ The current runtime target is Prime Agent `0.9.5` or newer (`@earendil-works/pi-coding-agent >=0.86.1`). See the [roadmap](ROADMAP.md) for direction rather than release promises.
105
+
106
+ ## Development and validation
107
+
108
+ ```bash
109
+ npm run typecheck
110
+ npm run lint
111
+ npm test
112
+ npm run test:python
113
+ npm run package:smoke
114
+ npm run release:check
115
+ ```
116
+
117
+ See [CONTRIBUTING.md](CONTRIBUTING.md) before proposing a change. Preserve the Prime-only authority model.
118
+
119
+ ## License
120
+
121
+ [MIT](LICENSE). Bundled dependency notices are in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
package/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes are released on the current minor line. Upgrade to the newest patch before reporting a problem.
6
+
7
+ | Version | Supported |
8
+ | --- | --- |
9
+ | 0.2.x | Yes |
10
+ | 0.1.x and earlier | No |
11
+
12
+ Support for a release also requires a Node.js version allowed by that release's `engines` field and supported Prime peer dependencies.
13
+
14
+ ## Report a vulnerability
15
+
16
+ Please report vulnerabilities privately with [GitHub Security Advisories](https://github.com/moreWax/prime-agent-dsh/security/advisories/new). Do not open a public issue, discussion, or pull request for an unpatched vulnerability. Include the affected version, platform, impact, reproduction steps or a minimal proof of concept, and any suggested mitigation. Remove real credentials and private transcripts.
17
+
18
+ We aim to acknowledge a report within five business days and provide a status update within ten business days. These are targets, not guarantees or an SLA. Timing depends on severity, reproducibility, maintainer availability, and coordinated disclosure needs. We will work with the reporter on disclosure after a fix or practical mitigation is available.
19
+
20
+ ## Security model
21
+
22
+ Read the full [security and operations guide](docs/security.md) before deploying the package. Important limits are:
23
+
24
+ - Prime's session JSONL is the sole authority for transcript content. DSH indexes and projections are derived and rebuildable.
25
+ - DSH protects against accidental traversal, symlink substitution, corruption, and cross-session reuse. It is not a sandbox against another process running as the same OS user.
26
+ - Session artifacts contain sensitive metadata and can contain selected context, exact task prompts, user-created artifacts, grants, and attachments. Treat the whole session tree as confidential.
27
+ - DSH does not replace Prime's provider, retention, deletion, authentication, backup, or secret-management controls.
@@ -0,0 +1,3 @@
1
+ # Third-party notices
2
+
3
+ This package uses DeepSeek Harness context, session, and attachment components and Prime Agent packages under their respective licenses. See the installed dependency packages for their license texts and notices.
@@ -0,0 +1,7 @@
1
+ # Durable context spill and generic attachments
2
+
3
+ `src/durable-file-attachments.ts` uses the verbatim file primitives added in `@deepseek-ai/dsh-attachment` and `@deepseek-ai/dsh-attachment-local` **0.1.6** (this package currently pins `0.1.6-alpha.2`). It needs those versions or a later compatible release. Files are provider-neutral, content-addressed, atomically published with private modes, and verified during every read.
4
+
5
+ `spillContextText()` stores an oversized UTF-8 value and returns a bounded preview plus a serializable locator. If storage or quota enforcement fails it returns the exact value inline. Keep locators in durable session data. A later process can reconstruct `DurableFileAttachments` with the same absolute `dshHome` and call `resolveContextSpill()`.
6
+
7
+ Set `maxObjectBytes`, `maxTotalBytes`, and `maxObjects` at construction. Call `cleanup(liveReferences)` only with a complete set of live generic-file references. Cleanup does not touch images.
@@ -0,0 +1,34 @@
1
+ # Durable context query adapter
2
+
3
+ `src/durable-context-query.ts` is a read-only query layer for
4
+ `DurableContextStore` commits. Prime's JSONL is the only full-content authority. The
5
+ publication store and every search view are derived and can be deleted and
6
+ rebuilt from Prime through the publisher.
7
+
8
+ The adapter intentionally has no new runtime dependency. Version
9
+ `0.1.6-alpha.2` of `@deepseek-ai/dsh-session-query` queries DSH Session event
10
+ logs through a Cordis service, while these records are Prime-derived context
11
+ checkpoints with content-addressed commit provenance. Its SQLite provider has
12
+ the same Session-event schema and therefore is not a safe direct index for this
13
+ format. If a future persistent FTS index is added, it should be an optional
14
+ cache keyed by `bindingDigest`, `commitDigest`, `objectDigest`, entry digest,
15
+ and extractor version. It must never become query or recovery authority.
16
+
17
+ ## Guarantees
18
+
19
+ - The constructor verifies `BINDING` against both the session ID and canonical
20
+ Prime file path. A store cannot be opened through another session binding.
21
+ - Every head, commit, object, locator, source-entry digest, and source aggregate
22
+ digest is checked before use. Effective hashes are provenance metadata; an
23
+ effective entry is returned only when it can be reconstructed losslessly.
24
+ A bad checkpoint is skipped and counted.
25
+ - Literal matching is case-insensitive and whitespace-flexible. Regex patterns
26
+ and flags are bounded. Full-text ranking uses deterministic BM25-style scores
27
+ and stable tie breaks.
28
+ - Cursors bind the complete query and a maximum generation. Later publications
29
+ do not change pages already in progress. Cursors remain usable after process
30
+ restart because their authority is immutable commits, not process memory.
31
+ - Checkpoint count, query bytes, scanned entries, page size, and cursor bytes
32
+ have explicit bounds.
33
+ - V3 source hits are dereferenced from the bound Prime JSONL and verify locator, ID, and digest. Effective hits are reconstructed only when a source mapping exists; `trace.exactBody` says whether reconstruction is byte-semantically exact.
34
+ - V3-reference is the sole supported derived-store format. Old cache schemas are discarded and rebuilt from Prime JSONL, not migrated or maintained.
@@ -0,0 +1,253 @@
1
+ # Getting started
2
+
3
+ This guide installs `prime-agent-dsh` from source. Version 0.2.0 is **not published to npm**.
4
+
5
+ ## Requirements
6
+
7
+ - Prime Agent `0.9.5` or newer.
8
+ - Node.js `^22.19.0` or `>=24.0.0`.
9
+ - npm and Git.
10
+ - A Prime provider that reports cache usage if you want cache-rate values. The context features do not require those metrics.
11
+ - Write access to the Prime configuration and session-artifact locations used by your installation.
12
+
13
+ Check the tools that are on your path:
14
+
15
+ ```bash
16
+ prime-agent --version
17
+ node --version
18
+ npm --version
19
+ git --version
20
+ ```
21
+
22
+ The package declares `@earendil-works/pi-coding-agent >=0.86.1` and related Prime packages as peer dependencies. `npm install` installs the pinned DSH runtime dependencies and development tools.
23
+
24
+ ## Install from GitHub
25
+
26
+ Clone the repository, validate the exact checkout, and register that checkout with Prime:
27
+
28
+ ```bash
29
+ git clone https://github.com/moreWax/prime-agent-dsh.git
30
+ cd prime-agent-dsh
31
+ npm install
32
+ npm run release:check
33
+ prime-agent package install "$PWD"
34
+ ```
35
+
36
+ Use a tagged release or reviewed commit when one is available. The default branch can contain unreleased work. Do not use `npm install -g prime-agent-dsh` or `npm install prime-agent-dsh`; no npm package is published for this release.
37
+
38
+ ## Install for one project
39
+
40
+ If you already have a trusted checkout and want activation only in the current project, run this **from the project that should use the package**:
41
+
42
+ ```bash
43
+ prime-agent package install --local /absolute/path/to/prime-agent-dsh
44
+ ```
45
+
46
+ Without `--local`, Prime registers the package in the user configuration. With `--local`, Prime registers it in the current project's configuration. The source checkout still needs its dependencies:
47
+
48
+ ```bash
49
+ cd /absolute/path/to/prime-agent-dsh
50
+ npm install
51
+ npm run release:check
52
+ ```
53
+
54
+ For extension development without registration, Prime also supports:
55
+
56
+ ```bash
57
+ cd /absolute/path/to/prime-agent-dsh
58
+ prime-agent -e ./extensions/index.ts
59
+ ```
60
+
61
+ Use that command only for a development run. Do not also activate the installed copy in the same run.
62
+
63
+ ## Restart and verify
64
+
65
+ Package registration does not change an already running Prime process. Exit all Prime Agent processes that should load the package, then start Prime again. A new process loads the extension and installs the `dsh-context` skill into its Python kernel.
66
+
67
+ First verify package registration:
68
+
69
+ ```bash
70
+ prime-agent package list
71
+ ```
72
+
73
+ Confirm that the output includes the source you installed. In the restarted Prime session:
74
+
75
+ 1. Run `/dsh`. Prime should report the resulting display and indexing state.
76
+ 2. Open IPython and evaluate:
77
+
78
+ ```python
79
+ ctx = dsh_context.current()
80
+ ctx
81
+ ctx.entries(last=3)
82
+ ctx.metrics
83
+ ```
84
+
85
+ 3. Continue the conversation for at least one completed assistant request. `ctx.entries(...)` should reflect the active Prime branch.
86
+
87
+ Cache rates can remain `—` when the provider does not report enough usage data. That does not mean projection failed. If the session has no publishable history yet, make a normal turn and retry.
88
+
89
+ ## Control the cache display
90
+
91
+ ```text
92
+ /dsh
93
+ /dsh on
94
+ /dsh off
95
+ ```
96
+
97
+ - `/dsh` toggles the native cache-rate text and reports the resulting state.
98
+ - `/dsh on` shows it.
99
+ - `/dsh off` hides it.
100
+
101
+ The command controls display only. Projection, indexing, and provider cache measurement continue while the display is hidden. A typical provider-reported value is:
102
+
103
+ ```text
104
+ DSH cache · turn 99.7% · session 97.1%
105
+ ```
106
+
107
+ `turn` covers the latest completed assistant request. `session` aggregates the canonical active Prime branch. Both use `cacheRead / (input + cacheRead)`. Prime controls where its native widget appears.
108
+
109
+ Set `PRIME_DSH_CACHE_DISPLAY=off` before starting Prime to make hidden the initial state.
110
+
111
+ ## Use the Python context skill
112
+
113
+ Inspect bounded values without changing model context:
114
+
115
+ ```python
116
+ ctx = dsh_context.current()
117
+ ctx.entries(last=10)
118
+ ctx.messages(last=10)
119
+ ctx.search("authentication", limit=20)
120
+ ctx.metrics
121
+ ```
122
+
123
+ Pin the current immutable view and save selected material as a private artifact:
124
+
125
+ ```python
126
+ snapshot = ctx.snapshot()
127
+ selection = ctx.search("migration decision", limit=8)
128
+ artifact = ctx.artifact(selection, label="Migration evidence")
129
+ ```
130
+
131
+ Reading or searching does not silently add data to the next model request. Explicitly admit a bounded selection by printing or returning it from the IPython cell:
132
+
133
+ ```python
134
+ print(ctx.inject(selection, label="Relevant migration decisions"))
135
+ ```
136
+
137
+ Prime records that output in its canonical JSONL before a later request can use it. `ctx.admit(...)` is an alias.
138
+
139
+ To share a larger selected value with a native RLM child:
140
+
141
+ ```python
142
+ selection = ctx.search("authentication design", limit=12)
143
+ grant = ctx.grant(selection, label="Authentication evidence")
144
+ child = await rlm.spawn(
145
+ "Review the design. " + grant.instruction,
146
+ name="auth-review",
147
+ )
148
+ ```
149
+
150
+ The child follows the instruction or opens the URI directly:
151
+
152
+ ```python
153
+ evidence = dsh_context.open_grant("dsh-context-grant:...")
154
+ evidence.value
155
+ ```
156
+
157
+ Grants are bounded, read-only, and expiring. They share selected evidence, not the parent's tools or live session. Native children also receive a small automatic evidence capsule through Prime lifecycle hooks.
158
+
159
+ ## Update
160
+
161
+ Updates are source updates, not npm upgrades. Stop Prime, then update the same checkout and validate it:
162
+
163
+ ```bash
164
+ cd /absolute/path/to/prime-agent-dsh
165
+ git fetch --all --tags
166
+ git checkout <reviewed-tag-or-commit>
167
+ npm install
168
+ npm run release:check
169
+ prime-agent package install "$PWD"
170
+ ```
171
+
172
+ If the package was registered locally, run the last command from the target project with `--local` and the absolute checkout path. Restart Prime afterward. `prime-agent package update [source]` exists for package sources that Prime can update, but a manual checkout update makes the reviewed revision explicit.
173
+
174
+ No manual data migration is required for 0.2.0. On first publication, it removes legacy rebuildable snapshot layouts and prunes old derived generations under the writer lock. It does not change Prime JSONL, user artifacts, grants, or inheritance data.
175
+
176
+ ## Uninstall
177
+
178
+ First identify the registered source:
179
+
180
+ ```bash
181
+ prime-agent package list
182
+ ```
183
+
184
+ Remove the same source value used at installation:
185
+
186
+ ```bash
187
+ prime-agent package remove <source>
188
+ ```
189
+
190
+ For a project-local registration, run from that project and include `--local`:
191
+
192
+ ```bash
193
+ prime-agent package remove --local <source>
194
+ ```
195
+
196
+ Restart Prime. Removal stops future extension loading. It does not delete source checkouts or existing Prime sessions and artifacts. Remove a checkout separately only after unregistering it.
197
+
198
+ ## Delete a session
199
+
200
+ DSH adds no deletion command. Use Prime's native **Agents** view:
201
+
202
+ 1. Select the session.
203
+ 2. Press `Ctrl+X` twice to confirm.
204
+
205
+ Prime deletes the matching session artifact directory. Do not manually remove individual DSH files from a live session. Prime alone owns session deletion and compaction.
206
+
207
+ ## Troubleshooting
208
+
209
+ ### The command or Python module is missing
210
+
211
+ - Run `prime-agent package list` and confirm the expected source is registered.
212
+ - Restart every Prime process after install or update.
213
+ - Run `npm install` in the checkout.
214
+ - Do not load both the installed package and `-e ./extensions/index.ts`.
215
+ - Confirm Prime and Node meet the versions above.
216
+
217
+ ### Cache rates show `—`
218
+
219
+ The provider did not report enough cache usage data for that request or branch. This is expected for some providers. It does not disable indexing or context objects.
220
+
221
+ ### Entries look stale
222
+
223
+ Make a normal Prime turn, then call `dsh_context.current()` again. Handles point to immutable snapshots, so create a new handle to observe a newer publication. If publication stopped because of its storage safety limits, free disk space and restart Prime to re-arm it.
224
+
225
+ ### Validation fails
226
+
227
+ Run individual checks to locate the failing layer:
228
+
229
+ ```bash
230
+ npm run typecheck
231
+ npm run lint
232
+ npm test
233
+ npm run test:python
234
+ npm run package:smoke
235
+ ```
236
+
237
+ Keep the complete command and output when requesting support. Do not include secrets or an unredacted session log.
238
+
239
+ ### Prime still works but DSH data is unavailable
240
+
241
+ This is the intended fail-open behavior. Projection errors leave Prime's request unchanged. Review the Prime process output, available disk space, checkout dependencies, and file permissions. The derived store stops publishing before it would exceed its 64 MiB quota or the 128 MiB free-space reserve; restart after correcting the condition.
242
+
243
+ ## Privacy and data handling
244
+
245
+ - Prime JSONL is the only full-content history. DSH reads the active branch and creates derived, rebuildable indexes and immutable objects under the matching Prime session artifact directory.
246
+ - New index roots store locators, IDs, offsets, lengths, and digests rather than a second full message-body store.
247
+ - User-created artifacts and grants can contain the selected content you give them. They are not removed by derived-generation pruning.
248
+ - Automatic child capsules can contain bounded user, assistant, and summary evidence. They exclude system/developer text, tool inputs/results, credentials, provider state, and synthetic inherited messages.
249
+ - Shadow telemetry is off by default. When enabled, it performs a second diagnostic-only round trip and therefore can send bounded mirrored context to the configured provider. Review [shadow telemetry validation](shadow-telemetry-validation.md) before enabling it.
250
+ - Directories use mode `0700`; files use `0600`. These permissions are not a hostile same-user sandbox. Another process running as your OS user can generally access or replace your files.
251
+ - Context sent in normal requests, explicit admissions, and shadow diagnostics remains subject to your Prime provider's data handling terms.
252
+
253
+ Before sharing logs or artifacts, inspect and redact them. Use separate OS identities or a sandbox for mutually hostile agents.
@@ -0,0 +1,78 @@
1
+ # Security and operations guide
2
+
3
+ This guide describes the security boundary of `prime-agent-dsh` 0.2.x. It supplements, but does not replace, the controls of Prime Agent, the operating system, the selected model provider, and your backup system.
4
+
5
+ ## Trust boundaries
6
+
7
+ Prime owns the agent loop, tool execution, provider request, canonical session JSONL, compaction, and session lifecycle. DSH observes committed Prime history and creates local, derived state. **The Prime JSONL is the sole content authority.** A DSH manifest, `CURRENT` file, index, object, commit, or shadow trace must never be treated as a replacement transcript. Reference projections are rebuilt and checked against the canonical JSONL.
8
+
9
+ The installation assumes that Prime, this package, its configured dependencies, and native parent/child sessions are cooperative. DSH rejects unsafe paths and corrupt objects, but it is not a hostile multi-tenant boundary. A process with the same OS user ID can generally read or modify session files, inspect process memory, race checks, or debug the Prime process. File modes do not stop that process. Run mutually hostile agents under separate OS identities, containers, or stronger sandboxes, and isolate their session and attachment roots.
10
+
11
+ DSH is not an authorization layer for Prime tools. A tool that can read a file or environment variable can still place its value in the canonical transcript or send it through Prime's normal model request.
12
+
13
+ ## Data inventory and metadata
14
+
15
+ The normal derived context store contains content-free references into Prime JSONL, content digests, offsets, lengths, line and entry identifiers, branch/session identifiers, absolute canonical file paths, timestamps, token counts, roles, and publication diagnostics. It does not copy message bodies into derived objects or the incremental index. Queries resolve references by reading and validating Prime JSONL.
16
+
17
+ This metadata is still sensitive. Paths and identifiers reveal host layout and activity. Sizes, timings, roles, token counts, and equality or prefix relationships can reveal usage patterns. SHA-256 digests can confirm guesses about low-entropy content. Do not publish manifests, indexes, fingerprints, traces, or error logs merely because they omit message bodies.
18
+
19
+ Other DSH state can contain content:
20
+
21
+ - `dsh-inheritance/` generations contain bounded, selected parent text after best-effort secret redaction, generated capsules, and the child's **exact task prompt**. Task prompts are not redacted.
22
+ - `dsh-context/artifacts/` contains exact values explicitly saved by the user.
23
+ - `dsh-context/grants/` contains exact bounded values and capability tokens created for descendants.
24
+ - local attachment storage can contain verbatim files or images admitted by the attachment backend.
25
+ - Prime JSONL remains a complete source of any sensitive content committed by Prime.
26
+
27
+ Treat the full Prime session tree, DSH artifact tree, attachment store, diagnostic output, and backups as confidential.
28
+
29
+ ## Local files and integrity controls
30
+
31
+ On POSIX systems DSH creates or tightens its managed directories to mode `0700` and creates managed files with mode `0600`. Host ACLs, mount options, backup agents, copied/restored files, and the permissions of ancestor directories remain operator responsibilities. Check them after migration or restore. Do not place session state on a shared or untrusted filesystem.
32
+
33
+ The durable store binds a session ID to the canonical real path of its Prime JSONL. It rejects store-root symlinks and symlinks within managed paths, rejects traversal outside the bound root, validates file type and size, uses exclusive temporary files and atomic rename, and fsyncs publication boundaries where the platform supports it. Content-addressed commits and objects, heads, source locators, attachment references, and inheritance artifacts are checked with digests and session bindings before use. `CURRENT` and compatibility manifests are hints, not recovery authority. Corrupt, stale, mismatched, or incomplete generations are rejected or ignored.
34
+
35
+ These controls reduce accidental substitution and corruption. They do not eliminate time-of-check/time-of-use races by a same-UID attacker, protect a compromised Prime process, or provide authenticity against an attacker who can rewrite all bound state. SHA-256 here is an integrity and content-addressing mechanism, not encryption or a secret MAC.
36
+
37
+ ## Provider and telemetry boundary
38
+
39
+ Prime sends the active request to the selected remote model provider under Prime's configuration and that provider's policy. DSH does not add a provider or make an additional model request. `PRIME_DSH_SHADOW_MODE=on` performs a bounded local conversion round trip and passively observes the provider payload that Prime is already preparing; it does not transmit that mirror itself.
40
+
41
+ Shadow telemetry is process-local and retains counters, byte lengths, timestamps, truncated display fingerprints, and full SHA-256 fingerprints/chunk fingerprints needed for prefix comparison. It temporarily serializes observed content in memory but does not retain provider request bodies or credentials as plaintext telemetry. Credential-shaped object keys are replaced before fingerprinting. This redaction is defense in depth, not a complete secret detector: secrets in ordinary message strings still influence one-way fingerprints. Process exit clears process-local shadow traces; shadow mode is off by default. Provider-reported cache token counts are copied into local manifests and status data; DSH cannot verify provider accounting.
42
+
43
+ Review Prime and provider logging, training, residency, retention, and incident policies separately. Disabling DSH telemetry does not stop Prime's normal provider request.
44
+
45
+ ## Retention, deletion, and backup
46
+
47
+ The derived publication store normally retains the two newest complete generations. Its quota and pruning apply to rebuildable commits, objects, heads, indexes, and compatibility manifests. They do **not** collect user `artifacts/`, `grants/`, inheritance generations, Prime JSONL, or all attachment objects. Grant expiry prevents a grant from being opened through the API; it does not erase the grant file. An artifact has no automatic expiry.
48
+
49
+ Use Prime's native Agents view to delete a session (`Ctrl+X` twice to confirm in the supported UI). DSH has no separate session-deletion or secure-erasure command. Prime is expected to remove the matching session artifact directory. Verify deletion of the canonical JSONL, matching `session-artifacts/<session>/`, descendant/inheritance directories, attachment objects that are no longer referenced, exported diagnostics, and applicable backups according to your Prime version and local layout. Filesystems, snapshots, SSD wear levelling, remote sync, and backups can retain copies; ordinary deletion is not guaranteed secure erasure.
50
+
51
+ Back up the canonical Prime JSONL and any user artifacts that must survive. The `dsh-context` projection is disposable and can be rebuilt; backing it up is optional. If DSH state is backed up, preserve its association with the matching canonical JSONL and session directory rather than restoring it under a different session. Stop writes or use a filesystem-consistent snapshot. Encrypt backups, restrict access, test restores, and apply the same retention policy as for transcripts. After a partial or uncertain restore, discard the derived projection and allow DSH to rebuild it from Prime JSONL.
52
+
53
+ ## Secret handling
54
+
55
+ Do not put API keys, cookies, passwords, private keys, connection URLs, or production customer data in prompts, task text, artifacts, grant values, filenames, labels, or transcripts. Use the platform's secret store or environment injection and pass opaque references where possible. Scope credentials narrowly and use short-lived values.
56
+
57
+ Inheritance applies best-effort pattern redaction to eligible parent text. It cannot identify every secret, and the exact child task prompt is persisted for binding and resume checks. Canonical history, explicit artifacts, grants, and attachments are not general-purpose redaction services. Never rely on hash-only metadata or redaction to make a secret safe after exposure. Avoid placing secrets in low-entropy content because fingerprints can permit guess confirmation.
58
+
59
+ Before sharing a bug report, archive, screenshot, trace, or test fixture, replace real session IDs, paths, capability tokens, transcript text, and credentials. Never send live secrets in a GitHub Security Advisory.
60
+
61
+ ## Operational checks
62
+
63
+ - Install only expected package versions and review lockfile changes. Run with a supported Node.js release and supported Prime peer dependencies.
64
+ - Keep session and attachment roots on local, access-controlled storage. Verify ownership, `0700` directories, `0600` files, and restrictive ancestor permissions.
65
+ - Leave `PRIME_DSH_SHADOW_MODE=off` unless local diagnostics are needed. Clear traces and restart after diagnostics.
66
+ - Monitor DSH warnings, disabled publication, integrity failures, unexpected permission changes, storage quota failures, and unfamiliar session descendants.
67
+ - Use separate OS users or sandboxes for different trust domains. Do not grant untrusted agents access to another agent's session tree or capability URI.
68
+ - Test Prime-native session deletion and encrypted backup restore in the actual deployment.
69
+
70
+ ## Incident response
71
+
72
+ 1. Stop affected Prime processes and isolate the host or session storage. Preserve read-only copies if forensic evidence is required.
73
+ 2. Assume exposed transcript text, task prompts, artifacts, grants, attachments, environment-derived values, and backups are compromised. Revoke and rotate credentials and provider tokens; invalidate or remove grants.
74
+ 3. Record package, Prime, Node.js, provider, and OS versions. Preserve relevant canonical JSONL and file metadata without publishing them.
75
+ 4. Remove untrusted derived state. After the canonical JSONL and host are known-good, let DSH rebuild its projection. Do not use a clean rebuild as proof that the canonical transcript is safe.
76
+ 5. Review provider and Prime audit data for unexpected requests. Follow their incident procedures for remote disclosure or account compromise.
77
+ 6. Report a suspected package vulnerability privately through the process in [`SECURITY.md`](../SECURITY.md). Coordinate public disclosure with the maintainers.
78
+ 7. After containment, verify permissions, session deletion behavior, backup copies, dependency integrity, and separation between trust domains.
@@ -0,0 +1,18 @@
1
+ # Shadow telemetry validation
2
+
3
+ Staging implementation observes Prime `context` and `before_provider_request` events without returning replacements or mutating event values.
4
+
5
+ ## Data retained
6
+
7
+ - SHA-256 fingerprint of canonical, credential-redacted payload
8
+ - byte size and previous-payload byte size
9
+ - byte-level longest common prefix and ratio
10
+ - request number, timestamp, stage, session ID, branch leaf ID, and change classification
11
+ - bounded in-memory trace (128 entries); no payload or message content
12
+
13
+ ## Commands
14
+
15
+
16
+ ## Validation
17
+
18
+ `npm run check` runs typechecking, lint, the Prime-native sidecar tests, and Python context-object tests. Coverage includes canonical fingerprints, credential redaction, UTF-8 byte LCP, append/rewrite classification, branch/session isolation, bounded traces, no payload mutation/content retention, and fail-open cyclic-payload handling.
@@ -0,0 +1,24 @@
1
+ # Projection and provider-cache architecture
2
+
3
+ Prime is the only owner of model requests, active context, canonical session JSONL, and compaction. DSH never plans, requests, summarizes, prunes, or commits compaction. It does not interpret history changes as compaction events.
4
+
5
+ DSH observes Prime lifecycle events and indexes the resulting JSONL into a rebuildable, reference-only projection. The `session_compact` hook is passive: after Prime has replaced history, it triggers the same resynchronization used by other lifecycle events.
6
+
7
+ ## Publication diagnostics
8
+
9
+ A publication reports only structural facts:
10
+
11
+ - source mode: `append`, `rebuild`, or `noop`;
12
+ - source entries reused, new, and reindexed;
13
+ - effective entries reused, new, and reindexed;
14
+ - a generic effective rebuild reason.
15
+
16
+ These facts do not assign semantic meaning to a history replacement. Prime entries such as `compaction` and `compactionSummary` remain ordinary canonical data that converters and RLM inheritance may read.
17
+
18
+ ## Provider cache metrics
19
+
20
+ Provider-reported input, cache-read, and cache-write token counts are collected as a generic request series. Aggregate counts, efficiency, and percentiles describe only what the provider reported. DSH does not create cache epochs, mark compaction boundaries, or classify first-after-compaction and summary requests.
21
+
22
+ ## Safety
23
+
24
+ DSH does not edit Prime JSONL or active request context. Derived state can be deleted and rebuilt from Prime's canonical files. Publication and telemetry failures fail open and leave Prime inference unchanged.