diff --git a/remote.md b/remote.md index 1b805d8..df86a0d 100644 --- a/remote.md +++ b/remote.md @@ -950,6 +950,31 @@ roles with a private TLS relay: whitespace and Unicode preserved, file and oversized refusal, single-use receive and refusal without the grant. The Remote race suite and `make check` passed; no live desktop clipboard was used. +Forty-fourth to forty-sixth implementation increments (2026-11-06): Braille. +Reader `bfbd731` adds typed `remote.braille` requests and events with +per-role direction checks to the host and both SDKs. `9361093` adds a +virtual-only `cthulhu-braille --virtual` mode sharing the physical helper's +liblouis viewport, an exporter that sends only accepted application frames +(never reader UI, flashes or secure frames; hidden frames are unroutable), +gesture and routing application, controller display of peer cells as an +untranslated raw frame, and local pan/route forwarding. The physical helper now +reports its width and edge pans. See [the Braille contract](../cthulhu/docs/tentacle-remote-braille.md). +Ordinary frames use the explicit `en-us-comp8.ctb` table for the virtual +display; contracted frames keep the user's table; the cursor is a static +dots-7-8 overlay. + +Here, a session-only Braille option requests `braille-stream`. A controlled +computer asks for geometry with an empty `set_braille_info`, applies the +controller's `numCells` or smallest `set_display_size`, sends coalesced +`display` cells and applies only the pan and route `braille_input` paths. A +controller advertises its width as `set_braille_info`, shows coalesced peer +cells and sends pan and route gestures as NVDA global-command script paths. +Tests cover both roles over a private TLS relay, coalescing, unsupported +gestures and refusal without the grant. Full default and `brlapi` reader +suites (private D-Bus), the Remote race suite and `make check` passed. No +physical display, NVDA or Orca peer was used; Braille keyboard input beyond pan +and routing remains unsupported. + ## 1. Intended result and recommended approach Build a native Go Tentacle named **Remote**, with package ID `remote`, in this @@ -1584,10 +1609,11 @@ to a keyboard-control release. - [x] Add explicit send/receive text operations, permissions and ownership tests. Implemented in the Tentacle using the reader's explicit clipboard read/write interactions; live desktop clipboard acceptance is pending. -- [ ] Add virtual Braille viewport, final-cell export, raw-cell input to the local - helper, display negotiation, panning and routing. -- [ ] Add allowlisted NVDA Braille gesture conversion in both directions and - document any unsupported device/input actions. +- [x] Add virtual Braille viewport, final-cell export, raw-cell input to the local + helper, display negotiation, panning and routing. Physical acceptance pending. +- [x] Add allowlisted NVDA Braille gesture conversion in both directions and + document any unsupported device/input actions. Only pan and routing are + converted; other gestures stay inert. - [ ] Test on physical Braille displays, including controlled-side no-display, translation tables and unplug/replug. Keep output/input claims separate. diff --git a/remote/README.md b/remote/README.md index a57facc..58c4ed4 100644 --- a/remote/README.md +++ b/remote/README.md @@ -41,6 +41,10 @@ Implemented: failed-write cleanup with sequence-checked acknowledgements. Capture, injection, AltGr and native layout/held-key ownership remain pending; these are library prerequisites, not keyboard control. See [keyboard.md](keyboard.md). +- Braille, approved per session: a controlled computer exports its Braille at + the controller's display width; a controller shows it and sends pan and + routing keys. Physical display acceptance is pending. See + [the reader contract](../../cthulhu/docs/tentacle-remote-braille.md). - Explicit clipboard text transfer, approved per session: send with Cthulhu+Ctrl+Shift+C; received text waits until Cthulhu+Ctrl+Shift+V copies it. Up to 8 KiB of text; no files, no automatic overwrite. diff --git a/remote/command.md b/remote/command.md index db636b1..5574ccf 100644 --- a/remote/command.md +++ b/remote/command.md @@ -306,3 +306,14 @@ on one and press Cthulhu+Ctrl+Shift+C; on the other press Cthulhu+Ctrl+Shift+V and paste into an editor. Confirm the clipboard did not change before the receive command, that a second receive reports nothing waiting, that copied files are refused, and that without the checkbox nothing transfers. + +## Braille live checks, pending + +With Braille checked on both computers and a display on the controller, open a +text document on the controlled computer. The controller's display should show +it at its own width. Pan both ways past the page edges, route to a word and +confirm the controlled caret moves. Test contracted and computer Braille, +non-Latin text and a controlled computer with no display attached. Open a +reader dialog and a flashed message on the controlled computer and confirm +neither appears remotely. Disconnect and confirm the controller's local Braille +returns. Unplug and replug the display during a session. diff --git a/remote/src/braille_bridge.go b/remote/src/braille_bridge.go new file mode 100644 index 0000000..ae878f1 --- /dev/null +++ b/remote/src/braille_bridge.go @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package remote + +import ( + "slices" + + sdk "git.stormux.org/storm/cthulhu/sdk/go/tentacle" +) + +// Braille bridges NVDA display traffic and the reader's remote.braille IPC. +// Cell streams are coalesced to the newest frame in both directions: an old +// display is never worth delivering. Other operations are ordered and +// bounded; overflow stops the connection. + +const maxBrailleOps = 16 + +func (stream *speechStream) braille_enabled() bool { + return slices.Contains(stream.grants, "braille-stream") +} + +// queue_braille_op_locked sends one ordered operation to the reader. +func (c *coordinator) queue_braille_op_locked(stream *speechStream, value sdk.RemoteBraille) { + select { + case stream.brailleOps <- value: + default: + c.stop_locked(errLimit) + } +} + +// queue_relay_locked sends one small Braille frame on the ordered writer. +func (c *coordinator) queue_relay_locked(stream *speechStream, kind string, payload any) { + frame, err := encodeMessage(kind, payload) + if err != nil { + c.stop_locked(errProtocol) + return + } + if stream.items == maxSpeechItems || stream.bytes+len(frame) > maxQueuedBytes { + c.stop_locked(errLimit) + return + } + stream.items++ + stream.bytes += len(frame) + stream.outgoing <- frame +} + +// braille_ready_locked starts negotiation once the peer has joined: a +// controlled peer asks for the controller's geometry; a controller asks its +// reader for the local display width. +func (c *coordinator) braille_ready_locked(a *connectionAttempt, stream *speechStream) { + if stream.brailleStarted || !stream.braille_enabled() || !c.speech_ready_locked(a, stream) { + return + } + stream.brailleStarted = true + if stream.role == "controlled" { + c.queue_relay_locked(stream, "set_braille_info", map[string]any{}) + } else { + c.queue_braille_op_locked(stream, sdk.RemoteBraille{Op: "geometry"}) + } +} + +// receive_braille handles peer Braille traffic. Membership, origin and +// direction were checked by the relay reader. +func (c *coordinator) receive_braille(a *connectionAttempt, stream *speechStream, message message) bool { + switch message.kind { + case "set_braille_info", "set_display_size", "display", "braille_input": + default: + return false + } + if !stream.braille_enabled() { + return false + } + c.mu.Lock() + defer c.mu.Unlock() + if !c.speech_ready_locked(a, stream) { + return true + } + switch { + case stream.role == "controlled" && message.kind == "set_braille_info": + info, ok := message.payload.(brailleInfo) + if !ok { + return false + } + c.queue_braille_op_locked(stream, sdk.RemoteBraille{Op: "size", Width: info.Cells}) + case stream.role == "controlled" && message.kind == "set_display_size": + sizes, ok := message.payload.([]int) + if !ok { + return false + } + width := 0 + for _, size := range sizes { + if size > 0 && (width == 0 || size < width) { + width = size + } + } + c.queue_braille_op_locked(stream, sdk.RemoteBraille{Op: "size", Width: width}) + case stream.role == "controlled" && message.kind == "braille_input": + g, ok := message.payload.(gesture) + if !ok || g.action == "" { + return false // Unsupported gestures stay inert. + } + value := sdk.RemoteBraille{Op: "gesture", Gesture: g.action} + if g.action == "route" { + value.Index = g.index + } + c.queue_braille_op_locked(stream, value) + case stream.role == "controller" && message.kind == "set_braille_info": + // The controlled peer asks for geometry again. + c.queue_braille_op_locked(stream, sdk.RemoteBraille{Op: "geometry"}) + case stream.role == "controller" && message.kind == "display": + cells, ok := message.payload.([]int) + if !ok || len(cells) == 0 { + return false + } + stream.readerCells = slices.Clone(cells) + select { + case stream.readerCellsSignal <- struct{}{}: + default: + } + default: + return false + } + return true +} + +// braille_event_locked handles reader remote.braille events for this lease. +func (c *coordinator) braille_event_locked(event sdk.SessionEvent) { + a := c.active + if a == nil || a.speech == nil || event.Braille == nil { + return + } + stream := a.speech + if !stream.braille_enabled() || event.Lease != stream.lease.Lease || event.Epoch != stream.lease.Epoch || !c.speech_ready_locked(a, stream) { + return + } + value := *event.Braille + switch { + case stream.role == "controlled" && value.Op == "cells": + stream.displayCells = slices.Clone(value.Cells) + select { + case stream.displaySignal <- struct{}{}: + default: + } + case stream.role == "controller" && value.Op == "geometry": + c.queue_relay_locked(stream, "set_braille_info", brailleInfo{Name: "Cthulhu", Cells: value.Width}) + case stream.role == "controller" && value.Op == "gesture": + script := map[string]string{"pan-left": "braille_scrollBack", "pan-right": "braille_scrollForward", "route": "braille_routeTo"}[value.Gesture] + if script == "" { + return + } + payload := map[string]any{"scriptPath": []string{"globalCommands", "GlobalCommands", script}} + if value.Gesture == "route" { + payload["routingIndex"] = value.Index + } + c.queue_relay_locked(stream, "braille_input", payload) + } +} + +// take_display_locked returns the newest cells for the relay, once. +func (stream *speechStream) take_display_locked() []int { + cells := stream.displayCells + stream.displayCells = nil + return cells +} + +func (stream *speechStream) take_reader_cells_locked() []int { + cells := stream.readerCells + stream.readerCells = nil + return cells +} diff --git a/remote/src/braille_bridge_test.go b/remote/src/braille_bridge_test.go new file mode 100644 index 0000000..dfde9dd --- /dev/null +++ b/remote/src/braille_bridge_test.go @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package remote + +import ( + "context" + "io" + "net" + "reflect" + "strings" + "testing" + "time" + + sdk "git.stormux.org/storm/cthulhu/sdk/go/tentacle" +) + +// brailleRelay joins one opposite-role peer, writes frames and records every +// Braille frame this computer sends. +func brailleRelay(t *testing.T, r role, frames []string, received chan<- string) endpoint { + t.Helper() + cert, roots := testCertificate(t, true) + peer := "slave" + if r == controlled { + peer = "master" + } + e := testRelay(t, cert, func(conn net.Conn) { + reader := relayHandshake(t, conn, r) + if reader == nil { + return + } + _, _ = io.WriteString(conn, `{"type":"channel_joined","channel":"synthetic-fixture","clients":[{"id":7,"connection_type":"`+peer+`"}]}`+"\n") + for _, frame := range frames { + _, _ = io.WriteString(conn, frame+"\n") + } + for { + line, err := reader.ReadString('\n') + if err != nil { + return + } + for _, kind := range []string{"set_braille_info", "display", "braille_input"} { + if strings.Contains(line, `"type":"`+kind+`"`) { + received <- strings.TrimSpace(line) + } + } + } + }) + e.roots = roots + return e +} + +func nextBrailleCall(t *testing.T, f *fixtureClient) sdk.RemoteBraille { + t.Helper() + for { + select { + case call := <-f.calls: + if call.method != "remote.braille" { + continue + } + request := call.params.(sdk.RemoteBrailleRequest) + if !sdk.ValidRemoteBrailleRequest(request) { + t.Fatal("invalid Braille request", request) + } + return request.Braille + case <-time.After(4 * time.Second): + t.Fatal("missing remote.braille call") + return sdk.RemoteBraille{} + } + } +} + +func nextRelayFrame(t *testing.T, received <-chan string) string { + t.Helper() + select { + case frame := <-received: + return frame + case <-time.After(4 * time.Second): + t.Fatal("missing relay Braille frame") + return "" + } +} + +func TestBrailleControlledExportsCellsAndAppliesGestures(t *testing.T) { + c, f := fixtureCoordinator(t, nil) + action := approveGrants(t, c, f, 1, "controlled", "output-observe", "braille-stream") + received := make(chan string, 8) + frames := []string{ + `{"type":"set_braille_info","origin":7,"name":"Focus","numCells":40}`, + `{"type":"braille_input","origin":7,"scriptPath":["globalCommands","GlobalCommands","braille_routeTo"],"routingIndex":5}`, + `{"type":"braille_input","origin":7,"scriptPath":["globalCommands","GlobalCommands","braille_scrollForward"]}`, + `{"type":"braille_input","origin":7,"scriptPath":["globalCommands","GlobalCommands","sayAll"]}`, + } + if err := c.connect(action, brailleRelay(t, controlled, frames, received), "synthetic-fixture"); err != nil { + t.Fatal(err) + } + if frame := nextRelayFrame(t, received); frame != `{"type":"set_braille_info"}` { + t.Fatal("controlled peer did not ask for geometry", frame) + } + for _, want := range []sdk.RemoteBraille{{Op: "size", Width: 40}, {Op: "gesture", Gesture: "route", Index: 5}, {Op: "gesture", Gesture: "pan-right"}} { + if got := nextBrailleCall(t, f); !reflect.DeepEqual(got, want) { + t.Fatalf("got %+v, want %+v", got, want) + } + } + lease := strings.Repeat("b", 32) + for index, cells := range [][]int{{1, 2}, {3, 4}, {5, 6, 7}} { + value := sdk.RemoteBraille{Op: "cells", Cells: cells} + f.events <- sdk.SessionEvent{Sequence: uint64(2 + index), Kind: "remote.braille", Lease: lease, Epoch: 1, Braille: &value} + } + // Coalescing may skip intermediate frames but always ends at the newest. + deadline := time.After(4 * time.Second) + for { + select { + case frame := <-received: + if !strings.Contains(frame, `"type":"display"`) { + t.Fatal("unexpected frame", frame) + } + if strings.Contains(frame, `"cells":[5,6,7]`) { + return + } + case <-deadline: + t.Fatal("newest display cells not sent") + } + } +} + +func TestBrailleControllerShowsPeerCellsAndSendsGestures(t *testing.T) { + c, f := fixtureCoordinator(t, func(_ context.Context, method string, params, result any) error { + if method == "remote.open" { + *result.(*sdk.RemoteLease) = sdk.RemoteLease{Lease: strings.Repeat("b", 32), Epoch: params.(sdk.RemoteOpen).Epoch} + } + return nil + }) + action := approveGrants(t, c, f, 1, "controller", "remote-present", "braille-stream") + received := make(chan string, 8) + frames := []string{`{"type":"display","origin":7,"cells":[0,1,255]}`} + if err := c.connect(action, brailleRelay(t, controller, frames, received), "synthetic-fixture"); err != nil { + t.Fatal(err) + } + if got := nextBrailleCall(t, f); got.Op != "geometry" { + t.Fatal("controller did not ask for local geometry", got) + } + if got := nextBrailleCall(t, f); !reflect.DeepEqual(got, sdk.RemoteBraille{Op: "cells", Cells: []int{0, 1, 255}}) { + t.Fatal("peer cells changed", got) + } + lease := strings.Repeat("b", 32) + geometry := sdk.RemoteBraille{Op: "geometry", Width: 32} + f.events <- sdk.SessionEvent{Sequence: 2, Kind: "remote.braille", Lease: lease, Epoch: 1, Braille: &geometry} + if frame := nextRelayFrame(t, received); !strings.Contains(frame, `"numCells":32`) || !strings.Contains(frame, `"name":"Cthulhu"`) { + t.Fatal("geometry not advertised", frame) + } + for index, value := range []sdk.RemoteBraille{{Op: "gesture", Gesture: "route", Index: 2}, {Op: "gesture", Gesture: "pan-left"}} { + f.events <- sdk.SessionEvent{Sequence: uint64(3 + index), Kind: "remote.braille", Lease: lease, Epoch: 1, Braille: &value} + } + if frame := nextRelayFrame(t, received); !strings.Contains(frame, `braille_routeTo`) || !strings.Contains(frame, `"routingIndex":2`) { + t.Fatal("route gesture changed", frame) + } + if frame := nextRelayFrame(t, received); !strings.Contains(frame, `braille_scrollBack`) || strings.Contains(frame, "routingIndex") { + t.Fatal("pan gesture changed", frame) + } +} + +func TestBrailleRequiresGrant(t *testing.T) { + c, f := fixtureCoordinator(t, nil) + action := approveGrants(t, c, f, 1, "controlled", "output-observe") + received := make(chan string, 4) + frames := []string{`{"type":"set_braille_info","origin":7,"name":"Focus","numCells":40}`} + if err := c.connect(action, brailleRelay(t, controlled, frames, received), "synthetic-fixture"); err != nil { + t.Fatal(err) + } + nextCall(t, f, "remote.open") + awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "ready" && s.ignored == 1 }) + select { + case frame := <-received: + t.Fatal("Braille sent without grant", frame) + case <-time.After(200 * time.Millisecond): + } + for { + select { + case call := <-f.calls: + if call.method == "remote.braille" { + t.Fatal("Braille request without grant") + } + default: + return + } + } +} diff --git a/remote/src/command.go b/remote/src/command.go index 1671d7b..cd8054e 100644 --- a/remote/src/command.go +++ b/remote/src/command.go @@ -49,6 +49,7 @@ type connectionCommand struct { keyboard bool // Session-only; never persisted. keyProfile string // "portable" or "us"; session-only. clipboard bool // Session-only; never persisted. + braille bool // Session-only; never persisted. } func (command *connectionCommand) commands() []sdk.Command { @@ -93,7 +94,7 @@ func (command *connectionCommand) selection_form(notice string) sdk.Interaction if command.keyProfile == "us" { profiles[0], profiles[1] = profiles[1], profiles[0] } - result := sdk.Interaction{Form: &sdk.Form{Title: "Remote relay and role. Experimental speech and keyboard; clipboard and Braille services are unavailable.", Elements: []sdk.Element{ + result := sdk.Interaction{Form: &sdk.Form{Title: "Remote relay and role. Experimental speech, keyboard, clipboard and Braille; live verification is pending.", Elements: []sdk.Element{ {ID: "cancel", Label: "Cancel", Kind: sdk.Button}, {ID: "host", Label: "Relay host", Kind: sdk.Entry, Text: command.selected.Host, MaxLength: 253}, {ID: "port", Label: "Relay port", Kind: sdk.Entry, Text: strconv.Itoa(command.selected.Port), MaxLength: 5}, @@ -101,6 +102,7 @@ func (command *connectionCommand) selection_form(notice string) sdk.Interaction {ID: "keyboard", Label: "Include keyboard control for this session: controlling sends this keyboard when remote focus is on; allowing access lets the helper type here", Kind: sdk.CheckBox, Checked: command.keyboard}, {ID: "key-profile", Label: "Keys that may be sent", Kind: sdk.List, Items: profiles}, {ID: "clipboard", Label: "Allow explicit clipboard text transfer in both directions for this session", Kind: sdk.CheckBox, Checked: command.clipboard}, + {ID: "braille", Label: "Include Braille for this session: controlling shows the other computer's Braille on this display; allowing access sends this computer's Braille", Kind: sdk.CheckBox, Checked: command.braille}, {ID: "review-access", Label: "Review access for this session", Kind: sdk.Button}, {ID: "save-settings", Label: "Save relay and role without connecting", Kind: sdk.Button}, }}, Next: "remote-select"} @@ -174,6 +176,7 @@ func (command *connectionCommand) select_relay(ctx context.Context, raw json.Raw command.selected = selected command.keyboard = value.Values["keyboard"].Checked command.clipboard = value.Values["clipboard"].Checked + command.braille = value.Values["braille"].Checked command.keyProfile = "portable" if value.Values["key-profile"].Selected == "us" { command.keyProfile = "us" @@ -199,6 +202,9 @@ func (command *connectionCommand) select_relay(ctx context.Context, raw json.Raw if command.clipboard { grants = append(grants, "clipboard-exchange") } + if command.braille { + grants = append(grants, "braille-stream") + } command.awaiting = true return sdk.Interaction{Remote: &sdk.RemoteRequest{Role: selected.Role, Grants: grants}, Next: "remote-approved"}, nil } diff --git a/remote/src/connection_ui.go b/remote/src/connection_ui.go index f58f4e2..92d3ec8 100644 --- a/remote/src/connection_ui.go +++ b/remote/src/connection_ui.go @@ -192,12 +192,18 @@ func session_scope_text(action sdk.SessionEvent) string { text += " and keyboard control of this computer by the helper" } if slices.Contains(action.Grants, "clipboard-exchange") { - text += ", and explicit clipboard text transfer" + text += ", explicit clipboard text transfer" } - text += "; live verification is pending. Braille services are unavailable." + if slices.Contains(action.Grants, "braille-stream") { + text += ", Braille display output and routing" + } + text += "; live verification is pending." if !slices.Contains(action.Grants, "clipboard-exchange") { text += " Clipboard transfer was not approved." } + if !slices.Contains(action.Grants, "braille-stream") { + text += " Braille was not approved." + } return text } diff --git a/remote/src/connection_ui_test.go b/remote/src/connection_ui_test.go index 4242d21..591faec 100644 --- a/remote/src/connection_ui_test.go +++ b/remote/src/connection_ui_test.go @@ -72,7 +72,7 @@ func TestConnectionWorkflowBindsReaderActionAndFreezesTrust(t *testing.T) { } result := w.form() encoded, _ := json.Marshal(result) - if result.Form == nil || result.Next != "remote-connection" || !strings.Contains(string(encoded), "services are unavailable") { + if result.Form == nil || result.Next != "remote-connection" || !strings.Contains(string(encoded), "was not approved") { t.Fatal("missing form, continuation or service limitation") } workflowSubmit(t, w, "connect", strings.Repeat("猫", 200)) @@ -155,7 +155,7 @@ func TestConnectionWorkflowConnectUsesLoadedKeyWithoutEcho(t *testing.T) { awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "waiting" }) result = workflowSubmit(t, w, "refresh", "") encoded, _ := json.Marshal(result) - if !strings.Contains(string(encoded), "waiting for one opposite-role peer") || !strings.Contains(string(encoded), "Braille services are unavailable") || !strings.Contains(string(encoded), "Clipboard transfer was not approved") || strings.Contains(string(encoded), "keyboard control") { + if !strings.Contains(string(encoded), "waiting for one opposite-role peer") || !strings.Contains(string(encoded), "Braille was not approved") || !strings.Contains(string(encoded), "Clipboard transfer was not approved") || strings.Contains(string(encoded), "keyboard control") { t.Fatal("status advertised desktop control or omitted waiting state") } if w.key != "" { diff --git a/remote/src/coordinator.go b/remote/src/coordinator.go index 71275e7..0b05831 100644 --- a/remote/src/coordinator.go +++ b/remote/src/coordinator.go @@ -118,6 +118,8 @@ func (c *coordinator) read_events() { c.capture_locked(event) case "remote.focus": c.focus_locked(event) + case "remote.braille": + c.braille_event_locked(event) } c.mu.Unlock() } @@ -393,6 +395,9 @@ func (c *coordinator) run(a *connectionAttempt, approval sdk.SessionEvent, e end } c.speech_output(a, stream, conn) }() + c.mu.Lock() + c.braille_ready_locked(a, stream) + c.mu.Unlock() for a.ctx.Err() == nil { m, err := conn.read() if err != nil { @@ -409,6 +414,9 @@ func (c *coordinator) run(a *connectionAttempt, approval sdk.SessionEvent, e end if !c.update(a, s) { return } + c.mu.Lock() + c.braille_ready_locked(a, stream) + c.mu.Unlock() if accepted { handled, err := c.receive_speech(a, stream, m) if err == nil && !handled { @@ -417,6 +425,9 @@ func (c *coordinator) run(a *connectionAttempt, approval sdk.SessionEvent, e end if err == nil && !handled { handled = c.receive_clipboard(a, stream, m) } + if err == nil && !handled { + handled = c.receive_braille(a, stream, m) + } if err != nil { failure = err return diff --git a/remote/src/speech_stream.go b/remote/src/speech_stream.go index d0d5f26..ce35321 100644 --- a/remote/src/speech_stream.go +++ b/remote/src/speech_stream.go @@ -46,13 +46,21 @@ type speechStream struct { // Explicit clipboard transfer; coordinator.mu. received string hasReceived bool + // Braille; coordinator.mu. Cell streams keep only the newest frame. + brailleStarted bool + brailleOps chan sdk.RemoteBraille + readerCells []int + readerCellsSignal chan struct{} + displayCells []int + displaySignal chan struct{} } func newSpeechStream(lease sdk.RemoteLease, approval sdk.SessionEvent) *speechStream { return &speechStream{lease: lease, role: approval.Role, grants: slices.Clone(approval.Grants), incoming: make(chan speechItem, maxSpeechItems), outgoing: make(chan []byte, maxSpeechItems), keys: make(chan sdk.RemoteKey, maxKeyItems), captured: make(chan sdk.RemoteCapturedKey, maxCapturedKeys), - focusRequests: make(chan bool, 4)} + focusRequests: make(chan bool, 4), brailleOps: make(chan sdk.RemoteBraille, maxBrailleOps), + readerCellsSignal: make(chan struct{}, 1), displaySignal: make(chan struct{}, 1)} } func (stream *speechStream) keyboard_enabled() bool { @@ -73,6 +81,7 @@ func (stream *speechStream) drain() { case <-stream.captured: stream.capturedItems-- case <-stream.focusRequests: + case <-stream.brailleOps: default: return } @@ -221,6 +230,17 @@ func (c *coordinator) speech_operations(a *connectionAttempt, stream *speechStre if !heartbeat() { return } + case value := <-stream.brailleOps: + if !c.braille_call(a, stream, value) { + return + } + case <-stream.readerCellsSignal: + c.mu.Lock() + cells := stream.take_reader_cells_locked() + c.mu.Unlock() + if cells != nil && !c.braille_call(a, stream, sdk.RemoteBraille{Op: "cells", Cells: cells}) { + return + } case remote := <-stream.focusRequests: c.mu.Lock() ready := c.speech_ready_locked(a, stream) @@ -303,11 +323,51 @@ func (c *coordinator) deliver_key(a *connectionAttempt, stream *speechStream, ke return true } +// braille_call sends one remote.braille operation in the shared sequence. +func (c *coordinator) braille_call(a *connectionAttempt, stream *speechStream, value sdk.RemoteBraille) bool { + c.mu.Lock() + ready := c.speech_ready_locked(a, stream) + c.mu.Unlock() + if !ready { + return false + } + stream.sequence++ + request := sdk.RemoteBrailleRequest{RemoteOperation: sdk.RemoteOperation{Lease: stream.lease.Lease, Epoch: a.epoch, Sequence: stream.sequence}, Braille: value} + if c.call("remote.braille", request, nil) != nil { + c.mu.Lock() + c.stop_locked(errLease) + c.mu.Unlock() + return false + } + return true +} + func (c *coordinator) speech_output(a *connectionAttempt, stream *speechStream, conn *relayConn) { for { select { case <-a.ctx.Done(): return + case <-stream.displaySignal: + c.mu.Lock() + ready := c.speech_ready_locked(a, stream) + cells := stream.take_display_locked() + c.mu.Unlock() + if !ready { + return + } + if cells == nil { + continue + } + frame, err := encodeMessage("display", map[string][]int{"cells": cells}) + if err == nil { + err = conn.write(a.ctx, frame) + } + if err != nil { + c.mu.Lock() + c.stop_locked(err) + c.mu.Unlock() + return + } case frame := <-stream.outgoing: c.mu.Lock() ready := c.speech_ready_locked(a, stream) diff --git a/tools/check.py b/tools/check.py index d817fec..8faefb7 100644 --- a/tools/check.py +++ b/tools/check.py @@ -168,8 +168,8 @@ def check_remote(repoRoot): timeout=60, check=True) value = json.loads(result.stdout) require(value.get("next") == "remote-select" - and "Experimental speech and keyboard; clipboard and Braille services are unavailable" in value["form"]["title"], - "Remote did not disclose its experimental speech and keyboard scope") + and "Experimental speech, keyboard, clipboard and Braille; live verification is pending" in value["form"]["title"], + "Remote did not disclose its experimental scope") subprocess.run([ "go", "test", "./internal/app", "-run", "^(TestRemoteConnectionCommand|TestRemoteSpeech|TestRemoteDocument|TestRemoteReadAll|TestRemoteCurrentLine|TestRemoteNative|TestRemoteReview|TestRemoteFlatReview|TestRemoteWhereAmI|TestRemoteKeyboard)", "-count=1", "-timeout=90s",