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
12 changes: 11 additions & 1 deletion plugins/rig-acp/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,16 @@ struct Served {
/// Makes this app the router: serves the client from the first frame and
/// exits when the client closes the connection or the app is asked to.
pub(crate) fn install(app: &mut App) {
// A word after `acp`, such as an option, is no option of the run.
let invoked = app.world().get_resource::<Invoked>();
let after = invoked.map(|invoked| invoked.args.arguments.join(" "));
if let Some(after) = after.filter(|after| !after.is_empty()) {
app.refuse_run(format!(
"rig acp takes nothing after `acp`, so `{after}` would be ignored; put options \
before `acp`, as in `rig --{TOOLS}=read acp`"
));
return;
}
let world = app.world();
let (Some(home), Some(stores), Some(runtime), Some(wake)) = (
world.get_resource::<RigHome>(),
Expand Down Expand Up @@ -798,7 +808,7 @@ pub(crate) fn install(app: &mut App) {
}
},
};
// Each session checks the tools `rig acp --tools` gives against its own,
// Each session checks the tools `rig --tools … acp` gives against its own,
// the client's MCP servers' among them.
let invoked = app.world().get_resource::<Invoked>();
if let Some(tools) = invoked.filter(|invoked| invoked.flag(TOOLS)) {
Expand Down
25 changes: 25 additions & 0 deletions plugins/rig-acp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,28 @@ fn sleeping(place: &Place) -> bool {
.is_ok_and(|line| String::from_utf8_lossy(&line).contains("sleep"))
})
}

/// `rig acp --tools=read` is refused, saying to put options before `acp`:
/// the router reads only the options before it, so one after it would be
/// dropped.
#[test]
fn an_option_after_acp_is_refused() {
let args = Invocation::parse(&["acp", "--tools=read"]).unwrap_or_default();
assert_eq!(args.arguments, ["--tools=read"]);
let mut app = App::new();
app.insert_resource(Invoked {
args,
terminal: false,
});
crate::router::install(&mut app);
let refused = app
.world()
.get_resource::<rig_harness::host::launcher::Refused>();
let why = refused
.map(|refused| refused.0.as_str())
.unwrap_or_default();
assert!(
why.contains("`--tools=read`") && why.contains("before `acp`"),
"{why}"
);
}
2 changes: 1 addition & 1 deletion plugins/rig-acp/src/tests/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ fn a_refused_model_change_says_why_and_keeps_the_model() {
assert!(router.is_some());
}

/// `rig acp --tools` reaches each session, which checks it against its own
/// `rig --tools … acp` reaches each session, which checks it against its own
/// tools: a name none has refuses the session as it opens, and a known
/// list keeps the session to it.
#[test]
Expand Down
Loading