Skip to content
Merged
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
2 changes: 2 additions & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"fast-glob": "^3.3.3",
"framer-motion": "^12.23.24",
"http-proxy": "^1.18.1",
"lodash": "^4.17.21",
"lowdb": "^7.0.1",
"nanoid": "^5.1.6",
"node-pty": "1.1.0-beta30",
Expand All @@ -75,6 +76,7 @@
"@superset/ui": "workspace:*",
"@tailwindcss/vite": "^4.0.9",
"@types/http-proxy": "^1.17.17",
"@types/lodash": "^4.17.20",
"@types/node": "^24.9.1",
"@types/react": "^19.1.11",
"@types/react-dom": "^19.1.7",
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/trpc/routers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { BrowserWindow } from "electron";
import { router } from "..";
import { createWindowRouter } from "./window";
import { createProjectsRouter } from "./projects";
import { createWorkspacesRouter } from "./workspaces";
import { createTerminalRouter } from "./terminal";
import { createWindowRouter } from "./window";
import { createWorkspacesRouter } from "./workspaces";

/**
* Main application router
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/trpc/routers/projects/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { createProjectsRouter } from "./projects";
export type { ProjectsRouter } from "./projects";
export { createProjectsRouter } from "./projects";
8 changes: 4 additions & 4 deletions apps/desktop/src/lib/trpc/routers/projects/projects.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { dialog } from "electron";
import type { BrowserWindow } from "electron";
import { basename } from "node:path";
import type { BrowserWindow } from "electron";
import { dialog } from "electron";
import { nanoid } from "nanoid";
import { z } from "zod";
import { db } from "main/lib/db";
import type { Project } from "main/lib/db/schemas";
import { publicProcedure, router } from "../..";
import { db } from "../../../../main/lib/db";
import type { Project } from "../../../../main/lib/db/schemas";
import { getGitRoot } from "../workspaces/utils/git";
import { assignRandomColor } from "./utils/colors";

Expand Down
146 changes: 88 additions & 58 deletions apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,144 @@
import { observable } from "@trpc/server/observable";
import { z } from "zod";
import { db } from "main/lib/db";
import { terminalManager } from "main/lib/terminal-manager";
import { publicProcedure, router } from "../..";

/**
* Terminal router with mocked implementations
* TODO: Replace with actual terminal IPC implementation
* Terminal router using TerminalManager with node-pty
* Sessions are keyed by tabId and linked to workspaces for cwd resolution
*/
export const createTerminalRouter = () => {
// Mock terminal sessions storage
const terminalSessions = new Map<string, string>();

return router({
create: publicProcedure
createOrAttach: publicProcedure
.input(
z.object({
id: z.string().optional(),
tabId: z.string(),
workspaceId: z.string(),
cols: z.number().optional(),
rows: z.number().optional(),
cwd: z.string().optional(),
}),
)
.mutation(async ({ input }) => {
const terminalId = input.id || `terminal-${Date.now()}`;

// Mock: Initialize empty session
terminalSessions.set(terminalId, "");
const { tabId, workspaceId, cols, rows } = input;

console.log(`[Terminal] Created terminal: ${terminalId}`, {
cwd: input.cwd,
cols: input.cols,
rows: input.rows,
});
// Get workspace to determine cwd from worktree path
const workspace = db.data.workspaces.find((w) => w.id === workspaceId);
let cwd: string | undefined;

return terminalId;
}),
if (workspace) {
const worktree = db.data.worktrees.find(
(wt) => wt.id === workspace.worktreeId,
);
if (worktree) {
cwd = worktree.path;
}
}

getHistory: publicProcedure
.input(z.string())
.query(async ({ input: terminalId }) => {
// Mock: Return undefined for new terminals (triggers welcome message)
const history = terminalSessions.get(terminalId);

console.log(`[Terminal] Get history for: ${terminalId}`, {
hasHistory: !!history,
const result = terminalManager.createOrAttach({
tabId,
workspaceId,
cwd,
cols,
rows,
});

return history || undefined;
return {
tabId,
isNew: result.isNew,
scrollback: result.scrollback,
};
}),

executeCommand: publicProcedure
write: publicProcedure
.input(
z.object({
id: z.string(),
command: z.string(),
tabId: z.string(),
data: z.string(),
}),
)
.mutation(async ({ input }) => {
console.log(`[Terminal] Execute command on ${input.id}:`, input.command);

// Mock: Store command in history
const currentHistory = terminalSessions.get(input.id) || "";
terminalSessions.set(
input.id,
`${currentHistory}$ ${input.command}\r\n[MOCK] Command not yet implemented\r\n`,
);
terminalManager.write(input);
}),

resize: publicProcedure
.input(
z.object({
id: z.string(),
tabId: z.string(),
cols: z.number(),
rows: z.number(),
seq: z.number(),
seq: z.number().optional(),
}),
)
.mutation(async ({ input }) => {
console.log(`[Terminal] Resize ${input.id}:`, {
cols: input.cols,
rows: input.rows,
seq: input.seq,
});
terminalManager.resize(input);
}),

signal: publicProcedure
.input(
z.object({
id: z.string(),
signal: z.string(),
tabId: z.string(),
signal: z.string().optional(),
}),
)
.mutation(async ({ input }) => {
console.log(`[Terminal] Signal ${input.id}:`, input.signal);
terminalManager.signal(input);
}),

detach: publicProcedure
.input(z.string())
.mutation(async ({ input: terminalId }) => {
console.log(`[Terminal] Detach: ${terminalId}`);
// Mock: Keep session in memory for reconnection
kill: publicProcedure
.input(
z.object({
tabId: z.string(),
}),
)
.mutation(async ({ input }) => {
terminalManager.kill(input);
}),

scrollLines: publicProcedure
/**
* Detach from terminal (keep session alive)
*/
detach: publicProcedure
.input(
z.object({
id: z.string(),
amount: z.number(),
tabId: z.string(),
}),
)
.mutation(async ({ input }) => {
console.log(`[Terminal] Scroll ${input.id} by ${input.amount} lines`);
terminalManager.detach(input);
}),

getSession: publicProcedure
.input(z.string())
.query(async ({ input: tabId }) => {
return terminalManager.getSession(tabId);
}),

stream: publicProcedure
.input(z.string())
.subscription(({ input: tabId }) => {
return observable<
| { type: "data"; data: string }
| { type: "exit"; exitCode: number; signal?: number }
>((emit) => {
const onData = (data: string) => {
emit.next({ type: "data", data });
};

const onExit = (exitCode: number, signal?: number) => {
emit.next({ type: "exit", exitCode, signal });
emit.complete();
};

terminalManager.on(`data:${tabId}`, onData);
terminalManager.on(`exit:${tabId}`, onExit);

// Cleanup on unsubscribe
return () => {
terminalManager.off(`data:${tabId}`, onData);
terminalManager.off(`exit:${tabId}`, onExit);
};
});
}),
});
};
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/trpc/routers/workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { createWorkspacesRouter } from "./workspaces";
export type { WorkspacesRouter } from "./workspaces";
export { createWorkspacesRouter } from "./workspaces";
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import simpleGit from "simple-git";
import { join } from "node:path";
import { mkdir } from "node:fs/promises";
import { join } from "node:path";
import simpleGit from "simple-git";

export function generateBranchName(): string {
const adjectives = [
Expand Down
25 changes: 12 additions & 13 deletions apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { z } from "zod";
import { nanoid } from "nanoid";
import { join } from "node:path";
import { nanoid } from "nanoid";
import { z } from "zod";
import { db } from "main/lib/db";
import { publicProcedure, router } from "../..";
import { db } from "../../../../main/lib/db";
import {
generateBranchName,
createWorktree,
generateBranchName,
removeWorktree,
} from "./utils/git";

Expand All @@ -26,11 +26,7 @@ export const createWorkspacesRouter = () => {

const branch = generateBranchName();

const worktreePath = join(
project.mainRepoPath,
".superset",
branch,
);
const worktreePath = join(project.mainRepoPath, ".superset", branch);

await createWorktree(project.mainRepoPath, branch, worktreePath);

Expand Down Expand Up @@ -97,9 +93,7 @@ export const createWorkspacesRouter = () => {
}),

getAll: publicProcedure.query(() => {
return db.data.workspaces
.slice()
.sort((a, b) => a.tabOrder - b.tabOrder);
return db.data.workspaces.slice().sort((a, b) => a.tabOrder - b.tabOrder);
}),

getAllGrouped: publicProcedure.query(() => {
Expand All @@ -110,7 +104,12 @@ export const createWorkspacesRouter = () => {
const groupsMap = new Map<
string,
{
project: { id: string; name: string; color: string; tabOrder: number };
project: {
id: string;
name: string;
color: string;
tabOrder: number;
};
workspaces: Array<{
id: string;
projectId: string;
Expand Down
9 changes: 6 additions & 3 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from "node:path";
import { app } from "electron";
import { makeAppSetup } from "lib/electron-app/factories/app/setup";
import { initDb } from "./lib/db";
import { registerStorageHandlers } from "./lib/storage-ipcs";
import { terminalManager } from "./lib/terminal-manager";
import { MainWindow } from "./windows/main";
import { initDb } from "./lib/db";

// Protocol scheme for deep linking
const PROTOCOL_SCHEME = "superset";
Expand Down Expand Up @@ -37,6 +38,8 @@ registerStorageHandlers();

await makeAppSetup(() => MainWindow());

// Stop all periodic rescans when app is quitting
app.on("before-quit", async () => {});
// Clean up all terminals when app is quitting
app.on("before-quit", async () => {
terminalManager.cleanup();
});
})();
2 changes: 1 addition & 1 deletion apps/desktop/src/main/lib/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSONFilePreset } from "lowdb/node";
import { join } from "node:path";
import { app } from "electron";
import { JSONFilePreset } from "lowdb/node";
import type { Database } from "./schemas";
import { defaultDatabase } from "./schemas";

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/main/lib/storage-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Store from "electron-store";
import { homedir } from "node:os";
import { join } from "node:path";
import Store from "electron-store";

/**
* Electron store instance for persisting application state
Expand Down
Loading