Skip to content

feat(rules): let Pi rules emit AGENTS.override.md - #2627

Merged
dyoshikawa merged 2 commits into
mainfrom
resolve-issue-2601-pi-agents-override
Aug 7, 2026
Merged

feat(rules): let Pi rules emit AGENTS.override.md#2627
dyoshikawa merged 2 commits into
mainfrom
resolve-issue-2601-pi-agents-override

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

Gap 2: AGENTS.override.md is now emittable

Verified upstream first: loadContextFileFromDir in packages/coding-agent/src/core/resource-loader.ts tries ["AGENTS.override.md", "AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"] and returns the first hit, and loadProjectContextFiles runs it over the global agent dir as well as the project ancestors — so the override wins deterministically at both scopes. (The doc line is packages/coding-agent/docs/usage.md ~106; the issue's docs/usage.md path is stale.)

A root: true rule opts in with pi.contextFile: override. Because Pi folds every rule body into the single root context file, the root rule decides for the whole Pi output: the flag is copied onto non-root rules, and setting it only on a non-root rule is ignored with a warning — emitting both files would leave everything in AGENTS.md unread by Pi. AGENTS.override.md is Pi-exclusive, so it round-trips through import and is cleaned up when the flag is toggled off, while the shared AGENTS.md is never deleted on Pi's behalf.

Gap 1: closing as not-a-bug

The premise does not hold. The stopagent_end mapping was made on 2026-07-19, ten days after agent_settled and its recommendation text already existed upstream (commit e9fa5a68, 2026-07-09), so it was not made in ignorance of the alternative. src/types/hooks.ts:1146-1152 records it as a deliberate trade-off: agent_settled would skip queued follow-ups instead, which is a pure trade-off rather than a strict improvement, so it is intentionally unmapped. Changing it would be a canonical-semantics design decision, not a bug fix.

With gap 2 implemented and gap 1 resolved as intended behavior, this issue is complete.

Closes #2601

🤖 Generated with Claude Code

Pi tries AGENTS.override.md before AGENTS.md and CLAUDE.md in every directory it scans, so it is the only way to make Rulesync's output deterministically win next to a sibling context file. The root rule opts in with pi.contextFile: override and decides for the whole Pi output; the flag on a non-root rule alone is ignored with a warning, because a split across both files would leave everything in AGENTS.md unread.
With pi.contextFile: override the target no longer writes ./AGENTS.md, so the orphan sweep removed the copy agentsmd, codexcli or warp had just written (the root-file ownership map only arbitrates --check). That path is never Pi-exclusive, so PiRule now refuses to delete it; the global ~/.pi/agent/AGENTS.md still is. Also align the flag across every targeted rule rather than only the non-root ones, so a second root rule cannot be left in the file Pi stops reading, and skip rules targeting other tools.
@dyoshikawa
dyoshikawa merged commit 85c0da1 into main Aug 7, 2026
9 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-2601-pi-agents-override branch August 7, 2026 21:07
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.

Follow up Pi Coding Agent upstream updates: stop hook should map to agent_settled, AGENTS.override.md not emittable

2 participants