* Partition candidates by their prior decision state: * - mustReapply: previously replaced → re-apply the cached replacement for * prefix stability * - frozen: previously seen and left unreplaced → off-limits (replacing * now would change a prefix that was already cached) * - fresh: ne
( candidates: ToolResultCandidate[], state: ContentReplacementState, )
| 647 | * - fresh: never seen → eligible for new replacement decisions |
| 648 | */ |
| 649 | function partitionByPriorDecision( |
| 650 | candidates: ToolResultCandidate[], |
| 651 | state: ContentReplacementState, |
| 652 | ): CandidatePartition { |
| 653 | return candidates.reduce<CandidatePartition>( |
| 654 | (acc, c) => { |
| 655 | const replacement = state.replacements.get(c.toolUseId) |
| 656 | if (replacement !== undefined) { |
| 657 | acc.mustReapply.push({ ...c, replacement }) |
| 658 | } else if (state.seenIds.has(c.toolUseId)) { |
| 659 | acc.frozen.push(c) |
| 660 | } else { |
| 661 | acc.fresh.push(c) |
| 662 | } |
| 663 | return acc |
| 664 | }, |
| 665 | { mustReapply: [], frozen: [], fresh: [] }, |
| 666 | ) |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Pick the largest fresh results to replace until the model-visible total |
no test coverage detected