diff --git a/scripts/review.sh b/scripts/review.sh index 43ebb64..41ca4bf 100755 --- a/scripts/review.sh +++ b/scripts/review.sh @@ -124,12 +124,16 @@ PROMPT="${PROMPT} The git diff is at /tmp/pi-diff.txt. Start by reading it, then read any files you need for full context." -# Run Pi in print mode (non-interactive, no session persistence) -# Capture stderr (tool call log) always — only show it when debug is on -pi --no-session \ +# Run Pi in print mode. +# Always save session to /tmp/pi-session so we can extract tool calls. +# Capture stderr for error diagnostics. +mkdir -p /tmp/pi-session + +pi \ ${PROVIDER_FLAG} \ --model "${PI_MODEL}" \ --tools "${PI_TOOLS}" \ + --session-dir /tmp/pi-session \ -p "${PROMPT}" \ > /tmp/pi-review.md 2>/tmp/pi-agent.log @@ -140,23 +144,59 @@ if [ ! -s /tmp/pi-review.md ]; then exit 1 fi -# If debug mode, append the agent's tool log to the review +# If debug mode, extract tool calls from session and append to review if [ "${PI_DEBUG}" = "true" ]; then - AGENT_LOG=$(sed 's/\x1b\[[0-9;]*m//g' /tmp/pi-agent.log | head -200) + SESSION_FILE=$(find /tmp/pi-session -name '*.jsonl' -type f 2>/dev/null | head -1) + 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. + TOOL_LOG=$(node -e " + const fs = require('fs'); + const lines = fs.readFileSync('${SESSION_FILE}', 'utf8').trim().split('\n'); + const entries = []; + 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); + } + } + } + } + } catch {} + } + console.log(entries.join('\n')); + " 2>/dev/null || echo "Could not parse session file") + fi + + if [ -z "${TOOL_LOG}" ]; then + TOOL_LOG="(no tool calls found — agent may have answered from the diff alone)" + fi + cat >> /tmp/pi-review.md << LOGEOF ---
-🔍 Agent Tool Log (debug) +🔍 Agent Tool Calls (${PI_MODEL}) \`\`\` -${AGENT_LOG} +${TOOL_LOG} \`\`\`
LOGEOF - echo "Debug: agent log appended to review" + echo "Debug: tool log appended to review" fi echo "Review generated successfully."