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
@@ -24,7 +24,7 @@ module Samagotchi
24
24
  #
25
25
  # The worker first takes the session's OwnerLock; when another owner holds
26
26
  # it (a racing resume spawned two workers, or the TUI has the session) it
27
- # exits quietly.
27
+ # exits quietly. A storage migration's hold is waited for (#owner_lock_for).
28
28
  #
29
29
  # A worker nobody uses returns once session.idle_exit_minutes have passed
30
30
  # (see WorkerIdleExit), and one a client asked to exit (Bridge POST /exit)
@@ -52,7 +52,7 @@ module Samagotchi
52
52
  # process's pid) and before any thread starts.
53
53
  detach_from_spawner(session_dir) if ENV.delete(SessionManager::WORKER_DETACH_ENV) == "1"
54
54
  # Kept in a module ivar so the lock's File lives as long as the worker.
55
- @owner_lock = OwnerLock.acquire(session_dir, kind: "worker", wait: owner_wait)
55
+ @owner_lock = owner_lock_for(session_dir, owner_wait)
56
56
  exit(0) unless @owner_lock
57
57
  # Set by the boot string when the newest installed chi didn't load.
58
58
  fallback = ENV.delete(SessionManager::BOOT_FALLBACK_ENV)
@@ -115,20 +115,36 @@ module Samagotchi
115
115
  end
116
116
 
117
117
  # Start this session's next worker as this one leaves (+result+), on
118
- # the session inbox's leave row (SessionInbox::WakePolicy), read on a
118
+ # the session inbox's leave row (InboxDelivery::WakePolicy), read on a
119
119
  # fresh WorkerPresence now the lock is free: a stop that landed as it
120
120
  # left wins for every way out (resume_session would clear it; a
121
121
  # restart's reminders go with it), and a worker that took the session
122
122
  # since, or one being started, gets no second one. What waits (input,
123
- # rings) stays on disk for the next start.
123
+ # rings) stays on disk for the next start. A storage migration holding
124
+ # the lock is waited for (WorkerPresence.settled), not read as an owner.
124
125
  private def respawn(session_id, state_dir:, session_dir:, result:)
125
- decided = SessionInbox::WakePolicy.for(:leave).decide(WorkerPresence.read(session_id, state_dir: state_dir))
126
+ decided = InboxDelivery::WakePolicy.for(:leave).decide(WorkerPresence.settled(session_id, state_dir: state_dir))
126
127
  return SessionManager.resume_session(session_id, state_dir: state_dir) if decided == :start
127
128
 
128
129
  ReminderCarry.remove(session_dir) if result == :restart && decided == :stopped
129
130
  Log.info(:worker, result == :restart ? "restart_dropped" : "respawn_dropped", why: decided, reason: result)
130
131
  end
131
132
 
133
+ # The session's OwnerLock, taken within +wait+ seconds; held then by a
134
+ # storage migration (OwnerLock::MIGRATING, converting the session's
135
+ # file), waited for up to MIGRATING_WAIT more: a worker started
136
+ # meanwhile (a ring's wake, a respawn) runs after it, never exits.
137
+ # @return [OwnerLock, nil] nil when another owner holds it
138
+ private def owner_lock_for(session_dir, wait)
139
+ lock = OwnerLock.acquire(session_dir, kind: "worker", wait: wait)
140
+ return lock if lock
141
+
142
+ owner = OwnerLock.owner(session_dir)
143
+ return nil if owner && !owner.migrating?
144
+
145
+ OwnerLock.acquire(session_dir, kind: "worker", wait: OwnerLock::MIGRATING_WAIT)
146
+ end
147
+
132
148
  # A spawned worker leaves its spawner's process tree: a killer that
133
149
  # walks the tree by parent pid (a terminal closing, a tool's teardown
134
150
  # of a `chi send --wait` it ran in the background) no longer reaches it.
@@ -5,7 +5,7 @@ require_relative "log"
5
5
  require_relative "participant_name"
6
6
  require_relative "participant_turn_mode"
7
7
  require_relative "participants"
8
- require_relative "steer"
8
+ require_relative "speaker"
9
9
  require_relative "turn_checkpoint"
10
10
  require_relative "verify_fresh"
11
11
 
@@ -62,7 +62,7 @@ module Samagotchi
62
62
  # else the config's; their turns and the side requests they caused,
63
63
  # Engine#metrics). The owner hears the cap once per cap (#cap_notice).
64
64
  def refusal(author)
65
- author = Steer.sender_author(author) or return nil
65
+ author = Speaker.sender_author(author) or return nil
66
66
 
67
67
  entry = entry(author)
68
68
  case ParticipantTurnMode.of(entry: entry, session: @session, now: Time.now)
@@ -117,7 +117,7 @@ module Samagotchi
117
117
  # +author+'s participants.json entry: this session's, a Verify fresh
118
118
  # child's parent's (Session#participants_source_id); nil for none.
119
119
  def entry(author)
120
- Participants.read(source_id, state_dir: @state_dir).find { |e| Steer.author_for(e.id) == author }
120
+ Participants.read(source_id, state_dir: @state_dir).find { |e| Speaker.author_for(e.id) == author }
121
121
  end
122
122
 
123
123
  # The session whose participants.json and audit trail this session's
@@ -137,7 +137,7 @@ module Samagotchi
137
137
  # A participant's cleaned name, else their id.
138
138
  def label(author, name)
139
139
  who = ParticipantName.clean(name)
140
- who.empty? ? Steer.participant_id(author) : who
140
+ who.empty? ? Speaker.participant_id(author) : who
141
141
  end
142
142
 
143
143
  # The owner's notice that a participant reached their cap: once per
@@ -147,7 +147,7 @@ module Samagotchi
147
147
  return if @cap_noticed.include?(key)
148
148
 
149
149
  @cap_noticed << key
150
- id = Steer.participant_id(author)
150
+ id = Speaker.participant_id(author)
151
151
  @event_log.announce(type: :hook_notice, hook: @hook, level: :warn, between_turns: true,
152
152
  text: format(CAP_NOTICE, name: label(author, entry.name), cap: cap,
153
153
  session: source_id[0, 8], id: id))
@@ -35,7 +35,7 @@ module Samagotchi
35
35
  # Read the facts for +session_id+ now.
36
36
  # @param state_dir [String, nil] nil: Session.default_state_dir
37
37
  # @param owner [OwnerLock::Owner, nil, :read, #call] the lock's holder as
38
- # the caller already read it (SessionManager.session_owner, a stand-in
38
+ # the caller already read it (OwnerLock.for_session, a stand-in
39
39
  # manager's), or a reader of it called only for a valid id; :read reads
40
40
  # it here (OwnerLock.owner)
41
41
  # @param link [nil, :look, :unlink, WorkerLink outcome] also resolve the
@@ -61,6 +61,24 @@ module Samagotchi
61
61
  link: resolved_link(link, dir, owner))
62
62
  end
63
63
 
64
+ # .read, waited for while a storage migration holds the owner lock
65
+ # (WorkerPresence#migrating?: StorageMigration converts the session's
66
+ # file in milliseconds), up to +wait+ seconds: what a delivery decides
67
+ # and a leaving worker's respawn reads are the session's facts once it
68
+ # is gone. Still held past +wait+, the migration is read as a start
69
+ # pending (WakePolicy#decide :starting). +owner+ as .read takes it, a
70
+ # reader (:read or #call) so that each look reads it again.
71
+ # @return [WorkerPresence]
72
+ def self.settled(session_id, wait: OwnerLock::MIGRATING_WAIT, **)
73
+ deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + wait
74
+ loop do
75
+ presence = read(session_id, **)
76
+ return presence unless presence.migrating? && Process.clock_gettime(Process::CLOCK_MONOTONIC) < deadline
77
+
78
+ sleep(OwnerLock::RETRY_INTERVAL)
79
+ end
80
+ end
81
+
64
82
  # The +link:+ argument as the outcome to carry: a resolved outcome
65
83
  # (anything responding to #live?) is used as is; nil reads no link;
66
84
  # :look or :unlink resolves the WorkerLink (WorkerLink.resolve).
@@ -98,6 +116,11 @@ module Samagotchi
98
116
  # delete, an empty session's discard) while the session's files go.
99
117
  def deleting? = owner&.deleting? == true
100
118
 
119
+ # A storage migration holds it (OwnerLock kind migrating) while it
120
+ # converts the session's file: no worker, gone in a moment (.settled
121
+ # waits for it).
122
+ def migrating? = owner&.migrating? == true
123
+
101
124
  # The `<id>/stopped` marker: a user's stop, not the turn's status.
102
125
  def stop_marked? = stop_marked
103
126
 
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.201.0
4
+ version: 0.202.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -388,6 +388,7 @@ files:
388
388
  - lib/samagotchi/context_window.rb
389
389
  - lib/samagotchi/continue_intent.rb
390
390
  - lib/samagotchi/continue_offer.rb
391
+ - lib/samagotchi/continue_repair_backoff.rb
391
392
  - lib/samagotchi/continued_from.rb
392
393
  - lib/samagotchi/core_notice.rb
393
394
  - lib/samagotchi/cut.rb
@@ -825,6 +826,7 @@ files:
825
826
  - lib/samagotchi/session_manager/running_tasks.rb
826
827
  - lib/samagotchi/session_manager/spawn.rb
827
828
  - lib/samagotchi/session_manager/worker_command.rb
829
+ - lib/samagotchi/session_messages.rb
828
830
  - lib/samagotchi/session_metrics.rb
829
831
  - lib/samagotchi/session_metrics/cost.rb
830
832
  - lib/samagotchi/session_metrics/model_segment.rb
@@ -858,6 +860,7 @@ files:
858
860
  - lib/samagotchi/steer.rb
859
861
  - lib/samagotchi/steer_cut.rb
860
862
  - lib/samagotchi/steer_cut_after.rb
863
+ - lib/samagotchi/storage_migration.rb
861
864
  - lib/samagotchi/stream_event.rb
862
865
  - lib/samagotchi/system_one.rb
863
866
  - lib/samagotchi/system_one/answer.rb
@@ -1242,6 +1245,7 @@ files:
1242
1245
  - lib/samagotchi/web/public/route.js
1243
1246
  - lib/samagotchi/web/public/running_tasks.js
1244
1247
  - lib/samagotchi/web/public/schedule_marks.js
1248
+ - lib/samagotchi/web/public/schedule_name.js
1245
1249
  - lib/samagotchi/web/public/scope.js
1246
1250
  - lib/samagotchi/web/public/scroll.js
1247
1251
  - lib/samagotchi/web/public/send_turn.js
@@ -1389,6 +1393,7 @@ files:
1389
1393
  - lib/samagotchi/worker/senders.rb
1390
1394
  - lib/samagotchi/worker/signal_grace.rb
1391
1395
  - lib/samagotchi/worker/startup.rb
1396
+ - lib/samagotchi/worker/turn_drain.rb
1392
1397
  - lib/samagotchi/worker/wake_turns.rb
1393
1398
  - lib/samagotchi/worker_boot.rb
1394
1399
  - lib/samagotchi/worker_exit_claim.rb