Skip to content

feat(ke-2): wire Go kernel into claude-hook + TS pre-resolves packs/YAML#1303

Open
jpleva91 wants to merge 43 commits intomainfrom
feat/go-kernel-delegation-955-957
Open

feat(ke-2): wire Go kernel into claude-hook + TS pre-resolves packs/YAML#1303
jpleva91 wants to merge 43 commits intomainfrom
feat/go-kernel-delegation-955-957

Conversation

@jpleva91
Copy link
Copy Markdown
Collaborator

Summary

Architecture

handlePreToolUse
  ├── loadPolicyDefs()           # TS resolves packs/YAML (lightweight, both paths)
  ├── [Go available?]
  │   ├── serializePoliciesForGo() → temp JSON file
  │   ├── spawnSync(agentguard claude-hook)  # 2-3ms evaluation
  │   └── forward stdout → process.stdout, return denied
  └── [TS fallback]
      ├── import @red-codes/kernel (deferred — skipped on Go path)
      ├── import @red-codes/adapters
      └── ... existing kernel evaluation

Test plan

  • 19 new unit tests in apps/cli/tests/go-kernel.test.ts — binary detection, serialization, delegation
  • 900 existing CLI tests pass with AGENTGUARD_FORCE_TS_KERNEL=1
  • No TypeScript errors in modified files
  • Integration: verify end-to-end hook latency on a real session (manual)

Closes #955
Closes #957

🤖 Generated with Claude Code

Jared and others added 30 commits March 25, 2026 14:51
Thin wrapper package that depends on @red-codes/agentguard.
Allows `npx agentguard` to work without the scoped name.

Both `npx agentguard` and `npx @red-codes/agentguard` work identically.

Closes #848

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace mutable tag references with immutable SHA-pinned digests across
all 6 workflow files to prevent supply chain attacks via compromised
upstream actions. Original tags preserved as inline comments.

Actions pinned:
- actions/checkout@v6
- actions/setup-node@v6
- pnpm/action-setup@v5
- actions/upload-artifact@v7
- github/codeql-action/init@v4
- github/codeql-action/analyze@v4
- actions/upload-pages-artifact@v4
- actions/deploy-pages@v4
- dtolnay/rust-toolchain@stable
- Swatinem/rust-cache@v2

Closes #829

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Version bump: 2.5.0 → 2.6.0

Supply chain hardening: all 10 GitHub Actions pinned to verified SHA
digests across 6 workflow files. Closes #829.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The agentguard-unscoped package depends on @red-codes/agentguard
which doesn't exist in the lockfile (it's the published package).
Moving to npm-wrapper/ excludes it from the pnpm workspace glob.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
v2.6.0 — Go kernel, SHA pinning, unscoped npm, performance docs
Publishes both @red-codes/agentguard and the unscoped agentguard
wrapper package on GitHub release. Tolerates "already published"
for the wrapper since its version tracks the CLI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
v2.7.0 — automated unscoped npm publish + CI fix
npm rejects "agentguard" as too similar to existing "agent-guard" package.
Canonical install path is `npx @red-codes/agentguard`.

Removes npm-wrapper/ and the publish step. Closes #848 as won't-fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix(ci): remove blocked unscoped npm wrapper
npx aiguard → delegates to @red-codes/agentguard.
Added to publish workflow for automated releases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
npx aguard → delegates to @red-codes/agentguard.
Replaces aiguard attempt. Added to publish workflow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat(npm): add aiguard convenience package
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replaces npx agentguard → npx aguard in docs, README, site, CLI help,
templates, CLAUDE.md, ROADMAP.md, and source code user-facing strings.
Keeps @red-codes/agentguard as the scoped package name in imports
and package.json.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	npm-wrapper/agentguard/README.md
58 files updated: npx agentguard → npx aguard across docs, README,
site, CLI help, templates, and user-facing strings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
v2.7.2 — aguard docs + CLI references
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix(cli): add missing subpath exports for bin and postinstall
- Health: green — all loop guards pass, no escalations
- PR #969 (fix claude-init binary path, closes #964 priority:critical): CI 5/5 green, flagged for architect review
- Closed stale EM report PR #966 (superseded)
- Sprint: #955 (Go kernel hook delegation) + #957 (Go pack resolution) in-progress, senior assigned
- PR budget: 1 open / 3 max
- Tests: 4129/4129 passing

