mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Merge forge/terminal-dev-loop into beta
feat: integrated terminal, project actions and dev server preview (OM-17, OM-18, OM-19) Integration with #380 and #379: - Adopt the git-config identity model: drop the branch's identity stubs (getShellEnv, getAssignedGitIdentityEnv, repo identity ids, duplicate createGitService and getMainCheckoutPath); terminals receive only the GitHub token env and take their commit identity from git config. - Add RepoWorkspaceService as the single owner of OpenCode workspace side effects: worktree setup commands on create and terminal cleanup on remove, used by the workspace routes, the session launcher (ocm tool and multi-run) and multi-run discard, with one worktree-sibling matcher. - Run repo-delete terminal cleanup inside the worktree branch deletion flow. - Combine the CreateWorktreeDialog tests and update docs for the identity model and setup command coverage.
This commit is contained in:
commit
b13707b5b3
135 files changed
+12726
-492
No files matched your search
@@ -18,6 +18,10 @@ export const DEFAULTS = {
|
||||
HEALTH_FAILURE_THRESHOLD: 2,
|
||||
},
|
||||
|
||||
PREVIEW: {
|
||||
PORT: 5004,
|
||||
},
|
||||
|
||||
DATABASE: {
|
||||
PATH: './data/opencode.db',
|
||||
},
|
||||
|
||||
@@ -74,6 +74,11 @@ export const ENV = {
|
||||
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),
|
||||
},
|
||||
@@ -162,6 +167,12 @@ export const getOpenCodeConfigFilePath = () => path.join(ENV.WORKSPACE.BASE_PATH
|
||||
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
|
||||
|
||||
|
||||
@@ -18,3 +18,6 @@ export * from './session-goals'
|
||||
export * from './internal-sessions'
|
||||
export * from './multi-runs'
|
||||
export * from './logs'
|
||||
export * from './terminal'
|
||||
export * from './project-config'
|
||||
export * from './preview'
|
||||
@@ -0,0 +1,30 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const PreviewPortSchema = z.object({
|
||||
port: z.number().int(),
|
||||
host: z.enum(['127.0.0.1', '::1']),
|
||||
pid: z.number().int().nullable(),
|
||||
command: z.string().nullable(),
|
||||
cwd: z.string().nullable(),
|
||||
inDirectory: z.boolean(),
|
||||
})
|
||||
|
||||
export const PreviewPortsResponseSchema = z.object({
|
||||
enabled: z.boolean(),
|
||||
ports: z.array(PreviewPortSchema),
|
||||
})
|
||||
|
||||
export const CreatePreviewSessionRequestSchema = z.object({
|
||||
port: z.number().int().min(1024).max(65535),
|
||||
})
|
||||
|
||||
export const CreatePreviewSessionResponseSchema = z.object({
|
||||
token: z.string(),
|
||||
previewPort: z.number().int(),
|
||||
publicUrl: z.string().nullable(),
|
||||
})
|
||||
|
||||
export type PreviewPort = z.infer<typeof PreviewPortSchema>
|
||||
export type PreviewPortsResponse = z.infer<typeof PreviewPortsResponseSchema>
|
||||
export type CreatePreviewSessionRequest = z.infer<typeof CreatePreviewSessionRequestSchema>
|
||||
export type CreatePreviewSessionResponse = z.infer<typeof CreatePreviewSessionResponseSchema>
|
||||
@@ -0,0 +1,138 @@
|
||||
import { z } from 'zod'
|
||||
import { TerminalInfoSchema } from './terminal'
|
||||
|
||||
export const ProjectActionIconSchema = z.enum([
|
||||
'play',
|
||||
'build',
|
||||
'test',
|
||||
'lint',
|
||||
'terminal',
|
||||
'server',
|
||||
'bug',
|
||||
'rocket',
|
||||
])
|
||||
|
||||
export const ProjectActionSchema = z.object({
|
||||
id: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/),
|
||||
name: z.string().trim().min(1).max(60),
|
||||
command: z.string().trim().min(1).max(4000),
|
||||
icon: ProjectActionIconSchema.optional(),
|
||||
url: z
|
||||
.string()
|
||||
.trim()
|
||||
.max(500)
|
||||
.refine((value) => /^https?:\/\//i.test(value), 'URL must start with http:// or https://')
|
||||
.optional(),
|
||||
autoOpenUrl: z.boolean().default(false),
|
||||
})
|
||||
|
||||
export const WorktreeSetupCommandsSchema = z.array(z.string().trim().min(1).max(4000)).max(20)
|
||||
|
||||
export const ProjectItemSourceSchema = z.enum(['personal', 'repo'])
|
||||
|
||||
export const RepoProjectFileSchema = z.looseObject({
|
||||
version: z.literal(1),
|
||||
projectActions: z.array(ProjectActionSchema).optional(),
|
||||
setupWorktree: WorktreeSetupCommandsSchema.optional(),
|
||||
})
|
||||
|
||||
export const ProjectConfigResponseSchema = z.object({
|
||||
actions: z.array(
|
||||
ProjectActionSchema.extend({
|
||||
source: ProjectItemSourceSchema,
|
||||
resolvedUrl: z.string().optional(),
|
||||
}),
|
||||
),
|
||||
worktreeSetup: z.array(
|
||||
z.object({
|
||||
command: z.string(),
|
||||
source: ProjectItemSourceSchema,
|
||||
}),
|
||||
),
|
||||
repoFile: z.object({
|
||||
path: z.literal('.ocm/project.json'),
|
||||
exists: z.boolean(),
|
||||
trusted: z.boolean(),
|
||||
hash: z.string().nullable(),
|
||||
executable: z
|
||||
.object({
|
||||
actions: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
command: z.string(),
|
||||
url: z.string().nullable(),
|
||||
autoOpenUrl: z.boolean(),
|
||||
}),
|
||||
),
|
||||
setup: z.array(z.string()),
|
||||
})
|
||||
.nullable(),
|
||||
error: z.string().optional(),
|
||||
warnings: z.array(z.string()),
|
||||
}),
|
||||
})
|
||||
|
||||
export const UpdateProjectActionsRequestSchema = z.object({
|
||||
actions: z.array(ProjectActionSchema).max(50),
|
||||
})
|
||||
|
||||
export const UpdateWorktreeSetupRequestSchema = z.object({
|
||||
commands: WorktreeSetupCommandsSchema,
|
||||
})
|
||||
|
||||
export const TrustRepoConfigRequestSchema = z.object({
|
||||
directory: z.string().optional(),
|
||||
hash: z.string().regex(/^[a-f0-9]{64}$/),
|
||||
})
|
||||
|
||||
export const MoveProjectItemRequestSchema = z.discriminatedUnion('kind', [
|
||||
z.object({
|
||||
kind: z.literal('action'),
|
||||
id: z.string(),
|
||||
to: ProjectItemSourceSchema,
|
||||
directory: z.string().optional(),
|
||||
}),
|
||||
z.object({
|
||||
kind: z.literal('setup'),
|
||||
command: z.string(),
|
||||
to: ProjectItemSourceSchema,
|
||||
directory: z.string().optional(),
|
||||
}),
|
||||
])
|
||||
|
||||
export const RunProjectActionRequestSchema = z.object({
|
||||
directory: z.string().optional(),
|
||||
})
|
||||
|
||||
export const RunProjectActionResponseSchema = z.object({
|
||||
terminal: TerminalInfoSchema,
|
||||
alreadyRunning: z.boolean(),
|
||||
resolvedUrl: z.string().optional(),
|
||||
autoOpenUrl: z.boolean(),
|
||||
})
|
||||
|
||||
export const WorktreeSetupResultSchema = z.discriminatedUnion('status', [
|
||||
z.object({ status: z.literal('none') }),
|
||||
z.object({
|
||||
status: z.literal('started'),
|
||||
terminal: TerminalInfoSchema,
|
||||
repoCommandsSkipped: z.boolean(),
|
||||
}),
|
||||
z.object({ status: z.literal('skipped'), reason: z.literal('untrusted') }),
|
||||
z.object({ status: z.literal('failed'), error: z.string() }),
|
||||
])
|
||||
|
||||
export type ProjectActionIcon = z.infer<typeof ProjectActionIconSchema>
|
||||
export type ProjectAction = z.infer<typeof ProjectActionSchema>
|
||||
export type WorktreeSetupCommands = z.infer<typeof WorktreeSetupCommandsSchema>
|
||||
export type ProjectItemSource = z.infer<typeof ProjectItemSourceSchema>
|
||||
export type RepoProjectFile = z.infer<typeof RepoProjectFileSchema>
|
||||
export type ProjectConfigResponse = z.infer<typeof ProjectConfigResponseSchema>
|
||||
export type UpdateProjectActionsRequest = z.infer<typeof UpdateProjectActionsRequestSchema>
|
||||
export type UpdateWorktreeSetupRequest = z.infer<typeof UpdateWorktreeSetupRequestSchema>
|
||||
export type TrustRepoConfigRequest = z.infer<typeof TrustRepoConfigRequestSchema>
|
||||
export type MoveProjectItemRequest = z.infer<typeof MoveProjectItemRequestSchema>
|
||||
export type RunProjectActionRequest = z.infer<typeof RunProjectActionRequestSchema>
|
||||
export type RunProjectActionResponse = z.infer<typeof RunProjectActionResponseSchema>
|
||||
export type WorktreeSetupResult = z.infer<typeof WorktreeSetupResultSchema>
|
||||
@@ -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>
|
||||
@@ -189,3 +189,33 @@ export {
|
||||
InstallSkillUploadRequestSchema,
|
||||
InstallSkillUploadManifestEntrySchema,
|
||||
} from '../schemas/skills'
|
||||
|
||||
export type {
|
||||
TerminalKind,
|
||||
TerminalInfo,
|
||||
CreateTerminalRequest,
|
||||
ResizeTerminalRequest,
|
||||
} from '../schemas/terminal'
|
||||
|
||||
export type {
|
||||
PreviewPort,
|
||||
PreviewPortsResponse,
|
||||
CreatePreviewSessionRequest,
|
||||
CreatePreviewSessionResponse,
|
||||
} from '../schemas/preview'
|
||||
|
||||
export type {
|
||||
ProjectActionIcon,
|
||||
ProjectAction,
|
||||
WorktreeSetupCommands,
|
||||
ProjectItemSource,
|
||||
RepoProjectFile,
|
||||
ProjectConfigResponse,
|
||||
UpdateProjectActionsRequest,
|
||||
UpdateWorktreeSetupRequest,
|
||||
TrustRepoConfigRequest,
|
||||
MoveProjectItemRequest,
|
||||
RunProjectActionRequest,
|
||||
RunProjectActionResponse,
|
||||
WorktreeSetupResult,
|
||||
} from '../schemas/project-config'
|
||||
@@ -2,3 +2,4 @@ export * from './jsonc'
|
||||
export * from './repo'
|
||||
export * from './sandbox-command'
|
||||
export * from './semver'
|
||||
export * from './terminal-title'
|
||||
@@ -0,0 +1,59 @@
|
||||
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 }
|
||||
}
|
||||
Reference in new issue
Block a user