Skip to content

arch: 5 route groups + crews/ split — codec_dashboard 3912→3618, codec_agents 1808→1128#161

Merged
AVADSA25 merged 4 commits into
mainfrom
dashboard-route-extraction
May 30, 2026
Merged

arch: 5 route groups + crews/ split — codec_dashboard 3912→3618, codec_agents 1808→1128#161
AVADSA25 merged 4 commits into
mainfrom
dashboard-route-extraction

Conversation

@AVADSA25
Copy link
Copy Markdown
Owner

Summary

Continuation of B6 architecture refactor (PR #160 deferrals). Pytest: 2128 → 2148 (+20 regression tests, 0 regressions).

What landed

5 dashboard route groups extracted (C1..C5)

Followed the proven routes/notifications.py pattern from PR #160 Phase 3.

Phase Group Endpoints Target
C1 /api/approvals/* 4 (list, count, allow, deny) routes/approvals.py
C2 /api/heartbeat/* 4 (config GET/PUT, alerts GET/PUT) routes/heartbeat.py
C3 /api/cortex/* 4 (health, skills, logs, restart) routes/cortex.py
C4 /api/audit/* 3 (raw, stream, stats) routes/audit.py
C5 /api/observer/buffer 1 (debug-only privileged) routes/observer.py

12 crew builders → codec_crews.py (C6)

~700 LOC of declarative wiring moved out of codec_agents.py. codec_agents now imports and re-exports the 12 builders so CREW_REGISTRY (which references them by name) and any external from codec_agents import deep_research_crew import keep working. Single-file extraction this time; future per-crew files at crews/{name}.py is a separate refactor.

LOC shift

  • codec_dashboard.py: 3,912 → 3,618 LOC (-294, -7.5%)
  • codec_agents.py: 1,808 → 1,128 LOC (-680, -37.6%)

Test plan

  • pytest tests/test_route_extractions.py20/20 new tests pass, parametrized across 6 phases
  • pytest tests/ -k "approval or heartbeat or cortex or audit or observer or notification" — 237/237 pass
  • pytest tests/ -k "crew or agent" — 236/236 pass
  • pytest tests/test_bounded_dicts.py — updated source-scan, 9/9 pass
  • pytest tests/test_skill_loader_unification.py — updated source-scan, all pass
  • pytest tests/test_security.py — crew floor test updated to scan codec_crews.py, all pass
  • pytest tests/ (full) — 2148 passed, 83 skipped, 0 failed in 1m34s

After merge

cd ~/codec-repo && git pull
pm2 restart codec-dashboard codec-mcp-http

🤖 Generated with Claude Code

Mikarina13 and others added 4 commits May 30, 2026 11:39
…c_agents 1808→1128

Continuation of B6 architecture refactor (PR #160 deferrals).
Pytest: 2128 → 2148 (+20 regression tests, 0 regressions).

DASHBOARD ROUTE GROUPS (C1..C5)

Followed the routes/notifications.py pattern from PR #160 P3. Each
group is a self-contained APIRouter included in codec_dashboard.

C1 / SR-36: /api/approvals/* → routes/approvals.py
  4 endpoints (list, count, allow, deny). All state already lived in
  routes/_shared (_pending_approvals, _approval_lock,
  _evict_expired_approvals). test_bounded_dicts source-scan updated
  to look at routes/approvals.py.

C2 / SR-37: /api/heartbeat/* → routes/heartbeat.py
  4 endpoints (config GET/PUT, alerts GET/PUT). Pure CONFIG_PATH JSON
  reads, no shared mutex needed.

C3 / SR-38: /api/cortex/* → routes/cortex.py
  4 endpoints (health, skills, logs/{svc}, restart/{svc}). The skills
  endpoint reads from codec_dispatch.registry (A-4 invariant preserved).
  test_skill_loader_unification source-scan updated.

C4 / SR-39: /api/audit, /api/audit/stream, /api/audit/stats → routes/audit.py
  3 read-only endpoints. AUDIT_LOG read from routes/_shared.

C5 / SR-40: /api/observer/buffer → routes/observer.py
  1 debug-only privileged endpoint. Emits OBSERVER_BUFFER_INSPECTED on
  every read (audit trail preserved).

CREWS SPLIT (C6)

C6 / SR-41: 12 crew builders → codec_crews.py
  ~700 LOC of declarative wiring moved out of codec_agents.py.
  codec_agents now imports and re-exports the 12 builders so
  CREW_REGISTRY (which references them by name) and any external
  `from codec_agents import deep_research_crew` import keep working.
  Single-file extraction this time; future per-crew files at
  crews/{name}.py is a separate refactor.

LOC SHIFT

  codec_dashboard.py: 3,912 → 3,618 LOC (-294, -7.5%)
  codec_agents.py:    1,808 → 1,128 LOC (-680, -37.6%)

NEW TESTS

  tests/test_route_extractions.py — 20 tests across 6 phases.
  Each phase pins (a) endpoint registered on the FastAPI app via the
  router include, (b) source-side invariants (e.g. cortex_skills uses
  codec_dispatch.registry; observer emits OBSERVER_BUFFER_INSPECTED).
  Plus a global LOC floor (codec_dashboard.py < 3,700) that tightens
  as future route extractions land.

UPDATED SOURCE-SCAN TESTS

- tests/test_bounded_dicts.py: scans routes/approvals.py for
  `_evict_expired_approvals(` (was: codec_dashboard.py)
- tests/test_skill_loader_unification.py: scans routes/cortex.py for
  `from codec_dispatch import registry` (was: codec_dashboard.py)
- tests/test_security.py: scans codec_crews.py for the 12 crew
  builders + their allowed_tools= invariant (was: codec_agents.py)

Full pytest: 2148 passed, 83 skipped (env-dependent), 0 failed (1m34s).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ogger

PR #161 CI smoke ruff gate failed on 7 unused imports:
- codec_crews.py: typing.List/Optional unused (carried over from copy);
  added missing `log = logging.getLogger("codec_crews")` for the
  function-local log.warning at meeting_summarizer_crew
- codec_dashboard.py: subprocess imported at top-level was shadowed by
  function-local re-imports throughout (screenshot/pbpaste/pbcopy/
  pdftotext/cmd_runner); dropped the unused top-level import
- codec_dashboard.py: AUDIT_LOG no longer needed at module level (audit
  endpoints moved to routes/audit.py in C4)
- codec_dashboard.py: _pending_approvals / _approval_lock /
  _evict_expired_approvals no longer needed at module level (approval
  endpoints moved to routes/approvals.py in C1)

No behavior change. Full pytest still 2148 passed, 0 failed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@AVADSA25 AVADSA25 merged commit 1f4e87b into main May 30, 2026
1 check passed
AVADSA25 added a commit that referenced this pull request May 30, 2026
* arch: D-series — 5 more route groups extracted, codec_dashboard 3618→2921

Continuation of route extraction (PR #161 deferrals).
Pytest: 2148 → 2172 (+24 regression tests, 0 regressions).

ROUTES EXTRACTED

D1 / SR-42: /api/qchat/*       → routes/qchat.py
  5 endpoints (sessions/{sid}/save/{sid}/search) + QCHAT_DB + qchat_db()
  helper. SQLite WAL + busy_timeout + auto-migration of user_id column.

D2 / SR-43: /api/vibe/*        → routes/vibe.py
  4 endpoints (sessions/session/save/delete) + VIBE_DB + vibe_db() helper.
  Same lifecycle pattern as qchat.

D3 / SR-44: /api/schedules/*   → routes/schedules.py
  6 endpoints including the /run endpoint with its background-thread
  _execute_task() (LLM report → Google Doc → notification flow).
  PUT endpoint uses codec_jsonstore.atomic_write_json (re-audit medium
  fix preserved).

D4 / SR-45: /api/prompts/*     → routes/prompts.py
  3 endpoints + the 3 helper functions (_load_prompt_overrides,
  _save_prompt_overrides, _get_all_prompts). codec_dashboard's
  chat_completion handler now lazy-imports _load_prompt_overrides
  from routes.prompts to avoid a module-load-time cycle.

D5 / SR-46: media endpoints    → routes/media.py
  6 endpoints (webcam x3, screenshot, clipboard x2). Vision-proxy POST
  in webcam_capture added to test_a12_invariant._ALLOWLIST (legitimate
  vision site pending A-11 cleanup).

NOT INCLUDED IN D5
- /api/upload and /api/upload_image (250 LOC with B1 fence markers +
  size cap + path safety) — kept in codec_dashboard.py to keep the
  security-hardening review surface tight. Future PR.

LOC SHIFT

  codec_dashboard.py: 3,618 → 2,921 LOC (-697, -19.3%)
                     (started at 3,912 before PR #160)

NEW TESTS

  tests/test_route_extractions_d.py — 24 tests across 5 phases.
  Each phase parametrizes endpoint-registered checks + source-side
  invariants (db helpers in module, atomic-write in schedules, lazy
  prompt import in dashboard). Global LOC floor tightened to < 3,000.

UPDATED SOURCE-SCAN TESTS

- tests/test_a12_invariant.py: routes/media.py added to allowlist
  (vision POST in webcam_capture, A-11 pending)
- tests/test_dashboard_llm.py: /chat/completions count assertion
  bumped 5 → 4 (vision POST moved out with media)

Full pytest: 2172 passed, 83 skipped (env-dependent), 0 failed (1m24s).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(lint): ruff F401/F821 — drop unused imports + lazy-import qchat_db/vibe_db

PR #162 CI smoke ruff gate failed:
- F401: sqlite3, uuid, pathlib.Path, _notif_lock, _load_notifications,
  _write_notifications, _append_schedule_run_log — all callers moved to
  routes/qchat, routes/vibe, routes/schedules
- F821: 4 call sites in codec_dashboard.py still referenced qchat_db()
  and vibe_db() — added lazy `from routes.qchat import qchat_db` (etc.)
  inside each function body that uses them

No behavior change. Full pytest still 2172 passed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Mickael Farina <farina.mickael@gmail.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants