context-guardian-core 0.1.0__tar.gz

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 (79) hide show
  1. context_guardian_core-0.1.0/.github/workflows/ci.yml +54 -0
  2. context_guardian_core-0.1.0/.github/workflows/release.yml +62 -0
  3. context_guardian_core-0.1.0/.gitignore +14 -0
  4. context_guardian_core-0.1.0/CHANGELOG.md +20 -0
  5. context_guardian_core-0.1.0/CONTRIBUTING.md +25 -0
  6. context_guardian_core-0.1.0/LICENSE +21 -0
  7. context_guardian_core-0.1.0/PKG-INFO +268 -0
  8. context_guardian_core-0.1.0/README.md +221 -0
  9. context_guardian_core-0.1.0/README.zh-CN.md +162 -0
  10. context_guardian_core-0.1.0/SECURITY.md +15 -0
  11. context_guardian_core-0.1.0/adapters/capabilities.json +23 -0
  12. context_guardian_core-0.1.0/adapters/deepseek-harness/README.md +99 -0
  13. context_guardian_core-0.1.0/adapters/deepseek-harness/README.zh-CN.md +94 -0
  14. context_guardian_core-0.1.0/adapters/deepseek-harness/cordis.patch.yml +9 -0
  15. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/bridge.d.ts +15 -0
  16. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/bridge.d.ts.map +1 -0
  17. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/bridge.js +155 -0
  18. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/bridge.js.map +1 -0
  19. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/host-model.d.ts +4 -0
  20. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/host-model.d.ts.map +1 -0
  21. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/host-model.js +54 -0
  22. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/host-model.js.map +1 -0
  23. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/index.d.ts +16 -0
  24. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/index.d.ts.map +1 -0
  25. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/index.js +126 -0
  26. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/index.js.map +1 -0
  27. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/types.d.ts +43 -0
  28. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/types.d.ts.map +1 -0
  29. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/types.js +2 -0
  30. context_guardian_core-0.1.0/adapters/deepseek-harness/lib/types.js.map +1 -0
  31. context_guardian_core-0.1.0/adapters/deepseek-harness/package.json +67 -0
  32. context_guardian_core-0.1.0/adapters/deepseek-harness/scripts/bridge.test.mjs +107 -0
  33. context_guardian_core-0.1.0/adapters/deepseek-harness/scripts/interactive-fixture-smoke.mjs +405 -0
  34. context_guardian_core-0.1.0/adapters/deepseek-harness/src/bridge.ts +178 -0
  35. context_guardian_core-0.1.0/adapters/deepseek-harness/src/host-model.ts +65 -0
  36. context_guardian_core-0.1.0/adapters/deepseek-harness/src/index.ts +158 -0
  37. context_guardian_core-0.1.0/adapters/deepseek-harness/src/types.ts +46 -0
  38. context_guardian_core-0.1.0/adapters/deepseek-harness/tsconfig.build.json +11 -0
  39. context_guardian_core-0.1.0/adapters/deepseek-harness/tsconfig.json +13 -0
  40. context_guardian_core-0.1.0/adapters/pi/README.md +55 -0
  41. context_guardian_core-0.1.0/adapters/pi/README.zh-CN.md +60 -0
  42. context_guardian_core-0.1.0/adapters/pi/extensions/context-guardian.ts +81 -0
  43. context_guardian_core-0.1.0/adapters/pi/package.json +42 -0
  44. context_guardian_core-0.1.0/adapters/pi/scripts/interactive-fixture-smoke.mjs +73 -0
  45. context_guardian_core-0.1.0/adapters/pi/scripts/session-fixture.mjs +116 -0
  46. context_guardian_core-0.1.0/adapters/pi/scripts/smoke.mjs +113 -0
  47. context_guardian_core-0.1.0/adapters/pi/src/bridge.ts +151 -0
  48. context_guardian_core-0.1.0/adapters/pi/src/host-model.ts +55 -0
  49. context_guardian_core-0.1.0/adapters/pi/src/types.ts +46 -0
  50. context_guardian_core-0.1.0/adapters/pi/tsconfig.json +14 -0
  51. context_guardian_core-0.1.0/context_guardian/__init__.py +46 -0
  52. context_guardian_core-0.1.0/context_guardian/__main__.py +3 -0
  53. context_guardian_core-0.1.0/context_guardian/adapters.py +58 -0
  54. context_guardian_core-0.1.0/context_guardian/bridge.py +98 -0
  55. context_guardian_core-0.1.0/context_guardian/checkpoint.py +81 -0
  56. context_guardian_core-0.1.0/context_guardian/cli.py +196 -0
  57. context_guardian_core-0.1.0/context_guardian/guidance.py +34 -0
  58. context_guardian_core-0.1.0/context_guardian/inspector.py +263 -0
  59. context_guardian_core-0.1.0/context_guardian/models.py +158 -0
  60. context_guardian_core-0.1.0/context_guardian/policy.py +54 -0
  61. context_guardian_core-0.1.0/context_guardian/providers.py +115 -0
  62. context_guardian_core-0.1.0/context_guardian/verification.py +79 -0
  63. context_guardian_core-0.1.0/docs/adapter-contract.md +35 -0
  64. context_guardian_core-0.1.0/docs/context-guardian-explainer.html +597 -0
  65. context_guardian_core-0.1.0/docs/publishing.md +63 -0
  66. context_guardian_core-0.1.0/examples/conversation.json +12 -0
  67. context_guardian_core-0.1.0/package-lock.json +4244 -0
  68. context_guardian_core-0.1.0/package.json +13 -0
  69. context_guardian_core-0.1.0/pyproject.toml +60 -0
  70. context_guardian_core-0.1.0/tests/test_adapter_contract.py +32 -0
  71. context_guardian_core-0.1.0/tests/test_bridge.py +57 -0
  72. context_guardian_core-0.1.0/tests/test_checkpoint.py +54 -0
  73. context_guardian_core-0.1.0/tests/test_cli.py +35 -0
  74. context_guardian_core-0.1.0/tests/test_guidance.py +39 -0
  75. context_guardian_core-0.1.0/tests/test_inspector.py +89 -0
  76. context_guardian_core-0.1.0/tests/test_models.py +25 -0
  77. context_guardian_core-0.1.0/tests/test_policy.py +28 -0
  78. context_guardian_core-0.1.0/tests/test_providers.py +61 -0
  79. context_guardian_core-0.1.0/tests/test_verification.py +20 -0
