refactor(guard): dedupe dashboard decoding and CLI helpers#159
refactor(guard): dedupe dashboard decoding and CLI helpers#159michiosw wants to merge 5 commits into
Conversation
Greptile SummaryThis PR refactors Guard dashboard decoding and CLI helper setup. The main changes are:
Confidence Score: 4/5This is close, but the dashboard API shape should be restored before merging.
web/guard-dashboard/src/dashboard/types.ts and web/guard-dashboard/src/dashboard/api.ts Important Files Changed
|
d96e0ff to
fb17077
Compare

Summary
This cleans up Guard dashboard decoding and Guard CLI helpers by making decision/profile IDs single-source-of-truth, removing duplicated wrappers, and keeping embedded assets in sync.
Before this, the dashboard duplicated allowed values between type unions and JSON decoding, and Guard CLI had repeated FlagSet boilerplate plus pass-through localruntime wrappers. Sidecar/hook failure paths also hid the underlying error reason. The repo also needed a dashboard asset refresh after the type cleanup.
Now the Guard path has one canonical set of values and clearer failure visibility:
user activity -> risk events -> dashboard rendering
hook runtime -> sidecar eval -> warning on stderr (only on error)
Why
This gives kontext-cli a cleaner maintenance path for Guard:
input/event -> boundary decode -> canonical helper/type/path -> result
This PR does not broaden behavior beyond the cleanup scope.
What changed
Added canonical value lists + guards for Decision/PolicyProfileID in web/guard-dashboard/src/dashboard/types.ts
Consolidated API decoding to use those guards and stopped any leaking across the JSON boundary
Removed redundant internal/guard/cli/localruntime.go wrappers and deduped FlagSet setup
Logged previously swallowed update/sidecar/access-mode read errors to stderr (only when errors happen)
Refreshed internal/guard/web/assets to match the dashboard build output
Deflaked llama-server startup timing tests (avoid tight 2s timing assumptions)
Verification
pnpm build
pnpm --dir web/guard-dashboard typecheck
go test ./... -count=1
go vet ./...
git diff --check