samagotchi 0.167.0 → 0.169.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 +64 -1
- data/docs/architecture.md +1 -1
- data/docs/cli.md +14 -10
- data/docs/configuration.md +1 -1
- data/docs/guardrails.md +2 -3
- data/docs/hooks.md +2 -2
- data/docs/internals/block-renderers.md +1 -1
- data/docs/internals/bridge.md +16 -4
- data/docs/internals/inline-widgets.md +1 -1
- data/docs/internals/objectives.md +2 -1
- data/docs/internals/remote-sessions.md +1 -1
- data/docs/internals/web-frontend.md +99 -19
- data/docs/plugins.md +1 -1
- data/docs/releasing.md +10 -6
- data/docs/testing.md +14 -3
- data/lib/samagotchi/bridge.rb +12 -2
- data/lib/samagotchi/bundle_command.rb +19 -4
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +3 -0
- data/lib/samagotchi/command_intake.rb +7 -7
- data/lib/samagotchi/compat.rb +12 -7
- data/lib/samagotchi/engine/objectives.rb +10 -1
- data/lib/samagotchi/guardrails/approvals.rb +10 -29
- data/lib/samagotchi/session_continue.rb +8 -11
- data/lib/samagotchi/session_manager/removal.rb +3 -3
- data/lib/samagotchi/session_stores.rb +79 -0
- data/lib/samagotchi/turn_stages/objectives.rb +6 -8
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/public/app.js +3 -1
- data/lib/samagotchi/web/public/block_watch.js +1 -1
- data/lib/samagotchi/web/public/cards_place.js +5 -1
- data/lib/samagotchi/web/public/dock_reserve.js +12 -2
- data/lib/samagotchi/web/public/history_end.js +16 -0
- data/lib/samagotchi/web/public/index.html +89 -44
- data/lib/samagotchi/web/public/markdown_place.js +1 -1
- data/lib/samagotchi/web/public/question_cards.js +21 -7
- data/lib/samagotchi/web/public/refs.js +4 -1
- data/lib/samagotchi/web/public/reload_check.js +5 -4
- data/lib/samagotchi/web/public/stage_asking.js +283 -0
- data/lib/samagotchi/web/public/stage_cards.js +20 -0
- data/lib/samagotchi/web/public/stage_frame.js +17 -23
- data/lib/samagotchi/web/public/stage_model.js +48 -15
- data/lib/samagotchi/web/public/stage_opened.js +239 -0
- data/lib/samagotchi/web/public/stage_slots.js +13 -90
- data/lib/samagotchi/web/public/stage_view.js +339 -225
- data/lib/samagotchi/web/public/stage_waiting.js +180 -0
- data/lib/samagotchi/web/public/stage_watch.js +8 -4
- data/lib/samagotchi/web/public/stream_handlers.js +1 -1
- data/lib/samagotchi/web/public/turn_block.js +14 -2
- data/lib/samagotchi/web/public/turn_model.js +1 -1
- data/lib/samagotchi/web/session_show.rb +14 -4
- data/lib/samagotchi/worker.rb +3 -4
- metadata +7 -1
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -82,6 +82,7 @@ module Samagotchi
|
|
|
82
82
|
input_epoch: "waiting-steer monitor",
|
|
83
83
|
last_answer_message: "message snapshot under event lock",
|
|
84
84
|
messages_checkpoint: "replace-only message copy",
|
|
85
|
+
objectives_view: "objectives snapshot under event lock",
|
|
85
86
|
pending_question: "question-desk monitor",
|
|
86
87
|
plugin_warning: "warning-state reader",
|
|
87
88
|
recap: "recap-job reference",
|
|
@@ -372,14 +373,21 @@ module Samagotchi
|
|
|
372
373
|
# against these messages; a reminder's, a Continue's or a note after it
|
|
373
374
|
# hides it no more. Absent otherwise (no prompt with a turn id, a
|
|
374
375
|
# rollback, an older worker's file).
|
|
376
|
+
# objectives: the view this worker announces, computed with the running
|
|
377
|
+
# conversation too; nil when there is no list, absent if reading it fails.
|
|
375
378
|
# @return [Hash] {messages:, current_turn:, working_set:, queued:, queued_commands:, recap:, saved_recap:, continue_offer:, pending_question:,
|
|
376
|
-
# guardrail_warning:, plugin_warning:, init_tasks:, cards:, commands:, chi_version:, event_seq:, event_id:, last_turn_drawing
|
|
379
|
+
# guardrail_warning:, plugin_warning:, init_tasks:, cards:, commands:, chi_version:, event_seq:, event_id:, last_turn_drawing:,
|
|
380
|
+
# objectives:}
|
|
377
381
|
def snapshot
|
|
378
382
|
@engine.synchronize_events do
|
|
379
383
|
seq = @engine.event_count
|
|
380
384
|
messages = @engine.messages_checkpoint
|
|
381
385
|
drawing = last_turn_drawing(messages)
|
|
382
|
-
|
|
386
|
+
objectives_unavailable = Object.new
|
|
387
|
+
objectives = Degrade.call(:bridge, "objectives_snapshot_failed", fallback: objectives_unavailable) do
|
|
388
|
+
@engine.objectives_view(@session_id, messages, state_dir: @state_dir)
|
|
389
|
+
end
|
|
390
|
+
snapshot = {
|
|
383
391
|
messages: messages,
|
|
384
392
|
current_turn: current_turn_with_generation,
|
|
385
393
|
working_set: @accumulator.working_set,
|
|
@@ -398,6 +406,8 @@ module Samagotchi
|
|
|
398
406
|
event_seq: seq,
|
|
399
407
|
event_id: event_id(seq)
|
|
400
408
|
}.merge(drawing ? { last_turn_drawing: drawing } : {})
|
|
409
|
+
snapshot[:objectives] = objectives unless objectives.equal?(objectives_unavailable)
|
|
410
|
+
snapshot
|
|
401
411
|
end
|
|
402
412
|
end
|
|
403
413
|
|
|
@@ -541,7 +541,7 @@ module Samagotchi
|
|
|
541
541
|
end
|
|
542
542
|
|
|
543
543
|
def status(rest)
|
|
544
|
-
parsed = parse_flags(NO_FLAGS, rest, "status", help: STATUS_HELP)
|
|
544
|
+
parsed = parse_flags(NO_FLAGS, rest, "status", help: STATUS_HELP, max_positionals: 1, noun: "bundle")
|
|
545
545
|
return parsed if parsed.is_a?(Integer)
|
|
546
546
|
|
|
547
547
|
name = parsed.args.first
|
|
@@ -644,7 +644,7 @@ module Samagotchi
|
|
|
644
644
|
def status_scope(st) = st.scope_error ? "#{st.scope} (unknown)" : st.scope
|
|
645
645
|
|
|
646
646
|
def diff(rest)
|
|
647
|
-
parsed = parse_flags(NO_FLAGS, rest, "diff", help: DIFF_HELP)
|
|
647
|
+
parsed = parse_flags(NO_FLAGS, rest, "diff", help: DIFF_HELP, max_positionals: 2)
|
|
648
648
|
return parsed if parsed.is_a?(Integer)
|
|
649
649
|
|
|
650
650
|
args = parsed.args
|
|
@@ -756,7 +756,7 @@ module Samagotchi
|
|
|
756
756
|
end
|
|
757
757
|
|
|
758
758
|
def list(rest)
|
|
759
|
-
parsed = parse_flags(NO_FLAGS, rest, "list", help: LIST_HELP)
|
|
759
|
+
parsed = parse_flags(NO_FLAGS, rest, "list", help: LIST_HELP, max_positionals: 0)
|
|
760
760
|
return parsed if parsed.is_a?(Integer)
|
|
761
761
|
|
|
762
762
|
listing = Samagotchi::MemoryBundle::Listing
|
|
@@ -1026,7 +1026,7 @@ module Samagotchi
|
|
|
1026
1026
|
# @return [CLI::Flags::Result, Integer] the result, or the exit status
|
|
1027
1027
|
# after the help or an unknown flag (a value flag without its value
|
|
1028
1028
|
# reads as one)
|
|
1029
|
-
def parse_flags(flags, rest, sub, help:)
|
|
1029
|
+
def parse_flags(flags, rest, sub, help:, max_positionals: nil, noun: "argument")
|
|
1030
1030
|
parsed = flags.parse(rest)
|
|
1031
1031
|
if parsed.help
|
|
1032
1032
|
@stdout.puts help
|
|
@@ -1036,6 +1036,21 @@ module Samagotchi
|
|
|
1036
1036
|
@stderr.puts "Unknown bundle #{sub} flag: #{parsed.error.arg}"
|
|
1037
1037
|
return CLI::Exit::USAGE
|
|
1038
1038
|
end
|
|
1039
|
+
if max_positionals && parsed.args.size > max_positionals
|
|
1040
|
+
extra = parsed.args[max_positionals..]
|
|
1041
|
+
count = if max_positionals == 1
|
|
1042
|
+
"one"
|
|
1043
|
+
else
|
|
1044
|
+
max_positionals == 2 ? "two" : max_positionals.to_s
|
|
1045
|
+
end
|
|
1046
|
+
allowed = if max_positionals.zero?
|
|
1047
|
+
"no #{noun}s"
|
|
1048
|
+
else
|
|
1049
|
+
"at most #{count} #{max_positionals == 1 ? noun : "#{noun}s"}"
|
|
1050
|
+
end
|
|
1051
|
+
@stderr.puts "chi bundle #{sub} takes #{allowed} (unexpected #{extra.join(", ")})"
|
|
1052
|
+
return CLI::Exit::USAGE
|
|
1053
|
+
end
|
|
1039
1054
|
parsed
|
|
1040
1055
|
end
|
|
1041
1056
|
|
data/lib/samagotchi/client_id.rb
CHANGED
|
@@ -109,6 +109,9 @@ module Samagotchi
|
|
|
109
109
|
HUMAN_IDS.include?(id) || HUMAN_PREFIXES.any? { |prefix| id.start_with?(prefix) }
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
# Whether +client_id+ is the owner's input, not a participant's.
|
|
113
|
+
def owner?(client_id) = human?(client_id) && !review?(client_id)
|
|
114
|
+
|
|
112
115
|
# The WakePolicy row a turn delivery from +client_id+ reads (deliver_turn's
|
|
113
116
|
# two liveness checks): :send for a person (a web tab, a chi TUI, chi
|
|
114
117
|
# send), :schedule, :plugin, :delegate or :participant for those
|
|
@@ -35,14 +35,14 @@ module Samagotchi
|
|
|
35
35
|
|
|
36
36
|
module_function
|
|
37
37
|
|
|
38
|
-
# Whether a message from +client_id+ may run as a session command:
|
|
39
|
-
#
|
|
40
|
-
# client)
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
38
|
+
# Whether a message from +client_id+ may run as a session command: the
|
|
39
|
+
# owner's input (ClientId.owner?: a web tab, a chi TUI, chi send, no
|
|
40
|
+
# client) and chi answer's. A participant (review:) is refused on its own.
|
|
41
|
+
# A delegate, a child's report, a context or task wake, a schedule, a
|
|
42
|
+
# reminder, a relay and a plugin may not (the bundles that send,
|
|
43
|
+
# coordinator and skills, send prose).
|
|
44
44
|
def allowed?(client_id)
|
|
45
|
-
ALLOWED_IDS.include?(client_id.to_s) ||
|
|
45
|
+
ALLOWED_IDS.include?(client_id.to_s) || ClientId.owner?(client_id)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
# Whether +text+ would be a shell line (!<cmd>, !rollback) if a command:
|
data/lib/samagotchi/compat.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rubygems/version"
|
|
4
|
+
require "date"
|
|
4
5
|
require_relative "version"
|
|
5
6
|
|
|
6
7
|
module Samagotchi
|
|
@@ -11,27 +12,31 @@ module Samagotchi
|
|
|
11
12
|
# decided (kept until then). spec/compat_spec.rb fails once VERSION
|
|
12
13
|
# passes a shim's +remove_after+, naming it. Each Ruby file names its
|
|
13
14
|
# shim's id in a comment ("compat shim <id>").
|
|
15
|
+
# A shim stays at least 14 days after the release that added it.
|
|
14
16
|
# @!attribute files [Array<String>] where the shim lives (from the repository root)
|
|
15
|
-
Shim = Data.define(:id, :added_in, :remove_after, :files, :what)
|
|
17
|
+
Shim = Data.define(:id, :added_in, :added_on, :remove_after, :files, :what)
|
|
18
|
+
MIN_AGE_DAYS = 14
|
|
16
19
|
|
|
17
20
|
SHIMS = [
|
|
18
|
-
Shim.new(id: :cards_v1_seed, added_in: "0.151.0", remove_after: "0.170.0",
|
|
21
|
+
Shim.new(id: :cards_v1_seed, added_in: "0.151.0", added_on: "2026-11-05", remove_after: "0.170.0",
|
|
19
22
|
files: ["lib/samagotchi/bridge/card_store.rb"],
|
|
20
23
|
what: "CardStore#seed_v1 reads a cards.json from before the turn log; its comment says a retention " \
|
|
21
24
|
"period after the release that wrote version 2 (0.151.0, 2026-11-05)"),
|
|
22
|
-
Shim.new(id: :
|
|
25
|
+
Shim.new(id: :approvals_bare_list, added_in: "0.169.0", added_on: "2026-11-12", remove_after: "0.172.0",
|
|
23
26
|
files: ["lib/samagotchi/guardrails/approvals.rb"],
|
|
24
|
-
what: "Approvals
|
|
25
|
-
"store, and #version_list rewrites it versioned on that first read")
|
|
27
|
+
what: "Approvals reads the bare list written by chi 0.166 and before, converting it on write")
|
|
26
28
|
].freeze
|
|
27
29
|
|
|
28
30
|
module_function
|
|
29
31
|
|
|
30
32
|
# The shims +version+ has passed the remove_after of.
|
|
31
33
|
# @return [Array<Shim>]
|
|
32
|
-
def overdue_shims(version: VERSION, shims: SHIMS)
|
|
34
|
+
def overdue_shims(version: VERSION, shims: SHIMS, today: Date.today)
|
|
33
35
|
current = Gem::Version.new(version)
|
|
34
|
-
shims.select
|
|
36
|
+
shims.select do |shim|
|
|
37
|
+
shim.remove_after && current > Gem::Version.new(shim.remove_after) &&
|
|
38
|
+
Date.iso8601(shim.added_on) + MIN_AGE_DAYS <= today
|
|
39
|
+
end
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
def verdict(worker_version:, version: VERSION, worker_protocol: nil, protocol: nil)
|
|
@@ -19,13 +19,22 @@ module Samagotchi
|
|
|
19
19
|
return unless session
|
|
20
20
|
|
|
21
21
|
synchronize_events do
|
|
22
|
-
event = @objectives_stage.announce(session,
|
|
22
|
+
event = @objectives_stage.announce(session, view: objectives_view(session.id, session.messages))
|
|
23
23
|
announce(event) if event
|
|
24
24
|
end
|
|
25
25
|
rescue StandardError => e
|
|
26
26
|
Log.warn(:turn, "objectives_announce_failed", error: e.class.name, msg: e.message)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# The view the worker announces and includes in its snapshots.
|
|
30
|
+
# @param session_id [String] the session whose objectives to read
|
|
31
|
+
# @param messages [Array<Hash>] the messages held by the caller's snapshot
|
|
32
|
+
# @param state_dir [String] the sessions dir
|
|
33
|
+
# @return [Hash, nil]
|
|
34
|
+
def objectives_view(session_id, messages, state_dir: session_state_dir)
|
|
35
|
+
Objectives.view(session_id, messages, state_dir: state_dir, running: live_conversation&.dup)
|
|
36
|
+
end
|
|
37
|
+
|
|
29
38
|
# Check this (ObjectivesCheck)'s one side request. Its usage is in the
|
|
30
39
|
# session's side line. Raises as ctx.ask_model's request does.
|
|
31
40
|
# @param request [Array<Hash>] chat messages
|
|
@@ -30,9 +30,8 @@ module Samagotchi
|
|
|
30
30
|
#
|
|
31
31
|
# The file is a versioned store, {"version", "approvals": [...]}
|
|
32
32
|
# (FORMAT); a write keeps its version and the keys this chi doesn't
|
|
33
|
-
# know. A list of entries (what 0.
|
|
34
|
-
#
|
|
35
|
-
# read (compat shim approvals_array_read).
|
|
33
|
+
# know. A bare list of entries (what 0.166 and before wrote) is read and
|
|
34
|
+
# becomes versioned on the next write.
|
|
36
35
|
class Approvals
|
|
37
36
|
FILE = "approvals.json"
|
|
38
37
|
COLLECTION = "approvals"
|
|
@@ -168,12 +167,11 @@ module Samagotchi
|
|
|
168
167
|
|
|
169
168
|
# @param locked [Boolean] the caller holds the store's lock
|
|
170
169
|
# @return [Array(Array<Hash>, StateFormat::Document)] the entries and,
|
|
171
|
-
#
|
|
170
|
+
# its document (nil when there is no file)
|
|
172
171
|
def read(locked: false)
|
|
173
172
|
return [[], nil] unless File.exist?(@path)
|
|
174
173
|
|
|
175
|
-
|
|
176
|
-
document ? [list, document] : version_list(locked: locked) || [list, nil]
|
|
174
|
+
parse(File.read(@path))
|
|
177
175
|
rescue JSON::ParserError, SystemCallError => e
|
|
178
176
|
aside = begin
|
|
179
177
|
locked ? set_aside : with_lock { set_aside }
|
|
@@ -194,6 +192,10 @@ module Samagotchi
|
|
|
194
192
|
def parse(text)
|
|
195
193
|
data = JSON.parse(text)
|
|
196
194
|
case data
|
|
195
|
+
when Array
|
|
196
|
+
# compat shim approvals_bare_list
|
|
197
|
+
document = FORMAT.read({ COLLECTION => data }, collection: COLLECTION)
|
|
198
|
+
[document.entries.map(&:raw).select { |e| e.is_a?(Hash) }, document]
|
|
197
199
|
when Hash
|
|
198
200
|
raise JSON::ParserError, "#{COLLECTION} is not a list" unless data.fetch(COLLECTION, []).is_a?(Array)
|
|
199
201
|
|
|
@@ -201,32 +203,11 @@ module Samagotchi
|
|
|
201
203
|
# An entry it can't read (no scope) is kept as it is: it matches
|
|
202
204
|
# nothing, and a write keeps it for the chi that wrote it.
|
|
203
205
|
[document.entries.map(&:raw).select { |e| e.is_a?(Hash) }, document]
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
else raise JSON::ParserError, "not a list or a versioned store"
|
|
206
|
+
else
|
|
207
|
+
raise JSON::ParserError, "not a versioned store"
|
|
207
208
|
end
|
|
208
209
|
end
|
|
209
210
|
|
|
210
|
-
# compat shim approvals_array_read: rewrite a list as the versioned
|
|
211
|
-
# store, under the lock, if it is still a list. One that can't be
|
|
212
|
-
# written (a read-only state dir) or changed meanwhile is read as it
|
|
213
|
-
# is this time.
|
|
214
|
-
# @return [Array(Array<Hash>, StateFormat::Document), nil] as #read's; nil when not rewritten
|
|
215
|
-
def version_list(locked:)
|
|
216
|
-
locked ? version_list! : with_lock { version_list! }
|
|
217
|
-
rescue JSON::ParserError, SystemCallError
|
|
218
|
-
nil
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def version_list!
|
|
222
|
-
list, document = parse(File.read(@path))
|
|
223
|
-
return [list, document] if document
|
|
224
|
-
|
|
225
|
-
document = FORMAT.read({ COLLECTION => list }, collection: COLLECTION)
|
|
226
|
-
write(document)
|
|
227
|
-
[list, document]
|
|
228
|
-
end
|
|
229
|
-
|
|
230
211
|
def write(document)
|
|
231
212
|
AtomicFile.write(@path, JSON.pretty_generate(FORMAT.write(document, collection: COLLECTION, updated_at: nil)))
|
|
232
213
|
end
|
|
@@ -21,6 +21,7 @@ require_relative "worker_link"
|
|
|
21
21
|
require_relative "model_profile"
|
|
22
22
|
require_relative "log"
|
|
23
23
|
require_relative "session_manager"
|
|
24
|
+
require_relative "session_stores"
|
|
24
25
|
|
|
25
26
|
module Samagotchi
|
|
26
27
|
# The next link of a session chain: chi send --new --continues and web
|
|
@@ -76,7 +77,7 @@ module Samagotchi
|
|
|
76
77
|
# (taking an UndoContext) that gives it back when the continue fails;
|
|
77
78
|
# empty when there is nothing to undo (CARRY's comment says why).
|
|
78
79
|
# +store+ is the SessionManager::SESSION_STATE_STORES store it carries.
|
|
79
|
-
CarryStep = Data.define(:name, :store, :carry, :undo)
|
|
80
|
+
CarryStep = Data.define(:name, :store, :carry, :undo, :files)
|
|
80
81
|
# What a carry step works on: the previous link (a Session), the new
|
|
81
82
|
# link's id, the delegates moving (ChildMove::Plan#move).
|
|
82
83
|
CarryContext = Data.define(:previous, :to, :state_dir, :move)
|
|
@@ -100,15 +101,16 @@ module Samagotchi
|
|
|
100
101
|
# Its open delegates (ChildMove): given back to the previous link
|
|
101
102
|
# first, then the rings one rang the link with just before the undo.
|
|
102
103
|
CarryStep.new(name: :children, store: :session_files, carry: :carry_children,
|
|
103
|
-
undo: { moved_back: :undo_move, link_stopped: :return_rings }
|
|
104
|
+
undo: { moved_back: :undo_move, link_stopped: :return_rings },
|
|
105
|
+
files: %w[delegates.json parent.json]),
|
|
104
106
|
# Its movable context too, with a note saying what moved and stayed.
|
|
105
107
|
# No undo: ContextSources.move copies (the previous link keeps its
|
|
106
108
|
# sources), and the link's copies go with its delete (remove_files).
|
|
107
|
-
CarryStep.new(name: :context, store: :context_sources, carry: :carry_context, undo: {}),
|
|
109
|
+
CarryStep.new(name: :context, store: :context_sources, carry: :carry_context, undo: {}, files: ["left.json"]),
|
|
108
110
|
# Its objectives: the list reads as the latest word. No undo: a note
|
|
109
111
|
# written into the link only (NoteMove::CONTINUE_SOURCES: never given
|
|
110
112
|
# back), which goes with its delete.
|
|
111
|
-
CarryStep.new(name: :objectives, store: :session_files, carry: :carry_objectives, undo: {}),
|
|
113
|
+
CarryStep.new(name: :objectives, store: :session_files, carry: :carry_objectives, undo: {}, files: []),
|
|
112
114
|
# Its waiting notes last: the carry above read a pending /objectives
|
|
113
115
|
# edit from them first. They keep their names, so they still sort
|
|
114
116
|
# ahead of the link's own notes. A note sent to the previous link
|
|
@@ -117,17 +119,12 @@ module Samagotchi
|
|
|
117
119
|
# once the link is out of the chain, and again for a note an older chi
|
|
118
120
|
# wrote after its folder went.
|
|
119
121
|
CarryStep.new(name: :notes, store: :session_files, carry: :carry_notes,
|
|
120
|
-
undo: { link_unlinked: :give_back_notes, link_deleted: :give_back_strays })
|
|
122
|
+
undo: { link_unlinked: :give_back_notes, link_deleted: :give_back_strays }, files: [])
|
|
121
123
|
].freeze
|
|
122
124
|
|
|
123
125
|
# The SessionManager::SESSION_STATE_STORES a continue deliberately
|
|
124
126
|
# leaves with the previous link, and why: every store is in CARRY or here.
|
|
125
|
-
NOT_CARRIED = {
|
|
126
|
-
plugin_session_state: "a bundle's per-session state (ctx.session_dir) stays with the archived link",
|
|
127
|
-
participants: "the archive ends the previous link's review (D8); a continue copies no grants",
|
|
128
|
-
system_one_runs: "System 1's saved runs record the previous link's own turns",
|
|
129
|
-
context_candidates_log: "the candidates log records the previous link's own turns"
|
|
130
|
-
}.freeze
|
|
127
|
+
NOT_CARRIED = SessionStores::STORES.reject(&:carried?).to_h { |store| [store.file, store.continue] }.freeze
|
|
131
128
|
|
|
132
129
|
# The model a new link runs on (#model_for): the name to spawn it with,
|
|
133
130
|
# and why it isn't the previous link's (nil when it is, or was given).
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../session_stores"
|
|
4
|
+
|
|
3
5
|
module Samagotchi
|
|
4
6
|
class SessionManager
|
|
5
7
|
# A delete that would pull the session from under its live worker.
|
|
@@ -61,9 +63,7 @@ module Samagotchi
|
|
|
61
63
|
|
|
62
64
|
# Every store with session-scoped state. Deletion, retention and failed
|
|
63
65
|
# continuation cleanup all pass through this registry.
|
|
64
|
-
SESSION_STATE_STORES =
|
|
65
|
-
session_files plugin_session_state context_sources participants system_one_runs context_candidates_log
|
|
66
|
-
].freeze
|
|
66
|
+
SESSION_STATE_STORES = SessionStores.removal_stores
|
|
67
67
|
|
|
68
68
|
# Removal: archive, unarchive and delete a session (an archive takes its
|
|
69
69
|
# delegates too), and the retention sweep's entry. Calls LifecyclePart's
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Samagotchi
|
|
4
|
+
# The files that hold state for a session, including stores outside its
|
|
5
|
+
# sidecar directory. `corpus_dir` is relative to the compatibility corpus.
|
|
6
|
+
# A Symbol in `continue` names the carry step; a String explains why it stays.
|
|
7
|
+
module SessionStores
|
|
8
|
+
Store = Data.define(:file, :owner, :removal, :cross_version, :continue, :corpus_dir, :corpus_exception) do
|
|
9
|
+
def initialize(file:, owner:, removal:, cross_version:, continue:, corpus_dir:, corpus_exception: nil)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def carried? = continue.is_a?(Symbol)
|
|
14
|
+
|
|
15
|
+
def corpus_exception? = !corpus_exception.nil?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
SIDE_CAR = "sessions/compat-session"
|
|
19
|
+
CONTEXT = "context/sessions/compat-session"
|
|
20
|
+
|
|
21
|
+
STORES = [
|
|
22
|
+
Store.new(file: "archived", owner: "ArchiveStore", removal: :session_files, cross_version: true,
|
|
23
|
+
continue: "the archived link remains its own session", corpus_dir: SIDE_CAR),
|
|
24
|
+
Store.new(file: "state.json", owner: "PluginSessionState", removal: :plugin_session_state, cross_version: false,
|
|
25
|
+
continue: "bundle state stays with the archived link", corpus_dir: nil),
|
|
26
|
+
Store.new(file: "left.json", owner: "ContextSources", removal: :context_sources, cross_version: true,
|
|
27
|
+
continue: :context, corpus_dir: CONTEXT),
|
|
28
|
+
Store.new(file: "participants.json", owner: "Participants", removal: :participants, cross_version: true,
|
|
29
|
+
continue: "a continue ends the previous link's review", corpus_dir: SIDE_CAR),
|
|
30
|
+
Store.new(file: "judgments.jsonl", owner: "SystemOne::RunsStore", removal: :system_one_runs, cross_version: false,
|
|
31
|
+
continue: "saved judgments belong to the previous link", corpus_dir: nil),
|
|
32
|
+
Store.new(file: "context_candidates.jsonl", owner: "ContextCandidatesLog", removal: :context_candidates_log,
|
|
33
|
+
cross_version: false, continue: "candidate records belong to the previous link", corpus_dir: nil),
|
|
34
|
+
Store.new(file: "bridge.json", owner: "WorkerSidecar", removal: :session_files, cross_version: true,
|
|
35
|
+
continue: "the bridge endpoint belongs to the old worker", corpus_dir: SIDE_CAR),
|
|
36
|
+
Store.new(file: "cards.json", owner: "Bridge::CardStore", removal: :session_files, cross_version: true,
|
|
37
|
+
continue: "cards describe turns in the previous link", corpus_dir: SIDE_CAR),
|
|
38
|
+
Store.new(file: "pending_card.json", owner: "Bridge::PendingCard", removal: :session_files, cross_version: true,
|
|
39
|
+
continue: "an open card belongs to its running turn", corpus_dir: SIDE_CAR),
|
|
40
|
+
Store.new(file: "turn_drawings.jsonl", owner: "Bridge::TurnDrawings", removal: :session_files, cross_version: true,
|
|
41
|
+
continue: "drawings describe turns in the previous link", corpus_dir: "sessions/compat-drawn"),
|
|
42
|
+
Store.new(file: "move.json", owner: "ChildMove", removal: :session_files, cross_version: true,
|
|
43
|
+
continue: "an interrupted move belongs to the previous continue", corpus_dir: SIDE_CAR),
|
|
44
|
+
Store.new(file: "continue.json", owner: "ContinueIntent", removal: :session_files, cross_version: true,
|
|
45
|
+
continue: "the intent records the previous link's continue", corpus_dir: SIDE_CAR),
|
|
46
|
+
Store.new(file: "objectives.lock", owner: "Objectives", removal: :session_files, cross_version: false,
|
|
47
|
+
continue: "a lock is not session data", corpus_dir: SIDE_CAR),
|
|
48
|
+
Store.new(file: "objectives_cards.json", owner: "Objectives", removal: :session_files, cross_version: true,
|
|
49
|
+
continue: "proposal answers belong to the previous link", corpus_dir: SIDE_CAR),
|
|
50
|
+
Store.new(file: "objective_checks.jsonl", owner: "ObjectivesCheck", removal: :session_files, cross_version: true,
|
|
51
|
+
continue: "checks belong to the previous link", corpus_dir: SIDE_CAR),
|
|
52
|
+
Store.new(file: "objective_tracks.jsonl", owner: "ObjectivesTrack", removal: :session_files, cross_version: true,
|
|
53
|
+
continue: "tracks belong to the previous link", corpus_dir: SIDE_CAR),
|
|
54
|
+
Store.new(file: "owner.lock", owner: "OwnerLock", removal: :session_files, cross_version: false,
|
|
55
|
+
continue: "the owner lock is not session data", corpus_dir: SIDE_CAR),
|
|
56
|
+
Store.new(file: "reminders.json", owner: "ReminderCarry", removal: :session_files, cross_version: true,
|
|
57
|
+
continue: "a restart hand-off is not a continue carry", corpus_dir: SIDE_CAR),
|
|
58
|
+
Store.new(file: "recap.json", owner: "RecapStore", removal: :session_files, cross_version: true,
|
|
59
|
+
continue: "the recap remains with the previous link", corpus_dir: SIDE_CAR),
|
|
60
|
+
Store.new(file: "stopped", owner: "Session", removal: :session_files, cross_version: true,
|
|
61
|
+
continue: "the stop marker belongs to the previous link", corpus_dir: SIDE_CAR),
|
|
62
|
+
Store.new(file: "parent.json", owner: "Session", removal: :session_files, cross_version: true,
|
|
63
|
+
continue: :children, corpus_dir: SIDE_CAR),
|
|
64
|
+
Store.new(file: "starting", owner: "StartingMarker", removal: :session_files, cross_version: true,
|
|
65
|
+
continue: "a start marker belongs to its spawn", corpus_dir: nil,
|
|
66
|
+
corpus_exception: "the corpus marker would always be stale, so it cannot pin the live-start handshake"),
|
|
67
|
+
Store.new(file: "thinking_tails.jsonl", owner: "ThinkingTails", removal: :session_files, cross_version: true,
|
|
68
|
+
continue: "generation tails remain with the previous link", corpus_dir: SIDE_CAR),
|
|
69
|
+
Store.new(file: "delegates.json", owner: "Tools::DelegateCursors", removal: :session_files, cross_version: true,
|
|
70
|
+
continue: :children, corpus_dir: SIDE_CAR),
|
|
71
|
+
Store.new(file: "delegates.lock", owner: "Tools::DelegateCursors", removal: :session_files, cross_version: false,
|
|
72
|
+
continue: "a lock is not session data", corpus_dir: SIDE_CAR)
|
|
73
|
+
].freeze
|
|
74
|
+
|
|
75
|
+
def self.removal_stores = STORES.map(&:removal).uniq.freeze
|
|
76
|
+
|
|
77
|
+
def self.corpus_stores = STORES.select(&:cross_version).freeze
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -97,18 +97,16 @@ module Samagotchi
|
|
|
97
97
|
# @param state_dir [String] the sessions dir
|
|
98
98
|
def note(session, note, recorder:, state_dir:) = audit(state_dir, recorder).note(session, note)
|
|
99
99
|
|
|
100
|
-
# The session's objectives as the page draws them (
|
|
101
|
-
# that differs from the last announced: after an edit (its file
|
|
102
|
-
# pending), once a list note is in, at a turn's end (its moves)
|
|
103
|
-
# a rollback. A session with no list announces nothing. The caller
|
|
100
|
+
# The session's objectives as the page draws them (Engine#objectives_view),
|
|
101
|
+
# when that differs from the last announced: after an edit (its file
|
|
102
|
+
# written, pending), once a list note is in, at a turn's end (its moves)
|
|
103
|
+
# and after a rollback. A session with no list announces nothing. The caller
|
|
104
104
|
# (Engine#announce_objectives) holds the event lock, the one guard of
|
|
105
105
|
# the last view, announces the event and logs a failure: it only
|
|
106
106
|
# informs, never fails a turn.
|
|
107
|
-
# @param
|
|
108
|
-
# @param running [Array<Hash>, nil] the running turn's conversation (Engine#live_conversation), nil between turns
|
|
107
|
+
# @param view [Hash, nil] the view from Engine#objectives_view
|
|
109
108
|
# @return [Hash, nil] the :objectives_updated event to announce, nil when the view is the same
|
|
110
|
-
def announce(session,
|
|
111
|
-
view = Samagotchi::Objectives.view(session.id, session.messages, state_dir: state_dir, running: running&.dup)
|
|
109
|
+
def announce(session, view:)
|
|
112
110
|
return if view.nil? || view == @announced
|
|
113
111
|
|
|
114
112
|
@announced = view
|
data/lib/samagotchi/version.rb
CHANGED
|
@@ -448,12 +448,14 @@ const questionCards = createQuestionCards({
|
|
|
448
448
|
isNearBottom: () => isNearBottom(),
|
|
449
449
|
scrollToEnd: () => { historyEl.scrollTop = historyEl.scrollHeight; },
|
|
450
450
|
removeHintIfEmpty: () => removeHintIfEmpty(),
|
|
451
|
-
askingText: () => turnDom.askingText(),
|
|
451
|
+
askingText: (pq) => turnDom.askingText(pq),
|
|
452
452
|
renderMarkdown,
|
|
453
453
|
linkRefs: linkRefsIn,
|
|
454
454
|
pairRefs: pairRefsIn,
|
|
455
455
|
// The bar's chip reads questionCards.pendingQuestion() (sessionWaits).
|
|
456
456
|
onPending: () => store.touch("infoBar"),
|
|
457
|
+
// The stage's waiting cards as data (stage_waiting.js).
|
|
458
|
+
onSettled: (key) => turnDom.settleWaiting?.(key),
|
|
457
459
|
});
|
|
458
460
|
// The history's bubbles (bubbles.js): output, end lines, every client's
|
|
459
461
|
// prompts, the recap, warnings and notices, command and note bubbles.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// One observer per turn root, filtered to TEXTS, as copy.js and answer_fold.js:
|
|
3
3
|
// every path that fills a root (a reload, a session switch, a turn's end, an
|
|
4
4
|
// answer_display, Revise's clones, a step's swap) arrives the same way, and
|
|
5
|
-
// cards,
|
|
5
|
+
// cards, a lead-in bubble and question replies are never touched. A block is
|
|
6
6
|
// drawn when it comes near its scroller's view (a closed <details> opening is
|
|
7
7
|
// such a coming near), and one that moves to another scroller while it waits
|
|
8
8
|
// (the stage's hand-off to #history) is watched there.
|
|
@@ -15,6 +15,7 @@ import { stepText } from "./turn_block.js";
|
|
|
15
15
|
import { llmContextNotice, noticeLine } from "./turn_events.js";
|
|
16
16
|
import { hookNoticeTemplate, TURN_PROMPT, turnPromptBubbles } from "./bubbles.js";
|
|
17
17
|
import { stillOn } from "./latest.js";
|
|
18
|
+
import { pluginCardKey } from "./stage_waiting.js";
|
|
18
19
|
|
|
19
20
|
// The elements of the reloaded turn that ends before +before+ (the next
|
|
20
21
|
// turn's prompt, or null for the last turn), its prompt first.
|
|
@@ -71,15 +72,18 @@ export function createCardsPlace({
|
|
|
71
72
|
if (!card || !card.id) return;
|
|
72
73
|
turnDom.settleFold?.();
|
|
73
74
|
const existing = cardElement(card.id);
|
|
75
|
+
const asks = (card.actions || []).some((a) => a && a.command);
|
|
74
76
|
if (existing) {
|
|
75
77
|
const drawn = drawCard(existing, card);
|
|
76
78
|
drawn.classList.add("card-updated");
|
|
77
79
|
setTimeout(() => drawn.classList.remove("card-updated"), 900);
|
|
80
|
+
// Redrawn without its actions (check-in's card turned into its notice
|
|
81
|
+
// row): it no longer asks (stage_waiting.js).
|
|
82
|
+
if (!asks) turnDom.settleWaiting?.(pluginCardKey(card.id), { only: "asks" });
|
|
78
83
|
return;
|
|
79
84
|
}
|
|
80
85
|
bubbles.removeHintIfEmpty();
|
|
81
86
|
const el = drawCard(document.createElement(isNoticeCard(card) ? "details" : "div"), card);
|
|
82
|
-
const asks = (card.actions || []).some((a) => a && a.command);
|
|
83
87
|
if (card.in_turn && !before && !asks && turnDom.card(el)) return;
|
|
84
88
|
bubbles.placeFollowing(el, before);
|
|
85
89
|
}
|
|
@@ -45,9 +45,11 @@ export function createDockReserve({
|
|
|
45
45
|
// A reader at the end stays there when the reserve changes: at once for the
|
|
46
46
|
// composer card, eased for the stage (+fromStage+: it appeared, grew or
|
|
47
47
|
// leaves), so the history glides rather than jumps. An eased follow running
|
|
48
|
-
// counts as at the end.
|
|
48
|
+
// counts as at the end. Not while the history is marked data-reading (a
|
|
49
|
+
// reason bubble read from its first line, stage_opened.js).
|
|
49
50
|
function updateReserve({ fromStage = false } = {}) {
|
|
50
|
-
const
|
|
51
|
+
const reading = historyEl.dataset.reading !== undefined;
|
|
52
|
+
const follow = !reading && (atHistoryEnd() || historyEl.dataset.following !== undefined);
|
|
51
53
|
const leaving = stageEl.classList.contains("leaving");
|
|
52
54
|
centerEl.classList.toggle("reserve-easing", leaving);
|
|
53
55
|
const reserve = `${dockReserve()}px`;
|
|
@@ -94,6 +96,14 @@ export function createDockReserve({
|
|
|
94
96
|
updateReserve({ fromStage: true });
|
|
95
97
|
}).observe(stageEl, { attributes: true, attributeFilter: ["class", "hidden"] });
|
|
96
98
|
win.addEventListener("resize", () => placeToast());
|
|
99
|
+
// The dock is on the history's column (index.html): a classic scrollbar
|
|
100
|
+
// (always shown) narrows the history's content box on the right, and the
|
|
101
|
+
// dock's right edge follows it (--history-sb, 0 with overlay scrollbars).
|
|
102
|
+
function scrollbarGutter() {
|
|
103
|
+
const sb = `${Math.max(0, historyEl.offsetWidth - historyEl.clientWidth)}px`;
|
|
104
|
+
if (centerEl.style.getPropertyValue("--history-sb") !== sb) centerEl.style.setProperty("--history-sb", sb);
|
|
105
|
+
}
|
|
106
|
+
new win.ResizeObserver(() => scrollbarGutter()).observe(historyEl);
|
|
97
107
|
// The model panel opening, closing or changing height (its list filters).
|
|
98
108
|
new win.ResizeObserver(() => placeToast()).observe(modelPanelEl);
|
|
99
109
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The one way the stage moves a turn's pieces into the history
|
|
2
|
+
// (stage_view.js): to its end, in the order given (the hand-off's
|
|
3
|
+
// handOffOrder, or what a turn opened in the history sends there as it
|
|
4
|
+
// arrives). The original nodes move (their ref bindings, selection and late
|
|
5
|
+
// updates with them); the empty history's hint goes first. +animate+: each
|
|
6
|
+
// piece arrives with .ts-arrive (gone at its animationend).
|
|
7
|
+
export function moveToHistoryEnd(historyEl, pieces, { animate = false } = {}) {
|
|
8
|
+
historyEl.querySelector(":scope > .hint")?.remove();
|
|
9
|
+
for (const el of pieces) {
|
|
10
|
+
historyEl.appendChild(el);
|
|
11
|
+
if (animate) {
|
|
12
|
+
el.classList.add("ts-arrive");
|
|
13
|
+
el.addEventListener("animationend", () => el.classList.remove("ts-arrive"), { once: true });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|