@oh-my-pi/pi-coding-agent 10.6.1 → 11.0.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 (86) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +80 -79
  3. package/docs/compaction.md +182 -149
  4. package/docs/config-usage.md +141 -78
  5. package/docs/custom-tools.md +45 -16
  6. package/docs/extension-loading.md +56 -954
  7. package/docs/extensions.md +192 -51
  8. package/docs/hooks.md +109 -70
  9. package/docs/python-repl.md +52 -19
  10. package/docs/rpc.md +43 -19
  11. package/docs/sdk.md +270 -211
  12. package/docs/session-tree-plan.md +60 -417
  13. package/docs/session.md +104 -39
  14. package/docs/skills.md +59 -95
  15. package/docs/theme.md +139 -110
  16. package/docs/tree.md +42 -33
  17. package/docs/tui.md +226 -80
  18. package/package.json +8 -9
  19. package/src/capability/index.ts +3 -4
  20. package/src/cli/args.ts +4 -4
  21. package/src/cli/grep-cli.ts +1 -1
  22. package/src/commit/agentic/index.ts +4 -3
  23. package/src/commit/git/index.ts +2 -3
  24. package/src/commit/map-reduce/index.ts +2 -1
  25. package/src/config/prompt-templates.ts +2 -0
  26. package/src/config/settings-schema.ts +30 -7
  27. package/src/config/settings.ts +0 -14
  28. package/src/config.ts +2 -2
  29. package/src/discovery/agents.ts +36 -0
  30. package/src/discovery/index.ts +1 -0
  31. package/src/exa/mcp-client.ts +3 -3
  32. package/src/ipy/executor.ts +5 -7
  33. package/src/ipy/gateway-coordinator.ts +1 -1
  34. package/src/ipy/kernel.ts +20 -15
  35. package/src/ipy/prelude.py +1 -1
  36. package/src/ipy/runtime.ts +7 -6
  37. package/src/lsp/lspmux.ts +3 -3
  38. package/src/main.ts +6 -8
  39. package/src/mcp/tool-bridge.ts +19 -9
  40. package/src/modes/components/assistant-message.ts +2 -2
  41. package/src/modes/components/hook-editor.ts +4 -4
  42. package/src/modes/components/settings-defs.ts +37 -2
  43. package/src/modes/components/tool-execution.ts +7 -7
  44. package/src/modes/controllers/command-controller.ts +2 -2
  45. package/src/modes/controllers/event-controller.ts +4 -7
  46. package/src/modes/controllers/input-controller.ts +4 -4
  47. package/src/modes/controllers/selector-controller.ts +1 -0
  48. package/src/modes/interactive-mode.ts +3 -5
  49. package/src/modes/rpc/rpc-mode.ts +8 -9
  50. package/src/patch/index.ts +6 -6
  51. package/src/prompts/agents/explore.md +2 -2
  52. package/src/prompts/agents/frontmatter.md +5 -5
  53. package/src/prompts/agents/plan.md +3 -2
  54. package/src/prompts/agents/reviewer.md +1 -1
  55. package/src/prompts/system/system-prompt.md +1 -3
  56. package/src/sdk.ts +13 -9
  57. package/src/session/agent-session.ts +6 -4
  58. package/src/session/compaction/compaction.ts +3 -3
  59. package/src/session/session-manager.ts +8 -9
  60. package/src/ssh/connection-manager.ts +4 -4
  61. package/src/system-prompt.ts +2 -6
  62. package/src/task/agents.ts +1 -1
  63. package/src/task/executor.ts +31 -8
  64. package/src/task/index.ts +14 -35
  65. package/src/task/omp-command.ts +3 -1
  66. package/src/task/output-manager.ts +20 -6
  67. package/src/task/parallel.ts +3 -3
  68. package/src/task/render.ts +16 -2
  69. package/src/task/types.ts +13 -20
  70. package/src/task/worktree.ts +3 -3
  71. package/src/tools/ask.ts +3 -8
  72. package/src/tools/fetch.ts +2 -2
  73. package/src/tools/gemini-image.ts +5 -6
  74. package/src/tools/grep.ts +5 -5
  75. package/src/tools/index.ts +12 -5
  76. package/src/tools/read.ts +1 -1
  77. package/src/tools/todo-write.ts +2 -3
  78. package/src/utils/frontmatter.ts +1 -1
  79. package/src/utils/image-resize.ts +1 -1
  80. package/src/utils/timings.ts +3 -2
  81. package/src/web/scrapers/github.ts +2 -2
  82. package/src/web/scrapers/utils.ts +2 -3
  83. package/src/web/scrapers/youtube.ts +2 -3
  84. package/src/web/search/auth.ts +5 -6
  85. package/src/web/search/providers/anthropic.ts +3 -2
  86. package/src/utils/terminal-notify.ts +0 -37
