samagotchi 0.168.0 → 0.170.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -1
  3. data/docs/architecture.md +1 -1
  4. data/docs/configuration.md +1 -1
  5. data/docs/guardrails.md +2 -2
  6. data/docs/hooks.md +2 -2
  7. data/docs/internals/block-renderers.md +1 -1
  8. data/docs/internals/bridge.md +19 -4
  9. data/docs/internals/inline-widgets.md +1 -1
  10. data/docs/internals/objectives.md +2 -1
  11. data/docs/internals/remote-sessions.md +1 -1
  12. data/docs/internals/web-frontend.md +72 -29
  13. data/docs/internals/working-set.md +2 -1
  14. data/docs/plugins.md +1 -1
  15. data/docs/releasing.md +13 -7
  16. data/docs/testing.md +22 -5
  17. data/lib/samagotchi/bridge.rb +25 -2
  18. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  19. data/lib/samagotchi/client_id.rb +3 -0
  20. data/lib/samagotchi/command_intake.rb +7 -7
  21. data/lib/samagotchi/compat.rb +14 -5
  22. data/lib/samagotchi/engine/events.rb +9 -0
  23. data/lib/samagotchi/engine/objectives.rb +10 -1
  24. data/lib/samagotchi/engine.rb +1 -1
  25. data/lib/samagotchi/event_fanout.rb +4 -7
  26. data/lib/samagotchi/guardrails/approvals.rb +8 -3
  27. data/lib/samagotchi/session_continue.rb +8 -11
  28. data/lib/samagotchi/session_manager/removal.rb +3 -3
  29. data/lib/samagotchi/session_stores.rb +79 -0
  30. data/lib/samagotchi/turn_stages/objectives.rb +6 -8
  31. data/lib/samagotchi/version.rb +1 -1
  32. data/lib/samagotchi/web/app.rb +17 -2
  33. data/lib/samagotchi/web/public/app.js +4 -1
  34. data/lib/samagotchi/web/public/block_watch.js +1 -1
  35. data/lib/samagotchi/web/public/cards_place.js +5 -1
  36. data/lib/samagotchi/web/public/index.html +67 -39
  37. data/lib/samagotchi/web/public/live_timing.js +5 -3
  38. data/lib/samagotchi/web/public/markdown_place.js +1 -1
  39. data/lib/samagotchi/web/public/question_cards.js +30 -7
  40. data/lib/samagotchi/web/public/stage_asking.js +283 -0
  41. data/lib/samagotchi/web/public/stage_frame.js +8 -12
  42. data/lib/samagotchi/web/public/stage_model.js +47 -14
  43. data/lib/samagotchi/web/public/stage_opened.js +33 -20
  44. data/lib/samagotchi/web/public/stage_slots.js +13 -89
  45. data/lib/samagotchi/web/public/stage_view.js +235 -170
  46. data/lib/samagotchi/web/public/stage_waiting.js +180 -0
  47. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  48. data/lib/samagotchi/web/public/turn_model.js +1 -1
  49. data/lib/samagotchi/web/session_control.rb +3 -1
  50. data/lib/samagotchi/web/session_hub.rb +16 -0
  51. data/lib/samagotchi/web/session_show.rb +14 -4
  52. data/lib/samagotchi/worker.rb +3 -4
  53. metadata +4 -1
@@ -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",
@@ -89,6 +90,7 @@ module Samagotchi
89
90
  relay_desk: "relay-store reference; status is monitor-protected",
90
91
  request_recap: "idle-recap monitor",
91
92
  reserve_enqueued_id: "turn-state monitor",
93
+ working_set_snapshot: "idle working-set snapshot under event lock",
92
94
  "running_turn_messages=": "callback writer; Bridge lifecycle",
93
95
  saved_recap: "recap mutex; replace-only session messages",
94
96
  session: "session reference; messages are replace-only",
@@ -366,20 +368,38 @@ module Samagotchi
366
368
  # working_set: the running turn's last :working_set_updated ({items:,
367
369
  # at:}, TurnAccumulator#working_set), which the messages lag; nil
368
370
  # between turns and before the turn emitted one.
371
+ # idle_working_set: what the worker would announce between turns
372
+ # ({items:, at:}, with adds: when present), built under the next turn's
373
+ # strategy; absent while a turn runs or if the build fails.
369
374
  # last_turn_drawing: the last prompt's turn as live drew it ({drawing:,
370
375
  # end:}, the file's line for that turn id, not unfolded: an attaching
371
376
  # TUI unfolds it, TurnAccumulator.replay_events), only while it holds
372
377
  # against these messages; a reminder's, a Continue's or a note after it
