/ src / commands / createMovedToPluginCommand.ts
createMovedToPluginCommand.ts
 1  import type { ContentBlockParam } from '@anthropic-ai/sdk/resources/messages.js'
 2  import type { Command } from '../commands.js'
 3  import type { ToolUseContext } from '../Tool.js'
 4  
 5  type Options = {
 6    name: string
 7    description: string
 8    progressMessage: string
 9    pluginName: string
10    pluginCommand: string
11    /**
12     * The prompt to use while the marketplace is private.
13     * External users will get this prompt. Once the marketplace is public,
14     * this parameter and the fallback logic can be removed.
15     */
16    getPromptWhileMarketplaceIsPrivate: (
17      args: string,
18      context: ToolUseContext,
19    ) => Promise<ContentBlockParam[]>
20  }
21  
22  export function createMovedToPluginCommand({
23    name,
24    description,
25    progressMessage,
26    pluginName,
27    pluginCommand,
28    getPromptWhileMarketplaceIsPrivate,
29  }: Options): Command {
30    return {
31      type: 'prompt',
32      name,
33      description,
34      progressMessage,
35      contentLength: 0, // Dynamic content
36      userFacingName() {
37        return name
38      },
39      source: 'builtin',
40      async getPromptForCommand(
41        args: string,
42        context: ToolUseContext,
43      ): Promise<ContentBlockParam[]> {
44        if (process.env.USER_TYPE === 'ant') {
45          return [
46            {
47              type: 'text',
48              text: `This command has been moved to a plugin. Tell the user:
49  
50  1. To install the plugin, run:
51     claude plugin install ${pluginName}@claude-code-marketplace
52  
53  2. After installation, use /${pluginName}:${pluginCommand} to run this command
54  
55  3. For more information, see: https://github.com/anthropics/claude-code-marketplace/blob/main/${pluginName}/README.md
56  
57  Do not attempt to run the command. Simply inform the user about the plugin installation.`,
58            },
59          ]
60        }
61  
62        return getPromptWhileMarketplaceIsPrivate(args, context)
63      },
64    }
65  }