an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
feat(settings): AI Engines config UI (BYOK keys + local endpoints)
Chaitanya Giri8e68ef86bce6
diff --git a/src/renderer/src/components/AddAgentModal.tsx b/src/renderer/src/components/AddAgentModal.tsxindex ded1cca9..2c0f5675 100644--- a/src/renderer/src/components/AddAgentModal.tsx+++ b/src/renderer/src/components/AddAgentModal.tsx@@ -763,6 +763,13 @@ export function AddAgentModal({ onClose, config, onConfigChange }: AddAgentModal</div></Row>}+ {(provider === 'opencode' || provider === 'crush' || provider === 'pi' || provider === 'qwen') && (+ <div style={{ fontSize: 12, color: 'var(--cth-ink-500)', lineHeight: '16px', margin: '2px 0 6px' }}>+ BYOK keys & local endpoints for this engine live in <strong>Settings → AI Engines</strong>.+ Live end-to-end is pending real model calls (verify on-device).+ </div>+ )}+<Row label={config.autoMode && preset.autoFlag ? 'Command (auto mode on)' : 'Command'}><inputvalue={command}diff --git a/src/renderer/src/components/AiEnginesSettings.tsx b/src/renderer/src/components/AiEnginesSettings.tsxnew file mode 100644index 00000000..f7f0803b--- /dev/null+++ b/src/renderer/src/components/AiEnginesSettings.tsx@@ -0,0 +1,191 @@+import { useState, useEffect, type CSSProperties } from 'react';+import type { HarnessConfig, AgentProvider } from '@/store/config';+import { PixelButton } from './PixelButton';+import { ProviderLogo } from './ProviderLogo';++/**+ * AiEnginesSettings — the v0.3.1 per-provider config surface for the BYOK CLI+ * engines (OpenCode · Crush · pi.dev · Qwen). Two stores by what the datum is:+ * - API keys → WRITE-ONLY in the secret broker (`providerKey:*` IPC). Keyed by the+ * BACKEND model-provider (anthropic/openai/…). The field shows only set/not-set;+ * the plaintext is never read back to the renderer (materialized MAIN-only at spawn).+ * - Local base-URL + default model → HarnessConfig (`providerBaseUrls` /+ * `providerDefaultModels`), keyed by CLI provider. Non-secret; normal config save.+ * See hive/shared/cli-agents/settings-ui-schema.md.+ */++/** Backend model-providers whose keys the CLIs read from standard env vars. Must+ * match BACKEND_KEY_ENV in src/main/index.ts. */+const BACKENDS: Array<{ id: string; label: string; envVar: string }> = [+ { id: 'anthropic', label: 'Anthropic', envVar: 'ANTHROPIC_API_KEY' },+ { id: 'openai', label: 'OpenAI', envVar: 'OPENAI_API_KEY' },+ { id: 'google', label: 'Google · Gemini', envVar: 'GEMINI_API_KEY' },+ { id: 'openrouter', label: 'OpenRouter', envVar: 'OPENROUTER_API_KEY' },+ { id: 'groq', label: 'Groq', envVar: 'GROQ_API_KEY' }+];++/** CLI engines that take a per-provider local base-URL + default model. */+const CLIS: Array<{ id: AgentProvider; label: string; hint: string }> = [+ { id: 'opencode', label: 'OpenCode', hint: 'http://localhost:11434/v1 (Ollama) — injected as a local provider' },+ { id: 'crush', label: 'Crush', hint: 'OpenAI-compatible endpoint — used as the proxy upstream' },+ { id: 'pi', label: 'Pi', hint: 'local models are file-based (models.json); base-URL reserved' },+ { id: 'qwen', label: 'Qwen', hint: 'OpenAI-compatible endpoint — used as the proxy upstream' }+];++const inputStyle: CSSProperties = {+ width: '100%',+ padding: '6px 8px 4px',+ background: 'var(--cth-paper-100)',+ border: 'none',+ boxShadow: 'inset 0 0 0 1px var(--cth-ink-700)',+ fontFamily: 'var(--cth-font-ui)',+ fontSize: 14,+ color: 'var(--cth-ink-900)',+ outline: 'none'+};+const labelStyle: CSSProperties = {+ fontFamily: 'var(--cth-font-display)',+ fontSize: 8,+ lineHeight: '12px',+ color: 'var(--cth-ink-700)',+ textTransform: 'uppercase'+};+const headStyle: CSSProperties = {+ fontFamily: 'var(--cth-font-display)', fontSize: 8, lineHeight: '12px',+ color: 'var(--cth-ink-500)', textTransform: 'uppercase', marginBottom: 2+};++export function AiEnginesSettings({ config }: { config: HarnessConfig }) {+ // Which backends already have a key stored (boolean only — never the value).+ const [hasKey, setHasKey] = useState<Record<string, boolean>>({});+ const [draftKey, setDraftKey] = useState<Record<string, string>>({});+ const [note, setNote] = useState<Record<string, string>>({});+ // Base-URL + default-model drafts, seeded from config.+ const [baseUrls, setBaseUrls] = useState<Partial<Record<AgentProvider, string>>>(+ config.providerBaseUrls ?? {}+ );+ const [models, setModels] = useState<Partial<Record<AgentProvider, string>>>(+ config.providerDefaultModels ?? {}+ );++ // Reseed set/not-set flags on mount (write-only — only the boolean is fetched).+ useEffect(() => {+ let alive = true;+ (async () => {+ const out: Record<string, boolean> = {};+ for (const b of BACKENDS) {+ try { out[b.id] = await window.cth.providerKeyHas(b.id); } catch { out[b.id] = false; }+ }+ if (alive) setHasKey(out);+ })();+ return () => { alive = false; };+ }, []);++ const saveKey = async (backend: string) => {+ const key = (draftKey[backend] ?? '').trim();+ if (!key) return;+ try {+ const r = await window.cth.providerKeySet({ backend, key });+ if (r.ok) {+ setHasKey((s) => ({ ...s, [backend]: true }));+ setDraftKey((s) => ({ ...s, [backend]: '' }));+ setNote((s) => ({ ...s, [backend]: 'saved' }));+ } else setNote((s) => ({ ...s, [backend]: r.error ?? 'failed' }));+ } catch (e) { setNote((s) => ({ ...s, [backend]: e instanceof Error ? e.message : String(e) })); }+ };+ const clearKey = async (backend: string) => {+ try {+ await window.cth.providerKeyClear(backend);+ setHasKey((s) => ({ ...s, [backend]: false }));+ setNote((s) => ({ ...s, [backend]: 'cleared' }));+ } catch { /* noop */ }+ };++ const saveBaseUrl = async (id: AgentProvider, value: string) => {+ const next = { ...baseUrls, [id]: value.trim() || undefined };+ setBaseUrls(next);+ try { await window.cth.updateConfig({ providerBaseUrls: next }); } catch { /* noop */ }+ };+ const saveModel = async (id: AgentProvider, value: string) => {+ const next = { ...models, [id]: value.trim() || undefined };+ setModels(next);+ try { await window.cth.updateConfig({ providerDefaultModels: next }); } catch { /* noop */ }+ };++ return (+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>+ <div>+ <div style={headStyle}>AI ENGINE PROVIDERS (BYOK)</div>+ <div style={{ fontSize: 13, color: 'var(--cth-ink-700)', lineHeight: '18px' }}>+ API keys + local endpoints for the OpenCode, Crush, pi.dev and Qwen engines.+ Keys are stored <strong>write-only</strong> (encrypted at rest; never shown again)+ and used only when those engines spawn. Claude Code and Codex use their own login.+ </div>+ </div>++ {/* Backend API keys (write-only) */}+ <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>+ <div style={headStyle}>API KEYS</div>+ {BACKENDS.map((b) => (+ <div key={b.id} style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>+ <label style={labelStyle}>+ {b.label} {hasKey[b.id] ? '· set ✓' : ''} <span style={{ opacity: 0.6 }}>({b.envVar})</span>+ </label>+ <div style={{ display: 'flex', gap: 6, alignItems: 'center' }}>+ <input+ type="password"+ autoComplete="off"+ placeholder={hasKey[b.id] ? '•••••••• (stored — type to replace)' : `paste ${b.label} key`}+ value={draftKey[b.id] ?? ''}+ onChange={(e) => setDraftKey((s) => ({ ...s, [b.id]: e.target.value }))}+ style={inputStyle}+ />+ <PixelButton variant="secondary" size="sm" onClick={() => saveKey(b.id)}>Save</PixelButton>+ {hasKey[b.id] && (+ <PixelButton variant="secondary" size="sm" onClick={() => clearKey(b.id)}>Clear</PixelButton>+ )}+ </div>+ {note[b.id] && <div style={{ fontSize: 11, color: 'var(--cth-ink-500)' }}>{note[b.id]}</div>}+ </div>+ ))}+ </div>++ {/* Per-CLI local endpoint + default model */}+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>+ <div style={headStyle}>LOCAL ENDPOINT · DEFAULT MODEL (PER ENGINE)</div>+ {CLIS.map((c) => (+ <div key={c.id} style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>+ <label style={{ ...labelStyle, display: 'flex', alignItems: 'center', gap: 6 }}>+ <ProviderLogo provider={c.id} size={12} /> {c.label}+ </label>+ <div style={{ display: 'flex', gap: 6 }}>+ <input+ placeholder={`base-URL — ${c.hint}`}+ defaultValue={baseUrls[c.id] ?? ''}+ onBlur={(e) => saveBaseUrl(c.id, e.target.value)}+ style={inputStyle}+ />+ <input+ placeholder="default model (provider/model)"+ defaultValue={models[c.id] ?? ''}+ onBlur={(e) => saveModel(c.id, e.target.value)}+ style={{ ...inputStyle, maxWidth: 220 }}+ />+ </div>+ </div>+ ))}+ </div>++ {/* Unsandboxed-in-auto caveat (Pam guardrail #6) */}+ <div style={{+ fontSize: 12, color: 'var(--cth-ink-700)', lineHeight: '17px',+ padding: 8, boxShadow: 'inset 0 0 0 1px var(--cth-ink-300)', background: 'var(--cth-paper-100)'+ }}>+ ⚠ In <strong>auto mode</strong> these engines run with full filesystem + shell access+ (no sandbox) — like Claude's bypass mode. Turn auto mode off (General) to make them+ ask first. Live end-to-end verification with real model calls is pending your keys / a+ local LLM.+ </div>+ </div>+ );+}diff --git a/src/renderer/src/components/SettingsModal.tsx b/src/renderer/src/components/SettingsModal.tsxindex 5688f085..31c8c077 100644--- a/src/renderer/src/components/SettingsModal.tsx+++ b/src/renderer/src/components/SettingsModal.tsx@@ -7,6 +7,7 @@ import { Icon } from './Icon';import { OfficeThemePicker } from './OfficeThemePicker';import { McpDefaultsSettings } from './McpDefaultsSettings';import { IntegrationsRegistry } from './IntegrationsRegistry';+import { AiEnginesSettings } from './AiEnginesSettings';export interface SettingsModalProps {config: HarnessConfig;@@ -108,8 +109,8 @@ function clearLocalState(): void {} catch { /* noop */ }}-type Section = 'General' | 'MCP' | 'Integrations' | 'Danger Zone';-const NAV_SECTIONS: Section[] = ['General', 'MCP', 'Integrations', 'Danger Zone'];+type Section = 'General' | 'AI Engines' | 'MCP' | 'Integrations' | 'Danger Zone';+const NAV_SECTIONS: Section[] = ['General', 'AI Engines', 'MCP', 'Integrations', 'Danger Zone'];export function SettingsModal({ config, onClose }: SettingsModalProps) {const [confirming, setConfirming] = useState(false);@@ -795,6 +796,10 @@ export function SettingsModal({ config, onClose }: SettingsModalProps) {)}{/* MCP DEFAULTS */}+ {activeSection === 'AI Engines' && (+ <AiEnginesSettings config={config} />+ )}+{activeSection === 'MCP' && (<McpDefaultsSettings config={config} />)}