Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db02da69ba | ||
|
|
ca37b7bafe |
No files matched your search
@@ -24,32 +24,32 @@ jobs:
|
||||
{
|
||||
name: "size:XS",
|
||||
color: "0e8a16",
|
||||
description: "0-9 effective changed lines (test files excluded in mixed PRs).",
|
||||
description: "0-9 changed lines (additions + deletions).",
|
||||
},
|
||||
{
|
||||
name: "size:S",
|
||||
color: "5ebd3e",
|
||||
description: "10-29 effective changed lines (test files excluded in mixed PRs).",
|
||||
description: "10-29 changed lines (additions + deletions).",
|
||||
},
|
||||
{
|
||||
name: "size:M",
|
||||
color: "fbca04",
|
||||
description: "30-99 effective changed lines (test files excluded in mixed PRs).",
|
||||
description: "30-99 changed lines (additions + deletions).",
|
||||
},
|
||||
{
|
||||
name: "size:L",
|
||||
color: "fe7d37",
|
||||
description: "100-499 effective changed lines (test files excluded in mixed PRs).",
|
||||
description: "100-499 changed lines (additions + deletions).",
|
||||
},
|
||||
{
|
||||
name: "size:XL",
|
||||
color: "d93f0b",
|
||||
description: "500-999 effective changed lines (test files excluded in mixed PRs).",
|
||||
description: "500-999 changed lines (additions + deletions).",
|
||||
},
|
||||
{
|
||||
name: "size:XXL",
|
||||
color: "b60205",
|
||||
description: "1,000+ effective changed lines (test files excluded in mixed PRs).",
|
||||
description: "1,000+ changed lines (additions + deletions).",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -131,18 +131,12 @@ jobs:
|
||||
with:
|
||||
script: |
|
||||
const issueNumber = context.payload.pull_request.number;
|
||||
const additions = context.payload.pull_request.additions ?? 0;
|
||||
const deletions = context.payload.pull_request.deletions ?? 0;
|
||||
const changedLines = additions + deletions;
|
||||
const managedLabels = JSON.parse(process.env.PR_SIZE_LABELS_JSON ?? "[]");
|
||||
const managedLabelNames = new Set(managedLabels.map((label) => label.name));
|
||||
// Keep this aligned with the repo's test entrypoints and test-only support files.
|
||||
const testFilePatterns = [
|
||||
/(^|\/)__tests__(\/|$)/,
|
||||
/(^|\/)tests?(\/|$)/,
|
||||
/^apps\/server\/integration\//,
|
||||
/\.(test|spec|browser|integration)\.[^.\/]+$/,
|
||||
];
|
||||
|
||||
const isTestFile = (filename) =>
|
||||
testFilePatterns.some((pattern) => pattern.test(filename));
|
||||
const managedLabelNames = new Set(managedLabels.map((label) => label.name));
|
||||
|
||||
const resolveSizeLabel = (totalChangedLines) => {
|
||||
if (totalChangedLines < 10) {
|
||||
@@ -168,42 +162,6 @@ jobs:
|
||||
return "size:XXL";
|
||||
};
|
||||
|
||||
const files = await github.paginate(
|
||||
github.rest.pulls.listFiles,
|
||||
{
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: issueNumber,
|
||||
per_page: 100,
|
||||
},
|
||||
(response) => response.data,
|
||||
);
|
||||
|
||||
if (files.length >= 3000) {
|
||||
core.warning(
|
||||
"The GitHub pull request files API may truncate results at 3,000 files; PR size may be undercounted.",
|
||||
);
|
||||
}
|
||||
|
||||
let testChangedLines = 0;
|
||||
let nonTestChangedLines = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const changedLinesForFile = (file.additions ?? 0) + (file.deletions ?? 0);
|
||||
|
||||
if (changedLinesForFile === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isTestFile(file.filename)) {
|
||||
testChangedLines += changedLinesForFile;
|
||||
continue;
|
||||
}
|
||||
|
||||
nonTestChangedLines += changedLinesForFile;
|
||||
}
|
||||
|
||||
const changedLines = nonTestChangedLines === 0 ? testChangedLines : nonTestChangedLines;
|
||||
const nextLabelName = resolveSizeLabel(changedLines);
|
||||
|
||||
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
|
||||
@@ -241,15 +199,4 @@ jobs:
|
||||
});
|
||||
}
|
||||
|
||||
const classification =
|
||||
nonTestChangedLines === 0
|
||||
? testChangedLines > 0
|
||||
? "test-only PR"
|
||||
: "no line changes"
|
||||
: testChangedLines > 0
|
||||
? "test lines excluded"
|
||||
: "all non-test changes";
|
||||
|
||||
core.info(
|
||||
`PR #${issueNumber}: ${nonTestChangedLines} non-test lines, ${testChangedLines} test lines, ${changedLines} effective lines -> ${nextLabelName} (${classification})`,
|
||||
);
|
||||
core.info(`PR #${issueNumber}: ${changedLines} changed lines -> ${nextLabelName}`);
|
||||
@@ -47,6 +47,7 @@ import { isArm64HostRunningIntelBuild, resolveDesktopRuntimeInfo } from "./runti
|
||||
syncShellEnvironment();
|
||||
|
||||
const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
|
||||
const GET_DOCUMENTS_PATH_CHANNEL = "desktop:get-documents-path";
|
||||
const CONFIRM_CHANNEL = "desktop:confirm";
|
||||
const SET_THEME_CHANNEL = "desktop:set-theme";
|
||||
const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
|
||||
@@ -1086,6 +1087,16 @@ function registerIpcHandlers(): void {
|
||||
return result.filePaths[0] ?? null;
|
||||
});
|
||||
|
||||
ipcMain.removeHandler(GET_DOCUMENTS_PATH_CHANNEL);
|
||||
ipcMain.handle(GET_DOCUMENTS_PATH_CHANNEL, async () => {
|
||||
try {
|
||||
const documentsPath = app.getPath("documents");
|
||||
return typeof documentsPath === "string" && documentsPath.length > 0 ? documentsPath : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.removeHandler(CONFIRM_CHANNEL);
|
||||
ipcMain.handle(CONFIRM_CHANNEL, async (_event, message: unknown) => {
|
||||
if (typeof message !== "string") {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { contextBridge, ipcRenderer } from "electron";
|
||||
import type { DesktopBridge } from "@t3tools/contracts";
|
||||
|
||||
const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
|
||||
const GET_DOCUMENTS_PATH_CHANNEL = "desktop:get-documents-path";
|
||||
const CONFIRM_CHANNEL = "desktop:confirm";
|
||||
const SET_THEME_CHANNEL = "desktop:set-theme";
|
||||
const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
|
||||
@@ -16,6 +17,7 @@ const wsUrl = process.env.T3CODE_DESKTOP_WS_URL ?? null;
|
||||
contextBridge.exposeInMainWorld("desktopBridge", {
|
||||
getWsUrl: () => wsUrl,
|
||||
pickFolder: () => ipcRenderer.invoke(PICK_FOLDER_CHANNEL),
|
||||
getDocumentsPath: () => ipcRenderer.invoke(GET_DOCUMENTS_PATH_CHANNEL),
|
||||
confirm: (message) => ipcRenderer.invoke(CONFIRM_CHANNEL, message),
|
||||
setTheme: (theme) => ipcRenderer.invoke(SET_THEME_CHANNEL, theme),
|
||||
showContextMenu: (items, position) => ipcRenderer.invoke(CONTEXT_MENU_CHANNEL, items, position),
|
||||
|
||||
@@ -469,46 +469,6 @@ describe("TerminalManager", () => {
|
||||
manager.dispose();
|
||||
});
|
||||
|
||||
it("persists only displayable transcript content when PTY emits ANSI control sequences", async () => {
|
||||
const { manager, ptyAdapter } = makeManager();
|
||||
await manager.open(openInput());
|
||||
const process = ptyAdapter.processes[0];
|
||||
expect(process).toBeDefined();
|
||||
if (!process) return;
|
||||
|
||||
process.emitData("prompt ");
|
||||
process.emitData("\u001b]11;rgb:ffff/ffff/ffff\u0007");
|
||||
process.emitData("\u001b[1;1R");
|
||||
process.emitData("done\n");
|
||||
|
||||
await manager.close({ threadId: "thread-1" });
|
||||
|
||||
const reopened = await manager.open(openInput());
|
||||
expect(reopened.history).toBe("prompt done\n");
|
||||
|
||||
manager.dispose();
|
||||
});
|
||||
|
||||
it("drops chunk-split terminal control sequences from persisted history", async () => {
|
||||
const { manager, ptyAdapter } = makeManager();
|
||||
await manager.open(openInput());
|
||||
const process = ptyAdapter.processes[0];
|
||||
expect(process).toBeDefined();
|
||||
if (!process) return;
|
||||
|
||||
process.emitData("prompt ");
|
||||
process.emitData("\u001b]11;");
|
||||
process.emitData("rgb:ffff/ffff/ffff\u0007\u001b[1;1");
|
||||
process.emitData("Rdone\n");
|
||||
|
||||
await manager.close({ threadId: "thread-1" });
|
||||
|
||||
const reopened = await manager.open(openInput());
|
||||
expect(reopened.history).toBe("prompt done\n");
|
||||
|
||||
manager.dispose();
|
||||
});
|
||||
|
||||
it("deletes history file when close(deleteHistory=true)", async () => {
|
||||
const { manager, ptyAdapter, logsDir } = makeManager();
|
||||
await manager.open(openInput());
|
||||
|
||||
@@ -254,132 +254,6 @@ function capHistory(history: string, maxLines: number): string {
|
||||
return hasTrailingNewline ? `${capped}\n` : capped;
|
||||
}
|
||||
|
||||
function isPrintableTerminalCharacter(codePoint: number): boolean {
|
||||
return codePoint >= 0x20 && codePoint !== 0x7f;
|
||||
}
|
||||
|
||||
function isCsiFinalByte(codePoint: number): boolean {
|
||||
return codePoint >= 0x40 && codePoint <= 0x7e;
|
||||
}
|
||||
|
||||
function findStringTerminatorIndex(input: string, start: number): number | null {
|
||||
for (let index = start; index < input.length; index += 1) {
|
||||
const codePoint = input.charCodeAt(index);
|
||||
if (codePoint === 0x07 || codePoint === 0x9c) {
|
||||
return index + 1;
|
||||
}
|
||||
if (codePoint === 0x1b && input.charCodeAt(index + 1) === 0x5c) {
|
||||
return index + 2;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function sanitizeTerminalHistoryChunk(
|
||||
pendingControlSequence: string,
|
||||
data: string,
|
||||
): { visibleText: string; pendingControlSequence: string } {
|
||||
const input = `${pendingControlSequence}${data}`;
|
||||
let visibleText = "";
|
||||
let index = 0;
|
||||
|
||||
while (index < input.length) {
|
||||
const codePoint = input.charCodeAt(index);
|
||||
|
||||
if (codePoint === 0x1b) {
|
||||
const nextCodePoint = input.charCodeAt(index + 1);
|
||||
if (Number.isNaN(nextCodePoint)) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
|
||||
if (nextCodePoint === 0x5b) {
|
||||
let cursor = index + 2;
|
||||
while (cursor < input.length) {
|
||||
if (isCsiFinalByte(input.charCodeAt(cursor))) {
|
||||
index = cursor + 1;
|
||||
break;
|
||||
}
|
||||
cursor += 1;
|
||||
}
|
||||
if (cursor >= input.length) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
nextCodePoint === 0x5d ||
|
||||
nextCodePoint === 0x50 ||
|
||||
nextCodePoint === 0x5e ||
|
||||
nextCodePoint === 0x5f
|
||||
) {
|
||||
const terminatorIndex = findStringTerminatorIndex(input, index + 2);
|
||||
if (terminatorIndex === null) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
index = terminatorIndex;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nextCodePoint >= 0x20 && nextCodePoint <= 0x2f) {
|
||||
let cursor = index + 2;
|
||||
while (
|
||||
cursor < input.length &&
|
||||
input.charCodeAt(cursor) >= 0x20 &&
|
||||
input.charCodeAt(cursor) <= 0x2f
|
||||
) {
|
||||
cursor++;
|
||||
}
|
||||
if (cursor >= input.length) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
index = cursor + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (codePoint === 0x9b) {
|
||||
let cursor = index + 1;
|
||||
while (cursor < input.length) {
|
||||
if (isCsiFinalByte(input.charCodeAt(cursor))) {
|
||||
index = cursor + 1;
|
||||
break;
|
||||
}
|
||||
cursor += 1;
|
||||
}
|
||||
if (cursor >= input.length) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (codePoint === 0x9d || codePoint === 0x90 || codePoint === 0x9e || codePoint === 0x9f) {
|
||||
const terminatorIndex = findStringTerminatorIndex(input, index + 1);
|
||||
if (terminatorIndex === null) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
index = terminatorIndex;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
codePoint === 0x0a ||
|
||||
codePoint === 0x0d ||
|
||||
codePoint === 0x09 ||
|
||||
isPrintableTerminalCharacter(codePoint)
|
||||
) {
|
||||
visibleText += input[index];
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return { visibleText, pendingControlSequence: "" };
|
||||
}
|
||||
|
||||
function legacySafeThreadId(threadId: string): string {
|
||||
return threadId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
||||
}
|
||||
@@ -504,7 +378,6 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
status: "starting",
|
||||
pid: null,
|
||||
history,
|
||||
pendingHistoryControlSequence: "",
|
||||
exitCode: null,
|
||||
exitSignal: null,
|
||||
updatedAt: new Date().toISOString(),
|
||||
@@ -534,12 +407,10 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
existing.cwd = input.cwd;
|
||||
existing.runtimeEnv = nextRuntimeEnv;
|
||||
existing.history = "";
|
||||
existing.pendingHistoryControlSequence = "";
|
||||
await this.persistHistory(existing.threadId, existing.terminalId, existing.history);
|
||||
} else if (existing.status === "exited" || existing.status === "error") {
|
||||
existing.runtimeEnv = nextRuntimeEnv;
|
||||
existing.history = "";
|
||||
existing.pendingHistoryControlSequence = "";
|
||||
await this.persistHistory(existing.threadId, existing.terminalId, existing.history);
|
||||
} else if (currentRuntimeEnv !== nextRuntimeEnv) {
|
||||
existing.runtimeEnv = nextRuntimeEnv;
|
||||
@@ -598,7 +469,6 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
await this.runWithThreadLock(input.threadId, async () => {
|
||||
const session = this.requireSession(input.threadId, input.terminalId);
|
||||
session.history = "";
|
||||
session.pendingHistoryControlSequence = "";
|
||||
session.updatedAt = new Date().toISOString();
|
||||
await this.persistHistory(input.threadId, input.terminalId, session.history);
|
||||
this.emitEvent({
|
||||
@@ -627,7 +497,6 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
status: "starting",
|
||||
pid: null,
|
||||
history: "",
|
||||
pendingHistoryControlSequence: "",
|
||||
exitCode: null,
|
||||
exitSignal: null,
|
||||
updatedAt: new Date().toISOString(),
|
||||
@@ -651,7 +520,6 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
const rows = input.rows ?? session.rows;
|
||||
|
||||
session.history = "";
|
||||
session.pendingHistoryControlSequence = "";
|
||||
await this.persistHistory(input.threadId, input.terminalId, session.history);
|
||||
await this.startSession(session, { ...input, cols, rows }, "restarted");
|
||||
return this.snapshot(session);
|
||||
@@ -826,16 +694,9 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
}
|
||||
|
||||
private onProcessData(session: TerminalSessionState, data: string): void {
|
||||
const sanitized = sanitizeTerminalHistoryChunk(session.pendingHistoryControlSequence, data);
|
||||
session.pendingHistoryControlSequence = sanitized.pendingControlSequence;
|
||||
if (sanitized.visibleText.length > 0) {
|
||||
session.history = capHistory(
|
||||
`${session.history}${sanitized.visibleText}`,
|
||||
this.historyLineLimit,
|
||||
);
|
||||
this.queuePersist(session.threadId, session.terminalId, session.history);
|
||||
}
|
||||
session.history = capHistory(`${session.history}${data}`, this.historyLineLimit);
|
||||
session.updatedAt = new Date().toISOString();
|
||||
this.queuePersist(session.threadId, session.terminalId, session.history);
|
||||
this.emitEvent({
|
||||
type: "output",
|
||||
threadId: session.threadId,
|
||||
@@ -852,7 +713,6 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
session.pid = null;
|
||||
session.hasRunningSubprocess = false;
|
||||
session.status = "exited";
|
||||
session.pendingHistoryControlSequence = "";
|
||||
session.exitCode = Number.isInteger(event.exitCode) ? event.exitCode : null;
|
||||
session.exitSignal = Number.isInteger(event.signal) ? event.signal : null;
|
||||
session.updatedAt = new Date().toISOString();
|
||||
@@ -876,7 +736,6 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
|
||||
session.pid = null;
|
||||
session.hasRunningSubprocess = false;
|
||||
session.status = "exited";
|
||||
session.pendingHistoryControlSequence = "";
|
||||
session.updatedAt = new Date().toISOString();
|
||||
this.killProcessWithEscalation(process, session.threadId, session.terminalId);
|
||||
this.evictInactiveSessionsIfNeeded();
|
||||
|
||||
@@ -32,7 +32,6 @@ export interface TerminalSessionState {
|
||||
status: TerminalSessionStatus;
|
||||
pid: number | null;
|
||||
history: string;
|
||||
pendingHistoryControlSequence: string;
|
||||
exitCode: number | null;
|
||||
exitSignal: number | null;
|
||||
updatedAt: string;
|
||||
|
||||
@@ -1641,6 +1641,49 @@ describe("WebSocket Server", () => {
|
||||
expect(fs.existsSync(path.join(workspace, "..", "escape.md"))).toBe(false);
|
||||
});
|
||||
|
||||
it("supports projects.createDirectory within the workspace root", async () => {
|
||||
const workspace = makeTempDir("t3code-ws-create-directory-");
|
||||
|
||||
server = await createTestServer({ cwd: "/test" });
|
||||
const addr = server.address();
|
||||
const port = typeof addr === "object" && addr !== null ? addr.port : 0;
|
||||
|
||||
const [ws] = await connectAndAwaitWelcome(port);
|
||||
connections.push(ws);
|
||||
|
||||
const response = await sendRequest(ws, WS_METHODS.projectsCreateDirectory, {
|
||||
cwd: workspace,
|
||||
relativePath: "sandboxes/fresh-room",
|
||||
});
|
||||
|
||||
expect(response.error).toBeUndefined();
|
||||
expect(response.result).toEqual({
|
||||
relativePath: "sandboxes/fresh-room",
|
||||
absolutePath: path.join(workspace, "sandboxes", "fresh-room"),
|
||||
});
|
||||
expect(fs.existsSync(path.join(workspace, "sandboxes", "fresh-room"))).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects projects.createDirectory when the target already exists", async () => {
|
||||
const workspace = makeTempDir("t3code-ws-create-directory-existing-");
|
||||
fs.mkdirSync(path.join(workspace, "existing"), { recursive: true });
|
||||
|
||||
server = await createTestServer({ cwd: "/test" });
|
||||
const addr = server.address();
|
||||
const port = typeof addr === "object" && addr !== null ? addr.port : 0;
|
||||
|
||||
const [ws] = await connectAndAwaitWelcome(port);
|
||||
connections.push(ws);
|
||||
|
||||
const response = await sendRequest(ws, WS_METHODS.projectsCreateDirectory, {
|
||||
cwd: workspace,
|
||||
relativePath: "existing",
|
||||
});
|
||||
|
||||
expect(response.result).toBeUndefined();
|
||||
expect(response.error?.message).toContain("Workspace directory already exists");
|
||||
});
|
||||
|
||||
it("routes git core methods over websocket", async () => {
|
||||
const listBranches = vi.fn(() =>
|
||||
Effect.succeed({
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
FileSystem,
|
||||
Layer,
|
||||
Path,
|
||||
PlatformError,
|
||||
Ref,
|
||||
Result,
|
||||
Schema,
|
||||
@@ -776,6 +777,58 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
return { relativePath: target.relativePath };
|
||||
}
|
||||
|
||||
case WS_METHODS.projectsCreateDirectory: {
|
||||
const body = stripRequestTag(request.body);
|
||||
const target = yield* resolveWorkspaceWritePath({
|
||||
workspaceRoot: body.cwd,
|
||||
relativePath: body.relativePath,
|
||||
path,
|
||||
});
|
||||
|
||||
const existingEntry = yield* Effect.result(fileSystem.stat(target.absolutePath));
|
||||
if (Result.isSuccess(existingEntry)) {
|
||||
return yield* new RouteRequestError({
|
||||
message: `Workspace directory already exists: ${target.relativePath}`,
|
||||
});
|
||||
}
|
||||
if (
|
||||
!(
|
||||
existingEntry.failure instanceof PlatformError.PlatformError &&
|
||||
existingEntry.failure.reason instanceof PlatformError.SystemError &&
|
||||
existingEntry.failure.reason._tag === "NotFound"
|
||||
)
|
||||
) {
|
||||
return yield* new RouteRequestError({
|
||||
message: `Failed to inspect workspace directory: ${String(existingEntry.failure)}`,
|
||||
});
|
||||
}
|
||||
|
||||
yield* fileSystem
|
||||
.makeDirectory(path.dirname(target.absolutePath), { recursive: true })
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new RouteRequestError({
|
||||
message: `Failed to prepare workspace directory path: ${String(cause)}`,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
yield* fileSystem.makeDirectory(target.absolutePath, { recursive: false }).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new RouteRequestError({
|
||||
message: `Failed to create workspace directory: ${String(cause)}`,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
relativePath: target.relativePath,
|
||||
absolutePath: target.absolutePath,
|
||||
};
|
||||
}
|
||||
|
||||
case WS_METHODS.shellOpenInEditor: {
|
||||
const body = stripRequestTag(request.body);
|
||||
return yield* openInEditor(body);
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
getCustomModelsByProvider,
|
||||
getCustomModelsForProvider,
|
||||
getDefaultCustomModelsForProvider,
|
||||
getProviderStartOptions,
|
||||
MODEL_PROVIDER_SETTINGS,
|
||||
normalizeCustomModelSlugs,
|
||||
patchCustomModels,
|
||||
@@ -119,35 +118,6 @@ describe("provider-specific custom models", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getProviderStartOptions", () => {
|
||||
it("returns only populated provider overrides", () => {
|
||||
expect(
|
||||
getProviderStartOptions({
|
||||
claudeBinaryPath: "/usr/local/bin/claude",
|
||||
codexBinaryPath: "",
|
||||
codexHomePath: "/Users/you/.codex",
|
||||
}),
|
||||
).toEqual({
|
||||
claudeAgent: {
|
||||
binaryPath: "/usr/local/bin/claude",
|
||||
},
|
||||
codex: {
|
||||
homePath: "/Users/you/.codex",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined when no provider overrides are configured", () => {
|
||||
expect(
|
||||
getProviderStartOptions({
|
||||
claudeBinaryPath: "",
|
||||
codexBinaryPath: "",
|
||||
codexHomePath: "",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("provider-indexed custom model settings", () => {
|
||||
const settings = {
|
||||
customCodexModels: ["custom/codex-model"],
|
||||
@@ -239,9 +209,9 @@ describe("AppSettingsSchema", () => {
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
claudeBinaryPath: "",
|
||||
codexBinaryPath: "/usr/local/bin/codex",
|
||||
codexHomePath: "",
|
||||
newProjectBasePath: "",
|
||||
defaultThreadEnvMode: "local",
|
||||
confirmThreadDelete: false,
|
||||
enableAssistantStreaming: false,
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { useCallback } from "react";
|
||||
import { Option, Schema } from "effect";
|
||||
import {
|
||||
TrimmedNonEmptyString,
|
||||
type ProviderKind,
|
||||
type ProviderStartOptions,
|
||||
} from "@t3tools/contracts";
|
||||
import { TrimmedNonEmptyString, type ProviderKind } from "@t3tools/contracts";
|
||||
import {
|
||||
getDefaultModel,
|
||||
getModelOptions,
|
||||
@@ -51,9 +47,9 @@ const withDefaults =
|
||||
);
|
||||
|
||||
export const AppSettingsSchema = Schema.Struct({
|
||||
claudeBinaryPath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
|
||||
codexBinaryPath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
|
||||
codexHomePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
|
||||
newProjectBasePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
|
||||
defaultThreadEnvMode: EnvMode.pipe(withDefaults(() => "local" as const satisfies EnvMode)),
|
||||
confirmThreadDelete: Schema.Boolean.pipe(withDefaults(() => true)),
|
||||
enableAssistantStreaming: Schema.Boolean.pipe(withDefaults(() => false)),
|
||||
@@ -226,30 +222,6 @@ export function getCustomModelOptionsByProvider(
|
||||
};
|
||||
}
|
||||
|
||||
export function getProviderStartOptions(
|
||||
settings: Pick<AppSettings, "claudeBinaryPath" | "codexBinaryPath" | "codexHomePath">,
|
||||
): ProviderStartOptions | undefined {
|
||||
const providerOptions: ProviderStartOptions = {
|
||||
...(settings.codexBinaryPath || settings.codexHomePath
|
||||
? {
|
||||
codex: {
|
||||
...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}),
|
||||
...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(settings.claudeBinaryPath
|
||||
? {
|
||||
claudeAgent: {
|
||||
binaryPath: settings.claudeBinaryPath,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
|
||||
return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
|
||||
}
|
||||
|
||||
export function useAppSettings() {
|
||||
const [settings, setSettings] = useLocalStorage(
|
||||
APP_SETTINGS_STORAGE_KEY,
|
||||
|
||||
@@ -122,7 +122,6 @@ import { readNativeApi } from "~/nativeApi";
|
||||
import {
|
||||
getCustomModelOptionsByProvider,
|
||||
getCustomModelsByProvider,
|
||||
getProviderStartOptions,
|
||||
resolveAppModelSelection,
|
||||
useAppSettings,
|
||||
} from "../appSettings";
|
||||
@@ -619,7 +618,17 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
const selectedModelOptionsForDispatch = composerProviderState.modelOptionsForDispatch;
|
||||
const providerOptionsForDispatch = useMemo(() => getProviderStartOptions(settings), [settings]);
|
||||
const providerOptionsForDispatch = useMemo(() => {
|
||||
if (!settings.codexBinaryPath && !settings.codexHomePath) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
codex: {
|
||||
...(settings.codexBinaryPath ? { binaryPath: settings.codexBinaryPath } : {}),
|
||||
...(settings.codexHomePath ? { homePath: settings.codexHomePath } : {}),
|
||||
},
|
||||
};
|
||||
}, [settings.codexBinaryPath, settings.codexHomePath]);
|
||||
const selectedModelForPicker = selectedModel;
|
||||
const modelOptionsByProvider = useMemo(
|
||||
() => getCustomModelOptionsByProvider(settings),
|
||||
|
||||
@@ -2,6 +2,8 @@ import {
|
||||
ArrowLeftIcon,
|
||||
ChevronRightIcon,
|
||||
FolderIcon,
|
||||
FolderOpenIcon,
|
||||
FolderPlusIcon,
|
||||
GitPullRequestIcon,
|
||||
PlusIcon,
|
||||
RocketIcon,
|
||||
@@ -64,6 +66,17 @@ import {
|
||||
import { Alert, AlertAction, AlertDescription, AlertTitle } from "./ui/alert";
|
||||
import { Button } from "./ui/button";
|
||||
import { Collapsible, CollapsibleContent } from "./ui/collapsible";
|
||||
import {
|
||||
Dialog,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogPanel,
|
||||
DialogPopup,
|
||||
DialogTitle,
|
||||
} from "./ui/dialog";
|
||||
import { Input } from "./ui/input";
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "./ui/menu";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
import {
|
||||
SidebarContent,
|
||||
@@ -272,7 +285,7 @@ export default function Sidebar() {
|
||||
);
|
||||
const navigate = useNavigate();
|
||||
const isOnSettings = useLocation({ select: (loc) => loc.pathname === "/settings" });
|
||||
const { settings: appSettings } = useAppSettings();
|
||||
const { settings: appSettings, updateSettings } = useAppSettings();
|
||||
const { handleNewThread } = useHandleNewThread();
|
||||
const routeThreadId = useParams({
|
||||
strict: false,
|
||||
@@ -285,11 +298,22 @@ export default function Sidebar() {
|
||||
const queryClient = useQueryClient();
|
||||
const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ queryClient }));
|
||||
const [addingProject, setAddingProject] = useState(false);
|
||||
const [isAddProjectMenuOpen, setIsAddProjectMenuOpen] = useState(false);
|
||||
const [newCwd, setNewCwd] = useState("");
|
||||
const [isPickingFolder, setIsPickingFolder] = useState(false);
|
||||
const [isAddingProject, setIsAddingProject] = useState(false);
|
||||
const [addProjectError, setAddProjectError] = useState<string | null>(null);
|
||||
const addProjectInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const addProjectMenuCloseTimerRef = useRef<number | null>(null);
|
||||
const [isCreateProjectDialogOpen, setIsCreateProjectDialogOpen] = useState(false);
|
||||
const [createProjectDirectoryPath, setCreateProjectDirectoryPath] = useState("");
|
||||
const [newProjectDirectoryName, setNewProjectDirectoryName] = useState("");
|
||||
const [isCreatingProjectDirectory, setIsCreatingProjectDirectory] = useState(false);
|
||||
const [isPickingCreateProjectDirectoryPath, setIsPickingCreateProjectDirectoryPath] =
|
||||
useState(false);
|
||||
const [createProjectDirectoryError, setCreateProjectDirectoryError] = useState<string | null>(
|
||||
null,
|
||||
);
|
||||
const [renamingThreadId, setRenamingThreadId] = useState<ThreadId | null>(null);
|
||||
const [renamingTitle, setRenamingTitle] = useState("");
|
||||
const [expandedThreadListsByProject, setExpandedThreadListsByProject] = useState<
|
||||
@@ -403,11 +427,11 @@ export default function Sidebar() {
|
||||
);
|
||||
|
||||
const addProjectFromPath = useCallback(
|
||||
async (rawCwd: string) => {
|
||||
async (rawCwd: string): Promise<{ ok: boolean; error?: string }> => {
|
||||
const cwd = rawCwd.trim();
|
||||
if (!cwd || isAddingProject) return;
|
||||
if (!cwd || isAddingProject) return { ok: false };
|
||||
const api = readNativeApi();
|
||||
if (!api) return;
|
||||
if (!api) return { ok: false, error: "Native API not available." };
|
||||
|
||||
setIsAddingProject(true);
|
||||
const finishAddingProject = () => {
|
||||
@@ -421,7 +445,7 @@ export default function Sidebar() {
|
||||
if (existing) {
|
||||
focusMostRecentThreadForProject(existing.id);
|
||||
finishAddingProject();
|
||||
return;
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
const projectId = newProjectId();
|
||||
@@ -453,9 +477,10 @@ export default function Sidebar() {
|
||||
} else {
|
||||
setAddProjectError(description);
|
||||
}
|
||||
return;
|
||||
return { ok: false, error: description };
|
||||
}
|
||||
finishAddingProject();
|
||||
return { ok: true };
|
||||
},
|
||||
[
|
||||
focusMostRecentThreadForProject,
|
||||
@@ -472,6 +497,26 @@ export default function Sidebar() {
|
||||
};
|
||||
|
||||
const canAddProject = newCwd.trim().length > 0 && !isAddingProject;
|
||||
const newProjectBasePath = appSettings.newProjectBasePath.trim();
|
||||
|
||||
const cancelAddProjectMenuClose = useCallback(() => {
|
||||
if (addProjectMenuCloseTimerRef.current === null) return;
|
||||
window.clearTimeout(addProjectMenuCloseTimerRef.current);
|
||||
addProjectMenuCloseTimerRef.current = null;
|
||||
}, []);
|
||||
|
||||
const openAddProjectMenu = useCallback(() => {
|
||||
cancelAddProjectMenuClose();
|
||||
setIsAddProjectMenuOpen(true);
|
||||
}, [cancelAddProjectMenuClose]);
|
||||
|
||||
const scheduleAddProjectMenuClose = useCallback(() => {
|
||||
cancelAddProjectMenuClose();
|
||||
addProjectMenuCloseTimerRef.current = window.setTimeout(() => {
|
||||
setIsAddProjectMenuOpen(false);
|
||||
addProjectMenuCloseTimerRef.current = null;
|
||||
}, 120);
|
||||
}, [cancelAddProjectMenuClose]);
|
||||
|
||||
const handlePickFolder = async () => {
|
||||
const api = readNativeApi();
|
||||
@@ -492,6 +537,7 @@ export default function Sidebar() {
|
||||
};
|
||||
|
||||
const handleStartAddProject = () => {
|
||||
setIsAddProjectMenuOpen(false);
|
||||
setAddProjectError(null);
|
||||
if (shouldBrowseForProjectImmediately) {
|
||||
void handlePickFolder();
|
||||
@@ -500,6 +546,110 @@ export default function Sidebar() {
|
||||
setAddingProject((prev) => !prev);
|
||||
};
|
||||
|
||||
const closeCreateProjectDialog = useCallback((open: boolean) => {
|
||||
setIsCreateProjectDialogOpen(open);
|
||||
if (!open) {
|
||||
setCreateProjectDirectoryPath("");
|
||||
setNewProjectDirectoryName("");
|
||||
setCreateProjectDirectoryError(null);
|
||||
setIsCreatingProjectDirectory(false);
|
||||
setIsPickingCreateProjectDirectoryPath(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleStartCreateProjectDirectory = useCallback(() => {
|
||||
setIsAddProjectMenuOpen(false);
|
||||
setAddProjectError(null);
|
||||
setCreateProjectDirectoryPath(newProjectBasePath);
|
||||
setNewProjectDirectoryName("");
|
||||
setCreateProjectDirectoryError(null);
|
||||
setIsCreateProjectDialogOpen(true);
|
||||
|
||||
if (newProjectBasePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
const api = readNativeApi();
|
||||
if (!api) {
|
||||
return;
|
||||
}
|
||||
|
||||
void api.dialogs.getDocumentsPath().then((documentsPath) => {
|
||||
if (!documentsPath) return;
|
||||
setCreateProjectDirectoryPath((current) =>
|
||||
current.trim().length > 0 ? current : documentsPath,
|
||||
);
|
||||
});
|
||||
}, [newProjectBasePath]);
|
||||
|
||||
const handlePickCreateProjectDirectoryPath = useCallback(async () => {
|
||||
const api = readNativeApi();
|
||||
if (!api || isPickingCreateProjectDirectoryPath) return;
|
||||
|
||||
setIsPickingCreateProjectDirectoryPath(true);
|
||||
try {
|
||||
const pickedPath = await api.dialogs.pickFolder();
|
||||
if (pickedPath) {
|
||||
setCreateProjectDirectoryPath(pickedPath);
|
||||
setCreateProjectDirectoryError(null);
|
||||
}
|
||||
} finally {
|
||||
setIsPickingCreateProjectDirectoryPath(false);
|
||||
}
|
||||
}, [isPickingCreateProjectDirectoryPath]);
|
||||
|
||||
const handleCreateProjectDirectory = useCallback(async () => {
|
||||
const basePath = createProjectDirectoryPath.trim();
|
||||
const relativePath = newProjectDirectoryName.trim();
|
||||
if (!basePath || !relativePath || isCreatingProjectDirectory || isAddingProject) {
|
||||
if (!basePath) {
|
||||
setCreateProjectDirectoryError("Enter a directory path.");
|
||||
}
|
||||
if (!relativePath) {
|
||||
setCreateProjectDirectoryError("Enter a directory name.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const api = readNativeApi();
|
||||
if (!api) return;
|
||||
|
||||
setIsCreatingProjectDirectory(true);
|
||||
setCreateProjectDirectoryError(null);
|
||||
|
||||
try {
|
||||
const result = await api.projects.createDirectory({
|
||||
cwd: basePath,
|
||||
relativePath,
|
||||
});
|
||||
const addedProject = await addProjectFromPath(result.absolutePath);
|
||||
if (!addedProject.ok) {
|
||||
setCreateProjectDirectoryError(addedProject.error ?? "Unable to open the new project.");
|
||||
setIsCreatingProjectDirectory(false);
|
||||
return;
|
||||
}
|
||||
closeCreateProjectDialog(false);
|
||||
} catch (error) {
|
||||
setCreateProjectDirectoryError(
|
||||
error instanceof Error ? error.message : "Unable to create the directory.",
|
||||
);
|
||||
setIsCreatingProjectDirectory(false);
|
||||
}
|
||||
}, [
|
||||
addProjectFromPath,
|
||||
closeCreateProjectDialog,
|
||||
createProjectDirectoryPath,
|
||||
isAddingProject,
|
||||
isCreatingProjectDirectory,
|
||||
newProjectDirectoryName,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
cancelAddProjectMenuClose();
|
||||
};
|
||||
}, [cancelAddProjectMenuClose]);
|
||||
|
||||
const cancelRename = useCallback(() => {
|
||||
setRenamingThreadId(null);
|
||||
renamingInputRef.current = null;
|
||||
@@ -1232,28 +1382,59 @@ export default function Sidebar() {
|
||||
<span className="text-[10px] font-medium uppercase tracking-wider text-muted-foreground/60">
|
||||
Projects
|
||||
</span>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
aria-label={shouldShowProjectPathEntry ? "Cancel add project" : "Add project"}
|
||||
aria-pressed={shouldShowProjectPathEntry}
|
||||
className="inline-flex size-5 cursor-pointer items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-accent hover:text-foreground"
|
||||
onClick={handleStartAddProject}
|
||||
<div onMouseEnter={openAddProjectMenu} onMouseLeave={scheduleAddProjectMenuClose}>
|
||||
<Menu open={isAddProjectMenuOpen} onOpenChange={setIsAddProjectMenuOpen}>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Add project"
|
||||
aria-expanded={isAddProjectMenuOpen}
|
||||
className="inline-flex size-5 cursor-pointer items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-accent hover:text-foreground"
|
||||
onClick={() => setIsAddProjectMenuOpen((open) => !open)}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PlusIcon
|
||||
className={`size-3.5 transition-transform duration-150 ${
|
||||
isAddProjectMenuOpen || shouldShowProjectPathEntry ? "rotate-90" : "rotate-0"
|
||||
}`}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PlusIcon
|
||||
className={`size-3.5 transition-transform duration-150 ${
|
||||
shouldShowProjectPathEntry ? "rotate-45" : "rotate-0"
|
||||
}`}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="right">
|
||||
{shouldShowProjectPathEntry ? "Cancel add project" : "Add project"}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
</MenuTrigger>
|
||||
<MenuPopup
|
||||
align="end"
|
||||
className="w-64"
|
||||
onMouseEnter={openAddProjectMenu}
|
||||
onMouseLeave={scheduleAddProjectMenuClose}
|
||||
>
|
||||
<MenuItem className="items-start py-2.5" onClick={handleStartAddProject}>
|
||||
<FolderOpenIcon className="mt-0.5 size-4" />
|
||||
<span className="flex flex-col gap-0.5">
|
||||
<span className="text-sm font-medium text-foreground">
|
||||
Open existing directory
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Add a project from a folder you already have.
|
||||
</span>
|
||||
</span>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
className="items-start py-2.5"
|
||||
onClick={handleStartCreateProjectDirectory}
|
||||
>
|
||||
<FolderPlusIcon className="mt-0.5 size-4" />
|
||||
<span className="flex flex-col gap-0.5">
|
||||
<span className="text-sm font-medium text-foreground">
|
||||
Create new empty directory
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Make a fresh folder inside your default project path.
|
||||
</span>
|
||||
</span>
|
||||
</MenuItem>
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{shouldShowProjectPathEntry && (
|
||||
@@ -1702,6 +1883,102 @@ export default function Sidebar() {
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarFooter>
|
||||
<Dialog open={isCreateProjectDialogOpen} onOpenChange={closeCreateProjectDialog}>
|
||||
<DialogPopup>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create new empty directory</DialogTitle>
|
||||
<DialogDescription>
|
||||
Choose where the new folder should live, then name the project and T3 Code will open
|
||||
it right away.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogPanel className="space-y-5 pt-0" scrollFade={false}>
|
||||
<div className="space-y-2">
|
||||
<span className="text-xs font-medium text-foreground">Directory path</span>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={createProjectDirectoryPath}
|
||||
onChange={(event) => {
|
||||
setCreateProjectDirectoryPath(event.target.value);
|
||||
if (createProjectDirectoryError) {
|
||||
setCreateProjectDirectoryError(null);
|
||||
}
|
||||
}}
|
||||
placeholder="/Users/you/Documents"
|
||||
spellCheck={false}
|
||||
autoFocus
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => void handlePickCreateProjectDirectoryPath()}
|
||||
disabled={isPickingCreateProjectDirectoryPath}
|
||||
>
|
||||
{isPickingCreateProjectDirectoryPath ? "Selecting..." : "Select"}
|
||||
</Button>
|
||||
</div>
|
||||
{!newProjectBasePath && createProjectDirectoryPath.trim() ? (
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
updateSettings({
|
||||
newProjectBasePath: createProjectDirectoryPath.trim(),
|
||||
})
|
||||
}
|
||||
>
|
||||
Set as default
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<label htmlFor="new-project-directory-name" className="block space-y-2">
|
||||
<span className="text-xs font-medium text-foreground">Project name</span>
|
||||
<Input
|
||||
id="new-project-directory-name"
|
||||
value={newProjectDirectoryName}
|
||||
onChange={(event) => {
|
||||
setNewProjectDirectoryName(event.target.value);
|
||||
if (createProjectDirectoryError) {
|
||||
setCreateProjectDirectoryError(null);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter") return;
|
||||
event.preventDefault();
|
||||
void handleCreateProjectDirectory();
|
||||
}}
|
||||
placeholder="my-new-project"
|
||||
spellCheck={false}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{createProjectDirectoryError ? (
|
||||
<p className="text-xs text-destructive">{createProjectDirectoryError}</p>
|
||||
) : null}
|
||||
</DialogPanel>
|
||||
<DialogFooter variant="bare" className="pt-0">
|
||||
<Button type="button" variant="outline" onClick={() => closeCreateProjectDialog(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={() => void handleCreateProjectDirectory()}
|
||||
disabled={
|
||||
!createProjectDirectoryPath.trim() ||
|
||||
!newProjectDirectoryName.trim() ||
|
||||
isCreatingProjectDirectory ||
|
||||
isAddingProject
|
||||
}
|
||||
>
|
||||
{isCreatingProjectDirectory || isAddingProject ? "Creating..." : "OK"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -164,45 +164,32 @@ function SelectPopup({
|
||||
);
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
hideIndicator = false,
|
||||
...props
|
||||
}: SelectPrimitive.Item.Props & {
|
||||
hideIndicator?: boolean;
|
||||
}) {
|
||||
function SelectItem({ className, children, ...props }: SelectPrimitive.Item.Props) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
className={cn(
|
||||
"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default items-center gap-2 rounded-sm py-1 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
hideIndicator ? "grid-cols-[1fr] ps-3 pe-3" : "grid-cols-[1rem_1fr] ps-2 pe-4",
|
||||
"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
className,
|
||||
)}
|
||||
data-slot="select-item"
|
||||
{...props}
|
||||
>
|
||||
{hideIndicator ? null : (
|
||||
<SelectPrimitive.ItemIndicator className="col-start-1" data-slot="select-item-indicator">
|
||||
<svg
|
||||
fill="none"
|
||||
height="24"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
viewBox="0 0 24 24"
|
||||
width="24"
|
||||
xmlns="http://www.w3.org/1500/svg"
|
||||
>
|
||||
<path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
|
||||
</svg>
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
)}
|
||||
<SelectPrimitive.ItemText
|
||||
className={cn("min-w-0", hideIndicator ? "col-start-1" : "col-start-2")}
|
||||
data-slot="select-item-text"
|
||||
>
|
||||
<SelectPrimitive.ItemIndicator className="col-start-1">
|
||||
<svg
|
||||
fill="none"
|
||||
height="24"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
viewBox="0 0 24 24"
|
||||
width="24"
|
||||
xmlns="http://www.w3.org/1500/svg"
|
||||
>
|
||||
<path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
|
||||
</svg>
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
<SelectPrimitive.ItemText className="col-start-2 min-w-0">
|
||||
{children}
|
||||
</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -10,14 +10,11 @@ import { serverConfigQueryOptions } from "../lib/serverReactQuery";
|
||||
import { resolveShortcutCommand } from "../keybindings";
|
||||
import { selectThreadTerminalState, useTerminalStateStore } from "../terminalStateStore";
|
||||
import { useThreadSelectionStore } from "../threadSelectionStore";
|
||||
import { Sidebar, SidebarProvider } from "~/components/ui/sidebar";
|
||||
import { resolveSidebarNewThreadEnvMode } from "~/components/Sidebar.logic";
|
||||
import { useAppSettings } from "~/appSettings";
|
||||
import { Sidebar, SidebarProvider, SidebarRail } from "~/components/ui/sidebar";
|
||||
|
||||
const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = [];
|
||||
const THREAD_SIDEBAR_WIDTH_STORAGE_KEY = "chat_thread_sidebar_width";
|
||||
const THREAD_SIDEBAR_MIN_WIDTH = 13 * 16;
|
||||
const THREAD_MAIN_CONTENT_MIN_WIDTH = 40 * 16;
|
||||
|
||||
function ChatRouteGlobalShortcuts() {
|
||||
const clearSelection = useThreadSelectionStore((state) => state.clearSelection);
|
||||
@@ -119,15 +116,8 @@ function ChatRouteLayout() {
|
||||
side="left"
|
||||
collapsible="offcanvas"
|
||||
className="border-r border-border bg-card text-foreground"
|
||||
resizable={{
|
||||
minWidth: THREAD_SIDEBAR_MIN_WIDTH,
|
||||
shouldAcceptWidth: ({ nextWidth, wrapper }) =>
|
||||
wrapper.clientWidth - nextWidth >= THREAD_MAIN_CONTENT_MIN_WIDTH,
|
||||
storageKey: THREAD_SIDEBAR_WIDTH_STORAGE_KEY,
|
||||
}}
|
||||
>
|
||||
<ThreadSidebar />
|
||||
<SidebarRail />
|
||||
</Sidebar>
|
||||
<Outlet />
|
||||
</SidebarProvider>
|
||||
|
||||
@@ -320,6 +320,42 @@ describe("wsNativeApi", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("forwards workspace directory creation to the websocket project method", async () => {
|
||||
requestMock.mockResolvedValue({
|
||||
relativePath: "sandbox",
|
||||
absolutePath: "/tmp/project/sandbox",
|
||||
});
|
||||
const { createWsNativeApi } = await import("./wsNativeApi");
|
||||
|
||||
const api = createWsNativeApi();
|
||||
await api.projects.createDirectory({
|
||||
cwd: "/tmp/project",
|
||||
relativePath: "sandbox",
|
||||
});
|
||||
|
||||
expect(requestMock).toHaveBeenCalledWith(WS_METHODS.projectsCreateDirectory, {
|
||||
cwd: "/tmp/project",
|
||||
relativePath: "sandbox",
|
||||
});
|
||||
});
|
||||
|
||||
it("reads the desktop documents path when the bridge is available", async () => {
|
||||
const getDocumentsPath = vi.fn().mockResolvedValue("/Users/davis/Documents");
|
||||
Object.defineProperty(getWindowForTest(), "desktopBridge", {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: {
|
||||
getDocumentsPath,
|
||||
},
|
||||
});
|
||||
|
||||
const { createWsNativeApi } = await import("./wsNativeApi");
|
||||
const api = createWsNativeApi();
|
||||
|
||||
await expect(api.dialogs.getDocumentsPath()).resolves.toBe("/Users/davis/Documents");
|
||||
expect(getDocumentsPath).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("forwards full-thread diff requests to the orchestration websocket method", async () => {
|
||||
requestMock.mockResolvedValue({ diff: "patch" });
|
||||
const { createWsNativeApi } = await import("./wsNativeApi");
|
||||
|
||||
@@ -94,6 +94,10 @@ export function createWsNativeApi(): NativeApi {
|
||||
if (!window.desktopBridge) return null;
|
||||
return window.desktopBridge.pickFolder();
|
||||
},
|
||||
getDocumentsPath: async () => {
|
||||
if (!window.desktopBridge) return null;
|
||||
return window.desktopBridge.getDocumentsPath();
|
||||
},
|
||||
confirm: async (message) => {
|
||||
if (window.desktopBridge) {
|
||||
return window.desktopBridge.confirm(message);
|
||||
@@ -114,6 +118,7 @@ export function createWsNativeApi(): NativeApi {
|
||||
projects: {
|
||||
searchEntries: (input) => transport.request(WS_METHODS.projectsSearchEntries, input),
|
||||
writeFile: (input) => transport.request(WS_METHODS.projectsWriteFile, input),
|
||||
createDirectory: (input) => transport.request(WS_METHODS.projectsCreateDirectory, input),
|
||||
},
|
||||
shell: {
|
||||
openInEditor: (cwd, editor) =>
|
||||
|
||||
@@ -19,6 +19,8 @@ import type {
|
||||
GitStatusResult,
|
||||
} from "./git";
|
||||
import type {
|
||||
ProjectCreateDirectoryInput,
|
||||
ProjectCreateDirectoryResult,
|
||||
ProjectSearchEntriesInput,
|
||||
ProjectSearchEntriesResult,
|
||||
ProjectWriteFileInput,
|
||||
@@ -97,6 +99,7 @@ export interface DesktopUpdateActionResult {
|
||||
export interface DesktopBridge {
|
||||
getWsUrl: () => string | null;
|
||||
pickFolder: () => Promise<string | null>;
|
||||
getDocumentsPath: () => Promise<string | null>;
|
||||
confirm: (message: string) => Promise<boolean>;
|
||||
setTheme: (theme: DesktopTheme) => Promise<void>;
|
||||
showContextMenu: <T extends string>(
|
||||
@@ -114,6 +117,7 @@ export interface DesktopBridge {
|
||||
export interface NativeApi {
|
||||
dialogs: {
|
||||
pickFolder: () => Promise<string | null>;
|
||||
getDocumentsPath: () => Promise<string | null>;
|
||||
confirm: (message: string) => Promise<boolean>;
|
||||
};
|
||||
terminal: {
|
||||
@@ -128,6 +132,7 @@ export interface NativeApi {
|
||||
projects: {
|
||||
searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
|
||||
writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
|
||||
createDirectory: (input: ProjectCreateDirectoryInput) => Promise<ProjectCreateDirectoryResult>;
|
||||
};
|
||||
shell: {
|
||||
openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
|
||||
|
||||
@@ -37,3 +37,15 @@ export const ProjectWriteFileResult = Schema.Struct({
|
||||
relativePath: TrimmedNonEmptyString,
|
||||
});
|
||||
export type ProjectWriteFileResult = typeof ProjectWriteFileResult.Type;
|
||||
|
||||
export const ProjectCreateDirectoryInput = Schema.Struct({
|
||||
cwd: TrimmedNonEmptyString,
|
||||
relativePath: TrimmedNonEmptyString.check(Schema.isMaxLength(PROJECT_WRITE_FILE_PATH_MAX_LENGTH)),
|
||||
});
|
||||
export type ProjectCreateDirectoryInput = typeof ProjectCreateDirectoryInput.Type;
|
||||
|
||||
export const ProjectCreateDirectoryResult = Schema.Struct({
|
||||
relativePath: TrimmedNonEmptyString,
|
||||
absolutePath: TrimmedNonEmptyString,
|
||||
});
|
||||
export type ProjectCreateDirectoryResult = typeof ProjectCreateDirectoryResult.Type;
|
||||
@@ -34,7 +34,11 @@ import {
|
||||
TerminalWriteInput,
|
||||
} from "./terminal";
|
||||
import { KeybindingRule } from "./keybindings";
|
||||
import { ProjectSearchEntriesInput, ProjectWriteFileInput } from "./project";
|
||||
import {
|
||||
ProjectCreateDirectoryInput,
|
||||
ProjectSearchEntriesInput,
|
||||
ProjectWriteFileInput,
|
||||
} from "./project";
|
||||
import { OpenInEditorInput } from "./editor";
|
||||
import { ServerConfigUpdatedPayload } from "./server";
|
||||
|
||||
@@ -47,6 +51,7 @@ export const WS_METHODS = {
|
||||
projectsRemove: "projects.remove",
|
||||
projectsSearchEntries: "projects.searchEntries",
|
||||
projectsWriteFile: "projects.writeFile",
|
||||
projectsCreateDirectory: "projects.createDirectory",
|
||||
|
||||
// Shell methods
|
||||
shellOpenInEditor: "shell.openInEditor",
|
||||
@@ -111,6 +116,7 @@ const WebSocketRequestBody = Schema.Union([
|
||||
// Project Search
|
||||
tagRequestBody(WS_METHODS.projectsSearchEntries, ProjectSearchEntriesInput),
|
||||
tagRequestBody(WS_METHODS.projectsWriteFile, ProjectWriteFileInput),
|
||||
tagRequestBody(WS_METHODS.projectsCreateDirectory, ProjectCreateDirectoryInput),
|
||||
|
||||
// Shell methods
|
||||
tagRequestBody(WS_METHODS.shellOpenInEditor, OpenInEditorInput),
|
||||
|
||||
Reference in new issue
Block a user