{"_id":"@arvoretech/pi-smart-context","_rev":"6-cceae4b5488a108a82679afd25fa0dd6","name":"@arvoretech/pi-smart-context","dist-tags":{"latest":"0.4.0"},"versions":{"0.1.0":{"name":"@arvoretech/pi-smart-context","version":"0.1.0","author":{"name":"Arvore"},"license":"MIT","_id":"@arvoretech/pi-smart-context@0.1.0","maintainers":[{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},{"name":"rafsouza","email":"rafasouza@protonmail.com"},{"name":"pedro.adas","email":"pedro.adas@gmail.com"},{"name":"ricardoraposorfox","email":"ricardorbxx1@gmail.com"},{"name":"jott4","email":"jvgcunha2002@gmail.com"},{"name":"vitor.piovezan","email":"vitor.piovezan@arvore.com.br"}],"homepage":"https://github.com/arvoreeducacao/arvore-pi-extensions#readme","bugs":{"url":"https://github.com/arvoreeducacao/arvore-pi-extensions/issues"},"pi":{"extensions":["./dist/index.js"]},"dist":{"shasum":"d66b8dcc881a646b58b5f80924ca7d8f19178bf7","tarball":"https://registry.npmjs.org/@arvoretech/pi-smart-context/-/pi-smart-context-0.1.0.tgz","fileCount":54,"integrity":"sha512-T4JuAD26XAp3HQAAAlmS2pIGRW8AH2M/zSkbyT+VdNCU2KYZY9rVjgyZGc+gfK1q0WAgjHNxfYfi1D8O/H6Dhg==","signatures":[{"sig":"MEUCIQDOcBTXouYCCb8vvTEdgmTLhbSu4QHOFzgla9l5GZj9qgIgGd1XxmrT6EWUzmC52pyeBfGauHSs0Kzi0SzxrA5uUVY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":94521},"main":"dist/index.js","type":"module","_from":"file:arvoretech-pi-smart-context-0.1.0.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsc --watch","lint":"tsc --noEmit","build":"tsc"},"_npmUser":{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},"_resolved":"/private/var/folders/4c/6zh0tf292w134k7bn_7vsd4w0000gn/T/012bfae40c3cbfa95f697b6a7a1c0135/arvoretech-pi-smart-context-0.1.0.tgz","_integrity":"sha512-T4JuAD26XAp3HQAAAlmS2pIGRW8AH2M/zSkbyT+VdNCU2KYZY9rVjgyZGc+gfK1q0WAgjHNxfYfi1D8O/H6Dhg==","repository":{"url":"git+https://github.com/arvoreeducacao/arvore-pi-extensions.git","type":"git","directory":"packages/smart-context"},"_npmVersion":"10.9.4","description":"Intelligent model routing and prompt compression for Pi/Kiro","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"typebox":"1.1.38","typescript":"^5.3.0","@types/node":"^20.10.0","@earendil-works/pi-ai":"^0.79.4","@earendil-works/pi-tui":"^0.79.4","@earendil-works/pi-coding-agent":"^0.79.4"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.74.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-smart-context_0.1.0_1781630234354_0.8661807855074604","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@arvoretech/pi-smart-context","version":"0.2.0","author":{"name":"Arvore"},"license":"MIT","_id":"@arvoretech/pi-smart-context@0.2.0","maintainers":[{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},{"name":"rafsouza","email":"rafasouza@protonmail.com"},{"name":"pedro.adas","email":"pedro.adas@gmail.com"},{"name":"ricardoraposorfox","email":"ricardorbxx1@gmail.com"},{"name":"jott4","email":"jvgcunha2002@gmail.com"},{"name":"vitor.piovezan","email":"vitor.piovezan@arvore.com.br"}],"homepage":"https://github.com/arvoreeducacao/arvore-pi-extensions#readme","bugs":{"url":"https://github.com/arvoreeducacao/arvore-pi-extensions/issues"},"pi":{"extensions":["./dist/index.js"]},"dist":{"shasum":"9c196012ea1226a9e9b7467d0543f721a9287319","tarball":"https://registry.npmjs.org/@arvoretech/pi-smart-context/-/pi-smart-context-0.2.0.tgz","fileCount":50,"integrity":"sha512-aa8WNzR3hAey0fb4CWAPnc38nkBhS12Dxyg+K0Jccf4eob3HlCKKctypM4OaPEnNSELl6oGGopg7ijVSKFE8YQ==","signatures":[{"sig":"MEQCIHc/zPN98tV4sYLzPpASvyPeg/sOfwxewP+lBywdKU9DAiBilKn8pn/yaxABs4Ht3EH+1il7R7sMH5t3IFnYyCIWCg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@arvoretech%2fpi-smart-context@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":92503},"main":"dist/index.js","type":"module","_from":"file:/tmp/arvoretech-pi-smart-context-0.2.0.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsc --watch","lint":"tsc --noEmit","build":"tsc"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:81eea466-e9e3-46a1-8de9-03f70e1581f7"}},"_resolved":"/tmp/arvoretech-pi-smart-context-0.2.0.tgz","_integrity":"sha512-aa8WNzR3hAey0fb4CWAPnc38nkBhS12Dxyg+K0Jccf4eob3HlCKKctypM4OaPEnNSELl6oGGopg7ijVSKFE8YQ==","repository":{"url":"git+https://github.com/arvoreeducacao/arvore-pi-extensions.git","type":"git","directory":"packages/smart-context"},"_npmVersion":"11.17.0","description":"Intelligent model routing and prompt compression for Pi/Kiro","directories":{},"_nodeVersion":"22.22.3","_hasShrinkwrap":false,"devDependencies":{"typebox":"1.1.38","typescript":"^5.3.0","@types/node":"^20.10.0","@earendil-works/pi-ai":"^0.79.4","@earendil-works/pi-tui":"^0.79.4","@earendil-works/pi-coding-agent":"^0.79.4"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.74.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-smart-context_0.2.0_1781636699144_0.09153169812645956","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@arvoretech/pi-smart-context","version":"0.3.0","author":{"name":"Arvore"},"license":"MIT","_id":"@arvoretech/pi-smart-context@0.3.0","maintainers":[{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},{"name":"rafsouza","email":"rafasouza@protonmail.com"},{"name":"pedro.adas","email":"pedro.adas@gmail.com"},{"name":"guilhermebs","email":"guilhermebscontact@gmail.com"},{"name":"ricardoraposorfox","email":"ricardorbxx1@gmail.com"},{"name":"jott4","email":"jvgcunha2002@gmail.com"},{"name":"vitor.piovezan","email":"vitor.piovezan@arvore.com.br"}],"homepage":"https://github.com/arvoreeducacao/arvore-pi-extensions#readme","bugs":{"url":"https://github.com/arvoreeducacao/arvore-pi-extensions/issues"},"pi":{"extensions":["./dist/index.js"]},"dist":{"shasum":"9d1824dc1851f73edcf9bf79674674bc63fad322","tarball":"https://registry.npmjs.org/@arvoretech/pi-smart-context/-/pi-smart-context-0.3.0.tgz","fileCount":50,"integrity":"sha512-Cleo0eEzAu50Z+IHSBu9EvvV7zmRbbDX4D6g5tIx60AaLEbFhJIp7ubkBDP+jlzDVbywkT+YcmRw1eckghZb8w==","signatures":[{"sig":"MEUCIQCb0S8HCmY9YPwTsE3OIW2f4UIdvdjaXMePc7HmN3j1YwIgDxcq5jKTCtfuzv8zTUBVJUl20ErdLl5jwOn+rqCgIFw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@arvoretech%2fpi-smart-context@0.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":95271},"main":"dist/index.js","type":"module","_from":"file:/tmp/arvoretech-pi-smart-context-0.3.0.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsc --watch","lint":"tsc --noEmit","build":"tsc"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:81eea466-e9e3-46a1-8de9-03f70e1581f7"}},"_resolved":"/tmp/arvoretech-pi-smart-context-0.3.0.tgz","_integrity":"sha512-Cleo0eEzAu50Z+IHSBu9EvvV7zmRbbDX4D6g5tIx60AaLEbFhJIp7ubkBDP+jlzDVbywkT+YcmRw1eckghZb8w==","repository":{"url":"git+https://github.com/arvoreeducacao/arvore-pi-extensions.git","type":"git","directory":"packages/smart-context"},"_npmVersion":"11.17.0","description":"Intelligent model routing and prompt compression for Pi/Kiro","directories":{},"_nodeVersion":"22.22.3","_hasShrinkwrap":false,"devDependencies":{"typebox":"1.1.38","typescript":"^5.3.0","@types/node":"^20.10.0","@earendil-works/pi-ai":"^0.79.4","@earendil-works/pi-tui":"^0.79.4","@earendil-works/pi-coding-agent":"^0.79.4"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.74.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-smart-context_0.3.0_1781798620277_0.7744528645188502","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"name":"@arvoretech/pi-smart-context","version":"0.3.1","keywords":["pi-package"],"author":{"name":"Arvore"},"license":"MIT","_id":"@arvoretech/pi-smart-context@0.3.1","maintainers":[{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},{"name":"rafsouza","email":"rafasouza@protonmail.com"},{"name":"pedro.adas","email":"pedro.adas@gmail.com"},{"name":"guilhermebs","email":"guilhermebscontact@gmail.com"},{"name":"ricardoraposorfox","email":"ricardorbxx1@gmail.com"},{"name":"jott4","email":"jvgcunha2002@gmail.com"},{"name":"vitor.piovezan","email":"vitor.piovezan@arvore.com.br"}],"homepage":"https://github.com/arvoreeducacao/arvore-pi-extensions#readme","bugs":{"url":"https://github.com/arvoreeducacao/arvore-pi-extensions/issues"},"pi":{"extensions":["./dist/index.js"]},"dist":{"shasum":"c19f3b63be28c1543dfe29fbe8024c086757997a","tarball":"https://registry.npmjs.org/@arvoretech/pi-smart-context/-/pi-smart-context-0.3.1.tgz","fileCount":50,"integrity":"sha512-V7QKIWkouRE2PWZGruPqkL+iO7whOuenOjQUbaLBGFJawdtKt1/0KJJXyVDcr1jiGB2QpvAf5Nqao22olcy7XA==","signatures":[{"sig":"MEYCIQCHxRTlatuAEcPoy2Im0MSfrmS8WmWU98u/e4bBp1S8KQIhAOThjCPh92IAcsMlLUnnr3tzKV3FxjkGQqOUZfnx4FCC","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@arvoretech%2fpi-smart-context@0.3.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":95309},"main":"dist/index.js","type":"module","_from":"file:/tmp/arvoretech-pi-smart-context-0.3.1.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsc --watch","lint":"tsc --noEmit","build":"tsc"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:81eea466-e9e3-46a1-8de9-03f70e1581f7"}},"_resolved":"/tmp/arvoretech-pi-smart-context-0.3.1.tgz","_integrity":"sha512-V7QKIWkouRE2PWZGruPqkL+iO7whOuenOjQUbaLBGFJawdtKt1/0KJJXyVDcr1jiGB2QpvAf5Nqao22olcy7XA==","repository":{"url":"git+https://github.com/arvoreeducacao/arvore-pi-extensions.git","type":"git","directory":"packages/smart-context"},"_npmVersion":"11.17.0","description":"Intelligent model routing and prompt compression for Pi/Kiro","directories":{},"_nodeVersion":"22.22.3","_hasShrinkwrap":false,"devDependencies":{"typebox":"1.1.38","typescript":"^5.3.0","@types/node":"^20.10.0","@earendil-works/pi-ai":"^0.79.4","@earendil-works/pi-tui":"^0.79.4","@earendil-works/pi-coding-agent":"^0.79.4"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.74.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-smart-context_0.3.1_1782216735707_0.0609853669999616","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"name":"@arvoretech/pi-smart-context","version":"0.4.0","description":"Intelligent model routing and prompt compression for Pi/Kiro","main":"dist/index.js","types":"dist/index.d.ts","type":"module","peerDependencies":{"@earendil-works/pi-coding-agent":">=0.74.0"},"devDependencies":{"@earendil-works/pi-coding-agent":"^0.79.4","@earendil-works/pi-ai":"^0.79.4","@earendil-works/pi-tui":"^0.79.4","@types/node":"^20.10.0","typebox":"1.1.38","typescript":"^5.3.0"},"pi":{"extensions":["./dist/index.js"]},"repository":{"type":"git","url":"git+https://github.com/arvoreeducacao/arvore-pi-extensions.git","directory":"packages/smart-context"},"author":{"name":"Arvore"},"license":"MIT","keywords":["pi-package"],"scripts":{"build":"tsc","dev":"tsc --watch","lint":"tsc --noEmit"},"_id":"@arvoretech/pi-smart-context@0.4.0","bugs":{"url":"https://github.com/arvoreeducacao/arvore-pi-extensions/issues"},"homepage":"https://github.com/arvoreeducacao/arvore-pi-extensions#readme","_integrity":"sha512-L/ojDaT67X5Rd0M7psZIK9bD3H032xDTZ+eaOqweeMQuQYW9+p3AU4rGog0xqeoX+76Sgw9XMQNWqtt81RiHYg==","_resolved":"/tmp/arvoretech-pi-smart-context-0.4.0.tgz","_from":"file:/tmp/arvoretech-pi-smart-context-0.4.0.tgz","_nodeVersion":"22.22.3","_npmVersion":"11.17.0","dist":{"integrity":"sha512-L/ojDaT67X5Rd0M7psZIK9bD3H032xDTZ+eaOqweeMQuQYW9+p3AU4rGog0xqeoX+76Sgw9XMQNWqtt81RiHYg==","shasum":"942198da80165e3076f1660213286e7198140555","tarball":"https://registry.npmjs.org/@arvoretech/pi-smart-context/-/pi-smart-context-0.4.0.tgz","fileCount":54,"unpackedSize":112659,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@arvoretech%2fpi-smart-context@0.4.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHOYmZsG8bv6hHEV6MNL03rAj3zXoyXamgYtefNiHPLhAiBtwhjF190SEHxZuRiFaDkq5sWHCVS4lzehAqeY/pdjmg=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:81eea466-e9e3-46a1-8de9-03f70e1581f7"}},"directories":{},"maintainers":[{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},{"name":"rafsouza","email":"rafasouza@protonmail.com"},{"name":"pedro.adas","email":"pedro.adas@gmail.com"},{"name":"guilhermebs","email":"guilhermebscontact@gmail.com"},{"name":"ricardoraposorfox","email":"ricardorbxx1@gmail.com"},{"name":"jott4","email":"jvgcunha2002@gmail.com"},{"name":"vitor.piovezan","email":"vitor.piovezan@arvore.com.br"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-smart-context_0.4.0_1782302506798_0.9902784010795203"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-16T17:17:14.155Z","modified":"2026-06-24T12:01:47.335Z","0.1.0":"2026-06-16T17:17:14.519Z","0.2.0":"2026-06-16T19:04:59.291Z","0.3.0":"2026-06-18T16:03:40.458Z","0.3.1":"2026-06-23T12:12:15.913Z","0.4.0":"2026-06-24T12:01:46.957Z"},"bugs":{"url":"https://github.com/arvoreeducacao/arvore-pi-extensions/issues"},"author":{"name":"Arvore"},"license":"MIT","homepage":"https://github.com/arvoreeducacao/arvore-pi-extensions#readme","keywords":["pi-package"],"repository":{"type":"git","url":"git+https://github.com/arvoreeducacao/arvore-pi-extensions.git","directory":"packages/smart-context"},"description":"Intelligent model routing and prompt compression for Pi/Kiro","maintainers":[{"name":"joao.barros.arvore","email":"joao.barros@arvore.com.br"},{"name":"rafsouza","email":"rafasouza@protonmail.com"},{"name":"pedro.adas","email":"pedro.adas@gmail.com"},{"name":"guilhermebs","email":"guilhermebscontact@gmail.com"},{"name":"ricardoraposorfox","email":"ricardorbxx1@gmail.com"},{"name":"jott4","email":"jvgcunha2002@gmail.com"},{"name":"vitor.piovezan","email":"vitor.piovezan@arvore.com.br"}],"readme":"# @arvoretech/pi-smart-context\n\nIntelligent model routing and retrieval-augmented prompt compression for Pi/Kiro.\n\n## Features\n\n### Model Routing\n\nUses a cheap classifier model (Haiku by default) to classify task complexity based on the full conversation context — not just the current message. So \"bora\" after a complex architecture discussion correctly routes to Opus.\n\n| Classification | Default model | When |\n|---|---|---|\n| trivial | `claude-haiku-4-5` | Greetings, meta-conversation, no pending task |\n| simple | `claude-sonnet-4-6` | Single-file fixes, quick questions |\n| medium | `claude-opus-4-8` | Standard multi-file work |\n| complex | `claude-opus-4-8` | Architecture, large refactors, security audits |\n| Large context (>500K) | `claude-sonnet-4-6` | 1M window needed |\n\nEvery slot above — provider and model — is configurable (see [Configuration](#configuration)).\n\n### Retrieval-Augmented Compression\n\nThe core principle (from the prompt-compression literature): **the model never loses access to information — it just pays less to carry it by default.**\n\nCompressed/dropped content is replaced by a summary + a `recover_context(\"id\")` hint. The original is kept in an in-memory store. If the model actually needs the detail, it calls the `recover_context` tool to pull back the full text. This lets us compress aggressively with no quality loss.\n\n#### Pipeline\n\n| Stage | Technique | Safety |\n|---|---|---|\n| **Tool output (structural)** | Log folding, n-gram dedup, JSON tabularize, cross-turn delta | Lossless / near-lossless |\n| **BM25 relevance** | Score old messages vs current query | — |\n| **Haiku summarization** | Summarize old messages preserving load-bearing facts, cached by hash | Lossy but recoverable |\n| **Retrieval drop** | Replace low-relevance content with stub + recover hint | Recoverable |\n\n#### Cache-aware (critical)\n\nAnthropic/Kiro use **prompt caching** keyed by prefix. Compression that rewrites the context differently each turn would *break the cache and increase cost*.\n\nTwo protections:\n\n1. **Runtime cache detection** — the extension inspects the last assistant message's `cacheRead`/`cacheWrite`. If the provider is actively caching, **lossy compression of the prefix is disabled** (only safe structural compression of new tool output runs). No cache break, ever.\n2. **Stable/monotonic compression** — when cache is off, once a message is compressed the identical compressed form is reused on every subsequent turn, so even the one-time prefix change rebuilds and stays stable.\n\n> Note: at the time of writing, the Kiro provider reports `cacheRead: 0 / cacheWrite: 0` across sessions — caching is effectively off, so compression is pure savings (the full context is re-billed every turn with no cache to break). The cache-detection path future-proofs the extension for when Kiro enables caching.\n\n#### Aggressive quality gate\n\nThe pipeline runs with one of two aggression profiles, chosen per turn:\n\n| Profile | Trigger | Protected turns | Min savings | Summarize ≥ | BM25 drop | Tool trim ≥ | Compress under cache |\n|---|---|---|---|---|---|---|---|\n| **Balanced** | Large-context model, low usage | 4 | 15% | 400 chars | 0.25 | 4000 chars | no |\n| **Aggressive** | Small context window (<200K) **or** usage ≥60% of the window | 2 | 10% | 250 chars | 0.35 | 2000 chars | yes |\n\nDetection uses `ctx.getModel().contextWindow` and `ctx.getContextUsage().tokens`. On a smaller-context model (or when the window is filling up) the extension protects fewer turns, summarizes shorter messages, drops more low-relevance content, trims tool output sooner, and — only in this mode — keeps compressing the prefix even when the provider is caching (the cost of a cache rebuild beats overflowing the window).\n\n### Commands\n\n- `/smart-context` — Stats: chars saved, avg ratio, Haiku calls/cache hits, recoverable items\n\n## Configuration\n\nModel routing is fully configurable via a project-local `.pi/smart-context.json` file. The extension walks up from the current working directory looking for the nearest `.pi`/`.git` root, then reads `.pi/smart-context.json` from it. If the file is missing or malformed, the built-in defaults are used (behavior identical to no config).\n\nEvery slot is a `{ \"provider\", \"model\" }` pair, so you are **not** locked to the `kiro` provider — you can mix providers and models freely across slots. The `provider`/`model` strings must match what `modelRegistry.find(provider, model)` resolves for your Pi setup.\n\n```json\n{\n  \"classifier\": { \"provider\": \"kiro\", \"model\": \"claude-haiku-4-5\" },\n\n  \"routing\": {\n    \"trivial\": { \"provider\": \"kiro\", \"model\": \"claude-haiku-4-5\" },\n    \"simple\":  { \"provider\": \"kiro\", \"model\": \"claude-sonnet-4-6\" },\n    \"medium\":  { \"provider\": \"kiro\", \"model\": \"claude-opus-4-8\" },\n    \"complex\": { \"provider\": \"kiro\", \"model\": \"claude-opus-4-8\" }\n  },\n\n  \"largeContext\": {\n    \"thresholdTokens\": 500000,\n    \"model\": { \"provider\": \"kiro\", \"model\": \"claude-sonnet-4-6\" }\n  }\n}\n```\n\n| Key | Purpose |\n|---|---|\n| `classifier` | The cheap model that classifies task complexity. Also reused by the compression summarizer. |\n| `routing.trivial` / `.simple` / `.medium` / `.complex` | Model picked for each classified complexity. |\n| `largeContext.thresholdTokens` | When context usage exceeds this, skip classification and use `largeContext.model` directly. |\n| `largeContext.model` | Model forced for very large contexts. |\n\nPartial configs are deep-merged over the defaults — you only need to specify the slots you want to override. Each slot independently falls back to its default if the value is missing or not a valid `{ provider, model }` pair.\n\n### Example: use a different provider\n\n```json\n{\n  \"classifier\": { \"provider\": \"anthropic\", \"model\": \"claude-haiku-4-5\" },\n  \"routing\": {\n    \"complex\": { \"provider\": \"openai\", \"model\": \"gpt-5\" }\n  }\n}\n```\n\nThis classifies with Anthropic Haiku, routes `complex` tasks to OpenAI, and keeps the defaults for every other slot.\n\n## Architecture\n\n```\nsrc/\n├── index.ts                      # Hooks + recover_context tool\n├── config.ts                     # .pi/smart-context.json loader (provider+model per slot)\n├── router.ts                     # Classifier-based complexity routing\n└── compression/\n    ├── pipeline.ts               # Orchestrates stages, cache-stable, retrieval-augmented\n    ├── store.ts                  # Content store for recover_context\n    ├── haiku-summarize.ts        # Haiku summarizer with hash cache\n    ├── types.ts\n    └── stages/\n        ├── bm25.ts               # BM25 relevance scoring\n        ├── dedup.ts              # N-gram line deduplication\n        ├── log-fold.ts           # Log error extraction + folding\n        ├── json-compact.ts       # JSON array tabularization\n        └── delta.ts              # Cross-turn delta compression\n```\n\n## Usage\n\n```bash\ncd arvore-pi-extensions && pnpm install\ncd packages/smart-context && pnpm build\n```\n\nAdd to your Pi packages. The extension hooks into `before_agent_start` (routing), `context` (compression), and `tool_result` (structural tool-output compression).\n","readmeFilename":"README.md"}