Overview
index.ts acts as thin CLI wiring: it registers commands via api.registerCli and delegates to handlers. Business logic lives in src/handlers/ and src/lib/. The plugin exports __internal for test-only access to handlers and lib functions.
File structure
Handler-to-command map
| Handler | Commands |
|---|---|
| recipes | list, show, status, bind, unbind, bindings |
| scaffold | scaffold |
| team | scaffold-team, migrate-team, remove-team |
| tickets | tickets, move-ticket, assign, take, handoff, dispatch, complete |
| install | install-skill (ClawHub skills), install (marketplace recipe), install-recipe (alias) |
| cron | Reconciled during scaffold (no standalone command) |
Shared scaffold flow
Bothscaffold and scaffold-team use:
scaffoldAgentFromRecipe— creates workspace, writes recipe-managed files, applies agent configreconcileRecipeCronJobs— when a recipe declarescronJobs, installs/updates cron jobs percronInstallationconfig
cronJobs in frontmatter.
Data flow
Media Drivers Subsystem
ClawRecipes implements AI media generation through a driver-based architecture:Architecture
Components
- MediaDriver Interface: Standardized interface for all providers (slug, mediaType, requiredEnvVars, invoke)
- Registry System: Maps provider names to drivers, checks env var availability
- Skill Discovery: Searches
~/.openclaw/skills/,~/.openclaw/workspace/skills/, etc. - Generic Driver: Auto-creates drivers for any installed skill not explicitly registered
Integration Points
- Workflow Worker: Executes
media-image,media-video,media-audionodes via drivers - CLI Command:
workflows media-driverslists available providers (used by ClawKitchen UI) - Environment Loading: Merges
process.env+~/.openclaw/openclaw.jsonenv vars
Supported Providers
- Image: nano-banana-pro (Gemini), openai-image-gen (DALL-E)
- Video: klingai (Kling AI), runway-video (Runway), luma-video (Luma AI)
- Audio: Extensible via generic driver pattern
OutputFields and Schema Validation
LLM nodes support structured output generation with runtime validation:Configuration
Runtime Behavior
- Schema Generation: outputFields converted to JSON Schema with required fields
- LLM Invocation: Schema passed to
llm-tasktool for structured generation - Validation: Response validated against schema before saving
- Template Variables: Structured fields become available as
{{nodeId.fieldName}}
Field Types
- text: String values
- list: Arrays of strings
- json: Nested JSON objects
Implementation
- Code Location:
src/lib/workflows/workflow-worker.tsin LLM node execution - Variable Extraction: JSON fields automatically exposed as template variables
- Error Handling: Schema validation failures logged with detailed error messages
Key Decisions
- Tool policy preservation: When a recipe omits
tools, the scaffold preserves the existing agent’s tool policy (rather than resetting it). See scaffold logic and tests. __internalexport: Unit tests import handlers and lib helpers via__internal; these are not part of the public plugin API.- Media driver registry: Prefers explicitly registered drivers over auto-discovery for better performance and error messages.
- Schema validation: OutputFields generate strict JSON schemas to ensure predictable LLM outputs for downstream template usage.
Quality automation
- smell-check:
npm run smell-checkruns:- ESLint:
no-explicit-any,complexity,max-lines-per-function,max-params(src/; index.ts exempt from complexity/lines) - jscpd: Duplicate code detection (≥8 lines, ≥50 tokens)
- Pattern grep:
as anyin src/ (max 10), TODO/FIXME/XXX (max 20)
- ESLint:
- lint:
npm run lint/npm run lint:fix - tests:
npm test(vitest),npm run test:coverage - CI:
.github/workflows/ci.ymlruns test:coverage, smell-check, npm audit
If this doc is outdated, please submit a PR to update it.
