@henryqw/pi-auto-compact 2.0.2 → 2.0.4
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/README.md +12 -6
- package/extensions/auto-compact.ts +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
# `@henryqw/pi-auto-compact`
|
|
2
2
|
|
|
3
|
-
Compact context
|
|
3
|
+
Compact Pi context at your chosen threshold, then continue the interrupted task automatically.
|
|
4
4
|
|
|
5
5
|
## Why
|
|
6
6
|
|
|
7
|
-
- **Created for**:
|
|
8
|
-
- **Advantage**:
|
|
7
|
+
- **Created for**: Long Pi sessions that need predictable context headroom.
|
|
8
|
+
- **Advantage**: Compact early through a shared model route, without making users restart the task.
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
12
|
+
Install the required Task Models extension first:
|
|
13
|
+
|
|
12
14
|
```bash
|
|
13
15
|
pi install npm:@henryqw/pi-task-models
|
|
14
16
|
pi install npm:@henryqw/pi-auto-compact
|
|
15
17
|
```
|
|
16
18
|
|
|
19
|
+
Run `/task-models` and configure the `fast` profile. Open `/task-models` again to verify that `fast` no longer says `not configured`.
|
|
20
|
+
|
|
17
21
|
Disable Pi's built-in auto-compaction in `~/.pi/agent/settings.json`:
|
|
18
22
|
|
|
19
23
|
```json
|
|
@@ -24,11 +28,13 @@ Disable Pi's built-in auto-compaction in `~/.pi/agent/settings.json`:
|
|
|
24
28
|
}
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
Restart Pi after install or settings changes. Trusted
|
|
31
|
+
Restart Pi after install or settings changes. Trusted `.pi/settings.json` files must not set `compaction.enabled` back to `true`.
|
|
32
|
+
|
|
33
|
+
Run `/auto-compact`, enter a threshold, and expect `Auto-compact threshold set to <value>%.`
|
|
28
34
|
|
|
29
35
|
## With
|
|
30
36
|
|
|
31
|
-
This package requires `@henryqw/pi-task-models` for shared compaction routes.
|
|
37
|
+
This package requires [`@henryqw/pi-task-models`](https://pi.henry.wang/extensions/pi-task-models) for shared compaction routes.
|
|
32
38
|
|
|
33
39
|
`~/.pi/agent/config/pi-task-models/config.json` is shared and owned by `@henryqw/pi-task-models`. The local `pi-auto-compact/autoCompact` declaration defaults to `fast`. A task entry is an explicit user override.
|
|
34
40
|
|
|
@@ -42,7 +48,7 @@ Use `/auto-compact` to set the compaction threshold.
|
|
|
42
48
|
- It checks `turn_start`, tool-call `turn_end`, `agent_end`, `context`, and resumed or forked `session_start`.
|
|
43
49
|
- Its consumer-owned `pi-auto-compact/autoCompact` task defaults to `fast`.
|
|
44
50
|
- It tries the effective profile primary, then fallback. If neither route works, the current session model still compacts.
|
|
45
|
-
- After mid-task compaction,
|
|
51
|
+
- After mid-task compaction, it resumes the current task automatically.
|
|
46
52
|
|
|
47
53
|
## Config
|
|
48
54
|
|
|
@@ -27,7 +27,7 @@ type AgentMessage = Parameters<typeof estimateTokens>[0];
|
|
|
27
27
|
* - context: last-resort guard with a temporary keep-recent context.
|
|
28
28
|
*
|
|
29
29
|
* Pi's ctx.compact() aborts active low-level run internally. Mid-task
|
|
30
|
-
* compaction sends a
|
|
30
|
+
* compaction sends a custom continuation message after summary.
|
|
31
31
|
*/
|
|
32
32
|
const DEFAULT_COMPACT_THRESHOLD_PERCENT = 70;
|
|
33
33
|
const MIN_COMPACT_THRESHOLD_PERCENT = 25;
|
|
@@ -87,6 +87,7 @@ function withoutDeletedHeaders(headers: Record<string, string | null> | undefine
|
|
|
87
87
|
// Emergency context guard keeps recent messages while default compaction runs.
|
|
88
88
|
const KEEP_RECENT_PERCENT = 15;
|
|
89
89
|
const COMPACTION_INSTRUCTIONS = "Preserve current task to be resumed after compaction.";
|
|
90
|
+
const RESUME_MESSAGE_TYPE = "pi-auto-compact/resume";
|
|
90
91
|
const RESUME_MESSAGE = "Auto-compact ran. Continue the current task.";
|
|
91
92
|
const COMPACTION_ABORT_ERROR = "This operation was aborted";
|
|
92
93
|
const ACTIVATION_ERROR =
|
|
@@ -166,7 +167,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
166
167
|
// Pi may flush queued input during compaction_end. Wait one macrotask
|
|
167
168
|
// before checking idle, otherwise follow-up can race that flush.
|
|
168
169
|
setImmediate(() => {
|
|
169
|
-
if (ctx.isIdle())
|
|
170
|
+
if (!ctx.isIdle()) return;
|
|
171
|
+
pi.sendMessage({
|
|
172
|
+
customType: RESUME_MESSAGE_TYPE,
|
|
173
|
+
content: RESUME_MESSAGE,
|
|
174
|
+
display: false,
|
|
175
|
+
}, { triggerTurn: true });
|
|
170
176
|
});
|
|
171
177
|
},
|
|
172
178
|
onError: () => {
|