samagotchi 0.192.0 → 0.194.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 +128 -1
- data/docs/architecture.md +3 -3
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +82 -40
- data/docs/cli.md +47 -17
- data/docs/configuration.md +75 -8
- data/docs/context.md +8 -5
- data/docs/desktop.md +3 -0
- data/docs/guardrails.md +20 -5
- data/docs/hooks.md +1 -0
- data/docs/internals/bridge.md +3 -1
- data/docs/internals/bundles.md +2 -2
- data/docs/internals/engine.md +46 -3
- data/docs/internals/pages.md +4 -4
- data/docs/internals/panes.md +66 -0
- data/docs/internals/participants.md +5 -3
- data/docs/internals/peers.md +176 -27
- data/docs/internals/prompt-caching.md +6 -1
- data/docs/internals/remote-sessions.md +6 -0
- data/docs/internals/session-lifecycle.md +12 -4
- data/docs/internals/web-frontend.md +106 -22
- data/docs/internals/working-set.md +5 -1
- data/docs/peers.md +150 -27
- data/docs/plugins.md +48 -7
- data/docs/releasing.md +30 -2
- data/docs/scheduling.md +3 -2
- data/docs/sessions.md +16 -7
- data/docs/sub-agent.md +6 -4
- data/docs/system-one.md +4 -0
- data/docs/testing.md +38 -3
- data/docs/thin-clients.md +27 -11
- data/lib/samagotchi/bridge/card_store.rb +1 -1
- data/lib/samagotchi/broadcast/triage_model.rb +17 -0
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +8 -5
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +24 -5
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +61 -24
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +31 -8
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +8 -5
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +62 -6
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +57 -19
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +28 -7
- data/lib/samagotchi/bundles/coordinator/manifest.yml +2 -2
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +31 -0
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
- data/lib/samagotchi/bundles/mcp/plugin.rb +0 -7
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/chi_invocation.rb +7 -0
- data/lib/samagotchi/client.rb +18 -0
- data/lib/samagotchi/codex_rollout.rb +93 -0
- data/lib/samagotchi/compat.rb +8 -1
- data/lib/samagotchi/config.rb +19 -6
- data/lib/samagotchi/continue_offer.rb +13 -1
- data/lib/samagotchi/delivery.rb +2 -2
- data/lib/samagotchi/effective_model.rb +28 -2
- data/lib/samagotchi/engine/cards.rb +9 -4
- data/lib/samagotchi/engine/hooks.rb +8 -0
- data/lib/samagotchi/engine/models.rb +197 -7
- data/lib/samagotchi/engine/plugins.rb +2 -0
- data/lib/samagotchi/engine/side_requests.rb +72 -13
- data/lib/samagotchi/engine/toolkit.rb +1 -1
- data/lib/samagotchi/engine/turn_helpers.rb +1 -1
- data/lib/samagotchi/engine.rb +11 -8
- data/lib/samagotchi/engine_snapshots.rb +16 -3
- data/lib/samagotchi/events.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +49 -18
- data/lib/samagotchi/hooks.rb +3 -1
- data/lib/samagotchi/host_registry.rb +146 -16
- data/lib/samagotchi/idle_client.rb +13 -2
- data/lib/samagotchi/idle_recap.rb +33 -3
- data/lib/samagotchi/idle_target.rb +27 -7
- data/lib/samagotchi/jsonl_store.rb +13 -2
- data/lib/samagotchi/llm/adapter_common.rb +4 -2
- data/lib/samagotchi/llm/anthropic_messages.rb +14 -2
- data/lib/samagotchi/llm/errors.rb +35 -4
- data/lib/samagotchi/llm/model_listing.rb +19 -0
- data/lib/samagotchi/llm/openai_chat.rb +8 -2
- data/lib/samagotchi/llm/prompt_cache.rb +5 -0
- data/lib/samagotchi/model_binding.rb +46 -4
- data/lib/samagotchi/model_catalog.rb +68 -8
- data/lib/samagotchi/model_profile.rb +35 -0
- data/lib/samagotchi/models_command.rb +8 -4
- data/lib/samagotchi/pages/launch.rb +1 -1
- data/lib/samagotchi/panes/kitty.rb +122 -0
- data/lib/samagotchi/panes.rb +185 -0
- data/lib/samagotchi/peer_announce.rb +245 -0
- data/lib/samagotchi/peer_cold.rb +92 -0
- data/lib/samagotchi/peer_command.rb +121 -20
- data/lib/samagotchi/peer_continue.rb +42 -16
- data/lib/samagotchi/peer_exchanges.rb +7 -0
- data/lib/samagotchi/peer_mailbox.rb +50 -10
- data/lib/samagotchi/peer_pair_here.rb +149 -0
- data/lib/samagotchi/peer_presence.rb +434 -0
- data/lib/samagotchi/peer_receipts.rb +33 -6
- data/lib/samagotchi/peer_say.rb +46 -21
- data/lib/samagotchi/peer_wait_expiry.rb +47 -0
- data/lib/samagotchi/plugin/api.rb +13 -1
- data/lib/samagotchi/plugin/card.rb +68 -11
- data/lib/samagotchi/plugin/context.rb +33 -2
- data/lib/samagotchi/plugin/panes.rb +54 -0
- data/lib/samagotchi/plugin/peer.rb +170 -63
- data/lib/samagotchi/plugin/peer_pairing.rb +290 -0
- data/lib/samagotchi/plugin/peer_start.rb +301 -0
- data/lib/samagotchi/plugin/peer_start_hook.rb +207 -0
- data/lib/samagotchi/plugin/peers.rb +89 -9
- data/lib/samagotchi/recap_setup.rb +40 -3
- data/lib/samagotchi/self_report.rb +25 -6
- data/lib/samagotchi/send_command.rb +6 -6
- data/lib/samagotchi/served_lookup.rb +225 -0
- data/lib/samagotchi/served_ref.rb +41 -0
- data/lib/samagotchi/session_access/contract.rb +6 -0
- data/lib/samagotchi/session_access/local.rb +149 -40
- data/lib/samagotchi/session_access/remote.rb +4 -4
- data/lib/samagotchi/session_access/remote_peers.rb +8 -5
- data/lib/samagotchi/session_chain/links.rb +8 -3
- data/lib/samagotchi/session_commands.rb +40 -8
- data/lib/samagotchi/session_continue.rb +11 -6
- data/lib/samagotchi/session_lifecycle/allowed.rb +4 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -0
- data/lib/samagotchi/session_manager/lifecycle.rb +58 -7
- data/lib/samagotchi/session_manager/removal.rb +3 -0
- data/lib/samagotchi/session_manager/spawn.rb +6 -1
- data/lib/samagotchi/session_model_settings.rb +7 -3
- data/lib/samagotchi/session_stores.rb +25 -11
- data/lib/samagotchi/sessions_command.rb +16 -3
- data/lib/samagotchi/system_one/http_backend.rb +111 -10
- data/lib/samagotchi/system_one/runs.rb +5 -2
- data/lib/samagotchi/system_prompt.rb +11 -4
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +26 -12
- data/lib/samagotchi/terminal_ui/status_row.rb +20 -3
- data/lib/samagotchi/terminal_ui.rb +1 -1
- data/lib/samagotchi/testing/boundary.rb +0 -1
- data/lib/samagotchi/testing/bundle.rb +6 -2
- data/lib/samagotchi/testing/host.rb +1 -0
- data/lib/samagotchi/testing/recorder.rb +3 -0
- data/lib/samagotchi/turn_endings.rb +6 -2
- data/lib/samagotchi/user_typed.rb +29 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +8 -20
- data/lib/samagotchi/web/participant_review.rb +1 -1
- data/lib/samagotchi/web/participant_view.rb +1 -1
- data/lib/samagotchi/web/peer_routes.rb +40 -15
- data/lib/samagotchi/web/public/agent_rows.js +206 -0
- data/lib/samagotchi/web/public/agent_runs.js +595 -0
- data/lib/samagotchi/web/public/answer_fold.js +41 -44
- data/lib/samagotchi/web/public/app.js +4 -4
- data/lib/samagotchi/web/public/block_fix.js +1 -1
- data/lib/samagotchi/web/public/card.js +26 -10
- data/lib/samagotchi/web/public/cards_place.js +6 -4
- data/lib/samagotchi/web/public/context_chips.js +24 -2
- data/lib/samagotchi/web/public/copy.js +8 -2
- data/lib/samagotchi/web/public/data.js +2 -1
- data/lib/samagotchi/web/public/format.js +9 -1
- data/lib/samagotchi/web/public/history_reveal.js +5 -2
- data/lib/samagotchi/web/public/index.html +56 -2
- data/lib/samagotchi/web/public/info_bar_model.js +1 -1
- data/lib/samagotchi/web/public/model_pick.js +18 -5
- data/lib/samagotchi/web/public/model_picker.js +1 -1
- data/lib/samagotchi/web/public/page_view.js +1 -1
- data/lib/samagotchi/web/public/pages.css +1 -7
- data/lib/samagotchi/web/public/peer_chip.js +15 -5
- data/lib/samagotchi/web/public/peer_data.js +4 -2
- data/lib/samagotchi/web/public/peer_mailbox_api.js +2 -1
- data/lib/samagotchi/web/public/peer_note.js +4 -2
- data/lib/samagotchi/web/public/peer_row.js +37 -0
- data/lib/samagotchi/web/public/peer_wait.js +36 -0
- data/lib/samagotchi/web/public/quiet_notes.js +12 -1
- data/lib/samagotchi/web/public/revise_stack.js +5 -2
- data/lib/samagotchi/web/public/send_turn.js +11 -3
- data/lib/samagotchi/web/public/served_ref.js +9 -0
- data/lib/samagotchi/web/public/session_fields.js +1 -0
- data/lib/samagotchi/web/public/session_state.js +4 -0
- data/lib/samagotchi/web/public/stage_missing.js +23 -6
- data/lib/samagotchi/web/public/stream_handlers.js +16 -0
- data/lib/samagotchi/web/public/turn_block.js +4 -0
- data/lib/samagotchi/web/public/version_notices.js +7 -1
- data/lib/samagotchi/web/session_control.rb +19 -10
- data/lib/samagotchi/web/session_show.rb +20 -0
- data/lib/samagotchi/web/update_ops.rb +2 -2
- data/lib/samagotchi/worker/command_queue.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +24 -1
- data/lib/samagotchi/worker.rb +8 -5
- data/lib/samagotchi/worker_inbound/mail.rb +34 -6
- data/lib/samagotchi/worker_inbound.rb +11 -3
- data/lib/samagotchi/worker_link.rb +13 -1
- data/lib/samagotchi/worker_wakes.rb +33 -5
- metadata +22 -2
- data/lib/samagotchi/web/public/pages_group.js +0 -67
|
@@ -55,15 +55,8 @@
|
|
|
55
55
|
# server's config: command/env/cwd or url/headers and digest, and why a
|
|
56
56
|
# config is refused), tools.rb (the tools/list cache and the tool index) and
|
|
57
57
|
# content.rb (a tools/call answer's text and images).
|
|
58
|
-
require "digest"
|
|
59
|
-
require "json"
|
|
60
58
|
require "samagotchi/token_usage"
|
|
61
59
|
require "samagotchi/tools/tool_index"
|
|
62
|
-
require "samagotchi/tool_declarations"
|
|
63
|
-
require "time"
|
|
64
|
-
require "shellwords"
|
|
65
|
-
require "tmpdir"
|
|
66
|
-
require "uri"
|
|
67
60
|
|
|
68
61
|
class Plugin
|
|
69
62
|
PROTOCOL_VERSION = "2025-06-18"
|
|
@@ -22,6 +22,13 @@ module Samagotchi
|
|
|
22
22
|
# chi --resume ID (chi --remote NAME --resume ID).
|
|
23
23
|
def resume(id) = command("--resume #{id}")
|
|
24
24
|
|
|
25
|
+
# How a stopped session starts again, after the caller's lead-in
|
|
26
|
+
# ("start it yourself: …", "ask your user to start it: …"): its resume,
|
|
27
|
+
# or a message from a terminal or the web. Only its owner's does: an
|
|
28
|
+
# agent's, a peer's or a schedule's never un-stops it
|
|
29
|
+
# (SessionInbox::WakePolicy).
|
|
30
|
+
def start_stopped(id) = "`#{resume(id)}`, or a message from a terminal or #{remote? ? web : "the web"}"
|
|
31
|
+
|
|
25
32
|
# What shows the session ("… shows it"): its attach.
|
|
26
33
|
def shows(id) = attach(id)
|
|
27
34
|
|
data/lib/samagotchi/client.rb
CHANGED
|
@@ -344,6 +344,24 @@ module Samagotchi
|
|
|
344
344
|
raise "#{LABEL} model listing failed (#{@host}:#{@port}): #{e.message}"
|
|
345
345
|
end
|
|
346
346
|
|
|
347
|
+
# #list_models as one bounded GET: the /props probe's short timeouts, no
|
|
348
|
+
# retry (ServedLookup's turn-start listing: a host that is down fails
|
|
349
|
+
# fast, and the turn's own request says so).
|
|
350
|
+
def list_models_probe
|
|
351
|
+
uri = URI("#{@scheme}://#{@host}:#{@port}#{MODELS_PATH}")
|
|
352
|
+
response = @http.fetch(uri, Net::HTTP::Get.new(uri), retries: false, log_fields: { purpose: "models" },
|
|
353
|
+
open_timeout: CONTEXT_WINDOW_PROBE_OPEN_TIMEOUT,
|
|
354
|
+
read_timeout: CONTEXT_WINDOW_PROBE_READ_TIMEOUT,
|
|
355
|
+
cancel_controller: Client.probe_cancel)
|
|
356
|
+
clear_props_failures!
|
|
357
|
+
parsed = JSON.parse(response.body.to_s)
|
|
358
|
+
parsed.fetch("data", parsed)
|
|
359
|
+
rescue LLM::ProviderError, LLM::RequestCancelled
|
|
360
|
+
raise
|
|
361
|
+
rescue StandardError => e
|
|
362
|
+
raise "#{LABEL} model listing failed (#{@host}:#{@port}): #{e.message}"
|
|
363
|
+
end
|
|
364
|
+
|
|
347
365
|
# What the running server says about itself (/props), as a ServerProps.
|
|
348
366
|
# One GET with short
|
|
349
367
|
# timeouts and no retry: it runs before generation and must never hold up
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Samagotchi
|
|
6
|
+
# Whether a Codex SessionStart hook comes from a fresh interactive Codex
|
|
7
|
+
# (the TUI's first message), read from the first line of its rollout file
|
|
8
|
+
# (the hook's `transcript_path`, `type: session_meta`). codex-peer's start
|
|
9
|
+
# hook (`chi peer announce codex`) takes a waiting mark only then, never
|
|
10
|
+
# for a `codex exec`, an `exec resume` or a subagent. The rule is an
|
|
11
|
+
# allowlist: `payload.originator == "codex-tui"`, `payload.thread_source
|
|
12
|
+
# == "user"`, a string `payload.source`, `payload.id` the hook's
|
|
13
|
+
# session_id; anything else, missing or unreadable: no.
|
|
14
|
+
#
|
|
15
|
+
# The format is Codex's own, undocumented: checked on Codex 0.172.0.
|
|
16
|
+
# Line 1 is big (about 19 KB: `payload.base_instructions`), so it is read
|
|
17
|
+
# to the first newline within LINE_MAX_BYTES; the hook fires a second or
|
|
18
|
+
# so after the file is born, so a missing file, a 0-byte one or a line
|
|
19
|
+
# with no newline yet is tried again (TRIES × TRY_SECONDS), then given up.
|
|
20
|
+
# The file must be a regular file (no link followed) whose real path is
|
|
21
|
+
# under <codex home>/sessions. See docs/internals/peers.md.
|
|
22
|
+
module CodexRollout
|
|
23
|
+
CHECKED_ON = "Codex 0.172.0"
|
|
24
|
+
LINE_MAX_BYTES = 1_048_576
|
|
25
|
+
TRIES = 10
|
|
26
|
+
TRY_SECONDS = 0.1
|
|
27
|
+
ORIGINATOR = "codex-tui"
|
|
28
|
+
THREAD_SOURCE = "user"
|
|
29
|
+
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# @param path [String] the hook's transcript_path
|
|
33
|
+
# @param session [String] the hook's session_id
|
|
34
|
+
# @param codex_home [String] CODEX_HOME, else ~/.codex
|
|
35
|
+
# @param sleeper [#call] waits between tries (specs: no real sleep)
|
|
36
|
+
# @return [Boolean]
|
|
37
|
+
def interactive_start?(path, session:, codex_home:, sleeper: ->(seconds) { sleep(seconds) })
|
|
38
|
+
return false unless path.is_a?(String) && path.start_with?("/") && session.is_a?(String) && !session.empty?
|
|
39
|
+
|
|
40
|
+
line = nil
|
|
41
|
+
TRIES.times do |try|
|
|
42
|
+
line = first_line(path, codex_home)
|
|
43
|
+
break unless line == :again
|
|
44
|
+
|
|
45
|
+
sleeper.call(TRY_SECONDS) if try < TRIES - 1
|
|
46
|
+
end
|
|
47
|
+
line.is_a?(String) && interactive_meta?(line, session)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Line 1 of +path+ (newline-terminated), :again (not there yet, empty or
|
|
51
|
+
# still being written), or nil (never: a link, not a file, outside the
|
|
52
|
+
# sessions folder, unreadable, over LINE_MAX_BYTES).
|
|
53
|
+
def first_line(path, codex_home)
|
|
54
|
+
stat = File.lstat(path)
|
|
55
|
+
return nil unless stat.file? && under?(path, codex_home)
|
|
56
|
+
|
|
57
|
+
# NONBLOCK and the open file's own stat: a FIFO (or anything but a
|
|
58
|
+
# regular file) swapped in after the lstat can't block the hook.
|
|
59
|
+
line = File.open(path, File::RDONLY | File::NOFOLLOW | File::NONBLOCK) do |io|
|
|
60
|
+
next :not_file unless io.stat.file?
|
|
61
|
+
|
|
62
|
+
io.binmode
|
|
63
|
+
io.gets("\n", LINE_MAX_BYTES + 1)
|
|
64
|
+
end
|
|
65
|
+
return nil if line == :not_file
|
|
66
|
+
return :again if line.nil?
|
|
67
|
+
return line if line.end_with?("\n")
|
|
68
|
+
|
|
69
|
+
line.bytesize > LINE_MAX_BYTES ? nil : :again
|
|
70
|
+
rescue Errno::ENOENT
|
|
71
|
+
:again
|
|
72
|
+
rescue SystemCallError, IOError
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# +path+'s real path is under <codex_home>/sessions.
|
|
77
|
+
def under?(path, codex_home)
|
|
78
|
+
root = File.realpath(File.join(codex_home.to_s, "sessions"))
|
|
79
|
+
File.realpath(path).start_with?("#{root}/")
|
|
80
|
+
rescue SystemCallError, ArgumentError
|
|
81
|
+
false
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def interactive_meta?(line, session)
|
|
85
|
+
data = JSON.parse(line.dup.force_encoding(Encoding::UTF_8))
|
|
86
|
+
payload = data.is_a?(Hash) && data["type"] == "session_meta" ? data["payload"] : nil
|
|
87
|
+
payload.is_a?(Hash) && payload["id"] == session && payload["originator"] == ORIGINATOR &&
|
|
88
|
+
payload["thread_source"] == THREAD_SOURCE && payload["source"].is_a?(String)
|
|
89
|
+
rescue JSON::ParserError, EncodingError
|
|
90
|
+
false
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
data/lib/samagotchi/compat.rb
CHANGED
|
@@ -17,7 +17,14 @@ module Samagotchi
|
|
|
17
17
|
Shim = Data.define(:id, :added_in, :added_on, :remove_after, :files, :what)
|
|
18
18
|
MIN_AGE_DAYS = 14
|
|
19
19
|
|
|
20
|
-
SHIMS = [
|
|
20
|
+
SHIMS = [
|
|
21
|
+
Shim.new(id: :agent_client_id, added_in: "0.185.0", added_on: "2026-11-22", remove_after: "0.195.0",
|
|
22
|
+
files: %w[lib/samagotchi/delivery.rb lib/samagotchi/session_manager/delivery.rb
|
|
23
|
+
lib/samagotchi/session_access/remote.rb spec/session_access_remote_spec.rb
|
|
24
|
+
spec/session_manager/delivery_spec.rb],
|
|
25
|
+
what: "an agent's client id (agent:<name>) sent as chi send's to a worker or chi web " \
|
|
26
|
+
"from before agent: senders (Delivery::AGENT_FEATURE)")
|
|
27
|
+
].freeze
|
|
21
28
|
|
|
22
29
|
module_function
|
|
23
30
|
|
data/lib/samagotchi/config.rb
CHANGED
|
@@ -89,7 +89,7 @@ module Samagotchi
|
|
|
89
89
|
new_session session_creation worker_start next_broadcast next_retention_sweep next_invocation next_lifecycle_decision
|
|
90
90
|
next_matching_use next_tool_or_approval process_start next_context_poll prompt_rebuild next_turn_start
|
|
91
91
|
next_request_or_turn_end next_update desktop_update web_start next_cli_run next_empty_answer_retry
|
|
92
|
-
next_history_access next_matching_turn_display_poll_write
|
|
92
|
+
next_history_access next_matching_turn_display_poll_write next_pane_lookup
|
|
93
93
|
].freeze
|
|
94
94
|
|
|
95
95
|
# llm_context.policy's default: the sentence forget_outputs' description
|
|
@@ -258,6 +258,10 @@ module Samagotchi
|
|
|
258
258
|
# wake isn't counted here); then they wait as notes, and the say's line says so. 0: a peer's message never
|
|
259
259
|
# wakes chi. Not context.wake's: that is attached context's only.
|
|
260
260
|
Entry.new(key: "peer.turns", yaml_path: %w[peer turns], type: :integer, default: 3, expose: %i[env config cli], lifecycle: :next_matching_turn_display_poll_write),
|
|
261
|
+
# A pairing the model sends to after this many minutes with no exchange (no send, no message from the peer,
|
|
262
|
+
# no pairing, one continue back included) is dormant: the send asks the owner first in a turn they started
|
|
263
|
+
# from the web or a TUI, and is refused in any other. 0: never asks.
|
|
264
|
+
Entry.new(key: "peer.quiet_minutes", yaml_path: %w[peer quiet_minutes], type: :integer, default: 30, expose: %i[env config cli], lifecycle: :next_matching_turn_display_poll_write),
|
|
261
265
|
# The candidate judge (ContextJudge): off (no conversation text goes to a System 1 host); audit (asks and logs
|
|
262
266
|
# context_candidates.jsonl, attaches nothing); on (ContextCandidateChoice: p ≥ threshold attaches quietly,
|
|
263
267
|
# offer_threshold ≤ p < threshold shows one card). Its host and model are system_one.host and .model.
|
|
@@ -361,8 +365,9 @@ module Samagotchi
|
|
|
361
365
|
check: ->(value) { "at least 0" unless value >= 0 }),
|
|
362
366
|
# The desktop helper's kitty targets (Desktop::MacOS.kitty_settings, one of its terminal_settings): listen_on copied from kitty.conf (unset = none),
|
|
363
367
|
# the kitty binary, and the foreground programs listed, "|"-separated (a YAML list works too; "*" = every window).
|
|
364
|
-
|
|
365
|
-
Entry.new(key: "kitty.
|
|
368
|
+
# listen_on and binary are also read live by a worker's Panes (/claude show, the sessions here list).
|
|
369
|
+
Entry.new(key: "kitty.listen_on", yaml_path: %w[kitty listen_on], type: :string, default: nil, expose: %i[env config], lifecycle: :next_pane_lookup),
|
|
370
|
+
Entry.new(key: "kitty.binary", yaml_path: %w[kitty binary], type: :string, default: "/Applications/kitty.app/Contents/MacOS/kitty", expose: %i[env config], lifecycle: :next_pane_lookup),
|
|
366
371
|
Entry.new(key: "kitty.agents", yaml_path: %w[kitty agents], type: :string, default: DESKTOP_AGENTS, expose: %i[env config], lifecycle: :desktop_update),
|
|
367
372
|
# Its tmux targets (Desktop::MacOS.tmux_settings): off until enabled; the tmux binary (unset = the tmux on
|
|
368
373
|
# chi's PATH when the launch file is written) and the foreground programs listed, as kitty.agents.
|
|
@@ -824,7 +829,10 @@ module Samagotchi
|
|
|
824
829
|
|
|
825
830
|
"config: model_aliases.#{name} points to the alias '#{inner}'; aliases don't chain, so '#{inner}' is sent as written"
|
|
826
831
|
end
|
|
827
|
-
|
|
832
|
+
served = aliases.keys.select { |name| name.to_s.strip.casecmp?(ConfigFile::SERVED_WORD) }.map do |name|
|
|
833
|
+
"config: model_aliases.#{name}: `served` is reserved (the model a host serves now); alias ignored"
|
|
834
|
+
end
|
|
835
|
+
slash + chains + served + hosts.keys.filter_map { |name| family_host_problem(name.to_s) }
|
|
828
836
|
end
|
|
829
837
|
|
|
830
838
|
# Model families whose ids carry a ':' tag on Ollama and friends
|
|
@@ -1392,7 +1400,8 @@ module Samagotchi
|
|
|
1392
1400
|
|
|
1393
1401
|
raw.each_with_object({}) do |(k, v), result|
|
|
1394
1402
|
key = k.to_s.strip
|
|
1395
|
-
|
|
1403
|
+
# `served` is reserved (ServedRef): main:served never goes through an alias.
|
|
1404
|
+
next if key.empty? || key.casecmp?(SERVED_WORD)
|
|
1396
1405
|
|
|
1397
1406
|
val = v.to_s.strip
|
|
1398
1407
|
next if val.empty?
|
|
@@ -1406,6 +1415,10 @@ module Samagotchi
|
|
|
1406
1415
|
# Words /model takes as arguments (clear/default/none/off reset the
|
|
1407
1416
|
# runtime model), so no alias may be named after one.
|
|
1408
1417
|
RESERVED_MODEL_ALIASES = %w[clear default none off].freeze
|
|
1418
|
+
# The model value "whatever the host serves now" (ServedRef::WORD, kept
|
|
1419
|
+
# equal by its spec; not required here, the config loads light): never
|
|
1420
|
+
# an alias name.
|
|
1421
|
+
SERVED_WORD = "served"
|
|
1409
1422
|
|
|
1410
1423
|
# What is wrong with +alias_name+ as an alias for +target+, or nil.
|
|
1411
1424
|
def model_alias_error(alias_name, target)
|
|
@@ -1413,7 +1426,7 @@ module Samagotchi
|
|
|
1413
1426
|
return "alias name is required" if alias_key.empty?
|
|
1414
1427
|
|
|
1415
1428
|
lowered_key = alias_key.downcase
|
|
1416
|
-
return "alias name '#{alias_key}' is reserved" if RESERVED_MODEL_ALIASES.include?(lowered_key)
|
|
1429
|
+
return "alias name '#{alias_key}' is reserved" if RESERVED_MODEL_ALIASES.include?(lowered_key) || lowered_key == SERVED_WORD
|
|
1417
1430
|
return "alias name must not contain whitespace" if alias_key.match?(/\s/)
|
|
1418
1431
|
return "alias name must not start with '-'" if alias_key.start_with?("-")
|
|
1419
1432
|
return "alias name must not contain '/'" if alias_key.include?("/")
|
|
@@ -162,6 +162,7 @@ module Samagotchi
|
|
|
162
162
|
offer = @turn_flow.offer
|
|
163
163
|
resume_from = @turn_flow.resume_from
|
|
164
164
|
enqueued_id = offer_turn_id
|
|
165
|
+
offer_client = @turn_state.last_context&.origin&.client_id
|
|
165
166
|
author = @engine.session&.last_turn&.participant_author
|
|
166
167
|
close("answered")
|
|
167
168
|
if author && (reason = @participant_refused.call(author))
|
|
@@ -179,7 +180,7 @@ module Samagotchi
|
|
|
179
180
|
Log.warn(:worker, "turn_not_begun", continue: true, error: e.class.name, msg: e.message)
|
|
180
181
|
return announce_offer(offer)
|
|
181
182
|
end
|
|
182
|
-
origin = TurnOrigin.new(client_id: command
|
|
183
|
+
origin = TurnOrigin.new(client_id: continue_client(command, offer_client), enqueued_id: enqueued_id, author: author)
|
|
183
184
|
@run_turn.call(nil, continue: true, origin: origin, resumed: true, resume_from: resume_from,
|
|
184
185
|
max_iterations: @max_iterations.call(offer[:no_interrupt])) do |result, error|
|
|
185
186
|
if error
|
|
@@ -241,6 +242,17 @@ module Samagotchi
|
|
|
241
242
|
# nil when it ran no input (a reminder turn, a delegate's first).
|
|
242
243
|
def offer_turn_id = @engine.session&.last_turn&.enqueued_id
|
|
243
244
|
|
|
245
|
+
# Who the continue turn runs as: the answer's sender, except that a
|
|
246
|
+
# person's tap (ClientId::CARD_ANSWER, which names no screen and so
|
|
247
|
+
# isn't interactive) continues an offer turn sent from a web tab or a
|
|
248
|
+
# TUI as that screen's, so the turn stays interactive as it was
|
|
249
|
+
# (ctx.turn_interactive?: a dormant peer send asks there).
|
|
250
|
+
def continue_client(command, offer_client)
|
|
251
|
+
return command.client_id unless command.client_id == ClientId::CARD_ANSWER && ClientId.interactive?(offer_client)
|
|
252
|
+
|
|
253
|
+
offer_client
|
|
254
|
+
end
|
|
255
|
+
|
|
244
256
|
def announce_offer(offer = @turn_flow.offer)
|
|
245
257
|
@event_log.announce(type: :continue_offered, context: offer[:context], no_interrupt: offer[:no_interrupt])
|
|
246
258
|
ask
|
data/lib/samagotchi/delivery.rb
CHANGED
|
@@ -67,8 +67,8 @@ module Samagotchi
|
|
|
67
67
|
# A worker (Bridge::FEATURES) or a chi web (Web::App::INFO_FEATURES)
|
|
68
68
|
# that reads an agent's client id (ClientId::AGENT_PREFIX). One without
|
|
69
69
|
# it would read agent:<name> as an unknown sender (automatic), so it is
|
|
70
|
-
# sent chi send's id instead: today's owner row
|
|
71
|
-
# agent_client_id
|
|
70
|
+
# sent chi send's id instead: today's owner row.
|
|
71
|
+
# compat shim agent_client_id
|
|
72
72
|
AGENT_FEATURE = "agent_sender"
|
|
73
73
|
# A worker (Bridge::FEATURES) that runs another session's question
|
|
74
74
|
# (ClientId::SESSION_PREFIX, ask_session) as a visitor's turn. One
|
|
@@ -9,6 +9,7 @@ require_relative "model_profile"
|
|
|
9
9
|
require_relative "reasoning_history"
|
|
10
10
|
require_relative "sampling_settings"
|
|
11
11
|
require_relative "served_model"
|
|
12
|
+
require_relative "served_ref"
|
|
12
13
|
require_relative "steer_cut"
|
|
13
14
|
require_relative "steer_cut_after"
|
|
14
15
|
require_relative "thinking"
|
|
@@ -39,9 +40,12 @@ module Samagotchi
|
|
|
39
40
|
# @param choice [ModelChoice]
|
|
40
41
|
# @param models [Hash{String => ModelSettings}, nil] one models: map for
|
|
41
42
|
# many models (a picker); ModelSettings.all at each read by default
|
|
43
|
+
# @param served_id [String, nil] a served ref's id as the turn pinned it
|
|
44
|
+
# (ModelBinding#served_id): it wins over the registry's lookup
|
|
42
45
|
# @raise what HostRegistry#resolve raises
|
|
43
|
-
def self.of(registry, choice, models: nil)
|
|
44
|
-
|
|
46
|
+
def self.of(registry, choice, models: nil, served_id: nil)
|
|
47
|
+
# Only with a pin: a registry stand-in (a picker's, a spec's) takes the name alone.
|
|
48
|
+
target = served_id ? registry.resolve(choice.name, served_id: served_id) : registry.resolve(choice.name)
|
|
45
49
|
names = registry.lookup_names(choice.typed, resolved: choice.name, target: target)
|
|
46
50
|
new(registry: registry, name: choice.name, typed: choice.typed, target: target, names: names,
|
|
47
51
|
lookup: ModelLookup.for(target, names: names, models: models, env: registry.env))
|
|
@@ -85,6 +89,8 @@ module Samagotchi
|
|
|
85
89
|
|
|
86
90
|
def entry = target.entry
|
|
87
91
|
def client = target.client
|
|
92
|
+
# The id the host is sent (HostRegistry#sent_model_id's, from this
|
|
93
|
+
# resolve): what a turn's wire, settings and checks name.
|
|
88
94
|
def bare = target.bare_model
|
|
89
95
|
def host_name = entry.name
|
|
90
96
|
|
|
@@ -94,6 +100,26 @@ module Samagotchi
|
|
|
94
100
|
# The resolved ref a session stores (ModelRef#ref): no resolve.
|
|
95
101
|
def ref = registry.model_ref(name).ref
|
|
96
102
|
|
|
103
|
+
# Whether the model is a served ref (main:served: whatever its host
|
|
104
|
+
# serves now; ServedRef).
|
|
105
|
+
def served_ref? = ServedRef.served?(registry.model_ref(name))
|
|
106
|
+
|
|
107
|
+
# The ref this model's generations are counted under (SessionMetrics'
|
|
108
|
+
# per-model segments, Engine#generation_model_ref): #ref, or for a
|
|
109
|
+
# served ref the host and the id it resolved to ("main:q8"; #ref while
|
|
110
|
+
# nothing is known).
|
|
111
|
+
def turn_ref
|
|
112
|
+
id = served_id
|
|
113
|
+
id ? "#{host_name}:#{id}" : ref
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# A served ref's id as resolved (the turn's pin, else what its host's
|
|
117
|
+
# last listing knows; no request), nil for any other model or while
|
|
118
|
+
# nothing is known: the UIs' "served · <id>" (session state's
|
|
119
|
+
# model_served).
|
|
120
|
+
# @return [String, nil]
|
|
121
|
+
def served_id = served_ref? && !ServedRef.word?(bare) ? bare : nil
|
|
122
|
+
|
|
97
123
|
# The configured request parameters (hosts: and models: sampling).
|
|
98
124
|
def sampling
|
|
99
125
|
SamplingSettings.for(lookup)
|
|
@@ -24,15 +24,20 @@ module Samagotchi
|
|
|
24
24
|
# @param source [String] who shows it (a bundle's name)
|
|
25
25
|
# @param actions [Array<Hash>] {label:, command:}, a line the session
|
|
26
26
|
# runs as typed (D3), or {label:, url:}, an http(s) address a UI opens
|
|
27
|
-
# (it sends nothing; Plugin::Card.build checks it)
|
|
27
|
+
# (it sends nothing; Plugin::Card.build checks it); row: N makes it
|
|
28
|
+
# row N's button
|
|
29
|
+
# @param rows [Array<Hash>, nil] {title:, sub:}: a list to pick from
|
|
28
30
|
# @return [String] the card's id
|
|
29
31
|
# @raise [ArgumentError] a card without a title, or a bad action
|
|
30
|
-
def show_card(source:, title:, body: "", actions: [], level: :info, id: nil, between_turns: false)
|
|
32
|
+
def show_card(source:, title:, body: "", actions: [], level: :info, id: nil, between_turns: false, rows: nil)
|
|
31
33
|
if between_turns && turn_running?
|
|
32
|
-
return running_anytime
|
|
34
|
+
return running_anytime do
|
|
35
|
+
show_card(source: source, title: title, body: body, actions: actions, level: level, id: id, rows: rows)
|
|
36
|
+
end
|
|
33
37
|
end
|
|
34
38
|
|
|
35
|
-
card = Plugin::Card.build(source: source, title: title, body: body, actions: actions, level: level, id: id
|
|
39
|
+
card = Plugin::Card.build(source: source, title: title, body: body, actions: actions, level: level, id: id,
|
|
40
|
+
rows: rows)
|
|
36
41
|
command = Thread.current[running_command_key]
|
|
37
42
|
card[:command] = command if command
|
|
38
43
|
@event_routes.route(card, **EventRoutes::CARD_MARKS)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../answer_display"
|
|
4
4
|
require_relative "../hooks/registry"
|
|
5
|
+
require_relative "../peer_presence"
|
|
5
6
|
|
|
6
7
|
module Samagotchi
|
|
7
8
|
class Engine
|
|
@@ -62,6 +63,13 @@ module Samagotchi
|
|
|
62
63
|
@hooks.clear_all
|
|
63
64
|
end
|
|
64
65
|
|
|
66
|
+
# A wait for a peer ran out (PeerWaitExpiry, between turns): the peer
|
|
67
|
+
# bundle's hook says so (ctx.notify).
|
|
68
|
+
# @param peer [String] the peer's name ("claude")
|
|
69
|
+
def peer_wait_ended(peer, minutes: PeerPresence::WAIT_SECONDS / 60)
|
|
70
|
+
@hooks.fire(:peer_wait_ended, { type: :peer_wait_ended, peer: peer.to_s, session_id: @session&.id, minutes: minutes })
|
|
71
|
+
end
|
|
72
|
+
|
|
65
73
|
# ── Reminders API ────────────────────────────────────────────────────────────
|
|
66
74
|
#
|
|
67
75
|
# Each turn injects the reminders due then (#turn_messages,
|