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: derive the workflow audit stage and the lane tests from the catalog
[._.]/ Adam Eivy6d89f905083e
diff --git a/server/lib/auditCatalog.js b/server/lib/auditCatalog.jsindex 0cfd258ef3..45e06ea757 100644--- a/server/lib/auditCatalog.js+++ b/server/lib/auditCatalog.js@@ -570,12 +570,17 @@ export function applyAuditModeWrapper(promptTemplate, modeInstructions) {* each as its own schedulable, provider-pinnable task so a managed app can run* every category of self-improvement on its own cadence. Keys are the lens* slugs slashdo uses; values are the AUDIT_DEFINITIONS types that own that- * lens's findings — the first entry is the primary owner.+ * lens's findings, in no significant order — the relation is many-to-many both+ * ways (`security` answers three lenses; `bugs-perf` has four owners), which+ * is why this is a lens-keyed map rather than a field on each definition. A+ * per-definition field could not answer the question the map exists for: did+ * upstream add a lens that NOTHING here owns?*- * auditCatalog.test.js checks this map two ways: every listed type is a real- * audit type, and (when the submodule is checked out) every lens slashdo- * declares has an entry here — so a lens added upstream cannot silently go- * unscheduled.+ * It is a parity record, not runtime wiring — nothing dereferences it at+ * dispatch. auditCatalog.test.js is its consumer, and checks it two ways: every+ * listed type is a real audit type, and (when the submodule is checked out)+ * every lens slashdo declares has an entry here, so a lens added upstream+ * cannot silently go unschedulable.*/export const DO_BETTER_LENS_COVERAGE = Object.freeze({security: ['security'],diff --git a/server/lib/auditCatalog.test.js b/server/lib/auditCatalog.test.jsindex fdd8202b64..26c58d85d7 100644--- a/server/lib/auditCatalog.test.js+++ b/server/lib/auditCatalog.test.js@@ -207,9 +207,10 @@ describe('getAuditFilingPreset', () => {// and it only means anything if both halves are checked: that every type it// names is real, and that every lens upstream declares is actually named.describe('DO_BETTER_LENS_COVERAGE', () => {- it('names only registered audit types, primary owner first', () => {+ it('names only registered audit types, without duplicates', () => {for (const [lens, owners] of Object.entries(DO_BETTER_LENS_COVERAGE)) {- expect(Array.isArray(owners) && owners.length, lens).toBeTruthy();+ expect(Array.isArray(owners), lens).toBe(true);+ expect(owners.length, lens).toBeGreaterThan(0);for (const owner of owners) {expect(AUDIT_TASK_TYPES.has(owner), `${lens} -> ${owner}`).toBe(true);}@@ -217,6 +218,19 @@ describe('DO_BETTER_LENS_COVERAGE', () => {}});+ // The seeded schedule row ALWAYS sets taskMetadata.fileIssues, so for a+ // scheduled dispatch the catalog default is never actually consulted — which+ // means the two can disagree and nothing would notice until someone read the+ // catalog and believed it. They encode one product decision; pin them equal.+ it('agrees with the seeded schedule row on every audit default', async () => {+ const { DEFAULT_TASK_INTERVALS } = await import('../services/taskScheduleRegistry.js');+ for (const taskType of AUDIT_TASK_TYPES) {+ const seeded = DEFAULT_TASK_INTERVALS[taskType]?.taskMetadata?.fileIssues;+ if (seeded === undefined) continue; // not seeded with an explicit posture+ expect(seeded, taskType).toBe(defaultFileIssuesFor(taskType));+ }+ });+it('gives every better-prefixed audit type a lens to be in parity with', () => {const covered = new Set(Object.values(DO_BETTER_LENS_COVERAGE).flat());const orphaned = [...AUDIT_TASK_TYPES]@@ -229,7 +243,12 @@ describe('DO_BETTER_LENS_COVERAGE', () => {// unschedulable — exactly the gap these task types were added to close.it('covers every lens the bundled do:better command declares', async () => {const { existsSync, readFileSync } = await import('fs');- const auditRef = new URL('../../lib/slashdo/lib/better-audit.md', import.meta.url);+ const { join } = await import('path');+ const { PATHS } = await import('./paths.js');+ // Anchored on PATHS.slashdo rather than a relative URL: a missing file here+ // SKIPS outside CI, so a path that silently goes stale disables the guard+ // instead of failing it — the exact failure this test exists to prevent.+ const auditRef = join(PATHS.slashdo, 'lib', 'better-audit.md');if (!existsSync(auditRef)) {requireSlashdoSubmoduleInCi(false);return;diff --git a/server/lib/workTracker.trackerInstructions.test.js b/server/lib/workTracker.trackerInstructions.test.jsindex 85234c246e..e991005bcb 100644--- a/server/lib/workTracker.trackerInstructions.test.js+++ b/server/lib/workTracker.trackerInstructions.test.js@@ -143,39 +143,27 @@ describe('formatTrackerInstructions — ux preset (#3273)', () => {expect(formatTrackerInstructions('github', ux)).toContain('{appName}');});- // The SHIPPED prompt (not the generator's mocked stand-in) must fully expand:- // a token that survives reaches the agent literally. The substitution order- // below MIRRORS buildImprovementTaskDescription and is load-bearing — the- // file-issues mode contract carries a {trackerInstructions} of its own, and- // the injected tracker block carries {appName}/{repoPath} of its own. Run in- // any other order and a real dispatch ships a literal placeholder.- it('leaves no unexpanded {token} in the shipped ux prompt on any tracker', async () => {- const { DEFAULT_TASK_PROMPTS } = await import('../services/taskPromptDefaults.js');- const { modeContractFor } = await import('./auditCatalog.js');- const template = DEFAULT_TASK_PROMPTS['ux'];- expect(template).toContain('{trackerInstructions}');- expect(template).toContain('{modeInstructions}');-- for (const tracker of ['plan', 'github', 'gitlab', 'jira']) {- for (const fileIssues of [true, false]) {- const rendered = template- .replace(/\{modeInstructions\}/g, () => modeContractFor(fileIssues))- .replace(/\{trackerInstructions\}/g, () => formatTrackerInstructions(tracker, ux))- .replace(/\{appName\}/g, () => 'Example App')- .replace(/\{repoPath\}/g, () => '/tmp/example-repo');- expect(rendered.match(/\{[a-zA-Z][a-zA-Z0-9_]*\}/g), `${tracker} fileIssues=${fileIssues}`).toBeNull();- }- }- });-- // The same contract for EVERY audit lane, not just ux. Each one is dispatched- // through the identical chain, so one prompt that introduces a placeholder the- // generator does not substitute ships that literal text to the agent — and the- // failure is invisible until someone reads a run's transcript. Cheap to assert- // across the whole catalog, and it covers each new lane on the day it is added.+ // The SHIPPED prompts must fully expand: a token that survives reaches the+ // agent literally. Two things make this worth asserting across the whole+ // catalog rather than for one prompt:+ //+ // * the substitution ORDER is load-bearing — the file-issues mode contract+ // carries a {trackerInstructions} of its own, and the injected tracker+ // block carries {appName}/{repoPath} of its own, so running these in any+ // other order ships a literal placeholder (see the same ordering, and the+ // same reason, in services/cosTaskPreStepBlocks.js);+ // * the tracker block is resolved by the REAL resolveTrackerFilingBlock, so+ // this cannot drift from production preset precedence. That matters: ux is+ // the one audit type present in BOTH registries, and production resolves+ // `alwaysPreset || auditPreset` — a test that reached for the catalog+ // preset alone would render a block no dispatch ever produces.+ //+ // If an audit prompt later adopts a placeholder the generator substitutes but+ // this chain does not, this test fails and names the token — add it here.it('leaves no unexpanded {token} in ANY shipped audit prompt, in either mode', async () => {const { DEFAULT_TASK_PROMPTS } = await import('../services/taskPromptDefaults.js');- const { AUDIT_TASK_TYPES, modeContractFor, getAuditFilingPreset } = await import('./auditCatalog.js');+ const { AUDIT_TASK_TYPES, modeContractFor } = await import('./auditCatalog.js');+ const { resolveTrackerFilingBlock } = await import('./workTracker.js');expect(AUDIT_TASK_TYPES.size).toBeGreaterThan(1);for (const taskType of AUDIT_TASK_TYPES) {@@ -183,13 +171,14 @@ describe('formatTrackerInstructions — ux preset (#3273)', () => {expect(template, taskType).toBeTruthy();for (const tracker of ['plan', 'github', 'gitlab', 'jira']) {for (const fileIssues of [true, false]) {- // Do-work mode resolves {trackerInstructions} to empty, exactly as- // resolveTrackerFilingBlock does when an audit is not filing.+ const { trackerInstructions } = await resolveTrackerFilingBlock(+ { repoPath: '/example', workTracker: tracker },+ taskType,+ { fileIssues },+ );const rendered = template.replace(/\{modeInstructions\}/g, () => modeContractFor(fileIssues))- .replace(/\{trackerInstructions\}/g, () => (- fileIssues ? formatTrackerInstructions(tracker, getAuditFilingPreset(taskType)) : ''- ))+ .replace(/\{trackerInstructions\}/g, () => trackerInstructions).replace(/\{appName\}/g, () => 'Example App').replace(/\{repoPath\}/g, () => '/tmp/example-repo');expect(@@ -200,6 +189,15 @@ describe('formatTrackerInstructions — ux preset (#3273)', () => {}}});++ // ux keeps one assertion of its own: it is the audit whose body most recently+ // hardcoded its posture instead of deferring to the injected banner.+ it('keeps the ux prompt on the injected tracker and mode seams', async () => {+ const { DEFAULT_TASK_PROMPTS } = await import('../services/taskPromptDefaults.js');+ const template = DEFAULT_TASK_PROMPTS['ux'];+ expect(template).toContain('{trackerInstructions}');+ expect(template).toContain('{modeInstructions}');+ });});describe('resolveTrackerFilingBlock — fileIssues audit types', () => {diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 460efb92ce..ba5cf2d713 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -182,7 +182,7 @@ import { RETIRED_CONSOLE_ERRORS_PROMPT } from './taskPromptDefaults/retiredPromp// — the posture guard below iterates it so the two can't drift apart.import { NON_COMMITTING_COORDINATOR_TASK_TYPES } from './taskTypeHooks.js'import { enforceManagedAgentOptions } from './taskScheduleRegistry.js'-import { modeContractFor, auditDoWorkRequiresWorktree } from '../lib/auditCatalog.js'+import { modeContractFor, auditDoWorkRequiresWorktree, AUDIT_TASK_TYPES } from '../lib/auditCatalog.js'import { loadState } from './cosState.js'@@ -1895,40 +1895,37 @@ describe('taskSchedule', () => {})describe('audit file-issues types', () => {- it('registers data-safety, simplify, and module-hygiene as enabled on-demand file-issues audits', () => {- for (const taskType of ['data-safety', 'simplify', 'module-hygiene']) {- expect(SELF_IMPROVEMENT_TASK_TYPES).toContain(taskType)- expect(TASK_TYPE_DESCRIPTIONS[taskType]).toBeTruthy()- const cfg = DEFAULT_TASK_INTERVALS[taskType]- expect(cfg.type).toBe(INTERVAL_TYPES.ON_DEMAND)- expect(cfg.enabled).toBe(true)- expect(cfg.taskMetadata.fileIssues).toBe(true)- expect(cfg.taskMetadata.useWorktree).toBe(false)- expect(cfg.taskMetadata.openPR).toBe(false)- expect(MANAGED_AGENT_OPTIONS[taskType]).toBeUndefined()- }- expect(DEFAULT_TASK_INTERVALS['module-hygiene'].dataInputs).toEqual([- 'open-issues',- 'open-pull-requests',+ // Every file-issues-by-default lane, in ONE table: the posture is a single+ // product decision ("an unattended scheduled run must not land code"), so+ // asserting it in two places 20 lines apart just means a future flag gets+ // added to one of them. `dataInputs` is the only column that varies — the+ // lanes that preload open issues/PRs dedup against work already filed or in+ // flight without spending the agent's own forge calls.+ const NO_PRELOAD = undefined+ const DEDUP_PRELOAD = ['open-issues', 'open-pull-requests']+ const FILE_ISSUES_LANES = [+ ['data-safety', NO_PRELOAD],+ ['simplify', NO_PRELOAD],+ ['module-hygiene', DEDUP_PRELOAD],+ // Derived, so a seventh better-* lane cannot be added without landing here.+ ...[...AUDIT_TASK_TYPES]+ .filter((taskType) => taskType.startsWith('better-'))+ .map((taskType) => [taskType, DEDUP_PRELOAD]),+ ]++ it('covers every better-* lane, derived from the catalog rather than hand-listed', () => {+ const lanes = FILE_ISSUES_LANES.map(([taskType]) => taskType).filter((t) => t.startsWith('better-'))+ expect(lanes).toEqual([+ 'better-complexity',+ 'better-cognitive-load',+ 'better-structural-drift',+ 'better-runtime-safety',+ 'better-dependency-freedom',+ 'better-test-quality',])})- // One scheduled lane per slashdo do:better audit lens. They ship file-issues- // by default because an unattended scheduled run must not land a refactor,- // and the four that restructure code require worktree isolation the moment- // the user flips them to implement — a mechanical rewrite of a hot function,- // a consolidation of two sources of truth, or a dependency swap is exactly- // the edit that must never happen in the operator's live checkout.- const BETTER_LANES = [- 'better-complexity',- 'better-cognitive-load',- 'better-structural-drift',- 'better-runtime-safety',- 'better-dependency-freedom',- 'better-test-quality',- ]-- it.each(BETTER_LANES)('registers %s as an enabled on-demand file-issues audit', (taskType) => {+ it.each(FILE_ISSUES_LANES)('registers %s as an enabled on-demand file-issues audit', (taskType, dataInputs) => {expect(SELF_IMPROVEMENT_TASK_TYPES).toContain(taskType)expect(TASK_TYPE_DESCRIPTIONS[taskType]).toBeTruthy()expect(DEFAULT_TASK_PROMPTS[taskType]).toBeTruthy()@@ -1938,16 +1935,15 @@ describe('taskSchedule', () => {expect(cfg.taskMetadata.fileIssues).toBe(true)expect(cfg.taskMetadata.useWorktree).toBe(false)expect(cfg.taskMetadata.openPR).toBe(false)- // Dedup against work already filed or in flight, without spending the- // agent's own forge calls — the shape module-hygiene established.- expect(cfg.dataInputs).toEqual(['open-issues', 'open-pull-requests'])+ expect(cfg.dataInputs).toEqual(dataInputs)// The file-issues posture is enforced at dispatch, so the user can still// flip the toggle and implement.expect(MANAGED_AGENT_OPTIONS[taskType]).toBeUndefined()})it('requires worktree isolation for the lanes whose remediation restructures code', () => {- const isolated = BETTER_LANES.filter((t) => auditDoWorkRequiresWorktree(t))+ const isolated = [...AUDIT_TASK_TYPES]+ .filter((t) => t.startsWith('better-') && auditDoWorkRequiresWorktree(t))expect(isolated).toEqual(['better-complexity','better-cognitive-load',diff --git a/server/services/workflow.js b/server/services/workflow.jsindex 8179d4dcb0..13be1152cc 100644--- a/server/services/workflow.js+++ b/server/services/workflow.js@@ -22,6 +22,7 @@*/import { getScheduleStatus } from './taskSchedule.js';+import { AUDIT_TASK_TYPES } from '../lib/auditCatalog.js';import * as autonomousJobs from './autonomousJobs.js';import { checkJobGate, hasGate, getRegisteredGates } from './jobGates.js';import { parseCronToNextRun, parseRecurrenceToNextRun } from './eventScheduler.js';@@ -63,34 +64,12 @@ export const WORKFLOW_STAGES = [id: 'audit',label: 'Audit',description: 'Quality, security, and accessibility audits. Independent of the plan, but typically scheduled lighter than build work.',- taskTypes: [- 'security',- 'code-quality',- 'test-coverage',- 'performance',- 'accessibility',- 'console-errors',- 'dependency-updates',- 'documentation',- 'error-handling',- 'typing',- 'ui-bugs',- 'mobile-responsive',- 'ux',- 'data-safety',- 'simplify',- 'module-hygiene',- 'api-contract',- 'react-lifecycle',- 'observability',- 'copy',- 'better-complexity',- 'better-cognitive-load',- 'better-structural-drift',- 'better-runtime-safety',- 'better-dependency-freedom',- 'better-test-quality'- ],+ // Derived, not restated: the audit stage IS the audit catalog. Listing the+ // types by hand made this a fourth edit site per new audit type and needed+ // a parity test whose only job was to catch the copy going stale.+ // `dependency-updates` is the one deliberate extra — it audits the manifest+ // but carries no file-issues/do-work toggle, so it is not a catalog type.+ taskTypes: [...AUDIT_TASK_TYPES, 'dependency-updates'],jobIds: ['job-wiki-maintenance', 'job-refresh-local-llm-catalog', 'job-refresh-cli-provider-catalogs']},{diff --git a/server/services/workflow.test.js b/server/services/workflow.test.jsindex 5b0a42170c..bc9d0574be 100644--- a/server/services/workflow.test.js+++ b/server/services/workflow.test.js@@ -65,9 +65,16 @@ describe('WORKFLOW_STAGES contract', () => {}});- it('places every audit task type in the audit stage', () => {+ // The audit stage is now derived from the catalog, so "every audit type is in+ // it" is true by construction and no longer worth asserting. What IS still a+ // decision — and the only part a reader could get wrong — is the one type the+ // stage adds on top of the catalog.+ it('adds dependency-updates to the derived audit stage, and nothing else', () => {const audit = WORKFLOW_STAGES.find(s => s.id === 'audit');- expect([...AUDIT_TASK_TYPES].filter(type => !audit.taskTypes.includes(type))).toEqual([]);+ const extras = audit.taskTypes.filter(type => !AUDIT_TASK_TYPES.has(type));+ expect(extras).toEqual(['dependency-updates']);+ // It earns the stage without being a catalog type: no file-issues toggle.+ expect(AUDIT_TASK_TYPES.has('dependency-updates')).toBe(false);});it('does not place the same job id in two stages', () => {