samagotchi 0.159.0 → 0.160.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -1
  3. data/docs/architecture.md +5 -6
  4. data/docs/cli.md +1 -1
  5. data/docs/guardrails.md +21 -2
  6. data/docs/internals/attached-context.md +4 -2
  7. data/docs/internals/bridge.md +7 -0
  8. data/docs/internals/engine.md +7 -1
  9. data/docs/memory.md +41 -13
  10. data/docs/scheduling.md +16 -3
  11. data/docs/sessions.md +3 -1
  12. data/lib/samagotchi/bridge.rb +11 -2
  13. data/lib/samagotchi/broadcast/scope_card.rb +2 -1
  14. data/lib/samagotchi/bundle_command.rb +1 -0
  15. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  16. data/lib/samagotchi/bundles/system/memory_guide.md +2 -2
  17. data/lib/samagotchi/client_id.rb +4 -0
  18. data/lib/samagotchi/command_intake.rb +56 -0
  19. data/lib/samagotchi/context_absorber.rb +6 -3
  20. data/lib/samagotchi/context_candidate_choice.rb +8 -5
  21. data/lib/samagotchi/context_candidates.rb +11 -8
  22. data/lib/samagotchi/context_command.rb +9 -3
  23. data/lib/samagotchi/context_poller.rb +5 -2
  24. data/lib/samagotchi/context_sources.rb +6 -4
  25. data/lib/samagotchi/engine/events.rb +13 -2
  26. data/lib/samagotchi/engine/guardrails.rb +3 -4
  27. data/lib/samagotchi/engine.rb +1 -0
  28. data/lib/samagotchi/engine_peers.rb +1 -0
  29. data/lib/samagotchi/events.rb +71 -0
  30. data/lib/samagotchi/guardrails/approvals.rb +27 -3
  31. data/lib/samagotchi/hook_routes.rb +0 -1
  32. data/lib/samagotchi/memory_bundle/asset_installer.rb +27 -6
  33. data/lib/samagotchi/memory_bundle/bundle_hook.rb +7 -27
  34. data/lib/samagotchi/memory_bundle/file_actions.rb +3 -4
  35. data/lib/samagotchi/memory_bundle/installed_bundle.rb +1 -1
  36. data/lib/samagotchi/memory_bundle/installer.rb +14 -11
  37. data/lib/samagotchi/memory_bundle/manifest.rb +6 -0
  38. data/lib/samagotchi/memory_bundle/shipped_update.rb +5 -3
  39. data/lib/samagotchi/memory_bundle/status.rb +2 -2
  40. data/lib/samagotchi/memory_bundle/uninstaller.rb +2 -0
  41. data/lib/samagotchi/memory_orphans.rb +14 -4
  42. data/lib/samagotchi/memory_paths.rb +29 -6
  43. data/lib/samagotchi/memory_usage.rb +23 -12
  44. data/lib/samagotchi/plugin/attached_context.rb +3 -1
  45. data/lib/samagotchi/plugin/sessions.rb +4 -1
  46. data/lib/samagotchi/project_command.rb +58 -20
  47. data/lib/samagotchi/project_id.rb +102 -0
  48. data/lib/samagotchi/project_id_clash.rb +62 -0
  49. data/lib/samagotchi/project_init.rb +214 -10
  50. data/lib/samagotchi/project_scope.rb +11 -2
  51. data/lib/samagotchi/schedules.rb +99 -39
  52. data/lib/samagotchi/session.rb +17 -2
  53. data/lib/samagotchi/session_access/local.rb +8 -5
  54. data/lib/samagotchi/session_access/remote.rb +2 -1
  55. data/lib/samagotchi/session_access.rb +4 -1
  56. data/lib/samagotchi/session_commands.rb +7 -3
  57. data/lib/samagotchi/session_continue.rb +10 -6
  58. data/lib/samagotchi/session_manager/spawn.rb +9 -2
  59. data/lib/samagotchi/session_manager/worker_command.rb +7 -19
  60. data/lib/samagotchi/state_format.rb +118 -0
  61. data/lib/samagotchi/tools/context_read.rb +7 -2
  62. data/lib/samagotchi/tools/delegate.rb +10 -2
  63. data/lib/samagotchi/turn_stages/context_judge.rb +7 -7
  64. data/lib/samagotchi/update_command.rb +2 -2
  65. data/lib/samagotchi/version.rb +1 -1
  66. data/lib/samagotchi/web/app.rb +5 -4
  67. data/lib/samagotchi/web/session_access_routes.rb +3 -3
  68. data/lib/samagotchi/worker.rb +18 -6
  69. data/lib/samagotchi/worker_inbound.rb +21 -2
  70. metadata +5 -1
@@ -6,6 +6,7 @@ require "time"
6
6
 
7
7
  require_relative "child_reports"
8
8
  require_relative "client_id"
9
+ require_relative "command_intake"
9
10
  require_relative "config"
10
11
  require_relative "context_note"
11
12
  require_relative "log"
@@ -211,11 +212,24 @@ module Samagotchi
211
212
  prompt
212
213
  end
213
214
 
215
+ # The first prompt's origin: the turn id spawn_session gave it (a wait
216
+ # for it, --new --wait, names it) and who sent it when no person did
217
+ # (Session#first_turn_client_id: a delegating parent, a schedule). A
218
+ # delegate child's task is its parent's even without the field (one
219
+ # spawned by an older chi, or by a caller that names no sender). NONE
220
+ # for a person's session from before either field.
221
+ # @return [TurnOrigin]
222
+ def initial_origin
223
+ client_id = @session.first_turn_client_id
224
+ client_id ||= ClientId.delegate(@session.parent_id) if @session.delegate? && @session.parent_id
225
+ TurnOrigin.of(client_id: client_id, enqueued_id: @session.first_turn_id)
226
+ end
227
+
214
228
  # The first prompt as a command (queued): the session was saved as
215
229
  # running for a turn that won't run.
216
230
  # @return [Boolean] whether it was one
217
231
  def initial_command?(prompt)
218
- return false unless queue_as_command(prompt, TurnOrigin::NONE)
232
+ return false unless queue_as_command(prompt, initial_origin)
219
233
 
220
234
  @session.status = Session::STATUS_IDLE
221
235
  save(:initial_command, unless_stopped: true)
@@ -264,7 +278,11 @@ module Samagotchi
264
278
  # POST /turn; an unknown /word stays a prompt. Queued: the loop's next
265
279
  # pass runs it. A participant's is refused (dropped, with its audit
266
280
  # line): commands and shell lines are the owner's (chi web and the
267
- # Bridge refuse them first; this is the worker's own layer).
281
+ # Bridge refuse them first; this is the worker's own layer). From a
282
+ # sender that may not send commands (CommandIntake.allowed?: a
283
+ # delegate, a schedule, a plugin...) a /word line is a prompt, and a
284
+ # shell line is queued for Worker#run_command_line to refuse, so its
285
+ # sender and the UIs see the refusal as the command's error.
268
286
  # @return [Boolean] whether +text+ was one
269
287
  def queue_as_command(text, origin, after_file = nil)
270
288
  return false unless @engine.command_registry.command?(text.to_s)
@@ -275,6 +293,7 @@ module Samagotchi
275
293
  what: "command", reason: "not_permitted")
276
294
  return true
277
295
  end
296
+ return false unless CommandIntake.allowed?(origin.client_id) || CommandIntake.shell_line?(text)
278
297
 
279
298
  @queue_command.call(text, origin.client_id, after_file, origin.enqueued_id)
280
299
  true
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.159.0
4
+ version: 0.160.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -314,6 +314,7 @@ files:
314
314
  - lib/samagotchi/cli/parent_wait.rb
315
315
  - lib/samagotchi/client.rb
316
316
  - lib/samagotchi/client_id.rb
317
+ - lib/samagotchi/command_intake.rb
317
318
  - lib/samagotchi/command_steps.rb
318
319
  - lib/samagotchi/commands/registry.rb
319
320
  - lib/samagotchi/composer_route.rb
@@ -595,6 +596,8 @@ files:
595
596
  - lib/samagotchi/process_group.rb
596
597
  - lib/samagotchi/project_command.rb
597
598
  - lib/samagotchi/project_env.rb
599
+ - lib/samagotchi/project_id.rb
600
+ - lib/samagotchi/project_id_clash.rb
598
601
  - lib/samagotchi/project_init.rb
599
602
  - lib/samagotchi/project_scope.rb
600
603
  - lib/samagotchi/prompt.rb
@@ -694,6 +697,7 @@ files:
694
697
  - lib/samagotchi/side_judgments.rb
695
698
  - lib/samagotchi/side_usage.rb
696
699
  - lib/samagotchi/starting_marker.rb
700
+ - lib/samagotchi/state_format.rb
697
701
  - lib/samagotchi/steer.rb
698
702
  - lib/samagotchi/steer_cut.rb
699
703
  - lib/samagotchi/steer_cut_after.rb