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
1 change: 1 addition & 0 deletions crates/mcp-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub mod claude_notice;
pub mod claude_resume;
pub mod permission_prompt;
pub mod prompt_hold;
pub mod seat_status;
pub mod usage;

/// Prefix of the name the sidecar is registered under in `.mcp.json`.
Expand Down
25 changes: 24 additions & 1 deletion crates/mcp-config/src/prompt_hold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ impl Queue {
/// seat is not `waiting`, and nothing is kept or being handed over. `None`
/// is the post kept.
pub fn pass(&mut self, waiting: bool, item: Item) -> Option<Item> {
if waiting || self.handing || !self.items.is_empty() {
if self.would_keep(waiting) {
self.items.push_back(item);
return None;
}
Some(item)
}

/// Whether a post handed over now would be kept rather than typed: the
/// seat is `waiting`, or something is kept or being handed over. The status
/// line a busy seat is typed (#412) is dropped, not kept, when this holds.
pub fn would_keep(&self, waiting: bool) -> bool {
waiting || self.handing || !self.items.is_empty()
}

/// Whether a hand-over begins now: something is kept, the seat is not
/// `waiting`, and no hand-over is under way. The caller that gets `true`
/// takes items with `next` until it gets `None`.
Expand Down Expand Up @@ -290,6 +297,22 @@ mod tests {
assert_eq!(q.next(false), None);
}

#[test]
fn would_keep_says_what_pass_would_do() {
let mut q = Queue::new();
assert!(!q.would_keep(false));
assert!(q.would_keep(true));
q.pass(true, post("a"));
// Not waiting any more, but something is kept.
assert!(q.would_keep(false));
assert!(q.begin(false));
q.next(false);
// Mid hand-over, nothing left in the queue.
assert!(q.would_keep(false));
assert_eq!(q.next(false), None);
assert!(!q.would_keep(false));
}

#[test]
fn one_hand_over_at_a_time() {
let mut q = Queue::new();
Expand Down
Loading
Loading