Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

@0xkobold/pi-patch

patch-package clone for pi - fuzzy matching and agent integration

extensionfuzzy-matchmonkey-patchnode_modulespatchpatch-packagepi
Published6 Apr 2026
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

Pi Patch 🩹

A full patch-package clone for pi. Create and apply patches to node_modules packages with fuzzy matching support.

🎯 Goal: Drop-in replacement for patch-package that works inside pi with agent integration.


Quick Start

# 1. Edit a dependency
$EDITOR node_modules/express/index.js

# 2. Create patch (exactly like patch-package)
/patch-package express

# 3. Commit patches
git add .patches/
git commit -m "fix: patch express"

Patches auto-apply when pi starts.


Commands

CommandDescription
/patch-package <package>Create patch from modified package
/patch-packageCreate patches for ALL modified packages
/patch or /patch applyApply all patches
/patch dry-runTest patches without applying
/patch revertRevert all patches
/patch statusShow modified packages & patches

Agent Integration

The agent can use the patch_package tool to manage patches programmatically:

// Create patch for a specific package
{
  "action": "create",
  "package_name": "lodash"
}

// Create patches for all modified packages
{ "action": "create_all" }

// List modified packages
{ "action": "list_modified" }

// Apply patches
{ "action": "apply" }

// Dry run
{ "action": "dry_run" }

// Status check
{ "action": "status" }

How It Works

1. Modify Dependencies

# Edit files in node_modules/
ed node_modules/some-package/index.js
# Files are automatically backed up as .orig

2. Create Patches

# Single package
/patch-package some-package

# All modified
/patch-package

Patch naming: package-name+1.2.3.patch

3. Apply Patches

Patches apply automatically on pi startup, or manually:

/patch apply

Fuzzy matching: Uses git apply with 3-way support (like patch-package).


Installation

mkdir -p ~/.pi/agent/extensions/pi-patch
cp extension.ts ~/.pi/agent/extensions/pi-patch/

Project-local

mkdir -p .pi/extensions/pi-patch
cp extension.ts .pi/extensions/pi-patch/
ln -s $(pwd)/extension.ts ~/.pi/agent/extensions/pi-patch/index.ts

Comparison with patch-package

Featurepatch-packagepi-patch
Patch node_modules✅✅
Fuzzy matching✅ (git apply)✅ (git apply)
Auto-apply✅ (postinstall)✅ (pi startup)
Version in filename✅✅
Scoped packages (@x/y)✅✅
Dry run✅✅
Revert patches✅✅
Agent tool access❌✅
Patch pi internals❌✅

Drop-in compatible: Same workflow, same patch format.


Configuration

Create .patches/pi-patch.json:

{
  "autoApply": true,
  "allowFuzzy": true,
  "postinstall": false,
  "excludePackages": ["@types/node"]
}
OptionDescription
autoApplyApply patches on pi startup
allowFuzzyAllow git fuzzy matching (recommended)
excludePackagesSkip these packages

Patch Format

Standard unified diff (same as patch-package):

diff --git a/lodash b/lodash
# Package: lodash
--- a/lib/debounce.js
+++ b/lib/debounce.js
@@ -10,3 +10,4 @@
 function debounce() {
+  if (!func) return;
   setup();
 }

Troubleshooting

Patch fails to apply

# Check what would happen
/patch dry-run

# See detailed output
/patch status

File changed too much

If upstream changed significantly:

# 1. Revert patch
/patch revert

# 2. Update package
npm update some-package

# 3. Re-apply your changes
# 4. Create new patch
/patch-package some-package

"No modified packages found"

The extension uses .orig files to detect modifications. Make sure:

  • You actually edited files in node_modules/
  • .orig backups exist (created automatically on first edit)

To force detect changes:

# Manually back up before editing
cp node_modules/pkg/file.js node_modules/pkg/file.js.orig
# Now edit the file

Testing

bun test          # Run all tests
bun test --watch  # Watch mode

54 tests covering:

  • Patch creation with git diff
  • Fuzzy matching with git apply
  • Package detection in node_modules
  • Edge cases and error scenarios

Workflow Examples

Fix a Bug in Production

# Find the bug in node_modules/express/lib/router.js

# Back up and edit
cp node_modules/express/lib/router.js{,.orig}
$EDITOR node_modules/express/lib/router.js

# Create patch
/patch-package express

# Commit
git add .patches/
git commit -m "fix: express router bug"

# Next deploy: patches auto-apply

Maintain Private Fork

# Heavy customization of a package
# Edit many files in node_modules/my-fork/

# Create patches for all modifications
/patch-package

# Result: Multiple patches committed to repo
# Patches survive npm install

Agent-Driven Patching

You can ask the agent to create patches:

"The lodash merge function has a bug. Can you patch it?"

The agent will:

  1. Locate node_modules/lodash/merge.js
  2. Create a backup as .orig
  3. Apply the fix
  4. Run patch_package tool to create the patch
  5. Report the created patch file

Why Not Just Use patch-package?

  1. Agent Integration: pi-patch gives agents direct access to patch management
  2. Pi Internals: Can patch pi-coding-agent itself (extensions, core files)
  3. No npm Required: Works with bun, pnpm, or any package manager
  4. Unified Interface: One tool for dependencies and pi customization

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@sinclair/typebox
Environment
{
  "local_name": "@sinclair/typebox",
  "alias": false,
  "peer_metadata": null
}
^0.32.0runtime
@mariozechner/pi-coding-agent
Environment
{
  "local_name": "@mariozechner/pi-coding-agent",
  "alias": false,
  "peer_metadata": null
}
*peer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "967cd33175148470741f77e22df107007718c227",
  "tarball": "https://registry.npmjs.org/@0xkobold/pi-patch/-/pi-patch-1.0.0.tgz",
  "fileCount": 9,
  "integrity": "sha512-7cEy7wCoPF9GZXdlKFat0T1sciDHmtPDcYrsK49c+nJXgfW47mSJnFw966f1pQ+MmyXU4Q4et2emAitpOkxrxw==",
  "signatures": [
    {
      "sig": "MEUCIQDpb87jzUzXnMQGszBrhHd1f1q7DRQe2C2R9z7y/84PQwIgSn1AYKGmmBEugLJ6ICtZmuOmJYJ71MUjZ8l046ueNYc=",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 84307
}

Repository

PENDING
0xkobold/pi-patch

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 09:03 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:f2cae40c90ec8c6101f66d2c94bd1963bc6f72e1f8fb14249f0e38cbd5f9ea67

Other collected versions

0.1.06 AprView all collected versions →