GeezerVison is showing github.com — fix: preserve dictation context and session lifecycle · FOX-cOSMIC/FOX-cOSMIC-t3@b8d5c37
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3570,6 +3570,7 @@ export default function ChatView(props: ChatViewProps) { | 3570 | 3570 | ) : null} | 3571 | 3571 | {!composerMounted ? null : ( | 3572 | 3572 | <ChatComposer | | 3573 | + getShortcutContext={getShortcutContextStable} | 3573 | 3574 | canOperateThread={canOperateThread} | 3574 | 3575 | reportedModelSelection={reportedModelSelection} | 3575 | 3576 | multipleModelSelections={multipleModelSelections} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ChatComposer.tsx +14-12Lines changed: 14 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -137,8 +137,11 @@ import { attachmentUploadBlockReason } from "../../lib/attachmentUploadState"; | 137 | 137 | import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection"; | 138 | 138 | import { isCommandPaletteOpen } from "../../commandPaletteBus"; | 139 | 139 | import { isInSideChatPane } from "../../lib/sideChatPane"; | 140 | | -import { getTerminalFocusOwner } from "../../lib/terminalFocus"; | 141 | | -import { resolveShortcutCommand, shortcutLabelForCommand } from "../../keybindings"; | | 140 | +import { | | 141 | + resolveShortcutCommand, | | 142 | + shortcutLabelForCommand, | | 143 | + type ShortcutMatchContext, | | 144 | +} from "../../keybindings"; | 142 | 145 | import { | 143 | 146 | type TerminalContextDraft, | 144 | 147 | type TerminalContextSelection, | @@ -356,6 +359,7 @@ export interface ChatComposerHandle { | 356 | 359 | } | 357 | 360 |
| 358 | 361 | export interface ChatComposerProps { | | 362 | + getShortcutContext: (target: EventTarget | null) => Partial<ShortcutMatchContext>; | 359 | 363 | composerDraftTarget: ScopedThreadRef | DraftId; | 360 | 364 | environmentId: EnvironmentId; | 361 | 365 | canOperateThread: boolean; | @@ -955,11 +959,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 955 | 959 | start: inserted.start, | 956 | 960 | end: inserted.end + (closed.cursor - selection.start), | 957 | 961 | }; | 958 | | - const previous = promptRef.current; | 959 | | - applyPromptReplacement(0, previous.length, closed.text, { | 960 | | - expandedCursorAfterReplace: closed.cursor, | 961 | | - focusEditorAfterReplace: false, | 962 | | - }); | | 962 | + onPromptChange( | | 963 | + closed.text, | | 964 | + collapseExpandedComposerCursor(closed.text, closed.cursor, isLiteralPendingAnswer), | | 965 | + closed.cursor, | | 966 | + isLiteralPendingAnswer, | | 967 | + isLiteralPendingAnswer ? [] : collectInlineContextIds(closed.text), | | 968 | + ); | 963 | 969 | }, | 964 | 970 | onCommitted: () => { | 965 | 971 | composerEditorRef.current?.focusAt(composerCursor); | @@ -2422,11 +2428,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 2422 | 2428 | ? event.target instanceof Node && composerFormRef.current?.contains(event.target) === true | 2423 | 2429 | : !isInSideChatPane(event.target)) && | 2424 | 2430 | resolveShortcutCommand(event, keybindings, { | 2425 | | - context: { | 2426 | | - terminalFocus: getTerminalFocusOwner() !== null, | 2427 | | - terminalOpen, | 2428 | | - modelPickerOpen: isComposerModelPickerOpen, | 2429 | | - }, | | 2431 | + context: props.getShortcutContext(event.target), | 2430 | 2432 | }) === "composer.dictate", | 2431 | 2433 | }); | 2432 | 2434 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/DictationSettings.tsx +10-9Lines changed: 10 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,10 +25,10 @@ import { useEnvironmentScope } from "~/state/session"; | 25 | 25 | import { useAtomCommand } from "~/state/use-atom-command"; | 26 | 26 | import { Button } from "../ui/button"; | 27 | 27 | import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; | | 28 | +import { Switch } from "../ui/switch"; | 28 | 29 | import { toastManager } from "../ui/toast"; | 29 | 30 | import { EnvironmentRow, environmentTransportLabel } from "./EnvironmentRow"; | 30 | 31 | import { FoldedSettingsSection } from "./FoldedSettingsSection"; | 31 | | -import { ScopedSwitch } from "./ScopedSwitch"; | 32 | 32 | import { useSettingsScope } from "./SettingsScopeContext"; | 33 | 33 | import { SettingsRow, SettingsSection } from "./settingsLayout"; | 34 | 34 | import { searchableSetting } from "./settingsSearch"; | @@ -84,7 +84,7 @@ const modelDetail = (model: DictationModel) => | 84 | 84 |
| 85 | 85 | // Scope model installation to each selected environment. | 86 | 86 | export function DictationSettingsSection() { | 87 | | - const { scope, environment, connectedEnvironments } = useSettingsScope(); | | 87 | + const { scope, environment, connectedEnvironments, targets } = useSettingsScope(); | 88 | 88 | const environmentId = | 89 | 89 | environment?.connection.phase === "connected" && environment.serverConfig !== null | 90 | 90 | ? environment.environmentId | @@ -93,6 +93,9 @@ export function DictationSettingsSection() { | 93 | 93 | // A server from before dictation has no dictation methods, so its subscription fails outright. | 94 | 94 | const outdated = environmentId !== null && state === null && error !== null; | 95 | 95 | const settings = useScopedSettings((unified) => unified.dictation); | | 96 | + const engineMixed = targets.some( | | 97 | + (target) => target.settings.dictation.engine !== settings.engine, | | 98 | + ); | 96 | 99 | const updateSettings = useUpdateScopedSettings(); | 97 | 100 | const canConfigure = useEnvironmentScope(environmentId, AuthSettingsWriteScope); | 98 | 101 | const projectScope = scope.kind === "project" || scope.kind === "checkout"; | @@ -116,9 +119,9 @@ export function DictationSettingsSection() { | 116 | 119 | : "Transcribe dictation on this environment with a local speech model. Audio is not sent to any other service." | 117 | 120 | } | 118 | 121 | control={ | 119 | | - <ScopedSwitch | 120 | | - settingKeys={["dictation"]} | 121 | | - checked={settings.engine === "local"} | | 122 | + <Switch | | 123 | + mixed={engineMixed} | | 124 | + checked={!engineMixed && settings.engine === "local"} | 122 | 125 | disabled={locked} | 123 | 126 | aria-label="Dictation" | 124 | 127 | onCheckedChange={(checked) => | @@ -277,12 +280,10 @@ function InactiveDictationModels(props: { | 277 | 280 | const [removing, setRemoving] = useState<DictationModel["id"] | null>(null); | 278 | 281 | if (!state?.supported) return null; | 279 | 282 | const inactive = state.models.filter( | 280 | | - // The environment keeps its own active model even when another environment's | 281 | | - // selection is shown; removing it would be a no-op on the server. | 282 | 283 | (model) => | 283 | 284 | model.install._tag === "installed" && | 284 | | - model.id !== props.selectedModel && | 285 | | - model.id !== state.settings.localModel, | | 285 | + (state.settings.engine === "off" || | | 286 | + (model.id !== props.selectedModel && model.id !== state.settings.localModel)), | 286 | 287 | ); | 287 | 288 | if (inactive.length === 0) return null; | 288 | 289 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/dictation/streamingDictation.ts +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -163,7 +163,7 @@ export function createStreamingDictation(input: { | 163 | 163 | throw new VoiceTranscriptionError("unavailable", "No environment can transcribe."); | 164 | 164 | } | 165 | 165 | // A start that never answers must not hold dictation open after a cancel. | 166 | | - const failure = await Promise.race([current.ready, rejectOnAbort(signal)]); | | 166 | + const failure = await Promise.race([current.ready, current.lost, rejectOnAbort(signal)]); | 167 | 167 | if (failure !== null) throw new VoiceTranscriptionError("preparation-failed", failure); | 168 | 168 | const sessionId = current.sessionId; | 169 | 169 | if (signal.aborted || sessionId === null) close(current); | @@ -227,17 +227,16 @@ export function createStreamingDictation(input: { | 227 | 227 | dependencies: { | 228 | 228 | recorder, | 229 | 229 | getTranscriber: () => (input.resolveEnvironmentId() === null ? null : transcriber), | 230 | | - // Opening the microphone is the browser's permission prompt. The session | 231 | | - // request goes out first so the network round trip overlaps it, and | 232 | | - // capture starts the moment the microphone is live. | | 230 | + // Permission prompts can outlive server sessions, so request a session only after consent. | 233 | 231 | requestPermission: async () => { | 234 | 232 | const environmentId = input.resolveEnvironmentId(); | 235 | 233 | close(session); | 236 | | - session = environmentId === null ? null : begin(environmentId); | | 234 | + session = null; | 237 | 235 | const access = await capture.open(); | 238 | 236 | if (!access.granted) { | 239 | 237 | return { granted: false, canAskAgain: true, message: access.message }; | 240 | 238 | } | | 239 | + session = environmentId === null ? null : begin(environmentId); | 241 | 240 | await capture.prepare(); | 242 | 241 | const current = session; | 243 | 242 | captureStartedAt = Date.now(); | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/inlineSkills.test.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,11 +15,16 @@ describe("replaceSpokenSkills", () => { | 15 | 15 | expect([...matchInlineSkills(text, skills)].map((match) => match.skill.name)).toEqual([ | 16 | 16 | "review", | 17 | 17 | ]); | | 18 | + const sentences = replaceSpokenSkills("Use the review skill. Then run tests.", skills); | | 19 | + expect(sentences).toBe("Use $review. Then run tests."); | | 20 | + expect([...matchInlineSkills(sentences, skills)].map((match) => match.skill.name)).toEqual([ | | 21 | + "review", | | 22 | + ]); | 18 | 23 | }); | 19 | 24 |
| 20 | 25 | it("matches multi-word names, split words, and small recognition slips", () => { | 21 | 26 | expect(replaceSpokenSkills("potato mode skill, fix the bug", skills)).toBe( | 22 | | - "$poteto-mode fix the bug", | | 27 | + "$poteto-mode, fix the bug", | 23 | 28 | ); | 24 | 29 | expect(replaceSpokenSkills("run skill post plan read on it", skills)).toBe( | 25 | 30 | "run $postplan-read on it", | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/inlineSkills.ts +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ export function formatProviderSkillDisplayName( | 22 | 22 | } | 23 | 23 |
| 24 | 24 | const SKILL_TOKEN_REGEX = | 25 | | - /(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/gu; | | 25 | + /(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|[.,!?;:]|$)/gu; | 26 | 26 |
| 27 | 27 | export function* matchInlineSkills<Skill extends InlineSkill>( | 28 | 28 | text: string, | @@ -131,7 +131,10 @@ export function replaceSpokenSkills(text: string, skills: readonly InlineSkill[] | 131 | 131 | if (words[first]!.start < consumedUntil) continue; | 132 | 132 | replacements.push({ | 133 | 133 | start: words[first]!.start, | 134 | | - end: words[match.last]!.end, | | 134 | + end: | | 135 | + words[match.last]!.start + | | 136 | + text.slice(words[match.last]!.start, words[match.last]!.end).replace(/[^\p{L}\p{N}]+$/u, "") | | 137 | + .length, | 135 | 138 | token: `$${match.skill.name}`, | 136 | 139 | }); | 137 | 140 | consumedUntil = words[match.last]!.end; | |
|