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(agents): challenge solver, AI config threading, draft preservation
Adam Eivyea927c8bb55c
diff --git a/client/src/components/agents/tabs/ToolsTab.jsx b/client/src/components/agents/tabs/ToolsTab.jsxindex eb38d27be6..b9b1a67c93 100644--- a/client/src/components/agents/tabs/ToolsTab.jsx+++ b/client/src/components/agents/tabs/ToolsTab.jsx@@ -132,18 +132,30 @@ export default function ToolsTab({ agentId, agent }) {const handlePublishPost = async () => {if (!postTitle || !postContent) return;setPublishing(true);- await api.publishAgentPost(agentId, selectedAccountId, selectedSubmolt, postTitle, postContent);+ const result = await api.publishAgentPost(agentId, selectedAccountId, selectedSubmolt, postTitle, postContent);if (activeDraftId) {- await api.deleteAgentDraft(agentId, activeDraftId).catch(() => {});- setActiveDraftId(null);+ if (result?.verificationFailed) {+ toast.error('Post verification failed — draft preserved for retry');+ } else {+ await api.updateAgentDraft(agentId, activeDraftId, {+ status: 'published',+ publishedPostId: result?.id || result?._id || result?.post_id || null,+ publishedAt: new Date().toISOString()+ }).catch(() => {});+ setActiveDraftId(null);+ toast.success('Post published');+ }loadDrafts();+ } else {+ toast.success('Post published');}- setPostTitle('');- setPostContent('');+ if (!result?.verificationFailed) {+ setPostTitle('');+ setPostContent('');+ }setPublishing(false);- toast.success('Post published');api.getAgentRateLimits(selectedAccountId).then(setRateLimits).catch(() => {});};@@ -175,20 +187,31 @@ export default function ToolsTab({ agentId, agent }) {const handlePublishComment = async () => {if (!selectedPost || !commentContent) return;setPublishingComment(true);- await api.publishAgentComment(+ const result = await api.publishAgentComment(agentId, selectedAccountId, selectedPost.id, commentContent, replyToId || undefined);if (activeDraftId) {- await api.deleteAgentDraft(agentId, activeDraftId).catch(() => {});- setActiveDraftId(null);+ if (result?.verificationFailed) {+ toast.error('Comment verification failed — draft preserved for retry');+ } else {+ await api.updateAgentDraft(agentId, activeDraftId, {+ status: 'published',+ publishedAt: new Date().toISOString()+ }).catch(() => {});+ setActiveDraftId(null);+ toast.success('Comment published');+ }loadDrafts();+ } else {+ toast.success('Comment published');}- setCommentContent('');- setReplyToId(null);+ if (!result?.verificationFailed) {+ setCommentContent('');+ setReplyToId(null);+ }setPublishingComment(false);- toast.success('Comment published');handleViewPost(selectedPost);api.getAgentRateLimits(selectedAccountId).then(setRateLimits).catch(() => {});};@@ -564,50 +587,60 @@ export default function ToolsTab({ agentId, agent }) {{drafts.length > 0 && (<div className="bg-port-card border border-port-border rounded-lg p-4"><h3 className="font-semibold text-white mb-3">- Drafts ({drafts.length})+ Drafts ({drafts.filter(d => d.status !== 'published').length})+ {drafts.some(d => d.status === 'published') && (+ <span className="text-xs text-gray-500 font-normal ml-2">+ +{drafts.filter(d => d.status === 'published').length} published+ </span>+ )}</h3><div className="space-y-2 max-h-[300px] overflow-y-auto">- {drafts.map(draft => (- <div- key={draft.id}- className={`p-3 border rounded transition-colors ${- activeDraftId === draft.id- ? 'border-port-accent bg-port-accent/10'- : 'border-port-border hover:border-port-border/80'- }`}- >- <div className="flex items-start justify-between">- <div className="flex-1 min-w-0 cursor-pointer" onClick={() => handleLoadDraft(draft)}>- <div className="flex items-center gap-2">- <span className="text-xs px-1.5 py-0.5 rounded bg-port-accent/20 text-port-accent">- {draft.type}- </span>- {draft.submolt && (- <span className="text-xs text-gray-500">/{draft.submolt}</span>+ {drafts.map(draft => {+ const isPublished = draft.status === 'published';+ return (+ <div+ key={draft.id}+ className={`p-3 border rounded transition-colors ${+ isPublished+ ? 'border-port-success/30 bg-port-success/5 opacity-60'+ : activeDraftId === draft.id+ ? 'border-port-accent bg-port-accent/10'+ : 'border-port-border hover:border-port-border/80'+ }`}+ >+ <div className="flex items-start justify-between">+ <div className="flex-1 min-w-0 cursor-pointer" onClick={() => !isPublished && handleLoadDraft(draft)}>+ <div className="flex items-center gap-2">+ <span className={`text-xs px-1.5 py-0.5 rounded ${isPublished ? 'bg-port-success/20 text-port-success' : 'bg-port-accent/20 text-port-accent'}`}>+ {isPublished ? 'published' : draft.type}+ </span>+ {draft.submolt && (+ <span className="text-xs text-gray-500">/{draft.submolt}</span>+ )}+ </div>+ <p className="text-sm text-white mt-1 truncate">+ {draft.title || draft.content?.substring(0, 80)}+ </p>+ {draft.postTitle && (+ <p className="text-xs text-gray-500 mt-0.5">+ re: {draft.postTitle}+ </p>)}- </div>- <p className="text-sm text-white mt-1 truncate">- {draft.title || draft.content?.substring(0, 80)}- </p>- {draft.postTitle && (- <p className="text-xs text-gray-500 mt-0.5">- re: {draft.postTitle}+ <p className="text-[10px] text-gray-600 mt-1">+ {isPublished ? `Published ${new Date(draft.publishedAt || draft.updatedAt).toLocaleString()}` : new Date(draft.createdAt).toLocaleString()}</p>- )}- <p className="text-[10px] text-gray-600 mt-1">- {new Date(draft.createdAt).toLocaleString()}- </p>+ </div>+ <button+ onClick={() => handleDeleteDraft(draft.id)}+ className="text-gray-600 hover:text-port-error ml-2 shrink-0 text-sm"+ title="Delete draft"+ >+ x+ </button></div>- <button- onClick={() => handleDeleteDraft(draft.id)}- className="text-gray-600 hover:text-port-error ml-2 shrink-0 text-sm"- title="Delete draft"- >- x- </button></div>- </div>- ))}+ );+ })}</div></div>)}diff --git a/server/integrations/moltbook/api.js b/server/integrations/moltbook/api.jsindex 1e1584ed45..a2fa9da46c 100644--- a/server/integrations/moltbook/api.js+++ b/server/integrations/moltbook/api.js@@ -55,7 +55,7 @@ async function handleVerification(data, apiKey, aiConfig) {/*** Make an API request to Moltbook*/-async function request(endpoint, options = {}) {+async function request(endpoint, options = {}, aiConfig) {const url = `${API_BASE}${endpoint}`;const config = {headers: {@@ -91,7 +91,7 @@ async function request(endpoint, options = {}) {// Auto-solve verification challenges embedded in responsesconst apiKey = config.headers?.['Authorization']?.replace('Bearer ', '');- if (apiKey) await handleVerification(data, apiKey);+ if (apiKey) await handleVerification(data, apiKey, aiConfig);return data;}@@ -99,14 +99,14 @@ async function request(endpoint, options = {}) {/*** Make an authenticated API request*/-async function authRequest(apiKey, endpoint, options = {}) {+async function authRequest(apiKey, endpoint, options = {}, aiConfig) {return request(endpoint, {...options,headers: {...options.headers,'Authorization': `Bearer ${apiKey}`}- });+ }, aiConfig);}// =============================================================================@@ -172,7 +172,7 @@ export async function updateProfile(apiKey, updates) {* @param {string} content - Post content (markdown)* @returns {Object} Created post*/-export async function createPost(apiKey, submolt, title, content) {+export async function createPost(apiKey, submolt, title, content, aiConfig) {// Check rate limitconst rateCheck = checkRateLimit(apiKey, 'post');if (!rateCheck.allowed) {@@ -182,7 +182,7 @@ export async function createPost(apiKey, submolt, title, content) {const result = await authRequest(apiKey, '/posts', {method: 'POST',body: JSON.stringify({ submolt, title, content })- });+ }, aiConfig);recordAction(apiKey, 'post');const postId = result?.id || result?._id || result?.post_id;@@ -238,7 +238,7 @@ export async function getPost(apiKey, postId) {* @param {string} postId - The post ID* @param {string} content - Comment content (markdown)*/-export async function createComment(apiKey, postId, content) {+export async function createComment(apiKey, postId, content, aiConfig) {// Check rate limitconst rateCheck = checkRateLimit(apiKey, 'comment');if (!rateCheck.allowed) {@@ -248,7 +248,7 @@ export async function createComment(apiKey, postId, content) {const result = await authRequest(apiKey, `/posts/${postId}/comments`, {method: 'POST',body: JSON.stringify({ content })- });+ }, aiConfig);recordAction(apiKey, 'comment');console.log(`💬 Moltbook: Commented on post ${postId}`);@@ -262,7 +262,7 @@ export async function createComment(apiKey, postId, content) {* @param {string} parentId - The parent comment ID* @param {string} content - Reply content (markdown)*/-export async function replyToComment(apiKey, postId, parentId, content) {+export async function replyToComment(apiKey, postId, parentId, content, aiConfig) {// Check rate limitconst rateCheck = checkRateLimit(apiKey, 'comment');if (!rateCheck.allowed) {@@ -272,7 +272,7 @@ export async function replyToComment(apiKey, postId, parentId, content) {const result = await authRequest(apiKey, `/posts/${postId}/comments`, {method: 'POST',body: JSON.stringify({ content, parentId })- });+ }, aiConfig);recordAction(apiKey, 'comment');console.log(`↩️ Moltbook: Replied to comment ${parentId}`);diff --git a/server/integrations/moltbook/challengeSolver.js b/server/integrations/moltbook/challengeSolver.jsindex 5fec6ac9af..be4130c9ba 100644--- a/server/integrations/moltbook/challengeSolver.js+++ b/server/integrations/moltbook/challengeSolver.js@@ -20,8 +20,8 @@ import { getActiveProvider, getProviderById } from '../../services/providers.js'* Removes: brackets, carets, braces, then collapses consecutive case-insensitive duplicate letters*/export function cleanChallengeText(text) {- // Strip bracket/symbol noise- let cleaned = text.replace(/[[\]{}^]/g, '');+ // Strip all injected noise — keep only letters, digits, spaces, commas, question marks, hyphens+ let cleaned = text.replace(/[^a-zA-Z0-9\s,?'-]/g, '');// Collapse consecutive case-insensitive duplicate letters// e.g., "LoOoBbSsTtEeR" -> "LoBSTER" (lobster)diff --git a/server/integrations/moltbook/index.js b/server/integrations/moltbook/index.jsindex 35f9fcd60c..5be0c9d423 100644--- a/server/integrations/moltbook/index.js+++ b/server/integrations/moltbook/index.js@@ -29,6 +29,7 @@ import { getRateLimitStatus } from './rateLimits.js';export class MoltbookClient {constructor(apiKey) {this.apiKey = apiKey;+ this.aiConfig = null;}// Account@@ -37,15 +38,15 @@ export class MoltbookClient {updateProfile(updates) { return api.updateProfile(this.apiKey, updates); }// Posts- createPost(submolt, title, content) { return api.createPost(this.apiKey, submolt, title, content); }+ createPost(submolt, title, content) { return api.createPost(this.apiKey, submolt, title, content, this.aiConfig); }getFeed(sort, limit) { return api.getFeed(this.apiKey, sort, limit); }getPost(postId) { return api.getPost(this.apiKey, postId); }getPostsByAuthor(username) { return api.getPostsByAuthor(this.apiKey, username); }deletePost(postId) { return api.deletePost(this.apiKey, postId); }// Comments- createComment(postId, content) { return api.createComment(this.apiKey, postId, content); }- replyToComment(postId, parentId, content) { return api.replyToComment(this.apiKey, postId, parentId, content); }+ createComment(postId, content) { return api.createComment(this.apiKey, postId, content, this.aiConfig); }+ replyToComment(postId, parentId, content) { return api.replyToComment(this.apiKey, postId, parentId, content, this.aiConfig); }getComments(postId) { return api.getComments(this.apiKey, postId); }// Votingdiff --git a/server/lib/validation.js b/server/lib/validation.jsindex 1fe6134324..cfe1a111fc 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -274,7 +274,10 @@ export const createDraftSchema = z.object({export const updateDraftSchema = z.object({title: z.string().max(300).optional().nullable(),content: z.string().min(1).max(10000).optional(),- submolt: z.string().max(100).optional().nullable()+ submolt: z.string().max(100).optional().nullable(),+ status: z.enum(['draft', 'published']).optional(),+ publishedPostId: z.string().optional().nullable(),+ publishedAt: z.string().optional().nullable()});/**diff --git a/server/routes/agentTools.js b/server/routes/agentTools.jsindex 3b786f598c..3f3a76897a 100644--- a/server/routes/agentTools.js+++ b/server/routes/agentTools.js@@ -101,10 +101,12 @@ router.post('/publish-post', asyncHandler(async (req, res) => {console.log(`🛠️ POST /api/agents/tools/publish-post agent=${data.agentId} submolt=${data.submolt}`);- const { client, account } = await getClientAndAgent(data.accountId, data.agentId);+ const { client, agent, account } = await getClientAndAgent(data.accountId, data.agentId);+ client.aiConfig = agent.aiConfig;const result = await client.createPost(data.submolt, data.title, data.content);const post = result?.post || result;const postId = post?.id || post?._id || post?.post_id;+ const verificationFailed = result?.verification_solved === false;await platformAccounts.recordActivity(data.accountId);await agentActivity.logActivity({@@ -112,12 +114,12 @@ router.post('/publish-post', asyncHandler(async (req, res) => {accountId: data.accountId,action: 'post',params: { submolt: data.submolt, title: data.title },- status: 'completed',- result: { type: 'post', postId, submolt: data.submolt, title: data.title },+ status: verificationFailed ? 'verification_failed' : 'completed',+ result: { type: 'post', postId, submolt: data.submolt, title: data.title, verificationFailed },timestamp: new Date().toISOString()});- res.json(post);+ res.json({ ...post, verificationFailed });}));// POST /publish-comment - Publish a comment to Moltbook@@ -129,7 +131,8 @@ router.post('/publish-comment', asyncHandler(async (req, res) => {console.log(`🛠️ POST /api/agents/tools/publish-comment agent=${data.agentId} post=${data.postId}`);- const { client } = await getClientAndAgent(data.accountId, data.agentId);+ const { client, agent } = await getClientAndAgent(data.accountId, data.agentId);+ client.aiConfig = agent.aiConfig;let result;if (data.parentId) {@@ -138,18 +141,20 @@ router.post('/publish-comment', asyncHandler(async (req, res) => {result = await client.createComment(data.postId, data.content);}+ const verificationFailed = result?.verification_solved === false;+await platformAccounts.recordActivity(data.accountId);await agentActivity.logActivity({agentId: data.agentId,accountId: data.accountId,action: 'comment',params: { postId: data.postId, parentId: data.parentId },- status: 'completed',- result: { type: 'comment', commentId: result?.id || result?._id || result?.comment_id, postId: data.postId, isReply: !!data.parentId },+ status: verificationFailed ? 'verification_failed' : 'completed',+ result: { type: 'comment', commentId: result?.id || result?._id || result?.comment_id, postId: data.postId, isReply: !!data.parentId, verificationFailed },timestamp: new Date().toISOString()});- res.json(result);+ res.json({ ...result, verificationFailed });}));// POST /engage - One-click autonomous engagement cyclediff --git a/server/services/agentDrafts.js b/server/services/agentDrafts.jsindex f2d2122ac7..73d90ca7d2 100644--- a/server/services/agentDrafts.js+++ b/server/services/agentDrafts.js@@ -53,6 +53,7 @@ export async function createDraft(agentId, draft) {const entry = {id: uuidv4(),type: draft.type, // 'post' or 'comment'+ status: 'draft',title: draft.title || null,content: draft.content,submolt: draft.submolt || null,