prompt_navigator 1.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98692f1dda3e7931462773cec0518c8347dd5cbd532c34524c7b46e0bc6d7ee1
4
- data.tar.gz: 5a99f94b64a65b330b9ea9a342f21033da9847099bf88388ba150f73eff7726f
3
+ metadata.gz: d2bd1c7a54df81a452d45f5c47cf2d9d615c960d49c9315a932aa72fcbbb1c46
4
+ data.tar.gz: f8a13126d0457b4f78368a8c00354bb91fcafc4ee65dc41f1d1c26021bc066fa
5
5
  SHA512:
6
- metadata.gz: d6b3509d25fccf173d8f03068cad8ba8f3faa711f9602974a9d9b039600eb270beb35abcaf00a5d4aa0e735a928f05392646f674a0dc0147b93fff1b6a8f8b12
7
- data.tar.gz: 7efcedc30d74200431f6d67a480747c37f71062bd2e6e773e68ac5608a1160ec4bde8bf2cd5412653d7145b921d3b94edeaf10716584b7c997837187fdd6a9eb
6
+ metadata.gz: 140614573d6032ef309d6899a43c0c79f04819bc0fc33cb42c867c66f905ba04ed0db30776d7b3eb2d4d5d6535949e63c46b17e351d4fc8b9d74fbb39af56854
7
+ data.tar.gz: 5854d8db2def7559e15e1e5f6c0c5161148c07a99bc51e8a9087c522b0666c21c72fd942b5c7565e0adbb3e38840e83adcde5556d07cd4a58bbaf2dc996c5d75
data/README.md CHANGED
@@ -14,7 +14,7 @@ A Rails engine for managing and visualizing LLM prompt execution history. It pro
14
14
 
15
15
  ## Requirements
16
16
 
17
- - Ruby >= 3.2.0
17
+ - Ruby >= 3.4.9
18
18
  - Rails >= 8.1.2
19
19
  - Stimulus ([Hotwire](https://hotwired.dev/))
20
20
 
@@ -2,8 +2,8 @@
2
2
  position: relative;
3
3
  display: flex;
4
4
  flex-direction: column;
5
- gap: 8px;
6
5
  padding-left: 32px; /* space for arrows */
6
+ margin-top: 20px;
7
7
  }
8
8
 
9
9
  .history-card {
@@ -14,6 +14,7 @@
14
14
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
15
15
  position: relative;
16
16
  z-index: 1;
17
+ margin-bottom: 16px;
17
18
  transition:
18
19
  box-shadow 0.15s ease,
19
20
  transform 0.15s ease;
@@ -27,17 +28,70 @@
27
28
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
28
29
  transform: translateY(-2px);
29
30
  }
31
+
32
+ &:last-child {
33
+ margin-bottom: 0;
34
+ }
35
+
36
+ &:has(+ .history-straight-arrow) {
37
+ margin-bottom: 0;
38
+ }
39
+ }
40
+
41
+ .history-card-row {
42
+ display: flex;
43
+ align-items: center;
44
+ gap: 6px;
45
+ }
46
+
47
+ .history-card-row .history-card-link {
48
+ flex: 1;
49
+ min-width: 0;
30
50
  }
31
51
 
32
52
  .history-card-link {
33
- display: grid;
34
- grid-template-columns: auto 1fr auto;
35
- grid-gap: 8px;
53
+ display: block;
36
54
  text-decoration: none;
37
55
  color: #333;
56
+ min-width: 0;
57
+ }
58
+
59
+ .history-card-delete-form {
60
+ margin: 0;
61
+ display: flex;
38
62
  align-items: center;
39
63
  }
40
64
 
