Skip to content
Open
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
12 changes: 12 additions & 0 deletions packages/server/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ export interface FileSystemFileContentResponse {
encoding: "utf-8" | "base64"
}

export interface DetectPathExistingInRecentRequest {
currentPath: string
recentPaths: RecentFolder[]
}

export interface DetectPathExistingInRecentResponse {
exists: boolean
currentPath: string
currentReal: string
foundResult: RecentFolder | undefined
}

export interface ConfigFileDescriptor {
id: string
label: string
Expand Down
42 changes: 42 additions & 0 deletions packages/server/src/server/routes/filesystem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FastifyInstance } from "fastify"
import { z } from "zod"
import fs from "node:fs/promises"
import { FileSystemBrowser } from "../../filesystem/browser"
import { RecentFolder, RecentFolderSchema } from '../../config/schema'

interface RouteDeps {
fileSystemBrowser: FileSystemBrowser
Expand All @@ -21,6 +23,11 @@ const FilesystemFileContentQuerySchema = z.object({
encoding: z.enum(["utf-8", "base64"]).optional(),
})

const FilesystemFileRealpathQuerySchema = z.object({
currentPath: z.string(),
recentFolders: z.array(RecentFolderSchema).default([]),
})

export function registerFilesystemRoutes(app: FastifyInstance, deps: RouteDeps) {
app.get("/api/filesystem", async (request, reply) => {
const query = FilesystemQuerySchema.parse(request.query ?? {})
Expand Down Expand Up @@ -66,4 +73,39 @@ export function registerFilesystemRoutes(app: FastifyInstance, deps: RouteDeps)
reply.code(400).type("text/plain").send((error as Error).message)
}
})

app.post("/api/filesystem/detect-path-existing-in-recent", async (request, reply) => {
const query = FilesystemFileRealpathQuerySchema.parse(request.body ?? {})

try {
const currentPath = query.currentPath
const currentReal = await fs.realpath(currentPath)

let exists = false
let foundResult: RecentFolder | undefined

const fn = async (folder: RecentFolder) => {
await fs.access(folder.path, fs.constants.F_OK)
return currentReal === await fs.realpath(folder.path)
}

for (const folder of query.recentFolders) {
if (currentPath === folder.path || currentReal === folder.path || await fn(folder).catch(() => false)) {
exists = true
foundResult = folder
break
}
}

return {
exists,
currentPath,
currentReal,
foundResult
}
} catch (error) {
reply.code(400).type("text/plain").send((error as Error).message)
}
})

}
18 changes: 13 additions & 5 deletions packages/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
showFolderSelection,
setShowFolderSelection,
} from "./stores/ui"
import { useConfig } from "./stores/preferences"
import { recentFolders, useConfig } from "./stores/preferences"
import {
createInstance,
getExistingInstanceForFolder,
Expand Down Expand Up @@ -70,6 +70,7 @@ import {
selectInstanceTab,
selectSidecarTab,
} from "./stores/app-tabs"
import { serverApi } from './lib/api-client'

const log = getLogger("actions")

Expand Down Expand Up @@ -268,6 +269,13 @@ const App: Component = () => {
if (!folderPath) {
return
}

const detectResult = await serverApi.detectPathExistingInRecent(folderPath, recentFolders())

if (detectResult?.exists) {
folderPath = detectResult.foundResult.path
}

const selectedBinary = binaryPath || serverSettings().opencodeBinary || "opencode"
recordWorkspaceLaunch(folderPath, selectedBinary)
clearLaunchError()
Expand Down Expand Up @@ -485,7 +493,7 @@ const App: Component = () => {
const tauriBridge = (window as { __TAURI__?: { event?: { listen: (event: string, handler: (event: { payload: unknown }) => void) => Promise<() => void> } } }).__TAURI__
if (tauriBridge?.event) {
let unlistenMenu: (() => void) | null = null

tauriBridge.event.listen("menu:newInstance", () => {
handleNewInstanceRequest()
}).then((unlisten) => {
Expand Down Expand Up @@ -527,7 +535,7 @@ const App: Component = () => {
<p class="text-xs font-medium text-muted uppercase tracking-wide mb-1">{t("app.launchError.binaryPathLabel")}</p>
<p class="text-sm font-mono text-primary break-all">{launchErrorPath()}</p>
</div>

<Show when={launchErrorMessage()}>
<div class="rounded-lg border border-base bg-surface-secondary p-4 flex flex-col gap-2 flex-1 min-h-0">
<p class="text-xs font-medium text-muted uppercase tracking-wide">{t("app.launchError.errorOutputLabel")}</p>
Expand Down Expand Up @@ -652,7 +660,7 @@ const App: Component = () => {
</div>
</div>
</Show>

<SettingsScreen />
<SideCarPickerDialog open={sidecarPickerOpen()} onClose={() => setSidecarPickerOpen(false)} onOpenSidecar={handleOpenSidecar} />
<Show when={alreadyOpenFolderChoice()}>
Expand All @@ -679,7 +687,7 @@ const App: Component = () => {
</Dialog.Portal>
</Dialog>
</Show>

<AlertDialog />

<Toaster
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/src/lib/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import type {
WorktreeCreateRequest,
WorktreeGitDiffResponse,
WorktreeGitStatusResponse,
RecentFolder,
DetectPathExistingInRecentResponse,
} from "../../../server/src/api-types"
import { getClientIdentity } from "./client-identity"
import { getLogger } from "./logger"
Expand Down Expand Up @@ -481,6 +483,12 @@ export const serverApi = {
}
return request<FileSystemFileContentResponse>(`/api/filesystem/files/content?${params.toString()}`)
},
detectPathExistingInRecent(currentPath: string, recentFolders: RecentFolder[]): Promise<DetectPathExistingInRecentResponse> {
return request<DetectPathExistingInRecentResponse>(`/api/filesystem/detect-path-existing-in-recent`, {
method: "POST",
body: JSON.stringify({ currentPath, recentFolders }),
})
},
readInstanceData(id: string): Promise<InstanceData> {
return request<InstanceData>(`/api/storage/instances/${encodeURIComponent(id)}`)
},
Expand Down
Loading