feat(worker): add Claude CLI preflight on startup

Worker now runs `claude --version` before listening; on non-zero exit
it logs critical and exits with code 1. Skippable via env var
CLAUDEDO_SKIP_CLI_PREFLIGHT=1 for environments without the CLI (tests,
dev). Closes verification step 2 / open.md item 3.1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-04-30 14:17:44 +02:00
parent 4c92da55ad
commit df66c4af46
3 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using System.Diagnostics;
namespace ClaudeDo.Worker.Lifecycle;
public static class ClaudeCliPreflight
{
public sealed record Result(bool Ok, string Version, string Error, int ExitCode);
public static async Task<Result> CheckAsync(string claudeBin, CancellationToken ct = default)
{
try
{
var psi = new ProcessStartInfo
{
FileName = claudeBin,
Arguments = "--version",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
};
using var proc = Process.Start(psi);
if (proc is null) return new Result(false, "", "Process.Start returned null", -1);
var stdoutTask = proc.StandardOutput.ReadToEndAsync(ct);
var stderrTask = proc.StandardError.ReadToEndAsync(ct);
await proc.WaitForExitAsync(ct);
var stdout = (await stdoutTask).Trim();
var stderr = (await stderrTask).Trim();
return new Result(proc.ExitCode == 0, stdout, stderr, proc.ExitCode);
}
catch (Exception ex)
{
return new Result(false, "", ex.Message, -1);
}
}
}