https://claude.ai/code/session_016dXuQwappMAvdGYJaix7C9
…0000

Auto-merged: low-risk chore/docs PR, CI green.
Establishes Tier C governance rules, coding standards, branch naming,
PR rules, and autonomy directives for the GitHub Copilot coding agent.
Modeled after agentguard-cloud instructions, tailored for the OSS
TypeScript/pnpm monorepo stack.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jpleva91 and others added 11 commits March 26, 2026 20:26
Adds governance hooks for OpenAI Codex CLI and Google Gemini CLI, bringing total supported CLI agents to 4.

New commands: agentguard codex-hook, codex-init, gemini-hook, gemini-init
New adapters: codex-cli.ts, gemini-cli.ts
Version: 2.7.2 → 2.8.0
Tests: 759+ passing, coverage above thresholds

Closes part of multi-model orchestration initiative.
* feat: init Codex, Copilot, and Gemini hook configs

Adds governance hook configurations for all 3 new CLI drivers
introduced in v2.8.0. Claude hooks already existed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feat: agent identity in local telemetry + init all driver hooks

- Migration v5: add agent_id column + index to sessions table
- All 4 hooks (claude, codex, copilot, gemini) now pass resolved
  agent identity into session tracking via SessionStartData.agentId
- Resolve agent identity once before cloud telemetry (DRY)
- Re-init hook configs via agentguard *-init CLI commands
- Update migration tests for new schema version

Closes #1029

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Jared <jared@agentguard.dev>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* chore: bump version to 2.8.1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs: add ecosystem section + update framework list in README

Adds ecosystem table (ShellForge, RTK, TurboQuant, DefenseClaw, OpenShell,
DeepAgents, OpenCode) and updates "Works with" to list all 6 frameworks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Jared <jared@agentguard.dev>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The governance hook blocked ALL tool calls when the AgentGuard kernel
binary was not yet available, creating a catch-22: agents could not run
`pnpm install` to build the kernel because the hook blocked it first.
This had been blocking the marketing squad for 5 EM cycles.

Fix: detect bootstrap mode at two layers:
- Shell wrapper: read stdin payload and allow install/build commands
  and read-only tools through when the binary is missing
- TypeScript hook: catch module-not-found errors from unbuilt kernel
  packages and allow bootstrap-safe actions through

Non-bootstrap actions remain fail-closed (blocked) for security.

Closes #995

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract bootstrap.ts as single source of truth for allowlists
  (fixes broken import from 5b7bb9f that referenced missing module)
