← Catalog

@jocax/model-scope

Per-project provider and model scoping for pi — restrict the visible model catalog from .pi/model-scope.json

Extension

Install

Install with PiG

pig install npm:@jocax/model-scope

Install with Pi

pi install npm:@jocax/model-scope
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./dist/index.js"
  ]
}

README

Written by the package's publisher, shown as published in version 0.3.1 (README.md). PiG does not review it.

@jocax/model-scope

Per-project provider and model scoping for the pi coding agent.

What

A pi extension that restricts which providers and models are visible and usable in a given project. Each project carries a .pi/model-scope.json file declaring what it permits; /model and --list-models then show only that.

Why

pi's model catalog is global. It resolves from ~/.pi/agent/models.json plus the built-in provider catalog, so every project sees every provider and every model. There is no project-scoped catalog, which means:

  • A project that must only use a local Ollama model still shows every frontier provider in /model.
  • A project with a per-project budget still offers expensive models by default.
  • A shared repo cannot carry its model policy with it — every developer has to configure their machine identically, and remember to.

The mechanisms that look like they solve this do not:

MechanismWhy it falls short
.pi/settings.json → enabledModelsGates only Ctrl+P cycling, the startup default, and /scoped-models. It does not filter the /model picker.
PI_CODING_AGENT_DIRRedirects the entire agent directory — settings, auth, sessions, tools — not just the catalog.
unregisterProvider(name)Restores built-ins rather than removing them, and cannot be queued at extension-load time.

Install

Install the package from npm:

{
  "source": "npm:@jocax/model-scope"
}

Then create .pi/model-scope.json in the project.

Usage

Allowlist — this project offers exactly two models:

{
  "mode": "allowlist",
  "providers": {
    "ollama": { "models": ["deepseek-v4.1-flash:cloud"] },
    "anthropic": { "models": ["claude-sonnet-4-6"] }
  }
}

Blocklist — this project offers everything except a few things:

{
  "mode": "blocklist",
  "hideProviders": ["lmstudio", "fireworks"],
  "providers": {
    "anthropic": { "models": ["opus"] }
  }
}

Subset — narrow one provider, leave everything else alone:

