Generator API

How the code generation system works.

The generator transforms an AgentConfig into a complete TypeScript project. This reference documents the generation process and output structure.

Generation Process

1. Configuration Validation

The generator validates the configuration before generating:

  • Required fields are present
  • SDK provider is valid
  • Tool configurations are consistent
  • MCP server configurations are valid

2. Dependency Resolution

Based on enabled tools and features, the generator determines required npm dependencies:

1// Base dependencies (always included)
2const baseDeps = {
3  'commander': '^11.1.0',
4  'chalk': '^5.3.0',
5  'ora': '^8.0.1',
6  'inquirer': '^9.2.12',
7  'dotenv': '^16.3.1'
8};
9
10// SDK-specific dependencies
11const sdkDeps = {
12  claude: { '@anthropic-ai/claude-code': '^0.1.53' },
13  openai: { '@openai/agents': '^0.1.0', 'zod': '^3.0.0' }
14};
15
16// Tool-specific dependencies
17const toolDeps = {
18  'find-files': { 'glob': '^10.3.10' },
19  'web-fetch': { 'axios': '^1.6.0', 'cheerio': '^1.0.0' },
20  'database-query': { 'better-sqlite3': '^9.0.0' },
21  'doc-ingest': { 'pdf-parse': '^1.1.1', 'mammoth': '^1.6.0' }
22};

3. File Generation

The generator creates files based on the configuration:

Core Files

  • package.json - With resolved dependencies
  • tsconfig.json - TypeScript configuration
  • src/cli.ts - CLI entry point
  • src/agent.ts - Agent implementation
  • src/config.ts - Configuration management
  • src/permissions.ts - Permission system

Conditional Files

  • src/mcp-config.ts - If MCP servers configured
  • src/planner.ts - If planning mode enabled
  • src/workflows.ts - If workflows configured

Lever Files

  • CLAUDE.md - If memory enabled
  • .claude/commands/*.md - For each slash command
  • .claude/skills/*/SKILL.md - For each skill
  • .claude/agents/*.md - For each subagent
  • .claude/settings.json - If hooks configured

Domain Workflows

Based on domain, the generator includes relevant workflow files:

1const domainWorkflows = {
2  development: ['code-audit', 'test-suite', 'refactor-analysis'],
3  business: ['invoice-batch', 'contract-review', 'meeting-summary'],
4  creative: ['content-calendar', 'blog-outline', 'campaign-brief'],
5  data: ['dataset-profile', 'chart-report'],
6  knowledge: ['literature-review', 'experiment-log']
7};

Generated Project Structure

1{projectName}/
2├── package.json
3├── tsconfig.json
4├── src/
5│   ├── cli.ts
6│   ├── agent.ts
7│   ├── config.ts
8│   ├── permissions.ts
9│   ├── mcp-config.ts
10│   ├── planner.ts
11│   └── workflows.ts
12├── .claude/
13│   ├── CLAUDE.md
14│   ├── commands/
15│   ├── agents/
16│   ├── skills/
17│   └── settings.json
18├── .commands/
19├── .plans/
20├── .mcp.json
21├── .env.example
22├── .gitignore
23├── README.md
24├── LICENSE
25└── scripts/
26    └── publish.sh

Output Format

GeneratedProject Type

1interface GeneratedProject {
2  files: GeneratedFile[];
3  metadata: ProjectMetadata;
4  config: AgentConfig;
5}
6
7interface GeneratedFile {
8  path: string;
9  content: string;
10  type: FileType;
11  template?: string;
12}
13
14type FileType =
15  | 'source'
16  | 'config'
17  | 'documentation'
18  | 'workflow'
19  | 'lever';
20
21interface ProjectMetadata {
22  dependencies: Record<string, string>;
23  devDependencies: Record<string, string>;
24  scripts: Record<string, string>;
25  buildInstructions: string[];
26  deploymentOptions: string[];
27}

Tool Generation

Each enabled tool generates corresponding implementation code:

1// Example: read-file tool generation
2const readFileTool = {
3  name: 'read-file',
4  description: 'Read the contents of a file',
5  parameters: {
6    type: 'object',
7    properties: {
8      path: {
9        type: 'string',
10        description: 'Path to the file to read'
11      }
12    },
13    required: ['path']
14  },
15  execute: async ({ path }) => {
16    const content = await fs.readFile(path, 'utf-8');
17    return { content };
18  }
19};

Customization Points

Extending the generator

The generated code is designed for customization. Key extension points:

  • Add tools in src/agent.ts
  • Modify permissions in src/permissions.ts
  • Add CLI commands in src/cli.ts
  • Extend workflows in .commands/

Build Scripts

1{
2  "scripts": {
3    "build": "tsc",
4    "dev": "tsc --watch",
5    "start": "node dist/cli.js",
6    "test": "node dist/cli.js --help"
7  }
8}