|
| 1 | +# Cloud Runs CLI Mirrors Implementation Plan |
| 2 | + |
| 3 | +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. |
| 4 | +
|
| 5 | +**Goal:** Add read-only cloud run inspection from the terminal: `codealmanac runs list`, `codealmanac runs show <run-id>`, and `codealmanac runs logs <run-id>`. |
| 6 | + |
| 7 | +**Architecture:** Keep local execution under `jobs`; add a separate cloud `runs` path that uses the stored CLI token and current GitHub checkout to resolve the cloud repository. Hosted adds CLI-token `/v1` run read routes that mirror existing browser `/api` run routes without account-scoped URL parameters. |
| 8 | + |
| 9 | +**Tech Stack:** FastAPI, Pydantic DTOs, SQL-backed hosted `Updates` service, CodeAlmanac Python services/workflows, argparse CLI, pytest. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Scope |
| 14 | + |
| 15 | +Implement now: |
| 16 | + |
| 17 | +- Hosted `/v1/repositories/{repo_id}/runs` |
| 18 | +- Hosted `/v1/runs/{run_id}` |
| 19 | +- Hosted `/v1/runs/{run_id}/events` |
| 20 | +- CodeAlmanac `cloud_runs` service and HTTP adapter methods |
| 21 | +- CodeAlmanac `cloud_runs` workflow that resolves the current checkout through the same local Git probe as `repo status` |
| 22 | +- CLI: |
| 23 | + - `codealmanac runs list [--limit N] [--json]` |
| 24 | + - `codealmanac runs show <run-id> [--json]` |
| 25 | + - `codealmanac runs logs <run-id> [--json]` |
| 26 | + |
| 27 | +Defer: |
| 28 | + |
| 29 | +- `codealmanac runs start` |
| 30 | +- `codealmanac runs cancel` |
| 31 | +- `codealmanac runs retry` |
| 32 | +- Browser UI changes |
| 33 | +- Worker lifecycle changes |
| 34 | + |
| 35 | +Reason for deferral: read-only inspection uses existing service semantics. Start/cancel/retry need explicit queue, billing, GitHub check, and worker-state semantics. |
| 36 | + |
| 37 | +## Design Wireframe |
| 38 | + |
| 39 | +```python |
| 40 | +# Hosted route edge |
| 41 | +user = current_cli_user(token) |
| 42 | +page = almanac.updates.runs_for_repo(user, repo_id, PageRequest(...)) |
| 43 | +run = almanac.updates.run_for_user(user, run_id) |
| 44 | +events = almanac.updates.run_events_for_user(user, run_id) |
| 45 | + |
| 46 | +# CodeAlmanac package API |
| 47 | +repo_status = app.workflows.cloud_repo.status(...) |
| 48 | +runs = app.cloud_runs.list_for_repo(repo_status.repository.repo_id) |
| 49 | +run = app.cloud_runs.show(run_id) |
| 50 | +events = app.cloud_runs.events(run_id) |
| 51 | + |
| 52 | +# CLI edge |
| 53 | +codealmanac runs list |
| 54 | +codealmanac runs show <run-id> |
| 55 | +codealmanac runs logs <run-id> |
| 56 | +``` |
| 57 | + |
| 58 | +## Task 1: Hosted CLI Run Routes |
| 59 | + |
| 60 | +**Files:** |
| 61 | + |
| 62 | +- Create: `/Users/rohan/.config/superpowers/worktrees/usealmanac/hosted-baseline-convergence/backend/src/almanac/server/cli_runs_router.py` |
| 63 | +- Modify: `/Users/rohan/.config/superpowers/worktrees/usealmanac/hosted-baseline-convergence/backend/src/almanac/server/app.py` |
| 64 | +- Test: `/Users/rohan/.config/superpowers/worktrees/usealmanac/hosted-baseline-convergence/backend/tests/test_cli_runs_api_contract.py` |
| 65 | + |
| 66 | +**Steps:** |
| 67 | + |
| 68 | +1. Add tests proving `/v1/repositories/{repo_id}/runs`, `/v1/runs/{run_id}`, and `/v1/runs/{run_id}/events` authenticate through `cli_tokens.authenticate`. |
| 69 | +2. Implement `cli_runs_router.py` with `current_cli_user` and existing `RunDTO`, `RunEventDTO`, and `PageDTO`. |
| 70 | +3. Include the router in `server/app.py`. |
| 71 | +4. Run: |
| 72 | + ```bash |
| 73 | + cd /Users/rohan/.config/superpowers/worktrees/usealmanac/hosted-baseline-convergence/backend |
| 74 | + uv run pytest tests/test_cli_runs_api_contract.py tests/test_repositories_api_contract.py tests/test_updates_contract.py -q |
| 75 | + ``` |
| 76 | + |
| 77 | +Expected: all pass. |
| 78 | + |
| 79 | +## Task 2: CodeAlmanac Cloud Runs Service |
| 80 | + |
| 81 | +**Files:** |
| 82 | + |
| 83 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/services/cloud_runs/models.py` |
| 84 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/services/cloud_runs/ports.py` |
| 85 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/services/cloud_runs/requests.py` |
| 86 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/services/cloud_runs/service.py` |
| 87 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/services/cloud_runs/__init__.py` |
| 88 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/integrations/cloud/http.py` |
| 89 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/app.py` |
| 90 | +- Test: `/Users/rohan/Desktop/Projects/codealmanac/tests/test_cloud_runs_service.py` |
| 91 | + |
| 92 | +**Steps:** |
| 93 | + |
| 94 | +1. Add Pydantic models for cloud run source, run, event, and paged list. |
| 95 | +2. Add a service-owned `CloudRunsClient` protocol. |
| 96 | +3. Add request objects for list/show/events. |
| 97 | +4. Add HTTP adapter parsing for hosted run DTOs. |
| 98 | +5. Wire `CloudRunsService` in `create_app`. |
| 99 | +6. Run: |
| 100 | + ```bash |
| 101 | + cd /Users/rohan/Desktop/Projects/codealmanac |
| 102 | + uv run pytest tests/test_cloud_runs_service.py -q |
| 103 | + ``` |
| 104 | + |
| 105 | +Expected: pass. |
| 106 | + |
| 107 | +## Task 3: CodeAlmanac Cloud Runs Workflow And CLI |
| 108 | + |
| 109 | +**Files:** |
| 110 | + |
| 111 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/workflows/cloud_runs/models.py` |
| 112 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/workflows/cloud_runs/requests.py` |
| 113 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/workflows/cloud_runs/service.py` |
| 114 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/workflows/cloud_runs/__init__.py` |
| 115 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/cli/parser/runs.py` |
| 116 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/cli/dispatch/runs.py` |
| 117 | +- Create: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/cli/render/cloud_runs.py` |
| 118 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/cli/parser/admin.py` |
| 119 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/cli/dispatch/admin.py` |
| 120 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/src/codealmanac/cli/render/admin.py` |
| 121 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/tests/test_cli.py` |
| 122 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/tests/test_architecture.py` |
| 123 | +- Test: `/Users/rohan/Desktop/Projects/codealmanac/tests/test_cloud_runs_workflow.py` |
| 124 | + |
| 125 | +**Steps:** |
| 126 | + |
| 127 | +1. Add a workflow that resolves current checkout through `CloudRepoWorkflow.status`. |
| 128 | +2. Add `runs list/show/logs` parsing with `--api-url` and `--json`. |
| 129 | +3. Render tabular rows for human output and typed JSON for `--json`. |
| 130 | +4. Add CLI tests using a fake cloud runs client. |
| 131 | +5. Add architecture tests so parser/dispatch/render packages remain split. |
| 132 | +6. Run: |
| 133 | + ```bash |
| 134 | + cd /Users/rohan/Desktop/Projects/codealmanac |
| 135 | + uv run pytest tests/test_cloud_runs_service.py tests/test_cloud_runs_workflow.py tests/test_cli.py tests/test_architecture.py -q |
| 136 | + ``` |
| 137 | + |
| 138 | +Expected: pass. |
| 139 | + |
| 140 | +## Task 4: Docs, Verification, Commit, Push |
| 141 | + |
| 142 | +**Files:** |
| 143 | + |
| 144 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/docs/codealmanac-launch/auth-api-contract.md` |
| 145 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/docs/codealmanac-launch/cli-contract.md` |
| 146 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/docs/codealmanac-launch/progress.md` |
| 147 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/docs/codealmanac-launch/verification-matrix.md` |
| 148 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/docs/codealmanac-launch/worklog.md` |
| 149 | +- Modify: `/Users/rohan/Desktop/Projects/codealmanac/docs/codealmanac-launch/next-agent-brief.md` |
| 150 | + |
| 151 | +**Verification:** |
| 152 | + |
| 153 | +Hosted: |
| 154 | + |
| 155 | +```bash |
| 156 | +cd /Users/rohan/.config/superpowers/worktrees/usealmanac/hosted-baseline-convergence/backend |
| 157 | +uv run pytest tests/test_cli_runs_api_contract.py tests/test_repositories_api_contract.py tests/test_updates_contract.py -q |
| 158 | +uv run ruff check . |
| 159 | +uv run python -m compileall src modal_app -q |
| 160 | +``` |
| 161 | + |
| 162 | +CodeAlmanac: |
| 163 | + |
| 164 | +```bash |
| 165 | +cd /Users/rohan/Desktop/Projects/codealmanac |
| 166 | +uv run pytest tests/test_cloud_runs_service.py tests/test_cloud_runs_workflow.py tests/test_cli.py tests/test_architecture.py -q |
| 167 | +uv run ruff check . |
| 168 | +uv run python -m compileall src -q |
| 169 | +git diff --check |
| 170 | +``` |
| 171 | + |
| 172 | +Commit/push: |
| 173 | + |
| 174 | +```bash |
| 175 | +cd /Users/rohan/.config/superpowers/worktrees/usealmanac/hosted-baseline-convergence |
| 176 | +git commit -m "feat: add CLI run read routes" |
| 177 | +git push origin codex/workos-authkit-api-foundation |
| 178 | + |
| 179 | +cd /Users/rohan/Desktop/Projects/codealmanac |
| 180 | +git commit -m "feat: inspect cloud runs from CLI" |
| 181 | +git push origin dev |
| 182 | +``` |
0 commit comments