diff --git a/components/reasoning-workspace.jsx b/components/reasoning-workspace.jsx index 43d14cb..88f1bf5 100644 --- a/components/reasoning-workspace.jsx +++ b/components/reasoning-workspace.jsx @@ -103,18 +103,14 @@ function SituationCard({ centralStatement }) { function CurrentUnderstanding({ currentSummary }) { const summary = resolveCurrentSummary(currentSummary); + if (!summary) return null; + return (

What we've established

- {summary ? ( -

{summary}

- ) : ( -

- We have separated what is known from what still needs checking. -

- )} +

{summary}

); } @@ -199,21 +195,30 @@ function CurrentFocusCard({ graph }) { // ── Investigation history card ──────────────────────────────── function InvestigationHistoryCard({ turn }) { + const qSnippet = turn.question.length > 80 + ? turn.question.slice(0, 80) + "…" + : turn.question; + return ( -
+
{new Date(turn.timestamp).toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", - })} + })} — {qSnippet}
-

{turn.question}

+

Question

+

{turn.question}

+

You answered

{turn.answer}

{turn.acknowledgement && ( -

{turn.acknowledgement}

+ <> +

What changed

+

{turn.acknowledgement}

+ )}
@@ -230,8 +235,8 @@ function InvestigationHistory({ turns }) { Investigation history
- {turns.map((turn, idx) => ( - + {turns.map((turn) => ( + ))}
@@ -384,33 +389,42 @@ export default function ReasoningWorkspace({ lastSubmittedAnswer, }) { const [investigationHistory, setInvestigationHistory] = useState([]); + const turnCounter = useRef(0); + const pendingTurnRef = useRef(null); - // Capture the previous question before each new question is set - const prevQuestionRef = useRef(null); - const hasCapturedInitialQuestion = useRef(false); + // Capture the current selected question at submit time (not from a stale ref) + const capturePendingTurn = (selectedQuestion, answerText) => { + if (!selectedQuestion || !answerText?.trim()) return null; + const q = typeof selectedQuestion === "string" ? selectedQuestion : selectedQuestion.question; + if (!q) return null; + turnCounter.current += 1; + return { + id: `turn-${turnCounter.current}`, + question: q, + answer: answerText.trim(), + acknowledgement: null, + timestamp: Date.now(), + }; + }; + // Append the captured pending turn to history after a successful update only useEffect(() => { - if (result?.selectedQuestion && !hasCapturedInitialQuestion.current) { - prevQuestionRef.current = result.selectedQuestion; - hasCapturedInitialQuestion.current = true; - } - }, [result?.selectedQuestion]); + const pending = pendingTurnRef.current; + if (!pending || updateStatus !== "success") return; - // Append completed turn to history after a successful update - useEffect(() => { - if (updateStatus === "success" && lastSubmittedAnswer) { - const q = prevQuestionRef.current; - setInvestigationHistory((prev) => [ - ...prev, - { - question: typeof q === "string" ? q : q?.question ?? "", - answer: lastSubmittedAnswer, - acknowledgement: result?.summary || null, - timestamp: Date.now(), - }, - ]); - } - }, [updateStatus, lastSubmittedAnswer, result]); + setInvestigationHistory((prev) => [ + ...prev, + { ...pending, acknowledgement: result?.summary || null }, + ]); + pendingTurnRef.current = null; + }, [updateStatus, result]); + + const handleUpdateCaptureAndSubmit = async (e) => { + e.preventDefault(); + if (!answer?.trim() || !result?.selectedQuestion) return; + pendingTurnRef.current = capturePendingTurn(result.selectedQuestion, answer); + await onAnswerSubmit(e); + }; const { elapsed: startElapsed, currentMessage: startMsg } = useLoadingStatus( INITIAL_MESSAGES, @@ -494,7 +508,7 @@ export default function ReasoningWorkspace({ {/* ── Answer form ──────────────────────────────── */} {canAnswer && ( -
+