Spaces:
Configuration error
Configuration error
Document Antigravity sync automation workaround
Browse filesFiles changed (2)
- agentmemory.mdAdded+33
- plugin/antigravity.mdAdded+70
123456789101112131415161718192021222324252627282930313233# AgentMemory Automation & Client Hook Roundabout
This file documents the technical details and configurations for automating memory sessions, observations, and prompt-context syncing in environments that lack native client-side hook runners.
---
## 1. PowerShell-Level Console Hook AutomationFor standard command shells that do not have custom plugins (such as PowerShell), we have implemented a native console hook system directly in the user profile:* **Profile File**: `D:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`* **Automation Mechanism**: 1. **Prompt Redefinition**: Overrides the default PowerShell `prompt` function to retrieve the last executed command from the session history (`Get-History`). 2. **Asynchronous Dispatch**: Uses PowerShell's `Start-Job` to send the command, execution status, and duration to the Hugging Face Space database (`https://yash030-agentmemory-python.hf.space/agentmemory/observe`) in the background, keeping terminal prompts lag-free. 3. **Interactive Shield**: Wraps the prompts and startup session creation in `if (-not [Console]::IsInputRedirected)` so background script executions or tool runners do not pollute the database. 4. **Active Session Reuse**: On console startup, checks for a cached session ID in `current_session.txt` and reuses it to prevent session clutter.
---
## 2. Antigravity Chat Sync LoopBecause the Gemini Antigravity agent runs inside a transient prompt-response loop sandbox, we automate chat log syncing through a shell-level daemon job:* **Sync Script**: `C:\Users\yashw\.gemini\antigravity\sync_antigravity.py`* **Daemon Job**: Appended to the PowerShell profile as a background `Start-Job` loop named `AntigravitySync`.* **Execution Heuristic**: - The job runs a continuous loop that executes the sync script every 30 seconds. - Uses a lock file (`sync_antigravity.lock`) to ensure only a single terminal window runs the sync globally. - The script parses `transcript.jsonl` from the local `brain/` directory and uploads new user prompts and response turns to the Hugging Face Space under the session `antigravity_<conversation_id>`.
---
## 3. Configuration & ControlsTo control this automation inside PowerShell, use the following commands:* **`Start-MemorySession -project "name"`**: Starts a new memory session. Use the `-Force` switch to override any active session.* **`End-MemorySession`**: Ends the active session, marking it completed and cleaning up the local cache file.* **`Get-Job -Name "AntigravitySync"`**: Checks the status of the background chat sync thread.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970# Antigravity Memory Integration (The Shell-Level Hook Automation)
This document details the background syncing and terminal prompt automation workaround implemented to support seamless long-term memory capture and context injection for the **Gemini Antigravity** coding agent.
---
## The ChallengeUnlike client agents like Claude Code or Codex, which have built-in client configuration hook runners (like `UserPromptSubmit` or `PreToolUse`), Antigravity runs inside a transient, reactive sandbox without any native client-side hooks. This makes it impossible for the agent itself to trigger startup/shutdown registration or command-level logging automatically.
---
## The Solution (The Roundabout)To achieve seamless, zero-reminder automation, we moved the integration logic from the agent sandbox into the **local shell environment itself**.
```[ PowerShell Console ] βββ Prompt Loop Hook (Asynchronous post-execution capture) βββ Startup Auto-Register (Detects Git project context & starts session) βββ Background Sync Job (Polls and uploads transcript.jsonl every 30s) β βΌ [ Hugging Face Space Database ] (https://yash030-agentmemory-python.hf.space)```
### 1. Active Chat Syncing (`sync_antigravity.py`)Located in the local application folder (`C:\Users\yashw\.gemini\antigravity\sync_antigravity.py`), this script runs outside the sandbox to bridge chat logs into the memory space:* **Transcript Parsing**: Reads the active conversation logs (`brain/<conversation_id>/.system_generated/logs/transcript.jsonl`).* **Observation Registry**: Formats and POSTs new user prompts and responses as observations under the session key `antigravity_<conversation_id>`.* **State Verification**: Checks existing observations first to ensure no duplicates are uploaded.
### 2. PowerShell Profile Integration (`Microsoft.PowerShell_profile.ps1`)To automate execution, we injected the sync loops and shell prompt captures directly into your PowerShell profile.
#### A. Interactive Check```powershellif (-not [Console]::IsInputRedirected) { # Define prompt hooks and background jobs here}```Ensures that prompt redefinitions and auto-start logic only run in real interactive terminals, completely preventing script runs or tool runners from spamming the database.
#### B. Active Session Reuse```powershellif (-not $Force -and (Test-Path $global:agentMemorySessionFile)) { $sessionId = Get-Content $global:agentMemorySessionFile -Raw if ($sessionId) { Write-Host "[AgentMemory] Reusing active session: $sessionId" -ForegroundColor Cyan return }}```Checks for an existing session ID in a local cache file (`current_session.txt`) on startup and reuses it. This prevents the creation of duplicate session IDs when opening multiple terminal tabs.
#### C. Async Console Command Capturing```powershellfunction prompt { $lastCommand = Get-History -Count 1 # ... format and POST to /observe in background job ...}```Redefines the terminal prompt to asynchronously log the execution status, command line, and duration of every command to the database in background threads, keeping terminal performance instantaneous.
#### D. Global Lock File Check```powershellStart-Job -Name "AntigravitySync" -ScriptBlock { # Check lock file modification time # If active instance exists, exit; otherwise, run sync_antigravity.py loop every 30s}```Uses a timestamp-based lock file (`sync_antigravity.lock`) so that only a single terminal window runs the background sync job globally, preventing CPU and network overhead.agentmemory.mdAdded+33
plugin/antigravity.mdAdded+70