373
378
  # hides it no more. Absent otherwise (no prompt with a turn id, a
374
379
  # rollback, an older worker's file).
380
+ # objectives: the view this worker announces, computed with the running
381
+ # conversation too; nil when there is no list, absent if reading it fails.
375
382
  # @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:}
383
+ # guardrail_warning:, plugin_warning:, init_tasks:, cards:, commands:, chi_version:, event_seq:, event_id:, last_turn_drawing:,
384
+ # objectives:, idle_working_set:}
377
385
  def snapshot
378
386
  @engine.synchronize_events do
379
387
  seq = @engine.event_count
380
388
  messages = @engine.messages_checkpoint
381
389
  drawing = last_turn_drawing(messages)
382
- {
390
+ idle_working_set_unavailable = Object.new
391
+ idle_working_set = if @engine.turn_running?
392
+ idle_working_set_unavailable
393
+ else
394
+ Degrade.call(:bridge, "working_set_snapshot_failed", fallback: idle_working_set_unavailable) do
395
+ @engine.working_set_snapshot&.to_h || idle_working_set_unavailable
396
+ end
397
+ end
398
+ objectives_unavailable = Object.new
399
+ objectives = Degrade.call(:bridge, "objectives_snapshot_failed", fallback: objectives_unavailable) do
400
+ @engine.objectives_view(@session_id, messages, state_dir: @state_dir)
401
+ end
402
+ snapshot = {
383
403
  messages: messages,
384
404
  current_turn: current_turn_with_generation,
385
405
  working_set: @accumulator.working_set,
@@ -398,6 +418,9 @@ module Samagotchi
398
418
  event_seq: seq,
399
419
  event_id: event_id(seq)
400
420
  }.merge(drawing ? { last_turn_drawing: drawing } : {})
421
+ snapshot[:objectives] = objectives unless objectives.equal?(objectives_unavailable)
422
+ snapshot[:idle_working_set] = idle_working_set unless idle_working_set.equal?(idle_working_set_unavailable)
423
+ snapshot
401
424
  end
402
425
  end
403
426
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.168.0
3
+ version: 0.170.0
4
4
  scope: system
5
5
  description: Default system memories — identity, self map, config modification protocol, memory guide and the delegated-session rules
6
6
  files:
@@ -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: a
39
- # human's input (ClientId.human?: a web tab, a chi TUI, chi send, no
40
- # client) but a participant's (review:, refused on its own), and chi
41
- # answer's. A delegate, a child's report, a context or task wake, a
42
- # schedule, a reminder, a relay and a plugin may not (the bundles that
43
- # send, coordinator and skills, send prose).
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) || (ClientId.human?(client_id) && !ClientId.review?(client_id))
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:
@@ -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,23 +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
- "period after the release that wrote version 2 (0.151.0, 2026-11-05)")
24
+ "period after the release that wrote version 2 (0.151.0, 2026-11-05)"),
25
+ Shim.new(id: :approvals_bare_list, added_in: "0.169.0", added_on: "2026-11-12", remove_after: "0.172.0",
26
+ files: ["lib/samagotchi/guardrails/approvals.rb"],
27
+ what: "Approvals reads the bare list written by chi 0.166 and before, converting it on write")
22
28
  ].freeze
23
29
 
24
30
  module_function
25
31
 
26
32
  # The shims +version+ has passed the remove_after of.
27
33
  # @return [Array<Shim>]
28
- def overdue_shims(version: VERSION, shims: SHIMS)
34
+ def overdue_shims(version: VERSION, shims: SHIMS, today: Date.today)
29
35
  current = Gem::Version.new(version)
30
- shims.select { |shim| shim.remove_after && current > Gem::Version.new(shim.remove_after) }
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
31
40
  end
32
41
 
33
42
  def verdict(worker_version:, version: VERSION, worker_protocol: nil, protocol: nil)
@@ -73,6 +73,15 @@ module Samagotchi
73
73
  synchronize_events { emit_working_set(nil, session, session.messages) }
74
74
  end
75
75
 
76
+ # The working set the session would announce for +conversation+ under
77
+ # the next turn's strategy.
78
+ def working_set_snapshot(session = @session, conversation = session&.messages)
79
+ return unless session && conversation
80
+
81
+ WorkingSet.build(conversation, cwd: session.working_directory, strategy: working_set_strategy,
82
+ pins: session.working_set_pins)
83
+ end
84
+
76
85
  # ── Load events ───────────────────────────────────────────────────────
77
86
 
78
87
  # Announce what failed to load and what plugins showed while loading,
