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

Installation

If available in Hex, the package can be installed by adding code_reasoning_ex to your list of dependencies in mix.exs:

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

Usage

Basic Example

# 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

# 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

# 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

List all available prompts:

prompts = CodeReasoning.list_prompts()

Documentation

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/code_reasoning_ex.

License

MIT License - see LICENSE file for details.