Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cursorrules.md
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,22 @@ jobs:
run: |
NODE_VERSION=$(node --version | cut -d. -f1 | tr -d v)
echo "Testing development mode for Node.js $NODE_VERSION"
# Node.js 21+: Use tsx (dev)
# Node.js 19-20: Use tsx (dev:node20)
# Node.js 18: Use ts-node with CommonJS (dev:node18)
# <18: Use ts-node with CommonJS (dev:compat)

if [ "$NODE_VERSION" -eq 22 ]; then
echo "Testing with npm run dev"
if [ "$NODE_VERSION" -ge 21 ]; then
echo "Testing with npm run dev (tsx)"
npm run dev -- --version
elif [ "$NODE_VERSION" -eq 20 ]; then
echo "Testing with npm run dev:node20"
elif [ "$NODE_VERSION" -le 20 ] && [ "$NODE_VERSION" -gt 18 ]; then
echo "Testing with npm run dev:node20 (tsx)"
npm run dev:node20 -- --version
elif [ "$NODE_VERSION" -eq 18 ]; then
echo "Testing with npm run dev:node18"
echo "Testing with npm run dev:node18 (ts-node)"
npm run dev:node18 -- --version
else
echo "Testing with npm run dev:compat"
echo "Testing with npm run dev:compat (ts-node)"
npm run dev:compat -- --version
fi
continue-on-error: true
118 changes: 118 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Repository Overview

This is a TypeScript project that implements a Git commit-msg hook tool, similar to Gerrit's commit-msg hook. The tool automatically generates and adds unique Change-Ids to Git commit messages.

The project follows a simplified single-package structure:

- Contains all the functionality including the command-line interface, user-facing commands, and core logic for commit message processing and hook functionality

## Common Commands

### Development

- `npm run dev -- <command>` - Run the CLI tool directly with ts-node for development (uses NODE_OPTIONS=--no-warnings to suppress experimental warnings)
- `npm run build` - Build the CLI package
- `npm test` - Run tests with Vitest

### Code Quality

- `npx eslint src/ test/` - Lint TypeScript files
- `npx prettier --check src/ test/` - Check code formatting
- `npx prettier --write src/ test/` - Format code

### Package Management

- `npm install` - Install dependencies and automatically build the project
- `npm run build` - Build the CLI package

## Code Architecture

### Project Structure

```
commit-msg/
├── src/ # Source code
│ ├── bin/ # Entry point scripts
│ ├── commands/ # Command implementations
│ ├── services/ # Business logic services
│ └── utils/ # Utility functions
├── dist/ # Compiled output
├── scripts/ # Build and utility scripts
├── templates/ # Template files
└── test/ # Test files
```

### Key Components

1. **CLI Entry Point** (`src/bin/commit-msg.ts`):
- Uses Commander.js for command-line argument parsing
- Implements two main commands: `install` and `exec`

2. **Commands** (`src/commands/`):
- `install.ts`: Installs the commit-msg hook in a Git repository
- `exec.ts`: Executes the commit-msg hook logic on a commit message file

3. **Core Interfaces**:
- Contains interfaces for commit message processing and hook functionality
- Defined in `src/index.ts`

### Build Process

The project uses a custom build script that handles TypeScript compilation, template copying, and setting executable permissions:

1. Compiles TypeScript code from `src/` to `dist/` using `npx tsc`
2. Copies template files from `templates/` to `dist/templates/`
3. Sets executable permissions on compiled bin files to ensure the CLI works correctly after installation

This is configured in the `build` script in package.json, which calls `scripts/build.js`.

### Code Quality Tools

- **ESLint**: Code quality checks with TypeScript support
- **Prettier**: Code formatting
- **Husky + lint-staged**: Pre-commit hooks that automatically format and lint staged files

## Commit Guidelines

- Commit messages must follow the Conventional Commits Specification
- Commit messages must be written in English.
- A good commit message should contain multiple lines: The first line is
the title, the second line is blank, and the third line onwards contains
a detailed description of the changes.
- In the detailed description of the commit message, explain the reason
for the change (why), and include a concise description of the
modification, rather than just describing how it was changed.
- Infer the reason for the commit from the prompt, combined with the
code changes.
- Each line in the commit message should not exceed 72 characters; wrap
lines if necessary (do not add extra blank lines).
- Use HereDoc format to run git commit commands, such as: `git commit -F-
<<-EOF`, instead of using multiple `-m <message>` parameters to create multi-line commit messages. Multiple `-m <message>` parameters will
cause redundant blank lines to be inserted between commit message
paragraphs.

### Development Workflow

1. Make changes to TypeScript files in `src/`
2. Run `npm run build` to compile TypeScript to JavaScript
3. Test changes using `npm run dev -- <command>`
4. Commit changes (pre-commit hooks will automatically format and lint)

The pre-commit hooks ensure code quality by running ESLint and Prettier on staged files before each commit.

## Version Management

This project uses npm version management. To update the version:

1. Update the package version: `npm version [major|minor|patch] --no-git-tag-version`
2. Build the project: `npm run build`
3. Optionally create a git tag: `git tag v<version>`
4. Push changes and tags: `git push && git push --tags`

The project uses a prepack script that automatically runs the build process before publishing, ensuring all compiled files are up-to-date.

The CLI tool dynamically reads its version from package.json, so the `--version` parameter will always show the current version.
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,58 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.11] - 2026-02-13

### Added

- Add Codex AI coding tool support
- Add CODEX_MANAGED_BY_NPM and CODEX_MANAGED_BY_BUN environment variable detection
- Enable tracking contributions from Codex AI coding tool
- Add comprehensive test coverage for Codex environment variables

- Add OpenCode AI coding tool support
- Add OPENCODE environment variable detection
- Enable tracking contributions from OpenCode AI coding tool
- Add comprehensive test coverage for OpenCode environment variable

- Refactor AI tool detection to use modular config files
- Move from hardcoded array to individual configuration files for each AI tool
- Support tool type classification (CLI, PLUGIN, IDE, OTHERS) with priority ordering
- Improve maintainability and extensibility for adding new AI tool support
- Each tool now has its own configuration file with type, userName, userEmail, and envVars

### Changed

- Improve Node.js version compatibility
- Use tsx for Node.js 21+ to resolve ESM module resolution issues
- Update script selection logic to handle Node.js 21+ correctly
- Update compatibility documentation and test scripts

### Fixed

- Fix ESM module resolution issues in Node.js 22+
- Replace ts-node with tsx for Node.js 22+ development mode
- Resolve "Cannot find module" errors in clean environments
- Ensure development mode works correctly across all supported Node.js versions

- Fix unstable status checks in hook tests
- Add debug output to help diagnose test failures
- Remove environment-dependent status checks that were causing test instability
- Keep important assertions about warning messages in stderr

### Testing

- Enhance npm pack tests with comprehensive installed package tests
- Add tests for all CLI commands (install, exec, check-update, --help)
- Add tests for core functionality in installed package
- Add module import and configuration loading tests
- Add Git integration tests in real Git repository

- Add production build tests to verify compiled code
- Verify module import and configuration loading from compiled code
- Ensure consistency between development and production builds
- Test functionality of getCoDevelopedBy() with various environment variables

## [0.2.10] - 2026-01-23

### Fixed
Expand Down
99 changes: 0 additions & 99 deletions CLAUDE.md

This file was deleted.

1 change: 1 addition & 0 deletions CLAUDE.md
1 change: 1 addition & 0 deletions GEMINI.md
Loading
Loading