samagotchi 0.182.0 → 0.184.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +107 -1
- data/bin/chi +3 -1
- data/docs/architecture.md +22 -11
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +103 -4
- data/docs/cli.md +28 -6
- data/docs/configuration.md +4 -2
- data/docs/guardrails.md +16 -1
- data/docs/internals/block-renderers.md +58 -3
- data/docs/internals/bridge.md +14 -6
- data/docs/internals/bundles.md +26 -5
- data/docs/internals/engine.md +20 -9
- data/docs/internals/participants.md +1 -1
- data/docs/internals/prompt-caching.md +8 -1
- data/docs/internals/remote-sessions.md +40 -5
- data/docs/internals/web-frontend.md +96 -31
- data/docs/internals/web-push.md +11 -0
- data/docs/internals/working-set.md +239 -7
- data/docs/mcp-server.md +84 -0
- data/docs/memory.md +2 -1
- data/docs/plugins.md +309 -22
- data/docs/scheduling.md +14 -0
- data/docs/sessions.md +4 -4
- data/docs/sub-agent.md +9 -0
- data/docs/testing.md +3 -1
- data/docs/thin-clients.md +165 -0
- data/lib/samagotchi/bridge/pending_card.rb +4 -3
- data/lib/samagotchi/bridge/sse_writer.rb +16 -15
- data/lib/samagotchi/bridge.rb +59 -68
- data/lib/samagotchi/bridge_client.rb +12 -4
- data/lib/samagotchi/bundle_command/api_calls.rb +1 -1
- data/lib/samagotchi/bundle_command/check.rb +55 -20
- data/lib/samagotchi/bundle_command.rb +50 -21
- data/lib/samagotchi/bundle_manifest.rb +105 -4
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/mcp/client.rb +260 -0
- data/lib/samagotchi/bundles/mcp/content.rb +107 -0
- data/lib/samagotchi/bundles/mcp/http_client.rb +432 -0
- data/lib/samagotchi/bundles/mcp/manifest.yml +13 -5
- data/lib/samagotchi/bundles/mcp/oauth.rb +814 -0
- data/lib/samagotchi/bundles/mcp/plugin.rb +556 -574
- data/lib/samagotchi/bundles/mcp/tools.rb +232 -0
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +10 -2
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +7 -2
- data/lib/samagotchi/cli/parent_wait.rb +5 -3
- data/lib/samagotchi/command_intake.rb +7 -0
- data/lib/samagotchi/commands/registry.rb +8 -3
- data/lib/samagotchi/continue_offer.rb +24 -15
- data/lib/samagotchi/engine/block_fix.rb +4 -4
- data/lib/samagotchi/engine/cards.rb +14 -5
- data/lib/samagotchi/engine/events.rb +10 -15
- data/lib/samagotchi/engine/models.rb +1 -1
- data/lib/samagotchi/engine/plugins.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -1
- data/lib/samagotchi/engine/session.rb +14 -6
- data/lib/samagotchi/engine/side_requests.rb +1 -1
- data/lib/samagotchi/engine/sign_in.rb +142 -0
- data/lib/samagotchi/engine/turn_end.rb +3 -3
- data/lib/samagotchi/engine/turn_helpers.rb +4 -3
- data/lib/samagotchi/engine.rb +43 -27
- data/lib/samagotchi/engine_snapshots.rb +1 -1
- data/lib/samagotchi/guardrail_wiring.rb +3 -1
- data/lib/samagotchi/guardrails/protected_paths.rb +51 -2
- data/lib/samagotchi/guardrails/verdict.rb +3 -2
- data/lib/samagotchi/hold_stop.rb +4 -4
- data/lib/samagotchi/idle_recap.rb +19 -11
- data/lib/samagotchi/idle_reminders.rb +7 -5
- data/lib/samagotchi/idle_scheduler.rb +7 -10
- data/lib/samagotchi/installed_bundles/dir.rb +37 -0
- data/lib/samagotchi/installed_bundles/manifest.rb +7 -1
- data/lib/samagotchi/installed_bundles/plugin_ref.rb +9 -5
- data/lib/samagotchi/installed_bundles/record.rb +3 -2
- data/lib/samagotchi/installed_bundles/standing.rb +3 -1
- data/lib/samagotchi/llm/http.rb +96 -5
- data/lib/samagotchi/mcp_command.rb +110 -0
- data/lib/samagotchi/mcp_server/http.rb +112 -0
- data/lib/samagotchi/mcp_server/protocol.rb +263 -0
- data/lib/samagotchi/mcp_server/stdio.rb +93 -0
- data/lib/samagotchi/mcp_server/text.rb +155 -0
- data/lib/samagotchi/mcp_server/tools.rb +246 -0
- data/lib/samagotchi/memory_bundle/asset_installer.rb +40 -12
- data/lib/samagotchi/memory_bundle/builder.rb +20 -2
- data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
- data/lib/samagotchi/memory_bundle/installer.rb +16 -3
- data/lib/samagotchi/memory_bundle/provenance.rb +18 -1
- data/lib/samagotchi/memory_bundle/shas.rb +6 -4
- data/lib/samagotchi/memory_bundle/shipped_update.rb +7 -3
- data/lib/samagotchi/memory_bundle/status.rb +15 -6
- data/lib/samagotchi/memory_bundle/uninstaller.rb +9 -4
- data/lib/samagotchi/model_notes.rb +34 -12
- data/lib/samagotchi/plugin/api.rb +6 -1
- data/lib/samagotchi/plugin/card.rb +36 -11
- data/lib/samagotchi/plugin/context.rb +63 -6
- data/lib/samagotchi/plugin/http.rb +40 -15
- data/lib/samagotchi/plugin/http_errors.rb +15 -0
- data/lib/samagotchi/plugin/http_stream.rb +86 -0
- data/lib/samagotchi/plugin/http_transport.rb +58 -16
- data/lib/samagotchi/plugin/loader.rb +18 -11
- data/lib/samagotchi/plugin/secrets.rb +266 -0
- data/lib/samagotchi/plugin/sign_in.rb +392 -0
- data/lib/samagotchi/plugin/sse_reader.rb +103 -0
- data/lib/samagotchi/prompt_files.rb +11 -4
- data/lib/samagotchi/prompt_layout.rb +88 -0
- data/lib/samagotchi/prompt_part.rb +82 -20
- data/lib/samagotchi/queued_command.rb +28 -4
- data/lib/samagotchi/recap_setup.rb +13 -4
- data/lib/samagotchi/ref.rb +3 -2
- data/lib/samagotchi/relay_verifier.rb +8 -7
- data/lib/samagotchi/relay_watcher.rb +4 -4
- data/lib/samagotchi/reply_wait.rb +6 -3
- data/lib/samagotchi/run_options.rb +2 -1
- data/lib/samagotchi/schedule_command.rb +18 -4
- data/lib/samagotchi/schedules.rb +40 -8
- data/lib/samagotchi/send_command.rb +54 -41
- data/lib/samagotchi/session_access/ask.rb +285 -0
- data/lib/samagotchi/session_access/contract.rb +5 -0
- data/lib/samagotchi/session_access/exchange/token.rb +101 -0
- data/lib/samagotchi/session_access/exchange.rb +176 -0
- data/lib/samagotchi/session_access/local.rb +34 -6
- data/lib/samagotchi/session_access/remote.rb +4 -1
- data/lib/samagotchi/session_command_catalog.rb +10 -0
- data/lib/samagotchi/session_commands.rb +17 -0
- data/lib/samagotchi/session_config.rb +4 -4
- data/lib/samagotchi/session_inbox.rb +15 -0
- data/lib/samagotchi/session_manager/delivery.rb +8 -4
- data/lib/samagotchi/session_observer.rb +27 -0
- data/lib/samagotchi/steer_cut.rb +4 -3
- data/lib/samagotchi/system_prompt.rb +196 -161
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +4 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -0
- data/lib/samagotchi/testing/boundary.rb +4 -0
- data/lib/samagotchi/testing/bundle.rb +48 -2
- data/lib/samagotchi/testing/fake_http.rb +60 -15
- data/lib/samagotchi/testing/host.rb +4 -1
- data/lib/samagotchi/testing/recorder.rb +45 -5
- data/lib/samagotchi/tools/memory.rb +11 -3
- data/lib/samagotchi/tools/tool_index.rb +14 -3
- data/lib/samagotchi/turn_stages/warmup.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +9 -8
- data/lib/samagotchi/web/ask_routes.rb +362 -0
- data/lib/samagotchi/web/mcp_route.rb +91 -0
- data/lib/samagotchi/web/public/app.js +2 -3
- data/lib/samagotchi/web/public/block_frame.js +72 -11
- data/lib/samagotchi/web/public/block_host.js +44 -8
- data/lib/samagotchi/web/public/block_regions.js +126 -0
- data/lib/samagotchi/web/public/card.js +22 -9
- data/lib/samagotchi/web/public/card_actions.js +21 -0
- data/lib/samagotchi/web/public/card_kinds.js +1 -1
- data/lib/samagotchi/web/public/card_registry.js +3 -2
- data/lib/samagotchi/web/public/data.js +15 -12
- data/lib/samagotchi/web/public/delete_sheet.js +231 -169
- data/lib/samagotchi/web/public/diagram_wiring.js +28 -0
- data/lib/samagotchi/web/public/format.js +3 -0
- data/lib/samagotchi/web/public/index.html +52 -7
- data/lib/samagotchi/web/public/more_sheet.js +6 -4
- data/lib/samagotchi/web/public/picture_regions.js +243 -0
- data/lib/samagotchi/web/public/picture_viewer.js +113 -12
- data/lib/samagotchi/web/public/refs.js +5 -3
- data/lib/samagotchi/web/public/region_hit.js +144 -0
- data/lib/samagotchi/web/public/removal_sheet_model.js +274 -0
- data/lib/samagotchi/web/public/running_tasks.js +3 -17
- data/lib/samagotchi/web/public/session_actions.js +96 -100
- data/lib/samagotchi/web/public/working_set_view.js +167 -21
- data/lib/samagotchi/web/public/ws_part_peek.js +277 -0
- data/lib/samagotchi/web/public/ws_peek.js +3 -1
- data/lib/samagotchi/web/public/ws_preview.css +30 -0
- data/lib/samagotchi/web/public/ws_reader.js +7 -3
- data/lib/samagotchi/web/public/ws_sections.js +37 -7
- data/lib/samagotchi/web/push/notifier.rb +33 -6
- data/lib/samagotchi/web/server.rb +1 -1
- data/lib/samagotchi/web/session_access_routes.rb +14 -11
- data/lib/samagotchi/web/session_control.rb +31 -9
- data/lib/samagotchi/web/session_create.rb +2 -2
- data/lib/samagotchi/web/session_hub.rb +26 -4
- data/lib/samagotchi/web/working_set_routes.rb +93 -5
- data/lib/samagotchi/worker/child_side.rb +3 -2
- data/lib/samagotchi/worker/command_queue.rb +13 -13
- data/lib/samagotchi/worker/leave.rb +3 -3
- data/lib/samagotchi/worker/scratch.rb +6 -6
- data/lib/samagotchi/worker/signal_grace.rb +6 -5
- data/lib/samagotchi/worker/startup.rb +3 -3
- data/lib/samagotchi/worker/wake_turns.rb +4 -4
- data/lib/samagotchi/worker.rb +32 -21
- data/lib/samagotchi/worker_exit_claim.rb +1 -1
- data/lib/samagotchi/worker_idle_exit.rb +18 -9
- data/lib/samagotchi/worker_inbound.rb +12 -7
- data/lib/samagotchi/worker_link.rb +2 -2
- data/lib/samagotchi/worker_participant_gate.rb +9 -7
- data/lib/samagotchi/worker_task_wakes.rb +7 -5
- data/lib/samagotchi/working_set.rb +162 -90
- data/lib/samagotchi/working_set_locator.rb +221 -0
- data/lib/samagotchi/working_set_own_changes.rb +221 -0
- data/lib/samagotchi/working_set_part.rb +281 -0
- metadata +36 -1
|
@@ -39,6 +39,7 @@ module Samagotchi
|
|
|
39
39
|
OBJECTIVES_COMMAND = "/objectives"
|
|
40
40
|
ROLLBACK_COMMAND = "!rollback"
|
|
41
41
|
CONTINUE_COMMAND = TurnFlow::CONTINUE_COMMAND
|
|
42
|
+
CALLBACK_COMMAND = "/callback"
|
|
42
43
|
SHELL_BANG_PREFIX = "!"
|
|
43
44
|
# /exit --delete: delete the session on the way out.
|
|
44
45
|
EXIT_DELETE_FLAG = "--delete"
|
|
@@ -102,6 +103,15 @@ module Samagotchi
|
|
|
102
103
|
registry.register(OBJECTIVES_COMMAND, "show or edit what this session is to achieve (set A | B, add TEXT, edit ID TEXT, done ID…, drop ID…, undo ID…, check ID, track)",
|
|
103
104
|
id: :objectives, anytime: true) { |text| objectives(text) }
|
|
104
105
|
registry.register(HELP_COMMAND, "list the commands, the bundles' too", anytime: true) { |_text| reply(help_listing) }
|
|
106
|
+
# A sign-in's ending pasted from a browser elsewhere (ctx.sign_in): at
|
|
107
|
+
# once, a turn running or not. Its address holds a one-time code: kept
|
|
108
|
+
# out of every event, log and echo (private_args, QueuedCommand).
|
|
109
|
+
# #run passes who sent it (as_parent:): a parent agent may not. Its
|
|
110
|
+
# match takes any line after the word, more lines too (the handler
|
|
111
|
+
# refuses those), so the address never goes to the model as a message.
|
|
112
|
+
registry.register(CALLBACK_COMMAND, "finish a waiting sign-in with the address the browser ended on (/callback ADDRESS)",
|
|
113
|
+
anytime: true, private_args: true,
|
|
114
|
+
match: ->(text) { text.match?(%r{\A/callback(?:\s|\z)}) }) { |text| callback(text) }
|
|
105
115
|
registry.register("/stats", "show the session's stats", local: true)
|
|
106
116
|
# /recap with words (on|off|default, or a slip: the usage) runs here:
|
|
107
117
|
# it toggles the idle job only, so it doesn't wait for a running turn.
|
|
@@ -189,6 +189,7 @@ module Samagotchi
|
|
|
189
189
|
# an anytime command runs on another thread against this instance.
|
|
190
190
|
return continue_command(text, as_parent: as_parent) if entry.id == :continue
|
|
191
191
|
return parent_answers(text, user_ui: user_ui) if entry.id == :parent_answers
|
|
192
|
+
return callback(text, as_parent: as_parent) if entry.id == :callback
|
|
192
193
|
|
|
193
194
|
instance_exec(text, &entry.handler)
|
|
194
195
|
end
|
|
@@ -545,6 +546,22 @@ module Samagotchi
|
|
|
545
546
|
reply(output, status: status, changed: changed ? [:title] : [])
|
|
546
547
|
end
|
|
547
548
|
|
|
549
|
+
# /callback ADDRESS: the waiting sign-in it belongs to takes the
|
|
550
|
+
# address's query (Engine#sign_in_callback). A parent agent's chi answer
|
|
551
|
+
# doesn't finish the owner's sign-in. The answer never repeats the
|
|
552
|
+
# address.
|
|
553
|
+
def callback(text, as_parent: false)
|
|
554
|
+
return reply("a parent agent doesn't finish this session's sign-in", status: :error) if as_parent
|
|
555
|
+
|
|
556
|
+
address = text.delete_prefix(CALLBACK_COMMAND).strip
|
|
557
|
+
if address.empty? || address.match?(/\s/)
|
|
558
|
+
return reply("usage: /callback ADDRESS, on one line (the address the browser ended on)", status: :error)
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
settled, line = @engine.sign_in_callback(address)
|
|
562
|
+
reply(line, status: settled ? :ok : :error)
|
|
563
|
+
end
|
|
564
|
+
|
|
548
565
|
# /objectives (ObjectivesCommand): nothing to save, an edit is a note file.
|
|
549
566
|
def objectives(text)
|
|
550
567
|
output, status = ObjectivesCommand.new(engine: @engine).run(text.delete_prefix(OBJECTIVES_COMMAND))
|
|
@@ -293,7 +293,7 @@ module Samagotchi
|
|
|
293
293
|
# The installed bundles a session may set settings of: a record that
|
|
294
294
|
# doesn't read is left out, and so is one this chi is too old for
|
|
295
295
|
# (InstalledBundles::Standing: requires_chi, plugin or not) or whose
|
|
296
|
-
# plugin doesn't load (Dir#
|
|
296
|
+
# plugin doesn't load (Dir#plugin_refusal: its files, their sha256),
|
|
297
297
|
# with a note saying why. A record with no
|
|
298
298
|
# session_settings whose shipped bundle lists some (installed before
|
|
299
299
|
# them) gets a note on refreshing it.
|
|
@@ -385,13 +385,13 @@ module Samagotchi
|
|
|
385
385
|
end
|
|
386
386
|
|
|
387
387
|
# Why a usable +standing+'s plugin doesn't load, as the plugin loader
|
|
388
|
-
# would refuse it (Dir#
|
|
389
|
-
# none.
|
|
388
|
+
# would refuse it (Dir#plugin_refusal: the file, its parts), nil when it
|
|
389
|
+
# does or it has none.
|
|
390
390
|
def unloadable(dir, standing)
|
|
391
391
|
plugin = standing.record.plugin
|
|
392
392
|
return nil unless plugin
|
|
393
393
|
|
|
394
|
-
InstalledBundles::Dir.new(name: standing.name, dir: dir).
|
|
394
|
+
InstalledBundles::Dir.new(name: standing.name, dir: dir).plugin_refusal(standing.record)&.text
|
|
395
395
|
end
|
|
396
396
|
|
|
397
397
|
# Whether chi ships a bundle +name+ whose manifest lists session_settings.
|
|
@@ -4,6 +4,7 @@ require "fileutils"
|
|
|
4
4
|
require "json"
|
|
5
5
|
require "time"
|
|
6
6
|
require "securerandom"
|
|
7
|
+
require "digest"
|
|
7
8
|
require_relative "atomic_file"
|
|
8
9
|
require_relative "context_note"
|
|
9
10
|
require_relative "delivery"
|
|
@@ -256,6 +257,20 @@ module Samagotchi
|
|
|
256
257
|
|
|
257
258
|
def self.new_enqueued_id = SecureRandom.uuid
|
|
258
259
|
|
|
260
|
+
# The enqueued id a client's own key names (an ask's request_id): the
|
|
261
|
+
# same key always gives the same id, shaped as a UUID v5 (SHA-256's
|
|
262
|
+
# first 128 bits, the version and variant bits set), so a Bridge keeps
|
|
263
|
+
# it (ENQUEUED_ID_UUID) and dedupes a retry.
|
|
264
|
+
# @param key [String]
|
|
265
|
+
# @return [String]
|
|
266
|
+
def self.enqueued_id_for(key)
|
|
267
|
+
bytes = Digest::SHA256.digest(key.to_s).bytes.first(16)
|
|
268
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x50
|
|
269
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
|
270
|
+
hex = bytes.pack("C*").unpack1("H*")
|
|
271
|
+
"#{hex[0, 8]}-#{hex[8, 4]}-#{hex[12, 4]}-#{hex[16, 4]}-#{hex[20, 12]}"
|
|
272
|
+
end
|
|
273
|
+
|
|
259
274
|
def self.valid_enqueued_id?(id) = id.is_a?(String) && ENQUEUED_ID_UUID.match?(id)
|
|
260
275
|
|
|
261
276
|
def self.output_name(timestamp, enqueued_id)
|
|
@@ -176,6 +176,9 @@ module Samagotchi
|
|
|
176
176
|
# stand-in (the web's specs); #session_owner is optional
|
|
177
177
|
# @param bridge [#call, nil] returns the BridgeClient or nil; defaults to
|
|
178
178
|
# the session's sidecar, waiting TURN_BRIDGE_WAIT for a new worker's
|
|
179
|
+
# @param enqueued_id [String, nil] the turn's id, the caller's (an ask's
|
|
180
|
+
# request_id: SessionInbox.enqueued_id_for), so a retry with the same
|
|
181
|
+
# one is the Bridge's duplicate and the file's one claim; nil mints one
|
|
179
182
|
# @return [DeliverResult] :accepted (via the Bridge or a file),
|
|
180
183
|
# :refused when the Bridge refused the request (any 4xx with an
|
|
181
184
|
# error: bad images, a delivery it doesn't run) or a queue would reach
|
|
@@ -186,13 +189,14 @@ module Samagotchi
|
|
|
186
189
|
# @raise [ArgumentError] no such session, or no client_id
|
|
187
190
|
def deliver_turn(session_id, prompt:, client_id:, images: [], delivery: nil, no_interrupt: false,
|
|
188
191
|
author: nil, pending_limit: nil, anchors: nil, follow: false, state_dir: nil, manager: self,
|
|
189
|
-
bridge: nil)
|
|
192
|
+
bridge: nil, enqueued_id: nil)
|
|
190
193
|
raise ArgumentError, "deliver_turn needs the sender's client_id" if client_id.to_s.empty?
|
|
191
194
|
|
|
192
195
|
follow_guard(session_id, state_dir, follow) do
|
|
193
196
|
deliver_turn_now(session_id, prompt: prompt, client_id: client_id, images: images, delivery: delivery,
|
|
194
197
|
no_interrupt: no_interrupt, author: author, pending_limit: pending_limit,
|
|
195
|
-
anchors: anchors, state_dir: state_dir, manager: manager, bridge: bridge
|
|
198
|
+
anchors: anchors, state_dir: state_dir, manager: manager, bridge: bridge,
|
|
199
|
+
enqueued_id: enqueued_id)
|
|
196
200
|
end
|
|
197
201
|
end
|
|
198
202
|
|
|
@@ -222,7 +226,7 @@ module Samagotchi
|
|
|
222
226
|
end
|
|
223
227
|
|
|
224
228
|
private def deliver_turn_now(session_id, prompt:, client_id:, images:, delivery:, no_interrupt:, author:,
|
|
225
|
-
pending_limit:, anchors:, state_dir:, manager:, bridge:)
|
|
229
|
+
pending_limit:, anchors:, state_dir:, manager:, bridge:, enqueued_id: nil)
|
|
226
230
|
anchors = TurnAnchors.from(anchors)
|
|
227
231
|
session_dir = Session.session_dir(session_id, state_dir: state_dir || Session.default_state_dir)
|
|
228
232
|
bridge ||= lambda do
|
|
@@ -234,7 +238,7 @@ module Samagotchi
|
|
|
234
238
|
refused = start_for_send(manager, session_id, state_dir, client_id, before: true)
|
|
235
239
|
return refused if refused
|
|
236
240
|
|
|
237
|
-
enqueued_id
|
|
241
|
+
enqueued_id ||= SessionInbox.new_enqueued_id
|
|
238
242
|
if (client = bridge.call)
|
|
239
243
|
if (missing = anchors.present.find { |anchor| !worker_has?(client, anchor.class::FEATURE) })
|
|
240
244
|
return DeliverResult.new(status: :refused, code: 409, ack: missing.class::UNAVAILABLE)
|
|
@@ -26,6 +26,15 @@ module Samagotchi
|
|
|
26
26
|
# counted (Engine#note_side_usage): `kind:` and `side:`, the session's
|
|
27
27
|
# whole side block (SessionMetrics#add_side), in fold order.
|
|
28
28
|
class SessionObserver
|
|
29
|
+
# Event types #announce accepts: facts about the session's input queue,
|
|
30
|
+
# a failed turn's prompt handed back and the continue offer, which live
|
|
31
|
+
# UIs need in the event log, emitted outside any turn's stream; a
|
|
32
|
+
# Verify fresh child's verdict landing on its card (:verdict_recorded).
|
|
33
|
+
ANNOUNCEABLE_EVENTS = %i[turn_enqueued turn_dequeued input_merged prompt_restored continue_offered continue_resolved
|
|
34
|
+
command_queued command_ran context_added card hook_notice guardrail_warning
|
|
35
|
+
plugin_init_started plugin_init_finished working_set_updated participants_changed
|
|
36
|
+
verdict_recorded objectives_updated].freeze
|
|
37
|
+
|
|
29
38
|
# Handle returned by #subscribe. Holds the observer reference and carries
|
|
30
39
|
# #unsubscribe so a caller can deregister without keeping the registry.
|
|
31
40
|
class SubscribedObserver
|
|
@@ -106,6 +115,19 @@ module Samagotchi
|
|
|
106
115
|
end
|
|
107
116
|
end
|
|
108
117
|
|
|
118
|
+
# Put a transport-level event into the ordered event log (#notify), after
|
|
119
|
+
# checking its type. Unlike turn events it reaches only persistent
|
|
120
|
+
# observers (no turn sink, no memory capture).
|
|
121
|
+
# @param event [Hash] with :type in ANNOUNCEABLE_EVENTS
|
|
122
|
+
# @raise [ArgumentError] for any other type (before #notify, outside the lock)
|
|
123
|
+
def announce(event)
|
|
124
|
+
unless ANNOUNCEABLE_EVENTS.include?(event[:type])
|
|
125
|
+
raise ArgumentError, "cannot announce #{event[:type].inspect} (allowed: #{ANNOUNCEABLE_EVENTS.join(", ")})"
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
notify(event)
|
|
129
|
+
end
|
|
130
|
+
|
|
109
131
|
# @return [Integer] total events emitted so far (Engine-local sequence)
|
|
110
132
|
def event_count
|
|
111
133
|
@mutex.synchronize { @seq }
|
|
@@ -117,5 +139,10 @@ module Samagotchi
|
|
|
117
139
|
def synchronize(&)
|
|
118
140
|
@mutex.synchronize(&)
|
|
119
141
|
end
|
|
142
|
+
|
|
143
|
+
# @return [Boolean] whether the calling thread holds the event lock
|
|
144
|
+
def held?
|
|
145
|
+
@mutex.mon_owned?
|
|
146
|
+
end
|
|
120
147
|
end
|
|
121
148
|
end
|
data/lib/samagotchi/steer_cut.rb
CHANGED
|
@@ -11,9 +11,10 @@ module Samagotchi
|
|
|
11
11
|
# A message for the running turn cutting the generation it came during:
|
|
12
12
|
# what the generation streams (GenerationPhase, fed by #observe from the
|
|
13
13
|
# turn's stream) and a message that came too early to cut (WaitingSteer).
|
|
14
|
-
# The Engine's
|
|
15
|
-
#
|
|
16
|
-
# turn
|
|
14
|
+
# The Engine's one, which the Worker hands the Bridge (Engine#steer_cut):
|
|
15
|
+
# the Bridge calls #cut_for_steer, #input_epoch and #generation_snapshot,
|
|
16
|
+
# the turn thread feeds #observe and #delivered!, and the turn's end calls
|
|
17
|
+
# #finished!. Callable from any thread: GenerationPhase
|
|
17
18
|
# and WaitingSteer hold their own locks.
|
|
18
19
|
class SteerCut
|
|
19
20
|
# A chunk's thinking and text. A chunk without the lanes (no loop of
|