samagotchi 0.170.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 +61 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +26 -9
- data/docs/bundles.md +4 -21
- data/docs/cli.md +81 -97
- data/docs/configuration.md +12 -14
- 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/block-renderers.md +2 -2
- data/docs/internals/bridge.md +34 -7
- data/docs/internals/context-telemetry.md +13 -1
- data/docs/internals/engine.md +25 -13
- data/docs/internals/inline-widgets.md +1 -1
- data/docs/internals/objectives.md +4 -6
- data/docs/internals/participants.md +340 -249
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +185 -35
- data/docs/internals/working-set.md +71 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/releasing.md +2 -1
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +17 -48
- 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 +8 -5
- data/lib/samagotchi/bridge.rb +64 -20
- 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 +36 -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 +8 -3
- data/lib/samagotchi/event_fanout.rb +22 -1
- data/lib/samagotchi/grants.rb +33 -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/image_store.rb +51 -12
- data/lib/samagotchi/kernel_loop.rb +7 -1
- data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
- data/lib/samagotchi/llm_context_stale.rb +4 -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 +48 -4
- data/lib/samagotchi/participant_revise.rb +61 -0
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participant_uploads.rb +98 -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/reply_wait/poll.rb +5 -1
- data/lib/samagotchi/revise_anchor.rb +9 -0
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +15 -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_inbox.rb +20 -12
- data/lib/samagotchi/session_manager/delivery.rb +32 -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 -1
- 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 +42 -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 +88 -25
- 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_anchors.rb +0 -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/turn_stages/verify_anchors.rb +13 -1
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_anchor.rb +6 -0
- 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 +45 -82
- data/lib/samagotchi/web/participant_access.rb +139 -40
- data/lib/samagotchi/web/participant_images.rb +185 -0
- data/lib/samagotchi/web/participant_review.rb +22 -142
- data/lib/samagotchi/web/participant_show.rb +241 -0
- data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
- data/lib/samagotchi/web/participant_view.rb +334 -27
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/annotate_bar.css +1 -2
- data/lib/samagotchi/web/public/annotate_bar.js +1 -2
- data/lib/samagotchi/web/public/app.js +126 -132
- data/lib/samagotchi/web/public/block_host.js +7 -4
- data/lib/samagotchi/web/public/bubbles.js +9 -1
- data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
- data/lib/samagotchi/web/public/chip_popover.js +5 -4
- data/lib/samagotchi/web/public/claim_link.js +4 -4
- data/lib/samagotchi/web/public/composer.css +4 -6
- data/lib/samagotchi/web/public/composer_mode.js +11 -6
- data/lib/samagotchi/web/public/composer_mount.js +4 -4
- data/lib/samagotchi/web/public/ctx.js +12 -3
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +49 -63
- data/lib/samagotchi/web/public/history_shape.js +5 -1
- data/lib/samagotchi/web/public/images.js +7 -1
- data/lib/samagotchi/web/public/index.html +50 -34
- data/lib/samagotchi/web/public/info_bar_model.js +2 -1
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/markdown_place.js +5 -4
- data/lib/samagotchi/web/public/owner_claim.js +5 -5
- data/lib/samagotchi/web/public/owner_verify.js +0 -2
- data/lib/samagotchi/web/public/participant_bar.js +107 -0
- data/lib/samagotchi/web/public/participant_main.js +289 -0
- data/lib/samagotchi/web/public/participant_model.js +5 -292
- data/lib/samagotchi/web/public/participant_names.js +17 -8
- data/lib/samagotchi/web/public/participant_revise.js +66 -0
- data/lib/samagotchi/web/public/participants_panel.js +32 -74
- data/lib/samagotchi/web/public/question_cards.js +14 -3
- data/lib/samagotchi/web/public/refs.js +53 -36
- data/lib/samagotchi/web/public/reload_check.js +70 -14
- data/lib/samagotchi/web/public/revise_stack.js +21 -10
- data/lib/samagotchi/web/public/send_turn.js +28 -29
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +1 -2
- data/lib/samagotchi/web/public/session_state.js +12 -7
- data/lib/samagotchi/web/public/session_sync.js +9 -2
- data/lib/samagotchi/web/public/session_view.js +14 -5
- 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 +7 -5
- 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_owner_wait.js +35 -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 +103 -410
- data/lib/samagotchi/web/public/stage_waiting.js +74 -6
- 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/storage.js +22 -0
- data/lib/samagotchi/web/public/stream_handlers.js +3 -10
- data/lib/samagotchi/web/public/tokens.css +1 -1
- data/lib/samagotchi/web/public/turn_block.js +2 -5
- data/lib/samagotchi/web/public/turn_events.js +30 -12
- data/lib/samagotchi/web/public/turn_html.js +9 -2
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/turn_range.js +1 -2
- data/lib/samagotchi/web/public/verify_target.js +2 -4
- data/lib/samagotchi/web/public/viewer.js +59 -0
- data/lib/samagotchi/web/public/viewer_self.js +59 -0
- data/lib/samagotchi/web/public/working_set.js +11 -5
- data/lib/samagotchi/web/public/working_set_view.js +53 -8
- data/lib/samagotchi/web/public/ws_cards.js +89 -0
- data/lib/samagotchi/web/public/ws_peek.js +106 -0
- data/lib/samagotchi/web/public/ws_preview.css +126 -0
- data/lib/samagotchi/web/public/ws_reader.js +319 -0
- data/lib/samagotchi/web/public/ws_timeline.js +200 -0
- data/lib/samagotchi/web/public/ws_way_in.js +25 -0
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +42 -15
- data/lib/samagotchi/web/session_create.rb +6 -72
- data/lib/samagotchi/web/session_show.rb +75 -28
- 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 +70 -0
- data/lib/samagotchi/web/working_set_routes.rb +132 -0
- data/lib/samagotchi/worker.rb +35 -28
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +322 -11
- metadata +32 -13
- 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/participant.html +0 -218
- data/lib/samagotchi/web/public/participant.js +0 -719
- data/lib/samagotchi/web/public/participant_annotate.js +0 -76
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_history.js +0 -72
- data/lib/samagotchi/web/public/review_start.js +0 -55
- data/lib/samagotchi/web/public/tools_overview.js +0 -42
|
@@ -30,8 +30,9 @@ module Samagotchi
|
|
|
30
30
|
# decide forgotten; edit, write and memory_write add ops and stamps only
|
|
31
31
|
# (their content is in the call's arguments, which no strategy cuts).
|
|
32
32
|
# Stale: the item's latest run left a stamp (ToolRun#stamp) and the file
|
|
33
|
-
# now differs from it in mtime or size, or is gone
|
|
34
|
-
#
|
|
33
|
+
# now differs from it in mtime or size, or is gone - for a memory, its
|
|
34
|
+
# entry or the model overlay read with it. A run with no stamp (an old
|
|
35
|
+
# session's) never makes an item stale.
|
|
35
36
|
module WorkingSet
|
|
36
37
|
FILE = "file"
|
|
37
38
|
MEMORY = "memory"
|
|
@@ -112,13 +113,15 @@ module Samagotchi
|
|
|
112
113
|
# LLMContextView takes it (the session's current one)
|
|
113
114
|
# @param stat [#call] File.stat, or a stand-in (specs)
|
|
114
115
|
# @param pins [Array<WorkingSetPin>] the session's pins
|
|
116
|
+
# @param root [String] the system memories folder
|
|
115
117
|
# @return [Snapshot]
|
|
116
|
-
def build(conversation, cwd:, strategy:, stat: File.method(:stat), pins: []
|
|
118
|
+
def build(conversation, cwd:, strategy:, stat: File.method(:stat), pins: [],
|
|
119
|
+
root: Tools::MemoryRead.memories_dir("system"))
|
|
117
120
|
conversation = Array(conversation)
|
|
118
121
|
view = LLMContextView.new(strategy: strategy)
|
|
119
122
|
pinned = pins.to_set { |pin| [pin.kind, pin.key] }
|
|
120
123
|
items = all_touches(conversation, cwd, view).group_by { |touch| [touch.kind, touch.key] }.map do |(kind, key), group|
|
|
121
|
-
item(kind, key, group, conversation, view, stat, pinned.include?([kind, key]))
|
|
124
|
+
item(kind, key, group, conversation, view, stat, pinned.include?([kind, key]), root)
|
|
122
125
|
end
|
|
123
126
|
Snapshot.new(items: items, at: conversation.size, adds: pending_adds(conversation))
|
|
124
127
|
end
|
|
@@ -189,6 +192,256 @@ module Samagotchi
|
|
|
189
192
|
touches.select { |touch| touch.content && pinned.include?([touch.kind, touch.key]) }.to_set { |touch| touch.run.ref.id }
|
|
190
193
|
end
|
|
191
194
|
|
|
195
|
+
# The reader's lines of a read: +first+ and +last+ line of the file it
|
|
196
|
+
# holds (+last+ from the text, so an end_line past the file is clamped,
|
|
197
|
+
# nil for a partial read's), whether it asked for the +whole+ file, and
|
|
198
|
+
# whether it is +partial+ (LLMContextStale.file_run's rule: a head/tail
|
|
199
|
+
# preview of a big file, an output ToolRunner cut): such a read is shown
|
|
200
|
+
# as is, kept out of the file strip and of merging.
|
|
201
|
+
Lines = Data.define(:first, :last, :whole, :partial)
|
|
202
|
+
|
|
203
|
+
# A memory_read's file, from its stamp (ToolRunner#memory_stamp): the
|
|
204
|
+
# +scope+ it answered from (project or system), the entry's +path+, the
|
|
205
|
+
# model overlay read with it (+overlay_path+) and that overlay's text as
|
|
206
|
+
# appended to the output (+overlay+; only for a read of one name, the
|
|
207
|
+
# rest of the output its +text+). nil fields for a session saved before
|
|
208
|
+
# memory stamps.
|
|
209
|
+
MemoryPart = Data.define(:scope, :path, :overlay_path, :overlay)
|
|
210
|
+
|
|
211
|
+
# One run of an item, as its timeline shows it: the run's chi +tool_id+
|
|
212
|
+
# (ToolIds; +derived+ for a legacy entry's), the tool_response entry's
|
|
213
|
+
# +index+, its global +step+ (LLMContextStale::PairedRun#step), +op+
|
|
214
|
+
# (read, edit, write, memory_read, memory_write, fetch), whether the
|
|
215
|
+
# model is still +sent+ it (#still_sent?: edits and writes always),
|
|
216
|
+
# +dropped+ (the user's applied drop) or +forgotten+ (not sent, not by a
|
|
217
|
+
# drop), and what it holds: a read's +lines+ and +text+ (the output as
|
|
218
|
+
# stored, without its lead or a clamp note), an edit's or write's saved
|
|
219
|
+
# +diff+ (ToolResponse's tool_diffs, never re-diffed: nil for a no-op or
|
|
220
|
+
# a failed snapshot, maybe truncated, {skipped} or {error}), a memory
|
|
221
|
+
# read's whole +text+ with +shared_with+ (the other names it holds) and
|
|
222
|
+
# +memory+, a memory_write's written text, a fetch's text.
|
|
223
|
+
Event = Data.define(:tool_id, :derived, :index, :step, :op, :sent, :dropped, :forgotten, :lines, :diff, :text,
|
|
224
|
+
:memory, :shared_with) do
|
|
225
|
+
def to_h = super.merge(lines: lines&.to_h, memory: memory&.to_h)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# An item's timeline: its identity and its events in conversation order
|
|
229
|
+
# (the reader shows them newest first).
|
|
230
|
+
Timeline = Data.define(:kind, :key, :events) do
|
|
231
|
+
def to_h = { kind: kind, key: key, events: events.map(&:to_h) }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# A stale memory's text now against what the model has: the +text+
|
|
235
|
+
# memory_read would answer now for the names the item's latest read
|
|
236
|
+
# read (nil when an entry is gone), and its +diff+ from what that read
|
|
237
|
+
# sent (TextDiff, EditPreview's shape; "" text for no change).
|
|
238
|
+
Now = Data.define(:text, :diff, :gone)
|
|
239
|
+
|
|
240
|
+
OPS = { "read" => "read", "edit" => "edit", "write" => "write", MEMORY_READ => "memory_read",
|
|
241
|
+
MEMORY_WRITE => "memory_write", WEB_FETCH => "fetch" }.freeze
|
|
242
|
+
# A range read past the file's end says so after its lines (Tools::Read).
|
|
243
|
+
CLAMP_NOTE = /\n\[read: end_line \d+ exceeds \d+ lines; returning lines \d+-\d+\]\z/
|
|
244
|
+
# The timeline of the item +kind+/+key+ (#build's identity): every run
|
|
245
|
+
# that touched it, edits and writes too, by the same walk #build and
|
|
246
|
+
# #outputs_of use (one all_touches), so the projection, the steer and
|
|
247
|
+
# the timeline never disagree on which runs belong to an item. An
|
|
248
|
+
# unknown key has none. Pure; the route adds #memory_now on request.
|
|
249
|
+
# @return [Timeline]
|
|
250
|
+
def timeline_of(conversation, kind:, key:, strategy:, cwd:)
|
|
251
|
+
conversation = Array(conversation)
|
|
252
|
+
view = LLMContextView.new(strategy: strategy)
|
|
253
|
+
events = all_touches(conversation, cwd, view).filter_map do |touch|
|
|
254
|
+
next unless touch.kind == kind && touch.key == key
|
|
255
|
+
|
|
256
|
+
event(touch, conversation, view, cwd)
|
|
257
|
+
end
|
|
258
|
+
Timeline.new(kind: kind, key: key, events: events)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# What the memory +key+'s latest memory_read would answer now, and its
|
|
262
|
+
# diff from what that read sent; nil when no read of it has a stamp (a
|
|
263
|
+
# session saved before memory stamps). +root+: the memories folder
|
|
264
|
+
# (MemoryPaths.system_dir: the projects' folders are under it); a stamped
|
|
265
|
+
# or resolved path outside it is never read, nil then. +read+: File.read,
|
|
266
|
+
# or a stand-in.
|
|
267
|
+
# @return [Now, nil]
|
|
268
|
+
def memory_now(conversation, key:, strategy:, cwd:, root:, read: ->(path) { File.read(path, encoding: "UTF-8") })
|
|
269
|
+
conversation = Array(conversation)
|
|
270
|
+
view = LLMContextView.new(strategy: strategy)
|
|
271
|
+
touch = all_touches(conversation, cwd, view).reverse.find do |candidate|
|
|
272
|
+
candidate.kind == MEMORY && candidate.key == key && candidate.op == "read"
|
|
273
|
+
end
|
|
274
|
+
entries = touch && memory_entries(touch.run, conversation)
|
|
275
|
+
return nil unless entries
|
|
276
|
+
|
|
277
|
+
names = found_names(touch.run)
|
|
278
|
+
current_entries = names.map do |name|
|
|
279
|
+
entry = entries[name]
|
|
280
|
+
return nil unless entry.is_a?(Hash)
|
|
281
|
+
|
|
282
|
+
if resolution_metadata?(entry)
|
|
283
|
+
resolved = resolve_memory(name, entry, system_dir: root)
|
|
284
|
+
if resolved != :stamped_paths
|
|
285
|
+
return Now.new(text: nil, diff: nil, gone: true) unless resolved
|
|
286
|
+
|
|
287
|
+
entry = resolved_memory_entry(resolved)
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
return nil unless memory_paths?(entry, root)
|
|
291
|
+
|
|
292
|
+
entry
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
had = body_of(touch.run.text)
|
|
296
|
+
bodies = names.zip(current_entries).map { |name, entry| memory_body(name, entry, read) }
|
|
297
|
+
return Now.new(text: nil, diff: nil, gone: true) if bodies.any?(&:nil?)
|
|
298
|
+
|
|
299
|
+
# Here, not at load: the testing kit loads WorkingSet and keeps a file budget (sandbox_spec).
|
|
300
|
+
require_relative "text_diff"
|
|
301
|
+
last = had.split(Tools::MemoryRead::SEPARATOR).last.to_s
|
|
302
|
+
bodies << last if last.match?(MISSING)
|
|
303
|
+
now = bodies.join(Tools::MemoryRead::SEPARATOR)
|
|
304
|
+
Now.new(text: now, diff: TextDiff.unified(had, now).merge(new_file: false), gone: false)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Whether a stamp entry's file and its overlay's are .md files inside the
|
|
308
|
+
# memories folder +root+ (a stamp is the session file's: never read
|
|
309
|
+
# what it names elsewhere).
|
|
310
|
+
def memory_paths?(entry, root)
|
|
311
|
+
overlay = field(entry, :overlay)
|
|
312
|
+
paths = [field(entry, :path), overlay.is_a?(Hash) ? field(overlay, :path) : nil].compact
|
|
313
|
+
base = File.join(File.expand_path(root.to_s), "")
|
|
314
|
+
real = File.exist?(base) ? File.join(File.realpath(base), "") : base
|
|
315
|
+
paths.all? do |path|
|
|
316
|
+
expanded = File.expand_path(path.to_s)
|
|
317
|
+
next false unless expanded.start_with?(base) && expanded.end_with?(".md")
|
|
318
|
+
|
|
319
|
+
!File.exist?(expanded) || File.realpath(expanded).start_with?(real)
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def project_dir_within_root?(path, root)
|
|
324
|
+
return true if path.nil?
|
|
325
|
+
|
|
326
|
+
File.expand_path(path.to_s).start_with?(File.join(File.expand_path(root.to_s), ""))
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def resolution_metadata?(entry)
|
|
330
|
+
%i[requested_scope model_key fallback_model_key project_dir].all? do |key|
|
|
331
|
+
entry.key?(key) || entry.key?(key.to_s)
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def resolve_memory(name, entry, system_dir:)
|
|
336
|
+
return :stamped_paths unless project_dir_within_root?(field(entry, :project_dir), system_dir)
|
|
337
|
+
|
|
338
|
+
Tools::MemoryRead.resolve(name, scope: field(entry, :requested_scope), model_key: field(entry, :model_key),
|
|
339
|
+
fallback_model_key: field(entry, :fallback_model_key),
|
|
340
|
+
project_dir: field(entry, :project_dir), system_dir: system_dir)
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def resolved_memory_entry(resolved)
|
|
344
|
+
{ path: resolved.path, overlay: resolved.overlay_path && { path: resolved.overlay_path } }
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def event(touch, conversation, view, cwd)
|
|
348
|
+
run = touch.run
|
|
349
|
+
name = run.call[:name].to_s
|
|
350
|
+
sent = !touch.content || still_sent?(touch, conversation, view)
|
|
351
|
+
dropped = touch.content && dropped?(touch, conversation)
|
|
352
|
+
text = body_of(run.text)
|
|
353
|
+
lines = diff = memory = nil
|
|
354
|
+
case name
|
|
355
|
+
when "read"
|
|
356
|
+
lines = lines_of(run, cwd, text)
|
|
357
|
+
text = text.sub(CLAMP_NOTE, "")
|
|
358
|
+
when "edit", "write"
|
|
359
|
+
diff = saved_diff(conversation[run.index], run.ref.run)
|
|
360
|
+
when MEMORY_READ
|
|
361
|
+
memory = memory_part(touch, conversation)
|
|
362
|
+
if memory&.overlay
|
|
363
|
+
overlay_key = Tools::MemoryRead.overlay_key(touch.key, memory.overlay_path)
|
|
364
|
+
text = text.delete_suffix(overlay_tail(text, overlay_key)) if overlay_key
|
|
365
|
+
end
|
|
366
|
+
when MEMORY_WRITE
|
|
367
|
+
text = run.call[:content].to_s
|
|
368
|
+
end
|
|
369
|
+
Event.new(tool_id: run.ref.id, derived: run.ref.derived?, index: run.index, step: run.step, op: OPS[name],
|
|
370
|
+
sent: sent, dropped: dropped, forgotten: !sent && !dropped, lines: lines, diff: diff, text: text,
|
|
371
|
+
memory: memory, shared_with: touch.content ? shared_with(touch, touch.key) : [])
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
# A run's output without its "[name]" lead.
|
|
375
|
+
def body_of(text) = text.to_s.sub(ToolResponse::LEAD, "")
|
|
376
|
+
|
|
377
|
+
# A read's Lines: its range off LLMContextStale.file_run, its last line
|
|
378
|
+
# off +text+ (the lines it holds).
|
|
379
|
+
def lines_of(run, cwd, text)
|
|
380
|
+
file = LLMContextStale.file_run(run.index, run.ref, run.call, run.text, cwd || Dir.pwd, run.step)
|
|
381
|
+
return Lines.new(first: nil, last: nil, whole: true, partial: true) unless file
|
|
382
|
+
|
|
383
|
+
whole = file.lines == LLMContextStale::WHOLE
|
|
384
|
+
return Lines.new(first: whole ? nil : file.lines.begin, last: nil, whole: whole, partial: true) if file.partial
|
|
385
|
+
|
|
386
|
+
count = text.sub(CLAMP_NOTE, "").lines.size
|
|
387
|
+
first = file.lines.begin
|
|
388
|
+
last = first + [count, 1].max - 1
|
|
389
|
+
last = [last, file.lines.end].min unless file.lines.end.infinite?
|
|
390
|
+
Lines.new(first: first, last: last, whole: whole, partial: false)
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
# The diff saved for the run at +place+ of +entry+: ToolResponse.joined
|
|
394
|
+
# saves an array (one per run, nil for none), .single the bare Hash.
|
|
395
|
+
def saved_diff(entry, place)
|
|
396
|
+
diffs = entry[:tool_diffs] || entry["tool_diffs"]
|
|
397
|
+
diff = diffs.is_a?(Array) ? diffs[place] : diffs
|
|
398
|
+
diff.is_a?(Hash) ? diff.transform_keys(&:to_sym) : nil
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
# The stamp's {name => entry} of a memory_read run, or nil.
|
|
402
|
+
def memory_entries(run, conversation)
|
|
403
|
+
stamp = stamp_hash(conversation[run.index], run.ref.run)
|
|
404
|
+
entries = stamp && field(stamp, :memories)
|
|
405
|
+
entries.is_a?(Hash) ? entries.transform_keys(&:to_s) : nil
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
def memory_part(touch, conversation)
|
|
409
|
+
entries = memory_entries(touch.run, conversation)
|
|
410
|
+
entry = entries && entries[touch.key]
|
|
411
|
+
return nil unless entry.is_a?(Hash)
|
|
412
|
+
|
|
413
|
+
path = field(entry, :path).to_s
|
|
414
|
+
overlay = field(entry, :overlay)
|
|
415
|
+
overlay_path = overlay.is_a?(Hash) ? field(overlay, :path).to_s : nil
|
|
416
|
+
overlay_key = overlay_path && Tools::MemoryRead.overlay_key(touch.key, overlay_path)
|
|
417
|
+
tail = touch.share == 1 && overlay_key ? overlay_tail(body_of(touch.run.text), overlay_key) : ""
|
|
418
|
+
MemoryPart.new(scope: memory_scope(path), path: path, overlay_path: overlay_path,
|
|
419
|
+
overlay: tail.empty? ? nil : tail.sub(Tools::MemoryRead.overlay_prefix(overlay_key), ""))
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
# The overlay memory_read appended to +text+ (its separator and head
|
|
423
|
+
# line included), or "".
|
|
424
|
+
def overlay_tail(text, key) = Tools::MemoryRead.overlay_tail(text, key)
|
|
425
|
+
|
|
426
|
+
# A memory's scope by where its file is: a project's under
|
|
427
|
+
# memories/projects/<key>/, a system one's in memories/.
|
|
428
|
+
def memory_scope(path) = File.basename(File.dirname(path, 2)) == "projects" ? "project" : "system"
|
|
429
|
+
|
|
430
|
+
# What memory_read would answer now for +name+ (its entry and the overlay
|
|
431
|
+
# read with it, as Tools::MemoryRead.call appends it); nil when a file is
|
|
432
|
+
# gone.
|
|
433
|
+
def memory_body(name, entry, read)
|
|
434
|
+
body = read.call(field(entry, :path).to_s)
|
|
435
|
+
overlay = field(entry, :overlay)
|
|
436
|
+
return body unless overlay.is_a?(Hash)
|
|
437
|
+
|
|
438
|
+
overlay_path = field(overlay, :path).to_s
|
|
439
|
+
model_key = Tools::MemoryRead.overlay_key(name, overlay_path)
|
|
440
|
+
model_key ? Tools::MemoryRead.append_overlay(body, read.call(overlay_path), model_key) : body
|
|
441
|
+
rescue SystemCallError
|
|
442
|
+
nil
|
|
443
|
+
end
|
|
444
|
+
|
|
192
445
|
# Every paired run's touches, with what +view+ sends of its output.
|
|
193
446
|
def all_touches(conversation, cwd, view)
|
|
194
447
|
stored = LLMContextStale.paired_runs(conversation)
|
|
@@ -244,7 +497,7 @@ module Samagotchi
|
|
|
244
497
|
names - missing
|
|
245
498
|
end
|
|
246
499
|
|
|
247
|
-
def item(kind, key, group, conversation, view, stat, pinned)
|
|
500
|
+
def item(kind, key, group, conversation, view, stat, pinned, root)
|
|
248
501
|
first = group.first
|
|
249
502
|
contents = group.select(&:content)
|
|
250
503
|
tokens = contents.sum { |touch| touch.sent.length / TokenUsage::CHARS_PER_TOKEN / touch.share }.ceil
|
|
@@ -252,6 +505,8 @@ module Samagotchi
|
|
|
252
505
|
contents.all? { |touch| dropped?(touch, conversation) } ? DROPPED : FORGOTTEN
|
|
253
506
|
elsif kind == FILE && changed?(key, group.last.run, conversation, stat)
|
|
254
507
|
STALE
|
|
508
|
+
elsif kind == MEMORY && memory_changed?(key, group.last.run, conversation, stat, root)
|
|
509
|
+
STALE
|
|
255
510
|
else
|
|
256
511
|
LIVE
|
|
257
512
|
end
|
|
@@ -291,24 +546,80 @@ module Samagotchi
|
|
|
291
546
|
stamp = stamp_of(conversation[run.index], run.ref.run)
|
|
292
547
|
return false unless stamp
|
|
293
548
|
|
|
549
|
+
differs?(path, stamp, stat)
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
# Whether the memory +key+ has changed since +run+'s stamp (the item's
|
|
553
|
+
# latest run): re-resolve stamps with request metadata, then compare the
|
|
554
|
+
# answering files. Older path-only stamps compare their stamped files.
|
|
555
|
+
# No stamp means not changed; a missing entry or overlay is changed.
|
|
556
|
+
def memory_changed?(key, run, conversation, stat, root)
|
|
557
|
+
stamp = stamp_hash(conversation[run.index], run.ref.run)
|
|
558
|
+
return false unless stamp
|
|
559
|
+
|
|
560
|
+
entries = field(stamp, :memories)
|
|
561
|
+
entry = entries.is_a?(Hash) ? field(entries, key) : nil
|
|
562
|
+
return false unless entry.is_a?(Hash)
|
|
563
|
+
|
|
564
|
+
if resolution_metadata?(entry)
|
|
565
|
+
resolved = resolve_memory(key, entry, system_dir: root)
|
|
566
|
+
unless resolved == :stamped_paths
|
|
567
|
+
return true unless resolved
|
|
568
|
+
|
|
569
|
+
return true unless memory_paths?(resolved_memory_entry(resolved), root)
|
|
570
|
+
|
|
571
|
+
stamped_overlay = field(entry, :overlay)
|
|
572
|
+
stamped_overlay_path = stamped_overlay.is_a?(Hash) ? field(stamped_overlay, :path) : nil
|
|
573
|
+
return true unless same_path?(resolved.path, field(entry, :path))
|
|
574
|
+
return true unless same_path?(resolved.overlay_path, stamped_overlay_path)
|
|
575
|
+
end
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
overlay = field(entry, :overlay)
|
|
579
|
+
differs?(field(entry, :path), entry, stat) ||
|
|
580
|
+
(overlay.is_a?(Hash) && differs?(field(overlay, :path), overlay, stat))
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
def same_path?(left, right)
|
|
584
|
+
return left.nil? && right.nil? if left.nil? || right.nil?
|
|
585
|
+
|
|
586
|
+
File.expand_path(left.to_s) == File.expand_path(right.to_s)
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
# Whether the file at +path+ is not what +entry+ ({mtime_ns:, size:}) says
|
|
590
|
+
# it was, in mtime or size.
|
|
591
|
+
def differs?(path, entry, stat)
|
|
294
592
|
now = stat.call(path)
|
|
295
593
|
mtime_ns = (now.mtime.to_i * 1_000_000_000) + now.mtime.nsec
|
|
296
|
-
mtime_ns != field(
|
|
594
|
+
mtime_ns != field(entry, :mtime_ns) || now.size != field(entry, :size)
|
|
297
595
|
rescue SystemCallError
|
|
298
596
|
# Gone (or unreadable): not what the model saw.
|
|
299
597
|
true
|
|
300
598
|
end
|
|
301
599
|
|
|
302
|
-
# +entry+'s tool_stamps at the run's place,
|
|
303
|
-
#
|
|
304
|
-
def
|
|
600
|
+
# +entry+'s tool_stamps at the run's place, whatever its shape (live has
|
|
601
|
+
# symbol keys, a reloaded session string keys); nil when there is none.
|
|
602
|
+
def stamp_hash(entry, place)
|
|
305
603
|
stamps = entry[:tool_stamps]
|
|
306
604
|
stamp = stamps.is_a?(Array) ? stamps[place] : nil
|
|
307
|
-
stamp.is_a?(Hash)
|
|
605
|
+
stamp.is_a?(Hash) ? stamp : nil
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
# A file run's stamp: {path:, mtime_ns:, size:}. A memory_read's stamp
|
|
609
|
+
# has no mtime_ns at its top ({memories: {name => ...}}), so a reader
|
|
610
|
+
# that knows only file stamps - one from before memory stamps, any
|
|
611
|
+
# strategy's - sees none there and never calls a memory stale.
|
|
612
|
+
def stamp_of(entry, place)
|
|
613
|
+
stamp = stamp_hash(entry, place)
|
|
614
|
+
stamp && field(stamp, :mtime_ns) ? stamp : nil
|
|
308
615
|
end
|
|
309
616
|
|
|
310
617
|
def field(hash, key) = hash.key?(key) ? hash[key] : hash[key.to_s]
|
|
311
618
|
|
|
312
|
-
private_class_method :all_touches, :touches, :failed?, :shared_with, :item, :still_sent?, :dropped?, :with_id,
|
|
619
|
+
private_class_method :all_touches, :touches, :failed?, :shared_with, :item, :still_sent?, :dropped?, :with_id,
|
|
620
|
+
:changed?, :memory_changed?, :same_path?, :differs?, :stamp_hash, :stamp_of, :field, :event, :body_of,
|
|
621
|
+
:lines_of, :saved_diff, :memory_entries, :memory_paths?, :project_dir_within_root?,
|
|
622
|
+
:resolution_metadata?, :resolve_memory, :resolved_memory_entry, :memory_part, :overlay_tail,
|
|
623
|
+
:memory_scope, :memory_body
|
|
313
624
|
end
|
|
314
625
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: samagotchi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.172.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dedov
|
|
@@ -366,6 +366,7 @@ files:
|
|
|
366
366
|
- lib/samagotchi/desktop_command.rb
|
|
367
367
|
- lib/samagotchi/edit_preview.rb
|
|
368
368
|
- lib/samagotchi/effective_model.rb
|
|
369
|
+
- lib/samagotchi/empty_answer_error.rb
|
|
369
370
|
- lib/samagotchi/empty_answer_retry.rb
|
|
370
371
|
- lib/samagotchi/engine.rb
|
|
371
372
|
- lib/samagotchi/engine/cards.rb
|
|
@@ -403,6 +404,7 @@ files:
|
|
|
403
404
|
- lib/samagotchi/guardrail_wiring.rb
|
|
404
405
|
- lib/samagotchi/guardrails.rb
|
|
405
406
|
- lib/samagotchi/guardrails/approval.rb
|
|
407
|
+
- lib/samagotchi/guardrails/approval_use.rb
|
|
406
408
|
- lib/samagotchi/guardrails/approvals.rb
|
|
407
409
|
- lib/samagotchi/guardrails/chi_dirs.rb
|
|
408
410
|
- lib/samagotchi/guardrails/child_boundary.rb
|
|
@@ -419,10 +421,10 @@ files:
|
|
|
419
421
|
- lib/samagotchi/guardrails/parent_approvals.rb
|
|
420
422
|
- lib/samagotchi/guardrails/parent_levels.rb
|
|
421
423
|
- lib/samagotchi/guardrails/parent_policy.rb
|
|
424
|
+
- lib/samagotchi/guardrails/participant_refusal.rb
|
|
422
425
|
- lib/samagotchi/guardrails/path_resolve.rb
|
|
423
426
|
- lib/samagotchi/guardrails/protected_paths.rb
|
|
424
427
|
- lib/samagotchi/guardrails/read_only_shell.rb
|
|
425
|
-
- lib/samagotchi/guardrails/review_boundary.rb
|
|
426
428
|
- lib/samagotchi/guardrails/review_paths.rb
|
|
427
429
|
- lib/samagotchi/guardrails/rm_targets.rb
|
|
428
430
|
- lib/samagotchi/guardrails/rules.rb
|
|
@@ -577,8 +579,10 @@ files:
|
|
|
577
579
|
- lib/samagotchi/parent_report.rb
|
|
578
580
|
- lib/samagotchi/participant_exposure.rb
|
|
579
581
|
- lib/samagotchi/participant_messages.rb
|
|
580
|
-
- lib/samagotchi/participant_mode.rb
|
|
581
582
|
- lib/samagotchi/participant_name.rb
|
|
583
|
+
- lib/samagotchi/participant_revise.rb
|
|
584
|
+
- lib/samagotchi/participant_turn_mode.rb
|
|
585
|
+
- lib/samagotchi/participant_uploads.rb
|
|
582
586
|
- lib/samagotchi/participants.rb
|
|
583
587
|
- lib/samagotchi/participants_watch.rb
|
|
584
588
|
- lib/samagotchi/paths.rb
|
|
@@ -647,9 +651,6 @@ files:
|
|
|
647
651
|
- lib/samagotchi/reply_wait/poll.rb
|
|
648
652
|
- lib/samagotchi/reply_wait/target.rb
|
|
649
653
|
- lib/samagotchi/reprefill_meter.rb
|
|
650
|
-
- lib/samagotchi/review_apply.rb
|
|
651
|
-
- lib/samagotchi/review_command.rb
|
|
652
|
-
- lib/samagotchi/review_start.rb
|
|
653
654
|
- lib/samagotchi/revise_anchor.rb
|
|
654
655
|
- lib/samagotchi/row_refs.rb
|
|
655
656
|
- lib/samagotchi/run_options.rb
|
|
@@ -707,6 +708,7 @@ files:
|
|
|
707
708
|
- lib/samagotchi/sessions_command.rb
|
|
708
709
|
- lib/samagotchi/setting_explained.rb
|
|
709
710
|
- lib/samagotchi/share_command.rb
|
|
711
|
+
- lib/samagotchi/share_terms.rb
|
|
710
712
|
- lib/samagotchi/side_judgments.rb
|
|
711
713
|
- lib/samagotchi/side_usage.rb
|
|
712
714
|
- lib/samagotchi/starting_marker.rb
|
|
@@ -835,6 +837,7 @@ files:
|
|
|
835
837
|
- lib/samagotchi/tools/execute.rb
|
|
836
838
|
- lib/samagotchi/tools/forget_outputs.rb
|
|
837
839
|
- lib/samagotchi/tools/index_hint.rb
|
|
840
|
+
- lib/samagotchi/tools/leftovers.rb
|
|
838
841
|
- lib/samagotchi/tools/list_reminders.rb
|
|
839
842
|
- lib/samagotchi/tools/list_schedules.rb
|
|
840
843
|
- lib/samagotchi/tools/list_sessions.rb
|
|
@@ -899,7 +902,9 @@ files:
|
|
|
899
902
|
- lib/samagotchi/web/markdown_renderer.rb
|
|
900
903
|
- lib/samagotchi/web/message_display.rb
|
|
901
904
|
- lib/samagotchi/web/participant_access.rb
|
|
905
|
+
- lib/samagotchi/web/participant_images.rb
|
|
902
906
|
- lib/samagotchi/web/participant_review.rb
|
|
907
|
+
- lib/samagotchi/web/participant_show.rb
|
|
903
908
|
- lib/samagotchi/web/participant_stream_filter.rb
|
|
904
909
|
- lib/samagotchi/web/participant_view.rb
|
|
905
910
|
- lib/samagotchi/web/participants_admin.rb
|
|
@@ -927,6 +932,7 @@ files:
|
|
|
927
932
|
- lib/samagotchi/web/public/bubbles.js
|
|
928
933
|
- lib/samagotchi/web/public/card.js
|
|
929
934
|
- lib/samagotchi/web/public/card_stamps.js
|
|
935
|
+
- lib/samagotchi/web/public/cards_offscreen.js
|
|
930
936
|
- lib/samagotchi/web/public/cards_place.js
|
|
931
937
|
- lib/samagotchi/web/public/chains.js
|
|
932
938
|
- lib/samagotchi/web/public/chip_popover.js
|
|
@@ -998,11 +1004,11 @@ files:
|
|
|
998
1004
|
- lib/samagotchi/web/public/objectives_wiring.js
|
|
999
1005
|
- lib/samagotchi/web/public/owner_claim.js
|
|
1000
1006
|
- lib/samagotchi/web/public/owner_verify.js
|
|
1001
|
-
- lib/samagotchi/web/public/
|
|
1002
|
-
- lib/samagotchi/web/public/
|
|
1003
|
-
- lib/samagotchi/web/public/participant_annotate.js
|
|
1007
|
+
- lib/samagotchi/web/public/participant_bar.js
|
|
1008
|
+
- lib/samagotchi/web/public/participant_main.js
|
|
1004
1009
|
- lib/samagotchi/web/public/participant_model.js
|
|
1005
1010
|
- lib/samagotchi/web/public/participant_names.js
|
|
1011
|
+
- lib/samagotchi/web/public/participant_revise.js
|
|
1006
1012
|
- lib/samagotchi/web/public/participants_panel.js
|
|
1007
1013
|
- lib/samagotchi/web/public/plain_line.js
|
|
1008
1014
|
- lib/samagotchi/web/public/popover_modal.js
|
|
@@ -1021,9 +1027,6 @@ files:
|
|
|
1021
1027
|
- lib/samagotchi/web/public/reload_check.js
|
|
1022
1028
|
- lib/samagotchi/web/public/restore.js
|
|
1023
1029
|
- lib/samagotchi/web/public/resync_reach.js
|
|
1024
|
-
- lib/samagotchi/web/public/review_apply.js
|
|
1025
|
-
- lib/samagotchi/web/public/review_history.js
|
|
1026
|
-
- lib/samagotchi/web/public/review_start.js
|
|
1027
1030
|
- lib/samagotchi/web/public/revise_stack.js
|
|
1028
1031
|
- lib/samagotchi/web/public/revise_switch.js
|
|
1029
1032
|
- lib/samagotchi/web/public/route.js
|
|
@@ -1045,11 +1048,18 @@ files:
|
|
|
1045
1048
|
- lib/samagotchi/web/public/settings_panel.js
|
|
1046
1049
|
- lib/samagotchi/web/public/shell_command.js
|
|
1047
1050
|
- lib/samagotchi/web/public/shown_texts.js
|
|
1051
|
+
- lib/samagotchi/web/public/stage_answer.js
|
|
1048
1052
|
- lib/samagotchi/web/public/stage_asking.js
|
|
1049
1053
|
- lib/samagotchi/web/public/stage_cards.js
|
|
1054
|
+
- lib/samagotchi/web/public/stage_cloud.js
|
|
1055
|
+
- lib/samagotchi/web/public/stage_dom.js
|
|
1050
1056
|
- lib/samagotchi/web/public/stage_frame.js
|
|
1057
|
+
- lib/samagotchi/web/public/stage_handoff.js
|
|
1051
1058
|
- lib/samagotchi/web/public/stage_model.js
|
|
1052
1059
|
- lib/samagotchi/web/public/stage_opened.js
|
|
1060
|
+
- lib/samagotchi/web/public/stage_owner_wait.js
|
|
1061
|
+
- lib/samagotchi/web/public/stage_pager.js
|
|
1062
|
+
- lib/samagotchi/web/public/stage_quiet_clock.js
|
|
1053
1063
|
- lib/samagotchi/web/public/stage_slots.js
|
|
1054
1064
|
- lib/samagotchi/web/public/stage_stall.js
|
|
1055
1065
|
- lib/samagotchi/web/public/stage_view.js
|
|
@@ -1079,7 +1089,6 @@ files:
|
|
|
1079
1089
|
- lib/samagotchi/web/public/token_fragment.js
|
|
1080
1090
|
- lib/samagotchi/web/public/tokens.css
|
|
1081
1091
|
- lib/samagotchi/web/public/toolkit_chip.js
|
|
1082
|
-
- lib/samagotchi/web/public/tools_overview.js
|
|
1083
1092
|
- lib/samagotchi/web/public/turn_block.js
|
|
1084
1093
|
- lib/samagotchi/web/public/turn_drawing.js
|
|
1085
1094
|
- lib/samagotchi/web/public/turn_events.js
|
|
@@ -1101,6 +1110,8 @@ files:
|
|
|
1101
1110
|
- lib/samagotchi/web/public/verify_preset.js
|
|
1102
1111
|
- lib/samagotchi/web/public/verify_target.js
|
|
1103
1112
|
- lib/samagotchi/web/public/version_notices.js
|
|
1113
|
+
- lib/samagotchi/web/public/viewer.js
|
|
1114
|
+
- lib/samagotchi/web/public/viewer_self.js
|
|
1104
1115
|
- lib/samagotchi/web/public/widget_picks.js
|
|
1105
1116
|
- lib/samagotchi/web/public/widget_walk.js
|
|
1106
1117
|
- lib/samagotchi/web/public/widgets.css
|
|
@@ -1108,6 +1119,12 @@ files:
|
|
|
1108
1119
|
- lib/samagotchi/web/public/working_set.js
|
|
1109
1120
|
- lib/samagotchi/web/public/working_set_rail.js
|
|
1110
1121
|
- lib/samagotchi/web/public/working_set_view.js
|
|
1122
|
+
- lib/samagotchi/web/public/ws_cards.js
|
|
1123
|
+
- lib/samagotchi/web/public/ws_peek.js
|
|
1124
|
+
- lib/samagotchi/web/public/ws_preview.css
|
|
1125
|
+
- lib/samagotchi/web/public/ws_reader.js
|
|
1126
|
+
- lib/samagotchi/web/public/ws_timeline.js
|
|
1127
|
+
- lib/samagotchi/web/public/ws_way_in.js
|
|
1111
1128
|
- lib/samagotchi/web/public_url.rb
|
|
1112
1129
|
- lib/samagotchi/web/push.rb
|
|
1113
1130
|
- lib/samagotchi/web/push/attention.rb
|
|
@@ -1134,6 +1151,8 @@ files:
|
|
|
1134
1151
|
- lib/samagotchi/web/update_check.rb
|
|
1135
1152
|
- lib/samagotchi/web/update_ops.rb
|
|
1136
1153
|
- lib/samagotchi/web/verify_fresh_routes.rb
|
|
1154
|
+
- lib/samagotchi/web/viewer.rb
|
|
1155
|
+
- lib/samagotchi/web/working_set_routes.rb
|
|
1137
1156
|
- lib/samagotchi/worker.rb
|
|
1138
1157
|
- lib/samagotchi/worker_boot.rb
|
|
1139
1158
|
- lib/samagotchi/worker_idle_exit.rb
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "review_paths"
|
|
4
|
-
require_relative "../toolkit"
|
|
5
|
-
require_relative "../steer"
|
|
6
|
-
|
|
7
|
-
module Samagotchi
|
|
8
|
-
module Guardrails
|
|
9
|
-
# A participant's turn may only read (D3, D4: it proposes, the owner
|
|
10
|
-
# applies). A core check, on in every guardrails mode and with
|
|
11
|
-
# guardrails.enabled: false, active only while the running turn's author
|
|
12
|
-
# is a participant (GuardrailWiring#checks); the owner's turns never get
|
|
13
|
-
# it. It denies, never asks (nobody on the participant's side may
|
|
14
|
-
# approve, and the owner's approval would be the participant's text
|
|
15
|
-
# acting with the owner's power), every call outside the review kit
|
|
16
|
-
# (Toolkit::REVIEW_TOOLS). Not forget_outputs: it would replace the
|
|
17
|
-
# owner's earlier tool outputs with a note of the participant's, which
|
|
18
|
-
# later owner turns read as their own output, with no review header.
|
|
19
|
-
# read: ReviewPaths: only under the session's project root, never a file of
|
|
20
|
-
# the read denylist (chi's state and config dirs, home secret dirs,
|
|
21
|
-
# project secret files), checked on the path as given and as it
|
|
22
|
-
# resolves (a symlink in the project to ~/.ssh is ~/.ssh);
|
|
23
|
-
# memory_read: the project scope only, named (no fallback to system);
|
|
24
|
-
# anything else, call_tool's real target included: a call_tool of a
|
|
25
|
-
# chi tool (a built-in or a plugin's chi/<name>) reaches the gate as
|
|
26
|
-
# that tool (ToolRunner#unwrapped), so what is left of call_tool is
|
|
27
|
-
# an MCP tool, denied in v1.
|
|
28
|
-
# The declared tools stay the session's (no prompt rebuild per author),
|
|
29
|
-
# so a participant turn's model may still try a write: it is denied
|
|
30
|
-
# here, with the header's "This turn may only read" to keep it rare.
|
|
31
|
-
class ReviewBoundary
|
|
32
|
-
RULE = "review-boundary"
|
|
33
|
-
SOURCE = "core"
|
|
34
|
-
ALLOWED = Toolkit::REVIEW_TOOLS
|
|
35
|
-
PROJECT_SCOPE = "project"
|
|
36
|
-
|
|
37
|
-
ADVICE = "This is a participant's review turn: answer from what you can read and propose any change as " \
|
|
38
|
-
"text or a diff for the owner to apply."
|
|
39
|
-
NOT_IN_KIT = "a participant's review turn may only read (read, memory_read): %s is not allowed"
|
|
40
|
-
OUTSIDE = "a participant's review turn reads only inside the session's project"
|
|
41
|
-
SECRET = "a participant's review turn can't read secrets or chi's own files"
|
|
42
|
-
HOME_ROOT = "a participant's review turn reads only inside a project, and this session's folder is the " \
|
|
43
|
-
"home folder or above it"
|
|
44
|
-
READ_REFUSALS = { ReviewPaths::OUTSIDE => OUTSIDE, ReviewPaths::SECRET => SECRET, ReviewPaths::HOME_ROOT => HOME_ROOT }.freeze
|
|
45
|
-
MEMORY_SCOPE = "a participant's review turn reads project memories only: call memory_read with scope: project"
|
|
46
|
-
|
|
47
|
-
# @param author [#call] → String, nil: the running turn's author
|
|
48
|
-
# (the call's TurnContext#author, GuardrailWiring#review_boundary /
|
|
49
|
-
# #pair_boundary); the check is off unless it is a
|
|
50
|
-
# participant's (Steer.participant_author?)
|
|
51
|
-
# @param root [#call] → String, nil: the session's project root (the
|
|
52
|
-
# work tree top of its folder); nil denies every read
|
|
53
|
-
# @param denied_dirs [#call] → Array<String>: chi's own dirs (state,
|
|
54
|
-
# config: sessions, grants, the web token, memories and .bundles,
|
|
55
|
-
# config.yml, hooks)
|
|
56
|
-
# @param home [#call] → String, nil
|
|
57
|
-
def initialize(author:, root:, denied_dirs: -> { ReviewPaths.chi_dirs }, home: -> { Dir.home })
|
|
58
|
-
@author = author
|
|
59
|
-
@root = root
|
|
60
|
-
@denied_dirs = denied_dirs
|
|
61
|
-
@home = home
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Vote on +verdict+ (its call and targets).
|
|
65
|
-
def check(verdict)
|
|
66
|
-
return verdict unless Steer.participant_author?(@author.call)
|
|
67
|
-
|
|
68
|
-
reason = refusal(verdict)
|
|
69
|
-
return verdict unless reason
|
|
70
|
-
|
|
71
|
-
verdict.deny!(reason, rule: RULE, source: SOURCE, decided_by: "core", advice: ADVICE)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
private
|
|
75
|
-
|
|
76
|
-
def refusal(verdict)
|
|
77
|
-
call = verdict.call || {}
|
|
78
|
-
tool = call[:name].to_s
|
|
79
|
-
return format(NOT_IN_KIT, tool_label(tool, verdict.targets)) unless ALLOWED.include?(tool)
|
|
80
|
-
|
|
81
|
-
case tool
|
|
82
|
-
when "read" then read_refusal(verdict.targets&.paths || [])
|
|
83
|
-
when "memory_read" then MEMORY_SCOPE unless call[:scope].to_s.strip.downcase == PROJECT_SCOPE
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# An MCP tool behind call_tool names what it acts as.
|
|
88
|
-
def tool_label(tool, targets)
|
|
89
|
-
acts_as = targets&.acts_as
|
|
90
|
-
acts_as && acts_as != tool ? "#{tool} (#{acts_as})" : tool
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def read_refusal(paths)
|
|
94
|
-
paths_check = ReviewPaths.new(root: @root.call, denied_dirs: @denied_dirs.call, home: @home.call)
|
|
95
|
-
READ_REFUSALS[paths_check.refusal(paths)]
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|