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(taskParser): centralize internal task ID prefix checks to fix ReferenceError
Adam Eivy871b2e318df7
diff --git a/server/lib/taskParser.js b/server/lib/taskParser.jsindex 7d124a2845..43b520118f 100644--- a/server/lib/taskParser.js+++ b/server/lib/taskParser.js@@ -28,6 +28,13 @@* - [ ] #sys-002 | MEDIUM | APPROVAL | Needs user approval*/+// Canonical prefix lists — add new prefixes here, not in scattered startsWith checks+const INTERNAL_PREFIXES = ['sys-', 'app-improve-'];+const ALL_KNOWN_PREFIXES = ['task-', ...INTERNAL_PREFIXES];++export const hasKnownPrefix = (id) => ALL_KNOWN_PREFIXES.some(p => id?.startsWith(p));+export const isInternalTaskId = (id) => INTERNAL_PREFIXES.some(p => id?.startsWith(p));+const STATUS_MAP = {'[ ]': 'pending','[~]': 'in_progress',@@ -56,7 +63,7 @@ function parseTaskLine(line) {const statusKey = `[${statusChar}]`;return {- id: id.startsWith('task-') || id.startsWith('sys-') || id.startsWith('app-improve-') ? id : `task-${id}`,+ id: hasKnownPrefix(id) ? id : `task-${id}`,status: STATUS_MAP[statusKey] || 'pending',priority: priority.toUpperCase(),priorityValue: PRIORITY_VALUES[priority.toUpperCase()] || 2,@@ -76,7 +83,7 @@ function parseTaskLine(line) {const statusKey = `[${statusChar}]`;return {- id: id.startsWith('task-') || id.startsWith('sys-') || id.startsWith('app-improve-') ? id : `task-${id}`,+ id: hasKnownPrefix(id) ? id : `task-${id}`,status: STATUS_MAP[statusKey] || 'pending',priority: priority.toUpperCase(),priorityValue: PRIORITY_VALUES[priority.toUpperCase()] || 2,@@ -308,7 +315,7 @@ export function updateTaskStatus(tasks, taskId, newStatus, metadata = {}) {*/export function addTask(tasks, { id, priority = 'MEDIUM', description, metadata = {} }) {const newTask = {- id: id.startsWith('task-') ? id : `task-${id}`,+ id: hasKnownPrefix(id) ? id : `task-${id}`,status: 'pending',priority: priority.toUpperCase(),priorityValue: PRIORITY_VALUES[priority.toUpperCase()] || 2,@@ -332,7 +339,7 @@ export function removeTask(tasks, taskId) {*/function isCriticalAutoFix(task) {const desc = (task.description || '').toLowerCase();- const isSysTask = task.id?.startsWith('sys-');+ const isSysTask = isInternalTaskId(task.id);const isCritical = task.priority === 'CRITICAL';const isHighPriorityFix = task.priority === 'HIGH' && (desc.includes('fix critical error') ||diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex 86dceeaf24..74024d032e 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -16,6 +16,7 @@ import { spawnAgentViaRunner, getActiveAgentsFromRunner, getRunnerHealth } fromimport { getActiveProvider, getAllProviders, getProviderById } from './providers.js';import { isProviderAvailable, markProviderUsageLimit, markProviderRateLimited, getFallbackProvider, getProviderStatus } from './providerStatus.js';import { PIPELINE_BEHAVIOR_FLAGS, MAX_TOTAL_SPAWNS } from '../lib/validation.js';+import { isInternalTaskId } from '../lib/taskParser.js';import { ensureDir, PATHS } from '../lib/fileUtils.js';import { getAppById } from './apps.js';import { createToolExecution, startExecution, completeExecution, errorExecution } from './toolStateMachine.js';@@ -87,8 +88,7 @@ export async function syncRunnerAgents() {if (!runnerAgents.has(agent.id)) {const task = taskMap.get(agent.taskId);- // Infer taskType for fallback: sys- and app-improve- prefix tasks are internal (CoS-generated)- const inferredType = (agent.taskId?.startsWith('sys-') || agent.taskId?.startsWith('app-improve-')) ? 'internal' : 'user';+ const inferredType = isInternalTaskId(agent.taskId) ? 'internal' : 'user';runnerAgents.set(agent.id, {taskId: agent.taskId,task: task || { id: agent.taskId, taskType: inferredType, description: 'Recovered from runner' },@@ -829,7 +829,7 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration// Ensure taskType is set — recovered agents may lack itif (task && !task.taskType) {const id = task.id || '';- task.taskType = (id.startsWith('sys-') || id.startsWith('app-improve-')) ? 'internal' : 'user';+ task.taskType = isInternalTaskId(id) ? 'internal' : 'user';}// Release execution lanediff --git a/server/services/agentManagement.js b/server/services/agentManagement.jsindex b122150aa0..31c68c8bff 100644--- a/server/services/agentManagement.js+++ b/server/services/agentManagement.js@@ -12,6 +12,7 @@ import { updateTask, addTask, getTaskById } from './cos.js';import { terminateAgentViaRunner, killAgentViaRunner, getAgentStatsFromRunner, getActiveAgentsFromRunner } from './cosRunnerClient.js';import { unregisterSpawnedAgent } from './agents.js';import { MAX_TOTAL_SPAWNS } from '../lib/validation.js';+import { isInternalTaskId } from '../lib/taskParser.js';import { activeAgents, runnerAgents, userTerminatedAgents, useRunner } from './agentState.js';import { cleanupAgentWorktree, syncRunnerAgents } from './agentLifecycle.js';import { cleanupOrphanedWorktrees } from './worktreeManager.js';@@ -300,7 +301,7 @@ export async function cleanupOrphanedAgents() {const stillAlive = await isPidAlive(agent.pid);if (stillAlive) {console.log(`🔄 Agent ${agent.id} (PID ${agent.pid}) still running, re-syncing to runner tracking`);- const inferredType = agent.taskId?.startsWith('sys-') ? 'internal' : 'user';+ const inferredType = isInternalTaskId(agent.taskId) ? 'internal' : 'user';runnerAgents.set(agent.id, {id: agent.id, pid: agent.pid, taskId: agent.taskId,task: { id: agent.taskId, taskType: inferredType, description: 'Re-synced from PID check' }