samagotchi 0.201.0 → 0.202.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 (175) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -1
  3. data/docs/architecture.md +47 -7
  4. data/docs/cli.md +20 -1
  5. data/docs/configuration.md +2 -1
  6. data/docs/internals/bridge.md +4 -4
  7. data/docs/internals/engine.md +9 -6
  8. data/docs/internals/knowledge.md +26 -6
  9. data/docs/internals/objectives.md +2 -2
  10. data/docs/internals/pages.md +4 -2
  11. data/docs/internals/participants.md +1 -1
  12. data/docs/internals/peers.md +9 -7
  13. data/docs/internals/remote-sessions.md +6 -6
  14. data/docs/internals/session-lifecycle.md +37 -15
  15. data/docs/internals/web-frontend.md +18 -7
  16. data/docs/pages.md +6 -3
  17. data/docs/plugins.md +2 -2
  18. data/docs/scheduling.md +40 -12
  19. data/docs/sessions.md +48 -6
  20. data/docs/sub-agent.md +1 -2
  21. data/docs/testing.md +92 -8
  22. data/lib/samagotchi/answer_display.rb +3 -2
  23. data/lib/samagotchi/answer_tail.rb +4 -4
  24. data/lib/samagotchi/bridge/card_places.rb +5 -5
  25. data/lib/samagotchi/bridge/turn_accumulator.rb +5 -5
  26. data/lib/samagotchi/bridge/turn_drawings/synth.rb +5 -5
  27. data/lib/samagotchi/bridge/turn_drawings.rb +2 -2
  28. data/lib/samagotchi/bridge/turn_ranges.rb +15 -8
  29. data/lib/samagotchi/bridge.rb +5 -5
  30. data/lib/samagotchi/broadcast_command.rb +3 -3
  31. data/lib/samagotchi/bundle_command/try/trace.rb +18 -6
  32. data/lib/samagotchi/bundles/knowledge/embedder.rb +2 -0
  33. data/lib/samagotchi/bundles/knowledge/github.rb +19 -0
  34. data/lib/samagotchi/bundles/knowledge/manifest.yml +6 -6
  35. data/lib/samagotchi/bundles/knowledge/plugin.rb +26 -54
  36. data/lib/samagotchi/bundles/knowledge/refresh.rb +89 -14
  37. data/lib/samagotchi/bundles/knowledge/store.rb +36 -2
  38. data/lib/samagotchi/bundles/schedules/manifest.yml +2 -2
  39. data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +24 -3
  40. data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
  41. data/lib/samagotchi/bundles/system/manifest.yml +3 -3
  42. data/lib/samagotchi/bundles/system/skill_pages.md +1 -1
  43. data/lib/samagotchi/chi_invocation.rb +1 -1
  44. data/lib/samagotchi/child_move.rb +6 -3
  45. data/lib/samagotchi/child_reports.rb +3 -3
  46. data/lib/samagotchi/children_status.rb +4 -2
  47. data/lib/samagotchi/client_id.rb +2 -2
  48. data/lib/samagotchi/compat.rb +4 -6
  49. data/lib/samagotchi/config.rb +3 -0
  50. data/lib/samagotchi/context_note.rb +1 -1
  51. data/lib/samagotchi/continue_intent.rb +1 -1
  52. data/lib/samagotchi/continue_offer.rb +2 -2
  53. data/lib/samagotchi/continue_repair_backoff.rb +71 -0
  54. data/lib/samagotchi/delivery.rb +1 -4
  55. data/lib/samagotchi/engine/participants.rb +1 -1
  56. data/lib/samagotchi/engine/recap.rb +1 -1
  57. data/lib/samagotchi/engine/turn_end.rb +1 -1
  58. data/lib/samagotchi/grants.rb +2 -2
  59. data/lib/samagotchi/guardrail_wiring.rb +1 -1
  60. data/lib/samagotchi/guardrails/approval.rb +3 -3
  61. data/lib/samagotchi/guardrails/pair_boundary.rb +3 -3
  62. data/lib/samagotchi/guardrails/participant_refusal.rb +2 -2
  63. data/lib/samagotchi/idle_recap.rb +6 -6
  64. data/lib/samagotchi/kernel_loop.rb +1 -1
  65. data/lib/samagotchi/last_turn.rb +9 -6
  66. data/lib/samagotchi/llm/chat_loop.rb +5 -2
  67. data/lib/samagotchi/mcp_command.rb +2 -2
  68. data/lib/samagotchi/memory_usage.rb +7 -6
  69. data/lib/samagotchi/note_command.rb +1 -1
  70. data/lib/samagotchi/note_delivery.rb +5 -5
  71. data/lib/samagotchi/objectives_backing.rb +3 -3
  72. data/lib/samagotchi/objectives_record.rb +2 -2
  73. data/lib/samagotchi/objectives_track.rb +2 -2
  74. data/lib/samagotchi/owner_lock.rb +28 -2
  75. data/lib/samagotchi/owner_prompt.rb +3 -3
  76. data/lib/samagotchi/pages/runtime.rb +9 -4
  77. data/lib/samagotchi/participant_revise.rb +6 -6
  78. data/lib/samagotchi/peer_receipts.rb +11 -4
  79. data/lib/samagotchi/plugin/side_question.rb +1 -1
  80. data/lib/samagotchi/recap_place.rb +5 -5
  81. data/lib/samagotchi/reply_for.rb +3 -3
  82. data/lib/samagotchi/reply_wait/liveness.rb +2 -2
  83. data/lib/samagotchi/reply_wait/poll.rb +3 -3
  84. data/lib/samagotchi/schedule_command.rb +1 -1
  85. data/lib/samagotchi/schedule_display.rb +4 -3
  86. data/lib/samagotchi/schedules/busy_part.rb +29 -5
  87. data/lib/samagotchi/schedules/history_part.rb +47 -7
  88. data/lib/samagotchi/schedules/marks_part.rb +52 -29
  89. data/lib/samagotchi/schedules/notices_part.rb +31 -4
  90. data/lib/samagotchi/schedules/protection_part.rb +69 -11
  91. data/lib/samagotchi/schedules/prune_part.rb +3 -2
  92. data/lib/samagotchi/schedules.rb +37 -47
  93. data/lib/samagotchi/send_command.rb +12 -12
  94. data/lib/samagotchi/session.rb +71 -59
  95. data/lib/samagotchi/session_access/contract.rb +7 -0
  96. data/lib/samagotchi/session_access/exchange.rb +1 -1
  97. data/lib/samagotchi/session_access/local.rb +9 -9
  98. data/lib/samagotchi/session_access/remote.rb +20 -24
  99. data/lib/samagotchi/session_access.rb +1 -1
  100. data/lib/samagotchi/session_chain/delete.rb +15 -8
  101. data/lib/samagotchi/session_chain/delete_preview.rb +3 -3
  102. data/lib/samagotchi/session_chain/links.rb +18 -4
  103. data/lib/samagotchi/session_chain/successor.rb +1 -1
  104. data/lib/samagotchi/session_chain.rb +3 -3
  105. data/lib/samagotchi/session_continue.rb +83 -32
  106. data/lib/samagotchi/session_inbox.rb +6 -17
  107. data/lib/samagotchi/session_inbox_delivery.rb +36 -13
  108. data/lib/samagotchi/session_lifecycle/allowed.rb +5 -5
  109. data/lib/samagotchi/session_manager/delegate_rule.rb +2 -2
  110. data/lib/samagotchi/session_manager/delivery.rb +13 -38
  111. data/lib/samagotchi/session_manager/emptiness.rb +35 -15
  112. data/lib/samagotchi/session_manager/lifecycle.rb +3 -2
  113. data/lib/samagotchi/session_manager/listing.rb +35 -10
  114. data/lib/samagotchi/session_manager/removal.rb +16 -0
  115. data/lib/samagotchi/session_manager/spawn.rb +9 -6
  116. data/lib/samagotchi/session_manager.rb +6 -4
  117. data/lib/samagotchi/session_messages.rb +602 -0
  118. data/lib/samagotchi/session_metrics.rb +7 -4
  119. data/lib/samagotchi/session_participants.rb +4 -4
  120. data/lib/samagotchi/session_protection.rb +16 -2
  121. data/lib/samagotchi/session_retention.rb +26 -12
  122. data/lib/samagotchi/session_row.rb +1 -1
  123. data/lib/samagotchi/session_stats.rb +17 -8
  124. data/lib/samagotchi/session_stores.rb +5 -0
  125. data/lib/samagotchi/session_transition.rb +3 -2
  126. data/lib/samagotchi/sessions_command.rb +55 -3
  127. data/lib/samagotchi/steer.rb +16 -50
  128. data/lib/samagotchi/storage_migration.rb +234 -0
  129. data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
  130. data/lib/samagotchi/terminal_ui/formatting.rb +5 -5
  131. data/lib/samagotchi/terminal_ui/join_replay.rb +3 -3
  132. data/lib/samagotchi/terminal_ui/question_prompt.rb +2 -2
  133. data/lib/samagotchi/toolkit_report_command.rb +1 -1
  134. data/lib/samagotchi/tools/ask_session.rb +2 -2
  135. data/lib/samagotchi/tools/send_note.rb +1 -1
  136. data/lib/samagotchi/turn_context.rb +3 -3
  137. data/lib/samagotchi/turn_endings.rb +17 -0
  138. data/lib/samagotchi/turn_excerpts.rb +7 -4
  139. data/lib/samagotchi/turn_flow.rb +1 -1
  140. data/lib/samagotchi/turn_note.rb +30 -2
  141. data/lib/samagotchi/turn_origin.rb +7 -7
  142. data/lib/samagotchi/turn_outcome.rb +11 -0
  143. data/lib/samagotchi/turn_stages/verify_anchors.rb +4 -4
  144. data/lib/samagotchi/verify_fresh.rb +6 -6
  145. data/lib/samagotchi/verify_fresh_origin.rb +4 -4
  146. data/lib/samagotchi/version.rb +1 -1
  147. data/lib/samagotchi/web/app.rb +4 -3
  148. data/lib/samagotchi/web/last_ask.rb +2 -2
  149. data/lib/samagotchi/web/message_display.rb +12 -12
  150. data/lib/samagotchi/web/page_routes.rb +9 -3
  151. data/lib/samagotchi/web/participant_view.rb +4 -4
  152. data/lib/samagotchi/web/participants_admin.rb +1 -1
  153. data/lib/samagotchi/web/public/bubbles.js +1 -1
  154. data/lib/samagotchi/web/public/composer_fold.js +0 -3
  155. data/lib/samagotchi/web/public/composer_grip.js +0 -2
  156. data/lib/samagotchi/web/public/page_view.js +29 -4
  157. data/lib/samagotchi/web/public/participant_model.js +1 -1
  158. data/lib/samagotchi/web/public/peer_wait.js +2 -4
  159. data/lib/samagotchi/web/public/schedule_marks.js +2 -5
  160. data/lib/samagotchi/web/public/schedule_name.js +14 -0
  161. data/lib/samagotchi/web/public/session_actions.js +5 -0
  162. data/lib/samagotchi/web/public/start_page.js +1 -1
  163. data/lib/samagotchi/web/public/stop_sheet.js +2 -4
  164. data/lib/samagotchi/web/public/working_set_rail.js +0 -3
  165. data/lib/samagotchi/web/push/attention.rb +1 -1
  166. data/lib/samagotchi/web/session_create.rb +1 -1
  167. data/lib/samagotchi/web/session_hub.rb +68 -20
  168. data/lib/samagotchi/web/session_summary.rb +18 -14
  169. data/lib/samagotchi/web/verify_fresh_routes.rb +4 -4
  170. data/lib/samagotchi/worker/turn_drain.rb +158 -0
  171. data/lib/samagotchi/worker.rb +8 -144
  172. data/lib/samagotchi/worker_boot.rb +21 -5
  173. data/lib/samagotchi/worker_participant_gate.rb +5 -5
  174. data/lib/samagotchi/worker_presence.rb +24 -1
  175. metadata +6 -1
