Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Add VS Code open support and stabilize chat autoscroll
Julius Marmingeecb4a1efa43a
diff --git a/apps/server/src/open.test.ts b/apps/server/src/open.test.tsindex 2ab65b90e..8adb3e1a6 100644--- a/apps/server/src/open.test.ts+++ b/apps/server/src/open.test.ts@@ -5,20 +5,29 @@ import { Effect } from "effect";import { assertSuccess } from "@effect/vitest/utils";describe("resolveEditorLaunch", () => {- it.effect("returns cursor command for cursor editor", () =>+ it.effect("returns commands for command-based editors", () =>Effect.gen(function* () {- const launch = yield* resolveEditorLaunch(+ const cursorLaunch = yield* resolveEditorLaunch({ cwd: "/tmp/workspace", editor: "cursor" },"darwin",);- assert.deepEqual(launch, {+ assert.deepEqual(cursorLaunch, {command: "cursor",args: ["/tmp/workspace"],});++ const vscodeLaunch = yield* resolveEditorLaunch(+ { cwd: "/tmp/workspace", editor: "vscode" },+ "darwin",+ );+ assert.deepEqual(vscodeLaunch, {+ command: "code",+ args: ["/tmp/workspace"],+ });}),);- it.effect("uses --goto when cursor target includes line/column suffixes", () =>+ it.effect("uses --goto when editor supports line/column suffixes", () =>Effect.gen(function* () {const lineOnly = yield* resolveEditorLaunch({ cwd: "/tmp/workspace/AGENTS.md:48", editor: "cursor" },@@ -37,6 +46,15 @@ describe("resolveEditorLaunch", () => {command: "cursor",args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],});++ const vscodeLineAndColumn = yield* resolveEditorLaunch(+ { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "vscode" },+ "darwin",+ );+ assert.deepEqual(vscodeLineAndColumn, {+ command: "code",+ args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],+ });}),);diff --git a/apps/server/src/open.ts b/apps/server/src/open.tsindex 97c822827..dcd4e736d 100644--- a/apps/server/src/open.ts+++ b/apps/server/src/open.ts@@ -33,7 +33,7 @@ interface EditorLaunch {const LINE_COLUMN_SUFFIX_PATTERN = /:\d+(?::\d+)?$/;function shouldUseGotoFlag(editorId: EditorId, target: string): boolean {- return editorId === "cursor" && LINE_COLUMN_SUFFIX_PATTERN.test(target);+ return (editorId === "cursor" || editorId === "vscode") && LINE_COLUMN_SUFFIX_PATTERN.test(target);}/**diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 8591ca22f..42accea48 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -517,6 +517,10 @@ export default function ChatView({ threadId }: ChatViewProps) {const messagesScrollRef = useRef<HTMLDivElement>(null);const [messagesScrollElement, setMessagesScrollElement] = useState<HTMLDivElement | null>(null);const shouldAutoScrollRef = useRef(true);+ const lastKnownScrollTopRef = useRef(0);+ const isPointerScrollActiveRef = useRef(false);+ const lastTouchClientYRef = useRef<number | null>(null);+ const pendingUserScrollUpIntentRef = useRef(false);const pendingAutoScrollFrameRef = useRef<number | null>(null);const composerEditorRef = useRef<ComposerPromptEditorHandle>(null);const composerCommandInputRef = useRef<HTMLInputElement>(null);@@ -1324,8 +1328,15 @@ export default function ChatView({ threadId }: ChatViewProps) {const scrollContainer = messagesScrollRef.current;if (!scrollContainer) return;scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior });+ lastKnownScrollTopRef.current = scrollContainer.scrollTop;shouldAutoScrollRef.current = true;}, []);+ const cancelPendingStickToBottom = useCallback(() => {+ const pendingFrame = pendingAutoScrollFrameRef.current;+ if (pendingFrame === null) return;+ pendingAutoScrollFrameRef.current = null;+ window.cancelAnimationFrame(pendingFrame);+ }, []);const scheduleStickToBottom = useCallback(() => {if (pendingAutoScrollFrameRef.current !== null) return;pendingAutoScrollFrameRef.current = window.requestAnimationFrame(() => {@@ -1333,19 +1344,77 @@ export default function ChatView({ threadId }: ChatViewProps) {scrollMessagesToBottom();});}, [scrollMessagesToBottom]);+ const forceStickToBottom = useCallback(() => {+ cancelPendingStickToBottom();+ scrollMessagesToBottom();+ scheduleStickToBottom();+ }, [cancelPendingStickToBottom, scheduleStickToBottom, scrollMessagesToBottom]);const onMessagesScroll = useCallback(() => {const scrollContainer = messagesScrollRef.current;if (!scrollContainer) return;- shouldAutoScrollRef.current = isScrollContainerNearBottom(scrollContainer);+ const currentScrollTop = scrollContainer.scrollTop;+ const isNearBottom = isScrollContainerNearBottom(scrollContainer);++ if (!shouldAutoScrollRef.current && isNearBottom) {+ shouldAutoScrollRef.current = true;+ pendingUserScrollUpIntentRef.current = false;+ } else if (shouldAutoScrollRef.current && pendingUserScrollUpIntentRef.current) {+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;+ if (scrolledUp) {+ shouldAutoScrollRef.current = false;+ }+ pendingUserScrollUpIntentRef.current = false;+ } else if (shouldAutoScrollRef.current && isPointerScrollActiveRef.current) {+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;+ if (scrolledUp) {+ shouldAutoScrollRef.current = false;+ }+ } else if (shouldAutoScrollRef.current && !isNearBottom) {+ // Catch-all for keyboard/assistive scroll interactions.+ const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;+ if (scrolledUp) {+ shouldAutoScrollRef.current = false;+ }+ }++ lastKnownScrollTopRef.current = currentScrollTop;+ }, []);+ const onMessagesWheel = useCallback((event: React.WheelEvent<HTMLDivElement>) => {+ if (event.deltaY < 0) {+ pendingUserScrollUpIntentRef.current = true;+ }+ }, []);+ const onMessagesPointerDown = useCallback((_event: React.PointerEvent<HTMLDivElement>) => {+ isPointerScrollActiveRef.current = true;+ }, []);+ const onMessagesPointerUp = useCallback((_event: React.PointerEvent<HTMLDivElement>) => {+ isPointerScrollActiveRef.current = false;+ }, []);+ const onMessagesPointerCancel = useCallback((_event: React.PointerEvent<HTMLDivElement>) => {+ isPointerScrollActiveRef.current = false;+ }, []);+ const onMessagesTouchStart = useCallback((event: React.TouchEvent<HTMLDivElement>) => {+ const touch = event.touches[0];+ if (!touch) return;+ lastTouchClientYRef.current = touch.clientY;+ }, []);+ const onMessagesTouchMove = useCallback((event: React.TouchEvent<HTMLDivElement>) => {+ const touch = event.touches[0];+ if (!touch) return;+ const previousTouchY = lastTouchClientYRef.current;+ if (previousTouchY !== null && touch.clientY > previousTouchY + 1) {+ pendingUserScrollUpIntentRef.current = true;+ }+ lastTouchClientYRef.current = touch.clientY;+ }, []);+ const onMessagesTouchEnd = useCallback((_event: React.TouchEvent<HTMLDivElement>) => {+ lastTouchClientYRef.current = null;}, []);useEffect(() => {return () => {- const frame = pendingAutoScrollFrameRef.current;- if (frame !== null) {- window.cancelAnimationFrame(frame);- }+ cancelPendingStickToBottom();};- }, []);+ }, [cancelPendingStickToBottom]);useLayoutEffect(() => {if (!activeThread?.id) return;shouldAutoScrollRef.current = true;@@ -1922,7 +1991,7 @@ export default function ChatView({ threadId }: ChatViewProps) {]);// Sending a message should always bring the latest user turn into view.shouldAutoScrollRef.current = true;- scheduleStickToBottom();+ forceStickToBottom();setThreadError(threadIdForSend, null);promptRef.current = "";@@ -2442,6 +2511,14 @@ export default function ChatView({ threadId }: ChatViewProps) {ref={setMessagesScrollContainerRef}className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-y-contain px-3 py-3 sm:px-5 sm:py-4"onScroll={onMessagesScroll}+ onWheel={onMessagesWheel}+ onPointerDown={onMessagesPointerDown}+ onPointerUp={onMessagesPointerUp}+ onPointerCancel={onMessagesPointerCancel}+ onTouchStart={onMessagesTouchStart}+ onTouchMove={onMessagesTouchMove}+ onTouchEnd={onMessagesTouchEnd}+ onTouchCancel={onMessagesTouchEnd}><MessagesTimelinekey={activeThread.id}@@ -3602,6 +3679,11 @@ const OpenInPicker = memo(function OpenInPicker({Icon: CursorIcon,value: "cursor",},+ {+ label: "VS Code",+ Icon: FileIcon,+ value: "vscode",+ },{label: isMacPlatform(navigator.platform)? "Finder"diff --git a/packages/contracts/src/editor.ts b/packages/contracts/src/editor.tsindex a53df901b..14f61a896 100644--- a/packages/contracts/src/editor.ts+++ b/packages/contracts/src/editor.ts@@ -3,6 +3,7 @@ import { TrimmedNonEmptyString } from "./baseSchemas";export const EDITORS = [{ id: "cursor", label: "Cursor", command: "cursor" },+ { id: "vscode", label: "VS Code", command: "code" },{ id: "file-manager", label: "File Manager", command: null },] as const;