mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Critical and high: - repos: unlinking a local repo removes only the Manager reference and alias, never the repository files; confirm button reads "Unlink" - auth: rate-limit by the socket address; trust proxy headers only when AUTH_TRUSTED_PROXY_HEADERS is set (documented and forwarded in compose) - composer: per-session in-memory drafts (text, bash mode, attachments); Escape no longer clears the prompt - url params: compose same-tick updates so schedule dialogs stay closed after create/delete; delete dialog names the job Medium: - tool rows show failures (non-zero shell exit, failed exploration members) - voice conversation shows the specific error and a starting state - settings: Escape in dropdowns and the shortcut recorder no longer closes the dialog; mobile deep links open the requested section; one content tree per platform - closing pushed sheets, settings, tool panels and schedule dialogs goes back in history - login returns to the requested page; signed-out pages make no authenticated requests - action terminals keep their output (Manager-side output capture and replay) - unpushed-commit detection, commit message kept on failure - binary files with unknown extensions are detected and not editable - tool panel resizes when docked and floats as a dismissible sheet when the page is too narrow - Docker image runs tini as PID 1 Low: not-found states, add-repo and branch validation errors (4xx), search-aware empty states, mobile repo sort/filter/select cues, sidebar resize affordance and collapse shortcut, mobile unread badge, preview port filtering, terminal close handling, walkthrough empty state and helper session filtering, placeholder contrast, permission labels and focus, TTS task-list sanitizing, git identity email validation, quieter git logging, hermetic worktree tests, and accessible names for icon-only controls.
205 lines
8.7 KiB
TypeScript
205 lines
8.7 KiB
TypeScript
import path from 'path'
|
|
import os from 'os'
|
|
import { randomBytes } from 'crypto'
|
|
import { DEFAULTS } from './defaults'
|
|
import { ASSISTANT_REPO_PATH, ASSISTANT_OPENCODE_DIR_NAME } from '../utils/repo'
|
|
|
|
try {
|
|
const { config } = await import('dotenv')
|
|
config({ path: path.resolve(process.cwd(), '.env') })
|
|
} catch {
|
|
// dotenv not available (e.g., in production Docker), env vars already set
|
|
}
|
|
|
|
const getEnvString = (key: string, defaultValue: string): string => {
|
|
return process.env[key] ?? defaultValue
|
|
}
|
|
|
|
const getEnvNumber = (key: string, defaultValue: number): number => {
|
|
const value = process.env[key]
|
|
return value ? parseInt(value, 10) : defaultValue
|
|
}
|
|
|
|
const getEnvBoolean = (key: string, defaultValue: boolean): boolean => {
|
|
const value = process.env[key]
|
|
if (value === undefined) return defaultValue
|
|
return value === 'true' || value === '1'
|
|
}
|
|
|
|
const resolveWorkspacePath = (): string => {
|
|
const envPath = process.env.WORKSPACE_PATH
|
|
if (envPath) {
|
|
if (envPath.startsWith('~')) {
|
|
return path.join(os.homedir(), envPath.slice(1))
|
|
}
|
|
return path.resolve(envPath)
|
|
}
|
|
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)
|
|
}
|
|
|
|
const defaultHealthWatchEnabled = getEnvString('NODE_ENV', 'development') === 'test'
|
|
? false
|
|
: DEFAULTS.OPENCODE.HEALTH_WATCH_ENABLED
|
|
|
|
export const ENV = {
|
|
SERVER: {
|
|
PORT: getEnvNumber('PORT', DEFAULTS.SERVER.PORT),
|
|
HOST: getEnvString('HOST', DEFAULTS.SERVER.HOST),
|
|
CORS_ORIGIN: getEnvString('CORS_ORIGIN', DEFAULTS.SERVER.CORS_ORIGIN),
|
|
NODE_ENV: getEnvString('NODE_ENV', 'development'),
|
|
},
|
|
|
|
OPENCODE: {
|
|
PORT: getEnvNumber('OPENCODE_SERVER_PORT', DEFAULTS.OPENCODE.PORT),
|
|
HOST: getEnvString('OPENCODE_HOST', DEFAULTS.OPENCODE.HOST),
|
|
HEALTH_WATCH_ENABLED: getEnvBoolean('OPENCODE_HEALTH_WATCH_ENABLED', defaultHealthWatchEnabled),
|
|
HEALTH_POLL_MS: getEnvNumber('OPENCODE_HEALTH_POLL_MS', DEFAULTS.OPENCODE.HEALTH_POLL_MS),
|
|
HEALTH_FAILURE_THRESHOLD: getEnvNumber('OPENCODE_HEALTH_FAILURE_THRESHOLD', DEFAULTS.OPENCODE.HEALTH_FAILURE_THRESHOLD),
|
|
SERVER_PASSWORD: getEnvString('OPENCODE_SERVER_PASSWORD', ''),
|
|
LEGACY_PUBLIC_URL: getEnvString('OPENCODE_PUBLIC_URL', ''),
|
|
},
|
|
|
|
PREVIEW: {
|
|
PORT: getEnvNumber('PREVIEW_PORT', DEFAULTS.PREVIEW.PORT),
|
|
PUBLIC_URL: getEnvString('PREVIEW_PUBLIC_URL', ''),
|
|
},
|
|
|
|
DATABASE: {
|
|
PATH: getEnvString('DATABASE_PATH', DEFAULTS.DATABASE.PATH),
|
|
},
|
|
|
|
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,
|
|
WALKTHROUGHS_DIR: DEFAULTS.WORKSPACE.WALKTHROUGHS_DIR,
|
|
CONFIG_DIR: DEFAULTS.WORKSPACE.CONFIG_DIR,
|
|
},
|
|
|
|
SANDBOX: {
|
|
MSB_PATH: getEnvString('MSB_PATH', DEFAULTS.SANDBOX.MSB_PATH),
|
|
IMAGE: getEnvString('SANDBOX_IMAGE', DEFAULTS.SANDBOX.IMAGE),
|
|
MEMORY: getEnvString('SANDBOX_MEMORY', DEFAULTS.SANDBOX.MEMORY),
|
|
CPUS: getEnvNumber('SANDBOX_CPUS', DEFAULTS.SANDBOX.CPUS),
|
|
EXEC_USER: getEnvString('SANDBOX_EXEC_USER', DEFAULTS.SANDBOX.EXEC_USER),
|
|
NET: getEnvString('SANDBOX_NET', DEFAULTS.SANDBOX.NET),
|
|
START_TIMEOUT_MS: getEnvNumber('SANDBOX_START_TIMEOUT_MS', DEFAULTS.SANDBOX.START_TIMEOUT_MS),
|
|
EXEC_TIMEOUT_MS: getEnvNumber('SANDBOX_EXEC_TIMEOUT_MS', DEFAULTS.SANDBOX.EXEC_TIMEOUT_MS),
|
|
},
|
|
|
|
TIMEOUTS: {
|
|
PROCESS_START_WAIT_MS: getEnvNumber('PROCESS_START_WAIT_MS', DEFAULTS.TIMEOUTS.PROCESS_START_WAIT_MS),
|
|
PROCESS_VERIFY_WAIT_MS: getEnvNumber('PROCESS_VERIFY_WAIT_MS', DEFAULTS.TIMEOUTS.PROCESS_VERIFY_WAIT_MS),
|
|
HEALTH_CHECK_TIMEOUT_MS: getEnvNumber('HEALTH_CHECK_TIMEOUT_MS', DEFAULTS.TIMEOUTS.HEALTH_CHECK_TIMEOUT_MS),
|
|
},
|
|
|
|
FILE_LIMITS: {
|
|
MAX_SIZE_BYTES: getEnvNumber('MAX_FILE_SIZE_MB', DEFAULTS.FILE_LIMITS.MAX_SIZE_MB) * 1024 * 1024,
|
|
MAX_UPLOAD_SIZE_BYTES: getEnvNumber('MAX_UPLOAD_SIZE_MB', DEFAULTS.FILE_LIMITS.MAX_UPLOAD_SIZE_MB) * 1024 * 1024,
|
|
},
|
|
|
|
LOGGING: {
|
|
DEBUG: getEnvBoolean('DEBUG', DEFAULTS.LOGGING.DEBUG),
|
|
LOG_LEVEL: getEnvString('LOG_LEVEL', DEFAULTS.LOGGING.LOG_LEVEL),
|
|
},
|
|
|
|
VAPID: {
|
|
PUBLIC_KEY: process.env.VAPID_PUBLIC_KEY ?? '',
|
|
PRIVATE_KEY: process.env.VAPID_PRIVATE_KEY ?? '',
|
|
SUBJECT: process.env.VAPID_SUBJECT ?? '',
|
|
},
|
|
|
|
AUTH: {
|
|
SECRET: getEnvString('AUTH_SECRET', process.env.NODE_ENV === 'production' ? '' : generateDefaultSecret()),
|
|
TRUSTED_ORIGINS: getEnvString('AUTH_TRUSTED_ORIGINS', 'http://localhost:5173,http://localhost:5003,http://127.0.0.1:5173,http://127.0.0.1:5003'),
|
|
SECURE_COOKIES: getEnvBoolean('AUTH_SECURE_COOKIES', getEnvString('NODE_ENV', 'development') === 'production'),
|
|
TRUSTED_PROXY_HEADERS: getEnvString('AUTH_TRUSTED_PROXY_HEADERS', ''),
|
|
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
|
|
ADMIN_PASSWORD: process.env.ADMIN_PASSWORD,
|
|
ADMIN_PASSWORD_RESET: getEnvBoolean('ADMIN_PASSWORD_RESET', false),
|
|
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID,
|
|
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
|
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
|
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
|
|
DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID,
|
|
DISCORD_CLIENT_SECRET: process.env.DISCORD_CLIENT_SECRET,
|
|
PASSKEY_RP_ID: getEnvString('PASSKEY_RP_ID', 'localhost'),
|
|
PASSKEY_RP_NAME: getEnvString('PASSKEY_RP_NAME', 'OpenCode Manager'),
|
|
PASSKEY_ORIGIN: getEnvString('PASSKEY_ORIGIN', 'http://localhost:5003'),
|
|
},
|
|
|
|
} 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 getWalkthroughsPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.WALKTHROUGHS_DIR)
|
|
export const getAssistantModePath = () => path.join(getReposPath(), ASSISTANT_REPO_PATH)
|
|
export const getAssistantOpenCodeDir = () => path.join(getAssistantModePath(), ASSISTANT_OPENCODE_DIR_NAME)
|
|
export const getOpenCodeConfigHome = () => path.join(ENV.WORKSPACE.BASE_PATH, '.config')
|
|
export const getOpenCodeStateHome = () => path.join(ENV.WORKSPACE.BASE_PATH, '.opencode', 'state')
|
|
export const getOpenCodeHealthWatchPath = () => path.join(getOpenCodeStateHome(), 'health-watch')
|
|
export const getOpenCodeGlobalConfigPath = () => path.join(getOpenCodeConfigHome(), 'opencode')
|
|
export const getOpenCodeGlobalSkillsPath = () => path.join(getOpenCodeGlobalConfigPath(), 'skills')
|
|
export const getOpenCodeDataPath = () => path.join(getOpenCodeStateHome(), 'opencode')
|
|
export const getOpenCodeModelStatePath = () => path.join(getOpenCodeDataPath(), 'model.json')
|
|
export const getOpenCodeToolOutputPath = () => path.join(getOpenCodeDataPath(), 'tool-output')
|
|
export const getOpenCodeWorktreesPath = () => path.join(getOpenCodeDataPath(), 'worktree')
|
|
export const getForgeWorktreesPath = () => path.join(getOpenCodeDataPath(), 'forge', 'worktrees')
|
|
export const getOpenCodeTmpHome = () => path.join(ENV.WORKSPACE.BASE_PATH, '.opencode', 'tmp')
|
|
export const getOpenCodeAgentTmpPath = () => path.join(getOpenCodeTmpHome(), 'opencode')
|
|
export const getConfigPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR)
|
|
export { OPENCODE_CONFIG_SOURCE_NAMES } from './defaults'
|
|
export const getOpenCodeConfigFilePath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR, 'opencode.json')
|
|
export const getAgentsMdPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR, 'AGENTS.md')
|
|
export const getDatabasePath = () => ENV.DATABASE.PATH
|
|
|
|
export const getTrustedOrigins = (): string[] =>
|
|
ENV.AUTH.TRUSTED_ORIGINS
|
|
.split(',')
|
|
.map((origin) => origin.trim())
|
|
.filter((origin) => origin.length > 0)
|
|
|
|
export const getApiUrl = (port: number = ENV.SERVER.PORT): string => {
|
|
const host = ENV.SERVER.HOST
|
|
|
|
if (host === '0.0.0.0') {
|
|
const interfaces = os.networkInterfaces()
|
|
const ips = Object.values(interfaces)
|
|
.flat()
|
|
.filter(info => info && !info.internal && info.family === 'IPv4')
|
|
.map(info => info!.address)
|
|
|
|
if (ips.length > 0) {
|
|
return `http://${ips[0]}:${port}`
|
|
}
|
|
|
|
return `http://localhost:${port}`
|
|
}
|
|
|
|
return `http://${host}:${port}`
|
|
}
|
|
|
|
export const SERVER_CONFIG = ENV.SERVER
|
|
export const OPENCODE_CONFIG = ENV.OPENCODE
|
|
export const FILE_LIMITS = ENV.FILE_LIMITS
|
|
export const TIMEOUTS = ENV.TIMEOUTS
|
|
export const WORKSPACE = ENV.WORKSPACE
|