Fix slash command
Co-Authored-By: siGit Code <noreply@sigit.si>
Seto Elkahfi committed
Sep 14, 2026 at 16:21 UTC
a363fa002ed0512b6bba4ec683b6475c102d1903
1 file changed
+32
-1
src/main.rs
+32
-1
@@ -1733,7 +1733,15 @@ impl SiGitAgent {
1733
return Ok(PromptResponse::new(StopReason::EndTurn));
1734
}
1735
1736
- let user_text = match parse_slash(&user_text) {
1736
+ let slash_command = parse_slash_from_prompt_texts(args.prompt.iter().filter_map(|block| {
1737
+ if let ContentBlock::Text(text) = block {
1738
+ Some(text.text.as_str())
1739
+ } else {
1740
+ None
1741
+ }
1742
+ }));
1743
+
1744
+ let user_text = match slash_command {
1745
// `/init` is not a status command: it substitutes the canned
1746
// AGENTS.md-generation prompt and runs a normal agent turn, so the
1747
// exploration and file write go through the ordinary tools and
@@ -3036,6 +3044,15 @@ fn parse_slash(input: &str) -> Option<SlashCommand> {
3044
})
3045
}
3046
3047
+/// ACP clients may prepend context as separate text blocks before the user's
3048
+/// input. Search from the end so a standalone slash command in the final user
3049
+/// block is still dispatched locally instead of being buried in joined context.
3050
+fn parse_slash_from_prompt_texts<'a>(
3051
+ texts: impl DoubleEndedIterator<Item = &'a str>,
3052
+) -> Option<SlashCommand> {
3053
+ texts.rev().find_map(parse_slash)
3054
+}
3055
+
3056
/// `on`/`off` (and synonyms) → `Some(bool)`; missing or unrecognized → `None`
3057
/// (meaning "toggle the current value").
3058
fn parse_on_off(arg: Option<&str>) -> Option<bool> {
@@ -4415,6 +4432,20 @@ mod tests {
4432
assert!(matches!(parse_slash(" /init "), Some(SlashCommand::Init)));
4433
}
4434
4435
+ #[test]
4436
+ fn parse_slash_finds_command_after_client_context_blocks() {
4437
+ let texts = [
4438
+ "<system-reminder>Xcode context</system-reminder>",
4439
+ "Project structure: App/App.swift",
4440
+ "/models",
4441
+ ];
4442
+
4443
+ assert!(matches!(
4444
+ parse_slash_from_prompt_texts(texts.into_iter()),
4445
+ Some(SlashCommand::Models(None))
4446
+ ));
4447
+ }
4448
+
4449
#[test]
4450
fn system_prompt_points_issue_and_pr_work_at_the_official_mcp_tools() {
4451
// The guidance must reference the exact namespaced names the official