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

refactor: deduplicate getDateString, HOUR, and DAY into shared fileUtils

Adam Eivy7d8633519cce
diff --git a/server/services/agentActivity.js b/server/services/agentActivity.js
index 7d75a78f75..6c4655dd23 100644
--- a/server/services/agentActivity.js
+++ b/server/services/agentActivity.js
@@ -9,7 +9,7 @@ import { readFile, writeFile, readdir } from 'fs/promises';
import { existsSync } from 'fs';
import { join } from 'path';
import EventEmitter from 'events';
-import { ensureDir, PATHS } from '../lib/fileUtils.js';
+import { ensureDir, getDateString, PATHS } from '../lib/fileUtils.js';
const AGENTS_DIR = PATHS.agentPersonalities;
const ACTIVITY_DIR = join(AGENTS_DIR, 'activity');
@@ -27,10 +27,6 @@ async function ensureActivityDir(agentId = null) {
}
}
-function getDateString(date = new Date()) {
- return date.toISOString().split('T')[0];
-}
-
function getActivityFilePath(agentId, date = new Date()) {
const dateStr = typeof date === 'string' ? date : getDateString(date);
return join(ACTIVITY_DIR, agentId, `${dateStr}.json`);
diff --git a/server/services/autonomousJobs.js b/server/services/autonomousJobs.js
index 9eb3320cb1..48063f6e91 100644
--- a/server/services/autonomousJobs.js
+++ b/server/services/autonomousJobs.js
@@ -20,7 +20,7 @@ import { fileURLToPath } from 'url'
import { v4 as uuidv4 } from 'uuid'
import { spawn } from 'child_process'
import { cosEvents } from './cosEvents.js'
-import { ensureDir, PATHS, readJSONFile } from '../lib/fileUtils.js'
+import { DAY, ensureDir, HOUR, PATHS, readJSONFile } from '../lib/fileUtils.js'
import { createMutex } from '../lib/asyncMutex.js'
import { checkAndPrompt as autobiographyCheckAndPrompt } from './autobiography.js'
@@ -90,9 +90,6 @@ const JOB_SKILL_MAP = {
'job-autobiography-prompt': 'autobiography-prompt'
}
-// Time constants
-const HOUR = 60 * 60 * 1000
-const DAY = 24 * HOUR
const WEEK = 7 * DAY
/**
diff --git a/server/services/productivity.js b/server/services/productivity.js
index f1739268aa..ed9730068b 100644
--- a/server/services/productivity.js
+++ b/server/services/productivity.js
@@ -8,7 +8,7 @@
import { writeFile } from 'fs/promises';
import { join } from 'path';
import { cosEvents, getAgents } from './cos.js';
-import { ensureDir, PATHS, readJSONFile } from '../lib/fileUtils.js';
+import { ensureDir, getDateString, PATHS, readJSONFile } from '../lib/fileUtils.js';
const DATA_DIR = PATHS.cos;
const PRODUCTIVITY_FILE = join(DATA_DIR, 'productivity.json');
@@ -64,13 +64,6 @@ async function saveProductivity(data) {
return data;
}
-/**
- * Get date string (YYYY-MM-DD) for a Date object
- */
-function getDateString(date = new Date()) {
- return date.toISOString().split('T')[0];
-}
-
/**
* Get week identifier (YYYY-WXX format)
*/
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index 6d506072c7..0e7b27214b 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -18,7 +18,7 @@ import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { cosEvents, emitLog } from './cos.js';
-import { readJSONFile } from '../lib/fileUtils.js';
+import { DAY, HOUR, readJSONFile } 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';
@@ -38,9 +38,6 @@ export const INTERVAL_TYPES = {
CUSTOM: 'custom' // Custom interval in milliseconds
};
-// Time constants in milliseconds
-const HOUR = 60 * 60 * 1000;
-const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
/**