Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/preserve-dev-web-launch-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agent-bundle": patch
---

Preserve literal stdio arguments when `agent-bundle dev` selects `/web` launches with AB8023 (#635)
15 changes: 5 additions & 10 deletions packages/agent-bundle/src/dev/web-host-launch-selection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from 'node:fs/promises';
import { isAbsolute, join, resolve } from 'node:path';
import { join, resolve } from 'node:path';

import type { TargetRegistry } from '../adapters/registry.ts';
import { digest } from '../core/digest.ts';
Expand Down Expand Up @@ -64,18 +64,11 @@ interface LaunchCandidate {
readonly target: string;
}

const normalizedStdioArgument = (
const normalizedStdioEntry = (
value: string,
artifactRoot: string,
cwd: string,
): string => {
if (
!isAbsolute(value) &&
!value.startsWith('./') &&
!value.startsWith('../') &&
!value.includes('/') &&
!value.includes('\\')
) return value;
const resolved = resolve(cwd, value);
return isInsideOrEqual(artifactRoot, resolved) ? resolved : value;
};
Expand Down Expand Up @@ -137,10 +130,12 @@ const launchIdentityOf = async (
const cwd = resolved.cwd === undefined
? artifactRoot
: assertInside(artifactRoot, resolve(artifactRoot, resolved.cwd));
const [entry, ...args] = resolved.args;
return digest({
args: resolved.args.map((argument) => normalizedStdioArgument(argument, artifactRoot, cwd)),
args,
command: resolved.command,
cwd,
entry: entry === undefined ? null : normalizedStdioEntry(entry, artifactRoot, cwd),
env: resolved.env ?? {},
kind: 'stdio',
});
Expand Down
16 changes: 16 additions & 0 deletions packages/agent-bundle/tests/web-host-launch-selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ describe('selectWebLaunch', () => {
expect(selection.sharedTargets).toEqual(['claude', 'portable']);
});

it('preserves path-looking literal arguments after the executable entry', async () => {
const root = await artifactRoot();
await writeManifest(root, '.mcp.json', {
status: claudeServer({
args: ['${CLAUDE_PLUGIN_ROOT}/mcp/mcp-status.mjs', '--label', './team/red'],
}),
});
await writeManifest(root, 'mcp.json', {
status: emittedPortableServer({
args: ['mcp/mcp-status.mjs', '--label', join(root, 'team', 'red')],
}),
});
const error = await failure(root, { declaredTargets: ['claude', 'portable'] });
expect(error.code).toBe('launch-ambiguous');
});

it('keeps an emitted portable entry distinct when it resolves to another artifact path', async () => {
const root = await artifactRoot();
await writeManifest(root, '.mcp.json', { status: claudeServer() });
Expand Down
Loading