feat: auto-discover runners (#12)

This commit is contained in:
banteg
2026-01-01 20:31:11 +04:00
committed by GitHub
parent 936ea5109b
commit d35752fc55
21 changed files with 1069 additions and 698 deletions
+12 -12
View File
@@ -94,15 +94,19 @@ Notes:
## Code changes (by file)
### 1) `src/takopi/engines.py`
### 1) New file: `src/takopi/runners/claude.py`
Add a new backend:
#### Backend export
* Engine ID: `EngineId("claude")`
Expose a module-level `BACKEND = EngineBackend(...)` (from `takopi.backends`).
Takopi auto-discovers runners by importing `takopi.runners.*` and looking for
`BACKEND`.
* `check_setup()` should:
`BACKEND` should provide:
* `shutil.which("claude")` must exist.
* Engine id: `"claude"`
* `install_cmd`:
* Install command for `claude` (used by onboarding when missing on PATH).
* Error message should include official install options and “run `claude` once to authenticate”.
* Install methods include install scripts, Homebrew, and npm. ([Claude Code][4])
@@ -110,11 +114,7 @@ Add a new backend:
* `build_runner()` should parse `[claude]` config and instantiate `ClaudeRunner`.
* `startup_message()` e.g.:
* `takopi (claude) is ready\npwd: ...`
### 2) New file: `src/takopi/runners/claude.py`
#### Runner implementation
Implement a new `Runner`:
@@ -319,7 +319,7 @@ Mirror the existing `CodexRunner` tests patterns.
1. **Contract & locking**
* `test_run_serializes_same_session` (stub `_run` like Codex tests)
* `test_run_serializes_same_session` (stub `run_impl` like Codex tests)
* `test_run_allows_parallel_new_sessions`
* `test_run_serializes_new_session_after_session_is_known`:
@@ -367,7 +367,7 @@ Mirror the existing `CodexRunner` tests patterns.
## Implementation checklist
* [ ] Add `ClaudeBackend` in `src/takopi/engines.py` and register in `ENGINES`.
* [ ] Export `BACKEND = EngineBackend(...)` from `src/takopi/runners/claude.py`.
* [ ] Add `src/takopi/runners/claude.py` implementing the `Runner` protocol.
* [ ] Add tests + stub executable fixtures.
* [ ] Update README and developing docs.
+4 -6
View File
@@ -44,8 +44,8 @@ Notes:
`claude --resume <session_id>`
```
Runner must implement its own regex (cannot use `compile_resume_pattern` because
that only matches `<engine> resume <token>`). Suggested regex:
Runner must implement its own regex because the resume format is
`claude --resume <session_id>`. Suggested regex:
```
(?im)^\s*`?claude\s+(?:--resume|-r)\s+(?P<token>[^`\s]+)`?\s*$
@@ -202,11 +202,9 @@ Add a Claude runner without changing the Takopi domain model:
1. Create `takopi/runners/claude.py` implementing `Runner` and (custom)
resume parsing.
2. Update `takopi/engines.py`:
- add `claude` backend id
- `check_setup`: locate `claude` binary (PATH + common locations)
2. Define `BACKEND` in `takopi/runners/claude.py`:
- `install_cmd`: install command for the `claude` binary
- `build_runner`: read `[claude]` config + construct runner
- `startup_message`: `"claude is ready\npwd: <cwd>"`
3. Add new docs (this file + `claude-stream-json-cheatsheet.md`).
4. Add fixtures in `tests/fixtures/` (see below).
5. Add unit tests mirroring `tests/test_codex_*` but for Claude translation