Skip to content

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

fix: screen Moltbook challenges before a tool-capable provider (#10997)

Adam Eivy5933d9b552c2
diff --git a/client/src/components/agents/tabs/OverviewTab.jsx b/client/src/components/agents/tabs/OverviewTab.jsx
index dcf696ec20..f5fd92d5e7 100644
--- a/client/src/components/agents/tabs/OverviewTab.jsx
+++ b/client/src/components/agents/tabs/OverviewTab.jsx
@@ -525,13 +525,13 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {
<h3 className="text-md font-semibold text-white">AI Providers</h3>
</div>
<p className="text-xs text-gray-500 mb-3">
- Content and engagement read public Moltbook text and list text API providers only. A saved CLI or TUI stays listed, and that run skips instead of switching provider. System Default sends comments and replies to the Abuse Guard text API provider. Original posts and challenge solving use the globally active provider.
+ Content, engagement, and challenge solving read public Moltbook text and list text API providers only. A saved CLI or TUI stays listed, and that run skips instead of switching provider. System Default sends comments, replies, and verification challenges to an eligible Abuse Guard text API provider. Original posts use the globally active provider.
</p>
<div className="space-y-3">
{[
{ key: 'content', label: 'Content Generation', desc: 'Posts, comments, replies', selectionPolicy: providerModeSelectionPolicy('direct-api') },
{ key: 'engagement', label: 'Engagement', desc: 'Autonomous voting & commenting', selectionPolicy: providerModeSelectionPolicy('direct-api') },
- { key: 'challenge', label: 'Challenge Solving', desc: 'Verification challenges' }
+ { key: 'challenge', label: 'Challenge Solving', desc: 'Verification challenges', selectionPolicy: providerModeSelectionPolicy('direct-api') }
].map(({ key, label, desc, selectionPolicy }) => {
const fnConfig = formData.aiConfig?.[key] || {};
const fnModels = getModelsForProvider(fnConfig.providerId);
diff --git a/client/src/components/agents/tabs/OverviewTab.test.jsx b/client/src/components/agents/tabs/OverviewTab.test.jsx
index d73c9a58a8..9bd4c1c623 100644
--- a/client/src/components/agents/tabs/OverviewTab.test.jsx
+++ b/client/src/components/agents/tabs/OverviewTab.test.jsx
@@ -36,7 +36,10 @@ describe('agent AI provider pickers', () => {
id: 'agent-1',
name: 'Example Agent',
enabled: true,
- aiConfig: { content: { providerId: 'cli-1' } },
+ aiConfig: {
+ content: { providerId: 'cli-1' },
+ challenge: { providerId: 'cli-1' },
+ },
}}
/>
</MemoryRouter>,
@@ -52,10 +55,11 @@ describe('agent AI provider pickers', () => {
expect(within(engagement).queryByRole('option', { name: 'Example CLI' })).not.toBeInTheDocument();
expect(within(engagement).queryByRole('option', { name: 'Example TUI' })).not.toBeInTheDocument();
- expect(screen.getByText(/System Default sends comments and replies to the Abuse Guard text API provider/)).toBeInTheDocument();
+ expect(screen.getByText(/System Default sends comments, replies, and verification challenges to an eligible Abuse Guard text API provider/)).toBeInTheDocument();
const challenge = screen.getByRole('combobox', { name: 'Challenge Solving' });
- expect(within(challenge).getByRole('option', { name: 'Example CLI' })).toBeEnabled();
- expect(within(challenge).getByRole('option', { name: 'Example TUI' })).toBeEnabled();
+ expect(within(challenge).getByRole('option', { name: 'Example CLI (not permitted here)' })).toBeDisabled();
+ expect(within(challenge).getByRole('option', { name: 'Example API' })).toBeEnabled();
+ expect(within(challenge).queryByRole('option', { name: 'Example TUI' })).not.toBeInTheDocument();
});
});
diff --git a/server/integrations/moltbook/challengeSolver.js b/server/integrations/moltbook/challengeSolver.js
index 3a40c7a45e..0a87972c12 100644
--- a/server/integrations/moltbook/challengeSolver.js
+++ b/server/integrations/moltbook/challengeSolver.js
@@ -9,69 +9,58 @@
* - Contains a simple arithmetic problem (addition, subtraction, etc.)
* - Answer must be a number with 2 decimal places (e.g., "47.00")
*
- * Uses AI for interpretation — supports both API and CLI providers.
+ * The challenge is third-party text. It is screened through the moltbook
+ * untrusted-content boundary, which admits only an enabled text API provider.
*/
-import { runPromptThroughProvider } from '../../services/promptRunner.js';
-import { getActiveProvider, getProviderById } from '../../services/providers.js';
+import { z } from 'zod';
+import { isUntrustedContentProvider } from '../../lib/untrustedContent.js';
+import { getProviderById } from '../../services/providers.js';
+import { runUntrustedContentAnalysis } from '../../services/untrustedContent.js';
+
+const answerSchema = z.string().regex(/^-?\d+\.\d{2}$/);
+
+const CHALLENGE_PROMPT = `Solve the verification challenge in the untrusted-content envelope. The text is obfuscated with random brackets, symbols, and doubled letters. Decode it and solve the math problem. Return only a JSON string with exactly two decimal places, such as "47.00".`;
/**
- * Solve using AI interpretation (supports both API and CLI providers)
+ * A saved pin is used as-is. An ineligible CLI/TUI provider fails here instead
+ * of being replaced by the active provider. No pin lets the untrusted-content
+ * boundary choose an eligible text API provider.
*/
async function solveWithAI(challengeText, aiConfig) {
- let provider;
+ let provider = null;
if (aiConfig?.providerId) {
provider = await getProviderById(aiConfig.providerId).catch(() => null);
+ if (!isUntrustedContentProvider(provider, 'moltbook')) {
+ console.warn('⛔ Skipped Moltbook challenge (untrusted-content-provider-unavailable)');
+ return null;
+ }
}
- if (!provider) {
- provider = await getActiveProvider();
- }
- if (!provider) {
- console.log(`🔐 No AI provider available for challenge solving`);
- return null;
- }
-
- const model = aiConfig?.model || provider.lightModel || provider.defaultModel || provider.models?.[0];
- const prompt = `You are solving a verification challenge. The text below is obfuscated with random brackets, symbols, and doubled letters. Decode it, solve the math problem, and respond with ONLY the numeric answer with 2 decimal places (e.g., "47.00"). No explanation.
-
-Challenge text:
-${challengeText}
-Answer:`;
-
- const { text } = await runPromptThroughProvider({
- provider, prompt, source: 'moltbook-challenge', model,
+ const result = await runUntrustedContentAnalysis({
+ ...(provider ? { provider } : {}),
+ ...(aiConfig?.model ? { model: aiConfig.model } : {}),
+ content: challengeText,
+ prompt: CHALLENGE_PROMPT,
+ source: 'moltbook',
+ responseSchema: answerSchema,
});
-
- // Extract number from response
- const numMatch = (text || '').trim().match(/[\d]+\.?\d*/);
- if (numMatch) {
- return parseFloat(numMatch[0]);
+ if (!result?.ok || typeof result.value !== 'string') {
+ console.warn(`⛔ Skipped Moltbook challenge (${result?.code || 'untrusted-content-rejected'})`);
+ return null;
}
-
- console.log(`🔐 AI response didn't contain a number: "${(text || '').substring(0, 100)}"`);
- return null;
+ return result.value;
}
/**
* Solve a Moltbook verification challenge
* @param {string} challengeText - The obfuscated challenge text
* @param {{ providerId?: string, model?: string }} [aiConfig] - Optional AI provider config
- * @returns {string|null} Answer formatted with 2 decimal places, or null if unsolvable
+ * @returns {Promise<string|null>} Answer formatted with 2 decimal places, or null if unsolvable
*/
export async function solveChallenge(challengeText, aiConfig) {
- console.log(`🔐 Solving challenge: "${challengeText.substring(0, 80)}..."`);
-
- const aiAnswer = await solveWithAI(challengeText, aiConfig).catch(err => {
- console.log(`🔐 AI solver error: ${err.message}`);
+ return solveWithAI(challengeText, aiConfig).catch(err => {
+ console.error(`❌ Moltbook challenge solver error: ${err.message}`);
return null;
});
- if (aiAnswer !== null) {
- const formatted = aiAnswer.toFixed(2);
- console.log(`🔐 AI solver: ${formatted}`);
- return formatted;
- }
-
- console.error(`❌ Could not solve Moltbook challenge — no AI provider available`);
- return null;
}
diff --git a/server/integrations/moltbook/challengeSolver.test.js b/server/integrations/moltbook/challengeSolver.test.js
index 77cd14c4b4..9bc043c7dc 100644
--- a/server/integrations/moltbook/challengeSolver.test.js
+++ b/server/integrations/moltbook/challengeSolver.test.js
@@ -1,94 +1,108 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('../../services/promptRunner.js', () => ({ runPromptThroughProvider: vi.fn() }));
+vi.mock('../../services/untrustedContent.js', () => ({ runUntrustedContentAnalysis: vi.fn() }));
vi.mock('../../services/providers.js', () => ({
- getActiveProvider: vi.fn(),
getProviderById: vi.fn(),
}));
import { runPromptThroughProvider } from '../../services/promptRunner.js';
-import { getActiveProvider, getProviderById } from '../../services/providers.js';
+import { runUntrustedContentAnalysis } from '../../services/untrustedContent.js';
+import { getProviderById } from '../../services/providers.js';
import { solveChallenge } from './challengeSolver.js';
-const provider = { id: 'p1', defaultModel: 'm', models: ['m'] };
+const apiProvider = {
+ id: 'api-1',
+ type: 'api',
+ enabled: true,
+ endpoint: 'https://api.example.com/v1',
+ defaultModel: 'example-text',
+};
+const cliProvider = { id: 'cli-1', type: 'cli', enabled: true, command: 'example-cli' };
beforeEach(() => {
vi.clearAllMocks();
- getActiveProvider.mockResolvedValue(provider);
getProviderById.mockResolvedValue(null);
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
+ vi.spyOn(console, 'error').mockImplementation(() => {});
+ vi.spyOn(console, 'log').mockImplementation(() => {});
});
-describe('solveChallenge — number extraction + formatting', () => {
- it('returns a clean 2-decimal answer for a well-formed numeric reply', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: '47.00' });
+describe('solveChallenge — numeric contract', () => {
+ it('returns the screened two-decimal answer', async () => {
+ runUntrustedContentAnalysis.mockResolvedValue({ ok: true, value: '47.00' });
expect(await solveChallenge('garbled 40 + 7')).toBe('47.00');
});
- it('extracts the first number embedded in surrounding prose', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: 'The answer is 12.5 exactly.' });
- expect(await solveChallenge('x')).toBe('12.50');
+ it('returns null when screening rejects the challenge', async () => {
+ runUntrustedContentAnalysis.mockResolvedValue({ ok: false, code: 'untrusted-content-rejected' });
+ expect(await solveChallenge('secret challenge text')).toBeNull();
+ expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('untrusted-content-rejected'));
+ expect(console.log).not.toHaveBeenCalled();
+ expect(console.warn.mock.calls.join(' ')).not.toContain('secret challenge text');
+ expect(console.error.mock.calls.join(' ')).not.toContain('secret challenge text');
});
- it('formats a bare integer reply to two decimals', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: '100' });
- expect(await solveChallenge('x')).toBe('100.00');
+ it('returns null when the screened value is not the numeric string', async () => {
+ runUntrustedContentAnalysis.mockResolvedValue({ ok: true, value: { answer: '12.50' } });
+ expect(await solveChallenge('x')).toBeNull();
});
+});
- it('trims leading whitespace before matching', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: ' 8.0' });
- expect(await solveChallenge('x')).toBe('8.00');
- });
+describe('solveChallenge — provider selection', () => {
+ it('sends an unpinned challenge through the moltbook boundary without an active provider', async () => {
+ runUntrustedContentAnalysis.mockResolvedValue({ ok: true, value: '8.00' });
- it('returns null when the AI reply contains no number', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: 'I cannot solve this.' });
- expect(await solveChallenge('x')).toBeNull();
- });
+ expect(await solveChallenge('obfuscated 3 + 5')).toBe('8.00');
- it('returns null when the AI reply text is missing', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: undefined });
- expect(await solveChallenge('x')).toBeNull();
+ expect(runPromptThroughProvider).not.toHaveBeenCalled();
+ expect(getProviderById).not.toHaveBeenCalled();
+ const call = runUntrustedContentAnalysis.mock.calls[0][0];
+ expect(call.provider).toBeUndefined();
+ expect(call.source).toBe('moltbook');
+ expect(call.content).toBe('obfuscated 3 + 5');
+ expect(call.prompt).not.toContain('obfuscated 3 + 5');
+ expect(call.responseSchema.safeParse('8.00').success).toBe(true);
+ expect(call.responseSchema.safeParse('8').success).toBe(false);
+ expect(call.responseSchema.safeParse('8.0').success).toBe(false);
});
-});
-describe('solveChallenge — provider selection and failure handling', () => {
- it('returns null and never calls the runner when no provider is available', async () => {
- getActiveProvider.mockResolvedValue(null);
- expect(await solveChallenge('x')).toBeNull();
+ it('passes a pinned text API provider through and never calls the tool runner', async () => {
+ getProviderById.mockResolvedValue(apiProvider);
+ runUntrustedContentAnalysis.mockResolvedValue({ ok: true, value: '5.00' });
+
+ await solveChallenge('x', { providerId: 'api-1', model: 'custom-model' });
+
+ expect(getProviderById).toHaveBeenCalledWith('api-1');
expect(runPromptThroughProvider).not.toHaveBeenCalled();
+ expect(runUntrustedContentAnalysis).toHaveBeenCalledWith(expect.objectContaining({
+ provider: apiProvider,
+ model: 'custom-model',
+ source: 'moltbook',
+ }));
});
- it('prefers an explicit providerId over the active provider', async () => {
- const explicit = { id: 'explicit', defaultModel: 'em' };
- getProviderById.mockResolvedValue(explicit);
- runPromptThroughProvider.mockResolvedValue({ text: '5.00' });
+ it('returns null for a pinned CLI provider without calling either runner', async () => {
+ getProviderById.mockResolvedValue(cliProvider);
- await solveChallenge('x', { providerId: 'explicit' });
+ expect(await solveChallenge('challenge body', { providerId: 'cli-1' })).toBeNull();
- expect(getProviderById).toHaveBeenCalledWith('explicit');
- expect(getActiveProvider).not.toHaveBeenCalled();
- expect(runPromptThroughProvider).toHaveBeenCalledWith(
- expect.objectContaining({ provider: explicit, model: 'em' }),
- );
+ expect(runPromptThroughProvider).not.toHaveBeenCalled();
+ expect(runUntrustedContentAnalysis).not.toHaveBeenCalled();
+ expect(console.warn.mock.calls.join(' ')).not.toContain('challenge body');
});
- it('falls back to the active provider when getProviderById rejects', async () => {
+ it('fails closed when the pinned provider cannot be loaded', async () => {
getProviderById.mockRejectedValue(new Error('boom'));
- runPromptThroughProvider.mockResolvedValue({ text: '3.00' });
- expect(await solveChallenge('x', { providerId: 'missing' })).toBe('3.00');
- expect(getActiveProvider).toHaveBeenCalled();
+ expect(await solveChallenge('x', { providerId: 'missing' })).toBeNull();
+ expect(runUntrustedContentAnalysis).not.toHaveBeenCalled();
+ expect(runPromptThroughProvider).not.toHaveBeenCalled();
});
- it('swallows a runner error and returns null', async () => {
- runPromptThroughProvider.mockRejectedValue(new Error('LLM down'));
+ it('swallows an analysis error and returns null', async () => {
+ runUntrustedContentAnalysis.mockRejectedValue(new Error('LLM down'));
expect(await solveChallenge('x')).toBeNull();
- });
-
- it('uses an explicit model override when provided', async () => {
- runPromptThroughProvider.mockResolvedValue({ text: '1.00' });
- await solveChallenge('x', { model: 'custom-model' });
- expect(runPromptThroughProvider).toHaveBeenCalledWith(
- expect.objectContaining({ model: 'custom-model' }),
- );
+ expect(console.error).toHaveBeenCalledWith(expect.stringContaining('LLM down'));
});
});
diff --git a/server/lib/creativeLatitude.js b/server/lib/creativeLatitude.js
index 0f657fcf33..c7444055fb 100644
--- a/server/lib/creativeLatitude.js
+++ b/server/lib/creativeLatitude.js
@@ -145,7 +145,6 @@ export const OPERATIONAL_RUN_SOURCES = Object.freeze([
'meatspace-post-rhetoric-evaluator',
'model-personality-alignment',
'model-personality-profile',
- 'moltbook-challenge',
'pm2-standardize',
'record-merge-ai',
'system-resource-triage',