samagotchi 0.183.0 → 0.185.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.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +84 -1
  3. data/docs/architecture.md +12 -11
  4. data/docs/bundles.md +63 -36
  5. data/docs/cli.md +10 -1
  6. data/docs/configuration.md +3 -2
  7. data/docs/context.md +76 -10
  8. data/docs/guardrails.md +7 -2
  9. data/docs/hooks.md +1 -0
  10. data/docs/internals/block-renderers.md +4 -2
  11. data/docs/internals/bridge.md +7 -3
  12. data/docs/internals/bundles.md +6 -2
  13. data/docs/internals/engine.md +2 -1
  14. data/docs/internals/llm-context-forget.md +6 -0
  15. data/docs/internals/participants.md +5 -2
  16. data/docs/internals/prompt-caching.md +8 -1
  17. data/docs/internals/remote-sessions.md +22 -4
  18. data/docs/internals/session-lifecycle.md +1 -1
  19. data/docs/internals/web-frontend.md +37 -15
  20. data/docs/internals/web-push.md +11 -0
  21. data/docs/internals/working-set.md +238 -6
  22. data/docs/mcp-server.md +11 -3
  23. data/docs/memory.md +2 -1
  24. data/docs/plugins.md +6 -6
  25. data/docs/scheduling.md +19 -0
  26. data/docs/sessions.md +13 -3
  27. data/docs/sub-agent.md +48 -3
  28. data/docs/thin-clients.md +38 -12
  29. data/lib/samagotchi/agent_caller.rb +97 -0
  30. data/lib/samagotchi/bridge.rb +7 -7
  31. data/lib/samagotchi/bridge_client.rb +12 -4
  32. data/lib/samagotchi/bundle_command/check.rb +20 -2
  33. data/lib/samagotchi/bundle_manifest.rb +5 -1
  34. data/lib/samagotchi/bundles/claude-peer/manifest.yml +14 -8
  35. data/lib/samagotchi/bundles/claude-peer/plugin.rb +3 -3
  36. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +49 -30
  37. data/lib/samagotchi/bundles/claude-peer/scripts/pair +2 -2
  38. data/lib/samagotchi/bundles/claude-peer/scripts/pair-remote +123 -0
  39. data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +11 -3
  40. data/lib/samagotchi/bundles/codex-peer/manifest.yml +10 -8
  41. data/lib/samagotchi/bundles/codex-peer/plugin.rb +3 -3
  42. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +29 -8
  43. data/lib/samagotchi/bundles/codex-peer/scripts/pair +1 -1
  44. data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +11 -3
  45. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  46. data/lib/samagotchi/bundles/mcp/http_client.rb +96 -54
  47. data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
  48. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  49. data/lib/samagotchi/bundles/system/self_map.md +9 -2
  50. data/lib/samagotchi/client_id.rb +61 -1
  51. data/lib/samagotchi/command_intake.rb +16 -8
  52. data/lib/samagotchi/context_absorber.rb +212 -46
  53. data/lib/samagotchi/delivery.rb +15 -0
  54. data/lib/samagotchi/driver_command.rb +68 -0
  55. data/lib/samagotchi/engine/block_fix.rb +2 -2
  56. data/lib/samagotchi/engine/session.rb +14 -6
  57. data/lib/samagotchi/engine/turn_helpers.rb +4 -3
  58. data/lib/samagotchi/engine.rb +13 -5
  59. data/lib/samagotchi/engine_peers.rb +6 -0
  60. data/lib/samagotchi/guardrails/pair_boundary.rb +1 -1
  61. data/lib/samagotchi/mcp_command.rb +7 -2
  62. data/lib/samagotchi/mcp_server/http.rb +3 -3
  63. data/lib/samagotchi/mcp_server/protocol.rb +23 -4
  64. data/lib/samagotchi/mcp_server/stdio.rb +1 -0
  65. data/lib/samagotchi/mcp_server/tools.rb +11 -4
  66. data/lib/samagotchi/model_notes.rb +34 -12
  67. data/lib/samagotchi/objectives_track.rb +2 -1
  68. data/lib/samagotchi/owner_prompt.rb +5 -1
  69. data/lib/samagotchi/parent_report.rb +9 -5
  70. data/lib/samagotchi/plugin/peer.rb +10 -4
  71. data/lib/samagotchi/prompt_files.rb +11 -4
  72. data/lib/samagotchi/prompt_layout.rb +88 -0
  73. data/lib/samagotchi/prompt_part.rb +82 -20
  74. data/lib/samagotchi/reply_wait.rb +16 -4
  75. data/lib/samagotchi/schedule_command.rb +18 -4
  76. data/lib/samagotchi/schedules.rb +49 -14
  77. data/lib/samagotchi/send_command/parent_gate.rb +3 -1
  78. data/lib/samagotchi/send_command.rb +45 -8
  79. data/lib/samagotchi/session.rb +9 -1
  80. data/lib/samagotchi/session_access/ask.rb +58 -14
  81. data/lib/samagotchi/session_access/contract.rb +2 -0
  82. data/lib/samagotchi/session_access/exchange.rb +5 -2
  83. data/lib/samagotchi/session_access/local.rb +13 -3
  84. data/lib/samagotchi/session_access/remote.rb +18 -2
  85. data/lib/samagotchi/session_access.rb +4 -2
  86. data/lib/samagotchi/session_command_catalog.rb +8 -0
  87. data/lib/samagotchi/session_commands.rb +9 -0
  88. data/lib/samagotchi/session_continue.rb +4 -1
  89. data/lib/samagotchi/session_inbox.rb +17 -0
  90. data/lib/samagotchi/session_inbox_delivery.rb +4 -2
  91. data/lib/samagotchi/session_manager/delivery.rb +58 -9
  92. data/lib/samagotchi/session_manager/spawn.rb +7 -1
  93. data/lib/samagotchi/steer.rb +95 -20
  94. data/lib/samagotchi/system_prompt.rb +196 -161
  95. data/lib/samagotchi/terminal_ui/formatting.rb +12 -2
  96. data/lib/samagotchi/tool_activity.rb +4 -0
  97. data/lib/samagotchi/tool_declarations.rb +22 -1
  98. data/lib/samagotchi/tool_names.rb +4 -0
  99. data/lib/samagotchi/toolkit.rb +3 -2
  100. data/lib/samagotchi/tools/ask_session.rb +208 -0
  101. data/lib/samagotchi/tools/builtin_calls.rb +1 -0
  102. data/lib/samagotchi/tools/builtins.rb +5 -0
  103. data/lib/samagotchi/tools/memory.rb +11 -3
  104. data/lib/samagotchi/turn_checkpoint.rb +19 -2
  105. data/lib/samagotchi/turn_stages/context_judge.rb +3 -1
  106. data/lib/samagotchi/turn_stages/objectives.rb +4 -2
  107. data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +3 -0
  108. data/lib/samagotchi/turn_stages/warmup.rb +2 -2
  109. data/lib/samagotchi/version.rb +1 -1
  110. data/lib/samagotchi/visitor.rb +37 -0
  111. data/lib/samagotchi/web/app.rb +2 -3
  112. data/lib/samagotchi/web/ask_routes.rb +95 -23
  113. data/lib/samagotchi/web/mcp_route.rb +7 -4
  114. data/lib/samagotchi/web/message_display.rb +15 -2
  115. data/lib/samagotchi/web/public/app.js +1 -1
  116. data/lib/samagotchi/web/public/block_fix.js +11 -3
  117. data/lib/samagotchi/web/public/delete_sheet.js +20 -18
  118. data/lib/samagotchi/web/public/history_shape.js +3 -1
  119. data/lib/samagotchi/web/public/index.html +8 -0
  120. data/lib/samagotchi/web/public/peer_links.js +27 -4
  121. data/lib/samagotchi/web/public/peer_note.js +19 -3
  122. data/lib/samagotchi/web/public/peer_text.js +45 -0
  123. data/lib/samagotchi/web/public/picture_regions.js +2 -2
  124. data/lib/samagotchi/web/public/removal_sheet_model.js +3 -4
  125. data/lib/samagotchi/web/public/running_tasks.js +0 -16
  126. data/lib/samagotchi/web/public/session_actions.js +0 -9
  127. data/lib/samagotchi/web/public/turn_events.js +19 -0
  128. data/lib/samagotchi/web/public/working_set_view.js +178 -23
  129. data/lib/samagotchi/web/public/ws_part_peek.js +277 -0
  130. data/lib/samagotchi/web/public/ws_peek.js +3 -1
  131. data/lib/samagotchi/web/public/ws_preview.css +30 -0
  132. data/lib/samagotchi/web/public/ws_reader.js +7 -3
  133. data/lib/samagotchi/web/public/ws_sections.js +37 -7
  134. data/lib/samagotchi/web/push/notifier.rb +33 -6
  135. data/lib/samagotchi/web/server.rb +1 -1
  136. data/lib/samagotchi/web/session_control.rb +1 -1
  137. data/lib/samagotchi/web/session_create.rb +11 -7
  138. data/lib/samagotchi/web/session_hub.rb +26 -4
  139. data/lib/samagotchi/web/working_set_routes.rb +93 -5
  140. data/lib/samagotchi/worker/command_queue.rb +5 -2
  141. data/lib/samagotchi/worker/senders.rb +79 -0
  142. data/lib/samagotchi/worker.rb +21 -18
  143. data/lib/samagotchi/worker_inbound.rb +12 -4
  144. data/lib/samagotchi/worker_link.rb +2 -2
  145. data/lib/samagotchi/worker_participant_gate.rb +1 -3
  146. data/lib/samagotchi/worker_wakes.rb +12 -0
  147. data/lib/samagotchi/working_set.rb +162 -90
  148. data/lib/samagotchi/working_set_locator.rb +221 -0
  149. data/lib/samagotchi/working_set_own_changes.rb +221 -0
  150. data/lib/samagotchi/working_set_part.rb +281 -0
  151. metadata +13 -1
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "delegate"
4
+ require_relative "../bridge_client"
5
+ require_relative "../agent_caller"
4
6
  require_relative "../client_id"
