{"_id":"@edmundmiller/pi-dcp","name":"@edmundmiller/pi-dcp","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@edmundmiller/pi-dcp","version":"0.1.1","type":"module","description":"Dynamic Context Pruning extension for pi - intelligently removes obsolete messages to optimize token usage","main":"./index.ts","keywords":["pi","pi-extension","context-pruning","token-optimization","pi-package"],"author":{"name":"Edmund Miller","email":"edmundmiller@hey.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/edmundmiller/dotfiles.git","directory":"packages/pi-dcp"},"peerDependencies":{"@mariozechner/pi-coding-agent":"*","@mariozechner/pi-agent-core":"*"},"devDependencies":{"@types/bun":"^1.3.8","@types/node":"^22.0.0","typescript":"^5.0.0"},"pi":{"extensions":["./index.ts"]},"dependencies":{"@sinclair/typebox":"^0.34.0","bunfig":"^0.15.6"},"_id":"@edmundmiller/pi-dcp@0.1.1","gitHead":"36ee91198779d95cceda4b850f6c9409f6a5003e","bugs":{"url":"https://github.com/edmundmiller/dotfiles/issues"},"homepage":"https://github.com/edmundmiller/dotfiles#readme","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-XlHQAncU8QJd2wnPI6U+dzDbvVFBw6ivM11NjgqzUQ2FYdeFechkmhf+v1uTfXnLQfdI9WT81MbNgeDizKW2zQ==","shasum":"5348970c4e9d04977903b9f63a4a41d4be93cefe","tarball":"https://registry.npmjs.org/@edmundmiller/pi-dcp/-/pi-dcp-0.1.1.tgz","fileCount":30,"unpackedSize":112357,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIF00iEE6v7puKGAhjcA6Zh/qc/+jqJ3n1Rb7e5Ay1+aAAiEAwNBFWON7yfaA60+M12VGwAjy5OHGwshWphGWRawq5yc="}]},"_npmUser":{"name":"emiller88","email":"edmund.a.miller@gmail.com"},"directories":{},"maintainers":[{"name":"emiller88","email":"edmund.a.miller@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-dcp_0.1.1_1771908843577_0.11244560640228785"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-24T04:54:03.512Z","0.1.1":"2026-02-24T04:54:03.768Z","modified":"2026-02-24T04:54:03.950Z"},"maintainers":[{"name":"emiller88","email":"edmund.a.miller@gmail.com"}],"description":"Dynamic Context Pruning extension for pi - intelligently removes obsolete messages to optimize token usage","homepage":"https://github.com/edmundmiller/dotfiles#readme","keywords":["pi","pi-extension","context-pruning","token-optimization","pi-package"],"repository":{"type":"git","url":"git+https://github.com/edmundmiller/dotfiles.git","directory":"packages/pi-dcp"},"author":{"name":"Edmund Miller","email":"edmundmiller@hey.com"},"bugs":{"url":"https://github.com/edmundmiller/dotfiles/issues"},"license":"MIT","readme":"# Pi-DCP: Dynamic Context Pruning Extension\n\n![Monolith logo](pi-dcp-banner.png)\n\nIntelligently prunes conversation context to optimize token usage while preserving conversation coherence.\n\n## Features\n\n- **Deduplication**: Removes duplicate tool outputs based on content hash\n- **Superseded Writes**: Removes older file writes when newer versions exist\n- **Error Purging**: Removes resolved errors from context\n- **Recency Protection**: Always preserves recent messages\n\n## Installation\n\nClone the repository into your pi agent extensions directory:\n\n```bash\ngit clone https://github.com/zenobi-us/pi-dcp.git ~/.pi/agent/extensions/pi-dcp\n```\n\n## Usage\n\nThe extension runs automatically on every LLM call. No manual intervention needed.\n\n### Commands\n\n- `/dcp-debug` - Toggle debug logging\n- `/dcp-stats` - Show pruning statistics for current session\n- `/dcp-toggle` - Enable/disable the extension\n- `/dcp-recent <number>` - Set how many recent messages to always keep (default: 10)\n\n### Flags\n\n- `--dcp-enabled=true/false` - Enable/disable extension at startup\n- `--dcp-debug=true/false` - Enable debug logging at startup\n\n## Architecture\n\n### Workflow\n\n1. **Prepare Phase**: Rules annotate message metadata\n2. **Process Phase**: Rules make pruning decisions based on metadata\n3. **Filter Phase**: Messages marked for pruning are removed\n\n### Built-in Rules\n\nLocated in `src/rules/`:\n\n1. **Deduplication** (`deduplication.ts`)\n   - Prepare: Hash message content\n   - Process: Mark duplicates for pruning\n\n2. **Superseded Writes** (`superseded-writes.ts`)\n   - Prepare: Extract file paths from write/edit operations\n   - Process: Mark older writes to the same file for pruning\n\n3. **Error Purging** (`error-purging.ts`)\n   - Prepare: Identify errors and check if resolved\n   - Process: Mark resolved errors for pruning\n\n4. **Recency** (`recency.ts`)\n   - Process: Protect last N messages from pruning (overrides other rules)\n\n### Configuration\n\nDefault configuration in `src/config.ts`:\n\n```typescript\n{\n  enabled: true,\n  debug: false,\n  rules: ['deduplication', 'superseded-writes', 'error-purging', 'recency'],\n  keepRecentCount: 10\n}\n```\n\n## Custom Rules\n\nCreate custom pruning rules by implementing the `PruneRule` interface:\n\n```typescript\nimport type { PruneRule } from \"./src/types\";\n\nconst myRule: PruneRule = {\n  name: \"my-custom-rule\",\n  description: \"My custom pruning logic\",\n\n  prepare(msg, ctx) {\n    // Annotate metadata during prepare phase\n    msg.metadata.myScore = calculateScore(msg.message);\n  },\n\n  process(msg, ctx) {\n    // Make pruning decision during process phase\n    if (msg.metadata.myScore < threshold) {\n      msg.metadata.shouldPrune = true;\n      msg.metadata.pruneReason = \"low score\";\n    }\n  },\n};\n```\n\nThen add to configuration: `rules: ['deduplication', myRule]`\n\n## Development\n\n### Type Checking\n\n```bash\nbun run typecheck\n```\n\n### Project Structure\n\n```\npi-dcp/\n├── index.ts              # Main extension entry point\n├── package.json          # Bun package config\n├── tsconfig.json         # TypeScript config\n├── src/\n│   ├── types.ts          # Core type definitions\n│   ├── config.ts         # Configuration management\n│   ├── metadata.ts       # Message metadata utilities\n│   ├── registry.ts       # Rule registration system\n│   ├── workflow.ts       # Prepare > Process > Filter workflow\n│   └── rules/\n│       ├── index.ts      # Export and register all rules\n│       ├── deduplication.ts\n│       ├── superseded-writes.ts\n│       ├── error-purging.ts\n│       └── recency.ts\n└── README.md\n```\n\n## How It Works\n\n1. **Context Event Hook**: The extension subscribes to the `context` event, which fires before each LLM call\n2. **Message Processing**: All messages are wrapped with metadata containers\n3. **Prepare Phase**: Each rule's `prepare` function annotates metadata (hashes, file paths, etc.)\n4. **Process Phase**: Each rule's `process` function makes pruning decisions based on metadata\n5. **Filter Phase**: Messages marked with `shouldPrune: true` are removed\n6. **Result**: Pruned message list is returned to pi and sent to the LLM\n\n## Benefits\n\n- **Token Savings**: Removes redundant and obsolete messages\n- **Cost Reduction**: Fewer tokens = lower API costs\n- **Preserved Coherence**: Smart rules keep important context\n- **Transparent**: No changes to user experience\n- **Configurable**: Adjust rules and thresholds as needed\n- **Extensible**: Easy to add custom rules\n\n## Example Output\n\n```\n[pi-dcp] Initialized with 4 rules: deduplication, superseded-writes, error-purging, recency\n[pi-dcp] Pruned 12 / 45 messages\n[pi-dcp] Pruned 8 / 52 messages\n```\n\nWith debug mode enabled (`/dcp-debug`):\n\n```\n[pi-dcp] Dedup: marking duplicate message at index 15 (hash: k2l9x)\n[pi-dcp] SupersededWrites: found file operation at index 23: src/index.ts\n[pi-dcp] SupersededWrites: marking superseded write at index 23: src/index.ts\n[pi-dcp] ErrorPurging: found resolved error at index 31\n[pi-dcp] Recency: protecting message at index 48 (distance from end: 3, threshold: 10)\n[pi-dcp] Filter phase complete: 12 pruned, 33 kept (45 total)\n[pi-dcp] Pruned messages:\n  [15] assistant: duplicate content\n  [23] toolResult: superseded by later write to src/index.ts\n  [31] toolResult: error resolved by later success\n  ...\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-6cc633284a9d279ec5fa88d251f95dab"}