Skip to content

Commit 3b38f98

Browse files
Lexus2016claude
andcommitted
feat: persist thinking blocks to SQLite during live streaming
Accumulate thinking chunks in fullThinking buffer (runCliSingle + runSshSingle). On session completion, save thinking BEFORE text so thinking id < text id — displays before response via ORDER BY id ASC. Previously, thinking blocks were only sent over WebSocket and lost on tab switch. Now switching back to a background tab that finished generating shows the Chain of thought badge correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7b0074f commit 3b38f98

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "claude-code-studio",
3-
"version": "5.44.1",
3+
"version": "5.44.2",
44
"description": "Full-featured web workspace for Claude Code — chat, Kanban, multi-agent, MCP, skills, projects",
55
"bin": {
66
"claude-code-studio": "./bin/cli.js"

server.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ async function runCliSingle(p) {
21592159
? ['View','GlobTool','GrepTool','ListDir','ReadNotebook', ...mcpTools]
21602160
: ['Bash','View','GlobTool','GrepTool','ReadNotebook','NotebookEditCell','ListDir','SearchReplace','Write', ...mcpTools];
21612161
const effectiveMaxTurns = maxTurns || 30;
2162-
let fullText = '', newCid = claudeSessionId, chunkCount = 0;
2162+
let fullText = '', fullThinking = '', newCid = claudeSessionId, chunkCount = 0;
21632163
let currentPrompt = prompt;
21642164
let continueCount = 0;
21652165
// First invocation carries attachments; subsequent auto-continues do not
@@ -2183,7 +2183,7 @@ async function runCliSingle(p) {
21832183
try { stmts.setPartialText.run(fullText, sessionId); } catch {}
21842184
}
21852185
})
2186-
.onThinking(t => { ws.send(JSON.stringify({ type:'thinking', text:t, ...(tabId ? { tabId } : {}) })); })
2186+
.onThinking(t => { fullThinking += t; ws.send(JSON.stringify({ type:'thinking', text:t, ...(tabId ? { tabId } : {}) })); })
21872187
.onTool((name, inp) => {
21882188
if (name === 'ask_user' || name === 'notify_user' || name === 'set_ui_state') {
21892189
try { stmts.addMsg.run(sessionId,'assistant','tool',(inp||'').substring(0,500),name,null,null,null); } catch {}
@@ -2287,6 +2287,7 @@ async function runCliSingle(p) {
22872287
}
22882288

22892289
// Persist final text and clean up
2290+
try { if (fullThinking) stmts.addMsg.run(sessionId, 'assistant', 'thinking', fullThinking, null, null, null, null); } catch {}
22902291
try { if (fullText) stmts.addMsg.run(sessionId, 'assistant', 'text', fullText, null, null, null, null); } catch {}
22912292
try { stmts.setPartialText.run(null, sessionId); } catch {}
22922293
return { cid: newCid, completed: lastResult?.subtype === 'success' };
@@ -2303,7 +2304,7 @@ async function runSshSingle(p) {
23032304
? ['View','GlobTool','GrepTool','ListDir','ReadNotebook', ...mcpTools]
23042305
: ['Bash','View','GlobTool','GrepTool','ListDir','SearchReplace','Write', ...mcpTools];
23052306
const effectiveMaxTurns = maxTurns || 30;
2306-
let fullText = '', newCid = claudeSessionId, chunkCount = 0;
2307+
let fullText = '', fullThinking = '', newCid = claudeSessionId, chunkCount = 0;
23072308
let currentPrompt = prompt;
23082309
let continueCount = 0;
23092310
let currentContentBlocks = Array.isArray(userContent) ? userContent : null;
@@ -2325,7 +2326,7 @@ async function runSshSingle(p) {
23252326
try { stmts.setPartialText.run(fullText, sessionId); } catch {}
23262327
}
23272328
})
2328-
.onThinking(t => { ws.send(JSON.stringify({ type:'thinking', text:t, ...(tabId ? { tabId } : {}) })); })
2329+
.onThinking(t => { fullThinking += t; ws.send(JSON.stringify({ type:'thinking', text:t, ...(tabId ? { tabId } : {}) })); })
23292330
.onTool((name, inp) => {
23302331
if (name === 'ask_user' || name === 'notify_user' || name === 'set_ui_state') {
23312332
try { stmts.addMsg.run(sessionId,'assistant','tool',(inp||'').substring(0,500),name,null,null,null); } catch {}
@@ -2398,6 +2399,7 @@ async function runSshSingle(p) {
23982399
currentContentBlocks = null;
23992400
}
24002401

2402+
try { if (fullThinking) stmts.addMsg.run(sessionId, 'assistant', 'thinking', fullThinking, null, null, null, null); } catch {}
24012403
try { if (fullText) stmts.addMsg.run(sessionId, 'assistant', 'text', fullText, null, null, null, null); } catch {}
24022404
try { stmts.setPartialText.run(null, sessionId); } catch {}
24032405
return { cid: newCid, completed: lastResult?.subtype === 'success' };

0 commit comments

Comments
 (0)