agentHost: support --host and print resolved server urls#306219
Merged
agentHost: support --host and print resolved server urls#306219
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds CLI/runtime support for selecting the bind host for the standalone Agent Host server and improves startup logging by printing resolved “Local” and “Network” WebSocket URLs.
Changes:
- Add
--hostsupport toscripts/code-agent-host.jsandagentHostServerMain.ts. - Introduce
resolveServerUrls/formatWebSocketUrlhelper to compute display URLs (including IPv6 bracket formatting). - Add unit tests for URL resolution/formatting behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/vs/platform/agentHost/test/node/serverUrls.test.ts | Adds tests for URL formatting and local/network URL resolution. |
| src/vs/platform/agentHost/node/serverUrls.ts | New helper to format WebSocket URLs and resolve local/network addresses for logging. |
| src/vs/platform/agentHost/node/agentHostServerMain.ts | Parses --host, passes it to the WebSocket server, and prints resolved Local/Network URLs on ready. |
| scripts/code-agent-host.js | Adds --host CLI support and changes startup behavior to rely on server-printed resolved URLs. |
Comments suppressed due to low confidence (2)
src/vs/platform/agentHost/node/serverUrls.ts:47
formatWebSocketUrlunconditionally brackets any host containing:. If the caller passes an already-bracketed IPv6 host (e.g."[::1]"), this produces an invalid URL likews://[[::1]]:8081. Consider normalizing by stripping a single surrounding[/]pair before applying the IPv6 bracketing logic.
export function formatWebSocketUrl(host: string, port: number): string {
const normalizedHost = host.includes(':') ? `[${host}]` : host;
return `ws://${normalizedHost}:${port}`;
scripts/code-agent-host.js:100
startServernow returns a Promise that never rejects and there’s no handler for the child processerrorevent. If spawning the server fails (missing build output, permission issues, etc.), the script can either crash due to an unhandlederrorevent or hang without a clear error path. Consider listening forproc.on('error', ...)and rejecting (or exiting with a non-zero code) when startup fails or the process exits before printingREADY:.
function startServer(programArgs) {
return new Promise((resolve) => {
const env = { ...process.env };
const entryPoint = path.join(
__dirname,
'..',
'out',
'vs',
'platform',
'agentHost',
'node',
'agentHostServerMain.js',
);
console.log(
`Starting agent host server: ${entryPoint} ${programArgs.join(' ')}`,
);
const proc = cp.spawn(process.execPath, [entryPoint, ...programArgs], {
env,
stdio: [process.stdin, null, process.stderr],
});
proc.stdout.on('data', (data) => {
const text = data.toString();
process.stdout.write(text);
const m = text.match(/READY:(\d+)/);
if (m) {
resolve();
}
});
proc.on('exit', (code) => process.exit(code));
connor4312
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--hostsupport toscripts/code-agent-host.jsLocalandNetworkaddresses instead of echoing the raw bind address