commit 57d1d6693d4cf64f48df7cfb5374c325fbfc24b7
parent 9254e89bf9d81bbdf9be90c75e59d97203620d09
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 19:19:22 -0500
umtool: ⌘K Commands -- every form verb in the palette, its form, Copy as CLI, POST /api/cli (redesign L8a)
The palette lists the registry's ui:"form" verbs once something is typed (`>` first: commands
only), matched on verb and summary. Choosing one opens its form in place (CommandForm), the
page's project and the clip, post or take its address names filled in (GET /api/cli?path=).
The line under it is the exact `node umtool/bin/umtool.mjs …` command (lib/cli/argv.mjs, the
server's own builder); Run posts {verb, values} and follows the job's live log, or Queue it
(a verb that renders) the durable queue's step. POST /api/cli runs only registry form verbs,
validates the values against the row's args and builds the argv itself; a raw argv, a ui:"none"
verb or a request from another site (or no page at all) is refused. knobs.md: "⌘K commands".
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 522 insertions(+), 7 deletions(-)
diff --git a/umtool/app/api/cli/route.ts b/umtool/app/api/cli/route.ts
@@ -0,0 +1,147 @@
+import path from "node:path";
+import { getJob, jobView, runningJob, startJob } from "@/lib/jobs";
+import { buildArgv, cliLine } from "@/lib/cli/argv.mjs";
+import { formVerbs, verbRow } from "@/lib/cli/verbs.mjs";
+import { resolveProject } from "@/lib/projects/core.mjs";
+import { resolveProjectPath } from "@/lib/projects";
+import { addStep, getStep, isQid, logFileOf, logTail } from "@/lib/queue/store.mjs";
+import { kickQueue, queueDir, queueRunnerStatus } from "@/lib/queue/runner";
+import { UMTOOL_DIR } from "@/lib/report/driver.mjs";
+import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs";
+
+export const dynamic = "force-dynamic";
+
+// ⌘K COMMANDS (umtool redesign, lane palette L8a; umtool/docs/knobs.md, "⌘K commands"):
+// the verb registry's forms, run.
+//
+// GET { verbs, context, queue }: every ui:"form" row (lib/cli/verbs.mjs:
+// verb, summary, target, queue, args) and, with ?path=<the page's
+// pathname + search>, what the page is about -- { project, clip, post, take }
+// GET ?job=<id>[&since=N] { job }: the app job a form started (lib/jobs.ts jobView, its log from N)
+// GET ?qid=<qid> { step, log }: a queued form's step and its log's last lines
+// POST { verb, values } -> 202 { job, line } | 202 { queued: { qid }, line }
+// the row's args validated and built into argv HERE (lib/cli/argv.mjs);
+// a row with `queue` (it renders, or holds the heavy slot) is added to the
+// durable queue, any other runs as one job on the app's runner
+// | 400 not a form verb, a value its schema refuses, a raw argv
+// | 403 not this app's own page | 409 another job is running
+//
+// The page never sends argv: a body that carries one is refused, and app/api/queue/route.ts
+// still refuses to add a step from a page. What runs is a registry row's argv, nothing else.
+const headers = { "cache-control": "no-store" };
+const umtoolCli = () => path.join(/* turbopackIgnore: true */ UMTOOL_DIR, "bin", "umtool.mjs");
+
+type Row = { verb: string; summary: string; ui: string; reason?: string; queue?: boolean; timeoutMin?: number; args: Array<{ name: string; type: string; context?: string }> };
+
+/** The project, and the selection, a page's address is about. */
+async function contextOf(raw: string | null) {
+ const ctx: { project: string | null; clip: string | null; post: string | null; take: string | null } = { project: null, clip: null, post: null, take: null };
+ if (!raw) return ctx;
+ let url: URL;
+ try {
+ url = new URL(raw, "http://x");
+ } catch {
+ return ctx;
+ }
+ const q = url.searchParams;
+ ctx.clip = q.get("clip");
+ ctx.take = q.get("take");
+ const segments = url.pathname.split("/").filter(Boolean).map((s) => {
+ try {
+ return decodeURIComponent(s);
+ } catch {
+ return s;
+ }
+ });
+ let rest: string[] = [];
+ if (segments[0] === "projects" && segments[1] === "at") {
+ ctx.project = q.get("path");
+ } else if (segments[0] === "projects" && segments.length > 1) {
+ const r = await resolveProjectPath(segments.slice(1)).catch(() => null);
+ if (r && "project" in r && r.project) {
+ ctx.project = r.project.id;
+ rest = (r as { rest?: string[] }).rest ?? [];
+ }
+ }
+ const [view, id] = rest;
+ if (id && view === "clip") ctx.clip = id;
+ if (id && view === "post") ctx.post = id;
+ if (id && view === "takes") ctx.take = id;
+ return ctx;
+}
+
+export async function GET(request: Request) {
+ const url = new URL(request.url);
+ const jobId = url.searchParams.get("job");
+ if (jobId) {
+ const job = getJob(jobId);
+ if (!job) return Response.json({ error: "no such job" }, { status: 404, headers });
+ return Response.json({ job: jobView(job, Math.max(0, Number(url.searchParams.get("since") ?? 0) || 0)) }, { headers });
+ }
+ const qid = url.searchParams.get("qid");
+ if (qid !== null) {
+ if (!isQid(qid)) return Response.json({ error: "?qid=<qid>" }, { status: 400, headers });
+ const step = (await getStep(queueDir(), qid)) as Record<string, unknown> | null;
+ if (!step) return Response.json({ error: "no such step" }, { status: 404, headers });
+ const log = await logTail(logFileOf(queueDir(), qid), 32 * 1024);
+ const pick = ["qid", "label", "state", "exitCode", "error", "blockedBy", "createdAt", "startedAt", "endedAt"] as const;
+ return Response.json({ step: Object.fromEntries(pick.map((k) => [k, step[k] ?? null])), log: log.slice(-200), runner: queueRunnerStatus() }, { headers });
+ }
+ return Response.json({ verbs: formVerbs(), context: await contextOf(url.searchParams.get("path")), queue: queueRunnerStatus() }, { headers });
+}
+
+/** Same-origin only: the browser says where a POST comes from, and one that says nothing is not a page of this app. */
+function refuseOrigin(request: Request): string | null {
+ const refused = crossSiteRefusal(request.headers);
+ if (refused) return refused;
+ const site = (request.headers.get("sec-fetch-site") ?? "").trim().toLowerCase();
+ if (site === "same-origin" || request.headers.get("origin")) return null;
+ return "refused: POST /api/cli runs only from this app's own pages -- in a terminal, run the command itself";
+}
+
+export async function POST(request: Request) {
+ const refused = refuseOrigin(request);
+ if (refused) return Response.json({ error: refused }, { status: 403, headers });
+ const body = (await request.json().catch(() => null)) as Record<string, unknown> | null;
+ if (!body || typeof body !== "object" || Array.isArray(body)) return Response.json({ error: "expected JSON: { verb, values }" }, { status: 400, headers });
+ if ("argv" in body || "args" in body || "cmd" in body || "command" in body) {
+ return Response.json({ error: "a raw command line is refused: name a verb of the registry and its values ({ verb, values })" }, { status: 400, headers });
+ }
+ const extra = Object.keys(body).filter((k) => k !== "verb" && k !== "values");
+ if (extra.length) return Response.json({ error: `unexpected ${extra.join(", ")}: the body is { verb, values }` }, { status: 400, headers });
+ const verb = typeof body.verb === "string" ? body.verb.trim() : "";
+ const row = verbRow(verb) as Row | null;
+ if (!row) return Response.json({ error: `no verb "${verb}" in the registry (umtool/lib/cli/verbs.mjs)` }, { status: 400, headers });
+ if (row.ui !== "form") return Response.json({ error: `umtool ${verb} has no form: ${row.reason}` }, { status: 400, headers });
+ const values = (body.values ?? {}) as Record<string, unknown>;
+ const built = buildArgv(row, values);
+ if (!built.ok) return Response.json({ error: built.error, field: built.field ?? null }, { status: 400, headers });
+
+ // A project arg is one the CLI will find: said here, not as the job's first line.
+ let project: string | null = null;
+ for (const a of row.args) {
+ const v = values[a.name];
+ if (a.type !== "project" || typeof v !== "string" || !v.trim()) continue;
+ const r = (await resolveProject(v.trim())) as { project?: { id: string }; ambiguous?: unknown[] };
+ if (r.ambiguous) return Response.json({ error: `"${v}" is the name of ${r.ambiguous.length} projects — give its id`, field: a.name }, { status: 400, headers });
+ if (!r.project) return Response.json({ error: `no project matches "${v}"`, field: a.name }, { status: 400, headers });
+ if (a.name === "project") project = r.project.id;
+ }
+ const take = row.args.filter((a) => a.context === "take").map((a) => values[a.name]).find((v): v is string => typeof v === "string" && !!v.trim()) ?? null;
+ const line = cliLine(built.argv);
+ const label = `⌘K: umtool ${built.argv.join(" ")}`.slice(0, 160);
+
+ if (row.queue) {
+ try {
+ const step = (await addStep(queueDir(), { argv: built.argv, label, by: "the umtool app (⌘K)", cwd: UMTOOL_DIR, target: project ? { project, take } : null })) as { qid: string };
+ kickQueue();
+ return Response.json({ ok: true, queued: { qid: step.qid }, line, queue: queueRunnerStatus() }, { status: 202, headers });
+ } catch (e) {
+ return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 409, headers });
+ }
+ }
+ const running = runningJob();
+ if (running) return Response.json({ error: `a job is already running (${running.kind}) — run this when it is done`, running: jobView(running, running.log.length) }, { status: 409, headers });
+ const job = startJob(`umtool ${verb}`, [{ cwd: UMTOOL_DIR, env: {}, label: `umtool ${built.argv.join(" ")}`.slice(0, 200), argv: [process.execPath, umtoolCli(), ...built.argv], timeoutMs: (row.timeoutMin ?? 15) * 60_000 }], { project });
+ return Response.json({ ok: true, job: jobView(job), line }, { status: 202, headers });
+}
diff --git a/umtool/components/shell/CommandForm.tsx b/umtool/components/shell/CommandForm.tsx
@@ -0,0 +1,263 @@
+"use client";
+
+import { useEffect, useMemo, useRef, useState } from "react";
+import { buildArgv, cliLine } from "@/lib/cli/argv.mjs";
+import { cn } from "@/lib/utils";
+
+// ---------------------------------------------------------------------------
+// ONE VERB AS A FORM (⌘K Commands, lane palette L8a): a row of the verb
+// registry (lib/cli/verbs.mjs, served by GET /api/cli) drawn as its args, the
+// 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.
+// ---------------------------------------------------------------------------
+
+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 CliContext = { project: string | null; clip: string | null; post: string | null; take: string | null };
+
+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 };
+
+const TEXTAREA = new Set(["pairs", "flagpairs", "list", "text", "json"]);
+const TERMINAL = new Set(["done", "failed", "cancelled", "blocked"]);
+
+/** What the page tells the form: the project for a project arg, the selection for one that asks. */
+function initialValues(row: CliVerb, ctx: CliContext): Record<string, Value> {
+ const v: Record<string, Value> = {};
+ for (const a of row.args) {
+ if (a.type === "project" && a.name === "project" && ctx.project) v[a.name] = ctx.project;
+ else if (a.context === "clip" && ctx.clip) v[a.name] = ctx.clip;
+ else if (a.context === "post" && ctx.post) v[a.name] = ctx.post;
+ else if (a.context === "take" && ctx.take && a.required) v[a.name] = ctx.take;
+ else if (a.default !== undefined) v[a.name] = typeof a.default === "boolean" ? a.default : String(a.default);
+ }
+ 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);
+ const [posting, setPosting] = useState(false);
+ const [refused, setRefused] = useState<string | null>(null);
+ const [copied, setCopied] = useState(false);
+ const first = useRef<HTMLElement | null>(null);
+ const logRef = useRef<HTMLPreElement>(null);
+
+ useEffect(() => {
+ first.current?.focus();
+ }, []);
+
+ const built = useMemo(() => buildArgv(row, values), [row, values]);
+ const line = built.ok ? cliLine(built.argv) : null;
+ const going = posting || (run !== null && !TERMINAL.has(run.state));
+
+ // Follow what Run started.
+ useEffect(() => {
+ if (!run || TERMINAL.has(run.state)) return;
+ let live = true;
+ const t = setTimeout(async () => {
+ try {
+ 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;
+ 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;
+ 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));
+ }
+ } catch {
+ /* the next turn tries again */
+ }
+ }, 700);
+ return () => {
+ live = false;
+ clearTimeout(t);
+ };
+ }, [run]);
+
+ useEffect(() => {
+ const el = logRef.current;
+ if (el) el.scrollTop = el.scrollHeight;
+ }, [run?.log.length]);
+
+ const set = (name: string, v: Value) => setValues((cur) => ({ ...cur, [name]: v }));
+
+ const submit = async () => {
+ if (!built.ok || going) return;
+ 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 j = (await r.json().catch(() => ({}))) as {
+ error?: 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}`);
+ } 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 });
+ } else if (j.queued) {
+ setRun({ kind: "queued", qid: j.queued.qid, state: "queued", log: [], error: null, exitCode: null, runnerUp: !!j.queue?.armed });
+ }
+ } catch (e) {
+ setRefused(e instanceof Error ? e.message : String(e));
+ } finally {
+ setPosting(false);
+ }
+ };
+
+ const copy = async () => {
+ if (!line) return;
+ try {
+ await navigator.clipboard.writeText(line);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 1500);
+ } catch {
+ setRefused("the clipboard refused: select the line and copy it");
+ }
+ };
+
+ const field = (a: CliArg, i: number) => {
+ const id = `cli-arg-${i}`;
+ const v = values[a.name];
+ const ref = i === 0 ? (el: HTMLElement | null) => void (first.current = el) : undefined;
+ const bad = !built.ok && built.field === a.name;
+ const control =
+ a.type === "boolean" ? (
+ <input id={id} ref={ref} type="checkbox" checked={v === true} onChange={(e) => set(a.name, e.target.checked)} className="h-3.5 w-3.5 accent-[var(--color-signal)]" />
+ ) : a.type === "choice" ? (
+ <select id={id} ref={ref} value={typeof v === "string" ? v : ""} onChange={(e) => set(a.name, e.target.value)} className="h-7 min-w-0 flex-1 rounded-[3px] border border-seam bg-panel-2 px-1.5 text-[12.5px]">
+ <option value="">{a.required ? "choose…" : "—"}</option>
+ {(a.choices ?? []).map((c) => (
+ <option key={c} value={c}>
+ {c}
+ </option>
+ ))}
+ </select>
+ ) : TEXTAREA.has(a.type) ? (
+ <textarea
+ id={id}
+ ref={ref}
+ rows={a.type === "text" || a.type === "json" ? 3 : 2}
+ value={typeof v === "string" ? v : ""}
+ placeholder={a.help ?? ""}
+ spellCheck={false}
+ onChange={(e) => set(a.name, e.target.value)}
+ className="min-w-0 flex-1 resize-y rounded-[3px] border border-seam bg-panel-2 px-1.5 py-1 font-mono text-[12px] text-text outline-none focus:border-signal"
+ />
+ ) : (
+ <input
+ id={id}
+ ref={ref}
+ value={typeof v === "string" ? v : ""}
+ inputMode={a.type === "number" ? "decimal" : undefined}
+ placeholder={a.help ?? (a.type === "number" ? "a number" : "")}
+ spellCheck={false}
+ onChange={(e) => set(a.name, e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ void submit();
+ }
+ }}
+ className="h-7 min-w-0 flex-1 rounded-[3px] border border-seam bg-panel-2 px-1.5 font-mono text-[12px] text-text outline-none focus:border-signal"
+ />
+ );
+ return (
+ <div key={a.name} data-cli-arg={a.name} className={cn("flex items-start gap-2 py-1", bad && "text-reject-text")}>
+ <label htmlFor={id} className="w-[132px] shrink-0 truncate pt-1 font-mono text-[11.5px] text-muted" title={a.help ?? a.name}>
+ {a.name}
+ {a.required && <span className="text-signal"> *</span>}
+ </label>
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
+ {control}
+ {a.help && a.type !== "boolean" && !TEXTAREA.has(a.type) && a.type !== "string" && a.type !== "number" && <span className="text-[11px] text-muted-2">{a.help}</span>}
+ {a.help && a.type === "boolean" && <span className="text-[11px] text-muted-2">{a.help}</span>}
+ </div>
+ </div>
+ );
+ };
+
+ return (
+ <div data-cli-form={row.verb} className="flex min-h-0 flex-1 flex-col">
+ <div className="flex items-baseline gap-3 border-b border-seam px-3.5 py-2.5">
+ <button type="button" data-cli-back="" onClick={onBack} className="font-mono text-[12px] text-muted hover:text-text">
+ ← Commands
+ </button>
+ <span className="font-mono text-[14px] text-text">umtool {row.verb}</span>
+ <span className="ml-auto min-w-0 truncate text-[12px] text-muted-2">{row.summary}</span>
+ </div>
+ <form
+ className="min-h-0 flex-1 overflow-y-auto px-3.5 py-1.5"
+ onSubmit={(e) => {
+ e.preventDefault();
+ void submit();
+ }}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
+ e.preventDefault();
+ void submit();
+ }
+ }}
+ >
+ {row.args.length ? row.args.map(field) : <p className="py-2 text-[12.5px] text-text-2">No arguments.</p>}
+ </form>
+ <div className="border-t border-seam px-3.5 py-2">
+ {line ? (
+ <code data-cli-line="" className="block select-all break-all font-mono text-[11.5px] text-text-2">
+ {line}
+ </code>
+ ) : (
+ <p data-cli-invalid="" className="text-[12px] text-reject-text">
+ {built.ok ? "" : built.error}
+ </p>
+ )}
+ <div className="mt-2 flex items-center gap-2">
+ <button type="button" data-cli-run="" disabled={!built.ok || going} onClick={() => void submit()} className="rounded-[3px] bg-signal px-3 py-1 text-[12.5px] font-medium text-on-signal disabled:opacity-40">
+ {row.queue ? "Queue it" : "Run"}
+ </button>
+ <button type="button" data-cli-copy="" disabled={!line} onClick={() => void copy()} className="rounded-[3px] border border-seam-2 px-3 py-1 text-[12.5px] text-text disabled:opacity-40">
+ {copied ? "Copied" : "Copy as CLI"}
+ </button>
+ <span className="text-[11.5px] text-muted-2">
+ {row.queue ? "renders: the durable queue runs it" : row.target === "draft" ? "writes the working draft (an undo point)" : row.target === "corpus" ? "not one project" : "a project's files"}
+ </span>
+ {run && (
+ <span data-cli-state={run.state} className={cn("ml-auto font-mono text-[12px]", run.state === "done" ? "text-kept-text" : TERMINAL.has(run.state) ? "text-reject-text" : "text-muted")}>
+ {run.kind === "queued" ? `${run.qid} · ` : ""}
+ {run.state}
+ {run.exitCode !== null && run.state !== "done" ? ` (exit ${run.exitCode})` : ""}
+ </span>
+ )}
+ </div>
+ {refused && (
+ <p data-cli-refused="" className="mt-1.5 text-[12px] text-reject-text">
+ {refused}
+ </p>
+ )}
+ {run && (
+ <>
+ {run.kind === "queued" && !run.runnerUp && run.state === "queued" && (
+ <p className="mt-1.5 text-[11.5px] text-muted-2">the queue's runner is not up in this app: the step waits (umtool queue ls)</p>
+ )}
+ {run.error && run.state !== "done" && <p className="mt-1.5 text-[12px] text-reject-text">{run.error}</p>}
+ <pre ref={logRef} data-cli-log="" className="mt-1.5 max-h-[22vh] overflow-auto whitespace-pre-wrap break-all rounded-[3px] bg-panel-2 px-2 py-1.5 font-mono text-[11px] leading-[1.45] text-text-2">
+ {run.log.join("\n") || "…"}
+ </pre>
+ </>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/umtool/components/shell/JumpPalette.tsx b/umtool/components/shell/JumpPalette.tsx
@@ -23,6 +23,7 @@ import {
} from "@/lib/hrefs";
import { MODES } from "@/lib/types";
import { cn } from "@/lib/utils";
+import CommandForm, { type CliContext, type CliVerb } from "./CommandForm";
// ---------------------------------------------------------------------------
// ⌘K: jump to any piece, place, tool or create action (plans/umtool-redesign.md,
@@ -34,11 +35,18 @@ import { cn } from "@/lib/utils";
// The places, tools and create actions are fixed and listed here. The pieces
// are fetched the first time it opens (GET /api/jump) and kept for the page.
// The rail's "Jump to…" opens it with an event, `umtool:jump`.
+//
+// COMMANDS (lane palette, L8a): every umtool verb the registry offers as a
+// form (lib/cli/verbs.mjs, GET /api/cli), matched on its verb and summary once
+// 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.
// ---------------------------------------------------------------------------
export const JUMP_EVENT = "umtool:jump";
-type Item = { id: string; section: "Places" | "Tools" | "Create" | "Pieces"; label: string; hint: string; href: string };
+type Item = { id: string; section: "Places" | "Tools" | "Create" | "Pieces" | "Commands"; label: string; hint: string; href: string; verb?: string };
type PieceRow = { id: string; title: string; href: string; kind: string; site: string | null; stage: string; lifecycle: string };
const FIXED: Item[] = [
@@ -73,6 +81,29 @@ const FIXED: Item[] = [
const words = (q: string) => q.toLowerCase().split(/\s+/).filter(Boolean);
+/** Each letter of `w` in `s`, in order: "tlins" finds "timeline insert". */
+const subsequence = (w: string, s: string) => {
+ let i = 0;
+ for (const ch of s) if (ch === w[i]) i += 1;
+ return i === w.length;
+};
+
+/** How well a verb answers the words typed: 0 is not at all. */
+function commandScore(v: CliVerb, w: string[]): number {
+ const verb = v.verb.toLowerCase();
+ const hay = `${verb} ${v.summary.toLowerCase()}`;
+ let score = 0;
+ for (const x of w) {
+ if (verb.startsWith(x)) score += 4;
+ else if (verb.split(" ").some((part) => part.startsWith(x))) score += 3;
+ else if (verb.includes(x)) score += 2;
+ else if (hay.includes(x)) score += 1;
+ else if (x.length >= 3 && subsequence(x, verb.replace(/[ -]/g, ""))) score += 0.5;
+ else return 0;
+ }
+ return score;
+}
+
export default function JumpPalette() {
const router = useRouter();
const dialog = useRef<HTMLDialogElement>(null);
@@ -85,10 +116,14 @@ export default function JumpPalette() {
const [error, setError] = useState<string | null>(null);
// 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 [form, setForm] = useState<CliVerb | null>(null);
const show = useCallback(() => {
setQ("");
setAt(0);
+ setForm(null);
setOpen(true);
}, []);
@@ -139,7 +174,33 @@ export default function JumpPalette() {
};
}, [open, pieces]);
+ // The verbs, and what this page is about, each time it opens (the page may have changed).
+ useEffect(() => {
+ if (!open) return;
+ let live = true;
+ const path = `${window.location.pathname}${window.location.search}`;
+ fetch(`/api/cli?path=${encodeURIComponent(path)}`, { cache: "no-store" })
+ .then((r) => (r.ok ? r.json() : Promise.reject(new Error(`HTTP ${r.status}`))))
+ .then((j: { verbs: CliVerb[]; context: CliContext }) => {
+ if (!live) return;
+ setVerbs(j.verbs);
+ setCtx(j.context);
+ })
+ .catch(() => live && setVerbs((v) => v ?? []));
+ return () => {
+ live = false;
+ };
+ }, [open]);
+
const items = useMemo(() => {
+ const commandsOnly = q.trimStart().startsWith(">");
+ const cw = words(commandsOnly ? q.trimStart().slice(1) : q);
+ const commands = (verbs ?? [])
+ .map((v) => ({ v, s: cw.length ? commandScore(v, cw) : 1 }))
+ .filter((x) => x.s > 0)
+ .sort((a, b) => b.s - a.s || a.v.verb.localeCompare(b.v.verb))
+ .map(({ v }): Item => ({ id: `cmd:${v.verb}`, section: "Commands", label: v.verb, hint: v.summary, href: "", verb: v.verb }));
+ if (commandsOnly) return commands.slice(0, 80);
const all: Item[] = [
...FIXED,
...(pieces ?? []).map(
@@ -154,6 +215,7 @@ 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 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)));
// A label that starts with what was typed first, then the rest, each in
@@ -162,8 +224,10 @@ export default function JumpPalette() {
return [
...hits.filter((it) => it.label.toLowerCase().startsWith(first)),
...hits.filter((it) => !it.label.toLowerCase().startsWith(first)),
- ].slice(0, 60);
- }, [q, pieces]);
+ ]
+ .slice(0, 60)
+ .concat(cmds);
+ }, [q, pieces, verbs]);
useEffect(() => {
list.current?.querySelector<HTMLElement>(`[data-jump-index="${at}"]`)?.scrollIntoView({ block: "nearest" });
@@ -171,6 +235,11 @@ export default function JumpPalette() {
const go = (it: Item | undefined) => {
if (!it) return;
+ if (it.verb) {
+ const v = verbs?.find((x) => x.verb === it.verb);
+ if (v) setForm(v);
+ return;
+ }
setOpen(false);
router.push(it.href);
};
@@ -182,9 +251,25 @@ export default function JumpPalette() {
data-ready={ready ? "" : undefined}
aria-label="Jump to"
onClose={() => setOpen(false)}
- className="ui-dialog mx-auto mb-auto mt-[12vh] w-[min(640px,calc(100vw-32px))] rounded-[3px] border border-seam-2 bg-panel p-0 text-text shadow-2xl"
+ className={cn(
+ "ui-dialog mx-auto mb-auto mt-[12vh] rounded-[3px] border border-seam-2 bg-panel p-0 text-text shadow-2xl",
+ form ? "w-[min(780px,calc(100vw-32px))]" : "w-[min(640px,calc(100vw-32px))]",
+ )}
>
- {open && (
+ {open && form && (
+ <div className="flex h-[76vh] max-h-[76vh] flex-col">
+ <CommandForm
+ key={form.verb}
+ row={form}
+ ctx={ctx}
+ onBack={() => {
+ setForm(null);
+ setTimeout(() => input.current?.focus(), 0);
+ }}
+ />
+ </div>
+ )}
+ {open && !form && (
<div className="flex max-h-[70vh] flex-col">
<div className="flex items-center gap-2 border-b border-seam px-3.5 py-2.5">
<span aria-hidden="true" className="font-mono text-muted-2">
@@ -199,7 +284,7 @@ export default function JumpPalette() {
aria-controls="jump-list"
aria-activedescendant={items[at] ? `jump-${at}` : undefined}
aria-label="Jump to a piece, place, tool or create action"
- placeholder="Jump to a piece, place, tool…"
+ placeholder="Jump to a piece, place, tool… or > a command"
onChange={(e) => {
setQ(e.target.value);
setAt(0);
@@ -239,7 +324,7 @@ export default function JumpPalette() {
i === at && "bg-panel-2 text-text before:absolute before:inset-y-1 before:left-0 before:w-[3px] before:bg-signal before:content-['']",
)}
>
- <span className="min-w-0 truncate">{it.label}</span>
+ <span className={cn("min-w-0 truncate", it.verb && "font-mono text-[12.5px]")}>{it.verb ? `umtool ${it.label}` : it.label}</span>
<span className="ml-auto min-w-0 shrink truncate font-mono text-[11px] text-muted-2">{it.hint}</span>
</div>
</li>
@@ -253,6 +338,9 @@ export default function JumpPalette() {
<span>
<kbd>enter</kbd> open
</span>
+ <span>
+ <kbd>></kbd> commands
+ </span>
{pieces === null && <span>reading pieces…</span>}
{error && <span className="text-reject-text">{error}</span>}
</div>
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -1705,6 +1705,23 @@ The files: `<out>/<slug>.<name>.mp4` and `<out>/variants.json`; `<out>` is the p
`preview.mp4`); a take with only its `preview.mp4` is encoded from that (`--source`). A flagged clip is fixed with its `audio.offset` (the sign: a clip whose sound is early, a
negative lag, needs a positive offset), then a build.
+## ⌘K commands (every verb a form)
+
+The other way round: every `umtool` verb the registry (`umtool/lib/cli/verbs.mjs`) marks `ui: "form"` is a form in
+the ⌘K palette, so a verb with no button of its own still has a UI path.
+
+| What | In umtool | From a terminal | Over HTTP |
+|---|---|---|---|
+| the verbs | ⌘K, type (`>` first: commands only); each row `umtool <verb>` and what it does | `umtool help`; [cli.md](cli.md), "Every verb" | `GET /api/cli` (`verbs`) |
+| one verb's form | choose it: its arguments, the page's project (and the clip, post or take its address names) filled in | the line under the form, **Copy as CLI** | — |
+| run it | **Run** (a verb that renders: **Queue it**, the durable queue): its state and live log under the form | that line | `POST /api/cli {verb, values}` from the app's own page only; `GET /api/cli?job=<id>` / `?qid=<qid>` |
+
+The server builds the argv from the row's schema (`lib/cli/argv.mjs`, the same function the Copy as CLI line comes
+from) and refuses a verb with no form (`ui: "none"`, its reason in cli.md), a value its schema refuses, a page of
+another site, and a body carrying a raw argv -- `app/api/queue/route.ts` still never adds a step from a page. A new
+verb gets its row there (`verbs.test.mjs` fails, naming it, until it has one) and its help lines in
+`lib/cli/groups.mjs`; `node umtool/lib/cli/docs.mjs` rewrites cli.md's generated section.
+
## Reading them back
`umtool show <p>` prints a **knobs** block — each clip's claim knobs, audio and blur (which clip stamps), the stamp's