Let a dictation be a command for Claude Code, not only text

Dictation ends the same way every time: the words you said land in the window
you were in. But half of what you say to a machine is not text to place, it is
something to do, and the answer to "what is on my calendar today" is not that
sentence written out.

`claude -p` is that session run without a window: the same skills, the same
connected services, the same account. So a second shortcut records exactly as
the first one does and sends the transcript there instead, and what comes back
is pasted where the transcript would have been. Which is what puts "save that
to my calendar on Thursday at three" inside a text field that has nothing to do
with Claude.

Permissions are the part worth being deliberate about, because nothing here can
answer a prompt: a mode that would have asked denies instead. It runs in `auto`,
which decides for itself with the prompt-injection checks left on, and the other
two modes are one setting away. What Claude was not allowed to touch is reported
rather than swallowed, since a reply that reads perfectly normal is otherwise
the only sign that the job did not happen.

Commands close together stay in one conversation, so "and move that to Thursday"
knows what "that" is; half an hour of silence ends it, as does the tray. The
answer is written to be read where it lands: no headings, no lists, and a
sentence naming what was done when something was done.

Its output is read as it streams rather than waited out, so the corner names the
tool it is on. A calendar lookup took 29 s in testing, which a still indicator
would have made indistinguishable from a hang. The clock and the stop button are
watched from a thread of their own, because the stream blocks between lines and
a model that thinks for a minute sends none: they end the run by killing the
process, which closes the stream and unwinds everything else on its own.

