From 2918368c475a92fbf8aa7ca016cccca53e31aa19 Mon Sep 17 00:00:00 2001 From: Jonathon Byrdziak Date: Fri, 20 Mar 2026 18:35:13 -0700 Subject: [PATCH] Add --verbose flag to protocol start for live debugging When run with -v/--verbose, protocol start: - Prints all stage log messages to stdout in real time - Passes output to subcommands instead of suppressing it - Disables animated stage display for plain sequential output Allows diagnosing hangs without checking log files. Co-Authored-By: Claude Opus 4.6 --- src/Commands/ProtocolStart.php | 21 +++++++++++---------- src/Helpers/StageRunner.php | 25 ++++++++++++++++--------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Commands/ProtocolStart.php b/src/Commands/ProtocolStart.php index ffa2305..8a41fbe 100644 --- a/src/Commands/ProtocolStart.php +++ b/src/Commands/ProtocolStart.php @@ -138,12 +138,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Prepare sub-command inputs $arrInput = new ArrayInput(['--dir' => $repo_dir]); $arrInput1 = new ArrayInput(['--dir' => $repo_dir, 'environment' => $environment]); - $nullOutput = new NullOutput(); + $verbose = $output->isVerbose(); + $subOutput = $verbose ? $output : new NullOutput(); $app = $this->getApplication(); $output->writeln(''); - $runner = new StageRunner($output); + $runner = new StageRunner($output, $verbose); // ── Stage 1: Scanning codebase ────────────────────────── $runner->run('Scanning codebase', function() use ($repo_dir, $environment, $strategy) { @@ -159,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int }); // ── Stage 2: Infrastructure provisioning ──────────────── - $runner->run('Infrastructure provisioning', function() use ($runner, $app, $arrInput, $arrInput1, $nullOutput, $repo_dir, $environment, $strategy, $isDev, $nodeConfig, $nodeData) { + $runner->run('Infrastructure provisioning', function() use ($runner, $app, $arrInput, $arrInput1, $subOutput, $repo_dir, $environment, $strategy, $isDev, $nodeConfig, $nodeData) { // Refresh GitHub App credentials and fix remote URLs if needed if (GitHubApp::isConfigured()) { @@ -204,15 +205,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($hasConfigRepo) { if ($configRemote) { $runner->log("Running config:slave"); - $app->find('config:slave')->run($arrInput, $nullOutput); + $app->find('config:slave')->run($arrInput, $subOutput); } $runner->log("Running config:link"); - $app->find('config:link')->run($arrInput, $nullOutput); + $app->find('config:link')->run($arrInput, $subOutput); } // Start the release watcher daemon $runner->log("Running deploy:slave"); - $app->find('deploy:slave')->run($arrInput, $nullOutput); + $app->find('deploy:slave')->run($arrInput, $subOutput); } else { // Legacy branch-based deployment mode @@ -227,20 +228,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int $runner->log("remote.origin.url={$remoteUrl}"); $runner->log("Running git:pull"); - $app->find('git:pull')->run($arrInput, $nullOutput); + $app->find('git:pull')->run($arrInput, $subOutput); $runner->log("git:pull completed"); $runner->log("Running git:slave"); - $app->find('git:slave')->run($arrInput, $nullOutput); + $app->find('git:slave')->run($arrInput, $subOutput); } if ($hasConfigRepo) { if (!$isDev && $configRemote) { $runner->log("Running config:slave"); - $app->find('config:slave')->run($arrInput, $nullOutput); + $app->find('config:slave')->run($arrInput, $subOutput); } $runner->log("Running config:link"); - $app->find('config:link')->run($arrInput, $nullOutput); + $app->find('config:link')->run($arrInput, $subOutput); } } diff --git a/src/Helpers/StageRunner.php b/src/Helpers/StageRunner.php index 7bbc105..2de91b1 100644 --- a/src/Helpers/StageRunner.php +++ b/src/Helpers/StageRunner.php @@ -19,15 +19,17 @@ class StageRunner private OutputInterface $output; private bool $isTty; + private bool $verbose; private array $completedStages = []; private float $startTime; private ?string $logFile = null; private ?string $currentStage = null; - public function __construct(OutputInterface $output) + public function __construct(OutputInterface $output, bool $verbose = false) { $this->output = $output; - $this->isTty = self::isTty(); + $this->verbose = $verbose; + $this->isTty = $verbose ? false : self::isTty(); $this->startTime = microtime(true); $this->initLog(); } @@ -67,15 +69,20 @@ private function initLog(): void */ public function log(string $message): void { - if (!$this->logFile) return; - $timestamp = date('H:i:s'); $prefix = $this->currentStage ? "[{$this->currentStage}] " : ''; - @file_put_contents( - $this->logFile, - "[{$timestamp}] {$prefix}{$message}\n", - FILE_APPEND | LOCK_EX - ); + + if ($this->logFile) { + @file_put_contents( + $this->logFile, + "[{$timestamp}] {$prefix}{$message}\n", + FILE_APPEND | LOCK_EX + ); + } + + if ($this->verbose) { + $this->output->writeln("[{$timestamp}] {$prefix}{$message}"); + } } /**