@narumitw/pi-codex-compact 0.49.5 → 0.50.1

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,10 +2,6 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-codex-compact)](https://www.npmjs.com/package/@narumitw/pi-codex-compact) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- > [!WARNING]
6
- > This extension is experimental. It depends on an undocumented OpenAI Codex Responses wire
7
- > contract and stores provider-specific opaque checkpoints. Keep backups of important sessions.
8
-
9
5
  `@narumitw/pi-codex-compact` adds Codex Remote Compaction V2 to the
10
6
  [Pi Coding Agent](https://pi.dev) for the built-in `openai-codex` OAuth provider. It replaces Pi's
11
7
  plaintext summary-generation call with a server-generated opaque compaction item and safely replays
@@ -47,7 +43,7 @@ pi -e npm:@narumitw/pi-codex-compact
47
43
  Try a local checkout from the repository root:
48
44
 
49
45
  ```bash
50
- pi -e ./experimental/pi-codex-compact
46
+ pi -e ./packages/pi-codex-compact
51
47
  # or
52
48
  just try codex-compact
53
49
  ```
@@ -63,8 +59,7 @@ and the local workspace at the same time.
63
59
  4. Run `/codex-compact` to inspect the effective route or choose **Compact now**.
64
60
  5. After compaction, continue the session normally; compatible requests replay the opaque checkpoint.
65
61
 
66
- The extension shows an experimental warning at session start in UI-capable modes. When the active
67
- model is unsupported, compaction remains entirely Pi-native.
62
+ When the active model is unsupported, compaction remains entirely Pi-native.
68
63
 
69
64
  ## 💬 Command
70
65
 
@@ -191,9 +186,10 @@ An individually oversized media item is dropped rather than making the session e
191
186
  oldest fitting text item may be partially truncated to preserve newer context. These hard byte
192
187
  ceilings are intentionally not configurable.
193
188
 
194
- ## 🚧 Experimental limitations
189
+ ## 🚧 Known limitations
195
190
 
196
- - The wire contract is undocumented and can change independently of Pi or this package.
191
+ - The wire contract is undocumented and can change independently of Pi or this package. Keep
192
+ backups of important sessions.
197
193
  - Full older history depends on this extension and the same compatible model. Removing the extension
198
194
  exposes only the portability fallback marker and Pi-retained recent messages.
199
195
  - The package does not reproduce Codex core's context-window UUID/number lineage, previous-model
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@narumitw/pi-codex-compact",
3
- "version": "0.49.5",
4
- "description": "Experimental Codex Remote Compaction V2 for Pi's OpenAI Codex provider.",
3
+ "version": "0.50.1",
4
+ "description": "Codex Remote Compaction V2 for Pi's OpenAI Codex provider.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -23,6 +23,9 @@
23
23
  "./src/index.ts"
24
24
  ]
25
25
  },
26
+ "piExtension": {
27
+ "lifecycle": "stable"
28
+ },
26
29
  "scripts": {
27
30
  "check": "biome check --vcs-use-ignore-file=false src test package.json tsconfig.json README.md && npm run typecheck",
28
31
  "format": "biome check --write --vcs-use-ignore-file=false src test package.json tsconfig.json README.md",
@@ -38,15 +41,15 @@
38
41
  },
39
42
  "devDependencies": {
40
43
  "@biomejs/biome": "2.5.7",
41
- "@earendil-works/pi-agent-core": "0.83.0",
42
- "@earendil-works/pi-ai": "0.83.0",
43
- "@earendil-works/pi-coding-agent": "0.83.0",
44
+ "@earendil-works/pi-agent-core": "0.84.1",
45
+ "@earendil-works/pi-ai": "0.84.1",
46
+ "@earendil-works/pi-coding-agent": "0.84.1",
44
47
  "@types/node": "26.1.2",
45
48
  "typescript": "7.0.2"
46
49
  },
47
50
  "repository": {
48
51
  "type": "git",
49
52
  "url": "https://github.com/narumiruna/pi-extensions",
50
- "directory": "experimental/pi-codex-compact"
53
+ "directory": "packages/pi-codex-compact"
51
54
  }
52
55
  }
package/src/checkpoint.ts CHANGED
@@ -123,6 +123,15 @@ export function latestCheckpoint(entries: readonly SessionEntry[]):
123
123
  return undefined;
124
124
  }
125
125
 
