@howaboua/pi-codex-conversion 1.5.12-dev.48.bf9d02e → 1.5.13-dev.50.32bb92f

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.13
4
+
5
+ - Relaxed native compaction replay parity so the extension preserves the OpenAI compacted window using Pi's current provider payload when persisted session replay shape diverges.
6
+
3
7
  ## 1.5.12
4
8
 
5
9
  - Hardened native Responses compaction replay after Pi fallback or compacted-window shape changes, preserving the previous native compacted window without aborting normal requests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-codex-conversion",
3
- "version": "1.5.12-dev.48.bf9d02e",
3
+ "version": "1.5.13-dev.50.32bb92f",
4
4
  "description": "Codex-oriented tool and prompt adapter for pi coding agent",
5
5
  "type": "module",
6
6
  "repository": {
@@ -399,6 +399,37 @@ function clonePayloadConversationInput(args: {
399
399
  return cloneResponsesInputSlice(args.payloadInput.slice(args.freshPreamble.leadingInput.length, tailEndIndex));
400
400
  }
401
401
 
402
+ function stripLeadingCompactionSummaryPlaceholder(args: {
403
+ conversationInput: readonly ResponsesInputItem[];
404
+ compactionSummaryInput: readonly ResponsesInputItem[];
405
+ }): ResponsesInputItem[] {
406
+ if (args.compactionSummaryInput.length === 0) return [...args.conversationInput];
407
+ if (!areEquivalentValues(args.conversationInput.slice(0, args.compactionSummaryInput.length), args.compactionSummaryInput)) {
408
+ return [...args.conversationInput];
409
+ }
410
+ return [...args.conversationInput.slice(args.compactionSummaryInput.length)];
411
+ }
412
+
413
+ function buildLenientNativeReplayPayload(args: {
414
+ payload: ResponsesCompatibleRequestPayload;
415
+ freshPreamble: FreshAuthoritativePreamble;
416
+ compactedWindow: readonly unknown[];
417
+ compactionSummaryInput: readonly ResponsesInputItem[];
418
+ }): { input: unknown[]; conversationInput: ResponsesInputItem[] } | undefined {
419
+ const conversationInput = clonePayloadConversationInput({ payloadInput: args.payload.input, freshPreamble: args.freshPreamble });
420
+ if (!conversationInput) return undefined;
421
+ const replayConversationInput = stripLeadingCompactionSummaryPlaceholder({ conversationInput, compactionSummaryInput: args.compactionSummaryInput });
422
+ return {
423
+ conversationInput: replayConversationInput,
424
+ input: [
425
+ ...args.freshPreamble.leadingInput,
426
+ ...args.compactedWindow,
427
+ ...replayConversationInput,
428
+ ...args.freshPreamble.trailingInput,
429
+ ],
430
+ };
431
+ }
432
+
402
433
  function findReplayMatch<TApi extends Api>(args: {
403
434
  model: Model<TApi>;
404
435
  payloadInput: readonly unknown[];
@@ -530,9 +561,10 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
530
561
  .slice(boundaryIndex + 1)
531
562
  .some((entry) => entry.type === "compaction");
532
563
  if (newerCompactionEntry) {
533
- const conversationInput = clonePayloadConversationInput({ payloadInput: args.payload.input, freshPreamble });
564
+ const compactionSummaryInput = serializeMessagesToResponsesInput(args.model, [createCompactionSummaryAgentMessage(args.compactionEntry)]);
565
+ const lenientReplay = buildLenientNativeReplayPayload({ payload: args.payload, freshPreamble, compactedWindow, compactionSummaryInput });
534
566
  const originalPiReplayInput = cloneResponsesInputSlice(args.payload.input);
535
- if (!conversationInput || !originalPiReplayInput) {
567
+ if (!lenientReplay || !originalPiReplayInput) {
536
568
  return {
537
569
  ok: false,
538
570
  reason: "unexpected-compaction-after-boundary",
@@ -550,24 +582,14 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
550
582
  compactionSummary: [],
551
583
  preCompactionKeptWindow: createReplaySlice([], [], []),
552
584
  compactedWindow,
553
- postCompactionTail: createReplaySlice(args.branchEntries.slice(boundaryIndex + 1), [], conversationInput),
585
+ postCompactionTail: createReplaySlice(args.branchEntries.slice(boundaryIndex + 1), [], lenientReplay.conversationInput),
554
586
  originalPiReplayInput,
555
- replayInput: [
556
- ...freshPreamble.leadingInput,
557
- ...compactedWindow,
558
- ...conversationInput,
559
- ...freshPreamble.trailingInput,
560
- ],
587
+ replayInput: lenientReplay.input,
561
588
  },
562
589
  rewrittenPayload: {
563
590
  ...args.payload,
564
591
  ...(freshPreamble.instructions !== undefined ? { instructions: freshPreamble.instructions } : {}),
565
- input: [
566
- ...freshPreamble.leadingInput,
567
- ...compactedWindow,
568
- ...conversationInput,
569
- ...freshPreamble.trailingInput,
570
- ],
592
+ input: lenientReplay.input,
571
593
  },
572
594
  };
573
595
  }
@@ -587,6 +609,30 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
587
609
 
588
610
  if (!replayMatch) {
589
611
  const compactionSummaryInput = serializeMessagesToResponsesInput(args.model, [compactionSummaryMessage]);
612
+ const lenientReplay = buildLenientNativeReplayPayload({ payload: args.payload, freshPreamble, compactedWindow, compactionSummaryInput });
613
+ if (lenientReplay) {
614
+ return {
615
+ ok: true,
616
+ segments: {
617
+ boundaryIndex,
618
+ firstKeptEntryIndex,
619
+ instructions: freshPreamble.instructions,
620
+ freshPreamble: freshPreamble.leadingInput,
621
+ trailingPreamble: freshPreamble.trailingInput,
622
+ compactionSummary: compactionSummaryInput,
623
+ preCompactionKeptWindow: createReplaySlice(preCompactionEntries, [], []),
624
+ compactedWindow,
625
+ postCompactionTail: createReplaySlice(postCompactionEntries, [], lenientReplay.conversationInput),
626
+ originalPiReplayInput: cloneResponsesInputSlice(args.payload.input) ?? [],
627
+ replayInput: lenientReplay.input,
628
+ },
629
+ rewrittenPayload: {
630
+ ...args.payload,
631
+ ...(freshPreamble.instructions !== undefined ? { instructions: freshPreamble.instructions } : {}),
632
+ input: lenientReplay.input,
633
+ },
634
+ };
635
+ }
590
636
  const expectedInput = [
591
637
  ...freshPreamble.leadingInput,
592
638
  ...compactionSummaryInput,