@@ -10,7 +10,7 @@ require_relative "session_inbox"
10
10
  require_relative "session_metrics"
11
11
  require_relative "session_row"
12
12
  require_relative "worker_link"
13
- require_relative "steer"
13
+ require_relative "speaker"
14
14
  require_relative "verify_anchor"
15
15
  require_relative "verify_fresh_origin"
16
16
 
@@ -79,7 +79,7 @@ module Samagotchi
79
79
  raise Refused.new(409, "not_unclear", NOT_UNCLEAR) unless field(record, :verdict).to_s == "unclear"
80
80
 
81
81
  anchor = VerifyAnchor.from(field(record, :anchor)) or raise Refused.new(404, "not_found", NOT_FOUND)
82
- author = Steer.sender_author(author)
82
+ author = Speaker.sender_author(author)
83
83
  origin = VerifyFreshOrigin.new(author: author, mode: author && mode.to_s, of: of, anchor: anchor)
84
84
  dir = Session.session_dir(parent.id, state_dir: state_dir)
85
85
  spawn ||= SessionManager.method(:spawn_session)
@@ -136,7 +136,7 @@ module Samagotchi
136
136
  # worker counts live).
137
137
  # @return [Float]
138
138
  def children_spend(parent_id, author, state_dir: Session.default_state_dir, except: nil)
