Automation & Workflows
Build repeatable workflows with routines, macros, and scripts to automate common development tasks
The Automation Stack
CodeMap provides four complementary automation tools:
- Templates: Reusable code scaffolds for consistent file creation
- Macros: Quick shell command shortcuts
- Scripts: Custom JavaScript automation for complex tasks
- Routines: Multi-step workflows combining tools, scripts, and checklists
Each layer builds on the previous, creating a flexible automation framework.
Level 0: Templates
Templates are reusable code scaffolds that help maintain consistency across your codebase. Save common file patterns (React components, API routes, test files) and deploy them instantly with proper naming and structure.
Common Use Cases
- Component boilerplate (React, Vue, Angular)
- API endpoint templates with standard error handling
- Test file scaffolds with common setup/teardown
- Configuration file templates
Example: React Component Template
import React from 'react';\n\nexport interface {{ComponentName}}Props {\n // Add props here\n}\n\nexport const {{ComponentName}}: React.FC<{{ComponentName}}Props> = (props) => {\n return (\n \n {/* Component content */}\n \n );\n};Deploy with template-deploy to create files with proper naming conventions automatically applied.
Level 1: Macros
Macros are named shortcuts for frequently-used shell commands. Use for wrapping long commands, standardizing build/test commands, and avoiding typos in critical commands.
Common Patterns
Create macros for build commands, test suites, linting, and deployment scripts. Keep each macro focused on a single command.
Level 2: Scripts
Scripts are JavaScript files with access to the full CodeMap API. They're organized into categories: audit, build, orient, close, and utility.
Example: Circular Dependency Check
// Check for circular dependencies\nmodule.exports = async (context) => {\n const { graph } = context\n const cycles = graph.findCycles()\n \n if (cycles.length > 0) {\n console.error(`Found ${cycles.length} circular dependencies`)\n return { success: false, cycles }\n }\n \n return { success: true }\n}Level 3: Routines
Routines combine scripts, macros, checklists, templates, and file references into multi-step workflows. Perfect for pre-deploy checks, PR reviews, release preparations, and onboarding processes.
Real-World Example: Pre-Deploy Workflow
A comprehensive pre-deploy routine might include:
- Checklist item: "All tests passing"
- Run audit script: check for circular dependencies
- Execute macro: run full test suite
- Execute macro: build production bundle
- Checklist item: "Deployment notes updated"
Built-In Session Workflows
CodeMap has two built-in routine-like workflows:
Session Start
- Orient to the project
- Check for premature termination
- Display session checklist
- Load project memory
Session Close
- Run audit scripts
- Verify code compiles
- Create session summary
- Write handoff notes
# Create a macro
codemap macro-create "test" "npm test"
# Create a script
codemap script-create audit "check-imports"
# Create a routine
codemap routine-create "pre-deploy"# Build a complete routine
codemap routine-create "pr-review"
codemap routine-add-item "pr-review" "Code compiles without warnings"
codemap routine-add-item "pr-review" "All tests pass"
codemap routine-add-script "pr-review" audit check-console-logs
codemap routine-add-macro "pr-review" lint
# Run the routine
codemap routine-run "pr-review"Version 0.3.x will introduce powerful template automation: feed templates with JSON, CSV, or XML files to generate multiple files at once. Routines will become fully automation-oriented with "fire once and done" workflows, massively reducing manual work for both AI agents and developers.
Begin with macros for single commands. When you need conditional logic or graph access, upgrade to scripts. When workflows span multiple tools, create routines.
All automation (macros, scripts, routines) is stored in .codemap/. Commit this directory to version control so your entire team benefits from shared workflows.
Always return { success: boolean, ...data } from scripts. This allows routines to handle failures gracefully and display meaningful results to users.
Routines execute in the order you add items. Run critical checks first to fail fast and save time. For example, run compilation checks before running slow test suites.