samagotchi 0.192.0 → 0.194.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 (190) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +128 -1
  3. data/docs/architecture.md +3 -3
  4. data/docs/bundle-authoring.md +1 -1
  5. data/docs/bundles.md +82 -40
  6. data/docs/cli.md +47 -17
  7. data/docs/configuration.md +75 -8
  8. data/docs/context.md +8 -5
  9. data/docs/desktop.md +3 -0
  10. data/docs/guardrails.md +20 -5
  11. data/docs/hooks.md +1 -0
  12. data/docs/internals/bridge.md +3 -1
  13. data/docs/internals/bundles.md +2 -2
  14. data/docs/internals/engine.md +46 -3
  15. data/docs/internals/pages.md +4 -4
  16. data/docs/internals/panes.md +66 -0
  17. data/docs/internals/participants.md +5 -3
  18. data/docs/internals/peers.md +176 -27
  19. data/docs/internals/prompt-caching.md +6 -1
  20. data/docs/internals/remote-sessions.md +6 -0
  21. data/docs/internals/session-lifecycle.md +12 -4
  22. data/docs/internals/web-frontend.md +106 -22
  23. data/docs/internals/working-set.md +5 -1
  24. data/docs/peers.md +150 -27
  25. data/docs/plugins.md +48 -7
  26. data/docs/releasing.md +30 -2
  27. data/docs/scheduling.md +3 -2
  28. data/docs/sessions.md +16 -7
  29. data/docs/sub-agent.md +6 -4
  30. data/docs/system-one.md +4 -0
  31. data/docs/testing.md +38 -3
  32. data/docs/thin-clients.md +27 -11
  33. data/lib/samagotchi/bridge/card_store.rb +1 -1
  34. data/lib/samagotchi/broadcast/triage_model.rb +17 -0
  35. data/lib/samagotchi/bundles/claude-peer/manifest.yml +8 -5
  36. data/lib/samagotchi/bundles/claude-peer/plugin.rb +24 -5
  37. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +61 -24
  38. data/lib/samagotchi/bundles/claude-peer/scripts/pair +31 -8
  39. data/lib/samagotchi/bundles/codex-peer/manifest.yml +8 -5
  40. data/lib/samagotchi/bundles/codex-peer/plugin.rb +62 -6
  41. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +57 -19
  42. data/lib/samagotchi/bundles/codex-peer/scripts/pair +28 -7
  43. data/lib/samagotchi/bundles/coordinator/manifest.yml +2 -2
  44. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +31 -0
  45. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  46. data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
  47. data/lib/samagotchi/bundles/mcp/plugin.rb +0 -7
  48. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  49. data/lib/samagotchi/chi_invocation.rb +7 -0
  50. data/lib/samagotchi/client.rb +18 -0
  51. data/lib/samagotchi/codex_rollout.rb +93 -0
  52. data/lib/samagotchi/compat.rb +8 -1
  53. data/lib/samagotchi/config.rb +19 -6
  54. data/lib/samagotchi/continue_offer.rb +13 -1
  55. data/lib/samagotchi/delivery.rb +2 -2
  56. data/lib/samagotchi/effective_model.rb +28 -2
  57. data/lib/samagotchi/engine/cards.rb +9 -4
  58. data/lib/samagotchi/engine/hooks.rb +8 -0
  59. data/lib/samagotchi/engine/models.rb +197 -7
  60. data/lib/samagotchi/engine/plugins.rb +2 -0
  61. data/lib/samagotchi/engine/side_requests.rb +72 -13
  62. data/lib/samagotchi/engine/toolkit.rb +1 -1
  63. data/lib/samagotchi/engine/turn_helpers.rb +1 -1
  64. data/lib/samagotchi/engine.rb +11 -8
  65. data/lib/samagotchi/engine_snapshots.rb +16 -3
  66. data/lib/samagotchi/events.rb +1 -0
  67. data/lib/samagotchi/guardrails/pair_boundary.rb +49 -18
  68. data/lib/samagotchi/hooks.rb +3 -1
  69. data/lib/samagotchi/host_registry.rb +146 -16
  70. data/lib/samagotchi/idle_client.rb +13 -2
  71. data/lib/samagotchi/idle_recap.rb +33 -3
  72. data/lib/samagotchi/idle_target.rb +27 -7
  73. data/lib/samagotchi/jsonl_store.rb +13 -2
  74. data/lib/samagotchi/llm/adapter_common.rb +4 -2
  75. data/lib/samagotchi/llm/anthropic_messages.rb +14 -2
  76. data/lib/samagotchi/llm/errors.rb +35 -4
  77. data/lib/samagotchi/llm/model_listing.rb +19 -0
  78. data/lib/samagotchi/llm/openai_chat.rb +8 -2
  79. data/lib/samagotchi/llm/prompt_cache.rb +5 -0
  80. data/lib/samagotchi/model_binding.rb +46 -4
  81. data/lib/samagotchi/model_catalog.rb +68 -8
  82. data/lib/samagotchi/model_profile.rb +35 -0
  83. data/lib/samagotchi/models_command.rb +8 -4
  84. data/lib/samagotchi/pages/launch.rb +1 -1
  85. data/lib/samagotchi/panes/kitty.rb +122 -0
  86. data/lib/samagotchi/panes.rb +185 -0
  87. data/lib/samagotchi/peer_announce.rb +245 -0
  88. data/lib/samagotchi/peer_cold.rb +92 -0
  89. data/lib/samagotchi/peer_command.rb +121 -20
  90. data/lib/samagotchi/peer_continue.rb +42 -16
  91. data/lib/samagotchi/peer_exchanges.rb +7 -0
  92. data/lib/samagotchi/peer_mailbox.rb +50 -10
  93. data/lib/samagotchi/peer_pair_here.rb +149 -0
  94. data/lib/samagotchi/peer_presence.rb +434 -0
  95. data/lib/samagotchi/peer_receipts.rb +33 -6
  96. data/lib/samagotchi/peer_say.rb +46 -21
  97. data/lib/samagotchi/peer_wait_expiry.rb +47 -0
  98. data/lib/samagotchi/plugin/api.rb +13 -1
  99. data/lib/samagotchi/plugin/card.rb +68 -11
  100. data/lib/samagotchi/plugin/context.rb +33 -2
  101. data/lib/samagotchi/plugin/panes.rb +54 -0
  102. data/lib/samagotchi/plugin/peer.rb +170 -63
  103. data/lib/samagotchi/plugin/peer_pairing.rb +290 -0
  104. data/lib/samagotchi/plugin/peer_start.rb +301 -0
  105. data/lib/samagotchi/plugin/peer_start_hook.rb +207 -0
  106. data/lib/samagotchi/plugin/peers.rb +89 -9
  107. data/lib/samagotchi/recap_setup.rb +40 -3
  108. data/lib/samagotchi/self_report.rb +25 -6
  109. data/lib/samagotchi/send_command.rb +6 -6
  110. data/lib/samagotchi/served_lookup.rb +225 -0
  111. data/lib/samagotchi/served_ref.rb +41 -0
  112. data/lib/samagotchi/session_access/contract.rb +6 -0
  113. data/lib/samagotchi/session_access/local.rb +149 -40
  114. data/lib/samagotchi/session_access/remote.rb +4 -4
  115. data/lib/samagotchi/session_access/remote_peers.rb +8 -5
  116. data/lib/samagotchi/session_chain/links.rb +8 -3
  117. data/lib/samagotchi/session_commands.rb +40 -8
  118. data/lib/samagotchi/session_continue.rb +11 -6
  119. data/lib/samagotchi/session_lifecycle/allowed.rb +4 -2
  120. data/lib/samagotchi/session_manager/delivery.rb +5 -0
  121. data/lib/samagotchi/session_manager/lifecycle.rb +58 -7
  122. data/lib/samagotchi/session_manager/removal.rb +3 -0
  123. data/lib/samagotchi/session_manager/spawn.rb +6 -1
  124. data/lib/samagotchi/session_model_settings.rb +7 -3
  125. data/lib/samagotchi/session_stores.rb +25 -11
  126. data/lib/samagotchi/sessions_command.rb +16 -3
  127. data/lib/samagotchi/system_one/http_backend.rb +111 -10
  128. data/lib/samagotchi/system_one/runs.rb +5 -2
  129. data/lib/samagotchi/system_prompt.rb +11 -4
  130. data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -1
  131. data/lib/samagotchi/terminal_ui/formatting.rb +26 -12
  132. data/lib/samagotchi/terminal_ui/status_row.rb +20 -3
  133. data/lib/samagotchi/terminal_ui.rb +1 -1
  134. data/lib/samagotchi/testing/boundary.rb +0 -1
  135. data/lib/samagotchi/testing/bundle.rb +6 -2
  136. data/lib/samagotchi/testing/host.rb +1 -0
  137. data/lib/samagotchi/testing/recorder.rb +3 -0
  138. data/lib/samagotchi/turn_endings.rb +6 -2
  139. data/lib/samagotchi/user_typed.rb +29 -0
  140. data/lib/samagotchi/version.rb +1 -1
  141. data/lib/samagotchi/web/app.rb +8 -20
  142. data/lib/samagotchi/web/participant_review.rb +1 -1
  143. data/lib/samagotchi/web/participant_view.rb +1 -1
  144. data/lib/samagotchi/web/peer_routes.rb +40 -15
  145. data/lib/samagotchi/web/public/agent_rows.js +206 -0
  146. data/lib/samagotchi/web/public/agent_runs.js +595 -0
  147. data/lib/samagotchi/web/public/answer_fold.js +41 -44
  148. data/lib/samagotchi/web/public/app.js +4 -4
  149. data/lib/samagotchi/web/public/block_fix.js +1 -1
  150. data/lib/samagotchi/web/public/card.js +26 -10
  151. data/lib/samagotchi/web/public/cards_place.js +6 -4
  152. data/lib/samagotchi/web/public/context_chips.js +24 -2
  153. data/lib/samagotchi/web/public/copy.js +8 -2
  154. data/lib/samagotchi/web/public/data.js +2 -1
  155. data/lib/samagotchi/web/public/format.js +9 -1
  156. data/lib/samagotchi/web/public/history_reveal.js +5 -2
  157. data/lib/samagotchi/web/public/index.html +56 -2
  158. data/lib/samagotchi/web/public/info_bar_model.js +1 -1
  159. data/lib/samagotchi/web/public/model_pick.js +18 -5
  160. data/lib/samagotchi/web/public/model_picker.js +1 -1
  161. data/lib/samagotchi/web/public/page_view.js +1 -1
  162. data/lib/samagotchi/web/public/pages.css +1 -7
  163. data/lib/samagotchi/web/public/peer_chip.js +15 -5
  164. data/lib/samagotchi/web/public/peer_data.js +4 -2
  165. data/lib/samagotchi/web/public/peer_mailbox_api.js +2 -1
  166. data/lib/samagotchi/web/public/peer_note.js +4 -2
  167. data/lib/samagotchi/web/public/peer_row.js +37 -0
  168. data/lib/samagotchi/web/public/peer_wait.js +36 -0
  169. data/lib/samagotchi/web/public/quiet_notes.js +12 -1
  170. data/lib/samagotchi/web/public/revise_stack.js +5 -2
  171. data/lib/samagotchi/web/public/send_turn.js +11 -3
  172. data/lib/samagotchi/web/public/served_ref.js +9 -0
  173. data/lib/samagotchi/web/public/session_fields.js +1 -0
  174. data/lib/samagotchi/web/public/session_state.js +4 -0
  175. data/lib/samagotchi/web/public/stage_missing.js +23 -6
  176. data/lib/samagotchi/web/public/stream_handlers.js +16 -0
  177. data/lib/samagotchi/web/public/turn_block.js +4 -0
  178. data/lib/samagotchi/web/public/version_notices.js +7 -1
  179. data/lib/samagotchi/web/session_control.rb +19 -10
  180. data/lib/samagotchi/web/session_show.rb +20 -0
  181. data/lib/samagotchi/web/update_ops.rb +2 -2
  182. data/lib/samagotchi/worker/command_queue.rb +3 -0
  183. data/lib/samagotchi/worker/mail.rb +24 -1
  184. data/lib/samagotchi/worker.rb +8 -5
  185. data/lib/samagotchi/worker_inbound/mail.rb +34 -6
  186. data/lib/samagotchi/worker_inbound.rb +11 -3
  187. data/lib/samagotchi/worker_link.rb +13 -1
  188. data/lib/samagotchi/worker_wakes.rb +33 -5
  189. metadata +22 -2
  190. data/lib/samagotchi/web/public/pages_group.js +0 -67
@@ -259,8 +259,12 @@ module Samagotchi
259
259
  def start
260
260
  # A scratch worker's grace for its terminal's first stream counts from here.
261
261
  @started_at = monotonic_now
262
- # The wake turns' budget (delegate reports, attached context, peers), from now.
263
- @wakes = WorkerWakes.new(grace: WAKE_START_GRACE)
262
+ # What this worker did with each peer message (PeerReceipts, read once).
263
+ @peer_receipts = PeerReceipts.new(session_id: @session_id, state_dir: @state_dir)
264
+ # The wake turns' budget (delegate reports, attached context, peers), from
265
+ # now; the peer wakes in a row from where the last worker left them.
266
+ @wakes = WorkerWakes.new(grace: WAKE_START_GRACE, peer_in_a_row: @peer_receipts.peer_wakes,
267
+ on_peer_count: method(:save_peer_wakes))
264
268
  # This worker holds the session now (a continue's starting marker held
265
269
  # off any other until it did), and a continue that died moving
266
270
  # delegates here left its intent: finish it.
@@ -293,8 +297,6 @@ module Samagotchi
293
297
  @event_log.announce(type: :hook_notice, hook: "config", text: message, level: :warn, between_turns: true)
294
298
  end
295
299
  prune_tombstones
296
- # What this worker did with each peer message (PeerReceipts, read once).
297
- @peer_receipts = PeerReceipts.new(session_id: @session_id, state_dir: @state_dir)
298
300
  settle_interrupted_turn
299
301
  settle_stale_status
300
302
  # Before the Bridge serves anything: a UI joining a resumed worker's
@@ -363,7 +365,7 @@ module Samagotchi
363
365
  awaiting_continue: -> { @turn_flow.awaiting_continue? },
364
366
  stopped: -> { stopped_on_disk? },
365
367
  peer_registry: @engine.peer_registry, peer_receipts: @peer_receipts,
366
- mail_cap: -> { ToolOutputCut.max_chars(nil) },
368
+ mail_cap: -> { ToolOutputCut.max_chars(nil) }, cache_ttl: -> { @engine.remote_cache_ttl },
367
369
  queue_command: lambda { |line, client_id, after_file, enqueued_id, author: nil|
368
370
  @bridge.queue_command(line, client_id: client_id, after_file: after_file,
369
371
  enqueued_id: enqueued_id, author: author)
@@ -544,6 +546,7 @@ module Samagotchi
544
546
  leaving = @exit_claim.taken? && leave_on_request
545
547
  return left(leaving) if leaving
546
548
 
549
+ expire_peer_waits
547
550
  @participant_gate.watch
548
551
  @waker.wait(idle_wait)
549
552
  nil
@@ -8,6 +8,7 @@ require_relative "../client_id"
8
8
  require_relative "../context_note"
9
9
  require_relative "../log"
10
10
  require_relative "../peer_mailbox"
11
+ require_relative "../peer_cold"
11
12
  require_relative "../peer_note"
12
13
  require_relative "../peer_receipts"
13
14
  require_relative "../turn_origin"
@@ -37,7 +38,8 @@ module Samagotchi
37
38
  # The fourth inbound kind: a peer's messages from the mailbox
38
39
  # (PeerMailbox), one note each, between turns. Mixed into WorkerInbound;
39
40
  # reads @session, @engine, @wakes, @awaiting_continue, @stopped,
40
- # @peer_registry, @peer_receipts, @mail_cap. See docs/internals/peers.md.
41
+ # @peer_registry, @peer_receipts, @mail_cap, @cache_ttl, @wall_clock.
42
+ # See docs/internals/peers.md.
41
43
  module MailPart
42
44
  # The holds a caller gives (a wake can't run now) and the receipt's
43
45
  # reason for each, beside :off and WorkerWakes#wake_hold's.
@@ -70,7 +72,7 @@ module Samagotchi
70
72
  taken = items.select(&:taken?)
71
73
  asking = taken.select(&:asked).last
72
74
  @wakes.pause! if replayed && asking
73
- reason = (replayed && asking ? :paused : hold) || (mail_hold(asking) if asking)
75
+ reason = (replayed && asking ? :paused : hold) || (mail_hold(asking, taken) if asking)
74
76
  if asking && reason.nil? && @wakes.in_grace?
75
77
  @mail_wake_waiting = true
76
78
  return nil
@@ -123,16 +125,32 @@ module Samagotchi
123
125
  end
124
126
 
125
127
  # Why the batch's newest asking message can't wake chi now: :off
126
- # (peer.turns is 0), else WorkerWakes#wake_hold's (an agreeing
127
- # message is held by session.max_wakes only); nil: it may.
128
- def mail_hold(asking)
128
+ # (peer.turns is 0), :cold (#cold_hold?), else WorkerWakes#wake_hold's
129
+ # (an agreeing message is held by session.max_wakes only); nil: it may.
130
+ def mail_hold(asking, batch)
129
131
  return :off if @wakes.peer_max.zero?
132
+ return :cold if cold_hold?(batch)
130
133
 
131
134
  @wakes.wake_hold(awaiting_continue: @awaiting_continue.call, peer: !agreed?(asking))
132
135
  end
133
136
 
134
137
  def agreed?(item) = PeerNote.agrees?(item&.message&.summary)
135
138
 
139
+ # Whether the batch is held because chi's cache is cold (PeerCold):
140
+ # none of its asking messages is an answer chi asked for (a +re+
141
+ # naming one of its sends, PeerCold.asked_for?) that doesn't agree, and
142
+ # the cache is cold now. An answer chi asked for wakes it cold or warm.
143
+ def cold_hold?(batch)
144
+ asked = batch.select(&:asked)
145
+ return false if asked.any? { |item| !agreed?(item) && asked_for?(item) }
146
+
147
+ PeerCold.cold?(ttl: @cache_ttl&.call, last_turn: @session.last_turn, used_tokens: PeerCold.used_tokens(@session_dir),
148
+ now: @wall_clock.call)
149
+ end
150
+
151
+ def asked_for?(item) = PeerCold.asked_for?(item.message, item.peer, session_id: @session.id,
152
+ continues: @session.continues, state_dir: @state_dir)
153
+
136
154
  # The notes, in order; the last one starts the wake turn (+waking+),
137
155
  # with the wake line of the newest message that asked (+asking+).
138
156
  # @return [Hash, nil] the turn start's plain note
@@ -204,11 +222,21 @@ module Samagotchi
204
222
 
205
223
  # The UIs hear once that a peer's message waits for the user's next
206
224
  # one when a wake budget held it (as #peer_held does for the context
207
- # path).
225
+ # path), or a cold cache did (its own notice and once-flag).
208
226
  def mail_held(asking, reason)
227
+ return cold_held(PeerMailbox.label(asking.peer)) if asking && reason == :cold
228
+
209
229
  key = { max_wakes: ChildRing::MAX_WAKES_KEY, peer_turns: WorkerWakes::PEER_TURNS_KEY }[reason]
210
230
  peer_held(PeerMailbox.label(asking.peer), key) if asking && key
211
231
  end
232
+
233
+ def cold_held(label)
234
+ return unless @wakes.notice_peer_cold!
235
+
236
+ @event_log.announce(type: :hook_notice, hook: "context", level: :info, between_turns: true,
237
+ text: "#{label} spoke up while chi's cache is cold; it waits as a note for your next " \
238
+ "message (a turn now would read the whole conversation again)")
239
+ end
212
240
  end
213
241
  end
214
242
  end
@@ -105,8 +105,13 @@ module Samagotchi
105
105
  # @param peer_receipts [PeerReceipts, nil] the worker's receipts
106
106
  # @param mail_cap [#call, nil] the most characters of a peer's text a
107
107
  # wake turn's note holds (the tool output cap)
108
+ # @param cache_ttl [#call, nil] the host's prompt-cache TTL in seconds,
109
+ # nil when its requests carry no breakpoints (Engine#remote_cache_ttl:
110
+ # the cold hold)
111
+ # @param wall_clock [#call] the time now (the cold hold's)
108
112
  def initialize(session:, state_dir:, session_dir:, engine:, event_log:, turn_state:, context_absorber:, wakes:,
109
- awaiting_continue:, stopped:, queue_command:, peer_registry: nil, peer_receipts: nil, mail_cap: nil)
113
+ awaiting_continue:, stopped:, queue_command:, peer_registry: nil, peer_receipts: nil, mail_cap: nil,
114
+ cache_ttl: nil, wall_clock: -> { Time.now })
110
115
  @session = session
111
116
  @state_dir = state_dir
112
117
  @session_dir = session_dir
@@ -121,6 +126,8 @@ module Samagotchi
121
126
  @peer_registry = peer_registry
122
127
  @peer_receipts = peer_receipts
123
128
  @mail_cap = mail_cap
129
+ @cache_ttl = cache_ttl
130
+ @wall_clock = wall_clock
124
131
  @initial_prompt_taken = false
125
132
  @context_wake_waiting = false
126
133
  # The link this one continues, when its notes may still come here
@@ -258,8 +265,9 @@ module Samagotchi
258
265
  # (Session#first_turn_client_id: a delegating parent, a schedule). A
259
266
  # delegate child's task is its parent's even without the field (one
260
267
  # spawned by an older chi, or by a caller that names no sender). Else
261
- # the owner's (ClientId::FIRST_PROMPT): a person's session saves no
262
- # sender for its first prompt, nor did one from before either field.
268
+ # the owner's (ClientId::FIRST_PROMPT): chi send's and no sender's save
269
+ # none (a web tab's or a TUI's does, from this chi on), nor did one from
270
+ # before either field.
263
271
  # @return [TurnOrigin]
264
272
  def initial_origin
265
273
  client_id = @session.first_turn_client_id
@@ -33,7 +33,19 @@ module Samagotchi
33
33
  # Bridge).
34
34
  module WorkerLink
35
35
  # The sidecar protocol this chi speaks; a sidecar with a bigger one is a
36
- # newer worker's (Skew).
36
+ # newer worker's (Skew). The policy (docs/releasing.md, "Bumping
37
+ # WorkerLink::PROTOCOL"):
38
+ # - an additive link change (a new sidecar key, Bridge route or FEATURES
39
+ # name) is no bump: older clients ignore what they don't know;
40
+ # - bump only when an older client would do damage driving a newer
41
+ # worker: a sidecar key, route or feature name removed, renamed or given
42
+ # a new meaning, or the secret rule changed;
43
+ # - every bump needs the owner's OK and a CHANGELOG line ("older chi web
44
+ # and terminals refuse workers of this release until restarted"), and
45
+ # starts a new list in spec/worker_link_contract_spec.rb (which fails
46
+ # when an entry of this protocol's list goes);
47
+ # - a worker on an older protocol is never refused: a restart is
48
+ # suggested, never gated.
37
49
  PROTOCOL = 1
38
50
 
39
51
  # A worker whose sidecar publishes this may be asked what it is busy with
@@ -17,7 +17,11 @@ module Samagotchi
17
17
  # A peer agent's messages (its mailbox: WorkerInbound#absorb_mail) have a
18
18
  # budget of their own on top: peer.turns wake turns in a row,
19
19
  # reset only by input typed in the web or a TUI (ClientId.interactive?),
20
- # not by chi send, which a peer can run (docs/peers.md).
20
+ # not by chi send, which a peer can run (docs/peers.md). That count
21
+ # outlives the worker: it starts from +peer_in_a_row+ (what the last
22
+ # worker saved) and each change goes to +on_peer_count+ (the Worker saves
23
+ # it in peer_receipts.json), so a peer that speaks once per idle exit is
24
+ # held after peer.turns wakes as one that speaks every minute is.
21
25
  class WorkerWakes
22
26
  PEER_TURNS_KEY = "peer.turns"
23
27
  PEER_TURNS_DEFAULT = 3
@@ -26,18 +30,25 @@ module Samagotchi
26
30
  # @param clock [#call] monotonic seconds
27
31
  # @param max [#call, nil] the budget; nil reads session.max_wakes
28
32
  # @param peer_max [#call, nil] the peer budget; nil reads peer.turns
29
- def initialize(grace:, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, max: nil, peer_max: nil)
33
+ # @param peer_in_a_row [Integer] the peer wake turns in a row a previous
34
+ # worker left (PeerReceipts#peer_wakes)
35
+ # @param on_peer_count [#call, nil] called with the peer count each time
36
+ # it changes (on the loop thread)
37
+ def initialize(grace:, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, max: nil, peer_max: nil,
38
+ peer_in_a_row: 0, on_peer_count: nil)
30
39
  @grace = grace
31
40
  @clock = clock
32
41
  @max = max
33
42
  @peer_max = peer_max
34
43
  @started_at = clock.call
35
44
  @in_a_row = 0
36
- @peer_in_a_row = 0
45
+ @peer_in_a_row = peer_in_a_row.is_a?(Integer) && peer_in_a_row.positive? ? peer_in_a_row : 0
46
+ @on_peer_count = on_peer_count
37
47
  @paused = false
38
48
  @budget_noticed = false
39
49
  @visitor_noticed = false
40
50
  @peer_noticed = false
51
+ @cold_noticed = false
41
52
  @handed = nil
42
53
  end
43
54
 
@@ -134,7 +145,10 @@ module Samagotchi
134
145
  # A wake turn starts; +peer+: for a peer's answer, which counts toward
135
146
  # both budgets. @return [Integer] the wake turns in a row now
136
147
  def count!(peer: false)
137
- @peer_in_a_row += 1 if peer
148
+ if peer
149
+ @peer_in_a_row += 1
150
+ @on_peer_count&.call(@peer_in_a_row)
151
+ end
138
152
  @in_a_row += 1
139
153
  end
140
154
 
@@ -154,8 +168,12 @@ module Samagotchi
154
168
  @visitor_noticed = false
155
169
  return unless interactive
156
170
 
157
- @peer_in_a_row = 0
158
171
  @peer_noticed = false
172
+ @cold_noticed = false
173
+ return if @peer_in_a_row.zero?
174
+
175
+ @peer_in_a_row = 0
176
+ @on_peer_count&.call(0)
159
177
  end
160
178
 
161
179
  # @return [Boolean] true the first time the budget is spent since the
@@ -184,6 +202,16 @@ module Samagotchi
184
202
  @peer_noticed = true
185
203
  end
186
204
 
205
+ # @return [Boolean] true the first time a peer's message is held for a
206
+ # cold cache (WorkerInbound::MailPart, :cold) since the last
207
+ # interactive input: the UIs hear it once. Apart from
208
+ # #notice_peer_budget!, whose text is about turn counts.
209
+ def notice_peer_cold!
210
+ return false if @cold_noticed
211
+
212
+ @cold_noticed = true
213
+ end
214
+
187
215
  # The idle loop's sleep: +poll+, or less while a wake (the block says
188
216
  # one is due) waits out the start grace.
189
217
  def idle_wait(poll)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samagotchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.192.0
4
+ version: 0.194.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -167,6 +167,7 @@ files:
167
167
  - docs/internals/llm-context-live.md
168
168
  - docs/internals/objectives.md
169
169
  - docs/internals/pages.md
170
+ - docs/internals/panes.md
170
171
  - docs/internals/participants.md
171
172
  - docs/internals/peers.md
172
173
  - docs/internals/prompt-caching.md
@@ -340,6 +341,7 @@ files:
340
341
  - lib/samagotchi/cli/parent_wait.rb
341
342
  - lib/samagotchi/client.rb
342
343
  - lib/samagotchi/client_id.rb
344
+ - lib/samagotchi/codex_rollout.rb
343
345
  - lib/samagotchi/command_intake.rb
344
346
  - lib/samagotchi/command_steps.rb
345
347
  - lib/samagotchi/commands/registry.rb
@@ -624,6 +626,8 @@ files:
624
626
  - lib/samagotchi/pages/runner.rb
625
627
  - lib/samagotchi/pages/runtime.rb
626
628
  - lib/samagotchi/pages/store.rb
629
+ - lib/samagotchi/panes.rb
630
+ - lib/samagotchi/panes/kitty.rb
627
631
  - lib/samagotchi/parent_answers_command.rb
628
632
  - lib/samagotchi/parent_report.rb
629
633
  - lib/samagotchi/participant_exposure.rb
@@ -636,15 +640,20 @@ files:
636
640
  - lib/samagotchi/participants.rb
637
641
  - lib/samagotchi/participants_watch.rb
638
642
  - lib/samagotchi/paths.rb
643
+ - lib/samagotchi/peer_announce.rb
644
+ - lib/samagotchi/peer_cold.rb
639
645
  - lib/samagotchi/peer_command.rb
640
646
  - lib/samagotchi/peer_continue.rb
641
647
  - lib/samagotchi/peer_exchanges.rb
642
648
  - lib/samagotchi/peer_mailbox.rb
643
649
  - lib/samagotchi/peer_note.rb
650
+ - lib/samagotchi/peer_pair_here.rb
651
+ - lib/samagotchi/peer_presence.rb
644
652
  - lib/samagotchi/peer_receipts.rb
645
653
  - lib/samagotchi/peer_registry.rb
646
654
  - lib/samagotchi/peer_roster.rb
647
655
  - lib/samagotchi/peer_say.rb
656
+ - lib/samagotchi/peer_wait_expiry.rb
648
657
  - lib/samagotchi/pending_question.rb
649
658
  - lib/samagotchi/plain_reply.rb
650
659
  - lib/samagotchi/plugin/api.rb
@@ -657,7 +666,11 @@ files:
657
666
  - lib/samagotchi/plugin/http_transport.rb
658
667
  - lib/samagotchi/plugin/judgments.rb
659
668
  - lib/samagotchi/plugin/loader.rb
669
+ - lib/samagotchi/plugin/panes.rb
660
670
  - lib/samagotchi/plugin/peer.rb
671
+ - lib/samagotchi/plugin/peer_pairing.rb
672
+ - lib/samagotchi/plugin/peer_start.rb
673
+ - lib/samagotchi/plugin/peer_start_hook.rb
661
674
  - lib/samagotchi/plugin/peers.rb
662
675
  - lib/samagotchi/plugin/prompt_sections.rb
663
676
  - lib/samagotchi/plugin/secrets.rb
@@ -740,7 +753,9 @@ files:
740
753
  - lib/samagotchi/send_command.rb
741
754
  - lib/samagotchi/send_command/busy.rb
742
755
  - lib/samagotchi/send_command/parent_gate.rb
756
+ - lib/samagotchi/served_lookup.rb
743
757
  - lib/samagotchi/served_model.rb
758
+ - lib/samagotchi/served_ref.rb
744
759
  - lib/samagotchi/session.rb
745
760
  - lib/samagotchi/session_access.rb
746
761
  - lib/samagotchi/session_access/ask.rb
@@ -982,6 +997,7 @@ files:
982
997
  - lib/samagotchi/update_command.rb
983
998
  - lib/samagotchi/update_hint.rb
984
999
  - lib/samagotchi/used_memories.rb
1000
+ - lib/samagotchi/user_typed.rb
985
1001
  - lib/samagotchi/utf8_default.rb
986
1002
  - lib/samagotchi/verdict.rb
987
1003
  - lib/samagotchi/verify_anchor.rb
@@ -1022,6 +1038,8 @@ files:
1022
1038
  - lib/samagotchi/web/project_list.rb
1023
1039
  - lib/samagotchi/web/proxy_gate.rb
1024
1040
  - lib/samagotchi/web/public/activity.js
1041
+ - lib/samagotchi/web/public/agent_rows.js
1042
+ - lib/samagotchi/web/public/agent_runs.js
1025
1043
  - lib/samagotchi/web/public/annotate_actions.js
1026
1044
  - lib/samagotchi/web/public/annotate_bar.css
1027
1045
  - lib/samagotchi/web/public/annotate_bar.js
@@ -1133,7 +1151,6 @@ files:
1133
1151
  - lib/samagotchi/web/public/page_table_model.js
1134
1152
  - lib/samagotchi/web/public/page_view.js
1135
1153
  - lib/samagotchi/web/public/pages.css
1136
- - lib/samagotchi/web/public/pages_group.js
1137
1154
  - lib/samagotchi/web/public/pages_list.js
1138
1155
  - lib/samagotchi/web/public/pages_model.js
1139
1156
  - lib/samagotchi/web/public/pages_wiring.js
@@ -1151,7 +1168,9 @@ files:
1151
1168
  - lib/samagotchi/web/public/peer_links.js
1152
1169
  - lib/samagotchi/web/public/peer_mailbox_api.js
1153
1170
  - lib/samagotchi/web/public/peer_note.js
1171
+ - lib/samagotchi/web/public/peer_row.js
1154
1172
  - lib/samagotchi/web/public/peer_text.js
1173
+ - lib/samagotchi/web/public/peer_wait.js
1155
1174
  - lib/samagotchi/web/public/picture_regions.js
1156
1175
  - lib/samagotchi/web/public/picture_viewer.js
1157
1176
  - lib/samagotchi/web/public/plain_line.js
@@ -1182,6 +1201,7 @@ files:
1182
1201
  - lib/samagotchi/web/public/scroll.js
1183
1202
  - lib/samagotchi/web/public/send_turn.js
1184
1203
  - lib/samagotchi/web/public/sentences.js
1204
+ - lib/samagotchi/web/public/served_ref.js
1185
1205
  - lib/samagotchi/web/public/session_actions.js
1186
1206
  - lib/samagotchi/web/public/session_fields.js
1187
1207
  - lib/samagotchi/web/public/session_payload.js
@@ -1,67 +0,0 @@
1
- // All sessions' former Pages group: KEPT for an older cached app.js until
2
- // the next release (the mixed-cache rule, docs/internals/web-frontend.md):
3
- // remove after 0.189.0, with index.html's inert #pagesGroup and pages.css's
4
- // group rules. Pages have their own way in now: the top bar's pages pill
5
- // and the Pages list (pages_list.js, pages_wiring.js); nothing new imports
6
- // this. What it did: above the session cards, one row of page cards, read
7
- // when All sessions opened (GET /api/pages) and filtered by the search
8
- // field (#filter), under a "Pages" heading and over a "Sessions" one.
9
- //
10
- // +root+: #pagesGroup. +filterEl+: #filter. +api+: data.js api.
11
- // +open(name)+: views.js openPage. +model+: pages_model.js's list, read
12
- // through instead of its own GET when given.
13
- import { html, nothing, render } from "./vendor/lit-html.js";
14
- import { createLatest } from "./latest.js";
15
- import { pageCardMeta } from "./pages_list.js";
16
-
17
- // A card's second line (the list's).
18
- export { pageCardMeta };
19
-
20
- // The pages the search shows: +query+ in the name or the title, any case.
21
- export function filterPages(pages, query = "") {
22
- const q = query.trim().toLowerCase();
23
- if (!q) return pages;
24
- return pages.filter((page) => page.name.toLowerCase().includes(q) || String(page.title || "").toLowerCase().includes(q));
25
- }
26
-
27
- export function pagesGroupTemplate(pages, { open, now = Date.now() }) {
28
- if (!pages.length) return nothing;
29
- return html`<div class="pg-group-label">Pages</div>
30
- <div class="pg-cards" role="list">${pages.map((page) => html`<button type="button" class="pg-card" role="listitem"
31
- data-page=${page.name} @click=${() => open(page.name)}><b>${page.title || page.name}</b><span class="pg-card-meta">${pageCardMeta(page, now)}</span></button>`)}</div>
32
- <div class="pg-group-label">Sessions</div>`;
33
- }
34
-
35
- export function createPagesGroup({ root, filterEl, api, open, model = null, now = () => Date.now() }) {
36
- let pages = [];
37
- const latest = createLatest();
38
-
39
- function draw() {
40
- const shown = filterPages(pages, filterEl?.value || "");
41
- root.hidden = !shown.length;
42
- render(pagesGroupTemplate(shown, { open, now: now() }), root);
43
- }
44
-
45
- async function load() {
46
- if (model) return model.load();
47
- const fresh = latest.begin();
48
- try {
49
- const answer = await api("/api/pages");
50
- if (!fresh()) return;
51
- pages = Array.isArray(answer?.pages) ? answer.pages : [];
52
- } catch (_) {
53
- if (!fresh()) return;
54
- pages = []; // the group is a way in, not a place for errors: the page itself says them
55
- }
56
- draw();
57
- }
58
-
59
- // A failed read empties the group, as its own read does.
60
- model?.subscribe((state) => {
61
- pages = state.failed ? [] : state.pages;
62
- draw();
63
- });
64
- filterEl?.addEventListener("input", draw);
65
- draw();
66
- return { load, redraw: draw };
67
- }