rulebook-ai

repository·main·Indexed 20 days ago

https://github.com/botingw/rulebook-ai

A command-line tool for managing and deploying consistent AI environments—including rules, context, and tools—across AI coding assistants such as Cursor, Copilot, Gemini, Windsurf, Cline, and RooCode. It utilizes a pack system (e.g., light-spec, medium-spec, heavy-spec) to provide standardized software development lifecycle environments and generates assistant-specific rule files via a project sync workflow.

Tokens
103K
Snippets
203
Records
402
Agent score
69%

What's inside rulebook-ai

  1. What rulebook-ai does

    main

    rulebook-ai is a Python package designed to manage LLM (Large Language Model) rulesets and assistant configurations. It is intended for development teams and individual developers who want to standardize AI-assisted development practices.

    Core Functionality

    • Rule Management: Install, sync, and clean rule sets for various AI assistants (e.g., Cursor, Windsurf, GitHub Copilot).
    • Memory Banking: Organize and share knowledge bases (memory banks) across different projects.
    • Tool Integration: Manage reusable tools and utilities for AI workflows.
    • CLI Interface: Provides a professional command-line interface to perform all the above operations.
  2. Overview of the Custom User Prompt (Rules) Framework

    main

    The Custom User Prompt (Rules) framework is designed to provide a consistent and context-aware environment for AI coding assistants such as Cursor, CLINE, RooCode, and Windsurf.

    It addresses the problem of inconsistent AI behavior and poor context management in complex software projects by using:

    1. Structured Documentation (Memory Bank): A system using docs/ and tasks/ directories to provide shared, persistent project context.
    2. Software Engineering Principles: Integration of established practices for planning, implementation, debugging, and documentation.
    3. Cross-Platform Compatibility: Native respect for the specific rule guidelines and loading mechanisms of different AI platforms.
    4. Minimal Token Usage: Optimized rule file organization to leverage platform-specific loading mechanisms efficiently.
  3. Rulebook-AI Pack Structure Specification

    main

    A Rulebook-AI Pack is a self-contained directory. To pass validation, the root directory must contain only the following items. Any extra files or directories at the root (like tests/ or docs/) will cause validation to fail; such content must be moved inside standard directories like memory_starters/docs/.

    Required Files/Directories

    • manifest.yaml: Metadata for the pack.
    • README.md: Description and usage.
    • rules/: The universal source for AI assistant rules.

    Optional Files/Directories

    • memory_starters/: Starter files for the user's memory/ directory.
    • tool_starters/: Starter scripts for the user's tools/ directory.

    Example Layout

    my-awesome-pack/
    ├── manifest.yaml
    ├── README.md
    ├── rules/
    │   ├── 01-rules/
    │   │   ├── 00-meta.md
    │   │   └── 01-principles.md
    │   ├── 02-rules-architect/
    │   │   └── 01-planning.md
    │   └── 03-rules-code/
    │       └── 01-coding.md
    ├── memory_starters/
    │   └── docs/
    │       └── new-feature-template.md
    └── tool_starters/
        └── my-custom-script.py
  4. Configure rules for Single-File Assistants

    main

    Single-file assistants (such as Warp, GitHub Copilot, or Claude) read from one consolidated rule file.

    When you run sync, the CLI:

    1. Concatenates content: It merges the content of all rule files from all active packs into a single output file (e.g., WARP.md).
    2. Determines order: The order of content follows the pack order defined in .rulebook-ai/selection.json, followed by the alphabetical order of files within each pack's rules/ directory. Using numeric prefixes (e.g., 01-) in your pack structure ensures this order is deterministic.
  5. Apply Microagents at Organization or User levels

    main

    To avoid duplicating microagents in every repository, you can define them at a higher scope:

    • Organization Level: Place microagent files in a special repository named .openhands (or openhands-config on GitLab). These are automatically loaded for every project owned by that organization.
    • User Level (Local): For local OpenHands installations, place microagent files in ~/.openhands/microagents to have them loaded for all conversations across your machine.
  6. Implement a Decision Log for AI Context

    main

    A Decision Log is a vital component for preventing AI from contradicting past architectural or technical choices.

    Usage requirements:

    • Record significant technical/architectural decisions, the rationale behind them, and alternatives considered.
    • Ensure the log is easily accessible and linked from relevant work items or Memory Bank files so the AI can retrieve this context during task execution.
  7. Use READ_ARCHITECTURE rules for architectural parsing

    main

    The READ_ARCHITECTURE rule set is designed to guide AI assistants in parsing and understanding solution architecture from a specific file: /memory/docs/architecture.md.

    When this rule is active, the AI is instructed to:

    1. Load and parse the complete Mermaid diagram within the file.
    2. Extract key architectural details, including module boundaries, relationships, data flow patterns, system interfaces, and component dependencies.
    3. Validate changes against the established architectural constraints.
    4. Enforce separation of concerns to ensure new code does not violate the defined architecture.

    Error Handling Behavior:

    • If /memory/docs/architecture.md is missing, the AI must STOP and notify the user.
    • If the Mermaid diagram fails to parse, the AI must REQUEST clarification.
    • If an architectural violation is detected, the AI must WARN the user.
    READ_ARCHITECTURE: |
      File: /memory/docs/architecture.md @architecture.md
      Required parsing:
      1. Load and parse complete Mermaid diagram
      2. Extract and understand:
         - Module boundaries and relationships
         - Data flow patterns
         - System interfaces
         - Component dependencies
      3. Validate any changes against architectural constraints
      4. Ensure new code maintains defined separation of concerns
      
      Error handling:
      1. If file not found: STOP and notify user
      2. If diagram parse fails: REQUEST clarification
      3. If architectural violation detected: WARN user
  8. Use lessons-learned rules for project intelligence

    main

    The 03-lessons-learned.md rule is a living document designed to capture important patterns, preferences, and project intelligence. It is intended to grow smarter as development progresses. When using AI assistants with this rule enabled, the assistant should use this file to record and retrieve context that prevents repetitive mistakes and maintains project consistency.

    Key behaviors captured in this rule include:

    • File Verification: Verifying file existence and content before modification.
    • Tool Selection: Choosing the appropriate tool (e.g., write_to_file vs. replace_in_file).
    • MCP Server Verification: Confirming MCP server availability and configuration.
    • Task Planning: Documenting tasks in tasks/tasks_plan.md before implementation.
    • Instruction Adherence: Following specific guidelines regarding tool usage and mode switching.
  9. Understand the rulebook-ai project structure

    main

    The project follows the modern Python src layout. This structure separates the main package code from tests and configuration files, ensuring that imports work correctly and the package is ready for distribution.

    Directory Layout

    • src/rulebook_ai/: Contains the main package code.
      • __init__.py: Package initialization.
      • __main__.py: Enables running the package via python -m rulebook_ai.
      • core.py: Contains the business logic, specifically the RuleManager class.
      • cli.py: Defines the command-line interface.
    • tests/integration/: Contains integration tests (e.g., test_rule_manager.py, test_cli_commands.py).
    • rule_sets/: Stores rule templates for various AI assistants.
    • memory_starters/: Contains memory bank templates.
    • tool_starters/: Contains tool integration examples.
    • pyproject.toml: The declarative project configuration file.
    rulebook-ai/
    ├── src/rulebook_ai/          # Main package (src layout)
    │   ├── __init__.py           # Package initialization
    │   ├── __main__.py           # Allow python -m rulebook_ai
    │   ├── core.py               # Business logic (RuleManager class)
    │   └── cli.py                # Command-line interface
    ├── tests/integration/        # Integration tests only
    │   ├── conftest.py           # Shared test fixtures
    │   ├── test_package_installation.py
    │   ├── test_rule_manager.py
    │   ├── test_cli_commands.py
    │   └── test_tools_integration.py
    ├── rule_sets/                # Rule templates for AI assistants
    ├── memory_starters/          # Memory bank templates
    ├── tool_starters/            # Tool integration examples
    ├── pyproject.toml            # Project configuration
    └── README.md                 # Project documentation
  10. How Light-Spec manages AI memory and rules

    main

    Light-Spec operates on a dual-system model: Procedural Rules (how the AI acts) and Contextual Memory (what the AI knows).

    1. Procedural Rules (The 'How')

    Rules are stored in .rulebook-ai/packs/light-spec/rules/ and define systematic workflows. The project sync command translates these into assistant-specific formats:

    • Cursor: .mdc files in .cursor/rules/.
    • RooCode: Mode-specific rules in .roo/rules-architect/ or .roo/rules-code/.
    • Windsurf: .md files in .windsurf/rules/.
    • Single-file assistants: A single concatenated file.

    2. Contextual Memory (The 'What')

    The memory/ directory is a user-owned space for persistent, structured knowledge. It includes PRDs, architecture docs, and task plans. This acts as the AI's long-term project 'second brain'.

    Prompting Patterns

    To get the best results, use file references (e.g., @filename) to connect rules and memory:

    • Planning: "Add a 'Refactor Auth' task to @memory/tasks/tasks_plan.md with a short description."
    • Context Lookup: "What database did we choose in @memory/docs/architecture.md?"
    • Implementation: "Follow @.rulebook-ai/packs/light-spec/rules/03-rules-code/01-code_v1.md to build the login flow described in @memory/tasks/active_context.md."