feat(repo): add graphical folder picker for adding local repositories (#324)

* feat(repo): add graphical folder picker for adding local repositories

Previously, adding a local repository or scanning a folder in the
"Add Repository" dialog required typing an absolute filesystem path by
hand. This adds a navigable directory browser so users can select a
folder graphically instead.

Backend
- New shared Zod schemas (DirectoryEntry, BrowseDirectoryResponse,
  BrowseDirectoryRequest) exported via shared/types and shared/schemas.
- New env var REPO_BROWSE_ROOT plus getBrowseRootPath() helper. It is
  intentionally NOT defaulted to WORKSPACE_PATH: folder browsing is
  opt-in and only works when an administrator explicitly configures a
  root directory.
- New filesystem service (browseDirectory) that lists only directories
  (hidden entries filtered), flags Git repositories, and confines all
  access to the configured root:
    - 501 when REPO_BROWSE_ROOT is not configured
    - 403 on path traversal outside the root
    - 404 for missing directories, 400 when the target is a file
- New authenticated route GET /api/filesystem/browse, registered under
  the protected API group.

Frontend
- New api client browseDirectory() (uses fetchWrapper, so auth cookies
  are sent).
- New DirectoryPickerDialog: navigate into subfolders, go up a level,
  Git repos marked with an icon, and a "Select This Folder" action.
  Retries are disabled so a configuration error is not polled
  repeatedly.
- When browsing is disabled (501), the dialog shows a clear, actionable
  message telling the user to set REPO_BROWSE_ROOT and to enter the
  path manually in the meantime, instead of a generic error.
- AddRepoDialog gains a "Browse" button next to both the Local and
  Folder path inputs; the chosen path is written back into the active
  field.

Tests
- Service and route tests covering listing, Git-repo detection, hidden
  filtering, parent navigation, and the 400/403/404/501 error paths.

Security note: because there is no default root, the picker is inert
until REPO_BROWSE_ROOT is set, and it can never escape that root.

* fix(fs): reject symlink escapes in directory browse

Canonicalize root and requested path with fs.realpath() and gate on
path.relative() so symlinks inside REPO_BROWSE_ROOT pointing outside
are rejected with 403 before fs.stat/fs.readdir follow them. Handles
root '/' correctly. Adds regression test for symlink escape.

* fix(ui): make directory picker fill dialog height

Replace grid content-start packing with explicit grid-rows tracks so
the directory list grows to fill the dialog and scrolls while the
header, path, and footer stay fixed. Drops the ineffective flex-1
from the grid child on the scroll container.

---------

Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
Alexander DrewekeandChris Scott authored and GitHub committed 2026-07-26 21:12:13 -04:00
1 parent 8d5102dc90
commit f8e361c0b8
12 files changed
+536 -37

No files matched your search

+13
View File
@@ -36,6 +36,17 @@ const resolveWorkspacePath = (): string => {
return path.resolve(DEFAULTS.WORKSPACE.BASE_PATH)
}
const resolveBrowseRoot = (): string => {
const envPath = process.env.REPO_BROWSE_ROOT
if (!envPath) {
return ''
}
if (envPath.startsWith('~')) {
return path.join(os.homedir(), envPath.slice(1))
}
return path.resolve(envPath)
}
const generateDefaultSecret = (): string => {
return randomBytes(32).toString('base64').slice(0, 32)
}
@@ -69,6 +80,7 @@ export const ENV = {
WORKSPACE: {
get BASE_PATH() { return resolveWorkspacePath() },
get BROWSE_ROOT() { return resolveBrowseRoot() },
REPOS_DIR: DEFAULTS.WORKSPACE.REPOS_DIR,
SCHEDULE_WORKTREES_DIR: DEFAULTS.WORKSPACE.SCHEDULE_WORKTREES_DIR,
CONFIG_DIR: DEFAULTS.WORKSPACE.CONFIG_DIR,
@@ -119,6 +131,7 @@ export const ENV = {
} as const
export const getWorkspacePath = () => ENV.WORKSPACE.BASE_PATH
export const getBrowseRootPath = () => ENV.WORKSPACE.BROWSE_ROOT
export const getReposPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.REPOS_DIR)
export const getScheduleWorktreesPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.SCHEDULE_WORKTREES_DIR)
export const getConfigPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR)
+18
View File
@@ -0,0 +1,18 @@
import { z } from 'zod'
export const DirectoryEntrySchema = z.object({
name: z.string(),
path: z.string(),
isGitRepo: z.boolean(),
})
export const BrowseDirectoryResponseSchema = z.object({
path: z.string(),
parentPath: z.string().nullable(),
isRoot: z.boolean(),
entries: z.array(DirectoryEntrySchema),
})
export const BrowseDirectoryRequestSchema = z.object({
path: z.string().optional(),
})
+1
View File
@@ -1,6 +1,7 @@
export * from './settings'
export * from './repo'
export * from './files'
export * from './filesystem'
export * from './opencode'
export * from './auth'
export * from './sse'
+9
View File
@@ -36,6 +36,11 @@ import {
SessionSchema,
MessageSchema,
} from '../schemas/opencode'
import {
DirectoryEntrySchema,
BrowseDirectoryResponseSchema,
BrowseDirectoryRequestSchema,
} from '../schemas/filesystem'
import {
NotificationPreferencesSchema,
PushSubscriptionRequestSchema,
@@ -82,6 +87,10 @@ export type FilePatchRequest = z.infer<typeof FilePatchRequestSchema>
export type Session = z.infer<typeof SessionSchema>
export type Message = z.infer<typeof MessageSchema>
export type DirectoryEntry = z.infer<typeof DirectoryEntrySchema>
export type BrowseDirectoryResponse = z.infer<typeof BrowseDirectoryResponseSchema>
export type BrowseDirectoryRequest = z.infer<typeof BrowseDirectoryRequestSchema>
export type NotificationPreferences = z.infer<typeof NotificationPreferencesSchema>
export type PushSubscriptionRequest = z.infer<typeof PushSubscriptionRequestSchema>
export type PushSubscriptionRecord = z.infer<typeof PushSubscriptionRecordSchema>