2 Commits
v9 ... v11

Author SHA1 Message Date
Markus Hofstetter 5cd267296e 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.
2026-06-13 14:47:06 +02:00
Markus Hofstetter 32829ae8ba feat: add debug logging for session directory and file in review script
Includes additional diagnostic outputs for PI_DEBUG mode: contents of the session directory and the selected session file.
2026-06-13 11:42:04 +02:00
+15 -10
View File
@@ -255,14 +255,21 @@ if [ ! -s /tmp/pi-review.md ]; then
exit 1
fi
echo "Debug mode: PI_DEBUG=${PI_DEBUG}"
# If debug mode, extract tool calls from session and append to review
if [ "${PI_DEBUG}" = "true" ]; then
echo "Session dir contents:"
find /tmp/pi-session -type f 2>/dev/null || echo " (none)"
SESSION_FILE=$(find /tmp/pi-session -name '*.jsonl' -type f 2>/dev/null | head -1)
echo "Session file: ${SESSION_FILE:-<none found>}"
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');
@@ -270,20 +277,18 @@ if [ "${PI_DEBUG}" = "true" ]; then
for (const line of lines) {
try {
const entry = JSON.parse(line);
if (entry.type === 'message') {
if (entry.type !== 'message') continue;
const msg = entry.message;
// Model requesting tool use
if (msg.role === 'assistant' && msg.content) {
if (!msg || !msg.content) continue;
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(' ');
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 {}
}
console.log(entries.join('\n'));