# ctx Pi context blowup fuse for oversized `bash` output. `ctx` does one thing: 1. watches `bash` tool results 2. if output is too large, stores full text off-context in SQLite FTS 3. replaces visible output with a small `ctx:stored ...` pointer 4. exposes `ctx` search for that stored output It does **not** run shell/JS/Python jobs. It does **not** inspect files. Use normal Pi tools for normal work. ## Tool ### `ctx` Search output previously stored by ctx: ```json { "query": "TARGET_EVENT", "source": "bash:178810b1:42", "limit": 3 } ``` Range-read known lines, like `read`: ```json { "source": "bash:178810b1:42", "offset": 201, "limit": 200 } ``` Use the exact `source` label from `ctx:stored`. ## Thresholds Defaults: ```text PI_CTX_LARGE_OUTPUT_THRESHOLD=20000 PI_CTX_ERROR_OUTPUT_THRESHOLD=5000 ``` Meaning: - successful `bash` output > 20KB → stored - failed `bash` output > 5KB → stored + error-oriented preview - smaller output → unchanged ## Storage Default DB path: ```text ${XDG_STATE_HOME:-~/.local/state}/pi/ctx/-.db ``` Platform fallbacks: ```text Linux: ${XDG_STATE_HOME:-~/.local/state}/pi/ctx/ macOS: ~/Library/Application Support/pi/ctx/ Windows:%LOCALAPPDATA%\\pi\\ctx\\ ``` `ctx` still requires the active Pi session file, but only to derive the session id. It does not store under `sessionManager.getSessionDir()`, because that can mix unrelated session runtime data. Override for tests/debug: ```bash PI_CTX_DB_PATH=/tmp/ctx.db ``` In benchmark runs this is inside sandbox HOME: ```text /home/bench/.local/state/pi/ctx/-.db ``` The DB contains: - `sources` table: labels, byte counts, metadata - `chunks_fts` FTS5 table: chunked searchable output ## Example flow ```text bash ./dump.sh → ctx:stored bash:178810b1:42 (2085.9KB, 135 chunks). Stored output is not in the workspace. Call the ctx tool with {"query":"...","source":"bash:178810b1:42"}. ctx {"query":"TARGET_EVENT","source":"bash:178810b1:42"} → matching snippets only ctx {"source":"bash:178810b1:42","offset":201,"limit":200} → exact line range ```