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/fix-web-launch-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agent-bundle": patch
---

Normalize `<plugin> web` and `/web` portable-plus-host launch identity to avoid false AB8023 conflicts (#633)
22 changes: 19 additions & 3 deletions packages/agent-bundle/src/dev/web-host-launch-selection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFile } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { isAbsolute, join, resolve } from 'node:path';

import type { TargetRegistry } from '../adapters/registry.ts';
import { digest } from '../core/digest.ts';
import { CodedError } from '../core/errors.ts';
import { assertInside, joinArtifact } from '../core/paths.ts';
import { assertInside, isInsideOrEqual, joinArtifact } from '../core/paths.ts';
import { parseJsonWithoutDuplicateKeys } from '../core/strict-json.ts';
import { resolveMcpPathTokens } from '../services/mcp-path-tokens.ts';
import {
Expand Down Expand Up @@ -64,6 +64,22 @@ interface LaunchCandidate {
readonly target: string;
}

const normalizedStdioArgument = (
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;
};

/**
* The normalized-launch runtime view of one projection: env values pass
* through the target's stdio-argument rule after token resolution, exactly
Expand Down Expand Up @@ -122,7 +138,7 @@ const launchIdentityOf = async (
? artifactRoot
: assertInside(artifactRoot, resolve(artifactRoot, resolved.cwd));
return digest({
args: resolved.args,
args: resolved.args.map((argument) => normalizedStdioArgument(argument, artifactRoot, cwd)),
command: resolved.command,
cwd,
env: resolved.env ?? {},
Expand Down
28 changes: 28 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 @@ -46,6 +46,15 @@ const portableServer = (overrides: Readonly<Record<string, unknown>> = {}): Read
...overrides,
});

const emittedPortableServer = (overrides: Readonly<Record<string, unknown>> = {}): Readonly<Record<string, unknown>> => ({
args: ['mcp/mcp-status.mjs'],
command: 'node',
cwd: '${PLUGIN_ROOT}',
env: { AGENT_BUNDLE_PLUGIN_ROOT: '${PLUGIN_ROOT}' },
type: 'stdio',
...overrides,
});

const codexServer = (overrides: Readonly<Record<string, unknown>> = {}): Readonly<Record<string, unknown>> => ({
args: ['./mcp/mcp-status.mjs'],
command: 'node',
Expand Down Expand Up @@ -97,6 +106,25 @@ describe('selectWebLaunch', () => {
expect(selection.sharedTargets).toEqual(['claude', 'portable']);
});

it('normalizes the emitted portable cwd-relative entry to the host artifact entry', async () => {
const root = await artifactRoot();
await writeManifest(root, '.mcp.json', { status: claudeServer() });
await writeManifest(root, 'mcp.json', { status: emittedPortableServer() });
const selection = await select(root, { declaredTargets: ['claude', 'portable'] });
expect(selection.target).toBe('claude');
expect(selection.sharedTargets).toEqual(['claude', 'portable']);
});

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() });
await writeManifest(root, 'mcp.json', {
status: emittedPortableServer({ args: ['mcp/mcp-other.mjs'] }),
});
const error = await failure(root, { declaredTargets: ['claude', 'portable'] });
expect(error.code).toBe('launch-ambiguous');
});

it('selects identically when the hosts are declared in reversed order', async () => {
const root = await artifactRoot();
await writeManifest(root, '.mcp.json', { status: claudeServer() });
Expand Down
Loading