fix(generate-cli): restore stdio fallback

This commit is contained in:
Peter Steinberger 2025-11-18 04:44:10 +00:00
parent 9d37fb18cc
commit 375f85af63
4 changed files with 55 additions and 4 deletions

View File

@ -183,7 +183,7 @@ function normalizeCommandInput(value: string): CommandInput {
if (looksLikeInlineCommand(value)) {
return parseInlineCommand(value);
}
return value;
return { command: value };
}
function looksLikeInlineCommand(value: string): boolean {

View File

@ -79,17 +79,23 @@ function defaultVscodeConfigPaths(): string[] {
function opencodeConfigPaths(rootDir: string): string[] {
const overrideConfig = process.env.OPENCODE_CONFIG;
const overrideDir = process.env.OPENCODE_CONFIG_DIR;
const envConfigPath = process.env.OPENAI_WORKDIR;
const xdg = process.env.XDG_CONFIG_HOME;
const configHome = xdg ?? path.join(process.env.HOME ?? '', '.config');
const paths = [
const paths: string[] = [
overrideConfig ?? '',
path.resolve(rootDir, 'opencode.jsonc'),
path.resolve(rootDir, 'opencode.json'),
];
if (overrideDir && overrideDir.length > 0) {
paths.push(path.join(overrideDir, 'opencode.jsonc'), path.join(overrideDir, 'opencode.json'));
}
paths.push(
path.resolve(rootDir, '.openai', 'config.json'),
envConfigPath ? path.resolve(envConfigPath, '.openai', 'config.json') : '',
path.join(configHome, 'openai', 'config.json'),
];
path.join(configHome, 'openai', 'config.json')
);
for (const dir of defaultOpencodeConfigDirs()) {
paths.push(path.join(dir, 'opencode.jsonc'), path.join(dir, 'opencode.json'));
}

View File

@ -80,6 +80,16 @@ describe('generate-cli runner internals', () => {
expect(inferred).toBe('shadcn');
});
it('wraps single-token stdio commands when passed via --command', () => {
const args = ['--command', './scripts/mcp-server.ts'];
const parsed = parseGenerateFlags([...args]);
expect(parsed.command).toBeDefined();
const spec = parsed.command as { command: string; args?: string[] };
expect(spec).toEqual({ command: './scripts/mcp-server.ts' });
const inferred = parsed.command !== undefined ? inferNameFromCommand(parsed.command) : undefined;
expect(inferred).toBe('mcp-server');
});
it('treats positional inline commands as generate-cli targets', () => {
const args = ['npx -y chrome-devtools-mcp@latest'];
const parsed = parseGenerateFlags([...args]);

View File

@ -379,4 +379,39 @@ describe('config imports', () => {
fs.rmSync(tempRoot, { recursive: true, force: true });
}
});
it('honors the OPENCODE_CONFIG_DIR override', async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mcporter-opencode-dir-'));
const dirConfigPath = path.join(tempDir, 'opencode.jsonc');
fs.mkdirSync(tempDir, { recursive: true });
fs.writeFileSync(
dirConfigPath,
JSON.stringify(
{
mcp: {
'opencode-dir-only': {
command: 'dir-cli',
args: ['--stdio'],
},
},
},
null,
2
)
);
process.env.OPENCODE_CONFIG_DIR = tempDir;
try {
const servers = await loadServerDefinitions({ rootDir: FIXTURE_ROOT });
const dirServer = servers.find((server) => server.name === 'opencode-dir-only');
expect(dirServer).toBeDefined();
expect(dirServer?.source).toEqual({
kind: 'import',
path: dirConfigPath,
importKind: 'opencode',
});
} finally {
process.env.OPENCODE_CONFIG_DIR = undefined;
fs.rmSync(tempDir, { recursive: true, force: true });
}
});
});