Skip to main content
Glama
session-bridge
by Mahyardana
README.md
# omp-agy-bridge

> **Bidirectional session bridge between [oh-my-pi (`omp`)](https://github.com/can1357/oh-my-pi) and Google Antigravity CLI (`agy`).**

Move seamlessly back and forth between `omp` and `agy` without losing conversation context, tool history, or workspace continuity — via **CLI**, **MCP server**, or **built-in Agent Skills**.

- **Zero dependencies** — pure Python 3 standard library (`bridge.py` + stdio JSON-RPC 2.0 `mcp_server.py`).
- **Native AGY → OMP conversion** — writes genuine, resumable OMP v3 `.jsonl` session trees directly into `~/.omp/agent/sessions/<encoded-cwd>/` so `omp -r <id>` opens the full history natively with 1:1 `toolCall`/`toolResult` pairing and automatic default-model restoration.
- **Smart OMP → AGY handoff** — walks OMP's branched `id`/`parentId` tree, respects compaction summaries and `context_edit` pruning, fits massive multi-megabyte sessions cleanly within a configurable character budget, archives the complete verbatim transcript on disk, and either injects directly into your active `agy` session via MCP or launches/creates a saved `agy` conversation.
- **Sandbox-friendly** — running as a host stdio MCP server lets both `agy` and `omp` read each other's session stores seamlessly across any workspace.

---

## Architecture

```mermaid
flowchart LR
    OMP["oh-my-pi (omp)<br/>~/.omp/agent/sessions/*.jsonl"]
    AGY["Antigravity CLI (agy)<br/>~/.gemini/antigravity-cli/"]

    subgraph Bridge["omp-agy-bridge (Pure Python 3 Stdlib)"]
        CORE["bridge.py<br/>Tree Parser • Compaction-Aware Formatter<br/>Native OMP v3 Writer • AGY API/CLI Seeder"]
        CLI["CLI: omp-agy"]
        MCP["Stdio MCP Server: session-bridge<br/>(6 tools, JSON-RPC 2.0)"]
        SKILLS["Agent Skills<br/>AGY + OMP SKILL.md"]
    end

    OMP <--> CORE
    AGY <--> CORE
    CLI --> CORE
    MCP --> CORE
    SKILLS -.guides.-> MCP
```

---

## Quickstart

### One-command install (recommended)

```bash
git clone https://github.com/Mahyardana/omp-agy-bridge.git
cd omp-agy-bridge
./install.sh
```

`install.sh` automatically:
1. Installs the core modules to `~/.local/share/omp-agy-bridge/`
2. Installs `omp-agy` and `omp-agy-mcp` to `~/.local/bin/`
3. Registers the `session-bridge` MCP server in both **AGY** (`~/.gemini/config/mcp_config.json`) and **OMP** (`~/.omp/agent/mcp.json`)
4. Installs the `session-bridge` skill in both **AGY** (`~/.gemini/config/skills/`) and **OMP** (`~/.omp/agent/skills/`)

Restart `agy` / `omp` so they pick up the new MCP server and skills.

> **Alternative (`pip` / `uv`):** You can also install the Python package via `pip install -e .` (or `uv tool install .`), which exposes the `omp-agy` and `omp-agy-mcp` console entrypoints.

---

## Usage

### 1. Inside `agy` or `omp` (Natural Language via MCP + Skill)

Just talk to either agent:

- **In `agy`:**
  - *"Import my latest omp session"*
  - *"List my omp sessions for this repo and import the most recent one"*
  - *"Export this conversation to omp"*
- **In `omp`:**
  - *"Import my latest agy session"*
  - *"Convert my latest agy conversation into a native omp session"*
  - *"Export this session to agy"*

### 2. Terminal CLI (`omp-agy`)

```bash
# List recent sessions across both tools (filter by source, workspace, or keyword)
omp-agy list
omp-agy list --source omp --cwd .
omp-agy list --query auth --limit 10

# Preview turns from any session
omp-agy show omp latest --start 0 --limit 10
omp-agy show agy latest --no-tools

# AGY -> OMP (writes a native resumable OMP v3 .jsonl session)
omp-agy agy2omp latest --open                    # Convert & immediately launch `omp -r <id>`
omp-agy agy2omp <id-prefix> --mode full          # Full native toolCall/toolResult history (default)
omp-agy agy2omp <id-prefix> --mode compact       # Merges tool actions into compact turn summaries
omp-agy agy2omp <id-prefix> --mode conversation  # Pure user/assistant text turns only

# OMP -> AGY
omp-agy omp2agy latest --open                    # Immediately open interactive `agy -i` in workspace
omp-agy omp2agy latest --create                  # Create a saved AGY conversation for `agy -r <id>`
omp-agy omp2agy latest --file-only               # Write handoff + full verbatim markdown archive only
```

### 3. MCP Tools Exposed (`session-bridge`)

| Tool | Description |
|---|---|
| `list_sessions` | List `omp`, `agy`, or `all` sessions newest-first with IDs, titles, workspaces, timestamps, and sizes. |
| `import_omp_session` | Load an OMP session directly into the active conversation (compaction-aware, budget-capped, with full verbatim archive on disk). |
| `import_agy_session` | Load an AGY conversation directly into the active conversation. |
| `export_agy_to_omp` | Convert an AGY conversation into a **native resumable OMP v3 `.jsonl` session** and return `omp -r <id>`. |
| `export_omp_to_agy` | Export an OMP session into AGY (creates a saved conversation via `ConversationService` or `agy -p`, or writes a handoff file). |
| `read_session_turns` | Paginate message-by-message through any `omp` or `agy` session (ideal for inspecting earlier turns of huge sessions). |

---

## How It Works Under the Hood

### AGY → OMP (Native Session Tree Writer)
- Reads AGY metadata (`title`, `workspace_uris`, `step_count`) from `~/.gemini/antigravity-cli/conversation_summaries.db` (read-only) and turns from `brain/<id>/.system_generated/logs/transcript_full.jsonl`.
- Strips internal AGY metadata wrappers (`<ADDITIONAL_METADATA>`, `<USER_SETTINGS_CHANGE>`, system efficiency nudges) while preserving user requests, assistant responses, thinking blocks, and tool executions.
- Maps AGY tools (`run_command`, `read_file`, `write_file`, `edit_file`, `search_web`) to OMP equivalents (`bash`, `read`, `write`, `edit`, `web_search`) and guarantees strict 1:1 `toolCall` ↔ `toolResult` pairing.
- Detects your default OMP model from `~/.omp/agent/config.yml` (`modelRoles.default`) and emits `model_change` entries so `omp -r <id>` restores cleanly without `SessionModelRestoreError`.
- Encodes the workspace `cwd` using OMP's directory bucketing convention (reusing existing matching session folders when present) and writes the `.jsonl` atomically.

### OMP → AGY (Compaction-Aware Handoff + Archive)
- Walks OMP's `id`/`parentId` tree along the active branch, respecting `compaction` boundaries and `context_edit` deletions.
- Always saves the complete verbatim markdown transcript to `~/.local/share/omp-agy-bridge/exports/` so nothing is ever lost.
- Produces a budget-aware handoff (preserving compaction summaries/initial goals + as many recent turns verbatim as fit within `max_chars`), usable directly in your current AGY session via MCP, launched interactively with `agy -i`, or seeded into a saved AGY conversation via `ConversationService` / `agy -p`.

---

## Running Tests

```bash
python3 -m unittest discover -s tests -v
```

## Uninstall

```bash
./uninstall.sh
```

## License

[MIT](LICENSE)

TDQS

A3.9/5.0

Scored across 6 tools

Disambiguation4/5

Each tool maps to a distinct operation (list, import, export, paginate) and the import/export tools encode source and direction explicitly in their names, so selection is largely unambiguous. The only soft spot is import_agy_session vs export_agy_to_omp, which both move agy content but into different destinations (context vs native omp file) and require reading descriptions to separate.

Naming Consistency5/5

All tools are snake_case and verb-first (list_, import_, export_, read_) with the same noun vocabulary (session/sessions, omp, agy). The source/target suffixes are applied symmetrically, making the pairs predictable.

Tool Count5/5

Six tools is well-scoped for a session bridge: enumerate, read, import each direction, export each direction. Every tool covers a distinct quadrant of the matrix with no filler.

Completeness4/5

The list/read/import/export matrix across both omp and agy is covered, including pagination for large sessions. Minor gaps remain: no search or filter of sessions by keyword/workspace, and no way to manage, prune, or delete the archived verbatim transcripts written to disk.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues