This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
@codifycli/schemas is the central contract library for the Codify ecosystem. It defines:
- JSON Schemas for all IPC message formats between Codify CLI core and plugins
- TypeScript type definitions for type-safe message handling
- Configuration file schemas for Codify projects and resources
- Schema store integration for IDE autocomplete/validation
Codify is an infrastructure-as-code tool with a plugin-based architecture where the CLI core orchestrates resource management through plugins that communicate via IPC messages validated by this package.
npm test # Run all tests with vitestnpm run prepublishOnly # Compile TypeScript and prepare for publishing (runs `tsc`)npm run script:upload-plugin # Upload resource schemas to Supabase registryCodify uses a request/response IPC protocol where:
- Core CLI sends messages to plugins with commands like
initialize,validate,plan,apply,import - Plugins respond with structured data validated against response schemas
- Two message wrapper versions: V1 (basic) and V2 (adds
requestIdfor correlation)
src/
├── messages/ # Request/response schemas for each IPC message type
│ ├── *-request-data-schema.json
│ ├── *-response-data-schema.json
│ └── commands.ts # MessageCmd enum
├── types/ # TypeScript interfaces and enums
│ └── index.ts # All exported types
├── schemastore/ # IDE integration schema
│ └── codify-schema.json # Combined schema for autocomplete (2,462 lines)
├── config-file-schema.json # Top-level config file format
├── project-schema.json # "project" block definition
├── resource-schema.json # Base resource configuration
├── ipc-message-schema.json # V1 message wrapper
├── ipc-message-schema-v2.json # V2 message wrapper (adds requestId)
└── index.ts # Main exports
Configuration Schemas:
config-file-schema.json- Top-level array of config blocks withtypefieldproject-schema.json- Special "project" block with version, plugins, descriptionresource-schema.json- Base schema for all resources (type, name, dependsOn, os)
Message Schemas (src/messages/):
- Initialize: Plugin startup, capability discovery
- Validate: Resource configuration validation
- Plan: Calculate changes (create/destroy/modify/recreate/noop)
- Apply: Execute planned changes
- Import: Discover existing system resources
- Match: Find matching resource in array
- Get Resource Info: Query resource metadata
- Command Request/Response: Execute commands (sudo/interactive)
- Set Verbosity, Press Key to Continue, Error Response, Empty Response
Schema Store:
codify-schema.json- Comprehensive IDE integration schema combining all resource types
- Uses
resolveJsonModule: trueto import JSON schemas as typed modules - All JSON schemas are copied to
dist/during build - Types and schemas are co-located for easier maintenance
- Strict mode enabled with full null checking
- TypeScript compiles
src/→dist/ - JSON schemas copied to
dist/ - Type declarations (
.d.ts) generated - Source maps created
- Package published as ES modules
- Create schemas in
src/messages/:[name]-request-data-schema.json[name]-response-data-schema.json
- Add TypeScript types in
src/types/index.ts:[Name]RequestDatainterface[Name]ResponseDatainterface
- Update
MessageCmdenum if needed insrc/messages/commands.ts - Import and export schemas in
src/index.ts - Create test:
src/messages/[name]-request-data-schema.test.ts - Run tests and build
Each schema has a .test.ts file that:
- Uses AJV in strict mode to compile the schema
- Tests valid inputs return
true - Tests invalid inputs return
falsewith appropriate errors - Validates naming conventions and patterns
Configuration: Tests use tsconfig.test.json which disables strictNullChecks for testing flexibility.
Resource schemas are defined in src/schemastore/codify-schema.json and uploaded to Supabase registry via scripts/upload-resources.ts. This script:
- Upserts "default" plugin
- Extracts each resource from the schema store
- Upserts into
registry_resourcestable - Extracts parameters and upserts into
registry_resource_parameterstable
Requires environment variables: SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY
- Stateful: CLI tracks state, plugins receive both desired config and current state
- Stateless: Plugins determine current state themselves, receive only desired config
Resources declare dependencies via dependsOn array containing resource identifiers.
Resources specify OS compatibility:
ResourceOsenum: LINUX | MACOS | WINDOWSLinuxDistroenum: Comprehensive distro list (debian, ubuntu, fedora, arch, alpine, etc.)OSenum: Node.js platform values (Darwin | Linux | Windows_NT)
Parameters can be marked isSensitive: true for secure handling by the CLI.
Plans track changes at parameter level:
ParameterOperation: ADD | REMOVE | MODIFY | NOOP- Each parameter change includes old/new values
- Breaking Changes: This package is critical infrastructure - maintain backward compatibility
- Validation: All schemas must have corresponding tests
- Documentation: Include
$commentfields with documentation URLs in schemas - Version Patterns: Use semantic versioning regex:
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ - Type Patterns: Resource types use pattern
^[a-zA-Z][\w-]+$(alphanumeric start, then alphanumeric/underscore/hyphen)