@kingingwang/pi-darwin-arm64 0.85.1 → 0.87.0

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.
Files changed (57) hide show
  1. package/bin/CHANGELOG.md +148 -0
  2. package/bin/README.md +39 -1
  3. package/bin/docs/compaction.md +62 -17
  4. package/bin/docs/custom-provider.md +22 -13
  5. package/bin/docs/development.md +4 -4
  6. package/bin/docs/docs.json +4 -0
  7. package/bin/docs/environment-variables.md +1 -0
  8. package/bin/docs/extensions.md +127 -49
  9. package/bin/docs/json.md +4 -4
  10. package/bin/docs/models.md +61 -2
  11. package/bin/docs/providers.md +10 -2
  12. package/bin/docs/sdk.md +17 -4
  13. package/bin/docs/security.md +1 -1
  14. package/bin/docs/session-format.md +96 -41
  15. package/bin/docs/sessions.md +27 -0
  16. package/bin/docs/settings.md +56 -1
  17. package/bin/docs/termux.md +0 -1
  18. package/bin/docs/tui.md +2 -2
  19. package/bin/docs/usage.md +1 -0
  20. package/bin/examples/extensions/README.md +0 -1
  21. package/bin/examples/extensions/custom-provider-anthropic/index.ts +18 -12
  22. package/bin/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  23. package/bin/examples/extensions/custom-provider-anthropic/package.json +1 -1
  24. package/bin/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  25. package/bin/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  26. package/bin/examples/extensions/gondolin/package-lock.json +2 -2
  27. package/bin/examples/extensions/gondolin/package.json +1 -1
  28. package/bin/examples/extensions/prompt-customizer.ts +19 -67
  29. package/bin/examples/extensions/sandbox/package-lock.json +2 -2
  30. package/bin/examples/extensions/sandbox/package.json +1 -1
  31. package/bin/examples/extensions/with-deps/package-lock.json +2 -2
  32. package/bin/examples/extensions/with-deps/package.json +1 -1
  33. package/bin/examples/plugins/pi-example-plugin/src/session.ts +3 -2
  34. package/bin/export-html/template.js +6 -1
  35. package/bin/native/darwin/prebuilds/darwin-arm64/{darwin-modifiers.node → darwin-platform.node} +0 -0
  36. package/bin/package.json +17 -23
  37. package/bin/pi +2 -2
  38. package/package.json +1 -1
  39. package/bin/examples/extensions/kimi-deferred-tools.ts +0 -61
  40. package/bin/node_modules/@mariozechner/clipboard/.yarnrc.yml +0 -1
  41. package/bin/node_modules/@mariozechner/clipboard/Cargo.toml +0 -45
  42. package/bin/node_modules/@mariozechner/clipboard/README.md +0 -60
  43. package/bin/node_modules/@mariozechner/clipboard/build.rs +0 -5
  44. package/bin/node_modules/@mariozechner/clipboard/clipboard.darwin-arm64.node +0 -0
  45. package/bin/node_modules/@mariozechner/clipboard/exp.ts +0 -12
  46. package/bin/node_modules/@mariozechner/clipboard/index.d.ts +0 -37
  47. package/bin/node_modules/@mariozechner/clipboard/index.js +0 -606
  48. package/bin/node_modules/@mariozechner/clipboard/package.json +0 -56
  49. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/common.rs +0 -307
  50. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/mod.rs +0 -93
  51. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/ios.rs +0 -313
  52. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/macos.rs +0 -471
  53. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/mod.rs +0 -252
  54. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/wayland.rs +0 -431
  55. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/win.rs +0 -712
  56. package/bin/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/x11.rs +0 -916
  57. package/bin/node_modules/@mariozechner/clipboard/src/lib.rs +0 -194
@@ -5,10 +5,10 @@ Sessions are stored as JSONL (JSON Lines) files. Each line is a JSON object with
5
5
  ## File Location
6
6
 
7
7
  ```
8
- ~/.pi/agent/sessions/--<path>--/<timestamp>_<uuid>.jsonl
8
+ ~/.pi/agent/sessions/--<path>--/<timestamp>_<session-id>.jsonl
9
9
  ```
10
10
 
11
- Where `<path>` is the working directory with `/` replaced by `-`.
11
+ By default, `<session-id>` is a UUID. Callers can supply a custom ID through the SDK or `--session-id`. For `<path>`, Pi removes the leading path separator and replaces `/`, `\\`, and `:` with `-`.
12
12
 
13
13
  ## Deleting Sessions
14
14
 
@@ -28,11 +28,11 @@ Existing sessions are automatically migrated to the current version (v3) when lo
28
28
 
29
29
  ## Source Files
30
30
 