5
7
  require_relative "../reply_wait"
6
8
  require_relative "../session"
@@ -25,9 +27,18 @@ module Samagotchi
25
27
  # One ask answers within this many seconds from its request's start,
26
28
  # whatever it waits for (a continue in flight, the Bridge of a worker
27
29
  # starting, the wait's slice): a proxy or a Shortcut with a 60 s limit
28
- # is safe. Only the post to a live worker isn't drawn from it: it is
29
- # instant unless the worker hangs (BridgeClient's 25 s deadline).
30
+ # is safe. The post to a live worker draws on it too (#ask_bridge), but
31
+ # never under POST_FLOOR, so a call ends within about 44 s.
30
32
  ASK_MAX_SECONDS = 35.0
33
+ # The shortest read a post to a live worker gets (#ask_bridge),
34
+ # however little of the deadline is left: a healthy but loaded worker
35
+ # still reads the message in time.
36
+ POST_FLOOR = 8.0
37
+ # The fewest seconds the post's body deadline leaves before its read
38
+ # times out (BridgeClient's deadline_margin): a worker that took the
39
+ # turn just in time still has that long to answer 202, so a 504 means
40
+ # it was not taken.
41
+ POST_MARGIN = 2.5
31
42
  # A wait route answers within this many seconds (status timeout); the
32
43
  # client asks again until its own --timeout. SessionAccessRoutes'
33
44
  # (which includes this module) too.
@@ -35,6 +46,14 @@ module Samagotchi
35
46
  # GET /api/info's feature: this chi web has the ask route, wait
36
47
  # tokens, the answer's wait and the create's token.
37
48
  ASK_FEATURE = "ask"
49
+ # A line a worker may run as a session command (#ask_request_id): a
50
+ # / name (Registry::UNKNOWN_COMMAND_WORD's shape, which every
51
+ # built-in a worker runs and a bundle's COMMAND_NAME fits) followed by
52
+ # whitespace or nothing, so "/Users/x/a.rb fails" is a message. A !
53
+ # line is the shell's.
54
+ COMMAND_SHAPE = %r{\A/[A-Za-z][A-Za-z0-9_-]*(?:\s|\z)}
55
+ # An ask's request_id: 1 to 128 printable ASCII characters.
56
+ REQUEST_ID = /\A[\x21-\x7e]{1,128}\z/
38
57
  # The wait body's own fields, which a token replaces.
39
58
  TOKEN_EXCLUDES = %w[cursor baseline turn queued ended_before owner_grace].freeze
40
59
 
@@ -62,15 +81,20 @@ module Samagotchi
62
81
 
63
82
  private
64
83
 
