prompt_navigator 2.4.0 → 2.5.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 +4 -4
- data/LICENSE +201 -0
- data/README.md +30 -4
- data/app/assets/stylesheets/prompt_navigator/history.css +2 -1
- data/app/javascript/controllers/history_controller.js +68 -12
- data/app/models/prompt_navigator/prompt_execution.rb +76 -0
- data/app/models/prompt_navigator/supplement.rb +28 -0
- data/app/views/prompt_navigator/_history_card.html.erb +11 -1
- data/lib/generators/prompt_navigator/modeling/modeling_generator.rb +5 -0
- data/lib/generators/prompt_navigator/modeling/templates/db/migrate/20260913000000_add_prompt_navigator_supplements.rb +36 -0
- data/lib/prompt_navigator/version.rb +1 -1
- metadata +5 -3
- data/MIT-LICENSE +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8370e951e3f5d39bef43187f1d47b67f57c5c35f01a187bdc4dcc2f75527c59f
|
|
4
|
+
data.tar.gz: a63769916fb05bcaf8274450550ce0729eeb6be287374ef4acc5a79e88cd27b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 941e78cb12e73b0f50118f8ad36f0ea76aff54bc73d678204d43cf8bd9afdd2baafab720593c9599e4ec93320cf8da837a8b706e5cc45c62ddf8f38ad121ca7f
|
|
7
|
+
data.tar.gz: 9c517219db4fa28275e6d59cc5df02d6030e93a33d188de55aae84b7f9cf718c78a97d4fc37a9432781a0054dcc72b906b3a91c08a8aba7abfb6447bfc0459cb
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 DBCLS
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -51,6 +51,28 @@ This creates the `prompt_navigator_prompt_executions` table with the following c
|
|
|
51
51
|
| `response` | text | The LLM response text |
|
|
52
52
|
| `previous_id` | integer | Foreign key to the parent execution (for building history tree) |
|
|
53
53
|
|
|
54
|
+
### Verify installation
|
|
55
|
+
|
|
56
|
+
Run each of these against your host app after `bin/rails db:migrate`:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# a) The prompt_navigator_prompt_executions table was created
|
|
60
|
+
bin/rails runner 'puts ActiveRecord::Base.connection.table_exists?("prompt_navigator_prompt_executions")'
|
|
61
|
+
# → true
|
|
62
|
+
|
|
63
|
+
# b) The history_list view helper is auto-mounted into ActionView
|
|
64
|
+
bin/rails runner 'puts ApplicationController.helpers.respond_to?(:history_list)'
|
|
65
|
+
# → true
|
|
66
|
+
|
|
67
|
+
# c) The HistoryManageable controller concern is auto-included
|
|
68
|
+
bin/rails runner 'puts ApplicationController.include?(PromptNavigator::HistoryManageable)'
|
|
69
|
+
# → true
|
|
70
|
+
|
|
71
|
+
# d) UUIDs are auto-generated on create
|
|
72
|
+
bin/rails runner 'puts PromptNavigator::PromptExecution.new(prompt: "x", llm_platform: "openai", model: "gpt-4", response: "y").tap(&:save).execution_id'
|
|
73
|
+
# → prints a fresh UUID
|
|
74
|
+
```
|
|
75
|
+
|
|
54
76
|
## Usage
|
|
55
77
|
|
|
56
78
|
### Layout Setup
|
|
@@ -228,10 +250,14 @@ Run the linter:
|
|
|
228
250
|
$ bundle exec rubocop
|
|
229
251
|
```
|
|
230
252
|
|
|
231
|
-
##
|
|
253
|
+
## Citation
|
|
254
|
+
|
|
255
|
+
This engine is a component of the AIbranch platform. If you use it in your research, please cite:
|
|
232
256
|
|
|
233
|
-
|
|
257
|
+
> Kim, J.-D. (2026). *AIbranch: A platform for branched multi-model LLM conversations*. *SoftwareX*. <https://doi.org/10.1016/j.softx.2026.102983>
|
|
234
258
|
|
|
235
|
-
##
|
|
259
|
+
## Related repositories
|
|
236
260
|
|
|
237
|
-
|
|
261
|
+
- [`llm_meta_client`](https://github.com/jdkim/llm_meta_client) — the main consumer of this gem
|
|
262
|
+
- [`chat_manager`](https://github.com/jdkim/chat_manager) — used alongside this gem inside `llm_meta_client`
|
|
263
|
+
- [`llm_meta_chat`](https://github.com/jdkim/llm_meta_chat) — a Rails chat application that indirectly uses this gem via `llm_meta_client`
|
|
@@ -7,7 +7,20 @@ export default class extends Controller {
|
|
|
7
7
|
// Private fields
|
|
8
8
|
#drawArrowsBound
|
|
9
9
|
#markerId = "history-arrow-head"
|
|
10
|
+
// Supplement edges get their own marker because the arrowhead is filled,
|
|
11
|
+
// not stroked — a dash pattern alone would leave the head solid grey.
|
|
12
|
+
#supplementMarkerId = "history-supplement-arrow-head"
|
|
13
|
+
#lineageStroke = "#555"
|
|
14
|
+
#supplementStroke = "#7c3aed"
|
|
15
|
+
#supplementDash = "4 3"
|
|
10
16
|
#startX = 32
|
|
17
|
+
// Supplement arcs run down the RIGHT gutter. Sharing the left one with the
|
|
18
|
+
// lineage arrows made both unreadable as soon as a prompt cited more than
|
|
19
|
+
// one node — several arcs of similar length overlapping in 32px. The two
|
|
20
|
+
// channels now have a side each, which also reinforces that they are
|
|
21
|
+
// different kinds of edge. Keep in step with .history-stack's
|
|
22
|
+
// padding-right in history.css.
|
|
23
|
+
#rightMargin = 32
|
|
11
24
|
// Curve offset scales with the vertical gap so arcs of different lengths
|
|
12
25
|
// nest instead of overlap. Bounded so short arcs don't collapse onto the
|
|
13
26
|
// stack and long arcs don't escape the sidebar pane (the stack only has
|
|
@@ -48,11 +61,13 @@ export default class extends Controller {
|
|
|
48
61
|
const cardMap = this.#buildCardMap()
|
|
49
62
|
const bbox = this.#setupSvgDimensions(svg)
|
|
50
63
|
|
|
51
|
-
this.#ensureArrowMarker(svg)
|
|
64
|
+
this.#ensureArrowMarker(svg, this.#markerId, this.#lineageStroke)
|
|
65
|
+
this.#ensureArrowMarker(svg, this.#supplementMarkerId, this.#supplementStroke)
|
|
52
66
|
|
|
53
67
|
// Iterate over Stimulus targets instead of querySelectorAll
|
|
54
68
|
for (const card of this.cardsTargets) {
|
|
55
69
|
this.#drawArrowForCard(card, cardMap, bbox, svg)
|
|
70
|
+
this.#drawSupplementArrows(card, cardMap, bbox, svg)
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
|
|
@@ -76,14 +91,14 @@ export default class extends Controller {
|
|
|
76
91
|
return bbox
|
|
77
92
|
}
|
|
78
93
|
|
|
79
|
-
#ensureArrowMarker(svg) {
|
|
80
|
-
if (svg.querySelector(`#${
|
|
94
|
+
#ensureArrowMarker(svg, id, fill) {
|
|
95
|
+
if (svg.querySelector(`#${id}`)) return
|
|
81
96
|
|
|
82
97
|
const marker = document.createElementNS(
|
|
83
98
|
"http://www.w3.org/2000/svg",
|
|
84
99
|
"marker"
|
|
85
100
|
)
|
|
86
|
-
marker.setAttribute("id",
|
|
101
|
+
marker.setAttribute("id", id)
|
|
87
102
|
marker.setAttribute("markerWidth", "6")
|
|
88
103
|
marker.setAttribute("markerHeight", "6")
|
|
89
104
|
marker.setAttribute("refX", "5")
|
|
@@ -95,12 +110,16 @@ export default class extends Controller {
|
|
|
95
110
|
"path"
|
|
96
111
|
)
|
|
97
112
|
arrowPath.setAttribute("d", "M0,0 L6,3 L0,6 Z")
|
|
98
|
-
arrowPath.setAttribute("fill",
|
|
113
|
+
arrowPath.setAttribute("fill", fill)
|
|
99
114
|
marker.appendChild(arrowPath)
|
|
100
115
|
|
|
101
|
-
|
|
116
|
+
// Reuse one <defs> so the second marker doesn't add a duplicate node.
|
|
117
|
+
let defs = svg.querySelector("defs")
|
|
118
|
+
if (!defs) {
|
|
119
|
+
defs = document.createElementNS("http://www.w3.org/2000/svg", "defs")
|
|
120
|
+
svg.appendChild(defs)
|
|
121
|
+
}
|
|
102
122
|
defs.appendChild(marker)
|
|
103
|
-
svg.appendChild(defs)
|
|
104
123
|
}
|
|
105
124
|
|
|
106
125
|
#drawArrowForCard(card, cardMap, bbox, svg) {
|
|
@@ -124,21 +143,58 @@ export default class extends Controller {
|
|
|
124
143
|
svg.appendChild(path)
|
|
125
144
|
}
|
|
126
145
|
|
|
127
|
-
|
|
128
|
-
|
|
146
|
+
// Supplement edges: nodes whose content is attached to this prompt as
|
|
147
|
+
// reference material rather than entering as dialogue. Drawn dotted and in
|
|
148
|
+
// a distinct colour so the two channels are told apart at a glance.
|
|
149
|
+
//
|
|
150
|
+
// Unlike the lineage arrow above there is NO short-gap bail-out. That
|
|
151
|
+
// shortcut exists because the template draws a straight ↑/↓ between
|
|
152
|
+
// adjacent parent/child cards; nothing does that for supplements, so
|
|
153
|
+
// skipping short gaps would silently drop the arrow entirely.
|
|
154
|
+
#drawSupplementArrows(card, cardMap, bbox, svg) {
|
|
155
|
+
const raw = card.dataset.supplementUuids
|
|
156
|
+
if (!raw) return
|
|
157
|
+
|
|
158
|
+
const childRect = card.getBoundingClientRect()
|
|
159
|
+
const endY = childRect.top + childRect.height / 2 - bbox.top
|
|
160
|
+
|
|
161
|
+
for (const uuid of raw.split(",")) {
|
|
162
|
+
const sourceCard = cardMap.get(uuid.trim())
|
|
163
|
+
if (!sourceCard) continue
|
|
164
|
+
|
|
165
|
+
const sourceRect = sourceCard.getBoundingClientRect()
|
|
166
|
+
const startY = sourceRect.top + sourceRect.height / 2 - bbox.top
|
|
167
|
+
const verticalGap = Math.abs(endY - startY)
|
|
168
|
+
|
|
169
|
+
const path = this.#createCurvedArrowPath(startY, endY, verticalGap, {
|
|
170
|
+
stroke: this.#supplementStroke,
|
|
171
|
+
dash: this.#supplementDash,
|
|
172
|
+
markerId: this.#supplementMarkerId,
|
|
173
|
+
x: bbox.width - this.#rightMargin,
|
|
174
|
+
direction: 1
|
|
175
|
+
})
|
|
176
|
+
svg.appendChild(path)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#createCurvedArrowPath(startY, endY, verticalGap, options = {}) {
|
|
181
|
+
const startX = options.x ?? this.#startX
|
|
182
|
+
// -1 bows outward to the left (lineage), +1 to the right (supplements).
|
|
183
|
+
const direction = options.direction ?? -1
|
|
129
184
|
const curveOffset = Math.max(
|
|
130
185
|
this.#minCurveOffset,
|
|
131
186
|
Math.min(verticalGap * this.#curveScale, this.#maxCurveOffset)
|
|
132
187
|
)
|
|
133
|
-
const curveX = startX
|
|
188
|
+
const curveX = startX + direction * curveOffset
|
|
134
189
|
const pathData = `M ${startX} ${startY} C ${curveX} ${startY}, ${curveX} ${endY}, ${startX} ${endY}`
|
|
135
190
|
|
|
136
191
|
const path = document.createElementNS("http://www.w3.org/2000/svg", "path")
|
|
137
192
|
path.setAttribute("d", pathData)
|
|
138
193
|
path.setAttribute("fill", "none")
|
|
139
|
-
path.setAttribute("stroke",
|
|
194
|
+
path.setAttribute("stroke", options.stroke || this.#lineageStroke)
|
|
140
195
|
path.setAttribute("stroke-width", "1.2")
|
|
141
|
-
path.setAttribute("
|
|
196
|
+
if (options.dash) path.setAttribute("stroke-dasharray", options.dash)
|
|
197
|
+
path.setAttribute("marker-end", `url(#${options.markerId || this.#markerId})`)
|
|
142
198
|
|
|
143
199
|
return path
|
|
144
200
|
}
|
|
@@ -2,6 +2,21 @@ module PromptNavigator
|
|
|
2
2
|
class PromptExecution < ApplicationRecord
|
|
3
3
|
belongs_to :previous, class_name: "PromptNavigator::PromptExecution", optional: true
|
|
4
4
|
|
|
5
|
+
# Reference edges this prompt carries. `supplements` are the executions
|
|
6
|
+
# cited; `cited_by` is the reverse, needed so deleting a cited node can
|
|
7
|
+
# clean up the edges pointing at it.
|
|
8
|
+
has_many :supplement_links, -> { order(:position) },
|
|
9
|
+
class_name: "PromptNavigator::Supplement",
|
|
10
|
+
foreign_key: :prompt_execution_id,
|
|
11
|
+
inverse_of: :prompt_execution,
|
|
12
|
+
dependent: :delete_all
|
|
13
|
+
has_many :supplements, through: :supplement_links, source: :supplement_execution
|
|
14
|
+
has_many :citation_links,
|
|
15
|
+
class_name: "PromptNavigator::Supplement",
|
|
16
|
+
foreign_key: :supplement_execution_id,
|
|
17
|
+
inverse_of: :supplement_execution,
|
|
18
|
+
dependent: :delete_all
|
|
19
|
+
|
|
5
20
|
before_create :set_execution_id
|
|
6
21
|
|
|
7
22
|
# Builds a context array from the direct lineage for summarization.
|
|
@@ -13,6 +28,11 @@ module PromptNavigator
|
|
|
13
28
|
end
|
|
14
29
|
end
|
|
15
30
|
|
|
31
|
+
# Delete PromptExecutions safely — use this for a single row too, not only
|
|
32
|
+
# for a set. `#delete` and `#delete_all` bypass callbacks, so `dependent:`
|
|
33
|
+
# never fires and the supplement edges (a second self-referential FK into
|
|
34
|
+
# this table) survive, making the delete fail with InvalidForeignKey.
|
|
35
|
+
#
|
|
16
36
|
# Bulk-delete a set of PromptExecutions, tolerating the self-referential
|
|
17
37
|
# `previous_id` foreign key by first nulling intra-set links. Callers
|
|
18
38
|
# (e.g. a host's Chat#destroy flow) pass the ids of orphaned executions
|
|
@@ -25,10 +45,66 @@ module PromptNavigator
|
|
|
25
45
|
ids = Array(ids).compact
|
|
26
46
|
return if ids.empty?
|
|
27
47
|
|
|
48
|
+
# Supplement edges are a second self-referential FK into this table, in
|
|
49
|
+
# both directions. `delete_all` bypasses callbacks, so `dependent:` never
|
|
50
|
+
# fires here and the rows have to go first — otherwise deleting a chat
|
|
51
|
+
# that used supplements raises InvalidForeignKey, which is exactly the
|
|
52
|
+
# failure this method exists to prevent.
|
|
53
|
+
#
|
|
54
|
+
# Both directions go unconditionally, including citations made from
|
|
55
|
+
# *outside* the set. That is deliberately unlike the `previous_id`
|
|
56
|
+
# handling below, which only unlinks within the set and lets an outside
|
|
57
|
+
# reference raise so the host can decide. The difference is that a
|
|
58
|
+
# citation is a soft reference — losing it degrades one turn's context —
|
|
59
|
+
# whereas a dangling previous_id would corrupt the lineage itself. It
|
|
60
|
+
# also keeps a per-card delete of a cited leaf from failing with an
|
|
61
|
+
# opaque FK error.
|
|
62
|
+
Supplement.where(prompt_execution_id: ids).delete_all
|
|
63
|
+
Supplement.where(supplement_execution_id: ids).delete_all
|
|
64
|
+
|
|
28
65
|
where(id: ids).update_all(previous_id: nil)
|
|
29
66
|
where(id: ids).delete_all
|
|
30
67
|
end
|
|
31
68
|
|
|
69
|
+
# Referenced material, grouped by identical prompt text.
|
|
70
|
+
#
|
|
71
|
+
# Supplements reach the model as *system context*, not as dialogue — that
|
|
72
|
+
# is the whole meaning of the dotted arrow the history pane draws for them,
|
|
73
|
+
# as against the solid arrow for the lineage that enters as conversation.
|
|
74
|
+
# What the user wants done with the material (compare it, merge it, weigh
|
|
75
|
+
# it) is said in the prompt itself and deliberately not modelled here:
|
|
76
|
+
# intent is language, not schema.
|
|
77
|
+
#
|
|
78
|
+
# The common case is the same question put to several models — which the
|
|
79
|
+
# Start node makes easy to produce — and repeating that question once per
|
|
80
|
+
# model would both waste tokens and read as though the user had asked it
|
|
81
|
+
# several times. Grouping collapses it to one question with N answers
|
|
82
|
+
# labelled by model, which is also what lets a prompt refer to them in
|
|
83
|
+
# words. A group of one renders as an ordinary question/answer pair, so
|
|
84
|
+
# callers need no special case.
|
|
85
|
+
#
|
|
86
|
+
# Returns [{ prompt:, answers: [{ response:, model:, llm_platform: }, ...] }]
|
|
87
|
+
# in selection order, the group taking the position of its first member.
|
|
88
|
+
def supplement_groups
|
|
89
|
+
self.class.group_supplements(supplements)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# The same grouping over an arbitrary list of executions, for callers that
|
|
93
|
+
# do not have a saved prompt to read edges from — a composer previewing
|
|
94
|
+
# what a *pending* selection would send, for instance. Sharing this with
|
|
95
|
+
# the instance method above is the point: a preview that computed its own
|
|
96
|
+
# grouping could drift from what actually gets sent.
|
|
97
|
+
def self.group_supplements(nodes)
|
|
98
|
+
Array(nodes).group_by { |pe| pe.prompt.to_s }.map do |prompt_text, group|
|
|
99
|
+
{
|
|
100
|
+
prompt: prompt_text,
|
|
101
|
+
answers: group.map do |pe|
|
|
102
|
+
{ response: pe.response, model: pe.model, llm_platform: pe.llm_platform }
|
|
103
|
+
end
|
|
104
|
+
}
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
32
108
|
private
|
|
33
109
|
|
|
34
110
|
# Returns ancestor PromptExecutions in chronological order (oldest first),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module PromptNavigator
|
|
2
|
+
# A reference edge: `prompt_execution` cites `supplement_execution`, whose
|
|
3
|
+
# content is injected as reference material for that one turn.
|
|
4
|
+
#
|
|
5
|
+
# Kept as a join model rather than a column on PromptExecution because a
|
|
6
|
+
# prompt may cite several nodes, and because the edge carries its own
|
|
7
|
+
# ordering.
|
|
8
|
+
class Supplement < ApplicationRecord
|
|
9
|
+
belongs_to :prompt_execution,
|
|
10
|
+
class_name: "PromptNavigator::PromptExecution"
|
|
11
|
+
belongs_to :supplement_execution,
|
|
12
|
+
class_name: "PromptNavigator::PromptExecution"
|
|
13
|
+
|
|
14
|
+
validate :cannot_reference_itself
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
# A prompt citing itself would duplicate its own text into its own
|
|
19
|
+
# reference block. Nothing in the UI offers it, but the edge is cheap to
|
|
20
|
+
# forbid and expensive to debug.
|
|
21
|
+
def cannot_reference_itself
|
|
22
|
+
return if prompt_execution_id.nil?
|
|
23
|
+
return unless prompt_execution_id == supplement_execution_id
|
|
24
|
+
|
|
25
|
+
errors.add(:supplement_execution, "cannot be the prompt itself")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -17,7 +17,17 @@
|
|
|
17
17
|
.strip
|
|
18
18
|
%>
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
<%
|
|
21
|
+
# Nodes this prompt cites. Their content reaches the model as material for
|
|
22
|
+
# this turn, not as dialogue — which is what the dotted arrow means, as
|
|
23
|
+
# against the solid one for the lineage.
|
|
24
|
+
#
|
|
25
|
+
# This reads an association per card. Hosts rendering a long pane should
|
|
26
|
+
# preload it (`includes(:supplements)`); chains are short enough that the
|
|
27
|
+
# gem does not force the issue, same reasoning as `ancestors`.
|
|
28
|
+
supplement_uuids = ann.respond_to?(:supplements) ? ann.supplements.map(&:execution_id) : []
|
|
29
|
+
%>
|
|
30
|
+
<div class="history-card<%= ' is-active' if is_active %>" data-history-target="cards" data-uuid="<%= ann.execution_id %>" data-parent-uuid="<%= parent_uuid %>" data-supplement-uuids="<%= supplement_uuids.join(",") %>">
|
|
21
31
|
<div class="history-card-row">
|
|
22
32
|
<%= link_to card_path.call(ann.execution_id), class: "history-card-link" do %>
|
|
23
33
|
<div class="history-card-prompt"><%= truncate(display_prompt, length: 30) %></div>
|
|
@@ -11,8 +11,13 @@ module PromptNavigator
|
|
|
11
11
|
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
# Each template is copied separately and renumbered, so a host that
|
|
15
|
+
# already ran an earlier one picks up only what it is missing. Existing
|
|
16
|
+
# migrations are never edited in place for that reason — hosts have
|
|
17
|
+
# already run them.
|
|
14
18
|
def add_migrations
|
|
15
19
|
migration_template "db/migrate/20260129073026_create_prompt_navigator_prompt_executions.rb", "db/migrate/create_prompt_navigator_prompt_executions.rb"
|
|
20
|
+
migration_template "db/migrate/20260913000000_add_prompt_navigator_supplements.rb", "db/migrate/add_prompt_navigator_supplements.rb"
|
|
16
21
|
end
|
|
17
22
|
end
|
|
18
23
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Supplement edges: a prompt may reference other executions whose content is
|
|
2
|
+
# injected as reference material for that one turn.
|
|
3
|
+
#
|
|
4
|
+
# The primary chain (`previous_id`) is deliberately untouched. It stays exactly
|
|
5
|
+
# one parent, because history serialization walks it and must stay
|
|
6
|
+
# deterministic — these edges add a DAG for *context* while the *structure*
|
|
7
|
+
# remains a tree.
|
|
8
|
+
#
|
|
9
|
+
# Nothing here records what the user meant to do with the references
|
|
10
|
+
# (compare them, merge them, weigh them). That is said in the prompt itself.
|
|
11
|
+
# The edge means one thing only: this content is available to that turn.
|
|
12
|
+
class AddPromptNavigatorSupplements < ActiveRecord::Migration[8.1]
|
|
13
|
+
def change
|
|
14
|
+
create_table :prompt_navigator_supplements do |t|
|
|
15
|
+
# The prompt that carries the references.
|
|
16
|
+
t.references :prompt_execution,
|
|
17
|
+
foreign_key: { to_table: :prompt_navigator_prompt_executions },
|
|
18
|
+
null: false, index: { name: "idx_pn_supplements_on_execution" }
|
|
19
|
+
# The execution being referenced.
|
|
20
|
+
t.references :supplement_execution,
|
|
21
|
+
foreign_key: { to_table: :prompt_navigator_prompt_executions },
|
|
22
|
+
null: false, index: { name: "idx_pn_supplements_on_supplement" }
|
|
23
|
+
# Selection order, so the injected material reads back in the order the
|
|
24
|
+
# user picked rather than by insertion id.
|
|
25
|
+
t.integer :position, null: false, default: 0
|
|
26
|
+
|
|
27
|
+
t.timestamps
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Explicit names throughout: the generated ones would exceed Postgres's
|
|
31
|
+
# 63-character identifier limit and be silently truncated.
|
|
32
|
+
add_index :prompt_navigator_supplements,
|
|
33
|
+
[ :prompt_execution_id, :supplement_execution_id ],
|
|
34
|
+
unique: true, name: "idx_pn_supplements_pair"
|
|
35
|
+
end
|
|
36
|
+
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: 2.
|
|
4
|
+
version: 2.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dhq_boiler
|
|
@@ -39,7 +39,7 @@ executables: []
|
|
|
39
39
|
extensions: []
|
|
40
40
|
extra_rdoc_files: []
|
|
41
41
|
files:
|
|
42
|
-
-
|
|
42
|
+
- LICENSE
|
|
43
43
|
- README.md
|
|
44
44
|
- Rakefile
|
|
45
45
|
- app/assets/config/prompt_navigator_manifest.js
|
|
@@ -53,12 +53,14 @@ files:
|
|
|
53
53
|
- app/mailers/prompt_navigator/application_mailer.rb
|
|
54
54
|
- app/models/prompt_navigator/application_record.rb
|
|
55
55
|
- app/models/prompt_navigator/prompt_execution.rb
|
|
56
|
+
- app/models/prompt_navigator/supplement.rb
|
|
56
57
|
- app/views/layouts/prompt_navigator/application.html.erb
|
|
57
58
|
- app/views/prompt_navigator/_history.html.erb
|
|
58
59
|
- app/views/prompt_navigator/_history_card.html.erb
|
|
59
60
|
- config/routes.rb
|
|
60
61
|
- lib/generators/prompt_navigator/modeling/modeling_generator.rb
|
|
61
62
|
- lib/generators/prompt_navigator/modeling/templates/db/migrate/20260129073026_create_prompt_navigator_prompt_executions.rb
|
|
63
|
+
- lib/generators/prompt_navigator/modeling/templates/db/migrate/20260913000000_add_prompt_navigator_supplements.rb
|
|
62
64
|
- lib/prompt_navigator.rb
|
|
63
65
|
- lib/prompt_navigator/configuration.rb
|
|
64
66
|
- lib/prompt_navigator/engine.rb
|
|
@@ -67,7 +69,7 @@ files:
|
|
|
67
69
|
- lib/tasks/prompt_navigator_tasks.rake
|
|
68
70
|
homepage: https://github.com/jdkim/prompt_manager
|
|
69
71
|
licenses:
|
|
70
|
-
-
|
|
72
|
+
- Apache-2.0
|
|
71
73
|
metadata:
|
|
72
74
|
allowed_push_host: https://rubygems.org
|
|
73
75
|
homepage_uri: https://github.com/jdkim/prompt_manager
|
data/MIT-LICENSE
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright dhq_boiler
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|