@@ -187,6 +187,46 @@ function formatDocumentInfo(result: unknown, ctx: FormatContext): string {
187187 return lines . join ( '\n' ) ;
188188}
189189
190+ // ---------------------------------------------------------------------------
191+ // Diff formatters
192+ // ---------------------------------------------------------------------------
193+
194+ function formatDiffSnapshot ( result : unknown , ctx : FormatContext ) : string {
195+ const record = asRecord ( result ) ;
196+ if ( ! record ) return `Revision ${ ctx . revision } : captured snapshot` ;
197+ const fingerprint = hasNonEmptyString ( record . fingerprint ) ? record . fingerprint : '<unknown>' ;
198+ const coverage = asRecord ( record . coverage ) ;
199+ const components = coverage
200+ ? Object . entries ( coverage )
201+ . filter ( ( [ , v ] ) => v === true )
202+ . map ( ( [ k ] ) => k )
203+ . join ( ', ' )
204+ : 'body' ;
205+ const payloadSize = record . payload ? JSON . stringify ( record . payload ) . length : 0 ;
206+ return `Revision ${ ctx . revision } : captured snapshot\n fingerprint: ${ fingerprint } \n coverage: ${ components } \n payload size: ${ payloadSize } bytes` ;
207+ }
208+
209+ function formatDiffPayload ( result : unknown , ctx : FormatContext ) : string {
210+ const record = asRecord ( result ) ;
211+ if ( ! record ) return `Revision ${ ctx . revision } : compared documents` ;
212+ const summary = asRecord ( record . summary ) ;
213+ const changed = asArray ( summary ?. changedComponents ) . filter ( hasNonEmptyString ) ;
214+ const baseFp = hasNonEmptyString ( record . baseFingerprint ) ? record . baseFingerprint : '<unknown>' ;
215+ const targetFp = hasNonEmptyString ( record . targetFingerprint ) ? record . targetFingerprint : '<unknown>' ;
216+ const changedStr = changed . length > 0 ? changed . join ( ', ' ) : 'none' ;
217+ return `Revision ${ ctx . revision } : compared documents\n base: ${ baseFp } \n target: ${ targetFp } \n changed: ${ changedStr } ` ;
218+ }
219+
220+ function formatDiffApplyResult ( result : unknown , ctx : FormatContext ) : string {
221+ const record = asRecord ( result ) ;
222+ if ( ! record ) return `Revision ${ ctx . revision } : applied diff` ;
223+ const ops = safeNumber ( record . appliedOperations , 0 ) ;
224+ const summary = asRecord ( record . summary ) ;
225+ const changed = asArray ( summary ?. changedComponents ) . filter ( hasNonEmptyString ) ;
226+ const changedStr = changed . length > 0 ? changed . join ( ', ' ) : 'none' ;
227+ return `Revision ${ ctx . revision } : applied diff (${ ops } operations)\n changed: ${ changedStr } ` ;
228+ }
229+
190230// ---------------------------------------------------------------------------
191231// Dispatch
192232// ---------------------------------------------------------------------------
@@ -200,6 +240,9 @@ const FORMAT_DISPATCH: Partial<Record<OutputFormat, Formatter>> = {
200240 listResult : ( result , ctx ) => formatListResult ( result , ctx ) ,
201241 trackChangeList : ( result , ctx ) => formatTrackChangeList ( result , ctx ) ,
202242 documentInfo : ( result , ctx ) => formatDocumentInfo ( result , ctx ) ,
243+ diffSnapshot : ( result , ctx ) => formatDiffSnapshot ( result , ctx ) ,
244+ diffPayload : ( result , ctx ) => formatDiffPayload ( result , ctx ) ,
245+ diffApplyResult : ( result , ctx ) => formatDiffApplyResult ( result , ctx ) ,
203246} ;
204247
205248/**
0 commit comments