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:
38
src/ClaudeDo.Worker/Lifecycle/ClaudeCliPreflight.cs
Normal file
38
src/ClaudeDo.Worker/Lifecycle/ClaudeCliPreflight.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user