Skip to content

fix(utils): strip any Markdown language tag from parseModelJson opening fence (PKT-567) - #458

Open
bugsyhewitt wants to merge 1 commit into
mainfrom
fix/pkt-567-parsemodeljson-language-tag
Open

fix(utils): strip any Markdown language tag from parseModelJson opening fence (PKT-567)#458
bugsyhewitt wants to merge 1 commit into
mainfrom
fix/pkt-567-parsemodeljson-language-tag

Conversation

@bugsyhewitt

Copy link
Copy Markdown
Owner

Summary

parseModelJson in src/alienclaw/utils.ts:62 used /\``(?: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, causing JSON.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, and AdvisorBot.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 skipped

Runtime verification

RUNTIME: N/A — parseModelJson is 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

  • Distinct from PKT-459 (over-stripping backticks INSIDE JSON string values — opposite failure mode)
  • Distinct from PKT-468 (anchored fence-strip, still used (?:json)? literal whitelist)
  • Closes PKT-567

🤖 Generated with Claude Code

…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>
@bugsyhewitt bugsyhewitt added the auto-merge-ok Binding review passed + ship-gate green — cleared for auto-merge label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-ok Binding review passed + ship-gate green — cleared for auto-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant