or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ai-integration.mdconfiguration-loading.mdconfiguration.mdenhanced-prompts.mdindex.mdmessage-generation.mdprompter.mdtypes.md
tile.json

message-generation.mddocs/

Message Generation

Functions for generating and formatting commit messages according to Conventional Commits specification.

Capabilities

Message Generation

Core function for generating formatted commit messages from user answers and configuration.

/**
 * Generate a formatted commit message from answers and configuration
 * @param answers - User responses from interactive prompts
 * @param options - Configuration options affecting message format
 * @param colorize - Whether to apply color formatting for display
 * @returns Formatted commit message string
 */
function generateMessage(
  answers: Answers,
  options: CommitizenGitOptions,
  colorize?: boolean
): string;

Usage Examples:

import { generateMessage } from "cz-git";

const answers = {
  type: 'feat',
  scope: 'auth',
  subject: 'add OAuth2 integration',
  body: 'Implements OAuth2 authentication flow|Supports Google and GitHub providers',
  breaking: 'Changes authentication API interface',
  footer: 'Closes #123, #456'
};

const options = {
  useEmoji: true,
  emojiAlign: 'center',
  breaklineChar: '|',
  formatMessageCB: undefined
};

// Generate the commit message
const message = generateMessage(answers, options);
// Result: "feat(auth): ✨ add OAuth2 integration\n\nImplements OAuth2 authentication flow\nSupports Google and GitHub providers\n\nBREAKING CHANGE: Changes authentication API interface\n\nCloses #123, #456"

// Generate with colorization for preview
const colorizedMessage = generateMessage(answers, options, true);

Alias Message Generation

Generate commit messages from predefined aliases for quick commits.

/**
 * Generate commit message from a predefined alias
 * @param options - Configuration options containing alias definitions
 * @param alias - Alias key to use for message generation
 * @returns Formatted commit message from alias
 */
function getAliasMessage(
  options: CommitizenGitOptions,
  alias: string
): string;

Usage Examples:

import { getAliasMessage } from "cz-git";

const options = {
  alias: {
    fd: 'docs: fix typos',
    wip: 'feat: work in progress',
    bump: 'chore: bump version'
  }
};

// Generate message from alias
const message = getAliasMessage(options, 'fd');
// Result: "docs: fix typos"

// Use in command line: cz_alias=fd cz

Message Parts Interface

Interface representing the subdivided parts of a commit message for advanced formatting.

interface CommitMessageOptions {
  /** Commit type (e.g., 'feat', 'fix') */
  type: string;
  
  /** Scope of the change */
  scope: string;
  
  /** Emoji code if useEmoji is enabled */
  emoji: string;
  
  /** Breaking change indicator ('!' or '') */
  markBreaking: string;
  
  /** Subject description */
  subject: string;
  
  /** Formatted header following Conventional Commits */
  defaultHeader: string;
  
  /** Body content with line breaks processed */
  body: string;
  
  /** Breaking changes description */
  breaking: string;
  
  /** Footer content (issues, references, etc.) */
  footer: string;
  
  /** Complete formatted message */
  defaultMessage: string;
}

Custom Message Formatting

Callback function interface for customizing the final message format.

/**
 * Custom message formatting callback
 * @param messageMod - Object containing all message parts
 * @returns Custom formatted commit message
 */
type FormatMessageCallback = (messageMod: CommitMessageOptions) => string;

Usage Examples:

import { definePrompt } from "cz-git";

export default definePrompt({
  formatMessageCB: ({ defaultMessage, type, scope, subject }) => {
    // Custom format with timestamp
    const timestamp = new Date().toISOString().slice(0, 10);
    return `[${timestamp}] ${type}${scope ? `(${scope})` : ''}: ${subject}`;
  }
});

// Alternative: Add prefixes or modify structure
export default definePrompt({
  formatMessageCB: ({ defaultHeader, body, footer }) => {
    let message = `πŸš€ ${defaultHeader}`;
    if (body) message += `\n\nπŸ“ ${body}`;
    if (footer) message += `\n\nπŸ”— ${footer}`;
    return message;
  }
});

Message Processing Utilities

Internal utilities for processing different parts of the commit message.

/**
 * Process and transform subject text
 * @param text - Raw subject input
 * @returns Cleaned subject text with trimmed whitespace
 */
function getProcessSubject(text: string): string;

/**
 * Transform subject case according to configuration
 * @param options - Configuration containing case preferences
 * @param subject - Subject text to transform
 * @returns Subject with applied case transformation
 */
function transformSubjectCase(
  options: CommitizenGitOptions, 
  subject: string
): string;

/**
 * Calculate maximum allowed subject length based on constraints
 * @param type - Commit type
 * @param scope - Commit scope
 * @param options - Configuration with length limits
 * @returns Maximum subject length considering header constraints
 */
function getMaxSubjectLength(
  type: Answers['type'],
  scope: Answers['scope'] | Answers['customScope'],
  options: CommitizenGitOptions
): number;

Message Preview

Function for displaying formatted commit message previews during confirmation.

/**
 * Display a formatted preview of the commit message
 * @param msg - Complete commit message to preview
 * @param confirmColorize - Whether to apply color formatting
 */
function previewMessage(msg: string, confirmColorize?: boolean): void;

Usage Examples:

import { previewMessage, generateMessage } from "cz-git";

const message = generateMessage(answers, options);

// Show preview with colors
previewMessage(message, true);

// Show plain preview
previewMessage(message, false);

Line Break Processing

The message generation system automatically processes line breaks using the configured breaklineChar (default: |):

  • Body: Converts | characters to actual line breaks
  • Breaking Changes: Converts | characters to actual line breaks
  • Line Length: Wraps long lines according to breaklineNumber setting

Examples:

// Input with line break characters
const answers = {
  body: 'First line|Second line|Third line',
  breaking: 'API change|Removes deprecated methods'
};

// Generated output includes actual line breaks:
// First line
// Second line  
// Third line
//
// BREAKING CHANGE: API change
// Removes deprecated methods

The message generation follows the Conventional Commits specification exactly, ensuring compatibility with automated tools and consistent formatting across projects.