# copilot-session

GitHub Copilot CLI JSONL adapter implementing the SessionSource protocol

## Installation

### From DevPi (private registry)

```bash
uv add copilot-session
```

> Requires the DevPi index to be configured in `~/.config/uv/uv.toml`:
> ```toml
> index-strategy = "unsafe-best-match"
>
> [[index]]
> name = "devpi"
> url = "https://pypi.registry.hochguertel.work/root/dev/+simple/"
> ```

### From source (monorepo)

```bash
git clone https://pastoral-oyster.pikapod.net/tools/ai-session-tools.git
cd ai-session-tools
uv sync --all-packages
```

## Usage

`CopilotSource` implements the `SessionSource` protocol for GitHub Copilot
CLI sessions. It reads from the `~/.copilot/session-state/` directory, which
contains both JSONL files (newer format) and session subdirectories with
`workspace.yaml` metadata (older format).

```python
from copilot_session import CopilotSource, CopilotConfig
from pathlib import Path

# Use default config (reads from ~/.copilot/session-state/)
source = CopilotSource()

# Or override the session directory
source = CopilotSource(CopilotConfig(session_dir=Path("/custom/session-state")))

# List recent Copilot sessions
sessions = source.list_sessions(limit=10)
for s in sessions:
    print(f"{s.session_id} — {s.title} ({s.message_count} messages)")

# Load a full session with all messages
session = source.load_session("abc-123")
for msg in session.messages:
    print(f"[{msg.role}] {msg.content[:80]}")

# Detect the most recently modified Copilot session
session_id = source.detect_current_session()
```

## Development

```bash
# Run tests
uv run pytest libs/copilot-session/tests/

# Lint
uv run ruff check libs/copilot-session/

# Type check
uv run mypy
```

## License

MIT
