commit 06845ceb37eb35dd3c9850f01015563b45d284ec
parent d1da939c66c0bb492f419c7af392fca03c32fe92
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 20:06:32 -0500
umtool: ⌘K form -- a second press for a no-undo verb, Runs that outlive Escape, no stale project (L8a review)
CommandForm asks "Yes, <what it does>" for a row whose confirm applies and posts confirm: true; what Run started is handed up and listed under Runs (nothing typed), reopened on its live log. The palette resets its page context on open and keys the form on it, so a quick pick after a client-side move never carries the last page's project.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 100 insertions(+), 20 deletions(-)
diff --git a/umtool/components/shell/CommandForm.tsx b/umtool/components/shell/CommandForm.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
-import { buildArgv, cliLine } from "@/lib/cli/argv.mjs";
+import { buildArgv, cliLine, confirmOf } from "@/lib/cli/argv.mjs";
import { cn } from "@/lib/utils";
// ---------------------------------------------------------------------------
@@ -10,14 +10,19 @@ import { cn } from "@/lib/utils";
// page's project and selection filled in; the exact command line under it
// (Copy as CLI -- built by the same lib/cli/argv.mjs the server builds argv
// with); Run posts { verb, values } to /api/cli and follows what it started:
-// the app job's live log, or the queued step's.
+// the app job's live log, or the queued step's. A row with `confirm` (no undo:
+// it deletes, evicts or kills) asks a second press, "Yes, <what it does>",
+// and the server wants that confirm too. What Run started is handed up
+// (onStarted), so the palette lists it under Runs after an Escape.
// ---------------------------------------------------------------------------
export type CliArg = { name: string; type: string; required?: boolean; choices?: string[]; default?: unknown; help?: string; repeat?: boolean; context?: string };
-export type CliVerb = { verb: string; summary: string; target: string; queue: boolean; args: CliArg[] };
+export type CliVerb = { verb: string; summary: string; target: string; queue: boolean; confirm?: { what: string; when?: string[]; unless?: string[] } | null; args: CliArg[] };
export type CliContext = { project: string | null; clip: string | null; post: string | null; take: string | null };
+export type Value = string | boolean;
+/** A run the palette keeps: its form's values and what it started. */
+export type CliRun = { verb: string; values: Record<string, Value>; kind: "job" | "queued"; id: string; line: string; at: number };
-type Value = string | boolean;
type Run =
| { kind: "job"; id: string; state: string; log: string[]; next: number; error: string | null; exitCode: number | null }
| { kind: "queued"; qid: string; state: string; log: string[]; error: string | null; exitCode: number | null; runnerUp: boolean };
@@ -38,9 +43,29 @@ function initialValues(row: CliVerb, ctx: CliContext): Record<string, Value> {
return v;
}
-export default function CommandForm({ row, ctx, onBack }: { row: CliVerb; ctx: CliContext; onBack: () => void }) {
- const [values, setValues] = useState<Record<string, Value>>(() => initialValues(row, ctx));
- const [run, setRun] = useState<Run | null>(null);
+export default function CommandForm({
+ row,
+ ctx,
+ onBack,
+ resume = null,
+ onStarted,
+}: {
+ row: CliVerb;
+ ctx: CliContext;
+ onBack: () => void;
+ /** A run started before (the palette's Runs): its values, and it is followed again. */
+ resume?: CliRun | null;
+ onStarted?: (run: CliRun) => void;
+}) {
+ const [values, setValues] = useState<Record<string, Value>>(() => (resume ? resume.values : initialValues(row, ctx)));
+ const [run, setRun] = useState<Run | null>(() =>
+ resume
+ ? resume.kind === "job"
+ ? { kind: "job", id: resume.id, state: "running", log: [], next: 0, error: null, exitCode: null }
+ : { kind: "queued", qid: resume.id, state: "queued", log: [], error: null, exitCode: null, runnerUp: true }
+ : null,
+ );
+ const [asking, setAsking] = useState<string | null>(null);
const [posting, setPosting] = useState(false);
const [refused, setRefused] = useState<string | null>(null);
const [copied, setCopied] = useState(false);
@@ -64,13 +89,21 @@ export default function CommandForm({ row, ctx, onBack }: { row: CliVerb; ctx: C
if (run.kind === "job") {
const r = await fetch(`/api/cli?job=${encodeURIComponent(run.id)}&since=${run.next}`, { cache: "no-store" });
const j = (await r.json()) as { job?: { state: string; log: string[]; next: number; error: string | null; exitCode: number | null } };
- if (!live || !j.job) return;
+ if (!live) return;
+ if (!j.job) {
+ setRun((cur) => (cur ? { ...cur, state: "failed", error: "the app no longer knows this job (it restarted): see Settings · system" } : cur));
+ return;
+ }
const job = j.job;
setRun((cur) => (cur && cur.kind === "job" ? { ...cur, state: job.state, log: [...cur.log, ...job.log].slice(-400), next: job.next, error: job.error, exitCode: job.exitCode } : cur));
} else {
const r = await fetch(`/api/cli?qid=${encodeURIComponent(run.qid)}`, { cache: "no-store" });
const j = (await r.json()) as { step?: { state: string; error: string | null; exitCode: number | null }; log?: string[]; runner?: { enabled: boolean; armed: boolean } };
- if (!live || !j.step) return;
+ if (!live) return;
+ if (!j.step) {
+ setRun((cur) => (cur ? { ...cur, state: "failed", error: "no such step in the queue" } : cur));
+ return;
+ }
const step = j.step;
setRun((cur) => (cur && cur.kind === "queued" ? { ...cur, state: step.state, log: j.log ?? [], error: step.error, exitCode: step.exitCode, runnerUp: !!j.runner?.armed } : cur));
}
@@ -91,24 +124,39 @@ export default function CommandForm({ row, ctx, onBack }: { row: CliVerb; ctx: C
const set = (name: string, v: Value) => setValues((cur) => ({ ...cur, [name]: v }));
- const submit = async () => {
+ const submit = async (confirmed = false) => {
if (!built.ok || going) return;
+ const what = confirmOf(row, values);
+ if (what && !confirmed) {
+ setAsking(what);
+ return;
+ }
+ setAsking(null);
setPosting(true);
setRefused(null);
try {
- const r = await fetch("/api/cli", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ verb: row.verb, values }) });
+ const r = await fetch("/api/cli", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ verb: row.verb, values, ...(confirmed ? { confirm: true } : {}) }),
+ });
const j = (await r.json().catch(() => ({}))) as {
error?: string;
+ line?: string;
+ confirm?: string;
job?: { id: string; state: string; log: string[]; next: number; error: string | null; exitCode: number | null };
queued?: { qid: string };
queue?: { armed: boolean };
};
if (!r.ok) {
- setRefused(j.error ?? `HTTP ${r.status}`);
+ if (j.confirm) setAsking(j.confirm);
+ else setRefused(j.error ?? `HTTP ${r.status}`);
} else if (j.job) {
setRun({ kind: "job", id: j.job.id, state: j.job.state, log: j.job.log, next: j.job.next, error: j.job.error, exitCode: j.job.exitCode });
+ onStarted?.({ verb: row.verb, values, kind: "job", id: j.job.id, line: j.line ?? line ?? "", at: Date.now() });
} else if (j.queued) {
setRun({ kind: "queued", qid: j.queued.qid, state: "queued", log: [], error: null, exitCode: null, runnerUp: !!j.queue?.armed });
+ onStarted?.({ verb: row.verb, values, kind: "queued", id: j.queued.qid, line: j.line ?? line ?? "", at: Date.now() });
}
} catch (e) {
setRefused(e instanceof Error ? e.message : String(e));
@@ -241,6 +289,17 @@ export default function CommandForm({ row, ctx, onBack }: { row: CliVerb; ctx: C
</span>
)}
</div>
+ {asking && (
+ <div data-cli-asking="" className="mt-2 flex flex-wrap items-center gap-2 rounded-[3px] border border-reject px-2 py-1.5">
+ <span className="text-[12px] text-text">This has no undo.</span>
+ <button type="button" data-cli-confirm="" onClick={() => void submit(true)} className="rounded-[3px] bg-reject px-2.5 py-1 text-[12px] font-medium text-on-signal">
+ Yes, {asking}
+ </button>
+ <button type="button" data-cli-cancel="" onClick={() => setAsking(null)} className="rounded-[3px] border border-seam-2 px-2.5 py-1 text-[12px] text-text">
+ Not now
+ </button>
+ </div>
+ )}
{refused && (
<p data-cli-refused="" className="mt-1.5 text-[12px] text-reject-text">
{refused}
diff --git a/umtool/components/shell/JumpPalette.tsx b/umtool/components/shell/JumpPalette.tsx
@@ -23,7 +23,7 @@ import {
} from "@/lib/hrefs";
import { MODES } from "@/lib/types";
import { cn } from "@/lib/utils";
-import CommandForm, { type CliContext, type CliVerb } from "./CommandForm";
+import CommandForm, { type CliContext, type CliRun, type CliVerb } from "./CommandForm";
// ---------------------------------------------------------------------------
// ⌘K: jump to any piece, place, tool or create action (plans/umtool-redesign.md,
@@ -41,12 +41,18 @@ import CommandForm, { type CliContext, type CliVerb } from "./CommandForm";
// something is typed (`>` first: commands only, all of them with nothing
// after it). Choosing one opens its form in place (CommandForm), the page's
// project and selection filled in -- GET /api/cli?path= says what the page is
-// about, asked each time the palette opens.
+// about, asked each time the palette opens (and reset first, so a quick pick never
+// gets the last page's project: the form is keyed on the context and remounts when
+// it arrives). What a form's Run started stays under Runs (nothing typed) for
+// the page's life, so an Escape mid-run loses nothing.
// ---------------------------------------------------------------------------
export const JUMP_EVENT = "umtool:jump";
-type Item = { id: string; section: "Places" | "Tools" | "Create" | "Pieces" | "Commands"; label: string; hint: string; href: string; verb?: string };
+type Item = { id: string; section: "Runs" | "Places" | "Tools" | "Create" | "Pieces" | "Commands"; label: string; hint: string; href: string; verb?: string; run?: CliRun };
+
+const NO_CONTEXT: CliContext = { project: null, clip: null, post: null, take: null };
+const clock = (ms: number) => new Date(ms).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
type PieceRow = { id: string; title: string; href: string; kind: string; site: string | null; stage: string; lifecycle: string };
const FIXED: Item[] = [
@@ -117,13 +123,17 @@ export default function JumpPalette() {
// Set once the chord is listened for, so a test (or a script) can wait for it.
const [ready, setReady] = useState(false);
const [verbs, setVerbs] = useState<CliVerb[] | null>(null);
- const [ctx, setCtx] = useState<CliContext>({ project: null, clip: null, post: null, take: null });
+ const [ctx, setCtx] = useState<CliContext>(NO_CONTEXT);
const [form, setForm] = useState<CliVerb | null>(null);
+ const [resume, setResume] = useState<CliRun | null>(null);
+ const [runs, setRuns] = useState<CliRun[]>([]);
const show = useCallback(() => {
setQ("");
setAt(0);
setForm(null);
+ setResume(null);
+ setCtx(NO_CONTEXT);
setOpen(true);
}, []);
@@ -214,7 +224,10 @@ export default function JumpPalette() {
),
];
const w = words(q);
- if (!w.length) return all.filter((it) => it.section !== "Pieces").concat(all.filter((it) => it.section === "Pieces").slice(0, 8));
+ const recent = runs.map(
+ (r): Item => ({ id: `run:${r.id}`, section: "Runs", label: r.verb, hint: `${r.kind === "queued" ? "queued " : ""}${r.id} · ${clock(r.at)}`, href: "", verb: r.verb, run: r }),
+ );
+ if (!w.length) return [...recent, ...all.filter((it) => it.section !== "Pieces"), ...all.filter((it) => it.section === "Pieces").slice(0, 8)];
const cmds = commands.slice(0, 12);
const hay = (it: Item) => `${it.label} ${it.hint}`.toLowerCase();
const hits = all.filter((it) => w.every((x) => hay(it).includes(x)));
@@ -227,7 +240,7 @@ export default function JumpPalette() {
]
.slice(0, 60)
.concat(cmds);
- }, [q, pieces, verbs]);
+ }, [q, pieces, verbs, runs]);
useEffect(() => {
list.current?.querySelector<HTMLElement>(`[data-jump-index="${at}"]`)?.scrollIntoView({ block: "nearest" });
@@ -237,7 +250,10 @@ export default function JumpPalette() {
if (!it) return;
if (it.verb) {
const v = verbs?.find((x) => x.verb === it.verb);
- if (v) setForm(v);
+ if (v) {
+ setResume(it.run ?? null);
+ setForm(v);
+ }
return;
}
setOpen(false);
@@ -259,11 +275,16 @@ export default function JumpPalette() {
{open && form && (
<div className="flex h-[76vh] max-h-[76vh] flex-col">
<CommandForm
- key={form.verb}
+ key={`${form.verb}|${resume?.id ?? ""}|${ctx.project ?? ""}|${ctx.clip ?? ""}|${ctx.post ?? ""}|${ctx.take ?? ""}`}
row={form}
ctx={ctx}
+ resume={resume}
+ onStarted={(r) => {
+ setRuns((cur) => [r, ...cur.filter((x) => x.id !== r.id)].slice(0, 8));
+ }}
onBack={() => {
setForm(null);
+ setResume(null);
setTimeout(() => input.current?.focus(), 0);
}}
/>