@mariozechner/pi-coding-agent 0.27.4 → 0.27.5
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 +11 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +96 -18
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction.d.ts +7 -0
- package/dist/core/compaction.d.ts.map +1 -1
- package/dist/core/compaction.js +26 -0
- package/dist/core/compaction.js.map +1 -1
- package/dist/core/export-html.d.ts +11 -2
- package/dist/core/export-html.d.ts.map +1 -1
- package/dist/core/export-html.js +551 -94
- package/dist/core/export-html.js.map +1 -1
- package/dist/core/hooks/types.d.ts +20 -2
- package/dist/core/hooks/types.d.ts.map +1 -1
- package/dist/core/hooks/types.js.map +1 -1
- package/docs/hooks.md +54 -1
- package/package.json +6 -5
package/docs/hooks.md
CHANGED
|
@@ -130,6 +130,11 @@ user clears session (/clear)
|
|
|
130
130
|
├─► session (reason: "before_clear", can cancel)
|
|
131
131
|
└─► session (reason: "clear", AFTER clear)
|
|
132
132
|
|
|
133
|
+
context compaction (auto or /compact)
|
|
134
|
+
│
|
|
135
|
+
├─► session (reason: "before_compact", can cancel or provide custom summary)
|
|
136
|
+
└─► session (reason: "compact", AFTER compaction)
|
|
137
|
+
|
|
133
138
|
user exits (double Ctrl+C or Ctrl+D)
|
|
134
139
|
│
|
|
135
140
|
└─► session (reason: "shutdown")
|
|
@@ -147,7 +152,7 @@ pi.on("session", async (event, ctx) => {
|
|
|
147
152
|
// event.sessionFile: string | null - current session file (null with --no-session)
|
|
148
153
|
// event.previousSessionFile: string | null - previous session file
|
|
149
154
|
// event.reason: "start" | "before_switch" | "switch" | "before_clear" | "clear" |
|
|
150
|
-
// "before_branch" | "branch" | "shutdown"
|
|
155
|
+
// "before_branch" | "branch" | "before_compact" | "compact" | "shutdown"
|
|
151
156
|
// event.targetTurnIndex: number - only for "before_branch" and "branch"
|
|
152
157
|
|
|
153
158
|
// Cancel a before_* action:
|
|
@@ -168,10 +173,26 @@ pi.on("session", async (event, ctx) => {
|
|
|
168
173
|
- `before_switch` / `switch`: User switched sessions (`/resume`)
|
|
169
174
|
- `before_clear` / `clear`: User cleared the session (`/clear`)
|
|
170
175
|
- `before_branch` / `branch`: User branched the session (`/branch`)
|
|
176
|
+
- `before_compact` / `compact`: Context compaction (auto or `/compact`)
|
|
171
177
|
- `shutdown`: Process is exiting (double Ctrl+C, Ctrl+D, or SIGTERM)
|
|
172
178
|
|
|
173
179
|
For `before_branch` and `branch` events, `event.targetTurnIndex` contains the entry index being branched from.
|
|
174
180
|
|
|
181
|
+
For `before_compact` events, additional fields are available:
|
|
182
|
+
- `event.cutPoint`: Where the context will be cut (`firstKeptEntryIndex`, `isSplitTurn`)
|
|
183
|
+
- `event.messagesToSummarize`: Messages that will be summarized
|
|
184
|
+
- `event.tokensBefore`: Current context token count
|
|
185
|
+
- `event.model`: Model to use for summarization
|
|
186
|
+
- `event.apiKey`: API key for the model
|
|
187
|
+
- `event.customInstructions`: Optional custom focus for summary (from `/compact` command)
|
|
188
|
+
|
|
189
|
+
Return `{ compactionEntry }` to provide a custom summary instead of the default. The `compactionEntry` must have: `type: "compaction"`, `timestamp`, `summary`, `firstKeptEntryIndex` (from `cutPoint`), `tokensBefore`.
|
|
190
|
+
|
|
191
|
+
For `compact` events (after compaction):
|
|
192
|
+
- `event.compactionEntry`: The saved compaction entry
|
|
193
|
+
- `event.tokensBefore`: Token count before compaction
|
|
194
|
+
- `event.fromHook`: Whether the compaction entry was provided by a hook
|
|
195
|
+
|
|
175
196
|
### agent_start / agent_end
|
|
176
197
|
|
|
177
198
|
Fired once per user prompt.
|
|
@@ -603,6 +624,38 @@ export default function (pi: HookAPI) {
|
|
|
603
624
|
}
|
|
604
625
|
```
|
|
605
626
|
|
|
627
|
+
### Custom Compaction
|
|
628
|
+
|
|
629
|
+
Use a cheaper model for summarization, or implement your own compaction strategy.
|
|
630
|
+
|
|
631
|
+
```typescript
|
|
632
|
+
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
|
633
|
+
import type { CompactionEntry } from "@mariozechner/pi-coding-agent";
|
|
634
|
+
|
|
635
|
+
export default function (pi: HookAPI) {
|
|
636
|
+
pi.on("session", async (event, ctx) => {
|
|
637
|
+
if (event.reason !== "before_compact") return;
|
|
638
|
+
|
|
639
|
+
// Example: Use a simpler summarization approach
|
|
640
|
+
const messages = event.messagesToSummarize;
|
|
641
|
+
const summary = messages
|
|
642
|
+
.filter((m) => m.role === "user")
|
|
643
|
+
.map((m) => `- ${typeof m.content === "string" ? m.content.slice(0, 100) : "[complex]"}`)
|
|
644
|
+
.join("\n");
|
|
645
|
+
|
|
646
|
+
const compactionEntry: CompactionEntry = {
|
|
647
|
+
type: "compaction",
|
|
648
|
+
timestamp: new Date().toISOString(),
|
|
649
|
+
summary: `User requests:\n${summary}`,
|
|
650
|
+
firstKeptEntryIndex: event.cutPoint.firstKeptEntryIndex,
|
|
651
|
+
tokensBefore: event.tokensBefore,
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
return { compactionEntry };
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
```
|
|
658
|
+
|
|
606
659
|
## Mode Behavior
|
|
607
660
|
|
|
608
661
|
Hooks behave differently depending on the run mode:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mariozechner/pi-coding-agent",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.5",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -39,15 +39,16 @@
|
|
|
39
39
|
"prepublishOnly": "npm run clean && npm run build"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@mariozechner/pi-agent-core": "^0.27.
|
|
43
|
-
"@mariozechner/pi-ai": "^0.27.
|
|
44
|
-
"@mariozechner/pi-tui": "^0.27.
|
|
42
|
+
"@mariozechner/pi-agent-core": "^0.27.5",
|
|
43
|
+
"@mariozechner/pi-ai": "^0.27.5",
|
|
44
|
+
"@mariozechner/pi-tui": "^0.27.5",
|
|
45
45
|
"chalk": "^5.5.0",
|
|
46
46
|
"cli-highlight": "^2.1.11",
|
|
47
47
|
"diff": "^8.0.2",
|
|
48
48
|
"file-type": "^21.1.1",
|
|
49
49
|
"glob": "^11.0.3",
|
|
50
|
-
"jiti": "^2.6.1"
|
|
50
|
+
"jiti": "^2.6.1",
|
|
51
|
+
"marked": "^15.0.12"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@types/diff": "^7.0.2",
|