samagotchi 0.187.0 → 0.189.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 +96 -1
- data/bin/chi +2 -0
- data/docs/architecture.md +13 -7
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +139 -120
- data/docs/cli.md +46 -8
- data/docs/configuration.md +4 -4
- data/docs/context.md +18 -162
- data/docs/guardrails.md +6 -3
- data/docs/hooks.md +2 -1
- data/docs/internals/attached-context.md +19 -37
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/bundles.md +3 -3
- data/docs/internals/engine.md +2 -2
- data/docs/internals/llm-context-forget.md +5 -6
- data/docs/internals/objectives.md +1 -0
- data/docs/internals/pages.md +71 -21
- data/docs/internals/peers.md +149 -0
- data/docs/internals/remote-sessions.md +7 -4
- data/docs/internals/session-lifecycle.md +19 -6
- data/docs/internals/web-frontend.md +63 -39
- data/docs/internals/web-push.md +12 -6
- data/docs/memory.md +1 -1
- data/docs/pages.md +70 -16
- data/docs/peers.md +144 -0
- data/docs/plugins.md +77 -28
- data/docs/releasing.md +1 -1
- data/docs/scheduling.md +71 -8
- data/docs/sessions.md +12 -8
- data/docs/sub-agent.md +5 -5
- data/docs/testing.md +1 -1
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundle_manifest.rb +34 -5
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
- data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
- data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/schedules/manifest.yml +11 -0
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +159 -0
- data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +2 -2
- data/lib/samagotchi/bundles/system/skill_pages.md +9 -4
- data/lib/samagotchi/client_id.rb +15 -1
- data/lib/samagotchi/config.rb +8 -7
- data/lib/samagotchi/context_absorber.rb +23 -277
- data/lib/samagotchi/context_sources.rb +17 -69
- data/lib/samagotchi/engine/messages.rb +12 -1
- data/lib/samagotchi/engine/plugins.rb +1 -1
- data/lib/samagotchi/engine.rb +7 -6
- data/lib/samagotchi/engine_peers.rb +0 -3
- data/lib/samagotchi/guardrail_wiring.rb +2 -0
- data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
- data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
- data/lib/samagotchi/inline_widgets.rb +11 -3
- data/lib/samagotchi/installed_bundles/manifest.rb +8 -1
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/memory_bundle/asset_installer.rb +3 -2
- data/lib/samagotchi/memory_bundle/builder.rb +1 -0
- data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
- data/lib/samagotchi/note_move.rb +3 -1
- data/lib/samagotchi/page_command.rb +25 -13
- data/lib/samagotchi/pages/builder.rb +7 -8
- data/lib/samagotchi/pages/bundled.rb +83 -0
- data/lib/samagotchi/pages/launch.rb +22 -4
- data/lib/samagotchi/pages/runner.rb +7 -2
- data/lib/samagotchi/pages/runtime.rb +83 -0
- data/lib/samagotchi/pages/store.rb +29 -7
- data/lib/samagotchi/pages.rb +47 -3
- data/lib/samagotchi/peer_command.rb +192 -0
- data/lib/samagotchi/peer_continue.rb +105 -0
- data/lib/samagotchi/peer_exchanges.rb +3 -3
- data/lib/samagotchi/peer_mailbox.rb +360 -0
- data/lib/samagotchi/peer_note.rb +208 -0
- data/lib/samagotchi/peer_receipts.rb +247 -0
- data/lib/samagotchi/peer_registry.rb +44 -0
- data/lib/samagotchi/peer_roster.rb +79 -0
- data/lib/samagotchi/peer_say.rb +168 -0
- data/lib/samagotchi/plugin/api.rb +29 -21
- data/lib/samagotchi/plugin/context.rb +7 -0
- data/lib/samagotchi/plugin/loader.rb +3 -3
- data/lib/samagotchi/plugin/peer.rb +175 -64
- data/lib/samagotchi/plugin/peers.rb +70 -0
- data/lib/samagotchi/run_options.rb +3 -2
- data/lib/samagotchi/schedule_command.rb +88 -39
- data/lib/samagotchi/schedule_display.rb +101 -0
- data/lib/samagotchi/schedules/busy_part.rb +146 -0
- data/lib/samagotchi/schedules/edit_part.rb +120 -0
- data/lib/samagotchi/schedules/history_part.rb +51 -0
- data/lib/samagotchi/schedules/listing_part.rb +52 -0
- data/lib/samagotchi/schedules/notices_part.rb +116 -0
- data/lib/samagotchi/schedules/protection_part.rb +103 -0
- data/lib/samagotchi/schedules/recurrence.rb +103 -0
- data/lib/samagotchi/schedules.rb +134 -330
- data/lib/samagotchi/session_access/contract.rb +18 -1
- data/lib/samagotchi/session_access/local.rb +140 -14
- data/lib/samagotchi/session_access/remote.rb +6 -3
- data/lib/samagotchi/session_access/remote_peers.rb +75 -0
- data/lib/samagotchi/session_chain/delete.rb +7 -5
- data/lib/samagotchi/session_continue.rb +12 -0
- data/lib/samagotchi/session_inbox_delivery.rb +5 -2
- data/lib/samagotchi/session_lifecycle/allowed.rb +2 -1
- data/lib/samagotchi/session_lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -3
- data/lib/samagotchi/session_manager/removal.rb +18 -9
- data/lib/samagotchi/session_manager/spawn.rb +2 -1
- data/lib/samagotchi/session_manager.rb +1 -0
- data/lib/samagotchi/session_protection.rb +99 -0
- data/lib/samagotchi/session_retention.rb +21 -6
- data/lib/samagotchi/session_stores.rb +17 -0
- data/lib/samagotchi/sessions_command.rb +4 -0
- data/lib/samagotchi/steer.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
- data/lib/samagotchi/testing/boundary.rb +17 -13
- data/lib/samagotchi/testing/bundle.rb +40 -5
- data/lib/samagotchi/testing/install.rb +4 -4
- data/lib/samagotchi/testing/recording_api.rb +2 -1
- data/lib/samagotchi/tools/cancel_schedule.rb +5 -2
- data/lib/samagotchi/tools/context_read.rb +0 -14
- data/lib/samagotchi/tools/list_schedules.rb +8 -3
- data/lib/samagotchi/turn_outcome.rb +41 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +2 -13
- data/lib/samagotchi/web/message_display.rb +4 -2
- data/lib/samagotchi/web/page_routes.rb +13 -8
- data/lib/samagotchi/web/peer_routes.rb +133 -0
- data/lib/samagotchi/web/public/app.js +23 -29
- data/lib/samagotchi/web/public/bubbles.js +2 -2
- data/lib/samagotchi/web/public/cards_place.js +20 -1
- data/lib/samagotchi/web/public/context_chips.js +45 -46
- data/lib/samagotchi/web/public/history_reveal.js +4 -1
- data/lib/samagotchi/web/public/history_shape.js +3 -2
- data/lib/samagotchi/web/public/index.html +24 -2
- data/lib/samagotchi/web/public/notify.js +1 -1
- data/lib/samagotchi/web/public/owner_claim.js +7 -5
- data/lib/samagotchi/web/public/page_links.js +1 -1
- data/lib/samagotchi/web/public/page_view.js +10 -6
- data/lib/samagotchi/web/public/pages.css +9 -2
- data/lib/samagotchi/web/public/pages_group.js +21 -19
- data/lib/samagotchi/web/public/pages_list.js +73 -0
- data/lib/samagotchi/web/public/pages_model.js +54 -0
- data/lib/samagotchi/web/public/pages_wiring.js +66 -0
- data/lib/samagotchi/web/public/peer_chip.js +60 -74
- data/lib/samagotchi/web/public/peer_data.js +13 -11
- data/lib/samagotchi/web/public/peer_links.js +12 -7
- data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
- data/lib/samagotchi/web/public/peer_note.js +7 -3
- data/lib/samagotchi/web/public/peer_text.js +4 -4
- data/lib/samagotchi/web/public/quiet_notes.js +199 -0
- data/lib/samagotchi/web/public/revise_stack.js +4 -3
- data/lib/samagotchi/web/public/session_view.js +2 -2
- data/lib/samagotchi/web/public/stream_handlers.js +3 -2
- data/lib/samagotchi/web/public/turn_block.js +7 -3
- data/lib/samagotchi/web/public/turn_events.js +6 -0
- data/lib/samagotchi/web/public/views.js +77 -23
- data/lib/samagotchi/web/push/attention.rb +3 -2
- data/lib/samagotchi/web/push/notifier.rb +4 -3
- data/lib/samagotchi/web/server.rb +3 -1
- data/lib/samagotchi/web/session_access_routes.rb +3 -20
- data/lib/samagotchi/web/session_hub.rb +64 -19
- data/lib/samagotchi/worker/leave.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +73 -0
- data/lib/samagotchi/worker/startup.rb +3 -0
- data/lib/samagotchi/worker/wake_turns.rb +20 -5
- data/lib/samagotchi/worker.rb +12 -6
- data/lib/samagotchi/worker_inbound/mail.rb +214 -0
- data/lib/samagotchi/worker_inbound.rb +43 -46
- data/lib/samagotchi/worker_wakes.rb +26 -21
- metadata +35 -2
- data/lib/samagotchi/peer_sources.rb +0 -58
|
@@ -4,7 +4,7 @@ require_relative "../session"
|
|
|
4
4
|
require_relative "../answer_refs"
|
|
5
5
|
require_relative "../answer_tail"
|
|
6
6
|
require_relative "../block_fix/stamp"
|
|
7
|
-
require_relative "../
|
|
7
|
+
require_relative "../peer_note"
|
|
8
8
|
require_relative "../context_note"
|
|
9
9
|
require_relative "../image_store"
|
|
10
10
|
require_relative "../message_parts"
|
|
@@ -180,6 +180,8 @@ module Samagotchi
|
|
|
180
180
|
next unless %w[user assistant].include?(norm_role)
|
|
181
181
|
|
|
182
182
|
message = { role: norm_role, content: stripped, **time_of(m) }
|
|
183
|
+
client_id = m[:client_id] || m["client_id"]
|
|
184
|
+
message[:client_id] = client_id.to_s if norm_role == "user" && client_id
|
|
183
185
|
# Merged into the running turn (Steer::INPUT_KIND): part of it,
|
|
184
186
|
# read by step +step+; a wake turn's report starts its turn
|
|
185
187
|
# (Steer.turn_prompt?). Its sender (a delegate report, chi send):
|
|
@@ -254,7 +256,7 @@ module Samagotchi
|
|
|
254
256
|
def peer_text_html(peer, content)
|
|
255
257
|
return nil unless peer.is_a?(Hash) && (peer["inline"] || peer[:inline]) && @markdown_renderer.available?
|
|
256
258
|
|
|
257
|
-
text = Samagotchi::
|
|
259
|
+
text = Samagotchi::PeerNote.text_of(content)
|
|
258
260
|
text && @markdown_renderer.render(text)
|
|
259
261
|
end
|
|
260
262
|
|
|
@@ -7,7 +7,7 @@ require_relative "../pages/launch"
|
|
|
7
7
|
module Samagotchi
|
|
8
8
|
module Web
|
|
9
9
|
# The pages routes, mixed into App (docs/internals/pages.md, chi web): the
|
|
10
|
-
# list for
|
|
10
|
+
# list for the Pages list and the pages pill, a page as stored (opening runs
|
|
11
11
|
# nothing), Refresh (one run through Pages::Launch, inside the request)
|
|
12
12
|
# and Delete. All the owner's: a participant never sees pages. The name
|
|
13
13
|
# is checked (Pages.valid_name?) before anything builds a path; one that
|
|
@@ -26,18 +26,19 @@ module Samagotchi
|
|
|
26
26
|
private
|
|
27
27
|
|
|
28
28
|
# GET /api/pages: {pages: [{name, title, state, ran_at, failed_at,
|
|
29
|
-
# changed, error_line}]}, by name
|
|
29
|
+
# changed, error_line, bundle}]}, by name (+bundle+: the bundle whose
|
|
30
|
+
# page it is, Pages::Bundled; nil for the owner's own).
|
|
30
31
|
def handle_pages_list(_req)
|
|
31
32
|
rows = Pages::Store.list.map do |page|
|
|
32
33
|
{ name: page.name, title: page.title, state: page.state.to_s, ran_at: page.ran_at, failed_at: page.error&.at,
|
|
33
|
-
changed: page.changed?, error_line: page.error&.line }
|
|
34
|
+
changed: page.changed?, error_line: page.error&.line, bundle: page.bundle }
|
|
34
35
|
end
|
|
35
36
|
json_response(200, { pages: rows })
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
# GET /api/pages/NAME: the page as stored (#page_json); 404 page_missing.
|
|
39
40
|
def handle_page_show(_req, name)
|
|
40
|
-
return page_missing(name) unless Pages.valid_name?(name) &&
|
|
41
|
+
return page_missing(name) unless Pages.valid_name?(name) && Pages.exists?(name)
|
|
41
42
|
|
|
42
43
|
json_response(200, page_json(Pages::Store.read(name)))
|
|
43
44
|
end
|
|
@@ -63,7 +64,8 @@ module Samagotchi
|
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
# DELETE /api/pages/NAME: the script and its result. {removed: NAME};
|
|
66
|
-
# 409 page_busy,
|
|
67
|
+
# 409 page_busy, 409 page_bundled (a bundle's page: Pages::FromBundle),
|
|
68
|
+
# 404 page_missing.
|
|
67
69
|
def handle_page_delete(_req, name)
|
|
68
70
|
return page_missing(name) unless Pages.valid_name?(name)
|
|
69
71
|
|
|
@@ -73,6 +75,8 @@ module Samagotchi
|
|
|
73
75
|
error_response(404, "page_missing", e.message)
|
|
74
76
|
rescue Pages::Busy => e
|
|
75
77
|
error_response(409, "page_busy", e.message)
|
|
78
|
+
rescue Pages::FromBundle => e
|
|
79
|
+
error_response(409, "page_bundled", e.message)
|
|
76
80
|
end
|
|
77
81
|
|
|
78
82
|
def page_missing(name) = error_response(404, "page_missing", Pages::Missing.new(name).message)
|
|
@@ -80,12 +84,13 @@ module Samagotchi
|
|
|
80
84
|
# A page for the view. +changed+: the result came from an older script
|
|
81
85
|
# (Stored#changed?); +changed_after_failure+: the script differs from
|
|
82
86
|
# the one that failed, so the view needs no sha. +script_changed_at+:
|
|
83
|
-
# the script file's mtime.
|
|
84
|
-
#
|
|
87
|
+
# the script file's mtime. +bundle+: the bundle whose page it is (the
|
|
88
|
+
# view offers no Delete), nil for the owner's own. A text block carries
|
|
89
|
+
# +html+ (sanitised) when Markdown rendering is available.
|
|
85
90
|
def page_json(page)
|
|
86
91
|
error = page.error
|
|
87
92
|
{ name: page.name, title: page.title, state: page.state.to_s, ran_at: page.ran_at, duration_ms: page.duration_ms,
|
|
88
|
-
changed: page.changed?,
|
|
93
|
+
changed: page.changed?, bundle: page.bundle,
|
|
89
94
|
changed_after_failure: !error.nil? && !error.script_sha.nil? && !page.current_sha.nil? &&
|
|
90
95
|
error.script_sha != page.current_sha,
|
|
91
96
|
script_changed_at: script_mtime(page.name),
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require_relative "../peer_exchanges"
|
|
5
|
+
require_relative "../peer_mailbox"
|
|
6
|
+
require_relative "../peer_roster"
|
|
7
|
+
require_relative "../peer_say"
|
|
8
|
+
require_relative "request_body"
|
|
9
|
+
|
|
10
|
+
module Samagotchi
|
|
11
|
+
module Web
|
|
12
|
+
# A session's peers, mixed into App, all the owner's: the peers model
|
|
13
|
+
# from the two stores without a worker (GET …/peers), one message's
|
|
14
|
+
# text, Unpair, and a remote's pair and say (SessionAccess::RemotePeers:
|
|
15
|
+
# the say waits here). See docs/internals/peers.md.
|
|
16
|
+
module PeerRoutes
|
|
17
|
+
ROUTES = [
|
|
18
|
+
["GET", %r{\A/api/sessions/([^/]+)/peers\z}, :handle_peers, :owner, :session],
|
|
19
|
+
["GET", %r{\A/api/sessions/([^/]+)/peers/([^/]+)/messages/([^/]+)\z}, :handle_peer_message, :owner, :session],
|
|
20
|
+
["DELETE", %r{\A/api/sessions/([^/]+)/peers/([^/]+)\z}, :handle_peer_unpair, :owner, :session],
|
|
21
|
+
["POST", %r{\A/api/sessions/([^/]+)/peers/([^/]+)/pair\z}, :handle_peer_pair, :owner, :session],
|
|
22
|
+
["POST", %r{\A/api/sessions/([^/]+)/peers/([^/]+)/say\z}, :handle_peer_say, :owner, :session]
|
|
23
|
+
].freeze
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
# GET /api/sessions/:id/peers → {peers: [{name, label, paired_at, from,
|
|
28
|
+
# address, can_send, messages, exchanges}]}: a row per peer with a
|
|
29
|
+
# mailbox folder (the peer chip's only feed). +exchanges+ joins chi's
|
|
30
|
+
# sends (peer_exchanges.jsonl) with the answers: the log's (an older
|
|
31
|
+
# pairing's) and the mailbox's messages (PeerExchanges.joined,
|
|
32
|
+
# unchanged). +messages+: the newest (PeerRoster), with their receipts
|
|
33
|
+
# and the receipt in chi's words (+words+: PeerRoster.state_words,
|
|
34
|
+
# "held · peer turns"); no text anywhere.
|
|
35
|
+
def handle_peers(_req, id)
|
|
36
|
+
@session_class.load(id, state_dir: default_state_dir)
|
|
37
|
+
entries = PeerExchanges.read(id, state_dir: default_state_dir).group_by { |entry| entry["peer"] }
|
|
38
|
+
rows = {}
|
|
39
|
+
entries.each_key { |name| rows[name] ||= peer_row(name) }
|
|
40
|
+
PeerRoster.build(id, state_dir: default_state_dir).each do |peer|
|
|
41
|
+
row = (rows[peer.name] ||= peer_row(peer.name))
|
|
42
|
+
row.merge!(paired_at: peer.paired_at, from: peer.from, address: peer.address,
|
|
43
|
+
can_send: peer.paired? && !peer.address.nil?,
|
|
44
|
+
messages: peer.messages.map { |message| message.to_h.merge("words" => PeerRoster.state_words(message.receipt)) })
|
|
45
|
+
(entries[peer.name] ||= []).concat(answer_entries(peer))
|
|
46
|
+
end
|
|
47
|
+
rows.each_value { |row| row[:exchanges] = PeerExchanges.joined(entries.fetch(row[:name], [])) }
|
|
48
|
+
json_response(200, { peers: rows.values })
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def peer_row(peer)
|
|
52
|
+
{ name: peer, label: PeerMailbox.label(peer), paired_at: nil, from: nil, address: nil, can_send: false, messages: [] }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# A peer's mailbox messages as the exchange log's answer lines.
|
|
56
|
+
def answer_entries(peer)
|
|
57
|
+
peer.messages.reverse.map do |row|
|
|
58
|
+
{ "t" => "answer", "peer" => peer.name, "re" => row.re, "summary" => row.summary, "serial" => row.serial,
|
|
59
|
+
"wake" => row.wake, "at" => row.at }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# GET /api/sessions/:id/peers/:name/messages/:serial → the message
|
|
64
|
+
# (its text) and its receipt; 404 no_message.
|
|
65
|
+
def handle_peer_message(req, id, name, serial)
|
|
66
|
+
@session_class.load(id, state_dir: default_state_dir)
|
|
67
|
+
return invalid_peer(name) unless PeerMailbox.valid_name?(name)
|
|
68
|
+
|
|
69
|
+
box = req.GET["box"].to_s
|
|
70
|
+
expected = PeerReceipts.read(id, state_dir: default_state_dir).peer(name).box
|
|
71
|
+
return error_response(409, "wrong_box", "this message belongs to another session") if !box.empty? && expected != box
|
|
72
|
+
|
|
73
|
+
message = PeerMailbox.message(id, name, serial, state_dir: default_state_dir)
|
|
74
|
+
return error_response(404, "no_message", "no message #{serial.to_s[0, 20]} from #{name}") unless message
|
|
75
|
+
|
|
76
|
+
receipt = PeerReceipts.receipt(id, name, message.serial, state_dir: default_state_dir)
|
|
77
|
+
json_response(200, message.to_h.merge("receipt" => receipt&.to_h))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# DELETE /api/sessions/:id/peers/:name (Unpair) → {unpaired: whether
|
|
81
|
+
# there was a pairing}; the messages stay.
|
|
82
|
+
def handle_peer_unpair(_req, id, name)
|
|
83
|
+
@session_class.load(id, state_dir: default_state_dir)
|
|
84
|
+
return invalid_peer(name) unless PeerMailbox.valid_name?(name)
|
|
85
|
+
|
|
86
|
+
json_response(200, { unpaired: session_access.peer_unpair(id, name) })
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# POST /api/sessions/:id/peers/:name/pair {address, from} → 200
|
|
90
|
+
# {status: "paired", link}; 409 {status: continued (next_id) |
|
|
91
|
+
# old_worker, detail}.
|
|
92
|
+
def handle_peer_pair(req, id, name)
|
|
93
|
+
body = body_hash(req, RequestBody::CONTEXT_PUSH_BODY_LIMIT) or return error_response(400, "invalid_json", "invalid JSON body")
|
|
94
|
+
return invalid_peer(name) unless PeerMailbox.valid_name?(name)
|
|
95
|
+
|
|
96
|
+
address, from = body.values_at("address", "from")
|
|
97
|
+
unless [address, from].all? { |value| value.nil? || value.is_a?(String) }
|
|
98
|
+
return error_response(400, "invalid_fields", "address and from are strings")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
paired = session_access.peer_pair(id, name, address: address, from: from)
|
|
102
|
+
return json_response(200, { status: "paired", link: paired.link.to_h }) if paired.status == :paired
|
|
103
|
+
|
|
104
|
+
json_response(409, { status: paired.status.to_s, next_id: paired.next_id, detail: paired.refusal }.compact)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# POST /api/sessions/:id/peers/:name/say {text, summary, wake, re,
|
|
108
|
+
# wait} → 200 PeerSay (and its line) once the receipt came or the
|
|
109
|
+
# wait (at most PeerSay::WAIT_MAX) ran out; 409 a refused say, the
|
|
110
|
+
# same shape; 400 a bad name, text or wait.
|
|
111
|
+
def handle_peer_say(req, id, name)
|
|
112
|
+
body = body_hash(req, RequestBody::CONTEXT_PUSH_BODY_LIMIT) or return error_response(400, "invalid_json", "invalid JSON body")
|
|
113
|
+
return invalid_peer(name) unless PeerMailbox.valid_name?(name)
|
|
114
|
+
return error_response(400, "missing_fields", "text is required") unless body["text"].is_a?(String)
|
|
115
|
+
|
|
116
|
+
wait = body["wait"] || 0
|
|
117
|
+
unless wait.is_a?(Numeric) && wait.between?(0, PeerSay::WAIT_MAX)
|
|
118
|
+
return error_response(400, "invalid_wait", "wait takes seconds from 0 to #{PeerSay::WAIT_MAX}")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
said = session_access.peer_say(id, name, text: body["text"], summary: string_or_nil(body["summary"]),
|
|
122
|
+
wake: body["wake"] == true, re: string_or_nil(body["re"]), wait: wait)
|
|
123
|
+
json_response(said.received? ? 200 : 409, said.to_h.merge("line" => said.line(name)))
|
|
124
|
+
rescue PeerMailbox::Invalid => e
|
|
125
|
+
error_response(400, "invalid_text", e.message)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def invalid_peer(name) = error_response(400, "invalid_peer", PeerMailbox.name_problem(name))
|
|
129
|
+
|
|
130
|
+
def string_or_nil(value) = value.is_a?(String) ? value : nil
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -73,6 +73,7 @@ import { wireBlockFix } from "./block_fix.js";
|
|
|
73
73
|
import { createWidgetDrawer } from "./inline_widgets.js";
|
|
74
74
|
import { copyText, installCopy } from "./copy.js";
|
|
75
75
|
import { installAnswerFold, sweepAnswerFolds } from "./answer_fold.js";
|
|
76
|
+
import { installQuietNotes } from "./quiet_notes.js";
|
|
76
77
|
import { sweepSessionPrefs } from "./session_prefs.js";
|
|
77
78
|
import { installDetailsMotion } from "./details_motion.js";
|
|
78
79
|
import { answerLabel, installReviseStacks, reviseChipTemplate, reviseWorkerUnavailable } from "./revise_stack.js";
|
|
@@ -83,9 +84,7 @@ import { hasHistory, historyLoader } from "./participant_history.js";
|
|
|
83
84
|
import { createCommandList } from "./command_list.js";
|
|
84
85
|
import { sessionHash } from "./route.js";
|
|
85
86
|
import { createViews } from "./views.js";
|
|
86
|
-
import {
|
|
87
|
-
import { createPagesGroup } from "./pages_group.js";
|
|
88
|
-
import { installPageLinks } from "./page_links.js";
|
|
87
|
+
import { wirePages } from "./pages_wiring.js";
|
|
89
88
|
import { createOwnerClaim } from "./owner_claim.js";
|
|
90
89
|
import { createOwnerVerify } from "./owner_verify.js";
|
|
91
90
|
import { scopeDir, scopeTemplate } from "./scope.js";
|
|
@@ -134,6 +133,7 @@ import { createViewer } from "./viewer.js";
|
|
|
134
133
|
import { createPictureViewer, thumbPicture } from "./picture_viewer.js";
|
|
135
134
|
import { createParticipantMain } from "./participant_main.js";
|
|
136
135
|
import { createPeers } from "./peer_data.js";
|
|
136
|
+
import { getPeerMessage, unpairPeer } from "./peer_mailbox_api.js";
|
|
137
137
|
import { peerStatusCommand } from "./peer_chip.js";
|
|
138
138
|
import { createPeerLinks } from "./peer_links.js";
|
|
139
139
|
import { PARTICIPANT_REVISE_UNAVAILABLE, participantMayRevise, participantReviseUnavailable } from "./participant_revise.js";
|
|
@@ -173,7 +173,7 @@ const infoTextEl = $("#infoText");
|
|
|
173
173
|
// (updateInfoBar redraws #infoText every tick; the chips keep their popover).
|
|
174
174
|
const contextChips = viewer.can("context") ? createContextChips({
|
|
175
175
|
el: $("#contextChips"),
|
|
176
|
-
api: { list: listContext, show: getContext, detach: detachContext },
|
|
176
|
+
api: { list: listContext, show: getContext, detach: detachContext, message: getPeerMessage, unpair: unpairPeer },
|
|
177
177
|
toast: (text) => showToast(text),
|
|
178
178
|
// A paired peer's one chip (peer_chip.js): its exchanges are the peers model's (below).
|
|
179
179
|
peers: () => peers,
|
|
@@ -438,8 +438,8 @@ function findInTurnRoots(selector) {
|
|
|
438
438
|
}
|
|
439
439
|
// The open session's peers (peer_data.js, owner only) and their exchange drawn in the conversation (peer_links.js).
|
|
440
440
|
const peers = contextChips ? createPeers({ sessionId: () => store.selected, onChange: () => { peerLinks.draw(); contextChips.peersChanged(); },
|
|
441
|
-
hasPeer: () =>
|
|
442
|
-
const peerLinks = peers && createPeerLinks({ peers, roots: turnRoots, running: () => liveTurn.running, showText: (name) => contextChips.showText?.(name), renderMarkdown });
|
|
441
|
+
hasPeer: () => true }) : null;
|
|
442
|
+
const peerLinks = peers && createPeerLinks({ peers, roots: turnRoots, running: () => liveTurn.running, showText: (name) => contextChips.showText?.(name), showMessage: (name, serial, box) => contextChips.showMessage?.(name, serial, box), renderMarkdown });
|
|
443
443
|
// The running turn as the page follows it (live_turn.js): whether one
|
|
444
444
|
// runs, its timing line and the turns this page saw end (live_timing.js),
|
|
445
445
|
// its merges' bubble flags, its turn-end reads.
|
|
@@ -547,7 +547,7 @@ turnRoots().forEach((root) => root.addEventListener("click", cards.onCardAction)
|
|
|
547
547
|
// take their functions (the session actions, the send, the stream handlers);
|
|
548
548
|
// the ones made later come in as getters, and each reaches the other lazily.
|
|
549
549
|
const sessionView = createSessionView({
|
|
550
|
-
store, historyEl, getSession,
|
|
550
|
+
store, historyEl, getSession, clientId,
|
|
551
551
|
liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet, wsPreview, gapClock,
|
|
552
552
|
bubbles, cards, markdown: markdownPlace, cardRegistry, peerLinks, pictures,
|
|
553
553
|
capabilities: () => pageCapabilities,
|
|
@@ -630,6 +630,7 @@ function openSessionEvents() {
|
|
|
630
630
|
snapshot: (data) => store.batch(() => {
|
|
631
631
|
versionNotices.notice(data);
|
|
632
632
|
versionNotices.reconnected(data.version);
|
|
633
|
+
pagesUi?.snapshot();
|
|
633
634
|
if (data.chi_update) versionNotices.frame(data.chi_update, { snapshot: true });
|
|
634
635
|
notifications?.noticeSessions("snapshot", data);
|
|
635
636
|
store.update({ sessions: applySessionEvent(store.sessions, "snapshot", data) });
|
|
@@ -650,6 +651,7 @@ function openSessionEvents() {
|
|
|
650
651
|
},
|
|
651
652
|
chi: (data) => versionNotices.notice(data),
|
|
652
653
|
chi_update: (data) => versionNotices.frame(data),
|
|
654
|
+
pages: () => pagesUi?.changed(), // a page script made or removed (pages_wiring.js)
|
|
653
655
|
}, {
|
|
654
656
|
dir: scope.dir,
|
|
655
657
|
onError: () => {
|
|
@@ -778,27 +780,21 @@ window.addEventListener("resize", () => rename.reposition());
|
|
|
778
780
|
|
|
779
781
|
const { confirmDelete, leaveGoneSession, continueSelected, archiveOne, setArchived } = sessionActions;
|
|
780
782
|
|
|
781
|
-
//
|
|
782
|
-
const
|
|
783
|
-
root: $("#pageView"), api, toast: (text) => showToast(text), copyText, back: () => closePage(), gone: () => leavePage(),
|
|
784
|
-
backLabel: () => pageBackLabel(), phone: () => !!window.matchMedia?.("(max-width: 600px)").matches,
|
|
785
|
-
}) : null;
|
|
783
|
+
// The pages capability's parts (pages_wiring.js): the pages pill, the Pages list at #/pages, a page at #/p/NAME, the #/p/ links.
|
|
784
|
+
const pagesUi = wirePages({ viewer, $, api, toast: (text) => showToast(text), copyText, turnRoots, views: () => views });
|
|
786
785
|
// The views by hash: All sessions, a page and the session's own (views.js).
|
|
787
|
-
const {
|
|
788
|
-
allViewOpen, openAllView, closeAllView, leaveAllView, setSessionHash, selectFromHash, applyView,
|
|
789
|
-
pageOpen, openPage, closePage, leavePage, pageBackLabel,
|
|
790
|
-
} = createViews({
|
|
786
|
+
const views = createViews({
|
|
791
787
|
participant, store, lists, topStripEl, pictures, eventsLive: () => !!eventsControl, refresh, updateSessionTitle,
|
|
792
|
-
select, clearSelection, ownerClaim: () => ownerClaim, pages: pageView,
|
|
788
|
+
select, clearSelection, ownerClaim: () => ownerClaim, pages: pagesUi?.pageView ?? null, pagesList: pagesUi?.pagesList ?? null,
|
|
789
|
+
allViewOpened: () => pagesUi?.allViewOpened(),
|
|
793
790
|
});
|
|
794
|
-
|
|
795
|
-
const pagesGroup = pageView && createPagesGroup({ root: $("#pagesGroup"), filterEl: $("#filter"), api, open: (name) => openPage(name) });
|
|
796
|
-
if (pageView) installPageLinks([...turnRoots(), $("#pageView")], { open: (name) => openPage(name) });
|
|
791
|
+
const { allViewOpen, openAllView, closeAllView, leaveAllView, setSessionHash, selectFromHash, applyView, pageOpen, pagesAreaOpen } = views;
|
|
797
792
|
// The page's claim links (owner_claim.js): one opened here, once drawn, and
|
|
798
793
|
// annotate's Copy link.
|
|
799
794
|
const ownerClaim = createOwnerClaim({
|
|
800
795
|
historyEl, store, claimTarget: () => participantsControl?.claimTarget() ?? null,
|
|
801
|
-
toast: (...args) => showToast(...args), copyText, allViewOpen,
|
|
796
|
+
toast: (...args) => showToast(...args), copyText, allViewOpen, pagesAreaOpen,
|
|
797
|
+
home: document.body.dataset.home || "",
|
|
802
798
|
});
|
|
803
799
|
|
|
804
800
|
// The composer's placeholder, hint, buttons and delivery row (composer_mode.js).
|
|
@@ -1294,7 +1290,7 @@ async function handleCancel() {
|
|
|
1294
1290
|
// The typed draft stays in the composer: paste in a session, then + new session
|
|
1295
1291
|
// starts from it (with the model picker). clearSelection leaves #prompt alone.
|
|
1296
1292
|
viewer.control($("#newBtn"), "sessions")?.addEventListener("click", () => {
|
|
1297
|
-
if (allViewOpen() || pageOpen()) leaveAllView("");
|
|
1293
|
+
if (allViewOpen() || pageOpen() || views.listOpen?.()) leaveAllView("");
|
|
1298
1294
|
clearSelection();
|
|
1299
1295
|
startPage.loadModels({ asked: true });
|
|
1300
1296
|
});
|
|
@@ -1488,18 +1484,16 @@ const blockFix = wireBlockFix({ viewer, roots: turnRoots(), store, getSession, c
|
|
|
1488
1484
|
// with their height animated (details_motion.js), in the history and on
|
|
1489
1485
|
// the stage.
|
|
1490
1486
|
installDetailsMotion({ root: document.body, selector: ".turn-work, .bubble.thinking, .bubble.recap" });
|
|
1491
|
-
// Long answers fold by hand (answer_fold.js), per viewer and session.
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
projectRoot: () => store.sessions.find((s) => s.id === store.selected)?.project_root ?? null,
|
|
1496
|
-
});
|
|
1487
|
+
// Long answers fold by hand (answer_fold.js), per viewer and session; background items into a notes row (quiet_notes.js).
|
|
1488
|
+
const projectRoot = () => store.sessions.find((s) => s.id === store.selected)?.project_root ?? null;
|
|
1489
|
+
installAnswerFold({ historyEl, sessionId: () => store.selected, projectRoot });
|
|
1490
|
+
installQuietNotes({ historyEl });
|
|
1497
1491
|
// Revise stacks (revise_stack.js): the superseded versions fold to stubs,
|
|
1498
1492
|
// the top answer gets its version chip, a final answer its Revise button.
|
|
1499
1493
|
reviseStacks = viewer.can("revise") || viewer.can("revise_own_turn") ? installReviseStacks({
|
|
1500
1494
|
historyEl,
|
|
1501
1495
|
sessionId: () => store.selected,
|
|
1502
|
-
projectRoot
|
|
1496
|
+
projectRoot,
|
|
1503
1497
|
running: () => (liveTurn.running ? { turnId: liveTurn.timing.turnId || null } : null),
|
|
1504
1498
|
verifyTurn: (turnId) => (store.current.verdicts || []).some((v) => v.check_turn_id === turnId),
|
|
1505
1499
|
unavailable: reviseUnavailable, unavailableText: reviseOffText,
|
|
@@ -17,8 +17,8 @@ import { TIME_GAP_CLASS, timeGapEl } from "./time_gaps.js";
|
|
|
17
17
|
|
|
18
18
|
// What a session's load places at a turn's prompt from the snapshot
|
|
19
19
|
// (cards_place.js placeSnapshotCards): its cards, answered questions,
|
|
20
|
-
// notices and warnings.
|
|
21
|
-
const SNAPSHOT_PLACED = ".plugin-card, .bubble.question, .bubble.hook-notice, .bubble.guardrail-warning";
|
|
20
|
+
// notices and warnings; and the notes rows over its lines (quiet_notes.js).
|
|
21
|
+
const SNAPSHOT_PLACED = ".plugin-card, .bubble.question, .bubble.hook-notice, .bubble.guardrail-warning, .quiet-notes";
|
|
22
22
|
|
|
23
23
|
export function removeQueuedBubble(bubble) {
|
|
24
24
|
if (!bubble) return;
|
|
@@ -122,13 +122,32 @@ export function createCardsPlace({
|
|
|
122
122
|
else if (entry.type === "question") placeResolvedQuestion(entry, before);
|
|
123
123
|
else if (entry.type === "guardrail_warning") bubbles.showGuardrailWarning(entry.message, entry.label || "guardrails", { before });
|
|
124
124
|
else if (entry.in_turn) placeTurnNotice(entry, before);
|
|
125
|
-
else if (entry.type === "hook_notice") bubbles.showHookNotice(entry, { before });
|
|
125
|
+
else if (entry.type === "hook_notice") bubbles.showHookNotice(entry, { before: afterTurnEnd(before) });
|
|
126
126
|
}
|
|
127
127
|
// A drawn turn's question slot whose question never came (CardStore
|
|
128
128
|
// dropped it, a pending one): nothing in its place.
|
|
129
129
|
historyEl.querySelectorAll("[data-question-slot]").forEach((slot) => slot.remove());
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// Where a between-turn line goes, given +before+ (the next opening, or null
|
|
133
|
+
// for the end): right after the turn that just ended, as live (a notice
|
|
134
|
+
// draws no time divider of its own), so above the next opening's divider
|
|
135
|
+
// and the context notes that came between the turns. It walks back over
|
|
136
|
+
// those and their notes rows (quiet_notes.js; never over earlier lines,
|
|
137
|
+
// cards or questions: several lines keep their order) and returns the
|
|
138
|
+
// first one it walked over, else +before+.
|
|
139
|
+
// Assumes the line came right after a turn (an after_turn hook), not after
|
|
140
|
+
// a later note: an anytime command's line between turns moves above the
|
|
141
|
+
// notes before it too (rare; the e2e reload checks cover it).
|
|
142
|
+
function afterTurnEnd(before) {
|
|
143
|
+
let place = before;
|
|
144
|
+
for (let el = before ? before.previousElementSibling : historyEl.lastElementChild; el; el = el.previousElementSibling) {
|
|
145
|
+
if (!el.matches(".time-gap, .bubble.note:not(.turn-start), .quiet-notes")) break;
|
|
146
|
+
place = el;
|
|
147
|
+
}
|
|
148
|
+
return place;
|
|
149
|
+
}
|
|
150
|
+
|
|
132
151
|
// An in-turn entry (not a question) of a turn the history drew from its
|
|
133
152
|
// drawing (its pieces carry data-drawn; the entry's of_turn, CardStore's).
|
|
134
153
|
function drawnEntry(entry) {
|
|
@@ -12,7 +12,7 @@ import { popoverPlace, SHEET_MAX, sheetPlace } from "./chip_popover.js";
|
|
|
12
12
|
import { focusBack, modalDialog } from "./popover_modal.js";
|
|
13
13
|
import { cantText } from "./format.js";
|
|
14
14
|
import { createLatest } from "./latest.js";
|
|
15
|
-
import { peerChipModel, peerGroups, peerKey, peerPopoverTemplate
|
|
15
|
+
import { peerChipModel, peerGroups, peerKey, peerPopoverTemplate } from "./peer_chip.js";
|
|
16
16
|
|
|
17
17
|
// "now", "3m", "2h", "4d" since an ISO time; "" for none.
|
|
18
18
|
export function ageText(iso, now = Date.now()) {
|
|
@@ -90,13 +90,14 @@ export function popoverTemplate(row, { text = null, now = Date.now() } = {}) {
|
|
|
90
90
|
// so focus stays. The
|
|
91
91
|
// popover behaves as every popover does (popover_modal.js): a modal dialog, its chip's
|
|
92
92
|
// aria-expanded, Esc closes it and focus goes back to the chip.
|
|
93
|
-
// A paired peer
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
93
|
+
// A paired peer is one chip (peer_chip.js), drawn first: +peers+() the
|
|
94
|
+
// peers model (peer_data.js createPeers, GET …/peers: the chip's only feed;
|
|
95
|
+
// null: none, no peer chips), read when a session's chips load, and the
|
|
96
|
+
// chips redrawn on its change (peersChanged); +peerActions+: {status(name):
|
|
97
|
+
// the status card's command line ("/claude") when the session has it, else
|
|
98
|
+
// null; run(line); drawn(id): whether that send's row is in the
|
|
99
|
+
// conversation; jump(id): to it}. +api+ also reads a peer's message
|
|
100
|
+
// (message(id, name, serial)) and ends a pairing (unpair(id, name)).
|
|
100
101
|
// +focusAway+(): where focus goes when a detach or Unpair took the last chip
|
|
101
102
|
// (the composer).
|
|
102
103
|
export function createContextChips({ el, api, toast = () => {}, peers = () => null, peerActions = {},
|
|
@@ -108,10 +109,8 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
108
109
|
let openKey = null;
|
|
109
110
|
// Only the newest list read for the open session is drawn (latest.js).
|
|
110
111
|
const latest = createLatest(() => sessionId);
|
|
111
|
-
// The open popover's text once read (view text; a peer's:
|
|
112
|
+
// The open popover's text once read (view text; a peer's: a message's).
|
|
112
113
|
let text = null;
|
|
113
|
-
// The peers the last read named (a new one reads the peers model again).
|
|
114
|
-
let peerNames = "";
|
|
115
114
|
const pop = doc.createElement("div");
|
|
116
115
|
pop.id = "contextPopover";
|
|
117
116
|
pop.className = "ctx-popover";
|
|
@@ -119,14 +118,14 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
119
118
|
doc.body.appendChild(pop);
|
|
120
119
|
modalDialog(pop, { isOpen: () => openKey !== null, doc });
|
|
121
120
|
|
|
122
|
-
const groups = () => peerGroups(
|
|
121
|
+
const groups = () => peerGroups(peers()?.peers?.() || []);
|
|
123
122
|
const groupOf = (key) => groups().find((group) => group.key === key) || null;
|
|
124
123
|
const exchangesOf = (name) => peers()?.peer?.(name)?.exchanges || [];
|
|
125
124
|
const rowOf = (name) => rows.find((r) => r.name === name) || null;
|
|
126
125
|
|
|
127
126
|
function chips(now = Date.now()) {
|
|
128
127
|
const peerChips = groups().map((group) => peerChipModel(group, exchangesOf(group.name), now));
|
|
129
|
-
return [...peerChips, ...chipModel(
|
|
128
|
+
return [...peerChips, ...chipModel(rows, now)];
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
function drawChips() {
|
|
@@ -166,17 +165,14 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
166
165
|
draw();
|
|
167
166
|
// An open popover follows its row, but not while it shows the text.
|
|
168
167
|
follow();
|
|
169
|
-
// The peers
|
|
170
|
-
// conversation's read if loaded or in flight)
|
|
171
|
-
|
|
172
|
-
if (names && (loading || names !== peerNames)) peers()?.refresh?.({ reuse: loading });
|
|
173
|
-
peerNames = names;
|
|
168
|
+
// The peers for their chips: at a session's open (reuse the
|
|
169
|
+
// conversation's read if loaded or in flight).
|
|
170
|
+
if (loading) peers()?.refresh?.({ reuse: true });
|
|
174
171
|
}
|
|
175
172
|
|
|
176
173
|
function load(id) {
|
|
177
174
|
sessionId = id;
|
|
178
175
|
rows = [];
|
|
179
|
-
peerNames = "";
|
|
180
176
|
close();
|
|
181
177
|
return refresh({ loading: true });
|
|
182
178
|
}
|
|
@@ -184,7 +180,6 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
184
180
|
function clear() {
|
|
185
181
|
sessionId = null;
|
|
186
182
|
rows = [];
|
|
187
|
-
peerNames = "";
|
|
188
183
|
close();
|
|
189
184
|
}
|
|
190
185
|
|
|
@@ -259,13 +254,17 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
259
254
|
if (key !== null) back([...el.querySelectorAll(".ctx-chip[data-name]")].find((chip) => chip.dataset.name === key));
|
|
260
255
|
}
|
|
261
256
|
|
|
262
|
-
|
|
257
|
+
// The open popover's text: a source's, or a peer's message (+serial+;
|
|
258
|
+
// default its newest).
|
|
259
|
+
async function viewText(serial = null, box = null) {
|
|
263
260
|
const key = openKey;
|
|
264
261
|
if (!key) return;
|
|
265
|
-
|
|
266
|
-
const
|
|
262
|
+
const peer = groupOf(key);
|
|
263
|
+
const number = peer ? serial ?? peer.peer.messages?.[0]?.serial : null;
|
|
264
|
+
const name = peer ? `${peer.label}'s message #${number}` : key;
|
|
265
|
+
if (peer && (number === null || number === undefined)) return;
|
|
267
266
|
try {
|
|
268
|
-
const data = await api.
|
|
267
|
+
const data = peer ? await api.message(sessionId, peer.name, number, box) : await api.show(sessionId, key);
|
|
269
268
|
if (key !== openKey) return;
|
|
270
269
|
const group = groupOf(key);
|
|
271
270
|
const row = group ? null : rowOf(key);
|
|
@@ -295,25 +294,21 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
296
|
|
|
298
|
-
// Unpair: one confirm, then
|
|
299
|
-
//
|
|
300
|
-
// into "answers only" over a half unpair).
|
|
297
|
+
// Unpair: one confirm, then the pairing ends (DELETE …/peers/NAME; its
|
|
298
|
+
// messages stay) and the peers are read again: the chip goes.
|
|
301
299
|
async function unpair() {
|
|
302
300
|
const group = groupOf(openKey);
|
|
303
301
|
if (!group) return;
|
|
304
|
-
|
|
305
|
-
if (!win.confirm(`Unpair ${group.label}? This detaches ${legs.join(" and ")} from this session.`)) return;
|
|
302
|
+
if (!win.confirm(`Unpair ${group.label}? chi stops sending to it; its messages stay.`)) return;
|
|
306
303
|
const id = sessionId;
|
|
307
304
|
close();
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
toast(cantText(`detach ${name}`, e));
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
305
|
+
try {
|
|
306
|
+
await api.unpair(id, group.name);
|
|
307
|
+
} catch (e) {
|
|
308
|
+
toast(cantText(`unpair ${group.label}`, e));
|
|
315
309
|
}
|
|
316
|
-
await refresh();
|
|
310
|
+
await peers()?.refresh?.();
|
|
311
|
+
drawChips();
|
|
317
312
|
focusAfterRemoval();
|
|
318
313
|
}
|
|
319
314
|
|
|
@@ -367,22 +362,26 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
367
362
|
// The ages move on by themselves.
|
|
368
363
|
win.setInterval(() => { if (rows.length) drawChips(); }, 60_000);
|
|
369
364
|
|
|
370
|
-
// +
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
function showText(name) {
|
|
365
|
+
// The popover of chip +key+ on its text (+serial+: a peer's message), at
|
|
366
|
+
// its chip. In a task of its own: the click that asks would close it on
|
|
367
|
+
// its way to the document.
|
|
368
|
+
function showAt(key, serial = null, box = null) {
|
|
375
369
|
setTimeout(() => {
|
|
376
|
-
const leg = rowOf(name);
|
|
377
|
-
const key = leg?.peer && groupOf(peerKey(leg.peer)) ? peerKey(leg.peer) : name;
|
|
378
370
|
const chip = [...el.querySelectorAll(".ctx-chip[data-name]")].find((c) => c.dataset.name === key);
|
|
379
371
|
if (!chip) return;
|
|
380
372
|
chip.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
381
373
|
if (openKey !== key) open(key, chip);
|
|
382
|
-
if (openKey === key && text === null) viewText();
|
|
374
|
+
if (openKey === key && text === null) viewText(serial, box);
|
|
383
375
|
}, 0);
|
|
384
376
|
}
|
|
385
377
|
|
|
378
|
+
// +name+'s popover on its text: an older peer answer's "Read the full
|
|
379
|
+
// answer" (peer_links.js; its context source, an ordinary chip now).
|
|
380
|
+
const showText = (name) => showAt(name);
|
|
381
|
+
// Peer +name+'s chip on its message +serial+ (a mailbox note's "Read the
|
|
382
|
+
// full answer", peer_links.js).
|
|
383
|
+
const showMessage = (name, serial, box) => showAt(peerKey(name), serial, box);
|
|
384
|
+
|
|
386
385
|
// The peers model read again: the chips and an open peer's popover follow it.
|
|
387
386
|
function peersChanged() {
|
|
388
387
|
if (!sessionId) return;
|
|
@@ -390,5 +389,5 @@ export function createContextChips({ el, api, toast = () => {}, peers = () => nu
|
|
|
390
389
|
if (groupOf(openKey)) follow();
|
|
391
390
|
}
|
|
392
391
|
|
|
393
|
-
return { load, clear, refresh, close, showText, peersChanged, get rows() { return rows; } };
|
|
392
|
+
return { load, clear, refresh, close, showText, showMessage, peersChanged, get rows() { return rows; } };
|
|
394
393
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// step, a diff), an answer or a delegate report folded (answer_fold.js: its row follows
|
|
4
4
|
// the bubble's class; the jump's unfold isn't saved), a superseded version
|
|
5
5
|
// of a Revise stack (revise_stack.js: its stub opens, not saved), a drawn
|
|
6
|
-
// block's source (block_source.js).
|
|
6
|
+
// block's source (block_source.js), a closed notes row (quiet_notes.js: it
|
|
7
|
+
// opens, never stored). Every
|
|
7
8
|
// jump goes through it (claim_link.js showClaim, refs.js showRow and so the
|
|
8
9
|
// working set's step tags, verdict_card.js "View check"), so a new way to
|
|
9
10
|
// hide history is opened in one place.
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
|
|
15
16
|
import { revealBlockSource } from "./block_source.js";
|
|
16
17
|
import { openStubOver } from "./revise_stack.js";
|
|
18
|
+
import { revealQuiet } from "./quiet_notes.js";
|
|
17
19
|
|
|
18
20
|
// Opens each closed <details> that holds +el+ (not +el+ itself: a fold the
|
|
19
21
|
// caller means to open it opens itself) and unfolds the folded answer that
|
|
@@ -21,6 +23,7 @@ import { openStubOver } from "./revise_stack.js";
|
|
|
21
23
|
export function revealInHistory(el) {
|
|
22
24
|
if (!el) return null;
|
|
23
25
|
openStubOver(el);
|
|
26
|
+
revealQuiet(el);
|
|
24
27
|
revealBlockSource(el);
|
|
25
28
|
el.closest?.(".bubble.folded")?.classList.remove("folded");
|
|
26
29
|
for (let details = el.parentElement?.closest("details"); details; details = details.parentElement?.closest("details")) {
|