address review: drop backwards-compat request/response aliases, use canonical names

This commit is contained in:
damocles 2026-07-19 15:12:14 +02:00 committed by mara
commit 144912f8e0
14 changed files with 183 additions and 229 deletions

View file

@ -6,17 +6,17 @@
use std::sync::Arc;
use hive_agent_sock::AgentResponse;
use hive_agent_sock::Response;
use crate::coordinator::Coordinator;
/// `ListSchedules` — snapshot every scheduled prompt onto the wire.
pub(super) fn handle_list_schedules(coord: &Arc<Coordinator>) -> AgentResponse {
pub(super) fn handle_list_schedules(coord: &Arc<Coordinator>) -> Response {
match coord.scheduled_prompts.list() {
Ok(schedules) => AgentResponse::Schedules {
Ok(schedules) => Response::Schedules {
schedules: schedules.into_iter().map(schedule_to_wire).collect(),
},
Err(e) => AgentResponse::Err {
Err(e) => Response::Err {
message: format!("list scheduled prompts: {e:#}"),
},
}
@ -32,26 +32,26 @@ pub(super) fn handle_request_schedule_prompt(
coord: &Arc<Coordinator>,
requester: &str,
payload: &hive_sh4re::SchedulePromptPayload,
) -> AgentResponse {
) -> Response {
if payload.targets.is_empty() {
return AgentResponse::Err {
return Response::Err {
message: "schedule must have at least one target".into(),
};
}
if payload.body.trim().is_empty() {
return AgentResponse::Err {
return Response::Err {
message: "schedule body must be non-empty".into(),
};
}
if let Some(0) = payload.interval_seconds {
return AgentResponse::Err {
return Response::Err {
message: "interval_seconds must be > 0 (use None for one-shot)".into(),
};
}
let commit_ref = match serde_json::to_string(payload) {
Ok(s) => s,
Err(e) => {
return AgentResponse::Err {
return Response::Err {
message: format!("encode SchedulePromptPayload: {e:#}"),
};
}
@ -66,7 +66,7 @@ pub(super) fn handle_request_schedule_prompt(
) {
Ok(id) => id,
Err(e) => {
return AgentResponse::Err {
return Response::Err {
message: format!("queue schedule_prompt approval: {e:#}"),
};
}
@ -87,7 +87,7 @@ pub(super) fn handle_request_schedule_prompt(
description: payload.description.clone(),
pr_number: None,
});
AgentResponse::Ok
Response::Ok
}
/// Cancel a schedule (whole or per-target). Manager-surface
@ -101,22 +101,22 @@ pub(super) fn handle_cancel_schedule(
requester: &str,
schedule_id: i64,
targets: Option<&[String]>,
) -> AgentResponse {
) -> Response {
let schedule = match coord.scheduled_prompts.get(schedule_id) {
Ok(Some(s)) => s,
Ok(None) => {
return AgentResponse::Err {
return Response::Err {
message: format!("schedule {schedule_id} not found"),
};
}
Err(e) => {
return AgentResponse::Err {
return Response::Err {
message: format!("read schedule {schedule_id}: {e:#}"),
};
}
};
if !cancel_authorized(requester, &schedule.owner) {
return AgentResponse::Err {
return Response::Err {
message: format!(
"not authorized: {requester} cannot cancel schedule owned by {owner}",
owner = schedule.owner
@ -136,9 +136,9 @@ pub(super) fn handle_cancel_schedule(
match result {
Ok(()) => {
coord.emit_schedules_snapshot();
AgentResponse::Ok
Response::Ok
}
Err(message) => AgentResponse::Err { message },
Err(message) => Response::Err { message },
}
}
@ -151,22 +151,22 @@ pub(super) async fn handle_fire_schedule_now(
coord: &Arc<Coordinator>,
requester: &str,
schedule_id: i64,
) -> AgentResponse {
) -> Response {
let schedule = match coord.scheduled_prompts.get(schedule_id) {
Ok(Some(s)) => s,
Ok(None) => {
return AgentResponse::Err {
return Response::Err {
message: format!("schedule {schedule_id} not found"),
};
}
Err(e) => {
return AgentResponse::Err {
return Response::Err {
message: format!("read schedule {schedule_id}: {e:#}"),
};
}
};
if !cancel_authorized(requester, &schedule.owner) {
return AgentResponse::Err {
return Response::Err {
message: format!(
"not authorized: {requester} cannot fire schedule owned by {owner}",
owner = schedule.owner
@ -178,9 +178,9 @@ pub(super) async fn handle_fire_schedule_now(
match crate::scheduled_prompts_worker::fire_now(coord, schedule_id, false).await {
Ok(_report) => {
coord.emit_schedules_snapshot();
AgentResponse::Ok
Response::Ok
}
Err(e) => AgentResponse::Err {
Err(e) => Response::Err {
message: format!("fire schedule {schedule_id} now: {e:#}"),
},
}
@ -217,7 +217,7 @@ pub(super) fn handle_edit_schedule(
requester: &str,
schedule_id: i64,
patch: EditSchedulePatch,
) -> AgentResponse {
) -> Response {
let EditSchedulePatch {
body,
description,
@ -229,18 +229,18 @@ pub(super) fn handle_edit_schedule(
let schedule = match coord.scheduled_prompts.get(schedule_id) {
Ok(Some(s)) => s,
Ok(None) => {
return AgentResponse::Err {
return Response::Err {
message: format!("schedule {schedule_id} not found"),
};
}
Err(e) => {
return AgentResponse::Err {
return Response::Err {
message: format!("read schedule {schedule_id}: {e:#}"),
};
}
};
if !cancel_authorized(requester, &schedule.owner) {
return AgentResponse::Err {
return Response::Err {
message: format!(
"not authorized: {requester} cannot edit schedule owned by {owner}",
owner = schedule.owner
@ -258,9 +258,9 @@ pub(super) fn handle_edit_schedule(
match coord.scheduled_prompts.update(schedule_id, patch) {
Ok(()) => {
coord.emit_schedules_snapshot();
AgentResponse::Ok
Response::Ok
}
Err(e) => AgentResponse::Err {
Err(e) => Response::Err {
message: format!("edit schedule {schedule_id}: {e:#}"),
},
}