Transcript cleanup is off on this path. Claude reads through "erm" and "hani"
without help, and skipping it saves an API call and a second or two in front of
a screen you are standing at.
This commit is contained in:
yusufipk
2026-07-28 16:57:10 +07:00
parent 352f7b6c22
commit 0206303751
10 changed files with 908 additions and 37 deletions
+242 -1
View File
@@ -1,6 +1,7 @@
"""Settings window."""
import os
import shutil
import threading
from PyQt6.QtCore import Qt, QUrl, pyqtSignal
@@ -13,6 +14,7 @@ from PyQt6.QtWidgets import (
)
import api
import assistant
import audio
import config as cfg
import filetranscribe
@@ -50,6 +52,16 @@ MEETING_MODELS = [
"google/gemini-3.5-flash", "google/gemini-3.1-pro-preview",
"anthropic/claude-sonnet-5", "openai/gpt-5.4", "x-ai/grok-4.5",
]
# Aliases resolve to the newest model of that name, so they age better than an
# id does; a full id can be typed in when a particular one is wanted.
ASSISTANT_MODELS = ["sonnet", "opus", "haiku", "fable"]
# What Claude Code may do without being able to ask. It cannot ask: there is no
# window to answer in, so a mode that would have prompted denies instead.
PERMISSION_MODES = [
("Decide on its own, with the safety checks on", "auto"),
("Allow everything", "bypassPermissions"),
("Only what needs no permission", "manual"),
]
MEETING_STATUS = {
"recorded": "waiting to be written up",
"transcribed": "transcript ready, minutes missing",
@@ -76,11 +88,12 @@ class SettingsWindow(QDialog):
_or_test_done = pyqtSignal(bool, str)
def __init__(self, conf, launch_command, meeting_command=None,
meetings=None, parent=None):
meetings=None, ask_command=None, parent=None):
super().__init__(parent)
self.conf = conf
self.launch_command = launch_command
self.meeting_command = meeting_command or launch_command
self.ask_command = ask_command or launch_command
self.meetings = meetings
# Each provider keeps its own transcription model, so switching the
# provider back and forth never overwrites the other one's.
@@ -94,6 +107,7 @@ class SettingsWindow(QDialog):
tabs.addTab(self._general_tab(), t("General"))
tabs.addTab(self._api_tab(), t("API and models"))
tabs.addTab(self._prompt_tab(), t("Cleanup rules"))
tabs.addTab(self._assistant_tab(), t("Claude"))
tabs.addTab(self._meeting_tab(), t("Meeting"))
tabs.addTab(self._minutes_tab(), t("Minutes"))
tabs.addTab(self._file_tab(), t("Audio file"))
@@ -304,6 +318,134 @@ class SettingsWindow(QDialog):
layout.addWidget(self.transcribe_prompt)
return page
def _assistant_tab(self):
page = QWidget()
layout = QVBoxLayout(page)
intro = QLabel(t(
"This shortcut records the same way dictation does, but the "
"transcript is not what gets pasted. It goes to Claude Code as a "
"command, and what comes back is pasted instead: the answer to a "
"question, or a sentence saying what was done. It runs as the "
"session you would have opened yourself, with your skills, your "
"connected services and your account."
))
intro.setWordWrap(True)
layout.addWidget(intro)
self.assistant_found = QLabel("")
self.assistant_found.setWordWrap(True)
layout.addWidget(self.assistant_found)
how = QGroupBox(t("How it runs"))
how_form = QFormLayout(how)
self.assistant_shortcut = QLineEdit()
self.assistant_shortcut.setPlaceholderText(t("none"))
install = QPushButton(t("Install as a KDE shortcut"))
install.clicked.connect(self._install_ask_shortcut)
remove = QPushButton(t("Remove"))
remove.clicked.connect(self._remove_ask_shortcut)
how_form.addRow(t("Shortcut"),
self._row(self.assistant_shortcut, install, remove))
self.assistant_shortcut_status = QLabel("")
self.assistant_shortcut_status.setWordWrap(True)
how_form.addRow(self.assistant_shortcut_status)
self.assistant_model = QComboBox()
self.assistant_model.setEditable(True)
self.assistant_model.addItems(ASSISTANT_MODELS)
self.assistant_model.setToolTip(t(
"A name like “sonnet” always means the newest model of that line. "
"Opus thinks harder and answers slower, which is felt here more "
"than anywhere else: you are standing in front of the screen."
))
how_form.addRow(t("Model"), self.assistant_model)
self.assistant_permission = QComboBox()
for label, value in PERMISSION_MODES:
self.assistant_permission.addItem(t(label), value)
how_form.addRow(t("Permissions"), self.assistant_permission)
self.assistant_dir = QLineEdit()
self.assistant_dir.setPlaceholderText(os.path.expanduser("~"))
browse = QPushButton(t("Choose…"))
browse.clicked.connect(self._choose_assistant_dir)
how_form.addRow(t("Working directory"),
self._row(self.assistant_dir, browse))
dir_note = QLabel(t(
"The directory the command runs in, which decides which project's "
"instructions and files it can see. Your own skills and services "
"are there whichever one it is."
))
dir_note.setWordWrap(True)
how_form.addRow(dir_note)
self.assistant_timeout = QSpinBox()
self.assistant_timeout.setRange(15, 3600)
self.assistant_timeout.setSuffix(t(" s"))
self.assistant_timeout.setToolTip(t(
"A command still running after this is given up on. The tray menu "
"can stop one earlier."
))
how_form.addRow(t("Give up after"), self.assistant_timeout)
layout.addWidget(how)
thread = QGroupBox(t("The conversation"))
thread_form = QFormLayout(thread)
self.assistant_session_minutes = QSpinBox()
self.assistant_session_minutes.setRange(0, 1440)
self.assistant_session_minutes.setSuffix(t(" min"))
self.assistant_session_minutes.setSpecialValueText(t("every command on its own"))
thread_form.addRow(t("Carry on for"), self.assistant_session_minutes)
thread_note = QLabel(t(
"Commands within this long of each other are one conversation, so "
"“and move that to Thursday” knows what “that” is. After it, the "
"next command starts fresh."
))
thread_note.setWordWrap(True)
thread_form.addRow(thread_note)
reset = QPushButton(t("Start a new conversation now"))
reset.clicked.connect(self._reset_assistant_session)
self.assistant_session_status = QLabel("")
self.assistant_session_status.setWordWrap(True)
thread_form.addRow(self._row(reset), self.assistant_session_status)
layout.addWidget(thread)
answer = QGroupBox(t("The answer"))
answer_form = QFormLayout(answer)
self.assistant_paste = QCheckBox(t("Paste it into the focused window"))
self.assistant_paste.setToolTip(t(
"It is copied to the clipboard either way."
))
answer_form.addRow("", self.assistant_paste)
self.assistant_cleanup = QCheckBox(t("Clean the transcript up before sending it"))
self.assistant_cleanup.setToolTip(t(
"Off by default: Claude reads through “erm” and “you know” without "
"help, and cleanup costs an API call and a second or two."
))
answer_form.addRow("", self.assistant_cleanup)
layout.addWidget(answer)
prompt_label = QLabel(t(
"Told to Claude alongside every command, on top of whatever your "
"own configuration already says."
))
prompt_label.setWordWrap(True)
layout.addWidget(prompt_label)
self.assistant_prompt = QPlainTextEdit()
self.assistant_prompt.setMinimumHeight(180)
layout.addWidget(self.assistant_prompt, 1)
reset_prompt = QPushButton(t("Reset to default"))
reset_prompt.clicked.connect(
lambda: self.assistant_prompt.setPlainText(cfg.default_assistant_prompt())
)
layout.addWidget(reset_prompt, 0, Qt.AlignmentFlag.AlignRight)
area = QScrollArea()
area.setWidgetResizable(True)
area.setFrameShape(QScrollArea.Shape.NoFrame)
area.setWidget(page)
return area
def _meeting_tab(self):
page = QWidget()
layout = QVBoxLayout(page)
@@ -677,6 +819,18 @@ class SettingsWindow(QDialog):
self.cleanup_prompt.setPlainText(conf["cleanup_prompt"] or cfg.default_cleanup_prompt())
self.transcribe_prompt.setPlainText(conf["transcribe_prompt"])
self.assistant_shortcut.setText(conf["assistant_shortcut"])
self.assistant_model.setCurrentText(conf["assistant_model"])
self._select_data(self.assistant_permission, conf["assistant_permission_mode"])
self.assistant_dir.setText(conf["assistant_dir"])
self.assistant_timeout.setValue(int(conf["assistant_timeout"]))
self.assistant_session_minutes.setValue(int(conf["assistant_session_minutes"]))
self.assistant_paste.setChecked(conf["assistant_paste"])
self.assistant_cleanup.setChecked(conf["assistant_cleanup"])
self.assistant_prompt.setPlainText(
conf["assistant_prompt"] or cfg.default_assistant_prompt()
)
self._select_data(self.meeting_mic, conf["meeting_mic_target"])
self._select_data(self.meeting_system, conf["meeting_system_target"])
self.meeting_self_name.setText(conf["meeting_self_name"])
@@ -704,6 +858,8 @@ class SettingsWindow(QDialog):
self._refresh_shortcut_status()
self._refresh_meeting_shortcut_status()
self._refresh_ask_shortcut_status()
self._refresh_assistant_status()
self._load_history()
self._load_minutes()
@@ -742,6 +898,20 @@ class SettingsWindow(QDialog):
conf["cleanup_prompt"] = "" if prompt == cfg.default_cleanup_prompt() else prompt
conf["transcribe_prompt"] = self.transcribe_prompt.toPlainText().strip()
conf["assistant_shortcut"] = self.assistant_shortcut.text().strip()
conf["assistant_model"] = (self.assistant_model.currentText().strip()
or cfg.DEFAULTS["assistant_model"])
conf["assistant_permission_mode"] = (self.assistant_permission.currentData()
or "auto")
conf["assistant_dir"] = self.assistant_dir.text().strip()
conf["assistant_timeout"] = self.assistant_timeout.value()
conf["assistant_session_minutes"] = self.assistant_session_minutes.value()
conf["assistant_paste"] = self.assistant_paste.isChecked()
conf["assistant_cleanup"] = self.assistant_cleanup.isChecked()
assistant_prompt = self.assistant_prompt.toPlainText().strip()
conf["assistant_prompt"] = ("" if assistant_prompt == cfg.default_assistant_prompt()
else assistant_prompt)
conf["meeting_mic_target"] = self.meeting_mic.currentData() or ""
conf["meeting_system_target"] = self.meeting_system.currentData() or ""
conf["meeting_self_name"] = self.meeting_self_name.text().strip()
@@ -1034,6 +1204,71 @@ class SettingsWindow(QDialog):
else t("No KDE shortcut installed. The tray menu starts a meeting too.")
)
# ---- Claude ----------------------------------------------------------
def _install_ask_shortcut(self):
combo = self.assistant_shortcut.text().strip()
if not combo:
QMessageBox.information(self, t("Shortcut"),
t("Type a key combination first."))
return
clashes = hotkey.conflicting_shortcuts(combo, hotkey.ASK_DESKTOP_ID)
if clashes:
answer = QMessageBox.question(
self, t("Shortcut conflict"),
t("{shortcut} is also used by:\n\n{list}\n\nInstall anyway?",
shortcut=combo, list="\n".join(clashes[:6])),
)
if answer != QMessageBox.StandardButton.Yes:
return
ok, message = hotkey.install_kde_shortcut(
combo, self.ask_command, name="Dikte: ask Claude Code",
desktop_id=hotkey.ASK_DESKTOP_ID,
)
QMessageBox.information(self, t("Shortcut"), message)
if ok:
self.conf["assistant_shortcut"] = combo
self.conf.save()
self._refresh_ask_shortcut_status()
def _remove_ask_shortcut(self):
hotkey.remove_kde_shortcut(hotkey.ASK_DESKTOP_ID)
self._refresh_ask_shortcut_status()
def _refresh_ask_shortcut_status(self):
current = hotkey.kde_shortcut_status(hotkey.ASK_DESKTOP_ID)
self.assistant_shortcut_status.setText(
t("Registered in KDE: {shortcut}", shortcut=current) if current
else t("No KDE shortcut installed. The tray menu asks Claude too.")
)
def _refresh_assistant_status(self):
found = shutil.which("claude")
self.assistant_found.setText(
t("Found: {path}", path=found) if found else
t("claude is not on your PATH, so this cannot run yet. Install "
"Claude Code first.")
)
age = assistant.session_age()
if age is None:
self.assistant_session_status.setText(t("No conversation going."))
else:
self.assistant_session_status.setText(
t("Last used {minutes} min ago.", minutes=int(age // 60))
)
def _reset_assistant_session(self):
assistant.clear_session()
self._refresh_assistant_status()
def _choose_assistant_dir(self):
chosen = QFileDialog.getExistingDirectory(
self, t("Working directory"),
self.assistant_dir.text().strip() or os.path.expanduser("~"),
)
if chosen:
self.assistant_dir.setText(chosen)
# ---- minutes ---------------------------------------------------------
def _load_minutes(self):
@@ -1121,6 +1356,12 @@ class SettingsWindow(QDialog):
preview = text[:110] + ("" if len(text) > 110 else "")
header = t("{ts} ({duration} s)",
ts=row.get("ts", ""), duration=row.get("duration", 0))
if row.get("mode") == "ask":
# The text of an answer says nothing about what was asked, and
# out of that context half of them read like non sequiturs.
asked = (row.get("question") or row.get("raw") or "").replace("\n", " ")
header += t(" · asked Claude: {question}",
question=asked[:60] + ("" if len(asked) > 60 else ""))
item = QListWidgetItem(f"{header}\n{preview}")
item.setData(Qt.ItemDataRole.UserRole, row)
self.history.addItem(item)