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: require operator authority for cover design, promotion plans, and POST LLM drills (#10989)
Adam Eivyb0abbdb62c8b
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.jsindex 2028a6ea5d..dd7f88ce78 100644--- a/server/lib/hostControlRoutes.js+++ b/server/lib/hostControlRoutes.js@@ -55,10 +55,15 @@* derive-from-manuscript/commit, manuscript cuts preview/apply, comic* extract-pages, audio extract-lines, scene video, TTS and music* rendering): none reaches the staged runner.- * - Caller-prompted AI outside Pipeline (#10908): game feedback, rounds- * generate/evaluate/derive-parts, personality generate, system-resource- * triage, mood-board style synthesis/compose/analyze and CoS task enhance- * take caller text and/or a caller-chosen provider; gated whole-operation.+ * - Caller-prompted AI outside Pipeline (#10908, #10989): game feedback,+ * rounds generate/evaluate/derive-parts, personality generate,+ * system-resource triage, mood-board style synthesis/compose/analyze, CoS+ * task enhance, Music Video cover design/generation and promotion plans,+ * and POST LLM scoring, rhetoric evaluation and drill-cache fill take+ * caller text and/or a caller-chosen provider; gated whole-operation.+ * POST /api/meatspace/post/drill is gated only when `type` is an LLM+ * drill; math, memory and cognitive drills stay open. Cover compose,+ * lettering saves and promotion reads stay open.* - Creative Director and Creative Commissions (#10867): project create/edit* choose agent instructions and provider pins; start/resume/directive/* replan/plan-step/auto-cast/smoke-test/review enqueue or re-arm writable@@ -135,6 +140,7 @@*/import { canonicalStringify, isPlainObject } from './objects.js';+import { LLM_DRILL_TYPES } from './postDrillTypes.js';import { escapeRegExp } from './textUtils.js';export const HOST_CONTROL_ROUTES = Object.freeze([@@ -646,6 +652,18 @@ export const HOST_CONTROL_ROUTES = Object.freeze(['POST /api/mood-boards/:id/compose-prompt','POST /api/mood-boards/:id/analyze','POST /api/cos/tasks/enhance',+ // Music Video cover design/generation and promotion planning, and POST LLM+ // drills (#10989). Each hands free text and/or a caller-chosen provider to+ // the prompt runner (or an image job a CLI/TUI agent can run) with no+ // tool-free restriction. Cover compose, lettering PUT, thumbnail selection+ // and promotion GET only record or read. POST /api/meatspace/post/drill is+ // body-gated below so deterministic drills stay open.+ 'POST /api/music-video/:id/publish-kit/cover-art/design',+ 'POST /api/music-video/:id/publish-kit/cover-art/generate',+ 'POST /api/music-video/:id/publish/promotion-plan',+ 'POST /api/meatspace/post/score-llm',+ 'POST /api/meatspace/post/rhetoric/evaluate',+ 'POST /api/meatspace/post/drill-cache/fill',// Writers Room authoring reaches the staged runner, including CLI/TUI// fallback. Stored prose and live cursor text are caller-controlled; a@@ -844,6 +862,9 @@ const COMPILED_BODY_ROUTES = [// sources, triage and Brain/Goal promotion stay data-only and open.['POST /api/review/queue/resolve', (body) => /^\s*cos:/i.test(body?.id) ? ['id'] : []],['POST /api/review/queue/promote-ask', (body) => body?.target === 'task' ? ['target'] : []],+ // LLM drill types reach a caller-chosen provider (#10989). Math, memory and+ // cognitive types stay open, including a missing or unknown type.+ ['POST /api/meatspace/post/drill', (body) => LLM_DRILL_TYPES.includes(body?.type) ? ['type'] : []],].map(([route, pick]) => ({ ...compileRoute(route), pick }));/** The host-control keys a request body names, for `method path` of a policy store; [] elsewhere. */diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.jsindex 7ed15d6ec8..9e6ff23d57 100644--- a/server/lib/hostControlRoutes.test.js+++ b/server/lib/hostControlRoutes.test.js@@ -4,6 +4,7 @@ import {HOST_CONTROL_ROUTES, changedVoiceConfigHostControlPaths, hostControlBodyKeys, hostControlSettingsPathsIn,hostControlRouteFor, isHostControlRoute, voiceConfigHostControlPathsIn,} from './hostControlRoutes.js';+import { LLM_DRILL_TYPES } from './postDrillTypes.js';describe('voice config instruction paths (#10990)', () => {const stored = {@@ -672,6 +673,51 @@ describe('Caller-prompted AI outside Pipeline policy (#10908)', () => {});});+describe('Music Video cover/promotion and POST LLM drill policy (#10989)', () => {+ const protectedRoutes = [+ 'POST /api/music-video/:id/publish-kit/cover-art/design',+ 'POST /api/music-video/:id/publish-kit/cover-art/generate',+ 'POST /api/music-video/:id/publish/promotion-plan',+ 'POST /api/meatspace/post/score-llm',+ 'POST /api/meatspace/post/rhetoric/evaluate',+ 'POST /api/meatspace/post/drill-cache/fill',+ ];++ it('gates each audited operation and maps every entry to a mounted route', () => {+ const mounted = new Set(getApiRouteCatalog().routes.map(({ method, path }) => method + ' ' + path));+ for (const route of protectedRoutes) {+ const [method, path] = route.split(' ');+ expect(mounted.has(route), route).toBe(true);+ expect(hostControlRouteFor(method, path), route).toBe(route);+ expect(hostControlRouteFor(method, path.toUpperCase() + '/'), route).toBe(route);+ }+ });++ it('gates an LLM drill type on the shared drill route and leaves other types open', () => {+ expect(isHostControlRoute('POST', '/api/meatspace/post/drill')).toBe(false);+ for (const type of LLM_DRILL_TYPES) {+ expect(hostControlBodyKeys('POST', '/api/meatspace/post/drill', { type }), type).toEqual(['type']);+ expect(hostControlBodyKeys('post', '/API/meatspace/post/drill/', { type }), type).toEqual(['type']);+ }+ for (const type of ['multiplication', 'memory-fill-blank', 'n-back', 'WORD-ASSOCIATION', '', null]) {+ expect(hostControlBodyKeys('POST', '/api/meatspace/post/drill', { type }), String(type)).toEqual([]);+ }+ expect(hostControlBodyKeys('POST', '/api/meatspace/post/drill', null)).toEqual([]);+ expect(hostControlBodyKeys('POST', '/api/meatspace/post/drill', ['word-association'])).toEqual([]);+ });++ it('keeps cover compose, lettering, promotion reads and deterministic drills open', () => {+ for (const [method, path] of [+ ['POST', '/api/music-video/:id/publish-kit/cover-art'],+ ['PUT', '/api/music-video/:id/publish-kit/cover-art/design'],+ ['PUT', '/api/music-video/:id/publish-kit/thumbnail'],+ ['GET', '/api/music-video/:id/publish/promotion-plan'],+ ['POST', '/api/meatspace/post/drill'],+ ['GET', '/api/meatspace/post/drill-cache/status'],+ ]) expect(isHostControlRoute(method, path), `${method} ${path}`).toBe(false);+ });+});+describe('3D model rigging host-workers (#10922)', () => {const protectedRoutes = ['POST /api/rigging/models/:id',diff --git a/server/routes/hostControlMusicVideoPostAi.test.js b/server/routes/hostControlMusicVideoPostAi.test.jsnew file mode 100644index 0000000000..d55df08b5d--- /dev/null+++ b/server/routes/hostControlMusicVideoPostAi.test.js@@ -0,0 +1,270 @@+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';+import express from 'express';+import { request } from '../lib/testHelper.js';+import { errorMiddleware } from '../lib/errorHandler.js';+import { DEV_PROXY_CLIENT_ADDRESS_HEADER } from '../../lib/portosAuthCore.js';+import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';+import { derivePeerAuthToken, PEER_AUTH_HEADER, PEER_INSTANCE_HEADER } from '../lib/peerHttpClient.js';++vi.mock('../lib/fileUtils.js', async (importOriginal) =>+ makePathsProxy(await importOriginal(), { dataRoot: () => lazyTempDataRoot('portos-mv-post-ai-') }));+afterAll(cleanupTempDataRoots);+afterEach(() => vi.restoreAllMocks());+vi.mock('../services/instanceIdentity.js', () => ({+ loadData: vi.fn(async () => ({ peers: [{+ id: 'example-peer', instanceId: 'example-instance', enabled: true, syncSecret: 'a'.repeat(32),+ }] })),+}));++// Music Video cover design/generation, promotion plans, and POST LLM drills+// (#10989). Real routers behind the real auth and host-control gates. Cover+// design runs for real against a synthetic CLI provider so the prompt-runner+// sink can be asserted; cover generation's image queue is the same doubled+// enqueueJob. The other families double their AI service so no provider, run+// record or fill can start.+const auth = vi.hoisted(() => ({ enabled: false }));+const cliProvider = vi.hoisted(() => ({+ id: 'example-cli', name: 'Example CLI', type: 'cli', enabled: true, command: 'example-agent', args: [], defaultModel: 'example-model',+}));+const sink = vi.hoisted(() => ({+ runPromptThroughProvider: vi.fn(async () => ({ text: '{}', model: 'example-model', provider: { id: 'example-cli' } })),+ enqueueJob: vi.fn(async () => ({ jobId: 'job-example' })),+}));+const DRAFT = {+ imagePrompt: 'Example image prompt: a grainy profile in blue light',+ rationale: 'Example reason.',+ design: {+ layout: 'top-center', typeface: 'serif', weight: 'light', letterCase: 'lower',+ titleColor: '#f0e6d2', accentColor: '#3366ff', backdrop: 'none', tagStyle: 'plain',+ },+};++vi.mock('../services/auth.js', async (importOriginal) => ({+ ...await importOriginal(),+ isAuthEnabled: vi.fn(async () => auth.enabled),+ verifyPassword: vi.fn(async () => true),+}));+vi.mock('../services/settings.js', () => ({+ settingsEvents: { on: vi.fn(), off: vi.fn(), emit: vi.fn() },+ getSettings: vi.fn(async () => ({})),+ updateSettingsWith: vi.fn(async (mutate) => mutate({})),+}));+vi.mock('../services/promptRunner.js', async (importOriginal) => ({+ ...await importOriginal(),+ runPromptThroughProvider: sink.runPromptThroughProvider,+}));+vi.mock('../services/mediaJobQueue/index.js', async (importOriginal) => ({+ ...await importOriginal(),+ enqueueJob: sink.enqueueJob,+}));+vi.mock('../services/musicVideo/promotionPlan.js', () => ({+ planMusicVideoPromotion: vi.fn(async () => ({ planKey: 'example-plan', steps: [] })),+ promotionPlanSteps: vi.fn(async () => ({ planKey: 'example-plan', steps: [] })),+}));+vi.mock('../services/meatspacePostLlm.js', () => ({+ generateLlmDrill: vi.fn(async () => ({ type: 'word-association', questions: [{ prompt: 'example' }] })),+ scoreLlmDrill: vi.fn(async () => ({ score: 1 })),+}));+vi.mock('../services/meatspacePostRhetoric.js', () => ({+ evaluateRhetoricAttempt: vi.fn(async () => ({ score: 1 })),+}));+vi.mock('../services/meatspacePostDrillCache.js', () => ({+ getCacheStats: vi.fn(() => ({})),+ requestCacheFill: vi.fn(() => ['compound-chain']),+ getCachedDrill: vi.fn(() => null),+ triggerReplenish: vi.fn(),+}));+vi.mock('../services/meatspacePostAdaptive.js', async (importOriginal) => ({+ ...await importOriginal(),+ resolveDrillConfig: vi.fn(async (_type, config) => ({ config: config ?? {}, adaptive: null, progression: null })),+}));++import { authGate, hostControlBodyGate, hostControlRouteGate } from '../services/authGate.js';+import { createSession } from '../services/auth.js';+import musicVideoRoutes from './musicVideo.js';+import meatspaceRoutes from './meatspacePostRoutes.js';+import { __setCoverArtDepsForTests } from '../services/musicVideo/coverArt.js';+import { createProject } from '../services/musicVideo/projects.js';+import { planMusicVideoPromotion, promotionPlanSteps } from '../services/musicVideo/promotionPlan.js';+import { generateLlmDrill, scoreLlmDrill } from '../services/meatspacePostLlm.js';+import { evaluateRhetoricAttempt } from '../services/meatspacePostRhetoric.js';+import { requestCacheFill, triggerReplenish } from '../services/meatspacePostDrillCache.js';+import * as postService from '../services/meatspacePost.js';++let projectId;+const picker = { providerId: cliProvider.id, model: 'example-model' };+const operations = () => [+ [`/api/music-video/${projectId}/publish-kit/cover-art/design`, { direction: 'Example direction', ...picker }, sink.runPromptThroughProvider, 200],+ [`/api/music-video/${projectId}/publish-kit/cover-art/generate`, { notes: 'Example notes' }, sink.enqueueJob, 200],+ [`/api/music-video/${projectId}/publish/promotion-plan`, { goal: 'Example goal', audience: 'Example audience', ...picker }, planMusicVideoPromotion, 201],+ ['/api/meatspace/post/score-llm', {+ type: 'word-association', drillData: { prompt: 'Example' }, responses: [{ response: 'Example answer' }], timeLimitMs: 1000, ...picker,+ }, scoreLlmDrill, 200],+ ['/api/meatspace/post/rhetoric/evaluate', {+ attemptId: 'attempt-example', mode: 'meter', prompt: 'Example prompt', response: 'Example response', ...picker,+ }, evaluateRhetoricAttempt, 200],+ ['/api/meatspace/post/drill-cache/fill', { types: ['compound-chain'], ...picker }, requestCacheFill, 200],+ ['/api/meatspace/post/drill', { type: 'word-association', ...picker }, generateLlmDrill, 200],+];+const sinks = () => [...new Set([...operations().map(([, , service]) => service), triggerReplenish])];++const appFor = (address = '192.0.2.10') => {+ const app = express();+ app.use((req, _res, next) => {+ Object.defineProperty(req.socket, 'remoteAddress', { value: address });+ next();+ });+ app.use(authGate, hostControlRouteGate, express.json(), hostControlBodyGate);+ app.use('/api/music-video', musicVideoRoutes);+ app.use('/api/meatspace', meatspaceRoutes);+ app.use(errorMiddleware);+ return app;+};+const post = (app, [path, body], headers = {}) => {+ const pending = request(app).post(path);+ for (const [name, value] of Object.entries(headers)) pending.set(name, value);+ return pending.send(body);+};+const expectNoEffects = () => {+ for (const service of sinks()) expect(service).not.toHaveBeenCalled();+};++beforeAll(async () => {+ projectId = (await createProject({ name: 'Example Song' })).id;+});++beforeEach(() => {+ vi.clearAllMocks();+ auth.enabled = false;+ sink.runPromptThroughProvider.mockResolvedValue({ text: JSON.stringify(DRAFT), model: 'example-model' });+ sink.enqueueJob.mockResolvedValue({ jobId: 'job-example' });+ vi.spyOn(postService, 'getPostConfig').mockResolvedValue({ rhetoricEvaluator: { enabled: true } });+ __setCoverArtDepsForTests({+ compose: vi.fn(async () => ({ width: 1, height: 1 })),+ enqueue: sink.enqueueJob,+ defaultRoute: async () => ({ mode: 'grok', model: null }),+ // A finished job is not in flight, so a later authorized generate can queue again.+ jobStatus: async () => 'completed',+ runner: async () => ({+ resolveProviderAndModel: async ({ providerId, model }) => ({+ provider: !providerId || providerId === cliProvider.id ? cliProvider : null,+ selectedModel: model || cliProvider.defaultModel,+ }),+ runPromptThroughProvider: sink.runPromptThroughProvider,+ }),+ getSettings: async () => ({}),+ getPlatforms: async () => ({ distrokid: { account: 'Example Artist' } }),+ imageParams: async (_settings, route, common) => ({ ...common, provider: route.mode }),+ withStyle: async (_project, params) => params,+ fonts: async () => [],+ registerFonts: async () => {},+ artistStyle: async () => null,+ });+});++describe('Music Video cover/promotion and POST LLM operator authority (#10989)', () => {+ it('refuses a remote password-free caller, including spoofed-proxy variants, before any provider call', async () => {+ for (const operation of operations()) {+ for (const [address, headers] of [+ ['192.0.2.10', {}],+ ['127.0.0.1', { [DEV_PROXY_CLIENT_ADDRESS_HEADER]: '192.0.2.10' }],+ ['192.0.2.10', { [DEV_PROXY_CLIENT_ADDRESS_HEADER]: '127.0.0.1' }],+ ]) {+ const response = await post(appFor(address), operation, headers);+ expect([response.status, response.body.code], operation[0]).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);+ }+ }+ expectNoEffects();+ });++ it('requires authentication with a password, denies legacy Basic and scoped-peer credentials', async () => {+ auth.enabled = true;+ for (const operation of operations()) {+ for (const [headers, status, code] of [+ [{}, 401, 'AUTH_REQUIRED'],+ [{ Authorization: 'Bearer invalid-session' }, 401, 'AUTH_REQUIRED'],+ [{ Authorization: 'Basic ' + Buffer.from(':example-password').toString('base64') }, 403, 'HOST_CONTROL_FORBIDDEN'],+ [{+ [PEER_AUTH_HEADER]: derivePeerAuthToken('a'.repeat(32), 'example-instance'),+ [PEER_INSTANCE_HEADER]: 'example-instance',+ }, 403, 'PEER_SCOPE_FORBIDDEN'],+ ]) {+ const response = await post(appFor(), operation, headers);+ expect([response.status, response.body.code], operation[0]).toEqual([status, code]);+ }+ }+ expectNoEffects();+ });++ it('matches case and trailing-slash variants before any provider call', async () => {+ for (const operation of operations()) {+ const variant = [operation[0].toUpperCase() + '/', operation[1]];+ const response = await post(appFor(), variant);+ expect([response.status, response.body.code], operation[0]).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);+ }+ expectNoEffects();+ });++ it('keeps working for local callers, operator sessions and delegated agent sessions', async () => {+ const operator = await createSession();+ const agent = await createSession({ label: 'agent' });+ for (const [enabled, address, headers] of [+ [false, '127.0.0.1', {}],+ [true, '192.0.2.10', { Authorization: `Bearer ${operator.token}` }],+ [true, '192.0.2.10', { Cookie: `portos_auth=${agent.token}` }],+ [true, '192.0.2.10', { Authorization: `Bearer ${agent.token}` }],+ ]) {+ auth.enabled = enabled;+ for (const operation of operations()) {+ const response = await post(appFor(address), operation, headers);+ expect(response.status, `${operation[0]}: ${JSON.stringify(response.body)}`).toBe(operation[3]);+ expect(operation[2], operation[0]).toHaveBeenCalled();+ }+ }+ });++ it('lets an authorized cover design reach the chosen CLI provider and nobody else', async () => {+ const operation = operations()[0];+ expect((await post(appFor('192.0.2.10'), operation)).status).toBe(403);+ expect(sink.runPromptThroughProvider).not.toHaveBeenCalled();++ expect((await post(appFor('127.0.0.1'), operation)).status).toBe(200);+ expect(sink.runPromptThroughProvider).toHaveBeenCalledTimes(1);+ expect(sink.runPromptThroughProvider.mock.calls[0][0]).toEqual(expect.objectContaining({+ provider: cliProvider, source: 'music-video-cover-design', model: 'example-model',+ }));+ expect(sink.runPromptThroughProvider.mock.calls[0][0].prompt).toContain('Example direction');+ });++ it('lets an authorized cover image reach enqueueJob', async () => {+ const operation = operations()[1];+ expect((await post(appFor('192.0.2.10'), operation)).status).toBe(403);+ expect(sink.enqueueJob).not.toHaveBeenCalled();++ expect((await post(appFor('127.0.0.1'), operation)).status).toBe(200);+ expect(sink.enqueueJob).toHaveBeenCalledWith(expect.objectContaining({+ kind: 'image', owner: `music-video-cover-art:${projectId}`,+ }));+ });++ it('keeps a non-LLM drill open to a remote caller', async () => {+ const response = await post(appFor(), ['/api/meatspace/post/drill', { type: 'doubling-chain' }]);+ expect(response.status, JSON.stringify(response.body)).toBe(200);+ expect(response.body.questions?.length).toBeGreaterThan(0);+ expectNoEffects();+ });++ it('leaves cover compose, lettering saves and promotion reads open to a remote caller', async () => {+ const app = appFor();+ const compose = await request(app).post(`/api/music-video/${projectId}/publish-kit/cover-art`).send({});+ expect([compose.status, compose.body.code]).toEqual([422, 'VALIDATION_ERROR']);++ const lettering = await request(app).put(`/api/music-video/${projectId}/publish-kit/cover-art/design`).send({ design: { layout: 'top-center' } });+ expect(lettering.status, JSON.stringify(lettering.body)).toBe(200);++ const plan = await request(app).get(`/api/music-video/${projectId}/publish/promotion-plan`);+ expect(plan.status).toBe(200);+ expect(promotionPlanSteps).toHaveBeenCalled();+ expectNoEffects();+ });+});