samagotchi 0.153.0 → 0.154.1

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 (226) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -1
  3. data/README.md +2 -3
  4. data/bin/chi +23 -24
  5. data/docs/architecture.md +30 -33
  6. data/docs/broadcast.md +5 -5
  7. data/docs/bundles.md +9 -12
  8. data/docs/cli.md +82 -96
  9. data/docs/configuration.md +27 -26
  10. data/docs/context.md +3 -3
  11. data/docs/desktop.md +1 -1
  12. data/docs/guardrails.md +8 -10
  13. data/docs/hooks.md +9 -9
  14. data/docs/internals/attached-context.md +2 -2
  15. data/docs/internals/background-tasks.md +3 -4
  16. data/docs/internals/block-renderers.md +4 -0
  17. data/docs/internals/bridge.md +21 -8
  18. data/docs/internals/context-telemetry.md +1 -1
  19. data/docs/internals/engine.md +33 -7
  20. data/docs/internals/objectives.md +6 -5
  21. data/docs/internals/participants.md +7 -7
  22. data/docs/internals/prompt-caching.md +4 -2
  23. data/docs/internals/remote-sessions.md +7 -7
  24. data/docs/internals/web-frontend.md +2 -2
  25. data/docs/internals/web-push.md +1 -1
  26. data/docs/memory.md +2 -2
  27. data/docs/plugins.md +23 -28
  28. data/docs/sessions.md +24 -24
  29. data/docs/sub-agent.md +2 -2
  30. data/docs/system-one.md +1 -1
  31. data/docs/testing.md +31 -6
  32. data/lib/samagotchi/answer_text.rb +33 -0
  33. data/lib/samagotchi/bridge/card_places.rb +56 -7
  34. data/lib/samagotchi/bridge/card_store.rb +24 -9
  35. data/lib/samagotchi/bridge.rb +52 -32
  36. data/lib/samagotchi/bridge_client.rb +19 -14
  37. data/lib/samagotchi/broadcast/recipients.rb +2 -2
  38. data/lib/samagotchi/broadcast/triage.rb +1 -1
  39. data/lib/samagotchi/broadcast_command.rb +5 -5
  40. data/lib/samagotchi/bundle_command/try/command.rb +1 -1
  41. data/lib/samagotchi/bundle_command/try/run.rb +1 -1
  42. data/lib/samagotchi/bundle_command/try/trace.rb +1 -1
  43. data/lib/samagotchi/bundle_command.rb +2 -2
  44. data/lib/samagotchi/bundles/btw/manifest.yml +2 -2
  45. data/lib/samagotchi/bundles/btw/plugin.rb +1 -1
  46. data/lib/samagotchi/bundles/coordinator/manifest.yml +2 -2
  47. data/lib/samagotchi/bundles/coordinator/plugin.rb +3 -2
  48. data/lib/samagotchi/bundles/decision-card/manifest.yml +4 -4
  49. data/lib/samagotchi/bundles/decision-card/plugin.rb +1 -9
  50. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  51. data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
  52. data/lib/samagotchi/bundles/github-pr/plugin.rb +3 -3
  53. data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
  54. data/lib/samagotchi/bundles/skills/plugin.rb +3 -2
  55. data/lib/samagotchi/bundles/system/config_modification_protocol.md +3 -4
  56. data/lib/samagotchi/bundles/system/manifest.yml +3 -3
  57. data/lib/samagotchi/bundles/system/self_map.md +1 -1
  58. data/lib/samagotchi/child_move.rb +3 -3
  59. data/lib/samagotchi/commands/registry.rb +6 -6
  60. data/lib/samagotchi/composer_route.rb +4 -5
  61. data/lib/samagotchi/config.rb +14 -12
  62. data/lib/samagotchi/context_candidate_choice.rb +1 -1
  63. data/lib/samagotchi/context_candidates.rb +4 -3
  64. data/lib/samagotchi/continue_offer.rb +1 -1
  65. data/lib/samagotchi/debug_log.rb +1 -1
  66. data/lib/samagotchi/degrade.rb +75 -0
  67. data/lib/samagotchi/desktop/macos/ChiRunner.swift +3 -3
  68. data/lib/samagotchi/engine/cards.rb +87 -0
  69. data/lib/samagotchi/engine/context_judge.rb +138 -0
  70. data/lib/samagotchi/engine/events.rb +131 -0
  71. data/lib/samagotchi/engine/guardrails.rb +87 -0
  72. data/lib/samagotchi/engine/hooks.rb +119 -0
  73. data/lib/samagotchi/engine/messages.rb +124 -0
  74. data/lib/samagotchi/engine/model_settings.rb +127 -0
  75. data/lib/samagotchi/engine/models.rb +261 -0
  76. data/lib/samagotchi/engine/objectives.rb +116 -0
  77. data/lib/samagotchi/engine/participants.rb +86 -0
  78. data/lib/samagotchi/engine/plugins.rb +208 -0
  79. data/lib/samagotchi/engine/questions.rb +98 -0
  80. data/lib/samagotchi/engine/recap.rb +130 -0
  81. data/lib/samagotchi/engine/session.rb +131 -0
  82. data/lib/samagotchi/engine/side_requests.rb +135 -0
  83. data/lib/samagotchi/engine/steering.rb +134 -0
  84. data/lib/samagotchi/engine/toolkit.rb +269 -0
  85. data/lib/samagotchi/engine/turn_end.rb +180 -0
  86. data/lib/samagotchi/engine/turn_helpers.rb +160 -0
  87. data/lib/samagotchi/engine/verify.rb +153 -0
  88. data/lib/samagotchi/engine.rb +62 -2646
  89. data/lib/samagotchi/engine_snapshots.rb +9 -8
  90. data/lib/samagotchi/grants.rb +575 -0
  91. data/lib/samagotchi/guardrail_wiring.rb +2 -2
  92. data/lib/samagotchi/guardrails/context.rb +2 -3
  93. data/lib/samagotchi/guardrails/parent_approvals.rb +2 -2
  94. data/lib/samagotchi/guardrails/parent_policy.rb +2 -2
  95. data/lib/samagotchi/hook_routes.rb +3 -3
  96. data/lib/samagotchi/idle_recap.rb +7 -6
  97. data/lib/samagotchi/idle_reminders.rb +3 -4
  98. data/lib/samagotchi/iteration_limit.rb +2 -2
  99. data/lib/samagotchi/kernel_loop.rb +13 -13
  100. data/lib/samagotchi/launch_mode.rb +13 -32
  101. data/lib/samagotchi/level_setting_command.rb +3 -2
  102. data/lib/samagotchi/llm/chat_loop.rb +3 -1
  103. data/lib/samagotchi/llm_context_command.rb +3 -2
  104. data/lib/samagotchi/log.rb +7 -7
  105. data/lib/samagotchi/log_line.rb +1 -1
  106. data/lib/samagotchi/log_path.rb +1 -1
  107. data/lib/samagotchi/note_command.rb +1 -1
  108. data/lib/samagotchi/note_delivery.rb +18 -8
  109. data/lib/samagotchi/objectives.rb +24 -3
  110. data/lib/samagotchi/objectives_check.rb +8 -27
  111. data/lib/samagotchi/objectives_command.rb +4 -69
  112. data/lib/samagotchi/objectives_edit.rb +87 -0
  113. data/lib/samagotchi/output_formatter.rb +7 -1
  114. data/lib/samagotchi/owner_lock.rb +7 -1
  115. data/lib/samagotchi/parent_answers_command.rb +5 -4
  116. data/lib/samagotchi/participant_exposure.rb +42 -0
  117. data/lib/samagotchi/participant_mode.rb +1 -1
  118. data/lib/samagotchi/participant_name.rb +1 -1
  119. data/lib/samagotchi/participants.rb +17 -17
  120. data/lib/samagotchi/participants_watch.rb +1 -1
  121. data/lib/samagotchi/plugin/api.rb +3 -2
  122. data/lib/samagotchi/plugin/context.rb +21 -7
  123. data/lib/samagotchi/plugin/peer.rb +2 -1
  124. data/lib/samagotchi/plugin/sessions.rb +6 -4
  125. data/lib/samagotchi/plugin_tasks.rb +1 -2
  126. data/lib/samagotchi/private_files.rb +29 -0
  127. data/lib/samagotchi/project_env.rb +2 -2
  128. data/lib/samagotchi/question_desk.rb +8 -7
  129. data/lib/samagotchi/recap_command.rb +2 -1
  130. data/lib/samagotchi/recap_setup.rb +1 -1
  131. data/lib/samagotchi/recap_store.rb +1 -1
  132. data/lib/samagotchi/redact.rb +86 -0
  133. data/lib/samagotchi/reminder_queue.rb +2 -2
  134. data/lib/samagotchi/remote_attach_command.rb +1 -1
  135. data/lib/samagotchi/reply_wait/poll.rb +2 -2
  136. data/lib/samagotchi/review_start.rb +1 -1
  137. data/lib/samagotchi/run_options.rb +6 -6
  138. data/lib/samagotchi/self_report.rb +42 -39
  139. data/lib/samagotchi/send_command/busy.rb +1 -1
  140. data/lib/samagotchi/send_command.rb +4 -1
  141. data/lib/samagotchi/session.rb +11 -2
  142. data/lib/samagotchi/session_access/contract.rb +3 -3
  143. data/lib/samagotchi/session_access/local.rb +9 -9
  144. data/lib/samagotchi/session_access/remote.rb +17 -7
  145. data/lib/samagotchi/session_access.rb +4 -4
  146. data/lib/samagotchi/session_archive_command.rb +2 -2
  147. data/lib/samagotchi/session_chain.rb +8 -6
  148. data/lib/samagotchi/session_commands.rb +45 -48
  149. data/lib/samagotchi/session_continue.rb +1 -1
  150. data/lib/samagotchi/session_delete_command.rb +4 -4
  151. data/lib/samagotchi/session_manager.rb +67 -49
  152. data/lib/samagotchi/session_metrics.rb +2 -2
  153. data/lib/samagotchi/session_model_settings.rb +3 -2
  154. data/lib/samagotchi/session_participants.rb +1 -1
  155. data/lib/samagotchi/session_retention.rb +27 -7
  156. data/lib/samagotchi/sessions_command.rb +4 -4
  157. data/lib/samagotchi/share_command.rb +10 -10
  158. data/lib/samagotchi/steer.rb +13 -2
  159. data/lib/samagotchi/stream_event.rb +22 -0
  160. data/lib/samagotchi/system_prompt.rb +154 -145
  161. data/lib/samagotchi/task_watch.rb +1 -1
  162. data/lib/samagotchi/terminal_ui/attach_launcher.rb +72 -10
  163. data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +12 -9
  164. data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +16 -0
  165. data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -3
  166. data/lib/samagotchi/terminal_ui/attached_loop.rb +17 -8
  167. data/lib/samagotchi/terminal_ui/attached_view.rb +1 -11
  168. data/lib/samagotchi/terminal_ui/event_renderer.rb +3 -5
  169. data/lib/samagotchi/terminal_ui/formatting.rb +7 -7
  170. data/lib/samagotchi/terminal_ui/input_support.rb +17 -22
  171. data/lib/samagotchi/terminal_ui/join_replay.rb +16 -12
  172. data/lib/samagotchi/terminal_ui/line_reader.rb +2 -2
  173. data/lib/samagotchi/terminal_ui/live_region.rb +2 -2
  174. data/lib/samagotchi/terminal_ui/log_tail.rb +135 -0
  175. data/lib/samagotchi/terminal_ui/one_shot_sink.rb +2 -2
  176. data/lib/samagotchi/terminal_ui/plain_surface.rb +1 -1
  177. data/lib/samagotchi/terminal_ui/question_prompt.rb +4 -5
  178. data/lib/samagotchi/terminal_ui/reline_seam.rb +2 -12
  179. data/lib/samagotchi/terminal_ui/status_row.rb +6 -14
  180. data/lib/samagotchi/terminal_ui.rb +142 -1387
  181. data/lib/samagotchi/title_command.rb +2 -2
  182. data/lib/samagotchi/tool_runner.rb +15 -16
  183. data/lib/samagotchi/toolkit_command.rb +2 -1
  184. data/lib/samagotchi/tools/delegate.rb +3 -1
  185. data/lib/samagotchi/tools/delegate_cursor.rb +3 -3
  186. data/lib/samagotchi/tools/delegate_wait.rb +1 -1
  187. data/lib/samagotchi/tools/objectives_tool.rb +2 -2
  188. data/lib/samagotchi/tools/send_note.rb +2 -1
  189. data/lib/samagotchi/turn_endings.rb +2 -2
  190. data/lib/samagotchi/turn_flow.rb +11 -7
  191. data/lib/samagotchi/update_hint.rb +2 -2
  192. data/lib/samagotchi/version.rb +1 -1
  193. data/lib/samagotchi/web/app.rb +42 -51
  194. data/lib/samagotchi/web/message_display.rb +7 -0
  195. data/lib/samagotchi/web/participant_access.rb +2 -2
  196. data/lib/samagotchi/web/participant_review.rb +5 -5
  197. data/lib/samagotchi/web/participant_stream_filter.rb +8 -8
  198. data/lib/samagotchi/web/participant_view.rb +2 -82
  199. data/lib/samagotchi/web/participants_admin.rb +1 -1
  200. data/lib/samagotchi/web/public/block_host.js +35 -8
  201. data/lib/samagotchi/web/public/block_renderers.css +9 -5
  202. data/lib/samagotchi/web/public/card_stamps.js +27 -0
  203. data/lib/samagotchi/web/public/cards_place.js +5 -3
  204. data/lib/samagotchi/web/public/chains.js +2 -2
  205. data/lib/samagotchi/web/public/claim_link.js +4 -4
  206. data/lib/samagotchi/web/public/composer_mode.js +1 -1
  207. data/lib/samagotchi/web/public/format.js +4 -3
  208. data/lib/samagotchi/web/public/turn_html.js +8 -4
  209. data/lib/samagotchi/web/push/store.rb +1 -1
  210. data/lib/samagotchi/web/session_access_routes.rb +13 -4
  211. data/lib/samagotchi/web/session_control.rb +12 -8
  212. data/lib/samagotchi/web/session_create.rb +1 -1
  213. data/lib/samagotchi/web/session_hub.rb +2 -2
  214. data/lib/samagotchi/web/session_show.rb +6 -2
  215. data/lib/samagotchi/web/session_summary.rb +1 -1
  216. data/lib/samagotchi/worker.rb +103 -9
  217. data/lib/samagotchi/worker_link.rb +3 -3
  218. data/lib/samagotchi/working_set_command.rb +3 -2
  219. data/lib/samagotchi.rb +0 -1
  220. metadata +31 -7
  221. data/lib/samagotchi/pending_input_queue.rb +0 -55
  222. data/lib/samagotchi/terminal_ui/between_turns.rb +0 -138
  223. data/lib/samagotchi/terminal_ui/repl_input.rb +0 -152
  224. data/lib/samagotchi/web/grants.rb +0 -575
  225. data/lib/samagotchi/web/participant_exposure.rb +0 -44
  226. data/lib/samagotchi/web/private_files.rb +0 -31
