agentSdkNodeProblem function
Why nodeExecutable cannot run the AI server, as a sentence naming the
remedy, or null when it can.
Why the version is checked and not only the runnability. The Agent SDK
does not run the CLI in the server process: it spawns Claude Code as a
grandchild, which fails to parse its own bundle on an older Node. A
machine whose node is v16 therefore starts the server perfectly well and
then dies with "exited with code 1" from a process the user never asked
for. Checking here converts that into the sentence it always was.
Why an unrecognisable version passes. The check exists to catch a known-too-old Node, not to gatekeep identity: refusing everything it could not parse would refuse any wrapper, launcher or stand-in that works fine. Only a positively identified major below the floor is rejected.
Implementation
Future<String?> agentSdkNodeProblem(String nodeExecutable) async {
final ProcessResult result;
try {
result = await Process.run(nodeExecutable, const [
'--version',
], runInShell: false);
} on ProcessException {
return agentSdkNodeNotRunnableReason(nodeExecutable);
}
if (result.exitCode != 0)
return agentSdkNodeNotRunnableReason(nodeExecutable);
final match = RegExp(
r'^v(\d+)\.\d+\.\d+',
).firstMatch('${result.stdout}${result.stderr}'.trim());
final major = match == null ? null : int.tryParse(match.group(1)!);
if (major != null && major < requiredNodeMajorVersion) {
return agentSdkNodeTooOldReason(nodeExecutable, major);
}
return null;
}