Skip to content

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.

Merge origin/main into codex/add-github-commit-push-ui

Julius Marminge1768d3166965
diff --cc apps/server/src/wsServer.test.ts
index 8b3a19876,770d1ccdb..379d6b4fd
--- a/apps/server/src/wsServer.test.ts
+++ b/apps/server/src/wsServer.test.ts
@@@ -286,70 -281,32 +286,96 @@@ describe("WebSocket Server", () =>
expect(afterRemove.result).toEqual([]);
});
+ it("supports git methods over websocket", async () => {
+ const repoCwd = makeTempDir("t3code-ws-git-project-");
+
+ server = createTestServer({ cwd: "/test" });
+ await server.start();
+ const addr = server.httpServer.address();
+ const port = typeof addr === "object" && addr !== null ? addr.port : 0;
+
+ const ws = await connectWs(port);
+ connections.push(ws);
+ await waitForMessage(ws);
+
+ const beforeInit = await sendRequest(ws, WS_METHODS.gitListBranches, { cwd: repoCwd });
+ expect(beforeInit.error).toBeUndefined();
+ expect(beforeInit.result).toEqual({ branches: [], isRepo: false });
+
+ const initResponse = await sendRequest(ws, WS_METHODS.gitInit, { cwd: repoCwd });
+ expect(initResponse.error).toBeUndefined();
+
+ const afterInit = await sendRequest(ws, WS_METHODS.gitListBranches, {
+ cwd: repoCwd,
+ });
+ expect(afterInit.error).toBeUndefined();
+ expect((afterInit.result as { isRepo: boolean }).isRepo).toBe(true);
+ });
+
+ it("responds to git.status via the git manager", async () => {
+ const gitManager = {
+ status: vi.fn().mockResolvedValue({
+ branch: "feature/test",
+ hasWorkingTreeChanges: true,
+ hasUpstream: false,
+ aheadCount: 0,
+ behindCount: 0,
+ }),
+ runStackedAction: vi.fn(),
+ };
+
+ server = createTestServer({ cwd: "/test", gitManager });
+ await server.start();
+ const addr = server.httpServer.address();
+ const port = typeof addr === "object" && addr !== null ? addr.port : 0;
+
+ const ws = await connectWs(port);
+ connections.push(ws);
+ await waitForMessage(ws);
+
+ const response = await sendRequest(ws, WS_METHODS.gitStatus, {
+ cwd: "/test",
+ });
+ expect(response.error).toBeUndefined();
+ expect(response.result).toEqual({
+ branch: "feature/test",
+ hasWorkingTreeChanges: true,
+ hasUpstream: false,
+ aheadCount: 0,
+ behindCount: 0,
+ });
+ expect(gitManager.status).toHaveBeenCalledWith({ cwd: "/test" });
+ });
+
+ it("returns errors from git.runStackedAction", async () => {
+ const gitManager = {
+ status: vi.fn(),
+ runStackedAction: vi
+ .fn()
+ .mockRejectedValue(new Error("Cannot push from detached HEAD.")),
+ };
+
+ server = createTestServer({ cwd: "/test", gitManager });
+ await server.start();
+ const addr = server.httpServer.address();
+ const port = typeof addr === "object" && addr !== null ? addr.port : 0;
+
+ const ws = await connectWs(port);
+ connections.push(ws);
+ await waitForMessage(ws);
+
+ const response = await sendRequest(ws, WS_METHODS.gitRunStackedAction, {
+ cwd: "/test",
+ action: "commit_push",
+ });
+ expect(response.result).toBeUndefined();
+ expect(response.error?.message).toContain("detached HEAD");
+ expect(gitManager.runStackedAction).toHaveBeenCalledWith({
+ cwd: "/test",
+ action: "commit_push",
+ });
+ });
+
it("prunes missing projects on startup", async () => {
const stateDir = makeTempDir("t3code-ws-prune-state-");
const existing = makeTempDir("t3code-ws-existing-project-");
diff --cc apps/server/src/wsServer.ts
index 5178718fc,353535ae3..f3904b844
--- a/apps/server/src/wsServer.ts
+++ b/apps/server/src/wsServer.ts
@@@ -19,7 -19,14 +19,15 @@@ import { WebSocketServer, type WebSocke
import { createLogger } from "./logger";
import { ProjectRegistry } from "./projectRegistry";
import { ProviderManager } from "./providerManager";
+import { GitManager } from "./gitManager";
+ import {
+ checkoutGitBranch,
+ createGitBranch,
+ createGitWorktree,
+ initGitRepo,
+ listGitBranches,
+ removeGitWorktree,
+ } from "./git";
const MIME_TYPES: Record<string, string> = {
".html": "text/html; charset=utf-8",
@@@ -308,11 -312,23 +316,28 @@@ export function createServer(options: S
return undefined;
}
+ case WS_METHODS.gitStatus:
+ return gitManager.status(request.params as never);
+
+ case WS_METHODS.gitRunStackedAction:
+ return gitManager.runStackedAction(request.params as never);
+ case WS_METHODS.gitListBranches:
+ return listGitBranches(request.params as never);
+
+ case WS_METHODS.gitCreateWorktree:
+ return createGitWorktree(request.params as never);
+
+ case WS_METHODS.gitRemoveWorktree:
+ return removeGitWorktree(request.params as never);
+
+ case WS_METHODS.gitCreateBranch:
+ return createGitBranch(request.params as never);
+
+ case WS_METHODS.gitCheckout:
+ return checkoutGitBranch(request.params as never);
+
+ case WS_METHODS.gitInit:
+ return initGitRepo(request.params as never);
case WS_METHODS.serverGetConfig:
return { cwd };
diff --cc apps/web/src/components/ChatView.tsx
index d9869197c,9792d07ff..df5b221e3
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@@ -181,26 -135,15 +176,20 @@@ export default function ChatView()
const [isConnecting, setIsConnecting] = useState(false);
const [isModelMenuOpen, setIsModelMenuOpen] = useState(false);
const [isEditorMenuOpen, setIsEditorMenuOpen] = useState(false);
+ const [isGitMenuOpen, setIsGitMenuOpen] = useState(false);
+ const [isGitActionRunning, setIsGitActionRunning] = useState(false);
+ const [gitStatus, setGitStatus] = useState<GitStatusResult | null>(null);
+ const [gitActionNotice, setGitActionNotice] = useState<string | null>(null);
+ const [gitActionError, setGitActionError] = useState<string | null>(null);
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;
+ return EDITORS.some((e) => e.id === stored) ? (stored as EditorId) : EDITORS[0].id;
});
- const [selectedEffort, setSelectedEffort] =
- useState<string>(DEFAULT_REASONING);
+ const [selectedEffort, setSelectedEffort] = useState<string>(DEFAULT_REASONING);
+ const [envMode, setEnvMode] = useState<"local" | "worktree">("local");
const [isSwitchingRuntimeMode, setIsSwitchingRuntimeMode] = useState(false);
- const [respondingRequestIds, setRespondingRequestIds] = useState<string[]>(
- [],
- );
- const [expandedWorkGroups, setExpandedWorkGroups] = useState<
- Record<string, boolean>
- >({});
+ const [respondingRequestIds, setRespondingRequestIds] = useState<string[]>([]);
+ const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>({});
const [nowTick, setNowTick] = useState(() => Date.now());
const messagesEndRef = useRef<HTMLDivElement>(null);
const textareaRef = useRef<HTMLTextAreaElement>(null);
@@@ -312,53 -250,13 +297,58 @@@
approvalPolicy: "on-request",
sandboxMode: "workspace-write",
} as const);
++ const gitCwd = activeThread?.worktreePath ?? activeProject?.cwd ?? null;
+ const gitActionsDisabled =
- !api || !activeProject || !gitStatus || isGitActionRunning;
++ !api || !gitCwd || !gitStatus || isGitActionRunning;
+ const pushActionDisabled = gitActionsDisabled || gitStatus.branch === null;
+
+ const refreshGitStatus = useCallback(async () => {
- if (!api || !activeProject) {
++ if (!api || !gitCwd) {
+ setGitStatus(null);
+ return;
+ }
+
- const nextStatus = await api.git.status({ cwd: activeProject.cwd });
++ const nextStatus = await api.git.status({ cwd: gitCwd });
+ setGitStatus(nextStatus);
- }, [api, activeProject]);
++ }, [api, gitCwd]);
+
+ const runGitAction = useCallback(
+ async (action: GitStackedAction) => {
- if (!api || !activeProject) return;
++ if (!api || !gitCwd) return;
+
+ setIsGitMenuOpen(false);
+ setIsGitActionRunning(true);
+ setGitActionError(null);
+ setGitActionNotice(null);
+ try {
+ const result = await api.git.runStackedAction({
- cwd: activeProject.cwd,
++ cwd: gitCwd,
+ action,
+ });
+ setGitActionNotice(summarizeGitActionResult(result));
+ } catch (error) {
+ setGitActionError(
+ error instanceof Error ? error.message : "Git action failed.",
+ );
+ } finally {
+ setIsGitActionRunning(false);
+ try {
+ await refreshGitStatus();
+ } catch {
+ setGitStatus(null);
+ }
+ }
+ },
- [api, activeProject, refreshGitStatus],
++ [api, gitCwd, refreshGitStatus],
++ );
++
+ const envLocked = Boolean(
+ activeThread &&
+ (activeThread.messages.length > 0 ||
+ (activeThread.session !== null && activeThread.session.status !== "closed")),
);
- const handleRuntimeModeChange = async (
- mode: "approval-required" | "full-access",
- ) => {
+ const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
if (mode === state.runtimeMode) return;
dispatch({ type: "SET_RUNTIME_MODE", mode });
if (!api) return;
@@@ -399,41 -293,11 +385,48 @@@
setExpandedWorkGroups({});
}, [activeThread?.id]);
+ const activeWorktreePath = activeThread?.worktreePath;
++
+ useEffect(() => {
+ setGitActionNotice(null);
+ setGitActionError(null);
- }, [activeProject?.id]);
++ }, [activeProject?.id, activeWorktreePath]);
+
+ useEffect(() => {
+ let cancelled = false;
- if (!api || !activeProject) {
++ if (!api || !gitCwd) {
+ setGitStatus(null);
+ return;
+ }
+
+ const load = async () => {
+ try {
- const nextStatus = await api.git.status({ cwd: activeProject.cwd });
++ const nextStatus = await api.git.status({ cwd: gitCwd });
+ if (!cancelled) {
+ setGitStatus(nextStatus);
+ }
+ } catch (error) {
+ if (!cancelled) {
+ setGitStatus(null);
+ setGitActionError(
+ error instanceof Error
+ ? error.message
+ : "Failed to read git status.",
+ );
+ }
+ }
+ };
+
+ void load();
+ return () => {
+ cancelled = true;
+ };
- }, [api, activeProject]);
++ }, [api, gitCwd]);
++
+ useEffect(() => {
+ if (!activeThread?.id) return;
+ setEnvMode(activeWorktreePath ? "worktree" : "local");
+ }, [activeThread?.id, activeWorktreePath]);
// Auto-resize textarea
useEffect(() => {
diff --cc apps/web/src/wsNativeApi.ts
index 6d85f513f,1705d0ae9..6b0c4d598
--- a/apps/web/src/wsNativeApi.ts
+++ b/apps/web/src/wsNativeApi.ts
@@@ -97,8 -97,12 +97,14 @@@ export function createWsNativeApi(): Na
transport.request(WS_METHODS.shellOpenInEditor, { cwd, editor }),
},
git: {
+ status: (input) => transport.request(WS_METHODS.gitStatus, input),
+ runStackedAction: (input) => transport.request(WS_METHODS.gitRunStackedAction, input),
+ listBranches: (input) => transport.request(WS_METHODS.gitListBranches, input),
+ createWorktree: (input) => transport.request(WS_METHODS.gitCreateWorktree, input),
+ removeWorktree: (input) => transport.request(WS_METHODS.gitRemoveWorktree, input),
+ createBranch: (input) => transport.request(WS_METHODS.gitCreateBranch, input),
+ checkout: (input) => transport.request(WS_METHODS.gitCheckout, input),
+ init: (input) => transport.request(WS_METHODS.gitInit, input),
},
contextMenu: {
show: async <T extends string>(
diff --cc packages/contracts/src/git.ts
index 360923f07,e53a600c5..1dba60249
--- a/packages/contracts/src/git.ts
+++ b/packages/contracts/src/git.ts
@@@ -1,66 -1,69 +1,130 @@@
import { z } from "zod";
-// ── Input schemas ──
++// ── Existing branch/worktree Git API ─────────────────────────────────
+
+ export const gitListBranchesInputSchema = z.object({
+ cwd: z.string().min(1),
+ });
+
+ export const gitCreateWorktreeInputSchema = z.object({
+ cwd: z.string().min(1),
- /** Base branch to create the worktree from. */
+ branch: z.string().min(1),
- /** New branch name to create in the worktree. */
+ newBranch: z.string().min(1),
+ path: z.string().min(1).optional(),
+ });
+
+ export const gitRemoveWorktreeInputSchema = z.object({
+ cwd: z.string().min(1),
+ path: z.string().min(1),
+ });
+
+ export const gitCreateBranchInputSchema = z.object({
+ cwd: z.string().min(1),
+ branch: z.string().min(1),
+ });
+
+ export const gitCheckoutInputSchema = z.object({
+ cwd: z.string().min(1),
+ branch: z.string().min(1),
+ });
+
+ export const gitInitInputSchema = z.object({
+ cwd: z.string().min(1),
+ });
+
-// ── Output schemas ──
-
+ export const gitBranchSchema = z.object({
+ name: z.string().min(1),
+ current: z.boolean(),
+ isDefault: z.boolean(),
+ worktreePath: z.string().min(1).nullable(),
+ });
+
+ export const gitWorktreeSchema = z.object({
+ path: z.string().min(1),
+ branch: z.string().min(1),
+ });
+
-// ── Types ──
-
+ export type GitListBranchesInput = z.infer<typeof gitListBranchesInputSchema>;
+ export type GitBranch = z.infer<typeof gitBranchSchema>;
+ export type GitCreateWorktreeInput = z.infer<typeof gitCreateWorktreeInputSchema>;
+ export type GitWorktree = z.infer<typeof gitWorktreeSchema>;
+ export type GitRemoveWorktreeInput = z.infer<typeof gitRemoveWorktreeInputSchema>;
+ export type GitCreateBranchInput = z.infer<typeof gitCreateBranchInputSchema>;
+ export type GitCheckoutInput = z.infer<typeof gitCheckoutInputSchema>;
+ export type GitInitInput = z.infer<typeof gitInitInputSchema>;
+
+ export interface GitListBranchesResult {
+ branches: GitBranch[];
+ isRepo: boolean;
+ }
+
+ export interface GitCreateWorktreeResult {
+ worktree: GitWorktree;
+ }
++
++// ── Stacked action Git API ───────────────────────────────────────────
++
+export const gitStatusInputSchema = z.object({
+ cwd: z.string().trim().min(1),
+});
+
+export const gitStatusResultSchema = z.object({
+ branch: z.string().min(1).nullable(),
+ hasWorkingTreeChanges: z.boolean(),
+ hasUpstream: z.boolean(),
+ aheadCount: z.number().int().nonnegative(),
+ behindCount: z.number().int().nonnegative(),
+});
+
+export const gitStackedActionSchema = z.enum([
+ "commit",
+ "commit_push",
+ "commit_push_pr",
+]);
+
+const gitCommitStepStatusSchema = z.enum(["created", "skipped_no_changes"]);
+const gitPushStepStatusSchema = z.enum([
+ "pushed",
+ "skipped_not_requested",
+ "skipped_up_to_date",
+]);
+const gitPrStepStatusSchema = z.enum([
+ "created",
+ "opened_existing",
+ "skipped_not_requested",
+]);
+
+export const gitRunStackedActionInputSchema = z.object({
+ cwd: z.string().trim().min(1),
+ action: gitStackedActionSchema,
+});
+
+export const gitRunStackedActionResultSchema = z.object({
+ action: gitStackedActionSchema,
+ commit: z.object({
+ status: gitCommitStepStatusSchema,
+ commitSha: z.string().min(1).optional(),
+ subject: z.string().min(1).optional(),
+ }),
+ push: z.object({
+ status: gitPushStepStatusSchema,
+ branch: z.string().min(1).optional(),
+ upstreamBranch: z.string().min(1).optional(),
+ setUpstream: z.boolean().optional(),
+ }),
+ pr: z.object({
+ status: gitPrStepStatusSchema,
+ url: z.string().url().optional(),
+ number: z.number().int().positive().optional(),
+ baseBranch: z.string().min(1).optional(),
+ headBranch: z.string().min(1).optional(),
+ title: z.string().min(1).optional(),
+ }),
+});
+
+export type GitStatusInput = z.input<typeof gitStatusInputSchema>;
+export type GitStatusResult = z.infer<typeof gitStatusResultSchema>;
+export type GitStackedAction = z.infer<typeof gitStackedActionSchema>;
+export type GitRunStackedActionInput = z.input<typeof gitRunStackedActionInputSchema>;
+export type GitRunStackedActionResult = z.infer<typeof gitRunStackedActionResultSchema>;
+
diff --cc packages/contracts/src/ipc.ts
index 84c1a3001,1681a0caf..3e7b92422
--- a/packages/contracts/src/ipc.ts
+++ b/packages/contracts/src/ipc.ts
@@@ -1,9 -1,13 +1,17 @@@
import type { AgentConfig, AgentExit, OutputChunk } from "./agent";
import type {
+ GitCheckoutInput,
+ GitCreateBranchInput,
+ GitCreateWorktreeInput,
+ GitCreateWorktreeResult,
+ GitInitInput,
+ GitListBranchesInput,
+ GitListBranchesResult,
+ GitRemoveWorktreeInput,
+ GitRunStackedActionInput,
+ GitRunStackedActionResult,
+ GitStatusInput,
+ GitStatusResult,
} from "./git";
import type {
ProviderEvent,
@@@ -69,10 -73,12 +77,18 @@@ export interface NativeApi
openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
};
git: {
++ // Existing branch/worktree API
+ listBranches: (input: GitListBranchesInput) => Promise<GitListBranchesResult>;
+ createWorktree: (input: GitCreateWorktreeInput) => Promise<GitCreateWorktreeResult>;
+ removeWorktree: (input: GitRemoveWorktreeInput) => Promise<void>;
+ createBranch: (input: GitCreateBranchInput) => Promise<void>;
+ checkout: (input: GitCheckoutInput) => Promise<void>;
+ init: (input: GitInitInput) => Promise<void>;
++ // Stacked action API
+ status: (input: GitStatusInput) => Promise<GitStatusResult>;
+ runStackedAction: (
+ input: GitRunStackedActionInput,
+ ) => Promise<GitRunStackedActionResult>;
};
contextMenu: {
show: <T extends string>(
@@@ -81,3 -87,3 +97,4 @@@
) => Promise<T | null>;
};
}
++
diff --cc packages/contracts/src/ws.ts
index 243606693,641227500..5e996f41d
--- a/packages/contracts/src/ws.ts
+++ b/packages/contracts/src/ws.ts
@@@ -20,8 -20,12 +20,14 @@@ export const WS_METHODS =
shellOpenInEditor: "shell.openInEditor",
// Git methods
+ gitStatus: "git.status",
+ gitRunStackedAction: "git.runStackedAction",
+ gitListBranches: "git.listBranches",
+ gitCreateWorktree: "git.createWorktree",
+ gitRemoveWorktree: "git.removeWorktree",
+ gitCreateBranch: "git.createBranch",
+ gitCheckout: "git.checkout",
+ gitInit: "git.init",
// Server meta
serverGetConfig: "server.getConfig",