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([issue-711]): address codex+claude iter-2 review
Adam Eivy7eda839f95ff
diff --git a/server/services/brain.js b/server/services/brain.jsindex 922d55580c..e7eb9ce111 100644--- a/server/services/brain.js+++ b/server/services/brain.js@@ -141,15 +141,14 @@ export async function captureThought(text, providerOverride, modelOverride) {const mode = await getDomainAutonomyMode('brain');// Create initial inbox log entry. When auto-classify is off the entry goes- // straight to needs_review rather than the transient classifying state.+ // straight to needs_review rather than the transient classifying state — and+ // carries no `ai` metadata, since no provider/model was ever invoked.const inboxEntry = await storage.createInboxLog({capturedText: text,source: 'brain_ui',- ai: {- providerId: provider,- modelId: model,- promptTemplateId: 'brain-classifier'- },+ ...(mode === 'off'+ ? {}+ : { ai: { providerId: provider, modelId: model, promptTemplateId: 'brain-classifier' } }),status: mode === 'off' ? 'needs_review' : 'classifying'});diff --git a/server/services/cos.test.js b/server/services/cos.test.jsindex fce21e1248..b454d02f60 100644--- a/server/services/cos.test.js+++ b/server/services/cos.test.js@@ -42,6 +42,7 @@ const COS_SRC = readFileSync(join(__dirname, 'cos.js'), 'utf-8');// listener) stays in cos.js. Source-level guards below read each invariant from// whichever module now owns it.const GEN_SRC = readFileSync(join(__dirname, 'cosTaskGenerator.js'), 'utf-8');+const SCHED_SRC = readFileSync(join(__dirname, 'cosJobScheduler.js'), 'utf-8');// ─── Inline replicas of the cos.js priority + capacity slice ───────────────@@ -671,6 +672,19 @@ describe('cos.js source — priority + capacity invariants', () => {}});+ it('CoS auto-run domain gate (#711) covers the scheduled-job + improvement-check timers', () => {+ // executeScheduledJob and the cos-improvement-check timer are a THIRD+ // autonomous spawn path (outside dequeueNextTask / evaluateTasks). They must+ // also respect the cos guardrail, or off/dry-run leaks scheduled-job agents+ // and keeps mutating COS-TASKS.md via queueEligibleImprovementTasks.+ const execFn = extractFnBody(SCHED_SRC, SCHED_SRC.indexOf('export async function executeScheduledJob'));+ expect(execFn, 'executeScheduledJob must read the cos autonomy mode').toMatch(/getDomainMode\(\s*state\.config\s*,\s*['"]cos['"]\s*\)/);+ expect(execFn, 'executeScheduledJob must fence on execute').toMatch(/cosAutonomyMode\s*!==\s*['"]execute['"]/);+ // The improvement-check timer must gate its queueEligibleImprovementTasks call.+ expect(SCHED_SRC, 'improvement-check timer must gate queueing on cos === execute')+ .toMatch(/idleReviewEnabled\s*&&\s*getDomainMode\(\s*state\.config\s*,\s*['"]cos['"]\s*\)\s*===\s*['"]execute['"]/);+ });+it('both on-demand loops dedupe markAppReviewStarted per app via reviewStartedApps set', () => {// Multiple on-demand requests targeting the same app should mark its// activity record review-started only once per cycle — without the guard,diff --git a/server/services/cosJobScheduler.js b/server/services/cosJobScheduler.jsindex 9e3caf37fc..dbd66c480b 100644--- a/server/services/cosJobScheduler.js+++ b/server/services/cosJobScheduler.js@@ -25,6 +25,7 @@ import { schedule as scheduleEvent, cancel as cancelEvent, parseCronToNextRun }import { getUserTimezone, getLocalParts, nextLocalTime } from '../lib/timezone.js';import { formatDuration } from '../lib/fileUtils.js';import { loadState, isDaemonRunning } from './cosState.js';+import { getDomainMode } from '../lib/domainAutonomy.js';import { cosEvents, emitLog } from './cosEvents.js';import { getCosTasks } from './cosTaskStore.js';import { queueEligibleImprovementTasks } from './cosTaskGenerator.js';@@ -172,6 +173,20 @@ export async function executeScheduledJob(jobId) {return;}+ // Per-domain CoS auto-run gate: a SCHEDULED job firing automatically is an+ // autonomous action, so off/dry-run withhold it (dry-run logs what it would+ // have run). Manual /jobs/:id triggers run through runJobNow, not this path,+ // so explicit user intent is unaffected. Re-register so it fires once the+ // domain is dialed back to execute.+ const cosAutonomyMode = getDomainMode(state.config, 'cos');+ if (cosAutonomyMode !== 'execute') {+ if (cosAutonomyMode === 'dry-run') {+ emitLog('info', `[dry-run] CoS auto-run would fire scheduled job: ${job.name}`, { jobId, domainAutonomy: 'cos' });+ }+ await registerSingleJobSchedule(jobId);+ return;+ }+// Script jobs and shell jobs execute directly without spawning an AI agentif (isScriptJob(job)) {const scriptOk = await executeScriptJob(job).then(() => true, err => {@@ -338,7 +353,11 @@ export async function scheduleNextImprovementCheck() {if (paused) return;const state = await loadState();- if (state.config.idleReviewEnabled) {+ // Gate on the CoS auto-run domain: queueing improvement tasks mutates+ // COS-TASKS.md with autonomous internal work, so off/dry-run must not+ // queue (dry-run is purely a planning posture; the spawn-side gate+ // already withholds execution, but we also avoid the queue mutation).+ if (state.config.idleReviewEnabled && getDomainMode(state.config, 'cos') === 'execute') {const cosTaskData = await getCosTasks();await queueEligibleImprovementTasks(state, cosTaskData);cosEvents.emit('cos:dequeue-requested');diff --git a/server/services/telegram.js b/server/services/telegram.jsindex bb89a1ad6f..c51c45af06 100644--- a/server/services/telegram.js+++ b/server/services/telegram.js@@ -371,6 +371,13 @@ async function handleCallbackQuery(query) {* Forward a notification to Telegram*/async function forwardNotification(notification) {+ // Use cached forwardTypes to avoid disk I/O on every notification.+ // (Runs before the per-domain gate so a filtered-out notification skips the+ // state read entirely, and so dry-run only reports what execute would send.)+ if (Array.isArray(cachedForwardTypes) && cachedForwardTypes.length > 0) {+ if (!cachedForwardTypes.includes(notification.type)) return;+ }+// Per-domain autonomy gate: `off` suppresses outbound forwarding; `dry-run`// logs what would have been sent without actually messaging the channel.const mode = await getDomainAutonomyMode('messages');@@ -381,11 +388,6 @@ async function forwardNotification(notification) {return;}- // Use cached forwardTypes to avoid disk I/O on every notification- if (Array.isArray(cachedForwardTypes) && cachedForwardTypes.length > 0) {- if (!cachedForwardTypes.includes(notification.type)) return;- }-const emoji = NOTIFICATION_EMOJI[notification.type] || '🔔';const priorityEmoji = PRIORITY_EMOJI[notification.priority] || '';const lines = [`${emoji} <b>${escapeHtml(notification.title)}</b>`];diff --git a/server/services/telegramBridge.js b/server/services/telegramBridge.jsindex 833b0b57b7..38bea7f66f 100644--- a/server/services/telegramBridge.js+++ b/server/services/telegramBridge.js@@ -223,6 +223,13 @@ export function updateCachedForwardTypes(forwardTypes) {* Forward a notification to Telegram via HTTP API*/async function forwardNotification(notification) {+ // Cached forward-type filter first (mirrors telegram.js): a filtered-out+ // notification skips the state read, and dry-run only reports what execute+ // would actually send.+ if (Array.isArray(cachedForwardTypes) && cachedForwardTypes.length > 0) {+ if (!cachedForwardTypes.includes(notification.type)) return;+ }+// Per-domain autonomy gate (mirrors telegram.js): `off` suppresses outbound// forwarding; `dry-run` logs what would have been sent without messaging.const mode = await getDomainAutonomyMode('messages');@@ -233,10 +240,6 @@ async function forwardNotification(notification) {return;}- if (Array.isArray(cachedForwardTypes) && cachedForwardTypes.length > 0) {- if (!cachedForwardTypes.includes(notification.type)) return;- }-const emoji = NOTIFICATION_EMOJI[notification.type] || '🔔';const priorityEmoji = PRIORITY_EMOJI[notification.priority] || '';const lines = [`${emoji} <b>${escapeHtml(notification.title)}</b>`];