@@ -102,6 +102,12 @@ function cloneJsonValue<T>(value: T): T {
102102 return structuredClone ( value ) ;
103103}
104104
105+ function removeContentBlock < T > ( content : T [ ] , blockIndex : number ) : T [ ] | null {
106+ const nextContent = cloneJsonValue ( content ) ;
107+ nextContent . splice ( blockIndex , 1 ) ;
108+ return nextContent . length > 0 ? nextContent : null ;
109+ }
110+
105111function normalizeClaudeCliContent (
106112 content : string | unknown [ ] ,
107113 toolNameRegistry : ToolNameRegistry ,
@@ -305,9 +311,8 @@ function parseClaudeCliHistoryEntry(
305311 }
306312 // The receipt proves only the matching text block is synthetic.
307313 // Preserve sibling images or other native content that has no local duplicate proof.
308- const nextContent = cloneJsonValue ( content ) ;
309- nextContent . splice ( candidate . blockIndex , 1 ) ;
310- if ( nextContent . length === 0 ) {
314+ const nextContent = removeContentBlock ( content , candidate . blockIndex ) ;
315+ if ( ! nextContent ) {
311316 return null ;
312317 }
313318 content = nextContent ;
@@ -316,12 +321,20 @@ function parseClaudeCliHistoryEntry(
316321 for ( const candidate of promptTextCandidates ) {
317322 const reseedPrompt = parseCliReseedPrompt ( candidate . text ) ;
318323 if ( reseedPrompt . kind === "legacy" ) {
319- if ( ! reseedPrompt . userMessage ) {
320- return null ;
321- }
322324 if ( candidate . blockIndex === undefined ) {
325+ if ( ! reseedPrompt . userMessage ) {
326+ return null ;
327+ }
323328 content = reseedPrompt . userMessage ;
324329 } else if ( Array . isArray ( content ) ) {
330+ if ( ! reseedPrompt . userMessage ) {
331+ const contentWithoutReseed = removeContentBlock ( content , candidate . blockIndex ) ;
332+ if ( ! contentWithoutReseed ) {
333+ return null ;
334+ }
335+ content = contentWithoutReseed ;
336+ break ;
337+ }
325338 const nextContent = cloneJsonValue ( content ) ;
326339 const block = nextContent [ candidate . blockIndex ] ;
327340 if ( block && typeof block === "object" ) {
0 commit comments