74 lines
2.0 KiB
Markdown
74 lines
2.0 KiB
Markdown
|
|
# Task ID: 93
|
||
|
|
|
||
|
|
**Title:** Implement mcpctl create stage Command
|
||
|
|
|
||
|
|
**Status:** cancelled
|
||
|
|
|
||
|
|
**Dependencies:** 71 ✓
|
||
|
|
|
||
|
|
**Priority:** medium
|
||
|
|
|
||
|
|
**Description:** Add CLI command to scaffold a new custom stage with boilerplate TypeScript code.
|
||
|
|
|
||
|
|
**Details:**
|
||
|
|
|
||
|
|
Create `src/cli/src/commands/create-stage.ts`:
|
||
|
|
|
||
|
|
```typescript
|
||
|
|
import { Command } from 'commander';
|
||
|
|
import { mkdir, writeFile, access } from 'fs/promises';
|
||
|
|
import { join } from 'path';
|
||
|
|
|
||
|
|
const STAGES_DIR = join(process.env.HOME ?? '', '.mcpctl', 'stages');
|
||
|
|
|
||
|
|
const STAGE_TEMPLATE = `import type { StageHandler } from 'mcpctl/proxymodel';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Custom stage: {{name}}
|
||
|
|
*
|
||
|
|
* Modify this handler to transform content as needed.
|
||
|
|
* Available in ctx:
|
||
|
|
* - ctx.llm.complete(prompt) - call the configured LLM
|
||
|
|
* - ctx.cache.getOrCompute(key, fn) - cache expensive computations
|
||
|
|
* - ctx.config - stage configuration from proxymodel YAML
|
||
|
|
* - ctx.originalContent - raw content before any stage processing
|
||
|
|
* - ctx.log - structured logging
|
||
|
|
*/
|
||
|
|
const handler: StageHandler = async (content, ctx) => {
|
||
|
|
// TODO: Implement your transformation
|
||
|
|
return { content };
|
||
|
|
};
|
||
|
|
|
||
|
|
export default handler;
|
||
|
|
`;
|
||
|
|
|
||
|
|
export function registerCreateStage(program: Command): void {
|
||
|
|
program
|
||
|
|
.command('create stage <name>')
|
||
|
|
.description('Create a new custom stage')
|
||
|
|
.action(async (name: string) => {
|
||
|
|
await mkdir(STAGES_DIR, { recursive: true });
|
||
|
|
|
||
|
|
const filePath = join(STAGES_DIR, `${name}.ts`);
|
||
|
|
|
||
|
|
try {
|
||
|
|
await access(filePath);
|
||
|
|
console.error(`Stage '${name}' already exists at ${filePath}`);
|
||
|
|
process.exit(1);
|
||
|
|
} catch {
|
||
|
|
// File doesn't exist, good
|
||
|
|
}
|
||
|
|
|
||
|
|
const code = STAGE_TEMPLATE.replace(/\{\{name\}\}/g, name);
|
||
|
|
await writeFile(filePath, code);
|
||
|
|
|
||
|
|
console.log(`Created ${filePath}`);
|
||
|
|
console.log('Edit the file to implement your stage logic.');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
**Test Strategy:**
|
||
|
|
|
||
|
|
CLI test: `mcpctl create stage my-filter` creates file at expected path with correct template. Test error when stage already exists. Verify generated code compiles.
|