mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-09 22:33:37 +00:00
parent
a1ab7f6ae6
commit
3612259caa
6 changed files with 948 additions and 34 deletions
574
run.json
574
run.json
File diff suppressed because one or more lines are too long
194
stages/006-simplify_opus@1/diff.patch
Normal file
194
stages/006-simplify_opus@1/diff.patch
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
diff --git a/lib/crates/fabro-automation/src/model.rs b/lib/crates/fabro-automation/src/model.rs
|
||||
index 530ab84e9..6e5cda0c1 100644
|
||||
--- a/lib/crates/fabro-automation/src/model.rs
|
||||
+++ b/lib/crates/fabro-automation/src/model.rs
|
||||
@@ -64,6 +64,20 @@ impl Automation {
|
||||
toml::to_string_pretty(&self.to_persisted()).map_err(AutomationStoreError::from)
|
||||
}
|
||||
|
||||
+ /// Returns the enabled API trigger if the automation itself is enabled and
|
||||
+ /// has one. Returns `None` when the automation is disabled or has no
|
||||
+ /// enabled API trigger.
|
||||
+ #[must_use]
|
||||
+ pub fn enabled_api_trigger(&self) -> Option<&ApiTrigger> {
|
||||
+ if !self.enabled {
|
||||
+ return None;
|
||||
+ }
|
||||
+ self.triggers.iter().find_map(|trigger| match trigger {
|
||||
+ AutomationTrigger::Api(trigger) if trigger.enabled => Some(trigger),
|
||||
+ _ => None,
|
||||
+ })
|
||||
+ }
|
||||
+
|
||||
fn from_persisted(
|
||||
id: AutomationId,
|
||||
revision: AutomationRevision,
|
||||
diff --git a/lib/crates/fabro-server/src/principal_middleware.rs b/lib/crates/fabro-server/src/principal_middleware.rs
|
||||
index 912f36d43..9e28be9e4 100644
|
||||
--- a/lib/crates/fabro-server/src/principal_middleware.rs
|
||||
+++ b/lib/crates/fabro-server/src/principal_middleware.rs
|
||||
@@ -238,7 +238,7 @@ impl<S: Send + Sync> FromRequestParts<S> for RequiredRunToolActor {
|
||||
.get::<AuthContextSlot>()
|
||||
.cloned()
|
||||
.unwrap_or_else(AuthContextSlot::initial);
|
||||
- require_run_tool_actor(&slot).map(Self)
|
||||
+ require_run_management_actor(&slot).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,10 +419,6 @@ pub(crate) fn require_run_management_actor(slot: &AuthContextSlot) -> Result<Pri
|
||||
}
|
||||
}
|
||||
|
||||
-pub(crate) fn require_run_tool_actor(slot: &AuthContextSlot) -> Result<Principal, ApiError> {
|
||||
- require_run_management_actor(slot)
|
||||
-}
|
||||
-
|
||||
fn require_worker_or_user_for_run(
|
||||
slot: &AuthContextSlot,
|
||||
route_run_id: &RunId,
|
||||
diff --git a/lib/crates/fabro-server/src/server.rs b/lib/crates/fabro-server/src/server.rs
|
||||
index 12e05edbc..4f0ff4dd5 100644
|
||||
--- a/lib/crates/fabro-server/src/server.rs
|
||||
+++ b/lib/crates/fabro-server/src/server.rs
|
||||
@@ -1056,10 +1056,6 @@ impl AppState {
|
||||
&self.automation_store
|
||||
}
|
||||
|
||||
- #[allow(
|
||||
- dead_code,
|
||||
- reason = "Automation scheduler wiring will call this after issue #398's materialization core."
|
||||
- )]
|
||||
pub(crate) async fn materialize_automation_run(
|
||||
&self,
|
||||
input: AutomationRunMaterializeInput,
|
||||
diff --git a/lib/crates/fabro-server/src/server/handler/automations.rs b/lib/crates/fabro-server/src/server/handler/automations.rs
|
||||
index 94b873fc4..87fcaf047 100644
|
||||
--- a/lib/crates/fabro-server/src/server/handler/automations.rs
|
||||
+++ b/lib/crates/fabro-server/src/server/handler/automations.rs
|
||||
@@ -2,9 +2,10 @@ use std::sync::Arc;
|
||||
|
||||
use axum::http::{HeaderMap, HeaderValue, header};
|
||||
use axum_extra::extract::Query as ExtraQuery;
|
||||
+use chrono::Utc;
|
||||
use fabro_automation::{
|
||||
- ApiTrigger, Automation, AutomationDraft, AutomationId, AutomationReplace, AutomationRevision,
|
||||
- AutomationStoreError, AutomationTrigger,
|
||||
+ Automation, AutomationDraft, AutomationId, AutomationReplace, AutomationRevision,
|
||||
+ AutomationStoreError,
|
||||
};
|
||||
use fabro_config::Storage;
|
||||
use fabro_types::{AutomationRef, RunId};
|
||||
@@ -15,13 +16,9 @@ use super::super::{
|
||||
State, StatusCode, get, paginate_items,
|
||||
};
|
||||
use super::runs;
|
||||
-use crate::automation_materializer::{
|
||||
- AutomationRunMaterializeError, AutomationRunMaterializeInput,
|
||||
-};
|
||||
+use crate::automation_materializer::AutomationRunMaterializeInput;
|
||||
use crate::principal_middleware::RequiredRunToolActor;
|
||||
|
||||
-const AUTOMATION_API_TRIGGER_DISABLED_CODE: &str = "automation_api_trigger_disabled";
|
||||
-
|
||||
#[derive(Serialize)]
|
||||
struct AutomationListResponse {
|
||||
data: Vec<Automation>,
|
||||
@@ -80,7 +77,7 @@ async fn list_automation_runs(
|
||||
|
||||
let entries = match state
|
||||
.store
|
||||
- .list_cached_runs(&fabro_store::ListRunsQuery::default(), chrono::Utc::now())
|
||||
+ .list_cached_runs(&fabro_store::ListRunsQuery::default(), Utc::now())
|
||||
.await
|
||||
{
|
||||
Ok(entries) => entries,
|
||||
@@ -107,8 +104,8 @@ async fn list_automation_runs(
|
||||
});
|
||||
|
||||
let total = runs.len() as u64;
|
||||
- let decorated = state.decorate_run_summaries(runs).await;
|
||||
- let (data, has_more) = paginate_items(decorated, &pagination);
|
||||
+ let (page, has_more) = paginate_items(runs, &pagination);
|
||||
+ let data = state.decorate_run_summaries(page).await;
|
||||
|
||||
(
|
||||
StatusCode::OK,
|
||||
@@ -133,24 +130,35 @@ async fn create_automation_run(
|
||||
let Some(automation) = state.automation_store().get(&id).await else {
|
||||
return ApiError::not_found(format!("automation not found: {id}")).into_response();
|
||||
};
|
||||
- let Some(api_trigger) = enabled_api_trigger(&automation) else {
|
||||
- return automation_api_trigger_disabled_error().into_response();
|
||||
+ let Some(api_trigger) = automation.enabled_api_trigger() else {
|
||||
+ return ApiError::with_code(
|
||||
+ StatusCode::CONFLICT,
|
||||
+ "automation is disabled or has no enabled API trigger",
|
||||
+ "automation_api_trigger_disabled",
|
||||
+ )
|
||||
+ .into_response();
|
||||
};
|
||||
let api_trigger_id = api_trigger.id.to_string();
|
||||
|
||||
let run_id = RunId::new();
|
||||
+ let temp_root = Storage::new(state.server_storage_dir())
|
||||
+ .scratch_dir()
|
||||
+ .join("automations");
|
||||
let materialized = match state
|
||||
.materialize_automation_run(AutomationRunMaterializeInput {
|
||||
automation_id: automation.id.clone(),
|
||||
target: automation.target.clone(),
|
||||
run_id,
|
||||
user_settings_path: state.active_config_path().to_path_buf(),
|
||||
- temp_root: automation_materialization_temp_root(state.as_ref()),
|
||||
+ temp_root,
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(materialized) => materialized,
|
||||
- Err(err) => return automation_materialize_error(&err).into_response(),
|
||||
+ Err(err) => {
|
||||
+ return ApiError::new(StatusCode::UNPROCESSABLE_ENTITY, err.to_string())
|
||||
+ .into_response();
|
||||
+ }
|
||||
};
|
||||
let explicit_title_supplied = materialized.manifest.title.is_some();
|
||||
let automation_ref = AutomationRef {
|
||||
@@ -254,37 +262,6 @@ fn unquote_etag(value: &str) -> &str {
|
||||
.unwrap_or(value)
|
||||
}
|
||||
|
||||
-fn enabled_api_trigger(automation: &Automation) -> Option<&ApiTrigger> {
|
||||
- if !automation.enabled {
|
||||
- return None;
|
||||
- }
|
||||
- automation
|
||||
- .triggers
|
||||
- .iter()
|
||||
- .find_map(|trigger| match trigger {
|
||||
- AutomationTrigger::Api(trigger) if trigger.enabled => Some(trigger),
|
||||
- _ => None,
|
||||
- })
|
||||
-}
|
||||
-
|
||||
-fn automation_api_trigger_disabled_error() -> ApiError {
|
||||
- ApiError::with_code(
|
||||
- StatusCode::CONFLICT,
|
||||
- "automation is disabled or has no enabled API trigger",
|
||||
- AUTOMATION_API_TRIGGER_DISABLED_CODE,
|
||||
- )
|
||||
-}
|
||||
-
|
||||
-fn automation_materialization_temp_root(state: &AppState) -> std::path::PathBuf {
|
||||
- Storage::new(state.server_storage_dir())
|
||||
- .scratch_dir()
|
||||
- .join("automations")
|
||||
-}
|
||||
-
|
||||
-fn automation_materialize_error(err: &AutomationRunMaterializeError) -> ApiError {
|
||||
- ApiError::new(StatusCode::UNPROCESSABLE_ENTITY, err.to_string())
|
||||
-}
|
||||
-
|
||||
fn automation_with_etag_response(status: StatusCode, automation: Automation) -> Response {
|
||||
let etag = HeaderValue::from_str(&format!("\"{}\"", automation.revision))
|
||||
.expect("automation revisions are valid ETag header values");
|
||||
6
stages/006-simplify_opus@1/status.json
Normal file
6
stages/006-simplify_opus@1/status.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"outcome": "succeeded",
|
||||
"notes": "Stage completed: simplify_opus",
|
||||
"failure_reason": null,
|
||||
"timestamp": "2026-05-28T00:54:06.793063Z"
|
||||
}
|
||||
185
stages/007-simplify_gpt@1/prompt.md
Normal file
185
stages/007-simplify_gpt@1/prompt.md
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
Goal: # Issue #399: Add automation run endpoints
|
||||
|
||||
- URL: https://github.com/fabro-sh/fabro/issues/399
|
||||
- State: OPEN
|
||||
- Author: Bryan Helmkamp (@brynary)
|
||||
- Created: 2026-05-25T15:06:27Z
|
||||
- Updated: 2026-05-25T15:06:27Z
|
||||
- Labels: None
|
||||
- Assignees: None
|
||||
- Milestone: None
|
||||
- Comments: 0
|
||||
|
||||
---
|
||||
|
||||
## Goal
|
||||
|
||||
Expose API endpoints for listing runs associated with an automation and starting a run through an enabled API trigger.
|
||||
|
||||
## Scope
|
||||
|
||||
Implement these endpoints:
|
||||
|
||||
```http
|
||||
GET /automations/{id}/runs
|
||||
POST /automations/{id}/runs
|
||||
```
|
||||
|
||||
`GET /automations/{id}/runs` behavior:
|
||||
|
||||
- Require the automation definition to exist; return 404 when it does not.
|
||||
- List cached runs from the existing run store.
|
||||
- Filter by `run.automation.as_ref().is_some_and(|a| a.id == id)`.
|
||||
- Sort newest first.
|
||||
- Support `page[limit]` and `page[offset]` using existing pagination behavior.
|
||||
- Return the existing paginated run list envelope:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": [],
|
||||
"meta": { "has_more": false, "total": 0 }
|
||||
}
|
||||
```
|
||||
|
||||
`POST /automations/{id}/runs` behavior:
|
||||
|
||||
- Use `RequiredRunToolActor`.
|
||||
- Require the automation to exist and be enabled.
|
||||
- Find an enabled trigger where `type = "api"`.
|
||||
- Return 409 with API error code `automation_api_trigger_disabled` when the automation is disabled or no enabled API trigger is available.
|
||||
- Materialize the run manifest using the configured `AutomationRunMaterializer`.
|
||||
- Call the shared create-run helper with:
|
||||
|
||||
```rust
|
||||
AutomationRef {
|
||||
id: automation.id.to_string(),
|
||||
name: Some(automation.name.clone()),
|
||||
trigger_id: Some(api_trigger.id.to_string()),
|
||||
}
|
||||
```
|
||||
|
||||
- Return 201 and the normal `Run` response shape with automation metadata populated.
|
||||
|
||||
Final integration expectations:
|
||||
|
||||
- Automation-created runs are visible through normal run APIs.
|
||||
- Automation-created runs are visible through `GET /automations/{id}/runs`.
|
||||
- Run history is derived from persisted/cached runs; no runtime automation state store is introduced.
|
||||
- Schedule trigger expressions are stored and validated by earlier phases but are not scheduled by this endpoint work.
|
||||
|
||||
## Files
|
||||
|
||||
Modify:
|
||||
|
||||
- `lib/crates/fabro-server/src/server/handler/automations.rs`
|
||||
- `lib/crates/fabro-server/src/server/handler/runs.rs`, only if additional helper exposure is needed from the previous phase
|
||||
- `lib/crates/fabro-server/tests/it/api/automations.rs`
|
||||
- `lib/crates/fabro-server/tests/it/api/mod.rs`
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- Disabled automations cannot start runs through the automation run endpoint.
|
||||
- Automations without an enabled API trigger cannot start runs through the automation run endpoint.
|
||||
- A successful API-triggered automation run returns a normal `Run` response with `automation.id`, `automation.name`, and `automation.trigger_id`.
|
||||
- The automation run listing endpoint returns only runs linked to that automation.
|
||||
- Automation run listings are newest-first and paginate correctly.
|
||||
- No scheduler, web UI route/component, or CLI command is added.
|
||||
|
||||
## Verification
|
||||
|
||||
Add integration tests using the fake materializer for:
|
||||
|
||||
- Disabled automation returns 409.
|
||||
- Disabled API trigger returns 409.
|
||||
- Missing API trigger returns 409.
|
||||
- Successful run creation returns 201.
|
||||
- Created run persists `Run.automation`.
|
||||
- Associated run listing includes the run.
|
||||
- Run listing excludes runs from other automations.
|
||||
- Run listing pagination and newest-first sorting.
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
cargo nextest run -p fabro-automation
|
||||
cargo nextest run -p fabro-api
|
||||
cargo nextest run -p fabro-server automations
|
||||
cargo nextest run -p fabro-server openapi_conformance
|
||||
cargo +nightly-2026-04-14 fmt --check --all
|
||||
cargo +nightly-2026-04-14 clippy --workspace --all-targets -- -D warnings
|
||||
git diff -- apps/fabro-web lib/crates/fabro-cli
|
||||
```
|
||||
|
||||
Expected: focused tests and checks pass; web UI and CLI command modules remain unchanged.
|
||||
|
||||
|
||||
## Completed stages
|
||||
- **toolchain**: succeeded
|
||||
- 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`
|
||||
- Output:
|
||||
```
|
||||
cargo 1.95.0 (f2d3ce0bd 2026-03-21)
|
||||
```
|
||||
- **preflight_compile**: succeeded
|
||||
- Script: `cargo check -q --workspace 2>&1`
|
||||
- Output: (empty)
|
||||
- **preflight_lint**: succeeded
|
||||
- Script: `cargo +nightly-2026-04-14 clippy -q --workspace --all-targets -- -D warnings 2>&1`
|
||||
- Output: (empty)
|
||||
- **implement**: succeeded
|
||||
- Model: gpt-5.5, 1.6m tokens in / 24.4k out
|
||||
- **simplify_opus**: succeeded
|
||||
- Model: claude-opus-4-7, 91.3k tokens in / 21.0k out
|
||||
- Files: /home/daytona/workspace/fabro/lib/crates/fabro-automation/src/model.rs, /home/daytona/workspace/fabro/lib/crates/fabro-server/src/principal_middleware.rs, /home/daytona/workspace/fabro/lib/crates/fabro-server/src/server.rs, /home/daytona/workspace/fabro/lib/crates/fabro-server/src/server/handler/automations.rs
|
||||
|
||||
|
||||
# Simplify: Code Review and Cleanup
|
||||
|
||||
Review changes vs. origin 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
stages/007-simplify_gpt@1/provider_used.json
Normal file
5
stages/007-simplify_gpt@1/provider_used.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"mode": "agent",
|
||||
"provider": "openai",
|
||||
"model": "gpt-5.5"
|
||||
}
|
||||
18
stages/007-simplify_gpt@1/response.md
Normal file
18
stages/007-simplify_gpt@1/response.md
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Review complete.
|
||||
|
||||
- Working tree was already clean; reviewed committed changes vs `origin/main`.
|
||||
- Launched the three requested review agents. The tool reported completion but did not return actionable findings, so I also performed a direct reuse/quality/efficiency review of the diff.
|
||||
- No cleanup changes were needed; implementation looked focused and consistent.
|
||||
|
||||
Verification run:
|
||||
|
||||
- `cargo nextest run -p fabro-server --features test-support api::automations` ✅
|
||||
- `cargo nextest run -p fabro-server --features test-support openapi_conformance` ✅
|
||||
- `cargo nextest run -p fabro-automation` ✅
|
||||
- `cargo nextest run -p fabro-api` ✅
|
||||
- `cargo +nightly-2026-04-14 fmt --check --all` ✅
|
||||
- `cargo +nightly-2026-04-14 clippy --workspace --all-targets -- -D warnings` ✅
|
||||
- `git diff -- apps/fabro-web lib/crates/fabro-cli` ✅ no output
|
||||
- Final `git status --short` ✅ clean
|
||||
|
||||
Note: Running `cargo nextest run -p fabro-server automations` without `--features test-support` found no integration tests because the `it` test target requires the `test-support` feature, so I reran with the required feature enabled.
|
||||
Loading…
Add table
Reference in a new issue