samagotchi 0.166.0 → 0.168.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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -1
  3. data/docs/architecture.md +1 -0
  4. data/docs/cli.md +24 -15
  5. data/docs/configuration.md +1 -0
  6. data/docs/guardrails.md +5 -5
  7. data/docs/hooks.md +4 -6
  8. data/docs/internals/bundles.md +2 -4
  9. data/docs/internals/engine.md +4 -5
  10. data/docs/internals/objectives.md +141 -9
  11. data/docs/internals/remote-sessions.md +5 -6
  12. data/docs/internals/web-frontend.md +85 -40
  13. data/docs/memory.md +1 -2
  14. data/docs/sessions.md +20 -2
  15. data/docs/testing.md +3 -3
  16. data/lib/samagotchi/bridge.rb +1 -1
  17. data/lib/samagotchi/bundle_command/installed_check.rb +2 -14
  18. data/lib/samagotchi/bundle_command.rb +35 -12
  19. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  20. data/lib/samagotchi/cli/command.rb +10 -0
  21. data/lib/samagotchi/compat.rb +1 -13
  22. data/lib/samagotchi/config.rb +3 -0
  23. data/lib/samagotchi/context_command.rb +2 -1
  24. data/lib/samagotchi/engine/objectives.rb +20 -1
  25. data/lib/samagotchi/engine/side_requests.rb +3 -2
  26. data/lib/samagotchi/engine/turn_end.rb +4 -1
  27. data/lib/samagotchi/engine.rb +3 -0
  28. data/lib/samagotchi/extension_load.rb +2 -26
  29. data/lib/samagotchi/guardrails/approvals.rb +15 -16
  30. data/lib/samagotchi/jsonl_store.rb +61 -0
  31. data/lib/samagotchi/memory_bundle/status.rb +3 -15
  32. data/lib/samagotchi/memory_bundle/system_bundle.rb +16 -10
  33. data/lib/samagotchi/memory_command.rb +4 -2
  34. data/lib/samagotchi/objectives.rb +43 -14
  35. data/lib/samagotchi/objectives_backing.rb +124 -0
  36. data/lib/samagotchi/objectives_check.rb +19 -126
  37. data/lib/samagotchi/objectives_command.rb +14 -7
  38. data/lib/samagotchi/objectives_record.rb +104 -0
  39. data/lib/samagotchi/objectives_track.rb +353 -0
  40. data/lib/samagotchi/push_command.rb +2 -1
  41. data/lib/samagotchi/remote_command.rb +2 -1
  42. data/lib/samagotchi/reply_wait/poll.rb +6 -6
  43. data/lib/samagotchi/reply_wait.rb +4 -24
  44. data/lib/samagotchi/schedule_command.rb +6 -0
  45. data/lib/samagotchi/schedules.rb +1 -1
  46. data/lib/samagotchi/session_access/remote.rb +3 -5
  47. data/lib/samagotchi/session_commands.rb +1 -1
  48. data/lib/samagotchi/sessions_command.rb +12 -6
  49. data/lib/samagotchi/share_command.rb +2 -1
  50. data/lib/samagotchi/tool_activity.rb +11 -1
  51. data/lib/samagotchi/tool_declarations.rb +5 -1
  52. data/lib/samagotchi/tools/objectives_tool.rb +19 -2
  53. data/lib/samagotchi/turn_stages/objectives.rb +46 -3
  54. data/lib/samagotchi/version.rb +1 -1
  55. data/lib/samagotchi/web/participant_access.rb +1 -1
  56. data/lib/samagotchi/web/public/app.js +52 -424
  57. data/lib/samagotchi/web/public/copy.js +2 -1
  58. data/lib/samagotchi/web/public/dock_reserve.js +12 -2
  59. data/lib/samagotchi/web/public/history_end.js +16 -0
  60. data/lib/samagotchi/web/public/index.html +74 -22
  61. data/lib/samagotchi/web/public/info_bar_model.js +3 -1
  62. data/lib/samagotchi/web/public/no_contact_fill.js +29 -0
  63. data/lib/samagotchi/web/public/objectives.css +14 -0
  64. data/lib/samagotchi/web/public/objectives_moves.js +82 -9
  65. data/lib/samagotchi/web/public/objectives_state.js +42 -0
  66. data/lib/samagotchi/web/public/objectives_strip.js +33 -9
  67. data/lib/samagotchi/web/public/objectives_track.js +52 -0
  68. data/lib/samagotchi/web/public/objectives_wiring.js +16 -1
  69. data/lib/samagotchi/web/public/participant.html +1 -1
  70. data/lib/samagotchi/web/public/participants_panel.js +14 -7
  71. data/lib/samagotchi/web/public/question_cards.js +8 -13
  72. data/lib/samagotchi/web/public/refs.js +4 -1
  73. data/lib/samagotchi/web/public/reload_check.js +5 -4
  74. data/lib/samagotchi/web/public/resync_reach.js +10 -6
  75. data/lib/samagotchi/web/public/scope.js +3 -3
  76. data/lib/samagotchi/web/public/session_rename.js +6 -2
  77. data/lib/samagotchi/web/public/session_state.js +1 -1
  78. data/lib/samagotchi/web/public/session_sync.js +249 -0
  79. data/lib/samagotchi/web/public/session_view.js +279 -0
  80. data/lib/samagotchi/web/public/stage_cards.js +20 -0
  81. data/lib/samagotchi/web/public/stage_frame.js +14 -16
  82. data/lib/samagotchi/web/public/stage_model.js +11 -4
  83. data/lib/samagotchi/web/public/stage_opened.js +229 -0
  84. data/lib/samagotchi/web/public/stage_slots.js +2 -3
  85. data/lib/samagotchi/web/public/stage_view.js +219 -147
  86. data/lib/samagotchi/web/public/stage_watch.js +8 -4
  87. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  88. data/lib/samagotchi/web/public/tokens.css +2 -2
  89. data/lib/samagotchi/web/public/turn_block.js +22 -2
  90. data/lib/samagotchi/web/public/turn_html.js +1 -1
  91. data/lib/samagotchi/web/public/widget_picks.js +3 -0
  92. data/lib/samagotchi/web/public/working_set_view.js +1 -1
  93. data/lib/samagotchi/web/session_access_routes.rb +4 -15
  94. metadata +13 -1
@@ -22,6 +22,12 @@ module Samagotchi
22
22
  RECORDED = "Recorded a move on %s."
23
23
  EDITED_BY_USER = "The user edits the list with /objectives."
24
24
  NONE = "There are no objectives here, so nothing was recorded. #{EDITED_BY_USER}".freeze
25
+ # A move's state: where the objective stands in the agent's view. DONE is
26
+ # its claim, never a status change (the user marks done).
27
+ PROGRESS = "progress"
28
+ BLOCKED = "blocked"
29
+ DONE = "done"
30
+ STATES = [PROGRESS, BLOCKED, DONE].freeze
25
31
 
26
32
  def self.name = NAME
27
33
 
@@ -32,8 +38,17 @@ module Samagotchi
32
38
  output.to_s.sub(ToolResponse::LEAD, "").start_with?(RECORDED % id)
33
39
  end
34
40
 
41
+ # A call's state as a move takes it: stripped and downcased, PROGRESS
42
+ # when it names none; nil for one that isn't a state.
43
+ def self.state_of(call)
44
+ state = call[:state].to_s.strip.downcase
45
+ return PROGRESS if state.empty?
46
+
47
+ STATES.include?(state) ? state : nil
48
+ end
49
+
35
50
  # @param call [Hash] the internal call (BuiltinCalls: action:, id:,
36
- # note:, evidence:)
51
+ # note:, evidence:, state:)
37
52
  # @param peers [#objectives, nil] the session's list
38
53
  # @return [String] the tool result
39
54
  def self.call(call, peers:)
@@ -67,7 +82,9 @@ module Samagotchi
67
82
  return "Error: #{Objectives.unknown(id, list)}. Nothing was recorded." unless item
68
83
  return "Error: #{Objectives.dropped(id)}. Nothing was recorded." if item.status == Objectives::DROPPED
69
84
 
70
- "Error: a move needs a note: what moved, in a line." if Objectives.clean(call[:note]).empty?
85
+ return "Error: a move needs a note: what moved, in a line." if Objectives.clean(call[:note]).empty?
86
+
87
+ "Error: a move's state must be #{STATES[0..-2].join(", ")} or #{STATES.last}. Nothing was recorded." unless state_of(call)
71
88
  end
72
89
  private_class_method :refusal
73
90
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "securerandom"
4
+ require_relative "../cancellation_controller"
4
5
  require_relative "../log"
5
6
  require_relative "../objectives"
6
7
  require_relative "../objectives_audit"
8
+ require_relative "../objectives_track"
7
9
  require_relative "../owner_prompt"
8
10
  require_relative "../system_one/client"
9
11
 
@@ -13,9 +15,11 @@ module Samagotchi
13
15
  # list itself; inside this class the bare name is this stage): System 1's
14
16
  # audit of what comes in at a turn's start and what goes out at its end
15
17
  # (ObjectivesAudit), the view announced when it changed, and the model's
16
- # proposals kept as cards until the turn is over. Its state is those
17
- # proposals under their mutex and the last view announced (under the
18
- # event lock); the audit is built per call.
18
+ # proposals kept as cards until the turn is over, and the tracker's
19
+ # automatic read after a turn (ObjectivesTrack). Its state is those
20
+ # proposals under their mutex, the automatic read's cancel under its own,
21
+ # and the last view announced (under the event lock); the audit is built
22
+ # per call.
19
23
  class Objectives
20
24
  # @param side_judgments [SideJudgments] the Engine's side asks (the audit's kinds)
21
25
  # @param host_registry [HostRegistry] System 1's client resolves its host here
@@ -27,6 +31,9 @@ module Samagotchi
27
31
  # The model's proposals until the turn is over (#finally).
28
32
  @proposals = []
29
33
  @proposals_mutex = Mutex.new
34
+ # The automatic read's cancel (#track), until the next turn's start.
35
+ @track_cancel = nil
36
+ @track_mutex = Mutex.new
30
37
  end
31
38
 
32
39
  # System 1 on the objectives, in audit (ObjectivesAudit), at a turn's
@@ -49,6 +56,42 @@ module Samagotchi
49
56
  audit(turn.context.state_dir, recorder).outgoing(turn.session, result.text)
50
57
  end
51
58
 
59
+ # After a completed turn (Engine#track_objectives_after), on the turn's
60
+ # thread: the tracker by itself when ObjectivesTrack.after_turn? says so,
61
+ # on a thread of its own kind (SideJudgments#start), so the turn's end
62
+ # never waits. The stored conversation is read here, on this thread. The
63
+ # next turn's start cancels it (#cancel_track); a typed track isn't.
64
+ # @param engine [Engine] what ObjectivesTrack reads and shows through
65
+ # @return [Thread, nil] the read's thread, nil when none started
66
+ def track(turn, engine:)
67
+ return nil unless ObjectivesTrack.after_turn?(engine, turn)
68
+
69
+ # Its last read still runs (a turn as short as a request): that one
70
+ # stays the one to cancel.
71
+ if @side_judgments.in_flight?(ObjectivesTrack::SOURCE)
72
+ Log.debug(:turn, "objectives_track_skipped", reason: "previous_read_running")
73
+ return nil
74
+ end
75
+
76
+ session = turn.session
77
+ conversation = session.messages.dup
78
+ cancel = CancellationController.new
79
+ thread = @side_judgments.start(ObjectivesTrack::SOURCE, warn: lambda { |e|
80
+ Log.warn(:turn, "objectives_track_failed", error: e.class.name, msg: e.message.to_s[0, 200])
81
+ }) { ObjectivesTrack.run_after_turn(engine, session, conversation, cancel) }
82
+ @track_mutex.synchronize { @track_cancel = cancel } if thread
83
+ thread
84
+ end
85
+
86
+ # The automatic read's request cancelled (CancellationController#cancel!
87
+ # :new_turn); nothing when none runs. At the very start of every turn
88
+ # (Engine#begin_turn, before its own probes and waits), a wake's too, so
89
+ # a one-slot server is free for it.
90
+ def cancel_track
91
+ cancel = @track_mutex.synchronize { @track_cancel.tap { @track_cancel = nil } }
92
+ cancel&.cancel!(:new_turn)
93
+ end
94
+
52
95
  # A note added between turns (Engine#add_context_note): incoming too.
53
96
  # @param recorder [SystemOne::Recorder] the audit's runs (built for this call)
54
97
  # @param state_dir [String] the sessions dir
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Samagotchi
4
- VERSION = "0.166.0"
4
+ VERSION = "0.168.0"
5
5
  # Sent as the User-Agent of every HTTP request chi makes.
6
6
  USER_AGENT = "chi/#{VERSION}"
7
7
  end
@@ -426,7 +426,7 @@ module Samagotchi
426
426
  grant = principal(req).grant
427
427
  return not_permitted_for(req, principal(req)) unless own_turn?(grant, id, options[:turn])
428
428
 
429
- options = options.merge(queued: true, cursor: nil, running_look: nil)
429
+ options = options.merge(queued: true, cursor: nil)
430
430
  session = session_access.show(id)
431
431
  result = session_access.wait_reply(id, **options, poll_interval: @wait_poll_interval,
432
432
  cancelled: -> { !@server_running.call || !@grants.active?(grant.id) })