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 open-in-editor feature with Cmd+O shortcut (#2)
Julius Marmingeeef57db95561
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 29bc383a2..4b32d7bdb 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -3,9 +3,10 @@ fixPath();import { spawn } from "node:child_process";import path from "node:path";-import { BrowserWindow, app, dialog, ipcMain, session } from "electron";+import { BrowserWindow, app, dialog, ipcMain, session, shell } from "electron";import {+ EDITORS,IPC_CHANNELS,type TerminalCommandInput,type TerminalCommandResult,@@ -126,6 +127,29 @@ function registerIpcHandlers(): void {}),);+ // Shell handlers+ ipcMain.handle(+ IPC_CHANNELS.shellOpenInEditor,+ async (_event, cwd: string, editor: string) => {+ if (!cwd) throw new Error("cwd is required");+ const editorDef = EDITORS.find((e) => e.id === editor);+ if (!editorDef) throw new Error(`Unknown editor: ${editor}`);+ if (!editorDef.command) {+ const error = await shell.openPath(cwd);+ if (error) throw new Error(error);+ return;+ }+ const child = spawn(editorDef.command, [cwd], {+ detached: true,+ stdio: "ignore",+ });+ child.on("error", () => {+ /* ignore spawn failures for detached editors */+ });+ child.unref();+ },+ );+// Agent handlersipcMain.handle(IPC_CHANNELS.agentSpawn,diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.tsindex 498403942..68b9311f5 100644--- a/apps/desktop/src/preload.ts+++ b/apps/desktop/src/preload.ts@@ -54,6 +54,10 @@ const nativeApi: NativeApi = {ipcRenderer.removeListener(IPC_CHANNELS.providerEvent, listener);},},+ shell: {+ openInEditor: (cwd: string, editor: string) =>+ ipcRenderer.invoke(IPC_CHANNELS.shellOpenInEditor, cwd, editor),+ },};contextBridge.exposeInMainWorld("nativeApi", nativeApi);diff --git a/apps/renderer/src/components/ChatView.tsx b/apps/renderer/src/components/ChatView.tsxindex 96483ea70..d73aa4d6b 100644--- a/apps/renderer/src/components/ChatView.tsx+++ b/apps/renderer/src/components/ChatView.tsx@@ -9,6 +9,7 @@ import {useState,} from "react";+import { EDITORS, type EditorId } from "@acme/contracts";import {DEFAULT_MODEL,DEFAULT_REASONING,@@ -33,6 +34,18 @@ function formatMessageMeta(createdAt: string, duration: string | null): string {return `${formatTimestamp(createdAt)} • ${duration}`;}+const FILE_MANAGER_LABEL = navigator.platform.includes("Mac")+ ? "Finder"+ : navigator.platform.includes("Win")+ ? "Explorer"+ : "Files";++function editorLabel(editor: (typeof EDITORS)[number]): string {+ return editor.command ? editor.label : FILE_MANAGER_LABEL;+}++const LAST_EDITOR_KEY = "codething:last-editor";+function workToneClass(tone: "thinking" | "tool" | "info" | "error"): string {if (tone === "error") return "text-rose-300/50";if (tone === "tool") return "text-[#8a8a8a]";@@ -111,6 +124,13 @@ export default function ChatView() {const [isSending, setIsSending] = useState(false);const [isConnecting, setIsConnecting] = useState(false);const [isModelMenuOpen, setIsModelMenuOpen] = useState(false);+ const [isEditorMenuOpen, setIsEditorMenuOpen] = useState(false);+ const [lastEditor, setLastEditor] = useState<EditorId>(() => {+ const stored = localStorage.getItem(LAST_EDITOR_KEY);+ return EDITORS.some((e) => e.id === stored)+ ? (stored as EditorId)+ : EDITORS[0].id;+ });const [selectedEffort, setSelectedEffort] =useState<string>(DEFAULT_REASONING);const [isSwitchingRuntimeMode, setIsSwitchingRuntimeMode] = useState(false);@@ -121,6 +141,7 @@ export default function ChatView() {const messagesEndRef = useRef<HTMLDivElement>(null);const textareaRef = useRef<HTMLTextAreaElement>(null);const modelMenuRef = useRef<HTMLDivElement>(null);+ const editorMenuRef = useRef<HTMLDivElement>(null);const activeThread = state.threads.find((t) => t.id === state.activeThreadId);const activeProject = state.projects.find(@@ -291,6 +312,47 @@ export default function ChatView() {};}, [isModelMenuOpen]);+ useEffect(() => {+ if (!isEditorMenuOpen) return;++ const handleClickOutside = (event: MouseEvent) => {+ if (!editorMenuRef.current) return;+ if (+ event.target instanceof Node &&+ !editorMenuRef.current.contains(event.target)+ ) {+ setIsEditorMenuOpen(false);+ }+ };++ window.addEventListener("mousedown", handleClickOutside);+ return () => {+ window.removeEventListener("mousedown", handleClickOutside);+ };+ }, [isEditorMenuOpen]);++ // Cmd+O / Ctrl+O to open in last-used editor+ useEffect(() => {+ const handler = (e: globalThis.KeyboardEvent) => {+ if (e.key === "o" && (e.metaKey || e.ctrlKey) && !e.shiftKey) {+ if (api && activeProject) {+ e.preventDefault();+ void api.shell.openInEditor(activeProject.cwd, lastEditor);+ }+ }+ };+ window.addEventListener("keydown", handler);+ return () => window.removeEventListener("keydown", handler);+ }, [api, activeProject, lastEditor]);++ const openInEditor = (editorId: EditorId) => {+ if (!api || !activeProject) return;+ void api.shell.openInEditor(activeProject.cwd, editorId);+ setLastEditor(editorId);+ localStorage.setItem(LAST_EDITOR_KEY, editorId);+ setIsEditorMenuOpen(false);+ };+const ensureSession = async (): Promise<string | null> => {if (!api || !activeThread || !activeProject) return null;if (activeThread.session && activeThread.session.status !== "closed") {@@ -458,6 +520,39 @@ export default function ChatView() {</h2></div><div className="flex items-center gap-3">+ {/* Open in editor */}+ {activeProject && (+ <div className="relative" ref={editorMenuRef}>+ <button+ type="button"+ className="rounded-md px-2 py-1 text-[10px] text-[#a0a0a0]/40 transition-colors duration-150 hover:text-[#a0a0a0]/60"+ onClick={() => setIsEditorMenuOpen((v) => !v)}+ >+ Open in…+ </button>+ {isEditorMenuOpen && (+ <div className="absolute right-0 top-full z-50 mt-1 min-w-[120px] rounded-md border border-white/[0.08] bg-[#1b1b1d] py-1 shadow-xl">+ {EDITORS.map((editor) => (+ <button+ key={editor.id}+ type="button"+ className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-[11px] text-[#e0e0e0] hover:bg-white/[0.06]"+ onClick={() => openInEditor(editor.id)}+ >+ {editorLabel(editor)}+ {editor.id === lastEditor && (+ <kbd className="ml-auto text-[9px] text-[#a0a0a0]/40">+ {navigator.platform.includes("Mac")+ ? "\u2318O"+ : "Ctrl+O"}+ </kbd>+ )}+ </button>+ ))}+ </div>+ )}+ </div>+ )}{/* Diff toggle */}<buttontype="button"diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.tsindex 92f8bd38f..d15ec97d4 100644--- a/packages/contracts/src/ipc.ts+++ b/packages/contracts/src/ipc.ts@@ -12,6 +12,13 @@ import type {import type { TerminalCommandInput, TerminalCommandResult } from "./terminal";import type { NewTodoInput, Todo } from "./todo";+export const EDITORS = [+ { id: "cursor", label: "Cursor", command: "cursor" },+ { id: "file-manager", label: "File Manager", command: null },+] as const;++export type EditorId = (typeof EDITORS)[number]["id"];+export const IPC_CHANNELS = {todosList: "todos:list",todosAdd: "todos:add",@@ -31,6 +38,7 @@ export const IPC_CHANNELS = {providerSessionList: "provider:session:list",providerRequestRespond: "provider:request:respond",providerEvent: "provider:event",+ shellOpenInEditor: "shell:open-in-editor",} as const;export interface NativeApi {@@ -66,4 +74,7 @@ export interface NativeApi {listSessions: () => Promise<ProviderSession[]>;onEvent: (callback: (event: ProviderEvent) => void) => () => void;};+ shell: {+ openInEditor: (cwd: string, editor: EditorId) => Promise<void>;+ };}