diff --git a/docs/session-extras.md b/docs/session-extras.md index eb58f6b..ce345bc 100644 --- a/docs/session-extras.md +++ b/docs/session-extras.md @@ -7,7 +7,7 @@ The smaller conveniences, each its own extension. - **Todo list** ([`extensions/todo.ts`](../extensions/todo.ts)): compaction-safe task tracking with the full list above the editor, as Claude Code shows its task list whenever a task is created or updated. `/todos-widget off|compact|full` hides the widget, shows counts and the active task on one line, or restores the full panel; it needs the terminal UI, since RPC mode draws no widgets. Empty lists stay hidden in every mode; `/todos` always opens the complete list. Display mode stays in effect across tree navigation and compaction; `/reload`, a new session, resume and fork reset it to `full`. **Divergence:** Claude Code collapses the list with `Ctrl+T` and saves that choice across sessions, and its collapsed form is the active task in the spinner line with the next one below it; `/todos-widget` and its one-line form are pi-code's own. - **Checkpoints / rewind** ([`extensions/git-checkpoint.ts`](../extensions/git-checkpoint.ts)): shadow-repo snapshots scoped to the files the session's edit tools touched, so checkpoint size tracks the edits rather than the size of the working directory; ignored files stay out even when edited. Restore overwrites checkpointed files, puts back a file the session first edited after the checkpoint as it was before that edit, and keeps files created later; 100 per session, repos pruned after 30 days. `CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING` skips the pre-run snapshot entirely. - **AskUserQuestion** ([`extensions/question.ts`](../extensions/question.ts)): 1-4 questions per call, each with `header` and 2-4 options, single- or `multiSelect`, plus free-text. Multiple questions share a TUI form: Left/Right or Tab/Shift+Tab move between the questions and a final Submit review, stopping at either end as in Claude Code. Navigation preserves answers, checkbox selections and text drafts; it does not select a highlighted option. Entering a question, answered or not, focuses its first row, as in Claude Code. A confirmed single-select answer shows a ✔ in the success colour: after the option's label, which also turns that colour, even with the focus on it, or after the text in the free-text row, as in Claude Code. The free-text row keeps its ✔ while its text is edited or deleted without Enter, deleted text showing the placeholder with the ✔, as Claude Code does, although the confirmed text stays the answer in the review and the result. Text typed in the free-text row stays there when an option is confirmed instead, and is not sent, as in Claude Code; a remote responder's option answer keeps it too. Checkboxes read `[✔]` in the success colour when checked and `[ ]` when not, as in Claude Code. **Divergence:** Claude Code draws every row number in grey; pi-code gives the number the colour of its label, and the success colour on a confirmed free-text row. The free-text option is an inline field: moving the highlight onto it starts typing, Left/Right move the cursor, Up/Down leave the row and keep the draft, and no key switches questions until typing stops. Enter confirms an answer and advances. A `multiSelect` question uses Space to toggle and Enter to confirm. **Divergence:** Claude Code toggles with Enter or Space and confirms on a separate Next/Submit row below the options. On the TUI overlay it also has the inline free-text row, whose checkbox is checked exactly while it has text; Space types there and never toggles it, and the typed text is sent after the checked labels as a separate `User wrote:` line. Enter with nothing checked and no text leaves it unanswered, as in Claude Code, clearing any earlier answer, and on a lone question it does nothing. The tab bar marks each question answered (☒) or not (☐). The Submit review lists the answered questions, warns when any are unanswered, and offers Submit answers or Cancel (Up/Down, Enter); Cancel is the same whole-call cancel as Esc. Once a `multiSelect` question is confirmed, every toggle and every edit of its text updates its answer, as in Claude Code, so what is shown is what is submitted. A confirmed single-select text answer changes only when Enter confirms the edited text, as in Claude Code. A confirmed single-select answer wins over a text draft left on the same question. Submitting marks unanswered questions explicitly as skipped while preserving confirmed answers and, for an unconfirmed `multiSelect` question, its checked options and typed text. Single-select text that Enter did not confirm is not an answer, as in Claude Code. Claude Code keeps the given answers on a partial submit too. **Divergence:** it leaves the unanswered questions out of the result, and reports that the user did not answer only when nothing was answered; pi-code names each unanswered question as skipped. The keys match Claude Code's [tab keybindings](https://code.claude.com/docs/en/keybindings#tabs-actions). Enter on a blank single-select field cancels the whole call, as Esc does, as in Claude Code. Esc cancels the whole call, from the field too, and discards every answer; the model gets a single cancellation. On the TUI overlay, Chat about this, below the options on every question, ends the call and sends the model Claude Code's clarify text with each question and the answer Submit would send: a `multiSelect` question's checks and text count as they stand, a single-select question's text only once Enter confirms it. **Divergence:** Claude Code returns that text as a rejected tool call, behind its rejection preamble "…To tell you how to proceed, the user said:", which credits its own template to the user; pi-code sends the clarify text alone. The RPC fallback has no Chat row, asks questions in sequence, and a cancel there also cancels the whole call. Honors `askUserQuestionTimeout` (`60s`/`5m`/`10m`, scope "User or managed" — a project's own settings.json cannot set it), read from managed settings then `~/.claude/settings.json`. On the TUI overlay only: a visible countdown for the last 20 seconds, any keypress restarting the timer, and on firing, confirmed answers are reported as on a normal submit, each unconfirmed question submits only its checked options, including a filled-in `multiSelect` text row, which the model gets apart from the checked labels (an unconfirmed highlight or single-select text draft is not sent), and the model is told once per call that the user may be away, even when every question was answered, so it proceeds on its own judgment rather than reading it as a cancel. **Not implemented:** restarting the timer on terminal focus-in, since pi's TUI input stream is not confirmed to carry that escape sequence; and the timeout on the RPC dialog-primitive fallback (no terminal, so no keypress or countdown to drive it); there a `multiSelect` question takes one option, since the dialog's select returns a single choice. - Remote responders (a chat bridge, for example): on the TUI each question is first emitted on `pi.events` as `pi-code:question:v1`, typed as `RemoteQuestionOffer` in the same file. A listener that calls `claim()` synchronously during emission receives the only settle handle. The overlay opens either way and the first answer, local or remote, wins. Answers are 1-based option indices, free text only when `allowFreeText`, or `cancel`; `pass` or an invalid reply withdraws the remote side and leaves the overlay open. `touch()` restarts the overlay idle timer, and the offer's `signal` aborts once the question is settled, after which replies are rejected. A call with several questions differs from a single one. Every question is offered when the form opens, so up to four offers are live at once; each carries `batch` (`id` shared by the call's offers, 1-based `index`, `total`), which a single question's offer omits. An offer stays live while its question is unanswered, whichever question has focus; a remote answer to another question saves there without moving focus. The settle handle returning `true` means the answer was accepted, not that it is final: the local user can still change it until the form is submitted. A remote `cancel` on any offer cancels the whole call. Every open offer aborts when the form closes. A remote answer that leaves every question answered submits the form without a terminal review, whether the other answers were local or remote; while the highlight is on a field holding text that Enter has not confirmed, the form stays open instead. + Remote responders (a chat bridge, for example): on the TUI each question is first emitted on `pi.events` as `pi-code:question:v1`, typed as `RemoteQuestionOffer` in the same file. A listener that calls `claim()` synchronously during emission receives the only settle handle. The overlay opens either way and the first answer, local or remote, wins. Answers are 1-based option indices, free text only when `allowFreeText`, or `cancel`; `pass` or an invalid reply withdraws the remote side and leaves the overlay open. `touch()` restarts the overlay idle timer, and the offer's `signal` aborts once the question is settled, after which replies are rejected. A call with several questions differs from a single one. Every question is offered when the form opens, so up to four offers are live at once; each carries `batch` (`id` shared by the call's offers, 1-based `index`, `total`), which a single question's offer omits. An offer stays live while its question is unanswered, whichever question has focus; a remote answer to another question saves there without moving focus. The settle handle returning `true` means the answer was accepted, not that it is final: the local user can still change it until the form is submitted. A remote `cancel` on any offer cancels the whole call. Every open offer aborts when the form closes. A remote answer that leaves every question answered submits the form without a terminal review, whether the other answers were local or remote; while the highlight is on another question's field holding text that Enter has not confirmed, the form stays open instead. A remote answer to the question being typed in answers it, and the typed text is not sent. - **Notifications** ([`extensions/notify.ts`](../extensions/notify.ts)): terminal notification when a turn ends (OSC 777 / Kitty OSC 99 / Windows toast); honors `preferredNotifChannel` (`terminal_bell`, `notifications_disabled`, `iterm2_with_bell`, else desktop) from user settings or the `--settings` flag; fires only when you appear to be away, approximated by turn duration since pi exposes no terminal-focus signal. - **Think keyword** ([`extensions/thinking.ts`](../extensions/thinking.ts)): `ultrathink` raises reasoning to the max for one turn, matched on a word boundary, only ever raising, restored once the turn settles. It is the only keyword, as in Claude: `think`, `think hard`, `think more` and similar phrases pass through as ordinary prompt text. **Divergence:** Claude adds an in-context instruction and leaves the API effort level unchanged; pi has no separate in-context channel for this and its thinking level is how deeper reasoning is requested, so the keyword moves the level and restores it after. - **Session title** ([`extensions/session-title.ts`](../extensions/session-title.ts)): names a new session from its first message with a single model call; never overwrites an existing name, best-effort, at most once per session. `CLAUDE_CODE_DISABLE_TERMINAL_TITLE` skips it, which also leaves the terminal/tab title untouched since `setSessionName` is the only sink for both. diff --git a/tests/question.test.ts b/tests/question.test.ts index cd43949..7451a41 100644 --- a/tests/question.test.ts +++ b/tests/question.test.ts @@ -2508,6 +2508,28 @@ describe('question batch lifecycle', () => { expect(submitted.content[0].text, 'The finished text and the remote answer should be sent').toBe('First?\nUser wrote: half typed\n\nSecond?\nUser selected: 2. Beta') }) + it('should submit when the remote answer is for the question being typed in, without the typed text', async () => { + const replies: Array> = [] + const tool = setupRemote((offer) => { + replies.push(offer.claim()) + }) + const { overlay, result } = openOverlayWith(tool, { + questions: [ + { question: 'First?', options: OPTIONS }, + { question: 'Second?', options: OPTIONS }, + ], + }) + + replies[1]?.({ action: 'answer', indices: [1] }) + overlay.handleInput(RAW.down) + overlay.handleInput(RAW.down) + overlay.handleInput('maria') + replies[0]?.({ action: 'answer', indices: [2] }) + const submitted = await result + + expect(submitted.content[0].text, 'The remote answer replaces the text being typed in that question').toBe('First?\nUser selected: 2. Beta\n\nSecond?\nUser selected: 1. Alpha') + }) + it('should stay open when a remote answer completes the batch while a confirmed text answer is being edited', async () => { const replies: Array> = [] const tool = setupRemote((offer) => {