samagotchi 0.183.0 → 0.185.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 +84 -1
- data/docs/architecture.md +12 -11
- data/docs/bundles.md +63 -36
- data/docs/cli.md +10 -1
- data/docs/configuration.md +3 -2
- data/docs/context.md +76 -10
- data/docs/guardrails.md +7 -2
- data/docs/hooks.md +1 -0
- data/docs/internals/block-renderers.md +4 -2
- data/docs/internals/bridge.md +7 -3
- data/docs/internals/bundles.md +6 -2
- data/docs/internals/engine.md +2 -1
- data/docs/internals/llm-context-forget.md +6 -0
- data/docs/internals/participants.md +5 -2
- data/docs/internals/prompt-caching.md +8 -1
- data/docs/internals/remote-sessions.md +22 -4
- data/docs/internals/session-lifecycle.md +1 -1
- data/docs/internals/web-frontend.md +37 -15
- data/docs/internals/web-push.md +11 -0
- data/docs/internals/working-set.md +238 -6
- data/docs/mcp-server.md +11 -3
- data/docs/memory.md +2 -1
- data/docs/plugins.md +6 -6
- data/docs/scheduling.md +19 -0
- data/docs/sessions.md +13 -3
- data/docs/sub-agent.md +48 -3
- data/docs/thin-clients.md +38 -12
- data/lib/samagotchi/agent_caller.rb +97 -0
- data/lib/samagotchi/bridge.rb +7 -7
- data/lib/samagotchi/bridge_client.rb +12 -4
- data/lib/samagotchi/bundle_command/check.rb +20 -2
- data/lib/samagotchi/bundle_manifest.rb +5 -1
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +14 -8
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +3 -3
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +49 -30
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +2 -2
- data/lib/samagotchi/bundles/claude-peer/scripts/pair-remote +123 -0
- data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +11 -3
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +10 -8
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +3 -3
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +29 -8
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +1 -1
- data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +11 -3
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/mcp/http_client.rb +96 -54
- data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/self_map.md +9 -2
- data/lib/samagotchi/client_id.rb +61 -1
- data/lib/samagotchi/command_intake.rb +16 -8
- data/lib/samagotchi/context_absorber.rb +212 -46
- data/lib/samagotchi/delivery.rb +15 -0
- data/lib/samagotchi/driver_command.rb +68 -0
- data/lib/samagotchi/engine/block_fix.rb +2 -2
- data/lib/samagotchi/engine/session.rb +14 -6
- data/lib/samagotchi/engine/turn_helpers.rb +4 -3
- data/lib/samagotchi/engine.rb +13 -5
- data/lib/samagotchi/engine_peers.rb +6 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +1 -1
- data/lib/samagotchi/mcp_command.rb +7 -2
- data/lib/samagotchi/mcp_server/http.rb +3 -3
- data/lib/samagotchi/mcp_server/protocol.rb +23 -4
- data/lib/samagotchi/mcp_server/stdio.rb +1 -0
- data/lib/samagotchi/mcp_server/tools.rb +11 -4
- data/lib/samagotchi/model_notes.rb +34 -12
- data/lib/samagotchi/objectives_track.rb +2 -1
- data/lib/samagotchi/owner_prompt.rb +5 -1
- data/lib/samagotchi/parent_report.rb +9 -5
- data/lib/samagotchi/plugin/peer.rb +10 -4
- 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/reply_wait.rb +16 -4
- data/lib/samagotchi/schedule_command.rb +18 -4
- data/lib/samagotchi/schedules.rb +49 -14
- data/lib/samagotchi/send_command/parent_gate.rb +3 -1
- data/lib/samagotchi/send_command.rb +45 -8
- data/lib/samagotchi/session.rb +9 -1
- data/lib/samagotchi/session_access/ask.rb +58 -14
- data/lib/samagotchi/session_access/contract.rb +2 -0
- data/lib/samagotchi/session_access/exchange.rb +5 -2
- data/lib/samagotchi/session_access/local.rb +13 -3
- data/lib/samagotchi/session_access/remote.rb +18 -2
- data/lib/samagotchi/session_access.rb +4 -2
- data/lib/samagotchi/session_command_catalog.rb +8 -0
- data/lib/samagotchi/session_commands.rb +9 -0
- data/lib/samagotchi/session_continue.rb +4 -1
- data/lib/samagotchi/session_inbox.rb +17 -0
- data/lib/samagotchi/session_inbox_delivery.rb +4 -2
- data/lib/samagotchi/session_manager/delivery.rb +58 -9
- data/lib/samagotchi/session_manager/spawn.rb +7 -1
- data/lib/samagotchi/steer.rb +95 -20
- data/lib/samagotchi/system_prompt.rb +196 -161
- data/lib/samagotchi/terminal_ui/formatting.rb +12 -2
- data/lib/samagotchi/tool_activity.rb +4 -0
- data/lib/samagotchi/tool_declarations.rb +22 -1
- data/lib/samagotchi/tool_names.rb +4 -0
- data/lib/samagotchi/toolkit.rb +3 -2
- data/lib/samagotchi/tools/ask_session.rb +208 -0
- data/lib/samagotchi/tools/builtin_calls.rb +1 -0
- data/lib/samagotchi/tools/builtins.rb +5 -0
- data/lib/samagotchi/tools/memory.rb +11 -3
- data/lib/samagotchi/turn_checkpoint.rb +19 -2
- data/lib/samagotchi/turn_stages/context_judge.rb +3 -1
- data/lib/samagotchi/turn_stages/objectives.rb +4 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +3 -0
- data/lib/samagotchi/turn_stages/warmup.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/visitor.rb +37 -0
- data/lib/samagotchi/web/app.rb +2 -3
- data/lib/samagotchi/web/ask_routes.rb +95 -23
- data/lib/samagotchi/web/mcp_route.rb +7 -4
- data/lib/samagotchi/web/message_display.rb +15 -2
- data/lib/samagotchi/web/public/app.js +1 -1
- data/lib/samagotchi/web/public/block_fix.js +11 -3
- data/lib/samagotchi/web/public/delete_sheet.js +20 -18
- data/lib/samagotchi/web/public/history_shape.js +3 -1
- data/lib/samagotchi/web/public/index.html +8 -0
- data/lib/samagotchi/web/public/peer_links.js +27 -4
- data/lib/samagotchi/web/public/peer_note.js +19 -3
- data/lib/samagotchi/web/public/peer_text.js +45 -0
- data/lib/samagotchi/web/public/picture_regions.js +2 -2
- data/lib/samagotchi/web/public/removal_sheet_model.js +3 -4
- data/lib/samagotchi/web/public/running_tasks.js +0 -16
- data/lib/samagotchi/web/public/session_actions.js +0 -9
- data/lib/samagotchi/web/public/turn_events.js +19 -0
- data/lib/samagotchi/web/public/working_set_view.js +178 -23
- 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_control.rb +1 -1
- data/lib/samagotchi/web/session_create.rb +11 -7
- data/lib/samagotchi/web/session_hub.rb +26 -4
- data/lib/samagotchi/web/working_set_routes.rb +93 -5
- data/lib/samagotchi/worker/command_queue.rb +5 -2
- data/lib/samagotchi/worker/senders.rb +79 -0
- data/lib/samagotchi/worker.rb +21 -18
- data/lib/samagotchi/worker_inbound.rb +12 -4
- data/lib/samagotchi/worker_link.rb +2 -2
- data/lib/samagotchi/worker_participant_gate.rb +1 -3
- data/lib/samagotchi/worker_wakes.rb +12 -0
- 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 +13 -1
data/docs/thin-clients.md
CHANGED
|
@@ -33,19 +33,32 @@ another link ran it. Body fields:
|
|
|
33
33
|
|
|
34
34
|
- `prompt` (required): the message, at most 16 KiB. A terminal-only command such
|
|
35
35
|
as `/stats` is refused (400 `local_command`); a session command such as
|
|
36
|
-
`/model x` runs and answers `{"status": "command"}`, with no token.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
`/model x` runs and answers `{"status": "command"}`, with no token.
|
|
37
|
+
`/continue yes` on a session whose turn ran out of steps, while its worker
|
|
38
|
+
runs, continues that turn and answers as a message does (its reply, or a
|
|
39
|
+
`token`); if the offer was answered elsewhere first you get what came of it.
|
|
40
|
+
A continue offer still shown as a question (409 `waiting`) is answered
|
|
41
|
+
through `/answer`.
|
|
42
42
|
- `timeout`: seconds to wait for the answer, at most 30 (the default).
|
|
43
43
|
- `queue`: `true` (the default) means a session running a turn queues your
|
|
44
44
|
message as its own turn, and you get that turn's answer. `false` refuses a
|
|
45
45
|
running session with 409 `busy`.
|
|
46
46
|
- `client_id`: who is asking. Leave it out for yourself (the line is the
|
|
47
|
-
owner's, as from the web composer). An agent sends `"
|
|
47
|
+
owner's, as from the web composer). An agent sends `"agent:NAME"`: see
|
|
48
48
|
[An agent over HTTP](#an-agent-over-http).
|
|
49
|
+
- `request_id`: your own key for this ask, 1 to 128 printable ASCII
|
|
50
|
+
characters. Send the same ask again with the same `request_id` (a retry
|
|
51
|
+
after a dropped connection) and you get the first one's turn instead of
|
|
52
|
+
sending it again. It is for messages only: a session command with one (a
|
|
53
|
+
line starting `!`, or `/name` then a space or nothing) is 400
|
|
54
|
+
`invalid_ask`; a path such as `/Users/me/a.rb fails` is a message. It holds
|
|
55
|
+
while that turn is running, queued, or has replied or ended, and otherwise
|
|
56
|
+
while the session's worker remembers the key; it does not hold across a
|
|
57
|
+
continue to a new link. Use a new key for a new message: while the first
|
|
58
|
+
turn is running, queued, or has replied or ended, the same key with another
|
|
59
|
+
prompt gets that turn's answer and nothing is sent; otherwise a worker that
|
|
60
|
+
remembers the key answers 409 `enqueued_id_conflict`. An answer that echoes
|
|
61
|
+
`request_id` means chi web used it (an older chi web ignores the field).
|
|
49
62
|
|
|
50
63
|
A question that is waiting for an answer refuses the ask with 409 `waiting` and
|
|
51
64
|
the `question`. Answer it first (below).
|
|
@@ -54,9 +67,9 @@ the `question`. Answer it first (below).
|
|
|
54
67
|
|
|
55
68
|
Each call answers within **35 seconds** of its request, whatever it waits for
|
|
56
69
|
(a continue in flight, a worker starting, the answer), so a proxy or a Shortcut
|
|
57
|
-
with a 60 s limit is safe.
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
with a 60 s limit is safe. A worker that hangs while it takes the message in
|
|
71
|
+
is given at most 8 s past that, then the call answers 504 `worker_timeout`; the
|
|
72
|
+
message was not taken. A turn still running then answers
|
|
60
73
|
`"status": "timeout"` with a `"token": "w1.…"`. Send that token back until the
|
|
61
74
|
status is something else:
|
|
62
75
|
|
|
@@ -101,6 +114,9 @@ The answer goes in before the wait starts, so a wait that fails afterwards
|
|
|
101
114
|
`wait_failed`, and a `detail`) in place of `reply`. Don't answer again (that
|
|
102
115
|
would be 409): ask or wait on the session instead.
|
|
103
116
|
|
|
117
|
+
Ask waits also return 409 `busy` / `waiting` / `continuing` / `owned_by_tui`, or 503
|
|
118
|
+
`server_stopping` (ask again).
|
|
119
|
+
|
|
104
120
|
## An agent over HTTP
|
|
105
121
|
|
|
106
122
|
An agent (Claude Code, Codex, a script acting on its own) should drive chi
|
|
@@ -111,9 +127,16 @@ the sender for it. An MCP host can add chi as an MCP server instead
|
|
|
111
127
|
on chi web), which names it too. An agent that calls these routes itself must name itself
|
|
112
128
|
the same way:
|
|
113
129
|
|
|
114
|
-
- `"client_id": "
|
|
130
|
+
- `"client_id": "agent:NAME"` on every ask (and on `POST /api/sessions`), NAME
|
|
131
|
+
lowercase letters, digits, `-` and `_`: its turns are labelled "agent NAME" and
|
|
132
|
+
it is a driver or a visitor as `chi send`'s agents are ([driver and
|
|
133
|
+
visitor](sub-agent.md#an-agents-messages-driver-and-visitor)); `POST
|
|
134
|
+
/api/sessions` also takes `"driver": "agent:NAME"`;
|
|
115
135
|
- `"client_id": "cli:answer"` on every answer.
|
|
116
136
|
|
|
137
|
+
`"cli:send"` still works and is held the same way, but it is the owner's row: it
|
|
138
|
+
restarts a stopped session and runs `!` lines.
|
|
139
|
+
|
|
117
140
|
Then `guardrails.parent_answers` applies as it does to `chi send` and `chi
|
|
118
141
|
answer` ([Answers from a parent agent](guardrails.md#answers-from-a-parent-agent)):
|
|
119
142
|
a `/continue yes` is held to it (403 `parent_continue_refused`), a
|
|
@@ -134,7 +157,10 @@ answers the first turn.
|
|
|
134
157
|
1. **Dictate Text** (or **Ask for Input**).
|
|
135
158
|
2. **Get Contents of URL**: `https://<your chi web>/api/sessions/<id>/ask`,
|
|
136
159
|
method POST, header `Authorization: Bearer <token>`, JSON body `prompt` =
|
|
137
|
-
the dictated text.
|
|
160
|
+
the dictated text. To survive a dropped connection, first **Set Variable**
|
|
161
|
+
`key` to **Current Date** formatted with seconds, send `request_id` = `key`,
|
|
162
|
+
and if the step fails (no `status` in the answer) run it again with the same
|
|
163
|
+
`key`: the retry answers the first one's turn instead of sending it twice.
|
|
138
164
|
3. **Repeat** while the answer's `status` is `timeout`: **Get Contents of URL**
|
|
139
165
|
for `…/api/sessions/<session_id>/wait` with the JSON body `token` = the
|
|
140
166
|
answer's `token`.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "client_id"
|
|
4
|
+
require_relative "session_paths"
|
|
5
|
+
|
|
6
|
+
module Samagotchi
|
|
7
|
+
# Who an agent's message goes in as: the one seat that names the client
|
|
8
|
+
# id chi send, Ask#agent_line (chi web's ask, the MCP tools on this
|
|
9
|
+
# machine) and the MCP tools to another machine send a message with. An
|
|
10
|
+
# agent is named by --as, else by the marker its process carries
|
|
11
|
+
# (Guardrails::ParentApprovals::AGENT_MARKERS); none is the owner (a pipe
|
|
12
|
+
# alone is not a marker: the owner's own script stays the owner's). The id
|
|
13
|
+
# is self-declared, as chi send's is: a convention for an honest agent,
|
|
14
|
+
# not a security boundary. No Engine, so a command loads it cheaply.
|
|
15
|
+
module AgentCaller
|
|
16
|
+
# A name: lowercase letters, digits, - and _ (ClientId::AGENT_NAME_MAX).
|
|
17
|
+
NAME = /\A[a-z0-9_-]{1,#{ClientId::AGENT_NAME_MAX}}\z/
|
|
18
|
+
# The name a marker gives when its value is not one.
|
|
19
|
+
FALLBACK = "agent"
|
|
20
|
+
# chi's own marker (execute and tasks set it, the model can't change it):
|
|
21
|
+
# its session's first 8 characters, or "chi" for a run with no session.
|
|
22
|
+
# Guardrails::ParentApprovals::PARENT_SESSION_ENV's (a spec keeps them
|
|
23
|
+
# the same: that file is too big a load for chi send's start).
|
|
24
|
+
PARENT_SESSION = "SAMAGOTCHI_PARENT_SESSION"
|
|
25
|
+
# The vendors' markers, in order, and the name each gives (nil: its
|
|
26
|
+
# value, cleaned).
|
|
27
|
+
VENDOR_MARKERS = [%w[CLAUDECODE claude], %w[CODEX_THREAD_ID codex], ["AI_AGENT", nil]].freeze
|
|
28
|
+
|
|
29
|
+
module_function
|
|
30
|
+
|
|
31
|
+
# +name+ as an agent's name (lowercased), or nil when it isn't one: the
|
|
32
|
+
# name reaches a header the model reads, so it is never free text.
|
|
33
|
+
def clean(name)
|
|
34
|
+
text = name.to_s.strip.downcase
|
|
35
|
+
text.match?(NAME) ? text : nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The caller's name, or nil for the owner: chi's own marker first, even
|
|
39
|
+
# over +as+ (a worker inherits its spawner's environment, so a chi
|
|
40
|
+
# session's own model may carry CLAUDECODE too); then +as+; then the
|
|
41
|
+
# vendors' markers.
|
|
42
|
+
# @param as [String, nil] chi send --as's (cleaned before: #clean)
|
|
43
|
+
def name(env: ENV, as: nil)
|
|
44
|
+
parent = env.fetch(PARENT_SESSION, "").to_s.strip
|
|
45
|
+
return parent_name(parent) unless parent.empty?
|
|
46
|
+
return as unless as.to_s.empty?
|
|
47
|
+
|
|
48
|
+
VENDOR_MARKERS.each do |key, given|
|
|
49
|
+
value = env.fetch(key, "").to_s.strip
|
|
50
|
+
next if value.empty?
|
|
51
|
+
|
|
52
|
+
return given || clean(value) || FALLBACK
|
|
53
|
+
end
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Whether chi's own marker names this process (chi send --as is ignored
|
|
58
|
+
# there).
|
|
59
|
+
def inside_chi?(env: ENV) = !env.fetch(PARENT_SESSION, "").to_s.strip.empty?
|
|
60
|
+
|
|
61
|
+
# chi send's sender from its --as (+as+, as typed) and +env+: the name
|
|
62
|
+
# (nil: the owner), a usage error for an --as that is no name, and a note
|
|
63
|
+
# for stderr when --as is ignored (inside a chi session).
|
|
64
|
+
# @return [Array(String, String, String)] name, error, note (each may be nil)
|
|
65
|
+
def send_name(as:, env: ENV)
|
|
66
|
+
return [name(env: env), nil, nil] if as.nil?
|
|
67
|
+
|
|
68
|
+
clean = clean(as)
|
|
69
|
+
return [nil, "--as takes a name: lowercase letters, digits, - and _, up to #{ClientId::AGENT_NAME_MAX}, not #{as}", nil] unless clean
|
|
70
|
+
|
|
71
|
+
note = "--as ignored: this runs inside a chi session, which names the sender" if inside_chi?(env: env)
|
|
72
|
+
[name(env: env, as: clean), nil, note]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# The client id a message from this caller goes in as: an agent's
|
|
76
|
+
# (agent:<name>), or chi send's, the owner's, with no name.
|
|
77
|
+
# @param name [String, nil] the agent's name (#name)
|
|
78
|
+
# @return [String]
|
|
79
|
+
def send_id(name: nil)
|
|
80
|
+
name.to_s.empty? ? ClientId::CLI_SEND : ClientId.agent(name)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# A /continue yes from +id+ (a parent line, ClientId.parent_line?) goes
|
|
84
|
+
# in as chi answer's, held to guardrails.parent_answers; any other id as
|
|
85
|
+
# given.
|
|
86
|
+
def continue_id(id) = ClientId.parent_line?(id) ? ClientId::CLI_ANSWER : id
|
|
87
|
+
|
|
88
|
+
# "chi" (Tools::Builtins.parent_env's, a run with no session) or
|
|
89
|
+
# anything not an id: "chi".
|
|
90
|
+
def parent_name(value)
|
|
91
|
+
return "chi" if value == "chi" || !SessionPaths.valid_id?(value)
|
|
92
|
+
|
|
93
|
+
clean("chi-#{value[0, 8]}") || "chi"
|
|
94
|
+
end
|
|
95
|
+
private_class_method :parent_name
|
|
96
|
+
end
|
|
97
|
+
end
|
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -809,7 +809,8 @@ module Samagotchi
|
|
|
809
809
|
SessionInbox::UNQUEUE_FEATURE, Delivery::REVIEW_FEATURE, Delivery::PAIR_FEATURE, TurnDrawings::FEATURE,
|
|
810
810
|
WorkerLink::ACTIVITY_FEATURE, ObjectivesTrack::FEATURE, Delivery::OWN_TURN_STEER_FEATURE,
|
|
811
811
|
Delivery::CANCEL_TURN_ID_FEATURE, ReviseAnchor::PARTICIPANT_FEATURE, Delivery::PARTICIPANT_ID_FEATURE,
|
|
812
|
-
WorkingSet::ITEM_FEATURE, BlockFix::FEATURE
|
|
812
|
+
WorkingSet::ITEM_FEATURE, BlockFix::FEATURE, Delivery::AGENT_FEATURE,
|
|
813
|
+
Delivery::ASK_FEATURE].freeze
|
|
813
814
|
|
|
814
815
|
# The routes, by method and what follows /session/:id/: a handler takes
|
|
815
816
|
# the session id and the request body and returns [headers, status, body].
|
|
@@ -1095,9 +1096,8 @@ module Samagotchi
|
|
|
1095
1096
|
client_id = fetched(parsed, "client_id")
|
|
1096
1097
|
return UNNAMED_COMMAND_REPLY if client_id.to_s.strip.empty?
|
|
1097
1098
|
|
|
1098
|
-
#
|
|
1099
|
-
|
|
1100
|
-
unless CommandIntake.allowed?(client_id)
|
|
1099
|
+
# As for a command sent as a message (CommandIntake: refused? first, then allowed?).
|
|
1100
|
+
if CommandIntake.refused?(line, client_id) || !CommandIntake.allowed?(client_id)
|
|
1101
1101
|
Log.warn(:bridge, "command_refused", client_id: client_id)
|
|
1102
1102
|
return [{}, 403, { error: CommandIntake::REFUSED_ERROR, detail: CommandIntake.refusal(line) }]
|
|
1103
1103
|
end
|
|
@@ -1342,11 +1342,11 @@ module Samagotchi
|
|
|
1342
1342
|
# schedule's or a plugin's /word line is a prompt, its shell line
|
|
1343
1343
|
# refused (403, nothing queued).
|
|
1344
1344
|
if images.empty? && @on_command && command_registry.command?(prompt.to_s)
|
|
1345
|
-
if CommandIntake.
|
|
1346
|
-
return queue_command_request(sid, prompt.to_s.strip, client_id: client_id, deadline: deadline, author: author)
|
|
1347
|
-
elsif CommandIntake.shell_line?(prompt)
|
|
1345
|
+
if CommandIntake.refused?(prompt, client_id) # an agent's ! line too: before allowed? would queue it
|
|
1348
1346
|
Log.warn(:bridge, "shell_line_refused", client_id: client_id)
|
|
1349
1347
|
return [{}, 403, { error: CommandIntake::REFUSED_ERROR, detail: CommandIntake::REFUSED }]
|
|
1348
|
+
elsif CommandIntake.allowed?(client_id)
|
|
1349
|
+
return queue_command_request(sid, prompt.to_s.strip, client_id: client_id, deadline: deadline, author: author)
|
|
1350
1350
|
end
|
|
1351
1351
|
end
|
|
1352
1352
|
return CommandIntake::PRIVATE_REFUSED if command_registry.private_args?(prompt.to_s) # never a message
|
|
@@ -89,11 +89,11 @@ module Samagotchi
|
|
|
89
89
|
# new secret) is reached by a client made after it, never by hand.
|
|
90
90
|
# @param sidecar [WorkerSidecar, nil]
|
|
91
91
|
# @return [BridgeClient, nil] nil without a sidecar
|
|
92
|
-
def self.for_sidecar(session_id, sidecar, host: HOST, read_timeout: READ_TIMEOUT)
|
|
92
|
+
def self.for_sidecar(session_id, sidecar, host: HOST, read_timeout: READ_TIMEOUT, deadline_margin: nil)
|
|
93
93
|
return nil unless sidecar
|
|
94
94
|
|
|
95
95
|
new(session_id: session_id, port: sidecar.port, secret: sidecar.secret, host: host, read_timeout: read_timeout,
|
|
96
|
-
features: sidecar.features)
|
|
96
|
+
features: sidecar.features, deadline_margin: deadline_margin)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
# How often a wait for a new worker's Bridge looks: a missing sidecar is
|
|
@@ -131,7 +131,11 @@ module Samagotchi
|
|
|
131
131
|
# none); from the worker's sidecar (.for_sidecar), never typed
|
|
132
132
|
# @param read_timeout [Numeric] see READ_TIMEOUT
|
|
133
133
|
# @param features [Array<String>] the sidecar's (#features)
|
|
134
|
-
|
|
134
|
+
# @param deadline_margin [Numeric, nil] the fewest seconds the deadline
|
|
135
|
+
# leaves before the read timeout for the write and the reply (a short
|
|
136
|
+
# read's DEADLINE_SHARE leaves under a second); nil: the share alone
|
|
137
|
+
def initialize(session_id:, port:, secret:, host: HOST, read_timeout: READ_TIMEOUT, features: [], deadline_margin: nil)
|
|
138
|
+
@deadline_margin = deadline_margin
|
|
135
139
|
@features = Array(features).freeze
|
|
136
140
|
@session_id = session_id
|
|
137
141
|
@port = port
|
|
@@ -442,7 +446,11 @@ module Samagotchi
|
|
|
442
446
|
# When this client stops waiting for a reply, as epoch seconds (see
|
|
443
447
|
# DEADLINE_SHARE). Wall clock: the worker runs on this machine and reads
|
|
444
448
|
# the same one.
|
|
445
|
-
def deadline
|
|
449
|
+
def deadline
|
|
450
|
+
allowed = @read_timeout * DEADLINE_SHARE
|
|
451
|
+
allowed = [allowed, @read_timeout - @deadline_margin].min if @deadline_margin
|
|
452
|
+
(Time.now.to_f + allowed).round(3)
|
|
453
|
+
end
|
|
446
454
|
|
|
447
455
|
def post(path, payload, read_body:, read_timeout: @read_timeout)
|
|
448
456
|
sock = TCPSocket.new(@host, @port)
|
|
@@ -208,8 +208,7 @@ module Samagotchi
|
|
|
208
208
|
|
|
209
209
|
# @return [Boolean] whether a listed file is missing
|
|
210
210
|
def check_files(manifest)
|
|
211
|
-
listed = manifest
|
|
212
|
-
manifest.scripts.keys.map { |s| File.join("scripts", s) }
|
|
211
|
+
listed = listed_files(manifest)
|
|
213
212
|
missing = listed.reject { |rel| File.file?(path(rel)) }
|
|
214
213
|
missing.each do |rel|
|
|
215
214
|
add(:error, :"missing-file", "manifest.yml", "lists #{rel}, which isn't in the bundle", line: manifest_line(rel),
|
|
@@ -218,6 +217,11 @@ module Samagotchi
|
|
|
218
217
|
!missing.empty?
|
|
219
218
|
end
|
|
220
219
|
|
|
220
|
+
def listed_files(manifest)
|
|
221
|
+
manifest.files.keys + manifest.plugin_files.map(&:first) +
|
|
222
|
+
manifest.scripts.keys.map { |s| File.join("scripts", s) }
|
|
223
|
+
end
|
|
224
|
+
|
|
221
225
|
# What an install leaves out: a memory files: doesn't list (by
|
|
222
226
|
# MemoryFiles' rules), a plugin or script the manifest doesn't name.
|
|
223
227
|
def check_unlisted(manifest)
|
|
@@ -231,6 +235,14 @@ module Samagotchi
|
|
|
231
235
|
Dir.glob(path("*.rb")).map { |f| File.basename(f) }.sort.each do |name|
|
|
232
236
|
unlisted(name, "plugin: parts:") unless plugin_files.include?(name)
|
|
233
237
|
end
|
|
238
|
+
listed = listed_files(manifest)
|
|
239
|
+
Dir.glob(path("**/*.rb")).sort.each do |file|
|
|
240
|
+
rel = file.delete_prefix("#{@dir}/")
|
|
241
|
+
next unless rel.include?("/")
|
|
242
|
+
next if rel.start_with?("spec/", "test/") || listed.include?(rel)
|
|
243
|
+
|
|
244
|
+
unlisted_nested_plugin_part(rel, manifest.plugin[:file])
|
|
245
|
+
end
|
|
234
246
|
elsif File.file?(path("plugin.rb"))
|
|
235
247
|
unlisted("plugin.rb", "plugin:")
|
|
236
248
|
end
|
|
@@ -239,6 +251,12 @@ module Samagotchi
|
|
|
239
251
|
end
|
|
240
252
|
end
|
|
241
253
|
|
|
254
|
+
def unlisted_nested_plugin_part(rel, plugin_file)
|
|
255
|
+
add(:warn, :unlisted, rel,
|
|
256
|
+
"manifest.yml's plugin: parts: doesn't list it, so an install leaves it out; parts sit next to #{plugin_file}",
|
|
257
|
+
fix: "move it up as #{File.basename(rel)} and list it under plugin: parts:, then chi bundle check --fix")
|
|
258
|
+
end
|
|
259
|
+
|
|
242
260
|
def unlisted(rel, key)
|
|
243
261
|
add(:warn, :unlisted, rel, "manifest.yml's #{key} doesn't list it, so an install leaves it out",
|
|
244
262
|
fix: "list it under #{key}, then chi bundle check --fix")
|
|
@@ -578,7 +578,11 @@ module Samagotchi
|
|
|
578
578
|
raw.each_with_object({}) do |(name, sha), parts|
|
|
579
579
|
name = name.to_s.strip
|
|
580
580
|
unless name.match?(PLUGIN_FILE)
|
|
581
|
-
|
|
581
|
+
message = "plugin parts: #{name.inspect} isn't a .rb file name in the bundle's top directory"
|
|
582
|
+
if name.include?("/") && name.end_with?(".rb")
|
|
583
|
+
message = "#{message}: parts sit next to #{plugin_file} (move #{name} up and list it as #{File.basename(name)})"
|
|
584
|
+
end
|
|
585
|
+
raise ValidationError, message
|
|
582
586
|
end
|
|
583
587
|
raise ValidationError, "plugin parts: #{name} is the plugin file itself" if name == plugin_file
|
|
584
588
|
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: claude-peer
|
|
3
|
-
version: 0.
|
|
3
|
+
version: 0.6.1
|
|
4
4
|
scope: system
|
|
5
|
-
description: "Pair this session with a Claude Code session you work with: the claude_send tool and /claude send it a part of the work (a plan step, a diff, a finding) to validate or as context, and Claude's answer comes back as
|
|
5
|
+
description: "Pair this session with a Claude Code session you work with: the claude_send tool and /claude send it a part of the work (a plan step, a diff, a finding) to validate or as context, and Claude's answer comes back as a note with its text (claude-outbox); /claude install-skill installs Claude's chi-peer skill, which pairs"
|
|
6
6
|
trust_level: reviewed
|
|
7
7
|
files:
|
|
8
8
|
skill_claude_peer.md:
|
|
9
|
-
sha256: sha256:
|
|
10
|
-
description: "Send a part of the work to the paired Claude Code session (claude_send): only when the user asks, or to reply to its answer in a peer turn; validate, context or question; Claude's answer comes as
|
|
9
|
+
sha256: sha256:cd8ba89d5cbe37a90c85ad8eb354dfc3d2651fc6150fe3047fd4b5ed6a73a004
|
|
10
|
+
description: "Send a part of the work to the paired Claude Code session (claude_send): only when the user asks, or to reply to its answer in a peer turn; validate, context or question; Claude's answer comes as a note with its text (claude-outbox)"
|
|
11
11
|
plugin:
|
|
12
12
|
file: plugin.rb
|
|
13
|
-
sha256: sha256:
|
|
13
|
+
sha256: sha256:a1020fd0ce9e8d68918605a23562dc1039f65d6f45b9ceb00e4f011cd000072a
|
|
14
14
|
scripts:
|
|
15
|
-
pair: sha256:
|
|
16
|
-
|
|
15
|
+
pair-remote: sha256:d7681f87a194e540b629564f84cad9f2d0a763197502c74614276ef88a8920cc
|
|
16
|
+
pair: sha256:23d79bb8cf37517d20d15b6716f6666038858a4c5c09d3b85085d1e98475d6b3
|
|
17
|
+
chi-peer-SKILL.md: sha256:8d2266d3a13e9fe8091e0e431c08555eaf1b48fe154a6250ce171c8b0bd2d947
|
|
17
18
|
# The plugin needs Samagotchi::Plugin::Peer and chi.peer_source (chi 0.67.0).
|
|
18
19
|
# An agreeing answer's closing wake (the skills say an OK wakes chi once)
|
|
19
20
|
# and the plugin's OUTBOX (Plugin::Peer's rename of REVIEW) need chi 0.70.0.
|
|
20
21
|
# The skill's `re` (the answered send) needs nothing newer: an older chi
|
|
21
22
|
# ignores the unknown key, and sends no `ref:` line for the skill to echo.
|
|
22
|
-
requires_chi: ">= 0.
|
|
23
|
+
requires_chi: ">= 0.185.0"
|
|
24
|
+
# The next chi: the installed skill's __CHI_PEER_PAIR_REMOTE__ placeholder
|
|
25
|
+
# (scripts/pair-remote's path), which only its Plugin::Peer
|
|
26
|
+
# #skill_target_and_text fills; an older chi would install the skill with it
|
|
27
|
+
# left in. Also the memory and the tool's words say a peer's note holds its
|
|
28
|
+
# text (chi's ContextAbsorber peer block), which the next chi adds.
|
|
@@ -75,9 +75,9 @@ class Plugin < Samagotchi::Plugin::Peer
|
|
|
75
75
|
"context), for Claude to validate, to take as context, or to answer a " \
|
|
76
76
|
"question about. Only when the user asks for it, or to reply to its answer " \
|
|
77
77
|
"in a peer turn. Needs a paired Claude Code session: without one it fails, " \
|
|
78
|
-
"and the user pairs from Claude. Claude's answer comes back later as
|
|
79
|
-
"claude-outbox
|
|
80
|
-
"send secrets or the whole conversation."
|
|
78
|
+
"and the user pairs from Claude. Claude's answer comes back later as a " \
|
|
79
|
+
"claude-outbox note with its text (a validate's wakes you): don't wait or " \
|
|
80
|
+
"poll. Never send secrets or the whole conversation."
|
|
81
81
|
TOOL_PARAMS = {
|
|
82
82
|
kind: { type: "string", enum: KINDS, required: true,
|
|
83
83
|
description: "validate: check this part and answer with a verdict; context: for Claude to know, no " \
|
|
@@ -84,16 +84,37 @@ EOF
|
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
- The second argument is always `wake` or `nowake`: `wake` for a validate or
|
|
87
|
-
a question (chi asked and is waiting),
|
|
87
|
+
a question (chi asked and is waiting), and for a message you start yourself
|
|
88
|
+
that chi should act on or know now (below); `nowake` for a reply to context
|
|
89
|
+
and for background chi can pick up at its next turn.
|
|
88
90
|
- The third is the `ref:` value of the message you answer (`s-ab12cd` above),
|
|
89
91
|
so chi ties the answer to its send; leave it out when the message had no
|
|
90
|
-
`ref:` line.
|
|
91
|
-
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
`ref:` line, and for a message you start.
|
|
93
|
+
- chi puts your whole text in its conversation (up to its tool output cap,
|
|
94
|
+
10,000 characters by default, for a message that wakes it; up to 2,000 for
|
|
95
|
+
one that doesn't; a longer one it reads on demand), and keeps each answer's
|
|
96
|
+
text there, so don't repeat points from an earlier answer (a chi newer than
|
|
97
|
+
0.184.0; 0.184.0 or older keeps only the latest text: repeat them there,
|
|
98
|
+
as before). The outbox itself
|
|
99
|
+
keeps only the latest push, so start the summary with the title you are
|
|
100
|
+
answering, and end it with your verdict (`VERDICT OK`, `VERDICT CHANGES` or
|
|
101
|
+
`VERDICT UNSURE`): an OK wakes chi once to close the round.
|
|
102
|
+
- Never answer a chi message with `chi send`: it goes in as an agent's
|
|
103
|
+
message (yours, not the user's) and counts toward the session's wake
|
|
104
|
+
budget (`session.max_wakes`), outside the round's limit. Use it only when
|
|
105
|
+
the user asks you to.
|
|
106
|
+
|
|
107
|
+
### A message you start
|
|
108
|
+
|
|
109
|
+
When something here changes what chi is doing (you changed code or a plan it
|
|
110
|
+
depends on, the user took a decision with you that chi should follow), tell
|
|
111
|
+
chi without waiting to be asked: the same push, with no third argument, and
|
|
112
|
+
`wake` when chi should react now, `nowake` when it is only background. Start
|
|
113
|
+
the summary with what it is about (`sync: <what>`). chi reads it as a message
|
|
114
|
+
you sent unasked, takes it into account within its user's task and tells its
|
|
115
|
+
user. A waking message counts toward the same limit as answers
|
|
116
|
+
(`context.peer_turns`, 3 in a row without the user typing); past it the
|
|
117
|
+
message waits in chi as a note. Don't send one only to acknowledge.
|
|
97
118
|
|
|
98
119
|
## chi continued the session
|
|
99
120
|
|
|
@@ -102,7 +123,8 @@ with the old id, so pair again:
|
|
|
102
123
|
|
|
103
124
|
- **A `moved` message** (`chi <old> · moved · continued as <new id>`): run
|
|
104
125
|
the pair command again with the new id, the same way you paired before
|
|
105
|
-
(the same `CHI_REMOTE
|
|
126
|
+
(the same `CHI_REMOTE`; over SSH, `pair-remote` with the new id: the new
|
|
127
|
+
id gets its own socket and forward). From then on answer only
|
|
106
128
|
the new id; an answer you are still writing goes there too. Don't reply to
|
|
107
129
|
the message itself.
|
|
108
130
|
- **A push refused** with `<old> was continued as <new id>`: pair again with
|
|
@@ -112,35 +134,32 @@ with the old id, so pair again:
|
|
|
112
134
|
|
|
113
135
|
When the chi session runs on a machine this Claude session reaches with SSH
|
|
114
136
|
(the user says so, or `CHI_REMOTE` or a remote URL is in play) and chi should
|
|
115
|
-
send here too,
|
|
116
|
-
|
|
137
|
+
send here too, the socket chi writes to must be one on chi's machine: an
|
|
138
|
+
`ssh -R` forward of this session's socket.
|
|
117
139
|
|
|
118
140
|
You need a chi remote for that machine first (`chi remote add <name> <url>`,
|
|
119
141
|
through an `ssh -L` tunnel if that is how you reach it — docs/cli.md "Through
|
|
120
|
-
an SSH tunnel"). Then, with the host and the
|
|
142
|
+
an SSH tunnel"). Then, with the ssh host and the remote's name (two names for
|
|
143
|
+
the same machine), run:
|
|
121
144
|
|
|
122
145
|
```sh
|
|
123
|
-
|
|
124
|
-
ssh -N -o ExitOnForwardFailure=yes -R /tmp/claude-peer-<id8>.sock:"$CLAUDE_CODE_MESSAGING_SOCKET" <host>
|
|
146
|
+
sh "__CHI_PEER_PAIR_REMOTE__" <host> <remote name> <chi session id or URL>
|
|
125
147
|
```
|
|
126
148
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```sh
|
|
138
|
-
CHI_REMOTE=<name> sh "__CHI_PEER_PAIR__" --inbox-socket /tmp/claude-peer-<id8>.sock <id>
|
|
139
|
-
```
|
|
149
|
+
It resolves the full id, ends a forward an earlier run left for that session,
|
|
150
|
+
starts the forward in the background (`/tmp/claude-peer-<id8>.sock` there) and
|
|
151
|
+
pairs through the remote. Its last line says how to end the forward
|
|
152
|
+
(`ssh -S <path> -O exit <host>`). It never prompts: when ssh needs a password
|
|
153
|
+
or 2FA, or the server refuses the forward (`AllowStreamLocalForwarding no`:
|
|
154
|
+
there is no fallback), it prints the commands for the user to run in a
|
|
155
|
+
terminal, then the pair line for you. A stale remote socket is not replaced
|
|
156
|
+
unless the **server's** sshd has `StreamLocalBindUnlink yes`; the script
|
|
157
|
+
removes it first.
|
|
140
158
|
|
|
141
159
|
The socket must be visible to chi's process on that machine (chi runs as the
|
|
142
160
|
SSH user, in the same `/tmp`, not inside a separate container): if `/claude`
|
|
143
|
-
in chi shows the socket **missing** while
|
|
161
|
+
in chi shows the socket **missing** while the forward runs, that is why (or
|
|
162
|
+
the host and the remote name point at different machines).
|
|
144
163
|
|
|
145
164
|
Replies are the same push, through the remote:
|
|
146
165
|
`CHI_REMOTE=<name> chi context push claude-outbox <id>`.
|
|
@@ -149,8 +168,8 @@ A path in a chi message — a `payload: <path>` file, a file or a diff to check
|
|
|
149
168
|
is on `<host>`, not here: read it with `ssh <host> cat <path>` (or the repo
|
|
150
169
|
there). The `Read(...)` permission note for payload files does not apply.
|
|
151
170
|
|
|
152
|
-
After this Claude session restarts its socket changes:
|
|
153
|
-
|
|
171
|
+
After this Claude session restarts its socket changes: run the same
|
|
172
|
+
`pair-remote` line again (it ends the old forward).
|
|
154
173
|
|
|
155
174
|
Security: whoever can write to that socket on the remote machine can send
|
|
156
175
|
prompts into this session (sshd makes it the user's, mode 0600 by default).
|
|
@@ -134,14 +134,14 @@ if [ -z "$inbox" ]; then
|
|
|
134
134
|
socket: $sock
|
|
135
135
|
claude cwd: $PWD
|
|
136
136
|
paired: $(date '+%Y-%m-%d %H:%M')
|
|
137
|
-
Send to it with the claude_send tool (your skill_claude_peer memory); its answers come as
|
|
137
|
+
Send to it with the claude_send tool (your skill_claude_peer memory); its answers come as claude-outbox notes holding their text."
|
|
138
138
|
summary="Claude Code paired from $PWD"
|
|
139
139
|
else
|
|
140
140
|
text="Claude Code peer inbox
|
|
141
141
|
socket: $inbox (on this machine: an ssh -R forward of Claude's socket $sock on Claude's machine)
|
|
142
142
|
claude cwd: $PWD
|
|
143
143
|
paired: $(date '+%Y-%m-%d %H:%M')
|
|
144
|
-
Send to it with the claude_send tool (your skill_claude_peer memory); its answers come as
|
|
144
|
+
Send to it with the claude_send tool (your skill_claude_peer memory); its answers come as claude-outbox notes holding their text.
|
|
145
145
|
If claude_send says the Claude session is gone, the ssh tunnel may be down: tell the user to restart it and pair again."
|
|
146
146
|
summary="Claude Code paired from $PWD over ssh"
|
|
147
147
|
fi
|