agy-context-saver 0.0.0-stage → 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 paragon-ux
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 CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # Agy-Context-Saver 🛡️
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Model Context Protocol (MCP) Server & Lifecycle Governor for Google Antigravity (Powered by RTK)**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/agy-context-saver.svg)](https://www.npmjs.com/package/agy-context-saver)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+ [![Docs](https://img.shields.io/badge/docs-Zensical-purple.svg)](https://paragon-ux.github.io/agy-context-saver/)
8
+ [![Tests](https://img.shields.io/badge/tests-100%25%20passing-brightgreen.svg)](https://github.com/paragon-ux/agy-context-saver/actions)
9
+
10
+ `Agy-Context-Saver` is a high-performance lifecycle governor and zero-dependency MCP server purpose-built for **Google Antigravity** (`agy`), paired with **RTK (Rust Token Killer)** for transparent CLI output reduction.
11
+
12
+ It permanently eliminates session degradation, memory bloat, and context window exhaustion caused by **background task busy-wait polling**, **uncompressed terminal outputs**, and **raw JSON transcript reading**.
13
+
14
+ ---
15
+
16
+ ## Architectural Division of Responsibilities
17
+
18
+ ```text
19
+ Antigravity Agent
20
+ |
21
+ +------------------+------------------+
22
+ | |
23
+ run_command native inspection /
24
+ | lifecycle tools
25
+ v |
26
+ RTK hook |
27
+ | +---------+----------+
28
+ v | |
29
+ RTK execution inspection tools lifecycle
30
+ | | |
31
+ v v v
32
+ compact command output Agy DENY + route Agy governance
33
+ | |
34
+ v v
35
+ RTK read/grep/find Agy MCP
36
+ | |
37
+ +---------+----------+
38
+ |
39
+ v
40
+ useful context
41
+ ```
42
+
43
+ ### RTK Owns:
44
+ - Transparent `run_command` rewriting (`rtk rewrite`)
45
+ - Shell command output reduction (`git`, `pytest`, `cargo`, `npm`, `docker`, etc.)
46
+ - Canonical codebase inspection CLI (`rtk read`, `rtk grep`, `rtk find`, `rtk ls`, `rtk tree`)
47
+ - Focused diagnostic utilities (`rtk err`, `rtk summary`)
48
+
49
+ ### Agy Owns:
50
+ - Antigravity lifecycle management & Reactive Wakeup enforcement
51
+ - Background task polling governance & 5-strike circuit breaker
52
+ - Antigravity internal state protection (`.system_generated/`)
53
+ - Zero-JSON Markdown transcript extraction (`read_transcript`, `query_transcript`)
54
+ - Subagent delegation formulation (`subagent_brief`)
55
+ - Benchmark and evaluation artifact mutation protection
56
+
57
+ ---
58
+
59
+ ## The Core Problems Solved
60
+
61
+ 1. **The Polling Trap**: When shell tasks detach to background jobs (`task-XYZ`), agents waste tokens repeatedly polling `manage_task(Action='status')` or scheduling artificial timers. Agy enforces native **Reactive Wakeup** (`<SYSTEM_MESSAGE>`).
62
+ 2. **The Terminal Bloat Trap**: Routine test runs and git operations dump hundreds of lines of noise into context. RTK compresses these outputs natively before they enter model context.
63
+ 3. **The Raw Transcript Trap**: Reading `transcript.jsonl` dumps megabytes of raw JSON into context. Agy blocks direct reads of `.system_generated` and provides high-density Markdown streaming tools.
64
+ 4. **Native Inspection Bypass**: Native inspection tools (`view_file`, `grep_search`, `find_by_name`, `list_dir`) bypass token reduction. Agy hard-routes workspace inspection to RTK's canonical CLI (`rtk read`, `rtk grep`, `rtk find`, `rtk ls`).
65
+
66
+ ---
67
+
68
+ ## Quickstart (Instant Install)
69
+
70
+ Install and synchronize the governor and RTK across your Antigravity environment:
71
+
72
+ ```bash
73
+ # Fastest: one-line registration via npx
74
+ npx agy-context-saver install
75
+
76
+ # Or locally from this repository
77
+ npm run setup
78
+
79
+ # Audit health across all layers at any time
80
+ npm run status
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Key Capabilities
86
+
87
+ - **Transparent RTK Rewriting**: Native `run_command` calls are automatically rewritten (e.g. `pytest` $\to$ `rtk pytest`) via Antigravity PreToolUse hooks.
88
+ - **Canonical Codebase Inspection**:
89
+ - `rtk read <file>`: Read file with intelligent token filtering and line ranges.
90
+ - `rtk find <path>`: Compact file search tree and directory listing (cross-platform, works on Windows & POSIX).
91
+ - Search by platform:
92
+ - **Windows**: `rtk rg "<pattern>" .` (explicit target `.` prevents child process stdin stalls) or `rg "<pattern>" .`.
93
+ - **POSIX / Linux / macOS**: `rtk grep "<pattern>"` or `rtk rg "<pattern>"`.
94
+ - Directory listing by platform:
95
+ - **Windows**: `rtk find <path>` or PowerShell `dir` / `Get-ChildItem`. (Avoid `rtk ls` / `rtk tree` on Windows as they rely on POSIX binaries/flags).
96
+ - **POSIX / Linux / macOS**: `rtk ls <path>` or `rtk tree`.
97
+ - `rtk err <cmd>`: Run command and show only errors/warnings.
98
+ - `rtk summary <cmd>`: Run command and produce a 2-line heuristic summary.
99
+ - **Antigravity Special Files Safe Harbor**: Direct `view_file` access to `SKILL.md`, brain artifacts, and config files is preserved.
100
+ - **Protected Internal State**: Root-based guard prevents reading `.system_generated/` (transcripts, task logs, progress).
101
+ - **Session-Wide Lifecycle Ledger**: Polling checks are tracked globally per session; changing task IDs or waiting does not reset governance.
102
+ - **Zero-JSON Transcript Streaming**: Stream conversation turns without raw JSON syntax using `read_transcript` and `query_transcript`.
103
+
104
+ ---
105
+
106
+ ## Zero-Guesswork Testing & Verification Playbook
107
+
108
+ To cleanly test every layer of the framework without guesswork or interactive stalls:
109
+
110
+ ### 1. Audit Live Registration
111
+ ```bash
112
+ npm run status
113
+ # or
114
+ node mcp/index.js status
115
+ ```
116
+ *Confirms that all 4 integration layers (Plugin link, Lifecycle Hook, MCP Server, Schemas) and RTK are active.*
117
+
118
+ ### 2. Run Complete Automated Test Suite
119
+ ```bash
120
+ npm test
121
+ ```
122
+ *Runs all 5 test suites (28 hook tests, MCP protocol tests, E2E probes, installed verification, lifecycle rollback).*
123
+
124
+ ### 3. Run Targeted Tests Individually
125
+ ```bash
126
+ # Governance hook unit tests (28 closed-topology tests)
127
+ node tests/test-hook.mjs
128
+
129
+ # MCP server protocol & method tests
130
+ node tests/test-mcp.mjs
131
+
132
+ # End-to-end edge case & probe tests
133
+ node tests/test-e2e-probes.mjs
134
+
135
+ # Live installed environment verification
136
+ node tests/test-installed-verification.mjs
137
+
138
+ # Clean install/uninstall/restore lifecycle test
139
+ node tests/test-lifecycle-rollback.mjs
140
+ ```
141
+
142
+ ### 4. Test MCP Tools from Antigravity Agent
143
+ - `get_installation_status`: Call with `{}` to audit all 4 layers + RTK.
144
+ - `check_context_health`: Call with `{ "transcriptPath": "<path-to-transcript.jsonl>" }`.
145
+ - `read_transcript`: Call with `{ "conversationId": "<uuid>", "lastTurns": 3, "mode": "compact" }`.
146
+ - `query_transcript`: Call with `{ "conversationId": "<uuid>", "query": "<term>", "summaryOnly": true }`.
147
+ - `subagent_brief`: Call with `{ "objective": "<goal>", "scopeFiles": ["..."] }`.
148
+
149
+ ### 5. Testing Pitfalls & Anti-Patterns to Avoid
150
+ - ❌ **Do NOT run `npm start` or `node mcp/index.js` interactively**: It starts the stdio JSON-RPC daemon and waits indefinitely on `stdin`.
151
+ - ❌ **Do NOT loop on `manage_task(Action='status')`**: Polling triggers the session ledger circuit breaker at 5 cumulative denials. Rely on native Reactive Wakeup (`<SYSTEM_MESSAGE>`).
152
+ - ❌ **Do NOT run `npm run uninstall` as a standalone check**: It unregisters the live hook. If run, immediately re-run `npm run setup`.
153
+ - ❌ **On Windows, do NOT omit the directory in `rtk rg`**: Always run `rtk rg "<pattern>" .` to avoid stdin pipe blocking.
154
+
155
+ ---
156
+
157
+ ## Available MCP Tools
158
+
159
+ 1. `check_context_health`: Diagnoses conversation transcript turn budgets, payload size, RTK status, and polling loops.
160
+ 2. `subagent_brief`: Formulates scope-isolated prompts for delegated subagents.
161
+ 3. `read_transcript`: Reads recent conversation history in clean Markdown format (compact/full).
162
+ 4. `query_transcript`: Forensic filtering and regex search engine for conversation logs.
163
+ 5. `get_installation_status`: Inspects live Antigravity plugin link, hook, MCP server, tool schemas, and RTK binary.
164
+ 6. `sync_installation`: Re-verifies and repairs all integration layers in ~25ms.
165
+
166
+ ---
167
+
168
+ ## License
169
+
170
+ MIT License. Copyright (c) 2026 paragon-ux.
package/hooks.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "agy-context-saver": {
3
+ "PreToolUse": [
4
+ {
5
+ "matcher": "manage_task|run_command|schedule",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node scripts/execution-guard-hook.mjs",
10
+ "timeout": 5
11
+ }
12
+ ]
13
+ }
14
+ ]
15
+ }
16
+ }
package/install.ps1 ADDED
@@ -0,0 +1,42 @@
1
+ # Agy-Context-Saver Universal Installer for Windows
2
+ # Installs hook script, wrapper, and registers in ~/.gemini/config/hooks.json & mcp_config.json
3
+
4
+ $ErrorActionPreference = "Stop"
5
+
6
+ $GeminiConfigDir = [System.IO.Path]::Combine($env:USERPROFILE, ".gemini", "config")
7
+ $DestHook = [System.IO.Path]::Combine($GeminiConfigDir, "scripts", "execution-guard-hook.mjs")
8
+
9
+ # 1. Ensure ~/.gemini/config exists
10
+ if (-not (Test-Path $GeminiConfigDir)) {
11
+ New-Item -ItemType Directory -Path $GeminiConfigDir -Force | Out-Null
12
+ }
13
+
14
+ # 2. Create node.cmd wrapper in ~/.gemini/config (prevents Windows cmd quote issues)
15
+ $NodeCmdPath = [System.IO.Path]::Combine($GeminiConfigDir, "node.cmd")
16
+ $NodeCmdLines = @(
17
+ '@echo off',
18
+ 'setlocal',
19
+ 'set "ARGS=%*"',
20
+ '',
21
+ 'echo %ARGS% | findstr /i "execution-guard" >nul',
22
+ 'if %errorlevel% equ 0 (',
23
+ " `"C:\Program Files\nodejs\node.exe`" `"$DestHook`"",
24
+ ' exit /b %errorlevel%',
25
+ ')',
26
+ '',
27
+ 'echo %ARGS% | findstr /i "waymark" >nul',
28
+ 'if %errorlevel% equ 0 (',
29
+ ' "C:\Program Files\nodejs\node.exe" "%USERPROFILE%\Desktop\Frameworks\Deepseek-Project\Waymark\scripts\hooks\waymark-compact-hook.mjs"',
30
+ ' exit /b %errorlevel%',
31
+ ')',
32
+ '',
33
+ 'echo {"decision": "allow"}',
34
+ 'exit /b 0'
35
+ )
36
+ $NodeCmdContent = $NodeCmdLines -join "`r`n"
37
+ Set-Content -Path $NodeCmdPath -Value $NodeCmdContent -Encoding ASCII
38
+ Write-Host "[OK] Node wrapper installed to: $NodeCmdPath" -ForegroundColor Green
39
+
40
+ # 3. Run cross-platform registration engine
41
+ $RegisterScript = [System.IO.Path]::Combine($PSScriptRoot, "scripts", "install-register.mjs")
42
+ & node "$RegisterScript"
package/install.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ # Agy-Context-Saver Zero-Delay Installer for macOS & Linux
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ node "$SCRIPT_DIR/scripts/install-register.mjs" "$@"