A skill that resolves a long text (a book) can hand it to the scheduler's
speech channel and return immediately; the gateway that owns the chat drains it
and streams it with text-to-speech until the user stops it.
- semif_agent/speech.py: SpeechService + ReadAloud. A bounded queue a front end
drains, plus a per-source streaming predicate (set_stream_check/supports) so a
skill asks before it posts one. Neutral and stdlib-only.
- semif_agent/reading.py: the bookmarks.json beside the saved books (load/save/
read a key -> last offset, atomic write) and a deterministic speakable
chunker at paragraph/sentence boundaries.
- Scheduler owns the channel (scheduler.speech); SkillRunner passes it into
every run's ActionContext, so a body reaches it as ctx.speech.
- gateway/service: registers stream_ready as the channel's capability
predicate, and surface() routes a drained read to the platform that owns the
run (a non-streaming adapter is traced and skipped, never handed a message it
would drop).
- gateway/voice: streams the saved text through the daemon's Piper voice chunk
by chunk, writing the bookmark before each chunk; a barge-in "stop" or any new
command ends it.
- gateway/lxmf: a read goes to a chat that last messaged by voice as a sequence
of Sideband HQ voice messages (Piper -> Opus/OGG, backpressure so a stop is
prompt), with the same bookmark-per-chunk resume; a "stop" message or any new
command interrupts it.
- A run that registers a read is terminal (read_aloud_terminal): the read is the
answer, so assess:outcome must not re-dispatch the request (which otherwise
authored a spurious skill).
- config.example.json regenerated with the new voice/lxmf read blocks.
While a reply is speaking the wake word is still scored, so the user can
interrupt it. On a wake the daemon aborts the playback, mutes further
speech while the interrupt is captured/handled, and hands the following
command to the front end. A bare "stop"/"cancel" aborts the reply and
drops anything queued behind it; anything else runs as a new command.
- voice_transport: AudioIO.play(pcm, rate, stop_event); SoundDeviceAudio
streams in ~50 ms chunks and aborts the output stream on a stop.
VoiceDaemon gains barge_in.{enabled,wait_s,threshold} and the
on_barge_in(active) callback; speak() drops text while muted and plays
through the interruptible path.
- gateway/voice: tags the interrupt utterance (raw["barge_in"]),
classifies stop vs new command (_is_stop_command), drops queued replies
on stop, and unmutes once handled.
- config: gateway.voice.barge_in block; config.example.json regenerated.
- tests: wake-abort, mute release, threshold gate, stop/new-command
classification, sentinel preservation.
The LXMF gateway now handles Sideband push-to-talk voice messages end to end.
Inbound: a PTT message carries its audio in LXMF.FIELD_AUDIO
(`[audio_mode, bytes]`); `lxmf_transport.parse_audio_field` normalizes it and
the adapter transcribes it into an ordinary command when
`gateway.lxmf.voice.enabled` is set. HQ Opus/OGG goes through faster-whisper
(requirements/transcribe.txt); non-HQ Codec2 through the optional pycodec2
bindings (requirements/codec2.txt). No microphone stack is needed.
Outbound: a chat that last messaged by voice is answered with a synthesized
voice message when `gateway.lxmf.voice.reply_with_voice` is on (the default).
`voice_transport.build_synthesizer` speaks the reply with Piper and
`voice_transport.pcm_to_opus_ogg` encodes it to OGG/Opus (48 kHz, PyAV's
libopus); `lxmf_transport.audio_fields` attaches it as a Sideband HQ PTT
message, with the reply text as the content so a text-only client still sees
it. The reply mode follows the chat's most recent inbound message. A missing
synthesizer or any synthesis/encode failure is traced and the reply falls back
to text. Deps: requirements/tts.txt (piper-tts + PyAV), still no microphone.
Also make LXMF replies result-only (`LxmfAdapter.result_only`, overridable via
`gateway.lxmf.result_only: false`): send the skill's result line, dropping
scheduler bookkeeping and the `<skill>: ok —` wrapper.
Wiring: new config keys under `gateway.lxmf` (result_only) and
`gateway.lxmf.voice` (reply_with_voice, max_speak_chars, reply_bitrate, tts);
regenerated config.example.json; the setup interview asks how to handle voice
messages and the install plan adds `install_lxmf_tts` (bootstrap installs
requirements/tts.txt and downloads the reply voice); cli anchors the LXMF
voice_dir to .runtime/voice/tts.
Tests cover the audio field shape, the outbound queue, the adapter's
voice-chat tracking and synthesis fallbacks, result-only routing, the
synthesis/encode helpers, and the setup plan. Docs updated.
New-skill authoring via the voice gateway never completed: STT emits
"Approve." / "Yes." / "retry." with sentence punctuation, but the
approval/repair maps were matched with an exact lookup, so a spoken
answer fell through to submit_request while the pending approval timed
out and nothing was registered.
- gateway/service: normalize the reply before the action lookup
(`_normalize_action`: lowercase, strip edge punctuation, first-word
fallback) and broaden the approval/repair vocabularies, so a spoken
"Approve." / "Yes." / "retry." matches like a typed one.
- scheduler: buffer the replies of a background drain (the codegen
worker's post-authoring re-run, a repair retry) in an outbox instead
of returning them into a thread that discards them; a front end's
`drain_outbox()` routes them, so the answer to the user's own request
is no longer swallowed.
- cli/dashboard: drain the outbox alongside the queue.
- tests: normalization + spoken approval/repair routing, outbox
routing, and the async requeue assertion.
Add the run-ledger chained-run path and make a compound request run its
known skills in order instead of authoring one monolithic skill.
- scheduler/skill: `assess:outcome` gains a `continue` verdict; a continued
step is re-dispatched with a bounded run ledger (max_reentries + a
monotonic-progress guard), and the ledger is rendered into the routing and
assessment state.
- navigation leaf guard (`confirm_skill_fit`) becomes same/part/different and
is ledger-aware, so the first step of a compound request runs instead of
being rejected into `create_skill` (a real run picked calculator.calculate
at 0.99 and was rejected into create_skill).
- results flow forward through `request.run_ledger` (`last_result` helper);
`simplex.send_message` sends the prior step's result rather than asking the
LLM bridge to recompute it. Documented in CODEGEN.md.
- `assess:outcome` stays the sole continuation authority: the guard only
decides whether a skill contributes, never forces a continuation (a forced
continue on `part` overrode a correct `done` on the final step and authored
a spurious category).
- verbosity levels, structured SchedulerReply fields, and a send_message
hermetic test for the chained-result path.
Gate the wake word on the scheduler's single slot being free: a wake that
fires while the current request is still running is ignored (traced
voice_wake_blocked), so a second command cannot start mid-run. The gate is
GatewayService.input_ready (False while a run executes, True when idle or
paused for the user's answer), handed to adapters via set_input_ready; the
voice adapter passes it to VoiceDaemon.input_ready.
Endpointing fix. The wake detector usually fires inside the wake phrase,
so the first speech captured after it is the phrase's tail (plus the cue
beep echoing back through the mic), not the command. A fixed 500 ms
trailing-silence endpoint then ended the capture during the natural pause
before the command: the utterance held 240-400 ms of speech and STT
returned empty. In a recorded session 18 of 30 wakes dropped the command
that way (only 10 transcribed).
The endpoint now uses a longer silence tolerance (vad.initial_silence_ms,
default 1500) until vad.min_command_ms (default 700) of speech is in
hand, then reverts to vad.silence_ms, so a pause before the command is
tolerated while a real command still ends promptly.
Front-end hardening (the ways it was silently dying or losing work):
- Utterances run on a worker thread, not the audio thread, and a task
error is traced and spoken rather than propagated, so one bad command
cannot stop the mic or take the front end down.
- Capture-stream watchdog: read with a timeout and close/reopen the input
after a sustained stall, so a wedged PortAudio/ALSA callback recovers
instead of hanging the gateway (traced voice_stream_stalled/reopened).
- faulthandler enabled (CLI + unit) so a fatal signal dumps every
thread's stack to the journal.
- The scheduler's answer-side entry points (answer, answer_question,
resolve_repair, answer_approval) are guarded like submit_request: an
EngineUnavailable is fatal-and-reported and any other resume/repair
error returns a reply instead of propagating into a front end.
Skill bodies prefixed their own `category.name` into `ActionResult.action_log`,
which duplicated the runner's deterministic summary prefix and leaked the name
into the text the gateways speak. Identity is not data for the output string.
- bodies (seeds, canned replies, housekeeping meta skills) write only the real
result; the runner already owns the `category.name:` summary prefix
- `run_queue`/`submit_request`/`answer` now return a structured `SchedulerReply`
(status, text, run_id, skill_ref, result); the gateway reads `skill_ref` and
`result` from it instead of regex-parsing them back out of the summary
- drop the gateway's `_SKILL_REF`/`_LEADING_RUN_ID` parsing helpers
- fix a latent double-prefix when a failed run had an empty action_log
- CODEGEN.md: generated bodies must not prefix the skill name
Four latency/ergonomics changes from the voice-gateway diagnosis:
1. Per-skill humanize override. A skill's own recorded config
(data/skills/<cat>/<name>/config.json -> {"humanize": bool}) now wins over
the per-platform and global defaults, so an already-speakable result
(time.now) can skip the rewrite. The gateway resolves the skill ref from the
result summary; `_finish_run` now emits `category.name: ok — …` (matching the
assessment summary) so the ref is available. Missing store/config/key and
test doubles degrade to the existing platform/global behavior.
2. Example voice endpointing: vad.silence_ms 1000 -> 500 (config.example.json).
3. Confident softmax winners skip their confirm guard. New
navigation.softmax_bypass_tau (default 0.5): a category winner at/above it
skips confirm_category_fit (trace `category_scope_bypassed`); a leaf winner
at/above it is handed to dispatch and skips confirm_skill_fit (trace
`intent_bypass`). Below the threshold the two-stage confirm is unchanged.
Assumption tested first on the decision log: 28/28 category and 28/28 leaf
winners >= 0.5 agreed with their guard.
4. Engine-throughput investigation saved to AGENTS.md "Later / open questions"
(routing/assessment compute dominates; profile the engine, not the audio).
Tests updated for the bypass threshold and added for the skill-level humanize
override and bypass paths. Full suite: 486 passed, 1 skipped.
Add trace boundaries and timings so the last-word -> first-audio latency can
be split by section:
- voice_transport: emit `voice_speech_end` (the last VAD-speech frame, i.e. the
true "last word"), `voice_speak_start`, `voice_tts_synth` (Piper duration +
audio length), and `voice_playback_start` (the instant the first reply
samples reach the device).
- trace: `TraceLog.append` accepts an explicit `ts` so an event records when it
happened, not when it was written.
- gateway/voice: trace `gateway_reply_dequeued` at the outbound pump.
- gateway/service: trace `humanize` (duration) and `gateway_reply_queued`; a
best-effort `_trace` helper tolerates test doubles with no trace log.
- log: persist the engine's per-decision `input_tokens`/`forward_seconds`/
`total_seconds` (already computed by the backend, previously discarded) into
the decision row's `extra.timing`.
scripts/voice-latency.py reads data/runs.jsonl and prints a per-interaction
breakdown (endpointing, STT, each SemIf guard, act/assess, humanize, TTS,
playback) plus aggregates.
Drop the urgency score and interrupt/preempt decisions: intake is now
idle -> dispatch, busy -> append to a bounded FIFO queue (RequestQueue).
The running process always finishes before the next queued request.
- queue.py: UrgencyQueue -> RequestQueue (deque, no weight/age/recency)
- scheduler.py: remove _priority_score, _interrupt_choice, urgency
constants, and the weight threaded through dispatch/authoring/requeue
- dashboard/static/gateway: drop weight + preempted handling
- tests + docs updated; flow-main.svg regenerated
Elicitation now asks one question at a time: only one PendingQuestion is
live, and the next is posted only after the current is answered (an empty
answer is accepted) or skipped. Each question gets a fresh
codegen.elicitation.answer_timeout (default 30s) that resets on every answer
submit; a timeout stops the sequence. questions_timeout is now traced only on
a real timeout. Front ends need no change — they read pending_questions().
Add opt-in creation_approval: the single-slot llm draft worker blocks after
authoring a proposal and before anything is registered; approve/deny via the
REPL, dashboard (/api/approvals + UI), or a gateway chat reply (yes/no). One
prompt per creation request (a category approval covers its chained skill);
denial or timeout aborts creation. Off by default.
Tests updated for both; full stdlib suite passes (337).
Split messaging UX (invite links, read, send) out of the command gateway into a
new `semif_agent.bridges` layer. Each bridge is its own process (`cli bridge`)
against its own service daemon/profile; the SimpleX bridge owns a second
simplex-chat daemon and buffers every inbound DM, so a message sent to the
connect-link address shows up in `simplex.next_message`.
- new: bridges/{base,inbox,registry,simplex}.py + neutral semif_agent/simplex_ws.py
- gateway: delete bridge.py; drop address/observer/pull-mode from the command path
- codegen: inject the bridge catalog (describe_bridges) into body + elicitation prompts
- seeds: repoint simplex.next_message/connect_link to top-level `simplex_bridge_url`
- config/bootstrap: new top-level `bridges` block + `simplex_bridge_url`; render
semif-simplex-forward + semif-bridge units; gateway config loses bridge/inbox
- docs: AGENTS.md gateway isolation is non-negotiable
- cli.load_config anchors skill_seeds/skill_bodies/category_registry/log/trace
to the checkout root, so a fresh clone's committed seeds load from any cwd
(running outside the repo root had an empty tree -> codegen loop).
- `skills` (CLI + REPL) lists scheduler.tree, not a throwaway built-ins tree.
- SimpleX adapter reads the real /_show_address shape
(contactLink.connLinkContact), so simplex.connect_link returns the link
instead of reporting no address.
Add a reusable corrId->Future request path to SimplexAdapter so the daemon
can be queried off the event loop, expose it as GET /address on the local
messaging bridge (injected address_provider; 503 unwired, 502 on daemon
failure), and ship a simplex.connect_link seed that reports the bot's short
and full contact link honestly, creating it on first call.
The gateway now exposes a localhost stdlib HTTP API (bridge.py) that
buffers authorized inbound DMs and forwards outbound sends, so a skill
body never opens a WebSocket to the simplex-chat daemon. Endpoints:
GET /health, /contacts, /inbox (peek), /inbox/next (pop oldest unread),
POST /send (resolve id/display name onto the adapter's outbound queue).
GatewayService gains an observer hook and inbox.dispatch (pull-only mode).
Expose the capability to codegen (SKILL.md, BODY_DIRECTIVES, elicitation,
TESTGEN.md) and add the simplex.next_message seed (SemIf recipient
resolution) with its hermetic loopback test. Config: messaging_bridge_url
plus gateway.simplex.{inbox,bridge}; bootstrap keeps them in sync.
Inbound DMs were silently dropped: simplex-chat v7 tags received text as
{"type": "rcvMsgContent", "msgContent": {"type": "text", ...}}, but
_parse_chat_item required a flat {"type": "text", "text": ...}. Every
message returned None (no gateway_message/gateway_sent/denied ever fired) so
pepper got no reply.
- parse content.msgContent.text, tolerating the DB/Aeson constructor-keyed
nesting as well
- resolve the peer name from profile.displayName first; v7's contact
displayName is null and localDisplayName is collision-suffixed (pepper_1)
- update the synthetic fixture to the real wire shape and add regression tests
- set PYTHONUNBUFFERED=1 in the rendered gateway unit so journal logging is live
The v7 receivedContactRequest event exposes contactRequestId (and contactId_,
the underscore being the generated-API optional marker); /_accept takes the
request id. The adapter looked for contactRequest.contactId, found nothing, and
silently no-oped — so contact requests hung unaccepted. Prefer contactRequestId,
fall back to contactId for legacy events, and trace the accepted ids. Tests for
both shapes and the disabled case.
Add a gateway adapter contract plus a SimpleX adapter (lazy websockets,
default-deny allowlist, batching, structured /_send) and a GatewayService
that maps chats onto the single-slot scheduler: submit_request, owner maps,
pending-run ownership, queue drain, and authoring questions/repairs routed
back to the origin chat. Wire `cli gateway [--platform simplex] [--dashboard]`
and the gateway.simplex config block. Scheduler gains submit_request() and an
on_request_requeued hook. DMs only for the first cut.