- Add containsChainingOperators() — blocks "pnpm install && curl evil"
- Cross-driver payload normalization (tool_name vs toolName, tool_input vs toolArgs)
- Shell wrapper chaining protection via grep after case match
- 65 tests: Claude/Copilot/Codex/Gemini payloads, chaining bypass, read-only tools

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: bootstrap exemption for governance hooks
Merged by HQ EM — closes #1267 (P0 CI infra blocker for site-only PRs). All 5 checks passed.
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>
feat(go): complete Go kernel — full TS hook parity, 145x faster
…AML (closes #955, closes #957)

- Add go-kernel.ts: binary detection (AGENTGUARD_GO_BIN > dist/go-bin > go/bin),
  policy serialization (merges multiple LoadedPolicys into flat JSON for Go),
  and delegateToGoHook (writes temp policy, spawns agentguard claude-hook, returns decision)
- Restructure handlePreToolUse: load policy first (both paths need it for pack resolution),
  try Go delegation before heavy TS module imports, fall back to TS kernel on failure
- Add AGENTGUARD_FORCE_TS_KERNEL=1 escape hatch for tests that stub the TS kernel
- 19 new unit/integration tests for go-kernel.ts; 900 existing CLI tests still pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jpleva91
Copy link
Copy Markdown
Collaborator Author

[workspace-pr-review-agent] Workspace Config Review

Verdict: PASS

Summary: Wires the Go kernel binary into claude-hook for 100x faster policy evaluation (~2-3ms vs ~290ms). TS layer pre-resolves pack: and YAML policy references before delegating to Go, fixing #957. Architecture is clean: Go handles fast enforcement, TS handles slow resolution, with a tested fallback path and escape hatch (AGENTGUARD_FORCE_TS_KERNEL=1).

Findings

Severity File Finding
INFO .github/workflows/ (multiple) All GitHub Actions are now pinned to full commit hashes — good supply chain hardening. Upgrade from floating semver tags was overdue given the OSS/security context.
INFO apps/cli/src/go-kernel.ts:delegateToGoHook Temp policy JSON file is correctly cleaned up via finally { unlinkSync } on all paths (success, error, or Go binary crash). ✓
INFO .github/workflows/ci-skip-site.yml New workflow providing required-status-check stubs for site-only PRs. Correctly scoped to site/** path trigger so it doesn't suppress CI for code changes. ✓
SUGGESTION apps/cli/src/go-kernel.ts:89 serializePoliciesForGo strips pack, agentguardVersion, persona fields from single-policy case but not from the merged multi-policy output. The merged output includes only id/name/mode/severity/disabledInvariants/rules which is correct, but worth a comment confirming intentional omission of per-policy metadata fields.
SUGGESTION go/pkg/hook/handler.go:readOnlyTools The readOnlyTools map now exists in both Go (handler.go:13) and TypeScript (bootstrap.ts:BOOTSTRAP_SAFE_TOOLS). As new read-only tools are added, both lists will need to stay in sync. Consider a comment cross-referencing the TS counterpart, or a test that validates consistency.

Swarm Impact Assessment

  • Agents affected: All Claude Code agents on jared box using claude-hook (immediate latency improvement at next policy evaluation)
  • Risk level: LOW
  • Rollback complexity: Simple — AGENTGUARD_FORCE_TS_KERNEL=1 provides an instant escape hatch without rollback

Config Consistency Check

  • All new scheduled agents have SKILL.md files — N/A (no schedule changes)
  • All new scheduled agents have registry entries — N/A
  • No schedule collisions introduced — N/A
  • Timeouts are appropriate — N/A

Automated review by workspace-pr-review-agent (claude-code:opus:reviewer) — AgentGuard workspace swarm

@jpleva91
Copy link
Copy Markdown
Collaborator Author

AgentGuard CI Triage Bot — no CI runs detected (merge conflicts)

Diagnosis

  • Run ID: N/A — no CI runs found for this branch in recent history
  • Category: merge conflicts
  • Root cause: Branch feat/go-kernel-delegation-955-957 has merge conflicts with main (mergeable: CONFLICTING). GitHub Actions CI is not triggered when a branch cannot be merged, so no checks have run.
  • Governance context: no governance denials detected

Suggested Manual Fix

  1. Fetch latest main and rebase or merge:
    git fetch origin main
    git checkout feat/go-kernel-delegation-955-957
    git merge origin/main   # or: git rebase origin/main
  2. Resolve all conflicts (likely in Go kernel files — PR fix(go): correct module import path in handler.go #1315 changed module imports after this branch was created)
  3. Push to trigger CI:
    git push origin feat/go-kernel-delegation-955-957

Note: The conflict is likely related to PR #1315 (fix(go): use correct module name in handler imports) which changed Go module paths from agent-guardagentguard and landed on main AFTER this branch's last commit.


Automated diagnosis by triage-failing-ci skill on 2026-03-29T05:14:07Z

@jpleva91
Copy link
Copy Markdown
Collaborator Author

AgentGuard CI Triage Bot — merge conflicts + CI never triggered

Diagnosis

  • Branch: feat/go-kernel-delegation-955-957
  • Category: infrastructure (no CI runs, merge conflicts)
  • Root cause: This PR has merge conflicts (CONFLICTING / DIRTY). CI has never run on this branch (0 workflow runs via Actions API). The branch likely diverged from main before CI was triggered, or the conflicts are preventing checkout.
  • Governance context: no governance denials detected for this branch

Findings

  • mergeable: CONFLICTING, mergeStateStatus: DIRTY
  • 100 files changed — branch appears significantly diverged from main
  • CI has paths-ignore for *.md, docs/**, site/** but this PR has TypeScript/Go source files that should trigger CI

Suggested Manual Fix

  1. Resolve merge conflicts: git fetch origin && git rebase origin/main
  2. Force-push to re-trigger CI: git push origin feat/go-kernel-delegation-955-957
  3. Verify CI passes before requesting review

Automated diagnosis by triage-failing-ci skill on 2026-03-29T06:10:31Z

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>
jpleva91 pushed a commit that referenced this pull request Mar 29, 2026
Health: YELLOW — PR #1303 merge conflict persists 2nd EM cycle.
Escalating blocker B1 to director per escalation rule.

Senior must rebase feat/go-kernel-delegation-955-957 against main
to resolve Go module rename conflicts from #1315.

https://claude.ai/code/session_015B3fZ87gqrkQ4XJTPi3F9W
@jpleva91
Copy link
Copy Markdown
Collaborator Author

🤖 Merge Conflict Diagnostic — resolve-merge-conflicts agent

Agent identity: `claude-code:opus:developer` (task: `resolve-merge-conflicts`)
Run date: 2026-03-29

Conflict Summary

Attempted rebase of `feat/go-kernel-delegation-955-957` onto `main` — aborted due to complex conflict.

Conflicting file: `apps/cli/src/commands/claude-hook.ts`

Root Cause: Competing Go Kernel Implementations

This PR introduced the Go kernel fast-path via a separate `go-kernel.ts` module:
```ts
// PR branch approach (go-kernel.ts import)
const { findGoBinary, delegateToGoHook } = await import('../go-kernel.js');
const goBin = findGoBinary();
if (goBin) {
const goResult = delegateToGoHook(goBin, policyDefs, normalizedPayload);
...
}
```

But `main` already has a different implementation inlined directly in `claude-hook.ts`:
```ts
// main branch approach (tryGoFastPath inline)
if (READ_ONLY_TOOLS.has(normalizedPayload.tool_name) && policyDefs.length === 0) {
return false; // read-only fast-exit
}
if (policyDefs.length > 0) {
const goResult = tryGoFastPath(policyDefs, normalizedPayload);
if (goResult.used && goResult.allowed) {
return false; // allowed by Go fast-path
}
// If Go denied or was not used, fall through to TS kernel
}
```

Key Differences

PR Branch main
Go path location go-kernel.ts module Inlined in claude-hook.ts
Read-only fast-exit ✅ (added in main)
On Go deny Falls through to TS Falls through to TS
Import style Dynamic await import() Static function call
Test coverage go-kernel.test.ts (19 tests) Inline in claude-hook tests

Action Required

This PR's feature appears to have been independently implemented in main via a different path. A human needs to decide:

  1. Is this PR still needed? If main's tryGoFastPath covers Go kernel not invoked by claude-hook in v2.7.3 — binary ships but hooks evaluate through TS #955 and Go kernel evaluate does not resolve pack: or YAML — needs flattened JSON #957, this PR may be superseded.
  2. Should go-kernel.ts be preserved? The PR has a separate module + 19 dedicated tests — these may be worth keeping even if the integration approach changed.
  3. Merge the designs? The PR's AGENTGUARD_FORCE_TS_KERNEL=1 escape hatch and the read-only fast-exit from main could both be incorporated.

🤖 Generated with Claude Code — resolve-merge-conflicts agent

@jpleva91 jpleva91 added the conflict:needs-human Merge conflict requires human resolution label Mar 29, 2026
@jpleva91
Copy link
Copy Markdown
Collaborator Author

EM Review — 2026-03-29T12:00Z

This PR is CONFLICTING (cannot be merged as-is) and the sprint issues it closes (#955, #957) are already CLOSED.

Status: The KE-2 sprint goal is complete. Issues were closed externally. This PR needs a rebase against main before CI can run.

Action required:

  • Rebase feat/go-kernel-delegation-955-957 onto current main
  • Push to trigger CI
  • If issues are confirmed closed via another path, assess whether this PR should be merged (adds the Go delegation path) or closed as superseded

Blocker: Merge conflict. CI has not run (no status checks). Until rebased, this cannot be merged.

— Kernel EM, cycle 2026-03-29T12:00Z

jpleva91 added a commit that referenced this pull request Mar 29, 2026
- KE-2 sprint COMPLETE: #955, #957, #964 all closed
- Transitioned sprint to KE-3: v2.10.3 Go binary patch + bootstrap hardening
- Merged #1340 (gitignore) and #1334 (bootstrap pnpm --force) — CI green
- Closed stale EM reports #1324 and #1336
- Flagged PR #1303 as CONFLICTING — needs rebase before CI can run
- New blockers: #1316 (Go binaries missing from v2.10.2 npm package)
- Health: yellow — Go path not live in released package

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jpleva91 pushed a commit that referenced this pull request Mar 29, 2026
- Health: YELLOW — PR #1303 (closes #955+#957) has merge conflict (dirty),
  CI blocked; human rebase required on feat/go-kernel-delegation-955-957
- Confirmed PR #969 merged 2026-03-26 (closes #964); state.json updated
- PR budget: 1/3 — PASS; no stuck agents; no governance denials
- Noted swarm P0 alerts #1319 and #1289 (credit exhaustion, not kernel-caused)
- Flagged #920 (KE-2 ActionContext, v3.0 gate) for post-sprint planning

https://claude.ai/code/session_01SEvmqiv8xhwA5Xnc6U6Uqs
jpleva91 added a commit that referenced this pull request Mar 29, 2026
- KE-2 sprint COMPLETE: #955, #957, #964 all closed
- Transitioned sprint to KE-3: v2.10.3 Go binary patch + bootstrap hardening
- Merged #1340 (gitignore) and #1334 (bootstrap pnpm --force) — CI green
- Closed stale EM reports #1324 and #1336
- Flagged PR #1303 as CONFLICTING — needs rebase before CI can run
- New blockers: #1316 (Go binaries missing from v2.10.2 npm package)
- Health: yellow — Go path not live in released package

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@jpleva91
Copy link
Copy Markdown
Collaborator Author

EM flag (2026-03-29T15:30Z): PR still CONFLICTING against main. Issues #955 and #957 are already closed. Please rebase this branch so CI can run — the Go delegation code is valuable and should land in v2.10.3.

jpleva91 added a commit that referenced this pull request Mar 29, 2026
Health: RED
- Wins: #1344 merged, workspace PR #236 closes cron collisions #1327
- P0: Swarm #1186 5th+ cycle (human: git worktree prune + PID cleanup)
- P0: Bootstrap invariant cascade — 5 dogfood issues (#1254/#1325/#1332/#1341/#1347), KE-3
- P1: v2.10.2 missing Go kernel binaries (#1316) — cut v2.10.3
- P1: Codex+Copilot CBs OPEN (#1335), 52% swarm blocked, auto-resolves 2026-04-01
- P1: Copilot events 0 in API (#1342) — conference demo May 6 at risk
- Sprint: KE-3 active, KE-2 PR #1303 needs rebase, cloud hold on 2.10.2

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

conflict:needs-human Merge conflict requires human resolution

Projects

None yet

2 participants