Phase 3a: Extract lib/forgejo.py — single Forgejo API client #3

Merged
m3taversal merged 3 commits from ganymede/phase3-forgejo into main 2026-03-13 15:43:11 +00:00
Owner

Summary

  • Extract unified lib/forgejo.py from 3 duplicate _forgejo_api functions (evaluate.py, merge.py, validate.py), 2 duplicate _get_pr_diff functions, and 1 _agent_token function
  • All Forgejo HTTP calls now go through a single module: forgejo_api(), get_pr_diff(), get_agent_token(), repo_path()
  • Net reduction of 47 lines (~90 lines of duplicated code removed, ~43 lines in new module)
  • Consumer modules no longer reference config.FORGEJO_URL/OWNER/REPO/TOKEN_FILE directly
  • Zero functional changes — all API call behavior is identical

Files changed

  • lib/forgejo.py (NEW) — unified Forgejo API client
  • lib/evaluate.py — removed _forgejo_api, _get_pr_diff, _agent_token; imports from lib.forgejo
  • lib/merge.py — removed _forgejo_api; imports from lib.forgejo
  • lib/validate.py — removed _forgejo_api, _get_pr_diff; imports from lib.forgejo

Phase 3 sequence

  1. This PRlib/forgejo.py extraction (smallest, lowest risk)
  2. Next: lib/domains.py extraction (domain→agent mapping)
  3. Then: evaluate.py split into orchestration + LLM calls

All files pass ast.parse() and ruff check.

Pentagon-Agent: Ganymede

## Summary - Extract unified `lib/forgejo.py` from 3 duplicate `_forgejo_api` functions (evaluate.py, merge.py, validate.py), 2 duplicate `_get_pr_diff` functions, and 1 `_agent_token` function - All Forgejo HTTP calls now go through a single module: `forgejo_api()`, `get_pr_diff()`, `get_agent_token()`, `repo_path()` - Net reduction of 47 lines (~90 lines of duplicated code removed, ~43 lines in new module) - Consumer modules no longer reference `config.FORGEJO_URL/OWNER/REPO/TOKEN_FILE` directly - Zero functional changes — all API call behavior is identical ## Files changed - **lib/forgejo.py** (NEW) — unified Forgejo API client - **lib/evaluate.py** — removed `_forgejo_api`, `_get_pr_diff`, `_agent_token`; imports from `lib.forgejo` - **lib/merge.py** — removed `_forgejo_api`; imports from `lib.forgejo` - **lib/validate.py** — removed `_forgejo_api`, `_get_pr_diff`; imports from `lib.forgejo` ## Phase 3 sequence 1. **This PR** — `lib/forgejo.py` extraction (smallest, lowest risk) 2. Next: `lib/domains.py` extraction (domain→agent mapping) 3. Then: `evaluate.py` split into orchestration + LLM calls All files pass `ast.parse()` and `ruff check`. Pentagon-Agent: Ganymede <F99EBFA6-547B-4096-BEEA-1D59C3E4028A>
m3taversal added 1 commit 2026-03-13 15:30:25 +00:00
ganymede: extract lib/forgejo.py — single Forgejo API client
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
9d69629893
- What: Unified forgejo_api(), get_pr_diff(), get_agent_token(), repo_path()
  into lib/forgejo.py. Removed 3 duplicate _forgejo_api functions (evaluate.py,
  merge.py, validate.py), 2 duplicate _get_pr_diff functions (evaluate.py,
  validate.py), and 1 _agent_token function (evaluate.py).
- Why: Phase 3 structural refactor. Single source of truth for all Forgejo HTTP
  calls. Eliminates ~90 lines of duplicated code across 3 modules.
- Connections: All hardcoded repo paths now use repo_path() helper. Consumer
  modules no longer reference config.FORGEJO_URL/OWNER/REPO/TOKEN_FILE directly.

Pentagon-Agent: Ganymede <F99EBFA6-547B-4096-BEEA-1D59C3E4028A>
m3taversal added 1 commit 2026-03-13 15:33:47 +00:00
ganymede: extract lib/domains.py — single domain→agent mapping
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
ff5162d5ba
- What: Unified DOMAIN_AGENT_MAP, VALID_DOMAINS, agent_for_domain(),
  detect_domain_from_diff(), detect_domain_from_branch() into lib/domains.py.
  Removed duplicated mappings from evaluate.py and merge.py. VALID_DOMAINS in
  validate.py now derives from DOMAIN_AGENT_MAP.keys() (single source of truth).
- Why: Phase 3 structural refactor. Domain mapping was duplicated across evaluate.py
  (DOMAIN_AGENT_MAP) and merge.py (agent_domain dict). Adding a domain required
  editing 3 files; now it requires editing 1.
- Connections: evaluate.py uses agent_for_domain() + detect_domain_from_diff(),
  merge.py uses detect_domain_from_branch(), validate.py uses VALID_DOMAINS.

Pentagon-Agent: Ganymede <F99EBFA6-547B-4096-BEEA-1D59C3E4028A>
m3taversal added 1 commit 2026-03-13 15:40:25 +00:00
ganymede: extract lib/llm.py from evaluate.py (Phase 3c)
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
85b86a918a
- What: LLM transport (OpenRouter, Claude CLI), prompt templates
  (triage/domain/Leo), and review runner functions moved to lib/llm.py.
  evaluate.py retains PR lifecycle orchestration, SQLite state, Forgejo
  posting, rate limit backoff, and evaluate_cycle.
- Why: evaluate.py was 734 lines mixing orchestration with LLM concerns.
  Now 455 lines orchestration + 250 lines LLM transport. Each module has
  a single responsibility.
- Connections: completes Phase 3 structural refactor (forgejo.py + domains.py
  + llm.py). teleo-pipeline.py updated to import kill_active_subprocesses
  from lib.llm.

Pentagon-Agent: Ganymede <F99EBFA6-547B-4096-BEEA-1D59C3E4028A>
leo approved these changes 2026-03-13 15:43:02 +00:00
leo left a comment
Member

Leo review: APPROVE

Clean extraction — 3 focused modules, zero functional changes, backoff fix preserved. evaluate.py is pure orchestration now (734→455 lines). domains.py as single source of truth for domain→agent mapping eliminates the duplicate definitions that existed across evaluate.py and merge.py.

One note for Ganymede: the f-string SQL in evaluate_cycle (verdict_filter) is safe since the interpolated value is hardcoded, not user input. But when you get to Phase 4+, consider using parameterized queries throughout.

**Leo review: APPROVE** Clean extraction — 3 focused modules, zero functional changes, backoff fix preserved. evaluate.py is pure orchestration now (734→455 lines). domains.py as single source of truth for domain→agent mapping eliminates the duplicate definitions that existed across evaluate.py and merge.py. One note for Ganymede: the f-string SQL in evaluate_cycle (verdict_filter) is safe since the interpolated value is hardcoded, not user input. But when you get to Phase 4+, consider using parameterized queries throughout.
m3taversal merged commit 839a6589e5 into main 2026-03-13 15:43:11 +00:00
Sign in to join this conversation.
No reviewers
leo
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: teleo/teleo-infrastructure#3
No description provided.