samagotchi 0.171.0 → 0.172.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 +33 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +24 -7
- data/docs/bundles.md +4 -21
- data/docs/cli.md +50 -80
- data/docs/configuration.md +11 -13
- data/docs/context.md +5 -6
- data/docs/guardrails.md +57 -96
- data/docs/hooks.md +3 -4
- data/docs/internals/attached-context.md +6 -7
- data/docs/internals/background-tasks.md +4 -3
- data/docs/internals/bridge.md +29 -3
- data/docs/internals/engine.md +21 -9
- data/docs/internals/objectives.md +3 -5
- data/docs/internals/participants.md +118 -143
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +33 -14
- data/docs/internals/working-set.md +7 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +15 -49
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +2 -2
- data/docs/testing.md +56 -7
- data/lib/samagotchi/bridge/card_store.rb +1 -0
- data/lib/samagotchi/bridge/sse_writer.rb +1 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +0 -1
- data/lib/samagotchi/bridge.rb +26 -9
- data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
- data/lib/samagotchi/bundle_command/test_run.rb +1 -0
- data/lib/samagotchi/bundle_command/try/run.rb +1 -0
- data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
- data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
- data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
- data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +126 -67
- data/lib/samagotchi/command_intake.rb +15 -3
- data/lib/samagotchi/compat.rb +6 -1
- data/lib/samagotchi/context_candidate_choice.rb +1 -3
- data/lib/samagotchi/context_candidates.rb +3 -4
- data/lib/samagotchi/continue_offer.rb +9 -2
- data/lib/samagotchi/delivery.rb +23 -12
- data/lib/samagotchi/empty_answer_error.rb +5 -0
- data/lib/samagotchi/engine/cards.rb +3 -0
- data/lib/samagotchi/engine/context_judge.rb +5 -3
- data/lib/samagotchi/engine/events.rb +4 -0
- data/lib/samagotchi/engine/hooks.rb +3 -0
- data/lib/samagotchi/engine/messages.rb +5 -0
- data/lib/samagotchi/engine/model_settings.rb +2 -0
- data/lib/samagotchi/engine/models.rb +10 -0
- data/lib/samagotchi/engine/objectives.rb +6 -0
- data/lib/samagotchi/engine/participants.rb +18 -14
- data/lib/samagotchi/engine/plugins.rb +8 -0
- data/lib/samagotchi/engine/questions.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -0
- data/lib/samagotchi/engine/session.rb +4 -0
- data/lib/samagotchi/engine/side_requests.rb +9 -0
- data/lib/samagotchi/engine/steering.rb +2 -0
- data/lib/samagotchi/engine/toolkit.rb +5 -0
- data/lib/samagotchi/engine/turn_end.rb +7 -0
- data/lib/samagotchi/engine/turn_helpers.rb +8 -0
- data/lib/samagotchi/engine/verify.rb +2 -0
- data/lib/samagotchi/engine.rb +3 -2
- data/lib/samagotchi/grants.rb +28 -22
- data/lib/samagotchi/guardrail_wiring.rb +23 -18
- data/lib/samagotchi/guardrails/approval_use.rb +59 -0
- data/lib/samagotchi/guardrails/approvals.rb +9 -11
- data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
- data/lib/samagotchi/guardrails/gate.rb +10 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
- data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
- data/lib/samagotchi/guardrails/review_paths.rb +2 -3
- data/lib/samagotchi/guardrails.rb +1 -1
- data/lib/samagotchi/llm_context_strategy.rb +2 -0
- data/lib/samagotchi/objectives.rb +1 -4
- data/lib/samagotchi/objectives_audit.rb +1 -1
- data/lib/samagotchi/objectives_track.rb +1 -1
- data/lib/samagotchi/owner_prompt.rb +3 -6
- data/lib/samagotchi/parent_report.rb +1 -0
- data/lib/samagotchi/participant_messages.rb +9 -4
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participants.rb +21 -12
- data/lib/samagotchi/participants_watch.rb +2 -2
- data/lib/samagotchi/plugin/api.rb +2 -2
- data/lib/samagotchi/plugin/attached_context.rb +1 -1
- data/lib/samagotchi/plugin/context.rb +0 -4
- data/lib/samagotchi/plugin/sessions.rb +1 -25
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +10 -10
- data/lib/samagotchi/session.rb +0 -3
- data/lib/samagotchi/session_access/contract.rb +1 -10
- data/lib/samagotchi/session_access/local.rb +10 -23
- data/lib/samagotchi/session_access/remote.rb +9 -20
- data/lib/samagotchi/session_access.rb +12 -16
- data/lib/samagotchi/session_chain.rb +4 -6
- data/lib/samagotchi/session_commands.rb +6 -3
- data/lib/samagotchi/session_continue.rb +1 -2
- data/lib/samagotchi/session_manager/delivery.rb +25 -5
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
- data/lib/samagotchi/session_manager/listing.rb +5 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/session_manager/worker_command.rb +9 -0
- data/lib/samagotchi/session_participants.rb +12 -8
- data/lib/samagotchi/session_review.rb +5 -7
- data/lib/samagotchi/session_stores.rb +3 -3
- data/lib/samagotchi/share_command.rb +10 -12
- data/lib/samagotchi/share_terms.rb +41 -0
- data/lib/samagotchi/steer.rb +8 -14
- data/lib/samagotchi/system_prompt.rb +16 -25
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
- data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
- data/lib/samagotchi/terminal_ui.rb +1 -2
- data/lib/samagotchi/testing/sessions.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +8 -9
- data/lib/samagotchi/toolkit.rb +4 -22
- data/lib/samagotchi/toolkit_suggest.rb +3 -3
- data/lib/samagotchi/tools/deferred_tools.rb +1 -0
- data/lib/samagotchi/tools/execute.rb +11 -45
- data/lib/samagotchi/tools/leftovers.rb +122 -0
- data/lib/samagotchi/tools/memory.rb +70 -26
- data/lib/samagotchi/tools/task_get.rb +1 -0
- data/lib/samagotchi/tools/task_list.rb +3 -2
- data/lib/samagotchi/tools/task_record.rb +6 -4
- data/lib/samagotchi/tools/task_runtime.rb +199 -20
- data/lib/samagotchi/tools/task_wait.rb +4 -3
- data/lib/samagotchi/turn_context.rb +1 -1
- data/lib/samagotchi/turn_origin.rb +1 -1
- data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
- data/lib/samagotchi/turn_stages/objectives.rb +2 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_fresh.rb +1 -1
- data/lib/samagotchi/verify_fresh_origin.rb +13 -11
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +3 -5
- data/lib/samagotchi/web/participant_access.rb +14 -18
- data/lib/samagotchi/web/participant_review.rb +3 -4
- data/lib/samagotchi/web/participant_show.rb +4 -3
- data/lib/samagotchi/web/participant_view.rb +3 -3
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/app.js +5 -47
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +17 -60
- data/lib/samagotchi/web/public/index.html +10 -30
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/owner_claim.js +2 -2
- data/lib/samagotchi/web/public/participant_bar.js +4 -5
- data/lib/samagotchi/web/public/participant_names.js +14 -10
- data/lib/samagotchi/web/public/participants_panel.js +29 -62
- data/lib/samagotchi/web/public/reload_check.js +2 -3
- data/lib/samagotchi/web/public/send_turn.js +4 -23
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +0 -1
- data/lib/samagotchi/web/public/session_state.js +0 -3
- data/lib/samagotchi/web/public/session_view.js +2 -3
- data/lib/samagotchi/web/public/settings_panel.js +4 -18
- data/lib/samagotchi/web/public/stage_answer.js +56 -0
- data/lib/samagotchi/web/public/stage_asking.js +1 -1
- data/lib/samagotchi/web/public/stage_cloud.js +93 -0
- data/lib/samagotchi/web/public/stage_dom.js +100 -0
- data/lib/samagotchi/web/public/stage_handoff.js +154 -0
- data/lib/samagotchi/web/public/stage_pager.js +59 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +90 -411
- data/lib/samagotchi/web/public/start_page.js +12 -33
- data/lib/samagotchi/web/public/start_settings.js +24 -78
- data/lib/samagotchi/web/public/start_toolkit.js +6 -10
- data/lib/samagotchi/web/public/stream_handlers.js +1 -9
- data/lib/samagotchi/web/public/turn_block.js +3 -7
- data/lib/samagotchi/web/public/turn_events.js +15 -6
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/viewer_self.js +8 -2
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +3 -1
- data/lib/samagotchi/web/session_create.rb +5 -71
- data/lib/samagotchi/web/session_summary.rb +1 -4
- data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
- data/lib/samagotchi/web/viewer.rb +3 -3
- data/lib/samagotchi/worker.rb +16 -14
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +87 -28
- metadata +13 -8
- data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
- data/lib/samagotchi/participant_mode.rb +0 -86
- data/lib/samagotchi/review_apply.rb +0 -131
- data/lib/samagotchi/review_command.rb +0 -123
- data/lib/samagotchi/review_start.rb +0 -196
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_start.js +0 -55
data/lib/samagotchi/client_id.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Samagotchi
|
|
4
4
|
# Who sent a turn, a line or an answer: its client_id, as a turn's origin,
|
|
5
5
|
# an input file and the events carry it. The one table of the ids chi
|
|
6
|
-
# makes
|
|
6
|
+
# makes (ROWS: one Sender row each), and what each may do. No requires,
|
|
7
7
|
# so any file can use it.
|
|
8
8
|
module ClientId
|
|
9
9
|
# A web tab (web:<random>, per tab); web:restart, the page's Restart.
|
|
@@ -43,74 +43,132 @@ module Samagotchi
|
|
|
43
43
|
PLUGIN = "plugin"
|
|
44
44
|
# A relayed answer (RelayVerifier): relay:<parent8>.
|
|
45
45
|
RELAY_PREFIX = "relay:"
|
|
46
|
-
# A participant's
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
# the
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
46
|
+
# A participant's turn: participant:<participant id> (chi web stamps it
|
|
47
|
+
# from the participant's token, never from the request's body). Not
|
|
48
|
+
# their author (Steer::PARTICIPANT_PREFIX, "p:<id>"), which says who
|
|
49
|
+
# wrote a turn: this says which sender delivered it.
|
|
50
|
+
PARTICIPANT_PREFIX = "participant:"
|
|
51
|
+
# compat shim review_client_id: the legacy review:<id> participant id
|
|
52
|
+
# used before 0.172 (still in turn_drawings.jsonl, input files and an
|
|
53
|
+
# older chi web still running): read it as a participant's, never the
|
|
54
|
+
# owner's, and send it to a worker without Delivery::PARTICIPANT_ID_FEATURE.
|
|
55
|
+
LEGACY_REVIEW_PREFIX = "review:"
|
|
56
|
+
|
|
57
|
+
# A worker's own first prompt (spawn_session's) when no sender was
|
|
58
|
+
# saved for it (WorkerInbound#initial_origin: a person's session saves
|
|
59
|
+
# no first_turn_client_id, nor did an older chi): the owner's, as chi
|
|
60
|
+
# send's. Seen in turn_drawings.jsonl and a turn's SSE origin, labelled
|
|
61
|
+
# as no sender is (the TUI's "user", the web's none).
|
|
62
|
+
FIRST_PROMPT = "spawn:first"
|
|
63
|
+
# A person's answer to a card that queues a command (ContinueOffer's
|
|
64
|
+
# Continue / Stop: a TUI's or the web's answer names no sender, only
|
|
65
|
+
# chi answer's does): the owner's, labelled as no sender is.
|
|
66
|
+
CARD_ANSWER = "card:answer"
|
|
67
|
+
|
|
68
|
+
# One sender: its id (+match+: the whole id, or a prefix ending in ":"
|
|
69
|
+
# for the ids that carry a suffix) and what it may do:
|
|
70
|
+
# human — a human's input (a web tab, a chi TUI, chi send, a
|
|
71
|
+
# participant: never automatic input);
|
|
72
|
+
# owner — the owner's input: session commands (CommandIntake),
|
|
73
|
+
# un-archive and wake resets (Worker#user_input);
|
|
74
|
+
# interactive — a screen that shows a command's reply and can answer
|
|
75
|
+
# it (CacheConfirm, /parent-answers);
|
|
76
|
+
# wake — the SessionInbox::WakePolicy row a delivery reads
|
|
77
|
+
# (only :send un-stops and un-archives);
|
|
78
|
+
# origin — LastTurn#origin / TurnOrigin#source;
|
|
79
|
+
# source — a merged line's Steer source: a String, nil (the
|
|
80
|
+
# user's own) or :automatic ("automatic:<id>");
|
|
81
|
+
# label — the TUI's and the web's word for it (turn_events.js
|
|
82
|
+
# CLIENT_LABELS keeps the same; nil: as no sender, the
|
|
83
|
+
# TUI's "user", the web's none).
|
|
84
|
+
Sender = Data.define(:match, :human, :owner, :interactive, :wake, :origin, :source, :label) do
|
|
85
|
+
def prefix? = match.to_s.end_with?(":")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
person = { human: true, owner: true, interactive: true, wake: :send, origin: "client", source: nil }
|
|
89
|
+
unattended = { human: false, owner: false, interactive: false, wake: :automatic, origin: "client", source: :automatic,
|
|
90
|
+
label: "automatic" }
|
|
91
|
+
|
|
92
|
+
# A participant: a human's input, never the owner's.
|
|
93
|
+
participant = Sender.new(match: PARTICIPANT_PREFIX, human: true, owner: false, interactive: false, wake: :participant,
|
|
94
|
+
origin: "participant", source: "participant", label: "invited")
|
|
95
|
+
|
|
96
|
+
# Every id chi makes: an allowlist. Delegates, plugins, reminders,
|
|
97
|
+
# context changes and any id chi doesn't know (UNKNOWN) are no human's.
|
|
98
|
+
ROWS = [
|
|
99
|
+
Sender.new(match: WEB_PREFIX, **person, label: "web"),
|
|
100
|
+
Sender.new(match: WEB_RESTART, **person, label: "web"),
|
|
101
|
+
Sender.new(match: WEB_CREATE, **person, label: "web"),
|
|
102
|
+
Sender.new(match: WEB_UNNAMED, **person, label: "web"),
|
|
103
|
+
Sender.new(match: TUI_PREFIX, **person, label: "tui"),
|
|
104
|
+
Sender.new(match: CLI_SEND, **person, interactive: false, source: "chi_send", label: "chi send"),
|
|
105
|
+
Sender.new(match: FIRST_PROMPT, **person, interactive: false, label: nil),
|
|
106
|
+
Sender.new(match: CARD_ANSWER, **person, interactive: false, wake: :automatic, label: nil),
|
|
107
|
+
# chi answer's: no human's input (a parent agent's), but CommandIntake
|
|
108
|
+
# lets its commands run (CommandIntake::ALLOWED_IDS).
|
|
109
|
+
Sender.new(match: CLI_ANSWER, **unattended, label: "chi answer"),
|
|
110
|
+
Sender.new(match: CLI_RESTART, **unattended),
|
|
111
|
+
Sender.new(match: DELEGATE_PREFIX, **unattended, wake: :delegate, origin: "delegate", source: "parent_agent",
|
|
112
|
+
label: "delegate"),
|
|
113
|
+
Sender.new(match: CHILD_PREFIX, **unattended, origin: "delegate_report", source: "delegate_report",
|
|
114
|
+
label: "delegate report"),
|
|
115
|
+
Sender.new(match: CONTEXT_PREFIX, **unattended, origin: "context"),
|
|
116
|
+
Sender.new(match: TASK_PREFIX, **unattended, origin: "task"),
|
|
117
|
+
Sender.new(match: SYSTEM_PREFIX, **unattended, label: "reminder"),
|
|
118
|
+
Sender.new(match: REMINDER, **unattended, origin: "reminder", label: "reminder"),
|
|
119
|
+
Sender.new(match: SCHEDULE_PREFIX, **unattended, wake: :schedule, origin: "schedule", label: "schedule"),
|
|
120
|
+
Sender.new(match: PLUGIN, **unattended, wake: :plugin, source: "plugin_send", label: "plugin"),
|
|
121
|
+
Sender.new(match: RELAY_PREFIX, **unattended),
|
|
122
|
+
participant,
|
|
123
|
+
# compat shim review_client_id: the legacy review:<id> id uses the
|
|
124
|
+
# participant sender row too.
|
|
125
|
+
participant.with(match: LEGACY_REVIEW_PREFIX)
|
|
126
|
+
].freeze
|
|
127
|
+
|
|
128
|
+
# No client id: reaches only a worker's own seams (an input file from
|
|
129
|
+
# an older chi, a Bridge POST /turn naming none). A human's (it counts
|
|
130
|
+
# for a delegate child's report and the session's metrics) but never
|
|
131
|
+
# the owner's: every sender names itself (POST /command refuses none;
|
|
132
|
+
# a POST /turn's /word line from none is prose).
|
|
133
|
+
NONE = Sender.new(match: nil, human: true, owner: false, interactive: false, wake: :automatic, origin: "client",
|
|
134
|
+
source: nil, label: nil)
|
|
135
|
+
# An id chi doesn't know: automatic input, never a human's.
|
|
136
|
+
UNKNOWN = Sender.new(match: nil, **unattended)
|
|
137
|
+
|
|
138
|
+
EXACT_ROWS = ROWS.reject(&:prefix?).to_h { |row| [row.match, row] }.freeze
|
|
139
|
+
# Longest first: system:schedule: before system:.
|
|
140
|
+
PREFIX_ROWS = ROWS.select(&:prefix?).sort_by { |row| -row.match.length }.freeze
|
|
80
141
|
|
|
81
142
|
module_function
|
|
82
143
|
|
|
144
|
+
# The row for +client_id+: the whole id first, then its longest prefix;
|
|
145
|
+
# NONE for nil, UNKNOWN for an id chi doesn't know ("" too).
|
|
146
|
+
# @return [Sender]
|
|
147
|
+
def sender(client_id)
|
|
148
|
+
return NONE if client_id.nil?
|
|
149
|
+
|
|
150
|
+
id = client_id.to_s
|
|
151
|
+
EXACT_ROWS[id] || PREFIX_ROWS.find { |row| id.start_with?(row.match) } || UNKNOWN
|
|
152
|
+
end
|
|
153
|
+
|
|
83
154
|
# What sent a turn: "delegate" (a delegating parent), "delegate_report"
|
|
84
155
|
# (a child's report), "context" (a context wake), "task" (a task finish
|
|
85
|
-
# wake), "
|
|
156
|
+
# wake), "participant", "reminder", "schedule" (a durable
|
|
86
157
|
# schedule's firing), else "client" (the owner, chi send, a plugin, nil).
|
|
87
158
|
# @return [String]
|
|
88
|
-
def origin(client_id)
|
|
89
|
-
id = client_id.to_s
|
|
90
|
-
return "reminder" if id == REMINDER
|
|
91
|
-
|
|
92
|
-
ORIGIN_PREFIXES.each { |prefix, origin| return origin if id.start_with?(prefix) }
|
|
93
|
-
"client"
|
|
94
|
-
end
|
|
159
|
+
def origin(client_id) = sender(client_id).origin
|
|
95
160
|
|
|
96
161
|
# Whether +client_id+ is a web tab or a chi TUI, which see a command's
|
|
97
162
|
# reply and can send the line it asks for (CacheConfirm); chi send, a
|
|
98
163
|
# delegate, a plugin, chi itself and nil are not.
|
|
99
|
-
def interactive?(client_id)
|
|
100
|
-
id = client_id.to_s
|
|
101
|
-
INTERACTIVE_PREFIXES.any? { |prefix| id.start_with?(prefix) }
|
|
102
|
-
end
|
|
164
|
+
def interactive?(client_id) = sender(client_id).interactive
|
|
103
165
|
|
|
104
166
|
# Whether +client_id+ (a turn's or a line's origin) is a human's input.
|
|
105
|
-
def human?(client_id)
|
|
106
|
-
return true if client_id.nil?
|
|
167
|
+
def human?(client_id) = sender(client_id).human
|
|
107
168
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
# Whether +client_id+ is the owner's input, not a participant's.
|
|
113
|
-
def owner?(client_id) = human?(client_id) && !review?(client_id)
|
|
169
|
+
# Whether +client_id+ is the owner's input: not a participant's, not
|
|
170
|
+
# automatic, never nil.
|
|
171
|
+
def owner?(client_id) = sender(client_id).owner
|
|
114
172
|
|
|
115
173
|
# The WakePolicy row a turn delivery from +client_id+ reads (deliver_turn's
|
|
116
174
|
# two liveness checks): :send for a person (a web tab, a chi TUI, chi
|
|
@@ -118,21 +176,22 @@ module Samagotchi
|
|
|
118
176
|
# senders, :automatic for anything else (nil too: deliver_turn refuses it
|
|
119
177
|
# first). Only :send un-stops a stopped session or starts an archived one.
|
|
120
178
|
# @return [Symbol]
|
|
121
|
-
def wake_kind(client_id)
|
|
122
|
-
id = client_id.to_s
|
|
123
|
-
return :send if id == CLI_SEND || PERSON_WAKE_PREFIXES.any? { |prefix| id.start_with?(prefix) }
|
|
124
|
-
return :plugin if id == PLUGIN
|
|
125
|
-
|
|
126
|
-
WAKE_PREFIXES.each { |prefix, kind| return kind if id.start_with?(prefix) }
|
|
127
|
-
:automatic
|
|
128
|
-
end
|
|
179
|
+
def wake_kind(client_id) = sender(client_id).wake
|
|
129
180
|
|
|
130
181
|
# The client id a participant's turn carries (chi web's, from their
|
|
131
|
-
# grant):
|
|
132
|
-
def
|
|
182
|
+
# grant): participant:<participant id>.
|
|
183
|
+
def participant(participant_id) = "#{PARTICIPANT_PREFIX}#{participant_id}"
|
|
184
|
+
|
|
185
|
+
# Whether +client_id+ is a participant's (participant:, or legacy
|
|
186
|
+
# review:).
|
|
187
|
+
def participant?(client_id) = sender(client_id).wake == :participant
|
|
133
188
|
|
|
134
|
-
#
|
|
135
|
-
|
|
189
|
+
# compat shim review_client_id: translate participant:<id> for a worker
|
|
190
|
+
# that still expects review:<id>.
|
|
191
|
+
def legacy_participant(client_id)
|
|
192
|
+
id = client_id.to_s
|
|
193
|
+
id.start_with?(PARTICIPANT_PREFIX) ? "#{LEGACY_REVIEW_PREFIX}#{id.delete_prefix(PARTICIPANT_PREFIX)}" : client_id
|
|
194
|
+
end
|
|
136
195
|
|
|
137
196
|
# The client id a delegating parent's task and follow-ups carry:
|
|
138
197
|
# delegate:<parent8>.
|
|
@@ -25,9 +25,16 @@ module Samagotchi
|
|
|
25
25
|
"(a web tab, a chi TUI, chi send); from a delegate, a schedule or another automatic sender it is not run. " \
|
|
26
26
|
"Say what to run in words instead (\"run `ls`\"), or leave out the leading !"
|
|
27
27
|
|
|
28
|
-
# The Bridge's error code for it (403).
|
|
28
|
+
# The Bridge's error code for it (403), and for COMMAND_REFUSED.
|
|
29
29
|
REFUSED_ERROR = "command_not_permitted"
|
|
30
30
|
|
|
31
|
+
# The one text a session command line gets on the Bridge's explicit
|
|
32
|
+
# command route (POST /command) from a sender that may not send one
|
|
33
|
+
# (#allowed?): a participant, a delegate, a plugin, an id chi doesn't
|
|
34
|
+
# know. Its shell lines get REFUSED.
|
|
35
|
+
COMMAND_REFUSED = "a session command runs only when you send it (a web tab, a chi TUI, chi send) or chi answer does; " \
|
|
36
|
+
"from a participant, a delegate, a plugin or another automatic sender it is not run"
|
|
37
|
+
|
|
31
38
|
# chi answer's marker (a parent agent's /continue yes and
|
|
32
39
|
# /parent-answers; Worker#as_parent? holds those to its own rules): any
|
|
33
40
|
# command, with chi send's trust.
|
|
@@ -36,8 +43,10 @@ module Samagotchi
|
|
|
36
43
|
module_function
|
|
37
44
|
|
|
38
45
|
# Whether a message from +client_id+ may run as a session command: the
|
|
39
|
-
# owner's input (ClientId.owner?: a web tab, a chi TUI, chi send,
|
|
40
|
-
#
|
|
46
|
+
# owner's input (ClientId.owner?: a web tab, a chi TUI, chi send, a
|
|
47
|
+
# worker's own first prompt, a person's card answer) and chi answer's.
|
|
48
|
+
# No client id is no one's: refused (every sender names itself). A
|
|
49
|
+
# participant (participant:) is refused on its own.
|
|
41
50
|
# A delegate, a child's report, a context or task wake, a schedule, a
|
|
42
51
|
# reminder, a relay and a plugin may not (the bundles that send,
|
|
43
52
|
# coordinator and skills, send prose).
|
|
@@ -52,5 +61,8 @@ module Samagotchi
|
|
|
52
61
|
# Whether the command line +line+ from +client_id+ is a shell line that
|
|
53
62
|
# must not run.
|
|
54
63
|
def refused?(line, client_id) = shell_line?(line) && !allowed?(client_id)
|
|
64
|
+
|
|
65
|
+
# The refusal text for +line+ from a sender that may not send commands.
|
|
66
|
+
def refusal(line) = shell_line?(line) ? REFUSED : COMMAND_REFUSED
|
|
55
67
|
end
|
|
56
68
|
end
|
data/lib/samagotchi/compat.rb
CHANGED
|
@@ -24,7 +24,12 @@ module Samagotchi
|
|
|
24
24
|
"period after the release that wrote version 2 (0.151.0, 2026-11-05)"),
|
|
25
25
|
Shim.new(id: :approvals_bare_list, added_in: "0.169.0", added_on: "2026-11-12", remove_after: "0.172.0",
|
|
26
26
|
files: ["lib/samagotchi/guardrails/approvals.rb"],
|
|
27
|
-
what: "Approvals reads the bare list written by chi 0.166 and before, converting it on write")
|
|
27
|
+
what: "Approvals reads the bare list written by chi 0.166 and before, converting it on write"),
|
|
28
|
+
Shim.new(id: :review_client_id, added_in: "0.172.0", added_on: "2026-11-14", remove_after: "0.173.0",
|
|
29
|
+
files: ["lib/samagotchi/client_id.rb", "lib/samagotchi/session_manager/delivery.rb",
|
|
30
|
+
"lib/samagotchi/web/public/turn_events.js", "lib/samagotchi/web/public/viewer_self.js"],
|
|
31
|
+
what: "A participant's client id from before participant:<id> (review:<id>: drawings, input files, an " \
|
|
32
|
+
"older chi web) reads as a participant's, and a worker without participant_client_id is sent it")
|
|
28
33
|
].freeze
|
|
29
34
|
|
|
30
35
|
module_function
|
|
@@ -19,8 +19,7 @@ module Samagotchi
|
|
|
19
19
|
# - below, it stays proposed.
|
|
20
20
|
#
|
|
21
21
|
# The card's actions are /context attach NAME and /context decline NAME
|
|
22
|
-
# (#choose), the owner's only: a participant can't send a / line
|
|
23
|
-
# review session refuses them.
|
|
22
|
+
# (#choose), the owner's only: a participant can't send a / line.
|
|
24
23
|
module ContextCandidateChoice
|
|
25
24
|
CARD_SOURCE = "context"
|
|
26
25
|
# The judge's attach, as the source's why (no probability: it is
|
|
@@ -120,7 +119,6 @@ module Samagotchi
|
|
|
120
119
|
# @return [Array(Symbol, String)] :ok or :error, and the answer
|
|
121
120
|
def choose(action, name, session:, state_dir:, show_card:)
|
|
122
121
|
return [:error, Session::NONE_YET] unless session&.id
|
|
123
|
-
return [:error, "a review session takes no context candidates"] if session.review?
|
|
124
122
|
return [:error, USAGE] if name.to_s.empty?
|
|
125
123
|
|
|
126
124
|
candidate, status = find(session, name, state_dir: state_dir)
|
|
@@ -21,9 +21,8 @@ module Samagotchi
|
|
|
21
21
|
# when it is at least 6 characters and holds a /, - or _; a URL exactly.
|
|
22
22
|
# Text inside fenced code blocks (pasted logs) never counts.
|
|
23
23
|
#
|
|
24
|
-
# Only the owner's own prompts count (OwnerPrompt)
|
|
25
|
-
#
|
|
26
|
-
# session.
|
|
24
|
+
# Only the owner's own prompts count (OwnerPrompt): a participant never
|
|
25
|
+
# attaches a source to the owner's session.
|
|
27
26
|
module ContextCandidates
|
|
28
27
|
STATUSES = %w[proposed attached declined].freeze
|
|
29
28
|
# How long a turn waits for a mention-attached source's first text, so
|
|
@@ -190,7 +189,7 @@ module Samagotchi
|
|
|
190
189
|
return [] unless session&.id
|
|
191
190
|
|
|
192
191
|
own = ContextSources.session_location(session.id, state_dir: state_dir)
|
|
193
|
-
return [] if own.candidates.empty? || !OwnerPrompt.turn?(
|
|
192
|
+
return [] if own.candidates.empty? || !OwnerPrompt.turn?(author: author)
|
|
194
193
|
|
|
195
194
|
# The earlier owner prompts too: a proposal that came while one ran
|
|
196
195
|
# (a one-shot's plugins never see a running turn's prompt).
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
require "time"
|
|
4
4
|
require_relative "last_turn"
|
|
5
5
|
require_relative "log"
|
|
6
|
+
require_relative "participant_messages"
|
|
6
7
|
require_relative "steer"
|
|
7
8
|
require_relative "turn_origin"
|
|
9
|
+
require_relative "client_id"
|
|
8
10
|
|
|
9
11
|
module Samagotchi
|
|
10
12
|
# A session worker's continue offer: what it announces when a turn runs out
|
|
@@ -37,7 +39,7 @@ module Samagotchi
|
|
|
37
39
|
# @param queue_command [#call] (line, client_id:) queues a session
|
|
38
40
|
# command as a card's (Bridge#queue_command, card: true)
|
|
39
41
|
# +participant_refused+ (author → reason or nil): why a participant's
|
|
40
|
-
# turn may no longer run ("revoked", "cap_reached": Worker's check).
|
|
42
|
+
# turn may no longer run ("revoked", "outdated", "cap_reached": Worker's check).
|
|
41
43
|
# @param save [#call] saves the session (a refused Continue's Stop)
|
|
42
44
|
def initialize(engine:, turn_flow:, run_turn:, max_iterations:, queue_command: nil, participant_refused: ->(_) {},
|
|
43
45
|
save: -> {})
|
|
@@ -222,7 +224,8 @@ module Samagotchi
|
|
|
222
224
|
|
|
223
225
|
REFUSED_NOTICE = "Not continued: participant %<who>s's turn %<reason>s."
|
|
224
226
|
REFUSED_WHY = { "revoked" => "is refused (their link was revoked or expired)",
|
|
225
|
-
"
|
|
227
|
+
"outdated" => "is refused (#{ParticipantMessages::TOKEN_OUTDATED})",
|
|
228
|
+
"cap_reached" => "is refused (they reached their cap)" }.freeze
|
|
226
229
|
|
|
227
230
|
# The enqueued_id of the turn the offer stands for: the exhausted
|
|
228
231
|
# turn's last_turn (a canceled continue turn's carries the same id);
|
|
@@ -281,6 +284,10 @@ module Samagotchi
|
|
|
281
284
|
elsif text.empty? then "/continue no"
|
|
282
285
|
else "/continue no, #{text}"
|
|
283
286
|
end
|
|
287
|
+
# A person's answer names no sender (a TUI's, the web's): the owner's
|
|
288
|
+
# card answer, so their Continue / Stop un-archives and resets the
|
|
289
|
+
# wakes (Worker#user_input); a parent agent's keeps its own.
|
|
290
|
+
client_id ||= ClientId::CARD_ANSWER unless answer.parent_agent?
|
|
284
291
|
@queue_command&.call(line, client_id: client_id)
|
|
285
292
|
end
|
|
286
293
|
end
|
data/lib/samagotchi/delivery.rb
CHANGED
|
@@ -48,22 +48,33 @@ module Samagotchi
|
|
|
48
48
|
"restart it (chi sessions restart ID, or the web's update badge) and send again"
|
|
49
49
|
}.freeze
|
|
50
50
|
|
|
51
|
-
# A worker that runs participants' turns inside
|
|
51
|
+
# A worker that runs participants' turns inside a boundary
|
|
52
52
|
# (Bridge::FEATURES): one without it would run theirs with the owner's
|
|
53
|
-
# tools
|
|
53
|
+
# tools. Kept on the wire for an older chi web; this chi checks
|
|
54
|
+
# PAIR_FEATURE, which every worker with this one's boundary has.
|
|
54
55
|
REVIEW_FEATURE = "review_turns"
|
|
55
|
-
REVIEW_UNAVAILABLE = {
|
|
56
|
-
"error" => "review_unavailable",
|
|
57
|
-
"detail" => "this session's worker predates participants' turns, so it has no review boundary; " \
|
|
58
|
-
"the owner must restart it (chi sessions restart ID, or the web's update badge)"
|
|
59
|
-
}.freeze
|
|
60
56
|
|
|
61
|
-
# A worker that runs a participant's turn
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
# restarts.
|
|
57
|
+
# A worker that runs a participant's turn as a pair turn under the
|
|
58
|
+
# owner's guardrails (Guardrails::PairBoundary). One without it would
|
|
59
|
+
# run it as a read-only review turn, which this chi doesn't run: chi web
|
|
60
|
+
# sends it no participant's turn (PAIR_UNAVAILABLE) and no invite is
|
|
61
|
+
# issued for its session (ShareTerms.of) until it restarts.
|
|
62
|
+
# Workers advertise REVIEW_FEATURE too: an older chi web refuses
|
|
63
|
+
# participants' turns to a worker without it.
|
|
66
64
|
PAIR_FEATURE = "pair_turns"
|
|
65
|
+
# A worker that reads a participant's client id as participant:<id>
|
|
66
|
+
# (ClientId::PARTICIPANT_PREFIX). One without it reads only review:<id>
|
|
67
|
+
# (an unknown id to it: never the owner's, but its lines' source would
|
|
68
|
+
# be automatic:… and a participant's Verify fresh child would ring its
|
|
69
|
+
# parent), so chi web sends it the old id (SessionManager's delivery).
|
|
70
|
+
PARTICIPANT_ID_FEATURE = "participant_client_id"
|
|
71
|
+
# The one sentence for a live worker without PAIR_FEATURE; each caller
|
|
72
|
+
# adds what to do (PAIR_UNAVAILABLE, ShareTerms::OLDER_WORKER_REFUSAL).
|
|
73
|
+
OLDER_THAN_PAIR = "this session's worker is too old to run a participant's turn"
|
|
74
|
+
PAIR_UNAVAILABLE = {
|
|
75
|
+
"error" => "pair_unavailable",
|
|
76
|
+
"detail" => "#{OLDER_THAN_PAIR}: the owner must restart it (chi sessions restart ID, or the web's update badge)"
|
|
77
|
+
}.freeze
|
|
67
78
|
# The worker sidecar feature (Bridge::FEATURES) of a worker whose
|
|
68
79
|
# participant's message sent while their own turn runs goes in at its
|
|
69
80
|
# next step (Bridge#same_author_steer?, SessionInbox.turn_end_data?'s
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../turn_stages/context_judge"
|
|
4
|
+
|
|
3
5
|
module Samagotchi
|
|
4
6
|
class Engine
|
|
5
7
|
# The attached-context candidate judge (TurnStages::ContextJudge,
|
|
@@ -15,12 +17,12 @@ module Samagotchi
|
|
|
15
17
|
# A late proposal no owner prompt mentions (Plugin::Host
|
|
16
18
|
# #candidate_proposed, maybe while the plugins load, before a session
|
|
17
19
|
# or the event log is there): TurnStages::ContextJudge#late_candidates
|
|
18
|
-
# on the session the Engine is on (none,
|
|
19
|
-
#
|
|
20
|
+
# on the session the Engine is on (none: nothing, before anything else
|
|
21
|
+
# is read), the owner's prompts so far, the
|
|
20
22
|
# recorder and the sessions dir, all read now on the caller's thread.
|
|
21
23
|
def judge_late_candidates
|
|
22
24
|
session = @session
|
|
23
|
-
return if session.nil?
|
|
25
|
+
return if session.nil?
|
|
24
26
|
|
|
25
27
|
@context_judge.late_candidates(session, messages: plugin_messages, recorder: system_one_recorder,
|
|
26
28
|
state_dir: session_state_dir)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../answer_tail"
|
|
4
|
+
require_relative "../context_note"
|
|
5
|
+
require_relative "../llm_context_view"
|
|
6
|
+
require_relative "../objectives"
|
|
7
|
+
|
|
3
8
|
module Samagotchi
|
|
4
9
|
class Engine
|
|
5
10
|
# The session messages API: out-of-turn edits to the current session's
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../config"
|
|
4
|
+
require_relative "../effective_model"
|
|
5
|
+
require_relative "../llm/backend"
|
|
6
|
+
require_relative "../llm/errors"
|
|
7
|
+
require_relative "../log"
|
|
8
|
+
require_relative "../model_notes"
|
|
9
|
+
require_relative "../model_profile"
|
|
10
|
+
require_relative "../prompt_note"
|
|
11
|
+
require_relative "../system_prompt"
|
|
12
|
+
|
|
3
13
|
module Samagotchi
|
|
4
14
|
class Engine
|
|
5
15
|
# The model: its names and refs, identity and notes, /model's switch (and
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../log"
|
|
4
|
+
require_relative "../objectives"
|
|
5
|
+
require_relative "../objectives_check"
|
|
6
|
+
require_relative "../objectives_track"
|
|
7
|
+
require_relative "../turn_stages/objectives"
|
|
8
|
+
|
|
3
9
|
module Samagotchi
|
|
4
10
|
class Engine
|
|
5
11
|
# The session's objectives (TurnStages::Objectives, forwarded): the view
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../participant_turn_mode"
|
|
4
|
+
require_relative "../guardrail_wiring"
|
|
5
|
+
require_relative "../steer"
|
|
6
|
+
|
|
3
7
|
module Samagotchi
|
|
4
8
|
class Engine
|
|
5
9
|
# The session's participants: the running turn's author, a pair turn's
|
|
@@ -23,19 +27,18 @@ module Samagotchi
|
|
|
23
27
|
# nothing is checked mid-turn.
|
|
24
28
|
attr_writer :participant_stop
|
|
25
29
|
|
|
26
|
-
# Before each generation (KernelLoop::Services#generation_guard): a
|
|
27
|
-
# participant's link ended
|
|
28
|
-
# finished turns, this one's finished
|
|
29
|
-
# passed their cap, stops on the
|
|
30
|
-
# work-cap's), with its notice. A
|
|
31
|
-
# once it ends, so a turn can pass
|
|
32
|
-
# turn-start check is the Worker's
|
|
33
|
-
#
|
|
30
|
+
# Before each generation (KernelLoop::Services#generation_guard): a
|
|
31
|
+
# participant's turn whose link ended (or is an older chi's), or whose
|
|
32
|
+
# spend (Engine#metrics: their finished turns, this one's finished
|
|
33
|
+
# generations, their side requests) passed their cap, stops on the
|
|
34
|
+
# plugins' stop path (cost-cap's, work-cap's), with its notice. A
|
|
35
|
+
# generation's own cost is known only once it ends, so a turn can pass
|
|
36
|
+
# the cap by its last generation. The turn-start check is the Worker's
|
|
37
|
+
# (Worker#participant_refusal).
|
|
34
38
|
# @param context [TurnContext] the running turn's (the loop's)
|
|
35
39
|
def guard_participant_spend(context)
|
|
36
40
|
author = context&.author
|
|
37
41
|
return if author.nil? || @participant_stop.nil?
|
|
38
|
-
return unless context.participant_mode == ParticipantMode::PAIR
|
|
39
42
|
|
|
40
43
|
reason = @participant_stop.call(author) or return
|
|
41
44
|
hook_stop_turn(reason, PARTICIPANTS_HOOK)
|
|
@@ -78,13 +81,14 @@ module Samagotchi
|
|
|
78
81
|
Steer.author_fields(author, @participants.name_for(author, session: session))
|
|
79
82
|
end
|
|
80
83
|
|
|
81
|
-
# A participant's opening message keeps the rules it was delivered under
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
+
# A participant's opening message keeps the rules it was delivered under,
|
|
85
|
+
# stamped before any request carries it, so its header never changes
|
|
86
|
+
# afterwards: "pair" for a pair turn (GuardrailWiring::PAIR). A turn this
|
|
87
|
+
# chi refuses (GuardrailWiring::REFUSED) gets no stamp: it reads as a
|
|
88
|
+
# review, whose header says the turn may only read.
|
|
84
89
|
# @param context [TurnContext] the turn's
|
|
85
90
|
def participant_mode_fields(context)
|
|
86
|
-
|
|
87
|
-
mode ? { participant_mode: mode.to_s } : {}
|
|
91
|
+
context.participant? && context.participant_mode == GuardrailWiring::PAIR ? { participant_mode: ParticipantTurnMode::PAIR_MODE } : {}
|
|
88
92
|
end
|
|
89
93
|
end
|
|
90
94
|
end
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../answer_display"
|
|
4
|
+
require_relative "../bundle_settings_check"
|
|
5
|
+
require_relative "../cache_confirm"
|
|
6
|
+
require_relative "../log"
|
|
7
|
+
require_relative "../plugin/context"
|
|
8
|
+
require_relative "../plugin/loader"
|
|
9
|
+
require_relative "../session_setup"
|
|
10
|
+
|
|
3
11
|
module Samagotchi
|
|
4
12
|
class Engine
|
|
5
13
|
# The Engine as the plugins' host: loading them (Plugin::Registries), their
|