Skip to content

Comments

Update cli to handle multi-file optimization#112

Merged
aliroberts merged 1 commit intodevfrom
feature/multifile
Feb 17, 2026
Merged

Update cli to handle multi-file optimization#112
aliroberts merged 1 commit intodevfrom
feature/multifile

Conversation

@aliroberts
Copy link
Contributor

Multi-file optimization support

Extends the CLI to optimize across multiple source files in a single run, while remaining fully backwards-compatible with the existing single-file (-s/--source) workflow.

Changes

CLI (cli.py)

  • Add --sources flag (mutually exclusive with -s/--source) accepting multiple file paths.
  • Normalize both input modes into a unified list[str] before passing downstream.

Optimizer (optimizer.py)

  • Represent source code as dict[str, str] (path -> content) throughout the optimization loop and resume flow.
  • Normalize server responses (single string or dict) into a file map at every boundary.
  • Replace inline log-writing with the new RunArtifacts manager.
  • Multi-file apply: _offer_apply_best_solution writes back all modified files and displays which paths changed.

Artifacts (artifacts.py) — new

  • RunArtifacts class that owns the on-disk layout under .runs/<run_id>/.
  • Step snapshots (steps/<n>/files/ + manifest.json), best snapshot (best/), and execution output (outputs/ + exec_output.jsonl).
  • Path sanitization (_sanitize_artifact_path) strips traversal components, absolute prefixes, and Windows drive letters.

Utils (utils.py)

  • Add run_evaluation_with_files_swap() — atomically swaps multiple files before evaluation and restores originals in a finally block.

Validation (validation.py)

  • Add validate_source_files() with per-file size (200 KB), total size (500 KB), file count (10), and duplicate-path checks.
  • Add validate_sources() dispatcher that routes single vs. multi-file input.

API (api.py)

  • Widen start_optimization_run signature: source_code accepts str | dict[str, str], source_path accepts str | None.

Tests (test_artifacts.py) — new

  • Parametrized path-sanitization tests (relative, absolute, traversal, Windows, empty).
  • Step/best snapshot round-trip tests, step independence, JSONL index verification.
  • Path-traversal containment tests for both step and best snapshots.

@aliroberts aliroberts merged commit 458ed51 into dev Feb 17, 2026
1 check passed
@aliroberts aliroberts deleted the feature/multifile branch February 17, 2026 14:24
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.

1 participant