Skip to content

Commit 920e516

Browse files
authored
Meetings: the reader that writes down who a call app shows and who is speaking, and the place each app's adapter plugs in (macOS; no app is read yet) (#2934)
1 parent f1c772c commit 920e516

10 files changed

Lines changed: 1697 additions & 20 deletions

File tree

‎docs/features/meetings.md‎

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,9 +2830,11 @@ current one), which is why Rust's name overlap decides.
28302830

28312831
### Speaker Names
28322832

2833-
Implemented: the data model, every reader of it, and the rules that work out
2834-
names from what a call app shows ([Working out names](#working-out-names)).
2835-
Not implemented: anything that reads a call app, so nothing runs those rules.
2833+
Implemented: the data model, every reader of it, the rules that work out
2834+
names from what a call app shows, and on macOS the reader that writes down
2835+
what a call app shows ([Working out names](#working-out-names)).
2836+
Not implemented: an adapter for any call app, or anything that starts the
2837+
reader, so nothing runs those rules.
28362838
No build writes a `speaker` or a `speakers` table yet, so every remote line
28372839
is still `Them` and every saved file, prompt, and JSON response is what it
28382840
was before.
@@ -2904,10 +2906,13 @@ hand-built tables; no recorded meeting has a named speaker.
29042906
#### Working Out Names
29052907
29062908
Exists (`src/meeting/speakers/`), tested, and called by nothing: the evidence
2907-
a reader would save, a calibration, the resolver, and the step that turns its
2908-
answer into the table and ids above. Does not exist: a reader of any call app,
2909-
the wiring into the transcript worker, a Labs switch, the pane's corrections,
2910-
any voice model. No file is written and no name appears.
2909+
a reader saves, a calibration, the resolver, the step that turns its answer
2910+
into the table and ids above, and on macOS the reader itself with the seam a
2911+
call app's adapter plugs into. Does not exist: an adapter for any call app
2912+
(each is written against a live read of that app), anything that starts the
2913+
reader with a recording, the wiring into the transcript worker, a Labs
2914+
switch, the pane's corrections, any voice model. No file is written and no
2915+
name appears.
29112916
29122917
```ts
29132918
speakers.ndjson (meeting folder, owner-only, to the Trash with the folder)
@@ -2950,8 +2955,34 @@ Resolver (pure) -> (remote words' times, evidence, calibration, strictness)
29502955
Lines -> a remote line takes a speaker only when everything it overlaps was
29512956
said by one person the call app showed, with a usable name; ids s1, s2
29522957
in the order people first speak; a name the user gave is from "user"
2958+
Reader (macOS only: it reads accessibility::tree snapshots) -> speakers.ndjson
2959+
├── Adapter, one per call app (pure) -> a snapshot of the app's windows ->
2960+
│ active { roster, floor } | no call window | untrusted(reason). Found by
2961+
│ canonical bundle id or by the call page's host. None is listed yet
2962+
├── Before any adapter is asked: a snapshot a budget cut short -> untrusted
2963+
│ cut_short; an app with no window -> no call window
2964+
├── Poll state (pure) -> one look in, the lines it adds out
2965+
│ ├── The app's own id for a person never leaves memory: each gets the
2966+
│ │ next key (p1, p2) when first seen, after any the meeting holds
2967+
│ ├── participant: when first seen, and again when the app shows them
2968+
│ │ differently (cleaned name, whether they are the user). Two tiles
2969+
│ │ of one person are one person
2970+
│ ├── floor: every look at a call read whole -> the one marked, or nobody
2971+
│ ├── untrusted: the adapter's reason, or cut_short
2972+
│ └── Nothing for no call window, or for a mark on someone never shown
2973+
├── Loop -> a look every 0.5 s on the recording's clock, stamped when it
2974+
│ starts; a look that overran -> a 0.25 s rest and one look, not the ones
2975+
│ missed; ends with the recording, with nothing read or written after
2976+
├── A write that fails -> those lines are lost and counted, and everyone
2977+
│ is written again at their next look
2978+
└── Logs -> what a look came to when that changes (debug), one warning for
2979+
a run of failed writes, counts at the end. Never a name or an app id
29532980
```
29542981
2982+
Not reconciled yet: when the app shows someone differently the reader writes
2983+
a second participant line, and the resolver still takes the first line for
2984+
each key, so a name that arrives after the tile does names nobody.
2985+
29552986
The accepted limit: a call app marks one speaker at a time, so words said
29562987
over the person holding the floor take that person's name, at every
29572988
strictness. A reply within half a second of someone stopping can too.
@@ -2984,6 +3015,25 @@ simulation's model, not a real one. File handling:
29843015
`a_line_cut_short_by_a_crash_spoils_only_itself`,
29853016
`a_line_from_a_newer_build_is_skipped_and_survives_a_correction`.
29863017
3018+
Reader checks (macOS; an invented call app read from hand-written snapshots,
3019+
a clock that moves only when waited on, no real app):
3020+
`people_are_written_once_under_keys_in_the_order_they_are_first_seen`,
3021+
`someone_the_app_comes_to_show_differently_is_written_again_under_their_key`,
3022+
`the_floor_is_written_at_every_look_as_it_passes_from_one_to_another`,
3023+
`a_snapshot_cut_short_is_an_untrusted_look_and_names_nobody_new`,
3024+
`two_call_windows_are_an_untrusted_look`,
3025+
`a_hidden_call_window_is_an_untrusted_look_for_as_long_as_it_is_hidden`,
3026+
`the_file_holds_keys_and_names_and_never_an_app_id` (the real file),
3027+
`the_log_holds_counts_and_reasons_and_never_a_name_or_an_app_id` (everything
3028+
logged at every level), `lines_that_were_not_saved_are_counted_and_everyone_is_written_again`,
3029+
`a_slow_look_is_followed_by_a_rest_and_one_look_not_by_the_ones_it_missed`,
3030+
`stopping_ends_the_reader_with_nothing_read_or_written_afterwards`, and one
3031+
property over random looks:
3032+
`whatever_an_app_shows_every_key_is_introduced_before_it_is_used_and_no_id_is_written`.
3033+
Seam: `a_snapshot_cut_short_is_never_shown_to_an_adapter`,
3034+
`an_app_is_read_by_the_adapter_listed_under_its_key`, `no_app_is_listed_twice`.
3035+
Nothing has read a real call app through it.
3036+
29873037
### Agent Access (MCP)
29883038
29893039
The release CLI also supports `hex meetings list`, `show <id|latest>` (with

‎src/meeting/speakers.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ use super::{MeetingManifest, MeetingSource, TranscriptEntry};
3131
// is not a test build expects them to be unused. The expectation fails the
3232
// build the moment one of them is fully in use, so it cannot outlive its
3333
// reason.
34+
//
35+
// The reader and what it reads through are macOS only: they take the
36+
// snapshot Hex's Accessibility client makes, and Windows and Linux Hex have
37+
// no such client yet.
38+
#[cfg(target_os = "macos")]
39+
#[cfg_attr(
40+
not(test),
41+
expect(dead_code, reason = "no call app has an adapter yet")
42+
)]
43+
mod adapter;
3444
#[cfg_attr(not(test), expect(dead_code, reason = "no reader writes evidence yet"))]
3545
mod calibrate;
3646
#[cfg_attr(not(test), expect(dead_code, reason = "no reader writes evidence yet"))]
@@ -39,6 +49,18 @@ mod evidence;
3949
mod floor;
4050
#[cfg_attr(not(test), expect(dead_code, reason = "no reader writes evidence yet"))]
4151
mod names;
52+
#[cfg(target_os = "macos")]
53+
#[cfg_attr(
54+
not(test),
55+
expect(dead_code, reason = "no recording starts a reader yet")
56+
)]
57+
mod reader;
58+
#[cfg(target_os = "macos")]
59+
#[cfg_attr(
60+
not(test),
61+
expect(dead_code, reason = "no call app has an adapter yet")
62+
)]
63+
mod registry;
4264
#[cfg_attr(not(test), expect(dead_code, reason = "no reader writes evidence yet"))]
4365
mod resolve;
4466