@@ -1,47 +1,67 @@
1
1
  # Compaction & Branch Summarization
2
2
 
3
- LLMs have limited context windows. When conversations grow too long, omp uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
3
+ LLMs have limited context windows. OMP uses compaction to summarize older context while keeping recent work intact, and branch summarization to capture work when moving between branches in the session tree.
4
4
 
5
5
  **Source files:**
6
6
 
7
- - [`src/core/compaction/compaction.ts`](../src/core/compaction/compaction.ts) - Auto-compaction logic
8
- - [`src/core/compaction/branch-summarization.ts`](../src/core/compaction/branch-summarization.ts) - Branch summarization
9
- - [`src/core/compaction/utils.ts`](../src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
10
- - [`src/core/session-manager.ts`](../src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
11
- - [`src/core/hooks/types.ts`](../src/core/hooks/types.ts) - Hook event types
7
+ - [`src/session/compaction/compaction.ts`](../src/session/compaction/compaction.ts) - Auto-compaction logic
8
+ - [`src/session/compaction/branch-summarization.ts`](../src/session/compaction/branch-summarization.ts) - Branch summarization
9
+ - [`src/session/compaction/utils.ts`](../src/session/compaction/utils.ts) - Shared utilities (file tracking, serialization)
10
+ - [`src/session/compaction/pruning.ts`](../src/session/compaction/pruning.ts) - Tool output pruning
11
+ - [`src/session/session-manager.ts`](../src/session/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
12
+ - [`src/extensibility/hooks/types.ts`](../src/extensibility/hooks/types.ts) - Hook event types
13
+ - [`src/prompts/compaction/*`](../src/prompts/compaction) - Summarization prompts
14
+ - [`src/prompts/system/*`](../src/prompts/system) - Summarization system prompt + file op tags
12
15
 
13
16
  ## Overview
14
17
 
15
18
  OMP has two summarization mechanisms:
16
19
 
17
- | Mechanism | Trigger | Purpose |
18
- | -------------------- | ---------------------------------------- | ----------------------------------------- |
19
- | Compaction | Context exceeds threshold, or `/compact` | Summarize old messages to free up context |
20
- | Branch summarization | `/tree` navigation | Preserve context when switching branches |
20
+ | Mechanism | Trigger | Purpose |
21
+ | -------------------- | ------------------------------------------------------ | ----------------------------------------- |
22
+ | Compaction | Context overflow/threshold, or `/compact` | Summarize old messages to free up context |
23
+ | Branch summarization | `/tree` navigation (when branch summaries are enabled) | Preserve context when switching branches |
21
24
 
22
- Both use the same structured summary format and track file operations cumulatively.
25
+ Compaction and branch summaries are stored as session entries and injected into LLM context as user messages via `compaction-summary-context.md` and `branch-summary-context.md`.
23
26
 
24
27
  ## Compaction
25
28
 
26
29
  ### When It Triggers
27
30
 
28
- Auto-compaction triggers when:
31
+ Auto-compaction runs after a turn completes:
29
32
 
30
- ```
31
- contextTokens > contextWindow - reserveTokens
32
- ```
33
+ - **Overflow recovery**: If the current model returns a context overflow error, OMP compacts and retries automatically.
34
+ - **Threshold**: If `contextTokens > contextWindow - reserveTokens`, OMP compacts without retry.
35
+ - Tool output pruning runs first and can reduce `contextTokens`.
33
36
 
34
- By default, `reserveTokens` is 16384 tokens (configurable in `~/.omp/agent/settings.json` or `<project-dir>/.omp/settings.json`). This leaves room for the LLM's response.
37
+ Manual compaction is available via `/compact [instructions]`.
35
38
 
36
- You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
39
+ Auto-compaction is controlled by `compaction.enabled`. After threshold compaction, OMP sends a synthetic "Continue if you have next steps." prompt unless `compaction.autoContinue` is set to `false`.
37
40
 
38
41
  ### How It Works
39
42
 
40
- 2. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.omp/agent/settings.json` or `<project-dir>/.omp/settings.json`) is reached
41
- 2. **Extract messages**: Collect messages from previous compaction (or start) up to cut point
42
- 3. **Generate summary**: Call LLM to summarize with structured format
43
- 4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
44
- 5. **Reload**: Session reloads, using summary + messages from `firstKeptEntryId` onwards
43
+ 1. **Prepare**: `prepareCompaction()` finds the latest compaction boundary and chooses a cut point that keeps approximately `keepRecentTokens` (adjusted using usage data).
44
+ 2. **Extract**: Collect messages to summarize, plus a turn prefix if the cut point splits a turn.
45
+ 3. **Track files**: Gather file ops from `read`/`write`/`edit` tool calls and previous compaction details.
46
+ 4. **Summarize**:
47
+ - Main summary uses `compaction-summary.md` or `compaction-update-summary.md` if there is a previous summary.
48
+ - Split turns add a turn-prefix summary from `compaction-turn-prefix.md` and merge with:
49
+
50
+ ```
51
+ <history summary>
52
+
53
+ ---
54
+
55
+ **Turn Context (split turn):**
56
+
57
+ <turn prefix summary>
58
+ ```
59
+
60
+ - Optional custom instructions are appended to the prompt.
61
+ - If `compaction.remoteEndpoint` is set, OMP POSTs `{ systemPrompt, prompt }` to the endpoint and expects `{ summary, shortSummary? }`.
62
+ 5. **Finalize**: Generate a short PR-style summary from recent messages, append file-operation tags, persist `CompactionEntry`, and reload session context.
63
+
64
+ Compaction rewrites the session like this:
45
65
 
46
66
  ```
47
67
  Before compaction:
@@ -75,87 +95,65 @@ What the LLM sees:
75
95
  prompt from cmp messages from firstKeptEntryId
76
96
  ```
77
97
 
78
- ### Split Turns
79
-
80
- A "turn" starts with a user message and includes all assistant responses and tool calls until the next user message. Normally, compaction cuts at turn boundaries.
81
-
82
- When a single turn exceeds `keepRecentTokens`, the cut point lands mid-turn at an assistant message. This is a "split turn":
98
+ Compaction summaries are injected into the LLM context using `compaction-summary-context.md`.
83
99
 
84
- ```
85
- Split turn (one huge turn exceeds budget):
86
-
87
- entry: 0 1 2 3 4 5 6 7 8
88
- ┌─────┬─────┬─────┬──────┬─────┬──────┬──────┬─────┬──────┐
89
- │ hdr │ usr │ ass │ tool │ ass │ tool │ tool │ ass │ tool │
90
- └─────┴─────┴─────┴──────┴─────┴──────┴──────┴─────┴──────┘
91
- ↑ ↑
92
- turnStartIndex = 1 firstKeptEntryId = 7
93
- │ │
94
- └──── turnPrefixMessages (1-6) ───────┘
95
- └── kept (7-8)
96
-
97
- isSplitTurn = true
98
- messagesToSummarize = [] (no complete turns before)
99
- turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
100
- ```
100
+ ### Split Turns
101
101
 
102
- For split turns, omp generates two summaries and merges them:
102
+ A "turn" starts with a user message and includes all assistant responses and tool calls until the next user message. `bashExecution` messages and `custom_message`/`branch_summary` entries are treated like user messages for turn boundaries.
103
103
 
104
- 1. **History summary**: Previous context (if any)
105
- 2. **Turn prefix summary**: The early part of the split turn
104
+ If a single turn exceeds `keepRecentTokens`, compaction cuts mid-turn at a non-user message (usually an assistant message). OMP produces two summaries (history + turn prefix) and merges them as shown above.
106
105
 
107
106
  ### Cut Point Rules
108
107
 
109
108
  Valid cut points are:
110
109
 
111
- - User messages
112
- - Assistant messages
113
- - BashExecution messages
114
- - Hook messages (custom_message, branch_summary)
110
+ - User, assistant, bashExecution, hookMessage, branchSummary, or compactionSummary messages
111
+ - `custom_message` and `branch_summary` entries (treated as user-role messages)
115
112
 
116
- Never cut at tool results (they must stay with their tool call).
113
+ Never cut at tool results; they must stay with their tool call. Non-message entries (model changes, labels, etc.) are pulled into the kept region before the cut point until a message or compaction boundary is reached.
117
114
 
118
115
  ### CompactionEntry Structure
119
116
 
120
- Defined in [`src/core/session-manager.ts`](../src/core/session-manager.ts):
117
+ Defined in [`src/session/session-manager.ts`](../src/session/session-manager.ts):
121
118
 
122
119
  ```typescript
123
120
  interface CompactionEntry<T = unknown> {
124
121
  type: "compaction";
125
122
  id: string;
126
- parentId: string;
127
- timestamp: number;
123
+ parentId: string | null;
124
+ timestamp: string;
128
125
  summary: string;
126
+ shortSummary?: string;
129
127
  firstKeptEntryId: string;
130
128
  tokensBefore: number;
131
- fromHook?: boolean; // true if hook provided the compaction
132
- details?: T; // hook-specific data
129
+ details?: T;
130
+ preserveData?: Record<string, unknown>;
131
+ fromExtension?: boolean;
133
132
  }
134
133
 
135
- // Default compaction uses this for details (from compaction.ts):
134
+ // Default compaction details:
136
135
  interface CompactionDetails {
137
136
  readFiles: string[];
138
137
  modifiedFiles: string[];
139
138
  }
140
139
  ```
141
140
 
142
- Hooks can store any JSON-serializable data in `details`. The default compaction tracks file operations, but custom compaction hooks can use their own structure.
143
-
144
- See [`prepareCompaction()`](../src/core/compaction/compaction.ts) and [`compact()`](../src/core/compaction/compaction.ts) for the implementation.
141
+ `shortSummary` is used in the UI tree. `preserveData` stores hook-provided state across compactions. Entries created by hooks set `fromExtension` and are excluded from default file tracking.
145
142
 
146
143
  ## Branch Summarization
147
144
 
148
145
  ### When It Triggers
149
146
 
150
- When you use `/tree` to navigate to a different branch, omp offers to summarize the work you're leaving. This injects context from the left branch into the new branch.
147
+ When you use `/tree` to navigate to a different branch, the UI prompts to summarize the branch you're leaving if `branchSummary.enabled` is true. You can optionally supply custom instructions.
148
+
149
+ Hooks fire regardless of user choice; a summary is only generated when `preparation.userWantsSummary` is true.
151
150
 
152
151
  ### How It Works
153
152
 
154
- 1. **Find common ancestor**: Deepest node shared by old and new positions
155
- 2. **Collect entries**: Walk from old leaf back to common ancestor
156
- 3. **Prepare with budget**: Include messages up to token budget (newest first)
157
- 4. **Generate summary**: Call LLM with structured format
158
- 5. **Append entry**: Save `BranchSummaryEntry` at navigation point
153
+ 1. **Find common ancestor**: Deepest node shared by old and new positions.
154
+ 2. **Collect entries**: Walk from old leaf back to the common ancestor (including compactions and prior branch summaries).
155
+ 3. **Budget**: Keep newest messages first under the token budget (`contextWindow - branchSummary.reserveTokens`).
156
+ 4. **Summarize**: Generate summary with `branch-summary.md`, prepend `branch-summary-preamble.md`, append file-op tags, and store `BranchSummaryEntry`.
159
157
 
160
158
  ```
161
159
  Tree before navigation:
@@ -174,127 +172,151 @@ After navigation with summary:
174
172
  └─ E ─ F (new leaf)
175
173
  ```
176
174
 
177
- ### Cumulative File Tracking
178
-
179
- Both compaction and branch summarization track files cumulatively. When generating a summary, omp extracts file operations from:
180
-
181
- - Tool calls in the messages being summarized
182
- - Previous compaction or branch summary `details` (if any)
183
-
184
- This means file tracking accumulates across multiple compactions or nested branch summaries, preserving the full history of read and modified files.
175
+ Branch summaries are injected into context using `branch-summary-context.md`.
185
176
 
186
177
  ### BranchSummaryEntry Structure
187
178
 
188
- Defined in [`src/core/session-manager.ts`](../src/core/session-manager.ts):
179
+ Defined in [`src/session/session-manager.ts`](../src/session/session-manager.ts):
189
180
 
190
181
  ```typescript
191
182
  interface BranchSummaryEntry<T = unknown> {
192
183
  type: "branch_summary";
193
184
  id: string;
194
- parentId: string;
195
- timestamp: number;
185
+ parentId: string | null;
186
+ timestamp: string;
187
+ fromId: string;
196
188
  summary: string;
197
- fromId: string; // Entry we navigated from
198
- fromHook?: boolean; // true if hook provided the summary
199
- details?: T; // hook-specific data
189
+ details?: T;
190
+ fromExtension?: boolean;
200
191
  }
201
192
 
202
- // Default branch summarization uses this for details (from branch-summarization.ts):
193
+ // Default branch summary details:
203
194
  interface BranchSummaryDetails {
204
195
  readFiles: string[];
205
196
  modifiedFiles: string[];
206
197
  }
207
198
  ```
208
199
 
209
- Same as compaction, hooks can store custom data in `details`.
200
+ ## Cumulative File Tracking
201
+
202
+ Both compaction and branch summarization track files cumulatively.
203
+
204
+ - File ops are extracted from `read`, `write`, and `edit` tool calls in assistant messages.
205
+ - Writes and edits are treated as modified files; read-only files exclude those modified.
206
+ - Compaction includes file ops from previous compaction details (only when `fromExtension` is false).
207
+ - Branch summaries include file ops from previous branch summary details even if those entries aren't within the token budget.
210
208
 
211
- See [`collectEntriesForBranchSummary()`](../src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](../src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](../src/core/compaction/branch-summarization.ts) for the implementation.
209
+ File lists are appended to the summary with XML tags:
210
+
211
+ ```
212
+ <read-files>
213
+ path/to/file.ts
214
+ </read-files>
215
+
216
+ <modified-files>
217
+ path/to/changed.ts
218
+ </modified-files>
219
+ ```
212
220
 
213
221
  ## Summary Format
214
222
 
215
- Both compaction and branch summarization use the same structured format:
223
+ ### Compaction Summary Format
224
+
225
+ Prompt: [`compaction-summary.md`](../src/prompts/compaction/compaction-summary.md)
216
226
 
217
227
  ```markdown
218
228
  ## Goal
219
-
220
- [What the user is trying to accomplish]
229
+ [User goals]
221
230
 
222
231
  ## Constraints & Preferences
223
-
224
- - [Requirements mentioned by user]
232
+ - [Constraints]
225
233
 
226
234
  ## Progress
227
235
 
228
236
  ### Done
229
-
230
237
  - [x] [Completed tasks]
231
238
 
232
239
  ### In Progress
233
-
234
240
  - [ ] [Current work]
235
241
 
236
242
  ### Blocked
237
-
238
243
  - [Issues, if any]
239
244
 
240
245
  ## Key Decisions
241
-
242
246
  - **[Decision]**: [Rationale]
243
247
 
244
248
  ## Next Steps
245
-
246
249
  1. [What should happen next]
247
250
 
248
251
  ## Critical Context
249
-
250
252
  - [Data needed to continue]
251
253
 
252
- <read-files>
253
- path/to/file1.ts
254
- path/to/file2.ts
255
- </read-files>
254
+ ## Additional Notes
255
+ [Anything else important not covered above]
256
+ ```
256
257
 
257
- <modified-files>
258
- path/to/changed.ts
259
- </modified-files>
258
+ File-operation tags are appended after the summary.
259
+
260
+ ### Branch Summary Format
261
+
262
+ Prompt: [`branch-summary.md`](../src/prompts/compaction/branch-summary.md)
263
+
264
+ ```markdown
265
+ ## Goal
266
+
267
+ [What user trying to accomplish in this branch?]
268
+
269
+ ## Constraints & Preferences
270
+ - [Constraints, preferences, requirements mentioned]
271
+ - [(none) if none mentioned]
272
+
273
+ ## Progress
274
+
275
+ ### Done
276
+ - [x] [Completed tasks/changes]
277
+
278
+ ### In Progress
279
+ - [ ] [Work started but not finished]
280
+
281
+ ### Blocked
282
+ - [Issues preventing progress]
283
+
284
+ ## Key Decisions
285
+ - **[Decision]**: [Brief rationale]
286
+
287
+ ## Next Steps
288
+ 1. [What should happen next to continue]
260
289
  ```
261
290
 
262
- ### Message Serialization
291
+ ### Short Summary
292
+
293
+ Compaction also generates a short PR-style summary (`compaction-short-summary.md`) for UI display. It is 2–3 sentences in first person, describing changes made.
263
294
 
264
- Before summarization, messages are serialized to text via [`serializeConversation()`](../src/core/compaction/utils.ts):
295
+ ## Message Serialization
296
+
297
+ Before summarization, messages are serialized to text via [`serializeConversation()`](../src/session/compaction/utils.ts). Messages are first converted with `convertToLlm()` so custom types (bash execution, hook messages, compaction summaries) are represented as user messages.
265
298
 
266
299
  ```
267
300
  [User]: What they said
268
301
  [Assistant thinking]: Internal reasoning
269
302
  [Assistant]: Response text
270
303
  [Assistant tool calls]: read(path="foo.ts"); edit(path="bar.ts", ...)
271
- [Tool result]: Output from tool
304
+ [Tool result]: Output from tool (or "[Output truncated - N tokens]")
272
305
  ```
273
306
 
274
- This prevents the model from treating it as a conversation to continue.
307
+ This prevents the model from treating the input as a conversation to continue.
275
308
 
276
309
  ## Custom Summarization via Hooks
277
310
 
278
- Hooks can intercept and customize both compaction and branch summarization. See [`src/core/hooks/types.ts`](../src/core/hooks/types.ts) for event type definitions.
311
+ Hooks can customize both compaction and branch summarization. See [`src/extensibility/hooks/types.ts`](../src/extensibility/hooks/types.ts).
279
312
 
280
313
  ### session_before_compact
281
314
 
282
- Fired before auto-compaction or `/compact`. Can cancel or provide custom summary. See `SessionBeforeCompactEvent` and `CompactionPreparation` in the types file.
315
+ Fired before auto-compaction or `/compact`. Can cancel or supply a custom summary.
283
316
 
284
317
  ```typescript
285
318
  pi.on("session_before_compact", async (event, ctx) => {
286
- const { preparation, branchEntries, customInstructions, signal } = event;
287
-
288
- // preparation.messagesToSummarize - messages to summarize
289
- // preparation.turnPrefixMessages - split turn prefix (if isSplitTurn)
290
- // preparation.previousSummary - previous compaction summary
291
- // preparation.fileOps - extracted file operations
292
- // preparation.tokensBefore - context tokens before compaction
293
- // preparation.firstKeptEntryId - where kept messages start
294
- // preparation.settings - compaction settings
295
-
296
- // branchEntries - all entries on current branch (for custom state)
297
- // signal - AbortSignal (pass to LLM calls)
319
+ const { preparation, customInstructions, signal } = event;
298
320
 
299
321
  // Cancel:
300
322
  return { cancel: true };
@@ -303,6 +325,7 @@ pi.on("session_before_compact", async (event, ctx) => {
303
325
  return {
304
326
  compaction: {
305
327
  summary: "Your summary...",
328
+ shortSummary: "Short summary...",
306
329
  firstKeptEntryId: preparation.firstKeptEntryId,
307
330
  tokensBefore: preparation.tokensBefore,
308
331
  details: {
@@ -323,16 +346,7 @@ import { convertToLlm, serializeConversation } from "@oh-my-pi/pi-coding-agent";
323
346
  pi.on("session_before_compact", async (event, ctx) => {
324
347
  const { preparation } = event;
325
348
 
326
- // Convert AgentMessage[] to Message[], then serialize to text
327
349
  const conversationText = serializeConversation(convertToLlm(preparation.messagesToSummarize));
328
- // Returns:
329
- // [User]: message text
330
- // [Assistant thinking]: thinking content
331
- // [Assistant]: response text
332
- // [Assistant tool calls]: read(path="..."); bash(command="...")
333
- // [Tool result]: output text
334
-
335
- // Now send to your model for summarization
336
350
  const summary = await myModel.summarize(conversationText);
337
351
 
338
352
  return {
@@ -347,9 +361,25 @@ pi.on("session_before_compact", async (event, ctx) => {
347
361
 
348
362
  See [examples/hooks/custom-compaction.ts](../examples/hooks/custom-compaction.ts) for a complete example using a different model.
349
363
 
364
+ ### session.compacting
365
+
366
+ Fired just before summarization to override the prompt or add extra context.
367
+
368
+ ```typescript
369
+ pi.on("session.compacting", async (event, ctx) => {
370
+ return {
371
+ prompt: "Override the default compaction prompt...",
372
+ context: ["Include ticket ABC-123", "Keep recent benchmark results"],
373
+ preserveData: { artifactIndex: ["foo.ts"] },
374
+ };
375
+ });
376
+ ```
377
+
378
+ `context` lines are injected as `<additional-context>` in the prompt. `preserveData` is stored on the compaction entry.
379
+
350
380
  ### session_before_tree
351
381
 
352
- Fired before `/tree` navigation. Always fires regardless of whether user chose to summarize. Can cancel navigation or provide custom summary.
382
+ Fired before `/tree` navigation. Always fires, even if the user opts out of summarization.
353
383
 
354
384
  ```typescript
355
385
  pi.on("session_before_tree", async (event, ctx) => {
@@ -378,26 +408,29 @@ pi.on("session_before_tree", async (event, ctx) => {
378
408
  });
379
409
  ```
380
410
 
381
- See `SessionBeforeTreeEvent` and `TreePreparation` in the types file.
382
-
383
411
  ## Settings
384
412
 
385
- Configure compaction in `~/.omp/agent/settings.json` or `<project-dir>/.omp/settings.json`:
386
-
387
- ```json
388
- {
389
- "compaction": {
390
- "enabled": true,
391
- "reserveTokens": 16384,
392
- "keepRecentTokens": 20000
393
- }
394
- }
413
+ Global settings are stored in `~/.omp/agent/config.yml`. Project-level overrides are loaded from `settings.json` in config directories (for example `.omp/settings.json` or `.claude/settings.json`).
414
+
415
+ ```yaml
416
+ # ~/.omp/agent/config.yml
417
+ compaction:
418
+ enabled: true
419
+ reserveTokens: 16384
420
+ keepRecentTokens: 20000
421
+ autoContinue: true
422
+ remoteEndpoint: "https://example.com/compaction"
423
+ branchSummary:
424
+ enabled: false
425
+ reserveTokens: 16384
395
426
  ```
396
427
 
397
- | Setting | Default | Description |
398
- | ------------------ | ------- | -------------------------------------- |
399
- | `enabled` | `true` | Enable auto-compaction |
400
- | `reserveTokens` | `16384` | Tokens to reserve for LLM response |
401
- | `keepRecentTokens` | `20000` | Recent tokens to keep (not summarized) |
402
-
403
- Disable auto-compaction with `"enabled": false`. You can still compact manually with `/compact`.
428
+ | Setting | Default | Description |
429
+ | ------------------------------ | ------- | ------------------------------------------------------ |
430
+ | `compaction.enabled` | `true` | Enable auto-compaction |
431
+ | `compaction.reserveTokens` | `16384` | Tokens reserved for prompts + response |
432
+ | `compaction.keepRecentTokens` | `20000` | Recent tokens to keep |
433
+ | `compaction.autoContinue` | `true` | Auto-send a continuation prompt after compaction |
434
+ | `compaction.remoteEndpoint` | unset | Remote summarization endpoint |
435
+ | `branchSummary.enabled` | `false` | Prompt to summarize when leaving a branch |
436
+ | `branchSummary.reserveTokens` | `16384` | Tokens reserved for branch summary prompts |