Skip to content

feat(plugin): expose agent identity and parentAgent in plugin hooks for governance#14806

Closed
ArmirKS wants to merge 4 commits intoanomalyco:devfrom
ArmirKS:contractops/local-patches-v2
Closed

feat(plugin): expose agent identity and parentAgent in plugin hooks for governance#14806
ArmirKS wants to merge 4 commits intoanomalyco:devfrom
ArmirKS:contractops/local-patches-v2

Conversation

@ArmirKS
Copy link
Copy Markdown

@ArmirKS ArmirKS commented Feb 23, 2026

Summary

  • Expose agent and parentAgent fields in tool.execute.before, tool.execute.after, and shell.env plugin hooks, enabling governance plugins (e.g. ContractOps) to enforce per-agent policies
  • Centralize duplicated Plugin.trigger calls into a new Tool.invoke() helper, fixing a bug where batch.ts sub-tools never fired plugin hooks
  • Add status field to tool.execute.after hook for distinguishing success from error

Test plan

  • 4 new test files with 30+ tests covering agent identity threading, parentAgent delegation, batch hook firing, and Tool.invoke behavior

Add agent to tool.execute.before, tool.execute.after, and shell.env
plugin hooks. This is a local-only patch for ContractOps governance.
5 tests covering:
- shell.env hook receives agent string
- tool.execute.before hook receives agent string
- tool.execute.after hook receives agent string
- shell.env handles undefined agent (PTY case)
- bash tool end-to-end agent threading

Validates patch f7aa1dacf exposes agent identity correctly.
…cking

Adds parentAgent? to tool.execute.before, tool.execute.after, and shell.env hooks.
When agent A spawns agent B via the task tool, hooks now receive:
  agent='B', parentAgent='A'
Top-level agents have parentAgent=undefined.

Threaded through: PromptInput, MessageV2.User, Tool.Context, ShellInput,
Pty.CreateInput, task.ts, and all 10 Plugin.trigger call sites.

10 tests pass (18 expect() calls) covering agent + parentAgent.
Removes ~50 lines of duplicated Plugin.trigger calls from 3 sites in
prompt.ts by extracting Tool.invoke() in tool.ts. Fixes a bug where
batch.ts sub-tools never fired plugin hooks. Adds status field to
tool.execute.after hook type for distinguishing success from error.
@github-actions github-actions bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Feb 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@ArmirKS ArmirKS closed this Feb 23, 2026
@ArmirKS ArmirKS deleted the contractops/local-patches-v2 branch February 23, 2026 17:31
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potentially related PR:

centralize tool plugin hooks + add agent to hook input (PR #13521)

This PR appears to be directly related - it mentions centralizing tool plugin hooks and adding agent information to hook inputs, which aligns with your PR's goal of exposing agent identity in plugin hooks and centralizing duplicated Plugin.trigger calls into a Tool.invoke() helper.

The other matches (PR #8315 and #10043) are about analytics metrics and general plugin hook tests but don't appear to be duplicates of the specific governance-focused changes in PR #14806.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant