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

fix: address PR review feedback (round 4)

Adam Eivyf44c22d86b96
diff --git a/client/src/components/cos/tabs/ScheduleTab.jsx b/client/src/components/cos/tabs/ScheduleTab.jsx
index f77133c010..064c76dfdc 100644
--- a/client/src/components/cos/tabs/ScheduleTab.jsx
+++ b/client/src/components/cos/tabs/ScheduleTab.jsx
@@ -238,6 +238,10 @@ function TaskTypeRow({ taskType, config, onUpdate, onTrigger, onReset, category,
className="w-full bg-port-card border border-port-border rounded px-3 py-2 text-white text-sm"
>
<option value="">Default model</option>
+ {/* Show current model even if not in availableModels (e.g., provider not loaded yet) */}
+ {selectedModel && !availableModels.includes(selectedModel) && (
+ <option value={selectedModel}>{selectedModel}</option>
+ )}
{availableModels.map(model => (
<option key={model} value={model}>
{model}
diff --git a/docs/features/soul-system.md b/docs/features/soul-system.md
index b3cd4ad10d..5082aad6c8 100644
--- a/docs/features/soul-system.md
+++ b/docs/features/soul-system.md
@@ -8,9 +8,9 @@ LLMs can embody specific personas, but creating comprehensive identity documents
## Architecture
-- **Soul Service** (`server/services/soul.js`): Document management, testing, enrichment
-- **Soul Routes** (`server/routes/soul.js`): REST API endpoints
-- **Soul Page** (`client/src/pages/Soul.jsx`): Overview, Documents, Test, Enrich, Export tabs
+- **Digital Twin Service** (`server/services/digitalTwin.js`): Document management, testing, enrichment
+- **Digital Twin Routes** (`server/routes/digital-twin.js`): REST API endpoints mounted under `/api/digital-twin/*`
+- **Digital Twin Page** (`client/src/pages/DigitalTwin.jsx`): Overview, Documents, Test, Enrich, Export tabs
## Features
@@ -89,22 +89,22 @@ data/soul/
| Route | Description |
|-------|-------------|
-| GET /api/soul | Status summary |
-| GET /api/soul/documents | List documents |
-| POST /api/soul/documents | Create document |
-| PUT /api/soul/documents/:id | Update document |
-| DELETE /api/soul/documents/:id | Delete document |
-| GET /api/soul/tests | Get test suite |
-| POST /api/soul/tests/run | Run single-model tests |
-| POST /api/soul/tests/run-multi | Run multi-model tests |
-| GET /api/soul/enrich/categories | List enrichment categories |
-| POST /api/soul/enrich/question | Get next question |
-| POST /api/soul/enrich/answer | Submit answer |
-| POST /api/soul/export | Export soul |
-| GET /api/soul/validate/completeness | Check soul completeness |
-| POST /api/soul/validate/contradictions | Detect contradictions |
-| POST /api/soul/tests/generate | Generate dynamic tests |
-| POST /api/soul/analyze-writing | Analyze writing samples |
+| GET /api/digital-twin | Status summary |
+| GET /api/digital-twin/documents | List documents |
+| POST /api/digital-twin/documents | Create document |
+| PUT /api/digital-twin/documents/:id | Update document |
+| DELETE /api/digital-twin/documents/:id | Delete document |
+| GET /api/digital-twin/tests | Get test suite |
+| POST /api/digital-twin/tests/run | Run single-model tests |
+| POST /api/digital-twin/tests/run-multi | Run multi-model tests |
+| GET /api/digital-twin/enrich/categories | List enrichment categories |
+| POST /api/digital-twin/enrich/question | Get next question |
+| POST /api/digital-twin/enrich/answer | Submit answer |
+| POST /api/digital-twin/export | Export soul |
+| GET /api/digital-twin/validate/completeness | Check soul completeness |
+| POST /api/digital-twin/validate/contradictions | Detect contradictions |
+| POST /api/digital-twin/tests/generate | Generate dynamic tests |
+| POST /api/digital-twin/analyze-writing | Analyze writing samples |
## Related Features
diff --git a/server/cos-runner/index.js b/server/cos-runner/index.js
index 0782ec0650..6d386c728b 100644
--- a/server/cos-runner/index.js
+++ b/server/cos-runner/index.js
@@ -27,6 +27,26 @@ const PORT = process.env.PORT || 5558;
const HOST = process.env.HOST || '127.0.0.1';
const RUNS_DIR = join(ROOT_DIR, 'data/runs');
+// Allowlist of permitted CLI commands to prevent arbitrary code execution.
+// Only commands in this list can be spawned by the runner.
+const ALLOWED_COMMANDS = new Set([
+ 'claude',
+ 'aider',
+ 'codex',
+ 'copilot'
+]);
+
+/**
+ * Validate that a command is in the allowlist.
+ * Extracts the base command name from the full path.
+ */
+function isAllowedCommand(command) {
+ if (!command || typeof command !== 'string') return false;
+ // Extract base command name from full path (e.g., /usr/bin/claude -> claude)
+ const baseName = command.split('/').pop();
+ return ALLOWED_COMMANDS.has(baseName);
+}
+
// Active agent processes (in memory)
const activeAgents = new Map();
@@ -219,6 +239,12 @@ app.post('/spawn', async (req, res) => {
// Use new CLI params if provided, otherwise fallback to legacy Claude defaults
let command, spawnArgs;
if (cliCommand && cliArgs !== undefined) {
+ // Validate command against allowlist to prevent arbitrary code execution
+ if (!isAllowedCommand(cliCommand)) {
+ return res.status(400).json({
+ error: `Command not allowed: ${cliCommand}. Permitted commands: ${[...ALLOWED_COMMANDS].join(', ')}`
+ });
+ }
command = cliCommand;
// Normalize cliArgs to an array
if (Array.isArray(cliArgs)) {
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.js
index 8d3e0dc806..9f0d87e92b 100644
--- a/server/lib/fileUtils.js
+++ b/server/lib/fileUtils.js
@@ -5,7 +5,6 @@
*/
import { mkdir, readFile } from 'fs/promises';
-import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
@@ -31,6 +30,7 @@ export const PATHS = {
/**
* Ensure a directory exists, creating it recursively if needed.
+ * Uses mkdir with recursive: true which is idempotent and avoids TOCTOU races.
*
* @param {string} dir - Directory path to ensure exists
* @returns {Promise<void>}
@@ -40,9 +40,8 @@ export const PATHS = {
* await ensureDir('/custom/path/to/dir');
*/
export async function ensureDir(dir) {
- if (!existsSync(dir)) {
- await mkdir(dir, { recursive: true });
- }
+ // mkdir with recursive: true is idempotent - it succeeds if dir exists
+ await mkdir(dir, { recursive: true });
}
/**
@@ -170,11 +169,20 @@ export function safeJSONParse(str, defaultValue = null, { allowArray = true, log
* const items = await readJSONFile('./items.json', []);
*/
export async function readJSONFile(filePath, defaultValue = null, { allowArray = true, logError = true } = {}) {
- if (!existsSync(filePath)) {
+ let content;
+ try {
+ content = await readFile(filePath, 'utf-8');
+ } catch (err) {
+ // ENOENT = file doesn't exist, return default silently
+ if (err.code === 'ENOENT') {
+ return defaultValue;
+ }
+ // Log other I/O errors if requested
+ if (logError) {
+ console.error(`⚠️ Failed to read file ${filePath}: ${err.message}`);
+ }
return defaultValue;
}
-
- const content = await readFile(filePath, 'utf-8');
return safeJSONParse(content, defaultValue, { allowArray, logError, context: filePath });
}
@@ -220,10 +228,19 @@ export function safeJSONLParse(content, { logErrors = false, context = '' } = {}
* const entries = await readJSONLFile('./logs.jsonl');
*/
export async function readJSONLFile(filePath, { logErrors = false } = {}) {
- if (!existsSync(filePath)) {
+ let content;
+ try {
+ content = await readFile(filePath, 'utf-8');
+ } catch (err) {
+ // ENOENT = file doesn't exist, return empty array silently
+ if (err.code === 'ENOENT') {
+ return [];
+ }
+ // Log other I/O errors if requested
+ if (logErrors) {
+ console.error(`⚠️ Failed to read file ${filePath}: ${err.message}`);
+ }
return [];
}
-
- const content = await readFile(filePath, 'utf-8');
return safeJSONLParse(content, { logErrors, context: filePath });
}