feat: support Pi Coding Agent as a presence source#40
Open
PerfectPan wants to merge 1 commit into
Open
Conversation
Add an `@earendil-works/pi-coding-agent` extension at ~/.pi/agent/extensions/agent-presence.ts that bridges Pi lifecycle events into the existing presence state/render/provider pipeline: - before_agent_start -> SessionStart (active gates on user prompt, not on opening pi) - turn_start / tool_execution_* -> Heartbeat - agent_end / session_shutdown -> Stop (synchronous spawn so quick pi -p runs don't leak state) `agent-presence setup` installs the managed extension; install/uninstall preserve user-owned Pi extensions and other Pi settings. Adds the `pi` source to the hook router so renders show `pi N` next to other sources. Tests cover hook context parsing, lifecycle transitions, render grouping, extension source generation, settings merge, and full install/uninstall filesystem behavior with a tmp HOME.
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.
Summary
@earendil-works/pi-coding-agentas a first-class presence source. A managed extension at~/.pi/agent/extensions/agent-presence.tsbridges Pi's lifecycle events (before_agent_start,turn_start,tool_execution_*,agent_end,session_shutdown) into the existing CLI hook → state → render → provider pipeline.before_agent_start, notsession_start, so an idle Pi TUI is never counted; Stop events go throughspawnSyncso quickpi -pruns don't leak state.setupinstalls the extension;uninstallremoves only the managed file and only its own entry insettings.json#/extensions, leaving user-owned Pi extensions and other settings untouched.pi Nalongsidecodex / claude / gemini / opencode.Files
src/hooks/pi.ts,scripts/install-pi-extension.ts,scripts/uninstall-pi-extension.ts,test/pi-extension-install.test.ts,.changeset/pi-coding-agent-support.md.src/cli/hook-context.ts,src/installers.ts(extension source builder + idempotent install/uninstall coordination),src/setup.ts(script order),package.json(install/uninstall:pi-extension scripts; fills the missinginstall:gemini-hookininstall:all-hooks),README.md,README.zh-CN.md,docs/architecture.md,skills/agent-presence/SKILL.md, and the existing hooks/installers/setup tests.Test plan
pnpm install --frozen-lockfile --ignore-scriptspnpm test— 15 test files / 114 tests passed (covers pi hook context, lifecycle transitions, render grouping withpi 1, extension source string contents, settings.json merge, tmp-HOME install/uninstall idempotency, refusal to overwrite a non-managed file)pnpm run typecheckpnpm run buildpnpm pack --dry-runagent-presence setup --provider feishu-signature --skip-login --hook-command absolute— extension written with marker, user's other Pi extension preservedpi --provider zai --model glm-5.1 -p "Reply with exactly: pi-ok"returnedpi-ok(exit 0)statusshowed"value": "1 个 AI 牛马正在搬砖 | pi 1"withactive[0].source = "pi"against the real Pi session id; activeCount returned to 0 after Pi exited (no residual state)status --remotematched local; remote slot updated through the existing l.garyyang provider, no Pi-specific provider pathresult=rate-limitedfollowed by a successful retry); Pi's own GLM call was unaffectedZAI_API_KEYenv-var name appears in docs; no real key, noglm.txtpath, nobyted/bnpm/private-tokenleaks; nodist/node_modulestrackedFollow-up risk
-pmode can stall when stdin is wired to a long-lived pipe (observed when invoking pi from another agent CLI's sandbox). The fix in that case ispi … -p "…" </dev/null; normal terminal use is unaffected. The extension itself is unchanged either way — oncebefore_agent_startfires the integration runs end-to-end.