Skip to content

Commit bcee479

Browse files
author
lijiuyang.5137
committed
Recognize remote control active prompt
1 parent e54a688 commit bcee479

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

src/runner.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ async fn run_stream_json(
528528
Some("control_response") => {}
529529
Some("control_cancel_request") => {}
530530
Some("user") => {
531+
let prompt = user_prompt_from_sdk_message(&value)?;
532+
logging::event(format!(
533+
"stream_user received content_chars={}",
534+
prompt.chars().count()
535+
));
531536
if ensure_sdk_mcp_runtime(process, tail, &mut input, &mut sdk_state, spawn).await? {
532537
tty_prepared = true;
533538
}
@@ -542,7 +547,6 @@ async fn run_stream_json(
542547
.await?;
543548
tty_prepared = true;
544549
}
545-
let prompt = user_prompt_from_sdk_message(&value)?;
546550
let _ = submit_prompt_and_tail_stream(
547551
process,
548552
tail,
@@ -3637,10 +3641,12 @@ fn tty_output_accepts_prompt(output: &str) -> bool {
36373641
let compact = compact_tty_output(&output);
36383642
let has_status = output.contains("permissions")
36393643
|| output.contains("Remote Control failed")
3644+
|| output.contains("Remote Control active")
36403645
|| output.contains("MCP server failed")
36413646
|| output.contains("/mcp")
36423647
|| compact.contains("permissions")
36433648
|| compact.contains("RemoteControlfailed")
3649+
|| compact.contains("RemoteControlactive")
36443650
|| compact.contains("MCPserverfailed")
36453651
|| compact.contains("/mcp");
36463652
let has_prompt_marker = output.contains('❯') || compact.contains('❯');
@@ -4281,6 +4287,19 @@ mod tests {
42814287
assert_eq!(question.options[1].description, "操作手册文档风格");
42824288
}
42834289

4290+
#[test]
4291+
fn accepts_remote_control_active_screen_as_prompt_ready() {
4292+
let output = "\
4293+
⏵⏵ auto mode on (shift+tab to cycle) · ← for agents ◉ xhigh · /effort \
4294+
Remote Control connecting… ⚠ 1 setup issue: MCP · /doctor ↯ /fast \
4295+
❯ Try \"edit main.go to...\" \
4296+
[Opus 4.8] │ workspace git:( test/remote-control ) Context ░░░░░░░░░░ 0% \
4297+
⏵⏵ auto mode on (shift+tab to cycle) · ← for agents \
4298+
Remote Control active ────── ↯ Remote Control active";
4299+
4300+
assert!(tty_output_accepts_prompt(output));
4301+
}
4302+
42844303
#[test]
42854304
fn keeps_english_question_leader_in_tty_question_prompt() {
42864305
let output = "\

tests/cctty_cli.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,54 @@ fn stream_json_text_prompt_uses_tty_transcript() {
9191
assert_eq!(lines[3]["result"], "FAKE_RESPONSE: Say OK");
9292
}
9393

94+
#[test]
95+
fn stream_json_remote_control_active_screen_accepts_prompt() {
96+
let fixture = FakeClaude::new();
97+
let workspace = tempfile::tempdir().unwrap();
98+
let config_dir = tempfile::tempdir().unwrap();
99+
let ready_output = "\
100+
⏵⏵ auto mode on (shift+tab to cycle) · ← for agents ◉ xhigh · /effort \
101+
Remote Control connecting… ⚠ 1 setup issue: MCP · /doctor ↯ /fast \
102+
❯ Try \"edit main.go to...\" \
103+
[Opus 4.8] │ workspace git:( test/remote-control ) Context ░░░░░░░░░░ 0% \
104+
⏵⏵ auto mode on (shift+tab to cycle) · ← for agents \
105+
Remote Control active ────── ↯ Remote Control active";
106+
let stdin = format!(
107+
"{}\n",
108+
serde_json::json!({
109+
"type": "user",
110+
"message": { "role": "user", "content": "Remote control prompt" },
111+
})
112+
);
113+
114+
let output = Command::cargo_bin("cctty")
115+
.unwrap()
116+
.env("CCTTY_CLAUDE_PATH", fixture.path())
117+
.env("CLAUDE_CONFIG_DIR", config_dir.path())
118+
.env("FAKE_CLAUDE_READY_OUTPUT", ready_output)
119+
.current_dir(workspace.path())
120+
.args([
121+
"--output-format",
122+
"stream-json",
123+
"--input-format",
124+
"stream-json",
125+
])
126+
.write_stdin(stdin)
127+
.output()
128+
.unwrap();
129+
130+
assert!(
131+
output.status.success(),
132+
"stderr:\n{}",
133+
String::from_utf8_lossy(&output.stderr)
134+
);
135+
let stdout = String::from_utf8(output.stdout).unwrap();
136+
assert!(
137+
stdout.contains("FAKE_RESPONSE: Remote control prompt"),
138+
"stdout:\n{stdout}"
139+
);
140+
}
141+
94142
#[test]
95143
fn stream_json_accepts_non_uuid_host_session_id() {
96144
let fixture = FakeClaude::new();

tests/support/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ startup_delay_ms = os.environ.get("FAKE_CLAUDE_STARTUP_DELAY_MS")
222222
if startup_delay_ms:
223223
time.sleep(int(startup_delay_ms) / 1000)
224224
225-
sys.stdout.write("Context permissions /mcp\n")
225+
ready_output = os.environ.get("FAKE_CLAUDE_READY_OUTPUT", "Context permissions /mcp\n")
226+
sys.stdout.write(ready_output)
227+
if ready_output and not ready_output.endswith("\n"):
228+
sys.stdout.write("\n")
226229
sys.stdout.flush()
227230
228231
buf = b""

0 commit comments

Comments
 (0)