Skip to content

Commit eee47b5

Browse files
Merge remote-tracking branch 'origin/main' into fix/restored-question-answer-leaves-draft
2 parents 20beef9 + 5cff012 commit eee47b5

29 files changed

Lines changed: 1067 additions & 228 deletions

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,30 @@ describe("ElectronShell", () => {
5454
}).pipe(Effect.provide(ElectronShell.layer)),
5555
);
5656

57-
it.effect("opens only the bare Grok Bot launch link", () =>
57+
it.effect("opens only the Grok Bot prompt link", () =>
5858
Effect.gen(function* () {
5959
openExternalMock.mockResolvedValue(undefined);
6060

61+
const prompt = "grokbot://app/v1/prompt?text=Add%20the%20MCP%20server";
6162
const electronShell = yield* ElectronShell.ElectronShell;
6263
const results = yield* Effect.forEach(
63-
["grokbot://app", "grokbot://app/v1/prompt?id=bot&text=hi", "grokbot://"],
64+
[
65+
prompt,
66+
"grokbot://app",
67+
"grokbot://app/v1/prompt?id=bot&text=hi",
68+
"grokbot://app/v1/prompt?text=a&text=b",
69+
"grokbot://app/v1/other?text=hi",
70+
"grokbot://app/v1/prompt?text=hi#x",
71+
"grokbot://:secret@app/v1/prompt?text=hi",
72+
"grokbot://user@app/v1/prompt?text=hi",
73+
"grokbot://other/v1/prompt?text=hi",
74+
"other://app/v1/prompt?text=hi",
75+
],
6476
(url) => electronShell.openExternal(url),
6577
);
6678

67-
assert.deepEqual(results, [true, false, false]);
68-
assert.deepEqual(openExternalMock.mock.calls, [["grokbot://app"]]);
79+
assert.deepEqual(results, [true, ...Array<boolean>(9).fill(false)]);
80+
assert.deepEqual(openExternalMock.mock.calls, [[prompt]]);
6981
}).pipe(Effect.provide(ElectronShell.layer)),
7082
);
7183

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
2121
}),
2222
);
2323

24-
// "Use T3 Code in another app" opens these apps (apps/web/src/components/mcp/mcpApps.ts). List
24+
// "Use T3 Code in another app" opens these apps (apps/web/src/components/mcp/mcpApps.ts). Match
2525
// each exact link shape the wizard sends, never a whole scheme.
26-
const APP_LAUNCH_URLS = new Set(["grokbot://app"]);
26+
const isAppLaunchUrl = (url: URL) =>
27+
url.protocol === "grokbot:" &&
28+
url.host === "app" &&
29+
url.pathname === "/v1/prompt" &&
30+
url.username.length === 0 &&
31+
url.password.length === 0 &&
32+
url.hash.length === 0 &&
33+
[...url.searchParams.keys()].join() === "text";
2734

2835
// Zed embeds [user@]host in the path; reject passwords and ports there.
2936
const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/;
@@ -50,7 +57,7 @@ export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
5057
try {
5158
const url = new URL(rawUrl);
5259
return SAFE_WEB_PROTOCOLS.has(url.protocol) ||
53-
APP_LAUNCH_URLS.has(url.href) ||
60+
isAppLaunchUrl(url) ||
5461
isRemoteEditorUrl(url) ||
5562
isLocalEditorFileUrl(url)
5663
? Option.some(url.href)

‎apps/mobile/src/lib/markdownDocument.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ function htmlTagMarkdown(
226226
const alt = (attribute(tag, "alt") ?? "").replace(/[\\[\]&]/g, "\\$&");
227227
return `![${alt}](${markdownDestination(src)})`;
228228
}
229+
// A raw newline would end the table row; both parsers decode this reference to one inside the cell.
230+
const cellBreak = "&#10;";
229231
// A blank line inside an open link label would end the paragraph before its "]".
230-
const blockBreak = anchors.open === 0 ? "\n\n" : " ";
232+
const blockBreak = anchors.open > 0 ? " " : options.inTableCell ? cellBreak : "\n\n";
231233
if (/^<summary\b/i.test(tag)) return `${blockBreak}**`;
232234
if (/^<\/summary\s*>/i.test(tag)) return `**${blockBreak}`;
233-
// A raw newline would end the table row; both parsers decode this reference to one inside the cell.
234-
if (/^<br\b/i.test(tag)) return options.inTableCell ? "&#10;" : " \n";
235+
if (/^<br\b/i.test(tag)) return options.inTableCell ? cellBreak : " \n";
235236
if (/^<\/?(?:p|div|details)\b/i.test(tag)) return blockBreak;
236237
return "";
237238
}

