Merges feat/agent-project-membership (task 166/152). An agent can finally join many projects: membership routes, per-membership role and optional brain override, chat resolving context from the membership, and CLI attach-agent / detach-agent / get memberships. The legacy Agent.projectId fallback is kept for this release as the schema comment promises. Conflict resolved in main.ts: that branch added its RBAC case to mapUrlToPermission inline, while this branch had extracted the function to middleware/url-permission.ts so it could be tested. Kept the extraction and ported the case into it — joining a team is `edit:agents:<name>`, not `create:agents`, which is the authority to mint a whole agent. Also fixes something the extraction makes possible. security.test.ts contained a hand-copied reproduction of mapUrlToPermission, because main.ts self-invokes main() and nothing in it was importable. A security test asserting against a copy stops testing the system the moment the real one changes, and this copy had already drifted. It now imports the real function; all 18 assertions still pass, against the code that actually runs. Local: build clean, workspace 2550 passed, lint unchanged at 794 errors. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N4wNHWf7xSwnZCWpJcyv9p
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.
|