139
- return 0.0 unless Steer.participant_author?(author)
139
+ return 0.0 unless Speaker.participant_author?(author)
140
140
 
141
141
  ledger(Session.session_dir(parent_id, state_dir: state_dir)).sum(0.0) do |row|
142
142
  next 0.0 unless row[:author] == author && row[:child_id] != except
@@ -150,7 +150,7 @@ module Samagotchi
150
150
  # fresh child, the parent's and its other fresh children's.
151
151
  # @return [Float]
152
152
  def related_spend(session, author, state_dir: Session.default_state_dir)
153
- return 0.0 unless Steer.participant_author?(author) && session
153
+ return 0.0 unless Speaker.participant_author?(author) && session
154
154
 
155
155
  if session.verify_fresh && session.parent_id
156
156
  parent_dir = Session.session_dir(session.parent_id, state_dir: state_dir)
@@ -167,7 +167,7 @@ module Samagotchi
167
167
  # The child's new verdicts (+records+, Engine's verdict records) into
168
168
  # its parent's INBOX, marked fresh: true with the child's id and the
169
169
  # verdict they check again (of). Best effort. A session inbox delivery
170
- # (SessionInbox.deliver :fresh_verdict): pinned to the parent the child
170
+ # (InboxDelivery.deliver :fresh_verdict): pinned to the parent the child
171
171
  # names (its original verdict's card is there, a continued one's too),
172
172
  # never a worker started for it; a parent that is gone gets nothing.
173
173
  # @param child [Session] a Verify fresh child
@@ -177,7 +177,7 @@ module Samagotchi
177
177
  return 0 unless fresh&.of && child.parent_id
178
178
 
179
179
  written = 0
180
- SessionInbox.deliver(:fresh_verdict, child.parent_id, state_dir: state_dir, wake: false) do |at|
180
+ InboxDelivery.deliver(:fresh_verdict, child.parent_id, state_dir: state_dir, wake: false) do |at|
181
181
  written = write_verdicts(Session.session_dir(at, state_dir: state_dir), child, fresh.of, records)
182
182
  false
183
183
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "steer"
3
+ require_relative "speaker"
4
4
  require_relative "turn_origin"
5
5
  require_relative "verify_anchor"
6
6
  require_relative "participant_turn_mode"
@@ -33,14 +33,14 @@ module Samagotchi
33
33
  of = field.call(:of)
34
34
  return self::INVALID unless anchor && of.is_a?(String) && !of.empty?
35
35
  return new(author: nil, mode: nil, of: of, anchor: anchor) if author.nil?
