O3: task sources and result sinks (#11)
This commit was merged in pull request #11.
This commit is contained in:
1 parent
2f79b69977
commit
afafc41376
10 files changed
+594
-76
No files matched your search
+7
-57
@@ -1,5 +1,6 @@
|
||||
//! One run: worktree -> hx (NDJSON, budgets, process group) -> commit -> gate -> final state.
|
||||
|
||||
use crate::adapter::Task;
|
||||
use crate::profile::Profile;
|
||||
use crate::state::{Run, Status, gate_log_path, kill_group, log_path, now};
|
||||
use anyhow::{Context, Result, bail};
|
||||
@@ -27,35 +28,8 @@ fn git(dir: &Path, args: &[&str]) -> Result<String> {
|
||||
Ok(String::from_utf8_lossy(&o.stdout).into_owned())
|
||||
}
|
||||
|
||||
/// Task file: first `#` heading = title, the rest = prompt.
|
||||
pub fn read_task(path: &Path) -> Result<(String, String)> {
|
||||
let s = std::fs::read_to_string(path).with_context(|| format!("task {}", path.display()))?;
|
||||
let title = s
|
||||
.lines()
|
||||
.find(|l| l.starts_with('#'))
|
||||
.map(|l| l.trim_start_matches('#').trim().to_string());
|
||||
let body: String = s
|
||||
.lines()
|
||||
.filter(|l| !l.starts_with('#'))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let stem = path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("task")
|
||||
.to_string();
|
||||
let title = title.unwrap_or(stem);
|
||||
let body = if body.trim().is_empty() {
|
||||
title.clone()
|
||||
} else {
|
||||
body.trim().to_string()
|
||||
};
|
||||
Ok((title, body))
|
||||
}
|
||||
|
||||
pub fn new_run(task: &Path, repo: &Path, profile: &str) -> Result<Run> {
|
||||
let (title, _) = read_task(task)?;
|
||||
let stem = task.file_stem().and_then(|s| s.to_str()).unwrap_or("task");
|
||||
pub fn new_run(task: &Task, repo: &Path, profile: &str) -> Result<Run> {
|
||||
let stem = task.id.as_str();
|
||||
let stem: String = stem
|
||||
.chars()
|
||||
.map(|c| {
|
||||
@@ -74,7 +48,7 @@ pub fn new_run(task: &Path, repo: &Path, profile: &str) -> Result<Run> {
|
||||
branch: format!("orch/{id}"),
|
||||
worktree: crate::state_dir().join("worktrees").join(&id),
|
||||
id,
|
||||
title,
|
||||
title: task.title.clone(),
|
||||
profile: profile.into(),
|
||||
repo,
|
||||
status: Status::Queued,
|
||||
@@ -91,6 +65,7 @@ pub fn new_run(task: &Path, repo: &Path, profile: &str) -> Result<Run> {
|
||||
attempts: 0,
|
||||
turns: 0,
|
||||
spent_tokens: 0,
|
||||
published: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -124,8 +99,8 @@ fn retry_prompt(gate: &str, code: Option<i32>, out: &[u8], resumed: bool, body:
|
||||
|
||||
/// Runs the whole pipeline. Errors only for orch-internal problems; task failures end as `Failed` or
|
||||
/// `NeedsHuman` state. After a failed gate hx gets the gate output on the same session, up to `max_retries`.
|
||||
pub fn execute(r: &mut Run, p: &Profile, task: &Path) -> Result<()> {
|
||||
let (_, body) = read_task(task)?;
|
||||
pub fn execute(r: &mut Run, p: &Profile, task: &Task) -> Result<()> {
|
||||
let body = task.body.clone();
|
||||
r.save()?;
|
||||
std::fs::create_dir_all(r.worktree.parent().unwrap())?;
|
||||
let wt = r.worktree.to_string_lossy().into_owned();
|
||||
@@ -298,28 +273,3 @@ fn run_hx(
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn task_parsing() {
|
||||
let d = std::env::temp_dir().join(format!("orch-task-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&d).unwrap();
|
||||
let f = d.join("fix-it.md");
|
||||
std::fs::write(&f, "# Fix it\n\nDo the thing\nplease\n").unwrap();
|
||||
assert_eq!(
|
||||
read_task(&f).unwrap(),
|
||||
("Fix it".into(), "Do the thing\nplease".into())
|
||||
);
|
||||
std::fs::write(&f, "no heading, just text").unwrap();
|
||||
assert_eq!(
|
||||
read_task(&f).unwrap(),
|
||||
("fix-it".into(), "no heading, just text".into())
|
||||
);
|
||||
std::fs::write(&f, "# Only title").unwrap();
|
||||
assert_eq!(read_task(&f).unwrap().1, "Only title");
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user