Skip to content

jdkim/prompt_manager

Repository files navigation

PromptNavigator

Rails engine for managing prompt execution history with visual interface.

Features

  • Visual history stack with parent-child relationships
  • Modern CSS with nested syntax
  • Stimulus-powered interactive arrows
  • Automatic asset pipeline integration
  • Active state highlighting
  • Responsive design with hover effects
  • Built-in model for tracking prompt executions

Installation

Add this line to your application's Gemfile:

gem "prompt_navigator"

And then execute:

$ bundle install

Generate the migration for prompt executions:

$ rails generate prompt_navigator:modeling
$ rails db:migrate

This will create the prompt_navigator_prompt_executions table with the following fields:

  • execution_id - Unique identifier (UUID) for each prompt execution
  • prompt - The prompt text
  • llm_platform - The LLM platform used (e.g., "openai", "anthropic")
  • model - The model name (e.g., "gpt-4", "claude-3")
  • configuration - Model configuration settings
  • response - The LLM response
  • previous_id - Reference to the parent execution (for history tree)

Usage

Basic Setup

In your application's layout file (app/views/layouts/application.html.erb), make sure you have <%= yield :head %> in the <head> section:

<head>
  <title>Your App</title>
  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>

  <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
  <%= javascript_importmap_tags %>

  <%= yield :head %>
</head>

Include the history partial in your view:

<%= render 'prompt_navigator/history', locals: { active_uuid: @current_execution_id, card_path: ->(execution_id) { my_path(execution_id) } } %>

Asset Pipeline Configuration

The engine automatically configures the asset pipeline to include:

  • prompt_navigator/history.css - Styles for the history component
  • controllers/history_controller.js - Stimulus controller for arrow drawing

The assets are automatically precompiled and made available to your application. For Rails 7+ with importmap, the CSS will be loaded via stylesheet_link_tag when you render the history partial, and the Stimulus controller will be automatically registered.

Controller Setup

Include HistoryManageable concern in your controller:

class MyController < ApplicationController
  include HistoryManageable

  def index
    # Initialize history with prompt executions
    initialize_history(PromptNavigator::PromptExecution.all)

    # Set the active execution ID (optional)
    set_active_message_uuid(params[:execution_id])
  end

  def create
    # Add new execution to history
    new_execution = PromptNavigator::PromptExecution.create(
      prompt: params[:prompt],
      llm_platform: "openai",
      model: "gpt-4",
      configuration: params[:config].to_json,
      response: llm_response,
      previous: @current_execution
    )
    push_to_history(new_execution)
  end
end

Using PromptExecution Model

The PromptNavigator::PromptExecution model has the following attributes and methods:

execution = PromptNavigator::PromptExecution.create(
  prompt: "Your prompt text",
  llm_platform: "openai",
  model: "gpt-4",
  configuration: "{\"temperature\": 0.7}",
  response: "LLM response text",
  previous: parent_execution  # Optional: for building history tree
)

# Access fields
execution.execution_id  # UUID, automatically generated
execution.prompt        # The prompt text
execution.llm_platform  # LLM platform used
execution.model         # Model name
execution.configuration # Configuration JSON
execution.response      # LLM response
execution.previous      # Parent execution (belongs_to association)

Using the Helper Method

The helper methods are automatically included in your views. You can use the history_list helper:

<%= history_list(->(execution_id) { my_item_path(execution_id) }, active_uuid: @current_execution_id) %>

Customizing the Card Path

The card_path parameter should be a callable (Proc or lambda) that takes an execution_id and returns a path:

<%= render 'prompt_navigator/history',
    locals: {
      active_uuid: @current_execution_id,
      card_path: ->(execution_id) { my_item_path(execution_id) }
    }
%>

Or using the helper:

<%= history_list(->(execution_id) { my_item_path(execution_id) }, active_uuid: @current_execution_id) %>

Troubleshooting

Styles not loading

Make sure you have <%= yield :head %> in your application layout's <head> section.

Arrows not appearing

The arrow visualization requires:

  1. Stimulus to be properly configured in your application
  2. The history_controller.js to be loaded (automatic with importmap)
  3. Parent-child relationships to be properly set using the previous association in your PromptExecution records

History not displaying

Ensure that:

  1. @history instance variable is set in your controller using initialize_history
  2. Your PromptExecution records have execution_id values (automatically generated on create)
  3. The card_path callable is correctly defined and returns valid paths

Requirements

  • Rails >= 8.1.2
  • Stimulus (Hotwired)

Installation

Add this line to your application's Gemfile:

gem "prompt_navigator"

And then execute:

$ bundle

Or install it yourself as:

$ gem install prompt_navigator

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages