@lll9p/pi-better-compaction 0.5.0 → 0.6.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/README.md CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  English | [中文](README.zh-CN.md)
4
4
 
5
- A [pi](https://github.com/nicepkg/pi) extension that upgrades context compaction with three coordinated strategies:
5
+ A [pi](https://github.com/nicepkg/pi) extension that upgrades context compaction with two coordinated strategies:
6
6
 
7
- 1. An optional **mid-run guard** aborts an oversized tool loop, waits for `agent_settled`, compacts once, then resumes with a hidden custom message.
8
- 2. **OpenAI Responses APIs** use the provider's native compaction endpoint, preserving opaque context that plain text summaries lose.
9
- 3. **All other APIs** (Anthropic, Gemini, etc.) can run pi's built-in compaction with a **dedicated cheaper/faster model**, so summarization doesn't consume quota on your primary model.
7
+ 1. **OpenAI Responses APIs** use the provider's native compaction endpoint, preserving opaque context that plain text summaries lose.
8
+ 2. **All other APIs** (Anthropic, Gemini, etc.) can run pi's built-in compaction with a **dedicated cheaper/faster model**, so summarization doesn't consume quota on your primary model.
10
9
 
11
10
  Everything fails open — if any step cannot proceed, pi's default compaction takes over.
12
11
 
@@ -70,8 +69,8 @@ If the file doesn't exist, all defaults apply. The extension never creates this
70
69
  | Option | Type | Default | Description |
71
70
  |--------|------|---------|-------------|
72
71
  | `enabled` | `boolean` | `true` | Master switch. Set `false` to disable the extension entirely. |
73
- | `midRun.enabled` | `boolean` | `false` | Enable the mid-run guard. It may abort a long tool loop once context reaches the configured threshold. |
74
- | `midRun.thresholdPercent` | `number` | `80` | Context usage percentage that triggers the mid-run guard after a tool-bearing turn. Must be greater than 0 and at most 100. |
72
+ | `midRun.enabled` | `boolean` | `false` | Reserved and currently ignored. The mid-run guard remains disabled even when set to `true`. |
73
+ | `midRun.thresholdPercent` | `number` | `80` | Reserved threshold for the disabled mid-run guard. Must be greater than 0 and at most 100. |
75
74
  | `compactionVersion` | `"v1" \| "v2"` | `"v2"` | Protocol for Responses-family APIs. **V2** (streaming, encrypted blob) is the current OpenAI default. **V1** uses the legacy `/responses/compact` endpoint. |
76
75
  | `compactionModel` | `string \| null` | `null` | Model for fallback compaction (non-Responses APIs, or when native compact fails). Format: `"provider/model-id"`, e.g. `"openai/gpt-5.1-mini"`. `null` = let pi use the current chat model. |
77
76
  | `compactionThinkingLevel` | `string` | `"off"` | Thinking level for the fallback compaction model. One of: `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. |
@@ -84,17 +83,6 @@ If the file doesn't exist, all defaults apply. The extension never creates this
84
83
  | `redactSensitiveData` | `boolean` | `true` | Redact secrets in debug artifacts. |
85
84
  | `artifactRoot` | `string` | `"~/.pi/agent/artifacts/pi-better-compaction"` | Root directory for debug artifacts. Supports `~/` and relative paths (resolved against config dir). |
86
85
 
87
- ### Example: enable mid-run compaction
88
-
89
- ```json
90
- {
91
- "midRun": {
92
- "enabled": true,
93
- "thresholdPercent": 80
94
- }
95
- }
96
- ```
97
-
98
86
  ### Example: use a cheap model for fallback compaction
99
87
 
100
88
  ```json
@@ -114,8 +102,6 @@ If the file doesn't exist, all defaults apply. The extension never creates this
114
102
 
115
103
  ## How it works
116
104
 
117
- With `midRun.enabled`, a completed tool-bearing `turn_end` above the threshold only calls `ctx.abort()`. After Pi emits `agent_settled`, the guard reuses any compaction Pi already completed during abort handling; otherwise it calls `ctx.compact()` exactly once. A successful or coalesced compaction triggers the next turn with a hidden custom message. Failed compaction does not resume, preventing a compact-fail-resume loop.
118
-
119
105
  When pi triggers compaction (`session_before_compact`):
120
106
 
121
107
  1. **Responses API detected** → run native compaction (V2 or V1 per config):
package/README.zh-CN.md CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  [English](README.md) | 中文
4
4
 
5
- 一个 [pi](https://github.com/nicepkg/pi) 扩展,通过三条协同策略提升上下文压缩效果:
5
+ 一个 [pi](https://github.com/nicepkg/pi) 扩展,通过两条协同策略提升上下文压缩效果:
6
6
 
7
- 1. 可选的 **mid-run guard** 在工具循环占满上下文时先中止运行,等待 `agent_settled` 后只压缩一次,再通过隐藏消息继续任务。
8
- 2. **OpenAI Responses 系列 API** 使用提供商原生压缩端点,保留纯文本摘要无法留存的不透明上下文。
9
- 3. **其他所有 API**(Anthropic、Gemini 等)可用一个**独立的低成本模型**执行 pi 内置压缩,避免在主模型上消耗额度。
7
+ 1. **OpenAI Responses 系列 API** 使用提供商原生压缩端点,保留纯文本摘要无法留存的不透明上下文。
8
+ 2. **其他所有 API**(Anthropic、Gemini 等)可用一个**独立的低成本模型**执行 pi 内置压缩,避免在主模型上消耗额度。
10
9
 
11
10
  所有环节都安全降级——任何步骤无法执行时,pi 的默认压缩自动接管。
12
11
 
@@ -70,8 +69,8 @@ cd pi-better-compaction && pi install .
70
69
  | 选项 | 类型 | 默认值 | 说明 |
71
70
  |------|------|--------|------|
72
71
  | `enabled` | `boolean` | `true` | 总开关。设为 `false` 完全禁用扩展。 |
73
- | `midRun.enabled` | `boolean` | `false` | 启用 mid-run guard。上下文达到阈值后,它可能主动中止长工具循环。 |
74
- | `midRun.thresholdPercent` | `number` | `80` | 工具型 turn 完成后触发 mid-run guard 的上下文占用百分比。必须大于 0 且不超过 100。 |
72
+ | `midRun.enabled` | `boolean` | `false` | 保留配置,当前会被忽略。即使设为 `true`,mid-run guard 仍保持禁用。 |
73
+ | `midRun.thresholdPercent` | `number` | `80` | 已禁用的 mid-run guard 的保留阈值。必须大于 0 且不超过 100。 |
75
74
  | `compactionVersion` | `"v1" \| "v2"` | `"v2"` | Responses 系列 API 的压缩协议。**V2**(流式,加密 blob)是 OpenAI 当前默认协议;**V1** 使用旧版 `/responses/compact` 端点。 |
76
75
  | `compactionModel` | `string \| null` | `null` | 回退压缩使用的模型(用于非 Responses API,或原生压缩失败时)。格式:`"provider/model-id"`,如 `"openai/gpt-5.1-mini"`。`null` = 由 pi 使用当前对话模型。 |
77
76
  | `compactionThinkingLevel` | `string` | `"off"` | 回退压缩模型的思考级别。可选:`off`、`minimal`、`low`、`medium`、`high`、`xhigh`、`max`。 |
@@ -84,17 +83,6 @@ cd pi-better-compaction && pi install .
84
83
  | `redactSensitiveData` | `boolean` | `true` | 在调试文件中脱敏。 |
85
84
  | `artifactRoot` | `string` | `"~/.pi/agent/artifacts/pi-better-compaction"` | 调试文件根目录。支持 `~/` 和相对路径(相对于配置文件目录解析)。 |
86
85
 
87
- ### 示例:启用 mid-run 压缩
88
-
89
- ```json
90
- {
91
- "midRun": {
92
- "enabled": true,
93
- "thresholdPercent": 80
94
- }
95
- }
96
- ```
97
-
98
86
  ### 示例:使用低成本模型做回退压缩
99
87
 
100
88
  ```json
@@ -114,8 +102,6 @@ cd pi-better-compaction && pi install .
114
102
 
115
103
  ## 工作原理
116
104
 
117
- 启用 `midRun.enabled` 后,超过阈值的工具型 `turn_end` 只调用 `ctx.abort()`。Pi 发出 `agent_settled` 后,guard 会复用 abort 收尾阶段已经完成的压缩;如果没有,则只调用一次 `ctx.compact()`。压缩成功或竞争合并后,通过隐藏 custom message 触发下一轮。压缩失败时不会自动继续,避免进入“压缩失败—继续—再次失败”的循环。
118
-
119
105
  pi 触发压缩时(`session_before_compact`):
120
106
 
121
107
  1. **检测到 Responses API** → 执行原生压缩(根据配置选择 V2 或 V1):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lll9p/pi-better-compaction",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Better compaction for pi: native /responses/compact replay for OpenAI Responses APIs, plus a configurable compaction model driving pi's native summarization everywhere else.",
6
6
  "author": "Lilin Lao",
@@ -10,7 +10,6 @@ import { executeV2Compaction } from "./compact-client-v2";
10
10
  import { loadExtensionConfig } from "./config";
11
11
  import { writeDebugArtifact } from "./debug";
12
12
  import { resolveLatestNativeCompactionEntry } from "./details-store";
13
- import { registerMidRunGuard } from "./midrun";
14
13
  import { runNativeFallbackCompaction } from "./native-fallback";
15
14
  import {
16
15
  rewriteResponsesPayloadWithNativeReplay,
@@ -672,8 +671,7 @@ export function registerExtensionRuntime(
672
671
  pi: ExtensionAPI,
673
672
  dependencies: ExtensionRuntimeDependencies = DEFAULT_DEPENDENCIES,
674
673
  ): void {
675
- registerMidRunGuard(pi, dependencies.loadExtensionConfig);
676
-
674
+ // Mid-run compaction is intentionally disabled regardless of config.
677
675
  pi.on("session_start", (_event, ctx) => {
678
676
  const { config, source, warnings } = dependencies.loadExtensionConfig();
679
677
  if (!config.enabled) return;