Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(drivers): write engine config files that hold a provider key 0600
DeryFerd9d238a0a2be2
diff --git a/server/drivers/acp/droid.ts b/server/drivers/acp/droid.tsindex 394cb4650f..02d719e646 100644--- a/server/drivers/acp/droid.ts+++ b/server/drivers/acp/droid.ts@@ -3,7 +3,7 @@// not configure JSON-RPC sessions: -m/--model, --auto, -r/--reasoning-effort, and// --disable-builtin-skills are still validated, but session settings come from JSON-RPC requests."// So model and autonomy are set over the wire in configureSession (verified on droid 0.196.0).-import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";import { join } from "node:path";import { userHome } from "../../env-path.ts";@@ -43,6 +43,15 @@ export function droidInjectId(host: string, model: string): string {return `${INJECT_ID_PREFIX}${safe}`;}+/** A custom model carries its apiKey, so the settings file it lands in is the server user's alone. The mode+ * applies only when the write creates the file, so an existing one is chmodded too. */+function writeFactorySettings(path: string, settings: FactorySettings & Record<string, unknown>): void {+ writeFileSync(path, `${JSON.stringify(settings, null, 2)}\n`, { mode: 0o600 });+ try {+ chmodSync(path, 0o600);+ } catch {}+}+/** Upsert a BYOK custom model so session/set_model can reach the local host. */export function ensureDroidInjectModel(modelId: string,@@ -72,7 +81,7 @@ export function ensureDroidInjectModel(if (!match.id) {match.id = id;settings.customModels = custom;- writeFileSync(path, `${JSON.stringify(settings, null, 2)}\n`);+ writeFactorySettings(path, settings);}return match.id;}@@ -85,7 +94,7 @@ export function ensureDroidInjectModel(provider: "generic-chat-completion-api",});settings.customModels = custom;- writeFileSync(path, `${JSON.stringify(settings, null, 2)}\n`);+ writeFactorySettings(path, settings);return id;}diff --git a/server/drivers/acp/hermes.ts b/server/drivers/acp/hermes.tsindex 80c08bab29..ff14c57397 100644--- a/server/drivers/acp/hermes.ts+++ b/server/drivers/acp/hermes.ts@@ -1,7 +1,7 @@// Hermes Agent (Nous Research's `hermes acp`), custom-only. ACP ignores `hermes -m` (cmd_acp does not// forward it), and OPENAI_API_KEY makes provider:auto resolve to OpenRouter without its key ("HTTP 401:// Missing Authentication header"), so injects write providers.<host> and set_model `custom:<host>:<model>`.-import { accessSync, constants, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";+import { accessSync, chmodSync, constants, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";import { homedir } from "node:os";import { join } from "node:path";import { parse as parseYaml } from "yaml";@@ -83,7 +83,14 @@ export function ensureHermesInjectProvider(text = "";}const next = upsertHermesProvider(text, inject.host, host.baseUrl, hostApiKey(host, env));- if (next !== text) writeFileSync(path, next);+ // The provider entry carries its api key, so this file is the server user's alone: the mode applies only when+ // the write creates it, so an existing file is chmodded too.+ if (next !== text) {+ writeFileSync(path, next, { mode: 0o600 });+ try {+ chmodSync(path, 0o600);+ } catch {}+ }return hermesAcpModelId(modelId) ?? modelId;}diff --git a/server/drivers/acp/opencode-go.ts b/server/drivers/acp/opencode-go.tsindex 958b773d7e..3d9119166b 100644--- a/server/drivers/acp/opencode-go.ts+++ b/server/drivers/acp/opencode-go.ts@@ -1,5 +1,5 @@// OpenCode over ACP; Zen, Go, OpenRouter and local providers are models it discovers, not separate drivers.-import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";+import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";import { homedir } from "node:os";import { dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from "node:path";@@ -413,7 +413,12 @@ export function ensureOpenCodeInjectModel(models,};config.provider = providers;- writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`);+ // The provider entry carries its apiKey, so this file is the server user's alone: the mode applies only when+ // the write creates it, so an existing file is chmodded too.+ writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });+ try {+ chmodSync(path, 0o600);+ } catch {}return native;}