mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix issues (#136)
* fix: prevent delete button click when card is not swiped open * refactor: improve CreateRepoInput type safety * security: require AUTH_SECRET and use secure random generation * fix: SSH key path validation, async passphrase stripping, and port handling * fix: use correct console methods for logger levels * Add error handling to DB update functions and improve migration logging * Add error handling for session lookup in auth middleware * Add structured git error handling with user-friendly messages - Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND, PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes - Return structured error responses with summary and detail from backend - Add GitErrorBanner component for better error display in UI - Add optional onError callback to useGit hook for external error handling * Make IPC server initialization/disposal async and fix SSH host key handler * add try-catch error handling in frontend lib utilities * remove unresolved promise handlers in speech synthesizer callbacks * Extract error types to shared package * Import GitErrorCode from shared package * Refactor API layer to use shared FetchError and fetchWrapper * Update prompt parser and source control components * Extract MCP server list to separate component with improved badge menu UX * merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility * add separate loading state for passkey sign in * refactor hooks: use fetchWrapper, improve error handling, add proper types * replace browser confirm() with DeleteDialog component in settings * fix: add missing variables parameter in React Query onError callbacks * Refactor message parts to use separate Zustand store * Update QuestionPrompt styling for light/dark mode
This commit is contained in:
1 parent
7f7d106c28
commit
5de419ee28
75 files changed
+1990
-1367
No files matched your search
@@ -6,7 +6,10 @@ const IV_LENGTH = 16
|
||||
const KEY_LENGTH = 32
|
||||
|
||||
function deriveKey(): Buffer {
|
||||
const secret = ENV.AUTH.SECRET || 'default-secret-do-not-use-in-production'
|
||||
const secret = ENV.AUTH.SECRET
|
||||
if (!secret) {
|
||||
throw new Error('AUTH_SECRET must be configured for encryption')
|
||||
}
|
||||
return scryptSync(secret, ENCRYPTION_KEY_SALT, KEY_LENGTH)
|
||||
}
|
||||
|
||||
|
||||
@@ -145,13 +145,13 @@ export function getSSHCredentialsForHost(credentials: GitCredential[], host: str
|
||||
try {
|
||||
const parsedCredHost = new URL(credHost)
|
||||
const credHostname = parsedCredHost.hostname.toLowerCase()
|
||||
const credPort = parsedCredHost.port || (parsedCredHost.protocol.includes('ssh') ? 22 : null)
|
||||
const credPort = parsedCredHost.port || (parsedCredHost.protocol.includes('ssh') ? '22' : '')
|
||||
const normalizedCredHost = credPort ? `${credHostname}:${credPort}` : credHostname
|
||||
|
||||
|
||||
const parsedTargetHost = new URL(`ssh://dummy@${targetHost}`)
|
||||
const targetHostname = parsedTargetHost.hostname.toLowerCase()
|
||||
const targetPort = parsedTargetHost.port || 22
|
||||
const normalizedTargetHost = targetPort !== '' ? `${targetHostname}:${targetPort}` : targetHostname
|
||||
const targetPort = parsedTargetHost.port || '22'
|
||||
const normalizedTargetHost = targetPort ? `${targetHostname}:${targetPort}` : targetHostname
|
||||
|
||||
return normalizedCredHost === normalizedTargetHost
|
||||
} catch {
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import type { GitErrorCode } from '@opencode-manager/shared'
|
||||
import { getErrorMessage } from './error-utils'
|
||||
|
||||
export type { GitErrorCode }
|
||||
|
||||
export function isNoUpstreamError(error: Error): boolean {
|
||||
const patterns = [
|
||||
/The current branch .+ has no upstream branch/i,
|
||||
@@ -10,4 +15,202 @@ export function isNoUpstreamError(error: Error): boolean {
|
||||
export function parseBranchNameFromError(error: Error): string | null {
|
||||
const match = error.message.match(/The current branch (.+) has no upstream branch/i)
|
||||
return match?.[1]?.trim() ?? null
|
||||
}
|
||||
}
|
||||
|
||||
export interface GitErrorInfo {
|
||||
code: GitErrorCode
|
||||
summary: string
|
||||
detail: string
|
||||
statusCode: number
|
||||
}
|
||||
|
||||
interface ErrorPattern {
|
||||
code: GitErrorCode
|
||||
summary: string
|
||||
statusCode: number
|
||||
patterns: RegExp[]
|
||||
}
|
||||
|
||||
const ERROR_PATTERNS: ErrorPattern[] = [
|
||||
{
|
||||
code: 'AUTH_FAILED',
|
||||
summary: 'Authentication failed. Check your credentials in Settings > Git Credentials.',
|
||||
statusCode: 401,
|
||||
patterns: [
|
||||
/authentication failed/i,
|
||||
/could not read Username/i,
|
||||
/could not read password/i,
|
||||
/git credentials/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'REPO_NOT_FOUND',
|
||||
summary: 'Repository not found. Check the URL and ensure you have access.',
|
||||
statusCode: 404,
|
||||
patterns: [
|
||||
/repository not found/i,
|
||||
/fatal: .* does not exist/i,
|
||||
/could not resolve host/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'PERMISSION_DENIED',
|
||||
summary: 'Permission denied. Check your repository access and credentials.',
|
||||
statusCode: 403,
|
||||
patterns: [
|
||||
/permission denied/i,
|
||||
/access denied/i,
|
||||
/not a readable path/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'PUSH_REJECTED',
|
||||
summary: 'Push rejected. Pull the latest changes first, then try again.',
|
||||
statusCode: 409,
|
||||
patterns: [
|
||||
/non-fast-forward/i,
|
||||
/rejected push/i,
|
||||
/fetch first/i,
|
||||
/Updates were rejected/i,
|
||||
/push failed/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'MERGE_CONFLICT',
|
||||
summary: 'Merge conflict detected. Resolve the conflicts before continuing.',
|
||||
statusCode: 409,
|
||||
patterns: [
|
||||
/CONFLICT \(/,
|
||||
/merge conflict/i,
|
||||
/fix conflicts/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'NO_UPSTREAM',
|
||||
summary: 'No upstream branch configured. Push will set upstream automatically.',
|
||||
statusCode: 400,
|
||||
patterns: [
|
||||
/no upstream branch/i,
|
||||
/has no upstream branch/i,
|
||||
/no upstream configured/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'TIMEOUT',
|
||||
summary: 'Operation timed out. Check your network connection and try again.',
|
||||
statusCode: 504,
|
||||
patterns: [
|
||||
/timed out/i,
|
||||
/etimedout/i,
|
||||
/connection timed out/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'NOT_A_REPO',
|
||||
summary: 'Not a valid Git repository.',
|
||||
statusCode: 400,
|
||||
patterns: [
|
||||
/not a git repository/i,
|
||||
/fatal: not a git repository/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'LOCK_FAILED',
|
||||
summary: 'Git is locked by another process. Wait a moment and try again.',
|
||||
statusCode: 409,
|
||||
patterns: [
|
||||
/unable to create lock/i,
|
||||
/index\.lock/i,
|
||||
/another git process seems to be running/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'DETACHED_HEAD',
|
||||
summary: 'Repository is in detached HEAD state. Switch to a branch first.',
|
||||
statusCode: 400,
|
||||
patterns: [
|
||||
/HEAD detached/i,
|
||||
/detached at/i,
|
||||
/detached HEAD/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'BRANCH_EXISTS',
|
||||
summary: 'A branch with that name already exists.',
|
||||
statusCode: 409,
|
||||
patterns: [
|
||||
/branch .* already exists/i,
|
||||
/fatal: A branch named .* already exists/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'BRANCH_NOT_FOUND',
|
||||
summary: 'Branch not found. Check the branch name and try again.',
|
||||
statusCode: 404,
|
||||
patterns: [
|
||||
/pathspec .* did not match/i,
|
||||
/unknown revision/i,
|
||||
/invalid ref/i,
|
||||
/reference.*not found/i,
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'UNCOMMITTED_CHANGES',
|
||||
summary: 'You have uncommitted changes. Commit or stash them first.',
|
||||
statusCode: 409,
|
||||
patterns: [
|
||||
/uncommitted changes/i,
|
||||
/local changes.*overwritten/i,
|
||||
/would lose uncommitted changes/i,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
function stripCommandFailedPrefix(message: string): string {
|
||||
return message.replace(/^Command failed with code \d+:\s*/, '')
|
||||
}
|
||||
|
||||
const PROGRESS_LINE_PATTERNS = [
|
||||
/^remote: Counting objects:.*$/gm,
|
||||
/^remote: Compressing objects:.*$/gm,
|
||||
/^remote: Receiving objects:.*$/gm,
|
||||
/^remote: Total .*$/gm,
|
||||
/^Resolving deltas:.*$/gm,
|
||||
/^From .+$/gm,
|
||||
/^ \* \[new branch] {2,}.*$/gm,
|
||||
/^ {3}.+-> .+$/gm,
|
||||
]
|
||||
|
||||
function cleanGitProgressLines(message: string): string {
|
||||
let cleaned = message
|
||||
for (const pattern of PROGRESS_LINE_PATTERNS) {
|
||||
cleaned = cleaned.replace(pattern, '')
|
||||
}
|
||||
return cleaned.replace(/\n{3,}/g, '\n\n').trim()
|
||||
}
|
||||
|
||||
export function parseGitError(error: unknown): GitErrorInfo {
|
||||
const rawMessage = getErrorMessage(error)
|
||||
const message = stripCommandFailedPrefix(rawMessage)
|
||||
const cleanedMessage = cleanGitProgressLines(message)
|
||||
|
||||
for (const errorPattern of ERROR_PATTERNS) {
|
||||
for (const pattern of errorPattern.patterns) {
|
||||
if (pattern.test(message) || pattern.test(cleanedMessage)) {
|
||||
return {
|
||||
code: errorPattern.code,
|
||||
summary: errorPattern.summary,
|
||||
detail: cleanedMessage || message,
|
||||
statusCode: errorPattern.statusCode,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
code: 'UNKNOWN',
|
||||
summary: 'A git operation failed.',
|
||||
detail: cleanedMessage || message,
|
||||
statusCode: 500,
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class Logger {
|
||||
}
|
||||
|
||||
info(message: string, ...args: unknown[]): void {
|
||||
console.warn(this.format('info', message), ...args)
|
||||
console.log(this.format('info', message), ...args)
|
||||
}
|
||||
|
||||
warn(message: string, ...args: unknown[]): void {
|
||||
@@ -29,7 +29,7 @@ class Logger {
|
||||
|
||||
debug(message: string, ...args: unknown[]): void {
|
||||
if (ENV.LOGGING.DEBUG) {
|
||||
console.warn(this.format('debug', message), ...args)
|
||||
console.debug(this.format('debug', message), ...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-empty */
|
||||
import { promises as fs } from 'fs'
|
||||
import { execFileSync } from 'child_process'
|
||||
import { execFile } from 'child_process'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { join } from 'path'
|
||||
import { getWorkspacePath } from '@opencode-manager/shared/config/env'
|
||||
@@ -58,7 +58,11 @@ export async function writeTemporarySSHKey(keyContent: string, identifier: strin
|
||||
const randomSuffix = randomBytes(8).toString('hex')
|
||||
const fileName = `key-${identifier}-${randomSuffix}`
|
||||
const keyPath = join(SSH_KEYS_DIR, fileName)
|
||||
|
||||
|
||||
if (!keyPath.startsWith(SSH_KEYS_DIR)) {
|
||||
throw new Error('Invalid key path')
|
||||
}
|
||||
|
||||
await fs.writeFile(keyPath, keyContent.trim() + '\n', { mode: 0o600 })
|
||||
|
||||
const isValid = await validateSSHKey(keyPath)
|
||||
@@ -108,6 +112,10 @@ export async function writePersistentSSHKey(keyContent: string, identifier: stri
|
||||
const fileName = `persistent-${identifier}`
|
||||
const keyPath = join(SSH_KEYS_DIR, fileName)
|
||||
|
||||
if (!keyPath.startsWith(SSH_KEYS_DIR)) {
|
||||
throw new Error('Invalid key path')
|
||||
}
|
||||
|
||||
await fs.writeFile(keyPath, keyContent.trim() + '\n', { mode: 0o600 })
|
||||
|
||||
const isValid = await validateSSHKey(keyPath)
|
||||
@@ -123,8 +131,13 @@ export function buildSSHCommandWithConfig(configPath: string, knownHostsPath: st
|
||||
return `ssh -T -F "${configPath}" -o UserKnownHostsFile="${knownHostsPath}" -o StrictHostKeyChecking=accept-new -o PasswordAuthentication=no`
|
||||
}
|
||||
|
||||
export function stripKeyPassphrase(keyPath: string, passphrase: string): void {
|
||||
execFileSync('ssh-keygen', ['-p', '-P', passphrase, '-N', '', '-f', keyPath], { stdio: 'ignore' })
|
||||
export async function stripKeyPassphrase(keyPath: string, passphrase: string): Promise<void> {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
execFile('ssh-keygen', ['-p', '-P', passphrase, '-N', '', '-f', keyPath], (error: Error | null) => {
|
||||
if (error) reject(error)
|
||||
else resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export interface SSHConfigEntry {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { executeCommand } from './process'
|
||||
|
||||
async function removeFile(filePath: string): Promise<void> {
|
||||
@@ -21,7 +22,7 @@ export async function validateSSHPrivateKey(key: string): Promise<{ valid: boole
|
||||
let tempKeyPath: string | null = null
|
||||
|
||||
try {
|
||||
tempKeyPath = join(tmpdir(), `temp-ssh-key-${Date.now()}-${Math.random().toString(36).slice(2)}`)
|
||||
tempKeyPath = join(tmpdir(), `temp-ssh-key-${Date.now()}-${randomBytes(8).toString('hex')}`)
|
||||
await fs.writeFile(tempKeyPath, trimmedKey + '\n', { mode: 0o600 })
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user