‎apps/mobile/src/lib/markdownHtml.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ describe("HTML in native Markdown", () => {
108108
]);
109109
});
110110

111+
it.each([
112+
"one<p>two</p>",
113+
"one<div>two</div>",
114+
"one<summary>two</summary>",
115+
"<p>one</p><p>two</p>",
116+
])("keeps a table row intact when a cell contains block HTML: %s", async (cell) => {
117+
const native = await parseMarkdown(
118+
markdownForNativeRendering(
119+
`| A | B |\n| - | - |\n| ${cell} | x |`,
120+
ENRICHED_INLINE_FILE_LINK_REGEX,
121+
),
122+
);
123+
const text = (node: { content?: string; children?: unknown[] }): string =>
124+
(node.content ?? "") +
125+
(node.children ?? []).map((child) => text(child as typeof node)).join("");
126+
expect(native.children).toHaveLength(1);
127+
expect(native.children?.[0]?.children?.[1]?.children?.[0]?.children?.map(text)).toEqual([
128+
expect.stringMatching(/one\s*two/),
129+
"x",
130+
]);
131+
});
132+
111133
it("keeps a table row intact when an anchor href contains a pipe", () => {
112134
const document = parseMarkdownDocument(
113135
"| Preview | Logs |\n| - | - |\n| <a href='https://example.com/?a=1&#124;2'>Open</a> | done |",

‎apps/server/src/cli/pair.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ describe("t3 pair", () => {
570570
});
571571
const spawner = ChildProcessSpawner.make((command) => {
572572
const { args } = command as unknown as { readonly args: ReadonlyArray<string> };
573-
const serve = args[0] === "serve";
573+
const serve = args[0] === "serve" && args[1] !== "status";
574574
return Effect.succeed(
575575
ChildProcessSpawner.makeHandle({
576576
pid: ChildProcessSpawner.ProcessId(1),
@@ -581,7 +581,11 @@ describe("t3 pair", () => {
581581
stdin: Sink.drain,
582582
stdout: Stream.make(
583583
new TextEncoder().encode(
584-
serve ? "" : '{"Self":{"DNSName":"pair-test.tail.ts.net."}}',
584+
serve
585+
? ""
586+
: args[0] === "serve"
587+
? "{}"
588+
: '{"Self":{"DNSName":"pair-test.tail.ts.net."}}',
585589
),
586590
),
587591
stderr: Stream.make(

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ it.layer(
11571157

11581158
process.emitData("prompt ");
11591159
process.emitData("\u001b[?2026$p\u001b[?2026;2$y\u001b[>q\u001b[?u\u001b[?31u");
1160+
process.emitData("\u001b[=c\u001b[=0c");
11601161
process.emitData("\u001bP$q m\u001b\\\u001bP1$r0m\u001b\\");
11611162
process.emitData("\u001bP+q544e\u001b\\\u001bP1+r544e=1b\u001b\\");
11621163
process.emitData('\u001b[!p\u001b["p\u001b[4 q\u001b[u');

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ function shouldStripCsiSequence(body: string, finalByte: string): boolean {
11061106
if (finalByte === "R" && /^[0-9;?]*$/.test(body)) {
11071107
return true;
11081108
}
1109-
if (finalByte === "c" && /^[>0-9;?]*$/.test(body)) {
1109+
if (finalByte === "c" && /^[>=0-9;?]*$/.test(body)) {
11101110
return true;
11111111
}
11121112
// Strip DECRQM/DECRPM query traffic to prevent echoed replies during replay; $ guards preserve setters.

‎apps/web/src/components/ChatView.logic.browser.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ it("keeps keyboard focus on a sidebar row on window return, but not a clicked ro
2828
expect(shouldRefocusComposerOnWindowFocus(document.activeElement)).toBe(false);
2929
});
3030

31+
it("keeps focus in a region with its own keys on window return", async () => {
32+
const region = document.createElement("div");
33+
region.tabIndex = -1;
34+
region.setAttribute("aria-keyshortcuts", "J K");
35+
region.textContent = "Guide prose";
36+
document.body.append(region);
37+
using _region = { [Symbol.dispose]: () => region.remove() };
38+
39+
await userEvent.click(region);
40+
expect(document.activeElement).toBe(region);
41+
expect(shouldRefocusComposerOnWindowFocus(document.activeElement)).toBe(false);
42+
});
43+
3144
it("refocuses the composer on window return from a clicked area after a bare key press", async () => {
3245
const controller = createWorkspaceFocusController(document);
3346
const root = document.createElement("div");

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,10 +1069,10 @@ export function hasServerAcknowledgedLocalDispatch(input: {
10691069
);
10701070
}
10711071

1072-
// Returning to the window should land the caret in the composer, so the reader can type right
1073-
// away. The exceptions are places where focus is deliberate: another text field, a terminal in
1074-
// the drawer or the right panel, an open dialog, menu, or popup, or a region or sidebar row
1075-
// reached from the keyboard. A plain focused button or a clicked row yields to the composer.
1072+
// Window return puts the caret in the composer unless focus is deliberate: another text field,
1073+
// a terminal, an open dialog, menu, or popup, a region or sidebar row reached from the keyboard,
1074+
// or a region with its own keys (aria-keyshortcuts). A plain focused button or a clicked row
1075+
// yields to the composer.
10761076
export function shouldRefocusComposerOnWindowFocus(
10771077
activeElement:
10781078
| (Pick<Element, "tagName" | "closest" | "getAttribute"> & { isContentEditable?: boolean })
@@ -1092,7 +1092,7 @@ export function shouldRefocusComposerOnWindowFocus(
10921092
}
10931093
return (
10941094
activeElement.closest(
1095-
'[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner]',
1095+
'[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts]',
10961096
) === null
10971097
);
10981098
}

‎apps/web/src/components/chat/composerFocusRedirect.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,26 @@ function isSurfaceLauncherKey(event: KeyboardEvent): boolean {
5959
return key !== null && (launcherKeys?.includes(key) ?? false);
6060
}
6161

62+
function isKeyClaimedInPath(event: KeyboardEvent): boolean {
63+
if (event.shiftKey) return false;
64+
const key = event.key.toUpperCase();
65+
return event
66+
.composedPath()
67+
.some(
68+
(target) =>
69+
target instanceof Element &&
70+
(target.getAttribute("aria-keyshortcuts")?.split(/\s+/).includes(key) ?? false),
71+
);
72+
}
73+
6274
export function shouldRedirectInputToComposer(event: Event): boolean {
6375
if (event.defaultPrevented) return false;
6476
// Never persist or send secret-request typing through the composer.
6577
if (eventPathContainsSelector(event, SECRET_REQUEST_SELECTOR)) return false;
6678
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_EDITABLE_SELECTOR)) return false;
6779
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_INTERACTIVE_SELECTOR)) return false;
6880
if (document.querySelector(TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR)) return false;
81+
if (document.querySelector('[data-chat-column-maximized-away="true"]')) return false;
6982
return true;
7083
}
7184

@@ -75,6 +88,7 @@ export function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
7588
if (event.key.length !== 1) return false;
7689
if (!shouldRedirectInputToComposer(event)) return false;
7790
if (isSurfaceLauncherKey(event)) return false;
91+
if (isKeyClaimedInPath(event)) return false;
7892

7993
return true;
8094
}

0 commit comments

Comments
 (0)