samagotchi 0.186.0 → 0.188.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 +68 -1
- data/bin/chi +4 -0
- data/docs/architecture.md +8 -4
- data/docs/bundles.md +124 -120
- data/docs/cli.md +26 -5
- data/docs/configuration.md +4 -4
- data/docs/context.md +18 -162
- data/docs/guardrails.md +3 -1
- data/docs/hooks.md +2 -1
- data/docs/internals/attached-context.md +19 -37
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/engine.md +2 -2
- data/docs/internals/inline-widgets.md +18 -0
- data/docs/internals/llm-context-forget.md +5 -6
- data/docs/internals/objectives.md +1 -0
- data/docs/internals/pages.md +175 -0
- data/docs/internals/peers.md +149 -0
- data/docs/internals/remote-sessions.md +7 -4
- data/docs/internals/web-frontend.md +65 -40
- data/docs/internals/web-push.md +1 -1
- data/docs/memory.md +8 -1
- data/docs/pages.md +151 -0
- data/docs/peers.md +141 -0
- data/docs/plugins.md +52 -27
- data/docs/sessions.md +8 -4
- data/docs/sub-agent.md +5 -5
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
- data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
- data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
- data/lib/samagotchi/bundles/system/manifest.yml +5 -2
- data/lib/samagotchi/bundles/system/self_map.md +5 -1
- data/lib/samagotchi/bundles/system/skill_pages.md +93 -0
- data/lib/samagotchi/client_id.rb +15 -1
- data/lib/samagotchi/config.rb +8 -7
- data/lib/samagotchi/context_absorber.rb +23 -277
- data/lib/samagotchi/context_sources.rb +17 -69
- data/lib/samagotchi/engine/messages.rb +12 -1
- data/lib/samagotchi/engine/plugins.rb +1 -1
- data/lib/samagotchi/engine.rb +7 -6
- data/lib/samagotchi/engine_peers.rb +0 -3
- data/lib/samagotchi/guardrail_wiring.rb +2 -0
- data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
- data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
- data/lib/samagotchi/inline_widgets.rb +73 -0
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/note_move.rb +3 -1
- data/lib/samagotchi/page_command.rb +243 -0
- data/lib/samagotchi/pages/builder.rb +186 -0
- data/lib/samagotchi/pages/launch.rb +193 -0
- data/lib/samagotchi/pages/runner.rb +154 -0
- data/lib/samagotchi/pages/store.rb +152 -0
- data/lib/samagotchi/pages.rb +119 -0
- data/lib/samagotchi/peer_command.rb +192 -0
- data/lib/samagotchi/peer_continue.rb +99 -0
- data/lib/samagotchi/peer_exchanges.rb +3 -3
- data/lib/samagotchi/peer_mailbox.rb +360 -0
- data/lib/samagotchi/peer_note.rb +208 -0
- data/lib/samagotchi/peer_receipts.rb +247 -0
- data/lib/samagotchi/peer_registry.rb +44 -0
- data/lib/samagotchi/peer_roster.rb +79 -0
- data/lib/samagotchi/peer_say.rb +168 -0
- data/lib/samagotchi/plugin/api.rb +29 -21
- data/lib/samagotchi/plugin/context.rb +7 -0
- data/lib/samagotchi/plugin/loader.rb +3 -3
- data/lib/samagotchi/plugin/peer.rb +175 -64
- data/lib/samagotchi/plugin/peers.rb +70 -0
- data/lib/samagotchi/run_options.rb +3 -1
- data/lib/samagotchi/schedule_command.rb +10 -3
- data/lib/samagotchi/schedule_display.rb +32 -0
- data/lib/samagotchi/session_access/contract.rb +19 -2
- data/lib/samagotchi/session_access/local.rb +132 -14
- data/lib/samagotchi/session_access/remote.rb +4 -2
- data/lib/samagotchi/session_access/remote_peers.rb +75 -0
- data/lib/samagotchi/session_continue.rb +12 -0
- data/lib/samagotchi/session_inbox_delivery.rb +5 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -3
- data/lib/samagotchi/session_manager/removal.rb +2 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -1
- data/lib/samagotchi/session_manager.rb +1 -0
- data/lib/samagotchi/session_stores.rb +17 -0
- data/lib/samagotchi/steer.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
- data/lib/samagotchi/testing/boundary.rb +4 -13
- data/lib/samagotchi/testing/bundle.rb +40 -5
- data/lib/samagotchi/testing/install.rb +4 -4
- data/lib/samagotchi/testing/recording_api.rb +2 -1
- data/lib/samagotchi/tools/context_read.rb +0 -14
- data/lib/samagotchi/tools/list_schedules.rb +8 -3
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +7 -18
- data/lib/samagotchi/web/message_display.rb +4 -2
- data/lib/samagotchi/web/page_routes.rb +116 -0
- data/lib/samagotchi/web/peer_routes.rb +133 -0
- data/lib/samagotchi/web/public/app.js +35 -95
- data/lib/samagotchi/web/public/bubbles.js +2 -2
- data/lib/samagotchi/web/public/cards_place.js +20 -1
- data/lib/samagotchi/web/public/context_chips.js +45 -46
- data/lib/samagotchi/web/public/history_reveal.js +4 -1
- data/lib/samagotchi/web/public/history_shape.js +3 -2
- data/lib/samagotchi/web/public/index.html +16 -0
- data/lib/samagotchi/web/public/notify.js +1 -1
- data/lib/samagotchi/web/public/page_blocks.js +58 -0
- data/lib/samagotchi/web/public/page_links.js +33 -0
- data/lib/samagotchi/web/public/page_model.js +68 -0
- data/lib/samagotchi/web/public/page_route.js +24 -0
- data/lib/samagotchi/web/public/page_table.js +74 -0
- data/lib/samagotchi/web/public/page_table_model.js +76 -0
- data/lib/samagotchi/web/public/page_view.js +219 -0
- data/lib/samagotchi/web/public/pages.css +77 -0
- data/lib/samagotchi/web/public/pages_group.js +65 -0
- data/lib/samagotchi/web/public/peer_chip.js +60 -74
- data/lib/samagotchi/web/public/peer_data.js +13 -11
- data/lib/samagotchi/web/public/peer_links.js +12 -7
- data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
- data/lib/samagotchi/web/public/peer_note.js +7 -3
- data/lib/samagotchi/web/public/peer_text.js +4 -4
- data/lib/samagotchi/web/public/quiet_notes.js +199 -0
- data/lib/samagotchi/web/public/revise_stack.js +4 -3
- data/lib/samagotchi/web/public/session_view.js +2 -2
- data/lib/samagotchi/web/public/stream_handlers.js +3 -2
- data/lib/samagotchi/web/public/turn_block.js +7 -3
- data/lib/samagotchi/web/public/turn_events.js +6 -0
- data/lib/samagotchi/web/public/views.js +161 -0
- data/lib/samagotchi/web/push/attention.rb +3 -2
- data/lib/samagotchi/web/session_access_routes.rb +3 -20
- data/lib/samagotchi/web/viewer.rb +1 -1
- data/lib/samagotchi/worker/leave.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +73 -0
- data/lib/samagotchi/worker/startup.rb +3 -0
- data/lib/samagotchi/worker/wake_turns.rb +20 -5
- data/lib/samagotchi/worker.rb +12 -6
- data/lib/samagotchi/worker_inbound/mail.rb +214 -0
- data/lib/samagotchi/worker_inbound.rb +43 -46
- data/lib/samagotchi/worker_wakes.rb +26 -21
- metadata +39 -2
- data/lib/samagotchi/peer_sources.rb +0 -58
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "peer_mailbox"
|
|
4
|
+
require_relative "peer_receipts"
|
|
5
|
+
|
|
6
|
+
module Samagotchi
|
|
7
|
+
# What chi peer say tells the peer, in chi's own words: the message's
|
|
8
|
+
# number, then what chi did with it (a receipt within the wait), or why it
|
|
9
|
+
# can't say yet, or why the say was refused; then the peer's other
|
|
10
|
+
# messages held and unread now. Built where the say ran (SessionAccess::
|
|
11
|
+
# Local#peer_say: this machine, or the remote's chi web) and drawn by
|
|
12
|
+
# #line, so a --remote say prints the remote's line.
|
|
13
|
+
#
|
|
14
|
+
# +status+: :received, or a refusal (nothing written): :gone (no such
|
|
15
|
+
# session), :deleting, :continued (+next_id+), :not_paired, :old_worker
|
|
16
|
+
# (a live worker without the peer mail), :full (UNTAKEN_MAX unread).
|
|
17
|
+
# +serial+: the message's. +wake+: what the say saw at once, when it
|
|
18
|
+
# didn't wait: :running (a turn runs), :starting, :stopped, :archived,
|
|
19
|
+
# :owned (a one-turn chi run's), :start_failed, :no_turn (no turn yet),
|
|
20
|
+
# :not_running (no worker, none asked), :deleting; nil when it waited.
|
|
21
|
+
# +receipt+: the worker's (PeerReceipts::Receipt) within the wait, nil
|
|
22
|
+
# without one. +earlier+: [[serial, reason]…] of the peer's other held
|
|
23
|
+
# messages. +turns+: the wakes in a row that a held receipt's reason
|
|
24
|
+
# names (peer turns or max wakes), as configured where the say ran.
|
|
25
|
+
PeerSay = Data.define(:status, :serial, :wake, :receipt, :earlier, :next_id, :turns) do
|
|
26
|
+
def initialize(status:, serial: nil, wake: nil, receipt: nil, earlier: [], next_id: nil, turns: nil) = super
|
|
27
|
+
|
|
28
|
+
def received? = status == :received
|
|
29
|
+
|
|
30
|
+
# The line for +peer+ (its name): "#12 received · woke chi".
|
|
31
|
+
def line(peer)
|
|
32
|
+
return PeerSay.refusal(status, peer, next_id) unless received?
|
|
33
|
+
|
|
34
|
+
parts = ["##{serial} received", tail(peer)]
|
|
35
|
+
parts << "also held: #{PeerSay.held_list(earlier)}" unless earlier.empty?
|
|
36
|
+
parts.join(" · ")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_h
|
|
40
|
+
{ "status" => status.to_s, "serial" => serial, "wake" => wake&.to_s, "receipt" => receipt&.to_h,
|
|
41
|
+
"earlier" => earlier, "next_id" => next_id, "turns" => turns }.compact
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The JSON a chi web answered (#to_h); nil for another shape.
|
|
45
|
+
def self.from_h(data)
|
|
46
|
+
return nil unless data.is_a?(Hash) && PeerSay::STATUSES.include?(data["status"].to_s)
|
|
47
|
+
|
|
48
|
+
earlier = Array(data["earlier"]).select { |pair| pair.is_a?(Array) && pair[0].is_a?(Integer) }
|
|
49
|
+
.map { |serial, reason| [serial, reason.to_s] }
|
|
50
|
+
new(status: data["status"].to_sym, serial: (data["serial"] if data["serial"].is_a?(Integer)),
|
|
51
|
+
wake: (data["wake"].to_sym if PeerSay::WAKES.include?(data["wake"].to_s)),
|
|
52
|
+
receipt: PeerReceipts::Receipt.from_h(data["receipt"]), earlier: earlier,
|
|
53
|
+
next_id: data["next_id"]&.to_s, turns: (data["turns"] if data["turns"].is_a?(Integer)))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# The words of a refused say, nothing written.
|
|
57
|
+
def self.refusal(status, peer, next_id)
|
|
58
|
+
case status
|
|
59
|
+
when :gone then "no such session"
|
|
60
|
+
when :deleting then "this session is being deleted"
|
|
61
|
+
when :continued then "this session was continued as #{next_id}: say it there"
|
|
62
|
+
when :not_paired then "not paired: run the pair script"
|
|
63
|
+
when :old_worker then "this session's chi is older than chi peer: restart the session (chi sessions restart)"
|
|
64
|
+
when :full then "chi has #{PeerMailbox::UNTAKEN_MAX} unread messages from #{peer}"
|
|
65
|
+
else status.to_s
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# "#10, #11 (paused)", a run of one reason at a time.
|
|
70
|
+
def self.held_list(earlier)
|
|
71
|
+
earlier.chunk_while { |a, b| a[1] == b[1] }.map do |run|
|
|
72
|
+
"#{run.map { |serial, _| "##{serial}" }.join(", ")} (#{PeerSay::SHORT_WORDS.fetch(run.first[1], run.first[1].tr("_", " "))})"
|
|
73
|
+
end.join(", ")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def tail(peer)
|
|
79
|
+
return PeerSay::AT_ONCE.fetch(wake) if wake
|
|
80
|
+
return "no answer from chi yet" unless receipt
|
|
81
|
+
|
|
82
|
+
case receipt.state
|
|
83
|
+
when "woke" then "woke chi"
|
|
84
|
+
when "noted" then "noted"
|
|
85
|
+
when "read" then "chi is reading it"
|
|
86
|
+
when "ended" then "chi read it (#{receipt.outcome == "canceled" ? "stopped" : receipt.outcome})"
|
|
87
|
+
when "held" then "held: #{held_words(receipt.reason)} · #{PeerSay::HELD_UNTIL.fetch(receipt.reason, PeerSay::HELD_UNTIL["paused"])}"
|
|
88
|
+
else "refused: #{refused_words(receipt.reason, peer)}"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def held_words(reason)
|
|
93
|
+
count = turns || 0
|
|
94
|
+
case reason
|
|
95
|
+
when "peer_turns" then "#{count} peer turn#{"s" unless count == 1} in a row (#{PeerSay::PEER_TURNS_KEY})"
|
|
96
|
+
when "max_wakes" then "#{count} wake turn#{"s" unless count == 1} in a row (session.max_wakes)"
|
|
97
|
+
else PeerSay::HELD_WORDS.fetch(reason, reason.to_s.tr("_", " "))
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def refused_words(reason, peer)
|
|
102
|
+
return "no bundle in that session declares peer #{peer}" if reason == "undeclared"
|
|
103
|
+
|
|
104
|
+
"chi couldn't read that message file"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# The longest a say waits for chi's answer (--wait).
|
|
109
|
+
PeerSay::WAIT_MAX = 30
|
|
110
|
+
# Between two looks at the receipts while it waits.
|
|
111
|
+
PeerSay::POLL_SECONDS = 0.25
|
|
112
|
+
|
|
113
|
+
# What chi peer pair did: :paired (+link+), or a refusal (nothing
|
|
114
|
+
# written): :continued (+next_id+), :old_worker (a live worker without
|
|
115
|
+
# the peer mail).
|
|
116
|
+
PeerPaired = Data.define(:status, :link, :next_id) do
|
|
117
|
+
def initialize(status:, link: nil, next_id: nil) = super
|
|
118
|
+
|
|
119
|
+
def refusal
|
|
120
|
+
case status
|
|
121
|
+
when :continued then "this session was continued as #{next_id}: pair with it"
|
|
122
|
+
when :old_worker then PeerSay.refusal(:old_worker, nil, nil)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
PeerSay::STATUSES = %w[received gone deleting continued not_paired old_worker full].freeze
|
|
128
|
+
PeerSay::WAKES = %w[running starting stopped archived owned start_failed no_turn not_running deleting].freeze
|
|
129
|
+
# The setting a peer_turns hold names (WorkerWakes::PEER_TURNS_KEY: the
|
|
130
|
+
# CLI loads no worker).
|
|
131
|
+
PeerSay::PEER_TURNS_KEY = "peer.turns"
|
|
132
|
+
# What the say says at once, without waiting for a receipt.
|
|
133
|
+
PeerSay::AT_ONCE = {
|
|
134
|
+
running: "chi is in a turn: it reads this when the turn ends",
|
|
135
|
+
starting: "chi is starting",
|
|
136
|
+
stopped: "chi is stopped: it reads this at its next start",
|
|
137
|
+
archived: "this session is archived: it reads this if you reopen it",
|
|
138
|
+
owned: "a one-turn chi run has this session: it reads this at its next start",
|
|
139
|
+
start_failed: "chi's worker isn't running and couldn't be started from here: it reads this at its next start",
|
|
140
|
+
no_turn: "chi hasn't had a turn yet: it reads this with its first",
|
|
141
|
+
not_running: "chi's worker isn't running: it reads this at its next start",
|
|
142
|
+
deleting: "this session is being deleted"
|
|
143
|
+
}.freeze
|
|
144
|
+
# A held receipt's reason in a sentence (peer_turns and max_wakes count).
|
|
145
|
+
PeerSay::HELD_WORDS = {
|
|
146
|
+
"off" => "#{PeerSay::PEER_TURNS_KEY} is 0",
|
|
147
|
+
"paused" => "wakes are paused after a failed wake turn",
|
|
148
|
+
"continue" => "a continue offer waits for the user",
|
|
149
|
+
"queued" => "a message is queued ahead of it",
|
|
150
|
+
"exit" => "chi is exiting",
|
|
151
|
+
"leaving" => "chi's worker is leaving",
|
|
152
|
+
"before_turn" => "a turn is starting"
|
|
153
|
+
}.freeze
|
|
154
|
+
# And until when it waits.
|
|
155
|
+
PeerSay::HELD_UNTIL = {
|
|
156
|
+
"off" => "waits for the user's next message", "paused" => "waits for the user's next message",
|
|
157
|
+
"continue" => "waits for the user's next message", "max_wakes" => "waits for the user's next message",
|
|
158
|
+
"peer_turns" => "waits for the user's next message",
|
|
159
|
+
"queued" => "chi reads it in its next turn", "before_turn" => "chi reads it in that turn",
|
|
160
|
+
"exit" => "it reads this at its next start", "leaving" => "it reads this at its next start"
|
|
161
|
+
}.freeze
|
|
162
|
+
# A reason in a few words (the "also held" list, the chip's).
|
|
163
|
+
PeerSay::SHORT_WORDS = {
|
|
164
|
+
"off" => "off", "paused" => "paused", "continue" => "continue offer", "max_wakes" => "max wakes",
|
|
165
|
+
"peer_turns" => "peer turns", "queued" => "queued", "exit" => "exit", "leaving" => "leaving",
|
|
166
|
+
"before_turn" => "before a turn"
|
|
167
|
+
}.freeze
|
|
168
|
+
end
|
|
@@ -40,7 +40,7 @@ module Samagotchi
|
|
|
40
40
|
"fallback_for:" => "0.35.0", "ctx.fork" => "0.45.0", "ctx.frontend" => "0.49.0",
|
|
41
41
|
"ctx.prompt_files" => "0.60.0", "chi.annotation" => "0.66.0", "chi.toolkit" => "0.66.0",
|
|
42
42
|
"ctx.use_toolkit" => "0.66.0", "ctx.toolkit" => "0.66.0", "ctx.declared_tools" => "0.66.0",
|
|
43
|
-
"chi.tool_source" => "0.67.0", "
|
|
43
|
+
"chi.tool_source" => "0.67.0", "ctx.http" => "0.80.0",
|
|
44
44
|
"ctx.cost" => "0.83.0", "ctx.sessions.children" => "0.34.0", "ctx.load_tools" => "0.99.0",
|
|
45
45
|
"ctx.usage" => "0.100.0", "ctx.sessions.stop" => "0.34.0", "ctx.turn_author" => "0.106.0",
|
|
46
46
|
"ctx.sessions.send(delivery:)" => "0.64.0",
|
|
@@ -60,7 +60,9 @@ module Samagotchi
|
|
|
60
60
|
"ctx.cancel_controller" => "0.183.0",
|
|
61
61
|
"ctx.secrets" => "0.183.0",
|
|
62
62
|
"ctx.sign_in" => "0.183.0",
|
|
63
|
-
"ctx.card(between_turns:)" => "0.183.0"
|
|
63
|
+
"ctx.card(between_turns:)" => "0.183.0",
|
|
64
|
+
"chi.peer" => "0.188.0",
|
|
65
|
+
"ctx.peers" => "0.188.0"
|
|
64
66
|
}.freeze
|
|
65
67
|
|
|
66
68
|
# chi.on's on_error: values. :log (the default) logs a raise and goes
|
|
@@ -85,7 +87,7 @@ module Samagotchi
|
|
|
85
87
|
@inits = []
|
|
86
88
|
@toolkits = []
|
|
87
89
|
@prompt_sections = []
|
|
88
|
-
@
|
|
90
|
+
@peers = []
|
|
89
91
|
@judgments = []
|
|
90
92
|
@tool_source = nil
|
|
91
93
|
@committed = false
|
|
@@ -418,21 +420,26 @@ module Samagotchi
|
|
|
418
420
|
nil
|
|
419
421
|
end
|
|
420
422
|
|
|
421
|
-
#
|
|
422
|
-
#
|
|
423
|
-
#
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
#
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
423
|
+
# Gone: a peer's answers come through its mailbox now (#peer). An
|
|
424
|
+
# older peer bundle that still calls it fails to load with how to
|
|
425
|
+
# upgrade, and chi starts without it (Plugin::Loader).
|
|
426
|
+
def peer_source(*, **)
|
|
427
|
+
raise ArgumentError, "chi.peer_source is gone: upgrade this bundle (chi bundle install #{@bundle} --force)"
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
# A peer agent this bundle speaks for (claude, codex): its messages in
|
|
431
|
+
# the session's mailbox (PeerMailbox, chi peer say) become its notes
|
|
432
|
+
# and may wake chi, on peer.turns. Declared here, in-process,
|
|
433
|
+
# never by a file a peer can write; gone with the bundle. +name+: a
|
|
434
|
+
# lowercase letter, then lowercase letters and digits; the peer's
|
|
435
|
+
# label is its name capitalised.
|
|
436
|
+
def peer(name)
|
|
437
|
+
raise ArgumentError, "this chi has no peer registry (plugins: false)" unless @registries.peer_registry
|
|
438
|
+
|
|
439
|
+
name = @registries.peer_registry.check!(name, bundle: @bundle)
|
|
440
|
+
raise ArgumentError, "peer #{name} is declared twice" if @peers.include?(name)
|
|
441
|
+
|
|
442
|
+
@peers << name
|
|
436
443
|
nil
|
|
437
444
|
end
|
|
438
445
|
|
|
@@ -465,7 +472,7 @@ module Samagotchi
|
|
|
465
472
|
# anything is registered: a raise here leaves the registries as they were.
|
|
466
473
|
def commit!
|
|
467
474
|
check_annotations!
|
|
468
|
-
@
|
|
475
|
+
@peers.each { |name| @registries.peer_registry.check!(name, bundle: @bundle) }
|
|
469
476
|
context = @context
|
|
470
477
|
@commands.each do |cmd|
|
|
471
478
|
block = cmd[:block]
|
|
@@ -503,7 +510,7 @@ module Samagotchi
|
|
|
503
510
|
@registries.prompt_sections.add(bundle: @bundle, name: item[:name], context: context, &item[:block])
|
|
504
511
|
end
|
|
505
512
|
@registries.tool_index.add(@tool_source) if @tool_source
|
|
506
|
-
@
|
|
513
|
+
@peers.each { |name| @registries.peer_registry.declare(name, bundle: @bundle) }
|
|
507
514
|
@judgments.each { |declaration| @registries.judgments.declare(declaration) }
|
|
508
515
|
@committed = true
|
|
509
516
|
end
|
|
@@ -522,7 +529,8 @@ module Samagotchi
|
|
|
522
529
|
def counts = { commands: @commands.size, annotations: @annotations.size, tools: @tools.size, hooks: @hooks.size,
|
|
523
530
|
services: @services.size, inits: @inits.size, toolkits: @toolkits.size,
|
|
524
531
|
prompt_sections: @prompt_sections.size,
|
|
525
|
-
tool_sources: @tool_source ? 1 : 0,
|
|
532
|
+
tool_sources: @tool_source ? 1 : 0, peers: @peers.size,
|
|
533
|
+
judgments: @judgments.size }
|
|
526
534
|
|
|
527
535
|
# Each annotation's command is one #command staged.
|
|
528
536
|
def check_annotations!
|
|
@@ -30,6 +30,7 @@ module Samagotchi
|
|
|
30
30
|
# bundle test kit, don't need.
|
|
31
31
|
autoload :Sessions, File.expand_path("sessions", __dir__)
|
|
32
32
|
autoload :AttachedContext, File.expand_path("attached_context", __dir__)
|
|
33
|
+
autoload :Peers, File.expand_path("peers", __dir__)
|
|
33
34
|
# ctx.http's file needs only json and uri (net/http loads with the first
|
|
34
35
|
# real request); autoloaded so a bundle can name HttpError at load time.
|
|
35
36
|
autoload :Http, File.expand_path("http", __dir__)
|
|
@@ -575,6 +576,12 @@ module Samagotchi
|
|
|
575
576
|
@context ||= AttachedContext.new(@host, bundle: @bundle)
|
|
576
577
|
end
|
|
577
578
|
|
|
579
|
+
# This session's peers: a pairing and a peer's messages (Peers).
|
|
580
|
+
# @return [Peers]
|
|
581
|
+
def peers
|
|
582
|
+
@peers ||= Peers.new(@host, continues: -> { continues })
|
|
583
|
+
end
|
|
584
|
+
|
|
578
585
|
# A single-select question through the question flow. Inside a
|
|
579
586
|
# stream hook's handler (generation_progress) it asks no one (nil).
|
|
580
587
|
# @param effects [Hash{String => Symbol}, nil] what an option does, by
|
|
@@ -26,7 +26,7 @@ module Samagotchi
|
|
|
26
26
|
# +init+ adds a chi.init task (Engine#add_init_task); +toolkits+ is the
|
|
27
27
|
# Engine's list of the plugins' toolkits (chi.toolkit: Toolkit::Kit);
|
|
28
28
|
# +tool_index+ the Engine's Tools::ToolIndex (chi.tool_source);
|
|
29
|
-
# +
|
|
29
|
+
# +peer_registry+ the Engine's PeerRegistry (chi.peer);
|
|
30
30
|
# +prompt_sections+ the Engine's PromptSections (chi.prompt_section),
|
|
31
31
|
# +prompt_changed+ rebuilds its system prompts (chi.prompt_changed!),
|
|
32
32
|
# +judgments+ the Engine's SystemOne::Judgments (chi.judgment),
|
|
@@ -34,8 +34,8 @@ module Samagotchi
|
|
|
34
34
|
# raises, with effect: :deny for a fail-closed one
|
|
35
35
|
# (HookRoutes#plugin_hook_failed).
|
|
36
36
|
Registries = Struct.new(:commands, :tools, :hooks, :context_for, :tools_changed, :services, :stage_tools, :init,
|
|
37
|
-
:toolkits, :tool_index, :
|
|
38
|
-
:hook_failed, keyword_init: true)
|
|
37
|
+
:toolkits, :tool_index, :prompt_sections, :prompt_changed, :judgments,
|
|
38
|
+
:hook_failed, :peer_registry, keyword_init: true)
|
|
39
39
|
|
|
40
40
|
# Loads installed bundles' plugins (manifest plugin: {file:, sha256:})
|
|
41
41
|
# into an Engine's registries (docs/plugins.md).
|