Initial release v0.2.5

This commit is contained in:
Chris Scott committed 2025-11-23 23:25:27 -05:00
commit bbf66c259b
158 files changed
+37115

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
import { config } from 'dotenv'
import path from 'path'
import os from 'os'
config({ path: '../.env' })
const getEnvNumber = (key: string, defaultValue: number): number => {
const value = process.env[key]
return value ? parseInt(value, 10) : defaultValue
}
const workspaceBasePath = process.env.WORKSPACE_PATH
? path.resolve(process.env.WORKSPACE_PATH)
: path.join(os.homedir(), '.opencode-workspace')
export const WORKSPACE = {
BASE_PATH: workspaceBasePath,
REPOS_DIR: 'repos',
CONFIG_DIR: 'config',
AUTH_FILE: '.opencode/state/opencode/auth.json',
} as const
export const getWorkspacePath = () => WORKSPACE.BASE_PATH
export const getReposPath = () => path.join(WORKSPACE.BASE_PATH, WORKSPACE.REPOS_DIR)
export const getConfigPath = () => path.join(WORKSPACE.BASE_PATH, WORKSPACE.CONFIG_DIR)
export const getAuthPath = () => path.join(WORKSPACE.BASE_PATH, WORKSPACE.AUTH_FILE)
export const TIMEOUTS = {
PROCESS_START_WAIT_MS: getEnvNumber('PROCESS_START_WAIT_MS', 2000),
PROCESS_VERIFY_WAIT_MS: getEnvNumber('PROCESS_VERIFY_WAIT_MS', 1000),
HEALTH_CHECK_INTERVAL_MS: getEnvNumber('HEALTH_CHECK_INTERVAL_MS', 5000),
HEALTH_CHECK_TIMEOUT_MS: getEnvNumber('HEALTH_CHECK_TIMEOUT_MS', 30000),
} as const
const maxFileSizeMB = getEnvNumber('MAX_FILE_SIZE_MB', 50)
const maxUploadSizeMB = getEnvNumber('MAX_UPLOAD_SIZE_MB', 50)
export const FILE_LIMITS = {
MAX_SIZE_BYTES: maxFileSizeMB * 1024 * 1024,
MAX_UPLOAD_SIZE_BYTES: maxUploadSizeMB * 1024 * 1024,
} as const
export const ALLOWED_MIME_TYPES = [
'text/plain',
'text/html',
'text/css',
'text/javascript',
'text/typescript',
'application/json',
'application/xml',
'image/png',
'image/jpeg',
'image/gif',
'image/svg+xml',
'application/pdf',
'application/zip',
] as const
export const GIT_PROVIDERS = {
GITHUB: 'github.com',
GITLAB: 'gitlab.com',
BITBUCKET: 'bitbucket.org',
} as const
+3
View File
@@ -0,0 +1,3 @@
export * from './constants'
export * from './schemas'
export * from './types'
+23
View File
@@ -0,0 +1,23 @@
import { z } from "zod";
export const AuthEntrySchema = z.object({
type: z.enum(["apiKey", "oauth"]),
apiKey: z.string().optional(),
refresh: z.string().optional(),
access: z.string().optional(),
expires: z.number().optional(),
});
export const AuthCredentialsSchema = z.record(z.string(), AuthEntrySchema);
export const SetCredentialRequestSchema = z.object({
apiKey: z.string().min(1),
});
export const CredentialStatusResponseSchema = z.object({
hasCredentials: z.boolean(),
});
export const CredentialListResponseSchema = z.object({
providers: z.array(z.string()),
});
+37
View File
@@ -0,0 +1,37 @@
import { z } from 'zod'
export const FileInfoSchema: z.ZodType<{
name: string
path: string
isDirectory: boolean
size: number
mimeType?: string
content?: string
children?: Array<any>
lastModified: Date
}> = z.object({
name: z.string(),
path: z.string(),
isDirectory: z.boolean(),
size: z.number(),
mimeType: z.string().optional(),
content: z.string().optional(),
children: z.lazy(() => z.array(FileInfoSchema)).optional(),
lastModified: z.date(),
})
export const CreateFileRequestSchema = z.object({
type: z.enum(['file', 'folder']),
content: z.string().optional(),
})
export const RenameFileRequestSchema = z.object({
newPath: z.string(),
})
export const FileUploadResponseSchema = z.object({
name: z.string(),
path: z.string(),
size: z.number(),
mimeType: z.string(),
})
+5
View File
@@ -0,0 +1,5 @@
export * from './settings'
export * from './repo'
export * from './files'
export * from './opencode'
export * from './auth'
+49
View File
@@ -0,0 +1,49 @@
import { z } from 'zod'
export const FileDiffSchema = z.object({
file: z.string(),
before: z.string(),
after: z.string(),
additions: z.number(),
deletions: z.number(),
})
export const SessionSchema = z.object({
id: z.string(),
projectID: z.string(),
directory: z.string(),
parentID: z.string().optional(),
summary: z.object({
diffs: FileDiffSchema.array(),
}).optional(),
share: z.object({
url: z.string(),
}).optional(),
title: z.string(),
version: z.string(),
time: z.object({
created: z.number(),
updated: z.number(),
compacting: z.number().optional(),
}),
revert: z.object({
messageID: z.string(),
partID: z.string().optional(),
snapshot: z.string().optional(),
diff: z.string().optional(),
}).optional(),
})
export const MessageSchema = z.object({
id: z.string(),
sessionID: z.string(),
role: z.enum(['user', 'assistant']),
time: z.object({
created: z.number(),
completed: z.number().optional(),
}),
})
export type FileDiff = z.infer<typeof FileDiffSchema>
export type Session = z.infer<typeof SessionSchema>
export type Message = z.infer<typeof MessageSchema>
+24
View File
@@ -0,0 +1,24 @@
import { z } from 'zod'
export const RepoStatusSchema = z.enum(['cloning', 'ready', 'error'])
export const RepoSchema = z.object({
id: z.number(),
repoUrl: z.string().url(),
localPath: z.string(),
fullPath: z.string(),
branch: z.string().optional(),
defaultBranch: z.string(),
cloneStatus: RepoStatusSchema,
clonedAt: z.number(),
lastPulled: z.number().optional(),
openCodeConfigName: z.string().optional(),
isWorktree: z.boolean().optional(),
})
export const CreateRepoRequestSchema = z.object({
repoUrl: z.string().url(),
branch: z.string().optional(),
openCodeConfigName: z.string().optional(),
useWorktree: z.boolean().optional(),
})
+102
View File
@@ -0,0 +1,102 @@
import { z } from "zod";
export const CustomCommandSchema = z.object({
name: z.string(),
description: z.string(),
promptTemplate: z.string(),
});
export const CustomAgentSchema = z.object({
name: z.string(),
description: z.string(),
config: z.record(z.string(), z.any()),
});
export const DEFAULT_KEYBOARD_SHORTCUTS = {
submit: "shift+Enter",
abort: "Escape",
undo: "ctrl+Z",
redo: "ctrl+R",
compact: "ctrl",
newSession: "ctrl+N",
toggleMode: "Tab",
selectModel: "ctrl+M",
};
export const UserPreferencesSchema = z.object({
theme: z.enum(["dark", "light", "system"]),
mode: z.enum(["plan", "build"]),
defaultModel: z.string().optional(),
defaultAgent: z.string().optional(),
autoScroll: z.boolean(),
showReasoning: z.boolean(),
expandToolCalls: z.boolean(),
keyboardShortcuts: z.record(z.string(), z.string()),
customCommands: z.array(CustomCommandSchema),
customAgents: z.array(CustomAgentSchema),
gitToken: z.string().optional(),
});
export const DEFAULT_USER_PREFERENCES = {
theme: "dark" as const,
mode: "build" as const,
autoScroll: true,
showReasoning: false,
expandToolCalls: false,
keyboardShortcuts: DEFAULT_KEYBOARD_SHORTCUTS,
customCommands: [],
customAgents: [],
gitToken: undefined,
};
export const SettingsResponseSchema = z.object({
preferences: UserPreferencesSchema,
updatedAt: z.number(),
});
export const UpdateSettingsRequestSchema = z.object({
preferences: UserPreferencesSchema.partial(),
});
export const OpenCodeConfigSchema = z.object({
$schema: z.string().optional(),
theme: z.string().optional(),
model: z.string().optional(),
small_model: z.string().optional(),
provider: z.record(z.string(), z.any()).optional(),
agent: z.record(z.string(), z.any()).optional(),
command: z.record(z.string(), z.any()).optional(),
keybinds: z.record(z.string(), z.any()).optional(),
autoupdate: z.boolean().optional(),
formatter: z.record(z.string(), z.any()).optional(),
permission: z.record(z.string(), z.any()).optional(),
mcp: z.record(z.string(), z.any()).optional(),
instructions: z.array(z.string()).optional(),
disabled_providers: z.array(z.string()).optional(),
share: z.string().optional(),
});
export const OpenCodeConfigMetadataSchema = z.object({
id: z.number(),
name: z.string().min(1).max(255),
content: OpenCodeConfigSchema,
isDefault: z.boolean(),
createdAt: z.number(),
updatedAt: z.number(),
});
export const CreateOpenCodeConfigRequestSchema = z.object({
name: z.string().min(1).max(255),
content: OpenCodeConfigSchema,
isDefault: z.boolean().optional(),
});
export const UpdateOpenCodeConfigRequestSchema = z.object({
content: OpenCodeConfigSchema,
isDefault: z.boolean().optional(),
});
export const OpenCodeConfigResponseSchema = z.object({
configs: z.array(OpenCodeConfigMetadataSchema),
defaultConfig: OpenCodeConfigMetadataSchema.nullable(),
});
+60
View File
@@ -0,0 +1,60 @@
import { z } from 'zod'
import {
UserPreferencesSchema,
SettingsResponseSchema,
UpdateSettingsRequestSchema,
CustomCommandSchema,
CustomAgentSchema,
OpenCodeConfigSchema,
OpenCodeConfigMetadataSchema,
CreateOpenCodeConfigRequestSchema,
UpdateOpenCodeConfigRequestSchema,
OpenCodeConfigResponseSchema,
} from '../schemas/settings'
import {
RepoSchema,
CreateRepoRequestSchema,
RepoStatusSchema,
} from '../schemas/repo'
import {
FileInfoSchema,
CreateFileRequestSchema,
RenameFileRequestSchema,
FileUploadResponseSchema,
} from '../schemas/files'
import {
SessionSchema,
MessageSchema,
} from '../schemas/opencode'
export type UserPreferences = z.infer<typeof UserPreferencesSchema>
export type SettingsResponse = z.infer<typeof SettingsResponseSchema>
export type UpdateSettingsRequest = z.infer<typeof UpdateSettingsRequestSchema>
export type CustomCommand = z.infer<typeof CustomCommandSchema>
export type CustomAgent = z.infer<typeof CustomAgentSchema>
export type OpenCodeConfig = z.infer<typeof OpenCodeConfigMetadataSchema>
export type OpenCodeConfigInput = z.infer<typeof OpenCodeConfigSchema>
export type CreateOpenCodeConfigRequest = z.infer<typeof CreateOpenCodeConfigRequestSchema>
export type UpdateOpenCodeConfigRequest = z.infer<typeof UpdateOpenCodeConfigRequestSchema>
export type OpenCodeConfigResponse = z.infer<typeof OpenCodeConfigResponseSchema>
export type Repo = z.infer<typeof RepoSchema>
export type CreateRepoRequest = z.infer<typeof CreateRepoRequestSchema>
export type RepoStatus = z.infer<typeof RepoStatusSchema>
export type FileInfo = z.infer<typeof FileInfoSchema>
export type CreateFileRequest = z.infer<typeof CreateFileRequestSchema>
export type RenameFileRequest = z.infer<typeof RenameFileRequestSchema>
export type FileUploadResponse = z.infer<typeof FileUploadResponseSchema>
export type Session = z.infer<typeof SessionSchema>
export type Message = z.infer<typeof MessageSchema>
export interface ErrorResponse {
error: string
details?: unknown
}
export interface SuccessResponse {
success: boolean
}