Codex-style apply_patch tool extension for the pi coding agent. It registers a freeform grammar patch tool for OpenAI GPT-family models and swaps out write / edit while those models are active.
The extension registers one LLM-callable tool: apply_patch. The tool accepts Codex patch envelopes and applies file additions, updates, deletions, and moves inside the current workspace.
| Case | Result |
|---|---|
| OpenAI GPT model active | replaces write and edit with apply_patch |
| Non-GPT model active | restores the original write and edit toolset |
| Raw freeform patch input | accepted and applied |
JSON { "input": "..." } patch input |
accepted and applied |
| Absolute or parent-escaping path | rejected |
Use this tool to edit files with the Codex patch format.
*** Begin Patch
*** Add File: hello.txt
+Hello world
*** Update File: src/app.py
@@ def greet():
-print("Hi")
+print("Hello, world!")
*** Delete File: obsolete.txt
*** End Patch
The OpenAI Responses API receives this as a custom freeform grammar tool, not as a JSON function tool.
The package targets the pi coding agent. Pi loads extensions from ~/.pi/agent/extensions/, project .pi/extensions/, or via the --extension / -e CLI flag.
# 1. From npm (once published)
pi install npm:@code-yeongyu/pi-apply-patch
# 2. From git
pi install git:github.com/code-yeongyu/pi-apply-patch
# 3. Manual placement
git clone https://github.com/code-yeongyu/pi-apply-patch ~/.pi/agent/extensions/pi-apply-patch
cd ~/.pi/agent/extensions/pi-apply-patch && npm install
# 4. Dev / one-shot test
pi -e /path/to/pi-apply-patch/src/index.tsAfter installation, restart pi or run /reload inside an interactive session.
npm install
npm test
npm run typecheck
npm run check
npm pack --dry-run
pi -e ./src/index.tsThe test suite uses vitest. TypeScript is strict, Node-only, and uses ESM imports with .js suffixes.
Ported from packages/coding-agent/src/core/extensions/builtin/gpt-apply-patch.ts in code-yeongyu/senpi-mono. The patch grammar and tool descriptions mirror Codex.
MIT.