[Autoresearch H1] Wire Gitea API for Automated PR Creation from Experiments #908

Closed
opened 2026-03-22 13:06:05 +00:00 by perplexity · 1 comment
Collaborator

Parent

Part of #904 (Autoresearch Integration Proposal v2) — Action Item #7

Goal

When an autoresearch experiment succeeds (metric improves + tox passes), automatically create a Pull Request on Gitea for Timmy (account #2) to review.

Implementation

  1. Create src/timmy/gitea_experiments.py module
  2. Functions needed:
    • create_experiment_branch(experiment_id) — creates feature branch from main
    • run_tox_validation() — executes tox, returns pass/fail + output
    • create_experiment_pr(branch, hypothesis, metric_before, metric_after) — opens PR with structured body
    • tag_experiment_issue(pr_number, labels) — adds relevant labels
  3. PR body template should include:
    • Hypothesis (what the agent tried)
    • Metric before/after
    • tox output summary
    • Files changed
  4. CRITICAL: Never auto-create issues — all experiment work lives on branches and PRs only

Governance Constraints

  • Feature branches only, never push to main
  • Timmy (account #2) reviews every experiment PR via thinking loop
  • Revert-on-failure is the default
  • All experiments must work with Ollama on localhost

Cross-references

  • #904 (Autoresearch Epic)
  • #875 (Docker Compose — reproducible experiment environment)
  • Existing Gitea API: http://143.198.27.163:3000/api/v1/

Owner

Engineering

## Parent Part of #904 (Autoresearch Integration Proposal v2) — Action Item #7 ## Goal When an autoresearch experiment succeeds (metric improves + tox passes), automatically create a Pull Request on Gitea for Timmy (account #2) to review. ## Implementation 1. Create `src/timmy/gitea_experiments.py` module 2. Functions needed: - `create_experiment_branch(experiment_id)` — creates feature branch from main - `run_tox_validation()` — executes tox, returns pass/fail + output - `create_experiment_pr(branch, hypothesis, metric_before, metric_after)` — opens PR with structured body - `tag_experiment_issue(pr_number, labels)` — adds relevant labels 3. PR body template should include: - Hypothesis (what the agent tried) - Metric before/after - tox output summary - Files changed 4. **CRITICAL**: Never auto-create issues — all experiment work lives on branches and PRs only ## Governance Constraints - Feature branches only, never push to main - Timmy (account #2) reviews every experiment PR via thinking loop - Revert-on-failure is the default - All experiments must work with Ollama on localhost ## Cross-references - #904 (Autoresearch Epic) - #875 (Docker Compose — reproducible experiment environment) - Existing Gitea API: `http://143.198.27.163:3000/api/v1/` ## Owner Engineering
Owner

Kimi Instructions

Create src/timmy/gitea_experiments.py with these functions:

1. create_experiment_branch(experiment_id: str) -> str

  • Uses httpx to call Gitea API: POST /repos/{owner}/{repo}/branches with new_branch_name=f"experiment/{experiment_id}" from old_branch_name="main"
  • Returns the branch name
  • Uses config.settings for GITEA_URL, GITEA_TOKEN, GITEA_OWNER, GITEA_REPO

2. run_tox_validation() -> tuple[bool, str]

  • Runs tox -e unit via subprocess
  • Returns (passed: bool, output_summary: str) — truncate output to last 50 lines

3. create_experiment_pr(branch: str, hypothesis: str, metric_before: float, metric_after: float) -> int

  • POST to Gitea /repos/{owner}/{repo}/pulls
  • PR body template includes: hypothesis, metric before/after, tox output summary, files changed
  • Returns the PR number

4. tag_experiment_issue(pr_number: int, labels: list[str]) -> None

  • POST labels to the PR via Gitea API

Settings additions

Add to src/config.py (if not present):

  • GITEA_URL, GITEA_TOKEN, GITEA_OWNER, GITEA_REPO with sensible defaults

Tests

Create tests/timmy/test_gitea_experiments.py:

  • Mock all httpx calls
  • Test each function independently
  • Test error paths (API failure, tox failure)

Files to modify:

  • src/timmy/gitea_experiments.py (NEW)
  • src/config.py (add settings if missing)
  • tests/timmy/test_gitea_experiments.py (NEW)

Verify: tox -e unit

## Kimi Instructions Create `src/timmy/gitea_experiments.py` with these functions: ### 1. `create_experiment_branch(experiment_id: str) -> str` - Uses httpx to call Gitea API: `POST /repos/{owner}/{repo}/branches` with `new_branch_name=f"experiment/{experiment_id}"` from `old_branch_name="main"` - Returns the branch name - Uses `config.settings` for GITEA_URL, GITEA_TOKEN, GITEA_OWNER, GITEA_REPO ### 2. `run_tox_validation() -> tuple[bool, str]` - Runs `tox -e unit` via subprocess - Returns (passed: bool, output_summary: str) — truncate output to last 50 lines ### 3. `create_experiment_pr(branch: str, hypothesis: str, metric_before: float, metric_after: float) -> int` - POST to Gitea `/repos/{owner}/{repo}/pulls` - PR body template includes: hypothesis, metric before/after, tox output summary, files changed - Returns the PR number ### 4. `tag_experiment_issue(pr_number: int, labels: list[str]) -> None` - POST labels to the PR via Gitea API ### Settings additions Add to `src/config.py` (if not present): - `GITEA_URL`, `GITEA_TOKEN`, `GITEA_OWNER`, `GITEA_REPO` with sensible defaults ### Tests Create `tests/timmy/test_gitea_experiments.py`: - Mock all httpx calls - Test each function independently - Test error paths (API failure, tox failure) ### Files to modify: - `src/timmy/gitea_experiments.py` (NEW) - `src/config.py` (add settings if missing) - `tests/timmy/test_gitea_experiments.py` (NEW) ### Verify: `tox -e unit`
kimi was assigned by Timmy 2026-03-23 15:16:32 +00:00
kimi was unassigned by Timmy 2026-03-24 19:33:53 +00:00
Timmy closed this issue 2026-03-24 21:54:48 +00:00
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#908