antigravity-plugin-context-mode 1.1.0 → 1.2.1
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 +28 -0
- package/README.md +47 -40
- package/hooks/pre-tool-use.js +302 -32
- package/hooks.json +1 -1
- package/lib/store.js +280 -57
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.js +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `antigravity-plugin-context-mode` will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.2.1] - 2026-11-15
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **CI Test Database Contention (`CONTEXT_MODE_DB_PATH`)**: Updated `getDefaultDbPath()` in `lib/store.js` to respect `process.env.CONTEXT_MODE_DB_PATH`, and configured `tests/test_mcp.js` and `tests/test_hooks.js` to run in dedicated isolated temporary directories. Prevents database lock contention (`SQLITE_BUSY`) during concurrent test execution on multi-core CI runners.
|
|
9
|
+
- **SQLite Busy Timeout**: Added `PRAGMA busy_timeout = 5000;` to database initialization with fallback handling to ensure robust concurrency when multiple processes interact with SQLite in WAL mode.
|
|
10
|
+
- **Category Exemption Group Toggles**: Replaced the long list of individual file exemption chips in the dashboard with clean, one-click category pills (`Images`, `Documents`, `3D Models`, `Music`, `Video`, `Archives`, and `Source Code`). All binary categories default to enabled, with Source Code disabled by default. Added optimistic UI state switching in `toggleCategory()` for instant feedback upon click.
|
|
11
|
+
- **Streamlined Custom File Types**: Restricted the dashboard's exemption tags container to only display user-added custom file types (e.g. `.csv`, `.parquet`, `.log`) with quick removal buttons (`×`).
|
|
12
|
+
- **Status Banner Cleanup**: Replaced `"Live Telemetry"` with **`"Showing stats for: <SCOPE>"`** and removed distracting animations (`animate-ping`, `animate-pulse`) for steady, non-blinking visual indicators.
|
|
13
|
+
- **Dynamic Upper-Right Version Badge**: Displays the active plugin version badge (`v1.2.1`) in the top-right header cluster of the dashboard, populated dynamically from `package.json` via `/api/stats`.
|
|
14
|
+
- **Documentation & Formatting Polishing**: Removed all LaTeX math syntax from `README.md`, replacing it with standard Unicode (`≤ 50 lines`, `≤ 200 lines`, `≤ 800 lines`), and consolidated redundant configuration tables.
|
|
15
|
+
|
|
16
|
+
## [1.2.0] - 2026-11-15
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- **Quoted Path Stripping in `PreToolUse`**: Added path argument sanitization to strip enclosing quotes (`"..."`, `'...'`), decode URI schemes (`file:///`), and trim line anchor fragments (`#L...`), preventing `fs.existsSync` failures on Windows when tool calls pass quoted file paths.
|
|
20
|
+
- **Interception Journaling & Telemetry**: Added event journaling on all blocked `read_file` and `run_command` tool calls directly into SQLite (`events` table). Interceptions now immediately update `tokensPreserved`, `keptOutBytes`, `reductionRate`, and the Prompt Payload Comparison bar in the sidecar dashboard.
|
|
21
|
+
- **Dynamic Command Inspection (No Hardcoded Extension Whitelist)**: Refactored `run_command` in `PreToolUse` (`inspectCommand`) to eliminate hardcoded extension regexes completely. Commands invoking `cat`, `type`, `Get-Content`, or `gc` now dynamically extract target paths, check them against the active SQLite cutoff, and respect user-configured exemptions. Safe small files ($\le$ cutoff) and bounded commands (`-Head`, `| Select-Object -First`) are allowed, while wildcard and unpaged dumps are blocked.
|
|
22
|
+
- **UTF-16 & Known Text Exemption Safeguard**: Added `KNOWN_TEXT_EXTENSIONS` check and UTF-16/UTF-8 BOM header inspection to prevent text and code files (such as `.cs` and `.md`) containing null bytes from being misidentified as binary files and bypassing size cutoffs.
|
|
23
|
+
- **Live Interception Feed in Dashboard**: Updated the "Recent Indexed Sources & Interceptions" dashboard panel to display blocked calls (`🛡️ Blocked <tool>: <path>`) with exact saved token metrics alongside indexed FTS5 sources.
|
|
24
|
+
- **Renamed 'Sandbox Cap' to 'Preview Limit'**: Replaced the confusing "Sandbox Cap" label with **`PREVIEW LIMIT`**, clearly indicating the maximum preview slice of command and script output returned into the chat.
|
|
25
|
+
- **Clickable 'Active' / 'Paused' Toggle**: Turned the status badge into an interactive toggle button. Users can click to switch Context Mode between **Active** (pulsing green dot) and **Paused** (amber dot). When paused, the `PreToolUse` hook allows all tool calls through without size checks or command interception, persisting the paused state across active scopes in SQLite.
|
|
26
|
+
- **Fixed Feed Width Truncation**: Removed the hardcoded `max-w-[210px]` container constraint and arbitrary string slice in the dashboard feed, replacing it with responsive `min-w-0 flex-1` flex sizing and clean path formatting (`formatItemPath`) so file and command paths scale dynamically to the full width of the dashboard panel.
|
|
27
|
+
- **Reformatted Metric Rows & Sidebar Layout**: Redesigned the 4 performance metrics into sleek, compact horizontal key-value rows inside a single card (labels on the left, values right-aligned) with subtle hairline dividers. This replaces the tall vertical 12-line card stack in normal sidebars with an information-dense, space-efficient ~140px card that naturally scales to 2 columns on wide screens without wrapping or wasting space.
|
|
28
|
+
- **Unified Lifecycle Gates & System Health (Moved to Bottom)**: Combined `Active Lifecycle Gates` and `Engine & Storage Health` into a single cohesive reference card with an inline `HEALTHY` badge, streamlined gate checkmarks, and compact engine specs. Moved this card to the very bottom of the dashboard so actively changing interactive panels (metrics, exemptions, search, and the live interception feed) remain prominently visible at the top.
|
|
29
|
+
- **Dual-Color Single Progress Bar**: Consolidated the separate raw dump and sandboxed slice progress bars into a single, compact dual-color progress bar placed directly beneath the Live Telemetry status banner. It visually depicts % of context saved in emerald green (`#00e599`) and prompt payload in rose (`#f43f5e`), with live `% saved` text. Removed the redundant middle comparison card and sub-labels since the metric cards directly below inform the user of all exact figures.
|
|
30
|
+
- **User-Friendly Dashboard Terminology**: Replaced cryptic architecture jargon (such as `"SQLite FTS5 Reciprocal Rank Fusion & Sandbox Execution"`, `"Porter BM25 + Trigram RRF"`, and `"Tokens diverted from LLM"`) with clear, value-focused explanations highlighting token savings, context reduction, and keeping LLMs smart, focused, and less forgetful.
|
|
31
|
+
- **Context-Focused Language & Removal of Log Fixation**: Changed card sub-labels from confusing "prompt bloat" phrasing to **`"Context reduced by <size>"`** and **`"Context window preserved"`**, clarifying that user prompts are never deleted or truncated. Removed all narrow fixations on "logs" throughout tooltips, input placeholders, and lifecycle gates to accurately represent all large files, code, and terminal outputs.
|
|
32
|
+
|
|
5
33
|
## [1.1.0] - 2026-11-14
|
|
6
34
|
|
|
7
35
|
### Added
|
package/README.md
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
1
|
# Antigravity Context Mode
|
|
2
2
|
|
|
3
|
-
> **Stop context bloat. Save 90%+ of your prompt tokens. Keep your agent fast, focused, and
|
|
3
|
+
> **Stop context bloat. Save 90%+ of your prompt tokens. Keep your agent fast, focused, and less forgetful.**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/antigravity-plugin-context-mode)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[]()
|
|
8
8
|
[]()
|
|
9
9
|
|
|
10
|
-
**Antigravity Context Mode** is a free, local-first plugin built specifically for the **Google Antigravity App**. It prevents terminal commands, build
|
|
10
|
+
**Antigravity Context Mode** is a free, local-first plugin built specifically for the **Google Antigravity App**. It prevents terminal commands, build outputs, multi-megabyte source files, and massive datasets from flooding your conversation history — saving thousands of tokens per turn and stopping "agent amnesia" in its tracks.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
|
-
<img width="
|
|
13
|
+
<img width="817" height="690" alt="Antigravity Context Mode Dashboard" src="https://github.com/user-attachments/assets/dbf6d666-58d0-48f3-bc02-9783acf3fb37" />
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## The Problem: Context Window Bloat
|
|
16
16
|
|
|
17
17
|
When an AI coding agent runs tools, standard workflows dump everything directly into your conversation history:
|
|
18
18
|
|
|
19
19
|
* Running `Get-Content Logs/Editor.log` dumps **65 KB (~16,000 tokens)** into your prompt.
|
|
20
|
-
* Running test suites or
|
|
20
|
+
* Running test suites, compiler outputs, or git diffs dumps **100+ KB** of repetitive text.
|
|
21
21
|
* Reading large source files or documentation dumps **thousands of lines** of irrelevant boilerplate.
|
|
22
22
|
|
|
23
23
|
### Why this hurts:
|
|
24
|
-
1. **Agent Amnesia**: Important system instructions and
|
|
25
|
-
2. **
|
|
26
|
-
3. **Burned Quota &
|
|
24
|
+
1. **Agent Amnesia**: Important system instructions, user constraints, and earlier architectural decisions get drowned out ("lost in the middle").
|
|
25
|
+
2. **Slower Responses**: Model evaluation and generation times climb as the context window fills up.
|
|
26
|
+
3. **Burned Quota & Ceilings**: You hit model context limits and rate limits after only a few turns.
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
|
30
|
-
##
|
|
30
|
+
## The Solution: How Context Mode Works
|
|
31
31
|
|
|
32
32
|
```text
|
|
33
33
|
┌────────────────────────────────────────────────────────────────────────┐
|
|
34
34
|
│ ANTIGRAVITY AGENT │
|
|
35
35
|
└───────────────────────────────────┬────────────────────────────────────┘
|
|
36
36
|
│
|
|
37
|
-
Tool Call (e.g. read large
|
|
37
|
+
Tool Call (e.g. read large file/command)
|
|
38
38
|
▼
|
|
39
39
|
┌────────────────────────────────────────────────────────────────────────┐
|
|
40
40
|
│ PRE-TOOL-USE LIFECYCLE HOOK GATE │
|
|
41
|
-
│ • Blocks unbounded dumps (cat
|
|
41
|
+
│ • Blocks unbounded dumps (cat, Get-Content, git diff) │
|
|
42
42
|
│ • Enforces 8 KB cutoff for un-paged file reads │
|
|
43
|
+
│ • Automatically exempts binary media, documents, & prompt attachments │
|
|
43
44
|
└───────────────────┬────────────────────────────────┬───────────────────┘
|
|
44
45
|
│ │
|
|
45
46
|
Under 8 KB (Safe) Over 8 KB (Blocked)
|
|
@@ -54,20 +55,20 @@ When an AI coding agent runs tools, standard workflows dump everything directly
|
|
|
54
55
|
└───────────────────────────────────┘
|
|
55
56
|
│
|
|
56
57
|
▼
|
|
57
|
-
Returns only the
|
|
58
|
-
|
|
58
|
+
Returns only the filtered,
|
|
59
|
+
relevant answer to the chat!
|
|
59
60
|
```
|
|
60
61
|
|
|
61
|
-
1. **Smart Lifecycle Gating (`hooks.json`)**: Before a command or file read executes, Context Mode checks if it will cause a
|
|
62
|
-
2. **"Thinking in Code" (`ctx_execute`)**: Instead of reading a 5,000-line log into memory, the agent executes a
|
|
63
|
-
3. **SQLite FTS5 Storage (`ctx_search`, `ctx_index`)**:
|
|
64
|
-
4. **Live Sidecar Dashboard**: A native side pane right inside the Antigravity App that displays
|
|
62
|
+
1. **Smart Lifecycle Gating (`hooks.json`)**: Before a command or file read executes, Context Mode checks if it will cause a context flood. If it exceeds 8 KB or attempts an unbounded file dump, the hook intercepts it and guides the agent to query or sandbox the data instead.
|
|
63
|
+
2. **"Thinking in Code" (`ctx_execute`)**: Instead of reading a 5,000-line log into memory, the agent executes a concise local script (Node.js, Python, or PowerShell). The script filters the data in **50 ms** and returns *only* the specific answer or error to the conversation.
|
|
64
|
+
3. **Local SQLite FTS5 Storage (`ctx_search`, `ctx_index`)**: Raw outputs are saved safely on your local disk in `~/.context-mode/context.db`. The agent uses reciprocal rank fusion search to fetch only the exact snippets it needs.
|
|
65
|
+
4. **Live Sidecar Dashboard**: A native side pane right inside the Antigravity App that displays real-time context savings, lets you toggle file categories on the fly, and search indexed data with a click.
|
|
65
66
|
|
|
66
67
|
---
|
|
67
68
|
|
|
68
|
-
##
|
|
69
|
+
## Proven Results
|
|
69
70
|
|
|
70
|
-
Tested live on real
|
|
71
|
+
Tested live on real-world build logs, source files, and datasets in the Antigravity App:
|
|
71
72
|
|
|
72
73
|
| Operation | Without Context Mode | With Context Mode | Savings |
|
|
73
74
|
| :--- | :---: | :---: | :---: |
|
|
@@ -77,7 +78,7 @@ Tested live on real Unity 6.6 build and engine logs in the Antigravity App:
|
|
|
77
78
|
|
|
78
79
|
---
|
|
79
80
|
|
|
80
|
-
##
|
|
81
|
+
## Quick Start & Installation
|
|
81
82
|
|
|
82
83
|
### Option 1: Global User Install (Recommended)
|
|
83
84
|
Installs Context Mode for all your projects and conversations:
|
|
@@ -105,26 +106,35 @@ npm install -g antigravity-plugin-context-mode
|
|
|
105
106
|
|
|
106
107
|
---
|
|
107
108
|
|
|
108
|
-
##
|
|
109
|
+
## Live Auxiliary Sidecar Dashboard
|
|
109
110
|
|
|
110
111
|
Context Mode includes a native web dashboard that opens directly in Antigravity's **Auxiliary (Side) Pane**:
|
|
111
112
|
|
|
112
113
|
* **One-Click Open Pill:** Click `[Open Context Mode Dashboard](sidecar://antigravity-plugin-context-mode/dashboard/)` in chat anytime.
|
|
114
|
+
* **Active / Paused Toggle:** Click the status pill in the top header to instantly pause protection when you intentionally need un-gated operations, and click again to re-activate.
|
|
115
|
+
* **Dynamic Version Badge:** Automatically reflects the active plugin version in the top-right header.
|
|
116
|
+
* **Context Saved Progress Bar:** Visual indicator displaying the exact percentage of context window preserved.
|
|
113
117
|
* **3-Way Scope Toggle:** Seamlessly inspect telemetry at three distinct levels:
|
|
114
|
-
* **Conversation**:
|
|
115
|
-
* **Session**: Metrics aggregated across all conversations since the app restarted
|
|
118
|
+
* **Conversation**: Metrics strictly for the active chat; clean slate on new conversations.
|
|
119
|
+
* **Session**: Metrics aggregated across all conversations since the app restarted.
|
|
116
120
|
* **Lifetime**: All-time cumulative database metrics and persistent totals.
|
|
117
|
-
* **
|
|
118
|
-
* **
|
|
119
|
-
* **
|
|
120
|
-
* **
|
|
121
|
-
* **
|
|
122
|
-
* **
|
|
121
|
+
* **File Category Toggles:** Clean, one-click pills for grouping exemptions without reading massive lists:
|
|
122
|
+
* **Images** (`.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.svg`, `.bmp`, `.ico`, `.tiff`, `.psd`) — *Enabled by default*
|
|
123
|
+
* **Documents** (`.pdf`, `.docx`, `.doc`, `.xlsx`, `.xls`, `.pptx`, `.ppt`, `.odt`, `.rtf`) — *Enabled by default*
|
|
124
|
+
* **3D Models** (`.blend`, `.fbx`, `.obj`, `.gltf`, `.glb`, `.stl`, `.dae`, `.3ds`, `.step`, `.iges`) — *Enabled by default*
|
|
125
|
+
* **Music** (`.mp3`, `.wav`, `.ogg`, `.flac`, `.aac`, `.m4a`, `.wma`, `.midi`) — *Enabled by default*
|
|
126
|
+
* **Video** (`.mp4`, `.mov`, `.avi`, `.mkv`, `.webm`, `.flv`, `.wmv`, `.m4v`) — *Enabled by default*
|
|
127
|
+
* **Archives** (`.zip`, `.tar`, `.gz`, `.7z`, `.rar`, `.wasm`) — *Enabled by default*
|
|
128
|
+
* **Source Code** (`.js`, `.ts`, `.py`, `.rs`, `.go`, `.java`, `.c`, `.cpp`, `.cs`, `.html`, `.css`, etc.) — *Disabled by default to protect context*
|
|
129
|
+
* **Custom File Extensions:** Dedicated section displaying only user-added file extensions (e.g. `.csv`, `.parquet`, `.log`) with instant removal.
|
|
130
|
+
* **Chat Attachment Exemption:** Files attached directly in chat messages (`@` mentions and drag-and-drops) always bypass size cutoffs so the agent can inspect them in full.
|
|
131
|
+
* **Interactive Cutoff Dropdown:** Switch size cutoffs on the fly (`2 KB`, `4 KB`, `8 KB`, `16 KB`, `32 KB`, `64 KB`, or `none`). Line slice limits scale dynamically (2 KB: ≤ 50 lines, 8 KB: ≤ 200 lines, 32 KB: ≤ 800 lines).
|
|
132
|
+
* **Interactive FTS5 Search Inspector:** Search your indexed logs and files directly from the UI to inspect what the agent has indexed.
|
|
123
133
|
* **1-Click Session Purge:** Wipe session indexes and reset counters whenever you start a fresh task.
|
|
124
134
|
|
|
125
135
|
---
|
|
126
136
|
|
|
127
|
-
##
|
|
137
|
+
## Available MCP Tools
|
|
128
138
|
|
|
129
139
|
Once installed, the following 8 tools are registered in your Antigravity App:
|
|
130
140
|
|
|
@@ -134,14 +144,14 @@ Once installed, the following 8 tools are registered in your Antigravity App:
|
|
|
134
144
|
| **`ctx_search`** | Searches SQLite FTS5 using BM25 stemming and Trigram matching. | Finding error codes, method names, or stack traces in past logs. |
|
|
135
145
|
| **`ctx_index`** | Indexes local files, web URLs, or text into searchable chunks. | Indexing a 1,000-line documentation file or architecture spec. |
|
|
136
146
|
| **`ctx_batch`** | Runs multiple shell commands in batch and indexes the combined output. | Running `git status`, `git log`, and `npm test` in one compact call. |
|
|
137
|
-
| **`ctx_stats`** | Displays a formatted
|
|
147
|
+
| **`ctx_stats`** | Displays a formatted savings report and token metrics. | Checking how many tokens were saved during your session. |
|
|
138
148
|
| **`ctx_resume`** | Returns recent indexed sources and state pointers. | Re-orienting the agent after context compaction. |
|
|
139
149
|
| **`ctx_doctor`** | Checks SQLite database health, WAL mode, and active runtimes. | Verifying database integrity and platform runtimes. |
|
|
140
150
|
| **`ctx_purge`** | Clears stored sources and events from SQLite. | Resetting session or worktree indexes. |
|
|
141
151
|
|
|
142
152
|
---
|
|
143
153
|
|
|
144
|
-
##
|
|
154
|
+
## Configuration & Environment Variables
|
|
145
155
|
|
|
146
156
|
You can customize Context Mode's cutoffs at any time using the dashboard dropdown or environment variables:
|
|
147
157
|
|
|
@@ -152,11 +162,6 @@ You can customize Context Mode's cutoffs at any time using the dashboard dropdow
|
|
|
152
162
|
| `CONTEXT_MODE_MAX_OUTPUT_BYTES` | *Dynamic* (or `16384`) | Maximum raw preview bytes returned by `ctx_execute` (defaults to 2x cutoff). |
|
|
153
163
|
| `CONTEXT_MODE_TIMEOUT_MS` | `30000` (30s) | Execution timeout for sandboxed code snippets. |
|
|
154
164
|
|
|
155
|
-
| Variable | Default | Description |
|
|
156
|
-
| :--- | :---: | :--- |
|
|
157
|
-
| `CONTEXT_MODE_MAX_READ_BYTES` | `8192` (8 KB) | Maximum file size allowed for an un-paged `read_file` before gating kicks in. Set to `4096` for strict mode or `16384` for relaxed mode. |
|
|
158
|
-
| `CONTEXT_MODE_MAX_LINE_RANGE` | `200` lines | Maximum line slice allowed without pagination rejection. |
|
|
159
|
-
|
|
160
165
|
### How to set on Windows (PowerShell):
|
|
161
166
|
```powershell
|
|
162
167
|
$env:CONTEXT_MODE_MAX_READ_BYTES = "4096" # Enforce strict 4 KB cutoff
|
|
@@ -169,7 +174,7 @@ export CONTEXT_MODE_MAX_READ_BYTES=4096
|
|
|
169
174
|
|
|
170
175
|
---
|
|
171
176
|
|
|
172
|
-
##
|
|
177
|
+
## Privacy & Zero Dependencies
|
|
173
178
|
|
|
174
179
|
* **100% Local**: All indexed data lives on your machine in `~/.context-mode/context.db`. Zero network calls are made.
|
|
175
180
|
* **Zero 3rd-Party Dependencies**: Built exclusively on native Node.js (`node:sqlite` / `DatabaseSync`, `child_process`, and `http`). No native C++ builds, no `node-gyp`, and no dependency security vulnerabilities.
|
|
@@ -177,7 +182,7 @@ export CONTEXT_MODE_MAX_READ_BYTES=4096
|
|
|
177
182
|
|
|
178
183
|
---
|
|
179
184
|
|
|
180
|
-
##
|
|
185
|
+
## Running Tests
|
|
181
186
|
|
|
182
187
|
Context Mode ships with a complete test suite using Node's native test runner:
|
|
183
188
|
|
|
@@ -190,10 +195,12 @@ Verifies:
|
|
|
190
195
|
* Reciprocal Rank Fusion (RRF) ranking.
|
|
191
196
|
* Sandbox execution and process timeout termination.
|
|
192
197
|
* `PreToolUse` and `SessionStart` lifecycle hook gating.
|
|
198
|
+
* File category toggles and custom extension management.
|
|
199
|
+
* Active / Paused state toggle and bypass logic.
|
|
193
200
|
* MCP stdio JSON-RPC protocol compliance.
|
|
194
201
|
|
|
195
202
|
---
|
|
196
203
|
|
|
197
|
-
##
|
|
204
|
+
## License
|
|
198
205
|
|
|
199
206
|
MIT © [Phillip Webber](https://github.com/Domush)
|
package/hooks/pre-tool-use.js
CHANGED
|
@@ -6,10 +6,23 @@ import { ContextModeStore } from "../lib/store.js";
|
|
|
6
6
|
export const DEFAULT_MAX_READ_BYTES = 8192; // 8 KB default cutoff
|
|
7
7
|
export const DEFAULT_MAX_LINE_RANGE = 200; // 200 lines max un-indexed slice
|
|
8
8
|
|
|
9
|
+
function isProtectionPaused(sessionId = null) {
|
|
10
|
+
try {
|
|
11
|
+
const store = new ContextModeStore();
|
|
12
|
+
const paused = store.isPaused(sessionId);
|
|
13
|
+
store.close();
|
|
14
|
+
return paused;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
function getMaxReadBytes(sessionId = null) {
|
|
10
21
|
try {
|
|
11
22
|
const store = new ContextModeStore();
|
|
12
|
-
|
|
23
|
+
const cutoff = store.getCutoff(sessionId);
|
|
24
|
+
store.close();
|
|
25
|
+
return cutoff;
|
|
13
26
|
} catch {
|
|
14
27
|
const envVal = process.env.CONTEXT_MODE_MAX_READ_BYTES;
|
|
15
28
|
if (envVal) {
|
|
@@ -23,7 +36,9 @@ function getMaxReadBytes(sessionId = null) {
|
|
|
23
36
|
function getExemptExtensions(sessionId = null) {
|
|
24
37
|
try {
|
|
25
38
|
const store = new ContextModeStore();
|
|
26
|
-
|
|
39
|
+
const exts = store.getExemptExtensions(sessionId);
|
|
40
|
+
store.close();
|
|
41
|
+
return exts;
|
|
27
42
|
} catch {
|
|
28
43
|
return Array.from(BINARY_EXTENSIONS);
|
|
29
44
|
}
|
|
@@ -49,6 +64,66 @@ function formatBytes(bytes) {
|
|
|
49
64
|
return `${Number.isInteger(mb) ? mb : mb.toFixed(2)} MB`;
|
|
50
65
|
}
|
|
51
66
|
|
|
67
|
+
export function cleanStringArg(val) {
|
|
68
|
+
if (val === undefined || val === null) return "";
|
|
69
|
+
let str = String(val).trim();
|
|
70
|
+
while (
|
|
71
|
+
(str.startsWith('"') && str.endsWith('"') && str.length >= 2) ||
|
|
72
|
+
(str.startsWith("'") && str.endsWith("'") && str.length >= 2)
|
|
73
|
+
) {
|
|
74
|
+
str = str.slice(1, -1).trim();
|
|
75
|
+
}
|
|
76
|
+
return str;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function cleanFilePath(val) {
|
|
80
|
+
let p = cleanStringArg(val);
|
|
81
|
+
if (!p) return "";
|
|
82
|
+
// Strip file URI prefix
|
|
83
|
+
if (p.startsWith("file:///")) {
|
|
84
|
+
p = p.slice(8);
|
|
85
|
+
} else if (p.startsWith("file://")) {
|
|
86
|
+
p = p.slice(7);
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
p = decodeURIComponent(p);
|
|
90
|
+
} catch {}
|
|
91
|
+
// Strip trailing line anchor (e.g. #L1-L20)
|
|
92
|
+
p = p.replace(/#L\d+(-L\d+)?$/i, "");
|
|
93
|
+
// Normalize Windows slashes
|
|
94
|
+
return path.normalize(p.trim());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function parseLineArg(val) {
|
|
98
|
+
if (val === undefined || val === null) return null;
|
|
99
|
+
const str = cleanStringArg(val);
|
|
100
|
+
if (!str || str.toLowerCase() === "null" || str.toLowerCase() === "undefined") {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const parsed = parseInt(str, 10);
|
|
104
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const KNOWN_TEXT_EXTENSIONS = new Set([
|
|
108
|
+
// Markdown & Documentation
|
|
109
|
+
".md", ".markdown", ".mdown", ".mkd", ".rst", ".adoc",
|
|
110
|
+
// Code
|
|
111
|
+
".cs", ".csx",
|
|
112
|
+
".js", ".jsx", ".mjs", ".cjs",
|
|
113
|
+
".ts", ".tsx", ".mts", ".cts",
|
|
114
|
+
".py", ".pyw",
|
|
115
|
+
".c", ".h", ".cpp", ".hpp", ".cc", ".cxx", ".hh",
|
|
116
|
+
".rs", ".go", ".java", ".kt", ".kts", ".scala",
|
|
117
|
+
".rb", ".php", ".sh", ".bash", ".ps1", ".psm1", ".psd1",
|
|
118
|
+
".bat", ".cmd",
|
|
119
|
+
// Web & Config
|
|
120
|
+
".html", ".htm", ".xhtml", ".css", ".scss", ".sass", ".less",
|
|
121
|
+
".json", ".jsonc", ".json5",
|
|
122
|
+
".xml", ".yaml", ".yml", ".toml", ".ini", ".cfg", ".conf",
|
|
123
|
+
".sql", ".graphql", ".gql",
|
|
124
|
+
".diff", ".patch", ".txt", ".text", ".log", ".csv", ".tsv"
|
|
125
|
+
]);
|
|
126
|
+
|
|
52
127
|
const BINARY_EXTENSIONS = new Set([
|
|
53
128
|
// Documents & Office
|
|
54
129
|
".pdf", ".docx", ".doc", ".xlsx", ".xls", ".pptx", ".ppt",
|
|
@@ -72,7 +147,11 @@ function isUserAttachedFile(filePath, absPath) {
|
|
|
72
147
|
}
|
|
73
148
|
|
|
74
149
|
function isBinaryFile(absPath, ext) {
|
|
75
|
-
|
|
150
|
+
const lowerExt = (ext || "").toLowerCase();
|
|
151
|
+
if (KNOWN_TEXT_EXTENSIONS.has(lowerExt)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (BINARY_EXTENSIONS.has(lowerExt)) {
|
|
76
155
|
return true;
|
|
77
156
|
}
|
|
78
157
|
try {
|
|
@@ -82,6 +161,15 @@ function isBinaryFile(absPath, ext) {
|
|
|
82
161
|
fs.closeSync(fd);
|
|
83
162
|
if (bytesRead === 0) return false;
|
|
84
163
|
|
|
164
|
+
// Check for UTF-16 LE BOM (FF FE) or BE BOM (FE FF)
|
|
165
|
+
if (bytesRead >= 2 && ((buf[0] === 0xff && buf[1] === 0xfe) || (buf[0] === 0xfe && buf[1] === 0xff))) {
|
|
166
|
+
return false; // Text file with UTF-16 BOM
|
|
167
|
+
}
|
|
168
|
+
// Check for UTF-8 BOM (EF BB BF)
|
|
169
|
+
if (bytesRead >= 3 && buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
85
173
|
// Check for PDF magic header (%PDF)
|
|
86
174
|
if (bytesRead >= 4 && buf[0] === 0x25 && buf[1] === 0x50 && buf[2] === 0x44 && buf[3] === 0x46) {
|
|
87
175
|
return true;
|
|
@@ -97,6 +185,30 @@ function isBinaryFile(absPath, ext) {
|
|
|
97
185
|
return false;
|
|
98
186
|
}
|
|
99
187
|
|
|
188
|
+
function recordInterception({ sessionId, cwd, toolName, path: targetPath, size, reason }) {
|
|
189
|
+
try {
|
|
190
|
+
const store = new ContextModeStore();
|
|
191
|
+
store.recordEvent({
|
|
192
|
+
sessionId: sessionId || "default",
|
|
193
|
+
worktree: cwd || process.cwd(),
|
|
194
|
+
agent: "antigravity",
|
|
195
|
+
kind: "interception",
|
|
196
|
+
tool: toolName,
|
|
197
|
+
key: "blocked",
|
|
198
|
+
path: targetPath || null,
|
|
199
|
+
ok: 0,
|
|
200
|
+
exitCode: 1,
|
|
201
|
+
bytes: size || 0,
|
|
202
|
+
body: reason,
|
|
203
|
+
sandboxBytes: size || 0,
|
|
204
|
+
returnedBytes: 0
|
|
205
|
+
});
|
|
206
|
+
store.close();
|
|
207
|
+
} catch {
|
|
208
|
+
// Non-blocking: database recording failure must never crash the hook
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
100
212
|
function readStdin() {
|
|
101
213
|
return new Promise((resolve) => {
|
|
102
214
|
let data = "";
|
|
@@ -110,13 +222,144 @@ function readStdin() {
|
|
|
110
222
|
});
|
|
111
223
|
}
|
|
112
224
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/^\s*
|
|
116
|
-
/^\s*git\s+log\
|
|
117
|
-
/^\s*curl
|
|
225
|
+
// Kept for backward compatibility
|
|
226
|
+
export const UNBOUNDED_COMMAND_PATTERNS = [
|
|
227
|
+
/^\s*(cat|type|Get-Content|gc)\b/i,
|
|
228
|
+
/^\s*git\s+log\b/i,
|
|
229
|
+
/^\s*(curl|wget)\b/i
|
|
118
230
|
];
|
|
119
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Dynamically inspects shell commands against active SQLite cutoff and user exemptions
|
|
234
|
+
* without relying on a static hardcoded file extension whitelist.
|
|
235
|
+
*/
|
|
236
|
+
export function inspectCommand({ commandLine, cwd, sessionId }) {
|
|
237
|
+
if (!commandLine || typeof commandLine !== "string") {
|
|
238
|
+
return { shouldDeny: false };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const cleanCmd = cleanStringArg(commandLine);
|
|
242
|
+
const maxReadBytes = getMaxReadBytes(sessionId);
|
|
243
|
+
const exemptExtensions = getExemptExtensions(sessionId);
|
|
244
|
+
|
|
245
|
+
// 1. Git log without count limiter
|
|
246
|
+
if (/^\s*git\s+log\b/i.test(cleanCmd)) {
|
|
247
|
+
const isLimited = /(-n\s+\d+|-\d+|--max-count|\s*\|\s*(head|Select-Object|select|more))/i.test(cleanCmd);
|
|
248
|
+
if (!isLimited) {
|
|
249
|
+
return {
|
|
250
|
+
shouldDeny: true,
|
|
251
|
+
reason:
|
|
252
|
+
`[context-mode protection] 'git log' without a count limiter risks dumping thousands of commits into context. ` +
|
|
253
|
+
`Please specify a count (e.g. 'git log -n 10') or run inside 'mcp_context-mode_ctx_execute'.`,
|
|
254
|
+
size: 32768,
|
|
255
|
+
targetPath: "git log"
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 2. Direct curl / wget to stdout without file destination or limiter
|
|
261
|
+
if (/^\s*(curl(\.exe)?|wget(\.exe)?)\b/i.test(cleanCmd)) {
|
|
262
|
+
const writesToFile = /(-o\s+|-O\s+|--output\s+|>)/i.test(cleanCmd);
|
|
263
|
+
const hasLimiter = /\|\s*(head|Select-Object|select|more)/i.test(cleanCmd);
|
|
264
|
+
if (!writesToFile && !hasLimiter) {
|
|
265
|
+
// Allow if downloading a file with an exempt extension (e.g. images, media, office docs)
|
|
266
|
+
const urlMatch = cleanCmd.match(/https?:\/\/[^\s"']+/i);
|
|
267
|
+
if (urlMatch) {
|
|
268
|
+
try {
|
|
269
|
+
const parsedUrl = new URL(urlMatch[0]);
|
|
270
|
+
const ext = path.extname(parsedUrl.pathname).toLowerCase();
|
|
271
|
+
if (ext && exemptExtensions.includes(ext)) {
|
|
272
|
+
return { shouldDeny: false };
|
|
273
|
+
}
|
|
274
|
+
} catch {}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
shouldDeny: true,
|
|
279
|
+
reason:
|
|
280
|
+
`[context-mode protection] Direct curl/wget download to stdout risks flooding the context window. ` +
|
|
281
|
+
`Please use 'mcp_context-mode_ctx_execute', save to disk ('-o <file>'), or append '| head -n 50'.`,
|
|
282
|
+
size: 32768,
|
|
283
|
+
targetPath: urlMatch ? urlMatch[0] : cleanCmd
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 3. Raw file dump utilities (cat, type, Get-Content, gc)
|
|
289
|
+
const printMatch = cleanCmd.match(/^\s*(cat|type|Get-Content|gc)(\.exe)?\b/i);
|
|
290
|
+
if (printMatch) {
|
|
291
|
+
// Allow if command includes pagination flags or piping to limiters / file sinks
|
|
292
|
+
const hasLimiter =
|
|
293
|
+
/(-Head|-TotalCount|-First|-Tail)\s+\d+/i.test(cleanCmd) ||
|
|
294
|
+
/\|\s*(head|Select-Object|select\s+(-[a-zA-Z]+\s+)*-First|more|Out-Null|Set-Content|Out-File)/i.test(cleanCmd) ||
|
|
295
|
+
/>\s*[^>]/i.test(cleanCmd);
|
|
296
|
+
|
|
297
|
+
if (hasLimiter) {
|
|
298
|
+
return { shouldDeny: false };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Extract target argument
|
|
302
|
+
const argMatch = cleanCmd.match(/(?:cat|type|Get-Content|gc)(?:\.exe)?(?:\s+(?:-Path|-LiteralPath))?\s+["']?([^"'\r\n;|]+)["']?/i);
|
|
303
|
+
const rawTarget = argMatch && argMatch[1] ? argMatch[1].trim() : "";
|
|
304
|
+
|
|
305
|
+
// Wildcard dump (e.g. cat *.log, Get-Content *)
|
|
306
|
+
if (rawTarget.includes("*") || rawTarget.includes("?")) {
|
|
307
|
+
return {
|
|
308
|
+
shouldDeny: true,
|
|
309
|
+
reason:
|
|
310
|
+
`[context-mode protection] Wildcard file dump ('${rawTarget}') risks flooding the context window. ` +
|
|
311
|
+
`Please use 'mcp_context-mode_ctx_execute' or append a limiter such as '| Select-Object -First 50'.`,
|
|
312
|
+
size: 32768,
|
|
313
|
+
targetPath: rawTarget
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (rawTarget) {
|
|
318
|
+
const cleanTarget = cleanFilePath(rawTarget);
|
|
319
|
+
const absPath = path.isAbsolute(cleanTarget) ? cleanTarget : path.resolve(cwd, cleanTarget);
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
if (fs.existsSync(absPath)) {
|
|
323
|
+
const ext = path.extname(absPath).toLowerCase();
|
|
324
|
+
// Dynamic exemption check from SQLite/Dashboard configuration
|
|
325
|
+
if (ext && exemptExtensions.includes(ext)) {
|
|
326
|
+
return { shouldDeny: false };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const stat = fs.statSync(absPath);
|
|
330
|
+
// Dynamic cutoff check against active setting
|
|
331
|
+
if (maxReadBytes > 0 && stat.size > maxReadBytes) {
|
|
332
|
+
return {
|
|
333
|
+
shouldDeny: true,
|
|
334
|
+
reason:
|
|
335
|
+
`[context-mode protection] Command attempts an un-paged dump of '${cleanTarget}' (${formatBytes(stat.size)}), ` +
|
|
336
|
+
`exceeding the ${formatBytes(maxReadBytes)} context limit. ` +
|
|
337
|
+
`Please use 'mcp_context-mode_ctx_execute' or append '| Select-Object -First 50' or '-Head 50'.`,
|
|
338
|
+
size: stat.size,
|
|
339
|
+
targetPath: cleanTarget
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// File is small and within cutoff
|
|
344
|
+
return { shouldDeny: false };
|
|
345
|
+
}
|
|
346
|
+
} catch {}
|
|
347
|
+
|
|
348
|
+
// If file doesn't exist on disk or path cannot be resolved, block unpaged dump defensively
|
|
349
|
+
return {
|
|
350
|
+
shouldDeny: true,
|
|
351
|
+
reason:
|
|
352
|
+
`[context-mode protection] Command matches an un-paged file dump ('${rawTarget}') that could flood the context window. ` +
|
|
353
|
+
`Please use 'mcp_context-mode_ctx_execute' or append a limiter such as '| Select-Object -First 50' or '| head -n 50'.`,
|
|
354
|
+
size: 32768,
|
|
355
|
+
targetPath: cleanTarget || rawTarget
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return { shouldDeny: false };
|
|
361
|
+
}
|
|
362
|
+
|
|
120
363
|
async function main() {
|
|
121
364
|
const rawInput = await readStdin();
|
|
122
365
|
if (!rawInput.trim()) {
|
|
@@ -143,11 +386,18 @@ async function main() {
|
|
|
143
386
|
process.env.ANTIGRAVITY_CONVERSATION_ID ||
|
|
144
387
|
null;
|
|
145
388
|
|
|
146
|
-
//
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
389
|
+
// If Context Mode protection is paused, allow all tool calls through without interception
|
|
390
|
+
if (isProtectionPaused(sessionId)) {
|
|
391
|
+
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
392
|
+
process.exit(0);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 1. Guard read_file / view_file
|
|
396
|
+
if (toolName === "read_file" || toolName === "view_file") {
|
|
397
|
+
const rawFilePath = args.Path || args.path || args.filePath || "";
|
|
398
|
+
const filePath = cleanFilePath(rawFilePath);
|
|
399
|
+
const startLine = parseLineArg(args.StartLine ?? args.startLine) ?? 1;
|
|
400
|
+
const endLine = parseLineArg(args.EndLine ?? args.endLine);
|
|
151
401
|
const maxReadBytes = getMaxReadBytes(sessionId);
|
|
152
402
|
const maxLineRange = getMaxLineRange(maxReadBytes);
|
|
153
403
|
|
|
@@ -156,7 +406,7 @@ async function main() {
|
|
|
156
406
|
try {
|
|
157
407
|
if (fs.existsSync(absPath)) {
|
|
158
408
|
const ext = path.extname(absPath).toLowerCase();
|
|
159
|
-
const isUserAttachment = isUserAttachedFile(
|
|
409
|
+
const isUserAttachment = isUserAttachedFile(rawFilePath, absPath);
|
|
160
410
|
const exemptExtensions = getExemptExtensions(sessionId);
|
|
161
411
|
const isExemptExt = exemptExtensions.includes(ext);
|
|
162
412
|
const isBinary = isBinaryFile(absPath, ext);
|
|
@@ -169,7 +419,7 @@ async function main() {
|
|
|
169
419
|
|
|
170
420
|
const stat = fs.statSync(absPath);
|
|
171
421
|
const isLargeFile = maxReadBytes > 0 && stat.size > maxReadBytes;
|
|
172
|
-
const isWideRange = maxLineRange > 0 && (endLine === null || endLine - startLine > maxLineRange);
|
|
422
|
+
const isWideRange = maxLineRange > 0 && (endLine === null || (endLine - startLine) > maxLineRange);
|
|
173
423
|
|
|
174
424
|
if (isLargeFile && isWideRange) {
|
|
175
425
|
const lineInstruction = maxLineRange > 0 ? ` or provide a tight StartLine/EndLine range (<= ${maxLineRange} lines).` : "";
|
|
@@ -178,13 +428,23 @@ async function main() {
|
|
|
178
428
|
`Reading the entire file risks severe context bloat. ` +
|
|
179
429
|
`Please use 'mcp_context-mode_ctx_index(path: "${filePath}")' followed by 'mcp_context-mode_ctx_search'${lineInstruction}`;
|
|
180
430
|
|
|
431
|
+
// Record interception event in SQLite store so dashboard telemetry updates immediately
|
|
432
|
+
recordInterception({
|
|
433
|
+
sessionId,
|
|
434
|
+
cwd,
|
|
435
|
+
toolName,
|
|
436
|
+
path: filePath,
|
|
437
|
+
size: stat.size,
|
|
438
|
+
reason
|
|
439
|
+
});
|
|
440
|
+
|
|
181
441
|
process.stdout.write(
|
|
182
442
|
JSON.stringify({
|
|
183
443
|
decision: "deny",
|
|
184
444
|
reason
|
|
185
445
|
}) + "\n"
|
|
186
446
|
);
|
|
187
|
-
|
|
447
|
+
process.exit(0);
|
|
188
448
|
}
|
|
189
449
|
}
|
|
190
450
|
} catch {
|
|
@@ -195,29 +455,39 @@ async function main() {
|
|
|
195
455
|
|
|
196
456
|
// 2. Guard run_command
|
|
197
457
|
if (toolName === "run_command") {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
458
|
+
const rawCommandLine = args.CommandLine || args.commandLine || args.command || "";
|
|
459
|
+
const inspection = inspectCommand({
|
|
460
|
+
commandLine: rawCommandLine,
|
|
461
|
+
cwd,
|
|
462
|
+
sessionId
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
if (inspection.shouldDeny) {
|
|
466
|
+
recordInterception({
|
|
467
|
+
sessionId,
|
|
468
|
+
cwd,
|
|
469
|
+
toolName,
|
|
470
|
+
path: inspection.targetPath || cleanStringArg(rawCommandLine),
|
|
471
|
+
size: inspection.size || 32768,
|
|
472
|
+
reason: inspection.reason
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
process.stdout.write(
|
|
476
|
+
JSON.stringify({
|
|
477
|
+
decision: "deny",
|
|
478
|
+
reason: inspection.reason
|
|
479
|
+
}) + "\n"
|
|
480
|
+
);
|
|
481
|
+
process.exit(0);
|
|
214
482
|
}
|
|
215
483
|
}
|
|
216
484
|
|
|
217
485
|
// Default allow
|
|
218
486
|
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
487
|
+
process.exit(0);
|
|
219
488
|
}
|
|
220
489
|
|
|
221
490
|
main().catch(() => {
|
|
222
491
|
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
492
|
+
process.exit(0);
|
|
223
493
|
});
|
package/hooks.json
CHANGED
package/lib/store.js
CHANGED
|
@@ -8,41 +8,57 @@ export const SNIPPET_MAX_BYTES = 800;
|
|
|
8
8
|
export const RRF_K = 60;
|
|
9
9
|
export const STATE_BUDGET = 2048;
|
|
10
10
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
11
|
+
export const FILE_CATEGORIES = {
|
|
12
|
+
images: {
|
|
13
|
+
id: "images",
|
|
14
|
+
name: "Images",
|
|
15
|
+
extensions: [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".ico", ".tiff", ".psd"]
|
|
16
|
+
},
|
|
17
|
+
documents: {
|
|
18
|
+
id: "documents",
|
|
19
|
+
name: "Documents",
|
|
20
|
+
extensions: [".pdf", ".docx", ".doc", ".xlsx", ".xls", ".pptx", ".ppt", ".odt", ".rtf"]
|
|
21
|
+
},
|
|
22
|
+
code: {
|
|
23
|
+
id: "code",
|
|
24
|
+
name: "Source Code",
|
|
25
|
+
extensions: [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".py", ".rs", ".go", ".java", ".c", ".cpp", ".h", ".cs", ".html", ".css", ".json", ".yaml", ".yml", ".sql", ".sh", ".ps1"]
|
|
26
|
+
},
|
|
27
|
+
models3d: {
|
|
28
|
+
id: "models3d",
|
|
29
|
+
name: "3D Models",
|
|
30
|
+
extensions: [".blend", ".fbx", ".obj", ".gltf", ".glb", ".stl", ".dae", ".3ds", ".step", ".iges"]
|
|
31
|
+
},
|
|
32
|
+
music: {
|
|
33
|
+
id: "music",
|
|
34
|
+
name: "Music",
|
|
35
|
+
extensions: [".mp3", ".wav", ".ogg", ".flac", ".aac", ".m4a", ".wma", ".midi"]
|
|
36
|
+
},
|
|
37
|
+
video: {
|
|
38
|
+
id: "video",
|
|
39
|
+
name: "Video",
|
|
40
|
+
extensions: [".mp4", ".mov", ".avi", ".mkv", ".webm", ".flv", ".wmv", ".m4v"]
|
|
41
|
+
},
|
|
42
|
+
archives: {
|
|
43
|
+
id: "archives",
|
|
44
|
+
name: "Archives",
|
|
45
|
+
extensions: [".zip", ".tar", ".gz", ".7z", ".rar", ".wasm"]
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const DEFAULT_ACTIVE_CATEGORIES = ["images", "documents", "models3d", "music", "video", "archives"];
|
|
50
|
+
|
|
51
|
+
export const DEFAULT_EXEMPT_EXTENSIONS = Array.from(
|
|
52
|
+
new Set(
|
|
53
|
+
DEFAULT_ACTIVE_CATEGORIES.flatMap((catId) => FILE_CATEGORIES[catId]?.extensions || [])
|
|
54
|
+
)
|
|
55
|
+
);
|
|
43
56
|
|
|
44
57
|
/** Default path to context database (~/.context-mode/context.db) */
|
|
45
58
|
export function getDefaultDbPath() {
|
|
59
|
+
if (process.env.CONTEXT_MODE_DB_PATH && process.env.CONTEXT_MODE_DB_PATH.trim()) {
|
|
60
|
+
return process.env.CONTEXT_MODE_DB_PATH.trim();
|
|
61
|
+
}
|
|
46
62
|
const dir = path.join(os.homedir(), ".context-mode");
|
|
47
63
|
return path.join(dir, "context.db");
|
|
48
64
|
}
|
|
@@ -103,8 +119,13 @@ export class ContextModeStore {
|
|
|
103
119
|
/** Initialize tables, FTS5 virtual tables, and indexes */
|
|
104
120
|
initSchema() {
|
|
105
121
|
if (!this.db) return;
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
try {
|
|
123
|
+
this.db.exec("PRAGMA busy_timeout = 5000;");
|
|
124
|
+
this.db.exec("PRAGMA journal_mode = WAL;");
|
|
125
|
+
this.db.exec("PRAGMA synchronous = NORMAL;");
|
|
126
|
+
} catch {
|
|
127
|
+
// Fallback if PRAGMA configuration is restricted
|
|
128
|
+
}
|
|
108
129
|
|
|
109
130
|
// Standard tables
|
|
110
131
|
this.db.exec(`
|
|
@@ -471,7 +492,7 @@ export class ContextModeStore {
|
|
|
471
492
|
.all(limit);
|
|
472
493
|
events = this.db
|
|
473
494
|
.prepare(`
|
|
474
|
-
SELECT seq, tool, kind, ok, sandbox_bytes, returned_bytes, created_at
|
|
495
|
+
SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, created_at
|
|
475
496
|
FROM events
|
|
476
497
|
ORDER BY seq DESC
|
|
477
498
|
LIMIT ?
|
|
@@ -489,7 +510,7 @@ export class ContextModeStore {
|
|
|
489
510
|
.all(sinceIso, sinceTs, limit);
|
|
490
511
|
events = this.db
|
|
491
512
|
.prepare(`
|
|
492
|
-
SELECT seq, tool, kind, ok, sandbox_bytes, returned_bytes, created_at
|
|
513
|
+
SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, created_at
|
|
493
514
|
FROM events
|
|
494
515
|
WHERE created_at >= ?
|
|
495
516
|
ORDER BY seq DESC
|
|
@@ -508,7 +529,7 @@ export class ContextModeStore {
|
|
|
508
529
|
.all(sid, limit);
|
|
509
530
|
events = this.db
|
|
510
531
|
.prepare(`
|
|
511
|
-
SELECT seq, tool, kind, ok, sandbox_bytes, returned_bytes, created_at
|
|
532
|
+
SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, created_at
|
|
512
533
|
FROM events
|
|
513
534
|
WHERE session_id = ?
|
|
514
535
|
ORDER BY seq DESC
|
|
@@ -755,21 +776,42 @@ export class ContextModeStore {
|
|
|
755
776
|
return numVal;
|
|
756
777
|
}
|
|
757
778
|
|
|
758
|
-
/**
|
|
759
|
-
|
|
779
|
+
/** Internal helper to recompute and save the combined exempt_ext list */
|
|
780
|
+
_recomputeExemptExtensions(sessionId = null) {
|
|
781
|
+
const activeCats = this.getExemptCategories(sessionId);
|
|
782
|
+
const customs = this.getCustomExemptExtensions(sessionId);
|
|
783
|
+
const combined = new Set(customs);
|
|
784
|
+
for (const catId of activeCats) {
|
|
785
|
+
const cat = FILE_CATEGORIES[catId];
|
|
786
|
+
if (cat && Array.isArray(cat.extensions)) {
|
|
787
|
+
for (const ext of cat.extensions) {
|
|
788
|
+
combined.add(ext);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
const cleanList = Array.from(combined);
|
|
793
|
+
const serialized = JSON.stringify(cleanList);
|
|
794
|
+
if (sessionId && sessionId !== "all") {
|
|
795
|
+
this.setMeta(`exempt_ext:session:${sessionId}`, serialized);
|
|
796
|
+
} else {
|
|
797
|
+
this.setMeta("exempt_ext:global", serialized);
|
|
798
|
+
}
|
|
799
|
+
return cleanList;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/** Get list of active category IDs */
|
|
803
|
+
getExemptCategories(sessionId = null) {
|
|
760
804
|
this.open();
|
|
761
|
-
// 1. Session/Conversation override
|
|
762
805
|
if (sessionId && sessionId !== "all") {
|
|
763
|
-
const raw = this.getMeta(`
|
|
806
|
+
const raw = this.getMeta(`exempt_categories:session:${sessionId}`);
|
|
764
807
|
if (raw) {
|
|
765
808
|
try {
|
|
766
809
|
const parsed = JSON.parse(raw);
|
|
767
810
|
if (Array.isArray(parsed)) return parsed;
|
|
768
811
|
} catch {}
|
|
769
812
|
}
|
|
770
|
-
// If checking a conversation, fall back to the app session exemptions if set
|
|
771
813
|
if (sessionId !== "app") {
|
|
772
|
-
const appRaw = this.getMeta("
|
|
814
|
+
const appRaw = this.getMeta("exempt_categories:session:app");
|
|
773
815
|
if (appRaw) {
|
|
774
816
|
try {
|
|
775
817
|
const parsed = JSON.parse(appRaw);
|
|
@@ -778,18 +820,85 @@ export class ContextModeStore {
|
|
|
778
820
|
}
|
|
779
821
|
}
|
|
780
822
|
}
|
|
781
|
-
const globalRaw = this.getMeta("
|
|
823
|
+
const globalRaw = this.getMeta("exempt_categories:global");
|
|
782
824
|
if (globalRaw) {
|
|
783
825
|
try {
|
|
784
826
|
const parsed = JSON.parse(globalRaw);
|
|
785
827
|
if (Array.isArray(parsed)) return parsed;
|
|
786
828
|
} catch {}
|
|
787
829
|
}
|
|
788
|
-
return [...
|
|
830
|
+
return [...DEFAULT_ACTIVE_CATEGORIES];
|
|
789
831
|
}
|
|
790
832
|
|
|
791
|
-
/** Set list of
|
|
792
|
-
|
|
833
|
+
/** Set list of active category IDs */
|
|
834
|
+
setExemptCategories(categories, sessionId = null) {
|
|
835
|
+
this.open();
|
|
836
|
+
const cleanList = Array.isArray(categories)
|
|
837
|
+
? Array.from(new Set(categories.map(c => String(c).trim().toLowerCase()).filter(c => FILE_CATEGORIES[c])))
|
|
838
|
+
: [...DEFAULT_ACTIVE_CATEGORIES];
|
|
839
|
+
const serialized = JSON.stringify(cleanList);
|
|
840
|
+
if (sessionId && sessionId !== "all") {
|
|
841
|
+
this.setMeta(`exempt_categories:session:${sessionId}`, serialized);
|
|
842
|
+
} else {
|
|
843
|
+
this.setMeta("exempt_categories:global", serialized);
|
|
844
|
+
}
|
|
845
|
+
this._recomputeExemptExtensions(sessionId);
|
|
846
|
+
return cleanList;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/** Toggle an exempt category on or off */
|
|
850
|
+
toggleExemptCategory(categoryId, enabled = null, sessionId = null) {
|
|
851
|
+
const active = this.getExemptCategories(sessionId);
|
|
852
|
+
const cat = String(categoryId || "").trim().toLowerCase();
|
|
853
|
+
if (!FILE_CATEGORIES[cat]) return active;
|
|
854
|
+
|
|
855
|
+
const isCurrentlyActive = active.includes(cat);
|
|
856
|
+
const shouldEnable = enabled !== null ? Boolean(enabled) : !isCurrentlyActive;
|
|
857
|
+
|
|
858
|
+
let updated;
|
|
859
|
+
if (shouldEnable && !isCurrentlyActive) {
|
|
860
|
+
updated = [...active, cat];
|
|
861
|
+
} else if (!shouldEnable && isCurrentlyActive) {
|
|
862
|
+
updated = active.filter(c => c !== cat);
|
|
863
|
+
} else {
|
|
864
|
+
return active;
|
|
865
|
+
}
|
|
866
|
+
return this.setExemptCategories(updated, sessionId);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** Get custom file extensions (explicitly added by user) */
|
|
870
|
+
getCustomExemptExtensions(sessionId = null) {
|
|
871
|
+
this.open();
|
|
872
|
+
if (sessionId && sessionId !== "all") {
|
|
873
|
+
const raw = this.getMeta(`custom_exempt_ext:session:${sessionId}`);
|
|
874
|
+
if (raw) {
|
|
875
|
+
try {
|
|
876
|
+
const parsed = JSON.parse(raw);
|
|
877
|
+
if (Array.isArray(parsed)) return parsed;
|
|
878
|
+
} catch {}
|
|
879
|
+
}
|
|
880
|
+
if (sessionId !== "app") {
|
|
881
|
+
const appRaw = this.getMeta("custom_exempt_ext:session:app");
|
|
882
|
+
if (appRaw) {
|
|
883
|
+
try {
|
|
884
|
+
const parsed = JSON.parse(appRaw);
|
|
885
|
+
if (Array.isArray(parsed)) return parsed;
|
|
886
|
+
} catch {}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const globalRaw = this.getMeta("custom_exempt_ext:global");
|
|
891
|
+
if (globalRaw) {
|
|
892
|
+
try {
|
|
893
|
+
const parsed = JSON.parse(globalRaw);
|
|
894
|
+
if (Array.isArray(parsed)) return parsed;
|
|
895
|
+
} catch {}
|
|
896
|
+
}
|
|
897
|
+
return [];
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** Set custom file extensions */
|
|
901
|
+
setCustomExemptExtensions(extensions, sessionId = null) {
|
|
793
902
|
this.open();
|
|
794
903
|
const cleanList = Array.from(
|
|
795
904
|
new Set(
|
|
@@ -801,36 +910,150 @@ export class ContextModeStore {
|
|
|
801
910
|
);
|
|
802
911
|
const serialized = JSON.stringify(cleanList);
|
|
803
912
|
if (sessionId && sessionId !== "all") {
|
|
804
|
-
this.setMeta(`
|
|
913
|
+
this.setMeta(`custom_exempt_ext:session:${sessionId}`, serialized);
|
|
805
914
|
} else {
|
|
806
|
-
this.setMeta("
|
|
915
|
+
this.setMeta("custom_exempt_ext:global", serialized);
|
|
807
916
|
}
|
|
917
|
+
this._recomputeExemptExtensions(sessionId);
|
|
808
918
|
return cleanList;
|
|
809
919
|
}
|
|
810
920
|
|
|
811
|
-
/** Add
|
|
812
|
-
|
|
813
|
-
const list = this.
|
|
921
|
+
/** Add custom file extension */
|
|
922
|
+
addCustomExemptExtension(ext, sessionId = null) {
|
|
923
|
+
const list = this.getCustomExemptExtensions(sessionId);
|
|
814
924
|
const cleanExt = String(ext || "").trim().toLowerCase();
|
|
815
925
|
if (!cleanExt) return list;
|
|
816
926
|
const formatted = cleanExt.startsWith(".") ? cleanExt : `.${cleanExt}`;
|
|
817
927
|
if (!list.includes(formatted)) {
|
|
818
928
|
list.push(formatted);
|
|
819
|
-
this.
|
|
929
|
+
this.setCustomExemptExtensions(list, sessionId);
|
|
820
930
|
}
|
|
821
931
|
return list;
|
|
822
932
|
}
|
|
823
933
|
|
|
824
|
-
/** Remove
|
|
825
|
-
|
|
826
|
-
const list = this.
|
|
934
|
+
/** Remove custom file extension */
|
|
935
|
+
removeCustomExemptExtension(ext, sessionId = null) {
|
|
936
|
+
const list = this.getCustomExemptExtensions(sessionId);
|
|
827
937
|
const cleanExt = String(ext || "").trim().toLowerCase();
|
|
828
938
|
const formatted = cleanExt.startsWith(".") ? cleanExt : `.${cleanExt}`;
|
|
829
939
|
const filtered = list.filter((e) => e !== formatted);
|
|
830
|
-
this.
|
|
940
|
+
this.setCustomExemptExtensions(filtered, sessionId);
|
|
831
941
|
return filtered;
|
|
832
942
|
}
|
|
833
943
|
|
|
944
|
+
/** Get list of file extensions exempt from the size cutoff */
|
|
945
|
+
getExemptExtensions(sessionId = null) {
|
|
946
|
+
this.open();
|
|
947
|
+
// 1. Session/Conversation override
|
|
948
|
+
if (sessionId && sessionId !== "all") {
|
|
949
|
+
const raw = this.getMeta(`exempt_ext:session:${sessionId}`);
|
|
950
|
+
if (raw) {
|
|
951
|
+
try {
|
|
952
|
+
const parsed = JSON.parse(raw);
|
|
953
|
+
if (Array.isArray(parsed)) return parsed;
|
|
954
|
+
} catch {}
|
|
955
|
+
}
|
|
956
|
+
// If checking a conversation, fall back to the app session exemptions if set
|
|
957
|
+
if (sessionId !== "app") {
|
|
958
|
+
const appRaw = this.getMeta("exempt_ext:session:app");
|
|
959
|
+
if (appRaw) {
|
|
960
|
+
try {
|
|
961
|
+
const parsed = JSON.parse(appRaw);
|
|
962
|
+
if (Array.isArray(parsed)) return parsed;
|
|
963
|
+
} catch {}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
const globalRaw = this.getMeta("exempt_ext:global");
|
|
968
|
+
if (globalRaw) {
|
|
969
|
+
try {
|
|
970
|
+
const parsed = JSON.parse(globalRaw);
|
|
971
|
+
if (Array.isArray(parsed)) return parsed;
|
|
972
|
+
} catch {}
|
|
973
|
+
}
|
|
974
|
+
return [...DEFAULT_EXEMPT_EXTENSIONS];
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/** Set list of file extensions exempt from the size cutoff */
|
|
978
|
+
setExemptExtensions(extensions, sessionId = null) {
|
|
979
|
+
this.open();
|
|
980
|
+
if (extensions === null) {
|
|
981
|
+
this.setExemptCategories(null, sessionId);
|
|
982
|
+
this.setCustomExemptExtensions([], sessionId);
|
|
983
|
+
return this.getExemptExtensions(sessionId);
|
|
984
|
+
}
|
|
985
|
+
const cleanList = Array.from(
|
|
986
|
+
new Set(
|
|
987
|
+
(Array.isArray(extensions) ? extensions : [])
|
|
988
|
+
.map((ext) => String(ext || "").trim().toLowerCase())
|
|
989
|
+
.filter(Boolean)
|
|
990
|
+
.map((ext) => (ext.startsWith(".") ? ext : `.${ext}`))
|
|
991
|
+
)
|
|
992
|
+
);
|
|
993
|
+
const activeCats = [];
|
|
994
|
+
for (const [catId, catObj] of Object.entries(FILE_CATEGORIES)) {
|
|
995
|
+
if (catObj.extensions.some((e) => cleanList.includes(e))) {
|
|
996
|
+
activeCats.push(catId);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const allCatExts = new Set(activeCats.flatMap((c) => FILE_CATEGORIES[c]?.extensions || []));
|
|
1000
|
+
const customs = cleanList.filter((e) => !allCatExts.has(e));
|
|
1001
|
+
|
|
1002
|
+
this.setExemptCategories(activeCats, sessionId);
|
|
1003
|
+
this.setCustomExemptExtensions(customs, sessionId);
|
|
1004
|
+
return this.getExemptExtensions(sessionId);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/** Add an exempt file extension */
|
|
1008
|
+
addExemptExtension(ext, sessionId = null) {
|
|
1009
|
+
this.addCustomExemptExtension(ext, sessionId);
|
|
1010
|
+
return this.getExemptExtensions(sessionId);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/** Remove an exempt file extension */
|
|
1014
|
+
removeExemptExtension(ext, sessionId = null) {
|
|
1015
|
+
this.removeCustomExemptExtension(ext, sessionId);
|
|
1016
|
+
return this.getExemptExtensions(sessionId);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
/** Check if protection is paused (true = paused, false = active) */
|
|
1020
|
+
isPaused(sessionId = null) {
|
|
1021
|
+
this.open();
|
|
1022
|
+
// 1. Session/Conversation override
|
|
1023
|
+
if (sessionId && sessionId !== "all") {
|
|
1024
|
+
const sessionPaused = this.getMeta(`paused:session:${sessionId}`);
|
|
1025
|
+
if (sessionPaused !== null) {
|
|
1026
|
+
return sessionPaused === "true" || sessionPaused === "1";
|
|
1027
|
+
}
|
|
1028
|
+
// If checking a conversation, fall back to the app session paused state if set
|
|
1029
|
+
if (sessionId !== "app") {
|
|
1030
|
+
const appPaused = this.getMeta("paused:session:app");
|
|
1031
|
+
if (appPaused !== null) {
|
|
1032
|
+
return appPaused === "true" || appPaused === "1";
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
// 2. Global paused setting
|
|
1037
|
+
const globalPaused = this.getMeta("paused:global");
|
|
1038
|
+
if (globalPaused !== null) {
|
|
1039
|
+
return globalPaused === "true" || globalPaused === "1";
|
|
1040
|
+
}
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/** Set protection paused state (true = paused, false = active) */
|
|
1045
|
+
setPaused(paused, sessionId = null) {
|
|
1046
|
+
this.open();
|
|
1047
|
+
const boolVal = Boolean(paused && paused !== "false" && paused !== "0");
|
|
1048
|
+
const strVal = boolVal ? "true" : "false";
|
|
1049
|
+
if (sessionId && sessionId !== "all") {
|
|
1050
|
+
this.setMeta(`paused:session:${sessionId}`, strVal);
|
|
1051
|
+
} else {
|
|
1052
|
+
this.setMeta("paused:global", strVal);
|
|
1053
|
+
}
|
|
1054
|
+
return boolVal;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
834
1057
|
/**
|
|
835
1058
|
* Automatic LRU pruning: limits the number of indexed sources and chunks
|
|
836
1059
|
* to avoid unbounded database expansion.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "antigravity-plugin-context-mode",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Native Antigravity plugin for context-mode: SQLite FTS5 indexing, sandboxed execution, and lifecycle hook protection against context window bloat",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "antigravity-plugin-context-mode",
|
|
3
3
|
"displayName": "Context Mode",
|
|
4
4
|
"description": "Context window protection for Antigravity: local SQLite FTS5 search, sandboxed execution, and lifecycle hook gating against token bloat.",
|
|
5
|
-
"version": "1.1
|
|
5
|
+
"version": "1.2.1",
|
|
6
6
|
"author": "Phillip Webber <github@webbsense.com>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
package/server.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import readline from "node:readline";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
3
6
|
import { ContextModeStore } from "./lib/store.js";
|
|
4
7
|
import { createTools } from "./lib/tools.js";
|
|
5
8
|
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
let pkgVersion = "1.0.0";
|
|
11
|
+
try {
|
|
12
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"));
|
|
13
|
+
if (pkg.version) pkgVersion = pkg.version;
|
|
14
|
+
} catch {}
|
|
15
|
+
|
|
6
16
|
const store = new ContextModeStore();
|
|
7
17
|
let currentCwd = process.cwd();
|
|
8
18
|
let currentSessionId =
|
|
@@ -196,7 +206,7 @@ rl.on("line", async (line) => {
|
|
|
196
206
|
},
|
|
197
207
|
serverInfo: {
|
|
198
208
|
name: "antigravity-plugin-context-mode",
|
|
199
|
-
version:
|
|
209
|
+
version: pkgVersion
|
|
200
210
|
}
|
|
201
211
|
});
|
|
202
212
|
break;
|