@@ -235,70 +235,32 @@ export function formatPlan(plan: SyncPlan): string {
235235 processOperations ( diff . toDelete , "DELETE" , toolName ) ;
236236 }
237237
238- // Format grouped operations
239- const createOps = Array . from ( itemOperations . values ( ) ) . filter (
240- ( op ) => op . operation === "CREATE" ,
241- ) ;
242- const updateOps = Array . from ( itemOperations . values ( ) ) . filter (
243- ( op ) => op . operation === "UPDATE" ,
244- ) ;
245- const deleteOps = Array . from ( itemOperations . values ( ) ) . filter (
246- ( op ) => op . operation === "DELETE" ,
247- ) ;
248-
249- if ( createOps . length > 0 ) {
250- // Calculate actual operation count (items × targets for each item)
251- const createOpCount = createOps . reduce (
252- ( sum , op ) => sum + op . targets . length ,
253- 0 ,
254- ) ;
255- lines . push (
256- `✨ CREATE (${ createOpCount } ${ createOpCount === 1 ? "operation" : "operations" } ):` ,
238+ // Format grouped operations - DRY: data-driven approach eliminates 3x duplication
239+ const operationConfigs = [
240+ { type : "CREATE" as const , emoji : "✨" , prefix : "+" } ,
241+ { type : "UPDATE" as const , emoji : "🔄" , prefix : "~" } ,
242+ { type : "DELETE" as const , emoji : "🗑️ " , prefix : "-" } ,
243+ ] ;
244+
245+ for ( const { type, emoji, prefix } of operationConfigs ) {
246+ const ops = Array . from ( itemOperations . values ( ) ) . filter (
247+ ( op ) => op . operation === type ,
257248 ) ;
258- for ( const op of createOps ) {
259- const targetStr =
260- op . targets . length === targetTools . length
261- ? t ( "planner.allTargets" )
262- : op . targets . join ( ", " ) ;
263- lines . push ( ` + [${ op . type } ] ${ op . name } → ${ targetStr } ` ) ;
264- }
265- lines . push ( "" ) ;
266- }
267249
268- if ( updateOps . length > 0 ) {
269- // Calculate actual operation count (items × targets for each item)
270- const updateOpCount = updateOps . reduce (
271- ( sum , op ) => sum + op . targets . length ,
272- 0 ,
273- ) ;
274- lines . push (
275- `🔄 UPDATE (${ updateOpCount } ${ updateOpCount === 1 ? "operation" : "operations" } ):` ,
276- ) ;
277- for ( const op of updateOps ) {
278- const targetStr =
279- op . targets . length === targetTools . length
280- ? t ( "planner.allTargets" )
281- : op . targets . join ( ", " ) ;
282- lines . push ( ` ~ [${ op . type } ] ${ op . name } → ${ targetStr } ` ) ;
283- }
284- lines . push ( "" ) ;
285- }
250+ if ( ops . length === 0 ) continue ;
286251
287- if ( deleteOps . length > 0 ) {
288252 // Calculate actual operation count (items × targets for each item)
289- const deleteOpCount = deleteOps . reduce (
290- ( sum , op ) => sum + op . targets . length ,
291- 0 ,
292- ) ;
253+ const opCount = ops . reduce ( ( sum , op ) => sum + op . targets . length , 0 ) ;
293254 lines . push (
294- `🗑️ DELETE (${ deleteOpCount } ${ deleteOpCount === 1 ? "operation" : "operations" } ):` ,
255+ `${ emoji } ${ type } (${ opCount } ${ opCount === 1 ? "operation" : "operations" } ):` ,
295256 ) ;
296- for ( const op of deleteOps ) {
257+
258+ for ( const op of ops ) {
297259 const targetStr =
298260 op . targets . length === targetTools . length
299261 ? t ( "planner.allTargets" )
300262 : op . targets . join ( ", " ) ;
301- lines . push ( ` - [${ op . type } ] ${ op . name } → ${ targetStr } ` ) ;
263+ lines . push ( ` ${ prefix } [${ op . type } ] ${ op . name } → ${ targetStr } ` ) ;
302264 }
303265 lines . push ( "" ) ;
304266 }
0 commit comments