mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(settings): harden config directory replace and consolidate upload plumbing
Validate the config before any filesystem work and persist the default row only after the directory swap succeeds; reject oversize uploads before buffering and stream parts to staging; re-ensure AGENTS.md after a replace. Consolidate the upload contract in shared, unify the default-config upsert, single-own the browser directory-upload and restart state, and drop dead code.
This commit is contained in:
1 parent
b1bccb3dd5
commit
39d2b98370
36 files changed
+1098
-510
No files matched your search
@@ -104,6 +104,7 @@ export type AssistantSettingsPatch = z.infer<typeof AssistantSettingsPatchSchema
|
||||
export { FetchError } from './errors'
|
||||
export type { ApiErrorResponse, ApiErrorCode, GitErrorCode } from './errors'
|
||||
export { BLOCKED_SERVER_ENV_KEYS, DEFAULT_SERVER_ENV_VARS } from '../schemas/settings'
|
||||
export type { ReplaceOpenCodeConfigDirectoryResult } from './settings'
|
||||
|
||||
export interface SuccessResponse {
|
||||
success: boolean
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export interface ReplaceOpenCodeConfigDirectoryResult {
|
||||
configSourceFilename: string
|
||||
filesInstalled: string[]
|
||||
skippedPaths: string[]
|
||||
preservedEntries: string[]
|
||||
executablesRestored: string[]
|
||||
}
|
||||
@@ -1,13 +1,27 @@
|
||||
export const OPENCODE_CONFIG_FILENAMES = ['opencode.json', 'opencode.jsonc'] as const
|
||||
const OPENCODE_CONFIG_FILENAMES = ['opencode.json', 'opencode.jsonc'] as const
|
||||
|
||||
export const OPENCODE_CANONICAL_CONFIG_FILENAME = 'opencode.json'
|
||||
|
||||
export const MAX_OPENCODE_CONFIG_DIRECTORY_FILES = 5000
|
||||
|
||||
export const EXCLUDED_OPENCODE_CONFIG_UPLOAD_SEGMENTS = ['node_modules', '.git'] as const
|
||||
|
||||
export const EXCLUDED_OPENCODE_CONFIG_UPLOAD_FILENAMES = ['.DS_Store'] as const
|
||||
|
||||
export const PRESERVED_OPENCODE_CONFIG_ENTRIES = ['node_modules'] as const
|
||||
|
||||
export const OPENCODE_CONFIG_STAGING_PREFIX = '.opencode-config-staging-'
|
||||
|
||||
export const OPENCODE_CONFIG_BACKUP_PREFIX = '.opencode-config-backup-'
|
||||
|
||||
export const OPENCODE_CONFIG_UPLOAD_ERRORS = {
|
||||
NO_FILES_PROVIDED: 'No files were provided for the OpenCode config directory replace',
|
||||
TOO_MANY_FILES: `Uploaded config directory contains too many files (max ${MAX_OPENCODE_CONFIG_DIRECTORY_FILES})`,
|
||||
EXCEEDS_MAX_UPLOAD_SIZE: 'Uploaded config directory files exceed maximum upload size',
|
||||
MISSING_ROOT_CONFIG: 'Uploaded directory must contain opencode.json or opencode.jsonc at its root',
|
||||
} as const
|
||||
|
||||
export function isOpenCodeConfigUploadPath(relativePath: string): boolean {
|
||||
if (relativePath.includes('/')) return false
|
||||
return OPENCODE_CONFIG_FILENAMES.some((filename) => filename === relativePath)
|
||||
}
|
||||
|
||||
@@ -28,3 +42,7 @@ export function getCommonUploadRootDirectory(relativePaths: string[]): string |
|
||||
if (!relativePaths.some((relativePath) => relativePath.includes('/'))) return null
|
||||
return root
|
||||
}
|
||||
|
||||
export function stripUploadRootDirectory(relativePath: string, commonRoot: string | null): string {
|
||||
return commonRoot ? relativePath.slice(commonRoot.length + 1) : relativePath
|
||||
}
|
||||
Reference in new issue
Block a user