Repository navigation
Apply nested Claude agent spawn rules (T181) - #89
Merged
Merged
Conversation
This was referenced Oct 9, 2026
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.
Closes #62
Sage task T181
What changes
Sage applies the brief and capacity checks to nested Claude agents. Only the main session starts a lead. A lead can start an implementer, code reviewer, security reviewer, UX reviewer or QA agent. Other agents cannot start agents.
The hook allows at most three leads per project and three children per lead. Leads and children also consume the project cap and the existing total fuse. The lower limit wins. As before, the native event folder selects the project through
projectName; the three-child limit follows the caller across folders. Task-bound project authority belongs to later steps. The main session keeps its existing direct specialist spawns and refusal texts.A reservation records the exact session, caller and tool call. The hook uses the documented structured Agent result to bind the child ID. It does not infer parent ownership from start order. Missing or ambiguous results keep capacity charged. A requested TaskStop does not count as confirmed completion for new lead or child slots.
The existing shared-core role policy already describes the lead/team limits. This PR connects those rules to Claude's native hook events and capacity lifecycle. It does not change the state tool, add the lead agent file or grant leads state-write permissions; those are later T181 steps.
Scope and coordination
Sources change in
packages/sage-claude/hooks/, with tests inscripts/sage-hook.test.mjsand one README rules row.npm run buildproduces the committed plugin files. Claude-owned issues #64–#68 remain separate.Slot mutations share a short filesystem lock. A failed lock acquisition refuses new admission and retains held capacity. The hook never steals a lock based only on age or probes a process list.
Validation
All commands ran on
b26a811d25f976846b35703b651b8327a61878abwith fake process tools first on PATH,env -u NODE_TEST_CONTEXT, andcaffeinate -i.npm run buildbuilt 212 filesnpm run checkall checks passtests 21; pass 21; fail 0; skipped 0npm testtests 718; pass 718; fail 0; cancelled 0; skipped 0git diff --checkFor regression proof,
git worktree add --detach <temporary-directory> origin/mainselected5431a74. Only the exact final test file was copied to that checkout.node --test --test-name-pattern='T181:' scripts/sage-hook.test.mjsended withtests 12; pass 0; fail 12; skipped 0. Every group failed withERR_ASSERTION; none failed from a missing fixture or module. The copied file matches the branch exactly, and the pre-existing main tests remain an unchanged byte prefix.The compatibility controls also reproduced the upgrade defect on the preceding implementation before repair. Tests use the actual five-marker pending layout emitted by main. Complete old reservations receive an opaque internal identity; incomplete records gain no authority. Replay cases cover own stop, parent cleanup, bound and unbound lease expiry, and a new result that tries to claim an old child ID.
Every test run puts fake
ps,pgrepandkillfirst on PATH. Fixtures send JSON to the hook; they do not launch real agents or execute attack strings in a shell. Existing test assertions remain unchanged.Review
First clean cycle on
b26a811:Second clean cycle on the same
b26a811commit:Both code/security and QA cycles are clean on the exact final commit.
Earlier review findings were repaired on this branch. Earlier failed cycles do not count.
Limits and not verified
GitHub CI
CI run 37864046630 passed on the exact reviewed commit
b26a811d25f976846b35703b651b8327a61878ab.