fix: positional arguments for MCP prompts (#8034)

This commit is contained in:
Luke Schlangen
2025-09-15 10:13:21 -05:00
committed by GitHub
parent 7470133a13
commit 5cbab75c7d
4 changed files with 368 additions and 18 deletions

View File

@@ -549,7 +549,13 @@ describe('useSlashCompletion', () => {
await waitFor(() => {
expect(mockCompletionFn).toHaveBeenCalledWith(
mockCommandContext,
expect.objectContaining({
invocation: {
raw: '/chat resume my-ch',
name: 'resume',
args: 'my-ch',
},
}),
'my-ch',
);
});
@@ -591,7 +597,16 @@ describe('useSlashCompletion', () => {
);
await waitFor(() => {
expect(mockCompletionFn).toHaveBeenCalledWith(mockCommandContext, '');
expect(mockCompletionFn).toHaveBeenCalledWith(
expect.objectContaining({
invocation: {
raw: '/chat resume',
name: 'resume',
args: '',
},
}),
'',
);
});
await waitFor(() => {

View File

@@ -7,7 +7,11 @@
import { useState, useEffect, useMemo } from 'react';
import { AsyncFzf } from 'fzf';
import type { Suggestion } from '../components/SuggestionsDisplay.js';
import type { CommandContext, SlashCommand } from '../commands/types.js';
import {
CommandKind,
type CommandContext,
type SlashCommand,
} from '../commands/types.js';
// Type alias for improved type safety based on actual fzf result structure
type FzfCommandResult = {
@@ -93,9 +97,13 @@ function useCommandParser(
const found: SlashCommand | undefined = currentLevel.find((cmd) =>
matchesCommand(cmd, part),
);
if (found) {
leafCommand = found;
currentLevel = found.subCommands as readonly SlashCommand[] | undefined;
if (found.kind === CommandKind.MCP_PROMPT) {
break;
}
} else {
leafCommand = null;
currentLevel = [];
@@ -194,7 +202,17 @@ function useCommandSuggestions(
const depth = commandPathParts.length;
const argString = rawParts.slice(depth).join(' ');
const results =
(await leafCommand.completion(commandContext, argString)) || [];
(await leafCommand.completion(
{
...commandContext,
invocation: {
raw: `/${rawParts.join(' ')}`,
name: leafCommand.name,
args: argString,
},
},
argString,
)) || [];
if (!signal.aborted) {
const finalSuggestions = results.map((s) => ({