65
- # POST /api/sessions/:id/ask {prompt, timeout, queue, client_id}: the
66
- # message delivered (to a chain's newest link; a running session
67
- # queues it as its own turn unless queue is false) and its answer
68
- # waited for, all within ASK_MAX_SECONDS. 200 wait_result_json's
69
- # fields + session_id (+ asked, the id given, when another link ran
70
- # it; + token when the status is timeout: POST …/wait {token} goes
71
- # on); 200 {status: command} for a session command. 404 not_found,
72
- # 400 ambiguous_id, 409 busy / waiting / continuing / owned_by_tui,
73
- # the turn route's delivery refusals, 503 server_stopping.
84
+ # POST /api/sessions/:id/ask {prompt, timeout, queue, client_id,
85
+ # request_id}: the message delivered (to a chain's newest link; a
86
+ # running session queues it as its own turn unless queue is false) and
87
+ # its answer waited for, all within ASK_MAX_SECONDS. A request_id (a
88
+ # message's, not a command's) names its turn: a retry whose turn the
89
+ # session knows waits on it again, nothing sent and no second history
90
+ # line (SessionAccess::Ask#call). 200 wait_result_json's fields +
91
+ # session_id (+ asked, the id given, when another link ran it; +
92
+ # token when the status is timeout: POST …/wait {token} goes on; +
93
+ # request_id when one was given); 200 {status: command} for a session
94
+ # command. 404 not_found, 400 ambiguous_id / invalid_ask, 409 busy /
95
+ # waiting / continuing / owned_by_tui / enqueued_id_conflict (the
96
+ # same request_id, another prompt), the turn route's delivery
97
+ # refusals, 503 server_stopping.
74
98
  def handle_ask(req, id)
75
99
  # One deadline from the request's start: the gate, the continue
76
100
  # waits, the Bridge wait and the slice all draw on it.
@@ -82,7 +106,7 @@ module Samagotchi
82
106
  gated = ask_gate(id, prompt, client_id)
83
107
  return gated if gated
84
108
 
85
- bridge = ->(sid) { live_bridge_client(sid, within: deadline - ask_clock) }
109
+ bridge = ->(sid) { ask_bridge(sid, deadline) }
86
110
  access = AskAccess.new(session_access, manager: @manager, bridge: bridge, poll_interval: @wait_poll_interval)
87
111
  stopping = -> { !@server_running.call }
