AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-onlyapp/src/lib/engines.ts
1// Engine registry + discovery. An "engine" is whatever executes an AI run: direct provider APIs or an agent CLI.2import { execFile } from "node:child_process";3import fs from "node:fs";4import os from "node:os";5import path from "node:path";6import { db, getSetting, setSetting } from "./db";7import { credentialStatus } from "./providers";89const OC_HOME = process.env.ZCS_OPENCODE_HOME || path.join(os.homedir(), ".local/opencode/home");10const OC_BIN = process.env.ZCS_OPENCODE_BIN || path.join(os.homedir(), ".local/opencode/node_modules/.bin/opencode");11export const isFreeOcModel = (m: string) => /^opencode\/[\w.-]+$/.test(m) && (/-free$/.test(m) || m === "opencode/big-pickle");12const env = () => ({ PATH: process.env.PATH, HOME: OC_HOME, XDG_CONFIG_HOME: `${OC_HOME}/c`, XDG_DATA_HOME: `${OC_HOME}/d`, XDG_STATE_HOME: `${OC_HOME}/s`, XDG_CACHE_HOME: `${OC_HOME}/k`, NO_COLOR: "1" } as unknown as NodeJS.ProcessEnv);13const run = (args: string[], ms: number) => new Promise<string | null>(res => execFile(OC_BIN, args, { env: env(), timeout: ms, maxBuffer: 1_000_000 }, (e, out) => res(e ? null : String(out))));1415export type OcInfo = { installed: boolean; version: string | null; models: string[]; freeModels: string[]; checkedAt: string };16let cache: { at: number; v: OcInfo } | null = null;17export async function opencodeInfo(force = false): Promise<OcInfo> {18 if (!force && cache && Date.now() - cache.at < 300_000) return cache.v;19 let installed = false; try { fs.accessSync(OC_BIN, fs.constants.X_OK); installed = true; } catch {}20 const version = installed ? (await run(["--version"], 15_000))?.trim().replace(/^opencode\s+v?/i, "") ?? null : null;21 const models = installed && version ? (await run(["models"], 30_000))?.split("\n").map(s => s.trim()).filter(l => /^[\w.-]+\/[\w.:-]+$/.test(l)) ?? [] : [];22 const v = { installed, version, models, freeModels: models.filter(isFreeOcModel), checkedAt: new Date().toISOString() }; cache = { at: Date.now(), v }; return v;23}2425export type EngineId = "claude-code" | "opencode" | "anthropic" | "openai" | "codex";26export const DEFAULT_MODEL: Record<string, string> = { opencode: "opencode/big-pickle", anthropic: "claude-haiku-5-5", openai: "gpt-4o-mini", mock: "mock-1" };27export async function loadEngineSettings() {28 let order: string[] = ["opencode", "anthropic", "openai"]; try { order = JSON.parse(await getSetting("ai.fallback_order", JSON.stringify(order))); } catch {}29 return { default: await getSetting("engine.default", ""), consent: (await getSetting("engine.opencode.consent", "0")) === "1", fallbackEnabled: (await getSetting("ai.fallback_enabled", "0")) === "1", fallbackOrder: order };30}31export async function engineStatus(orgId: string) {32 const oc = await opencodeInfo(); const cs = await credentialStatus(orgId); const st = await loadEngineSettings();33 const direct = (id: "anthropic" | "openai", name: string, models: string[]) => ({ id, name, kind: "direct API", installed: true, ready: !!cs[id], state: cs[id] ? (cs[id].status === "verified" ? "ready" : "key stored (" + cs[id].status + ")") : "awaiting credentials", models, note: "Streaming adapter verified against protocol stubs. Never run against the real API: no key supplied." });34 return [35 { id: "opencode", name: "OpenCode", kind: "agent engine (CLI)", installed: oc.installed, version: oc.version, ready: oc.installed && st.consent && oc.freeModels.length > 0, state: !oc.installed ? "not installed" : !st.consent ? "installed — owner consent required" : "ready (free models)", models: oc.freeModels, note: "Runs `opencode run --standalone` as a child process: no listening port. Execution engine, not a sandbox. Only documented free models are enabled; paid providers need credentials that are not configured." },36 direct("anthropic", "Direct Anthropic API", ["claude-sonnet-5-5", "claude-opus-5-5", "claude-haiku-5-5"]),37 direct("openai", "Direct OpenAI API", ["gpt-4o", "gpt-4o-mini"]),38 { id: "claude-code", name: "Claude Code", kind: "agent engine (CLI)", installed: false, ready: false, state: "blocked", models: [], note: "Not used as an application engine: a Claude Code subscription login is not an application credential and is never read. Needs an API-key-based integration and an isolation runtime." },39 { id: "codex", name: "Codex", kind: "agent engine (CLI)", installed: false, ready: false, state: "planned", models: [], note: "Future integration; nothing installed." },40 ];41}42export async function activeSessions(orgId?: string) {43 return await db().prepare("SELECT s.id,s.title,s.provider,s.model,s.status,s.project_id,s.spent_usd,r.status run_status FROM ai_sessions s LEFT JOIN LATERAL (SELECT status FROM ai_runs WHERE session_id=s.id ORDER BY created_at DESC LIMIT 1) r ON true WHERE (s.status<>'idle' OR r.status IN ('queued','running','paused')) AND (?::text IS NULL OR s.org_id=?) ORDER BY s.updated_at DESC LIMIT 20").all(orgId ?? null, orgId ?? null);44}45export { setSetting };46
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 0eebc42 on master.
Approval requests
None pending.