Skip to content

feat(go): complete Go kernel — full TS hook parity, 145x faster#1300

Merged
jpleva91 merged 1 commit intomasterfrom
feat/go-kernel-complete
Mar 29, 2026
Merged

feat(go): complete Go kernel — full TS hook parity, 145x faster#1300
jpleva91 merged 1 commit intomasterfrom
feat/go-kernel-complete

Conversation

@jpleva91
Copy link
Copy Markdown
Collaborator

Summary

  • Complete Go kernel implementation replacing the TypeScript hook pipeline
  • Go handles all hook events: PreToolUse, PostToolUse, Stop, Notification
  • 145x faster hook evaluation: 2ms Go vs 290ms TS
  • Root cause fix: FromStdin() fallback — Claude Code sends payloads via stdin, not env vars. The Go fast-path was never actually executing.

New Go files (975 lines added)

  • env.go — .env loading (AGENTGUARD_* vars from project root)
  • session.go — session state persistence (format/test pass, written files, retry counts) + root session tracking
  • identity.go — agent identity resolution + wizard prompt
  • lesson.go — denial lesson capture for educate mode learning
  • telemetry.go — cloud telemetry client (async HTTP, 2s timeout)

Key changes

  • types.goFromStdin() reads JSON from stdin when env vars aren't set
  • handler.go — monitor/guide/educate/enforce mode routing, read-only tool fail-open, invariant checking, retry tracking
  • claude.go — full PreToolUse/PostToolUse/Stop/Notification event handling

Test plan

  • All 14 Go packages pass (go test ./...)
  • Write tool allowed through Go fast-path (exit 0)
  • Force push denied by policy in enforce mode (exit 2)
  • Force push warned in monitor mode (exit 0 + stderr warning)
  • Guide mode retry tracking increments counter
  • Verify CI passes (lint, test-and-build)

🤖 Generated with Claude Code

Go kernel now handles all Claude Code hook events with full feature parity:
- PreToolUse: policy eval, invariant checking, enforcement mode routing
  (enforce/guide/educate/monitor), read-only tool fail-open, session state,
  identity wizard, retry tracking, cloud telemetry, lesson capture
- PostToolUse: bash error reporting, format/test pass tracking, PR detection
- Stop: session viewer generation, root session cleanup
- Notification: live session viewer spawn

New files: env.go, session.go, identity.go, lesson.go, telemetry.go
Key fix: FromStdin() fallback — Claude Code sends payloads via stdin,
not env vars. This was the root cause of Go fast-path never executing.

Performance: 2ms Go vs 290ms TS — 145x faster hook evaluation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpleva91 jpleva91 merged commit 759913b into master Mar 29, 2026
5 checks passed
jpleva91 added a commit that referenced this pull request Mar 29, 2026
- Health: yellow — PR #1303 (sprint #955/#957) CONFLICTING after PR #1300 merged
- PR #1300 MERGED: complete Go kernel (145x faster, 2ms vs 290ms) — major milestone
- PR #1295 MERGED: bootstrap catch-22 fix (#995)
- PR #1296 MERGED: site-only PR CI skip fix (#1267)
- PR #969 MERGED: fix claude-init binary path (closes #964)
- PR #1303: sprint work CONFLICTING — senior must assess rebase vs close
- No P0/P1 issues open
- PR #1317 (Gemini tests, 4/4 CI green, copilot squad): ready for human review
- Dogfood #1323 filed: pnpm install --frozen-lockfile bootstrap hang in non-TTY

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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