Summary & Motivation
When an autonomous agent attempts a complex code task, it may modify multiple files, generate syntax errors, or fail verification checks. If the task fails or requires multiple divergent retries, leftover uncommitted changes or broken diffs in the working tree can pollute subsequent attempts or corrupt the user's active branch.
We want to introduce Ephemeral Git Worktree Sandboxing: running each contract execution attempt in an isolated, temporary Git worktree (.letitloop/worktrees/<task_id>_<attempt>) that is automatically cleanly merged to the main branch upon passing verification, or pruned on failure.
Architectural Proposal
WorktreeSandbox Manager (orchestrator/worktree_sandbox.py):
- Creates an isolated branch and worktree directory:
git worktree add -b letitloop/<task_id>_<attempt> <worktree_path> HEAD.
- Executes the worker adapter strictly inside
<worktree_path>.
- Runs deterministic verifiers (
test_command, linter, static analysis) inside the worktree.
- Atomic Merge on Success:
- If verification and QC review pass (
PASS), merge the worktree branch into the base branch using fast-forward or squash merge.
- If verification fails (
FAIL), prune the worktree: git worktree remove --force <worktree_path> and discard the scratch branch.
- Zero Host Branch Contamination:
- Ensures the developer's live workspace remains 100% pristine and compiling at all times.
Key Files & Areas
orchestrator/worktree_sandbox.py: New worktree lifecycle manager.
orchestrator/supervisor.py: Wrap _execute_single_contract with worktree isolation.
orchestrator/cli.py: Add --worktree flag to lil run and lil resume.
tests/test_worktree_sandbox.py: Unit and integration tests.
Acceptance Criteria
Summary & Motivation
When an autonomous agent attempts a complex code task, it may modify multiple files, generate syntax errors, or fail verification checks. If the task fails or requires multiple divergent retries, leftover uncommitted changes or broken diffs in the working tree can pollute subsequent attempts or corrupt the user's active branch.
We want to introduce Ephemeral Git Worktree Sandboxing: running each contract execution attempt in an isolated, temporary Git worktree (
.letitloop/worktrees/<task_id>_<attempt>) that is automatically cleanly merged to the main branch upon passing verification, or pruned on failure.Architectural Proposal
WorktreeSandboxManager (orchestrator/worktree_sandbox.py):git worktree add -b letitloop/<task_id>_<attempt> <worktree_path> HEAD.<worktree_path>.test_command, linter, static analysis) inside the worktree.PASS), merge the worktree branch into the base branch using fast-forward or squash merge.FAIL), prune the worktree:git worktree remove --force <worktree_path>and discard the scratch branch.Key Files & Areas
orchestrator/worktree_sandbox.py: New worktree lifecycle manager.orchestrator/supervisor.py: Wrap_execute_single_contractwith worktree isolation.orchestrator/cli.py: Add--worktreeflag tolil runandlil resume.tests/test_worktree_sandbox.py: Unit and integration tests.Acceptance Criteria