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
fix: address Copilot review — dedup, streaks, rename fallback, tests
Adam Eivy5fb7b6292673
diff --git a/client/package-lock.json b/client/package-lock.jsonindex 74eb34eb2c..bef0e852a5 100644--- a/client/package-lock.json+++ b/client/package-lock.json@@ -1,12 +1,12 @@{"name": "portos-client",- "version": "1.0.2",+ "version": "1.0.3","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos-client",- "version": "1.0.2",+ "version": "1.0.3","dependencies": {"@dnd-kit/core": "^6.3.1","@dnd-kit/sortable": "^10.0.0",diff --git a/client/package.json b/client/package.jsonindex 7fd6d6e539..00e746811d 100644--- a/client/package.json+++ b/client/package.json@@ -1,6 +1,6 @@{"name": "portos-client",- "version": "1.0.2",+ "version": "1.0.3","private": true,"type": "module","scripts": {diff --git a/package-lock.json b/package-lock.jsonindex 0b94092294..54ca123e3a 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "portos",- "version": "1.0.2",+ "version": "1.0.3","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos",- "version": "1.0.2",+ "version": "1.0.3","license": "MIT","workspaces": ["packages/*",@@ -29,7 +29,7 @@},"client": {"name": "portos-client",- "version": "1.0.2",+ "version": "1.0.3","dependencies": {"@dnd-kit/core": "^6.3.1","@dnd-kit/sortable": "^10.0.0",@@ -9242,7 +9242,7 @@},"server": {"name": "portos-server",- "version": "1.0.1",+ "version": "1.0.3","dependencies": {"axios": "^1.7.9","cors": "^2.8.5",diff --git a/package.json b/package.jsonindex 2d5b46572f..41f5ebe837 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "portos",- "version": "1.0.2",+ "version": "1.0.3","private": true,"description": "Local dev machine App OS portal","author": "Adam Eivy (@antic|@atomantic)",diff --git a/server/package-lock.json b/server/package-lock.jsonindex 58f08608ee..d5d09c676e 100644--- a/server/package-lock.json+++ b/server/package-lock.json@@ -1,12 +1,12 @@{"name": "portos-server",- "version": "1.0.1",+ "version": "1.0.3","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos-server",- "version": "1.0.1",+ "version": "1.0.3","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --git a/server/package.json b/server/package.jsonindex c58dfca796..fcab2c21b5 100644--- a/server/package.json+++ b/server/package.json@@ -1,6 +1,6 @@{"name": "portos-server",- "version": "1.0.2",+ "version": "1.0.3","private": true,"type": "module","scripts": {diff --git a/server/routes/cos.js b/server/routes/cos.jsindex f94aab0faa..28434e2c8f 100644--- a/server/routes/cos.js+++ b/server/routes/cos.js@@ -208,7 +208,7 @@ router.post('/health/check', asyncHandler(async (req, res) => {res.json(result);}));-// GET /api/cos/agents - Get running agents (auto-cleans zombies)+// GET /api/cos/agents - Get state-resident agents (running + recently completed, auto-cleans zombies)router.get('/agents', asyncHandler(async (req, res) => {await cos.cleanupZombieAgents();const agents = await cos.getAgents();diff --git a/server/routes/cos.test.js b/server/routes/cos.test.jsindex 35be470f32..26f4e1441c 100644--- a/server/routes/cos.test.js+++ b/server/routes/cos.test.js@@ -25,6 +25,8 @@ vi.mock('../services/cos.js', () => ({runHealthCheck: vi.fn(),cleanupZombieAgents: vi.fn(),getAgents: vi.fn(),+ getAgentDates: vi.fn(),+ getAgentsByDate: vi.fn(),getAgent: vi.fn(),terminateAgent: vi.fn(),killAgent: vi.fn(),@@ -326,7 +328,7 @@ describe('CoS Routes', () => {});describe('GET /api/cos/agents', () => {- it('should return all agents after cleaning zombies', async () => {+ it('should return state-resident agents after cleaning zombies', async () => {cos.cleanupZombieAgents.mockResolvedValue({ cleaned: [], count: 0 });cos.getAgents.mockResolvedValue([{ id: 'agent-001', status: 'running' },@@ -341,6 +343,47 @@ describe('CoS Routes', () => {});});+ describe('GET /api/cos/agents/history', () => {+ it('should return available date buckets', async () => {+ cos.getAgentDates.mockResolvedValue([+ { date: '2026-02-25', count: 5 },+ { date: '2026-02-24', count: 3 }+ ]);++ const response = await request(app).get('/api/cos/agents/history');++ expect(response.status).toBe(200);+ expect(response.body.dates).toHaveLength(2);+ expect(response.body.dates[0]).toEqual({ date: '2026-02-25', count: 5 });+ });+ });++ describe('GET /api/cos/agents/history/:date', () => {+ it('should return agents for a valid date', async () => {+ cos.getAgentsByDate.mockResolvedValue([+ { id: 'agent-001', status: 'completed' }+ ]);++ const response = await request(app).get('/api/cos/agents/history/2026-02-25');++ expect(response.status).toBe(200);+ expect(response.body).toHaveLength(1);+ expect(cos.getAgentsByDate).toHaveBeenCalledWith('2026-02-25');+ });++ it('should return 400 for invalid date format', async () => {+ const response = await request(app).get('/api/cos/agents/history/not-a-date');++ expect(response.status).toBe(400);+ });++ it('should return 400 for partial date format', async () => {+ const response = await request(app).get('/api/cos/agents/history/2026-02');++ expect(response.status).toBe(400);+ });+ });+describe('GET /api/cos/agents/:id', () => {it('should return agent by ID', async () => {cos.getAgent.mockResolvedValue({ id: 'agent-001', status: 'running' });diff --git a/server/services/agentGateway.js b/server/services/agentGateway.jsindex 866ef20f29..5a730eccf4 100644--- a/server/services/agentGateway.js+++ b/server/services/agentGateway.js@@ -51,9 +51,6 @@ function cleanExpiredCache() {}}-// Run cache cleanup every 5 minutes-setInterval(cleanExpiredCache, 5 * 60 * 1000)-/*** Route a request through the gateway* Handles deduplication and cachingdiff --git a/server/services/cos.js b/server/services/cos.jsindex fe68db3153..b7b3ed5557 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -431,10 +431,11 @@ export async function getStatus() {// Count active agents from stateconst activeAgents = Object.values(state.agents).filter(a => a.status === 'running').length;- // Derive tasksCompleted from index (all completed agents on disk) + state,+ // Derive tasksCompleted from union of index (disk) + state completed agents,// since state.stats.tasksCompleted can drift after state resets- const stateCompleted = Object.values(state.agents).filter(a => a.status === 'completed').length;- const tasksCompleted = Math.max(state.stats.tasksCompleted, idx.size + stateCompleted);+ const stateCompletedIds = Object.keys(state.agents).filter(id => state.agents[id].status === 'completed');+ const stateOnlyCompleted = stateCompletedIds.filter(id => !idx.has(id)).length;+ const tasksCompleted = Math.max(state.stats.tasksCompleted, idx.size + stateOnlyCompleted);return {running: daemonRunning,@@ -2722,7 +2723,8 @@ export async function getAgent(agentId) {// For completed agents, read full output from fileif (agent.status === 'completed') {- const agentDir = getAgentDir(agentId);+ const dateStr = agent.completedAt?.slice(0, 10);+ const agentDir = dateStr ? getAgentDir(agentId, dateStr) : getAgentDir(agentId);const outputFile = join(agentDir, 'output.txt');if (existsSync(outputFile)) {const fullOutput = await readFile(outputFile, 'utf-8');@@ -3292,9 +3294,11 @@ function formatRelativeTime(timestamp) {/*** Archive stale completed agents from state.json.- * Agents are already persisted to disk (metadata.json) and the in-memory cache- * by completeAgent(), so removing them from state.json only reduces file bloat.- * They remain accessible via getAgents()/getAgent() through the cache.+ * Completed agents are already persisted to per-agent metadata files on disk+ * (metadata.json) by completeAgent(), so removing them from state.json only+ * reduces the size of the in-memory state and the state.json file.+ * Archived agents remain accessible via the date index (getAgentsByDate()/getAgent()),+ * which loads them from disk as needed; getAgents() returns only state.agents.*/export async function archiveStaleAgents() {return withStateLock(async () => {@@ -3327,9 +3331,18 @@ export async function archiveStaleAgents() {const targetDir = join(bucketDir, id);if (existsSync(flatDir) && !existsSync(targetDir)) {- // Write metadata then move+ // Write metadata then move (with cross-filesystem fallback)await writeFile(join(flatDir, 'metadata.json'), JSON.stringify(agentWithoutOutput, null, 2)).catch(() => {});- await rename(flatDir, targetDir).catch(() => {});+ await rename(flatDir, targetDir).catch(async () => {+ await mkdir(targetDir, { recursive: true });+ const files = await readdir(flatDir).catch(() => []);+ for (const file of files) {+ const content = await readFile(join(flatDir, file)).catch(() => null);+ if (content !== null) await writeFile(join(targetDir, file), content);+ }+ await rm(flatDir, { recursive: true }).catch(() => {});+ });+ if (!existsSync(targetDir)) continue; // Skip index update if move failed} else if (!existsSync(targetDir)) {await mkdir(targetDir, { recursive: true });await writeFile(join(targetDir, 'metadata.json'), JSON.stringify(agentWithoutOutput, null, 2)).catch(() => {});diff --git a/server/services/productivity.js b/server/services/productivity.jsindex 6db7082a9e..d83663d3f3 100644--- a/server/services/productivity.js+++ b/server/services/productivity.js@@ -441,27 +441,25 @@ export async function onTaskCompleted(agent) {else data.dailyHistory[dateStr].failures++;data.dailyHistory[dateStr].successRate = Math.round((data.dailyHistory[dateStr].successes / data.dailyHistory[dateStr].tasks) * 100);- // Update streaks- const today = getDateString();- if (data.streaks.lastActiveDate !== today) {- if (isConsecutiveDay(data.streaks.lastActiveDate, today)) {+ // Update streaks using agent's completion date (not "now")+ if (data.streaks.lastActiveDate !== dateStr) {+ if (isConsecutiveDay(data.streaks.lastActiveDate, dateStr)) {data.streaks.currentDaily++;} else {data.streaks.currentDaily = 1;}data.streaks.longestDaily = Math.max(data.streaks.longestDaily, data.streaks.currentDaily);- data.streaks.lastActiveDate = today;+ data.streaks.lastActiveDate = dateStr;}- const thisWeek = getWeekId();- if (data.streaks.lastActiveWeek !== thisWeek) {- if (isConsecutiveWeek(data.streaks.lastActiveWeek, thisWeek)) {+ if (data.streaks.lastActiveWeek !== weekId) {+ if (isConsecutiveWeek(data.streaks.lastActiveWeek, weekId)) {data.streaks.currentWeekly++;} else {data.streaks.currentWeekly = 1;}data.streaks.longestWeekly = Math.max(data.streaks.longestWeekly, data.streaks.currentWeekly);- data.streaks.lastActiveWeek = thisWeek;+ data.streaks.lastActiveWeek = weekId;}// Prune dailyHistory older than 90 daysdiff --git a/server/services/weeklyDigest.js b/server/services/weeklyDigest.jsindex 44b1ad8230..693ff037c6 100644--- a/server/services/weeklyDigest.js+++ b/server/services/weeklyDigest.js@@ -105,10 +105,12 @@ export async function generateWeeklyDigest(weekId = null) {const weekDates = dates.map(d => d.date).filter(d => getWeekId(new Date(d + 'T12:00:00')) === targetWeekId);- const dateAgents = await Promise.all(weekDates.map(d => getAgentsByDate(d)));- // Also include running agents from state that completed this week+ const flatDateAgents = (await Promise.all(weekDates.map(d => getAgentsByDate(d)))).flat();+ const dateAgentIds = new Set(flatDateAgents.map(a => a.id));+ // Also include state agents not yet in the date index (avoid double-counting)const stateAgents = await getAgents();- const allAgents = [...dateAgents.flat(), ...stateAgents];+ const dedupedStateAgents = stateAgents.filter(a => !dateAgentIds.has(a.id));+ const allAgents = [...flatDateAgents, ...dedupedStateAgents];const weekAgents = allAgents.filter(a => {if (!a.completedAt) return false;