Welcome to the first chapter of our tutorial! We are going to build a feature called pr-comments. This tool helps fetch and summarize comments from GitHub Pull Requests using AI.
Before we write the logic to fetch data, we need a place to put that code. We need a "container" that allows our code to plug into the main application.
Imagine you have built a custom machine that reads comments. You want to ship this machine to a factory (the main application) so it can be used there.
If you build the machine directly into the factory's wall, it becomes hard to remove, upgrade, or move later. This is called tight coupling.
Instead, we use a Plugin Migration Wrapper. Think of this like a standard Shipping Container.
In our code, the function createMovedToPluginCommand is that shipping container. It wraps your specific logic so the main system can load it easily as a plugin.
To use this wrapper, we need to understand two simple parts:
createMovedToPluginCommand. It takes your settings and logic and bundles them up.
Let's look at index.ts. This file is the entry point for our plugin. We will break it down into small steps.
First, we need to import the tool that creates our wrapper.
// index.ts
import { createMovedToPluginCommand } from '../createMovedToPluginCommand.js'
Explanation: We are grabbing the "shipping container builder" from our tools folder.
Next, we export the result of calling this function.
export default createMovedToPluginCommand({
// We will fill this with settings in the next steps
name: 'pr-comments',
description: 'Get comments from a GitHub pull request',
// ... more settings
})
Explanation:
export default: We are sending this package out to the main system.createMovedToPluginCommand({...}): We are creating the container.{}, we define our plugin.Inside the wrapper, we provide labels so the system knows what this plugin does.
// Inside the object...
progressMessage: 'fetching PR comments',
pluginName: 'pr-comments',
pluginCommand: 'pr-comments',
Explanation:
Finally, we put the actual "machine" inside the container. This function runs when the user types the command.
async getPromptWhileMarketplaceIsPrivate(args) {
return [
{
type: 'text',
text: `You are an AI assistant... (logic continues)`
},
]
},
Explanation:
getPromptWhileMarketplaceIsPrivate: This is a specific spot in the wrapper where we define our behavior.What actually happens when the application runs your code? Let's visualize the flow.
index.ts and sees the Wrapper.pr-comments) with the system.pr-comments, the Wrapper executes our logic.Here is a simplified view of the interaction:
The createMovedToPluginCommand helper abstracts away complex system requirements.
Instead of writing:
The wrapper says: "Just give me an object with a name and a getPrompt... function, and I will handle the rest."
This architecture allows us to focus entirely on fetching GitHub data (which we will learn in GitHub Data Retrieval Strategy) and formatting it (covered in Output Formatting Specification), without worrying about how the CLI application works internally.
In this chapter, we learned that the Plugin Migration Wrapper is a utility that allows us to package our code modularly. It decouples our logic from the main system, making our feature portable and easy to manage.
Now that we have our container ready, we need to label it correctly.
Next Chapter: Command Configuration
Generated by Code IQ