verifyAgentSdkServerSource function
The release gate: checks that sourceDir — a build's ai/ folder —
carries exactly what a release may ship of the AI server.
Two directions, both of which matter. Missing: a plain flutter build
produces an app with no ai/ folder, whose Install button then has nothing
to install from; that is invisible at run time, so the build is the only
place it can be caught. Too much: a node_modules, or anything of the
Agent SDK, in the folder means the release redistributes proprietary
software inside the application — the one thing this layout exists to
prevent, and a mistake no user would ever report.
Implementation
AgentSdkSourceVerification verifyAgentSdkServerSource({
required String sourceDir,
}) {
final sep = Platform.pathSeparator;
final problems = <String>[];
AgentSdkSourceVerification result() => AgentSdkSourceVerification(
sourceDir: sourceDir,
problems: List.unmodifiable(problems),
);
if (!Directory(sourceDir).existsSync()) {
problems.add(
'no AI server source at "$sourceDir" — this build never ran '
'tool/package_app.dart, so its Install button has nothing to install '
'from',
);
return result();
}
for (final name in agentSdkServerSourceFiles) {
final file = File('$sourceDir$sep$name');
if (!file.existsSync()) {
problems.add('"$name" is missing: "${file.path}"');
} else if (file.lengthSync() == 0) {
problems.add('"$name" is empty: "${file.path}"');
}
}
final lock = File('$sourceDir$sep$agentSdkServerLockfileName');
if (lock.existsSync() && lock.lengthSync() > 0) {
final sdk = agentSdkInLockfile(lock.readAsStringSync());
if (sdk == null) {
problems.add(
'the lockfile does not lock $_sdkScope/$_sdkName — `npm ci` would '
'install a server with no Agent SDK',
);
} else if (sdk.platforms.isEmpty) {
problems.add(
'the locked Agent SDK declares no platform CLI packages — an install '
'would have nothing to spawn',
);
}
}
if (Directory('$sourceDir${sep}node_modules').existsSync()) {
problems.add(
'the build carries "node_modules" in "$sourceDir" — the Agent SDK is '
"installed by the user under Anthropic's terms and must not ship",
);
}
// Anything of the SDK anywhere in the folder, however it got there.
for (final entity in Directory(
sourceDir,
).listSync(recursive: true, followLinks: false)) {
final name = entity.path.split(sep).last;
if (name == _sdkScope || name.startsWith(_sdkName)) {
problems.add('the build carries part of the Agent SDK: "${entity.path}"');
break;
}
}
return result();
}