You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary
This cleans up hook payload JSON helpers by moving map encode/decode and numeric-preserving JSON parsing into one canonical hook helper.
Before this, localruntime, sidecar, and hookruntime each carried their own JSON map helpers or decode path, which made hook payload handling easier to drift.
Why
This gives kontext-cli a cleaner maintenance path for hook payload handling:
hook event/result
-> internal/hook/json.go
-> localruntime, sidecar, hookruntime
-> one typed decision path and one JSON codec
This PR does not broaden behavior beyond the cleanup scope.
What changed
Added internal/hook/json.go and regression tests for nil-map handling and large-number preservation
Removed duplicate JSON map helpers from internal/localruntime and internal/sidecar
Consolidated Claude tool-response decoding onto the shared helper
Strengthened localruntime.EvaluateResult.Decision to use hook.Decision
Updated localruntime and sidecar tests for the typed decision path
Verification go test ./internal/hook ./internal/hookruntime ./internal/localruntime ./internal/sidecar -count=1 go test ./... go vet ./...
ToolInput and ToolInputAlt are still decoded by the outer json.Unmarshal into map[string]any, so large integers in Claude tool inputs are converted to float64 before the new shared helper ever sees them. When Claude sends a PreToolUse payload such as tool_input.id = 9007199254740993, this path rounds it before localruntime or sidecar forwarding, and downstream policy checks, recordings, or hashes can receive the wrong ID. Decode the Claude input with UseNumber too, or keep the tool input fields as json.RawMessage and pass them through hook.UnmarshalMapJSON like the updated response path.
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
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
This cleans up hook payload JSON helpers by moving map encode/decode and numeric-preserving JSON parsing into one canonical hook helper.
Before this, localruntime, sidecar, and hookruntime each carried their own JSON map helpers or decode path, which made hook payload handling easier to drift.
Now
internal/hook/json.gois the canonical path:Why
This gives kontext-cli a cleaner maintenance path for hook payload handling:
hook event/result
-> internal/hook/json.go
-> localruntime, sidecar, hookruntime
-> one typed decision path and one JSON codec
This PR does not broaden behavior beyond the cleanup scope.
What changed
Added
internal/hook/json.goand regression tests for nil-map handling and large-number preservationRemoved duplicate JSON map helpers from
internal/localruntimeandinternal/sidecarConsolidated Claude tool-response decoding onto the shared helper
Strengthened
localruntime.EvaluateResult.Decisionto usehook.DecisionUpdated localruntime and sidecar tests for the typed decision path
Verification
go test ./internal/hook ./internal/hookruntime ./internal/localruntime ./internal/sidecar -count=1go test ./...go vet ./...