Skip to content

feat: support Pi Coding Agent as a presence source#40

Open
PerfectPan wants to merge 1 commit into
mainfrom
feat/pi-coding-agent
Open

feat: support Pi Coding Agent as a presence source#40
PerfectPan wants to merge 1 commit into
mainfrom
feat/pi-coding-agent

Conversation

@PerfectPan
Copy link
Copy Markdown
Owner

Summary

  • Add @earendil-works/pi-coding-agent as a first-class presence source. A managed extension at ~/.pi/agent/extensions/agent-presence.ts bridges Pi's lifecycle events (before_agent_start, turn_start, tool_execution_*, agent_end, session_shutdown) into the existing CLI hook → state → render → provider pipeline.
  • Active state gates on before_agent_start, not session_start, so an idle Pi TUI is never counted; Stop events go through spawnSync so quick pi -p runs don't leak state.
  • setup installs the extension; uninstall removes only the managed file and only its own entry in settings.json#/extensions, leaving user-owned Pi extensions and other settings untouched.
  • Render output gains pi N alongside codex / claude / gemini / opencode.

Files

  • New: 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.
  • Updated: 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 missing install:gemini-hook in install: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-scripts
  • pnpm test — 15 test files / 114 tests passed (covers pi hook context, lifecycle transitions, render grouping with pi 1, extension source string contents, settings.json merge, tmp-HOME install/uninstall idempotency, refusal to overwrite a non-managed file)
  • pnpm run typecheck
  • pnpm run build
  • pnpm pack --dry-run
  • agent-presence setup --provider feishu-signature --skip-login --hook-command absolute — extension written with marker, user's other Pi extension preserved
  • Real pi --provider zai --model glm-5.1 -p "Reply with exactly: pi-ok" returned pi-ok (exit 0)
  • Mid-run local status showed "value": "1 个 AI 牛马正在搬砖 | pi 1" with active[0].source = "pi" against the real Pi session id; activeCount returned to 0 after Pi exited (no residual state)
  • status --remote matched local; remote slot updated through the existing l.garyyang provider, no Pi-specific provider path
  • Provider 429 rate-limit hits seen during sampling were absorbed by existing deferred-flush logic (result=rate-limited followed by a successful retry); Pi's own GLM call was unaffected
  • Hygiene scan: only ZAI_API_KEY env-var name appears in docs; no real key, no glm.txt path, no byted/bnpm/private-token leaks; no dist/node_modules tracked

Follow-up risk

  • Pi 0.75.5's -p mode 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 is pi … -p "…" </dev/null; normal terminal use is unaffected. The extension itself is unchanged either way — once before_agent_start fires the integration runs end-to-end.

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.
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.

1 participant