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): one formatSkipCauses definition in server/lib, shared by every park surface
Adam Eivy9404793f058c
diff --git a/client/src/components/apps/WorkItemPicker.jsx b/client/src/components/apps/WorkItemPicker.jsxindex ede9b4858c..c7b96f2502 100644--- a/client/src/components/apps/WorkItemPicker.jsx+++ b/client/src/components/apps/WorkItemPicker.jsx@@ -2,6 +2,7 @@ import { useState, useCallback, useId, useRef } from 'react';import { Loader2, RefreshCw } from 'lucide-react';import { ISSUE_AUTHOR_FILTER_OPTIONS } from '../cos/constants';import { WORK_TRACKER_LABELS, workItemNoun } from './constants';+import { formatSkipCauses } from '../../lib/perpetualSkipCauses';import * as api from '../../services/api';// Trackers with an author gate — PLAN.md items and JIRA sprint tickets have none.@@ -38,6 +39,11 @@ function emptyMessage(work) {? `Couldn't complete the check — ${work.remedy}.`: `Couldn't reach the tracker (${work.reason}) — retry, or let the agent decide.`;}+ // The detector's per-cause attribution answers "why is nothing claimable"+ // with the real counts ("49 needs-input, 17 blocked") rather than a static+ // sentence that must re-enumerate the cause vocabulary by hand.+ const causes = formatSkipCauses(work.skipCauses, 3, 'in-flight');+ if (causes) return `${EMPTY_REASONS[work.reason] || `Nothing to pick (${work.reason || 'unknown'}).`} (${causes})`;return EMPTY_REASONS[work.reason] || `Nothing to pick (${work.reason || 'unknown'}).`;}diff --git a/client/src/hooks/useOnDemandTaskToast.js b/client/src/hooks/useOnDemandTaskToast.jsindex 6572aaf5b5..8d23dd726a 100644--- a/client/src/hooks/useOnDemandTaskToast.js+++ b/client/src/hooks/useOnDemandTaskToast.js@@ -133,7 +133,9 @@ export function useOnDemandTaskToast() {// Per-cause attribution ("49 needs-input, 17 blocked") — the answer to// "why is nothing claimable when 88 issues are open". Replaces the bare// "N filtered" when present, since the causes ARE the filtered detail.- const causes = formatSkipCauses(data?.skipCauses);+ // `in-flight` is excluded: the counts breakdown already shows it, and+ // the detector includes it in the map as informational only.+ const causes = formatSkipCauses(data?.skipCauses, 3, 'in-flight');if (causes) parts.push(causes);else if (c.filtered) parts.push(`${c.filtered} filtered`);const detail = parts.length ? ` — ${parts.join(', ')}` : '';diff --git a/client/src/hooks/useOnDemandTaskToast.test.jsx b/client/src/hooks/useOnDemandTaskToast.test.jsxindex b861b33667..ed2975c1a8 100644--- a/client/src/hooks/useOnDemandTaskToast.test.jsx+++ b/client/src/hooks/useOnDemandTaskToast.test.jsx@@ -139,6 +139,24 @@ describe('useOnDemandTaskToast — parked outcome', () => {expect(msg).not.toMatch(/78 filtered/);});+ it('does not double-report in-flight (the counts breakdown already carries it)', () => {+ renderHook(() => useOnDemandTaskToast());+ fire({+ taskType: 'claim-issue', appName: 'App One', outcome: 'parked',+ parkReason: 'no-actionable-issues',+ counts: { open: 20, inFlight: 10, filtered: 10 },+ // The detector includes `in-flight` in the map as informational only —+ // the toast must not render it twice ("10 in-flight, 10 in-flight").+ skipCauses: { 'in-flight': 10, 'needs-input': 6, blocked: 4 },+ parkedUntil: new Date(Date.now() + 23 * 3600 * 1000).toISOString()+ });+ const [msg] = toastSpy.mock.calls[0];+ expect(msg).toMatch(/10 in-flight/);+ expect(msg).toMatch(/6 needs-input, 4 blocked/);+ // Exactly one "in-flight" mention — the counts breakdown's.+ expect(msg.match(/in-flight/g)).toHaveLength(1);+ });+// branch-reconcile's park used to report 'no-in-flight-branches' while merged// branches sat behind a protected worktree — "nothing to do" for a task the// user could see had work queued, which reads as the task not running at all.diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 3252615554..020c6e065e 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -31,7 +31,7 @@ grep -i "what you want to do" client/src/lib/README.md| `eidoverseWorldReset.js` | Client reset-reconciliation maps for Eidoverse source kinds and district asset slots; parity-tested against the authoritative server world-design contracts. || `postQuickSession.js` | Pure Quick POST duration presets, local-observation estimator, deterministic budget composer, and preview metadata. || `postRotation.js` | Re-export of `server/lib/postRotation.js` — `orderByRecencyRotation` sorts POST practice candidates fresh-before-recently-practiced, then by priority, rotating equivalent ones by local day. |-| `perpetualSkipCauses.js` | `formatSkipCauses(skipCauses, maxCauses)` — renders a perpetual work-detector's per-cause skip map (`{ 'needs-input': 49, blocked: 17 }`) as a compact largest-first string; client mirror of `formatSkipCauses` in `server/services/cosTaskGenerator.js`, used by the on-demand "Run" toast. |+| `perpetualSkipCauses.js` | Re-export of `server/lib/perpetualSkipCauses.js` — `formatSkipCauses(skipCauses, maxCauses?, excludeCause?)` renders a perpetual work-detector's per-cause skip map (`{ 'needs-input': 49, blocked: 17 }`) as a compact largest-first string; used by the on-demand "Run" toast and the work-item picker. |---diff --git a/client/src/lib/perpetualSkipCauses.js b/client/src/lib/perpetualSkipCauses.jsindex acb153ec87..268633cd3e 100644--- a/client/src/lib/perpetualSkipCauses.js+++ b/client/src/lib/perpetualSkipCauses.js@@ -1,17 +1,7 @@/**- * Render a perpetual work-detector skip-cause map- * ({ 'needs-input': 49, blocked: 17, … }) as a compact human string, largest- * cause first. Mirrors `formatSkipCauses` in server/services/cosTaskGenerator.js- * — the server renders it into park log lines, the client into the on-demand- * "Run" toast, and both must answer "why did N open issues yield zero work"- * with the same words. Returns '' for an empty/absent map.+ * Re-export of `server/lib/perpetualSkipCauses.js` — the one definition of the+ * skip-cause rendering, imported rather than copied so the PM2 park log line+ * and the on-demand toast cannot drift apart in wording. The file stays so+ * every `lib/perpetualSkipCauses` import path in the client is unchanged.*/-export function formatSkipCauses(skipCauses, maxCauses = 3) {- if (!skipCauses || typeof skipCauses !== 'object') return '';- return Object.entries(skipCauses)- .filter(([, n]) => Number.isFinite(n) && n > 0)- .sort((a, b) => b[1] - a[1])- .slice(0, maxCauses)- .map(([cause, n]) => `${n} ${cause}`)- .join(', ');-}+export { formatSkipCauses } from '../../../server/lib/perpetualSkipCauses.js';diff --git a/server/lib/README.md b/server/lib/README.mdindex ebffe5164f..14df27d0fd 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -446,6 +446,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `peerProbeDiagnostics.js` | Classify federated peer probe failures (`local_refused` / `tunnel_dial` / `probe_http` / timeout / auth / DNS) so Instances UI and logs can tell a dead local forward from a tunnel dial miss from a PortOS health-details failure; messages stay redacted (no full `tc…` capabilities). || `peerSelfHost.js` | Tailscale-issued hostname this PortOS sends in federation. || `peerUrl.js` | Build the base URL for a peer. |+| `perpetualSkipCauses.js` | `formatSkipCauses(skipCauses, maxCauses?, excludeCause?)` — renders a perpetual work-detector's per-cause skip map (`{ 'needs-input': 49, blocked: 17 }`) as a compact largest-first string; the one definition shared by the park log line, the on-demand toast, and the work-item picker. Re-exported at `client/src/lib/perpetualSkipCauses.js`. || `sharingOrigin.js` | Origin metadata for records imported from share buckets. || `syncIntegrity.js` | Pure diff of local vs remote manifest lists. `INTEGRITY_STATUS` constants + `computeRecordIntegrity(localList, remoteList)` — classifies each record as `in-parity`, `local-only`, `peer-only`, `diverged`, or `assets-missing`. No I/O. || `syncWire.js` | Single source of truth for what fields cross the federated-peer wire (snapshot loop + per-record push agree). |diff --git a/server/lib/index.js b/server/lib/index.jsindex 2b1551ab88..18ace784bc 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -421,6 +421,7 @@ export * from './peerProbeDiagnostics.js';export * from './peerSelfHost.js';export * from './protobufWire.js';export * from './peerUrl.js';+export * from './perpetualSkipCauses.js';export * from './pinterestFeed.js';export * from './readResponseJson.js';export * from './safeUrlFetch.js';diff --git a/server/lib/perpetualSkipCauses.js b/server/lib/perpetualSkipCauses.jsnew file mode 100644index 0000000000..adc940c579--- /dev/null+++ b/server/lib/perpetualSkipCauses.js@@ -0,0 +1,20 @@+/**+ * Render a perpetual work-detector skip-cause map+ * ({ 'needs-input': 49, blocked: 17, … }) as a compact human string, largest+ * cause first. The one definition shared by every surface that answers "why+ * did N open issues yield zero work" — the park log line (taskSchedule.js),+ * the gate log (cosTaskGenerator.js), the on-demand toast, and the work-item+ * picker — so they cannot drift apart in wording. `excludeCause` drops one+ * cause from the rendering for callers that already show it through another+ * channel (the toast excludes `in-flight` because `counts.inFlight` carries+ * it). Returns '' for an empty/absent map.+ */+export function formatSkipCauses(skipCauses, maxCauses = 3, excludeCause = null) {+ if (!skipCauses || typeof skipCauses !== 'object') return '';+ return Object.entries(skipCauses)+ .filter(([cause, n]) => cause !== excludeCause && Number.isFinite(n) && n > 0)+ .sort((a, b) => b[1] - a[1])+ .slice(0, maxCauses)+ .map(([cause, n]) => `${n} ${cause}`)+ .join(', ');+}diff --git a/server/lib/perpetualSkipCauses.test.js b/server/lib/perpetualSkipCauses.test.jsnew file mode 100644index 0000000000..69ba1d7c98--- /dev/null+++ b/server/lib/perpetualSkipCauses.test.js@@ -0,0 +1,29 @@+import { describe, it, expect } from 'vitest';+import { formatSkipCauses } from './perpetualSkipCauses.js';++describe('formatSkipCauses', () => {+ it('renders causes largest-first, capped at maxCauses', () => {+ expect(formatSkipCauses({ 'needs-input': 49, blocked: 17, 'decomposed-epic': 12, assigned: 2 }))+ .toBe('49 needs-input, 17 blocked, 12 decomposed-epic');+ expect(formatSkipCauses({ 'needs-input': 49, blocked: 17, 'decomposed-epic': 12, assigned: 2 }, 2))+ .toBe('49 needs-input, 17 blocked');+ });++ it('excludes a cause another channel already shows (the toast excludes in-flight)', () => {+ expect(formatSkipCauses({ 'in-flight': 10, 'needs-input': 6, blocked: 4 }, 3, 'in-flight'))+ .toBe('6 needs-input, 4 blocked');+ });++ it('returns "" for an absent, empty, or non-object map', () => {+ expect(formatSkipCauses(null)).toBe('');+ expect(formatSkipCauses(undefined)).toBe('');+ expect(formatSkipCauses({})).toBe('');+ expect(formatSkipCauses('needs-input')).toBe('');+ });++ it('drops non-finite and non-positive counts rather than rendering them', () => {+ // The map crosses a persisted-JSON boundary (the schedule store), so a+ // hand-edited or corrupted entry must not reach the string.+ expect(formatSkipCauses({ blocked: 3, stale: NaN, zero: 0 })).toBe('3 blocked');+ });+});diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex 61cd63b8ca..51d8f5809a 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -36,6 +36,7 @@ import { isPlainObject } from '../lib/objects.js';import { hasQuotaBurnProvenance, isManualOnDemandRequest } from '../lib/quotaBurnOrigin.js';import { isAutoApprovableInvestigation } from '../lib/investigationTasks.js';import { parsePlanItems, extractAllIds, findInProgressIds, pickFirstAvailable, diagnoseUnpickablePlan } from '../lib/planIds.js';+import { formatSkipCauses } from '../lib/perpetualSkipCauses.js';import { loadState, saveState, withStateLock, isImprovementEnabled, isDaemonRunning } from './cosState.js';import { getDomainMode } from '../lib/domainAutonomy.js';import { remainingActionBudget } from '../lib/domainBudgets.js';@@ -2115,22 +2116,6 @@ const transientVerdictKey = (taskType, appId) => `${taskType}:${appId || 'global// escalating to `warn` — see recordPerpetualTransient's return value.export const PERPETUAL_TRANSIENT_ESCALATION_THRESHOLD = 3;-/**- * Render a detector skip-cause map ({ 'needs-input': 49, blocked: 17, … }) as a- * compact human string, largest cause first. Shared by the park log line and the- * on-demand toast so both answer "why did 88 open issues yield zero work" with- * the same words. Returns '' for an empty/absent map.- */-export function formatSkipCauses(skipCauses, maxCauses = 3) {- if (!skipCauses || typeof skipCauses !== 'object') return '';- return Object.entries(skipCauses)- .filter(([, n]) => Number.isFinite(n) && n > 0)- .sort((a, b) => b[1] - a[1])- .slice(0, maxCauses)- .map(([cause, n]) => `${n} ${cause}`)- .join(', ');-}-// Consecutive-transient-skip counters, keyed the same as transientVerdicts but// deliberately tracked SEPARATELY from it: this streak must survive across// evaluations more than 60s apart (it counts how many evaluations IN A ROW came@@ -2608,13 +2593,13 @@ async function applyPerpetualWorkGate(app, taskType, promptTaskType, metadata, i// Per-cause skip attribution for the same question at one level deeper: not// just "78 filtered" but "49 needs-input, 17 blocked, …". Only the claim// detectors report it; every other park shape keeps the field absent.- const skipCauses = detection.skipCauses && Object.keys(detection.skipCauses).length > 0- ? detection.skipCauses- : null;+ // parkPerpetual's own log line renders the summary (it is the single choke+ // point every park flows through), so this one stays bare.+ const skipCauses = detection.skipCauses ?? null;// Terminal park — parkPerpetual zeroes the dispatch budget in the same write, so// the next drain window starts fresh instead of capping early on this one's spend.await taskSchedule.parkPerpetual(taskType, app.id, { reason: detection.reason, actionableCount: detection.count, counts, skipCauses, signature: null });- emitLog('info', `Perpetual ${taskType} parked for ${app.name}: ${detection.reason}${skipCauses ? ` (${formatSkipCauses(skipCauses)})` : ''}`, { appId: app.id });+ emitLog('info', `Perpetual ${taskType} parked for ${app.name}: ${detection.reason}`, { appId: app.id });return { skip: true };}diff --git a/server/services/perpetualWork.test.js b/server/services/perpetualWork.test.jsindex bf9615d69d..184f041afb 100644--- a/server/services/perpetualWork.test.js+++ b/server/services/perpetualWork.test.js@@ -387,7 +387,7 @@ describe('perpetualWork', () => {expect(out.skipCauses).toEqual({ 'needs-input': 5, blocked: 1, 'decomposed-epic': 1 });});- it('attributes skips per cause (assigned / in-flight / excluded label) so a park names its reasons', async () => {+ it('carries an empty skipCauses map when issues remain actionable (attribution is park-only)', async () => {routeSpawn({'gh issue': { stdout: JSON.stringify([{ number: 1, title: 'plain', assignees: [], labels: [] },diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 1bb8336a45..2cc5b9a3e9 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -20,6 +20,7 @@*/import { cosEvents, emitLog } from './cosEvents.js';+import { formatSkipCauses } from '../lib/perpetualSkipCauses.js';import { DAY, safeDate } from '../lib/fileUtils.js';import { mapWithConcurrency } from '../lib/mapWithConcurrency.js';import { getAdaptiveCooldownMultiplier } from './taskLearning.js';@@ -605,13 +606,8 @@ export async function parkPerpetual(taskType, appId = null, { reason = null, act// open issues" reads as the task being broken. Render the top skip causes// inline ("49 needs-input, 17 blocked") so the one line they see answers the// question the toast exists for.- const causeSummary = skipCauses && Object.keys(skipCauses).length > 0- ? ` — ${Object.entries(skipCauses)- .sort((a, b) => b[1] - a[1])- .slice(0, 3)- .map(([cause, n]) => `${n} ${cause}`)- .join(', ')}`- : '';+ const causes = formatSkipCauses(skipCauses);+ const causeSummary = causes ? ` — ${causes}` : '';emitLog('info', `Perpetual ${taskType} parked until ${parkedUntil} (${reason || 'idle'}${causeSummary})`, { taskType, appId, parkedUntil }, '📅 TaskSchedule');cosEvents.emit('schedule:perpetual-parked', { taskType, appId, parkedUntil, reason, actionableCount, counts, skipCauses });return record;diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 11fa2c2eea..2e6bfc4508 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -2877,7 +2877,7 @@ describe('taskSchedule', () => {// The log line the operator reads in PM2 names the top 3 causes inline.const logged = emitLog.mock.calls.at(-1);expect(logged[1]).toMatch(/no-actionable-issues — 49 needs-input, 17 blocked, 12 decomposed-epic/);- expect(logged[1]).not.toMatch(/assigned: 2/);+ expect(logged[1]).not.toMatch(/2 assigned/);})it('parkPerpetual leaves parkSkipCauses absent when the detector reports no attribution', async () => {diff --git a/server/services/workItems.js b/server/services/workItems.jsindex de5313663f..51134bd64a 100644--- a/server/services/workItems.js+++ b/server/services/workItems.js@@ -80,6 +80,10 @@ export async function listWorkItems(app, { issueAuthorFilter, issueExcludeLabels// Present only when the detector named a fault that won't self-clear (a// permission the token lacks), so the picker can print the way out instead of// the generic "retry" copy every other transient gets.- remedy: result.remedy || null+ remedy: result.remedy || null,+ // Per-cause skip attribution for an empty list (the detector computes it+ // exactly when items run out), so the picker can say WHY each issue was+ // skipped instead of a hand-maintained cause list that goes stale.+ skipCauses: result.skipCauses && Object.keys(result.skipCauses).length > 0 ? result.skipCauses : null};}diff --git a/server/services/workItems.test.js b/server/services/workItems.test.jsindex 6f98f4d6ed..eef83fc7a4 100644--- a/server/services/workItems.test.js+++ b/server/services/workItems.test.js@@ -78,6 +78,30 @@ describe('listWorkItems', () => {expect(out).toMatchObject({ tracker: 'gitlab', items: [], count: 0, reason: 'glab-list-failed', transient: true });});+ it('passes the detector\'s per-cause skip attribution through for an empty list', async () => {+ resolveAppWorkTracker.mockResolvedValue({ resolved: 'github', source: 'origin' });+ detectActionableWork.mockResolvedValue({+ actionable: false, count: 0, reason: 'no-actionable-issues',+ items: [], skipCauses: { 'needs-input': 5, blocked: 2 }+ });++ const out = await listWorkItems(app);++ // The picker renders WHY each issue was skipped from this map — a null (not+ // {}) when the detector reported no attribution keeps the field absent for+ // every other empty shape (plan items, JIRA tickets).+ expect(out.skipCauses).toEqual({ 'needs-input': 5, blocked: 2 });+ });++ it('omits skipCauses when the detector reports none', async () => {+ resolveAppWorkTracker.mockResolvedValue({ resolved: 'github', source: 'origin' });+ detectActionableWork.mockResolvedValue({ actionable: false, count: 0, reason: 'no-open-issues', items: [] });++ const out = await listWorkItems(app);++ expect(out.skipCauses).toBeNull();+ });+it('lists JIRA sprint tickets, skipping ones already started or done', async () => {resolveAppWorkTracker.mockResolvedValue({ resolved: 'jira', source: 'configured' });fetchMyCurrentSprintTickets.mockResolvedValue([