31
- Source on GitHub ([pi-mono](https://github.com/earendil-works/pi-mono)):
32
- - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts) - Session entry types and SessionManager
33
- - [`packages/coding-agent/src/core/messages.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/messages.ts) - Extended message types (BashExecutionMessage, CustomMessage, etc.)
34
- - [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/types.ts) - Base message types (UserMessage, AssistantMessage, ToolResultMessage)
35
- - [`packages/agent/src/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/agent/src/types.ts) - AgentMessage union type
31
+ Source on GitHub ([pi](https://github.com/earendil-works/pi)):
32
+ - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts) - Session entry types and SessionManager
33
+ - [`packages/coding-agent/src/core/messages.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/messages.ts) - Extended message types (BashExecutionMessage, CustomMessage, etc.)
34
+ - [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/ai/src/types.ts) - Base message types (UserMessage, AssistantMessage, ToolResultMessage)
35
+ - [`packages/agent/src/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/agent/src/types.ts) - AgentMessage union type
36
36
 
37
37
  For TypeScript definitions in your project, inspect `node_modules/@earendil-works/pi-coding-agent/dist/` and `node_modules/@earendil-works/pi-ai/dist/`.
38
38
 
@@ -48,6 +48,7 @@ Messages contain arrays of typed content blocks:
48
48
  interface TextContent {
49
49
  type: "text";
50
50
  text: string;
51
+ textSignature?: string;
51
52
  }
52
53
 
53
54
  interface ImageContent {
@@ -59,6 +60,8 @@ interface ImageContent {
59
60
  interface ThinkingContent {
60
61
  type: "thinking";
61
62
  thinking: string;
63
+ thinkingSignature?: string;
64
+ redacted?: boolean;
62
65
  }
63
66
 
64
67
  interface ToolCall {
@@ -66,12 +69,22 @@ interface ToolCall {
66
69
  id: string;
67
70
  name: string;
68
71
  arguments: Record<string, any>;
72
+ thoughtSignature?: string;
73
+ namespace?: string;
69
74
  }
70
75
  ```
71
76
 
72
77
  ### Base Message Types (from pi-ai)
73
78
 
74
79
  ```typescript
80
+ interface SystemMessage {
81
+ role: "system";
82
+ content: string | TextContent[];
83
+ toolsAdded?: Tool[];
84
+ toolsRemoved?: Array<{ name: string }>;
85
+ timestamp: number; // Unix ms
86
+ }
87
+
75
88
  interface UserMessage {
76
89
  role: "user";
77
90
  content: string | (TextContent | ImageContent)[];
@@ -84,9 +97,16 @@ interface AssistantMessage {
84
97
  api: string;
85
98
  provider: string;
86
99
  model: string;
100
+ responseModel?: string;
101
+ responseId?: string;
102
+ providerThinkingLevel?: string;
103
+ diagnostics?: AssistantMessageDiagnostic[];
87
104
  usage: Usage;
88
- stopReason: "stop" | "length" | "toolUse" | "error" | "aborted";
105
+ stopReason: "pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred";
106
+ deferred?: DeferredHandle;
89
107
  errorMessage?: string;
108
+ rawStopReason?: string;
109
+ endTurn?: boolean;
90
110
  timestamp: number;
91
111
  }
92
112
 
@@ -106,6 +126,8 @@ interface Usage {
106
126
  output: number;
107
127
  cacheRead: number;
108
128
  cacheWrite: number;
129
+ cacheWrite1h?: number;
130
+ reasoning?: number;
109
131
  totalTokens: number;
110
132
  cost: {
111
133
  input: number;
@@ -117,7 +139,7 @@ interface Usage {
117
139
  }
118
140
  ```
119
141
 
120
- The exported pi-ai `StopReason` type also includes `"pending"`, but that value is reserved for partial messages in streaming events. Terminal `done`/`error` messages replace it with a completion reason before pi persists the assistant message, so `"pending"` should never appear in session JSONL.
142
+ `"pending"` is reserved for partial messages in streaming events. Terminal events replace it with a completion reason before Pi persists the assistant message, so `"pending"` should never appear in session JSONL. `"deferred"` is a terminal reason for a provider response that will complete later; its `deferred` handle contains the provider data needed to retrieve that response.
121
143
 
122
144
  ### Extended Message Types (from pi-coding-agent)
123
145
 
@@ -146,7 +168,7 @@ interface CustomMessage {
146
168
  interface BranchSummaryMessage {
147
169
  role: "branchSummary";
148
170
  summary: string;
149
- fromId: string; // Entry we branched from
171
+ fromId: string | null; // Previous leaf whose abandoned path was summarized
150
172
  timestamp: number;
151
173
  }
152
174
 
@@ -162,6 +184,7 @@ interface CompactionSummaryMessage {
162
184
 
163
185
  ```typescript
164
186
  type AgentMessage =
187
+ | SystemMessage
165
188
  | UserMessage
166
189
  | AssistantMessage
167
190
  | ToolResultMessage
@@ -178,8 +201,8 @@ All entries (except `SessionHeader`) extend `SessionEntryBase`:
178
201
  ```typescript
179
202
  interface SessionEntryBase {
180
203
  type: string;
181
- id: string; // 8-char hex ID
182
- parentId: string | null; // Parent entry ID (null for first entry)
204
+ id: string; // Usually an 8-char hex ID; may fall back to a full UUID
205
+ parentId: string | null; // Parent entry ID (null for a root entry)
183
206
  timestamp: string; // ISO timestamp
184
207
  }
185
208
  ```
@@ -202,12 +225,19 @@ For sessions with a parent (created via `/fork`, `/clone`, or `newSession({ pare
202
225
 
203
226
  ### SessionMessageEntry
204
227
 
205
- A message in the conversation. The `message` field contains an `AgentMessage`.
228
+ A message in the conversation. The `message` field contains an `AgentMessage`. System messages carry the prompt and tool loadout: the first request of a session persists one with every prompt section and tool declaration, and later changes persist as system messages that patch `sections` by name (`null` removes one) and list `toolsAdded`/`toolsRemoved`. Replaying them in order yields the current prompt and tools; there is no separate prompt state entry.
206
229
 
207
230
  ```json
208
- {"type":"message","id":"a1b2c3d4","parentId":"prev1234","timestamp":"2024-12-03T14:00:01.000Z","message":{"role":"user","content":"Hello"}}
209
- {"type":"message","id":"b2c3d4e5","parentId":"a1b2c3d4","timestamp":"2024-12-03T14:00:02.000Z","message":{"role":"assistant","content":[{"type":"text","text":"Hi!"}],"provider":"anthropic","model":"claude-sonnet-4-5","usage":{...},"stopReason":"stop"}}
210
- {"type":"message","id":"c3d4e5f6","parentId":"b2c3d4e5","timestamp":"2024-12-03T14:00:03.000Z","message":{"role":"toolResult","toolCallId":"call_123","toolName":"bash","content":[{"type":"text","text":"output"}],"isError":false}}
231
+ {"type":"message","id":"a0b1c2d3","parentId":null,"timestamp":"2024-12-03T14:00:00.000Z","message":{"role":"system","content":"","sections":{"preamble":"You are an expert coding assistant...","tools":"<tools>\n- read: ...\n</tools>","cwd":"/project"},"toolsAdded":[{"name":"read","description":"...","parameters":{}}],"timestamp":1733234400000}}
232
+ {"type":"message","id":"d4e5f6g7","parentId":"c3d4e5f6","timestamp":"2024-12-03T14:04:00.000Z","message":{"role":"system","content":"","sections":{"skills":"<skills>...</skills>"},"toolsRemoved":[{"name":"write"}],"timestamp":1733234640000}}
233
+ ```
234
+
235
+ Sessions created before system messages existed have no leading system message; the first request declares the current prompt as a later system message, which replays the same way.
236
+
237
+ ```json
238
+ {"type":"message","id":"a1b2c3d4","parentId":"prev1234","timestamp":"2024-12-03T14:00:01.000Z","message":{"role":"user","content":"Hello","timestamp":1733234401000}}
239
+ {"type":"message","id":"b2c3d4e5","parentId":"a1b2c3d4","timestamp":"2024-12-03T14:00:02.000Z","message":{"role":"assistant","content":[{"type":"text","text":"Hi!"}],"api":"anthropic-messages","provider":"anthropic","model":"claude-sonnet-4-5","usage":{...},"stopReason":"stop","timestamp":1733234402000}}
240
+ {"type":"message","id":"c3d4e5f6","parentId":"b2c3d4e5","timestamp":"2024-12-03T14:00:03.000Z","message":{"role":"toolResult","toolCallId":"call_123","toolName":"bash","content":[{"type":"text","text":"output"}],"isError":false,"timestamp":1733234403000}}
211
241
  ```
212
242
 
213
243
  ### ModelChangeEntry
@@ -226,26 +256,41 @@ Emitted when the user changes the thinking/reasoning level.
226
256
  {"type":"thinking_level_change","id":"e5f6g7h8","parentId":"d4e5f6g7","timestamp":"2024-12-03T14:06:00.000Z","thinkingLevel":"high"}
227
257
  ```
228
258
 
229
- ### CompactionEntry
259
+ ### UsageEntry
230
260
 
231
- Created when context is compacted. Stores a summary of earlier messages.
261
+ Records model-attributed usage that is not an assistant message and does not participate in LLM context. `kind` is an arbitrary string identifying the operation; for example, cache warming uses `"cache_warm"`.
232
262
 
233
263
  ```json
234
- {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000}
264
+ {"type":"usage","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:08:00.000Z","kind":"cache_warm","provider":"anthropic","model":"claude-sonnet-4-5","usage":{"input":0,"output":0,"cacheRead":50000,"cacheWrite":0,"totalTokens":50000,"cost":{"input":0,"output":0,"cacheRead":0.015,"cacheWrite":0,"total":0.015}}}
235
265
  ```
236
266
 
237
- Newer harness-generated compactions embed the retained post-compaction context directly on the entry, instead of `firstKeptEntryId`:
267
+ Usage entries contribute to session token and cost totals. Pi hides them from the conversation tree. Consumers should treat unknown `kind` values as normal usage rather than rejecting them.
268
+
269
+ ### CompactionEntry
270
+
271
+ Created when context is compacted. Stores a summary of earlier messages and a complete system prompt/tool checkpoint.
238
272
 
239
273
  ```json
240
- {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","tokensBefore":50000,"retainedTail":[{"role":"user","content":"latest request"},{"role":"assistant","content":[{"type":"text","text":"latest reply"}],"provider":"anthropic","model":"claude-sonnet-4-5","usage":{...},"stopReason":"stop"}]}
274
+ {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000,"systemMessage":{"role":"system","content":"You are a coding assistant.","toolsAdded":[],"timestamp":1733235000000}}
241
275
  ```
242
276
 
277
+ `firstKeptEntryId` is required. It identifies the first entry retained from before the compaction entry. When rebuilding context, Pi replaces older summarized entries with the compaction summary and keeps the range beginning at this entry. A retain-none compaction stores its own ID in this field, so no preceding entries are retained.
278
+
243
279
  Optional fields:
280
+ - `systemMessage`: The replayed prompt sections and tool declarations at the compaction boundary; it becomes the leading system message of the compacted context, and system messages among the kept entries are dropped in its favor. It is absent on older session entries.
244
281
  - `usage`: LLM usage from generating the summary; included in session token and cost totals
245
- - `retainedTail`: Materialized `AgentMessage[]` kept after compaction. This is optional only for backward compatibility with older sessions. Newer harness-generated compactions include it so we can rebuild context from this checkpoint without walking older entries before the compaction entry.
246
282
  - `details`: Implementation-specific data (e.g., `{ readFiles: string[], modifiedFiles: string[] }` for default, or custom data for extensions)
247
283
  - `fromHook`: `true` if generated by an extension, `false`/`undefined` if pi-generated (legacy field name)
248
- - `firstKeptEntryId`: for compatibility with old entry format.
284
+
285
+ ### ContextEditEntry
286
+
287
+ Append-only edit of one earlier context-producing entry. It changes only future model context; the target entry and its metadata remain unchanged in raw history, UI, exports, and session accounting.
288
+
289
+ ```json
290
+ {"type":"context_edit","id":"g6h7i8j9","parentId":"f6g7h8i9","timestamp":"2024-12-03T14:11:00.000Z","targetId":"c3d4e5f6","replacement":null}
291
+ ```
292
+
293
+ Targets may be user, assistant, tool-result, or custom-message entries. `replacement: null` omits the target from model context. A non-null `replacement` replaces only the target message content. String replacements for assistant and tool-result entries are normalized to one text block because those roles require content arrays. If several edits target the same entry, the latest edit on the active branch wins. Edits are branch-relative: navigating to a point before the edit reveals the target's original contribution again.
249
294
 
250
295
  ### BranchSummaryEntry
251
296
 
@@ -255,6 +300,8 @@ Created when switching branches via `/tree` with an LLM generated summary of the
255
300
  {"type":"branch_summary","id":"g7h8i9j0","parentId":"a1b2c3d4","timestamp":"2024-12-03T14:15:00.000Z","fromId":"f6g7h8i9","summary":"Branch explored approach A..."}
256
301
  ```
257
302
 
303
+ `parentId` is the entry from which the new branch continues. `fromId` is the previous leaf whose abandoned path was summarized.
304
+
258
305
  Optional fields:
259
306
  - `usage`: LLM usage from generating the summary; included in session token and cost totals
260
307
  - `details`: File tracking data (`{ readFiles: string[], modifiedFiles: string[] }`) for default, or custom data for extensions
@@ -305,11 +352,12 @@ The session name is displayed in the session selector (`/resume`) instead of the
305
352
 
306
353
  ## Tree Structure
307
354
 
308
- Entries form a tree:
309
- - First entry has `parentId: null`
310
- - Each subsequent entry points to its parent via `parentId`
355
+ Entries normally form one tree, but navigation APIs can create multiple roots:
356
+ - A root entry has `parentId: null`; the first entry is initially the root
357
+ - Each non-root entry points to its parent via `parentId`
311
358
  - Branching creates new children from an earlier entry
312
359
  - The "leaf" is the current position in the tree
360
+ - Calling `resetLeaf()` or `branchWithSummary(null, ...)` allows a later entry to become another root
313
361
 
314
362
  ```
315
363
  [user msg] ─── [assistant] ─── [user msg] ─── [assistant] ─┬─ [user msg] ← current leaf
@@ -322,24 +370,26 @@ Entries form a tree:
322
370
  `buildContextEntries()` walks from the current leaf to the root, producing the active entry list while honoring compaction:
323
371
 
324
372
  1. Collects all entries on the path
325
- 2. If a `CompactionEntry` is on the path:
373
+ 2. If one or more `CompactionEntry` values are on the path, uses the latest one:
326
374
  - Includes the compaction entry first
327
- - If `retainedTail` is present, it acts as a self-contained checkpoint and entries after the compaction are included
328
- - Otherwise entries from `firstKeptEntryId` to the compaction are included
329
- - Then entries after compaction are included
375
+ - Includes non-system entries from `firstKeptEntryId` up to, but not including, the compaction entry
376
+ - Includes entries after the compaction entry
330
377
  3. Preserves non-message entries in the selected range so interactive mode can render them
331
378
 
332
- `buildSessionContext()` builds on that entry list to produce the message list for the LLM:
379
+ `buildSessionProjection()` then applies the latest `context_edit` for each selected target. It returns the model-visible messages together with their source entries. Omitted targets produce no message; replacements retain the source entry's role and metadata while changing only content. The raw selected entries are not modified.
380
+
381
+ `buildSessionContext()` builds on that projection to produce the message list for the LLM:
333
382
 
334
383
  1. Extracts current model and thinking level settings from the full path
335
384
  2. Converts selected entries to messages:
336
385
  - `message` -> stored `AgentMessage`
337
- - `compaction` -> `compactionSummary` plus `retainedTail` when present
386
+ - `compaction` -> complete system checkpoint followed by `compactionSummary`
338
387
  - `branch_summary` -> `branchSummary`
339
388
  - `custom_message` -> `CustomMessage`
340
- - `custom` -> no context message
389
+ - `context_edit` -> no context message of its own
390
+ - `usage` and `custom` -> no context message
341
391
 
342
- This makes newer compactions act like self-contained checkpoints. `retainedTail` is optional only so older sessions that only store `firstKeptEntryId` continue to load correctly.
392
+ The compaction summary replaces entries before `firstKeptEntryId`. Pre-compaction system messages are folded into the complete checkpoint rather than replayed from the retained range. Retained non-system entries and all entries after the compaction remain available to the LLM.
343
393
 
344
394
  ## Parsing Example
345
395
 
@@ -364,6 +414,9 @@ for (const line of lines) {
364
414
  case "branch_summary":
365
415
  console.log(`[${entry.id}] Branch from ${entry.fromId}`);
366
416
  break;
417
+ case "usage":
418
+ console.log(`[${entry.id}] Usage (${entry.kind}): ${entry.usage.totalTokens} tokens`);
419
+ break;
367
420
  case "custom":
368
421
  console.log(`[${entry.id}] Custom (${entry.customType}): ${JSON.stringify(entry.data)}`);
369
422
  break;
@@ -388,18 +441,19 @@ for (const line of lines) {
388
441
  Key methods for working with sessions programmatically.
389
442
 
390
443
  ### Static Creation Methods
391
- - `SessionManager.create(cwd, sessionDir?)` - New session
392
- - `SessionManager.open(path, sessionDir?)` - Open existing session file
444
+ - `SessionManager.create(cwd, sessionDir?, options?)` - New session; `options` can set `id` and `parentSession`
445
+ - `SessionManager.open(path, sessionDir?, cwdOverride?)` - Open existing session file
393
446
  - `SessionManager.continueRecent(cwd, sessionDir?)` - Continue most recent or create new
394
- - `SessionManager.inMemory(cwd?)` - No file persistence
395
- - `SessionManager.forkFrom(sourcePath, targetCwd, sessionDir?)` - Fork session from another project
447
+ - `SessionManager.inMemory(cwd?, options?, entries?)` - No file persistence, optionally initialized from entries
448
+ - `SessionManager.forkFrom(sourcePath, targetCwd, sessionDir?, options?)` - Fork session from another project
396
449
 
397
450
  ### Static Listing Methods
398
451
  - `SessionManager.list(cwd, sessionDir?, onProgress?)` - List sessions for a directory
399
452
  - `SessionManager.listAll(onProgress?)` - List all sessions across all projects
453
+ - `SessionManager.listAll(sessionDir?, onProgress?)` - List sessions from a custom session root
400
454
 
401
455
  ### Instance Methods - Session Management
402
- - `newSession(options?)` - Start a new session (options: `{ parentSession?: string }`)
456
+ - `newSession(options?)` - Start a new session (options: `{ id?: string, parentSession?: string }`)
403
457
  - `setSessionFile(path)` - Switch to a different session file
404
458
  - `createBranchedSession(leafId)` - Extract branch to new session file
405
459
 
@@ -407,7 +461,8 @@ Key methods for working with sessions programmatically.
407
461
  - `appendMessage(message)` - Add message
408
462
  - `appendThinkingLevelChange(level)` - Record thinking change
409
463
  - `appendModelChange(provider, modelId)` - Record model change
410
- - `appendCompaction(summary, firstKeptEntryId, tokensBefore, details?, fromHook?)` - Add compaction
464
+ - `appendUsage(kind, provider, model, usage)` - Record model-attributed usage outside the conversation
465
+ - `appendCompaction(summary, firstKeptEntryId, tokensBefore, details?, fromHook?, usage?)` - Add compaction
411
466
  - `appendCustomEntry(customType, data?)` - Extension state (not in context)
412
467
  - `appendSessionInfo(name)` - Set session display name
413
468
  - `appendCustomMessageEntry(customType, content, display, details?)` - Extension message (in context)
@@ -423,7 +478,7 @@ Key methods for working with sessions programmatically.
423
478
  - `getLabel(id)` - Get label for entry
424
479
  - `branch(entryId)` - Move leaf to earlier entry
425
480
  - `resetLeaf()` - Reset leaf to null (before any entries)
426
- - `branchWithSummary(entryId, summary, details?, fromHook?)` - Branch with context summary
481
+ - `branchWithSummary(entryId, summary, details?, fromHook?, usage?)` - Branch with context summary; `entryId` may be `null` to branch from the root
427
482
 
428
483
  ### Instance Methods - Context & Info
429
484
  - `buildContextEntries()` - Get active branch entries with compaction applied
@@ -33,6 +33,7 @@ For the JSONL file format and SessionManager API, see [Session Format](session-f
33
33
  | `/compact [prompt]` | Summarize older context; see [Compaction](compaction.md) |
34
34
  | `/export [file]` | Export session to HTML |
35
35
  | `/share` | Upload as private GitHub gist with shareable HTML link |
36
+ | `/bug [description]` | Report a bug to the Pi developers; see [Reporting Bugs](#reporting-bugs) |
36
37
 
37
38
  ## Resuming and Deleting Sessions
38
39
 
@@ -138,6 +139,32 @@ When prompted, choose one of:
138
139
 
139
140
  See [Compaction](compaction.md) for branch summarization internals and extension hooks.
140
141
 
142
+ ## Reporting Bugs
143
+
144
+ `/bug [description]` collects a bug report for the Pi developers. The report is not shared publicly. The dialog asks for an optional description and whether to include the session transcript. If you decline the transcript, pi offers to have the current model write a summary of what went wrong instead; the transcript is sent to your provider with your credentials, and only the summary is attached.
145
+
146
+ The last step chooses where the report goes:
147
+
148
+ - **Upload Report** sends it to the Pi developers through `radius.pi.dev`. No login is required; if you are logged into Radius, the report is attributed to your account so the developers can follow up. If the upload fails, pi offers to export the zip instead.
149
+ - **Export as Zip** writes a zip archive to the current directory. Attach it to an issue or send it to the developers yourself.
150
+
151
+ Both contain the same files:
152
+
153
+ | File | Content |
154
+ |------|---------|
155
+ | `report.json` | pi version, runtime, OS, terminal, current model and provider configuration, loaded extensions, and settings. API keys, header values, URL credentials, and the analytics tracking id are never included. |
156
+ | `diagnostics.json` | Provider and runtime error diagnostics attached to assistant messages across the whole session (failed or aborted turns, retries, error messages), plus any recorded crashes. Always included; message content is not. |
157
+ | `session.jsonl` | The current branch of the session, only when you chose to include it. It contains file contents and command output read during the session. |
158
+ | `summary.md` | The model-written summary, only when you chose to generate one. |
159
+
160
+ Each report has a UUID. pi shows it after upload or export and records it in the session as a `pi.bug-report` entry so you can refer to it later.
161
+
162
+ Set `PI_RADIUS_GATEWAY` to upload to a different Radius deployment.
163
+
164
+ ### Crashes
165
+
166
+ When pi exits because of an uncaught exception or a fatal runtime error, it stores the error message and stack trace in `~/.pi/agent/crashes.json` (the newest five). The next interactive start shows a warning once; running `/bug` attaches the stored crashes to `diagnostics.json` and removes the file after the report is uploaded or exported. Resume the crashed session with `pi -r` first if you want the transcript in the report.
167
+
141
168
  ## Session Format
142
169
 
143
170
  Session files are JSONL and contain message entries, model changes, thinking-level changes, labels, compactions, branch summaries, and extension entries.
@@ -32,8 +32,31 @@ Use `/trust` in interactive mode to save a project trust decision for future ses
32
32
  | `defaultThinkingLevel` | string | - | Startup thinking level (saved with Ctrl+S in `/thinking`, or edited manually): `"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"` |
33
33
  | `modelThinkingLevels` | object | - | Per-model startup thinking levels keyed by `"provider/modelId"`; configure from `/settings` → Default thinking level per model or edit manually |
34
34
  | `hideThinkingBlock` | boolean | `false` | Hide thinking blocks in output |
35
- | `showCacheMissNotices` | boolean | `false` | Show transcript notices for significant prompt-cache misses, compaction or branch-summary usage, and provider recovery diagnostics such as dropped Anthropic thinking blocks |
35
+ | `showCacheMissNotices` | boolean | `false` | Show transcript notices for significant prompt-cache misses, successful cache-warming usage, compaction or branch-summary usage, and provider recovery diagnostics such as dropped Anthropic thinking blocks |
36
36
  | `thinkingBudgets` | object | - | Custom token budgets per thinking level. Anthropic, Google, and Bedrock use these natively. OpenAI-compatible models use them when `compat.thinkingTokenBudgetField` (or `supportsThinkingTokenBudget`) is set. |
37
+ | `cacheWarming` | string | `"streaming"` | Prompt cache-warming mode: `"off"`, `"streaming"`, or `"idle"`. Global setting only. |
38
+
39
+ #### Cache Warming
40
+
41
+ Providers drop a prompt cache entry after a period of inactivity, so the first request after a pause pays full input price again. Cache warming re-sends the last request with a one-token output budget shortly before expiry:
42
+
43
+ - `"off"` disables warming.
44
+ - `"streaming"` protects expensive prefixes during long tool executions and stops as soon as the agent settles.
45
+ - `"idle"` also considers refreshes while waiting for your next prompt, using a fixed 15% continuation probability measured from real usage.
46
+
47
+ ```json
48
+ {
49
+ "cacheWarming": "idle"
50
+ }
51
+ ```
52
+
53
+ A refresh is sent only when the expected avoided cache-miss cost, minus the cost of the refresh, leaves at least $0.05 of expected savings. Active agent runs use 100% continuation probability. `/session` shows the next decision, continuation probability, expected savings, threshold, and estimated costs. When cache miss notices are enabled, each successful refresh appears in the transcript with its cost; notices identify extension overrides.
54
+
55
+ Warming stops when the context changes (model switch, compaction, branch navigation). Idle warming stops no later than 30 minutes after the last real provider request; warming during an active agent run stops after 60 minutes. Extensions can override each decision through the [`cache_warming_decision`](extensions.md#cache_warming_decision) event.
56
+
57
+ Each refresh is billed as a cache read of the full context plus one output token. Usage and cost show up in session totals but never enter model context. Pi schedules candidates at 90% of the cache lifetime while leaving at least ten seconds before expiry.
58
+
59
+ Warming needs a known cache lifetime for the model and the retention tier the request used (`short`, or `long` with `PI_CACHE_RETENTION=long`). The built-in catalog carries lifetimes for direct Anthropic; custom models and other providers can declare theirs with `promptCache` in `models.json` (see [Prompt Cache Lifetimes](models.md#prompt-cache-lifetimes)). Claude models that use budget-based rather than adaptive thinking are skipped while thinking is on, because Anthropic derives the thinking budget from `max_tokens` and keys the message cache on it, so a one-token request cannot reproduce the entry.
37
60
 
38
61
  #### thinkingBudgets
39
62
 
@@ -118,6 +141,7 @@ Set `PI_SKIP_VERSION_CHECK=1` to disable the Pi version update check. Use `--off
118
141
  | `compaction.enabled` | boolean | `true` | Enable auto-compaction |
119
142
  | `compaction.reserveTokens` | number | `16384` | Tokens reserved for LLM response |
120
143
  | `compaction.keepRecentTokens` | number | `20000` | Recent tokens to keep (not summarized) |
144
+ | `compaction.modelOverrides` | object | - | Per-model `reserveTokens` and `keepRecentTokens` overrides keyed by exact `"provider/modelId"` |
121
145
 
122
146
  ```json
123
147
  {
@@ -129,6 +153,37 @@ Set `PI_SKIP_VERSION_CHECK=1` to disable the Pi version update check. Use `--off
129
153
  }
130
154
  ```
131
155
 
156
+ #### Per-model compaction overrides
157
+
158
+ ```json
159
+ {
160
+ "compaction": {
161
+ "enabled": true,
162
+ "reserveTokens": 16384,
163
+ "keepRecentTokens": 20000,
164
+ "modelOverrides": {
165
+ "some-provider/big-model": {
166
+ "reserveTokens": 400000
167
+ },
168
+ "local/small-model": {
169
+ "reserveTokens": 2048,
170
+ "keepRecentTokens": 4096
171
+ }
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ Keys match exact, case-sensitive `provider/modelId` values, not names or glob patterns. Model IDs may contain slashes (for example, `openrouter/anthropic/claude-sonnet-4`).
178
+
179
+ Each token setting resolves independently: matching model override → ordinary `compaction` setting → built-in default. In the example, `some-provider/big-model` keeps the ordinary 20000 recent tokens. Token values must be non-negative safe integers. Invalid values in the matching model override produce an error when read; only omitted fields fall back to the ordinary setting. Model override entries must be objects. Invalid ordinary token settings produce an error when read, even if the active model has a valid override. Only omitted ordinary values use built-in defaults. Zero is accepted, but `reserveTokens: 0` leaves no response margin and also sets the summarization output budget to zero.
180
+
181
+ Global and project settings merge recursively **before** model lookup. A project can override one field for a model without replacing its other fields or other models. A global model-specific value takes precedence over a project-wide fallback; override the same model entry in the project to change it.
182
+
183
+ `enabled` is not model-specific. The active model's token settings apply to manual compaction, automatic threshold checks (including between assistant turns), and overflow recovery. Switching models takes effect on the next check or compaction. Configure overrides in JSON; `/settings` retains the ordinary auto-compaction toggle.
184
+
185
+ See [compaction.md](compaction.md) for trigger and summarization behavior.
186
+
132
187
  ### Branch Summary
133
188
 
134
189
  | Setting | Type | Default | Description |
@@ -96,7 +96,6 @@ termux-camera-photo out.jpg # Take photo
96
96
  ## Limitations
97
97
 
98
98
  - **No image clipboard**: Termux clipboard API only supports text
99
- - **No native binaries**: Some optional native dependencies (like the clipboard module) are unavailable on Android ARM64 and are skipped during installation
100
99
  - **Storage access**: To access files in `/storage/emulated/0` (Downloads, etc.), run `termux-setup-storage` once to grant permissions
101
100
 
102
101
  ## Troubleshooting
package/bin/docs/tui.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Extensions and custom tools can render custom TUI components for interactive user interfaces. This page covers the component system and available building blocks.
6
6
 
7
- **Source:** [`@earendil-works/pi-tui`](https://github.com/earendil-works/pi-mono/tree/main/packages/tui)
7
+ **Source:** [`@earendil-works/pi-tui`](https://github.com/earendil-works/pi/tree/main/packages/tui)
8
8
 
9
9
  ## Component Interface
10
10
 
@@ -930,7 +930,7 @@ export default function (pi: ExtensionAPI) {
930
930
 
931
931
  - **Extend `CustomEditor`** (not base `Editor`) to get app keybindings (escape to abort, ctrl+d to exit, model switching, etc.)
932
932
  - **Call `super.handleInput(data)`** for keys you don't handle
933
- - **Working status**: custom editors keep the standalone working row by default. Pass `{ embedWorkingStatus: true }` as the fourth `CustomEditor` constructor argument to use the built-in editor-border spinner instead.
933
+ - **Status spinners**: custom editors keep standalone status rows by default. Pass `{ embedWorkingStatus: true }` as the fourth `CustomEditor` constructor argument to embed working, compaction, branch summarization, and retry spinners in the editor border instead.
934
934
  - **Factory pattern**: `setEditorComponent` receives a factory function that gets `tui`, `theme`, and `keybindings`
935
935
  - **Pass `undefined`** to restore the default editor: `ctx.ui.setEditorComponent(undefined)`
936
936
 
package/bin/docs/usage.md CHANGED
@@ -55,6 +55,7 @@ Type `/` in the editor to open command completion. Extensions can register custo
55
55
  | `/export [file]` | Export session to HTML or JSONL |
56
56
  | `/import <file>` | Import and resume a session from a JSONL file |
57
57
  | `/share` | Upload as private GitHub gist with shareable HTML link |
58
+ | `/bug [description]` | Report a bug to the Pi developers; see [Sessions](sessions.md#reporting-bugs) |
58
59
  | `/reload` | Reload keybindings, extensions, skills, prompts, themes, and context files |
59
60
  | `/hotkeys` | Show all keyboard shortcuts |
60
61
  | `/changelog` | Display version history |
@@ -36,7 +36,6 @@ cp permission-gate.ts ~/.pi/agent/extensions/
36
36
  | `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
37
37
  | `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
38
38
  | `dynamic-tools.ts` | Register tools after startup (`session_start`) and at runtime via command, with prompt snippets and tool-specific prompt guidelines |
39
- | `kimi-deferred-tools.ts` | Search for and progressively activate tools for Kimi's deferred-tool loading protocol |
40
39
  | `structured-output.ts` | Final structured-output tool that returns `terminate: true` so the agent can end on the tool call |
41
40
  | `built-in-tool-renderer.ts` | Custom compact rendering for built-in tools (read, bash, edit, write) while keeping original behavior |
42
41
  | `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
@@ -27,9 +27,11 @@ import {
27
27
  type Api,
28
28
  type AssistantMessage,
29
29
  type AssistantMessageEventStream,
30
- type Context,
31
30
  calculateCost,
31
+ collapseSystemMessages,
32
32
  createAssistantMessageEventStream,
33
+ getCurrentSystemPrompt,
34
+ getCurrentTools,
33
35
  type ImageContent,
34
36
  type Message,
35
37
  type Model,
@@ -42,6 +44,7 @@ import {
42
44
  type Tool,
43
45
  type ToolCall,
44
46
  type ToolResultMessage,
47
+ type TranscriptContext,
45
48
  } from "@earendil-works/pi-ai";
46
49
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
47
50
 
@@ -334,10 +337,15 @@ function mapStopReason(reason: string): StopReason {
334
337
 
335
338
  function streamCustomAnthropic(
336
339
  model: Model<Api>,
337
- context: Context,
340
+ context: TranscriptContext,
338
341
  options?: SimpleStreamOptions,
339
342
  ): AssistantMessageEventStream {
340
343
  const stream = createAssistantMessageEventStream();
344
+ // The transcript carries the prompt and tools in its system messages. This provider sends
345
+ // one top-level system prompt, so fold later system messages into the leading one first.
346
+ const transcript = collapseSystemMessages(context);
347
+ const systemPrompt = getCurrentSystemPrompt(transcript.messages);
348
+ const tools = getCurrentTools(transcript.messages);
341
349
 
342
350
  (async () => {
343
351
  const output: AssistantMessage = {
@@ -393,7 +401,7 @@ function streamCustomAnthropic(
393
401
  // Build request params
394
402
  const params: MessageCreateParamsStreaming = {
395
403
  model: model.id,
396
- messages: convertMessages(context.messages, isOAuth, context.tools),
404
+ messages: convertMessages(transcript.messages, isOAuth, tools),
397
405
  max_tokens: options?.maxTokens || Math.floor(model.maxTokens / 3),
398
406
  stream: true,
399
407
  };
@@ -407,25 +415,25 @@ function streamCustomAnthropic(
407
415
  cache_control: { type: "ephemeral" },
408
416
  },
409
417
  ];
410
- if (context.systemPrompt) {
418
+ if (systemPrompt) {
411
419
  params.system.push({
412
420
  type: "text",
413
- text: sanitizeSurrogates(context.systemPrompt),
421
+ text: sanitizeSurrogates(systemPrompt),
414
422
  cache_control: { type: "ephemeral" },
415
423
  });
416
424
  }
417
- } else if (context.systemPrompt) {
425
+ } else if (systemPrompt) {
418
426
  params.system = [
419
427
  {
420
428
  type: "text",
421
- text: sanitizeSurrogates(context.systemPrompt),
429
+ text: sanitizeSurrogates(systemPrompt),
422
430
  cache_control: { type: "ephemeral" },
423
431
  },
424
432
  ];
425
433
  }
426
434
 
427
- if (context.tools) {
428
- params.tools = convertTools(context.tools, isOAuth);
435
+ if (tools.length > 0) {
436
+ params.tools = convertTools(tools, isOAuth);
429
437
  }
430
438
 
431
439
  // Handle thinking/reasoning
@@ -474,9 +482,7 @@ function streamCustomAnthropic(
474
482
  output.content.push({
475
483
  type: "toolCall",
476
484
  id: event.content_block.id,
477
- name: isOAuth
478
- ? fromClaudeCodeName(event.content_block.name, context.tools)
479
- : event.content_block.name,
485
+ name: isOAuth ? fromClaudeCodeName(event.content_block.name, tools) : event.content_block.name,
480
486
  arguments: {},
481
487
  partialJson: "",
482
488
  index: event.index,
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "0.85.1",
3
+ "version": "0.87.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "0.85.1",
9
+ "version": "0.87.0",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "0.85.1",
4
+ "version": "0.87.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -13,7 +13,6 @@ import {
13
13
  type Api,
14
14
  type AssistantMessageEventStream,
15
15
  anthropicMessagesApi,
16
- type Context,
17
16
  createAssistantMessageEventStream,
18
17
  type Model,
19
18
  type OAuthCredentials,
@@ -21,6 +20,7 @@ import {
21
20
  openAIResponsesApi,
22
21
  type SimpleStreamOptions,
23
22
  type ThinkingLevelMap,
23
+ type TranscriptContext,
24
24
  } from "@earendil-works/pi-ai/compat";
25
25
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
26
26
 
@@ -306,7 +306,7 @@ async function refreshGitLabToken(credentials: OAuthCredentials, signal: AbortSi
306
306
 
307
307
  export function streamGitLabDuo(
308
308
  model: Model<Api>,
309
- context: Context,
309
+ context: TranscriptContext,
310
310
  options?: SimpleStreamOptions,
311
311
  ): AssistantMessageEventStream {
312
312
  const stream = createAssistantMessageEventStream();