@@ -19,13 +19,22 @@ module Samagotchi
19
19
  return unless session
20
20
 
21
21
  synchronize_events do
22
- event = @objectives_stage.announce(session, state_dir: session_state_dir, running: live_conversation)
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
@@ -526,7 +526,7 @@ module Samagotchi
526
526
  live_conversation: -> { live_conversation },
527
527
  used_memory_names: -> { used_memory_names },
528
528
  served_expected_by: ->(served) { served_expected_by(served) },
529
- working_set_strategy: -> { working_set_strategy },
529
+ working_set_snapshot: ->(session, conversation) { working_set_snapshot(session, conversation) },
530
530
  turn_running: -> { turn_running? },
531
531
  announce_or_hold: ->(event) { announce_or_hold(event) }
532
532
  )
@@ -3,7 +3,6 @@
3
3
  require_relative "hooks"
4
4
  require_relative "log"
5
5
  require_relative "steer_cut"
6
- require_relative "working_set"
7
6
 
8
7
  module Samagotchi
9
8
  # How one of an Engine's events reaches the turn's sink and the persistent
@@ -33,12 +32,12 @@ module Samagotchi
33
32
  # @param live_conversation [#call] → Array<Hash>, the running turn's conversation
34
33
  # @param used_memory_names [#call] → Array<String>
35
34
  # @param served_expected_by [#call] (served) → the host expecting the served model
36
- # @param working_set_strategy [#call] → the strategy the working set is built under
35
+ # @param working_set_snapshot [#call] (session, conversation) → WorkingSet::Snapshot
37
36
  # @param turn_running [#call] → Boolean
38
37
  # @param announce_or_hold [#call] (event) → announces the event, or holds it
39
38
  def initialize(observer:, used_memories:, muted:, steer_cut:, thinking_notices:, metrics:, hooks:, turn_context:,
40
39
  last_turn_context:, model_settings:, session:, live_conversation:, used_memory_names:, served_expected_by:,
41
- working_set_strategy:, turn_running:, announce_or_hold:)
40
+ working_set_snapshot:, turn_running:, announce_or_hold:)
42
41
  @observer = observer
43
42
  @used_memories = used_memories
44
43
  @muted = muted
@@ -53,7 +52,7 @@ module Samagotchi
53
52
  @live_conversation = live_conversation
54
53
  @used_memory_names = used_memory_names
55
54
  @served_expected_by = served_expected_by
56
- @working_set_strategy = working_set_strategy
55
+ @working_set_snapshot = working_set_snapshot
57
56
  @turn_running = turn_running
58
57
  @announce_or_hold = announce_or_hold
59
58
  @working_set_emitted = nil
@@ -132,8 +131,7 @@ module Samagotchi
132
131
  def emit_working_set(on_event, session, conversation)
133
132
  return unless session && conversation
134
133
 
135
- snapshot = WorkingSet.build(conversation, cwd: session.working_directory, strategy: working_set_strategy,
136
- pins: session.working_set_pins)
134
+ snapshot = @working_set_snapshot.call(session, conversation)
137
135
 
138
136
  shown = snapshot.to_h.except(:at)
139
137
  last = @working_set_emitted
@@ -234,7 +232,6 @@ module Samagotchi
234
232
  def live_conversation = @live_conversation.call
235
233
  def used_memory_names = @used_memory_names.call
236
234
  def served_expected_by(served) = @served_expected_by.call(served)
237
- def working_set_strategy = @working_set_strategy.call
238
235
  def turn_running? = @turn_running.call
239
236
  def announce_or_hold(event) = @announce_or_hold.call(event)
240
237
  end
@@ -30,8 +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 bare list of entries (what 0.166 and before wrote) is not
34
- # a versioned store: it is set aside like an unreadable file.
33
+ # know. A bare list of entries (what 0.166 and before wrote) is read and
34
+ # becomes versioned on the next write.
35
35
  class Approvals
36
36
  FILE = "approvals.json"
37
37
  COLLECTION = "approvals"
@@ -192,6 +192,10 @@ module Samagotchi
192
192
  def parse(text)
193
193
  data = JSON.parse(text)
194
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]
195
199
  when Hash
196
200
  raise JSON::ParserError, "#{COLLECTION} is not a list" unless data.fetch(COLLECTION, []).is_a?(Array)
197
201
 
@@ -199,7 +203,8 @@ module Samagotchi
199
203
  # An entry it can't read (no scope) is kept as it is: it matches
200
204
  # nothing, and a write keeps it for the chi that wrote it.
201
205
  [document.entries.map(&:raw).select { |e| e.is_a?(Hash) }, document]
