or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Git Commit Message Helper with Hook Integration

Overview

Build a command-line tool that integrates with Git's prepare-commit-msg hook to help generate standardized commit messages interactively. The tool should write the commit message to the appropriate file location so Git can use it during the commit process.

Requirements

Core Functionality

  1. Hook Integration Mode

    • The tool must support running in Git hook integration mode via a --hook command-line flag
    • In hook mode, write the commit message to .git/COMMIT_EDITMSG instead of executing a commit
    • In normal mode (without --hook), create the commit directly
  2. Interactive Message Builder

    • Provide an interactive prompt-based interface to build commit messages
    • Support selecting commit type from a list (e.g., feat, fix, docs, style, refactor, test, chore)
    • Support optionally entering a scope
    • Support entering a subject line
    • Output messages in Conventional Commits format: <type>(<scope>): <subject>
  3. Configuration Loading

    • Read configuration from a .czrc file in the current directory if it exists
    • Support customizing the list of available commit types via config
    • Support customizing the list of available scopes via config
    • Use sensible defaults when no configuration file is present

Implementation

  • Build as a Node.js CLI tool
  • Name the main executable commit-helper
  • Ensure proper error handling for Git operations

Test Cases

Test 1: Hook Mode Writes to File { @test }

Setup:

git init test-repo
cd test-repo
echo "test" > test.txt
git add test.txt

Test file: test.test.js

Scenario: Run the tool with --hook flag and verify it writes to .git/COMMIT_EDITMSG

Expected behavior:

  • The tool should not execute git commit
  • The file .git/COMMIT_EDITMSG should be created
  • The file should contain a properly formatted commit message

Test 2: Normal Mode Executes Commit { @test }

Setup:

git init test-repo
cd test-repo
echo "test" > test.txt
git add test.txt

Test file: test.test.js

Scenario: Run the tool without --hook flag

Expected behavior:

  • The tool should execute git commit -m "<message>"
  • A new commit should be created in the repository
  • The commit message should follow Conventional Commits format

Test 3: Configuration from .czrc { @test }

Setup:

git init test-repo
cd test-repo
cat > .czrc << 'EOF'
{
  "types": [
    {"value": "feature", "name": "feature: A new feature"},
    {"value": "bugfix", "name": "bugfix: A bug fix"}
  ],
  "scopes": ["api", "ui", "database"]
}
EOF
echo "test" > test.txt
git add test.txt

Test file: test.test.js

Scenario: Run the tool and verify it uses custom types and scopes from .czrc

Expected behavior:

  • The tool should offer "feature" and "bugfix" as commit types
  • The tool should offer "api", "ui", and "database" as scopes
  • Generated commit messages should use the custom types

Dependencies { .dependencies }

czg { .dependency }

Provides Git commit message generation with hook integration support.

Success Criteria

  • The tool correctly writes to .git/COMMIT_EDITMSG when --hook flag is provided
  • The tool executes git commit when --hook flag is not provided
  • Configuration is properly loaded from .czrc
  • All commit messages follow Conventional Commits format
  • All three test cases pass