Skip to content

Latest commit

Β 

History

History
178 lines (150 loc) Β· 9.66 KB

File metadata and controls

178 lines (150 loc) Β· 9.66 KB

AGENTS.md β€” AI Coding Assistant Instructions

This file provides context for AI coding assistants (Antigravity, Copilot, Cursor, etc.) working on this project.

Project Overview

OmniAntigravity Remote Chat (v1.3.0) is a premium mobile command center for Antigravity AI sessions.
Architecture: Node.js server connects to Antigravity via Chrome DevTools Protocol (CDP), mirrors the chat UI to a mobile browser via WebSocket, and adds remote workspace tools, supervisor intelligence, quota monitoring, and tunnel-based remote access.

Tech Stack

  • Runtime: Node.js 22+ (ESM modules, "type": "module")
  • Server: Express.js 4.22, WebSocket (ws 8.x), Cookie-based auth, compression
  • Frontend: Vanilla HTML/CSS/JS (no framework), 5 themes, PWA support
  • Protocol: Chrome DevTools Protocol (CDP) for Antigravity communication
  • Testing: Vitest 4.x (unit), custom smoke suite (integration)
  • Tunneling: Cloudflare Quick Tunnels, Pinggy (SSH-based), ngrok (optional)
  • Notifications: Telegram Bot (optional, lazy-loaded node-telegram-bot-api)
  • AI Supervisor: OmniRoute OpenAI-compatible API (optional)
  • Ports: CDP on 7800-7803 (configurable via CDP_PORTS), web server on 4747 (configurable via PORT)
  • Docker: node:22-alpine with production-only deps

Project Structure

src/
β”œβ”€β”€ server.js               β€” Main server: Express + WebSocket + CDP actions (3400+ lines)
β”œβ”€β”€ config.js               β€” Constants, env vars, feature flags, version
β”œβ”€β”€ env.js                  β€” dotenv bootstrap (resolves .env from project root)
β”œβ”€β”€ state.js                β€” Shared mutable state + JSDoc type definitions
β”œβ”€β”€ supervisor.js           β€” AI supervisor (OmniRoute), suggest queue, heuristic safety
β”œβ”€β”€ quota-service.js        β€” Model quota polling via language server HTTPS API
β”œβ”€β”€ session-stats.js        β€” In-memory session analytics and metrics
β”œβ”€β”€ screenshot-timeline.js  β€” Persistent screenshot capture with disk storage
β”œβ”€β”€ ui_inspector.js         β€” UI DOM inspection utilities
β”œβ”€β”€ cdp/
β”‚   └── connection.js       β€” CDP discovery, WebSocket connect, context management
└── utils/
    β”œβ”€β”€ network.js          β€” getLocalIP, isLocalRequest, getJson
    β”œβ”€β”€ process.js          β€” killPortProcess, isPortFree, launchAntigravity
    β”œβ”€β”€ hash.js             β€” djb2 hash for snapshot diff detection
    β”œβ”€β”€ telegram.js         β€” Telegram bot: commands, inline keyboards, rate-limiting, threading
    └── workspace.js        β€” File browser, terminal manager, Git actions, quick commands, uploads

public/
β”œβ”€β”€ index.html              β€” Main mobile chat interface
β”œβ”€β”€ login.html              β€” Authentication page
β”œβ”€β”€ admin.html              β€” Admin panel (metrics, logs, tunnel control)
β”œβ”€β”€ minimal.html            β€” Lite mode for unstable connections
β”œβ”€β”€ manifest.json           β€” PWA manifest
β”œβ”€β”€ sw.js                   β€” Service worker
β”œβ”€β”€ css/                    β€” Modular CSS: variables, themes (5), layout, components, workspace, assist, chat
β”œβ”€β”€ js/
β”‚   β”œβ”€β”€ app.js              β€” Main client logic (WebSocket, rendering, UI state)
β”‚   β”œβ”€β”€ admin.js            β€” Admin panel logic
β”‚   β”œβ”€β”€ login.js            β€” Login page logic
β”‚   β”œβ”€β”€ minimal.js          β€” Lite mode logic
β”‚   β”œβ”€β”€ theme-bootstrap.js  β€” Theme initialization (CSP-compliant external script)
β”‚   └── components/         β€” Modular workspace panels (assist, files, git, stats, terminal, timeline)
└── icons/                  β€” SVG app icons (standard + maskable)

scripts/
β”œβ”€β”€ cloudflare-tunnel.js    β€” Cloudflare Quick Tunnel manager
β”œβ”€β”€ pinggy-tunnel.js        β€” Pinggy SSH tunnel manager
β”œβ”€β”€ generate_ssl.js         β€” SSL certificate generator (OpenSSL + Node.js crypto fallback)
β”œβ”€β”€ setup-ssl.js            β€” Interactive SSL setup with mkcert
β”œβ”€β”€ install_context_menu.*  β€” OS context menu installers (Windows/Linux)
β”œβ”€β”€ start.sh / start.bat    β€” Shell launchers (local)
β”œβ”€β”€ start_web.sh / start_web.bat β€” Shell launchers (remote)
β”œβ”€β”€ sync_features.py        β€” Feature sync utility
└── windows-wsl-remote/     β€” PowerShell scripts for WSL2 integration

