From 5cd267296ed68de05510b0e5de2bc2d2388d01f0 Mon Sep 17 00:00:00 2001 From: Markus Hofstetter Date: Sat, 13 Jun 2026 14:47:06 +0200 Subject: [PATCH] fix: update tool-call extraction logic for Pi session JSONL Refine parsing of assistant tool calls in review.sh to handle "toolCall" and "arguments" structures, aligning with Pi session format changes. --- scripts/review.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/review.sh b/scripts/review.sh index 5f9530b..ffec710 100755 --- a/scripts/review.sh +++ b/scripts/review.sh @@ -266,8 +266,10 @@ if [ "${PI_DEBUG}" = "true" ]; then TOOL_LOG="" if [ -n "${SESSION_FILE}" ]; then - # Extract tool-use entries: each line is a JSON object. - # Tool calls appear as messages with tool_use/function_call content. + # Extract tool-call entries from Pi session JSONL. + # Pi stores assistant messages with content blocks of type "toolCall" + # (NOT the Anthropic SDK's "tool_use"), using "arguments" (NOT "input"). + # Tool results are separate entries with role "toolResult". TOOL_LOG=$(node -e " const fs = require('fs'); const lines = fs.readFileSync('${SESSION_FILE}', 'utf8').trim().split('\n'); @@ -275,18 +277,16 @@ if [ "${PI_DEBUG}" = "true" ]; then for (const line of lines) { try { const entry = JSON.parse(line); - if (entry.type === 'message') { - const msg = entry.message; - // Model requesting tool use - if (msg.role === 'assistant' && msg.content) { - const parts = Array.isArray(msg.content) ? msg.content : [msg.content]; - for (const part of parts) { - if (typeof part === 'object' && part.type === 'tool_use') { - const input = part.input || {}; - const args = Object.entries(input).map(([k,v]) => k + '=' + JSON.stringify(v)).join(' '); - entries.push('[tool:' + part.name + '] ' + args); - } - } + if (entry.type !== 'message') continue; + const msg = entry.message; + if (!msg || !msg.content) continue; + const parts = Array.isArray(msg.content) ? msg.content : [msg.content]; + for (const part of parts) { + if (typeof part !== 'object') continue; + if (part.type === 'toolCall') { + const args = Object.entries(part.arguments || {}) + .map(([k,v]) => k + '=' + JSON.stringify(v)).join(' '); + entries.push('[tool:' + part.name + '] ' + args); } } } catch {}