mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-30 04:05:43 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4eb9be9be | ||
|
|
b0b7fbcdd5 | ||
|
|
8b7cb47ef2 | ||
|
|
693fa22377 | ||
|
|
22a318b1de | ||
|
|
4f8fed2e2b |
@@ -118,10 +118,14 @@ test("projects and pinned chats reorder while ordinary workspaces stay newest fi
|
||||
await firstProject.client.setWorkspacePinned(firstProject.workspaceId, true);
|
||||
await secondProject.client.setWorkspacePinned(secondProject.workspaceId, true);
|
||||
const secondProjectWorkspaceTestId = `sidebar-workspace-row-${getServerId()}:${secondProject.workspaceId}`;
|
||||
// Both rows also exist in their project groups, so match them only once each pin has
|
||||
// moved its row into the Pinned section.
|
||||
await quickDragFirstRowAfterSecond(
|
||||
page.locator(
|
||||
`[data-testid="${firstWorkspaceTestId}"], [data-testid="${secondProjectWorkspaceTestId}"]`,
|
||||
),
|
||||
page
|
||||
.getByTestId("sidebar-pinned-section")
|
||||
.locator(
|
||||
`[data-testid="${firstWorkspaceTestId}"], [data-testid="${secondProjectWorkspaceTestId}"]`,
|
||||
),
|
||||
pressWorkspaceRow,
|
||||
);
|
||||
} finally {
|
||||
|
||||
@@ -392,6 +392,8 @@ test.describe("Terminal protocol queries", () => {
|
||||
await terminalSurface(page).click();
|
||||
await terminalSurface(page).pressSequentially("Q", { delay: 0 });
|
||||
await expectTerminalOutput(lightTerminalId, "WATCH2031_DONE");
|
||||
// One report per switch: a second responder would deliver each switch twice.
|
||||
expect(watch2031Events(await terminalOutput(lightTerminalId))).toEqual(["1", "2"]);
|
||||
|
||||
await selectAppThemeInApp(page, "Dark");
|
||||
await runPaletteChecks(lightTerminalId, TERMINAL_PALETTE_SCENARIOS.dark, {
|
||||
@@ -428,6 +430,10 @@ test.describe("Terminal protocol queries", () => {
|
||||
return capture.lines.join("").replace(/\s/g, "");
|
||||
}
|
||||
|
||||
function watch2031Events(output: string): string[] {
|
||||
return [...output.matchAll(/WATCH2031_EVENT:([12])/g)].map(([, scheme]) => scheme);
|
||||
}
|
||||
|
||||
async function expectTerminalOutput(terminalId: string, text: string): Promise<void> {
|
||||
await expect.poll(() => terminalOutput(terminalId), { timeout: 10_000 }).toContain(text);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ press "id=\"combined-model-selector\""
|
||||
wait "id=\"model-provider-${PROVIDER_ID}\"" 10000
|
||||
press "id=\"model-provider-${PROVIDER_ID}\""
|
||||
wait "id=\"model-row-${PROVIDER_ID}-${MODEL_ID}\"" 3000
|
||||
# Back takes the header's step to the provider list first, then dismisses the modal.
|
||||
back
|
||||
wait "id=\"model-provider-${PROVIDER_ID}\"" 3000
|
||||
back
|
||||
wait "id=\"combined-model-selector\" label=\"Select model (${MODEL_LABEL})\"" 3000
|
||||
close
|
||||
|
||||
@@ -10,13 +10,13 @@ wait "id=\"agent-controls-model\"" 10000
|
||||
gesture pan 540 790 0 960 500
|
||||
wait "id=\"combined-model-selector\"" 3000
|
||||
|
||||
# Reopen, dismiss the nested model browser, then dismiss its restored parent.
|
||||
# Android Back steps from Model back to Agent settings, then closes the sheet.
|
||||
press "id=\"combined-model-selector\""
|
||||
wait "id=\"agent-controls-model\"" 10000
|
||||
press "id=\"agent-controls-model\""
|
||||
wait stable 300 5000
|
||||
gesture pan 540 790 0 960 500
|
||||
wait "id=\"model-search-all-input\"" 10000
|
||||
back
|
||||
wait "id=\"agent-controls-model\"" 3000
|
||||
gesture pan 540 790 0 960 500
|
||||
back
|
||||
wait "id=\"combined-model-selector\"" 3000
|
||||
close
|
||||
|
||||
+93
-13
@@ -1,11 +1,13 @@
|
||||
package sh.paseo.terminal
|
||||
|
||||
import android.os.Build
|
||||
import android.text.InputType
|
||||
import android.view.KeyCharacterMap
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.SdkSuppress
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
@@ -77,6 +79,15 @@ class TerminalInputConnectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** Gboard commits each letter in its own batch edit when the editor disables suggestions. */
|
||||
private fun TerminalInputConnection.typeLikeGboard(text: String) {
|
||||
for (ch in text) {
|
||||
beginBatchEdit()
|
||||
commitText(ch.toString(), 1)
|
||||
endBatchEdit()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun editorInfoDisablesSuggestionsFullscreenAndPersonalizedLearning() {
|
||||
instrumentation.runOnMainSync {
|
||||
@@ -100,13 +111,8 @@ class TerminalInputConnectionTest {
|
||||
@Test
|
||||
fun batchedCommitTextAndSetComposingTextDoNotDoubleCharacters() {
|
||||
withInputHarness { _, ic, _, terminal ->
|
||||
for (ch in listOf("a", "b", "c", "d")) {
|
||||
ic.beginBatchEdit()
|
||||
ic.commitText(ch, 1)
|
||||
ic.endBatchEdit()
|
||||
}
|
||||
ic.typeLikeGboard("abcd")
|
||||
assertEquals("abcd", terminal.rawStream)
|
||||
assertEquals("", ic.editable.toString())
|
||||
|
||||
// Coalesced setComposingText + finishComposingText inside one batch emits once.
|
||||
ic.beginBatchEdit()
|
||||
@@ -114,28 +120,96 @@ class TerminalInputConnectionTest {
|
||||
ic.finishComposingText()
|
||||
ic.endBatchEdit()
|
||||
assertEquals("abcdef", terminal.rawStream)
|
||||
assertEquals("", ic.editable.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun editorKeepsTheTypedLineUntilTerminalKeyBoundary() {
|
||||
withInputHarness { _, ic, _, terminal ->
|
||||
// IMEs address edits by offsets into the text they committed, so the editor must keep it.
|
||||
ic.typeLikeGboard("ab")
|
||||
assertEquals("ab", ic.getTextBeforeCursor(10, 0).toString())
|
||||
|
||||
// Enter leaves the shell line, so the editor starts the next line empty.
|
||||
ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER))
|
||||
ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER))
|
||||
assertEquals("", ic.getTextBeforeCursor(10, 0).toString())
|
||||
|
||||
ic.typeLikeGboard("helo")
|
||||
ic.beginBatchEdit()
|
||||
ic.setComposingRegion(0, 4)
|
||||
ic.commitText("hello ", 1)
|
||||
ic.endBatchEdit()
|
||||
assertEquals("ab\rhello ", terminal.applyToLine())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun gboardArrowKeyStartsTheEditorOnAnEmptyLine() {
|
||||
withInputHarness { _, ic, _, terminal ->
|
||||
ic.typeLikeGboard("echo helo")
|
||||
// Gboard's editing panel sends arrows as key events. The shell cursor moves, so the
|
||||
// editor's copy of the line no longer matches where the next edit lands.
|
||||
ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))
|
||||
ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT))
|
||||
assertEquals("", ic.getTextBeforeCursor(10, 0).toString())
|
||||
assertEquals(listOf("ArrowLeft"), terminal.keys.map { it.key })
|
||||
assertEquals("echo helo", terminal.rawStream)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun suggestionPickedThroughComposingRegionReplacesCommittedWord() {
|
||||
withInputHarness { _, ic, _, terminal ->
|
||||
// Gboard before Android 14 selects the committed word, then commits the suggestion.
|
||||
ic.typeLikeGboard("helo")
|
||||
ic.beginBatchEdit()
|
||||
ic.setComposingRegion(3, 4)
|
||||
ic.commitText("lo ", 1)
|
||||
ic.endBatchEdit()
|
||||
assertEquals("hello ", terminal.applyToLine())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
fun gboardReplaceTextRewritesCommittedText() {
|
||||
// Gboard on Android 14+ picks suggestions and applies double-space period with replaceText,
|
||||
// addressing text it committed earlier. Offsets and texts below are the calls Gboard made live.
|
||||
fun assertReplacement(typed: String, start: Int, end: Int, replacement: String, line: String) {
|
||||
withInputHarness { _, ic, _, terminal ->
|
||||
ic.typeLikeGboard(typed)
|
||||
ic.beginBatchEdit()
|
||||
ic.replaceText(start, end, replacement, 1, null)
|
||||
ic.endBatchEdit()
|
||||
assertEquals("$typed -> $replacement", line, terminal.applyToLine())
|
||||
}
|
||||
}
|
||||
|
||||
assertReplacement("helo", 3, 4, "lo ", line = "hello ")
|
||||
assertReplacement("helo", 3, 4, "p ", line = "help ")
|
||||
assertReplacement("echo hello", 5, 10, "jello ", line = "echo jello ")
|
||||
assertReplacement("ab ", 2, 3, ". ", line = "ab. ")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun backspaceWorksAcrossAllThreeImePaths() {
|
||||
withInputHarness { _, ic, _, terminal ->
|
||||
ic.commitText("abcd", 1)
|
||||
assertEquals("abcd", terminal.applyToLine())
|
||||
|
||||
// Path 1: deleteSurroundingText (empty editable after commit)
|
||||
// Path 1: deleteSurroundingText
|
||||
ic.deleteSurroundingText(0, 0)
|
||||
assertEquals("abcd", terminal.applyToLine())
|
||||
ic.deleteSurroundingText(1, 0)
|
||||
assertEquals("abc", terminal.applyToLine())
|
||||
|
||||
// Path 2: deleteSurroundingTextInCodePoints (empty editable)
|
||||
// Path 2: deleteSurroundingTextInCodePoints
|
||||
ic.deleteSurroundingTextInCodePoints(1, 0)
|
||||
assertEquals("ab", terminal.applyToLine())
|
||||
|
||||
// Path 2b: deleteSurroundingTextInCodePoints on surrogate-pair emoji in composing buffer
|
||||
ic.setComposingText("😀", 1)
|
||||
// Path 2b: deleteSurroundingTextInCodePoints removes a surrogate-pair emoji as one code point
|
||||
ic.commitText("😀", 1)
|
||||
assertEquals("ab😀", terminal.applyToLine())
|
||||
ic.deleteSurroundingTextInCodePoints(1, 0)
|
||||
assertEquals("ab", terminal.applyToLine())
|
||||
@@ -145,10 +219,16 @@ class TerminalInputConnectionTest {
|
||||
ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL))
|
||||
assertEquals("a", terminal.applyToLine())
|
||||
|
||||
// Multi-char deleteSurroundingText on empty buffer
|
||||
// Multi-char deleteSurroundingText
|
||||
ic.commitText("xyz", 1)
|
||||
ic.deleteSurroundingText(2, 0)
|
||||
assertEquals("ax", terminal.applyToLine())
|
||||
|
||||
// After Enter the editor is empty, so Backspace still reaches text the shell already holds
|
||||
ic.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER))
|
||||
ic.deleteSurroundingText(1, 0)
|
||||
ic.deleteSurroundingTextInCodePoints(1, 0)
|
||||
assertEquals("\r\u007f\u007f", terminal.rawStream.takeLast(3))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +322,7 @@ class TerminalInputConnectionTest {
|
||||
ic.commitText("the", 1)
|
||||
assertEquals("hellothe", terminal.applyToLine())
|
||||
|
||||
// Repeated clipboard paste of identical text works because editable clears after commit
|
||||
// Repeated clipboard paste of identical text appends both copies
|
||||
ic.commitText("echo ok", 1)
|
||||
ic.commitText("echo ok", 1)
|
||||
assertEquals("hellotheecho okecho ok", terminal.applyToLine())
|
||||
|
||||
+33
-48
@@ -22,9 +22,16 @@ internal data class TerminalKeyPayload(
|
||||
/**
|
||||
* Single authoritative IME + key stream for the Android native terminal.
|
||||
*
|
||||
* Keeps a private [SpannableStringBuilder] so Android IMEs can compose Hangul, Pinyin, and Latin
|
||||
* candidates normally, diffs the editable against what was last sent to the PTY once each batch
|
||||
* edit settles, and clears the editable as soon as no composing span remains.
|
||||
* The private [SpannableStringBuilder] holds the text the IME has typed on the current shell line,
|
||||
* committed and composing alike. IMEs keep their own copy of that text and edit it by offset:
|
||||
* Gboard picks a suggestion or applies double-space period by replacing text it committed
|
||||
* earlier. Once each batch edit settles, the editable is diffed against what the terminal already
|
||||
* holds and only the difference is sent, as rubouts plus the new suffix.
|
||||
*
|
||||
* A terminal key (Enter, Tab, Escape, arrows, control and hardware characters) changes the shell
|
||||
* line outside the IME, so it empties the editable and restarts the IME on the empty line.
|
||||
* Keys sent to the terminal without passing through this connection do not empty it: the
|
||||
* accessory bar, and the hardware arrows that `PaseoHardwareKeyboardModule` claims at window level.
|
||||
*/
|
||||
internal class TerminalInputConnection(
|
||||
private val targetView: View,
|
||||
@@ -196,6 +203,7 @@ internal class TerminalInputConnection(
|
||||
KeyEvent.KEYCODE_DPAD_LEFT,
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
||||
deadAccent = 0
|
||||
flushAndClear()
|
||||
val name = when (keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_UP -> "ArrowUp"
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> "ArrowDown"
|
||||
@@ -342,57 +350,38 @@ internal class TerminalInputConnection(
|
||||
if (diff.isNotEmpty()) {
|
||||
out.append(normalizeLineEndings(diff))
|
||||
}
|
||||
lastSentText = currentText
|
||||
|
||||
val compStart = getComposingSpanStart(sharedEditable)
|
||||
val compEnd = getComposingSpanEnd(sharedEditable)
|
||||
val isComposing = compStart >= 0 && compEnd > compStart
|
||||
|
||||
if (!isComposing) {
|
||||
val hadText = sharedEditable.isNotEmpty()
|
||||
if (hadText || compStart >= 0) {
|
||||
clearEditableSilently()
|
||||
}
|
||||
lastSentText = ""
|
||||
if (hadText) {
|
||||
// The IME just advanced its cursor for the committed text; report the reset to 0, 0.
|
||||
forceUpdateSelection(0, 0, -1, -1)
|
||||
} else {
|
||||
notifySelectionIfChanged(0, 0, -1, -1)
|
||||
}
|
||||
} else {
|
||||
lastSentText = currentText
|
||||
val selStart = maxOf(0, Selection.getSelectionStart(sharedEditable))
|
||||
val selEnd = maxOf(0, Selection.getSelectionEnd(sharedEditable))
|
||||
notifySelectionIfChanged(selStart, selEnd, compStart, compEnd)
|
||||
var compStart = getComposingSpanStart(sharedEditable)
|
||||
var compEnd = getComposingSpanEnd(sharedEditable)
|
||||
if (compStart >= 0 && compEnd <= compStart) {
|
||||
// An empty composing span would make hardware arrows look like IME navigation.
|
||||
removeComposingSpans(sharedEditable)
|
||||
compStart = -1
|
||||
compEnd = -1
|
||||
}
|
||||
notifySelectionIfChanged(
|
||||
maxOf(0, Selection.getSelectionStart(sharedEditable)),
|
||||
maxOf(0, Selection.getSelectionEnd(sharedEditable)),
|
||||
compStart,
|
||||
compEnd,
|
||||
)
|
||||
|
||||
if (out.isNotEmpty()) {
|
||||
onInput(out.toString())
|
||||
}
|
||||
}
|
||||
|
||||
/** Sends pending IME text, then starts the IME on an empty line before a terminal key. */
|
||||
private fun flushAndClear() {
|
||||
batchEditDepth = 0
|
||||
val hadText = sharedEditable.isNotEmpty()
|
||||
val out = StringBuilder()
|
||||
if (pendingBackspaces > 0) {
|
||||
repeat(pendingBackspaces) { out.append('\u007f') }
|
||||
pendingBackspaces = 0
|
||||
}
|
||||
val currentText = sharedEditable.toString()
|
||||
val diff = computeDiff(lastSentText, currentText)
|
||||
if (diff.isNotEmpty()) {
|
||||
out.append(normalizeLineEndings(diff))
|
||||
}
|
||||
if (hadText || getComposingSpanStart(sharedEditable) >= 0) {
|
||||
clearEditableSilently()
|
||||
}
|
||||
lastSentText = ""
|
||||
if (hadText || lastSelStart != 0 || lastSelEnd != 0 || lastCompStart != -1 || lastCompEnd != -1) {
|
||||
forceUpdateSelection(0, 0, -1, -1)
|
||||
}
|
||||
if (out.isNotEmpty()) {
|
||||
onInput(out.toString())
|
||||
flush()
|
||||
if (sharedEditable.isEmpty()) return
|
||||
resetState()
|
||||
// The IME still holds the old line; updateSelection alone does not make Gboard reload it.
|
||||
val imm = targetView.context.getSystemService(InputMethodManager::class.java) ?: return
|
||||
if (imm.isActive(targetView)) {
|
||||
imm.restartInput(targetView)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,10 +400,6 @@ internal class TerminalInputConnection(
|
||||
) {
|
||||
return
|
||||
}
|
||||
forceUpdateSelection(selStart, selEnd, compStart, compEnd)
|
||||
}
|
||||
|
||||
private fun forceUpdateSelection(selStart: Int, selEnd: Int, compStart: Int, compEnd: Int) {
|
||||
lastSelStart = selStart
|
||||
lastSelEnd = selEnd
|
||||
lastCompStart = compStart
|
||||
|
||||
@@ -7,7 +7,7 @@ import { act } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { RetainedPanelActivity } from "@/components/retained-panel";
|
||||
import { reduceStreamUpdate, type StreamItem } from "@/types/stream";
|
||||
import { hydrateStreamState, reduceStreamUpdate, type StreamItem } from "@/types/stream";
|
||||
import type { StreamRenderInput, StreamSegmentRenderers, StreamViewportHandle } from "./strategy";
|
||||
import { createWebStreamStrategy } from "./strategy-web";
|
||||
|
||||
@@ -1660,4 +1660,86 @@ describe("createWebStreamStrategy", () => {
|
||||
expect(container.querySelector('[data-testid="agent-chat-scroll"]')).toBe(scrollContainer);
|
||||
expect(scrollTo).toHaveBeenCalledWith({ top: 2200, behavior: "auto" });
|
||||
});
|
||||
|
||||
it("renders batched user messages sharing a provider messageId without duplicate React keys", () => {
|
||||
const sharedProviderMessageId = "9ffc3d6e-f0ff-4005-8675-e76e9c5eb5a8";
|
||||
const historyMounted = hydrateStreamState(
|
||||
[
|
||||
{
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "first queued prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-queued-1",
|
||||
},
|
||||
},
|
||||
timestamp: new Date("2026-11-29T13:00:00.000Z"),
|
||||
timelineCursor: { epoch: "epoch-1", seq: 1 },
|
||||
},
|
||||
{
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "second direct prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-direct-2",
|
||||
},
|
||||
},
|
||||
timestamp: new Date("2026-11-29T13:00:01.000Z"),
|
||||
timelineCursor: { epoch: "epoch-1", seq: 2 },
|
||||
},
|
||||
],
|
||||
{ source: "canonical" },
|
||||
);
|
||||
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const renderers = createRenderers(() => {});
|
||||
const strategy = createWebStreamStrategy({ isMobileBreakpoint: false });
|
||||
container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
|
||||
const rendered = strategy.render({
|
||||
agentId: "agent",
|
||||
segments: { historyVirtualized: [], historyMounted, liveHead: [] },
|
||||
boundary: {
|
||||
hasVirtualizedHistory: false,
|
||||
hasMountedHistory: true,
|
||||
hasLiveHead: false,
|
||||
},
|
||||
renderers,
|
||||
listEmptyComponent: null,
|
||||
viewportRef: React.createRef<StreamViewportHandle>(),
|
||||
routeBottomAnchorRequest: null,
|
||||
isAuthoritativeHistoryReady: true,
|
||||
onNearBottomChange: () => {},
|
||||
onNearHistoryStart: async () => true,
|
||||
isLoadingOlderHistory: false,
|
||||
hasOlderHistory: false,
|
||||
olderHistoryProgressKey: null,
|
||||
scrollEnabled: true,
|
||||
listStyle: null,
|
||||
baseListContentContainerStyle: null,
|
||||
forwardListContentContainerStyle: null,
|
||||
contentMaxWidth: DEFAULT_CONTENT_MAX_WIDTH,
|
||||
});
|
||||
act(() => {
|
||||
root?.render(rendered);
|
||||
});
|
||||
|
||||
const isSameKeyMessage = (arg: unknown) => typeof arg === "string" && arg.includes("same key");
|
||||
const duplicateKeyErrors = consoleError.mock.calls.filter((args) =>
|
||||
args.some(isSameKeyMessage),
|
||||
);
|
||||
expect(duplicateKeyErrors).toEqual([]);
|
||||
expect(
|
||||
Array.from(container.querySelectorAll("[data-history-row-id]")).map((node) =>
|
||||
node.getAttribute("data-history-row-id"),
|
||||
),
|
||||
).toEqual(["client-queued-1", "client-direct-2"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,6 +60,10 @@ export interface SheetHeaderSearch {
|
||||
testID?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* One step back inside the sheet, such as from a page to the one before it. Android Back takes
|
||||
* this step too, and closes the sheet only when the header has no back.
|
||||
*/
|
||||
export interface SheetHeaderBack {
|
||||
onPress: () => void;
|
||||
label?: string;
|
||||
@@ -738,10 +742,17 @@ export function AdaptiveModalSheet({
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
const headerBack = header?.back?.onPress;
|
||||
const handleBack = useCallback(() => {
|
||||
if (!headerBack) return false;
|
||||
headerBack();
|
||||
return true;
|
||||
}, [headerBack]);
|
||||
const { sheetRef, handleSheetChange, handleSheetDismiss } = useIsolatedBottomSheetVisibility({
|
||||
visible,
|
||||
isEnabled: isSheet,
|
||||
onClose,
|
||||
onBack: handleBack,
|
||||
});
|
||||
const [shouldRenderWeb, setShouldRenderWeb] = useState(visible);
|
||||
const [isWebClosing, setIsWebClosing] = useState(false);
|
||||
|
||||
@@ -1385,6 +1385,52 @@ it("retains semantic agent messages across disk-cache reconstruction", async ()
|
||||
expect(await createCache(storage).readTimeline(SERVER_ID, "agent-1")).toEqual(value);
|
||||
});
|
||||
|
||||
it("heals cached user_message rows whose stored id collided on a shared provider messageId", async () => {
|
||||
const storage = new MemoryStorage();
|
||||
const writer = createCache(storage);
|
||||
const sharedProviderMessageId = "9ffc3d6e-f0ff-4005-8675-e76e9c5eb5a8";
|
||||
const value = timeline();
|
||||
value.items = [
|
||||
{
|
||||
kind: "user_message",
|
||||
id: sharedProviderMessageId,
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-queued-1",
|
||||
text: "first queued prompt",
|
||||
timestamp: new Date(1),
|
||||
timelineCursor: { epoch: "epoch-1", seq: 1 },
|
||||
},
|
||||
{
|
||||
kind: "user_message",
|
||||
id: sharedProviderMessageId,
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-direct-2",
|
||||
text: "second direct prompt",
|
||||
timestamp: new Date(2),
|
||||
timelineCursor: { epoch: "epoch-1", seq: 2 },
|
||||
},
|
||||
];
|
||||
writer.commitTimeline(SERVER_ID, "agent-1", value);
|
||||
await writer.flush();
|
||||
|
||||
const restored = await createCache(storage).readTimeline(SERVER_ID, "agent-1");
|
||||
expect(restored?.items.map((item) => item.id)).toEqual(["client-queued-1", "client-direct-2"]);
|
||||
expect(restored?.items).toMatchObject([
|
||||
{
|
||||
kind: "user_message",
|
||||
id: "client-queued-1",
|
||||
clientMessageId: "client-queued-1",
|
||||
messageId: sharedProviderMessageId,
|
||||
},
|
||||
{
|
||||
kind: "user_message",
|
||||
id: "client-direct-2",
|
||||
clientMessageId: "client-direct-2",
|
||||
messageId: sharedProviderMessageId,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("retains workspace metadata across replica-cache reload and invalidates pre-metadata rows", async () => {
|
||||
const storage = new MemoryStorage();
|
||||
const writer = createCache(storage);
|
||||
|
||||
@@ -562,6 +562,14 @@ function deserializeTimelineItem(item: StoredTimelineItem): StreamItem {
|
||||
return deserializeBuiltinTimelineItem(item);
|
||||
}
|
||||
|
||||
// COMPAT(userMessageRowId): added in v0.18.2, remove after 2027-06-01.
|
||||
// Earlier builds stored batched user rows under the shared provider messageId instead of clientMessageId.
|
||||
function storedUserMessageRowId(
|
||||
item: Extract<StoredTimelineItem, { kind: "user_message" }>,
|
||||
): string {
|
||||
return item.clientMessageId && item.id === item.messageId ? item.clientMessageId : item.id;
|
||||
}
|
||||
|
||||
function deserializeBuiltinTimelineItem(
|
||||
item: Exclude<StoredTimelineItem, { kind: "plugin" }>,
|
||||
): StreamItem {
|
||||
@@ -575,6 +583,7 @@ function deserializeBuiltinTimelineItem(
|
||||
case "user_message":
|
||||
return {
|
||||
...base,
|
||||
id: storedUserMessageRowId(item),
|
||||
kind: item.kind,
|
||||
...(item.clientMessageId ? { clientMessageId: item.clientMessageId } : {}),
|
||||
...(item.messageId ? { messageId: item.messageId } : {}),
|
||||
|
||||
@@ -762,6 +762,29 @@ describe("terminal emulator runtime in a real browser", () => {
|
||||
expect(mounted.inputs).toEqual([]);
|
||||
});
|
||||
|
||||
// The daemon owns DEC 2031: it sends one ESC[?997;Nn per palette switch. A browser
|
||||
// report on top of that delivers the switch twice.
|
||||
it("does not emit a PTY input report when the theme changes under DEC 2031", async () => {
|
||||
await page.viewport(900, 600);
|
||||
const mounted = createTerminalHost({ width: 720, height: 360 });
|
||||
|
||||
await waitFor({ predicate: () => mounted.sizes.length > 0 });
|
||||
|
||||
const writeCommitted = (bytes: string) =>
|
||||
new Promise<void>((resolve) =>
|
||||
mounted.runtime.write({ data: terminalOutput(bytes), onCommitted: resolve }),
|
||||
);
|
||||
|
||||
mounted.runtime.setTheme({ theme: { background: "#ffffff", foreground: "#1a1a1e" } });
|
||||
await writeCommitted("\x1b[?2031h");
|
||||
mounted.runtime.setTheme({ theme: { background: "#181b1a", foreground: "#fafafa" } });
|
||||
mounted.runtime.setTheme({ theme: { background: "#ffffff", foreground: "#1a1a1e" } });
|
||||
await writeCommitted("\x1b]11;#000000\x07");
|
||||
await nextFrame();
|
||||
|
||||
expect(mounted.inputs).toEqual([]);
|
||||
});
|
||||
|
||||
it("replays snapshots without synchronously resetting the visible terminal", async () => {
|
||||
await page.viewport(900, 600);
|
||||
const mounted = createTerminalHost({ width: 720, height: 360 });
|
||||
|
||||
@@ -577,6 +577,10 @@ export class TerminalEmulatorRuntime {
|
||||
},
|
||||
scrollback: input.scrollback,
|
||||
theme: withOverviewRulerBorderHidden(input.theme),
|
||||
// The daemon owns DEC 2031 and DSR 996: it tracks the mode and reports each
|
||||
// palette switch once. xterm would otherwise send its own unsolicited
|
||||
// ESC[?997;Nn on every theme change, which no query suppression can catch.
|
||||
vtExtensions: { colorSchemeQuery: false },
|
||||
});
|
||||
const fitAddon = new FitAddon();
|
||||
let webglAddon: WebglAddon | null = null;
|
||||
|
||||
@@ -2495,7 +2495,63 @@ describe("processTimelineResponse", () => {
|
||||
.map((item) => ({ id: item.id, messageId: item.messageId })),
|
||||
).toEqual([
|
||||
{ id: "local-prompt", messageId: undefined },
|
||||
{ id: "remote-prompt", messageId: "remote-prompt" },
|
||||
{ id: "remote-client-prompt", messageId: "remote-prompt" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("assigns unique row ids when batched user messages share a provider messageId", () => {
|
||||
const sharedProviderMessageId = "9ffc3d6e-f0ff-4005-8675-e76e9c5eb5a8";
|
||||
const result = processTimelineResponse({
|
||||
...baseTimelineInput,
|
||||
isInitializing: true,
|
||||
hasActiveInitDeferred: true,
|
||||
initRequestDirection: "tail",
|
||||
payload: {
|
||||
...baseTimelineInput.payload,
|
||||
direction: "tail",
|
||||
epoch: "epoch-1",
|
||||
startCursor: { seq: 1 },
|
||||
endCursor: { seq: 2 },
|
||||
entries: [
|
||||
{
|
||||
...makeTimelineEntry(1, "first queued prompt", "user_message"),
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "first queued prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-queued-1",
|
||||
},
|
||||
},
|
||||
{
|
||||
...makeTimelineEntry(2, "second direct prompt", "user_message"),
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "second direct prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-direct-2",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
result.tail.map((item) =>
|
||||
item.kind === "user_message"
|
||||
? { id: item.id, clientMessageId: item.clientMessageId, messageId: item.messageId }
|
||||
: null,
|
||||
),
|
||||
).toEqual([
|
||||
{
|
||||
id: "client-queued-1",
|
||||
clientMessageId: "client-queued-1",
|
||||
messageId: sharedProviderMessageId,
|
||||
},
|
||||
{
|
||||
id: "client-direct-2",
|
||||
clientMessageId: "client-direct-2",
|
||||
messageId: sharedProviderMessageId,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -329,6 +329,104 @@ describe("user message identity", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("assigns distinct row ids to batched user messages that share a provider messageId", () => {
|
||||
const sharedProviderMessageId = "9ffc3d6e-f0ff-4005-8675-e76e9c5eb5a8";
|
||||
const firstTimestamp = new Date("2026-11-29T13:00:00.000Z");
|
||||
const secondTimestamp = new Date("2026-11-29T13:00:01.000Z");
|
||||
|
||||
const hydrated = hydrateStreamState(
|
||||
[
|
||||
{
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "first queued prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-queued-1",
|
||||
},
|
||||
},
|
||||
timestamp: firstTimestamp,
|
||||
timelineCursor: { epoch: "epoch-1", seq: 1 },
|
||||
},
|
||||
{
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "second direct prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-direct-2",
|
||||
},
|
||||
},
|
||||
timestamp: secondTimestamp,
|
||||
timelineCursor: { epoch: "epoch-1", seq: 2 },
|
||||
},
|
||||
],
|
||||
{ source: "canonical" },
|
||||
);
|
||||
|
||||
expect(hydrated).toHaveLength(2);
|
||||
expect(hydrated.map((item) => item.id)).toEqual(["client-queued-1", "client-direct-2"]);
|
||||
expect(hydrated).toMatchObject([
|
||||
{
|
||||
kind: "user_message",
|
||||
id: "client-queued-1",
|
||||
clientMessageId: "client-queued-1",
|
||||
messageId: sharedProviderMessageId,
|
||||
text: "first queued prompt",
|
||||
},
|
||||
{
|
||||
kind: "user_message",
|
||||
id: "client-direct-2",
|
||||
clientMessageId: "client-direct-2",
|
||||
messageId: sharedProviderMessageId,
|
||||
text: "second direct prompt",
|
||||
},
|
||||
]);
|
||||
|
||||
const afterFirstLive = applyStreamEvent({
|
||||
tail: [],
|
||||
head: [],
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "first queued prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-queued-1",
|
||||
},
|
||||
},
|
||||
timestamp: firstTimestamp,
|
||||
timelineCursor: { epoch: "epoch-1", seq: 1 },
|
||||
});
|
||||
const afterSecondLive = applyStreamEvent({
|
||||
tail: afterFirstLive.tail,
|
||||
head: afterFirstLive.head,
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "second direct prompt",
|
||||
messageId: sharedProviderMessageId,
|
||||
clientMessageId: "client-direct-2",
|
||||
},
|
||||
},
|
||||
timestamp: secondTimestamp,
|
||||
timelineCursor: { epoch: "epoch-1", seq: 2 },
|
||||
});
|
||||
|
||||
expect(afterSecondLive.tail).toHaveLength(2);
|
||||
expect(afterSecondLive.tail.map((item) => item.id)).toEqual([
|
||||
"client-queued-1",
|
||||
"client-direct-2",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
function assistantTimeline(
|
||||
|
||||
@@ -969,7 +969,7 @@ function appendUserMessage(
|
||||
|
||||
const chunkSeed = chunk.trim() || chunk || images?.[0]?.id || "image";
|
||||
const nextItem = createUserMessage({
|
||||
id: messageId ?? createUniqueTimelineId(state, "user", chunkSeed, timestamp),
|
||||
id: clientMessageId || messageId || createUniqueTimelineId(state, "user", chunkSeed, timestamp),
|
||||
clientMessageId,
|
||||
messageId,
|
||||
timelineCursor,
|
||||
@@ -1967,7 +1967,9 @@ function buildCanonicalUserMessage(params: {
|
||||
const fallbackKey = normalized.chunk.trim() || images?.[0]?.id || "image";
|
||||
const canonical = createUserMessage({
|
||||
id:
|
||||
item.messageId ?? createUniqueTimelineId([...tail, ...head], "user", fallbackKey, timestamp),
|
||||
item.clientMessageId ||
|
||||
item.messageId ||
|
||||
createUniqueTimelineId([...tail, ...head], "user", fallbackKey, timestamp),
|
||||
messageId: item.messageId,
|
||||
clientMessageId: item.clientMessageId,
|
||||
turnId,
|
||||
|
||||
Reference in New Issue
Block a user