examples: add pkgxray-guard supply-chain hook#17
Open
adamsjack711-ux wants to merge 1 commit into
Open
Conversation
A hook that runs pkgxray supply-chain triage on any package an AI coding agent tries to install — before it runs — and denies the command on a BLOCK verdict, returning pkgxray's cited evidence to the agent. - OnBeforeExecution: parses npm/pnpm/yarn/bun installs, npx/bunx/pnpm-dlx runners, and `claude mcp add … -- <launcher>`; runs `pkgxray guard` per package; worst verdict wins. Conservative parsing — unrecognized shapes and local/VCS installs are allowed through rather than wrongly blocked. - OnAfterFileEdit (opt-in): re-audits package.json/lockfiles on edit. - pkgxrayguard/: stdlib-only core (parse/guard/policy) with offline table tests + fake-pkgxray exec tests. Policy strict/balanced/permissive; default balanced fails closed on a missing/broken pkgxray. - Part of the root module (no separate go.mod) so `go build/test ./...` covers it, matching examples/multi-hook. Drop-in agent configs under configs/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
For context on the other side of this integration: the pkgxray repo carries the companion reference copy of this hook plus a reusable lockfile-audit GitHub workflow — adamsjack711-ux/pkgxray#13 (merged).
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Adds
examples/pkgxray-guard/— a hook that runs pkgxray supply-chain triage on any package an AI coding agent tries to install, before it runs, and denies the command on aBLOCKverdict with pkgxray's cited evidence returned to the agent. hookshot supplies the cross-agent hook surface (Claude Code, Cursor, Windsurf Cascade, Factory Droid, OpenAI Codex); pkgxray supplies the detection engine.What's included
main.go— registersOnBeforeExecution(guard installs, worst-verdict-wins across a multi-package command) and an opt-inOnAfterFileEditlockfile re-audit. Env config:PKGXRAY_BIN,PKGXRAY_HOOK_POLICY,PKGXRAY_HOOK_DISABLE,PKGXRAY_HOOK_AUDIT_LOCKFILES,PKGXRAY_GUARD_ARGS.pkgxrayguard/— pure, stdlib-only core:parse.go— shell command → package refs; handlesnpm/pnpm/yarn/bun install|i|add,npx/bunx/pnpm dlxrunners, andclaude mcp add … -- <launcher>. Conservative: unrecognized shapes and local/VCS installs are allowed through, not wrongly blocked.guard.go— runspkgxray guard <ref> --format json, maps the decision, and falls back to the process exit code (2=block/3=review/0=safe) if the JSON is unparsable, so a truncated payload still fails in the right direction.policy.go—strict/balanced/permissive. Defaultbalanceddenies BLOCK, asks on REVIEW, and denies UNKNOWN so a missing/broken pkgxray fails closed.configs/— drop-in hook configs for Claude Code, Cursor, and Codex.README.md— install, config, policy matrix, layout, limits.Design notes
go.mod— the example is part of the root module (likeexamples/multi-hook), sogo build ./.../go test ./...build and test it in the existinggo.ymlCI. Every hookshot symbol and handler signature used was checked againstunified.go.pkgxrayguardcore is stdlib-only and tests offline.pkgxray guardreaches the network (registry/OSV/GitHub); budget ~1s/package, tunable viaPKGXRAY_GUARD_ARGS.Verification
Built and tested green via
go build ./.../go test ./...(the offlinepkgxrayguardtests included) on my fork's CI before opening this PR.🤖 Generated with Claude Code