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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor: eliminate DRY violations by using shared ensureDir from fileUtils
Adam Eivyf35ed396a88a
diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsxindex 45192e2c71..a3d5e0d361 100644--- a/client/src/components/Layout.jsx+++ b/client/src/components/Layout.jsx@@ -451,15 +451,19 @@ export default function Layout() {</header>{/* Main content */}- <main id="main-content" className={`flex-1 overflow-auto ${location.pathname.startsWith('/cos') || location.pathname.startsWith('/brain') || location.pathname.startsWith('/digital-twin') || location.pathname.startsWith('/agents') || location.pathname === '/shell' || location.pathname === '/city' ? '' : 'p-4 md:p-6'}`}>- {location.pathname.startsWith('/cos') || location.pathname.startsWith('/brain') || location.pathname.startsWith('/digital-twin') || location.pathname.startsWith('/agents') || location.pathname === '/shell' || location.pathname === '/city' ? (- <Outlet />- ) : (- <div className="max-w-7xl mx-auto">- <Outlet />- </div>- )}- </main>+ {(() => {+ const isFullWidth = location.pathname.startsWith('/cos') ||+ location.pathname.startsWith('/brain') ||+ location.pathname.startsWith('/digital-twin') ||+ location.pathname.startsWith('/agents') ||+ location.pathname === '/shell' ||+ location.pathname === '/city';+ return (+ <main id="main-content" className={`flex-1 overflow-auto ${isFullWidth ? '' : 'p-4 md:p-6'}`}>+ {isFullWidth ? <Outlet /> : <div className="max-w-7xl mx-auto"><Outlet /></div>}+ </main>+ );+ })()}</div></div>);diff --git a/server/services/appActivity.js b/server/services/appActivity.jsindex c4266d3130..248dcc7450 100644--- a/server/services/appActivity.js+++ b/server/services/appActivity.js@@ -5,15 +5,11 @@* Prevents the CoS from working on the same app in a loop.*/-import { writeFile, mkdir } from 'fs/promises';-import { existsSync } from 'fs';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';-import { readJSONFile } from '../lib/fileUtils.js';--const __filename = fileURLToPath(import.meta.url);-const __dirname = dirname(__filename);-const DATA_DIR = join(__dirname, '../../data/cos');+import { writeFile } from 'fs/promises';+import { join } from 'path';+import { ensureDir, PATHS, readJSONFile } from '../lib/fileUtils.js';++const DATA_DIR = PATHS.cos;const ACTIVITY_FILE = join(DATA_DIR, 'app-activity.json');const DEFAULT_ACTIVITY = {@@ -27,17 +23,15 @@ const DEFAULT_ACTIVITY = {/*** Ensure the data directory exists*/-async function ensureDir() {- if (!existsSync(DATA_DIR)) {- await mkdir(DATA_DIR, { recursive: true });- }+async function ensureDataDir() {+ await ensureDir(DATA_DIR);}/*** Load app activity data*/export async function loadAppActivity() {- await ensureDir();+ await ensureDataDir();const loaded = await readJSONFile(ACTIVITY_FILE, null);return loaded ? { ...DEFAULT_ACTIVITY, ...loaded } : { ...DEFAULT_ACTIVITY };@@ -47,7 +41,7 @@ export async function loadAppActivity() {* Save app activity data*/export async function saveAppActivity(activity) {- await ensureDir();+ await ensureDataDir();await writeFile(ACTIVITY_FILE, JSON.stringify(activity, null, 2));}diff --git a/server/services/autonomousJobs.js b/server/services/autonomousJobs.jsindex a93c345a0b..aec57d824a 100644--- a/server/services/autonomousJobs.js+++ b/server/services/autonomousJobs.js@@ -14,18 +14,14 @@* - Custom user-defined jobs*/-import { promises as fs } from 'fs'-import { existsSync } from 'fs'-import path from 'path'-import { fileURLToPath } from 'url'+import { writeFile } from 'fs/promises'+import { join } from 'path'import { v4 as uuidv4 } from 'uuid'import { cosEvents } from './cosEvents.js'-import { readJSONFile } from '../lib/fileUtils.js'+import { ensureDir, PATHS, readJSONFile } from '../lib/fileUtils.js'-const __filename = fileURLToPath(import.meta.url)-const __dirname = path.dirname(__filename)-const DATA_DIR = path.join(__dirname, '../../data/cos')-const JOBS_FILE = path.join(DATA_DIR, 'autonomous-jobs.json')+const DATA_DIR = PATHS.cos+const JOBS_FILE = join(DATA_DIR, 'autonomous-jobs.json')// Time constantsconst HOUR = 60 * 60 * 1000@@ -155,9 +151,7 @@ Report a project health summary when done.`,* Ensure data directory exists*/async function ensureDataDir() {- if (!existsSync(DATA_DIR)) {- await fs.mkdir(DATA_DIR, { recursive: true })- }+ await ensureDir(DATA_DIR)}/**@@ -221,7 +215,7 @@ function mergeWithDefaults(loaded) {async function saveJobs(data) {await ensureDataDir()data.lastUpdated = new Date().toISOString()- await fs.writeFile(JOBS_FILE, JSON.stringify(data, null, 2))+ await writeFile(JOBS_FILE, JSON.stringify(data, null, 2))}/**diff --git a/server/services/autonomousJobs.test.js b/server/services/autonomousJobs.test.jsindex 587ac18818..30d01c2cab 100644--- a/server/services/autonomousJobs.test.js+++ b/server/services/autonomousJobs.test.js@@ -6,15 +6,13 @@ vi.mock('./cosEvents.js', () => ({}))vi.mock('../lib/fileUtils.js', () => ({- readJSONFile: vi.fn()+ readJSONFile: vi.fn(),+ ensureDir: vi.fn().mockResolvedValue(),+ PATHS: { cos: '/mock/data/cos' }}))-vi.mock('fs', () => ({- existsSync: vi.fn().mockReturnValue(true),- promises: {- writeFile: vi.fn().mockResolvedValue(),- mkdir: vi.fn().mockResolvedValue()- }+vi.mock('fs/promises', () => ({+ writeFile: vi.fn().mockResolvedValue()}))// Import after mocksdiff --git a/server/services/productivity.js b/server/services/productivity.jsindex 164ddcdb34..65e1d3d9e3 100644--- a/server/services/productivity.js+++ b/server/services/productivity.js@@ -5,16 +5,12 @@* insights about optimal working times.*/-import { writeFile, mkdir } from 'fs/promises';-import { existsSync } from 'fs';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { writeFile } from 'fs/promises';+import { join } from 'path';import { cosEvents, getAgents } from './cos.js';-import { readJSONFile } from '../lib/fileUtils.js';+import { ensureDir, PATHS, readJSONFile } 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 PRODUCTIVITY_FILE = join(DATA_DIR, 'productivity.json');/**@@ -45,9 +41,7 @@ const DEFAULT_PRODUCTIVITY = {* Ensure data directory exists*/async function ensureDataDir() {- if (!existsSync(DATA_DIR)) {- await mkdir(DATA_DIR, { recursive: true });- }+ await ensureDir(DATA_DIR);}/**