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
address PR review: fix 9 issues from copilot review
Adam Eivy7b7e317a58aa
diff --git a/server/integrations/moltworld/api.js b/server/integrations/moltworld/api.jsindex 4714057dbd..602aeec556 100644--- a/server/integrations/moltworld/api.js+++ b/server/integrations/moltworld/api.js@@ -164,7 +164,10 @@ export async function getBalance(agentId) {export async function joinWorld(agentId, options = {}) {const rateCheck = checkRateLimit(agentId, 'join');if (!rateCheck.allowed) {- throw new Error(`Rate limited: ${rateCheck.reason}`);+ const err = new Error(`Rate limited: ${rateCheck.reason}`);+ err.status = 429;+ err.waitMs = rateCheck.waitMs;+ throw err;}const body = { agentId, ...options };@@ -186,7 +189,10 @@ export async function joinWorld(agentId, options = {}) {export async function think(agentId, thought) {const rateCheck = checkRateLimit(agentId, 'think');if (!rateCheck.allowed) {- throw new Error(`Rate limited: ${rateCheck.reason}`);+ const err = new Error(`Rate limited: ${rateCheck.reason}`);+ err.status = 429;+ err.waitMs = rateCheck.waitMs;+ throw err;}const result = await request('/api/world/think', {@@ -212,7 +218,10 @@ export async function think(agentId, thought) {export async function build(agentId, options = {}) {const rateCheck = checkRateLimit(agentId, 'build');if (!rateCheck.allowed) {- throw new Error(`Rate limited: ${rateCheck.reason}`);+ const err = new Error(`Rate limited: ${rateCheck.reason}`);+ err.status = 429;+ err.waitMs = rateCheck.waitMs;+ throw err;}const result = await request('/api/world/build', {diff --git a/server/lib/validation.js b/server/lib/validation.jsindex c0e56ae90b..86bc7a12e4 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -366,6 +366,17 @@ export const moltworldWsInteractSchema = z.object({payload: z.record(z.unknown()).optional().default({})});+export const moltworldQueueActionTypeSchema = z.enum([+ 'mw_explore', 'mw_build', 'mw_say', 'mw_think', 'mw_heartbeat', 'mw_interact'+]);++export const moltworldQueueAddSchema = z.object({+ agentId: z.string().min(1),+ actionType: moltworldQueueActionTypeSchema,+ params: z.record(z.unknown()).optional().default({}),+ scheduledFor: z.string().datetime().optional().nullable()+});+/*** Validate data against a schema* Returns { success: true, data } or { success: false, errors }diff --git a/server/routes/cos.js b/server/routes/cos.jsindex 855290c0d7..f820b1ba61 100644--- a/server/routes/cos.js+++ b/server/routes/cos.js@@ -258,7 +258,11 @@ router.post('/agents/:id/feedback', asyncHandler(async (req, res) => {const result = await cos.submitAgentFeedback(req.params.id, { rating, comment });if (result?.error) {- throw new ServerError(result.error, { status: 404, code: 'NOT_FOUND' });+ const isNotFound = result.error === 'Agent not found';+ throw new ServerError(result.error, {+ status: isNotFound ? 404 : 400,+ code: isNotFound ? 'NOT_FOUND' : 'INVALID_STATE'+ });}res.json(result);}));diff --git a/server/routes/moltworldTools.js b/server/routes/moltworldTools.jsindex 0cede02872..2503cb7ad6 100644--- a/server/routes/moltworldTools.js+++ b/server/routes/moltworldTools.js@@ -7,7 +7,7 @@import { Router } from 'express';import { asyncHandler, ServerError } from '../lib/errorHandler.js';-import { validate, moltworldJoinSchema, moltworldBuildSchema, moltworldExploreSchema, moltworldThinkSchema, moltworldSaySchema } from '../lib/validation.js';+import { validate, moltworldJoinSchema, moltworldBuildSchema, moltworldExploreSchema, moltworldThinkSchema, moltworldSaySchema, moltworldQueueAddSchema } from '../lib/validation.js';import * as platformAccounts from '../services/platformAccounts.js';import * as agentPersonalities from '../services/agentPersonalities.js';import * as agentActivity from '../services/agentActivity.js';@@ -262,12 +262,12 @@ router.get('/queue/:agentId', asyncHandler(async (req, res) => {// POST /queue — Add action to queuerouter.post('/queue', asyncHandler(async (req, res) => {- const { agentId, actionType, params, scheduledFor } = req.body;- if (!agentId || !actionType) {- throw new ServerError('agentId and actionType required', { status: 400, code: 'VALIDATION_ERROR' });+ const { success, data, errors } = validate(moltworldQueueAddSchema, req.body);+ if (!success) {+ throw new ServerError('Validation failed', { status: 400, code: 'VALIDATION_ERROR', context: { errors } });}- console.log(`📋 POST /api/agents/tools/moltworld/queue agentId=${agentId} action=${actionType}`);- const item = moltworldQueue.addAction(agentId, actionType, params || {}, scheduledFor);+ console.log(`📋 POST /api/agents/tools/moltworld/queue agentId=${data.agentId} action=${data.actionType}`);+ const item = moltworldQueue.addAction(data.agentId, data.actionType, data.params, data.scheduledFor);res.json(item);}));diff --git a/server/services/goalProgress.js b/server/services/goalProgress.jsindex 12418b9169..9e423988ef 100644--- a/server/services/goalProgress.js+++ b/server/services/goalProgress.js@@ -9,12 +9,9 @@*/import { readFile } from 'fs/promises'-import { join, dirname } from 'path'-import { fileURLToPath } from 'url'+import { join } from 'path'import { readJSONFile, PATHS } from '../lib/fileUtils.js'-const __filename = fileURLToPath(import.meta.url)-const __dirname = dirname(__filename)const GOALS_FILE = join(PATHS.data, 'COS-GOALS.md')const LEARNING_FILE = join(PATHS.cos, 'learning.json')@@ -126,7 +123,6 @@ function calculateGoalProgress(goals, taskStats) {return goals.map(goal => {let totalTasks = 0let succeededTasks = 0- let recentActivity = 0 // Tasks in last 24h (approximated from streak/recent)// Sum up tasks matching this goal's task typesfor (const taskType of goal.mapping.taskTypes) {@@ -217,7 +213,7 @@ async function getGoalProgress() {async function getGoalProgressSummary() {const progress = await getGoalProgress()- // Return top 3 goals by activity for compact display+ // Return top 5 goals by activity for compact displayconst topGoals = progress.goals.sort((a, b) => b.metrics.totalTasks - a.metrics.totalTasks).slice(0, 5)diff --git a/server/services/moltworldQueue.js b/server/services/moltworldQueue.jsindex 2834cedd17..06b36f8283 100644--- a/server/services/moltworldQueue.js+++ b/server/services/moltworldQueue.js@@ -65,6 +65,10 @@ export function getFullQueue(agentId) {*/export function addAction(agentId, actionType, params = {}, scheduledFor = null) {const queue = getOrCreateQueue(agentId);+ const pendingCount = queue.filter(i => i.status === 'pending' || i.status === 'executing').length;+ if (pendingCount >= MAX_ITEMS_PER_AGENT) {+ throw new Error(`Queue full: ${pendingCount} pending/executing items (max ${MAX_ITEMS_PER_AGENT})`);+ }const item = {id: randomUUID(),agentId,diff --git a/server/services/moltworldWs.js b/server/services/moltworldWs.jsindex 59ff0059d2..a5b0eb33a0 100644--- a/server/services/moltworldWs.js+++ b/server/services/moltworldWs.js@@ -72,7 +72,9 @@ function scheduleReconnect() {reconnectAttempts++;setStatus('reconnecting');console.log(`🌐 Moltworld WS: reconnecting in ${Math.round(delay / 1000)}s (attempt ${reconnectAttempts})`);- reconnectTimer = setTimeout(() => doConnect(), delay);+ reconnectTimer = setTimeout(() => doConnect().catch(err => {+ console.error(`🌐 Moltworld WS: reconnect failed: ${err.message}`);+ }), delay);}function handleMessage(raw) {@@ -105,7 +107,7 @@ function handleMessage(raw) {agentActivity.logActivity({agentId: currentAgentId,accountId: currentAccountId,- action: 'moltworld:interaction',+ action: 'mw_interaction',params: { eventType, from: data.agentName || data.agentId },status: 'completed',result: { type: eventType, content: data.message || data.thought || '' },