@henryqw/pi-auto-compact 2.0.2 → 2.0.3
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 +1 -1
- package/extensions/auto-compact.ts +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ Use `/auto-compact` to set the compaction threshold.
|
|
|
42
42
|
- It checks `turn_start`, tool-call `turn_end`, `agent_end`, `context`, and resumed or forked `session_start`.
|
|
43
43
|
- Its consumer-owned `pi-auto-compact/autoCompact` task defaults to `fast`.
|
|
44
44
|
- It tries the effective profile primary, then fallback. If neither route works, the current session model still compacts.
|
|
45
|
-
- After mid-task compaction,
|
|
45
|
+
- After mid-task compaction, it resumes the current task automatically.
|
|
46
46
|
|
|
47
47
|
## Config
|
|
48
48
|
|
|
@@ -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: () => {
|