202
- else raise JSON::ParserError, "not a versioned store"
206
+ else
207
+ raise JSON::ParserError, "not a versioned store"
203
208
  end
204
209
  end
205
210
 
@@ -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 = %i[
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 (Objectives.view), when
101
- # that differs from the last announced: after an edit (its file written,
102
- # pending), once a list note is in, at a turn's end (its moves) and after
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 state_dir [String] the sessions dir
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, state_dir:, running:)
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Samagotchi
4
- VERSION = "0.168.0"
4
+ VERSION = "0.170.0"
5
5
  # Sent as the User-Agent of every HTTP request chi makes.
6
6
  USER_AGENT = "chi/#{VERSION}"
7
7
  end
@@ -1404,11 +1404,15 @@ module Samagotchi
1404
1404
  def handle_working_set(_req, id)
1405
1405
  session = @session_class.load(id, state_dir: default_state_dir)
1406
1406
  live = bridge_get_json(id, "snapshot")
1407
- running = !live&.dig("snapshot", "current_turn").nil?
1407
+ worker_snapshot = live && live["snapshot"]
1408
+ running = !worker_snapshot&.dig("current_turn").nil?
1408
1409
  turn_set = running && running_working_set(live["snapshot"]["working_set"])
1409
1410
  return json_response(200, turn_set.merge(running: true)) if turn_set
1410
1411
 
1411
- messages = live_or_saved(live && live["snapshot"], "messages") { session.messages }
1412
+ idle_set = idle_working_set(worker_snapshot && worker_snapshot["idle_working_set"]) unless running
1413
+ return json_response(200, idle_set.merge(running: false)) if idle_set
1414
+
1415
+ messages = live_or_saved(worker_snapshot, "messages") { session.messages }
1412
1416
  # A snapshot's entries have string keys (paired_runs reads symbols).
1413
1417
  messages = Array(messages).map { |message| message.is_a?(Hash) ? message.transform_keys(&:to_sym) : message }
1414
1418
  llm_context = SessionSetting::LLM_CONTEXT.snapshot_value(live && live["session_state_snapshot"]) do
@@ -1427,6 +1431,17 @@ module Samagotchi
1427
1431
  { items: set["items"], at: set["at"] }
1428
1432
  end
1429
1433
 
1434
+ # The worker's between-turns working set ({"items", "at", optional
1435
+ # "adds"}); nil for an older or malformed snapshot.
1436
+ def idle_working_set(set)
1437
+ return nil unless set.is_a?(Hash) && set["items"].is_a?(Array) && set["at"].is_a?(Integer)
1438
+ return nil if set.key?("adds") && !set["adds"].is_a?(Array)
1439
+
1440
+ { items: set["items"], at: set["at"] }.tap do |snapshot|
1441
+ snapshot[:adds] = set["adds"] if set.key?("adds")
1442
+ end
1443
+ end
1444
+
1430
1445
  # The strategy an llm_context summary names ("none", "stale,forget"), as
1431
1446
  # LLMContextView takes it; none when there is no chip.
1432
1447
  def working_set_strategy(llm_context)
@@ -404,6 +404,7 @@ const liveTurn = createLiveTurn({
404
404
  (stageHost || historyEl).appendChild(el);
405
405
  return !!stageHost;
406
406
  },
407
+ stageToolRunning: () => turnDom.callClockActive?.() ?? false,
407
408
  // The stage's quiet signal and tool clock tick with it (?.: a stage_view.js an open tab loaded before).
408
409
  onTick: () => { store.touch("infoBar"); turnDom.tick?.(); },
409
410
  });
@@ -448,12 +449,14 @@ const questionCards = createQuestionCards({
448
449
  isNearBottom: () => isNearBottom(),
449
450
  scrollToEnd: () => { historyEl.scrollTop = historyEl.scrollHeight; },
450
451
  removeHintIfEmpty: () => removeHintIfEmpty(),
451
- askingText: () => turnDom.askingText(),
452
+ askingText: (pq) => turnDom.askingText(pq),
452
453
  renderMarkdown,
453
454
  linkRefs: linkRefsIn,
454
455
  pairRefs: pairRefsIn,
455
456
  // The bar's chip reads questionCards.pendingQuestion() (sessionWaits).
456
457
  onPending: () => store.touch("infoBar"),
458
+ // The stage's waiting cards as data (stage_waiting.js).
459
+ onSettled: (key) => turnDom.settleWaiting?.(key),
457
460
  });
458
461
  // The history's bubbles (bubbles.js): output, end lines, every client's
459
462
  // 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, the asking slot and question replies are never touched. A block is
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
  }