From 8c963655fe047c80f0d12ba3826aefcb4815f556 Mon Sep 17 00:00:00 2001 From: NagyVikt Date: Wed, 15 Apr 2026 19:08:58 +0200 Subject: [PATCH] Enable cleanup max-branches limit forwarding Allow gx cleanup to accept --max-branches and pass it through to branch pruning with strict validation and clearer watch logging. Constraint: Must stay backward compatible with existing cleanup defaults Rejected: Hardcode a fixed branch limit | removes operator control over cleanup window Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep parseCleanupArgs and cleanup arg forwarding in sync for future cleanup options Tested: node --check bin/multiagent-safety.js; npm test Not-tested: Manual long-running cleanup watch against large real repositories --- bin/multiagent-safety.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bin/multiagent-safety.js b/bin/multiagent-safety.js index 4d7b000..d66db9b 100755 --- a/bin/multiagent-safety.js +++ b/bin/multiagent-safety.js @@ -2410,6 +2410,7 @@ function parseCleanupArgs(rawArgs) { watch: false, intervalSeconds: 60, once: false, + maxBranches: 0, }; for (let index = 0; index < rawArgs.length; index += 1) { @@ -2495,6 +2496,19 @@ function parseCleanupArgs(rawArgs) { options.once = true; continue; } + if (arg === '--max-branches') { + const next = rawArgs[index + 1]; + if (!next) { + throw new Error('--max-branches requires an integer value'); + } + const parsed = Number.parseInt(next, 10); + if (!Number.isInteger(parsed) || parsed < 1) { + throw new Error('--max-branches must be an integer >= 1'); + } + options.maxBranches = parsed; + index += 1; + continue; + } throw new Error(`Unknown option: ${arg}`); } @@ -4565,6 +4579,9 @@ function cleanup(rawArgs) { if (options.idleMinutes > 0) { args.push('--idle-minutes', String(options.idleMinutes)); } + if (options.maxBranches > 0) { + args.push('--max-branches', String(options.maxBranches)); + } args.push('--delete-branches'); if (!options.keepRemote) { args.push('--delete-remote-branches'); @@ -4582,7 +4599,7 @@ function cleanup(rawArgs) { while (true) { cycle += 1; console.log( - `[${TOOL_NAME}] Cleanup watch cycle=${cycle} (interval=${options.intervalSeconds}s, idleMinutes=${options.idleMinutes}).`, + `[${TOOL_NAME}] Cleanup watch cycle=${cycle} (interval=${options.intervalSeconds}s, idleMinutes=${options.idleMinutes}, maxBranches=${options.maxBranches > 0 ? options.maxBranches : "unbounded"}).`, ); runCleanupCycle(); if (options.once) {