36
- return self::INVALID unless author.is_a?(String) && Steer.participant_author?(author) && self::MODES.include?(mode)
36
+ return self::INVALID unless author.is_a?(String) && Speaker.participant_author?(author) && self::MODES.include?(mode)
37
37
 
38
38
  new(author: author, mode: mode, of: of, anchor: anchor)
39
39
  end
40
40
 
41
41
  # Whether a participant asked for it (the owner's child runs as any
42
42
  # delegate child).
43
- def participant? = Steer.participant_author?(author)
43
+ def participant? = Speaker.participant_author?(author)
44
44
 
45
45
  # Whether a participant's turns run here, under the owner's rules: only
46
46
  # when saved so (fail closed: ParticipantTurnMode).
@@ -68,6 +68,6 @@ module Samagotchi
68
68
  # A verify_fresh field that doesn't read: a participant author nobody
69
69
  # has, so the worker refuses its turns ("revoked").
70
70
 
71
- VerifyFreshOrigin::INVALID = VerifyFreshOrigin.new(author: "#{Steer::PARTICIPANT_PREFIX}invalid", mode: "review",
71
+ VerifyFreshOrigin::INVALID = VerifyFreshOrigin.new(author: "#{Speaker::PARTICIPANT_PREFIX}invalid", mode: "review",
72
72
  of: nil, anchor: nil)
73
73
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Samagotchi
4
- VERSION = "0.201.0"
4
+ VERSION = "0.202.0"
5
5
  # Sent as the User-Agent of every HTTP request chi makes.
6
6
  USER_AGENT = "chi/#{VERSION}"
7
7
  end
@@ -1856,7 +1856,7 @@ module Samagotchi
1856
1856
  if File.file?(full) && full.start_with?(@public_dir)
1857
1857
  revalidated_body(req, File.binread(full), mime_type(full))
1858
1858
  else
1859
- not_found(path: req.path_info)
1859
+ not_found(path: req.path_info, reason: SessionAccess::Contract::NO_ROUTE)
1860
1860
  end
1861
1861
  end
1862
1862
 
@@ -2048,8 +2048,9 @@ module Samagotchi
2048
2048
  json_response(status, { error: code, detail: detail })
2049
2049
  end
2050
2050
 
2051
- def not_found(path:)
2052
- error_response(404, "not_found", "not found: #{path}")
2051
+ # +reason+: a code beside the error and the words (the static 404's SessionAccess::Contract::NO_ROUTE).
2052
+ def not_found(path:, reason: nil)
2053
+ json_response(404, { error: "not_found", detail: "not found: #{path}", reason: reason }.compact)
2053
2054
  end
2054
2055
 
2055
2056
  # 404 not_found for an id (or prefix) that names no session, in
@@ -52,9 +52,9 @@ module Samagotchi
52
52
  # and it is not archived with nothing continuing it (a continued one
53
53
  # keeps its id: the ask follows the chain to its newest link, a
54
54
  # continue in flight included); else #recent.
55
- # @param head [#call] id → SessionInbox::Resolved (a send's chain walk)
55
+ # @param head [#call] id → InboxDelivery::Resolved (a send's chain walk)
56
56
  # @return [String, nil] nil: no session to ask
57
- def target(state_dir:, head: ->(id) { SessionInbox::Head.resolve(:send, id, state_dir: state_dir) })
57
+ def target(state_dir:, head: ->(id) { InboxDelivery::Head.resolve(:send, id, state_dir: state_dir) })
58
58
  id = recorded(state_dir: state_dir)
59
59
  return recent(state_dir: state_dir) unless id && Session.exist?(id, state_dir: state_dir)
60
60
  return id if head.call(id).id != id
@@ -68,7 +68,7 @@ module Samagotchi
68
68
 
69
69
  messages = Array(session.messages)
70
70
  covered = saved[:covered].to_i
71
- since = messages.drop(covered).count { |m| Samagotchi::Steer.turn_opening?(m) }
71
+ since = messages.drop(covered).count { |m| Samagotchi::Speaker.turn_opening?(m) }
72
72
  { text: saved[:text], turns_since: since, opening_id: RecapPlace.opening_id(messages, covered),
73
73
  created_at: saved[:created_at] }.compact
74
74
  rescue StandardError
@@ -79,7 +79,7 @@ module Samagotchi
79
79
  # +index+: one past the model messages between it and the turn's
80
80
  # prompt.
81
81
  def steer_step(list, index)
82
- list[0...index].reverse_each.take_while { |m| !Samagotchi::Steer.turn_prompt?(m) }
82
+ list[0...index].reverse_each.take_while { |m| !Samagotchi::Speaker.turn_prompt?(m) }
83
83
  .count { |m| %w[model assistant].include?((m[:role] || m["role"]).to_s) } + 1
84
84
  end
85
85
 
@@ -139,9 +139,9 @@ module Samagotchi
139
139
  note[:objectives] = entry
140
140
  objectives = Samagotchi::Objectives.from_payload(payload)
141
141
  end
142
- # A context wake turn's note starts that turn (Steer.turn_prompt?):
142
+ # A context wake turn's note starts that turn (Speaker.turn_prompt?):
143
143
  # the page opens the turn with it and pairs it with its record.
144
- if Samagotchi::Steer.turn_prompt?(m)
144
+ if Samagotchi::Speaker.turn_prompt?(m)
145
145
  note[:turn_start] = true
146
146
  note[:turn_id] = (m[:turn_id] || m["turn_id"]).to_s
147
147
  note.merge!(revises_of(m))
@@ -151,7 +151,7 @@ module Samagotchi
151
151
  end
152
152
  # A plugin's steer: a row of the step that answered it, which the
153
153
  # page finds by `step`.
154
- if Samagotchi::Steer.steer?(m)
154
+ if Samagotchi::Speaker.steer?(m)
155
155
  filtered << { role: "steer", content: content, source: (m[:source] || m["source"]).to_s, step: steer_step(list, index), **time_of(m) }
156
156
  next
157
157
  end
@@ -165,8 +165,8 @@ module Samagotchi
165
165
  next if role == "system"
166
166
  next if role == "tool_response"
167
167
  # KernelLoop's recovery line: a row of its turn the page showed as
168
- # nothing live (no turn opens with it, Steer.recovery?).
169
- next if Samagotchi::Steer.recovery?(m)
168
+ # nothing live (no turn opens with it, Speaker.recovery?).
169
+ next if Samagotchi::Speaker.recovery?(m)
170
170
 
171
171
  stripped = Samagotchi::OutputFormatter.strip_markup(content)
172
172
  step = %w[model assistant].include?(role)
@@ -182,18 +182,18 @@ module Samagotchi
182
182
  message = { role: norm_role, content: stripped, **time_of(m) }
183
183
  client_id = m[:client_id] || m["client_id"]
184
184
  message[:client_id] = client_id.to_s if norm_role == "user" && client_id
185
- # Merged into the running turn (Steer::INPUT_KIND): part of it,
185
+ # Merged into the running turn (Speaker::INPUT_KIND): part of it,
186
186
  # read by step +step+; a wake turn's report starts its turn
187
- # (Steer.turn_prompt?). Its sender (a delegate report, chi send):
187
+ # (Speaker.turn_prompt?). Its sender (a delegate report, chi send):
188
188
  # the page's label.
189
- if norm_role == "user" && Samagotchi::Steer.input?(m)
190
- message.merge!(merged: true, step: steer_step(list, index)) unless Samagotchi::Steer.turn_prompt?(m)
189
+ if norm_role == "user" && Samagotchi::Speaker.input?(m)
190
+ message.merge!(merged: true, step: steer_step(list, index)) unless Samagotchi::Speaker.turn_prompt?(m)
191
191
  source = (m[:source] || m["source"]).to_s
192
192
  message[:source] = source unless source.empty?
193
193
  # A delegate report is the child's markdown: rendered as an
194
194
  # answer is (its copy source stays the text). Another user line
195
195
  # stays plain.
196
- if markdown && source == Samagotchi::Steer::DELEGATE_REPORT && @markdown_renderer.available?
196
+ if markdown && source == Samagotchi::Speaker::DELEGATE_REPORT && @markdown_renderer.available?
197
197
  message[:html] = @markdown_renderer.render(report_markdown(stripped))
198
198
  end
199
199
  end
@@ -22,7 +22,8 @@ module Samagotchi
22
22
 
23
23
  # How much of a failed run's stderr the answer carries (its tail).
24
24
  STDERR_BYTES = 2048
25
- BAD_PARAMS = 'the body must be {"params": {name: value}}, every name and value text'
25
+ BAD_PARAMS = 'the body must be {"params": {name: value}}, every name and value text; a run takes at most ' \
26
+ "#{Pages::MAX_PARAMS} params, each value at most #{Pages::MAX_CHOICE} characters"
26
27
 
27
28
  private
28
29
 
@@ -90,8 +91,11 @@ module Samagotchi
90
91
 
91
92
  # A run's values from its raw body: {} for an empty one; nil (400) for
92
93
  # one that isn't a JSON object, or whose +params+ (when there) isn't a
93
- # Hash of String => String. The raw body, not parse_json: that answers
94
- # nil for an empty body and malformed JSON alike.
94
+ # Hash of String => String within the caps a script could declare
95
+ # anyway (Pages::MAX_PARAMS, MAX_CHOICE): the values go into one argv
96
+ # JSON (Pages::Launch#command), and a huge body would fail the spawn
97
+ # (E2BIG) with a 500. The raw body, not parse_json: that answers nil
98
+ # for an empty body and malformed JSON alike.
95
99
  def run_params(raw)
96
100
  return {} if raw.strip.empty?
97
101
 
@@ -100,6 +104,8 @@ module Samagotchi
100
104
 
101
105
  params = body.fetch("params", {})
102
106
  return nil unless params.is_a?(Hash) && params.all? { |key, value| value.is_a?(String) && key.is_a?(String) }
107
+ return nil if params.size > Pages::MAX_PARAMS
108
+ return nil if params.any? { |_name, value| value.size > Pages::MAX_CHOICE }
103
109
 
104
110
  params
105
111
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "../output_formatter"
4
4
  require_relative "../model_markup"
5
- require_relative "../steer"
5
+ require_relative "../speaker"
6
6
  require_relative "../turn_origin"
7
7
  require_relative "../turn_anchors"
8
8
  require_relative "../redact"
@@ -95,7 +95,7 @@ module Samagotchi
95
95
  # A merged input line's saved sources a participant sees: a person's
96
96
  # (the owner, chi send, a participant). A delegate's report, a
97
97
  # plugin's or an automatic client's input is not.
98
- PERSON_SOURCES = ["", "chi_send", Steer::PARTICIPANT_SOURCE].freeze
98
+ PERSON_SOURCES = ["", "chi_send", Speaker::PARTICIPANT_SOURCE].freeze
99
99
 
100
100
  # A tool call's status words a row may carry.
101
101
  STATUSES = %w[ok error blocked stopped denied].freeze
@@ -144,7 +144,7 @@ module Samagotchi
144
144
  return nil unless origin.is_a?(Hash)
145
145
 
146
146
  author = field(origin, :author)
147
- return nil unless viewer.own?(author) && Steer.participant_author?(author)
147
+ return nil unless viewer.own?(author) && Speaker.participant_author?(author)
148
148
 
149
149
  out = { "type" => "prompt_restored", **seq(event), "prompt" => field(event, :prompt).to_s }
150
150
  images = image_refs(field(event, :images), author, viewer)
@@ -671,7 +671,7 @@ module Samagotchi
671
671
  # turn's +mode+ (its participant_mode stamp: review or pair) when
672
672
  # it has one.
673
673
  def author_fields(author, name, viewer, mode = nil)
674
- return {} unless Steer.participant_author?(author)
674
+ return {} unless Speaker.participant_author?(author)
675
675
 
676
676
  out = { "author" => author.to_s }
677
677
  out["author_name"] = name.to_s if name.is_a?(String) && !name.empty?
@@ -50,7 +50,7 @@ module Samagotchi
50
50
  def with_spend(id, grants)
51
51
  rows = SessionMetrics.saved_by_author(Session.session_dir(id, state_dir: default_state_dir))
52
52
  grants.map do |grant|
53
- row = rows[Steer.author_for(grant[:id])] || { turns: 0, cost: 0.0 }
53
+ row = rows[Speaker.author_for(grant[:id])] || { turns: 0, cost: 0.0 }
54
54
  grant.merge(spend: row[:cost].round(4), turns: row[:turns])
55
55
  end
56
56
  end
@@ -31,7 +31,7 @@ export function removeQueuedBubble(bubble) {
31
31
  // A prompt that started a turn: not a line steered into a running one, nor a
32
32
  // failed turn's prompt, drawn again after the history (it went back to its
33
33
  // sender: the session and the turn count have no such turn). A wake turn's
34
- // note opens its turn too. The same turns as Steer.turn_opening? in Ruby, which
34
+ // note opens its turn too. The same turns as Speaker.turn_opening? in Ruby, which
35
35
  // counts turns_since.
36
36
  export const TURN_PROMPT = ".bubble.user:not(.steered):not(.failed), .bubble.note.turn-start";
37
37
 
@@ -8,9 +8,6 @@
8
8
  // screen folds it for that time, on top of all of these (+cardField+): the
9
9
  // keyboard is up and the card needs the rows; nothing is saved.
10
10
 
11
- // session_prefs.js COMPOSER_FOLD's name, kept for an older importer.
12
- export const COMPOSER_FOLD_KEY = "chi_composer_collapsed";
13
-
14
11
  // Whether the composer is folded: the saved choice or an archived visit,
15
12
  // unless this visit opened it.
16
13
  export function composerFolded({ saved, archivedVisit, visitOpen, cardField = false }) {
@@ -7,8 +7,6 @@ import { COMPOSER_FLOOR, COMPOSER_FOLD, forget as forgetPref, read as readPref,
7
7
  // the box's height (fitPrompt) and the grip's floor (+floor+ / +setFloor+), which
8
8
  // fitPrompt reads; the floor is saved per session (session_prefs.js
9
9
  // COMPOSER_FLOOR, chi_composer_floor:<session>; the start page's in memory).
10
- // GRIP_KEY: its name, kept for an older importer.
11
- export const GRIP_KEY = "chi_composer_floor";
12
10
  // A card's text field with the focus folds the composer on these screens.
13
11
  const CARD_FIELD_SCREEN = "(max-width: 600px), (hover: none) and (pointer: coarse)";
14
12
  const CARD_FIELD = '.bubble.question input[type="text"], .bubble.continue input[type="text"]';
@@ -15,7 +15,9 @@
15
15
  // Refresh, with every shown value and that one changed; Refresh asks for
16
16
  // the values shown. While a run goes every choice is disabled and the
17
17
  // tapped one has the pending look; a failure the view's own run asked for
18
- // names the choices (+asked+, the view's memory, never stored).
18
+ // names the choices (+asked+, the view's memory, never stored). A good run
19
+ // whose answer no longer has a choice it was asked for (the script changed:
20
+ // the run is lenient, Pages::Params) toasts what ran instead.
19
21
  //
20
22
  // Made only with the pages capability (pages_wiring.js; the null-control rule).
21
23
  // +root+: #pageView. +api+: data.js api. +toast(text)+, +copyText(text)+:
@@ -33,7 +35,7 @@ import { blocksTemplate, drawWalks } from "./page_blocks.js";
33
35
  import { tableTemplate } from "./page_table.js";
34
36
  import { nextSort } from "./page_table_model.js";
35
37
  import { changedText, errorCopy, failureParts, keptAfterFailure, metaText } from "./page_model.js";
36
- import { pageParams, shownValues } from "./page_params.js";
38
+ import { askedText, pageParams, shownValues } from "./page_params.js";
37
39
 
38
40
  // Mirrors Pages::NAME (lib/samagotchi/pages.rb); pinned by spec/pages_name_sync_spec.rb.
39
41
  const PAGE_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
@@ -92,12 +94,31 @@ export function createPageView({
92
94
  draw();
93
95
  }
94
96
 
97
+ // What ran instead of a choice the script no longer has: the run is
98
+ // lenient (Pages::Params), the param took its default, and the toast names
99
+ // both sides in the pages' words: "Period: 7 days: 90 days is no longer a
100
+ // choice" (the asked one as the result before the run named it).
101
+ function ranInstead(before, page, asked) {
102
+ const shownBefore = pageParams(before);
103
+ return pageParams(page)
104
+ .filter((param) => Object.hasOwn(asked, param.name) && asked[param.name] !== param.value)
105
+ .map((param) => {
106
+ const kept = param.choices.find((choice) => choice?.value === param.value);
107
+ const wanted = shownBefore.find((row) => row.name === param.name);
108
+ const choice = wanted?.choices.find((row) => row?.value === asked[param.name]);
109
+ return `${param.label || param.name}: ${kept?.label ?? param.value}: ${choice?.label ?? asked[param.name]}`
110
+ + " is no longer a choice";
111
+ })
112
+ .join(", ");
113
+ }
114
+
95
115
  // One run of the open page (Refresh and a tapped choice): +values+
96
116
  // {name: value}, the values shown when not given. A page with no params
97
117
  // posts no body.
98
118
  async function runPage(values = shownValues(view?.page)) {
99
119
  if (!view || view.running || view.status !== "ready") return;
100
120
  const name = view.name;
121
+ const before = view.page; // the result on screen before the run (the toast's asked words)
101
122
  const run = { answered: false };
102
123
  runs.set(name, run);
103
124
  const asked = pageParams(view.page).length ? values : null;
@@ -109,10 +130,14 @@ export function createPageView({
109
130
  run.answered = true;
110
131
  if (runs.get(name) === run) runs.delete(name);
111
132
  if (!still()) return;
133
+ // A good answer whose params differ from what was asked: a choice the
134
+ // script no longer has ran as the default; the toast says so (a failed
135
+ // run's line names the asked choices instead).
136
+ if (page.state !== "failed" && asked && askedText(page, asked)) toast(`Ran ${ranInstead(before, page, asked)}`);
112
137
  const sorts = Object.fromEntries(Object.entries(view.sorts).filter(([index]) => {
113
- const before = view.page?.blocks?.[index]?.columns;
138
+ const cols = view.page?.blocks?.[index]?.columns;
114
139
  const after = page.blocks?.[index]?.columns;
115
- return Array.isArray(before) && Array.isArray(after) && before.length === after.length;
140
+ return Array.isArray(cols) && Array.isArray(after) && cols.length === after.length;
116
141
  }));
117
142
  set({ status: "ready", running: false, asked: page.state === "failed" ? view.asked : null, page,
118
143
  stderr: page.stderr || "", sorts, opened: {} });
@@ -5,7 +5,7 @@
5
5
  // (viewer_self.js).
6
6
 
7
7
  // A participant's author: "p:" and its grant id, as the server writes it
8
- // (Steer.author_for / PARTICIPANT_PREFIX): the one place the web spells it.
8
+ // (Speaker.author_for / PARTICIPANT_PREFIX): the one place the web spells it.
9
9
  export const PARTICIPANT_PREFIX = "p:";
10
10
  export const participantAuthor = (id) => `${PARTICIPANT_PREFIX}${id}`;
11
11
  export const isParticipantAuthor = (by) => typeof by === "string" && by.startsWith(PARTICIPANT_PREFIX);
@@ -6,10 +6,8 @@
6
6
  import { html } from "./vendor/lit-html.js";
7
7
 
8
8
  // The peer's app as its bundle words it: the waiting row's `app` (the wait mark's, PeerWaiting; chi web loads no
9
- // plugins); else its label. APPS: the N-1 fallback for a wait an older worker wrote (it lives 10 minutes), remove in
10
- // the release after next.
11
- const APPS = { claude: "Claude Code" };
12
- const appOf = (group) => group?.peer?.app || APPS[group?.name] || group?.label || group?.name || "peer";
9
+ // plugins); else its label.
10
+ const appOf = (group) => group?.peer?.app || group?.label || group?.name || "peer";
13
11
 
14
12
  // The whole minutes left until +until+ (rounded up, at least 1 while it waits); 0 past it or unparsable.
15
13
  export function waitMinutesLeft(until, now = Date.now()) {
@@ -6,14 +6,11 @@
6
6
  // classifies a mark (kind: stopped, open_tab, other), so nothing here
7
7
  // matches words. Pure: spec/web/public/info_bar_model.test.js.
8
8
 
9
+ import { scheduleName } from "./schedule_name.js";
10
+
9
11
  export const SCHEDULE_ICON = "⏸";
10
12
  export const SCHEDULE_BADGE_TEXT = `${SCHEDULE_ICON} schedule`;
11
13
 
12
- // "title" when it has one, else its short id.
13
- function scheduleName(mark) {
14
- return mark.title ? `"${mark.title}"` : String(mark.id || "").slice(0, 8);
15
- }
16
-
17
14
  const sentence = (text) => (/[.!?]$/.test(text) ? text : `${text}.`);
18
15
 
19
16
  // One mark's line: {id, text, after (a second sentence, "" for none),
@@ -0,0 +1,14 @@
1
+ // A schedule's name as the page says it: its title in quotes, else its short
2
+ // id (the first 8 characters). Two callers say it the same way, and must not
3
+ // drift: the schedules a stop leaves waiting (stop_sheet.js scheduleWords,
4
+ // the sheet's line and the plain confirm) and the waiting marks' lines
5
+ // (schedule_marks.js scheduleLine, the notice strip and the card's badge).
6
+ // Pure.
7
+ //
8
+ // A new module: the export ratchet refuses new exports on existing modules
9
+ // (docs/internals/web-frontend.md, "New exports go in new modules").
10
+
11
+ export function scheduleName(item) {
12
+ const title = String(item?.title ?? "").trim();
13
+ return title ? `"${title}"` : String(item?.id ?? "").slice(0, 8);
14
+ }
@@ -180,6 +180,11 @@ export function createSessionActions({
180
180
  } catch {
181
181
  holds = []; // a worker that can't say, or none: stop as before
182
182
  }
183
+ // While the worker answered the page may have moved to another session:
184
+ // the sheet or the confirm must not open over it (as pickForSession
185
+ // re-checks selected()). A stale stop asks nothing; the next Stop on
186
+ // the open session asks again.
187
+ if (selected() !== id) return;
183
188
  if (stopSheet.open(id, holds, schedules)) return;
184
189
  const waiting = scheduleWords(schedules);
185
190
  if (!confirm(`Stop session ${id}?${waiting ? `\n\n${waiting}` : ""}`)) return;
@@ -300,7 +300,7 @@ export function createStartPage({
300
300
  syncModelPick, commandRan, restoreStartPick, loadModels, chosenModel, newChoices, clearChoices, dropChoices,
301
301
  openForSession,
302
302
  // The models list is in: the bar's name may open it (info_bar_model.js sessionBar's modelSwitch).
303
- // (An older cached model_picker.js has no open: the name stays plain text.)
303
+ // (An older cached model_picker.js has no open: the name stays plain text.) Remove after 0.202.0.
304
304
  modelsLoaded: () => !pickEl.hidden && typeof modelPicker.open === "function",
305
305
  // A fresh link's /model still in flight (a send waits for it), or null.
306
306
  pendingPick: () => pendingPick,
@@ -17,6 +17,7 @@
17
17
  import { html, nothing, render } from "./vendor/lit-html.js";
18
18
  import { createChipPopover } from "./chip_popover.js";
19
19
  import { cutCommand, NAMED_MAX } from "./running_tasks.js";
20
+ import { scheduleName } from "./schedule_name.js";
20
21
 
21
22
  // At most this many of a kind named in the sheet; the rest are one "+N more".
22
23
  export const MAX_NAMED = NAMED_MAX;
@@ -54,10 +55,7 @@ export function scheduleWords(schedules) {
54
55
  const list = (Array.isArray(schedules) ? schedules : []).filter((item) => item && typeof item === "object");
55
56
  if (!list.length) return "";
56
57
 
57
- const names = list.slice(0, MAX_NAMED).map((item) => {
58
- const title = String(item.title ?? "").trim();
59
- return title ? `"${title}"` : String(item.id ?? "").slice(0, 8);
60
- });
58
+ const names = list.slice(0, MAX_NAMED).map(scheduleName);
61
59
  const more = list.length > MAX_NAMED ? ` +${list.length - MAX_NAMED} more` : "";
62
60
  const named = `${names.join(", ")}${more}`;
63
61
  const come = "Your message starts it again.";
@@ -35,9 +35,6 @@ export function addLabels(items, pending) {
35
35
  import { WS_RAIL_FOLD, read as readPref, write as writePref } from "./session_prefs.js";
36
36
  import { reducedMotion } from "./stage_frame.js";
37
37
 
38
- // session_prefs.js WS_RAIL_FOLD's name (chi_working_set_collapsed:<session>),
39
- // kept for an older importer.
40
- export const COLLAPSE_KEY = "chi_working_set_collapsed";
41
38
  // The stage width (px) under which the rail is a row; the phone's
42
39
  // (index.html, under 600 px of window) shows neither.
43
40
  export const RAIL_MIN = 760;
@@ -171,7 +171,7 @@ module Samagotchi
171
171
  icon = { "confirmed" => "✅", "refuted" => "❌", "unclear" => "❓" }.fetch(result, "")
172
172
  by = verdict[:by_name]
173
173
  # An owner's verdict has no participant author (nil, "" or "owner").
174
- by = Steer.participant_author?(verdict[:by]) ? "A participant" : "You" unless present?(by)
174
+ by = Speaker.participant_author?(verdict[:by]) ? "A participant" : "You" unless present?(by)
175
175
  reason = clip(verdict[:reason].to_s, 120)
176
176
  "#{by}: #{icon} #{result} — #{reason}"
177
177
  end
@@ -160,7 +160,7 @@ module Samagotchi
160
160
  # page prefills (SessionChain.opener_for; null: the page's constant).
161
161
  # A model it can't start on is 400 invalid_model, nothing archived.
162
162
  # 409 continued (with next_id, the link that continues it already: the
163
- # page opens that one), open_children (ids), folder_gone, transition_busy, busy, scratch
163
+ # page opens that one), open_children (ids), folder_gone, transition_busy, undo_pending, busy, scratch
164
164
  # or owned_by_tui.
165
165
  def handle_continue(body, prompt, idle)
166
166
  given = body["continues"]