88
112
  exchange = SessionAccess::Exchange.new(access, continuing_wait: [SessionAccess::Exchange::CONTINUING_WAIT,
@@ -90,14 +114,15 @@ module Samagotchi
90
114
  outcome = SessionAccess::Ask.new(access, exchange: exchange)
91
115
  .call(id, prompt: prompt, client_id: client_id, cap: deadline - ask_clock,
92
116
  cancelled: stopping, **options)
93
- record_history(body, prompt) unless outcome.is_a?(SessionAccess::Ask::Refused)
94
- ask_response(id, outcome)
117
+ rebound = outcome.is_a?(SessionAccess::Ask::Reply) && outcome.rebound
118
+ record_history(body, prompt) unless outcome.is_a?(SessionAccess::Ask::Refused) || rebound
119
+ ask_response(id, outcome, request_id: options[:request_id])
95
120
  rescue SessionManager::OwnedByTUI => e
96
121
  owned_by_tui(e)
97
122
  end
98
123
 
99
- # The ask's body read: [prompt, client_id, {queue:, timeout:}, nil] or
100
- # [.., a 400 response].
124
+ # The ask's body read: [prompt, client_id, {queue:, timeout:,
125
+ # request_id:}, nil] or [.., a 400 response].
101
126
  def ask_request(id, body)
102
127
  return [nil, nil, nil, error_response(400, "missing_fields", "prompt is required")] unless body["prompt"].is_a?(String)
103
128
 
@@ -118,18 +143,44 @@ module Samagotchi
118
143
  client_id = body["client_id"]
119
144
  return [nil, nil, nil, error_response(400, "invalid_ask", "client_id is a string")] unless client_id.nil? || client_id.is_a?(String)
120
145
 
121
- [prompt, ask_sender(client_id, prompt), { queue: queue, timeout: [timeout, WAIT_MAX_SECONDS].min }, nil]
146
+ request_id, error = ask_request_id(body, prompt)
147
+ return [nil, nil, nil, error] if error
148
+
149
+ options = { queue: queue, timeout: [timeout, WAIT_MAX_SECONDS].min }
150
+ options[:request_id] = request_id if request_id
151
+ [prompt, ask_sender(client_id, prompt), options, nil]
122
152
  rescue SessionInbox::NoteRejected => e
123
153
  [nil, nil, nil, error_response(400, "invalid_prompt", e.message)]
124
154
  end
125
155
 
156
+ # The body's request_id: [nil or it, nil] or [nil, a 400]. A session
157
+ # command never runs as a turn of that id (the Bridge's command path
158
+ # takes none), so a retry would run it again: refused. Any line the
159
+ # worker may run as one, by its shape (COMMAND_SHAPE): chi web can't
160
+ # see a bundle's commands, which only the worker's registry has.
161
+ def ask_request_id(body, prompt)
162
+ request_id = body["request_id"]
163
+ return [nil, nil] if request_id.nil?
164
+ unless request_id.is_a?(String) && REQUEST_ID.match?(request_id)
165
+ return [nil, error_response(400, "invalid_ask", "request_id is 1 to 128 printable ASCII characters")]
166
+ end
167
+
168
+ line = prompt.strip
169
+ if line.start_with?("!") || COMMAND_SHAPE.match?(line)
170
+ return [nil, error_response(400, "invalid_ask", "request_id is for messages, not session commands")]
171
+ end
172
+
173
+ [request_id, nil]
174
+ end
175
+
126
176
  # Who asks: the owner (WEB_UNNAMED) unless the body names a sender
127
177
  # (owner_sender's rule); a parent agent's /continue yes sent as
128
- # cli:send goes in as cli:answer, as chi send sends it (the worker
129
- # holds that one to guardrails.parent_answers).
178
+ # cli:send or an agent's id (ClientId.parent_line?) goes in as
179
+ # cli:answer, as chi send sends it (the worker holds that one to
180
+ # guardrails.parent_answers).
130
181
  def ask_sender(client_id, prompt)
131
182
  sender = owner_sender({ "client_id" => client_id })
132
- sender == ClientId::CLI_SEND && TurnFlow.continue_yes?(prompt) ? ClientId::CLI_ANSWER : sender
183
+ TurnFlow.continue_yes?(prompt) ? AgentCaller.continue_id(sender) : sender
133
184
  end
134
185
 
135
186
  # A parent agent's line refused before anything is sent, as POST
@@ -137,7 +188,7 @@ module Samagotchi
137
188
  # session asked and of its chain's newest link (where it goes).
138
189
  # @return [Array, nil] the response, or nil to go on
139
190
  def ask_gate(id, prompt, client_id)
140
- return nil unless App::CLI_SEND_IDS.include?(client_id)
191
+ return nil unless ClientId.parent_line?(client_id)
141
192
 
142
193
  asked = session_access.resolve(id)
143
194
  ids = [asked, session_access.head(asked).id].uniq
@@ -151,8 +202,9 @@ module Samagotchi
151
202
  nil
152
203
  end
153
204
 
154
- # The ask's answer for an Ask value.
155
- def ask_response(id, outcome)
205
+ # The ask's answer for an Ask value (+request_id+ echoed when given:
206
+ # the client sees this chi web used it).
207
+ def ask_response(id, outcome, request_id: nil)
156
208
  case outcome
157
209
  when SessionAccess::Ask::Ran then json_response(200, { status: "command", session_id: outcome.session_id })
158
210
  when SessionAccess::Ask::Refused then ask_refused(id, outcome)
@@ -163,6 +215,7 @@ module Samagotchi
163
215
  json = wait_result_json(result, session_access.parent_strategy(outcome.session_id)).merge(session_id: outcome.session_id)
164
216
  json[:asked] = outcome.asked if outcome.asked && outcome.asked != outcome.session_id
165
217
  json[:token] = outcome.token if outcome.token
218
+ json[:request_id] = request_id if request_id
166
219
  json_response(200, json)
167
220
  end
168
221
  end
@@ -283,6 +336,25 @@ module Samagotchi
283
336
 
284
337
  def plain_exchange = SessionAccess::Exchange.new(session_access)
285
338
 
339
+ # The worker's Bridge client for an ask's delivery (App's
340
+ # live_bridge_client, drawn from +deadline+): a worker starting is
341
+ # waited for out of what is left, and the post's read is what is left
342
+ # after that but MIN_SLICE, within POST_FLOOR..READ_TIMEOUT. The
343
+ # client's body deadline is a share of that read (DEADLINE_SHARE, at
344
+ # least POST_MARGIN short of it), so
345
+ # a worker that reads the message late drops it (408
346
+ # deadline_passed) rather than run it after the call gave up.
347
+ # @param deadline [Numeric] ask_clock's seconds the call ends by
348
+ # @return [BridgeClient, nil] nil: no live worker in time
349
+ def ask_bridge(sid, deadline)
350
+ link = worker_link(sid)
351
+ link = await_worker_link(sid, timeout: [@bridge_wait_timeout.to_f, deadline - ask_clock].min.clamp(0.0..)) unless link.live?
352
+ return nil unless link.live?
353
+
354
+ read = (deadline - ask_clock - SessionAccess::Ask::MIN_SLICE).clamp(POST_FLOOR, BridgeClient::READ_TIMEOUT)
355
+ link.client(sid, host: App::DEFAULT_HOST, read_timeout: read, deadline_margin: POST_MARGIN)
356
+ end
357
+
286
358
  # The ask's deadline clock (the Exchange's: monotonic seconds).
287
359
  def ask_clock = Process.clock_gettime(Process::CLOCK_MONOTONIC)
288
360
 
@@ -20,7 +20,7 @@ module Samagotchi
20
20
  # Bearer, so a host says it needs a token rather than look for OAuth.
21
21
  # GET 405 (no stream), DELETE 200 (a legacy host closing its session).
22
22
  # Included in App through SessionAccessRoutes; its helpers
23
- # (request_body, session_access, live_bridge_client, error_response)
23
+ # (request_body, session_access, ask_bridge, ask_clock, error_response)
24
24
  # and ivars (@manager, @hub, @wait_poll_interval, @server_running)
25
25
  # answer. See docs/mcp-server.md.
26
26
  module McpRoute
@@ -55,8 +55,11 @@ module Samagotchi
55
55
  private
56
56
 
57
57
  def handle_mcp(req)
58
+ # One deadline per POST (one call), as the ask's: the post to a
59
+ # live worker draws on it (AskRoutes#ask_bridge).
60
+ deadline = ask_clock + McpServer::Tools::CAP
58
61
  body = request_body(req, BODY_LIMIT, what: "an MCP request")
59
- McpServer::Http.new(mcp_protocol).call(req.env, body)
62
+ McpServer::Http.new(mcp_protocol(deadline)).call(req.env, body)
60
63
  end
61
64
 
62
65
  def handle_mcp_get(_req)
@@ -67,8 +70,8 @@ module Samagotchi
67
70
  # Nothing is kept for a legacy session id: nothing to end.
68
71
  def handle_mcp_delete(_req) = [200, { "Content-Length" => "0" }, []]
69
72
 
70
- def mcp_protocol
71
- bridge = ->(sid) { live_bridge_client(sid, within: McpServer::Tools::CAP) }
73
+ def mcp_protocol(deadline)
74
+ bridge = ->(sid) { ask_bridge(sid, deadline) }
72
75
  access = McpAccess.new(session_access, hub: @hub, manager: @manager, bridge: bridge, poll_interval: @wait_poll_interval)
73
76
  stopping = -> { !@server_running.call }
74
77
  exchange = ->(backend) { SessionAccess::Exchange.new(backend, cancelled: stopping) }
@@ -4,6 +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 "../context_absorber"
7
8
  require_relative "../context_note"
8
9
  require_relative "../image_store"
9
10
  require_relative "../message_parts"
@@ -97,8 +98,8 @@ module Samagotchi
97
98
  # but that (a text-less step) is kept with empty content
98
99
  # @param cwd [String, nil] the session's working directory (the parts'
99
100
  # tool titles are relative to it)
100
- # @param markdown [Boolean] false: no html for a delegate report or an
101
- # answer (the participant review drops both and renders its replies
101
+ # @param markdown [Boolean] false: no html for a delegate report, an
102
+ # answer or a peer's text (the participant review drops them and renders its replies
102
103
  # from their redacted text, ParticipantReview#with_reply_html)
103
104
  # @param drawings [Array<Bridge::TurnDrawings::Line>, nil] the owner
104
105
  # show's lines (TurnDrawings.cover against +msgs+): each item of a
@@ -130,6 +131,8 @@ module Samagotchi
130
131
  note[:context_source] = context_source.to_s if context_source
131
132
  peer = Samagotchi::ContextNote.fetch(m, :peer)
132
133
  note[:peer] = peer if peer.is_a?(Hash)
134
+ peer_html = markdown && peer_text_html(peer, note[:content])
135
+ note[:peer_html] = peer_html if peer_html
133
136
  payload = Samagotchi::ContextNote.fetch(m, :objectives)
134
137
  entry = payload && Samagotchi::Objectives.entry(payload, before: objectives)
135
138
  if entry
@@ -245,6 +248,16 @@ module Samagotchi
245
248
  []
246
249
  end
247
250
 
251
+ # A peer's text in its note (+peer+'s `inline`), rendered as an
252
+ # answer is: the bubble draws it at once (peer_note.js), so a history
253
+ # read asks for no render per bubble. nil without a block or a renderer.
254
+ def peer_text_html(peer, content)
255
+ return nil unless peer.is_a?(Hash) && (peer["inline"] || peer[:inline]) && @markdown_renderer.available?
256
+
257
+ text = Samagotchi::ContextAbsorber.peer_text_of(content)
258
+ text && @markdown_renderer.render(text)
259
+ end
260
+
248
261
  # The ✂ marks of the outputs right after the model message at +index+,
249
262
  # by output id, as its parts have them (a stub's size from its own
250
263
  # output): its parts are read only when +marks+ (the session's, by
@@ -437,7 +437,7 @@ function findInTurnRoots(selector) {
437
437
  // The open session's peers (peer_data.js, owner only) and their exchange drawn in the conversation (peer_links.js).
438
438
  const peers = contextChips ? createPeers({ sessionId: () => store.selected, onChange: () => { peerLinks.draw(); contextChips.peersChanged(); },
439
439
  hasPeer: () => peerLinks.hasPeer() || contextChips.rows.some((row) => row.peer) }) : null;
440
- const peerLinks = peers && createPeerLinks({ peers, roots: turnRoots, running: () => liveTurn.running, showText: (name) => contextChips.showText?.(name) });
440
+ const peerLinks = peers && createPeerLinks({ peers, roots: turnRoots, running: () => liveTurn.running, showText: (name) => contextChips.showText?.(name), renderMarkdown });
441
441
  // The running turn as the page follows it (live_turn.js): whether one
442
442
  // runs, its timing line and the turns this page saw end (live_timing.js),
443
443
  // its merges' bubble flags, its turn-end reads.
@@ -136,6 +136,7 @@ export function createBlockFix({ roots, sessionId, features, bridgeUp = () => tr
136
136
  }
137
137
  if (status === 200) { setFixNote(pre, "nohelp"); return; }
138
138
  if (status === 202) {
139
+ if (typeof body.key === "string" && body.key) pre.dataset.blockFixKey = body.key;
139
140
  // Running, unless the worker's word already came.
140
141
  if (asking(pre)) giveUpLater(turnId);
141
142
  return;
@@ -195,13 +196,20 @@ export function createBlockFix({ roots, sessionId, features, bridgeUp = () => tr
195
196
  noticeSession();
196
197
  const turnId = data?.turn_id;
197
198
  if (!turnId) return;
198
- if (pending.has(turnId)) { timers.clearTimeout(pending.get(turnId)); pending.delete(turnId); }
199
+ const asked = askedIn(turnId);
200
+ const relevant = data.key ? asked.filter((pre) => !pre.dataset.blockFixKey || pre.dataset.blockFixKey === data.key) : asked;
201
+ if (!relevant.length) return;
202
+ for (const pre of relevant) delete pre.dataset.blockFixAsked;
203
+ if (pending.has(turnId) && !askedIn(turnId).some(asking)) {
204
+ timers.clearTimeout(pending.get(turnId));
205
+ pending.delete(turnId);
206
+ }
199
207
  if (data.state === "fixed") {
200
- for (const pre of askedIn(turnId)) redrawOnce(turnId, codeText(pre));
208
+ for (const pre of relevant) redrawOnce(turnId, codeText(pre));
201
209
  refresh(sessionId(), turnId);
202
210
  return;
203
211
  }
204
- for (const pre of askedIn(turnId)) setFixNote(pre, "nohelp");
212
+ for (const pre of relevant) setFixNote(pre, "nohelp");
205
213
  }
206
214
 
207
215
  function scan(el) {
@@ -24,17 +24,9 @@
24
24
 
25
25
  import { html, nothing, render } from "./vendor/lit-html.js";
26
26
  import { createChipPopover, SHEET_TALL } from "./chip_popover.js";
27
- import { archiveSheetModel, buttonWords, cantModel, choiceTail, deleteToast as modelToast, sessionSheetModel, sheetTitle,
27
+ import { archiveSheetModel, buttonWords, cantModel, choiceTail, sessionSheetModel, sheetTitle,
28
28
  stopTasksOptions, stopsFirst } from "./removal_sheet_model.js";
29
29
 
30
- // The toast after a delete, for an older cached session_actions.js (0.182.0),
31
- // which adds the stopped tasks to it itself: without them, so they aren't
32
- // said twice. This session_actions.js imports removal_sheet_model.js'. Kept
33
- // until the next release (web-frontend.md, removing an export).
34
- export function deleteToast(which, result, plan, id) {
35
- return modelToast(which, result, plan, id, { withTasks: false });
36
- }
37
-
38
30
  const short = (id) => String(id ?? "").slice(0, 8);
39
31
  const count = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
40
32
 
@@ -218,13 +210,13 @@ export function refusalModel(refusal, previousId = null) {
218
210
  return { title: "Not deleted", text: refusal?.message || "The delete was refused.", stop: null };
219
211
  }
220
212
 
221
- export function refusalTemplate(model, { back = false } = {}) {
213
+ export function refusalTemplate(model, { back = false, busy = false } = {}) {
222
214
  return html`<div class="delete-sheet">${headTemplate(back)}
223
215
  <div class="ds-title">${model.title}</div>
224
216
  <div class="ds-sub">${model.text}</div>
225
217
  ${model.stop ? html`<div class="ds-choices"><button type="button" class="ds-choice primary" data-act="del:stop"
226
- ><span class="ds-label">${model.stop.label}</span><span class="ds-line dim">${model.stop.line}</span></button></div>` : nothing}
227
- <div class="ds-acts"><button type="button" class="ds-cancel" data-act="del:cancel">${model.stop ? "Cancel" : "Close"}</button></div>
218
+ ?disabled=${busy}><span class="ds-label">${busy ? "Stopping…" : model.stop.label}</span><span class="ds-line dim">${model.stop.line}</span></button></div>` : nothing}
219
+ <div class="ds-acts"><button type="button" class="ds-cancel" data-act="del:cancel" ?disabled=${busy}>${model.stop ? "Cancel" : "Close"}</button></div>
228
220
  </div>`;
229
221
  }
230
222
 
@@ -266,7 +258,8 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
266
258
 
267
259
  const list = () => (typeof sessions === "function" ? sessions() : sessions);
268
260
  const showSheet = () => show(deleteSheetTemplate(model, { back, busy, notice, stopping, act: archive ? "archive" : "this" }));
269
- const showRefusal = () => show(refusalTemplate(refusalModel(refusal, plan?.link?.previous_id), { back }));
261
+ const showRefusal = (busyRefusal = false) =>
262
+ show(refusalTemplate(refusalModel(refusal, plan?.link?.previous_id), { back, busy: busyRefusal }));
270
263
  // A plan that can't be read: why, in the sheet, and only Close.
271
264
  const cant = (error) => {
272
265
  busy = false;
@@ -307,8 +300,7 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
307
300
  return { tasks: choice.tasks, stops: choice.stops, digest: which === "chain" ? plan?.chain?.digest : plan?.link?.digest };
308
301
  }
309
302
 
310
- async function run(which) {
311
- if (busy || !live()) return;
303
+ async function sendDelete(which) {
312
304
  const choice = chosen(which);
313
305
  if (!choice) return;
314
306
  busy = true;
@@ -347,6 +339,11 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
347
339
  }
348
340
  }
349
341
 
342
+ async function run(which) {
343
+ if (busy || !live()) return;
344
+ await sendDelete(which);
345
+ }
346
+
350
347
  // The sheet as it is now, with "changed; check again" on top: the plan
351
348
  // read again (a delete), or the 409's own tasks (an archive's).
352
349
  async function refreshPlan(error) {
@@ -378,20 +375,25 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
378
375
  if (busy || !live()) return;
379
376
  const ids = refusal?.ids || [];
380
377
  busy = true;
378
+ showRefusal(true);
381
379
  for (const child of ids) {
382
380
  let released = false;
383
381
  try {
384
382
  released = (await api.stopSession(child))?.released === true;
385
383
  } catch (_) { released = false; }
386
384
  if (!released) {
387
- refusal = { reason: "still_stopping", message: `${short(child)}'s worker is still running; try again in a moment.`, ids };
388
385
  busy = false;
386
+ const message = `${short(child)}'s worker is still running; try again in a moment.`;
387
+ if (!live()) {
388
+ failed(Object.assign(new Error(message), { code: "still_stopping", body: { ids } }));
389
+ return;
390
+ }
391
+ refusal = { reason: "still_stopping", message, ids };
389
392
  showRefusal();
390
393
  return;
391
394
  }
392
395
  }
393
- busy = false;
394
- run("this");
396
+ await sendDelete("this");
395
397
  }
396
398
 
397
399
  return {
@@ -57,12 +57,14 @@ function sameBut(a, b, key) {
57
57
 
58
58
  // What a reader reads of +el+: its text, without the copy button, the
59
59
  // time dividers and a peer answer's late slots (peer_links.js fills them
60
- // from GET …/peers, which an offscreen reload doesn't read), whitespace
60
+ // from GET …/peers, which an offscreen reload doesn't read), a peer's text
61
+ // as its source (peer_links.js swaps in its markdown later), whitespace
61
62
  // collapsed.
62
63
  function textOf(el) {
63
64
  if (!el) return "";
64
65
  const copy = el.cloneNode(true);
65
66
  copy.querySelectorAll(".copy-btn, .time-gap, [data-peer-slot]").forEach((node) => node.remove());
67
+ copy.querySelectorAll("[data-peer-md]").forEach((node) => { node.textContent = node.dataset.peerMd; });
66
68
  return copy.textContent.replace(/\s+/g, " ").trim();
67
69
  }
68
70
 
@@ -513,6 +513,14 @@ button.system-one-wrong,.system-one-wrong.marked{flex:none;padding:1px 6px;borde
513
513
  A send's state (peer_exchange.js pillTemplate) is a pill in the chip's shape after the row's params. */
514
514
  .bubble.note.peer-answer{border:1px solid var(--border-strong);border-radius:10px;background:var(--bg-panel);opacity:1;font-size:13px;color:var(--text);white-space:normal;display:flex;flex-direction:column;gap:8px}
515
515
  .bubble.note.peer-answer .note-text{max-height:none;overflow:visible;line-height:1.5}
516
+ .bubble.note.peer-answer .peer-text{line-height:1.5;white-space:pre-wrap;overflow-wrap:anywhere}
517
+ .bubble.note.peer-answer .peer-text.markdown{white-space:normal}
518
+ .bubble.note.peer-answer .peer-text.md-compact{
519
+ --md-heading-size:14.5px;--md-heading-color:var(--text);
520
+ --md-subheading-size:14px;--md-subheading-color:var(--text-2);
521
+ --md-strong-color:var(--text);--md-blockquote-color:var(--text-muted);--md-code-color:var(--text);
522
+ --md-pre-size:12.5px;--md-cell-size:13px
523
+ }
516
524
  .peer-head{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 8px}
517
525
  .peer-who{font-weight:700;color:var(--text-bright)}
518
526
  .peer-mark{margin-left:auto;display:inline-flex;align-items:baseline;gap:8px}
@@ -30,7 +30,7 @@ export function upTemplate(exchange) {
30
30
  }
31
31
 
32
32
  // "Read the full answer": the newest answer of a peer only (its outbox keeps
33
- // one text).
33
+ // one text), and not one whose bubble holds its text (data-peer-inline).
34
34
  export function fullTemplate(newest) {
35
35
  return newest ? html`<button type="button" class="peer-full" data-peer-full="1">Read the full answer</button>` : nothing;
36
36
  }
@@ -38,11 +38,16 @@ export function fullTemplate(newest) {
38
38
  // +peers+ the model (peer_data.js); +roots+() the elements a turn's rows can
39
39
  // be in (the history and the stage); +running+() whether a turn runs;
40
40
  // +showText+(source) opens that context source's text (context_chips.js);
41
- // +behavior+() the scroll's.
41
+ // +renderMarkdown+(text) a text's sanitized markdown HTML or null
42
+ // (markdown_place.js; none: the peer's text stays plain); +behavior+() the
43
+ // scroll's.
42
44
  //
43
45
  // @return {draw(), drawn(), hasPeer(), hasSend(id), showSend(id), reset()}
44
- export function createPeerLinks({ peers, roots, running = () => false, showText = () => {}, behavior = smooth } = {}) {
46
+ export function createPeerLinks({ peers, roots, running = () => false, showText = () => {}, renderMarkdown = null, behavior = smooth } = {}) {
45
47
  const all = (selector) => roots().filter(Boolean).flatMap((root) => [...root.querySelectorAll(selector)]);
48
+ // The peer texts already asked for (each is asked once; a failed read
49
+ // keeps the plain text).
50
+ const asked = new WeakSet();
46
51
 
47
52
  // A slot of the running turn (the stage's, or a turn opened in the history).
48
53
  const live = (slot) => running() && !!slot.closest(".turn-stage, [data-opened-turn]");
@@ -81,10 +86,28 @@ export function createPeerLinks({ peers, roots, running = () => false, showText
81
86
  const up = note.querySelector(":scope > .peer-head > .peer-up-slot");
82
87
  if (up) render(upTemplate(answerOf(note)), up);
83
88
  const full = note.querySelector(":scope > .peer-foot > .peer-full-slot");
84
- if (full) render(fullTemplate(newest.get(note.dataset.peerSource || "") === note && !!note.dataset.peerSource), full);
89
+ const last = newest.get(note.dataset.peerSource || "") === note && !!note.dataset.peerSource;
90
+ if (full) render(fullTemplate(last && !note.dataset.peerInline), full);
91
+ const text = note.querySelector(":scope > .peer-text[data-peer-md]:not(.markdown)");
92
+ if (text) renderText(text);
85
93
  }
86
94
  }
87
95
 
96
+ // A bubble's peer text as its markdown, as the answers' (POST
97
+ // /api/render, sanitized there): its source stays in data-peer-md, which
98
+ // history_shape.js reads, so live and an offscreen reload read alike.
99
+ function renderText(el) {
100
+ if (!renderMarkdown || asked.has(el)) return;
101
+ asked.add(el);
102
+ const source = el.dataset.peerMd;
103
+ Promise.resolve(renderMarkdown(source)).then((rendered) => {
104
+ if (!rendered || el.dataset.peerMd !== source) return;
105
+ // Sanitized on the server (POST /api/render).
106
+ el.innerHTML = rendered;
107
+ el.classList.add("markdown", "md-compact");
108
+ }).catch(() => {});
109
+ }
110
+
88
111
  function answerOf(note) {
89
112
  const { peerName, peerSerial, peerRe } = note.dataset;
90
113
  return peers.answer(peerName, peerSerial ?? null, peerRe || null);
@@ -7,11 +7,20 @@
7
7
  // reload_check.js and revise_stack.js (its `.note-text`, the summary) read
8
8
  // it as any wake note. The ↑ to the send and "Read the full answer" are
9
9
  // slots peer_links.js fills (data-peer-slot: history_shape.js leaves them
10
- // out, so live and an offscreen reload read alike).
10
+ // out, so live and an offscreen reload read alike). A note whose peer hash
11
+ // says `inline` holds the peer's text (peer_text.js): the bubble shows it
12
+ // in `.peer-text` under the summary: as the markdown the history read
13
+ // rendered (the note's `peer_html`, MessageDisplay#peer_text_html), else
14
+ // (a live context_added, an older server) as plain text that peer_links.js
15
+ // swaps for its markdown; its source kept in data-peer-md. The fold shows
16
+ // the rest, and the bubble is marked data-peer-inline (no "Read the full
17
+ // answer").
11
18
  // Its own module: new exports go in new modules (web-frontend.md).
12
19
 
13
20
  import { html, nothing } from "./vendor/lit-html.js";
21
+ import { unsafeHTML } from "./vendor/directives/unsafe-html.js";
14
22
  import { fullTime } from "./format.js";
23
+ import { peerBlock } from "./peer_text.js";
15
24
 
16
25
  const VERDICT_CLASS = { OK: "ok", CHANGES: "changes", UNSURE: "unsure" };
17
26
 
@@ -37,7 +46,7 @@ export function peerSummaryText(note) {
37
46
  }
38
47
 
39
48
  // The bubble for +note+ (a context note with `peer`: {peer, label, re,
40
- // summary, serial, verdict, agreed}).
49
+ // summary, serial, verdict, agreed, inline}).
41
50
  export function peerNoteTemplate(note) {
42
51
  const peer = note.peer || {};
43
52
  const name = peer.label || peer.peer || "Your peer";
@@ -45,5 +54,12 @@ export function peerNoteTemplate(note) {
45
54
  const opening = note.turn_start && note.turn_id ? String(note.turn_id) : nothing;
46
55
  const source = note.context_source || (peer.peer ? `${peer.peer}-outbox` : "");
47
56
  const attr = (value) => (value === null || value === undefined || value === "" ? nothing : String(value));
48
- return html`<div class=${cls} title=${fullTime(note.at) || nothing} data-opening-id=${opening} data-peer-source=${attr(source)} data-peer-name=${attr(peer.peer)} data-peer-re=${attr(peer.re)} data-peer-serial=${attr(peer.serial)}><div class="peer-head"><span class="peer-who">${name} answered</span><span class="peer-up-slot" data-peer-slot="up"></span>${verdictTemplate(peer)}</div><div class="note-text">${peerSummaryText(note)}</div><div class="peer-foot"><span class="peer-full-slot" data-peer-slot="full"></span><details class="peer-told"><summary>what chi told the agent</summary><div class="peer-told-text">${note.content ?? ""}</div></details></div></div>`;
57
+ const block = peer.inline ? peerBlock(note.content) : null;
58
+ // Sanitized on the server (MarkdownRenderer), as an answer's html.
59
+ const rendered = block && typeof note.peer_html === "string" && note.peer_html;
60
+ const body = !block ? nothing
61
+ : rendered ? html`<div class="peer-text markdown md-compact" data-peer-md=${block.text}>${unsafeHTML(rendered)}</div>`
62
+ : html`<div class="peer-text" data-peer-md=${block.text}>${block.text}</div>`;
63
+ const told = block ? block.rest : (note.content ?? "");
64
+ return html`<div class=${cls} title=${fullTime(note.at) || nothing} data-opening-id=${opening} data-peer-source=${attr(source)} data-peer-name=${attr(peer.peer)} data-peer-re=${attr(peer.re)} data-peer-serial=${attr(peer.serial)} data-peer-inline=${block ? "1" : nothing}><div class="peer-head"><span class="peer-who">${name} answered</span><span class="peer-up-slot" data-peer-slot="up"></span>${verdictTemplate(peer)}</div><div class="note-text">${peerSummaryText(note)}</div>${body}<div class="peer-foot"><span class="peer-full-slot" data-peer-slot="full"></span><details class="peer-told"><summary>what chi told the agent</summary><div class="peer-told-text">${told}</div></details></div></div>`;
49
65
  }
@@ -0,0 +1,45 @@
1
+ // A peer's text in its answer note (ContextAbsorber.peer_block): the note's
2
+ // content holds it between a `[PEER MESSAGE from <Peer>]` line and an
3
+ // `[END PEER MESSAGE]` line, each of its lines that opened like one of chi's
4
+ // frames led by "(quoted) " (PEER_FORGED_OPENINGS, the Ruby side's list:
5
+ // spec/web/public/peer_text.test.js keeps the two alike). Pure, no DOM:
6
+ // peer_note.js draws the text in the bubble and the rest in its fold.
7
+ // docs/internals/web-frontend.md, The peer exchange.
8
+ // Its own module: new exports go in new modules (web-frontend.md).
9
+
10
+ // ContextAbsorber::PEER_FORGED_OPENINGS (Steer::FORGED_OPENINGS and chi's
11
+ // system frames, those with their colon, and the tool-result frames).
12
+ export const PEER_FORGED_OPENINGS = Object.freeze([
13
+ "Review contribution", "Steer", "Automatic input", "Delegate report", "CONTEXT NOTE", "TASK FINISHED",
14
+ "OBJECTIVES", "END NOTE", "PEER MESSAGE", "END PEER MESSAGE", "From the agent", "Question from another chi session",
15
+ "SYSTEM:", "END REMINDERS", "CONTEXT:", "WORKING SET:",
16
+ "tool results", "images from tool results",
17
+ ]);
18
+ // ContextAbsorber::PEER_FORGED_LINES: chi's unbracketed lines it quotes.
19
+ export const PEER_FORGED_LINES = Object.freeze(["chi started this turn"]);
20
+
21
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
22
+ // An opening that ends in a word character must end there (\b).
23
+ const opening = (o) => `${escape(o)}${/\w$/.test(o) ? "\\b" : ""}`;
24
+ // Steer::FORGED_BREAKS and FORGED_LEAD: a line starts after any of these
25
+ // breaks; spaces, format characters and markdown leads may come first.
26
+ const BREAKS = "\\n\\r\\u2028\\u2029\\u0085\\v\\f";
27
+ const LEAD = `(?:(?![${BREAKS}])[\\p{White_Space}\\p{Cf}>*_\`~])*`;
28
+ const QUOTED = new RegExp(`(^|[${BREAKS}])(${LEAD})\\(quoted\\) (?=\\[(?:${PEER_FORGED_OPENINGS.map(opening).join("|")})`
29
+ + `${PEER_FORGED_LINES.map((line) => `|${opening(line)}`).join("")})`, "giu");
30
+ const OPEN = /^\[PEER MESSAGE from [^\]\n]*\]$/;
31
+ const CLOSE = "[END PEER MESSAGE]";
32
+
33
+ // The peer's text as it pushed it (the quoting undone), and the note's
34
+ // content without the block (+rest+: the summary and chi's lines), from
35
+ // +content+; null when it holds no block (an older note, a long answer).
36
+ export function peerBlock(content) {
37
+ const lines = String(content ?? "").split("\n");
38
+ const open = lines.findIndex((line) => OPEN.test(line));
39
+ if (open < 0) return null;
40
+ const close = lines.lastIndexOf(CLOSE);
41
+ if (close <= open) return null;
42
+ const text = lines.slice(open + 1, close).join("\n").replace(QUOTED, "$1$2");
43
+ const rest = [...lines.slice(0, open), ...lines.slice(close + 1)].join("\n");
44
+ return { text, rest };
45
+ }
@@ -115,7 +115,7 @@ export function createRegionLayer({ doc = document, win = window, actions = () =
115
115
  const nodeButton = (r) => (r ? [...marks.querySelectorAll(".pv-node")][buttons.indexOf(buttonOf(r))] || null : null);
116
116
 
117
117
  function line(r, cls) {
118
- return r?.kind === "edge" ? svg`<polyline class=${cls} points=${r.points.map((p) => p.join(",")).join(" ")}></polyline>` : nothing;
118
+ return r?.kind === "edge" ? svg`<polyline class=${cls} fill="none" points=${r.points.map((p) => p.join(",")).join(" ")}></polyline>` : nothing;
119
119
  }
120
120
 
121
121
  function boxMarks(r, cls) {
@@ -132,7 +132,7 @@ export function createRegionLayer({ doc = document, win = window, actions = () =
132
132
 
133
133
  function draw() {
134
134
  const hover = hovered && !sameRegion(hovered, selected) ? hovered : null;
135
- render(regions && bound ? html`${boxMarks(hover, "pv-hover")}${boxMarks(selected, "pv-on")}<svg class="pv-lines" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true">${line(hover, "pv-hover")}${line(selected, "pv-on")}</svg>
135
+ render(regions && bound ? html`${boxMarks(hover, "pv-hover")}${boxMarks(selected, "pv-on")}<svg class="pv-lines" style="position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true">${line(hover, "pv-hover")}${line(selected, "pv-on")}</svg>
136
136
  <div class="pv-nodes" role="group" aria-label=${countLine(buttons)}>${buttons.map((r) => html`<button type="button" class="pv-node" style=${buttonStyle(r)} tabindex=${sameRegion(r, stop) ? "0" : "-1"} aria-label=${regionName(r, regions)} aria-pressed=${sameRegion(r, selected) ? "true" : "false"} @click=${() => select(r, "key")} @focus=${() => { stop = r; }}></button>`)}</div>` : nothing, marks);
137
137
  drawCard();
138
138
  }