mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-08 22:21:45 +00:00
parent
c8af9ff4b1
commit
6a4176b623
6 changed files with 526 additions and 18 deletions
|
|
@ -1,47 +1,52 @@
|
|||
{
|
||||
"timestamp": "2026-03-20T01:09:06.457574Z",
|
||||
"current_node": "implement",
|
||||
"timestamp": "2026-03-20T01:13:32.956365Z",
|
||||
"current_node": "simplify_opus",
|
||||
"completed_nodes": [
|
||||
"start",
|
||||
"toolchain",
|
||||
"preflight_compile",
|
||||
"preflight_lint",
|
||||
"implement"
|
||||
"implement",
|
||||
"simplify_opus"
|
||||
],
|
||||
"node_retries": {
|
||||
"implement": 1,
|
||||
"simplify_opus": 1,
|
||||
"preflight_compile": 1,
|
||||
"start": 1,
|
||||
"toolchain": 1,
|
||||
"preflight_lint": 1
|
||||
},
|
||||
"context_values": {
|
||||
"internal.retry_count.implement": 1,
|
||||
"failure_class": "",
|
||||
"internal.node_visit_count": 1,
|
||||
"failure_signature": "",
|
||||
"thread.start.current_node": "toolchain",
|
||||
"command.output": "",
|
||||
"thread.preflight_lint.current_node": "implement",
|
||||
"internal.retry_count.toolchain": 1,
|
||||
"last_response": "Here's a summary of all changes made:\n\n### Files changed\n\n1. **`lib/crates/fabro-cli/src/commands/wait.rs`** (new file) — The `fabro wait` command implementation:\n - `WaitArgs` struct with `run`, ",
|
||||
"outcome": "success",
|
||||
"command.stderr": "",
|
||||
"internal.thread_id": "preflight_lint",
|
||||
"response.simplify_opus": "All clean. Here's a summary of what was fixed:\n\n### Fixes applied\n\n1. **Simplified `build_json_output`** (Code Reuse): Replaced verbose hand-rolled `serde_json::Map::new()` with `serde_json::json!{}` macro, which is already used elsewhere in the codebase for known shapes. Reduces the function from 20 lines to 11.\n\n2. **Replaced dead `_ => \"Unknown\"` branch with `unreachable!()`** (Code Quality): The poll loop only breaks when `is_terminal()` returns true, which is exactly `Succeeded | Failed | Dead`. The wildcard arm was dead code masquerading as a fallback. `unreachable!()` makes the invariant explicit.\n\n3. **Capped sleep duration at remaining deadline** (Efficiency): Previously, `thread::sleep(interval)` could sleep well past the deadline (e.g., `--timeout 5 --interval 10000` would sleep 10s). Now the sleep is `interval.min(dl - now)`, so it wakes up promptly when the deadline arrives.\n\n4. **Used `to_writer_pretty` instead of `to_string_pretty`** (Efficiency): Avoids allocating an intermediate `String` by writing JSON directly to the locked stdout handle.",
|
||||
"internal.thread_id": "implement",
|
||||
"internal.fidelity": "compact",
|
||||
"current.preamble": "Goal: # Plan: `fabro wait` subcommand\n\n## Context\n\n`fabro run` launches workflows but there's no way to block until a run completes and get its exit code — analogous to `docker wait`. This is useful for scripting (e.g., `fabro run smoke && echo \"passed\"`). The closest existing command is `fabro logs --follow`, which streams events and exits when `conclusion.json` appears.\n\n## Implementation\n\n### 1. Create `lib/crates/fabro-cli/src/commands/wait.rs`\n\n**Args struct:**\n```rust\n#[derive(Args)]\npub struct WaitArgs {\n /// Run ID prefix or workflow name (most recent run)\n pub run: String,\n\n /// Maximum time to wait in seconds\n #[arg(long, value_name = \"SECONDS\")]\n pub timeout: Option<u64>,\n\n /// Poll interval in milliseconds\n #[arg(long, value_name = \"MS\", default_value = \"1000\")]\n pub interval: u64,\n\n /// Output conclusion as JSON\n #[arg(long)]\n pub json: bool,\n}\n```\n\n**`run()` function logic:**\n1. Resolve run via `fabro_workflows::run_lookup::resolve_run()` (same as `logs.rs:30`)\n2. Poll `status.json` via `RunStatusRecord::load()` every `--interval` ms\n3. When `status.is_terminal()`, read `conclusion.json` for summary data\n4. Print human-readable status line to stderr (or `--json` to stdout)\n5. Exit 0 for `Succeeded`, exit 1 for `Failed`/`Dead` (use `std::process::exit(1)` to avoid printing an error prefix, matching the pattern in `run.rs`)\n\n**Completion detection:** Poll `status.json` (not `conclusion.json` existence) since `RunStatusRecord::load()` gives the exact status. Fall back to `Dead` if the file is missing (orphaned run).\n\n**Timeout:** Check deadline after each sleep iteration; `bail!()` with a message if exceeded.\n\n### 2. Register in `lib/crates/fabro-cli/src/commands/mod.rs`\n\nAdd `pub mod wait;` between `validate` and `workflow` (line 19).\n\n### 3. Register in `lib/crates/fabro-cli/src/main.rs`\n\nThree insertions:\n\n**(a)** Command enum variant (after `Rewind` at ~line 149):\n```rust\n/// Block until a workflow run completes\nWait(commands::wait::WaitArgs),\n```\n\n**(b)** Command name mapping (~line 497):\n```rust\nCommand::Wait(_) => \"wait\",\n```\n\n**(c)** Execution dispatch (~line 884, after `Rewind`):\n```rust\nCommand::Wait(args) => {\n let styles = fabro_util::terminal::Styles::detect_stderr();\n commands::wait::run(args, &styles)?;\n}\n```\n\n### Reused utilities\n\n| Utility | Location |\n|---|---|\n| `resolve_run()` | `fabro_workflows::run_lookup` (run ID/name resolution) |\n| `RunStatusRecord::load()` | `fabro_workflows::run_status` (poll status.json) |\n| `RunStatus::is_terminal()` | `fabro_workflows::run_status` (check completion) |\n| `Conclusion::load()` | `fabro_workflows::conclusion` (read duration/cost) |\n| `format_duration_ms()` | `commands::shared` (human-readable duration) |\n| `Styles` | `fabro_util::terminal` (colored output) |\n\nNo new dependencies needed — all are already in `fabro-cli/Cargo.toml`.\n\n## Verification\n\n1. `cargo build -p fabro-cli` — compiles\n2. `cargo test -p fabro-cli` — existing tests pass\n3. `fabro wait --help` — shows usage\n4. `fabro wait <completed-run-id>` — prints status immediately, exits 0 or 1\n5. Launch a run, then `fabro wait <run-id>` — blocks until completion\n6. `fabro wait --timeout 1 <active-run>` — times out with error\n7. `fabro wait --json <run-id>` — prints JSON to stdout\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",
|
||||
"last_stage": "implement",
|
||||
"thread.preflight_compile.current_node": "preflight_lint",
|
||||
"graph.rankdir": "LR",
|
||||
"thread.toolchain.current_node": "preflight_compile",
|
||||
"graph.goal": "# Plan: `fabro wait` subcommand\n\n## Context\n\n`fabro run` launches workflows but there's no way to block until a run completes and get its exit code — analogous to `docker wait`. This is useful for scripting (e.g., `fabro run smoke && echo \"passed\"`). The closest existing command is `fabro logs --follow`, which streams events and exits when `conclusion.json` appears.\n\n## Implementation\n\n### 1. Create `lib/crates/fabro-cli/src/commands/wait.rs`\n\n**Args struct:**\n```rust\n#[derive(Args)]\npub struct WaitArgs {\n /// Run ID prefix or workflow name (most recent run)\n pub run: String,\n\n /// Maximum time to wait in seconds\n #[arg(long, value_name = \"SECONDS\")]\n pub timeout: Option<u64>,\n\n /// Poll interval in milliseconds\n #[arg(long, value_name = \"MS\", default_value = \"1000\")]\n pub interval: u64,\n\n /// Output conclusion as JSON\n #[arg(long)]\n pub json: bool,\n}\n```\n\n**`run()` function logic:**\n1. Resolve run via `fabro_workflows::run_lookup::resolve_run()` (same as `logs.rs:30`)\n2. Poll `status.json` via `RunStatusRecord::load()` every `--interval` ms\n3. When `status.is_terminal()`, read `conclusion.json` for summary data\n4. Print human-readable status line to stderr (or `--json` to stdout)\n5. Exit 0 for `Succeeded`, exit 1 for `Failed`/`Dead` (use `std::process::exit(1)` to avoid printing an error prefix, matching the pattern in `run.rs`)\n\n**Completion detection:** Poll `status.json` (not `conclusion.json` existence) since `RunStatusRecord::load()` gives the exact status. Fall back to `Dead` if the file is missing (orphaned run).\n\n**Timeout:** Check deadline after each sleep iteration; `bail!()` with a message if exceeded.\n\n### 2. Register in `lib/crates/fabro-cli/src/commands/mod.rs`\n\nAdd `pub mod wait;` between `validate` and `workflow` (line 19).\n\n### 3. Register in `lib/crates/fabro-cli/src/main.rs`\n\nThree insertions:\n\n**(a)** Command enum variant (after `Rewind` at ~line 149):\n```rust\n/// Block until a workflow run completes\nWait(commands::wait::WaitArgs),\n```\n\n**(b)** Command name mapping (~line 497):\n```rust\nCommand::Wait(_) => \"wait\",\n```\n\n**(c)** Execution dispatch (~line 884, after `Rewind`):\n```rust\nCommand::Wait(args) => {\n let styles = fabro_util::terminal::Styles::detect_stderr();\n commands::wait::run(args, &styles)?;\n}\n```\n\n### Reused utilities\n\n| Utility | Location |\n|---|---|\n| `resolve_run()` | `fabro_workflows::run_lookup` (run ID/name resolution) |\n| `RunStatusRecord::load()` | `fabro_workflows::run_status` (poll status.json) |\n| `RunStatus::is_terminal()` | `fabro_workflows::run_status` (check completion) |\n| `Conclusion::load()` | `fabro_workflows::conclusion` (read duration/cost) |\n| `format_duration_ms()` | `commands::shared` (human-readable duration) |\n| `Styles` | `fabro_util::terminal` (colored output) |\n\nNo new dependencies needed — all are already in `fabro-cli/Cargo.toml`.\n\n## Verification\n\n1. `cargo build -p fabro-cli` — compiles\n2. `cargo test -p fabro-cli` — existing tests pass\n3. `fabro wait --help` — shows usage\n4. `fabro wait <completed-run-id>` — prints status immediately, exits 0 or 1\n5. Launch a run, then `fabro wait <run-id>` — blocks until completion\n6. `fabro wait --timeout 1 <active-run>` — times out with error\n7. `fabro wait --json <run-id>` — prints JSON to stdout\n",
|
||||
"current_node": "simplify_opus",
|
||||
"internal.retry_count.simplify_opus": 1,
|
||||
"thread.implement.current_node": "simplify_opus",
|
||||
"graph.model_stylesheet": "\n * { backend: api; model: claude-opus-4-6;}\n ",
|
||||
"response.implement": "Here's a summary of all changes made:\n\n### Files changed\n\n1. **`lib/crates/fabro-cli/src/commands/wait.rs`** (new file) — The `fabro wait` command implementation:\n - `WaitArgs` struct with `run`, `--timeout`, `--interval` (default 1000ms), and `--json` flags\n - `run()` function that resolves the run via `resolve_run()`, polls `status.json` via `RunStatusRecord::load()` every `--interval` ms, detects terminal status, reads `conclusion.json` for summary data, prints human-readable output to stderr (or JSON to stdout with `--json`), exits 0 for `Succeeded` and exits 1 for `Failed`/`Dead`\n - `build_json_output()` — builds JSON with run_id, status, duration_ms, and total_cost\n - `print_human_output()` — colored status line with duration and cost\n - 7 unit tests covering JSON output (with/without conclusion, various statuses), human output, poll behavior, and missing status fallback to Dead\n\n2. **`lib/crates/fabro-cli/src/commands/mod.rs`** — Added `pub mod wait;`\n\n3. **`lib/crates/fabro-cli/src/main.rs`** — Three insertions:\n - `Wait(commands::wait::WaitArgs)` variant in the `Command` enum\n - `Command::Wait(_) => \"wait\"` in the command name mapping\n - `Command::Wait(args) => { ... }` dispatch in the execution block",
|
||||
"internal.retry_count.implement": 1,
|
||||
"internal.node_visit_count": 1,
|
||||
"command.output": "",
|
||||
"last_response": "All clean. Here's a summary of what was fixed:\n\n### Fixes applied\n\n1. **Simplified `build_json_output`** (Code Reuse): Replaced verbose hand-rolled `serde_json::Map::new()` with `serde_json::json!{}` ",
|
||||
"last_stage": "simplify_opus",
|
||||
"command.stderr": "",
|
||||
"current.preamble": "Goal: # Plan: `fabro wait` subcommand\n\n## Context\n\n`fabro run` launches workflows but there's no way to block until a run completes and get its exit code — analogous to `docker wait`. This is useful for scripting (e.g., `fabro run smoke && echo \"passed\"`). The closest existing command is `fabro logs --follow`, which streams events and exits when `conclusion.json` appears.\n\n## Implementation\n\n### 1. Create `lib/crates/fabro-cli/src/commands/wait.rs`\n\n**Args struct:**\n```rust\n#[derive(Args)]\npub struct WaitArgs {\n /// Run ID prefix or workflow name (most recent run)\n pub run: String,\n\n /// Maximum time to wait in seconds\n #[arg(long, value_name = \"SECONDS\")]\n pub timeout: Option<u64>,\n\n /// Poll interval in milliseconds\n #[arg(long, value_name = \"MS\", default_value = \"1000\")]\n pub interval: u64,\n\n /// Output conclusion as JSON\n #[arg(long)]\n pub json: bool,\n}\n```\n\n**`run()` function logic:**\n1. Resolve run via `fabro_workflows::run_lookup::resolve_run()` (same as `logs.rs:30`)\n2. Poll `status.json` via `RunStatusRecord::load()` every `--interval` ms\n3. When `status.is_terminal()`, read `conclusion.json` for summary data\n4. Print human-readable status line to stderr (or `--json` to stdout)\n5. Exit 0 for `Succeeded`, exit 1 for `Failed`/`Dead` (use `std::process::exit(1)` to avoid printing an error prefix, matching the pattern in `run.rs`)\n\n**Completion detection:** Poll `status.json` (not `conclusion.json` existence) since `RunStatusRecord::load()` gives the exact status. Fall back to `Dead` if the file is missing (orphaned run).\n\n**Timeout:** Check deadline after each sleep iteration; `bail!()` with a message if exceeded.\n\n### 2. Register in `lib/crates/fabro-cli/src/commands/mod.rs`\n\nAdd `pub mod wait;` between `validate` and `workflow` (line 19).\n\n### 3. Register in `lib/crates/fabro-cli/src/main.rs`\n\nThree insertions:\n\n**(a)** Command enum variant (after `Rewind` at ~line 149):\n```rust\n/// Block until a workflow run completes\nWait(commands::wait::WaitArgs),\n```\n\n**(b)** Command name mapping (~line 497):\n```rust\nCommand::Wait(_) => \"wait\",\n```\n\n**(c)** Execution dispatch (~line 884, after `Rewind`):\n```rust\nCommand::Wait(args) => {\n let styles = fabro_util::terminal::Styles::detect_stderr();\n commands::wait::run(args, &styles)?;\n}\n```\n\n### Reused utilities\n\n| Utility | Location |\n|---|---|\n| `resolve_run()` | `fabro_workflows::run_lookup` (run ID/name resolution) |\n| `RunStatusRecord::load()` | `fabro_workflows::run_status` (poll status.json) |\n| `RunStatus::is_terminal()` | `fabro_workflows::run_status` (check completion) |\n| `Conclusion::load()` | `fabro_workflows::conclusion` (read duration/cost) |\n| `format_duration_ms()` | `commands::shared` (human-readable duration) |\n| `Styles` | `fabro_util::terminal` (colored output) |\n\nNo new dependencies needed — all are already in `fabro-cli/Cargo.toml`.\n\n## Verification\n\n1. `cargo build -p fabro-cli` — compiles\n2. `cargo test -p fabro-cli` — existing tests pass\n3. `fabro wait --help` — shows usage\n4. `fabro wait <completed-run-id>` — prints status immediately, exits 0 or 1\n5. Launch a run, then `fabro wait <run-id>` — blocks until completion\n6. `fabro wait --timeout 1 <active-run>` — times out with error\n7. `fabro wait --json <run-id>` — prints JSON to stdout\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, 64.1k tokens in / 6.7k out\n - Files: /home/daytona/workspace/lib/crates/fabro-cli/src/commands/mod.rs, /home/daytona/workspace/lib/crates/fabro-cli/src/commands/wait.rs, /home/daytona/workspace/lib/crates/fabro-cli/src/main.rs\n",
|
||||
"thread.preflight_compile.current_node": "preflight_lint",
|
||||
"graph.rankdir": "LR",
|
||||
"internal.run_id": "01KM4C8NP9T0GX1XX23NCZ8HVQ",
|
||||
"current_node": "implement",
|
||||
"internal.retry_count.start": 1,
|
||||
"internal.retry_count.preflight_compile": 1,
|
||||
"graph.model_stylesheet": "\n * { backend: api; model: claude-opus-4-6;}\n ",
|
||||
"internal.retry_count.preflight_lint": 1,
|
||||
"response.implement": "Here's a summary of all changes made:\n\n### Files changed\n\n1. **`lib/crates/fabro-cli/src/commands/wait.rs`** (new file) — The `fabro wait` command implementation:\n - `WaitArgs` struct with `run`, `--timeout`, `--interval` (default 1000ms), and `--json` flags\n - `run()` function that resolves the run via `resolve_run()`, polls `status.json` via `RunStatusRecord::load()` every `--interval` ms, detects terminal status, reads `conclusion.json` for summary data, prints human-readable output to stderr (or JSON to stdout with `--json`), exits 0 for `Succeeded` and exits 1 for `Failed`/`Dead`\n - `build_json_output()` — builds JSON with run_id, status, duration_ms, and total_cost\n - `print_human_output()` — colored status line with duration and cost\n - 7 unit tests covering JSON output (with/without conclusion, various statuses), human output, poll behavior, and missing status fallback to Dead\n\n2. **`lib/crates/fabro-cli/src/commands/mod.rs`** — Added `pub mod wait;`\n\n3. **`lib/crates/fabro-cli/src/main.rs`** — Three insertions:\n - `Wait(commands::wait::WaitArgs)` variant in the `Command` enum\n - `Command::Wait(_) => \"wait\"` in the command name mapping\n - `Command::Wait(args) => { ... }` dispatch in the execution block"
|
||||
"internal.retry_count.preflight_lint": 1
|
||||
},
|
||||
"logs": [],
|
||||
"node_outcomes": {
|
||||
|
|
@ -96,13 +101,36 @@
|
|||
"notes": "Script completed: cargo check -q --workspace 2>&1",
|
||||
"duration_ms": 72008
|
||||
},
|
||||
"simplify_opus": {
|
||||
"status": "success",
|
||||
"context_updates": {
|
||||
"last_response": "All clean. Here's a summary of what was fixed:\n\n### Fixes applied\n\n1. **Simplified `build_json_output`** (Code Reuse): Replaced verbose hand-rolled `serde_json::Map::new()` with `serde_json::json!{}` ",
|
||||
"last_stage": "simplify_opus",
|
||||
"response.simplify_opus": "All clean. Here's a summary of what was fixed:\n\n### Fixes applied\n\n1. **Simplified `build_json_output`** (Code Reuse): Replaced verbose hand-rolled `serde_json::Map::new()` with `serde_json::json!{}` macro, which is already used elsewhere in the codebase for known shapes. Reduces the function from 20 lines to 11.\n\n2. **Replaced dead `_ => \"Unknown\"` branch with `unreachable!()`** (Code Quality): The poll loop only breaks when `is_terminal()` returns true, which is exactly `Succeeded | Failed | Dead`. The wildcard arm was dead code masquerading as a fallback. `unreachable!()` makes the invariant explicit.\n\n3. **Capped sleep duration at remaining deadline** (Efficiency): Previously, `thread::sleep(interval)` could sleep well past the deadline (e.g., `--timeout 5 --interval 10000` would sleep 10s). Now the sleep is `interval.min(dl - now)`, so it wakes up promptly when the deadline arrives.\n\n4. **Used `to_writer_pretty` instead of `to_string_pretty`** (Efficiency): Avoids allocating an intermediate `String` by writing JSON directly to the locked stdout handle."
|
||||
},
|
||||
"notes": "Stage completed: simplify_opus",
|
||||
"usage": {
|
||||
"model": "claude-opus-4-6",
|
||||
"input_tokens": 37469,
|
||||
"output_tokens": 10421,
|
||||
"cache_read_tokens": 568244,
|
||||
"cache_write_tokens": 42110,
|
||||
"reasoning_tokens": 449,
|
||||
"cost": 1.34361
|
||||
},
|
||||
"files_touched": [
|
||||
"/home/daytona/workspace/lib/crates/fabro-cli/src/commands/wait.rs"
|
||||
],
|
||||
"duration_ms": 262469
|
||||
},
|
||||
"start": {
|
||||
"status": "success",
|
||||
"duration_ms": 0
|
||||
}
|
||||
},
|
||||
"next_node_id": "simplify_opus",
|
||||
"next_node_id": "simplify_gpt",
|
||||
"node_visits": {
|
||||
"simplify_opus": 1,
|
||||
"implement": 1,
|
||||
"start": 1,
|
||||
"toolchain": 1,
|
||||
|
|
|
|||
294
nodes/implement/diff.patch
Normal file
294
nodes/implement/diff.patch
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
diff --git a/lib/crates/fabro-cli/src/commands/mod.rs b/lib/crates/fabro-cli/src/commands/mod.rs
|
||||
index d7cf9c68..6c4535f5 100644
|
||||
--- a/lib/crates/fabro-cli/src/commands/mod.rs
|
||||
+++ b/lib/crates/fabro-cli/src/commands/mod.rs
|
||||
@@ -17,4 +17,5 @@ pub mod secret;
|
||||
pub(crate) mod shared;
|
||||
pub mod ssh;
|
||||
pub mod validate;
|
||||
+pub mod wait;
|
||||
pub mod workflow;
|
||||
diff --git a/lib/crates/fabro-cli/src/commands/wait.rs b/lib/crates/fabro-cli/src/commands/wait.rs
|
||||
new file mode 100644
|
||||
index 00000000..561fb8c6
|
||||
--- /dev/null
|
||||
+++ b/lib/crates/fabro-cli/src/commands/wait.rs
|
||||
@@ -0,0 +1,246 @@
|
||||
+use std::io::Write;
|
||||
+
|
||||
+use anyhow::{bail, Result};
|
||||
+use clap::Args;
|
||||
+use fabro_util::terminal::Styles;
|
||||
+use fabro_workflows::run_status::{RunStatus, RunStatusRecord};
|
||||
+use tracing::info;
|
||||
+
|
||||
+use super::shared::format_duration_ms;
|
||||
+
|
||||
+#[derive(Args)]
|
||||
+pub struct WaitArgs {
|
||||
+ /// Run ID prefix or workflow name (most recent run)
|
||||
+ pub run: String,
|
||||
+
|
||||
+ /// Maximum time to wait in seconds
|
||||
+ #[arg(long, value_name = "SECONDS")]
|
||||
+ pub timeout: Option<u64>,
|
||||
+
|
||||
+ /// Poll interval in milliseconds
|
||||
+ #[arg(long, value_name = "MS", default_value = "1000")]
|
||||
+ pub interval: u64,
|
||||
+
|
||||
+ /// Output conclusion as JSON
|
||||
+ #[arg(long)]
|
||||
+ pub json: bool,
|
||||
+}
|
||||
+
|
||||
+pub fn run(args: WaitArgs, styles: &Styles) -> Result<()> {
|
||||
+ let base = fabro_workflows::run_lookup::default_runs_base();
|
||||
+ let run_info = fabro_workflows::run_lookup::resolve_run(&base, &args.run)?;
|
||||
+
|
||||
+ info!(run_id = %run_info.run_id, "Waiting for run to complete");
|
||||
+
|
||||
+ let status_path = run_info.path.join("status.json");
|
||||
+ let deadline = args
|
||||
+ .timeout
|
||||
+ .map(|secs| std::time::Instant::now() + std::time::Duration::from_secs(secs));
|
||||
+ let interval = std::time::Duration::from_millis(args.interval);
|
||||
+
|
||||
+ let final_status = loop {
|
||||
+ let status = match RunStatusRecord::load(&status_path) {
|
||||
+ Ok(record) => record.status,
|
||||
+ Err(_) => RunStatus::Dead,
|
||||
+ };
|
||||
+
|
||||
+ if status.is_terminal() {
|
||||
+ break status;
|
||||
+ }
|
||||
+
|
||||
+ if let Some(dl) = deadline {
|
||||
+ if std::time::Instant::now() >= dl {
|
||||
+ bail!(
|
||||
+ "Timed out after {}s waiting for run '{}'",
|
||||
+ args.timeout.unwrap(),
|
||||
+ run_info.run_id
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ std::thread::sleep(interval);
|
||||
+ };
|
||||
+
|
||||
+ let conclusion_path = run_info.path.join("conclusion.json");
|
||||
+ let conclusion = fabro_workflows::conclusion::Conclusion::load(&conclusion_path).ok();
|
||||
+
|
||||
+ if args.json {
|
||||
+ let json_value = build_json_output(final_status, &run_info.run_id, conclusion.as_ref());
|
||||
+ let stdout = std::io::stdout();
|
||||
+ let mut out = stdout.lock();
|
||||
+ writeln!(out, "{}", serde_json::to_string_pretty(&json_value)?)?;
|
||||
+ } else {
|
||||
+ print_human_output(final_status, &run_info.run_id, conclusion.as_ref(), styles);
|
||||
+ }
|
||||
+
|
||||
+ if final_status == RunStatus::Succeeded {
|
||||
+ Ok(())
|
||||
+ } else {
|
||||
+ std::process::exit(1);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+fn build_json_output(
|
||||
+ status: RunStatus,
|
||||
+ run_id: &str,
|
||||
+ conclusion: Option<&fabro_workflows::conclusion::Conclusion>,
|
||||
+) -> serde_json::Value {
|
||||
+ let mut map = serde_json::Map::new();
|
||||
+ map.insert("run_id".into(), serde_json::Value::String(run_id.into()));
|
||||
+ map.insert(
|
||||
+ "status".into(),
|
||||
+ serde_json::Value::String(status.to_string()),
|
||||
+ );
|
||||
+ if let Some(c) = conclusion {
|
||||
+ map.insert(
|
||||
+ "duration_ms".into(),
|
||||
+ serde_json::Value::Number(c.duration_ms.into()),
|
||||
+ );
|
||||
+ if let Some(cost) = c.total_cost {
|
||||
+ if let Some(n) = serde_json::Number::from_f64(cost) {
|
||||
+ map.insert("total_cost".into(), serde_json::Value::Number(n));
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ serde_json::Value::Object(map)
|
||||
+}
|
||||
+
|
||||
+fn print_human_output(
|
||||
+ status: RunStatus,
|
||||
+ run_id: &str,
|
||||
+ conclusion: Option<&fabro_workflows::conclusion::Conclusion>,
|
||||
+ styles: &Styles,
|
||||
+) {
|
||||
+ let (style, label) = match status {
|
||||
+ RunStatus::Succeeded => (&styles.bold_green, "Succeeded"),
|
||||
+ RunStatus::Failed => (&styles.bold_red, "Failed"),
|
||||
+ RunStatus::Dead => (&styles.bold_red, "Dead"),
|
||||
+ _ => (&styles.bold, "Unknown"),
|
||||
+ };
|
||||
+ let status_display = style.apply_to(label);
|
||||
+
|
||||
+ let details = match conclusion {
|
||||
+ Some(c) => {
|
||||
+ let duration = format_duration_ms(c.duration_ms);
|
||||
+ let cost = c
|
||||
+ .total_cost
|
||||
+ .map(|v| format!(" ${v:.2}"))
|
||||
+ .unwrap_or_default();
|
||||
+ format!(" {duration}{cost}")
|
||||
+ }
|
||||
+ None => String::new(),
|
||||
+ };
|
||||
+
|
||||
+ eprintln!(
|
||||
+ "{} {}{details}",
|
||||
+ status_display,
|
||||
+ styles.dim.apply_to(run_id),
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+#[cfg(test)]
|
||||
+mod tests {
|
||||
+ use super::*;
|
||||
+ use fabro_workflows::conclusion::Conclusion;
|
||||
+ use fabro_workflows::outcome::StageStatus;
|
||||
+
|
||||
+ fn no_color_styles() -> Styles {
|
||||
+ Styles::new(false)
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn json_output_succeeded_with_conclusion() {
|
||||
+ let conclusion = Conclusion {
|
||||
+ timestamp: chrono::Utc::now(),
|
||||
+ status: StageStatus::Success,
|
||||
+ duration_ms: 12345,
|
||||
+ failure_reason: None,
|
||||
+ final_git_commit_sha: None,
|
||||
+ stages: vec![],
|
||||
+ total_cost: Some(0.42),
|
||||
+ total_retries: 0,
|
||||
+ };
|
||||
+ let json = build_json_output(RunStatus::Succeeded, "ABC123", Some(&conclusion));
|
||||
+ assert_eq!(json["run_id"], "ABC123");
|
||||
+ assert_eq!(json["status"], "succeeded");
|
||||
+ assert_eq!(json["duration_ms"], 12345);
|
||||
+ assert!((json["total_cost"].as_f64().unwrap() - 0.42).abs() < f64::EPSILON);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn json_output_failed_without_conclusion() {
|
||||
+ let json = build_json_output(RunStatus::Failed, "DEF456", None);
|
||||
+ assert_eq!(json["run_id"], "DEF456");
|
||||
+ assert_eq!(json["status"], "failed");
|
||||
+ assert!(json.get("duration_ms").is_none());
|
||||
+ assert!(json.get("total_cost").is_none());
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn json_output_dead_status() {
|
||||
+ let json = build_json_output(RunStatus::Dead, "GHI789", None);
|
||||
+ assert_eq!(json["status"], "dead");
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn json_output_no_cost_when_none() {
|
||||
+ let conclusion = Conclusion {
|
||||
+ timestamp: chrono::Utc::now(),
|
||||
+ status: StageStatus::Fail,
|
||||
+ duration_ms: 500,
|
||||
+ failure_reason: Some("error".into()),
|
||||
+ final_git_commit_sha: None,
|
||||
+ stages: vec![],
|
||||
+ total_cost: None,
|
||||
+ total_retries: 0,
|
||||
+ };
|
||||
+ let json = build_json_output(RunStatus::Failed, "JKL012", Some(&conclusion));
|
||||
+ assert!(json.get("total_cost").is_none());
|
||||
+ assert_eq!(json["duration_ms"], 500);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn human_output_succeeded() {
|
||||
+ let styles = no_color_styles();
|
||||
+ let conclusion = Conclusion {
|
||||
+ timestamp: chrono::Utc::now(),
|
||||
+ status: StageStatus::Success,
|
||||
+ duration_ms: 8000,
|
||||
+ failure_reason: None,
|
||||
+ final_git_commit_sha: None,
|
||||
+ stages: vec![],
|
||||
+ total_cost: Some(0.15),
|
||||
+ total_retries: 0,
|
||||
+ };
|
||||
+ // Just verify no panic; actual stderr output is hard to capture
|
||||
+ print_human_output(RunStatus::Succeeded, "ABC123", Some(&conclusion), &styles);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn human_output_failed_no_conclusion() {
|
||||
+ let styles = no_color_styles();
|
||||
+ print_human_output(RunStatus::Failed, "DEF456", None, &styles);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn poll_terminal_immediately() {
|
||||
+ let dir = tempfile::tempdir().unwrap();
|
||||
+ let status_path = dir.path().join("status.json");
|
||||
+ let record = RunStatusRecord::new(RunStatus::Succeeded, None);
|
||||
+ record.save(&status_path).unwrap();
|
||||
+
|
||||
+ // Simulate what the poll loop does
|
||||
+ let status = RunStatusRecord::load(&status_path).unwrap().status;
|
||||
+ assert!(status.is_terminal());
|
||||
+ assert_eq!(status, RunStatus::Succeeded);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn missing_status_treated_as_dead() {
|
||||
+ let status = match RunStatusRecord::load(std::path::Path::new("/nonexistent/status.json")) {
|
||||
+ Ok(record) => record.status,
|
||||
+ Err(_) => RunStatus::Dead,
|
||||
+ };
|
||||
+ assert_eq!(status, RunStatus::Dead);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/lib/crates/fabro-cli/src/main.rs b/lib/crates/fabro-cli/src/main.rs
|
||||
index 6a4a9ea5..72742920 100644
|
||||
--- a/lib/crates/fabro-cli/src/main.rs
|
||||
+++ b/lib/crates/fabro-cli/src/main.rs
|
||||
@@ -149,6 +149,8 @@ enum Command {
|
||||
Rewind(commands::rewind::RewindArgs),
|
||||
/// Fork a workflow run from an earlier checkpoint into a new run
|
||||
Fork(commands::fork::ForkArgs),
|
||||
+ /// Block until a workflow run completes
|
||||
+ Wait(commands::wait::WaitArgs),
|
||||
/// Workflow operations
|
||||
Workflow {
|
||||
#[command(subcommand)]
|
||||
@@ -496,6 +498,7 @@ async fn main_inner() -> (String, Result<()>) {
|
||||
},
|
||||
Command::Rewind(_) => "rewind",
|
||||
Command::Fork(_) => "fork",
|
||||
+ Command::Wait(_) => "wait",
|
||||
Command::Workflow { command } => match command {
|
||||
WorkflowCommand::List(_) => "workflow list",
|
||||
WorkflowCommand::Create(_) => "workflow create",
|
||||
@@ -886,6 +889,10 @@ async fn main_inner() -> (String, Result<()>) {
|
||||
let styles = fabro_util::terminal::Styles::detect_stderr();
|
||||
commands::fork::run(&args, &styles)?;
|
||||
}
|
||||
+ Command::Wait(args) => {
|
||||
+ let styles = fabro_util::terminal::Styles::detect_stderr();
|
||||
+ commands::wait::run(args, &styles)?;
|
||||
+ }
|
||||
Command::Workflow { command } => match command {
|
||||
WorkflowCommand::List(args) => {
|
||||
commands::workflow::list_command(&args)?;
|
||||
164
nodes/simplify_opus/prompt.md
Normal file
164
nodes/simplify_opus/prompt.md
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
Goal: # Plan: `fabro wait` subcommand
|
||||
|
||||
## Context
|
||||
|
||||
`fabro run` launches workflows but there's no way to block until a run completes and get its exit code — analogous to `docker wait`. This is useful for scripting (e.g., `fabro run smoke && echo "passed"`). The closest existing command is `fabro logs --follow`, which streams events and exits when `conclusion.json` appears.
|
||||
|
||||
## Implementation
|
||||
|
||||
### 1. Create `lib/crates/fabro-cli/src/commands/wait.rs`
|
||||
|
||||
**Args struct:**
|
||||
```rust
|
||||
#[derive(Args)]
|
||||
pub struct WaitArgs {
|
||||
/// Run ID prefix or workflow name (most recent run)
|
||||
pub run: String,
|
||||
|
||||
/// Maximum time to wait in seconds
|
||||
#[arg(long, value_name = "SECONDS")]
|
||||
pub timeout: Option<u64>,
|
||||
|
||||
/// Poll interval in milliseconds
|
||||
#[arg(long, value_name = "MS", default_value = "1000")]
|
||||
pub interval: u64,
|
||||
|
||||
/// Output conclusion as JSON
|
||||
#[arg(long)]
|
||||
pub json: bool,
|
||||
}
|
||||
```
|
||||
|
||||
**`run()` function logic:**
|
||||
1. Resolve run via `fabro_workflows::run_lookup::resolve_run()` (same as `logs.rs:30`)
|
||||
2. Poll `status.json` via `RunStatusRecord::load()` every `--interval` ms
|
||||
3. When `status.is_terminal()`, read `conclusion.json` for summary data
|
||||
4. Print human-readable status line to stderr (or `--json` to stdout)
|
||||
5. Exit 0 for `Succeeded`, exit 1 for `Failed`/`Dead` (use `std::process::exit(1)` to avoid printing an error prefix, matching the pattern in `run.rs`)
|
||||
|
||||
**Completion detection:** Poll `status.json` (not `conclusion.json` existence) since `RunStatusRecord::load()` gives the exact status. Fall back to `Dead` if the file is missing (orphaned run).
|
||||
|
||||
**Timeout:** Check deadline after each sleep iteration; `bail!()` with a message if exceeded.
|
||||
|
||||
### 2. Register in `lib/crates/fabro-cli/src/commands/mod.rs`
|
||||
|
||||
Add `pub mod wait;` between `validate` and `workflow` (line 19).
|
||||
|
||||
### 3. Register in `lib/crates/fabro-cli/src/main.rs`
|
||||
|
||||
Three insertions:
|
||||
|
||||
**(a)** Command enum variant (after `Rewind` at ~line 149):
|
||||
```rust
|
||||
/// Block until a workflow run completes
|
||||
Wait(commands::wait::WaitArgs),
|
||||
```
|
||||
|
||||
**(b)** Command name mapping (~line 497):
|
||||
```rust
|
||||
Command::Wait(_) => "wait",
|
||||
```
|
||||
|
||||
**(c)** Execution dispatch (~line 884, after `Rewind`):
|
||||
```rust
|
||||
Command::Wait(args) => {
|
||||
let styles = fabro_util::terminal::Styles::detect_stderr();
|
||||
commands::wait::run(args, &styles)?;
|
||||
}
|
||||
```
|
||||
|
||||
### Reused utilities
|
||||
|
||||
| Utility | Location |
|
||||
|---|---|
|
||||
| `resolve_run()` | `fabro_workflows::run_lookup` (run ID/name resolution) |
|
||||
| `RunStatusRecord::load()` | `fabro_workflows::run_status` (poll status.json) |
|
||||
| `RunStatus::is_terminal()` | `fabro_workflows::run_status` (check completion) |
|
||||
| `Conclusion::load()` | `fabro_workflows::conclusion` (read duration/cost) |
|
||||
| `format_duration_ms()` | `commands::shared` (human-readable duration) |
|
||||
| `Styles` | `fabro_util::terminal` (colored output) |
|
||||
|
||||
No new dependencies needed — all are already in `fabro-cli/Cargo.toml`.
|
||||
|
||||
## Verification
|
||||
|
||||
1. `cargo build -p fabro-cli` — compiles
|
||||
2. `cargo test -p fabro-cli` — existing tests pass
|
||||
3. `fabro wait --help` — shows usage
|
||||
4. `fabro wait <completed-run-id>` — prints status immediately, exits 0 or 1
|
||||
5. Launch a run, then `fabro wait <run-id>` — blocks until completion
|
||||
6. `fabro wait --timeout 1 <active-run>` — times out with error
|
||||
7. `fabro wait --json <run-id>` — prints JSON to stdout
|
||||
|
||||
|
||||
## 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, 64.1k tokens in / 6.7k out
|
||||
- Files: /home/daytona/workspace/lib/crates/fabro-cli/src/commands/mod.rs, /home/daytona/workspace/lib/crates/fabro-cli/src/commands/wait.rs, /home/daytona/workspace/lib/crates/fabro-cli/src/main.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).
|
||||
5
nodes/simplify_opus/provider_used.json
Normal file
5
nodes/simplify_opus/provider_used.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"mode": "agent",
|
||||
"provider": "anthropic",
|
||||
"model": "claude-opus-4-6"
|
||||
}
|
||||
11
nodes/simplify_opus/response.md
Normal file
11
nodes/simplify_opus/response.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
All clean. Here's a summary of what was fixed:
|
||||
|
||||
### Fixes applied
|
||||
|
||||
1. **Simplified `build_json_output`** (Code Reuse): Replaced verbose hand-rolled `serde_json::Map::new()` with `serde_json::json!{}` macro, which is already used elsewhere in the codebase for known shapes. Reduces the function from 20 lines to 11.
|
||||
|
||||
2. **Replaced dead `_ => "Unknown"` branch with `unreachable!()`** (Code Quality): The poll loop only breaks when `is_terminal()` returns true, which is exactly `Succeeded | Failed | Dead`. The wildcard arm was dead code masquerading as a fallback. `unreachable!()` makes the invariant explicit.
|
||||
|
||||
3. **Capped sleep duration at remaining deadline** (Efficiency): Previously, `thread::sleep(interval)` could sleep well past the deadline (e.g., `--timeout 5 --interval 10000` would sleep 10s). Now the sleep is `interval.min(dl - now)`, so it wakes up promptly when the deadline arrives.
|
||||
|
||||
4. **Used `to_writer_pretty` instead of `to_string_pretty`** (Efficiency): Avoids allocating an intermediate `String` by writing JSON directly to the locked stdout handle.
|
||||
6
nodes/simplify_opus/status.json
Normal file
6
nodes/simplify_opus/status.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"status": "success",
|
||||
"notes": "Stage completed: simplify_opus",
|
||||
"failure_reason": null,
|
||||
"timestamp": "2026-03-20T01:13:32.955839+00:00"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue