Skip to content
Open
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
28 changes: 27 additions & 1 deletion crates/trodden/src/harness/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct CursorHookInput {
#[serde(default)]
loop_count: Option<u64>,
#[serde(default)]
status: Option<String>,
#[serde(default)]
trigger: Option<String>,
}

Expand Down Expand Up @@ -391,8 +393,13 @@ impl Agent for Cursor {
observed.push(observer.edit("Edit", path, edit, true));
Moment::ToolDone
}
// A turn the user stopped, or one that errored, must not be restarted by a reminder.
"stop" => Moment::TurnEnd {
continued: input.loop_count.is_some_and(|count| count > 0),
continued: input.loop_count.is_some_and(|count| count > 0)
|| input
.status
.as_deref()
.is_some_and(|status| status != "completed"),
},
"preCompact" => {
observed.push(observer.compaction(input.trigger.as_deref() != Some("manual")));
Expand Down Expand Up @@ -721,6 +728,10 @@ mod tests {
),
Some(Moment::TurnEnd { continued: true })
);
assert_eq!(
Payload::moment(json!({"hook_event_name": "stop", "loop_count": 0})),
Some(Moment::TurnEnd { continued: false })
);
assert_eq!(
Payload::rendered(
Moment::TurnEnd { continued: false },
Expand All @@ -734,6 +745,21 @@ mod tests {
);
}

#[test]
fn stopped_or_failed_turns_are_never_reminded() {
for status in ["aborted", "error"] {
let moment = Payload::moment(
json!({"hook_event_name": "stop", "status": status, "loop_count": 0}),
)
.expect("event");
assert_eq!(
Payload::rendered(moment, Reply::Remind("run it")),
None,
"{status}"
);
}
}

#[test]
fn other_events_and_odd_payloads_are_ignored() {
assert_eq!(
Expand Down
Loading