The-Agency/lib/src/commands/doctor.dart

72 lines
2.7 KiB
Dart

import 'dart:io';
import '../command.dart';
import '../local_state.dart' show joinPath;
const _largeClaudeMdWarningChars = 40000;
Future<CommandResult> run(CommandContext context, List<String> args) async {
final workingDirectory = Directory(context.workingDirectory);
final legacyRoot = Directory(joinPath(context.workingDirectory, 'old_repo'));
final claudeMdFile = File(
joinPath(joinPath(context.workingDirectory, '.the_agency'), 'THE_AGENCY.md'),
);
final hasGit = await Directory(joinPath(context.workingDirectory, '.git')).exists();
final hasLegacyPackageManifest =
await File(joinPath(legacyRoot.path, 'package.json')).exists() ||
await File(joinPath(legacyRoot.path, 'tsconfig.json')).exists();
final configFile = File(context.settingsStore.path);
final runtimeFile = File(context.runtimeStateStore.path);
context.writeLine('Doctor');
context.writeLine(
'Runtime: Dart ${Platform.version.split(' ').first} on ${Platform.operatingSystem}',
);
context.writeLine('Working directory: ${workingDirectory.path}');
context.writeLine('');
context.writeLine(
'[ok] settings: ${await configFile.exists() ? context.settingsStore.path : 'missing'}',
);
context.writeLine(
'[ok] runtime state: ${await runtimeFile.exists() ? context.runtimeStateStore.path : 'missing'}',
);
context.writeLine(
'[${await legacyRoot.exists() ? 'ok' : 'warn'}] legacy source root: ${legacyRoot.path}',
);
context.writeLine(
'[${hasGit ? 'ok' : 'warn'}] git repository: ${hasGit ? 'detected' : 'not detected'}',
);
if (await claudeMdFile.exists()) {
final length = await claudeMdFile.length();
final level = length > _largeClaudeMdWarningChars ? 'warn' : 'ok';
context.writeLine(
'[$level] THE_AGENCY.md: ${claudeMdFile.path} (${length.toString()} bytes)',
);
} else {
context.writeLine('[warn] THE_AGENCY.md: not found');
}
context.writeLine(
'[${hasLegacyPackageManifest ? 'ok' : 'warn'}] legacy manifests: ${hasLegacyPackageManifest ? 'detected' : 'old_repo has no package.json or tsconfig.json at its root'}',
);
context.writeLine('');
context.writeLine('Notes:');
if (!hasGit) {
context.writeLine(' - This workspace is not currently inside a git repository.');
}
if (!hasLegacyPackageManifest) {
context.writeLine(
' - Exact legacy runtime reproduction is harder because old_repo lacks a checked-in package manifest.',
);
}
if (!await legacyRoot.exists()) {
context.writeLine(' - old_repo is missing, so legacy source parity checks cannot run.');
}
if (hasGit && hasLegacyPackageManifest && await legacyRoot.exists()) {
context.writeLine(' - No obvious environment blockers detected.');
}
return const CommandResult();
}