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
refactor: start a POST session with one named options object (#9183)
[._.]/ Adam Eivy60f34b3eee30
diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsxindex 06bc990da9..56e5236ced 100644--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx@@ -429,7 +429,7 @@ export default function PostSessionLauncher({// for better retention (issue #2100). Full coverage is preserved — every// enabled drill still runs, just reordered.const drillConfigs = interleaveByDomain([...mathConfigs, ...llmConfigs, ...cognitiveConfigs, ...memoryConfigs]);- onStart(drillConfigs, buildCleanConditions(conditions), mode === 'train');+ onStart({ drills: drillConfigs, conditions: buildCleanConditions(conditions), training: mode === 'train' });}// Build domain → enabled drills map for quick session@@ -513,13 +513,18 @@ export default function PostSessionLauncher({return drillConfig;});if (!drillConfigs.length) return;- onStart(drillConfigs, buildCleanConditions(conditions), mode === 'train', {+ onStart({+ drills: drillConfigs,+ conditions: buildCleanConditions(conditions),+ training: mode === 'train',+ plan: {targetDurationSec: quickPlan.targetDurationSec,estimatedDurationSec: quickPlan.estimatedDurationSec,toleranceSec: quickPlan.toleranceSec,omittedDomains: quickPlan.omittedDomains,omittedReviews: quickPlan.omittedReviews,selectedTypes: quickPlan.selected.map(candidate => candidate.type),+ },});}@@ -536,11 +541,15 @@ export default function PostSessionLauncher({config: { ...task.config },timeLimitSec: task.timeLimitSec,}));- onStart(drillConfigs, buildCleanConditions(conditions), false, null, {+ onStart({+ drills: drillConfigs,+ conditions: buildCleanConditions(conditions),+ benchmark: {protocolId: protocol.protocolId,protocolVersion: protocol.protocolVersion,scorerVersion: protocol.scorerVersion,formId: form.formId,+ },});}).catch(error => setBenchmarkError(error.message || 'Benchmark could not be loaded'))@@ -592,7 +601,7 @@ export default function PostSessionLauncher({function handleFocusDomain(domainKey) {const drills = enabledDomains[domainKey];if (!drills || drills.length === 0) return;- onStart(drills.map(d => buildFocusDrillConfig(d, domainKey)), buildCleanConditions(conditions), mode === 'train');+ onStart({ drills: drills.map(d => buildFocusDrillConfig(d, domainKey)), conditions: buildCleanConditions(conditions), training: mode === 'train' });}// Start a session with exactly ONE recommended drill (issue #2100): an Up next@@ -601,7 +610,7 @@ export default function PostSessionLauncher({function startDrillByType(type) {const entry = allEnabledDrills.find(d => d.type === type);if (!entry) return;- onStart([buildFocusDrillConfig(entry)], buildCleanConditions(conditions), mode === 'train');+ onStart({ drills: [buildFocusDrillConfig(entry)], conditions: buildCleanConditions(conditions), training: mode === 'train' });}// Launch a single due maintenance-review rep from an "Up next" skill-review@@ -628,7 +637,7 @@ export default function PostSessionLauncher({reviewLabel: rep.label,...(rep.providerId && { providerId: rep.providerId }),};- onStart([drillConfig], buildCleanConditions(conditions), mode === 'train');+ onStart({ drills: [drillConfig], conditions: buildCleanConditions(conditions), training: mode === 'train' });}const hasAnyDrills = enabledMathDrills.length > 0 || enabledLlmDrills.length > 0 || enabledCognitiveDrills.length > 0 || enabledMemoryDrills.length > 0;diff --git a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx b/client/src/components/meatspace/post/PostSessionLauncher.test.jsxindex dfe86895c9..f29a3f516f 100644--- a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx+++ b/client/src/components/meatspace/post/PostSessionLauncher.test.jsx@@ -194,12 +194,12 @@ describe('PostSessionLauncher render (issue #2100)', () => {await waitFor(() => expect(onStart).toHaveBeenCalledTimes(1));expect(getPostBenchmarkProtocol).toHaveBeenCalledWith({ silent: true });- expect(onStart.mock.calls[0][0]).toEqual([+ expect(onStart.mock.calls[0][0].drills).toEqual([expect.objectContaining({ type: 'doubling-chain', config: { startValue: 5, steps: 8 } }),expect.objectContaining({ type: 'task-switching', config: { seed: 'post-foundation-a', count: 12 } }),]);- expect(onStart.mock.calls[0][2]).toBe(false);- expect(onStart.mock.calls[0][4]).toEqual({+ expect(onStart.mock.calls[0][0]).not.toHaveProperty('training');+ expect(onStart.mock.calls[0][0].benchmark).toEqual({protocolId: 'post-foundation-battery',protocolVersion: 1,scorerVersion: 'post-deterministic-v1',@@ -242,7 +242,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {fireEvent.click(screen.getByRole('button', { name: /Quick 10 Min/ }));expect(onStart).toHaveBeenCalledTimes(1);- expect(onStart.mock.calls[0][3]).toMatchObject({+ expect(onStart.mock.calls[0][0].plan).toMatchObject({targetDurationSec: 600,toleranceSec: 30,selectedTypes: expect.arrayContaining(['multiplication', 'n-back']),@@ -270,7 +270,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {expect(row).toBeTruthy();fireEvent.click(row);expect(onStart).toHaveBeenCalledTimes(1);- const drills = onStart.mock.calls[0][0];+ const drills = onStart.mock.calls[0][0].drills;// Only the recommended drill runs — powers/estimation are NOT queued.expect(drills.map(d => d.type)).toEqual(['multiplication']);});@@ -290,7 +290,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {});await waitFor(() => expect(onStart).toHaveBeenCalledTimes(1));- expect(onStart.mock.calls[0][0].map(d => d.type)).toEqual(['multiplication']);+ expect(onStart.mock.calls[0][0].drills.map(d => d.type)).toEqual(['multiplication']);expect(onAutoStartConsumed).toHaveBeenCalledTimes(1);});@@ -324,7 +324,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {await waitFor(() => expect(screen.getByText('Re-verify Multiplication 1×2')).toBeTruthy());fireEvent.click(screen.getByText('Re-verify Multiplication 1×2').closest('button'));expect(onStart).toHaveBeenCalledTimes(1);- const drills = onStart.mock.calls[0][0];+ const drills = onStart.mock.calls[0][0].drills;expect(drills).toHaveLength(1);expect(drills[0].isReview).toBe(true);expect(drills[0].config.reviewSkillId).toBe('multiplication:L1');@@ -342,7 +342,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {await waitFor(() => expect(screen.getByText('Re-verify n-back L0')).toBeTruthy());fireEvent.click(screen.getByText('Re-verify n-back L0').closest('button'));await waitFor(() => expect(onStart).toHaveBeenCalledTimes(1));- expect(onStart.mock.calls[0][0][0].config.reviewSkillId).toBe('cognitive:n-back:L0');+ expect(onStart.mock.calls[0][0].drills[0].config.reviewSkillId).toBe('cognitive:n-back:L0');});it('does not start any session when a skill-review rep cannot be found', async () => {@@ -404,7 +404,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {await waitFor(() => expect(getPostRecommendations).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));expect(onStart).toHaveBeenCalledTimes(1);- const drills = onStart.mock.calls[0][0];+ const drills = onStart.mock.calls[0][0].drills;expect(drills.some(d => d.type === 'wit-comeback')).toBe(false);expect(drills.some(d => d.type === 'multiplication')).toBe(true);});@@ -545,7 +545,7 @@ describe('PostSessionLauncher — Start card (issue #3249)', () => {fireEvent.click(screen.getByText('Start: Shore up Powers'));expect(onStart).toHaveBeenCalledTimes(1);// The EXACT recommended drill, not its whole domain.- const drills = onStart.mock.calls[0][0];+ const drills = onStart.mock.calls[0][0].drills;expect(drills).toHaveLength(1);expect(drills[0].type).toBe('powers');});@@ -567,7 +567,7 @@ describe('PostSessionLauncher — Start card (issue #3249)', () => {await waitFor(() => expect(screen.getByText('Start: Full POST')).toBeTruthy());fireEvent.click(screen.getByText('Start: Full POST'));expect(onStart).toHaveBeenCalledTimes(1);- expect(onStart.mock.calls[0][0].length).toBeGreaterThan(1);+ expect(onStart.mock.calls[0][0].drills.length).toBeGreaterThan(1);});it('collapses Conditions by default and keeps a set value when re-collapsed', async () => {@@ -638,7 +638,7 @@ describe('PostSessionLauncher topic gating (issue #3252)', () => {await waitFor(() => expect(screen.getByText('Full POST')).toBeTruthy());fireEvent.click(screen.getByText('Full POST'));- const types = onStart.mock.calls[0][0].map(d => d.type).sort();+ const types = onStart.mock.calls[0][0].drills.map(d => d.type).sort();expect(types).toEqual(['bridge-word', 'pun-wordplay', 'what-if', 'wit-comeback']);});@@ -648,7 +648,7 @@ describe('PostSessionLauncher topic gating (issue #3252)', () => {await waitFor(() => expect(screen.getByText('Full POST')).toBeTruthy());fireEvent.click(screen.getByText('Full POST'));- const types = onStart.mock.calls[0][0].map(d => d.type).sort();+ const types = onStart.mock.calls[0][0].drills.map(d => d.type).sort();expect(types).toEqual(['bridge-word', 'pun-wordplay']);});@@ -669,7 +669,7 @@ describe('PostSessionLauncher topic gating (issue #3252)', () => {await waitFor(() => expect(getPostRecommendations).toHaveBeenCalled());fireEvent.click(await screen.findByRole("button", { name: /Quick 5 Min/ }));- const mathDrills = onStart.mock.calls[0][0].filter(drill => drill.domain === "math");+ const mathDrills = onStart.mock.calls[0][0].drills.filter(drill => drill.domain === "math");expect(mathDrills.map(drill => drill.type)).toEqual(["powers"]);});@@ -687,12 +687,12 @@ describe('PostSessionLauncher topic gating (issue #3252)', () => {const quick = await screen.findByRole('button', { name: /Quick 5 Min/ });fireEvent.click(quick);- for (const drill of onStart.mock.calls[0][0]) {+ for (const drill of onStart.mock.calls[0][0].drills) {expect(['pun-wordplay', 'bridge-word', 'multiplication']).toContain(drill.type);}// Quick picks one drill per domain — math and wordplay only, never the two// switched-off llm topics.- expect(onStart.mock.calls[0][0].map(d => d.domain).sort()).toEqual(['math', 'wordplay']);+ expect(onStart.mock.calls[0][0].drills.map(d => d.domain).sort()).toEqual(['math', 'wordplay']);});});@@ -737,7 +737,7 @@ describe('PostSessionLauncher review-rep topic gating (issue #3252)', () => {await waitFor(() => expect(screen.getByText(/due for a maintenance rep/)).toBeTruthy());fireEvent.click(await screen.findByRole('button', { name: /Quick 5 Min/ }));- expect(onStart.mock.calls[0][0].some(d => d.isReview && d.type === 'n-back')).toBe(true);+ expect(onStart.mock.calls[0][0].drills.some(d => d.isReview && d.type === 'n-back')).toBe(true);});it('drops the review rep — and its launcher nudge — when its topic is switched off', async () => {@@ -747,8 +747,8 @@ describe('PostSessionLauncher review-rep topic gating (issue #3252)', () => {expect(screen.queryByText(/due for a maintenance rep/)).toBeNull();fireEvent.click(await screen.findByRole('button', { name: /Quick 5 Min/ }));- expect(onStart.mock.calls[0][0].some(d => d.isReview)).toBe(false);- expect(onStart.mock.calls[0][0].some(d => d.type === 'n-back')).toBe(false);+ expect(onStart.mock.calls[0][0].drills.some(d => d.isReview)).toBe(false);+ expect(onStart.mock.calls[0][0].drills.some(d => d.type === 'n-back')).toBe(false);});});@@ -786,7 +786,7 @@ describe('PostSessionLauncher honors the mentalMath module flag (issue #3252)',await waitFor(() => expect(screen.getByText('Full POST')).toBeTruthy());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0].map(d => d.type)).toEqual(['n-back']);+ expect(onStart.mock.calls[0][0].drills.map(d => d.type)).toEqual(['n-back']);});});@@ -836,7 +836,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalledWith({ silent: true }));fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0]).toEqual(expect.arrayContaining([+ expect(onStart.mock.calls[0][0].drills).toEqual(expect.arrayContaining([expect.objectContaining({type: 'memory-sequence',domain: 'memory',@@ -844,10 +844,10 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {timeLimitSec: 90,}),]));- expect(onStart.mock.calls[0][0].some(d => d.type === 'memory-element-flash')).toBe(false);+ expect(onStart.mock.calls[0][0].drills.some(d => d.type === 'memory-element-flash')).toBe(false);fireEvent.click(screen.getByRole('button', { name: /Quick 5 Min/ }));- expect(onStart.mock.calls[1][0]).toEqual(expect.arrayContaining([+ expect(onStart.mock.calls[1][0].drills).toEqual(expect.arrayContaining([expect.objectContaining({type: 'memory-sequence',domain: 'memory',@@ -863,7 +863,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0].map(d => d.type)).toEqual(['multiplication']);+ expect(onStart.mock.calls[0][0].drills.map(d => d.type)).toEqual(['multiplication']);});it('does not compose memory when every item is disabled in the Practice Plan', async () => {@@ -878,7 +878,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0].some(d => d.domain === 'memory')).toBe(false);+ expect(onStart.mock.calls[0][0].drills.some(d => d.domain === 'memory')).toBe(false);});it('omits Element Flash when the built-in elements item is unavailable', async () => {@@ -898,7 +898,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0].some(d => d.type === 'memory-element-flash')).toBe(false);+ expect(onStart.mock.calls[0][0].drills.some(d => d.type === 'memory-element-flash')).toBe(false);});it('pins Element Flash to the compatible elements item', async () => {@@ -917,7 +917,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0]).toEqual(expect.arrayContaining([+ expect(onStart.mock.calls[0][0].drills).toEqual(expect.arrayContaining([expect.objectContaining({type: 'memory-element-flash',config: { count: 6, memoryItemId: 'elements-song' },@@ -936,7 +936,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0].some(d => d.type === 'memory-sequence')).toBe(false);+ expect(onStart.mock.calls[0][0].drills.some(d => d.type === 'memory-sequence')).toBe(false);});it('pins Sequence Recall to a compatible item instead of a lower-mastery one-line item', async () => {@@ -949,7 +949,7 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());fireEvent.click(screen.getByText('Full POST'));- expect(onStart.mock.calls[0][0]).toEqual(expect.arrayContaining([+ expect(onStart.mock.calls[0][0].drills).toEqual(expect.arrayContaining([expect.objectContaining({type: 'memory-sequence',config: { count: 4, memoryItemId: 'runnable' },diff --git a/client/src/components/meatspace/tabs/PostTab.jsx b/client/src/components/meatspace/tabs/PostTab.jsxindex f81c9cecfb..0126e97961 100644--- a/client/src/components/meatspace/tabs/PostTab.jsx+++ b/client/src/components/meatspace/tabs/PostTab.jsx@@ -88,8 +88,8 @@ export default function PostTab({ tab = 'launcher', subtab, mode }) {setStatsWeek(stWeek);}- async function handleStart(drillConfigs, conditions, training = false, sessionPlan = null, benchmark = null) {- const started = await session.startSession(drillConfigs, training, conditions || {}, sessionPlan, benchmark);+ async function handleStart(options) {+ const started = await session.startSession(options);if (started) navigate('/post/session/run');}diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex 2080841c5a..fb06ca948a 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -235,16 +235,18 @@ export function usePostSession() {});}, [runId, state, drills, currentDrillIndex, currentDrill, currentQuestionIndex, answers, drillResults, sessionScore, isTraining, conditions, legacyTags, sessionPlan, benchmark]);- const startSession = useCallback(async (drillConfigs, training = false, sessionConditions = {}, plan = null, benchmarkMetadata = null) => {- // drillConfigs: [{ type, config, timeLimitSec }]+ const startSession = useCallback(async ({ drills: drillConfigs, training = false, conditions: sessionConditions = {}, plan = null, benchmark: benchmarkMetadata = null } = {}) => {+ // drills: [{ type, config, timeLimitSec }]if (!drillConfigs?.length) {toast.error('No drills configured');return;}setState(STATES.LOADING);+ // A training run never carries benchmark metadata.+ const effectiveBenchmark = training ? null : benchmarkMetadata || null;setIsTraining(training);setSessionPlan(plan || null);- setBenchmark(training ? null : benchmarkMetadata || null);+ setBenchmark(effectiveBenchmark);setDrills(drillConfigs);setCurrentDrillIndex(0);setDrillResults([]);