diff --git a/checkpoint.json b/checkpoint.json index 5e6037a19..fc557542a 100644 --- a/checkpoint.json +++ b/checkpoint.json @@ -1,6 +1,6 @@ { - "timestamp": "2026-03-20T02:07:17.861341Z", - "current_node": "verify", + "timestamp": "2026-03-20T02:07:21.545941Z", + "current_node": "fmt", "completed_nodes": [ "start", "toolchain", @@ -11,7 +11,8 @@ "simplify_gpt", "verify", "fixup", - "verify" + "verify", + "fmt" ], "node_retries": { "preflight_compile": 1, @@ -21,6 +22,7 @@ "toolchain": 1, "preflight_lint": 1, "verify": 1, + "fmt": 1, "implement": 1, "simplify_opus": 1 }, @@ -28,30 +30,31 @@ "internal.retry_count.preflight_lint": 1, "internal.retry_count.fixup": 1, "last_response": "All tests pass and clippy is clean. Here's a summary of what was fixed:\n\n## Changes Made\n\n### 1. `lib/crates/fabro-sandbox/src/worktree.rs` — Fix `initialize()` command order\n\n**Root cause**: `git b", - "current.preamble": "Goal: # Unified WorktreeSandbox\n\n## Context\n\nWorktree management is currently split across two locations with duplicated logic:\n\n1. **Parallel branches** (`parallel.rs`): Inline git commands in `ParallelHandler::execute()`, a thin `WorktreeSandbox` decorator, and separate local/remote code paths\n2. **Top-level CLI run** (`run.rs`): A `setup_worktree()` function using synchronous git helpers, with the worktree path fed into a plain `LocalSandbox`\n\nThe goal is a single `WorktreeSandbox` type that wraps any `Arc`, manages the worktree lifecycle in `initialize()`/`cleanup()`, and eliminates the local/remote branching.\n\n## Plan\n\n### Step 1: Create `WorktreeSandbox` in fabro-sandbox\n\n**New file:** `lib/crates/fabro-sandbox/src/worktree.rs`\n\nDefine:\n\n```rust\npub enum WorktreeEvent {\n BranchCreated { branch: String, sha: String },\n WorktreeAdded { path: String, branch: String },\n WorktreeRemoved { path: String },\n Reset { sha: String },\n}\n\npub type WorktreeEventCallback = Arc;\n\npub struct WorktreeConfig {\n pub branch_name: String,\n pub base_sha: String,\n pub worktree_path: String,\n /// Skip branch creation and reset (for resume, where branch already exists).\n pub skip_branch_creation: bool,\n}\n\npub struct WorktreeSandbox {\n inner: Arc,\n config: WorktreeConfig,\n event_callback: Option,\n}\n```\n\n**Constructor + getters:** `new(inner, config)`, `set_event_callback()`, `branch_name()`, `base_sha()`, `worktree_path()`\n\n**`initialize()`:**\n1. If `!skip_branch_creation`: `git branch --force {branch_name} {base_sha}` via `inner.exec_command()`, emit `BranchCreated`\n2. `git worktree remove --force {path}` (best-effort), then `git worktree add {path} {branch}`, emit `WorktreeAdded`\n3. If `!skip_branch_creation`: `git reset --hard {base_sha}` in worktree dir, emit `Reset`\n\nDoes NOT call `inner.initialize()` — the inner sandbox's lifecycle is managed separately.\n\n**`cleanup()`:** `git worktree remove --force {path}`, emit `WorktreeRemoved`. Does NOT call `inner.cleanup()`.\n\n**`working_directory()`:** Returns `config.worktree_path`.\n\n**`exec_command()`:** Defaults `working_dir` to `config.worktree_path` when `None`, delegates to inner.\n\n**All other Sandbox methods:** Delegate to inner. Must be a manual `impl Sandbox` block (can't use `delegate_sandbox!` since it generates `initialize`/`cleanup`/`working_directory`/`exec_command` which we need to override).\n\nAll interpolated values in git commands use `shell_quote()`.\n\n### Step 2: Register module and re-exports\n\n- `lib/crates/fabro-sandbox/src/lib.rs`: Add `pub mod worktree;` and `pub use worktree::WorktreeSandbox;`\n- `lib/crates/fabro-agent/src/sandbox.rs`: Add re-export of `WorktreeSandbox`\n\n### Step 3: Unit tests for WorktreeSandbox\n\nIn `worktree.rs` `#[cfg(test)]` module, using `MockSandbox`:\n\n- `initialize()` issues correct git commands (branch, worktree remove, worktree add, reset) and emits events\n- `skip_branch_creation` skips branch + reset, only does worktree add\n- `cleanup()` issues `worktree remove` and emits `WorktreeRemoved`\n- `working_directory()` returns worktree path\n- `exec_command()` with `None` working_dir defaults to worktree path\n- `exec_command()` with explicit working_dir passes it through\n- `initialize()` propagates errors on non-zero exit\n\n**MockSandbox enhancement:** Add `captured_commands: Mutex>` field to `test_support.rs` to capture the sequence of `exec_command` calls (current `captured_command` only stores the last one). Append to vec in `exec_command()` impl.\n\n### Step 4: Refactor parallel.rs\n\n- **Remove** the private `WorktreeSandbox` struct (lines 28-126) and `use fabro_agent::LocalSandbox`\n- **Replace** the inline git setup loop (lines 361-450) with:\n - Construct `WorktreeConfig` with branch name, base SHA, worktree path\n - Create `WorktreeSandbox::new(Arc::clone(&services.sandbox), config)`\n - Wire event callback to bridge `WorktreeEvent` → `WorkflowRunEvent`\n - Call `initialize().await`\n- This eliminates the `if services.sandbox.is_remote()` branch (lines 442-449) — `WorktreeSandbox` works the same for any inner sandbox\n- **Cleanup loop** (lines 659-668): Keep calling `git_remove_worktree()` on the parent sandbox (the `WorktreeSandbox` Arc is consumed by the spawned task and dropped). Alternatively, could store the sandbox Arc in `BranchResult` and call `.cleanup()`, but the current approach is simpler.\n\n### Step 5: Refactor run.rs — new runs\n\nReplace `setup_worktree()` call (lines 830-845) + separate `LocalSandbox` construction with:\n\n```\nif workdir_strategy == LocalWorktree:\n base_sha = git::head_sha()\n branch_name = \"fabro/run/{run_id}\"\n inner = Arc::new(LocalSandbox::new(original_cwd))\n wt_sandbox = WorktreeSandbox::new(inner, WorktreeConfig { ... })\n wt_sandbox.set_event_callback(bridge to WorkflowRunEvent)\n wt_sandbox.initialize().await\n std::env::set_current_dir(&worktree_path) // stays in CLI, not in sandbox\n sandbox = Arc::new(wt_sandbox)\n // store base_sha, branch_name for RunConfig\n```\n\n**Delete** the `setup_worktree()` function (lines 1696-1714) — its logic is absorbed above.\n\n`std::env::set_current_dir()` stays in `run.rs` — it's a process-global side effect that belongs to the CLI.\n\n### Step 6: Refactor run.rs — resume (run_from_branch)\n\nReplace worktree re-attachment (lines 1810-1822) with:\n\n```\ninner = Arc::new(LocalSandbox::new(original_cwd))\nwt_sandbox = WorktreeSandbox::new(inner, WorktreeConfig {\n branch_name: run_branch,\n base_sha: base_sha.unwrap_or_default(),\n worktree_path: wt_str,\n skip_branch_creation: true, // branch already exists\n})\nwt_sandbox.initialize().await\nstd::env::set_current_dir(&wt)\n```\n\n### Step 7: Verify\n\n- `cargo build --workspace`\n- `cargo test --workspace`\n- `cargo clippy --workspace -- -D warnings`\n- Manual: `fabro run` with worktree mode enabled on a local workflow\n- Manual: `fabro run --run-branch` to test resume path\n\n## Files to modify\n\n| File | Change |\n|---|---|\n| `lib/crates/fabro-sandbox/src/worktree.rs` | **New** — WorktreeSandbox, WorktreeConfig, WorktreeEvent, impl Sandbox, tests |\n| `lib/crates/fabro-sandbox/src/lib.rs` | Add module + re-export |\n| `lib/crates/fabro-sandbox/src/test_support.rs` | Add `captured_commands: Mutex>` to MockSandbox |\n| `lib/crates/fabro-agent/src/sandbox.rs` | Add WorktreeSandbox re-export |\n| `lib/crates/fabro-workflows/src/handler/parallel.rs` | Remove old WorktreeSandbox, use new one |\n| `lib/crates/fabro-cli/src/commands/run.rs` | Replace setup_worktree + run_from_branch worktree logic |\n\n## Functions that become removable\n\n| Function | Location | Reason |\n|---|---|---|\n| `setup_worktree()` | `run.rs:1696` | Logic absorbed into WorktreeSandbox |\n| Old `WorktreeSandbox` struct | `parallel.rs:28-126` | Replaced by shared WorktreeSandbox |\n\nEngine git helpers (`git_add_worktree`, `git_remove_worktree`, etc. in `engine.rs`) stay — still used by parallel cleanup and potentially other callers. Sync git helpers in `git.rs` also stay.\n\n\n## Completed stages\n- **toolchain**: success\n - Script: `command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1`\n - Stdout:\n ```\n cargo 1.94.0 (85eff7c80 2026-01-15)\n ```\n - Stderr: (empty)\n- **preflight_compile**: success\n - Script: `cargo check -q --workspace 2>&1`\n - Stdout: (empty)\n - Stderr: (empty)\n- **preflight_lint**: success\n - Script: `cargo clippy -q --workspace -- -D warnings 2>&1`\n - Stdout: (empty)\n - Stderr: (empty)\n- **implement**: success\n - Model: claude-sonnet-4-6, 190.9k tokens in / 105.0k out\n - Files: /home/daytona/workspace/lib/crates/fabro-agent/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-agent/src/sandbox.rs, /home/daytona/workspace/lib/crates/fabro-cli/src/commands/run.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/test_support.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/worktree.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n- **simplify_opus**: success\n - Model: claude-sonnet-4-6, 84.8k tokens in / 30.2k out\n - Files: /home/daytona/workspace/lib/crates/fabro-cli/src/commands/run.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n- **simplify_gpt**: success\n - Model: claude-sonnet-4-6, 65.5k tokens in / 23.2k out\n - Files: /home/daytona/workspace/lib/crates/fabro-cli/src/commands/run.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/worktree.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/event.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n- **verify**: fail\n - Script: `cargo clippy -q --workspace -- -D warnings 2>&1 && cargo nextest run --cargo-quiet --workspace --status-level fail 2>&1`\n - Stdout:\n ```\n (97 lines omitted)\n code=1\n stdout=\"\"\n stderr=```\n Workflow: Simple (4 nodes, 3 edges)\n Graph: ../../../test/simple.fabro\n Goal: Run tests and report results\n \n Version: 0.176.2\n Run: 01JTEST1234567890ABCDE\n Time: 2026-03-20 02:03:08\n Run: /tmp/.tmpNkZI0a/run\n Worktree: /tmp/.tmpNkZI0a/run/worktree\n Base: fabro/run/01KM4CC4HA0SYCXGQW7BJWJE8F (1a66765c743d)\n error: Engine error: Failed to initialize sandbox: git branch --force failed (exit 128): fatal: cannot force update the branch \\'fabro/run/01JTEST1234567890ABCDE\\' used by worktree at \\'/tmp/.tmpNkZI0a/run/worktree\\'\n ```\n \n \n note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n \n ────────────\n Summary [ 2.638s] 464/3226 tests run: 462 passed, 2 failed, 177 skipped\n FAIL [ 0.477s] ( 461/3226) fabro-cli::cli dry_run_writes_jsonl_and_live_json\n FAIL [ 0.459s] ( 464/3226) fabro-cli::cli run_id_passthrough_uses_provided_ulid\n warning: 2762/3226 tests were not run due to test failure (run with --no-fail-fast to run all tests, or run with --max-fail)\n error: test run failed\n ```\n - Stderr: (empty)\n- **fixup**: success\n - Model: claude-sonnet-4-6, 45.4k tokens in / 8.9k out\n - Files: /home/daytona/workspace/lib/crates/fabro-sandbox/src/worktree.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/git.rs\n", + "current.preamble": "Goal: # Unified WorktreeSandbox\n\n## Context\n\nWorktree management is currently split across two locations with duplicated logic:\n\n1. **Parallel branches** (`parallel.rs`): Inline git commands in `ParallelHandler::execute()`, a thin `WorktreeSandbox` decorator, and separate local/remote code paths\n2. **Top-level CLI run** (`run.rs`): A `setup_worktree()` function using synchronous git helpers, with the worktree path fed into a plain `LocalSandbox`\n\nThe goal is a single `WorktreeSandbox` type that wraps any `Arc`, manages the worktree lifecycle in `initialize()`/`cleanup()`, and eliminates the local/remote branching.\n\n## Plan\n\n### Step 1: Create `WorktreeSandbox` in fabro-sandbox\n\n**New file:** `lib/crates/fabro-sandbox/src/worktree.rs`\n\nDefine:\n\n```rust\npub enum WorktreeEvent {\n BranchCreated { branch: String, sha: String },\n WorktreeAdded { path: String, branch: String },\n WorktreeRemoved { path: String },\n Reset { sha: String },\n}\n\npub type WorktreeEventCallback = Arc;\n\npub struct WorktreeConfig {\n pub branch_name: String,\n pub base_sha: String,\n pub worktree_path: String,\n /// Skip branch creation and reset (for resume, where branch already exists).\n pub skip_branch_creation: bool,\n}\n\npub struct WorktreeSandbox {\n inner: Arc,\n config: WorktreeConfig,\n event_callback: Option,\n}\n```\n\n**Constructor + getters:** `new(inner, config)`, `set_event_callback()`, `branch_name()`, `base_sha()`, `worktree_path()`\n\n**`initialize()`:**\n1. If `!skip_branch_creation`: `git branch --force {branch_name} {base_sha}` via `inner.exec_command()`, emit `BranchCreated`\n2. `git worktree remove --force {path}` (best-effort), then `git worktree add {path} {branch}`, emit `WorktreeAdded`\n3. If `!skip_branch_creation`: `git reset --hard {base_sha}` in worktree dir, emit `Reset`\n\nDoes NOT call `inner.initialize()` — the inner sandbox's lifecycle is managed separately.\n\n**`cleanup()`:** `git worktree remove --force {path}`, emit `WorktreeRemoved`. Does NOT call `inner.cleanup()`.\n\n**`working_directory()`:** Returns `config.worktree_path`.\n\n**`exec_command()`:** Defaults `working_dir` to `config.worktree_path` when `None`, delegates to inner.\n\n**All other Sandbox methods:** Delegate to inner. Must be a manual `impl Sandbox` block (can't use `delegate_sandbox!` since it generates `initialize`/`cleanup`/`working_directory`/`exec_command` which we need to override).\n\nAll interpolated values in git commands use `shell_quote()`.\n\n### Step 2: Register module and re-exports\n\n- `lib/crates/fabro-sandbox/src/lib.rs`: Add `pub mod worktree;` and `pub use worktree::WorktreeSandbox;`\n- `lib/crates/fabro-agent/src/sandbox.rs`: Add re-export of `WorktreeSandbox`\n\n### Step 3: Unit tests for WorktreeSandbox\n\nIn `worktree.rs` `#[cfg(test)]` module, using `MockSandbox`:\n\n- `initialize()` issues correct git commands (branch, worktree remove, worktree add, reset) and emits events\n- `skip_branch_creation` skips branch + reset, only does worktree add\n- `cleanup()` issues `worktree remove` and emits `WorktreeRemoved`\n- `working_directory()` returns worktree path\n- `exec_command()` with `None` working_dir defaults to worktree path\n- `exec_command()` with explicit working_dir passes it through\n- `initialize()` propagates errors on non-zero exit\n\n**MockSandbox enhancement:** Add `captured_commands: Mutex>` field to `test_support.rs` to capture the sequence of `exec_command` calls (current `captured_command` only stores the last one). Append to vec in `exec_command()` impl.\n\n### Step 4: Refactor parallel.rs\n\n- **Remove** the private `WorktreeSandbox` struct (lines 28-126) and `use fabro_agent::LocalSandbox`\n- **Replace** the inline git setup loop (lines 361-450) with:\n - Construct `WorktreeConfig` with branch name, base SHA, worktree path\n - Create `WorktreeSandbox::new(Arc::clone(&services.sandbox), config)`\n - Wire event callback to bridge `WorktreeEvent` → `WorkflowRunEvent`\n - Call `initialize().await`\n- This eliminates the `if services.sandbox.is_remote()` branch (lines 442-449) — `WorktreeSandbox` works the same for any inner sandbox\n- **Cleanup loop** (lines 659-668): Keep calling `git_remove_worktree()` on the parent sandbox (the `WorktreeSandbox` Arc is consumed by the spawned task and dropped). Alternatively, could store the sandbox Arc in `BranchResult` and call `.cleanup()`, but the current approach is simpler.\n\n### Step 5: Refactor run.rs — new runs\n\nReplace `setup_worktree()` call (lines 830-845) + separate `LocalSandbox` construction with:\n\n```\nif workdir_strategy == LocalWorktree:\n base_sha = git::head_sha()\n branch_name = \"fabro/run/{run_id}\"\n inner = Arc::new(LocalSandbox::new(original_cwd))\n wt_sandbox = WorktreeSandbox::new(inner, WorktreeConfig { ... })\n wt_sandbox.set_event_callback(bridge to WorkflowRunEvent)\n wt_sandbox.initialize().await\n std::env::set_current_dir(&worktree_path) // stays in CLI, not in sandbox\n sandbox = Arc::new(wt_sandbox)\n // store base_sha, branch_name for RunConfig\n```\n\n**Delete** the `setup_worktree()` function (lines 1696-1714) — its logic is absorbed above.\n\n`std::env::set_current_dir()` stays in `run.rs` — it's a process-global side effect that belongs to the CLI.\n\n### Step 6: Refactor run.rs — resume (run_from_branch)\n\nReplace worktree re-attachment (lines 1810-1822) with:\n\n```\ninner = Arc::new(LocalSandbox::new(original_cwd))\nwt_sandbox = WorktreeSandbox::new(inner, WorktreeConfig {\n branch_name: run_branch,\n base_sha: base_sha.unwrap_or_default(),\n worktree_path: wt_str,\n skip_branch_creation: true, // branch already exists\n})\nwt_sandbox.initialize().await\nstd::env::set_current_dir(&wt)\n```\n\n### Step 7: Verify\n\n- `cargo build --workspace`\n- `cargo test --workspace`\n- `cargo clippy --workspace -- -D warnings`\n- Manual: `fabro run` with worktree mode enabled on a local workflow\n- Manual: `fabro run --run-branch` to test resume path\n\n## Files to modify\n\n| File | Change |\n|---|---|\n| `lib/crates/fabro-sandbox/src/worktree.rs` | **New** — WorktreeSandbox, WorktreeConfig, WorktreeEvent, impl Sandbox, tests |\n| `lib/crates/fabro-sandbox/src/lib.rs` | Add module + re-export |\n| `lib/crates/fabro-sandbox/src/test_support.rs` | Add `captured_commands: Mutex>` to MockSandbox |\n| `lib/crates/fabro-agent/src/sandbox.rs` | Add WorktreeSandbox re-export |\n| `lib/crates/fabro-workflows/src/handler/parallel.rs` | Remove old WorktreeSandbox, use new one |\n| `lib/crates/fabro-cli/src/commands/run.rs` | Replace setup_worktree + run_from_branch worktree logic |\n\n## Functions that become removable\n\n| Function | Location | Reason |\n|---|---|---|\n| `setup_worktree()` | `run.rs:1696` | Logic absorbed into WorktreeSandbox |\n| Old `WorktreeSandbox` struct | `parallel.rs:28-126` | Replaced by shared WorktreeSandbox |\n\nEngine git helpers (`git_add_worktree`, `git_remove_worktree`, etc. in `engine.rs`) stay — still used by parallel cleanup and potentially other callers. Sync git helpers in `git.rs` also stay.\n\n\n## Completed stages\n- **toolchain**: success\n - Script: `command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1`\n - Stdout:\n ```\n cargo 1.94.0 (85eff7c80 2026-01-15)\n ```\n - Stderr: (empty)\n- **preflight_compile**: success\n - Script: `cargo check -q --workspace 2>&1`\n - Stdout: (empty)\n - Stderr: (empty)\n- **preflight_lint**: success\n - Script: `cargo clippy -q --workspace -- -D warnings 2>&1`\n - Stdout: (empty)\n - Stderr: (empty)\n- **implement**: success\n - Model: claude-sonnet-4-6, 190.9k tokens in / 105.0k out\n - Files: /home/daytona/workspace/lib/crates/fabro-agent/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-agent/src/sandbox.rs, /home/daytona/workspace/lib/crates/fabro-cli/src/commands/run.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/test_support.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/worktree.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n- **simplify_opus**: success\n - Model: claude-sonnet-4-6, 84.8k tokens in / 30.2k out\n - Files: /home/daytona/workspace/lib/crates/fabro-cli/src/commands/run.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n- **simplify_gpt**: success\n - Model: claude-sonnet-4-6, 65.5k tokens in / 23.2k out\n - Files: /home/daytona/workspace/lib/crates/fabro-cli/src/commands/run.rs, /home/daytona/workspace/lib/crates/fabro-sandbox/src/worktree.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/event.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n- **verify**: success\n - Script: `cargo clippy -q --workspace -- -D warnings 2>&1 && cargo nextest run --cargo-quiet --workspace --status-level fail 2>&1`\n - Stdout:\n ```\n ────────────\n Nextest run ID 743fdc16-ccf2-4b01-9e7e-647d6c23e3f2 with nextest profile: default\n Starting 3226 tests across 41 binaries (177 tests skipped)\n ────────────\n Summary [ 14.596s] 3226 tests run: 3226 passed, 177 skipped\n ```\n - Stderr: (empty)\n- **fixup**: success\n - Model: claude-sonnet-4-6, 45.4k tokens in / 8.9k out\n - Files: /home/daytona/workspace/lib/crates/fabro-sandbox/src/worktree.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/git.rs\n- **verify**: success\n - Script: `cargo clippy -q --workspace -- -D warnings 2>&1 && cargo nextest run --cargo-quiet --workspace --status-level fail 2>&1`\n - Stdout:\n ```\n ────────────\n Nextest run ID 743fdc16-ccf2-4b01-9e7e-647d6c23e3f2 with nextest profile: default\n Starting 3226 tests across 41 binaries (177 tests skipped)\n ────────────\n Summary [ 14.596s] 3226 tests run: 3226 passed, 177 skipped\n ```\n - Stderr: (empty)\n", "last_stage": "fixup", "response.simplify_opus": "Zero warnings. Here's a summary of what was fixed:\n\n## Fixes Applied\n\n### 1. Extracted `WorktreeEvent → WorkflowRunEvent` callback helper (3 → 1)\nThe same 12-line match block mapping `WorktreeEvent` variants to `WorkflowRunEvent` was duplicated in three places:\n- `run.rs`: new-run path (`SandboxProvider::Local`)\n- `run.rs`: resume path (`run_from_branch`)\n- `parallel.rs`: branch worktree setup\n\n**Fix:** Added `fn worktree_event_callback(emitter: Arc) -> WorktreeEventCallback` to each file as a local helper, replacing all three inline match blocks with a single call.\n\n### 2. Extracted `LocalSandbox + event_callback` helper (3 → 1)\nIn `run.rs`, the pattern `let mut env = LocalSandbox::new(cwd); env.set_event_callback(...); Arc::new(env)` appeared twice in the same match arm (fallback on error + else branch) and again in `run_from_branch`.\n\n**Fix:** Added `fn local_sandbox_with_callback(cwd: PathBuf, emitter: Arc) -> Arc` and replaced all three sites.\n\n### 3. Eliminated `.clone().unwrap()` on `Option`\n`worktree_base_sha.clone().unwrap()` (and same for `branch_name`, `wt_path`) cloned the entire `Option` before unwrapping. \n\n**Fix:** Changed `if worktree_base_sha.is_some()` to `if let (Some(base_sha), Some(branch_name), Some(wt_path)) = (worktree_base_sha.as_ref(), ...)` — borrows the inner values directly, then only clones the `String`/`PathBuf` when actually needed for `WorktreeConfig`.\n\n### 4. Fixed `.to_string_lossy().to_string()` → `.into_owned()` (3 sites)\n`.to_string_lossy().to_string()` calls `.to_string()` on a `Cow`, which allocates a new `String` even when `Cow` is already `Owned`. `.into_owned()` moves directly from `Cow::Owned` without the extra allocation.", - "current_node": "verify", + "current_node": "fmt", "thread.simplify_gpt.current_node": "verify", - "thread.verify.current_node": "fixup", - "internal.node_visit_count": 2, + "thread.verify.current_node": "fmt", + "internal.node_visit_count": 1, "internal.retry_count.simplify_gpt": 1, "response.implement": "Zero failures and zero errors. Let me provide a summary of all changes made:\n\n## Summary of Changes\n\n### New file: `lib/crates/fabro-sandbox/src/worktree.rs`\n- Defines `WorktreeEvent` enum (BranchCreated, WorktreeAdded, WorktreeRemoved, Reset)\n- Defines `WorktreeEventCallback` type alias\n- Defines `WorktreeConfig` struct (branch_name, base_sha, worktree_path, skip_branch_creation)\n- Implements `WorktreeSandbox` struct wrapping `Arc` with:\n - `initialize()`: runs git branch + worktree remove + worktree add + reset, emitting events; does NOT call inner's `initialize()`\n - `cleanup()`: runs git worktree remove, emits WorktreeRemoved; does NOT call inner's `cleanup()`\n - `working_directory()`: returns `config.worktree_path`\n - `exec_command()`: defaults `working_dir` to `config.worktree_path` when `None`\n - All other `Sandbox` methods delegate to inner\n- 14 unit tests covering all specified behaviors (TDD green)\n\n### Modified: `lib/crates/fabro-sandbox/src/test_support.rs`\n- Added `captured_commands: Mutex>` to `MockSandbox` (captures all commands in sequence)\n- Added `captured_working_dirs: Mutex>>` to `MockSandbox` (captures working_dir per call)\n- Updated `exec_command()` to populate both new fields alongside existing `captured_command`\n\n### Modified: `lib/crates/fabro-sandbox/src/lib.rs`\n- Added `pub mod worktree;`\n- Added `pub use worktree::{WorktreeConfig, WorktreeEvent, WorktreeEventCallback, WorktreeSandbox};`\n\n### Modified: `lib/crates/fabro-agent/src/sandbox.rs` + `lib.rs`\n- Re-exported `WorktreeConfig`, `WorktreeEvent`, `WorktreeEventCallback`, `WorktreeSandbox` from `fabro_sandbox`\n- Also re-exported `shell_quote` (which was already in `sandbox.rs` but not in `lib.rs`)\n\n### Modified: `lib/crates/fabro-workflows/src/handler/parallel.rs`\n- Removed the private `WorktreeSandbox` struct and its full `impl Sandbox` (126 lines deleted)\n- Removed `use fabro_agent::LocalSandbox`\n- Added `use fabro_agent::{WorktreeConfig, WorktreeEvent, WorktreeSandbox}`\n- Replaced the inline git setup loop (branch creation, worktree add, reset, `is_remote()` branch for sandbox type) with a `WorktreeSandbox` that handles all of this uniformly for any inner sandbox\n\n### Modified: `lib/crates/fabro-cli/src/commands/run.rs`\n- Added `WorktreeConfig`, `WorktreeEvent`, `WorktreeSandbox` to imports\n- **New runs**: Replaced `setup_worktree()` call with inline config computation (head_sha, branch_name, worktree_path), and replaced `LocalSandbox::new(cwd)` in `SandboxProvider::Local` with `WorktreeSandbox::new(LocalSandbox(original_cwd), config)` + `initialize().await` + `set_current_dir()`; graceful fallback on failure\n- **Resume** (`run_from_branch`): Replaced `replace_worktree()` + `LocalSandbox::new(wt)` with `WorktreeSandbox::new(LocalSandbox(original_cwd), {skip_branch_creation: true})` + `initialize().await`\n- Deleted `setup_worktree()` function (logic absorbed into `WorktreeSandbox`)\n- Replaced `worktree_work_dir.is_some()` with `worktree_path.is_some()` for `meta_branch` and `git_checkpoint_enabled`", "internal.retry_count.preflight_compile": 1, "internal.retry_count.implement": 1, "thread.simplify_opus.current_node": "simplify_gpt", + "internal.retry_count.fmt": 1, "internal.run_id": "01KM4CC4HA0SYCXGQW7BJWJE8F", "thread.preflight_lint.current_node": "implement", "thread.fixup.current_node": "verify", "internal.retry_count.toolchain": 1, - "command.output": "────────────\n Nextest run ID 743fdc16-ccf2-4b01-9e7e-647d6c23e3f2 with nextest profile: default\n Starting 3226 tests across 41 binaries (177 tests skipped)\n────────────\n Summary [ 14.596s] 3226 tests run: 3226 passed, 177 skipped\n", + "command.output": "", "graph.model_stylesheet": "\n * { backend: api; model: claude-opus-4-6;}\n ", "graph.rankdir": "LR", "internal.retry_count.simplify_opus": 1, "graph.goal": "# Unified WorktreeSandbox\n\n## Context\n\nWorktree management is currently split across two locations with duplicated logic:\n\n1. **Parallel branches** (`parallel.rs`): Inline git commands in `ParallelHandler::execute()`, a thin `WorktreeSandbox` decorator, and separate local/remote code paths\n2. **Top-level CLI run** (`run.rs`): A `setup_worktree()` function using synchronous git helpers, with the worktree path fed into a plain `LocalSandbox`\n\nThe goal is a single `WorktreeSandbox` type that wraps any `Arc`, manages the worktree lifecycle in `initialize()`/`cleanup()`, and eliminates the local/remote branching.\n\n## Plan\n\n### Step 1: Create `WorktreeSandbox` in fabro-sandbox\n\n**New file:** `lib/crates/fabro-sandbox/src/worktree.rs`\n\nDefine:\n\n```rust\npub enum WorktreeEvent {\n BranchCreated { branch: String, sha: String },\n WorktreeAdded { path: String, branch: String },\n WorktreeRemoved { path: String },\n Reset { sha: String },\n}\n\npub type WorktreeEventCallback = Arc;\n\npub struct WorktreeConfig {\n pub branch_name: String,\n pub base_sha: String,\n pub worktree_path: String,\n /// Skip branch creation and reset (for resume, where branch already exists).\n pub skip_branch_creation: bool,\n}\n\npub struct WorktreeSandbox {\n inner: Arc,\n config: WorktreeConfig,\n event_callback: Option,\n}\n```\n\n**Constructor + getters:** `new(inner, config)`, `set_event_callback()`, `branch_name()`, `base_sha()`, `worktree_path()`\n\n**`initialize()`:**\n1. If `!skip_branch_creation`: `git branch --force {branch_name} {base_sha}` via `inner.exec_command()`, emit `BranchCreated`\n2. `git worktree remove --force {path}` (best-effort), then `git worktree add {path} {branch}`, emit `WorktreeAdded`\n3. If `!skip_branch_creation`: `git reset --hard {base_sha}` in worktree dir, emit `Reset`\n\nDoes NOT call `inner.initialize()` — the inner sandbox's lifecycle is managed separately.\n\n**`cleanup()`:** `git worktree remove --force {path}`, emit `WorktreeRemoved`. Does NOT call `inner.cleanup()`.\n\n**`working_directory()`:** Returns `config.worktree_path`.\n\n**`exec_command()`:** Defaults `working_dir` to `config.worktree_path` when `None`, delegates to inner.\n\n**All other Sandbox methods:** Delegate to inner. Must be a manual `impl Sandbox` block (can't use `delegate_sandbox!` since it generates `initialize`/`cleanup`/`working_directory`/`exec_command` which we need to override).\n\nAll interpolated values in git commands use `shell_quote()`.\n\n### Step 2: Register module and re-exports\n\n- `lib/crates/fabro-sandbox/src/lib.rs`: Add `pub mod worktree;` and `pub use worktree::WorktreeSandbox;`\n- `lib/crates/fabro-agent/src/sandbox.rs`: Add re-export of `WorktreeSandbox`\n\n### Step 3: Unit tests for WorktreeSandbox\n\nIn `worktree.rs` `#[cfg(test)]` module, using `MockSandbox`:\n\n- `initialize()` issues correct git commands (branch, worktree remove, worktree add, reset) and emits events\n- `skip_branch_creation` skips branch + reset, only does worktree add\n- `cleanup()` issues `worktree remove` and emits `WorktreeRemoved`\n- `working_directory()` returns worktree path\n- `exec_command()` with `None` working_dir defaults to worktree path\n- `exec_command()` with explicit working_dir passes it through\n- `initialize()` propagates errors on non-zero exit\n\n**MockSandbox enhancement:** Add `captured_commands: Mutex>` field to `test_support.rs` to capture the sequence of `exec_command` calls (current `captured_command` only stores the last one). Append to vec in `exec_command()` impl.\n\n### Step 4: Refactor parallel.rs\n\n- **Remove** the private `WorktreeSandbox` struct (lines 28-126) and `use fabro_agent::LocalSandbox`\n- **Replace** the inline git setup loop (lines 361-450) with:\n - Construct `WorktreeConfig` with branch name, base SHA, worktree path\n - Create `WorktreeSandbox::new(Arc::clone(&services.sandbox), config)`\n - Wire event callback to bridge `WorktreeEvent` → `WorkflowRunEvent`\n - Call `initialize().await`\n- This eliminates the `if services.sandbox.is_remote()` branch (lines 442-449) — `WorktreeSandbox` works the same for any inner sandbox\n- **Cleanup loop** (lines 659-668): Keep calling `git_remove_worktree()` on the parent sandbox (the `WorktreeSandbox` Arc is consumed by the spawned task and dropped). Alternatively, could store the sandbox Arc in `BranchResult` and call `.cleanup()`, but the current approach is simpler.\n\n### Step 5: Refactor run.rs — new runs\n\nReplace `setup_worktree()` call (lines 830-845) + separate `LocalSandbox` construction with:\n\n```\nif workdir_strategy == LocalWorktree:\n base_sha = git::head_sha()\n branch_name = \"fabro/run/{run_id}\"\n inner = Arc::new(LocalSandbox::new(original_cwd))\n wt_sandbox = WorktreeSandbox::new(inner, WorktreeConfig { ... })\n wt_sandbox.set_event_callback(bridge to WorkflowRunEvent)\n wt_sandbox.initialize().await\n std::env::set_current_dir(&worktree_path) // stays in CLI, not in sandbox\n sandbox = Arc::new(wt_sandbox)\n // store base_sha, branch_name for RunConfig\n```\n\n**Delete** the `setup_worktree()` function (lines 1696-1714) — its logic is absorbed above.\n\n`std::env::set_current_dir()` stays in `run.rs` — it's a process-global side effect that belongs to the CLI.\n\n### Step 6: Refactor run.rs — resume (run_from_branch)\n\nReplace worktree re-attachment (lines 1810-1822) with:\n\n```\ninner = Arc::new(LocalSandbox::new(original_cwd))\nwt_sandbox = WorktreeSandbox::new(inner, WorktreeConfig {\n branch_name: run_branch,\n base_sha: base_sha.unwrap_or_default(),\n worktree_path: wt_str,\n skip_branch_creation: true, // branch already exists\n})\nwt_sandbox.initialize().await\nstd::env::set_current_dir(&wt)\n```\n\n### Step 7: Verify\n\n- `cargo build --workspace`\n- `cargo test --workspace`\n- `cargo clippy --workspace -- -D warnings`\n- Manual: `fabro run` with worktree mode enabled on a local workflow\n- Manual: `fabro run --run-branch` to test resume path\n\n## Files to modify\n\n| File | Change |\n|---|---|\n| `lib/crates/fabro-sandbox/src/worktree.rs` | **New** — WorktreeSandbox, WorktreeConfig, WorktreeEvent, impl Sandbox, tests |\n| `lib/crates/fabro-sandbox/src/lib.rs` | Add module + re-export |\n| `lib/crates/fabro-sandbox/src/test_support.rs` | Add `captured_commands: Mutex>` to MockSandbox |\n| `lib/crates/fabro-agent/src/sandbox.rs` | Add WorktreeSandbox re-export |\n| `lib/crates/fabro-workflows/src/handler/parallel.rs` | Remove old WorktreeSandbox, use new one |\n| `lib/crates/fabro-cli/src/commands/run.rs` | Replace setup_worktree + run_from_branch worktree logic |\n\n## Functions that become removable\n\n| Function | Location | Reason |\n|---|---|---|\n| `setup_worktree()` | `run.rs:1696` | Logic absorbed into WorktreeSandbox |\n| Old `WorktreeSandbox` struct | `parallel.rs:28-126` | Replaced by shared WorktreeSandbox |\n\nEngine git helpers (`git_add_worktree`, `git_remove_worktree`, etc. in `engine.rs`) stay — still used by parallel cleanup and potentially other callers. Sync git helpers in `git.rs` also stay.\n", "internal.retry_count.start": 1, "failure_signature": "", - "internal.thread_id": "fixup", + "internal.thread_id": "verify", "outcome": "success", "internal.fidelity": "compact", "command.stderr": "", @@ -66,6 +69,15 @@ }, "logs": [], "node_outcomes": { + "fmt": { + "status": "success", + "context_updates": { + "command.stderr": "", + "command.output": "" + }, + "notes": "Script completed: cargo fmt --all 2>&1", + "duration_ms": 1256 + }, "preflight_compile": { "status": "success", "context_updates": { @@ -206,11 +218,12 @@ "duration_ms": 0 } }, - "next_node_id": "fmt", + "next_node_id": "exit", "node_visits": { "preflight_compile": 1, "simplify_gpt": 1, "start": 1, + "fmt": 1, "implement": 1, "verify": 2, "preflight_lint": 1, diff --git a/nodes/fmt/script_invocation.json b/nodes/fmt/script_invocation.json new file mode 100644 index 000000000..237863974 --- /dev/null +++ b/nodes/fmt/script_invocation.json @@ -0,0 +1,5 @@ +{ + "command": "cargo fmt --all 2>&1", + "language": "shell", + "timeout_ms": null +} \ No newline at end of file diff --git a/nodes/fmt/script_timing.json b/nodes/fmt/script_timing.json new file mode 100644 index 000000000..96e5b7831 --- /dev/null +++ b/nodes/fmt/script_timing.json @@ -0,0 +1,5 @@ +{ + "duration_ms": 1255, + "exit_code": 0, + "timed_out": false +} \ No newline at end of file diff --git a/nodes/fmt/status.json b/nodes/fmt/status.json new file mode 100644 index 000000000..6a5ef2e8d --- /dev/null +++ b/nodes/fmt/status.json @@ -0,0 +1,6 @@ +{ + "status": "success", + "notes": "Script completed: cargo fmt --all 2>&1", + "failure_reason": null, + "timestamp": "2026-03-20T02:07:21.545434+00:00" +} \ No newline at end of file