Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: 3 Copilot findings on v1.54.0 PR (iter 6)

[._.]/ Adam Eivye871e90c71d5
diff --git a/server/lib/aiToolkit/prompts.js b/server/lib/aiToolkit/prompts.js
index 8f2cf459b0..39462203ad 100644
--- a/server/lib/aiToolkit/prompts.js
+++ b/server/lib/aiToolkit/prompts.js
@@ -13,6 +13,13 @@ export function createPromptsService(config = {}) {
let stageConfig = null;
let variables = null;
+ // mkdir -p the prompts dir before writes — on a fresh data directory the
+ // dir may not exist yet and writes to `stage-config.json` / `variables.json`
+ // would fail with ENOENT before the per-write `stagesDir` mkdir runs.
+ async function ensurePromptsDir() {
+ if (!existsSync(PROMPTS_PATH)) await mkdir(PROMPTS_PATH, { recursive: true });
+ }
+
async function loadPrompts() {
const configPath = join(PROMPTS_PATH, 'stage-config.json');
const varsPath = join(PROMPTS_PATH, 'variables.json');
@@ -88,6 +95,7 @@ export function createPromptsService(config = {}) {
async updateStageConfig(stageName, updatedConfig) {
if (!stageConfig) await loadPrompts();
stageConfig.stages[stageName] = { ...stageConfig.stages[stageName], ...updatedConfig };
+ await ensurePromptsDir();
await writeFile(join(PROMPTS_PATH, 'stage-config.json'), JSON.stringify(stageConfig, null, 2));
},
@@ -97,6 +105,7 @@ export function createPromptsService(config = {}) {
throw new Error(`Stage ${stageName} already exists`);
}
stageConfig.stages[stageName] = config;
+ await ensurePromptsDir();
await writeFile(join(PROMPTS_PATH, 'stage-config.json'), JSON.stringify(stageConfig, null, 2));
const stagesDir = join(PROMPTS_PATH, 'stages');
@@ -112,6 +121,7 @@ export function createPromptsService(config = {}) {
throw new Error(`Stage ${stageName} not found`);
}
delete stageConfig.stages[stageName];
+ await ensurePromptsDir();
await writeFile(join(PROMPTS_PATH, 'stage-config.json'), JSON.stringify(stageConfig, null, 2));
const templatePath = join(PROMPTS_PATH, 'stages', `${stageName}.md`);
@@ -134,6 +144,7 @@ export function createPromptsService(config = {}) {
async updateVariable(key, data) {
if (!variables) await loadPrompts();
variables.variables[key] = { ...variables.variables[key], ...data };
+ await ensurePromptsDir();
await writeFile(join(PROMPTS_PATH, 'variables.json'), JSON.stringify(variables, null, 2));
},
@@ -143,12 +154,14 @@ export function createPromptsService(config = {}) {
throw new Error(`Variable ${key} already exists`);
}
variables.variables[key] = data;
+ await ensurePromptsDir();
await writeFile(join(PROMPTS_PATH, 'variables.json'), JSON.stringify(variables, null, 2));
},
async deleteVariable(key) {
if (!variables) await loadPrompts();
delete variables.variables[key];
+ await ensurePromptsDir();
await writeFile(join(PROMPTS_PATH, 'variables.json'), JSON.stringify(variables, null, 2));
},
diff --git a/server/lib/aiToolkit/routes/runs.js b/server/lib/aiToolkit/routes/runs.js
index 791a7ef9a4..a9678f0f0c 100644
--- a/server/lib/aiToolkit/routes/runs.js
+++ b/server/lib/aiToolkit/routes/runs.js
@@ -1,4 +1,5 @@
import { Router } from 'express';
+import { runSchema, validate } from '../validation.js';
export function createRunsRoutes(runnerService, options = {}) {
const router = Router();
@@ -14,13 +15,20 @@ export function createRunsRoutes(runnerService, options = {}) {
}));
router.post('/', asyncHandler(async (req, res) => {
- const { providerId, model, prompt, workspacePath, workspaceName, timeout, screenshots } = req.body;
+ // Validate up front so invalid types (timeout: "abc", screenshots: "x")
+ // can't reach the runner — setTimeout would treat "abc" as 0 and kill
+ // the run immediately, and iterating a string `screenshots` would walk
+ // characters as individual paths.
+ const result = validate(runSchema, req.body);
+ if (!result.success) {
+ return res.status(400).json({ error: 'Invalid run data', details: result.errors });
+ }
+ const { providerId, model, prompt, workspacePath, workspaceName, timeout, screenshots } = result.data;
console.log(`🚀 POST /runs - provider: ${providerId}, model: ${model}, workspace: ${workspaceName}`);
if (!providerId) {
return res.status(400).json({ error: 'providerId is required' });
}
-
if (!prompt) {
return res.status(400).json({ error: 'prompt is required' });
}
diff --git a/server/lib/aiToolkit/validation.js b/server/lib/aiToolkit/validation.js
index 624e0432ee..03947ef320 100644
--- a/server/lib/aiToolkit/validation.js
+++ b/server/lib/aiToolkit/validation.js
@@ -1,6 +1,10 @@
import { z } from 'zod';
export const providerSchema = z.object({
+ // Sample providers post a stable id (e.g. 'codex') so the server can adopt
+ // them verbatim rather than slugifying the display name (which would turn
+ // 'Codex CLI' into 'codex-cli' and break id-keyed CLI argument handling).
+ id: z.string().regex(/^[a-z0-9][a-z0-9-]*$/, 'id must be lowercase alphanumeric with hyphens').max(80).optional(),
name: z.string().min(1).max(100),
type: z.enum(['cli', 'api']),
command: z.string().optional(),