‎src/meeting/speakers/adapter.rs‎

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
//! What a call app shows, as Hex takes it.
2+
//!
3+
//! Every call app draws its call differently, and each gets an adapter: one
4+
//! pure function from a snapshot of the app's windows to an
5+
//! [`Observation`], which says who is on the call and who holds the floor,
6+
//! or why that cannot be told. The snapshot is plain data
7+
//! ([`accessibility::tree`](crate::accessibility::tree)), so an adapter
8+
//! touches no app, no clock and no file, and is tested on trees written by
9+
//! hand. Reading another app is one adapter and one line in
10+
//! [`registry`](super::registry).
11+
//!
12+
//! An adapter tells people apart by whatever the app does, most often a
13+
//! user id inside a DOM id. That is an [`AppParticipantId`], and it is the
14+
//! one thing here that must never be saved or logged. It cannot be: it does
15+
//! not serialize, it prints without its text, and nothing reads the text
16+
//! back out of it. The [`reader`](super::reader) gives each one a key of
17+
//! the meeting's own (`p1`, `p2`) and forgets it when the recording ends.
18+
//!
19+
//! macOS only: the snapshot is read by Hex's Accessibility client, and
20+
//! Windows and Linux Hex have none (UI Automation, AT-SPI) yet.
21+
22+
use std::fmt;
23+
24+
use super::SpeakerName;
25+
use super::evidence::Untrusted;
26+
use crate::accessibility::tree::Snapshot;
27+
28+
/// A call app's own id for someone on a call. It tells two tiles of one
29+
/// person from two people, and that is all it can do: two of them can be
30+
/// compared, and nothing else.
31+
#[derive(Clone, Eq, Hash, PartialEq)]
32+
pub struct AppParticipantId(String);
33+
34+
impl AppParticipantId {
35+
/// The id an app shows for someone. `None` when there is nothing in
36+
/// it: a blank id would make one person of everyone it was read for.
37+
pub fn parse(shown: &str) -> Option<Self> {
38+
let id = shown.trim();
39+
(!id.is_empty()).then(|| Self(id.to_owned()))
40+
}
41+
}
42+
43+
impl fmt::Debug for AppParticipantId {
44+
/// Without the text, so that no log line or panic message can carry it.
45+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
46+
formatter.write_str("AppParticipantId(..)")
47+
}
48+
}
49+
50+
/// Someone a call app showed on the call at one look.
51+
#[derive(Clone, Debug, Eq, PartialEq)]
52+
pub struct ObservedParticipant {
53+
pub id: AppParticipantId,
54+
/// What the app calls them, cleaned. Nobody when it shows nothing Hex
55+
/// can use as a name.
56+
pub name: Option<SpeakerName>,
57+
/// The person using Hex.
58+
pub is_local: bool,
59+
}
60+
61+
/// What one look at a call app's windows showed.
62+
#[derive(Clone, Debug, Eq, PartialEq)]
63+
pub enum Observation {
64+
/// The call, read whole.
65+
Active {
66+
/// Everyone the app shows on the call. Two tiles of one person are
67+
/// one person: the first of them stands.
68+
roster: Vec<ObservedParticipant>,
69+
/// The one person the app marks as speaking, or nobody. They are
70+
/// in the roster, now or at an earlier look: a mark on someone the
71+
/// app never showed says nothing about the floor.
72+
floor: Option<AppParticipantId>,
73+
},
74+
/// None of the app's windows is a call.
75+
NoCallWindow,
76+
/// A call window is there, and what it shows cannot be relied on.
77+
Untrusted(Untrusted),
78+
}
79+
80+
impl Observation {
81+
/// What `adapter` makes of one snapshot, under the two rules that hold
82+
/// for every app and so are no adapter's to remember. A snapshot a
83+
/// budget cut short may be missing a tile, so no adapter is shown it.
84+
/// And an app with no window has no call window.
85+
pub fn of(snapshot: &Snapshot, adapter: &dyn CallAppAdapter) -> Self {
86+
if !snapshot.cut_short.is_empty() {
87+
Self::Untrusted(Untrusted::CutShort)
88+
} else if snapshot.windows.is_empty() {
89+
Self::NoCallWindow
90+
} else {
91+
adapter.observe(snapshot)
92+
}
93+
}
94+
}
95+
96+
/// Reads one call app's windows. The same snapshot always gets the same
97+
/// answer and nothing is touched, so one adapter serves every recording.
98+
pub trait CallAppAdapter: Sync {
99+
/// What the app's windows show. Asked only through
100+
/// [`Observation::of`]: of a snapshot read whole, with a window in it.
101+
fn observe(&self, snapshot: &Snapshot) -> Observation;
102+
}
103+
104+
/// An adapter is most often just a function.
105+
impl<F: Fn(&Snapshot) -> Observation + Sync> CallAppAdapter for F {
106+
fn observe(&self, snapshot: &Snapshot) -> Observation {
107+
self(snapshot)
108+
}
109+
}
110+
111+
#[cfg(test)]
112+
mod tests {
113+
use super::*;
114+
use crate::accessibility::tree::{Cut, Node};
115+
116+
fn window() -> Node {
117+
Node {
118+
role: Some("AXWindow".into()),
119+
..Default::default()
120+
}
121+
}
122+
123+
fn nobody_speaking(_: &Snapshot) -> Observation {
124+
Observation::Active {
125+
roster: Vec::new(),
126+
floor: None,
127+
}
128+
}
129+
130+
fn never_asked(_: &Snapshot) -> Observation {
131+
panic!("no adapter is shown this snapshot")
132+
}
133+
134+
#[test]
135+
fn a_snapshot_read_whole_is_the_adapters_to_read() {
136+
let snapshot = Snapshot {
137+
windows: vec![window()],
138+
..Default::default()
139+
};
140+
assert_eq!(
141+
Observation::of(&snapshot, &nobody_speaking),
142+
nobody_speaking(&snapshot)
143+
);
144+
}
145+
146+
#[test]
147+
fn a_snapshot_cut_short_is_never_shown_to_an_adapter() {
148+
for cut in [Cut::Nodes, Cut::Depth, Cut::Deadline] {
149+
// Whatever was read before the budget ran out, even nothing.
150+
for windows in [vec![window()], Vec::new()] {
151+
let snapshot = Snapshot {
152+
windows,
153+
cut_short: vec![cut],
154+
..Default::default()
155+
};
156+
assert_eq!(
157+
Observation::of(&snapshot, &never_asked),
158+
Observation::Untrusted(Untrusted::CutShort)
159+
);
160+
}
161+
}
162+
}
163+
164+
#[test]
165+
fn an_app_with_no_window_has_no_call_window() {
166+
assert_eq!(
167+
Observation::of(&Snapshot::default(), &never_asked),
168+
Observation::NoCallWindow
169+
);
170+
}
171+
172+
#[test]
173+
fn an_app_id_is_never_blank_and_never_printed() {
174+
let id = AppParticipantId::parse(" U024BE7LH ").unwrap();
175+
assert_eq!(id, AppParticipantId::parse("U024BE7LH").unwrap());
176+
assert_ne!(id, AppParticipantId::parse("U024BE7LJ").unwrap());
177+
for blank in ["", " ", "\n"] {
178+
assert_eq!(AppParticipantId::parse(blank), None, "{blank:?}");
179+
}
180+
181+
let seen = Observation::Active {
182+
roster: vec![ObservedParticipant {
183+
id: id.clone(),
184+
name: SpeakerName::parse("Priya Nair"),
185+
is_local: false,
186+
}],
187+
floor: Some(id),
188+
};
189+
let printed = format!("{seen:?}");
190+
assert!(!printed.contains("U024BE7LH") && !printed.contains("Priya"));
191+
}
192+
}

