Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6ac633bf3 | ||
|
|
ed9a9184d0 | ||
|
|
d4c7df4f96 |
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": "0.1.5",
|
"version": "0.1.6",
|
||||||
"sha256": {
|
"sha256": {
|
||||||
"aarch64-apple-darwin": "106d0f4156b687a7a5e1ef8cdd9fcf5f00408afdb320f93e885acdd892b353a1",
|
"aarch64-apple-darwin": "52669aa98fd6d710cf78f5faf75530eaab00df0e1fafe74d36155ba6f2a1c999",
|
||||||
"x86_64-unknown-linux-musl": "2a86641064692c52c4455b327856be772ff75f93572bdad5836e2a5124f6c3ba"
|
"x86_64-unknown-linux-musl": "a1f140d6c114dce386ad676f8fdfdf89792f192cc47462a694da7b4bb5d95263"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -417,6 +417,10 @@ impl Agent {
|
|||||||
/// An abort ends this run only; the next `run` starts un-aborted.
|
/// An abort ends this run only; the next `run` starts un-aborted.
|
||||||
pub async fn run(&mut self, prompt: impl Into<String>) -> Result<Message, Error> {
|
pub async fn run(&mut self, prompt: impl Into<String>) -> Result<Message, Error> {
|
||||||
let r = self.run_inner(prompt.into()).await;
|
let r = self.run_inner(prompt.into()).await;
|
||||||
|
self.emit(Event::RunEnd {
|
||||||
|
aborted: matches!(r, Err(Error::Aborted)),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
self.abort_tx
|
self.abort_tx
|
||||||
.send_if_modified(|a| std::mem::replace(a, false));
|
.send_if_modified(|a| std::mem::replace(a, false));
|
||||||
r
|
r
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ pub enum Event {
|
|||||||
TurnEnd,
|
TurnEnd,
|
||||||
/// Model finished without tool calls. `Inject` makes the agent continue.
|
/// Model finished without tool calls. `Inject` makes the agent continue.
|
||||||
AgentEnd,
|
AgentEnd,
|
||||||
|
/// A run ended for any reason (done, error, abort). Fires after the last turn.
|
||||||
|
RunEnd {
|
||||||
|
aborted: bool,
|
||||||
|
},
|
||||||
/// Streaming output from the model (UI).
|
/// Streaming output from the model (UI).
|
||||||
Stream(StreamEvent),
|
Stream(StreamEvent),
|
||||||
Message(Message),
|
Message(Message),
|
||||||
@@ -57,6 +61,7 @@ impl Event {
|
|||||||
"content": content, "is_error": is_error}),
|
"content": content, "is_error": is_error}),
|
||||||
Event::TurnEnd => json!({"type": "turn_end"}),
|
Event::TurnEnd => json!({"type": "turn_end"}),
|
||||||
Event::AgentEnd => json!({"type": "agent_end"}),
|
Event::AgentEnd => json!({"type": "agent_end"}),
|
||||||
|
Event::RunEnd { aborted } => json!({"type": "run_end", "aborted": aborted}),
|
||||||
Event::Stream(e) => json!({"type": "stream", "event": e}),
|
Event::Stream(e) => json!({"type": "stream", "event": e}),
|
||||||
Event::Message(m) => json!({"type": "message", "message": m}),
|
Event::Message(m) => json!({"type": "message", "message": m}),
|
||||||
Event::Info(t) => json!({"type": "info", "text": t}),
|
Event::Info(t) => json!({"type": "info", "text": t}),
|
||||||
@@ -74,6 +79,7 @@ impl Event {
|
|||||||
Event::ToolResult { .. } => "tool_result",
|
Event::ToolResult { .. } => "tool_result",
|
||||||
Event::TurnEnd => "turn_end",
|
Event::TurnEnd => "turn_end",
|
||||||
Event::AgentEnd => "agent_end",
|
Event::AgentEnd => "agent_end",
|
||||||
|
Event::RunEnd { .. } => "run_end",
|
||||||
Event::Stream(_) => "stream",
|
Event::Stream(_) => "stream",
|
||||||
Event::Message(_) => "message",
|
Event::Message(_) => "message",
|
||||||
Event::Info(_) => "info",
|
Event::Info(_) => "info",
|
||||||
|
|||||||
@@ -370,6 +370,21 @@ pub fn format_findings(v: &[&Finding]) -> String {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Hook for Lens {
|
impl Hook for Lens {
|
||||||
async fn on(&self, ev: &Event) -> HookAction {
|
async fn on(&self, ev: &Event) -> HookAction {
|
||||||
|
// Anything that changed on disk during the run is ours (bash, subagents, an aborted
|
||||||
|
// tool that already wrote), not the user's. Re-baseline the read-guard too.
|
||||||
|
if matches!(ev, Event::TurnEnd | Event::AgentEnd | Event::RunEnd { .. }) {
|
||||||
|
for p in self.watch.scan(&self.seq, Source::Agent) {
|
||||||
|
if let Some(st) = self.state.get() {
|
||||||
|
st.mark_seen(&p);
|
||||||
|
}
|
||||||
|
if matches!(ev, Event::RunEnd { aborted: true }) {
|
||||||
|
self.note(format!(
|
||||||
|
"{} changed by your aborted previous run (may be half-done); re-read it",
|
||||||
|
self.rel(&p)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
match ev {
|
match ev {
|
||||||
Event::ToolResult {
|
Event::ToolResult {
|
||||||
name,
|
name,
|
||||||
@@ -395,7 +410,7 @@ impl Hook for Lens {
|
|||||||
}
|
}
|
||||||
Event::TurnStart => {
|
Event::TurnStart => {
|
||||||
// edits made outside hx while the model was thinking
|
// edits made outside hx while the model was thinking
|
||||||
self.watch.scan(&self.seq);
|
self.watch.scan(&self.seq, Source::External);
|
||||||
HookAction::Continue
|
HookAction::Continue
|
||||||
}
|
}
|
||||||
Event::TurnEnd if self.mode == Mode::TurnEnd => self
|
Event::TurnEnd if self.mode == Mode::TurnEnd => self
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ pub enum Source {
|
|||||||
AgentEdit,
|
AgentEdit,
|
||||||
Format,
|
Format,
|
||||||
Autofix,
|
Autofix,
|
||||||
|
/// Changed during an agent run by something other than a file tool (bash, subagent, aborted tool).
|
||||||
|
Agent,
|
||||||
External,
|
External,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ impl Watch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Record files whose mtime changed since last seen. Returns them.
|
/// Record files whose mtime changed since last seen. Returns them.
|
||||||
pub fn scan(&self, seq: &SeqLog) -> Vec<PathBuf> {
|
pub fn scan(&self, seq: &SeqLog, src: Source) -> Vec<PathBuf> {
|
||||||
let mut map = self.mtimes.lock().unwrap_or_else(|e| e.into_inner());
|
let mut map = self.mtimes.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
let mut changed = vec![];
|
let mut changed = vec![];
|
||||||
for (p, old) in map.iter_mut() {
|
for (p, old) in map.iter_mut() {
|
||||||
let now = mtime(p);
|
let now = mtime(p);
|
||||||
if now != *old {
|
if now != *old {
|
||||||
*old = now;
|
*old = now;
|
||||||
seq.bump(p, Source::External);
|
seq.bump(p, src);
|
||||||
changed.push(p.clone());
|
changed.push(p.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ impl Watch {
|
|||||||
let mut t = tokio::time::interval(every);
|
let mut t = tokio::time::interval(every);
|
||||||
loop {
|
loop {
|
||||||
t.tick().await;
|
t.tick().await;
|
||||||
w.scan(&seq);
|
w.scan(&seq, Source::External);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -71,16 +71,31 @@ mod tests {
|
|||||||
std::fs::write(&f, "1").unwrap();
|
std::fs::write(&f, "1").unwrap();
|
||||||
let (w, s) = (Watch::default(), SeqLog::default());
|
let (w, s) = (Watch::default(), SeqLog::default());
|
||||||
w.track(f.clone());
|
w.track(f.clone());
|
||||||
assert!(w.scan(&s).is_empty());
|
assert!(w.scan(&s, Source::External).is_empty());
|
||||||
std::thread::sleep(Duration::from_millis(20));
|
std::thread::sleep(Duration::from_millis(20));
|
||||||
std::fs::write(&f, "2").unwrap();
|
std::fs::write(&f, "2").unwrap();
|
||||||
assert_eq!(w.scan(&s), std::slice::from_ref(&f));
|
assert_eq!(w.scan(&s, Source::External), std::slice::from_ref(&f));
|
||||||
assert!(w.scan(&s).is_empty());
|
assert!(w.scan(&s, Source::External).is_empty());
|
||||||
assert_eq!(s.project(), 1);
|
assert_eq!(s.project(), 1);
|
||||||
// our own write: re-baseline, no bump
|
// our own write: re-baseline, no bump
|
||||||
std::thread::sleep(Duration::from_millis(20));
|
std::thread::sleep(Duration::from_millis(20));
|
||||||
std::fs::write(&f, "3").unwrap();
|
std::fs::write(&f, "3").unwrap();
|
||||||
w.track(f);
|
w.track(f);
|
||||||
assert!(w.scan(&s).is_empty());
|
assert!(w.scan(&s, Source::External).is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn agent_scan_not_external() {
|
||||||
|
let d = tempfile::tempdir().unwrap();
|
||||||
|
let f = d.path().join("a.rs");
|
||||||
|
std::fs::write(&f, "1").unwrap();
|
||||||
|
let (w, s) = (Watch::default(), SeqLog::default());
|
||||||
|
w.track(f.clone());
|
||||||
|
std::thread::sleep(Duration::from_millis(20));
|
||||||
|
std::fs::write(&f, "2").unwrap(); // e.g. bash sed, or an aborted edit
|
||||||
|
assert_eq!(w.scan(&s, Source::Agent).len(), 1);
|
||||||
|
// later turn start: nothing left to call external
|
||||||
|
assert!(w.scan(&s, Source::External).is_empty());
|
||||||
|
assert!(s.since(0).len() == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user