or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-commands.mdconfiguration-api.mdindex.md
tile.json

configuration-api.mddocs/

Configuration API

Programmatic configuration functions and types for integrating czg with projects and customizing commit behavior.

Capabilities

Configuration Helper Functions

Functions that provide type safety and editor support for czg configuration.

/**
 * Helper function for type-safe configuration definition
 * @param config - Configuration object with czg/cz-git options
 * @returns The same configuration object with full type support
 */
function defineConfig<T extends UserConfig>(config: T): T;

/**
 * Helper function for type-safe prompt configuration definition
 * @param config - Prompt configuration object
 * @returns The same configuration object with full type support
 */
function definePrompt<T extends UserConfig>(config: T): T;

Usage Examples:

import { defineConfig } from "czg";

// Type-safe configuration with autocomplete and validation
export default defineConfig({
  types: [
    { value: "feat", name: "feat: ✨ A new feature", emoji: ":sparkles:" },
    { value: "fix", name: "fix: πŸ› A bug fix", emoji: ":bug:" },
    { value: "docs", name: "docs: πŸ“š Documentation changes", emoji: ":books:" },
    { value: "style", name: "style: πŸ’Ž Code style changes", emoji: ":gem:" },
    { value: "refactor", name: "refactor: πŸ“¦ Code refactoring", emoji: ":package:" },
    { value: "perf", name: "perf: πŸš€ Performance improvements", emoji: ":rocket:" },
    { value: "test", name: "test: 🚨 Testing", emoji: ":rotating_light:" },
    { value: "build", name: "build: πŸ› οΈ Build system changes", emoji: ":hammer_and_wrench:" },
    { value: "ci", name: "ci: βš™οΈ CI changes", emoji: ":gear:" },
    { value: "chore", name: "chore: ♻️ Other changes", emoji: ":recycle:" },
    { value: "revert", name: "revert: πŸ—‘οΈ Revert changes", emoji: ":wastebasket:" },
  ],
  scopes: ["api", "ui", "db", "auth", "config"],
  allowEmptyScopes: true,
  skipQuestions: ["body", "footer"],
  subjectMaxLength: 72,
  breaklineChar: "|",
  footerPrefix: "ISSUES CLOSED:",
  askForBreakingChangeFirst: true,
});
import { definePrompt } from "czg";

// Define custom prompts
export default definePrompt({
  messages: {
    type: "Select the type of change that you're committing:",
    scope: "What is the scope of this change (e.g. component or file name):",
    subject: "Write a short, imperative tense description of the change:",
    body: "Provide a longer description of the change:",
    breaking: "Are there any breaking changes?",
    footer: "List any ISSUES CLOSED by this change:",
    confirmCommit: "Are you sure you want to proceed with the commit above?",
  },
});

Configuration Types

Core Configuration Interface

The main configuration interface re-exported from cz-git.

interface UserConfig {
  /** Commit types configuration */
  types?: Array<{
    value: string;
    name: string;
    emoji?: string;
  }>;
  /** Available scopes for commits */
  scopes?: string[];
  /** Allow empty scopes */
  allowEmptyScopes?: boolean;
  /** Questions to skip in the prompt */
  skipQuestions?: string[];
  /** Maximum length for commit subject */
  subjectMaxLength?: number;
  /** Character for breaking lines in body */
  breaklineChar?: string;
  /** Prefix for footer */
  footerPrefix?: string;
  /** Ask for breaking changes first */
  askForBreakingChangeFirst?: boolean;
  /** Custom messages for prompts */
  messages?: {
    type?: string;
    scope?: string;
    subject?: string;
    body?: string;
    breaking?: string;
    footer?: string;
    confirmCommit?: string;
  };
  /** Enable emoji mode */
  useEmoji?: boolean;
  /** Enable AI mode */
  useAI?: boolean;
  /** AI configuration */
  aiOptions?: {
    model?: string;
    apiKey?: string;
    apiEndpoint?: string;
    apiProxy?: string;
  };
}

Commitizen Git Options

Configuration options for Commitizen integration.

interface CommitizenGitOptions {
  /** Path to configuration file */
  configPath?: string;
  /** Disable append paths */
  disableAppendPaths?: boolean;
  /** Emit data events */
  emitData?: boolean;
  /** Quiet mode */
  quiet?: boolean;
  /** Retry last commit */
  retryLastCommit?: boolean;
  /** Reback last commit */
  rebackLastCommit?: boolean;
  /** Hook mode */
  hookMode?: boolean;
  /** Environment variables */
  environment?: any;
  /** Git arguments */
  args?: string[];
}

CLI Argument Types

Parsed Arguments Structure

The structure returned by the argument parser.

interface CzgitParseArgs {
  czgitArgs: {
    flag: (CzgitCommonFlag & CzgitFlag & InitFlag) | null;
    subCommand: CzgitSubCommand | null;
  };
  gitArgs: string[];
}

Flag Definitions

Common flags available in the CLI.

interface CzgitCommonFlag {
  /** Show version information */
  version?: boolean;
  /** Show help information */
  help?: boolean;
  /** Disable AI mode for this session */
  ai?: boolean;
}

