diff --git a/CHANGELOG.md b/CHANGELOG.md index ffc66bf..3ac8a69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- Codex integration: `agents/codex/AGENTS.md` flat entry point (all rules inlined) +- `ai-rules generate` command: resolves `@rules/` imports and writes a flat file + for agents without native import support (`supports_imports = false`) +- `src/ai_rules/generator.py`: `resolve_imports()` and `generate_flat_file()` functions +- `agents.toml`: Codex agent registered (`install_dir = ~/.codex`, no import support) +- `tests/test_generator.py`: 7 tests for the generator module +- `rules/cli.md`: require shell completion for every CLI tool +- `rules/commits.md`: prefer detailed commit messages + ## [0.3.1] - 2026-03-26 ### Added diff --git a/README.md b/README.md index 0e6f269..62d684d 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,20 @@ supported AI assistants. ## Supported assistants -| Key | Assistant | Config file | -|----------|--------------|---------------------------| -| `claude` | Claude Code | `agents/claude/CLAUDE.md` | +| Key | Assistant | Config file | Import support | +|----------|--------------|-------------------------------|----------------| +| `claude` | Claude Code | `agents/claude/CLAUDE.md` | native | +| `codex` | Codex | `agents/codex/AGENTS.md` | flat file | ## Structure ``` ai-rules/ ├── agents/ -│ └── claude/ -│ └── CLAUDE.md # Claude Code entry point (imports rules via @rules/) +│ ├── claude/ +│ │ └── CLAUDE.md # Claude Code entry point (imports rules via @rules/) +│ └── codex/ +│ └── AGENTS.md # Codex entry point (flat file, generated via `ai-rules generate`) ├── rules/ # Shared rule files by topic │ ├── principles.md │ ├── language.md @@ -89,10 +92,11 @@ Options: --help Show this message and exit. Commands: - list List available agents. - status Show installation status for one or all agents. - install Install rules for one or all agents. - update Update installation for one or all agents. + list List available agents. + status Show installation status for one or all agents. + install Install rules for one or all agents. + update Update installation for one or all agents. + generate Generate flat rule files for agents without native import support. ``` ### Examples @@ -114,6 +118,10 @@ ai-rules install claude # Dry run ai-rules install --dry-run +# Regenerate flat files for agents without native import support +ai-rules generate +ai-rules generate codex + # Shell completion (bash/zsh/fish) ai-rules --install-completion ``` @@ -131,6 +139,17 @@ For each declared link in `agents.toml`, `ai-rules install`: | `~/.claude/CLAUDE.md` | `agents/claude/CLAUDE.md` | | `~/.claude/rules` | `rules/` | | `~/.claude/settings.json` | `settings.json` | +| `~/.codex/AGENTS.md` | `agents/codex/AGENTS.md` | + +### Agents without native import support (Codex) + +Codex does not support `@rules/` imports natively. Its entry point is a flat +file generated from the Claude entry point with all imports resolved inline. +Regenerate it after updating any rule file: + +```bash +ai-rules generate codex +``` ## Development diff --git a/TODO.md b/TODO.md index 4eaecb5..99dda29 100644 --- a/TODO.md +++ b/TODO.md @@ -3,10 +3,10 @@ Improvements and additions to consider for future iterations of this config. ## Codex integration -- [ ] Add `agents/codex/AGENTS.md` entry point (flat file — no @rules/ import support) -- [ ] Add `generate` command to CLI: concatenate rules/ into a flat file for agents without native import support -- [ ] Register Codex agent in `agents.toml` -- [ ] Add tests for generate command and Codex agent +- [x] Add `agents/codex/AGENTS.md` entry point (flat file — no @rules/ import support) +- [x] Add `generate` command to CLI: concatenate rules/ into a flat file for agents without native import support +- [x] Register Codex agent in `agents.toml` +- [x] Add tests for generate command and Codex agent ## Naming conventions - [ ] Add naming conventions for other languages (JavaScript/TypeScript, Python, Go...) in `rules/naming.md` as they become relevant in projects diff --git a/agents.toml b/agents.toml index 9ea78a7..b9bb9bb 100644 --- a/agents.toml +++ b/agents.toml @@ -27,3 +27,13 @@ supports_imports = true [[agents.claude.links]] source = "settings.json" target = "settings.json" + +[agents.codex] +name = "Codex" +entry_point = "agents/codex/AGENTS.md" +install_dir = "~/.codex" +supports_imports = false + + [[agents.codex.links]] + source = "agents/codex/AGENTS.md" + target = "AGENTS.md" diff --git a/agents/codex/AGENTS.md b/agents/codex/AGENTS.md new file mode 100644 index 0000000..be76cf5 --- /dev/null +++ b/agents/codex/AGENTS.md @@ -0,0 +1,595 @@ +# Global Rules + +## Language & style + +# Language + +All code, code comments, commit messages, variable names, script output strings, filenames, and any other project artifact must be written in English. + +French is reserved exclusively for conversational exchanges between the user and the AI. + +# Naming Conventions + +## Shell scripts +- `UPPER_CASE` — constants, global variables, environment variables +- `lower_case` — local variables inside functions +- `_leading_underscore` — internal/private functions not meant to be called directly +- `lower_case` — public functions (descriptive verb-noun, e.g. `parse_arguments`, `check_dependencies`) +- Avoid abbreviations unless universally understood (e.g. `dir`, `tmp`, `cmd`) + +## Files and directories +- `kebab-case` for script filenames (e.g. `install-forgejo.sh`) +- `UPPER_CASE` for top-level doc files (e.g. `README.md`, `CHANGELOG.md`) +- `lower_case` or `kebab-case` for directories + +# Editor Configuration + +Every project must include an `.editorconfig` file at the root with at least the following settings: + +```ini +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.sh] +indent_style = space +indent_size = 2 + +[*.{js,ts,json,yml,yaml}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false +``` + +Adapt indentation rules to the language conventions of the project. Propose the `.editorconfig` at project start and wait for user validation. + +## General principles + +# General Coding Principles + +## Analyze before coding +Always read and understand the relevant code before writing or modifying anything. Never edit a file that has not been read first. If the scope is unclear, ask before proceeding. + +## Propose before implementing +For any non-trivial change, describe the intended approach and wait for explicit validation before writing code. This avoids costly back-and-forth on the wrong solution. + +## Clarify before starting +If a request is ambiguous, incomplete, or could be interpreted in multiple ways, ask for clarification before writing any code. Starting on a wrong assumption wastes more time than a single clarifying question. + +## Propose options before deciding +For any structuring choice (architecture, tooling, git strategy, framework, etc.), present the available options with their trade-offs and wait for explicit validation before proceeding. Never make a significant design decision autonomously. + +## Prefer minimal diffs +Make the smallest change that correctly solves the problem. Do not touch code outside the scope of the request, even to fix style or improve readability. + +## No refactoring without explicit request +Never restructure, rename, or reorganize existing code unless the user has explicitly asked for it. Refactoring mixed with feature changes makes review harder and increases risk. + +## No speculative additions +Do not add features, options, abstractions, or error handling for hypothetical future needs. Implement only what is currently required. + +## No dead code +Do not leave commented-out code, unused variables, or untracked TODOs. Either resolve them or open a tracked issue. + +## Confirm before irreversible actions +Any action that is hard or impossible to undo (file deletion, branch deletion, `git reset --hard`, force-push, database drop, etc.) must be explicitly described to the user and confirmed before execution. Never perform destructive operations autonomously. + +## Explicit naming +Names for functions, methods, classes, variables, and files must be as explicit as possible. Prefer clarity over brevity: a longer name that describes intent precisely is always better than a short name that requires context to understand. + +## Development practices + +# Test-Driven Development + +Always apply TDD. At the start of a project, propose one or more suitable test frameworks with a clear recommendation. Use the framework validated by the user throughout the project. + +- Follow the Red-Green-Refactor cycle: write a failing test first, make it pass with minimal code, then refactor. +- Write tests before or alongside every new feature or fix. +- Keep tests in a `tests/` directory with a dedicated runner script. +- For shell scripts: bats-core is the standard choice. + +# Security + +- Never hardcode credentials, tokens, API keys, or passwords in source files +- Use environment variables or a secret manager for sensitive values +- Add secret files (`.env`, `*.key`, `*_token`, etc.) to `.gitignore` before the first commit +- Always version a `.env.example` file alongside `.env`: it lists all expected keys with empty or placeholder values, documents the required configuration without exposing secrets, and must be kept in sync with `.env` as new variables are added +- If a secret is accidentally committed: immediately inform the user, explain the risks (exposure in git history, potential misuse), attempt to remediate (e.g. `git filter-branch` or BFG, force-push if not yet public), and in all cases revoke/rotate the credential without delay + +## File permissions +- Never create world-writable files +- Configuration files containing credentials: `600` +- Scripts that read sensitive configs: `700` + +## Input validation +- Always validate and sanitize arguments before use in shell scripts to prevent command injection +- Reject or abort on unexpected/empty values for critical parameters + +## External dependencies +- Check for required external commands at the top of every script before use: + `command -v foo || { echo "foo is required" >&2; exit 1; }` + +## Least privilege +- Scripts request only the permissions strictly necessary to function +- Never use `sudo` by default — only when explicitly required and documented + +## Error handling +- Write error messages to `stderr` (`>&2`), never to `stdout` +- Use explicit and consistent exit codes (`exit 0` success, `exit 1` general error, higher values for specific cases) +- Avoid silencing errors with `|| true` unless the case is explicitly justified with a comment + +# Dependencies + +- Pin dependency versions explicitly — never use unpinned or wildcard versions in production +- Prefer actively maintained packages with a clear release history +- Run a security audit before each release (e.g. `npm audit`, `pip audit`, or equivalent) +- Keep dependencies up to date; review and update regularly +- Minimize the number of dependencies — prefer standard library or well-established tools over niche packages +- Document why each non-obvious dependency was chosen (in `README.md` or inline comment) + +# Compatibility + +## Shell +- Target **Bash 5+** by default +- If POSIX `sh` compatibility is required, declare it explicitly at project start and avoid Bash-specific features (arrays, `[[`, `$(())` with non-POSIX syntax, etc.) +- Declare the target shell in the shebang: `#!/usr/bin/env bash` + +## Operating system +- Target **Ubuntu LTS** (current and previous release) by default +- Declare supported OS and versions in `README.md` +- If the script relies on OS-specific tools, document the assumption and add a compatibility check at startup + +## Project structure & documentation + +# Documentation + +Every project must include the following files from the start: + +- `README.md` — project description, usage, install instructions +- `CHANGELOG.md` — updated on every meaningful change +- `VERSION` — single line, semver (e.g. `1.0.0`), source of truth for version numbers +- `LICENSE.md` — ask the user to validate the license choice before creating it + +Keep all documentation up to date as the project evolves. + +## Community / open source (on user request) + +When the user intends to share the project publicly, propose the following files and wait for explicit validation before creating each one: + +- `CONTRIBUTING.md` — contribution guidelines (workflow, conventions, PR process) +- `CODE_OF_CONDUCT.md` — code of conduct (e.g. Contributor Covenant) +- `SECURITY.md` — vulnerability reporting policy +- `SUPPORT.md` — where to get help +- `.github/ISSUE_TEMPLATE/bug_report.md` — bug report template +- `.github/ISSUE_TEMPLATE/feature_request.md` — feature request template +- `.github/PULL_REQUEST_TEMPLATE.md` — pull request template +- `AUTHORS.md` — list of contributors (optional, ask user) + +The application/script must read its version from the `VERSION` file, not from a hardcoded constant. + +**First commit of a new project:** `init: ` with a detail block. +**Subsequent commits:** standard conventional commit messages (`feat:`, `fix:`, `docs:`, `test:`, etc.). + +# Changelog + +Follow the [Keep a Changelog](https://keepachangelog.com) format. + +## Structure +- Always maintain an `[Unreleased]` section at the top for changes not yet released +- On release: rename `[Unreleased]` to `[X.Y.Z] - YYYY-MM-DD` and add a new empty `[Unreleased]` section + +## Sections (use only those that apply) +- `Added` — new features +- `Changed` — changes to existing functionality +- `Deprecated` — features to be removed in a future release +- `Removed` — removed features +- `Fixed` — bug fixes +- `Security` — vulnerability fixes + +## Rules +- Every meaningful commit must have a corresponding entry in `[Unreleased]` +- Entries are written in English, in the imperative mood (e.g. "Add logging support") +- Do not list trivial changes (formatting, typos in comments, etc.) + +# Semantic Versioning + +All projects follow semver (`MAJOR.MINOR.PATCH`): + +- **PATCH** — backwards-compatible bug fixes +- **MINOR** — new backwards-compatible functionality +- **MAJOR** — breaking changes + +Bump the version in the `VERSION` file as part of the commit that introduces the change. + +## Shell & CLI + +# Shell Scripts + +- Always enable strict mode at the top of every script: `set -euo pipefail` +- Run `shellcheck` on all scripts before proposing a commit +- Ensure scripts are executable: `chmod +x