Share a global AGENTS.md #9
Labels
No labels
dependencies
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
alex/pi-shared#9
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
At the moment I just drop
~/.pi/agents/AGENTS.mdlocally with some simple instructions:Analyze the Pi extensibility and figure out how we can do this just installing this very repo as we do now (
pi install git:forge.l3x.in/alex/pi-shared) and remove the need for the~/.piagents file./pi work on it in a new PR
Now I understand the Pi extensibility model. Let me verify the global context-file loading path to confirm my approach:I have a clear understanding now. Let me summarize my findings before implementing:
Key finding: Pi packages can only declare
extensions,skills,prompts, andthemesin their manifest — there is no mechanism for a package to ship a global context file (AGENTS.md). GlobalAGENTS.mdfiles are loaded only from the global agent dir (~/.pi/agent/AGENTS.md) or project ancestors.The solution is an extension that injects the rules into the system prompt via the
before_agent_startevent — exactly the pattern used by pi's ownclaude-rules.tsexample. Since thepimanifest already declares"extensions": ["./extensions"], a new extension file is auto-discovered onpi install.Let me build it:Now let me typecheck the extension against the installed pi types and validate the runtime resolution logic:Typecheck passes. Now let me verify the path-resolution logic actually points at the file (the extension is at
<root>/extensions/global-agents.ts, so twodirnamecalls should yield the package root):Path resolution works correctly. Now let me confirm the new extension is auto-discovered by the existingpimanifest ("extensions": ["./extensions"]loads all.tsfiles), and check there are no other references that need updating:The new extension is auto-discovered by the existing manifest. Let me do a final runtime sanity check by loading the extension through jiti (the exact loader pi uses) and invoking its handlers:The extension works end-to-end under pi's actual jiti loader — both events register and the global instructions are correctly appended to the system prompt. Now let me document it in the README:Let me do a final review of all changes and make sure nothing stray is left behind:Everything is clean (node_modules/is correctly ignored). Let me create the pull request:This is a Forgejo instance (public athttps://forge.l3x.in) where the default branch ismaster, notmain. My override ofbase: "main"caused the 404. Let me retry with the correct base branch:The PR tool isn't compatible with this Forgejo instance's API. Let me create the branch, commit, push, and open the PR via the Forgejo REST API directly. First, let me verify connectivity and git identity:API works with the token. Let me set git identity, create a branch, commit, and push:Branch pushed. Now let me create the pull request via the Forgejo REST API:PR #10 created successfully: #10Summary
I analyzed Pi's extensibility model and implemented a way to ship global
AGENTS.mdrules with the package itself, eliminating the manual~/.pi/agent/AGENTS.mdfile.The finding
Pi packages can declare
extensions,skills,prompts, andthemes— but not a global context file. GlobalAGENTS.mdfiles are loaded only from the global agent dir (~/.pi/agent/AGENTS.md) or project ancestors (inloadProjectContextFiles), andresources_discoverhas no return value for context files. So there's no native "ship a global AGENTS.md" manifest key.The solution
A new
global-agentsextension (extensions/global-agents.ts) that injectsagents/AGENTS.mdinto every session's system prompt via thebefore_agent_starthook — the exact pattern pi's ownexamples/extensions/claude-rules.tsuses. It:agents/AGENTS.mdrelative to itself viaimport.meta.url,session_startso/newand/reloadpick up edits,<global_context>block that mirrors pi's<project_context>context-file format.It auto-loads because the existing manifest already declares
"extensions": ["./extensions"]— nopackage.jsonchange needed.Verified
tsc --strictagainst the installed pi types passes.before_agent_startcorrectly appends the rules block.Note: the built-in PR tool returned 404 (this repo runs on Forgejo with default branch
master), so I created the branch, pushed, and opened the PR via the Forgejo REST API.View action run | Model: zai/glm-5.2 (thinking: xhigh) | Time: 10m 13s | Tokens: 1.9M | Pi SDK v0.80.2 | Action v2.24.0-develop (develop @ 268c2eb)