resolve method
Resolve nested tool wiring for the given context.
requestedCommands — commands the user is invoking. Only nested
tools providing these commands will be queried. Pass null to wire
all tools (e.g., in help mode).
workspaceRoot — workspace root for finding the wiring YAML file.
tolerateMissing — if true, missing binaries produce warnings
instead of errors (used in help mode).
Implementation
Future<WiringResult> resolve({
Set<String>? requestedCommands,
required String workspaceRoot,
bool tolerateMissing = false,
}) async {
// Step 1: Merge wiring sources
mergeWiringSources(workspaceRoot: workspaceRoot);
if (_effectiveWiring.isEmpty) {
return const WiringResult();
}
// Step 2: Determine which tools need querying
final neededTools = <String, ToolWiringEntry>{};
if (requestedCommands == null) {
// Help mode: wire all tools
neededTools.addAll(_effectiveWiring);
} else {
for (final cmdName in requestedCommands) {
final wiring = _commandToWiring[cmdName];
if (wiring != null) {
neededTools[wiring.binary] = wiring;
}
}
}
if (neededTools.isEmpty) {
return const WiringResult();
}
// Step 3: Query each needed tool
final commands = <CommandDefinition>[];
final executors = <String, NestedToolExecutor>{};
final warnings = <String>[];
final errors = <String>[];
for (final entry in neededTools.entries) {
final binary = entry.key;
final wiring = entry.value;
final resolved = resolveBinary(binary);
// Check binary exists
if (!isBinaryOnPath(resolved)) {
final msg =
':${wiring.hostCommandNames.join(', :')} '
'— binary $resolved not found';
if (tolerateMissing) {
warnings.add(msg);
// Add placeholder commands for help display
_addUnavailableCommands(commands, wiring, 'binary $binary not found');
continue;
} else {
errors.add(msg);
continue;
}
}
// Run --dump-definitions
final dumpResult = await _queryDumpDefinitions(binary, workspaceRoot);
if (dumpResult == null) {
final msg = 'Failed to query $binary --dump-definitions';
if (tolerateMissing) {
warnings.add(msg);
continue;
} else {
errors.add(msg);
continue;
}
}
// Build commands and executors from dump
_buildFromDump(wiring, dumpResult, commands, executors);
}
return WiringResult(
commands: commands,
executors: executors,
warnings: warnings,
errors: errors,
);
}