@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 +5 -9
- package/package.json +9 -6
- package/src/checkpoint.ts +31 -10
- package/src/codex-compact.ts +6 -11
package/README.md
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-codex-compact) [](https://pi.dev) [](./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 ./
|
|
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
|
-
|
|
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
|
-
## 🚧
|
|
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.
|
|
4
|
-
"description": "
|
|
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.
|
|
42
|
-
"@earendil-works/pi-ai": "0.
|
|
43
|
-
"@earendil-works/pi-coding-agent": "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": "
|
|
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
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
) {
|
|
142
|
-
|
|
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(
|
|
170
|
+
...messages.slice(messageIndex),
|
|
150
171
|
];
|
|
151
172
|
}
|
|
152
173
|
|
package/src/codex-compact.ts
CHANGED
|
@@ -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
|
|
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(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|