@@ -0,0 +1,54 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ python:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ python-version: ["3.11", "3.12", "3.13"]
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-python@v5
16
+ with:
17
+ python-version: ${{ matrix.python-version }}
18
+ - run: python -m pip install -e '.[dev]'
19
+ - run: pytest --cov=context_guardian
20
+ - run: ruff check .
21
+
22
+ pi:
23
+ runs-on: ubuntu-latest
24
+ defaults:
25
+ run:
26
+ working-directory: adapters/pi
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: actions/setup-node@v4
30
+ with:
31
+ node-version: 22.19.0
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: "3.13"
35
+ - run: python -m pip install .
36
+ working-directory: .
37
+ - run: npm install
38
+ - run: npm run typecheck
39
+ - run: npm run smoke
40
+
41
+ deepseek-harness:
42
+ runs-on: ubuntu-latest
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+ - uses: actions/setup-node@v4
46
+ with:
47
+ node-version: 22.19.0
48
+ - uses: actions/setup-python@v5
49
+ with:
50
+ python-version: "3.13"
51
+ - run: python -m pip install -e '.[dev]'
52
+ - run: npm install
53
+ - run: npm run typecheck:dsh
54
+ - run: npm run test:dsh
@@ -0,0 +1,62 @@
1
+ name: Publish packages
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ package:
7
+ description: Package set to publish
8
+ required: true
9
+ default: all
10
+ type: choice
11
+ options:
12
+ - all
13
+ - python
14
+ - npm
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ python:
21
+ if: ${{ inputs.package == 'all' || inputs.package == 'python' }}
22
+ runs-on: ubuntu-latest
23
+ permissions:
24
+ contents: read
25
+ id-token: write
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: actions/setup-python@v5
29
+ with:
30
+ python-version: "3.11"
31
+ - run: python -m pip install --upgrade build
32
+ - run: python -m build
33
+ - uses: pypa/gh-action-pypi-publish@release/v1
34
+
35
+ npm:
36
+ if: ${{ inputs.package == 'all' || inputs.package == 'npm' }}
37
+ runs-on: ubuntu-latest
38
+ permissions:
39
+ contents: read
40
+ id-token: write
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+ - uses: actions/setup-node@v4
44
+ with:
45
+ node-version: 22.19.0
46
+ registry-url: https://registry.npmjs.org
47
+ package-manager-cache: false
48
+ # npm Trusted Publishing requires npm 11.5.1 or newer.
49
+ - name: Upgrade npm for trusted publishing
50
+ run: npm install --global npm@11.5.1
51
+ - uses: actions/setup-python@v5
52
+ with:
53
+ python-version: "3.13"
54
+ - run: python -m pip install -e '.[dev]'
55
+ - run: npm ci
56
+ - run: npm run typecheck
57
+ - run: npm run typecheck:dsh
58
+ - run: npm run test:dsh
59
+ # Authentication is provided by GitHub OIDC after each package is configured
60
+ # with this repository's npm Trusted Publisher relationship.
61
+ - run: npm publish --workspace adapters/pi --access public
62
+ - run: npm publish --workspace adapters/deepseek-harness --access public
@@ -0,0 +1,14 @@
1
+ .venv*/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .coverage
6
+ htmlcov/
7
+ .ruff_cache/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ node_modules/
12
+ .DS_Store
13
+ .agents/context-guardian.md
14
+ .agents/context-guardian-state.json
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Added portable `build_checkpoint()` output for assisted integrations.
6
+ - Added a shared adapter contract and capability matrix for host integrations.
7
+ - Added a DeepSeek Harness adapter that decorates native compaction with Context
8
+ Guardian inspection, human review, host-model reuse, and fail-open fallback.
9
+ - Added a pre-seeded interactive DeepSeek Harness fixture smoke for manual Keep/Drop
10
+ validation without requiring a long real conversation.
11
+ - Hardened the JSONL guidance bridge to validate candidates received over the wire.
12
+
13
+ ## 0.1.0 - 2026-09-11
14
+
15
+ - Added framework-neutral Python inspection core.
16
+ - Added deterministic rules mode and optional structured providers.
17
+ - Added JSONL bridge for host-model calls.
18
+ - Added Pi compaction adapter with fail-open behavior.
19
+ - Added deterministic verification CLI, Pi RPC smoke test, pre-seeded interactive Pi
20
+ fixture smoke test, example conversation, tests, and release documentation.
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ 1. Create a focused change that preserves the core boundary.
4
+ 2. Add or update tests for behavior changes.
5
+ 3. Run `context-guardian verify examples/conversation.json`.
6
+ 4. Run `pytest` and `ruff check .`.
7
+ 5. For Pi changes, run `npm run typecheck` and `npm run smoke` in `adapters/pi`.
8
+ 6. For DeepSeek Harness changes, run `npm run typecheck:dsh`, `npm run test:dsh`,
9
+ and `npm run dsh-fixture-smoke`.
10
+ 7. Before a release, run the interactive fixture checks from the repository root:
11
+ `npm run pi-fixture-smoke` and `npm run dsh-fixture-smoke`; manually review every
12
+ Keep/Drop flow.
13
+
14
+ The deterministic verifier, RPC smoke test, and CI fixture jobs are fast regression
15
+ checks. The local fixture smoke commands are interactive so a maintainer can verify
16
+ the actual review surface before release. Set `CONTEXT_GUARDIAN_REVIEW_MODE=keep` in
17
+ automation when no terminal is available.
18
+
19
+ The manual publish workflow lives in `.github/workflows/release.yml`. Python and npm
20
+ publishing use trusted publishing through GitHub Actions OIDC; no long-lived registry
21
+ token is required. Each npm package must have a Trusted Publisher configured for
22
+ the `deulofeu1/context-guardian` repository and `release.yml` workflow.
23
+
24
+ Do not add a server, persistent memory database, or replacement summarizer without
25
+ first discussing the project scope.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Context Guardian 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.
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.5
2
+ Name: context-guardian-core
3
+ Version: 0.1.0
4
+ Summary: A human-in-the-loop control layer for AI agent context compaction.
5
+ Author: Context Guardian Contributors
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Context Guardian Contributors
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Keywords: ai-agent,context-compaction,human-in-the-loop,memory,pi
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3
33
+ Classifier: Programming Language :: Python :: 3.11
34
+ Classifier: Programming Language :: Python :: 3.12
35
+ Classifier: Programming Language :: Python :: 3.13
36
+ Classifier: Topic :: Software Development :: Libraries
37
+ Requires-Python: >=3.11
38
+ Requires-Dist: pydantic<3,>=2.7
39
+ Provides-Extra: dev
40
+ Requires-Dist: build<2,>=1.2; extra == 'dev'
41
+ Requires-Dist: pytest-cov<7,>=5.0; extra == 'dev'
42
+ Requires-Dist: pytest<9,>=8.0; extra == 'dev'
43
+ Requires-Dist: ruff<1,>=0.6; extra == 'dev'
44
+ Provides-Extra: openai
45
+ Requires-Dist: openai<2,>=1.40; extra == 'openai'
46
+ Description-Content-Type: text/markdown
47
+
48
+ # Context Guardian
49
+
50
+ > Never let your coding agent forget the wrong thing.
51
+
52
+ [English](README.md) · [简体中文](README.zh-CN.md)
53
+
54
+ Context Guardian adds a human review layer before an AI agent compacts its context.
55
+ It does not replace the agent's memory system, summarizer, token manager, or native
56
+ compaction engine. It makes the hidden keep/drop decision inspectable.
57
+
58
+ ```text
59
+ Context
60
+
61
+ Inspect
62
+
63
+ Auto Keep / Auto Drop
64
+
65
+ Human Review
66
+
67
+ Compaction Guidance
68
+
69
+ Agent Native Compaction
70
+ ```
71
+
72
+ ## Why it exists
73
+
74
+ Agents often discard the reason a path was rejected. That can make them repeat the
75
+ same failed approach after compaction. Context Guardian surfaces durable decisions,
76
+ constraints, failed attempts, unfinished work, and transient noise before the host
77
+ agent summarizes the context.
78
+
79
+ ## Quick start
80
+
81
+ ### Installation status
82
+
83
+ This repository is source-installable today, but the Python and npm packages have
84
+ not been published yet. That means the current path is clone/download → install
85
+ the Python and JavaScript dependencies → run the adapter from the checkout.
86
+
87
+ The no-checkout installation shown below is the target end-user experience after
88
+ release. The host CLIs remain separate prerequisites. The Python distribution is
89
+ named `context-guardian-core`; its installed CLI remains `context-guardian`.
90
+
91
+ Package publication is designed around npm Trusted Publishing with GitHub Actions
92
+ OIDC. The release workflow does not use a long-lived `NPM_TOKEN`; configure the
93
+ trusted publisher for each npm package as described in
94
+ [`docs/publishing.md`](docs/publishing.md).
95
+
96
+ ### Use this repository today
97
+
98
+ ```bash
99
+ git clone https://github.com/deulofeu1/context-guardian.git
100
+ cd context-guardian
101
+
102
+ python3 -m venv .venv
103
+ . .venv/bin/activate
104
+ python -m pip install -e '.[dev]'
105
+ npm install
106
+ ```
107
+
108
+ The workspace install does not install the host CLI itself. The Pi workflow expects
109
+ Pi `0.82.1` and Node.js `22.19.0+`; the DeepSeek Harness workflow expects the
110
+ DeepSeek Harness `0.1.5-rc.x` API family and the same Node.js runtime.
111
+
112
+ Now run the local Python CLI without an API key:
113
+
114
+ ```bash
115
+ context-guardian inspect examples/conversation.json
116
+ context-guardian inspect examples/conversation.json --json
117
+ context-guardian review examples/conversation.json
118
+ context-guardian verify examples/conversation.json
119
+ ```
120
+
121
+ `verify` is a deterministic release smoke test. It needs no model or API key and
122
+ checks critical-memory retention, noise removal, stable candidate IDs, and rendered
123
+ guidance. It is a fast core check, not a replacement for the interactive Pi test.
124
+
125
+ For the source Pi workflow, use the interactive fixture from the checkout:
126
+
127
+ ```bash
128
+ npm run pi-fixture-smoke
129
+ ```
130
+
131
+ It opens Pi with a pre-seeded long conversation and lets you manually choose
132
+ Keep/Drop. To load the source extension in an existing Pi session, see
133
+ [`adapters/pi/README.md`](adapters/pi/README.md).
134
+
135
+ For DeepSeek Harness, install the local adapter into the Web profile:
136
+
137
+ ```bash
138
+ dsh plugin --profile web add "$PWD/adapters/deepseek-harness"
139
+ ```
140
+
141
+ ### Install published packages after release
142
+
143
+ These are the intended commands for end users once the package names are published
144
+ and the Python distribution name is resolved:
145
+
146
+ ```bash
147
+ python -m pip install context-guardian-core
148
+ pi install npm:@context-guardian/pi
149
+ dsh plugin --profile web add context-guardian-deepseek-harness
150
+ ```
151
+
152
+ Until then, do not use these commands as an installation test; use the source
153
+ workflow above.
154
+
155
+ Inside Pi, the adapter reuses the current host model and its existing credentials.
156
+ No second API key is required. The Python process never receives those credentials.
157
+ The published adapter is tested against Pi `0.82.1` and Node.js `22.19.0+`.
158
+
159
+ For DeepSeek Harness:
160
+
161
+ ```bash
162
+ dsh plugin --profile web add /absolute/path/to/ContextGuardian/adapters/deepseek-harness
163
+ ```
164
+
165
+ After the adapter is published, the path can be replaced with
166
+ `context-guardian-deepseek-harness`.
167
+
168
+ This adapter decorates DeepSeek Harness's native `dsh-compaction-basic` backend.
169
+ It reuses Harness's active model route for structured inspection, presents uncertain
170
+ candidates through Harness's user-question UI, and passes the resulting guidance back
171
+ into the native summary. Harness remains responsible for session persistence and the
172
+ compaction transaction. The adapter targets the DeepSeek Harness `0.1.5-rc.x` API
173
+ family and is installed as a separate package from the Pi adapter. Web sessions use
174
+ the selected agent preset, so the preset must contain the Context Guardian compaction
175
+ row; the adapter README documents the one-time preset setup.
176
+
177
+ ## Modes
178
+
179
+ - Rules mode is local, deterministic, conservative, and the default for the CLI.
180
+ - Pi mode asks the host agent's current model for structured candidates, then uses
181
+ Pi's native compaction helper with the resulting guidance.
182
+ - OpenAI is an optional standalone CLI provider: `pip install 'context-guardian-core[openai]'` after release.
183
+
184
+ If the bridge, model call, or review UI fails, the adapter fails open and lets native
185
+ Pi compaction continue normally.
186
+
187
+ ## Integrations
188
+
189
+ | Platform | Level | Auto trigger | Host model | Human review | Preservation |
190
+ | --- | --- | --- | --- | --- | --- |
191
+ | Pi | Native | Yes | Pi current model | Pi UI | Direct native `customInstructions` |
192
+ | DeepSeek Harness | Native | Yes | Harness current `ctx.llm` route | `userQuestions` UI | Direct native input message |
193
+
194
+ The current release focuses on native compaction integrations. See
195
+ [`docs/adapter-contract.md`](docs/adapter-contract.md) and
196
+ [`adapters/capabilities.json`](adapters/capabilities.json) for the shared contract
197
+ and capability declaration.
198
+
199
+ ## Python API
200
+
201
+ ```python
202
+ from context_guardian import ContextGuardian
203
+
204
+ guardian = ContextGuardian()
205
+ result = guardian.inspect(messages)
206
+
207
+ decisions = [{"candidate_id": result.review[0].id, "action": "keep"}]
208
+ guidance = guardian.build_guidance(result.candidates, decisions)
209
+ print(guidance.text)
210
+
211
+ checkpoint = guardian.build_checkpoint(result.candidates, decisions)
212
+ print(checkpoint.text)
213
+ ```
214
+
215
+ ## Project boundary
216
+
217
+ Context Guardian intentionally does not implement an agent loop, context window
218
+ management, conversation persistence, vector database, RAG, or a competing summarizer.
219
+ If the host agent already provides a capability, the adapter reuses it.
220
+
221
+ ## Development
222
+
223
+ ```bash
224
+ python -m venv .venv
225
+ . .venv/bin/activate
226
+ python -m pip install -e '.[dev]'
227
+ pytest
228
+ ruff check .
229
+
230
+ npm install
231
+ npm run typecheck
232
+ npm run typecheck:dsh
233
+ npm run test:dsh
234
+ npm run pi-smoke
235
+ npm run pi-fixture-smoke
236
+ npm run dsh-fixture-smoke
237
+ ```
238
+
239
+ The fast Pi smoke test loads the extension in RPC mode and exercises the Python JSONL
240
+ bridge without requiring a live model call. The important end-to-end check is the
241
+ interactive fixture smoke test:
242
+
243
+ ```bash
244
+ npm run pi-fixture-smoke
245
+ ```
246
+
247
+ It creates a temporary Pi session containing a pre-seeded, sufficiently large
248
+ conversation, opens the Pi UI, and lets you run `/compact` and manually choose
249
+ Keep/Drop for uncertain candidates. This means nobody needs to spend time creating a
250
+ long real conversation just to validate the adapter. The fixture uses the current Pi
251
+ model and authentication, so log in to Pi first if necessary. If the Python core is
252
+ outside the repository virtual environment, set `CONTEXT_GUARDIAN_PYTHON` explicitly.
253
+
254
+ The DeepSeek Harness adapter has the equivalent interactive fixture:
255
+
256
+ ```bash
257
+ env PATH="/path/to/node-22.19/bin:$PATH" npm run dsh-fixture-smoke
258
+ ```
259
+
260
+ It creates a temporary Harness profile and a pre-seeded long session, opens the Web UI,
261
+ and pauses on an uncertain SQLite decision so you can select Keep or Drop. It also
262
+ verifies that the goal, API constraint, PostgreSQL decision, `auth.py` TODO, and useful
263
+ failure context reach native compaction guidance while transient grep/npm output is
264
+ discarded. No real API key is needed because the fixture uses a replay model.
265
+
266
+ ## License
267
+
268
+ MIT.
@@ -0,0 +1,221 @@
1
+ # Context Guardian
2
+
3
+ > Never let your coding agent forget the wrong thing.
4
+
5
+ [English](README.md) · [简体中文](README.zh-CN.md)
6
+
7
+ Context Guardian adds a human review layer before an AI agent compacts its context.
8
+ It does not replace the agent's memory system, summarizer, token manager, or native
9
+ compaction engine. It makes the hidden keep/drop decision inspectable.
10
+
11
+ ```text
12
+ Context
13
+
14
+ Inspect
15
+
16
+ Auto Keep / Auto Drop
17
+
18
+ Human Review
19
+
20
+ Compaction Guidance
21
+
22
+ Agent Native Compaction
23
+ ```
24
+
25
+ ## Why it exists
26
+
27
+ Agents often discard the reason a path was rejected. That can make them repeat the
28
+ same failed approach after compaction. Context Guardian surfaces durable decisions,
29
+ constraints, failed attempts, unfinished work, and transient noise before the host
30
+ agent summarizes the context.
31
+
32
+ ## Quick start
33
+
34
+ ### Installation status
35
+
36
+ This repository is source-installable today, but the Python and npm packages have
37
+ not been published yet. That means the current path is clone/download → install
38
+ the Python and JavaScript dependencies → run the adapter from the checkout.
39
+
40
+ The no-checkout installation shown below is the target end-user experience after
41
+ release. The host CLIs remain separate prerequisites. The Python distribution is
42
+ named `context-guardian-core`; its installed CLI remains `context-guardian`.
43
+
44
+ Package publication is designed around npm Trusted Publishing with GitHub Actions
45
+ OIDC. The release workflow does not use a long-lived `NPM_TOKEN`; configure the
46
+ trusted publisher for each npm package as described in
47
+ [`docs/publishing.md`](docs/publishing.md).
48
+
49
+ ### Use this repository today
50
+
51
+ ```bash
52
+ git clone https://github.com/deulofeu1/context-guardian.git
53
+ cd context-guardian
54
+
55
+ python3 -m venv .venv
56
+ . .venv/bin/activate
57
+ python -m pip install -e '.[dev]'
58
+ npm install
59
+ ```
60
+
61
+ The workspace install does not install the host CLI itself. The Pi workflow expects
62
+ Pi `0.82.1` and Node.js `22.19.0+`; the DeepSeek Harness workflow expects the
63
+ DeepSeek Harness `0.1.5-rc.x` API family and the same Node.js runtime.
64
+
65
+ Now run the local Python CLI without an API key:
66
+
67
+ ```bash
68
+ context-guardian inspect examples/conversation.json
69
+ context-guardian inspect examples/conversation.json --json
70
+ context-guardian review examples/conversation.json
71
+ context-guardian verify examples/conversation.json
72
+ ```
73
+
74
+ `verify` is a deterministic release smoke test. It needs no model or API key and
75
+ checks critical-memory retention, noise removal, stable candidate IDs, and rendered
76
+ guidance. It is a fast core check, not a replacement for the interactive Pi test.
77
+
78
+ For the source Pi workflow, use the interactive fixture from the checkout:
79
+
80
+ ```bash
81
+ npm run pi-fixture-smoke
82
+ ```
83
+
84
+ It opens Pi with a pre-seeded long conversation and lets you manually choose
85
+ Keep/Drop. To load the source extension in an existing Pi session, see
86
+ [`adapters/pi/README.md`](adapters/pi/README.md).
87
+
88
+ For DeepSeek Harness, install the local adapter into the Web profile:
89
+
90
+ ```bash
91
+ dsh plugin --profile web add "$PWD/adapters/deepseek-harness"
92
+ ```
93
+
94
+ ### Install published packages after release
95
+
96
+ These are the intended commands for end users once the package names are published
97
+ and the Python distribution name is resolved:
98
+
99
+ ```bash
100
+ python -m pip install context-guardian-core
101
+ pi install npm:@context-guardian/pi
102
+ dsh plugin --profile web add context-guardian-deepseek-harness
103
+ ```
104
+
105
+ Until then, do not use these commands as an installation test; use the source
106
+ workflow above.
107
+
108
+ Inside Pi, the adapter reuses the current host model and its existing credentials.
109
+ No second API key is required. The Python process never receives those credentials.
110
+ The published adapter is tested against Pi `0.82.1` and Node.js `22.19.0+`.
111
+
112
+ For DeepSeek Harness:
113
+
114
+ ```bash
115
+ dsh plugin --profile web add /absolute/path/to/ContextGuardian/adapters/deepseek-harness
116
+ ```
117
+
118
+ After the adapter is published, the path can be replaced with
119
+ `context-guardian-deepseek-harness`.
120
+
121
+ This adapter decorates DeepSeek Harness's native `dsh-compaction-basic` backend.
122
+ It reuses Harness's active model route for structured inspection, presents uncertain
123
+ candidates through Harness's user-question UI, and passes the resulting guidance back
124
+ into the native summary. Harness remains responsible for session persistence and the
125
+ compaction transaction. The adapter targets the DeepSeek Harness `0.1.5-rc.x` API
126
+ family and is installed as a separate package from the Pi adapter. Web sessions use
127
+ the selected agent preset, so the preset must contain the Context Guardian compaction
128
+ row; the adapter README documents the one-time preset setup.
129
+
130
+ ## Modes
131
+
132
+ - Rules mode is local, deterministic, conservative, and the default for the CLI.
133
+ - Pi mode asks the host agent's current model for structured candidates, then uses
134
+ Pi's native compaction helper with the resulting guidance.
135
+ - OpenAI is an optional standalone CLI provider: `pip install 'context-guardian-core[openai]'` after release.
136
+
137
+ If the bridge, model call, or review UI fails, the adapter fails open and lets native
138
+ Pi compaction continue normally.
139
+
140
+ ## Integrations
141
+
142
+ | Platform | Level | Auto trigger | Host model | Human review | Preservation |
143
+ | --- | --- | --- | --- | --- | --- |
144
+ | Pi | Native | Yes | Pi current model | Pi UI | Direct native `customInstructions` |
145
+ | DeepSeek Harness | Native | Yes | Harness current `ctx.llm` route | `userQuestions` UI | Direct native input message |
146
+
147
+ The current release focuses on native compaction integrations. See
148
+ [`docs/adapter-contract.md`](docs/adapter-contract.md) and
149
+ [`adapters/capabilities.json`](adapters/capabilities.json) for the shared contract
150
+ and capability declaration.
151
+
152
+ ## Python API
153
+
154
+ ```python
155
+ from context_guardian import ContextGuardian
156
+
157
+ guardian = ContextGuardian()
158
+ result = guardian.inspect(messages)
159
+
160
+ decisions = [{"candidate_id": result.review[0].id, "action": "keep"}]
161
+ guidance = guardian.build_guidance(result.candidates, decisions)
162
+ print(guidance.text)
163
+
164
+ checkpoint = guardian.build_checkpoint(result.candidates, decisions)
165
+ print(checkpoint.text)
166
+ ```
167
+
168
+ ## Project boundary
169
+
170
+ Context Guardian intentionally does not implement an agent loop, context window
171
+ management, conversation persistence, vector database, RAG, or a competing summarizer.
172
+ If the host agent already provides a capability, the adapter reuses it.
173
+
174
+ ## Development
175
+
176
+ ```bash
177
+ python -m venv .venv
178
+ . .venv/bin/activate
179
+ python -m pip install -e '.[dev]'
180
+ pytest
181
+ ruff check .
182
+
183
+ npm install
184
+ npm run typecheck
185
+ npm run typecheck:dsh
186
+ npm run test:dsh
187
+ npm run pi-smoke
188
+ npm run pi-fixture-smoke
189
+ npm run dsh-fixture-smoke
190
+ ```
191
+
192
+ The fast Pi smoke test loads the extension in RPC mode and exercises the Python JSONL
193
+ bridge without requiring a live model call. The important end-to-end check is the
194
+ interactive fixture smoke test:
195
+
196
+ ```bash
197
+ npm run pi-fixture-smoke
198
+ ```
199
+
200
+ It creates a temporary Pi session containing a pre-seeded, sufficiently large
201
+ conversation, opens the Pi UI, and lets you run `/compact` and manually choose
202
+ Keep/Drop for uncertain candidates. This means nobody needs to spend time creating a
203
+ long real conversation just to validate the adapter. The fixture uses the current Pi
204
+ model and authentication, so log in to Pi first if necessary. If the Python core is
205
+ outside the repository virtual environment, set `CONTEXT_GUARDIAN_PYTHON` explicitly.
206
+
207
+ The DeepSeek Harness adapter has the equivalent interactive fixture:
208
+
209
+ ```bash
210
+ env PATH="/path/to/node-22.19/bin:$PATH" npm run dsh-fixture-smoke
211
+ ```
212
+
213
+ It creates a temporary Harness profile and a pre-seeded long session, opens the Web UI,
214
+ and pauses on an uncertain SQLite decision so you can select Keep or Drop. It also
215
+ verifies that the goal, API constraint, PostgreSQL decision, `auth.py` TODO, and useful
216
+ failure context reach native compaction guidance while transient grep/npm output is
217
+ discarded. No real API key is needed because the fixture uses a replay model.
218
+
219
+ ## License
220
+
221
+ MIT.