Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-harness/blob/main/cli/src/config.ts # omega-harness Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-harness / cli / src / config.ts` 203 lines ยท 5921 bytes Raw Blame History 1 import fs from 'node:fs'; 2 import os from 'node:os'; 3 import path from 'node:path'; 4 import { execFileSync } from 'node:child_process'; 5 import { fileURLToPath } from 'node:url'; 6 7 export type ApprovalMode = 'default' | 'auto-edit' | 'yolo' | 'omega-only'; 8 export type ProviderKind = 'inkling' | 'gemini'; 9 10 export interface OmegaConfig { 11 provider: ProviderKind; 12 endpoint: string; 13 apiKey?: string; 14 model: string; 15 approvalMode: ApprovalMode; 16 omcPath?: string; 17 harnessRoot: string; 18 defaultSkills: string[]; 19 } 20 21 export interface PersistedConfig { 22 provider?: ProviderKind; 23 endpoint?: string; 24 apiKey?: string; 25 model?: string; 26 approvalMode?: ApprovalMode; 27 omcPath?: string; 28 defaultSkills?: string[]; 29 } 30 31 export const DEFAULT_PROVIDER: ProviderKind = 'inkling'; 32 export const DEFAULT_INKLING_ENDPOINT = 'http://127.0.0.1:8080'; 33 export const DEFAULT_INKLING_MODEL = 'inkling-2-mini'; 34 export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro'; 35 36 export const RECOMMENDED_MODELS: Record> = { 37 inkling: [ 38 { id: 'inkling-2-mini', note: 'Inkling-2-Mini (pure seeded-Omega GB10 zero-CUDA server)' }, 39 ], 40 gemini: [ 41 { id: 'gemini-2.5-pro', note: 'Best for complex Omega & systems engineering' }, 42 { id: 'gemini-2.5-flash', note: 'Fast everyday coding & iteration' }, 43 { id: 'gemini-2.5-flash-lite', note: 'Lightweight, lowest latency' }, 44 { id: 'gemini-3-pro-preview', note: 'Preview next-gen reasoning' }, 45 ], 46 }; 47 48 export function getConfigDir(): string { 49 const xdg = process.env.XDG_CONFIG_HOME; 50 return path.join(xdg || path.join(os.homedir(), '.config'), 'omega-harness'); 51 } 52 53 export function getConfigPath(): string { 54 return path.join(getConfigDir(), 'config.json'); 55 } 56 57 export function detectHarnessRoot(): string { 58 if (process.env.OMEGA_HARNESS_ROOT && fs.existsSync(process.env.OMEGA_HARNESS_ROOT)) { 59 return path.resolve(process.env.OMEGA_HARNESS_ROOT); 60 } 61 const thisDir = path.dirname(fileURLToPath(import.meta.url)); 62 const candidate = path.resolve(thisDir, '..', '..'); 63 if (fs.existsSync(path.join(candidate, 'PIN')) && fs.existsSync(path.join(candidate, 'skills'))) { 64 return candidate; 65 } 66 const fallback = path.join(os.homedir(), 'workspace', 'omega-harness'); 67 if (fs.existsSync(path.join(fallback, 'skills'))) { 68 return fallback; 69 } 70 return candidate; 71 } 72 73 export function detectOmcPath(configured?: string): string | undefined { 74 const candidates = [ 75 process.env.OMEGA_OMC, 76 process.env.OMC, 77 configured, 78 path.join(os.homedir(), '.local', 'bin', 'omc'), 79 path.join(os.homedir(), '.local', 'share', 'aien-omega', 'omc'), 80 ].filter((p): p is string => Boolean(p)); 81 82 for (const c of candidates) { 83 try { 84 fs.accessSync(c, fs.constants.X_OK); 85 return c; 86 } catch { 87 // keep searching 88 } 89 } 90 91 try { 92 const found = execFileSync('which', ['omc'], { 93 encoding: 'utf8', 94 stdio: ['ignore', 'pipe', 'ignore'], 95 }).trim(); 96 if (found) return found; 97 } catch { 98 // not in PATH 99 } 100 return undefined; 101 } 102 103 export function readPersistedConfig(): PersistedConfig { 104 const cfgPath = getConfigPath(); 105 try { 106 const raw = fs.readFileSync(cfgPath, 'utf8'); 107 const parsed = JSON.parse(raw); 108 if (parsed && typeof parsed === 'object') { 109 return parsed as PersistedConfig; 110 } 111 } catch { 112 // missing or invalid config 113 } 114 return {}; 115 } 116 117 export function writePersistedConfig(patch: Partial): void { 118 const dir = getConfigDir(); 119 fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); 120 const current = readPersistedConfig(); 121 const next: PersistedConfig = { ...current, ...patch }; 122 const cfgPath = getConfigPath(); 123 fs.writeFileSync(cfgPath, JSON.stringify(next, null, 2) + '\n', { mode: 0o600 }); 124 } 125 126 export function loadConfig(overrides: Partial = {}): OmegaConfig { 127 const persisted = readPersistedConfig(); 128 129 const envProvider = process.env.OMEGA_PROVIDER?.toLowerCase(); 130 const provider: ProviderKind = 131 overrides.provider || 132 (envProvider === 'gemini' || envProvider === 'inkling' ? envProvider : undefined) || 133 persisted.provider || 134 DEFAULT_PROVIDER; 135 136 const endpoint = ( 137 overrides.endpoint || 138 process.env.INKLING_URL || 139 process.env.OMEGA_ENDPOINT || 140 persisted.endpoint || 141 DEFAULT_INKLING_ENDPOINT 142 ).replace(/\/+$/, ''); 143 144 const apiKey = 145 overrides.apiKey || 146 (provider === 'inkling' 147 ? process.env.INKLING_API_KEY 148 : process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY) || 149 persisted.apiKey; 150 151 const defaultModelForProvider = 152 provider === 'inkling' ? DEFAULT_INKLING_MODEL : DEFAULT_GEMINI_MODEL; 153 154 const model = 155 overrides.model || 156 process.env.OMEGA_MODEL || 157 (provider === 'inkling' ? process.env.INKLING_MODEL : process.env.GEMINI_MODEL) || 158 persisted.model || 159 defaultModelForProvider; 160 161 const approvalMode: ApprovalMode = 162 overrides.approvalMode || 163 persisted.approvalMode || 164 'default'; 165 166 const harnessRoot = overrides.harnessRoot || detectHarnessRoot(); 167 const omcPath = detectOmcPath(overrides.omcPath || persisted.omcPath); 168 const defaultSkills = overrides.defaultSkills || persisted.defaultSkills || []; 169 170 return { 171 provider, 172 endpoint, 173 apiKey, 174 model, 175 approvalMode, 176 omcPath, 177 harnessRoot, 178 defaultSkills, 179 }; 180 } 181 182 export function formatShortPath(p: string): string { 183 const home = os.homedir(); 184 if (p === home) return '~'; 185 if (p.startsWith(home + path.sep)) { 186 return '~' + p.slice(home.length); 187 } 188 return p; 189 } 190 191 export function detectGitBranch(cwd: string): string | undefined { 192 try { 193 const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { 194 cwd, 195 encoding: 'utf8', 196 stdio: ['ignore', 'pipe', 'ignore'], 197 timeout: 1500, 198 }).trim(); 199 return branch || undefined; 200 } catch { 201 return undefined; 202 } 203 }