mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* perf: bound transcription decoder threads and raise inference QoS
GGUF sessions on GPU devices now request one CPU thread instead of
transcribe.cpp's default min(8, ncpu). Parakeet's per-token TDT decoder
runs on CPU even with Metal encoding, and ggml's spin-waiting worker pool
stalls it under CPU load. CPU-only devices (Linux Backend::Auto fallback)
keep the library default so the encoder is not serialized.
The macOS inference thread moves from user-initiated to user-interactive
QoS. ggml creates workers with plain pthread_create, which starts them at
QOS_CLASS_DEFAULT rather than inheriting (confirmed with a probe); with one
thread no workers are created and decoding stays on this thread.
transcribe-cpp 0.2.4 bench, Unified English Q8, Metal, Mac Studio (18
cores, already loaded by other work), user-interactive QoS, median ms for
3/30/90 s clips:
+ 36 `yes` procs: 1 thread 170/703/1819, 2 threads 136/1907/4940,
4 threads 178/4304/13519
no extra load: 1 thread 83/364/1631, 2 threads 64/705/2889
Not verified physically on the MacBook Pro or on Linux.
* fix(paste): mark transcript clipboard writes as transient
Clipboard managers such as Maccy and Raycast recorded every dictation
because the paste write carried only plain text. Publish the transcript
as one pasteboard item that also carries org.nspasteboard.TransientType
and org.nspasteboard.AutoGeneratedType so conforming managers skip it.
Generation-safe restoration of the previous clipboard is unchanged.
Refs kitlangton/Hex#223
* fix(keyboard): resolve Command shortcuts on the layout's Command layer
On "Dvorak – QWERTY ⌘" the plain layer puts V on keycode 47, but with
Command held that key is ⌘. — so synthetic ⌘V posted ⌘. and paste beeped.
Build a second snapshot map with UCKeyTranslate's cmdKey modifier state
during initialize_layout and resolve Command shortcuts against it first,
falling back to the plain snapshot. Headless lookups do the same.
Refs kitlangton/Hex#162
* fix(dictation): discard near-silent captures before inference
Holding the shortcut without speaking made Cohere (and Whisper-style
models) paste a hallucinated "thank you". Measure the loudest 30 ms
window of the captured 16 kHz audio, DC removed and excluding model
padding, and discard captures below -50 dBFS as empty: no inference,
paste, History, or last-result update. The level and threshold are
logged. The threshold is conservative so whispered speech is kept.
Covers macOS hotkey, voice-delimited, and Voice Action captures and the
Linux hotkey loop. Local API dictation and host-audio transcription
deliberately keep returning raw model output.
Refs anomalyco/hex#108
* fix(audio): keep the held press when a cold microphone glitches
With Release when idle, the first hold after minutes of idle failed with
the error tone. The cold stream reported "A buffer underrun or overrun
occurred" — cpal 0.18's ErrorKind::Xrun from CoreAudio's processor
overload listener, which does not stop the stream — and HEX treated it as
fatal: the owner closed the device without retrying and recognition
suspended the still-held gesture.
- Log and ignore Xrun and RealtimeDenied stream errors; real sample gaps
still fail the capture as discontinuities.
- In release-when-idle mode, a stream failure before the hold threshold
returns the press to pending and reopens, so release-before-ready
discards and readiness captures from the original press. Later
failures still fail the capture rather than paste a fragment.
- Cold opens retry the selected microphone twice, 100 ms apart, before
the existing automatic fallback.
Refs anomalyco/hex#130
* feat: add pause segmenter for incremental transcription
* feat: cut intentional dictation captures at pauses
* feat: transcribe completed speech at pauses and join it with the tail
* feat: add Transcribe during pauses setting
* docs: map incremental transcription
* fix(audio): drain before checking pending cold captures
* fix: keep piece admission guard held through inference and refine segment joins
* refactor: simplify clipboard, keyboard, silence gate, and cold-audio helpers
* refactor: simplify incremental transcription state and session options
* feat(meetings): transcribe in rolling overlapping chunks with echo suppression
Stream each track through a 16 kHz resampler into pause-aware chunks
(first pause after 20 s, hard cut at 30 s with a 2 s overlap) and
transcribe them while recording on a utility-QoS session that waits for
dictation capture and inference. Tracks that fall behind are rebuilt from
their WAV after Stop. Seams drop repeated words, microphone utterances
that echo overlapping remote speech are removed, and each finished meeting
is written as Markdown to the configured folder. Remote speech is labeled
Them.
* feat(meetings): add release opt-in, call capsules, and menu-bar recording
Meetings (beta) in Settings enables detection, the Meetings pane, and
meeting paste in release builds, with a Screen Recording permission row
and a transcript folder. Offers appear as a focus-free capsule with a
countdown and stay snoozed for the call. The menu bar shows elapsed
recording time with Stop & Transcribe, and a capsule asks Keep Recording
or Stop & Transcribe when the call app leaves the microphone.
* docs: map Meetings beta and update meeting invariants
* feat(meetings): write titles, summaries, and action items with Apple Intelligence
Add a weak-linked FoundationModels Swift bridge (availability, context
size, guided-generation notes at utility priority) and a meeting notes
worker that runs after final publication: bounded map/reduce chunking
sized from the model context, a total deadline, manifest storage, and an
in-place marker-delimited Markdown update that keeps the file name.
Settings gains 'Summarize with Apple Intelligence' (default on) with a
one-line availability; the Meetings pane and ready capsule show the
generated title, notes, and a Regenerate Notes action. Debug CLI:
hex meeting summarize <id|file>.
* docs: map Apple Intelligence meeting notes
* fix(meetings): stop labeling speaker echo as You with signal-level bleed detection
Rolling chunks fell behind (packet-bounded queue) and the pane then showed the raw
Moonshine draft without any echo suppression, so microphone twins of remote speech
appeared as You. Coalesce rolling audio into one-second blocks, keep transcribed
entries of a track that fell behind, judge the live draft with the same echo rules,
split timed words into sentences, and classify microphone segments by comparing
their energy with delayed system audio so misheard bleed is dropped and double-talk
is kept.
* feat(meetings): redesign the pane with notes, conversational turns, search, rename, and delete
List rows show the generated title, time, length, app, and a status chip, grouped
by day. The detail leads with notes, then Them/You turns on opposite sides that
follow the live tail, under one action row: Copy Notes, Copy Transcript, Reveal
Markdown, Regenerate Notes, Rename, and a two-step Delete that moves the Markdown
and recording to the Trash. Adds a deterministic meetings preview.
* docs: map meeting echo suppression, pane redesign, delete, and rename
* feat(meetings): add read-only hex mcp server for meeting transcripts
* docs(meetings): map the meetings MCP server and Granola import options
* feat(meetings): provisional titles while recording and one-call short summaries
Name a recording from its opening (~90 s of speech or 600 words) with one
title-only Apple Intelligence call, refreshed once at ten minutes, shown in
the menu bar, Meetings pane, manifest, and exported file. After publication,
write the final title and a summary of at most two sentences with one call
over a bounded excerpt (opening, sampled middle, ending) instead of
map-reduce. Remove action items, decisions, and chunking; older manifests
still read. get_meeting_notes now returns the title and summary and points
agents at the transcript.
* feat(meetings): mirror another Mac's meetings for local MCP servers
One periodic rsync (scripts/sync-meetings-mirror.sh, LaunchAgent template)
replaces an SSH session per MCP client, which exhausted the Pro's sshd.
A copy of the binary named hex-meetings-mcp always runs hex mcp.
* test(dictation): prove release trimming keeps the last word and isolate the instance-lock test
Add a resampled delayed-release regression test (44.1/48 kHz, segmented and
not) and an opt-in Unified English release-boundary harness. The instance
lock test now uses a temporary directory instead of the real Application
Support folder, which accumulated test-<pid>.lock files.
* fix(dictation): preserve mid-clause pause joins, skip silent tails, and add corpus harness
* feat(dictation): keep 200 ms of audio after release
* test(dictation): apply the post-release tail in the corpus harness
* fix(dictation): transcribe short final pieces with their preceding audio
* fix(linux): borrow the model path for GGUF validation
* fix(linux): scope macOS-only history, deletion, and thread-test code out of Linux dead-code lints
332 lines
12 KiB
Rust
332 lines
12 KiB
Rust
//! `hex mcp`: a read-only MCP stdio server over recorded meetings. A thin
|
|
//! adapter; queries and output live in `meeting::query`.
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
use color_eyre::eyre::{Result, eyre};
|
|
use rmcp::handler::server::router::tool::ToolRouter;
|
|
use rmcp::handler::server::wrapper::Parameters;
|
|
use rmcp::model::{
|
|
CallToolResult, ContentBlock, Implementation, ListResourceTemplatesResult, ListResourcesResult,
|
|
PaginatedRequestParams, ReadResourceRequestParams, ReadResourceResponse, ReadResourceResult,
|
|
Resource, ResourceContents, ResourceTemplate, ServerCapabilities, ServerConfig,
|
|
};
|
|
use rmcp::service::RequestContext;
|
|
use rmcp::{
|
|
ErrorData, RoleServer, ServerHandler, ServiceExt, schemars, tool, tool_handler, tool_router,
|
|
};
|
|
use serde::Deserialize;
|
|
|
|
use crate::events::now_ms;
|
|
use crate::meeting::query::{Library, ListQuery, SearchQuery, TranscriptQuery};
|
|
|
|
const RESOURCE_SCHEME: &str = "hex-meeting://";
|
|
|
|
const INSTRUCTIONS: &str = "Kit's locally recorded HEX meetings (calls captured on his Mac). \
|
|
Speakers are `You` (Kit, his microphone) and `Them` (everyone else, system audio); individual \
|
|
remote speakers are not separated. Transcripts come from local speech recognition and contain \
|
|
misheard words, so search is stemmed and fuzzy by default. Typical flow: list_meetings or \
|
|
search_transcripts to find a meeting and timestamp, then get_transcript around it, and \
|
|
get_meeting_notes for a stored title and two-sentence summary. Details, decisions, and action \
|
|
items are only in the transcript. Everything is read-only and stays on the machine.";
|
|
|
|
#[derive(Debug, Deserialize, schemars::JsonSchema)]
|
|
pub struct ListMeetingsArgs {
|
|
/// Only meetings overlapping this time or later: `2026-10-15`, `2026-10-15T14:00`,
|
|
/// RFC 3339, `today`, `yesterday`, or relative `7d`/`36h`.
|
|
#[serde(default)]
|
|
pub since: Option<String>,
|
|
/// Only meetings starting before this time; a date alone includes that whole day.
|
|
#[serde(default)]
|
|
pub until: Option<String>,
|
|
/// Words that must all appear in the title or app (case- and accent-insensitive).
|
|
#[serde(default)]
|
|
pub query: Option<String>,
|
|
/// Maximum meetings to return (default 20, maximum 200).
|
|
#[serde(default)]
|
|
pub limit: Option<u32>,
|
|
/// Include a meeting that is being recorded right now (default true).
|
|
#[serde(default)]
|
|
pub include_in_progress: Option<bool>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, schemars::JsonSchema)]
|
|
pub struct SearchTranscriptsArgs {
|
|
/// Words to find. BM25-ranked; tolerant of misspellings and sound-alikes unless
|
|
/// fuzzy is false. Wrap words in double quotes to require an exact phrase.
|
|
pub query: String,
|
|
/// Only meetings overlapping this time or later (same formats as list_meetings).
|
|
#[serde(default)]
|
|
pub since: Option<String>,
|
|
/// Only meetings starting before this time.
|
|
#[serde(default)]
|
|
pub until: Option<String>,
|
|
/// Search a single meeting.
|
|
#[serde(default)]
|
|
pub meeting_id: Option<String>,
|
|
/// Maximum passages to return (default 10, maximum 50).
|
|
#[serde(default)]
|
|
pub limit: Option<u32>,
|
|
/// Match prefixes, small misspellings, and sound-alike names (default true).
|
|
#[serde(default)]
|
|
pub fuzzy: Option<bool>,
|
|
/// Include a meeting that is being recorded right now (default true).
|
|
#[serde(default)]
|
|
pub include_in_progress: Option<bool>,
|
|
}
|
|
|
|
/// A transcript offset: `mm:ss`, `h:mm:ss`, or seconds.
|
|
#[derive(Debug, Deserialize, schemars::JsonSchema)]
|
|
#[serde(untagged)]
|
|
pub enum Offset {
|
|
Seconds(f64),
|
|
Text(String),
|
|
}
|
|
|
|
impl Offset {
|
|
fn text(self) -> String {
|
|
match self {
|
|
Self::Seconds(seconds) => seconds.to_string(),
|
|
Self::Text(text) => text,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, schemars::JsonSchema)]
|
|
pub struct GetTranscriptArgs {
|
|
/// The meeting id from list_meetings or search_transcripts.
|
|
pub meeting_id: String,
|
|
/// Start offset into the meeting: `mm:ss`, `h:mm:ss`, or seconds.
|
|
#[serde(default)]
|
|
pub start: Option<Offset>,
|
|
/// End offset into the meeting: `mm:ss`, `h:mm:ss`, or seconds.
|
|
#[serde(default)]
|
|
pub end: Option<Offset>,
|
|
/// `you`, `them`, or `all` (default).
|
|
#[serde(default)]
|
|
pub speaker: Option<String>,
|
|
/// Maximum transcript characters to return (default 20000).
|
|
#[serde(default)]
|
|
pub max_chars: Option<u32>,
|
|
/// `next_cursor` from a previous call, to continue where it stopped.
|
|
#[serde(default)]
|
|
pub cursor: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, schemars::JsonSchema)]
|
|
pub struct GetMeetingNotesArgs {
|
|
/// The meeting id from list_meetings or search_transcripts.
|
|
pub meeting_id: String,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct MeetingServer {
|
|
library: Arc<Library>,
|
|
tool_router: ToolRouter<Self>,
|
|
}
|
|
|
|
impl std::fmt::Debug for MeetingServer {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
formatter
|
|
.debug_struct("MeetingServer")
|
|
.field("root", &self.library.root())
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
fn reply(result: Result<String>) -> Result<CallToolResult, ErrorData> {
|
|
Ok(match result {
|
|
Ok(text) => CallToolResult::success(vec![ContentBlock::text(text)]),
|
|
Err(error) => CallToolResult::error(vec![ContentBlock::text(error.to_string())]),
|
|
})
|
|
}
|
|
|
|
#[tool_router]
|
|
impl MeetingServer {
|
|
pub fn new(root: PathBuf) -> Self {
|
|
Self {
|
|
library: Arc::new(Library::new(root)),
|
|
tool_router: Self::tool_router(),
|
|
}
|
|
}
|
|
|
|
#[tool(
|
|
description = "List recorded meetings, newest first: id, title (generated title when \
|
|
present), start time, duration, status, transcript kind, participants, and whether notes exist.",
|
|
annotations(read_only_hint = true, open_world_hint = false)
|
|
)]
|
|
fn list_meetings(
|
|
&self,
|
|
Parameters(args): Parameters<ListMeetingsArgs>,
|
|
) -> Result<CallToolResult, ErrorData> {
|
|
reply(self.library.list(
|
|
&ListQuery {
|
|
since: args.since,
|
|
until: args.until,
|
|
query: args.query,
|
|
limit: args.limit.unwrap_or(20) as usize,
|
|
include_in_progress: args.include_in_progress.unwrap_or(true),
|
|
},
|
|
now_ms(),
|
|
))
|
|
}
|
|
|
|
#[tool(
|
|
description = "Full-text search across meeting transcripts and stored notes. Returns \
|
|
ranked passages with meeting id, title, speaker, mm:ss offset, absolute time, and a snippet \
|
|
with surrounding lines, plus match counts per meeting. Case- and accent-insensitive, stemmed, \
|
|
and fuzzy for speech-recognition errors (Dax/DAX/Dacks).",
|
|
annotations(read_only_hint = true, open_world_hint = false)
|
|
)]
|
|
fn search_transcripts(
|
|
&self,
|
|
Parameters(args): Parameters<SearchTranscriptsArgs>,
|
|
) -> Result<CallToolResult, ErrorData> {
|
|
reply(self.library.search(
|
|
&SearchQuery {
|
|
query: args.query,
|
|
since: args.since,
|
|
until: args.until,
|
|
meeting_id: args.meeting_id,
|
|
limit: args.limit.unwrap_or(10) as usize,
|
|
fuzzy: args.fuzzy.unwrap_or(true),
|
|
include_in_progress: args.include_in_progress.unwrap_or(true),
|
|
},
|
|
now_ms(),
|
|
))
|
|
}
|
|
|
|
#[tool(
|
|
description = "Read a meeting transcript as merged You/Them turns with mm:ss offsets and \
|
|
local clock times. Optionally limit to a time range or one speaker. Long results stop at \
|
|
max_chars and return next_cursor to continue.",
|
|
annotations(read_only_hint = true, open_world_hint = false)
|
|
)]
|
|
fn get_transcript(
|
|
&self,
|
|
Parameters(args): Parameters<GetTranscriptArgs>,
|
|
) -> Result<CallToolResult, ErrorData> {
|
|
reply(self.library.transcript(
|
|
&TranscriptQuery {
|
|
meeting_id: args.meeting_id,
|
|
start: args.start.map(Offset::text),
|
|
end: args.end.map(Offset::text),
|
|
speaker: args.speaker,
|
|
max_chars: args.max_chars.unwrap_or(20_000) as usize,
|
|
cursor: args.cursor,
|
|
},
|
|
now_ms(),
|
|
))
|
|
}
|
|
|
|
#[tool(
|
|
description = "The stored Apple Intelligence title and summary (at most two sentences) \
|
|
for a meeting. Only a short overview: read the transcript with get_transcript or \
|
|
search_transcripts for details, decisions, and action items. Never generates notes; when none \
|
|
are stored it says so.",
|
|
annotations(read_only_hint = true, open_world_hint = false)
|
|
)]
|
|
fn get_meeting_notes(
|
|
&self,
|
|
Parameters(args): Parameters<GetMeetingNotesArgs>,
|
|
) -> Result<CallToolResult, ErrorData> {
|
|
reply(self.library.notes(&args.meeting_id))
|
|
}
|
|
}
|
|
|
|
fn internal(error: color_eyre::Report) -> ErrorData {
|
|
ErrorData::internal_error(error.to_string(), None)
|
|
}
|
|
|
|
#[tool_handler(router = self.tool_router)]
|
|
impl ServerHandler for MeetingServer {
|
|
fn get_info(&self) -> ServerConfig {
|
|
ServerConfig::new(
|
|
ServerCapabilities::builder()
|
|
.enable_tools()
|
|
.enable_resources()
|
|
.build(),
|
|
)
|
|
.with_server_info(
|
|
Implementation::new("hex-meetings", env!("CARGO_PKG_VERSION"))
|
|
.with_title("HEX Meetings"),
|
|
)
|
|
.with_instructions(INSTRUCTIONS)
|
|
}
|
|
|
|
async fn list_resources(
|
|
&self,
|
|
_request: Option<PaginatedRequestParams>,
|
|
_context: RequestContext<RoleServer>,
|
|
) -> Result<ListResourcesResult, ErrorData> {
|
|
let scan = self.library.scan().map_err(internal)?;
|
|
Ok(ListResourcesResult::with_all_items(
|
|
scan.meetings
|
|
.iter()
|
|
.map(|meeting| {
|
|
Resource::new(
|
|
format!("{RESOURCE_SCHEME}{}", meeting.id),
|
|
meeting.id.clone(),
|
|
)
|
|
.with_title(meeting.title())
|
|
.with_description(format!(
|
|
"Meeting transcript and notes, started {}",
|
|
crate::meeting::query::iso_local(meeting.start_ms())
|
|
))
|
|
.with_mime_type("text/markdown")
|
|
})
|
|
.collect(),
|
|
))
|
|
}
|
|
|
|
async fn list_resource_templates(
|
|
&self,
|
|
_request: Option<PaginatedRequestParams>,
|
|
_context: RequestContext<RoleServer>,
|
|
) -> Result<ListResourceTemplatesResult, ErrorData> {
|
|
Ok(ListResourceTemplatesResult::with_all_items(vec![
|
|
ResourceTemplate::new(format!("{RESOURCE_SCHEME}{{meeting_id}}"), "meeting")
|
|
.with_title("Meeting Markdown")
|
|
.with_description("A meeting's metadata, stored notes, and transcript")
|
|
.with_mime_type("text/markdown"),
|
|
]))
|
|
}
|
|
|
|
async fn read_resource(
|
|
&self,
|
|
request: ReadResourceRequestParams,
|
|
_context: RequestContext<RoleServer>,
|
|
) -> Result<ReadResourceResponse, ErrorData> {
|
|
let Some(id) = request.uri.strip_prefix(RESOURCE_SCHEME) else {
|
|
return Err(ErrorData::resource_not_found(
|
|
format!("unknown resource {}", request.uri),
|
|
None,
|
|
));
|
|
};
|
|
let markdown = self
|
|
.library
|
|
.markdown(id.trim_end_matches('/'), now_ms())
|
|
.map_err(|error| ErrorData::resource_not_found(error.to_string(), None))?;
|
|
Ok(ReadResourceResult::new(vec![
|
|
ResourceContents::text(markdown, request.uri.clone()).with_mime_type("text/markdown"),
|
|
])
|
|
.into())
|
|
}
|
|
}
|
|
|
|
/// Serves MCP over stdin/stdout until the client disconnects. Reads only
|
|
/// `root`; logs go to stderr so stdout carries protocol messages alone.
|
|
pub fn run(root: PathBuf) -> Result<()> {
|
|
let runtime = tokio::runtime::Builder::new_current_thread()
|
|
.enable_all()
|
|
.build()?;
|
|
runtime.block_on(async move {
|
|
let service = MeetingServer::new(root)
|
|
.serve(rmcp::transport::stdio())
|
|
.await
|
|
.map_err(|error| eyre!("MCP session failed to start: {error}"))?;
|
|
service.waiting().await?;
|
|
Ok(())
|
|
})
|
|
}
|