samagotchi 0.185.0 → 0.187.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -1
  3. data/bin/chi +2 -0
  4. data/docs/cli.md +1 -0
  5. data/docs/configuration.md +18 -0
  6. data/docs/guardrails.md +13 -0
  7. data/docs/internals/bridge.md +1 -0
  8. data/docs/internals/engine.md +15 -1
  9. data/docs/internals/inline-widgets.md +18 -0
  10. data/docs/internals/pages.md +172 -0
  11. data/docs/internals/prompt-caching.md +14 -0
  12. data/docs/internals/remote-sessions.md +7 -0
  13. data/docs/internals/web-frontend.md +5 -4
  14. data/docs/memory.md +7 -0
  15. data/docs/pages.md +150 -0
  16. data/docs/thin-clients.md +67 -2
  17. data/lib/samagotchi/bridge.rb +1 -1
  18. data/lib/samagotchi/bundles/system/manifest.yml +5 -2
  19. data/lib/samagotchi/bundles/system/self_map.md +5 -1
  20. data/lib/samagotchi/bundles/system/skill_pages.md +93 -0
  21. data/lib/samagotchi/config.rb +3 -1
  22. data/lib/samagotchi/context_absorber.rb +5 -2
  23. data/lib/samagotchi/engine.rb +9 -2
  24. data/lib/samagotchi/inline_widgets.rb +65 -0
  25. data/lib/samagotchi/llm/chat_loop.rb +16 -2
  26. data/lib/samagotchi/page_command.rb +234 -0
  27. data/lib/samagotchi/pages/builder.rb +187 -0
  28. data/lib/samagotchi/pages/launch.rb +187 -0
  29. data/lib/samagotchi/pages/runner.rb +154 -0
  30. data/lib/samagotchi/pages/store.rb +143 -0
  31. data/lib/samagotchi/pages.rb +119 -0
  32. data/lib/samagotchi/plain_reply.rb +75 -0
  33. data/lib/samagotchi/reply_for.rb +254 -0
  34. data/lib/samagotchi/run_options.rb +1 -0
  35. data/lib/samagotchi/session_access/ask.rb +5 -2
  36. data/lib/samagotchi/session_access/contract.rb +1 -1
  37. data/lib/samagotchi/session_access/exchange/token.rb +42 -7
  38. data/lib/samagotchi/session_access/exchange.rb +5 -2
  39. data/lib/samagotchi/session_access/local.rb +4 -2
  40. data/lib/samagotchi/session_access/remote.rb +5 -1
  41. data/lib/samagotchi/session_manager/delivery.rb +36 -6
  42. data/lib/samagotchi/steer.rb +30 -8
  43. data/lib/samagotchi/turn_anchors.rb +65 -17
  44. data/lib/samagotchi/turn_checkpoint.rb +5 -3
  45. data/lib/samagotchi/version.rb +1 -1
  46. data/lib/samagotchi/web/app.rb +6 -6
  47. data/lib/samagotchi/web/ask_routes.rb +62 -17
  48. data/lib/samagotchi/web/page_routes.rb +116 -0
  49. data/lib/samagotchi/web/participant_access.rb +1 -1
  50. data/lib/samagotchi/web/public/app.js +24 -84
  51. data/lib/samagotchi/web/public/index.html +3 -0
  52. data/lib/samagotchi/web/public/page_blocks.js +58 -0
  53. data/lib/samagotchi/web/public/page_links.js +33 -0
  54. data/lib/samagotchi/web/public/page_model.js +68 -0
  55. data/lib/samagotchi/web/public/page_route.js +24 -0
  56. data/lib/samagotchi/web/public/page_table.js +74 -0
  57. data/lib/samagotchi/web/public/page_table_model.js +76 -0
  58. data/lib/samagotchi/web/public/page_view.js +218 -0
  59. data/lib/samagotchi/web/public/pages.css +77 -0
  60. data/lib/samagotchi/web/public/pages_group.js +65 -0
  61. data/lib/samagotchi/web/public/peer_text.js +22 -5
  62. data/lib/samagotchi/web/public/views.js +161 -0
  63. data/lib/samagotchi/web/session_access_routes.rb +30 -2
  64. data/lib/samagotchi/web/session_control.rb +21 -2
  65. data/lib/samagotchi/web/viewer.rb +1 -1
  66. data/lib/samagotchi/worker.rb +2 -1
  67. metadata +23 -1
@@ -5,6 +5,7 @@ require_relative "../client_id"
5
5
  require_relative "../delivery"
6
6
  require_relative "../image_store"
7
7
  require_relative "../prompt_history"
8
+ require_relative "../reply_for"
8
9
  require_relative "../session"
9
10
  require_relative "../session_command_catalog"
10
11
  require_relative "../session_manager"
@@ -57,6 +58,19 @@ module Samagotchi
57
58
  qid = body["id"]
58
59
  return error_response(400, "missing_fields", "id is required") if qid.to_s.strip.empty?
59
60
 
61
+ # reply_for: the answering surface's (a thin client's, ReplyFor). One
62
+ # without detail may not answer an approval, a spending question or
63
+ # a user-only option (ReplyFor#answers?): 403, nothing relayed.
64
+ begin
65
+ answering = ReplyFor.parse(body["reply_for"])
66
+ rescue ReplyFor::Invalid => e
67
+ return error_response(400, "invalid_answer", e.message)
68
+ end
69
+ pending = session.pending_question
70
+ if answering && pending && pending.id.to_s == qid.to_s && !answering.answers?(pending)
71
+ return json_response(403, ReplyFor::NEEDS_DETAIL)
72
+ end
73
+
60
74
  # wait: a thin client's answer that also waits for what comes next
61
75
  # (AskRoutes#answered_wait), its start read before the answer goes in.
62
76
  wait, error = answer_wait_option(body)
@@ -65,6 +79,11 @@ module Samagotchi
65
79
  start = answer_wait_start(id, session, qid) if wait
66
80
  return session_not_found(id) if wait && !start
67
81
 
82
+ # The pending turn's surface, from its saved opener (the running
83
+ # turn's checkpoint copy until its first boundary), read before the
84
+ # answer goes in: its reply is shaped for it (#answered_wait).
85
+ reply_for = ReplyFor.of_latest_turn(session.messages) if wait
86
+
68
87
  # client_id: only chi answer's (a parent agent's answer, which the
69
88
  # worker holds to its guardrails.parent_answers) is passed on; any
70
89
  # other is dropped, so a forward can only tighten (an answer never
@@ -93,7 +112,7 @@ module Samagotchi
93
112
  detail: reply_detail(reply, "the worker refused that option") })
94
113
  end
95
114
  end
96
- relayed.is_a?(Symbol) ? answered_wait(id, qid, start, wait, answered: relayed == :answered) : relayed
115
+ relayed.is_a?(Symbol) ? answered_wait(id, qid, start, wait, answered: relayed == :answered, reply_for: reply_for) : relayed
97
116
  end
98
117
 
99
118
  # A request to the worker sent once more when the worker dropped it as
@@ -235,7 +254,7 @@ module Samagotchi
235
254
  result = SessionManager.deliver_turn(id, prompt: prompt.to_s, client_id: client_id, images: images,
236
255
  delivery: delivery, no_interrupt: body["no_interrupt"] == true,
237
256
  author: principal(req).author,
238
- anchors: TurnAnchors.from(body),
257
+ anchors: TurnAnchors.from_turn_route(body),
239
258
  follow: body["follow"] == true,
240
259
  state_dir: @state_dir, manager: @manager,
241
260
  bridge: -> { live_bridge_client(id) })
@@ -48,7 +48,7 @@ module Samagotchi
48
48
  # docs/internals/web-frontend.md, The viewer).
49
49
  Viewer::CAPABILITIES = %w[
50
50
  sessions models prompt_history push context working_set working_set_items participants_admin rename images
51
- session_controls revise answer_cards render block_renderers stop_any_turn steer_any_turn
51
+ session_controls revise answer_cards render block_renderers stop_any_turn steer_any_turn pages
52
52
  ].freeze
53
53
 
54
54
  # A participant's capabilities: names of their own (the owner's are
@@ -26,6 +26,7 @@ require_relative "reminder_carry"
26
26
  require_relative "log"
27
27
  require_relative "turn_flow"
28
28
  require_relative "turn_checkpoint"
29
+ require_relative "reply_for"
29
30
  require_relative "continue_offer"
30
31
  require_relative "iteration_limit"
31
32
  require_relative "session_commands"
@@ -763,7 +764,7 @@ module Samagotchi
763
764
  restores = @turn_flow.restores
764
765
  begin
765
766
  @checkpoint.begin_turn(prompt: prompt, turn_id: turn_args[:id], enqueued_id: origin.enqueued_id, author: turn_author_fields(origin),
766
- source: turn_args[:opener_source])
767
+ source: turn_args[:opener_source], reply: ReplyFor.opener_fields(@session.messages, turn_args[:reply_for]))
767
768
  @session.status = Session::STATUS_RUNNING
768
769
  # A continue that moved this session to the chain's new link wrote
769
770
  # the new parent beside it (Session::PARENT_FILE): this turn's
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.185.0
4
+ version: 0.187.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -166,6 +166,7 @@ files:
166
166
  - docs/internals/llm-context-forget.md
167
167
  - docs/internals/llm-context-live.md
168
168
  - docs/internals/objectives.md
169
+ - docs/internals/pages.md
169
170
  - docs/internals/participants.md
170
171
  - docs/internals/prompt-caching.md
171
172
  - docs/internals/remote-sessions.md
@@ -176,6 +177,7 @@ files:
176
177
  - docs/internals/working-set.md
177
178
  - docs/mcp-server.md
178
179
  - docs/memory.md
180
+ - docs/pages.md
179
181
  - docs/plugins.md
180
182
  - docs/releasing.md
181
183
  - docs/scheduling.md
@@ -312,6 +314,7 @@ files:
312
314
  - lib/samagotchi/bundles/system/manifest.yml
313
315
  - lib/samagotchi/bundles/system/memory_guide.md
314
316
  - lib/samagotchi/bundles/system/self_map.md
317
+ - lib/samagotchi/bundles/system/skill_pages.md
315
318
  - lib/samagotchi/bundles/web-search/manifest.yml
316
319
  - lib/samagotchi/bundles/web-search/plugin.rb
317
320
  - lib/samagotchi/bundles/work-cap/manifest.yml
@@ -606,6 +609,12 @@ files:
606
609
  - lib/samagotchi/output_formatter.rb
607
610
  - lib/samagotchi/owner_lock.rb
608
611
  - lib/samagotchi/owner_prompt.rb
612
+ - lib/samagotchi/page_command.rb
613
+ - lib/samagotchi/pages.rb
614
+ - lib/samagotchi/pages/builder.rb
615
+ - lib/samagotchi/pages/launch.rb
616
+ - lib/samagotchi/pages/runner.rb
617
+ - lib/samagotchi/pages/store.rb
609
618
  - lib/samagotchi/parent_answers_command.rb
610
619
  - lib/samagotchi/parent_report.rb
611
620
  - lib/samagotchi/participant_exposure.rb
@@ -621,6 +630,7 @@ files:
621
630
  - lib/samagotchi/peer_exchanges.rb
622
631
  - lib/samagotchi/peer_sources.rb
623
632
  - lib/samagotchi/pending_question.rb
633
+ - lib/samagotchi/plain_reply.rb
624
634
  - lib/samagotchi/plugin/api.rb
625
635
  - lib/samagotchi/plugin/attached_context.rb
626
636
  - lib/samagotchi/plugin/card.rb
@@ -686,6 +696,7 @@ files:
686
696
  - lib/samagotchi/remote_attach_command.rb
687
697
  - lib/samagotchi/remote_command.rb
688
698
  - lib/samagotchi/remotes.rb
699
+ - lib/samagotchi/reply_for.rb
689
700
  - lib/samagotchi/reply_wait.rb
690
701
  - lib/samagotchi/reply_wait/liveness.rb
691
702
  - lib/samagotchi/reply_wait/poll.rb
@@ -963,6 +974,7 @@ files:
963
974
  - lib/samagotchi/web/markdown_renderer.rb
964
975
  - lib/samagotchi/web/mcp_route.rb
965
976
  - lib/samagotchi/web/message_display.rb
977
+ - lib/samagotchi/web/page_routes.rb
966
978
  - lib/samagotchi/web/participant_access.rb
967
979
  - lib/samagotchi/web/participant_history.rb
968
980
  - lib/samagotchi/web/participant_images.rb
@@ -1075,6 +1087,15 @@ files:
1075
1087
  - lib/samagotchi/web/public/objectives_wiring.js
1076
1088
  - lib/samagotchi/web/public/owner_claim.js
1077
1089
  - lib/samagotchi/web/public/owner_verify.js
1090
+ - lib/samagotchi/web/public/page_blocks.js
1091
+ - lib/samagotchi/web/public/page_links.js
1092
+ - lib/samagotchi/web/public/page_model.js
1093
+ - lib/samagotchi/web/public/page_route.js
1094
+ - lib/samagotchi/web/public/page_table.js
1095
+ - lib/samagotchi/web/public/page_table_model.js
1096
+ - lib/samagotchi/web/public/page_view.js
1097
+ - lib/samagotchi/web/public/pages.css
1098
+ - lib/samagotchi/web/public/pages_group.js
1078
1099
  - lib/samagotchi/web/public/pan_zoom.js
1079
1100
  - lib/samagotchi/web/public/participant_bar.js
1080
1101
  - lib/samagotchi/web/public/participant_history.js
@@ -1202,6 +1223,7 @@ files:
1202
1223
  - lib/samagotchi/web/public/version_notices.js
1203
1224
  - lib/samagotchi/web/public/viewer.js
1204
1225
  - lib/samagotchi/web/public/viewer_self.js
1226
+ - lib/samagotchi/web/public/views.js
1205
1227
  - lib/samagotchi/web/public/widget_picks.js
1206
1228
  - lib/samagotchi/web/public/widget_walk.js
1207
1229
  - lib/samagotchi/web/public/widgets.css