126
+ function isOlderCompactionSummary(message: AgentMessage, timestamp: number): boolean {
127
+ return (
128
+ message.role === "compactionSummary" &&
129
+ Number.isFinite(message.timestamp) &&
130
+ Number.isFinite(timestamp) &&
131
+ message.timestamp < timestamp
132
+ );
133
+ }
134
+
126
135
  export function projectCheckpointContext(
127
136
  messages: readonly AgentMessage[],
128
137
  details: CodexCheckpointDetails,
@@ -132,21 +141,33 @@ export function projectCheckpointContext(
132
141
  (message) => message.role === "compactionSummary" && message.summary === summary,
133
142
  );
134
143
  if (summaryIndex < 0) return undefined;
135
- const keptStart = summaryIndex + 1;
136
- const keptEnd = keptStart + details.keptMessageFingerprints.length;
137
- if (keptEnd > messages.length) return undefined;
138
- for (let index = keptStart; index < keptEnd; index++) {
139
- if (
140
- fingerprintMessage(messages[index]) !== details.keptMessageFingerprints[index - keptStart]
141
- ) {
142
- return undefined;
144
+ const timestamp = messages[summaryIndex].timestamp;
145
+ let messageIndex = summaryIndex + 1;
146
+ let fingerprintIndex = 0;
147
+ while (fingerprintIndex < details.keptMessageFingerprints.length) {
148
+ if (messageIndex >= messages.length) return undefined;
149
+ const message = messages[messageIndex];
150
+ if (fingerprintMessage(message) === details.keptMessageFingerprints[fingerprintIndex]) {
151
+ messageIndex += 1;
152
+ fingerprintIndex += 1;
153
+ continue;
154
+ }
155
+ if (isOlderCompactionSummary(message, timestamp)) {
156
+ messageIndex += 1;
157
+ continue;
143
158
  }
159
+ return undefined;
160
+ }
161
+ while (
162
+ messageIndex < messages.length &&
163
+ isOlderCompactionSummary(messages[messageIndex], timestamp)
164
+ ) {
165
+ messageIndex += 1;
144
166
  }
145
- const timestamp = messages[summaryIndex].timestamp;
146
167
  return [
147
168
  ...messages.slice(0, summaryIndex),
148
169
  markerMessage(details.checkpointId, timestamp),
149
- ...messages.slice(keptEnd),
170
+ ...messages.slice(messageIndex),
150
171
  ];
151
172
  }
152
173
 
@@ -30,8 +30,6 @@ import {
30
30
  import { showCodexCompactMenu } from "./settings-menu.js";
31
31
 
32
32
  const STATUS_KEY = "codex-compact";
33
- const EXPERIMENTAL_WARNING =
34
- "Experimental: Codex Remote Compaction V2 uses an opaque, provider-specific checkpoint. Sessions require this extension and openai-codex for full replay.";
35
33
 
36
34
  function isSupportedModel(model: Model<Api> | undefined): model is Model<"openai-codex-responses"> {
37
35
  return model?.provider === "openai-codex" && hasApi(model, "openai-codex-responses");
@@ -186,7 +184,7 @@ export function createCodexCompactExtension(
186
184
  let generation = 0;
187
185
 
188
186
  pi.registerCommand("codex-compact", {
189
- description: "Compact now or configure experimental Codex Remote Compaction V2",
187
+ description: "Compact now or configure Codex Remote Compaction V2",
190
188
  handler: async (_args, ctx) => {
191
189
  const ownerGeneration = generation;
192
190
  await showCodexCompactMenu(settingsRuntime, ctx, {
@@ -223,14 +221,11 @@ export function createCodexCompactExtension(
223
221
  ) {
224
222
  return;
225
223
  }
226
- if (ctx.hasUI) {
227
- ctx.ui.notify(EXPERIMENTAL_WARNING, "warning");
228
- if (state.kind === "invalid") {
229
- ctx.ui.notify(
230
- `Invalid pi-codex-compact.json; using defaults without overwriting it. ${state.issue}`,
231
- "warning",
232
- );
233
- }
224
+ if (ctx.hasUI && state.kind === "invalid") {
225
+ ctx.ui.notify(
226
+ `Invalid pi-codex-compact.json; using defaults without overwriting it. ${state.issue}`,
227
+ "warning",
228
+ );
234
229
  }
235
230
  });
236
231