@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.
- package/CHANGELOG.md +44 -0
- package/README.md +80 -79
- package/docs/compaction.md +182 -149
- package/docs/config-usage.md +141 -78
- package/docs/custom-tools.md +45 -16
- package/docs/extension-loading.md +56 -954
- package/docs/extensions.md +192 -51
- package/docs/hooks.md +109 -70
- package/docs/python-repl.md +52 -19
- package/docs/rpc.md +43 -19
- package/docs/sdk.md +270 -211
- package/docs/session-tree-plan.md +60 -417
- package/docs/session.md +104 -39
- package/docs/skills.md +59 -95
- package/docs/theme.md +139 -110
- package/docs/tree.md +42 -33
- package/docs/tui.md +226 -80
- package/package.json +8 -9
- package/src/capability/index.ts +3 -4
- package/src/cli/args.ts +4 -4
- package/src/cli/grep-cli.ts +1 -1
- package/src/commit/agentic/index.ts +4 -3
- package/src/commit/git/index.ts +2 -3
- package/src/commit/map-reduce/index.ts +2 -1
- package/src/config/prompt-templates.ts +2 -0
- package/src/config/settings-schema.ts +30 -7
- package/src/config/settings.ts +0 -14
- package/src/config.ts +2 -2
- package/src/discovery/agents.ts +36 -0
- package/src/discovery/index.ts +1 -0
- package/src/exa/mcp-client.ts +3 -3
- package/src/ipy/executor.ts +5 -7
- package/src/ipy/gateway-coordinator.ts +1 -1
- package/src/ipy/kernel.ts +20 -15
- package/src/ipy/prelude.py +1 -1
- package/src/ipy/runtime.ts +7 -6
- package/src/lsp/lspmux.ts +3 -3
- package/src/main.ts +6 -8
- package/src/mcp/tool-bridge.ts +19 -9
- package/src/modes/components/assistant-message.ts +2 -2
- package/src/modes/components/hook-editor.ts +4 -4
- package/src/modes/components/settings-defs.ts +37 -2
- package/src/modes/components/tool-execution.ts +7 -7
- package/src/modes/controllers/command-controller.ts +2 -2
- package/src/modes/controllers/event-controller.ts +4 -7
- package/src/modes/controllers/input-controller.ts +4 -4
- package/src/modes/controllers/selector-controller.ts +1 -0
- package/src/modes/interactive-mode.ts +3 -5
- package/src/modes/rpc/rpc-mode.ts +8 -9
- package/src/patch/index.ts +6 -6
- package/src/prompts/agents/explore.md +2 -2
- package/src/prompts/agents/frontmatter.md +5 -5
- package/src/prompts/agents/plan.md +3 -2
- package/src/prompts/agents/reviewer.md +1 -1
- package/src/prompts/system/system-prompt.md +1 -3
- package/src/sdk.ts +13 -9
- package/src/session/agent-session.ts +6 -4
- package/src/session/compaction/compaction.ts +3 -3
- package/src/session/session-manager.ts +8 -9
- package/src/ssh/connection-manager.ts +4 -4
- package/src/system-prompt.ts +2 -6
- package/src/task/agents.ts +1 -1
- package/src/task/executor.ts +31 -8
- package/src/task/index.ts +14 -35
- package/src/task/omp-command.ts +3 -1
- package/src/task/output-manager.ts +20 -6
- package/src/task/parallel.ts +3 -3
- package/src/task/render.ts +16 -2
- package/src/task/types.ts +13 -20
- package/src/task/worktree.ts +3 -3
- package/src/tools/ask.ts +3 -8
- package/src/tools/fetch.ts +2 -2
- package/src/tools/gemini-image.ts +5 -6
- package/src/tools/grep.ts +5 -5
- package/src/tools/index.ts +12 -5
- package/src/tools/read.ts +1 -1
- package/src/tools/todo-write.ts +2 -3
- package/src/utils/frontmatter.ts +1 -1
- package/src/utils/image-resize.ts +1 -1
- package/src/utils/timings.ts +3 -2
- package/src/web/scrapers/github.ts +2 -2
- package/src/web/scrapers/utils.ts +2 -3
- package/src/web/scrapers/youtube.ts +2 -3
- package/src/web/search/auth.ts +5 -6
- package/src/web/search/providers/anthropic.ts +3 -2
- package/src/utils/terminal-notify.ts +0 -37
package/docs/compaction.md
CHANGED
|
@@ -1,47 +1,67 @@
|
|
|
1
1
|
# Compaction & Branch Summarization
|
|
2
2
|
|
|
3
|
-
LLMs have limited context windows.
|
|
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/
|
|
8
|
-
- [`src/
|
|
9
|
-
- [`src/
|
|
10
|
-
- [`src/
|
|
11
|
-
- [`src/
|
|
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
|
|
18
|
-
| -------------------- |
|
|
19
|
-
| Compaction | Context
|
|
20
|
-
| Branch summarization | `/tree` navigation
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
37
|
+
Manual compaction is available via `/compact [instructions]`.
|
|
35
38
|
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
2. **Extract
|
|
42
|
-
3. **
|
|
43
|
-
4. **
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
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
|
|
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/
|
|
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:
|
|
123
|
+
parentId: string | null;
|
|
124
|
+
timestamp: string;
|
|
128
125
|
summary: string;
|
|
126
|
+
shortSummary?: string;
|
|
129
127
|
firstKeptEntryId: string;
|
|
130
128
|
tokensBefore: number;
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
details?: T;
|
|
130
|
+
preserveData?: Record<string, unknown>;
|
|
131
|
+
fromExtension?: boolean;
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
// Default compaction
|
|
134
|
+
// Default compaction details:
|
|
136
135
|
interface CompactionDetails {
|
|
137
136
|
readFiles: string[];
|
|
138
137
|
modifiedFiles: string[];
|
|
139
138
|
}
|
|
140
139
|
```
|
|
141
140
|
|
|
142
|
-
|
|
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,
|
|
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. **
|
|
157
|
-
4. **Generate summary
|
|
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
|
-
|
|
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/
|
|
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:
|
|
185
|
+
parentId: string | null;
|
|
186
|
+
timestamp: string;
|
|
187
|
+
fromId: string;
|
|
196
188
|
summary: string;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
details?: T; // hook-specific data
|
|
189
|
+
details?: T;
|
|
190
|
+
fromExtension?: boolean;
|
|
200
191
|
}
|
|
201
192
|
|
|
202
|
-
// Default branch
|
|
193
|
+
// Default branch summary details:
|
|
203
194
|
interface BranchSummaryDetails {
|
|
204
195
|
readFiles: string[];
|
|
205
196
|
modifiedFiles: string[];
|
|
206
197
|
}
|
|
207
198
|
```
|
|
208
199
|
|
|
209
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
</read-files>
|
|
254
|
+
## Additional Notes
|
|
255
|
+
[Anything else important not covered above]
|
|
256
|
+
```
|
|
256
257
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
386
|
-
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
|
398
|
-
|
|
|
399
|
-
| `enabled`
|
|
400
|
-
| `reserveTokens`
|
|
401
|
-
| `keepRecentTokens`
|
|
402
|
-
|
|
403
|
-
|
|
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 |
|