@@ -10,7 +10,7 @@ module Samagotchi
10
10
  # stderr. stdout is the answer's alone, printed after the turn: a
11
11
  # script or a parent agent reads it.
12
12
  #
13
- # It prints the retry lines the REPL shows: the loop asking again after
13
+ # It prints the retry lines the attached terminal shows: the loop asking again after
14
14
  # an empty answer (:empty_answer_retry), and a generation retried after
15
15
  # a failed request (:generation_retrying). And the hooks' notices
16
16
  # (:hook_notice): one during the turn as it comes, one the after_turn
@@ -18,7 +18,7 @@ module Samagotchi
18
18
  # #flush, which the caller runs after it has printed the answer. And
19
19
  # the load warnings the first turn announces (:guardrail_warning: the
20
20
  # guardrails, the plugins, an orphaned project memory folder), as the
21
- # REPL's "<label>> …" lines.
21
+ # attached terminal's "<label>> …" lines.
22
22
  class OneShotSink
23
23
  include Formatting
24
24
 
@@ -12,7 +12,7 @@ module Samagotchi
12
12
  # print as lines. The activity slot is dropped, because redrawing it in
13
13
  # place needs cursor movement (the turn's lines still print as they end).
14
14
  # The prompt is Reline's own, so output may cross it; the editor slot
15
- # prints the prompt of a plain read (the REPL's ? off a terminal).
15
+ # prints the prompt of a plain read (a question's ? off a terminal).
16
16
  class PlainSurface
17
17
  include Surface
18
18
 
@@ -11,8 +11,7 @@ module Samagotchi
11
11
  # slot content (#slot), the line it leaves (#summary) and the parsing of
12
12
  # a typed answer ("2", "1,3", "1 3; text", option labels). No I/O:
13
13
  # callers draw the slot and print the messages, and
14
- # record the answer (the REPL on its Engine, an attached UI over the
15
- # Bridge). An approval (kind "approval") takes only a number, an exact
14
+ # record the answer (an attached UI over the Bridge). An approval (kind "approval") takes only a number, an exact
16
15
  # label, y (the first option, Allow once) or n (the last, Deny), plus
17
16
  # an optional "; reason"; a substring would pick the wrong one ("y" is
18
17
  # in "Deny"). The step-limit question (kind "continue") reads the
@@ -86,8 +85,8 @@ module Samagotchi
86
85
  end
87
86
 
88
87
  # The line a question dismissed in a --non-interactive run leaves (no
89
- # one could answer it there): the REPL's own, and an attached UI's on
90
- # its cancel (QuestionDesk::UNANSWERABLE_REASON).
88
+ # one could answer it there): the one-shot's own, and an attached UI's
89
+ # on its cancel (QuestionDesk::UNANSWERABLE_REASON).
91
90
  UNANSWERABLE_TEXT = "(dismissed: no one to answer in a non-interactive run)"
