fix(utils): strip any Markdown language tag from parseModelJson opening fence (PKT-567) - #458
Open
bugsyhewitt wants to merge 1 commit into
Open
fix(utils): strip any Markdown language tag from parseModelJson opening fence (PKT-567)#458bugsyhewitt wants to merge 1 commit into
bugsyhewitt wants to merge 1 commit into
Conversation
…ng fence, not just literal 'json' PKT-567: extends regex from /```(?:json)?\n?/g to /```(?:[a-zA-Z][a-zA-Z0-9_+\-]*)?\n?/g so that fences tagged javascript, js, typescript, python, JSON, Json, json5, etc. are stripped before JSON.parse — previously these silently fell back to onText with the language tag as garbage prefix, breaking parseSubGoals, parseSchemeDraft, and AdvisorBot.parseResponse for any LLM that emits non-json fence tags. Adds 7 new test cases (TDD red→green); all 3 control cases (bare fence, json fence, unfenced) still pass. No existing assertions modified. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parseModelJsoninsrc/alienclaw/utils.ts:62used/\``(?:json)?\n?/g— a literal whitelist that only stripped fences tagged with the stringjson(or no tag). Any other language tag (javascript,js,typescript,python,JSON,Json,json5, etc.) was NOT stripped, causingJSON.parseto fail on the language-tag-prefixed body and silently falling back toonTextwith garbage text. This broke structured output for all three production callers:parseSubGoals,parseSchemeDraft, andAdvisorBot.parseResponse— whenever the LLM emitted any non-json` fence tag (the default for many LLMs for code-like output).Fix: extend regex from
(?:json)?to(?:[a-zA-Z][a-zA-Z0-9_+\-]*)?to match any valid Markdown language identifier. The change is one token in one line; preserves all existing behavior; adds 7 new tests.Changes
src/alienclaw/utils.ts:62— regex whitelist extended (1 line changed)test/utils.test.ts— 7 new PKT-567 tests + 3 control cases + 1 fallback case (+81 lines, no existing assertions modified)TDD evidence
Ran tests BEFORE fix: 7 new cases FAIL (
path='text'not'json'), 18 existing pass.Ran tests AFTER fix: all 25 pass (7 new + 18 existing).
Ship gate
pnpm exec vitest run: 2199 passed, 46 skipped (138 files, 2 skipped)PYTHONPATH=src pytest -q: 1241 passed, 125 skippedRuntime verification
RUNTIME: N/A —
parseModelJsonis a pure utility function with no drivable network/CLI surface. Behavior verified through the test suite.Architect review
alienclaw-architect reviewed the full branch diff: VERDICT: APPROVE — regex correct, scope exact, no architecture/wall/naming/genome violations.
Related packets
(?:json)?literal whitelist)🤖 Generated with Claude Code