interface CzgitFlag {
  /** Path to configuration file */
  config?: string;
  /** Direct commit alias */
  alias?: string;
  /** OpenAI API key (deprecated, use api-key) */
  "openai-token"?: string;
  /** OpenAI API key */
  "api-key"?: string;
  /** AI model name */
  "ai-model"?: string;
  /** Number of AI suggestions to generate */
  "ai-num"?: string;
  /** API proxy URL */
  "api-proxy"?: string;
  /** API endpoint URL */
  "api-endpoint"?: string;
  /** Remove proxy configuration */
  "unset-proxy"?: boolean;
  /** Retry last commit attempt */
  retry?: boolean;
  /** Reback last commit (not implemented) */
  reback?: boolean;
  /** Enable hook mode for git hooks */
  hook?: boolean;
}

interface InitFlag {
  /** Automatic yes to prompts during initialization */
  yes?: boolean;
}

Subcommand Definitions

Available subcommands and their flags.

type CzgitSubCommandList = "init" | "emoji" | "ai" | "checkbox" | "break" | "gpg";

interface CzgitSubCommand {
  /** Initialize configuration */
  init?: boolean;
  /** Enable AI-powered commit messages */
  ai?: boolean;
  /** Enable emoji in commit messages */
  emoji?: boolean;
  /** Use checkbox for scope selection */
  checkbox?: boolean;
  /** Indicate breaking changes with ! */
  break?: boolean;
  /** Enable GPG signing */
  gpg?: boolean;
}

Flag List Type

Union type of all valid CLI flags.

type CzgitFlagList =
  | "config"
  | "version"
  | "help"
  | "reback"
  | "retry"
  | "yes"
  | "hook"
  | "alias"
  | "ai-num"
  | "ai-model"
  | "openai-token"
  | "api-key"
  | "api-model"
  | "api-endpoint"
  | "api-proxy"
  | "unset-proxy"
  | "ai";

Utility Functions

Environment Utilities

Functions for managing environment variables during execution.

/**
 * Inject boolean environment flag
 * @param key - Environment variable name
 * @param value - Boolean value to set
 */
function injectEnvFlag(key: string, value: boolean): void;

/**
 * Inject string environment value
 * @param key - Environment variable name  
 * @param value - String value to set
 */
function injectEnvValue(key: string, value: string): void;

Cache Utilities

Functions for managing commit cache for retry functionality.

/**
 * Read cached commit data synchronously
 * @param cachePath - Path to cache file
 * @param repoPath - Git repository path
 * @returns Cached commit data
 */
function getCacheValueSync(cachePath: string, repoPath: string): {
  options: any;
  template: string;
};

/**
 * Write commit data to cache synchronously
 * @param cachePath - Path to cache file
 * @param repoPath - Git repository path
 * @param data - Data to cache
 */
function writeCacheSync(
  cachePath: string,
  repoPath: string,
  data: { template: string; retryOptions: any }
): void;

Directory Utilities

/**
 * Ensure directory exists, creating it if necessary
 * @param dir - Directory path to ensure
 * @param callback - Completion callback
 */
function ensureDir(dir: string, callback: CallBackFn): void;

Configuration File Examples

Basic Configuration (.czrc)

{
  "types": [
    { "value": "feat", "name": "feat: A new feature" },
    { "value": "fix", "name": "fix: A bug fix" },
    { "value": "docs", "name": "docs: Documentation only changes" }
  ],
  "scopes": ["api", "ui", "db"],
  "allowEmptyScopes": true,
  "skipQuestions": ["body", "footer"],
  "subjectMaxLength": 72
}

Advanced Configuration (cz.config.js)

module.exports = {
  types: [
    { value: "feat", name: "feat: ✨ A new feature", emoji: ":sparkles:" },
    { value: "fix", name: "fix: πŸ› A bug fix", emoji: ":bug:" },
    { value: "docs", name: "docs: πŸ“š Documentation changes", emoji: ":books:" },
  ],
  scopes: ["frontend", "backend", "devops", "testing"],
  allowEmptyScopes: true,
  skipQuestions: ["body"],
  subjectMaxLength: 72,
  breaklineChar: "|",
  footerPrefix: "ISSUES CLOSED:",
  askForBreakingChangeFirst: true,
  useEmoji: true,
  useAI: true,
  aiOptions: {
    model: "gpt-4o-mini",
    apiEndpoint: "https://api.openai.com/v1",
  },
  messages: {
    type: "Select the type of change you're committing:",
    scope: "What is the scope of this change:",
    subject: "Write a short description of the change:",
    body: "Provide a longer description:",
    breaking: "Are there any breaking changes?",
    footer: "List any issues closed by this change:",
    confirmCommit: "Are you sure you want to proceed?",
  },
};

TypeScript Configuration (cz.config.ts)

import { defineConfig } from "czg";

export default defineConfig({
  types: [
    { value: "feat", name: "feat: ✨ A new feature" },
    { value: "fix", name: "fix: πŸ› A bug fix" },
    { value: "docs", name: "docs: πŸ“š Documentation" },
    { value: "style", name: "style: πŸ’Ž Code style" },
    { value: "refactor", name: "refactor: πŸ“¦ Refactoring" },
    { value: "perf", name: "perf: πŸš€ Performance" },
    { value: "test", name: "test: 🚨 Testing" },
    { value: "build", name: "build: πŸ› οΈ Build system" },
    { value: "ci", name: "ci: βš™οΈ CI changes" },
    { value: "chore", name: "chore: ♻️ Other changes" },
  ],
  scopes: ["core", "ui", "api", "docs", "build", "deps"],
  allowEmptyScopes: true,
  skipQuestions: ["body", "footer"],
  subjectMaxLength: 72,
  breaklineChar: "|",
  askForBreakingChangeFirst: true,
  useEmoji: true,
});