‎src/meeting/speakers/calibrate.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! the reader saw is used.
1010
1111
use super::evidence::Interval;
12+
use super::floor::POLL_MS;
1213

1314
/// The mark's delays. Until a call has shown enough, Hex assumes the slow
1415
/// end of what call apps were described as doing: half a second to come on
@@ -64,7 +65,7 @@ const LONGEST_LAG_MS: u64 = 2_000;
6465
const LONGEST_TAIL_MS: u64 = 4_000;
6566
/// How close the end of speech may be to the mark coming on and still be
6667
/// what set it off: one look.
67-
const LOOK_MS: u64 = 500;
68+
const LOOK_MS: u64 = POLL_MS;
6869
/// The user talking this long, this many times, with the tile never
6970
/// lighting, is a reader that cannot see the tile.
7071
const UNSEEN_TURN_MS: u64 = 2_000;

‎src/meeting/speakers/evidence.rs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! What Hex saw of who was speaking, kept beside the meeting.
22
//!
33
//! A call app shows who is on the call and marks who is speaking. A reader
4-
//! (which does not exist yet) will note what it sees while a meeting
5-
//! records: who is there, and at each look who holds the floor. Those notes
4+
//! (which nothing starts yet) notes what it sees while a meeting records:
5+
//! who is there, and at each look who holds the floor. Those notes
66
//! are the evidence, and names are worked out from them afterwards, so a
77
//! better rule or a correction from the user renames a meeting without
88
//! recording it again.
@@ -99,14 +99,15 @@ impl ParticipantKey {
9999
/// holds.
100100
pub fn next(evidence: &[Evidence]) -> Self {
101101
let highest = evidence.iter().filter_map(|line| match line {
102-
Evidence::Participant(participant) => Some(participant.key.0),
102+
Evidence::Participant(participant) => Some(participant.key),
103103
_ => None,
104104
});
105-
Self(
106-
highest
107-
.max()
108-
.map_or(NonZeroU32::MIN, |key| key.saturating_add(1)),
109-
)
105+
highest.max().map_or(Self(NonZeroU32::MIN), Self::following)
106+
}
107+
108+
/// The key after this one, for the next person met.
109+
pub fn following(self) -> Self {
110+
Self(self.0.saturating_add(1))
110111
}
111112

112113
#[cfg(test)]
@@ -160,7 +161,8 @@ pub struct Participant {
160161
/// they never name a remote line; their tile is what the reader is
161162
/// checked against.
162163
pub is_local: bool,
163-
/// When the reader first saw them.
164+
/// When the reader first saw them as this line has them. Someone the
165+
/// call app comes to show under another name gets another line.
164166
pub at_ms: u64,
165167
}
166168

@@ -532,6 +534,7 @@ mod tests {
532534
#[test]
533535
fn keys_are_handed_out_in_the_order_people_are_first_seen() {
534536
assert_eq!(ParticipantKey::next(&[]), key(1));
537+
assert_eq!(key(1).following(), key(2));
535538
let call = [person(1, "Kit", true), person(4, "Priya Nair", false)];
536539
assert_eq!(ParticipantKey::next(&call), key(5));
537540
}

0 commit comments

Comments
 (0)