samagotchi 0.153.0 → 0.154.1
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 +42 -1
- data/README.md +2 -3
- data/bin/chi +23 -24
- data/docs/architecture.md +30 -33
- data/docs/broadcast.md +5 -5
- data/docs/bundles.md +9 -12
- data/docs/cli.md +82 -96
- data/docs/configuration.md +27 -26
- data/docs/context.md +3 -3
- data/docs/desktop.md +1 -1
- data/docs/guardrails.md +8 -10
- data/docs/hooks.md +9 -9
- data/docs/internals/attached-context.md +2 -2
- data/docs/internals/background-tasks.md +3 -4
- data/docs/internals/block-renderers.md +4 -0
- data/docs/internals/bridge.md +21 -8
- data/docs/internals/context-telemetry.md +1 -1
- data/docs/internals/engine.md +33 -7
- data/docs/internals/objectives.md +6 -5
- data/docs/internals/participants.md +7 -7
- data/docs/internals/prompt-caching.md +4 -2
- data/docs/internals/remote-sessions.md +7 -7
- data/docs/internals/web-frontend.md +2 -2
- data/docs/internals/web-push.md +1 -1
- data/docs/memory.md +2 -2
- data/docs/plugins.md +23 -28
- data/docs/sessions.md +24 -24
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +1 -1
- data/docs/testing.md +31 -6
- data/lib/samagotchi/answer_text.rb +33 -0
- data/lib/samagotchi/bridge/card_places.rb +56 -7
- data/lib/samagotchi/bridge/card_store.rb +24 -9
- data/lib/samagotchi/bridge.rb +52 -32
- data/lib/samagotchi/bridge_client.rb +19 -14
- data/lib/samagotchi/broadcast/recipients.rb +2 -2
- data/lib/samagotchi/broadcast/triage.rb +1 -1
- data/lib/samagotchi/broadcast_command.rb +5 -5
- data/lib/samagotchi/bundle_command/try/command.rb +1 -1
- data/lib/samagotchi/bundle_command/try/run.rb +1 -1
- data/lib/samagotchi/bundle_command/try/trace.rb +1 -1
- data/lib/samagotchi/bundle_command.rb +2 -2
- data/lib/samagotchi/bundles/btw/manifest.yml +2 -2
- data/lib/samagotchi/bundles/btw/plugin.rb +1 -1
- data/lib/samagotchi/bundles/coordinator/manifest.yml +2 -2
- data/lib/samagotchi/bundles/coordinator/plugin.rb +3 -2
- data/lib/samagotchi/bundles/decision-card/manifest.yml +4 -4
- data/lib/samagotchi/bundles/decision-card/plugin.rb +1 -9
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +3 -3
- data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/plugin.rb +3 -2
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +3 -4
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +1 -1
- data/lib/samagotchi/child_move.rb +3 -3
- data/lib/samagotchi/commands/registry.rb +6 -6
- data/lib/samagotchi/composer_route.rb +4 -5
- data/lib/samagotchi/config.rb +14 -12
- data/lib/samagotchi/context_candidate_choice.rb +1 -1
- data/lib/samagotchi/context_candidates.rb +4 -3
- data/lib/samagotchi/continue_offer.rb +1 -1
- data/lib/samagotchi/debug_log.rb +1 -1
- data/lib/samagotchi/degrade.rb +75 -0
- data/lib/samagotchi/desktop/macos/ChiRunner.swift +3 -3
- data/lib/samagotchi/engine/cards.rb +87 -0
- data/lib/samagotchi/engine/context_judge.rb +138 -0
- data/lib/samagotchi/engine/events.rb +131 -0
- data/lib/samagotchi/engine/guardrails.rb +87 -0
- data/lib/samagotchi/engine/hooks.rb +119 -0
- data/lib/samagotchi/engine/messages.rb +124 -0
- data/lib/samagotchi/engine/model_settings.rb +127 -0
- data/lib/samagotchi/engine/models.rb +261 -0
- data/lib/samagotchi/engine/objectives.rb +116 -0
- data/lib/samagotchi/engine/participants.rb +86 -0
- data/lib/samagotchi/engine/plugins.rb +208 -0
- data/lib/samagotchi/engine/questions.rb +98 -0
- data/lib/samagotchi/engine/recap.rb +130 -0
- data/lib/samagotchi/engine/session.rb +131 -0
- data/lib/samagotchi/engine/side_requests.rb +135 -0
- data/lib/samagotchi/engine/steering.rb +134 -0
- data/lib/samagotchi/engine/toolkit.rb +269 -0
- data/lib/samagotchi/engine/turn_end.rb +180 -0
- data/lib/samagotchi/engine/turn_helpers.rb +160 -0
- data/lib/samagotchi/engine/verify.rb +153 -0
- data/lib/samagotchi/engine.rb +62 -2646
- data/lib/samagotchi/engine_snapshots.rb +9 -8
- data/lib/samagotchi/grants.rb +575 -0
- data/lib/samagotchi/guardrail_wiring.rb +2 -2
- data/lib/samagotchi/guardrails/context.rb +2 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +2 -2
- data/lib/samagotchi/guardrails/parent_policy.rb +2 -2
- data/lib/samagotchi/hook_routes.rb +3 -3
- data/lib/samagotchi/idle_recap.rb +7 -6
- data/lib/samagotchi/idle_reminders.rb +3 -4
- data/lib/samagotchi/iteration_limit.rb +2 -2
- data/lib/samagotchi/kernel_loop.rb +13 -13
- data/lib/samagotchi/launch_mode.rb +13 -32
- data/lib/samagotchi/level_setting_command.rb +3 -2
- data/lib/samagotchi/llm/chat_loop.rb +3 -1
- data/lib/samagotchi/llm_context_command.rb +3 -2
- data/lib/samagotchi/log.rb +7 -7
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/log_path.rb +1 -1
- data/lib/samagotchi/note_command.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +18 -8
- data/lib/samagotchi/objectives.rb +24 -3
- data/lib/samagotchi/objectives_check.rb +8 -27
- data/lib/samagotchi/objectives_command.rb +4 -69
- data/lib/samagotchi/objectives_edit.rb +87 -0
- data/lib/samagotchi/output_formatter.rb +7 -1
- data/lib/samagotchi/owner_lock.rb +7 -1
- data/lib/samagotchi/parent_answers_command.rb +5 -4
- data/lib/samagotchi/participant_exposure.rb +42 -0
- data/lib/samagotchi/participant_mode.rb +1 -1
- data/lib/samagotchi/participant_name.rb +1 -1
- data/lib/samagotchi/participants.rb +17 -17
- data/lib/samagotchi/participants_watch.rb +1 -1
- data/lib/samagotchi/plugin/api.rb +3 -2
- data/lib/samagotchi/plugin/context.rb +21 -7
- data/lib/samagotchi/plugin/peer.rb +2 -1
- data/lib/samagotchi/plugin/sessions.rb +6 -4
- data/lib/samagotchi/plugin_tasks.rb +1 -2
- data/lib/samagotchi/private_files.rb +29 -0
- data/lib/samagotchi/project_env.rb +2 -2
- data/lib/samagotchi/question_desk.rb +8 -7
- data/lib/samagotchi/recap_command.rb +2 -1
- data/lib/samagotchi/recap_setup.rb +1 -1
- data/lib/samagotchi/recap_store.rb +1 -1
- data/lib/samagotchi/redact.rb +86 -0
- data/lib/samagotchi/reminder_queue.rb +2 -2
- data/lib/samagotchi/remote_attach_command.rb +1 -1
- data/lib/samagotchi/reply_wait/poll.rb +2 -2
- data/lib/samagotchi/review_start.rb +1 -1
- data/lib/samagotchi/run_options.rb +6 -6
- data/lib/samagotchi/self_report.rb +42 -39
- data/lib/samagotchi/send_command/busy.rb +1 -1
- data/lib/samagotchi/send_command.rb +4 -1
- data/lib/samagotchi/session.rb +11 -2
- data/lib/samagotchi/session_access/contract.rb +3 -3
- data/lib/samagotchi/session_access/local.rb +9 -9
- data/lib/samagotchi/session_access/remote.rb +17 -7
- data/lib/samagotchi/session_access.rb +4 -4
- data/lib/samagotchi/session_archive_command.rb +2 -2
- data/lib/samagotchi/session_chain.rb +8 -6
- data/lib/samagotchi/session_commands.rb +45 -48
- data/lib/samagotchi/session_continue.rb +1 -1
- data/lib/samagotchi/session_delete_command.rb +4 -4
- data/lib/samagotchi/session_manager.rb +67 -49
- data/lib/samagotchi/session_metrics.rb +2 -2
- data/lib/samagotchi/session_model_settings.rb +3 -2
- data/lib/samagotchi/session_participants.rb +1 -1
- data/lib/samagotchi/session_retention.rb +27 -7
- data/lib/samagotchi/sessions_command.rb +4 -4
- data/lib/samagotchi/share_command.rb +10 -10
- data/lib/samagotchi/steer.rb +13 -2
- data/lib/samagotchi/stream_event.rb +22 -0
- data/lib/samagotchi/system_prompt.rb +154 -145
- data/lib/samagotchi/task_watch.rb +1 -1
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +72 -10
- data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +12 -9
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +16 -0
- data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -3
- data/lib/samagotchi/terminal_ui/attached_loop.rb +17 -8
- data/lib/samagotchi/terminal_ui/attached_view.rb +1 -11
- data/lib/samagotchi/terminal_ui/event_renderer.rb +3 -5
- data/lib/samagotchi/terminal_ui/formatting.rb +7 -7
- data/lib/samagotchi/terminal_ui/input_support.rb +17 -22
- data/lib/samagotchi/terminal_ui/join_replay.rb +16 -12
- data/lib/samagotchi/terminal_ui/line_reader.rb +2 -2
- data/lib/samagotchi/terminal_ui/live_region.rb +2 -2
- data/lib/samagotchi/terminal_ui/log_tail.rb +135 -0
- data/lib/samagotchi/terminal_ui/one_shot_sink.rb +2 -2
- data/lib/samagotchi/terminal_ui/plain_surface.rb +1 -1
- data/lib/samagotchi/terminal_ui/question_prompt.rb +4 -5
- data/lib/samagotchi/terminal_ui/reline_seam.rb +2 -12
- data/lib/samagotchi/terminal_ui/status_row.rb +6 -14
- data/lib/samagotchi/terminal_ui.rb +142 -1387
- data/lib/samagotchi/title_command.rb +2 -2
- data/lib/samagotchi/tool_runner.rb +15 -16
- data/lib/samagotchi/toolkit_command.rb +2 -1
- data/lib/samagotchi/tools/delegate.rb +3 -1
- data/lib/samagotchi/tools/delegate_cursor.rb +3 -3
- data/lib/samagotchi/tools/delegate_wait.rb +1 -1
- data/lib/samagotchi/tools/objectives_tool.rb +2 -2
- data/lib/samagotchi/tools/send_note.rb +2 -1
- data/lib/samagotchi/turn_endings.rb +2 -2
- data/lib/samagotchi/turn_flow.rb +11 -7
- data/lib/samagotchi/update_hint.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +42 -51
- data/lib/samagotchi/web/message_display.rb +7 -0
- data/lib/samagotchi/web/participant_access.rb +2 -2
- data/lib/samagotchi/web/participant_review.rb +5 -5
- data/lib/samagotchi/web/participant_stream_filter.rb +8 -8
- data/lib/samagotchi/web/participant_view.rb +2 -82
- data/lib/samagotchi/web/participants_admin.rb +1 -1
- data/lib/samagotchi/web/public/block_host.js +35 -8
- data/lib/samagotchi/web/public/block_renderers.css +9 -5
- data/lib/samagotchi/web/public/card_stamps.js +27 -0
- data/lib/samagotchi/web/public/cards_place.js +5 -3
- data/lib/samagotchi/web/public/chains.js +2 -2
- data/lib/samagotchi/web/public/claim_link.js +4 -4
- data/lib/samagotchi/web/public/composer_mode.js +1 -1
- data/lib/samagotchi/web/public/format.js +4 -3
- data/lib/samagotchi/web/public/turn_html.js +8 -4
- data/lib/samagotchi/web/push/store.rb +1 -1
- data/lib/samagotchi/web/session_access_routes.rb +13 -4
- data/lib/samagotchi/web/session_control.rb +12 -8
- data/lib/samagotchi/web/session_create.rb +1 -1
- data/lib/samagotchi/web/session_hub.rb +2 -2
- data/lib/samagotchi/web/session_show.rb +6 -2
- data/lib/samagotchi/web/session_summary.rb +1 -1
- data/lib/samagotchi/worker.rb +103 -9
- data/lib/samagotchi/worker_link.rb +3 -3
- data/lib/samagotchi/working_set_command.rb +3 -2
- data/lib/samagotchi.rb +0 -1
- metadata +31 -7
- data/lib/samagotchi/pending_input_queue.rb +0 -55
- data/lib/samagotchi/terminal_ui/between_turns.rb +0 -138
- data/lib/samagotchi/terminal_ui/repl_input.rb +0 -152
- data/lib/samagotchi/web/grants.rb +0 -575
- data/lib/samagotchi/web/participant_exposure.rb +0 -44
- data/lib/samagotchi/web/private_files.rb +0 -31
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "monitor"
|
|
4
|
-
require_relative "line_reader"
|
|
5
|
-
|
|
6
|
-
module Samagotchi
|
|
7
|
-
class TerminalUI
|
|
8
|
-
# The REPL's input on a terminal: one LineReader keeps a prompt open for
|
|
9
|
-
# the whole session, turns included, and this routes what it reads. A
|
|
10
|
-
# line goes to a question waiting at the prompt (asked at ? ), to
|
|
11
|
-
# the running turn when its handler takes it (steering), else to the
|
|
12
|
-
# inbox the REPL loop takes its next line from.
|
|
13
|
-
class ReplInput
|
|
14
|
-
# @param prompt [#call] -> the prompt when no question waits
|
|
15
|
-
# @param read [#call] (prompt, prefill) -> line (nil = Ctrl-D)
|
|
16
|
-
# @param surface [Surface] the editor slot a dropped read leaves is
|
|
17
|
-
# cleared under its lock
|
|
18
|
-
def initialize(prompt:, read:, surface:)
|
|
19
|
-
@prompt = prompt
|
|
20
|
-
@read = read
|
|
21
|
-
@surface = surface
|
|
22
|
-
@inbox = Thread::Queue.new
|
|
23
|
-
# Lines a turn left over: they come before the inbox.
|
|
24
|
-
@front = []
|
|
25
|
-
@turn = nil
|
|
26
|
-
@lock = Monitor.new
|
|
27
|
-
@answers = nil
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def start(prefill: nil)
|
|
31
|
-
@reader = LineReader.new(self, prompt: method(:prompt_text), read: @read, prefill: prefill).start
|
|
32
|
-
self
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def open? = @reader&.alive? || false
|
|
36
|
-
|
|
37
|
-
def stop
|
|
38
|
-
@reader&.stop
|
|
39
|
-
@surface.clear_slot(:editor)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# From the reader thread: [:line, text] or [:interrupt, info].
|
|
43
|
-
def <<(item)
|
|
44
|
-
@lock.synchronize do
|
|
45
|
-
next @answers << item if @answers
|
|
46
|
-
|
|
47
|
-
taken = @turn && item.first == :line && @turn.call(item.last)
|
|
48
|
-
# Not now: the line goes back into the prompt.
|
|
49
|
-
next @reader&.prefill_next(item.last) if taken == :back
|
|
50
|
-
next if taken
|
|
51
|
-
|
|
52
|
-
@inbox << item
|
|
53
|
-
end
|
|
54
|
-
self
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# @return [Array, nil] the next item, nil after +timeout+ seconds
|
|
58
|
-
def pop(timeout:)
|
|
59
|
-
@lock.synchronize { return @front.shift unless @front.empty? }
|
|
60
|
-
@inbox.pop(timeout: timeout)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# While a turn runs, +handler+ (line -> truthy when it took the line,
|
|
64
|
-
# :back to put it back into the prompt) sees each line first. Once it ends, +leftovers+ (-> lines it took that the
|
|
65
|
-
# turn never merged) come next, in order, before anything in the inbox.
|
|
66
|
-
def during_turn(handler, leftovers:)
|
|
67
|
-
@lock.synchronize { @turn = handler }
|
|
68
|
-
yield
|
|
69
|
-
ensure
|
|
70
|
-
@lock.synchronize do
|
|
71
|
-
@turn = nil
|
|
72
|
-
@front.concat(Array(leftovers.call).map { |line| [:line, line] })
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def prompt_text
|
|
77
|
-
@lock.synchronize { @answers ? @choice_prompt : @prompt.call }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Start the open read again when its prompt changed (a continue offer
|
|
81
|
-
# came or went); what was typed is kept.
|
|
82
|
-
def sync_prompt
|
|
83
|
-
return unless open?
|
|
84
|
-
|
|
85
|
-
with_surface_lock do
|
|
86
|
-
next if @reader.current == prompt_text
|
|
87
|
-
|
|
88
|
-
@surface.clear_slot(:editor)
|
|
89
|
-
@reader.reprompt(keep_text: true)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Put +text+ into the open prompt, unless something is typed there.
|
|
94
|
-
# @return [Boolean] whether it went in
|
|
95
|
-
def prefill(text) = open? && @reader.prefill(text)
|
|
96
|
-
|
|
97
|
-
# What the open prompt holds, nil when none is open: a line typed
|
|
98
|
-
# ahead there is the next turn's input.
|
|
99
|
-
def typed_text = @reader&.typed_text
|
|
100
|
-
|
|
101
|
-
# Whether the next turn's input is already here: text typed ahead at
|
|
102
|
-
# the open prompt, or a line a turn took as steering but never merged
|
|
103
|
-
# (it runs as the next turn).
|
|
104
|
-
def waiting_input?
|
|
105
|
-
@lock.synchronize { return true unless @front.empty? }
|
|
106
|
-
|
|
107
|
-
!typed_text.to_s.strip.empty?
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# A question answered at the open prompt: the lines submitted from now
|
|
111
|
-
# on go to it, at the ? prompt. What was typed at the prompt is put aside
|
|
112
|
-
# and comes back once the question closes.
|
|
113
|
-
# @yield [Thread::Queue] the answers ([:line, text] or [:interrupt, info])
|
|
114
|
-
# A prompt closed by Ctrl-D mid-turn (the REPL exits after the turn)
|
|
115
|
-
# opens for the question and closes again after it.
|
|
116
|
-
def ask(choice_prompt)
|
|
117
|
-
was_open = open?
|
|
118
|
-
typed = was_open ? @reader.typed_text : nil
|
|
119
|
-
answers = Thread::Queue.new
|
|
120
|
-
@lock.synchronize do
|
|
121
|
-
@answers = answers
|
|
122
|
-
@choice_prompt = choice_prompt
|
|
123
|
-
end
|
|
124
|
-
was_open ? reprompt : start
|
|
125
|
-
yield answers
|
|
126
|
-
ensure
|
|
127
|
-
@lock.synchronize { @answers = nil }
|
|
128
|
-
if !was_open
|
|
129
|
-
stop
|
|
130
|
-
elsif open?
|
|
131
|
-
reprompt(prefill: typed)
|
|
132
|
-
else
|
|
133
|
-
# Ctrl-D at the question ended the reader: start it again.
|
|
134
|
-
start(prefill: typed)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
private
|
|
139
|
-
|
|
140
|
-
def reprompt(prefill: nil)
|
|
141
|
-
with_surface_lock do
|
|
142
|
-
@surface.clear_slot(:editor)
|
|
143
|
-
@reader.reprompt(prefill: prefill)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def with_surface_lock(&)
|
|
148
|
-
@surface.respond_to?(:synchronize) ? @surface.synchronize(&) : yield
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
end
|