malv generate
Run code generators to create TypeScript types from your JSON schema files. This keeps your type definitions in sync with your configuration.
Usage
# Run all generators
malv generate
# Run a specific generator
malv generate types
malv generate tokens
malv generate events
Generators
| Command | Source File | Output | Description |
|---|---|---|---|
all |
- | - | Run all generators (default) |
types |
tools.json |
Tool input/output types | Type definitions for tool parameters and returns |
tokens |
tokens.json |
TokenPayloads.ts |
Token payload interfaces |
events |
events.json |
EventHandlerTypes.ts |
Event handler type definitions |
env |
environment.json |
Environment.ts |
Environment variable types |
exports |
tools/objects | package.json exports |
Auto-generate package exports |
objects |
objects.json |
Object type definitions | Type definitions for objects |
tools |
src/tools/*.ts |
tools.json |
Generate tools.json from TypeScript |
icons |
objects.json |
Icon scaffolding | Create icon file stubs |
renders |
objects.json |
Renderer scaffolding | Create web renderer stubs |
When to Run
Run generators after modifying schema files:
| Changed File | Run |
|---|---|
tools.json or tool files |
malv generate types |
tokens.json |
malv generate tokens |
events.json |
malv generate events |
environment.json |
malv generate env |
objects.json |
malv generate objects |
Automatic Generation
The malv build command runs all generators automatically before bundling. You only need to run malv generate manually when:
- You want to regenerate types without a full build
- You're debugging generation issues
- You want to run a specific generator
Example: Types Generator
Given this tools.json:
{
"tools": [
{
"name": "create_note",
"input_schema": {
"type": "object",
"properties": {
"title": { "type": "string" },
"content": { "type": "string" }
},
"required": ["title"]
},
"output_schema": {
"type": "object",
"properties": {
"noteId": { "type": "string" },
"success": { "type": "boolean" }
}
}
}
]
}
Running malv generate types creates:
export interface CreateNoteInput {
title: string;
content?: string;
}
export interface CreateNoteOutput {
noteId?: string;
success?: boolean;
}
Example: Tokens Generator
Given this tokens.json:
{
"note_access": {
"state": "Note selected",
"schema": {
"properties": {
"noteId": { "type": "string" },
"permissions": { "type": "string" }
},
"required": ["noteId"]
}
}
}
Running malv generate tokens creates:
export interface NoteAccessPayload {
noteId: string;
permissions?: string;
}
export type TokenPayloads = {
note_access: NoteAccessPayload;
};
Example: Tools Generator
The tools generator works in reverse - it reads your TypeScript tool files and generates tools.json. This lets you define tools using TypeScript decorators or JSDoc comments:
// src/tools/create_note.ts
/**
* @tool create_note
* @description Creates a new note with the given title and content
* @capability storage
* @capability token
*/
export default async function create_note(
input: { title: string; content?: string },
capabilities: Capabilities
): Promise<{ noteId: string; success: boolean }> {
// ...
}
Running malv generate tools updates tools.json with the tool definition.
Output
$ malv generate
Running generators...
✓ types (3 tools)
✓ tokens (2 tokens)
✓ events (1 event)
✓ env (4 variables)
✓ exports
✓ objects (2 objects)
Generation complete.
Common Issues
JSON syntax errors
Error: Failed to parse tools.json
Check your JSON files for syntax errors. Use a JSON validator if needed.
Missing required fields
Error: Tool "my_tool" is missing required field "description"
Ensure all required fields are present in your schema files.
Type conflicts
If generated types conflict with existing code, check that your schema definitions match what your code expects.