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: address round 5 review — input guards, responseMs clamping, strict validation
Adam Eivy508862c7fdb0
diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex 00c5540e49..ffc40c6cdd 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -29,6 +29,10 @@ export function usePostSession() {const startSession = useCallback(async (drillConfigs) => {// drillConfigs: [{ type, config, timeLimitSec }]+ if (!drillConfigs?.length) {+ toast.error('No drills configured');+ return;+ }setState(STATES.LOADING);setDrills(drillConfigs);setCurrentDrillIndex(0);@@ -142,13 +146,14 @@ export function usePostSession() {setState(STATES.IDLE);return null;});- if (!drill) return;+ if (!drill) return false;setCurrentDrill({ ...drill, timeLimitSec: next.timeLimitSec });setCurrentQuestionIndex(0);setAnswers([]);questionStartRef.current = Date.now();drillStartRef.current = Date.now();setState(STATES.DRILLING);+ return true;}, [currentDrillIndex, drills]);const timeExpired = useCallback(() => {diff --git a/server/lib/postValidation.js b/server/lib/postValidation.jsindex 76647c0379..1cebbd35d9 100644--- a/server/lib/postValidation.js+++ b/server/lib/postValidation.js@@ -17,25 +17,6 @@ const questionResultSchema = z.object({responseMs: z.number().min(0)});-// Task result within a session-// score is optional — the server recomputes it via scoreDrill-const taskResultSchema = z.object({- module: z.string(),- type: z.string(),- config: z.record(z.unknown()).optional().default({}),- questions: z.array(questionResultSchema),- score: z.number().min(0).max(100).optional(),- totalMs: z.number().min(0)-});--// Full session submission-export const postSessionSubmitSchema = z.object({- cadence: z.enum(['daily', 'weekly', 'monthly']).optional().default('daily'),- modules: z.array(z.string()).min(1),- tasks: z.array(taskResultSchema).min(1),- tags: postTagsSchema.optional().default({})-});-// Drill type configurationconst DRILL_TYPES = ['doubling-chain', 'serial-subtraction', 'multiplication', 'powers', 'estimation'];@@ -53,6 +34,25 @@ const drillTypeConfigSchema = z.object({tolerancePct: z.number().min(1).max(50).optional()});+// Task result within a session+// score is optional — the server recomputes it via scoreDrill+const taskResultSchema = z.object({+ module: z.string(),+ type: z.enum(DRILL_TYPES),+ config: drillTypeConfigSchema.optional().default({}),+ questions: z.array(questionResultSchema),+ score: z.number().min(0).max(100).optional(),+ totalMs: z.number().min(0)+});++// Full session submission+export const postSessionSubmitSchema = z.object({+ cadence: z.enum(['daily', 'weekly', 'monthly']).optional().default('daily'),+ modules: z.array(z.string()).min(1),+ tasks: z.array(taskResultSchema).min(1),+ tags: postTagsSchema.optional().default({})+});+// Config update (partial)export const postConfigUpdateSchema = z.object({mentalMath: z.object({diff --git a/server/routes/meatspace.js b/server/routes/meatspace.jsindex ca9ce7a45b..e60b03927c 100644--- a/server/routes/meatspace.js+++ b/server/routes/meatspace.js@@ -327,7 +327,7 @@ router.get('/post/stats', asyncHandler(async (req, res) => {/*** POST /api/meatspace/post/drill* Generate a drill with questions and expected answers for client-side feedback.- * Server-side scoring recomputes expected from the prompt, so client values are not trusted.+ * Server-side scoring recomputes expected answers from the prompt when possible.*/router.post('/post/drill', asyncHandler(async (req, res) => {const data = validateRequest(postDrillRequestSchema, req.body);diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.jsindex aa83b7a21e..22641347fd 100644--- a/server/services/meatspacePost.js+++ b/server/services/meatspacePost.js@@ -287,7 +287,8 @@ export function scoreDrill(type, questions, timeLimitMs, config = {}) {const correctCount = recomputed.filter(q => q.correct).length;const correctRatio = correctCount / recomputed.length;- const totalResponseMs = answered.reduce((sum, q) => sum + (q.responseMs || 0), 0);+ // Clamp responseMs to [0, timeLimitMs] to prevent inflated speed bonuses+ const totalResponseMs = answered.reduce((sum, q) => sum + Math.min(Math.max(q.responseMs || 0, 0), timeLimitMs), 0);const avgResponseMs = answered.length > 0 ? totalResponseMs / answered.length : timeLimitMs;const speedBonus = Math.max(0, 1 - avgResponseMs / timeLimitMs);