Skip to content

feat: ai agents hook events#61

Merged
ashishkurmi merged 12 commits into
step-security:mainfrom
raysubham:feat/ai-agents-hook-events
May 13, 2026
Merged

feat: ai agents hook events#61
ashishkurmi merged 12 commits into
step-security:mainfrom
raysubham:feat/ai-agents-hook-events

Conversation

@raysubham
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the AI-agent hooks domain: a new hooks install / hooks uninstall CLI surface, a hidden _hook runtime invoked by Claude Code and Codex on every hook event, audit-mode policy evaluation for npm-ecosystem package-manager activity, telemetry upload to /v1/{customer}/ai-agents/events, secret/MCP/npm enrichment, an atomic config-editing layer for JSON and TOML, and end-to-end smoke + stress tests. The hot path bypasses cli.Parse and logger setup in main to honor the fail-open contract (exit 0 on every error path).

Changes:

  • New internal/aiagents/... tree covering adapters (claudecode, codex), policy/decision/bypass-detection, ingest gate + HTTP client, identity/redaction/enrichment, atomic file writes, hook runtime, and a cli subpackage for install/uninstall/hook entry points.
  • New hooks subcommand parsed by internal/cli with narrow flag surface; _hook is intercepted in main before any setup.
  • Dependencies added: google/shlex, pelletier/go-toml/v2, tidwall/gjson, tidwall/sjson, tidwall/pretty, tidwall/match.

Reviewed changes

Copilot reviewed 75 out of 76 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cmd/stepsecurity-dev-machine-guard/main.go Adds _hook early-return and wires hooks install/uninstall commands.
internal/cli/cli.go, cli_test.go New parseHooks sub-parser with --agent flag and dedicated help; rejects global flags.
internal/aiagents/adapter/{adapter.go,adapter_test.go} Defines the per-agent Adapter contract and shared result types.
internal/aiagents/adapter/claudecode/{adapter,hooks,parse}.go Claude Code adapter: install/uninstall against ~/.claude/settings.json, hook-event mapping, payload parse + redaction.
internal/aiagents/adapter/codex/{adapter,hooks,parse}.go Codex adapter: hooks.json + config.toml install with feature-flag patching, payload parse.
internal/aiagents/atomicfile/atomicfile.go Atomic write + rotated .dmg-*.bak backups, mkdirAll tracking.
internal/aiagents/cli/{hook,install,uninstall,detect,rootuser,selfpath,errlog}.go and tests Hook runtime entry, install/uninstall handlers, console-user resolution, chown sweep, self-path canonicalization, JSONL error log.
internal/aiagents/cli/{smoke_test,stress_test}.go E2E install→invoke→uninstall and concurrent-invocation stress.
internal/aiagents/configedit/{json,toml}.go and tests Byte-preserving JSON edits via gjson/sjson and TOML [features].codex_hooks patcher with string-mask scanner.
internal/aiagents/enrich/npm/{detect,enrich,registry}.go and tests npm/pnpm/yarn/bun command classification, registry resolution (incl. yarn berry), config-source listing.
internal/aiagents/enrich/mcp/classify.go and test MCP signal classification from shell commands with redacted snippet.
internal/aiagents/enrich/secrets/{rules,scanner}.go and test In-process transcript secret scanner with dedup-by-fingerprint and bounded reads.
internal/aiagents/hook/{stdin.go,codex_test.go} Bounded stdin reader and codex-runtime allow-path tests.
internal/aiagents/identity/identity.go and test 1s-bounded device-identity probe wrapping internal/device.Gather.
internal/aiagents/ingest/{config,client}.go and tests Stricter enterprise-config gate (rejects {{...}} placeholders, env overrides) and JSON-array POST client with success on 200/201/202/409.
internal/aiagents/policy/{bypass,decision,ecosystem,eval,policy}.go and tests, builtin/policy.json Ecosystem-keyed audit policy with embedded default; pure evaluator covering install/config_set/config_delete/config_edit; bypass-detection shell parser.
internal/aiagents/doc.go Package-level docs for the domain root.
go.mod, go.sum New direct and indirect dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ashishkurmi ashishkurmi merged commit 33b752f into step-security:main May 13, 2026
5 checks passed
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.

3 participants