samagotchi 0.165.0 → 0.167.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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -1
  3. data/docs/architecture.md +1 -0
  4. data/docs/cli.md +16 -7
  5. data/docs/configuration.md +4 -1
  6. data/docs/guardrails.md +8 -3
  7. data/docs/hooks.md +4 -6
  8. data/docs/internals/bridge.md +6 -0
  9. data/docs/internals/bundles.md +2 -4
  10. data/docs/internals/engine.md +4 -5
  11. data/docs/internals/objectives.md +141 -9
  12. data/docs/internals/remote-sessions.md +6 -7
  13. data/docs/internals/web-frontend.md +62 -24
  14. data/docs/memory.md +1 -2
  15. data/docs/releasing.md +12 -3
  16. data/docs/sessions.md +24 -6
  17. data/docs/testing.md +14 -4
  18. data/lib/samagotchi/bridge.rb +1 -1
  19. data/lib/samagotchi/bundle_command/installed_check.rb +2 -14
  20. data/lib/samagotchi/bundle_command.rb +19 -11
  21. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  22. data/lib/samagotchi/cli/command.rb +10 -0
  23. data/lib/samagotchi/compat.rb +4 -14
  24. data/lib/samagotchi/config.rb +3 -0
  25. data/lib/samagotchi/context_command.rb +2 -1
  26. data/lib/samagotchi/engine/objectives.rb +20 -1
  27. data/lib/samagotchi/engine/side_requests.rb +3 -2
  28. data/lib/samagotchi/engine/turn_end.rb +4 -1
  29. data/lib/samagotchi/engine.rb +3 -0
  30. data/lib/samagotchi/extension_load.rb +2 -26
  31. data/lib/samagotchi/guardrails/approvals.rb +59 -9
  32. data/lib/samagotchi/jsonl_store.rb +61 -0
  33. data/lib/samagotchi/memory_bundle/status.rb +3 -15
  34. data/lib/samagotchi/memory_bundle/system_bundle.rb +16 -10
  35. data/lib/samagotchi/memory_command.rb +4 -2
  36. data/lib/samagotchi/objectives.rb +43 -14
  37. data/lib/samagotchi/objectives_backing.rb +124 -0
  38. data/lib/samagotchi/objectives_check.rb +19 -126
  39. data/lib/samagotchi/objectives_command.rb +14 -7
  40. data/lib/samagotchi/objectives_record.rb +104 -0
  41. data/lib/samagotchi/objectives_track.rb +353 -0
  42. data/lib/samagotchi/plugin/sessions.rb +4 -1
  43. data/lib/samagotchi/push_command.rb +2 -1
  44. data/lib/samagotchi/remote_command.rb +2 -1
  45. data/lib/samagotchi/reply_wait/poll.rb +10 -21
  46. data/lib/samagotchi/reply_wait.rb +4 -47
  47. data/lib/samagotchi/run_options.rb +1 -1
  48. data/lib/samagotchi/schedule_command.rb +6 -0
  49. data/lib/samagotchi/schedules.rb +1 -1
  50. data/lib/samagotchi/session_access/remote.rb +7 -24
  51. data/lib/samagotchi/session_commands.rb +1 -1
  52. data/lib/samagotchi/session_inbox.rb +1 -1
  53. data/lib/samagotchi/sessions_command.rb +12 -6
  54. data/lib/samagotchi/share_command.rb +2 -1
  55. data/lib/samagotchi/tool_activity.rb +11 -1
  56. data/lib/samagotchi/tool_declarations.rb +5 -1
  57. data/lib/samagotchi/tools/delegate.rb +2 -4
  58. data/lib/samagotchi/tools/objectives_tool.rb +19 -2
  59. data/lib/samagotchi/turn_stages/objectives.rb +46 -3
  60. data/lib/samagotchi/version.rb +1 -1
  61. data/lib/samagotchi/web/participant_access.rb +1 -1
  62. data/lib/samagotchi/web/public/app.js +55 -420
  63. data/lib/samagotchi/web/public/auth_lost.js +3 -1
  64. data/lib/samagotchi/web/public/bar_fold.js +1 -1
  65. data/lib/samagotchi/web/public/chip_popover.js +5 -1
  66. data/lib/samagotchi/web/public/copy.js +2 -1
  67. data/lib/samagotchi/web/public/delivery_line.js +19 -4
  68. data/lib/samagotchi/web/public/index.html +156 -49
  69. data/lib/samagotchi/web/public/info_bar.js +1 -1
  70. data/lib/samagotchi/web/public/info_bar_model.js +8 -1
  71. data/lib/samagotchi/web/public/live_timing.js +3 -0
  72. data/lib/samagotchi/web/public/no_contact_fill.js +29 -0
  73. data/lib/samagotchi/web/public/objectives.css +14 -0
  74. data/lib/samagotchi/web/public/objectives_moves.js +82 -9
  75. data/lib/samagotchi/web/public/objectives_state.js +42 -0
  76. data/lib/samagotchi/web/public/objectives_strip.js +33 -9
  77. data/lib/samagotchi/web/public/objectives_track.js +52 -0
  78. data/lib/samagotchi/web/public/objectives_wiring.js +16 -1
  79. data/lib/samagotchi/web/public/participant.html +1 -1
  80. data/lib/samagotchi/web/public/participants_panel.js +14 -7
  81. data/lib/samagotchi/web/public/question_cards.js +7 -12
  82. data/lib/samagotchi/web/public/resync_reach.js +63 -0
  83. data/lib/samagotchi/web/public/scope.js +3 -3
  84. data/lib/samagotchi/web/public/session_fields.js +1 -0
  85. data/lib/samagotchi/web/public/session_rename.js +6 -2
  86. data/lib/samagotchi/web/public/session_state.js +6 -1
  87. data/lib/samagotchi/web/public/session_sync.js +249 -0
  88. data/lib/samagotchi/web/public/session_view.js +279 -0
  89. data/lib/samagotchi/web/public/stage_frame.js +4 -2
  90. data/lib/samagotchi/web/public/stage_stall.js +134 -0
  91. data/lib/samagotchi/web/public/stage_view.js +75 -6
  92. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  93. data/lib/samagotchi/web/public/tokens.css +2 -2
  94. data/lib/samagotchi/web/public/turn_block.js +8 -0
  95. data/lib/samagotchi/web/public/turn_html.js +1 -1
  96. data/lib/samagotchi/web/public/widget_picks.js +3 -0
  97. data/lib/samagotchi/web/public/working_set_view.js +1 -1
  98. data/lib/samagotchi/web/session_access_routes.rb +4 -15
  99. data/lib/samagotchi/web/token.rb +2 -2
  100. metadata +12 -1
@@ -144,11 +144,18 @@ module Samagotchi
144
144
 
145
145
  def list
146
146
  format, scope, cwd = @opts.values_at(:format, :scope, :cwd)
147
- unless format.nil? || %w[text json tsv].include?(format)
148
- return usage_error("unknown format #{format.inspect}: use --format text|json|tsv")
149
- end
147
+ refused = format_refusal(format, %w[text json tsv])
148
+ return refused if refused
150
149
  return usage_error("unknown scope #{scope.inspect}: use --scope=project|all") unless scope.nil? || %w[project all].include?(scope)
151
150
 
151
+ sort, order = @opts.values_at(:sort, :order)
152
+ unless sort.nil? || Samagotchi::Session::SORT_KEYS.include?(sort)
153
+ return usage_error("unknown sort #{sort.inspect}: use --sort #{Samagotchi::Session::SORT_KEYS.join("|")}")
154
+ end
155
+ unless order.nil? || Samagotchi::Session::SORT_ORDERS.include?(order)
156
+ return usage_error("unknown order #{order.inspect}: use --order #{Samagotchi::Session::SORT_ORDERS.join("|")}")
157
+ end
158
+
152
159
  # The current git project's sessions (Samagotchi::ProjectScope), like
153
160
  # chi web's; --scope=all, a folder in no repo or an explicit --cwd: every
154
161
  # project's. Machine-local (this cwd's project): remotely every
@@ -210,9 +217,8 @@ module Samagotchi
210
217
  return usage_error("stats takes one session id") if ids.size > 1
211
218
 
212
219
  format = @opts[:format]
213
- unless format.nil? || %w[text json].include?(format)
214
- return usage_error("unknown format #{format.inspect}: use --format text|json")
215
- end
220
+ refused = format_refusal(format)
221
+ return refused if refused
216
222
 
217
223
  id = begin
218
224
  Samagotchi::Session.resolve_id(ids.first)
@@ -135,7 +135,8 @@ module Samagotchi
135
135
  return usage_error("ls takes at most one session ID") if args.size > 1
136
136
 
137
137
  format = options[:format]
138
- return usage_error("unknown format #{format.inspect}: use --format text|json") unless [nil, "text", "json"].include?(format)
138
+ refused = format_refusal(format)
139
+ return refused if refused
139
140
 
140
141
  id = args.first && @access.resolve(args.first)
141
142
  rows = @access.participants(id)
@@ -89,6 +89,16 @@ module Samagotchi
89
89
 
90
90
  def objectives_proposal?(call) = call[:action].to_s.strip.downcase == Tools::ObjectivesTool::PROPOSE
91
91
 
92
+ # A move's state=, before note= so a cut can't drop it: the page reads it from
93
+ # the params (the title stays as an older page reads it). None for a
94
+ # proposal, progress or a state the tool refuses.
95
+ def objectives_state_param(call)
96
+ return [] if objectives_proposal?(call)
97
+
98
+ state = Tools::ObjectivesTool.state_of(call)
99
+ [Tools::ObjectivesTool::BLOCKED, Tools::ObjectivesTool::DONE].include?(state) ? ["state=#{preview_tool_param(state)}"] : []
100
+ end
101
+
92
102
  # An objectives row's words: "O2 note · evidence", or "propose done O2 note".
93
103
  def objectives_title(call)
94
104
  return "#{Tools::ObjectivesTool::PROPOSE} #{call[:change]} #{call[:id]} #{call[:text]} · #{call[:note]}".squeeze(" ") if objectives_proposal?(call)
@@ -447,7 +457,7 @@ module Samagotchi
447
457
  parts << "note=#{preview_tool_param(request.note)}" unless request.note.empty?
448
458
  parts.empty? ? nil : parts.join(" ")
449
459
  when Tools::ObjectivesTool::NAME
450
- parts = ["id=#{preview_tool_param(call[:id])}", "note=#{preview_tool_param(call[:note])}"]
460
+ parts = ["id=#{preview_tool_param(call[:id])}", *objectives_state_param(call), "note=#{preview_tool_param(call[:note])}"]
451
461
  parts.unshift("change=#{preview_tool_param(call[:change])}") if objectives_proposal?(call)
452
462
  parts << "evidence=#{preview_tool_param(call[:evidence])}" unless call[:evidence].to_s.strip.empty?
453
463
  parts.join(" ")
@@ -486,7 +486,7 @@ module Samagotchi
486
486
  },
487
487
  {
488
488
  name: "objectives",
489
- description: "Record a move on one of the objectives in the OBJECTIVES note: in a line, what you did or found that moves it, so the user can follow. One when an objective really moved, not per step. Or propose a change to the list (action propose): the user sees a card and applies it or not. This tool doesn't edit the list, change a status or mark anything done, and it approves nothing; the user edits the list with /objectives. Asked to change it, propose it or say so, instead of saying you changed it.",
489
+ description: "Record a move on one of the objectives in the OBJECTIVES note: in a line, what you did or found that moves it and where it stands (state), so the user can follow. One when an objective really moved, not per step. Or propose a change to the list (action propose): the user sees a card and applies it or not. This tool doesn't edit the list, change a status or mark anything done, and it approves nothing; the user edits the list with /objectives. Asked to change it, propose it or say so, instead of saying you changed it.",
490
490
  parameters: {
491
491
  type: "object",
492
492
  properties: {
@@ -506,6 +506,10 @@ module Samagotchi
506
506
  type: "string",
507
507
  description: "Optional, a move's: what shows it (a commit, a test count, a file)"
508
508
  },
509
+ state: {
510
+ type: "string",
511
+ description: "A move's: progress (default), blocked or done. done is your claim, not a status change"
512
+ },
509
513
  change: {
510
514
  type: "string",
511
515
  description: "A proposal's: add, reword, done or drop"
@@ -397,10 +397,8 @@ module Samagotchi
397
397
  # whether it runs as a turn of its own (the child idle, or its
398
398
  # running turn ended before taking it) or a running turn's drain
399
399
  # merges it (that turn's end is its answer: the drain's merge record,
400
- # or ReplyWait's inference for a 0.156 child, ReplyWait::Poll#
401
- # follow_merge). Only from a worker that names turn_ids; nil
402
- # otherwise: the wait takes the next reply (compat shim merge_inference:
403
- # Compat::SHIMS).
400
+ # ReplyWait::Poll#follow_merge). Only from a worker that names
401
+ # turn_ids; nil otherwise: the wait takes the next reply.
404
402
  # @return [String, nil]
405
403
  def self.follow_up_turn(id, enqueued_id, state_dir:)
406
404
  ReplyWait.turn_ids?(Session.session_dir(id, state_dir: state_dir)) ? enqueued_id : nil
@@ -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.165.0"
4
+ VERSION = "0.167.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) })