antigravity-plugin-context-mode 1.2.1 → 1.3.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 CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  All notable changes to `antigravity-plugin-context-mode` will be documented in this file.
4
4
 
5
+ ## [1.3.1] - 2026-11-16
6
+
7
+ ### Added
8
+ - **1-Click CLI Installer (`npx antigravity-plugin-context-mode install`)**: Added automated CLI installation handler to `server.js`. Running `npx antigravity-plugin-context-mode install` automatically detects the user's OS and copies plugin manifests, hooks, skills, and MCP tools directly into `~/.gemini/config/plugins/antigravity-plugin-context-mode` (or workspace-scoped via `--workspace`).
9
+ - **CLI Uninstaller (`npx antigravity-plugin-context-mode uninstall`)**: Easily remove the installed plugin from the Antigravity discovery directory with clean terminal confirmation.
10
+ - **CLI Flags (`--help`, `-h`, `--version`, `-v`)**: Quick terminal reference for command options while maintaining 100% backward compatibility with MCP stdio JSON-RPC protocol execution.
11
+
12
+ ## [1.3.0] - 2026-11-15
13
+
14
+ ### Added
15
+ - **Subagent & Primary Agent Unified Lifecycle Hooks**: `PreToolUse` now evaluates all lifecycle checks (un-paged file reads, unbounded command dumps, active cutoffs, and file category exemptions) identically across both primary agents and subagents.
16
+ - **Shared Conversation Dashboard for Subagents**: Interceptions and metrics generated by subagents now resolve to the root/parent conversation ID (`resolveSharedSessionId`), feeding directly into the active conversation dashboard in real-time. Added dedicated subagent badges in the recent activity feed to indicate which subagent triggered the event.
17
+ - **Session Lifecycle Overrides Reset**: Added `clearSessionOverrides()` to `ContextModeStore`. Wired into the `SessionStart` hook and server process initialization so that when a new application session begins (app restart), transient session overrides are cleared and the session starts fresh with the Lifetime default.
18
+ - **Direct Indexing Telemetry (`ctx_index`)**: `ctx_index` now records an event in the `events` journal upon successful indexing, immediately updating dashboard call counts and crediting kept-out tokens.
19
+
20
+ ### Fixed
21
+ - **Lifetime Cutoff Propagation to New Sessions and Conversations**: Changing the cutoff in Lifetime scope (`"all"`, `"lifetime"`, or `null`) now updates `cutoff:global` in SQLite and clears any transient session-level (`cutoff:session:app`) and fallback default (`cutoff:session:default`) overrides. New sessions and new conversations automatically inherit the new Lifetime cutoff as their default.
22
+ - **Accurate Context Saved Calculations (Eliminated Double-Counting)**: Refactored `getStats()` to prevent execution outputs from being counted twice across `events` (`sandbox_bytes`) and `sources` (`bytes_total`). Raw, returned, and kept-out bytes are now computed on a per-event basis with `MAX(sandbox_bytes, bytes, returned_bytes)`, ensuring passthrough commands with full returns do not penalize the savings of other tools.
23
+ - **MCP Server Root Session Binding**: `server.js` and `createTools` now bind session ID resolution to `process.env.ANTIGRAVITY_ROOT_CONVERSATION_ID` and `process.env.ANTIGRAVITY_PARENT_CONVERSATION_ID`, ensuring MCP tool calls from subagents share indexed chunks and search states with the primary conversation.
24
+
5
25
  ## [1.2.1] - 2026-11-15
6
26
 
7
27
  ### Fixed
