mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
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:
1 parent
8d5102dc90
commit
f8e361c0b8
12 files changed
+536
-37
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user