{
  "updated": "2026-07-04T16:31:35Z",
  "iteration": 4,
  "contract_version": 2,
  "mission": "Turn ccmeter into a sub2api-backed fleet monitor + ccmeter-claude launcher, proven on staging before any promotion.",
  "loop_state": "running",
  "oracle": {
    "pytest": "green (54 passed)",
    "staging_health": "green (127.0.0.1:8190 → 200)",
    "staging_url": "green (https 200)",
    "sub2api_prod": "200",
    "ccmeter_claude_smoke": "n/a until Phase 3"
  },
  "phases": [
    {
      "id": "Phase 0",
      "title": "Isolation + LiteLLM removal (branch, purge, config rename, fix unit paths)",
      "status": "done"
    },
    {
      "id": "Phase 1",
      "title": "Staging environment (ccmeter-staging.service :8190, additive Caddy vhost, staging URL 200)",
      "status": "done"
    },
    {
      "id": "Phase 2",
      "title": "sub2api adapter (ccmeter/sub2api.py, repoint /api/accounts + /api/routing/live) \u2014 pool/gateway-key checkpoint",
      "status": "done"
    },
    {
      "id": "Phase 3",
      "title": "ccmeter-claude launcher (bin shim, ~/.local/bin install, smoke-test through sub2api)",
      "status": "blocked"
    },
    {
      "id": "Phase 4",
      "title": "ccmax-monitor-adapted robustness (429 retry, velocity alerts + forecast, fleet panel, fail-safe drill)",
      "status": "pending"
    },
    {
      "id": "Phase 5",
      "title": "Docs + tests + full staging verification",
      "status": "pending"
    }
  ],
  "inventory": [
    {
      "component": "sub2api (gateway)",
      "status": "live",
      "detail": "/opt/sub2api/sub2api on 127.0.0.1:8080 \u00b7 systemd enabled \u00b7 Postgres+Redis backed"
    },
    {
      "component": "sub2api.epatner.com",
      "status": "live",
      "detail": "Caddy \u2192 :8080 \u00b7 HTTP 200 \u00b7 SSE streaming \u00b7 health checks"
    },
    {
      "component": "Caddy",
      "status": "live",
      "detail": "v2.11.4 \u00b7 auto-TLS \u00b7 serves sub2api + staging-ccmeter + pulse vhosts"
    },
    {
      "component": "PostgreSQL 16.14",
      "status": "live",
      "detail": "127.0.0.1:5432 \u00b7 db/user sub2api"
    },
    {
      "component": "Redis 7.0.15",
      "status": "live",
      "detail": "127.0.0.1:6379 \u00b7 sub2api cache/queue"
    },
    {
      "component": "pulse.epatner.com",
      "status": "live",
      "detail": "this research dashboard \u00b7 Caddy file_server \u2192 /srv/pulse"
    },
    {
      "component": "ccmeter (staging app)",
      "status": "live",
      "detail": "v0.13.0 · 127.0.0.1:8190 · pure read-model (proxy role retired) · https://staging-ccmeter.epatner.com → 200"
    },
    {
      "component": "ccmeter.epatner.com (prod)",
      "status": "parked",
      "detail": "intentionally not deployed during this effort"
    },
    {
      "component": "LiteLLM",
      "status": "removed",
      "detail": "dropped by directive \u2014 sub2api is the only gateway"
    }
  ],
  "blockers": [
    {
      "what": "sub2api pool is empty",
      "blocks": "Phase 3",
      "action": "Add at least one Claude/OpenRouter account to the sub2api pool and create a gateway API key (sub2api admin UI). Verified 2026-07-04: 0 accounts, 0 keys, 0 channels — the launcher would have nothing to route to."
    }
  ],
  "commands": [
    {
      "name": "ccmeter-claude",
      "routed": true,
      "mode": "bypass permissions",
      "detail": "ANTHROPIC_BASE_URL \u2192 sub2api \u00b7 429 auto-retry \u00b7 new PATH shim"
    },
    {
      "name": "claude",
      "routed": false,
      "mode": "normal",
      "detail": "untouched \u2014 vanilla, direct to Anthropic, normal permissions"
    }
  ],
  "iterations": [
    {
      "n": 1,
      "at": "2026-07-04T14:06:40Z",
      "version": "0.10.0",
      "oracle": "green",
      "summary": "Phase 0 shipped: branch feature/sub2api-monitor; LiteLLM purged (deploy artifacts deleted, CLAUDE.md + routing doc rewritten to sub2api); GATEWAY_URL \u2192 SUB2API_BASE_URL + admin creds from env; ccmeter.service paths fixed; fail-safe numeric env parsing; 8 new acceptance tests."
    },
    {
      "n": 2,
      "at": "2026-07-04T15:47:15Z",
      "version": "0.11.0",
      "oracle": "green",
      "summary": "Phase 1 shipped: ccmeter-staging.service live on 127.0.0.1:8190 (EnvironmentFile=-/etc/ccmeter/staging.env 600, NoNewPrivileges/PrivateTmp/MemoryMax hardening); additive Caddy vhost \u2192 https://staging-ccmeter.epatner.com 200; repaired venv polluted with foreign-macOS shebangs (rebuilt clean); 6 new acceptance tests; oracle fully green incl. staging checks for the first time."
    },
    {
      "n": 3,
      "at": "2026-07-04T16:12:18Z",
      "version": "0.12.0",
      "oracle": "green",
      "summary": "Phase 2 advanced: ccmeter/sub2api.py read-only admin adapter (JWT login cached, 401 re-login, transient-5xx retry, never-die 60s poller, fail-safe snapshots) live on staging; /api/accounts + /api/routing/live now sourced from sub2api; fixed staging.env var-name mismatch that left creds unread. CHECKPOINT: sub2api pool is EMPTY (0 accounts / 0 keys / 0 channels) \u2014 Phase 3 launcher blocked on operator; dashboard reports pool_empty honestly. 8 new adapter tests (71 total). Proxy-role retirement remains before Phase 2 closes."
    },
    {
      "n": 4,
      "at": "2026-07-04T16:31:35Z",
      "version": "0.13.0",
      "oracle": "green",
      "summary": "Phase 2 CLOSED: proxy role retired \u2014 /v1/messages hot path, routing decide/turn-end endpoints, proxy.py, routing.py, openrouter.py and 24 legacy tests deleted; /api/accounts = quota view + sub2api fleet; /api/routing/live = pure sub2api read-model; dashboard panels repointed; 9 dead config knobs removed. Hardening: /api/health now flags a silent (stalled) sub2api poll loop while an unreachable admin API stays healthy-degraded. 54 tests green. Phase 3 remains blocked: sub2api pool still empty."
    }
  ]
}