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(server): restore missing ensureDir imports in 9 service files

Adam Eivyf94c5e62669b
diff --git a/server/services/browserService.js b/server/services/browserService.js
index 5dc157c6f1..9be162ccf5 100644
--- a/server/services/browserService.js
+++ b/server/services/browserService.js
@@ -4,22 +4,17 @@
* Stores config in data/browser-config.json
*/
-import { readFile, writeFile, mkdir } from 'fs/promises';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
+import { readFile, writeFile } from 'fs/promises';
+import { join } from 'path';
import { EventEmitter } from 'events';
-import { safeJSONParse } from '../lib/fileUtils.js';
+import { ensureDir, safeJSONParse, PATHS } from '../lib/fileUtils.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const PROJECT_ROOT = join(__dirname, '..', '..');
-const DATA_DIR = join(PROJECT_ROOT, 'data');
-const CONFIG_FILE = join(DATA_DIR, 'browser-config.json');
-const ECOSYSTEM_FILE = join(PROJECT_ROOT, 'ecosystem.config.cjs');
+const CONFIG_FILE = join(PATHS.data, 'browser-config.json');
+const ECOSYSTEM_FILE = join(PATHS.root, 'ecosystem.config.cjs');
export const browserEvents = new EventEmitter();
-const DEFAULT_PROFILE_DIR = join(DATA_DIR, 'browser-profile');
+const DEFAULT_PROFILE_DIR = PATHS.browserProfile;
const DEFAULT_CONFIG = {
cdpPort: 5556,
@@ -43,7 +38,7 @@ export async function loadConfig() {
}
export async function saveConfig(config) {
- await mkdir(DATA_DIR, { recursive: true });
+ await ensureDir(DATA_DIR);
cachedConfig = { ...DEFAULT_CONFIG, ...config };
await writeFile(CONFIG_FILE, JSON.stringify(cachedConfig, null, 2));
browserEvents.emit('config:changed', cachedConfig);
diff --git a/server/services/decisionLog.js b/server/services/decisionLog.js
index 1c9d998a88..06743c8a42 100644
--- a/server/services/decisionLog.js
+++ b/server/services/decisionLog.js
@@ -6,16 +6,13 @@
* This helps users understand CoS behavior and identify patterns.
*/
-import { writeFile, mkdir } from 'fs/promises';
+import { writeFile } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
-import { readJSONFile } from '../lib/fileUtils.js';
+import { join } from 'path';
+import { ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
import { cosEvents } from './cosEvents.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DATA_DIR = join(__dirname, '../../data/cos');
+const DATA_DIR = PATHS.cos;
const DECISION_FILE = join(DATA_DIR, 'decisions.json');
// In-memory cache for recent decisions (avoid excessive file I/O)
@@ -58,7 +55,7 @@ async function loadDecisions() {
}
if (!existsSync(DATA_DIR)) {
- await mkdir(DATA_DIR, { recursive: true });
+ await ensureDir(DATA_DIR);
}
decisionCache = await readJSONFile(DECISION_FILE, { ...DEFAULT_DATA });
diff --git a/server/services/digital-twin.js b/server/services/digital-twin.js
index bb80f62cca..83978227b2 100644
--- a/server/services/digital-twin.js
+++ b/server/services/digital-twin.js
@@ -9,10 +9,9 @@
* - CoS integration (digital twin context injection)
*/
-import { readFile, writeFile, unlink, readdir, mkdir, stat } from 'fs/promises';
+import { readFile, writeFile, unlink, readdir, stat } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname, basename } from 'path';
-import { fileURLToPath } from 'url';
+import { join, basename } from 'path';
import { v4 as uuidv4 } from 'uuid';
import EventEmitter from 'events';
import { getActiveProvider, getProviderById } from './providers.js';
@@ -22,11 +21,9 @@ import {
documentMetaSchema,
testHistoryEntrySchema
} from '../lib/digitalTwinValidation.js';
-import { safeJSONParse } from '../lib/fileUtils.js';
+import { ensureDir, safeJSONParse, PATHS } from '../lib/fileUtils.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DIGITAL_TWIN_DIR = join(__dirname, '../../data/digital-twin');
+const DIGITAL_TWIN_DIR = PATHS.digitalTwin;
const META_FILE = join(DIGITAL_TWIN_DIR, 'meta.json');
// Event emitter for digital twin data changes
@@ -271,7 +268,7 @@ function now() {
async function ensureSoulDir() {
if (!existsSync(DIGITAL_TWIN_DIR)) {
- await mkdir(DIGITAL_TWIN_DIR, { recursive: true });
+ await ensureDir(DIGITAL_TWIN_DIR);
console.log(`🧬 Created soul data directory: ${DIGITAL_TWIN_DIR}`);
}
}
diff --git a/server/services/feedbackLoop.js b/server/services/feedbackLoop.js
index b4dd173adf..5e31177011 100644
--- a/server/services/feedbackLoop.js
+++ b/server/services/feedbackLoop.js
@@ -6,17 +6,14 @@
* Tracks feedback patterns and adjusts document weights for confidence scoring.
*/
-import { readFile, writeFile, mkdir } from 'fs/promises';
+import { readFile, writeFile } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
+import { join } from 'path';
import { v4 as uuidv4 } from 'uuid';
-import { safeJSONParse } from '../lib/fileUtils.js';
+import { ensureDir, safeJSONParse, PATHS } from '../lib/fileUtils.js';
import { digitalTwinEvents } from './digital-twin.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DIGITAL_TWIN_DIR = join(__dirname, '../../data/digital-twin');
+const DIGITAL_TWIN_DIR = PATHS.digitalTwin;
const FEEDBACK_FILE = join(DIGITAL_TWIN_DIR, 'feedback.json');
function now() {
@@ -52,7 +49,7 @@ async function loadFeedback() {
async function saveFeedback(data) {
if (!existsSync(DIGITAL_TWIN_DIR)) {
- await mkdir(DIGITAL_TWIN_DIR, { recursive: true });
+ await ensureDir(DIGITAL_TWIN_DIR);
}
data.updatedAt = now();
await writeFile(FEEDBACK_FILE, JSON.stringify(data, null, 2));
diff --git a/server/services/taskLearning.js b/server/services/taskLearning.js
index d873f4388e..1453bb899c 100644
--- a/server/services/taskLearning.js
+++ b/server/services/taskLearning.js
@@ -6,19 +6,16 @@
* to provide smarter task prioritization and model selection.
*/
-import { writeFile, mkdir, rename } from 'fs/promises';
+import { writeFile, rename } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
+import { join } from 'path';
import { cosEvents, emitLog } from './cos.js';
-import { readJSONFile } from '../lib/fileUtils.js';
+import { ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
import { createMutex } from '../lib/asyncMutex.js';
const withLock = createMutex();
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DATA_DIR = join(__dirname, '../../data/cos');
+const DATA_DIR = PATHS.cos;
const LEARNING_FILE = join(DATA_DIR, 'learning.json');
/**
@@ -56,7 +53,7 @@ const DEFAULT_LEARNING_DATA = {
*/
async function loadLearningData() {
if (!existsSync(DATA_DIR)) {
- await mkdir(DATA_DIR, { recursive: true });
+ await ensureDir(DATA_DIR);
}
return readJSONFile(LEARNING_FILE, { ...DEFAULT_LEARNING_DATA });
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index afff3775d2..394de2ae6e 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -13,19 +13,16 @@
* - 'custom': Custom interval in milliseconds
*/
-import { writeFile, mkdir } from 'fs/promises';
+import { writeFile } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
+import { join } from 'path';
import { cosEvents, emitLog } from './cos.js';
-import { DAY, HOUR, readJSONFile } from '../lib/fileUtils.js';
+import { DAY, ensureDir, HOUR, readJSONFile, PATHS } from '../lib/fileUtils.js';
import { getAdaptiveCooldownMultiplier } from './taskLearning.js';
import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getActiveApps, getAppTaskTypeOverrides } from './apps.js';
import { PORTOS_UI_URL } from '../lib/ports.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DATA_DIR = join(__dirname, '../../data/cos');
+const DATA_DIR = PATHS.cos;
const SCHEDULE_FILE = join(DATA_DIR, 'task-schedule.json');
// Interval type constants
@@ -855,9 +852,9 @@ const DEFAULT_SCHEDULE = {
templates: []
};
-async function ensureDir() {
+async function ensureDataDir() {
if (!existsSync(DATA_DIR)) {
- await mkdir(DATA_DIR, { recursive: true });
+ await ensureDir(DATA_DIR);
}
}
@@ -950,7 +947,7 @@ function migrateScheduleV1toV2(schedule) {
* Load schedule data (auto-migrates from v1 if needed)
*/
export async function loadSchedule() {
- await ensureDir();
+ await ensureDataDir();
const loaded = await readJSONFile(SCHEDULE_FILE, null);
if (!loaded) {
@@ -1047,7 +1044,7 @@ export async function loadSchedule() {
}
async function saveSchedule(schedule) {
- await ensureDir();
+ await ensureDataDir();
schedule.lastUpdated = new Date().toISOString();
await writeFile(SCHEDULE_FILE, JSON.stringify(schedule, null, 2));
}
diff --git a/server/services/taskTemplates.js b/server/services/taskTemplates.js
index 63c397a955..80dd46ac3f 100644
--- a/server/services/taskTemplates.js
+++ b/server/services/taskTemplates.js
@@ -5,15 +5,12 @@
* Helps users quickly create tasks for frequently needed operations.
*/
-import { writeFile, mkdir } from 'fs/promises';
+import { writeFile } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
-import { readJSONFile } from '../lib/fileUtils.js';
+import { join } from 'path';
+import { ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DATA_DIR = join(__dirname, '../../data/cos');
+const DATA_DIR = PATHS.cos;
const TEMPLATES_FILE = join(DATA_DIR, 'task-templates.json');
// Built-in templates based on common task patterns
@@ -116,7 +113,7 @@ async function saveState(state) {
state.lastUpdated = new Date().toISOString();
if (!existsSync(DATA_DIR)) {
- await mkdir(DATA_DIR, { recursive: true });
+ await ensureDir(DATA_DIR);
}
await writeFile(TEMPLATES_FILE, JSON.stringify(state, null, 2));
diff --git a/server/services/taste-questionnaire.js b/server/services/taste-questionnaire.js
index d089a75024..ab0bbfb92a 100644
--- a/server/services/taste-questionnaire.js
+++ b/server/services/taste-questionnaire.js
@@ -6,19 +6,16 @@
* with branching follow-up questions based on responses.
*/
-import { readFile, writeFile, mkdir } from 'fs/promises';
+import { readFile, writeFile } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
+import { join } from 'path';
import { v4 as uuidv4 } from 'uuid';
-import { safeJSONParse } from '../lib/fileUtils.js';
+import { ensureDir, safeJSONParse, PATHS } from '../lib/fileUtils.js';
import { getActiveProvider, getProviderById } from './providers.js';
import { buildPrompt } from './promptService.js';
import { digitalTwinEvents } from './digital-twin.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DIGITAL_TWIN_DIR = join(__dirname, '../../data/digital-twin');
+const DIGITAL_TWIN_DIR = PATHS.digitalTwin;
const TASTE_PROFILE_FILE = join(DIGITAL_TWIN_DIR, 'taste-profile.json');
function now() {
@@ -415,7 +412,7 @@ async function loadTasteProfile() {
async function saveTasteProfile(profile) {
if (!existsSync(DIGITAL_TWIN_DIR)) {
- await mkdir(DIGITAL_TWIN_DIR, { recursive: true });
+ await ensureDir(DIGITAL_TWIN_DIR);
}
profile.updatedAt = now();
await writeFile(TASTE_PROFILE_FILE, JSON.stringify(profile, null, 2));
diff --git a/server/services/weeklyDigest.js b/server/services/weeklyDigest.js
index 693ff037c6..086903a4eb 100644
--- a/server/services/weeklyDigest.js
+++ b/server/services/weeklyDigest.js
@@ -6,17 +6,13 @@
* error patterns, and accomplishments.
*/
-import { writeFile, mkdir, readdir } from 'fs/promises';
+import { writeFile, readdir } from 'fs/promises';
import { existsSync } from 'fs';
-import { join, dirname } from 'path';
-import { fileURLToPath } from 'url';
+import { join } from 'path';
import { cosEvents, emitLog, getAgents, getAgentDates, getAgentsByDate } from './cos.js';
-import { readJSONFile, formatDuration } from '../lib/fileUtils.js';
+import { ensureDir, readJSONFile, formatDuration, PATHS } from '../lib/fileUtils.js';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const DATA_DIR = join(__dirname, '../../data/cos');
-const DIGESTS_DIR = join(DATA_DIR, 'digests');
+const DIGESTS_DIR = PATHS.digests;
/**
* Get the start of a week (Monday) for a given date
@@ -53,7 +49,7 @@ function getWeekId(date = new Date()) {
*/
async function ensureDigestDir() {
if (!existsSync(DIGESTS_DIR)) {
- await mkdir(DIGESTS_DIR, { recursive: true });
+ await ensureDir(DIGESTS_DIR);
}
}