Repository navigation
fix(chat): check for a masked prompt before typing an immediate send's OpenCode skill - #3174
Conversation
…fore a write A queued message's last checks before the paste compared only the PID in front, so a process that took the agent's PID (or whose known start became unreadable) passed, and a masked prompt that came up during that last process read got the paste or the Enter. - stillInFront also compares the bound process start after the PID is seen - samePendingIdentity refuses a known start of the same PID that can no longer be read - the screen is read once more right before the paste and the Enter; the window left is that read and herdr's write, as herdr has no compare-and-write
… checks Review round on #3172 (omo, Codex): - stillInFront checks the bound PID, so a bound process gone from the front is refused, and compares its start last, after Claude's session read, through samePendingIdentity (platform leeway and its mocks apply) - the start is compared once more after the last screen read - Pi's last check after its receipt anchor passes the bound identity - OpenCode skill keys and Codex steering's Escape re-read the screen for a masked prompt right before they are written
… as unknown The stricter identity check failed a Pi receipt for good when the agent's start was unreadable for a moment at the same PID. Reconciliation now reads it again later; only a write is refused on an unknown start.
…rocess start OpenCode's skill-accept Tab is decided on a screen read after revalidate. typeWithSkills now hands that screen to a beforeKey hook right before the key: the pending path refuses a masked prompt on it and compares the bound process start (no further herdr read).
…a launch's unknown start - the skill-accept Tab's own screen is the viewport, which may be scrolled: the live screen is read once more and the start compared before the key - a launch-bound first message whose agent's start reads as unknown for the same PID waits for the next read instead of being held as replaced
…ng on any status since its read From CodeRabbit's review: - a message whose deadline passed during the final reads before the paste is not typed (submit_timeout) - Codex steering's Escape compares the status from before its screen read - the birth-guard tests use starts outside macOS's one-second leeway - the changelog says a refused message stays queued when nothing was typed
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Review round on 88b51bc: omo review CLEAR; Codex (adversarial) found two HIGHs and one LOW, all reproduced with its own tests and fixed in the next commit:
Note for #3172: |
|
Re-review at 80a23b6: omo review CLEAR. A targeted Codex re-check confirmed the two HIGHs and the LOW above are closed (no writes, It found one more HIGH, in the shared recognizer rather than this PR: CodeRabbit skipped this PR (base is not the default branch); the omo and Codex reviews above stand in for it. |
…th a leading space (#3177) Fixes #3175. ## What `secretPrompt` (shared/secret-prompt.ts) is what keeps queued messages, typed input and the immediate send's OpenCode skill text out of a password prompt. It missed a masked prompt wrapped over several rows in three ways: - **Leading space dropped**: joining a row onto the one above called `trimStart()` on the joined text, so a wrapped row starting with a space (`" '/tmp/a-ver"`) lost it and the prompt no longer matched. Any prompt wrapped into 3+ rows where a later row starts with a space was missed (e.g. `Enter passphrase for key '/tmp/key':` at 10 columns). - **Rows measured by string length**: a row is only joined when it reaches the right edge, but a row of Korean/Chinese/Japanese text fills 80 columns with far fewer than 80 characters, so a CJK key path at 80 or 20 columns was never joined. ## How - Join rows without trimming (the candidate is still trimmed before matching). - Measure rows in terminal columns with a small `displayWidth`, per grapheme cluster (East Asian Wide/Fullwidth or emoji presentation = 2, combining/zero-width only = 0, else 1; code points where `Intl.Segmenter` is missing), and pad to the edge by columns. A wide character that did not fit leaves the last cell empty, which is padded as a space exactly as xterm's `translateToString` reads the wrapped row in the browser, so the browser and the server keep agreeing on the prompt text (`server/core/input.ts` compares them). - `displayWidth` is exported so callers that guess the width from the row above (#3174) can measure it the same way. ## Validation - Failing-first: the new cases in `shared/secret-prompt.test.ts` fail on main (leading space, 4 rows at 10 columns, CJK at 80 and 20 columns, emoji and a ZWJ emoji sequence) and pass with the fix. - Masked-prompt / pending-input tests: `bun test shared/secret-prompt.test.ts server/pending-input.contract.test.ts server/pane-routes.test.ts server/submit.contract.test.ts server/terminal-insert.contract.test.ts server/prompt.test.ts server/opencode-first-message.contract.test.ts server/core/status.test.ts` (isolated test session). - `bun run check fast`. - Skipped: browser regressions (no UI change; `src/lib/useTerminalMount.ts` only calls the shared function). ## Known limits (pre-existing, not changed here) - A row whose text ends in two or more spaces before the wrap is still not joined (the server's row text is trimmed); same on main. - Two separate CJK output lines that happen to fill a row exactly can be read as one wrapped line (`Password for 管理者` + `is stored here:` at 19 columns): input is refused, never typed.
…et go of the watch on a first refusal
80a23b6 to
55d3d91
Compare
|
Merge note (merge pass) at head 55d3d91:
|
Summary
An immediate (not queued) chat message that names an OpenCode skill is typed key by key (
typeWithSkillsinserver/core/composer.ts). That path rechecked only the pane, its session andblockedstate before each write, so the skill's accept key, the rest of the message and its Enter could go into a masked password prompt that came up on the terminal. #3172 added a masked-prompt check to the queued path's skill typing (beforeKey+ a live-screen read); this routes the immediate path through the same guard:revalidate(run before every write and before the Enter) now also reads the live screen and refuses withagent_blockedwhen a masked prompt is showing.beforeKey: the screen it was decided on (escapes stripped), then the live screen, so a scrolled viewport that still shows the autocomplete row cannot hide a prompt below.maskedPromptAtAnyWidthtries every width at which the row above the last reaches the right edge (the only rowssecretPromptjoins), measured in terminal columns withdisplayWidth(fix(shared): recognize a masked prompt wrapped by display width or with a leading space #3177), so a wrapped prompt is refused at any width, wide characters included.Fail closed: nothing typed -> the send is refused (
agent_blocked); part typed -> the existingsubmit_partialanswer (chat text kept, check the terminal). Everything else on the immediate path is unchanged; agent-only messages still go throughagent.prompt.Stacked on #3172 (
fix/pending-birth-guard); GitHub retargets it tomainonce #3172 merges.Validation
server/core/immediate-skill-guard.test.ts(5 tests). The first three failed on fix(pending): fail closed on a reused PID and a late masked prompt before a write #3172's earlier head 88f7019 (writes were@effect, Tab, " ", Enter); the wrapped-prompt and watch cases failed on this PR's first commit; the wide-character case fails with the row above measured by.lengthand passes withdisplayWidth.agent_blockedand a cancelled watch.bun run check fastat the head: green (unit 12745 pass, 0 fail; typecheck, build).