Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: handle multiple JSON blocks in AI response parsing#393

Merged
breaking-brake merged 1 commit intomainbreaking-brake/cc-wf-studio:mainfrom
fix/multiple-json-blocks-parsingbreaking-brake/cc-wf-studio:fix/multiple-json-blocks-parsingCopy head branch name to clipboard
Jan 6, 2026
Merged

fix: handle multiple JSON blocks in AI response parsing#393
breaking-brake merged 1 commit intomainbreaking-brake/cc-wf-studio:mainfrom
fix/multiple-json-blocks-parsingbreaking-brake/cc-wf-studio:fix/multiple-json-blocks-parsingCopy head branch name to clipboard

Conversation

@breaking-brake
Copy link
Copy Markdown
Owner

Problem

When AI returns multiple JSON code blocks in a single response (e.g., raw workflow + structured response), the workflow is not applied to the canvas. Instead, only the explanatory text is displayed.

Current Behavior

  1. User requests workflow refinement
  2. AI returns: explanation + json { workflow } + more text + json { status: "success", ... }
  3. ❌ Parser extracts invalid JSON (mixing content from different blocks)
  4. ❌ Parse fails → treated as "clarification" → workflow not applied

Expected Behavior

  1. User requests workflow refinement
  2. AI returns multiple JSON blocks
  3. ✅ Parser correctly extracts the structured response with status field
  4. ✅ Workflow is applied to canvas

Solution

Improved parseClaudeCodeOutput function in claude-code-service.ts to properly handle multiple JSON blocks.

Changes

File: src/extension/services/claude-code-service.ts

  1. Added extractAllJsonBlocks() helper function

    • Uses non-greedy regex to extract each JSON block individually
    • Returns array of JSON content strings
  2. Improved Strategy 3 parsing logic

    • Extract all JSON blocks using the new helper
    • Search from end to find block with status field (structured response format)
    • Fallback to last block if no status field found
// Before (buggy)
const jsonBlockStart = trimmed.indexOf('```json');    // First block start
const jsonBlockEnd = trimmed.lastIndexOf('```');      // Last block end (wrong!)

// After (fixed)
const jsonBlocks = extractAllJsonBlocks(trimmed);     // All blocks as array
// Find block with 'status' field, searching from end

Impact

  • ✅ Fixes AI refinement not applying workflow when multiple JSON blocks returned
  • ✅ Also improves AI generation (new workflow) parsing
  • ✅ Backward compatible: single JSON block behavior unchanged
  • ✅ No breaking changes

Testing

  • Manual E2E testing: multiple JSON blocks case
  • Manual E2E testing: single JSON block case
  • Code quality checks passed (npm run format && npm run lint && npm run check)
  • Build passed (npm run build)

🤖 Generated with Claude Code

- Add extractAllJsonBlocks helper to extract all JSON code blocks
- Prioritize blocks with 'status' field for structured responses
- Fix issue where multiple JSON blocks caused parse failure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@breaking-brake breaking-brake merged commit 29c01bf into main Jan 6, 2026
3 checks passed
@breaking-brake breaking-brake deleted the fix/multiple-json-blocks-parsing branch January 6, 2026 12:39
@breaking-brake breaking-brake mentioned this pull request Jan 6, 2026
braking-brake-semantic-release Bot pushed a commit that referenced this pull request Jan 6, 2026
## [3.12.8](v3.12.7...v3.12.8) (2026-01-06)

### Bug Fixes

* handle multiple JSON blocks in AI response parsing ([#393](#393)) ([29c01bf](29c01bf))

### Improvements

* add node name constraint to AI refinement prompts ([#394](#394)) ([055d254](055d254))
* auto-focus canvas on newly added nodes ([#392](#392)) ([7c1856c](7c1856c))
@braking-brake-semantic-release
Copy link
Copy Markdown

🎉 This PR is included in version 3.12.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.