{"_id":"@0xkobold/pi-patch","_rev":"2-851b4a3c1d09b6d5ae16246536110a13","name":"@0xkobold/pi-patch","dist-tags":{"latest":"0.1.0"},"versions":{"1.0.0":{"name":"@0xkobold/pi-patch","version":"1.0.0","keywords":["pi","extension","patch","patch-package","monkey-patch","fuzzy-match","node_modules"],"author":{"name":"0xKobold"},"license":"MIT","_id":"@0xkobold/pi-patch@1.0.0","maintainers":[{"name":"moikapy","email":"warrenckhan@gmail.com"}],"homepage":"https://github.com/0xKobold/pi-patch#readme","bugs":{"url":"https://github.com/0xKobold/pi-patch/issues"},"pi":{"name":"pi-patch","extensions":["./extension.ts"],"description":"Create patches from modified node_modules (patch-package clone)"},"dist":{"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},"main":"./extension.ts","type":"module","exports":{".":"./extension.ts"},"gitHead":"a3dc1631249089963df00a39f882f756f40fc9fc","scripts":{"test":"bun test","typecheck":"tsc --noEmit","test:watch":"bun test --watch","prepublishOnly":"bun typecheck && bun test"},"_npmUser":{"name":"moikapy","email":"warrenckhan@gmail.com"},"repository":{"url":"git+https://github.com/0xKobold/pi-patch.git","type":"git"},"_npmVersion":"9.2.0","description":"patch-package clone for pi - fuzzy matching and agent integration","directories":{},"_nodeVersion":"20.19.2","dependencies":{"@sinclair/typebox":"^0.32.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"@mariozechner/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-patch_1.0.0_1775452178429_0.0619945576443639","host":"s3://npm-registry-packages-npm-production"}},"0.1.0":{"name":"@0xkobold/pi-patch","version":"0.1.0","description":"patch-package clone for pi - fuzzy matching and agent integration","type":"module","main":"./extension.ts","scripts":{"test":"bun test","test:watch":"bun test --watch","typecheck":"tsc --noEmit","prepublishOnly":"bun typecheck && bun test"},"exports":{".":"./extension.ts"},"pi":{"extensions":["./extension.ts"],"name":"pi-patch","description":"Create patches from modified node_modules (patch-package clone)"},"keywords":["pi","extension","patch","patch-package","monkey-patch","fuzzy-match","node_modules"],"author":{"name":"0xKobold"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/0xKobold/pi-patch.git"},"bugs":{"url":"https://github.com/0xKobold/pi-patch/issues"},"homepage":"https://github.com/0xKobold/pi-patch#readme","dependencies":{"@sinclair/typebox":"^0.32.0"},"peerDependencies":{"@mariozechner/pi-coding-agent":"*"},"publishConfig":{"access":"public"},"gitHead":"6bf52e39fd38995e32408c3184bfe18729061114","_id":"@0xkobold/pi-patch@0.1.0","_nodeVersion":"20.19.2","_npmVersion":"9.2.0","dist":{"integrity":"sha512-gnravtAAXik8YdVl8BofnhSsGSurBPZfoYmnw38wFycFmyghhKQH28DQYtGj+5QL/S1EoYDqTUJ66lEfCgd4ZQ==","shasum":"4aea242244c51522b241ddaba28c827350c5a800","tarball":"https://registry.npmjs.org/@0xkobold/pi-patch/-/pi-patch-0.1.0.tgz","fileCount":9,"unpackedSize":84307,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGabHUPBdFXt1lbfH4VxBJXqeX8WMzBkA4XpmxQvLp4oAiBr0ieh5g64rtO7FDJF9JYsFSosBl9ZKFoBflTyHGSOQQ=="}]},"_npmUser":{"name":"moikapy","email":"warrenckhan@gmail.com"},"directories":{},"maintainers":[{"name":"moikapy","email":"warrenckhan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-patch_0.1.0_1775452265265_0.9126273539927754"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-06T05:09:38.324Z","modified":"2026-04-06T05:11:05.556Z","1.0.0":"2026-04-06T05:09:38.572Z","0.1.0":"2026-04-06T05:11:05.433Z"},"bugs":{"url":"https://github.com/0xKobold/pi-patch/issues"},"author":{"name":"0xKobold"},"license":"MIT","homepage":"https://github.com/0xKobold/pi-patch#readme","keywords":["pi","extension","patch","patch-package","monkey-patch","fuzzy-match","node_modules"],"repository":{"type":"git","url":"git+https://github.com/0xKobold/pi-patch.git"},"description":"patch-package clone for pi - fuzzy matching and agent integration","maintainers":[{"name":"moikapy","email":"warrenckhan@gmail.com"}],"readme":"# Pi Patch 🩹\n\n**A full patch-package clone for pi. Create and apply patches to node_modules packages with fuzzy matching support.**\n\n> 🎯 **Goal**: Drop-in replacement for `patch-package` that works inside pi with agent integration.\n\n---\n\n## Quick Start\n\n```bash\n# 1. Edit a dependency\n$EDITOR node_modules/express/index.js\n\n# 2. Create patch (exactly like patch-package)\n/patch-package express\n\n# 3. Commit patches\ngit add .patches/\ngit commit -m \"fix: patch express\"\n```\n\nPatches auto-apply when pi starts.\n\n---\n\n## Commands\n\n| Command | Description |\n|---------|-------------|\n| `/patch-package <package>` | Create patch from modified package |\n| `/patch-package` | Create patches for ALL modified packages |\n| `/patch` or `/patch apply` | Apply all patches |\n| `/patch dry-run` | Test patches without applying |\n| `/patch revert` | Revert all patches |\n| `/patch status` | Show modified packages & patches |\n\n---\n\n## Agent Integration\n\nThe agent can use the `patch_package` tool to manage patches programmatically:\n\n```typescript\n// Create patch for a specific package\n{\n  \"action\": \"create\",\n  \"package_name\": \"lodash\"\n}\n\n// Create patches for all modified packages\n{ \"action\": \"create_all\" }\n\n// List modified packages\n{ \"action\": \"list_modified\" }\n\n// Apply patches\n{ \"action\": \"apply\" }\n\n// Dry run\n{ \"action\": \"dry_run\" }\n\n// Status check\n{ \"action\": \"status\" }\n```\n\n---\n\n## How It Works\n\n### 1. Modify Dependencies\n\n```bash\n# Edit files in node_modules/\ned node_modules/some-package/index.js\n# Files are automatically backed up as .orig\n```\n\n### 2. Create Patches\n\n```bash\n# Single package\n/patch-package some-package\n\n# All modified\n/patch-package\n```\n\n**Patch naming:** `package-name+1.2.3.patch`\n\n### 3. Apply Patches\n\nPatches apply automatically on pi startup, or manually:\n```bash\n/patch apply\n```\n\n**Fuzzy matching:** Uses `git apply` with 3-way support (like patch-package).\n\n---\n\n## Installation\n\n### Global (Recommended)\n\n```bash\nmkdir -p ~/.pi/agent/extensions/pi-patch\ncp extension.ts ~/.pi/agent/extensions/pi-patch/\n```\n\n### Project-local\n\n```bash\nmkdir -p .pi/extensions/pi-patch\ncp extension.ts .pi/extensions/pi-patch/\n```\n\n### For Development (Symlink)\n\n```bash\nln -s $(pwd)/extension.ts ~/.pi/agent/extensions/pi-patch/index.ts\n```\n\n---\n\n## Comparison with patch-package\n\n| Feature | patch-package | pi-patch |\n|---------|--------------|----------|\n| Patch node_modules | ✅ | ✅ |\n| Fuzzy matching | ✅ (git apply) | ✅ (git apply) |\n| Auto-apply | ✅ (postinstall) | ✅ (pi startup) |\n| Version in filename | ✅ | ✅ |\n| Scoped packages (@x/y) | ✅ | ✅ |\n| Dry run | ✅ | ✅ |\n| Revert patches | ✅ | ✅ |\n| **Agent tool access** | ❌ | ✅ |\n| **Patch pi internals** | ❌ | ✅ |\n\n**Drop-in compatible:** Same workflow, same patch format.\n\n---\n\n## Configuration\n\nCreate `.patches/pi-patch.json`:\n\n```json\n{\n  \"autoApply\": true,\n  \"allowFuzzy\": true,\n  \"postinstall\": false,\n  \"excludePackages\": [\"@types/node\"]\n}\n```\n\n| Option | Description |\n|--------|-------------|\n| `autoApply` | Apply patches on pi startup |\n| `allowFuzzy` | Allow git fuzzy matching (recommended) |\n| `excludePackages` | Skip these packages |\n\n---\n\n## Patch Format\n\nStandard unified diff (same as patch-package):\n\n```diff\ndiff --git a/lodash b/lodash\n# Package: lodash\n--- a/lib/debounce.js\n+++ b/lib/debounce.js\n@@ -10,3 +10,4 @@\n function debounce() {\n+  if (!func) return;\n   setup();\n }\n```\n\n---\n\n## Troubleshooting\n\n### Patch fails to apply\n\n```bash\n# Check what would happen\n/patch dry-run\n\n# See detailed output\n/patch status\n```\n\n### File changed too much\n\nIf upstream changed significantly:\n\n```bash\n# 1. Revert patch\n/patch revert\n\n# 2. Update package\nnpm update some-package\n\n# 3. Re-apply your changes\n# 4. Create new patch\n/patch-package some-package\n```\n\n### \"No modified packages found\"\n\nThe extension uses `.orig` files to detect modifications. Make sure:\n- You actually edited files in `node_modules/`\n- `.orig` backups exist (created automatically on first edit)\n\nTo force detect changes:\n```bash\n# Manually back up before editing\ncp node_modules/pkg/file.js node_modules/pkg/file.js.orig\n# Now edit the file\n```\n\n---\n\n## Testing\n\n```bash\nbun test          # Run all tests\nbun test --watch  # Watch mode\n```\n\n**54 tests** covering:\n- Patch creation with git diff\n- Fuzzy matching with git apply\n- Package detection in node_modules\n- Edge cases and error scenarios\n\n---\n\n## Workflow Examples\n\n### Fix a Bug in Production\n\n```bash\n# Find the bug in node_modules/express/lib/router.js\n\n# Back up and edit\ncp node_modules/express/lib/router.js{,.orig}\n$EDITOR node_modules/express/lib/router.js\n\n# Create patch\n/patch-package express\n\n# Commit\ngit add .patches/\ngit commit -m \"fix: express router bug\"\n\n# Next deploy: patches auto-apply\n```\n\n### Maintain Private Fork\n\n```bash\n# Heavy customization of a package\n# Edit many files in node_modules/my-fork/\n\n# Create patches for all modifications\n/patch-package\n\n# Result: Multiple patches committed to repo\n# Patches survive npm install\n```\n\n### Agent-Driven Patching\n\nYou can ask the agent to create patches:\n\n> \"The lodash merge function has a bug. Can you patch it?\"\n\nThe agent will:\n1. Locate `node_modules/lodash/merge.js`\n2. Create a backup as `.orig`\n3. Apply the fix\n4. Run `patch_package` tool to create the patch\n5. Report the created patch file\n\n---\n\n## Why Not Just Use patch-package?\n\n1. **Agent Integration**: pi-patch gives agents direct access to patch management\n2. **Pi Internals**: Can patch pi-coding-agent itself (extensions, core files)\n3. **No npm Required**: Works with bun, pnpm, or any package manager\n4. **Unified Interface**: One tool for dependencies and pi customization\n\n---\n\n## License\n\nMIT\n","readmeFilename":"README.md"}