Skip to content

Extract extractJsonFromFence into a shared src/utils/json-fence.js#55

Merged
4nkur merged 1 commit intomainfrom
dedup/json-fence
Apr 29, 2026
Merged

Extract extractJsonFromFence into a shared src/utils/json-fence.js#55
4nkur merged 1 commit intomainfrom
dedup/json-fence

Conversation

@4nkur
Copy link
Copy Markdown
Owner

@4nkur 4nkur commented Apr 29, 2026

Summary

  • The same fence-extraction helper — find the first ```json or ``` opener and slice to the last closing fence so nested ``` inside JSON values (a directory_structure markdown tree, for instance) don't truncate the capture — was defined verbatim in src/ai/prompts/new.js and src/ai/prompts/greenfield.js. The greenfield copy carried an explanatory comment; the new.js copy didn't. Both flowed through every JSON-shaped model call (parsePlanResponse, parseQuestionsResponse, parseStacksResponse).
  • New src/utils/json-fence.js hosts the function as a named export. Both prompt modules now import it.
  • Adds test/utils/json-fence.test.js with five direct cases (no fence, json fence, bare fence, nested inside payload, missing closing fence) so the helper has direct coverage instead of relying on the parse-response tests for indirect coverage.

Test plan

  • npm test — 312 passing (+5 from the new test file)
  • npm run lint — clean
  • No behavior change in any of the three parse*Response functions

The same fence-extraction helper — find the first ```json or ``` opener and slice to the LAST closing fence so nested ``` inside JSON values (a `directory_structure` markdown tree, for instance) don't truncate the capture — was defined verbatim in `src/ai/prompts/new.js` and `src/ai/prompts/greenfield.js`. The greenfield copy carried an explanatory comment; the new.js copy didn't. Both flowed through every JSON-shaped model call (`parsePlanResponse`, `parseQuestionsResponse`, `parseStacksResponse`).

New module hosts the function as a named export. Both prompt modules now import it. Adds `test/utils/json-fence.test.js` with five direct cases (no fence, ```json fence, bare fence, nested ``` inside payload, missing closing fence) so the helper has direct coverage instead of relying on the parse-response tests for indirect coverage. 312 tests passing (+5 from the new file), lint clean.
@4nkur 4nkur force-pushed the dedup/json-fence branch from 0b58c02 to bc283c4 Compare April 29, 2026 10:13
@4nkur 4nkur merged commit 81e5029 into main Apr 29, 2026
2 checks passed
@4nkur 4nkur deleted the dedup/json-fence branch April 29, 2026 10:13
4nkur added a commit that referenced this pull request Apr 29, 2026
The polish + cleanup release. Half ergonomic improvements (`draftwise init` auto-detects new project vs existing codebase from the filesystem instead of asking; plain-language UX throughout init — #51), half code-quality work (five small dedup + tidy PRs that shrink the public API surface, fix two user-visible `draft` → `draftwise` typos in error messages, and consolidate drafting-command boilerplate behind shared helpers — #53/#54/#55/#56/#57). One genuinely new surface: `draftwise skills <install|uninstall|help>` drops standalone slash-command skills into Claude Code, Cursor, and Gemini CLI's user-level skill dirs (#52) — same SKILL.md, per-provider frontmatter trim — independent of the Claude Code marketplace plugin.

Bumps `package.json` + `package-lock.json` from 0.2.0 → 0.2.1. Patch bump because the additive `skills` verb is non-breaking and the removed prompt aliases (`PLAN_SYSTEM`, `SPEC_SYSTEM`, `tech.SYSTEM`, `tasks.SYSTEM`) were never imported by anyone outside this repo (verified by audit). Rolls all [Unreleased] entries into [0.2.1] — 2026-04-29 — Ankur, with a fresh empty [Unreleased] block above.

After merge, ritual: `git tag -a v0.2.1 -m "v0.2.1"`, `git push origin v0.2.1`, `npm publish` (interactive — OTP + login may be needed if the npm session expired).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant