Rails engine for managing prompt execution history with visual interface.
- 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
Add this line to your application's Gemfile:
gem "prompt_navigator"And then execute:
$ bundle installGenerate the migration for prompt executions:
$ rails generate prompt_navigator:modeling
$ rails db:migrateThis will create the prompt_navigator_prompt_executions table with the following fields:
execution_id- Unique identifier (UUID) for each prompt executionprompt- The prompt textllm_platform- The LLM platform used (e.g., "openai", "anthropic")model- The model name (e.g., "gpt-4", "claude-3")configuration- Model configuration settingsresponse- The LLM responseprevious_id- Reference to the parent execution (for history tree)
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) } } %>The engine automatically configures the asset pipeline to include:
prompt_navigator/history.css- Styles for the history componentcontrollers/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.
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
endThe 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)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) %>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) %>Make sure you have <%= yield :head %> in your application layout's <head> section.
The arrow visualization requires:
- Stimulus to be properly configured in your application
- The
history_controller.jsto be loaded (automatic with importmap) - Parent-child relationships to be properly set using the
previousassociation in your PromptExecution records
Ensure that:
@historyinstance variable is set in your controller usinginitialize_history- Your PromptExecution records have
execution_idvalues (automatically generated on create) - The
card_pathcallable is correctly defined and returns valid paths
- Rails >= 8.1.2
- Stimulus (Hotwired)
Add this line to your application's Gemfile:
gem "prompt_navigator"And then execute:
$ bundleOr install it yourself as:
$ gem install prompt_navigatorContribution directions go here.
The gem is available as open source under the terms of the MIT License.