Compare commits

..
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 550f85e1ae fix(app): keep an open keyboard open when you swipe the browser terminal
A touch drag blurred the terminal input to stop Android from reopening a
keyboard that Back had hidden. It also closed a keyboard that was open,
so scrolling while typing needed a new tap. Blur only when the visual
viewport shows no software keyboard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 13:18:32 +00:00
c016c161cc fix(app): keep a touch drag from refocusing the browser terminal
Builds on the contributor commit for the Android browser keyboard.
A touch drag now keeps the dismissed keyboard closed, and a tap
still opens it.

- Keep calling onFocus on every pointer-down, so a touch drag still
  marks the terminal as focused and claims its size as before. Only
  the input focus waits for a tap.
- Move the test tap into a helper.
- Leave the native fullscreen scrolling change, its tests, the
  inertial gesture check, and the QA video out of this branch. They
  belong to #7762.

Refs #9481

Co-authored-by: Tony <liutuo@outlook.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 12:30:33 +00:00
Tony 83e1f0b041 fix(terminal): restore mobile scrolling and touch keyboard focus 2026-11-19 12:28:42 +00:00
Matt Pilsbury 4929ed5a0f fix(codex): restore subagent status after reopen and rewind (#10171)
* fix(codex): settle historical collaboration subagents

* fix(codex): reconcile replayed collaboration with child turns
2026-11-19 12:07:48 +00:00
Mohamed Boudra c951de2332 Keep waiting heartbeats out of Running (#10216)
* fix(agents): keep waiting heartbeats out of Running

* fix(protocol): keep the work count default as a wire contract

* test(app): verify heartbeat status before, during, and after its turn
2026-11-19 18:45:40 +07:00
paseo-bot[bot]andClaude Opus 5.5 4fb95106e7 Notify once while an agent's finish is unread, not on each turn it starts on its own (#10200)
* fix(server): notify once while an agent's finish is unread

Since v0.16.0, a turn that an agent starts on its own cleared the
agent's unread "finished" attention. Every such turn that then ended
raised a new "finished" notification. A Claude Code agent that reacts
to each event of a Monitor or a background task starts one turn per
event, so the user got a notification every few seconds.

A turn that the agent starts on its own now clears only error
attention, which is what the earlier change intended. An unread finish
stays unread, so the next finish does not notify again. After the
user reads the agent, the next finish notifies as before. A prompt
from the user still clears all attention.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(server): notify a repeat finish the user was not told about

The previous commit kept an unread finish across turns that an agent
starts on its own, and the agent manager then sent no attention for
the later finishes. Suppose the user had the agent on screen for the
first finish. The app keeps that finish unread, and no notification
is sent while the agent is on screen. After the user left, no later
finish notified at all.

The agent manager now reports each finish, and marks a finish that
repeats an unread finish. The websocket server owns delivery, so it
records whether it delivered a notification for the unread finish.
A repeat notifies only when nothing was delivered for it yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(server): key the notified unread finish by its attention timestamp

The websocket server recorded only that it had notified for some
finish of an agent. Mark as unread starts a new unread finish without
an attention event, so a later repeat used the record of an older
finish that the user had already read, and sent nothing.

The attention callback now carries the timestamp of the agent's
current unread attention, which identifies the unread finish. The
server stores the timestamp it notified for, and suppresses a finish
only when it belongs to that same unread finish. This replaces the
repeatsUnreadFinish flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:08:01 +00:00
Mohamed Boudra c4e8c17022 Wait for starting file watchers to close during shutdown (#10208)
* fix(server): drain starting file observations during shutdown

Workspace Git aborts starting watchers on shutdown. The observer only tracked completed subscriptions, so close could return while a startup scan was still releasing its resources.

* test(server): verify watcher release during startup shutdown

Use an internal backend adapter to hold startup open and observe watcher release when close returns.

* fix(server): leave startup scan drainage to watcher backends

Both backends already drain their admitted scans. Preserve cleanup for a failed root lookup after the observer takes ownership up front.
2026-11-19 18:07:00 +07:00
Mohamed Boudra 69c6bd7464 Keep the model tooltip closed when opening the picker
Pressing the model picker shortcut now focuses search without opening the button tooltip. Attach picker hints to the shared trigger button so focus inside the picker stays independent.
2026-11-19 17:26:15 +07:00
ad3c490a52 Keep a file view's scroll position when switching Preview and Source (#10195)
* Keep a file view's scroll offset when switching Preview and Source

A file tab rendered either its Preview or its Source, so each switch
unmounted the view on screen and its scroll offset with it. Coming back
started at the top of the file.

Each view now stays mounted once shown and is hidden with RetainedPanel
while the other view shows. The hidden Preview keeps the text it last
showed, so editing in Source does not render it on every change.

Co-authored-by: apple-ouyang <45086632+apple-ouyang@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Assert what the file pane shows, not that the other view unmounted

The Preview and Source views now stay mounted once shown, so the file
editing spec checks the visible heading and a hidden HTML preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Load the HTML preview again in the WebView that shows after a hidden panel

iOS destroys the native WebView of a hidden retained panel and makes a new
one when the panel shows. The navigation guard latched the document per
component mount, so it refused the new WebView's load of the same document
and the preview stayed blank after Source -> Preview. The guard now releases
the latch while its retained panel is hidden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Name the iOS HTML preview as the view that does not keep its offset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Load a changed HTML document in a new preview frame on web

The Preview stays mounted and hidden while Source shows. When the file
changed meanwhile, the Preview got the new document in the same render
that showed it again. Chromium left the reused iframe blank in that case
until the next Source/Preview switch. Key the iframe by its document so
each document loads in a new frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: apple-ouyang <45086632+apple-ouyang@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 09:53:05 +00:00
Mohamed Boudra 120df507a9 Start a workspace in an existing worktree, and branch off or check out any branch or pull request (#10190)
* feat(server): branch off a pull request and list every git worktree

A workspace.create worktree source with action "branch-off" and a
checkoutSource used to check the pull request out, because core took
any change request as a checkout. Branch-off now fetches the pull
request's head into a remote-tracking ref (origin/<head> for a
same-repo head, paseo-pr-<N>/<head> otherwise) and starts the new
branch there, with no upstream and no remote added. A request with no
action still checks the pull request out, as older clients expect.

checkout.worktrees.list returns all git worktrees of the repository,
not only the ones Paseo created, so the New workspace screen can offer
any of them. Bare and prunable entries are left out.

Hosts advertise both through server_info.features: worktreeRefActions
and checkoutWorktreeList. Older hosts ignore the branch-off action on a
pull request, so the app must gate on the flag.

* feat(app): pick an existing worktree, and branch off or check out a ref

Isolation now offers Project directory (was "Local"), New worktree, and
Existing worktree. Existing worktree is a local workspace at the chosen
worktree's path, not a third isolation value, so plugins, preferences, and
the create request still see "local". The list comes from
checkout.worktrees.list, so it includes worktrees Paseo did not create.

The ref picker gains Branches / Pull requests pills and a Branch off /
Check out toggle with a tooltip per action. Branches default to Branch off
and pull requests to Check out. On a host without worktreeRefActions the
toggle is hidden and the defaults apply.

Git keeps a branch in one worktree at a time. Picking a held branch in
Check out mode moves to the worktree that holds it, and creating from a
held branch that was never picked fails with an explanation. Without
this the server would silently check out a "<branch>-1" copy.

* docs: describe Existing worktree and Branch off / Check out

* fix(server): give a fork pull request branch-off a base the repository has

A branch off a fork's pull request stored the fork's head as its base, under
refs/remotes/paseo-pr-<N>. Create PR then asked for a pull request into a
branch the base repository does not have, and the ref piled up in base branch
pickers because no remote owns it. The new branch now starts at the fetched
head, kept under refs/paseo/change-requests/<N>, and its base is the pull
request's base branch. A same-repository branch-off still stacks on the pull
request's branch.

A routed create_workspace with a prNumber and no mode checks the pull request
out again, as before branch-off could start from a pull request.

The worktree list skips a locked worktree whose directory is gone, since it
cannot be opened.

* fix(app): start an existing worktree's agent in that worktree

Existing worktree created the workspace at the worktree, but the composer and
terminal still used the project directory, so the daemon rejected the first
agent as outside the workspace. The screen now derives one working directory
from the isolation and uses it for the workspace, the composer, and the
terminal. A worktree that left the list is no longer a choice.

The ref picker names change requests the way the project's forge does, so a
GitLab project shows Merge requests. The schedule form uses the isolation
labels Project directory and New worktree.

* fix(server): compare a fork pull request branch-off against the remote base

The base was stored as the bare branch name, which resolves to the local branch
first. A local main behind origin/main put upstream commits in the workspace's
changes for its whole life, and a base branch the clone never fetched failed
creation. The base branch is now fetched from origin and stored as its
remote-tracking ref.

* fix(server): take a pull request's base and a checked-out branch from the remote that has them

A fork branch-off fetched its base from origin. In a clone whose base
repository is upstream, origin is the user's fork or missing, so the base was
stale or the create failed. The base now comes from the remote that served the
pull request, and a failed base fetch falls back to the bare branch name.

Check out of a branch that only a remote other than origin has failed with an
unknown branch. The local branch is now created from the one remote-tracking
ref with that name, tracking it, as git does.

The fork branch-off test passes a git identity to commit-tree, which CI
runners do not have.

* fix(server): branch off a pull request from the remote that serves it

A same-repository pull request's head was fetched into refs/remotes/origin.
In a fork clone, upstream serves the pull request and origin is the fork, so
the base refresh replaced the head with the fork's branch of the same name and
the new branch started from code that is not the pull request. The head now
lands under refs/paseo/change-requests/<N>, the branch starts there, and the
base is fetched from the remote that served the head.

A routed create_workspace that branches off a pull request is refused, as it
is on the local host.

* fix(app): branch off a plugin's base ref whatever the branch action

setBaseRef chose the base but kept the user's Check out switch, so a plugin's base became a checkout or a held-branch error. A base is what a new worktree starts from, so setBaseRef switches branches back to Branch off.
2026-11-19 16:31:38 +07:00
paseo-bot[bot]andClaude Opus 5.5 b76533830a test(terminal): wait for a killed worker's processes before cleanup (#10198)
Four worker-terminal-manager tests SIGKILL a terminal worker whose
terminal program runs in the test's temporary home. On Windows that
program ends only when the dead worker's console closes, a moment
later. afterEach then removed the home with a 0.5 s retry budget, and
Windows refuses to remove a directory that is a live process's working
directory, so cleanup failed with EBUSY.

The tests now kill a worker through crashWorker, which records the
worker and its terminal programs. afterEach waits up to 10 s for them
to end before it removes the temporary dirs.

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 09:30:41 +00:00
Mohamed Boudra 68cfad2c8a Add interactive permissions and session history to Antigravity (#10193)
* feat(antigravity): run sessions through the shared ACP provider

Use Antigravity’s ACP server for workspace sessions, mode changes, approvals, and conversation history. Keep existing conversations importable and migrate saved Full access sessions to Default.

* fix(acp): finish delayed history replay before sessions become ready

Keep delayed load updates on the history side of the readiness boundary. Reuse the ACP catalog and configuration mapping to translate legacy Antigravity selections and document the approval requirements for scheduled runs.

* fix(antigravity): preserve Full access in ACP sessions

Keep unattended Antigravity runs working through the shared ACP permission policy. Commit a Full access change only when the session is idle and retire unanswered approvals when a turn ends.

* fix(acp): cancel pending approvals when stopping a turn

Send the approval cancellation when the client asks the agent to stop. Agents that wait for the approval response can then finish the turn, and late replies to closed approvals leave the session usable.
2026-11-19 14:21:12 +07:00
Mohamed Boudra c1f04a8cae Keep Changes available when Git metadata watching fails (#10188)
* fix(server): keep Changes available when Git metadata watching fails

A valid checkout could lose its first comparison when metadata observation exceeded the directory limit. Keep working-tree observation active and share a backing-off metadata sample per Git root so quiet comparisons stay idle.

* fix(server): probe only revisions used by degraded Changes streams

Reuse each comparison's initial Git resolution as the baseline. Batched ref lookups run after subscription setup, stay bounded when the repository has a large ref table, and refresh only comparisons with changed inputs.

* fix(server): report Changes metadata fallback in daemon diagnostics

Log the watcher failure once per root and count comparisons currently using the fallback. Exercise the transition from an active watcher to polling and the release of the last comparison.

* fix(server): keep Changes probes working across Git versions and worktrees

Use line-delimited batch input for older Git versions. Resolve shared refs in the common Git directory so a removed worktree cannot block the remaining comparisons.

* fix(server): isolate invalid revisions in Changes polling

Git aborts a batch when an upstream or reflog expression cannot resolve. Resolve expressions independently so a failed lookup leaves other comparisons current.
2026-11-19 14:17:07 +07:00
Mohamed Boudra 1c479d7b3d Keep finished replies visible across idle notifications (#10135)
* fix(timeline): keep replies visible across idle notifications

Resolve notification membership at the manager's live event boundary. An idle notice gets a display turn without starting a run, and in-flight notices join the open run.

* test(timeline): keep notice paging assertions compatible with async history

* fix(timeline): reuse managed turn assignment for notices

Resolve notices before waiter matching with the same rule used by live persistence. Verify untagged foreground runtime notices through runAgent and idle Pi notices through timeline paging.
2026-11-19 13:15:13 +07:00
Mohamed Boudra 808766ed7f Acknowledge workspace taps promptly and reduce destination mount work (#9887)
* fix(app): acknowledge accepted workspace taps before navigation

Short taps finish before the delayed hold feedback paints, then navigation occupies JS. Paint accepted feedback on the native UI thread while retaining the existing press cancellation and delay rules.

* fix(app): avoid persistent tint on selected docked workspace rows

* perf(app): reduce workspace mount work and narrow panel subscriptions
2026-11-19 13:10:12 +07:00
Christian WuandClaude Fable 5.2 9faa3034f1 fix(app): keep a submenu open when its row is tapped on a touch screen (#10175)
A tap on the web arrives as pointer events: the finger enters the row as it
lands and leaves as it lifts. The submenu row and its flyout read both as
hover, so the leave queued a close just as the press opened the flyout, and
it disappeared about a quarter of a second later. A tap inside an open
flyout closed it the same way.

Hover intent now ignores pointer events whose pointerType is touch. Mouse
and pen behave as before, including on touch screens with a mouse attached.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 06:02:06 +00:00
Mohamed Boudra 157abbbbda Let agents choose which desktop opens a browser tab (#10189)
* fix(browser): let agents choose which desktop opens a tab

Registration order sent new tabs to the wrong desktop window. Let the agent discover and select the intended window by name, and require a choice when several windows can open tabs.

* test(desktop): run browser host selection in a fresh app session

Closing the second window can leave the existing browser journey in a different renderer state. Give both journeys their own windows and daemon so the routing test does not change the old test setup.

* fix(browser): keep window names visible and stable across reconnects

Frameless desktop windows need an in-app place to see and copy their name. Give each window one browser host identity so a reconnect replaces a lingering connection without creating a duplicate choice.

* test(desktop): cover host selection in the browser journey

Open the second window after the existing browser checks finish so their setup remains isolated within one CI run.
2026-11-19 13:01:34 +07:00
Mohamed BoudraandBrandon Elliott 2c22e64644 Keep dictation working after closing another chat (#10185)
* fix(app): keep dictation working after closing another chat

Keep the shared native recorder alive while a client still uses it. Report microphone startup errors at the composer so the user can retry from the same control.

Co-authored-by: Brandon Elliott <923787+Brandon168@users.noreply.github.com>

* fix(app): explain how to recover from dictation startup failures

Classify known microphone failures at the capture boundary. Keep daemon stream errors available to the composer and clear stale capture feedback on the next attempt.

* fix(app): keep permission guidance when the native request fails

* fix(app): show dictation errors after a terminal prompt shortcut

---------

Co-authored-by: Brandon Elliott <923787+Brandon168@users.noreply.github.com>
2026-11-19 12:06:30 +07:00
paseo-bot[bot]andClaude Opus 5.5 b09b17e6ee fix(opencode): fail the turn when a shared OpenCode service stops (#10187)
When Paseo used an OpenCode v2 service it did not start (a discovered
`opencode serve --service`, or a configured server URL), nothing
reported that service going away. The connection's `exited` signal
resolved only when Paseo itself stopped using it. A turn that was
running when the service died was never failed, the event stream
retried the dead port every 100 ms, and Stop, send and reload were
refused with "active run cancellation was not acknowledged".

The shared connection now treats a refused connection as the service
exiting, the same signal an owned server's process exit gives. The
session fails the turn, stops its stream, and reconnects on the next
operation.

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 05:01:50 +00:00
Mohamed Boudra f5d27b7901 Let agents watch a pull request (#10148)
* feat(server): let agents watch pull requests

* fix(server): isolate PR watch test homes

* fix(server): preserve watch delivery during subscription changes

* fix(server): batch co-due PR observations and drain admitted updates

* fix(server): settle combined poll requests with await

* fix(server): deliver overdue PR updates together

* fix(server): include failing check links in PR watch updates

* test(server): verify PR watch check links on live GitHub

* fix(server): deliver PR digests through the shared agent queue

* test(server): verify PR and child updates share the next turn

* fix(server): withdraw queued updates before provider admission

* feat(server): show PR watches as agent background work

Render active watches beside heartbeats so users can see and stop them while the agent is idle. Bind Stop to the original subscription so a delayed request leaves a replacement intact.
2026-11-19 11:51:06 +07:00
Mohamed BoudraandChristoph Leiter 4e78d15bdc Search agent settings in Cmd-K before the first message (#10182)
* fix(app): make agent controls searchable before the first message

New workspace already renders the shared draft controls, but Command Center registration lived in the workspace tab. Register from the draft controls and use the active composer scope so each host gets the same behavior.

Co-authored-by: Christoph Leiter <135764+cleiter@users.noreply.github.com>

* fix(app): keep agent settings searchable in fullscreen

Compact fullscreen editing used to unmount the toolbar and remove the active composer settings from Command Center. Keep the controls registered while fullscreen hides the inline toolbar.

* fix(app): show composer settings from compact sidebar search

The sidebar suspends editor shortcuts while it covers the pane. Give Command Center an explicit target so sidebar search still uses the center composer and Explorer keeps its own scope when open.

* test(app): cover compact Command Center settings for running agents

---------

Co-authored-by: Christoph Leiter <135764+cleiter@users.noreply.github.com>
2026-11-19 11:20:09 +07:00
Qi JiandMohamed Boudra 2327701497 fix(codex): support flex speed (#9809)
* fix(codex): offer the Flex speed and thread it through

Speed choices came from the model list's `serviceTiers`, and Codex never
advertises Flex there: `ModelInfo::supports_service_tier` treats it as an API
request option that is valid whatever the model advertises. So the Speed menu
could never list it, choosing `flex` threw "Codex speed 'flex' is not
available", and a stored `service_tier: "flex"` was rewritten to Normal before
the first turn.

Flex now joins Normal as a tier Paseo knows, on every Codex model. The Speed
control and the tier checks read one list, so what the control offers is what
the session runs: `turn/start` and rewind's `thread/fork` carry
`serviceTier: "flex"`, a saved Flex survives open and model switches, and a
catalog that does advertise Flex keeps its own entry instead of duplicating it.

Ref: #9773

* Verify Codex Flex in the browser Speed menu

* Gate unadvertised Flex on Codex 0.156

Codex 0.155 silently strips Flex from outgoing requests when the catalog omits it. Use the connected app-server version to gate the locally added option and normalize unsupported saved selections. Keep the Speed icon highlight for any explicitly selected tier and verify Flex follows that behavior.

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-11-19 11:14:16 +07:00
paseo-bot[bot]andClaude Opus 5.5 a6da22f86a fix(app): keep a toast that replaces one timing out (#10183)
When a toast replaced another just as the other's timer expired, the
old timer fired before the viewport rescheduled it and dismissed the
new toast. The new toast showed for one frame and faded out. The
timer now dismisses only the toast it was set for.

This made "Reloaded npm-review" vanish in the plugin-management e2e
journey when the reload finished about 2200 ms after the install
toast.

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 03:41:06 +00:00
Mohamed Boudra a8456ee63f Rewind the latest turn from Command Center (#10144)
* feat(app): rewind the latest turn from Command Center

Make the latest prompt easy to revise without finding its message menu. Focus the composer when a rewind restores that prompt so editing can resume immediately.

* fix(app): hide rewind for attachment-only prompts

Keep the Command Center and message menu eligibility aligned. Rewinding an attachment-only prompt removes the turn without a prompt the composer can restore.

* fix(app): wait for current history before rewinding the latest turn

Keep cached prompts out of the Command Center rewind target while the active chat catches up. The visible-message menu still targets the specific prompt the user chose.
2026-11-19 10:39:19 +07:00
Mohamed Boudra cf91362af4 Add composer shortcuts for model and effort (#10147)
* feat(app): add composer model and effort shortcuts

* fix(app): route composer shortcuts to the focused input
2026-11-19 10:38:48 +07:00
paseo-bot[bot]andClaude Opus 5.5 4663f3e40f Find a plugin toast in e2e while the previous toast still fades out (#10168)
* test(app): find a plugin toast while the previous one still fades

A toast that times out stays in the page during its 140 ms fade. When the
next toast appears in that window, the plugin helper's locator matched both
and failed in strict mode. Wait for the toast that carries the message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(app): match toast text with case so Installed differs from Uninstalled

A string passed to hasText matches part of the text and ignores case, so
"Installed e2e-plugin" also matched the "Uninstalled e2e-plugin" toast that
the spec shows just before it reinstalls. Use a case-sensitive pattern, as
toContainText did before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(app): find a plugin toast while a toast with the same text fades

Two "Reloaded e2e-plugin" toasts can share the screen during the 140 ms
fade, and the filtered locator then matched both. Either one shows the
message, so take the first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 03:00:38 +00:00
Mohamed Boudraandfivetaku 51baa2beb8 feat(claude): give Ultracode its own toggle (#10150)
Keep Ultracode independent of effort in the Claude composer and retain support for saved Ultra Code choices.

Co-authored-by: fivetaku <zipsanyang.ai@gmail.com>
2026-11-19 09:25:07 +07:00
Mohamed Boudra 31b6c2ebd3 Highlight shell scripts and Dockerfiles (#10178)
Use the existing CodeMirror modes for shell scripts and Dockerfiles. Pass full paths through tool-call highlighting so Dockerfile detection works across source views and diffs.
2026-11-19 09:21:01 +07:00
paseo-bot[bot]andClaude Opus 5.5 3da26f32ab fix(server): say which browser_wait condition expired (#10172)
An expired browser_wait condition reached the agent as "The browser did
not respond before the timeout. Try again or check the browser host."
The host did respond. summarizeBrowserError replaced every
browser_timeout message with that fixed text, so the host's own message
("Timed out waiting for browser text: ...") never reached the agent.

The tool text is now the producer's message for browser_timeout. The
broker's round trip timeout, the one case where the host did not
answer, now says so in its own message.

Closes #10128

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 01:43:45 +00:00
bcf52f93b1 fix(app): draw Mermaid flowcharts whose labels contain an @ (#10165)
Mermaid 11's lexer reads an edge id (`e1@-->`) from any run of
non-space characters ending in "@". In `F[@mention] --> G` that run
starts at the node id and crosses the label's opening bracket, so the
parse fails and the card falls back to the source. Backport the lexer
half of mermaid-js/mermaid#8459, which stops the edge id at the node
shape characters, onto the pinned mermaid 11.16.0 and rebuild the
runtime. Moving to mermaid 12 instead changes the default layout and
look of every diagram and raises the browser floor, so it stays a
separate decision.

Closes #10157

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: monarchmaisuriya <37824914+monarchmaisuriya@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 21:52:18 +00:00
paseo-bot[bot]andClaude Opus 5.5 d8c98400fb fix(server): reopen a plugin agent whose provider closed its session (#10153)
When a plugin provider closed a session with session.closed, the next
prompt went stale and Paseo tried to reopen the agent. The reopen first
closes the old session, and that close sent session.close for a session
the plugin runtime had already forgotten. The send failed with "Unknown
provider session", the reopen stopped, and the prompt was rejected with
"Provider session <id> is stale after its plugin reloaded". Every later
prompt failed the same way.

A session that the provider closed now skips the native close and only
drops its routing, so the reopen continues and the prompt runs.

Closes #10151

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 20:45:55 +00:00
VladimirGVPandVladimirGVP 77392d3c1b perf(workspace-git): retain warm targets across short reconnects (#10142)
Co-authored-by: VladimirGVP <322008768+VladimirGVP@users.noreply.github.com>
2026-11-18 20:18:30 +00:00
paseo-bot[bot] 8edccf0503 test(app): press a fork trigger again when a streamed line moves it (#10156)
"forks a streaming assistant turn without interrupting it" pressed the
in-flight turn's fork trigger once and waited for the menu. While the
chat is shorter than the viewport, each streamed line moves the trigger
down. A line that arrives between the press and the release moves the
trigger out from under the pointer, the press opens nothing, and the
wait for "Fork in a new tab" timed out.

openForkMenu now presses the trigger until its menu shows.

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
2026-11-18 18:51:59 +00:00
Okan YILDIRIM ac633eb096 fix(markdown): wait for the host before reading a chat image (#10111)
When the app opens straight into a chat on a host it hasn't connected to yet,
such as a page reload or a cold start on an agent route, it renders the cached
messages before the host's client exists. useMarkdownSource enabled the image
read anyway, with no client to read through, so it failed with "Image
unavailable". The query's retries cover a host that connects within about
seven seconds. After that the read stays failed and the image collapses to its
alt text. The query key doesn't include the client, so the client's arrival
never starts another read, and the image stays as alt text after the host
connects.

Markdown that belongs to a host, which has a serverId, now waits for that
host's client before it reads. Until the host connects the image keeps its
pending placeholder, and once the client arrives the query runs and reads the
file. Markdown with no host, such as the changelog, has no client to wait for
and still falls back to its alt text.
2026-11-18 15:59:10 +00:00
25ff8adf06 fix(omp): allowing a tool approval approves it when OMP offers session or grant choices (#10126)
* fix(omp): map tool approvals that offer session or grant choices

OMP 18.x adds "Approve <tool> for this session" and directory/file grant
choices to its rpc-ui approval select. The mapper only recognised the exact
["Approve", "Deny"] options, so these prompts fell through to a generic
"OMP select" question; allowing it from the CLI or a notification answered
with no value and OMP treated the call as denied.

Recognise approval selects whose one-call choice is "Approve" or
"Approve Once", whose last choice is "Deny", and whose other choices are
approval labels. Surface the extra choices as allow actions and answer with
the selected label.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

* fix(omp): allow one call when a grant is labeled Approve

OMP names the one-call choice "Approve Once" whenever it also offers
grants. A grant for a target that is not a file is then labeled
"Approve", so the select arrives as
["Approve", "Always Approve", "Approve Once", "Deny"]. Taking the
first "Approve" as the one-call choice made a plain allow pick the
grant, which remembers more than the call. Prefer "Approve Once" when
it is offered.

Co-authored-by: Dhruv Singal <dhruvsingalabc@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(omp): read the picked approval choice from its action

Each extra approval choice's action label is the select value OMP
offered, so the response reads it from request.actions instead of a
second copy in metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Dhruv Singal <dhruvsingalabc@gmail.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 15:11:16 +00:00
paseo-ai[bot] 09a15abb06 fix: update lockfile signatures and Nix hash [skip ci] 2026-11-18 15:01:27 +00:00
Mohamed Boudra 81fb9c03f6 chore(release): reconcile main with 0.16.2 (#10132) 2026-11-18 21:51:22 +07:00
649 changed files with 17539 additions and 14240 deletions
+21
View File
@@ -1,5 +1,26 @@
# Changelog
## 0.16.2 - 2026-11-18
### Fixed
- Fixed Collapse turns hiding a finished reply when Claude answers a later background task notification ([#10092](https://github.com/getpaseo/paseo/pull/10092))
- Fixed detached worktree commits getting lost when archiving a workspace ([#10009](https://github.com/getpaseo/paseo/pull/10009) by [@ragokan](https://github.com/ragokan))
- Fixed Desktop updates leaving an older daemon running when an earlier Desktop session started it ([#10067](https://github.com/getpaseo/paseo/pull/10067))
- Fixed daemons losing their Hub connection after execution permissions changed ([#10113](https://github.com/getpaseo/paseo/pull/10113))
- Fixed saved hosts disappearing when one stored entry could not be read ([#9847](https://github.com/getpaseo/paseo/pull/9847) by [@ragokan](https://github.com/ragokan))
- Fixed worktree creation timing out while scanning large ignored folders that `.worktreeinclude` does not name ([#10020](https://github.com/getpaseo/paseo/pull/10020) by [@mgranderath](https://github.com/mgranderath))
- Fixed Steer cancelling a Claude compaction in progress ([#10028](https://github.com/getpaseo/paseo/pull/10028) by [@NightMachinery](https://github.com/NightMachinery))
- Fixed agents getting stuck after a second Stop when the provider reused the cancelled turn ID ([#9774](https://github.com/getpaseo/paseo/pull/9774) by [@DAnaeto](https://github.com/DAnaeto))
- Fixed Desktop staying blank after its renderer exited unexpectedly ([#10035](https://github.com/getpaseo/paseo/pull/10035))
- Fixed failed file downloads taking over the app window on web and Desktop ([#9937](https://github.com/getpaseo/paseo/pull/9937) by [@panta82](https://github.com/panta82))
- Fixed Import Session losing its scroll position when you select Load more ([#9974](https://github.com/getpaseo/paseo/pull/9974))
- Fixed terminals failing to open when the home filesystem refuses Unix sockets, such as on AFS ([#9214](https://github.com/getpaseo/paseo/pull/9214) by [@bendavid](https://github.com/bendavid))
- Fixed timed-out Git watchers repeatedly rescanning large repositories ([#9828](https://github.com/getpaseo/paseo/pull/9828) by [@Spshulem](https://github.com/Spshulem))
- Fixed `paseo workspace create --path .` using the local daemon's directory instead of the caller's ([#10010](https://github.com/getpaseo/paseo/pull/10010))
- Fixed MCP agent status and list responses omitting background work for idle agents ([#10022](https://github.com/getpaseo/paseo/pull/10022) by [@ortschun](https://github.com/ortschun))
- Fixed the thinking selector showing an old level after OMP changes it ([#9841](https://github.com/getpaseo/paseo/pull/9841) by [@dsingal0](https://github.com/dsingal0))
## 0.16.1 - 2026-11-17
### Fixed
+21
View File
@@ -1,5 +1,26 @@
# Changelog
## 0.16.2 - 2026-11-18
### 修复
- 修复启用“折叠轮次”时,Claude 回复后续后台任务通知导致上一条已完成的回复被折叠的问题 ([#10092](https://github.com/getpaseo/paseo/pull/10092))
- 修复归档工作区时丢失分离 HEAD 的 worktree 提交的问题 ([#10009](https://github.com/getpaseo/paseo/pull/10009),贡献者:[@ragokan](https://github.com/ragokan))
- 修复 Desktop 更新后,由上一次 Desktop 会话启动的旧版 daemon 仍在运行的问题 ([#10067](https://github.com/getpaseo/paseo/pull/10067))
- 修复更改执行权限后 daemon 与 Hub 断开连接的问题 ([#10113](https://github.com/getpaseo/paseo/pull/10113))
- 修复一条已保存的主机记录无法读取时,其他主机也消失的问题 ([#9847](https://github.com/getpaseo/paseo/pull/9847),贡献者:[@ragokan](https://github.com/ragokan))
- 修复创建 worktree 时,扫描 `.worktreeinclude` 未指定的大型忽略目录导致超时的问题 ([#10020](https://github.com/getpaseo/paseo/pull/10020),贡献者:[@mgranderath](https://github.com/mgranderath))
- 修复发送引导消息时取消 Claude 正在进行的上下文压缩的问题 ([#10028](https://github.com/getpaseo/paseo/pull/10028),贡献者:[@NightMachinery](https://github.com/NightMachinery))
- 修复 Provider 重用已取消的轮次 ID 时,再次停止导致 Agent 卡住的问题 ([#9774](https://github.com/getpaseo/paseo/pull/9774),贡献者:[@DAnaeto](https://github.com/DAnaeto))
- 修复 Desktop 渲染进程意外退出后窗口一直空白的问题 ([#10035](https://github.com/getpaseo/paseo/pull/10035))
- 修复 Web 和 Desktop 上文件下载失败时,错误页面占据应用窗口的问题 ([#9937](https://github.com/getpaseo/paseo/pull/9937),贡献者:[@panta82](https://github.com/panta82))
- 修复在“导入会话”中选择“加载更多”时丢失滚动位置的问题 ([#9974](https://github.com/getpaseo/paseo/pull/9974))
- 修复主目录所在的文件系统拒绝 Unix 套接字时无法打开终端的问题,例如 AFS ([#9214](https://github.com/getpaseo/paseo/pull/9214),贡献者:[@bendavid](https://github.com/bendavid))
- 修复 Git 监视器设置超时后反复扫描大型仓库的问题 ([#9828](https://github.com/getpaseo/paseo/pull/9828),贡献者:[@Spshulem](https://github.com/Spshulem))
- 修复 `paseo workspace create --path .` 使用本地 daemon 的目录而非命令所在目录的问题 ([#10010](https://github.com/getpaseo/paseo/pull/10010))
- 修复针对空闲 Agent 查询 MCP 状态或列表时漏报后台任务的问题 ([#10022](https://github.com/getpaseo/paseo/pull/10022),贡献者:[@ortschun](https://github.com/ortschun))
- 修复 OMP 更改思考级别后,选择器仍显示旧级别的问题 ([#9841](https://github.com/getpaseo/paseo/pull/9841),贡献者:[@dsingal0](https://github.com/dsingal0))
## 0.16.1 - 2026-11-17
### 修复
-1
View File
@@ -54,7 +54,6 @@ At the start of non-trivial work, list `docs/` and skim anything relevant to the
| [docs/permissions.md](docs/permissions.md) | Semantic daemon permissions, principals, credentials, pairing invitations, and Hub authority |
| [docs/terminal-performance.md](docs/terminal-performance.md) | Terminal latency pipeline, coalescing/backpressure invariants, benchmark + perf spec usage |
| [docs/terminal-rendering.md](docs/terminal-rendering.md) | Native terminal view: xterm owns the grid, cluster placement, emoji widths, mixed-direction limits, render regression |
| [docs/timeline-sync.md](docs/timeline-sync.md) | Owned agent history, rewind retirements, live stream vs authoritative fetch, paged catch-up, client replica |
| [docs/agent-stream-performance.md](docs/agent-stream-performance.md) | Assistant text pipeline — coalescing window, paced reveal, why arrival lumps are smoothed at render |
| [docs/agent-stream-disclosure.md](docs/agent-stream-disclosure.md) | Expand/collapse in the chat timeline — hold contract, native anchor sequence, frame spacing, render-window cost |
| [docs/markdown-renderer.md](docs/markdown-renderer.md) | Shared Markdown engine, native selection, links, images and library constraints |
+3 -6
View File
@@ -39,8 +39,8 @@ An unarchived agent may be `closed` without being deleted or archived. Closing r
processes and subscriptions while retaining its Paseo identity, persistence handle, timeline,
workspace, labels, title, usage, attention, timestamps, and parent relationship. Opening or prompting
the agent runs through `ensureAgentLoaded()`, which resumes the durable provider session under the
same Paseo agent ID. Resume does not read provider history when the agent already has a timeline;
see [owned history](timeline-sync.md#owned-history).
same Paseo agent ID. Provider history is not appended again when the canonical timeline is already
primed.
Reload releases the old runtime before resuming its durable session: an idle provider process can
still own an exclusive writer. A close failure retains that runtime for cleanup and blocks the
@@ -240,8 +240,7 @@ lifecycle is separate from public workspace visibility and is not a public creat
Archive is a **soft delete**: the agent record stays on disk with `archivedAt` set, the runtime is closed, and the agent disappears from active lists. Archive is **global** — it lives on the server and propagates to every connected client.
Archive sets `archivedAt`, invokes the provider's native archive hook, and cascades to managed
children. The timeline and the provider children stay, so an archived chat reads them without its
provider; deleting the agent removes them.
children.
`create_agent_request` can opt an agent into `autoArchive`. In that mode the daemon archives the agent after the first terminal turn event (`turn_completed`, `turn_failed`, or `turn_canceled`). When the agent owns an isolated workspace, auto-archive archives that workspace too; the managed worktree is removed when its final workspace reference is gone.
@@ -337,8 +336,6 @@ Workspace status is an aggregate activity signal computed **per `workspaceId`**.
Running provider-native subagents contribute `running` to the workspace owned by their parent agent. Their completed, failed, and canceled states stay in the parent's subagents track.
Only the parent's current runtime makes a provider child running. A child's stored status is the last report about it, and that report can come from provider history or from a runtime an earlier daemon ran, so a stored `running` child does not make the workspace running or keep the parent's runtime alive. It counts again once the live session reports it running. Closing a runtime cancels the children that runtime reported running; children it never reported keep their stored status.
A finished or failed workspace can be marked unread after it has been reviewed. The daemon restores
attention on its newest eligible workspace-root agent, `error` for an agent whose lifecycle is
`error` and `finished` otherwise, without sending a new notification. Opening a workspace restores
+12 -5
View File
@@ -163,8 +163,16 @@ override a scroll away because they can arrive after the action that requested t
### Draw distance
`drawDistance` is 2000 px on each side of the viewport. A fling over rows that were never measured
blanks the viewport until LegendList renders and measures them. Twelve flings over a chat with a
The native timeline starts with one window-height of draw distance, up to 2000 px. This keeps
nearby rows ready for a fling during placement. Once the chat is placed, history is visible, and
the sidebar has settled, the timeline schedules expansion to 2000 px through two frame callbacks.
The callbacks leave time for the reveal to paint. Verify the actual reveal on the device.
A drag cancels a pending expansion and uses the existing buffer as the window moves. Expansion
resumes when the gesture settles, including momentum. In an Android emulator capture, expanding
the full buffer during the first fling changed the measured content height and returned the chat
to the end mid-fling.
A fling over rows that were never measured blanks the viewport
until LegendList renders and measures them. Twelve flings over a chat with a
15,000 px turn expanded, Android emulator, dev build:
| List | Blank viewport | Janky frames | p50 / p90 / p99 |
@@ -179,9 +187,8 @@ With every turn collapsed, flinging from a cold open into history did not blank
### LegendList patch
`patches/@legendapp+list+3.7.1.patch` carries twelve changes for the timeline. Its header lists
them by purpose, and
[legend-list #593](https://github.com/LegendApp/legend-list/issues/593) reports each upstream.
`patches/@legendapp+list+3.7.1.patch` lists its changes by purpose.
[legend-list #593](https://github.com/LegendApp/legend-list/issues/593) reports the first twelve.
Drop a hunk when the installed LegendList ships its fix.
### Scroll view corrections
-1
View File
@@ -94,7 +94,6 @@ workspace for a directory clears it. The store lives in memory and resets on dae
| `server/directory-sync/` | Daemon-global latest-state sequences for projects, workspaces, and agents |
| `server/workspace-labels/` | Host-local label catalog, assignment mutations, and explicit subscriptions |
| `server/agent/agent-manager.ts` | Agent lifecycle state machine, timeline tracking, subscriber management |
| `server/agent/timeline/` | Owned agent history, provider children, rewind retirements, behind a backend |
| `server/agent/agent-storage.ts` | File-backed JSON persistence at `$PASEO_HOME/agents/` |
| `server/agent/tools/` | Transport-neutral catalog for workspaces, agents, permissions, and automation |
| `server/agent/mcp-server.ts` | Thin MCP adapter that registers the Paseo tool catalog with the MCP SDK |
-8
View File
@@ -180,14 +180,6 @@ Terminal activity contributes to the workspace status bucket **per `workspaceId`
---
## Runtime-only Agent Timelines
Agent timelines are not written to `$PASEO_HOME`. `AgentTimeline` owns each agent's history behind
a backend, and the only backend is in memory, so a daemon restart loses it and the next resume
imports provider history. See [owned history](timeline-sync.md#owned-history).
---
## 2. Daemon Configuration
**Path:** `$PASEO_HOME/config.json`
+8
View File
@@ -20,6 +20,14 @@ input focused while its scrollable list lives in a Portal. There is no shared
"floating panel" primitive yet — when a fifth use case shows up we can revisit;
until then prefer copying the closest file and trimming.
## Picker trigger tooltips
Keep the picker surface outside `TooltipTrigger`. React focus events bubble
through portals, so putting the surface inside the trigger makes focus in its
search field look like focus on the button when a shortcut opens the picker.
For new `ComboboxTrigger` buttons, pass the hint through the `tooltip` prop. An
explicit `TooltipTrigger` wrapper is also safe when it wraps only the button.
## Popover width contract
Combobox desktop popovers are never narrower than their trigger, and they grow
+3 -2
View File
@@ -6,7 +6,7 @@ Authoritative terminology. UI label wins. Don't invent synonyms; use what's here
- **Workspace** — One concrete `cwd` on one daemon, with git state; belongs to exactly one project. Its `id` is opaque workspace identity; its `cwd` is the filesystem directory. UI: "Workspace". Code: `WorkspaceDescriptorPayload` (`packages/protocol/src/messages.ts:2178`). Don't confuse with: Branch (one branch can back many workspaces via worktrees). Forbidden: "Folder", "Directory" as UI label.
- **Archive workspace** — Removes one workspace from active use and archives everything it owns. UI, CLI, and MCP always say "Archive workspace", regardless of backing. The daemon leaves ordinary directories intact and removes a Paseo-owned worktree only when no active workspace still references it.
- **Workspace kind** — `"directory" | "local_checkout" | "worktree"`. The git-derived, persisted property of a workspace, used across its lifetime (archive safety, sidebar, grouping). Derived from the cwd's git reality by `deriveWorkspaceKind` in `workspace-registry-model.ts`, not stored from a user choice. Don't confuse with **Isolation** (the create-time intent).
- **Isolation** — Create-time choice for a new workspace: reuse the existing checkout (**Local**) or cut a dedicated git worktree (**New worktree**). A transient setup input, also remembered as a create-form preference; it is not a workspace property. UI: "Isolation" control on the New Workspace screen. Code: `isolation` (`"local" | "worktree"`), `useWorkspaceIsolation` (`packages/app/src/screens/new-workspace-screen.tsx`); persisted as `FormPreferences.isolation` (`packages/app/src/create-agent-preferences/preferences.ts`). Distinct from **Workspace kind**, which is the git-derived property the intent produces (Local → `local_checkout` or `directory` by git-ness; New worktree → `worktree`). On the wire it is the create request's `source.kind` (`directory | worktree`, `packages/protocol/src/messages.ts:1693`).
- **Isolation** — Create-time choice for a new workspace, with three options: work in the project's own directory (**Project directory**), cut a dedicated git worktree (**New worktree**), or work in a git worktree already on disk (**Existing worktree**). A transient setup input; Project directory and New worktree are also remembered as a create-form preference. It is not a workspace property. UI: "Isolation" control on the New Workspace screen. Code: `isolation` (`"local" | "worktree"`), `useWorkspaceIsolation` (`packages/app/src/screens/new-workspace-screen.tsx`); persisted as `FormPreferences.isolation` (`packages/app/src/create-agent-preferences/preferences.ts`). Existing worktree is not a third value: it is `local` with the worktree's path as the source directory (`existingWorktreePath` in `packages/app/src/screens/new-workspace/setup-model.ts`), so plugins, preferences, and the wire see `local`. Distinct from **Workspace kind**, which is the git-derived property the intent produces (Project directory → `local_checkout` or `directory` by git-ness; New worktree and Existing worktree → `worktree`). On the wire it is the create request's `source.kind` (`directory | worktree`, `packages/protocol/src/messages.ts`). Forbidden: "Local" as the UI label.
- **Agent** — See **Agent session**. UI still says "Agent" / "New Agent" in places, but moving toward **Agent session** as the canonical term. Code: `AgentSnapshotPayload` (`packages/protocol/src/messages.ts:608`). Forbidden: "Task", "Job", "Run".
- **Daemon** — Local Paseo server process; identified by `serverId`. UI: "Daemon" (system contexts only). Code: `serverId` in `ServerInfoStatusPayloadSchema` (`packages/protocol/src/messages.ts:1936`), `DaemonClient` (`packages/client/src/daemon-client.ts`).
- **Host** — Client-side connection profile pointing at a daemon; bundles one or more `HostConnection`s. UI: "Host" / "Add host" / "Switch host". Code: `HostProfile` (`packages/app/src/types/host-connection.ts:37`). Forbidden: "Connection" (means `HostConnection`, not host).
@@ -17,7 +17,8 @@ Authoritative terminology. UI label wins. Don't invent synonyms; use what's here
- **Forge** — Git hosting service behind Paseo's change-request features: GitHub, GitLab, Gitea, Forgejo, or a future registered adapter. Code: `ForgeService`, `forge-registry`, `forge-resolver`. Use `forge` for internal abstraction and registry IDs; use concrete forge names only when a behavior or RPC is forge-specific.
- **Change request** — Forge-neutral term for a proposed branch-to-branch code change. UI normally renders the forge noun instead: GitHub/Gitea/Forgejo "PR", GitLab "MR". Code: `forge_change_request` attachments, `checkoutSource: { kind: "change_request" }`, and PR/MR status payloads.
- **MR** — GitLab merge request. UI label for GitLab change requests only; do not use MR for GitHub/Gitea/Forgejo.
- **Worktree** — Paseo-managed git worktree (`~/.paseo/worktrees/{name}`); also a `workspaceKind` value. User-facing creation treats it as the `worktree` workspace isolation choice. Code and `paseo.json` retain worktree terminology for git lifecycle implementation. Forbidden: "Checkout" as a product synonym.
- **Worktree** — A git worktree: any working directory that `git worktree list` reports for the repository, whoever created it. Paseo creates its own under `$PASEO_HOME/worktrees/` and owns their setup and removal; worktrees made with `git worktree add` are listed by the Existing worktree picker but never removed by Paseo. Also a `workspaceKind` value. Code: `checkout.worktrees.list` RPC (`listGitWorktrees` in `packages/server/src/utils/worktree.ts`), gated on `server_info.features.checkoutWorktreeList`. Code and `paseo.json` retain worktree terminology for git lifecycle implementation. Don't confuse with: **Workspace** (Paseo's place for a task; several workspaces can work in one worktree, and a worktree with no workspace is still a worktree). Forbidden: "Checkout" as a product synonym.
- **Branch off / Check out** — What a New worktree does with the branch or pull request picked in the ref picker. **Branch off** starts a new branch from it; **Check out** works on that branch itself. Branches default to Branch off and pull requests to Check out; the user can switch either. Branching off a pull request starts the new branch at the pull request's head with no upstream. Git keeps a branch in one worktree at a time, so checking out a branch another worktree holds sends the user to that worktree instead of creating a copy. Code: `RefAction` (`packages/app/src/screens/new-workspace-picker-item.ts`), the worktree source's `action` (`"branch-off" | "checkout"`), gated on `server_info.features.worktreeRefActions`.
- **Repository / Remote** — Internal Git observations. They may produce mutable kind, branch, and project-grouping metadata but never the host-local project ID, root, display name, or workspace membership. No UI label.
- **Sidebar items** — The configurable entries of the app sidebar, in two sections. Header: the rows at the head of the sidebar — New workspace, History, Search, Schedules, and plugin header items. Footer: the full-width rows between Add project and the footer icon row — Usage and plugin footer items. Add project and the icon row (Hosts, Help and support, Settings) are fixed and are not sidebar items. A plugin item may render several rows, such as one per bot; it is still one item that moves and hides as a block. Each section's order and visibility is one per-device preference (`AppSettings.sidebarNavItems`, `AppSettings.sidebarFooterItems`); every item may be off. UI: the Header and Footer cards on the Sidebar settings page. Code: `packages/app/src/sidebar-nav/model.ts` resolves a section, and the sidebar (`components/sidebar/sidebar-nav-rows.tsx`, the footer in `components/left-sidebar.tsx`) and the settings page (`screens/settings/sidebar/sidebar-nav-section.tsx`) read it through `useSidebarNavItems(section)`. Never hardcode one of these entries or add a second place that decides which ones show. Don't confuse with **Explorer sidebar**.
- **Explorer sidebar** — The dedicated navigation dock containing the Files and Changes trees. UI: "Explorer sidebar". Code: `packages/app/src/workspace-tabs/explorer-sidebar.ts`; persisted pane identifiers retain the `explorer` spelling. See [explorer-sidebar.md](explorer-sidebar.md).
+3 -2
View File
@@ -788,14 +788,15 @@ is the [New workspace items reference](../public-docs/plugins/reference.md#new-w
The screen's choices that a plugin may change live in one plain store,
`createNewWorkspaceSetup` (`packages/app/src/screens/new-workspace/setup-model.ts`): the base
picker selection, the manual isolation, the branch name and the workspace metadata. The pickers and
picker selection, the manual isolation, the chosen existing worktree, the Branch off or Check out
action per ref list, the branch name and the workspace metadata. The pickers and
the plugin commands write to it, so a command sees what an earlier command left. Project and host
stay in the screen's hooks (`useNewWorkspaceHostSelector` reconciles them against each other), and
they are read-only to plugins; a command that switched them would unmount the item that called it.
The store is built in the render that creates the screen, with what the screen derives from its
hooks (the lock, the project, whether the project can make worktrees, whether the host supports
metadata), so a command is valid from a child's first effect, which runs before the screen's own
metadata and ref actions, the project's git worktrees), so a command is valid from a child's first effect, which runs before the screen's own
effects. `syncInputs` refreshes those inputs in a layout effect on every commit, and commands read
them when they run, never from the render that built them. The pickers and the commands pick
through the same `chooseBase` and `chooseIsolation`, so a plugin command has the effects of a
+3 -3
View File
@@ -19,7 +19,7 @@ provider icon map. You do not need a core manifest entry or provider factory.
| Provider | Transport | Setup and limitations |
| ----------- | ------------------------------------------ | ---------------------------------------------------------------- |
| Antigravity | Installed `agy` CLI | [Antigravity](../public-docs/supported-providers/antigravity.md) |
| Antigravity | ACP over the installed `agy acp` CLI | [Antigravity](../public-docs/supported-providers/antigravity.md) |
| Muse Code | MSP over one `muse serve` host per session | [Muse Code](../public-docs/supported-providers/muse-code.md) |
## Provider-native session options
@@ -50,8 +50,8 @@ or without a control.
reject. A key the running session cannot apply (one the provider reads only when it opens) is
rejected too, so a stored option always describes what runs. Claude reads most options when it
starts its query, and replacing a started query would end its background work, so after the
first prompt only Fast can change. Codex fixes its approval policy and sandbox when the thread
starts, so it applies only `service_tier` and `plan_mode` live. A session with no
first prompt only Fast and Ultracode can change. Codex fixes its approval policy and sandbox
when the thread starts, so it applies only `service_tier` and `plan_mode` live. A session with no
`applyOptions` rejects every patch; the daemon enforces this. The provider returns the options
it ended up with when they differ from the request. The daemon stores the patch and that
result in one step after the call resolves. Throwing rejects the whole patch and none of it is
+11 -63
View File
@@ -5,9 +5,15 @@ Agent chat delivery has two paths:
1. **Live stream** — `agent_stream` WebSocket messages for immediacy. These may be delta-shaped lifecycle updates.
2. **Authoritative history** — `fetch_agent_timeline_request` for correctness. This always returns full projected timeline items, never lifecycle deltas.
Pagination bounds each read, not total resident history. Streaming overhead must remain
proportional to the retained transcript. Cumulative text snapshots must be released after their
deltas have been consumed.
The daemon retains projected items in memory. Each source event advances the stream sequence,
then replaces the previous tool state or merges into the current text item. Intermediate payloads
are never retained for history or catch-up. Provider history is the durable transcript authority
and rebuilds the projection when an agent resumes.
Pagination bounds each read, not total resident history. Active and idle agents retain their
projected transcript; archive releases it and later history reads rebuild it from the provider.
Streaming overhead must remain proportional to the retained transcript. Cumulative text snapshots
must be released after their deltas have been consumed.
The invariants are:
@@ -26,45 +32,6 @@ bounded item is used for runtime timeline rows and live stream events. Provider
applies the same rule so reopening an agent cannot restore an oversized payload. Fetches apply it
again to assistant and reasoning rows the projection merges from many chunks.
## Owned history
The daemon owns each agent's history in `AgentTimeline`
(`packages/server/src/server/agent/timeline/`): one ordered history per agent, with each provider
child's descriptor and history in a child scope of the same agent. Each source event advances the
stream sequence, then replaces the previous tool state or merges into the current text item.
Intermediate payloads are never retained for history or catch-up.
History is append-only: rewind, import, reload and archive never delete or rewrite a row. Only
deleting the agent, or a provider removing one of its own children, deletes history.
- **Rewind** retires a range of rows. They leave the conversation and stay stored, in the same
epoch. See [Rewind retires rows](#rewind-retires-rows).
- **Provider history** is imported only into an agent that has no history. After that, resume
does not read it. Reload agent and Unarchive require the provider history to start with the
same prompt IDs and text in order. They then append whole new turns, starting at the next
prompt. Existing replies, including partial replies, stay as recorded. If the prompts differ,
for example because the provider stored expanded attachment text, the chat stays unchanged and
Paseo reports a mismatch. A provider child Paseo already holds, listed or retired, is never imported again.
- **Archive and reload** keep the history and the provider children. An archived chat reads them
without its provider. Deleting the agent deletes its history and every child's, retired ones
included.
`epoch` is the stored history's identity, minted once when the history is created.
`AgentTimeline` serializes every operation of one agent, child scopes included, and keeps its
state in an `AgentTimelineBackend`: the sequence, the rows and retirements, prompt identities, the
open rewind, and the children. The backend contract suite is `agent-timeline.test.ts`, run over
`TIMELINE_CONTRACT_BACKENDS` in `timeline/testing.ts`. The only backend keeps everything in
memory, so a daemon restart loses the owned history: the next resume imports provider history into
a new epoch, and clients take the destructive reset below. Rewinds retired before the restart come
back if the provider history still holds them. Retained history costs memory for every loaded,
closed or archived agent until the daemon exits or the agent is deleted.
An open rewind is stored with the history. Resuming an agent whose history holds one settles it
before the agent takes prompts: a recorded provider cut is committed, and an unknown outcome is
judged from the resumed provider history. When that history proves nothing, the rewind stays open
and the agent refuses prompts with the unknown-outcome error.
## Presence is not delivery
Client heartbeat reports presence:
@@ -201,7 +168,7 @@ or retry backoff. This cannot keep a mobile socket alive after the operating sys
bookkeeping without replacing timeline arrays, preserving an upward-scrolled viewport.
- When the page overlaps or is adjacent to the local end cursor, only projected items newer than
that cursor are applied. Already-covered rows are not replayed.
- A true middle gap or epoch change atomically replaces stale canonical history with the
- A true middle gap, epoch change, or rewind atomically replaces stale canonical history with the
latest tail. The replacement reconciles positioned live rows beyond its coverage and unresolved
local submissions; it never retains two discontiguous canonical ranges.
@@ -214,24 +181,6 @@ history replay. The pending approval UI can hide that tool from presentation, bu
must retain its position. Creating a new history card on rejection places it after the prompt that
rejected it; changing steer-event ordering would also put new assistant output before that prompt.
## Rewind retires rows
A conversation rewind commits a retirement `{ seq, retireFromSeq }`: active rows anchored in
`[retireFromSeq, seq)` leave the conversation, and `seq` is the retirement's own position in the
sequence. The provider children spawned by retired tool calls, and their descendants, are retired
in the same commit. They leave the listing, keep their history, and drop late provider events.
Clients learn of a retirement live through `agent.timeline.rewind`, and on pages through
`retirements`, which lists the retirements whose `seq` lies inside the page's span. The client
drops the rows it holds in that range; rows without a timeline position are unechoed local sends
and stay. Retired ranges and the retirement's `seq` count as covered, so forward cursors advance
through them. Tail, before and prompt-jump pages are served from active rows, so one served before
a retirement the client already applied is stale and is refetched (`viewed-timeline-sync.ts`).
Clients without `timeline_rewind_operations` cannot drop retired rows. For them the session derives
a wire epoch that changes with each retirement, so they take the destructive replacement they
always took on rewind. The shim is tagged `COMPAT(timelineRewindOperations)`.
## Provider child history
Child transcripts use the same projected-page reconciliation as the main conversation. The client
@@ -396,7 +345,7 @@ the draft-create handoff is the one boundary that also permits the legacy canoni
arrived first. Generic reducers and consumers do not reimplement message identity matching.
Ordinary bootstrap, same-epoch reset, and catch-up replacement preserve unmatched locally submitted
rows because a provider may never echo them. A known epoch change replaces history and
rows because a provider may never echo them. A known epoch change or rewind replaces history and
drops acknowledged local rows omitted by the new canonical epoch; every transaction not yet
acknowledged by the provider, and no other local row, crosses that destructive boundary. A cold
reset without an existing epoch is destructive because the client has no continuity anchor.
@@ -412,7 +361,6 @@ canonical assistant prefix, it stays in the head lane. No row may be returned in
## Relevant code
- Server owned history: `packages/server/src/server/agent/timeline/`
- Server live stream forwarding: `packages/server/src/server/session.ts`
- App sync planning: `packages/app/src/timeline/timeline-sync-plan.ts`
- App viewed-agent synchronization: `packages/app/src/timeline/viewed-timeline-sync.ts`
@@ -0,0 +1,8 @@
Fixed
- Fixed Collapse turns hiding a finished reply when Claude answers a later background task notification
- Fixed detached worktree commits getting lost when archiving a workspace
- Fixed Desktop updates leaving an older daemon running when an earlier Desktop session started it
- Fixed daemons losing their Hub connection after execution permissions changed
- Fixed saved hosts disappearing when one stored entry could not be read
Full notes: https://paseo.sh/changelog
@@ -0,0 +1,8 @@
Fixed
- Fixed Collapse turns hiding a finished reply when Claude answers a later background task notification
- Fixed detached worktree commits getting lost when archiving a workspace
- Fixed Desktop updates leaving an older daemon running when an earlier Desktop session started it
- Fixed daemons losing their Hub connection after execution permissions changed
- Fixed saved hosts disappearing when one stored entry could not be read
Full notes: https://paseo.sh/changelog
@@ -0,0 +1,8 @@
Fixed
- Fixed Collapse turns hiding a finished reply when Claude answers a later background task notification
- Fixed detached worktree commits getting lost when archiving a workspace
- Fixed Desktop updates leaving an older daemon running when an earlier Desktop session started it
- Fixed daemons losing their Hub connection after execution permissions changed
- Fixed saved hosts disappearing when one stored entry could not be read
Full notes: https://paseo.sh/changelog
@@ -0,0 +1,8 @@
Fixed
- Fixed Collapse turns hiding a finished reply when Claude answers a later background task notification
- Fixed detached worktree commits getting lost when archiving a workspace
- Fixed Desktop updates leaving an older daemon running when an earlier Desktop session started it
- Fixed daemons losing their Hub connection after execution permissions changed
- Fixed saved hosts disappearing when one stored entry could not be read
Full notes: https://paseo.sh/changelog
+1 -1
View File
@@ -1 +1 @@
sha256-k7+5S/4tyAmHdZmUdhpuZ7GOc7hp9cG8wUBFdJI32ng=
sha256-yLTaVMgu3tc/dgngJ7RP0htJcWE0ZtQ4mouypevyv0s=
+28 -28
View File
@@ -1,12 +1,12 @@
{
"name": "paseo",
"version": "0.16.1",
"version": "0.16.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "paseo",
"version": "0.16.1",
"version": "0.16.2",
"hasInstallScript": true,
"license": "Apache-2.0",
"workspaces": [
@@ -37468,7 +37468,7 @@
},
"packages/app": {
"name": "@getpaseo/app",
"version": "0.16.1",
"version": "0.16.2",
"dependencies": {
"@codemirror/commands": "6.10.4",
"@codemirror/language": "6.12.4",
@@ -39637,13 +39637,13 @@
},
"packages/cli": {
"name": "@getpaseo/cli",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@clack/prompts": "^1.0.0",
"@getpaseo/client": "0.16.1",
"@getpaseo/protocol": "0.16.1",
"@getpaseo/server": "0.16.1",
"@getpaseo/client": "0.16.2",
"@getpaseo/protocol": "0.16.2",
"@getpaseo/server": "0.16.2",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"mime-types": "^2.1.35",
@@ -39890,11 +39890,11 @@
},
"packages/client": {
"name": "@getpaseo/client",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@getpaseo/protocol": "0.16.1",
"@getpaseo/relay": "0.16.1",
"@getpaseo/protocol": "0.16.2",
"@getpaseo/relay": "0.16.2",
"ws": "^8.20.0",
"zod": "^4.4.3"
},
@@ -39906,7 +39906,7 @@
},
"packages/desktop": {
"name": "@getpaseo/desktop",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@getpaseo/cli": "*",
@@ -40149,7 +40149,7 @@
},
"packages/expo-two-way-audio": {
"name": "@getpaseo/expo-two-way-audio",
"version": "0.16.1",
"version": "0.16.2",
"license": "MIT",
"devDependencies": {
"@types/jest": "^29.5.14",
@@ -40195,7 +40195,7 @@
},
"packages/highlight": {
"name": "@getpaseo/highlight",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@codemirror/language": "6.12.4",
@@ -40225,7 +40225,7 @@
},
"packages/plugin": {
"name": "@getpaseo/plugin",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@agentclientprotocol/sdk": "^1.4.0",
@@ -40233,8 +40233,8 @@
"use-sync-external-store": "^1.6.0"
},
"devDependencies": {
"@getpaseo/client": "0.16.1",
"@getpaseo/protocol": "0.16.1",
"@getpaseo/client": "0.16.2",
"@getpaseo/protocol": "0.16.2",
"@types/node": "^20.9.0",
"@types/react": "~19.2.0",
"react": "19.2.3",
@@ -40244,8 +40244,8 @@
"zod": "^4.4.3"
},
"peerDependencies": {
"@getpaseo/client": "0.16.1",
"@getpaseo/protocol": "0.16.1",
"@getpaseo/client": "0.16.2",
"@getpaseo/protocol": "0.16.2",
"react": ">=19.1.0 <20",
"react-native": ">=0.81.5",
"zod": "^4.4.3"
@@ -40267,7 +40267,7 @@
},
"packages/protocol": {
"name": "@getpaseo/protocol",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"semver": "^7.8.5",
@@ -40295,7 +40295,7 @@
},
"packages/relay": {
"name": "@getpaseo/relay",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@noble/ciphers": "^2.4.0",
@@ -40517,17 +40517,17 @@
},
"packages/server": {
"name": "@getpaseo/server",
"version": "0.16.1",
"version": "0.16.2",
"license": "Apache-2.0",
"dependencies": {
"@agentclientprotocol/sdk": "^0.17.1",
"@anthropic-ai/claude-agent-sdk": "0.3.326",
"@anthropic-ai/sdk": "^0.104.2",
"@getpaseo/client": "0.16.1",
"@getpaseo/highlight": "0.16.1",
"@getpaseo/plugin": "0.16.1",
"@getpaseo/protocol": "0.16.1",
"@getpaseo/relay": "0.16.1",
"@getpaseo/client": "0.16.2",
"@getpaseo/highlight": "0.16.2",
"@getpaseo/plugin": "0.16.2",
"@getpaseo/protocol": "0.16.2",
"@getpaseo/relay": "0.16.2",
"@isaacs/ttlcache": "^2.1.4",
"@modelcontextprotocol/sdk": "1.29.0",
"@opencode-ai/sdk": "1.14.46",
@@ -41474,7 +41474,7 @@
},
"packages/website": {
"name": "@getpaseo/website",
"version": "0.16.1",
"version": "0.16.2",
"dependencies": {
"@cloudflare/vite-plugin": "^1.29.1",
"@cloudflare/workers-types": "^4.20260317.1",
@@ -43084,7 +43084,7 @@
},
"plugins": {
"name": "@getpaseo/builtin-plugins",
"version": "0.16.1",
"version": "0.16.2",
"dependencies": {
"@getpaseo/plugin": "*",
"zod": "^4.4.3"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "paseo",
"version": "0.16.1",
"version": "0.16.2",
"private": true,
"description": "Paseo: voice-controlled development environment for local AI coding agents",
"keywords": [
@@ -2,22 +2,17 @@ import type { Locator } from "@playwright/test";
import { expect, test, type Page } from "../support/fixtures";
import { expectAgentIdle, expectAgentReadyToInterrupt } from "../support/helpers/agent-stream";
import {
blurComposerInput,
cancelAgent,
fillComposerDraft,
expectComposerDraft,
expectComposerNotFocused,
expectComposerVisible,
submitMessage,
} from "../support/helpers/composer";
import { expectNearBottom, scrollChatAwayFromBottom } from "../support/helpers/agent-bottom-anchor";
import { holdRewindCompletion } from "../support/helpers/agent-timeline-gate";
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
import { userScrollsTimelineToHistoryStart } from "../support/helpers/timeline-pagination";
import {
closeWorkspaceAgentTab,
fetchAgentArchivedAt,
primeAdditionalPage,
resetSeededPageState,
} from "../support/helpers/archive-tab";
async function completeSubmittedTurn(
page: Page,
@@ -53,194 +48,47 @@ async function expectTurnCompletesNormally(
await expectAgentIdle(page);
}
async function openAgentOnAnotherClient(
page: Page,
agent: Awaited<ReturnType<typeof seedMockAgentWorkspace>>,
): Promise<void> {
await primeAdditionalPage(page);
await resetSeededPageState(page);
await openAgentRoute(page, agent);
await expectComposerVisible(page);
}
/** The prompts the chat shows, in order, each exactly once. */
async function expectPrompts(page: Page, prompts: string[]): Promise<void> {
const messages = page.getByTestId("user-message");
await expect(messages).toHaveCount(prompts.length);
await expect(messages).toContainText(prompts);
}
async function reloadAgentFromTabMenu(page: Page, agentId: string): Promise<void> {
const tabId = `workspace-tab-agent_${agentId}`;
await page.getByTestId(tabId).filter({ visible: true }).first().click({ button: "right" });
await page.getByTestId(`workspace-tab-context-agent_${agentId}-reload-agent`).click();
}
async function archiveAgentByClosingTab(
page: Page,
agent: Awaited<ReturnType<typeof seedMockAgentWorkspace>>,
): Promise<void> {
await closeWorkspaceAgentTab(page, agent.agentId);
await expect.poll(() => fetchAgentArchivedAt(agent.client, agent.agentId)).not.toBeNull();
}
async function unarchiveAgent(page: Page): Promise<void> {
await page.getByRole("button", { name: "Unarchive", exact: true }).click();
await expect(page.getByText("This agent is archived", { exact: true })).toHaveCount(0, {
timeout: 30_000,
});
}
async function expectToast(page: Page, message: string): Promise<void> {
await expect(page.getByTestId("app-toast-message")).toHaveText(message, { timeout: 30_000 });
}
// The mock provider's resumed session holds no history, so it never matches what Paseo shows.
const UNSYNCED_RELOAD =
"Reloaded agent, but the provider's history doesn't match this chat, so it wasn't synced";
/** The prompts of the whole conversation, after scrolling up through its older pages. */
async function expectConversationPrompts(page: Page, prompts: string[]): Promise<void> {
const messages = page.getByTestId("user-message");
await expect
.poll(async () => {
await userScrollsTimelineToHistoryStart(page);
return await messages.count();
})
.toBe(prompts.length);
await expect(messages).toContainText(prompts);
}
// A row React remounts loses this attribute; one that stays mounted keeps it.
async function markMounted(row: Locator): Promise<void> {
await row.evaluate((element) => element.setAttribute("data-e2e-mounted", "before-rewind"));
}
async function expectStillMounted(row: Locator): Promise<void> {
await expect(row).toHaveAttribute("data-e2e-mounted", "before-rewind");
}
test.describe("Agent message rewind", () => {
test("rewinds a prompt in place on every open client and keeps a human draft", async ({
test("rewinds a submitted prompt without replaying history and preserves a human draft", async ({
page,
}) => {
test.setTimeout(150_000);
test.setTimeout(90_000);
const retainedPrompt = "Keep this completed turn after rewind.";
const rewoundPrompt = "Remove this completed turn after rewind.";
const nextPrompt = "Continue after the rewind.";
const preservedDraft = "Keep this human draft after rewind.";
const agent = await seedMockAgentWorkspace({
repoPrefix: "message-rewind-roundtrip-",
title: "Message rewind roundtrip",
model: "ten-second-stream",
});
const otherClient = await page.context().newPage();
try {
const rewindCompletion = await holdRewindCompletion(page, agent.agentId);
await openAgentRoute(page, agent);
await expectComposerVisible(page);
const retainedMessage = await completeSubmittedTurn(page, agent, retainedPrompt);
await completeSubmittedTurn(page, agent, retainedPrompt);
const userMessage = await completeSubmittedTurn(page, agent, rewoundPrompt);
await test.step("a second client opens the same chat", async () => {
await openAgentOnAnotherClient(otherClient, agent);
await expectPrompts(otherClient, [retainedPrompt, rewoundPrompt]);
});
await markMounted(retainedMessage);
await scrollChatAwayFromBottom(page, {
deltaY: -900,
minDistanceFromBottom: 300,
});
await fillComposerDraft(page, preservedDraft);
await blurComposerInput(page);
rewindCompletion.clearTimelineStreamCount();
await test.step("the rewind stays pending until the daemon answers", async () => {
const rewind = rewindConversation(page, userMessage, rewoundPrompt);
await rewindCompletion.waitForDelayedResponse();
await expect(page.getByTestId("rewind-menu-conversation")).toBeDisabled();
expect(rewindCompletion.timelineStreamCount()).toBe(0);
rewindCompletion.release();
await rewind;
});
const rewind = rewindConversation(page, userMessage, rewoundPrompt);
await rewindCompletion.waitForDelayedResponse();
await expect(page.getByTestId("rewind-menu-conversation")).toBeDisabled();
expect(rewindCompletion.timelineStreamCount()).toBe(0);
rewindCompletion.release();
await rewind;
await test.step("the rewound turn leaves without reloading the chat", async () => {
await expectPrompts(page, [retainedPrompt]);
await expectStillMounted(retainedMessage);
expect(rewindCompletion.timelineFetchCount()).toBe(0);
await expectComposerDraft(page, preservedDraft);
await expectNearBottom(page);
await expectPrompts(otherClient, [retainedPrompt]);
});
await test.step("the next prompt appears once on both clients", async () => {
await completeSubmittedTurn(otherClient, agent, nextPrompt);
await expectPrompts(otherClient, [retainedPrompt, nextPrompt]);
await expectPrompts(page, [retainedPrompt, nextPrompt]);
});
await test.step("a reconnecting client loads the rewound conversation", async () => {
await otherClient.reload();
await expectPrompts(otherClient, [retainedPrompt, nextPrompt]);
});
} finally {
await otherClient.close();
await agent.cleanup();
}
});
test("keeps the rewound conversation through Reload agent, archive and unarchive", async ({
page,
}) => {
test.setTimeout(150_000);
const keptPrompt = "Keep this turn through reload and archive.";
const rewoundPrompt = "Rewind this turn before reloading.";
const nextPrompt = "Continue after the rewind, then reload.";
const agent = await seedMockAgentWorkspace({
repoPrefix: "message-rewind-reload-archive-",
title: "Message rewind reload archive",
model: "ten-second-stream",
});
try {
await openAgentRoute(page, agent);
await expectComposerVisible(page);
await completeSubmittedTurn(page, agent, keptPrompt);
const rewound = await completeSubmittedTurn(page, agent, rewoundPrompt);
await rewindConversation(page, rewound, rewoundPrompt);
await expectPrompts(page, [keptPrompt]);
await completeSubmittedTurn(page, agent, nextPrompt);
await expectPrompts(page, [keptPrompt, nextPrompt]);
await test.step("Reload agent keeps the chat and says the provider's history was not synced", async () => {
await reloadAgentFromTabMenu(page, agent.agentId);
await expectToast(page, UNSYNCED_RELOAD);
await expectPrompts(page, [keptPrompt, nextPrompt]);
await expectComposerVisible(page);
});
await test.step("the archived chat shows the rewound conversation", async () => {
await archiveAgentByClosingTab(page, agent);
await openAgentRoute(page, agent);
await expect(page.getByText("This agent is archived", { exact: true })).toBeVisible({
timeout: 30_000,
});
await expectConversationPrompts(page, [keptPrompt, nextPrompt]);
});
await test.step("unarchiving keeps the rewound conversation", async () => {
await unarchiveAgent(page);
await expectToast(page, UNSYNCED_RELOAD);
await expectComposerVisible(page);
await expectConversationPrompts(page, [keptPrompt, nextPrompt]);
});
await test.step("a reconnecting client loads the same conversation", async () => {
await page.reload();
await expectComposerVisible(page);
await expectConversationPrompts(page, [keptPrompt, nextPrompt]);
});
await expect(page.getByTestId("user-message").filter({ hasText: rewoundPrompt })).toHaveCount(
0,
);
await expectComposerDraft(page, preservedDraft);
await expectComposerNotFocused(page);
await expectNearBottom(page);
} finally {
await agent.cleanup();
}
+8 -5
View File
@@ -26,7 +26,7 @@ test.use({
},
});
// Rendered light-theme colors: palette yellow 400 for Fast and Ultrafast, muted foreground for Normal.
// The Speed icon highlights any explicit tier other than Normal.
const ACTIVE_SPEED_COLOR = "rgb(251, 191, 36)";
const NORMAL_SPEED_COLOR = "rgb(113, 113, 122)";
@@ -63,7 +63,7 @@ async function expectSpeedIconColor(page: Page, color: string): Promise<void> {
}
async function expectSpeedChoices(page: Page, choices: string[]): Promise<void> {
for (const choice of ["Normal", "Fast", "Ultrafast"]) {
for (const choice of ["Normal", "Flex", "Fast", "Ultrafast"]) {
const option = page.getByText(choice, { exact: true }).last();
if (choices.includes(choice)) {
await expect(option).toBeVisible();
@@ -115,21 +115,24 @@ for (const viewport of [
await expectSpeedIconColor(page, ACTIVE_SPEED_COLOR);
await page.screenshot({ path: testInfo.outputPath(`${viewport.name}-fast-selected.png`) });
await openSpeedSelector(page);
await expectSpeedChoices(page, ["Normal", "Fast", "Ultrafast"]);
await expectSpeedChoices(page, ["Normal", "Flex", "Fast", "Ultrafast"]);
await page.screenshot({ path: testInfo.outputPath(`${viewport.name}-speed-options.png`) });
await selectSpeed(page, "Ultrafast");
await expectSpeedIconColor(page, ACTIVE_SPEED_COLOR);
await openSpeedSelector(page);
await expectSpeedChoices(page, ["Normal", "Fast", "Ultrafast"]);
await expectSpeedChoices(page, ["Normal", "Flex", "Fast", "Ultrafast"]);
await page.screenshot({
path: testInfo.outputPath(`${viewport.name}-ultrafast-selected.png`),
});
await selectSpeed(page, "Flex");
await expectSpeedIconColor(page, ACTIVE_SPEED_COLOR);
await openSpeedSelector(page);
await selectSpeed(page, "Normal");
await expectSpeedIconColor(page, NORMAL_SPEED_COLOR);
if (viewport.name === "desktop") {
await switchAgentModel(agent.id, "gpt-6-sol");
await openSpeedSelector(page);
await expectSpeedChoices(page, ["Normal", "Fast"]);
await expectSpeedChoices(page, ["Normal", "Flex", "Fast"]);
await page.screenshot({ path: testInfo.outputPath("desktop-fast-only.png") });
}
} finally {
@@ -1,6 +1,17 @@
import { expect, test } from "../support/fixtures";
import type { FormPreferences } from "@/create-agent-preferences/preferences";
import { closeCommandCenter, openCommandCenter } from "../support/helpers/command-center";
import {
closeCommandCenter,
openCommandCenter,
openCommandCenterWithShortcut,
} from "../support/helpers/command-center";
import {
enterComposerFullscreen,
exitComposerFullscreen,
expectComposerVisible,
fillComposerDraft,
resizeComposerViewport,
} from "../support/helpers/composer";
import {
applyCommandCenterAgentControls,
chooseCommandCenterAgentControl,
@@ -14,8 +25,18 @@ import {
} from "../support/helpers/command-center-agent-controls";
import { clickNewChat, gotoWorkspace } from "../support/helpers/launcher";
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
import {
assertNewWorkspaceSidebarAndHeader,
connectNewWorkspaceDaemonClient,
openGlobalNewWorkspaceComposer,
selectNewWorkspaceProject,
selectWorkspaceIsolation,
submitNewWorkspacePrompt,
} from "../support/helpers/new-workspace";
import { getServerId } from "../support/helpers/server-id";
import { expectAppRoute } from "../support/helpers/route-assertions";
import { seedWorkspace } from "../support/helpers/seed-client";
import { closeMobileAgentSidebar, openMobileAgentSidebar } from "../support/helpers/sidebar";
import { buildSchedulesRoute } from "@/utils/host-routes";
const CREATE_AGENT_PREFERENCES_KEY = "@paseo:create-agent-preferences";
@@ -30,7 +51,7 @@ async function seedMockDraftPreferences(page: import("@playwright/test").Page):
providerPreferences: {
mock: {
model: "five-minute-stream",
mode: "load-test",
mode: "approval-test",
},
},
} satisfies FormPreferences),
@@ -221,6 +242,94 @@ test.describe("Command Center agent controls", () => {
await workspace.cleanup();
}
});
test("applies New workspace model and mode choices before the first message", async ({
page,
}) => {
const workspace = await seedWorkspace({ repoPrefix: "command-center-new-workspace-controls-" });
await seedMockDraftPreferences(page);
const client = await connectNewWorkspaceDaemonClient();
try {
const backgroundAgent = await workspace.client.createAgent({
provider: "mock",
cwd: workspace.repoPath,
workspaceId: workspace.workspaceId,
title: "Background agent",
model: "five-minute-stream",
modeId: "approval-test",
});
await openAgentRoute(page, {
workspaceId: workspace.workspaceId,
agentId: backgroundAgent.id,
});
await openGlobalNewWorkspaceComposer(page);
await selectNewWorkspaceProject(page, workspace);
await selectWorkspaceIsolation(page, "local");
await applyCommandCenterAgentControls(page, DRAFT_AGENT_CONTROL_CHOICES);
await closeCommandCenter(page);
await submitNewWorkspacePrompt(page, "Create with Command Center choices");
const created = await assertNewWorkspaceSidebarAndHeader(page, {
serverId: getServerId(),
client,
previousWorkspaceId: workspace.workspaceId,
projectDisplayName: workspace.projectDisplayName,
});
await expectWorkspaceAgentConfiguration(
{ client: workspace.client, workspaceId: created.workspaceId },
{ provider: "mock", model: "ten-second-stream", modeId: "load-test" },
);
await expectWorkspaceAgentConfiguration(workspace, {
id: backgroundAgent.id,
provider: "mock",
model: "five-minute-stream",
modeId: "approval-test",
});
} finally {
await client.close().catch(() => undefined);
await workspace.cleanup();
}
});
test("keeps draft settings searchable from the compact sidebar and fullscreen editor", async ({
page,
}) => {
const workspace = await seedWorkspace({ repoPrefix: "command-center-fullscreen-draft-" });
await seedMockDraftPreferences(page);
try {
await openDraftComposer(page, workspace.workspaceId);
await resizeComposerViewport(page, "portrait");
await applyCompactComposerSettings(page);
} finally {
await workspace.cleanup();
}
});
test("applies compact sidebar and fullscreen settings to the running agent", async ({ page }) => {
const workspace = await seedMockAgentWorkspace({
repoPrefix: "command-center-fullscreen-agent-",
title: "Compact Command Center settings",
model: "five-minute-stream",
modeId: "approval-test",
});
try {
await resizeComposerViewport(page, "portrait");
await openAgentRoute(page, workspace);
await applyCompactComposerSettings(page);
await expectWorkspaceAgentConfiguration(workspace, {
id: workspace.agentId,
provider: "mock",
model: "ten-second-stream",
modeId: "load-test",
});
} finally {
await workspace.cleanup();
}
});
});
const DRAFT_AGENT_CONTROL_CHOICES = [
@@ -233,3 +342,22 @@ async function openDraftComposer(page: import("@playwright/test").Page, workspac
await clickNewChat(page);
await waitForDraftComposer(page);
}
async function applyCompactComposerSettings(page: import("@playwright/test").Page): Promise<void> {
const [model, mode] = DRAFT_AGENT_CONTROL_CHOICES;
await expectComposerVisible(page);
await openMobileAgentSidebar(page);
await openCommandCenter(page);
await chooseCommandCenterAgentControl({ page, ...mode });
await closeMobileAgentSidebar(page);
await fillComposerDraft(page, "First line\nSecond line\nThird line");
await enterComposerFullscreen(page);
await openCommandCenterWithShortcut(page);
await chooseCommandCenterAgentControl({ page, ...model });
await exitComposerFullscreen(page);
await openCommandCenterWithShortcut(page);
await expectCommandCenterAgentControlSelected({ page, ...model });
await expectCommandCenterAgentControlSelected({ page, ...mode });
}
@@ -1,4 +1,4 @@
import { test, expect } from "../support/fixtures";
import { test, expect, type Page } from "../support/fixtures";
import { openWorkspaceWithAgents } from "../support/helpers/archive-tab";
import {
composerLocator,
@@ -311,3 +311,88 @@ test.describe("Composer trailing disc on a new chat", () => {
}
});
});
const SHORTCUT_MOD = process.platform === "darwin" ? "Meta" : "Control";
async function toggleModelPickerFromComposer(page: Page) {
await composerLocator(page).focus();
await page.keyboard.press(`${SHORTCUT_MOD}+Slash`);
}
async function expectModelPickerClosesFromSearch(page: Page) {
const search = page.getByPlaceholder(/Search (all )?models/);
await expect(search).toBeVisible();
await search.focus();
await page.keyboard.press(`${SHORTCUT_MOD}+Slash`);
await expect(search).toBeHidden();
}
async function cycleComposerEffort(page: Page) {
await composerLocator(page).focus();
await page.keyboard.press(`${SHORTCUT_MOD}+Shift+Slash`);
}
function modelControl(page: Page) {
return page.getByRole("button", { name: "Select model (Ten second stream)", exact: true });
}
function thinkingControl(page: Page, effort: string) {
return page.getByRole("button", { name: `Select thinking option (${effort})`, exact: true });
}
async function expectShortcutHint(
page: Page,
control: ReturnType<typeof modelControl>,
label: string,
) {
await control.hover();
const tooltip = page.getByRole("tooltip").filter({ hasText: label });
await expect(tooltip).toContainText("/");
}
test.describe("Composer model and effort shortcuts", () => {
test("opens and closes the model picker and wraps effort in toolbar order", async ({ page }) => {
const agent = await seedMockAgentWorkspace({
repoPrefix: "composer-shortcuts-",
title: "Composer shortcuts",
model: "ten-second-stream",
thinkingOptionId: "high",
});
try {
await openAgentRoute(page, agent);
await expectComposerVisible(page);
await expect(thinkingControl(page, "High")).toBeVisible();
await test.step("Focus model search without opening its tooltip", async () => {
await toggleModelPickerFromComposer(page);
await expect(page.getByPlaceholder(/Search (all )?models/)).toBeFocused();
await expect(page.getByRole("tooltip").filter({ hasText: "Change model" })).toBeHidden();
await expectModelPickerClosesFromSearch(page);
});
await test.step("Show both shortcuts in the toolbar tooltips", async () => {
await expectShortcutHint(page, modelControl(page), "Change model");
await expectShortcutHint(page, thinkingControl(page, "High"), "Thinking mode");
});
await test.step("Wrap from High to Low and advance to Medium", async () => {
await cycleComposerEffort(page);
await expect(thinkingControl(page, "Low")).toBeVisible();
await cycleComposerEffort(page);
await expect(thinkingControl(page, "Medium")).toBeVisible();
});
await test.step("Toggle the folded picker and cycle effort in a compact window", async () => {
await page.setViewportSize({ width: 480, height: 844 });
const effortLabel = page.getByTestId("combined-model-selector-thinking-label");
await expect(effortLabel).toHaveText("Medium");
await toggleModelPickerFromComposer(page);
await expectModelPickerClosesFromSearch(page);
await cycleComposerEffort(page);
await expect(effortLabel).toHaveText("High");
});
} finally {
await agent.cleanup();
}
});
});
@@ -513,3 +513,37 @@ test("compact file sheets cover Explorer and return to its retained file list",
await workspace.cleanup();
}
});
async function toggleCommentInMainEditor(page: Parameters<typeof ensureExplorerSidebar>[0]) {
const editor = page.getByLabel("Source editor for comment.cs").getByRole("textbox");
await expect(editor).toBeVisible();
await editor.press(process.platform === "darwin" ? "Meta+Slash" : "Control+Slash");
await expect(editor).toHaveText("// public class Example {}");
}
test("keeps the comment shortcut in the editor beside an Explorer agent", async ({ page }) => {
const workspace = await seedMockAgentWorkspace({
repoPrefix: "explorer-comment-shortcut-",
title: "Chat beside the editor",
model: "ten-second-stream",
});
try {
await writeFile(`${workspace.cwd}/comment.cs`, "public class Example {}");
await openAgentRoute(page, workspace);
await expect(
page.getByRole("button", { name: "Select model (Ten second stream)" }),
).toBeVisible();
await ensureExplorerSidebar(page);
await dragTabIntoExplorer(page, `agent_${workspace.agentId}`);
await expect(
explorerSidebar(page).getByRole("button", { name: "Select model (Ten second stream)" }),
).toBeVisible();
await openFilesPanel(page);
await openFileFromExplorer(page, "comment.cs");
await explorerSidebar(page).getByTestId(`workspace-tab-agent_${workspace.agentId}`).click();
await toggleCommentInMainEditor(page);
await expect(page.getByPlaceholder(/Search (all )?models/)).toBeHidden();
} finally {
await workspace.cleanup();
}
});
+45 -2
View File
@@ -777,7 +777,9 @@ test.describe("CodeMirror workspace file editing", () => {
await replaceEditorText(page, "# Saved from source\n");
await expect(page.getByTestId("workspace-tab-modified-file_notes.md")).toBeVisible();
await selectFileView(page, "Preview");
await expect(visibleFilePane.getByText("Saved from source", { exact: true })).toBeVisible();
await expect(
visibleFilePane.getByRole("heading", { name: "Saved from source", exact: true }),
).toBeVisible();
await expect(toolbar.getByLabel("Line 1, column 1")).toHaveCount(0);
await expect.poll(() => readFile(markdownPath, "utf8")).toBe("# Saved from source\n");
await expect(page.getByTestId("workspace-tab-modified-file_notes.md")).not.toBeVisible();
@@ -864,11 +866,52 @@ test.describe("CodeMirror workspace file editing", () => {
await selectFileView(page, "Source");
await expect(page.getByTestId("file-source-editor")).toBeVisible();
await expect(preview.host).toHaveCount(0);
await expect(preview.host).toBeHidden();
await selectFileView(page, "Preview");
await expect(preview.host).toBeVisible();
});
test("shows the changed HTML page after the file changes on disk while Source shows", async ({
page,
withWorkspace,
}) => {
const workspace = await withWorkspace({ prefix: "file-editing-html-hidden-change-" });
const htmlPath = path.join(workspace.repoPath, "plan.html");
await writeFile(htmlPath, "<!doctype html><html><body><h1>First plan</h1></body></html>");
await workspace.navigateTo();
await openWorkspaceFile(page, "plan.html");
const preview = htmlPreview(page);
await expect(preview.document.getByRole("heading", { name: "First plan" })).toBeVisible();
await selectFileView(page, "Source");
await writeFile(htmlPath, "<!doctype html><html><body><h1>Changed on disk</h1></body></html>");
await expect(editor(page)).toContainText("Changed on disk");
await selectFileView(page, "Preview");
await expect(preview.document.getByRole("heading", { name: "Changed on disk" })).toBeVisible();
});
test("shows the HTML page edited in Source when Preview shows again", async ({
page,
withWorkspace,
}) => {
const workspace = await withWorkspace({ prefix: "file-editing-html-hidden-edit-" });
await writeFile(
path.join(workspace.repoPath, "plan.html"),
"<!doctype html><html><body><h1>First plan</h1></body></html>",
);
await workspace.navigateTo();
await openWorkspaceFile(page, "plan.html");
const preview = htmlPreview(page);
await expect(preview.document.getByRole("heading", { name: "First plan" })).toBeVisible();
await selectFileView(page, "Source");
await replaceEditorText(page, "<!doctype html><html><body><h1>Edited plan</h1></body></html>");
await selectFileView(page, "Preview");
await expect(preview.document.getByRole("heading", { name: "Edited plan" })).toBeVisible();
});
test("keeps HTML fragment links in the preview and scrolls to the target", async ({
page,
withWorkspace,
@@ -0,0 +1,130 @@
import { writeFile } from "node:fs/promises";
import path from "node:path";
import { expect, test, type Page } from "../support/fixtures";
import { openFileExplorer, openFileFromExplorer } from "../support/helpers/file-explorer";
// Switching a file tab between Preview and Source returns to where each view was left.
const sections = Array.from({ length: 200 }, (_, index) => index);
const LONG_MARKDOWN = sections.map((i) => `## Section ${i}\n\nParagraph ${i}.\n`).join("\n");
const LONG_HTML = `<!doctype html><html><body>${sections
.map((i) => `<h2>Section ${i}</h2><p>Paragraph ${i}</p>`)
.join("")}</body></html>`;
type FileView = "markdown preview" | "html preview" | "source";
function htmlPreviewFrame(page: Page) {
const frame = page.frames().find((candidate) => candidate.url().startsWith("data:text/html"));
if (!frame) throw new Error("The HTML preview frame is not loaded.");
return frame;
}
/**
* Moves the view's visible scroller to `offset` when given, and returns its offset. The
* scroller is Markdown's scroll view, CodeMirror's scroller, or the HTML page itself.
*/
async function viewScroll(page: Page, view: FileView, offset?: number): Promise<number> {
if (view === "html preview") {
return htmlPreviewFrame(page).evaluate((target) => {
if (target !== undefined) window.scrollTo(0, target);
return window.scrollY;
}, offset);
}
return page.evaluate(
(input) => {
const visible = (element: HTMLElement) => element.offsetParent !== null;
let scroller: HTMLElement | null;
if (input.view === "source") {
scroller =
[...document.querySelectorAll<HTMLElement>(".cm-scroller")].find(visible) ?? null;
} else {
scroller =
[
...document.querySelectorAll<HTMLElement>('[data-testid="markdown-preview-frame"]'),
].find(visible) ?? null;
while (scroller && !(scroller.scrollHeight > scroller.clientHeight + 10)) {
scroller = scroller.parentElement;
}
}
if (!scroller) throw new Error(`No visible scroller for the ${input.view}.`);
if (input.offset !== undefined) scroller.scrollTop = input.offset;
return scroller.scrollTop;
},
{ view, offset },
);
}
async function openLongFile(
page: Page,
withWorkspace: (options?: { prefix?: string }) => Promise<{
repoPath: string;
navigateTo(): Promise<void>;
}>,
name: string,
content: string,
): Promise<void> {
const workspace = await withWorkspace({ prefix: "file-view-scroll-" });
await writeFile(path.join(workspace.repoPath, name), content);
await workspace.navigateTo();
await openFileExplorer(page);
await openFileFromExplorer(page, name);
await expect(page.getByTestId("file-mode-preview")).toBeVisible({ timeout: 30_000 });
}
async function showView(page: Page, view: "preview" | "source"): Promise<void> {
await page.getByTestId(`file-mode-${view}`).click();
}
/** Scrolls the view past the first screen and returns where it settled. */
async function scrollDown(page: Page, view: FileView): Promise<number> {
await expect(async () => {
expect(await viewScroll(page, view, 1200)).toBeGreaterThan(1000);
}).toPass({ timeout: 15_000 });
// CodeMirror can adjust the offset once after a scroll; read it after that settles.
await page.waitForTimeout(300);
return viewScroll(page, view);
}
async function expectOffsetKept(page: Page, view: FileView, offset: number): Promise<void> {
await expect.poll(() => viewScroll(page, view), { timeout: 5_000 }).toBe(offset);
}
test("Markdown preview keeps its scroll offset after showing Source", async ({
page,
withWorkspace,
}) => {
await openLongFile(page, withWorkspace, "long.md", LONG_MARKDOWN);
const offset = await scrollDown(page, "markdown preview");
await showView(page, "source");
await expect(page.getByTestId("file-source-editor")).toBeVisible();
await showView(page, "preview");
await expectOffsetKept(page, "markdown preview", offset);
});
test("HTML preview keeps its scroll offset after showing Source", async ({
page,
withWorkspace,
}) => {
await openLongFile(page, withWorkspace, "long.html", LONG_HTML);
const offset = await scrollDown(page, "html preview");
await showView(page, "source");
await expect(page.getByTestId("file-source-editor")).toBeVisible();
await showView(page, "preview");
await expectOffsetKept(page, "html preview", offset);
});
test("Source keeps its scroll offset after showing Preview", async ({ page, withWorkspace }) => {
await openLongFile(page, withWorkspace, "long.md", LONG_MARKDOWN);
await showView(page, "source");
const offset = await scrollDown(page, "source");
await showView(page, "preview");
await expect(page.getByTestId("markdown-preview-frame")).toBeVisible();
await showView(page, "source");
await expectOffsetKept(page, "source", offset);
});
@@ -16,6 +16,13 @@ import {
expectComposerFullscreenControls,
} from "../support/helpers/composer";
import { waitForSidebarHydration } from "../support/helpers/workspace-ui";
import {
seedTerminalProfiles,
selectLaunchOption,
terminalPromptInput,
} from "../support/helpers/new-workspace-launch";
test.use({ channel: "chromium", launchOptions: { args: ["--use-fake-device-for-media-stream"] } });
type WebSocketMessage = string | Buffer;
@@ -254,3 +261,82 @@ test("dictation shortcut leaves retained fullscreen and exposes recording contro
await agent.cleanup();
}
});
async function controlMicrophonePermission(page: Page) {
const cdp = await page.context().newCDPSession(page);
const { targetInfo } = await cdp.send("Target.getTargetInfo");
const origin = new URL(page.url()).origin;
return async (setting: "denied" | "granted") => {
await cdp.send("Browser.setPermission", {
permission: { name: "microphone" },
setting,
origin,
browserContextId: targetInfo.browserContextId,
});
};
}
function startDictationByMic(page: Page) {
return page.getByRole("button", { name: "Start dictation", exact: true }).click();
}
function expectDictationPermissionError(page: Page) {
return expect(page.getByTestId("message-input-root").getByRole("alert")).toHaveText(
"Allow microphone access and try again.",
);
}
test("keeps the draft and retries from the mic after access is restored", async ({ page }) => {
const agent = await seedMockAgentWorkspace({
repoPrefix: "dictation-permission-",
title: "Dictation permission",
});
const draft = "Keep my draft";
await installDictationFailureHarness(page);
try {
await openAgentRoute(page, agent);
await expectComposerVisible(page);
await fillComposerDraft(page, draft);
const setMicrophonePermission = await controlMicrophonePermission(page);
await setMicrophonePermission("denied");
await startDictationByMic(page);
await expectDictationPermissionError(page);
await expect(composerLocator(page)).toHaveValue(draft);
await setMicrophonePermission("granted");
await startDictationByMic(page);
await expect(page.getByRole("button", { name: "Cancel dictation", exact: true })).toBeVisible();
await expect(page.getByText("Allow microphone access and try again.")).toHaveCount(0);
await page.getByRole("button", { name: "Cancel dictation", exact: true }).click();
await expect(composerLocator(page)).toHaveValue(draft);
} finally {
await agent.cleanup();
}
});
test("shows dictation failure when the terminal prompt starts it by shortcut", async ({ page }) => {
const workspace = await seedWorkspace({ repoPrefix: "terminal-dictation-permission-" });
const profile = {
id: "echo-prompt",
name: "Echo prompt",
command: "echo",
args: ["{{{prompt}}}"],
};
const profiles = await seedTerminalProfiles([profile]);
await installDictationFailureHarness(page);
try {
await gotoAppShell(page);
await waitForSidebarHydration(page);
await openNewWorkspaceComposer(page, workspace);
await selectLaunchOption(page, profile.id);
const setMicrophonePermission = await controlMicrophonePermission(page);
await setMicrophonePermission("denied");
await terminalPromptInput(page).press("Control+d");
await expectDictationPermissionError(page);
} finally {
await profiles.restore();
await workspace.cleanup();
}
});
@@ -1,4 +1,6 @@
import { execSync } from "node:child_process";
import { existsSync } from "node:fs";
import { realpath } from "node:fs/promises";
import path from "node:path";
import { buildHostWorkspaceRoute } from "@/utils/host-routes";
import { expect, test } from "../support/fixtures";
@@ -890,6 +892,53 @@ test.describe("New workspace flow", () => {
});
});
test("existing worktree starts the first agent in the chosen worktree", async ({ page }) => {
const tempRepo = await createTempGitRepo("existing-worktree-");
// Made with git, not Paseo: the list holds every git worktree of the repository.
const worktreePath = path.join(tempRepo.path, "manual-worktree");
execSync(`git worktree add -b e2e/manual ${JSON.stringify(worktreePath)}`, {
cwd: tempRepo.path,
stdio: "ignore",
});
try {
const openedProject = await openProjectViaDaemon(client, tempRepo.path);
localWorkspaceIds.add(openedProject.workspaceId);
localProjectIds.add(openedProject.projectId);
await gotoAppShell(page);
await waitForSidebarHydration(page);
await openNewWorkspaceComposer(page, {
projectKey: openedProject.projectKey,
projectDisplayName: openedProject.projectDisplayName,
});
await selectWorkspaceIsolation(page, "existing");
await expect(page.getByTestId("new-workspace-worktree-picker-trigger")).toContainText(
"e2e/manual",
);
await submitNewWorkspacePrompt(page);
const createdWorkspace = await assertNewWorkspaceSidebarAndHeader(page, {
serverId: getServerId(),
client,
previousWorkspaceId: openedProject.workspaceId,
projectDisplayName: openedProject.projectDisplayName,
});
localWorkspaceIds.add(createdWorkspace.workspaceId);
expect(await realpath(createdWorkspace.workspaceDirectory)).toBe(
await realpath(worktreePath),
);
const agentTabs = page
.getByTestId(`workspace-deck-entry-${getServerId()}:${createdWorkspace.workspaceId}`)
.filter({ visible: true })
.locator('[data-testid^="workspace-tab-agent_"]');
await expect(agentTabs).toHaveCount(1, { timeout: 30_000 });
} finally {
await tempRepo.cleanup();
}
});
test("branch picker opens via keyboard and selects the filtered option on Enter", async ({
page,
}) => {
@@ -1,16 +1,29 @@
import type { Locator } from "@playwright/test";
import { expect, test, type Page } from "../support/fixtures";
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
import { installDaemonWebSocketGate } from "../support/helpers/daemon-websocket-gate";
import { scrollChatAwayFromBottom } from "../support/helpers/agent-bottom-anchor";
import {
closeCommandCenter,
openCommandCenter,
selectCommandCenterTab,
} from "../support/helpers/command-center";
import { installDaemonWebSocketGate } from "../support/helpers/daemon-websocket-gate";
import {
attachComposerTestImage,
composerLocator,
expectComposerDraft,
expectComposerFocused,
expectComposerNotFocused,
expectComposerVisible,
fillComposerDraft,
submitMessage,
submitMessageWithButton,
} from "../support/helpers/composer";
import { readReplicaCache, writeReplicaCache } from "../support/helpers/replica-cache-storage";
import {
disconnectViewedTimeline,
releaseHeldCatchUp,
restoreViewedTimelineHoldingCatchUp,
} from "../support/helpers/timeline-resume";
// UI plumbing contract against the dev mock provider. Real-provider behavior is tested in `daemon-e2e/*-rewind.real.e2e.test.ts`.
@@ -33,6 +46,17 @@ async function selectRewindOption(page: Page, name: string): Promise<void> {
await option.click();
}
async function searchRewindActions(page: Page): Promise<Locator> {
const palette = await openCommandCenter(page);
await selectCommandCenterTab(palette, "Actions");
await palette.getByRole("textbox").fill("rewind last turn");
return palette;
}
function rewindAction(palette: Locator, name: string): Locator {
return palette.getByRole("button", { name: `${name} This action cannot be undone`, exact: true });
}
async function rewriteCachedMessageAsLegacyRow(
page: Page,
input: { prompt: string; agentId: string; workspaceId: string },
@@ -199,10 +223,6 @@ test.describe("Rewind sheet", () => {
await expectUserMessageCount(page, 2);
await session.client.waitForFinish(session.agentId);
await scrollChatAwayFromBottom(page, {
deltaY: -900,
minDistanceFromBottom: 300,
});
await userMessage(page, firstPrompt).hover();
await page.getByTestId("rewind-menu-trigger").first().click();
const rewindSheet = page.getByTestId("rewind-menu-content");
@@ -215,14 +235,15 @@ test.describe("Rewind sheet", () => {
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
await expect(userMessage(page, secondPrompt)).toHaveCount(0);
await expect(page.getByText("Cycle 1", { exact: true })).toHaveCount(0);
await expectUserMessageCount(page, 0);
await expectUserMessageCount(page, 1);
await expectComposerDraft(page, firstPrompt);
await expectComposerFocused(page);
await submitMessage(page, replacementPrompt);
await expectUserMessageVisible(page, replacementPrompt);
await expect(userMessage(page, secondPrompt)).toHaveCount(0);
await expect(page.getByText("Cycle 1", { exact: true })).toHaveCount(0);
await expectUserMessageCount(page, 1);
await expectUserMessageCount(page, 2);
await fillComposerDraft(page, "");
await composerLocator(page).evaluate((element) => element.blur());
@@ -232,18 +253,8 @@ test.describe("Rewind sheet", () => {
await selectRewindOption(page, "Rewind files");
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
await expectComposerDraft(page, "");
await expectUserMessageCount(page, 1);
const preservedDraft = "Keep this human draft after rewind.";
await fillComposerDraft(page, preservedDraft);
await composerLocator(page).evaluate((element) => element.blur());
await userMessage(page, replacementPrompt).hover();
await page.getByTestId("rewind-menu-trigger").last().click();
await expect(page.getByTestId("rewind-menu-content")).toBeVisible();
await selectRewindOption(page, "Rewind files");
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
await expectComposerDraft(page, preservedDraft);
await expectUserMessageCount(page, 1);
await expectComposerNotFocused(page);
await expectUserMessageCount(page, 2);
await fillComposerDraft(page, "");
await composerLocator(page).evaluate((element) => element.blur());
@@ -253,7 +264,104 @@ test.describe("Rewind sheet", () => {
await selectRewindOption(page, "Rewind conversation and files");
await expect(page.getByTestId("rewind-menu-content")).toHaveCount(0);
await expectComposerDraft(page, replacementPrompt);
await expectUserMessageCount(page, 0);
await expectComposerFocused(page);
await expectUserMessageCount(page, 1);
} finally {
await session.cleanup();
}
});
test("rewinds the latest turn from the Command Center", async ({ page }) => {
const firstPrompt = "Keep this earlier turn.";
const latestPrompt = "Edit this latest turn.";
const session = await seedMockAgentWorkspace({
repoPrefix: "rewind-command-center-e2e-",
title: "Command Center rewind",
initialPrompt: firstPrompt,
});
try {
await openAgentRoute(page, session);
await expectComposerVisible(page);
await submitMessage(page, latestPrompt);
await expectUserMessageVisible(page, latestPrompt);
await session.client.waitForFinish(session.agentId);
const palette = await searchRewindActions(page);
await expect(rewindAction(palette, "Rewind files")).toBeVisible();
await expect(rewindAction(palette, "Rewind conversation and files")).toBeVisible();
await rewindAction(palette, "Rewind conversation").click();
await expectUserMessageVisible(page, firstPrompt);
await expect(userMessage(page, latestPrompt)).toHaveCount(0);
await expectComposerDraft(page, latestPrompt);
await expectComposerFocused(page);
} finally {
await session.cleanup();
}
});
test("waits for the latest prompt before offering Command Center rewind after reconnect", async ({
page,
}) => {
const cachedPrompt = "Keep the prompt that was visible before reconnect.";
const latestPrompt = "Rewind the prompt sent while the app was disconnected.";
const gate = await installDaemonWebSocketGate(page);
const session = await seedMockAgentWorkspace({
repoPrefix: "rewind-reconnect-e2e-",
title: "Rewind after reconnect",
initialPrompt: cachedPrompt,
});
try {
await openAgentRoute(page, session);
await expectUserMessageVisible(page, cachedPrompt);
const initialPalette = await searchRewindActions(page);
await expect(rewindAction(initialPalette, "Rewind conversation")).toBeVisible();
await closeCommandCenter(page);
await disconnectViewedTimeline(page, gate);
await session.client.sendAgentMessage(session.agentId, latestPrompt);
await session.client.waitForFinish(session.agentId);
await restoreViewedTimelineHoldingCatchUp(page, gate);
const palette = await searchRewindActions(page);
await expect(palette.getByText("No matches", { exact: true })).toBeVisible();
await releaseHeldCatchUp(page, gate);
await rewindAction(palette, "Rewind conversation").click();
await expectUserMessageVisible(page, cachedPrompt);
await expectComposerDraft(page, latestPrompt);
} finally {
gate.restore();
await session.cleanup();
}
});
test("hides rewind when the latest prompt only contains an attachment", async ({ page }) => {
const session = await seedMockAgentWorkspace({
repoPrefix: "rewind-image-only-e2e-",
title: "Rewind image-only prompt",
initialPrompt: "Earlier text prompt.",
});
try {
await openAgentRoute(page, session);
await expectComposerVisible(page);
const palette = await searchRewindActions(page);
await expect(rewindAction(palette, "Rewind conversation")).toBeVisible();
await closeCommandCenter(page);
await attachComposerTestImage(page);
await submitMessageWithButton(page, "");
const imagePrompt = page.getByTestId("user-message").filter({
has: page.getByRole("button", { name: "Open image attachment" }),
});
await expect(imagePrompt).toHaveAttribute("aria-busy", "false");
await session.client.waitForFinish(session.agentId);
const reopened = await searchRewindActions(page);
await expect(reopened.getByText("No matches", { exact: true })).toBeVisible();
} finally {
await session.cleanup();
}
@@ -277,6 +385,10 @@ test.describe("Rewind sheet", () => {
await expectUserMessageVisible(page, firstPrompt);
const palette = await searchRewindActions(page);
await rewindAction(palette, "Rewind conversation").click();
await expect(page.getByTestId("app-toast-message")).toHaveText(rewindError);
await userMessage(page, firstPrompt).hover();
await page.getByTestId("rewind-menu-trigger").first().click();
const rewindSheet = page.getByTestId("rewind-menu-content");
@@ -362,7 +362,7 @@ test.describe("Schedules project target", () => {
).toHaveCount(0);
await page.getByTestId("schedule-isolation-trigger").click();
await page.getByTestId("schedule-isolation-worktree").click();
await expect(page.getByTestId("schedule-isolation-trigger")).toContainText("Worktree");
await expect(page.getByTestId("schedule-isolation-trigger")).toContainText("New worktree");
await page.getByTestId("schedule-archive-on-finish-switch").click();
await page.getByLabel("Schedule name").fill(scheduleName);
await page.getByLabel("Prompt").fill("Run with custom workspace cleanup.");
@@ -383,7 +383,7 @@ test.describe("Schedules project target", () => {
const formSheet = page.getByTestId("schedule-form-sheet");
await expect(formSheet).toBeVisible({ timeout: 10_000 });
await expectStableHeight(formSheet);
await expect(page.getByTestId("schedule-isolation-trigger")).toContainText("Worktree");
await expect(page.getByTestId("schedule-isolation-trigger")).toContainText("New worktree");
await expect(page.getByTestId("schedule-archive-on-finish-switch")).toHaveAttribute(
"aria-checked",
"false",
@@ -503,6 +503,35 @@ test.describe("terminal history with a finger", () => {
await expectMouseWheelScrollsHistory(page);
});
test("finger scrolling leaves the keyboard closed and a tap focuses input", async ({ page }) => {
await openPhoneTerminalHistory(page);
await input(page).evaluate((element) => element.blur());
await expect(input(page)).not.toBeFocused();
await expectSingleFingerScroll(page, 24);
await expect(input(page)).not.toBeFocused();
await expectSingleFingerScroll(page, 1);
await expect(input(page)).not.toBeFocused();
await tapTerminalScreen(page);
await expect(input(page)).toBeFocused();
// Android's Back button hides the IME without blurring this input.
await expectSingleFingerScroll(page, 24);
await expect(input(page)).not.toBeFocused();
await terminalScreen(page).click();
await expect(input(page)).toBeFocused();
});
test("finger scrolling keeps an open keyboard open", async ({ page }) => {
await openPhoneTerminalHistory(page);
await tapTerminalScreen(page);
await expect(input(page)).toBeFocused();
await showSoftwareKeyboard(page);
await expectSingleFingerScroll(page, 24);
await expect(input(page)).toBeFocused();
});
for (const mode of ["alternate", "mouse"] as const) {
test(`preserves finger navigation in ${mode} input mode`, async ({ page }) => {
await openPhoneInputCapture(page, mode);
@@ -531,6 +560,32 @@ async function openPhoneTerminalHistory(page: Page) {
});
await openPhoneTerminal(page);
await expect.poll(() => getTerminalBufferText(page)).toContain("HISTORY_150");
await expect
.poll(() => page.evaluate(() => window.__paseoTerminal!.buffer.active.baseY))
.toBeGreaterThan(0);
await page.evaluate(() => window.__paseoTerminal!.scrollToBottom());
await expect.poll(() => viewport(page)).toBeGreaterThan(0);
}
function terminalScreen(page: Page) {
return page.getByTestId("terminal-surface").filter({ visible: true }).locator(".xterm-screen");
}
async function tapTerminalScreen(page: Page) {
const box = await terminalScreen(page).boundingBox();
expect(box).not.toBeNull();
await page.touchscreen.tap(box!.x + box!.width / 2, box!.y + box!.height / 3);
}
// Playwright cannot show a software keyboard. A phone browser keeps the layout
// viewport and shortens the visual viewport by the keyboard height.
async function showSoftwareKeyboard(page: Page) {
await page.evaluate(() => {
Object.defineProperty(window.visualViewport!, "height", {
configurable: true,
get: () => window.innerHeight - 300,
});
});
}
async function openPhoneInputCapture(page: Page, mode: "alternate" | "mouse") {
@@ -570,6 +625,20 @@ async function openPhoneTerminal(page: Page) {
await page.getByTestId(`sidebar-workspace-row-${getServerId()}:${harness.workspaceId}`).click();
await expect(page.getByRole("textbox", { name: "Terminal input" })).toBeVisible();
await expect(page.getByTestId("terminal-surface").filter({ visible: true })).toBeVisible();
// The terminal stays mounted while the sidebar's closing backdrop still intercepts input.
await expect
.poll(() =>
page
.getByTestId("terminal-surface")
.filter({ visible: true })
.evaluate((root) => {
const box = root.querySelector(".xterm-screen")!.getBoundingClientRect();
return root.contains(
document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 3),
);
}),
)
.toBe(true);
}
async function expectMouseWheelScrollsHistory(page: Page) {
+11 -4
View File
@@ -728,7 +728,15 @@ test("a scheduled heartbeat opens a separate turn without reopening the previous
});
expect(created.error).toBeNull();
scheduleId = created.schedule!.id;
const fired = await schedules.scheduleRunOnce({ id: scheduleId });
const running = page.getByTestId("workspace-status-indicator-running");
const tasks = page.getByRole("button", { name: "1 background task", exact: true });
await expect(tasks).toBeVisible();
await expect(running).toHaveCount(0);
const [fired] = await Promise.all([
schedules.scheduleRunOnce({ id: scheduleId }),
expect(running.first()).toBeVisible(),
]);
expect(fired.error).toBeNull();
await expect(
page.getByTestId("tool-call-badge").filter({ hasText: /^Heartbeat/ }),
@@ -743,15 +751,14 @@ test("a scheduled heartbeat opens a separate turn without reopening the previous
await expect(summaries).toHaveCount(2);
await expect.poll(() => rowsBetweenLatestSummaryAndReply(page)).toBe(0);
await expect(page.getByRole("button", { name: /^Worked for/ })).toHaveCount(2);
const tasks = page.getByRole("button", { name: "1 background task", exact: true });
await expect(page.getByTestId("workspace-status-indicator-running").first()).toBeVisible();
await expect(running).toHaveCount(0);
await expect(page.getByRole("button", { name: "Stop agent", exact: true })).toHaveCount(0);
await tasks.click();
const panel = page.getByTestId("background-work-panel");
await expect(panel).toContainText("Heartbeat");
await panel.getByRole("button", { name: "Stop Check the completed work" }).click();
await expect(tasks).toHaveCount(0);
await expect(page.getByTestId("workspace-status-indicator-running")).toHaveCount(0);
await expect(running).toHaveCount(0);
const remaining = await schedules.scheduleList();
expect(remaining.error).toBeNull();
expect(remaining.schedules.map((schedule) => schedule.id)).not.toContain(scheduleId);
+1 -1
View File
@@ -24,7 +24,7 @@ function send(message) {
function respond(method, params) {
switch (method) {
case "initialize":
return {};
return { userAgent: "codex/0.159.0" };
case "model/list":
return { data: models };
case "config/read":
@@ -583,7 +583,7 @@ run_host_scroll() {
prepare_composer closed
if [[ "${host}" == new-workspace ]]; then
ad press 'id="workspace-create-isolation-trigger"' --settle
ad press 'text="Local"' --settle
ad press 'text="Project directory"' --settle
fi
# Submit through each real host; draft/workspace creation then mounts its chat.
# A selectable mock model keeps this test independent of provider credentials.
@@ -31,8 +31,6 @@ export interface RewindCompletionGate {
clearTimelineStreamCount(): void;
release(): void;
timelineStreamCount(): number;
/** Timeline reads this page sent since the last clear. */
timelineFetchCount(): number;
waitForDelayedResponse(): Promise<void>;
}
@@ -188,20 +186,12 @@ export async function holdDaemonHydration(page: Page): Promise<DaemonHydrationGa
};
}
// The rewind response and the timeline change it causes; the change removes the rewound row too.
const REWIND_COMPLETION_MESSAGES = new Set([
"agent.rewind.response",
"agent.timeline.rewind",
"agent.timeline.replacement",
]);
export async function holdRewindCompletion(
page: Page,
agentId: string,
): Promise<RewindCompletionGate> {
let released = false;
let timelineStreamCount = 0;
let timelineFetchCount = 0;
const delayedForwards: Array<() => void> = [];
let resolveDelayedResponse: (() => void) | null = null;
const delayedResponse = new Promise<void>((resolve) => {
@@ -210,16 +200,7 @@ export async function holdRewindCompletion(
await page.routeWebSocket(daemonWsRoutePattern(), (ws) => {
const server = ws.connectToServer();
ws.onMessage((message) => {
const sessionMessage = getSessionMessage(message);
if (
sessionMessage?.type === "fetch_agent_timeline_request" &&
sessionMessage.agentId === agentId
) {
timelineFetchCount += 1;
}
server.send(message);
});
ws.onMessage((message) => server.send(message));
server.onMessage((message) => {
const sessionMessage = getSessionMessage(message);
const payload = sessionMessage ? getPayload(sessionMessage) : null;
@@ -235,11 +216,11 @@ export async function holdRewindCompletion(
}
if (
!released &&
sessionMessage &&
REWIND_COMPLETION_MESSAGES.has(String(sessionMessage.type)) &&
(sessionMessage?.type === "agent.rewind.response" ||
sessionMessage?.type === "agent.timeline.replacement") &&
payload?.agentId === agentId
) {
// The rewind also signals completion and removes the rewound row/menu.
// The replacement also signals completion and removes the rewound row/menu.
// Hold it with the response so the pending-state assertion observes a pending rewind.
delayedForwards.push(() => ws.send(message));
if (sessionMessage.type === "agent.rewind.response") resolveDelayedResponse?.();
@@ -252,7 +233,6 @@ export async function holdRewindCompletion(
return {
clearTimelineStreamCount() {
timelineStreamCount = 0;
timelineFetchCount = 0;
},
release() {
released = true;
@@ -261,7 +241,6 @@ export async function holdRewindCompletion(
}
},
timelineStreamCount: () => timelineStreamCount,
timelineFetchCount: () => timelineFetchCount,
waitForDelayedResponse: () => delayedResponse,
};
}
@@ -56,11 +56,20 @@ function inFlightTurn(page: Page) {
return page.getByTestId("turn-working-indicator");
}
/**
* Presses a fork trigger until its menu shows.
*
* The in-flight turn's trigger sits below text that is still streaming in. While the chat is
* shorter than the viewport, each new line moves the trigger down. A line that arrives between
* the press and the release moves the trigger away from the pointer, so the press opens nothing,
* and the next press lands on the trigger where it is now.
*/
async function openForkMenu(page: Page, trigger: ReturnType<Page["getByRole"]>): Promise<void> {
await trigger.click();
await expect(page.getByRole("menuitem", { name: "Fork in a new tab" })).toBeVisible({
timeout: 10_000,
});
const forkInNewTab = page.getByRole("menuitem", { name: "Fork in a new tab" });
await expect(async () => {
await trigger.click({ timeout: 5_000 });
await expect(forkInNewTab).toBeVisible({ timeout: 5_000 });
}).toPass({ timeout: 30_000 });
}
export async function openMostRecentAssistantForkMenu(page: Page): Promise<void> {
@@ -23,6 +23,11 @@ export async function openCommandCenter(page: Page): Promise<Locator> {
return panel;
}
export async function openCommandCenterWithShortcut(page: Page): Promise<void> {
await page.keyboard.press("ControlOrMeta+k");
await expect(page.getByTestId("command-center-panel")).toBeVisible();
}
export async function closeCommandCenter(page: Page): Promise<void> {
await page.keyboard.press("Escape");
await expect(page.getByTestId("command-center-panel")).not.toBeVisible();
@@ -334,16 +334,19 @@ export async function selectNewWorkspaceProject(
await expectNewWorkspaceProjectSelected(page, input.projectDisplayName);
}
// The isolation trigger renders the active isolation's label ("Local" / "New
// worktree"), so asserting its text proves what the screen currently remembers.
const ISOLATION_TRIGGER_LABEL: Record<"local" | "worktree", string> = {
local: "Local",
type IsolationChoice = "local" | "worktree" | "existing";
// The isolation trigger renders the active isolation's label ("Project directory" / "New
// worktree" / "Existing worktree"), so asserting its text proves what the screen remembers.
const ISOLATION_TRIGGER_LABEL: Record<IsolationChoice, string> = {
local: "Project directory",
worktree: "New worktree",
existing: "Existing worktree",
};
export async function expectWorkspaceIsolationSelected(
page: Page,
isolation: "local" | "worktree",
isolation: IsolationChoice,
): Promise<void> {
const trigger = page.getByRole("button", { name: "Workspace isolation" });
await expect(trigger).toBeVisible({ timeout: 30_000 });
@@ -352,7 +355,7 @@ export async function expectWorkspaceIsolationSelected(
export async function selectWorkspaceIsolation(
page: Page,
isolation: "local" | "worktree",
isolation: IsolationChoice,
): Promise<void> {
const trigger = page.getByTestId("workspace-create-isolation-trigger");
await expect(trigger).toBeVisible({ timeout: 30_000 });
@@ -385,8 +388,16 @@ export async function selectBranchInPicker(page: Page, name: string): Promise<vo
await branchRow.click();
}
// The ref picker lists branches and pull requests separately.
async function showRefList(page: Page, list: "branches" | "pull-requests"): Promise<void> {
const tab = page.getByTestId(`new-workspace-ref-picker-tab-${list}`);
await expect(tab).toBeVisible({ timeout: 30_000 });
await tab.click();
}
export async function searchAndSelectBranchInPicker(page: Page, name: string): Promise<void> {
const searchInput = page.getByPlaceholder("Search branches and PRs");
await showRefList(page, "branches");
const searchInput = page.getByPlaceholder("Search branches");
await expect(searchInput).toBeVisible({ timeout: 30_000 });
await searchInput.fill(name);
await selectBranchInPicker(page, name);
@@ -410,6 +421,7 @@ export async function captureStartingRefPicker(page: Page, screenshotPath: strin
}
export async function selectGitHubPrInPicker(page: Page, number: number): Promise<void> {
await showRefList(page, "pull-requests");
const prRow = page.getByTestId(`new-workspace-ref-picker-pr-${number}`);
await expect(prRow).toBeVisible({ timeout: 30_000 });
await prRow.click();
@@ -432,7 +444,7 @@ export async function openBranchPicker(page: Page): Promise<void> {
}
export async function selectPickerOptionByKeyboard(page: Page, label: string): Promise<void> {
const searchInput = page.getByPlaceholder("Search branches and PRs");
const searchInput = page.getByPlaceholder("Search branches");
await expect(searchInput).toBeVisible({ timeout: 30_000 });
await page.keyboard.type(label);
await expect(page.getByTestId(`new-workspace-ref-picker-branch-${label}`)).toBeVisible({
@@ -2,6 +2,7 @@ import { buildSettingsHostSectionRoute } from "@/utils/host-routes";
import { expect, type Page } from "../fixtures";
import { getServerId } from "./server-id";
import { expectAppRoute } from "./route-assertions";
import { escapeRegex } from "./regex";
/**
* Settings → Host → Plugins: the Installed and Browse tabs, the page menu, the install sheet and a
@@ -28,8 +29,17 @@ function pluginSwitch(page: Page, name: string, action: "Disable" | "Enable") {
});
}
/**
* A toast that times out stays in the page while it fades, so the next toast can share the screen
* with it, even when both have the same text. The pattern matches case, so "Installed x" does not
* match "Uninstalled x".
*/
export async function expectToast(page: Page, message: string): Promise<void> {
await expect(page.getByTestId("app-toast-message")).toContainText(message);
const toast = page
.getByTestId("app-toast-message")
.filter({ hasText: new RegExp(escapeRegex(message)) })
.first();
await expect(toast).toBeVisible();
}
// Tabs and search
@@ -0,0 +1,19 @@
apply plugin: 'com.android.library'
group = 'sh.paseo.pressfeedback'
version = '0.1.0'
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()
useDefaultAndroidSdkVersions()
android {
namespace "sh.paseo.pressfeedback"
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
@@ -0,0 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,39 @@
package sh.paseo.pressfeedback
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.kotlin.types.ColorCompat
import expo.modules.kotlin.views.ExpoView
class PaseoPressFeedbackModule : Module() {
override fun definition() = ModuleDefinition {
Name("PaseoPressFeedback")
View(PaseoPressFeedbackView::class) {
Prop("tint") { view: PaseoPressFeedbackView, color: Color -> view.paint.color = ColorCompat.toArgb(color) }
Prop("radius") { view: PaseoPressFeedbackView, radius: Double -> view.radius = radius.toFloat() * view.resources.displayMetrics.density }
Prop("resetKey") { view: PaseoPressFeedbackView, key: String -> view.reset(key) }
AsyncFunction("acknowledge") { view: PaseoPressFeedbackView -> view.acknowledge() }
}
}
}
class PaseoPressFeedbackView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
var radius = 0f
private var acknowledged = false
private var resetKey = ""
init { setWillNotDraw(false); importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO }
fun acknowledge() { acknowledged = true; invalidate() }
fun reset(key: String) {
if (key != resetKey) { resetKey = key; acknowledged = false; invalidate() }
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (acknowledged) canvas.drawRoundRect(0f, 0f, width.toFloat(), height.toFloat(), radius, radius, paint)
}
}
@@ -0,0 +1,5 @@
{
"platforms": ["android", "ios"],
"android": { "modules": ["sh.paseo.pressfeedback.PaseoPressFeedbackModule"] },
"ios": { "modules": ["PaseoPressFeedbackModule"] }
}
@@ -0,0 +1 @@
export { useWorkspaceRowPress } from "./src/ui";
@@ -0,0 +1,22 @@
Pod::Spec.new do |s|
s.name = 'PaseoPressFeedback'
s.version = '0.1.0'
s.summary = 'Native accepted press feedback for Paseo'
s.description = 'Paints accepted press feedback independently of React commits'
s.license = 'Apache-2.0'
s.author = 'Paseo'
s.homepage = 'https://paseo.sh'
s.platforms = { :ios => '15.1' }
s.swift_version = '5.4'
s.source = { :path => '.' }
s.static_framework = true
s.dependency 'ExpoModulesCore'
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
'SWIFT_COMPILATION_MODE' => 'wholemodule'
}
s.source_files = "**/*.{h,m,swift}"
end
@@ -0,0 +1,33 @@
import ExpoModulesCore
import UIKit
public class PaseoPressFeedbackModule: Module {
public func definition() -> ModuleDefinition {
Name("PaseoPressFeedback")
View(PaseoPressFeedbackView.self) {
Prop("tint") { (view: PaseoPressFeedbackView, color: UIColor) in view.tint = color }
Prop("radius") { (view: PaseoPressFeedbackView, radius: Double) in view.radius = radius }
Prop("resetKey") { (view: PaseoPressFeedbackView, key: String) in view.reset(key) }
AsyncFunction("acknowledge") { (view: PaseoPressFeedbackView) in view.acknowledge() }
}
}
}
final class PaseoPressFeedbackView: ExpoView {
var tint = UIColor.clear
var radius: Double = 0
private var acknowledged = false
private var resetKey = ""
required init(appContext: AppContext? = nil) {
super.init(appContext: appContext)
isOpaque = false
isUserInteractionEnabled = false
}
func acknowledge() { acknowledged = true; setNeedsDisplay() }
func reset(_ key: String) {
if key != resetKey { resetKey = key; acknowledged = false; setNeedsDisplay() }
}
override func draw(_ rect: CGRect) {
if acknowledged { tint.setFill(); UIBezierPath(roundedRect: bounds, cornerRadius: radius).fill() }
}
}
@@ -0,0 +1,5 @@
{
"name": "paseo-press-feedback",
"version": "0.1.0",
"private": true
}
@@ -0,0 +1,104 @@
import { expect, it } from "vitest";
import { acceptWorkspaceRowPress, type WorkspaceRowPress } from "./accept";
function rowPress(overrides: Partial<WorkspaceRowPress> = {}) {
const visible: string[] = [];
const press: WorkspaceRowPress = {
cancelled: false,
native: true,
selected: false,
sidebar: "overlay",
target: "agent-list",
acknowledge: () => visible.push("row"),
navigate: () => visible.push("workspace"),
...overrides,
};
return { press, visible };
}
it("acknowledges an accepted row before navigation starts", () => {
const { press, visible } = rowPress();
expect(acceptWorkspaceRowPress(press)).toBe(true);
expect(visible).toEqual(["row", "workspace"]);
});
it("does not acknowledge or navigate after scrolling or a long press claims the touch", () => {
const { press, visible } = rowPress({ cancelled: true });
expect(acceptWorkspaceRowPress(press)).toBe(false);
expect(visible).toEqual([]);
});
it("accepts only the first row while its selection closes the sidebar", () => {
const { press, visible } = rowPress();
press.navigate = () => {
press.target = "agent";
visible.push("workspace B");
};
expect(acceptWorkspaceRowPress(press)).toBe(true);
expect(acceptWorkspaceRowPress(press)).toBe(false);
expect(visible).toEqual(["row", "workspace B"]);
});
it.each([
{
name: "open phone or tablet overlay",
sidebar: "overlay",
target: "agent-list",
native: true,
accepted: true,
},
{ name: "closing overlay", sidebar: "overlay", target: "agent", native: true, accepted: false },
{
name: "explorer covering an overlay",
sidebar: "overlay",
target: "file-explorer",
native: true,
accepted: false,
},
{ name: "docked sidebar", sidebar: "dock", target: "agent", native: true, accepted: true },
{
name: "docked sidebar beside explorer",
sidebar: "dock",
target: "file-explorer",
native: true,
accepted: true,
},
{ name: "hidden sidebar", sidebar: "hidden", target: "agent", native: true, accepted: false },
{
name: "suspended open overlay",
sidebar: "suspended",
target: "agent-list",
native: true,
accepted: true,
},
{
name: "suspended closed overlay",
sidebar: "suspended",
target: "agent",
native: true,
accepted: false,
},
{
name: "web sidebar independent of native panel target",
sidebar: "overlay",
target: "agent",
native: false,
accepted: true,
},
] as const)("uses the panel state for $name", ({ accepted, name: _, ...state }) => {
const { press, visible } = rowPress(state);
expect(acceptWorkspaceRowPress(press)).toBe(accepted);
expect(visible).toEqual(accepted ? ["row", "workspace"] : []);
});
it("does not leave an acknowledgement over an already selected docked row", () => {
const { press, visible } = rowPress({ selected: true, sidebar: "dock", target: "agent" });
expect(acceptWorkspaceRowPress(press)).toBe(true);
expect(visible).toEqual(["workspace"]);
});
it("still acknowledges a selected overlay row before the sidebar leaves", () => {
const { press, visible } = rowPress({ selected: true });
expect(acceptWorkspaceRowPress(press)).toBe(true);
expect(visible).toEqual(["row", "workspace"]);
});
@@ -0,0 +1,20 @@
import type { LeftSidebarPresentation, MobilePanelView } from "@/stores/panel-store";
export interface WorkspaceRowPress {
cancelled: boolean;
native: boolean;
selected: boolean;
sidebar: LeftSidebarPresentation;
target: MobilePanelView;
acknowledge(): void;
navigate(): void;
}
export function acceptWorkspaceRowPress(press: WorkspaceRowPress): boolean {
if (press.cancelled) return false;
if (press.native && press.sidebar !== "dock" && press.target !== "agent-list") return false;
// A selected docked row neither changes selection nor leaves the screen to clear the fill.
if (!press.selected || press.sidebar !== "dock") press.acknowledge();
press.navigate();
return true;
}
@@ -0,0 +1,47 @@
import { requireNativeView } from "expo";
import { type Ref } from "react";
import { usePanelStore } from "@/stores/panel-store";
import { withUnistyles } from "react-native-unistyles";
import { View, StyleSheet, type ViewProps } from "react-native";
export interface RowFeedbackHandle {
acknowledge(): Promise<void>;
}
interface FeedbackProps extends ViewProps {
ref?: Ref<RowFeedbackHandle>;
resetKey: string;
tint?: string;
radius?: number;
}
const NativeFeedback = withUnistyles(requireNativeView<FeedbackProps>("PaseoPressFeedback"));
const mapTheme = (theme: import("@/styles/theme").Theme) => ({
tint: theme.colors.interactionHighlight,
radius: theme.borderRadius.lg,
});
export function RowFeedback({
ref,
selected,
}: {
ref?: Ref<RowFeedbackHandle>;
selected: boolean;
}) {
const revision = usePanelStore((state) => state.mobilePanel.revision);
// Selection takes over the fill; a new panel transition clears it before reopening.
const resetKey = `${selected}:${revision}`;
return (
<View pointerEvents="none" style={styles.overlay}>
<NativeFeedback
ref={ref}
resetKey={resetKey}
pointerEvents="none"
style={styles.fill}
uniProps={mapTheme}
/>
</View>
);
}
const styles = StyleSheet.create({
overlay: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0 },
fill: { flex: 1 },
});
@@ -0,0 +1,7 @@
import type { Ref } from "react";
export interface RowFeedbackHandle {
acknowledge(): Promise<void>;
}
export function RowFeedback(_props: { ref?: Ref<RowFeedbackHandle>; selected: boolean }) {
return null;
}
@@ -0,0 +1,38 @@
import { useCallback, useRef, type RefObject } from "react";
import { isNative } from "@/constants/platform";
import { usePanelStore } from "@/stores/panel-store";
import { acceptWorkspaceRowPress } from "../accept";
import { RowFeedback, type RowFeedbackHandle } from "./feedback";
export function useWorkspaceRowPress({
didLongPressRef,
onPress,
selected,
}: {
didLongPressRef?: RefObject<boolean>;
onPress(): void;
selected: boolean;
}) {
const feedback = useRef<RowFeedbackHandle>(null);
const handlePress = useCallback(() => {
const cancelled = didLongPressRef?.current ?? false;
if (didLongPressRef) didLongPressRef.current = false;
const panel = usePanelStore.getState();
acceptWorkspaceRowPress({
cancelled,
native: isNative,
selected,
sidebar: panel.layout.leftSidebar,
target: panel.mobilePanel.target,
// Paint on the native UI thread before navigation occupies JS; never wait for paint.
acknowledge: () => {
void feedback.current?.acknowledge();
},
navigate: onPress,
});
}, [didLongPressRef, onPress, selected]);
return {
onPress: handlePress,
feedback: <RowFeedback ref={feedback} selected={selected} />,
};
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@getpaseo/app",
"version": "0.16.1",
"version": "0.16.2",
"private": true,
"main": "index.ts",
"scripts": {
@@ -30,6 +30,25 @@ function answer(
}
describe("draft options model", () => {
it("retains an Ultracode option only after the current host advertises it", () => {
const model = openDraftOptions({ provider: "claude" });
const legacy = { provider: "claude", cwd: "/repo", thinkingOptionId: "ultracode" };
model.applyResolved(answer("claude", "old-host", {}, []));
expect(model.retainResolvedOption("ultracode", "old-host")).toBeUndefined();
expect(draftControlsRequest(model.getState(), legacy)).toEqual(legacy);
model.applyResolved(
answer("claude", "new-host", { ultracode: true }, [
{ type: "toggle", key: "ultracode", label: "Ultracode" },
]),
);
expect(model.retainResolvedOption("ultracode", "old-host")).toBeUndefined();
expect(model.retainResolvedOption("ultracode", "new-host")).toEqual({ ultracode: true });
expect(
draftControlsRequest(model.getState(), { ...legacy, thinkingOptionId: "high" }),
).toMatchObject({ thinkingOptionId: "high", providerOptions: { ultracode: true } });
});
it("draws a legacy Fast profile as the Fast tier the daemon resolved", () => {
const model = openDraftOptions({ provider: "codex", seed: { service_tier: "fast" } });
model.applyResolved(answer("codex", "k1", { service_tier: "priority" }));
@@ -47,6 +47,7 @@ export interface DraftOptionsModel {
applyProfile: (profile: { provider: string; options: ProviderOptions }) => void;
setRemembered: (remembered: ProviderOptions) => void;
setOption: (key: string, value: unknown) => void;
retainResolvedOption: (key: string, requestKey: string) => ProviderOptions | undefined;
applyResolved: (resolved: ResolvedDraftOptions) => void;
}
@@ -112,6 +113,17 @@ export function openDraftOptions(input: {
: { ...current, edits: { ...current.edits, [key]: value } },
);
},
retainResolvedOption: (key, requestKey) => {
const resolved = state.resolved;
if (resolved?.requestKey !== requestKey || key in state.edits) return undefined;
const value = resolved.options[key];
if (value === undefined || !resolved.controls.some((control) => control.key === key)) {
return undefined;
}
const patch = { [key]: value };
publish((current) => ({ ...current, edits: { ...current.edits, ...patch } }));
return patch;
},
applyResolved: (resolved) =>
publish((current) => ({
...current,
@@ -56,7 +56,6 @@ export function ChatFind({
agentId,
serverId,
epoch,
rewindSeq,
items,
viewportRef,
revealLoadedMessage,
@@ -96,8 +95,8 @@ export function ChatFind({
);
const state = useSyncExternalStore(model.subscribe, model.getSnapshot, model.getSnapshot);
useEffect(() => {
model.updateHistory(epoch, items, rewindSeq);
}, [model, epoch, items, rewindSeq]);
model.updateHistory(epoch, items);
}, [model, epoch, items]);
useEffect(() => () => model.close(), [model]);
useEffect(() => {
if (!active) model.close();
@@ -18,7 +18,7 @@ function message(seq: number, text = "target"): StreamItem {
kind: "assistant_message",
text,
timestamp: new Date(0),
timelineCursor: { epoch: "epoch", seq, anchorSeq: seq },
timelineCursor: { epoch: "epoch", seq },
};
}
@@ -39,7 +39,7 @@ it("loads an older location and searches a response merged across suppressed tas
source.map((item, index) => ({
event: { type: "timeline" as const, provider: "claude" as const, item },
timestamp: new Date(0),
timelineCursor: { epoch: "epoch", seq: index + 1, anchorSeq: index + 1 },
timelineCursor: { epoch: "epoch", seq: index + 1 },
})),
{ source: "canonical" },
);
@@ -55,7 +55,7 @@ it("loads an older location and searches a response merged across suppressed tas
},
async load(_epoch, seq) {
loaded.push(seq);
model.updateHistory("epoch", history, null);
model.updateHistory("epoch", history);
},
async reveal(_id, _query, occurrence) {
revealed.push(occurrence);
@@ -64,7 +64,7 @@ it("loads an older location and searches a response merged across suppressed tas
clear() {},
});
try {
model.updateHistory("epoch", [], null);
model.updateHistory("epoch", []);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
@@ -99,7 +99,7 @@ it("skips a source-only candidate and highlights a displayed match", async () =>
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.updateHistory("epoch", [message(1), message(2)]);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().selectedItemId).toBe("row-2");
@@ -129,7 +129,7 @@ it("ignores replies after closing and does not navigate", async () => {
},
clear() {},
});
model.updateHistory("epoch", [message(1)], null);
model.updateHistory("epoch", [message(1)]);
model.open();
model.setQuery("target");
await expect.poll(() => calls).toEqual(["search"]);
@@ -155,7 +155,7 @@ it("retains a failed search for retry and distinguishes failure from zero matche
};
const model = new ChatFindModel(operations);
try {
model.updateHistory("epoch", [], null);
model.updateHistory("epoch", []);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("error");
@@ -185,7 +185,7 @@ it("reports a failed timeline load as a connection failure", async () => {
clear() {},
});
try {
model.updateHistory("epoch", [], null);
model.updateHistory("epoch", []);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("error");
@@ -207,160 +207,24 @@ it("reports a search result that outlived its epoch as a changed history", async
clear() {},
});
try {
model.updateHistory("epoch", [message(1)], null);
model.updateHistory("epoch", [message(1)]);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
model.updateHistory("epoch-2", [message(1)], null);
model.updateHistory("epoch-2", [message(1)]);
expect(model.getSnapshot()).toMatchObject({ phase: "error", failure: "historyChanged" });
} finally {
model.close();
}
});
it("reports results that a rewind took messages from as a changed history", async () => {
const model = new ChatFindModel({
async search() {
return response([{ seq: 2, role: "assistant" }]);
},
async load() {},
async reveal() {
return { count: 1, occurrence: 0 };
},
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
expect(model.getSnapshot()).toMatchObject({ selectedItemId: "row-2", count: 1 });
// Another client rewinds the turn holding the match; the epoch stays.
model.updateHistory("epoch", [message(1)], 3);
expect(model.getSnapshot()).toMatchObject({
phase: "error",
failure: "historyChanged",
selectedItemId: null,
});
} finally {
model.close();
}
});
it("stops a search still receiving pages when a rewind lands between them", async () => {
let pages = 0;
let releaseSecondPage!: () => void;
const secondPage = new Promise<void>((resolve) => {
releaseSecondPage = resolve;
});
const model = new ChatFindModel({
async search(_query, cursor) {
pages += 1;
if (cursor === undefined)
return { ...response([{ seq: 2, role: "assistant" }]), nextCursor: 2 };
await secondPage;
return response([{ seq: 1, role: "assistant" }]);
},
async load() {},
async reveal() {
return { count: 1, occurrence: 0 };
},
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.open();
model.setQuery("target");
await expect.poll(() => pages).toBe(2);
model.updateHistory("epoch", [message(1)], 3);
releaseSecondPage();
await expect.poll(() => model.getSnapshot().failure).toBe("historyChanged");
expect(model.getSnapshot()).toMatchObject({ phase: "error", selectedItemId: null });
} finally {
model.close();
}
});
it.each([
["Next", "next"],
["Previous", "previous"],
] as const)("reports a rewind after %s as a changed history", async (_label, step) => {
const model = new ChatFindModel({
async search() {
return response([
{ seq: 1, role: "assistant" },
{ seq: 2, role: "assistant" },
]);
},
async load() {},
async reveal() {
return { count: 1, occurrence: 0 };
},
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
model[step]();
await expect.poll(() => model.getSnapshot().selectedItemId).toBe("row-2");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
model.updateHistory("epoch", [message(1)], 3);
expect(model.getSnapshot()).toMatchObject({
phase: "error",
failure: "historyChanged",
selectedItemId: null,
});
} finally {
model.close();
}
});
it("stops a pending Next when a rewind lands before it reveals", async () => {
let reveals = 0;
let revealSecond!: () => void;
const secondReveal = new Promise<void>((resolve) => {
revealSecond = resolve;
});
const model = new ChatFindModel({
async search() {
return response([
{ seq: 1, role: "assistant" },
{ seq: 2, role: "assistant" },
]);
},
async load() {},
async reveal() {
reveals += 1;
if (reveals > 1) await secondReveal;
return { count: 1, occurrence: 0 };
},
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
model.next();
await expect.poll(() => reveals).toBe(2);
model.updateHistory("epoch", [message(1)], 3);
revealSecond();
await expect.poll(() => model.getSnapshot().failure).toBe("historyChanged");
expect(model.getSnapshot()).toMatchObject({ phase: "error", selectedItemId: null });
} finally {
model.close();
}
});
it("can load a search location before the initial chat history has arrived", async () => {
const model = new ChatFindModel({
async search() {
return response([{ seq: 1, role: "assistant" }]);
},
async load() {
model.updateHistory("epoch", [message(1)], null);
model.updateHistory("epoch", [message(1)]);
},
async reveal() {
return { count: 1, occurrence: 0 };
@@ -368,7 +232,7 @@ it("can load a search location before the initial chat history has arrived", asy
clear() {},
});
try {
model.updateHistory(null, [], null);
model.updateHistory(null, []);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
@@ -396,7 +260,7 @@ it("reports the position across the whole chat and corrects it with rendered cou
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.updateHistory("epoch", [message(1), message(2)]);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
@@ -433,7 +297,7 @@ it("counts one match per message from a host that reports no counts", async () =
clear() {},
});
try {
model.updateHistory("epoch", [message(1), message(2)], null);
model.updateHistory("epoch", [message(1), message(2)]);
model.open();
model.setQuery("target");
await expect.poll(() => model.getSnapshot().phase).toBe("ready");
@@ -76,10 +76,6 @@ export class ChatFindModel {
private items: StreamItem[] = [];
private epoch: string | null = null;
private resultEpoch: string | null = null;
/** The latest rewind applied to the history. A rewind keeps the epoch and retires messages. */
private rewindSeq: number | null = null;
/** The latest rewind when the current result set's search started; undefined until a search starts. */
private searchedRewindSeq: number | null | undefined = undefined;
private locations: Location[] = [];
private resolved = new Map<Location, Target>();
private current = -1;
@@ -117,7 +113,6 @@ export class ChatFindModel {
this.cancel();
this.locations = [];
this.resultEpoch = null;
this.searchedRewindSeq = undefined;
this.resolved.clear();
this.current = -1;
this.inMessage = { occurrence: 0, count: 0 };
@@ -149,7 +144,6 @@ export class ChatFindModel {
});
}
private async search(signal: AbortSignal) {
this.searchedRewindSeq = this.rewindSeq;
try {
let cursor: number | undefined;
do {
@@ -174,14 +168,15 @@ export class ChatFindModel {
this.fail(error, signal);
}
}
/** `rewindSeq` is the sequence number of the latest rewind applied to this history. */
updateHistory(epoch: string | null, items: StreamItem[], rewindSeq: number | null) {
const replaced = this.resultEpoch !== null && epoch !== null && epoch !== this.resultEpoch;
const rewound = this.searchedRewindSeq !== undefined && rewindSeq !== this.searchedRewindSeq;
if ((replaced || rewound) && this.state.open) {
updateHistory(epoch: string | null, items: StreamItem[]) {
if (
this.resultEpoch !== null &&
epoch !== null &&
epoch !== this.resultEpoch &&
this.state.open
) {
this.fail(new ChatFindFailureError("historyChanged"), this.abort.signal);
}
this.rewindSeq = rewindSeq;
this.epoch = epoch;
this.items = items;
this.historyListeners.forEach((listener) => listener());
@@ -9,8 +9,6 @@ export interface ChatFindProps {
agentId: string;
serverId: string;
epoch: string | null;
/** The sequence number of the latest rewind applied to this history, if any. */
rewindSeq: number | null;
items: StreamItem[];
viewportRef: RefObject<StreamViewportHandle | null>;
revealLoadedMessage(messageId: string): boolean;
@@ -139,7 +139,7 @@ describe("useChatOutline", () => {
kind: "user_message",
text: "live prompt",
timestamp: new Date(seq),
timelineCursor: { epoch: "epoch-1", seq, anchorSeq: seq },
timelineCursor: { epoch: "epoch-1", seq },
});
rerender({ tail: [loadedPrompt(2)] });
await waitFor(() => expect(runtime.listAgentTimelinePrompts).toHaveBeenCalledTimes(2));
@@ -198,7 +198,7 @@ describe("useChatOutline", () => {
kind: "assistant_message",
text: "chunk",
timestamp: new Date(),
timelineCursor: { epoch: "epoch-1", seq: 2, anchorSeq: 2 },
timelineCursor: { epoch: "epoch-1", seq: 2 },
},
],
timelineEpoch: "epoch-1",
@@ -219,7 +219,7 @@ describe("useChatOutline", () => {
kind: "user_message",
text: "Replaced conversation",
timestamp: new Date(2),
timelineCursor: { epoch: "epoch-2", seq: 1, anchorSeq: 1 },
timelineCursor: { epoch: "epoch-2", seq: 1 },
},
],
timelineEpoch: "epoch-2",
@@ -275,7 +275,7 @@ describe("useChatOutline", () => {
kind: "user_message" as const,
text: "prompt",
timestamp: new Date(1),
timelineCursor: { epoch: "epoch-1", seq: 1, anchorSeq: 1 },
timelineCursor: { epoch: "epoch-1", seq: 1 },
},
];
const { result, rerender } = renderHook(
@@ -326,7 +326,7 @@ describe("useChatOutline", () => {
kind: "user_message" as const,
text: "prompt",
timestamp: new Date(1),
timelineCursor: { epoch: "epoch-1", seq: 1, anchorSeq: 1 },
timelineCursor: { epoch: "epoch-1", seq: 1 },
};
const { result, rerender } = renderHook(
({ tail, mountedHistoryMessageIds }) =>
@@ -381,7 +381,7 @@ describe("useChatOutline", () => {
kind: "user_message" as const,
text: "prompt",
timestamp: new Date(2),
timelineCursor: { epoch: "epoch-1", seq: 2, anchorSeq: 2 },
timelineCursor: { epoch: "epoch-1", seq: 2 },
};
const revealLoadedMessage = vi.fn();
revealLoadedMessage.mockReturnValue(false);
@@ -0,0 +1,85 @@
import { expect, it } from "vitest";
import { createInitialDrawDistanceExpansion } from "./initial-draw-distance";
function mountInitialBuffer() {
let nextId = 0;
const pending = new Map<number, () => void>();
const expansions: string[] = [];
const buffer = createInitialDrawDistanceExpansion(
{
requestFrame(callback) {
const id = ++nextId;
pending.set(id, callback);
return id;
},
cancelFrame(id) {
pending.delete(id);
},
},
() => expansions.push("full draw distance"),
);
function advanceFrame() {
const callbacks = [...pending.values()];
pending.clear();
for (const callback of callbacks) callback();
}
return { buffer, expansions, advanceFrame };
}
it("requests the full draw distance after two frame callbacks once the reveal is eligible", () => {
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
buffer.schedule();
advanceFrame();
expect(expansions).toEqual([]);
advanceFrame();
expect(expansions).toEqual(["full draw distance"]);
});
it.each([0, 1])(
"leaves initial draw distance in place during a gesture after %i frames",
(elapsed) => {
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
buffer.schedule();
if (elapsed === 1) advanceFrame();
buffer.pauseForScroll();
advanceFrame();
advanceFrame();
expect(expansions).toEqual([]);
buffer.resumeAfterScroll();
advanceFrame();
expect(expansions).toEqual([]);
advanceFrame();
expect(expansions).toEqual(["full draw distance"]);
},
);
it("cancels a covered reveal and schedules again when it is eligible", () => {
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
const cancel = buffer.schedule();
advanceFrame();
cancel();
advanceFrame();
expect(expansions).toEqual([]);
buffer.schedule();
advanceFrame();
advanceFrame();
expect(expansions).toEqual(["full draw distance"]);
});
it("keeps a covered list at its initial draw distance when a gesture ends", () => {
const { buffer, expansions, advanceFrame } = mountInitialBuffer();
buffer.pauseForScroll();
const cover = buffer.schedule();
advanceFrame();
advanceFrame();
expect(expansions).toEqual([]);
cover();
buffer.resumeAfterScroll();
advanceFrame();
advanceFrame();
expect(expansions).toEqual([]);
});
@@ -0,0 +1,50 @@
interface InitialDrawDistanceFrames {
requestFrame(callback: () => void): number;
cancelFrame(id: number): void;
}
export function createInitialDrawDistanceExpansion(
frames: InitialDrawDistanceFrames,
expand: () => void,
) {
let frame: number | null = null;
let eligible = false;
let scrolling = false;
let expanded = false;
function cancel() {
if (frame === null) return;
frames.cancelFrame(frame);
frame = null;
}
function scheduleIfIdle() {
if (!eligible || scrolling || expanded || frame !== null) return;
frame = frames.requestFrame(() => {
frame = frames.requestFrame(() => {
frame = null;
expanded = true;
expand();
});
});
}
return {
schedule() {
eligible = true;
scheduleIfIdle();
return () => {
eligible = false;
cancel();
};
},
pauseForScroll() {
scrolling = true;
cancel();
},
resumeAfterScroll() {
scrolling = false;
scheduleIfIdle();
},
};
}
@@ -40,6 +40,7 @@ function wait(ms: number): Promise<void> {
}
const LIST_STYLE = { flex: 1 };
const ESTIMATED_LIST_SIZE = { width: 300, height: VIEWPORT_HEIGHT };
const rowStyles = new Map<number, { height: number }>();
function rowStyle(height: number) {
@@ -89,6 +90,10 @@ function keyExtractor(item: Row) {
return item.id;
}
function estimateRowSize(item: Row) {
return item.height;
}
function mountList(heldRowId: string) {
const listRef = React.createRef<LegendListRef>();
const maintainVisibleContentPosition = holdOnly(heldRowId);
@@ -264,3 +269,49 @@ it("keeps measured row sizes while the list is not laid out", async () => {
expect(rows.map((row) => list.rowSize(row.id))).toEqual([40, 40, 40]);
});
it("expands the draw distance of a placed end-anchored list without moving its bottom row", async () => {
const rows: Row[] = Array.from({ length: 99 }, (_, index) => ({
id: `row-${index}`,
height: index % 2 === 0 ? 20 : 60,
}));
const lastRow = { id: "last-row", height: 180 };
rows.push(lastRow);
const listRef = React.createRef<LegendListRef>();
function render(drawDistance: number) {
act(() => {
root.render(
<LegendList
ref={listRef}
data={rows}
renderItem={renderRow}
keyExtractor={keyExtractor}
estimatedListSize={ESTIMATED_LIST_SIZE}
recycleItems={false}
getEstimatedItemSize={estimateRowSize}
drawDistance={drawDistance}
alignItemsAtEnd
initialScrollAtEnd
style={LIST_STYLE}
/>,
);
});
}
render(50);
await wait(300);
const initial = listRef.current?.getState();
const lastRowTop = initial?.positionByKey(lastRow.id);
expect(initial?.sizes.get(lastRow.id)).toBe(lastRow.height);
expect(initial?.sizes.size).toBeLessThan(8);
expect(initial?.scroll).toBe(Number(lastRowTop) + lastRow.height - VIEWPORT_HEIGHT);
render(1000);
await wait(150);
const expanded = listRef.current?.getState();
expect(expanded?.sizes.size).toBeGreaterThan(20);
expect(expanded?.scroll).toBe(initial?.scroll);
expect(expanded?.positionByKey(lastRow.id)).toBe(lastRowTop);
});
@@ -320,7 +320,7 @@ describe("stream presentation through installed plugins", () => {
const source = harness.source();
const live = source.head[0];
if (live?.kind !== "assistant_message") throw new Error("Expected a live assistant message");
const canonical = { ...live, timelineCursor: { epoch: "epoch-1", seq: 42, anchorSeq: 42 } };
const canonical = { ...live, timelineCursor: { epoch: "epoch-1", seq: 42 } };
const present = createStreamPresentation();
present({ ...presentationOptions, tail: [], head: [live], transform: undefined });
const repointed = rows(
@@ -330,7 +330,7 @@ describe("stream presentation through installed plugins", () => {
{
id: streamed[0]!.id,
text: "Streamed answer",
timelineCursor: { epoch: "epoch-1", seq: 42, anchorSeq: 42 },
timelineCursor: { epoch: "epoch-1", seq: 42 },
},
]);
});
@@ -517,7 +517,7 @@ describe("timeline presentation", () => {
messageId: "provider-message",
clientMessageId: "client-message",
turnId: "turn-1",
timelineCursor: { epoch: "epoch", seq: 12, anchorSeq: 12 },
timelineCursor: { epoch: "epoch", seq: 12 },
});
const presentMessage = () =>
present({
@@ -9,6 +9,7 @@ import {
useState,
} from "react";
import {
Dimensions,
View,
type LayoutChangeEvent,
type NativeScrollEvent,
@@ -31,6 +32,7 @@ import { useTranslation } from "react-i18next";
import type { StreamItem } from "@/types/stream";
import type { Theme } from "@/styles/theme";
import { useStableEvent } from "@/hooks/use-stable-event";
import { useIsMobilePanelActive } from "@/mobile-panels/provider";
import { shouldAnimateNativeScrollToBottom } from "./native-scroll-animation";
import { useRevisedHistoryRows } from "./history-row-revision";
import { useBottomAnchorController } from "./bottom-anchor-controller";
@@ -43,6 +45,7 @@ import {
} from "./native-disclosure-hold";
import { EndPinnedScrollView } from "./native-end-pin";
import { createNewRowEstimates } from "./new-row-estimates";
import { createInitialDrawDistanceExpansion } from "./initial-draw-distance";
import type {
DisclosureTriggerEdge,
StreamRenderInput,
@@ -132,6 +135,14 @@ function keyExtractor(item: { id: string }): string {
return item.id;
}
function InitialDrawDistanceExpansion({ schedule }: { schedule: () => () => void }) {
const isSidebarActive = useIsMobilePanelActive("agent-list");
useLayoutEffect(() => {
if (!isSidebarActive) return schedule();
}, [schedule, isSidebarActive]);
return null;
}
function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrategy }) {
const {
agentId,
@@ -157,6 +168,16 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
strategy,
} = props;
const isActive = useRetainedPanelActive();
// Keep a screenful in reserve for a fling that starts before the full buffer mounts.
const [drawDistance, setDrawDistance] = useState(() =>
Math.min(Dimensions.get("window").height, NATIVE_STREAM_DRAW_DISTANCE),
);
const [drawDistanceExpansion] = useState(() =>
createInitialDrawDistanceExpansion(
{ requestFrame: requestAnimationFrame, cancelFrame: cancelAnimationFrame },
() => setDrawDistance(NATIVE_STREAM_DRAW_DISTANCE),
),
);
const { t } = useTranslation();
const { renderHistoryMountedRow, renderLiveHeadRow, renderLiveAuxiliary } = renderers;
const listRef = useRef<LegendListRef>(null);
@@ -569,6 +590,9 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
cancelDisclosureHold();
bottomAnchorController.beginUserScroll();
historyStartPagination.rearm();
// The reserve follows the gesture. Expanding the buffer here shifted the measured
// content and returned the viewport to the end during an Android fling.
drawDistanceExpansion.pauseForScroll();
});
useEffect(() => {
@@ -591,6 +615,7 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
bottomAnchorController.endUserScroll({
isAtEnd: isReleasedAtEndRef.current || isAtEnd(),
});
drawDistanceExpansion.resumeAfterScroll();
});
});
@@ -610,6 +635,7 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
bottomAnchorController.endUserScroll({
isAtEnd: isReleasedAtEndRef.current || isScrollEventAtEnd(event),
});
drawDistanceExpansion.resumeAfterScroll();
},
);
@@ -732,6 +758,11 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
);
}, [historyStartPaginationState, hasOlderHistory, retryHistoryStart, t]);
const canExpandDrawDistance =
drawDistance < NATIVE_STREAM_DRAW_DISTANCE &&
isActive &&
isListPlaced &&
historyStartPaginationState.visible;
return (
<View style={viewportStyle}>
<LegendList<StreamItem>
@@ -764,11 +795,14 @@ function NativeStreamViewport(props: StreamRenderInput & { strategy: StreamStrat
recycleItems={false}
alignItemsAtEnd
initialScrollAtEnd
drawDistance={NATIVE_STREAM_DRAW_DISTANCE}
drawDistance={drawDistance}
getEstimatedItemSize={getEstimatedItemSize}
scrollEnabled={scrollEnabled}
showsVerticalScrollIndicator
/>
{canExpandDrawDistance ? (
<InitialDrawDistanceExpansion schedule={drawDistanceExpansion.schedule} />
) : null}
{!historyStartPaginationState.visible ? (
<View pointerEvents="none" testID="agent-initial-fill" style={initialFillStyle}>
<ThemedLoadingSpinner size="large" uniProps={foregroundMutedColorMapping} />
@@ -33,7 +33,7 @@ describe("resolveAssistantTurnForkBoundary", () => {
it("forks a failed assistant turn from its Paseo timeline cursor without a provider message id", () => {
const failedTurn = {
...assistantMessage("assistant-error", 2),
timelineCursor: { epoch: "timeline-1", seq: 42, anchorSeq: 42 },
timelineCursor: { epoch: "timeline-1", seq: 42 },
};
expect(
@@ -50,7 +50,7 @@ describe("resolveAssistantTurnForkBoundary", () => {
it("includes the provider message id with a supported timeline cursor", () => {
const selected = {
...assistantMessage("assistant-1", 2, "msg-assistant-1"),
timelineCursor: { epoch: "timeline-1", seq: 42, anchorSeq: 42 },
timelineCursor: { epoch: "timeline-1", seq: 42 },
};
expect(
@@ -68,7 +68,7 @@ describe("resolveAssistantTurnForkBoundary", () => {
it("falls back to the provider message id when timeline cursors are unsupported", () => {
const selected = {
...assistantMessage("assistant-1", 2, "msg-assistant-1"),
timelineCursor: { epoch: "timeline-1", seq: 42, anchorSeq: 42 },
timelineCursor: { epoch: "timeline-1", seq: 42 },
};
expect(
@@ -1,13 +1,7 @@
import type { StreamItem } from "@/types/stream";
/** The daemon's timeline cursor; the row's anchor stays in the client. */
interface TimelineBoundaryCursor {
epoch: string;
seq: number;
}
import type { StreamItem, TimelinePosition } from "@/types/stream";
export type AssistantTurnForkBoundary =
| { boundaryCursor: TimelineBoundaryCursor; boundaryMessageId?: string }
| { boundaryCursor: TimelinePosition; boundaryMessageId?: string }
| { boundaryCursor?: undefined; boundaryMessageId: string };
export function resolveAssistantTurnForkBoundary(input: {
@@ -21,7 +15,7 @@ export function resolveAssistantTurnForkBoundary(input: {
}
if (input.supportsTimelineCursor && item.timelineCursor) {
return {
boundaryCursor: { epoch: item.timelineCursor.epoch, seq: item.timelineCursor.seq },
boundaryCursor: item.timelineCursor,
...(item.messageId ? { boundaryMessageId: item.messageId } : {}),
};
}
@@ -140,7 +140,7 @@ describe("collapseTurns", () => {
it("stands at its host's timeline position, taking a new row when that position lands", () => {
const live = collapse([user("u1"), shell("c1"), reply("r1")]);
expect(live.summaryRowsByHostId.get("u1")).not.toHaveProperty("timelineCursor");
const cursor = { epoch: "epoch-1", seq: 7, anchorSeq: 7 };
const cursor = { epoch: "epoch-1", seq: 7 };
const placed = [{ ...user("u1"), timelineCursor: cursor }, shell("c1"), reply("r1")];
const canonical = collapse(placed, { previousSummaryRowsByHostId: live.summaryRowsByHostId });
expect(canonical.summaryRowsByHostId.get("u1")).not.toBe(live.summaryRowsByHostId.get("u1"));
-5
View File
@@ -411,10 +411,6 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
const timelineEpoch = useSessionStore(
(state) => state.sessions[resolvedServerId]?.agentTimelineCursor.get(agentId)?.epoch ?? null,
);
const timelineRewindSeq = useSessionStore((state) => {
const rewind = state.sessions[resolvedServerId]?.agentTimelineLatestRewind.get(agentId);
return rewind && rewind.epoch === timelineEpoch ? rewind.seq : null;
});
const isTimelineDetached = useSessionStore(
(state) => state.sessions[resolvedServerId]?.agentTimelineHasNewer.get(agentId) === true,
);
@@ -1171,7 +1167,6 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
agentId={agentId}
serverId={resolvedServerId}
epoch={timelineEpoch}
rewindSeq={timelineRewindSeq}
items={findItems}
viewportRef={viewportRef}
revealLoadedMessage={revealLoadedMessage}
+18 -1
View File
@@ -3,7 +3,6 @@ export interface AudioEngineCallbacks {
onVolumeLevel(level: number): void;
onInterruption?(): void;
onCaptureAvailabilityChange?(available: boolean): void;
onError?(error: Error): void;
}
export interface AudioPlaybackSource {
@@ -31,3 +30,21 @@ export interface AudioEngineOptions {
traceLabel?: string;
captureMode?: "conversation" | "dictation";
}
export type AudioCaptureStartFailure =
| "permissionDenied"
| "insecureContext"
| "unsupported"
| "noMicrophone"
| "startFailed";
export class AudioCaptureStartError extends Error {
constructor(
readonly reason: AudioCaptureStartFailure,
message: string,
options?: ErrorOptions,
) {
super(message, options);
this.name = "AudioCaptureStartError";
}
}
+50 -229
View File
@@ -1,239 +1,60 @@
import type {
AudioEngine,
AudioEngineCallbacks,
AudioEngineOptions,
AudioPlaybackSource,
} from "./audio-engine-types";
import type { AudioEngine, AudioEngineCallbacks, AudioEngineOptions } from "./audio-engine-types";
import { createAudioPlayer, setAudioModeAsync } from "expo-audio";
import { File, Paths } from "expo-file-system";
import { createPlaybackQueue } from "./playback";
import { playFile } from "./file-playback";
import { playPcm16 } from "./pcm";
import { createNativeAudioEngine, type NativeAudioEngineDeps } from "./native-audio-engine";
// AVPlayer needs a file extension to recognize local encoded audio on iOS.
const FILE_EXTENSIONS: Record<string, string> = {
"audio/wav": "wav",
"audio/x-wav": "wav",
"audio/wave": "wav",
"audio/mpeg": "mp3",
"audio/mp3": "mp3",
"audio/mp4": "m4a",
"audio/aac": "aac",
"audio/ogg": "ogg",
"audio/flac": "flac",
};
let nextFileId = 0;
async function playEncodedAudio(
bytes: Uint8Array,
mimeType: string,
signal: AbortSignal,
context: { isCaptureActive(): boolean },
): Promise<number> {
// Capture owns its audio session while active. File playback alone must not
// initialize the microphone or the native two-way engine.
if (!context.isCaptureActive()) {
await setAudioModeAsync({
playsInSilentMode: true,
allowsRecording: false,
interruptionMode: "duckOthers",
interruptionModeAndroid: "duckOthers",
});
}
if (signal.aborted) throw new Error("Playback stopped");
const extension = FILE_EXTENSIONS[mimeType.split(";")[0].trim()] ?? "audio";
const file = new File(Paths.cache, `paseo-audio-${Date.now()}-${nextFileId++}.${extension}`);
try {
file.write(bytes);
const player = createAudioPlayer(file.uri, {
updateInterval: 100,
keepAudioSessionActive: context.isCaptureActive(),
});
return await playFile(player, signal);
} finally {
if (file.exists) file.delete();
}
}
export function createAudioEngine(
callbacks: AudioEngineCallbacks,
options?: AudioEngineOptions,
): AudioEngine {
const native = require("@getpaseo/expo-two-way-audio");
const refs: {
initialized: boolean;
captureActive: boolean;
muted: boolean;
destroyed: boolean;
} = {
initialized: false,
captureActive: false,
muted: false,
destroyed: false,
};
const microphoneSubscription = native.addExpoTwoWayAudioEventListener(
"onMicrophoneData",
(event: { data: Uint8Array }) => {
if (!refs.captureActive || refs.muted) {
return;
}
const pcm = event.data;
callbacks.onCaptureData(pcm);
},
);
const volumeSubscription = native.addExpoTwoWayAudioEventListener(
"onInputVolumeLevelData",
(event: { data: number }) => {
if (!refs.captureActive) {
return;
}
const level = refs.muted ? 0 : event.data;
callbacks.onVolumeLevel(level);
},
);
const interruptionSubscription = native.addExpoTwoWayAudioEventListener(
"onAudioInterruption",
(event: { data: string }) => {
if (event.data === "capture_paused" || event.data === "capture_resumed") {
if (refs.captureActive) {
callbacks.onCaptureAvailabilityChange?.(event.data === "capture_resumed");
}
return;
}
if (event.data !== "blocked") {
return;
}
const wasCaptureActive = refs.captureActive;
refs.captureActive = false;
refs.muted = false;
callbacks.onVolumeLevel(0);
if (wasCaptureActive) {
callbacks.onInterruption?.();
}
},
);
async function ensureInitialized(): Promise<void> {
if (refs.initialized) {
return;
}
const success = await native.initialize();
if (!success) {
throw new Error("expo-two-way-audio: native initialize() returned false");
}
refs.initialized = true;
}
/**
* Release the OS audio session as soon as we are neither capturing nor playing.
* Holding it keeps the user's background music paused — on iOS the non-mixing
* `.playAndRecord` category survives backgrounding and is re-asserted on every
* foreground, so an unreleased session means their music never comes back.
*/
function releaseSessionIfIdle(): void {
if (!refs.initialized || refs.destroyed) {
return;
}
if (refs.captureActive || playback.isPlaying()) {
return;
}
// The wrapper no-ops on binaries whose native module predates this function.
native.releaseAudioSession();
}
async function ensureMicrophonePermission(): Promise<void> {
let permission = await native.getMicrophonePermissionsAsync().catch(() => null);
if (!permission?.granted) {
permission = await native.requestMicrophonePermissionsAsync().catch(() => null);
}
if (!permission?.granted) {
throw new Error(
"Microphone permission is required to capture audio. Please enable microphone access in system settings.",
);
}
}
let nextFileId = 0;
async function playAudio(audio: AudioPlaybackSource, signal: AbortSignal): Promise<number> {
const bytes = new Uint8Array(await audio.arrayBuffer());
if (signal.aborted) throw new Error("Playback stopped");
if (audio.type.startsWith("audio/pcm")) {
await ensureInitialized();
return playPcm16(bytes, audio.type, signal, native);
}
// Capture owns its audio session while active. File playback alone must not
// initialize the microphone or the native two-way engine.
if (!refs.captureActive) {
await setAudioModeAsync({
playsInSilentMode: true,
allowsRecording: false,
interruptionMode: "duckOthers",
interruptionModeAndroid: "duckOthers",
});
}
if (signal.aborted) throw new Error("Playback stopped");
// AVPlayer needs a file extension to recognize local encoded audio on iOS.
const extension =
{
"audio/wav": "wav",
"audio/x-wav": "wav",
"audio/wave": "wav",
"audio/mpeg": "mp3",
"audio/mp3": "mp3",
"audio/mp4": "m4a",
"audio/aac": "aac",
"audio/ogg": "ogg",
"audio/flac": "flac",
}[audio.type.split(";")[0].trim()] ?? "audio";
const file = new File(Paths.cache, `paseo-audio-${Date.now()}-${nextFileId++}.${extension}`);
try {
file.write(bytes);
const player = createAudioPlayer(file.uri, {
updateInterval: 100,
keepAudioSessionActive: refs.captureActive,
});
return await playFile(player, signal);
} finally {
if (file.exists) file.delete();
}
}
const playback = createPlaybackQueue(playAudio, releaseSessionIfIdle);
return {
async initialize() {
await ensureInitialized();
},
async destroy() {
if (refs.destroyed) {
return;
}
refs.destroyed = true;
playback.destroy();
if (refs.captureActive) {
native.toggleRecording(false);
refs.captureActive = false;
}
refs.muted = false;
callbacks.onVolumeLevel(0);
if (refs.initialized) {
native.tearDown();
refs.initialized = false;
}
microphoneSubscription.remove();
volumeSubscription.remove();
interruptionSubscription.remove();
},
async startCapture() {
if (refs.captureActive) {
return;
}
try {
await ensureMicrophonePermission();
await ensureInitialized();
const isRecording =
options?.captureMode === "dictation"
? native.startDictation()
: native.toggleRecording(true);
if (!isRecording) {
throw new Error(
"Microphone capture could not start because Android audio focus is unavailable.",
);
}
refs.captureActive = true;
} catch (error) {
const wrapped = error instanceof Error ? error : new Error(String(error));
callbacks.onError?.(wrapped);
throw wrapped;
}
},
async stopCapture() {
if (refs.captureActive) {
native.toggleRecording(false);
}
refs.captureActive = false;
refs.muted = false;
callbacks.onVolumeLevel(0);
callbacks.onCaptureAvailabilityChange?.(true);
releaseSessionIfIdle();
},
toggleMute() {
refs.muted = !refs.muted;
if (refs.muted) {
callbacks.onVolumeLevel(0);
}
return refs.muted;
},
isMuted() {
return refs.muted;
},
play: playback.play,
stop: playback.stop,
clearQueue: playback.clearQueue,
isPlaying: playback.isPlaying,
};
const native: NativeAudioEngineDeps["native"] = require("@getpaseo/expo-two-way-audio");
return createNativeAudioEngine({ native, playEncodedAudio }, callbacks, options);
}
+1 -3
View File
@@ -292,9 +292,7 @@ export function createAudioEngine(
refs.gain = gain;
} catch (error) {
await stopCapture();
const wrapped = error instanceof Error ? error : new Error(String(error));
callbacks.onError?.(wrapped);
throw wrapped;
throw error;
}
},
+1
View File
@@ -1,3 +1,4 @@
export { createAudioEngine } from "./audio-engine";
export type { AudioEngine, AudioEngineCallbacks, AudioPlaybackSource } from "./audio-engine-types";
export { createPlayAudio } from "./play-audio";
export { AudioCaptureStartError, type AudioCaptureStartFailure } from "./audio-engine-types";
@@ -0,0 +1,188 @@
import { expect, test } from "vitest";
import type { AudioEngineCallbacks } from "./audio-engine-types";
import { createNativeAudioEngine, type NativeAudioEngineDeps } from "./native-audio-engine";
// In-memory stand-in for `@getpaseo/expo-two-way-audio`, matching its iOS and Android modules:
// one native engine per app, `initialize()` reuses it, `tearDown()` frees it, and
// `toggleRecording(true)` / `startDictation()` return false while no engine exists.
// Session handling follows iOS: recording activates the OS audio session, stopping does not
// deactivate it, and `releaseAudioSession()` deactivates it only while nothing is recording.
function fakeTwoWayAudio({
captureAvailable = true,
permissionRequestError,
}: { captureAvailable?: boolean; permissionRequestError?: Error } = {}) {
let engine: { recording: boolean; sessionActive: boolean } | null = null;
const calls = { initialize: 0, tearDown: 0 };
const native: NativeAudioEngineDeps["native"] = {
async initialize() {
calls.initialize += 1;
engine ??= { recording: false, sessionActive: false };
return true;
},
tearDown() {
calls.tearDown += 1;
engine = null;
},
toggleRecording(value: boolean) {
if (!engine) return false;
engine.recording = value;
if (value) engine.sessionActive = true;
return value;
},
startDictation() {
if (!engine || !captureAvailable) return false;
engine.recording = true;
engine.sessionActive = true;
return true;
},
releaseAudioSession() {
if (engine && !engine.recording) engine.sessionActive = false;
},
playPCMData() {},
resumePlayback() {},
stopPlayback() {},
async getMicrophonePermissionsAsync() {
return { granted: !permissionRequestError };
},
async requestMicrophonePermissionsAsync() {
if (permissionRequestError) throw permissionRequestError;
return { granted: true };
},
addExpoTwoWayAudioEventListener() {
return { remove() {} };
},
};
return {
native,
calls,
hasEngine: () => engine !== null,
sessionActive: () => engine?.sessionActive ?? false,
};
}
const recordingCallbacks: AudioEngineCallbacks = {
onCaptureData() {},
onVolumeLevel() {},
};
function deps(native: NativeAudioEngineDeps["native"]): NativeAudioEngineDeps {
return {
native,
playEncodedAudio: async () => 0,
};
}
// Issue #4147: on iPhone, voice mode failed with "Android audio focus is unavailable"
// after the dictation engine was destroyed.
test("voice capture starts after the dictation engine is destroyed", async () => {
const fake = fakeTwoWayAudio();
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
await voiceEngine.initialize();
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await dictationEngine.startCapture();
await dictationEngine.stopCapture();
await dictationEngine.destroy();
await expect(voiceEngine.startCapture()).resolves.toBeUndefined();
});
test("destroying dictation while voice is capturing keeps the native engine", async () => {
const fake = fakeTwoWayAudio();
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
await voiceEngine.startCapture();
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await dictationEngine.initialize();
await dictationEngine.destroy();
expect(fake.hasEngine()).toBe(true);
expect(fake.calls.tearDown).toBe(0);
});
// Review on #9051: with voice holding the engine, destroying an active dictation engine must
// still hand back the idle OS audio session so background music resumes (#2866).
test("destroying active dictation releases the idle audio session while voice keeps the engine", async () => {
const fake = fakeTwoWayAudio();
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
await voiceEngine.initialize();
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await dictationEngine.startCapture();
await dictationEngine.destroy();
expect(fake.hasEngine()).toBe(true);
expect(fake.sessionActive()).toBe(false);
});
test("destroying dictation does not release the session while voice is recording", async () => {
const fake = fakeTwoWayAudio();
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
await voiceEngine.startCapture();
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await dictationEngine.initialize();
await dictationEngine.destroy();
expect(fake.sessionActive()).toBe(true);
});
test("destroying the last engine tears the native engine down", async () => {
const fake = fakeTwoWayAudio();
const voiceEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
const dictationEngine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await voiceEngine.initialize();
await dictationEngine.initialize();
await dictationEngine.destroy();
await voiceEngine.destroy();
expect(fake.calls.tearDown).toBe(1);
expect(fake.hasEngine()).toBe(false);
});
test("an engine destroyed while initializing does not keep the native engine", async () => {
const fake = fakeTwoWayAudio();
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks);
const initializing = expect(engine.initialize()).rejects.toThrow("Audio engine destroyed");
await engine.destroy();
await initializing;
expect(fake.hasEngine()).toBe(false);
});
test("a failed native recording start rejects with a platform-neutral error", async () => {
const fake = fakeTwoWayAudio({ captureAvailable: false });
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await expect(engine.startCapture()).rejects.toThrow(/^Microphone capture could not start\.$/);
await engine.destroy();
});
test("a failed native permission request retains the permission reason and original error", async () => {
const permissionRequestError = new Error("The current activity is not available.");
const fake = fakeTwoWayAudio({ permissionRequestError });
const engine = createNativeAudioEngine(deps(fake.native), recordingCallbacks, {
captureMode: "dictation",
});
await expect(engine.startCapture()).rejects.toMatchObject({
reason: "permissionDenied",
cause: permissionRequestError,
});
expect(fake.hasEngine()).toBe(false);
await engine.destroy();
});
@@ -0,0 +1,292 @@
import type {
AudioEngine,
AudioEngineCallbacks,
AudioEngineOptions,
AudioPlaybackSource,
} from "./audio-engine-types";
import { AudioCaptureStartError } from "./audio-engine-types";
import { createNativeEngineLease, type NativeEngineLease } from "./native-engine-lease";
import { createPlaybackQueue } from "./playback";
import { playPcm16 } from "./pcm";
interface NativeSubscription {
remove(): void;
}
interface MicrophonePermission {
granted: boolean;
}
/** The surface of `@getpaseo/expo-two-way-audio` the engine drives. */
export interface TwoWayAudioModule {
initialize(): Promise<boolean>;
tearDown(): void;
toggleRecording(value: boolean): boolean;
startDictation(): boolean;
releaseAudioSession(): void;
playPCMData(data: Uint8Array): void;
getMicrophonePermissionsAsync(): Promise<MicrophonePermission>;
requestMicrophonePermissionsAsync(): Promise<MicrophonePermission>;
addExpoTwoWayAudioEventListener(
event: "onMicrophoneData",
listener: (event: { data: Uint8Array }) => void,
): NativeSubscription;
addExpoTwoWayAudioEventListener(
event: "onInputVolumeLevelData",
listener: (event: { data: number }) => void,
): NativeSubscription;
addExpoTwoWayAudioEventListener(
event: "onAudioInterruption",
listener: (event: { data: string }) => void,
): NativeSubscription;
}
export interface NativeAudioEngineDeps {
native: TwoWayAudioModule & Parameters<typeof playPcm16>[3];
/** Plays encoded audio (wav, mp3, ...) through the platform player. */
playEncodedAudio(
bytes: Uint8Array,
mimeType: string,
signal: AbortSignal,
context: { isCaptureActive(): boolean },
): Promise<number>;
}
// Voice mode and dictation each create an engine, but the native module holds a single engine
// per app. Every JS engine on the same module shares one lease, so one engine's teardown
// cannot free the native engine another still uses (#4147).
const leases = new WeakMap<TwoWayAudioModule, NativeEngineLease>();
function leaseFor(native: TwoWayAudioModule): NativeEngineLease {
let lease = leases.get(native);
if (!lease) {
lease = createNativeEngineLease(native);
leases.set(native, lease);
}
return lease;
}
export function createNativeAudioEngine(
deps: NativeAudioEngineDeps,
callbacks: AudioEngineCallbacks,
options?: AudioEngineOptions,
): AudioEngine {
const { native } = deps;
const lease = leaseFor(native);
const refs: {
initialized: boolean;
captureActive: boolean;
muted: boolean;
destroyed: boolean;
} = {
initialized: false,
captureActive: false,
muted: false,
destroyed: false,
};
const microphoneSubscription = native.addExpoTwoWayAudioEventListener(
"onMicrophoneData",
(event: { data: Uint8Array }) => {
if (!refs.captureActive || refs.muted) {
return;
}
const pcm = event.data;
callbacks.onCaptureData(pcm);
},
);
const volumeSubscription = native.addExpoTwoWayAudioEventListener(
"onInputVolumeLevelData",
(event: { data: number }) => {
if (!refs.captureActive) {
return;
}
const level = refs.muted ? 0 : event.data;
callbacks.onVolumeLevel(level);
},
);
const interruptionSubscription = native.addExpoTwoWayAudioEventListener(
"onAudioInterruption",
(event: { data: string }) => {
if (event.data === "capture_paused" || event.data === "capture_resumed") {
if (refs.captureActive) {
callbacks.onCaptureAvailabilityChange?.(event.data === "capture_resumed");
}
return;
}
if (event.data !== "blocked") {
return;
}
const wasCaptureActive = refs.captureActive;
refs.captureActive = false;
refs.muted = false;
callbacks.onVolumeLevel(0);
if (wasCaptureActive) {
callbacks.onInterruption?.();
}
},
);
let initializing: Promise<void> | null = null;
async function ensureInitialized(): Promise<void> {
if (refs.destroyed) {
throw new Error("Audio engine destroyed");
}
if (refs.initialized) {
return;
}
initializing ??= (async () => {
try {
await lease.acquire();
if (refs.destroyed) {
releaseNativeEngine();
throw new Error("Audio engine destroyed");
}
refs.initialized = true;
} finally {
initializing = null;
}
})();
await initializing;
}
/**
* Release the OS audio session as soon as we are neither capturing nor playing.
* Holding it keeps the user's background music paused — on iOS the non-mixing
* `.playAndRecord` category survives backgrounding and is re-asserted on every
* foreground, so an unreleased session means their music never comes back.
*/
function releaseSessionIfIdle(): void {
if (!refs.initialized || refs.destroyed) {
return;
}
if (refs.captureActive || playback.isPlaying()) {
return;
}
// The wrapper no-ops on binaries whose native module predates this function.
native.releaseAudioSession();
}
async function ensureMicrophonePermission(): Promise<void> {
const permission = await native.getMicrophonePermissionsAsync().catch(() => null);
if (permission?.granted) return;
let cause: unknown;
try {
if ((await native.requestMicrophonePermissionsAsync()).granted) return;
} catch (error) {
cause = error;
}
throw new AudioCaptureStartError(
"permissionDenied",
"Allow microphone access in system settings and try again.",
{ cause },
);
}
function releaseNativeEngine(): void {
try {
// Native keeps the session active while any wrapper is capturing or playing.
native.releaseAudioSession();
} finally {
lease.release();
}
}
async function playAudio(audio: AudioPlaybackSource, signal: AbortSignal): Promise<number> {
const bytes = new Uint8Array(await audio.arrayBuffer());
if (signal.aborted) throw new Error("Playback stopped");
if (audio.type.startsWith("audio/pcm")) {
await ensureInitialized();
if (signal.aborted) throw new Error("Playback stopped");
return playPcm16(bytes, audio.type, signal, native);
}
return deps.playEncodedAudio(bytes, audio.type, signal, {
isCaptureActive: () => refs.captureActive,
});
}
const playback = createPlaybackQueue(playAudio, releaseSessionIfIdle);
return {
async initialize() {
await ensureInitialized();
},
async destroy() {
if (refs.destroyed) {
return;
}
refs.destroyed = true;
try {
playback.destroy();
if (refs.captureActive) {
refs.captureActive = false;
native.toggleRecording(false);
}
refs.muted = false;
callbacks.onVolumeLevel(0);
} finally {
microphoneSubscription.remove();
volumeSubscription.remove();
interruptionSubscription.remove();
if (refs.initialized) {
refs.initialized = false;
releaseNativeEngine();
}
}
},
async startCapture() {
if (refs.captureActive) {
return;
}
await ensureMicrophonePermission();
await ensureInitialized();
if (refs.destroyed) {
throw new Error("Audio engine destroyed");
}
if (refs.captureActive) {
return;
}
const isRecording =
options?.captureMode === "dictation"
? native.startDictation()
: native.toggleRecording(true);
if (!isRecording) {
throw new Error("Microphone capture could not start.");
}
refs.captureActive = true;
},
async stopCapture() {
if (refs.captureActive) {
native.toggleRecording(false);
}
refs.captureActive = false;
refs.muted = false;
callbacks.onVolumeLevel(0);
callbacks.onCaptureAvailabilityChange?.(true);
releaseSessionIfIdle();
},
toggleMute() {
refs.muted = !refs.muted;
if (refs.muted) {
callbacks.onVolumeLevel(0);
}
return refs.muted;
},
isMuted() {
return refs.muted;
},
play: playback.play,
stop: playback.stop,
clearQueue: playback.clearQueue,
isPlaying: playback.isPlaying,
};
}
@@ -0,0 +1,116 @@
import { expect, test } from "vitest";
import { createNativeEngineLease, type NativeAudioEngineLifecycle } from "./native-engine-lease";
// Mirrors the iOS and Android modules: one engine per app, `initialize()` reuses it,
// `tearDown()` frees it, and `toggleRecording(true)` returns false once it is gone.
function fakeNativeModule(options: { initializeResult?: boolean } = {}) {
let engine: object | null = null;
const calls = { initialize: 0, tearDown: 0 };
let finishInitialize: (() => void) | null = null;
let deferInitialize = false;
const native: NativeAudioEngineLifecycle & {
toggleRecording(value: boolean): boolean;
} = {
initialize() {
calls.initialize += 1;
const complete = () => {
if (options.initializeResult === false) {
return false;
}
engine ??= {};
return true;
};
if (!deferInitialize) {
return Promise.resolve(complete());
}
return new Promise<boolean>((resolve) => {
finishInitialize = () => resolve(complete());
});
},
tearDown() {
calls.tearDown += 1;
engine = null;
},
toggleRecording(value: boolean) {
return engine !== null && value;
},
};
return {
native,
calls,
deferNextInitialize() {
deferInitialize = true;
},
finishInitialize() {
finishInitialize?.();
},
};
}
test("dictation releasing the engine keeps it for voice mode", async () => {
const fake = fakeNativeModule();
const lease = createNativeEngineLease(fake.native);
await lease.acquire(); // voice mode
await lease.acquire(); // dictation
lease.release(); // dictation unmounts
expect(fake.calls.tearDown).toBe(0);
expect(fake.native.toggleRecording(true)).toBe(true);
});
test("the last release tears the native engine down and the next acquire rebuilds it", async () => {
const fake = fakeNativeModule();
const lease = createNativeEngineLease(fake.native);
await lease.acquire();
lease.release();
expect(fake.calls.tearDown).toBe(1);
expect(fake.native.toggleRecording(true)).toBe(false);
await lease.acquire();
expect(fake.calls.initialize).toBe(2);
expect(fake.native.toggleRecording(true)).toBe(true);
});
test("concurrent acquires share one native initialize", async () => {
const fake = fakeNativeModule();
fake.deferNextInitialize();
const lease = createNativeEngineLease(fake.native);
const first = lease.acquire();
const second = lease.acquire();
fake.finishInitialize();
await Promise.all([first, second]);
expect(fake.calls.initialize).toBe(1);
lease.release();
expect(fake.calls.tearDown).toBe(0);
lease.release();
expect(fake.calls.tearDown).toBe(1);
});
test("a failed initialize is not counted as a holder and can be retried", async () => {
const fake = fakeNativeModule({ initializeResult: false });
const lease = createNativeEngineLease(fake.native);
await expect(lease.acquire()).rejects.toThrow("native initialize() returned false");
lease.release();
expect(fake.calls.tearDown).toBe(0);
await expect(lease.acquire()).rejects.toThrow();
expect(fake.calls.initialize).toBe(2);
});
test("a release with no holders is a no-op", async () => {
const fake = fakeNativeModule();
const lease = createNativeEngineLease(fake.native);
await lease.acquire();
lease.release();
lease.release();
await lease.acquire();
lease.release();
expect(fake.calls.tearDown).toBe(2);
});
@@ -0,0 +1,57 @@
/**
* The part of `@getpaseo/expo-two-way-audio` that owns the native engine's lifetime.
* Each platform keeps a single engine per app: `initialize()` reuses it, `tearDown()` frees it.
*/
export interface NativeAudioEngineLifecycle {
initialize(): Promise<boolean>;
tearDown(): void;
}
export interface NativeEngineLease {
/** Ensure the native engine exists and count the caller as a holder. */
acquire(): Promise<void>;
/** Drop one holder; the native engine is torn down when the last holder releases. */
release(): void;
}
/**
* Voice mode and dictation each create their own JS audio engine, but both drive the one
* native engine. Counting holders keeps one consumer's teardown from freeing the engine
* the other still uses (issue #4147: voice mode on iOS could not start after dictation).
*/
export function createNativeEngineLease(native: NativeAudioEngineLifecycle): NativeEngineLease {
let holders = 0;
let ready: Promise<void> | null = null;
async function initialize(): Promise<void> {
const success = await native.initialize();
if (!success) {
throw new Error("expo-two-way-audio: native initialize() returned false");
}
}
return {
async acquire() {
holders += 1;
ready ??= initialize();
try {
await ready;
} catch (error) {
holders -= 1;
ready = null;
throw error;
}
},
release() {
if (holders === 0) {
return;
}
holders -= 1;
if (holders === 0) {
ready = null;
native.tearDown();
}
},
};
}
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import {
CalendarClock,
CircleDashed,
Copy,
Folder,
FolderPlus,
History,
@@ -17,6 +18,8 @@ import {
} from "lucide-react-native";
import { withUnistyles } from "react-native-unistyles";
import { useIsCompactFormFactor } from "@/constants/layout";
import { useToast } from "@/contexts/toast-context";
import { getDesktopHost } from "@/desktop/host";
import { useKeyboardShortcutOverrides } from "@/hooks/use-keyboard-shortcut-overrides";
import { useOpenAddProject } from "@/hooks/use-open-add-project";
import { useImportSession } from "@/hooks/use-import-session";
@@ -27,6 +30,7 @@ import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
import { usePanelStore } from "@/stores/panel-store";
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
import { clearCommandCenterFocusRestoreElement } from "@/utils/command-center-focus-restore";
import { copyToClipboard } from "@/utils/copy-to-clipboard";
import {
buildOpenProjectRoute,
buildSchedulesRoute,
@@ -35,6 +39,7 @@ import {
} from "@/utils/host-routes";
import { getShortcutOs } from "@/utils/shortcut-platform";
import type { CommandCenterContribution, CommandCenterIconProps } from "./contributions";
import { getCommandCenterIcon } from "./icon";
import { useCommandCenterActions } from "./provider";
import { buildGroupingContribution } from "./root-contributions";
@@ -63,6 +68,7 @@ const ThemedCircleDashed = withUnistyles(CircleDashed, (theme) => ({
const ThemedPanelLeft = withUnistyles(PanelLeft, (theme) => ({
color: theme.colors.foregroundMuted,
}));
const BrowserHostCopyIcon = getCommandCenterIcon(Copy);
function PlusIcon({ size }: CommandCenterIconProps) {
return <ThemedPlus size={size} strokeWidth={2.4} />;
@@ -111,6 +117,8 @@ function PanelLeftIcon({ size }: CommandCenterIconProps) {
export function CommandCenterRootActions() {
const keyboardActionDispatcher = useKeyboardActionDispatcher();
const { t } = useTranslation();
const toast = useToast();
const browserHostLabel = getDesktopHost()?.browserHostLabel;
const { overrides } = useKeyboardShortcutOverrides();
const shortcutsAvailable = useHardwareKeyboardPresent();
const openAddProject = useOpenAddProject();
@@ -296,6 +304,32 @@ export function CommandCenterRootActions() {
},
];
if (browserHostLabel) {
availableActions.push({
id: "copy-browser-host-name",
group: "actions",
groupRank: 0,
rank: 9,
keywords: ["browser", "host", "window", browserHostLabel],
visibility: "query",
run: async () => {
try {
await copyToClipboard(browserHostLabel);
toast.copied();
} catch {
toast.error(t("common.errors.unableToCopy"));
}
},
presentation: {
kind: "action",
title: t("shell.commandCenter.copyBrowserHostName"),
subtitle: browserHostLabel,
sectionTitle: t("shell.commandCenter.actions"),
icon: BrowserHostCopyIcon,
},
});
}
if (shortcutsAvailable) {
availableActions.push({
id: "keyboard-shortcuts",
@@ -332,6 +366,7 @@ export function CommandCenterRootActions() {
return availableActions;
}, [
browserHostLabel,
groupMode,
homeRoute,
keyboardActionDispatcher,
@@ -346,6 +381,7 @@ export function CommandCenterRootActions() {
shortcutPlatform,
shortcutsAvailable,
t,
toast,
toggleAgentList,
]);
@@ -6,7 +6,6 @@ import { FOOTER_HEIGHT } from "@/constants/layout";
import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime";
import { KeyboardTranslateView } from "@/keyboard/shift";
import { Button } from "@/components/ui/button";
import { useToast } from "@/contexts/toast-context";
import type { Theme } from "@/styles/theme";
import { toErrorMessage } from "@/utils/error-messages";
@@ -19,7 +18,6 @@ export function ArchivedAgentCallout({ serverId, agentId }: ArchivedAgentCallout
const { t } = useTranslation();
const client = useHostRuntimeClient(serverId);
const isConnected = useHostRuntimeIsConnected(serverId);
const toast = useToast();
const [isUnarchiving, setIsUnarchiving] = useState(false);
const [unarchiveError, setUnarchiveError] = useState<string | null>(null);
@@ -28,15 +26,12 @@ export function ArchivedAgentCallout({ serverId, agentId }: ArchivedAgentCallout
setIsUnarchiving(true);
setUnarchiveError(null);
try {
const refreshed = await client.refreshAgent(agentId);
if (refreshed.historyDiverged) {
toast.show(t("workspace.tabs.toasts.reloadedAgentHistoryDiverged"), { variant: "warning" });
}
await client.refreshAgent(agentId);
} catch (error) {
setUnarchiveError(toErrorMessage(error));
setIsUnarchiving(false);
}
}, [client, isConnected, isUnarchiving, agentId, toast, t]);
}, [client, isConnected, isUnarchiving, agentId]);
return (
<KeyboardTranslateView style={styles.container}>
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
import { Pressable, Text, View, type PressableStateCallbackType } from "react-native";
import { useTranslation } from "react-i18next";
import { StyleSheet, withUnistyles } from "react-native-unistyles";
@@ -19,7 +19,10 @@ import {
type ToolbarGlyph,
} from "@/components/ui/control-geometry";
import { useKeyboardToggle, type KeyboardToggleAction } from "@/hooks/use-keyboard-toggle";
const EMPTY_COMBOBOX_OPTIONS: ComboboxOption[] = [];
const DEFAULT_TRIGGER_DECORATION = { showCaret: true, tooltip: undefined };
const ThemedLoadingSpinner = withUnistyles(LoadingSpinner);
const foregroundMutedMapping = (theme: Theme) => ({
@@ -47,6 +50,7 @@ interface CombinedModelSelectorProps {
hovered: boolean;
pressed: boolean;
}) => React.ReactNode;
toggleAction?: KeyboardToggleAction;
onOpen?: () => void;
onClose?: () => void;
onRetryProvider?: (provider: AgentProvider) => void;
@@ -67,6 +71,7 @@ interface CombinedModelSelectorProps {
toolbar?: {
glyph: ToolbarGlyph;
showCaret: boolean;
tooltip?: ReactNode;
};
}
@@ -82,6 +87,7 @@ export function CombinedModelSelector({
onCreateProfile,
onEditProfile,
renderTrigger,
toggleAction,
onOpen,
onClose,
onRetryProvider,
@@ -147,6 +153,14 @@ export function CombinedModelSelector({
handleOpenChange(!isOpen);
}, [handleOpenChange, isOpen]);
useKeyboardToggle({
action: toggleAction,
disabled,
open: isOpen,
searchFocused: browser.isSearchFocused,
onToggle: handleTriggerPress,
});
const triggerStyle = useCallback(
({ pressed, hovered }: PressableStateCallbackType & { hovered?: boolean }) => {
if (triggerFill) {
@@ -216,6 +230,8 @@ export function CombinedModelSelector({
</View>
);
const { showCaret, tooltip } = toolbar ?? DEFAULT_TRIGGER_DECORATION;
return (
<>
{renderTrigger ? (
@@ -254,7 +270,8 @@ export function CombinedModelSelector({
model: browser.selectedModelLabel,
})}
testID="combined-model-selector"
chevron={toolbar?.showCaret === false ? null : undefined}
chevron={showCaret === false ? null : undefined}
tooltip={tooltip}
>
{selectedProvider.trim().length > 0 ? (
<View style={toolbar ? styles.toolbarGlyph : styles.glyph}>
File diff suppressed because one or more lines are too long
@@ -215,6 +215,32 @@ describe("Mermaid sandbox runtime", () => {
expect(widths).toEqual([240, 350, 900]);
});
/**
* Agents often write a label that starts with a mention or holds an email address. Mermaid 11
* read the text up to the "@" as an edge id, so these diagrams failed to parse.
*/
it.each([
"flowchart LR\n F[@mention in any workspace] --> G[Look up token]",
"flowchart LR\n A[ops@example.com] --> B",
"flowchart LR\n A -->|@user approves| B",
"graph TD\n A(@x) --> B{@x?}",
])("renders a flowchart whose label contains an @: %s", async (source) => {
const frame = await mountRuntime();
const result = await render(frame, { revision: 1, source });
expect(result).toMatchObject({ type: "rendered", revision: 1, source });
});
it("still renders a flowchart edge id", async () => {
const frame = await mountRuntime();
const source = "flowchart LR\n A[Start] e1@--> B[End]";
const result = await render(frame, { revision: 1, source });
expect(result).toMatchObject({ type: "rendered", revision: 1, source });
});
it("coalesces queued input and never reports an obsolete result", async () => {
const frame = await mountRuntime();
const obsoleteSource = `flowchart TD\n${Array.from({ length: 250 }, (_, index) => `A${index} --> A${index + 1}`).join("\n")}`;
@@ -0,0 +1,103 @@
// @vitest-environment jsdom
import type { ReactNode } from "react";
import { cleanup, renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { afterEach, beforeEach, expect, it } from "vitest";
import type { FileReadResult } from "@getpaseo/client/internal/daemon-client";
import { __setAttachmentStoreForTests } from "@/attachments/store";
import type { AttachmentStore } from "@/attachments/types";
import { useMarkdownSource, type MarkdownImageContext } from "./images";
import { PENDING_MARKDOWN_IMAGE } from "./source";
const memoryStore: AttachmentStore = {
storageType: "web-indexeddb",
async save(input) {
return {
id: input.id ?? "att_chart",
mimeType: input.mimeType ?? "image/png",
storageType: "web-indexeddb",
storageKey: input.id ?? "att_chart",
fileName: input.fileName,
createdAt: 1,
};
},
async encodeBase64() {
return "";
},
async resolvePreviewUrl() {
return "blob:chart";
},
async releasePreviewUrl() {},
async delete() {},
async garbageCollect() {},
};
function createHostFiles() {
const reads: { cwd: string; path: string }[] = [];
return {
reads,
async readFile(cwd: string, path: string): Promise<FileReadResult> {
reads.push({ cwd, path });
return {
kind: "image",
path,
mime: "image/png",
size: 4,
modifiedAt: "2026-11-18T00:00:00.000Z",
bytes: new Uint8Array([1, 2, 3, 4]),
};
},
};
}
beforeEach(() => {
__setAttachmentStoreForTests(memoryStore);
});
afterEach(() => {
cleanup();
__setAttachmentStoreForTests(null);
});
function renderMarkdownSource(text: string, initialProps: MarkdownImageContext) {
// No retries: a failed read settles at once. For a host's Markdown this is the state once the
// retries have run out on a host that is slow to connect.
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const wrapper = ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
const rendered = renderHook((props: MarkdownImageContext) => useMarkdownSource(text, props), {
wrapper,
initialProps,
});
return { ...rendered, queryClient };
}
it("waits for the host's client before reading a workspace image", async () => {
const context = { serverId: "srv_test", workspaceRoot: "/repo" };
const { result, rerender, queryClient } = renderMarkdownSource("![Chart](chart.png)", {
...context,
client: null,
});
await waitFor(() => {
expect(queryClient.isFetching()).toBe(0);
expect(result.current.markdown.replace(PENDING_MARKDOWN_IMAGE, "pending")).toBe(
"![Chart](<pending>)",
);
});
const files = createHostFiles();
rerender({ ...context, client: files });
await waitFor(() => expect(result.current.imageSources).toEqual({ "blob:chart": "chart.png" }));
expect(files.reads).toEqual([{ cwd: "/repo", path: "chart.png" }]);
});
it("shows the alt text of a file image in Markdown that belongs to no host", async () => {
const { result } = renderMarkdownSource("![Chart](/tmp/chart.png)", {});
await waitFor(() =>
expect(result.current.markdown.replace(PENDING_MARKDOWN_IMAGE, "pending")).toBe("Chart"),
);
});
@@ -81,7 +81,10 @@ export function useMarkdownSource(
const results = useFetchQueries(
acquisitions.map((acquisition, index) => ({
queryKey: ["markdownImage", acquisition?.key ?? sources[index]],
enabled: acquisition !== null,
// A host that hasn't connected yet has no client. Its images stay pending until it does: the
// key doesn't change when the client arrives, so a read that already failed would not run
// again. Markdown with no host has no client to wait for and falls back to its alt text.
enabled: acquisition !== null && (context.client != null || !context.serverId),
immutableWhen: () => true,
dataShape: "value",
gcTime: 0,
+7 -3
View File
@@ -11,8 +11,12 @@ import {
} from "@/components/attachment-pill";
import { MarkdownRenderer } from "@/components/markdown/renderer";
import { useRetainedPanelActive } from "@/components/retained-panel";
import { RewindMenu, type RewindMode } from "@/components/rewind/rewind-menu";
import { useRewindAgentMutation } from "@/components/rewind/use-rewind-agent-mutation";
import {
isRewindableMessage,
RewindMenu,
useRewindAgentMutation,
type RewindMode,
} from "@/components/rewind";
import { TaskListRow } from "@/components/task-list-row";
import { LoadingSpinner } from "@/components/ui/loading-spinner";
import { useIsCompactFormFactor } from "@/constants/layout";
@@ -530,7 +534,7 @@ export const UserMessage = memo(function UserMessage({
<Text style={userMessageStylesheet.timestampText} testID="user-message-timestamp">
{formattedTimestamp}
</Text>
{capabilities && messageId ? (
{capabilities && isRewindableMessage(messageId, message) ? (
<RewindMenu
capabilities={capabilities}
isPending={rewindMutation.isPending}
@@ -0,0 +1,91 @@
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Undo2 } from "lucide-react-native";
import type { AgentCapabilityFlags } from "@getpaseo/protocol/agent-types";
import type { CommandCenterContribution } from "@/command-center/contributions";
import { getCommandCenterIcon } from "@/command-center/icon";
import { useCommandCenterActions } from "@/command-center/provider";
import { hasActiveMessageSubmission } from "@/composer/submission/model";
import { useToast } from "@/contexts/toast-context";
import type { AgentScreenReadySyncState } from "@/hooks/use-agent-screen-state-machine";
import { selectAgentTimelineState, useSessionStore } from "@/stores/session-store";
import { useRewindAgentMutation } from "./use-rewind-agent-mutation";
import { isRewindableMessage, useRewindMenuItems } from "./use-rewind-capabilities";
export function RewindCommandCenterRegistration({
serverId,
agentId,
capabilities,
timelineSync,
enabled,
}: {
serverId: string;
agentId: string;
capabilities: AgentCapabilityFlags | null | undefined;
timelineSync: AgentScreenReadySyncState | null;
enabled: boolean;
}) {
const { t } = useTranslation();
const toast = useToast();
const canSelectLatestMessage = enabled && timelineSync?.status === "idle";
const client = useSessionStore((state) => state.sessions[serverId]?.client);
const message = useSessionStore((state) => {
const session = state.sessions[serverId];
if (
!canSelectLatestMessage ||
!session ||
hasActiveMessageSubmission(session.messageSubmissions.get(agentId))
) {
return undefined;
}
const timeline = selectAgentTimelineState(session, agentId);
if (timeline.status !== "synced" || timeline.newer === "available") {
return undefined;
}
return (
session.agentStreamHead.get(agentId)?.findLast((item) => item.kind === "user_message") ??
timeline.items.findLast((item) => item.kind === "user_message")
);
});
const { rewindAgent, isPending } = useRewindAgentMutation({
serverId,
agentId,
client,
messageId: message?.messageId,
});
const items = useRewindMenuItems(capabilities);
const actions = useMemo<CommandCenterContribution[]>(() => {
if (!message || !isRewindableMessage(message.messageId, message.text)) return [];
return items.map((item, rank) => ({
id: `rewind:${item.mode}`,
group: "rewind",
groupRank: 1.5,
rank,
visibility: "query",
keywords: ["rewind last turn", ...(item.mode === "files" ? [] : ["rewind chat"])],
presentation: {
kind: "action",
title: item.label,
subtitle: t("rewind.warning"),
icon: getCommandCenterIcon(Undo2),
},
run: async () => {
const dismiss = toast.show(`${item.label}…`, { durationMs: null });
try {
await rewindAgent({ mode: item.mode, rewoundText: message.text });
} catch {
// The mutation reports the failure through the app toast.
} finally {
dismiss();
}
},
}));
}, [items, message, rewindAgent, t, toast]);
useCommandCenterActions({
sourceId: `rewind:${serverId}:${agentId}`,
enabled: canSelectLatestMessage && Boolean(client) && !isPending,
actions,
});
return null;
}
@@ -8,7 +8,7 @@ interface RewindComposerRestoreContextValue {
interface RewindComposerRestoreProviderProps {
textSource: ComposerTextSource;
setText: (text: string) => void;
onRewindComplete: () => void;
onRewindComplete: (restoredComposerText: boolean) => void;
children: ReactNode;
}
@@ -37,10 +37,11 @@ export function RewindComposerRestoreProvider({
currentText: currentText,
rewoundText,
});
if (nextText !== currentText) {
const restoredComposerText = nextText !== currentText;
if (restoredComposerText) {
setText(nextText);
}
onRewindComplete();
onRewindComplete(restoredComposerText);
},
[onRewindComplete, setText, textSource],
);
@@ -0,0 +1,5 @@
export { RewindCommandCenterRegistration } from "./command-center-registration";
export { RewindComposerRestoreProvider } from "./composer-restore";
export { RewindMenu } from "./rewind-menu";
export { useRewindAgentMutation } from "./use-rewind-agent-mutation";
export { isRewindableMessage, type RewindMode } from "./use-rewind-capabilities";
@@ -11,11 +11,9 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { type RewindMode, useRewindCapabilities } from "./use-rewind-capabilities";
import { type RewindMode, useRewindMenuItems } from "./use-rewind-capabilities";
import type { AgentCapabilityFlags } from "@getpaseo/protocol/agent-types";
export type { RewindMode };
interface RewindMenuProps {
capabilities: AgentCapabilityFlags;
rewoundText: string;
@@ -44,15 +42,7 @@ export const RewindMenu = memo(function RewindMenu({
}: RewindMenuProps) {
const { theme } = useUnistyles();
const { t } = useTranslation();
const rewindLabels = useMemo(
() => ({
conversation: t("rewind.actions.conversation"),
files: t("rewind.actions.files"),
both: t("rewind.actions.both"),
}),
[t],
);
const items = useRewindCapabilities(capabilities, rewindLabels);
const items = useRewindMenuItems(capabilities);
const [isOpen, setIsOpen] = useState(false);
const [pendingMode, setPendingMode] = useState<RewindMode | null>(null);
const isLocked = isPendingProp || pendingMode !== null;
@@ -1,7 +1,7 @@
import { planTimelineTailFetch } from "@/timeline/timeline-sync-plan";
import { useCallback } from "react";
import { useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useMutation } from "@tanstack/react-query";
import { useIsMutating, useMutation, useQueryClient } from "@tanstack/react-query";
import { useToast } from "@/contexts/toast-context";
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import type { RewindMode } from "./use-rewind-capabilities";
@@ -9,7 +9,6 @@ import { useRewindComposerRestore } from "./composer-restore";
import { useSessionStore } from "@/stores/session-store";
import { shouldRestoreComposerForRewindMode } from "./rewind-mode";
import { getHostRuntimeStore } from "@/runtime/host-runtime";
import { hostSupportsFeature } from "@/runtime/host-features";
interface UseRewindAgentMutationInput {
serverId?: string;
@@ -30,22 +29,20 @@ export function useRewindAgentMutation(input: UseRewindAgentMutationInput): {
const toast = useToast();
const { t } = useTranslation();
const composerRestore = useRewindComposerRestore();
const { isPending, mutateAsync } = useMutation({
const queryClient = useQueryClient();
const mutationKey = useMemo(
() => ["agent-rewind", input.serverId, input.agentId],
[input.serverId, input.agentId],
);
const isPending = useIsMutating({ mutationKey, exact: true }) > 0;
const { mutateAsync } = useMutation({
mutationKey,
mutationFn: async ({ mode }: RewindAgentInput) => {
if (!input.client || !input.agentId || !input.messageId) {
throw new Error(t("common.errors.daemonClientUnavailable"));
}
await input.client.rewindAgent(input.agentId, input.messageId, mode);
// COMPAT(timelineRewindOperations): added in v0.14.1, remove after 2027-05-10. A daemon with
// the feature delivers the rewind on the live timeline; an older one replaced the timeline
// and this client has to read it again.
const appliesLive =
input.serverId !== undefined &&
hostSupportsFeature(
useSessionStore.getState().sessions[input.serverId]?.serverInfo,
"timelineRewindOperations",
);
if (mode !== "files" && !appliesLive) {
if (mode !== "files") {
const cursor = input.serverId
? useSessionStore
.getState()
@@ -71,12 +68,12 @@ export function useRewindAgentMutation(input: UseRewindAgentMutationInput): {
const rewindAgent = useCallback(
async (rewindInput: RewindAgentInput) => {
if (isPending) {
if (queryClient.isMutating({ mutationKey, exact: true }) > 0) {
return;
}
await mutateAsync(rewindInput);
},
[isPending, mutateAsync],
[mutateAsync, mutationKey, queryClient],
);
return {
@@ -1,4 +1,5 @@
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import type { AgentCapabilityFlags } from "@getpaseo/protocol/agent-types";
export type RewindMode = "conversation" | "files" | "both";
@@ -21,6 +22,10 @@ const DEFAULT_REWIND_MENU_LABELS: RewindMenuLabels = {
both: "Rewind conversation and files",
};
export function isRewindableMessage(messageId: string | undefined, text: string): boolean {
return Boolean(messageId) && text.trim().length > 0;
}
export function resolveRewindMenuItems(
capabilities:
| Pick<
@@ -60,9 +65,17 @@ export function resolveRewindMenuItems(
return items;
}
export function useRewindCapabilities(
export function useRewindMenuItems(
capabilities: Parameters<typeof resolveRewindMenuItems>[0],
labels?: Partial<RewindMenuLabels>,
): RewindMenuItem[] {
return useMemo(() => resolveRewindMenuItems(capabilities, labels), [capabilities, labels]);
const { t } = useTranslation();
return useMemo(
() =>
resolveRewindMenuItems(capabilities, {
conversation: t("rewind.actions.conversation"),
files: t("rewind.actions.files"),
both: t("rewind.actions.both"),
}),
[capabilities, t],
);
}
@@ -825,20 +825,22 @@ function ScheduleIsolationField({
{
id: "local",
value: "local",
label: "Local",
label: "Project directory",
testID: "schedule-isolation-local",
},
{
id: "worktree",
value: "worktree",
label: "Worktree",
label: "New worktree",
testID: "schedule-isolation-worktree",
},
],
[],
);
const selectedDisplay = useMemo<SelectFieldDisplay>(
() => ({ label: state.effectiveIsolation === "worktree" ? "Worktree" : "Local" }),
() => ({
label: state.effectiveIsolation === "worktree" ? "New worktree" : "Project directory",
}),
[state.effectiveIsolation],
);
const triggerLeading = useMemo(
@@ -1,3 +1,4 @@
import { useWorkspaceRowPress } from "../../modules/paseo-press-feedback";
import { PressHighlight as Pressable } from "@/components/ui/press-highlight";
import { LoadingSpinner } from "@/components/ui/loading-spinner";
import {
@@ -1091,13 +1092,11 @@ function WorkspaceRowInner({
...dragAttributes
} = dragHandleProps?.attributes ?? {};
const handlePress = useCallback(() => {
if (interaction.didLongPressRef.current) {
interaction.didLongPressRef.current = false;
return;
}
onPress();
}, [interaction.didLongPressRef, onPress]);
const { onPress: handlePress, feedback } = useWorkspaceRowPress({
didLongPressRef: interaction.didLongPressRef,
onPress,
selected,
});
const accessibilityState = useMemo(() => ({ selected }), [selected]);
const isEditingTitle = titleEditor !== null;
@@ -1192,6 +1191,7 @@ function WorkspaceRowInner({
onTogglePin={onTogglePin}
/>
</SidebarWorkspaceRowContent>
{feedback}
</SidebarWorkspaceContextMenu>
</View>
);
@@ -1,3 +1,4 @@
import { useWorkspaceRowPress } from "../../../modules/paseo-press-feedback";
import { PressHighlight as Pressable } from "@/components/ui/press-highlight";
import {
memo,
@@ -848,13 +849,11 @@ function StatusWorkspaceRowInnerContent({
const startDragPress = dragInteraction?.handlePressIn;
const moveDragPress = dragInteraction?.handleTouchMove;
const endDragPress = dragInteraction?.handlePressOut;
const handlePress = useCallback(() => {
if (didLongPressRef?.current) {
didLongPressRef.current = false;
return;
}
onPress();
}, [didLongPressRef, onPress]);
const { onPress: handlePress, feedback } = useWorkspaceRowPress({
didLongPressRef,
onPress,
selected,
});
return (
<SidebarWorkspaceRowFrame
@@ -967,6 +966,7 @@ function StatusWorkspaceRowInnerContent({
/>
) : null}
</SidebarWorkspaceRowContent>
{feedback}
</SidebarWorkspaceContextMenu>
</View>
);
@@ -13,6 +13,7 @@ import {
useRef,
type CSSProperties,
type MouseEvent as ReactMouseEvent,
type PointerEvent as ReactPointerEvent,
type Ref,
} from "react";
import type { DOMProps } from "expo/dom";
@@ -63,6 +64,22 @@ const HOST_DIV_STYLE: CSSProperties = {
paddingRight: 0,
};
interface TerminalTouchFocus {
pointerId: number;
x: number;
y: number;
}
// A phone browser shortens the visual viewport, not the layout viewport, for its keyboard.
const SOFTWARE_KEYBOARD_MIN_HEIGHT_PX = 100;
function isSoftwareKeyboardShown(): boolean {
const viewport = window.visualViewport;
if (!viewport) return false;
const visibleHeight = viewport.height * viewport.scale;
return window.innerHeight - visibleHeight > SOFTWARE_KEYBOARD_MIN_HEIGHT_PX;
}
function buildXtermThemeKey(theme: ITheme): string {
const values: Array<string> = [
theme.background,
@@ -553,10 +570,48 @@ export default function TerminalEmulator({
});
}, []);
const handleRootPointerDown = useCallback(() => {
onFocus?.();
runtimeRef.current?.focus();
}, [onFocus]);
const touchFocusRef = useRef<TerminalTouchFocus | null>(null);
const handleRootPointerDown = useCallback(
(event: ReactPointerEvent) => {
onFocus?.();
touchFocusRef.current = null;
if (event.pointerType !== "touch") {
runtimeRef.current?.focus();
return;
}
// Focusing before a touch becomes a tap opens the keyboard during a scroll.
if (event.isPrimary) {
touchFocusRef.current = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
};
}
},
[onFocus],
);
const handleRootPointerMove = useCallback((event: ReactPointerEvent) => {
const touch = touchFocusRef.current;
if (touch?.pointerId !== event.pointerId) return;
if (Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 8) {
touchFocusRef.current = null;
// Android Back hides the keyboard but leaves the input focused, and a drag
// on a focused input reopens it. An open keyboard stays open while scrolling.
if (!isSoftwareKeyboardShown()) runtimeRef.current?.blur();
}
}, []);
const handleRootPointerUp = useCallback((event: ReactPointerEvent) => {
const touch = touchFocusRef.current;
touchFocusRef.current = null;
if (touch?.pointerId === event.pointerId) runtimeRef.current?.focus();
}, []);
const handleRootPointerCancel = useCallback(() => {
touchFocusRef.current = null;
}, []);
const handleRootContextMenu = useCallback(
(event: ReactMouseEvent) => {
@@ -588,6 +643,9 @@ export default function TerminalEmulator({
data-terminal-scrollbar-root="true"
style={rootDivStyle}
onPointerDown={handleRootPointerDown}
onPointerMove={handleRootPointerMove}
onPointerUp={handleRootPointerUp}
onPointerCancel={handleRootPointerCancel}
onContextMenu={handleRootContextMenu}
>
<div ref={hostRef} style={HOST_DIV_STYLE} />
@@ -0,0 +1,69 @@
import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ToastViewport, useToastHost, type ToastApi } from "@/components/toast-host";
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
let root: Root | null = null;
let container: HTMLDivElement | null = null;
afterEach(() => {
act(() => root?.unmount());
container?.remove();
root = null;
container = null;
vi.useRealTimers();
});
function mountToastHost(): ToastApi {
let api: ToastApi | null = null;
function Host() {
const host = useToastHost();
api = host.api;
return <ToastViewport toast={host.toast} onDismiss={host.dismiss} placement="sidebar" />;
}
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
act(() =>
root?.render(
<SafeAreaProvider>
<Host />
</SafeAreaProvider>,
),
);
if (!api) throw new Error("The toast host did not render");
return api;
}
function shownMessage(): string | null {
return document.querySelector('[data-testid="app-toast-message"]')?.textContent ?? null;
}
describe("ToastViewport", () => {
it("keeps a new toast when the toast it replaced times out before the next render", () => {
vi.useFakeTimers();
const toast = mountToastHost();
act(() => {
toast.show("Installed review");
});
act(() => {
vi.advanceTimersByTime(2199);
});
// The new toast is in state, but React has not rendered it, so the old toast's timer is
// still scheduled when it expires.
act(() => {
toast.show("Reloaded review");
vi.advanceTimersByTime(1);
});
expect(shownMessage()).toBe("Reloaded review");
act(() => {
vi.advanceTimersByTime(2199);
});
expect(shownMessage()).toBe("Reloaded review");
});
});
+25 -14
View File
@@ -53,6 +53,12 @@ export interface ToastState {
/** Dismisses the toast it was returned for; a no-op once another toast replaced it. */
export type DismissToast = () => void;
/**
* Dismisses the toast with this ID, and does nothing once another toast replaced it. Without an
* ID, it dismisses whichever toast is shown.
*/
export type DismissToastById = (id?: number) => void;
export interface ToastApi {
show: (content: ReactNode, options?: ToastShowOptions) => DismissToast;
copied: (label?: string) => void;
@@ -81,7 +87,7 @@ const errorIcon = (theme: Theme) => ({ color: theme.colors.destructive });
export function useToastHost(): {
api: ToastApi;
toast: ToastState | null;
dismiss: () => void;
dismiss: DismissToastById;
} {
const { t } = useTranslation();
const [toast, setToastState] = useState<ToastState | null>(null);
@@ -96,6 +102,13 @@ export function useToastHost(): {
previous?.onDismiss?.();
}, []);
const dismiss = useCallback<DismissToastById>(
(id) => {
if (id === undefined || toastRef.current?.id === id) setToast(null);
},
[setToast],
);
const show = useCallback(
(content: ReactNode, options?: ToastShowOptions): DismissToast => {
const nativeMessage = typeof content === "string" ? content.trim() : null;
@@ -127,11 +140,9 @@ export function useToastHost(): {
testID: options?.testID,
onDismiss: options?.onDismiss,
});
return () => {
if (toastRef.current?.id === id) setToast(null);
};
return () => dismiss(id);
},
[setToast],
[dismiss, setToast],
);
const api = useMemo<ToastApi>(
@@ -147,10 +158,6 @@ export function useToastHost(): {
[show, t],
);
const dismiss = useCallback(() => {
setToast(null);
}, [setToast]);
return { api, toast, dismiss };
}
@@ -161,7 +168,8 @@ export function ToastViewport({
onBottomCoverageChange,
}: {
toast: ToastState | null;
onDismiss: () => void;
/** Called with the ID of the toast that timed out. */
onDismiss: (id: number) => void;
placement?: ToastViewportPlacement;
/** Sidebar placement: reports the distance from the region's bottom edge to the toast's top. */
onBottomCoverageChange?: (coverage: number) => void;
@@ -180,7 +188,7 @@ export function ToastViewport({
}, []);
const scheduleDismiss = useCallback(
(durationMs: number | null) => {
(id: number, durationMs: number | null) => {
clearTimer();
if (durationMs === null) {
remainingDurationRef.current = 0;
@@ -190,8 +198,10 @@ export function ToastViewport({
const nextDurationMs = Math.max(0, durationMs);
remainingDurationRef.current = nextDurationMs;
dismissDeadlineRef.current = Date.now() + nextDurationMs;
// A replacing toast is in the host before this viewport renders it and reschedules, so the
// timer names its own toast rather than dismissing whichever one is current.
timeoutRef.current = setTimeout(() => {
onDismiss();
onDismiss(id);
}, nextDurationMs);
},
[onDismiss, clearTimer],
@@ -209,13 +219,14 @@ export function ToastViewport({
if (!toast || toast.durationMs === null) {
return;
}
scheduleDismiss(remainingDurationRef.current || toast.durationMs);
scheduleDismiss(toast.id, remainingDurationRef.current || toast.durationMs);
}, [scheduleDismiss, toast]);
const toastId = toast?.id;
const durationMs = toast?.durationMs ?? null;
useEffect(() => {
scheduleDismiss(durationMs);
if (toastId === undefined) return;
scheduleDismiss(toastId, durationMs);
return clearTimer;
}, [clearTimer, durationMs, scheduleDismiss, toastId]);
@@ -21,7 +21,7 @@ import { highlightDiffLines } from "@/utils/diff-highlight";
import { hasMeaningfulToolCallDetail } from "@/utils/tool-call-detail-state";
import { inlineUnistylesStyle } from "@/styles/unistyles-inline-style";
import { CODE_SURFACE_DATASET } from "@/styles/code-surface";
import { extensionFromPath, highlightToKeyedLines } from "@/utils/highlight-cache";
import { highlightToKeyedLines } from "@/utils/highlight-cache";
import { HighlightedLines } from "./highlighted-content";
import { DiffViewer } from "./diff-viewer";
import { getCodeInsets } from "./code-insets";
@@ -226,7 +226,7 @@ function ScrollableTextSection({
startLine,
}: ScrollableContentProps) {
const keyedLines = useMemo(
() => (filePath ? highlightToKeyedLines(content, extensionFromPath(filePath)) : null),
() => highlightToKeyedLines(content, filePath ?? null),
[content, filePath],
);
const body = (
@@ -19,6 +19,7 @@ import {
import { StyleSheet, withUnistyles } from "react-native-unistyles";
import { ChevronDown } from "lucide-react-native";
import { ICON_SIZE, type Theme } from "@/styles/theme";
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
const ThemedChevronDown = withUnistyles(ChevronDown);
@@ -38,6 +39,7 @@ interface ComboboxTriggerProps extends Omit<PressableProps, "style" | "children"
style?: TriggerStyleProp;
children?: ReactNode;
chevron?: ReactNode | null;
tooltip?: ReactNode;
// Fill the Pressable's width and use the standard sidebar-row gap, so the
// trigger reads as a full-width row: the label expands and the chevron pins to
// the trailing edge. Default (false) keeps the content-width pill used by the
@@ -46,7 +48,7 @@ interface ComboboxTriggerProps extends Omit<PressableProps, "style" | "children"
}
export const ComboboxTrigger = forwardRef<View, ComboboxTriggerProps>(function ComboboxTrigger(
{ children, chevron, style, block = false, onFocus, onBlur, ...props },
{ children, chevron, tooltip, style, block = false, onFocus, onBlur, ...props },
ref,
): ReactElement {
const [focused, setFocused] = useState(false);
@@ -76,7 +78,7 @@ export const ComboboxTrigger = forwardRef<View, ComboboxTriggerProps>(function C
const rowStyle = useMemo(() => [styles.row, block && styles.rowBlock], [block]);
return (
const button = (
<Pressable
ref={ref}
collapsable={false}
@@ -96,6 +98,16 @@ export const ComboboxTrigger = forwardRef<View, ComboboxTriggerProps>(function C
</View>
</Pressable>
);
if (!tooltip) return button;
return (
<Tooltip>
<TooltipTrigger asChild>{button}</TooltipTrigger>
<TooltipContent side="top" align="center" offset={8}>
{tooltip}
</TooltipContent>
</Tooltip>
);
});
const styles = StyleSheet.create((theme) => ({
+51 -3
View File
@@ -130,6 +130,8 @@ export interface ComboboxProps {
desktopFixedHeight?: number;
/** Content rendered above the scroll area on desktop (sticky header). */
stickyHeader?: ReactNode;
/** Controls rendered between the search field and the options, such as list tabs. */
toolbar?: ReactNode;
/** Content rendered below the scroll area. */
footer?: ReactNode;
/** When true, selecting an option does not close the picker (multi-select mode). */
@@ -227,6 +229,8 @@ export function SearchInput({
export interface ComboboxItemProps {
label: string;
/** Muted text before the label, such as a pull request number. */
labelPrefix?: string;
description?: string;
kind?: "directory" | "file";
leadingSlot?: ReactNode;
@@ -243,6 +247,7 @@ export interface ComboboxItemProps {
export function ComboboxItem({
label,
labelPrefix,
description,
kind,
leadingSlot,
@@ -284,8 +289,15 @@ export function ComboboxItem({
);
const itemContentStyle = useMemo(
() => [styles.comboboxItemContent, description && styles.comboboxItemContentInline],
[description],
() => [
styles.comboboxItemContent,
(description || labelPrefix) && styles.comboboxItemContentInline,
],
[description, labelPrefix],
);
const labelStyle = useMemo(
() => [styles.comboboxItemLabel, labelPrefix && styles.comboboxItemLabelAfterPrefix],
[labelPrefix],
);
return (
@@ -299,7 +311,12 @@ export function ComboboxItem({
>
{leadingContent}
<View style={itemContentStyle}>
<Text numberOfLines={1} style={styles.comboboxItemLabel}>
{labelPrefix ? (
<Text numberOfLines={1} style={styles.comboboxItemLabelPrefix}>
{labelPrefix}
</Text>
) : null}
<Text numberOfLines={1} style={labelStyle}>
{label}
</Text>
{description ? (
@@ -920,6 +937,7 @@ interface MobileBodyProps {
header: SheetHeader | undefined;
onClose: () => void;
stickyHeader: ReactNode;
toolbar: ReactNode;
footer: ReactNode;
searchable: boolean;
hasChildren: boolean;
@@ -1012,6 +1030,7 @@ function MobileComboboxSheet(props: MobileBodyProps): ReactElement {
resetKey={props.searchResetKey}
/>
) : null}
{props.toolbar ? <View style={styles.toolbar}>{props.toolbar}</View> : null}
</>
)}
{props.hasChildren && !props.mobileChildrenScrollEnabled ? (
@@ -1072,6 +1091,7 @@ interface DesktopBodyProps {
handleDesktopContentLayout: (event: LayoutChangeEvent) => void;
header: SheetHeader | undefined;
stickyHeader: ReactNode;
toolbar: ReactNode;
footer: ReactNode;
searchable: boolean;
searchPlaceholder: string;
@@ -1126,6 +1146,7 @@ function DesktopComboboxChildrenBody(props: {
function DesktopComboboxOptionsBody(props: {
header: SheetHeader | undefined;
stickyHeader: ReactNode;
toolbar: ReactNode;
searchable: boolean;
searchPlaceholder: string;
searchQuery: string;
@@ -1165,6 +1186,7 @@ function DesktopComboboxOptionsBody(props: {
useBottomSheetInput={false}
/>
)}
{props.toolbar ? <View style={styles.toolbar}>{props.toolbar}</View> : null}
{props.effectiveOptionsPosition === "above-search" ? (
<ScrollView
ref={props.desktopOptionsScrollRef}
@@ -1241,6 +1263,7 @@ function DesktopComboboxBody(props: DesktopBodyProps): ReactElement | null {
<DesktopComboboxOptionsBody
header={props.header}
stickyHeader={props.stickyHeader}
toolbar={props.toolbar}
searchable={props.searchable}
searchPlaceholder={props.searchPlaceholder}
searchQuery={props.searchQuery}
@@ -1317,6 +1340,7 @@ export function Combobox({
desktopLockWidth,
desktopFixedHeight,
stickyHeader,
toolbar,
footer,
keepOpenOnSelect = false,
anchorRef,
@@ -1602,6 +1626,7 @@ export function Combobox({
header={header}
onClose={handleClose}
stickyHeader={stickyHeader}
toolbar={toolbar}
footer={footer}
searchable={searchable}
hasChildren={hasChildren}
@@ -1640,6 +1665,7 @@ export function Combobox({
handleDesktopContentLayout={handleDesktopContentLayout}
header={header}
stickyHeader={stickyHeader}
toolbar={toolbar}
footer={footer}
searchable={searchable}
searchPlaceholder={effectiveSearchPlaceholder}
@@ -1683,6 +1709,18 @@ const styles = StyleSheet.create((theme) => ({
borderBottomColor: theme.colors.border,
...(IS_WEB ? {} : { marginHorizontal: theme.spacing[1] }),
},
toolbar: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
gap: theme.spacing[2],
// The search field's inset, so a filled control starts on the rows' leading rail.
paddingHorizontal: theme.spacing[3],
paddingVertical: theme.spacing[2],
borderBottomWidth: 1,
borderBottomColor: theme.colors.border,
...(IS_WEB ? {} : { marginHorizontal: theme.spacing[1] }),
},
searchInput: {
flex: 1,
paddingVertical: theme.spacing[3],
@@ -1752,6 +1790,16 @@ const styles = StyleSheet.create((theme) => ({
color: theme.colors.foreground,
flexShrink: 0,
},
comboboxItemLabelPrefix: {
fontSize: theme.fontSize.base,
color: theme.colors.foregroundMuted,
fontVariant: ["tabular-nums"],
flexShrink: 0,
},
// The prefix holds its width; the label gives way.
comboboxItemLabelAfterPrefix: {
flexShrink: 1,
},
comboboxItemDescription: {
fontSize: theme.fontSize.sm,
color: theme.colors.foregroundMuted,

Some files were not shown because too many files have changed in this diff Show More