diff --git a/checkpoint.json b/checkpoint.json index ce7f26d19..7c22f58a7 100644 --- a/checkpoint.json +++ b/checkpoint.json @@ -1,47 +1,52 @@ { - "timestamp": "2026-03-16T02:04:57.223407Z", - "current_node": "implement", + "timestamp": "2026-03-16T02:10:22.218007Z", + "current_node": "simplify_opus", "completed_nodes": [ "start", "toolchain", "preflight_compile", "preflight_lint", - "implement" + "implement", + "simplify_opus" ], "node_retries": { "preflight_compile": 1, "preflight_lint": 1, "start": 1, "toolchain": 1, - "implement": 1 + "implement": 1, + "simplify_opus": 1 }, "context_values": { - "thread.preflight_lint.current_node": "implement", "internal.retry_count.preflight_lint": 1, - "internal.retry_count.implement": 1, - "current.preamble": "Goal: # Wire up missing hook invocations\n\n## Context\n\nFive `HookEvent` variants exist in the enum and are documented in `docs/agents/hooks.mdx`, but `run_hooks()` is never called for them in the engine. Users can configure hooks for these events, but they silently never fire.\n\n**Events to wire up:** `StageRetrying`, `ParallelStart`, `ParallelComplete`\n**Events to mark as reserved:** `SandboxReady`, `SandboxCleanup` (sandbox lifecycle is managed outside the engine; wiring these requires significant architecture changes)\n\n## Changes\n\n### 1. Add StageRetrying hook calls in `engine.rs`\n\nFile: `lib/crates/fabro-workflows/src/engine.rs`\n\nTwo sites in `execute_with_retry`, both immediately after `WorkflowRunEvent::StageRetrying` emission and before `tokio::time::sleep(delay).await`:\n\n- **Site A (~line 1127):** error-retry path\n- **Site B (~line 1155):** explicit Retry status path\n\nPattern (same for both sites):\n```rust\n{\n let mut hook_ctx = HookContext::new(\n HookEvent::StageRetrying,\n context.run_id(),\n graph.name.clone(),\n );\n hook_ctx.node_id = Some(node.id.clone());\n hook_ctx.node_label = Some(node.label().to_string());\n hook_ctx.handler_type = node.handler_type().map(String::from);\n hook_ctx.attempt = Some(usize::try_from(attempt).unwrap_or(usize::MAX));\n hook_ctx.max_attempts = Some(\n usize::try_from(policy.max_attempts).unwrap_or(usize::MAX),\n );\n let _ = self.run_hooks(&hook_ctx, None).await;\n}\n```\n\nAvailable via: `self.run_hooks()` (engine method), `context.run_id()`, `graph.name`, `node`, `attempt`, `policy`.\n\n### 2. Add ParallelStart hook call in `parallel.rs`\n\nFile: `lib/crates/fabro-workflows/src/handler/parallel.rs`\n\nAfter `ParallelStarted` event emission (~line 301). Call `hook_runner.run()` directly since the handler has `services: &EngineServices` (which has `hook_runner` and `sandbox`):\n\n```rust\nif let Some(ref runner) = services.hook_runner {\n let hook_ctx = HookContext::new(\n HookEvent::ParallelStart,\n context.run_id(),\n graph.name.clone(),\n );\n let _ = runner\n .run(&hook_ctx, services.sandbox.clone(), None)\n .await;\n}\n```\n\n### 3. Add ParallelComplete hook call in `parallel.rs`\n\nSame file, after `ParallelCompleted` event emission (~line 713). Same pattern as ParallelStart but with `HookEvent::ParallelComplete`.\n\n### 4. Mark SandboxReady/SandboxCleanup as reserved\n\nFile: `lib/crates/fabro-workflows/src/hook/types.rs`\n\nAdd doc comments:\n```rust\n/// Reserved: hooks for this event are not yet invoked by the engine.\nSandboxReady,\n/// Reserved: hooks for this event are not yet invoked by the engine.\nSandboxCleanup,\n```\n\n### 5. Update docs\n\nFile: `docs/agents/hooks.mdx`\n\nIn the lifecycle events table, annotate `sandbox_ready` and `sandbox_cleanup` rows — e.g., append \"(not yet wired)\" to the description or add a note.\n\n## Verification\n\n1. `cargo fmt --check --all`\n2. `cargo clippy --workspace -- -D warnings`\n3. `cargo test --workspace` — existing tests pass, no regressions\n4. Manual test: create a workflow with a retrying node and a `post_tool_use`-style hook for `stage_retrying`, verify it fires in the CLI log\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", + "current.preamble": "Goal: # Wire up missing hook invocations\n\n## Context\n\nFive `HookEvent` variants exist in the enum and are documented in `docs/agents/hooks.mdx`, but `run_hooks()` is never called for them in the engine. Users can configure hooks for these events, but they silently never fire.\n\n**Events to wire up:** `StageRetrying`, `ParallelStart`, `ParallelComplete`\n**Events to mark as reserved:** `SandboxReady`, `SandboxCleanup` (sandbox lifecycle is managed outside the engine; wiring these requires significant architecture changes)\n\n## Changes\n\n### 1. Add StageRetrying hook calls in `engine.rs`\n\nFile: `lib/crates/fabro-workflows/src/engine.rs`\n\nTwo sites in `execute_with_retry`, both immediately after `WorkflowRunEvent::StageRetrying` emission and before `tokio::time::sleep(delay).await`:\n\n- **Site A (~line 1127):** error-retry path\n- **Site B (~line 1155):** explicit Retry status path\n\nPattern (same for both sites):\n```rust\n{\n let mut hook_ctx = HookContext::new(\n HookEvent::StageRetrying,\n context.run_id(),\n graph.name.clone(),\n );\n hook_ctx.node_id = Some(node.id.clone());\n hook_ctx.node_label = Some(node.label().to_string());\n hook_ctx.handler_type = node.handler_type().map(String::from);\n hook_ctx.attempt = Some(usize::try_from(attempt).unwrap_or(usize::MAX));\n hook_ctx.max_attempts = Some(\n usize::try_from(policy.max_attempts).unwrap_or(usize::MAX),\n );\n let _ = self.run_hooks(&hook_ctx, None).await;\n}\n```\n\nAvailable via: `self.run_hooks()` (engine method), `context.run_id()`, `graph.name`, `node`, `attempt`, `policy`.\n\n### 2. Add ParallelStart hook call in `parallel.rs`\n\nFile: `lib/crates/fabro-workflows/src/handler/parallel.rs`\n\nAfter `ParallelStarted` event emission (~line 301). Call `hook_runner.run()` directly since the handler has `services: &EngineServices` (which has `hook_runner` and `sandbox`):\n\n```rust\nif let Some(ref runner) = services.hook_runner {\n let hook_ctx = HookContext::new(\n HookEvent::ParallelStart,\n context.run_id(),\n graph.name.clone(),\n );\n let _ = runner\n .run(&hook_ctx, services.sandbox.clone(), None)\n .await;\n}\n```\n\n### 3. Add ParallelComplete hook call in `parallel.rs`\n\nSame file, after `ParallelCompleted` event emission (~line 713). Same pattern as ParallelStart but with `HookEvent::ParallelComplete`.\n\n### 4. Mark SandboxReady/SandboxCleanup as reserved\n\nFile: `lib/crates/fabro-workflows/src/hook/types.rs`\n\nAdd doc comments:\n```rust\n/// Reserved: hooks for this event are not yet invoked by the engine.\nSandboxReady,\n/// Reserved: hooks for this event are not yet invoked by the engine.\nSandboxCleanup,\n```\n\n### 5. Update docs\n\nFile: `docs/agents/hooks.mdx`\n\nIn the lifecycle events table, annotate `sandbox_ready` and `sandbox_cleanup` rows — e.g., append \"(not yet wired)\" to the description or add a note.\n\n## Verification\n\n1. `cargo fmt --check --all`\n2. `cargo clippy --workspace -- -D warnings`\n3. `cargo test --workspace` — existing tests pass, no regressions\n4. Manual test: create a workflow with a retrying node and a `post_tool_use`-style hook for `stage_retrying`, verify it fires in the CLI log\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-opus-4-6, 33.1k tokens in / 7.2k out\n - Files: /home/daytona/workspace/lib/crates/fabro-workflows/src/engine.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs\n", "graph.goal": "# Wire up missing hook invocations\n\n## Context\n\nFive `HookEvent` variants exist in the enum and are documented in `docs/agents/hooks.mdx`, but `run_hooks()` is never called for them in the engine. Users can configure hooks for these events, but they silently never fire.\n\n**Events to wire up:** `StageRetrying`, `ParallelStart`, `ParallelComplete`\n**Events to mark as reserved:** `SandboxReady`, `SandboxCleanup` (sandbox lifecycle is managed outside the engine; wiring these requires significant architecture changes)\n\n## Changes\n\n### 1. Add StageRetrying hook calls in `engine.rs`\n\nFile: `lib/crates/fabro-workflows/src/engine.rs`\n\nTwo sites in `execute_with_retry`, both immediately after `WorkflowRunEvent::StageRetrying` emission and before `tokio::time::sleep(delay).await`:\n\n- **Site A (~line 1127):** error-retry path\n- **Site B (~line 1155):** explicit Retry status path\n\nPattern (same for both sites):\n```rust\n{\n let mut hook_ctx = HookContext::new(\n HookEvent::StageRetrying,\n context.run_id(),\n graph.name.clone(),\n );\n hook_ctx.node_id = Some(node.id.clone());\n hook_ctx.node_label = Some(node.label().to_string());\n hook_ctx.handler_type = node.handler_type().map(String::from);\n hook_ctx.attempt = Some(usize::try_from(attempt).unwrap_or(usize::MAX));\n hook_ctx.max_attempts = Some(\n usize::try_from(policy.max_attempts).unwrap_or(usize::MAX),\n );\n let _ = self.run_hooks(&hook_ctx, None).await;\n}\n```\n\nAvailable via: `self.run_hooks()` (engine method), `context.run_id()`, `graph.name`, `node`, `attempt`, `policy`.\n\n### 2. Add ParallelStart hook call in `parallel.rs`\n\nFile: `lib/crates/fabro-workflows/src/handler/parallel.rs`\n\nAfter `ParallelStarted` event emission (~line 301). Call `hook_runner.run()` directly since the handler has `services: &EngineServices` (which has `hook_runner` and `sandbox`):\n\n```rust\nif let Some(ref runner) = services.hook_runner {\n let hook_ctx = HookContext::new(\n HookEvent::ParallelStart,\n context.run_id(),\n graph.name.clone(),\n );\n let _ = runner\n .run(&hook_ctx, services.sandbox.clone(), None)\n .await;\n}\n```\n\n### 3. Add ParallelComplete hook call in `parallel.rs`\n\nSame file, after `ParallelCompleted` event emission (~line 713). Same pattern as ParallelStart but with `HookEvent::ParallelComplete`.\n\n### 4. Mark SandboxReady/SandboxCleanup as reserved\n\nFile: `lib/crates/fabro-workflows/src/hook/types.rs`\n\nAdd doc comments:\n```rust\n/// Reserved: hooks for this event are not yet invoked by the engine.\nSandboxReady,\n/// Reserved: hooks for this event are not yet invoked by the engine.\nSandboxCleanup,\n```\n\n### 5. Update docs\n\nFile: `docs/agents/hooks.mdx`\n\nIn the lifecycle events table, annotate `sandbox_ready` and `sandbox_cleanup` rows — e.g., append \"(not yet wired)\" to the description or add a note.\n\n## Verification\n\n1. `cargo fmt --check --all`\n2. `cargo clippy --workspace -- -D warnings`\n3. `cargo test --workspace` — existing tests pass, no regressions\n4. Manual test: create a workflow with a retrying node and a `post_tool_use`-style hook for `stage_retrying`, verify it fires in the CLI log\n", - "failure_class": "", - "failure_signature": "", - "thread.toolchain.current_node": "preflight_compile", - "graph.model_stylesheet": "\n * { backend: api; model: claude-opus-4-6;}\n ", + "internal.retry_count.simplify_opus": 1, "internal.fidelity": "compact", - "internal.retry_count.start": 1, - "response.implement": "All changes are complete and verified. Here's a summary of what was done:\n\n### Changes Made\n\n1. **`lib/crates/fabro-workflows/src/engine.rs`** — Added `StageRetrying` hook calls at both retry sites in `execute_with_retry`:\n - **Site A (error-retry path, ~line 1128):** After `WorkflowRunEvent::StageRetrying` emission, before `tokio::time::sleep(delay).await`\n - **Site B (explicit Retry status path, ~line 1165):** Same pattern, after the event emission and before the sleep\n\n2. **`lib/crates/fabro-workflows/src/handler/parallel.rs`** — Added `ParallelStart` and `ParallelComplete` hook calls:\n - Added `use crate::hook::{HookContext, HookEvent};` import\n - After `ParallelStarted` event emission: calls `runner.run()` with `HookEvent::ParallelStart`\n - After `ParallelCompleted` event emission: calls `runner.run()` with `HookEvent::ParallelComplete`\n\n3. **`lib/crates/fabro-workflows/src/hook/types.rs`** — Added `/// Reserved: hooks for this event are not yet invoked by the engine.` doc comments to `SandboxReady` and `SandboxCleanup` variants\n\n4. **`docs/agents/hooks.mdx`** — Annotated `sandbox_ready` and `sandbox_cleanup` rows with \"(reserved — not yet wired)\"\n\n### Verification\n- `cargo fmt --check --all` ✅\n- `cargo clippy --workspace -- -D warnings` ✅ \n- `cargo test --workspace` ✅ (179 passed, 0 failed, 13 ignored)", "internal.run_id": "01KKT5VGGG35Y853TNCTBVB39R", - "last_stage": "implement", - "last_response": "All changes are complete and verified. Here's a summary of what was done:\n\n### Changes Made\n\n1. **`lib/crates/fabro-workflows/src/engine.rs`** — Added `StageRetrying` hook calls at both retry sites ", + "thread.implement.current_node": "simplify_opus", + "last_stage": "simplify_opus", "command.output": "", "thread.preflight_compile.current_node": "preflight_lint", - "current_node": "implement", + "internal.retry_count.implement": 1, + "graph.rankdir": "LR", + "internal.retry_count.preflight_compile": 1, + "response.simplify_opus": "All clean. Here's a summary of what was fixed:\n\n### Changes Made\n\n1. **Extracted duplicated StageRetrying hook code into a helper method** (`engine.rs`): The two identical 14-line blocks that built a `HookContext` for `StageRetrying` and called `run_hooks()` were extracted into a new `stage_retrying_hook()` method. This follows the existing pattern established by `run_failed_hook()` (line 963). Each call site is now a single 2-line method call instead of a 14-line block.\n\n2. **Restored trailing newline in `hooks.mdx`**: The previous commit accidentally stripped the trailing newline from the docs file.\n\n### Issues Reviewed and Deemed Clean\n\n- **parallel.rs hook pattern**: The `if let Some(ref runner) = services.hook_runner` pattern is correct — handlers don't have access to the engine's `run_hooks()` wrapper, so directly calling `runner.run()` is the appropriate approach.\n- **Type conversions**: `usize::try_from(u32)` matches the existing convention throughout the file. Not worth deviating.\n- **Cloning**: `graph.name.clone()`, `node.id.clone()`, `services.sandbox.clone()` — all are necessary since `HookContext` owns its strings, and sandbox is `Arc`-wrapped (cheap clone).", + "failure_class": "", + "thread.toolchain.current_node": "preflight_compile", + "failure_signature": "", + "response.implement": "All changes are complete and verified. Here's a summary of what was done:\n\n### Changes Made\n\n1. **`lib/crates/fabro-workflows/src/engine.rs`** — Added `StageRetrying` hook calls at both retry sites in `execute_with_retry`:\n - **Site A (error-retry path, ~line 1128):** After `WorkflowRunEvent::StageRetrying` emission, before `tokio::time::sleep(delay).await`\n - **Site B (explicit Retry status path, ~line 1165):** Same pattern, after the event emission and before the sleep\n\n2. **`lib/crates/fabro-workflows/src/handler/parallel.rs`** — Added `ParallelStart` and `ParallelComplete` hook calls:\n - Added `use crate::hook::{HookContext, HookEvent};` import\n - After `ParallelStarted` event emission: calls `runner.run()` with `HookEvent::ParallelStart`\n - After `ParallelCompleted` event emission: calls `runner.run()` with `HookEvent::ParallelComplete`\n\n3. **`lib/crates/fabro-workflows/src/hook/types.rs`** — Added `/// Reserved: hooks for this event are not yet invoked by the engine.` doc comments to `SandboxReady` and `SandboxCleanup` variants\n\n4. **`docs/agents/hooks.mdx`** — Annotated `sandbox_ready` and `sandbox_cleanup` rows with \"(reserved — not yet wired)\"\n\n### Verification\n- `cargo fmt --check --all` ✅\n- `cargo clippy --workspace -- -D warnings` ✅ \n- `cargo test --workspace` ✅ (179 passed, 0 failed, 13 ignored)", + "graph.model_stylesheet": "\n * { backend: api; model: claude-opus-4-6;}\n ", + "internal.retry_count.start": 1, + "last_response": "All clean. Here's a summary of what was fixed:\n\n### Changes Made\n\n1. **Extracted duplicated StageRetrying hook code into a helper method** (`engine.rs`): The two identical 14-line blocks that built a ", + "current_node": "simplify_opus", "command.stderr": "", "internal.node_visit_count": 1, - "internal.thread_id": "preflight_lint", - "graph.rankdir": "LR", + "internal.thread_id": "implement", "outcome": "success", + "thread.preflight_lint.current_node": "implement", "internal.retry_count.toolchain": 1, - "thread.start.current_node": "toolchain", - "internal.retry_count.preflight_compile": 1 + "thread.start.current_node": "toolchain" }, "logs": [], "node_outcomes": { @@ -98,13 +103,36 @@ "/home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs" ], "duration_ms": 280813 + }, + "simplify_opus": { + "status": "success", + "context_updates": { + "last_response": "All clean. Here's a summary of what was fixed:\n\n### Changes Made\n\n1. **Extracted duplicated StageRetrying hook code into a helper method** (`engine.rs`): The two identical 14-line blocks that built a ", + "response.simplify_opus": "All clean. Here's a summary of what was fixed:\n\n### Changes Made\n\n1. **Extracted duplicated StageRetrying hook code into a helper method** (`engine.rs`): The two identical 14-line blocks that built a `HookContext` for `StageRetrying` and called `run_hooks()` were extracted into a new `stage_retrying_hook()` method. This follows the existing pattern established by `run_failed_hook()` (line 963). Each call site is now a single 2-line method call instead of a 14-line block.\n\n2. **Restored trailing newline in `hooks.mdx`**: The previous commit accidentally stripped the trailing newline from the docs file.\n\n### Issues Reviewed and Deemed Clean\n\n- **parallel.rs hook pattern**: The `if let Some(ref runner) = services.hook_runner` pattern is correct — handlers don't have access to the engine's `run_hooks()` wrapper, so directly calling `runner.run()` is the appropriate approach.\n- **Type conversions**: `usize::try_from(u32)` matches the existing convention throughout the file. Not worth deviating.\n- **Cloning**: `graph.name.clone()`, `node.id.clone()`, `services.sandbox.clone()` — all are necessary since `HookContext` owns its strings, and sandbox is `Arc`-wrapped (cheap clone).", + "last_stage": "simplify_opus" + }, + "notes": "Stage completed: simplify_opus", + "usage": { + "model": "claude-opus-4-6", + "input_tokens": 36928, + "output_tokens": 12773, + "cache_read_tokens": 727540, + "cache_write_tokens": 43418, + "reasoning_tokens": 1413, + "cost": 1.511895 + }, + "files_touched": [ + "/home/daytona/workspace/lib/crates/fabro-workflows/src/engine.rs" + ], + "duration_ms": 322756 } }, - "next_node_id": "simplify_opus", + "next_node_id": "simplify_gemini", "node_visits": { "toolchain": 1, "preflight_lint": 1, "implement": 1, + "simplify_opus": 1, "preflight_compile": 1, "start": 1 } diff --git a/nodes/implement/diff.patch b/nodes/implement/diff.patch new file mode 100644 index 000000000..d96e20b7f --- /dev/null +++ b/nodes/implement/diff.patch @@ -0,0 +1,124 @@ +diff --git a/docs/agents/hooks.mdx b/docs/agents/hooks.mdx +index 25cf860..f5104c4 100644 +--- a/docs/agents/hooks.mdx ++++ b/docs/agents/hooks.mdx +@@ -94,8 +94,8 @@ Each hook fires on a specific lifecycle event: + | `edge_selected` | After an edge is chosen for traversal | Yes | + | `parallel_start` | Before parallel branches fan out | No | + | `parallel_complete` | After parallel branches merge | No | +-| `sandbox_ready` | After the sandbox environment is created | No | +-| `sandbox_cleanup` | Before the sandbox is torn down | No | ++| `sandbox_ready` | After the sandbox environment is created (reserved — not yet wired) | No | ++| `sandbox_cleanup` | Before the sandbox is torn down (reserved — not yet wired) | No | + | `checkpoint_saved` | After a checkpoint is written to disk | No | + | `pre_tool_use` | Before an agent tool call executes | Yes | + | `post_tool_use` | After an agent tool call succeeds | No | +@@ -399,4 +399,4 @@ event = "post_tool_use" + command = "cargo fmt" + matcher = "write_file|edit_file|apply_patch" + blocking = true +-``` ++``` +\ No newline at end of file +diff --git a/lib/crates/fabro-workflows/src/engine.rs b/lib/crates/fabro-workflows/src/engine.rs +index ca68942..cd152c0 100644 +--- a/lib/crates/fabro-workflows/src/engine.rs ++++ b/lib/crates/fabro-workflows/src/engine.rs +@@ -1125,6 +1125,20 @@ impl WorkflowRunEngine { + .unwrap_or(usize::MAX), + delay_ms: millis_u64(delay), + }); ++ { ++ let mut hook_ctx = HookContext::new( ++ HookEvent::StageRetrying, ++ context.run_id(), ++ graph.name.clone(), ++ ); ++ hook_ctx.node_id = Some(node.id.clone()); ++ hook_ctx.node_label = Some(node.label().to_string()); ++ hook_ctx.handler_type = node.handler_type().map(String::from); ++ hook_ctx.attempt = Some(usize::try_from(attempt).unwrap_or(usize::MAX)); ++ hook_ctx.max_attempts = ++ Some(usize::try_from(policy.max_attempts).unwrap_or(usize::MAX)); ++ let _ = self.run_hooks(&hook_ctx, None).await; ++ } + tokio::time::sleep(delay).await; + continue; + } +@@ -1153,6 +1167,20 @@ impl WorkflowRunEngine { + .unwrap_or(usize::MAX), + delay_ms: millis_u64(delay), + }); ++ { ++ let mut hook_ctx = HookContext::new( ++ HookEvent::StageRetrying, ++ context.run_id(), ++ graph.name.clone(), ++ ); ++ hook_ctx.node_id = Some(node.id.clone()); ++ hook_ctx.node_label = Some(node.label().to_string()); ++ hook_ctx.handler_type = node.handler_type().map(String::from); ++ hook_ctx.attempt = Some(usize::try_from(attempt).unwrap_or(usize::MAX)); ++ hook_ctx.max_attempts = ++ Some(usize::try_from(policy.max_attempts).unwrap_or(usize::MAX)); ++ let _ = self.run_hooks(&hook_ctx, None).await; ++ } + tokio::time::sleep(delay).await; + continue; + } +diff --git a/lib/crates/fabro-workflows/src/handler/parallel.rs b/lib/crates/fabro-workflows/src/handler/parallel.rs +index 41b83f9..ab2a9ee 100644 +--- a/lib/crates/fabro-workflows/src/handler/parallel.rs ++++ b/lib/crates/fabro-workflows/src/handler/parallel.rs +@@ -11,6 +11,7 @@ use crate::context::Context; + use crate::error::FabroError; + use crate::event::WorkflowRunEvent; + use crate::graph::{Graph, Node}; ++use crate::hook::{HookContext, HookEvent}; + use crate::millis_u64; + use crate::outcome::{Outcome, StageStatus}; + use fabro_agent::LocalSandbox; +@@ -299,6 +300,14 @@ impl Handler for ParallelHandler { + join_policy: join_policy.to_string(), + error_policy: error_policy.to_string(), + }); ++ if let Some(ref runner) = services.hook_runner { ++ let hook_ctx = HookContext::new( ++ HookEvent::ParallelStart, ++ context.run_id(), ++ graph.name.clone(), ++ ); ++ let _ = runner.run(&hook_ctx, services.sandbox.clone(), None).await; ++ } + let max_parallel = node + .attrs + .get("max_parallel") +@@ -711,6 +720,14 @@ impl Handler for ParallelHandler { + success_count, + failure_count: fail_count, + }); ++ if let Some(ref runner) = services.hook_runner { ++ let hook_ctx = HookContext::new( ++ HookEvent::ParallelComplete, ++ context.run_id(), ++ graph.name.clone(), ++ ); ++ let _ = runner.run(&hook_ctx, services.sandbox.clone(), None).await; ++ } + + // Evaluate join policy + let status = match join_policy { +diff --git a/lib/crates/fabro-workflows/src/hook/types.rs b/lib/crates/fabro-workflows/src/hook/types.rs +index 2a299b8..bc14215 100644 +--- a/lib/crates/fabro-workflows/src/hook/types.rs ++++ b/lib/crates/fabro-workflows/src/hook/types.rs +@@ -14,7 +14,9 @@ pub enum HookEvent { + EdgeSelected, + ParallelStart, + ParallelComplete, ++ /// Reserved: hooks for this event are not yet invoked by the engine. + SandboxReady, ++ /// Reserved: hooks for this event are not yet invoked by the engine. + SandboxCleanup, + CheckpointSaved, + PreToolUse, diff --git a/nodes/simplify_opus/prompt.md b/nodes/simplify_opus/prompt.md new file mode 100644 index 000000000..1072286a3 --- /dev/null +++ b/nodes/simplify_opus/prompt.md @@ -0,0 +1,161 @@ +Goal: # Wire up missing hook invocations + +## Context + +Five `HookEvent` variants exist in the enum and are documented in `docs/agents/hooks.mdx`, but `run_hooks()` is never called for them in the engine. Users can configure hooks for these events, but they silently never fire. + +**Events to wire up:** `StageRetrying`, `ParallelStart`, `ParallelComplete` +**Events to mark as reserved:** `SandboxReady`, `SandboxCleanup` (sandbox lifecycle is managed outside the engine; wiring these requires significant architecture changes) + +## Changes + +### 1. Add StageRetrying hook calls in `engine.rs` + +File: `lib/crates/fabro-workflows/src/engine.rs` + +Two sites in `execute_with_retry`, both immediately after `WorkflowRunEvent::StageRetrying` emission and before `tokio::time::sleep(delay).await`: + +- **Site A (~line 1127):** error-retry path +- **Site B (~line 1155):** explicit Retry status path + +Pattern (same for both sites): +```rust +{ + let mut hook_ctx = HookContext::new( + HookEvent::StageRetrying, + context.run_id(), + graph.name.clone(), + ); + hook_ctx.node_id = Some(node.id.clone()); + hook_ctx.node_label = Some(node.label().to_string()); + hook_ctx.handler_type = node.handler_type().map(String::from); + hook_ctx.attempt = Some(usize::try_from(attempt).unwrap_or(usize::MAX)); + hook_ctx.max_attempts = Some( + usize::try_from(policy.max_attempts).unwrap_or(usize::MAX), + ); + let _ = self.run_hooks(&hook_ctx, None).await; +} +``` + +Available via: `self.run_hooks()` (engine method), `context.run_id()`, `graph.name`, `node`, `attempt`, `policy`. + +### 2. Add ParallelStart hook call in `parallel.rs` + +File: `lib/crates/fabro-workflows/src/handler/parallel.rs` + +After `ParallelStarted` event emission (~line 301). Call `hook_runner.run()` directly since the handler has `services: &EngineServices` (which has `hook_runner` and `sandbox`): + +```rust +if let Some(ref runner) = services.hook_runner { + let hook_ctx = HookContext::new( + HookEvent::ParallelStart, + context.run_id(), + graph.name.clone(), + ); + let _ = runner + .run(&hook_ctx, services.sandbox.clone(), None) + .await; +} +``` + +### 3. Add ParallelComplete hook call in `parallel.rs` + +Same file, after `ParallelCompleted` event emission (~line 713). Same pattern as ParallelStart but with `HookEvent::ParallelComplete`. + +### 4. Mark SandboxReady/SandboxCleanup as reserved + +File: `lib/crates/fabro-workflows/src/hook/types.rs` + +Add doc comments: +```rust +/// Reserved: hooks for this event are not yet invoked by the engine. +SandboxReady, +/// Reserved: hooks for this event are not yet invoked by the engine. +SandboxCleanup, +``` + +### 5. Update docs + +File: `docs/agents/hooks.mdx` + +In the lifecycle events table, annotate `sandbox_ready` and `sandbox_cleanup` rows — e.g., append "(not yet wired)" to the description or add a note. + +## Verification + +1. `cargo fmt --check --all` +2. `cargo clippy --workspace -- -D warnings` +3. `cargo test --workspace` — existing tests pass, no regressions +4. Manual test: create a workflow with a retrying node and a `post_tool_use`-style hook for `stage_retrying`, verify it fires in the CLI log + + +## Completed stages +- **toolchain**: success + - 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` + - Stdout: + ``` + cargo 1.94.0 (85eff7c80 2026-01-15) + ``` + - Stderr: (empty) +- **preflight_compile**: success + - Script: `cargo check -q --workspace 2>&1` + - Stdout: (empty) + - Stderr: (empty) +- **preflight_lint**: success + - Script: `cargo clippy -q --workspace -- -D warnings 2>&1` + - Stdout: (empty) + - Stderr: (empty) +- **implement**: success + - Model: claude-opus-4-6, 33.1k tokens in / 7.2k out + - Files: /home/daytona/workspace/lib/crates/fabro-workflows/src/engine.rs, /home/daytona/workspace/lib/crates/fabro-workflows/src/handler/parallel.rs + + +# Simplify: Code Review and Cleanup + +Review all changed files for reuse, quality, and efficiency. Fix any issues found. + +## Phase 1: Identify Changes + +Run git diff (or git diff HEAD if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation. + +## Phase 2: Launch Three Review Agents in Parallel + +Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context. + +### Agent 1: Code Reuse Review + +For each change: + +1. Search for existing utilities and helpers that could replace newly written code. Use Grep to find similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones. +2. Flag any new function that duplicates existing functionality. Suggest the existing function to use instead. +3. Flag any inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates. + +Note: This is a greenfield app, so focus on maximizing simplicity and don't worry about changing things to achieve it. + +### Agent 2: Code Quality Review + +Review the same changes for hacky patterns: + +1. Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls +2. Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones +3. Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction +4. Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries +5. Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase + +Note: This is a greenfield app, so be aggressive in optimizing quality. + +### Agent 3: Efficiency Review + +Review the same changes for efficiency: + +1. Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns +2. Missed concurrency: independent operations run sequentially when they could run in parallel +3. Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths +4. Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error +5. Memory: unbounded data structures, missing cleanup, event listener leaks +6. Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one + +## Phase 3: Fix Issues + +Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it. + +When done, briefly summarize what was fixed (or confirm the code was already clean). \ No newline at end of file diff --git a/nodes/simplify_opus/provider_used.json b/nodes/simplify_opus/provider_used.json new file mode 100644 index 000000000..c1905ff10 --- /dev/null +++ b/nodes/simplify_opus/provider_used.json @@ -0,0 +1,5 @@ +{ + "mode": "agent", + "provider": "anthropic", + "model": "claude-opus-4-6" +} \ No newline at end of file diff --git a/nodes/simplify_opus/response.md b/nodes/simplify_opus/response.md new file mode 100644 index 000000000..66f93c079 --- /dev/null +++ b/nodes/simplify_opus/response.md @@ -0,0 +1,13 @@ +All clean. Here's a summary of what was fixed: + +### Changes Made + +1. **Extracted duplicated StageRetrying hook code into a helper method** (`engine.rs`): The two identical 14-line blocks that built a `HookContext` for `StageRetrying` and called `run_hooks()` were extracted into a new `stage_retrying_hook()` method. This follows the existing pattern established by `run_failed_hook()` (line 963). Each call site is now a single 2-line method call instead of a 14-line block. + +2. **Restored trailing newline in `hooks.mdx`**: The previous commit accidentally stripped the trailing newline from the docs file. + +### Issues Reviewed and Deemed Clean + +- **parallel.rs hook pattern**: The `if let Some(ref runner) = services.hook_runner` pattern is correct — handlers don't have access to the engine's `run_hooks()` wrapper, so directly calling `runner.run()` is the appropriate approach. +- **Type conversions**: `usize::try_from(u32)` matches the existing convention throughout the file. Not worth deviating. +- **Cloning**: `graph.name.clone()`, `node.id.clone()`, `services.sandbox.clone()` — all are necessary since `HookContext` owns its strings, and sandbox is `Arc`-wrapped (cheap clone). \ No newline at end of file diff --git a/nodes/simplify_opus/status.json b/nodes/simplify_opus/status.json new file mode 100644 index 000000000..ecc5c571a --- /dev/null +++ b/nodes/simplify_opus/status.json @@ -0,0 +1,6 @@ +{ + "status": "success", + "notes": "Stage completed: simplify_opus", + "failure_reason": null, + "timestamp": "2026-03-16T02:10:22.216608+00:00" +} \ No newline at end of file