samagotchi 0.60.0 → 0.61.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 +41 -1
- data/docs/architecture.md +7 -4
- data/docs/hooks.md +72 -1
- data/docs/internals/engine.md +34 -5
- data/docs/internals/prompt-caching.md +3 -1
- data/docs/plugins.md +7 -3
- data/docs/sessions.md +7 -3
- data/lib/samagotchi/answer_display.rb +4 -3
- data/lib/samagotchi/answer_refs.rb +210 -0
- data/lib/samagotchi/bridge/card_store.rb +6 -1
- data/lib/samagotchi/bundles/check-in/manifest.yml +2 -2
- data/lib/samagotchi/bundles/check-in/plugin.rb +27 -3
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/engine.rb +38 -9
- data/lib/samagotchi/hooks/registry.rb +3 -1
- data/lib/samagotchi/interrupted_turn.rb +39 -0
- data/lib/samagotchi/kernel_loop.rb +6 -4
- data/lib/samagotchi/llm/chat_loop.rb +5 -2
- data/lib/samagotchi/log_subscriber.rb +6 -3
- data/lib/samagotchi/ref.rb +25 -8
- data/lib/samagotchi/reply_wait.rb +6 -2
- data/lib/samagotchi/session.rb +40 -4
- data/lib/samagotchi/session_manager.rb +64 -6
- data/lib/samagotchi/terminal_ui.rb +4 -0
- data/lib/samagotchi/turn_checkpoint.rb +128 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +5 -0
- data/lib/samagotchi/web/public/answer_refs.js +217 -0
- data/lib/samagotchi/web/public/app.js +15 -18
- data/lib/samagotchi/web/public/index.html +5 -3
- data/lib/samagotchi/web/public/ref_menu.js +9 -1
- data/lib/samagotchi/web/public/ref_scan.js +5 -3
- data/lib/samagotchi/web/public/refs.js +28 -6
- data/lib/samagotchi/web/public/stream_handlers.js +5 -3
- data/lib/samagotchi/web/public/turn_view.js +17 -7
- data/lib/samagotchi/worker.rb +168 -21
- data/lib/samagotchi/worker_signals.rb +81 -0
- metadata +6 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Samagotchi
|
|
4
|
+
# TERM, HUP and INT in a worker process: the running turn stops as a Stop
|
|
5
|
+
# does (reason :signal), is saved, and the worker leaves (Worker#run
|
|
6
|
+
# returns :signal). SessionManager.run_session_loop installs the traps in
|
|
7
|
+
# a spawned worker only (WORKER_PROCESS_ENV), never in a process that runs
|
|
8
|
+
# the loop in-process (the specs, which fire #fire directly).
|
|
9
|
+
#
|
|
10
|
+
# A trap handler may take no lock (Mutex#lock raises ThreadError in trap
|
|
11
|
+
# context) and should do no IO: the trap only records the signal and
|
|
12
|
+
# starts a thread, which calls the worker's handler (#on_signal).
|
|
13
|
+
#
|
|
14
|
+
# Ruby's default for these signals raised SignalException in the main
|
|
15
|
+
# thread, mid-turn: the turn skipped every end-of-turn path and nothing of
|
|
16
|
+
# it reached the session file.
|
|
17
|
+
class WorkerSignals
|
|
18
|
+
SIGNALS = %w[TERM HUP INT].freeze
|
|
19
|
+
|
|
20
|
+
# Nothing trapped and nothing fires: Worker.new's default (specs, and
|
|
21
|
+
# any caller that isn't a spawned worker).
|
|
22
|
+
class None
|
|
23
|
+
def on_signal(&) = nil
|
|
24
|
+
def signal = nil
|
|
25
|
+
def count = 0
|
|
26
|
+
def hard_exit = nil
|
|
27
|
+
def restore! = nil
|
|
28
|
+
end
|
|
29
|
+
NONE = None.new.freeze
|
|
30
|
+
|
|
31
|
+
# @return [String, nil] the first signal received ("TERM"), nil before one
|
|
32
|
+
attr_reader :signal
|
|
33
|
+
|
|
34
|
+
# @param hard_exit [#call] the last resort when the worker hasn't left
|
|
35
|
+
# long after the signal (exit! in a real worker)
|
|
36
|
+
def initialize(hard_exit: -> { Process.exit!(1) })
|
|
37
|
+
@signal = nil
|
|
38
|
+
@count = 0
|
|
39
|
+
@handler = nil
|
|
40
|
+
@hard_exit = hard_exit
|
|
41
|
+
@previous = {}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# How many signals came (a second one skips the grace).
|
|
45
|
+
attr_reader :count
|
|
46
|
+
|
|
47
|
+
# The worker's handler, called on a thread of its own with the signal
|
|
48
|
+
# name and the count, once per signal.
|
|
49
|
+
def on_signal(&handler)
|
|
50
|
+
@handler = handler
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Trap SIGNALS in this process (the previous handlers kept for #restore!).
|
|
54
|
+
# @return [self]
|
|
55
|
+
def install!
|
|
56
|
+
SIGNALS.each { |name| @previous[name] = Signal.trap(name) { fire(name) } }
|
|
57
|
+
self
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# The handlers from before #install!.
|
|
61
|
+
def restore!
|
|
62
|
+
@previous.each { |name, handler| Signal.trap(name, handler || "DEFAULT") }
|
|
63
|
+
@previous.clear
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# What a trap does (and what specs call): record +name+ and run the
|
|
67
|
+
# handler on its own thread. Safe in trap context: no lock, no IO.
|
|
68
|
+
# @return [Thread, nil] the handler's thread
|
|
69
|
+
def fire(name)
|
|
70
|
+
@signal ||= name
|
|
71
|
+
@count += 1
|
|
72
|
+
handler = @handler
|
|
73
|
+
count = @count
|
|
74
|
+
return nil unless handler
|
|
75
|
+
|
|
76
|
+
Thread.new { handler.call(name, count) }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def hard_exit = @hard_exit.call
|
|
80
|
+
end
|
|
81
|
+
end
|
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.
|
|
4
|
+
version: 0.61.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dedov
|
|
@@ -150,6 +150,7 @@ files:
|
|
|
150
150
|
- lib/samagotchi/analytics_file.rb
|
|
151
151
|
- lib/samagotchi/answer_command.rb
|
|
152
152
|
- lib/samagotchi/answer_display.rb
|
|
153
|
+
- lib/samagotchi/answer_refs.rb
|
|
153
154
|
- lib/samagotchi/answer_tail.rb
|
|
154
155
|
- lib/samagotchi/archive_store.rb
|
|
155
156
|
- lib/samagotchi/atomic_file.rb
|
|
@@ -308,6 +309,7 @@ files:
|
|
|
308
309
|
- lib/samagotchi/image_store.rb
|
|
309
310
|
- lib/samagotchi/installed_gem.rb
|
|
310
311
|
- lib/samagotchi/installed_versions.rb
|
|
312
|
+
- lib/samagotchi/interrupted_turn.rb
|
|
311
313
|
- lib/samagotchi/iteration_limit.rb
|
|
312
314
|
- lib/samagotchi/kernel_loop.rb
|
|
313
315
|
- lib/samagotchi/last_turn.rb
|
|
@@ -507,6 +509,7 @@ files:
|
|
|
507
509
|
- lib/samagotchi/tools/tool_path.rb
|
|
508
510
|
- lib/samagotchi/tools/web_fetch.rb
|
|
509
511
|
- lib/samagotchi/tools/write.rb
|
|
512
|
+
- lib/samagotchi/turn_checkpoint.rb
|
|
510
513
|
- lib/samagotchi/turn_flow.rb
|
|
511
514
|
- lib/samagotchi/turn_note.rb
|
|
512
515
|
- lib/samagotchi/turn_state.rb
|
|
@@ -530,6 +533,7 @@ files:
|
|
|
530
533
|
- lib/samagotchi/web/public/annotate_bar.js
|
|
531
534
|
- lib/samagotchi/web/public/annotate_presets.js
|
|
532
535
|
- lib/samagotchi/web/public/annotations.js
|
|
536
|
+
- lib/samagotchi/web/public/answer_refs.js
|
|
533
537
|
- lib/samagotchi/web/public/app.js
|
|
534
538
|
- lib/samagotchi/web/public/card.js
|
|
535
539
|
- lib/samagotchi/web/public/chains.js
|
|
@@ -604,6 +608,7 @@ files:
|
|
|
604
608
|
- lib/samagotchi/worker_idle_exit.rb
|
|
605
609
|
- lib/samagotchi/worker_inbound.rb
|
|
606
610
|
- lib/samagotchi/worker_sidecar.rb
|
|
611
|
+
- lib/samagotchi/worker_signals.rb
|
|
607
612
|
- lib/samagotchi/worker_wakes.rb
|
|
608
613
|
- lib/samagotchi/yaml_lines.rb
|
|
609
614
|
homepage: https://github.com/dm1try/samagotchi
|