Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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),
Expand Down
43 changes: 43 additions & 0 deletions apps/server/src/wsServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
53 changes: 53 additions & 0 deletions apps/server/src/wsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
FileSystem,
Layer,
Path,
PlatformError,
Ref,
Result,
Schema,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/appSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ describe("AppSettingsSchema", () => {
).toMatchObject({
codexBinaryPath: "/usr/local/bin/codex",
codexHomePath: "",
newProjectBasePath: "",
defaultThreadEnvMode: "local",
confirmThreadDelete: false,
enableAssistantStreaming: false,
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/appSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const withDefaults =
export const AppSettingsSchema = Schema.Struct({
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)),
Expand Down
Loading