Skip to content

refactor(capture): data-driven hook mappings for all four adapters - #2

Merged
tabladrum merged 1 commit into
mainfrom
feat/data-driven-capture-maps
Oct 23, 2026
Merged

tabladrum merged 1 commit into
mainfrom
feat/data-driven-capture-maps

Conversation

@tabladrum

@tabladrum tabladrum commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Rebased onto main (2026-10-22), ready for review. It was held during the open-source launch freeze; the freeze is over. The rebase had no conflicts (nothing under internal/capture/ changed on main in the meantime), and build/vet/gofmt/go test ./... plus CI (lint + tests on ubuntu/windows/macos) are green afterwards.

What this does

Moves every adapter's hook contract (event names, field names, snake/camel variants, tool→op) out of Go and into internal/capture/maps/<tool>.json, read by a shared engine (mapping.go). A vendor renaming a field or event becomes a JSON edit, not a code change + rebuild.

  • claude-code, codex, cursor, copilot parsers are now ~15-line delegators to applyMapping().
  • Maps are go:embed'd — fresh install works offline, no setup. The loader is the seam a future shale update-map overlay plugs into.
  • Structural extraction that can't be a flat field map stays in code via a structuralHandlers registry: Codex's apply_patch envelope is wired in as the codex map's tool_fallback, self-guarding on the tool name.
  • New mapping_test.go fails CI if any embedded map is malformed or incomplete (no silent no-op).

Why it's safe to merge

  • Every existing fixture test passes unchanged — behavior is identical across all four adapters. This is a pure refactor.
  • go vet + gofmt clean locally.
  • Caveat worth noting: the cursor/codex/copilot fixtures are synthetic (not recorded from real runs), so they prove engine parity, not real-payload correctness. claude-code is the only adapter exercised in production today.

Designed follow-ups (intentionally NOT here)

Value-shape fallback for unseen fields · quarantine of unmatched payloads to surface silent drift · signed mapping pack via opt-in shale update-map.

🤖 Generated with Claude Code

@tabladrum

Copy link
Copy Markdown
Contributor Author

Tracking issue with contributor guidance (real Cursor/Copilot payloads wanted): #4

Move every adapter's hook contract — event names, field names, snake/camel
variants, tool→op — out of Go and into internal/capture/maps/<tool>.json, read
by a small shared engine (mapping.go). A vendor renaming a field or an event
is now a JSON edit, not a Go change + rebuild.

- claude-code, codex, cursor, copilot parsers are now ~15-line delegators to
  applyMapping(); all behavior preserved (every existing fixture test passes
  unchanged).
- Maps are go:embed'd, so a fresh install works offline with no setup. The
  loader is the single seam a future `shale update-map` overlay would hook into.
- Structural extraction that can't be a flat field map stays in code via a
  structuralHandlers registry: Codex's apply_patch envelope is wired in as the
  codex map's tool_fallback, self-guarding on the tool name.
- Shared object/path helpers (only the still-hand-written adapters used them)
  removed; helpers.go keeps just firstNonEmpty + firstRaw.
- New mapping_test.go guards that every embedded map is loadable and complete,
  so a malformed map can't ship as a silent no-op.

Follow-ups (designed, not in this change): value-shape fallback for unseen
field names; quarantine of unmatched payloads to surface silent drift; a
signed mapping pack distributed via opt-in `shale update-map`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tabladrum
tabladrum force-pushed the feat/data-driven-capture-maps branch from 2f05c70 to b613650 Compare October 23, 2026 00:03
@tabladrum
tabladrum marked this pull request as ready for review October 23, 2026 00:06
@tabladrum
tabladrum merged commit cbd91bf into main Oct 23, 2026
4 checks passed
@tabladrum
tabladrum deleted the feat/data-driven-capture-maps branch October 23, 2026 00:06
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