samagotchi 0.133.0 → 0.135.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 +116 -1
- data/bin/chi +2 -3
- data/docs/architecture.md +6 -3
- data/docs/cli.md +50 -34
- data/docs/configuration.md +9 -6
- data/docs/guardrails.md +146 -13
- data/docs/internals/background-tasks.md +1 -0
- data/docs/internals/engine.md +6 -3
- data/docs/internals/participants.md +7 -6
- data/docs/internals/tool-guardrails.md +2 -0
- data/docs/internals/web-frontend.md +262 -0
- data/docs/plugins.md +2 -1
- data/docs/sessions.md +5 -2
- data/docs/testing.md +34 -4
- data/lib/samagotchi/bridge.rb +11 -6
- data/lib/samagotchi/bridge_client.rb +8 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/chi_home.rb +12 -2
- data/lib/samagotchi/config.rb +0 -2
- data/lib/samagotchi/desktop/macos.rb +19 -4
- data/lib/samagotchi/engine.rb +82 -12
- data/lib/samagotchi/guardrail_wiring.rb +8 -6
- data/lib/samagotchi/guardrails/approval.rb +41 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +158 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +11 -5
- data/lib/samagotchi/guardrails/pair_command.rb +828 -86
- data/lib/samagotchi/guardrails/parent_approvals.rb +13 -16
- data/lib/samagotchi/guardrails/read_only_shell.rb +58 -4
- data/lib/samagotchi/guardrails/shared_git.rb +1 -1
- data/lib/samagotchi/guardrails/shell_git_dirs.rb +7 -2
- data/lib/samagotchi/guardrails/shell_lex.rb +45 -0
- data/lib/samagotchi/guardrails/shell_paths.rb +3 -2
- data/lib/samagotchi/guardrails/targets.rb +8 -3
- data/lib/samagotchi/guardrails_command.rb +13 -10
- data/lib/samagotchi/home_command.rb +22 -6
- data/lib/samagotchi/home_doctor.rb +36 -3
- data/lib/samagotchi/home_notice.rb +8 -1
- data/lib/samagotchi/hooks/loader.rb +5 -0
- data/lib/samagotchi/llm/chat_loop.rb +4 -3
- data/lib/samagotchi/log_line.rb +12 -0
- data/lib/samagotchi/message_parts.rb +1 -1
- data/lib/samagotchi/project_env.rb +3 -11
- data/lib/samagotchi/revise_anchor.rb +33 -0
- data/lib/samagotchi/self_report.rb +3 -1
- data/lib/samagotchi/session_inbox.rb +20 -12
- data/lib/samagotchi/session_manager.rb +13 -11
- data/lib/samagotchi/system_one/approval_question.rb +21 -16
- data/lib/samagotchi/system_one/self_protect.rb +70 -16
- data/lib/samagotchi/testing/waiting.rb +13 -0
- data/lib/samagotchi/toolkit_binding.rb +16 -0
- data/lib/samagotchi/tools/delegate_relay.rb +6 -5
- data/lib/samagotchi/tools/delegate_wait.rb +5 -5
- data/lib/samagotchi/tools/execute.rb +6 -6
- data/lib/samagotchi/tools/output_guardrails.rb +9 -2
- data/lib/samagotchi/tools/read.rb +5 -5
- data/lib/samagotchi/turn_anchors.rb +49 -0
- data/lib/samagotchi/update_command.rb +7 -3
- data/lib/samagotchi/update_hint.rb +6 -1
- data/lib/samagotchi/verify_anchor.rb +5 -5
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +2 -14
- data/lib/samagotchi/web/message_display.rb +17 -1
- data/lib/samagotchi/web/participant_access.rb +2 -2
- data/lib/samagotchi/web/participant_view.rb +8 -0
- data/lib/samagotchi/web/public/activity.js +1 -1
- data/lib/samagotchi/web/public/annotations.js +1 -1
- data/lib/samagotchi/web/public/answer_fold.js +262 -0
- data/lib/samagotchi/web/public/answer_refs.js +2 -0
- data/lib/samagotchi/web/public/app.js +462 -338
- data/lib/samagotchi/web/public/bubbles.js +3 -3
- data/lib/samagotchi/web/public/cards_place.js +9 -4
- data/lib/samagotchi/web/public/chip_popover.js +73 -11
- data/lib/samagotchi/web/public/claim_link.js +4 -2
- data/lib/samagotchi/web/public/composer.css +11 -1
- data/lib/samagotchi/web/public/context_chips.js +9 -6
- data/lib/samagotchi/web/public/data.js +4 -2
- data/lib/samagotchi/web/public/dock_reserve.js +13 -15
- data/lib/samagotchi/web/public/feature_gates.js +33 -0
- data/lib/samagotchi/web/public/history_reveal.js +27 -0
- data/lib/samagotchi/web/public/index.html +82 -37
- data/lib/samagotchi/web/public/latest.js +46 -0
- data/lib/samagotchi/web/public/lists_view.js +15 -13
- data/lib/samagotchi/web/public/live_timing.js +2 -0
- data/lib/samagotchi/web/public/llm_context_chip.js +5 -13
- data/lib/samagotchi/web/public/markdown_place.js +1 -1
- data/lib/samagotchi/web/public/method_api.js +14 -0
- data/lib/samagotchi/web/public/notifications.js +4 -11
- data/lib/samagotchi/web/public/participant.js +11 -6
- data/lib/samagotchi/web/public/participant_names.js +1 -1
- data/lib/samagotchi/web/public/participants_panel.js +4 -2
- data/lib/samagotchi/web/public/project_picker.js +18 -22
- data/lib/samagotchi/web/public/question_cards.js +2 -2
- data/lib/samagotchi/web/public/refs.js +6 -7
- data/lib/samagotchi/web/public/restore.js +2 -0
- data/lib/samagotchi/web/public/review_start.js +1 -1
- data/lib/samagotchi/web/public/revise_stack.js +372 -0
- data/lib/samagotchi/web/public/scope.js +12 -20
- data/lib/samagotchi/web/public/send_turn.js +29 -16
- data/lib/samagotchi/web/public/session_actions.js +15 -14
- data/lib/samagotchi/web/public/session_fields.js +152 -0
- data/lib/samagotchi/web/public/session_payload.js +35 -0
- data/lib/samagotchi/web/public/session_state.js +2 -0
- data/lib/samagotchi/web/public/session_store.js +191 -0
- data/lib/samagotchi/web/public/stage_model.js +4 -4
- data/lib/samagotchi/web/public/stage_view.js +11 -16
- data/lib/samagotchi/web/public/start_page.js +4 -4
- data/lib/samagotchi/web/public/start_settings.js +29 -18
- data/lib/samagotchi/web/public/start_toolkit.js +5 -4
- data/lib/samagotchi/web/public/stream_handlers.js +88 -90
- data/lib/samagotchi/web/public/task_stop.js +1 -1
- data/lib/samagotchi/web/public/timing.js +7 -3
- data/lib/samagotchi/web/public/{turn_view.js → turn_block.js} +46 -101
- data/lib/samagotchi/web/public/turn_events.js +2 -2
- data/lib/samagotchi/web/public/turn_html.js +17 -9
- data/lib/samagotchi/web/public/turn_model.js +6 -6
- data/lib/samagotchi/web/public/turn_range.js +32 -0
- data/lib/samagotchi/web/public/verdict_card.js +5 -13
- data/lib/samagotchi/web/public/verdict_fresh.js +2 -0
- data/lib/samagotchi/web/public/verify_target.js +7 -10
- data/lib/samagotchi/web/public/working_set_view.js +3 -1
- data/lib/samagotchi/web/server.rb +4 -4
- data/lib/samagotchi/web/session_control.rb +2 -2
- data/lib/samagotchi/worker.rb +9 -9
- data/lib/samagotchi/worker_inbound.rb +6 -5
- metadata +16 -3
- data/lib/samagotchi/web/public/hold.js +0 -78
|
@@ -92,7 +92,7 @@ module Samagotchi
|
|
|
92
92
|
# on while the server runs
|
|
93
93
|
# @return [Integer] the exit status
|
|
94
94
|
def self.launch(port: nil, host: nil, scope: "project", start_dir: nil, open_browser: false, markdown: false,
|
|
95
|
-
|
|
95
|
+
annotate_presets: Config::BY_KEY["web.annotate_presets"].default,
|
|
96
96
|
editor: Config::BY_KEY["web.editor"].default, new_token: false,
|
|
97
97
|
working_set: Config::BY_KEY["web.working_set"].default, tunnel: nil, start_dir_from: :flag,
|
|
98
98
|
restarted: false, restart_argv: ["web"], exec: nil)
|
|
@@ -152,7 +152,7 @@ module Samagotchi
|
|
|
152
152
|
# would refuse, or a key store others can read, stops it here,
|
|
153
153
|
# before any tunnel goes up.
|
|
154
154
|
Push.preflight!(public_url)
|
|
155
|
-
options = { port: port, host: host, url: url, open_browser: open_browser, markdown: markdown,
|
|
155
|
+
options = { port: port, host: host, url: url, open_browser: open_browser, markdown: markdown,
|
|
156
156
|
annotate_presets: annotate_presets, editor: editor, lan: lan, working_set: working_set,
|
|
157
157
|
public_url: public_url, start_dir: start_dir }
|
|
158
158
|
started = if plan
|
|
@@ -345,7 +345,7 @@ module Samagotchi
|
|
|
345
345
|
# @return [Boolean, :restart] false when the port was taken (said so on stderr);
|
|
346
346
|
# :restart when the owner requested an in-place process replacement
|
|
347
347
|
def self.start(port: nil, host: nil, url: nil, open_browser: false, state_dir: nil, manager: nil, markdown: false,
|
|
348
|
-
|
|
348
|
+
annotate_presets: Config::BY_KEY["web.annotate_presets"].default, hub: nil, lan: nil,
|
|
349
349
|
editor: Config::BY_KEY["web.editor"].default, token_path: Token.path,
|
|
350
350
|
working_set: Config::BY_KEY["web.working_set"].default, public_url: nil, public_notes: [],
|
|
351
351
|
on_bound: nil, start_dir: Dir.pwd, update_check: nil)
|
|
@@ -362,7 +362,7 @@ module Samagotchi
|
|
|
362
362
|
lan_option = { ip: lan.ip, token: Token::Source.new(token_path) } if lan
|
|
363
363
|
public_token = Token::Source.new(token_path) if public_url
|
|
364
364
|
push = push_runtime(public_url, state_dir)
|
|
365
|
-
app = App.new(manager: manager, state_dir: state_dir, markdown: markdown,
|
|
365
|
+
app = App.new(manager: manager, state_dir: state_dir, markdown: markdown,
|
|
366
366
|
annotate_presets: annotate_presets, editor: editor, hub: hub, lan: lan_option, working_set: working_set,
|
|
367
367
|
public_url: public_url, public_token: public_token, push: push, start_dir: start_dir)
|
|
368
368
|
webrick = nil
|
|
@@ -196,11 +196,11 @@ module Samagotchi
|
|
|
196
196
|
|
|
197
197
|
# no_interrupt: an attached TUI's --no-interrupt (chi --remote --attach).
|
|
198
198
|
# author: the principal's (nil for the owner), never the body's.
|
|
199
|
-
|
|
199
|
+
# anchors: a Verify turn's claim, a Revise turn's draft (TurnAnchors).
|
|
200
200
|
result = SessionManager.deliver_turn(id, prompt: prompt.to_s, client_id: client_id, images: images,
|
|
201
201
|
delivery: delivery, no_interrupt: body["no_interrupt"] == true,
|
|
202
202
|
author: principal(req).author,
|
|
203
|
-
|
|
203
|
+
anchors: TurnAnchors.from(body),
|
|
204
204
|
state_dir: @state_dir, manager: @manager,
|
|
205
205
|
bridge: -> { live_bridge_client(id) })
|
|
206
206
|
case result.status
|
data/lib/samagotchi/worker.rb
CHANGED
|
@@ -678,7 +678,7 @@ module Samagotchi
|
|
|
678
678
|
@initial_turn = true
|
|
679
679
|
fresh = @session.verify_fresh
|
|
680
680
|
run_prompt(WorkerInbound::Prompt.new(text: prompt, origin: TurnOrigin.new(enqueued_id: @session.first_turn_id),
|
|
681
|
-
verify: fresh&.anchor))
|
|
681
|
+
anchors: { verify: fresh&.anchor }))
|
|
682
682
|
ensure
|
|
683
683
|
@initial_turn = false
|
|
684
684
|
end
|
|
@@ -705,10 +705,10 @@ module Samagotchi
|
|
|
705
705
|
@continue_offer.drop(origin)
|
|
706
706
|
@turn_flow.before_prompt_turn
|
|
707
707
|
run_engine_turn(prompt.text, origin: origin, max_iterations: max_iterations(prompt.no_interrupt),
|
|
708
|
-
images: prompt.images, **
|
|
708
|
+
images: prompt.images, **prompt.anchors.kwargs) do |result, error|
|
|
709
709
|
if error
|
|
710
710
|
# The Engine announced :turn_failed (with the error's one line).
|
|
711
|
-
restore_failed_turn([[prompt.text, origin, prompt.images, prompt.
|
|
711
|
+
restore_failed_turn([[prompt.text, origin, prompt.images, prompt.anchors], *@merged_this_turn], error: error)
|
|
712
712
|
else
|
|
713
713
|
@continue_offer.after_turn(result, no_interrupt: prompt.no_interrupt)
|
|
714
714
|
end
|
|
@@ -1395,10 +1395,10 @@ module Samagotchi
|
|
|
1395
1395
|
# or the restored ones, never the one without the other. A turn that
|
|
1396
1396
|
# got somewhere stays instead (TurnFlow#prompt_turn_failed), with the
|
|
1397
1397
|
# prompts it took: nothing goes back.
|
|
1398
|
-
# @param prompts [Array<Array(String, TurnOrigin|nil, Array|nil,
|
|
1399
|
-
# [prompt, origin, images,
|
|
1400
|
-
# back,
|
|
1401
|
-
# a
|
|
1398
|
+
# @param prompts [Array<Array(String, TurnOrigin|nil, Array|nil, TurnAnchors|nil)>]
|
|
1399
|
+
# [prompt, origin, images, anchors] (a web client gets its image chips
|
|
1400
|
+
# back, a Verify turn's claim, so sending it again still records a
|
|
1401
|
+
# verdict, and a Revise turn's draft, so it still stacks)
|
|
1402
1402
|
# @param error [Exception, nil] what failed: its one line stays in the
|
|
1403
1403
|
# conversation as a turn note
|
|
1404
1404
|
# Not saved here: run_engine_turn saves after its block.
|
|
@@ -1406,10 +1406,10 @@ module Samagotchi
|
|
|
1406
1406
|
@engine.synchronize_events do
|
|
1407
1407
|
next if @turn_flow.prompt_turn_failed(error: error) == :kept
|
|
1408
1408
|
|
|
1409
|
-
prompts.each do |prompt, origin, images,
|
|
1409
|
+
prompts.each do |prompt, origin, images, anchors|
|
|
1410
1410
|
restored = { type: :prompt_restored, prompt: prompt, origin: origin.wire }
|
|
1411
1411
|
restored[:images] = images unless Array(images).empty?
|
|
1412
|
-
restored
|
|
1412
|
+
restored.merge!(anchors.to_h) if anchors
|
|
1413
1413
|
@engine.announce(restored)
|
|
1414
1414
|
end
|
|
1415
1415
|
end
|
|
@@ -39,10 +39,11 @@ module Samagotchi
|
|
|
39
39
|
# +no_interrupt+: an offer its turn makes keeps it for its continue
|
|
40
40
|
# turn; +images+: its image refs ({file:, name:}); +delivery+: the wire
|
|
41
41
|
# value the sender asked for ("queue", or nil for the default
|
|
42
|
-
# next_step); +origin+: a TurnOrigin (a Hash is read as one)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
# next_step); +origin+: a TurnOrigin (a Hash is read as one); +anchors+:
|
|
43
|
+
# a Verify turn's claim, a Revise turn's draft (TurnAnchors).
|
|
44
|
+
Prompt = Data.define(:text, :origin, :no_interrupt, :images, :delivery, :anchors) do
|
|
45
|
+
def initialize(text:, origin: nil, no_interrupt: false, images: [], delivery: nil, anchors: nil)
|
|
46
|
+
super(text:, origin: TurnOrigin.of(origin), no_interrupt:, images:, delivery:, anchors: TurnAnchors.from(anchors))
|
|
46
47
|
end
|
|
47
48
|
end
|
|
48
49
|
|
|
@@ -215,7 +216,7 @@ module Samagotchi
|
|
|
215
216
|
return if input.images.empty? && queue_as_command(input.prompt, input.origin, File.basename(input_file))
|
|
216
217
|
|
|
217
218
|
yield Prompt.new(text: input.prompt, origin: input.origin, no_interrupt: input.no_interrupt, images: input.images,
|
|
218
|
-
delivery: input.delivery,
|
|
219
|
+
delivery: input.delivery, anchors: input.anchors)
|
|
219
220
|
ensure
|
|
220
221
|
FileUtils.rm_f(claimed_file)
|
|
221
222
|
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.135.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dedov
|
|
@@ -164,6 +164,7 @@ files:
|
|
|
164
164
|
- docs/internals/prompt-caching.md
|
|
165
165
|
- docs/internals/remote-sessions.md
|
|
166
166
|
- docs/internals/tool-guardrails.md
|
|
167
|
+
- docs/internals/web-frontend.md
|
|
167
168
|
- docs/internals/web-push.md
|
|
168
169
|
- docs/internals/working-set.md
|
|
169
170
|
- docs/memory.md
|
|
@@ -350,6 +351,7 @@ files:
|
|
|
350
351
|
- lib/samagotchi/guardrails/context.rb
|
|
351
352
|
- lib/samagotchi/guardrails/data_readers.rb
|
|
352
353
|
- lib/samagotchi/guardrails/gate.rb
|
|
354
|
+
- lib/samagotchi/guardrails/implicit_writers.rb
|
|
353
355
|
- lib/samagotchi/guardrails/load_failures.rb
|
|
354
356
|
- lib/samagotchi/guardrails/model_size.rb
|
|
355
357
|
- lib/samagotchi/guardrails/outside.rb
|
|
@@ -549,6 +551,7 @@ files:
|
|
|
549
551
|
- lib/samagotchi/review_apply.rb
|
|
550
552
|
- lib/samagotchi/review_command.rb
|
|
551
553
|
- lib/samagotchi/review_start.rb
|
|
554
|
+
- lib/samagotchi/revise_anchor.rb
|
|
552
555
|
- lib/samagotchi/row_refs.rb
|
|
553
556
|
- lib/samagotchi/run_options.rb
|
|
554
557
|
- lib/samagotchi/sampling_settings.rb
|
|
@@ -727,6 +730,7 @@ files:
|
|
|
727
730
|
- lib/samagotchi/tools/tool_path.rb
|
|
728
731
|
- lib/samagotchi/tools/web_fetch.rb
|
|
729
732
|
- lib/samagotchi/tools/write.rb
|
|
733
|
+
- lib/samagotchi/turn_anchors.rb
|
|
730
734
|
- lib/samagotchi/turn_checkpoint.rb
|
|
731
735
|
- lib/samagotchi/turn_endings.rb
|
|
732
736
|
- lib/samagotchi/turn_flow.rb
|
|
@@ -771,6 +775,7 @@ files:
|
|
|
771
775
|
- lib/samagotchi/web/public/annotate_bar.js
|
|
772
776
|
- lib/samagotchi/web/public/annotate_presets.js
|
|
773
777
|
- lib/samagotchi/web/public/annotations.js
|
|
778
|
+
- lib/samagotchi/web/public/answer_fold.js
|
|
774
779
|
- lib/samagotchi/web/public/answer_refs.js
|
|
775
780
|
- lib/samagotchi/web/public/app.js
|
|
776
781
|
- lib/samagotchi/web/public/apple-touch-icon.png
|
|
@@ -801,9 +806,10 @@ files:
|
|
|
801
806
|
- lib/samagotchi/web/public/dock_reserve.js
|
|
802
807
|
- lib/samagotchi/web/public/families_view.js
|
|
803
808
|
- lib/samagotchi/web/public/favicon.svg
|
|
809
|
+
- lib/samagotchi/web/public/feature_gates.js
|
|
804
810
|
- lib/samagotchi/web/public/format.js
|
|
805
811
|
- lib/samagotchi/web/public/forms.css
|
|
806
|
-
- lib/samagotchi/web/public/
|
|
812
|
+
- lib/samagotchi/web/public/history_reveal.js
|
|
807
813
|
- lib/samagotchi/web/public/icons/chi-180.png
|
|
808
814
|
- lib/samagotchi/web/public/icons/chi-192.png
|
|
809
815
|
- lib/samagotchi/web/public/icons/chi-512.png
|
|
@@ -814,6 +820,7 @@ files:
|
|
|
814
820
|
- lib/samagotchi/web/public/init_row.js
|
|
815
821
|
- lib/samagotchi/web/public/keep_focus.js
|
|
816
822
|
- lib/samagotchi/web/public/kept_commands.js
|
|
823
|
+
- lib/samagotchi/web/public/latest.js
|
|
817
824
|
- lib/samagotchi/web/public/level_chip.js
|
|
818
825
|
- lib/samagotchi/web/public/lists_view.js
|
|
819
826
|
- lib/samagotchi/web/public/live_timing.js
|
|
@@ -822,6 +829,7 @@ files:
|
|
|
822
829
|
- lib/samagotchi/web/public/manifest.webmanifest
|
|
823
830
|
- lib/samagotchi/web/public/markdown_place.js
|
|
824
831
|
- lib/samagotchi/web/public/markdown_tip.js
|
|
832
|
+
- lib/samagotchi/web/public/method_api.js
|
|
825
833
|
- lib/samagotchi/web/public/model_pick.js
|
|
826
834
|
- lib/samagotchi/web/public/model_picker.js
|
|
827
835
|
- lib/samagotchi/web/public/notice_links.js
|
|
@@ -849,14 +857,18 @@ files:
|
|
|
849
857
|
- lib/samagotchi/web/public/review_apply.js
|
|
850
858
|
- lib/samagotchi/web/public/review_history.js
|
|
851
859
|
- lib/samagotchi/web/public/review_start.js
|
|
860
|
+
- lib/samagotchi/web/public/revise_stack.js
|
|
852
861
|
- lib/samagotchi/web/public/route.js
|
|
853
862
|
- lib/samagotchi/web/public/scope.js
|
|
854
863
|
- lib/samagotchi/web/public/scroll.js
|
|
855
864
|
- lib/samagotchi/web/public/send_turn.js
|
|
856
865
|
- lib/samagotchi/web/public/sentences.js
|
|
857
866
|
- lib/samagotchi/web/public/session_actions.js
|
|
867
|
+
- lib/samagotchi/web/public/session_fields.js
|
|
868
|
+
- lib/samagotchi/web/public/session_payload.js
|
|
858
869
|
- lib/samagotchi/web/public/session_rename.js
|
|
859
870
|
- lib/samagotchi/web/public/session_state.js
|
|
871
|
+
- lib/samagotchi/web/public/session_store.js
|
|
860
872
|
- lib/samagotchi/web/public/session_title.js
|
|
861
873
|
- lib/samagotchi/web/public/sessions_list.js
|
|
862
874
|
- lib/samagotchi/web/public/shown_texts.js
|
|
@@ -887,10 +899,11 @@ files:
|
|
|
887
899
|
- lib/samagotchi/web/public/tokens.css
|
|
888
900
|
- lib/samagotchi/web/public/toolkit_chip.js
|
|
889
901
|
- lib/samagotchi/web/public/tools_overview.js
|
|
902
|
+
- lib/samagotchi/web/public/turn_block.js
|
|
890
903
|
- lib/samagotchi/web/public/turn_events.js
|
|
891
904
|
- lib/samagotchi/web/public/turn_html.js
|
|
892
905
|
- lib/samagotchi/web/public/turn_model.js
|
|
893
|
-
- lib/samagotchi/web/public/
|
|
906
|
+
- lib/samagotchi/web/public/turn_range.js
|
|
894
907
|
- lib/samagotchi/web/public/unqueue.js
|
|
895
908
|
- lib/samagotchi/web/public/update_notice.js
|
|
896
909
|
- lib/samagotchi/web/public/update_sheet.js
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// The answer pop (D6): the promoted answer bubble is held at the live box's
|
|
2
|
-
// height (`.boxed` + an inline max-height, scrolled to its tail), then grows
|
|
3
|
-
// to its content while the content fades in, then becomes a plain bubble.
|
|
4
|
-
// One hold at a time: a new hold, and reset, finish the previous one first,
|
|
5
|
-
// and a safety timer un-boxes its own bubble whatever happens to the rest, so
|
|
6
|
-
// no bubble is left clipped for good.
|
|
7
|
-
//
|
|
8
|
-
// Timers, not transitionend: under reduced motion and in a hidden tab none
|
|
9
|
-
// fires. rAF only to follow the pop: a hidden tab has none, and finish()
|
|
10
|
-
// follows once more.
|
|
11
|
-
export const HOLD_MS = 1500;
|
|
12
|
-
export const REVEAL_MS = 400;
|
|
13
|
-
export const SAFETY_MS = HOLD_MS + REVEAL_MS + 1000;
|
|
14
|
-
|
|
15
|
-
export function createHold({ isNearBottom, follow, timers = globalThis }) {
|
|
16
|
-
// { bubble, timer, follow, revealing }
|
|
17
|
-
let held = null;
|
|
18
|
-
|
|
19
|
-
function unbox(bubble) {
|
|
20
|
-
bubble.classList.remove("boxed", "revealing");
|
|
21
|
-
bubble.removeAttribute("style");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Hold +bubble+ at +maxHeight+ px until reveal() or HOLD_MS.
|
|
25
|
-
function start(bubble, maxHeight) {
|
|
26
|
-
finish();
|
|
27
|
-
bubble.classList.add("boxed");
|
|
28
|
-
bubble.style.maxHeight = `${maxHeight}px`;
|
|
29
|
-
bubble.scrollTop = bubble.scrollHeight;
|
|
30
|
-
held = {
|
|
31
|
-
bubble,
|
|
32
|
-
timer: timers.setTimeout(reveal, HOLD_MS),
|
|
33
|
-
follow: false,
|
|
34
|
-
};
|
|
35
|
-
timers.setTimeout(() => {
|
|
36
|
-
if (held?.bubble === bubble) finish();
|
|
37
|
-
else unbox(bubble);
|
|
38
|
-
}, SAFETY_MS);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// The pop: the held bubble grows to its content under the CSS transition;
|
|
42
|
-
// the class and the inline style go REVEAL_MS later (reload parity).
|
|
43
|
-
function reveal() {
|
|
44
|
-
if (!held || held.revealing) return;
|
|
45
|
-
timers.clearTimeout(held.timer);
|
|
46
|
-
const { bubble } = held;
|
|
47
|
-
held.revealing = true;
|
|
48
|
-
held.follow = isNearBottom();
|
|
49
|
-
bubble.scrollTop = 0;
|
|
50
|
-
bubble.style.maxHeight = `${bubble.scrollHeight}px`;
|
|
51
|
-
bubble.classList.add("revealing");
|
|
52
|
-
held.timer = timers.setTimeout(finish, REVEAL_MS);
|
|
53
|
-
// Following: the answer's end stays above the dock while it grows,
|
|
54
|
-
// frame by frame, not one jump at the end.
|
|
55
|
-
if (held.follow && timers.requestAnimationFrame) {
|
|
56
|
-
const pin = () => {
|
|
57
|
-
if (held?.bubble !== bubble) return;
|
|
58
|
-
follow();
|
|
59
|
-
timers.requestAnimationFrame(pin);
|
|
60
|
-
};
|
|
61
|
-
timers.requestAnimationFrame(pin);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// The held bubble as a plain answer bubble, at once.
|
|
66
|
-
function finish() {
|
|
67
|
-
if (!held) return;
|
|
68
|
-
// The safety timer stays: it un-boxes its bubble again, a no-op on a
|
|
69
|
-
// plain one.
|
|
70
|
-
timers.clearTimeout(held.timer);
|
|
71
|
-
const { bubble, follow: wasFollowing } = held;
|
|
72
|
-
held = null;
|
|
73
|
-
unbox(bubble);
|
|
74
|
-
if (wasFollowing) follow();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return { start, reveal, finish, get bubble() { return held?.bubble ?? null; } };
|
|
78
|
-
}
|