feat(pi): ctx setup pi - Pi coding-agent CLI integration - #161
Conversation
PI.1 of specs/pi-cli-integration.md: the thin shim extension (the .pi/extensions/ctx.ts deploy source) wiring Pi lifecycle events to ctx system subcommands - hook-JSON envelope on piped stdin, isError gating, session_start warm-up cache, branch-scan context re-injection after compaction - plus the 10-skill bundled set copied from the OpenCode integration (frontmatter conforms to the Agent Skills standard; no harness-specific content inside the skills). Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
PI.2-PI.4 of specs/pi-cli-integration.md: the ctx setup pi surface. internal/cli/setup/core/pi implements the deploy contract mirroring the OpenCode integration (extension fatal, AGENTS.md + skills warn; validateManagedTarget refuses symlink and non-regular targets; refresh- in-place on drift): - PI.2: PiExtension/PiSkills accessors (internal/assets/read/agent/pi.go), config/hook pi path constants (.pi/extensions/ctx.ts, .pi/skills), asset.go directory constants, embed.go directives. - PI.3: core/pi package - pi.go Deploy (extension, AGENTS.md, skills, summary), extension.go, skill.go, validate.go, plus the deploy test suite (refresh, symlink refusal, non-regular target refusal; windows-skipped where needed). - PI.4: case cfgHook.ToolPi in setup root Run() - dry-run prints the hook.pi blueprint, --write deploys; hooks.yaml hook.pi + supported-tools entry, write.yaml write.hook-pi-created/skipped/summary, config/embed/text DescKeys, write/setup InfoPi* (TestDescKeyYAMLLinkage green; no new Use* constant, no new subcommand). Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
PI.5 of specs/pi-cli-integration.md: pi entries in the supported-tools reference (operations/integrations.md + cli/setup.md), a pi quickstart (docs/home/pi.md, registered in zensical.toml nav), and the multi-tool-setup recipe. site/ HTML rebuild is deferred: this machine's zensical 0.0.51 venv renders entity-escape drift (120 files, &ActiveMemory#39; vs literal ') against the committed artifacts - unpinned zensical transitive deps make the build non-reproducible off the canonical toolchain. Rebuild on the canonical machine and stage site/ with a follow-up commit. Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
PI.7 of specs/pi-cli-integration.md: tools/typecheck/pi/ (tsconfig strict noEmit over the embedded ctx.ts, devDeps on @earendil-works/pi-coding-agent types + @types/node + typescript, committed lockfile, README) and the typecheck-pi-extension CI job mirroring typecheck-opencode-plugin. Verified locally: tsc --noEmit passes against pi-coding-agent 0.84.2. Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
Validation summary: go build + golangci-lint clean; full-suite delta vs clean main shows zero new failures (all failing packages pre-exist on this Windows machine: CRLF render drift, .exe exec, audit path exemptions). Scratch project verified: init, dry-run, --write, idempotent re-run, tamper refresh (byte-identical to embedded source), unknown-tool listing. Live pi: extension loads clean (A/B run with and without .pi identical); LLM round-trip blocked by local pi provider config - left for a working-provider machine. Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
… rebuild drift) Both surfaced during the pi integration: the Windows schannel/openssl git TLS quirk and the non-reproducible zensical site rebuild (escape- churn detection procedure). Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
…naming Independent review (approve-with-nits) follow-ups: - setup root package doc: add opencode + pi to the tool list (spec 'Files to create' required the docstring update) - TestSkillFrontmatter: add the pi skill tree so the Agent Skills frontmatter contract is validated for the pi set - new deploy tests: fresh-project full deploy (all 12 files, byte-identical to embedded; AGENTS.md marker) and deterministic skill ordering (deploy output sequence must be lexicographic) - spec: FilePiExtension -> FilePiExtensionDeploy (matches the shipped constant; the FileOpenCodePluginDeploy convention) - read/agent/pi.go: document the deliberate file-split deviation from agent.go's layout Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
fable-5 effort-max branch audit (0 blocker, 1 major, 4 minor, 3 nit): - MAJOR 1: needsContextInjection scanned only branch entries after the last compaction, missing ctx packets that survive into the kept tail (a custom_message is a valid cut point, kept within keepRecentTokens) and causing the duplicate injection the spec explicitly rules out. Now scans sessionManager.buildContextEntries() - the compaction-aware live context (summary + kept tail + post-compaction entries); strictly smaller function, delivers the spec's no-duplicate guarantee. Spec updated to match (event map row, compaction interop paragraph, files-to-create comment). - MINOR 2: child.stdin now swallows async 'error' emissions (EPIPE when the child exits before the write flushes, destroyed-stream writes on a failed spawn) so they cannot escape Pi's handler stack; spawn/exec failures still surface via the execFile callback. - TASKS.md PI.8: follow-up for the remaining minor/nit findings (post- compaction inline re-warm, EOL pinning for embedded assets, unused tool_result nudge channel, tsconfig paths hardening). Audit NIT 6 (summary omits persistence behavior) was a false positive - all five behaviors are listed in write.hook-pi-summary. Verified: tsc --noEmit (strict, pi-coding-agent 0.84.2 types), go build, pi deploy suite + assets/read/skill green; remaining suite failures are pre-existing on clean main. Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
|
@bilersan looks good; give some fresh cookies to your minions. Some nits: Minor
Nit
|
Brings the Codex integration (ActiveMemory#163), the hook robustness sweep, and the dependabot bumps under the Pi branch. Every conflict was a shared insertion point where both branches add a tool: the setup dispatch imports and docstring, the write/setup Info* helpers, the skill frontmatter test comment, the setup docs table and examples, and the TASKS/LEARNINGS context files. Both sides kept; Pi placed after Codex so the branch diff against main stays a pure addition. Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
…r guard Maintainer nits on PR ActiveMemory#161 (2026-09-05): - docs: the re-injection predicate in the Pi quickstart and the integrations reference now describes the live-context scan that 694f6d3 shipped (summary + kept tail + post-compaction entries) instead of the retired "after the most recent compaction" rule - spec: soften the latency claim; the first prompt normally injects from cache, and a cache miss (first prompt outrunning the warm-up, or the first prompt after session_compact drops the cache) runs the fetch on the prompt path, bounded by the 15s subprocess timeout - skills: "plugin hook" -> "tool integration" in ctx-agent, in both the Pi and OpenCode trees (Pi has extensions, not plugins) - test: TestPiSkillsMirrorOpenCode freezes the intentionally identical Pi/OpenCode skill trees byte-for-byte - typecheck: pin @earendil-works/pi-coding-agent to exactly 0.84.2 in package.json and the lockfile root so a lockfile regeneration cannot float the gate Independent review findings folded in: - DECISIONS.md records the three Pi design choices the spec cites as decided 2026-08-23 (display:true, live-context predicate, flat single-file extension) - flag-era wording ("flag loss can only cause an extra injection") replaced in the spec and the extension header: only the packet cache lives in extension memory; the injection decision is derived from live session state - spec: tests bullet names the real guards; line-count estimate dropped. Quickstart: compaction sentence made conditional. README: integrations row lists Pi - tasks: PI.9 records this round; PI.1 wording updated; PI.8 gains (a) cache-the-promise note and (e) shared deploy helper for the pi/opencode twins - learnings: golangci-lint exits 7 with 0 issues while tools/typecheck/*/node_modules exists on this machine - chore (bundled): refresh go.work.sum with the grpc v1.83.1 sums the go 1.26.3 workspace load adds after main's 1.83.2 bump; a clean upstream/main build leaves the same two-line drift Spec: specs/pi-cli-integration.md Signed-off-by: Ersan Bilik <ersanbilik@gmail.com>
|
Thanks for the read. Two commits since your comment:
Also folded in from an independent review pass: three One bundled chore: Still pending: the live Pi round-trip (spec verification step 3) needs a machine with a working Pi provider; PI.6 records the block. Locally on Windows the full suite shows the same 28 pre-existing failing packages as clean |
feat(pi): ctx setup pi — Pi coding-agent CLI integration
New AI-tool integration:
ctx setup pi [--write]for the Pi coding-agent CLI(earendil-works/pi, pi.dev). Pi has no built-in MCP by design, so the
integration is a thin TypeScript extension + Agent-Skills-standard skills +
AGENTS.md; all logic stays in the ctx binary viactx systemsubcommands.Spec:
specs/pi-cli-integration.md(committed on-branch).What ships
internal/assets/integrations/pi/extension/ctx.ts:flat
.pi/extensions/ctx.tsshim wiring Pi lifecycle events toctx system:session_start: warm-upctx agent --budget 4000off the prompt pathbefore_agent_start: injects the packet as a persistentcustomType: "ctx-context"message (display: true) only when no ctxmessage exists in the live context — compaction-aware scan of
sessionManager.buildContextEntries()(summary + kept tail +post-compaction entries), so kept-tail packets suppress re-injection and
folded-away packets trigger it; fail-safe across
/new/resume/fork/reloadtool_result(bash,git commitregex,!isError):ctx system post-commitwith the hook-JSON envelope on piped+closed stdin (
node:child_processis mandatory — Pi's exec helper hardcodes
stdio: ["ignore","pipe","pipe"])tool_result(edit/write,!isError):check-task-completion;agent_settled:check-persistence;session_compact: cache dropctx setup pi— deploy core (internal/cli/setup/core/pi/) mirroringthe OpenCode integration: extension fatal,
AGENTS.md+ 10 bundled skillswarn; refresh-in-place, symlink/non-regular refusal; dry-run prints the
hook.piblueprint;case cfgHook.ToolPiin setup root (no newsubcommand, no new
Use*constant)tools/typecheck/pi/(stricttsc --noEmitagainst@earendil-works/pi-coding-agent@0.84.2types, committed lockfile) +typecheck-pi-extensionjob in.github/workflows/ci.ymldocs/home/pi.mdquickstart, multi-tool recipe, zensical nav
Validation
go build ./...,golangci-lint(0 issues), targetedgo testgreenpre-exist on this Windows machine: CRLF render drift,
.exeexec, auditpath exemptions)
init+ dry-run +--write+ idempotent re-run +tamper-refresh (byte-identical to embedded)
.piidentical);full LLM round-trip blocked by local pi provider config — left for a
working-provider machine
tsc --noEmitpasses against pi-coding-agent 0.84.2 typesReviews
(
32c55041: docstring, frontmatter coverage, spec naming)claude -pfable-5 effort-max branch audit: ship-ready after onedecision — the one decision (kept-tail duplicate-injection gap, MAJOR 1)
resolved by switching the predicate to a
buildContextEntries()scan(
694f6d37, with a one-line stdin stream hardening)Notes / follow-ups
site/HTML rebuild deferred: this machine's zensical toolchain rendersentity-escape drift vs the committed artifacts; rebuild on the canonical
build machine (documented in PI.5 / commit
03a7e776)TASKS.mdPI.8 tracks the remaining low-priority audit follow-ups(post-compaction re-warm location, embedded-asset EOL pinning, unused
tool_resultnudge channel, tsconfig paths hardening)