Skip to content

Conversation

@malhashemi
Copy link
Contributor

@malhashemi malhashemi commented Jan 7, 2026

Summary

Small cleanup to align the task tool's filtering approach with how skill.ts handles it, plus simplification of the userInvokedAgents mechanism.

Self-contained filtering:

Simplify bypass logic:

  • Replace userInvokedAgents array with bypassAgentCheck boolean
  • Only check the current turn's user message (not all messages in session)
  • Prevents bypass from persisting across the entire session

Test cleanup:

  • Remove redundant filterSubagents tests (already covered by PermissionNext.evaluate tests)

Changes

  • task.ts: Filter during description generation + simplify permission check
  • prompt.ts: Remove regeneration block + use bypassAgentCheck boolean
  • test: Remove redundant tests (~130 lines)

No functional changes to permission behavior - just cleaner code!

Move subagent filtering logic from prompt.ts into task.ts, following
the same pattern used by skill.ts. This makes the task tool self-contained
and removes coupling between files.

Changes:
- task.ts: Filter agents using ctx?.agent permissions during description generation
- prompt.ts: Remove regeneration block and imports (TASK_DESCRIPTION, filterSubagents)
- test: Define filterSubagents helper locally instead of importing

No functional changes - just cleaner architecture.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

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

No duplicate PRs found

@malhashemi
Copy link
Contributor Author

@rekram1-node Just tidying up, no functionality changes, just moved the filtration logic to task took to be self contained.

The filterSubagents tests were testing a local helper function that
mirrored the production code. The PermissionNext.evaluate tests already
cover the same logic, making these tests redundant.

- Remove filterSubagents helper and its test block (~130 lines)
- Update integration tests to use PermissionNext.evaluate directly
- All test coverage preserved through existing evaluate tests
Replace the userInvokedAgents array with a simple boolean that only
checks the current turn's user message. This prevents the bypass from
persisting across the entire session.

- Check only last user message instead of all messages
- Simplify task.ts permission check to just use bypassAgentCheck
- Command subtasks continue to use bypassAgentCheck: true
@malhashemi
Copy link
Contributor Author

malhashemi commented Jan 7, 2026

Hey! Looked into simplifying userInvokedAgentsbypassAgentCheck.

The tricky part was that the old code looked at ALL user messages in the session, so once you @ invoked any agent, the bypass would persist for the entire session - even for subsequent turns where you didn't @ invoke anything. And with using bypassAgentCheck the primary agent can literally invoke any subagent for the reset of the session once you invoke it once.

Fixed it by only checking the last user message (current turn):

// Before: checks all messages (persists across session)
const userInvokedAgents = msgs
  .filter((m) => m.info.role === "user")
  .flatMap((m) => m.parts.filter((p) => p.type === "agent"))
  .map((p) => p.name)

// After: checks only current turn
const lastUserMsg = msgs.findLast((m) => m.info.role === "user")
const bypassAgentCheck = lastUserMsg?.parts.some((p) => p.type === "agent") ?? false

This way:

  • Turn 1: @plan do X → bypasses ✅
  • Turn 2: "call plan again" (no @) → prompts as expected ✅

Also cleaned up the redundant filterSubagents tests - the PermissionNext.evaluate tests already cover similar logic.

@rekram1-node
Copy link
Collaborator

/review

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

lgtm

@rekram1-node rekram1-node merged commit 34c9d10 into anomalyco:dev Jan 7, 2026
2 checks passed
@malhashemi malhashemi deleted the refactor/task-tool-self-contained-filtering branch January 7, 2026 20:00
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.

2 participants