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
feat: pin Code Animation authoring route and record opted-in substitution (#9387)
[._.]/ Adam Eivyd264ee0241c2
diff --git a/server/lib/codeAnimationProjects.js b/server/lib/codeAnimationProjects.jsindex 208d36f9b1..c06442a2f1 100644--- a/server/lib/codeAnimationProjects.js+++ b/server/lib/codeAnimationProjects.js@@ -18,6 +18,10 @@ const localSettingsSchema = z.object({mode: z.enum(['api', 'cli', 'tui']).nullable().default(null),model: z.string().max(256).nullable().default(null),effort: z.enum(EFFORT_LEVELS).nullable().default(null),+ // 'pinned' (default): the selected route must run the work; a fallback or+ // swapped route is an error. 'allowed': substitution is an explicit decision+ // that the effective-route record carries.+ substitution: z.enum(['pinned', 'allowed']).default('pinned'),}).strict();export const codeAnimationProjectSchema = z.object({diff --git a/server/services/codeAnimation/preflight.js b/server/services/codeAnimation/preflight.jsindex f5985e265c..a77e043f56 100644--- a/server/services/codeAnimation/preflight.js+++ b/server/services/codeAnimation/preflight.js@@ -5,12 +5,49 @@ import { applyModelAccess } from '../../lib/aiToolkit/internal/modelAccess.js';import { harnessForProvider, providerRouteMode } from '../../lib/providerHarnesses.js';import { effortLevelsForProvider, hasEffortFlag, isConfiguredDefaultModel, antigravityBaseModels } from '../../lib/providerModels.js';import { isCompositeProviderId } from '../../lib/providerRef.js';+import { isVisionCapableCliProvider } from '../../lib/localModelHeuristics.js';+import { isVisionCapableCodexTuiProvider } from '../../lib/codex.js';+import { ServerError } from '../../lib/errorHandler.js';++const substitutionOf = requested => requested?.substitution === 'allowed' ? 'allowed' : 'pinned';++/** Pure route capability map: what the selected route can honestly do. No tool or provider probe. */+export function routeCapabilities(provider, mode) {+ const accepted = mode === 'api' || isVisionCapableCliProvider(provider) || isVisionCapableCodexTuiProvider(provider);+ return {+ packageImportExport: true,+ // API text may carry structured, validated package files without shell/tools.+ textPackageOutput: Boolean(mode),+ // The route can receive images, but no render/inspection adapter is wired yet.+ imageInputAccepted: Boolean(accepted),+ imageInspection: false,+ visualReview: false,+ research: false,+ toolsDeclared: mode === 'api' ? [] : null,+ };+}++/**+ * Compare the route that actually ran with the pinned route. Pinned mode throws on+ * any substitution; an opted-in substitution is returned as a recorded decision.+ */+export function recordEffectiveRoute(resolved, requested, runResult) {+ const ran = runResult?.fallbackProvider || runResult?.provider || null;+ const effective = { providerId: ran?.id ?? resolved.providerId, model: runResult?.model ?? resolved.model, effort: resolved.effort };+ const substituted = effective.providerId !== resolved.providerId || effective.model !== resolved.model || Boolean(runResult?.usedFallback);+ const policy = substitutionOf(requested);+ if (substituted && policy === 'pinned') {+ throw new ServerError('The pinned authoring route was substituted; refusing to record it as the requested route.', { status: 409, code: 'AUTHORING_ROUTE_SUBSTITUTED' });+ }+ return { effective, substituted, substitution: policy, decision: substituted ? { optedIn: true, from: resolved.providerId, to: effective.providerId } : null };+}export async function preflightProductionProject(id) {const project = await getProductionProject(id);const requested = project.localSettings;const problems = [];const result = { requested, resolved: null, effective: null, executed: false, problems,+ substitution: substitutionOf(requested), allowFallback: substitutionOf(requested) === 'allowed',capabilities: { packageImportExport: true, authoringDispatch: false, renderTools: false, imageInspection: false, research: false },notes: ['Settings preview only. Authoring, rendering, visual inspection and research adapters are not connected; use package export/import.'],};@@ -34,6 +71,7 @@ export async function preflightProductionProject(id) {const connectionId = provider.serviceId ?? null;const effortLevels = mode === 'api' ? [] : effortLevelsForProvider(provider, model) || [];const effort = requested.effort || provider.effort || null;+ result.capabilities = { ...result.capabilities, ...routeCapabilities(provider, mode) };result.resolved = { providerId: provider.id, harness, connectionId, mode, model, effort: null };if (!mode || !harness) problems.push('The selected route has no recognized authoring harness or mode.');if (requested.mode && requested.mode !== mode) problems.push('The saved execution mode no longer matches the selected route.');diff --git a/server/services/codeAnimation/preflight.test.js b/server/services/codeAnimation/preflight.test.jsindex 4ea2e8fd0d..dedfe075dc 100644--- a/server/services/codeAnimation/preflight.test.js+++ b/server/services/codeAnimation/preflight.test.js@@ -11,7 +11,7 @@ vi.mock('../promptRunner.js', async importOriginal => ({ ...await importOriginalimport { getProjectRecord } from './projectStore.js';import { getProviderById, getSelectableProviders } from '../providers.js';import { runPromptThroughProvider } from '../promptRunner.js';-import { preflightProductionProject } from './preflight.js';+import { preflightProductionProject, recordEffectiveRoute } from './preflight.js';const app = express();app.use('/api/code-animation', router);@@ -75,3 +75,21 @@ describe('saved production authoring preflight', () => {expect(getProviderById).not.toHaveBeenCalled();});});++describe('pinned route and substitution provenance', () => {+ const resolved = { providerId: 'example', model: 'example-model', effort: 'high' };+ it('defaults to pinned, reports route capabilities and never claims visual review', async () => {+ getSelectableProviders.mockResolvedValue({ providers: [{ ...provider, type: 'api', models: ['example-model'] }] });+ const result = await preflightProductionProject('project');+ expect(result).toMatchObject({ substitution: 'pinned', allowFallback: false, capabilities: { textPackageOutput: true, imageInputAccepted: true, imageInspection: false, visualReview: false, research: false } });+ expect(runPromptThroughProvider).not.toHaveBeenCalled();+ });+ it('refuses a silent fallback in pinned mode', () => {+ expect(() => recordEffectiveRoute(resolved, {}, { provider: { id: 'other' }, usedFallback: true })).toThrow(/substituted/);+ });+ it('records an opted-in substitution and passes an unchanged route through', () => {+ const swapped = recordEffectiveRoute(resolved, { substitution: 'allowed' }, { provider: { id: 'example' }, fallbackProvider: { id: 'other' }, model: 'm2', usedFallback: true });+ expect(swapped).toMatchObject({ substituted: true, effective: { providerId: 'other', model: 'm2' }, decision: { optedIn: true, from: 'example', to: 'other' } });+ expect(recordEffectiveRoute(resolved, {}, { provider: { id: 'example' }, model: 'example-model' })).toMatchObject({ substituted: false, decision: null });+ });+});