Skip to content

code-yeongyu/pi-apply-patch

Repository files navigation

pi-apply-patch

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.

Behavior

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

Tool

apply_patch

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.

Installation

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

After installation, restart pi or run /reload inside an interactive session.

Development

npm install
npm test
npm run typecheck
npm run check
npm pack --dry-run
pi -e ./src/index.ts

The test suite uses vitest. TypeScript is strict, Node-only, and uses ESM imports with .js suffixes.

Origin

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.

License

MIT.

Acknowledgements

  • Mario Zechner (@badlogic) — author of pi-mono and the pi-coding-agent extension API this package targets.
  • OpenAI Codex — reference apply_patch tool grammar and patch language.

About

Codex-style apply_patch tool extension for pi

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors