section 2: Phase 2: Terminal service, REST routes and cleanup

This commit is contained in:
Chris Scott committed 2026-10-03 01:05:02 -04:00
1 parent b494ee9f4a
commit beab2646e7
15 files changed
+907 -57

No files matched your search

+1
View File
@@ -12,3 +12,4 @@ export * from './skills'
export * from './internal-assistant'
export * from './session-pins'
export * from './logs'
export * from './terminal'
+29
View File
@@ -0,0 +1,29 @@
import { z } from 'zod'
export const TerminalKindSchema = z.enum(['shell', 'action', 'setup'])
export const TerminalInfoSchema = z.object({
id: z.string(),
title: z.string(),
kind: TerminalKindSchema,
actionId: z.string().optional(),
cwd: z.string(),
status: z.enum(['running', 'exited']),
exitCode: z.number().int().optional(),
})
export const CreateTerminalRequestSchema = z.object({
directory: z.string().trim().min(1).optional(),
title: z.string().trim().min(1).max(80).optional(),
})
export const ResizeTerminalRequestSchema = z.object({
directory: z.string().trim().min(1).optional(),
cols: z.number().int().min(1).max(1000),
rows: z.number().int().min(1).max(500),
})
export type TerminalKind = z.infer<typeof TerminalKindSchema>
export type TerminalInfo = z.infer<typeof TerminalInfoSchema>
export type CreateTerminalRequest = z.infer<typeof CreateTerminalRequestSchema>
export type ResizeTerminalRequest = z.infer<typeof ResizeTerminalRequestSchema>
+7
View File
@@ -158,3 +158,10 @@ export {
InstallSkillUploadRequestSchema,
InstallSkillUploadManifestEntrySchema,
} from '../schemas/skills'
export type {
TerminalKind,
TerminalInfo,
CreateTerminalRequest,
ResizeTerminalRequest,
} from '../schemas/terminal'
+1
View File
@@ -2,3 +2,4 @@ export * from './jsonc'
export * from './repo'
export * from './sandbox-command'
export * from './semver'
export * from './terminal-title'
+53
View File
@@ -0,0 +1,53 @@
import type { 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 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 }
}