Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Commit 0eb2d8e

Browse files
z23ccclaude
andcommitted
feat(daemon): add flow_dir to DaemonState, migrate list handlers
Add flow_dir: PathBuf to DaemonState for json_store access. Migrate epics_handler and tasks_handler from DB to json_store. Remaining handlers (epic create/plan, task CRUD, dag) still use DB for writes — gradual migration continues in task .11. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4698aa7 commit 0eb2d8e

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

flowctl/crates/flowctl-daemon/src/handlers/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub struct DaemonState {
6262
pub runtime: DaemonRuntime,
6363
pub event_bus: flowctl_scheduler::EventBus,
6464
pub db: libsql::Connection,
65+
pub flow_dir: std::path::PathBuf,
6566
}
6667

6768
/// Map service-layer errors to HTTP-appropriate AppErrors.

flowctl/crates/flowctl-daemon/src/handlers/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ pub async fn status_handler(State(state): State<AppState>) -> impl IntoResponse
7373
)
7474
}
7575

76-
/// GET /api/v1/epics -- list epics from the database.
76+
/// GET /api/v1/epics -- list epics from JSON files.
7777
pub async fn epics_handler(
7878
State(state): State<AppState>,
7979
) -> Result<Json<serde_json::Value>, AppError> {
80-
let conn = state.db.clone();
81-
let repo = flowctl_db::EpicRepo::new(conn);
82-
let epics = repo.list(None).await?;
80+
let epics = flowctl_core::json_store::epic_list(&state.flow_dir)
81+
.map_err(|e| AppError::Internal(format!("json_store error: {e}")))?;
8382
let value = serde_json::to_value(&epics)
8483
.map_err(|e| AppError::Internal(format!("serialization error: {e}")))?;
8584
Ok(Json(value))
@@ -90,12 +89,12 @@ pub async fn tasks_handler(
9089
State(state): State<AppState>,
9190
axum::extract::Query(params): axum::extract::Query<TasksQuery>,
9291
) -> Result<Json<serde_json::Value>, AppError> {
93-
let conn = state.db.clone();
94-
let repo = flowctl_db::TaskRepo::new(conn);
9592
let tasks = if let Some(ref epic_id) = params.epic_id {
96-
repo.list_by_epic(epic_id).await?
93+
flowctl_core::json_store::task_list_by_epic(&state.flow_dir, epic_id)
94+
.map_err(|e| AppError::Internal(format!("json_store error: {e}")))?
9795
} else {
98-
repo.list_all(None, None).await?
96+
flowctl_core::json_store::task_list_all(&state.flow_dir)
97+
.map_err(|e| AppError::Internal(format!("json_store error: {e}")))?
9998
};
10099
let value = serde_json::to_value(&tasks)
101100
.map_err(|e| AppError::Internal(format!("serialization error: {e}")))?;

flowctl/crates/flowctl-daemon/src/server.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ pub async fn create_state(runtime: DaemonRuntime, event_bus: flowctl_scheduler::
2929
.with_context(|| format!("failed to open db in {}", working_dir.display()))?;
3030
let conn = db.connect().context("failed to connect to libsql db")?;
3131
let cancel = runtime.cancel.clone();
32+
// .flow/.state/ → parent is .flow/
33+
let flow_dir = runtime.paths.state_dir.parent()
34+
.map(|p| p.to_path_buf())
35+
.unwrap_or_else(|| working_dir.to_path_buf());
3236
let state = Arc::new(DaemonState {
3337
runtime,
3438
event_bus,
3539
db: conn,
40+
flow_dir,
3641
});
3742
Ok((state, cancel))
3843
}

0 commit comments

Comments
 (0)