README.md

# CodeReasoning

A structured code reasoning system for Elixir applications that provides tools for reflective problem-solving through sequential thinking, with support for branching and revision semantics. Designed for integration with Phoenix/LiveView applications.

## Features

- **Sequential Thought Processing**: Break down complex problems into manageable steps with built-in validation
- **Branching**: Explore alternative approaches from any existing thought point
- **Revision Semantics**: Correct or update earlier thoughts when new insights emerge
- **Built-in Prompt Templates**: Ready-to-use templates for common development tasks:
  - Bug analysis and debugging
  - Architecture decisions
  - Code review
  - Feature planning
  - Refactoring strategies
- **Safety Limits**: Automatic prevention of infinite loops (max 20 thoughts)
- **Phoenix/LiveView Ready**: Seamlessly integrates with Phoenix applications

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `code_reasoning_ex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:code_reasoning_ex, "~> 0.0.1"}
  ]
end
```

## Usage

### Basic Example

```elixir
# Process a single thought
{:ok, result} = CodeReasoning.process_thought(%{
  thought: "Analyzing the bug in the authentication module",
  thought_number: 1,
  total_thoughts: 5,
  next_thought_needed: true
})

# Use a prompt template
{:ok, prompt} = CodeReasoning.apply_prompt("bug-analysis", %{
  bug_behavior: "User login fails silently",
  expected_behavior: "User should see error message",
  affected_components: "AuthController, SessionManager"
})
```

### Branching Example

```elixir
# Create a branch to explore an alternative approach
{:ok, branch} = CodeReasoning.process_thought(%{
  thought: "Exploring cache-based solution",
  thought_number: 3,
  total_thoughts: 7,
  next_thought_needed: true,
  branch_from_thought: 2,
  branch_id: "cache-approach"
})
```

### Revision Example

```elixir
# Revise an earlier thought with new insights
{:ok, revision} = CodeReasoning.process_thought(%{
  thought: "Actually, the issue is in the middleware, not the controller",
  thought_number: 4,
  total_thoughts: 6,
  next_thought_needed: true,
  is_revision: true,
  revises_thought: 2
})
```

## Available Prompt Templates

- **`architecture-decision`**: Framework for making architectural decisions
- **`bug-analysis`**: Systematic approach to debugging
- **`code-review`**: Comprehensive code review checklist
- **`feature-planning`**: Structure for planning new features
- **`refactoring-plan`**: Strategy for code refactoring

List all available prompts:

```elixir
prompts = CodeReasoning.list_prompts()
```

## Documentation

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/code_reasoning_ex>.

## License

MIT License - see LICENSE file for details.