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(cos): extract precondition helper, static import, fix JSDoc placement
Adam Eivy3b559acef836
diff --git a/server/services/cos.js b/server/services/cos.jsindex 87db5e99b0..33d1bc1d86 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -1930,10 +1930,6 @@ Use model: claude-opus-4-5-20251101 for thorough security analysis`* @param {Object} state - Current CoS state* @returns {Object} Generated task*/-/**- * Initialize pipeline runtime state on metadata if pipeline stages are configured.- * Mutates the metadata object in place.- *//*** Check if a pipeline stage's precondition is met.* Supports { fileExists: 'path' } and { fileNotExists: 'path' }.@@ -1953,6 +1949,25 @@ export function checkStagePrecondition(stage, repoPath) {return { passed: true };}+/**+ * Check stage 0 precondition after pipeline initialization.+ * Returns true if the task should be skipped (precondition failed).+ */+function shouldSkipForPrecondition(metadata, app, analysisType) {+ const stage0 = metadata.pipeline?.stages?.[0];+ if (!stage0?.precondition) return false;+ const check = checkStagePrecondition(stage0, app.repoPath);+ if (!check.passed) {+ emitLog('info', `⏭️ Skipping ${analysisType} for ${app.name}: ${check.reason}`, { appId: app.id, analysisType });+ return true;+ }+ return false;+}++/**+ * Initialize pipeline runtime state on metadata if pipeline stages are configured.+ * Mutates the metadata object in place.+ */function initializePipelineMetadata(metadata) {if (!metadata.pipeline?.stages?.length) return;metadata.pipeline = {@@ -2085,16 +2100,7 @@ async function generateManagedAppImprovementTask(app, state) {}initializePipelineMetadata(metadata);-- // Check stage 0 precondition before creating the task- const stage0 = metadata.pipeline?.stages?.[0];- if (stage0?.precondition) {- const check = checkStagePrecondition(stage0, app.repoPath);- if (!check.passed) {- emitLog('info', `⏭️ Skipping ${nextType} for ${app.name}: ${check.reason}`, { appId: app.id, analysisType: nextType });- return null;- }- }+ if (shouldSkipForPrecondition(metadata, app, nextType)) return null;const promptTemplate = metadata.pipeline?.stages? await taskSchedule.getStagePrompt(nextType, 0)@@ -2176,16 +2182,7 @@ async function generateManagedAppImprovementTaskForType(taskType, app, state) {}initializePipelineMetadata(metadata);-- // Check stage 0 precondition before creating the task- const stage0 = metadata.pipeline?.stages?.[0];- if (stage0?.precondition) {- const check = checkStagePrecondition(stage0, app.repoPath);- if (!check.passed) {- emitLog('info', `⏭️ Skipping ${taskType} for ${app.name}: ${check.reason}`, { appId: app.id, analysisType: taskType });- return null;- }- }+ if (shouldSkipForPrecondition(metadata, app, taskType)) return null;const promptTemplate = metadata.pipeline?.stages? await taskSchedule.getStagePrompt(taskType, 0)diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.jsindex 1033511953..547c6c98ed 100644--- a/server/services/subAgentSpawner.js+++ b/server/services/subAgentSpawner.js@@ -12,7 +12,7 @@ import { writeFile, mkdir, readFile, readdir, rm, stat } from 'fs/promises'; //import { existsSync } from 'fs';import { homedir } from 'os';import { v4 as uuidv4 } from 'uuid';-import { cosEvents, registerAgent, updateAgent, completeAgent, appendAgentOutput, getConfig, updateTask, addTask, emitLog, getTaskById } from './cos.js';+import { cosEvents, registerAgent, updateAgent, completeAgent, appendAgentOutput, getConfig, updateTask, addTask, emitLog, getTaskById, checkStagePrecondition } from './cos.js';import { startAppCooldown, markAppReviewCompleted } from './appActivity.js';import { isRunnerAvailable, spawnAgentViaRunner, terminateAgentViaRunner, killAgentViaRunner, getAgentStatsFromRunner, initCosRunnerConnection, onCosRunnerEvent, getActiveAgentsFromRunner, getRunnerHealth } from './cosRunnerClient.js';import { getActiveProvider, getProviderById, getAllProviders } from './providers.js';@@ -1827,7 +1827,6 @@ async function handlePipelineProgression(task, agentId, success) {// Check next stage's precondition before advancingif (nextStage.precondition && task.metadata.repoPath) {- const { checkStagePrecondition } = await import('./cos.js');const check = checkStagePrecondition(nextStage, task.metadata.repoPath);if (!check.passed) {await updateTask(task.id, {