Add a new AI CLI as a session source for atm (discover + parse its on-disk sessions, central HarnessSpec registration, tests, trilingual docs). Use when asked to support another coding agent CLI such as Gemini CLI, OpenCode, Grok Build.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Add Session Source?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/lyfuci-add-session-source)
---
name: add-session-source
description: Add a new AI CLI as a session source for atm (discover + parse its on-disk sessions, central HarnessSpec registration, tests, trilingual docs). Use when asked to support another coding agent CLI such as Gemini CLI, OpenCode, Grok Build.
---
# Add a session source
A "source" is one CLI whose sessions atm can list and resume. Built-in source metadata and downstream wiring
are centralized in `src/atm/harnesses.py`, so adding a new built-in source only touches the adapter,
`model.Source`, `harnesses.HARNESSES`, tests, and docs — guard tests in `tests/test_harnesses.py`,
`tests/test_dispatch.py`, `tests/test_grouping.py`, `tests/test_sources.py`, `tests/test_config.py`, and
`tests/test_i18n.py` enforce completeness automatically.
## 0. Before writing code: qualify the CLI
Three conditions, all required:
1. It runs in a terminal pane (a GUI app has no pane to swap).
2. It writes **one file per session** (or a single SQLite DB with per-session `<db>#<id>` synthetic `FileRef`s) on disk, and carries the session id and the cwd.
3. It has a **resume-by-id** command (`claude --resume <id>`, `codex resume <id>`, `pi --session <id>`).
Find out — by reading real files if the CLI is installed, otherwise from upstream docs — and write down:
- root directory and filename pattern (or SQLite DB path); how many directory levels to scan (Claude: exactly one — recursing picks up 1332 sub-artefacts with no session id of their own)
- which record/column carries `id` / `cwd` / `git branch`; whether they are in the file head (atm reads heads only: 198 ms cold start over 1.73 GB depends on it)
- how the display title is produced and whether it can change later in the file (Pi's `session_info` can be renamed — scan the tail too)
- which "user" messages are actually injected wrappers (`<local-command-caveat>`, `<environment_context>`, tool results masquerading as user turns) and must be skipped for the title
- the exact resume argv (plus any short flag or alias for `atm restore`)
If the adapter is written from docs rather than observed data, **say so in the module docstring, in the PR, and in
docs/reference.md** — Pi's adapter is marked this way.
## 1. `src/atm/sources/<name>.py`
Implement the standard adapter surface:
```python
DEFAULT_ROOT = Path.home() / "..."
def discover(root: Path | None = None) -> Iterator[FileRef]: ...
def parse(ref: FileRef) -> SessionEntry | None: ...
```
Optional adapter hooks recognized automatically by `index.py`, `restore.py`, `cli.py`, and `harnesses.py`:
- `default_root() -> Path`: optional custom root resolver; for a simple single-env-var override, setting `root_env` on `HarnessSpec` suffices for both `index.build()` and `atm doctor` (implement `default_root()` only for custom parsing such as comma-separated env values or direct `discover(None)` calls).
- `prepare_ingest(root: Path | None = None, roots: object | None = None) -> tuple[Iterator[FileRef], Callable[[FileRef], SessionEntry | None]]`: preloads per-build shared state (legacy index, project registry, or SQLite session map) once per index build.
- `latest_raw_name(path: str) -> str | None`: full-file rescan of the latest user-assigned name (pair with `supports_rename_rescan=True` on `HarnessSpec`).
- `doctor_extra(root: Path | None = None) -> dict[str, Any]`: extra per-source fields merged into `atm doctor --json`.
Rules:
- Never import `tmux.py`, `curses`, `config`, `dispatch`, `restore`, or `sidebar` in `sources/` (enforced by `tests/test_harnesses.py`).
- `discover(root)` must accept an override (tests pass `tmp_path`). Open SQLite stores read-only (`mode=ro`).
- Read the head only (`_MAX_RECORDS`), then a bounded tail scan only if the format needs it.
- Every JSON access is defensive: `.get`, isinstance checks, `continue` on garbage. Return `None` for a file that yields no usable entry — never raise.
- Filename-derived ids must be validated (`_ID_RE`); reject rather than fabricate.
- Use `text.clean_title(...)` for titles; it strips the known injection wrappers.
## 2. Central Registration (`model.py` + `harnesses.py`)
Only two core files need changes:
| File | Change |
|---|---|
| `src/atm/model.py` | Add `Source.<NAME> = "<name>"` |
| `src/atm/harnesses.py` | Append a `HarnessSpec(...)` entry to `HARNESSES` (`tag`, `display_name`, `tab_label`, `program`, `resume_argv`, `module_name`, optional `short_resume_flag`, `extra_resume_flags`, `set_initial_pane_title`, `supports_rename_rescan`, `root_env`, `cache_path_markers`, `cache_db_name`, `cache_match_priority`) |
Everything downstream (`SOURCE_TAG`, `sources/__init__.py`, `index.py` ingestion & `_cached_source`, `dispatch.RESUME_PROGRAMS` & pane title, `restore` short/extra flags & rename rescan, `sidebar.AI_COMMANDS`, `cli.LAUNCH_PROGRAMS` & `doctor`, `tui._AGENT_NAME` & `Tab` help, `sidebar_tui` help, and `conftest.py` root isolation) derives automatically from `HARNESSES`. No edits to those modules or `i18n_catalog.py` are needed.
If the source's default root sits inside another source's directory tree (like `agy` under `~/.gemini/`), set a higher `cache_match_priority` so negative cache entries are not misattributed during filtered `--source` builds.
## 3. Tests (`tests/`)
- `conftest.py`: `_isolate_source_roots` automatically isolates `DEFAULT_ROOT` and `spec.root_env` for every entry in `HARNESSES`; add a `<name>_root` fixture (and synthetic DB/JSONL helper if needed) under `tmp_path` — never real data.
- `test_sources.py`: discover finds files and skips the wrong depth; parse yields id/cwd/title; malformed file → `None`; injected wrappers are not used as titles; late rename is picked up (if applicable); filename with a bad id is rejected.
- `test_harnesses.py`: add a negative-cache path case to `test_cached_source_attribution_for_every_source_and_agy_precedence`; existing guard tests automatically verify registration completeness, uniqueness, `RESERVED_SUBCOMMANDS` non-collision, `SourceRoots`, `doctor`, `dispatch`/`restore`/`tui`/`sidebar_tui` wiring, and `tmux`-import isolation.
## 4. Docs — three languages, same commit
- `README.md` / `README-cn.md` / `README-ja.md`: the "What it is" line and the Requirements bullet list the CLIs and their session directories.
- `docs/usage.md` / `-cn` / `-ja`: the `Tab` cycle list and `--source` values in the usage guide.
- `docs/reference.md` (Chinese): "数据来源" section — add the root, filename pattern, which record carries what, the resume command, and whether it was verified on real data.
- `research/README*.md`: the "Sidebar data sources" section gets a paragraph like Pi's.
## 5. Verify
```bash
uv run --frozen ruff check . && uv run --frozen ruff format --check .
uv run --frozen pytest
uv run --frozen atm doctor --json # new root reported; program on PATH or not
uv run --frozen atm list --source <name> -n 5
```
If the CLI is installed, resume one real session through `atm resume <id-prefix> --print` and run the printed line
by hand. If it is not installed, say so in the PR and ask for verification on a machine that has it.