plan mode: show full plan before the exit prompt (claude ExitPlanMode via bridge, ask_user path)
This commit is contained in:
1 parent
36e99fc8af
commit
8a9d8fe607
6 files changed
+78
-6
No files matched your search
@@ -168,6 +168,8 @@ pub async fn serve(path: &Path, cx: ToolCtx, bus: Bus, mode: Unanswered) -> std:
|
||||
Err(r)
|
||||
} else if let Err(r) = unprompted(&cx) {
|
||||
Err(r)
|
||||
} else if tool == "ExitPlanMode" {
|
||||
exit_plan(&cx, v["input"]["plan"].as_str().unwrap_or_default()).await
|
||||
} else if v["tool_name"] == "AskUserQuestion" {
|
||||
// claude's own question tool: show hx's popup, hand the answers back as input
|
||||
input = ask(&cx, &v["input"]).await;
|
||||
@@ -210,6 +212,38 @@ pub async fn serve(path: &Path, cx: ToolCtx, bus: Bus, mode: Unanswered) -> std:
|
||||
}
|
||||
}
|
||||
|
||||
/// claude's `ExitPlanMode`: the TUI shows the whole plan, then asks. Implement ends hx plan mode too.
|
||||
async fn exit_plan(cx: &ToolCtx, plan: &str) -> Result<(), String> {
|
||||
let q = crate::Question {
|
||||
text: "Implement this plan?".into(),
|
||||
options: vec![
|
||||
("Implement".into(), "leave plan mode and start".into()),
|
||||
(
|
||||
"Keep planning".into(),
|
||||
"stay read-only; type feedback below".into(),
|
||||
),
|
||||
],
|
||||
multi: false,
|
||||
other: true,
|
||||
plan: Some(plan.into()),
|
||||
};
|
||||
match cx.state.choose(q).await {
|
||||
Ok(Some(v)) if v.first().is_some_and(|s| s == "Implement") => {
|
||||
cx.state
|
||||
.allow
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.set_plan(false);
|
||||
Ok(())
|
||||
}
|
||||
Ok(Some(v)) if v.first().is_some_and(|s| s != "Keep planning") => Err(format!(
|
||||
"plan not approved, user feedback: {}. Revise and present the plan again.",
|
||||
v.join(", ")
|
||||
)),
|
||||
_ => Err("plan not approved; keep planning and ask what to change".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Run each `AskUserQuestion` question through the popup; `input` plus `answers` (question -> label(s)).
|
||||
/// None = no frontend or dismissed.
|
||||
async fn ask(cx: &ToolCtx, input: &Value) -> Option<Value> {
|
||||
@@ -227,6 +261,7 @@ async fn ask(cx: &ToolCtx, input: &Value) -> Option<Value> {
|
||||
options: options.collect(),
|
||||
multi: q["multiSelect"].as_bool().unwrap_or(false),
|
||||
other: true,
|
||||
plan: None,
|
||||
})
|
||||
.await
|
||||
.ok()??;
|
||||
@@ -362,6 +397,24 @@ mod tests {
|
||||
assert_eq!(ask(&cx, &inp).await.unwrap()["answers"]["Which?"], "B");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn exit_plan_shows_plan_and_implement_ends_plan_mode() {
|
||||
let cx = ToolCtx {
|
||||
cwd: ".".into(),
|
||||
state: Default::default(),
|
||||
};
|
||||
cx.state.allow.lock().unwrap().set_plan(true);
|
||||
let seen = std::sync::Arc::new(std::sync::Mutex::new(None));
|
||||
let s = seen.clone();
|
||||
let _ = cx.state.choose.set(std::sync::Arc::new(move |q| {
|
||||
*s.lock().unwrap() = q.plan.clone();
|
||||
Box::pin(async { Some(vec!["Keep planning".to_string()]) })
|
||||
}));
|
||||
assert!(exit_plan(&cx, "# P\nstep 1").await.is_err());
|
||||
assert_eq!(seen.lock().unwrap().as_deref(), Some("# P\nstep 1"));
|
||||
assert!(cx.state.allow.lock().unwrap().plan_on());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn socket_round_trip_allows_and_denies() {
|
||||
use crate::permit::Decision;
|
||||
|
||||
Reference in new issue
Block a user