discoverHostedAiWorkspaces function
Every VS Code CLI server answering right now, for the workspace pin.
Lives here rather than in the composition root because the scan belongs
beside the transport that consumes it — and because the root would otherwise
need its own dependency on tom_vscode_scripting_api to ask a question this
package already knows how to ask.
Returns every responder, including duplicates of one identity: two windows on one workspace answer identically, and a settings picker needs to know that before it offers the name as a choice. Sorted by port so the list is stable between scans.
Implementation
Future<List<AgentSdkWorkspaceCandidate>> discoverHostedAiWorkspaces({
String host = '127.0.0.1',
int minPort = defaultVSCodeBridgePort,
int maxPort = maxVSCodeBridgePort,
}) async {
final table = await scanBridgePorts(
host: host,
minPort: minPort,
maxPort: maxPort,
);
return [
for (final entry in table.entries)
AgentSdkWorkspaceCandidate(identity: entry.value, port: entry.key),
]..sort((a, b) => a.port.compareTo(b.port));
}