diff --git a/CHANGELOG.md b/CHANGELOG.md index d05bb6201..c6ea47c84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ### Fixes & Improvements - **Git commands stay on the folder's own repository.** A host daemon started from a Git hook or with `GIT_DIR` set in its environment no longer runs Git status, file search, worktree, clone or pool preparation against that other repository. The Git panel of a bare repository now reports "not a Git repository" instead of failing. On Windows pool workers, a long creation ID no longer makes preparation fail on Git's path-length limit, and the reported CPU busy time no longer counts interrupt time twice. +- **Multiple-choice questions show which options are already checked.** When omp asks one checkbox question at a time, each option now shows ☑ or ☐, and screen readers announce "checked" or "not checked". Before, every option looked unchecked, so tapping an option the agent had pre-checked unchecked it instead. In the composer, tapping a checkbox option now toggles it at once instead of waiting for **Next**, so choosing **Done selecting** next can no longer drop it. This needs an omp that sends checkbox state on `select` requests (can1357/oh-my-pi#18929); older omp versions show the options as before. - **Reuse unchanged chat Markdown during streaming.** Markdown bodies skip rendering when their props are unchanged, while relevant tool-result changes still refresh their message. Back/forward session navigation requests the selected session instead of downloading the full session list. - **Listing files in a folder that is not a Git repository no longer leaves a `git` process running in it.** The @-mention and file-search index asks Git first; when the folder is not a repository it now waits for both Git queries to exit before falling back to reading the folder. A leftover `git` process could briefly keep Windows from deleting or renaming that folder. - **Dollar amounts no longer render as math.** In text such as “$5 and $10”, the span between the two dollar signs turned into glued italic formula text. Single-dollar math now follows Pandoc's rule: the opening `$` must be followed by a non-space, and the closing `$` must be preceded by a non-space and not followed by a digit. `$x^2$` still renders as math. diff --git a/components/ExtensionDialog.test.mjs b/components/ExtensionDialog.test.mjs index 85b7de934..fc9c2ae2b 100644 --- a/components/ExtensionDialog.test.mjs +++ b/components/ExtensionDialog.test.mjs @@ -2,7 +2,7 @@ import "../tests/setup-dom.mjs"; import assert from "node:assert/strict"; import test, { afterEach } from "node:test"; import React from "react"; -const { cleanup, fireEvent, render, screen } = await import("@testing-library/react/pure.js"); +const { cleanup, fireEvent, render, screen, waitFor } = await import("@testing-library/react/pure.js"); const { ExtensionDialog } = await import("./ExtensionDialog.tsx"); afterEach(cleanup); @@ -73,6 +73,102 @@ test("question selection survives request replay but is cleared for the next que } }); +test("omp's checkbox select shows which options are already checked", async () => { + const request = { + type: "extension_ui_request", + id: "jobs-1", + method: "select", + title: "(2 selected) Choose enabled jobs", + options: ["pytest", "go-quality", "lint", "Other (type your own)", "✓ Done selecting"], + selectionMarker: "checkbox", + checkedIndices: [0, 1], + markableCount: 3, + }; + const view = render(React.createElement(ExtensionDialog, { request, onRespond: () => {} })); + try { + // Accessible names carry the state; the visible glyph is aria-hidden. + for (const name of ["pytest, checked", "go-quality, checked", "lint, not checked", "Other (type your own)", "✓ Done selecting"]) { + screen.getByRole("button", { name }); + } + assert.equal(screen.getByRole("button", { name: "pytest, checked" }).textContent, "☑pytest, checked"); + assert.equal(screen.getByRole("button", { name: "lint, not checked" }).textContent, "☐lint, not checked"); + } finally { + view.unmount(); + } +}); + +test("attached checkbox select sends each toggle at once, so Done cannot replace it", async () => { + const request = { + type: "extension_ui_request", + id: "jobs-2", + method: "select", + title: "Choose enabled jobs", + options: ["pytest", "lint", "✓ Done selecting"], + selectionMarker: "checkbox", + checkedIndices: [], + markableCount: 2, + }; + const responses = []; + const dialog = (current) => React.createElement(ExtensionDialog, { + request: current, + onRespond: (answered, response) => { + responses.push({ id: answered.id, ...response }); + return Promise.resolve(true); + }, + attached: true, + }); + const view = render(dialog(request)); + try { + fireEvent.click(screen.getByRole("button", { name: "lint, not checked" })); + assert.deepEqual(responses, [{ id: "jobs-2", value: "lint" }]); + // omp takes one answer per request: the options are disabled until the next request arrives. + assert.equal(screen.getByRole("button", { name: "pytest, not checked" }).disabled, true); + fireEvent.click(screen.getByRole("button", { name: "pytest, not checked" })); + assert.equal(responses.length, 1); + + // The next request carries the toggle; the action row waits for Next. + view.rerender(dialog({ ...request, id: "jobs-3", checkedIndices: [1] })); + fireEvent.click(screen.getByRole("button", { name: "✓ Done selecting" })); + assert.equal(responses.length, 1); + fireEvent.click(screen.getByRole("button", { name: "Next" })); + assert.deepEqual(responses[1], { id: "jobs-3", value: "✓ Done selecting" }); + } finally { + view.unmount(); + } +}); + +test("a checkbox toggle that fails to send can be tried again", async () => { + const request = { + type: "extension_ui_request", + id: "jobs-4", + method: "select", + title: "Choose enabled jobs", + options: ["pytest", "✓ Done selecting"], + selectionMarker: "checkbox", + checkedIndices: [], + markableCount: 1, + }; + const responses = []; + const results = [false, true]; + const view = render(React.createElement(ExtensionDialog, { + request, + onRespond: (answered, response) => { + responses.push({ id: answered.id, ...response }); + return Promise.resolve(results.shift()); + }, + attached: true, + })); + try { + fireEvent.click(screen.getByRole("button", { name: "pytest, not checked" })); + await waitFor(() => assert.equal(screen.getByRole("button", { name: "pytest, not checked" }).disabled, false)); + fireEvent.click(screen.getByRole("button", { name: "pytest, not checked" })); + assert.deepEqual(responses, [{ id: "jobs-4", value: "pytest" }, { id: "jobs-4", value: "pytest" }]); + assert.equal(screen.getByRole("button", { name: "pytest, not checked" }).disabled, true); + } finally { + view.unmount(); + } +}); + test("ExtensionDialog masks sensitive input and toggles visibility", async () => { const request = { type: "extension_ui_request", diff --git a/components/ExtensionDialog.tsx b/components/ExtensionDialog.tsx index e567cc5bb..61145756a 100644 --- a/components/ExtensionDialog.tsx +++ b/components/ExtensionDialog.tsx @@ -235,7 +235,8 @@ export function ExtensionDialog({ attached = false, }: { request: ExtensionDialogRequest; - onRespond: (request: ExtensionDialogRequest, response: ExtensionDialogResponse) => void; + /** Resolves `false` when the answer could not be sent, so the panel takes another answer. */ + onRespond: (request: ExtensionDialogRequest, response: ExtensionDialogResponse) => void | Promise; /** Render as a composer panel instead of a full-chat overlay. */ attached?: boolean; }) { @@ -247,6 +248,10 @@ export function ExtensionDialog({ // `pointerType` of the latest press: the pointer media query only describes // the primary pointer, not the one pressing now. const pressPointerRef = useRef(null); + // omp takes one answer per request id and the panel stays up until the next request arrives, so the + // select controls are disabled in that window instead of sending a tap omp would silently drop. + const [answeredId, setAnsweredId] = useState(null); + const awaitingNext = request.method === "select" && answeredId === request.id; const [askDrafts, setAskDrafts] = useState(() => initialAskDrafts(request)); const viewportMaxHeight = useViewportMaxHeight(); const { touchTargets } = useTouchTargets(); @@ -278,9 +283,16 @@ export function ExtensionDialog({ // task, so the phone keyboard closes once instead of flashing as the // focused field disappears from under it. const respond = (response: ExtensionDialogResponse) => { + if (request.method === "select") { + if (awaitingNext) return; + setAnsweredId(request.id); + } const active = document.activeElement; if (active instanceof HTMLElement && panelRef.current?.contains(active)) active.blur(); - onRespond(request, response); + const id = request.id; + void Promise.resolve(onRespond(request, response)).then((sent) => { + if (sent === false) setAnsweredId((current) => current === id ? null : current); + }); }; const cancel = () => respond({ cancelled: true }); @@ -415,13 +427,19 @@ export function ExtensionDialog({ )} {request.method === "select" && (
- {request.options.map((option) => { + {request.options.map((option, index) => { const selected = selectedOption === option; + const checkbox = request.selectionMarker === "checkbox" && index < (request.markableCount ?? request.options.length); + const checked = checkbox && (request.checkedIndices?.includes(index) ?? false); + // A checkbox toggle goes out at once even when attached: staging it for Next would let the + // next row (often "Done selecting") silently replace it, and a stray toggle is undone by one tap. + const stage = attached && !checkbox; return ( ); })} @@ -712,7 +732,7 @@ export function ExtensionDialog({ ) : (request.method === "select" && attached) || request.method === "ask" ? (