commit 09d021357cc7cc92e85a3effcd9ffed087137247
parent 4779aee89cd25afdee5e7f0f4552fe0a29ca6071
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 14 Oct 2026 07:43:40 -0400
umtool: a system action's plan takes the focus (its confirm, else Keep it), Escape keeps it, and closing returns to its button
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/umtool/components/system/ActionPlan.tsx b/umtool/components/system/ActionPlan.tsx
@@ -1,7 +1,7 @@
"use client";
import { useRouter } from "next/navigation";
-import { useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { Button } from "@/components/ui/button";
import { useHydrated } from "@/components/ui/use-hydrated";
import type { ActionAnswer, ActionPlanView } from "@/lib/system/plan-types";
@@ -63,6 +63,20 @@ export default function ActionPlan({
const router = useRouter();
const hydrated = useHydrated();
const [phase, setPhase] = useState<Phase>({ at: "closed" });
+ // The keys follow the plan: it opens on its confirm (or Keep it when there
+ // is nothing to confirm), and closing returns to the button that opened it.
+ const trigger = useRef<HTMLButtonElement>(null);
+ const first = useRef<HTMLButtonElement>(null);
+ const opened = useRef(false);
+ useEffect(() => {
+ if (phase.at === "plan" || phase.at === "error") {
+ opened.current = true;
+ first.current?.focus();
+ } else if (phase.at === "closed" && opened.current) {
+ opened.current = false;
+ trigger.current?.focus();
+ }
+ }, [phase.at]);
const ask = async () => {
setPhase({ at: "asking" });
@@ -93,7 +107,7 @@ export default function ActionPlan({
if (phase.at === "closed") {
return (
<span className="inline-flex flex-wrap items-center gap-2">
- <Button size="sm" variant={variant} disabled={!hydrated} onClick={() => void ask()} data-plan-trigger={subject}>
+ <Button ref={trigger} size="sm" variant={variant} disabled={!hydrated} onClick={() => void ask()} data-plan-trigger={subject}>
{label}
</Button>
{phase.done && (
@@ -109,7 +123,7 @@ export default function ActionPlan({
return (
<span role="alert" className="flex items-center gap-2 text-[12px] text-reject-text">
{phase.error}
- <Button size="sm" variant="quiet" onClick={() => setPhase({ at: "closed" })}>
+ <Button ref={first} size="sm" variant="quiet" onClick={() => setPhase({ at: "closed" })}>
Keep it
</Button>
</span>
@@ -123,6 +137,12 @@ export default function ActionPlan({
data-plan={plan.action}
data-plan-blocked={plan.blocked ? "yes" : "no"}
className="mt-2 basis-full rounded-[3px] border border-seam-2 bg-ink p-3 text-[12px]"
+ onKeyDown={(e) => {
+ if (e.key === "Escape" && phase.at === "plan") {
+ e.preventDefault();
+ setPhase({ at: "closed" });
+ }
+ }}
>
<p className="m-0 font-semibold text-text">{plan.title}</p>
<p className="m-0 mt-0.5 text-text-2">{plan.summary}</p>
@@ -161,11 +181,18 @@ export default function ActionPlan({
)}
<div className="mt-2.5 flex flex-wrap items-center gap-2">
{!plan.blocked && (
- <Button size="sm" variant={variant === "destructive" ? "destructive" : "primary"} disabled={phase.at === "working"} onClick={() => void confirm(plan)} data-plan-confirm="">
+ <Button
+ ref={first}
+ size="sm"
+ variant={variant === "destructive" ? "destructive" : "primary"}
+ disabled={phase.at === "working"}
+ onClick={() => void confirm(plan)}
+ data-plan-confirm=""
+ >
{phase.at === "working" ? "Working…" : plan.confirm}
</Button>
)}
- <Button size="sm" variant="quiet" onClick={() => setPhase({ at: "closed" })}>
+ <Button ref={plan.blocked ? first : undefined} size="sm" variant="quiet" onClick={() => setPhase({ at: "closed" })}>
Keep it
</Button>
</div>