{
  "mode": "subset",
  "providers": {
    "openai": { "models": ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-6-astra"] }
  }
}

This is the mode to use when you want to add a curated provider without removing the ones you already rely on. allowlist would hide every provider it does not name.

Full schema and worked examples: USAGE.md.

The /model-scope command

  • /model-scope re-reads .pi/model-scope.json and re-applies it. Use it after editing the config — no /reload and no restart.
  • It also reports the effective scope, including which providers are hidden.

Editing the config and re-running /model-scope can widen the scope as well as narrow it. Deleting the config and re-running it restores the full catalog.

How it works

The whole feature runs on pi's public extension API. Nothing here patches pi internals.

On session_start the extension:

  1. Reads and validates .pi/model-scope.json (missing file → strict no-op).
  2. Unregisters every provider it overlaid on a previous pass, so pi falls back to its built-ins and the catalog is read unfiltered.
  3. Reads the catalog via ctx.modelRegistry.getAll().
  4. Computes the surviving subset for each provider.
  5. Re-registers each provider whose surviving subset is smaller than its current catalog, plus any provider a previous pass overlaid; a provider the plan does not narrow is left to pi.

registerProvider with a models array replaces that provider's model list. A provider whose surviving subset is empty gets models: [], which contributes zero rows to the model list — so it disappears from /model and --list-models without any provider-removal API being needed.

Because the surviving model records are read from the live catalog and projected field-for-field onto the public registration shape, the rewrite is lossless: cost, contextWindow, maxTokens, compat, and thinkingLevelMap all survive. The extension can only ever remove from the global catalog, never add to it — so a project config can tighten your catalog but never smuggle in a model you did not already have.

Limitations

These are honest boundaries, not bugs.

--list-models does not reflect the scope. The CLI listing is produced before any session starts, so the session_start rewrite never runs for it — pi --list-models prints the full global catalog regardless of this project's config. Measured directly: with an allowlist of one model, the session catalog held exactly 1 entry while pi --list-models still printed all 1371. Use /model inside a session, or /model-scope, to see the effective scope. If pi ever gains a pre-session extension hook, this can be fixed.

Ctrl+P cycling is not scoped. Ctrl+P cycles the scoped models, which pi resolves from --models / enabledModels — a list independent of the catalog this extension rewrites. No public extension API can change it. If you want Ctrl+P to match your scope, mirror it in .pi/settings.json:

{ "enabledModels": ["ollama/deepseek-v4.1-flash:cloud", "anthropic/claude-sonnet-4-6"] }

The startup model is corrected, not pre-empted. pi resolves the startup model before the session starts, so the very first model it picks can be one your project does not permit. The extension detects that at session start and switches to the first in-scope model, with a notification. The switch is immediate; it is just not before pi's own resolution step.

A hidden provider still exists. models: [] empties a provider's model list; it does not delete the provider. Provider-oriented surfaces outside the model list (for example /login) may still name it. This is the cost of staying entirely on public API, and it is the right trade — see the design notes in the originating spec.

A malformed config never breaks your session. An unreadable or invalid .pi/model-scope.json produces a warning and leaves the full catalog available.

Troubleshooting

The scope is not applied. Project-local config is only read in a trusted project. Run /trust, then restart pi. Also confirm the file is at .pi/model-scope.json relative to the directory pi was started in.

Nothing changed at all. Check that the extension is actually loaded — a package can be registered without its extension being active. If your project's .pi/settings.json filters this package's src/index.ts out of its manifest, the extension never runs. Point an extensions entry at the extension file directly to confirm loading.

A provider I named is missing. Provider and model ids must match the catalog exactly. The extension warns about ids it cannot find rather than failing — check the notifications, and run /model-scope to see the result.

Everything disappeared. In allowlist mode, providers you do not name are hidden. A config with an empty providers map hides every provider; the extension warns loudly about this. Delete the file to recover.

Run the demo

just demo model-scope          # herdr — the default
just demo-web model-scope      # browser

herdr is the default surface because /model is pi's own selector and only a terminal can show it.

Scenario "One model in scope"

StepDo thisWatch
1Start the sessionmodel-scope: N model(s) in scope (the exact number varies by pi version — one live run measured 1496), with no warning about azure-openai-responses or any other provider: a provider the plan does not narrow is left alone instead of being re-registered
2Type /modelOnly the providers this session can reach are listed — Ollama is narrowed to deepseek-v4.1-flash:cloud [ollama]. The startup count and this list measure different things: the count covers every provider pi knows, /model only the ones usable here
3Type /model-scopemodel-scope: re-applied — N model(s) in scope, and /model still lists only the same one model

Scenario "An unusable scope file"

StepDo thisWatch
1Start the sessionA warning quotes the bad value — "mode" must be "allowlist", "blocklist" or "subset", got "only-the-cheap-ones" — followed by model-scope: config unusable — the full catalog is still available
2Type /modelEvery Ollama model your local install knows is listed — a broken policy file never makes pi unusable

The scope file uses subset mode, which narrows only the providers it names. With a keyed fallback provider rather than Ollama there is no ollama in the catalog, so the file would warn that the provider it names is not there and scope nothing — the session still runs.

Needs herdr 0.9.3 or newer and one reachable model provider — see demo-kit.

Development

npx tsc --noEmit -p software/packages/model-scope/tsconfig.json
npx vitest run software/packages/model-scope/tests/

The package is layered so the semantics are testable without a pi session: src/config.ts (schema and loading) and src/scope.ts (scope computation) are pure, src/apply.ts drives a narrow injectable API surface, and src/index.ts is the only module that touches pi.