65
+ .history-card-delete {
66
+ display: flex;
67
+ align-items: center;
68
+ justify-content: center;
69
+ width: 22px;
70
+ height: 22px;
71
+ padding: 0;
72
+ border: none;
73
+ background: transparent;
74
+ border-radius: 4px;
75
+ color: #888;
76
+ cursor: pointer;
77
+ flex-shrink: 0;
78
+ opacity: 0;
79
+ transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
80
+
81
+ i {
82
+ font-size: 12px;
83
+ }
84
+
85
+ &:hover {
86
+ color: #dc2626;
87
+ background-color: rgba(220, 38, 38, 0.1);
88
+ }
89
+ }
90
+
91
+ .history-card:hover .history-card-delete {
92
+ opacity: 1;
93
+ }
94
+
41
95
  .history-card-number {
42
96
  font-size: 12px;
43
97
  font-weight: 600;
@@ -57,7 +111,6 @@
57
111
  font-size: 10px;
58
112
  font-weight: 700;
59
113
  letter-spacing: 0.02em;
60
- margin-left: auto;
61
114
  flex-shrink: 0;
62
115
  padding: 2px 6px;
63
116
  border-radius: 4px;
@@ -85,9 +138,10 @@
85
138
  display: flex;
86
139
  justify-content: center;
87
140
  align-items: center;
88
- height: 8px;
141
+ height: 16px;
89
142
  margin: 0;
90
- font-size: 10px;
143
+ font-size: 16px;
144
+ font-weight: bold;
91
145
  color: #555;
92
146
  line-height: 1;
93
147
  }
