zeroscan 2.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.
zeroscan-2.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chau Vu / CPF-FAMILY
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,320 @@
1
+ Metadata-Version: 2.4
2
+ Name: zeroscan
3
+ Version: 2.1.0
4
+ Summary: The Zero-Scan, Git-Aware Context Engine for AI Coding Agents (Hermes, Claude Code, Codex, OpenCode)
5
+ Author-email: Chau Vu / CPF-FAMILY <chauvuusvn@users.noreply.github.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/chauvuusvn/zeroscan
8
+ Project-URL: Documentation, https://github.com/chauvuusvn/zeroscan#readme
9
+ Project-URL: Repository, https://github.com/chauvuusvn/zeroscan.git
10
+ Project-URL: Issues, https://github.com/chauvuusvn/zeroscan/issues
11
+ Keywords: ai-agents,context-window,mcp,model-context-protocol,claude-code,cursor,windsurf,hermes-agent,token-optimization,zero-scan
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # ZeroScan (`.agent/`) β€” Project Memory V2.1
31
+
32
+ [![CI Suite](https://github.com/chauvuusvn/zeroscan/actions/workflows/ci.yml/badge.svg)](https://github.com/chauvuusvn/zeroscan/actions/workflows/ci.yml)
33
+ [![PyPI - Version](https://img.shields.io/badge/pypi-v2.1.0-blue.svg)](https://pypi.org/project/zeroscan/)
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
35
+ [![Python: 3.9+](https://img.shields.io/badge/Python-3.9%2B-blue.svg)](https://www.python.org/)
36
+ [![Context Budget](https://img.shields.io/badge/Context%20Budget-%3C=10%20KB-success.svg)](https://github.com/chauvuusvn/zeroscan)
37
+
38
+ ```bash
39
+ # Instant Installation via pip
40
+ pip install zeroscan
41
+
42
+ # Instant Bootstrap in any repository
43
+ zeroscan-bootstrap --name "my-awesome-project" --mission "Build scalable AI apps"
44
+ ```
45
+
46
+ [ πŸ‡¬πŸ‡§ English ](README.md) | [ πŸ‡»πŸ‡³ TiαΊΏng Việt ](README.vi.md) | [ πŸ“˜ Usage Guide ](USAGE_GUIDE.md) | [ πŸ“• HΖ°α»›ng dαΊ«n sα»­ dα»₯ng ](HUONG_DAN_SU_DUNG.md) | [ πŸš€ Deep-Dive Article ](articles/zero-scan-llm-vram-optimization.md)
47
+
48
+ > **The Zero-Scan, Git-Aware Context Engine for AI Coding Agents**
49
+ > Compatible with Hermes Agent, Claude Code, OpenAI Codex, and OpenCode.
50
+
51
+ ---
52
+
53
+ ## 🌟 Overview
54
+
55
+ **Project Memory V2.0** is an open standard designed to eliminate context bloat, hallucination, and directory-crawling overhead in AI-driven software development.
56
+
57
+ Traditional coding agents waste tens of thousands of tokens scanning entire codebases upon startup. Project Memory replaces scanning with a lightweight, Git-bound **Level 0 Boot Anchor** (`BOOT.md` < 1 KB) and an architectural **GPS Map** (`PROJECT_MAP.json`), ensuring agents boot instantly with `<= 10 KB` of total context.
58
+
59
+ ---
60
+
61
+ ## πŸ’‘ Why It Saves 90–95% Tokens
62
+
63
+ ### 1. Zero-Scan Startup (Level 0 Boot Anchor)
64
+ Traditional agents ingest entire repositories on every session turn, easily burning 30,000–100,000+ tokens before writing a single line of code. With Project Memory, the agent reads **only `BOOT.md` (~1 KB / ~500 tokens)**, gaining immediate architectural clarity and task direction without exploring irrelevant directories.
65
+
66
+ ### 2. GPS Navigation via `PROJECT_MAP.json`
67
+ Instead of performing costly regex searches across the tree, agents query the structured domain map to resolve exact source and test file paths just-in-time. Irrelevant modules are never loaded into working context.
68
+
69
+ ### 3. Lean Multi-Agent Task Delegation
70
+ When an orchestrator agent delegates tasks to subagents or workers (e.g. specialized coding models), it passes only `BOOT.md` and `NEXT_TASK.md`. Worker agents operate in isolated, razor-sharp context windows without paying the token tax of the full repository.
71
+
72
+ ### πŸ“Š Token Consumption Comparison
73
+
74
+ | Lifecycle Stage | Traditional Approach (Full Scan) | Project Memory V2.0 (`.agent/`) | Token Savings |
75
+ |---|---|---|:---:|
76
+ | **Session Boot** | Ingest whole repo (30k–100k+ tokens) | Read `BOOT.md` (< 1 KB / ~500 tokens) | **~95%** |
77
+ | **Domain Navigation** | Recursive grep & tree traversal | Query `PROJECT_MAP.json` (< 3 KB) | **~90%** |
78
+ | **Worker Subagent Boot** | Re-read full repo per child agent | Load `NEXT_TASK.md` + target files | **~92%** |
79
+ | **Session Memory Drift** | Prompt bloat & hallucination | External append-only ledger & ADRs | **Zero Drift** |
80
+
81
+ > **πŸ“Œ Engineering Scope Note:** Token savings specifically measure context initialization, recursive directory crawling, and exploratory search overhead. Tokens required to author or modify actual code files depend naturally on the size of the generated diff.
82
+
83
+ ---
84
+
85
+ ## πŸ“ Standard `.agent/` Architecture
86
+
87
+ Every compliant project contains an `.agent/` directory with the following structure:
88
+
89
+ ```
90
+ .agent/
91
+ β”œβ”€β”€ BOOT.md # [Level 0] Ultra-light session anchor (< 1 KB / ~30 lines)
92
+ β”œβ”€β”€ PROJECT_STATE.json # [Level 1] Machine state tied to git verified_commit & metrics
93
+ β”œβ”€β”€ PROJECT_MAP.json # Codebase GPS: Maps functional domains to files & tests
94
+ β”œβ”€β”€ DECISIONS.md # Architectural Decision Records (ADRs) with [LOCKED] status
95
+ β”œβ”€β”€ TASK_LEDGER.jsonl # Immutable append-only record of completed tasks & evidence
96
+ β”œβ”€β”€ NEXT_TASK.md # Concrete active task spec, acceptance criteria & test commands
97
+ β”œβ”€β”€ MEMORY_PROTOCOL.md # The 10 Golden Rules for agent execution & evidence verification
98
+ └── memory.py # Pure Python 3.11+ zero-dependency engine (validate, checkpoint, status)
99
+ ```
100
+
101
+ ---
102
+
103
+ ## πŸš€ Quick Start: Scaffolding a New Project
104
+
105
+ ### Option A: Instant One-Liner (No Clone Required)
106
+ ```bash
107
+ curl -fsSL https://raw.githubusercontent.com/chauvuusvn/zeroscan/main/bootstrap.py | python3 - -n "Quantum Engine" --domains "engine,storage,network,api" --git-init
108
+ ```
109
+
110
+ ### Option B: Using local `bootstrap.py`
111
+ Use `bootstrap.py` to generate a standard `.agent/` memory system in any target repository:
112
+
113
+ ```bash
114
+ # Basic usage in current directory
115
+ python3 bootstrap.py
116
+
117
+ # Custom scaffolding for a specific project
118
+ python3 bootstrap.py \
119
+ --target /path/to/my-project \
120
+ --name "Quantum Engine" \
121
+ --mission "High-performance distributed event processing engine" \
122
+ --phase "Phase 1 - Core Architecture" \
123
+ --domains "engine,storage,network,api" \
124
+ --git-init
125
+ ```
126
+
127
+ ### CLI Arguments for `bootstrap.py`:
128
+ | Option | Short | Default | Description |
129
+ |---|---|---|---|
130
+ | `--target` | `-t` | `.` | Target project directory path |
131
+ | `--name` | `-n` | Directory name | Name of the project |
132
+ | `--mission` | `-m` | "Autonomous..." | High-level mission statement |
133
+ | `--phase` | `-p` | "Phase 1..." | Initial project phase name |
134
+ | `--domains` | `-d` | "core" | Comma-separated functional domain names |
135
+ | `--force` | `-f` | `False` | Overwrite existing `.agent/` directory |
136
+ | `--git-init` | | `False` | Run `git init` if target is not a git repo |
137
+
138
+ ---
139
+
140
+ ## πŸ› οΈ Operating `.agent/memory.py` in Target Projects
141
+
142
+ Once bootstrapped, agents interact with the memory engine directly:
143
+
144
+ ### 1. View Project Status & Budget
145
+ ```bash
146
+ python3 .agent/memory.py status
147
+ ```
148
+ Displays mission, current phase, active task, git HEAD vs verified commit, and context size budget breakdown.
149
+
150
+ ### 2. Validate Memory Integrity
151
+ ```bash
152
+ python3 .agent/memory.py validate
153
+ ```
154
+ Validates JSON schemas, git commit alignment, and verifies that `BOOTSTRAP_CONTEXT_BYTES <= 10,240 bytes` (10 KB).
155
+
156
+ ### 3. Checkpoint State Atomically & Synchronize Next Task
157
+ ```bash
158
+ python3 .agent/memory.py checkpoint \
159
+ --phase "Phase 2 - Feature Development" \
160
+ --status "IN_PROGRESS" \
161
+ --record-ledger \
162
+ --task-id "TASK-002" \
163
+ --task-summary "Completed user registration and password hashing" \
164
+ --evidence "pytest_exit_0_hash_abc123" \
165
+ --test-status "ALL_PASS (48/48)" \
166
+ --next-task "Build JWT Refresh Token Rotation" \
167
+ --next-task-id "TASK-003" \
168
+ --next-task-desc "Implement Redis-backed refresh token rotation with revoke whitelist"
169
+ ```
170
+ - Atomically updates `PROJECT_STATE.json`.
171
+ - Synchronously regenerates `BOOT.md`.
172
+ - Synchronously updates `NEXT_TASK.md` with acceptance criteria.
173
+ - Appends task evidence to `TASK_LEDGER.jsonl`.
174
+ - Recalculates exact context metrics.
175
+
176
+ ### 4. Append Architectural Decision (ADR)
177
+ ```bash
178
+ python3 .agent/memory.py add-decision \
179
+ --id "ADR-002" \
180
+ --title "Use SQLite with WAL mode for local cache" \
181
+ --status "LOCKED" \
182
+ --context "High concurrent read requirements without external DB services" \
183
+ --decision "Use embedded SQLite database with WAL and 64MB mmap" \
184
+ --consequences "Zero external runtime dependencies; single-node only"
185
+ ```
186
+
187
+ ---
188
+
189
+ ## πŸ”Œ Model Context Protocol (MCP) Server Integration
190
+
191
+ Zero-Scan includes a native **Model Context Protocol (MCP)** server for 1-click integration with **Cursor**, **Claude Desktop**, **Windsurf**, **Trae**, and **Claude Code**.
192
+
193
+ ### Setup in Claude Desktop (`claude_desktop_config.json`) / Cursor:
194
+ ```json
195
+ {
196
+ "mcpServers": {
197
+ "zeroscan": {
198
+ "command": "npx",
199
+ "args": ["-y", "zeroscan-mcp"]
200
+ }
201
+ }
202
+ }
203
+ ```
204
+ *Or using Python directly:*
205
+ ```json
206
+ {
207
+ "mcpServers": {
208
+ "zeroscan": {
209
+ "command": "python3",
210
+ "args": ["-m", "core.mcp_server"]
211
+ }
212
+ }
213
+ }
214
+ ```
215
+
216
+ ### πŸ› οΈ Exposed MCP Tools:
217
+ - `zeroscan_boot`: Instant Level 0 Boot Anchor (< 1 KB / ~500 tokens). Eliminates repository scanning.
218
+ - `zeroscan_get_map`: Structured architectural GPS map (`PROJECT_MAP.json`).
219
+ - `zeroscan_get_state`: Milestone progress, git hash alignment, and execution state.
220
+ - `zeroscan_get_next_task`: Immediate actionable next task (`NEXT_TASK.md`).
221
+ - `zeroscan_record_decision`: Append ADRs to `DECISIONS.md` across sessions.
222
+ - `zeroscan_validate`: Enforce `<= 10 KB` context budget.
223
+
224
+ ---
225
+
226
+ ## πŸ“Š Context Size Metrics & Limits
227
+
228
+ Project Memory V2.0 strictly enforces context budgets:
229
+
230
+ - **Bootstrap Context Budget (`BOOTSTRAP_CONTEXT_BYTES`)**:
231
+ $$\text{Size}(\text{BOOT.md}) + \text{Size}(\text{PROJECT_STATE.json}) + \text{Size}(\text{NEXT_TASK.md}) \le 10,240 \text{ bytes (10 KB)}$$
232
+ - **Zero Directory Traversal**: Agents read `BOOT.md` and `PROJECT_MAP.json` to navigate directly to relevant files instead of listing/reading entire trees.
233
+
234
+ ---
235
+
236
+ ## πŸ“œ The 10 Golden Rules
237
+
238
+ 1. **Level 0 Boot First**: Read `.agent/BOOT.md` on boot. Never recursive-scan codebase.
239
+ 2. **Verified Commit Binding**: All state transitions must reference valid git commit hashes.
240
+ 3. **GPS Routing via Map**: Use `PROJECT_MAP.json` to load only relevant domain files.
241
+ 4. **Immutable Locked Decisions**: Never violate `[LOCKED]` ADRs in `DECISIONS.md`.
242
+ 5. **Atomic State Checkpointing**: Use `memory.py checkpoint` for all updates.
243
+ 6. **Append-Only Ledger**: Never modify or truncate `TASK_LEDGER.jsonl`.
244
+ 7. **Single Active Task Focus**: `NEXT_TASK.md` governs the current single focus.
245
+ 8. **Evidence-Based Verification**: Only mark tasks complete after passing verified test suites.
246
+ 9. **Strict Context Budget**: Keep combined bootstrap files under 10 KB.
247
+ 10. **Memory Validation Guard**: Run `memory.py validate` in pre-commit / CI.
248
+
249
+ ---
250
+
251
+ ## ⚠️ Common Pitfalls & Anti-Patterns (and How to Avoid Them)
252
+
253
+ | Anti-Pattern / Pitfall | Root Cause | Impact | Zero-Scan Solution & Recovery |
254
+ |---|---|---|---|
255
+ | **1. The Stale State Trap** | Agent implements features but forgets to update `BOOT.md` / `PROJECT_STATE.json` before session exit. | Next agent session restarts from stale state, causing duplicate work or broken invariants. | **Session Exit Gate**: Enforce `python3 .agent/memory.py checkpoint` in pre-commit hooks and agent termination protocols before ending turns. |
256
+ | **2. Decisions Bloat Trap** | Accumulating dozens of trivial ADRs in `DECISIONS.md` until it exceeds 20 KB. | Blows past the 10 KB bootstrap budget, inflating KV-cache VRAM. | **Compaction Protocol**: Stabilized decisions are consolidated into core axioms in `PROJECT_STATE.json` / `PROJECT.md`, moving historical notes to `DECISIONS_ARCHIVE.md`. |
257
+ | **3. Concurrent State Corruption** | Multiple parallel subagents writing to `PROJECT_STATE.json` simultaneously. | Partial or corrupt JSON writes (`JSONDecodeError`). | **Atomic Write Engine**: `memory.py` always writes to a temporary file (`.tmp.<pid>`) and performs an atomic POSIX `os.replace` rename. |
258
+ | **4. Accidental Full-Scan Drift** | Agent invokes unrestricted `find .` or recursive grep across `node_modules` / `venv`. | Floods context window with 100k+ tokens, degrading model reasoning (Lost-in-the-Middle). | **Strict GPS Routing**: Agents must query `PROJECT_MAP.json` first to get exact file paths for the active domain only. |
259
+ | **5. Phantom Commit Binding** | Agent records a completed task in ledger without committing code to git first. | State claims task is verified, but git HEAD points to uncommitted or non-existent commit. | **Git Verification Guard**: `memory.py validate` checks `git rev-parse HEAD` against recorded hashes and rejects uncommitted state. |
260
+
261
+ ---
262
+
263
+ ## ❓ Frequently Asked Questions (FAQ)
264
+
265
+ <details>
266
+ <summary><b>1. Which AI coding agents are compatible with Project Memory V2.0?</b></summary>
267
+
268
+ Project Memory V2.0 is designed as a model-agnostic, open specification. It works out-of-the-box with:
269
+ - **Hermes Agent**
270
+ - **Claude Code (Anthropic)**
271
+ - **OpenAI Codex**
272
+ - **OpenCode**
273
+ - **Cursor / Aider / Custom LLM Agent Frameworks**
274
+ </details>
275
+
276
+ <details>
277
+ <summary><b>2. Does `.agent/` require external Python packages or third-party dependencies?</b></summary>
278
+
279
+ **No.** The core engine (`memory.py` and `bootstrap.py`) is written in 100% pure Python 3.11+ standard library (`json`, `subprocess`, `hashlib`, `argparse`, `pathlib`). There are zero external `pip` dependencies required to run status checks, validation, or state checkpointing.
280
+ </details>
281
+
282
+ <details>
283
+ <summary><b>3. How does Project Memory V2.0 prevent context drift across long sessions?</b></summary>
284
+
285
+ Context drift occurs when agents rely on transient chat memory that gets truncated or diluted. Project Memory moves ground-truth memory out of the prompt window and into the filesystem:
286
+ - Architecture rules are locked in `DECISIONS.md`.
287
+ - Historical progress is permanently recorded in the immutable `TASK_LEDGER.jsonl`.
288
+ - The active session only reads `< 2.5 KB` of state from `BOOT.md`, eliminating hallucination.
289
+ </details>
290
+
291
+ <details>
292
+ <summary><b>4. Can I apply Project Memory V2.0 to an existing, established repository?</b></summary>
293
+
294
+ **Yes.** Simply run:
295
+ ```bash
296
+ python3 bootstrap.py --target /path/to/existing-repo --domains "auth,api,db,ui"
297
+ ```
298
+ Then define your module mappings in `.agent/PROJECT_MAP.json` and set your current phase in `.agent/PROJECT_STATE.json`.
299
+ </details>
300
+
301
+ <details>
302
+ <summary><b>5. How can I enforce memory integrity in CI/CD pipelines?</b></summary>
303
+
304
+ Add `python3 .agent/memory.py validate` to your GitHub Actions workflow or pre-commit hooks. It will fail with exit code `1` if:
305
+ - Bootstrap context exceeds 10 KB budget.
306
+ - JSON state files fail schema validation.
307
+ - Uncommitted or unverified changes violate the git commit baseline.
308
+ </details>
309
+
310
+ ---
311
+
312
+ ## πŸ‘€ Author & Maintainer
313
+
314
+ **Justin** β€” [@chauvuusvn](https://github.com/chauvuusvn)
315
+ *Architected for high-autonomy multi-agent ecosystems and lean AI workflows.*
316
+
317
+ ---
318
+
319
+ ## πŸ§ͺ License
320
+ Apache-2.0 / MIT. Created for high-autonomy agent workflows.
@@ -0,0 +1,291 @@
1
+ # ZeroScan (`.agent/`) β€” Project Memory V2.1
2
+
3
+ [![CI Suite](https://github.com/chauvuusvn/zeroscan/actions/workflows/ci.yml/badge.svg)](https://github.com/chauvuusvn/zeroscan/actions/workflows/ci.yml)
4
+ [![PyPI - Version](https://img.shields.io/badge/pypi-v2.1.0-blue.svg)](https://pypi.org/project/zeroscan/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
+ [![Python: 3.9+](https://img.shields.io/badge/Python-3.9%2B-blue.svg)](https://www.python.org/)
7
+ [![Context Budget](https://img.shields.io/badge/Context%20Budget-%3C=10%20KB-success.svg)](https://github.com/chauvuusvn/zeroscan)
8
+
9
+ ```bash
10
+ # Instant Installation via pip
11
+ pip install zeroscan
12
+
13
+ # Instant Bootstrap in any repository
14
+ zeroscan-bootstrap --name "my-awesome-project" --mission "Build scalable AI apps"
15
+ ```
16
+
17
+ [ πŸ‡¬πŸ‡§ English ](README.md) | [ πŸ‡»πŸ‡³ TiαΊΏng Việt ](README.vi.md) | [ πŸ“˜ Usage Guide ](USAGE_GUIDE.md) | [ πŸ“• HΖ°α»›ng dαΊ«n sα»­ dα»₯ng ](HUONG_DAN_SU_DUNG.md) | [ πŸš€ Deep-Dive Article ](articles/zero-scan-llm-vram-optimization.md)
18
+
19
+ > **The Zero-Scan, Git-Aware Context Engine for AI Coding Agents**
20
+ > Compatible with Hermes Agent, Claude Code, OpenAI Codex, and OpenCode.
21
+
22
+ ---
23
+
24
+ ## 🌟 Overview
25
+
26
+ **Project Memory V2.0** is an open standard designed to eliminate context bloat, hallucination, and directory-crawling overhead in AI-driven software development.
27
+
28
+ Traditional coding agents waste tens of thousands of tokens scanning entire codebases upon startup. Project Memory replaces scanning with a lightweight, Git-bound **Level 0 Boot Anchor** (`BOOT.md` < 1 KB) and an architectural **GPS Map** (`PROJECT_MAP.json`), ensuring agents boot instantly with `<= 10 KB` of total context.
29
+
30
+ ---
31
+
32
+ ## πŸ’‘ Why It Saves 90–95% Tokens
33
+
34
+ ### 1. Zero-Scan Startup (Level 0 Boot Anchor)
35
+ Traditional agents ingest entire repositories on every session turn, easily burning 30,000–100,000+ tokens before writing a single line of code. With Project Memory, the agent reads **only `BOOT.md` (~1 KB / ~500 tokens)**, gaining immediate architectural clarity and task direction without exploring irrelevant directories.
36
+
37
+ ### 2. GPS Navigation via `PROJECT_MAP.json`
38
+ Instead of performing costly regex searches across the tree, agents query the structured domain map to resolve exact source and test file paths just-in-time. Irrelevant modules are never loaded into working context.
39
+
40
+ ### 3. Lean Multi-Agent Task Delegation
41
+ When an orchestrator agent delegates tasks to subagents or workers (e.g. specialized coding models), it passes only `BOOT.md` and `NEXT_TASK.md`. Worker agents operate in isolated, razor-sharp context windows without paying the token tax of the full repository.
42
+
43
+ ### πŸ“Š Token Consumption Comparison
44
+
45
+ | Lifecycle Stage | Traditional Approach (Full Scan) | Project Memory V2.0 (`.agent/`) | Token Savings |
46
+ |---|---|---|:---:|
47
+ | **Session Boot** | Ingest whole repo (30k–100k+ tokens) | Read `BOOT.md` (< 1 KB / ~500 tokens) | **~95%** |
48
+ | **Domain Navigation** | Recursive grep & tree traversal | Query `PROJECT_MAP.json` (< 3 KB) | **~90%** |
49
+ | **Worker Subagent Boot** | Re-read full repo per child agent | Load `NEXT_TASK.md` + target files | **~92%** |
50
+ | **Session Memory Drift** | Prompt bloat & hallucination | External append-only ledger & ADRs | **Zero Drift** |
51
+
52
+ > **πŸ“Œ Engineering Scope Note:** Token savings specifically measure context initialization, recursive directory crawling, and exploratory search overhead. Tokens required to author or modify actual code files depend naturally on the size of the generated diff.
53
+
54
+ ---
55
+
56
+ ## πŸ“ Standard `.agent/` Architecture
57
+
58
+ Every compliant project contains an `.agent/` directory with the following structure:
59
+
60
+ ```
61
+ .agent/
62
+ β”œβ”€β”€ BOOT.md # [Level 0] Ultra-light session anchor (< 1 KB / ~30 lines)
63
+ β”œβ”€β”€ PROJECT_STATE.json # [Level 1] Machine state tied to git verified_commit & metrics
64
+ β”œβ”€β”€ PROJECT_MAP.json # Codebase GPS: Maps functional domains to files & tests
65
+ β”œβ”€β”€ DECISIONS.md # Architectural Decision Records (ADRs) with [LOCKED] status
66
+ β”œβ”€β”€ TASK_LEDGER.jsonl # Immutable append-only record of completed tasks & evidence
67
+ β”œβ”€β”€ NEXT_TASK.md # Concrete active task spec, acceptance criteria & test commands
68
+ β”œβ”€β”€ MEMORY_PROTOCOL.md # The 10 Golden Rules for agent execution & evidence verification
69
+ └── memory.py # Pure Python 3.11+ zero-dependency engine (validate, checkpoint, status)
70
+ ```
71
+
72
+ ---
73
+
74
+ ## πŸš€ Quick Start: Scaffolding a New Project
75
+
76
+ ### Option A: Instant One-Liner (No Clone Required)
77
+ ```bash
78
+ curl -fsSL https://raw.githubusercontent.com/chauvuusvn/zeroscan/main/bootstrap.py | python3 - -n "Quantum Engine" --domains "engine,storage,network,api" --git-init
79
+ ```
80
+
81
+ ### Option B: Using local `bootstrap.py`
82
+ Use `bootstrap.py` to generate a standard `.agent/` memory system in any target repository:
83
+
84
+ ```bash
85
+ # Basic usage in current directory
86
+ python3 bootstrap.py
87
+
88
+ # Custom scaffolding for a specific project
89
+ python3 bootstrap.py \
90
+ --target /path/to/my-project \
91
+ --name "Quantum Engine" \
92
+ --mission "High-performance distributed event processing engine" \
93
+ --phase "Phase 1 - Core Architecture" \
94
+ --domains "engine,storage,network,api" \
95
+ --git-init
96
+ ```
97
+
98
+ ### CLI Arguments for `bootstrap.py`:
99
+ | Option | Short | Default | Description |
100
+ |---|---|---|---|
101
+ | `--target` | `-t` | `.` | Target project directory path |
102
+ | `--name` | `-n` | Directory name | Name of the project |
103
+ | `--mission` | `-m` | "Autonomous..." | High-level mission statement |
104
+ | `--phase` | `-p` | "Phase 1..." | Initial project phase name |
105
+ | `--domains` | `-d` | "core" | Comma-separated functional domain names |
106
+ | `--force` | `-f` | `False` | Overwrite existing `.agent/` directory |
107
+ | `--git-init` | | `False` | Run `git init` if target is not a git repo |
108
+
109
+ ---
110
+
111
+ ## πŸ› οΈ Operating `.agent/memory.py` in Target Projects
112
+
113
+ Once bootstrapped, agents interact with the memory engine directly:
114
+
115
+ ### 1. View Project Status & Budget
116
+ ```bash
117
+ python3 .agent/memory.py status
118
+ ```
119
+ Displays mission, current phase, active task, git HEAD vs verified commit, and context size budget breakdown.
120
+
121
+ ### 2. Validate Memory Integrity
122
+ ```bash
123
+ python3 .agent/memory.py validate
124
+ ```
125
+ Validates JSON schemas, git commit alignment, and verifies that `BOOTSTRAP_CONTEXT_BYTES <= 10,240 bytes` (10 KB).
126
+
127
+ ### 3. Checkpoint State Atomically & Synchronize Next Task
128
+ ```bash
129
+ python3 .agent/memory.py checkpoint \
130
+ --phase "Phase 2 - Feature Development" \
131
+ --status "IN_PROGRESS" \
132
+ --record-ledger \
133
+ --task-id "TASK-002" \
134
+ --task-summary "Completed user registration and password hashing" \
135
+ --evidence "pytest_exit_0_hash_abc123" \
136
+ --test-status "ALL_PASS (48/48)" \
137
+ --next-task "Build JWT Refresh Token Rotation" \
138
+ --next-task-id "TASK-003" \
139
+ --next-task-desc "Implement Redis-backed refresh token rotation with revoke whitelist"
140
+ ```
141
+ - Atomically updates `PROJECT_STATE.json`.
142
+ - Synchronously regenerates `BOOT.md`.
143
+ - Synchronously updates `NEXT_TASK.md` with acceptance criteria.
144
+ - Appends task evidence to `TASK_LEDGER.jsonl`.
145
+ - Recalculates exact context metrics.
146
+
147
+ ### 4. Append Architectural Decision (ADR)
148
+ ```bash
149
+ python3 .agent/memory.py add-decision \
150
+ --id "ADR-002" \
151
+ --title "Use SQLite with WAL mode for local cache" \
152
+ --status "LOCKED" \
153
+ --context "High concurrent read requirements without external DB services" \
154
+ --decision "Use embedded SQLite database with WAL and 64MB mmap" \
155
+ --consequences "Zero external runtime dependencies; single-node only"
156
+ ```
157
+
158
+ ---
159
+
160
+ ## πŸ”Œ Model Context Protocol (MCP) Server Integration
161
+
162
+ Zero-Scan includes a native **Model Context Protocol (MCP)** server for 1-click integration with **Cursor**, **Claude Desktop**, **Windsurf**, **Trae**, and **Claude Code**.
163
+
164
+ ### Setup in Claude Desktop (`claude_desktop_config.json`) / Cursor:
165
+ ```json
166
+ {
167
+ "mcpServers": {
168
+ "zeroscan": {
169
+ "command": "npx",
170
+ "args": ["-y", "zeroscan-mcp"]
171
+ }
172
+ }
173
+ }
174
+ ```
175
+ *Or using Python directly:*
176
+ ```json
177
+ {
178
+ "mcpServers": {
179
+ "zeroscan": {
180
+ "command": "python3",
181
+ "args": ["-m", "core.mcp_server"]
182
+ }
183
+ }
184
+ }
185
+ ```
186
+
187
+ ### πŸ› οΈ Exposed MCP Tools:
188
+ - `zeroscan_boot`: Instant Level 0 Boot Anchor (< 1 KB / ~500 tokens). Eliminates repository scanning.
189
+ - `zeroscan_get_map`: Structured architectural GPS map (`PROJECT_MAP.json`).
190
+ - `zeroscan_get_state`: Milestone progress, git hash alignment, and execution state.
191
+ - `zeroscan_get_next_task`: Immediate actionable next task (`NEXT_TASK.md`).
192
+ - `zeroscan_record_decision`: Append ADRs to `DECISIONS.md` across sessions.
193
+ - `zeroscan_validate`: Enforce `<= 10 KB` context budget.
194
+
195
+ ---
196
+
197
+ ## πŸ“Š Context Size Metrics & Limits
198
+
199
+ Project Memory V2.0 strictly enforces context budgets:
200
+
201
+ - **Bootstrap Context Budget (`BOOTSTRAP_CONTEXT_BYTES`)**:
202
+ $$\text{Size}(\text{BOOT.md}) + \text{Size}(\text{PROJECT_STATE.json}) + \text{Size}(\text{NEXT_TASK.md}) \le 10,240 \text{ bytes (10 KB)}$$
203
+ - **Zero Directory Traversal**: Agents read `BOOT.md` and `PROJECT_MAP.json` to navigate directly to relevant files instead of listing/reading entire trees.
204
+
205
+ ---
206
+
207
+ ## πŸ“œ The 10 Golden Rules
208
+
209
+ 1. **Level 0 Boot First**: Read `.agent/BOOT.md` on boot. Never recursive-scan codebase.
210
+ 2. **Verified Commit Binding**: All state transitions must reference valid git commit hashes.
211
+ 3. **GPS Routing via Map**: Use `PROJECT_MAP.json` to load only relevant domain files.
212
+ 4. **Immutable Locked Decisions**: Never violate `[LOCKED]` ADRs in `DECISIONS.md`.
213
+ 5. **Atomic State Checkpointing**: Use `memory.py checkpoint` for all updates.
214
+ 6. **Append-Only Ledger**: Never modify or truncate `TASK_LEDGER.jsonl`.
215
+ 7. **Single Active Task Focus**: `NEXT_TASK.md` governs the current single focus.
216
+ 8. **Evidence-Based Verification**: Only mark tasks complete after passing verified test suites.
217
+ 9. **Strict Context Budget**: Keep combined bootstrap files under 10 KB.
218
+ 10. **Memory Validation Guard**: Run `memory.py validate` in pre-commit / CI.
219
+
220
+ ---
221
+
222
+ ## ⚠️ Common Pitfalls & Anti-Patterns (and How to Avoid Them)
223
+
224
+ | Anti-Pattern / Pitfall | Root Cause | Impact | Zero-Scan Solution & Recovery |
225
+ |---|---|---|---|
226
+ | **1. The Stale State Trap** | Agent implements features but forgets to update `BOOT.md` / `PROJECT_STATE.json` before session exit. | Next agent session restarts from stale state, causing duplicate work or broken invariants. | **Session Exit Gate**: Enforce `python3 .agent/memory.py checkpoint` in pre-commit hooks and agent termination protocols before ending turns. |
227
+ | **2. Decisions Bloat Trap** | Accumulating dozens of trivial ADRs in `DECISIONS.md` until it exceeds 20 KB. | Blows past the 10 KB bootstrap budget, inflating KV-cache VRAM. | **Compaction Protocol**: Stabilized decisions are consolidated into core axioms in `PROJECT_STATE.json` / `PROJECT.md`, moving historical notes to `DECISIONS_ARCHIVE.md`. |
228
+ | **3. Concurrent State Corruption** | Multiple parallel subagents writing to `PROJECT_STATE.json` simultaneously. | Partial or corrupt JSON writes (`JSONDecodeError`). | **Atomic Write Engine**: `memory.py` always writes to a temporary file (`.tmp.<pid>`) and performs an atomic POSIX `os.replace` rename. |
229
+ | **4. Accidental Full-Scan Drift** | Agent invokes unrestricted `find .` or recursive grep across `node_modules` / `venv`. | Floods context window with 100k+ tokens, degrading model reasoning (Lost-in-the-Middle). | **Strict GPS Routing**: Agents must query `PROJECT_MAP.json` first to get exact file paths for the active domain only. |
230
+ | **5. Phantom Commit Binding** | Agent records a completed task in ledger without committing code to git first. | State claims task is verified, but git HEAD points to uncommitted or non-existent commit. | **Git Verification Guard**: `memory.py validate` checks `git rev-parse HEAD` against recorded hashes and rejects uncommitted state. |
231
+
232
+ ---
233
+
234
+ ## ❓ Frequently Asked Questions (FAQ)
235
+
236
+ <details>
237
+ <summary><b>1. Which AI coding agents are compatible with Project Memory V2.0?</b></summary>
238
+
239
+ Project Memory V2.0 is designed as a model-agnostic, open specification. It works out-of-the-box with:
240
+ - **Hermes Agent**
241
+ - **Claude Code (Anthropic)**
242
+ - **OpenAI Codex**
243
+ - **OpenCode**
244
+ - **Cursor / Aider / Custom LLM Agent Frameworks**
245
+ </details>
246
+
247
+ <details>
248
+ <summary><b>2. Does `.agent/` require external Python packages or third-party dependencies?</b></summary>
249
+
250
+ **No.** The core engine (`memory.py` and `bootstrap.py`) is written in 100% pure Python 3.11+ standard library (`json`, `subprocess`, `hashlib`, `argparse`, `pathlib`). There are zero external `pip` dependencies required to run status checks, validation, or state checkpointing.
251
+ </details>
252
+
253
+ <details>
254
+ <summary><b>3. How does Project Memory V2.0 prevent context drift across long sessions?</b></summary>
255
+
256
+ Context drift occurs when agents rely on transient chat memory that gets truncated or diluted. Project Memory moves ground-truth memory out of the prompt window and into the filesystem:
257
+ - Architecture rules are locked in `DECISIONS.md`.
258
+ - Historical progress is permanently recorded in the immutable `TASK_LEDGER.jsonl`.
259
+ - The active session only reads `< 2.5 KB` of state from `BOOT.md`, eliminating hallucination.
260
+ </details>
261
+
262
+ <details>
263
+ <summary><b>4. Can I apply Project Memory V2.0 to an existing, established repository?</b></summary>
264
+
265
+ **Yes.** Simply run:
266
+ ```bash
267
+ python3 bootstrap.py --target /path/to/existing-repo --domains "auth,api,db,ui"
268
+ ```
269
+ Then define your module mappings in `.agent/PROJECT_MAP.json` and set your current phase in `.agent/PROJECT_STATE.json`.
270
+ </details>
271
+
272
+ <details>
273
+ <summary><b>5. How can I enforce memory integrity in CI/CD pipelines?</b></summary>
274
+
275
+ Add `python3 .agent/memory.py validate` to your GitHub Actions workflow or pre-commit hooks. It will fail with exit code `1` if:
276
+ - Bootstrap context exceeds 10 KB budget.
277
+ - JSON state files fail schema validation.
278
+ - Uncommitted or unverified changes violate the git commit baseline.
279
+ </details>
280
+
281
+ ---
282
+
283
+ ## πŸ‘€ Author & Maintainer
284
+
285
+ **Justin** β€” [@chauvuusvn](https://github.com/chauvuusvn)
286
+ *Architected for high-autonomy multi-agent ecosystems and lean AI workflows.*
287
+
288
+ ---
289
+
290
+ ## πŸ§ͺ License
291
+ Apache-2.0 / MIT. Created for high-autonomy agent workflows.