UNPKG

trellis

Version:

Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications

49 lines (47 loc) 1.16 kB
// src/client/config.ts import { existsSync, readFileSync, writeFileSync } from "fs"; import { resolve, join } from "path"; var CONFIG_FILE = ".trellis-db.json"; function configPath(dir = ".") { return resolve(join(dir, CONFIG_FILE)); } function hasConfig(dir = ".") { return existsSync(configPath(dir)); } function readConfig(dir = ".") { const path = configPath(dir); if (!existsSync(path)) return null; try { return JSON.parse(readFileSync(path, "utf8")); } catch { throw new Error(`Failed to parse ${path}: invalid JSON`); } } function writeConfig(config, dir = ".") { const path = configPath(dir); writeFileSync(path, JSON.stringify(config, null, 2) + "\n", "utf8"); } function updateConfig(updates, dir = ".") { const existing = readConfig(dir) ?? { mode: "local" }; const merged = { ...existing, ...updates }; writeConfig(merged, dir); return merged; } function defaultLocalConfig(dbPath, opts = {}) { return { mode: "local", dbPath, port: 3e3, multiTenant: false, ...opts }; } export { CONFIG_FILE, configPath, hasConfig, readConfig, writeConfig, updateConfig, defaultLocalConfig };