Files
opencode-manager/shared/src/utils/terminal-title.ts
T
Chris Scott c60a9b35f2 fix(terminal-dev-loop): address branch review findings
Security:
- Reject same-site and cross-site state-changing requests on cookie-authenticated routes unless the origin is trusted
- Drop Manager and ocm_preview Set-Cookie headers from preview responses
- Show and hash the full executable content of .ocm/project.json at trust time
- Restrict action URLs to http(s) and refuse symlinked repo config paths
- Keep the preview start redirect on the gateway origin

Lifecycle:
- Stop terminals in OpenCode workspace siblings when a repo is deleted
- Report preview as unavailable instead of crashing when the gateway port cannot be bound

Performance:
- Skip branch lookups when validating terminal and project-config directories
- Stop the /proc scan once all listening sockets are mapped and pause port polling while a preview is open
- Close slow WebSocket clients with 1013 so they reconnect with replay
- Lazy-load the xterm terminal view and skip unchanged resize requests
- Request uncompressed responses from preview targets

Cleanup:
- Share one repo directory resolver, trusted-origins parser, cookie prefix, WebSocket frame forwarder, header filter, icon map and dialog-param helper
- Remove unused props, options and exports

Docs: update terminal, preview, project actions, sandboxing, internal API and environment pages
2026-10-03 10:00:33 -04:00

60 lines
1.8 KiB
TypeScript

import type { TerminalInfo, TerminalKind } from '../schemas/terminal'
const ACTION_TITLE_PREFIX = 'ocm:action:'
const SETUP_TITLE_PREFIX = 'ocm:setup:'
const ACTION_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/
export interface FormatTerminalTitleInput {
kind: TerminalKind
name: string
actionId?: string
}
export interface ParsedTerminalTitle {
kind: TerminalKind
title: string
actionId?: string
}
export function formatTerminalTitle(input: FormatTerminalTitleInput): string {
if (input.kind === 'action') {
if (!input.actionId || !ACTION_ID_PATTERN.test(input.actionId)) {
throw new Error('Action terminals require a valid action id')
}
return `${ACTION_TITLE_PREFIX}${input.actionId}:${input.name}`
}
if (input.kind === 'setup') {
return `${SETUP_TITLE_PREFIX}${input.name}`
}
return input.name
}
export type RunningActionTerminal = Pick<TerminalInfo, 'kind' | 'actionId' | 'status'>
export function isRunningActionTerminal(terminal: RunningActionTerminal, actionId: string): boolean {
return terminal.kind === 'action' && terminal.actionId === actionId && terminal.status === 'running'
}
export function parseTerminalTitle(raw: string): ParsedTerminalTitle {
if (raw.startsWith(ACTION_TITLE_PREFIX)) {
const rest = raw.slice(ACTION_TITLE_PREFIX.length)
const separator = rest.indexOf(':')
const actionId = separator === -1 ? rest : rest.slice(0, separator)
const title = separator === -1 ? '' : rest.slice(separator + 1)
if (ACTION_ID_PATTERN.test(actionId) && title.length > 0) {
return { kind: 'action', title, actionId }
}
return { kind: 'shell', title: raw }
}
if (raw.startsWith(SETUP_TITLE_PREFIX)) {
return { kind: 'setup', title: raw.slice(SETUP_TITLE_PREFIX.length) }
}
return { kind: 'shell', title: raw }
}