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 @@ -150,6 +150,7 @@
"@xterm/addon-webgl": "0.20.0-beta.194",
"@xterm/headless": "6.1.0-beta.195",
"@xterm/xterm": "6.1.0-beta.195",
"@xyflow/react": "^12.10.2",
"ai": "^6.0.0",
"ansi_up": "^6.0.6",
"better-auth": "1.5.6",
Expand All @@ -170,6 +171,7 @@
"dotenv": "^17.3.1",
"drizzle-orm": "0.45.1",
"electron-updater": "^6.7.3",
"elkjs": "^0.11.1",
"exceljs": "^4.4.0",
"execa": "^9.6.0",
"express": "^5.1.0",
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/lib/trpc/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createNotificationsRouter } from "./notifications";
import { createPermissionsRouter } from "./permissions";
import { createPortsRouter } from "./ports";
import { createProjectsRouter } from "./projects";
import { createReferenceGraphRouter } from "./reference-graph";
import { createResourceMetricsRouter } from "./resource-metrics";
import { createRingtoneRouter } from "./ringtone";
import { createSettingsRouter } from "./settings";
Expand Down Expand Up @@ -63,6 +64,7 @@ export const createAppRouter = (
resourceMetrics: createResourceMetricsRouter(),
menu: createMenuRouter(),
languageServices: createLanguageServicesRouter(),
referenceGraph: createReferenceGraphRouter(),
external: createExternalRouter(),
settings: createSettingsRouter(),
config: createConfigRouter(),
Expand Down
74 changes: 74 additions & 0 deletions apps/desktop/src/lib/trpc/routers/reference-graph/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import path from "node:path";
import { TRPCError } from "@trpc/server";
import { buildReferenceGraph } from "main/lib/reference-graph";
import { z } from "zod";
import { publicProcedure, router } from "../..";
import { getWorkspace } from "../workspaces/utils/db-helpers";
import { getWorkspacePath } from "../workspaces/utils/worktree";

function resolveWorkspacePath(workspaceId: string): string {
const workspace = getWorkspace(workspaceId);
if (!workspace) {
throw new TRPCError({
code: "NOT_FOUND",
message: `Workspace ${workspaceId} not found`,
});
}

const workspacePath = getWorkspacePath(workspace);
if (!workspacePath) {
throw new TRPCError({
code: "PRECONDITION_FAILED",
message: `Workspace ${workspaceId} has no filesystem path`,
});
}

return workspacePath;
}

export const createReferenceGraphRouter = () => {
return router({
buildGraph: publicProcedure
.input(
z.object({
workspaceId: z.string(),
absolutePath: z.string(),
languageId: z.string(),
Comment thread
MocA-Love marked this conversation as resolved.
line: z.number().int().positive(),
column: z.number().int().positive(),
maxDepth: z.number().int().min(1).max(10).optional(),
maxNodes: z.number().int().min(1).max(500).optional(),
excludePatterns: z.array(z.string()).optional(),
}),
)
.mutation(async ({ input }) => {
const workspacePath = resolveWorkspacePath(input.workspaceId);

// Ensure absolutePath is within the workspace (prevent path traversal)
const resolved = path.resolve(input.absolutePath);
if (
!resolved.startsWith(workspacePath + path.sep) &&
resolved !== workspacePath
) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "absolutePath must be within the workspace",
});
}

const graph = await buildReferenceGraph({
workspaceId: input.workspaceId,
workspacePath,
absolutePath: input.absolutePath,
languageId: input.languageId,
line: input.line,
column: input.column,
maxDepth: input.maxDepth,
maxNodes: input.maxNodes,
excludePatterns: input.excludePatterns,
});

return graph;
}),
});
};
26 changes: 26 additions & 0 deletions apps/desktop/src/lib/trpc/routers/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,32 @@ export const createSettingsRouter = () => {
return { success: true };
}),

getReferenceGraph: publicProcedure.query(() => {
const row = getSettings();
return {
enabled: row.referenceGraphEnabled ?? true,
};
}),

setReferenceGraph: publicProcedure
.input(
z.object({
enabled: z.boolean(),
}),
)
.mutation(({ input }) => {
localDb
.insert(settings)
.values({ id: 1, referenceGraphEnabled: input.enabled })
.onConflictDoUpdate({
target: settings.id,
set: { referenceGraphEnabled: input.enabled },
})
.run();

return { success: true };
}),

// TODO: remove telemetry procedures once telemetry_enabled column is dropped
getTelemetryEnabled: publicProcedure.query(() => {
return true;
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop/src/lib/trpc/routers/ui-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const paneSchema = z.object({
"database-explorer",
"action-logs",
"vscode-extension",
"reference-graph",
]),
name: z.string(),
isNew: z.boolean().optional(),
Expand Down Expand Up @@ -125,6 +126,14 @@ const paneSchema = z.object({
worktreePath: z.string(),
})
.optional(),
referenceGraph: z
.object({
absolutePath: z.string(),
languageId: z.string(),
line: z.number(),
column: z.number(),
})
.optional(),
workspaceRun: z
.object({
workspaceId: z.string(),
Expand Down
Loading
Loading