test/
β”œβ”€β”€ test.js                 β€” Integration/smoke test suite
└── unit/                   β€” Vitest unit tests (9 test files)
    β”œβ”€β”€ config.test.js
    β”œβ”€β”€ hash.test.js
    β”œβ”€β”€ network.test.js
    β”œβ”€β”€ quota-service.test.js
    β”œβ”€β”€ screenshot-timeline.test.js
    β”œβ”€β”€ session-stats.test.js
    β”œβ”€β”€ supervisor.test.js
    └── telegram.test.js

launcher.js                 β€” Node.js entry point (QR code, tunnel orchestration)
data/                       β€” Runtime data (quick-commands.json, screenshots/, uploads/)
docs/                       β€” Extended documentation (CODE_DOCUMENTATION, plans, competitive analysis)

Key Patterns

  • ESM imports β€” All .js files use import/export, not require(). Exceptions: fix_ts.cjs and sync_wsl.cjs (CommonJS utilities)
  • PROJECT_ROOT β€” src/config.js uses join(__dirname, '..') as PROJECT_ROOT since it lives in src/
  • CDP connection β€” discoverCDP() scans configurable ports (default 7800-7803) for Antigravity targets
  • Multi-window β€” discoverAllCDP() returns all available CDP workbench targets across ports
  • Auth β€” Cookie-based via omni_ag_auth, password from APP_PASSWORD env var, LAN auto-auth
  • CSP enforcement β€” Strict Content-Security-Policy via both HTTP header and meta tags; zero inline JS
  • Snapshot polling β€” Background loop captures DOM snapshots, detects changes via hash, and broadcasts via WebSocket
  • Tunnel support β€” Multi-provider tunnel system (Cloudflare, Pinggy, ngrok) with automatic fallback
  • Supervisor β€” OmniRoute-backed AI supervisor with heuristic safety gates and suggest queue
  • Quota monitoring β€” Discovers local language_server processes, probes HTTPS endpoints for quota data
  • Screenshot timeline β€” Disk-persisted screenshot captures with manifest, auto-capture on change, pruning
  • Session stats β€” In-memory metrics (messages, approvals, errors, uploads, screen activity)
  • Telegram integration β€” Lazy-loaded bot with commands, inline keyboards, rate-limiting, message threading
  • Workspace tools β€” File browser, terminal streaming, Git panel, assist chat, all via REST API
  • Theme system β€” 5 themes (dark, light, slate, pastel, rainbow) with CSS variables and persistence

API Surface (60+ endpoints)

Core

  • POST /login, POST /logout, GET /health, GET /snapshot

Chat Control

  • POST /send, POST /stop, POST /set-mode, POST /set-model
  • POST /new-chat, GET /chat-history, POST /select-chat, GET /chat-status

CDP / Multi-Window

  • GET /cdp-targets, POST /select-target, POST /api/launch-window
  • POST /remote-click, POST /remote-scroll, GET /app-state

Workspace

  • GET /api/fs/ls, GET /api/fs/cat
  • GET /api/terminal/history, POST /api/terminal/run, POST /api/terminal/stop
  • GET /api/git/status, POST /api/git/add, POST /api/git/commit, POST /api/git/push
  • GET /api/quick-commands, PUT /api/admin/quick-commands

Supervisor & Suggestions

  • POST /api/interact-action
  • GET /api/suggestions, GET /api/suggestions/pending
  • POST /api/suggestions/:id/approve, POST /api/suggestions/:id/reject
  • DELETE /api/suggestions

Analytics & Monitoring

  • GET /api/stats, GET /api/quota
  • GET /api/timeline, GET /api/timeline/:filename, POST /api/timeline/capture, DELETE /api/timeline

Assist

  • POST /api/assist/chat, GET /api/assist/history, DELETE /api/assist/history

Screencast & Media

  • GET /api/screencast/status, POST /api/screencast/start, POST /api/screencast/stop
  • POST /api/upload-image

Admin

  • GET /admin, GET /api/admin/logs, GET /api/admin/metrics
  • GET /api/admin/tunnel, POST /api/admin/tunnel/start, POST /api/admin/tunnel/stop

Debug

  • GET /ssl-status, POST /generate-ssl, GET /debug-ui, GET /ui-inspect, GET /minimal

Development Commands

npm start                # Start server directly
npm run dev              # Dev server (alias for start)
npm run start:local      # Launch with QR code (Wi-Fi)
npm run start:web        # Launch with tunnel (Cloudflare preferred)
npm run start:web:pinggy # Launch with Pinggy tunnel
npm run setup:ssl        # Generate trusted HTTPS certificates
npm test                 # Run integration/smoke test suite
npm run test:unit        # Run Vitest unit tests
npm run test:unit:watch  # Run Vitest in watch mode
npm run test:coverage    # Run Vitest with V8 coverage
npm run test:all         # Run both smoke + unit tests

Important Notes

  • Never use require() β€” this is an ESM project ("type": "module")
  • The public/ directory is served as static files from PROJECT_ROOT
  • SSL certs go in certs/ at project root (auto-generated via scripts/setup-ssl.js)
  • .env contains secrets β€” never commit it (it's in .gitignore)
  • Runtime data lives in data/ (quick-commands.json, screenshots/, uploads/)
  • The _tasks/ and _references/ directories are internal development tracking β€” not part of the product
  • Frontend workspace panels in public/js/components/ are modular and self-contained
  • Telegram bot is lazy-loaded β€” the server works fine without node-telegram-bot-api installed
  • The supervisor is optional β€” set OMNIROUTE_SUPERVISOR_ENABLED=true to activate
  • CSP is enforced both via HTTP header and HTML meta tags for defense-in-depth