@@ -8,7 +8,13 @@ export default class extends Controller {
8
8
  #drawArrowsBound
9
9
  #markerId = "history-arrow-head"
10
10
  #startX = 32
11
- #curveOffset = 40
11
+ // Curve offset scales with the vertical gap so arcs of different lengths
12
+ // nest instead of overlap. Bounded so short arcs don't collapse onto the
13
+ // stack and long arcs don't escape the sidebar pane (the stack only has
14
+ // `padding-left: 32px` of space before the chat area).
15
+ #minCurveOffset = 12
16
+ #maxCurveOffset = 28
17
+ #curveScale = 0.22
12
18
 
13
19
  connect() {
14
20
  this.#drawArrows()
@@ -102,13 +108,17 @@ export default class extends Controller {
102
108
  // Skip if cards are adjacent - straight arrow is rendered by helper
103
109
  if (verticalGap < 80) return
104
110
 
105
- const path = this.#createCurvedArrowPath(startY, endY)
111
+ const path = this.#createCurvedArrowPath(startY, endY, verticalGap)
106
112
  svg.appendChild(path)
107
113
  }
108
114
 
109
- #createCurvedArrowPath(startY, endY) {
115
+ #createCurvedArrowPath(startY, endY, verticalGap) {
110
116
  const startX = this.#startX // left edge margin
111
- const curveX = startX - this.#curveOffset // curve outward to the left
117
+ const curveOffset = Math.max(
118
+ this.#minCurveOffset,
119
+ Math.min(verticalGap * this.#curveScale, this.#maxCurveOffset)
120
+ )
121
+ const curveX = startX - curveOffset // curve outward to the left
112
122
  const pathData = `M ${startX} ${startY} C ${curveX} ${startY}, ${curveX} ${endY}, ${startX} ${endY}`
113
123
 
114
124
  const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
@@ -13,6 +13,22 @@ module PromptNavigator
13
13
  end
14
14
  end
15
15
 
16
+ # Bulk-delete a set of PromptExecutions, tolerating the self-referential
17
+ # `previous_id` foreign key by first nulling intra-set links. Callers
18
+ # (e.g. a host's Chat#destroy flow) pass the ids of orphaned executions
19
+ # after their owning records (Messages) have been destroyed.
20
+ #
21
+ # Raises ActiveRecord::InvalidForeignKey if any PE in the set is still
22
+ # referenced from outside the set (e.g. another chat's branch); callers
23
+ # decide whether to rescue and leave the orphans in place.
24
+ def self.delete_set!(ids)
25
+ ids = Array(ids).compact
26
+ return if ids.empty?
27
+
28
+ where(id: ids).update_all(previous_id: nil)
29
+ where(id: ids).delete_all
30
+ end
31
+
16
32
  private
17
33
 
18
34
  # Returns ancestor PromptExecutions in chronological order (oldest first),
@@ -1,13 +1,16 @@
1
1
  <%
2
2
  active_uuid = locals[:active_uuid]
3
3
  card_path = locals[:card_path]
4
+ delete_path = locals[:delete_path]
5
+ # A PE is a leaf when no other PE in the chat references it as `previous`.
6
+ non_leaf_ids = @history.filter_map { |pe| pe.previous_id }
4
7
  %>
5
8
 
6
9
  <h2>History</h2>
7
10
  <% if @history.present? %>
8
11
  <div class="history-stack" data-controller="history">
9
12
  <% @history.each_with_index do |ann, idx| %>
10
- <%= render 'prompt_navigator/history_card', locals: { ann: ann, next_ann: @history[idx + 1], is_active: ann.execution_id == active_uuid, card_path: card_path } %>
13
+ <%= render 'prompt_navigator/history_card', locals: { ann: ann, next_ann: @history[idx + 1], is_active: ann.execution_id == active_uuid, card_path: card_path, delete_path: delete_path, is_leaf: !non_leaf_ids.include?(ann.id) } %>
11
14
  <% end %>
12
15
  <svg class="history-arrows" data-history-target="svg"></svg>
13
16
  </div>
@@ -4,18 +4,40 @@
4
4
  is_active = locals[:is_active]
5
5
  parent_uuid = ann.previous&.execution_id
6
6
  card_path = locals[:card_path]
7
+ delete_path = locals[:delete_path]
8
+ is_leaf = locals[:is_leaf]
7
9
  %>
8
10
 
11
+ <%
12
+ # Hide leading attached-image data URIs (`![](data:image/png;base64,…)`).
13
+ # The base64 blob isn't useful in a 30-char preview — replace each with a
14
+ # short marker so the rest of the prompt text is visible.
15
+ display_prompt = ann.prompt.to_s.gsub(/!\[[^\]]*\]\(data:[^)]+\)/m, "[image]").strip
16
+ %>
9
17
  <div class="history-card<%= ' is-active' if is_active %>" data-history-target="cards" data-uuid="<%= ann.execution_id %>" data-parent-uuid="<%= parent_uuid %>">
10
- <%= link_to card_path.call(ann.execution_id), class: "history-card-link" do %>
11
- <div class="history-card-prompt"><%= truncate(ann.prompt.to_s, length: 30) %></div>
18
+ <div class="history-card-row">
19
+ <%= link_to card_path.call(ann.execution_id), class: "history-card-link" do %>
20
+ <div class="history-card-prompt"><%= truncate(display_prompt, length: 30) %></div>
21
+ <% end %>
22
+ <% if is_leaf && delete_path %>
23
+ <%= button_to delete_path.call(ann.execution_id),
24
+ method: :delete,
25
+ class: "history-card-delete",
26
+ title: "Delete this prompt",
27
+ form: { class: "history-card-delete-form" },
28
+ data: { turbo_confirm: "Delete this prompt? This cannot be undone." } do %>
29
+ <i class="bi bi-trash"></i>
30
+ <% end %>
31
+ <% end %>
12
32
  <% if ann.llm_platform.present? %>
13
- <span class="history-card-platform-label" data-platform="<%= ann.llm_platform %>"><%= { "openai" => "GPT", "anthropic" => "A", "google" => "G", "ollama" => "O" }[ann.llm_platform] || ann.llm_platform %></span>
33
+ <% platform_label = { "openai" => "GPT", "anthropic" => "A", "google" => "G", "ollama" => "O" }[ann.llm_platform] || ann.llm_platform %>
34
+ <% tooltip = ann.model.present? ? "#{ann.model} (#{ann.llm_platform})" : ann.llm_platform.to_s %>
35
+ <span class="history-card-platform-label" data-platform="<%= ann.llm_platform %>" title="<%= tooltip %>"><%= platform_label %></span>
14
36
  <% end %>
15
- <% end %>
37
+ </div>
16
38
  </div>
17
39
 
18
40
  <%# Check !next_ann.nil? to prevent the "↑" arrow from appearing below the bottom history entry, as parent_uuid would be nil in that case. %>
19
41
  <% if !next_ann.nil? && parent_uuid == next_ann.execution_id %>
20
42
  <div class="history-straight-arrow">↑</div>
21
- <% end %>
43
+ <% end %>
@@ -1,7 +1,11 @@
1
1
  module PromptNavigator
2
2
  module Helpers
3
- def history_list(card_path, active_uuid: nil)
4
- render "prompt_navigator/history", locals: { card_path: card_path, active_uuid: active_uuid }
3
+ def history_list(card_path, active_uuid: nil, delete_path: nil)
4
+ render "prompt_navigator/history", locals: {
5
+ card_path: card_path,
6
+ active_uuid: active_uuid,
7
+ delete_path: delete_path
8
+ }
5
9
  end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module PromptNavigator
2
- VERSION = "1.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prompt_navigator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler
@@ -79,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.2.0
82
+ version: 3.4.9
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 4.0.3
89
+ rubygems_version: 3.6.9
90
90
  specification_version: 4
91
91
  summary: A Rails engine for managing and visualizing LLM prompt execution history.
92
92
  test_files: []