samagotchi 0.162.0 → 0.163.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/CHANGELOG.md +17 -1
- data/docs/architecture.md +1 -1
- data/docs/cli.md +1 -1
- data/docs/configuration.md +1 -1
- data/docs/internals/bridge.md +37 -24
- data/docs/internals/web-frontend.md +1 -1
- data/docs/memory.md +8 -2
- data/docs/testing.md +8 -2
- data/lib/samagotchi/bridge/turn_drawings/synth.rb +7 -3
- data/lib/samagotchi/bridge/turn_drawings.rb +45 -30
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/project_command.rb +74 -6
- data/lib/samagotchi/project_subfolders.rb +188 -0
- data/lib/samagotchi/terminal_ui/join_replay.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/message_display.rb +53 -36
- data/lib/samagotchi/web/public/app.js +8 -7
- data/lib/samagotchi/web/public/data.js +4 -6
- data/lib/samagotchi/web/public/reload_check.js +7 -4
- data/lib/samagotchi/web/public/time_gaps.js +1 -2
- data/lib/samagotchi/web/public/timing.js +49 -224
- data/lib/samagotchi/web/public/turn_block.js +40 -122
- data/lib/samagotchi/web/public/turn_html.js +3 -2
- data/lib/samagotchi/web/reload_check_route.rb +6 -3
- data/lib/samagotchi/web/session_show.rb +8 -24
- metadata +2 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require_relative "guardrails/path_resolve"
|
|
5
|
+
require_relative "memory_paths"
|
|
6
|
+
require_relative "paths"
|
|
7
|
+
|
|
8
|
+
module Samagotchi
|
|
9
|
+
# Memories saved from a subfolder of a marked project before
|
|
10
|
+
# `chi project init`: a session there keyed them by its own path
|
|
11
|
+
# (MemoryPaths.lookup was :none, the root its cwd), and after init the
|
|
12
|
+
# subfolder resolves to the project, so that folder is out of reach.
|
|
13
|
+
#
|
|
14
|
+
# A path key can't be reversed, so the candidates come only from this
|
|
15
|
+
# machine's session rows (each stores the root it keyed by: a project-less
|
|
16
|
+
# session's is its cwd); memories older than the sessions kept are not
|
|
17
|
+
# found (docs/memory.md: move them by hand). No directory walk: one
|
|
18
|
+
# listing of the sessions, one stat per row. Memories only: a subfolder's
|
|
19
|
+
# project context sources and skills history stay where they are.
|
|
20
|
+
#
|
|
21
|
+
# The one text for the condition is #message (`chi project init`'s report
|
|
22
|
+
# and `chi project`'s note); #merge (`chi project init --merge-subfolders`)
|
|
23
|
+
# moves them, #running_message refuses while a session could write.
|
|
24
|
+
module ProjectSubfolders
|
|
25
|
+
# +path+: the subfolder a session keyed its memories by; +dir+: that
|
|
26
|
+
# memories folder; +count+: the memories in it.
|
|
27
|
+
Found = Data.define(:path, :dir, :count)
|
|
28
|
+
|
|
29
|
+
FLAG = "--merge-subfolders"
|
|
30
|
+
INDEX = "index.md"
|
|
31
|
+
# What an emptied folder may still hold, none of it moved: the index
|
|
32
|
+
# (removed only when #hand_written? says it holds nothing of the user's),
|
|
33
|
+
# IndexUpdater's lock, and .root: ProjectIdClash's claim, written only in
|
|
34
|
+
# an id folder, so in a path-keyed one it is a copy's stray (a copied
|
|
35
|
+
# id folder renamed by hand) that names no folder this key belongs to.
|
|
36
|
+
LEFTOVERS = [INDEX, ".index.lock", ".root"].freeze
|
|
37
|
+
|
|
38
|
+
module_function
|
|
39
|
+
|
|
40
|
+
# The subfolders of +root+ (a marked project's realpath) whose
|
|
41
|
+
# path-keyed memories folder exists: a row's stored root under +root+
|
|
42
|
+
# that resolves to +root+ now (a nested git repository or marked folder
|
|
43
|
+
# is its own project; a symlink out of +root+ resolves elsewhere).
|
|
44
|
+
# @param sessions [Array<SessionRow>] this machine's sessions (+project+, +cwd+)
|
|
45
|
+
# @return [Array<Found>] sorted by path
|
|
46
|
+
def find(root, sessions:, env: ENV, home: MemoryPaths.default_home)
|
|
47
|
+
projects = MemoryPaths.projects_dir(env: env)
|
|
48
|
+
seen = {}
|
|
49
|
+
Array(sessions).each do |row|
|
|
50
|
+
path = (row.project || row.cwd).to_s
|
|
51
|
+
next if path.empty? || seen.key?(path)
|
|
52
|
+
|
|
53
|
+
seen[path] = nil
|
|
54
|
+
real = Guardrails::PathResolve.real(path)
|
|
55
|
+
next if real == root || !Guardrails::PathResolve.under?(real, root)
|
|
56
|
+
next unless MemoryPaths.lookup(path, home: home).root == root
|
|
57
|
+
|
|
58
|
+
dir = File.join(projects, MemoryPaths.key_for_root(path))
|
|
59
|
+
next unless File.directory?(dir) && !File.symlink?(dir)
|
|
60
|
+
|
|
61
|
+
count = entries(dir).size
|
|
62
|
+
seen[path] = Found.new(path: path, dir: dir, count: count) if count.positive?
|
|
63
|
+
end
|
|
64
|
+
seen.values.compact.uniq(&:dir).sort_by(&:path)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The one text for found subfolder memories, or nil for none.
|
|
68
|
+
def message(found)
|
|
69
|
+
return nil if found.empty?
|
|
70
|
+
|
|
71
|
+
list = found.map { |item| "#{Paths.tilde(item.path)} (#{item.count} #{item.count == 1 ? "memory" : "memories"})" }
|
|
72
|
+
"memories saved from subfolders before init: #{list.join(", ")}; move them into the project with " \
|
|
73
|
+
"chi project init #{FLAG}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# The running sessions that refuse a merge: under +root+ by the root
|
|
77
|
+
# they stored or by their folder (a live pre-init session stored its cwd).
|
|
78
|
+
def running(root, sessions:, home: MemoryPaths.default_home)
|
|
79
|
+
Array(sessions).select do |row|
|
|
80
|
+
next false unless row.live
|
|
81
|
+
|
|
82
|
+
[row.project, row.cwd].compact.map(&:to_s).reject(&:empty?).any? do |path|
|
|
83
|
+
Guardrails::PathResolve.under?(Guardrails::PathResolve.real(path), root) ||
|
|
84
|
+
MemoryPaths.lookup(path, home: home).root == root
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def running_message(root, rows)
|
|
90
|
+
"#{Paths.tilde(root)} has running sessions (#{rows.map { |row| row.id[0, 8] }.join(", ")}): stop them " \
|
|
91
|
+
"(chi sessions stop ID) and rerun chi project init #{FLAG}, which moves the subfolders' memories while " \
|
|
92
|
+
"no session can write to them"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Moves each found folder's memories (the file, its model overlays,
|
|
96
|
+
# its index line) into +target+ (the project's memories folder). One
|
|
97
|
+
# the project has by that name, or a bundle owns, stays and is named;
|
|
98
|
+
# an emptied folder is removed, with no link: every chi that knows
|
|
99
|
+
# markers resolves the subfolder to the project, and a link would hide
|
|
100
|
+
# a folder made there again from #find.
|
|
101
|
+
# @return [Array<String>] the report's lines
|
|
102
|
+
def merge(found, target:, env: ENV)
|
|
103
|
+
require_relative "memory_bundle/index_updater"
|
|
104
|
+
require_relative "memory_bundle/provenance"
|
|
105
|
+
require_relative "tools/memory"
|
|
106
|
+
lines = []
|
|
107
|
+
found.each { |item| lines.concat(merge_one(item, target, env)) }
|
|
108
|
+
lines << "no memories saved from subfolders before init to move" if lines.empty?
|
|
109
|
+
lines
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# The entries of a memories folder: each <name>.md but the index and
|
|
113
|
+
# the model overlays of another entry (Tools::MemoryWrite.overlay_files),
|
|
114
|
+
# with its managed index line (or nil).
|
|
115
|
+
# @return [Hash{String => String, nil}] name → line
|
|
116
|
+
def entries(dir)
|
|
117
|
+
index_text = index_text(dir)
|
|
118
|
+
names = Dir.children(dir).select { |name| name.end_with?(".md") && name != INDEX && File.file?(File.join(dir, name)) }
|
|
119
|
+
.map { |name| name.delete_suffix(".md") }.sort
|
|
120
|
+
require_relative "tools/memory"
|
|
121
|
+
overlays = names.flat_map { |name| Tools::MemoryWrite.overlay_files(dir, name, index_text) }
|
|
122
|
+
.map { |path| File.basename(path, ".md") }
|
|
123
|
+
(names - overlays).to_h { |name| [name, index_text[Tools::MemoryWrite.managed_pattern(name)]&.chomp] }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def index_text(dir)
|
|
127
|
+
path = File.join(dir, INDEX)
|
|
128
|
+
File.file?(path) ? File.read(path, encoding: "UTF-8") : ""
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def merge_one(item, target, env)
|
|
132
|
+
from = item.dir
|
|
133
|
+
index_text = index_text(from)
|
|
134
|
+
moved = []
|
|
135
|
+
kept = []
|
|
136
|
+
entries(from).each do |name, line|
|
|
137
|
+
files = [File.join(from, "#{name}.md")] + Tools::MemoryWrite.overlay_files(from, name, index_text)
|
|
138
|
+
owner = MemoryBundle::Provenance.claimants("#{name}.md", scope: "project",
|
|
139
|
+
dir: MemoryPaths.bundles_dir(env: env)).first ||
|
|
140
|
+
(line && MemoryBundle::IndexUpdater.extract_source(line))
|
|
141
|
+
next kept << "#{name} (from bundle #{owner})" if owner
|
|
142
|
+
next kept << "#{name} (the project has one by that name)" if files.any? { |path| File.exist?(File.join(target, File.basename(path))) }
|
|
143
|
+
|
|
144
|
+
FileUtils.mkdir_p(target)
|
|
145
|
+
bytes = File.size(files.first)
|
|
146
|
+
files.each { |path| File.rename(path, File.join(target, File.basename(path))) }
|
|
147
|
+
description = line && MemoryBundle::IndexUpdater.extract_description(line)
|
|
148
|
+
MemoryBundle::IndexUpdater.update_index("project", name, bytes, description, target_dir: target)
|
|
149
|
+
MemoryBundle::IndexUpdater.remove_index("project", name, target_dir: from)
|
|
150
|
+
moved << name
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
lines = []
|
|
154
|
+
unless moved.empty?
|
|
155
|
+
lines << "moved #{moved.size} #{moved.size == 1 ? "memory" : "memories"} saved from " \
|
|
156
|
+
"#{Paths.tilde(item.path)} into #{Paths.tilde(target)}: #{moved.join(", ")}"
|
|
157
|
+
end
|
|
158
|
+
lines << "kept in #{Paths.tilde(from)}: #{kept.join(", ")}" unless kept.empty?
|
|
159
|
+
rest = Dir.children(from) - LEFTOVERS
|
|
160
|
+
if rest.empty? && hand_written?(index_text(from))
|
|
161
|
+
lines << "#{Paths.tilde(from)} keeps its index.md: it has lines written by hand"
|
|
162
|
+
elsif rest.empty?
|
|
163
|
+
FileUtils.rm_rf(from)
|
|
164
|
+
lines << "removed the emptied #{Paths.tilde(from)}"
|
|
165
|
+
else
|
|
166
|
+
left = index_text(from)
|
|
167
|
+
memory_files = entries(from).keys.flat_map do |name|
|
|
168
|
+
["#{name}.md"] + Tools::MemoryWrite.overlay_files(from, name, left).map { |path| File.basename(path) }
|
|
169
|
+
end
|
|
170
|
+
others = (rest - memory_files).sort
|
|
171
|
+
lines << "#{Paths.tilde(from)} keeps files that aren't memories: #{others.join(", ")}" unless others.empty?
|
|
172
|
+
end
|
|
173
|
+
lines
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Whether an index holds a line that isn't the auto header, blank or a
|
|
177
|
+
# managed line (memory_write keeps every other line byte for byte; a
|
|
178
|
+
# dangling managed line, its file gone, may go with the folder).
|
|
179
|
+
def hand_written?(text)
|
|
180
|
+
header = MemoryBundle::IndexUpdater.auto_index_header.lines.map(&:strip)
|
|
181
|
+
text.each_line.any? do |line|
|
|
182
|
+
line = line.strip
|
|
183
|
+
!(line.empty? || header.include?(line) || line.match?(/\A- \*\*[^*]+\*\*[ \t]*(?:[·•].*|:.*)?\z/))
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
private_class_method :index_text, :merge_one, :hand_written?
|
|
187
|
+
end
|
|
188
|
+
end
|
|
@@ -146,8 +146,8 @@ module Samagotchi
|
|
|
146
146
|
|
|
147
147
|
# The snapshot's drawing as [turn, end event] when it is +prompt+'s
|
|
148
148
|
# turn (a Continue's or a reminder's drawing isn't the prompt's: the
|
|
149
|
-
#
|
|
150
|
-
# list of rows.
|
|
149
|
+
# prompt's turn is made from its messages, #made_turn), else nil; nil
|
|
150
|
+
# too for one whose parts aren't a list of rows.
|
|
151
151
|
def drawn_turn(drawing, prompt)
|
|
152
152
|
return nil unless drawing.is_a?(Hash) && drawing[:drawing].is_a?(Hash) && drawing[:end].is_a?(Hash)
|
|
153
153
|
|
data/lib/samagotchi/version.rb
CHANGED
|
@@ -90,27 +90,31 @@ module Samagotchi
|
|
|
90
90
|
|
|
91
91
|
# @param msgs [Array<Hash>] a session's messages; symbol keys from disk,
|
|
92
92
|
# string keys from a Bridge snapshot
|
|
93
|
-
# @param parts [Boolean] the
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
93
|
+
# @param parts [Boolean] the participant review's: each assistant
|
|
94
|
+
# message also carries what it did (MessageParts: thinking, tool
|
|
95
|
+
# calls with params and output), and a message with nothing to show
|
|
96
|
+
# but that (a text-less step) is kept with empty content
|
|
97
97
|
# @param cwd [String, nil] the session's working directory (the parts'
|
|
98
98
|
# tool titles are relative to it)
|
|
99
99
|
# @param markdown [Boolean] false: no html for a delegate report or an
|
|
100
100
|
# answer (the participant review drops both and renders its replies
|
|
101
101
|
# from their redacted text, ParticipantReview#with_reply_html)
|
|
102
|
-
# @param drawings [Array<Bridge::TurnDrawings::Line
|
|
103
|
-
# (TurnDrawings.
|
|
104
|
-
# draws (#drawn_kind?) from a line's range gets
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
|
|
102
|
+
# @param drawings [Array<Bridge::TurnDrawings::Line>, nil] the owner
|
|
103
|
+
# show's lines (TurnDrawings.cover against +msgs+): each item of a
|
|
104
|
+
# kind a drawing draws (#drawn_kind?) from a line's range gets
|
|
105
|
+
# `drawn: <turn_id>`, a step its outputs' ✂ marks as `marks:
|
|
106
|
+
# {tool_id => edit}` (an overlay on the drawing's rows), and a
|
|
107
|
+
# text-less step stays (empty content: its marks, the turn's last
|
|
108
|
+
# step); nil: no stamps (the participant review, a lone answer)
|
|
109
|
+
def messages_for_display(msgs, parts: false, cwd: nil, markdown: true, drawings: nil)
|
|
108
110
|
filtered = []
|
|
109
111
|
list = Array(msgs)
|
|
112
|
+
steps = !drawings.nil?
|
|
110
113
|
# Each item's message index, for the drawings' stamps.
|
|
111
114
|
origins = []
|
|
112
|
-
# The outputs' ✂ marks (LLM context edits), by id, for the parts
|
|
113
|
-
|
|
115
|
+
# The outputs' ✂ marks (LLM context edits), by id, for the parts
|
|
116
|
+
# and the drawn steps.
|
|
117
|
+
marks = parts || steps ? MessageParts.edit_marks(list) : {}
|
|
114
118
|
# The list before each objectives note, for what its entry says changed.
|
|
115
119
|
objectives = nil
|
|
116
120
|
list.each_with_index do |m, index|
|
|
@@ -145,7 +149,7 @@ module Samagotchi
|
|
|
145
149
|
# empty steps (with ?parts=1) and the item the page draws its
|
|
146
150
|
# notice from; the note itself stays hidden.
|
|
147
151
|
if (marker = Samagotchi::TurnNote.empty_answer(m))
|
|
148
|
-
filtered.concat(empty_answer_items(marker, parts: parts, cwd: cwd))
|
|
152
|
+
filtered.concat(empty_answer_items(marker, parts: parts, steps: steps, cwd: cwd))
|
|
149
153
|
next
|
|
150
154
|
end
|
|
151
155
|
next if role == "system"
|
|
@@ -155,8 +159,9 @@ module Samagotchi
|
|
|
155
159
|
next if Samagotchi::Steer.recovery?(m)
|
|
156
160
|
|
|
157
161
|
stripped = Samagotchi::OutputFormatter.strip_markup(content)
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
step = %w[model assistant].include?(role)
|
|
163
|
+
did = parts && step ? message_parts(list, index, cwd, marks) : nil
|
|
164
|
+
next if stripped.empty? && did.nil? && !(steps && step && did_something?(m, content))
|
|
160
165
|
|
|
161
166
|
norm_role = role == "model" ? "assistant" : role
|
|
162
167
|
# normalize assistant vs model, keep user as is
|
|
@@ -219,31 +224,52 @@ module Samagotchi
|
|
|
219
224
|
message[:display_refs] = refs unless refs.empty?
|
|
220
225
|
end
|
|
221
226
|
message[:parts] = did if did
|
|
227
|
+
step_marks = steps && step ? output_marks(list, index, cwd, marks) : {}
|
|
228
|
+
message[:marks] = step_marks unless step_marks.empty?
|
|
222
229
|
filtered << message
|
|
223
230
|
end
|
|
224
231
|
origins.fill(list.size - 1, origins.size...filtered.size)
|
|
225
|
-
stamp_drawn(filtered, origins, Array(drawings)
|
|
232
|
+
stamp_drawn(filtered, origins, Array(drawings))
|
|
226
233
|
rescue StandardError
|
|
227
234
|
[]
|
|
228
235
|
end
|
|
229
236
|
|
|
237
|
+
# Whether a text-less model message did something a drawing draws as
|
|
238
|
+
# a step: a call or thinking (MessageParts' own read, without
|
|
239
|
+
# parsing the calls).
|
|
240
|
+
def did_something?(message, content)
|
|
241
|
+
calls = message[:tool_calls] || message["tool_calls"]
|
|
242
|
+
(calls.is_a?(Array) && !calls.empty?) || !content.strip.empty? || !(message[:thinking] || message["thinking"]).to_s.strip.empty?
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# The ✂ marks of the outputs right after the model message at +index+,
|
|
246
|
+
# by output id, as its parts have them (a stub's size from its own
|
|
247
|
+
# output): its parts are read only when +marks+ (the session's, by
|
|
248
|
+
# output id) names one of them.
|
|
249
|
+
def output_marks(list, index, cwd, marks)
|
|
250
|
+
return {} if marks.empty?
|
|
251
|
+
|
|
252
|
+
responses = list.drop(index + 1).take_while { |r| (r[:role] || r["role"]).to_s == "tool_response" }
|
|
253
|
+
return {} unless responses.any? { |r| Array(r[:tool_ids] || r["tool_ids"]).any? { |id| marks.key?(id.to_s) } }
|
|
254
|
+
|
|
255
|
+
tools = Array(message_parts(list, index, cwd, marks)&.dig(:tools))
|
|
256
|
+
tools.filter_map { |tool| [tool[:tool_id], tool[:edit]] if tool[:tool_id] && tool[:edit] }.to_h
|
|
257
|
+
end
|
|
258
|
+
|
|
230
259
|
# +items+ with a drawn turn's stamp on each item of a kind its drawing
|
|
231
260
|
# draws (the opening, steps, steers, merged lines, the empty answer):
|
|
232
261
|
# a context note, a `!cmd`'s record and anything else keep today's
|
|
233
262
|
# place. +origins+: each item's message index.
|
|
234
263
|
# One walk: +drawings+ are sorted apart by range, +origins+ never go
|
|
235
264
|
# back.
|
|
236
|
-
def stamp_drawn(items, origins, drawings
|
|
265
|
+
def stamp_drawn(items, origins, drawings)
|
|
237
266
|
return items if drawings.empty?
|
|
238
267
|
|
|
239
268
|
at = 0
|
|
240
269
|
items.each_with_index.map do |item, i|
|
|
241
270
|
at += 1 while at < drawings.size && drawings[at].to <= origins[i]
|
|
242
271
|
line = drawings[at] if at < drawings.size && drawings[at].range.cover?(origins[i])
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
stamped = item.merge(drawn: line.turn_id)
|
|
246
|
-
strip ? without_parts(stamped) : stamped
|
|
272
|
+
line && drawn_kind?(item) ? item.merge(drawn: line.turn_id) : item
|
|
247
273
|
end
|
|
248
274
|
end
|
|
249
275
|
|
|
@@ -255,15 +281,6 @@ module Samagotchi
|
|
|
255
281
|
end
|
|
256
282
|
end
|
|
257
283
|
|
|
258
|
-
# A drawn item without its parts: its ✂ marks by output id stay (an
|
|
259
|
-
# overlay on the drawing's rows: later state, as a card's latest body).
|
|
260
|
-
def without_parts(item)
|
|
261
|
-
tools = Array(item.dig(:parts, :tools))
|
|
262
|
-
marks = tools.filter_map { |tool| [tool[:tool_id], tool[:edit]] if tool[:tool_id] && tool[:edit] }.to_h
|
|
263
|
-
out = item.except(:parts)
|
|
264
|
-
marks.empty? ? out : out.merge(marks: marks)
|
|
265
|
-
end
|
|
266
|
-
|
|
267
284
|
# A turn opening's Revise stamp as {revises: {turn_id:}}, checked again
|
|
268
285
|
# (a stored file is never trusted), or nothing.
|
|
269
286
|
def revises_of(message)
|
|
@@ -280,13 +297,13 @@ module Samagotchi
|
|
|
280
297
|
|
|
281
298
|
# A no-answer turn's marker as display items: each empty step that
|
|
282
299
|
# has something to show (its thinking) as a text-less assistant step
|
|
283
|
-
# (only with +parts+, as other text-less steps
|
|
284
|
-
# { role: "empty_answer", retries: }.
|
|
285
|
-
def empty_answer_items(marker, parts:, cwd:)
|
|
286
|
-
|
|
287
|
-
items =
|
|
300
|
+
# (only with +parts+ or +steps+, as other text-less steps; its parts
|
|
301
|
+
# with +parts+), then { role: "empty_answer", retries: }.
|
|
302
|
+
def empty_answer_items(marker, parts:, steps:, cwd:)
|
|
303
|
+
saved = parts || steps ? Array(marker[:steps] || marker["steps"]) : []
|
|
304
|
+
items = saved.filter_map do |step|
|
|
288
305
|
did = step.is_a?(Hash) ? MessageParts.for_message(step, [], cwd: cwd) : nil
|
|
289
|
-
{ role: "assistant", content: "", parts: did } if did
|
|
306
|
+
{ role: "assistant", content: "", **(parts ? { parts: did } : {}) } if did
|
|
290
307
|
end
|
|
291
308
|
refusal = marker[:refusal] || marker["refusal"]
|
|
292
309
|
items << { role: "empty_answer", content: "", retries: (marker[:retries] || marker["retries"]).to_i, refusal: refusal }.compact
|
|
@@ -365,7 +365,7 @@ const reloadCheck = createReloadCheck({
|
|
|
365
365
|
enabled: () => document.body.dataset.reloadCheck === "1",
|
|
366
366
|
sessionId: () => store.selected,
|
|
367
367
|
running: () => liveTurn.running,
|
|
368
|
-
read: (id) => getSession(id
|
|
368
|
+
read: (id) => getSession(id),
|
|
369
369
|
render: (data) => turnHistoryNodes(data.messages || [], normalizeTiming(data.timing), historyOpts(data)),
|
|
370
370
|
post: (id, body) => api(`/api/sessions/${id}/reload_check`, { method: "POST", body: JSON.stringify(body) }),
|
|
371
371
|
});
|
|
@@ -961,7 +961,7 @@ async function resync({ endText = null } = {}) {
|
|
|
961
961
|
let data;
|
|
962
962
|
try {
|
|
963
963
|
try {
|
|
964
|
-
data = await getSession(id
|
|
964
|
+
data = await getSession(id);
|
|
965
965
|
} catch (e) {
|
|
966
966
|
if (e.status === 404) return leaveGoneSession(id, "not_found");
|
|
967
967
|
if (id === store.selected) {
|
|
@@ -1090,13 +1090,12 @@ function renderSessionView(data, { kept = [] } = {}) {
|
|
|
1090
1090
|
}
|
|
1091
1091
|
|
|
1092
1092
|
// The working set's turns from a session's messages, as turnHistoryNodes
|
|
1093
|
-
// numbers them
|
|
1094
|
-
//
|
|
1093
|
+
// numbers them: the drawn ones (the running turn, which the replay draws
|
|
1094
|
+
// in the stage, has no drawing yet).
|
|
1095
1095
|
function seedWorkingSet(data) {
|
|
1096
1096
|
if (!workingSet) return;
|
|
1097
1097
|
const items = data.messages || [];
|
|
1098
1098
|
const groups = typeof items[0] === "object" && items[0]?.role ? turnGroups(items, store.current.timing, { drawings: data.turn_drawings }).filter((g) => g.kind === "turn") : [];
|
|
1099
|
-
if (data.current_turn && groups.length) groups.pop();
|
|
1100
1099
|
workingSet.seed(groups.map((g, i) => {
|
|
1101
1100
|
const text = String(items[g.user]?.content ?? "").replace(/\s+/g, " ").trim();
|
|
1102
1101
|
return { items: groupItems(g, i), prompt: text.length > 60 ? `${text.slice(0, 59)}\u2026` : text };
|
|
@@ -1104,9 +1103,11 @@ function seedWorkingSet(data) {
|
|
|
1104
1103
|
}
|
|
1105
1104
|
|
|
1106
1105
|
// turnHistoryNodes' options for a read's +data+: its turns' drawings
|
|
1107
|
-
// (turn_drawing.js)
|
|
1106
|
+
// (turn_drawing.js), cards (a drawn card's body) and the running turn's id
|
|
1107
|
+
// (its prompt has no drawing yet: a plain row, no miss).
|
|
1108
1108
|
const historyOpts = (data = {}) => ({ thumbs: (images) => thumbsTemplate(store.selected, images), workingSet: !!workingSet,
|
|
1109
|
-
drawings: data.turn_drawings || null, cards: data.cards || null, capabilities: pageCapabilities
|
|
1109
|
+
drawings: data.turn_drawings || null, cards: data.cards || null, capabilities: pageCapabilities,
|
|
1110
|
+
runningTurnId: data.current_turn?.turn_id || null });
|
|
1110
1111
|
|
|
1111
1112
|
function renderHistory(items, data = {}) {
|
|
1112
1113
|
gapClock.seed(null);
|
|
@@ -129,12 +129,10 @@ export function uploadImage(id, file, name, opts = {}) {
|
|
|
129
129
|
// opts.recent its timing holds the newest turn's records and turn_count
|
|
130
130
|
// (mergeTiming), and opts.turnId asks for that turn's answer.
|
|
131
131
|
// opts.timing: the whole timing alone (when the merge came up short).
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
export function getSession(id, { tail, recent, turnId, timing, parts, cards, ...opts } = {}) {
|
|
137
|
-
let query = cards ? "?cards=1" : tail ? "?tail=1" : timing ? "?timing=1" : parts ? "?parts=1&drawings=1" : "";
|
|
132
|
+
// The full read (none of those): every finished turn as its
|
|
133
|
+
// turn_drawings, its items stamped (drawn: turn_drawing.js).
|
|
134
|
+
export function getSession(id, { tail, recent, turnId, timing, cards, ...opts } = {}) {
|
|
135
|
+
let query = cards ? "?cards=1" : tail ? "?tail=1" : timing ? "?timing=1" : "";
|
|
138
136
|
if (tail && recent) query += "&recent=1";
|
|
139
137
|
if (tail && turnId) query += `&turn_id=${encodeURIComponent(turnId)}`;
|
|
140
138
|
return api(`/api/sessions/${id}${query}`, opts);
|
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
// entries that would explain the differences (`explained`: all of them
|
|
8
8
|
// have one), so chi web's log counts each class apart (the bugs turn
|
|
9
9
|
// drawings close, the deliberate ones). It posts the counts, never
|
|
10
|
-
// content: {turn_id, same, kinds, excused, explained, drawn}; chi
|
|
11
|
-
// them (reload_checked, reload_mismatch).
|
|
10
|
+
// content: {turn_id, same, kinds, excused, explained, drawn, undrawn}; chi
|
|
11
|
+
// web logs them (reload_checked, reload_mismatch). `undrawn`: how many rows
|
|
12
|
+
// of the reload came without their turn's drawing (turn_block.js's plain
|
|
13
|
+
// fallback, data-undrawn): 0 unless chi web missed one. Fire-and-forget: no toast, no
|
|
12
14
|
// store write, a failure is dropped.
|
|
13
15
|
//
|
|
14
16
|
// Cards are left out on both sides: a reload places them after the render
|
|
@@ -34,7 +36,7 @@ function withoutCards(shape) {
|
|
|
34
36
|
// @param sessionId () => the open session's id
|
|
35
37
|
// @param running () => whether a turn runs now (liveTurn.running: a queued
|
|
36
38
|
// turn started streaming)
|
|
37
|
-
// @param read (id) => the session as a reload reads it (GET
|
|
39
|
+
// @param read (id) => the session as a reload reads it (the full GET)
|
|
38
40
|
// @param render (data) => that read drawn as a reload draws it (a fragment)
|
|
39
41
|
// @param post (id, body) => the counts to chi web
|
|
40
42
|
export function createReloadCheck({ enabled, sessionId, running, read, render, post }) {
|
|
@@ -62,7 +64,8 @@ export function createReloadCheck({ enabled, sessionId, running, read, render, p
|
|
|
62
64
|
: { same: false, kinds: ["prompt"], excused: [], explained: false };
|
|
63
65
|
// Whether the read had a drawing for the turn (turn drawings, P2).
|
|
64
66
|
const drawn = !!data?.turn_drawings?.[turnId];
|
|
65
|
-
|
|
67
|
+
const undrawn = holder.querySelectorAll("[data-undrawn]").length;
|
|
68
|
+
await post(id, { turn_id: turnId, same, kinds, excused, explained, drawn, undrawn });
|
|
66
69
|
} catch (_) {
|
|
67
70
|
// Fire-and-forget: a failed read or post is no finding.
|
|
68
71
|
}
|
|
@@ -28,8 +28,7 @@ export function timeGapEl(text) {
|
|
|
28
28
|
|
|
29
29
|
// The history items a group (timing.js turnGroups) holds, by index.
|
|
30
30
|
function groupIndexes(group) {
|
|
31
|
-
if (group.kind === "note" || group.kind === "
|
|
32
|
-
if (group.kind === "answer") return [group.answer];
|
|
31
|
+
if (group.kind === "note" || group.kind === "plain" || group.kind === "command") return [group.i];
|
|
33
32
|
const steps = group.steps || [];
|
|
34
33
|
return [
|
|
35
34
|
group.user, ...steps.map((step) => step.i), ...steps.flatMap((step) => step.steers || []),
|