mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
fix(growth): robust json:candidate extraction (#3211)
The sed + tr approach grabbed invalid JSON when Claude's output had multiple candidate-like blocks or mixed analysis text. Switch to bun script that tries to JSON.parse each match, keeping the last valid one. Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Ahmed Abushagur <ahmed@abushagur.com>
This commit is contained in:
parent
714c29c5a6
commit
1e858503cb
1 changed files with 10 additions and 2 deletions
|
|
@ -162,9 +162,17 @@ fi
|
|||
# --- Phase 3: Extract candidate and POST to SPA ---
|
||||
CANDIDATE_JSON=""
|
||||
|
||||
# Extract the json:candidate block from Claude's output (may be multi-line)
|
||||
# Extract the last valid json:candidate block from Claude's output
|
||||
if [[ -f "${CLAUDE_OUTPUT_FILE}" ]]; then
|
||||
CANDIDATE_JSON=$(sed -n '/^```json:candidate$/,/^```$/{/^```/d;p;}' "${CLAUDE_OUTPUT_FILE}" | tr -d '\n')
|
||||
CANDIDATE_JSON=$(bun -e "
|
||||
const text = await Bun.file('${CLAUDE_OUTPUT_FILE}').text();
|
||||
const blocks = [...text.matchAll(/\`\`\`json:candidate\n([\s\S]*?)\n\`\`\`/g)];
|
||||
let result = '';
|
||||
for (const block of blocks) {
|
||||
try { result = JSON.stringify(JSON.parse(block[1].trim())); } catch {}
|
||||
}
|
||||
if (result) console.log(result);
|
||||
" 2>/dev/null)
|
||||
fi
|
||||
|
||||
if [[ -z "${CANDIDATE_JSON}" ]]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue