samagotchi 0.190.1 → 0.192.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 +61 -1
- data/docs/architecture.md +13 -11
- data/docs/bundles.md +1 -1
- data/docs/cli.md +17 -6
- data/docs/configuration.md +6 -1
- data/docs/context.md +8 -1
- data/docs/internals/attached-context.md +3 -1
- data/docs/internals/inline-widgets.md +2 -1
- data/docs/internals/participants.md +1 -5
- data/docs/internals/peers.md +15 -3
- data/docs/internals/remote-sessions.md +5 -2
- data/docs/internals/session-lifecycle.md +233 -18
- data/docs/internals/web-frontend.md +107 -9
- data/docs/peers.md +3 -1
- data/docs/plugins.md +2 -1
- data/docs/scheduling.md +31 -7
- data/docs/sessions.md +12 -12
- data/docs/sub-agent.md +1 -1
- data/docs/testing.md +1 -2
- data/docs/thin-clients.md +98 -12
- data/lib/samagotchi/bridge.rb +3 -4
- data/lib/samagotchi/bundles/mcp/manifest.yml +4 -2
- data/lib/samagotchi/bundles/mcp/plugin.rb +7 -398
- data/lib/samagotchi/bundles/mcp/server_config.rb +158 -0
- data/lib/samagotchi/bundles/mcp/sign_in.rb +261 -0
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +2 -19
- data/lib/samagotchi/compat.rb +1 -7
- data/lib/samagotchi/config.rb +3 -0
- data/lib/samagotchi/context_command.rb +5 -1
- data/lib/samagotchi/context_sources.rb +28 -0
- data/lib/samagotchi/continue_intent.rb +23 -43
- data/lib/samagotchi/delivery.rb +1 -5
- data/lib/samagotchi/hold_stop.rb +5 -2
- data/lib/samagotchi/participants.rb +13 -5
- data/lib/samagotchi/peer_say.rb +29 -14
- data/lib/samagotchi/plugin/sessions.rb +9 -5
- data/lib/samagotchi/schedule_command.rb +6 -1
- data/lib/samagotchi/schedules/prune_part.rb +162 -41
- data/lib/samagotchi/schedules.rb +32 -15
- data/lib/samagotchi/send_command.rb +6 -6
- data/lib/samagotchi/session.rb +7 -0
- data/lib/samagotchi/session_access/ask.rb +9 -3
- data/lib/samagotchi/session_access/exchange.rb +6 -2
- data/lib/samagotchi/session_access/local.rb +103 -32
- data/lib/samagotchi/session_access/remote.rb +10 -9
- data/lib/samagotchi/session_access/remote_peers.rb +2 -2
- data/lib/samagotchi/session_access.rb +17 -7
- data/lib/samagotchi/session_chain/delete.rb +100 -47
- data/lib/samagotchi/session_chain/delete_preview.rb +9 -5
- data/lib/samagotchi/session_chain/successor.rb +78 -0
- data/lib/samagotchi/session_continue.rb +112 -42
- data/lib/samagotchi/session_inbox.rb +1 -1
- data/lib/samagotchi/session_inbox_delivery.rb +111 -25
- data/lib/samagotchi/session_lifecycle/allowed.rb +20 -1
- data/lib/samagotchi/session_lifecycle/reading.rb +9 -3
- data/lib/samagotchi/session_lifecycle.rb +17 -2
- data/lib/samagotchi/session_manager/delivery.rb +61 -29
- data/lib/samagotchi/session_manager/emptiness.rb +5 -2
- data/lib/samagotchi/session_manager/lifecycle.rb +68 -19
- data/lib/samagotchi/session_manager/listing.rb +2 -1
- data/lib/samagotchi/session_manager/removal.rb +67 -13
- data/lib/samagotchi/session_manager/spawn.rb +16 -9
- data/lib/samagotchi/session_manager.rb +4 -0
- data/lib/samagotchi/session_retention.rb +28 -7
- data/lib/samagotchi/session_row.rb +2 -0
- data/lib/samagotchi/session_transition.rb +361 -0
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/tools/cancel_schedule.rb +10 -6
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +13 -3
- data/lib/samagotchi/web/ask_create.rb +138 -0
- data/lib/samagotchi/web/ask_routes.rb +56 -9
- data/lib/samagotchi/web/last_ask.rb +78 -0
- data/lib/samagotchi/web/peer_routes.rb +5 -2
- data/lib/samagotchi/web/public/answer_refs.js +3 -9
- data/lib/samagotchi/web/public/answer_write.js +28 -0
- data/lib/samagotchi/web/public/app.js +72 -96
- data/lib/samagotchi/web/public/block_fix.js +30 -12
- data/lib/samagotchi/web/public/chains.js +3 -1
- data/lib/samagotchi/web/public/command_list.js +5 -3
- data/lib/samagotchi/web/public/composer.js +9 -6
- data/lib/samagotchi/web/public/composer_mount.js +18 -11
- data/lib/samagotchi/web/public/draft_keys.js +10 -0
- data/lib/samagotchi/web/public/drafts.js +278 -0
- data/lib/samagotchi/web/public/owner_claim.js +7 -12
- data/lib/samagotchi/web/public/prompt_history.js +6 -0
- data/lib/samagotchi/web/public/send_turn.js +51 -20
- data/lib/samagotchi/web/public/session_actions.js +80 -16
- data/lib/samagotchi/web/public/session_prefs.js +9 -3
- data/lib/samagotchi/web/public/session_view.js +7 -2
- data/lib/samagotchi/web/public/turn_events.js +0 -2
- data/lib/samagotchi/web/public/unqueue.js +22 -9
- data/lib/samagotchi/web/public/viewer_self.js +1 -6
- data/lib/samagotchi/web/public/views.js +12 -1
- data/lib/samagotchi/web/session_access_routes.rb +11 -5
- data/lib/samagotchi/web/session_control.rb +8 -1
- data/lib/samagotchi/web/session_create.rb +51 -34
- data/lib/samagotchi/web/session_hub.rb +52 -36
- data/lib/samagotchi/web/session_summary.rb +45 -7
- data/lib/samagotchi/web/start_dir.rb +6 -4
- data/lib/samagotchi/worker_boot.rb +28 -6
- data/lib/samagotchi/worker_presence.rb +22 -6
- metadata +10 -1
|
@@ -147,8 +147,7 @@ module Samagotchi
|
|
|
147
147
|
thread = @thread
|
|
148
148
|
@thread = nil
|
|
149
149
|
thread&.join(@scan_interval + 1.0)
|
|
150
|
-
|
|
151
|
-
schedule_thread&.join(SCHEDULE_TICK_STOP_WAIT)
|
|
150
|
+
drain_schedule_tick(timeout: SCHEDULE_TICK_STOP_WAIT)
|
|
152
151
|
sweep_thread = @monitor.synchronize { @sweep_thread }
|
|
153
152
|
sweep_thread&.join(SWEEP_STOP_WAIT)
|
|
154
153
|
nil
|
|
@@ -343,33 +342,6 @@ module Samagotchi
|
|
|
343
342
|
@monitor.synchronize { !@subscribers.delete(handle).nil? }
|
|
344
343
|
end
|
|
345
344
|
|
|
346
|
-
private
|
|
347
|
-
|
|
348
|
-
def run_loop
|
|
349
|
-
until @stopped
|
|
350
|
-
begin
|
|
351
|
-
scan
|
|
352
|
-
rescue StandardError => e
|
|
353
|
-
Log.warn(:web, "hub_scan_failed", error: e.class.name, msg: e.message)
|
|
354
|
-
end
|
|
355
|
-
@wakeup.pop(timeout: @scan_interval)
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
def full_probe_due?
|
|
360
|
-
now = @now.call
|
|
361
|
-
return false if @next_full_probe && now < @next_full_probe
|
|
362
|
-
|
|
363
|
-
@next_full_probe = now + @full_probe_interval
|
|
364
|
-
true
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
def sweep
|
|
368
|
-
@manager.retention_sweep_if_due(state_dir: @state_dir)
|
|
369
|
-
rescue StandardError => e
|
|
370
|
-
Log.warn(:web, "retention_sweep_failed", error: e.class.name, msg: e.message)
|
|
371
|
-
end
|
|
372
|
-
|
|
373
345
|
# chi web can be the scheduler when the user opts in (schedule.auto_tick):
|
|
374
346
|
# the same tick cron runs, gated by schedule.tick_interval_minutes and
|
|
375
347
|
# sharing schedules.lock, so cron and the hub never both fire. The scan
|
|
@@ -378,18 +350,20 @@ module Samagotchi
|
|
|
378
350
|
# auto_tick off as well (#claim_disabled_if_due). Only the scan(tick:
|
|
379
351
|
# true) path gets here: server.rb's seeding scan(tick: false) runs before
|
|
380
352
|
# the Notifier subscribes, and a notice claimed then would reach no one.
|
|
353
|
+
# @return [Thread, nil] the Thread it started, or nil when it started none.
|
|
381
354
|
def schedule_tick
|
|
382
355
|
claim_disabled_if_due
|
|
383
|
-
return unless Config.get("schedule.auto_tick")
|
|
356
|
+
return nil unless Config.get("schedule.auto_tick")
|
|
384
357
|
|
|
385
358
|
now = @now.call
|
|
386
359
|
@monitor.synchronize do
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
360
|
+
if @schedule_tick_in_flight || (@next_schedule_tick && now < @next_schedule_tick)
|
|
361
|
+
nil
|
|
362
|
+
else
|
|
363
|
+
@next_schedule_tick = now + (Samagotchi::Schedules.tick_interval_minutes * 60)
|
|
364
|
+
@schedule_tick_in_flight = true
|
|
365
|
+
@schedule_tick_thread = Thread.new { run_schedule_tick }
|
|
366
|
+
end
|
|
393
367
|
end
|
|
394
368
|
rescue StandardError => e
|
|
395
369
|
@monitor.synchronize do
|
|
@@ -402,6 +376,8 @@ module Samagotchi
|
|
|
402
376
|
nil
|
|
403
377
|
end
|
|
404
378
|
|
|
379
|
+
# The tick's body on the caller's thread (the specs call it directly;
|
|
380
|
+
# #schedule_tick runs it on its own thread).
|
|
405
381
|
def run_schedule_tick
|
|
406
382
|
schedules = Samagotchi::Schedules.new(state_dir: @state_dir)
|
|
407
383
|
# Stopping kills a condition's CMD (its process group) and runs no more.
|
|
@@ -417,6 +393,46 @@ module Samagotchi
|
|
|
417
393
|
end
|
|
418
394
|
end
|
|
419
395
|
|
|
396
|
+
# Whether a schedule tick is at work (started, not finished).
|
|
397
|
+
def schedule_tick_running?
|
|
398
|
+
@monitor.synchronize { @schedule_tick_in_flight }
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
# Waits for a running schedule tick to finish (it does not start one).
|
|
402
|
+
# @return [Boolean] true once no tick is running, else false.
|
|
403
|
+
def drain_schedule_tick(timeout:)
|
|
404
|
+
thread = @monitor.synchronize { @schedule_tick_thread }
|
|
405
|
+
thread&.join(timeout)
|
|
406
|
+
@monitor.synchronize { !@schedule_tick_in_flight }
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
private
|
|
410
|
+
|
|
411
|
+
def run_loop
|
|
412
|
+
until @stopped
|
|
413
|
+
begin
|
|
414
|
+
scan
|
|
415
|
+
rescue StandardError => e
|
|
416
|
+
Log.warn(:web, "hub_scan_failed", error: e.class.name, msg: e.message)
|
|
417
|
+
end
|
|
418
|
+
@wakeup.pop(timeout: @scan_interval)
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def full_probe_due?
|
|
423
|
+
now = @now.call
|
|
424
|
+
return false if @next_full_probe && now < @next_full_probe
|
|
425
|
+
|
|
426
|
+
@next_full_probe = now + @full_probe_interval
|
|
427
|
+
true
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def sweep
|
|
431
|
+
@manager.retention_sweep_if_due(state_dir: @state_dir)
|
|
432
|
+
rescue StandardError => e
|
|
433
|
+
Log.warn(:web, "retention_sweep_failed", error: e.class.name, msg: e.message)
|
|
434
|
+
end
|
|
435
|
+
|
|
420
436
|
# Once per schedule.tick_interval_minutes: a lock-free read of
|
|
421
437
|
# schedules.json (Schedules#claim_disabled_notices), so a cron tick's or
|
|
422
438
|
# a run-now's turn-off reaches the phone within one interval. A claim
|
|
@@ -14,6 +14,8 @@ require_relative "../worker_link"
|
|
|
14
14
|
require_relative "../compat"
|
|
15
15
|
require_relative "../session_row"
|
|
16
16
|
require_relative "../bridge/pending_card"
|
|
17
|
+
require_relative "../session_lifecycle"
|
|
18
|
+
require_relative "../worker_presence"
|
|
17
19
|
|
|
18
20
|
module Samagotchi
|
|
19
21
|
module Web
|
|
@@ -30,8 +32,27 @@ module Samagotchi
|
|
|
30
32
|
archived project_root bridge_up worker_version worker_features worker_compat pending_question pending_card
|
|
31
33
|
last_turn verdicts verify_fresh last_verdict].freeze
|
|
32
34
|
|
|
35
|
+
# The hub's answer for a session: its lifecycle state and whether its
|
|
36
|
+
# Bridge is up for it (the state, not the link alone).
|
|
37
|
+
Shown = Data.define(:state, :up)
|
|
38
|
+
|
|
33
39
|
module_function
|
|
34
40
|
|
|
41
|
+
# What the hub should show for +session+ (its state and up), from the
|
|
42
|
+
# lifecycle facts WorkerPresence reads (its link passed in, or looked
|
|
43
|
+
# up here).
|
|
44
|
+
# @param session [Session]
|
|
45
|
+
# @param owner [OwnerLock::Owner, nil]
|
|
46
|
+
# @param session_dir [String] the session's folder
|
|
47
|
+
# @param link [WorkerLink outcome, nil] already resolved; nil: resolved here
|
|
48
|
+
# @return [Shown]
|
|
49
|
+
def shown(session, owner:, session_dir:, link: nil)
|
|
50
|
+
link ||= WorkerLink.resolve(session_dir, unlink: false, owner: owner)
|
|
51
|
+
presence = WorkerPresence.read(session.id, state_dir: File.dirname(session_dir), owner: owner, link: link)
|
|
52
|
+
state = SessionLifecycle::Reading.derive(presence).state
|
|
53
|
+
Shown.new(state: state, up: state == :live)
|
|
54
|
+
end
|
|
55
|
+
|
|
35
56
|
# @param session [Session] a saved session (messages may be empty)
|
|
36
57
|
# @param owner [OwnerLock::Owner, nil] SessionManager.session_owner's; its
|
|
37
58
|
# kind is shown as `owner`
|
|
@@ -51,7 +72,8 @@ module Samagotchi
|
|
|
51
72
|
def build(session, owner:, session_dir:, status: displayed_status(session, owner: owner), root_cache: nil,
|
|
52
73
|
registry: nil, compat_version: VERSION)
|
|
53
74
|
link = WorkerLink.resolve(session_dir, unlink: false, owner: owner)
|
|
54
|
-
|
|
75
|
+
shown = shown(session, owner: owner, session_dir: session_dir, link: link)
|
|
76
|
+
up = shown.up
|
|
55
77
|
sidecar = up ? link.sidecar : nil
|
|
56
78
|
saved = SessionMetrics.saved_summary(session_dir, budget_tokens: budget_resolver(session, registry))
|
|
57
79
|
# The facts every list shares (SessionRow), from this one link,
|
|
@@ -60,7 +82,7 @@ module Samagotchi
|
|
|
60
82
|
saved: saved, card: RecapStore.card(session_dir))
|
|
61
83
|
values = {
|
|
62
84
|
id: row.id,
|
|
63
|
-
status: status,
|
|
85
|
+
status: unstopped(status, session, shown.state, owner),
|
|
64
86
|
mode: session.mode,
|
|
65
87
|
model_name: session.model_name,
|
|
66
88
|
working_directory: row.cwd,
|
|
@@ -107,9 +129,9 @@ module Samagotchi
|
|
|
107
129
|
# Hidden from the strip and the list unless the all view's "archived" toggle is on.
|
|
108
130
|
archived: row.archived,
|
|
109
131
|
project_root: row.project,
|
|
110
|
-
# A worker
|
|
111
|
-
# a worker
|
|
112
|
-
#
|
|
132
|
+
# A worker's Bridge answers and no stop is marked (the lifecycle
|
|
133
|
+
# state is live: a stopping worker, a worker on its way or with a
|
|
134
|
+
# newer protocol is not up).
|
|
113
135
|
bridge_up: up,
|
|
114
136
|
# The chi the live worker runs and what it can do (its sidecar;
|
|
115
137
|
# nil and [] without one): the page's stale-worker badge.
|
|
@@ -119,8 +141,8 @@ module Samagotchi
|
|
|
119
141
|
# For the tab's notifications (notify.js): an open question, the
|
|
120
142
|
# running turn's open card with actions, and how the last turn
|
|
121
143
|
# ended. A question saved by a worker that died is not open, nor a
|
|
122
|
-
# one-turn chi run's (only a worker shares it): the
|
|
123
|
-
pending_question: session.waiting_question(live:
|
|
144
|
+
# one-turn chi run's (only a worker shares it): the shown live.
|
|
145
|
+
pending_question: session.waiting_question(live: up),
|
|
124
146
|
pending_card: up ? Bridge::PendingCard.read(session_dir) : nil,
|
|
125
147
|
last_turn: session.last_turn&.to_file,
|
|
126
148
|
# Its Verify verdicts, the fresh ones its worker hasn't taken yet
|
|
@@ -166,6 +188,22 @@ module Samagotchi
|
|
|
166
188
|
session.displayed_status(owner: owner)
|
|
167
189
|
end
|
|
168
190
|
|
|
191
|
+
# The status the page shows: a "stopped" overlay (or a pre-marker file
|
|
192
|
+
# that says stopped) is only true in a stopped state; everywhere else
|
|
193
|
+
# the session's own status is shown, as displayed_status would (a
|
|
194
|
+
# "running" with no owner is idle). A statuses== stopped file that
|
|
195
|
+
# predates the marker stays stopped.
|
|
196
|
+
def unstopped(status, session, state, owner)
|
|
197
|
+
return status unless status == Session::STATUS_STOPPED
|
|
198
|
+
return status if SessionLifecycle::STOPPED_STATES.include?(state)
|
|
199
|
+
|
|
200
|
+
loaded = session.loaded_status
|
|
201
|
+
return status if loaded.nil? || loaded == Session::STATUS_STOPPED
|
|
202
|
+
|
|
203
|
+
loaded == Session::STATUS_RUNNING && owner.nil? ? Session::STATUS_IDLE : loaded
|
|
204
|
+
end
|
|
205
|
+
private_class_method :unstopped
|
|
206
|
+
|
|
169
207
|
def shown_status(session, state, turn_snapshot, owner:)
|
|
170
208
|
status = displayed_status(session, state, owner: owner)
|
|
171
209
|
return Session::STATUS_IDLE if status == Session::STATUS_RUNNING && turn_snapshot && !turn_snapshot["current_turn"]
|
|
@@ -10,17 +10,19 @@ module Samagotchi
|
|
|
10
10
|
class Invalid < StandardError; end
|
|
11
11
|
|
|
12
12
|
# Where +given+ came from, as its error names it.
|
|
13
|
-
|
|
13
|
+
# web.ask_dir (a thin client's create, Web::AskCreate) may come from
|
|
14
|
+
# config.yml or SAMAGOTCHI_WEB_ASK_DIR: named alone.
|
|
15
|
+
SOURCES = { flag: "--start-dir", config: "web.start_dir in config.yml", ask_config: "web.ask_dir" }.freeze
|
|
14
16
|
|
|
15
17
|
# +given+ as an absolute folder (~ expanded, a relative one against
|
|
16
|
-
# +cwd+, or the home folder for a
|
|
17
|
-
# @param from [Symbol] :flag or :
|
|
18
|
+
# +cwd+, or the home folder for a setting's value); nil or blank: +cwd+.
|
|
19
|
+
# @param from [Symbol] :flag, :config or :ask_config (SOURCES)
|
|
18
20
|
# @raise [Invalid] when it is no folder
|
|
19
21
|
def self.resolve(given, cwd: Dir.pwd, from: :flag)
|
|
20
22
|
return File.expand_path(cwd) if given.nil? || given.to_s.strip.empty?
|
|
21
23
|
|
|
22
24
|
source = SOURCES.fetch(from)
|
|
23
|
-
dir = File.expand_path(given.to_s.strip, from == :
|
|
25
|
+
dir = File.expand_path(given.to_s.strip, from == :flag ? cwd : Dir.home)
|
|
24
26
|
raise Invalid, "#{source} #{given}: no such folder" unless File.exist?(dir)
|
|
25
27
|
raise Invalid, "#{source} #{given}: not a folder" unless File.directory?(dir)
|
|
26
28
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "session_manager"
|
|
4
|
+
require_relative "session_transition"
|
|
4
5
|
|
|
5
6
|
module Samagotchi
|
|
6
7
|
# WorkerBoot: the worker process, from the entry the boot string names
|
|
@@ -156,12 +157,14 @@ module Samagotchi
|
|
|
156
157
|
|
|
157
158
|
# Delete a scratch session its worker left (its terminal gone:
|
|
158
159
|
# Worker#leave_scratch, or any other way out), now the lock is free.
|
|
159
|
-
# Its terminal may have deleted it first.
|
|
160
|
+
# Its terminal may have deleted it first. Held by a transition or a
|
|
161
|
+
# send now (#unheld), it stays: the retention sweep takes a leftover
|
|
162
|
+
# scratch session.
|
|
160
163
|
private def delete_left_scratch(session_id, state_dir:)
|
|
161
164
|
policy = SessionManager::RunningTasks::Policy.stop(by: "scratch")
|
|
162
|
-
SessionManager.delete_session(session_id, state_dir: state_dir, running_tasks: policy)
|
|
165
|
+
unheld(session_id, state_dir) { SessionManager.delete_session(session_id, state_dir: state_dir, running_tasks: policy) }
|
|
163
166
|
Log.info(:worker, "scratch_deleted", sid: session_id)
|
|
164
|
-
rescue SessionManager::DeleteRefused, ArgumentError, SystemCallError => e
|
|
167
|
+
rescue SessionManager::DeleteRefused, SessionTransition::Busy, ArgumentError, SystemCallError => e
|
|
165
168
|
Log.info(:worker, "scratch_kept", sid: session_id, error: e.class.name, msg: e.message)
|
|
166
169
|
ensure
|
|
167
170
|
SessionManager::RunningTasks.log_automatic!(policy) if policy
|
|
@@ -173,17 +176,36 @@ module Samagotchi
|
|
|
173
176
|
# (one that went in before the lock keeps the session), and a worker
|
|
174
177
|
# woken meanwhile owns it (delete_session refuses). A delivery during
|
|
175
178
|
# the deleting lock is refused (DeliverResult::DELETING, its file taken
|
|
176
|
-
# back), one after removal finds no session.
|
|
179
|
+
# back), one after removal finds no session. One holding its
|
|
180
|
+
# transition lock now (#unheld: a send's shared hold, a continue or a
|
|
181
|
+
# delete) keeps it.
|
|
177
182
|
private def discard_left_session(session_id, state_dir:, default_model:)
|
|
178
183
|
empty = -> { SessionManager.discardable?(session_id, state_dir: state_dir, default_model: default_model) }
|
|
179
184
|
return unless empty.call
|
|
180
185
|
|
|
181
|
-
|
|
186
|
+
unheld(session_id, state_dir) do
|
|
187
|
+
SessionManager.delete_session(session_id, state_dir: state_dir, purge_runs: false, still: empty)
|
|
188
|
+
end
|
|
182
189
|
Log.info(:worker, "discarded_empty", sid: session_id)
|
|
183
|
-
rescue SessionManager::DeleteRefused, SessionManager::OwnedByTUI, ArgumentError,
|
|
190
|
+
rescue SessionManager::DeleteRefused, SessionManager::OwnedByTUI, SessionTransition::Busy, ArgumentError,
|
|
191
|
+
SystemCallError => e
|
|
184
192
|
Log.info(:worker, "kept_session", sid: session_id, error: e.class.name, msg: e.message)
|
|
185
193
|
end
|
|
186
194
|
|
|
195
|
+
# The block under +session_id+'s transition lock held exclusively
|
|
196
|
+
# (kind :delete, one try), taken after this worker let go of its
|
|
197
|
+
# owner lock (transition before owner): a send, a continue or a
|
|
198
|
+
# delete holding it now raises SessionTransition::Busy, and the
|
|
199
|
+
# session stays. A session already gone takes no lock (its folder is
|
|
200
|
+
# not made again): the delete says so.
|
|
201
|
+
private def unheld(session_id, state_dir, &)
|
|
202
|
+
on_disk = File.exist?(Session.session_file(session_id, state_dir: state_dir)) ||
|
|
203
|
+
Dir.exist?(Session.session_dir(session_id, state_dir: state_dir))
|
|
204
|
+
return yield unless on_disk && Session.valid_id?(session_id)
|
|
205
|
+
|
|
206
|
+
SessionTransition.exclusive([session_id], kind: :delete, state_dir: state_dir, deadline: 0, &)
|
|
207
|
+
end
|
|
208
|
+
|
|
187
209
|
# The tools' ProjectEnv for the session's folder (its working_directory;
|
|
188
210
|
# spawn_options chdirs there unless it is gone), installed for this
|
|
189
211
|
# process's tool spawns. Never fatal: a worker without it still runs.
|
|
@@ -38,9 +38,12 @@ module Samagotchi
|
|
|
38
38
|
# the caller already read it (SessionManager.session_owner, a stand-in
|
|
39
39
|
# manager's), or a reader of it called only for a valid id; :read reads
|
|
40
40
|
# it here (OwnerLock.owner)
|
|
41
|
-
# @param link [nil, :look, :unlink] also resolve the
|
|
42
|
-
# :look leaves a stale sidecar, :unlink removes it (
|
|
43
|
-
# given the owner read here or by the caller: one
|
|
41
|
+
# @param link [nil, :look, :unlink, WorkerLink outcome] also resolve the
|
|
42
|
+
# WorkerLink: :look leaves a stale sidecar, :unlink removes it (a
|
|
43
|
+
# WorkerLink.resolve, given the owner read here or by the caller: one
|
|
44
|
+
# moment's snapshot); an already resolved outcome (anything responding
|
|
45
|
+
# to #live?, e.g. a caller's own WorkerLink.resolve) is used as is.
|
|
46
|
+
# nil reads no link
|
|
44
47
|
# @return [WorkerPresence]
|
|
45
48
|
def self.read(session_id, state_dir: nil, owner: :read, link: nil)
|
|
46
49
|
return absent(session_id, link: link) unless Session.valid_id?(session_id)
|
|
@@ -55,15 +58,28 @@ module Samagotchi
|
|
|
55
58
|
stop_marked: Session.stopped_marker?(session_id, state_dir: sd),
|
|
56
59
|
starting_marked: StartingMarker.fresh?(session_id, state_dir: sd),
|
|
57
60
|
archived: ArchiveStore.archived?(dir),
|
|
58
|
-
link: link
|
|
61
|
+
link: resolved_link(link, dir, owner))
|
|
59
62
|
end
|
|
60
63
|
|
|
64
|
+
# The +link:+ argument as the outcome to carry: a resolved outcome
|
|
65
|
+
# (anything responding to #live?) is used as is; nil reads no link;
|
|
66
|
+
# :look or :unlink resolves the WorkerLink (WorkerLink.resolve).
|
|
67
|
+
# @return [WorkerLink outcome, nil]
|
|
68
|
+
def self.resolved_link(link, dir, owner)
|
|
69
|
+
return nil if link.nil?
|
|
70
|
+
return link if link.respond_to?(:live?)
|
|
71
|
+
|
|
72
|
+
WorkerLink.resolve(dir, unlink: link == :unlink, owner: owner)
|
|
73
|
+
end
|
|
74
|
+
private_class_method :resolved_link
|
|
75
|
+
|
|
61
76
|
# An id that isn't one names no session: nothing on disk is read
|
|
62
|
-
# (Session.session_dir would raise), and a link asked for
|
|
77
|
+
# (Session.session_dir would raise), and a link asked for resolves as
|
|
78
|
+
# None unless it was already resolved.
|
|
63
79
|
# @return [WorkerPresence]
|
|
64
80
|
def self.absent(session_id, link: nil)
|
|
65
81
|
new(session_id: session_id, exists: false, owner: nil, stop_marked: false, starting_marked: false,
|
|
66
|
-
archived: false, link: link && WorkerLink::None.new)
|
|
82
|
+
archived: false, link: link.respond_to?(:live?) ? link : (link && WorkerLink::None.new))
|
|
67
83
|
end
|
|
68
84
|
|
|
69
85
|
def initialize(session_id:, exists:, owner:, stop_marked:, starting_marked:, archived:, link: nil) = super
|
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.192.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dedov
|
|
@@ -296,6 +296,8 @@ files:
|
|
|
296
296
|
- lib/samagotchi/bundles/mcp/manifest.yml
|
|
297
297
|
- lib/samagotchi/bundles/mcp/oauth.rb
|
|
298
298
|
- lib/samagotchi/bundles/mcp/plugin.rb
|
|
299
|
+
- lib/samagotchi/bundles/mcp/server_config.rb
|
|
300
|
+
- lib/samagotchi/bundles/mcp/sign_in.rb
|
|
299
301
|
- lib/samagotchi/bundles/mcp/tools.rb
|
|
300
302
|
- lib/samagotchi/bundles/model-notes/manifest.yml
|
|
301
303
|
- lib/samagotchi/bundles/model-notes/model_notes_deepseek.md
|
|
@@ -757,6 +759,7 @@ files:
|
|
|
757
759
|
- lib/samagotchi/session_chain/delete.rb
|
|
758
760
|
- lib/samagotchi/session_chain/delete_preview.rb
|
|
759
761
|
- lib/samagotchi/session_chain/links.rb
|
|
762
|
+
- lib/samagotchi/session_chain/successor.rb
|
|
760
763
|
- lib/samagotchi/session_command_catalog.rb
|
|
761
764
|
- lib/samagotchi/session_commands.rb
|
|
762
765
|
- lib/samagotchi/session_config.rb
|
|
@@ -796,6 +799,7 @@ files:
|
|
|
796
799
|
- lib/samagotchi/session_setting.rb
|
|
797
800
|
- lib/samagotchi/session_setup.rb
|
|
798
801
|
- lib/samagotchi/session_stores.rb
|
|
802
|
+
- lib/samagotchi/session_transition.rb
|
|
799
803
|
- lib/samagotchi/sessions_command.rb
|
|
800
804
|
- lib/samagotchi/setting_explained.rb
|
|
801
805
|
- lib/samagotchi/share_command.rb
|
|
@@ -989,6 +993,7 @@ files:
|
|
|
989
993
|
- lib/samagotchi/visitor.rb
|
|
990
994
|
- lib/samagotchi/waiting_steer.rb
|
|
991
995
|
- lib/samagotchi/web/app.rb
|
|
996
|
+
- lib/samagotchi/web/ask_create.rb
|
|
992
997
|
- lib/samagotchi/web/ask_routes.rb
|
|
993
998
|
- lib/samagotchi/web/auto_update.rb
|
|
994
999
|
- lib/samagotchi/web/auto_update_record.rb
|
|
@@ -998,6 +1003,7 @@ files:
|
|
|
998
1003
|
- lib/samagotchi/web/editor.rb
|
|
999
1004
|
- lib/samagotchi/web/info_probe.rb
|
|
1000
1005
|
- lib/samagotchi/web/lan.rb
|
|
1006
|
+
- lib/samagotchi/web/last_ask.rb
|
|
1001
1007
|
- lib/samagotchi/web/link_codes.rb
|
|
1002
1008
|
- lib/samagotchi/web/markdown_renderer.rb
|
|
1003
1009
|
- lib/samagotchi/web/mcp_route.rb
|
|
@@ -1023,6 +1029,7 @@ files:
|
|
|
1023
1029
|
- lib/samagotchi/web/public/annotations.js
|
|
1024
1030
|
- lib/samagotchi/web/public/answer_fold.js
|
|
1025
1031
|
- lib/samagotchi/web/public/answer_refs.js
|
|
1032
|
+
- lib/samagotchi/web/public/answer_write.js
|
|
1026
1033
|
- lib/samagotchi/web/public/app.js
|
|
1027
1034
|
- lib/samagotchi/web/public/apple-touch-icon.png
|
|
1028
1035
|
- lib/samagotchi/web/public/auth_lost.js
|
|
@@ -1069,6 +1076,8 @@ files:
|
|
|
1069
1076
|
- lib/samagotchi/web/public/diagram_wiring.js
|
|
1070
1077
|
- lib/samagotchi/web/public/diff_view.js
|
|
1071
1078
|
- lib/samagotchi/web/public/dock_reserve.js
|
|
1079
|
+
- lib/samagotchi/web/public/draft_keys.js
|
|
1080
|
+
- lib/samagotchi/web/public/drafts.js
|
|
1072
1081
|
- lib/samagotchi/web/public/families_view.js
|
|
1073
1082
|
- lib/samagotchi/web/public/favicon.svg
|
|
1074
1083
|
- lib/samagotchi/web/public/feature_gates.js
|