{"_id":"@andriimartynov/pi-ollama-model-switcher","_rev":"2-56c181e8ed30a4eae159a85dff8ae350","name":"@andriimartynov/pi-ollama-model-switcher","dist-tags":{"latest":"0.1.0"},"versions":{"0.0.1":{"name":"@andriimartynov/pi-ollama-model-switcher","version":"0.0.1","keywords":["pi","pi-package","extension","ollama","llm"],"author":{"name":"Andrii Martynov"},"license":"MIT","_id":"@andriimartynov/pi-ollama-model-switcher@0.0.1","maintainers":[{"name":"andriimartynov","email":"andrii.martynov@gmail.com"}],"homepage":"https://github.com/andriimartynov/pi-ollama-model-switcher#readme","bugs":{"url":"https://github.com/andriimartynov/pi-ollama-model-switcher/issues"},"pi":{"extensions":["./index.ts"]},"dist":{"shasum":"b83d4e93f90d3f59bced2729503503f73a3210c6","tarball":"https://registry.npmjs.org/@andriimartynov/pi-ollama-model-switcher/-/pi-ollama-model-switcher-0.0.1.tgz","fileCount":4,"integrity":"sha512-HlX2D3yiDIFtqS0Tg5ilDzIFnAgju+FWqRu0tpzqlpEZr3nb/+wVk+e3cIar51exxXqfNJoXwSnLFz7euk5b0A==","signatures":[{"sig":"MEUCIGmukEV/HS+Qpl/JVcAhyuYPRFpEb0nw8zyXOzO/ISBaAiEAxOG7Z1NMu8B3KgpyUFmCFjAeYIL+FdVkgGsGiaMQxD8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4746},"type":"module","gitHead":"c10dcaca6189f113d6d0671de16ba7f595140990","scripts":{"clean":"rimraf dist"},"_npmUser":{"name":"andriimartynov","email":"andrii.martynov@gmail.com"},"repository":{"url":"git+https://github.com/andriimartynov/pi-ollama-model-switcher.git","type":"git"},"_npmVersion":"11.12.1","description":"Monitors and manages Ollama model instances within the pi coding agent harness.","directories":{},"_nodeVersion":"24.15.0","_hasShrinkwrap":false,"devDependencies":{"rimraf":"^6.0.1","typescript":"^5.8.2","@types/node":"^24.0.0"},"peerDependencies":{"@mariozechner/pi-coding-agent":"^0.71.1"},"_npmOperationalInternal":{"tmp":"tmp/pi-ollama-model-switcher_0.0.1_1777706793648_0.12457415097835045","host":"s3://npm-registry-packages-npm-production"}},"0.1.0":{"name":"@andriimartynov/pi-ollama-model-switcher","version":"0.1.0","description":"Monitors and manages Ollama model instances within the pi coding agent harness.","keywords":["pi","pi-package","extension","ollama","llm"],"homepage":"https://github.com/andriimartynov/pi-ollama-model-switcher#readme","bugs":{"url":"https://github.com/andriimartynov/pi-ollama-model-switcher/issues"},"repository":{"type":"git","url":"git+https://github.com/andriimartynov/pi-ollama-model-switcher.git"},"license":"MIT","author":{"name":"Andrii Martynov"},"type":"module","scripts":{"clean":"npm run clean --workspaces","check":"biome check --write --error-on-warnings ."},"devDependencies":{"@types/node":"^24.0.0","@biomejs/biome":"2.3.5","rimraf":"^6.0.1","typescript":"^5.9.2"},"peerDependencies":{"@mariozechner/pi-coding-agent":"^0.71.1"},"pi":{"extensions":["./src/index.ts"]},"gitHead":"4a47fc9fc8f716d159f40b154a341b3611bf2f3c","_id":"@andriimartynov/pi-ollama-model-switcher@0.1.0","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-9Ls2NHOgIMZK4NG54OoRNapkl7LvgqcFW1LgKaU/gZaGCfrQP42rjagM10GtgN8R8jwAl42I8sRez32oWv4Y3w==","shasum":"a83a748d98cf67e8af236f4ae1c2e36d72ad4df6","tarball":"https://registry.npmjs.org/@andriimartynov/pi-ollama-model-switcher/-/pi-ollama-model-switcher-0.1.0.tgz","fileCount":5,"unpackedSize":6942,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDlKDIfG1aC8IWpA3pCF/b15VF124c/nmIT2CpdKBy8nAIhAJ3mTltyNiostk4GDFu9CJkYzBRbky/9mn8C5SWEGA0b"}]},"_npmUser":{"name":"andriimartynov","email":"andrii.martynov@gmail.com"},"directories":{},"maintainers":[{"name":"andriimartynov","email":"andrii.martynov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-ollama-model-switcher_0.1.0_1778999140550_0.5097958884232263"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-02T07:26:33.540Z","modified":"2026-05-17T06:25:40.812Z","0.0.1":"2026-05-02T07:26:33.794Z","0.1.0":"2026-05-17T06:25:40.702Z"},"bugs":{"url":"https://github.com/andriimartynov/pi-ollama-model-switcher/issues"},"author":{"name":"Andrii Martynov"},"license":"MIT","homepage":"https://github.com/andriimartynov/pi-ollama-model-switcher#readme","keywords":["pi","pi-package","extension","ollama","llm"],"repository":{"type":"git","url":"git+https://github.com/andriimartynov/pi-ollama-model-switcher.git"},"description":"Monitors and manages Ollama model instances within the pi coding agent harness.","maintainers":[{"name":"andriimartynov","email":"andrii.martynov@gmail.com"}],"readme":"# Ollama Model Switcher Extension\n\n> Monitor and auto-manage Ollama model instances within the `pi` coding agent harness.\n\n## Description\n\nThis extension monitors changes in the selected language model. Its primary purpose is to automatically manage and stop a previously running Ollama model instance when a new model is selected, ensuring that system resources are released efficiently.\n\nThe extension communicates directly with the [Ollama REST API](https://github.com/ollama/ollama/blob/main/docs/api.md) using HTTP requests instead of shell commands, making it safer and more portable.\n\n## Prerequisites\n\n*    [pi](https://pi.dev) coding agent harness must be installed.\n*    [Ollama](https://ollama.com/) must be installed and running on your system.\n*    Ollama API must be accessible (default: `http://localhost:11434`).\n\n## Installation\n\n### From Npm\n\n```bash\npi install npm:@andriimartynov/pi-ollama-model-switcher\n```\n\n### From GitHub\n\n```bash\npi install git:github.com/andriimartynov/pi-ollama-model-switcher\n```\n\n### FROM LOCAL PATH (DEVELOPMENT)\n\n```bash\npi install /path/to/pi-ollama-model-switcher\n```\n\n## Configuration\n\n### `OLLAMA_HOST`\n\nBy default, the extension connects to Ollama at `http://localhost:11434`. To use a different host or port, set the `OLLAMA_HOST` environment variable:\n\n```bash\nexport OLLAMA_HOST=\"http://192.168.1.100:11434\"\n```\n\nThis is the same environment variable used by the [Ollama CLI](https://github.com/ollama/ollama/blob/main/docs/docs.md#custom-address-or-port).\n\n## Features\n\n*    **Model Change Detection:** Listens for the `model_select` event.\n*    **Ollama Management:** If the selected model changes from a previous Ollama model, it safely stops the old instance via the Ollama REST API.\n*    **Safe Operation:** No shell commands are executed — only HTTP requests to the Ollama API.\n*    **Cancellation Support:** Integrates with `pi` harness cancellation signals.\n\n## How it Works\n\n1.  **Trigger:** A user changes the selected model in the harness.\n2.  **Check:** The extension verifies if the previously active model was an Ollama model.\n3.  **Action:** If so, it sends an HTTP POST request to `${OLLAMA_HOST}/api/generate` with `{ model: \"<previous_model_id>\", keep_alive: 0 }`, which forces Ollama to unload the model from memory immediately.\n\nThis ensures that resources tied to the old instance are released before new operations continue.\n\n## Limitations\n\n*    **Ollama Only:** It only manages cleanup for Ollama models; switching to/from non-Ollama models does not trigger cleanup.\n*    **Stop Only:** This extension manages stopping existing processes; it does not handle starting new models.\n\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for details.\n","readmeFilename":"README.md"}