package/README.md CHANGED
@@ -3,12 +3,15 @@
3
3
  > **Stop context bloat. Save 90%+ of your prompt tokens. Keep your agent fast, focused, and less forgetful.**
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/antigravity-plugin-context-mode.svg)](https://www.npmjs.com/package/antigravity-plugin-context-mode)
6
+ [![Website](https://img.shields.io/badge/Website-domush.github.io%2Fantigravity--plugin--context--mode-10b981?style=flat&logo=github)](https://domush.github.io/antigravity-plugin-context-mode/)
6
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
8
  [![Zero Runtime Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)]()
8
9
  [![Antigravity App Compatible](https://img.shields.io/badge/Antigravity%20App-Native%20Plugin-6366f1.svg)]()
9
10
 
10
11
  **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
12
 
13
+ > 🌐 **Live Website, Simulator & Changelog:** [domush.github.io/antigravity-plugin-context-mode](https://domush.github.io/antigravity-plugin-context-mode/)
14
+
12
15
  ---
13
16
  <img width="817" height="690" alt="Antigravity Context Mode Dashboard" src="https://github.com/user-attachments/assets/dbf6d666-58d0-48f3-bc02-9783acf3fb37" />
14
17
 
@@ -59,10 +62,10 @@ When an AI coding agent runs tools, standard workflows dump everything directly
59
62
  relevant answer to the chat!
60
63
  ```
61
64
 
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.
65
+ 1. **Smart Lifecycle Gating (`hooks.json`)**: Before a command or file read executes, Context Mode checks if it will cause a context flood. Applied identically to primary agents and subagents, the hook intercepts un-paged reads exceeding the active cutoff (default 8 KB) and unbounded dumps, guiding agents to query or sandbox the data instead.
63
66
  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.
67
+ 3. **Local SQLite FTS5 Storage (`ctx_search`, `ctx_index`)**: Raw outputs and indexed files 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.
68
+ 4. **Live Sidecar Dashboard**: A native side pane right inside the Antigravity App that displays real-time context savings across primary agents and subagents, lets you toggle file categories on the fly, and search indexed data with a click.
66
69
 
67
70
  ---
68
71
 
@@ -80,28 +83,38 @@ Tested live on real-world build logs, source files, and datasets in the Antigrav
80
83
 
81
84
  ## Quick Start & Installation
82
85
 
83
- ### Option 1: Global User Install (Recommended)
84
- Installs Context Mode for all your projects and conversations:
86
+ ### Method 1: 1-Click CLI Installer (Fastest)
87
+ Run this command from any terminal:
85
88
 
86
89
  ```bash
87
- # Clone directly into your Antigravity user plugins directory
88
- git clone https://github.com/Domush/antigravity-plugin-context-mode.git ~/.gemini/config/plugins/antigravity-plugin-context-mode
90
+ npx antigravity-plugin-context-mode install
89
91
  ```
90
92
 
91
- Restart the Antigravity App once. The plugin, hooks, and MCP tools will be active globally!
93
+ This automatically detects your operating system, unpacks the latest release into `~/.gemini/config/plugins/antigravity-plugin-context-mode`, and activates hooks and MCP tools. Restart the Antigravity App to activate!
94
+
95
+ > **Workspace-only install:** To install only for the current project, add `--workspace`:
96
+ > ```bash
97
+ > npx antigravity-plugin-context-mode install --workspace
98
+ > ```
99
+
100
+ ---
92
101
 
93
- ### Option 2: Project-Scoped Workspace Install
94
- If you only want Context Mode active in a specific project:
102
+ ### Method 2: Git Clone (Ideal for Easy Updates)
103
+ If you prefer managing the plugin via Git for easy `git pull` updates:
95
104
 
105
+ **Windows (PowerShell):**
106
+ ```powershell
107
+ git clone https://github.com/Domush/antigravity-plugin-context-mode.git "$env:USERPROFILE\.gemini\config\plugins\antigravity-plugin-context-mode"
108
+ ```
109
+
110
+ **macOS / Linux:**
96
111
  ```bash
97
- # From your project root directory:
98
- mkdir -p .agents/plugins
99
- git clone https://github.com/Domush/antigravity-plugin-context-mode.git .agents/plugins/antigravity-plugin-context-mode
112
+ git clone https://github.com/Domush/antigravity-plugin-context-mode.git ~/.gemini/config/plugins/antigravity-plugin-context-mode
100
113
  ```
101
114
 
102
- ### Option 3: Via npm
115
+ **To update later:**
103
116
  ```bash
104
- npm install -g antigravity-plugin-context-mode
117
+ cd ~/.gemini/config/plugins/antigravity-plugin-context-mode && git pull
105
118
  ```
106
119
 
107
120
  ---
@@ -115,9 +128,10 @@ Context Mode includes a native web dashboard that opens directly in Antigravity'
115
128
  * **Dynamic Version Badge:** Automatically reflects the active plugin version in the top-right header.
116
129
  * **Context Saved Progress Bar:** Visual indicator displaying the exact percentage of context window preserved.
117
130
  * **3-Way Scope Toggle:** Seamlessly inspect telemetry at three distinct levels:
118
- * **Conversation**: Metrics strictly for the active chat; clean slate on new conversations.
119
- * **Session**: Metrics aggregated across all conversations since the app restarted.
120
- * **Lifetime**: All-time cumulative database metrics and persistent totals.
131
+ * **Conversation**: Metrics strictly for the active chat; clean slate on new conversations. Subagent actions within the conversation feed directly into this view.
132
+ * **Session**: Metrics aggregated across all conversations since the app restarted. Automatically resets transient overrides on app reboot.
133
+ * **Lifetime**: All-time cumulative database metrics and persistent totals. Changing the cutoff in Lifetime updates the baseline defaults for all new sessions and new conversations.
134
+ * **Shared Subagent Feed:** Interceptions triggered by subagents (`researcher`, `browser`, etc.) are badged by role and displayed alongside primary agent events in the same conversation feed.
121
135
  * **File Category Toggles:** Clean, one-click pills for grouping exemptions without reading massive lists:
122
136
  * **Images** (`.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.svg`, `.bmp`, `.ico`, `.tiff`, `.psd`) — *Enabled by default*
123
137
  * **Documents** (`.pdf`, `.docx`, `.doc`, `.xlsx`, `.xls`, `.pptx`, `.ppt`, `.odt`, `.rtf`) — *Enabled by default*
@@ -194,7 +208,10 @@ Verifies:
194
208
  * SQLite FTS5 schema initialization, chunking, Porter BM25, and Trigram search.
195
209
  * Reciprocal Rank Fusion (RRF) ranking.
196
210
  * Sandbox execution and process timeout termination.
197
- * `PreToolUse` and `SessionStart` lifecycle hook gating.
211
+ * `PreToolUse` and `SessionStart` lifecycle hook gating for primary agents and subagents.
212
+ * Shared conversation dashboard linking and subagent interception event journal.
213
+ * Lifetime cutoff inheritance across new sessions and new conversations.
214
+ * Mathematically accurate context savings calculations without double-counting.
198
215
  * File category toggles and custom extension management.
199
216
  * Active / Paused state toggle and bypass logic.
200
217
  * MCP stdio JSON-RPC protocol compliance.
@@ -185,13 +185,42 @@ function isBinaryFile(absPath, ext) {
185
185
  return false;
186
186
  }
187
187
 
188
- function recordInterception({ sessionId, cwd, toolName, path: targetPath, size, reason }) {
188
+ export function resolveSharedSessionId(payload = {}) {
189
+ return (
190
+ payload.rootConversationId ||
191
+ payload.root_conversation_id ||
192
+ payload.parentConversationId ||
193
+ payload.parent_conversation_id ||
194
+ process.env.ANTIGRAVITY_ROOT_CONVERSATION_ID ||
195
+ process.env.ANTIGRAVITY_PARENT_CONVERSATION_ID ||
196
+ process.env.ANTIGRAVITY_CONVERSATION_ID ||
197
+ payload.conversationId ||
198
+ payload.conversation_id ||
199
+ payload.sessionId ||
200
+ payload.session_id ||
201
+ "default"
202
+ );
203
+ }
204
+
205
+ export function resolveAgentName(payload = {}) {
206
+ return (
207
+ payload.agent ||
208
+ payload.agentName ||
209
+ payload.agent_name ||
210
+ payload.agentType ||
211
+ payload.agent_type ||
212
+ payload.role ||
213
+ (payload.subagent ? "subagent" : "antigravity")
214
+ );
215
+ }
216
+
217
+ function recordInterception({ sessionId, agent, cwd, toolName, path: targetPath, size, reason }) {
189
218
  try {
190
219
  const store = new ContextModeStore();
191
220
  store.recordEvent({
192
221
  sessionId: sessionId || "default",
193
222
  worktree: cwd || process.cwd(),
194
- agent: "antigravity",
223
+ agent: agent || "antigravity",
195
224
  kind: "interception",
196
225
  tool: toolName,
197
226
  key: "blocked",
@@ -379,12 +408,8 @@ async function main() {
379
408
  const toolName = toolCall.name || "";
380
409
  const args = toolCall.args || {};
381
410
  const cwd = payload.cwd || process.cwd();
382
- const sessionId =
383
- payload.sessionId ||
384
- payload.session_id ||
385
- payload.conversationId ||
386
- process.env.ANTIGRAVITY_CONVERSATION_ID ||
387
- null;
411
+ const sessionId = resolveSharedSessionId(payload);
412
+ const agentName = resolveAgentName(payload);
388
413
 
389
414
  // If Context Mode protection is paused, allow all tool calls through without interception
390
415
  if (isProtectionPaused(sessionId)) {
@@ -431,6 +456,7 @@ async function main() {
431
456
  // Record interception event in SQLite store so dashboard telemetry updates immediately
432
457
  recordInterception({
433
458
  sessionId,
459
+ agent: agentName,
434
460
  cwd,
435
461
  toolName,
436
462
  path: filePath,
@@ -465,6 +491,7 @@ async function main() {
465
491
  if (inspection.shouldDeny) {
466
492
  recordInterception({
467
493
  sessionId,
494
+ agent: agentName,
468
495
  cwd,
469
496
  toolName,
470
497
  path: inspection.targetPath || cleanStringArg(rawCommandLine),
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { ContextModeStore } from "../lib/store.js";
2
3
 
3
4
  function readStdin() {
4
5
  return new Promise((resolve) => {
@@ -16,6 +17,12 @@ function readStdin() {
16
17
  async function main() {
17
18
  await readStdin();
18
19
 
20
+ try {
21
+ const store = new ContextModeStore();
22
+ store.clearSessionOverrides();
23
+ store.close();
24
+ } catch {}
25
+
19
26
  const response = {
20
27
  injectSteps: [
21
28
  {
package/lib/store.js CHANGED
@@ -492,7 +492,7 @@ export class ContextModeStore {
492
492
  .all(limit);
493
493
  events = this.db
494
494
  .prepare(`
495
- SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, created_at
495
+ SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, agent, created_at
496
496
  FROM events
497
497
  ORDER BY seq DESC
498
498
  LIMIT ?
@@ -510,7 +510,7 @@ export class ContextModeStore {
510
510
  .all(sinceIso, sinceTs, limit);
511
511
  events = this.db
512
512
  .prepare(`
513
- SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, created_at
513
+ SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, agent, created_at
514
514
  FROM events
515
515
  WHERE created_at >= ?
516
516
  ORDER BY seq DESC
@@ -529,7 +529,7 @@ export class ContextModeStore {
529
529
  .all(sid, limit);
530
530
  events = this.db
531
531
  .prepare(`
532
- SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, created_at
532
+ SELECT seq, tool, kind, key, path, ok, sandbox_bytes, returned_bytes, agent, created_at
533
533
  FROM events
534
534
  WHERE session_id = ?
535
535
  ORDER BY seq DESC
@@ -570,13 +570,15 @@ export class ContextModeStore {
570
570
 
571
571
  let eventStats;
572
572
  let sourceStats;
573
+ let unrecordedSources;
573
574
 
574
575
  if (sid === "all" || sid === "lifetime") {
575
576
  eventStats = this.db.prepare(`
576
577
  SELECT
577
578
  COUNT(*) AS total_calls,
578
- SUM(sandbox_bytes) AS total_sandbox_bytes,
579
- SUM(returned_bytes) AS total_returned_bytes
579
+ SUM(MAX(sandbox_bytes, bytes, returned_bytes)) AS total_raw_bytes,
580
+ SUM(returned_bytes) AS total_returned_bytes,
581
+ SUM(MAX(0, MAX(sandbox_bytes, bytes, returned_bytes) - returned_bytes)) AS total_kept_out_bytes
580
582
  FROM events
581
583
  `).get();
582
584
 
@@ -587,12 +589,24 @@ export class ContextModeStore {
587
589
  SUM(chunk_count) AS total_chunks
588
590
  FROM sources
589
591
  `).get();
592
+
593
+ unrecordedSources = this.db.prepare(`
594
+ SELECT COALESCE(SUM(bytes_total), 0) AS unrecorded_source_bytes
595
+ FROM sources s
596
+ WHERE s.kind NOT IN ('execution', 'batch', 'tool_output', 'exec')
597
+ AND NOT EXISTS (
598
+ SELECT 1 FROM events e
599
+ WHERE e.tool = 'ctx_index'
600
+ AND e.sandbox_bytes = s.bytes_total
601
+ )
602
+ `).get();
590
603
  } else if (sid === "app" && sinceIso) {
591
604
  eventStats = this.db.prepare(`
592
605
  SELECT
593
606
  COUNT(*) AS total_calls,
594
- SUM(sandbox_bytes) AS total_sandbox_bytes,
595
- SUM(returned_bytes) AS total_returned_bytes
607
+ SUM(MAX(sandbox_bytes, bytes, returned_bytes)) AS total_raw_bytes,
608
+ SUM(returned_bytes) AS total_returned_bytes,
609
+ SUM(MAX(0, MAX(sandbox_bytes, bytes, returned_bytes) - returned_bytes)) AS total_kept_out_bytes
596
610
  FROM events
597
611
  WHERE created_at >= ?
598
612
  `).get(sinceIso);
@@ -605,12 +619,25 @@ export class ContextModeStore {
605
619
  FROM sources
606
620
  WHERE created_at >= ? OR created_ts >= ?
607
621
  `).get(sinceIso, sinceTs);
622
+
623
+ unrecordedSources = this.db.prepare(`
624
+ SELECT COALESCE(SUM(bytes_total), 0) AS unrecorded_source_bytes
625
+ FROM sources s
626
+ WHERE (created_at >= ? OR created_ts >= ?)
627
+ AND s.kind NOT IN ('execution', 'batch', 'tool_output', 'exec')
628
+ AND NOT EXISTS (
629
+ SELECT 1 FROM events e
630
+ WHERE e.tool = 'ctx_index'
631
+ AND e.sandbox_bytes = s.bytes_total
632
+ )
633
+ `).get(sinceIso, sinceTs);
608
634
  } else {
609
635
  eventStats = this.db.prepare(`
610
636
  SELECT
611
637
  COUNT(*) AS total_calls,
612
- SUM(sandbox_bytes) AS total_sandbox_bytes,
613
- SUM(returned_bytes) AS total_returned_bytes
638
+ SUM(MAX(sandbox_bytes, bytes, returned_bytes)) AS total_raw_bytes,
639
+ SUM(returned_bytes) AS total_returned_bytes,
640
+ SUM(MAX(0, MAX(sandbox_bytes, bytes, returned_bytes) - returned_bytes)) AS total_kept_out_bytes
614
641
  FROM events
615
642
  WHERE session_id = ?
616
643
  `).get(sid);
@@ -623,11 +650,25 @@ export class ContextModeStore {
623
650
  FROM sources
624
651
  WHERE session_id = ?
625
652
  `).get(sid);
653
+
654
+ unrecordedSources = this.db.prepare(`
655
+ SELECT COALESCE(SUM(bytes_total), 0) AS unrecorded_source_bytes
656
+ FROM sources s
657
+ WHERE s.session_id = ?
658
+ AND s.kind NOT IN ('execution', 'batch', 'tool_output', 'exec')
659
+ AND NOT EXISTS (
660
+ SELECT 1 FROM events e
661
+ WHERE e.session_id = s.session_id
662
+ AND e.tool = 'ctx_index'
663
+ AND e.sandbox_bytes = s.bytes_total
664
+ )
665
+ `).get(sid);
626
666
  }
627
667
 
628
- const totalRawBytes = (eventStats?.total_sandbox_bytes || 0) + (sourceStats?.total_source_bytes || 0);
668
+ const unrecordedBytes = unrecordedSources?.unrecorded_source_bytes || 0;
669
+ const totalRawBytes = (eventStats?.total_raw_bytes || 0) + unrecordedBytes;
629
670
  const totalReturnedBytes = eventStats?.total_returned_bytes || 0;
630
- const keptOutBytes = Math.max(0, totalRawBytes - totalReturnedBytes);
671
+ const keptOutBytes = (eventStats?.total_kept_out_bytes || 0) + unrecordedBytes;
631
672
  const savingsPercent = totalRawBytes > 0 ? Number(((keptOutBytes / totalRawBytes) * 100).toFixed(1)) : 0;
632
673
  const tokensKeptOut = Math.round(keptOutBytes / 4);
633
674
 
@@ -728,11 +769,30 @@ export class ContextModeStore {
728
769
  .run(key, String(value));
729
770
  }
730
771
 
772
+ /** Delete a key from meta table */
773
+ deleteMeta(key) {
774
+ this.open();
775
+ this.db.prepare("DELETE FROM meta WHERE key = ?").run(key);
776
+ }
777
+
778
+ /** Clear all session-level overrides so new sessions start with lifetime defaults */
779
+ clearSessionOverrides() {
780
+ this.open();
781
+ this.db.prepare("DELETE FROM meta WHERE key LIKE '%:session:app' OR key LIKE '%:session:default'").run();
782
+ }
783
+
784
+ /** Check if a session or conversation has an explicit cutoff override */
785
+ hasCutoffOverride(sessionId) {
786
+ if (!sessionId || sessionId === "all" || sessionId === "lifetime") return false;
787
+ this.open();
788
+ return this.getMeta(`cutoff:session:${sessionId}`) !== null;
789
+ }
790
+
731
791
  /** Get active cutoff in bytes (0 = none/disabled) */
732
792
  getCutoff(sessionId = null) {
733
793
  this.open();
734
794
  // 1. Session/Conversation override
735
- if (sessionId && sessionId !== "all") {
795
+ if (sessionId && sessionId !== "all" && sessionId !== "lifetime") {
736
796
  const sessionCutoff = this.getMeta(`cutoff:session:${sessionId}`);
737
797
  if (sessionCutoff !== null) {
738
798
  return parseInt(sessionCutoff, 10);
@@ -768,10 +828,14 @@ export class ContextModeStore {
768
828
  this.open();
769
829
  const val = parseInt(bytes, 10);
770
830
  const numVal = Number.isNaN(val) ? 8192 : Math.max(0, val);
771
- if (sessionId && sessionId !== "all") {
831
+ if (sessionId && sessionId !== "all" && sessionId !== "lifetime") {
772
832
  this.setMeta(`cutoff:session:${sessionId}`, numVal);
773
833
  } else {
774
834
  this.setMeta("cutoff:global", numVal);
835
+ // When changing cutoff in lifetime, clear session-level and default overrides
836
+ // so new sessions and new conversations inherit this global setting as their default.
837
+ this.deleteMeta("cutoff:session:app");
838
+ this.deleteMeta("cutoff:session:default");
775
839
  }
776
840
  return numVal;
777
841
  }
package/lib/tools.js CHANGED
@@ -233,13 +233,31 @@ export function createTools({ store, getCwd = () => process.cwd(), getSessionId
233
233
  content: rawText
234
234
  });
235
235
 
236
- return {
236
+ const returnObj = {
237
237
  sourceId: indexed.sourceId,
238
238
  label: indexed.label,
239
239
  bytesTotal: indexed.bytesTotal,
240
240
  chunkCount: indexed.chunkCount,
241
241
  message: `Indexed ${formatBytes(indexed.bytesTotal)} into ${indexed.chunkCount} chunks. Query with ctx_search.`
242
242
  };
243
+
244
+ const returnedBytes = Buffer.byteLength(JSON.stringify(returnObj), "utf8");
245
+
246
+ store.recordEvent({
247
+ sessionId,
248
+ worktree: cwd,
249
+ agent: "antigravity",
250
+ kind: "index",
251
+ tool: "ctx_index",
252
+ path: filePath || url || null,
253
+ ok: 1,
254
+ bytes: indexed.bytesTotal,
255
+ body: returnObj.message,
256
+ sandboxBytes: indexed.bytesTotal,
257
+ returnedBytes
258
+ });
259
+
260
+ return returnObj;
243
261
  },
244
262
 
245
263
  // 4. ctx_search
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antigravity-plugin-context-mode",
3
- "version": "1.2.1",
3
+ "version": "1.3.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",
@@ -12,7 +12,7 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/Domush/antigravity-plugin-context-mode/issues"
14
14
  },
15
- "homepage": "https://github.com/Domush/antigravity-plugin-context-mode#readme",
15
+ "homepage": "https://domush.github.io/antigravity-plugin-context-mode/",
16
16
  "keywords": [
17
17
  "antigravity",
18
18
  "antigravity-plugin",
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.2.1",
5
+ "version": "1.3.0",
6
6
  "author": "Phillip Webber <github@webbsense.com>",
7
7
  "repository": {
8
8
  "type": "git",
package/server.js CHANGED
@@ -13,6 +13,103 @@ try {
13
13
  if (pkg.version) pkgVersion = pkg.version;
14
14
  } catch {}
15
15
 
16
+ // Handle CLI subcommands (e.g. npx antigravity-plugin-context-mode install)
17
+ const cliArg = process.argv[2];
18
+ if (
19
+ cliArg === "install" ||
20
+ cliArg === "uninstall" ||
21
+ cliArg === "--help" ||
22
+ cliArg === "-h" ||
23
+ cliArg === "--version" ||
24
+ cliArg === "-v"
25
+ ) {
26
+ if (cliArg === "--version" || cliArg === "-v") {
27
+ console.log(`antigravity-plugin-context-mode v${pkgVersion}`);
28
+ process.exit(0);
29
+ }
30
+
31
+ if (cliArg === "--help" || cliArg === "-h") {
32
+ console.log(`
33
+ Antigravity Context Mode CLI (v${pkgVersion})
34
+
35
+ Usage:
36
+ npx antigravity-plugin-context-mode install [options] Install plugin into Google Antigravity
37
+ npx antigravity-plugin-context-mode uninstall [options] Remove installed plugin
38
+ npx antigravity-plugin-context-mode Start MCP stdio JSON-RPC server
39
+
40
+ Options:
41
+ --global, -g Install globally in ~/.gemini/config/plugins/ (default)
42
+ --workspace, -w Install in current workspace (.gemini/plugins/antigravity-plugin-context-mode)
43
+ `);
44
+ process.exit(0);
45
+ }
46
+
47
+ const isWorkspace = process.argv.includes("--workspace") || process.argv.includes("-w");
48
+ const homeDir = process.env.USERPROFILE || process.env.HOME || "";
49
+
50
+ let targetDir = "";
51
+ if (isWorkspace) {
52
+ targetDir = path.join(process.cwd(), ".gemini", "plugins", "antigravity-plugin-context-mode");
53
+ } else {
54
+ targetDir = path.join(homeDir, ".gemini", "config", "plugins", "antigravity-plugin-context-mode");
55
+ }
56
+
57
+ if (cliArg === "uninstall") {
58
+ if (fs.existsSync(targetDir)) {
59
+ fs.rmSync(targetDir, { recursive: true, force: true });
60
+ console.log(`\nāœ” Antigravity Context Mode successfully removed from:`);
61
+ console.log(` ${targetDir}\n`);
62
+ } else {
63
+ console.log(`\nℹ Plugin not found at: ${targetDir}\n`);
64
+ }
65
+ process.exit(0);
66
+ }
67
+
68
+ if (cliArg === "install") {
69
+ console.log(`\nšŸ“¦ Installing Antigravity Context Mode v${pkgVersion}...`);
70
+ try {
71
+ fs.mkdirSync(targetDir, { recursive: true });
72
+
73
+ const filesToCopy = [
74
+ "plugin.json",
75
+ "hooks.json",
76
+ "mcp_config.json",
77
+ "server.js",
78
+ "package.json",
79
+ "README.md",
80
+ "LICENSE",
81
+ "CHANGELOG.md"
82
+ ];
83
+
84
+ const dirsToCopy = ["lib", "hooks", "skills", "rules", "assets"];
85
+
86
+ for (const file of filesToCopy) {
87
+ const src = path.join(__dirname, file);
88
+ const dest = path.join(targetDir, file);
89
+ if (fs.existsSync(src)) {
90
+ fs.copyFileSync(src, dest);
91
+ }
92
+ }
93
+
94
+ for (const dir of dirsToCopy) {
95
+ const srcDir = path.join(__dirname, dir);
96
+ const destDir = path.join(targetDir, dir);
97
+ if (fs.existsSync(srcDir)) {
98
+ fs.cpSync(srcDir, destDir, { recursive: true });
99
+ }
100
+ }
101
+
102
+ console.log(`\n✨ Installation complete!`);
103
+ console.log(`šŸ“ Location: ${targetDir}`);
104
+ console.log(`šŸš€ Restart or open the Google Antigravity App to activate Context Mode.\n`);
105
+ } catch (err) {
106
+ console.error(`\nāŒ Installation failed: ${err.message}\n`);
107
+ process.exit(1);
108
+ }
109
+ process.exit(0);
110
+ }
111
+ }
112
+
16
113
  const store = new ContextModeStore();
17
114
  let currentCwd = process.cwd();
18
115
  let currentSessionId =
@@ -24,6 +121,8 @@ const tools = createTools({
24
121
  store,
25
122
  getCwd: () => currentCwd,
26
123
  getSessionId: () =>
124
+ process.env.ANTIGRAVITY_ROOT_CONVERSATION_ID ||
125
+ process.env.ANTIGRAVITY_PARENT_CONVERSATION_ID ||
27
126
  process.env.ANTIGRAVITY_CONVERSATION_ID ||
28
127
  process.env.CONVERSATION_ID ||
29
128
  currentSessionId ||