@counterposition/skill-pi 0.78.1 → 0.80.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@counterposition/skill-pi",
3
- "version": "0.78.1",
3
+ "version": "0.80.9",
4
4
  "description": "Pi coding agent reference skill — extensions, settings, providers, SDK/RPC, packages, and .pi/ config",
5
5
  "keywords": [
6
6
  "ai-skill",
@@ -53,6 +53,7 @@ Core packages on npm (source: [github.com/earendil-works/pi](https://github.com/
53
53
  - **Skills** — Markdown capability packages (`SKILL.md` + frontmatter) following the Agent Skills standard. Pi loads names + descriptions into the system prompt; bodies load on demand. → `references/skills.md`
54
54
  - **Settings** — Hierarchical JSON: project `.pi/settings.json` merges over global `~/.pi/agent/settings.json`. → `references/settings.md`
55
55
  - **Packages** — Bundles of extensions/skills/prompts/themes via npm, git, or local paths. Installed with `pi install`. → `references/packages.md`
56
+ - **Project trust** — Pi 0.79+ asks before loading project-local settings, resources, and packages; decisions persist in `~/.pi/agent/trust.json`. `--approve`/`--no-approve` override per run; `defaultProjectTrust` sets the non-interactive fallback. → `references/settings.md`
56
57
  - **Context files & prompt templates** — Pi loads `AGENTS.md` / `CLAUDE.md` from the agent dir and from `cwd` up through ancestors. `.pi/SYSTEM.md` replaces the system prompt; `APPEND_SYSTEM.md` appends. Prompt templates in `prompts/` become slash commands. → `references/settings.md`
57
58
  - **SDK** — Programmatic embedding via `createAgentSession()`; `createAgentSessionRuntime()` for session replacement. → `references/sdk.md`
58
59
  - **Custom providers & models** — `models.json` or extension `pi.registerProvider()` for any OpenAI-/Anthropic-/Google-compatible or custom LLM endpoint. → `references/providers.md`
@@ -25,6 +25,7 @@ import { Text } from "@earendil-works/pi-tui";
25
25
 
26
26
  - Use `typebox` (1.x) for schemas.
27
27
  - Use `StringEnum` from `@earendil-works/pi-ai` for Google-compatible string enums.
28
+ - Pi 0.80.0 moved pi-ai's old global API (`getModel`, `getModels`, `stream`, `complete`, `registerApiProvider`, ...) off the pi-ai root entrypoint to `@earendil-works/pi-ai/compat`. Extensions keep working unchanged at runtime (the extension loader aliases the root to the compat superset), but extension sources that typecheck against pi-ai's published types must import those APIs from `@earendil-works/pi-ai/compat`. `StringEnum` and the type surface remain on the root. The compat entrypoint and loader alias will be removed in a future release.
28
29
 
29
30
  ## Quick Start
30
31
 
@@ -75,8 +76,12 @@ Useful session events:
75
76
  - `session_compact`
76
77
  - `session_before_tree`
77
78
  - `session_tree`
79
+ - `session_info_changed` — observe session display-name changes
78
80
  - `session_shutdown`
79
81
  - `resources_discover`
82
+ - `project_trust` — user/global and CLI extensions only, fired before project resources load; return `{ trusted: "yes" | "no" | "undecided" }` (optionally `remember: true` to persist). The first yes/no decision wins and suppresses the built-in trust prompt.
83
+
84
+ `session_before_compact` and `session_compact` carry `reason` and `willRetry` (Pi 0.79.10) so handlers can distinguish manual `/compact`, threshold auto-compaction, and overflow-retry compaction.
80
85
 
81
86
  `session_start` carries `event.reason` — `"startup" | "reload" | "new" | "resume" | "fork"` — and `event.previousSessionFile` for `"new"`/`"resume"`/`"fork"`. The old post-transition `session_switch` / `session_fork` events were removed; route all of those flows through `session_start`.
82
87
 
@@ -85,13 +90,15 @@ Useful agent events:
85
90
  - `input` — carries `event.streamingBehavior` (`"steer" | "followUp" | undefined`) so handlers can distinguish idle prompts, mid-stream steers, and queued follow-ups; return `{ action: "transform" | "handled" | "continue" }`
86
91
  - `before_agent_start` — receives `event.systemPromptOptions` (a `BuildSystemPromptOptions`) so handlers can inspect the structured inputs feeding the system prompt
87
92
  - `agent_start`
88
- - `agent_end`
93
+ - `agent_end` — one low-level run; Pi may still auto-retry, auto-compact and retry, or continue with queued follow-ups
94
+ - `agent_settled` (Pi 0.80.4) — fired when no retry/compaction/follow-up remains; use for status integrations that need to know Pi will not continue automatically (`ctx.isIdle()` is true here unless another extension started a new run)
89
95
  - `turn_start`
90
96
  - `turn_end`
91
97
  - `message_start`
92
98
  - `message_update`
93
99
  - `message_end` — return a replacement message to override usage/cost or rewrite the finalized assistant message
94
100
  - `context`
101
+ - `before_provider_headers` (Pi 0.80.4) — mutate `event.headers` in place after outgoing HTTP headers are assembled: set a key to a string to add/override, `null` to delete. Runs once per provider request; retries reuse the same headers
95
102
  - `before_provider_request`
96
103
  - `after_provider_response` — inspect the provider HTTP status and headers before stream consumption
97
104
  - `model_select`
@@ -116,8 +123,8 @@ Tool results may include `terminate: true` to end the current tool batch without
116
123
  - `ctx.ui` for interactive UI hooks
117
124
  - `ctx.mode` — `"tui" | "rpc" | "json" | "print"`; gate terminal-only features on `ctx.mode === "tui"`
118
125
  - `ctx.cwd`
119
- - `ctx.sessionManager` (read-only)
120
- - `ctx.modelRegistry` / `ctx.model`
126
+ - `ctx.sessionManager` (read-only; `buildContextEntries()` returns active-branch entries with compaction applied, Pi 0.80.4)
127
+ - `ctx.modelRegistry` / `ctx.model` — `ctx.modelRegistry` is the synchronous extension-facing facade; its `refresh()` became `Promise<void>` in Pi 0.80.8 (await it before synchronous registry reads)
121
128
  - `ctx.hasUI` — `true` in TUI and RPC modes
122
129
  - `ctx.signal` — the active agent abort signal (or `undefined` when idle); pass it to `fetch`/model calls for abort-aware nested work
123
130
  - `ctx.isIdle()` / `ctx.hasPendingMessages()`
@@ -125,6 +132,9 @@ Tool results may include `terminate: true` to end the current tool batch without
125
132
  - `ctx.getContextUsage()`
126
133
  - `ctx.compact(options?)` — trigger compaction without awaiting completion
127
134
  - `ctx.getSystemPrompt()`
135
+ - `ctx.isProjectTrusted()` — the effective project trust decision, including temporary `--approve`/`--no-approve` decisions
136
+
137
+ Use `CONFIG_DIR_NAME` (exported from `@earendil-works/pi-coding-agent`) instead of hardcoding `.pi` when building project config paths, e.g. `join(ctx.cwd, CONFIG_DIR_NAME, "my-extension.json")`.
128
138
 
129
139
  Command handlers receive `ExtensionCommandContext`, which extends the above with session-control methods that would deadlock from event handlers: `ctx.getSystemPromptOptions()` (inspect the base system-prompt inputs), `ctx.waitForIdle()`, `ctx.newSession()`, `ctx.fork()`, `ctx.switchSession()`, `ctx.navigateTree()`, and `ctx.reload()`.
130
140
 
@@ -163,6 +173,19 @@ Important rules:
163
173
  4. Use the file-mutation queue for write/edit style tools.
164
174
  5. Put reconstructable state in `details`; it persists in session history.
165
175
 
176
+ ## Dynamic Tool Loading
177
+
178
+ Pi 0.80.7 lets an extension register many tools while keeping only a small initial set active, then add more during execution — cache-friendly on models with native deferred loading. Lifecycle:
179
+
180
+ 1. Register every tool with `pi.registerTool()` (all appear in `pi.getAllTools()`).
181
+ 2. Keep a loader tool (e.g. `search_tools`) active; leave searchable tools inactive — e.g. on `session_start`, `pi.setActiveTools()` to the filtered set.
182
+ 3. During loader execution, call `pi.setActiveTools([...pi.getActiveTools(), ...matches])`. The change must be purely additive; unknown names are ignored.
183
+ 4. Pi records the added tools on that tool result and exposes their definitions before the next model response.
184
+
185
+ Native deferred loading preserves the cached prompt prefix on Anthropic Sonnet/Opus/Fable ≥ 4.5 (not Haiku) and OpenAI `gpt-5.4`+; Kimi K3 works via `compat.deferredToolsMode: "kimi"` (Pi 0.80.9). For verified custom models/proxies, enable `compat.supportsToolReferences: true` (`anthropic-messages`) or `compat.supportsToolSearch: true` (`openai-responses`/`openai-codex-responses`). All other models fall back to sending the full active tool list on the next request — activation still works, but may invalidate the provider's cached prefix. Non-additive changes (removals/replacements) always use the fallback.
186
+
187
+ Cache tips: keep the loader active for the whole session; add rather than replace. Activating a tool that has `promptSnippet`/`promptGuidelines` rebuilds the system prompt and can invalidate the prefix even with native support — lazily loaded tools should rely on their `description` alone.
188
+
166
189
  ## UI Methods
167
190
 
168
191
  Check `ctx.hasUI` first. Non-interactive modes may not support UI.
@@ -191,7 +214,11 @@ const editorFactory = ctx.ui.getEditorComponent(); // wrap the a
191
214
 
192
215
  ctx.ui.setToolsExpanded(true);
193
216
 
194
- ctx.ui.addAutocompleteProvider((query, ctx) => /* completions */); // stack on top of slash/path provider
217
+ ctx.ui.addAutocompleteProvider((current) => ({ // stack on top of slash/path provider
218
+ triggerCharacters: ["#"], // optional natural triggers (Pi 0.79.1)
219
+ async getSuggestions(lines, cursorLine, cursorCol, options) { /* ... or delegate to current */ },
220
+ applyCompletion(...args) { return current.applyCompletion(...args); },
221
+ }));
195
222
 
196
223
  const result = await ctx.ui.custom((tui, theme, keybindings, done) => {
197
224
  return new Text("Press Enter", 0, 0);
@@ -228,6 +255,15 @@ Store extension state with custom session entries:
228
255
  pi.appendEntry("my-extension-state", { key: "value" });
229
256
  ```
230
257
 
258
+ Custom entries never participate in LLM context. Since Pi 0.80.4 they can also render in the interactive transcript via `pi.registerEntryRenderer(customType, renderer)` — the TUI-only counterpart to `pi.registerMessageRenderer()` (whose custom messages DO enter LLM context via `pi.sendMessage()`):
259
+
260
+ ```typescript
261
+ pi.registerEntryRenderer("status-card", (entry, { expanded }, theme) => {
262
+ return new Text(theme.fg("accent", JSON.stringify(entry.data)));
263
+ });
264
+ pi.appendEntry("status-card", { title: "Indexed files", count: 17 });
265
+ ```
266
+
231
267
  Use lifecycle hooks to restore it:
232
268
 
233
269
  ```typescript
@@ -268,12 +304,16 @@ pi.registerProvider("anthropic", { baseUrl: "https://proxy.example.com" });
268
304
  pi.unregisterProvider("my-provider");
269
305
  ```
270
306
 
307
+ Dynamic providers can implement `refreshModels(context)` (Pi 0.80.8) for model discovery: Pi calls it during catalog refresh (`/model`, `pi update --models`) and publishes the returned list; its models replace extension-provided `models`. Persist results through the scoped `context.store` only when they should survive restarts — live servers like llama.cpp can ignore it.
308
+
271
309
  If you need auth for a specific model request, use:
272
310
 
273
311
  ```typescript
274
312
  const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
275
313
  ```
276
314
 
315
+ (Still supported for extensions in Pi 0.80.8+; SDK code should use `ModelRuntime.getAuth()` — see `references/sdk.md`.)
316
+
277
317
  Pass `shouldStopAfterTurn` via the SDK to exit the agent loop gracefully after a completed turn. See `references/sdk.md` and `references/providers.md` for the full provider/model schema.
278
318
 
279
319
  ## Handy Patterns
@@ -16,16 +16,21 @@ pi install ./relative/path/to/package
16
16
  pi remove npm:@foo/bar
17
17
  pi uninstall npm:@foo/bar
18
18
  pi list
19
- pi update # update pi itself + all installed packages (skips pinned)
20
- pi update --self # update pi only
19
+ pi update # update pi only (changed in Pi 0.79.7)
20
+ pi update --all # update pi + packages, reconcile pinned git refs
21
21
  pi update --extensions # update packages only
22
+ pi update --models # refresh model catalogs only (Pi 0.80.8)
23
+ pi update --self # update pi only
22
24
  pi update <source> # update one package
23
- pi config
25
+ pi config # starts in global settings; Tab switches scope
26
+ pi config -l # start in project overrides (.pi/settings.json)
24
27
  ```
25
28
 
26
- By default, `install` and `remove` write to user settings (`~/.pi/agent/settings.json`). Use `-l` to write to project settings (`.pi/settings.json`) instead.
29
+ By default, `install` and `remove` write to user settings (`~/.pi/agent/settings.json`). Use `-l` to write to project settings (`.pi/settings.json`) instead. `pi update` installs the exact version returned by the update check.
30
+
31
+ Package commands follow the project trust flow (`pi update` never prompts); pass `--approve`/`-a` or `--no-approve`/`-na` to trust or ignore project-local settings for one command.
27
32
 
28
- Project installs are shareable with a team. Pi will install missing project packages automatically on startup.
33
+ Project installs are shareable with a team. Pi will install missing project packages automatically on startup once the project is trusted.
29
34
 
30
35
  For temporary one-run testing, use `--extension` / `-e` with an npm or git source. Pi installs it into a temporary directory for that run only.
31
36
 
@@ -40,7 +45,7 @@ npm:pkg
40
45
 
41
46
  - User installs go under `~/.pi/agent/npm/`
42
47
  - Project installs go under `.pi/npm/`
43
- - Version-pinned installs are skipped by `pi update`
48
+ - Version-pinned installs are skipped by `pi update --extensions` / `--all`
44
49
  - Use `npmCommand` in settings if you need a wrapper such as `mise` or `asdf`
45
50
 
46
51
  ### git
@@ -54,7 +59,7 @@ ssh://git@github.com/user/repo@v1
54
59
 
55
60
  - Global clones live in `~/.pi/agent/git/`
56
61
  - Project clones live in `.pi/git/`
57
- - Refs pin the package and are skipped by `pi update`
62
+ - Refs pin the package; `pi update --extensions` / `--all` do not move them to newer refs but do reconcile the clone to the configured ref — use `pi install git:host/user/repo@new-ref` to move a pin
58
63
  - Pi runs `npm install` after clone/pull when `package.json` exists
59
64
 
60
65
  ### local paths
@@ -126,6 +131,6 @@ Rules:
126
131
 
127
132
  ## Scope and Deduplication
128
133
 
129
- - Project settings override global settings for the same package identity
134
+ - Project settings override global settings for the same package identity — unless the project entry has `autoload: false`, in which case it is applied as a delta over the global entry (Pi 0.80.4)
130
135
  - Identity is package name for npm, repo URL for git, and resolved absolute path for local sources
131
- - `pi config` can enable or disable package resources after installation
136
+ - `pi config` can enable or disable package resources after installation; since Pi 0.80.4 it manages global vs project-local scopes (Tab to switch, `pi config -l` to start in project mode with inherited global resources dimmed)
@@ -9,8 +9,12 @@ Use `/login` in interactive mode, then select a provider. The `/login` selector
9
9
  - Anthropic Claude Pro / Max — third-party usage draws from extra usage and is billed per token (suppress the warning via `warnings.anthropicExtraUsage`)
10
10
  - OpenAI ChatGPT Plus / Pro (Codex) — `/login` defaults to browser auth but can use a device-code flow for headless environments
11
11
  - GitHub Copilot
12
+ - xAI (Grok/X subscription, Pi 0.80.8) — `/login xai` then **Use a subscription** (device-code OAuth); `XAI_API_KEY` remains available via **Use an API key**
13
+ - Radius (Pi 0.80.8) — a dynamic `pi-messages` gateway; `/login radius` stores OAuth tokens, and custom Radius gateways can be declared in `models.json` with `"oauth": "radius"` plus a gateway `baseUrl`
12
14
 
13
- Use `/logout` to clear stored OAuth credentials. Pi 0.71.0 removed built-in Google Gemini CLI and Google Antigravity providers.
15
+ `/login <provider>` with autocomplete works since Pi 0.80.4, and login methods are provider-owned since 0.80.8 (registered pi-ai providers expose their own auth options and status in `/login`). Use `/logout` to clear stored OAuth credentials. Pi 0.71.0 removed built-in Google Gemini CLI and Google Antigravity providers.
16
+
17
+ Since Pi 0.80.8, built-in catalogs are complemented by dynamic ones: `/model` refreshes configured providers in the background, `pi update --models` forces an immediate refresh, and refreshed catalogs are cached in `~/.pi/agent/models-store.json` for offline use.
14
18
 
15
19
  ## API Key Providers
16
20
 
@@ -35,6 +39,8 @@ Use `/logout` to clear stored OAuth credentials. Pi 0.71.0 removed built-in Goog
35
39
  | ZAI Coding Plan (China) | `ZAI_CODING_CN_API_KEY` | `zai-coding-cn` |
36
40
  | OpenCode Zen | `OPENCODE_API_KEY` | `opencode` |
37
41
  | OpenCode Go | `OPENCODE_API_KEY` | `opencode-go` |
42
+ | Amazon Bedrock | `AWS_BEARER_TOKEN_BEDROCK` | `amazon-bedrock` |
43
+ | Radius | `RADIUS_API_KEY` | `radius` |
38
44
  | Hugging Face | `HF_TOKEN` | `huggingface` |
39
45
  | Fireworks | `FIREWORKS_API_KEY` | `fireworks` |
40
46
  | Together AI | `TOGETHER_API_KEY` | `together` |
@@ -52,16 +58,25 @@ Use `/logout` to clear stored OAuth credentials. Pi 0.71.0 removed built-in Goog
52
58
  {
53
59
  "anthropic": { "type": "api_key", "key": "sk-ant-..." },
54
60
  "openai": { "type": "api_key", "key": "!op read 'OpenAI API Key'" },
55
- "google": { "type": "api_key", "key": "GEMINI_API_KEY" },
56
- "together": { "type": "api_key", "key": "TOGETHER_API_KEY" }
61
+ "google": { "type": "api_key", "key": "$GEMINI_API_KEY" },
62
+ "cloudflare-ai-gateway": {
63
+ "type": "api_key",
64
+ "key": "$CLOUDFLARE_API_KEY",
65
+ "env": {
66
+ "CLOUDFLARE_ACCOUNT_ID": "account-id",
67
+ "CLOUDFLARE_GATEWAY_ID": "gateway-id"
68
+ }
69
+ }
57
70
  }
58
71
  ```
59
72
 
60
73
  `key` values can be:
61
74
 
62
75
  - A literal secret
63
- - An environment variable name
64
- - A shell command prefixed with `!`
76
+ - `$ENV_VAR` / `${ENV_VAR}` environment interpolation (works inside larger literals). Plain uppercase names without `$` are treated as literals since Pi 0.79.4 — the old bare-env-var-name form no longer resolves.
77
+ - A shell command prefixed with `!` (stdout is used, cached for the process lifetime)
78
+
79
+ Entries may include an `env` object (Pi 0.79.5) for provider-scoped environment overrides — Cloudflare account/gateway IDs, Azure endpoints, Vertex project/location, Bedrock config, cache retention, proxies — applied without changing the project shell.
65
80
 
66
81
  ## Credential Resolution Order
67
82
 
@@ -77,8 +92,10 @@ Use `/logout` to clear stored OAuth credentials. Pi 0.71.0 removed built-in Goog
77
92
  ```bash
78
93
  export AZURE_OPENAI_API_KEY=...
79
94
  export AZURE_OPENAI_BASE_URL=https://your-resource.openai.azure.com
80
- # Cognitive Services endpoints are also supported and auto-normalized to /openai/v1:
95
+ # Cognitive Services and modern Microsoft Foundry endpoint URLs are also
96
+ # supported; root endpoints are auto-normalized to /openai/v1:
81
97
  # export AZURE_OPENAI_BASE_URL=https://your-resource.cognitiveservices.azure.com
98
+ # export AZURE_OPENAI_BASE_URL=https://your-resource.ai.azure.com
82
99
  # Or supply the resource name only:
83
100
  export AZURE_OPENAI_RESOURCE_NAME=your-resource
84
101
 
@@ -88,7 +105,7 @@ export AZURE_OPENAI_DEPLOYMENT_NAME_MAP=gpt-4o=my-gpt4o
88
105
 
89
106
  ### Amazon Bedrock
90
107
 
91
- Pi supports standard AWS auth flows:
108
+ `/login amazon-bedrock` stores a Bedrock API key (Pi 0.80.7). Ambient AWS credential flows also work — these keep using SigV4 authentication:
92
109
 
93
110
  - `AWS_PROFILE`
94
111
  - `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`
@@ -156,6 +173,8 @@ Use `models.json` for OpenAI-compatible, Anthropic-compatible, Google-compatible
156
173
  }
157
174
  ```
158
175
 
176
+ `apiKey` is optional (Pi 0.80.0): omit it when auth comes from `/login`, `auth.json`, or CLI `--api-key`. Like `auth.json` keys, `apiKey` and `headers` values support `!command` execution and `$ENV_VAR` interpolation; plain uppercase strings are literals. Keyless local servers (e.g. Ollama) should keep a dummy value so their models appear in `/model`.
177
+
159
178
  Common `api` values:
160
179
 
161
180
  - `"openai-completions"`
@@ -169,10 +188,14 @@ Common `api` values:
169
188
 
170
189
  ### Model & Compatibility Knobs
171
190
 
172
- - `thinkingLevelMap` (Pi 0.72) replaces `compat.reasoningEffortMap`. Map pi levels (`off`/`minimal`/`low`/`medium`/`high`/`xhigh`) to provider values; use `null` to hide a level.
191
+ - `thinkingLevelMap` (Pi 0.72) replaces `compat.reasoningEffortMap`. Map pi levels (`off`/`minimal`/`low`/`medium`/`high`/`xhigh`/`max`) to provider values; use `null` to hide a level. Maps may contain holes (Pi 0.80.6) — e.g. expose `high` and `max` without `xhigh`. When a key is omitted, standard levels through `high` use the provider default mapping, but the extended `xhigh`/`max` levels are unsupported.
192
+ - `cost` supports request-wide input pricing tiers (Pi 0.80.6): a `tiers` array where each tier supplies a complete alternate rate set and applies to the whole request when total input usage (`input + cacheRead + cacheWrite`) exceeds `inputTokensAbove`; the highest matching threshold wins. Also usable in `modelOverrides` and extension-registered providers.
193
+ - `modelOverrides` applies to built-in and (since Pi 0.80.4) extension-registered provider models; per-model fields: `name`, `reasoning`, `thinkingLevelMap`, `input`, `cost` (partial), `contextWindow`, `maxTokens`, `headers`, `compat`.
173
194
  - `openRouterRouting` is forwarded as-is in the OpenRouter `provider` field (fallbacks, ZDR, ignore lists, throughput/latency).
174
- - `compat.thinkingFormat` supports OpenAI-compatible reasoning variants: `openrouter` sends `reasoning: { effort }`, `together` sends `reasoning: { enabled }` plus `reasoning_effort` when supported, and `qwen-chat-template` targets local Qwen-compatible servers that read `chat_template_kwargs.enable_thinking`.
175
- - Advanced `compat` flags exist for proxy quirks (`cacheControlFormat`, `supportsReasoningEffort`, `supportsLongCacheRetention`, `supportsEagerToolInputStreaming`, `sendSessionIdHeader`, `sendSessionAffinityHeaders`). See [Pi `docs/models.md`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/models.md) when a proxy rejects pi's defaults.
195
+ - `compat.thinkingFormat` supports OpenAI-compatible reasoning variants: `openrouter` sends `reasoning: { effort }`, `together` sends `reasoning: { enabled }` plus `reasoning_effort` when supported, `qwen-chat-template` targets local Qwen-compatible servers that read `chat_template_kwargs.enable_thinking`, and `chat-template` (Pi 0.79.9) sends configurable `chat_template_kwargs` via `compat.chatTemplateKwargs` — e.g. `{ "thinking": { "$var": "thinking.enabled" } }` for DeepSeek models behind vLLM/Hugging Face chat templates (`"$var"` accepts `"thinking.enabled"` or `"thinking.effort"`).
196
+ - **Breaking (Pi 0.80.7):** `compat.sendSessionIdHeader` was removed. Session affinity is now controlled by `compat.sessionAffinityFormat` (`"openai"` sends `session_id`/`x-client-request-id`, `"openai-nosession"` omits the underscore-containing `session_id` header, `"openrouter"` sends `x-session-id`; default auto-detected). Replace `sendSessionIdHeader: false` with `sessionAffinityFormat: "openai-nosession"`. `sendSessionAffinityHeaders` still gates the behavior for `openai-completions`.
197
+ - `compat.deferredToolsMode: "kimi"` (Pi 0.80.9) enables Kimi's deferred tool serialization; `compat.supportsToolReferences` / `compat.supportsToolSearch` enable native dynamic tool loading on verified custom endpoints (see `references/extensions.md`).
198
+ - Advanced `compat` flags exist for proxy quirks (`cacheControlFormat`, `supportsReasoningEffort`, `supportsLongCacheRetention`, `supportsEagerToolInputStreaming`, `supportsStrictMode`). See [Pi `docs/models.md`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/models.md) when a proxy rejects pi's defaults.
176
199
 
177
200
  ### Context Overflow Recovery
178
201
 
@@ -206,7 +229,7 @@ pi.registerProvider("anthropic", { baseUrl: "https://proxy.example.com" });
206
229
 
207
230
  ## SDK / Extension Auth Lookup
208
231
 
209
- If extension or SDK code needs auth for a specific model request, use `getApiKeyAndHeaders(model)` rather than the removed `getApiKey(model)`:
232
+ If extension code needs auth for a specific model request, use `getApiKeyAndHeaders(model)` rather than the removed `getApiKey(model)`:
210
233
 
211
234
  ```typescript
212
235
  const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
@@ -215,4 +238,4 @@ if (!auth.ok) throw new Error(auth.error);
215
238
  const { apiKey, headers } = auth;
216
239
  ```
217
240
 
218
- This matters for providers whose headers or auth values resolve dynamically on every request.
241
+ This matters for providers whose headers or auth values resolve dynamically on every request. In SDK code, use `ModelRuntime.getAuth(providerOrModel)` instead (Pi 0.80.8) — passing a model also resolves built-in, `models.json`, and extension model headers; see `references/sdk.md`.
@@ -12,19 +12,16 @@ npm install @earendil-works/pi-coding-agent
12
12
 
13
13
  ```typescript
14
14
  import {
15
- AuthStorage,
16
15
  createAgentSession,
17
- ModelRegistry,
16
+ ModelRuntime,
18
17
  SessionManager,
19
18
  } from "@earendil-works/pi-coding-agent";
20
19
 
21
- const authStorage = AuthStorage.create();
22
- const modelRegistry = ModelRegistry.create(authStorage);
20
+ const modelRuntime = await ModelRuntime.create();
23
21
 
24
22
  const { session } = await createAgentSession({
25
23
  sessionManager: SessionManager.inMemory(),
26
- authStorage,
27
- modelRegistry,
24
+ modelRuntime,
28
25
  });
29
26
 
30
27
  session.subscribe((event) => {
@@ -38,38 +35,37 @@ await session.prompt("What files are in the current directory?");
38
35
 
39
36
  Run with `npx tsx my-script.ts`.
40
37
 
41
- **Important:** `ModelRegistry` no longer has a public constructor. Use `ModelRegistry.create(authStorage, modelsJsonPath?)` for file-backed registries or `ModelRegistry.inMemory(authStorage)` for built-in models only.
38
+ **Breaking (Pi 0.80.8):** `ModelRuntime` replaced the old `AuthStorage`/`ModelRegistry` pair as the SDK model/auth facade. `CreateAgentSessionOptions.authStorage` and `modelRegistry` are gone — pass the async `modelRuntime` instead. `AuthStorage` is no longer exported; use `ModelRuntime` (or a custom pi-ai `CredentialStore`), or `readStoredCredential()` for one-off reads of `auth.json`. `ModelRegistry` still exists only as the synchronous extension-facing compatibility facade, and its `refresh()` is now `Promise<void>`.
42
39
 
43
40
  ## Key Imports
44
41
 
45
42
  ```typescript
46
43
  import {
47
- AuthStorage,
48
44
  createAgentSession,
49
45
  DefaultResourceLoader,
50
46
  defineTool,
51
- ModelRegistry,
47
+ ModelRuntime,
52
48
  SessionManager,
53
49
  } from "@earendil-works/pi-coding-agent";
54
- import { getModel } from "@earendil-works/pi-ai";
50
+ import { getBuiltinModel } from "@earendil-works/pi-ai/providers/all";
55
51
  ```
56
52
 
53
+ **pi-ai 0.80.0 API move:** the old global API (`getModel`, `getModels`, `getProviders`, `stream`, `complete`, `completeSimple`, `registerApiProvider`, `getEnvApiKey`, ...) moved off the `@earendil-works/pi-ai` root entrypoint to `@earendil-works/pi-ai/compat` (a deprecated shim slated for removal). For built-in model lookup use `getBuiltinModel(provider, modelId)` from `@earendil-works/pi-ai/providers/all`, or the provider-factory API (`createModels()` / `Models.getModel()`). Extensions loaded by Pi are unaffected at runtime — the extension loader aliases the pi-ai root to the compat superset — but standalone SDK scripts and typechecked extension sources must use the new paths. The selective `@earendil-works/pi-ai/base` / `@earendil-works/pi-agent-core/base` entrypoints introduced in 0.79.8 were removed again in 0.80.0.
54
+
57
55
  ## Core Options
58
56
 
59
57
  ```typescript
60
58
  const cwd = "/path/to/project";
61
- const authStorage = AuthStorage.create();
62
- const modelRegistry = ModelRegistry.create(authStorage);
59
+ const modelRuntime = await ModelRuntime.create();
63
60
 
64
61
  const { session } = await createAgentSession({
65
62
  cwd,
66
63
  agentDir: "~/.pi/agent",
67
- authStorage,
68
- modelRegistry,
69
- model: getModel("anthropic", "claude-opus-4-8"),
70
- thinkingLevel: "medium",
64
+ modelRuntime,
65
+ model: getBuiltinModel("anthropic", "claude-opus-4-8"),
66
+ thinkingLevel: "medium", // off | minimal | low | medium | high | xhigh | max
71
67
  scopedModels: [
72
- { model: getModel("anthropic", "claude-opus-4-8"), thinkingLevel: "high" },
68
+ { model: getBuiltinModel("anthropic", "claude-opus-4-8"), thinkingLevel: "high" },
73
69
  ],
74
70
  tools: ["read", "bash", "edit", "write"],
75
71
  customTools: [/* defineTool(...) entries */],
@@ -88,6 +84,50 @@ Notes:
88
84
  - `DefaultResourceLoader` loads extensions, skills, prompt templates, themes, and context files. Replace it to drive resource discovery from custom sources (and it must implement `loadProjectContextFiles()` if you want `AGENTS.md`/`CLAUDE.md` discovery; that helper is also exported standalone).
89
85
  - Pass `shouldStopAfterTurn(state) => boolean` (Pi 0.72.0) to exit the agent loop gracefully after a completed turn.
90
86
 
87
+ ## Models & Auth (`ModelRuntime`)
88
+
89
+ `ModelRuntime` (Pi 0.80.8) implements the pi-ai `Models` interface and owns credential storage. Auth resolution priority: runtime overrides (`setRuntimeApiKey`, not persisted) → stored credentials in `auth.json` → environment variables → fallback resolver for `models.json` keys.
90
+
91
+ ```typescript
92
+ import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
93
+ import { ModelRuntime } from "@earendil-works/pi-coding-agent";
94
+
95
+ // Default: ~/.pi/agent/auth.json and ~/.pi/agent/models.json
96
+ const modelRuntime = await ModelRuntime.create();
97
+
98
+ // Model lookup (use pi-ai Models methods directly; the old
99
+ // getAll()/find()/getSnapshot() projections were removed)
100
+ const model = modelRuntime.getModel("my-provider", "my-model");
101
+ const available = await modelRuntime.getAvailable(); // only models with valid auth
102
+
103
+ // Provider-owned auth methods and current status
104
+ for (const provider of modelRuntime.getProviders()) {
105
+ const status = await modelRuntime.checkAuth(provider.id);
106
+ }
107
+
108
+ modelRuntime.setRuntimeApiKey("anthropic", "sk-my-temp-key");
109
+
110
+ // Custom locations, or inject any pi-ai CredentialStore
111
+ const custom = await ModelRuntime.create({ authPath: "/my/auth.json", modelsPath: "/my/models.json" });
112
+ const inMemory = await ModelRuntime.create({ credentials: new InMemoryCredentialStore() });
113
+ ```
114
+
115
+ `ModelRuntime.getAuth(providerOrModel)` assembles final request auth (replacing `ModelRegistry.getApiKeyAndHeaders()` on the SDK side); passing a model also resolves built-in, `models.json`, and extension model headers. Dynamic provider catalogs refresh via async `ModelRuntime.refresh()` and are cached in `~/.pi/agent/models-store.json`.
116
+
117
+ To match CLI model parsing, use the exported resolver helpers (Pi 0.80.4):
118
+
119
+ ```typescript
120
+ import { resolveCliModel, resolveModelScopeWithDiagnostics } from "@earendil-works/pi-coding-agent";
121
+
122
+ const cliModel = resolveCliModel({ cliModel: "anthropic/claude-opus-4-8:high", modelRuntime });
123
+ const { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(
124
+ ["anthropic/*:high", "gpt-5"],
125
+ modelRuntime,
126
+ );
127
+ ```
128
+
129
+ `resolveCliModel()` resolves against all registered models (so `--api-key`-style first-time setup works before stored auth exists); `resolveModelScopeWithDiagnostics()` matches `--models`/`enabledModels` semantics and returns warnings instead of printing.
130
+
91
131
  ## Prompting & Queueing
92
132
 
93
133
  ```typescript
@@ -191,7 +231,8 @@ session.subscribe((event) => {
191
231
  case "tool_execution_update":
192
232
  case "tool_execution_end":
193
233
  case "agent_start":
194
- case "agent_end":
234
+ case "agent_end": // one low-level run; may be followed by retry/compaction/queued follow-ups
235
+ case "agent_settled": // fully settled — no automatic continuation left (Pi 0.80.4)
195
236
  case "turn_start":
196
237
  case "turn_end":
197
238
  case "queue_update":
@@ -204,6 +245,19 @@ session.subscribe((event) => {
204
245
  });
205
246
  ```
206
247
 
248
+ `compaction_end` results and RPC `compact` responses include estimated post-compaction token counts (Pi 0.79.8) so clients can show the approximate context reduction.
249
+
250
+ ## RPC Mode
251
+
252
+ `pi --mode rpc` speaks newline-delimited JSON over stdio. Additions since Pi 0.79:
253
+
254
+ - `agent_settled` event (Pi 0.80.4) fires when a run is fully settled — no automatic retry, compaction retry, or queued continuation remains; `agent_end` now carries `willRetry`. `set_thinking_level` accepts `"max"` where the model supports it.
255
+ - `get_entries` / `get_tree` (Pi 0.80.3) read session entries and tree snapshots over RPC.
256
+ - `@earendil-works/pi-coding-agent/rpc-entry` (Pi 0.80.3) launches Pi directly in RPC mode from an importing process.
257
+ - RPC extension UI request/response types are exported from the public API (Pi 0.79.0).
258
+ - Package asset path helpers are exported from the public API (Pi 0.79.0).
259
+ - `CONFIG_DIR_NAME` and edit diff helpers (`generateDiffString`, `generateUnifiedPatch`, `EditDiffResult`) are exported for extensions and hosts (Pi 0.79.7).
260
+
207
261
  ## Resource Loader Hooks
208
262
 
209
263
  `DefaultResourceLoader` supports overrides for extensions, skills, prompts, themes, and context files. Common patterns:
@@ -213,6 +267,20 @@ session.subscribe((event) => {
213
267
  - Add custom skills or prompt templates without touching disk
214
268
  - Share an event bus between the host app and loaded extensions
215
269
 
270
+ To name an inline factory in the startup Extensions list (instead of `<inline:1>`), wrap it in an `InlineExtension` (Pi 0.80.4):
271
+
272
+ ```typescript
273
+ import type { InlineExtension } from "@earendil-works/pi-coding-agent";
274
+
275
+ const myProvider: InlineExtension = {
276
+ name: "my-provider",
277
+ factory: (pi) => { /* ... */ },
278
+ };
279
+ const loader = new DefaultResourceLoader({ extensionFactories: [myProvider] });
280
+ ```
281
+
282
+ Bare factory functions are still accepted.
283
+
216
284
  ## Standalone Custom Tools
217
285
 
218
286
  Use `defineTool()` when you want a reusable custom tool definition outside `pi.registerTool(...)`:
@@ -17,6 +17,7 @@ Edit JSON directly or use `/settings` for common interactive options.
17
17
  "defaultModel": "claude-sonnet-4-20250514",
18
18
  "defaultThinkingLevel": "medium",
19
19
  "hideThinkingBlock": false,
20
+ "showCacheMissNotices": false,
20
21
  "thinkingBudgets": {
21
22
  "minimal": 1024,
22
23
  "low": 4096,
@@ -26,8 +27,9 @@ Edit JSON directly or use `/settings` for common interactive options.
26
27
  }
27
28
  ```
28
29
 
29
- - Thinking levels: `"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`
30
+ - Thinking levels: `"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"` — `max` (Pi 0.80.6) is an opt-in level above `xhigh`, exposed only when the selected model supports it (some models, e.g. GPT-5.6, expose both). Custom themes can define `thinkingMax`; existing themes fall back to `thinkingXhigh`.
30
31
  - `hideThinkingBlock` hides visible thinking output in the UI
32
+ - `showCacheMissNotices` (Pi 0.80.4) shows transcript notices for significant prompt-cache misses
31
33
 
32
34
  ## UI & Display
33
35
 
@@ -39,14 +41,19 @@ Edit JSON directly or use `/settings` for common interactive options.
39
41
  "doubleEscapeAction": "tree",
40
42
  "treeFilterMode": "default",
41
43
  "editorPaddingX": 0,
44
+ "outputPad": 1,
42
45
  "autocompleteMaxVisible": 5,
43
- "showHardwareCursor": false
46
+ "showHardwareCursor": false,
47
+ "externalEditor": "code --wait"
44
48
  }
45
49
  ```
46
50
 
47
51
  - `doubleEscapeAction`: `"tree"`, `"fork"`, or `"none"`
48
52
  - `treeFilterMode`: `"default"`, `"no-tools"`, `"user-only"`, `"labeled-only"`, or `"all"`
49
53
  - In `/tree`, `Shift+T` toggles timestamps on entry labels
54
+ - `theme` also accepts `"light-name/dark-name"` (Pi 0.79.7) to switch themes automatically with the terminal color scheme; `/` is reserved in theme names for this. On first run Pi detects the terminal background and defaults to `dark` or `light`.
55
+ - `outputPad` (Pi 0.80.3, `0` or `1`) sets horizontal padding for user messages, assistant messages, and thinking blocks.
56
+ - `externalEditor` (Pi 0.80.3) sets the `Ctrl+G` external editor command and takes precedence over `$VISUAL`/`$EDITOR`.
50
57
 
51
58
  ## Compaction, Branch Summary, Retry
52
59
 
@@ -89,7 +96,8 @@ Notes:
89
96
  "followUpMode": "one-at-a-time",
90
97
  "transport": "auto",
91
98
  "httpIdleTimeoutMs": 300000,
92
- "websocketConnectTimeoutMs": 15000
99
+ "websocketConnectTimeoutMs": 15000,
100
+ "httpProxy": "http://127.0.0.1:7890"
93
101
  }
94
102
  ```
95
103
 
@@ -97,6 +105,7 @@ Notes:
97
105
  - `transport` (default `"auto"`): `"sse"`, `"websocket"`, `"websocket-cached"`, or `"auto"` — the preferred transport for providers that support several
98
106
  - `httpIdleTimeoutMs` (default `300000`) is the HTTP header/body idle timeout, also applied as the default SDK request timeout for providers that support it (e.g. OpenAI Codex WebSocket waits, llama.cpp). Set to `0` to disable.
99
107
  - `websocketConnectTimeoutMs` (default `15000`) bounds the WebSocket connect/open handshake. Set to `0` to disable.
108
+ - `httpProxy` (Pi 0.79.5, global settings only) is applied as `HTTP_PROXY` and `HTTPS_PROXY` for Pi-managed HTTP clients.
100
109
 
101
110
  ## Terminal, Images, and Shell
102
111
 
@@ -118,6 +127,7 @@ Notes:
118
127
  }
119
128
  ```
120
129
 
130
+ - `shellPath` supports a leading `~` for the home directory (Pi 0.80.6).
121
131
  - `npmCommand` is argv-style and is used for npm lookup/install operations, including git-package installs. User-scoped npm packages install under `~/.pi/agent/npm/`; project-scoped npm packages install under `.pi/npm/`.
122
132
  - `terminal.showTerminalProgress` (default `false` since Pi 0.70.0) toggles OSC 9;4 progress reporting in supporting terminals (iTerm2, WezTerm, Windows Terminal, Kitty).
123
133
  - `terminal.imageWidthCells` (Pi 0.68.1) caps inline tool-output image width in terminal cells.
@@ -147,6 +157,21 @@ Notes:
147
157
 
148
158
  When multiple sources specify a session directory, `--session-dir` takes precedence over `sessionDir` in settings. Pi 0.65.0 removed the old `session_directory` extension/settings hook.
149
159
 
160
+ ## Project Trust
161
+
162
+ Since Pi 0.79.0, project-local settings, resources, and packages (`.pi/` settings/extensions/skills/prompts/themes, project packages) only load after the project is trusted. `AGENTS.md` / `CLAUDE.md` context files load regardless of trust. Trust is a loading gate, not a sandbox.
163
+
164
+ ```json
165
+ {
166
+ "defaultProjectTrust": "ask"
167
+ }
168
+ ```
169
+
170
+ - Interactive mode prompts on first use; `/trust` saves a decision (written to `~/.pi/agent/trust.json`; restart Pi to apply).
171
+ - `--approve`/`-a` and `--no-approve`/`-na` override trust for one run, including for `pi install` and other package commands. `pi update` never prompts.
172
+ - Non-interactive modes (`-p`, `--mode json`, `--mode rpc`) never prompt. Without a saved decision they follow `defaultProjectTrust` (global setting only): `"ask"` (default) and `"never"` skip project resources; `"always"` trusts them.
173
+ - Extensions can decide or defer trust via the `project_trust` event and inspect the outcome with `ctx.isProjectTrusted()` — see `references/extensions.md`.
174
+
150
175
  ## Resources
151
176
 
152
177
  These settings control what Pi loads from disk or packages:
@@ -214,7 +239,7 @@ pi [options] [@files...] [messages...]
214
239
  --provider <name> e.g. anthropic, openai, google
215
240
  --model <pattern> supports provider/id and optional :<thinking>
216
241
  --api-key <key>
217
- --thinking off|minimal|low|medium|high|xhigh
242
+ --thinking off|minimal|low|medium|high|xhigh|max
218
243
  --models <patterns> Ctrl+P cycling allowlist
219
244
  --list-models [search]
220
245
 
@@ -240,6 +265,11 @@ pi [options] [@files...] [messages...]
240
265
  --no-extensions / --no-skills / --no-prompt-templates / --no-themes
241
266
  --no-context-files, -nc skip AGENTS.md / CLAUDE.md discovery
242
267
 
268
+ # trust and network
269
+ -a, --approve trust project-local files for this run
270
+ -na, --no-approve ignore project-local files for this run
271
+ --offline disable startup network operations (same as PI_OFFLINE=1)
272
+
243
273
  # prompts and misc
244
274
  --system-prompt <text> replace default
245
275
  --append-system-prompt <text> repeatable; appended with double newlines
@@ -259,7 +289,7 @@ pi [options] [@files...] [messages...]
259
289
  | `PI_CACHE_RETENTION` | Set to `long` for extended prompt-cache retention where supported |
260
290
  | `PI_OAUTH_CALLBACK_HOST` | Bind the OAuth callback server to a custom interface |
261
291
  | `PI_CODING_AGENT=true` | Set automatically at startup so subprocesses can detect Pi |
262
- | `VISUAL`, `EDITOR` | External editor for `Ctrl+G` |
292
+ | `VISUAL`, `EDITOR` | External editor for `Ctrl+G` (the `externalEditor` setting takes precedence) |
263
293
  | Provider API key env vars | See `references/providers.md` |
264
294
 
265
295
  ## Practical Notes
@@ -18,7 +18,7 @@ Pi discovers skills from:
18
18
  - Global:
19
19
  - `~/.pi/agent/skills/`
20
20
  - `~/.agents/skills/`
21
- - Project:
21
+ - Project (loaded only after the project is trusted; see project trust in `references/settings.md`):
22
22
  - `.pi/skills/`
23
23
  - `.agents/skills/` in `cwd` and ancestor directories
24
24
  - Packages: