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 review (codex): surface the LI skip reason on a manual Run instead of a false idle
[._.]/ Adam Eivy198bd4813f29
diff --git a/client/src/hooks/useOnDemandTaskToast.js b/client/src/hooks/useOnDemandTaskToast.jsindex c4fefaaaf1..eaf351ddf2 100644--- a/client/src/hooks/useOnDemandTaskToast.js+++ b/client/src/hooks/useOnDemandTaskToast.js@@ -2,6 +2,7 @@ import { useEffect } from 'react';import toast from '../components/ui/Toast';import socket from '../services/socket';import { timeUntil } from '../utils/formatters';+import { formatLiReason } from '../utils/layeredIntelligenceReasons';// Humanize a perpetual work-detector park reason for a user-facing toast. The// raw reason strings are the same ones surfaced in the CoS → Schedule tab; here@@ -44,8 +45,18 @@ export function useOnDemandTaskToast() {}// A non-perpetual task produced no task ⇒ genuinely nothing to do right- // now (not a failure, not a park). Keep it calm and neutral.+ // now (not a failure, not a park). Keep it calm and neutral — UNLESS the+ // server surfaced an actionable reason (e.g. Layered Intelligence pinned to+ // an api-only provider that can't drive the reasoning agent). Then say WHY+ // and warn, so a misconfiguration isn't hidden behind "nothing to do".if (data?.outcome === 'idle') {+ if (data?.taskType === 'layered-intelligence' && data?.reason) {+ toast(`${task}${scope}: ${formatLiReason({ action: 'skipped', reason: data.reason })}.`, {+ duration: 8000,+ icon: '⚠️'+ });+ return;+ }toast(`${task}${scope}: re-checked now — nothing to do right now.`, {duration: 6000,icon: '💤'diff --git a/client/src/hooks/useOnDemandTaskToast.test.jsx b/client/src/hooks/useOnDemandTaskToast.test.jsxnew file mode 100644index 0000000000..e7055c38db--- /dev/null+++ b/client/src/hooks/useOnDemandTaskToast.test.jsx@@ -0,0 +1,48 @@+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';+import { renderHook, cleanup } from '@testing-library/react';++// Capture the socket handler the hook registers so tests can drive the+// `cos:schedule:on-demand-empty` event, and record toast calls.+const handlers = new Map();+vi.mock('../services/socket', () => ({+ default: {+ on: (event, fn) => { handlers.set(event, fn); },+ off: (event, fn) => { if (handlers.get(event) === fn) handlers.delete(event); },+ emit: () => {},+ },+}));++const toastSpy = vi.fn();+vi.mock('../components/ui/Toast', () => ({ default: (...a) => toastSpy(...a) }));++const { useOnDemandTaskToast } = await import('./useOnDemandTaskToast.js');+const fire = (payload) => handlers.get('cos:schedule:on-demand-empty')?.(payload);++describe('useOnDemandTaskToast — idle outcome', () => {+ beforeEach(() => { handlers.clear(); toastSpy.mockClear(); });+ afterEach(cleanup);++ it('toasts a generic "nothing to do" for a plain idle result', () => {+ renderHook(() => useOnDemandTaskToast());+ fire({ taskType: 'pr-watcher', appName: 'App One', outcome: 'idle' });+ expect(toastSpy).toHaveBeenCalledTimes(1);+ expect(toastSpy.mock.calls[0][0]).toMatch(/nothing to do right now/);+ });++ it('surfaces the actionable LI reason (api-only provider) instead of "nothing to do"', () => {+ renderHook(() => useOnDemandTaskToast());+ fire({ taskType: 'layered-intelligence', appName: 'App One', outcome: 'idle', reason: 'provider-not-agent-capable' });+ expect(toastSpy).toHaveBeenCalledTimes(1);+ const [msg, opts] = toastSpy.mock.calls[0];+ expect(msg).toMatch(/API-only model with no coding harness — pick a CLI\/TUI provider/i);+ expect(msg).not.toMatch(/nothing to do/);+ // Warned, not the calm 💤 idle tone.+ expect(opts.icon).toBe('⚠️');+ });++ it('falls back to the generic idle toast for an LI idle result with no reason', () => {+ renderHook(() => useOnDemandTaskToast());+ fire({ taskType: 'layered-intelligence', appName: 'App One', outcome: 'idle', reason: null });+ expect(toastSpy.mock.calls[0][0]).toMatch(/nothing to do right now/);+ });+});diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex fc53ca4325..5c38eb1001 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -1524,12 +1524,26 @@ export async function emitOnDemandEmpty({ taskScheduleMod, request, targetApp, tconst parkInfo = await taskScheduleMod.getPerpetualParkInfo(request.taskType, appId).catch(() => null);const isPerpetual = taskConfig?.type === taskScheduleMod.INTERVAL_TYPES.PERPETUAL;const outcome = parkInfo ? 'parked' : (isPerpetual ? 'transient' : 'idle');++ // Layered Intelligence skips (e.g. a provider that can't drive an agent) record+ // an actionable last-run reason. Surface it so a manual "Run" toasts WHY it+ // produced nothing (e.g. "pick a CLI/TUI provider") instead of a misleading+ // generic "nothing to do". Read the freshest record — the skip's recordRun+ // landed after `targetApp` was loaded. Best-effort; a read failure just omits it.+ let reason = null;+ if (outcome === 'idle' && appId && request.taskType === 'layered-intelligence') {+ const { getAppById } = await import('./apps.js');+ const app = await getAppById(appId).catch(() => null);+ reason = app?.layeredIntelligence?.lastRunReason || null;+ }+cosEvents.emit('schedule:on-demand-empty', {requestId: request.id,taskType: request.taskType,appId,appName: targetApp?.name || null,outcome,+ reason,parkReason: parkInfo?.parkReason || null,parkedUntil: parkInfo?.parkedUntil || null,actionableCount: parkInfo?.parkActionableCount ?? null,diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.jsindex e1348a0060..fe83fe4a92 100644--- a/server/services/cosTaskGenerator.test.js+++ b/server/services/cosTaskGenerator.test.js@@ -15,7 +15,7 @@ import { describe, it, expect } from 'vitest';import { readFileSync } from 'fs';import { fileURLToPath } from 'url';import { dirname, join } from 'path';-import { selectDryRunAutoApproved, exceedsMaxSpawns, resolveIssueAuthorFilterBlock, resolveSwarmBlock, isCooldownExemptTask } from './cosTaskGenerator.js';+import { selectDryRunAutoApproved, exceedsMaxSpawns, resolveIssueAuthorFilterBlock, resolveSwarmBlock, isCooldownExemptTask, emitOnDemandEmpty } from './cosTaskGenerator.js';import { cosEvents } from './cosEvents.js';import { MAX_TOTAL_SPAWNS } from '../lib/validation.js';@@ -475,3 +475,41 @@ describe('selectDryRunAutoApproved', () => {// visible agent task (or the shared emitOnDemandEmpty no-dispatch feedback when the// buildTaskInput hook skips), and the filing outcome surfaces via the agent + the// app's lastRun bookkeeping — so the bespoke bridge is no longer needed.++describe('emitOnDemandEmpty', () => {+ // Minimal taskScheduleMod stub: no park (→ 'idle' for a non-perpetual type),+ // and the INTERVAL_TYPES enum the perpetual check reads.+ const stubMod = {+ getPerpetualParkInfo: async () => null,+ INTERVAL_TYPES: { PERPETUAL: 'perpetual' }+ };++ it("emits an 'idle' event with reason null for a non-LI task type", async () => {+ const events = [];+ const handler = (d) => events.push(d);+ cosEvents.on('schedule:on-demand-empty', handler);+ try {+ await emitOnDemandEmpty({+ taskScheduleMod: stubMod,+ request: { id: 'req-1', taskType: 'pr-watcher' },+ targetApp: { id: 'app-1', name: 'App One' },+ taskConfig: { type: 'custom' }+ });+ } finally {+ cosEvents.off('schedule:on-demand-empty', handler);+ }+ expect(events).toHaveLength(1);+ // A non-LI task type never reads a last-run reason (that read is LI-only).+ expect(events[0]).toMatchObject({ taskType: 'pr-watcher', outcome: 'idle', reason: null });+ });++ it('reads the LI last-run reason only for the layered-intelligence task type', () => {+ // Source-pinned (the behavioral read dynamic-imports the live app store):+ // the reason surfacing is gated on the LI task type + the 'idle' outcome and+ // reads the app's recorded lastRunReason.+ const idx = GEN_SRC.indexOf('export async function emitOnDemandEmpty');+ const body = GEN_SRC.slice(idx, idx + 1600);+ expect(body).toMatch(/request\.taskType === 'layered-intelligence'/);+ expect(body).toMatch(/layeredIntelligence\?\.lastRunReason/);+ });+});