Skip to content

feat(chunker): structured JSON prompt for commit message generation#213

Merged
blak0p merged 4 commits into
mainfrom
feat/chunker-prompt-quality
Jul 2, 2026
Merged

feat(chunker): structured JSON prompt for commit message generation#213
blak0p merged 4 commits into
mainfrom
feat/chunker-prompt-quality

Conversation

@blak0p

@blak0p blak0p commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Closes #206

Summary

  • Replace emoji-prefixed plain-text annotations with structured JSON (annotated_diff, call_graph, cfg) in the LLM prompt for commit message generation
  • Remove legacy emoji merger from diff_merger.go
  • All existing tests pass with zero regressions

Changes

File Change
internal/core/domain/diff.go Added AnnotatedEntry, CallGraphEntry, CFGEntry, CFGSummary types; DiffChunk gains AnnotatedEntries/CallGraph fields
internal/infra/chunkers/hunk_extractor.go New file: buildAnnotatedEntries, parseDiffHunks, hunkLinesForLabel
internal/infra/chunkers/diff_merger.go Removed emoji parsing (MergeDiffIntoAnnotations, parseLabelGroups, etc.)
internal/infra/chunkers/unified.go formatLabelsForChunk returns []AnnotatedEntry; Annotate populates AnnotatedEntries
internal/infra/chunkers/adapter.go AnnotateWithContent populates AnnotatedEntries with hunk before/after
internal/shared/prompts/prompts.go MessageParams gains AnnotatedJSON, CallGraphJSON, CFGJSON fields
internal/shared/prompts/md/commit_message.md Template renders JSON blocks with 3-level fallback
internal/adapters/llm/openai_standard/adapter_commit.go GenerateChunkMessage marshals typed fields to JSON
internal/adapters/llm/openai_standard/adapter_release.go regenerateChunk uses same JSON marshaling
internal/workflow/commit.go combineChunks merges AnnotatedEntries/CallGraph slices; prepareStages preserves CFG metadata

Test Plan

  • go test -short ./... — 42 packages, all pass
  • go vet ./... — clean
  • go vet -tags manual ./... — clean
  • 21 new tests across 9 test files
  • Strict TDD: all tasks have RED/GREEN/REFACTOR evidence

blak0p added 4 commits July 2, 2026 11:06
…nk extractor

Add AnnotatedEntry, CallGraphEntry, CFGEntry, CFGSummary domain types and
DiffChunk.AnnotatedEntries/CallGraph fields (additive — AnnotatedDiff string
kept for backward compat). Extract hunk-line helpers from diff_merger into the
new hunk_extractor.go and add buildAnnotatedEntries, which converts labels +
parsed diff hunks into per-symbol before/after hunk records.

Add AnnotatedJSON/CallGraphJSON/CFGJSON to MessageParams with updated
BuildMessageParams/BuildMessageParamsWithRetry signatures, and render the new
JSON blocks in commit_message.md with a three-level fallback
(AnnotatedJSON → AnnotatedDiff → Diff). Adapter callers pass empty JSON
strings for now; full marshaling is wired in the integration phase.

Includes table-driven buildAnnotatedEntries tests, approval tests proving the
new path is hunk-equivalent to the legacy merge, and JSON-field prompt tests.
…hContent

Refactor formatLabelsForChunk to return []AnnotatedEntry instead of an
emoji-prefixed string, and populate chunk.AnnotatedEntries alongside the
legacy AnnotatedDiff in both the UnifiedASTPass.Process chunk builder and
Annotate. AnnotateWithContent now calls buildAnnotatedEntries with the parsed
diff hunks and pre-computed labels to fill per-symbol before/after hunk lines
on the structured entries, keeping ProcessWithContent at one call per file.

Add formatEntriesAsLegacyString to render entries back to the emoji format for
backward-compatible AnnotatedDiff consumers. Includes table-driven tests for
the new return type, Annotate population, and AnnotateWithContent structured
entry population.
…rompt

GenerateChunkMessage and regenerateChunk now marshal chunk.AnnotatedEntries,
CallGraph, and CFGBefore/CFGAfter into the AnnotatedJSON/CallGraphJSON/CFGJSON
prompt params via the shared buildChunkAnnotationJSON helper. When
AnnotatedEntries is non-empty the legacy emoji AnnotatedDiff and raw Diff are
dropped so the prompt uses the structured JSON path exclusively; when empty
the existing raw-diff fallback is preserved. CFGJSON is omitted when
CFGBefore/CFGAfter are nil (cfg not computed).

Includes tests covering annotated_diff/call_graph/cfg JSON rendering, the
null-CFG omission, and the empty-entries raw-diff fallback for both generate
and regenerate paths.
…ji merger

combineChunks now merges AnnotatedEntries and CallGraph slices from sub-chunks
into the combined chunk (append), alongside the existing CFG count summation.
prepareStages stops clearing CFGBefore/CFGAfter after classification — CFG
data is now needed downstream to build the CFGSummary for the LLM prompt.

Remove the legacy emoji-era diff_merger.go functions (MergeDiffIntoAnnotations,
parseLabelGroups, parseLabelLine, rebuildAnnotatedDiff) now that the structured
buildAnnotatedEntries path is fully wired. Migrate the manual e2e test to use
AnnotateWithContent (which populates AnnotatedEntries with hunk before/after)
and drop the MergeDiffIntoAnnotations approval test, keeping the equivalence
test that proves buildAnnotatedEntries matches the old merge's hunk extraction.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@blak0p blak0p added the type:feature New feature label Jul 2, 2026
@blak0p blak0p merged commit e98c67e into main Jul 2, 2026
6 checks passed
@blak0p blak0p deleted the feat/chunker-prompt-quality branch July 2, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-courer — chunker-prompt-quality

1 participant