Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions apps/server/src/agent_runs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ pub struct UserTurnExtras {

impl Default for UserTurnExtras {
fn default() -> Self {
Self { tool_calls_json: "[]".into(), attachments_json: "[]".into(), reply_to_uuid: None }
Self {
tool_calls_json: "[]".into(),
attachments_json: "[]".into(),
reply_to_uuid: None,
}
}
}

Expand All @@ -37,7 +41,14 @@ pub async fn record_user_turn(
agent_uuid: &str,
content: &str,
) -> Result<String, String> {
record_user_turn_with(pool, project_uuid, agent_uuid, content, &UserTurnExtras::default()).await
record_user_turn_with(
pool,
project_uuid,
agent_uuid,
content,
&UserTurnExtras::default(),
)
.await
}

pub async fn record_user_turn_with(
Expand Down Expand Up @@ -186,7 +197,17 @@ pub async fn save_assistant_and_finish(
tools_json: &str,
provider: &str,
) -> Result<(), sqlx::Error> {
save_assistant_and_finish_as(pool, run_uuid, project_uuid, agent_uuid, reply, tools_json, provider, "completed").await
save_assistant_and_finish_as(
pool,
run_uuid,
project_uuid,
agent_uuid,
reply,
tools_json,
provider,
"completed",
)
.await
}

/// Fin de tour avec un statut explicite (`completed` | `cancelled`, P4-05).
Expand Down Expand Up @@ -247,7 +268,11 @@ pub async fn fail_run(pool: &PgPool, run_uuid: &str, agent_uuid: &str, error: &s
pub fn summary_line(reply: &str) -> String {
let line = reply
.lines()
.map(|l| l.trim().trim_start_matches(['#', '*', '-', '>', ' ']).trim())
.map(|l| {
l.trim()
.trim_start_matches(['#', '*', '-', '>', ' '])
.trim()
})
.find(|l| !l.is_empty())
.unwrap_or("");
clip(line, 160)
Expand All @@ -263,12 +288,13 @@ pub async fn enqueue_with(
title: Option<&str>,
) -> Result<String, String> {
let uuid = enqueue(pool, project_uuid, agent_uuid, message_uuid).await?;
let _ = sqlx::query("UPDATE agent_runs SET kind = $1, title = COALESCE(title, $2) WHERE uuid = $3")
.bind(kind)
.bind(title.map(|t| clip(t, 80)))
.bind(&uuid)
.execute(pool)
.await;
let _ =
sqlx::query("UPDATE agent_runs SET kind = $1, title = COALESCE(title, $2) WHERE uuid = $3")
.bind(kind)
.bind(title.map(|t| clip(t, 80)))
.bind(&uuid)
.execute(pool)
.await;
Ok(uuid)
}

Expand All @@ -278,7 +304,14 @@ pub fn wake_title(marker: &str, content: &str) -> String {
if !m.is_empty() {
return clip(m, 80);
}
clip(content.lines().find(|l| !l.trim().is_empty()).unwrap_or("Réveil").trim(), 80)
clip(
content
.lines()
.find(|l| !l.trim().is_empty())
.unwrap_or("Réveil")
.trim(),
80,
)
}

/// Prochain worker en file d'attente du projet, passé en `pending` (P4-03).
Expand Down Expand Up @@ -360,7 +393,9 @@ pub fn deploy_repair_followup(user_message: &str, tools_json: &str) -> Option<St
let calls: Vec<Value> = serde_json::from_str(tools_json).unwrap_or_default();
// Publication verrouillée : l'agent attend la validation, pas de relance automatique.
let awaiting_approval = calls.iter().any(|call| {
call.get("result").and_then(|r| r.get("code")).and_then(|v| v.as_str())
call.get("result")
.and_then(|r| r.get("code"))
.and_then(|v| v.as_str())
== Some("publish_approval_required")
});
if awaiting_approval {
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/auto_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub async fn ensure_project_webhook(state: &AppState, project: &Project) -> Opti
}
}


async fn latest_success_sha(state: &AppState, project_id: i64) -> Option<String> {
let row: Option<(Option<String>,)> = sqlx::query_as(
"SELECT git_sha FROM deployments WHERE project_id = $1 AND environment = 'production' AND status IN ('success', 'ready') ORDER BY created_at DESC LIMIT 1",
Expand Down Expand Up @@ -155,7 +154,12 @@ async fn project_is_behind(state: &AppState, project: &Project) -> Option<(u64,
}
}

pub(crate) async fn deploy_project(state: &AppState, project: &Project, message: &str, target_sha: Option<&str>) {
pub(crate) async fn deploy_project(
state: &AppState,
project: &Project,
message: &str,
target_sha: Option<&str>,
) {
let dep_uuid = new_uuid();
let now = now_str();

Expand Down
Loading
Loading