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 Marmingeae296e59a427
diff --cc apps/server/src/git.ts
index 6498a71bb,7e299c6c4..43482ebf5
--- a/apps/server/src/git.ts
+++ b/apps/server/src/git.ts
@@@ -3,52 -3,64 +3,95 @@@ import fs from "node:fs"
import os from "node:os";
import path from "node:path";
-import type {
- GitCheckoutInput,
- GitCreateBranchInput,
- GitCreateWorktreeInput,
- GitCreateWorktreeResult,
- GitInitInput,
- GitListBranchesInput,
- GitListBranchesResult,
- GitRemoveWorktreeInput,
+import {
+ gitStatusInputSchema,
+ gitStatusResultSchema,
+ type GitCheckoutInput,
+ type GitCreateBranchInput,
+ type GitCreateWorktreeInput,
+ type GitCreateWorktreeResult,
+ type GitInitInput,
+ type GitListBranchesInput,
+ type GitListBranchesResult,
+ type GitRemoveWorktreeInput,
+ type GitStatusInput,
+ type GitStatusResult,
- type TerminalCommandInput,
- type TerminalCommandResult,
} from "@t3tools/contracts";
+ export interface TerminalCommandInput {
+ command: string;
+ cwd: string;
+ timeoutMs?: number;
+ maxOutputBytes?: number;
+ }
+
+ export interface TerminalCommandResult {
+ stdout: string;
+ stderr: string;
+ code: number | null;
+ signal: NodeJS.Signals | null;
+ timedOut: boolean;
+ }
+
+export interface GitStatusDetails extends GitStatusResult {
+ upstreamRef: string | null;
+}
+
+export interface GitPreparedCommitContext {
+ stagedSummary: string;
+ stagedPatch: string;
+}
+
+export interface GitPushResult {
+ status: "pushed" | "skipped_up_to_date";
+ branch: string;
+ upstreamBranch?: string | undefined;
+ setUpstream?: boolean | undefined;
+}
+
+export interface GitRangeContext {
+ commitSummary: string;
+ diffSummary: string;
+ diffPatch: string;
+}
+
+interface RunGitOptions {
+ timeoutMs?: number | undefined;
+ allowNonZeroExit?: boolean | undefined;
+}
+
+ const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
+
+ function appendChunkWithinLimit(
+ target: string,
+ currentBytes: number,
+ chunk: Buffer,
+ maxBytes: number,
+ ): {
+ next: string;
+ nextBytes: number;
+ truncated: boolean;
+ } {
+ const remaining = maxBytes - currentBytes;
+ if (remaining <= 0) {
+ return { next: target, nextBytes: currentBytes, truncated: true };
+ }
+ if (chunk.length <= remaining) {
+ return {
+ next: `${target}${chunk.toString()}`,
+ nextBytes: currentBytes + chunk.length,
+ truncated: false,
+ };
+ }
+ return {
+ next: `${target}${chunk.subarray(0, remaining).toString()}`,
+ nextBytes: currentBytes + remaining,
+ truncated: true,
+ };
+ }
+
/** Spawn git directly with an argv array — no shell, no quoting needed. */
-function runGit(args: string[], cwd: string, timeoutMs = 30_000): Promise<TerminalCommandResult> {
+function runGit(args: readonly string[], cwd: string, timeoutMs = 30_000): Promise<TerminalCommandResult> {
return new Promise((resolve, reject) => {
const child = spawn("git", args, {
cwd,
diff --cc apps/server/src/wsServer.test.ts
index 379d6b4fd,8a86a8786..9d256604f
--- a/apps/server/src/wsServer.test.ts
+++ b/apps/server/src/wsServer.test.ts
@@@ -85,10 -180,7 +180,11 @@@ describe("WebSocket Server", () =>
devUrl?: string;
authToken?: string;
stateDir?: string;
+ gitManager?: {
+ status: (input: { cwd: string }) => Promise<unknown>;
+ runStackedAction: (input: { cwd: string; action: string }) => Promise<unknown>;
+ };
+ terminalManager?: TerminalManager;
} = {},
): ReturnType<typeof createServer> {
const stateDir = options.stateDir ?? makeTempDir("t3code-ws-state-");
@@@ -98,7 -190,9 +194,10 @@@
...(options.devUrl ? { devUrl: options.devUrl } : {}),
...(options.authToken ? { authToken: options.authToken } : {}),
projectRegistry: new ProjectRegistry(stateDir),
+ ...(options.gitManager ? { gitManager: options.gitManager as never } : {}),
+ ...(options.terminalManager
+ ? { terminalManager: options.terminalManager }
+ : {}),
});
}
diff --cc apps/server/src/wsServer.ts
index f3904b844,d010c4a7c..60ed5abf8
--- a/apps/server/src/wsServer.ts
+++ b/apps/server/src/wsServer.ts
@@@ -52,7 -53,7 +54,8 @@@ export interface ServerOptions
devUrl?: string | undefined;
logWebSocketEvents?: boolean | undefined;
projectRegistry?: ProjectRegistry | undefined;
+ gitManager?: GitManager | undefined;
+ terminalManager?: TerminalManager | undefined;
authToken?: string | undefined;
}
@@@ -73,13 -74,13 +76,15 @@@ export function createServer(options: S
devUrl,
logWebSocketEvents: explicitLogWsEvents,
projectRegistry: providedRegistry,
+ gitManager: providedGitManager,
+ terminalManager: providedTerminalManager,
authToken,
} = options;
const providerManager = new ProviderManager();
+ const terminalManager = providedTerminalManager ?? new TerminalManager();
const projectRegistry =
providedRegistry ?? new ProjectRegistry(path.join(os.homedir(), ".t3", "userdata"));
+ const gitManager = providedGitManager ?? new GitManager();
const clients = new Set<WebSocket>();
const logger = createLogger("ws");
const logWebSocketEvents =
diff --cc apps/web/src/components/ChatView.tsx
index 060aec0d8,a052a3db2..9435f2c96
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@@ -162,10 -153,10 +165,12 @@@ export default function ChatView()
const textareaRef = useRef<HTMLTextAreaElement>(null);
const modelMenuRef = useRef<HTMLDivElement>(null);
const editorMenuRef = useRef<HTMLDivElement>(null);
+ const gitMenuRef = useRef<HTMLDivElement>(null);
+ const latestGitCwdRef = useRef<string | null>(null);
+ const terminalOpenByThreadRef = useRef<Record<string, boolean>>({});
const activeThread = state.threads.find((t) => t.id === state.activeThreadId);
+ const activeThreadId = activeThread?.id ?? null;
const activeProject = state.projects.find((p) => p.id === activeThread?.projectId);
const selectedModel = resolveModelSlug(
activeThread?.model ?? activeProject?.model ?? DEFAULT_MODEL,
@@@ -821,57 -691,18 +876,68 @@@
)}
</div>
)}
+ {/* Git actions */}
+ {activeProject && (
+ <div className="relative" ref={gitMenuRef}>
+ <button
+ type="button"
+ className="inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[10px] text-muted-foreground/70 transition-colors duration-150 hover:bg-accent hover:text-foreground/80 disabled:cursor-not-allowed disabled:opacity-60"
+ onClick={() => setIsGitMenuOpen((v) => !v)}
+ disabled={!gitStatus || isGitActionRunning}
+ >
+ {isGitActionRunning ? "Running..." : "Git actions"}
+ <span aria-hidden="true">▾</span>
+ </button>
+ {isGitMenuOpen && (
+ <div className="absolute right-0 top-full z-50 mt-1 w-[240px] rounded-xl border border-border bg-popover p-2 shadow-xl">
+ <p className="px-2 pb-1 text-[10px] uppercase tracking-[0.1em] text-muted-foreground/60">
+ Git actions
+ </p>
+ {gitActionMenuItems.map((item) => {
+ return (
+ <button
+ key={item.id}
+ type="button"
+ className="mb-1 flex w-full items-center rounded-lg px-2 py-2 text-left text-[11px] text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50"
+ disabled={item.disabled}
+ onClick={() => {
+ void runGitAction(item.id);
+ }}
+ >
+ {item.label}
+ </button>
+ );
+ })}
+ {gitStatus?.branch === null && (
+ <p className="px-2 pt-1 text-[10px] text-amber-500 dark:text-amber-300">
+ Detached HEAD: push and PR actions are unavailable.
+ </p>
+ )}
+ {gitStatus &&
+ gitStatus.branch !== null &&
+ !gitStatus.hasWorkingTreeChanges &&
+ gitStatus.aheadCount === 0 &&
+ gitStatus.behindCount > 0 && (
+ <p className="px-2 pt-1 text-[10px] text-amber-500 dark:text-amber-300">
+ Branch is behind upstream. Pull/rebase before opening a PR.
+ </p>
+ )}
+ </div>
+ )}
+ </div>
+ )}
{/* Diff toggle */}
+ <button
+ type="button"
+ className={`rounded-md px-2 py-1 text-[10px] transition-colors duration-150 ${
+ activeThread.terminalOpen
+ ? "bg-accent text-foreground"
+ : "text-muted-foreground/40 hover:text-muted-foreground/60"
+ }`}
+ onClick={toggleTerminalVisibility}
+ >
+ Terminal <span className="text-muted-foreground/50">{terminalShortcutHint}</span>
+ </button>
<button
type="button"
className={`rounded-md px-2 py-1 text-[10px] transition-colors duration-150 ${