92
91
 
93
92
  # What a question closed with no answer here says: a relayed approval
@@ -220,7 +219,7 @@ module Samagotchi
220
219
  end
221
220
 
222
221
  # The continue words, or an option's number. Empty is Continue (Enter
223
- # alone, as at the REPL's continue prompt).
222
+ # alone).
224
223
  def parse_continue(raw)
225
224
  text = raw.to_s.strip
226
225
  if text.match?(/\A\d+\z/)
@@ -39,16 +39,11 @@ module Samagotchi
39
39
  attr_reader :screen
40
40
 
41
41
  # Asked first on Ctrl-C during a read, with or without a screen: a
42
- # truthy answer means it handled the key (the REPL cancelled a running
43
- # turn) and the read goes on with the typed text as it is.
42
+ # truthy answer means it handled the key (the attached loop cancelled a
43
+ # running turn) and the read goes on with the typed text as it is.
44
44
  # @return [#call, nil]
45
45
  attr_accessor :interrupt_handler
46
46
 
47
- # Called with no arguments for each key a read takes (typing is
48
- # activity for the REPL's idle clock).
49
- # @return [#call, nil]
50
- attr_accessor :key_handler
51
-
52
47
  # @return [Boolean] a Reline read is open (it owns stdin)
53
48
  def reading? = @reading == true
54
49
 
@@ -150,11 +145,6 @@ module Samagotchi
150
145
  @rendered_screen.base_y = 0 if RelineSeam.screen
151
146
  end
152
147
 
153
- def update(key)
154
- RelineSeam.key_handler&.call
155
- super
156
- end
157
-
158
148
  def screen_height
159
149
  screen = RelineSeam.screen
160
150
  screen ? [super, screen.editor_budget].min : super
@@ -6,8 +6,8 @@ module Samagotchi
6
6
  class TerminalUI
7
7
  # The status row under the prompt, the same for both TUIs:
8
8
  # `status> Title | model=… | ↳ parent | ⑂ 2 running · 1 waiting | 2 participants | ctx=12.3% (under20) | mem: … | muted: …`.
9
- # A UI feeds it what it learns (attached mode from the Bridge's events,
10
- # the REPL from its Engine's) through #update, and the row is redrawn in
9
+ # The attached TUI feeds it what it learns from the Bridge's events
10
+ # through #update, and the row is redrawn in
11
11
  # the surface's status slot only when its text changes.
12
12
  class StatusRow
13
13
  include Formatting
@@ -54,13 +54,6 @@ module Samagotchi
54
54
  @shown = nil
55
55
  end
56
56
 
57
- # The surface it draws on (the REPL swaps in a live region): the row
58
- # is drawn there at the next change.
59
- def surface=(surface)
60
- @surface = surface
61
- @shown = nil
62
- end
63
-
64
57
  def [](field) = @values[field]
65
58
 
66
59
  # Change some fields; the row is redrawn when its text changed.
@@ -72,8 +65,8 @@ module Samagotchi
72
65
  refresh
73
66
  end
74
67
 
75
- # Take a session's state: the REPL's Engine#session_state_snapshot, or
76
- # the one a worker sends an attached TUI when it joins. A key the state
68
+ # Take a session's state: the one a worker sends an attached TUI when
69
+ # it joins (Engine#session_state_snapshot). A key the state
77
70
  # lacks (an older worker's) leaves its field as it was; the served pair
78
71
  # is cleared without one, and the model is kept without a name.
79
72
  # @param default_model [String, nil] the config's default, named beside
@@ -94,8 +87,7 @@ module Samagotchi
94
87
  STATE_LISTS = { used_memories: :used_memory_names, preloaded: :preloaded_memory_names,
95
88
  muted: :muted_memory_names }.freeze
96
89
 
97
- # Take what a turn event says about the row (the Engine's events in
98
- # the REPL, the Bridge's in attached mode): ctx, the memories used,
90
+ # Take what a turn event says about the row (the Bridge's events): ctx, the memories used,
99
91
  # the model the server served, whether a turn runs (the steer
100
92
  # hint). Other events change nothing.
101
93
  def take_event(event)
@@ -178,7 +170,7 @@ module Samagotchi
178
170
  end
179
171
 
180
172
  # `⑂ 2 running · 1 waiting`, the counts there are; "" with neither (no
181
- # children, or all ended). Not "not reported": a REPL parent is never
173
+ # children, or all ended). Not "not reported": a one-shot parent is never
182
174
  # given its children's replies (no wakes there), and a worker moves
183
175
  # the cursors only after the turn_completed a terminal refreshes on.
184
176
  def children_text(counts)